Home | History | Annotate | Line # | Download | only in ixdp425
ixdp425_machdep.c revision 1.21
      1 /*	$NetBSD: ixdp425_machdep.c,v 1.21 2009/03/14 14:45:58 dsl Exp $ */
      2 /*
      3  * Copyright (c) 2003
      4  *	Ichiro FUKUHARA <ichiro (at) ichiro.org>.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Ichiro FUKUHARA.
     18  * 4. The name of the company nor the name of the author may be used to
     19  *    endorse or promote products derived from this software without specific
     20  *    prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
     26  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 /*
     35  * Copyright (c) 1997,1998 Mark Brinicombe.
     36  * Copyright (c) 1997,1998 Causality Limited.
     37  * All rights reserved.
     38  *
     39  * Redistribution and use in source and binary forms, with or without
     40  * modification, are permitted provided that the following conditions
     41  * are met:
     42  * 1. Redistributions of source code must retain the above copyright
     43  *    notice, this list of conditions and the following disclaimer.
     44  * 2. Redistributions in binary form must reproduce the above copyright
     45  *    notice, this list of conditions and the following disclaimer in the
     46  *    documentation and/or other materials provided with the distribution.
     47  * 3. All advertising materials mentioning features or use of this software
     48  *    must display the following acknowledgement:
     49  *	This product includes software developed by Mark Brinicombe
     50  *	for the NetBSD Project.
     51  * 4. The name of the company nor the name of the author may be used to
     52  *    endorse or promote products derived from this software without specific
     53  *    prior written permission.
     54  *
     55  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     56  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     57  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     58  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     59  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     60  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     61  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     62  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     63  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     64  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     65  * SUCH DAMAGE.
     66  */
     67 
     68 /* Machine dependant functions for kernel setup for Intel IXP425 evaluation
     69  * boards using RedBoot firmware.
     70  */
     71 
     72 #include <sys/cdefs.h>
     73 __KERNEL_RCSID(0, "$NetBSD: ixdp425_machdep.c,v 1.21 2009/03/14 14:45:58 dsl Exp $");
     74 
     75 #include "opt_ddb.h"
     76 #include "opt_kgdb.h"
     77 #include "opt_pmap_debug.h"
     78 
     79 #include <sys/param.h>
     80 #include <sys/device.h>
     81 #include <sys/systm.h>
     82 #include <sys/kernel.h>
     83 #include <sys/exec.h>
     84 #include <sys/proc.h>
     85 #include <sys/msgbuf.h>
     86 #include <sys/reboot.h>
     87 #include <sys/termios.h>
     88 #include <sys/ksyms.h>
     89 
     90 #include <uvm/uvm_extern.h>
     91 
     92 #include <dev/cons.h>
     93 
     94 #include <machine/db_machdep.h>
     95 #include <ddb/db_sym.h>
     96 #include <ddb/db_extern.h>
     97 
     98 #include <machine/bootconfig.h>
     99 #include <machine/bus.h>
    100 #include <machine/cpu.h>
    101 #include <machine/frame.h>
    102 #include <arm/undefined.h>
    103 
    104 #include <arm/arm32/machdep.h>
    105 
    106 #include <arm/xscale/ixp425reg.h>
    107 #include <arm/xscale/ixp425var.h>
    108 #include <arm/xscale/ixp425_sipvar.h>
    109 
    110 #include <evbarm/ixdp425/ixdp425reg.h>
    111 
    112 #include "com.h"
    113 #if NCOM > 0
    114 #include <dev/ic/comreg.h>
    115 #include <dev/ic/comvar.h>
    116 #endif
    117 
    118 #include "ksyms.h"
    119 
    120 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    121 #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
    122 #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    123 
    124 /*
    125  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    126  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    127  */
    128 #define	KERNEL_VM_SIZE		0x0C000000
    129 
    130 
    131 /*
    132  * Address to call from cpu_reset() to reset the machine.
    133  * This is machine architecture dependant as it varies depending
    134  * on where the ROM appears when you turn the MMU off.
    135  */
    136 
    137 u_int cpu_reset_address = 0x00000000;
    138 
    139 /* Define various stack sizes in pages */
    140 #define IRQ_STACK_SIZE	1
    141 #define ABT_STACK_SIZE	1
    142 #define UND_STACK_SIZE	1
    143 
    144 BootConfig bootconfig;		/* Boot config storage */
    145 char *boot_args = NULL;
    146 char *boot_file = NULL;
    147 
    148 vm_offset_t physical_start;
    149 vm_offset_t physical_freestart;
    150 vm_offset_t physical_freeend;
    151 vm_offset_t physical_end;
    152 u_int free_pages;
    153 vm_offset_t pagetables_start;
    154 int physmem = 0;
    155 
    156 /* Physical and virtual addresses for some global pages */
    157 pv_addr_t irqstack;
    158 pv_addr_t undstack;
    159 pv_addr_t abtstack;
    160 pv_addr_t kernelstack;
    161 pv_addr_t minidataclean;
    162 
    163 vm_offset_t msgbufphys;
    164 
    165 extern u_int data_abort_handler_address;
    166 extern u_int prefetch_abort_handler_address;
    167 extern u_int undefined_handler_address;
    168 extern int end;
    169 
    170 #ifdef PMAP_DEBUG
    171 extern int pmap_debug_level;
    172 #endif
    173 
    174 #define KERNEL_PT_SYS		0	/* L2 table for mapping zero page */
    175 
    176 #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
    177 #define	KERNEL_PT_KERNEL_NUM	4
    178 #define	KERNEL_PT_IO		(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    179 					/* L2 tables for mapping kernel VM */
    180 #define KERNEL_PT_VMDATA	(KERNEL_PT_IO + 1)
    181 #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    182 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    183 
    184 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    185 
    186 struct user *proc0paddr;
    187 
    188 /* Prototypes */
    189 
    190 void	consinit(void);
    191 u_int	cpu_get_control(void);
    192 
    193 /*
    194  * Define the default console speed for the board.  This is generally
    195  * what the firmware provided with the board defaults to.
    196  */
    197 #ifndef CONSPEED
    198 #define CONSPEED B115200
    199 #endif /* ! CONSPEED */
    200 
    201 #ifndef CONUNIT
    202 #define	CONUNIT	0
    203 #endif
    204 
    205 #ifndef CONMODE
    206 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
    207 #endif
    208 
    209 int comcnspeed = CONSPEED;
    210 int comcnmode = CONMODE;
    211 int comcnunit = CONUNIT;
    212 
    213 #if KGDB
    214 #ifndef KGDB_DEVNAME
    215 #error Must define KGDB_DEVNAME
    216 #endif
    217 const char kgdb_devname[] = KGDB_DEVNAME;
    218 
    219 #ifndef KGDB_DEVADDR
    220 #error Must define KGDB_DEVADDR
    221 #endif
    222 unsigned long kgdb_devaddr = KGDB_DEVADDR;
    223 
    224 #ifndef KGDB_DEVRATE
    225 #define KGDB_DEVRATE	CONSPEED
    226 #endif
    227 int kgdb_devrate = KGDB_DEVRATE;
    228 
    229 #ifndef KGDB_DEVMODE
    230 #define KGDB_DEVMODE	CONMODE
    231 #endif
    232 int kgdb_devmode = KGDB_DEVMODE;
    233 #endif /* KGDB */
    234 
    235 /*
    236  * void cpu_reboot(int howto, char *bootstr)
    237  *
    238  * Reboots the system
    239  *
    240  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    241  * then reset the CPU.
    242  */
    243 void
    244 cpu_reboot(int howto, char *bootstr)
    245 {
    246 	u_int32_t reg;
    247 
    248 #ifdef DIAGNOSTIC
    249 	/* info */
    250 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    251 #endif
    252 
    253 	/*
    254 	 * If we are still cold then hit the air brakes
    255 	 * and crash to earth fast
    256 	 */
    257 	if (cold) {
    258 		doshutdownhooks();
    259 		pmf_system_shutdown(boothowto);
    260 		printf("The operating system has halted.\n");
    261 		printf("Please press any key to reboot.\n\n");
    262 		cngetc();
    263 		printf("rebooting...\n");
    264 		goto reset;
    265 	}
    266 
    267 	/* Disable console buffering */
    268 
    269 	/*
    270 	 * If RB_NOSYNC was not specified sync the discs.
    271 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    272 	 * unmount.  It looks like syslogd is getting woken up only to find
    273 	 * that it cannot page part of the binary in as the filesystem has
    274 	 * been unmounted.
    275 	 */
    276 	if (!(howto & RB_NOSYNC))
    277 		bootsync();
    278 
    279 	/* Say NO to interrupts */
    280 	splhigh();
    281 
    282 	/* Do a dump if requested. */
    283 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    284 		dumpsys();
    285 
    286 	/* Run any shutdown hooks */
    287 	doshutdownhooks();
    288 
    289 	pmf_system_shutdown(boothowto);
    290 
    291 	/* Make sure IRQ's are disabled */
    292 	IRQdisable;
    293 
    294 	if (howto & RB_HALT) {
    295 		printf("The operating system has halted.\n");
    296 		printf("Please press any key to reboot.\n\n");
    297 		cngetc();
    298 	}
    299 
    300 	printf("rebooting...\n\r");
    301  reset:
    302 	/*
    303 	 * Make really really sure that all interrupts are disabled,
    304 	 */
    305 	(void) disable_interrupts(I32_bit|F32_bit);
    306 	IXPREG(IXP425_INT_ENABLE) = 0;
    307 
    308 	/*
    309 	 * Map the boot Flash device down at physical address 0.
    310 	 * This is safe since NetBSD runs out of an alias of
    311 	 * SDRAM at 0x10000000.
    312 	 */
    313 	reg = EXP_CSR_READ_4(ixpsip_softc, EXP_CNFG0_OFFSET);
    314 	reg |= EXP_CNFG0_MEM_MAP;
    315 	EXP_CSR_WRITE_4(ixpsip_softc, EXP_CNFG0_OFFSET, reg);
    316 
    317 	/*
    318 	 * Jump into the bootcode's reset vector
    319 	 *
    320 	 * XXX:
    321 	 * Redboot doesn't like the state in which we leave the PCI
    322 	 * ethernet card, and so fails to detect it on reboot. This
    323 	 * pretty much necessitates a hard reset/power cycle to be
    324 	 * able to download a new kernel image over ethernet.
    325 	 *
    326 	 * I suspect this is due to a bug in Redboot's i82557 driver.
    327 	 */
    328 	cpu_reset();
    329 
    330 	/* ...and if that didn't work, just croak. */
    331 	printf("RESET FAILED!\n");
    332 	for (;;);
    333 }
    334 
    335 /* Static device mappings. */
    336 static const struct pmap_devmap ixp425_devmap[] = {
    337 	/* Physical/Virtual address for I/O space */
    338     {
    339 	IXP425_IO_VBASE,
    340 	IXP425_IO_HWBASE,
    341 	IXP425_IO_SIZE,
    342 	VM_PROT_READ|VM_PROT_WRITE,
    343 	PTE_NOCACHE,
    344     },
    345 
    346 	/* Expansion Bus */
    347     {
    348 	IXP425_EXP_VBASE,
    349 	IXP425_EXP_HWBASE,
    350 	IXP425_EXP_SIZE,
    351 	VM_PROT_READ|VM_PROT_WRITE,
    352 	PTE_NOCACHE,
    353     },
    354 
    355 	/* IXP425 PCI Configuration */
    356     {
    357 	IXP425_PCI_VBASE,
    358 	IXP425_PCI_HWBASE,
    359 	IXP425_PCI_SIZE,
    360 	VM_PROT_READ|VM_PROT_WRITE,
    361 	PTE_NOCACHE,
    362     },
    363 
    364 	/* SDRAM Controller */
    365     {
    366 	IXP425_MCU_VBASE,
    367 	IXP425_MCU_HWBASE,
    368 	IXP425_MCU_SIZE,
    369 	VM_PROT_READ|VM_PROT_WRITE,
    370 	PTE_NOCACHE,
    371     },
    372 
    373 	/* PCI Memory Space */
    374     {
    375 	IXP425_PCI_MEM_VBASE,
    376 	IXP425_PCI_MEM_HWBASE,
    377 	IXP425_PCI_MEM_SIZE,
    378 	VM_PROT_READ|VM_PROT_WRITE,
    379 	PTE_NOCACHE,
    380     },
    381 
    382     {
    383 	0,
    384 	0,
    385 	0,
    386 	0,
    387 	0,
    388     }
    389 };
    390 
    391 /*
    392  * u_int initarm(...)
    393  *
    394  * Initial entry point on startup. This gets called before main() is
    395  * entered.
    396  * It should be responsible for setting up everything that must be
    397  * in place when main is called.
    398  * This includes
    399  *   Taking a copy of the boot configuration structure.
    400  *   Initialising the physical console so characters can be printed.
    401  *   Setting up page tables for the kernel
    402  *   Relocating the kernel to the bottom of physical memory
    403  */
    404 u_int
    405 initarm(void *arg)
    406 {
    407 	extern vaddr_t xscale_cache_clean_addr;
    408 #ifdef DIAGNOSTIC
    409 	extern vsize_t xscale_minidata_clean_size;
    410 #endif
    411 	int loop;
    412 	int loop1;
    413 	u_int kerneldatasize;
    414 	u_int l1pagetable;
    415 	u_int freemempos;
    416 
    417 	/*
    418 	 * Since we map v0xf0000000 == p0xc8000000, it's possible for
    419 	 * us to initialize the console now.
    420 	 */
    421 	consinit();
    422 
    423 #ifdef VERBOSE_INIT_ARM
    424 	/* Talk to the user */
    425 	printf("\nNetBSD/evbarm (Intel IXDP425) booting ...\n");
    426 #endif
    427 
    428 	/*
    429 	 * Heads up ... Setup the CPU / MMU / TLB functions
    430 	 */
    431 	if (set_cpufuncs())
    432 		panic("cpu not recognized!");
    433 
    434 	/* XXX overwrite bootconfig to hardcoded values */
    435 	bootconfig.dramblocks = 1;
    436 	bootconfig.dram[0].address = 0x10000000;
    437 	bootconfig.dram[0].pages = ixp425_sdram_size() / PAGE_SIZE;
    438 
    439 	kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
    440 
    441 #ifdef VERBOSE_INIT_ARM
    442         printf("kernsize=0x%x\n", kerneldatasize);
    443 #endif
    444         kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8;
    445 
    446 	/*
    447 	 * Set up the variables that define the availablilty of
    448 	 * physical memory.  For now, we're going to set
    449 	 * physical_freestart to 0x10200000 (where the kernel
    450 	 * was loaded), and allocate the memory we need downwards.
    451 	 * If we get too close to the L1 table that we set up, we
    452 	 * will panic.  We will update physical_freestart and
    453 	 * physical_freeend later to reflect what pmap_bootstrap()
    454 	 * wants to see.
    455 	 *
    456 	 * XXX pmap_bootstrap() needs an enema.
    457 	 */
    458 	physical_start = bootconfig.dram[0].address;
    459 	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
    460 
    461 	physical_freestart = physical_start
    462                 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
    463         physical_freeend = physical_end;
    464 
    465 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    466 
    467 	/* Tell the user about the memory */
    468 #ifdef VERBOSE_INIT_ARM
    469 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    470 	    physical_start, physical_end - 1);
    471 
    472 	printf("Allocating page tables\n");
    473 #endif
    474 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    475 
    476 	freemempos = 0x10000000;
    477 
    478 #ifdef VERBOSE_INIT_ARM
    479         printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
    480                 physical_start, physical_end);
    481 #endif
    482 
    483 	/* Define a macro to simplify memory allocation */
    484 #define	valloc_pages(var, np)				\
    485 	alloc_pages((var).pv_pa, (np));			\
    486 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    487 
    488 #if 0
    489 #define alloc_pages(var, np)				\
    490 	physical_freeend -= ((np) * PAGE_SIZE);		\
    491 	if (physical_freeend < physical_freestart)	\
    492 		panic("initarm: out of memory");	\
    493 	(var) = physical_freeend;			\
    494 	free_pages -= (np);				\
    495 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    496 #else
    497 #define alloc_pages(var, np)				\
    498         (var) = freemempos;                             \
    499         memset((char *)(var), 0, ((np) * PAGE_SIZE));   \
    500         freemempos += (np) * PAGE_SIZE;
    501 #endif
    502 
    503 	loop1 = 0;
    504 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    505 		/* Are we 16KB aligned for an L1 ? */
    506 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    507 		    && kernel_l1pt.pv_pa == 0) {
    508 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    509 		} else {
    510 			valloc_pages(kernel_pt_table[loop1],
    511 			    L2_TABLE_SIZE / PAGE_SIZE);
    512 			++loop1;
    513 		}
    514 	}
    515 
    516 	/* This should never be able to happen but better confirm that. */
    517 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    518 		panic("initarm: Failed to align the kernel page directory");
    519 
    520 	/*
    521 	 * Allocate a page for the system page.
    522 	 * This page will just contain the system vectors and can be
    523 	 * shared by all processes.
    524 	 */
    525 	alloc_pages(systempage.pv_pa, 1);
    526 
    527 	/* Allocate stacks for all modes */
    528 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    529 	valloc_pages(abtstack, ABT_STACK_SIZE);
    530 	valloc_pages(undstack, UND_STACK_SIZE);
    531 	valloc_pages(kernelstack, UPAGES);
    532 
    533 	/* Allocate enough pages for cleaning the Mini-Data cache. */
    534 	KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
    535 	valloc_pages(minidataclean, 1);
    536 
    537 #ifdef VERBOSE_INIT_ARM
    538 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    539 	    irqstack.pv_va);
    540 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    541 	    abtstack.pv_va);
    542 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    543 	    undstack.pv_va);
    544 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    545 	    kernelstack.pv_va);
    546 #endif
    547 
    548 	/*
    549 	 * XXX Defer this to later so that we can reclaim the memory
    550 	 * XXX used by the RedBoot page tables.
    551 	 */
    552 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    553 
    554 	/*
    555 	 * Ok we have allocated physical pages for the primary kernel
    556 	 * page tables
    557 	 */
    558 
    559 #ifdef VERBOSE_INIT_ARM
    560 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    561 #endif
    562 
    563 	/*
    564 	 * Now we start construction of the L1 page table
    565 	 * We start by mapping the L2 page tables into the L1.
    566 	 * This means that we can replace L1 mappings later on if necessary
    567 	 */
    568 	l1pagetable = kernel_l1pt.pv_pa;
    569 
    570 	/* Map the L2 pages tables in the L1 page table */
    571 	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
    572 	    &kernel_pt_table[KERNEL_PT_SYS]);
    573 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    574 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    575 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    576 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    577 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    578 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    579 
    580 	/* update the top of the kernel VM */
    581 	pmap_curmaxkvaddr =
    582 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    583 
    584 	pmap_link_l2pt(l1pagetable, IXP425_IO_VBASE,
    585 	    &kernel_pt_table[KERNEL_PT_IO]);
    586 
    587 #ifdef VERBOSE_INIT_ARM
    588 	printf("Mapping kernel\n");
    589 #endif
    590 
    591 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    592 	{
    593 		extern char etext[], _end[];
    594 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    595 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    596 		u_int logical;
    597 
    598 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    599 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    600 
    601 		logical = 0x00200000;	/* offset of kernel in RAM */
    602 
    603 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    604 		    physical_start + logical, textsize,
    605 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    606 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    607 		    physical_start + logical, totalsize - textsize,
    608 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    609 	}
    610 
    611 #ifdef VERBOSE_INIT_ARM
    612 	printf("Constructing L2 page tables\n");
    613 #endif
    614 
    615 	/* Map the stack pages */
    616 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    617 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    618 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    619 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    620 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    621 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    622 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    623 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    624 
    625 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    626 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    627 
    628 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    629 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    630 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    631 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    632 	}
    633 
    634 	/* Map the Mini-Data cache clean area. */
    635 	xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
    636 	    minidataclean.pv_pa);
    637 
    638 	/* Map the vector page. */
    639 	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
    640 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    641 
    642         /*
    643          * Map the IXP425 registers
    644          */
    645 	pmap_devmap_bootstrap(l1pagetable, ixp425_devmap);
    646 
    647 	/*
    648 	 * Give the XScale global cache clean code an appropriately
    649 	 * sized chunk of unmapped VA space starting at 0xff000000
    650 	 * (our device mappings end before this address).
    651 	 */
    652 	xscale_cache_clean_addr = 0xff000000U;
    653 
    654 	/*
    655 	 * Now we have the real page tables in place so we can switch to them.
    656 	 * Once this is done we will be running with the REAL kernel page
    657 	 * tables.
    658 	 */
    659 
    660 	/*
    661 	 * Update the physical_freestart/physical_freeend/free_pages
    662 	 * variables.
    663 	 */
    664 	{
    665 		extern char _end[];
    666 
    667 		physical_freestart = physical_start +
    668 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    669 		     KERNEL_BASE);
    670 		physical_freeend = physical_end;
    671 		free_pages =
    672 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    673 	}
    674 
    675 	/* Switch tables */
    676 #ifdef VERBOSE_INIT_ARM
    677 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    678 	       physical_freestart, free_pages, free_pages);
    679 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    680 #endif
    681 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    682 	setttb(kernel_l1pt.pv_pa);
    683 	cpu_tlb_flushID();
    684 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    685 
    686 	/*
    687 	 * Moved from cpu_startup() as data_abort_handler() references
    688 	 * this during uvm init
    689 	 */
    690 	proc0paddr = (struct user *)kernelstack.pv_va;
    691 	lwp0.l_addr = proc0paddr;
    692 
    693 #ifdef VERBOSE_INIT_ARM
    694 	printf("bootstrap done.\n");
    695 #endif
    696 
    697 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    698 
    699 	/*
    700 	 * Pages were allocated during the secondary bootstrap for the
    701 	 * stacks for different CPU modes.
    702 	 * We must now set the r13 registers in the different CPU modes to
    703 	 * point to these stacks.
    704 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    705 	 * of the stack memory.
    706 	 */
    707 #ifdef VERBOSE_INIT_ARM
    708 	printf("init subsystems: stacks ");
    709 #endif
    710 
    711 	set_stackptr(PSR_IRQ32_MODE,
    712 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    713 	set_stackptr(PSR_ABT32_MODE,
    714 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    715 	set_stackptr(PSR_UND32_MODE,
    716 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    717 
    718 	/*
    719 	 * Well we should set a data abort handler.
    720 	 * Once things get going this will change as we will need a proper
    721 	 * handler.
    722 	 * Until then we will use a handler that just panics but tells us
    723 	 * why.
    724 	 * Initialisation of the vectors will just panic on a data abort.
    725 	 * This just fills in a slightly better one.
    726 	 */
    727 #ifdef VERBOSE_INIT_ARM
    728 	printf("vectors ");
    729 #endif
    730 	data_abort_handler_address = (u_int)data_abort_handler;
    731 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    732 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    733 
    734 	/* Initialise the undefined instruction handlers */
    735 #ifdef VERBOSE_INIT_ARM
    736 	printf("undefined ");
    737 #endif
    738 	undefined_init();
    739 
    740 	/* Load memory into UVM. */
    741 #ifdef VERBOSE_INIT_ARM
    742 	printf("page ");
    743 #endif
    744 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    745 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    746 	    atop(physical_freestart), atop(physical_freeend),
    747 	    VM_FREELIST_DEFAULT);
    748 
    749 	/* Boot strap pmap telling it where the kernel page table is */
    750 #ifdef VERBOSE_INIT_ARM
    751 	printf("pmap ");
    752 #endif
    753 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    754 
    755 	/* Setup the IRQ system */
    756 #ifdef VERBOSE_INIT_ARM
    757 	printf("irq ");
    758 #endif
    759 	ixp425_intr_init();
    760 #ifdef VERBOSE_INIT_ARM
    761 	printf("\nAll initialize done!\nNow Starting NetBSD, Hear we go!\n");
    762 #endif
    763 
    764 #ifdef BOOTHOWTO
    765 	boothowto = BOOTHOWTO;
    766 #endif
    767 
    768 #ifdef DDB
    769 	db_machine_init();
    770 	if (boothowto & RB_KDB)
    771 		Debugger();
    772 #endif
    773 
    774 	/* We return the new stack pointer address */
    775 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    776 }
    777 
    778 /*
    779  * consinit
    780  */
    781 void
    782 consinit(void)
    783 {
    784 	static int consinit_called;
    785 	static const bus_addr_t addrs[2] = {
    786 		IXP425_UART0_HWBASE, IXP425_UART1_HWBASE
    787 	};
    788 
    789 	if (consinit_called != 0)
    790 		return;
    791 
    792 	consinit_called = 1;
    793 
    794 	pmap_devmap_register(ixp425_devmap);
    795 
    796 	if (comcnattach(&ixp425_a4x_bs_tag, addrs[comcnunit],
    797 	    comcnspeed, IXP425_UART_FREQ, COM_TYPE_PXA2x0, comcnmode))
    798 		panic("can't init serial console (UART%d)", comcnunit);
    799 }
    800