mm_md.c revision 1.2 1 /* $NetBSD: mm_md.c,v 1.2 2011/06/12 03:35:47 rmind 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.2 2011/06/12 03:35:47 rmind Exp $");
80
81 #include <sys/param.h>
82 #include <sys/errno.h>
83 #include <uvm/uvm_extern.h>
84 #include <machine/leds.h>
85 #include <machine/pmap.h>
86 #include <dev/mm.h>
87
88 #define DEV_VME16D16 5 /* minor device 5 is /dev/vme16d16 */
89 #define DEV_VME24D16 6 /* minor device 6 is /dev/vme24d16 */
90 #define DEV_EEPROM 11 /* minor device 11 is eeprom */
91 #define DEV_LEDS 13 /* minor device 13 is leds */
92
93 int
94 mm_md_physacc(paddr_t pa, vm_prot_t prot)
95 {
96
97 /* Allow access only in "managed" RAM. */
98 if (pa < avail_start || pa >= avail_end)
99 return EFAULT;
100 return 0;
101 }
102
103 bool
104 mm_md_direct_mapped_phys(paddr_t paddr, vaddr_t *vaddr)
105 {
106
107 if (paddr >= avail_start)
108 return false;
109 *vaddr = paddr;
110 return true;
111 }
112
113 /*
114 * Allow access to the PROM mapping similiar to uvm_kernacc().
115 */
116 int
117 mm_md_kernacc(void *ptr, vm_prot_t prot, bool *handled)
118 {
119
120 if ((vaddr_t)ptr < SUN2_PROM_BASE || (vaddr_t)ptr > SUN2_MONEND) {
121 *handled = false;
122 return 0;
123 }
124
125 *handled = true;
126 /* Read in the PROM itself is OK, write not. */
127 if ((prot & VM_PROT_WRITE) == 0)
128 return 0;
129 return EFAULT;
130 }
131
132 int
133 mm_md_readwrite(dev_t dev, struct uio *uio)
134 {
135
136 switch (minor(dev)) {
137 case DEV_LEDS:
138 return leds_uio(uio);
139 default:
140 return ENXIO;
141 }
142 }
143
144 paddr_t
145 mm_md_mmap(dev_t dev, off_t off, int prot)
146 {
147
148 switch (minor(dev)) {
149 case DEV_VME16D16:
150 if (off & 0xffff0000)
151 return -1;
152 off |= 0xff0000;
153 /* fall through */
154 case DEV_VME24D16:
155 if (off & 0xff000000)
156 return -1;
157 return (off | (off & 0x800000 ? PMAP_VME8: PMAP_VME0));
158 default:
159 return (-1);
160 }
161 }
162