Home | History | Annotate | Line # | Download | only in integrator
integrator_machdep.c revision 1.23
      1  1.23  rearnsha /*	$NetBSD: integrator_machdep.c,v 1.23 2002/07/08 16:20:07 rearnsha Exp $	*/
      2   1.1  rearnsha 
      3   1.1  rearnsha /*
      4  1.23  rearnsha  * Copyright (c) 2001,2002 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.23  rearnsha  * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND
     20  1.23  rearnsha  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.23  rearnsha  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.23  rearnsha  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ARM LTD
     23  1.23  rearnsha  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.23  rearnsha  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.23  rearnsha  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.23  rearnsha  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.23  rearnsha  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.23  rearnsha  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.23  rearnsha  * POSSIBILITY OF SUCH DAMAGE.
     30  1.23  rearnsha  */
     31  1.23  rearnsha 
     32  1.23  rearnsha /*
     33   1.1  rearnsha  * Copyright (c) 1997,1998 Mark Brinicombe.
     34   1.1  rearnsha  * Copyright (c) 1997,1998 Causality Limited.
     35   1.1  rearnsha  * All rights reserved.
     36   1.1  rearnsha  *
     37   1.1  rearnsha  * Redistribution and use in source and binary forms, with or without
     38   1.1  rearnsha  * modification, are permitted provided that the following conditions
     39   1.1  rearnsha  * are met:
     40   1.1  rearnsha  * 1. Redistributions of source code must retain the above copyright
     41   1.1  rearnsha  *    notice, this list of conditions and the following disclaimer.
     42   1.1  rearnsha  * 2. Redistributions in binary form must reproduce the above copyright
     43   1.1  rearnsha  *    notice, this list of conditions and the following disclaimer in the
     44   1.1  rearnsha  *    documentation and/or other materials provided with the distribution.
     45   1.1  rearnsha  * 3. All advertising materials mentioning features or use of this software
     46   1.1  rearnsha  *    must display the following acknowledgement:
     47   1.1  rearnsha  *	This product includes software developed by Mark Brinicombe
     48   1.1  rearnsha  *	for the NetBSD Project.
     49   1.1  rearnsha  * 4. The name of the company nor the name of the author may be used to
     50   1.1  rearnsha  *    endorse or promote products derived from this software without specific
     51   1.1  rearnsha  *    prior written permission.
     52   1.1  rearnsha  *
     53   1.1  rearnsha  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     54   1.1  rearnsha  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     55   1.1  rearnsha  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     56   1.1  rearnsha  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     57   1.1  rearnsha  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     58   1.1  rearnsha  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     59   1.1  rearnsha  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     60   1.1  rearnsha  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     61   1.1  rearnsha  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     62   1.1  rearnsha  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     63   1.1  rearnsha  * SUCH DAMAGE.
     64   1.1  rearnsha  *
     65   1.1  rearnsha  * Machine dependant functions for kernel setup for integrator board
     66   1.1  rearnsha  *
     67   1.1  rearnsha  * Created      : 24/11/97
     68   1.1  rearnsha  */
     69   1.1  rearnsha 
     70   1.1  rearnsha #include "opt_ddb.h"
     71   1.1  rearnsha #include "opt_pmap_debug.h"
     72   1.1  rearnsha 
     73   1.1  rearnsha #include <sys/param.h>
     74   1.1  rearnsha #include <sys/device.h>
     75   1.1  rearnsha #include <sys/systm.h>
     76   1.1  rearnsha #include <sys/kernel.h>
     77   1.1  rearnsha #include <sys/exec.h>
     78   1.1  rearnsha #include <sys/proc.h>
     79   1.1  rearnsha #include <sys/msgbuf.h>
     80   1.1  rearnsha #include <sys/reboot.h>
     81   1.1  rearnsha #include <sys/termios.h>
     82   1.1  rearnsha 
     83   1.1  rearnsha #include <dev/cons.h>
     84   1.1  rearnsha 
     85   1.1  rearnsha #include <machine/db_machdep.h>
     86   1.1  rearnsha #include <ddb/db_sym.h>
     87   1.1  rearnsha #include <ddb/db_extern.h>
     88   1.1  rearnsha 
     89   1.1  rearnsha #include <machine/bootconfig.h>
     90   1.1  rearnsha #include <machine/bus.h>
     91   1.1  rearnsha #include <machine/cpu.h>
     92   1.1  rearnsha #include <machine/frame.h>
     93   1.1  rearnsha #include <machine/intr.h>
     94   1.8   thorpej #include <evbarm/ifpga/irqhandler.h>	/* XXX XXX XXX */
     95   1.6   thorpej #include <arm/undefined.h>
     96   1.1  rearnsha 
     97  1.23  rearnsha #include <arm/arm32/machdep.h>
     98  1.23  rearnsha 
     99   1.1  rearnsha #include <evbarm/integrator/integrator_boot.h>
    100   1.1  rearnsha 
    101   1.1  rearnsha #include "opt_ipkdb.h"
    102   1.1  rearnsha #include "pci.h"
    103   1.1  rearnsha 
    104   1.1  rearnsha void ifpga_reset(void) __attribute__((noreturn));
    105   1.1  rearnsha /*
    106   1.1  rearnsha  * Address to call from cpu_reset() to reset the machine.
    107   1.1  rearnsha  * This is machine architecture dependant as it varies depending
    108   1.1  rearnsha  * on where the ROM appears when you turn the MMU off.
    109   1.1  rearnsha  */
    110   1.1  rearnsha 
    111   1.1  rearnsha u_int cpu_reset_address = (u_int) ifpga_reset;
    112   1.1  rearnsha 
    113   1.1  rearnsha /* Define various stack sizes in pages */
    114   1.1  rearnsha #define IRQ_STACK_SIZE	1
    115   1.1  rearnsha #define ABT_STACK_SIZE	1
    116   1.1  rearnsha #ifdef IPKDB
    117   1.1  rearnsha #define UND_STACK_SIZE	2
    118   1.1  rearnsha #else
    119   1.1  rearnsha #define UND_STACK_SIZE	1
    120   1.1  rearnsha #endif
    121   1.1  rearnsha 
    122   1.1  rearnsha BootConfig bootconfig;		/* Boot config storage */
    123   1.1  rearnsha char *boot_args = NULL;
    124   1.1  rearnsha char *boot_file = NULL;
    125   1.1  rearnsha 
    126   1.1  rearnsha vm_offset_t physical_start;
    127   1.1  rearnsha vm_offset_t physical_freestart;
    128   1.1  rearnsha vm_offset_t physical_freeend;
    129   1.1  rearnsha vm_offset_t physical_end;
    130   1.1  rearnsha u_int free_pages;
    131   1.1  rearnsha vm_offset_t pagetables_start;
    132   1.1  rearnsha int physmem = 0;
    133   1.1  rearnsha 
    134   1.1  rearnsha /*int debug_flags;*/
    135   1.1  rearnsha #ifndef PMAP_STATIC_L1S
    136   1.1  rearnsha int max_processes = 64;			/* Default number */
    137   1.1  rearnsha #endif	/* !PMAP_STATIC_L1S */
    138   1.1  rearnsha 
    139   1.1  rearnsha /* Physical and virtual addresses for some global pages */
    140   1.1  rearnsha pv_addr_t systempage;
    141   1.1  rearnsha pv_addr_t irqstack;
    142   1.1  rearnsha pv_addr_t undstack;
    143   1.1  rearnsha pv_addr_t abtstack;
    144   1.1  rearnsha pv_addr_t kernelstack;
    145   1.1  rearnsha 
    146   1.1  rearnsha vm_offset_t msgbufphys;
    147   1.1  rearnsha 
    148   1.1  rearnsha extern u_int data_abort_handler_address;
    149   1.1  rearnsha extern u_int prefetch_abort_handler_address;
    150   1.1  rearnsha extern u_int undefined_handler_address;
    151   1.1  rearnsha 
    152   1.1  rearnsha #ifdef PMAP_DEBUG
    153   1.1  rearnsha extern int pmap_debug_level;
    154   1.1  rearnsha #endif
    155   1.1  rearnsha 
    156  1.23  rearnsha #define KERNEL_PT_SYS		0	/* L2 table for mapping zero page */
    157  1.23  rearnsha 
    158  1.23  rearnsha #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
    159  1.23  rearnsha #define	KERNEL_PT_KERNEL_NUM	2
    160  1.23  rearnsha 					/* L2 tables for mapping kernel VM */
    161  1.23  rearnsha #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    162  1.17     chris #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    163   1.1  rearnsha #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    164   1.1  rearnsha 
    165  1.14   thorpej pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    166   1.1  rearnsha 
    167   1.1  rearnsha struct user *proc0paddr;
    168   1.1  rearnsha 
    169   1.1  rearnsha /* Prototypes */
    170   1.1  rearnsha 
    171  1.23  rearnsha static void	integrator_sdram_bounds	(paddr_t *, psize_t *);
    172   1.1  rearnsha 
    173  1.23  rearnsha void	consinit(void);
    174   1.1  rearnsha 
    175   1.1  rearnsha /* A load of console goo. */
    176   1.1  rearnsha #include "vga.h"
    177  1.23  rearnsha #if NVGA > 0
    178   1.1  rearnsha #include <dev/ic/mc6845reg.h>
    179   1.1  rearnsha #include <dev/ic/pcdisplayvar.h>
    180   1.1  rearnsha #include <dev/ic/vgareg.h>
    181   1.1  rearnsha #include <dev/ic/vgavar.h>
    182   1.1  rearnsha #endif
    183   1.1  rearnsha 
    184   1.1  rearnsha #include "pckbc.h"
    185  1.23  rearnsha #if NPCKBC > 0
    186   1.1  rearnsha #include <dev/ic/i8042reg.h>
    187   1.1  rearnsha #include <dev/ic/pckbcvar.h>
    188   1.1  rearnsha #endif
    189   1.1  rearnsha 
    190   1.1  rearnsha #include "com.h"
    191  1.23  rearnsha #if NCOM > 0
    192   1.1  rearnsha #include <dev/ic/comreg.h>
    193   1.1  rearnsha #include <dev/ic/comvar.h>
    194   1.1  rearnsha #ifndef CONCOMADDR
    195   1.1  rearnsha #define CONCOMADDR 0x3f8
    196   1.1  rearnsha #endif
    197   1.1  rearnsha #endif
    198   1.1  rearnsha 
    199  1.23  rearnsha /*
    200  1.23  rearnsha  * Define the default console speed for the board.  This is generally
    201  1.23  rearnsha  * what the firmware provided with the board defaults to.
    202  1.23  rearnsha  */
    203   1.1  rearnsha #define CONSPEED B115200
    204   1.1  rearnsha #ifndef CONSPEED
    205   1.1  rearnsha #define CONSPEED B9600	/* TTYDEF_SPEED */
    206   1.1  rearnsha #endif
    207   1.1  rearnsha #ifndef CONMODE
    208   1.1  rearnsha #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    209   1.1  rearnsha #endif
    210   1.1  rearnsha 
    211   1.1  rearnsha int comcnspeed = CONSPEED;
    212   1.1  rearnsha int comcnmode = CONMODE;
    213   1.1  rearnsha 
    214   1.1  rearnsha #include "plcom.h"
    215   1.1  rearnsha #if (NPLCOM > 0)
    216   1.1  rearnsha #include <evbarm/dev/plcomreg.h>
    217   1.1  rearnsha #include <evbarm/dev/plcomvar.h>
    218   1.1  rearnsha 
    219   1.1  rearnsha #include <evbarm/ifpga/ifpgamem.h>
    220   1.1  rearnsha #include <evbarm/ifpga/ifpgareg.h>
    221   1.1  rearnsha #include <evbarm/ifpga/ifpgavar.h>
    222   1.1  rearnsha #endif
    223   1.1  rearnsha 
    224   1.1  rearnsha #ifndef CONSDEVNAME
    225   1.1  rearnsha #define CONSDEVNAME "plcom"
    226   1.1  rearnsha #endif
    227   1.1  rearnsha 
    228   1.1  rearnsha #ifndef PLCONSPEED
    229   1.1  rearnsha #define PLCONSPEED B38400
    230   1.1  rearnsha #endif
    231   1.1  rearnsha #ifndef PLCONMODE
    232   1.1  rearnsha #define PLCONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    233   1.1  rearnsha #endif
    234   1.1  rearnsha #ifndef PLCOMCNUNIT
    235   1.1  rearnsha #define PLCOMCNUNIT -1
    236   1.1  rearnsha #endif
    237   1.1  rearnsha 
    238   1.1  rearnsha int plcomcnspeed = PLCONSPEED;
    239   1.1  rearnsha int plcomcnmode = PLCONMODE;
    240   1.1  rearnsha 
    241   1.1  rearnsha #if 0
    242   1.1  rearnsha extern struct consdev kcomcons;
    243   1.1  rearnsha static void kcomcnputc(dev_t, int);
    244   1.1  rearnsha #endif
    245   1.1  rearnsha 
    246   1.1  rearnsha /*
    247   1.1  rearnsha  * void cpu_reboot(int howto, char *bootstr)
    248   1.1  rearnsha  *
    249   1.1  rearnsha  * Reboots the system
    250   1.1  rearnsha  *
    251   1.1  rearnsha  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    252   1.1  rearnsha  * then reset the CPU.
    253   1.1  rearnsha  */
    254   1.1  rearnsha void
    255  1.23  rearnsha cpu_reboot(int howto, 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 
    278   1.1  rearnsha 	/*
    279   1.1  rearnsha 	 * If RB_NOSYNC was not specified sync the discs.
    280  1.23  rearnsha 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    281  1.23  rearnsha 	 * unmount.  It looks like syslogd is getting woken up only to find
    282  1.23  rearnsha 	 * that it cannot page part of the binary in as the filesystem has
    283  1.23  rearnsha 	 * 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.23  rearnsha 	vaddr_t	va;
    318  1.23  rearnsha 	vaddr_t	pa;
    319  1.23  rearnsha 	vsize_t	size;
    320  1.23  rearnsha 	vm_prot_t prot;
    321  1.23  rearnsha 	int cache;
    322   1.1  rearnsha } l1_sec_table[] = {
    323   1.1  rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
    324  1.23  rearnsha 	{
    325  1.23  rearnsha 		UART0_BOOT_BASE,
    326  1.23  rearnsha 		IFPGA_IO_BASE + IFPGA_UART0,
    327  1.23  rearnsha 		1024 * 1024,
    328  1.23  rearnsha 		VM_PROT_READ|VM_PROT_WRITE,
    329  1.23  rearnsha 		PTE_NOCACHE
    330  1.23  rearnsha 	},
    331  1.23  rearnsha 
    332  1.23  rearnsha 	{
    333  1.23  rearnsha 		UART1_BOOT_BASE,
    334  1.23  rearnsha 		IFPGA_IO_BASE + IFPGA_UART1,
    335  1.23  rearnsha 		1024 * 1024,
    336  1.23  rearnsha 		VM_PROT_READ|VM_PROT_WRITE,
    337  1.23  rearnsha 		PTE_NOCACHE
    338  1.23  rearnsha 	},
    339   1.1  rearnsha #endif
    340   1.1  rearnsha #if NPCI > 0
    341  1.23  rearnsha 	{
    342  1.23  rearnsha 		IFPGA_PCI_IO_VBASE,
    343  1.23  rearnsha 		IFPGA_PCI_IO_BASE,
    344  1.23  rearnsha 		IFPGA_PCI_IO_VSIZE,
    345  1.23  rearnsha 		VM_PROT_READ|VM_PROT_WRITE,
    346  1.23  rearnsha 		PTE_NOCACHE
    347  1.23  rearnsha 	},
    348  1.23  rearnsha 
    349  1.23  rearnsha 	{
    350  1.23  rearnsha 		IFPGA_PCI_CONF_VBASE,
    351  1.23  rearnsha 		IFPGA_PCI_CONF_BASE,
    352  1.23  rearnsha 		IFPGA_PCI_CONF_VSIZE,
    353  1.23  rearnsha 		VM_PROT_READ|VM_PROT_WRITE,
    354  1.23  rearnsha 		PTE_NOCACHE },
    355   1.1  rearnsha #endif
    356   1.1  rearnsha 
    357  1.23  rearnsha 	{
    358  1.23  rearnsha 		0,
    359  1.23  rearnsha 		0,
    360  1.23  rearnsha 		0,
    361  1.23  rearnsha 		0,
    362  1.23  rearnsha 		0
    363  1.23  rearnsha 	}
    364   1.1  rearnsha };
    365   1.1  rearnsha 
    366   1.1  rearnsha /*
    367  1.23  rearnsha  * u_int initarm(...)
    368   1.1  rearnsha  *
    369   1.1  rearnsha  * Initial entry point on startup. This gets called before main() is
    370   1.1  rearnsha  * entered.
    371   1.1  rearnsha  * It should be responsible for setting up everything that must be
    372   1.1  rearnsha  * in place when main is called.
    373   1.1  rearnsha  * This includes
    374   1.1  rearnsha  *   Taking a copy of the boot configuration structure.
    375   1.1  rearnsha  *   Initialising the physical console so characters can be printed.
    376   1.1  rearnsha  *   Setting up page tables for the kernel
    377   1.1  rearnsha  *   Relocating the kernel to the bottom of physical memory
    378   1.1  rearnsha  */
    379   1.1  rearnsha 
    380   1.1  rearnsha u_int
    381  1.23  rearnsha initarm(void *arg)
    382   1.1  rearnsha {
    383   1.1  rearnsha 	int loop;
    384   1.1  rearnsha 	int loop1;
    385   1.1  rearnsha 	u_int l1pagetable;
    386   1.1  rearnsha 	extern int etext asm ("_etext");
    387   1.1  rearnsha 	extern int end asm ("_end");
    388   1.1  rearnsha 	pv_addr_t kernel_l1pt;
    389   1.1  rearnsha 	pv_addr_t kernel_ptpt;
    390  1.23  rearnsha 	paddr_t memstart;
    391  1.23  rearnsha 	psize_t memsize;
    392   1.1  rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
    393   1.1  rearnsha 	static struct bus_space plcom_bus_space;
    394   1.1  rearnsha #endif
    395   1.1  rearnsha 
    396   1.1  rearnsha 	/*
    397   1.1  rearnsha 	 * Heads up ... Setup the CPU / MMU / TLB functions
    398   1.1  rearnsha 	 */
    399   1.1  rearnsha 	if (set_cpufuncs())
    400   1.1  rearnsha 		panic("cpu not recognized!");
    401   1.1  rearnsha 
    402   1.1  rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
    403   1.1  rearnsha 	/*
    404   1.1  rearnsha 	 * Initialise the diagnostic serial console
    405   1.1  rearnsha 	 * This allows a means of generating output during initarm().
    406   1.1  rearnsha 	 * Once all the memory map changes are complete we can call consinit()
    407   1.1  rearnsha 	 * and not have to worry about things moving.
    408   1.1  rearnsha 	 */
    409   1.1  rearnsha 
    410   1.1  rearnsha 	if (PLCOMCNUNIT == 0) {
    411   1.1  rearnsha 		ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd600000);
    412   1.1  rearnsha 		plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
    413   1.1  rearnsha 		    IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
    414   1.1  rearnsha 	} else if (PLCOMCNUNIT == 1) {
    415   1.1  rearnsha 		ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd700000);
    416   1.1  rearnsha 		plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
    417   1.1  rearnsha 		    IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT);
    418   1.1  rearnsha 	}
    419   1.1  rearnsha #endif
    420   1.1  rearnsha 
    421   1.1  rearnsha 	/* Talk to the user */
    422  1.23  rearnsha 	printf("\nNetBSD/evbarm (Integrator) booting ...\n");
    423   1.1  rearnsha 
    424   1.1  rearnsha 	/*
    425   1.1  rearnsha 	 * Ok we have the following memory map
    426   1.1  rearnsha 	 *
    427  1.23  rearnsha 	 * XXX NO WE DON'T
    428  1.23  rearnsha 	 *
    429   1.1  rearnsha 	 * virtual address == physical address apart from the areas:
    430   1.1  rearnsha 	 * 0x00000000 -> 0x000fffff which is mapped to
    431   1.1  rearnsha 	 * top 1MB of physical memory
    432   1.1  rearnsha 	 * 0x00100000 -> 0x0fffffff which is mapped to
    433   1.1  rearnsha 	 * physical addresses 0x00100000 -> 0x0fffffff
    434   1.1  rearnsha 	 * 0x10000000 -> 0x1fffffff which is mapped to
    435   1.1  rearnsha 	 * physical addresses 0x00000000 -> 0x0fffffff
    436   1.1  rearnsha 	 * 0x20000000 -> 0xefffffff which is mapped to
    437   1.1  rearnsha 	 * physical addresses 0x20000000 -> 0xefffffff
    438   1.1  rearnsha 	 * 0xf0000000 -> 0xf03fffff which is mapped to
    439   1.1  rearnsha 	 * physical addresses 0x00000000 -> 0x003fffff
    440   1.1  rearnsha 	 *
    441   1.1  rearnsha 	 * This means that the kernel is mapped suitably for continuing
    442   1.1  rearnsha 	 * execution, all I/O is mapped 1:1 virtual to physical and
    443   1.1  rearnsha 	 * physical memory is accessible.
    444   1.1  rearnsha 	 *
    445   1.1  rearnsha 	 * The initarm() has the responsibility for creating the kernel
    446   1.1  rearnsha 	 * page tables.
    447   1.1  rearnsha 	 * It must also set up various memory pointers that are used
    448   1.1  rearnsha 	 * by pmap etc.
    449   1.1  rearnsha 	 */
    450   1.1  rearnsha 
    451   1.1  rearnsha 	/*
    452  1.23  rearnsha 	 * Fetch the SDRAM start/size from the CM configuration registers.
    453   1.1  rearnsha 	 */
    454  1.23  rearnsha 	integrator_sdram_bounds(&memstart, &memsize);
    455   1.1  rearnsha 
    456   1.1  rearnsha 	printf("initarm: Configuring system ...\n");
    457   1.1  rearnsha 
    458  1.23  rearnsha 	/* Fake bootconfig structure for the benefit of pmap.c */
    459  1.23  rearnsha 	/* XXX must make the memory description h/w independent */
    460  1.23  rearnsha 	bootconfig.dramblocks = 1;
    461  1.23  rearnsha 	bootconfig.dram[0].address = memstart;
    462  1.23  rearnsha 	bootconfig.dram[0].pages = memsize / NBPG;
    463  1.23  rearnsha 
    464   1.1  rearnsha 	/*
    465   1.1  rearnsha 	 * Set up the variables that define the availablilty of
    466  1.23  rearnsha 	 * physical memory.  For now, we're going to set
    467  1.23  rearnsha 	 * physical_freestart to 0x00200000 (where the kernel
    468  1.23  rearnsha 	 * was loaded), and allocate the memory we need downwards.
    469  1.23  rearnsha 	 * If we get too close to the L1 table that we set up, we
    470  1.23  rearnsha 	 * will panic.  We will update physical_freestart and
    471  1.23  rearnsha 	 * physical_freeend later to reflect what pmap_bootstrap()
    472  1.23  rearnsha 	 * wants to see.
    473  1.23  rearnsha 	 *
    474  1.23  rearnsha 	 * XXX pmap_bootstrap() needs an enema.
    475   1.1  rearnsha 	 */
    476  1.23  rearnsha 	physical_start = bootconfig.dram[0].address;
    477  1.23  rearnsha 	physical_end = physical_start + (bootconfig.dram[0].pages * NBPG);
    478   1.1  rearnsha 
    479  1.23  rearnsha 	physical_freestart = 0x00009000UL;
    480  1.23  rearnsha 	physical_freeend = 0x00200000UL;
    481   1.1  rearnsha 
    482   1.1  rearnsha 	physmem = (physical_end - physical_start) / NBPG;
    483   1.1  rearnsha 
    484   1.1  rearnsha 	/* Tell the user about the memory */
    485   1.1  rearnsha 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    486   1.1  rearnsha 	    physical_start, physical_end - 1);
    487   1.1  rearnsha 
    488   1.1  rearnsha 	/*
    489  1.23  rearnsha 	 * Okay, the kernel starts 2MB in from the bottom of physical
    490  1.23  rearnsha 	 * memory.  We are going to allocate our bootstrap pages downwards
    491  1.23  rearnsha 	 * from there.
    492   1.1  rearnsha 	 *
    493  1.23  rearnsha 	 * We need to allocate some fixed page tables to get the kernel
    494  1.23  rearnsha 	 * going.  We allocate one page directory and a number of page
    495  1.23  rearnsha 	 * tables and store the physical addresses in the kernel_pt_table
    496  1.23  rearnsha 	 * array.
    497  1.23  rearnsha 	 *
    498  1.23  rearnsha 	 * The kernel page directory must be on a 16K boundary.  The page
    499  1.23  rearnsha 	 * tables must be on 4K bounaries.  What we do is allocate the
    500  1.23  rearnsha 	 * page directory on the first 16K boundary that we encounter, and
    501  1.23  rearnsha 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    502  1.23  rearnsha 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    503  1.23  rearnsha 	 * least one 16K aligned region.
    504   1.1  rearnsha 	 */
    505   1.1  rearnsha 
    506   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    507   1.1  rearnsha 	printf("Allocating page tables\n");
    508   1.1  rearnsha #endif
    509   1.1  rearnsha 
    510  1.23  rearnsha 	free_pages = (physical_freeend - physical_freestart) / NBPG;
    511   1.1  rearnsha 
    512   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    513  1.23  rearnsha 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    514   1.1  rearnsha 	       physical_freestart, free_pages, free_pages);
    515   1.1  rearnsha #endif
    516   1.1  rearnsha 
    517   1.1  rearnsha 	/* Define a macro to simplify memory allocation */
    518  1.23  rearnsha #define	valloc_pages(var, np)				\
    519  1.23  rearnsha 	alloc_pages((var).pv_pa, (np));			\
    520  1.23  rearnsha 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    521  1.23  rearnsha 
    522  1.23  rearnsha #define alloc_pages(var, np)				\
    523  1.23  rearnsha 	physical_freeend -= ((np) * NBPG);		\
    524  1.23  rearnsha 	if (physical_freeend < physical_freestart)	\
    525  1.23  rearnsha 		panic("initarm: out of memory");	\
    526  1.23  rearnsha 	(var) = physical_freeend;			\
    527  1.23  rearnsha 	free_pages -= (np);				\
    528   1.1  rearnsha 	memset((char *)(var), 0, ((np) * NBPG));
    529   1.1  rearnsha 
    530   1.1  rearnsha 	loop1 = 0;
    531   1.1  rearnsha 	kernel_l1pt.pv_pa = 0;
    532   1.1  rearnsha 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    533   1.1  rearnsha 		/* Are we 16KB aligned for an L1 ? */
    534  1.23  rearnsha 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    535   1.1  rearnsha 		    && kernel_l1pt.pv_pa == 0) {
    536  1.21   thorpej 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / NBPG);
    537   1.1  rearnsha 		} else {
    538  1.14   thorpej 			alloc_pages(kernel_pt_table[loop1].pv_pa,
    539  1.21   thorpej 			    L2_TABLE_SIZE / NBPG);
    540  1.14   thorpej 			kernel_pt_table[loop1].pv_va =
    541  1.14   thorpej 			    kernel_pt_table[loop1].pv_pa;
    542  1.23  rearnsha 			++loop1;
    543   1.1  rearnsha 		}
    544   1.1  rearnsha 	}
    545   1.1  rearnsha 
    546   1.1  rearnsha 	/* This should never be able to happen but better confirm that. */
    547  1.21   thorpej 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    548   1.1  rearnsha 		panic("initarm: Failed to align the kernel page directory\n");
    549   1.1  rearnsha 
    550   1.1  rearnsha 	/*
    551   1.1  rearnsha 	 * Allocate a page for the system page mapped to V0x00000000
    552   1.1  rearnsha 	 * This page will just contain the system vectors and can be
    553   1.1  rearnsha 	 * shared by all processes.
    554   1.1  rearnsha 	 */
    555   1.1  rearnsha 	alloc_pages(systempage.pv_pa, 1);
    556   1.1  rearnsha 
    557  1.23  rearnsha 	/* Allocate a page for the page table to map kernel page tables. */
    558  1.21   thorpej 	valloc_pages(kernel_ptpt, L2_TABLE_SIZE / NBPG);
    559   1.1  rearnsha 
    560   1.1  rearnsha 	/* Allocate stacks for all modes */
    561   1.1  rearnsha 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    562   1.1  rearnsha 	valloc_pages(abtstack, ABT_STACK_SIZE);
    563   1.1  rearnsha 	valloc_pages(undstack, UND_STACK_SIZE);
    564   1.1  rearnsha 	valloc_pages(kernelstack, UPAGES);
    565   1.1  rearnsha 
    566   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    567  1.23  rearnsha 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    568  1.23  rearnsha 	    irqstack.pv_va);
    569  1.23  rearnsha 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    570  1.23  rearnsha 	    abtstack.pv_va);
    571  1.23  rearnsha 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    572  1.23  rearnsha 	    undstack.pv_va);
    573  1.23  rearnsha 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    574  1.23  rearnsha 	    kernelstack.pv_va);
    575   1.1  rearnsha #endif
    576   1.1  rearnsha 
    577   1.1  rearnsha 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / NBPG);
    578   1.1  rearnsha 
    579   1.1  rearnsha 	/*
    580   1.1  rearnsha 	 * Ok we have allocated physical pages for the primary kernel
    581   1.1  rearnsha 	 * page tables
    582   1.1  rearnsha 	 */
    583   1.1  rearnsha 
    584   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    585  1.23  rearnsha 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    586   1.1  rearnsha #endif
    587   1.1  rearnsha 
    588   1.1  rearnsha 	/*
    589  1.23  rearnsha 	 * Now we start construction of the L1 page table
    590   1.1  rearnsha 	 * We start by mapping the L2 page tables into the L1.
    591   1.1  rearnsha 	 * This means that we can replace L1 mappings later on if necessary
    592   1.1  rearnsha 	 */
    593   1.1  rearnsha 	l1pagetable = kernel_l1pt.pv_pa;
    594   1.1  rearnsha 
    595   1.1  rearnsha 	/* Map the L2 pages tables in the L1 page table */
    596  1.11   thorpej 	pmap_link_l2pt(l1pagetable, 0x00000000,
    597  1.14   thorpej 	    &kernel_pt_table[KERNEL_PT_SYS]);
    598  1.23  rearnsha 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    599  1.23  rearnsha 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    600  1.23  rearnsha 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    601  1.23  rearnsha 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    602  1.11   thorpej 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    603  1.14   thorpej 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    604  1.23  rearnsha 	pmap_link_l2pt(l1pagetable, PTE_BASE, &kernel_ptpt);
    605  1.17     chris 
    606  1.17     chris 	/* update the top of the kernel VM */
    607  1.19   thorpej 	pmap_curmaxkvaddr =
    608  1.19   thorpej 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    609   1.1  rearnsha 
    610   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    611   1.1  rearnsha 	printf("Mapping kernel\n");
    612   1.1  rearnsha #endif
    613   1.1  rearnsha 
    614   1.1  rearnsha 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    615   1.1  rearnsha 	{
    616   1.1  rearnsha 		size_t textsize = (uintptr_t) &etext - KERNEL_TEXT_BASE;
    617   1.1  rearnsha 		size_t totalsize = (uintptr_t) &end - KERNEL_TEXT_BASE;
    618  1.23  rearnsha 		u_int logical;
    619   1.1  rearnsha 
    620  1.23  rearnsha 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    621   1.1  rearnsha 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    622  1.23  rearnsha 
    623  1.23  rearnsha 		logical = 0x00200000;	/* offset of kernel in RAM */
    624  1.23  rearnsha 
    625  1.23  rearnsha 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    626  1.23  rearnsha 		    physical_start + logical, textsize,
    627  1.12   thorpej 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    628  1.23  rearnsha 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    629  1.23  rearnsha 		    physical_start + logical, totalsize - textsize,
    630  1.12   thorpej 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    631   1.1  rearnsha 	}
    632   1.1  rearnsha 
    633   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    634   1.1  rearnsha 	printf("Constructing L2 page tables\n");
    635   1.1  rearnsha #endif
    636   1.1  rearnsha 
    637   1.1  rearnsha 	/* Map the stack pages */
    638  1.14   thorpej 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    639  1.14   thorpej 	    IRQ_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    640  1.14   thorpej 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    641  1.14   thorpej 	    ABT_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    642  1.14   thorpej 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    643  1.14   thorpej 	    UND_STACK_SIZE * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    644  1.14   thorpej 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    645  1.14   thorpej 	    UPAGES * NBPG, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    646  1.13   thorpej 
    647  1.14   thorpej 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    648  1.21   thorpej 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    649   1.1  rearnsha 
    650   1.1  rearnsha 	/* Map the page table that maps the kernel pages */
    651  1.16   thorpej 	pmap_map_entry(l1pagetable, kernel_ptpt.pv_va, kernel_ptpt.pv_pa,
    652  1.10   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    653   1.1  rearnsha 
    654   1.1  rearnsha 	/*
    655   1.1  rearnsha 	 * Map entries in the page table used to map PTE's
    656   1.1  rearnsha 	 * Basically every kernel page table gets mapped here
    657   1.1  rearnsha 	 */
    658   1.1  rearnsha 	/* The -2 is slightly bogus, it should be -log2(sizeof(pt_entry_t)) */
    659  1.23  rearnsha 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++) {
    660  1.23  rearnsha 		pmap_map_entry(l1pagetable,
    661  1.23  rearnsha 		    PTE_BASE + ((KERNEL_BASE +
    662  1.23  rearnsha 		    (loop * 0x00400000)) >> (PGSHIFT-2)),
    663  1.23  rearnsha 		    kernel_pt_table[KERNEL_PT_KERNEL + loop].pv_pa,
    664  1.23  rearnsha 		    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    665  1.23  rearnsha 	}
    666  1.15   thorpej 	pmap_map_entry(l1pagetable,
    667  1.18   thorpej 	    PTE_BASE + (PTE_BASE >> (PGSHIFT-2)),
    668  1.23  rearnsha 	    kernel_ptpt.pv_pa, VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    669  1.15   thorpej 	pmap_map_entry(l1pagetable,
    670  1.18   thorpej 	    PTE_BASE + (0x00000000 >> (PGSHIFT-2)),
    671  1.14   thorpej 	    kernel_pt_table[KERNEL_PT_SYS].pv_pa,
    672  1.10   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    673  1.23  rearnsha 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    674  1.15   thorpej 		pmap_map_entry(l1pagetable,
    675  1.18   thorpej 		    PTE_BASE + ((KERNEL_VM_BASE +
    676   1.1  rearnsha 		    (loop * 0x00400000)) >> (PGSHIFT-2)),
    677  1.14   thorpej 		    kernel_pt_table[KERNEL_PT_VMDATA + loop].pv_pa,
    678  1.10   thorpej 		    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    679   1.1  rearnsha 
    680  1.20   thorpej 	/* Map the vector page. */
    681   1.1  rearnsha #if 1
    682   1.1  rearnsha 	/* MULTI-ICE requires that page 0 is NC/NB so that it can download
    683   1.1  rearnsha 	   the cache-clean code there.  */
    684  1.20   thorpej 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    685  1.10   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    686   1.1  rearnsha #else
    687  1.20   thorpej 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    688  1.20   thorpej 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    689   1.1  rearnsha #endif
    690   1.1  rearnsha 	/* Map the core memory needed before autoconfig */
    691   1.1  rearnsha 	loop = 0;
    692   1.1  rearnsha 	while (l1_sec_table[loop].size) {
    693   1.1  rearnsha 		vm_size_t sz;
    694   1.1  rearnsha 
    695   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    696   1.1  rearnsha 		printf("%08lx -> %08lx @ %08lx\n", l1_sec_table[loop].pa,
    697   1.1  rearnsha 		    l1_sec_table[loop].pa + l1_sec_table[loop].size - 1,
    698   1.1  rearnsha 		    l1_sec_table[loop].va);
    699   1.1  rearnsha #endif
    700  1.21   thorpej 		for (sz = 0; sz < l1_sec_table[loop].size; sz += L1_S_SIZE)
    701   1.9   thorpej 			pmap_map_section(l1pagetable,
    702   1.9   thorpej 			    l1_sec_table[loop].va + sz,
    703   1.1  rearnsha 			    l1_sec_table[loop].pa + sz,
    704   1.9   thorpej 			    l1_sec_table[loop].prot,
    705   1.9   thorpej 			    l1_sec_table[loop].cache);
    706   1.1  rearnsha 		++loop;
    707   1.1  rearnsha 	}
    708   1.1  rearnsha 
    709   1.1  rearnsha 	/*
    710   1.1  rearnsha 	 * Now we have the real page tables in place so we can switch to them.
    711  1.23  rearnsha 	 * Once this is done we will be running with the REAL kernel page
    712  1.23  rearnsha 	 * tables.
    713  1.23  rearnsha 	 */
    714  1.23  rearnsha 
    715  1.23  rearnsha 	/*
    716  1.23  rearnsha 	 * Update the physical_freestart/physical_freeend/free_pages
    717  1.23  rearnsha 	 * variables.
    718   1.1  rearnsha 	 */
    719  1.23  rearnsha 	{
    720  1.23  rearnsha 		physical_freestart = physical_start +
    721  1.23  rearnsha 		    (((((uintptr_t) &end) + PGOFSET) & ~PGOFSET) -
    722  1.23  rearnsha 		     KERNEL_BASE);
    723  1.23  rearnsha 		physical_freeend = physical_end;
    724  1.23  rearnsha 		free_pages = (physical_freeend - physical_freestart) / NBPG;
    725  1.23  rearnsha 	}
    726   1.1  rearnsha 
    727   1.1  rearnsha 	/* Switch tables */
    728   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    729  1.23  rearnsha 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    730   1.1  rearnsha 	       physical_freestart, free_pages, free_pages);
    731   1.1  rearnsha 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    732   1.1  rearnsha #endif
    733   1.1  rearnsha 	setttb(kernel_l1pt.pv_pa);
    734  1.23  rearnsha 	cpu_tlb_flushID();
    735   1.1  rearnsha 
    736   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    737   1.1  rearnsha 	printf("done!\n");
    738   1.1  rearnsha #endif
    739   1.1  rearnsha 
    740   1.1  rearnsha #ifdef PLCONSOLE
    741   1.1  rearnsha 	/*
    742   1.1  rearnsha 	 * The IFPGA registers have just moved.
    743   1.1  rearnsha 	 * Detach the diagnostic serial port and reattach at the new address.
    744   1.1  rearnsha 	 */
    745   1.1  rearnsha 	plcomcndetach();
    746   1.1  rearnsha #endif
    747   1.1  rearnsha 
    748   1.1  rearnsha 	/*
    749   1.1  rearnsha 	 * XXX this should only be done in main() but it useful to
    750   1.1  rearnsha 	 * have output earlier ...
    751   1.1  rearnsha 	 */
    752   1.1  rearnsha 	consinit();
    753   1.1  rearnsha 
    754   1.1  rearnsha #ifdef VERBOSE_INIT_ARM
    755   1.1  rearnsha 	printf("bootstrap done.\n");
    756   1.1  rearnsha #endif
    757   1.1  rearnsha 
    758  1.20   thorpej 	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
    759   1.1  rearnsha 
    760   1.1  rearnsha 	/*
    761   1.1  rearnsha 	 * Pages were allocated during the secondary bootstrap for the
    762   1.1  rearnsha 	 * stacks for different CPU modes.
    763   1.1  rearnsha 	 * We must now set the r13 registers in the different CPU modes to
    764   1.1  rearnsha 	 * point to these stacks.
    765   1.1  rearnsha 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    766   1.1  rearnsha 	 * of the stack memory.
    767   1.1  rearnsha 	 */
    768   1.1  rearnsha 	printf("init subsystems: stacks ");
    769   1.1  rearnsha 
    770   1.1  rearnsha 	set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * NBPG);
    771   1.1  rearnsha 	set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * NBPG);
    772   1.1  rearnsha 	set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * NBPG);
    773   1.1  rearnsha 
    774   1.1  rearnsha 	/*
    775   1.1  rearnsha 	 * Well we should set a data abort handler.
    776  1.23  rearnsha 	 * Once things get going this will change as we will need a proper
    777  1.23  rearnsha 	 * handler.
    778   1.1  rearnsha 	 * Until then we will use a handler that just panics but tells us
    779   1.1  rearnsha 	 * why.
    780   1.1  rearnsha 	 * Initialisation of the vectors will just panic on a data abort.
    781   1.1  rearnsha 	 * This just fills in a slighly better one.
    782   1.1  rearnsha 	 */
    783   1.1  rearnsha 	printf("vectors ");
    784   1.1  rearnsha 	data_abort_handler_address = (u_int)data_abort_handler;
    785   1.1  rearnsha 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    786   1.1  rearnsha 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    787   1.1  rearnsha 
    788   1.1  rearnsha 	/* Initialise the undefined instruction handlers */
    789   1.1  rearnsha 	printf("undefined ");
    790   1.1  rearnsha 	undefined_init();
    791   1.1  rearnsha 
    792   1.1  rearnsha 	/* Boot strap pmap telling it where the kernel page table is */
    793   1.1  rearnsha 	printf("pmap ");
    794   1.1  rearnsha 	pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, kernel_ptpt);
    795   1.1  rearnsha 
    796   1.1  rearnsha 	/* Setup the IRQ system */
    797   1.1  rearnsha 	printf("irq ");
    798   1.1  rearnsha 	irq_init();
    799   1.1  rearnsha 
    800   1.1  rearnsha 	printf("done.\n");
    801   1.1  rearnsha 
    802   1.1  rearnsha #ifdef IPKDB
    803   1.1  rearnsha 	/* Initialise ipkdb */
    804   1.1  rearnsha 	ipkdb_init();
    805   1.1  rearnsha 	if (boothowto & RB_KDB)
    806   1.1  rearnsha 		ipkdb_connect(0);
    807   1.1  rearnsha #endif
    808   1.1  rearnsha 
    809   1.1  rearnsha #ifdef DDB
    810   1.1  rearnsha 	db_machine_init();
    811   1.4   thorpej 
    812   1.4   thorpej 	/* Firmware doesn't load symbols. */
    813   1.4   thorpej 	ddb_init(0, NULL, NULL);
    814   1.1  rearnsha 
    815   1.1  rearnsha 	if (boothowto & RB_KDB)
    816   1.1  rearnsha 		Debugger();
    817   1.1  rearnsha #endif
    818   1.1  rearnsha 
    819   1.1  rearnsha 	/* We return the new stack pointer address */
    820   1.1  rearnsha 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    821   1.1  rearnsha }
    822   1.1  rearnsha 
    823   1.1  rearnsha void
    824   1.1  rearnsha consinit(void)
    825   1.1  rearnsha {
    826   1.1  rearnsha 	static int consinit_called = 0;
    827   1.1  rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
    828   1.1  rearnsha 	static struct bus_space plcom_bus_space;
    829   1.1  rearnsha #endif
    830   1.1  rearnsha #if 0
    831   1.1  rearnsha 	char *console = CONSDEVNAME;
    832   1.1  rearnsha #endif
    833   1.1  rearnsha 
    834   1.1  rearnsha 	if (consinit_called != 0)
    835   1.1  rearnsha 		return;
    836   1.1  rearnsha 
    837   1.1  rearnsha 	consinit_called = 1;
    838   1.1  rearnsha 
    839   1.1  rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
    840   1.1  rearnsha 	if (PLCOMCNUNIT == 0) {
    841   1.1  rearnsha 		ifpga_create_io_bs_tag(&plcom_bus_space,
    842   1.1  rearnsha 		    (void*)UART0_BOOT_BASE);
    843   1.1  rearnsha 		if (plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
    844   1.1  rearnsha 		    IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT))
    845   1.1  rearnsha 			panic("can't init serial console");
    846   1.1  rearnsha 		return;
    847   1.1  rearnsha 	} else if (PLCOMCNUNIT == 1) {
    848   1.1  rearnsha 		ifpga_create_io_bs_tag(&plcom_bus_space,
    849   1.1  rearnsha 		    (void*)UART0_BOOT_BASE);
    850   1.1  rearnsha 		if (plcomcnattach(&plcom_bus_space, 0, plcomcnspeed,
    851   1.1  rearnsha 		    IFPGA_UART_CLK, plcomcnmode, PLCOMCNUNIT))
    852   1.1  rearnsha 			panic("can't init serial console");
    853   1.1  rearnsha 		return;
    854   1.1  rearnsha 	}
    855   1.1  rearnsha #endif
    856   1.1  rearnsha #if (NCOM > 0)
    857   1.1  rearnsha 	if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
    858   1.1  rearnsha 	    COM_FREQ, comcnmode))
    859   1.1  rearnsha 		panic("can't init serial console @%x", CONCOMADDR);
    860   1.1  rearnsha 	return;
    861   1.1  rearnsha #endif
    862   1.1  rearnsha 	panic("No serial console configured");
    863  1.23  rearnsha }
    864  1.23  rearnsha 
    865  1.23  rearnsha static void
    866  1.23  rearnsha integrator_sdram_bounds(paddr_t *memstart, psize_t *memsize)
    867  1.23  rearnsha {
    868  1.23  rearnsha 	volatile unsigned long *cm_sdram
    869  1.23  rearnsha 	    = (volatile unsigned long *)0x10000020;
    870  1.23  rearnsha 
    871  1.23  rearnsha 	*memstart = 0;
    872  1.23  rearnsha 
    873  1.23  rearnsha 	switch ((*cm_sdram >> 2) & 0x7)
    874  1.23  rearnsha 	{
    875  1.23  rearnsha 	case 0:
    876  1.23  rearnsha 		*memsize = 16 * 1024 * 1024;
    877  1.23  rearnsha 		break;
    878  1.23  rearnsha 	case 1:
    879  1.23  rearnsha 		*memsize = 32 * 1024 * 1024;
    880  1.23  rearnsha 		break;
    881  1.23  rearnsha 	case 2:
    882  1.23  rearnsha 		*memsize = 64 * 1024 * 1024;
    883  1.23  rearnsha 		break;
    884  1.23  rearnsha 	case 3:
    885  1.23  rearnsha 		*memsize = 128 * 1024 * 1024;
    886  1.23  rearnsha 		break;
    887  1.23  rearnsha 	case 4:
    888  1.23  rearnsha 		*memsize = 256 * 1024 * 1024;
    889  1.23  rearnsha 		break;
    890  1.23  rearnsha 	default:
    891  1.23  rearnsha 		printf("CM_SDRAM retuns unknown value, using 16M\n");
    892  1.23  rearnsha 		*memsize = 16 * 1024 * 1024;
    893  1.23  rearnsha 		break;
    894  1.23  rearnsha 	}
    895   1.1  rearnsha }
    896