Home | History | Annotate | Line # | Download | only in ixm1200
ixm1200_machdep.c revision 1.23
      1 /*	$NetBSD: ixm1200_machdep.c,v 1.23 2003/05/17 23:47:01 thorpej 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.23 2003/05/17 23:47:01 thorpej Exp $");
     71 
     72 #include "opt_ddb.h"
     73 #include "opt_pmap_debug.h"
     74 
     75 #include <sys/param.h>
     76 #include <sys/device.h>
     77 #include <sys/systm.h>
     78 #include <sys/kernel.h>
     79 #include <sys/exec.h>
     80 #include <sys/proc.h>
     81 #include <sys/msgbuf.h>
     82 #include <sys/reboot.h>
     83 #include <sys/termios.h>
     84 #include <sys/ksyms.h>
     85 
     86 #include <uvm/uvm_extern.h>
     87 
     88 #include <dev/cons.h>
     89 
     90 #include "ksyms.h"
     91 
     92 #if NKSYMS || defined(DDB) || defined(LKM)
     93 #include <machine/db_machdep.h>
     94 #include <ddb/db_sym.h>
     95 #include <ddb/db_extern.h>
     96 #ifndef DB_ELFSIZE
     97 #error Must define DB_ELFSIZE!
     98 #endif
     99 #define ELFSIZE	DB_ELFSIZE
    100 #include <sys/exec_elf.h>
    101 #endif
    102 
    103 #include <machine/bootconfig.h>
    104 #include <machine/bus.h>
    105 #include <machine/cpu.h>
    106 #include <machine/frame.h>
    107 #include <arm/undefined.h>
    108 
    109 #include <arm/arm32/machdep.h>
    110 
    111 #include <arm/ixp12x0/ixp12x0reg.h>
    112 #include <arm/ixp12x0/ixp12x0var.h>
    113 #include <arm/ixp12x0/ixp12x0_comreg.h>
    114 #include <arm/ixp12x0/ixp12x0_comvar.h>
    115 #include <arm/ixp12x0/ixp12x0_pcireg.h>
    116 
    117 #include <evbarm/ixm1200/ixm1200reg.h>
    118 #include <evbarm/ixm1200/ixm1200var.h>
    119 
    120 #include "opt_ipkdb.h"
    121 
    122 /* XXX for consinit related hacks */
    123 #include <sys/conf.h>
    124 
    125 void ixp12x0_reset(void) __attribute__((noreturn));
    126 
    127 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    128 #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
    129 
    130 /*
    131  * Address to call from cpu_reset() to reset the machine.
    132  * This is machine architecture dependant as it varies depending
    133  * on where the ROM appears when you turn the MMU off.
    134  */
    135 
    136 u_int cpu_reset_address = (u_int) ixp12x0_reset;
    137 
    138 /*
    139  * Define the default console speed for the board.
    140  */
    141 #ifndef CONMODE
    142 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB)) | CS8) /* 8N1 */
    143 #endif
    144 #ifndef CONSPEED
    145 #define CONSPEED B38400
    146 #endif
    147 #ifndef CONADDR
    148 #define CONADDR IXPCOM_UART_BASE
    149 #endif
    150 
    151 /* Define various stack sizes in pages */
    152 #define IRQ_STACK_SIZE  1
    153 #define ABT_STACK_SIZE  1
    154 #ifdef IPKDB
    155 #define UND_STACK_SIZE  2
    156 #else
    157 #define UND_STACK_SIZE  1
    158 #endif
    159 
    160 BootConfig bootconfig;          /* Boot config storage */
    161 char *boot_args = NULL;
    162 char *boot_file = NULL;
    163 
    164 vm_offset_t physical_start;
    165 vm_offset_t physical_freestart;
    166 vm_offset_t physical_freeend;
    167 vm_offset_t physical_end;
    168 u_int free_pages;
    169 vm_offset_t pagetables_start;
    170 int physmem = 0;
    171 
    172 /*int debug_flags;*/
    173 #ifndef PMAP_STATIC_L1S
    174 int max_processes = 64;                 /* Default number */
    175 #endif  /* !PMAP_STATIC_L1S */
    176 
    177 /* Physical and virtual addresses for some global pages */
    178 pv_addr_t systempage;
    179 pv_addr_t irqstack;
    180 pv_addr_t undstack;
    181 pv_addr_t abtstack;
    182 pv_addr_t kernelstack;
    183 
    184 vm_offset_t msgbufphys;
    185 
    186 extern u_int data_abort_handler_address;
    187 extern u_int prefetch_abort_handler_address;
    188 extern u_int undefined_handler_address;
    189 extern int end;
    190 
    191 #ifdef PMAP_DEBUG
    192 extern int pmap_debug_level;
    193 #endif  /* PMAP_DEBUG */
    194 
    195 #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    196 #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    197 #define KERNEL_PT_KERNEL_NUM	2
    198 #define KERNEL_PT_IO		(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    199 					/* Page table for mapping IO */
    200 #define KERNEL_PT_VMDATA	(KERNEL_PT_IO + 1)
    201 					/* Page tables for mapping kernel VM */
    202 #define KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    203 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    204 
    205 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    206 
    207 struct user *proc0paddr;
    208 
    209 #ifdef CPU_IXP12X0
    210 #define CPU_IXP12X0_CACHE_CLEAN_SIZE (0x4000 * 2)
    211 extern unsigned int ixp12x0_cache_clean_addr;
    212 extern unsigned int ixp12x0_cache_clean_size;
    213 static vaddr_t ixp12x0_cc_base;
    214 #endif  /* CPU_IXP12X0 */
    215 
    216 /* Prototypes */
    217 
    218 void consinit		__P((void));
    219 u_int cpu_get_control	__P((void));
    220 
    221 void ixdp_ixp12x0_cc_setup(void);
    222 
    223 extern int db_trapper(u_int, u_int, trapframe_t *, int);
    224 
    225 /*
    226  * void cpu_reboot(int howto, char *bootstr)
    227  *
    228  * Reboots the system
    229  *
    230  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    231  * then reset the CPU.
    232  */
    233 
    234 void
    235 cpu_reboot(howto, bootstr)
    236 	int howto;
    237 	char *bootstr;
    238 {
    239 	/*
    240 	 * If we are still cold then hit the air brakes
    241 	 * and crash to earth fast
    242 	 */
    243 	if (cold) {
    244 		doshutdownhooks();
    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 	/* 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 /*
    297  * Initial entry point on startup. This gets called before main() is
    298  * entered.
    299  * It should be responsible for setting up everything that must be
    300  * in place when main is called.
    301  * This includes
    302  *   Taking a copy of the boot configuration structure.
    303  *   Initialising the physical console so characters can be printed.
    304  *   Setting up page tables for the kernel
    305  *   Relocating the kernel to the bottom of physical memory
    306  */
    307 u_int
    308 initarm(void *arg)
    309 {
    310         int loop;
    311 	int loop1;
    312 	u_int kerneldatasize, symbolsize;
    313 	vaddr_t l1pagetable;
    314 	vaddr_t freemempos;
    315 	pv_addr_t kernel_l1pt;
    316 #if NKSYMS || defined(DDB) || defined(LKM)
    317         Elf_Shdr *sh;
    318 #endif
    319 
    320         /*
    321          * Since we map v0xf0000000 == p0x90000000, it's possible for
    322          * us to initialize the console now.
    323          */
    324 	consinit();
    325 
    326 #ifdef VERBOSE_INIT_ARM
    327 	/* Talk to the user */
    328 	printf("\nNetBSD/evbarm (IXM1200) booting ...\n");
    329 #endif
    330 
    331 	/*
    332 	 * Heads up ... Setup the CPU / MMU / TLB functions
    333 	 */
    334 	if (set_cpufuncs())
    335 		panic("cpu not recognized!");
    336 
    337 	/* XXX overwrite bootconfig to hardcoded values */
    338 	bootconfig.dram[0].address = 0xc0000000;
    339 	bootconfig.dram[0].pages   = 0x10000000 / PAGE_SIZE; /* SDRAM 256MB */
    340 	bootconfig.dramblocks = 1;
    341 
    342 	kerneldatasize = (u_int32_t)&end - (u_int32_t)KERNEL_TEXT_BASE;
    343 
    344 	symbolsize = 0;
    345 
    346 #ifdef PMAP_DEBUG
    347 	pmap_debug(-1);
    348 #endif
    349 
    350 #if NKSYMS || defined(DDB) || defined(LKM)
    351         if (! memcmp(&end, "\177ELF", 4)) {
    352                 sh = (Elf_Shdr *)((char *)&end + ((Elf_Ehdr *)&end)->e_shoff);
    353                 loop = ((Elf_Ehdr *)&end)->e_shnum;
    354                 for(; loop; loop--, sh++)
    355                         if (sh->sh_offset > 0 &&
    356                             (sh->sh_offset + sh->sh_size) > symbolsize)
    357                                 symbolsize = sh->sh_offset + sh->sh_size;
    358         }
    359 #endif
    360 #ifdef VERBOSE_INIT_ARM
    361 	printf("kernsize=0x%x\n", kerneldatasize);
    362 #endif
    363 	kerneldatasize += symbolsize;
    364 	kerneldatasize = ((kerneldatasize - 1) & ~(PAGE_SIZE * 4 - 1)) + PAGE_SIZE * 8;
    365 
    366 	/*
    367 	 * Set up the variables that define the availablilty of physcial
    368 	 * memory
    369 	 */
    370 	physical_start = bootconfig.dram[0].address;
    371 	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
    372 
    373 	physical_freestart = physical_start
    374 		+ (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
    375 	physical_freeend = physical_end;
    376 
    377 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    378 
    379 	freemempos = 0xc0000000;
    380 
    381 #ifdef VERBOSE_INIT_ARM
    382 	printf("Allocating page tables\n");
    383 #endif
    384 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    385 
    386 #ifdef VERBOSE_INIT_ARM
    387 	printf("CP15 Register1 = 0x%08x\n", cpu_get_control());
    388 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    389 		physical_freestart, free_pages, free_pages);
    390 	printf("physical_start = 0x%08lx, physical_end = 0x%08lx\n",
    391 		physical_start, physical_end);
    392 #endif
    393 
    394 	/* Define a macro to simplify memory allocation */
    395 #define valloc_pages(var, np)			\
    396 	alloc_pages((var).pv_pa, (np));		\
    397 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    398 #define alloc_pages(var, np)				\
    399 	(var) = freemempos;				\
    400 	memset((char *)(var), 0, ((np) * PAGE_SIZE));	\
    401 	freemempos += (np) * PAGE_SIZE;
    402 
    403 	loop1 = 0;
    404 	kernel_l1pt.pv_pa = 0;
    405 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    406 		/* Are we 16KB aligned for an L1 ? */
    407 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    408 		    && kernel_l1pt.pv_pa == 0) {
    409 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    410 		} else {
    411 			valloc_pages(kernel_pt_table[loop1],
    412 			    L2_TABLE_SIZE / PAGE_SIZE);
    413 			++loop1;
    414 		}
    415 	}
    416 
    417 #ifdef DIAGNOSTIC
    418 	/* This should never be able to happen but better confirm that. */
    419 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    420 		panic("initarm: Failed to align the kernel page directory");
    421 #endif
    422 
    423 	/*
    424 	 * Allocate a page for the system page mapped to V0x00000000
    425 	 * This page will just contain the system vectors and can be
    426 	 * shared by all processes.
    427 	 */
    428 	alloc_pages(systempage.pv_pa, 1);
    429 
    430 	/* Allocate stacks for all modes */
    431 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    432 	valloc_pages(abtstack, ABT_STACK_SIZE);
    433 	valloc_pages(undstack, UND_STACK_SIZE);
    434 	valloc_pages(kernelstack, UPAGES);
    435 
    436 #ifdef VERBOSE_INIT_ARM
    437 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa, irqstack.pv_va);
    438 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa, abtstack.pv_va);
    439 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa, undstack.pv_va);
    440 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa, kernelstack.pv_va);
    441 #endif
    442 
    443 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    444 
    445 #ifdef CPU_IXP12X0
    446         /*
    447          * XXX totally stuffed hack to work round problems introduced
    448          * in recent versions of the pmap code. Due to the calls used there
    449          * we cannot allocate virtual memory during bootstrap.
    450          */
    451 	for(;;) {
    452 		alloc_pages(ixp12x0_cc_base, 1);
    453 		if (! (ixp12x0_cc_base & (CPU_IXP12X0_CACHE_CLEAN_SIZE - 1)))
    454 			break;
    455 	}
    456 	{
    457 		vaddr_t dummy;
    458 		alloc_pages(dummy, CPU_IXP12X0_CACHE_CLEAN_SIZE / PAGE_SIZE - 1);
    459 	}
    460 	ixp12x0_cache_clean_addr = ixp12x0_cc_base;
    461 	ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2;
    462 #endif /* CPU_IXP12X0 */
    463 
    464 #ifdef VERBOSE_INIT_ARM
    465 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    466 #endif
    467 
    468 	/*
    469 	 * Now we start construction of the L1 page table
    470 	 * We start by mapping the L2 page tables into the L1.
    471 	 * This means that we can replace L1 mappings later on if necessary
    472 	 */
    473 	l1pagetable = kernel_l1pt.pv_pa;
    474 
    475 	/* Map the L2 pages tables in the L1 page table */
    476 	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
    477 	    &kernel_pt_table[KERNEL_PT_SYS]);
    478 
    479 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    480 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    481 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    482 
    483 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    484 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    485 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    486 
    487 	/* update the top of the kernel VM */
    488 	pmap_curmaxkvaddr =
    489 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    490 
    491 	pmap_link_l2pt(l1pagetable, IXP12X0_IO_VBASE,
    492 	    &kernel_pt_table[KERNEL_PT_IO]);
    493 
    494 #ifdef VERBOSE_INIT_ARM
    495 	printf("Mapping kernel\n");
    496 #endif
    497 
    498 #if XXX
    499 	/* Now we fill in the L2 pagetable for the kernel code/data */
    500 	{
    501 		extern char etext[], _end[];
    502 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    503 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    504 		u_int logical;
    505 
    506 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    507 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    508 
    509 		logical = 0x00200000;   /* offset of kernel in RAM */
    510 
    511 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    512 		    physical_start + logical, textsize,
    513 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    514 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    515 		    physical_start + logical, totalsize - textsize,
    516 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    517 	}
    518 #else
    519 	{
    520 		pmap_map_chunk(l1pagetable, KERNEL_TEXT_BASE,
    521                     KERNEL_TEXT_BASE, kerneldatasize,
    522                     VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    523 	}
    524 #endif
    525 
    526 #ifdef VERBOSE_INIT_ARM
    527         printf("Constructing L2 page tables\n");
    528 #endif
    529 
    530 	/* Map the stack pages */
    531 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    532 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    533 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    534 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    535 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    536 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    537 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    538 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    539 
    540 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    541 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    542 
    543 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    544 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    545 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    546 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    547 	}
    548 
    549 	/* Map the vector page. */
    550 	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
    551 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    552 
    553 #ifdef VERBOSE_INIT_ARM
    554 	printf("systempage (vector page): p0x%08lx v0x%08lx\n",
    555 	       systempage.pv_pa, vector_page);
    556 #endif
    557 
    558 	/*
    559 	 * Map the PCI I/O spaces and IXP12x0 registers
    560 	 */
    561 
    562 	ixp12x0_pmap_io_reg(l1pagetable);
    563 
    564 #ifdef VERBOSE_INIT_ARM
    565 	printf("done.\n");
    566 #endif
    567 
    568 	/*
    569 	 * Map the Dcache Flush page.
    570 	 * Hw Ref Manual 3.2.4.5 Software Dcache Flush
    571 	 */
    572 	pmap_map_chunk(l1pagetable, ixp12x0_cache_clean_addr, 0xe0000000,
    573 	    CPU_IXP12X0_CACHE_CLEAN_SIZE, VM_PROT_READ, PTE_CACHE);
    574 
    575 	/*
    576 	 * Now we have the real page tables in place so we can switch to them.
    577 	 * Once this is done we will be running with the REAL kernel page
    578 	 * tables.
    579 	 */
    580 
    581 	/* Switch tables */
    582 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    583 	setttb(kernel_l1pt.pv_pa);
    584 	cpu_tlb_flushID();
    585 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    586 
    587 	/*
    588 	 * Moved here from cpu_startup() as data_abort_handler() references
    589 	 * this during init
    590 	 */
    591 	proc0paddr = (struct user *)kernelstack.pv_va;
    592 	lwp0.l_addr = proc0paddr;
    593 
    594 	/*
    595 	 * We must now clean the cache again....
    596 	 * Cleaning may be done by reading new data to displace any
    597 	 * dirty data in the cache. This will have happened in setttb()
    598 	 * but since we are boot strapping the addresses used for the read
    599 	 * may have just been remapped and thus the cache could be out
    600 	 * of sync. A re-clean after the switch will cure this.
    601 	 * After booting there are no gross reloations of the kernel thus
    602 	 * this problem will not occur after initarm().
    603 	 */
    604 	cpu_idcache_wbinv_all();
    605 
    606 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    607 
    608 	/*
    609 	 * Pages were allocated during the secondary bootstrap for the
    610 	 * stacks for different CPU modes.
    611 	 * We must now set the r13 registers in the different CPU modes to
    612 	 * point to these stacks.
    613 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    614 	 * of the stack memory.
    615 	 */
    616 #ifdef VERBOSE_INIT_ARM
    617 	printf("init subsystems: stacks ");
    618 #endif
    619 
    620 	set_stackptr(PSR_IRQ32_MODE,
    621 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    622 	set_stackptr(PSR_ABT32_MODE,
    623 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    624 	set_stackptr(PSR_UND32_MODE,
    625 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    626 #ifdef PMAP_DEBUG
    627 	if (pmap_debug_level >= 0)
    628 		printf("kstack V%08lx P%08lx\n", kernelstack.pv_va,
    629 		    kernelstack.pv_pa);
    630 #endif  /* PMAP_DEBUG */
    631 
    632 	/*
    633 	 * Well we should set a data abort handler.
    634 	 * Once things get going this will change as we will need a proper
    635 	 * handler. Until then we will use a handler that just panics but
    636 	 * tells us why.
    637 	 * Initialisation of the vetcors will just panic on a data abort.
    638 	 * This just fills in a slighly better one.
    639 	 */
    640 #ifdef VERBOSE_INIT_ARM
    641 	printf("vectors ");
    642 #endif
    643 	data_abort_handler_address = (u_int)data_abort_handler;
    644 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    645 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    646 #ifdef VERBOSE_INIT_ARM
    647 	printf("\ndata_abort_handler_address = %08x\n", data_abort_handler_address);
    648 	printf("prefetch_abort_handler_address = %08x\n", prefetch_abort_handler_address);
    649 	printf("undefined_handler_address = %08x\n", undefined_handler_address);
    650 #endif
    651 
    652 	/* Initialise the undefined instruction handlers */
    653 #ifdef VERBOSE_INIT_ARM
    654 	printf("undefined ");
    655 #endif
    656 	undefined_init();
    657 
    658 	/* Load memory into UVM. */
    659 #ifdef VERBOSE_INIT_ARM
    660 	printf("page ");
    661 #endif
    662 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    663 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    664 	    atop(physical_freestart), atop(physical_freeend),
    665 	    VM_FREELIST_DEFAULT);
    666 
    667 	/* Boot strap pmap telling it where the kernel page table is */
    668 #ifdef VERBOSE_INIT_ARM
    669 	printf("pmap ");
    670 #endif
    671 	pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
    672 	    KERNEL_VM_BASE + KERNEL_VM_SIZE);
    673 
    674 	/* Setup the IRQ system */
    675 #ifdef VERBOSE_INIT_ARM
    676 	printf("irq ");
    677 #endif
    678 	ixp12x0_intr_init();
    679 
    680 #ifdef VERBOSE_INIT_ARM
    681 	printf("done.\n");
    682 #endif
    683 
    684 #ifdef VERBOSE_INIT_ARM
    685 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    686 		physical_freestart, free_pages, free_pages);
    687 	printf("freemempos=%08lx\n", freemempos);
    688 	printf("switching to new L1 page table  @%#lx... \n", kernel_l1pt.pv_pa);
    689 #endif
    690 
    691 	consinit();
    692 #ifdef VERBOSE_INIT_ARM
    693 	printf("consinit \n");
    694 #endif
    695 
    696 	ixdp_ixp12x0_cc_setup();
    697 
    698 #ifdef VERBOSE_INIT_ARM
    699 	printf("bootstrap done.\n");
    700 #endif
    701 
    702 #ifdef IPKDB
    703 	/* Initialise ipkdb */
    704 	ipkdb_init();
    705 	if (boothowto & RB_KDB)
    706 		ipkdb_connect(0);
    707 #endif  /* NIPKDB */
    708 
    709 #if NKSYMS || defined(DDB) || defined(LKM)
    710 	ksyms_init(symbolsize, ((int *)&end), ((char *)&end) + symbolsize);
    711 #endif
    712 
    713 #ifdef DDB
    714 	{
    715 		static struct undefined_handler uh;
    716 
    717 		uh.uh_handler = db_trapper;
    718 		install_coproc_handler_static(0, &uh);
    719 	}
    720 
    721 	if (boothowto & RB_KDB)
    722 		Debugger();
    723 #endif
    724 
    725 	/* We return the new stack pointer address */
    726 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    727 }
    728 
    729 void
    730 consinit(void)
    731 {
    732 	extern struct bus_space ixpsip_bs_tag;
    733 	static int consinit_called = 0;
    734 
    735 	if (consinit_called != 0)
    736 		return;
    737 
    738 	consinit_called = 1;
    739 
    740 	if (ixpcomcnattach(&ixpsip_bs_tag,
    741 			   IXPCOM_UART_HWBASE, IXPCOM_UART_VBASE,
    742 			   CONSPEED, CONMODE))
    743 		panic("can't init serial console @%lx", IXPCOM_UART_HWBASE);
    744 }
    745 
    746 /*
    747  * For optimal cache cleaning we need two 16K banks of
    748  * virtual address space that NOTHING else will access
    749  * and then we alternate the cache cleaning between the
    750  * two banks.
    751  * The cache cleaning code requires requires 2 banks aligned
    752  * on total size boundry so the banks can be alternated by
    753  * eorring the size bit (assumes the bank size is a power of 2)
    754  */
    755 void
    756 ixdp_ixp12x0_cc_setup(void)
    757 {
    758 	int loop;
    759 	paddr_t kaddr;
    760 	pt_entry_t *pte;
    761 
    762 	(void) pmap_extract(pmap_kernel(), KERNEL_TEXT_BASE, &kaddr);
    763 	for (loop = 0; loop < CPU_IXP12X0_CACHE_CLEAN_SIZE; loop += PAGE_SIZE) {
    764                 pte = vtopte(ixp12x0_cc_base + loop);
    765                 *pte = L2_S_PROTO | kaddr |
    766                     L2_S_PROT(PTE_KERNEL, VM_PROT_READ) | pte_l2_s_cache_mode;
    767 		PTE_SYNC(pte);
    768         }
    769 	ixp12x0_cache_clean_addr = ixp12x0_cc_base;
    770 	ixp12x0_cache_clean_size = CPU_IXP12X0_CACHE_CLEAN_SIZE / 2;
    771 }
    772