Home | History | Annotate | Line # | Download | only in eb7500atx
      1  1.37    andvar /*	$NetBSD: eb7500atx_machdep.c,v 1.37 2022/05/15 20:37:51 andvar Exp $	*/
      2   1.1     chris 
      3   1.1     chris /*
      4   1.1     chris  * Copyright (c) 2000-2002 Reinoud Zandijk.
      5   1.1     chris  * Copyright (c) 1994-1998 Mark Brinicombe.
      6   1.1     chris  * Copyright (c) 1994 Brini.
      7   1.1     chris  * All rights reserved.
      8   1.1     chris  *
      9   1.1     chris  * This code is derived from software written for Brini by Mark Brinicombe
     10   1.1     chris  *
     11   1.1     chris  * Redistribution and use in source and binary forms, with or without
     12   1.1     chris  * modification, are permitted provided that the following conditions
     13   1.1     chris  * are met:
     14   1.1     chris  * 1. Redistributions of source code must retain the above copyright
     15   1.1     chris  *    notice, this list of conditions and the following disclaimer.
     16   1.1     chris  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.1     chris  *    notice, this list of conditions and the following disclaimer in the
     18   1.1     chris  *    documentation and/or other materials provided with the distribution.
     19   1.1     chris  * 3. All advertising materials mentioning features or use of this software
     20   1.1     chris  *    must display the following acknowledgement:
     21   1.1     chris  *	This product includes software developed by Brini.
     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 BRINI ``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 BRINI 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.1     chris  * RiscBSD kernel project
     39   1.1     chris  *
     40   1.1     chris  * machdep.c
     41   1.1     chris  *
     42  1.20       wiz  * Machine dependent functions for kernel setup
     43   1.1     chris  *
     44   1.1     chris  * This file still needs a lot of work
     45   1.1     chris  *
     46   1.1     chris  * Created      : 17/09/94
     47   1.1     chris  * Updated for yet another new bootloader 28/12/02
     48   1.1     chris  */
     49   1.1     chris 
     50   1.1     chris #include "opt_ddb.h"
     51  1.14       apb #include "opt_modular.h"
     52   1.1     chris #include "vidcvideo.h"
     53   1.1     chris #include "pckbc.h"
     54   1.1     chris 
     55   1.1     chris #include <sys/param.h>
     56   1.1     chris 
     57  1.37    andvar __KERNEL_RCSID(0, "$NetBSD: eb7500atx_machdep.c,v 1.37 2022/05/15 20:37:51 andvar Exp $");
     58   1.1     chris 
     59   1.1     chris #include <sys/systm.h>
     60   1.1     chris #include <sys/kernel.h>
     61   1.1     chris #include <sys/reboot.h>
     62   1.1     chris #include <sys/proc.h>
     63   1.1     chris #include <sys/msgbuf.h>
     64   1.1     chris #include <sys/exec.h>
     65  1.16   tsutsui #include <sys/exec_aout.h>
     66   1.1     chris #include <sys/ksyms.h>
     67  1.21    dyoung #include <sys/bus.h>
     68  1.26      matt #include <sys/cpu.h>
     69  1.26      matt #include <sys/intr.h>
     70  1.26      matt #include <sys/device.h>
     71   1.1     chris 
     72   1.1     chris #include <dev/cons.h>
     73   1.1     chris 
     74  1.26      matt #include <dev/ic/pckbcvar.h>
     75  1.26      matt 
     76  1.26      matt #include <dev/i2c/i2cvar.h>
     77  1.26      matt #include <dev/i2c/pcf8583var.h>
     78  1.26      matt 
     79   1.1     chris #include <machine/db_machdep.h>
     80   1.1     chris #include <ddb/db_sym.h>
     81   1.1     chris #include <ddb/db_extern.h>
     82   1.1     chris 
     83   1.1     chris #include <uvm/uvm.h>
     84   1.1     chris 
     85  1.26      matt #include <arm/locore.h>
     86  1.26      matt #include <arm/undefined.h>
     87  1.26      matt 
     88   1.1     chris #include <machine/signal.h>
     89   1.1     chris #include <machine/bootconfig.h>
     90   1.1     chris #include <machine/io.h>
     91   1.1     chris #include <arm/arm32/machdep.h>
     92   1.1     chris #include <machine/rtc.h>
     93   1.1     chris 
     94   1.1     chris #include <arm/iomd/vidc.h>
     95   1.1     chris #include <arm/iomd/iomdreg.h>
     96   1.1     chris #include <arm/iomd/iomdvar.h>
     97   1.1     chris #include <arm/iomd/vidcvideo.h>
     98   1.1     chris #include <arm/iomd/iomdiicvar.h>
     99   1.1     chris 
    100   1.1     chris /* static i2c_tag_t acorn32_i2c_tag;*/
    101   1.1     chris 
    102   1.1     chris #include "ksyms.h"
    103   1.1     chris 
    104   1.1     chris /* Kernel text starts at the base of the kernel address space. */
    105   1.1     chris #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00000000)
    106   1.1     chris #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    107   1.1     chris 
    108   1.1     chris /*
    109   1.1     chris  * The range 0xf1000000 - 0xf5ffffff is available for kernel VM space
    110   1.1     chris  * Fixed mappings exist from 0xf6000000 - 0xffffffff
    111   1.1     chris  */
    112   1.1     chris #define	KERNEL_VM_SIZE		0x05000000
    113   1.1     chris 
    114   1.1     chris /*
    115   1.1     chris  * Address to call from cpu_reset() to reset the machine.
    116  1.20       wiz  * This is machine architecture dependent as it varies depending
    117   1.1     chris  * on where the ROM appears when you turn the MMU off.
    118   1.1     chris  */
    119   1.1     chris 
    120   1.1     chris #define VERBOSE_INIT_ARM
    121   1.1     chris 
    122   1.1     chris struct bootconfig bootconfig;	/* Boot config storage */
    123   1.1     chris videomemory_t videomemory;	/* Video memory descriptor */
    124   1.1     chris 
    125   1.1     chris char *boot_args = NULL;		/* holds the pre-processed boot arguments */
    126   1.1     chris extern char *booted_kernel;	/* used for ioctl to retrieve booted kernel */
    127   1.1     chris 
    128   1.1     chris extern int       *vidc_base;
    129  1.22     skrll extern uint32_t  iomd_base;
    130   1.1     chris extern struct bus_space iomd_bs_tag;
    131   1.1     chris 
    132   1.1     chris paddr_t physical_start;
    133   1.1     chris paddr_t physical_freestart;
    134   1.1     chris paddr_t physical_freeend;
    135   1.1     chris paddr_t physical_end;
    136   1.1     chris paddr_t dma_range_begin;
    137   1.1     chris paddr_t dma_range_end;
    138   1.1     chris 
    139   1.1     chris u_int free_pages;
    140   1.1     chris paddr_t memoryblock_end;
    141   1.1     chris 
    142   1.1     chris #ifndef PMAP_STATIC_L1S
    143   1.1     chris int max_processes = 64;		/* Default number */
    144   1.1     chris #endif	/* !PMAP_STATIC_L1S */
    145   1.1     chris 
    146   1.1     chris u_int videodram_size = 0;	/* Amount of DRAM to reserve for video */
    147   1.1     chris 
    148   1.1     chris paddr_t msgbufphys;
    149   1.1     chris 
    150   1.1     chris #define	KERNEL_PT_VMEM		0 /* Page table for mapping video memory */
    151   1.1     chris #define	KERNEL_PT_SYS		1 /* Page table for mapping proc0 zero page */
    152   1.1     chris #define	KERNEL_PT_KERNEL	2 /* Page table for mapping kernel */
    153   1.1     chris #define	KERNEL_PT_VMDATA	3 /* Page tables for mapping kernel VM */
    154  1.33     skrll #define	KERNEL_PT_VMDATA_NUM	4 /* start with 16MB of KVM */
    155   1.1     chris #define	NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    156   1.1     chris 
    157   1.1     chris pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    158   1.1     chris 
    159   1.1     chris 
    160   1.1     chris #ifdef CPU_SA110
    161   1.1     chris #define CPU_SA110_CACHE_CLEAN_SIZE (0x4000 * 2)
    162   1.1     chris static vaddr_t sa110_cc_base;
    163   1.1     chris #endif	/* CPU_SA110 */
    164   1.1     chris 
    165   1.1     chris /* Prototypes */
    166   1.1     chris void physcon_display_base(u_int);
    167   1.1     chris extern void consinit(void);
    168   1.1     chris 
    169   1.1     chris void data_abort_handler(trapframe_t *);
    170   1.1     chris void prefetch_abort_handler(trapframe_t *);
    171   1.1     chris void undefinedinstruction_bounce(trapframe_t *frame);
    172   1.1     chris 
    173   1.1     chris static void canonicalise_bootconfig(struct bootconfig *, struct bootconfig *);
    174   1.1     chris static void process_kernel_args(void);
    175   1.1     chris 
    176   1.1     chris extern void dump_spl_masks(void);
    177   1.1     chris 
    178   1.1     chris void rpc_sa110_cc_setup(void);
    179   1.1     chris 
    180   1.1     chris void parse_rpc_bootargs(char *args);
    181   1.1     chris 
    182   1.1     chris extern void dumpsys(void);
    183   1.1     chris 
    184   1.1     chris 
    185   1.1     chris #	define console_flush()		/* empty */
    186   1.1     chris 
    187   1.1     chris 
    188   1.1     chris #define panic2(a) do {							\
    189   1.1     chris 	memset((void *) (videomemory.vidm_vbase), 0x55, 50*1024);	\
    190   1.1     chris 	consinit();							\
    191   1.1     chris 	panic a;							\
    192   1.1     chris } while (/* CONSTCOND */ 0)
    193   1.1     chris 
    194   1.1     chris /*
    195   1.1     chris  * void cpu_reboot(int howto, char *bootstr)
    196   1.1     chris  *
    197   1.1     chris  * Reboots the system
    198   1.1     chris  *
    199   1.1     chris  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    200   1.1     chris  * then reset the CPU.
    201   1.1     chris  */
    202   1.1     chris 
    203   1.1     chris /* NOTE: These variables will be removed, well some of them */
    204   1.1     chris 
    205   1.1     chris extern u_int current_mask;
    206   1.1     chris 
    207   1.1     chris void
    208   1.1     chris cpu_reboot(int howto, char *bootstr)
    209   1.1     chris {
    210   1.1     chris 
    211   1.1     chris #ifdef DIAGNOSTIC
    212   1.1     chris 	printf("boot: howto=%08x curlwp=%p\n", howto, curlwp);
    213   1.1     chris 
    214   1.1     chris 	printf("ipl_bio=%08x ipl_net=%08x ipl_tty=%08x ipl_vm=%08x\n",
    215   1.1     chris 	    irqmasks[IPL_BIO], irqmasks[IPL_NET], irqmasks[IPL_TTY],
    216   1.1     chris 	    irqmasks[IPL_VM]);
    217   1.1     chris 	printf("ipl_audio=%08x ipl_clock=%08x ipl_none=%08x\n",
    218   1.1     chris 	    irqmasks[IPL_AUDIO], irqmasks[IPL_CLOCK], irqmasks[IPL_NONE]);
    219   1.1     chris 
    220   1.1     chris 	/* dump_spl_masks(); */
    221   1.1     chris #endif	/* DIAGNOSTIC */
    222   1.1     chris 
    223   1.1     chris 	/*
    224   1.1     chris 	 * If we are still cold then hit the air brakes
    225   1.1     chris 	 * and crash to earth fast
    226   1.1     chris 	 */
    227   1.1     chris 	if (cold) {
    228   1.1     chris 		doshutdownhooks();
    229  1.10    dyoung 		pmf_system_shutdown(boothowto);
    230   1.1     chris 		printf("Halted while still in the ICE age.\n");
    231   1.1     chris 		printf("The operating system has halted.\n");
    232   1.1     chris 		printf("Please press any key to reboot.\n\n");
    233   1.1     chris 		cngetc();
    234   1.1     chris 		printf("rebooting...\n");
    235   1.1     chris 		cpu_reset();
    236   1.1     chris 		/*NOTREACHED*/
    237   1.1     chris 	}
    238   1.1     chris 
    239   1.1     chris 	/* Disable console buffering */
    240   1.1     chris 	cnpollc(1);
    241   1.1     chris 
    242   1.1     chris 	/*
    243   1.1     chris 	 * If RB_NOSYNC was not specified sync the discs.
    244   1.1     chris 	 * Note: Unless cold is set to 1 here, syslogd will die during
    245   1.1     chris 	 * the unmount.  It looks like syslogd is getting woken up
    246   1.1     chris 	 * only to find that it cannot page part of the binary in as
    247   1.1     chris 	 * the filesystem has been unmounted.
    248   1.1     chris 	 */
    249   1.1     chris 	if (!(howto & RB_NOSYNC))
    250   1.1     chris 		bootsync();
    251   1.1     chris 
    252   1.1     chris 	/* Say NO to interrupts */
    253   1.1     chris 	splhigh();
    254   1.1     chris 
    255   1.1     chris 	/* Do a dump if requested. */
    256   1.1     chris 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    257   1.1     chris 		dumpsys();
    258   1.1     chris 
    259   1.1     chris 	/*
    260   1.1     chris 	 * Auto reboot overload protection
    261   1.1     chris 	 *
    262   1.1     chris 	 * This code stops the kernel entering an endless loop of reboot
    263   1.1     chris 	 * - panic cycles. This will have the effect of stopping further
    264   1.1     chris 	 * reboots after it has rebooted 8 times after panics. A clean
    265   1.1     chris 	 * halt or reboot will reset the counter.
    266   1.1     chris 	 */
    267   1.1     chris 
    268   1.1     chris 	/* Run any shutdown hooks */
    269   1.1     chris 	doshutdownhooks();
    270   1.1     chris 
    271  1.10    dyoung 	pmf_system_shutdown(boothowto);
    272  1.10    dyoung 
    273   1.1     chris 	/* Make sure IRQ's are disabled */
    274   1.1     chris 	IRQdisable;
    275   1.1     chris 
    276   1.1     chris 	if (howto & RB_HALT) {
    277   1.1     chris 		printf("The operating system has halted.\n");
    278   1.1     chris 		printf("Please press any key to reboot.\n\n");
    279   1.1     chris 		cngetc();
    280   1.1     chris 	}
    281   1.1     chris 
    282   1.1     chris 	printf("rebooting...\n");
    283   1.1     chris 	cpu_reset();
    284   1.1     chris 	/*NOTREACHED*/
    285   1.1     chris }
    286   1.1     chris 
    287   1.1     chris 
    288   1.1     chris /*
    289   1.1     chris  * u_int initarm(BootConfig *bootconf)
    290   1.1     chris  *
    291   1.1     chris  * Initial entry point on startup. This gets called before main() is
    292   1.1     chris  * entered.
    293   1.1     chris  * It should be responsible for setting up everything that must be
    294   1.1     chris  * in place when main is called.
    295   1.1     chris  * This includes
    296   1.1     chris  *   Taking a copy of the boot configuration structure.
    297   1.1     chris  *   Initialising the physical console so characters can be printed.
    298   1.1     chris  *   Setting up page tables for the kernel
    299   1.1     chris  *   Relocating the kernel to the bottom of physical memory
    300   1.1     chris  */
    301   1.1     chris 
    302   1.1     chris /*
    303   1.1     chris  * this part is completely rewritten for the new bootloader ... It features
    304   1.1     chris  * a flat memory map with a mapping comparable to the EBSA arm32 machine
    305   1.1     chris  * to boost the portability and likeness of the code
    306   1.1     chris  */
    307   1.1     chris 
    308   1.1     chris /*
    309   1.1     chris  * Mapping table for core kernel memory. This memory is mapped at init
    310   1.1     chris  * time with section mappings.
    311  1.33     skrll  *
    312   1.1     chris  * XXX One big assumption in the current architecture seems that the kernel is
    313   1.1     chris  * XXX supposed to be mapped into bootconfig.dram[0].
    314   1.1     chris  */
    315   1.1     chris 
    316   1.1     chris #define ONE_MB	0x100000
    317   1.1     chris 
    318   1.1     chris struct l1_sec_map {
    319   1.1     chris 	vaddr_t		va;
    320   1.1     chris 	paddr_t		pa;
    321   1.1     chris 	vsize_t		size;
    322   1.1     chris 	vm_prot_t	prot;
    323   1.1     chris 	int		cache;
    324   1.1     chris } l1_sec_table[] = {
    325   1.1     chris 	/* Map 1Mb section for VIDC20 */
    326   1.1     chris 	{ VIDC_BASE,		VIDC_HW_BASE,
    327   1.1     chris 	    ONE_MB,		VM_PROT_READ|VM_PROT_WRITE,
    328   1.1     chris 	    PTE_NOCACHE },
    329   1.1     chris 
    330   1.1     chris 	/* Map 1Mb section from IOMD */
    331   1.1     chris 	{ IOMD_BASE,		IOMD_HW_BASE,
    332   1.1     chris 	    ONE_MB,		VM_PROT_READ|VM_PROT_WRITE,
    333   1.1     chris 	    PTE_NOCACHE },
    334   1.1     chris 
    335   1.1     chris 	/* Map 1Mb of COMBO (and module space) */
    336   1.1     chris 	{ IO_BASE,		IO_HW_BASE,
    337   1.1     chris 	    ONE_MB,		VM_PROT_READ|VM_PROT_WRITE,
    338   1.1     chris 	    PTE_NOCACHE },
    339   1.1     chris 	{ 0, 0, 0, 0, 0 }
    340   1.1     chris };
    341   1.1     chris 
    342   1.1     chris 
    343   1.1     chris static void
    344   1.1     chris canonicalise_bootconfig(struct bootconfig *bootconf, struct bootconfig *raw_bootconf)
    345   1.1     chris {
    346   1.1     chris 	/* check for bootconfig v2+ structure */
    347   1.1     chris 	if (raw_bootconf->magic == BOOTCONFIG_MAGIC) {
    348   1.1     chris 		/* v2+ cleaned up structure found */
    349   1.1     chris 		*bootconf = *raw_bootconf;
    350   1.1     chris 		return;
    351   1.1     chris 	} else {
    352   1.1     chris 		panic2(("Internal error: no valid bootconfig block found"));
    353   1.1     chris 	}
    354   1.1     chris }
    355   1.1     chris 
    356   1.1     chris 
    357  1.31     skrll vaddr_t
    358   1.1     chris initarm(void *cookie)
    359   1.1     chris {
    360   1.1     chris 	struct bootconfig *raw_bootconf = cookie;
    361   1.1     chris 	int loop;
    362   1.1     chris 	int loop1;
    363   1.1     chris 	u_int logical;
    364   1.1     chris 	u_int kerneldatasize;
    365   1.1     chris 	u_int l1pagetable;
    366   1.1     chris 	struct exec *kernexec = (struct exec *)KERNEL_TEXT_BASE;
    367   1.1     chris 
    368   1.1     chris 	/*
    369   1.1     chris 	 * Heads up ... Setup the CPU / MMU / TLB functions
    370   1.1     chris 	 */
    371   1.1     chris 	set_cpufuncs();
    372   1.1     chris 
    373  1.36    andvar 	/* canonicalise the boot configuration structure to allow versioning */
    374   1.1     chris 	canonicalise_bootconfig(&bootconfig, raw_bootconf);
    375   1.1     chris 	booted_kernel = bootconfig.kernelname;
    376   1.1     chris 
    377   1.1     chris 	/* if the wscons interface is used, switch off VERBOSE booting :( */
    378   1.1     chris #if NVIDCVIDEO>0
    379   1.1     chris #	undef VERBOSE_INIT_ARM
    380   1.1     chris #endif
    381   1.1     chris 
    382   1.1     chris 	/*
    383   1.1     chris 	 * Initialise the video memory descriptor
    384   1.1     chris 	 *
    385   1.1     chris 	 * Note: all references to the video memory virtual/physical address
    386   1.1     chris 	 * should go via this structure.
    387   1.1     chris 	 */
    388   1.1     chris 
    389   1.1     chris 	/* Hardwire it on the place the bootloader tells us */
    390   1.1     chris 	videomemory.vidm_vbase = bootconfig.display_start;
    391   1.1     chris 	videomemory.vidm_pbase = bootconfig.display_phys;
    392   1.1     chris 	videomemory.vidm_size = bootconfig.display_size;
    393  1.33     skrll 	if (bootconfig.vram[0].pages)
    394   1.1     chris 		videomemory.vidm_type = VIDEOMEM_TYPE_VRAM;
    395  1.33     skrll 	else
    396   1.1     chris 		videomemory.vidm_type = VIDEOMEM_TYPE_DRAM;
    397   1.1     chris 	vidc_base = (int *) VIDC_HW_BASE;
    398   1.1     chris 	iomd_base =         IOMD_HW_BASE;
    399   1.1     chris 
    400   1.1     chris 	/*
    401   1.1     chris 	 * Initialise the physical console
    402   1.1     chris 	 * This is done in main() but for the moment we do it here so that
    403   1.1     chris 	 * we can use printf in initarm() before main() has been called.
    404   1.1     chris 	 * only for `vidcconsole!' ... not wscons
    405   1.1     chris 	 */
    406   1.1     chris #if NVIDCVIDEO == 0
    407   1.1     chris 	consinit();
    408   1.1     chris #endif
    409   1.1     chris 
    410   1.1     chris 	/*
    411   1.1     chris 	 * Initialise the diagnostic serial console
    412   1.1     chris 	 * This allows a means of generating output during initarm().
    413   1.1     chris 	 * Once all the memory map changes are complete we can call consinit()
    414   1.1     chris 	 * and not have to worry about things moving.
    415   1.1     chris 	 */
    416   1.1     chris 	/* fcomcnattach(DC21285_ARMCSR_BASE, comcnspeed, comcnmode); */
    417   1.1     chris 	/* XXX snif .... i am still not able to this */
    418   1.1     chris 
    419   1.1     chris 	/*
    420   1.1     chris 	 * We have the following memory map (derived from EBSA)
    421   1.1     chris 	 *
    422   1.1     chris 	 * virtual address == physical address apart from the areas:
    423   1.1     chris 	 * 0x00000000 -> 0x000fffff which is mapped to
    424   1.1     chris 	 * top 1MB of physical memory
    425  1.37    andvar 	 * 0xf0000000 -> 0xf0ffffff which is mapped to
    426   1.1     chris 	 * physical address 0x01000000 -> 0x01ffffff (DRAM0a, dram[0])
    427   1.1     chris 	 *
    428   1.1     chris 	 * This means that the kernel is mapped suitably for continuing
    429   1.1     chris 	 * execution, all I/O is mapped 1:1 virtual to physical and
    430   1.1     chris 	 * physical memory is accessible.
    431   1.1     chris 	 *
    432   1.1     chris 	 * The initarm() has the responsibility for creating the kernel
    433   1.1     chris 	 * page tables.
    434   1.1     chris 	 * It must also set up various memory pointers that are used
    435  1.33     skrll 	 * by pmap etc.
    436   1.1     chris 	 */
    437   1.1     chris 
    438   1.1     chris 	/* START OF REAL NEW STUFF */
    439   1.1     chris 
    440   1.1     chris 	/* Check to make sure the page size is correct */
    441   1.1     chris 	if (PAGE_SIZE != bootconfig.pagesize)
    442   1.1     chris 		panic2(("Page size is %d bytes instead of %d !! (huh?)\n",
    443   1.1     chris 			   bootconfig.pagesize, PAGE_SIZE));
    444   1.1     chris 
    445   1.1     chris 	/* process arguments */
    446   1.1     chris 	process_kernel_args();
    447   1.1     chris 
    448   1.1     chris 
    449   1.1     chris 	/*
    450   1.1     chris 	 * Now set up the page tables for the kernel ... this part is copied
    451  1.33     skrll 	 * in a (modified?) way from the EBSA machine port....
    452   1.1     chris 	 */
    453   1.1     chris 
    454   1.1     chris #ifdef VERBOSE_INIT_ARM
    455   1.1     chris 	printf("Allocating page tables\n");
    456   1.1     chris #endif
    457   1.1     chris 	/*
    458  1.35    andvar 	 * Set up the variables that define the availability of physical
    459   1.1     chris 	 * memory
    460   1.1     chris 	 */
    461   1.1     chris 	physical_start = 0xffffffff;
    462  1.33     skrll 	physical_end = 0;
    463   1.1     chris 	for (loop = 0, physmem = 0; loop < bootconfig.dramblocks; ++loop) {
    464   1.1     chris 	    	if (bootconfig.dram[loop].address < physical_start)
    465   1.1     chris 			physical_start = bootconfig.dram[loop].address;
    466   1.1     chris 		memoryblock_end = bootconfig.dram[loop].address +
    467   1.1     chris 		    bootconfig.dram[loop].pages * PAGE_SIZE;
    468   1.1     chris 		if (memoryblock_end > physical_end)
    469   1.1     chris 			physical_end = memoryblock_end;
    470   1.1     chris 		physmem += bootconfig.dram[loop].pages;
    471   1.1     chris 	};
    472   1.1     chris 	/* constants for now, but might be changed/configured */
    473   1.1     chris 	dma_range_begin = (paddr_t) physical_start;
    474   1.1     chris 	dma_range_end   = (paddr_t) MIN(physical_end, 512*1024*1024);
    475   1.1     chris 	/* XXX HACK HACK XXX */
    476   1.1     chris 	/* dma_range_end   = 0x18000000; */
    477   1.1     chris 
    478   1.1     chris 	if (physical_start !=  bootconfig.dram[0].address) {
    479   1.1     chris 		int oldblocks = 0;
    480   1.1     chris 
    481  1.33     skrll 		/*
    482   1.1     chris 		 * must be a kinetic, as it's the only thing to shuffle memory
    483   1.1     chris 		 * around
    484   1.1     chris 		 */
    485   1.1     chris 		/* hack hack - throw away the slow dram */
    486   1.1     chris 		for (loop = 0; loop < bootconfig.dramblocks; ++loop) {
    487   1.1     chris 			if (bootconfig.dram[loop].address <
    488   1.1     chris 			    bootconfig.dram[0].address)	{
    489   1.1     chris 				/* non kinetic ram */
    490   1.1     chris 				bootconfig.dram[loop].address = 0;
    491   1.1     chris 				physmem -= bootconfig.dram[loop].pages;
    492   1.1     chris 				bootconfig.drampages -=
    493   1.1     chris 				    bootconfig.dram[loop].pages;
    494   1.1     chris 				bootconfig.dram[loop].pages = 0;
    495   1.1     chris 				oldblocks++;
    496   1.1     chris 			}
    497   1.1     chris 		}
    498   1.1     chris 		physical_start = bootconfig.dram[0].address;
    499  1.33     skrll 		bootconfig.dramblocks -= oldblocks;
    500   1.1     chris 	}
    501  1.33     skrll 
    502   1.1     chris 	physical_freestart = physical_start;
    503   1.1     chris 	free_pages = bootconfig.drampages;
    504   1.1     chris 	physical_freeend = physical_end;
    505  1.33     skrll 
    506   1.1     chris 
    507   1.1     chris 	/*
    508   1.1     chris 	 * AHUM !! set this variable ... it was set up in the old 1st
    509   1.1     chris 	 * stage bootloader
    510   1.1     chris 	 */
    511   1.1     chris 	kerneldatasize = bootconfig.kernsize + bootconfig.MDFsize;
    512   1.1     chris 
    513   1.1     chris 	/* Update the address of the first free page of physical memory */
    514   1.1     chris 	/* XXX Assumption that the kernel and stuff is at the LOWEST physical memory address? XXX */
    515   1.1     chris 	physical_freestart +=
    516   1.1     chris 	    bootconfig.kernsize + bootconfig.MDFsize + bootconfig.scratchsize;
    517   1.1     chris 	free_pages -= (physical_freestart - physical_start) / PAGE_SIZE;
    518  1.33     skrll 
    519   1.1     chris 	/* Define a macro to simplify memory allocation */
    520   1.1     chris #define	valloc_pages(var, np)						\
    521   1.1     chris 	alloc_pages((var).pv_pa, (np));					\
    522   1.1     chris 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    523   1.1     chris 
    524   1.1     chris #define alloc_pages(var, np)						\
    525   1.1     chris 	(var) = physical_freestart;					\
    526   1.1     chris 	physical_freestart += ((np) * PAGE_SIZE);			\
    527   1.1     chris 	free_pages -= (np);						\
    528   1.1     chris 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    529   1.1     chris 
    530   1.1     chris 	loop1 = 0;
    531   1.1     chris 	kernel_l1pt.pv_pa = 0;
    532   1.1     chris 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    533   1.1     chris 		/* Are we 16KB aligned for an L1 ? */
    534   1.1     chris 		if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0
    535   1.1     chris 		    && kernel_l1pt.pv_pa == 0) {
    536   1.1     chris 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    537   1.1     chris 		} else {
    538   1.1     chris 			valloc_pages(kernel_pt_table[loop1],
    539   1.1     chris 					L2_TABLE_SIZE / PAGE_SIZE);
    540   1.1     chris 			++loop1;
    541   1.1     chris 		}
    542   1.1     chris 	}
    543   1.1     chris 
    544   1.1     chris 
    545   1.1     chris #ifdef DIAGNOSTIC
    546   1.1     chris 	/* This should never be able to happen but better confirm that. */
    547   1.1     chris 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    548   1.1     chris 		panic2(("initarm: Failed to align the kernel page "
    549   1.1     chris 		    "directory\n"));
    550   1.1     chris #endif
    551   1.1     chris 
    552   1.1     chris 	/*
    553   1.1     chris 	 * Allocate a page for the system page mapped to V0x00000000
    554   1.1     chris 	 * This page will just contain the system vectors and can be
    555   1.1     chris 	 * shared by all processes.
    556   1.1     chris 	 */
    557   1.1     chris 	alloc_pages(systempage.pv_pa, 1);
    558   1.1     chris 
    559   1.1     chris 	/* Allocate stacks for all modes */
    560   1.1     chris 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    561   1.1     chris 	valloc_pages(abtstack, ABT_STACK_SIZE);
    562   1.1     chris 	valloc_pages(undstack, UND_STACK_SIZE);
    563   1.1     chris 	valloc_pages(kernelstack, UPAGES);
    564   1.1     chris 
    565   1.1     chris #ifdef VERBOSE_INIT_ARM
    566   1.1     chris 	printf("Setting up stacks :\n");
    567   1.1     chris 	printf("IRQ stack: p0x%08lx v0x%08lx\n",
    568  1.33     skrll 	    irqstack.pv_pa, irqstack.pv_va);
    569   1.1     chris 	printf("ABT stack: p0x%08lx v0x%08lx\n",
    570  1.33     skrll 	    abtstack.pv_pa, abtstack.pv_va);
    571   1.1     chris 	printf("UND stack: p0x%08lx v0x%08lx\n",
    572  1.33     skrll 	    undstack.pv_pa, undstack.pv_va);
    573   1.1     chris 	printf("SVC stack: p0x%08lx v0x%08lx\n",
    574  1.33     skrll 	    kernelstack.pv_pa, kernelstack.pv_va);
    575   1.1     chris 	printf("\n");
    576   1.1     chris #endif
    577   1.1     chris 
    578   1.1     chris 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    579   1.1     chris 
    580   1.1     chris #ifdef CPU_SA110
    581   1.1     chris 	/*
    582   1.1     chris 	 * XXX totally stuffed hack to work round problems introduced
    583   1.1     chris 	 * in recent versions of the pmap code. Due to the calls used there
    584   1.1     chris 	 * we cannot allocate virtual memory during bootstrap.
    585   1.1     chris 	 */
    586   1.1     chris 	sa110_cc_base = (KERNEL_BASE + (physical_freestart - physical_start)
    587   1.1     chris 	    + (CPU_SA110_CACHE_CLEAN_SIZE - 1))
    588   1.1     chris 	    & ~(CPU_SA110_CACHE_CLEAN_SIZE - 1);
    589   1.1     chris #endif	/* CPU_SA110 */
    590   1.1     chris 
    591   1.1     chris 	/*
    592   1.1     chris 	 * Ok we have allocated physical pages for the primary kernel
    593   1.1     chris 	 * page tables
    594   1.1     chris 	 */
    595   1.1     chris 
    596   1.1     chris #ifdef VERBOSE_INIT_ARM
    597   1.1     chris 	printf("Creating L1 page table\n");
    598   1.1     chris #endif
    599   1.1     chris 
    600   1.1     chris 	/*
    601   1.1     chris 	 * Now we start construction of the L1 page table
    602   1.1     chris 	 * We start by mapping the L2 page tables into the L1.
    603   1.1     chris 	 * This means that we can replace L1 mappings later on if necessary
    604   1.1     chris 	 */
    605   1.1     chris 	l1pagetable = kernel_l1pt.pv_pa;
    606   1.1     chris 
    607   1.1     chris 	/* Map the L2 pages tables in the L1 page table */
    608   1.1     chris 	pmap_link_l2pt(l1pagetable, 0x00000000,
    609   1.1     chris 	    &kernel_pt_table[KERNEL_PT_SYS]);
    610   1.1     chris 	pmap_link_l2pt(l1pagetable, KERNEL_BASE,
    611   1.1     chris 	    &kernel_pt_table[KERNEL_PT_KERNEL]);
    612   1.1     chris 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
    613   1.1     chris 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    614   1.1     chris 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    615   1.1     chris 	pmap_link_l2pt(l1pagetable, VMEM_VBASE,
    616   1.1     chris 	    &kernel_pt_table[KERNEL_PT_VMEM]);
    617   1.1     chris 
    618   1.1     chris 	/* update the top of the kernel VM */
    619   1.1     chris 	pmap_curmaxkvaddr =
    620   1.1     chris 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    621   1.1     chris 
    622   1.1     chris #ifdef VERBOSE_INIT_ARM
    623   1.1     chris 	printf("Mapping kernel\n");
    624   1.1     chris #endif
    625   1.1     chris 
    626   1.1     chris 	/* Now we fill in the L2 pagetable for the kernel code/data */
    627   1.1     chris 	/* XXX Kernel doesn't have to be on physical_start (!) use bootconfig XXX */
    628   1.1     chris 	/*
    629   1.1     chris 	 * The defines are a workaround for a recent problem that occurred
    630   1.1     chris 	 * with ARM 610 processors and some ARM 710 processors
    631   1.1     chris 	 * Other ARM 710 and StrongARM processors don't have a problem.
    632   1.1     chris 	 */
    633   1.1     chris 	if (N_GETMAGIC(kernexec[0]) == ZMAGIC) {
    634   1.1     chris #if defined(CPU_ARM6) || defined(CPU_ARM7)
    635   1.1     chris 		logical = pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE,
    636   1.1     chris 		    physical_start, kernexec->a_text,
    637   1.1     chris 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    638   1.1     chris #else	/* CPU_ARM6 || CPU_ARM7 */
    639   1.1     chris 		logical = pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE,
    640   1.1     chris 		    physical_start, kernexec->a_text,
    641   1.1     chris 		    VM_PROT_READ, PTE_CACHE);
    642   1.1     chris #endif	/* CPU_ARM6 || CPU_ARM7 */
    643   1.1     chris 		logical += pmap_map_chunk(l1pagetable,
    644   1.1     chris 		    KERNEL_TEXT_BASE + logical, physical_start + logical,
    645   1.1     chris 		    kerneldatasize - kernexec->a_text,
    646   1.1     chris 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    647   1.1     chris 	} else {	/* !ZMAGIC */
    648   1.1     chris 		/*
    649   1.1     chris 		 * Most likely an ELF kernel ...
    650   1.1     chris 		 * XXX no distinction yet between read only and
    651   1.1     chris 		 * read/write area's ...
    652   1.1     chris 		 */
    653   1.1     chris 		pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE,
    654   1.1     chris 		    physical_start, kerneldatasize,
    655   1.1     chris 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    656   1.1     chris 	};
    657   1.1     chris 
    658   1.1     chris 
    659   1.1     chris #ifdef VERBOSE_INIT_ARM
    660   1.1     chris 	printf("Constructing L2 page tables\n");
    661   1.1     chris #endif
    662   1.1     chris 
    663   1.1     chris 	/* Map the stack pages */
    664   1.1     chris 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    665   1.1     chris 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    666   1.1     chris 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    667   1.1     chris 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    668   1.1     chris 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    669   1.1     chris 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    670   1.1     chris 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    671   1.1     chris 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    672   1.1     chris 
    673   1.1     chris 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    674   1.1     chris 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    675   1.1     chris 
    676   1.1     chris 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    677   1.1     chris 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    678   1.1     chris 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    679   1.1     chris 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    680   1.1     chris 	}
    681   1.1     chris 
    682   1.1     chris 	/* Now we fill in the L2 pagetable for the VRAM */
    683   1.1     chris 	/*
    684   1.1     chris 	 * Current architectures mean that the VRAM is always in 1
    685   1.1     chris 	 * continuous bank.  This means that we can just map the 2 meg
    686   1.1     chris 	 * that the VRAM would occupy.  In theory we don't need a page
    687   1.1     chris 	 * table for VRAM, we could section map it but we would need
    688   1.1     chris 	 * the page tables if DRAM was in use.
    689   1.1     chris 	 * XXX please map two adjacent virtual areas to ONE physical
    690   1.1     chris 	 * area
    691   1.1     chris 	 */
    692   1.1     chris 	pmap_map_chunk(l1pagetable, VMEM_VBASE, videomemory.vidm_pbase,
    693   1.1     chris 	    videomemory.vidm_size, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    694   1.1     chris 	pmap_map_chunk(l1pagetable, VMEM_VBASE + videomemory.vidm_size,
    695   1.1     chris 	    videomemory.vidm_pbase, videomemory.vidm_size,
    696   1.1     chris 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    697   1.1     chris 
    698   1.1     chris 	/* Map the vector page. */
    699   1.1     chris 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    700   1.1     chris 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    701   1.1     chris 
    702   1.1     chris 	/* Map the core memory needed before autoconfig */
    703   1.1     chris 	loop = 0;
    704   1.1     chris 	while (l1_sec_table[loop].size) {
    705  1.27      matt 		vsize_t sz;
    706   1.1     chris 
    707   1.1     chris #ifdef VERBOSE_INIT_ARM
    708   1.1     chris 		printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
    709   1.1     chris 			l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
    710   1.1     chris 			l1_sec_table[loop].va);
    711   1.1     chris #endif
    712   1.1     chris 		for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_S_SIZE)
    713   1.1     chris 			pmap_map_section(l1pagetable,
    714   1.1     chris 			    l1_sec_table[loop].va + sz,
    715   1.1     chris 			    l1_sec_table[loop].pa + sz,
    716   1.1     chris 			    l1_sec_table[loop].prot,
    717   1.1     chris 			    l1_sec_table[loop].cache);
    718   1.1     chris 		++loop;
    719   1.1     chris 	}
    720   1.1     chris 
    721   1.1     chris 	/*
    722   1.1     chris 	 * Now we have the real page tables in place so we can switch
    723   1.1     chris 	 * to them.  Once this is done we will be running with the
    724   1.1     chris 	 * REAL kernel page tables.
    725   1.1     chris 	 */
    726   1.1     chris 
    727   1.1     chris #ifdef VERBOSE_INIT_ARM
    728   1.1     chris 	printf("switching domains\n");
    729   1.1     chris #endif
    730   1.1     chris 	/* be a client to all domains */
    731   1.1     chris 	cpu_domains(0x55555555);
    732   1.1     chris 
    733  1.12     chris 	/* Switch tables */
    734  1.12     chris #ifdef VERBOSE_INIT_ARM
    735  1.12     chris 	printf("switching to new L1 page table\n");
    736  1.12     chris #endif
    737  1.25      matt 	cpu_setttb(kernel_l1pt.pv_pa, true);
    738   1.1     chris 
    739   1.1     chris 	/*
    740   1.1     chris 	 * We must now clean the cache again....
    741   1.1     chris 	 * Cleaning may be done by reading new data to displace any
    742  1.19  uebayasi 	 * dirty data in the cache. This will have happened in cpu_setttb()
    743   1.1     chris 	 * but since we are boot strapping the addresses used for the read
    744   1.1     chris 	 * may have just been remapped and thus the cache could be out
    745   1.1     chris 	 * of sync. A re-clean after the switch will cure this.
    746  1.35    andvar 	 * After booting there are no gross relocations of the kernel thus
    747   1.1     chris 	 * this problem will not occur after initarm().
    748   1.1     chris 	 */
    749   1.1     chris 	cpu_idcache_wbinv_all();
    750   1.1     chris 	cpu_tlb_flushID();
    751   1.1     chris 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    752   1.1     chris 
    753   1.1     chris 	/*
    754   1.1     chris 	 * Moved from cpu_startup() as data_abort_handler() references
    755   1.1     chris 	 * this during uvm init
    756   1.1     chris 	 */
    757  1.18     rmind 	uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
    758   1.1     chris 
    759  1.33     skrll 	/*
    760   1.1     chris 	 * if there is support for a serial console ...we should now
    761   1.1     chris 	 * reattach it
    762   1.1     chris 	 */
    763   1.1     chris 	/*      fcomcndetach();*/
    764   1.1     chris 
    765   1.1     chris 	/*
    766   1.1     chris 	 * Reflect videomemory relocation in the videomemory structure
    767   1.1     chris 	 * and reinit console
    768   1.1     chris 	 */
    769   1.1     chris 	if (bootconfig.vram[0].pages == 0) {
    770   1.1     chris 		videomemory.vidm_vbase   = VMEM_VBASE;
    771   1.1     chris 	} else {
    772   1.1     chris 		videomemory.vidm_vbase   = VMEM_VBASE;
    773   1.1     chris 		bootconfig.display_start = VMEM_VBASE;
    774   1.1     chris 	};
    775   1.1     chris 	vidc_base = (int *) VIDC_BASE;
    776   1.1     chris 	iomd_base =         IOMD_BASE;
    777   1.1     chris 
    778   1.1     chris #ifdef VERBOSE_INIT_ARM
    779   1.1     chris 	printf("running on the new L1 page table!\n");
    780   1.1     chris 	printf("done.\n");
    781   1.1     chris #endif
    782   1.1     chris 
    783   1.1     chris 	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
    784   1.1     chris 
    785   1.1     chris #ifdef VERBOSE_INIT_ARM
    786   1.1     chris 	printf("\n");
    787   1.1     chris #endif
    788   1.1     chris 
    789   1.1     chris 	/*
    790   1.1     chris 	 * Pages were allocated during the secondary bootstrap for the
    791   1.1     chris 	 * stacks for different CPU modes.
    792   1.1     chris 	 * We must now set the r13 registers in the different CPU modes to
    793   1.1     chris 	 * point to these stacks.
    794   1.1     chris 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    795   1.1     chris 	 * of the stack memory.
    796   1.1     chris 	 */
    797   1.1     chris #ifdef VERBOSE_INIT_ARM
    798   1.1     chris 	printf("init subsystems: stacks ");
    799   1.1     chris 	console_flush();
    800   1.1     chris #endif
    801   1.1     chris 
    802   1.1     chris 	set_stackptr(PSR_IRQ32_MODE,
    803   1.1     chris 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    804   1.1     chris 	set_stackptr(PSR_ABT32_MODE,
    805   1.1     chris 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    806   1.1     chris 	set_stackptr(PSR_UND32_MODE,
    807   1.1     chris 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    808  1.34     skrll #ifdef VERBOSE_INIT_ARM
    809  1.34     skrll 	printf("kstack V%08lx P%08lx\n", kernelstack.pv_va,
    810  1.34     skrll 	    kernelstack.pv_pa);
    811  1.34     skrll #endif	/* VERBOSE_INIT_ARM */
    812   1.1     chris 
    813   1.1     chris 	/*
    814   1.1     chris 	 * Well we should set a data abort handler.
    815   1.1     chris 	 * Once things get going this will change as we will need a proper
    816   1.1     chris 	 * handler. Until then we will use a handler that just panics but
    817   1.1     chris 	 * tells us why.
    818   1.1     chris 	 * Initialisation of the vectors will just panic on a data abort.
    819   1.2       abs 	 * This just fills in a slightly better one.
    820   1.1     chris 	 */
    821   1.1     chris #ifdef VERBOSE_INIT_ARM
    822   1.1     chris 	printf("vectors ");
    823   1.1     chris #endif
    824   1.1     chris 	data_abort_handler_address = (u_int)data_abort_handler;
    825   1.1     chris 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    826   1.1     chris 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    827   1.1     chris 	console_flush();
    828   1.1     chris 
    829   1.1     chris 
    830   1.1     chris 	/*
    831   1.1     chris 	 * At last !
    832   1.1     chris 	 * We now have the kernel in physical memory from the bottom upwards.
    833   1.1     chris 	 * Kernel page tables are physically above this.
    834   1.1     chris 	 * The kernel is mapped to 0xf0000000
    835  1.33     skrll 	 * The kernel data PTs will handle the mapping of
    836   1.1     chris 	 *   0xf1000000-0xf5ffffff (80 Mb)
    837   1.1     chris 	 * 2Meg of VRAM is mapped to 0xf7000000
    838   1.1     chris 	 * The page tables are mapped to 0xefc00000
    839   1.1     chris 	 * The IOMD is mapped to 0xf6000000
    840   1.1     chris 	 * The VIDC is mapped to 0xf6100000
    841   1.1     chris 	 * The IOMD/VIDC could be pushed up higher but i havent got
    842   1.1     chris 	 * sufficient documentation to do so; the addresses are not
    843   1.1     chris 	 * parametized yet and hard to read... better fix this before;
    844   1.1     chris 	 * its pretty unforgiving.
    845   1.1     chris 	 */
    846   1.1     chris 
    847   1.1     chris 	/* Initialise the undefined instruction handlers */
    848   1.1     chris #ifdef VERBOSE_INIT_ARM
    849   1.1     chris 	printf("undefined ");
    850   1.1     chris #endif
    851   1.1     chris 	undefined_init();
    852   1.1     chris 	console_flush();
    853   1.1     chris 
    854   1.1     chris 	/* Load memory into UVM. */
    855   1.1     chris #ifdef VERBOSE_INIT_ARM
    856   1.1     chris 	printf("page ");
    857   1.1     chris #endif
    858  1.29    cherry 	uvm_md_init();
    859  1.29    cherry 
    860   1.1     chris 	for (loop = 0; loop < bootconfig.dramblocks; loop++) {
    861   1.1     chris 		paddr_t start = (paddr_t)bootconfig.dram[loop].address;
    862   1.1     chris 		paddr_t end = start + (bootconfig.dram[loop].pages * PAGE_SIZE);
    863   1.1     chris 
    864   1.1     chris 		if (start < physical_freestart)
    865   1.1     chris 			start = physical_freestart;
    866   1.1     chris 		if (end > physical_freeend)
    867   1.1     chris 			end = physical_freeend;
    868   1.1     chris 
    869   1.1     chris 		/* XXX Consider DMA range intersection checking. */
    870   1.1     chris 
    871   1.1     chris 		uvm_page_physload(atop(start), atop(end),
    872   1.1     chris 		    atop(start), atop(end), VM_FREELIST_DEFAULT);
    873   1.1     chris 	}
    874   1.1     chris 
    875  1.30     skrll 	/* Boot strap pmap telling it where managed kernel virtual memory is */
    876   1.1     chris #ifdef VERBOSE_INIT_ARM
    877   1.1     chris 	printf("pmap ");
    878   1.1     chris #endif
    879  1.12     chris 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    880   1.1     chris 	console_flush();
    881   1.1     chris 
    882   1.1     chris 	/* Setup the IRQ system */
    883   1.1     chris #ifdef VERBOSE_INIT_ARM
    884   1.1     chris 	printf("irq ");
    885   1.1     chris #endif
    886   1.1     chris 	console_flush();
    887   1.1     chris 	irq_init();
    888   1.1     chris #ifdef VERBOSE_INIT_ARM
    889   1.1     chris 	printf("done.\n\n");
    890   1.1     chris #endif
    891   1.1     chris 
    892   1.1     chris #if NVIDCVIDEO>0
    893   1.1     chris 	consinit();		/* necessary ? */
    894   1.1     chris #endif
    895   1.1     chris 
    896   1.1     chris 	/* Talk to the user */
    897   1.1     chris 	printf("NetBSD/evbarm booting ... \n");
    898   1.1     chris 
    899   1.1     chris 	/* Tell the user if his boot loader is too old */
    900   1.1     chris 	if ((bootconfig.magic < BOOTCONFIG_MAGIC) ||
    901   1.1     chris 	    (bootconfig.version != BOOTCONFIG_VERSION)) {
    902   1.1     chris 		printf("\nDETECTED AN OLD BOOTLOADER. PLEASE UPGRADE IT\n\n");
    903   1.1     chris 		delay(5000000);
    904   1.1     chris 	}
    905   1.1     chris 
    906   1.1     chris 	printf("Kernel loaded from file %s\n", bootconfig.kernelname);
    907   1.1     chris 	printf("Kernel arg string (@%p) %s\n",
    908   1.1     chris 	    bootconfig.args, bootconfig.args);
    909   1.1     chris 	printf("\nBoot configuration structure reports the following "
    910   1.1     chris 	    "memory\n");
    911   1.1     chris 
    912   1.1     chris 	printf(" DRAM block 0a at %08x size %08x "
    913   1.1     chris 	    "DRAM block 0b at %08x size %08x\n\r",
    914   1.1     chris 	    bootconfig.dram[0].address,
    915   1.1     chris 	    bootconfig.dram[0].pages * bootconfig.pagesize,
    916   1.1     chris 	    bootconfig.dram[1].address,
    917   1.1     chris 	    bootconfig.dram[1].pages * bootconfig.pagesize);
    918   1.1     chris 	printf(" DRAM block 1a at %08x size %08x "
    919   1.1     chris 	    "DRAM block 1b at %08x size %08x\n\r",
    920   1.1     chris 	    bootconfig.dram[2].address,
    921   1.1     chris 	    bootconfig.dram[2].pages * bootconfig.pagesize,
    922   1.1     chris 	    bootconfig.dram[3].address,
    923   1.1     chris 	    bootconfig.dram[3].pages * bootconfig.pagesize);
    924   1.1     chris 	printf(" VRAM block 0  at %08x size %08x\n\r",
    925   1.1     chris 	    bootconfig.vram[0].address,
    926   1.1     chris 	    bootconfig.vram[0].pages * bootconfig.pagesize);
    927   1.1     chris 
    928  1.11        ad #if NKSYMS || defined(DDB) || defined(MODULAR)
    929  1.13    martin 	ksyms_addsyms_elf(bootconfig.ksym_end - bootconfig.ksym_start,
    930   1.1     chris 		(void *) bootconfig.ksym_start, (void *) bootconfig.ksym_end);
    931   1.1     chris #endif
    932   1.1     chris 
    933   1.1     chris 
    934   1.1     chris #ifdef DDB
    935   1.1     chris 	db_machine_init();
    936   1.1     chris 	if (boothowto & RB_KDB)
    937   1.1     chris 		Debugger();
    938   1.1     chris #endif	/* DDB */
    939   1.1     chris 
    940   1.1     chris 	/* We return the new stack pointer address */
    941  1.32     skrll 	return kernelstack.pv_va + USPACE_SVC_STACK_TOP;
    942   1.1     chris }
    943   1.1     chris 
    944   1.1     chris 
    945   1.1     chris static void
    946   1.1     chris process_kernel_args(void)
    947   1.1     chris {
    948   1.1     chris 	char *args;
    949   1.1     chris 
    950   1.1     chris 	/* Ok now we will check the arguments for interesting parameters. */
    951   1.1     chris 	args = bootconfig.args;
    952   1.1     chris 	boothowto = 0;
    953   1.1     chris 
    954   1.1     chris 	/* Only arguments itself are passed from the new bootloader */
    955   1.1     chris 	while (*args == ' ')
    956   1.1     chris 		++args;
    957   1.1     chris 
    958   1.1     chris 	boot_args = args;
    959   1.1     chris 	parse_mi_bootargs(boot_args);
    960   1.1     chris 	parse_rpc_bootargs(boot_args);
    961   1.1     chris }
    962   1.1     chris 
    963   1.1     chris 
    964   1.1     chris void
    965   1.1     chris parse_rpc_bootargs(char *args)
    966   1.1     chris {
    967   1.1     chris 	int integer;
    968   1.1     chris 
    969   1.1     chris 	if (get_bootconf_option(args, "videodram", BOOTOPT_TYPE_INT,
    970   1.1     chris 	    &integer)) {
    971   1.1     chris 		videodram_size = integer;
    972   1.1     chris 		/* Round to 4K page */
    973   1.1     chris 		videodram_size *= 1024;
    974   1.1     chris 		videodram_size = round_page(videodram_size);
    975   1.1     chris 		if (videodram_size > 1024*1024)
    976   1.1     chris 			videodram_size = 1024*1024;
    977   1.1     chris 	}
    978   1.1     chris }
    979   1.1     chris /* End of machdep.c */
    980