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