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