Home | History | Annotate | Line # | Download | only in integrator
integrator_machdep.c revision 1.13
      1  1.13   thorpej /*	$NetBSD: integrator_machdep.c,v 1.13 2002/02/21 05:25:24 thorpej Exp $	*/
      2   1.1  rearnsha 
      3   1.1  rearnsha /*
      4   1.1  rearnsha  * Copyright (c) 2001 ARM Ltd
      5   1.1  rearnsha  * All rights reserved.
      6   1.1  rearnsha  *
      7   1.1  rearnsha  * Redistribution and use in source and binary forms, with or without
      8   1.1  rearnsha  * modification, are permitted provided that the following conditions
      9   1.1  rearnsha  * are met:
     10   1.1  rearnsha  * 1. Redistributions of source code must retain the above copyright
     11   1.1  rearnsha  *    notice, this list of conditions and the following disclaimer.
     12   1.1  rearnsha  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  rearnsha  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  rearnsha  *    documentation and/or other materials provided with the distribution.
     15   1.1  rearnsha  * 3. The name of the company may not be used to endorse or promote
     16   1.1  rearnsha  *    products derived from this software without specific prior written
     17   1.1  rearnsha  *    permission.
     18   1.1  rearnsha  *
     19   1.1  rearnsha  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     20   1.1  rearnsha  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     21   1.1  rearnsha  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22   1.1  rearnsha  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     23   1.1  rearnsha  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24   1.1  rearnsha  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     25   1.1  rearnsha  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1  rearnsha  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1  rearnsha  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1  rearnsha  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1  rearnsha  * SUCH DAMAGE.
     30   1.1  rearnsha  *
     31   1.1  rearnsha  * Copyright (c) 1997,1998 Mark Brinicombe.
     32   1.1  rearnsha  * Copyright (c) 1997,1998 Causality Limited.
     33   1.1  rearnsha  * All rights reserved.
     34   1.1  rearnsha  *
     35   1.1  rearnsha  * Redistribution and use in source and binary forms, with or without
     36   1.1  rearnsha  * modification, are permitted provided that the following conditions
     37   1.1  rearnsha  * are met:
     38   1.1  rearnsha  * 1. Redistributions of source code must retain the above copyright
     39   1.1  rearnsha  *    notice, this list of conditions and the following disclaimer.
     40   1.1  rearnsha  * 2. Redistributions in binary form must reproduce the above copyright
     41   1.1  rearnsha  *    notice, this list of conditions and the following disclaimer in the
     42   1.1  rearnsha  *    documentation and/or other materials provided with the distribution.
     43   1.1  rearnsha  * 3. All advertising materials mentioning features or use of this software
     44   1.1  rearnsha  *    must display the following acknowledgement:
     45   1.1  rearnsha  *	This product includes software developed by Mark Brinicombe
     46   1.1  rearnsha  *	for the NetBSD Project.
     47   1.1  rearnsha  * 4. The name of the company nor the name of the author may be used to
     48   1.1  rearnsha  *    endorse or promote products derived from this software without specific
     49   1.1  rearnsha  *    prior written permission.
     50   1.1  rearnsha  *
     51   1.1  rearnsha  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     52   1.1  rearnsha  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     53   1.1  rearnsha  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     54   1.1  rearnsha  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     55   1.1  rearnsha  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     56   1.1  rearnsha  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     57   1.1  rearnsha  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     58   1.1  rearnsha  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     59   1.1  rearnsha  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     60   1.1  rearnsha  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     61   1.1  rearnsha  * SUCH DAMAGE.
     62   1.1  rearnsha  *
     63   1.1  rearnsha  * Machine dependant functions for kernel setup for integrator board
     64   1.1  rearnsha  *
     65   1.1  rearnsha  * Created      : 24/11/97
     66   1.1  rearnsha  */
     67   1.1  rearnsha 
     68   1.1  rearnsha #include "opt_ddb.h"
     69   1.1  rearnsha #include "opt_pmap_debug.h"
     70   1.1  rearnsha 
     71   1.1  rearnsha #include <sys/param.h>
     72   1.1  rearnsha #include <sys/device.h>
     73   1.1  rearnsha #include <sys/systm.h>
     74   1.1  rearnsha #include <sys/kernel.h>
     75   1.1  rearnsha #include <sys/exec.h>
     76   1.1  rearnsha #include <sys/proc.h>
     77   1.1  rearnsha #include <sys/msgbuf.h>
     78   1.1  rearnsha #include <sys/reboot.h>
     79   1.1  rearnsha #include <sys/termios.h>
     80   1.1  rearnsha 
     81   1.1  rearnsha #include <dev/cons.h>
     82   1.1  rearnsha 
     83   1.1  rearnsha #include <machine/db_machdep.h>
     84   1.1  rearnsha #include <ddb/db_sym.h>
     85   1.1  rearnsha #include <ddb/db_extern.h>
     86   1.1  rearnsha 
     87   1.1  rearnsha #include <machine/bootconfig.h>
     88   1.1  rearnsha #include <machine/bus.h>
     89   1.1  rearnsha #include <machine/cpu.h>
     90   1.1  rearnsha #include <machine/frame.h>
     91   1.1  rearnsha #include <machine/intr.h>
     92   1.8   thorpej #include <evbarm/ifpga/irqhandler.h>	/* XXX XXX XXX */
     93   1.6   thorpej #include <arm/undefined.h>
     94   1.1  rearnsha 
     95   1.1  rearnsha #include <evbarm/integrator/integrator_boot.h>
     96   1.1  rearnsha 
     97   1.1  rearnsha #include "opt_ipkdb.h"
     98   1.1  rearnsha #include "pci.h"
     99   1.1  rearnsha 
    100   1.1  rearnsha void ifpga_reset(void) __attribute__((noreturn));
    101   1.1  rearnsha /*
    102   1.1  rearnsha  * Address to call from cpu_reset() to reset the machine.
    103   1.1  rearnsha  * This is machine architecture dependant as it varies depending
    104   1.1  rearnsha  * on where the ROM appears when you turn the MMU off.
    105   1.1  rearnsha  */
    106   1.1  rearnsha 
    107   1.1  rearnsha u_int cpu_reset_address = (u_int) ifpga_reset;
    108   1.1  rearnsha 
    109   1.1  rearnsha /* Define various stack sizes in pages */
    110   1.1  rearnsha #define IRQ_STACK_SIZE	1
    111   1.1  rearnsha #define ABT_STACK_SIZE	1
    112   1.1  rearnsha #ifdef IPKDB
    113   1.1  rearnsha #define UND_STACK_SIZE	2
    114   1.1  rearnsha #else
    115   1.1  rearnsha #define UND_STACK_SIZE	1
    116   1.1  rearnsha #endif
    117   1.1  rearnsha 
    118   1.1  rearnsha struct intbootinfo intbootinfo;
    119   1.1  rearnsha BootConfig bootconfig;		/* Boot config storage */
    120   1.1  rearnsha static char bootargs[MAX_BOOT_STRING + 1];
    121   1.1  rearnsha char *boot_args = NULL;
    122   1.1  rearnsha char *boot_file = NULL;
    123   1.1  rearnsha 
    124   1.1  rearnsha vm_offset_t physical_start;
    125   1.1  rearnsha vm_offset_t physical_freestart;
    126   1.1  rearnsha vm_offset_t physical_freeend;
    127   1.1  rearnsha vm_offset_t physical_end;
    128   1.1  rearnsha u_int free_pages;
    129   1.1  rearnsha vm_offset_t pagetables_start;
    130   1.1  rearnsha int physmem = 0;
    131   1.1  rearnsha 
    132   1.1  rearnsha /*int debug_flags;*/
    133   1.1  rearnsha #ifndef PMAP_STATIC_L1S
    134   1.1  rearnsha int max_processes = 64;			/* Default number */
    135   1.1  rearnsha #endif	/* !PMAP_STATIC_L1S */
    136   1.1  rearnsha 
    137   1.1  rearnsha /* Physical and virtual addresses for some global pages */
    138   1.1  rearnsha pv_addr_t systempage;
    139   1.1  rearnsha pv_addr_t irqstack;
    140   1.1  rearnsha pv_addr_t undstack;
    141   1.1  rearnsha pv_addr_t abtstack;
    142   1.1  rearnsha pv_addr_t kernelstack;
    143   1.1  rearnsha 
    144   1.1  rearnsha vm_offset_t msgbufphys;
    145   1.1  rearnsha 
    146   1.1  rearnsha extern u_int data_abort_handler_address;
    147   1.1  rearnsha extern u_int prefetch_abort_handler_address;
    148   1.1  rearnsha extern u_int undefined_handler_address;
    149   1.1  rearnsha 
    150   1.1  rearnsha #ifdef PMAP_DEBUG
    151   1.1  rearnsha extern int pmap_debug_level;
    152   1.1  rearnsha #endif
    153   1.1  rearnsha 
    154   1.1  rearnsha #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    155   1.1  rearnsha #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    156   1.1  rearnsha #define KERNEL_PT_VMDATA	2	/* Page tables for mapping kernel VM */
    157   1.1  rearnsha #define	KERNEL_PT_VMDATA_NUM	(KERNEL_VM_SIZE >> (PDSHIFT + 2))
    158   1.1  rearnsha #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    159   1.1  rearnsha 
    160   1.1  rearnsha pt_entry_t kernel_pt_table[NUM_KERNEL_PTS];
    161   1.1  rearnsha 
    162   1.1  rearnsha struct user *proc0paddr;
    163   1.1  rearnsha 
    164   1.1  rearnsha /* Prototypes */
    165   1.1  rearnsha 
    166   1.1  rearnsha void consinit		__P((void));
    167   1.1  rearnsha 
    168   1.1  rearnsha void process_kernel_args	__P((char *));
    169   1.1  rearnsha void data_abort_handler		__P((trapframe_t *frame));
    170   1.1  rearnsha void prefetch_abort_handler	__P((trapframe_t *frame));
    171   1.1  rearnsha void undefinedinstruction_bounce	__P((trapframe_t *frame));
    172   1.1  rearnsha extern void configure		__P((void));
    173   1.1  rearnsha extern void parse_mi_bootargs	__P((char *args));
    174   1.1  rearnsha extern void dumpsys		__P((void));
    175   1.1  rearnsha 
    176   1.1  rearnsha /* A load of console goo. */
    177   1.1  rearnsha #include "vga.h"
    178   1.1  rearnsha #if (NVGA > 0)
    179   1.1  rearnsha #include <dev/ic/mc6845reg.h>
    180   1.1  rearnsha #include <dev/ic/pcdisplayvar.h>
    181   1.1  rearnsha #include <dev/ic/vgareg.h>
    182   1.1  rearnsha #include <dev/ic/vgavar.h>
    183   1.1  rearnsha #endif
    184   1.1  rearnsha 
    185   1.1  rearnsha #include "pckbc.h"
    186   1.1  rearnsha #if (NPCKBC > 0)
    187   1.1  rearnsha #include <dev/ic/i8042reg.h>
    188   1.1  rearnsha #include <dev/ic/pckbcvar.h>
    189   1.1  rearnsha #endif
    190   1.1  rearnsha 
    191   1.1  rearnsha #include "com.h"
    192   1.1  rearnsha #if (NCOM > 0)
    193   1.1  rearnsha #include <dev/ic/comreg.h>
    194   1.1  rearnsha #include <dev/ic/comvar.h>
    195   1.1  rearnsha #ifndef CONCOMADDR
    196   1.1  rearnsha #define CONCOMADDR 0x3f8
    197   1.1  rearnsha #endif
    198   1.1  rearnsha #endif
    199   1.1  rearnsha 
    200   1.1  rearnsha #define CONSPEED B115200
    201   1.1  rearnsha #ifndef CONSPEED
    202   1.1  rearnsha #define CONSPEED B9600	/* TTYDEF_SPEED */
    203   1.1  rearnsha #endif
    204   1.1  rearnsha #ifndef CONMODE
    205   1.1  rearnsha #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    206   1.1  rearnsha #endif
    207   1.1  rearnsha 
    208   1.1  rearnsha int comcnspeed = CONSPEED;
    209   1.1  rearnsha int comcnmode = CONMODE;
    210   1.1  rearnsha 
    211   1.1  rearnsha #include "plcom.h"
    212   1.1  rearnsha #if (NPLCOM > 0)
    213   1.1  rearnsha #include <evbarm/dev/plcomreg.h>
    214   1.1  rearnsha #include <evbarm/dev/plcomvar.h>
    215   1.1  rearnsha 
    216   1.1  rearnsha #include <evbarm/ifpga/ifpgamem.h>
    217   1.1  rearnsha #include <evbarm/ifpga/ifpgareg.h>
    218   1.1  rearnsha #include <evbarm/ifpga/ifpgavar.h>
    219   1.1  rearnsha #endif
    220   1.1  rearnsha 
    221   1.1  rearnsha #ifndef CONSDEVNAME
    222   1.1  rearnsha #define CONSDEVNAME "plcom"
    223   1.1  rearnsha #endif
    224   1.1  rearnsha 
    225   1.1  rearnsha #ifndef PLCONSPEED
    226   1.1  rearnsha #define PLCONSPEED B38400
    227   1.1  rearnsha #endif
    228   1.1  rearnsha #ifndef PLCONMODE
    229   1.1  rearnsha #define PLCONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    230   1.1  rearnsha #endif
    231   1.1  rearnsha #ifndef PLCOMCNUNIT
    232   1.1  rearnsha #define PLCOMCNUNIT -1
    233   1.1  rearnsha #endif
    234   1.1  rearnsha 
    235   1.1  rearnsha int plcomcnspeed = PLCONSPEED;
    236   1.1  rearnsha int plcomcnmode = PLCONMODE;
    237   1.1  rearnsha 
    238   1.1  rearnsha #if 0
    239   1.1  rearnsha extern struct consdev kcomcons;
    240   1.1  rearnsha static void kcomcnputc(dev_t, int);
    241   1.1  rearnsha #endif
    242   1.1  rearnsha 
    243   1.1  rearnsha /*
    244   1.1  rearnsha  * void cpu_reboot(int howto, char *bootstr)
    245   1.1  rearnsha  *
    246   1.1  rearnsha  * Reboots the system
    247   1.1  rearnsha  *
    248   1.1  rearnsha  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    249   1.1  rearnsha  * then reset the CPU.
    250   1.1  rearnsha  */
    251   1.1  rearnsha 
    252   1.1  rearnsha void
    253   1.1  rearnsha cpu_reboot(howto, bootstr)
    254   1.1  rearnsha 	int howto;
    255   1.1  rearnsha 	char *bootstr;
    256   1.1  rearnsha {
    257   1.1  rearnsha #ifdef DIAGNOSTIC
    258   1.1  rearnsha 	/* info */
    259   1.1  rearnsha 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    260   1.1  rearnsha #endif
    261   1.1  rearnsha 
    262   1.1  rearnsha 	/*
    263   1.1  rearnsha 	 * If we are still cold then hit the air brakes
    264   1.1  rearnsha 	 * and crash to earth fast
    265   1.1  rearnsha 	 */
    266   1.1  rearnsha 	if (cold) {
    267   1.1  rearnsha 		doshutdownhooks();
    268   1.1  rearnsha 		printf("The operating system has halted.\n");
    269   1.1  rearnsha 		printf("Please press any key to reboot.\n\n");
    270   1.1  rearnsha 		cngetc();
    271   1.1  rearnsha 		printf("rebooting...\n");
    272   1.1  rearnsha 		ifpga_reset();
    273   1.1  rearnsha 		/*NOTREACHED*/
    274   1.1  rearnsha 	}
    275   1.1  rearnsha 
    276   1.1  rearnsha 	/* Disable console buffering */
    277   1.1  rearnsha /*	cnpollc(1);*/
    278   1.1  rearnsha 
    279   1.1  rearnsha 	/*
    280   1.1  rearnsha 	 * If RB_NOSYNC was not specified sync the discs.
    281   1.1  rearnsha 	 * Note: Unless cold is set to 1 here, syslogd will die during the unmount.
    282   1.1  rearnsha 	 * It looks like syslogd is getting woken up only to find that it cannot
    283   1.1  rearnsha 	 * page part of the binary in as the filesystem has been unmounted.
    284   1.1  rearnsha 	 */
    285   1.1  rearnsha 	if (!(howto & RB_NOSYNC))
    286   1.1  rearnsha 		bootsync();
    287   1.1  rearnsha 
    288   1.1  rearnsha 	/* Say NO to interrupts */
    289   1.1  rearnsha 	splhigh();
    290   1.1  rearnsha 
    291   1.1  rearnsha 	/* Do a dump if requested. */
    292   1.1  rearnsha 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    293   1.1  rearnsha 		dumpsys();
    294   1.1  rearnsha 
    295   1.1  rearnsha 	/* Run any shutdown hooks */
    296   1.1  rearnsha 	doshutdownhooks();
    297   1.1  rearnsha 
    298   1.1  rearnsha 	/* Make sure IRQ's are disabled */
    299   1.1  rearnsha 	IRQdisable;
    300   1.1  rearnsha 
    301   1.1  rearnsha 	if (howto & RB_HALT) {
    302   1.1  rearnsha 		printf("The operating system has halted.\n");
    303   1.1  rearnsha 		printf("Please press any key to reboot.\n\n");
    304   1.1  rearnsha 		cngetc();
    305   1.1  rearnsha 	}
    306   1.1  rearnsha 
    307   1.1  rearnsha 	printf("rebooting...\n");
    308   1.1  rearnsha 	ifpga_reset();
    309   1.1  rearnsha 	/*NOTREACHED*/
    310   1.1  rearnsha }
    311   1.1  rearnsha 
    312   1.1  rearnsha /*
    313   1.1  rearnsha  * Mapping table for core kernel memory. This memory is mapped at init
    314   1.1  rearnsha  * time with section mappings.
    315   1.1  rearnsha  */
    316   1.1  rearnsha struct l1_sec_map {
    317   1.1  rearnsha 	vm_offset_t	va;
    318   1.1  rearnsha 	vm_offset_t	pa;
    319   1.1  rearnsha 	vm_size_t	size;
    320  1.12   thorpej 	vm_prot_t	prot;
    321   1.9   thorpej 	int		cache;
    322   1.1  rearnsha } l1_sec_table[] = {
    323   1.1  rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
    324   1.9   thorpej 	{ UART0_BOOT_BASE, IFPGA_IO_BASE + IFPGA_UART0, 1024 * 1024,
    325   1.9   thorpej 	  VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE },
    326   1.9   thorpej 	{ UART1_BOOT_BASE, IFPGA_IO_BASE + IFPGA_UART1, 1024 * 1024,
    327   1.9   thorpej 	  VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE },
    328   1.1  rearnsha #endif
    329   1.1  rearnsha #if NPCI > 0
    330   1.9   thorpej 	{ IFPGA_PCI_IO_VBASE, IFPGA_PCI_IO_BASE, IFPGA_PCI_IO_VSIZE,
    331   1.9   thorpej 	  VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE },
    332   1.9   thorpej 	{ IFPGA_PCI_CONF_VBASE, IFPGA_PCI_CONF_BASE, IFPGA_PCI_CONF_VSIZE,
    333   1.9   thorpej 	  VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE },
    334   1.1  rearnsha #endif
    335   1.1  rearnsha 
    336   1.9   thorpej 	{ 0, 0, 0, 0, 0 }
    337   1.1  rearnsha };
    338   1.1  rearnsha 
    339   1.1  rearnsha /*
    340   1.1  rearnsha  * u_int initarm(struct ebsaboot *bootinfo)
    341   1.1  rearnsha  *
    342   1.1  rearnsha  * Initial entry point on startup. This gets called before main() is
    343   1.1  rearnsha  * entered.
    344   1.1  rearnsha  * It should be responsible for setting up everything that must be
    345   1.1  rearnsha  * in place when main is called.
    346   1.1  rearnsha  * This includes
    347   1.1  rearnsha  *   Taking a copy of the boot configuration structure.
    348   1.1  rearnsha  *   Initialising the physical console so characters can be printed.
    349   1.1  rearnsha  *   Setting up page tables for the kernel
    350   1.1  rearnsha  *   Relocating the kernel to the bottom of physical memory
    351   1.1  rearnsha  */
    352   1.1  rearnsha 
    353   1.1  rearnsha u_int
    354   1.1  rearnsha initarm(bootinfo)
    355   1.1  rearnsha 	struct intbootinfo *bootinfo;
    356   1.1  rearnsha {
    357   1.1  rearnsha 	int loop;
    358   1.1  rearnsha 	int loop1;
    359   1.1  rearnsha 	u_int l1pagetable;
    360   1.1  rearnsha 	u_int l2pagetable;
    361   1.1  rearnsha 	extern char page0[], page0_end[];
    362   1.1  rearnsha 	extern int etext asm ("_etext");
    363   1.1  rearnsha 	extern int end asm ("_end");
    364   1.1  rearnsha 	pv_addr_t kernel_l1pt;
    365   1.1  rearnsha 	pv_addr_t kernel_ptpt;
    366   1.1  rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
    367   1.1  rearnsha 	static struct bus_space plcom_bus_space;
    368   1.1  rearnsha #endif
    369   1.1  rearnsha 
    370   1.1  rearnsha 
    371   1.1  rearnsha #if 0
    372   1.1  rearnsha 	cn_tab = &kcomcons;
    373   1.1  rearnsha #endif
    374   1.1  rearnsha 	/*
    375   1.1  rearnsha 	 * Heads up ... Setup the CPU / MMU / TLB functions
    376   1.1  rearnsha 	 */
    377   1.1  rearnsha 	if (set_cpufuncs())
    378   1.1  rearnsha 		panic("cpu not recognized!");
    379   1.1  rearnsha 
    380   1.1  rearnsha 	/*    - intbootinfo.bt_memstart) / NBPG */;
    381   1.1  rearnsha 
    382   1.1  rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
    383   1.1  rearnsha 	/*
    384   1.1  rearnsha 	 * Initialise the diagnostic serial console
    385   1.1  rearnsha 	 * This allows a means of generating output during initarm().
    386   1.1  rearnsha 	 * Once all the memory map changes are complete we can call consinit()
    387   1.1  rearnsha 	 * and not have to worry about things moving.
    388   1.1  rearnsha 	 */
    389   1.1  rearnsha 
    390   1.1  rearnsha 	if (PLCOMCNUNIT == 0) {
    391   1.1  rearnsha 		ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd600000);
    392   1.1  rearnsha 		plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
    393   1.1  rearnsha 		    IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
    394   1.1  rearnsha 	} else if (PLCOMCNUNIT == 1) {
    395   1.1  rearnsha 		ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd700000);
    396   1.1  rearnsha 		plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
    397   1.1  rearnsha 		    IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
    398   1.1  rearnsha 	}
    399   1.1  rearnsha #endif
    400   1.1  rearnsha 
    401   1.1  rearnsha 	/* Talk to the user */
    402   1.1  rearnsha 	printf("\nNetBSD/integrator booting ...\n");
    403   1.1  rearnsha 
    404   1.1  rearnsha #if 0
    405   1.1  rearnsha 	if (intbootinfo.bt_magic != BT_MAGIC_NUMBER_EBSA
    406   1.1  rearnsha 	    && intbootinfo.bt_magic != BT_MAGIC_NUMBER_CATS)
    407   1.1  rearnsha 		panic("Incompatible magic number passed in boot args\n");
    408   1.1  rearnsha #endif
    409   1.1  rearnsha 
    410   1.1  rearnsha /*	{
    411   1.1  rearnsha 	int loop;
    412   1.1  rearnsha 	for (loop = 0; loop < 8; ++loop) {
    413   1.1  rearnsha 		printf("%08x\n", *(((int *)bootinfo)+loop));
    414   1.1  rearnsha 	}
    415   1.1  rearnsha 	}*/
    416   1.1  rearnsha 
    417   1.1  rearnsha 	/*
    418   1.1  rearnsha 	 * Ok we have the following memory map
    419   1.1  rearnsha 	 *
    420   1.1  rearnsha 	 * virtual address == physical address apart from the areas:
    421   1.1  rearnsha 	 * 0x00000000 -> 0x000fffff which is mapped to
    422   1.1  rearnsha 	 * top 1MB of physical memory
    423   1.1  rearnsha 	 * 0x00100000 -> 0x0fffffff which is mapped to
    424   1.1  rearnsha 	 * physical addresses 0x00100000 -> 0x0fffffff
    425   1.1  rearnsha 	 * 0x10000000 -> 0x1fffffff which is mapped to
    426   1.1  rearnsha 	 * physical addresses 0x00000000 -> 0x0fffffff
    427   1.1  rearnsha 	 * 0x20000000 -> 0xefffffff which is mapped to
    428   1.1  rearnsha 	 * physical addresses 0x20000000 -> 0xefffffff
    429   1.1  rearnsha 	 * 0xf0000000 -> 0xf03fffff which is mapped to
    430   1.1  rearnsha 	 * physical addresses 0x00000000 -> 0x003fffff
    431   1.1  rearnsha 	 *
    432   1.1  rearnsha 	 * This means that the kernel is mapped suitably for continuing
    433   1.1  rearnsha 	 * execution, all I/O is mapped 1:1 virtual to physical and
    434   1.1  rearnsha 	 * physical memory is accessible.
    435   1.1  rearnsha 	 *
    436   1.1  rearnsha 	 * The initarm() has the responsibility for creating the kernel
    437   1.1  rearnsha 	 * page tables.
    438   1.1  rearnsha 	 * It must also set up various memory pointers that are used
    439   1.1  rearnsha 	 * by pmap etc.
    440   1.1  rearnsha 	 */
    441   1.1  rearnsha 
    442   1.1  rearnsha 	/*
    443   1.1  rearnsha 	 * Examine the boot args string for options we need to know about
    444   1.1  rearnsha 	 * now.
    445   1.1  rearnsha 	 */
    446   1.1  rearnsha #if 0
    447   1.1  rearnsha 	process_kernel_args((char *)intbootinfo.bt_args);
    448   1.1  rearnsha #endif
    449   1.1  rearnsha 
    450   1.1  rearnsha 	printf("initarm: Configuring system ...\n");
    451   1.1  rearnsha 
    452   1.1  rearnsha 	/*
    453   1.1  rearnsha 	 * Set up the variables that define the availablilty of
    454   1.1  rearnsha 	 * physical memory
    455   1.1  rearnsha 	 */
    456   1.1  rearnsha 	physical_start = 0 /*intbootinfo.bt_memstart*/;
    457   1.1  rearnsha 	physical_freestart = physical_start;
    458   1.1  rearnsha 
    459   1.1  rearnsha #if 0
    460   1.1  rearnsha 	physical_end = /*intbootinfo.bt_memend*/ /*intbootinfo.bi_nrpages * NBPG */ 32*1024*1024;
    461   1.1  rearnsha #else
    462   1.1  rearnsha 	{
    463   1.1  rearnsha 		volatile unsigned long *cm_sdram
    464   1.1  rearnsha 		    = (volatile unsigned long *)0x10000020;
    465   1.1  rearnsha 
    466   1.1  rearnsha 		switch ((*cm_sdram >> 2) & 0x7)
    467   1.1  rearnsha 		{
    468   1.1  rearnsha 		case 0:
    469   1.1  rearnsha 			physical_end = 16 * 1024 * 1024;
    470   1.1  rearnsha 			break;
    471   1.1  rearnsha 		case 1:
    472   1.1  rearnsha 			physical_end = 32 * 1024 * 1024;
    473   1.1  rearnsha 			break;
    474   1.1  rearnsha 		case 2:
    475   1.1  rearnsha 			physical_end = 64 * 1024 * 1024;
    476   1.1  rearnsha 			break;
    477   1.1  rearnsha 		case 3:
    478   1.1  rearnsha 			physical_end = 128 * 1024 * 1024;
    479   1.1  rearnsha 			break;
    480   1.1  rearnsha 		case 4:
    481   1.1  rearnsha 			physical_end = 256 * 1024 * 1024;
    482   1.1  rearnsha 			break;
    483   1.1  rearnsha 		default:
    484   1.1  rearnsha 			printf("CM_SDRAM retuns unknown value, using 16M\n");
    485   1.1  rearnsha 			physical_end = 16 * 1024 * 1024;
    486   1.1  rearnsha 			break;
    487   1.1  rearnsha 		}
    488   1.1  rearnsha 	}
    489   1.1  rearnsha #endif
    490   1.1  rearnsha 
    491   1.1  rearnsha 	physical_freeend = physical_end;
    492   1.1  rearnsha 	free_pages = (physical_end - physical_start) / NBPG;
    493   1.1  rearnsha 
    494   1.1  rearnsha 	/* Set up the bootconfig structure for the benefit of pmap.c */
    495   1.1  rearnsha 	bootconfig.dramblocks = 1;
    496   1.1  rearnsha 	bootconfig.dram[0].address = physical_start;
    497   1.1  rearnsha 	bootconfig.dram[0].pages = free_pages;
    498   1.1  rearnsha 
    499   1.1  rearnsha 	physmem = (physical_end - physical_start) / NBPG;
    500   1.1  rearnsha 
    501   1.1  rearnsha 	/* Tell the user about the memory */
    502   1.1  rearnsha 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    503   1.1  rearnsha 	    physical_start, physical_end - 1);
    504   1.1  rearnsha 
    505   1.1  rearnsha 	/*
    506   1.1  rearnsha 	 * Ok the kernel occupies the bottom of physical memory.
    507   1.1  rearnsha 	 * The first free page after the kernel can be found in
    508   1.1  rearnsha 	 * intbootinfo->bt_memavail
    509   1.1  rearnsha 	 * We now need to allocate some fixed page tables to get the kernel
    510   1.1  rearnsha 	 * going.
    511   1.1  rearnsha 	 * We allocate one page directory and a number page tables and store
    512   1.1  rearnsha 	 * the physical addresses in the kernel_pt_table array.
    513   1.1  rearnsha 	 *
    514   1.1  rearnsha 	 * Ok the next bit of physical allocation may look complex but it is
    515   1.1  rearnsha 	 * simple really. I have done it like this so that no memory gets
    516   1.1  rearnsha 	 * wasted during the allocation of various pages and tables that are
    517   1.1  rearnsha 	 * all different sizes.
    518   1.1  rearnsha 	 * The start addresses will be page aligned.
    519   1.1  rearnsha 	 * We allocate the kernel page directory on the first free 16KB boundry
    520   1.1  rearnsha 	 * we find.
    521   1.1  rearnsha 	 * We allocate the kernel page tables on the first 4KB boundry we find.
    522   1.1  rearnsha 	 * Since we allocate at least 3 L2 pagetables we know that we must
    523   1.1  rearnsha 	 * encounter at least one 16KB aligned address.
    524   1.1  rearnsha 	 */
    525   1.1  rearnsha 
    526   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    527   1.1  rearnsha 	printf("Allocating page tables\n");
    528   1.1  rearnsha #endif
    529   1.1  rearnsha 
    530   1.1  rearnsha 	/* Update the address of the first free 16KB chunk of physical memory */
    531   1.1  rearnsha         physical_freestart = ((uintptr_t) &end - KERNEL_TEXT_BASE + PGOFSET)
    532   1.1  rearnsha 	    & ~PGOFSET;
    533   1.1  rearnsha #if 0
    534   1.1  rearnsha         physical_freestart += (kernexec->a_syms + sizeof(int)
    535   1.1  rearnsha 		    + *(u_int *)((int)end + kernexec->a_syms + sizeof(int))
    536   1.1  rearnsha 		    + (NBPG - 1)) & ~(NBPG - 1);
    537   1.1  rearnsha #endif
    538   1.1  rearnsha 
    539   1.1  rearnsha 	free_pages -= (physical_freestart - physical_start) / NBPG;
    540   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    541   1.1  rearnsha 	printf("freestart = %#lx, free_pages = %d (%#x)\n",
    542   1.1  rearnsha 	       physical_freestart, free_pages, free_pages);
    543   1.1  rearnsha #endif
    544   1.1  rearnsha 
    545   1.1  rearnsha 	/* Define a macro to simplify memory allocation */
    546   1.1  rearnsha #define	valloc_pages(var, np)			\
    547   1.1  rearnsha 	alloc_pages((var).pv_pa, (np));		\
    548   1.1  rearnsha 	(var).pv_va = KERNEL_TEXT_BASE + (var).pv_pa - physical_start;
    549   1.1  rearnsha 
    550   1.1  rearnsha #define alloc_pages(var, np)			\
    551   1.1  rearnsha 	(var) = physical_freestart;		\
    552   1.1  rearnsha 	physical_freestart += ((np) * NBPG);	\
    553   1.1  rearnsha 	free_pages -= (np);			\
    554   1.1  rearnsha 	memset((char *)(var), 0, ((np) * NBPG));
    555   1.1  rearnsha 
    556   1.1  rearnsha 	loop1 = 0;
    557   1.1  rearnsha 	kernel_l1pt.pv_pa = 0;
    558   1.1  rearnsha 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    559   1.1  rearnsha 		/* Are we 16KB aligned for an L1 ? */
    560   1.1  rearnsha 		if ((physical_freestart & (PD_SIZE - 1)) == 0
    561   1.1  rearnsha 		    && kernel_l1pt.pv_pa == 0) {
    562   1.1  rearnsha 			valloc_pages(kernel_l1pt, PD_SIZE / NBPG);
    563   1.1  rearnsha 		} else {
    564   1.1  rearnsha 			alloc_pages(kernel_pt_table[loop1], PT_SIZE / NBPG);
    565   1.1  rearnsha 			++loop1;
    566   1.1  rearnsha 		}
    567   1.1  rearnsha 	}
    568   1.1  rearnsha 
    569   1.1  rearnsha 	/* This should never be able to happen but better confirm that. */
    570   1.1  rearnsha 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (PD_SIZE-1)) != 0)
    571   1.1  rearnsha 		panic("initarm: Failed to align the kernel page directory\n");
    572   1.1  rearnsha 
    573   1.1  rearnsha 	/*
    574   1.1  rearnsha 	 * Allocate a page for the system page mapped to V0x00000000
    575   1.1  rearnsha 	 * This page will just contain the system vectors and can be
    576   1.1  rearnsha 	 * shared by all processes.
    577   1.1  rearnsha 	 */
    578   1.1  rearnsha 	alloc_pages(systempage.pv_pa, 1);
    579   1.1  rearnsha 
    580   1.1  rearnsha 	/* Allocate a page for the page table to map kernel page tables*/
    581   1.1  rearnsha 	valloc_pages(kernel_ptpt, PT_SIZE / NBPG);
    582   1.1  rearnsha 
    583   1.1  rearnsha 	/* Allocate stacks for all modes */
    584   1.1  rearnsha 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    585   1.1  rearnsha 	valloc_pages(abtstack, ABT_STACK_SIZE);
    586   1.1  rearnsha 	valloc_pages(undstack, UND_STACK_SIZE);
    587   1.1  rearnsha 	valloc_pages(kernelstack, UPAGES);
    588   1.1  rearnsha 
    589   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    590   1.1  rearnsha 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va);
    591   1.1  rearnsha 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va);
    592   1.1  rearnsha 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va);
    593   1.1  rearnsha 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va);
    594   1.1  rearnsha #endif
    595   1.1  rearnsha 
    596   1.1  rearnsha 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG);
    597   1.1  rearnsha 
    598   1.1  rearnsha 	/*
    599   1.1  rearnsha 	 * Ok we have allocated physical pages for the primary kernel
    600   1.1  rearnsha 	 * page tables
    601   1.1  rearnsha 	 */
    602   1.1  rearnsha 
    603   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    604   1.1  rearnsha 	printf("Creating L1 page table at %#lx\n", kernel_l1pt.pv_pa);
    605   1.1  rearnsha #endif
    606   1.1  rearnsha 
    607   1.1  rearnsha 	/*
    608   1.1  rearnsha 	 * Now we start consturction of the L1 page table
    609   1.1  rearnsha 	 * We start by mapping the L2 page tables into the L1.
    610   1.1  rearnsha 	 * This means that we can replace L1 mappings later on if necessary
    611   1.1  rearnsha 	 */
    612   1.1  rearnsha 	l1pagetable = kernel_l1pt.pv_pa;
    613   1.1  rearnsha 
    614   1.1  rearnsha 	/* Map the L2 pages tables in the L1 page table */
    615  1.11   thorpej 	pmap_link_l2pt(l1pagetable, 0x00000000,
    616   1.1  rearnsha 	    kernel_pt_table[KERNEL_PT_SYS]);
    617  1.11   thorpej 	pmap_link_l2pt(l1pagetable, KERNEL_BASE,
    618   1.1  rearnsha 	    kernel_pt_table[KERNEL_PT_KERNEL]);
    619   1.1  rearnsha 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
    620  1.11   thorpej 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    621   1.1  rearnsha 		    kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    622  1.11   thorpej 	pmap_link_l2pt(l1pagetable, PROCESS_PAGE_TBLS_BASE,
    623   1.1  rearnsha 	    kernel_ptpt.pv_pa);
    624   1.1  rearnsha 
    625   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    626   1.1  rearnsha 	printf("Mapping kernel\n");
    627   1.1  rearnsha #endif
    628   1.1  rearnsha 
    629   1.1  rearnsha 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    630   1.1  rearnsha 	l2pagetable = kernel_pt_table[KERNEL_PT_KERNEL];
    631   1.1  rearnsha 
    632   1.1  rearnsha 	{
    633   1.1  rearnsha 		u_int logical;
    634   1.1  rearnsha 		size_t textsize = (uintptr_t) &etext - KERNEL_TEXT_BASE;
    635   1.1  rearnsha 		size_t totalsize = (uintptr_t) &end - KERNEL_TEXT_BASE;
    636   1.1  rearnsha 
    637   1.1  rearnsha 		/* Round down text size and round up total size
    638   1.1  rearnsha 		 */
    639   1.1  rearnsha 		textsize = textsize & ~PGOFSET;
    640   1.1  rearnsha 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    641  1.12   thorpej 		/* logical  = pmap_map_chunk(l1pagetable, l2pagetable,
    642  1.12   thorpej 		    KERNEL_BASE, physical_start, KERNEL_TEXT_BASE - KERNEL_BASE,
    643  1.12   thorpej 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE); */
    644  1.12   thorpej 		logical = pmap_map_chunk(l1pagetable, l2pagetable,
    645   1.1  rearnsha 		    KERNEL_TEXT_BASE, physical_start, textsize,
    646  1.12   thorpej 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    647  1.12   thorpej 		logical += pmap_map_chunk(l1pagetable, l2pagetable,
    648   1.1  rearnsha 		    KERNEL_TEXT_BASE + logical, physical_start + logical,
    649  1.12   thorpej 		    totalsize - textsize, VM_PROT_READ|VM_PROT_WRITE,
    650  1.12   thorpej 		    PTE_CACHE);
    651   1.1  rearnsha #if 0
    652  1.13   thorpej 		logical += pmap_map_chunk(l1pagetable, l2pagetable,
    653  1.13   thorpej 		    KERNEL_BASE + logical,
    654   1.1  rearnsha 		    physical_start + logical, kernexec->a_syms + sizeof(int)
    655   1.1  rearnsha 		    + *(u_int *)((int)end + kernexec->a_syms + sizeof(int)),
    656  1.12   thorpej 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    657   1.1  rearnsha #endif
    658   1.1  rearnsha 	}
    659   1.1  rearnsha 
    660   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    661   1.1  rearnsha 	printf("Constructing L2 page tables\n");
    662   1.1  rearnsha #endif
    663   1.1  rearnsha 
    664   1.1  rearnsha 	/* Map the boot arguments page */
    665   1.1  rearnsha #if 0
    666  1.10   thorpej 	pmap_map_entry(l2pagetable, intbootinfo.bt_vargp,
    667  1.10   thorpej 	    intbootinfo.bt_pargp, VM_PROT_READ, PTE_CACHE);
    668   1.1  rearnsha #endif
    669   1.1  rearnsha 
    670   1.1  rearnsha 	/* Map the stack pages */
    671  1.13   thorpej 	pmap_map_chunk(l1pagetable, l2pagetable, irqstack.pv_va,
    672  1.13   thorpej 	    irqstack.pv_pa, IRQ_STACK_SIZE * NBPG,
    673  1.13   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    674  1.13   thorpej 	pmap_map_chunk(l1pagetable, l2pagetable, abtstack.pv_va,
    675  1.13   thorpej 	    abtstack.pv_pa, ABT_STACK_SIZE * NBPG,
    676  1.13   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    677  1.13   thorpej 	pmap_map_chunk(l1pagetable, l2pagetable, undstack.pv_va,
    678  1.13   thorpej 	    undstack.pv_pa, UND_STACK_SIZE * NBPG,
    679  1.13   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    680  1.13   thorpej 	pmap_map_chunk(l1pagetable, l2pagetable, kernelstack.pv_va,
    681  1.13   thorpej 	    kernelstack.pv_pa, UPAGES * NBPG,
    682  1.13   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    683  1.13   thorpej 
    684  1.13   thorpej 	pmap_map_chunk(l1pagetable, l2pagetable, kernel_l1pt.pv_va,
    685  1.13   thorpej 	    kernel_l1pt.pv_pa, PD_SIZE,
    686  1.13   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    687   1.1  rearnsha 
    688   1.1  rearnsha 	/* Map the page table that maps the kernel pages */
    689  1.10   thorpej 	pmap_map_entry(l2pagetable, kernel_ptpt.pv_pa, kernel_ptpt.pv_pa,
    690  1.10   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    691   1.1  rearnsha 
    692   1.1  rearnsha 	/*
    693   1.1  rearnsha 	 * Map entries in the page table used to map PTE's
    694   1.1  rearnsha 	 * Basically every kernel page table gets mapped here
    695   1.1  rearnsha 	 */
    696   1.1  rearnsha 	/* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */
    697   1.1  rearnsha 	l2pagetable = kernel_ptpt.pv_pa;
    698  1.10   thorpej 	pmap_map_entry(l2pagetable, (KERNEL_BASE >> (PGSHIFT-2)),
    699  1.10   thorpej 	    kernel_pt_table[KERNEL_PT_KERNEL],
    700  1.10   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    701  1.10   thorpej 	pmap_map_entry(l2pagetable, (PROCESS_PAGE_TBLS_BASE >> (PGSHIFT-2)),
    702  1.10   thorpej 	    kernel_ptpt.pv_pa,
    703  1.10   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    704  1.10   thorpej 	pmap_map_entry(l2pagetable, (0x00000000 >> (PGSHIFT-2)),
    705  1.10   thorpej 	    kernel_pt_table[KERNEL_PT_SYS],
    706  1.10   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    707   1.1  rearnsha 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; ++loop)
    708  1.10   thorpej 		pmap_map_entry(l2pagetable, ((KERNEL_VM_BASE +
    709   1.1  rearnsha 		    (loop * 0x00400000)) >> (PGSHIFT-2)),
    710  1.10   thorpej 		    kernel_pt_table[KERNEL_PT_VMDATA + loop],
    711  1.10   thorpej 		    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    712   1.1  rearnsha 
    713   1.1  rearnsha 	/*
    714   1.1  rearnsha 	 * Map the system page in the kernel page table for the bottom 1Meg
    715   1.1  rearnsha 	 * of the virtual memory map.
    716   1.1  rearnsha 	 */
    717   1.1  rearnsha 	l2pagetable = kernel_pt_table[KERNEL_PT_SYS];
    718   1.1  rearnsha #if 1
    719   1.1  rearnsha 	/* MULTI-ICE requires that page 0 is NC/NB so that it can download
    720   1.1  rearnsha 	   the cache-clean code there.  */
    721  1.10   thorpej 	pmap_map_entry(l2pagetable, 0x00000000, systempage.pv_pa,
    722  1.10   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    723   1.1  rearnsha #else
    724  1.10   thorpej 	pmap_map_entry(l2pagetable, 0x00000000, systempage.pv_pa,
    725  1.10   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    726   1.1  rearnsha #endif
    727   1.1  rearnsha 	/* Map the core memory needed before autoconfig */
    728   1.1  rearnsha 	loop = 0;
    729   1.1  rearnsha 	while (l1_sec_table[loop].size) {
    730   1.1  rearnsha 		vm_size_t sz;
    731   1.1  rearnsha 
    732   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    733   1.1  rearnsha 		printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
    734   1.1  rearnsha 		    l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
    735   1.1  rearnsha 		    l1_sec_table[loop].va);
    736   1.1  rearnsha #endif
    737   1.1  rearnsha 		for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_SEC_SIZE)
    738   1.9   thorpej 			pmap_map_section(l1pagetable,
    739   1.9   thorpej 			    l1_sec_table[loop].va + sz,
    740   1.1  rearnsha 			    l1_sec_table[loop].pa + sz,
    741   1.9   thorpej 			    l1_sec_table[loop].prot,
    742   1.9   thorpej 			    l1_sec_table[loop].cache);
    743   1.1  rearnsha 		++loop;
    744   1.1  rearnsha 	}
    745   1.1  rearnsha 
    746   1.1  rearnsha 	/*
    747   1.1  rearnsha 	 * Now we have the real page tables in place so we can switch to them.
    748   1.1  rearnsha 	 * Once this is done we will be running with the REAL kernel page tables.
    749   1.1  rearnsha 	 */
    750   1.1  rearnsha 
    751   1.1  rearnsha 	/* Switch tables */
    752   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    753   1.1  rearnsha 	printf("freestart = %#lx, free_pages = %d (%#x)\n",
    754   1.1  rearnsha 	       physical_freestart, free_pages, free_pages);
    755   1.1  rearnsha 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    756   1.1  rearnsha #endif
    757   1.1  rearnsha 
    758   1.1  rearnsha 	setttb(kernel_l1pt.pv_pa);
    759   1.1  rearnsha 
    760   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    761   1.1  rearnsha 	printf("done!\n");
    762   1.1  rearnsha #endif
    763   1.1  rearnsha 
    764   1.1  rearnsha #ifdef PLCONSOLE
    765   1.1  rearnsha 	/*
    766   1.1  rearnsha 	 * The IFPGA registers have just moved.
    767   1.1  rearnsha 	 * Detach the diagnostic serial port and reattach at the new address.
    768   1.1  rearnsha 	 */
    769   1.1  rearnsha 	plcomcndetach();
    770   1.1  rearnsha #endif
    771   1.1  rearnsha 
    772   1.1  rearnsha 	/*
    773   1.1  rearnsha 	 * XXX this should only be done in main() but it useful to
    774   1.1  rearnsha 	 * have output earlier ...
    775   1.1  rearnsha 	 */
    776   1.1  rearnsha 	consinit();
    777   1.1  rearnsha 
    778   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    779   1.1  rearnsha 	printf("bootstrap done.\n");
    780   1.1  rearnsha #endif
    781   1.1  rearnsha 
    782   1.1  rearnsha 	/* Right set up the vectors at the bottom of page 0 */
    783   1.1  rearnsha 	memcpy((char *)0x00000000, page0, page0_end - page0);
    784   1.1  rearnsha 
    785   1.1  rearnsha 	/* We have modified a text page so sync the icache */
    786   1.7   thorpej 	cpu_icache_sync_all();
    787   1.1  rearnsha 
    788   1.1  rearnsha 	/*
    789   1.1  rearnsha 	 * Pages were allocated during the secondary bootstrap for the
    790   1.1  rearnsha 	 * stacks for different CPU modes.
    791   1.1  rearnsha 	 * We must now set the r13 registers in the different CPU modes to
    792   1.1  rearnsha 	 * point to these stacks.
    793   1.1  rearnsha 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    794   1.1  rearnsha 	 * of the stack memory.
    795   1.1  rearnsha 	 */
    796   1.1  rearnsha 	printf("init subsystems: stacks ");
    797   1.1  rearnsha 
    798   1.1  rearnsha 	set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG);
    799   1.1  rearnsha 	set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG);
    800   1.1  rearnsha 	set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG);
    801   1.1  rearnsha 
    802   1.1  rearnsha 	/*
    803   1.1  rearnsha 	 * Well we should set a data abort handler.
    804   1.1  rearnsha 	 * Once things get going this will change as we will need a proper handler.
    805   1.1  rearnsha 	 * Until then we will use a handler that just panics but tells us
    806   1.1  rearnsha 	 * why.
    807   1.1  rearnsha 	 * Initialisation of the vectors will just panic on a data abort.
    808   1.1  rearnsha 	 * This just fills in a slighly better one.
    809   1.1  rearnsha 	 */
    810   1.1  rearnsha 	printf("vectors ");
    811   1.1  rearnsha 	data_abort_handler_address = (u_int)data_abort_handler;
    812   1.1  rearnsha 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    813   1.1  rearnsha 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    814   1.1  rearnsha 
    815   1.1  rearnsha 	/* At last !
    816   1.1  rearnsha 	 * We now have the kernel in physical memory from the bottom upwards.
    817   1.1  rearnsha 	 * Kernel page tables are physically above this.
    818   1.1  rearnsha 	 * The kernel is mapped to KERNEL_TEXT_BASE
    819   1.1  rearnsha 	 * The kernel data PTs will handle the mapping of 0xf1000000-0xf3ffffff
    820   1.1  rearnsha 	 * The page tables are mapped to 0xefc00000
    821   1.1  rearnsha 	 */
    822   1.1  rearnsha 
    823   1.1  rearnsha 	/* Initialise the undefined instruction handlers */
    824   1.1  rearnsha 	printf("undefined ");
    825   1.1  rearnsha 	undefined_init();
    826   1.1  rearnsha 
    827   1.1  rearnsha 	/* Boot strap pmap telling it where the kernel page table is */
    828   1.1  rearnsha 	printf("pmap ");
    829   1.1  rearnsha 	pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt);
    830   1.1  rearnsha 
    831   1.1  rearnsha 	/* Setup the IRQ system */
    832   1.1  rearnsha 	printf("irq ");
    833   1.1  rearnsha 	irq_init();
    834   1.1  rearnsha 
    835   1.1  rearnsha 	printf("done.\n");
    836   1.1  rearnsha 
    837   1.1  rearnsha #ifdef IPKDB
    838   1.1  rearnsha 	/* Initialise ipkdb */
    839   1.1  rearnsha 	ipkdb_init();
    840   1.1  rearnsha 	if (boothowto & RB_KDB)
    841   1.1  rearnsha 		ipkdb_connect(0);
    842   1.1  rearnsha #endif
    843   1.1  rearnsha 
    844   1.1  rearnsha #ifdef DDB
    845   1.1  rearnsha 	db_machine_init();
    846   1.4   thorpej 
    847   1.4   thorpej 	/* Firmware doesn't load symbols. */
    848   1.4   thorpej 	ddb_init(0, NULL, NULL);
    849   1.1  rearnsha 
    850   1.1  rearnsha 	if (boothowto & RB_KDB)
    851   1.1  rearnsha 		Debugger();
    852   1.1  rearnsha #endif
    853   1.1  rearnsha 
    854   1.1  rearnsha 	/* We return the new stack pointer address */
    855   1.1  rearnsha 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    856   1.1  rearnsha }
    857   1.1  rearnsha 
    858   1.1  rearnsha void
    859   1.1  rearnsha process_kernel_args(args)
    860   1.1  rearnsha 	char *args;
    861   1.1  rearnsha {
    862   1.1  rearnsha 
    863   1.1  rearnsha 	boothowto = 0;
    864   1.1  rearnsha 
    865   1.1  rearnsha 	/* Make a local copy of the bootargs */
    866   1.1  rearnsha 	strncpy(bootargs, args, MAX_BOOT_STRING);
    867   1.1  rearnsha 
    868   1.1  rearnsha 	args = bootargs;
    869   1.1  rearnsha 	boot_file = bootargs;
    870   1.1  rearnsha 
    871   1.1  rearnsha 	/* Skip the kernel image filename */
    872   1.1  rearnsha 	while (*args != ' ' && *args != 0)
    873   1.1  rearnsha 		++args;
    874   1.1  rearnsha 
    875   1.1  rearnsha 	if (*args != 0)
    876   1.1  rearnsha 		*args++ = 0;
    877   1.1  rearnsha 
    878   1.1  rearnsha 	while (*args == ' ')
    879   1.1  rearnsha 		++args;
    880   1.1  rearnsha 
    881   1.1  rearnsha 	boot_args = args;
    882   1.1  rearnsha 
    883   1.1  rearnsha 	printf("bootfile: %s\n", boot_file);
    884   1.1  rearnsha 	printf("bootargs: %s\n", boot_args);
    885   1.1  rearnsha 
    886   1.1  rearnsha 	parse_mi_bootargs(boot_args);
    887   1.1  rearnsha }
    888   1.1  rearnsha 
    889   1.1  rearnsha void
    890   1.1  rearnsha consinit(void)
    891   1.1  rearnsha {
    892   1.1  rearnsha 	static int consinit_called = 0;
    893   1.1  rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
    894   1.1  rearnsha 	static struct bus_space plcom_bus_space;
    895   1.1  rearnsha #endif
    896   1.1  rearnsha #if 0
    897   1.1  rearnsha 	char *console = CONSDEVNAME;
    898   1.1  rearnsha #endif
    899   1.1  rearnsha 
    900   1.1  rearnsha 	if (consinit_called != 0)
    901   1.1  rearnsha 		return;
    902   1.1  rearnsha 
    903   1.1  rearnsha 	consinit_called = 1;
    904   1.1  rearnsha 
    905   1.1  rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
    906   1.1  rearnsha 	if (PLCOMCNUNIT == 0) {
    907   1.1  rearnsha 		ifpga_create_io_bs_tag(&plcom_bus_space,
    908   1.1  rearnsha 		    (void*)UART0_BOOT_BASE);
    909   1.1  rearnsha 		if (plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
    910   1.1  rearnsha 		    IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT))
    911   1.1  rearnsha 			panic("can't init serial console");
    912   1.1  rearnsha 		return;
    913   1.1  rearnsha 	} else if (PLCOMCNUNIT == 1) {
    914   1.1  rearnsha 		ifpga_create_io_bs_tag(&plcom_bus_space,
    915   1.1  rearnsha 		    (void*)UART0_BOOT_BASE);
    916   1.1  rearnsha 		if (plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
    917   1.1  rearnsha 		    IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT))
    918   1.1  rearnsha 			panic("can't init serial console");
    919   1.1  rearnsha 		return;
    920   1.1  rearnsha 	}
    921   1.1  rearnsha #endif
    922   1.1  rearnsha #if (NCOM > 0)
    923   1.1  rearnsha 	if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
    924   1.1  rearnsha 	    COM_FREQ, comcnmode))
    925   1.1  rearnsha 		panic("can't init serial console @%x", CONCOMADDR);
    926   1.1  rearnsha 	return;
    927   1.1  rearnsha #endif
    928   1.1  rearnsha 	panic("No serial console configured");
    929   1.1  rearnsha }
    930   1.1  rearnsha 
    931   1.1  rearnsha #if 0
    932   1.1  rearnsha static bus_space_handle_t kcom_base = (bus_space_handle_t) (DC21285_PCI_IO_VBASE + CONCOMADDR);
    933   1.1  rearnsha 
    934   1.1  rearnsha u_int8_t footbridge_bs_r_1(void *, bus_space_handle_t, bus_size_t);
    935   1.1  rearnsha void footbridge_bs_w_1(void *, bus_space_handle_t, bus_size_t, u_int8_t);
    936   1.1  rearnsha 
    937   1.1  rearnsha #define	KCOM_GETBYTE(r)		footbridge_bs_r_1(0, kcom_base, (r))
    938   1.1  rearnsha #define	KCOM_PUTBYTE(r,v)	footbridge_bs_w_1(0, kcom_base, (r), (v))
    939   1.1  rearnsha 
    940   1.1  rearnsha static int
    941   1.1  rearnsha kcomcngetc(dev_t dev)
    942   1.1  rearnsha {
    943   1.1  rearnsha 	int stat, c;
    944   1.1  rearnsha 
    945   1.1  rearnsha 	/* block until a character becomes available */
    946   1.1  rearnsha 	while (!ISSET(stat = KCOM_GETBYTE(com_lsr), LSR_RXRDY))
    947   1.1  rearnsha 		;
    948   1.1  rearnsha 
    949   1.1  rearnsha 	c = KCOM_GETBYTE(com_data);
    950   1.1  rearnsha 	stat = KCOM_GETBYTE(com_iir);
    951   1.1  rearnsha 	return c;
    952   1.1  rearnsha }
    953   1.1  rearnsha 
    954   1.1  rearnsha /*
    955   1.1  rearnsha  * Console kernel output character routine.
    956   1.1  rearnsha  */
    957   1.1  rearnsha static void
    958   1.1  rearnsha kcomcnputc(dev_t dev, int c)
    959   1.1  rearnsha {
    960   1.1  rearnsha 	int timo;
    961   1.1  rearnsha 
    962   1.1  rearnsha 	/* wait for any pending transmission to finish */
    963   1.1  rearnsha 	timo = 150000;
    964   1.1  rearnsha 	while (!ISSET(KCOM_GETBYTE(com_lsr), LSR_TXRDY) && --timo)
    965   1.1  rearnsha 		continue;
    966   1.1  rearnsha 
    967   1.1  rearnsha 	KCOM_PUTBYTE(com_data, c);
    968   1.1  rearnsha 
    969   1.1  rearnsha 	/* wait for this transmission to complete */
    970   1.1  rearnsha 	timo = 1500000;
    971   1.1  rearnsha 	while (!ISSET(KCOM_GETBYTE(com_lsr), LSR_TXRDY) && --timo)
    972   1.1  rearnsha 		continue;
    973   1.1  rearnsha }
    974   1.1  rearnsha 
    975   1.1  rearnsha static void
    976   1.1  rearnsha kcomcnpollc(dev_t dev, int on)
    977   1.1  rearnsha {
    978   1.1  rearnsha }
    979   1.1  rearnsha 
    980   1.1  rearnsha struct consdev kcomcons = {
    981   1.1  rearnsha 	NULL, NULL, kcomcngetc, kcomcnputc, kcomcnpollc, NULL,
    982   1.1  rearnsha 	NODEV, CN_NORMAL
    983   1.1  rearnsha };
    984   1.1  rearnsha 
    985   1.1  rearnsha #endif
    986