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