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