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