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