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