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