arm32_machdep.c revision 1.118 1 /* $NetBSD: arm32_machdep.c,v 1.118 2018/08/05 14:02:35 skrll 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.118 2018/08/05 14:02:35 skrll Exp $");
46
47 #include "opt_arm_debug.h"
48 #include "opt_fdt.h"
49 #include "opt_modular.h"
50 #include "opt_md.h"
51 #include "opt_pmap_debug.h"
52 #include "opt_multiprocessor.h"
53
54 #include <sys/param.h>
55 #include <sys/systm.h>
56 #include <sys/reboot.h>
57 #include <sys/proc.h>
58 #include <sys/kauth.h>
59 #include <sys/kernel.h>
60 #include <sys/mbuf.h>
61 #include <sys/mount.h>
62 #include <sys/buf.h>
63 #include <sys/msgbuf.h>
64 #include <sys/device.h>
65 #include <sys/sysctl.h>
66 #include <sys/cpu.h>
67 #include <sys/intr.h>
68 #include <sys/module.h>
69 #include <sys/atomic.h>
70 #include <sys/xcall.h>
71 #include <sys/ipi.h>
72
73 #include <uvm/uvm_extern.h>
74
75 #include <dev/cons.h>
76 #include <dev/mm.h>
77
78 #include <arm/locore.h>
79
80 #include <arm/arm32/machdep.h>
81
82 #include <machine/bootconfig.h>
83 #include <machine/pcb.h>
84
85 #if defined(FDT)
86 #include <arm/fdt/arm_fdtvar.h>
87 #include <arch/evbarm/fdt/platform.h>
88 #endif
89
90 #ifdef VERBOSE_INIT_ARM
91 #define VPRINTF(...) printf(__VA_ARGS__)
92 #else
93 #define VPRINTF(...) do { } while (/* CONSTCOND */ 0)
94 #endif
95
96 void (*cpu_reset_address)(void); /* Used by locore */
97 paddr_t cpu_reset_address_paddr; /* Used by locore */
98
99 struct vm_map *phys_map = NULL;
100
101 #if defined(MEMORY_DISK_HOOKS) && !defined(MEMORY_DISK_ROOT_SIZE)
102 extern size_t md_root_size; /* Memory disc size */
103 #endif /* MEMORY_DISK_HOOKS && !MEMORY_DISK_ROOT_SIZE */
104
105 pv_addr_t kernelstack;
106 pv_addr_t abtstack;
107 pv_addr_t fiqstack;
108 pv_addr_t irqstack;
109 pv_addr_t undstack;
110 pv_addr_t idlestack;
111
112 void * msgbufaddr;
113 extern paddr_t msgbufphys;
114
115 int kernel_debug = 0;
116 int cpu_printfataltraps = 0;
117 int cpu_fpu_present;
118 int cpu_hwdiv_present;
119 int cpu_neon_present;
120 int cpu_simd_present;
121 int cpu_simdex_present;
122 int cpu_umull_present;
123 int cpu_synchprim_present;
124 int cpu_unaligned_sigbus;
125 const char *cpu_arch = "";
126
127 int cpu_instruction_set_attributes[6];
128 int cpu_memory_model_features[4];
129 int cpu_processor_features[2];
130 int cpu_media_and_vfp_features[2];
131
132 /* exported variable to be filled in by the bootloaders */
133 char *booted_kernel;
134
135 /* Prototypes */
136
137 void data_abort_handler(trapframe_t *frame);
138 void prefetch_abort_handler(trapframe_t *frame);
139 extern void configure(void);
140
141 /*
142 * arm32_vector_init:
143 *
144 * Initialize the vector page, and select whether or not to
145 * relocate the vectors.
146 *
147 * NOTE: We expect the vector page to be mapped at its expected
148 * destination.
149 */
150 void
151 arm32_vector_init(vaddr_t va, int which)
152 {
153 #if defined(CPU_ARMV7) || defined(CPU_ARM11) || defined(ARM_HAS_VBAR)
154 /*
155 * If this processor has the security extension, don't bother
156 * to move/map the vector page. Simply point VBAR to the copy
157 * that exists in the .text segment.
158 */
159 #ifndef ARM_HAS_VBAR
160 if (va == ARM_VECTORS_LOW
161 && (armreg_pfr1_read() & ARM_PFR1_SEC_MASK) != 0) {
162 #endif
163 extern const uint32_t page0rel[];
164 vector_page = (vaddr_t)page0rel;
165 KASSERT((vector_page & 0x1f) == 0);
166 armreg_vbar_write(vector_page);
167 VPRINTF(" vbar=%p", page0rel);
168 cpu_control(CPU_CONTROL_VECRELOC, 0);
169 return;
170 #ifndef ARM_HAS_VBAR
171 }
172 #endif
173 #endif
174 #ifndef ARM_HAS_VBAR
175 if (CPU_IS_PRIMARY(curcpu())) {
176 extern unsigned int page0[], page0_data[];
177 unsigned int *vectors = (int *) va;
178 unsigned int *vectors_data = vectors + (page0_data - page0);
179 int vec;
180
181 /*
182 * Loop through the vectors we're taking over, and copy the
183 * vector's insn and data word.
184 */
185 for (vec = 0; vec < ARM_NVEC; vec++) {
186 if ((which & (1 << vec)) == 0) {
187 /* Don't want to take over this vector. */
188 continue;
189 }
190 vectors[vec] = page0[vec];
191 vectors_data[vec] = page0_data[vec];
192 }
193
194 /* Now sync the vectors. */
195 cpu_icache_sync_range(va, (ARM_NVEC * 2) * sizeof(u_int));
196
197 vector_page = va;
198 }
199
200 if (va == ARM_VECTORS_HIGH) {
201 /*
202 * Assume the MD caller knows what it's doing here, and
203 * really does want the vector page relocated.
204 *
205 * Note: This has to be done here (and not just in
206 * cpu_setup()) because the vector page needs to be
207 * accessible *before* cpu_startup() is called.
208 * Think ddb(9) ...
209 *
210 * NOTE: If the CPU control register is not readable,
211 * this will totally fail! We'll just assume that
212 * any system that has high vector support has a
213 * readable CPU control register, for now. If we
214 * ever encounter one that does not, we'll have to
215 * rethink this.
216 */
217 cpu_control(CPU_CONTROL_VECRELOC, CPU_CONTROL_VECRELOC);
218 }
219 #endif
220 }
221
222 /*
223 * Debug function just to park the CPU
224 */
225
226 void
227 halt(void)
228 {
229 while (1)
230 cpu_sleep(0);
231 }
232
233
234 /* Sync the discs, unmount the filesystems, and adjust the todr */
235
236 void
237 bootsync(void)
238 {
239 static bool bootsyncdone = false;
240
241 if (bootsyncdone) return;
242
243 bootsyncdone = true;
244
245 /* Make sure we can still manage to do things */
246 if (GetCPSR() & I32_bit) {
247 /*
248 * If we get here then boot has been called without RB_NOSYNC
249 * and interrupts were disabled. This means the boot() call
250 * did not come from a user process e.g. shutdown, but must
251 * have come from somewhere in the kernel.
252 */
253 IRQenable;
254 printf("Warning IRQ's disabled during boot()\n");
255 }
256
257 vfs_shutdown();
258
259 resettodr();
260 }
261
262 /*
263 * void cpu_startup(void)
264 *
265 * Machine dependent startup code.
266 *
267 */
268 void
269 cpu_startup(void)
270 {
271 vaddr_t minaddr;
272 vaddr_t maxaddr;
273 char pbuf[9];
274
275 /*
276 * Until we better locking, we have to live under the kernel lock.
277 */
278 //KERNEL_LOCK(1, NULL);
279
280 /* Set the CPU control register */
281 cpu_setup(boot_args);
282
283 #ifndef ARM_HAS_VBAR
284 /* Lock down zero page */
285 vector_page_setprot(VM_PROT_READ);
286 #endif
287
288 /*
289 * Give pmap a chance to set up a few more things now the vm
290 * is initialised
291 */
292 pmap_postinit();
293
294 /*
295 * Initialize error message buffer (at end of core).
296 */
297
298 /* msgbufphys was setup during the secondary boot strap */
299 if (!pmap_extract(pmap_kernel(), (vaddr_t)msgbufaddr, NULL)) {
300 for (u_int loop = 0; loop < btoc(MSGBUFSIZE); ++loop) {
301 pmap_kenter_pa((vaddr_t)msgbufaddr + loop * PAGE_SIZE,
302 msgbufphys + loop * PAGE_SIZE,
303 VM_PROT_READ|VM_PROT_WRITE, 0);
304 }
305 }
306 pmap_update(pmap_kernel());
307 initmsgbuf(msgbufaddr, round_page(MSGBUFSIZE));
308
309 /*
310 * Identify ourselves for the msgbuf (everything printed earlier will
311 * not be buffered).
312 */
313 printf("%s%s", copyright, version);
314
315 format_bytes(pbuf, sizeof(pbuf), arm_ptob(physmem));
316 printf("total memory = %s\n", pbuf);
317
318 minaddr = 0;
319
320 /*
321 * Allocate a submap for physio
322 */
323 phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
324 VM_PHYS_SIZE, 0, false, NULL);
325
326 format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
327 printf("avail memory = %s\n", pbuf);
328
329 /*
330 * This is actually done by initarm_common, but not all ports use it
331 * yet so do it here to catch them as well
332 */
333 struct lwp * const l = &lwp0;
334 struct pcb * const pcb = lwp_getpcb(l);
335
336 /* Zero out the PCB. */
337 memset(pcb, 0, sizeof(*pcb));
338
339 pcb->pcb_ksp = uvm_lwp_getuarea(l) + USPACE_SVC_STACK_TOP;
340 pcb->pcb_ksp -= sizeof(struct trapframe);
341
342 struct trapframe * tf = (struct trapframe *)pcb->pcb_ksp;
343
344 /* Zero out the trapframe. */
345 memset(tf, 0, sizeof(*tf));
346 lwp_settrapframe(l, tf);
347
348 #if defined(__ARMEB__)
349 tf->tf_spsr = PSR_USR32_MODE | (CPU_IS_ARMV7_P() ? PSR_E_BIT : 0);
350 #else
351 tf->tf_spsr = PSR_USR32_MODE;
352 #endif
353 }
354
355 /*
356 * machine dependent system variables.
357 */
358 static int
359 sysctl_machdep_booted_device(SYSCTLFN_ARGS)
360 {
361 struct sysctlnode node;
362
363 if (booted_device == NULL)
364 return (EOPNOTSUPP);
365
366 node = *rnode;
367 node.sysctl_data = __UNCONST(device_xname(booted_device));
368 node.sysctl_size = strlen(device_xname(booted_device)) + 1;
369 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
370 }
371
372 static int
373 sysctl_machdep_booted_kernel(SYSCTLFN_ARGS)
374 {
375 struct sysctlnode node;
376
377 if (booted_kernel == NULL || booted_kernel[0] == '\0')
378 return (EOPNOTSUPP);
379
380 node = *rnode;
381 node.sysctl_data = booted_kernel;
382 node.sysctl_size = strlen(booted_kernel) + 1;
383 return (sysctl_lookup(SYSCTLFN_CALL(&node)));
384 }
385
386 static int
387 sysctl_machdep_cpu_arch(SYSCTLFN_ARGS)
388 {
389 struct sysctlnode node = *rnode;
390 node.sysctl_data = __UNCONST(cpu_arch);
391 node.sysctl_size = strlen(cpu_arch) + 1;
392 return sysctl_lookup(SYSCTLFN_CALL(&node));
393 }
394
395 static int
396 sysctl_machdep_powersave(SYSCTLFN_ARGS)
397 {
398 struct sysctlnode node = *rnode;
399 int error, newval;
400
401 newval = cpu_do_powersave;
402 node.sysctl_data = &newval;
403 if (cpufuncs.cf_sleep == (void *) cpufunc_nullop)
404 node.sysctl_flags &= ~CTLFLAG_READWRITE;
405 error = sysctl_lookup(SYSCTLFN_CALL(&node));
406 if (error || newp == NULL || newval == cpu_do_powersave)
407 return (error);
408
409 if (newval < 0 || newval > 1)
410 return (EINVAL);
411 cpu_do_powersave = newval;
412
413 return (0);
414 }
415
416 SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
417 {
418
419 sysctl_createv(clog, 0, NULL, NULL,
420 CTLFLAG_PERMANENT,
421 CTLTYPE_NODE, "machdep", NULL,
422 NULL, 0, NULL, 0,
423 CTL_MACHDEP, CTL_EOL);
424
425 sysctl_createv(clog, 0, NULL, NULL,
426 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
427 CTLTYPE_INT, "debug", NULL,
428 NULL, 0, &kernel_debug, 0,
429 CTL_MACHDEP, CPU_DEBUG, CTL_EOL);
430 sysctl_createv(clog, 0, NULL, NULL,
431 CTLFLAG_PERMANENT,
432 CTLTYPE_STRING, "booted_device", NULL,
433 sysctl_machdep_booted_device, 0, NULL, 0,
434 CTL_MACHDEP, CPU_BOOTED_DEVICE, CTL_EOL);
435 sysctl_createv(clog, 0, NULL, NULL,
436 CTLFLAG_PERMANENT,
437 CTLTYPE_STRING, "booted_kernel", NULL,
438 sysctl_machdep_booted_kernel, 0, NULL, 0,
439 CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL);
440 sysctl_createv(clog, 0, NULL, NULL,
441 CTLFLAG_PERMANENT,
442 CTLTYPE_STRUCT, "console_device", NULL,
443 sysctl_consdev, 0, NULL, sizeof(dev_t),
444 CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
445 sysctl_createv(clog, 0, NULL, NULL,
446 CTLFLAG_PERMANENT,
447 CTLTYPE_STRING, "cpu_arch", NULL,
448 sysctl_machdep_cpu_arch, 0, NULL, 0,
449 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
450 sysctl_createv(clog, 0, NULL, NULL,
451 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
452 CTLTYPE_INT, "powersave", NULL,
453 sysctl_machdep_powersave, 0, &cpu_do_powersave, 0,
454 CTL_MACHDEP, CPU_POWERSAVE, CTL_EOL);
455 sysctl_createv(clog, 0, NULL, NULL,
456 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
457 CTLTYPE_INT, "cpu_id", NULL,
458 NULL, curcpu()->ci_arm_cpuid, NULL, 0,
459 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
460 #ifdef FPU_VFP
461 sysctl_createv(clog, 0, NULL, NULL,
462 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
463 CTLTYPE_INT, "fpu_id", NULL,
464 NULL, 0, &cpu_info_store.ci_vfp_id, 0,
465 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
466 #endif
467 sysctl_createv(clog, 0, NULL, NULL,
468 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
469 CTLTYPE_INT, "fpu_present", NULL,
470 NULL, 0, &cpu_fpu_present, 0,
471 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
472 sysctl_createv(clog, 0, NULL, NULL,
473 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
474 CTLTYPE_INT, "hwdiv_present", NULL,
475 NULL, 0, &cpu_hwdiv_present, 0,
476 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
477 sysctl_createv(clog, 0, NULL, NULL,
478 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
479 CTLTYPE_INT, "neon_present", NULL,
480 NULL, 0, &cpu_neon_present, 0,
481 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
482 sysctl_createv(clog, 0, NULL, NULL,
483 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
484 CTLTYPE_STRUCT, "id_isar", NULL,
485 NULL, 0,
486 cpu_instruction_set_attributes,
487 sizeof(cpu_instruction_set_attributes),
488 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
489 sysctl_createv(clog, 0, NULL, NULL,
490 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
491 CTLTYPE_STRUCT, "id_mmfr", NULL,
492 NULL, 0,
493 cpu_memory_model_features,
494 sizeof(cpu_memory_model_features),
495 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
496 sysctl_createv(clog, 0, NULL, NULL,
497 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
498 CTLTYPE_STRUCT, "id_pfr", NULL,
499 NULL, 0,
500 cpu_processor_features,
501 sizeof(cpu_processor_features),
502 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
503 sysctl_createv(clog, 0, NULL, NULL,
504 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
505 CTLTYPE_STRUCT, "id_mvfr", NULL,
506 NULL, 0,
507 cpu_media_and_vfp_features,
508 sizeof(cpu_media_and_vfp_features),
509 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
510 sysctl_createv(clog, 0, NULL, NULL,
511 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
512 CTLTYPE_INT, "simd_present", NULL,
513 NULL, 0, &cpu_simd_present, 0,
514 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
515 sysctl_createv(clog, 0, NULL, NULL,
516 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
517 CTLTYPE_INT, "simdex_present", NULL,
518 NULL, 0, &cpu_simdex_present, 0,
519 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
520 sysctl_createv(clog, 0, NULL, NULL,
521 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
522 CTLTYPE_INT, "synchprim_present", NULL,
523 NULL, 0, &cpu_synchprim_present, 0,
524 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
525 sysctl_createv(clog, 0, NULL, NULL,
526 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
527 CTLTYPE_INT, "printfataltraps", NULL,
528 NULL, 0, &cpu_printfataltraps, 0,
529 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
530 cpu_unaligned_sigbus = !CPU_IS_ARMV6_P() && !CPU_IS_ARMV7_P();
531 sysctl_createv(clog, 0, NULL, NULL,
532 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
533 CTLTYPE_INT, "unaligned_sigbus",
534 SYSCTL_DESCR("Do SIGBUS for fixed unaligned accesses"),
535 NULL, 0, &cpu_unaligned_sigbus, 0,
536 CTL_MACHDEP, CTL_CREATE, CTL_EOL);
537 }
538
539 void
540 parse_mi_bootargs(char *args)
541 {
542 int integer;
543
544 if (get_bootconf_option(args, "single", BOOTOPT_TYPE_BOOLEAN, &integer)
545 || get_bootconf_option(args, "-s", BOOTOPT_TYPE_BOOLEAN, &integer))
546 if (integer)
547 boothowto |= RB_SINGLE;
548 if (get_bootconf_option(args, "kdb", BOOTOPT_TYPE_BOOLEAN, &integer)
549 || get_bootconf_option(args, "-k", BOOTOPT_TYPE_BOOLEAN, &integer)
550 || get_bootconf_option(args, "-d", BOOTOPT_TYPE_BOOLEAN, &integer))
551 if (integer)
552 boothowto |= RB_KDB;
553 if (get_bootconf_option(args, "ask", BOOTOPT_TYPE_BOOLEAN, &integer)
554 || get_bootconf_option(args, "-a", BOOTOPT_TYPE_BOOLEAN, &integer))
555 if (integer)
556 boothowto |= RB_ASKNAME;
557
558 #ifdef PMAP_DEBUG
559 if (get_bootconf_option(args, "pmapdebug", BOOTOPT_TYPE_INT, &integer)) {
560 pmap_debug_level = integer;
561 pmap_debug(pmap_debug_level);
562 }
563 #endif /* PMAP_DEBUG */
564
565 /* if (get_bootconf_option(args, "nbuf", BOOTOPT_TYPE_INT, &integer))
566 bufpages = integer;*/
567
568 #if defined(MEMORY_DISK_HOOKS) && !defined(MEMORY_DISK_ROOT_SIZE)
569 if (get_bootconf_option(args, "memorydisc", BOOTOPT_TYPE_INT, &integer)
570 || get_bootconf_option(args, "memorydisk", BOOTOPT_TYPE_INT, &integer)) {
571 md_root_size = integer;
572 md_root_size *= 1024;
573 if (md_root_size < 32*1024)
574 md_root_size = 32*1024;
575 if (md_root_size > 2048*1024)
576 md_root_size = 2048*1024;
577 }
578 #endif /* MEMORY_DISK_HOOKS && !MEMORY_DISK_ROOT_SIZE */
579
580 if (get_bootconf_option(args, "quiet", BOOTOPT_TYPE_BOOLEAN, &integer)
581 || get_bootconf_option(args, "-q", BOOTOPT_TYPE_BOOLEAN, &integer))
582 if (integer)
583 boothowto |= AB_QUIET;
584 if (get_bootconf_option(args, "verbose", BOOTOPT_TYPE_BOOLEAN, &integer)
585 || get_bootconf_option(args, "-v", BOOTOPT_TYPE_BOOLEAN, &integer))
586 if (integer)
587 boothowto |= AB_VERBOSE;
588 if (get_bootconf_option(args, "debug", BOOTOPT_TYPE_BOOLEAN, &integer)
589 || get_bootconf_option(args, "-x", BOOTOPT_TYPE_BOOLEAN, &integer))
590 if (integer)
591 boothowto |= AB_DEBUG;
592 }
593
594 #ifdef __HAVE_FAST_SOFTINTS
595 #if IPL_SOFTSERIAL != IPL_SOFTNET + 1
596 #error IPLs are screwed up
597 #elif IPL_SOFTNET != IPL_SOFTBIO + 1
598 #error IPLs are screwed up
599 #elif IPL_SOFTBIO != IPL_SOFTCLOCK + 1
600 #error IPLs are screwed up
601 #elif !(IPL_SOFTCLOCK > IPL_NONE)
602 #error IPLs are screwed up
603 #elif (IPL_NONE != 0)
604 #error IPLs are screwed up
605 #endif
606
607 #ifndef __HAVE_PIC_FAST_SOFTINTS
608 #define SOFTINT2IPLMAP \
609 (((IPL_SOFTSERIAL - IPL_SOFTCLOCK) << (SOFTINT_SERIAL * 4)) | \
610 ((IPL_SOFTNET - IPL_SOFTCLOCK) << (SOFTINT_NET * 4)) | \
611 ((IPL_SOFTBIO - IPL_SOFTCLOCK) << (SOFTINT_BIO * 4)) | \
612 ((IPL_SOFTCLOCK - IPL_SOFTCLOCK) << (SOFTINT_CLOCK * 4)))
613 #define SOFTINT2IPL(l) ((SOFTINT2IPLMAP >> ((l) * 4)) & 0x0f)
614
615 /*
616 * This returns a mask of softint IPLs that be dispatch at <ipl>
617 * SOFTIPLMASK(IPL_NONE) = 0x0000000f
618 * SOFTIPLMASK(IPL_SOFTCLOCK) = 0x0000000e
619 * SOFTIPLMASK(IPL_SOFTBIO) = 0x0000000c
620 * SOFTIPLMASK(IPL_SOFTNET) = 0x00000008
621 * SOFTIPLMASK(IPL_SOFTSERIAL) = 0x00000000
622 */
623 #define SOFTIPLMASK(ipl) ((0x0f << (ipl)) & 0x0f)
624
625 void softint_switch(lwp_t *, int);
626
627 void
628 softint_trigger(uintptr_t mask)
629 {
630 curcpu()->ci_softints |= mask;
631 }
632
633 void
634 softint_init_md(lwp_t *l, u_int level, uintptr_t *machdep)
635 {
636 lwp_t ** lp = &l->l_cpu->ci_softlwps[level];
637 KASSERT(*lp == NULL || *lp == l);
638 *lp = l;
639 *machdep = 1 << SOFTINT2IPL(level);
640 KASSERT(level != SOFTINT_CLOCK || *machdep == (1 << (IPL_SOFTCLOCK - IPL_SOFTCLOCK)));
641 KASSERT(level != SOFTINT_BIO || *machdep == (1 << (IPL_SOFTBIO - IPL_SOFTCLOCK)));
642 KASSERT(level != SOFTINT_NET || *machdep == (1 << (IPL_SOFTNET - IPL_SOFTCLOCK)));
643 KASSERT(level != SOFTINT_SERIAL || *machdep == (1 << (IPL_SOFTSERIAL - IPL_SOFTCLOCK)));
644 }
645
646 void
647 dosoftints(void)
648 {
649 struct cpu_info * const ci = curcpu();
650 const int opl = ci->ci_cpl;
651 const uint32_t softiplmask = SOFTIPLMASK(opl);
652
653 splhigh();
654 for (;;) {
655 u_int softints = ci->ci_softints & softiplmask;
656 KASSERT((softints != 0) == ((ci->ci_softints >> opl) != 0));
657 KASSERT(opl == IPL_NONE || (softints & (1 << (opl - IPL_SOFTCLOCK))) == 0);
658 if (softints == 0) {
659 splx(opl);
660 return;
661 }
662 #define DOSOFTINT(n) \
663 if (ci->ci_softints & (1 << (IPL_SOFT ## n - IPL_SOFTCLOCK))) { \
664 ci->ci_softints &= \
665 ~(1 << (IPL_SOFT ## n - IPL_SOFTCLOCK)); \
666 softint_switch(ci->ci_softlwps[SOFTINT_ ## n], \
667 IPL_SOFT ## n); \
668 continue; \
669 }
670 DOSOFTINT(SERIAL);
671 DOSOFTINT(NET);
672 DOSOFTINT(BIO);
673 DOSOFTINT(CLOCK);
674 panic("dosoftints wtf (softints=%u?, ipl=%d)", softints, opl);
675 }
676 }
677 #endif /* !__HAVE_PIC_FAST_SOFTINTS */
678 #endif /* __HAVE_FAST_SOFTINTS */
679
680 #ifdef MODULAR
681 /*
682 * Push any modules loaded by the boot loader.
683 */
684 void
685 module_init_md(void)
686 {
687 }
688 #endif /* MODULAR */
689
690 int
691 mm_md_physacc(paddr_t pa, vm_prot_t prot)
692 {
693 if (pa >= physical_start && pa < physical_end)
694 return 0;
695
696 return kauth_authorize_machdep(kauth_cred_get(),
697 KAUTH_MACHDEP_UNMANAGEDMEM, NULL, NULL, NULL, NULL);
698 }
699
700 #ifdef __HAVE_CPU_UAREA_ALLOC_IDLELWP
701 vaddr_t
702 cpu_uarea_alloc_idlelwp(struct cpu_info *ci)
703 {
704 const vaddr_t va = idlestack.pv_va + ci->ci_cpuid * USPACE;
705 // printf("%s: %s: va=%lx\n", __func__, ci->ci_data.cpu_name, va);
706 return va;
707 }
708 #endif
709
710 #ifdef MULTIPROCESSOR
711 void
712 cpu_boot_secondary_processors(void)
713 {
714 VPRINTF("%s: writing mbox with %#x\n", __func__, arm_cpu_hatched);
715 arm_cpu_mbox = arm_cpu_hatched;
716 membar_producer();
717 #ifdef _ARM_ARCH_7
718 __asm __volatile("sev; sev; sev");
719 #endif
720 while (arm_cpu_mbox) {
721 __asm("wfe");
722 }
723 }
724
725 void
726 xc_send_ipi(struct cpu_info *ci)
727 {
728 KASSERT(kpreempt_disabled());
729 KASSERT(curcpu() != ci);
730
731 intr_ipi_send(ci != NULL ? ci->ci_kcpuset : NULL, IPI_XCALL);
732 }
733
734 void
735 cpu_ipi(struct cpu_info *ci)
736 {
737 KASSERT(kpreempt_disabled());
738 KASSERT(curcpu() != ci);
739
740 intr_ipi_send(ci != NULL ? ci->ci_kcpuset : NULL, IPI_GENERIC);
741 }
742
743 #endif /* MULTIPROCESSOR */
744
745 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
746 bool
747 mm_md_direct_mapped_phys(paddr_t pa, vaddr_t *vap)
748 {
749 bool rv;
750 vaddr_t va = pmap_direct_mapped_phys(pa, &rv, 0);
751 if (rv) {
752 *vap = va;
753 }
754 return rv;
755 }
756 #endif
757
758 bool
759 mm_md_page_color(paddr_t pa, int *colorp)
760 {
761 #if (ARM_MMU_V6 + ARM_MMU_V7) != 0
762 *colorp = atop(pa & arm_cache_prefer_mask);
763
764 return arm_cache_prefer_mask ? false : true;
765 #else
766 *colorp = 0;
767
768 return true;
769 #endif
770 }
771
772 #if defined(FDT)
773 extern char KERNEL_BASE_phys[];
774 #define KERNEL_BASE_PHYS ((paddr_t)KERNEL_BASE_phys)
775
776 void
777 cpu_kernel_vm_init(paddr_t memory_start, psize_t memory_size)
778 {
779 const struct arm_platform *plat = arm_fdt_platform();
780
781 #ifdef VERBOSE_INIT_ARM
782 extern char _end[];
783
784 const vaddr_t kernend = round_page((vaddr_t)_end);
785
786 const paddr_t kernstart_phys = KERNEL_BASE_PHYS;
787 const paddr_t kernend_phys = KERN_VTOPHYS(kernend);
788 #endif
789
790 VPRINTF("KERNEL_BASE=0x%x, "
791 "KERNEL_VM_BASE=0x%x, "
792 "KERNEL_VM_BASE - KERNEL_BASE=0x%x, "
793 "KERNEL_BASE_VOFFSET=0x%x\n",
794 KERNEL_BASE,
795 KERNEL_VM_BASE,
796 KERNEL_VM_BASE - KERNEL_BASE,
797 KERNEL_BASE_VOFFSET);
798
799 VPRINTF("%s: kernel phys start %lx end %lx\n", __func__,
800 kernstart_phys, kernend_phys);
801
802 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
803 const bool mapallmem_p = true;
804 #ifndef PMAP_NEED_ALLOC_POOLPAGE
805 if (memory_size > KERNEL_VM_BASE - KERNEL_BASE) {
806 VPRINTF("%s: dropping RAM size from %luMB to %uMB\n",
807 __func__, (unsigned long) (memory_size >> 20),
808 (KERNEL_VM_BASE - KERNEL_BASE) >> 20);
809 memory_size = KERNEL_VM_BASE - KERNEL_BASE;
810 }
811 #endif
812 #else
813 const bool mapallmem_p = false;
814 #endif
815
816 arm32_bootmem_init(memory_start, memory_size, KERNEL_BASE_PHYS);
817 arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0,
818 plat->ap_devmap(), mapallmem_p);
819 }
820 #endif
821
822