Home | History | Annotate | Line # | Download | only in iq80310
iq80310_machdep.c revision 1.1.4.1
      1  1.1.4.1  thorpej /*	$NetBSD: iq80310_machdep.c,v 1.1.4.1 2001/11/12 21:16:53 thorpej Exp $	*/
      2      1.1     matt 
      3      1.1     matt /*
      4      1.1     matt  * Copyright (c) 1997,1998 Mark Brinicombe.
      5      1.1     matt  * Copyright (c) 1997,1998 Causality Limited.
      6      1.1     matt  * All rights reserved.
      7      1.1     matt  *
      8      1.1     matt  * Redistribution and use in source and binary forms, with or without
      9      1.1     matt  * modification, are permitted provided that the following conditions
     10      1.1     matt  * are met:
     11      1.1     matt  * 1. Redistributions of source code must retain the above copyright
     12      1.1     matt  *    notice, this list of conditions and the following disclaimer.
     13      1.1     matt  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1     matt  *    notice, this list of conditions and the following disclaimer in the
     15      1.1     matt  *    documentation and/or other materials provided with the distribution.
     16      1.1     matt  * 3. All advertising materials mentioning features or use of this software
     17      1.1     matt  *    must display the following acknowledgement:
     18      1.1     matt  *	This product includes software developed by Mark Brinicombe
     19      1.1     matt  *	for the NetBSD Project.
     20      1.1     matt  * 4. The name of the company nor the name of the author may be used to
     21      1.1     matt  *    endorse or promote products derived from this software without specific
     22      1.1     matt  *    prior written permission.
     23      1.1     matt  *
     24      1.1     matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     25      1.1     matt  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     26      1.1     matt  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27      1.1     matt  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     28      1.1     matt  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     29      1.1     matt  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     30      1.1     matt  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31      1.1     matt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32      1.1     matt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33      1.1     matt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34      1.1     matt  * SUCH DAMAGE.
     35      1.1     matt  *
     36  1.1.4.1  thorpej  * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
     37  1.1.4.1  thorpej  * boards using RedBoot firmware.
     38      1.1     matt  */
     39      1.1     matt 
     40      1.1     matt #include "opt_ddb.h"
     41      1.1     matt #include "opt_pmap_debug.h"
     42      1.1     matt 
     43      1.1     matt #include <sys/param.h>
     44      1.1     matt #include <sys/device.h>
     45      1.1     matt #include <sys/systm.h>
     46      1.1     matt #include <sys/kernel.h>
     47      1.1     matt #include <sys/exec.h>
     48      1.1     matt #include <sys/proc.h>
     49      1.1     matt #include <sys/msgbuf.h>
     50      1.1     matt #include <sys/reboot.h>
     51      1.1     matt #include <sys/termios.h>
     52      1.1     matt 
     53      1.1     matt #include <dev/cons.h>
     54      1.1     matt 
     55      1.1     matt #include <machine/db_machdep.h>
     56      1.1     matt #include <ddb/db_sym.h>
     57      1.1     matt #include <ddb/db_extern.h>
     58      1.1     matt 
     59      1.1     matt #include <machine/bootconfig.h>
     60      1.1     matt #include <machine/bus.h>
     61      1.1     matt #include <machine/cpu.h>
     62      1.1     matt #include <machine/frame.h>
     63      1.1     matt #include <machine/irqhandler.h>
     64      1.1     matt #include <machine/pte.h>
     65      1.1     matt #include <machine/undefined.h>
     66      1.1     matt 
     67      1.1     matt #include <arm/xscale/i80312reg.h>
     68      1.1     matt #include <arm/xscale/i80312var.h>
     69      1.1     matt 
     70  1.1.4.1  thorpej #include <dev/pci/ppbreg.h>
     71      1.1     matt 
     72  1.1.4.1  thorpej #include <evbarm/iq80310/iq80310reg.h>
     73  1.1.4.1  thorpej #include <evbarm/iq80310/iq80310var.h>
     74  1.1.4.1  thorpej #include <evbarm/iq80310/obiovar.h>
     75  1.1.4.1  thorpej 
     76  1.1.4.1  thorpej #include "opt_ipkdb.h"
     77      1.1     matt 
     78      1.1     matt /*
     79      1.1     matt  * Address to call from cpu_reset() to reset the machine.
     80      1.1     matt  * This is machine architecture dependant as it varies depending
     81      1.1     matt  * on where the ROM appears when you turn the MMU off.
     82      1.1     matt  */
     83      1.1     matt 
     84  1.1.4.1  thorpej u_int cpu_reset_address = 0;
     85      1.1     matt 
     86      1.1     matt /* Define various stack sizes in pages */
     87      1.1     matt #define IRQ_STACK_SIZE	1
     88      1.1     matt #define ABT_STACK_SIZE	1
     89      1.1     matt #ifdef IPKDB
     90      1.1     matt #define UND_STACK_SIZE	2
     91      1.1     matt #else
     92      1.1     matt #define UND_STACK_SIZE	1
     93      1.1     matt #endif
     94      1.1     matt 
     95      1.1     matt BootConfig bootconfig;		/* Boot config storage */
     96      1.1     matt static char bootargs[MAX_BOOT_STRING + 1];
     97      1.1     matt char *boot_args = NULL;
     98      1.1     matt char *boot_file = NULL;
     99      1.1     matt 
    100      1.1     matt vm_offset_t physical_start;
    101      1.1     matt vm_offset_t physical_freestart;
    102      1.1     matt vm_offset_t physical_freeend;
    103      1.1     matt vm_offset_t physical_end;
    104      1.1     matt u_int free_pages;
    105      1.1     matt vm_offset_t pagetables_start;
    106      1.1     matt int physmem = 0;
    107      1.1     matt 
    108      1.1     matt /*int debug_flags;*/
    109      1.1     matt #ifndef PMAP_STATIC_L1S
    110      1.1     matt int max_processes = 64;			/* Default number */
    111      1.1     matt #endif	/* !PMAP_STATIC_L1S */
    112      1.1     matt 
    113      1.1     matt /* Physical and virtual addresses for some global pages */
    114      1.1     matt pv_addr_t systempage;
    115      1.1     matt pv_addr_t irqstack;
    116      1.1     matt pv_addr_t undstack;
    117      1.1     matt pv_addr_t abtstack;
    118      1.1     matt pv_addr_t kernelstack;
    119  1.1.4.1  thorpej pv_addr_t minidataclean;
    120      1.1     matt 
    121      1.1     matt vm_offset_t msgbufphys;
    122      1.1     matt 
    123      1.1     matt extern u_int data_abort_handler_address;
    124      1.1     matt extern u_int prefetch_abort_handler_address;
    125      1.1     matt extern u_int undefined_handler_address;
    126      1.1     matt 
    127      1.1     matt #ifdef PMAP_DEBUG
    128      1.1     matt extern int pmap_debug_level;
    129      1.1     matt #endif
    130      1.1     matt 
    131      1.1     matt #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    132      1.1     matt #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    133  1.1.4.1  thorpej #define	KERNEL_PT_IOPXS		2	/* Page table for mapping i80312 */
    134  1.1.4.1  thorpej #define KERNEL_PT_VMDATA	3	/* Page tables for mapping kernel VM */
    135      1.1     matt #define	KERNEL_PT_VMDATA_NUM	(KERNEL_VM_SIZE >> (PDSHIFT + 2))
    136      1.1     matt #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    137      1.1     matt 
    138      1.1     matt pt_entry_t kernel_pt_table[NUM_KERNEL_PTS];
    139      1.1     matt 
    140      1.1     matt struct user *proc0paddr;
    141      1.1     matt 
    142      1.1     matt /* Prototypes */
    143      1.1     matt 
    144  1.1.4.1  thorpej void	consinit(void);
    145      1.1     matt 
    146  1.1.4.1  thorpej void	map_section(vm_offset_t pt, vm_offset_t va, vm_offset_t pa,
    147  1.1.4.1  thorpej 	    int cacheable);
    148  1.1.4.1  thorpej void	map_pagetable(vm_offset_t pt, vm_offset_t va, vm_offset_t pa);
    149  1.1.4.1  thorpej void	map_entry(vm_offset_t pt, vm_offset_t va, vm_offset_t pa);
    150  1.1.4.1  thorpej void	map_entry_nc(vm_offset_t pt, vm_offset_t va, vm_offset_t pa);
    151  1.1.4.1  thorpej void	map_entry_ro(vm_offset_t pt, vm_offset_t va, vm_offset_t pa);
    152  1.1.4.1  thorpej vm_size_t map_chunk(vm_offset_t pd, vm_offset_t pt, vm_offset_t va,
    153  1.1.4.1  thorpej 	    vm_offset_t pa, vm_size_t size, u_int acc, u_int flg);
    154  1.1.4.1  thorpej 
    155  1.1.4.1  thorpej void	process_kernel_args(char *);
    156  1.1.4.1  thorpej void	data_abort_handler(trapframe_t *frame);
    157  1.1.4.1  thorpej void	prefetch_abort_handler(trapframe_t *frame);
    158  1.1.4.1  thorpej void	undefinedinstruction_bounce(trapframe_t *frame);
    159  1.1.4.1  thorpej 
    160  1.1.4.1  thorpej extern void parse_mi_bootargs(char *args);
    161  1.1.4.1  thorpej extern void dumpsys(void);
    162      1.1     matt 
    163      1.1     matt #include "com.h"
    164  1.1.4.1  thorpej #if NCOM > 0
    165      1.1     matt #include <dev/ic/comreg.h>
    166      1.1     matt #include <dev/ic/comvar.h>
    167      1.1     matt #endif
    168      1.1     matt 
    169      1.1     matt #ifndef CONSPEED
    170  1.1.4.1  thorpej #define CONSPEED B115200	/* What RedBoot uses */
    171      1.1     matt #endif
    172      1.1     matt #ifndef CONMODE
    173      1.1     matt #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    174      1.1     matt #endif
    175      1.1     matt 
    176      1.1     matt int comcnspeed = CONSPEED;
    177      1.1     matt int comcnmode = CONMODE;
    178      1.1     matt 
    179      1.1     matt /*
    180      1.1     matt  * void cpu_reboot(int howto, char *bootstr)
    181      1.1     matt  *
    182      1.1     matt  * Reboots the system
    183      1.1     matt  *
    184      1.1     matt  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    185      1.1     matt  * then reset the CPU.
    186      1.1     matt  */
    187      1.1     matt void
    188      1.1     matt cpu_reboot(int howto, char *bootstr)
    189      1.1     matt {
    190      1.1     matt #ifdef DIAGNOSTIC
    191      1.1     matt 	/* info */
    192      1.1     matt 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    193      1.1     matt #endif
    194      1.1     matt 
    195      1.1     matt 	/*
    196      1.1     matt 	 * If we are still cold then hit the air brakes
    197      1.1     matt 	 * and crash to earth fast
    198      1.1     matt 	 */
    199      1.1     matt 	if (cold) {
    200      1.1     matt 		doshutdownhooks();
    201      1.1     matt 		printf("The operating system has halted.\n");
    202      1.1     matt 		printf("Please press any key to reboot.\n\n");
    203      1.1     matt 		cngetc();
    204      1.1     matt 		printf("rebooting...\n");
    205      1.1     matt 		cpu_reset();
    206      1.1     matt 		/*NOTREACHED*/
    207      1.1     matt 	}
    208      1.1     matt 
    209      1.1     matt 	/* Disable console buffering */
    210      1.1     matt /*	cnpollc(1);*/
    211      1.1     matt 
    212      1.1     matt 	/*
    213      1.1     matt 	 * If RB_NOSYNC was not specified sync the discs.
    214  1.1.4.1  thorpej 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    215  1.1.4.1  thorpej 	 * unmount.  It looks like syslogd is getting woken up only to find
    216  1.1.4.1  thorpej 	 * that it cannot page part of the binary in as the filesystem has
    217  1.1.4.1  thorpej 	 * been unmounted.
    218      1.1     matt 	 */
    219      1.1     matt 	if (!(howto & RB_NOSYNC))
    220      1.1     matt 		bootsync();
    221      1.1     matt 
    222      1.1     matt 	/* Say NO to interrupts */
    223      1.1     matt 	splhigh();
    224      1.1     matt 
    225      1.1     matt 	/* Do a dump if requested. */
    226      1.1     matt 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    227      1.1     matt 		dumpsys();
    228      1.1     matt 
    229      1.1     matt 	/* Run any shutdown hooks */
    230      1.1     matt 	doshutdownhooks();
    231      1.1     matt 
    232      1.1     matt 	/* Make sure IRQ's are disabled */
    233      1.1     matt 	IRQdisable;
    234      1.1     matt 
    235      1.1     matt 	if (howto & RB_HALT) {
    236      1.1     matt 		printf("The operating system has halted.\n");
    237      1.1     matt 		printf("Please press any key to reboot.\n\n");
    238      1.1     matt 		cngetc();
    239      1.1     matt 	}
    240      1.1     matt 
    241      1.1     matt 	printf("rebooting...\n");
    242      1.1     matt 	cpu_reset();
    243      1.1     matt 	/*NOTREACHED*/
    244      1.1     matt }
    245      1.1     matt 
    246      1.1     matt /*
    247      1.1     matt  * Mapping table for core kernel memory. This memory is mapped at init
    248      1.1     matt  * time with section mappings.
    249      1.1     matt  */
    250      1.1     matt struct l1_sec_map {
    251      1.1     matt 	vaddr_t	va;
    252      1.1     matt 	vaddr_t	pa;
    253      1.1     matt 	vsize_t	size;
    254      1.1     matt 	int flags;
    255      1.1     matt } l1_sec_table[] = {
    256  1.1.4.1  thorpej     /*
    257  1.1.4.1  thorpej      * Map the on-board devices VA == PA so that we can access them
    258  1.1.4.1  thorpej      * with the MMU on or off.
    259  1.1.4.1  thorpej      */
    260  1.1.4.1  thorpej     {
    261  1.1.4.1  thorpej 	IQ80310_OBIO_BASE,
    262  1.1.4.1  thorpej 	IQ80310_OBIO_BASE,
    263  1.1.4.1  thorpej 	IQ80310_OBIO_SIZE,
    264  1.1.4.1  thorpej 	0,
    265  1.1.4.1  thorpej     },
    266  1.1.4.1  thorpej 
    267      1.1     matt     {
    268      1.1     matt 	0,
    269      1.1     matt 	0,
    270      1.1     matt 	0,
    271      1.1     matt 	0,
    272      1.1     matt     }
    273      1.1     matt };
    274      1.1     matt 
    275      1.1     matt /*
    276  1.1.4.1  thorpej  * u_int initarm(...)
    277      1.1     matt  *
    278      1.1     matt  * Initial entry point on startup. This gets called before main() is
    279      1.1     matt  * entered.
    280      1.1     matt  * It should be responsible for setting up everything that must be
    281      1.1     matt  * in place when main is called.
    282      1.1     matt  * This includes
    283      1.1     matt  *   Taking a copy of the boot configuration structure.
    284      1.1     matt  *   Initialising the physical console so characters can be printed.
    285      1.1     matt  *   Setting up page tables for the kernel
    286      1.1     matt  *   Relocating the kernel to the bottom of physical memory
    287      1.1     matt  */
    288      1.1     matt u_int
    289  1.1.4.1  thorpej initarm(void)
    290      1.1     matt {
    291  1.1.4.1  thorpej 	extern vaddr_t xscale_cache_clean_addr, xscale_minidata_clean_addr;
    292  1.1.4.1  thorpej 	extern vsize_t xscale_minidata_clean_size;
    293      1.1     matt 	int loop;
    294      1.1     matt 	int loop1;
    295      1.1     matt 	u_int l1pagetable;
    296      1.1     matt 	u_int l2pagetable;
    297      1.1     matt 	extern char page0[], page0_end[];
    298      1.1     matt 	pv_addr_t kernel_l1pt;
    299      1.1     matt 	pv_addr_t kernel_ptpt;
    300  1.1.4.1  thorpej 	paddr_t memstart;
    301  1.1.4.1  thorpej 	psize_t memsize;
    302  1.1.4.1  thorpej 
    303  1.1.4.1  thorpej 	/*
    304  1.1.4.1  thorpej 	 * Clear out the 7-segment display.  Whee, the first visual
    305  1.1.4.1  thorpej 	 * indication that we're running kernel code.
    306  1.1.4.1  thorpej 	 */
    307  1.1.4.1  thorpej 	iq80310_7seg(' ', ' ');
    308      1.1     matt 
    309      1.1     matt 	/*
    310      1.1     matt 	 * Heads up ... Setup the CPU / MMU / TLB functions
    311      1.1     matt 	 */
    312      1.1     matt 	if (set_cpufuncs())
    313      1.1     matt 		panic("cpu not recognized!");
    314      1.1     matt 
    315  1.1.4.1  thorpej 	/* Calibrate the delay loop. */
    316  1.1.4.1  thorpej 	iq80310_calibrate_delay();
    317      1.1     matt 
    318      1.1     matt 	/*
    319  1.1.4.1  thorpej 	 * Since we map the on-board devices VA==PA, and the kernel
    320  1.1.4.1  thorpej 	 * is running VA==PA, it's possible for us to initialize
    321  1.1.4.1  thorpej 	 * the console now.
    322      1.1     matt 	 */
    323  1.1.4.1  thorpej 	consinit();
    324      1.1     matt 
    325      1.1     matt 	/* Talk to the user */
    326  1.1.4.1  thorpej 	printf("\nNetBSD/evbarm (IQ80310) booting ...\n");
    327      1.1     matt 
    328      1.1     matt 	/*
    329  1.1.4.1  thorpej 	 * Reset the secondary PCI bus.  RedBoot doesn't stop devices
    330  1.1.4.1  thorpej 	 * on the PCI bus before handing us control, so we have to
    331  1.1.4.1  thorpej 	 * do this.
    332  1.1.4.1  thorpej 	 *
    333  1.1.4.1  thorpej 	 * XXX This is arguably a bug in RedBoot, and doing this reset
    334  1.1.4.1  thorpej 	 * XXX could be problematic in the future if we encounter an
    335  1.1.4.1  thorpej 	 * XXX application where the PPB in the i80312 is used as a
    336  1.1.4.1  thorpej 	 * XXX PPB.
    337  1.1.4.1  thorpej 	 */
    338  1.1.4.1  thorpej 	{
    339  1.1.4.1  thorpej 		uint32_t reg;
    340  1.1.4.1  thorpej 
    341  1.1.4.1  thorpej 		printf("Resetting secondary PCI bus...\n");
    342  1.1.4.1  thorpej 		reg = bus_space_read_4(&obio_bs_tag,
    343  1.1.4.1  thorpej 		    I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL);
    344  1.1.4.1  thorpej 		bus_space_write_4(&obio_bs_tag,
    345  1.1.4.1  thorpej 		    I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL,
    346  1.1.4.1  thorpej 		    reg | PPB_BC_SECONDARY_RESET);
    347  1.1.4.1  thorpej 		delay(10 * 1000);	/* 10ms enough? */
    348  1.1.4.1  thorpej 		bus_space_write_4(&obio_bs_tag,
    349  1.1.4.1  thorpej 		    I80312_PMMR_BASE + I80312_PPB_BASE, PPB_REG_BRIDGECONTROL,
    350  1.1.4.1  thorpej 		    reg);
    351  1.1.4.1  thorpej 	}
    352  1.1.4.1  thorpej 
    353  1.1.4.1  thorpej 	/*
    354  1.1.4.1  thorpej 	 * Okay, RedBoot has provided us with the following memory map:
    355  1.1.4.1  thorpej 	 *
    356  1.1.4.1  thorpej 	 * Physical Address Range     Description
    357  1.1.4.1  thorpej 	 * -----------------------    ----------------------------------
    358  1.1.4.1  thorpej 	 * 0x00000000 - 0x00000fff    flash Memory
    359  1.1.4.1  thorpej 	 * 0x00001000 - 0x00001fff    80312 Internal Registers
    360  1.1.4.1  thorpej 	 * 0x00002000 - 0x007fffff    flash Memory
    361  1.1.4.1  thorpej 	 * 0x00800000 - 0x7fffffff    PCI ATU Outbound Direct Window
    362  1.1.4.1  thorpej 	 * 0x80000000 - 0x83ffffff    Primary PCI 32-bit Memory
    363  1.1.4.1  thorpej 	 * 0x84000000 - 0x87ffffff    Primary PCI 64-bit Memory
    364  1.1.4.1  thorpej 	 * 0x88000000 - 0x8bffffff    Secondary PCI 32-bit Memory
    365  1.1.4.1  thorpej 	 * 0x8c000000 - 0x8fffffff    Secondary PCI 64-bit Memory
    366  1.1.4.1  thorpej 	 * 0x90000000 - 0x9000ffff    Primary PCI IO Space
    367  1.1.4.1  thorpej 	 * 0x90010000 - 0x9001ffff    Secondary PCI IO Space
    368  1.1.4.1  thorpej 	 * 0x90020000 - 0x9fffffff    Unused
    369  1.1.4.1  thorpej 	 * 0xa0000000 - 0xbfffffff    SDRAM
    370  1.1.4.1  thorpej 	 * 0xc0000000 - 0xefffffff    Unused
    371  1.1.4.1  thorpej 	 * 0xf0000000 - 0xffffffff    80200 Internal Registers
    372  1.1.4.1  thorpej 	 *
    373      1.1     matt 	 *
    374  1.1.4.1  thorpej 	 * Virtual Address Range    C B  Description
    375  1.1.4.1  thorpej 	 * -----------------------  - -  ----------------------------------
    376  1.1.4.1  thorpej 	 * 0x00000000 - 0x00000fff  Y Y  SDRAM
    377  1.1.4.1  thorpej 	 * 0x00001000 - 0x00001fff  N N  80312 Internal Registers
    378  1.1.4.1  thorpej 	 * 0x00002000 - 0x007fffff  Y N  flash Memory
    379  1.1.4.1  thorpej 	 * 0x00800000 - 0x7fffffff  N N  PCI ATU Outbound Direct Window
    380  1.1.4.1  thorpej 	 * 0x80000000 - 0x83ffffff  N N  Primary PCI 32-bit Memory
    381  1.1.4.1  thorpej 	 * 0x84000000 - 0x87ffffff  N N  Primary PCI 64-bit Memory
    382  1.1.4.1  thorpej 	 * 0x88000000 - 0x8bffffff  N N  Secondary PCI 32-bit Memory
    383  1.1.4.1  thorpej 	 * 0x8c000000 - 0x8fffffff  N N  Secondary PCI 64-bit Memory
    384  1.1.4.1  thorpej 	 * 0x90000000 - 0x9000ffff  N N  Primary PCI IO Space
    385  1.1.4.1  thorpej 	 * 0x90010000 - 0x9001ffff  N N  Secondary PCI IO Space
    386  1.1.4.1  thorpej 	 * 0xa0000000 - 0xa0000fff  Y N  flash
    387  1.1.4.1  thorpej 	 * 0xa0001000 - 0xbfffffff  Y Y  SDRAM
    388  1.1.4.1  thorpej 	 * 0xc0000000 - 0xcfffffff  Y Y  Cache Flush Region
    389  1.1.4.1  thorpej 	 * 0xf0000000 - 0xffffffff  N N  80200 Internal Registers
    390      1.1     matt 	 *
    391  1.1.4.1  thorpej 	 * The first level page table is at 0xa0004000.  There are also
    392  1.1.4.1  thorpej 	 * 2 second-level tables at 0xa0008000 and 0xa0008400.
    393      1.1     matt 	 *
    394  1.1.4.1  thorpej 	 * This corresponds roughly to the physical memory map, i.e.
    395  1.1.4.1  thorpej 	 * we are quite nearly running VA==PA.
    396      1.1     matt 	 */
    397      1.1     matt 
    398      1.1     matt 	/*
    399      1.1     matt 	 * Examine the boot args string for options we need to know about
    400      1.1     matt 	 * now.
    401      1.1     matt 	 */
    402      1.1     matt #if 0
    403      1.1     matt 	process_kernel_args((char *)nwbootinfo.bt_args);
    404      1.1     matt #endif
    405      1.1     matt 
    406  1.1.4.1  thorpej 	/*
    407  1.1.4.1  thorpej 	 * Fetch the SDRAM start/size from the i80312 SDRAM configration
    408  1.1.4.1  thorpej 	 * registers.
    409  1.1.4.1  thorpej 	 */
    410  1.1.4.1  thorpej 	i80312_sdram_bounds(&obio_bs_tag, I80312_PMMR_BASE + I80312_MEM_BASE,
    411  1.1.4.1  thorpej 	    &memstart, &memsize);
    412  1.1.4.1  thorpej 
    413      1.1     matt 	printf("initarm: Configuring system ...\n");
    414      1.1     matt 
    415  1.1.4.1  thorpej 	/* Fake bootconfig structure for the benefit of pmap.c */
    416  1.1.4.1  thorpej 	/* XXX must make the memory description h/w independant */
    417  1.1.4.1  thorpej 	bootconfig.dramblocks = 1;
    418  1.1.4.1  thorpej 	bootconfig.dram[0].address = memstart;
    419  1.1.4.1  thorpej 	bootconfig.dram[0].pages = memsize / NBPG;
    420  1.1.4.1  thorpej 
    421      1.1     matt 	/*
    422      1.1     matt 	 * Set up the variables that define the availablilty of
    423  1.1.4.1  thorpej 	 * physical memory.  For now, we're going to set
    424  1.1.4.1  thorpej 	 * physical_freestart to 0xa0200000 (where the kernel
    425  1.1.4.1  thorpej 	 * was loaded), and allocate the memory we need downwards.
    426  1.1.4.1  thorpej 	 * If we get too close to the page tables that RedBoot
    427  1.1.4.1  thorpej 	 * set up, we will panic.  We will update physical_freestart
    428  1.1.4.1  thorpej 	 * and physical_freeend later to reflect what pmap_bootstrap()
    429  1.1.4.1  thorpej 	 * wants to see.
    430  1.1.4.1  thorpej 	 *
    431  1.1.4.1  thorpej 	 * XXX pmap_bootstrap() needs an enema.
    432      1.1     matt 	 */
    433  1.1.4.1  thorpej 	physical_start = bootconfig.dram[0].address;
    434  1.1.4.1  thorpej 	physical_end = physical_start + (bootconfig.dram[0].pages * NBPG);
    435  1.1.4.1  thorpej 
    436  1.1.4.1  thorpej 	physical_freestart = 0xa0009000UL;
    437  1.1.4.1  thorpej 	physical_freeend = 0xa0200000UL;
    438  1.1.4.1  thorpej 
    439      1.1     matt 	physmem = (physical_end - physical_start) / NBPG;
    440      1.1     matt 
    441      1.1     matt 	/* Tell the user about the memory */
    442      1.1     matt 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    443      1.1     matt 	    physical_start, physical_end - 1);
    444      1.1     matt 
    445      1.1     matt 	/*
    446  1.1.4.1  thorpej 	 * Okay, the kernel starts 2MB in from the bottom of physical
    447  1.1.4.1  thorpej 	 * memory.  We are going to allocate our bootstrap pages downwards
    448  1.1.4.1  thorpej 	 * from there.
    449  1.1.4.1  thorpej 	 *
    450  1.1.4.1  thorpej 	 * We need to allocate some fixed page tables to get the kernel
    451  1.1.4.1  thorpej 	 * going.  We allocate one page directory and a number of page
    452  1.1.4.1  thorpej 	 * tables and store the physical addresses in the kernel_pt_table
    453  1.1.4.1  thorpej 	 * array.
    454      1.1     matt 	 *
    455  1.1.4.1  thorpej 	 * The kernel page directory must be on a 16K boundary.  The page
    456  1.1.4.1  thorpej 	 * tables must be on 4K bounaries.  What we do is allocate the
    457  1.1.4.1  thorpej 	 * page directory on the first 16K boundary that we encounter, and
    458  1.1.4.1  thorpej 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    459  1.1.4.1  thorpej 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    460  1.1.4.1  thorpej 	 * least one 16K aligned region.
    461      1.1     matt 	 */
    462      1.1     matt 
    463      1.1     matt #ifdef VERBOSE_INIT_ARM
    464      1.1     matt 	printf("Allocating page tables\n");
    465      1.1     matt #endif
    466      1.1     matt 
    467  1.1.4.1  thorpej 	free_pages = (physical_freeend - physical_freestart) / NBPG;
    468      1.1     matt 
    469      1.1     matt #ifdef VERBOSE_INIT_ARM
    470  1.1.4.1  thorpej 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    471      1.1     matt 	       physical_freestart, free_pages, free_pages);
    472      1.1     matt #endif
    473      1.1     matt 
    474      1.1     matt 	/* Define a macro to simplify memory allocation */
    475  1.1.4.1  thorpej #define	valloc_pages(var, np)				\
    476  1.1.4.1  thorpej 	alloc_pages((var).pv_pa, (np));			\
    477      1.1     matt 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    478      1.1     matt 
    479  1.1.4.1  thorpej #define alloc_pages(var, np)				\
    480  1.1.4.1  thorpej 	physical_freeend -= ((np) * NBPG);		\
    481  1.1.4.1  thorpej 	if (physical_freeend < physical_freestart)	\
    482  1.1.4.1  thorpej 		panic("initarm: out of memory");	\
    483  1.1.4.1  thorpej 	(var) = physical_freeend;			\
    484  1.1.4.1  thorpej 	free_pages -= (np);				\
    485      1.1     matt 	memset((char *)(var), 0, ((np) * NBPG));
    486      1.1     matt 
    487      1.1     matt 	loop1 = 0;
    488      1.1     matt 	kernel_l1pt.pv_pa = 0;
    489      1.1     matt 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    490      1.1     matt 		/* Are we 16KB aligned for an L1 ? */
    491  1.1.4.1  thorpej 		if (((physical_freeend - PD_SIZE) & (PD_SIZE - 1)) == 0
    492      1.1     matt 		    && kernel_l1pt.pv_pa == 0) {
    493      1.1     matt 			valloc_pages(kernel_l1pt, PD_SIZE / NBPG);
    494      1.1     matt 		} else {
    495      1.1     matt 			alloc_pages(kernel_pt_table[loop1], PT_SIZE / NBPG);
    496      1.1     matt 			++loop1;
    497      1.1     matt 		}
    498      1.1     matt 	}
    499      1.1     matt 
    500      1.1     matt 	/* This should never be able to happen but better confirm that. */
    501      1.1     matt 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (PD_SIZE-1)) != 0)
    502      1.1     matt 		panic("initarm: Failed to align the kernel page directory\n");
    503      1.1     matt 
    504      1.1     matt 	/*
    505      1.1     matt 	 * Allocate a page for the system page mapped to V0x00000000
    506      1.1     matt 	 * This page will just contain the system vectors and can be
    507      1.1     matt 	 * shared by all processes.
    508      1.1     matt 	 */
    509      1.1     matt 	alloc_pages(systempage.pv_pa, 1);
    510      1.1     matt 
    511  1.1.4.1  thorpej 	/* Allocate a page for the page table to map kernel page tables. */
    512      1.1     matt 	valloc_pages(kernel_ptpt, PT_SIZE / NBPG);
    513      1.1     matt 
    514      1.1     matt 	/* Allocate stacks for all modes */
    515      1.1     matt 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    516      1.1     matt 	valloc_pages(abtstack, ABT_STACK_SIZE);
    517      1.1     matt 	valloc_pages(undstack, UND_STACK_SIZE);
    518      1.1     matt 	valloc_pages(kernelstack, UPAGES);
    519      1.1     matt 
    520  1.1.4.1  thorpej 	/* Allocate enough pages for cleaning the Mini-Data cache. */
    521  1.1.4.1  thorpej 	KASSERT(xscale_minidata_clean_size <= NBPG);
    522  1.1.4.1  thorpej 	valloc_pages(minidataclean, 1);
    523  1.1.4.1  thorpej 	xscale_minidata_clean_addr = minidataclean.pv_va;
    524  1.1.4.1  thorpej 
    525      1.1     matt #ifdef VERBOSE_INIT_ARM
    526  1.1.4.1  thorpej 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    527  1.1.4.1  thorpej 	    irqstack.pv_va);
    528  1.1.4.1  thorpej 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    529  1.1.4.1  thorpej 	    abtstack.pv_va);
    530  1.1.4.1  thorpej 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    531  1.1.4.1  thorpej 	    undstack.pv_va);
    532  1.1.4.1  thorpej 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    533  1.1.4.1  thorpej 	    kernelstack.pv_va);
    534      1.1     matt #endif
    535      1.1     matt 
    536  1.1.4.1  thorpej 	/*
    537  1.1.4.1  thorpej 	 * XXX Defer this to later so that we can reclaim the memory
    538  1.1.4.1  thorpej 	 * XXX used by the RedBoot page tables.
    539  1.1.4.1  thorpej 	 */
    540      1.1     matt 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG);
    541      1.1     matt 
    542      1.1     matt 	/*
    543      1.1     matt 	 * Ok we have allocated physical pages for the primary kernel
    544      1.1     matt 	 * page tables
    545      1.1     matt 	 */
    546      1.1     matt 
    547      1.1     matt #ifdef VERBOSE_INIT_ARM
    548  1.1.4.1  thorpej 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    549      1.1     matt #endif
    550      1.1     matt 
    551      1.1     matt 	/*
    552      1.1     matt 	 * Now we start consturction of the L1 page table
    553      1.1     matt 	 * We start by mapping the L2 page tables into the L1.
    554      1.1     matt 	 * This means that we can replace L1 mappings later on if necessary
    555      1.1     matt 	 */
    556      1.1     matt 	l1pagetable = kernel_l1pt.pv_pa;
    557      1.1     matt 
    558      1.1     matt 	/* Map the L2 pages tables in the L1 page table */
    559      1.1     matt 	map_pagetable(l1pagetable, 0x00000000,
    560      1.1     matt 	    kernel_pt_table[KERNEL_PT_SYS]);
    561      1.1     matt 	map_pagetable(l1pagetable, KERNEL_BASE,
    562      1.1     matt 	    kernel_pt_table[KERNEL_PT_KERNEL]);
    563  1.1.4.1  thorpej 	map_pagetable(l1pagetable, IQ80310_IOPXS_VBASE,
    564  1.1.4.1  thorpej 	    kernel_pt_table[KERNEL_PT_IOPXS]);
    565      1.1     matt 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
    566      1.1     matt 		map_pagetable(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    567      1.1     matt 		    kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    568      1.1     matt 	map_pagetable(l1pagetable, PROCESS_PAGE_TBLS_BASE,
    569      1.1     matt 	    kernel_ptpt.pv_pa);
    570      1.1     matt 
    571      1.1     matt #ifdef VERBOSE_INIT_ARM
    572      1.1     matt 	printf("Mapping kernel\n");
    573      1.1     matt #endif
    574      1.1     matt 
    575      1.1     matt 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    576      1.1     matt 	l2pagetable = kernel_pt_table[KERNEL_PT_KERNEL];
    577      1.1     matt 
    578      1.1     matt 	{
    579  1.1.4.1  thorpej 		extern char etext[], _end[];
    580  1.1.4.1  thorpej 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    581  1.1.4.1  thorpej 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    582      1.1     matt 		u_int logical;
    583      1.1     matt 
    584  1.1.4.1  thorpej 		/* Round down text size and round up total size. */
    585      1.1     matt 		textsize = textsize & ~PGOFSET;
    586      1.1     matt 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    587  1.1.4.1  thorpej 
    588  1.1.4.1  thorpej 		logical = 0x00200000;	/* offset of kernel in RAM */
    589  1.1.4.1  thorpej 
    590  1.1.4.1  thorpej 		/*
    591  1.1.4.1  thorpej 		 * This maps the kernel text/data/bss VA==PA.
    592  1.1.4.1  thorpej 		 */
    593      1.1     matt 		logical += map_chunk(0, l2pagetable, KERNEL_BASE + logical,
    594      1.1     matt 		    physical_start + logical, textsize,
    595      1.1     matt 		    AP_KRW, PT_CACHEABLE);
    596      1.1     matt 		logical += map_chunk(0, l2pagetable, KERNEL_BASE + logical,
    597      1.1     matt 		    physical_start + logical, totalsize - textsize,
    598      1.1     matt 		    AP_KRW, PT_CACHEABLE);
    599  1.1.4.1  thorpej 
    600  1.1.4.1  thorpej #if 0 /* XXX No symbols yet. */
    601      1.1     matt 		logical += map_chunk(0, l2pagetable, KERNEL_BASE + logical,
    602      1.1     matt 		    physical_start + logical, kernexec->a_syms + sizeof(int)
    603      1.1     matt 		    + *(u_int *)((int)end + kernexec->a_syms + sizeof(int)),
    604      1.1     matt 		    AP_KRW, PT_CACHEABLE);
    605      1.1     matt #endif
    606      1.1     matt 	}
    607      1.1     matt 
    608      1.1     matt #ifdef VERBOSE_INIT_ARM
    609      1.1     matt 	printf("Constructing L2 page tables\n");
    610      1.1     matt #endif
    611      1.1     matt 
    612      1.1     matt 	/* Map the stack pages */
    613      1.1     matt 	map_chunk(0, l2pagetable, irqstack.pv_va, irqstack.pv_pa,
    614      1.1     matt 	    IRQ_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
    615      1.1     matt 	map_chunk(0, l2pagetable, abtstack.pv_va, abtstack.pv_pa,
    616      1.1     matt 	    ABT_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
    617      1.1     matt 	map_chunk(0, l2pagetable, undstack.pv_va, undstack.pv_pa,
    618      1.1     matt 	    UND_STACK_SIZE * NBPG, AP_KRW, PT_CACHEABLE);
    619      1.1     matt 	map_chunk(0, l2pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    620      1.1     matt 	    UPAGES * NBPG, AP_KRW, PT_CACHEABLE);
    621      1.1     matt 	map_chunk(0, l2pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    622      1.1     matt 	    PD_SIZE, AP_KRW, 0);
    623      1.1     matt 
    624  1.1.4.1  thorpej 	/* Map the Mini-Data cache clean area. */
    625  1.1.4.1  thorpej 	map_chunk(0, l2pagetable, minidataclean.pv_va, minidataclean.pv_pa,
    626  1.1.4.1  thorpej 	    NBPG, AP_KRW, PT_CACHEABLE);
    627  1.1.4.1  thorpej 
    628      1.1     matt 	/* Map the page table that maps the kernel pages */
    629      1.1     matt 	map_entry_nc(l2pagetable, kernel_ptpt.pv_pa, kernel_ptpt.pv_pa);
    630      1.1     matt 
    631      1.1     matt 	/*
    632      1.1     matt 	 * Map entries in the page table used to map PTE's
    633      1.1     matt 	 * Basically every kernel page table gets mapped here
    634      1.1     matt 	 */
    635      1.1     matt 	/* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */
    636      1.1     matt 	l2pagetable = kernel_ptpt.pv_pa;
    637      1.1     matt 	map_entry_nc(l2pagetable, (KERNEL_BASE >> (PGSHIFT-2)),
    638      1.1     matt 	    kernel_pt_table[KERNEL_PT_KERNEL]);
    639      1.1     matt 	map_entry_nc(l2pagetable, (PROCESS_PAGE_TBLS_BASE >> (PGSHIFT-2)),
    640      1.1     matt 	    kernel_ptpt.pv_pa);
    641      1.1     matt 	map_entry_nc(l2pagetable, (0x00000000 >> (PGSHIFT-2)),
    642      1.1     matt 	    kernel_pt_table[KERNEL_PT_SYS]);
    643      1.1     matt 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
    644      1.1     matt 		map_entry_nc(l2pagetable, ((KERNEL_VM_BASE +
    645      1.1     matt 		    (loop * 0x00400000)) >> (PGSHIFT-2)),
    646      1.1     matt 		    kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    647      1.1     matt 
    648      1.1     matt 	/*
    649      1.1     matt 	 * Map the system page in the kernel page table for the bottom 1Meg
    650      1.1     matt 	 * of the virtual memory map.
    651      1.1     matt 	 */
    652      1.1     matt 	l2pagetable = kernel_pt_table[KERNEL_PT_SYS];
    653      1.1     matt 	map_entry(l2pagetable, 0x00000000, systempage.pv_pa);
    654      1.1     matt 
    655  1.1.4.1  thorpej 	/*
    656  1.1.4.1  thorpej 	 * Map devices we can map w/ section mappings.
    657  1.1.4.1  thorpej 	 */
    658      1.1     matt 	loop = 0;
    659      1.1     matt 	while (l1_sec_table[loop].size) {
    660      1.1     matt 		vm_size_t sz;
    661      1.1     matt 
    662      1.1     matt #ifdef VERBOSE_INIT_ARM
    663      1.1     matt 		printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
    664      1.1     matt 		    l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
    665      1.1     matt 		    l1_sec_table[loop].va);
    666      1.1     matt #endif
    667      1.1     matt 		for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_SEC_SIZE)
    668      1.1     matt 			map_section(l1pagetable, l1_sec_table[loop].va + sz,
    669      1.1     matt 			    l1_sec_table[loop].pa + sz,
    670      1.1     matt 			    l1_sec_table[loop].flags);
    671      1.1     matt 		++loop;
    672      1.1     matt 	}
    673      1.1     matt 
    674      1.1     matt 	/*
    675  1.1.4.1  thorpej 	 * Map the PCI I/O spaces and i80312 registers.  These are too
    676  1.1.4.1  thorpej 	 * small to be mapped w/ section mappings.
    677  1.1.4.1  thorpej 	 */
    678  1.1.4.1  thorpej 	l2pagetable = kernel_pt_table[KERNEL_PT_IOPXS];
    679  1.1.4.1  thorpej #ifdef VERBOSE_INIT_ARM
    680  1.1.4.1  thorpej 	printf("Mapping PIOW 0x%08lx -> 0x%08lx @ 0x%08lx\n",
    681  1.1.4.1  thorpej 	    I80312_PCI_XLATE_PIOW_BASE,
    682  1.1.4.1  thorpej 	    I80312_PCI_XLATE_PIOW_BASE + I80312_PCI_XLATE_IOSIZE - 1,
    683  1.1.4.1  thorpej 	    IQ80310_PIOW_VBASE);
    684  1.1.4.1  thorpej #endif
    685  1.1.4.1  thorpej 	map_chunk(0, l2pagetable, IQ80310_PIOW_VBASE,
    686  1.1.4.1  thorpej 	    I80312_PCI_XLATE_PIOW_BASE, I80312_PCI_XLATE_IOSIZE, AP_KRW, 0);
    687  1.1.4.1  thorpej 
    688  1.1.4.1  thorpej #ifdef VERBOSE_INIT_ARM
    689  1.1.4.1  thorpej 	printf("Mapping SIOW 0x%08lx -> 0x%08lx @ 0x%08lx\n",
    690  1.1.4.1  thorpej 	    I80312_PCI_XLATE_SIOW_BASE,
    691  1.1.4.1  thorpej 	    I80312_PCI_XLATE_SIOW_BASE + I80312_PCI_XLATE_IOSIZE - 1,
    692  1.1.4.1  thorpej 	    IQ80310_SIOW_VBASE);
    693  1.1.4.1  thorpej #endif
    694  1.1.4.1  thorpej 	map_chunk(0, l2pagetable, IQ80310_SIOW_VBASE,
    695  1.1.4.1  thorpej 	    I80312_PCI_XLATE_SIOW_BASE, I80312_PCI_XLATE_IOSIZE, AP_KRW, 0);
    696  1.1.4.1  thorpej 
    697  1.1.4.1  thorpej #ifdef VERBOSE_INIT_ARM
    698  1.1.4.1  thorpej 	printf("Mapping 80312 0x%08lx -> 0x%08lx @ 0x%08lx\n",
    699  1.1.4.1  thorpej 	    I80312_PMMR_BASE,
    700  1.1.4.1  thorpej 	    I80312_PMMR_BASE + I80312_PMMR_SIZE - 1,
    701  1.1.4.1  thorpej 	    IQ80310_80312_VBASE);
    702  1.1.4.1  thorpej #endif
    703  1.1.4.1  thorpej 	map_chunk(0, l2pagetable, IQ80310_80312_VBASE,
    704  1.1.4.1  thorpej 	    I80312_PMMR_BASE, I80312_PMMR_SIZE, AP_KRW, 0);
    705  1.1.4.1  thorpej 
    706  1.1.4.1  thorpej 	/*
    707  1.1.4.1  thorpej 	 * Give the XScale global cache clean code an appropriately
    708  1.1.4.1  thorpej 	 * sized chunk of unmapped VA space starting at 0xff000000
    709  1.1.4.1  thorpej 	 * (our device mappings end before this address).
    710  1.1.4.1  thorpej 	 */
    711  1.1.4.1  thorpej 	xscale_cache_clean_addr = 0xff000000U;
    712  1.1.4.1  thorpej 
    713  1.1.4.1  thorpej 	/*
    714      1.1     matt 	 * Now we have the real page tables in place so we can switch to them.
    715  1.1.4.1  thorpej 	 * Once this is done we will be running with the REAL kernel page
    716  1.1.4.1  thorpej 	 * tables.
    717      1.1     matt 	 */
    718      1.1     matt 
    719  1.1.4.1  thorpej 	/*
    720  1.1.4.1  thorpej 	 * Update the physical_freestart/physical_freeend/free_pages
    721  1.1.4.1  thorpej 	 * variables.
    722  1.1.4.1  thorpej 	 */
    723  1.1.4.1  thorpej 	{
    724  1.1.4.1  thorpej 		extern char _end[];
    725  1.1.4.1  thorpej 
    726  1.1.4.1  thorpej 		physical_freestart = (((uintptr_t) _end) + PGOFSET) & ~PGOFSET;
    727  1.1.4.1  thorpej 		physical_freeend = physical_end;
    728  1.1.4.1  thorpej 		free_pages = (physical_freeend - physical_freestart) / NBPG;
    729  1.1.4.1  thorpej 	}
    730  1.1.4.1  thorpej 
    731      1.1     matt 	/* Switch tables */
    732      1.1     matt #ifdef VERBOSE_INIT_ARM
    733  1.1.4.1  thorpej 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    734      1.1     matt 	       physical_freestart, free_pages, free_pages);
    735      1.1     matt 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    736      1.1     matt #endif
    737      1.1     matt 	setttb(kernel_l1pt.pv_pa);
    738      1.1     matt 
    739      1.1     matt #ifdef VERBOSE_INIT_ARM
    740      1.1     matt 	printf("done!\n");
    741      1.1     matt #endif
    742      1.1     matt 
    743      1.1     matt #ifdef VERBOSE_INIT_ARM
    744      1.1     matt 	printf("bootstrap done.\n");
    745      1.1     matt #endif
    746      1.1     matt 
    747  1.1.4.1  thorpej 	/* Right, set up the vectors at the bottom of page 0 */
    748      1.1     matt 	memcpy((char *)0x00000000, page0, page0_end - page0);
    749      1.1     matt 
    750      1.1     matt 	/* We have modified a text page so sync the icache */
    751      1.1     matt 	cpu_cache_syncI();
    752      1.1     matt 
    753      1.1     matt 	/*
    754      1.1     matt 	 * Pages were allocated during the secondary bootstrap for the
    755      1.1     matt 	 * stacks for different CPU modes.
    756      1.1     matt 	 * We must now set the r13 registers in the different CPU modes to
    757      1.1     matt 	 * point to these stacks.
    758      1.1     matt 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    759      1.1     matt 	 * of the stack memory.
    760      1.1     matt 	 */
    761      1.1     matt 	printf("init subsystems: stacks ");
    762      1.1     matt 
    763      1.1     matt 	set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG);
    764      1.1     matt 	set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG);
    765      1.1     matt 	set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG);
    766      1.1     matt 
    767      1.1     matt 	/*
    768      1.1     matt 	 * Well we should set a data abort handler.
    769  1.1.4.1  thorpej 	 * Once things get going this will change as we will need a proper
    770  1.1.4.1  thorpej 	 * handler.
    771      1.1     matt 	 * Until then we will use a handler that just panics but tells us
    772      1.1     matt 	 * why.
    773      1.1     matt 	 * Initialisation of the vectors will just panic on a data abort.
    774      1.1     matt 	 * This just fills in a slighly better one.
    775      1.1     matt 	 */
    776      1.1     matt 	printf("vectors ");
    777      1.1     matt 	data_abort_handler_address = (u_int)data_abort_handler;
    778      1.1     matt 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    779      1.1     matt 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    780      1.1     matt 
    781      1.1     matt 	/* At last !
    782      1.1     matt 	 * We now have the kernel in physical memory from the bottom upwards.
    783      1.1     matt 	 * Kernel page tables are physically above this.
    784      1.1     matt 	 * The kernel is mapped to KERNEL_TEXT_BASE
    785      1.1     matt 	 * The kernel data PTs will handle the mapping of 0xf1000000-0xf3ffffff
    786      1.1     matt 	 * The page tables are mapped to 0xefc00000
    787      1.1     matt 	 */
    788      1.1     matt 
    789      1.1     matt 	/* Initialise the undefined instruction handlers */
    790      1.1     matt 	printf("undefined ");
    791      1.1     matt 	undefined_init();
    792      1.1     matt 
    793      1.1     matt 	/* Boot strap pmap telling it where the kernel page table is */
    794      1.1     matt 	printf("pmap ");
    795      1.1     matt 	pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt);
    796      1.1     matt 
    797      1.1     matt 	/* Setup the IRQ system */
    798      1.1     matt 	printf("irq ");
    799      1.1     matt 	irq_init();
    800      1.1     matt 	printf("done.\n");
    801      1.1     matt 
    802      1.1     matt #ifdef IPKDB
    803      1.1     matt 	/* Initialise ipkdb */
    804      1.1     matt 	ipkdb_init();
    805      1.1     matt 	if (boothowto & RB_KDB)
    806      1.1     matt 		ipkdb_connect(0);
    807      1.1     matt #endif
    808      1.1     matt 
    809      1.1     matt #ifdef DDB
    810      1.1     matt 	db_machine_init();
    811  1.1.4.1  thorpej 
    812  1.1.4.1  thorpej 	/* Firmware doesn't load symbols. */
    813  1.1.4.1  thorpej 	ddb_init(0, NULL, NULL);
    814      1.1     matt 
    815      1.1     matt 	if (boothowto & RB_KDB)
    816      1.1     matt 		Debugger();
    817      1.1     matt #endif
    818      1.1     matt 
    819      1.1     matt 	/* We return the new stack pointer address */
    820      1.1     matt 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    821      1.1     matt }
    822      1.1     matt 
    823      1.1     matt void
    824  1.1.4.1  thorpej process_kernel_args(char *args)
    825      1.1     matt {
    826      1.1     matt 
    827      1.1     matt 	boothowto = 0;
    828      1.1     matt 
    829      1.1     matt 	/* Make a local copy of the bootargs */
    830      1.1     matt 	strncpy(bootargs, args, MAX_BOOT_STRING);
    831      1.1     matt 
    832      1.1     matt 	args = bootargs;
    833      1.1     matt 	boot_file = bootargs;
    834      1.1     matt 
    835      1.1     matt 	/* Skip the kernel image filename */
    836      1.1     matt 	while (*args != ' ' && *args != 0)
    837      1.1     matt 		++args;
    838      1.1     matt 
    839      1.1     matt 	if (*args != 0)
    840      1.1     matt 		*args++ = 0;
    841      1.1     matt 
    842      1.1     matt 	while (*args == ' ')
    843      1.1     matt 		++args;
    844      1.1     matt 
    845      1.1     matt 	boot_args = args;
    846      1.1     matt 
    847      1.1     matt 	printf("bootfile: %s\n", boot_file);
    848      1.1     matt 	printf("bootargs: %s\n", boot_args);
    849      1.1     matt 
    850      1.1     matt 	parse_mi_bootargs(boot_args);
    851      1.1     matt }
    852      1.1     matt 
    853      1.1     matt void
    854      1.1     matt consinit(void)
    855      1.1     matt {
    856  1.1.4.1  thorpej 	static int consinit_called;
    857      1.1     matt 
    858      1.1     matt 	if (consinit_called != 0)
    859      1.1     matt 		return;
    860      1.1     matt 
    861      1.1     matt 	consinit_called = 1;
    862      1.1     matt 
    863  1.1.4.1  thorpej #if NCOM > 0
    864  1.1.4.1  thorpej 	if (comcnattach(&obio_bs_tag, IQ80310_UART2, comcnspeed,
    865  1.1.4.1  thorpej 	    COM_FREQ, comcnmode))
    866  1.1.4.1  thorpej 			panic("can't init serial console @%lx", IQ80310_UART1);
    867      1.1     matt #else
    868  1.1.4.1  thorpej 	panic("serial console @%lx not configured", IQ80310_UART1);
    869      1.1     matt #endif
    870      1.1     matt }
    871