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