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