arm32_machdep.c revision 1.102 1 /* $NetBSD: arm32_machdep.c,v 1.102 2014/03/28 21:39:09 matt Exp $ */
2
3 /*
4 * Copyright (c) 1994-1998 Mark Brinicombe.
5 * Copyright (c) 1994 Brini.
6 * All rights reserved.
7 *
8 * This code is derived from software written for Brini by Mark Brinicombe
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Mark Brinicombe
21 * for the NetBSD Project.
22 * 4. The name of the company nor the name of the author may be used to
23 * endorse or promote products derived from this software without specific
24 * prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * Machine dependent functions for kernel setup
39 *
40 * Created : 17/09/94
41 * Updated : 18/04/01 updated for new wscons
42 */
43
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.102 2014/03/28 21:39:09 matt Exp $");
46
47 #include "opt_modular.h"
48 #include "opt_md.h"
49 #include "opt_pmap_debug.h"
50
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/reboot.h>
54 #include <sys/proc.h>
55 #include <sys/kauth.h>
56 #include <sys/kernel.h>
57 #include <sys/mbuf.h>
58 #include <sys/mount.h>
59 #include <sys/buf.h>
60 #include <sys/msgbuf.h>
61 #include <sys/device.h>
62 #include <sys/sysctl.h>
63 #include <sys/cpu.h>
64 #include <sys/intr.h>
65 #include <sys/module.h>
66 #include <sys/atomic.h>
67 #include <sys/xcall.h>
68
69 #include <uvm/uvm_extern.h>
70
71 #include <dev/cons.h>
72 #include <dev/mm.h>
73
74 #include <arm/locore.h>
75
76 #include <arm/arm32/katelib.h>
77 #include <arm/arm32/machdep.h>
78
79 #include <machine/bootconfig.h>
80 #include <machine/pcb.h>
81
82 void (*cpu_reset_address)(void); /* Used by locore */
83 paddr_t cpu_reset_address_paddr; /* Used by locore */
84
85 struct vm_map *phys_map = NULL;
86
87 #if defined(MEMORY_DISK_HOOKS) && !defined(MEMORY_DISK_ROOT_SIZE)
88 extern size_t md_root_size; /* Memory disc size */
89 #endif /* MEMORY_DISK_HOOKS && !MEMORY_DISK_ROOT_SIZE */
90
91 pv_addr_t kernelstack;
92 pv_addr_t abtstack;
93 pv_addr_t fiqstack;
94 pv_addr_t irqstack;
95 pv_addr_t undstack;
96 pv_addr_t idlestack;
97
98 void * msgbufaddr;
99 extern paddr_t msgbufphys;
100
101 int kernel_debug = 0;
102 int cpu_printfataltraps = 0;
103 int cpu_fpu_present;
104 int cpu_hwdiv_present;
105 int cpu_neon_present;
106 int cpu_simd_present;
107 int cpu_simdex_present;
108 int cpu_umull_present;
109 int cpu_synchprim_present;
110 const char *cpu_arch = "";
111
112 int cpu_instruction_set_attributes[6];
113 int cpu_memory_model_features[4];
114 int cpu_processor_features[2];
115 int cpu_media_and_vfp_features[2];
116
117 /* exported variable to be filled in by the bootloaders */
118 char *booted_kernel;
119
120 /* Prototypes */
121
122 void data_abort_handler(trapframe_t *frame);
123 void prefetch_abort_handler(trapframe_t *frame);
124 extern void configure(void);
125
126 /*
127 * arm32_vector_init:
128 *
129 * Initialize the vector page, and select whether or not to
130 * relocate the vectors.
131 *
132 * NOTE: We expect the vector page to be mapped at its expected
133 * destination.
134 */
135 void
136 arm32_vector_init(vaddr_t va, int which)
137 {
138 #if defined(CPU_ARMV7) || defined(CPU_ARM11) || defined(ARM_HAS_VBAR)
139 /*
140 * If this processor has the security extension, don't bother
141 * to move/map the vector page. Simply point VBAR to the copy
142 * that exists in the .text segment.
143 */
144 #ifndef ARM_HAS_VBAR
145 if (va == ARM_VECTORS_LOW
146 && (armreg_pfr1_read() & ARM_PFR1_SEC_MASK) != 0) {
147 #endif
148 extern const uint32_t page0rel[];
149 vector_page = (vaddr_t)page0rel;
150 KASSERT((vector_page & 0x1f) == 0);
151 armreg_vbar_write(vector_page);
152 #ifdef VERBOSE_INIT_ARM
153 printf(" vbar=%p", page0rel);
154 #endif
155 cpu_control(CPU_CONTROL_VECRELOC, 0);
156 return;
157 #ifndef ARM_HAS_VBAR
158 }
159 #endif
160 #endif
161 #ifndef ARM_HAS_VBAR
162 if (CPU_IS_PRIMARY(curcpu())) {
163 extern unsigned int page0[], page0_data[];
164 unsigned int *vectors = (int *) va;
165 unsigned int *vectors_data = vectors + (page0_data - page0);
166 int vec;
167
168 /*
169 * Loop through the vectors we're taking over, and copy the
170 * vector's insn and data word.
171 */
172 for (vec = 0; vec < ARM_NVEC; vec++) {
173 if ((which & (1 << vec)) == 0) {
174 /* Don't want to take over this vector. */
175 continue;
176 }
177 vectors[vec] = page0[vec];
178 vectors_data[vec] = page0_data[vec];
179 }
180
181 /* Now sync the vectors. */
182 cpu_icache_sync_range(va, (ARM_NVEC * 2) * sizeof(u_int));
183
184 vector_page = va;
185 }
186
187 if (va == ARM_VECTORS_HIGH) {
188 /*
189 * Assume the MD caller knows what it's doing here, and
190 * really does want the vector page relocated.
191 *
192 * Note: This has to be done here (and not just in
193 * cpu_setup()) because the vector page needs to be
194 * accessible *before* cpu_startup() is called.
195 * Think ddb(9) ...
196 *
197 * NOTE: If the CPU control register is not readable,
198 * this will totally fail! We'll just assume that
199 * any system that has high vector support has a
200 * readable CPU control register, for now. If we
201 * ever encounter one that does not, we'll have to
202 * rethink this.
203 */
204 cpu_control(CPU_CONTROL_VECRELOC, CPU_CONTROL_VECRELOC);
205 }
206 #endif
207 }
208
209 /*
210 * Debug function just to park the CPU
211 */
212
213 void
214 halt(void)
215 {
216 while (1)
217 cpu_sleep(0);
218 }
219
220
221 /* Sync the discs, unmount the filesystems, and adjust the todr */
222
223 void
224 bootsync(void)
225 {
226 static bool bootsyncdone = false;
227
228 if (bootsyncdone) return;
229
230 bootsyncdone = true;
231
232 /* Make sure we can still manage to do things */
233 if (GetCPSR() & I32_bit) {
234 /*
235 * If we get here then boot has been called without RB_NOSYNC
236 * and interrupts were disabled. This means the boot() call
237 * did not come from a user process e.g. shutdown, but must
238 * have come from somewhere in the kernel.
239 */
240 IRQenable;
241 printf("Warning IRQ's disabled during boot()\n");
242 }
243
244 vfs_shutdown();
245
246 resettodr();
247 }
248
249 /*
250 * void cpu_startup(void)
251 *
252 * Machine dependent startup code.
253 *
254 */
255 void
256 cpu_startup(void)
257 {
258 vaddr_t minaddr;
259 vaddr_t maxaddr;
260 u_int loop;
261 char pbuf[9];
262
263 /*
264 * Until we better locking, we have to live under the kernel lock.
265 */
266 //KERNEL_LOCK(1, NULL);
267
268 /* Set the CPU control register */
269 cpu_setup(boot_args);
270
271 #ifndef ARM_HAS_VBAR
272 /* Lock down zero page */
273 vector_page_setprot(VM_PROT_READ);
274 #endif
275
276 /*
277 * Give pmap a chance to set up a few more things now the vm
278 * is initialised
279 */
280 pmap_postinit();
281
282 /*
283 * Initialize error message buffer (at end of core).
284 */
285
286 /* msgbufphys was setup during the secondary boot strap */
287 for (loop = 0; loop < btoc(MSGBUFSIZE); ++loop)
288 pmap_kenter_pa((vaddr_t)msgbufaddr + loop * PAGE_SIZE,
289 msgbufphys + loop * PAGE_SIZE,
290 VM_PROT_READ|VM_PROT_WRITE, 0);
291 pmap_update(pmap_kernel());
292 initmsgbuf(msgbufaddr, round_page(MSGBUFSIZE));
293
294 /*
295 * Identify ourselves for the msgbuf (everything printed earlier will
296 * not be buffered).
297 */
298 printf("%s%s", copyright, version);
299
300 format_bytes(pbuf, sizeof(pbuf), arm_ptob(physmem));
301 printf("total memory = %s\n", pbuf);
302
303 minaddr = 0;
304
305 /*
306 * Allocate a submap for physio
307 */
308 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
309 VM_PHYS_SIZE, 0, false, NULL);
310
311 format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
312 printf("avail memory = %s\n", pbuf);
313
314 struct lwp * const l = &lwp0;
315 struct pcb * const pcb = lwp_getpcb(l);
316 pcb->pcb_ksp = uvm_lwp_getuarea(l) + USPACE_SVC_STACK_TOP;
317 lwp_settrapframe(l, (struct trapframe *)pcb->pcb_ksp - 1);
318 }
319
320 /*
321 * machine dependent system variables.
322 */
323 static int
324 sysctl_machdep_booted_device(SYSCTLFN_ARGS)
325 {
326 struct sysctlnode node;
327
328 if (booted_device == NULL)
329 return (EOPNOTSUPP);
330
331 node = *rnode;
332 node.sysctl_data = __UNCONST(device_xname(booted_device));
333 node.sysctl_size = strlen(device_xname(booted_device)) + 1;
334 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
335 }
336
337 static int
338 sysctl_machdep_booted_kernel(SYSCTLFN_ARGS)
339 {
340 struct sysctlnode node;
341
342 if (booted_kernel == NULL || booted_kernel[0] == '\0')
343 return (EOPNOTSUPP);
344
345 node = *rnode;
346 node.sysctl_data = booted_kernel;
347 node.sysctl_size = strlen(booted_kernel) + 1;
348 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
349 }
350
351 static int
352 sysctl_machdep_cpu_arch(SYSCTLFN_ARGS)
353 {
354 struct sysctlnode node = *rnode;
355 node.sysctl_data = __UNCONST(cpu_arch);
356 node.sysctl_size = strlen(cpu_arch) + 1;
357 return sysctl_lookup(SYSCTLFN_CALL(&node));
358 }
359
360 static int
361 sysctl_machdep_powersave(SYSCTLFN_ARGS)
362 {
363 struct sysctlnode node = *rnode;
364 int error, newval;
365
366 newval = cpu_do_powersave;
367 node.sysctl_data = &newval;
368 if (cpufuncs.cf_sleep == (void *) cpufunc_nullop)
369 node.sysctl_flags &= ~CTLFLAG_READWRITE;
370 error = sysctl_lookup(SYSCTLFN_CALL(&node));
371 if (error || newp == NULL || newval == cpu_do_powersave)
372 return (error);
373
374 if (newval < 0 || newval > 1)
375 return (EINVAL);
376 cpu_do_powersave = newval;
377
378 return (0);
379 }
380
381 static int
382 sysctl_hw_machine_arch(SYSCTLFN_ARGS)
383 {
384 struct sysctlnode node = *rnode;
385 node.sysctl_data = l->l_proc->p_md.md_march;
386 node.sysctl_size = strlen(l->l_proc->p_md.md_march) + 1;
387 return sysctl_lookup(SYSCTLFN_CALL(&node));
388 }
389
390 SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
391 {
392
393 sysctl_createv(clog, 0, NULL, NULL,
394 CTLFLAG_PERMANENT,
395 CTLTYPE_NODE, "machdep", NULL,
396 NULL, 0, NULL, 0,
397 CTL_MACHDEP, CTL_EOL);
398
399 sysctl_createv(clog, 0, NULL, NULL,
400 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
401 CTLTYPE_INT, "debug", NULL,
402 NULL, 0, &kernel_debug, 0,
403 CTL_MACHDEP, CPU_DEBUG, CTL_EOL);
404 sysctl_createv(clog, 0, NULL, NULL,
405 CTLFLAG_PERMANENT,
406 CTLTYPE_STRING, "booted_device", NULL,
407 sysctl_machdep_booted_device, 0, NULL, 0,
408 CTL_MACHDEP, CPU_BOOTED_DEVICE, CTL_EOL);
409 sysctl_createv(clog, 0, NULL, NULL,
410 CTLFLAG_PERMANENT,
411 CTLTYPE_STRING, "booted_kernel", NULL,
412 sysctl_machdep_booted_kernel, 0, NULL, 0,
413 CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL);
414 sysctl_createv(clog, 0, NULL, NULL,
415 CTLFLAG_PERMANENT,
416 CTLTYPE_STRUCT, "console_device", NULL,
417 sysctl_consdev, 0, NULL, sizeof(dev_t),
418 CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
419 sysctl_createv(clog, 0, NULL, NULL,
420 CTLFLAG_PERMANENT,
421 CTLTYPE_STRING, "cpu_arch", NULL,
422 sysctl_machdep_cpu_arch, 0, NULL, 0,
423 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
424 sysctl_createv(clog, 0, NULL, NULL,
425 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
426 CTLTYPE_INT, "powersave", NULL,
427 sysctl_machdep_powersave, 0, &cpu_do_powersave, 0,
428 CTL_MACHDEP, CPU_POWERSAVE, CTL_EOL);
429 sysctl_createv(clog, 0, NULL, NULL,
430 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
431 CTLTYPE_INT, "cpu_id", NULL,
432 NULL, curcpu()->ci_arm_cpuid, NULL, 0,
433 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
434 #ifdef FPU_VFP
435 sysctl_createv(clog, 0, NULL, NULL,
436 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
437 CTLTYPE_INT, "fpu_id", NULL,
438 NULL, 0, &cpu_info_store.ci_vfp_id, 0,
439 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
440 #endif
441 sysctl_createv(clog, 0, NULL, NULL,
442 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
443 CTLTYPE_INT, "fpu_present", NULL,
444 NULL, 0, &cpu_fpu_present, 0,
445 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
446 sysctl_createv(clog, 0, NULL, NULL,
447 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
448 CTLTYPE_INT, "hwdiv_present", NULL,
449 NULL, 0, &cpu_hwdiv_present, 0,
450 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
451 sysctl_createv(clog, 0, NULL, NULL,
452 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
453 CTLTYPE_INT, "neon_present", NULL,
454 NULL, 0, &cpu_neon_present, 0,
455 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
456 sysctl_createv(clog, 0, NULL, NULL,
457 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
458 CTLTYPE_STRUCT, "id_isar", NULL,
459 NULL, 0,
460 cpu_instruction_set_attributes,
461 sizeof(cpu_instruction_set_attributes),
462 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
463 sysctl_createv(clog, 0, NULL, NULL,
464 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
465 CTLTYPE_STRUCT, "id_mmfr", NULL,
466 NULL, 0,
467 cpu_memory_model_features,
468 sizeof(cpu_memory_model_features),
469 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
470 sysctl_createv(clog, 0, NULL, NULL,
471 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
472 CTLTYPE_STRUCT, "id_pfr", NULL,
473 NULL, 0,
474 cpu_processor_features,
475 sizeof(cpu_processor_features),
476 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
477 sysctl_createv(clog, 0, NULL, NULL,
478 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
479 CTLTYPE_STRUCT, "id_mvfr", NULL,
480 NULL, 0,
481 cpu_media_and_vfp_features,
482 sizeof(cpu_media_and_vfp_features),
483 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
484 sysctl_createv(clog, 0, NULL, NULL,
485 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
486 CTLTYPE_INT, "simd_present", NULL,
487 NULL, 0, &cpu_simd_present, 0,
488 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
489 sysctl_createv(clog, 0, NULL, NULL,
490 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
491 CTLTYPE_INT, "simdex_present", NULL,
492 NULL, 0, &cpu_simdex_present, 0,
493 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
494 sysctl_createv(clog, 0, NULL, NULL,
495 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
496 CTLTYPE_INT, "synchprim_present", NULL,
497 NULL, 0, &cpu_synchprim_present, 0,
498 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
499 sysctl_createv(clog, 0, NULL, NULL,
500 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
501 CTLTYPE_INT, "printfataltraps", NULL,
502 NULL, 0, &cpu_printfataltraps, 0,
503 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
504
505
506 /*
507 * We need override the usual CTL_HW HW_MACHINE_ARCH so we
508 * return the right machine_arch based on the running executable.
509 */
510 sysctl_createv(clog, 0, NULL, NULL,
511 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
512 CTLTYPE_STRING, "machine_arch",
513 SYSCTL_DESCR("Machine CPU class"),
514 sysctl_hw_machine_arch, 0, NULL, 0,
515 CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
516 }
517
518 void
519 parse_mi_bootargs(char *args)
520 {
521 int integer;
522
523 if (get_bootconf_option(args, "single", BOOTOPT_TYPE_BOOLEAN, &integer)
524 || get_bootconf_option(args, "-s", BOOTOPT_TYPE_BOOLEAN, &integer))
525 if (integer)
526 boothowto |= RB_SINGLE;
527 if (get_bootconf_option(args, "kdb", BOOTOPT_TYPE_BOOLEAN, &integer)
528 || get_bootconf_option(args, "-k", BOOTOPT_TYPE_BOOLEAN, &integer)
529 || get_bootconf_option(args, "-d", BOOTOPT_TYPE_BOOLEAN, &integer))
530 if (integer)
531 boothowto |= RB_KDB;
532 if (get_bootconf_option(args, "ask", BOOTOPT_TYPE_BOOLEAN, &integer)
533 || get_bootconf_option(args, "-a", BOOTOPT_TYPE_BOOLEAN, &integer))
534 if (integer)
535 boothowto |= RB_ASKNAME;
536
537 #ifdef PMAP_DEBUG
538 if (get_bootconf_option(args, "pmapdebug", BOOTOPT_TYPE_INT, &integer)) {
539 pmap_debug_level = integer;
540 pmap_debug(pmap_debug_level);
541 }
542 #endif /* PMAP_DEBUG */
543
544 /* if (get_bootconf_option(args, "nbuf", BOOTOPT_TYPE_INT, &integer))
545 bufpages = integer;*/
546
547 #if defined(MEMORY_DISK_HOOKS) && !defined(MEMORY_DISK_ROOT_SIZE)
548 if (get_bootconf_option(args, "memorydisc", BOOTOPT_TYPE_INT, &integer)
549 || get_bootconf_option(args, "memorydisk", BOOTOPT_TYPE_INT, &integer)) {
550 md_root_size = integer;
551 md_root_size *= 1024;
552 if (md_root_size < 32*1024)
553 md_root_size = 32*1024;
554 if (md_root_size > 2048*1024)
555 md_root_size = 2048*1024;
556 }
557 #endif /* MEMORY_DISK_HOOKS && !MEMORY_DISK_ROOT_SIZE */
558
559 if (get_bootconf_option(args, "quiet", BOOTOPT_TYPE_BOOLEAN, &integer)
560 || get_bootconf_option(args, "-q", BOOTOPT_TYPE_BOOLEAN, &integer))
561 if (integer)
562 boothowto |= AB_QUIET;
563 if (get_bootconf_option(args, "verbose", BOOTOPT_TYPE_BOOLEAN, &integer)
564 || get_bootconf_option(args, "-v", BOOTOPT_TYPE_BOOLEAN, &integer))
565 if (integer)
566 boothowto |= AB_VERBOSE;
567 }
568
569 #ifdef __HAVE_FAST_SOFTINTS
570 #if IPL_SOFTSERIAL != IPL_SOFTNET + 1
571 #error IPLs are screwed up
572 #elif IPL_SOFTNET != IPL_SOFTBIO + 1
573 #error IPLs are screwed up
574 #elif IPL_SOFTBIO != IPL_SOFTCLOCK + 1
575 #error IPLs are screwed up
576 #elif !(IPL_SOFTCLOCK > IPL_NONE)
577 #error IPLs are screwed up
578 #elif (IPL_NONE != 0)
579 #error IPLs are screwed up
580 #endif
581
582 #ifndef __HAVE_PIC_FAST_SOFTINTS
583 #define SOFTINT2IPLMAP \
584 (((IPL_SOFTSERIAL - IPL_SOFTCLOCK) << (SOFTINT_SERIAL * 4)) | \
585 ((IPL_SOFTNET - IPL_SOFTCLOCK) << (SOFTINT_NET * 4)) | \
586 ((IPL_SOFTBIO - IPL_SOFTCLOCK) << (SOFTINT_BIO * 4)) | \
587 ((IPL_SOFTCLOCK - IPL_SOFTCLOCK) << (SOFTINT_CLOCK * 4)))
588 #define SOFTINT2IPL(l) ((SOFTINT2IPLMAP >> ((l) * 4)) & 0x0f)
589
590 /*
591 * This returns a mask of softint IPLs that be dispatch at <ipl>
592 * SOFTIPLMASK(IPL_NONE) = 0x0000000f
593 * SOFTIPLMASK(IPL_SOFTCLOCK) = 0x0000000e
594 * SOFTIPLMASK(IPL_SOFTBIO) = 0x0000000c
595 * SOFTIPLMASK(IPL_SOFTNET) = 0x00000008
596 * SOFTIPLMASK(IPL_SOFTSERIAL) = 0x00000000
597 */
598 #define SOFTIPLMASK(ipl) ((0x0f << (ipl)) & 0x0f)
599
600 void softint_switch(lwp_t *, int);
601
602 void
603 softint_trigger(uintptr_t mask)
604 {
605 curcpu()->ci_softints |= mask;
606 }
607
608 void
609 softint_init_md(lwp_t *l, u_int level, uintptr_t *machdep)
610 {
611 lwp_t ** lp = &l->l_cpu->ci_softlwps[level];
612 KASSERT(*lp == NULL || *lp == l);
613 *lp = l;
614 *machdep = 1 << SOFTINT2IPL(level);
615 KASSERT(level != SOFTINT_CLOCK || *machdep == (1 << (IPL_SOFTCLOCK - IPL_SOFTCLOCK)));
616 KASSERT(level != SOFTINT_BIO || *machdep == (1 << (IPL_SOFTBIO - IPL_SOFTCLOCK)));
617 KASSERT(level != SOFTINT_NET || *machdep == (1 << (IPL_SOFTNET - IPL_SOFTCLOCK)));
618 KASSERT(level != SOFTINT_SERIAL || *machdep == (1 << (IPL_SOFTSERIAL - IPL_SOFTCLOCK)));
619 }
620
621 void
622 dosoftints(void)
623 {
624 struct cpu_info * const ci = curcpu();
625 const int opl = ci->ci_cpl;
626 const uint32_t softiplmask = SOFTIPLMASK(opl);
627
628 splhigh();
629 for (;;) {
630 u_int softints = ci->ci_softints & softiplmask;
631 KASSERT((softints != 0) == ((ci->ci_softints >> opl) != 0));
632 KASSERT(opl == IPL_NONE || (softints & (1 << (opl - IPL_SOFTCLOCK))) == 0);
633 if (softints == 0) {
634 splx(opl);
635 return;
636 }
637 #define DOSOFTINT(n) \
638 if (ci->ci_softints & (1 << (IPL_SOFT ## n - IPL_SOFTCLOCK))) { \
639 ci->ci_softints &= \
640 ~(1 << (IPL_SOFT ## n - IPL_SOFTCLOCK)); \
641 softint_switch(ci->ci_softlwps[SOFTINT_ ## n], \
642 IPL_SOFT ## n); \
643 continue; \
644 }
645 DOSOFTINT(SERIAL);
646 DOSOFTINT(NET);
647 DOSOFTINT(BIO);
648 DOSOFTINT(CLOCK);
649 panic("dosoftints wtf (softints=%u?, ipl=%d)", softints, opl);
650 }
651 }
652 #endif /* !__HAVE_PIC_FAST_SOFTINTS */
653 #endif /* __HAVE_FAST_SOFTINTS */
654
655 #ifdef MODULAR
656 /*
657 * Push any modules loaded by the boot loader.
658 */
659 void
660 module_init_md(void)
661 {
662 }
663 #endif /* MODULAR */
664
665 int
666 mm_md_physacc(paddr_t pa, vm_prot_t prot)
667 {
668
669 return (pa < ctob(physmem)) ? 0 : EFAULT;
670 }
671
672 #ifdef __HAVE_CPU_UAREA_ALLOC_IDLELWP
673 vaddr_t
674 cpu_uarea_alloc_idlelwp(struct cpu_info *ci)
675 {
676 const vaddr_t va = idlestack.pv_va + ci->ci_cpuid * USPACE;
677 // printf("%s: %s: va=%lx\n", __func__, ci->ci_data.cpu_name, va);
678 return va;
679 }
680 #endif
681
682 #ifdef MULTIPROCESSOR
683 void
684 cpu_boot_secondary_processors(void)
685 {
686 #ifdef VERBOSE_INIT_ARM
687 printf("%s: writing mbox with %#x\n", __func__, arm_cpu_hatched);
688 #endif
689 arm_cpu_mbox = arm_cpu_hatched;
690 membar_producer();
691 #ifdef _ARM_ARCH_7
692 __asm __volatile("sev; sev; sev");
693 #endif
694 while (arm_cpu_mbox) {
695 __asm("wfe");
696 }
697 }
698
699 void
700 xc_send_ipi(struct cpu_info *ci)
701 {
702 KASSERT(kpreempt_disabled());
703 KASSERT(curcpu() != ci);
704
705 intr_ipi_send(ci != NULL ? ci->ci_kcpuset : NULL, IPI_XCALL);
706 }
707 #endif /* MULTIPROCESSOR */
708
709 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
710 bool
711 mm_md_direct_mapped_phys(paddr_t pa, vaddr_t *vap)
712 {
713 if (physical_start <= pa && pa < physical_end) {
714 *vap = KERNEL_BASE + (pa - physical_start);
715 return true;
716 }
717
718 return false;
719 }
720 #endif
721