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