1 /* $FreeBSD: src/sys/dev/bktr/bktr_mem.c,v 1.13 2005/01/27 01:40:12 imp Exp */
2 /* $DragonFly: src/sys/dev/video/bktr/bktr_mem.c,v 1.8 2007/10/03 19:27:08 swildner Exp $ */
3
4 /*
5 * This is part of the Driver for Video Capture Cards (Frame grabbers)
6 * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
7 * chipset.
8 * Copyright Roger Hardiman.
9 *
10 * bktr_mem : This kernel module allows us to keep our allocated
11 * contiguous memory for the video buffer, DMA programs and VBI data
12 * while the main bktr driver is unloaded and reloaded.
13 * This avoids the problem of trying to allocate contiguous each
14 * time the bktr driver is loaded.
15 */
16
17 /*-
18 * 1. Redistributions of source code must retain the
19 * Copyright (c) 2000 Roger Hardiman
20 * All rights reserved.
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
25 * 1. Redistributions of source code must retain the above copyright
26 * notice, this list of conditions and the following disclaimer.
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 * 3. All advertising materials mentioning features or use of this software
31 * must display the following acknowledgement:
32 * This product includes software developed by Roger Hardiman
33 * 4. The name of the author may not be used to endorse or promote products
34 * derived from this software without specific prior written permission.
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
37 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
40 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
42 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
45 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46 * POSSIBILITY OF SUCH DAMAGE.
47 */
48
49
50 #include <sys/param.h>
51 #include <sys/kernel.h>
52 #include <sys/systm.h>
53 #include <dev/video/bktr/bktr_mem.h>
54
55 struct memory_pointers {
56 int addresses_stored;
57 vm_offset_t dma_prog;
58 vm_offset_t odd_dma_prog;
59 vm_offset_t vbidata;
60 vm_offset_t vbibuffer;
61 vm_offset_t buf;
62 } memory_pointers;
63
64 static struct memory_pointers memory_list[BKTR_MEM_MAX_DEVICES];
65
66 /*************************************************************/
67
68 static int
69 bktr_mem_modevent(module_t mod, int type, void *unused)
70 {
71
72 switch (type) {
73 case MOD_LOAD:
74 kprintf("bktr_mem: memory holder loaded\n");
75 bzero(memory_list, sizeof(memory_list));
76 return 0;
77 case MOD_UNLOAD:
78 kprintf("bktr_mem: memory holder cannot be unloaded\n");
79 return EBUSY;
80 default:
81 return EOPNOTSUPP;
82 break;
83 }
84 };
85
86 /*************************************************************/
87
88 int
89 bktr_has_stored_addresses(int unit)
90 {
91
92 if (unit < 0 || unit >= BKTR_MEM_MAX_DEVICES) {
93 kprintf("bktr_mem: Unit number %d invalid\n",unit);
94 return 0;
95 }
96
97 return memory_list[unit].addresses_stored;
98 }
99
100 /*************************************************************/
101
102 void
103 bktr_store_address(int unit, int type, vm_offset_t addr)
104 {
105
106 if (unit < 0 || unit >= BKTR_MEM_MAX_DEVICES) {
107 kprintf("bktr_mem: Unit number %d invalid for memory type %d, address %p\n",
108 unit, type, (void *)addr);
109 return;
110 }
111
112 switch (type) {
113 case BKTR_MEM_DMA_PROG:
114 memory_list[unit].dma_prog = addr;
115 memory_list[unit].addresses_stored = 1;
116 break;
117 case BKTR_MEM_ODD_DMA_PROG:
118 memory_list[unit].odd_dma_prog = addr;
119 memory_list[unit].addresses_stored = 1;
120 break;
121 case BKTR_MEM_VBIDATA:
122 memory_list[unit].vbidata = addr;
123 memory_list[unit].addresses_stored = 1;
124 break;
125 case BKTR_MEM_VBIBUFFER:
126 memory_list[unit].vbibuffer = addr;
127 memory_list[unit].addresses_stored = 1;
128 break;
129 case BKTR_MEM_BUF:
130 memory_list[unit].buf = addr;
131 memory_list[unit].addresses_stored = 1;
132 break;
133 default:
134 kprintf("bktr_mem: Invalid memory type %d for bktr%d, address %p\n",
135 type, unit, (void *)addr);
136 break;
137 }
138 }
139
140 /*************************************************************/
141
142 vm_offset_t
143 bktr_retrieve_address(int unit, int type)
144 {
145
146 if (unit < 0 || unit >= BKTR_MEM_MAX_DEVICES) {
147 kprintf("bktr_mem: Unit number %d too large for memory type %d\n",
148 unit, type);
149 return (0);
150 }
151 switch (type) {
152 case BKTR_MEM_DMA_PROG:
153 return memory_list[unit].dma_prog;
154 case BKTR_MEM_ODD_DMA_PROG:
155 return memory_list[unit].odd_dma_prog;
156 case BKTR_MEM_VBIDATA:
157 return memory_list[unit].vbidata;
158 case BKTR_MEM_VBIBUFFER:
159 return memory_list[unit].vbibuffer;
160 case BKTR_MEM_BUF:
161 return memory_list[unit].buf;
162 default:
163 kprintf("bktr_mem: Invalid memory type %d for bktr%d",
164 type, unit);
165 return (0);
166 }
167 }
168
169 /*************************************************************/
170
171 static moduledata_t bktr_mem_mod = {
172 "bktr_mem",
173 bktr_mem_modevent,
174 0
175 };
176
177 /*
178 * The load order is First and module type is Driver to make sure bktr_mem
179 * loads (and initialises) before bktr when both are loaded together.
180 */
181 DECLARE_MODULE(bktr_mem, bktr_mem_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
182 MODULE_VERSION(bktr_mem, 1);
Cache object: e900ed7acfe1fb3fb12c638d98c183d7
|