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