arm32_machdep.c revision 1.98 1 /* $NetBSD: arm32_machdep.c,v 1.98 2013/09/10 21:30:21 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.98 2013/09/10 21:30:21 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_fpu_present;
103 int cpu_hwdiv_present;
104 int cpu_neon_present;
105 int cpu_simd_present;
106 int cpu_simdex_present;
107 int cpu_umull_present;
108 const char *cpu_arch = "";
109
110 int cpu_instruction_set_attributes[6];
111 int cpu_memory_model_features[4];
112 int cpu_processor_features[2];
113 int cpu_media_and_vfp_features[2];
114
115 /* exported variable to be filled in by the bootloaders */
116 char *booted_kernel;
117
118 /* Prototypes */
119
120 void data_abort_handler(trapframe_t *frame);
121 void prefetch_abort_handler(trapframe_t *frame);
122 extern void configure(void);
123
124 /*
125 * arm32_vector_init:
126 *
127 * Initialize the vector page, and select whether or not to
128 * relocate the vectors.
129 *
130 * NOTE: We expect the vector page to be mapped at its expected
131 * destination.
132 */
133 void
134 arm32_vector_init(vaddr_t va, int which)
135 {
136 #if defined(CPU_ARMV7) || defined(CPU_ARM11) || defined(ARM_HAS_VBAR)
137 /*
138 * If this processor has the security extension, don't bother
139 * to move/map the vector page. Simply point VBAR to the copy
140 * that exists in the .text segment.
141 */
142 #ifndef ARM_HAS_VBAR
143 if (va == ARM_VECTORS_LOW
144 && (armreg_pfr1_read() & ARM_PFR1_SEC_MASK) != 0) {
145 #endif
146 extern const uint32_t page0rel[];
147 vector_page = (vaddr_t)page0rel;
148 KASSERT((vector_page & 0x1f) == 0);
149 armreg_vbar_write(vector_page);
150 #ifdef VERBOSE_INIT_ARM
151 printf(" vbar=%p", page0rel);
152 #endif
153 cpu_control(CPU_CONTROL_VECRELOC, 0);
154 return;
155 #ifndef ARM_HAS_VBAR
156 }
157 #endif
158 #endif
159 #ifndef ARM_HAS_VBAR
160 if (CPU_IS_PRIMARY(curcpu())) {
161 extern unsigned int page0[], page0_data[];
162 unsigned int *vectors = (int *) va;
163 unsigned int *vectors_data = vectors + (page0_data - page0);
164 int vec;
165
166 /*
167 * Loop through the vectors we're taking over, and copy the
168 * vector's insn and data word.
169 */
170 for (vec = 0; vec < ARM_NVEC; vec++) {
171 if ((which & (1 << vec)) == 0) {
172 /* Don't want to take over this vector. */
173 continue;
174 }
175 vectors[vec] = page0[vec];
176 vectors_data[vec] = page0_data[vec];
177 }
178
179 /* Now sync the vectors. */
180 cpu_icache_sync_range(va, (ARM_NVEC * 2) * sizeof(u_int));
181
182 vector_page = va;
183 }
184
185 if (va == ARM_VECTORS_HIGH) {
186 /*
187 * Assume the MD caller knows what it's doing here, and
188 * really does want the vector page relocated.
189 *
190 * Note: This has to be done here (and not just in
191 * cpu_setup()) because the vector page needs to be
192 * accessible *before* cpu_startup() is called.
193 * Think ddb(9) ...
194 *
195 * NOTE: If the CPU control register is not readable,
196 * this will totally fail! We'll just assume that
197 * any system that has high vector support has a
198 * readable CPU control register, for now. If we
199 * ever encounter one that does not, we'll have to
200 * rethink this.
201 */
202 cpu_control(CPU_CONTROL_VECRELOC, CPU_CONTROL_VECRELOC);
203 }
204 #endif
205 }
206
207 /*
208 * Debug function just to park the CPU
209 */
210
211 void
212 halt(void)
213 {
214 while (1)
215 cpu_sleep(0);
216 }
217
218
219 /* Sync the discs, unmount the filesystems, and adjust the todr */
220
221 void
222 bootsync(void)
223 {
224 static bool bootsyncdone = false;
225
226 if (bootsyncdone) return;
227
228 bootsyncdone = true;
229
230 /* Make sure we can still manage to do things */
231 if (GetCPSR() & I32_bit) {
232 /*
233 * If we get here then boot has been called without RB_NOSYNC
234 * and interrupts were disabled. This means the boot() call
235 * did not come from a user process e.g. shutdown, but must
236 * have come from somewhere in the kernel.
237 */
238 IRQenable;
239 printf("Warning IRQ's disabled during boot()\n");
240 }
241
242 vfs_shutdown();
243
244 resettodr();
245 }
246
247 /*
248 * void cpu_startup(void)
249 *
250 * Machine dependent startup code.
251 *
252 */
253 void
254 cpu_startup(void)
255 {
256 vaddr_t minaddr;
257 vaddr_t maxaddr;
258 u_int loop;
259 char pbuf[9];
260
261 /*
262 * Until we better locking, we have to live under the kernel lock.
263 */
264 //KERNEL_LOCK(1, NULL);
265
266 /* Set the CPU control register */
267 cpu_setup(boot_args);
268
269 #ifndef ARM_HAS_VBAR
270 /* Lock down zero page */
271 vector_page_setprot(VM_PROT_READ);
272 #endif
273
274 /*
275 * Give pmap a chance to set up a few more things now the vm
276 * is initialised
277 */
278 pmap_postinit();
279
280 /*
281 * Initialize error message buffer (at end of core).
282 */
283
284 /* msgbufphys was setup during the secondary boot strap */
285 for (loop = 0; loop < btoc(MSGBUFSIZE); ++loop)
286 pmap_kenter_pa((vaddr_t)msgbufaddr + loop * PAGE_SIZE,
287 msgbufphys + loop * PAGE_SIZE,
288 VM_PROT_READ|VM_PROT_WRITE, 0);
289 pmap_update(pmap_kernel());
290 initmsgbuf(msgbufaddr, round_page(MSGBUFSIZE));
291
292 /*
293 * Identify ourselves for the msgbuf (everything printed earlier will
294 * not be buffered).
295 */
296 printf("%s%s", copyright, version);
297
298 format_bytes(pbuf, sizeof(pbuf), arm_ptob(physmem));
299 printf("total memory = %s\n", pbuf);
300
301 minaddr = 0;
302
303 /*
304 * Allocate a submap for physio
305 */
306 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
307 VM_PHYS_SIZE, 0, false, NULL);
308
309 format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
310 printf("avail memory = %s\n", pbuf);
311
312 struct lwp * const l = &lwp0;
313 struct pcb * const pcb = lwp_getpcb(l);
314 pcb->pcb_ksp = uvm_lwp_getuarea(l) + USPACE_SVC_STACK_TOP;
315 lwp_settrapframe(l, (struct trapframe *)pcb->pcb_ksp - 1);
316 }
317
318 /*
319 * machine dependent system variables.
320 */
321 static int
322 sysctl_machdep_booted_device(SYSCTLFN_ARGS)
323 {
324 struct sysctlnode node;
325
326 if (booted_device == NULL)
327 return (EOPNOTSUPP);
328
329 node = *rnode;
330 node.sysctl_data = __UNCONST(device_xname(booted_device));
331 node.sysctl_size = strlen(device_xname(booted_device)) + 1;
332 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
333 }
334
335 static int
336 sysctl_machdep_booted_kernel(SYSCTLFN_ARGS)
337 {
338 struct sysctlnode node;
339
340 if (booted_kernel == NULL || booted_kernel[0] == '\0')
341 return (EOPNOTSUPP);
342
343 node = *rnode;
344 node.sysctl_data = booted_kernel;
345 node.sysctl_size = strlen(booted_kernel) + 1;
346 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
347 }
348
349 static int
350 sysctl_machdep_cpu_arch(SYSCTLFN_ARGS)
351 {
352 struct sysctlnode node = *rnode;
353 node.sysctl_data = __UNCONST(cpu_arch);
354 node.sysctl_size = strlen(cpu_arch) + 1;
355 return sysctl_lookup(SYSCTLFN_CALL(&node));
356 }
357
358 static int
359 sysctl_machdep_powersave(SYSCTLFN_ARGS)
360 {
361 struct sysctlnode node = *rnode;
362 int error, newval;
363
364 newval = cpu_do_powersave;
365 node.sysctl_data = &newval;
366 if (cpufuncs.cf_sleep == (void *) cpufunc_nullop)
367 node.sysctl_flags &= ~CTLFLAG_READWRITE;
368 error = sysctl_lookup(SYSCTLFN_CALL(&node));
369 if (error || newp == NULL || newval == cpu_do_powersave)
370 return (error);
371
372 if (newval < 0 || newval > 1)
373 return (EINVAL);
374 cpu_do_powersave = newval;
375
376 return (0);
377 }
378
379 static int
380 sysctl_hw_machine_arch(SYSCTLFN_ARGS)
381 {
382 struct sysctlnode node = *rnode;
383 node.sysctl_data = l->l_proc->p_md.md_march;
384 node.sysctl_size = strlen(l->l_proc->p_md.md_march) + 1;
385 return sysctl_lookup(SYSCTLFN_CALL(&node));
386 }
387
388 SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
389 {
390
391 sysctl_createv(clog, 0, NULL, NULL,
392 CTLFLAG_PERMANENT,
393 CTLTYPE_NODE, "machdep", NULL,
394 NULL, 0, NULL, 0,
395 CTL_MACHDEP, CTL_EOL);
396
397 sysctl_createv(clog, 0, NULL, NULL,
398 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
399 CTLTYPE_INT, "debug", NULL,
400 NULL, 0, &kernel_debug, 0,
401 CTL_MACHDEP, CPU_DEBUG, CTL_EOL);
402 sysctl_createv(clog, 0, NULL, NULL,
403 CTLFLAG_PERMANENT,
404 CTLTYPE_STRING, "booted_device", NULL,
405 sysctl_machdep_booted_device, 0, NULL, 0,
406 CTL_MACHDEP, CPU_BOOTED_DEVICE, CTL_EOL);
407 sysctl_createv(clog, 0, NULL, NULL,
408 CTLFLAG_PERMANENT,
409 CTLTYPE_STRING, "booted_kernel", NULL,
410 sysctl_machdep_booted_kernel, 0, NULL, 0,
411 CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL);
412 sysctl_createv(clog, 0, NULL, NULL,
413 CTLFLAG_PERMANENT,
414 CTLTYPE_STRUCT, "console_device", NULL,
415 sysctl_consdev, 0, NULL, sizeof(dev_t),
416 CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
417 sysctl_createv(clog, 0, NULL, NULL,
418 CTLFLAG_PERMANENT,
419 CTLTYPE_STRING, "cpu_arch", NULL,
420 sysctl_machdep_cpu_arch, 0, NULL, 0,
421 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
422 sysctl_createv(clog, 0, NULL, NULL,
423 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
424 CTLTYPE_INT, "powersave", NULL,
425 sysctl_machdep_powersave, 0, &cpu_do_powersave, 0,
426 CTL_MACHDEP, CPU_POWERSAVE, CTL_EOL);
427 sysctl_createv(clog, 0, NULL, NULL,
428 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
429 CTLTYPE_INT, "cpu_id", NULL,
430 NULL, curcpu()->ci_arm_cpuid, NULL, 0,
431 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
432 #ifdef FPU_VFP
433 sysctl_createv(clog, 0, NULL, NULL,
434 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
435 CTLTYPE_INT, "fpu_id", NULL,
436 NULL, 0, &cpu_info_store.ci_vfp_id, 0,
437 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
438 #endif
439 sysctl_createv(clog, 0, NULL, NULL,
440 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
441 CTLTYPE_INT, "fpu_present", NULL,
442 NULL, 0, &cpu_fpu_present, 0,
443 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
444 sysctl_createv(clog, 0, NULL, NULL,
445 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
446 CTLTYPE_INT, "hwdiv_present", NULL,
447 NULL, 0, &cpu_hwdiv_present, 0,
448 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
449 sysctl_createv(clog, 0, NULL, NULL,
450 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
451 CTLTYPE_INT, "neon_present", NULL,
452 NULL, 0, &cpu_neon_present, 0,
453 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
454 sysctl_createv(clog, 0, NULL, NULL,
455 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
456 CTLTYPE_STRUCT, "id_isar", NULL,
457 NULL, 0,
458 cpu_instruction_set_attributes,
459 sizeof(cpu_instruction_set_attributes),
460 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
461 sysctl_createv(clog, 0, NULL, NULL,
462 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
463 CTLTYPE_STRUCT, "id_mmfr", NULL,
464 NULL, 0,
465 cpu_memory_model_features,
466 sizeof(cpu_memory_model_features),
467 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
468 sysctl_createv(clog, 0, NULL, NULL,
469 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
470 CTLTYPE_STRUCT, "id_pfr", NULL,
471 NULL, 0,
472 cpu_processor_features,
473 sizeof(cpu_processor_features),
474 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
475 sysctl_createv(clog, 0, NULL, NULL,
476 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
477 CTLTYPE_STRUCT, "id_mvfr", NULL,
478 NULL, 0,
479 cpu_media_and_vfp_features,
480 sizeof(cpu_media_and_vfp_features),
481 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
482 sysctl_createv(clog, 0, NULL, NULL,
483 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
484 CTLTYPE_INT, "simd_present", NULL,
485 NULL, 0, &cpu_simd_present, 0,
486 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
487 sysctl_createv(clog, 0, NULL, NULL,
488 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
489 CTLTYPE_INT, "simdex_present", NULL,
490 NULL, 0, &cpu_simdex_present, 0,
491 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
492
493 /*
494 * We need override the usual CTL_HW HW_MACHINE_ARCH so we
495 * return the right machine_arch based on the running executable.
496 */
497 sysctl_createv(clog, 0, NULL, NULL,
498 CTLFLAG_PERMANENT,
499 CTLTYPE_NODE, "hw", NULL,
500 NULL, 0, NULL, 0,
501 CTL_HW, CTL_EOL);
502 sysctl_createv(clog, 0, NULL, NULL,
503 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
504 CTLTYPE_STRING, "machine_arch",
505 SYSCTL_DESCR("Machine CPU class"),
506 sysctl_hw_machine_arch, 0, NULL, 0,
507 CTL_HW, HW_MACHINE_ARCH, CTL_EOL);
508 }
509
510 void
511 parse_mi_bootargs(char *args)
512 {
513 int integer;
514
515 if (get_bootconf_option(args, "single", BOOTOPT_TYPE_BOOLEAN, &integer)
516 || get_bootconf_option(args, "-s", BOOTOPT_TYPE_BOOLEAN, &integer))
517 if (integer)
518 boothowto |= RB_SINGLE;
519 if (get_bootconf_option(args, "kdb", BOOTOPT_TYPE_BOOLEAN, &integer)
520 || get_bootconf_option(args, "-k", BOOTOPT_TYPE_BOOLEAN, &integer)
521 || get_bootconf_option(args, "-d", BOOTOPT_TYPE_BOOLEAN, &integer))
522 if (integer)
523 boothowto |= RB_KDB;
524 if (get_bootconf_option(args, "ask", BOOTOPT_TYPE_BOOLEAN, &integer)
525 || get_bootconf_option(args, "-a", BOOTOPT_TYPE_BOOLEAN, &integer))
526 if (integer)
527 boothowto |= RB_ASKNAME;
528
529 #ifdef PMAP_DEBUG
530 if (get_bootconf_option(args, "pmapdebug", BOOTOPT_TYPE_INT, &integer)) {
531 pmap_debug_level = integer;
532 pmap_debug(pmap_debug_level);
533 }
534 #endif /* PMAP_DEBUG */
535
536 /* if (get_bootconf_option(args, "nbuf", BOOTOPT_TYPE_INT, &integer))
537 bufpages = integer;*/
538
539 #if defined(MEMORY_DISK_HOOKS) && !defined(MEMORY_DISK_ROOT_SIZE)
540 if (get_bootconf_option(args, "memorydisc", BOOTOPT_TYPE_INT, &integer)
541 || get_bootconf_option(args, "memorydisk", BOOTOPT_TYPE_INT, &integer)) {
542 md_root_size = integer;
543 md_root_size *= 1024;
544 if (md_root_size < 32*1024)
545 md_root_size = 32*1024;
546 if (md_root_size > 2048*1024)
547 md_root_size = 2048*1024;
548 }
549 #endif /* MEMORY_DISK_HOOKS && !MEMORY_DISK_ROOT_SIZE */
550
551 if (get_bootconf_option(args, "quiet", BOOTOPT_TYPE_BOOLEAN, &integer)
552 || get_bootconf_option(args, "-q", BOOTOPT_TYPE_BOOLEAN, &integer))
553 if (integer)
554 boothowto |= AB_QUIET;
555 if (get_bootconf_option(args, "verbose", BOOTOPT_TYPE_BOOLEAN, &integer)
556 || get_bootconf_option(args, "-v", BOOTOPT_TYPE_BOOLEAN, &integer))
557 if (integer)
558 boothowto |= AB_VERBOSE;
559 }
560
561 #ifdef __HAVE_FAST_SOFTINTS
562 #if IPL_SOFTSERIAL != IPL_SOFTNET + 1
563 #error IPLs are screwed up
564 #elif IPL_SOFTNET != IPL_SOFTBIO + 1
565 #error IPLs are screwed up
566 #elif IPL_SOFTBIO != IPL_SOFTCLOCK + 1
567 #error IPLs are screwed up
568 #elif !(IPL_SOFTCLOCK > IPL_NONE)
569 #error IPLs are screwed up
570 #elif (IPL_NONE != 0)
571 #error IPLs are screwed up
572 #endif
573
574 #ifndef __HAVE_PIC_FAST_SOFTINTS
575 #define SOFTINT2IPLMAP \
576 (((IPL_SOFTSERIAL - IPL_SOFTCLOCK) << (SOFTINT_SERIAL * 4)) | \
577 ((IPL_SOFTNET - IPL_SOFTCLOCK) << (SOFTINT_NET * 4)) | \
578 ((IPL_SOFTBIO - IPL_SOFTCLOCK) << (SOFTINT_BIO * 4)) | \
579 ((IPL_SOFTCLOCK - IPL_SOFTCLOCK) << (SOFTINT_CLOCK * 4)))
580 #define SOFTINT2IPL(l) ((SOFTINT2IPLMAP >> ((l) * 4)) & 0x0f)
581
582 /*
583 * This returns a mask of softint IPLs that be dispatch at <ipl>
584 * SOFTIPLMASK(IPL_NONE) = 0x0000000f
585 * SOFTIPLMASK(IPL_SOFTCLOCK) = 0x0000000e
586 * SOFTIPLMASK(IPL_SOFTBIO) = 0x0000000c
587 * SOFTIPLMASK(IPL_SOFTNET) = 0x00000008
588 * SOFTIPLMASK(IPL_SOFTSERIAL) = 0x00000000
589 */
590 #define SOFTIPLMASK(ipl) ((0x0f << (ipl)) & 0x0f)
591
592 void softint_switch(lwp_t *, int);
593
594 void
595 softint_trigger(uintptr_t mask)
596 {
597 curcpu()->ci_softints |= mask;
598 }
599
600 void
601 softint_init_md(lwp_t *l, u_int level, uintptr_t *machdep)
602 {
603 lwp_t ** lp = &l->l_cpu->ci_softlwps[level];
604 KASSERT(*lp == NULL || *lp == l);
605 *lp = l;
606 *machdep = 1 << SOFTINT2IPL(level);
607 KASSERT(level != SOFTINT_CLOCK || *machdep == (1 << (IPL_SOFTCLOCK - IPL_SOFTCLOCK)));
608 KASSERT(level != SOFTINT_BIO || *machdep == (1 << (IPL_SOFTBIO - IPL_SOFTCLOCK)));
609 KASSERT(level != SOFTINT_NET || *machdep == (1 << (IPL_SOFTNET - IPL_SOFTCLOCK)));
610 KASSERT(level != SOFTINT_SERIAL || *machdep == (1 << (IPL_SOFTSERIAL - IPL_SOFTCLOCK)));
611 }
612
613 void
614 dosoftints(void)
615 {
616 struct cpu_info * const ci = curcpu();
617 const int opl = ci->ci_cpl;
618 const uint32_t softiplmask = SOFTIPLMASK(opl);
619
620 splhigh();
621 for (;;) {
622 u_int softints = ci->ci_softints & softiplmask;
623 KASSERT((softints != 0) == ((ci->ci_softints >> opl) != 0));
624 KASSERT(opl == IPL_NONE || (softints & (1 << (opl - IPL_SOFTCLOCK))) == 0);
625 if (softints == 0) {
626 splx(opl);
627 return;
628 }
629 #define DOSOFTINT(n) \
630 if (ci->ci_softints & (1 << (IPL_SOFT ## n - IPL_SOFTCLOCK))) { \
631 ci->ci_softints &= \
632 ~(1 << (IPL_SOFT ## n - IPL_SOFTCLOCK)); \
633 softint_switch(ci->ci_softlwps[SOFTINT_ ## n], \
634 IPL_SOFT ## n); \
635 continue; \
636 }
637 DOSOFTINT(SERIAL);
638 DOSOFTINT(NET);
639 DOSOFTINT(BIO);
640 DOSOFTINT(CLOCK);
641 panic("dosoftints wtf (softints=%u?, ipl=%d)", softints, opl);
642 }
643 }
644 #endif /* !__HAVE_PIC_FAST_SOFTINTS */
645 #endif /* __HAVE_FAST_SOFTINTS */
646
647 #ifdef MODULAR
648 /*
649 * Push any modules loaded by the boot loader.
650 */
651 void
652 module_init_md(void)
653 {
654 }
655 #endif /* MODULAR */
656
657 int
658 mm_md_physacc(paddr_t pa, vm_prot_t prot)
659 {
660
661 return (pa < ctob(physmem)) ? 0 : EFAULT;
662 }
663
664 #ifdef __HAVE_CPU_UAREA_ALLOC_IDLELWP
665 vaddr_t
666 cpu_uarea_alloc_idlelwp(struct cpu_info *ci)
667 {
668 const vaddr_t va = idlestack.pv_va + ci->ci_cpuid * USPACE;
669 // printf("%s: %s: va=%lx\n", __func__, ci->ci_data.cpu_name, va);
670 return va;
671 }
672 #endif
673
674 #ifdef MULTIPROCESSOR
675 void
676 cpu_boot_secondary_processors(void)
677 {
678 uint32_t mbox;
679 kcpuset_export_u32(kcpuset_attached, &mbox, sizeof(mbox));
680 atomic_swap_32(&arm_cpu_mbox, mbox);
681 membar_producer();
682 #ifdef _ARM_ARCH_7
683 __asm __volatile("sev; sev; sev");
684 #endif
685 }
686
687 void
688 xc_send_ipi(struct cpu_info *ci)
689 {
690 KASSERT(kpreempt_disabled());
691 KASSERT(curcpu() != ci);
692
693
694 if (ci) {
695 /* Unicast, remote CPU */
696 printf("%s: -> %s", __func__, ci->ci_data.cpu_name);
697 intr_ipi_send(ci->ci_kcpuset, IPI_XCALL);
698 } else {
699 printf("%s: -> !%s", __func__, ci->ci_data.cpu_name);
700 /* Broadcast to all but ourselves */
701 kcpuset_t *kcp;
702 kcpuset_create(&kcp, (ci != NULL));
703 KASSERT(kcp != NULL);
704 kcpuset_copy(kcp, kcpuset_running);
705 kcpuset_clear(kcp, cpu_index(ci));
706 intr_ipi_send(kcp, IPI_XCALL);
707 kcpuset_destroy(kcp);
708 }
709 printf("\n");
710 }
711 #endif /* MULTIPROCESSOR */
712
713 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
714 bool
715 mm_md_direct_mapped_phys(paddr_t pa, vaddr_t *vap)
716 {
717 if (physical_start <= pa && pa < physical_end) {
718 *vap = KERNEL_BASE + (pa - physical_start);
719 return true;
720 }
721
722 return false;
723 }
724 #endif
725