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