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