Home | History | Annotate | Line # | Download | only in adi_brh
brh_machdep.c revision 1.48.8.1
      1 /*	$NetBSD: brh_machdep.c,v 1.48.8.1 2020/04/20 11:28:53 bouyer Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed for the NetBSD Project by
     20  *	Wasabi Systems, Inc.
     21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  *    or promote products derived from this software without specific prior
     23  *    written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * Copyright (c) 1997,1998 Mark Brinicombe.
     40  * Copyright (c) 1997,1998 Causality Limited.
     41  * All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. All advertising materials mentioning features or use of this software
     52  *    must display the following acknowledgement:
     53  *	This product includes software developed by Mark Brinicombe
     54  *	for the NetBSD Project.
     55  * 4. The name of the company nor the name of the author may be used to
     56  *    endorse or promote products derived from this software without specific
     57  *    prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     60  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     61  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     62  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     63  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     64  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     65  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  * SUCH DAMAGE.
     70  *
     71  * Machine dependent functions for kernel setup for the ADI Engineering
     72  * BRH i80200 evaluation platform.
     73  */
     74 
     75 #include <sys/cdefs.h>
     76 __KERNEL_RCSID(0, "$NetBSD: brh_machdep.c,v 1.48.8.1 2020/04/20 11:28:53 bouyer Exp $");
     77 
     78 #include "opt_arm_debug.h"
     79 #include "opt_console.h"
     80 #include "opt_ddb.h"
     81 
     82 #include <sys/param.h>
     83 #include <sys/device.h>
     84 #include <sys/systm.h>
     85 #include <sys/kernel.h>
     86 #include <sys/exec.h>
     87 #include <sys/proc.h>
     88 #include <sys/msgbuf.h>
     89 #include <sys/reboot.h>
     90 #include <sys/termios.h>
     91 #include <sys/ksyms.h>
     92 #include <sys/bus.h>
     93 #include <sys/cpu.h>
     94 
     95 #include <uvm/uvm_extern.h>
     96 
     97 #include <dev/cons.h>
     98 
     99 #include <machine/db_machdep.h>
    100 #include <ddb/db_sym.h>
    101 #include <ddb/db_extern.h>
    102 
    103 #include <machine/bootconfig.h>
    104 #include <arm/locore.h>
    105 #include <arm/undefined.h>
    106 
    107 #include <arm/arm32/machdep.h>
    108 
    109 #include <arm/xscale/i80200reg.h>
    110 #include <arm/xscale/i80200var.h>
    111 
    112 #include <dev/pci/ppbreg.h>
    113 
    114 #include <arm/xscale/beccreg.h>
    115 #include <arm/xscale/beccvar.h>
    116 
    117 #include <evbarm/adi_brh/brhreg.h>
    118 #include <evbarm/adi_brh/brhvar.h>
    119 #include <evbarm/adi_brh/obiovar.h>
    120 
    121 #include "ksyms.h"
    122 
    123 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    124 #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
    125 #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    126 
    127 /*
    128  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    129  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    130  */
    131 #define KERNEL_VM_SIZE		0x0C000000
    132 
    133 BootConfig bootconfig;		/* Boot config storage */
    134 char *boot_args = NULL;
    135 char *boot_file = NULL;
    136 
    137 vaddr_t physical_start;
    138 vaddr_t physical_freestart;
    139 vaddr_t physical_freeend;
    140 vaddr_t physical_end;
    141 u_int free_pages;
    142 
    143 /*int debug_flags;*/
    144 #ifndef PMAP_STATIC_L1S
    145 int max_processes = 64;			/* Default number */
    146 #endif	/* !PMAP_STATIC_L1S */
    147 
    148 /* Physical and virtual addresses for some global pages */
    149 pv_addr_t minidataclean;
    150 
    151 paddr_t msgbufphys;
    152 
    153 #define KERNEL_PT_SYS		0	/* L2 table for mapping zero page */
    154 
    155 #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
    156 #define	KERNEL_PT_KERNEL_NUM	2
    157 
    158 					/* L2 tables for mapping kernel VM */
    159 #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    160 #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    161 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    162 
    163 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    164 
    165 /* Prototypes */
    166 
    167 void	consinit(void);
    168 
    169 #include "com.h"
    170 #if NCOM > 0
    171 #include <dev/ic/comreg.h>
    172 #include <dev/ic/comvar.h>
    173 #endif
    174 
    175 /*
    176  * Define the default console speed for the board.  This is generally
    177  * what the firmware provided with the board defaults to.
    178  */
    179 #ifndef CONSPEED
    180 #define CONSPEED B57600
    181 #endif /* ! CONSPEED */
    182 
    183 #ifndef CONUNIT
    184 #define	CONUNIT	0
    185 #endif
    186 
    187 #ifndef CONMODE
    188 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    189 #endif
    190 
    191 int comcnspeed = CONSPEED;
    192 int comcnmode = CONMODE;
    193 int comcnunit = CONUNIT;
    194 
    195 /*
    196  * void cpu_reboot(int howto, char *bootstr)
    197  *
    198  * Reboots the system
    199  *
    200  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    201  * then reset the CPU.
    202  */
    203 void
    204 cpu_reboot(int howto, char *bootstr)
    205 {
    206 
    207 	/*
    208 	 * If we are still cold then hit the air brakes
    209 	 * and crash to earth fast
    210 	 */
    211 	if (cold) {
    212 		doshutdownhooks();
    213 		pmf_system_shutdown(boothowto);
    214 		printf("The operating system has halted.\n");
    215 		printf("Please press any key to reboot.\n\n");
    216 		cngetc();
    217 		printf("rebooting...\n");
    218 		goto reset;
    219 	}
    220 
    221 	/* Disable console buffering */
    222 
    223 	/*
    224 	 * If RB_NOSYNC was not specified sync the discs.
    225 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    226 	 * unmount.  It looks like syslogd is getting woken up only to find
    227 	 * that it cannot page part of the binary in as the filesystem has
    228 	 * been unmounted.
    229 	 */
    230 	if (!(howto & RB_NOSYNC))
    231 		bootsync();
    232 
    233 	/* Say NO to interrupts */
    234 	splhigh();
    235 
    236 	/* Do a dump if requested. */
    237 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    238 		dumpsys();
    239 
    240 	/* Run any shutdown hooks */
    241 	doshutdownhooks();
    242 
    243 	pmf_system_shutdown(boothowto);
    244 
    245 	/* Make sure IRQ's are disabled */
    246 	IRQdisable;
    247 
    248 	if (howto & RB_HALT) {
    249 		brh_7seg('8');
    250 		printf("The operating system has halted.\n");
    251 		printf("Please press any key to reboot.\n\n");
    252 		cngetc();
    253 	}
    254 
    255 	printf("rebooting...\n\r");
    256  reset:
    257 	cpu_reset();
    258 }
    259 
    260 /* Static device mappings. */
    261 static const struct pmap_devmap brh_devmap[] = {
    262     {
    263 	BRH_PCI_CONF_VBASE,
    264 	BECC_PCI_CONF_BASE,
    265 	BRH_PCI_CONF_VSIZE,
    266 	VM_PROT_READ|VM_PROT_WRITE,
    267 	PTE_NOCACHE,
    268     },
    269     {
    270 	BRH_PCI_MEM1_VBASE,
    271 	BECC_PCI_MEM1_BASE,
    272 	BRH_PCI_MEM1_VSIZE,
    273 	VM_PROT_READ|VM_PROT_WRITE,
    274 	PTE_NOCACHE,
    275     },
    276     {
    277 	BRH_PCI_MEM2_VBASE,
    278 	BECC_PCI_MEM2_BASE,
    279 	BRH_PCI_MEM2_VSIZE,
    280 	VM_PROT_READ|VM_PROT_WRITE,
    281 	PTE_NOCACHE,
    282     },
    283     {
    284 	BRH_UART1_VBASE,
    285 	BRH_UART1_BASE,
    286 	BRH_UART1_VSIZE,
    287 	VM_PROT_READ|VM_PROT_WRITE,
    288 	PTE_NOCACHE,
    289     },
    290     {
    291 	BRH_UART2_VBASE,
    292 	BRH_UART2_BASE,
    293 	BRH_UART2_VSIZE,
    294 	VM_PROT_READ|VM_PROT_WRITE,
    295 	PTE_NOCACHE,
    296     },
    297     {
    298 	BRH_LED_VBASE,
    299 	BRH_LED_BASE,
    300 	BRH_LED_VSIZE,
    301 	VM_PROT_READ|VM_PROT_WRITE,
    302 	PTE_NOCACHE,
    303     },
    304     {
    305 	BRH_PCI_IO_VBASE,
    306 	BECC_PCI_IO_BASE,
    307 	BRH_PCI_IO_VSIZE,
    308 	VM_PROT_READ|VM_PROT_WRITE,
    309 	PTE_NOCACHE,
    310     },
    311     {
    312 	BRH_BECC_VBASE,
    313 	BECC_REG_BASE,
    314 	BRH_BECC_VSIZE,
    315 	VM_PROT_READ|VM_PROT_WRITE,
    316 	PTE_NOCACHE,
    317     },
    318     {
    319 	0,
    320 	0,
    321 	0,
    322 	0,
    323 	0,
    324     }
    325 };
    326 
    327 static void
    328 brh_hardclock_hook(void)
    329 {
    330 	static int snakefreq;
    331 
    332 	if ((snakefreq++ & 15) == 0)
    333 		brh_7seg_snake();
    334 }
    335 
    336 /*
    337  * vaddr_t initarm(...)
    338  *
    339  * Initial entry point on startup. This gets called before main() is
    340  * entered.
    341  * It should be responsible for setting up everything that must be
    342  * in place when main is called.
    343  * This includes
    344  *   Taking a copy of the boot configuration structure.
    345  *   Initialising the physical console so characters can be printed.
    346  *   Setting up page tables for the kernel
    347  *   Relocating the kernel to the bottom of physical memory
    348  */
    349 vaddr_t
    350 initarm(void *arg)
    351 {
    352 	extern vaddr_t xscale_cache_clean_addr;
    353 #ifdef DIAGNOSTIC
    354 	extern vsize_t xscale_minidata_clean_size;
    355 #endif
    356 	int loop;
    357 	int loop1;
    358 	u_int l1pagetable;
    359 	paddr_t memstart;
    360 	psize_t memsize;
    361 
    362 	/*
    363 	 * Clear out the 7-segment display.  Whee, the first visual
    364 	 * indication that we're running kernel code.
    365 	 */
    366 	brh_7seg(' ');
    367 
    368 	/*
    369 	 * Since we have mapped the on-board devices at their permanent
    370 	 * locations already, it is possible for us to initialize
    371 	 * the console now.
    372 	 */
    373 	consinit();
    374 
    375 #ifdef VERBOSE_INIT_ARM
    376 	/* Talk to the user */
    377 	printf("\nNetBSD/evbarm (ADI BRH) booting ...\n");
    378 #endif
    379 
    380 	/* Calibrate the delay loop. */
    381 	becc_hardclock_hook = brh_hardclock_hook;
    382 
    383 	/*
    384 	 * Heads up ... Setup the CPU / MMU / TLB functions
    385 	 */
    386 	if (set_cpufuncs())
    387 		panic("CPU not recognized!");
    388 
    389 	/*
    390 	 * We are currently running with the MMU enabled and the
    391 	 * entire address space mapped VA==PA.  Memory conveniently
    392 	 * starts at 0xc0000000, which is where we want it.  Certain
    393 	 * on-board devices have already been mapped where we want
    394 	 * them to be.  There is an L1 page table at 0xc0004000.
    395 	 */
    396 
    397 	becc_icu_init();
    398 
    399 	/*
    400 	 * Memory always starts at 0xc0000000 on a BRH, and the
    401 	 * memory size is always 128M.
    402 	 */
    403 	memstart = 0xc0000000UL;
    404 	memsize = (128UL * 1024 * 1024);
    405 
    406 #ifdef VERBOSE_INIT_ARM
    407 	printf("initarm: Configuring system ...\n");
    408 #endif
    409 
    410 	/* Fake bootconfig structure for the benefit of pmap.c */
    411 	/* XXX must make the memory description h/w independent */
    412 	bootconfig.dramblocks = 1;
    413 	bootconfig.dram[0].address = memstart;
    414 	bootconfig.dram[0].pages = memsize / PAGE_SIZE;
    415 
    416 	/*
    417 	 * Set up the variables that define the availablilty of
    418 	 * physical memory.  For now, we're going to set
    419 	 * physical_freestart to 0xc0200000 (where the kernel
    420 	 * was loaded), and allocate the memory we need downwards.
    421 	 * If we get too close to the L1 table that we set up, we
    422 	 * will panic.  We will update physical_freestart and
    423 	 * physical_freeend later to reflect what pmap_bootstrap()
    424 	 * wants to see.
    425 	 *
    426 	 * XXX pmap_bootstrap() needs an enema.
    427 	 */
    428 	physical_start = bootconfig.dram[0].address;
    429 	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
    430 
    431 	physical_freestart = 0xc0009000UL;
    432 	physical_freeend = 0xc0200000UL;
    433 
    434 #ifdef VERBOSE_INIT_ARM
    435 	/* Tell the user about the memory */
    436 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    437 	    physical_start, physical_end - 1);
    438 #endif
    439 
    440 	/*
    441 	 * Okay, the kernel starts 2MB in from the bottom of physical
    442 	 * memory.  We are going to allocate our bootstrap pages downwards
    443 	 * from there.
    444 	 *
    445 	 * We need to allocate some fixed page tables to get the kernel
    446 	 * going.  We allocate one page directory and a number of page
    447 	 * tables and store the physical addresses in the kernel_pt_table
    448 	 * array.
    449 	 *
    450 	 * The kernel page directory must be on a 16K boundary.  The page
    451 	 * tables must be on 4K boundaries.  What we do is allocate the
    452 	 * page directory on the first 16K boundary that we encounter, and
    453 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    454 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    455 	 * least one 16K aligned region.
    456 	 */
    457 
    458 #ifdef VERBOSE_INIT_ARM
    459 	printf("Allocating page tables\n");
    460 #endif
    461 
    462 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    463 
    464 #ifdef VERBOSE_INIT_ARM
    465 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    466 	       physical_freestart, free_pages, free_pages);
    467 #endif
    468 
    469 	/* Define a macro to simplify memory allocation */
    470 #define	valloc_pages(var, np)				\
    471 	alloc_pages((var).pv_pa, (np));			\
    472 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    473 
    474 #define alloc_pages(var, np)				\
    475 	physical_freeend -= ((np) * PAGE_SIZE);		\
    476 	if (physical_freeend < physical_freestart)	\
    477 		panic("initarm: out of memory");	\
    478 	(var) = physical_freeend;			\
    479 	free_pages -= (np);				\
    480 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    481 
    482 	loop1 = 0;
    483 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    484 		/* Are we 16KB aligned for an L1 ? */
    485 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    486 		    && kernel_l1pt.pv_pa == 0) {
    487 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    488 		} else {
    489 			valloc_pages(kernel_pt_table[loop1],
    490 			    L2_TABLE_SIZE / PAGE_SIZE);
    491 			++loop1;
    492 		}
    493 	}
    494 
    495 	/* This should never be able to happen but better confirm that. */
    496 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    497 		panic("initarm: Failed to align the kernel page directory\n");
    498 
    499 	/*
    500 	 * Allocate a page for the system page mapped to V0x00000000
    501 	 * This page will just contain the system vectors and can be
    502 	 * shared by all processes.
    503 	 */
    504 	alloc_pages(systempage.pv_pa, 1);
    505 
    506 	/* Allocate stacks for all modes */
    507 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    508 	valloc_pages(abtstack, ABT_STACK_SIZE);
    509 	valloc_pages(undstack, UND_STACK_SIZE);
    510 	valloc_pages(kernelstack, UPAGES);
    511 
    512 	/* Allocate enough pages for cleaning the Mini-Data cache. */
    513 	KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
    514 	valloc_pages(minidataclean, 1);
    515 
    516 #ifdef VERBOSE_INIT_ARM
    517 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    518 	    irqstack.pv_va);
    519 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    520 	    abtstack.pv_va);
    521 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    522 	    undstack.pv_va);
    523 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    524 	    kernelstack.pv_va);
    525 #endif
    526 
    527 	/*
    528 	 * XXX Defer this to later so that we can reclaim the memory
    529 	 * XXX used by the RedBoot page tables.
    530 	 */
    531 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    532 
    533 	/*
    534 	 * Ok we have allocated physical pages for the primary kernel
    535 	 * page tables
    536 	 */
    537 
    538 #ifdef VERBOSE_INIT_ARM
    539 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    540 #endif
    541 
    542 	/*
    543 	 * Now we start construction of the L1 page table
    544 	 * We start by mapping the L2 page tables into the L1.
    545 	 * This means that we can replace L1 mappings later on if necessary
    546 	 */
    547 	l1pagetable = kernel_l1pt.pv_pa;
    548 
    549 	/* Map the L2 pages tables in the L1 page table */
    550 	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
    551 	    &kernel_pt_table[KERNEL_PT_SYS]);
    552 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    553 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    554 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    555 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    556 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    557 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    558 
    559 	/* update the top of the kernel VM */
    560 	pmap_curmaxkvaddr =
    561 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    562 
    563 #ifdef VERBOSE_INIT_ARM
    564 	printf("Mapping kernel\n");
    565 #endif
    566 
    567 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    568 	{
    569 		extern char etext[], _end[];
    570 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    571 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    572 		u_int logical;
    573 
    574 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    575 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    576 
    577 		logical = 0x00200000;	/* offset of kernel in RAM */
    578 
    579 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    580 		    physical_start + logical, textsize,
    581 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    582 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    583 		    physical_start + logical, totalsize - textsize,
    584 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    585 	}
    586 
    587 #ifdef VERBOSE_INIT_ARM
    588 	printf("Constructing L2 page tables\n");
    589 #endif
    590 
    591 	/* Map the stack pages */
    592 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    593 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    594 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    595 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    596 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    597 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    598 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    599 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    600 
    601 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    602 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    603 
    604 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    605 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    606 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    607 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    608 	}
    609 
    610 	/* Map the Mini-Data cache clean area. */
    611 	xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
    612 	    minidataclean.pv_pa);
    613 
    614 	/* Map the vector page. */
    615 	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
    616 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    617 
    618 	/* Map the statically mapped devices. */
    619 	pmap_devmap_bootstrap(l1pagetable, brh_devmap);
    620 
    621 	/*
    622 	 * Give the XScale global cache clean code an appropriately
    623 	 * sized chunk of unmapped VA space starting at 0xff500000
    624 	 * (our device mappings end before this address).
    625 	 */
    626 	xscale_cache_clean_addr = 0xff500000U;
    627 
    628 	/*
    629 	 * Now we have the real page tables in place so we can switch to them.
    630 	 * Once this is done we will be running with the REAL kernel page
    631 	 * tables.
    632 	 */
    633 
    634 	/* Switch tables */
    635 #ifdef VERBOSE_INIT_ARM
    636 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    637 #endif
    638 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    639 	cpu_setttb(kernel_l1pt.pv_pa, true);
    640 	cpu_tlb_flushID();
    641 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    642 
    643 	/*
    644 	 * Move from cpu_startup() as data_abort_handler() references
    645 	 * this during uvm init
    646 	 */
    647 	uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
    648 
    649 #ifdef VERBOSE_INIT_ARM
    650 	printf("done!\n");
    651 #endif
    652 
    653 #ifdef VERBOSE_INIT_ARM
    654 	printf("bootstrap done.\n");
    655 #endif
    656 
    657 	/*
    658 	 * Inform the BECC code where the BECC is mapped.
    659 	 */
    660 	becc_vaddr = BRH_BECC_VBASE;
    661 
    662 	/*
    663 	 * Now that we have becc_vaddr set, calibrate delay.
    664 	 */
    665 	becc_calibrate_delay();
    666 
    667 	/*
    668 	 * BECC <= Rev7 can only address 64M through the inbound
    669 	 * PCI windows.  Limit memory to 64M on those revs.  (This
    670 	 * problem was fixed in Rev8 of the BECC; get an FPGA upgrade.)
    671 	 */
    672 	{
    673 		vaddr_t va = BRH_PCI_CONF_VBASE | (1U << BECC_IDSEL_BIT) |
    674 		    PCI_CLASS_REG;
    675 		uint32_t reg;
    676 
    677 		reg = *(volatile uint32_t *) va;
    678 		becc_rev = PCI_REVISION(reg);
    679 		if (becc_rev <= BECC_REV_V7 &&
    680 		    memsize > (64UL * 1024 * 1024)) {
    681 			memsize = (64UL * 1024 * 1024);
    682 			bootconfig.dram[0].pages = memsize / PAGE_SIZE;
    683 			physical_end = physical_start +
    684 			    (bootconfig.dram[0].pages * PAGE_SIZE);
    685 			printf("BECC <= Rev7: memory truncated to 64M\n");
    686 		}
    687 	}
    688 
    689 	/*
    690 	 * Update the physical_freestart/physical_freeend/free_pages
    691 	 * variables.
    692 	 */
    693 	{
    694 		extern char _end[];
    695 
    696 		physical_freestart = physical_start +
    697 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    698 		     KERNEL_BASE);
    699 		physical_freeend = physical_end;
    700 		free_pages =
    701 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    702 	}
    703 #ifdef VERBOSE_INIT_ARM
    704 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    705 	       physical_freestart, free_pages, free_pages);
    706 #endif
    707 
    708 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    709 
    710 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    711 
    712 	/*
    713 	 * Pages were allocated during the secondary bootstrap for the
    714 	 * stacks for different CPU modes.
    715 	 * We must now set the r13 registers in the different CPU modes to
    716 	 * point to these stacks.
    717 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    718 	 * of the stack memory.
    719 	 */
    720 #ifdef VERBOSE_INIT_ARM
    721 	printf("init subsystems: stacks ");
    722 #endif
    723 
    724 	set_stackptr(PSR_IRQ32_MODE,
    725 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    726 	set_stackptr(PSR_ABT32_MODE,
    727 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    728 	set_stackptr(PSR_UND32_MODE,
    729 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    730 
    731 	/*
    732 	 * Well we should set a data abort handler.
    733 	 * Once things get going this will change as we will need a proper
    734 	 * handler.
    735 	 * Until then we will use a handler that just panics but tells us
    736 	 * why.
    737 	 * Initialisation of the vectors will just panic on a data abort.
    738 	 * This just fills in a slightly better one.
    739 	 */
    740 #ifdef VERBOSE_INIT_ARM
    741 	printf("vectors ");
    742 #endif
    743 	data_abort_handler_address = (u_int)data_abort_handler;
    744 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    745 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    746 
    747 	/* Initialise the undefined instruction handlers */
    748 #ifdef VERBOSE_INIT_ARM
    749 	printf("undefined ");
    750 #endif
    751 	undefined_init();
    752 
    753 	/* Load memory into UVM. */
    754 #ifdef VERBOSE_INIT_ARM
    755 	printf("page ");
    756 #endif
    757 	uvm_md_init();
    758 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    759 	    atop(physical_freestart), atop(physical_freeend),
    760 	    VM_FREELIST_DEFAULT);
    761 
    762 	/* Boot strap pmap telling it where the managed kernel virtual memory is */
    763 #ifdef VERBOSE_INIT_ARM
    764 	printf("pmap ");
    765 #endif
    766 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    767 
    768 	/* Setup the IRQ system */
    769 #ifdef VERBOSE_INIT_ARM
    770 	printf("irq ");
    771 #endif
    772 	becc_intr_init();
    773 #ifdef VERBOSE_INIT_ARM
    774 	printf("done.\n");
    775 #endif
    776 
    777 #ifdef DDB
    778 	db_machine_init();
    779 	if (boothowto & RB_KDB)
    780 		Debugger();
    781 #endif
    782 
    783 	/* We return the new stack pointer address */
    784 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    785 }
    786 
    787 void
    788 consinit(void)
    789 {
    790 	static const bus_addr_t comcnaddrs[] = {
    791 		BRH_UART1_BASE,		/* com0 */
    792 		BRH_UART2_BASE,		/* com1 */
    793 	};
    794 	static int consinit_called;
    795 
    796 	if (consinit_called != 0)
    797 		return;
    798 
    799 	consinit_called = 1;
    800 
    801 	/*
    802 	 * brh_start() has mapped the console devices for us per
    803 	 * the devmap, so register it now so drivers can map the
    804 	 * console device.
    805 	 */
    806 	pmap_devmap_register(brh_devmap);
    807 
    808 #if NCOM > 0
    809 	if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
    810 	    BECC_PERIPH_CLOCK, COM_TYPE_NORMAL, comcnmode))
    811 		panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
    812 #else
    813 	panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
    814 #endif
    815 }
    816