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