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