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