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