Home | History | Annotate | Line # | Download | only in ixm1200
ixm1200_machdep.c revision 1.40
      1 /*	$NetBSD: ixm1200_machdep.c,v 1.40 2009/03/14 15:36:05 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.40 2009/03/14 15:36:05 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(int howto, char *bootstr)
    235 {
    236 	/*
    237 	 * If we are still cold then hit the air brakes
    238 	 * and crash to earth fast
    239 	 */
    240 	if (cold) {
    241 		doshutdownhooks();
    242 		pmf_system_shutdown(boothowto);
    243 		printf("Halted while still in the ICE age.\n");
    244 		printf("The operating system has halted.\n");
    245 		printf("Please press any key to reboot.\n\n");
    246 		cngetc();
    247 		printf("rebooting...\n");
    248 		ixp12x0_reset();
    249 	}
    250 
    251 	/* Disable console buffering */
    252 	cnpollc(1);
    253 
    254 	/*
    255 	 * If RB_NOSYNC was not specified sync the discs.
    256 	 * Note: Unless cold is set to 1 here, syslogd will die during the unmount.
    257 	 * It looks like syslogd is getting woken up only to find that it cannot
    258 	 * page part of the binary in as the filesystem has been unmounted.
    259 	 */
    260 	if (!(howto & RB_NOSYNC))
    261 		bootsync();
    262 
    263 	/* Say NO to interrupts */
    264 	splhigh();
    265 
    266 	/* Do a dump if requested. */
    267 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    268 		dumpsys();
    269 
    270 	/* Run any shutdown hooks */
    271 	doshutdownhooks();
    272 
    273 	pmf_system_shutdown(boothowto);
    274 
    275 	/* Make sure IRQ's are disabled */
    276 	IRQdisable;
    277 
    278 	if (howto & RB_HALT) {
    279 		printf("The operating system has halted.\n");
    280 		printf("Please press any key to reboot.\n\n");
    281 		cngetc();
    282 	}
    283 
    284 	printf("rebooting...\n");
    285 
    286 	/* all interrupts are disabled */
    287 	disable_interrupts(I32_bit);
    288 
    289 	ixp12x0_reset();
    290 
    291 	/* ...and if that didn't work, just croak. */
    292 	printf("RESET FAILED!\n");
    293 	for (;;);
    294 }
    295 
    296 /* Static device mappings. */
    297 static const struct pmap_devmap ixm1200_devmap[] = {
    298 	/* StrongARM System and Peripheral Registers */
    299 	{
    300 		IXP12X0_SYS_VBASE,
    301 		IXP12X0_SYS_HWBASE,
    302 		IXP12X0_SYS_SIZE,
    303 		VM_PROT_READ|VM_PROT_WRITE,
    304 		PTE_NOCACHE,
    305 	},
    306 	/* PCI Registers Accessible Through StrongARM Core */
    307 	{
    308 		IXP12X0_PCI_VBASE, IXP12X0_PCI_HWBASE,
    309 		IXP12X0_PCI_SIZE,
    310 		VM_PROT_READ|VM_PROT_WRITE,
    311 		PTE_NOCACHE,
    312 	},
    313 	/* PCI Registers Accessible Through I/O Cycle Access */
    314 	{
    315 		IXP12X0_PCI_IO_VBASE, IXP12X0_PCI_IO_HWBASE,
    316 		IXP12X0_PCI_IO_SIZE,
    317 		VM_PROT_READ|VM_PROT_WRITE,
    318 		PTE_NOCACHE,
    319 	},
    320 	/* PCI Type0 Configuration Space */
    321 	{
    322 		IXP12X0_PCI_TYPE0_VBASE, IXP12X0_PCI_TYPE0_HWBASE,
    323 		IXP12X0_PCI_TYPE0_SIZE,
    324 		VM_PROT_READ|VM_PROT_WRITE,
    325 		PTE_NOCACHE,
    326 	},
    327 	/* PCI Type1 Configuration Space */
    328 	{
    329 		IXP12X0_PCI_TYPE1_VBASE, IXP12X0_PCI_TYPE1_HWBASE,
    330 		IXP12X0_PCI_TYPE1_SIZE,
    331 		VM_PROT_READ|VM_PROT_WRITE,
    332 		PTE_NOCACHE,
    333 	},
    334 	{
    335 		0,
    336 		0,
    337 		0,
    338 		0,
    339 		0
    340 	},
    341 };
    342 
    343 /*
    344  * Initial entry point on startup. This gets called before main() is
    345  * entered.
    346  * It should be responsible for setting up everything that must be
    347  * in place when main is called.
    348  * This includes
    349  *   Taking a copy of the boot configuration structure.
    350  *   Initialising the physical console so characters can be printed.
    351  *   Setting up page tables for the kernel
    352  *   Relocating the kernel to the bottom of physical memory
    353  */
    354 u_int
    355 initarm(void *arg)
    356 {
    357         int loop;
    358 	int loop1;
    359 	u_int kerneldatasize, symbolsize;
    360 	vaddr_t l1pagetable;
    361 	vaddr_t freemempos;
    362 #if NKSYMS || defined(DDB) || defined(MODULAR)
    363         Elf_Shdr *sh;
    364 #endif
    365 
    366         /*
    367          * Since we map v0xf0000000 == p0x90000000, it's possible for
    368          * us to initialize the console now.
    369          */
    370 	consinit();
    371 
    372 #ifdef VERBOSE_INIT_ARM
    373 	/* Talk to the user */
    374 	printf("\nNetBSD/evbarm (IXM1200) booting ...\n");
    375 #endif
    376 
    377 	/*
    378 	 * Heads up ... Setup the CPU / MMU / TLB functions
    379 	 */
    380 	if (set_cpufuncs())
    381 		panic("CPU not recognized!");
    382 
    383 	/* XXX overwrite bootconfig to hardcoded values */
    384 	bootconfig.dram[0].address = 0xc0000000;
    385 	bootconfig.dram[0].pages   = 0x10000000 / PAGE_SIZE; /* SDRAM 256MB */
    386 	bootconfig.dramblocks = 1;
    387 
    388 	kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
    389 
    390 	symbolsize = 0;
    391 
    392 #ifdef PMAP_DEBUG
    393 	pmap_debug(-1);
    394 #endif
    395 
    396 #if NKSYMS || defined(DDB) || defined(MODULAR)
    397         if (! memcmp(&end, "\177ELF", 4)) {
    398                 sh = (Elf_Shdr *)((char *)&end + ((Elf_Ehdr *)&end)->e_shoff);
    399                 loop = ((Elf_Ehdr *)&end)->e_shnum;
    400                 for(; loop; loop--, sh++)
    401                         if (sh->sh_offset > 0 &&
    402                             (sh->sh_offset + sh->sh_size) > symbolsize)
    403                                 symbolsize = sh->sh_offset + sh->sh_size;
    404         }
    405 #endif
    406 #ifdef VERBOSE_INIT_ARM
    407 	printf("kernsize=0x%x\n", kerneldatasize);
    408 #endif
    409 	kerneldatasize += symbolsize;
    410 	kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8;
    411 
    412 	/*
    413 	 * Set up the variables that define the availablilty of physcial
    414 	 * memory
    415 	 */
    416 	physical_start = bootconfig.dram[0].address;
    417 	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
    418 
    419 	physical_freestart = physical_start
    420 		+ (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
    421 	physical_freeend = physical_end;
    422 
    423 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    424 
    425 	freemempos = 0xc0000000;
    426 
    427 #ifdef VERBOSE_INIT_ARM
    428 	printf("Allocating page tables\n");
    429 #endif
    430 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    431 
    432 #ifdef VERBOSE_INIT_ARM
    433 	printf("CP15 Register1 = 0x%08x\n", cpu_get_control());
    434 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    435 		physical_freestart, free_pages, free_pages);
    436 	printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
    437 		physical_start, physical_end);
    438 #endif
    439 
    440 	/* Define a macro to simplify memory allocation */
    441 #define valloc_pages(var, np)			\
    442 	alloc_pages((var).pv_pa, (np));		\
    443 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    444 #define alloc_pages(var, np)				\
    445 	(var) = freemempos;				\
    446 	memset((char *)(var), 0, ((np) * PAGE_SIZE));	\
    447 	freemempos += (np) * PAGE_SIZE;
    448 
    449 	loop1 = 0;
    450 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    451 		/* Are we 16KB aligned for an L1 ? */
    452 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    453 		    && kernel_l1pt.pv_pa == 0) {
    454 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    455 		} else {
    456 			valloc_pages(kernel_pt_table[loop1],
    457 			    L2_TABLE_SIZE / PAGE_SIZE);
    458 			++loop1;
    459 		}
    460 	}
    461 
    462 #ifdef DIAGNOSTIC
    463 	/* This should never be able to happen but better confirm that. */
    464 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    465 		panic("initarm: Failed to align the kernel page directory");
    466 #endif
    467 
    468 	/*
    469 	 * Allocate a page for the system page mapped to V0x00000000
    470 	 * This page will just contain the system vectors and can be
    471 	 * shared by all processes.
    472 	 */
    473 	alloc_pages(systempage.pv_pa, 1);
    474 
    475 	/* Allocate stacks for all modes */
    476 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    477 	valloc_pages(abtstack, ABT_STACK_SIZE);
    478 	valloc_pages(undstack, UND_STACK_SIZE);
    479 	valloc_pages(kernelstack, UPAGES);
    480 
    481 #ifdef VERBOSE_INIT_ARM
    482 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va);
    483 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va);
    484 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va);
    485 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va);
    486 #endif
    487 
    488 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    489 
    490 #ifdef CPU_IXP12X0
    491         /*
    492          * XXX totally stuffed hack to work round problems introduced
    493          * in recent versions of the pmap code. Due to the calls used there
    494          * we cannot allocate virtual memory during bootstrap.
    495          */
    496 	for(;;) {
    497 		alloc_pages(ixp12x0_cc_base, 1);
    498 		if (! (ixp12x0_cc_base & (CPU_IXP12X0_CACHE_CLEAN_SIZE - 1)))
    499 			break;
    500 	}
    501 	{
    502 		vaddr_t dummy;
    503 		alloc_pages(dummy, CPU_IXP12X0_CACHE_CLEAN_SIZE / PAGE_SIZE - 1);
    504 	}
    505 	ixp12x0_cache_clean_addr = ixp12x0_cc_base;
    506 	ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2;
    507 #endif /* CPU_IXP12X0 */
    508 
    509 #ifdef VERBOSE_INIT_ARM
    510 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    511 #endif
    512 
    513 	/*
    514 	 * Now we start construction of the L1 page table
    515 	 * We start by mapping the L2 page tables into the L1.
    516 	 * This means that we can replace L1 mappings later on if necessary
    517 	 */
    518 	l1pagetable = kernel_l1pt.pv_pa;
    519 
    520 	/* Map the L2 pages tables in the L1 page table */
    521 	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
    522 	    &kernel_pt_table[KERNEL_PT_SYS]);
    523 
    524 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    525 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    526 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    527 
    528 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    529 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    530 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    531 
    532 	/* update the top of the kernel VM */
    533 	pmap_curmaxkvaddr =
    534 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    535 
    536 	pmap_link_l2pt(l1pagetable, IXP12X0_IO_VBASE,
    537 	    &kernel_pt_table[KERNEL_PT_IO]);
    538 
    539 #ifdef VERBOSE_INIT_ARM
    540 	printf("Mapping kernel\n");
    541 #endif
    542 
    543 #if XXX
    544 	/* Now we fill in the L2 pagetable for the kernel code/data */
    545 	{
    546 		extern char etext[], _end[];
    547 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    548 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    549 		u_int logical;
    550 
    551 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    552 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    553 
    554 		logical = 0x00200000;   /* offset of kernel in RAM */
    555 
    556 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    557 		    physical_start + logical, textsize,
    558 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    559 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    560 		    physical_start + logical, totalsize - textsize,
    561 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    562 	}
    563 #else
    564 	{
    565 		pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE,
    566                     KERNEL_TEXT_BASE, kerneldatasize,
    567                     VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    568 	}
    569 #endif
    570 
    571 #ifdef VERBOSE_INIT_ARM
    572         printf("Constructing L2 page tables\n");
    573 #endif
    574 
    575 	/* Map the stack pages */
    576 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    577 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    578 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    579 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    580 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    581 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    582 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    583 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    584 
    585 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    586 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    587 
    588 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    589 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    590 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    591 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    592 	}
    593 
    594 	/* Map the vector page. */
    595 	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
    596 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    597 
    598 #ifdef VERBOSE_INIT_ARM
    599 	printf("systempage (vector page): p0x%08lx v0x%08lx\n",
    600 	       systempage.pv_pa, vector_page);
    601 #endif
    602 
    603 	/* Map the statically mapped devices. */
    604 	pmap_devmap_bootstrap(l1pagetable, ixm1200_devmap);
    605 
    606 #ifdef VERBOSE_INIT_ARM
    607 	printf("done.\n");
    608 #endif
    609 
    610 	/*
    611 	 * Map the Dcache Flush page.
    612 	 * Hw Ref Manual 3.2.4.5 Software Dcache Flush
    613 	 */
    614 	pmap_map_chunk(l1pagetable, ixp12x0_cache_clean_addr, 0xe0000000,
    615 	    CPU_IXP12X0_CACHE_CLEAN_SIZE, VM_PROT_READ, PTE_CACHE);
    616 
    617 	/*
    618 	 * Now we have the real page tables in place so we can switch to them.
    619 	 * Once this is done we will be running with the REAL kernel page
    620 	 * tables.
    621 	 */
    622 
    623 	/* Switch tables */
    624 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    625 	setttb(kernel_l1pt.pv_pa);
    626 	cpu_tlb_flushID();
    627 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    628 
    629 	/*
    630 	 * Moved here from cpu_startup() as data_abort_handler() references
    631 	 * this during init
    632 	 */
    633 	proc0paddr = (struct user *)kernelstack.pv_va;
    634 	lwp0.l_addr = proc0paddr;
    635 
    636 	/*
    637 	 * We must now clean the cache again....
    638 	 * Cleaning may be done by reading new data to displace any
    639 	 * dirty data in the cache. This will have happened in setttb()
    640 	 * but since we are boot strapping the addresses used for the read
    641 	 * may have just been remapped and thus the cache could be out
    642 	 * of sync. A re-clean after the switch will cure this.
    643 	 * After booting there are no gross reloations of the kernel thus
    644 	 * this problem will not occur after initarm().
    645 	 */
    646 	cpu_idcache_wbinv_all();
    647 
    648 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    649 
    650 	/*
    651 	 * Pages were allocated during the secondary bootstrap for the
    652 	 * stacks for different CPU modes.
    653 	 * We must now set the r13 registers in the different CPU modes to
    654 	 * point to these stacks.
    655 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    656 	 * of the stack memory.
    657 	 */
    658 #ifdef VERBOSE_INIT_ARM
    659 	printf("init subsystems: stacks ");
    660 #endif
    661 
    662 	set_stackptr(PSR_IRQ32_MODE,
    663 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    664 	set_stackptr(PSR_ABT32_MODE,
    665 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    666 	set_stackptr(PSR_UND32_MODE,
    667 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    668 #ifdef PMAP_DEBUG
    669 	if (pmap_debug_level >= 0)
    670 		printf("kstack V%08lx P%08lx\n", kernelstack.pv_va,
    671 		    kernelstack.pv_pa);
    672 #endif  /* PMAP_DEBUG */
    673 
    674 	/*
    675 	 * Well we should set a data abort handler.
    676 	 * Once things get going this will change as we will need a proper
    677 	 * handler. Until then we will use a handler that just panics but
    678 	 * tells us why.
    679 	 * Initialisation of the vetcors will just panic on a data abort.
    680 	 * This just fills in a slightly better one.
    681 	 */
    682 #ifdef VERBOSE_INIT_ARM
    683 	printf("vectors ");
    684 #endif
    685 	data_abort_handler_address = (u_int)data_abort_handler;
    686 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    687 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    688 #ifdef VERBOSE_INIT_ARM
    689 	printf("\ndata_abort_handler_address = %08x\n", data_abort_handler_address);
    690 	printf("prefetch_abort_handler_address = %08x\n", prefetch_abort_handler_address);
    691 	printf("undefined_handler_address = %08x\n", undefined_handler_address);
    692 #endif
    693 
    694 	/* Initialise the undefined instruction handlers */
    695 #ifdef VERBOSE_INIT_ARM
    696 	printf("undefined ");
    697 #endif
    698 	undefined_init();
    699 
    700 	/* Load memory into UVM. */
    701 #ifdef VERBOSE_INIT_ARM
    702 	printf("page ");
    703 #endif
    704 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    705 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    706 	    atop(physical_freestart), atop(physical_freeend),
    707 	    VM_FREELIST_DEFAULT);
    708 
    709 	/* Boot strap pmap telling it where the kernel page table is */
    710 #ifdef VERBOSE_INIT_ARM
    711 	printf("pmap ");
    712 #endif
    713 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    714 
    715 	/* Setup the IRQ system */
    716 #ifdef VERBOSE_INIT_ARM
    717 	printf("irq ");
    718 #endif
    719 	ixp12x0_intr_init();
    720 
    721 #ifdef VERBOSE_INIT_ARM
    722 	printf("done.\n");
    723 #endif
    724 
    725 #ifdef VERBOSE_INIT_ARM
    726 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    727 		physical_freestart, free_pages, free_pages);
    728 	printf("freemempos=%08lx\n", freemempos);
    729 	printf("switching to new L1 page table  @%#lx... \n", kernel_l1pt.pv_pa);
    730 #endif
    731 
    732 	consinit();
    733 #ifdef VERBOSE_INIT_ARM
    734 	printf("consinit \n");
    735 #endif
    736 
    737 	ixdp_ixp12x0_cc_setup();
    738 
    739 #ifdef VERBOSE_INIT_ARM
    740 	printf("bootstrap done.\n");
    741 #endif
    742 
    743 #if NKSYMS || defined(DDB) || defined(MODULAR)
    744 	ksyms_addsyms_elf(symbolsize, ((int *)&end), ((char *)&end) + symbolsize);
    745 #endif
    746 
    747 #ifdef DDB
    748 	db_machine_init();
    749 	if (boothowto & RB_KDB)
    750 		Debugger();
    751 #endif
    752 
    753 	/* We return the new stack pointer address */
    754 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    755 }
    756 
    757 void
    758 consinit(void)
    759 {
    760 	static int consinit_called = 0;
    761 
    762 	if (consinit_called != 0)
    763 		return;
    764 
    765 	consinit_called = 1;
    766 
    767 	pmap_devmap_register(ixm1200_devmap);
    768 
    769 	if (ixpcomcnattach(&ixp12x0_bs_tag,
    770 			   IXPCOM_UART_HWBASE, IXPCOM_UART_VBASE,
    771 			   CONSPEED, CONMODE))
    772 		panic("can't init serial console @%lx", IXPCOM_UART_HWBASE);
    773 }
    774 
    775 /*
    776  * For optimal cache cleaning we need two 16K banks of
    777  * virtual address space that NOTHING else will access
    778  * and then we alternate the cache cleaning between the
    779  * two banks.
    780  * The cache cleaning code requires requires 2 banks aligned
    781  * on total size boundry so the banks can be alternated by
    782  * eorring the size bit (assumes the bank size is a power of 2)
    783  */
    784 void
    785 ixdp_ixp12x0_cc_setup(void)
    786 {
    787 	int loop;
    788 	paddr_t kaddr;
    789 	pt_entry_t *pte;
    790 
    791 	(void) pmap_extract(pmap_kernel(), KERNEL_TEXT_BASE, &kaddr);
    792 	for (loop = 0; loop < CPU_IXP12X0_CACHE_CLEAN_SIZE; loop += PAGE_SIZE) {
    793                 pte = vtopte(ixp12x0_cc_base + loop);
    794                 *pte = L2_S_PROTO | kaddr |
    795                     L2_S_PROT(PTE_KERNEL, VM_PROT_READ) | pte_l2_s_cache_mode;
    796 		PTE_SYNC(pte);
    797         }
    798 	ixp12x0_cache_clean_addr = ixp12x0_cc_base;
    799 	ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2;
    800 }
    801