| @@ -1,2185 +1,2197 @@ | | | @@ -1,2185 +1,2197 @@ |
1 | /* $NetBSD: machdep.c,v 1.293 2009/05/16 17:01:15 cegger Exp $ */ | | 1 | /* $NetBSD: machdep.c,v 1.294 2009/05/26 03:30:24 macallan Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, | | 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, |
9 | * NASA Ames Research Center. | | 9 | * NASA Ames Research Center. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
15 | * notice, this list of conditions and the following disclaimer. | | 15 | * notice, this list of conditions and the following disclaimer. |
16 | * 2. Redistributions in binary form must reproduce the above copyright | | 16 | * 2. Redistributions in binary form must reproduce the above copyright |
17 | * notice, this list of conditions and the following disclaimer in the | | 17 | * notice, this list of conditions and the following disclaimer in the |
18 | * documentation and/or other materials provided with the distribution. | | 18 | * documentation and/or other materials provided with the distribution. |
19 | * | | 19 | * |
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
30 | * POSSIBILITY OF SUCH DAMAGE. | | 30 | * POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | /* | | 33 | /* |
34 | * Copyright (c) 1992, 1993 | | 34 | * Copyright (c) 1992, 1993 |
35 | * The Regents of the University of California. All rights reserved. | | 35 | * The Regents of the University of California. All rights reserved. |
36 | * | | 36 | * |
37 | * This software was developed by the Computer Systems Engineering group | | 37 | * This software was developed by the Computer Systems Engineering group |
38 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and | | 38 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and |
39 | * contributed to Berkeley. | | 39 | * contributed to Berkeley. |
40 | * | | 40 | * |
41 | * All advertising materials mentioning features or use of this software | | 41 | * All advertising materials mentioning features or use of this software |
42 | * must display the following acknowledgement: | | 42 | * must display the following acknowledgement: |
43 | * This product includes software developed by the University of | | 43 | * This product includes software developed by the University of |
44 | * California, Lawrence Berkeley Laboratory. | | 44 | * California, Lawrence Berkeley Laboratory. |
45 | * | | 45 | * |
46 | * Redistribution and use in source and binary forms, with or without | | 46 | * Redistribution and use in source and binary forms, with or without |
47 | * modification, are permitted provided that the following conditions | | 47 | * modification, are permitted provided that the following conditions |
48 | * are met: | | 48 | * are met: |
49 | * 1. Redistributions of source code must retain the above copyright | | 49 | * 1. Redistributions of source code must retain the above copyright |
50 | * notice, this list of conditions and the following disclaimer. | | 50 | * notice, this list of conditions and the following disclaimer. |
51 | * 2. Redistributions in binary form must reproduce the above copyright | | 51 | * 2. Redistributions in binary form must reproduce the above copyright |
52 | * notice, this list of conditions and the following disclaimer in the | | 52 | * notice, this list of conditions and the following disclaimer in the |
53 | * documentation and/or other materials provided with the distribution. | | 53 | * documentation and/or other materials provided with the distribution. |
54 | * 3. Neither the name of the University nor the names of its contributors | | 54 | * 3. Neither the name of the University nor the names of its contributors |
55 | * may be used to endorse or promote products derived from this software | | 55 | * may be used to endorse or promote products derived from this software |
56 | * without specific prior written permission. | | 56 | * without specific prior written permission. |
57 | * | | 57 | * |
58 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 58 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
59 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 59 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
61 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 61 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
68 | * SUCH DAMAGE. | | 68 | * SUCH DAMAGE. |
69 | * | | 69 | * |
70 | * @(#)machdep.c 8.6 (Berkeley) 1/14/94 | | 70 | * @(#)machdep.c 8.6 (Berkeley) 1/14/94 |
71 | */ | | 71 | */ |
72 | | | 72 | |
73 | #include <sys/cdefs.h> | | 73 | #include <sys/cdefs.h> |
74 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.293 2009/05/16 17:01:15 cegger Exp $"); | | 74 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.294 2009/05/26 03:30:24 macallan Exp $"); |
75 | | | 75 | |
76 | #include "opt_compat_netbsd.h" | | 76 | #include "opt_compat_netbsd.h" |
77 | #include "opt_compat_sunos.h" | | 77 | #include "opt_compat_sunos.h" |
78 | #include "opt_sparc_arch.h" | | 78 | #include "opt_sparc_arch.h" |
79 | #include "opt_modular.h" | | 79 | #include "opt_modular.h" |
80 | #include "opt_multiprocessor.h" | | 80 | #include "opt_multiprocessor.h" |
81 | | | 81 | |
82 | #include <sys/param.h> | | 82 | #include <sys/param.h> |
83 | #include <sys/signal.h> | | 83 | #include <sys/signal.h> |
84 | #include <sys/signalvar.h> | | 84 | #include <sys/signalvar.h> |
85 | #include <sys/proc.h> | | 85 | #include <sys/proc.h> |
86 | #include <sys/user.h> | | 86 | #include <sys/user.h> |
87 | #include <sys/extent.h> | | 87 | #include <sys/extent.h> |
88 | #include <sys/savar.h> | | 88 | #include <sys/savar.h> |
89 | #include <sys/buf.h> | | 89 | #include <sys/buf.h> |
90 | #include <sys/device.h> | | 90 | #include <sys/device.h> |
91 | #include <sys/reboot.h> | | 91 | #include <sys/reboot.h> |
92 | #include <sys/systm.h> | | 92 | #include <sys/systm.h> |
93 | #include <sys/kernel.h> | | 93 | #include <sys/kernel.h> |
94 | #include <sys/conf.h> | | 94 | #include <sys/conf.h> |
95 | #include <sys/file.h> | | 95 | #include <sys/file.h> |
96 | #include <sys/malloc.h> | | 96 | #include <sys/malloc.h> |
97 | #include <sys/mbuf.h> | | 97 | #include <sys/mbuf.h> |
98 | #include <sys/mount.h> | | 98 | #include <sys/mount.h> |
99 | #include <sys/msgbuf.h> | | 99 | #include <sys/msgbuf.h> |
100 | #include <sys/syscallargs.h> | | 100 | #include <sys/syscallargs.h> |
101 | #include <sys/exec.h> | | 101 | #include <sys/exec.h> |
102 | #include <sys/ucontext.h> | | 102 | #include <sys/ucontext.h> |
103 | #include <sys/simplelock.h> | | 103 | #include <sys/simplelock.h> |
104 | #include <sys/module.h> | | 104 | #include <sys/module.h> |
105 | | | 105 | |
106 | #include <uvm/uvm.h> /* we use uvm.kernel_object */ | | 106 | #include <uvm/uvm.h> /* we use uvm.kernel_object */ |
107 | | | 107 | |
108 | #include <sys/sysctl.h> | | 108 | #include <sys/sysctl.h> |
109 | | | 109 | |
110 | #ifdef COMPAT_13 | | 110 | #ifdef COMPAT_13 |
111 | #include <compat/sys/signal.h> | | 111 | #include <compat/sys/signal.h> |
112 | #include <compat/sys/signalvar.h> | | 112 | #include <compat/sys/signalvar.h> |
113 | #endif | | 113 | #endif |
114 | | | 114 | |
115 | #define _SPARC_BUS_DMA_PRIVATE | | 115 | #define _SPARC_BUS_DMA_PRIVATE |
116 | #include <machine/autoconf.h> | | 116 | #include <machine/autoconf.h> |
117 | #include <machine/bus.h> | | 117 | #include <machine/bus.h> |
118 | #include <machine/frame.h> | | 118 | #include <machine/frame.h> |
119 | #include <machine/cpu.h> | | 119 | #include <machine/cpu.h> |
120 | #include <machine/pmap.h> | | 120 | #include <machine/pmap.h> |
121 | #include <machine/oldmon.h> | | 121 | #include <machine/oldmon.h> |
122 | #include <machine/bsd_openprom.h> | | 122 | #include <machine/bsd_openprom.h> |
123 | #include <machine/bootinfo.h> | | 123 | #include <machine/bootinfo.h> |
124 | | | 124 | |
125 | #include <sparc/sparc/asm.h> | | 125 | #include <sparc/sparc/asm.h> |
126 | #include <sparc/sparc/cache.h> | | 126 | #include <sparc/sparc/cache.h> |
127 | #include <sparc/sparc/vaddrs.h> | | 127 | #include <sparc/sparc/vaddrs.h> |
128 | #include <sparc/sparc/cpuvar.h> | | 128 | #include <sparc/sparc/cpuvar.h> |
129 | | | 129 | |
130 | #include "fb.h" | | 130 | #include "fb.h" |
131 | #include "power.h" | | 131 | #include "power.h" |
132 | | | 132 | |
133 | #if NPOWER > 0 | | 133 | #if NPOWER > 0 |
134 | #include <sparc/dev/power.h> | | 134 | #include <sparc/dev/power.h> |
135 | #endif | | 135 | #endif |
136 | | | 136 | |
137 | struct vm_map *mb_map = NULL; | | 137 | struct vm_map *mb_map = NULL; |
138 | extern paddr_t avail_end; | | 138 | extern paddr_t avail_end; |
139 | | | 139 | |
140 | int physmem; | | 140 | int physmem; |
141 | | | 141 | |
142 | struct simplelock fpulock = SIMPLELOCK_INITIALIZER; | | 142 | struct simplelock fpulock = SIMPLELOCK_INITIALIZER; |
143 | | | 143 | |
144 | /* | | 144 | /* |
145 | * safepri is a safe priority for sleep to set for a spin-wait | | 145 | * safepri is a safe priority for sleep to set for a spin-wait |
146 | * during autoconfiguration or after a panic. | | 146 | * during autoconfiguration or after a panic. |
147 | */ | | 147 | */ |
148 | int safepri = 0; | | 148 | int safepri = 0; |
149 | | | 149 | |
150 | /* | | 150 | /* |
151 | * dvmamap24 is used to manage DVMA memory for devices that have the upper | | 151 | * dvmamap24 is used to manage DVMA memory for devices that have the upper |
152 | * eight address bits wired to all-ones (e.g. `le' and `ie') | | 152 | * eight address bits wired to all-ones (e.g. `le' and `ie') |
153 | */ | | 153 | */ |
154 | struct extent *dvmamap24; | | 154 | struct extent *dvmamap24; |
155 | | | 155 | |
156 | void dumpsys(void); | | 156 | void dumpsys(void); |
157 | void stackdump(void); | | 157 | void stackdump(void); |
158 | | | 158 | |
159 | /* | | 159 | /* |
160 | * Machine-dependent startup code | | 160 | * Machine-dependent startup code |
161 | */ | | 161 | */ |
162 | void | | 162 | void |
163 | cpu_startup(void) | | 163 | cpu_startup(void) |
164 | { | | 164 | { |
165 | #ifdef DEBUG | | 165 | #ifdef DEBUG |
166 | extern int pmapdebug; | | 166 | extern int pmapdebug; |
167 | int opmapdebug = pmapdebug; | | 167 | int opmapdebug = pmapdebug; |
168 | #endif | | 168 | #endif |
169 | vaddr_t minaddr, maxaddr; | | 169 | vaddr_t minaddr, maxaddr; |
170 | vsize_t size; | | 170 | vsize_t size; |
171 | paddr_t pa; | | 171 | paddr_t pa; |
172 | char pbuf[9]; | | 172 | char pbuf[9]; |
173 | | | 173 | |
174 | #ifdef DEBUG | | 174 | #ifdef DEBUG |
175 | pmapdebug = 0; | | 175 | pmapdebug = 0; |
176 | #endif | | 176 | #endif |
177 | | | 177 | |
178 | /* XXX */ | | 178 | /* XXX */ |
179 | if (lwp0.l_addr && lwp0.l_addr->u_pcb.pcb_psr == 0) | | 179 | if (lwp0.l_addr && lwp0.l_addr->u_pcb.pcb_psr == 0) |
180 | lwp0.l_addr->u_pcb.pcb_psr = getpsr(); | | 180 | lwp0.l_addr->u_pcb.pcb_psr = getpsr(); |
181 | | | 181 | |
182 | /* | | 182 | /* |
183 | * Re-map the message buffer from its temporary address | | 183 | * Re-map the message buffer from its temporary address |
184 | * at KERNBASE to MSGBUF_VA. | | 184 | * at KERNBASE to MSGBUF_VA. |
185 | */ | | 185 | */ |
186 | #if !defined(MSGBUFSIZE) || MSGBUFSIZE <= 8192 | | 186 | #if !defined(MSGBUFSIZE) || MSGBUFSIZE <= 8192 |
187 | /* | | 187 | /* |
188 | * We use the free page(s) in front of the kernel load address. | | 188 | * We use the free page(s) in front of the kernel load address. |
189 | */ | | 189 | */ |
190 | size = 8192; | | 190 | size = 8192; |
191 | | | 191 | |
192 | /* Get physical address of the message buffer */ | | 192 | /* Get physical address of the message buffer */ |
193 | pmap_extract(pmap_kernel(), (vaddr_t)KERNBASE, &pa); | | 193 | pmap_extract(pmap_kernel(), (vaddr_t)KERNBASE, &pa); |
194 | | | 194 | |
195 | /* Invalidate the current mapping at KERNBASE. */ | | 195 | /* Invalidate the current mapping at KERNBASE. */ |
196 | pmap_kremove((vaddr_t)KERNBASE, size); | | 196 | pmap_kremove((vaddr_t)KERNBASE, size); |
197 | pmap_update(pmap_kernel()); | | 197 | pmap_update(pmap_kernel()); |
198 | | | 198 | |
199 | /* Enter the new mapping */ | | 199 | /* Enter the new mapping */ |
200 | pmap_map(MSGBUF_VA, pa, pa + size, VM_PROT_READ|VM_PROT_WRITE); | | 200 | pmap_map(MSGBUF_VA, pa, pa + size, VM_PROT_READ|VM_PROT_WRITE); |
201 | | | 201 | |
202 | /* | | 202 | /* |
203 | * Re-initialize the message buffer. | | 203 | * Re-initialize the message buffer. |
204 | */ | | 204 | */ |
205 | initmsgbuf((void *)MSGBUF_VA, size); | | 205 | initmsgbuf((void *)MSGBUF_VA, size); |
206 | #else /* MSGBUFSIZE */ | | 206 | #else /* MSGBUFSIZE */ |
207 | { | | 207 | { |
208 | struct pglist mlist; | | 208 | struct pglist mlist; |
209 | struct vm_page *m; | | 209 | struct vm_page *m; |
210 | vaddr_t va0, va; | | 210 | vaddr_t va0, va; |
211 | | | 211 | |
212 | /* | | 212 | /* |
213 | * We use the free page(s) in front of the kernel load address, | | 213 | * We use the free page(s) in front of the kernel load address, |
214 | * and then allocate some more. | | 214 | * and then allocate some more. |
215 | */ | | 215 | */ |
216 | size = round_page(MSGBUFSIZE); | | 216 | size = round_page(MSGBUFSIZE); |
217 | | | 217 | |
218 | /* Get physical address of first 8192 chunk of the message buffer */ | | 218 | /* Get physical address of first 8192 chunk of the message buffer */ |
219 | pmap_extract(pmap_kernel(), (vaddr_t)KERNBASE, &pa); | | 219 | pmap_extract(pmap_kernel(), (vaddr_t)KERNBASE, &pa); |
220 | | | 220 | |
221 | /* Allocate additional physical pages */ | | 221 | /* Allocate additional physical pages */ |
222 | if (uvm_pglistalloc(size - 8192, | | 222 | if (uvm_pglistalloc(size - 8192, |
223 | vm_first_phys, vm_first_phys+vm_num_phys, | | 223 | vm_first_phys, vm_first_phys+vm_num_phys, |
224 | 0, 0, &mlist, 1, 0) != 0) | | 224 | 0, 0, &mlist, 1, 0) != 0) |
225 | panic("cpu_start: no memory for message buffer"); | | 225 | panic("cpu_start: no memory for message buffer"); |
226 | | | 226 | |
227 | /* Invalidate the current mapping at KERNBASE. */ | | 227 | /* Invalidate the current mapping at KERNBASE. */ |
228 | pmap_kremove((vaddr_t)KERNBASE, 8192); | | 228 | pmap_kremove((vaddr_t)KERNBASE, 8192); |
229 | pmap_update(pmap_kernel()); | | 229 | pmap_update(pmap_kernel()); |
230 | | | 230 | |
231 | /* Allocate virtual memory space */ | | 231 | /* Allocate virtual memory space */ |
232 | va0 = va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY); | | 232 | va0 = va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY); |
233 | if (va == 0) | | 233 | if (va == 0) |
234 | panic("cpu_start: no virtual memory for message buffer"); | | 234 | panic("cpu_start: no virtual memory for message buffer"); |
235 | | | 235 | |
236 | /* Map first 8192 */ | | 236 | /* Map first 8192 */ |
237 | while (va < va0 + 8192) { | | 237 | while (va < va0 + 8192) { |
238 | pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); | | 238 | pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); |
239 | pa += PAGE_SIZE; | | 239 | pa += PAGE_SIZE; |
240 | va += PAGE_SIZE; | | 240 | va += PAGE_SIZE; |
241 | } | | 241 | } |
242 | pmap_update(pmap_kernel()); | | 242 | pmap_update(pmap_kernel()); |
243 | | | 243 | |
244 | /* Map the rest of the pages */ | | 244 | /* Map the rest of the pages */ |
245 | TAILQ_FOREACH(m, &mlist ,pageq.queue) { | | 245 | TAILQ_FOREACH(m, &mlist ,pageq.queue) { |
246 | if (va >= va0 + size) | | 246 | if (va >= va0 + size) |
247 | panic("cpu_start: memory buffer size botch"); | | 247 | panic("cpu_start: memory buffer size botch"); |
248 | pa = VM_PAGE_TO_PHYS(m); | | 248 | pa = VM_PAGE_TO_PHYS(m); |
249 | pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); | | 249 | pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); |
250 | va += PAGE_SIZE; | | 250 | va += PAGE_SIZE; |
251 | } | | 251 | } |
252 | pmap_update(pmap_kernel()); | | 252 | pmap_update(pmap_kernel()); |
253 | | | 253 | |
254 | /* | | 254 | /* |
255 | * Re-initialize the message buffer. | | 255 | * Re-initialize the message buffer. |
256 | */ | | 256 | */ |
257 | initmsgbuf((void *)va0, size); | | 257 | initmsgbuf((void *)va0, size); |
258 | } | | 258 | } |
259 | #endif /* MSGBUFSIZE */ | | 259 | #endif /* MSGBUFSIZE */ |
260 | | | 260 | |
261 | /* | | 261 | /* |
262 | * Good {morning,afternoon,evening,night}. | | 262 | * Good {morning,afternoon,evening,night}. |
263 | */ | | 263 | */ |
264 | printf("%s%s", copyright, version); | | 264 | printf("%s%s", copyright, version); |
265 | /*identifycpu();*/ | | 265 | /*identifycpu();*/ |
266 | format_bytes(pbuf, sizeof(pbuf), ctob(physmem)); | | 266 | format_bytes(pbuf, sizeof(pbuf), ctob(physmem)); |
267 | printf("total memory = %s\n", pbuf); | | 267 | printf("total memory = %s\n", pbuf); |
268 | | | 268 | |
269 | /* | | 269 | /* |
270 | * Tune buffer cache variables based on the capabilities of the MMU | | 270 | * Tune buffer cache variables based on the capabilities of the MMU |
271 | * to cut down on VM space allocated for the buffer caches that | | 271 | * to cut down on VM space allocated for the buffer caches that |
272 | * would lead to MMU resource shortage. | | 272 | * would lead to MMU resource shortage. |
273 | */ | | 273 | */ |
274 | if (CPU_ISSUN4 || CPU_ISSUN4C) { | | 274 | if (CPU_ISSUN4 || CPU_ISSUN4C) { |
275 | /* Clip UBC windows */ | | 275 | /* Clip UBC windows */ |
276 | if (cpuinfo.mmu_nsegment <= 128) { | | 276 | if (cpuinfo.mmu_nsegment <= 128) { |
277 | /* | | 277 | /* |
278 | * ubc_nwins and ubc_winshift control the amount | | 278 | * ubc_nwins and ubc_winshift control the amount |
279 | * of VM used by the UBC. Normally, this VM is | | 279 | * of VM used by the UBC. Normally, this VM is |
280 | * not wired in the kernel map, hence non-locked | | 280 | * not wired in the kernel map, hence non-locked |
281 | * `PMEGs' (see pmap.c) are used for this space. | | 281 | * `PMEGs' (see pmap.c) are used for this space. |
282 | * We still limit possible fragmentation to prevent | | 282 | * We still limit possible fragmentation to prevent |
283 | * the occasional wired UBC mappings from tying up | | 283 | * the occasional wired UBC mappings from tying up |
284 | * too many PMEGs. | | 284 | * too many PMEGs. |
285 | * | | 285 | * |
286 | * Set the upper limit to 9 segments (default | | 286 | * Set the upper limit to 9 segments (default |
287 | * winshift = 13). | | 287 | * winshift = 13). |
288 | */ | | 288 | */ |
289 | ubc_nwins = 512; | | 289 | ubc_nwins = 512; |
290 | | | 290 | |
291 | /* | | 291 | /* |
292 | * buf_setvalimit() allocates a submap for buffer | | 292 | * buf_setvalimit() allocates a submap for buffer |
293 | * allocation. We use it to limit the number of locked | | 293 | * allocation. We use it to limit the number of locked |
294 | * `PMEGs' (see pmap.c) dedicated to the buffer cache. | | 294 | * `PMEGs' (see pmap.c) dedicated to the buffer cache. |
295 | * | | 295 | * |
296 | * Set the upper limit to 12 segments (3MB), which | | 296 | * Set the upper limit to 12 segments (3MB), which |
297 | * corresponds approximately to the size of the | | 297 | * corresponds approximately to the size of the |
298 | * traditional 5% rule (assuming a maximum 64MB of | | 298 | * traditional 5% rule (assuming a maximum 64MB of |
299 | * memory in small sun4c machines). | | 299 | * memory in small sun4c machines). |
300 | */ | | 300 | */ |
301 | buf_setvalimit(12 * 256*1024); | | 301 | buf_setvalimit(12 * 256*1024); |
302 | } | | 302 | } |
303 | | | 303 | |
304 | /* Clip max data & stack to avoid running into the MMU hole */ | | 304 | /* Clip max data & stack to avoid running into the MMU hole */ |
305 | #if MAXDSIZ > 256*1024*1024 | | 305 | #if MAXDSIZ > 256*1024*1024 |
306 | maxdmap = 256*1024*1024; | | 306 | maxdmap = 256*1024*1024; |
307 | #endif | | 307 | #endif |
308 | #if MAXSSIZ > 256*1024*1024 | | 308 | #if MAXSSIZ > 256*1024*1024 |
309 | maxsmap = 256*1024*1024; | | 309 | maxsmap = 256*1024*1024; |
310 | #endif | | 310 | #endif |
311 | } | | 311 | } |
312 | | | 312 | |
313 | minaddr = 0; | | 313 | minaddr = 0; |
314 | if (CPU_ISSUN4 || CPU_ISSUN4C) { | | 314 | if (CPU_ISSUN4 || CPU_ISSUN4C) { |
315 | /* | | 315 | /* |
316 | * Allocate DMA map for 24-bit devices (le, ie) | | 316 | * Allocate DMA map for 24-bit devices (le, ie) |
317 | * [dvma_base - dvma_end] is for VME devices.. | | 317 | * [dvma_base - dvma_end] is for VME devices.. |
318 | */ | | 318 | */ |
319 | dvmamap24 = extent_create("dvmamap24", | | 319 | dvmamap24 = extent_create("dvmamap24", |
320 | D24_DVMA_BASE, D24_DVMA_END, | | 320 | D24_DVMA_BASE, D24_DVMA_END, |
321 | M_DEVBUF, 0, 0, EX_NOWAIT); | | 321 | M_DEVBUF, 0, 0, EX_NOWAIT); |
322 | if (dvmamap24 == NULL) | | 322 | if (dvmamap24 == NULL) |
323 | panic("unable to allocate DVMA map"); | | 323 | panic("unable to allocate DVMA map"); |
324 | } | | 324 | } |
325 | | | 325 | |
326 | /* | | 326 | /* |
327 | * Finally, allocate mbuf cluster submap. | | 327 | * Finally, allocate mbuf cluster submap. |
328 | */ | | 328 | */ |
329 | mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, | | 329 | mb_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, |
330 | nmbclusters * mclbytes, VM_MAP_INTRSAFE, false, NULL); | | 330 | nmbclusters * mclbytes, VM_MAP_INTRSAFE, false, NULL); |
331 | | | 331 | |
332 | #ifdef DEBUG | | 332 | #ifdef DEBUG |
333 | pmapdebug = opmapdebug; | | 333 | pmapdebug = opmapdebug; |
334 | #endif | | 334 | #endif |
335 | format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free)); | | 335 | format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free)); |
336 | printf("avail memory = %s\n", pbuf); | | 336 | printf("avail memory = %s\n", pbuf); |
337 | | | 337 | |
338 | pmap_redzone(); | | 338 | pmap_redzone(); |
339 | } | | 339 | } |
340 | | | 340 | |
341 | /* | | 341 | /* |
342 | * Set up registers on exec. | | 342 | * Set up registers on exec. |
343 | * | | 343 | * |
344 | * XXX this entire mess must be fixed | | 344 | * XXX this entire mess must be fixed |
345 | */ | | 345 | */ |
346 | /* ARGSUSED */ | | 346 | /* ARGSUSED */ |
347 | void | | 347 | void |
348 | setregs(struct lwp *l, struct exec_package *pack, u_long stack) | | 348 | setregs(struct lwp *l, struct exec_package *pack, u_long stack) |
349 | { | | 349 | { |
350 | struct trapframe *tf = l->l_md.md_tf; | | 350 | struct trapframe *tf = l->l_md.md_tf; |
351 | struct fpstate *fs; | | 351 | struct fpstate *fs; |
352 | int psr; | | 352 | int psr; |
353 | | | 353 | |
354 | /* Don't allow unaligned data references by default */ | | 354 | /* Don't allow unaligned data references by default */ |
355 | l->l_proc->p_md.md_flags &= ~MDP_FIXALIGN; | | 355 | l->l_proc->p_md.md_flags &= ~MDP_FIXALIGN; |
356 | | | 356 | |
357 | /* | | 357 | /* |
358 | * Set the registers to 0 except for: | | 358 | * Set the registers to 0 except for: |
359 | * %o6: stack pointer, built in exec()) | | 359 | * %o6: stack pointer, built in exec()) |
360 | * %psr: (retain CWP and PSR_S bits) | | 360 | * %psr: (retain CWP and PSR_S bits) |
361 | * %g1: address of p->p_psstr (used by crt0) | | 361 | * %g1: address of p->p_psstr (used by crt0) |
362 | * %pc,%npc: entry point of program | | 362 | * %pc,%npc: entry point of program |
363 | */ | | 363 | */ |
364 | psr = tf->tf_psr & (PSR_S | PSR_CWP); | | 364 | psr = tf->tf_psr & (PSR_S | PSR_CWP); |
365 | if ((fs = l->l_md.md_fpstate) != NULL) { | | 365 | if ((fs = l->l_md.md_fpstate) != NULL) { |
366 | struct cpu_info *cpi; | | 366 | struct cpu_info *cpi; |
367 | int s; | | 367 | int s; |
368 | /* | | 368 | /* |
369 | * We hold an FPU state. If we own *some* FPU chip state | | 369 | * We hold an FPU state. If we own *some* FPU chip state |
370 | * we must get rid of it, and the only way to do that is | | 370 | * we must get rid of it, and the only way to do that is |
371 | * to save it. In any case, get rid of our FPU state. | | 371 | * to save it. In any case, get rid of our FPU state. |
372 | */ | | 372 | */ |
373 | FPU_LOCK(s); | | 373 | FPU_LOCK(s); |
374 | if ((cpi = l->l_md.md_fpu) != NULL) { | | 374 | if ((cpi = l->l_md.md_fpu) != NULL) { |
375 | if (cpi->fplwp != l) | | 375 | if (cpi->fplwp != l) |
376 | panic("FPU(%d): fplwp %p", | | 376 | panic("FPU(%d): fplwp %p", |
377 | cpi->ci_cpuid, cpi->fplwp); | | 377 | cpi->ci_cpuid, cpi->fplwp); |
378 | if (l == cpuinfo.fplwp) | | 378 | if (l == cpuinfo.fplwp) |
379 | savefpstate(fs); | | 379 | savefpstate(fs); |
380 | #if defined(MULTIPROCESSOR) | | 380 | #if defined(MULTIPROCESSOR) |
381 | else | | 381 | else |
382 | XCALL1(savefpstate, fs, 1 << cpi->ci_cpuid); | | 382 | XCALL1(savefpstate, fs, 1 << cpi->ci_cpuid); |
383 | #endif | | 383 | #endif |
384 | cpi->fplwp = NULL; | | 384 | cpi->fplwp = NULL; |
385 | } | | 385 | } |
386 | l->l_md.md_fpu = NULL; | | 386 | l->l_md.md_fpu = NULL; |
387 | FPU_UNLOCK(s); | | 387 | FPU_UNLOCK(s); |
388 | free((void *)fs, M_SUBPROC); | | 388 | free((void *)fs, M_SUBPROC); |
389 | l->l_md.md_fpstate = NULL; | | 389 | l->l_md.md_fpstate = NULL; |
390 | } | | 390 | } |
391 | memset((void *)tf, 0, sizeof *tf); | | 391 | memset((void *)tf, 0, sizeof *tf); |
392 | tf->tf_psr = psr; | | 392 | tf->tf_psr = psr; |
393 | tf->tf_global[1] = (int)l->l_proc->p_psstr; | | 393 | tf->tf_global[1] = (int)l->l_proc->p_psstr; |
394 | tf->tf_pc = pack->ep_entry & ~3; | | 394 | tf->tf_pc = pack->ep_entry & ~3; |
395 | tf->tf_npc = tf->tf_pc + 4; | | 395 | tf->tf_npc = tf->tf_pc + 4; |
396 | stack -= sizeof(struct rwindow); | | 396 | stack -= sizeof(struct rwindow); |
397 | tf->tf_out[6] = stack; | | 397 | tf->tf_out[6] = stack; |
398 | } | | 398 | } |
399 | | | 399 | |
400 | #ifdef DEBUG | | 400 | #ifdef DEBUG |
401 | int sigdebug = 0; | | 401 | int sigdebug = 0; |
402 | int sigpid = 0; | | 402 | int sigpid = 0; |
403 | #define SDB_FOLLOW 0x01 | | 403 | #define SDB_FOLLOW 0x01 |
404 | #define SDB_KSTACK 0x02 | | 404 | #define SDB_KSTACK 0x02 |
405 | #define SDB_FPSTATE 0x04 | | 405 | #define SDB_FPSTATE 0x04 |
406 | #endif | | 406 | #endif |
407 | | | 407 | |
408 | /* | | 408 | /* |
409 | * machine dependent system variables. | | 409 | * machine dependent system variables. |
410 | */ | | 410 | */ |
411 | static int | | 411 | static int |
412 | sysctl_machdep_boot(SYSCTLFN_ARGS) | | 412 | sysctl_machdep_boot(SYSCTLFN_ARGS) |
413 | { | | 413 | { |
414 | struct sysctlnode node = *rnode; | | 414 | struct sysctlnode node = *rnode; |
415 | struct btinfo_kernelfile *bi_file; | | 415 | struct btinfo_kernelfile *bi_file; |
416 | const char *cp; | | 416 | const char *cp; |
417 | | | 417 | |
418 | | | 418 | |
419 | switch (node.sysctl_num) { | | 419 | switch (node.sysctl_num) { |
420 | case CPU_BOOTED_KERNEL: | | 420 | case CPU_BOOTED_KERNEL: |
421 | if ((bi_file = lookup_bootinfo(BTINFO_KERNELFILE)) != NULL) | | 421 | if ((bi_file = lookup_bootinfo(BTINFO_KERNELFILE)) != NULL) |
422 | cp = bi_file->name; | | 422 | cp = bi_file->name; |
423 | else | | 423 | else |
424 | cp = prom_getbootfile(); | | 424 | cp = prom_getbootfile(); |
425 | if (cp != NULL && cp[0] == '\0') | | 425 | if (cp != NULL && cp[0] == '\0') |
426 | cp = "netbsd"; | | 426 | cp = "netbsd"; |
427 | break; | | 427 | break; |
428 | case CPU_BOOTED_DEVICE: | | 428 | case CPU_BOOTED_DEVICE: |
429 | cp = prom_getbootpath(); | | 429 | cp = prom_getbootpath(); |
430 | break; | | 430 | break; |
431 | case CPU_BOOT_ARGS: | | 431 | case CPU_BOOT_ARGS: |
432 | cp = prom_getbootargs(); | | 432 | cp = prom_getbootargs(); |
433 | break; | | 433 | break; |
434 | default: | | 434 | default: |
435 | return (EINVAL); | | 435 | return (EINVAL); |
436 | } | | 436 | } |
437 | | | 437 | |
438 | if (cp == NULL || cp[0] == '\0') | | 438 | if (cp == NULL || cp[0] == '\0') |
439 | return (ENOENT); | | 439 | return (ENOENT); |
440 | | | 440 | |
441 | node.sysctl_data = __UNCONST(cp); | | 441 | node.sysctl_data = __UNCONST(cp); |
442 | node.sysctl_size = strlen(cp) + 1; | | 442 | node.sysctl_size = strlen(cp) + 1; |
443 | return (sysctl_lookup(SYSCTLFN_CALL(&node))); | | 443 | return (sysctl_lookup(SYSCTLFN_CALL(&node))); |
444 | } | | 444 | } |
445 | | | 445 | |
446 | SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup") | | 446 | SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup") |
447 | { | | 447 | { |
448 | | | 448 | |
449 | sysctl_createv(clog, 0, NULL, NULL, | | 449 | sysctl_createv(clog, 0, NULL, NULL, |
450 | CTLFLAG_PERMANENT, | | 450 | CTLFLAG_PERMANENT, |
451 | CTLTYPE_NODE, "machdep", NULL, | | 451 | CTLTYPE_NODE, "machdep", NULL, |
452 | NULL, 0, NULL, 0, | | 452 | NULL, 0, NULL, 0, |
453 | CTL_MACHDEP, CTL_EOL); | | 453 | CTL_MACHDEP, CTL_EOL); |
454 | | | 454 | |
455 | sysctl_createv(clog, 0, NULL, NULL, | | 455 | sysctl_createv(clog, 0, NULL, NULL, |
456 | CTLFLAG_PERMANENT, | | 456 | CTLFLAG_PERMANENT, |
457 | CTLTYPE_STRING, "booted_kernel", NULL, | | 457 | CTLTYPE_STRING, "booted_kernel", NULL, |
458 | sysctl_machdep_boot, 0, NULL, 0, | | 458 | sysctl_machdep_boot, 0, NULL, 0, |
459 | CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL); | | 459 | CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL); |
460 | sysctl_createv(clog, 0, NULL, NULL, | | 460 | sysctl_createv(clog, 0, NULL, NULL, |
461 | CTLFLAG_PERMANENT, | | 461 | CTLFLAG_PERMANENT, |
462 | CTLTYPE_STRING, "booted_device", NULL, | | 462 | CTLTYPE_STRING, "booted_device", NULL, |
463 | sysctl_machdep_boot, 0, NULL, 0, | | 463 | sysctl_machdep_boot, 0, NULL, 0, |
464 | CTL_MACHDEP, CPU_BOOTED_DEVICE, CTL_EOL); | | 464 | CTL_MACHDEP, CPU_BOOTED_DEVICE, CTL_EOL); |
465 | sysctl_createv(clog, 0, NULL, NULL, | | 465 | sysctl_createv(clog, 0, NULL, NULL, |
466 | CTLFLAG_PERMANENT, | | 466 | CTLFLAG_PERMANENT, |
467 | CTLTYPE_STRING, "boot_args", NULL, | | 467 | CTLTYPE_STRING, "boot_args", NULL, |
468 | sysctl_machdep_boot, 0, NULL, 0, | | 468 | sysctl_machdep_boot, 0, NULL, 0, |
469 | CTL_MACHDEP, CPU_BOOT_ARGS, CTL_EOL); | | 469 | CTL_MACHDEP, CPU_BOOT_ARGS, CTL_EOL); |
470 | sysctl_createv(clog, 0, NULL, NULL, | | 470 | sysctl_createv(clog, 0, NULL, NULL, |
471 | CTLFLAG_PERMANENT, | | 471 | CTLFLAG_PERMANENT, |
472 | CTLTYPE_INT, "cpu_arch", NULL, | | 472 | CTLTYPE_INT, "cpu_arch", NULL, |
473 | NULL, 0, &cpu_arch, 0, | | 473 | NULL, 0, &cpu_arch, 0, |
474 | CTL_MACHDEP, CPU_ARCH, CTL_EOL); | | 474 | CTL_MACHDEP, CPU_ARCH, CTL_EOL); |
475 | } | | 475 | } |
476 | | | 476 | |
477 | /* | | 477 | /* |
478 | * Send an interrupt to process. | | 478 | * Send an interrupt to process. |
479 | */ | | 479 | */ |
480 | struct sigframe { | | 480 | struct sigframe { |
481 | siginfo_t sf_si; | | 481 | siginfo_t sf_si; |
482 | ucontext_t sf_uc; | | 482 | ucontext_t sf_uc; |
483 | }; | | 483 | }; |
484 | | | 484 | |
485 | void | | 485 | void |
486 | sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask) | | 486 | sendsig_siginfo(const ksiginfo_t *ksi, const sigset_t *mask) |
487 | { | | 487 | { |
488 | struct lwp *l = curlwp; | | 488 | struct lwp *l = curlwp; |
489 | struct proc *p = l->l_proc; | | 489 | struct proc *p = l->l_proc; |
490 | struct sigacts *ps = p->p_sigacts; | | 490 | struct sigacts *ps = p->p_sigacts; |
491 | struct trapframe *tf; | | 491 | struct trapframe *tf; |
492 | ucontext_t uc; | | 492 | ucontext_t uc; |
493 | struct sigframe *fp; | | 493 | struct sigframe *fp; |
494 | u_int onstack, oldsp, newsp; | | 494 | u_int onstack, oldsp, newsp; |
495 | u_int catcher; | | 495 | u_int catcher; |
496 | int sig, error; | | 496 | int sig, error; |
497 | size_t ucsz; | | 497 | size_t ucsz; |
498 | | | 498 | |
499 | sig = ksi->ksi_signo; | | 499 | sig = ksi->ksi_signo; |
500 | | | 500 | |
501 | tf = l->l_md.md_tf; | | 501 | tf = l->l_md.md_tf; |
502 | oldsp = tf->tf_out[6]; | | 502 | oldsp = tf->tf_out[6]; |
503 | | | 503 | |
504 | /* | | 504 | /* |
505 | * Compute new user stack addresses, subtract off | | 505 | * Compute new user stack addresses, subtract off |
506 | * one signal frame, and align. | | 506 | * one signal frame, and align. |
507 | */ | | 507 | */ |
508 | onstack = | | 508 | onstack = |
509 | (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 && | | 509 | (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 && |
510 | (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0; | | 510 | (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0; |
511 | | | 511 | |
512 | if (onstack) | | 512 | if (onstack) |
513 | fp = (struct sigframe *) | | 513 | fp = (struct sigframe *) |
514 | ((char *)l->l_sigstk.ss_sp + | | 514 | ((char *)l->l_sigstk.ss_sp + |
515 | l->l_sigstk.ss_size); | | 515 | l->l_sigstk.ss_size); |
516 | else | | 516 | else |
517 | fp = (struct sigframe *)oldsp; | | 517 | fp = (struct sigframe *)oldsp; |
518 | | | 518 | |
519 | fp = (struct sigframe *)((int)(fp - 1) & ~7); | | 519 | fp = (struct sigframe *)((int)(fp - 1) & ~7); |
520 | | | 520 | |
521 | #ifdef DEBUG | | 521 | #ifdef DEBUG |
522 | if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) | | 522 | if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) |
523 | printf("sendsig: %s[%d] sig %d newusp %p si %p uc %p\n", | | 523 | printf("sendsig: %s[%d] sig %d newusp %p si %p uc %p\n", |
524 | p->p_comm, p->p_pid, sig, fp, &fp->sf_si, &fp->sf_uc); | | 524 | p->p_comm, p->p_pid, sig, fp, &fp->sf_si, &fp->sf_uc); |
525 | #endif | | 525 | #endif |
526 | | | 526 | |
527 | /* | | 527 | /* |
528 | * Build the signal context to be used by sigreturn. | | 528 | * Build the signal context to be used by sigreturn. |
529 | */ | | 529 | */ |
530 | uc.uc_flags = _UC_SIGMASK | | | 530 | uc.uc_flags = _UC_SIGMASK | |
531 | ((l->l_sigstk.ss_flags & SS_ONSTACK) | | 531 | ((l->l_sigstk.ss_flags & SS_ONSTACK) |
532 | ? _UC_SETSTACK : _UC_CLRSTACK); | | 532 | ? _UC_SETSTACK : _UC_CLRSTACK); |
533 | uc.uc_sigmask = *mask; | | 533 | uc.uc_sigmask = *mask; |
534 | uc.uc_link = l->l_ctxlink; | | 534 | uc.uc_link = l->l_ctxlink; |
535 | memset(&uc.uc_stack, 0, sizeof(uc.uc_stack)); | | 535 | memset(&uc.uc_stack, 0, sizeof(uc.uc_stack)); |
536 | | | 536 | |
537 | /* | | 537 | /* |
538 | * Now copy the stack contents out to user space. | | 538 | * Now copy the stack contents out to user space. |
539 | * We need to make sure that when we start the signal handler, | | 539 | * We need to make sure that when we start the signal handler, |
540 | * its %i6 (%fp), which is loaded from the newly allocated stack area, | | 540 | * its %i6 (%fp), which is loaded from the newly allocated stack area, |
541 | * joins seamlessly with the frame it was in when the signal occurred, | | 541 | * joins seamlessly with the frame it was in when the signal occurred, |
542 | * so that the debugger and _longjmp code can back up through it. | | 542 | * so that the debugger and _longjmp code can back up through it. |
543 | * Since we're calling the handler directly, allocate a full size | | 543 | * Since we're calling the handler directly, allocate a full size |
544 | * C stack frame. | | 544 | * C stack frame. |
545 | */ | | 545 | */ |
546 | sendsig_reset(l, sig); | | 546 | sendsig_reset(l, sig); |
547 | mutex_exit(p->p_lock); | | 547 | mutex_exit(p->p_lock); |
548 | newsp = (int)fp - sizeof(struct frame); | | 548 | newsp = (int)fp - sizeof(struct frame); |
549 | cpu_getmcontext(l, &uc.uc_mcontext, &uc.uc_flags); | | 549 | cpu_getmcontext(l, &uc.uc_mcontext, &uc.uc_flags); |
550 | ucsz = (int)&uc.__uc_pad - (int)&uc; | | 550 | ucsz = (int)&uc.__uc_pad - (int)&uc; |
551 | error = (copyout(&ksi->ksi_info, &fp->sf_si, sizeof ksi->ksi_info) || | | 551 | error = (copyout(&ksi->ksi_info, &fp->sf_si, sizeof ksi->ksi_info) || |
552 | copyout(&uc, &fp->sf_uc, ucsz) || | | 552 | copyout(&uc, &fp->sf_uc, ucsz) || |
553 | suword(&((struct rwindow *)newsp)->rw_in[6], oldsp)); | | 553 | suword(&((struct rwindow *)newsp)->rw_in[6], oldsp)); |
554 | mutex_enter(p->p_lock); | | 554 | mutex_enter(p->p_lock); |
555 | | | 555 | |
556 | if (error) { | | 556 | if (error) { |
557 | /* | | 557 | /* |
558 | * Process has trashed its stack; give it an illegal | | 558 | * Process has trashed its stack; give it an illegal |
559 | * instruction to halt it in its tracks. | | 559 | * instruction to halt it in its tracks. |
560 | */ | | 560 | */ |
561 | #ifdef DEBUG | | 561 | #ifdef DEBUG |
562 | if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) | | 562 | if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) |
563 | printf("sendsig: window save or copyout error\n"); | | 563 | printf("sendsig: window save or copyout error\n"); |
564 | #endif | | 564 | #endif |
565 | sigexit(l, SIGILL); | | 565 | sigexit(l, SIGILL); |
566 | /* NOTREACHED */ | | 566 | /* NOTREACHED */ |
567 | } | | 567 | } |
568 | | | 568 | |
569 | switch (ps->sa_sigdesc[sig].sd_vers) { | | 569 | switch (ps->sa_sigdesc[sig].sd_vers) { |
570 | default: | | 570 | default: |
571 | /* Unsupported trampoline version; kill the process. */ | | 571 | /* Unsupported trampoline version; kill the process. */ |
572 | sigexit(l, SIGILL); | | 572 | sigexit(l, SIGILL); |
573 | case 2: | | 573 | case 2: |
574 | /* | | 574 | /* |
575 | * Arrange to continue execution at the user's handler. | | 575 | * Arrange to continue execution at the user's handler. |
576 | * It needs a new stack pointer, a return address and | | 576 | * It needs a new stack pointer, a return address and |
577 | * three arguments: (signo, siginfo *, ucontext *). | | 577 | * three arguments: (signo, siginfo *, ucontext *). |
578 | */ | | 578 | */ |
579 | catcher = (u_int)SIGACTION(p, sig).sa_handler; | | 579 | catcher = (u_int)SIGACTION(p, sig).sa_handler; |
580 | tf->tf_pc = catcher; | | 580 | tf->tf_pc = catcher; |
581 | tf->tf_npc = catcher + 4; | | 581 | tf->tf_npc = catcher + 4; |
582 | tf->tf_out[0] = sig; | | 582 | tf->tf_out[0] = sig; |
583 | tf->tf_out[1] = (int)&fp->sf_si; | | 583 | tf->tf_out[1] = (int)&fp->sf_si; |
584 | tf->tf_out[2] = (int)&fp->sf_uc; | | 584 | tf->tf_out[2] = (int)&fp->sf_uc; |
585 | tf->tf_out[6] = newsp; | | 585 | tf->tf_out[6] = newsp; |
586 | tf->tf_out[7] = (int)ps->sa_sigdesc[sig].sd_tramp - 8; | | 586 | tf->tf_out[7] = (int)ps->sa_sigdesc[sig].sd_tramp - 8; |
587 | break; | | 587 | break; |
588 | } | | 588 | } |
589 | | | 589 | |
590 | /* Remember that we're now on the signal stack. */ | | 590 | /* Remember that we're now on the signal stack. */ |
591 | if (onstack) | | 591 | if (onstack) |
592 | l->l_sigstk.ss_flags |= SS_ONSTACK; | | 592 | l->l_sigstk.ss_flags |= SS_ONSTACK; |
593 | | | 593 | |
594 | #ifdef DEBUG | | 594 | #ifdef DEBUG |
595 | if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) | | 595 | if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid) |
596 | printf("sendsig: about to return to catcher\n"); | | 596 | printf("sendsig: about to return to catcher\n"); |
597 | #endif | | 597 | #endif |
598 | } | | 598 | } |
599 | | | 599 | |
600 | /* | | 600 | /* |
601 | * cpu_upcall: | | 601 | * cpu_upcall: |
602 | * | | 602 | * |
603 | * Send an an upcall to userland. | | 603 | * Send an an upcall to userland. |
604 | */ | | 604 | */ |
605 | void | | 605 | void |
606 | cpu_upcall(struct lwp *l, int type, int nevents, int ninterrupted, | | 606 | cpu_upcall(struct lwp *l, int type, int nevents, int ninterrupted, |
607 | void *sas, void *ap, void *sp, sa_upcall_t upcall) | | 607 | void *sas, void *ap, void *sp, sa_upcall_t upcall) |
608 | { | | 608 | { |
609 | struct trapframe *tf; | | 609 | struct trapframe *tf; |
610 | vaddr_t addr; | | 610 | vaddr_t addr; |
611 | | | 611 | |
612 | tf = l->l_md.md_tf; | | 612 | tf = l->l_md.md_tf; |
613 | addr = (vaddr_t) upcall; | | 613 | addr = (vaddr_t) upcall; |
614 | | | 614 | |
615 | /* Arguments to the upcall... */ | | 615 | /* Arguments to the upcall... */ |
616 | tf->tf_out[0] = type; | | 616 | tf->tf_out[0] = type; |
617 | tf->tf_out[1] = (vaddr_t) sas; | | 617 | tf->tf_out[1] = (vaddr_t) sas; |
618 | tf->tf_out[2] = nevents; | | 618 | tf->tf_out[2] = nevents; |
619 | tf->tf_out[3] = ninterrupted; | | 619 | tf->tf_out[3] = ninterrupted; |
620 | tf->tf_out[4] = (vaddr_t) ap; | | 620 | tf->tf_out[4] = (vaddr_t) ap; |
621 | | | 621 | |
622 | /* | | 622 | /* |
623 | * Ensure the stack is double-word aligned, and provide a | | 623 | * Ensure the stack is double-word aligned, and provide a |
624 | * C call frame. | | 624 | * C call frame. |
625 | */ | | 625 | */ |
626 | sp = (void *)(((vaddr_t)sp & ~0x7) - CCFSZ); | | 626 | sp = (void *)(((vaddr_t)sp & ~0x7) - CCFSZ); |
627 | | | 627 | |
628 | /* Arrange to begin execution at the upcall handler. */ | | 628 | /* Arrange to begin execution at the upcall handler. */ |
629 | tf->tf_pc = addr; | | 629 | tf->tf_pc = addr; |
630 | tf->tf_npc = addr + 4; | | 630 | tf->tf_npc = addr + 4; |
631 | tf->tf_out[6] = (vaddr_t) sp; | | 631 | tf->tf_out[6] = (vaddr_t) sp; |
632 | tf->tf_out[7] = -1; /* "you lose" if upcall returns */ | | 632 | tf->tf_out[7] = -1; /* "you lose" if upcall returns */ |
633 | } | | 633 | } |
634 | | | 634 | |
635 | void | | 635 | void |
636 | cpu_getmcontext(struct lwp *l, mcontext_t *mcp, unsigned int *flags) | | 636 | cpu_getmcontext(struct lwp *l, mcontext_t *mcp, unsigned int *flags) |
637 | { | | 637 | { |
638 | struct trapframe *tf = (struct trapframe *)l->l_md.md_tf; | | 638 | struct trapframe *tf = (struct trapframe *)l->l_md.md_tf; |
639 | __greg_t *r = mcp->__gregs; | | 639 | __greg_t *r = mcp->__gregs; |
640 | #ifdef FPU_CONTEXT | | 640 | #ifdef FPU_CONTEXT |
641 | __fpregset_t *f = &mcp->__fpregs; | | 641 | __fpregset_t *f = &mcp->__fpregs; |
642 | struct fpstate *fps = l->l_md.md_fpstate; | | 642 | struct fpstate *fps = l->l_md.md_fpstate; |
643 | #endif | | 643 | #endif |
644 | | | 644 | |
645 | /* | | 645 | /* |
646 | * Put the stack in a consistent state before we whack away | | 646 | * Put the stack in a consistent state before we whack away |
647 | * at it. Note that write_user_windows may just dump the | | 647 | * at it. Note that write_user_windows may just dump the |
648 | * registers into the pcb; we need them in the process's memory. | | 648 | * registers into the pcb; we need them in the process's memory. |
649 | */ | | 649 | */ |
650 | write_user_windows(); | | 650 | write_user_windows(); |
651 | if ((l->l_flag & LW_SA_SWITCHING) == 0 && rwindow_save(l)) { | | 651 | if ((l->l_flag & LW_SA_SWITCHING) == 0 && rwindow_save(l)) { |
652 | mutex_enter(l->l_proc->p_lock); | | 652 | mutex_enter(l->l_proc->p_lock); |
653 | sigexit(l, SIGILL); | | 653 | sigexit(l, SIGILL); |
654 | } | | 654 | } |
655 | | | 655 | |
656 | /* | | 656 | /* |
657 | * Get the general purpose registers | | 657 | * Get the general purpose registers |
658 | */ | | 658 | */ |
659 | r[_REG_PSR] = tf->tf_psr; | | 659 | r[_REG_PSR] = tf->tf_psr; |
660 | r[_REG_PC] = tf->tf_pc; | | 660 | r[_REG_PC] = tf->tf_pc; |
661 | r[_REG_nPC] = tf->tf_npc; | | 661 | r[_REG_nPC] = tf->tf_npc; |
662 | r[_REG_Y] = tf->tf_y; | | 662 | r[_REG_Y] = tf->tf_y; |
663 | r[_REG_G1] = tf->tf_global[1]; | | 663 | r[_REG_G1] = tf->tf_global[1]; |
664 | r[_REG_G2] = tf->tf_global[2]; | | 664 | r[_REG_G2] = tf->tf_global[2]; |
665 | r[_REG_G3] = tf->tf_global[3]; | | 665 | r[_REG_G3] = tf->tf_global[3]; |
666 | r[_REG_G4] = tf->tf_global[4]; | | 666 | r[_REG_G4] = tf->tf_global[4]; |
667 | r[_REG_G5] = tf->tf_global[5]; | | 667 | r[_REG_G5] = tf->tf_global[5]; |
668 | r[_REG_G6] = tf->tf_global[6]; | | 668 | r[_REG_G6] = tf->tf_global[6]; |
669 | r[_REG_G7] = tf->tf_global[7]; | | 669 | r[_REG_G7] = tf->tf_global[7]; |
670 | r[_REG_O0] = tf->tf_out[0]; | | 670 | r[_REG_O0] = tf->tf_out[0]; |
671 | r[_REG_O1] = tf->tf_out[1]; | | 671 | r[_REG_O1] = tf->tf_out[1]; |
672 | r[_REG_O2] = tf->tf_out[2]; | | 672 | r[_REG_O2] = tf->tf_out[2]; |
673 | r[_REG_O3] = tf->tf_out[3]; | | 673 | r[_REG_O3] = tf->tf_out[3]; |
674 | r[_REG_O4] = tf->tf_out[4]; | | 674 | r[_REG_O4] = tf->tf_out[4]; |
675 | r[_REG_O5] = tf->tf_out[5]; | | 675 | r[_REG_O5] = tf->tf_out[5]; |
676 | r[_REG_O6] = tf->tf_out[6]; | | 676 | r[_REG_O6] = tf->tf_out[6]; |
677 | r[_REG_O7] = tf->tf_out[7]; | | 677 | r[_REG_O7] = tf->tf_out[7]; |
678 | | | 678 | |
679 | *flags |= _UC_CPU; | | 679 | *flags |= _UC_CPU; |
680 | | | 680 | |
681 | #ifdef FPU_CONTEXT | | 681 | #ifdef FPU_CONTEXT |
682 | /* | | 682 | /* |
683 | * Get the floating point registers | | 683 | * Get the floating point registers |
684 | */ | | 684 | */ |
685 | memcpy(f->__fpu_regs, fps->fs_regs, sizeof(fps->fs_regs)); | | 685 | memcpy(f->__fpu_regs, fps->fs_regs, sizeof(fps->fs_regs)); |
686 | f->__fp_nqsize = sizeof(struct fp_qentry); | | 686 | f->__fp_nqsize = sizeof(struct fp_qentry); |
687 | f->__fp_nqel = fps->fs_qsize; | | 687 | f->__fp_nqel = fps->fs_qsize; |
688 | f->__fp_fsr = fps->fs_fsr; | | 688 | f->__fp_fsr = fps->fs_fsr; |
689 | if (f->__fp_q != NULL) { | | 689 | if (f->__fp_q != NULL) { |
690 | size_t sz = f->__fp_nqel * f->__fp_nqsize; | | 690 | size_t sz = f->__fp_nqel * f->__fp_nqsize; |
691 | if (sz > sizeof(fps->fs_queue)) { | | 691 | if (sz > sizeof(fps->fs_queue)) { |
692 | #ifdef DIAGNOSTIC | | 692 | #ifdef DIAGNOSTIC |
693 | printf("getcontext: fp_queue too large\n"); | | 693 | printf("getcontext: fp_queue too large\n"); |
694 | #endif | | 694 | #endif |
695 | return; | | 695 | return; |
696 | } | | 696 | } |
697 | if (copyout(fps->fs_queue, f->__fp_q, sz) != 0) { | | 697 | if (copyout(fps->fs_queue, f->__fp_q, sz) != 0) { |
698 | #ifdef DIAGNOSTIC | | 698 | #ifdef DIAGNOSTIC |
699 | printf("getcontext: copy of fp_queue failed %d\n", | | 699 | printf("getcontext: copy of fp_queue failed %d\n", |
700 | error); | | 700 | error); |
701 | #endif | | 701 | #endif |
702 | return; | | 702 | return; |
703 | } | | 703 | } |
704 | } | | 704 | } |
705 | f->fp_busy = 0; /* XXX: How do we determine that? */ | | 705 | f->fp_busy = 0; /* XXX: How do we determine that? */ |
706 | *flags |= _UC_FPU; | | 706 | *flags |= _UC_FPU; |
707 | #endif | | 707 | #endif |
708 | | | 708 | |
709 | return; | | 709 | return; |
710 | } | | 710 | } |
711 | | | 711 | |
712 | /* | | 712 | /* |
713 | * Set to mcontext specified. | | 713 | * Set to mcontext specified. |
714 | * Return to previous pc and psl as specified by | | 714 | * Return to previous pc and psl as specified by |
715 | * context left by sendsig. Check carefully to | | 715 | * context left by sendsig. Check carefully to |
716 | * make sure that the user has not modified the | | 716 | * make sure that the user has not modified the |
717 | * psl to gain improper privileges or to cause | | 717 | * psl to gain improper privileges or to cause |
718 | * a machine fault. | | 718 | * a machine fault. |
719 | * This is almost like sigreturn() and it shows. | | 719 | * This is almost like sigreturn() and it shows. |
720 | */ | | 720 | */ |
721 | int | | 721 | int |
722 | cpu_setmcontext(struct lwp *l, const mcontext_t *mcp, unsigned int flags) | | 722 | cpu_setmcontext(struct lwp *l, const mcontext_t *mcp, unsigned int flags) |
723 | { | | 723 | { |
724 | struct trapframe *tf; | | 724 | struct trapframe *tf; |
725 | const __greg_t *r = mcp->__gregs; | | 725 | const __greg_t *r = mcp->__gregs; |
726 | struct proc *p = l->l_proc; | | 726 | struct proc *p = l->l_proc; |
727 | #ifdef FPU_CONTEXT | | 727 | #ifdef FPU_CONTEXT |
728 | __fpregset_t *f = &mcp->__fpregs; | | 728 | __fpregset_t *f = &mcp->__fpregs; |
729 | struct fpstate *fps = l->l_md.md_fpstate; | | 729 | struct fpstate *fps = l->l_md.md_fpstate; |
730 | #endif | | 730 | #endif |
731 | | | 731 | |
732 | write_user_windows(); | | 732 | write_user_windows(); |
733 | if (rwindow_save(l)) { | | 733 | if (rwindow_save(l)) { |
734 | mutex_enter(p->p_lock); | | 734 | mutex_enter(p->p_lock); |
735 | sigexit(l, SIGILL); | | 735 | sigexit(l, SIGILL); |
736 | } | | 736 | } |
737 | | | 737 | |
738 | #ifdef DEBUG | | 738 | #ifdef DEBUG |
739 | if (sigdebug & SDB_FOLLOW) | | 739 | if (sigdebug & SDB_FOLLOW) |
740 | printf("__setmcontext: %s[%d], __mcontext %p\n", | | 740 | printf("__setmcontext: %s[%d], __mcontext %p\n", |
741 | l->l_proc->p_comm, l->l_proc->p_pid, mcp); | | 741 | l->l_proc->p_comm, l->l_proc->p_pid, mcp); |
742 | #endif | | 742 | #endif |
743 | | | 743 | |
744 | if (flags & _UC_CPU) { | | 744 | if (flags & _UC_CPU) { |
745 | /* Restore register context. */ | | 745 | /* Restore register context. */ |
746 | tf = (struct trapframe *)l->l_md.md_tf; | | 746 | tf = (struct trapframe *)l->l_md.md_tf; |
747 | | | 747 | |
748 | /* | | 748 | /* |
749 | * Only the icc bits in the psr are used, so it need not be | | 749 | * Only the icc bits in the psr are used, so it need not be |
750 | * verified. pc and npc must be multiples of 4. This is all | | 750 | * verified. pc and npc must be multiples of 4. This is all |
751 | * that is required; if it holds, just do it. | | 751 | * that is required; if it holds, just do it. |
752 | */ | | 752 | */ |
753 | if (((r[_REG_PC] | r[_REG_nPC]) & 3) != 0) { | | 753 | if (((r[_REG_PC] | r[_REG_nPC]) & 3) != 0) { |
754 | printf("pc or npc are not multiples of 4!\n"); | | 754 | printf("pc or npc are not multiples of 4!\n"); |
755 | return (EINVAL); | | 755 | return (EINVAL); |
756 | } | | 756 | } |
757 | | | 757 | |
758 | /* take only psr ICC field */ | | 758 | /* take only psr ICC field */ |
759 | tf->tf_psr = (tf->tf_psr & ~PSR_ICC) | | | 759 | tf->tf_psr = (tf->tf_psr & ~PSR_ICC) | |
760 | (r[_REG_PSR] & PSR_ICC); | | 760 | (r[_REG_PSR] & PSR_ICC); |
761 | tf->tf_pc = r[_REG_PC]; | | 761 | tf->tf_pc = r[_REG_PC]; |
762 | tf->tf_npc = r[_REG_nPC]; | | 762 | tf->tf_npc = r[_REG_nPC]; |
763 | tf->tf_y = r[_REG_Y]; | | 763 | tf->tf_y = r[_REG_Y]; |
764 | | | 764 | |
765 | /* Restore everything */ | | 765 | /* Restore everything */ |
766 | tf->tf_global[1] = r[_REG_G1]; | | 766 | tf->tf_global[1] = r[_REG_G1]; |
767 | tf->tf_global[2] = r[_REG_G2]; | | 767 | tf->tf_global[2] = r[_REG_G2]; |
768 | tf->tf_global[3] = r[_REG_G3]; | | 768 | tf->tf_global[3] = r[_REG_G3]; |
769 | tf->tf_global[4] = r[_REG_G4]; | | 769 | tf->tf_global[4] = r[_REG_G4]; |
770 | tf->tf_global[5] = r[_REG_G5]; | | 770 | tf->tf_global[5] = r[_REG_G5]; |
771 | tf->tf_global[6] = r[_REG_G6]; | | 771 | tf->tf_global[6] = r[_REG_G6]; |
772 | tf->tf_global[7] = r[_REG_G7]; | | 772 | tf->tf_global[7] = r[_REG_G7]; |
773 | | | 773 | |
774 | tf->tf_out[0] = r[_REG_O0]; | | 774 | tf->tf_out[0] = r[_REG_O0]; |
775 | tf->tf_out[1] = r[_REG_O1]; | | 775 | tf->tf_out[1] = r[_REG_O1]; |
776 | tf->tf_out[2] = r[_REG_O2]; | | 776 | tf->tf_out[2] = r[_REG_O2]; |
777 | tf->tf_out[3] = r[_REG_O3]; | | 777 | tf->tf_out[3] = r[_REG_O3]; |
778 | tf->tf_out[4] = r[_REG_O4]; | | 778 | tf->tf_out[4] = r[_REG_O4]; |
779 | tf->tf_out[5] = r[_REG_O5]; | | 779 | tf->tf_out[5] = r[_REG_O5]; |
780 | tf->tf_out[6] = r[_REG_O6]; | | 780 | tf->tf_out[6] = r[_REG_O6]; |
781 | tf->tf_out[7] = r[_REG_O7]; | | 781 | tf->tf_out[7] = r[_REG_O7]; |
782 | } | | 782 | } |
783 | | | 783 | |
784 | #ifdef FPU_CONTEXT | | 784 | #ifdef FPU_CONTEXT |
785 | if (flags & _UC_FPU) { | | 785 | if (flags & _UC_FPU) { |
786 | /* | | 786 | /* |
787 | * Set the floating point registers | | 787 | * Set the floating point registers |
788 | */ | | 788 | */ |
789 | int error; | | 789 | int error; |
790 | size_t sz = f->__fp_nqel * f->__fp_nqsize; | | 790 | size_t sz = f->__fp_nqel * f->__fp_nqsize; |
791 | if (sz > sizeof(fps->fs_queue)) { | | 791 | if (sz > sizeof(fps->fs_queue)) { |
792 | #ifdef DIAGNOSTIC | | 792 | #ifdef DIAGNOSTIC |
793 | printf("setmcontext: fp_queue too large\n"); | | 793 | printf("setmcontext: fp_queue too large\n"); |
794 | #endif | | 794 | #endif |
795 | return (EINVAL); | | 795 | return (EINVAL); |
796 | } | | 796 | } |
797 | memcpy(fps->fs_regs, f->__fpu_regs, sizeof(fps->fs_regs)); | | 797 | memcpy(fps->fs_regs, f->__fpu_regs, sizeof(fps->fs_regs)); |
798 | fps->fs_qsize = f->__fp_nqel; | | 798 | fps->fs_qsize = f->__fp_nqel; |
799 | fps->fs_fsr = f->__fp_fsr; | | 799 | fps->fs_fsr = f->__fp_fsr; |
800 | if (f->__fp_q != NULL) { | | 800 | if (f->__fp_q != NULL) { |
801 | if ((error = copyin(f->__fp_q, fps->fs_queue, sz)) != 0) { | | 801 | if ((error = copyin(f->__fp_q, fps->fs_queue, sz)) != 0) { |
802 | #ifdef DIAGNOSTIC | | 802 | #ifdef DIAGNOSTIC |
803 | printf("setmcontext: fp_queue copy failed\n"); | | 803 | printf("setmcontext: fp_queue copy failed\n"); |
804 | #endif | | 804 | #endif |
805 | return (error); | | 805 | return (error); |
806 | } | | 806 | } |
807 | } | | 807 | } |
808 | } | | 808 | } |
809 | #endif | | 809 | #endif |
810 | | | 810 | |
811 | mutex_enter(p->p_lock); | | 811 | mutex_enter(p->p_lock); |
812 | if (flags & _UC_SETSTACK) | | 812 | if (flags & _UC_SETSTACK) |
813 | l->l_sigstk.ss_flags |= SS_ONSTACK; | | 813 | l->l_sigstk.ss_flags |= SS_ONSTACK; |
814 | if (flags & _UC_CLRSTACK) | | 814 | if (flags & _UC_CLRSTACK) |
815 | l->l_sigstk.ss_flags &= ~SS_ONSTACK; | | 815 | l->l_sigstk.ss_flags &= ~SS_ONSTACK; |
816 | mutex_exit(p->p_lock); | | 816 | mutex_exit(p->p_lock); |
817 | | | 817 | |
818 | return (0); | | 818 | return (0); |
819 | } | | 819 | } |
820 | | | 820 | |
821 | int waittime = -1; | | 821 | int waittime = -1; |
822 | | | 822 | |
823 | void | | 823 | void |
824 | cpu_reboot(int howto, char *user_boot_string) | | 824 | cpu_reboot(int howto, char *user_boot_string) |
825 | { | | 825 | { |
826 | int i; | | 826 | int i; |
827 | char opts[4]; | | 827 | char opts[4]; |
828 | static char str[128]; | | 828 | static char str[128]; |
829 | | | 829 | |
830 | /* If system is cold, just halt. */ | | 830 | /* If system is cold, just halt. */ |
831 | if (cold) { | | 831 | if (cold) { |
832 | howto |= RB_HALT; | | 832 | howto |= RB_HALT; |
833 | goto haltsys; | | 833 | goto haltsys; |
834 | } | | 834 | } |
835 | | | 835 | |
836 | #if NFB > 0 | | 836 | #if NFB > 0 |
837 | fb_unblank(); | | 837 | fb_unblank(); |
838 | #endif | | 838 | #endif |
839 | boothowto = howto; | | 839 | boothowto = howto; |
840 | if ((howto & RB_NOSYNC) == 0 && waittime < 0) { | | 840 | if ((howto & RB_NOSYNC) == 0 && waittime < 0) { |
841 | extern struct lwp lwp0; | | 841 | extern struct lwp lwp0; |
842 | | | 842 | |
843 | /* XXX protect against curlwp->p_stats.foo refs in sync() */ | | 843 | /* XXX protect against curlwp->p_stats.foo refs in sync() */ |
844 | if (curlwp == NULL) | | 844 | if (curlwp == NULL) |
845 | curlwp = &lwp0; | | 845 | curlwp = &lwp0; |
846 | waittime = 0; | | 846 | waittime = 0; |
847 | vfs_shutdown(); | | 847 | vfs_shutdown(); |
848 | | | 848 | |
849 | /* | | 849 | /* |
850 | * If we've been adjusting the clock, the todr | | 850 | * If we've been adjusting the clock, the todr |
851 | * will be out of synch; adjust it now. | | 851 | * will be out of synch; adjust it now. |
852 | * resettodr will only do this only if inittodr() | | 852 | * resettodr will only do this only if inittodr() |
853 | * has already been called. | | 853 | * has already been called. |
854 | */ | | 854 | */ |
855 | resettodr(); | | 855 | resettodr(); |
856 | } | | 856 | } |
857 | | | 857 | |
858 | /* Disable interrupts. But still allow IPI on MP systems */ | | 858 | /* Disable interrupts. But still allow IPI on MP systems */ |
859 | if (sparc_ncpus > 1) | | 859 | if (sparc_ncpus > 1) |
860 | (void)splsched(); | | 860 | (void)splsched(); |
861 | else | | 861 | else |
862 | (void)splhigh(); | | 862 | (void)splhigh(); |
863 | | | 863 | |
864 | #if defined(MULTIPROCESSOR) | | 864 | #if defined(MULTIPROCESSOR) |
865 | /* Direct system interrupts to this CPU, since dump uses polled I/O */ | | 865 | /* Direct system interrupts to this CPU, since dump uses polled I/O */ |
866 | if (CPU_ISSUN4M) | | 866 | if (CPU_ISSUN4M) |
867 | *((u_int *)ICR_ITR) = cpuinfo.mid - 8; | | 867 | *((u_int *)ICR_ITR) = cpuinfo.mid - 8; |
868 | #endif | | 868 | #endif |
869 | | | 869 | |
870 | /* If rebooting and a dump is requested, do it. */ | | 870 | /* If rebooting and a dump is requested, do it. */ |
871 | #if 0 | | 871 | #if 0 |
872 | if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) | | 872 | if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) |
873 | #else | | 873 | #else |
874 | if (howto & RB_DUMP) | | 874 | if (howto & RB_DUMP) |
875 | #endif | | 875 | #endif |
876 | dumpsys(); | | 876 | dumpsys(); |
877 | | | 877 | |
878 | haltsys: | | 878 | haltsys: |
879 | | | 879 | |
880 | /* Run any shutdown hooks. */ | | 880 | /* Run any shutdown hooks. */ |
881 | doshutdownhooks(); | | 881 | doshutdownhooks(); |
882 | | | 882 | |
883 | pmf_system_shutdown(boothowto); | | 883 | pmf_system_shutdown(boothowto); |
884 | | | 884 | |
885 | /* If powerdown was requested, do it. */ | | 885 | /* If powerdown was requested, do it. */ |
886 | if ((howto & RB_POWERDOWN) == RB_POWERDOWN) { | | 886 | if ((howto & RB_POWERDOWN) == RB_POWERDOWN) { |
887 | prom_interpret("power-off"); | | 887 | prom_interpret("power-off"); |
888 | #if NPOWER > 0 | | 888 | #if NPOWER > 0 |
889 | /* Fall back on `power' device if the PROM can't do it */ | | 889 | /* Fall back on `power' device if the PROM can't do it */ |
890 | powerdown(); | | 890 | powerdown(); |
891 | #endif | | 891 | #endif |
892 | printf("WARNING: powerdown not supported\n"); | | 892 | printf("WARNING: powerdown not supported\n"); |
893 | /* | | 893 | /* |
894 | * RB_POWERDOWN implies RB_HALT... fall into it... | | 894 | * RB_POWERDOWN implies RB_HALT... fall into it... |
895 | */ | | 895 | */ |
896 | } | | 896 | } |
897 | | | 897 | |
898 | if (howto & RB_HALT) { | | 898 | if (howto & RB_HALT) { |
899 | #if defined(MULTIPROCESSOR) | | 899 | #if defined(MULTIPROCESSOR) |
900 | mp_halt_cpus(); | | 900 | mp_halt_cpus(); |
901 | printf("cpu%d halted\n\n", cpu_number()); | | 901 | printf("cpu%d halted\n\n", cpu_number()); |
902 | #else | | 902 | #else |
903 | printf("halted\n\n"); | | 903 | printf("halted\n\n"); |
904 | #endif | | 904 | #endif |
905 | prom_halt(); | | 905 | prom_halt(); |
906 | } | | 906 | } |
907 | | | 907 | |
908 | printf("rebooting\n\n"); | | 908 | printf("rebooting\n\n"); |
909 | | | 909 | |
910 | i = 1; | | 910 | i = 1; |
911 | if (howto & RB_SINGLE) | | 911 | if (howto & RB_SINGLE) |
912 | opts[i++] = 's'; | | 912 | opts[i++] = 's'; |
913 | if (howto & RB_KDB) | | 913 | if (howto & RB_KDB) |
914 | opts[i++] = 'd'; | | 914 | opts[i++] = 'd'; |
915 | opts[i] = '\0'; | | 915 | opts[i] = '\0'; |
916 | opts[0] = (i > 1) ? '-' : '\0'; | | 916 | opts[0] = (i > 1) ? '-' : '\0'; |
917 | | | 917 | |
918 | if (user_boot_string && *user_boot_string) { | | 918 | if (user_boot_string && *user_boot_string) { |
919 | i = strlen(user_boot_string); | | 919 | i = strlen(user_boot_string); |
920 | if (i > sizeof(str) - sizeof(opts) - 1) | | 920 | if (i > sizeof(str) - sizeof(opts) - 1) |
921 | prom_boot(user_boot_string); /* XXX */ | | 921 | prom_boot(user_boot_string); /* XXX */ |
922 | memcpy(str, user_boot_string, i); | | 922 | memcpy(str, user_boot_string, i); |
923 | if (opts[0] != '\0') | | 923 | if (opts[0] != '\0') |
924 | str[i] = ' '; | | 924 | str[i] = ' '; |
925 | } | | 925 | } |
926 | strcat(str, opts); | | 926 | strcat(str, opts); |
927 | prom_boot(str); | | 927 | prom_boot(str); |
928 | /*NOTREACHED*/ | | 928 | /*NOTREACHED*/ |
929 | } | | 929 | } |
930 | | | 930 | |
931 | uint32_t dumpmag = 0x8fca0101; /* magic number for savecore */ | | 931 | uint32_t dumpmag = 0x8fca0101; /* magic number for savecore */ |
932 | int dumpsize = 0; /* also for savecore */ | | 932 | int dumpsize = 0; /* also for savecore */ |
933 | long dumplo = 0; | | 933 | long dumplo = 0; |
934 | | | 934 | |
935 | void | | 935 | void |
936 | cpu_dumpconf(void) | | 936 | cpu_dumpconf(void) |
937 | { | | 937 | { |
938 | const struct bdevsw *bdev; | | 938 | const struct bdevsw *bdev; |
939 | int nblks, dumpblks; | | 939 | int nblks, dumpblks; |
940 | | | 940 | |
941 | if (dumpdev == NODEV) | | 941 | if (dumpdev == NODEV) |
942 | return; | | 942 | return; |
943 | bdev = bdevsw_lookup(dumpdev); | | 943 | bdev = bdevsw_lookup(dumpdev); |
944 | if (bdev == NULL || bdev->d_psize == NULL) | | 944 | if (bdev == NULL || bdev->d_psize == NULL) |
945 | return; | | 945 | return; |
946 | | | 946 | |
947 | nblks = (*bdev->d_psize)(dumpdev); | | 947 | nblks = (*bdev->d_psize)(dumpdev); |
948 | | | 948 | |
949 | dumpblks = ctod(physmem) + pmap_dumpsize(); | | 949 | dumpblks = ctod(physmem) + pmap_dumpsize(); |
950 | if (dumpblks > (nblks - ctod(1))) | | 950 | if (dumpblks > (nblks - ctod(1))) |
951 | /* | | 951 | /* |
952 | * dump size is too big for the partition. | | 952 | * dump size is too big for the partition. |
953 | * Note, we safeguard a click at the front for a | | 953 | * Note, we safeguard a click at the front for a |
954 | * possible disk label. | | 954 | * possible disk label. |
955 | */ | | 955 | */ |
956 | return; | | 956 | return; |
957 | | | 957 | |
958 | /* Put the dump at the end of the partition */ | | 958 | /* Put the dump at the end of the partition */ |
959 | dumplo = nblks - dumpblks; | | 959 | dumplo = nblks - dumpblks; |
960 | | | 960 | |
961 | /* | | 961 | /* |
962 | * savecore(8) expects dumpsize to be the number of pages | | 962 | * savecore(8) expects dumpsize to be the number of pages |
963 | * of actual core dumped (i.e. excluding the MMU stuff). | | 963 | * of actual core dumped (i.e. excluding the MMU stuff). |
964 | */ | | 964 | */ |
965 | dumpsize = physmem; | | 965 | dumpsize = physmem; |
966 | } | | 966 | } |
967 | | | 967 | |
968 | #define BYTES_PER_DUMP (32 * 1024) /* must be a multiple of pagesize */ | | 968 | #define BYTES_PER_DUMP (32 * 1024) /* must be a multiple of pagesize */ |
969 | static vaddr_t dumpspace; | | 969 | static vaddr_t dumpspace; |
970 | | | 970 | |
971 | void * | | 971 | void * |
972 | reserve_dumppages(void *p) | | 972 | reserve_dumppages(void *p) |
973 | { | | 973 | { |
974 | | | 974 | |
975 | dumpspace = (vaddr_t)p; | | 975 | dumpspace = (vaddr_t)p; |
976 | return ((char *)p + BYTES_PER_DUMP); | | 976 | return ((char *)p + BYTES_PER_DUMP); |
977 | } | | 977 | } |
978 | | | 978 | |
979 | /* | | 979 | /* |
980 | * Write a crash dump. | | 980 | * Write a crash dump. |
981 | */ | | 981 | */ |
982 | void | | 982 | void |
983 | dumpsys(void) | | 983 | dumpsys(void) |
984 | { | | 984 | { |
985 | const struct bdevsw *bdev; | | 985 | const struct bdevsw *bdev; |
986 | int psize; | | 986 | int psize; |
987 | daddr_t blkno; | | 987 | daddr_t blkno; |
988 | int (*dump)(dev_t, daddr_t, void *, size_t); | | 988 | int (*dump)(dev_t, daddr_t, void *, size_t); |
989 | int error = 0; | | 989 | int error = 0; |
990 | struct memarr *mp; | | 990 | struct memarr *mp; |
991 | int nmem; | | 991 | int nmem; |
992 | extern struct memarr pmemarr[]; | | 992 | extern struct memarr pmemarr[]; |
993 | extern int npmemarr; | | 993 | extern int npmemarr; |
994 | | | 994 | |
995 | /* copy registers to memory */ | | 995 | /* copy registers to memory */ |
996 | snapshot(cpuinfo.curpcb); | | 996 | snapshot(cpuinfo.curpcb); |
997 | stackdump(); | | 997 | stackdump(); |
998 | | | 998 | |
999 | if (dumpdev == NODEV) | | 999 | if (dumpdev == NODEV) |
1000 | return; | | 1000 | return; |
1001 | bdev = bdevsw_lookup(dumpdev); | | 1001 | bdev = bdevsw_lookup(dumpdev); |
1002 | if (bdev == NULL || bdev->d_psize == NULL) | | 1002 | if (bdev == NULL || bdev->d_psize == NULL) |
1003 | return; | | 1003 | return; |
1004 | | | 1004 | |
1005 | /* | | 1005 | /* |
1006 | * For dumps during autoconfiguration, | | 1006 | * For dumps during autoconfiguration, |
1007 | * if dump device has already configured... | | 1007 | * if dump device has already configured... |
1008 | */ | | 1008 | */ |
1009 | if (dumpsize == 0) | | 1009 | if (dumpsize == 0) |
1010 | cpu_dumpconf(); | | 1010 | cpu_dumpconf(); |
1011 | if (dumplo <= 0) { | | 1011 | if (dumplo <= 0) { |
1012 | printf("\ndump to dev %u,%u not possible\n", | | 1012 | printf("\ndump to dev %u,%u not possible\n", |
1013 | major(dumpdev), minor(dumpdev)); | | 1013 | major(dumpdev), minor(dumpdev)); |
1014 | return; | | 1014 | return; |
1015 | } | | 1015 | } |
1016 | printf("\ndumping to dev %u,%u offset %ld\n", | | 1016 | printf("\ndumping to dev %u,%u offset %ld\n", |
1017 | major(dumpdev), minor(dumpdev), dumplo); | | 1017 | major(dumpdev), minor(dumpdev), dumplo); |
1018 | | | 1018 | |
1019 | psize = (*bdev->d_psize)(dumpdev); | | 1019 | psize = (*bdev->d_psize)(dumpdev); |
1020 | printf("dump "); | | 1020 | printf("dump "); |
1021 | if (psize == -1) { | | 1021 | if (psize == -1) { |
1022 | printf("area unavailable\n"); | | 1022 | printf("area unavailable\n"); |
1023 | return; | | 1023 | return; |
1024 | } | | 1024 | } |
1025 | blkno = dumplo; | | 1025 | blkno = dumplo; |
1026 | dump = bdev->d_dump; | | 1026 | dump = bdev->d_dump; |
1027 | | | 1027 | |
1028 | error = pmap_dumpmmu(dump, blkno); | | 1028 | error = pmap_dumpmmu(dump, blkno); |
1029 | blkno += pmap_dumpsize(); | | 1029 | blkno += pmap_dumpsize(); |
1030 | | | 1030 | |
1031 | for (mp = pmemarr, nmem = npmemarr; --nmem >= 0 && error == 0; mp++) { | | 1031 | for (mp = pmemarr, nmem = npmemarr; --nmem >= 0 && error == 0; mp++) { |
1032 | unsigned i = 0, n; | | 1032 | unsigned i = 0, n; |
1033 | int maddr = mp->addr; | | 1033 | int maddr = mp->addr; |
1034 | | | 1034 | |
1035 | if (maddr == 0) { | | 1035 | if (maddr == 0) { |
1036 | /* Skip first page at physical address 0 */ | | 1036 | /* Skip first page at physical address 0 */ |
1037 | maddr += PAGE_SIZE; | | 1037 | maddr += PAGE_SIZE; |
1038 | i += PAGE_SIZE; | | 1038 | i += PAGE_SIZE; |
1039 | blkno += btodb(PAGE_SIZE); | | 1039 | blkno += btodb(PAGE_SIZE); |
1040 | } | | 1040 | } |
1041 | | | 1041 | |
1042 | for (; i < mp->len; i += n) { | | 1042 | for (; i < mp->len; i += n) { |
1043 | n = mp->len - i; | | 1043 | n = mp->len - i; |
1044 | if (n > BYTES_PER_DUMP) | | 1044 | if (n > BYTES_PER_DUMP) |
1045 | n = BYTES_PER_DUMP; | | 1045 | n = BYTES_PER_DUMP; |
1046 | | | 1046 | |
1047 | /* print out how many MBs we have dumped */ | | 1047 | /* print out how many MBs we have dumped */ |
1048 | if (i && (i % (1024*1024)) == 0) | | 1048 | if (i && (i % (1024*1024)) == 0) |
1049 | printf_nolog("%d ", i / (1024*1024)); | | 1049 | printf_nolog("%d ", i / (1024*1024)); |
1050 | | | 1050 | |
1051 | (void) pmap_map(dumpspace, maddr, maddr + n, | | 1051 | (void) pmap_map(dumpspace, maddr, maddr + n, |
1052 | VM_PROT_READ); | | 1052 | VM_PROT_READ); |
1053 | error = (*dump)(dumpdev, blkno, | | 1053 | error = (*dump)(dumpdev, blkno, |
1054 | (void *)dumpspace, (int)n); | | 1054 | (void *)dumpspace, (int)n); |
1055 | pmap_kremove(dumpspace, n); | | 1055 | pmap_kremove(dumpspace, n); |
1056 | pmap_update(pmap_kernel()); | | 1056 | pmap_update(pmap_kernel()); |
1057 | if (error) | | 1057 | if (error) |
1058 | break; | | 1058 | break; |
1059 | maddr += n; | | 1059 | maddr += n; |
1060 | blkno += btodb(n); | | 1060 | blkno += btodb(n); |
1061 | } | | 1061 | } |
1062 | } | | 1062 | } |
1063 | | | 1063 | |
1064 | switch (error) { | | 1064 | switch (error) { |
1065 | | | 1065 | |
1066 | case ENXIO: | | 1066 | case ENXIO: |
1067 | printf("device bad\n"); | | 1067 | printf("device bad\n"); |
1068 | break; | | 1068 | break; |
1069 | | | 1069 | |
1070 | case EFAULT: | | 1070 | case EFAULT: |
1071 | printf("device not ready\n"); | | 1071 | printf("device not ready\n"); |
1072 | break; | | 1072 | break; |
1073 | | | 1073 | |
1074 | case EINVAL: | | 1074 | case EINVAL: |
1075 | printf("area improper\n"); | | 1075 | printf("area improper\n"); |
1076 | break; | | 1076 | break; |
1077 | | | 1077 | |
1078 | case EIO: | | 1078 | case EIO: |
1079 | printf("i/o error\n"); | | 1079 | printf("i/o error\n"); |
1080 | break; | | 1080 | break; |
1081 | | | 1081 | |
1082 | case 0: | | 1082 | case 0: |
1083 | printf("succeeded\n"); | | 1083 | printf("succeeded\n"); |
1084 | break; | | 1084 | break; |
1085 | | | 1085 | |
1086 | default: | | 1086 | default: |
1087 | printf("error %d\n", error); | | 1087 | printf("error %d\n", error); |
1088 | break; | | 1088 | break; |
1089 | } | | 1089 | } |
1090 | } | | 1090 | } |
1091 | | | 1091 | |
1092 | /* | | 1092 | /* |
1093 | * get the fp and dump the stack as best we can. don't leave the | | 1093 | * get the fp and dump the stack as best we can. don't leave the |
1094 | * current stack page | | 1094 | * current stack page |
1095 | */ | | 1095 | */ |
1096 | void | | 1096 | void |
1097 | stackdump(void) | | 1097 | stackdump(void) |
1098 | { | | 1098 | { |
1099 | struct frame *fp = getfp(), *sfp; | | 1099 | struct frame *fp = getfp(), *sfp; |
1100 | | | 1100 | |
1101 | sfp = fp; | | 1101 | sfp = fp; |
1102 | printf("Frame pointer is at %p\n", fp); | | 1102 | printf("Frame pointer is at %p\n", fp); |
1103 | printf("Call traceback:\n"); | | 1103 | printf("Call traceback:\n"); |
1104 | while (fp && ((u_long)fp >> PGSHIFT) == ((u_long)sfp >> PGSHIFT)) { | | 1104 | while (fp && ((u_long)fp >> PGSHIFT) == ((u_long)sfp >> PGSHIFT)) { |
1105 | printf(" pc = 0x%x args = (0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) fp = %p\n", | | 1105 | printf(" pc = 0x%x args = (0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) fp = %p\n", |
1106 | fp->fr_pc, fp->fr_arg[0], fp->fr_arg[1], fp->fr_arg[2], | | 1106 | fp->fr_pc, fp->fr_arg[0], fp->fr_arg[1], fp->fr_arg[2], |
1107 | fp->fr_arg[3], fp->fr_arg[4], fp->fr_arg[5], fp->fr_arg[6], | | 1107 | fp->fr_arg[3], fp->fr_arg[4], fp->fr_arg[5], fp->fr_arg[6], |
1108 | fp->fr_fp); | | 1108 | fp->fr_fp); |
1109 | fp = fp->fr_fp; | | 1109 | fp = fp->fr_fp; |
1110 | } | | 1110 | } |
1111 | } | | 1111 | } |
1112 | | | 1112 | |
1113 | int | | 1113 | int |
1114 | cpu_exec_aout_makecmds(struct lwp *l, struct exec_package *epp) | | 1114 | cpu_exec_aout_makecmds(struct lwp *l, struct exec_package *epp) |
1115 | { | | 1115 | { |
1116 | | | 1116 | |
1117 | return (ENOEXEC); | | 1117 | return (ENOEXEC); |
1118 | } | | 1118 | } |
1119 | | | 1119 | |
1120 | #if defined(SUN4) | | 1120 | #if defined(SUN4) |
1121 | void | | 1121 | void |
1122 | oldmon_w_trace(u_long va) | | 1122 | oldmon_w_trace(u_long va) |
1123 | { | | 1123 | { |
1124 | u_long stop; | | 1124 | u_long stop; |
1125 | struct frame *fp; | | 1125 | struct frame *fp; |
1126 | | | 1126 | |
1127 | if (curlwp) | | 1127 | if (curlwp) |
1128 | printf("curlwp = %p, pid %d\n", | | 1128 | printf("curlwp = %p, pid %d\n", |
1129 | curlwp, curproc->p_pid); | | 1129 | curlwp, curproc->p_pid); |
1130 | else | | 1130 | else |
1131 | printf("no curlwp\n"); | | 1131 | printf("no curlwp\n"); |
1132 | | | 1132 | |
1133 | printf("uvm: swtch %d, trap %d, sys %d, intr %d, soft %d, faults %d\n", | | 1133 | printf("uvm: swtch %d, trap %d, sys %d, intr %d, soft %d, faults %d\n", |
1134 | uvmexp.swtch, uvmexp.traps, uvmexp.syscalls, uvmexp.intrs, | | 1134 | uvmexp.swtch, uvmexp.traps, uvmexp.syscalls, uvmexp.intrs, |
1135 | uvmexp.softs, uvmexp.faults); | | 1135 | uvmexp.softs, uvmexp.faults); |
1136 | write_user_windows(); | | 1136 | write_user_windows(); |
1137 | | | 1137 | |
1138 | #define round_up(x) (( (x) + (PAGE_SIZE-1) ) & (~(PAGE_SIZE-1)) ) | | 1138 | #define round_up(x) (( (x) + (PAGE_SIZE-1) ) & (~(PAGE_SIZE-1)) ) |
1139 | | | 1139 | |
1140 | printf("\nstack trace with sp = 0x%lx\n", va); | | 1140 | printf("\nstack trace with sp = 0x%lx\n", va); |
1141 | stop = round_up(va); | | 1141 | stop = round_up(va); |
1142 | printf("stop at 0x%lx\n", stop); | | 1142 | printf("stop at 0x%lx\n", stop); |
1143 | fp = (struct frame *) va; | | 1143 | fp = (struct frame *) va; |
1144 | while (round_up((u_long) fp) == stop) { | | 1144 | while (round_up((u_long) fp) == stop) { |
1145 | printf(" 0x%x(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) fp %p\n", fp->fr_pc, | | 1145 | printf(" 0x%x(0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) fp %p\n", fp->fr_pc, |
1146 | fp->fr_arg[0], fp->fr_arg[1], fp->fr_arg[2], fp->fr_arg[3], | | 1146 | fp->fr_arg[0], fp->fr_arg[1], fp->fr_arg[2], fp->fr_arg[3], |
1147 | fp->fr_arg[4], fp->fr_arg[5], fp->fr_arg[6], fp->fr_fp); | | 1147 | fp->fr_arg[4], fp->fr_arg[5], fp->fr_arg[6], fp->fr_fp); |
1148 | fp = fp->fr_fp; | | 1148 | fp = fp->fr_fp; |
1149 | if (fp == NULL) | | 1149 | if (fp == NULL) |
1150 | break; | | 1150 | break; |
1151 | } | | 1151 | } |
1152 | printf("end of stack trace\n"); | | 1152 | printf("end of stack trace\n"); |
1153 | } | | 1153 | } |
1154 | | | 1154 | |
1155 | void | | 1155 | void |
1156 | oldmon_w_cmd(u_long va, char *ar) | | 1156 | oldmon_w_cmd(u_long va, char *ar) |
1157 | { | | 1157 | { |
1158 | switch (*ar) { | | 1158 | switch (*ar) { |
1159 | case '\0': | | 1159 | case '\0': |
1160 | switch (va) { | | 1160 | switch (va) { |
1161 | case 0: | | 1161 | case 0: |
1162 | panic("g0 panic"); | | 1162 | panic("g0 panic"); |
1163 | case 4: | | 1163 | case 4: |
1164 | printf("w: case 4\n"); | | 1164 | printf("w: case 4\n"); |
1165 | break; | | 1165 | break; |
1166 | default: | | 1166 | default: |
1167 | printf("w: unknown case %ld\n", va); | | 1167 | printf("w: unknown case %ld\n", va); |
1168 | break; | | 1168 | break; |
1169 | } | | 1169 | } |
1170 | break; | | 1170 | break; |
1171 | case 't': | | 1171 | case 't': |
1172 | oldmon_w_trace(va); | | 1172 | oldmon_w_trace(va); |
1173 | break; | | 1173 | break; |
1174 | default: | | 1174 | default: |
1175 | printf("w: arg not allowed\n"); | | 1175 | printf("w: arg not allowed\n"); |
1176 | } | | 1176 | } |
1177 | } | | 1177 | } |
1178 | | | 1178 | |
1179 | int | | 1179 | int |
1180 | ldcontrolb(void *addr) | | 1180 | ldcontrolb(void *addr) |
1181 | { | | 1181 | { |
1182 | struct pcb *xpcb; | | 1182 | struct pcb *xpcb; |
1183 | extern struct user *proc0paddr; | | 1183 | extern struct user *proc0paddr; |
1184 | u_long saveonfault; | | 1184 | u_long saveonfault; |
1185 | int res; | | 1185 | int res; |
1186 | int s; | | 1186 | int s; |
1187 | | | 1187 | |
1188 | if (CPU_ISSUN4M || CPU_ISSUN4D) { | | 1188 | if (CPU_ISSUN4M || CPU_ISSUN4D) { |
1189 | printf("warning: ldcontrolb called on sun4m/sun4d\n"); | | 1189 | printf("warning: ldcontrolb called on sun4m/sun4d\n"); |
1190 | return 0; | | 1190 | return 0; |
1191 | } | | 1191 | } |
1192 | | | 1192 | |
1193 | s = splhigh(); | | 1193 | s = splhigh(); |
1194 | if (curlwp == NULL) | | 1194 | if (curlwp == NULL) |
1195 | xpcb = (struct pcb *)proc0paddr; | | 1195 | xpcb = (struct pcb *)proc0paddr; |
1196 | else | | 1196 | else |
1197 | xpcb = &curlwp->l_addr->u_pcb; | | 1197 | xpcb = &curlwp->l_addr->u_pcb; |
1198 | | | 1198 | |
1199 | saveonfault = (u_long)xpcb->pcb_onfault; | | 1199 | saveonfault = (u_long)xpcb->pcb_onfault; |
1200 | res = xldcontrolb(addr, xpcb); | | 1200 | res = xldcontrolb(addr, xpcb); |
1201 | xpcb->pcb_onfault = (void *)saveonfault; | | 1201 | xpcb->pcb_onfault = (void *)saveonfault; |
1202 | | | 1202 | |
1203 | splx(s); | | 1203 | splx(s); |
1204 | return (res); | | 1204 | return (res); |
1205 | } | | 1205 | } |
1206 | #endif /* SUN4 */ | | 1206 | #endif /* SUN4 */ |
1207 | | | 1207 | |
1208 | void | | 1208 | void |
1209 | wzero(void *vb, u_int l) | | 1209 | wzero(void *vb, u_int l) |
1210 | { | | 1210 | { |
1211 | u_char *b = vb; | | 1211 | u_char *b = vb; |
1212 | u_char *be = b + l; | | 1212 | u_char *be = b + l; |
1213 | u_short *sp; | | 1213 | u_short *sp; |
1214 | | | 1214 | |
1215 | if (l == 0) | | 1215 | if (l == 0) |
1216 | return; | | 1216 | return; |
1217 | | | 1217 | |
1218 | /* front, */ | | 1218 | /* front, */ |
1219 | if ((u_long)b & 1) | | 1219 | if ((u_long)b & 1) |
1220 | *b++ = 0; | | 1220 | *b++ = 0; |
1221 | | | 1221 | |
1222 | /* back, */ | | 1222 | /* back, */ |
1223 | if (b != be && ((u_long)be & 1) != 0) { | | 1223 | if (b != be && ((u_long)be & 1) != 0) { |
1224 | be--; | | 1224 | be--; |
1225 | *be = 0; | | 1225 | *be = 0; |
1226 | } | | 1226 | } |
1227 | | | 1227 | |
1228 | /* and middle. */ | | 1228 | /* and middle. */ |
1229 | sp = (u_short *)b; | | 1229 | sp = (u_short *)b; |
1230 | while (sp != (u_short *)be) | | 1230 | while (sp != (u_short *)be) |
1231 | *sp++ = 0; | | 1231 | *sp++ = 0; |
1232 | } | | 1232 | } |
1233 | | | 1233 | |
1234 | void | | 1234 | void |
1235 | wcopy(const void *vb1, void *vb2, u_int l) | | 1235 | wcopy(const void *vb1, void *vb2, u_int l) |
1236 | { | | 1236 | { |
1237 | const u_char *b1e, *b1 = vb1; | | 1237 | const u_char *b1e, *b1 = vb1; |
1238 | u_char *b2 = vb2; | | 1238 | u_char *b2 = vb2; |
1239 | const u_short *sp; | | 1239 | const u_short *sp; |
1240 | int bstore = 0; | | 1240 | int bstore = 0; |
1241 | | | 1241 | |
1242 | if (l == 0) | | 1242 | if (l == 0) |
1243 | return; | | 1243 | return; |
1244 | | | 1244 | |
1245 | /* front, */ | | 1245 | /* front, */ |
1246 | if ((u_long)b1 & 1) { | | 1246 | if ((u_long)b1 & 1) { |
1247 | *b2++ = *b1++; | | 1247 | *b2++ = *b1++; |
1248 | l--; | | 1248 | l--; |
1249 | } | | 1249 | } |
1250 | | | 1250 | |
1251 | /* middle, */ | | 1251 | /* middle, */ |
1252 | sp = (const u_short *)b1; | | 1252 | sp = (const u_short *)b1; |
1253 | b1e = b1 + l; | | 1253 | b1e = b1 + l; |
1254 | if (l & 1) | | 1254 | if (l & 1) |
1255 | b1e--; | | 1255 | b1e--; |
1256 | bstore = (u_long)b2 & 1; | | 1256 | bstore = (u_long)b2 & 1; |
1257 | | | 1257 | |
1258 | while (sp < (const u_short *)b1e) { | | 1258 | while (sp < (const u_short *)b1e) { |
1259 | if (bstore) { | | 1259 | if (bstore) { |
1260 | b2[1] = *sp & 0xff; | | 1260 | b2[1] = *sp & 0xff; |
1261 | b2[0] = *sp >> 8; | | 1261 | b2[0] = *sp >> 8; |
1262 | } else | | 1262 | } else |
1263 | *((short *)b2) = *sp; | | 1263 | *((short *)b2) = *sp; |
1264 | sp++; | | 1264 | sp++; |
1265 | b2 += 2; | | 1265 | b2 += 2; |
1266 | } | | 1266 | } |
1267 | | | 1267 | |
1268 | /* and back. */ | | 1268 | /* and back. */ |
1269 | if (l & 1) | | 1269 | if (l & 1) |
1270 | *b2 = *b1e; | | 1270 | *b2 = *b1e; |
1271 | } | | 1271 | } |
1272 | | | 1272 | |
1273 | #ifdef MODULAR | | 1273 | #ifdef MODULAR |
1274 | void | | 1274 | void |
1275 | module_init_md(void) | | 1275 | module_init_md(void) |
1276 | { | | 1276 | { |
1277 | } | | 1277 | } |
1278 | #endif | | 1278 | #endif |
1279 | | | 1279 | |
1280 | /* | | 1280 | /* |
1281 | * Common function for DMA map creation. May be called by bus-specific | | 1281 | * Common function for DMA map creation. May be called by bus-specific |
1282 | * DMA map creation functions. | | 1282 | * DMA map creation functions. |
1283 | */ | | 1283 | */ |
1284 | int | | 1284 | int |
1285 | _bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments, | | 1285 | _bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments, |
1286 | bus_size_t maxsegsz, bus_size_t boundary, int flags, | | 1286 | bus_size_t maxsegsz, bus_size_t boundary, int flags, |
1287 | bus_dmamap_t *dmamp) | | 1287 | bus_dmamap_t *dmamp) |
1288 | { | | 1288 | { |
1289 | struct sparc_bus_dmamap *map; | | 1289 | struct sparc_bus_dmamap *map; |
1290 | void *mapstore; | | 1290 | void *mapstore; |
1291 | size_t mapsize; | | 1291 | size_t mapsize; |
1292 | | | 1292 | |
1293 | /* | | 1293 | /* |
1294 | * Allocate and initialize the DMA map. The end of the map | | 1294 | * Allocate and initialize the DMA map. The end of the map |
1295 | * is a variable-sized array of segments, so we allocate enough | | 1295 | * is a variable-sized array of segments, so we allocate enough |
1296 | * room for them in one shot. | | 1296 | * room for them in one shot. |
1297 | * | | 1297 | * |
1298 | * Note we don't preserve the WAITOK or NOWAIT flags. Preservation | | 1298 | * Note we don't preserve the WAITOK or NOWAIT flags. Preservation |
1299 | * of ALLOCNOW notifies others that we've reserved these resources, | | 1299 | * of ALLOCNOW notifies others that we've reserved these resources, |
1300 | * and they are not to be freed. | | 1300 | * and they are not to be freed. |
1301 | * | | 1301 | * |
1302 | * The bus_dmamap_t includes one bus_dma_segment_t, hence | | 1302 | * The bus_dmamap_t includes one bus_dma_segment_t, hence |
1303 | * the (nsegments - 1). | | 1303 | * the (nsegments - 1). |
1304 | */ | | 1304 | */ |
1305 | mapsize = sizeof(struct sparc_bus_dmamap) + | | 1305 | mapsize = sizeof(struct sparc_bus_dmamap) + |
1306 | (sizeof(bus_dma_segment_t) * (nsegments - 1)); | | 1306 | (sizeof(bus_dma_segment_t) * (nsegments - 1)); |
1307 | if ((mapstore = malloc(mapsize, M_DMAMAP, | | 1307 | if ((mapstore = malloc(mapsize, M_DMAMAP, |
1308 | (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) | | 1308 | (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) |
1309 | return (ENOMEM); | | 1309 | return (ENOMEM); |
1310 | | | 1310 | |
1311 | memset(mapstore, 0, mapsize); | | 1311 | memset(mapstore, 0, mapsize); |
1312 | map = (struct sparc_bus_dmamap *)mapstore; | | 1312 | map = (struct sparc_bus_dmamap *)mapstore; |
1313 | map->_dm_size = size; | | 1313 | map->_dm_size = size; |
1314 | map->_dm_segcnt = nsegments; | | 1314 | map->_dm_segcnt = nsegments; |
1315 | map->_dm_maxmaxsegsz = maxsegsz; | | 1315 | map->_dm_maxmaxsegsz = maxsegsz; |
1316 | map->_dm_boundary = boundary; | | 1316 | map->_dm_boundary = boundary; |
1317 | map->_dm_align = PAGE_SIZE; | | 1317 | map->_dm_align = PAGE_SIZE; |
1318 | map->_dm_flags = flags & ~(BUS_DMA_WAITOK|BUS_DMA_NOWAIT); | | 1318 | map->_dm_flags = flags & ~(BUS_DMA_WAITOK|BUS_DMA_NOWAIT); |
1319 | map->dm_maxsegsz = maxsegsz; | | 1319 | map->dm_maxsegsz = maxsegsz; |
1320 | map->dm_mapsize = 0; /* no valid mappings */ | | 1320 | map->dm_mapsize = 0; /* no valid mappings */ |
1321 | map->dm_nsegs = 0; | | 1321 | map->dm_nsegs = 0; |
1322 | | | 1322 | |
1323 | *dmamp = map; | | 1323 | *dmamp = map; |
1324 | return (0); | | 1324 | return (0); |
1325 | } | | 1325 | } |
1326 | | | 1326 | |
1327 | /* | | 1327 | /* |
1328 | * Common function for DMA map destruction. May be called by bus-specific | | 1328 | * Common function for DMA map destruction. May be called by bus-specific |
1329 | * DMA map destruction functions. | | 1329 | * DMA map destruction functions. |
1330 | */ | | 1330 | */ |
1331 | void | | 1331 | void |
1332 | _bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map) | | 1332 | _bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map) |
1333 | { | | 1333 | { |
1334 | | | 1334 | |
1335 | free(map, M_DMAMAP); | | 1335 | free(map, M_DMAMAP); |
1336 | } | | 1336 | } |
1337 | | | 1337 | |
1338 | /* | | 1338 | /* |
1339 | * Like _bus_dmamap_load(), but for mbufs. | | 1339 | * Like _bus_dmamap_load(), but for mbufs. |
1340 | */ | | 1340 | */ |
1341 | int | | 1341 | int |
1342 | _bus_dmamap_load_mbuf(bus_dma_tag_t t, bus_dmamap_t map, | | 1342 | _bus_dmamap_load_mbuf(bus_dma_tag_t t, bus_dmamap_t map, |
1343 | struct mbuf *m, int flags) | | 1343 | struct mbuf *m, int flags) |
1344 | { | | 1344 | { |
1345 | | | 1345 | |
1346 | panic("_bus_dmamap_load_mbuf: not implemented"); | | 1346 | panic("_bus_dmamap_load_mbuf: not implemented"); |
1347 | } | | 1347 | } |
1348 | | | 1348 | |
1349 | /* | | 1349 | /* |
1350 | * Like _bus_dmamap_load(), but for uios. | | 1350 | * Like _bus_dmamap_load(), but for uios. |
1351 | */ | | 1351 | */ |
1352 | int | | 1352 | int |
1353 | _bus_dmamap_load_uio(bus_dma_tag_t t, bus_dmamap_t map, | | 1353 | _bus_dmamap_load_uio(bus_dma_tag_t t, bus_dmamap_t map, |
1354 | struct uio *uio, int flags) | | 1354 | struct uio *uio, int flags) |
1355 | { | | 1355 | { |
1356 | | | 1356 | |
1357 | panic("_bus_dmamap_load_uio: not implemented"); | | 1357 | panic("_bus_dmamap_load_uio: not implemented"); |
1358 | } | | 1358 | } |
1359 | | | 1359 | |
1360 | /* | | 1360 | /* |
1361 | * Like _bus_dmamap_load(), but for raw memory allocated with | | 1361 | * Like _bus_dmamap_load(), but for raw memory allocated with |
1362 | * bus_dmamem_alloc(). | | 1362 | * bus_dmamem_alloc(). |
1363 | */ | | 1363 | */ |
1364 | int | | 1364 | int |
1365 | _bus_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t map, | | 1365 | _bus_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t map, |
1366 | bus_dma_segment_t *segs, int nsegs, bus_size_t size, | | 1366 | bus_dma_segment_t *segs, int nsegs, bus_size_t size, |
1367 | int flags) | | 1367 | int flags) |
1368 | { | | 1368 | { |
1369 | | | 1369 | |
1370 | panic("_bus_dmamap_load_raw: not implemented"); | | 1370 | panic("_bus_dmamap_load_raw: not implemented"); |
1371 | } | | 1371 | } |
1372 | | | 1372 | |
1373 | /* | | 1373 | /* |
1374 | * Common function for DMA map synchronization. May be called | | 1374 | * Common function for DMA map synchronization. May be called |
1375 | * by bus-specific DMA map synchronization functions. | | 1375 | * by bus-specific DMA map synchronization functions. |
1376 | */ | | 1376 | */ |
1377 | void | | 1377 | void |
1378 | _bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t map, | | 1378 | _bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t map, |
1379 | bus_addr_t offset, bus_size_t len, int ops) | | 1379 | bus_addr_t offset, bus_size_t len, int ops) |
1380 | { | | 1380 | { |
1381 | } | | 1381 | } |
1382 | | | 1382 | |
1383 | /* | | 1383 | /* |
1384 | * Common function for DMA-safe memory allocation. May be called | | 1384 | * Common function for DMA-safe memory allocation. May be called |
1385 | * by bus-specific DMA memory allocation functions. | | 1385 | * by bus-specific DMA memory allocation functions. |
1386 | */ | | 1386 | */ |
1387 | int | | 1387 | int |
1388 | _bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, | | 1388 | _bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, |
1389 | bus_size_t alignment, bus_size_t boundary, | | 1389 | bus_size_t alignment, bus_size_t boundary, |
1390 | bus_dma_segment_t *segs, int nsegs, int *rsegs, | | 1390 | bus_dma_segment_t *segs, int nsegs, int *rsegs, |
1391 | int flags) | | 1391 | int flags) |
1392 | { | | 1392 | { |
1393 | vaddr_t low, high; | | 1393 | vaddr_t low, high; |
1394 | struct pglist *mlist; | | 1394 | struct pglist *mlist; |
1395 | int error; | | 1395 | int error; |
1396 | | | 1396 | |
1397 | /* Always round the size. */ | | 1397 | /* Always round the size. */ |
1398 | size = round_page(size); | | 1398 | size = round_page(size); |
1399 | low = vm_first_phys; | | 1399 | low = vm_first_phys; |
1400 | high = vm_first_phys + vm_num_phys - PAGE_SIZE; | | 1400 | high = vm_first_phys + vm_num_phys - PAGE_SIZE; |
1401 | | | 1401 | |
1402 | if ((mlist = malloc(sizeof(*mlist), M_DEVBUF, | | 1402 | if ((mlist = malloc(sizeof(*mlist), M_DEVBUF, |
1403 | (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) | | 1403 | (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) |
1404 | return (ENOMEM); | | 1404 | return (ENOMEM); |
1405 | | | 1405 | |
1406 | /* | | 1406 | /* |
1407 | * Allocate pages from the VM system. | | 1407 | * Allocate pages from the VM system. |
1408 | */ | | 1408 | */ |
1409 | error = uvm_pglistalloc(size, low, high, 0, 0, | | 1409 | error = uvm_pglistalloc(size, low, high, 0, 0, |
1410 | mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0); | | 1410 | mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0); |
1411 | if (error) | | 1411 | if (error) |
1412 | return (error); | | 1412 | return (error); |
1413 | | | 1413 | |
1414 | /* | | 1414 | /* |
1415 | * Simply keep a pointer around to the linked list, so | | 1415 | * Simply keep a pointer around to the linked list, so |
1416 | * bus_dmamap_free() can return it. | | 1416 | * bus_dmamap_free() can return it. |
1417 | * | | 1417 | * |
1418 | * NOBODY SHOULD TOUCH THE pageq.queue FIELDS WHILE THESE PAGES | | 1418 | * NOBODY SHOULD TOUCH THE pageq.queue FIELDS WHILE THESE PAGES |
1419 | * ARE IN OUR CUSTODY. | | 1419 | * ARE IN OUR CUSTODY. |
1420 | */ | | 1420 | */ |
1421 | segs[0]._ds_mlist = mlist; | | 1421 | segs[0]._ds_mlist = mlist; |
1422 | | | 1422 | |
1423 | /* | | 1423 | /* |
1424 | * We now have physical pages, but no DVMA addresses yet. These | | 1424 | * We now have physical pages, but no DVMA addresses yet. These |
1425 | * will be allocated in bus_dmamap_load*() routines. Hence we | | 1425 | * will be allocated in bus_dmamap_load*() routines. Hence we |
1426 | * save any alignment and boundary requirements in this DMA | | 1426 | * save any alignment and boundary requirements in this DMA |
1427 | * segment. | | 1427 | * segment. |
1428 | */ | | 1428 | */ |
1429 | segs[0].ds_addr = 0; | | 1429 | segs[0].ds_addr = 0; |
1430 | segs[0].ds_len = 0; | | 1430 | segs[0].ds_len = 0; |
1431 | segs[0]._ds_va = 0; | | 1431 | segs[0]._ds_va = 0; |
1432 | *rsegs = 1; | | 1432 | *rsegs = 1; |
1433 | return (0); | | 1433 | return (0); |
1434 | } | | 1434 | } |
1435 | | | 1435 | |
1436 | /* | | 1436 | /* |
1437 | * Common function for freeing DMA-safe memory. May be called by | | 1437 | * Common function for freeing DMA-safe memory. May be called by |
1438 | * bus-specific DMA memory free functions. | | 1438 | * bus-specific DMA memory free functions. |
1439 | */ | | 1439 | */ |
1440 | void | | 1440 | void |
1441 | _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs) | | 1441 | _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs) |
1442 | { | | 1442 | { |
1443 | | | 1443 | |
1444 | if (nsegs != 1) | | 1444 | if (nsegs != 1) |
1445 | panic("bus_dmamem_free: nsegs = %d", nsegs); | | 1445 | panic("bus_dmamem_free: nsegs = %d", nsegs); |
1446 | | | 1446 | |
1447 | /* | | 1447 | /* |
1448 | * Return the list of pages back to the VM system. | | 1448 | * Return the list of pages back to the VM system. |
1449 | */ | | 1449 | */ |
1450 | uvm_pglistfree(segs[0]._ds_mlist); | | 1450 | uvm_pglistfree(segs[0]._ds_mlist); |
1451 | free(segs[0]._ds_mlist, M_DEVBUF); | | 1451 | free(segs[0]._ds_mlist, M_DEVBUF); |
1452 | } | | 1452 | } |
1453 | | | 1453 | |
1454 | /* | | 1454 | /* |
1455 | * Common function for unmapping DMA-safe memory. May be called by | | 1455 | * Common function for unmapping DMA-safe memory. May be called by |
1456 | * bus-specific DMA memory unmapping functions. | | 1456 | * bus-specific DMA memory unmapping functions. |
1457 | */ | | 1457 | */ |
1458 | void | | 1458 | void |
1459 | _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size) | | 1459 | _bus_dmamem_unmap(bus_dma_tag_t t, void *kva, size_t size) |
1460 | { | | 1460 | { |
1461 | | | 1461 | |
1462 | #ifdef DIAGNOSTIC | | 1462 | #ifdef DIAGNOSTIC |
1463 | if ((u_long)kva & PAGE_MASK) | | 1463 | if ((u_long)kva & PAGE_MASK) |
1464 | panic("_bus_dmamem_unmap"); | | 1464 | panic("_bus_dmamem_unmap"); |
1465 | #endif | | 1465 | #endif |
1466 | | | 1466 | |
1467 | size = round_page(size); | | 1467 | size = round_page(size); |
1468 | pmap_kremove((vaddr_t)kva, size); | | 1468 | pmap_kremove((vaddr_t)kva, size); |
1469 | pmap_update(pmap_kernel()); | | 1469 | pmap_update(pmap_kernel()); |
1470 | uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY); | | 1470 | uvm_km_free(kernel_map, (vaddr_t)kva, size, UVM_KMF_VAONLY); |
1471 | } | | 1471 | } |
1472 | | | 1472 | |
1473 | /* | | 1473 | /* |
1474 | * Common functin for mmap(2)'ing DMA-safe memory. May be called by | | 1474 | * Common functin for mmap(2)'ing DMA-safe memory. May be called by |
1475 | * bus-specific DMA mmap(2)'ing functions. | | 1475 | * bus-specific DMA mmap(2)'ing functions. |
1476 | */ | | 1476 | */ |
1477 | paddr_t | | 1477 | paddr_t |
1478 | _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, | | 1478 | _bus_dmamem_mmap(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, |
1479 | off_t off, int prot, int flags) | | 1479 | off_t off, int prot, int flags) |
1480 | { | | 1480 | { |
1481 | | | 1481 | |
1482 | panic("_bus_dmamem_mmap: not implemented"); | | 1482 | panic("_bus_dmamem_mmap: not implemented"); |
1483 | } | | 1483 | } |
1484 | | | 1484 | |
1485 | /* | | 1485 | /* |
1486 | * Utility to allocate an aligned kernel virtual address range | | 1486 | * Utility to allocate an aligned kernel virtual address range |
1487 | */ | | 1487 | */ |
1488 | vaddr_t | | 1488 | vaddr_t |
1489 | _bus_dma_valloc_skewed(size_t size, u_long boundary, u_long align, u_long skew) | | 1489 | _bus_dma_valloc_skewed(size_t size, u_long boundary, u_long align, u_long skew) |
1490 | { | | 1490 | { |
1491 | size_t oversize; | | 1491 | size_t oversize; |
1492 | vaddr_t va, sva; | | 1492 | vaddr_t va, sva; |
1493 | | | 1493 | |
1494 | /* | | 1494 | /* |
1495 | * Find a region of kernel virtual addresses that is aligned | | 1495 | * Find a region of kernel virtual addresses that is aligned |
1496 | * to the given address modulo the requested alignment, i.e. | | 1496 | * to the given address modulo the requested alignment, i.e. |
1497 | * | | 1497 | * |
1498 | * (va - skew) == 0 mod align | | 1498 | * (va - skew) == 0 mod align |
1499 | * | | 1499 | * |
1500 | * The following conditions apply to the arguments: | | 1500 | * The following conditions apply to the arguments: |
1501 | * | | 1501 | * |
1502 | * - `size' must be a multiple of the VM page size | | 1502 | * - `size' must be a multiple of the VM page size |
1503 | * - `align' must be a power of two | | 1503 | * - `align' must be a power of two |
1504 | * and greater than or equal to the VM page size | | 1504 | * and greater than or equal to the VM page size |
1505 | * - `skew' must be smaller than `align' | | 1505 | * - `skew' must be smaller than `align' |
1506 | * - `size' must be smaller than `boundary' | | 1506 | * - `size' must be smaller than `boundary' |
1507 | */ | | 1507 | */ |
1508 | | | 1508 | |
1509 | #ifdef DIAGNOSTIC | | 1509 | #ifdef DIAGNOSTIC |
1510 | if ((size & PAGE_MASK) != 0) | | 1510 | if ((size & PAGE_MASK) != 0) |
1511 | panic("_bus_dma_valloc_skewed: invalid size %lx", size); | | 1511 | panic("_bus_dma_valloc_skewed: invalid size %lx", size); |
1512 | if ((align & PAGE_MASK) != 0) | | 1512 | if ((align & PAGE_MASK) != 0) |
1513 | panic("_bus_dma_valloc_skewed: invalid alignment %lx", align); | | 1513 | panic("_bus_dma_valloc_skewed: invalid alignment %lx", align); |
1514 | if (align < skew) | | 1514 | if (align < skew) |
1515 | panic("_bus_dma_valloc_skewed: align %lx < skew %lx", | | 1515 | panic("_bus_dma_valloc_skewed: align %lx < skew %lx", |
1516 | align, skew); | | 1516 | align, skew); |
1517 | #endif | | 1517 | #endif |
1518 | | | 1518 | |
1519 | /* XXX - Implement this! */ | | 1519 | /* XXX - Implement this! */ |
1520 | if (boundary) { | | 1520 | if (boundary) { |
1521 | printf("_bus_dma_valloc_skewed: " | | 1521 | printf("_bus_dma_valloc_skewed: " |
1522 | "boundary check not implemented"); | | 1522 | "boundary check not implemented"); |
1523 | return (0); | | 1523 | return (0); |
1524 | } | | 1524 | } |
1525 | | | 1525 | |
1526 | /* | | 1526 | /* |
1527 | * First, find a region large enough to contain any aligned chunk | | 1527 | * First, find a region large enough to contain any aligned chunk |
1528 | */ | | 1528 | */ |
1529 | oversize = size + align - PAGE_SIZE; | | 1529 | oversize = size + align - PAGE_SIZE; |
1530 | sva = vm_map_min(kernel_map); | | 1530 | sva = vm_map_min(kernel_map); |
1531 | if (uvm_map(kernel_map, &sva, oversize, NULL, UVM_UNKNOWN_OFFSET, | | 1531 | if (uvm_map(kernel_map, &sva, oversize, NULL, UVM_UNKNOWN_OFFSET, |
1532 | align, UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_NONE, | | 1532 | align, UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_NONE, |
1533 | UVM_ADV_RANDOM, UVM_FLAG_NOWAIT))) | | 1533 | UVM_ADV_RANDOM, UVM_FLAG_NOWAIT))) |
1534 | return (0); | | 1534 | return (0); |
1535 | | | 1535 | |
1536 | /* | | 1536 | /* |
1537 | * Compute start of aligned region | | 1537 | * Compute start of aligned region |
1538 | */ | | 1538 | */ |
1539 | va = sva; | | 1539 | va = sva; |
1540 | va += (skew + align - va) & (align - 1); | | 1540 | va += (skew + align - va) & (align - 1); |
1541 | | | 1541 | |
1542 | /* | | 1542 | /* |
1543 | * Return excess virtual addresses | | 1543 | * Return excess virtual addresses |
1544 | */ | | 1544 | */ |
1545 | if (va != sva) | | 1545 | if (va != sva) |
1546 | (void)uvm_unmap(kernel_map, sva, va); | | 1546 | (void)uvm_unmap(kernel_map, sva, va); |
1547 | if (va + size != sva + oversize) | | 1547 | if (va + size != sva + oversize) |
1548 | (void)uvm_unmap(kernel_map, va + size, sva + oversize); | | 1548 | (void)uvm_unmap(kernel_map, va + size, sva + oversize); |
1549 | | | 1549 | |
1550 | return (va); | | 1550 | return (va); |
1551 | } | | 1551 | } |
1552 | | | 1552 | |
1553 | /* sun4/sun4c DMA map functions */ | | 1553 | /* sun4/sun4c DMA map functions */ |
1554 | int sun4_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, | | 1554 | int sun4_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, |
1555 | bus_size_t, struct proc *, int); | | 1555 | bus_size_t, struct proc *, int); |
1556 | int sun4_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, | | 1556 | int sun4_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, |
1557 | bus_dma_segment_t *, int, bus_size_t, int); | | 1557 | bus_dma_segment_t *, int, bus_size_t, int); |
1558 | void sun4_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); | | 1558 | void sun4_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); |
1559 | int sun4_dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, | | 1559 | int sun4_dmamem_map(bus_dma_tag_t, bus_dma_segment_t *, |
1560 | int, size_t, void **, int); | | 1560 | int, size_t, void **, int); |
1561 | | | 1561 | |
1562 | /* | | 1562 | /* |
1563 | * sun4/sun4c: load DMA map with a linear buffer. | | 1563 | * sun4/sun4c: load DMA map with a linear buffer. |
1564 | */ | | 1564 | */ |
1565 | int | | 1565 | int |
1566 | sun4_dmamap_load(bus_dma_tag_t t, bus_dmamap_t map, | | 1566 | sun4_dmamap_load(bus_dma_tag_t t, bus_dmamap_t map, |
1567 | void *buf, bus_size_t buflen, | | 1567 | void *buf, bus_size_t buflen, |
1568 | struct proc *p, int flags) | | 1568 | struct proc *p, int flags) |
1569 | { | | 1569 | { |
1570 | bus_size_t sgsize; | | 1570 | bus_size_t sgsize; |
1571 | vaddr_t va = (vaddr_t)buf; | | 1571 | vaddr_t va = (vaddr_t)buf; |
1572 | int pagesz = PAGE_SIZE; | | 1572 | int pagesz = PAGE_SIZE; |
1573 | vaddr_t dva; | | 1573 | vaddr_t dva; |
1574 | pmap_t pmap; | | 1574 | pmap_t pmap; |
1575 | | | 1575 | |
1576 | /* | | 1576 | /* |
1577 | * Make sure that on error condition we return "no valid mappings". | | 1577 | * Make sure that on error condition we return "no valid mappings". |
1578 | */ | | 1578 | */ |
1579 | map->dm_nsegs = 0; | | 1579 | map->dm_nsegs = 0; |
1580 | | | 1580 | |
1581 | if (buflen > map->_dm_size) | | 1581 | if (buflen > map->_dm_size) |
1582 | return (EINVAL); | | 1582 | return (EINVAL); |
1583 | | | 1583 | |
1584 | cache_flush(buf, buflen); | | 1584 | cache_flush(buf, buflen); |
1585 | | | 1585 | |
1586 | if ((map->_dm_flags & BUS_DMA_24BIT) == 0) { | | 1586 | if ((map->_dm_flags & BUS_DMA_24BIT) == 0) { |
1587 | /* | | 1587 | /* |
1588 | * XXX Need to implement "don't DMA across this boundry". | | 1588 | * XXX Need to implement "don't DMA across this boundry". |
1589 | */ | | 1589 | */ |
1590 | if (map->_dm_boundary != 0) { | | 1590 | if (map->_dm_boundary != 0) { |
1591 | bus_addr_t baddr; | | 1591 | bus_addr_t baddr; |
1592 | | | 1592 | |
1593 | /* Calculate first boundary line after `buf' */ | | 1593 | /* Calculate first boundary line after `buf' */ |
1594 | baddr = ((bus_addr_t)va + map->_dm_boundary) & | | 1594 | baddr = ((bus_addr_t)va + map->_dm_boundary) & |
1595 | -map->_dm_boundary; | | 1595 | -map->_dm_boundary; |
1596 | | | 1596 | |
1597 | /* | | 1597 | /* |
1598 | * If the requested segment crosses the boundary, | | 1598 | * If the requested segment crosses the boundary, |
1599 | * we can't grant a direct map. For now, steal some | | 1599 | * we can't grant a direct map. For now, steal some |
1600 | * space from the `24BIT' map instead. | | 1600 | * space from the `24BIT' map instead. |
1601 | * | | 1601 | * |
1602 | * (XXX - no overflow detection here) | | 1602 | * (XXX - no overflow detection here) |
1603 | */ | | 1603 | */ |
1604 | if (buflen > (baddr - (bus_addr_t)va)) | | 1604 | if (buflen > (baddr - (bus_addr_t)va)) |
1605 | goto no_fit; | | 1605 | goto no_fit; |
1606 | } | | 1606 | } |
1607 | map->dm_mapsize = buflen; | | 1607 | map->dm_mapsize = buflen; |
1608 | map->dm_nsegs = 1; | | 1608 | map->dm_nsegs = 1; |
1609 | map->dm_segs[0].ds_addr = (bus_addr_t)va; | | 1609 | map->dm_segs[0].ds_addr = (bus_addr_t)va; |
1610 | map->dm_segs[0].ds_len = buflen; | | 1610 | map->dm_segs[0].ds_len = buflen; |
1611 | map->_dm_flags |= _BUS_DMA_DIRECTMAP; | | 1611 | map->_dm_flags |= _BUS_DMA_DIRECTMAP; |
1612 | return (0); | | 1612 | return (0); |
1613 | } | | 1613 | } |
1614 | | | 1614 | |
1615 | no_fit: | | 1615 | no_fit: |
1616 | sgsize = round_page(buflen + (va & (pagesz - 1))); | | 1616 | sgsize = round_page(buflen + (va & (pagesz - 1))); |
1617 | | | 1617 | |
1618 | if (extent_alloc(dvmamap24, sgsize, pagesz, map->_dm_boundary, | | 1618 | if (extent_alloc(dvmamap24, sgsize, pagesz, map->_dm_boundary, |
1619 | (flags & BUS_DMA_NOWAIT) == 0 ? EX_WAITOK : EX_NOWAIT, | | 1619 | (flags & BUS_DMA_NOWAIT) == 0 ? EX_WAITOK : EX_NOWAIT, |
1620 | &dva) != 0) { | | 1620 | &dva) != 0) { |
1621 | return (ENOMEM); | | 1621 | return (ENOMEM); |
1622 | } | | 1622 | } |
1623 | | | 1623 | |
1624 | /* | | 1624 | /* |
1625 | * We always use just one segment. | | 1625 | * We always use just one segment. |
1626 | */ | | 1626 | */ |
1627 | map->dm_mapsize = buflen; | | 1627 | map->dm_mapsize = buflen; |
1628 | map->dm_segs[0].ds_addr = dva + (va & (pagesz - 1)); | | 1628 | map->dm_segs[0].ds_addr = dva + (va & (pagesz - 1)); |
1629 | map->dm_segs[0].ds_len = buflen; | | 1629 | map->dm_segs[0].ds_len = buflen; |
1630 | map->dm_segs[0]._ds_sgsize = sgsize; | | 1630 | map->dm_segs[0]._ds_sgsize = sgsize; |
1631 | | | 1631 | |
1632 | if (p != NULL) | | 1632 | if (p != NULL) |
1633 | pmap = p->p_vmspace->vm_map.pmap; | | 1633 | pmap = p->p_vmspace->vm_map.pmap; |
1634 | else | | 1634 | else |
1635 | pmap = pmap_kernel(); | | 1635 | pmap = pmap_kernel(); |
1636 | | | 1636 | |
1637 | for (; buflen > 0; ) { | | 1637 | for (; buflen > 0; ) { |
1638 | paddr_t pa; | | 1638 | paddr_t pa; |
1639 | | | 1639 | |
1640 | /* | | 1640 | /* |
1641 | * Get the physical address for this page. | | 1641 | * Get the physical address for this page. |
1642 | */ | | 1642 | */ |
1643 | (void) pmap_extract(pmap, va, &pa); | | 1643 | (void) pmap_extract(pmap, va, &pa); |
1644 | | | 1644 | |
1645 | /* | | 1645 | /* |
1646 | * Compute the segment size, and adjust counts. | | 1646 | * Compute the segment size, and adjust counts. |
1647 | */ | | 1647 | */ |
1648 | sgsize = pagesz - (va & (pagesz - 1)); | | 1648 | sgsize = pagesz - (va & (pagesz - 1)); |
1649 | if (buflen < sgsize) | | 1649 | if (buflen < sgsize) |
1650 | sgsize = buflen; | | 1650 | sgsize = buflen; |
1651 | | | 1651 | |
1652 | #ifdef notyet | | 1652 | #ifdef notyet |
1653 | #if defined(SUN4) | | 1653 | #if defined(SUN4) |
1654 | if (have_iocache) | | 1654 | if (have_iocache) |
1655 | pa |= PG_IOC; | | 1655 | pa |= PG_IOC; |
1656 | #endif | | 1656 | #endif |
1657 | #endif | | 1657 | #endif |
1658 | pmap_kenter_pa(dva, (pa & -pagesz) | PMAP_NC, | | 1658 | pmap_kenter_pa(dva, (pa & -pagesz) | PMAP_NC, |
1659 | VM_PROT_READ | VM_PROT_WRITE); | | 1659 | VM_PROT_READ | VM_PROT_WRITE); |
1660 | | | 1660 | |
1661 | dva += pagesz; | | 1661 | dva += pagesz; |
1662 | va += sgsize; | | 1662 | va += sgsize; |
1663 | buflen -= sgsize; | | 1663 | buflen -= sgsize; |
1664 | } | | 1664 | } |
1665 | pmap_update(pmap_kernel()); | | 1665 | pmap_update(pmap_kernel()); |
1666 | | | 1666 | |
1667 | map->dm_nsegs = 1; | | 1667 | map->dm_nsegs = 1; |
1668 | return (0); | | 1668 | return (0); |
1669 | } | | 1669 | } |
1670 | | | 1670 | |
1671 | /* | | 1671 | /* |
1672 | * Like _bus_dmamap_load(), but for raw memory allocated with | | 1672 | * Like _bus_dmamap_load(), but for raw memory allocated with |
1673 | * bus_dmamem_alloc(). | | 1673 | * bus_dmamem_alloc(). |
1674 | */ | | 1674 | */ |
1675 | int | | 1675 | int |
1676 | sun4_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t map, | | 1676 | sun4_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t map, |
1677 | bus_dma_segment_t *segs, int nsegs, bus_size_t size, | | 1677 | bus_dma_segment_t *segs, int nsegs, bus_size_t size, |
1678 | int flags) | | 1678 | int flags) |
1679 | { | | 1679 | { |
1680 | struct vm_page *m; | | 1680 | struct vm_page *m; |
1681 | paddr_t pa; | | 1681 | paddr_t pa; |
1682 | vaddr_t dva; | | 1682 | vaddr_t dva; |
1683 | bus_size_t sgsize; | | 1683 | bus_size_t sgsize; |
1684 | struct pglist *mlist; | | 1684 | struct pglist *mlist; |
1685 | int pagesz = PAGE_SIZE; | | 1685 | int pagesz = PAGE_SIZE; |
1686 | int error; | | 1686 | int error; |
1687 | | | 1687 | |
1688 | map->dm_nsegs = 0; | | 1688 | map->dm_nsegs = 0; |
1689 | sgsize = (size + pagesz - 1) & -pagesz; | | 1689 | sgsize = (size + pagesz - 1) & -pagesz; |
1690 | | | 1690 | |
1691 | /* Allocate DVMA addresses */ | | 1691 | /* Allocate DVMA addresses */ |
1692 | if ((map->_dm_flags & BUS_DMA_24BIT) != 0) { | | 1692 | if ((map->_dm_flags & BUS_DMA_24BIT) != 0) { |
1693 | error = extent_alloc(dvmamap24, sgsize, pagesz, | | 1693 | error = extent_alloc(dvmamap24, sgsize, pagesz, |
1694 | map->_dm_boundary, | | 1694 | map->_dm_boundary, |
1695 | (flags & BUS_DMA_NOWAIT) == 0 | | 1695 | (flags & BUS_DMA_NOWAIT) == 0 |
1696 | ? EX_WAITOK : EX_NOWAIT, | | 1696 | ? EX_WAITOK : EX_NOWAIT, |
1697 | &dva); | | 1697 | &dva); |
1698 | if (error) | | 1698 | if (error) |
1699 | return (error); | | 1699 | return (error); |
1700 | } else { | | 1700 | } else { |
1701 | /* Any properly aligned virtual address will do */ | | 1701 | /* Any properly aligned virtual address will do */ |
1702 | dva = _bus_dma_valloc_skewed(sgsize, map->_dm_boundary, | | 1702 | dva = _bus_dma_valloc_skewed(sgsize, map->_dm_boundary, |
1703 | pagesz, 0); | | 1703 | pagesz, 0); |
1704 | if (dva == 0) | | 1704 | if (dva == 0) |
1705 | return (ENOMEM); | | 1705 | return (ENOMEM); |
1706 | } | | 1706 | } |
1707 | | | 1707 | |
1708 | map->dm_segs[0].ds_addr = dva; | | 1708 | map->dm_segs[0].ds_addr = dva; |
1709 | map->dm_segs[0].ds_len = size; | | 1709 | map->dm_segs[0].ds_len = size; |
1710 | map->dm_segs[0]._ds_sgsize = sgsize; | | 1710 | map->dm_segs[0]._ds_sgsize = sgsize; |
1711 | | | 1711 | |
1712 | /* Map physical pages into IOMMU */ | | 1712 | /* Map physical pages into IOMMU */ |
1713 | mlist = segs[0]._ds_mlist; | | 1713 | mlist = segs[0]._ds_mlist; |
1714 | for (m = TAILQ_FIRST(mlist); m != NULL; m = TAILQ_NEXT(m,pageq.queue)) { | | 1714 | for (m = TAILQ_FIRST(mlist); m != NULL; m = TAILQ_NEXT(m,pageq.queue)) { |
1715 | if (sgsize == 0) | | 1715 | if (sgsize == 0) |
1716 | panic("sun4_dmamap_load_raw: size botch"); | | 1716 | panic("sun4_dmamap_load_raw: size botch"); |
1717 | pa = VM_PAGE_TO_PHYS(m); | | 1717 | pa = VM_PAGE_TO_PHYS(m); |
1718 | #ifdef notyet | | 1718 | #ifdef notyet |
1719 | #if defined(SUN4) | | 1719 | #if defined(SUN4) |
1720 | if (have_iocache) | | 1720 | if (have_iocache) |
1721 | pa |= PG_IOC; | | 1721 | pa |= PG_IOC; |
1722 | #endif | | 1722 | #endif |
1723 | #endif | | 1723 | #endif |
1724 | pmap_kenter_pa(dva, (pa & -pagesz) | PMAP_NC, | | 1724 | pmap_kenter_pa(dva, (pa & -pagesz) | PMAP_NC, |
1725 | VM_PROT_READ | VM_PROT_WRITE); | | 1725 | VM_PROT_READ | VM_PROT_WRITE); |
1726 | | | 1726 | |
1727 | dva += pagesz; | | 1727 | dva += pagesz; |
1728 | sgsize -= pagesz; | | 1728 | sgsize -= pagesz; |
1729 | } | | 1729 | } |
1730 | pmap_update(pmap_kernel()); | | 1730 | pmap_update(pmap_kernel()); |
1731 | | | 1731 | |
1732 | map->dm_nsegs = 1; | | 1732 | map->dm_nsegs = 1; |
1733 | map->dm_mapsize = size; | | 1733 | map->dm_mapsize = size; |
1734 | | | 1734 | |
1735 | return (0); | | 1735 | return (0); |
1736 | } | | 1736 | } |
1737 | | | 1737 | |
1738 | /* | | 1738 | /* |
1739 | * sun4/sun4c function for unloading a DMA map. | | 1739 | * sun4/sun4c function for unloading a DMA map. |
1740 | */ | | 1740 | */ |
1741 | void | | 1741 | void |
1742 | sun4_dmamap_unload(bus_dma_tag_t t, bus_dmamap_t map) | | 1742 | sun4_dmamap_unload(bus_dma_tag_t t, bus_dmamap_t map) |
1743 | { | | 1743 | { |
1744 | bus_dma_segment_t *segs = map->dm_segs; | | 1744 | bus_dma_segment_t *segs = map->dm_segs; |
1745 | int nsegs = map->dm_nsegs; | | 1745 | int nsegs = map->dm_nsegs; |
1746 | int flags = map->_dm_flags; | | 1746 | int flags = map->_dm_flags; |
1747 | vaddr_t dva; | | 1747 | vaddr_t dva; |
1748 | bus_size_t len; | | 1748 | bus_size_t len; |
1749 | int i, s, error; | | 1749 | int i, s, error; |
1750 | | | 1750 | |
1751 | map->dm_maxsegsz = map->_dm_maxmaxsegsz; | | 1751 | map->dm_maxsegsz = map->_dm_maxmaxsegsz; |
1752 | | | 1752 | |
1753 | if ((flags & _BUS_DMA_DIRECTMAP) != 0) { | | 1753 | if ((flags & _BUS_DMA_DIRECTMAP) != 0) { |
1754 | /* Nothing to release */ | | 1754 | /* Nothing to release */ |
1755 | map->dm_mapsize = 0; | | 1755 | map->dm_mapsize = 0; |
1756 | map->dm_nsegs = 0; | | 1756 | map->dm_nsegs = 0; |
1757 | map->_dm_flags &= ~_BUS_DMA_DIRECTMAP; | | 1757 | map->_dm_flags &= ~_BUS_DMA_DIRECTMAP; |
1758 | return; | | 1758 | return; |
1759 | } | | 1759 | } |
1760 | | | 1760 | |
1761 | for (i = 0; i < nsegs; i++) { | | 1761 | for (i = 0; i < nsegs; i++) { |
1762 | dva = segs[i].ds_addr & -PAGE_SIZE; | | 1762 | dva = segs[i].ds_addr & -PAGE_SIZE; |
1763 | len = segs[i]._ds_sgsize; | | 1763 | len = segs[i]._ds_sgsize; |
1764 | | | 1764 | |
1765 | pmap_kremove(dva, len); | | 1765 | pmap_kremove(dva, len); |
1766 | | | 1766 | |
1767 | if ((flags & BUS_DMA_24BIT) != 0) { | | 1767 | if ((flags & BUS_DMA_24BIT) != 0) { |
1768 | s = splhigh(); | | 1768 | s = splhigh(); |
1769 | error = extent_free(dvmamap24, dva, len, EX_NOWAIT); | | 1769 | error = extent_free(dvmamap24, dva, len, EX_NOWAIT); |
1770 | splx(s); | | 1770 | splx(s); |
1771 | if (error != 0) | | 1771 | if (error != 0) |
1772 | printf("warning: %ld of DVMA space lost\n", len); | | 1772 | printf("warning: %ld of DVMA space lost\n", len); |
1773 | } else { | | 1773 | } else { |
1774 | uvm_unmap(kernel_map, dva, dva + len); | | 1774 | uvm_unmap(kernel_map, dva, dva + len); |
1775 | } | | 1775 | } |
1776 | } | | 1776 | } |
1777 | pmap_update(pmap_kernel()); | | 1777 | pmap_update(pmap_kernel()); |
1778 | | | 1778 | |
1779 | /* Mark the mappings as invalid. */ | | 1779 | /* Mark the mappings as invalid. */ |
1780 | map->dm_mapsize = 0; | | 1780 | map->dm_mapsize = 0; |
1781 | map->dm_nsegs = 0; | | 1781 | map->dm_nsegs = 0; |
1782 | } | | 1782 | } |
1783 | | | 1783 | |
1784 | /* | | 1784 | /* |
1785 | * Common function for mapping DMA-safe memory. May be called by | | 1785 | * Common function for mapping DMA-safe memory. May be called by |
1786 | * bus-specific DMA memory map functions. | | 1786 | * bus-specific DMA memory map functions. |
1787 | */ | | 1787 | */ |
1788 | int | | 1788 | int |
1789 | sun4_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, | | 1789 | sun4_dmamem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, |
1790 | size_t size, void **kvap, int flags) | | 1790 | size_t size, void **kvap, int flags) |
1791 | { | | 1791 | { |
1792 | struct vm_page *m; | | 1792 | struct vm_page *m; |
1793 | vaddr_t va; | | 1793 | vaddr_t va; |
1794 | struct pglist *mlist; | | 1794 | struct pglist *mlist; |
1795 | const uvm_flag_t kmflags = | | 1795 | const uvm_flag_t kmflags = |
1796 | (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0; | | 1796 | (flags & BUS_DMA_NOWAIT) != 0 ? UVM_KMF_NOWAIT : 0; |
1797 | | | 1797 | |
1798 | if (nsegs != 1) | | 1798 | if (nsegs != 1) |
1799 | panic("sun4_dmamem_map: nsegs = %d", nsegs); | | 1799 | panic("sun4_dmamem_map: nsegs = %d", nsegs); |
1800 | | | 1800 | |
1801 | size = round_page(size); | | 1801 | size = round_page(size); |
1802 | | | 1802 | |
1803 | va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags); | | 1803 | va = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY | kmflags); |
1804 | if (va == 0) | | 1804 | if (va == 0) |
1805 | return (ENOMEM); | | 1805 | return (ENOMEM); |
1806 | | | 1806 | |
1807 | segs[0]._ds_va = va; | | 1807 | segs[0]._ds_va = va; |
1808 | *kvap = (void *)va; | | 1808 | *kvap = (void *)va; |
1809 | | | 1809 | |
1810 | mlist = segs[0]._ds_mlist; | | 1810 | mlist = segs[0]._ds_mlist; |
1811 | TAILQ_FOREACH(m, mlist, pageq.queue) { | | 1811 | TAILQ_FOREACH(m, mlist, pageq.queue) { |
1812 | paddr_t pa; | | 1812 | paddr_t pa; |
1813 | | | 1813 | |
1814 | if (size == 0) | | 1814 | if (size == 0) |
1815 | panic("sun4_dmamem_map: size botch"); | | 1815 | panic("sun4_dmamem_map: size botch"); |
1816 | | | 1816 | |
1817 | pa = VM_PAGE_TO_PHYS(m); | | 1817 | pa = VM_PAGE_TO_PHYS(m); |
1818 | pmap_kenter_pa(va, pa | PMAP_NC, VM_PROT_READ | VM_PROT_WRITE); | | 1818 | pmap_kenter_pa(va, pa | PMAP_NC, VM_PROT_READ | VM_PROT_WRITE); |
1819 | | | 1819 | |
1820 | va += PAGE_SIZE; | | 1820 | va += PAGE_SIZE; |
1821 | size -= PAGE_SIZE; | | 1821 | size -= PAGE_SIZE; |
1822 | } | | 1822 | } |
1823 | pmap_update(pmap_kernel()); | | 1823 | pmap_update(pmap_kernel()); |
1824 | | | 1824 | |
1825 | return (0); | | 1825 | return (0); |
1826 | } | | 1826 | } |
1827 | | | 1827 | |
1828 | | | 1828 | |
1829 | struct sparc_bus_dma_tag mainbus_dma_tag = { | | 1829 | struct sparc_bus_dma_tag mainbus_dma_tag = { |
1830 | NULL, | | 1830 | NULL, |
1831 | _bus_dmamap_create, | | 1831 | _bus_dmamap_create, |
1832 | _bus_dmamap_destroy, | | 1832 | _bus_dmamap_destroy, |
1833 | sun4_dmamap_load, | | 1833 | sun4_dmamap_load, |
1834 | _bus_dmamap_load_mbuf, | | 1834 | _bus_dmamap_load_mbuf, |
1835 | _bus_dmamap_load_uio, | | 1835 | _bus_dmamap_load_uio, |
1836 | sun4_dmamap_load_raw, | | 1836 | sun4_dmamap_load_raw, |
1837 | sun4_dmamap_unload, | | 1837 | sun4_dmamap_unload, |
1838 | _bus_dmamap_sync, | | 1838 | _bus_dmamap_sync, |
1839 | | | 1839 | |
1840 | _bus_dmamem_alloc, | | 1840 | _bus_dmamem_alloc, |
1841 | _bus_dmamem_free, | | 1841 | _bus_dmamem_free, |
1842 | sun4_dmamem_map, | | 1842 | sun4_dmamem_map, |
1843 | _bus_dmamem_unmap, | | 1843 | _bus_dmamem_unmap, |
1844 | _bus_dmamem_mmap | | 1844 | _bus_dmamem_mmap |
1845 | }; | | 1845 | }; |
1846 | | | 1846 | |
1847 | | | 1847 | |
1848 | /* | | 1848 | /* |
1849 | * Base bus space handlers. | | 1849 | * Base bus space handlers. |
1850 | */ | | 1850 | */ |
1851 | static int sparc_bus_map(bus_space_tag_t, bus_addr_t, | | 1851 | static int sparc_bus_map(bus_space_tag_t, bus_addr_t, |
1852 | bus_size_t, int, vaddr_t, | | 1852 | bus_size_t, int, vaddr_t, |
1853 | bus_space_handle_t *); | | 1853 | bus_space_handle_t *); |
1854 | static int sparc_bus_unmap(bus_space_tag_t, bus_space_handle_t, | | 1854 | static int sparc_bus_unmap(bus_space_tag_t, bus_space_handle_t, |
1855 | bus_size_t); | | 1855 | bus_size_t); |
1856 | static int sparc_bus_subregion(bus_space_tag_t, bus_space_handle_t, | | 1856 | static int sparc_bus_subregion(bus_space_tag_t, bus_space_handle_t, |
1857 | bus_size_t, bus_size_t, | | 1857 | bus_size_t, bus_size_t, |
1858 | bus_space_handle_t *); | | 1858 | bus_space_handle_t *); |
1859 | static paddr_t sparc_bus_mmap(bus_space_tag_t, bus_addr_t, off_t, | | 1859 | static paddr_t sparc_bus_mmap(bus_space_tag_t, bus_addr_t, off_t, |
1860 | int, int); | | 1860 | int, int); |
1861 | static void *sparc_mainbus_intr_establish(bus_space_tag_t, int, int, | | 1861 | static void *sparc_mainbus_intr_establish(bus_space_tag_t, int, int, |
1862 | int (*)(void *), | | 1862 | int (*)(void *), |
1863 | void *, | | 1863 | void *, |
1864 | void (*)(void)); | | 1864 | void (*)(void)); |
1865 | static void sparc_bus_barrier(bus_space_tag_t, bus_space_handle_t, | | 1865 | static void sparc_bus_barrier(bus_space_tag_t, bus_space_handle_t, |
1866 | bus_size_t, bus_size_t, int); | | 1866 | bus_size_t, bus_size_t, int); |
1867 | | | 1867 | |
1868 | /* | | 1868 | /* |
1869 | * Allocate a new bus tag and have it inherit the methods of the | | 1869 | * Allocate a new bus tag and have it inherit the methods of the |
1870 | * given parent. | | 1870 | * given parent. |
1871 | */ | | 1871 | */ |
1872 | bus_space_tag_t | | 1872 | bus_space_tag_t |
1873 | bus_space_tag_alloc(bus_space_tag_t parent, void *cookie) | | 1873 | bus_space_tag_alloc(bus_space_tag_t parent, void *cookie) |
1874 | { | | 1874 | { |
1875 | struct sparc_bus_space_tag *sbt; | | 1875 | struct sparc_bus_space_tag *sbt; |
1876 | | | 1876 | |
1877 | sbt = malloc(sizeof(struct sparc_bus_space_tag), | | 1877 | sbt = malloc(sizeof(struct sparc_bus_space_tag), |
1878 | M_DEVBUF, M_NOWAIT|M_ZERO); | | 1878 | M_DEVBUF, M_NOWAIT|M_ZERO); |
1879 | if (sbt == NULL) | | 1879 | if (sbt == NULL) |
1880 | return (NULL); | | 1880 | return (NULL); |
1881 | | | 1881 | |
1882 | if (parent) { | | 1882 | if (parent) { |
1883 | memcpy(sbt, parent, sizeof(*sbt)); | | 1883 | memcpy(sbt, parent, sizeof(*sbt)); |
1884 | sbt->parent = parent; | | 1884 | sbt->parent = parent; |
1885 | sbt->ranges = NULL; | | 1885 | sbt->ranges = NULL; |
1886 | sbt->nranges = 0; | | 1886 | sbt->nranges = 0; |
1887 | } | | 1887 | } |
1888 | | | 1888 | |
1889 | sbt->cookie = cookie; | | 1889 | sbt->cookie = cookie; |
1890 | return (sbt); | | 1890 | return (sbt); |
1891 | } | | 1891 | } |
1892 | | | 1892 | |
1893 | /* | | 1893 | /* |
1894 | * Generic routine to translate an address using OpenPROM `ranges'. | | 1894 | * Generic routine to translate an address using OpenPROM `ranges'. |
1895 | */ | | 1895 | */ |
1896 | int | | 1896 | int |
1897 | bus_space_translate_address_generic(struct openprom_range *ranges, int nranges, | | 1897 | bus_space_translate_address_generic(struct openprom_range *ranges, int nranges, |
1898 | bus_addr_t *bap) | | 1898 | bus_addr_t *bap) |
1899 | { | | 1899 | { |
1900 | int i, space = BUS_ADDR_IOSPACE(*bap); | | 1900 | int i, space = BUS_ADDR_IOSPACE(*bap); |
1901 | | | 1901 | |
1902 | for (i = 0; i < nranges; i++) { | | 1902 | for (i = 0; i < nranges; i++) { |
1903 | struct openprom_range *rp = &ranges[i]; | | 1903 | struct openprom_range *rp = &ranges[i]; |
1904 | | | 1904 | |
1905 | if (rp->or_child_space != space) | | 1905 | if (rp->or_child_space != space) |
1906 | continue; | | 1906 | continue; |
1907 | | | 1907 | |
1908 | /* We've found the connection to the parent bus. */ | | 1908 | /* We've found the connection to the parent bus. */ |
1909 | *bap = BUS_ADDR(rp->or_parent_space, | | 1909 | *bap = BUS_ADDR(rp->or_parent_space, |
1910 | rp->or_parent_base + BUS_ADDR_PADDR(*bap)); | | 1910 | rp->or_parent_base + BUS_ADDR_PADDR(*bap)); |
1911 | return (0); | | 1911 | return (0); |
1912 | } | | 1912 | } |
1913 | | | 1913 | |
1914 | return (EINVAL); | | 1914 | return (EINVAL); |
1915 | } | | 1915 | } |
1916 | | | 1916 | |
1917 | int | | 1917 | static int |
1918 | sparc_bus_map(bus_space_tag_t t, bus_addr_t ba, bus_size_t size, int flags, | | 1918 | sparc_bus_map_iodev(bus_space_tag_t t, bus_addr_t ba, bus_size_t size, int flags, |
1919 | vaddr_t va, bus_space_handle_t *hp) | | 1919 | vaddr_t va, bus_space_handle_t *hp) |
1920 | { | | 1920 | { |
1921 | vaddr_t v; | | 1921 | vaddr_t v; |
1922 | paddr_t pa; | | 1922 | paddr_t pa; |
1923 | unsigned int pmtype; | | 1923 | unsigned int pmtype; |
1924 | bus_space_tag_t pt; | | 1924 | bus_space_tag_t pt; |
1925 | static vaddr_t iobase; | | 1925 | static vaddr_t iobase; |
1926 | | | 1926 | |
1927 | /* | | 1927 | /* |
1928 | * This base class bus map function knows about address range | | 1928 | * This base class bus map function knows about address range |
1929 | * translation so bus drivers that need no other special | | 1929 | * translation so bus drivers that need no other special |
1930 | * handling can just keep this method in their tags. | | 1930 | * handling can just keep this method in their tags. |
1931 | * | | 1931 | * |
1932 | * We expect to resolve range translations iteratively, but allow | | 1932 | * We expect to resolve range translations iteratively, but allow |
1933 | * for recursion just in case. | | 1933 | * for recursion just in case. |
1934 | */ | | 1934 | */ |
1935 | while ((pt = t->parent) != NULL) { | | 1935 | while ((pt = t->parent) != NULL) { |
1936 | if (t->ranges != NULL) { | | 1936 | if (t->ranges != NULL) { |
1937 | int error; | | 1937 | int error; |
1938 | | | 1938 | |
1939 | if ((error = bus_space_translate_address_generic( | | 1939 | if ((error = bus_space_translate_address_generic( |
1940 | t->ranges, t->nranges, &ba)) != 0) | | 1940 | t->ranges, t->nranges, &ba)) != 0) |
1941 | return (error); | | 1941 | return (error); |
1942 | } | | 1942 | } |
1943 | if (pt->sparc_bus_map != sparc_bus_map) | | 1943 | if (pt->sparc_bus_map != sparc_bus_map) |
1944 | return (bus_space_map2(pt, ba, size, flags, va, hp)); | | 1944 | return (bus_space_map2(pt, ba, size, flags, va, hp)); |
1945 | t = pt; | | 1945 | t = pt; |
1946 | } | | 1946 | } |
1947 | | | 1947 | |
1948 | if (iobase == 0) | | 1948 | if (iobase == 0) |
1949 | iobase = IODEV_BASE; | | 1949 | iobase = IODEV_BASE; |
1950 | | | 1950 | |
1951 | size = round_page(size); | | 1951 | size = round_page(size); |
1952 | if (size == 0) { | | 1952 | if (size == 0) { |
1953 | printf("sparc_bus_map: zero size\n"); | | 1953 | printf("sparc_bus_map: zero size\n"); |
1954 | return (EINVAL); | | 1954 | return (EINVAL); |
1955 | } | | 1955 | } |
1956 | | | 1956 | |
1957 | if (va) | | 1957 | if (va) |
1958 | v = trunc_page(va); | | 1958 | v = trunc_page(va); |
1959 | else { | | 1959 | else { |
1960 | v = iobase; | | 1960 | v = iobase; |
1961 | iobase += size; | | 1961 | iobase += size; |
1962 | if (iobase > IODEV_END) /* unlikely */ | | 1962 | if (iobase > IODEV_END) /* unlikely */ |
1963 | panic("sparc_bus_map: iobase=0x%lx", iobase); | | 1963 | panic("sparc_bus_map: iobase=0x%lx", iobase); |
1964 | } | | 1964 | } |
1965 | | | 1965 | |
1966 | pmtype = PMAP_IOENC(BUS_ADDR_IOSPACE(ba)); | | 1966 | pmtype = PMAP_IOENC(BUS_ADDR_IOSPACE(ba)); |
1967 | pa = BUS_ADDR_PADDR(ba); | | 1967 | pa = BUS_ADDR_PADDR(ba); |
1968 | | | 1968 | |
1969 | /* note: preserve page offset */ | | 1969 | /* note: preserve page offset */ |
1970 | *hp = (bus_space_handle_t)(v | ((u_long)pa & PGOFSET)); | | 1970 | *hp = (bus_space_handle_t)(v | ((u_long)pa & PGOFSET)); |
1971 | | | 1971 | |
1972 | pa = trunc_page(pa); | | 1972 | pa = trunc_page(pa); |
1973 | do { | | 1973 | do { |
1974 | pmap_kenter_pa(v, pa | pmtype | PMAP_NC, | | 1974 | pmap_kenter_pa(v, pa | pmtype | PMAP_NC, |
1975 | VM_PROT_READ | VM_PROT_WRITE); | | 1975 | VM_PROT_READ | VM_PROT_WRITE); |
1976 | v += PAGE_SIZE; | | 1976 | v += PAGE_SIZE; |
1977 | pa += PAGE_SIZE; | | 1977 | pa += PAGE_SIZE; |
1978 | } while ((size -= PAGE_SIZE) > 0); | | 1978 | } while ((size -= PAGE_SIZE) > 0); |
1979 | | | 1979 | |
1980 | pmap_update(pmap_kernel()); | | 1980 | pmap_update(pmap_kernel()); |
1981 | return (0); | | 1981 | return (0); |
1982 | } | | 1982 | } |
1983 | | | 1983 | |
1984 | int | | 1984 | static int |
1985 | sparc_bus_map_large(bus_space_tag_t t, int slot, bus_size_t offset, | | 1985 | sparc_bus_map_large(bus_space_tag_t t, bus_addr_t ba, |
1986 | bus_size_t size, int flags, bus_space_handle_t *hp) | | 1986 | bus_size_t size, int flags, bus_space_handle_t *hp) |
1987 | { | | 1987 | { |
1988 | bus_addr_t pa = BUS_ADDR(slot,offset); | | | |
1989 | vaddr_t v = 0; | | 1988 | vaddr_t v = 0; |
1990 | | | 1989 | |
1991 | if (uvm_map(kernel_map, &v, size, NULL, 0, PAGE_SIZE, | | 1990 | if (uvm_map(kernel_map, &v, size, NULL, 0, PAGE_SIZE, |
1992 | UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, UVM_INH_SHARE, UVM_ADV_NORMAL, | | 1991 | UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, UVM_INH_SHARE, UVM_ADV_NORMAL, |
1993 | 0)) == 0) { | | 1992 | 0)) == 0) { |
1994 | return sparc_bus_map(t, pa, size, flags, v, hp); | | 1993 | return sparc_bus_map_iodev(t, ba, size, flags, v, hp); |
1995 | } | | 1994 | } |
1996 | return -1; | | 1995 | return -1; |
1997 | } | | 1996 | } |
1998 | | | 1997 | |
1999 | int | | 1998 | int |
| | | 1999 | sparc_bus_map(bus_space_tag_t t, bus_addr_t ba, |
| | | 2000 | bus_size_t size, int flags, vaddr_t va, |
| | | 2001 | bus_space_handle_t *hp) |
| | | 2002 | { |
| | | 2003 | |
| | | 2004 | if (flags & BUS_SPACE_MAP_LARGE) { |
| | | 2005 | return sparc_bus_map_large(t, ba, size, flags, hp); |
| | | 2006 | } else |
| | | 2007 | return sparc_bus_map_iodev(t, ba, size, flags, va, hp); |
| | | 2008 | |
| | | 2009 | } |
| | | 2010 | |
| | | 2011 | int |
2000 | sparc_bus_unmap(bus_space_tag_t t, bus_space_handle_t bh, bus_size_t size) | | 2012 | sparc_bus_unmap(bus_space_tag_t t, bus_space_handle_t bh, bus_size_t size) |
2001 | { | | 2013 | { |
2002 | vaddr_t va = trunc_page((vaddr_t)bh); | | 2014 | vaddr_t va = trunc_page((vaddr_t)bh); |
2003 | | | 2015 | |
2004 | /* | | 2016 | /* |
2005 | * XXX | | 2017 | * XXX |
2006 | * mappings from sparc_bus_map_large() probably need additional care | | 2018 | * mappings with BUS_SPACE_MAP_LARGE need additional care here |
2007 | * here | | 2019 | * we can just check if the VA is in the IODEV range |
2008 | */ | | 2020 | */ |
2009 | | | 2021 | |
2010 | pmap_kremove(va, round_page(size)); | | 2022 | pmap_kremove(va, round_page(size)); |
2011 | pmap_update(pmap_kernel()); | | 2023 | pmap_update(pmap_kernel()); |
2012 | return (0); | | 2024 | return (0); |
2013 | } | | 2025 | } |
2014 | | | 2026 | |
2015 | int | | 2027 | int |
2016 | sparc_bus_subregion(bus_space_tag_t tag, bus_space_handle_t handle, | | 2028 | sparc_bus_subregion(bus_space_tag_t tag, bus_space_handle_t handle, |
2017 | bus_size_t offset, bus_size_t size, | | 2029 | bus_size_t offset, bus_size_t size, |
2018 | bus_space_handle_t *nhandlep) | | 2030 | bus_space_handle_t *nhandlep) |
2019 | { | | 2031 | { |
2020 | | | 2032 | |
2021 | *nhandlep = handle + offset; | | 2033 | *nhandlep = handle + offset; |
2022 | return (0); | | 2034 | return (0); |
2023 | } | | 2035 | } |
2024 | | | 2036 | |
2025 | paddr_t | | 2037 | paddr_t |
2026 | sparc_bus_mmap(bus_space_tag_t t, bus_addr_t ba, off_t off, | | 2038 | sparc_bus_mmap(bus_space_tag_t t, bus_addr_t ba, off_t off, |
2027 | int prot, int flags) | | 2039 | int prot, int flags) |
2028 | { | | 2040 | { |
2029 | u_int pmtype; | | 2041 | u_int pmtype; |
2030 | paddr_t pa; | | 2042 | paddr_t pa; |
2031 | bus_space_tag_t pt; | | 2043 | bus_space_tag_t pt; |
2032 | | | 2044 | |
2033 | /* | | 2045 | /* |
2034 | * Base class bus mmap function; see also sparc_bus_map | | 2046 | * Base class bus mmap function; see also sparc_bus_map |
2035 | */ | | 2047 | */ |
2036 | while ((pt = t->parent) != NULL) { | | 2048 | while ((pt = t->parent) != NULL) { |
2037 | if (t->ranges != NULL) { | | 2049 | if (t->ranges != NULL) { |
2038 | int error; | | 2050 | int error; |
2039 | | | 2051 | |
2040 | if ((error = bus_space_translate_address_generic( | | 2052 | if ((error = bus_space_translate_address_generic( |
2041 | t->ranges, t->nranges, &ba)) != 0) | | 2053 | t->ranges, t->nranges, &ba)) != 0) |
2042 | return (-1); | | 2054 | return (-1); |
2043 | } | | 2055 | } |
2044 | if (pt->sparc_bus_mmap != sparc_bus_mmap) | | 2056 | if (pt->sparc_bus_mmap != sparc_bus_mmap) |
2045 | return (bus_space_mmap(pt, ba, off, prot, flags)); | | 2057 | return (bus_space_mmap(pt, ba, off, prot, flags)); |
2046 | t = pt; | | 2058 | t = pt; |
2047 | } | | 2059 | } |
2048 | | | 2060 | |
2049 | pmtype = PMAP_IOENC(BUS_ADDR_IOSPACE(ba)); | | 2061 | pmtype = PMAP_IOENC(BUS_ADDR_IOSPACE(ba)); |
2050 | pa = trunc_page(BUS_ADDR_PADDR(ba) + off); | | 2062 | pa = trunc_page(BUS_ADDR_PADDR(ba) + off); |
2051 | | | 2063 | |
2052 | return (paddr_t)(pa | pmtype | PMAP_NC); | | 2064 | return (paddr_t)(pa | pmtype | PMAP_NC); |
2053 | } | | 2065 | } |
2054 | | | 2066 | |
2055 | /* | | 2067 | /* |
2056 | * Establish a temporary bus mapping for device probing. | | 2068 | * Establish a temporary bus mapping for device probing. |
2057 | */ | | 2069 | */ |
2058 | int | | 2070 | int |
2059 | bus_space_probe(bus_space_tag_t tag, bus_addr_t paddr, bus_size_t size, | | 2071 | bus_space_probe(bus_space_tag_t tag, bus_addr_t paddr, bus_size_t size, |
2060 | size_t offset, int flags, | | 2072 | size_t offset, int flags, |
2061 | int (*callback)(void *, void *), void *arg) | | 2073 | int (*callback)(void *, void *), void *arg) |
2062 | { | | 2074 | { |
2063 | bus_space_handle_t bh; | | 2075 | bus_space_handle_t bh; |
2064 | void *tmp; | | 2076 | void *tmp; |
2065 | int result; | | 2077 | int result; |
2066 | | | 2078 | |
2067 | if (bus_space_map2(tag, paddr, size, flags, TMPMAP_VA, &bh) != 0) | | 2079 | if (bus_space_map2(tag, paddr, size, flags, TMPMAP_VA, &bh) != 0) |
2068 | return (0); | | 2080 | return (0); |
2069 | | | 2081 | |
2070 | tmp = (void *)bh; | | 2082 | tmp = (void *)bh; |
2071 | result = (probeget((char *)tmp + offset, size) != -1); | | 2083 | result = (probeget((char *)tmp + offset, size) != -1); |
2072 | if (result && callback != NULL) | | 2084 | if (result && callback != NULL) |
2073 | result = (*callback)(tmp, arg); | | 2085 | result = (*callback)(tmp, arg); |
2074 | bus_space_unmap(tag, bh, size); | | 2086 | bus_space_unmap(tag, bh, size); |
2075 | return (result); | | 2087 | return (result); |
2076 | } | | 2088 | } |
2077 | | | 2089 | |
2078 | | | 2090 | |
2079 | void * | | 2091 | void * |
2080 | sparc_mainbus_intr_establish(bus_space_tag_t t, int pil, int level, | | 2092 | sparc_mainbus_intr_establish(bus_space_tag_t t, int pil, int level, |
2081 | int (*handler)(void *), void *arg, | | 2093 | int (*handler)(void *), void *arg, |
2082 | void (*fastvec)(void)) | | 2094 | void (*fastvec)(void)) |
2083 | { | | 2095 | { |
2084 | struct intrhand *ih; | | 2096 | struct intrhand *ih; |
2085 | | | 2097 | |
2086 | ih = (struct intrhand *) | | 2098 | ih = (struct intrhand *) |
2087 | malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT); | | 2099 | malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT); |
2088 | if (ih == NULL) | | 2100 | if (ih == NULL) |
2089 | return (NULL); | | 2101 | return (NULL); |
2090 | | | 2102 | |
2091 | ih->ih_fun = handler; | | 2103 | ih->ih_fun = handler; |
2092 | ih->ih_arg = arg; | | 2104 | ih->ih_arg = arg; |
2093 | intr_establish(pil, level, ih, fastvec); | | 2105 | intr_establish(pil, level, ih, fastvec); |
2094 | return (ih); | | 2106 | return (ih); |
2095 | } | | 2107 | } |
2096 | | | 2108 | |
2097 | void sparc_bus_barrier (bus_space_tag_t t, bus_space_handle_t h, | | 2109 | void sparc_bus_barrier (bus_space_tag_t t, bus_space_handle_t h, |
2098 | bus_size_t offset, bus_size_t size, int flags) | | 2110 | bus_size_t offset, bus_size_t size, int flags) |
2099 | { | | 2111 | { |
2100 | | | 2112 | |
2101 | /* No default barrier action defined */ | | 2113 | /* No default barrier action defined */ |
2102 | return; | | 2114 | return; |
2103 | } | | 2115 | } |
2104 | | | 2116 | |
2105 | static uint8_t | | 2117 | static uint8_t |
2106 | sparc_bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) | | 2118 | sparc_bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) |
2107 | { | | 2119 | { |
2108 | | | 2120 | |
2109 | return bus_space_read_1_real(t, h, o); | | 2121 | return bus_space_read_1_real(t, h, o); |
2110 | } | | 2122 | } |
2111 | | | 2123 | |
2112 | static uint16_t | | 2124 | static uint16_t |
2113 | sparc_bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) | | 2125 | sparc_bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) |
2114 | { | | 2126 | { |
2115 | | | 2127 | |
2116 | return bus_space_read_2_real(t, h, o); | | 2128 | return bus_space_read_2_real(t, h, o); |
2117 | } | | 2129 | } |
2118 | | | 2130 | |
2119 | static uint32_t | | 2131 | static uint32_t |
2120 | sparc_bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) | | 2132 | sparc_bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) |
2121 | { | | 2133 | { |
2122 | | | 2134 | |
2123 | return bus_space_read_4_real(t, h, o); | | 2135 | return bus_space_read_4_real(t, h, o); |
2124 | } | | 2136 | } |
2125 | | | 2137 | |
2126 | static uint64_t | | 2138 | static uint64_t |
2127 | sparc_bus_space_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) | | 2139 | sparc_bus_space_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) |
2128 | { | | 2140 | { |
2129 | | | 2141 | |
2130 | return bus_space_read_8_real(t, h, o); | | 2142 | return bus_space_read_8_real(t, h, o); |
2131 | } | | 2143 | } |
2132 | | | 2144 | |
2133 | static void | | 2145 | static void |
2134 | sparc_bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, | | 2146 | sparc_bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, |
2135 | uint8_t v) | | 2147 | uint8_t v) |
2136 | { | | 2148 | { |
2137 | | | 2149 | |
2138 | bus_space_write_1_real(t, h, o, v); | | 2150 | bus_space_write_1_real(t, h, o, v); |
2139 | } | | 2151 | } |
2140 | | | 2152 | |
2141 | static void | | 2153 | static void |
2142 | sparc_bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, | | 2154 | sparc_bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, |
2143 | uint16_t v) | | 2155 | uint16_t v) |
2144 | { | | 2156 | { |
2145 | | | 2157 | |
2146 | bus_space_write_2_real(t, h, o, v); | | 2158 | bus_space_write_2_real(t, h, o, v); |
2147 | } | | 2159 | } |
2148 | | | 2160 | |
2149 | static void | | 2161 | static void |
2150 | sparc_bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, | | 2162 | sparc_bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, |
2151 | uint32_t v) | | 2163 | uint32_t v) |
2152 | { | | 2164 | { |
2153 | | | 2165 | |
2154 | bus_space_write_4_real(t, h, o, v); | | 2166 | bus_space_write_4_real(t, h, o, v); |
2155 | } | | 2167 | } |
2156 | | | 2168 | |
2157 | static void | | 2169 | static void |
2158 | sparc_bus_space_write_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, | | 2170 | sparc_bus_space_write_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, |
2159 | uint64_t v) | | 2171 | uint64_t v) |
2160 | { | | 2172 | { |
2161 | | | 2173 | |
2162 | bus_space_write_8_real(t, h, o, v); | | 2174 | bus_space_write_8_real(t, h, o, v); |
2163 | } | | 2175 | } |
2164 | | | 2176 | |
2165 | struct sparc_bus_space_tag mainbus_space_tag = { | | 2177 | struct sparc_bus_space_tag mainbus_space_tag = { |
2166 | NULL, /* cookie */ | | 2178 | NULL, /* cookie */ |
2167 | NULL, /* parent bus tag */ | | 2179 | NULL, /* parent bus tag */ |
2168 | NULL, /* ranges */ | | 2180 | NULL, /* ranges */ |
2169 | 0, /* nranges */ | | 2181 | 0, /* nranges */ |
2170 | sparc_bus_map, /* bus_space_map */ | | 2182 | sparc_bus_map, /* bus_space_map */ |
2171 | sparc_bus_unmap, /* bus_space_unmap */ | | 2183 | sparc_bus_unmap, /* bus_space_unmap */ |
2172 | sparc_bus_subregion, /* bus_space_subregion */ | | 2184 | sparc_bus_subregion, /* bus_space_subregion */ |
2173 | sparc_bus_barrier, /* bus_space_barrier */ | | 2185 | sparc_bus_barrier, /* bus_space_barrier */ |
2174 | sparc_bus_mmap, /* bus_space_mmap */ | | 2186 | sparc_bus_mmap, /* bus_space_mmap */ |
2175 | sparc_mainbus_intr_establish, /* bus_intr_establish */ | | 2187 | sparc_mainbus_intr_establish, /* bus_intr_establish */ |
2176 | | | 2188 | |
2177 | sparc_bus_space_read_1, /* bus_space_read_1 */ | | 2189 | sparc_bus_space_read_1, /* bus_space_read_1 */ |
2178 | sparc_bus_space_read_2, /* bus_space_read_2 */ | | 2190 | sparc_bus_space_read_2, /* bus_space_read_2 */ |
2179 | sparc_bus_space_read_4, /* bus_space_read_4 */ | | 2191 | sparc_bus_space_read_4, /* bus_space_read_4 */ |
2180 | sparc_bus_space_read_8, /* bus_space_read_8 */ | | 2192 | sparc_bus_space_read_8, /* bus_space_read_8 */ |
2181 | sparc_bus_space_write_1, /* bus_space_write_1 */ | | 2193 | sparc_bus_space_write_1, /* bus_space_write_1 */ |
2182 | sparc_bus_space_write_2, /* bus_space_write_2 */ | | 2194 | sparc_bus_space_write_2, /* bus_space_write_2 */ |
2183 | sparc_bus_space_write_4, /* bus_space_write_4 */ | | 2195 | sparc_bus_space_write_4, /* bus_space_write_4 */ |
2184 | sparc_bus_space_write_8 /* bus_space_write_8 */ | | 2196 | sparc_bus_space_write_8 /* bus_space_write_8 */ |
2185 | }; | | 2197 | }; |