Home | History | Annotate | Line # | Download | only in arm32
arm32_machdep.c revision 1.83.2.1
      1  1.83.2.1       tls /*	$NetBSD: arm32_machdep.c,v 1.83.2.1 2012/11/20 03:01:02 tls Exp $	*/
      2       1.1     chris 
      3       1.1     chris /*
      4       1.1     chris  * Copyright (c) 1994-1998 Mark Brinicombe.
      5       1.1     chris  * Copyright (c) 1994 Brini.
      6       1.1     chris  * All rights reserved.
      7       1.1     chris  *
      8       1.1     chris  * This code is derived from software written for Brini by Mark Brinicombe
      9       1.1     chris  *
     10       1.1     chris  * Redistribution and use in source and binary forms, with or without
     11       1.1     chris  * modification, are permitted provided that the following conditions
     12       1.1     chris  * are met:
     13       1.1     chris  * 1. Redistributions of source code must retain the above copyright
     14       1.1     chris  *    notice, this list of conditions and the following disclaimer.
     15       1.1     chris  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1     chris  *    notice, this list of conditions and the following disclaimer in the
     17       1.1     chris  *    documentation and/or other materials provided with the distribution.
     18       1.1     chris  * 3. All advertising materials mentioning features or use of this software
     19       1.1     chris  *    must display the following acknowledgement:
     20       1.1     chris  *	This product includes software developed by Mark Brinicombe
     21       1.1     chris  *	for the NetBSD Project.
     22       1.1     chris  * 4. The name of the company nor the name of the author may be used to
     23       1.1     chris  *    endorse or promote products derived from this software without specific
     24       1.1     chris  *    prior written permission.
     25       1.1     chris  *
     26       1.1     chris  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     27       1.1     chris  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     28       1.1     chris  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     29       1.1     chris  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     30       1.1     chris  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     31       1.1     chris  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     32       1.1     chris  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33       1.1     chris  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34       1.1     chris  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35       1.1     chris  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36       1.1     chris  * SUCH DAMAGE.
     37       1.1     chris  *
     38      1.76       wiz  * Machine dependent functions for kernel setup
     39       1.1     chris  *
     40       1.1     chris  * Created      : 17/09/94
     41       1.1     chris  * Updated	: 18/04/01 updated for new wscons
     42       1.1     chris  */
     43      1.37     lukem 
     44      1.37     lukem #include <sys/cdefs.h>
     45  1.83.2.1       tls __KERNEL_RCSID(0, "$NetBSD: arm32_machdep.c,v 1.83.2.1 2012/11/20 03:01:02 tls Exp $");
     46       1.1     chris 
     47      1.72      jmmv #include "opt_modular.h"
     48       1.1     chris #include "opt_md.h"
     49       1.1     chris #include "opt_pmap_debug.h"
     50       1.1     chris 
     51       1.1     chris #include <sys/param.h>
     52       1.1     chris #include <sys/systm.h>
     53       1.1     chris #include <sys/reboot.h>
     54       1.1     chris #include <sys/proc.h>
     55      1.75     rmind #include <sys/kauth.h>
     56       1.1     chris #include <sys/kernel.h>
     57       1.1     chris #include <sys/mbuf.h>
     58       1.1     chris #include <sys/mount.h>
     59       1.1     chris #include <sys/buf.h>
     60       1.1     chris #include <sys/msgbuf.h>
     61       1.1     chris #include <sys/device.h>
     62       1.1     chris #include <sys/sysctl.h>
     63      1.49      yamt #include <sys/cpu.h>
     64      1.83      matt #include <sys/intr.h>
     65      1.72      jmmv #include <sys/module.h>
     66      1.83      matt #include <sys/atomic.h>
     67      1.83      matt #include <sys/xcall.h>
     68       1.1     chris 
     69      1.77     skrll #include <uvm/uvm_extern.h>
     70      1.77     skrll 
     71       1.1     chris #include <dev/cons.h>
     72      1.75     rmind #include <dev/mm.h>
     73       1.1     chris 
     74       1.7   thorpej #include <arm/arm32/katelib.h>
     75       1.9     chris #include <arm/arm32/machdep.h>
     76      1.81      matt 
     77       1.1     chris #include <machine/bootconfig.h>
     78      1.81      matt #include <machine/pcb.h>
     79      1.81      matt 
     80      1.82      matt void (*cpu_reset_address)(void);	/* Used by locore */
     81      1.82      matt paddr_t cpu_reset_address_paddr;	/* Used by locore */
     82       1.1     chris 
     83       1.1     chris struct vm_map *phys_map = NULL;
     84       1.1     chris 
     85      1.74   hannken #if defined(MEMORY_DISK_HOOKS) && !defined(MEMORY_DISK_ROOT_SIZE)
     86      1.24  jdolecek extern size_t md_root_size;		/* Memory disc size */
     87      1.74   hannken #endif	/* MEMORY_DISK_HOOKS && !MEMORY_DISK_ROOT_SIZE */
     88       1.1     chris 
     89       1.1     chris pv_addr_t kernelstack;
     90      1.79      matt pv_addr_t abtstack;
     91      1.79      matt pv_addr_t fiqstack;
     92      1.79      matt pv_addr_t irqstack;
     93      1.79      matt pv_addr_t undstack;
     94      1.83      matt pv_addr_t idlestack;
     95       1.1     chris 
     96      1.48  christos void *	msgbufaddr;
     97       1.1     chris extern paddr_t msgbufphys;
     98       1.1     chris 
     99       1.1     chris int kernel_debug = 0;
    100       1.1     chris 
    101      1.12   reinoud /* exported variable to be filled in by the bootloaders */
    102       1.1     chris char *booted_kernel;
    103       1.1     chris 
    104       1.1     chris /* Prototypes */
    105       1.1     chris 
    106      1.63       dsl void data_abort_handler(trapframe_t *frame);
    107      1.63       dsl void prefetch_abort_handler(trapframe_t *frame);
    108      1.63       dsl extern void configure(void);
    109       1.1     chris 
    110       1.1     chris /*
    111      1.22   thorpej  * arm32_vector_init:
    112      1.22   thorpej  *
    113      1.22   thorpej  *	Initialize the vector page, and select whether or not to
    114      1.22   thorpej  *	relocate the vectors.
    115      1.22   thorpej  *
    116      1.22   thorpej  *	NOTE: We expect the vector page to be mapped at its expected
    117      1.22   thorpej  *	destination.
    118      1.22   thorpej  */
    119      1.22   thorpej void
    120      1.22   thorpej arm32_vector_init(vaddr_t va, int which)
    121      1.22   thorpej {
    122      1.83      matt 	if (CPU_IS_PRIMARY(curcpu())) {
    123      1.83      matt 		extern unsigned int page0[], page0_data[];
    124      1.83      matt 		unsigned int *vectors = (int *) va;
    125      1.83      matt 		unsigned int *vectors_data = vectors + (page0_data - page0);
    126      1.83      matt 		int vec;
    127      1.22   thorpej 
    128      1.83      matt 		/*
    129      1.83      matt 		 * Loop through the vectors we're taking over, and copy the
    130      1.83      matt 		 * vector's insn and data word.
    131      1.83      matt 		 */
    132      1.83      matt 		for (vec = 0; vec < ARM_NVEC; vec++) {
    133      1.83      matt 			if ((which & (1 << vec)) == 0) {
    134      1.83      matt 				/* Don't want to take over this vector. */
    135      1.83      matt 				continue;
    136      1.83      matt 			}
    137      1.83      matt 			vectors[vec] = page0[vec];
    138      1.83      matt 			vectors_data[vec] = page0_data[vec];
    139      1.22   thorpej 		}
    140      1.22   thorpej 
    141      1.83      matt 		/* Now sync the vectors. */
    142      1.83      matt 		cpu_icache_sync_range(va, (ARM_NVEC * 2) * sizeof(u_int));
    143      1.22   thorpej 
    144      1.83      matt 		vector_page = va;
    145      1.83      matt 	}
    146      1.30       scw 
    147      1.30       scw 	if (va == ARM_VECTORS_HIGH) {
    148      1.30       scw 		/*
    149      1.30       scw 		 * Assume the MD caller knows what it's doing here, and
    150      1.30       scw 		 * really does want the vector page relocated.
    151      1.30       scw 		 *
    152      1.30       scw 		 * Note: This has to be done here (and not just in
    153      1.30       scw 		 * cpu_setup()) because the vector page needs to be
    154      1.30       scw 		 * accessible *before* cpu_startup() is called.
    155      1.30       scw 		 * Think ddb(9) ...
    156      1.32   thorpej 		 *
    157      1.32   thorpej 		 * NOTE: If the CPU control register is not readable,
    158      1.32   thorpej 		 * this will totally fail!  We'll just assume that
    159      1.32   thorpej 		 * any system that has high vector support has a
    160      1.32   thorpej 		 * readable CPU control register, for now.  If we
    161      1.32   thorpej 		 * ever encounter one that does not, we'll have to
    162      1.32   thorpej 		 * rethink this.
    163      1.30       scw 		 */
    164      1.30       scw 		cpu_control(CPU_CONTROL_VECRELOC, CPU_CONTROL_VECRELOC);
    165      1.30       scw 	}
    166      1.22   thorpej }
    167      1.22   thorpej 
    168      1.22   thorpej /*
    169       1.1     chris  * Debug function just to park the CPU
    170       1.1     chris  */
    171       1.1     chris 
    172       1.1     chris void
    173      1.65    cegger halt(void)
    174       1.1     chris {
    175       1.1     chris 	while (1)
    176       1.1     chris 		cpu_sleep(0);
    177       1.1     chris }
    178       1.1     chris 
    179       1.1     chris 
    180       1.1     chris /* Sync the discs and unmount the filesystems */
    181       1.1     chris 
    182       1.1     chris void
    183       1.1     chris bootsync(void)
    184       1.1     chris {
    185      1.58      matt 	static bool bootsyncdone = false;
    186       1.1     chris 
    187       1.1     chris 	if (bootsyncdone) return;
    188       1.1     chris 
    189      1.58      matt 	bootsyncdone = true;
    190       1.1     chris 
    191       1.1     chris 	/* Make sure we can still manage to do things */
    192       1.1     chris 	if (GetCPSR() & I32_bit) {
    193       1.1     chris 		/*
    194       1.1     chris 		 * If we get here then boot has been called without RB_NOSYNC
    195       1.1     chris 		 * and interrupts were disabled. This means the boot() call
    196       1.1     chris 		 * did not come from a user process e.g. shutdown, but must
    197       1.1     chris 		 * have come from somewhere in the kernel.
    198       1.1     chris 		 */
    199       1.1     chris 		IRQenable;
    200       1.1     chris 		printf("Warning IRQ's disabled during boot()\n");
    201       1.1     chris 	}
    202       1.1     chris 
    203       1.1     chris 	vfs_shutdown();
    204       1.1     chris }
    205       1.1     chris 
    206       1.1     chris /*
    207       1.1     chris  * void cpu_startup(void)
    208       1.1     chris  *
    209      1.76       wiz  * Machine dependent startup code.
    210       1.1     chris  *
    211       1.1     chris  */
    212       1.1     chris void
    213      1.58      matt cpu_startup(void)
    214       1.1     chris {
    215      1.42        pk 	vaddr_t minaddr;
    216      1.42        pk 	vaddr_t maxaddr;
    217      1.42        pk 	u_int loop;
    218       1.1     chris 	char pbuf[9];
    219       1.1     chris 
    220      1.83      matt 	/*
    221      1.83      matt 	 * Until we better locking, we have to live under the kernel lock.
    222      1.83      matt 	 */
    223      1.83      matt 	//KERNEL_LOCK(1, NULL);
    224      1.83      matt 
    225      1.43       wiz 	/* Set the CPU control register */
    226       1.1     chris 	cpu_setup(boot_args);
    227       1.1     chris 
    228       1.1     chris 	/* Lock down zero page */
    229      1.22   thorpej 	vector_page_setprot(VM_PROT_READ);
    230       1.1     chris 
    231       1.1     chris 	/*
    232       1.1     chris 	 * Give pmap a chance to set up a few more things now the vm
    233       1.1     chris 	 * is initialised
    234       1.1     chris 	 */
    235       1.1     chris 	pmap_postinit();
    236       1.1     chris 
    237       1.1     chris 	/*
    238       1.1     chris 	 * Initialize error message buffer (at end of core).
    239       1.1     chris 	 */
    240       1.1     chris 
    241       1.1     chris 	/* msgbufphys was setup during the secondary boot strap */
    242       1.1     chris 	for (loop = 0; loop < btoc(MSGBUFSIZE); ++loop)
    243      1.29   thorpej 		pmap_kenter_pa((vaddr_t)msgbufaddr + loop * PAGE_SIZE,
    244      1.67    cegger 		    msgbufphys + loop * PAGE_SIZE,
    245      1.67    cegger 		    VM_PROT_READ|VM_PROT_WRITE, 0);
    246       1.5     chris 	pmap_update(pmap_kernel());
    247       1.1     chris 	initmsgbuf(msgbufaddr, round_page(MSGBUFSIZE));
    248       1.1     chris 
    249       1.1     chris 	/*
    250       1.1     chris 	 * Identify ourselves for the msgbuf (everything printed earlier will
    251       1.1     chris 	 * not be buffered).
    252       1.1     chris 	 */
    253      1.45     lukem 	printf("%s%s", copyright, version);
    254       1.1     chris 
    255      1.20   thorpej 	format_bytes(pbuf, sizeof(pbuf), arm_ptob(physmem));
    256       1.1     chris 	printf("total memory = %s\n", pbuf);
    257       1.1     chris 
    258      1.42        pk 	minaddr = 0;
    259       1.1     chris 
    260       1.1     chris 	/*
    261       1.1     chris 	 * Allocate a submap for physio
    262       1.1     chris 	 */
    263       1.1     chris 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    264      1.47   thorpej 				   VM_PHYS_SIZE, 0, false, NULL);
    265       1.1     chris 
    266       1.1     chris 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    267       1.1     chris 	printf("avail memory = %s\n", pbuf);
    268       1.1     chris 
    269      1.81      matt 	struct lwp * const l = &lwp0;
    270      1.81      matt 	struct pcb * const pcb = lwp_getpcb(l);
    271      1.81      matt 	pcb->pcb_sp = uvm_lwp_getuarea(l) + USPACE_SVC_STACK_TOP;
    272      1.81      matt 	lwp_settrapframe(l, (struct trapframe *)pcb->pcb_sp - 1);
    273       1.1     chris }
    274       1.1     chris 
    275       1.1     chris /*
    276       1.1     chris  * machine dependent system variables.
    277       1.1     chris  */
    278      1.39    atatat static int
    279      1.39    atatat sysctl_machdep_booted_device(SYSCTLFN_ARGS)
    280      1.39    atatat {
    281      1.39    atatat 	struct sysctlnode node;
    282      1.39    atatat 
    283      1.39    atatat 	if (booted_device == NULL)
    284      1.39    atatat 		return (EOPNOTSUPP);
    285      1.39    atatat 
    286      1.39    atatat 	node = *rnode;
    287  1.83.2.1       tls 	node.sysctl_data = __UNCONST(device_xname(booted_device));
    288  1.83.2.1       tls 	node.sysctl_size = strlen(device_xname(booted_device)) + 1;
    289      1.39    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    290      1.39    atatat }
    291       1.1     chris 
    292      1.39    atatat static int
    293      1.39    atatat sysctl_machdep_booted_kernel(SYSCTLFN_ARGS)
    294       1.1     chris {
    295      1.39    atatat 	struct sysctlnode node;
    296      1.39    atatat 
    297      1.39    atatat 	if (booted_kernel == NULL || booted_kernel[0] == '\0')
    298       1.1     chris 		return (EOPNOTSUPP);
    299       1.1     chris 
    300      1.39    atatat 	node = *rnode;
    301      1.39    atatat 	node.sysctl_data = booted_kernel;
    302      1.39    atatat 	node.sysctl_size = strlen(booted_kernel) + 1;
    303      1.39    atatat 	return (sysctl_lookup(SYSCTLFN_CALL(&node)));
    304      1.39    atatat }
    305      1.25   thorpej 
    306      1.39    atatat static int
    307      1.39    atatat sysctl_machdep_powersave(SYSCTLFN_ARGS)
    308      1.39    atatat {
    309      1.39    atatat 	struct sysctlnode node = *rnode;
    310      1.39    atatat 	int error, newval;
    311      1.25   thorpej 
    312      1.39    atatat 	newval = cpu_do_powersave;
    313      1.39    atatat 	node.sysctl_data = &newval;
    314      1.39    atatat 	if (cpufuncs.cf_sleep == (void *) cpufunc_nullop)
    315      1.44    atatat 		node.sysctl_flags &= ~CTLFLAG_READWRITE;
    316      1.39    atatat 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
    317      1.39    atatat 	if (error || newp == NULL || newval == cpu_do_powersave)
    318      1.39    atatat 		return (error);
    319      1.39    atatat 
    320      1.39    atatat 	if (newval < 0 || newval > 1)
    321      1.39    atatat 		return (EINVAL);
    322      1.39    atatat 	cpu_do_powersave = newval;
    323      1.25   thorpej 
    324      1.39    atatat 	return (0);
    325      1.39    atatat }
    326      1.25   thorpej 
    327      1.39    atatat SYSCTL_SETUP(sysctl_machdep_setup, "sysctl machdep subtree setup")
    328      1.39    atatat {
    329       1.1     chris 
    330      1.44    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    331      1.44    atatat 		       CTLFLAG_PERMANENT,
    332      1.39    atatat 		       CTLTYPE_NODE, "machdep", NULL,
    333      1.39    atatat 		       NULL, 0, NULL, 0,
    334      1.39    atatat 		       CTL_MACHDEP, CTL_EOL);
    335      1.39    atatat 
    336      1.44    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    337      1.44    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    338      1.40    atatat 		       CTLTYPE_INT, "debug", NULL,
    339      1.39    atatat 		       NULL, 0, &kernel_debug, 0,
    340      1.41  rearnsha 		       CTL_MACHDEP, CPU_DEBUG, CTL_EOL);
    341      1.44    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    342      1.44    atatat 		       CTLFLAG_PERMANENT,
    343      1.39    atatat 		       CTLTYPE_STRING, "booted_device", NULL,
    344      1.39    atatat 		       sysctl_machdep_booted_device, 0, NULL, 0,
    345      1.39    atatat 		       CTL_MACHDEP, CPU_BOOTED_DEVICE, CTL_EOL);
    346      1.44    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    347      1.44    atatat 		       CTLFLAG_PERMANENT,
    348      1.39    atatat 		       CTLTYPE_STRING, "booted_kernel", NULL,
    349      1.39    atatat 		       sysctl_machdep_booted_kernel, 0, NULL, 0,
    350      1.39    atatat 		       CTL_MACHDEP, CPU_BOOTED_KERNEL, CTL_EOL);
    351      1.44    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    352      1.44    atatat 		       CTLFLAG_PERMANENT,
    353      1.39    atatat 		       CTLTYPE_STRUCT, "console_device", NULL,
    354      1.39    atatat 		       sysctl_consdev, 0, NULL, sizeof(dev_t),
    355      1.39    atatat 		       CTL_MACHDEP, CPU_CONSDEV, CTL_EOL);
    356      1.44    atatat 	sysctl_createv(clog, 0, NULL, NULL,
    357      1.44    atatat 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    358      1.39    atatat 		       CTLTYPE_INT, "powersave", NULL,
    359      1.39    atatat 		       sysctl_machdep_powersave, 0, &cpu_do_powersave, 0,
    360      1.39    atatat 		       CTL_MACHDEP, CPU_POWERSAVE, CTL_EOL);
    361       1.1     chris }
    362       1.1     chris 
    363       1.1     chris void
    364      1.64       dsl parse_mi_bootargs(char *args)
    365       1.1     chris {
    366       1.1     chris 	int integer;
    367       1.1     chris 
    368       1.1     chris 	if (get_bootconf_option(args, "single", BOOTOPT_TYPE_BOOLEAN, &integer)
    369       1.1     chris 	    || get_bootconf_option(args, "-s", BOOTOPT_TYPE_BOOLEAN, &integer))
    370       1.1     chris 		if (integer)
    371       1.1     chris 			boothowto |= RB_SINGLE;
    372       1.1     chris 	if (get_bootconf_option(args, "kdb", BOOTOPT_TYPE_BOOLEAN, &integer)
    373       1.1     chris 	    || get_bootconf_option(args, "-k", BOOTOPT_TYPE_BOOLEAN, &integer))
    374       1.1     chris 		if (integer)
    375       1.1     chris 			boothowto |= RB_KDB;
    376       1.1     chris 	if (get_bootconf_option(args, "ask", BOOTOPT_TYPE_BOOLEAN, &integer)
    377       1.1     chris 	    || get_bootconf_option(args, "-a", BOOTOPT_TYPE_BOOLEAN, &integer))
    378       1.1     chris 		if (integer)
    379       1.1     chris 			boothowto |= RB_ASKNAME;
    380       1.1     chris 
    381       1.1     chris #ifdef PMAP_DEBUG
    382       1.1     chris 	if (get_bootconf_option(args, "pmapdebug", BOOTOPT_TYPE_INT, &integer)) {
    383       1.1     chris 		pmap_debug_level = integer;
    384       1.1     chris 		pmap_debug(pmap_debug_level);
    385       1.1     chris 	}
    386       1.1     chris #endif	/* PMAP_DEBUG */
    387       1.1     chris 
    388       1.1     chris /*	if (get_bootconf_option(args, "nbuf", BOOTOPT_TYPE_INT, &integer))
    389       1.1     chris 		bufpages = integer;*/
    390       1.1     chris 
    391      1.74   hannken #if defined(MEMORY_DISK_HOOKS) && !defined(MEMORY_DISK_ROOT_SIZE)
    392       1.1     chris 	if (get_bootconf_option(args, "memorydisc", BOOTOPT_TYPE_INT, &integer)
    393       1.1     chris 	    || get_bootconf_option(args, "memorydisk", BOOTOPT_TYPE_INT, &integer)) {
    394      1.24  jdolecek 		md_root_size = integer;
    395      1.24  jdolecek 		md_root_size *= 1024;
    396      1.24  jdolecek 		if (md_root_size < 32*1024)
    397      1.24  jdolecek 			md_root_size = 32*1024;
    398      1.24  jdolecek 		if (md_root_size > 2048*1024)
    399      1.24  jdolecek 			md_root_size = 2048*1024;
    400       1.1     chris 	}
    401      1.74   hannken #endif	/* MEMORY_DISK_HOOKS && !MEMORY_DISK_ROOT_SIZE */
    402       1.1     chris 
    403       1.1     chris 	if (get_bootconf_option(args, "quiet", BOOTOPT_TYPE_BOOLEAN, &integer)
    404       1.1     chris 	    || get_bootconf_option(args, "-q", BOOTOPT_TYPE_BOOLEAN, &integer))
    405       1.1     chris 		if (integer)
    406       1.1     chris 			boothowto |= AB_QUIET;
    407       1.1     chris 	if (get_bootconf_option(args, "verbose", BOOTOPT_TYPE_BOOLEAN, &integer)
    408       1.1     chris 	    || get_bootconf_option(args, "-v", BOOTOPT_TYPE_BOOLEAN, &integer))
    409       1.1     chris 		if (integer)
    410       1.1     chris 			boothowto |= AB_VERBOSE;
    411       1.1     chris }
    412      1.49      yamt 
    413      1.56      matt #ifdef __HAVE_FAST_SOFTINTS
    414      1.56      matt #if IPL_SOFTSERIAL != IPL_SOFTNET + 1
    415      1.56      matt #error IPLs are screwed up
    416      1.58      matt #elif IPL_SOFTNET != IPL_SOFTBIO + 1
    417      1.58      matt #error IPLs are screwed up
    418      1.58      matt #elif IPL_SOFTBIO != IPL_SOFTCLOCK + 1
    419      1.56      matt #error IPLs are screwed up
    420      1.58      matt #elif !(IPL_SOFTCLOCK > IPL_NONE)
    421      1.56      matt #error IPLs are screwed up
    422      1.58      matt #elif (IPL_NONE != 0)
    423      1.56      matt #error IPLs are screwed up
    424      1.56      matt #endif
    425      1.58      matt 
    426      1.83      matt #ifndef __HAVE_PIC_FAST_SOFTINTS
    427      1.56      matt #define	SOFTINT2IPLMAP \
    428      1.58      matt 	(((IPL_SOFTSERIAL - IPL_SOFTCLOCK) << (SOFTINT_SERIAL * 4)) | \
    429      1.58      matt 	 ((IPL_SOFTNET    - IPL_SOFTCLOCK) << (SOFTINT_NET    * 4)) | \
    430      1.58      matt 	 ((IPL_SOFTBIO    - IPL_SOFTCLOCK) << (SOFTINT_BIO    * 4)) | \
    431      1.58      matt 	 ((IPL_SOFTCLOCK  - IPL_SOFTCLOCK) << (SOFTINT_CLOCK  * 4)))
    432      1.56      matt #define	SOFTINT2IPL(l)	((SOFTINT2IPLMAP >> ((l) * 4)) & 0x0f)
    433      1.56      matt 
    434      1.56      matt /*
    435      1.56      matt  * This returns a mask of softint IPLs that be dispatch at <ipl>
    436      1.59      matt  * SOFTIPLMASK(IPL_NONE)	= 0x0000000f
    437      1.59      matt  * SOFTIPLMASK(IPL_SOFTCLOCK)	= 0x0000000e
    438      1.59      matt  * SOFTIPLMASK(IPL_SOFTBIO)	= 0x0000000c
    439      1.59      matt  * SOFTIPLMASK(IPL_SOFTNET)	= 0x00000008
    440      1.59      matt  * SOFTIPLMASK(IPL_SOFTSERIAL)	= 0x00000000
    441      1.56      matt  */
    442      1.78     skrll #define	SOFTIPLMASK(ipl) ((0x0f << (ipl)) & 0x0f)
    443      1.56      matt 
    444      1.56      matt void softint_switch(lwp_t *, int);
    445      1.56      matt 
    446      1.56      matt void
    447      1.56      matt softint_trigger(uintptr_t mask)
    448      1.56      matt {
    449      1.56      matt 	curcpu()->ci_softints |= mask;
    450      1.56      matt }
    451      1.56      matt 
    452      1.56      matt void
    453      1.56      matt softint_init_md(lwp_t *l, u_int level, uintptr_t *machdep)
    454      1.56      matt {
    455      1.83      matt 	lwp_t ** lp = &l->l_cpu->ci_softlwps[level];
    456      1.56      matt 	KASSERT(*lp == NULL || *lp == l);
    457      1.56      matt 	*lp = l;
    458      1.56      matt 	*machdep = 1 << SOFTINT2IPL(level);
    459      1.59      matt 	KASSERT(level != SOFTINT_CLOCK || *machdep == (1 << (IPL_SOFTCLOCK - IPL_SOFTCLOCK)));
    460      1.59      matt 	KASSERT(level != SOFTINT_BIO || *machdep == (1 << (IPL_SOFTBIO - IPL_SOFTCLOCK)));
    461      1.59      matt 	KASSERT(level != SOFTINT_NET || *machdep == (1 << (IPL_SOFTNET - IPL_SOFTCLOCK)));
    462      1.59      matt 	KASSERT(level != SOFTINT_SERIAL || *machdep == (1 << (IPL_SOFTSERIAL - IPL_SOFTCLOCK)));
    463      1.56      matt }
    464      1.53       mrg 
    465      1.56      matt void
    466      1.56      matt dosoftints(void)
    467      1.56      matt {
    468      1.56      matt 	struct cpu_info * const ci = curcpu();
    469      1.56      matt 	const int opl = ci->ci_cpl;
    470      1.56      matt 	const uint32_t softiplmask = SOFTIPLMASK(opl);
    471      1.56      matt 
    472      1.77     skrll 	splhigh();
    473      1.56      matt 	for (;;) {
    474      1.56      matt 		u_int softints = ci->ci_softints & softiplmask;
    475      1.59      matt 		KASSERT((softints != 0) == ((ci->ci_softints >> opl) != 0));
    476      1.77     skrll 		KASSERT(opl == IPL_NONE || (softints & (1 << (opl - IPL_SOFTCLOCK))) == 0);
    477      1.77     skrll 		if (softints == 0) {
    478      1.77     skrll 			splx(opl);
    479      1.56      matt 			return;
    480      1.77     skrll 		}
    481      1.56      matt #define	DOSOFTINT(n) \
    482      1.77     skrll 		if (ci->ci_softints & (1 << (IPL_SOFT ## n - IPL_SOFTCLOCK))) { \
    483      1.58      matt 			ci->ci_softints &= \
    484      1.58      matt 			    ~(1 << (IPL_SOFT ## n - IPL_SOFTCLOCK)); \
    485      1.56      matt 			softint_switch(ci->ci_softlwps[SOFTINT_ ## n], \
    486      1.56      matt 			    IPL_SOFT ## n); \
    487      1.56      matt 			continue; \
    488      1.56      matt 		}
    489      1.56      matt 		DOSOFTINT(SERIAL);
    490      1.56      matt 		DOSOFTINT(NET);
    491      1.56      matt 		DOSOFTINT(BIO);
    492      1.56      matt 		DOSOFTINT(CLOCK);
    493      1.56      matt 		panic("dosoftints wtf (softints=%u?, ipl=%d)", softints, opl);
    494      1.56      matt 	}
    495      1.53       mrg }
    496      1.83      matt #endif /* !__HAVE_PIC_FAST_SOFTINTS */
    497      1.56      matt #endif /* __HAVE_FAST_SOFTINTS */
    498      1.72      jmmv 
    499      1.72      jmmv #ifdef MODULAR
    500      1.72      jmmv /*
    501      1.72      jmmv  * Push any modules loaded by the boot loader.
    502      1.72      jmmv  */
    503      1.72      jmmv void
    504      1.72      jmmv module_init_md(void)
    505      1.72      jmmv {
    506      1.72      jmmv }
    507      1.72      jmmv #endif /* MODULAR */
    508      1.75     rmind 
    509      1.75     rmind int
    510      1.75     rmind mm_md_physacc(paddr_t pa, vm_prot_t prot)
    511      1.75     rmind {
    512      1.75     rmind 
    513      1.75     rmind 	return (pa < ctob(physmem)) ? 0 : EFAULT;
    514      1.75     rmind }
    515      1.83      matt 
    516      1.83      matt #ifdef __HAVE_CPU_UAREA_ALLOC_IDLELWP
    517      1.83      matt vaddr_t
    518      1.83      matt cpu_uarea_alloc_idlelwp(struct cpu_info *ci)
    519      1.83      matt {
    520      1.83      matt 	const vaddr_t va = idlestack.pv_va + ci->ci_cpuid * USPACE;
    521      1.83      matt 	// printf("%s: %s: va=%lx\n", __func__, ci->ci_data.cpu_name, va);
    522      1.83      matt 	return va;
    523      1.83      matt }
    524      1.83      matt #endif
    525      1.83      matt 
    526      1.83      matt #ifdef MULTIPROCESSOR
    527      1.83      matt void
    528      1.83      matt cpu_boot_secondary_processors(void)
    529      1.83      matt {
    530      1.83      matt 	uint32_t mbox;
    531  1.83.2.1       tls 	kcpuset_export_u32(kcpuset_attached, &mbox, sizeof(mbox));
    532      1.83      matt 	atomic_swap_32(&arm_cpu_mbox, mbox);
    533      1.83      matt 	membar_producer();
    534      1.83      matt #ifdef _ARM_ARCH_7
    535      1.83      matt 	__asm __volatile("sev; sev; sev");
    536      1.83      matt #endif
    537      1.83      matt }
    538      1.83      matt 
    539      1.83      matt void
    540      1.83      matt xc_send_ipi(struct cpu_info *ci)
    541      1.83      matt {
    542      1.83      matt 	KASSERT(kpreempt_disabled());
    543      1.83      matt 	KASSERT(curcpu() != ci);
    544      1.83      matt 
    545      1.83      matt 
    546      1.83      matt 	if (ci) {
    547      1.83      matt 		/* Unicast, remote CPU */
    548      1.83      matt 		printf("%s: -> %s", __func__, ci->ci_data.cpu_name);
    549      1.83      matt 		intr_ipi_send(ci->ci_kcpuset, IPI_XCALL);
    550      1.83      matt 	} else {
    551      1.83      matt 		printf("%s: -> !%s", __func__, ci->ci_data.cpu_name);
    552      1.83      matt 		/* Broadcast to all but ourselves */
    553      1.83      matt 		kcpuset_t *kcp;
    554      1.83      matt 		kcpuset_create(&kcp, (ci != NULL));
    555      1.83      matt 		KASSERT(kcp != NULL);
    556      1.83      matt 		kcpuset_copy(kcp, kcpuset_running);
    557      1.83      matt 		kcpuset_clear(kcp, cpu_index(ci));
    558      1.83      matt 		intr_ipi_send(kcp, IPI_XCALL);
    559      1.83      matt 		kcpuset_destroy(kcp);
    560      1.83      matt 	}
    561      1.83      matt 	printf("\n");
    562      1.83      matt }
    563      1.83      matt #endif /* MULTIPROCESSOR */
    564