Home | History | Annotate | Line # | Download | only in sun3
      1 /*	$NetBSD: mm_md.c,v 1.3 2013/09/07 15:56:11 tsutsui Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1990, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * the Systems Programming Group of the University of Utah Computer
      9  * Science Department.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	from: @(#)mem.c	8.3 (Berkeley) 1/12/94
     36  */
     37 
     38 /*
     39  * Copyright (c) 1994, 1995 Gordon W. Ross
     40  * Copyright (c) 1993 Adam Glass
     41  * Copyright (c) 1988 University of Utah.
     42  *
     43  * This code is derived from software contributed to Berkeley by
     44  * the Systems Programming Group of the University of Utah Computer
     45  * Science Department.
     46  *
     47  * Redistribution and use in source and binary forms, with or without
     48  * modification, are permitted provided that the following conditions
     49  * are met:
     50  * 1. Redistributions of source code must retain the above copyright
     51  *    notice, this list of conditions and the following disclaimer.
     52  * 2. Redistributions in binary form must reproduce the above copyright
     53  *    notice, this list of conditions and the following disclaimer in the
     54  *    documentation and/or other materials provided with the distribution.
     55  * 3. All advertising materials mentioning features or use of this software
     56  *    must display the following acknowledgement:
     57  *	This product includes software developed by the University of
     58  *	California, Berkeley and its contributors.
     59  * 4. Neither the name of the University nor the names of its contributors
     60  *    may be used to endorse or promote products derived from this software
     61  *    without specific prior written permission.
     62  *
     63  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     64  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     65  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     66  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     67  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     68  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     69  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     70  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     71  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     72  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     73  * SUCH DAMAGE.
     74  *
     75  *	from: @(#)mem.c	8.3 (Berkeley) 1/12/94
     76  */
     77 
     78 #include <sys/cdefs.h>
     79 __KERNEL_RCSID(0, "$NetBSD: mm_md.c,v 1.3 2013/09/07 15:56:11 tsutsui Exp $");
     80 
     81 #include <sys/param.h>
     82 #include <sys/errno.h>
     83 #include <uvm/uvm_extern.h>
     84 #include <machine/eeprom.h>
     85 #include <machine/leds.h>
     86 #include <machine/pmap.h>
     87 #include <dev/mm.h>
     88 
     89 #define DEV_VME16D16	5	/* minor device 5 is /dev/vme16d16 */
     90 #define DEV_VME24D16	6	/* minor device 6 is /dev/vme24d16 */
     91 #define DEV_VME32D16	7	/* minor device 7 is /dev/vme32d16 */
     92 #define DEV_VME16D32	8	/* minor device 8 is /dev/vme16d32 */
     93 #define DEV_VME24D32	9	/* minor device 9 is /dev/vme24d32 */
     94 #define DEV_VME32D32	10	/* minor device 10 is /dev/vme32d32 */
     95 #define DEV_EEPROM	11	/* minor device 11 is eeprom */
     96 #define DEV_LEDS	13	/* minor device 13 is leds */
     97 
     98 int
     99 mm_md_readwrite(dev_t dev, struct uio *uio)
    100 {
    101 
    102 	switch (minor(dev)) {
    103 	case DEV_EEPROM:
    104 		return eeprom_uio(uio);
    105 	case DEV_LEDS:
    106 		return leds_uio(uio);
    107 	default:
    108 		return ENXIO;
    109 	}
    110 }
    111 
    112 paddr_t
    113 mm_md_mmap(dev_t dev, off_t off, int prot)
    114 {
    115 
    116 	switch (minor(dev)) {
    117 	case DEV_VME16D16:
    118 		if (off & 0xffff0000)
    119 			return -1;
    120 		off |= 0xff0000;
    121 		/* fall through */
    122 	case DEV_VME24D16:
    123 		if (off & 0xff000000)
    124 			return -1;
    125 		off |= 0xff000000;
    126 		/* fall through */
    127 	case DEV_VME32D16:
    128 		return (off | PMAP_VME16);
    129 
    130 	case DEV_VME16D32:
    131 		if (off & 0xffff0000)
    132 			return -1;
    133 		off |= 0xff0000;
    134 		/* fall through */
    135 	case DEV_VME24D32:
    136 		if (off & 0xff000000)
    137 			return -1;
    138 		off |= 0xff000000;
    139 		/* fall through */
    140 	case DEV_VME32D32:
    141 		return off | PMAP_VME32;
    142 	default:
    143 		return -1;
    144 	}
    145 }
    146