Home | History | Annotate | Line # | Download | only in viper
viper_machdep.c revision 1.6
      1  1.6    wiz /*	$NetBSD: viper_machdep.c,v 1.6 2006/11/24 22:04:22 wiz Exp $	*/
      2  1.1  pooka 
      3  1.1  pooka /*
      4  1.1  pooka  * Startup routines for the Arcom Viper.  Below you can trace the
      5  1.1  pooka  * impressive lineage ;)
      6  1.1  pooka  *
      7  1.1  pooka  * Modified for the Viper by Antti Kantee <pooka (at) netbsd.org>
      8  1.1  pooka  */
      9  1.1  pooka 
     10  1.1  pooka /*
     11  1.1  pooka  * Copyright (c) 2002, 2003, 2005  Genetec Corporation.  All rights reserved.
     12  1.1  pooka  * Written by Hiroyuki Bessho for Genetec Corporation.
     13  1.1  pooka  *
     14  1.1  pooka  * Redistribution and use in source and binary forms, with or without
     15  1.1  pooka  * modification, are permitted provided that the following conditions
     16  1.1  pooka  * are met:
     17  1.1  pooka  * 1. Redistributions of source code must retain the above copyright
     18  1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     19  1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     20  1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     21  1.1  pooka  *    documentation and/or other materials provided with the distribution.
     22  1.1  pooka  * 3. The name of Genetec Corporation may not be used to endorse or
     23  1.1  pooka  *    promote products derived from this software without specific prior
     24  1.1  pooka  *    written permission.
     25  1.1  pooka  *
     26  1.1  pooka  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     27  1.1  pooka  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  pooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  pooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     30  1.1  pooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  pooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  pooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  pooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  pooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  pooka  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  pooka  *
     38  1.1  pooka  * Machine dependant functions for kernel setup for
     39  1.1  pooka  * Intel DBPXA250 evaluation board (a.k.a. Lubbock).
     40  1.1  pooka  * Based on iq80310_machhdep.c
     41  1.1  pooka  */
     42  1.1  pooka /*
     43  1.1  pooka  * Copyright (c) 2001 Wasabi Systems, Inc.
     44  1.1  pooka  * All rights reserved.
     45  1.1  pooka  *
     46  1.1  pooka  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     47  1.1  pooka  *
     48  1.1  pooka  * Redistribution and use in source and binary forms, with or without
     49  1.1  pooka  * modification, are permitted provided that the following conditions
     50  1.1  pooka  * are met:
     51  1.1  pooka  * 1. Redistributions of source code must retain the above copyright
     52  1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     53  1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     54  1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     55  1.1  pooka  *    documentation and/or other materials provided with the distribution.
     56  1.1  pooka  * 3. All advertising materials mentioning features or use of this software
     57  1.1  pooka  *    must display the following acknowledgement:
     58  1.1  pooka  *	This product includes software developed for the NetBSD Project by
     59  1.1  pooka  *	Wasabi Systems, Inc.
     60  1.1  pooka  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     61  1.1  pooka  *    or promote products derived from this software without specific prior
     62  1.1  pooka  *    written permission.
     63  1.1  pooka  *
     64  1.1  pooka  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     65  1.1  pooka  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     66  1.1  pooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     67  1.1  pooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     68  1.1  pooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     69  1.1  pooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     70  1.1  pooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     71  1.1  pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     72  1.1  pooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     73  1.1  pooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     74  1.1  pooka  * POSSIBILITY OF SUCH DAMAGE.
     75  1.1  pooka  */
     76  1.1  pooka 
     77  1.1  pooka /*
     78  1.1  pooka  * Copyright (c) 1997,1998 Mark Brinicombe.
     79  1.1  pooka  * Copyright (c) 1997,1998 Causality Limited.
     80  1.1  pooka  * All rights reserved.
     81  1.1  pooka  *
     82  1.1  pooka  * Redistribution and use in source and binary forms, with or without
     83  1.1  pooka  * modification, are permitted provided that the following conditions
     84  1.1  pooka  * are met:
     85  1.1  pooka  * 1. Redistributions of source code must retain the above copyright
     86  1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     87  1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     88  1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     89  1.1  pooka  *    documentation and/or other materials provided with the distribution.
     90  1.1  pooka  * 3. All advertising materials mentioning features or use of this software
     91  1.1  pooka  *    must display the following acknowledgement:
     92  1.1  pooka  *	This product includes software developed by Mark Brinicombe
     93  1.1  pooka  *	for the NetBSD Project.
     94  1.1  pooka  * 4. The name of the company nor the name of the author may be used to
     95  1.1  pooka  *    endorse or promote products derived from this software without specific
     96  1.1  pooka  *    prior written permission.
     97  1.1  pooka  *
     98  1.1  pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     99  1.1  pooka  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    100  1.1  pooka  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    101  1.1  pooka  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    102  1.1  pooka  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    103  1.1  pooka  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    104  1.1  pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    105  1.1  pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    106  1.1  pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    107  1.1  pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    108  1.1  pooka  * SUCH DAMAGE.
    109  1.1  pooka  *
    110  1.1  pooka  * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
    111  1.1  pooka  * boards using RedBoot firmware.
    112  1.1  pooka  */
    113  1.1  pooka 
    114  1.1  pooka #include <sys/cdefs.h>
    115  1.6    wiz __KERNEL_RCSID(0, "$NetBSD: viper_machdep.c,v 1.6 2006/11/24 22:04:22 wiz Exp $");
    116  1.1  pooka 
    117  1.1  pooka #include "opt_ddb.h"
    118  1.1  pooka #include "opt_kgdb.h"
    119  1.1  pooka #include "opt_ipkdb.h"
    120  1.1  pooka #include "opt_pmap_debug.h"
    121  1.1  pooka #include "opt_md.h"
    122  1.1  pooka #include "opt_com.h"
    123  1.1  pooka #include "md.h"
    124  1.1  pooka #include "lcd.h"
    125  1.1  pooka 
    126  1.1  pooka #include <sys/param.h>
    127  1.1  pooka #include <sys/device.h>
    128  1.1  pooka #include <sys/systm.h>
    129  1.1  pooka #include <sys/kernel.h>
    130  1.1  pooka #include <sys/exec.h>
    131  1.1  pooka #include <sys/proc.h>
    132  1.1  pooka #include <sys/msgbuf.h>
    133  1.1  pooka #include <sys/reboot.h>
    134  1.1  pooka #include <sys/termios.h>
    135  1.1  pooka #include <sys/ksyms.h>
    136  1.1  pooka 
    137  1.1  pooka #include <uvm/uvm_extern.h>
    138  1.1  pooka 
    139  1.1  pooka #include <sys/conf.h>
    140  1.1  pooka #include <dev/cons.h>
    141  1.1  pooka #include <dev/md.h>
    142  1.1  pooka #include <dev/ic/smc91cxxreg.h>
    143  1.1  pooka 
    144  1.1  pooka #include <machine/db_machdep.h>
    145  1.1  pooka #include <ddb/db_sym.h>
    146  1.1  pooka #include <ddb/db_extern.h>
    147  1.1  pooka #ifdef KGDB
    148  1.1  pooka #include <sys/kgdb.h>
    149  1.1  pooka #endif
    150  1.1  pooka 
    151  1.1  pooka #include <machine/bootconfig.h>
    152  1.1  pooka #include <machine/bus.h>
    153  1.1  pooka #include <machine/cpu.h>
    154  1.1  pooka #include <machine/frame.h>
    155  1.1  pooka #include <arm/undefined.h>
    156  1.1  pooka 
    157  1.1  pooka #include <arm/arm32/machdep.h>
    158  1.1  pooka 
    159  1.1  pooka #include <arm/xscale/pxa2x0reg.h>
    160  1.1  pooka #include <arm/xscale/pxa2x0var.h>
    161  1.1  pooka #include <arm/xscale/pxa2x0_gpio.h>
    162  1.1  pooka #include <arm/sa11x0/sa1111_reg.h>
    163  1.1  pooka #include <evbarm/viper/viper_reg.h>
    164  1.1  pooka 
    165  1.1  pooka /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    166  1.1  pooka #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
    167  1.1  pooka #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    168  1.1  pooka 
    169  1.1  pooka /*
    170  1.1  pooka  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    171  1.1  pooka  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    172  1.1  pooka  */
    173  1.1  pooka #define KERNEL_VM_SIZE		0x0C000000
    174  1.1  pooka 
    175  1.1  pooka 
    176  1.1  pooka /*
    177  1.1  pooka  * Address to call from cpu_reset() to reset the machine.
    178  1.1  pooka  * This is machine architecture dependant as it varies depending
    179  1.1  pooka  * on where the ROM appears when you turn the MMU off.
    180  1.1  pooka  */
    181  1.1  pooka 
    182  1.1  pooka u_int cpu_reset_address = 0;
    183  1.1  pooka 
    184  1.1  pooka /* Define various stack sizes in pages */
    185  1.1  pooka #define IRQ_STACK_SIZE	1
    186  1.1  pooka #define ABT_STACK_SIZE	1
    187  1.1  pooka #ifdef IPKDB
    188  1.1  pooka #define UND_STACK_SIZE	2
    189  1.1  pooka #else
    190  1.1  pooka #define UND_STACK_SIZE	1
    191  1.1  pooka #endif
    192  1.1  pooka 
    193  1.1  pooka BootConfig bootconfig;		/* Boot config storage */
    194  1.1  pooka char *boot_args = NULL;
    195  1.1  pooka char *boot_file = NULL;
    196  1.1  pooka 
    197  1.1  pooka vm_offset_t physical_start;
    198  1.1  pooka vm_offset_t physical_freestart;
    199  1.1  pooka vm_offset_t physical_freeend;
    200  1.1  pooka vm_offset_t physical_end;
    201  1.1  pooka u_int free_pages;
    202  1.1  pooka vm_offset_t pagetables_start;
    203  1.1  pooka int physmem = 0;
    204  1.1  pooka 
    205  1.1  pooka /*int debug_flags;*/
    206  1.1  pooka #ifndef PMAP_STATIC_L1S
    207  1.1  pooka int max_processes = 64;			/* Default number */
    208  1.1  pooka #endif	/* !PMAP_STATIC_L1S */
    209  1.1  pooka 
    210  1.1  pooka /* Physical and virtual addresses for some global pages */
    211  1.1  pooka pv_addr_t systempage;
    212  1.1  pooka pv_addr_t irqstack;
    213  1.1  pooka pv_addr_t undstack;
    214  1.1  pooka pv_addr_t abtstack;
    215  1.1  pooka pv_addr_t kernelstack;
    216  1.1  pooka pv_addr_t minidataclean;
    217  1.1  pooka 
    218  1.1  pooka vm_offset_t msgbufphys;
    219  1.1  pooka 
    220  1.1  pooka extern u_int data_abort_handler_address;
    221  1.1  pooka extern u_int prefetch_abort_handler_address;
    222  1.1  pooka extern u_int undefined_handler_address;
    223  1.1  pooka 
    224  1.1  pooka #ifdef PMAP_DEBUG
    225  1.1  pooka extern int pmap_debug_level;
    226  1.1  pooka #endif
    227  1.1  pooka 
    228  1.1  pooka #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    229  1.1  pooka #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    230  1.1  pooka #define	KERNEL_PT_KERNEL_NUM	4
    231  1.1  pooka #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
    232  1.1  pooka 				        /* Page tables for mapping kernel VM */
    233  1.1  pooka #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    234  1.1  pooka #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    235  1.1  pooka 
    236  1.1  pooka pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    237  1.1  pooka 
    238  1.1  pooka struct user *proc0paddr;
    239  1.1  pooka 
    240  1.1  pooka /* Prototypes */
    241  1.1  pooka 
    242  1.1  pooka #if 0
    243  1.1  pooka void	process_kernel_args(char *);
    244  1.1  pooka #endif
    245  1.1  pooka 
    246  1.1  pooka void	consinit(void);
    247  1.1  pooka void	kgdb_port_init(void);
    248  1.1  pooka void	change_clock(uint32_t v);
    249  1.1  pooka 
    250  1.1  pooka bs_protos(bs_notimpl);
    251  1.1  pooka 
    252  1.1  pooka #include "com.h"
    253  1.1  pooka #if NCOM > 0
    254  1.1  pooka #include <dev/ic/comreg.h>
    255  1.1  pooka #include <dev/ic/comvar.h>
    256  1.1  pooka #endif
    257  1.1  pooka 
    258  1.1  pooka #ifndef CONSPEED
    259  1.1  pooka #define CONSPEED B115200	/* What RedBoot uses */
    260  1.1  pooka #endif
    261  1.1  pooka #ifndef CONMODE
    262  1.1  pooka #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    263  1.1  pooka #endif
    264  1.1  pooka 
    265  1.1  pooka int comcnspeed = CONSPEED;
    266  1.1  pooka int comcnmode = CONMODE;
    267  1.1  pooka 
    268  1.1  pooka /*
    269  1.1  pooka  * void cpu_reboot(int howto, char *bootstr)
    270  1.1  pooka  *
    271  1.1  pooka  * Reboots the system
    272  1.1  pooka  *
    273  1.1  pooka  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    274  1.1  pooka  * then reset the CPU.
    275  1.1  pooka  */
    276  1.1  pooka void
    277  1.1  pooka cpu_reboot(int howto, char *bootstr)
    278  1.1  pooka {
    279  1.1  pooka #ifdef DIAGNOSTIC
    280  1.1  pooka 	/* info */
    281  1.1  pooka 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    282  1.1  pooka #endif
    283  1.1  pooka 
    284  1.1  pooka 	/*
    285  1.1  pooka 	 * If we are still cold then hit the air brakes
    286  1.1  pooka 	 * and crash to earth fast
    287  1.1  pooka 	 */
    288  1.1  pooka 	if (cold) {
    289  1.1  pooka 		doshutdownhooks();
    290  1.1  pooka 		printf("The operating system has halted.\n");
    291  1.1  pooka 		printf("Please press any key to reboot.\n\n");
    292  1.1  pooka 		cngetc();
    293  1.1  pooka 		printf("rebooting...\n");
    294  1.1  pooka 		cpu_reset();
    295  1.1  pooka 		/*NOTREACHED*/
    296  1.1  pooka 	}
    297  1.1  pooka 
    298  1.1  pooka 	/* Disable console buffering */
    299  1.1  pooka /*	cnpollc(1);*/
    300  1.1  pooka 
    301  1.1  pooka 	/*
    302  1.1  pooka 	 * If RB_NOSYNC was not specified sync the discs.
    303  1.1  pooka 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    304  1.1  pooka 	 * unmount.  It looks like syslogd is getting woken up only to find
    305  1.1  pooka 	 * that it cannot page part of the binary in as the filesystem has
    306  1.1  pooka 	 * been unmounted.
    307  1.1  pooka 	 */
    308  1.1  pooka 	if (!(howto & RB_NOSYNC))
    309  1.1  pooka 		bootsync();
    310  1.1  pooka 
    311  1.1  pooka 	/* Say NO to interrupts */
    312  1.1  pooka 	splhigh();
    313  1.1  pooka 
    314  1.1  pooka 	/* Do a dump if requested. */
    315  1.1  pooka 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    316  1.1  pooka 		dumpsys();
    317  1.1  pooka 
    318  1.1  pooka 	/* Run any shutdown hooks */
    319  1.1  pooka 	doshutdownhooks();
    320  1.1  pooka 
    321  1.1  pooka 	/* Make sure IRQ's are disabled */
    322  1.1  pooka 	IRQdisable;
    323  1.1  pooka 
    324  1.1  pooka 	if (howto & RB_HALT) {
    325  1.1  pooka 		printf("The operating system has halted.\n");
    326  1.1  pooka 		printf("Please press any key to reboot.\n\n");
    327  1.1  pooka 		cngetc();
    328  1.1  pooka 	}
    329  1.1  pooka 
    330  1.1  pooka 	printf("rebooting...\n");
    331  1.1  pooka 	cpu_reset();
    332  1.1  pooka 	/*NOTREACHED*/
    333  1.1  pooka }
    334  1.1  pooka 
    335  1.1  pooka /*
    336  1.1  pooka  * Static device mappings. These peripheral registers are mapped at
    337  1.1  pooka  * fixed virtual addresses very early in viper_start() so that we
    338  1.1  pooka  * can use them while booting the kernel, and stay at the same address
    339  1.1  pooka  * throughout whole kernel's life time.
    340  1.1  pooka  *
    341  1.1  pooka  * We use this table twice; once with bootstrap page table, and once
    342  1.1  pooka  * with kernel's page table which we build up in initarm().
    343  1.1  pooka  */
    344  1.1  pooka 
    345  1.1  pooka static const struct pmap_devmap viper_devmap[] = {
    346  1.1  pooka     {
    347  1.1  pooka 	    VIPER_GPIO_VBASE,
    348  1.1  pooka 	    PXA2X0_GPIO_BASE,
    349  1.1  pooka 	    L1_S_SIZE,
    350  1.1  pooka 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    351  1.1  pooka     },
    352  1.1  pooka     {
    353  1.1  pooka 	    VIPER_CLKMAN_VBASE,
    354  1.1  pooka 	    PXA2X0_CLKMAN_BASE,
    355  1.1  pooka 	    L1_S_SIZE,
    356  1.1  pooka 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    357  1.1  pooka     },
    358  1.1  pooka     {
    359  1.1  pooka 	    VIPER_INTCTL_VBASE,
    360  1.1  pooka 	    PXA2X0_INTCTL_BASE,
    361  1.1  pooka 	    L1_S_SIZE,
    362  1.1  pooka 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    363  1.1  pooka     },
    364  1.1  pooka     {
    365  1.1  pooka 	    VIPER_FFUART_VBASE,
    366  1.1  pooka 	    PXA2X0_FFUART_BASE,
    367  1.1  pooka 	    L1_S_SIZE,
    368  1.1  pooka 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    369  1.1  pooka     },
    370  1.1  pooka     {
    371  1.1  pooka 	    VIPER_BTUART_VBASE,
    372  1.1  pooka 	    PXA2X0_BTUART_BASE,
    373  1.1  pooka 	    L1_S_SIZE,
    374  1.1  pooka 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    375  1.1  pooka     },
    376  1.1  pooka 
    377  1.1  pooka     {0, 0, 0, 0,}
    378  1.1  pooka };
    379  1.1  pooka 
    380  1.1  pooka #ifndef MEMSTART
    381  1.1  pooka #define MEMSTART 0xa0000000
    382  1.1  pooka #endif
    383  1.1  pooka #ifndef MEMSIZE
    384  1.1  pooka #define MEMSIZE 0x4000000
    385  1.1  pooka #endif
    386  1.1  pooka 
    387  1.1  pooka /*
    388  1.1  pooka  * u_int initarm(...)
    389  1.1  pooka  *
    390  1.1  pooka  * Initial entry point on startup. This gets called before main() is
    391  1.1  pooka  * entered.
    392  1.1  pooka  * It should be responsible for setting up everything that must be
    393  1.1  pooka  * in place when main is called.
    394  1.1  pooka  * This includes
    395  1.1  pooka  *   Taking a copy of the boot configuration structure.
    396  1.1  pooka  *   Initialising the physical console so characters can be printed.
    397  1.1  pooka  *   Setting up page tables for the kernel
    398  1.1  pooka  *   Relocating the kernel to the bottom of physical memory
    399  1.1  pooka  */
    400  1.1  pooka u_int
    401  1.1  pooka initarm(void *arg)
    402  1.1  pooka {
    403  1.1  pooka 	extern vaddr_t xscale_cache_clean_addr;
    404  1.1  pooka 	int loop;
    405  1.1  pooka 	int loop1;
    406  1.1  pooka 	u_int l1pagetable;
    407  1.1  pooka 	pv_addr_t kernel_l1pt;
    408  1.1  pooka #ifdef DIAGNOSTIC
    409  1.1  pooka 	extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
    410  1.1  pooka #endif
    411  1.1  pooka 
    412  1.1  pooka 	/* Register devmap for devices we mapped in start */
    413  1.1  pooka 	pmap_devmap_register(viper_devmap);
    414  1.1  pooka 
    415  1.3  lukem 	/* start 32.768 kHz OSC */
    416  1.1  pooka 	ioreg_write(VIPER_CLKMAN_VBASE + 0x08, 2);
    417  1.1  pooka 	/* Get ready for splfoo() */
    418  1.1  pooka 	pxa2x0_intr_bootstrap(VIPER_INTCTL_VBASE);
    419  1.1  pooka 
    420  1.1  pooka 	/*
    421  1.1  pooka 	 * Heads up ... Setup the CPU / MMU / TLB functions
    422  1.1  pooka 	 */
    423  1.1  pooka 	if (set_cpufuncs())
    424  1.1  pooka 		panic("cpu not recognized!");
    425  1.1  pooka 
    426  1.1  pooka #if 0
    427  1.1  pooka 	/* Calibrate the delay loop. */
    428  1.1  pooka #endif
    429  1.1  pooka 
    430  1.1  pooka 	/* setup GPIO for BTUART, in case bootloader doesn't take care of it */
    431  1.1  pooka 	pxa2x0_gpio_bootstrap(VIPER_GPIO_VBASE);
    432  1.1  pooka 	pxa2x0_gpio_set_function(42, GPIO_ALT_FN_1_IN);
    433  1.1  pooka 	pxa2x0_gpio_set_function(43, GPIO_ALT_FN_2_OUT);
    434  1.1  pooka 	pxa2x0_gpio_set_function(44, GPIO_ALT_FN_1_IN);
    435  1.1  pooka 	pxa2x0_gpio_set_function(45, GPIO_ALT_FN_2_OUT);
    436  1.1  pooka 
    437  1.1  pooka 	/* turn on clock to UART block.
    438  1.1  pooka 	   XXX: this should not be done here. */
    439  1.1  pooka 	ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN, CKEN_FFUART|CKEN_BTUART |
    440  1.1  pooka 	    ioreg_read(VIPER_CLKMAN_VBASE+CLKMAN_CKEN));
    441  1.1  pooka 
    442  1.1  pooka 	consinit();
    443  1.1  pooka #ifdef KGDB
    444  1.1  pooka 	kgdb_port_init();
    445  1.1  pooka #endif
    446  1.1  pooka 	/* Talk to the user */
    447  1.1  pooka 	printf("\nNetBSD/evbarm (viper) booting ...\n");
    448  1.1  pooka 
    449  1.1  pooka #if 0
    450  1.1  pooka 	/*
    451  1.1  pooka 	 * Examine the boot args string for options we need to know about
    452  1.1  pooka 	 * now.
    453  1.1  pooka 	 */
    454  1.1  pooka 	process_kernel_args((char *)nwbootinfo.bt_args);
    455  1.1  pooka #endif
    456  1.1  pooka 
    457  1.1  pooka 	printf("initarm: Configuring system ...\n");
    458  1.1  pooka 
    459  1.1  pooka 	/* Fake bootconfig structure for the benefit of pmap.c */
    460  1.6    wiz 	/* XXX must make the memory description h/w independent */
    461  1.1  pooka 	bootconfig.dramblocks = 1;
    462  1.1  pooka 	bootconfig.dram[0].address = MEMSTART;
    463  1.1  pooka 	bootconfig.dram[0].pages = MEMSIZE / PAGE_SIZE;
    464  1.1  pooka 
    465  1.1  pooka 	/*
    466  1.1  pooka 	 * Set up the variables that define the availablilty of
    467  1.1  pooka 	 * physical memory.  For now, we're going to set
    468  1.1  pooka 	 * physical_freestart to 0xa0200000 (where the kernel
    469  1.1  pooka 	 * was loaded), and allocate the memory we need downwards.
    470  1.1  pooka 	 * If we get too close to the page tables that RedBoot
    471  1.1  pooka 	 * set up, we will panic.  We will update physical_freestart
    472  1.1  pooka 	 * and physical_freeend later to reflect what pmap_bootstrap()
    473  1.1  pooka 	 * wants to see.
    474  1.1  pooka 	 *
    475  1.1  pooka 	 * XXX pmap_bootstrap() needs an enema.
    476  1.1  pooka 	 * (now that would be truly hardcore XXX)
    477  1.1  pooka 	 */
    478  1.1  pooka 	physical_start = bootconfig.dram[0].address;
    479  1.1  pooka 	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
    480  1.1  pooka 
    481  1.1  pooka 	physical_freestart = 0xa0009000UL;
    482  1.1  pooka 	physical_freeend = 0xa0200000UL;
    483  1.1  pooka 
    484  1.1  pooka 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    485  1.1  pooka 
    486  1.1  pooka #ifdef VERBOSE_INIT_ARM
    487  1.1  pooka 	/* Tell the user about the memory */
    488  1.1  pooka 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    489  1.1  pooka 	    physical_start, physical_end - 1);
    490  1.1  pooka #endif
    491  1.1  pooka 
    492  1.1  pooka 	/*
    493  1.1  pooka 	 * Okay, the kernel starts 2MB in from the bottom of physical
    494  1.1  pooka 	 * memory.  We are going to allocate our bootstrap pages downwards
    495  1.1  pooka 	 * from there.
    496  1.1  pooka 	 *
    497  1.1  pooka 	 * We need to allocate some fixed page tables to get the kernel
    498  1.1  pooka 	 * going.  We allocate one page directory and a number of page
    499  1.1  pooka 	 * tables and store the physical addresses in the kernel_pt_table
    500  1.1  pooka 	 * array.
    501  1.1  pooka 	 *
    502  1.1  pooka 	 * The kernel page directory must be on a 16K boundary.  The page
    503  1.1  pooka 	 * tables must be on 4K boundaries.  What we do is allocate the
    504  1.1  pooka 	 * page directory on the first 16K boundary that we encounter, and
    505  1.1  pooka 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    506  1.1  pooka 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    507  1.1  pooka 	 * least one 16K aligned region.
    508  1.1  pooka 	 */
    509  1.1  pooka 
    510  1.1  pooka #ifdef VERBOSE_INIT_ARM
    511  1.1  pooka 	printf("Allocating page tables\n");
    512  1.1  pooka #endif
    513  1.1  pooka 
    514  1.1  pooka 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    515  1.1  pooka 
    516  1.1  pooka #ifdef VERBOSE_INIT_ARM
    517  1.1  pooka 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    518  1.1  pooka 	       physical_freestart, free_pages, free_pages);
    519  1.1  pooka #endif
    520  1.1  pooka 
    521  1.1  pooka 	/* Define a macro to simplify memory allocation */
    522  1.1  pooka #define	valloc_pages(var, np)				\
    523  1.1  pooka 	alloc_pages((var).pv_pa, (np));			\
    524  1.1  pooka 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    525  1.1  pooka 
    526  1.1  pooka #define alloc_pages(var, np)				\
    527  1.1  pooka 	physical_freeend -= ((np) * PAGE_SIZE);		\
    528  1.1  pooka 	if (physical_freeend < physical_freestart)	\
    529  1.1  pooka 		panic("initarm: out of memory");	\
    530  1.1  pooka 	(var) = physical_freeend;			\
    531  1.1  pooka 	free_pages -= (np);				\
    532  1.1  pooka 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    533  1.1  pooka 
    534  1.1  pooka 	loop1 = 0;
    535  1.1  pooka 	kernel_l1pt.pv_pa = 0;
    536  1.4    mrg 	kernel_l1pt.pv_va = 0;
    537  1.1  pooka 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    538  1.1  pooka 		/* Are we 16KB aligned for an L1 ? */
    539  1.1  pooka 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    540  1.1  pooka 		    && kernel_l1pt.pv_pa == 0) {
    541  1.1  pooka 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    542  1.1  pooka 		} else {
    543  1.1  pooka 			valloc_pages(kernel_pt_table[loop1],
    544  1.1  pooka 			    L2_TABLE_SIZE / PAGE_SIZE);
    545  1.1  pooka 			++loop1;
    546  1.1  pooka 		}
    547  1.1  pooka 	}
    548  1.1  pooka 
    549  1.1  pooka 	/* This should never be able to happen but better confirm that. */
    550  1.1  pooka 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    551  1.1  pooka 		panic("initarm: Failed to align the kernel page directory");
    552  1.1  pooka 
    553  1.1  pooka 	/*
    554  1.1  pooka 	 * Allocate a page for the system page mapped to V0x00000000
    555  1.1  pooka 	 * This page will just contain the system vectors and can be
    556  1.1  pooka 	 * shared by all processes.
    557  1.1  pooka 	 */
    558  1.1  pooka 	alloc_pages(systempage.pv_pa, 1);
    559  1.1  pooka 
    560  1.1  pooka 	/* Allocate stacks for all modes */
    561  1.1  pooka 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    562  1.1  pooka 	valloc_pages(abtstack, ABT_STACK_SIZE);
    563  1.1  pooka 	valloc_pages(undstack, UND_STACK_SIZE);
    564  1.1  pooka 	valloc_pages(kernelstack, UPAGES);
    565  1.1  pooka 
    566  1.1  pooka 	/* Allocate enough pages for cleaning the Mini-Data cache. */
    567  1.1  pooka 	KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
    568  1.1  pooka 	valloc_pages(minidataclean, 1);
    569  1.1  pooka 
    570  1.1  pooka #ifdef VERBOSE_INIT_ARM
    571  1.1  pooka 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    572  1.1  pooka 	    irqstack.pv_va);
    573  1.1  pooka 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    574  1.1  pooka 	    abtstack.pv_va);
    575  1.1  pooka 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    576  1.1  pooka 	    undstack.pv_va);
    577  1.1  pooka 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    578  1.1  pooka 	    kernelstack.pv_va);
    579  1.1  pooka #endif
    580  1.1  pooka 
    581  1.1  pooka 	/*
    582  1.1  pooka 	 * XXX Defer this to later so that we can reclaim the memory
    583  1.1  pooka 	 * XXX used by the RedBoot page tables.
    584  1.1  pooka 	 */
    585  1.1  pooka 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    586  1.1  pooka 
    587  1.1  pooka 	/*
    588  1.1  pooka 	 * Ok we have allocated physical pages for the primary kernel
    589  1.1  pooka 	 * page tables
    590  1.1  pooka 	 */
    591  1.1  pooka 
    592  1.1  pooka #ifdef VERBOSE_INIT_ARM
    593  1.1  pooka 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    594  1.1  pooka #endif
    595  1.1  pooka 
    596  1.1  pooka 	/*
    597  1.1  pooka 	 * Now we start construction of the L1 page table
    598  1.1  pooka 	 * We start by mapping the L2 page tables into the L1.
    599  1.1  pooka 	 * This means that we can replace L1 mappings later on if necessary
    600  1.1  pooka 	 */
    601  1.1  pooka 	l1pagetable = kernel_l1pt.pv_pa;
    602  1.1  pooka 
    603  1.1  pooka 	/* Map the L2 pages tables in the L1 page table */
    604  1.1  pooka 	pmap_link_l2pt(l1pagetable, 0x00000000,
    605  1.1  pooka 	    &kernel_pt_table[KERNEL_PT_SYS]);
    606  1.1  pooka 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    607  1.1  pooka 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    608  1.1  pooka 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    609  1.1  pooka 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    610  1.1  pooka 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    611  1.1  pooka 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    612  1.1  pooka 
    613  1.1  pooka 	/* update the top of the kernel VM */
    614  1.1  pooka 	pmap_curmaxkvaddr =
    615  1.1  pooka 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    616  1.1  pooka 
    617  1.1  pooka #ifdef VERBOSE_INIT_ARM
    618  1.1  pooka 	printf("Mapping kernel\n");
    619  1.1  pooka #endif
    620  1.1  pooka 
    621  1.1  pooka 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    622  1.1  pooka 	{
    623  1.1  pooka 		extern char etext[], _end[];
    624  1.1  pooka 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    625  1.1  pooka 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    626  1.1  pooka 		u_int logical;
    627  1.1  pooka 
    628  1.1  pooka 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    629  1.1  pooka 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    630  1.1  pooka 
    631  1.1  pooka 		logical = 0x00200000;	/* offset of kernel in RAM */
    632  1.1  pooka 
    633  1.1  pooka 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    634  1.1  pooka 		    physical_start + logical, textsize,
    635  1.1  pooka 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    636  1.1  pooka 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    637  1.1  pooka 		    physical_start + logical, totalsize - textsize,
    638  1.1  pooka 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    639  1.1  pooka 	}
    640  1.1  pooka 
    641  1.1  pooka #ifdef VERBOSE_INIT_ARM
    642  1.1  pooka 	printf("Constructing L2 page tables\n");
    643  1.1  pooka #endif
    644  1.1  pooka 
    645  1.1  pooka 	/* Map the stack pages */
    646  1.1  pooka 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    647  1.1  pooka 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    648  1.1  pooka 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    649  1.1  pooka 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    650  1.1  pooka 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    651  1.1  pooka 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    652  1.1  pooka 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    653  1.1  pooka 	    UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    654  1.1  pooka 
    655  1.1  pooka 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    656  1.1  pooka 	    L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
    657  1.1  pooka 
    658  1.1  pooka 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    659  1.1  pooka 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    660  1.1  pooka 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    661  1.1  pooka 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    662  1.1  pooka 	}
    663  1.1  pooka 
    664  1.1  pooka 	/* Map the Mini-Data cache clean area. */
    665  1.1  pooka 	xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
    666  1.1  pooka 	    minidataclean.pv_pa);
    667  1.1  pooka 
    668  1.1  pooka 	/* Map the vector page. */
    669  1.1  pooka #if 1
    670  1.1  pooka 	/* MULTI-ICE requires that page 0 is NC/NB so that it can download the
    671  1.1  pooka 	 * cache-clean code there.  */
    672  1.1  pooka 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    673  1.1  pooka 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    674  1.1  pooka #else
    675  1.1  pooka 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    676  1.1  pooka 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    677  1.1  pooka #endif
    678  1.1  pooka 
    679  1.1  pooka 	/*
    680  1.1  pooka 	 * map integrated peripherals at same address in l1pagetable
    681  1.1  pooka 	 * so that we can continue to use console.
    682  1.1  pooka 	 */
    683  1.1  pooka 	pmap_devmap_bootstrap(l1pagetable, viper_devmap);
    684  1.1  pooka 
    685  1.1  pooka 	/*
    686  1.1  pooka 	 * Give the XScale global cache clean code an appropriately
    687  1.1  pooka 	 * sized chunk of unmapped VA space starting at 0xff000000
    688  1.1  pooka 	 * (our device mappings end before this address).
    689  1.1  pooka 	 */
    690  1.1  pooka 	xscale_cache_clean_addr = 0xff000000U;
    691  1.1  pooka 
    692  1.1  pooka 	/*
    693  1.1  pooka 	 * Now we have the real page tables in place so we can switch to them.
    694  1.1  pooka 	 * Once this is done we will be running with the REAL kernel page
    695  1.1  pooka 	 * tables.
    696  1.1  pooka 	 */
    697  1.1  pooka 
    698  1.1  pooka 	/*
    699  1.1  pooka 	 * Update the physical_freestart/physical_freeend/free_pages
    700  1.1  pooka 	 * variables.
    701  1.1  pooka 	 */
    702  1.1  pooka 	{
    703  1.1  pooka 		extern char _end[];
    704  1.1  pooka 
    705  1.1  pooka 		physical_freestart = physical_start +
    706  1.1  pooka 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    707  1.1  pooka 		     KERNEL_BASE);
    708  1.1  pooka 		physical_freeend = physical_end;
    709  1.1  pooka 		free_pages =
    710  1.1  pooka 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    711  1.1  pooka 	}
    712  1.1  pooka 
    713  1.1  pooka 	/* Switch tables */
    714  1.1  pooka #ifdef VERBOSE_INIT_ARM
    715  1.1  pooka 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    716  1.1  pooka 	       physical_freestart, free_pages, free_pages);
    717  1.1  pooka 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    718  1.1  pooka #endif
    719  1.1  pooka 
    720  1.1  pooka 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    721  1.1  pooka 	setttb(kernel_l1pt.pv_pa);
    722  1.1  pooka 	cpu_tlb_flushID();
    723  1.1  pooka 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    724  1.1  pooka 
    725  1.1  pooka 	/*
    726  1.1  pooka 	 * Moved from cpu_startup() as data_abort_handler() references
    727  1.1  pooka 	 * this during uvm init
    728  1.1  pooka 	 */
    729  1.1  pooka 	proc0paddr = (struct user *)kernelstack.pv_va;
    730  1.1  pooka 	lwp0.l_addr = proc0paddr;
    731  1.1  pooka 
    732  1.1  pooka #ifdef VERBOSE_INIT_ARM
    733  1.1  pooka 	printf("bootstrap done.\n");
    734  1.1  pooka #endif
    735  1.1  pooka 
    736  1.1  pooka 	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
    737  1.1  pooka 
    738  1.1  pooka 	/*
    739  1.1  pooka 	 * Pages were allocated during the secondary bootstrap for the
    740  1.1  pooka 	 * stacks for different CPU modes.
    741  1.1  pooka 	 * We must now set the r13 registers in the different CPU modes to
    742  1.1  pooka 	 * point to these stacks.
    743  1.1  pooka 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    744  1.1  pooka 	 * of the stack memory.
    745  1.1  pooka 	 */
    746  1.1  pooka 	printf("init subsystems: stacks ");
    747  1.1  pooka 
    748  1.1  pooka 	set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    749  1.1  pooka 	set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    750  1.1  pooka 	set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    751  1.1  pooka 
    752  1.1  pooka 	/*
    753  1.1  pooka 	 * Well we should set a data abort handler.
    754  1.1  pooka 	 * Once things get going this will change as we will need a proper
    755  1.1  pooka 	 * handler.
    756  1.1  pooka 	 * Until then we will use a handler that just panics but tells us
    757  1.1  pooka 	 * why.
    758  1.1  pooka 	 * Initialisation of the vectors will just panic on a data abort.
    759  1.1  pooka 	 * This just fills in a slightly better one.
    760  1.1  pooka 	 */
    761  1.1  pooka 	printf("vectors ");
    762  1.1  pooka 	data_abort_handler_address = (u_int)data_abort_handler;
    763  1.1  pooka 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    764  1.1  pooka 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    765  1.1  pooka 
    766  1.1  pooka 	/* Initialise the undefined instruction handlers */
    767  1.1  pooka 	printf("undefined ");
    768  1.1  pooka 	undefined_init();
    769  1.1  pooka 
    770  1.1  pooka 	/* Load memory into UVM. */
    771  1.1  pooka 	printf("page ");
    772  1.1  pooka 	uvm_setpagesize();        /* initialize PAGE_SIZE-dependent variables */
    773  1.1  pooka 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    774  1.1  pooka 	    atop(physical_freestart), atop(physical_freeend),
    775  1.1  pooka 	    VM_FREELIST_DEFAULT);
    776  1.1  pooka 
    777  1.1  pooka 	/* Boot strap pmap telling it where the kernel page table is */
    778  1.1  pooka 	printf("pmap ");
    779  1.1  pooka 	pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
    780  1.1  pooka 	    KERNEL_VM_BASE + KERNEL_VM_SIZE);
    781  1.1  pooka 
    782  1.1  pooka #ifdef __HAVE_MEMORY_DISK__
    783  1.1  pooka 	md_root_setconf(memory_disk, sizeof memory_disk);
    784  1.1  pooka #endif
    785  1.1  pooka 
    786  1.1  pooka #ifdef IPKDB
    787  1.1  pooka 	/* Initialise ipkdb */
    788  1.1  pooka 	ipkdb_init();
    789  1.1  pooka 	if (boothowto & RB_KDB)
    790  1.1  pooka 		ipkdb_connect(0);
    791  1.1  pooka #endif
    792  1.1  pooka 
    793  1.1  pooka #ifdef KGDB
    794  1.1  pooka 	if (boothowto & RB_KDB) {
    795  1.1  pooka 		kgdb_debug_init = 1;
    796  1.1  pooka 		kgdb_connect(1);
    797  1.1  pooka 	}
    798  1.1  pooka #endif
    799  1.1  pooka 
    800  1.1  pooka #ifdef DDB
    801  1.1  pooka 	db_machine_init();
    802  1.1  pooka 
    803  1.1  pooka 	/* Firmware doesn't load symbols. */
    804  1.1  pooka 	ddb_init(0, NULL, NULL);
    805  1.1  pooka 
    806  1.1  pooka 	if (boothowto & RB_KDB)
    807  1.1  pooka 		Debugger();
    808  1.1  pooka #endif
    809  1.1  pooka 
    810  1.1  pooka 	/* We return the new stack pointer address */
    811  1.1  pooka 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    812  1.1  pooka }
    813  1.1  pooka 
    814  1.1  pooka #if 0
    815  1.1  pooka void
    816  1.1  pooka process_kernel_args(char *args)
    817  1.1  pooka {
    818  1.1  pooka 
    819  1.1  pooka 	boothowto = 0;
    820  1.1  pooka 
    821  1.1  pooka 	/* Make a local copy of the bootargs */
    822  1.1  pooka 	strncpy(bootargs, args, MAX_BOOT_STRING);
    823  1.1  pooka 
    824  1.1  pooka 	args = bootargs;
    825  1.1  pooka 	boot_file = bootargs;
    826  1.1  pooka 
    827  1.1  pooka 	/* Skip the kernel image filename */
    828  1.1  pooka 	while (*args != ' ' && *args != 0)
    829  1.1  pooka 		++args;
    830  1.1  pooka 
    831  1.1  pooka 	if (*args != 0)
    832  1.1  pooka 		*args++ = 0;
    833  1.1  pooka 
    834  1.1  pooka 	while (*args == ' ')
    835  1.1  pooka 		++args;
    836  1.1  pooka 
    837  1.1  pooka 	boot_args = args;
    838  1.1  pooka 
    839  1.1  pooka 	printf("bootfile: %s\n", boot_file);
    840  1.1  pooka 	printf("bootargs: %s\n", boot_args);
    841  1.1  pooka 
    842  1.1  pooka 	parse_mi_bootargs(boot_args);
    843  1.1  pooka }
    844  1.1  pooka #endif
    845  1.1  pooka 
    846  1.1  pooka #ifdef KGDB
    847  1.1  pooka #ifndef KGDB_DEVNAME
    848  1.1  pooka #define KGDB_DEVNAME "ffuart"
    849  1.1  pooka #endif
    850  1.1  pooka const char kgdb_devname[] = KGDB_DEVNAME;
    851  1.1  pooka 
    852  1.1  pooka #if (NCOM > 0)
    853  1.1  pooka #ifndef KGDB_DEVMODE
    854  1.1  pooka #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    855  1.1  pooka #endif
    856  1.1  pooka int comkgdbmode = KGDB_DEVMODE;
    857  1.1  pooka #endif /* NCOM */
    858  1.1  pooka 
    859  1.1  pooka #endif /* KGDB */
    860  1.1  pooka 
    861  1.1  pooka 
    862  1.1  pooka void
    863  1.1  pooka consinit(void)
    864  1.1  pooka {
    865  1.1  pooka 	static int consinit_called = 0;
    866  1.1  pooka 	uint32_t ckenreg = ioreg_read(VIPER_CLKMAN_VBASE+CLKMAN_CKEN);
    867  1.1  pooka #if 0
    868  1.1  pooka 	char *console = CONSDEVNAME;
    869  1.1  pooka #endif
    870  1.1  pooka 
    871  1.1  pooka 	if (consinit_called != 0)
    872  1.1  pooka 		return;
    873  1.1  pooka 	consinit_called = 1;
    874  1.1  pooka 
    875  1.1  pooka #if NCOM > 0
    876  1.1  pooka 
    877  1.1  pooka #ifdef FFUARTCONSOLE
    878  1.1  pooka #ifdef KGDB
    879  1.1  pooka 	if (0 == strcmp(kgdb_devname, "ffuart")) {
    880  1.1  pooka 		/* port is reserved for kgdb */
    881  1.1  pooka 	} else
    882  1.1  pooka #endif
    883  1.1  pooka 	if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
    884  1.1  pooka 		     comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
    885  1.1  pooka 
    886  1.1  pooka #if 0
    887  1.1  pooka 		/* XXX: can't call pxa2x0_clkman_config yet */
    888  1.1  pooka 		pxa2x0_clkman_config(CKEN_FFUART, 1);
    889  1.1  pooka #else
    890  1.1  pooka 		ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN,
    891  1.1  pooka 		    ckenreg|CKEN_FFUART);
    892  1.1  pooka #endif
    893  1.1  pooka 
    894  1.1  pooka 		return;
    895  1.1  pooka 	}
    896  1.1  pooka 
    897  1.1  pooka #endif /* FFUARTCONSOLE */
    898  1.1  pooka 
    899  1.1  pooka #ifdef BTUARTCONSOLE
    900  1.1  pooka #ifdef KGDB
    901  1.1  pooka 	if (0 == strcmp(kgdb_devname, "btuart")) {
    902  1.1  pooka 		/* port is reserved for kgdb */
    903  1.1  pooka 	} else
    904  1.1  pooka #endif
    905  1.1  pooka 	if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
    906  1.1  pooka 		comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
    907  1.1  pooka 		ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN,
    908  1.1  pooka 		    ckenreg|CKEN_BTUART);
    909  1.1  pooka 		return;
    910  1.1  pooka 	}
    911  1.1  pooka #endif /* BTUARTCONSOLE */
    912  1.1  pooka 
    913  1.1  pooka 	/* no console, guess we're flying blind */
    914  1.1  pooka 
    915  1.1  pooka #endif /* NCOM */
    916  1.1  pooka 
    917  1.1  pooka }
    918  1.1  pooka 
    919  1.1  pooka #ifdef KGDB
    920  1.1  pooka void
    921  1.1  pooka kgdb_port_init(void)
    922  1.1  pooka {
    923  1.1  pooka #if (NCOM > 0) && defined(COM_PXA2X0)
    924  1.1  pooka 	paddr_t paddr = 0;
    925  1.1  pooka 	uint32_t ckenreg = ioreg_read(VIPER_CLKMAN_VBASE+CLKMAN_CKEN);
    926  1.1  pooka 
    927  1.1  pooka 	if (0 == strcmp(kgdb_devname, "ffuart")) {
    928  1.1  pooka 		paddr = PXA2X0_FFUART_BASE;
    929  1.1  pooka 		ckenreg |= CKEN_FFUART;
    930  1.1  pooka 	}
    931  1.1  pooka 	else if (0 == strcmp(kgdb_devname, "btuart")) {
    932  1.1  pooka 		paddr = PXA2X0_BTUART_BASE;
    933  1.1  pooka 		ckenreg |= CKEN_BTUART;
    934  1.1  pooka 	}
    935  1.1  pooka 
    936  1.1  pooka 	if (paddr &&
    937  1.1  pooka 	    0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
    938  1.1  pooka 		kgdb_rate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
    939  1.1  pooka 
    940  1.1  pooka 		ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN, ckenreg);
    941  1.1  pooka 	}
    942  1.1  pooka #endif
    943  1.1  pooka }
    944  1.1  pooka #endif
    945