Home | History | Annotate | Line # | Download | only in ixdp425
ixdp425_machdep.c revision 1.7
      1 /*	$NetBSD: ixdp425_machdep.c,v 1.7 2003/09/25 14:11:18 ichiro 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.7 2003/09/25 14:11:18 ichiro 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 
    109 #include <arm/xscale/ixp425_sipvar.h>
    110 #include <arm/xscale/ixp425_comvar.h>
    111 
    112 #include "opt_ipkdb.h"
    113 #include "ksyms.h"
    114 
    115 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    116 #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
    117 #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    118 
    119 /*
    120  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    121  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    122  */
    123 #define	KERNEL_VM_SIZE		0x0C000000
    124 
    125 
    126 /*
    127  * Address to call from cpu_reset() to reset the machine.
    128  * This is machine architecture dependant as it varies depending
    129  * on where the ROM appears when you turn the MMU off.
    130  */
    131 
    132 u_int cpu_reset_address = 0x00000000;
    133 
    134 /* Define various stack sizes in pages */
    135 #define IRQ_STACK_SIZE	1
    136 #define ABT_STACK_SIZE	1
    137 #ifdef IPKDB
    138 #define UND_STACK_SIZE	2
    139 #else
    140 #define UND_STACK_SIZE	1
    141 #endif
    142 
    143 BootConfig bootconfig;		/* Boot config storage */
    144 char *boot_args = NULL;
    145 char *boot_file = NULL;
    146 
    147 vm_offset_t physical_start;
    148 vm_offset_t physical_freestart;
    149 vm_offset_t physical_freeend;
    150 vm_offset_t physical_end;
    151 u_int free_pages;
    152 vm_offset_t pagetables_start;
    153 int physmem = 0;
    154 
    155 /*int debug_flags;*/
    156 #ifndef PMAP_STATIC_L1S
    157 int max_processes = 64;			/* Default number */
    158 #endif	/* !PMAP_STATIC_L1S */
    159 
    160 /* Physical and virtual addresses for some global pages */
    161 pv_addr_t systempage;
    162 pv_addr_t irqstack;
    163 pv_addr_t undstack;
    164 pv_addr_t abtstack;
    165 pv_addr_t kernelstack;
    166 pv_addr_t minidataclean;
    167 
    168 vm_offset_t msgbufphys;
    169 
    170 extern u_int data_abort_handler_address;
    171 extern u_int prefetch_abort_handler_address;
    172 extern u_int undefined_handler_address;
    173 extern int end;
    174 
    175 #ifdef PMAP_DEBUG
    176 extern int pmap_debug_level;
    177 #endif
    178 
    179 #define KERNEL_PT_SYS		0	/* L2 table for mapping zero page */
    180 
    181 #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
    182 #define	KERNEL_PT_KERNEL_NUM	4
    183 #define	KERNEL_PT_IO		(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    184 					/* L2 tables for mapping kernel VM */
    185 #define KERNEL_PT_VMDATA	(KERNEL_PT_IO + 1)
    186 #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    187 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    188 
    189 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    190 
    191 struct user *proc0paddr;
    192 
    193 /* Prototypes */
    194 
    195 void	consinit(void);
    196 u_int	cpu_get_control   __P((void));
    197 
    198 /*
    199  * Define the default console speed for the board.  This is generally
    200  * what the firmware provided with the board defaults to.
    201  */
    202 #ifndef CONSPEED
    203 #define CONSPEED B115200
    204 #endif /* ! CONSPEED */
    205 
    206 #ifndef CONUNIT
    207 #define	CONUNIT	0
    208 #endif
    209 
    210 #ifndef CONMODE
    211 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
    212 #endif
    213 
    214 int comcnspeed = CONSPEED;
    215 int comcnmode = CONMODE;
    216 int comcnunit = CONUNIT;
    217 
    218 #if KGDB
    219 #ifndef KGDB_DEVNAME
    220 #error Must define KGDB_DEVNAME
    221 #endif
    222 const char kgdb_devname[] = KGDB_DEVNAME;
    223 
    224 #ifndef KGDB_DEVADDR
    225 #error Must define KGDB_DEVADDR
    226 #endif
    227 unsigned long kgdb_devaddr = KGDB_DEVADDR;
    228 
    229 #ifndef KGDB_DEVRATE
    230 #define KGDB_DEVRATE	CONSPEED
    231 #endif
    232 int kgdb_devrate = KGDB_DEVRATE;
    233 
    234 #ifndef KGDB_DEVMODE
    235 #define KGDB_DEVMODE	CONMODE
    236 #endif
    237 int kgdb_devmode = KGDB_DEVMODE;
    238 #endif /* KGDB */
    239 
    240 /*
    241  * void cpu_reboot(int howto, char *bootstr)
    242  *
    243  * Reboots the system
    244  *
    245  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    246  * then reset the CPU.
    247  */
    248 void
    249 cpu_reboot(int howto, char *bootstr)
    250 {
    251 #ifdef DIAGNOSTIC
    252 	/* info */
    253 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    254 #endif
    255 
    256 	/*
    257 	 * If we are still cold then hit the air brakes
    258 	 * and crash to earth fast
    259 	 */
    260 	if (cold) {
    261 		doshutdownhooks();
    262 		printf("The operating system has halted.\n");
    263 		printf("Please press any key to reboot.\n\n");
    264 		cngetc();
    265 		printf("rebooting...\n");
    266 		goto reset;
    267 	}
    268 
    269 	/* Disable console buffering */
    270 
    271 	/*
    272 	 * If RB_NOSYNC was not specified sync the discs.
    273 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    274 	 * unmount.  It looks like syslogd is getting woken up only to find
    275 	 * that it cannot page part of the binary in as the filesystem has
    276 	 * been unmounted.
    277 	 */
    278 	if (!(howto & RB_NOSYNC))
    279 		bootsync();
    280 
    281 	/* Say NO to interrupts */
    282 	splhigh();
    283 
    284 	/* Do a dump if requested. */
    285 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    286 		dumpsys();
    287 
    288 	/* Run any shutdown hooks */
    289 	doshutdownhooks();
    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 /*
    307  * XXX system reset routine
    308  */
    309 	(void) disable_interrupts(I32_bit|F32_bit);
    310 	/* ...and if that didn't work, just croak. */
    311 	printf("RESET FAILED!\n");
    312 	for (;;);
    313 }
    314 
    315 /* Static device mappings. */
    316 static const struct pmap_devmap ixp425_devmap[] = {
    317 	/* Physical/Virtual address for I/O space */
    318     {
    319 	IXP425_IO_VBASE,
    320 	IXP425_IO_HWBASE,
    321 	IXP425_IO_SIZE,
    322 	VM_PROT_READ|VM_PROT_WRITE,
    323 	PTE_NOCACHE,
    324     },
    325 
    326 	/* Expansion Bus */
    327     {
    328 	IXP425_EXP_VBASE,
    329 	IXP425_EXP_HWBASE,
    330 	IXP425_EXP_SIZE,
    331 	VM_PROT_READ|VM_PROT_WRITE,
    332 	PTE_NOCACHE,
    333     },
    334 
    335 	/* IXP425 PCI Configuration */
    336     {
    337 	IXP425_PCI_VBASE,
    338 	IXP425_PCI_HWBASE,
    339 	IXP425_PCI_SIZE,
    340 	VM_PROT_READ|VM_PROT_WRITE,
    341 	PTE_NOCACHE,
    342     },
    343 
    344 	/* PCI Memory Space */
    345     {
    346 	IXP425_PCI_MEM_VBASE,
    347 	IXP425_PCI_MEM_HWBASE,
    348 	IXP425_PCI_MEM_SIZE,
    349 	VM_PROT_READ|VM_PROT_WRITE,
    350 	PTE_NOCACHE,
    351     },
    352 
    353     {
    354 	0,
    355 	0,
    356 	0,
    357 	0,
    358 	0,
    359     }
    360 };
    361 
    362 /*
    363  * u_int initarm(...)
    364  *
    365  * Initial entry point on startup. This gets called before main() is
    366  * entered.
    367  * It should be responsible for setting up everything that must be
    368  * in place when main is called.
    369  * This includes
    370  *   Taking a copy of the boot configuration structure.
    371  *   Initialising the physical console so characters can be printed.
    372  *   Setting up page tables for the kernel
    373  *   Relocating the kernel to the bottom of physical memory
    374  */
    375 u_int
    376 initarm(void *arg)
    377 {
    378 	extern vaddr_t xscale_cache_clean_addr;
    379 #ifdef DIAGNOSTIC
    380 	extern vsize_t xscale_minidata_clean_size;
    381 #endif
    382 	int loop;
    383 	int loop1;
    384 	u_int kerneldatasize, symbolsize;
    385 	u_int l1pagetable;
    386 	u_int freemempos;
    387 	pv_addr_t kernel_l1pt;
    388 #if 0
    389 	paddr_t memstart;
    390 	psize_t memsize;
    391 #endif
    392 
    393 	/*
    394 	 * Since we map v0xf0000000 == p0xc8000000, it's possible for
    395 	 * us to initialize the console now.
    396 	 */
    397 	consinit();
    398 
    399 #ifdef VERBOSE_INIT_ARM
    400 	/* Talk to the user */
    401 	printf("\nNetBSD/evbarm (IXP425) booting ...\n");
    402 #endif
    403 
    404 	/*
    405 	 * Heads up ... Setup the CPU / MMU / TLB functions
    406 	 */
    407 	if (set_cpufuncs())
    408 		panic("cpu not recognized!");
    409 
    410 	/* XXX overwrite bootconfig to hardcoded values */
    411 	bootconfig.dramblocks = 1;
    412 	bootconfig.dram[0].address = 0x10000000;
    413 /* XXX */
    414 #if BOARDTYPE == zao425
    415 	bootconfig.dram[0].pages = 0x04000000 / PAGE_SIZE; /* SDRAM 64MB */
    416 #elif BOARDTYPE == ixdp425
    417 	bootconfig.dram[0].pages = 0x10000000 / PAGE_SIZE; /* SDRAM 256MB */
    418 #endif
    419 
    420 	kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
    421 
    422 #ifdef VERBOSE_INIT_ARM
    423         printf("kernsize=0x%x\n", kerneldatasize);
    424 #endif
    425         kerneldatasize += symbolsize;
    426         kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8;
    427 
    428 	/*
    429 	 * Set up the variables that define the availablilty of
    430 	 * physical memory.  For now, we're going to set
    431 	 * physical_freestart to 0x10200000 (where the kernel
    432 	 * was loaded), and allocate the memory we need downwards.
    433 	 * If we get too close to the L1 table that we set up, we
    434 	 * will panic.  We will update physical_freestart and
    435 	 * physical_freeend later to reflect what pmap_bootstrap()
    436 	 * wants to see.
    437 	 *
    438 	 * XXX pmap_bootstrap() needs an enema.
    439 	 */
    440 	physical_start = bootconfig.dram[0].address;
    441 	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
    442 
    443 	physical_freestart = physical_start
    444                 + (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
    445         physical_freeend = physical_end;
    446 
    447 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    448 
    449 	/* Tell the user about the memory */
    450 #ifdef VERBOSE_INIT_ARM
    451 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    452 	    physical_start, physical_end - 1);
    453 
    454 	printf("Allocating page tables\n");
    455 #endif
    456 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    457 
    458 	freemempos = 0x10000000;
    459 
    460 #ifdef VERBOSE_INIT_ARM
    461         printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
    462                 physical_start, physical_end);
    463 #endif
    464 
    465 	/* Define a macro to simplify memory allocation */
    466 #define	valloc_pages(var, np)				\
    467 	alloc_pages((var).pv_pa, (np));			\
    468 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    469 
    470 #if 0
    471 #define alloc_pages(var, np)				\
    472 	physical_freeend -= ((np) * PAGE_SIZE);		\
    473 	if (physical_freeend < physical_freestart)	\
    474 		panic("initarm: out of memory");	\
    475 	(var) = physical_freeend;			\
    476 	free_pages -= (np);				\
    477 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    478 #else
    479 #define alloc_pages(var, np)				\
    480         (var) = freemempos;                             \
    481         memset((char *)(var), 0, ((np) * PAGE_SIZE));   \
    482         freemempos += (np) * PAGE_SIZE;
    483 #endif
    484 
    485 	loop1 = 0;
    486 	kernel_l1pt.pv_pa = 0;
    487 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    488 		/* Are we 16KB aligned for an L1 ? */
    489 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    490 		    && kernel_l1pt.pv_pa == 0) {
    491 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    492 		} else {
    493 			valloc_pages(kernel_pt_table[loop1],
    494 			    L2_TABLE_SIZE / PAGE_SIZE);
    495 			++loop1;
    496 		}
    497 	}
    498 
    499 	/* This should never be able to happen but better confirm that. */
    500 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    501 		panic("initarm: Failed to align the kernel page directory");
    502 
    503 	/*
    504 	 * Allocate a page for the system page mapped to V0x00000000
    505 	 * This page will just contain the system vectors and can be
    506 	 * shared by all processes.
    507 	 */
    508 	alloc_pages(systempage.pv_pa, 1);
    509 
    510 	/* Allocate stacks for all modes */
    511 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    512 	valloc_pages(abtstack, ABT_STACK_SIZE);
    513 	valloc_pages(undstack, UND_STACK_SIZE);
    514 	valloc_pages(kernelstack, UPAGES);
    515 
    516 	/* Allocate enough pages for cleaning the Mini-Data cache. */
    517 	KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
    518 	valloc_pages(minidataclean, 1);
    519 
    520 #ifdef VERBOSE_INIT_ARM
    521 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    522 	    irqstack.pv_va);
    523 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    524 	    abtstack.pv_va);
    525 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    526 	    undstack.pv_va);
    527 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    528 	    kernelstack.pv_va);
    529 #endif
    530 
    531 	/*
    532 	 * XXX Defer this to later so that we can reclaim the memory
    533 	 * XXX used by the RedBoot page tables.
    534 	 */
    535 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    536 
    537 	/*
    538 	 * Ok we have allocated physical pages for the primary kernel
    539 	 * page tables
    540 	 */
    541 
    542 #ifdef VERBOSE_INIT_ARM
    543 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    544 #endif
    545 
    546 	/*
    547 	 * Now we start construction of the L1 page table
    548 	 * We start by mapping the L2 page tables into the L1.
    549 	 * This means that we can replace L1 mappings later on if necessary
    550 	 */
    551 	l1pagetable = kernel_l1pt.pv_pa;
    552 
    553 	/* Map the L2 pages tables in the L1 page table */
    554 	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
    555 	    &kernel_pt_table[KERNEL_PT_SYS]);
    556 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    557 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    558 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    559 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    560 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    561 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    562 
    563 	/* update the top of the kernel VM */
    564 	pmap_curmaxkvaddr =
    565 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    566 
    567 	pmap_link_l2pt(l1pagetable, IXP425_IO_VBASE,
    568 	    &kernel_pt_table[KERNEL_PT_IO]);
    569 
    570 #ifdef VERBOSE_INIT_ARM
    571 	printf("Mapping kernel\n");
    572 #endif
    573 
    574 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    575 	{
    576 		extern char etext[], _end[];
    577 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    578 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    579 		u_int logical;
    580 
    581 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    582 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    583 
    584 		logical = 0x00200000;	/* offset of kernel in RAM */
    585 
    586 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    587 		    physical_start + logical, textsize,
    588 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    589 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    590 		    physical_start + logical, totalsize - textsize,
    591 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    592 	}
    593 
    594 #ifdef VERBOSE_INIT_ARM
    595 	printf("Constructing L2 page tables\n");
    596 #endif
    597 
    598 	/* Map the stack pages */
    599 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    600 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    601 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    602 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    603 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    604 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    605 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    606 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    607 
    608 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    609 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    610 
    611 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    612 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    613 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    614 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    615 	}
    616 
    617 	/* Map the Mini-Data cache clean area. */
    618 	xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
    619 	    minidataclean.pv_pa);
    620 
    621 	/* Map the vector page. */
    622 	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
    623 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    624 
    625         /*
    626          * Map the IXP425 registers
    627          */
    628 	pmap_devmap_bootstrap(l1pagetable, ixp425_devmap);
    629 
    630 	/*
    631 	 * Give the XScale global cache clean code an appropriately
    632 	 * sized chunk of unmapped VA space starting at 0xff000000
    633 	 * (our device mappings end before this address).
    634 	 */
    635 	xscale_cache_clean_addr = 0xff000000U;
    636 
    637 	/*
    638 	 * Now we have the real page tables in place so we can switch to them.
    639 	 * Once this is done we will be running with the REAL kernel page
    640 	 * tables.
    641 	 */
    642 
    643 	/*
    644 	 * Update the physical_freestart/physical_freeend/free_pages
    645 	 * variables.
    646 	 */
    647 	{
    648 		extern char _end[];
    649 
    650 		physical_freestart = physical_start +
    651 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    652 		     KERNEL_BASE);
    653 		physical_freeend = physical_end;
    654 		free_pages =
    655 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    656 	}
    657 
    658 	/* Switch tables */
    659 #ifdef VERBOSE_INIT_ARM
    660 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    661 	       physical_freestart, free_pages, free_pages);
    662 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    663 #endif
    664 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    665 	setttb(kernel_l1pt.pv_pa);
    666 	cpu_tlb_flushID();
    667 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    668 
    669 	/*
    670 	 * Moved from cpu_startup() as data_abort_handler() references
    671 	 * this during uvm init
    672 	 */
    673 	proc0paddr = (struct user *)kernelstack.pv_va;
    674 	lwp0.l_addr = proc0paddr;
    675 
    676 #ifdef VERBOSE_INIT_ARM
    677 	printf("bootstrap done.\n");
    678 #endif
    679 
    680 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    681 
    682 	/*
    683 	 * Pages were allocated during the secondary bootstrap for the
    684 	 * stacks for different CPU modes.
    685 	 * We must now set the r13 registers in the different CPU modes to
    686 	 * point to these stacks.
    687 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    688 	 * of the stack memory.
    689 	 */
    690 #ifdef VERBOSE_INIT_ARM
    691 	printf("init subsystems: stacks ");
    692 #endif
    693 
    694 	set_stackptr(PSR_IRQ32_MODE,
    695 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    696 	set_stackptr(PSR_ABT32_MODE,
    697 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    698 	set_stackptr(PSR_UND32_MODE,
    699 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    700 
    701 	/*
    702 	 * Well we should set a data abort handler.
    703 	 * Once things get going this will change as we will need a proper
    704 	 * handler.
    705 	 * Until then we will use a handler that just panics but tells us
    706 	 * why.
    707 	 * Initialisation of the vectors will just panic on a data abort.
    708 	 * This just fills in a slighly better one.
    709 	 */
    710 #ifdef VERBOSE_INIT_ARM
    711 	printf("vectors ");
    712 #endif
    713 	data_abort_handler_address = (u_int)data_abort_handler;
    714 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    715 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    716 
    717 	/* Initialise the undefined instruction handlers */
    718 #ifdef VERBOSE_INIT_ARM
    719 	printf("undefined ");
    720 #endif
    721 	undefined_init();
    722 
    723 	/* Load memory into UVM. */
    724 #ifdef VERBOSE_INIT_ARM
    725 	printf("page ");
    726 #endif
    727 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    728 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    729 	    atop(physical_freestart), atop(physical_freeend),
    730 	    VM_FREELIST_DEFAULT);
    731 
    732 	/* Boot strap pmap telling it where the kernel page table is */
    733 #ifdef VERBOSE_INIT_ARM
    734 	printf("pmap ");
    735 #endif
    736 	pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
    737 	    KERNEL_VM_BASE + KERNEL_VM_SIZE);
    738 
    739 	/* Setup the IRQ system */
    740 #ifdef VERBOSE_INIT_ARM
    741 	printf("irq ");
    742 #endif
    743 	ixp425_intr_init();
    744 #ifdef VERBOSE_INIT_ARM
    745 	printf("\nAll initialize done!\nNow Starting NetBSD, Hear we go!\n");
    746 #endif
    747 
    748 #ifdef BOOTHOWTO
    749 	boothowto = BOOTHOWTO;
    750 #endif
    751 
    752 #ifdef IPKDB
    753 	/* Initialise ipkdb */
    754 	ipkdb_init();
    755 	if (boothowto & RB_KDB)
    756 		ipkdb_connect(0);
    757 #endif
    758 
    759 #if NKSYMS || defined(DDB) || defined(LKM)
    760 	/* Firmware doesn't load symbols. */
    761 	ksyms_init(0, NULL, NULL);
    762 #endif
    763 
    764 #ifdef DDB
    765 	db_machine_init();
    766 	if (boothowto & RB_KDB)
    767 		Debugger();
    768 #endif
    769 
    770 	/* We return the new stack pointer address */
    771 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    772 }
    773 
    774 /*
    775  * consinit
    776  */
    777 void
    778 consinit(void)
    779 {
    780 	static int consinit_called;
    781 
    782 	if (consinit_called != 0)
    783 		return;
    784 
    785 	consinit_called = 1;
    786 
    787 	pmap_devmap_register(ixp425_devmap);
    788 
    789 	if (ixdp_ixp4xx_comcnattach(&ixpsip_bs_tag, comcnunit,
    790 				comcnspeed, FREQ, comcnmode))
    791 		panic("can't init serial console (UART%d)", comcnunit);
    792 }
    793