]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/bktr/bktr_mem.c
Use __FBSDID().
[FreeBSD/FreeBSD.git] / sys / dev / bktr / bktr_mem.c
1
2
3 #include <sys/cdefs.h>
4 __FBSDID("$FreeBSD$");
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 <sys/systm.h>
54 #include <dev/bktr/bktr_mem.h>
55
56 struct memory_pointers {
57         int         addresses_stored;
58         vm_offset_t dma_prog;
59         vm_offset_t odd_dma_prog;
60         vm_offset_t vbidata;
61         vm_offset_t vbibuffer;
62         vm_offset_t buf;
63 } memory_pointers;
64
65 static struct memory_pointers memory_list[BKTR_MEM_MAX_DEVICES];
66
67 /*************************************************************/
68
69 static int
70 bktr_mem_modevent(module_t mod, int type, void *unused){
71
72         switch (type) {
73         case MOD_LOAD:
74                 {
75                 printf("bktr_mem: memory holder loaded\n");
76 /*
77  * bzero causes a panic.
78                 bzero((caddr_t)memory_list, sizeof(memory_list));
79  * So use a simple for loop for now.
80 */
81                 {int x;
82                  unsigned char *d = (unsigned char *)memory_list;
83                  for (x=0; x< sizeof(memory_list); x++) {
84                   d[x]=0;
85                  }
86                 }
87                 return 0;
88                 }
89         case MOD_UNLOAD:
90                 {
91                 printf("bktr_mem: memory holder cannot be unloaded\n");
92                 return EBUSY;
93                 }
94         default:
95                 break;
96         }
97         return 0;
98 };
99
100 /*************************************************************/
101
102 int
103 bktr_has_stored_addresses(int unit) {
104
105         if ((unit < 0) || (unit >= BKTR_MEM_MAX_DEVICES)) {
106                 printf("bktr_mem: Unit number %d invalid\n",unit);
107                 return 0;
108         }
109
110         return memory_list[unit].addresses_stored;
111 }
112
113 /*************************************************************/
114
115 void
116 bktr_store_address(int unit, int type, vm_offset_t addr) {
117
118         if ((unit < 0) || (unit >= BKTR_MEM_MAX_DEVICES)) {
119                 printf("bktr_mem: Unit number %d invalid for memory type %d, address 0x%x\n"
120                        ,unit,type,addr);
121                 return;
122         }
123
124         switch (type) {
125                 case BKTR_MEM_DMA_PROG:     memory_list[unit].dma_prog = addr;
126                                             memory_list[unit].addresses_stored = 1;
127                                             break;
128                 case BKTR_MEM_ODD_DMA_PROG: memory_list[unit].odd_dma_prog = addr;
129                                             memory_list[unit].addresses_stored = 1;
130                                             break;
131                 case BKTR_MEM_VBIDATA:      memory_list[unit].vbidata = addr;
132                                             memory_list[unit].addresses_stored = 1;
133                                             break;
134                 case BKTR_MEM_VBIBUFFER:    memory_list[unit].vbibuffer = addr;
135                                             memory_list[unit].addresses_stored = 1;
136                                             break;
137                 case BKTR_MEM_BUF:          memory_list[unit].buf = addr;
138                                             memory_list[unit].addresses_stored = 1;
139                                             break;
140                 default:                    printf("bktr_mem: Invalid memory type %d for bktr%d, address 0x%xn",
141                                                    type,unit,addr);
142                                             break;
143         }
144 }
145
146 /*************************************************************/
147
148 vm_offset_t
149 bktr_retrieve_address(int unit, int type) {
150
151         if ((unit < 0) || (unit >= BKTR_MEM_MAX_DEVICES)) {
152                 printf("bktr_mem: Unit number %d too large for memory type %d\n",unit,type);
153                 return NULL;
154         }
155         switch (type) {
156                 case BKTR_MEM_DMA_PROG:     return memory_list[unit].dma_prog;
157                 case BKTR_MEM_ODD_DMA_PROG: return memory_list[unit].odd_dma_prog;
158                 case BKTR_MEM_VBIDATA:      return memory_list[unit].vbidata;
159                 case BKTR_MEM_VBIBUFFER:    return memory_list[unit].vbibuffer;
160                 case BKTR_MEM_BUF:          return memory_list[unit].buf;
161                 default:                    printf("bktr_mem: Invalid memory type %d for bktr%d",type,unit);
162                                             return NULL;
163         }
164 }
165
166 /*************************************************************/
167
168 static moduledata_t bktr_mem_mod = {
169         "bktr_mem",
170         bktr_mem_modevent,
171         0
172 };
173 /* The load order is First and module type is Driver to make sure bktr_mem
174    loads (and initialises) before bktr when both are loaded together */
175 DECLARE_MODULE(bktr_mem, bktr_mem_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
176 MODULE_VERSION(bktr_mem, 1);