Home | History | Annotate | Line # | Download | only in mini2440
mini2440_machdep.c revision 1.4
      1 /*-
      2  * Copyright (c) 2012 The NetBSD Foundation, Inc.
      3  * All rights reserved.
      4  *
      5  * This code is derived from software contributed to The NetBSD Foundation
      6  * by Paul Fleischer <paul (at) xpg.dk>
      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  *
     17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  * POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 /* This file is based on arch/evbarm/smdk2xx0/smdk2410_machdep.c */
     30 /*
     31  * Copyright (c) 2002, 2003 Fujitsu Component Limited
     32  * Copyright (c) 2002, 2003, 2005 Genetec Corporation
     33  * All rights reserved.
     34  *
     35  * Redistribution and use in source and binary forms, with or without
     36  * modification, are permitted provided that the following conditions
     37  * are met:
     38  * 1. Redistributions of source code must retain the above copyright
     39  *    notice, this list of conditions and the following disclaimer.
     40  * 2. Redistributions in binary form must reproduce the above copyright
     41  *    notice, this list of conditions and the following disclaimer in the
     42  *    documentation and/or other materials provided with the distribution.
     43  * 3. Neither the name of The Fujitsu Component Limited nor the name of
     44  *    Genetec corporation may not be used to endorse or promote products
     45  *    derived from this software without specific prior written permission.
     46  *
     47  * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
     48  * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     49  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     50  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     51  * DISCLAIMED.  IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
     52  * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     53  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     54  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
     55  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     56  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     57  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     58  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59  * SUCH DAMAGE.
     60  */
     61 /*
     62  * Copyright (c) 2001,2002 ARM Ltd
     63  * All rights reserved.
     64  *
     65  * Redistribution and use in source and binary forms, with or without
     66  * modification, are permitted provided that the following conditions
     67  * are met:
     68  * 1. Redistributions of source code must retain the above copyright
     69  *    notice, this list of conditions and the following disclaimer.
     70  * 2. Redistributions in binary form must reproduce the above copyright
     71  *    notice, this list of conditions and the following disclaimer in the
     72  *    documentation and/or other materials provided with the distribution.
     73  * 3. The name of the company may not be used to endorse or promote
     74  *    products derived from this software without specific prior written
     75  *    permission.
     76  *
     77  * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND
     78  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     79  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     80  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ARM LTD
     81  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     82  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     83  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     84  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     85  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     86  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     87  * POSSIBILITY OF SUCH DAMAGE.
     88  *
     89  */
     90 
     91 /*
     92  * Copyright (c) 1997,1998 Mark Brinicombe.
     93  * Copyright (c) 1997,1998 Causality Limited.
     94  * All rights reserved.
     95  *
     96  * Redistribution and use in source and binary forms, with or without
     97  * modification, are permitted provided that the following conditions
     98  * are met:
     99  * 1. Redistributions of source code must retain the above copyright
    100  *    notice, this list of conditions and the following disclaimer.
    101  * 2. Redistributions in binary form must reproduce the above copyright
    102  *    notice, this list of conditions and the following disclaimer in the
    103  *    documentation and/or other materials provided with the distribution.
    104  * 3. All advertising materials mentioning features or use of this software
    105  *    must display the following acknowledgement:
    106  *	This product includes software developed by Mark Brinicombe
    107  *	for the NetBSD Project.
    108  * 4. The name of the company nor the name of the author may be used to
    109  *    endorse or promote products derived from this software without specific
    110  *    prior written permission.
    111  *
    112  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
    113  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    114  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    115  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    116  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    117  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    118  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    119  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    120  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    121  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    122  * SUCH DAMAGE.
    123  *
    124  * Machine dependant functions for kernel setup for integrator board
    125  *
    126  * Created      : 24/11/97
    127  */
    128 
    129 /*
    130  * Machine dependant functions for kernel setup for FriendlyARM MINI2440
    131  */
    132 
    133 #include <sys/cdefs.h>
    134 __KERNEL_RCSID(0, "$NetBSD: mini2440_machdep.c,v 1.4 2012/07/29 00:07:09 matt Exp $");
    135 
    136 #include "opt_ddb.h"
    137 #include "opt_kgdb.h"
    138 #include "opt_pmap_debug.h"
    139 #include "opt_md.h"
    140 
    141 #include <sys/param.h>
    142 #include <sys/device.h>
    143 #include <sys/systm.h>
    144 #include <sys/kernel.h>
    145 #include <sys/exec.h>
    146 #include <sys/proc.h>
    147 #include <sys/msgbuf.h>
    148 #include <sys/reboot.h>
    149 #include <sys/termios.h>
    150 #include <sys/ksyms.h>
    151 #include <sys/mount.h>
    152 
    153 #include <net/if.h>
    154 #include <net/if_ether.h>
    155 #include <net/if_media.h>
    156 
    157 #include <uvm/uvm_extern.h>
    158 
    159 #include <dev/cons.h>
    160 #include <dev/md.h>
    161 
    162 #include <machine/db_machdep.h>
    163 #include <ddb/db_sym.h>
    164 #include <ddb/db_extern.h>
    165 #ifdef KGDB
    166 #include <sys/kgdb.h>
    167 #endif
    168 
    169 #include <sys/exec_elf.h>
    170 
    171 #include <sys/bus.h>
    172 #include <machine/cpu.h>
    173 #include <machine/frame.h>
    174 #include <machine/intr.h>
    175 #include <arm/undefined.h>
    176 
    177 #include <machine/autoconf.h>
    178 
    179 #include <arm/arm32/machdep.h>
    180 
    181 #include <arm/s3c2xx0/s3c2440reg.h>
    182 #include <arm/s3c2xx0/s3c2440var.h>
    183 
    184 #include <arch/evbarm/mini2440/mini2440_bootinfo.h>
    185 
    186 #include "ksyms.h"
    187 
    188 #ifndef	SDRAM_START
    189 #define	SDRAM_START	S3C2440_SDRAM_START
    190 #endif
    191 #ifndef	SDRAM_SIZE
    192 #define	SDRAM_SIZE	(64*1024*1024) /* 64 Mb */
    193 #endif
    194 
    195 /*
    196  * Address to map I/O registers in early initialize stage.
    197  */
    198 #define MINI2440_IO_VBASE	0xfd000000
    199 
    200 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    201 #define KERNEL_OFFSET		0x00200000
    202 #define	KERNEL_TEXT_BASE	(KERNEL_BASE + KERNEL_OFFSET)
    203 #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    204 
    205 /*
    206  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    207  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    208  */
    209 #define KERNEL_VM_SIZE		0x0C000000
    210 
    211 /*
    212  * Address to call from cpu_reset() to reset the machine.
    213  * This is machine architecture dependant as it varies depending
    214  * on where the ROM appears when you turn the MMU off.
    215  */
    216 u_int cpu_reset_address = (u_int)0;
    217 
    218 /* Define various stack sizes in pages */
    219 #define IRQ_STACK_SIZE	1
    220 #define ABT_STACK_SIZE	1
    221 #define UND_STACK_SIZE	1
    222 
    223 /* Declared extern elsewhere in the kernel */
    224 BootConfig bootconfig;		/* Boot config storage */
    225 char *boot_args = NULL;
    226 //char *boot_file = NULL;
    227 
    228 char bootinfo[BOOTINFO_MAXSIZE];
    229 struct btinfo_rootdevice 	*bi_rdev;
    230 struct btinfo_net		*bi_net;
    231 struct btinfo_bootpath		*bi_path;
    232 
    233 vm_offset_t physical_start;
    234 vm_offset_t physical_freestart;
    235 vm_offset_t physical_freeend;
    236 vm_offset_t physical_freeend_low;
    237 vm_offset_t physical_end;
    238 u_int free_pages;
    239 vm_offset_t pagetables_start;
    240 
    241 /*int debug_flags;*/
    242 #ifndef PMAP_STATIC_L1S
    243 int max_processes = 64;		/* Default number */
    244 #endif				/* !PMAP_STATIC_L1S */
    245 
    246 vm_offset_t msgbufphys;
    247 
    248 #ifdef PMAP_DEBUG
    249 extern int pmap_debug_level;
    250 #endif
    251 
    252 #define KERNEL_PT_SYS		0	/* L2 table for mapping zero page */
    253 #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
    254 #define KERNEL_PT_KERNEL_NUM	3	/* L2 tables for mapping kernel VM */
    255 
    256 #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    257 
    258 #define KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    259 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    260 
    261 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    262 
    263 struct user *proc0paddr;
    264 
    265 /* Prototypes */
    266 
    267 void consinit(void);
    268 void kgdb_port_init(void);
    269 static void mini2440_ksyms(struct btinfo_symtab *bi_symtab);
    270 static void *lookup_bootinfo(int type);
    271 static void mini2440_device_register(device_t dev, void *aux);
    272 
    273 
    274 #include "com.h"
    275 #if NCOM > 0
    276 #include <dev/ic/comreg.h>
    277 #include <dev/ic/comvar.h>
    278 #endif
    279 
    280 #include "sscom.h"
    281 #if NSSCOM > 0
    282 #include "opt_sscom.h"
    283 #include <arm/s3c2xx0/sscom_var.h>
    284 #endif
    285 
    286 /*
    287  * Define the default console speed for the board.  This is generally
    288  * what the firmware provided with the board defaults to.
    289  */
    290 #ifndef CONSPEED
    291 #define CONSPEED B115200	/* TTYDEF_SPEED */
    292 #endif
    293 #ifndef CONMODE
    294 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)   /* 8N1 */
    295 #endif
    296 
    297 int comcnspeed = CONSPEED;
    298 int comcnmode = CONMODE;
    299 
    300 /*
    301  * void cpu_reboot(int howto, char *bootstr)
    302  *
    303  * Reboots the system
    304  *
    305  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    306  * then reset the CPU.
    307  */
    308 void
    309 cpu_reboot(int howto, char *bootstr)
    310 {
    311 #ifdef DIAGNOSTIC
    312 	/* info */
    313 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    314 #endif
    315 
    316 	cpu_reset_address = vtophys((u_int)s3c2440_softreset);
    317 
    318 	/*
    319 	 * If we are still cold then hit the air brakes
    320 	 * and crash to earth fast
    321 	 */
    322 	if (cold) {
    323 		doshutdownhooks();
    324 		printf("The operating system has halted.\n");
    325 		printf("Please press any key to reboot.\n\n");
    326 		cngetc();
    327 		printf("rebooting...\n");
    328 		cpu_reset();
    329 		/* NOTREACHED */
    330 	}
    331 	/* Disable console buffering */
    332 
    333 	/*
    334 	 * If RB_NOSYNC was not specified sync the discs.
    335 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    336 	 * unmount.  It looks like syslogd is getting woken up only to find
    337 	 * that it cannot page part of the binary in as the filesystem has
    338 	 * been unmounted.
    339 	 */
    340 	if (!(howto & RB_NOSYNC))
    341 		bootsync();
    342 
    343 	/* Say NO to interrupts */
    344 	splhigh();
    345 
    346 	/* Do a dump if requested. */
    347 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    348 		dumpsys();
    349 
    350 	/* Run any shutdown hooks */
    351 	doshutdownhooks();
    352 
    353 	/* Make sure IRQ's are disabled */
    354 	IRQdisable;
    355 
    356 	if (howto & RB_HALT) {
    357 		printf("The operating system has halted.\n");
    358 		printf("Please press any key to reboot.\n\n");
    359 		cngetc();
    360 	}
    361 	printf("rebooting...\n");
    362 	cpu_reset();
    363 	/* NOTREACHED */
    364 }
    365 
    366 /*
    367  * Static device mappings. These peripheral registers are mapped at
    368  * fixed virtual addresses very early in initarm() so that we can use
    369  * them while booting the kernel , and stay at the same address
    370  * throughout whole kernel's life time.
    371  *
    372  * We use this table twice; once with bootstrap page table, and once
    373  * with kernel's page table which we build up in initarm().
    374  *
    375  * Since we map these registers into the bootstrap page table using
    376  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    377  * registers segment-aligned and segment-rounded in order to avoid
    378  * using the 2nd page tables.
    379  */
    380 
    381 #define	_A(a)	((a) & ~L1_S_OFFSET)
    382 #define	_S(s)	(((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    383 
    384 #define	_V(n)	(MINI2440_IO_VBASE + (n) * L1_S_SIZE)
    385 
    386 #define	GPIO_VBASE	_V(0)
    387 #define	INTCTL_VBASE	_V(1)
    388 #define	CLKMAN_VBASE	_V(2)
    389 #define	UART_VBASE	_V(3)
    390 
    391 static const struct pmap_devmap mini2440_devmap[] = {
    392 	/* GPIO registers */
    393 	{
    394 		GPIO_VBASE,
    395 		_A(S3C2440_GPIO_BASE),
    396 		_S(S3C2440_GPIO_SIZE),
    397 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    398 	},
    399 	{
    400 		INTCTL_VBASE,
    401 		_A(S3C2440_INTCTL_BASE),
    402 		_S(S3C2440_INTCTL_SIZE),
    403 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    404 	},
    405 	{
    406 		CLKMAN_VBASE,
    407 		_A(S3C2440_CLKMAN_BASE),
    408 		_S(S3C24X0_CLKMAN_SIZE),
    409 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    410 	},
    411 	{	/* UART registers for UART0, 1, 2. */
    412 		UART_VBASE,
    413 		_A(S3C2440_UART0_BASE),
    414 		_S(S3C2440_UART_BASE(3) - S3C2440_UART0_BASE),
    415 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    416 	},
    417 
    418 	{ 0, 0, 0, 0 }
    419 };
    420 
    421 #undef	_A
    422 #undef	_S
    423 
    424 static inline	pd_entry_t *
    425 read_ttb(void)
    426 {
    427 	long ttb;
    428 
    429 	__asm volatile("mrc	p15, 0, %0, c2, c0, 0" : "=r"(ttb));
    430 
    431 
    432 	return (pd_entry_t *)(ttb & ~((1 << 14) - 1));
    433 }
    434 
    435 
    436 #define	ioreg_write32(a,v)  	(*(volatile uint32_t *)(a)=(v))
    437 
    438 /*
    439  * u_int initarm(...)
    440  *
    441  * Initial entry point on startup. This gets called before main() is
    442  * entered.
    443  * It should be responsible for setting up everything that must be
    444  * in place when main is called.
    445  * This includes
    446  *   Taking a copy of the boot configuration structure.
    447  *   Initialising the physical console so characters can be printed.
    448  *   Setting up page tables for the kernel
    449  *   Relocating the kernel to the bottom of physical memory
    450  */
    451 
    452 u_int
    453 initarm(void *arg)
    454 {
    455 	int loop;
    456 	int loop1;
    457 	u_int l1pagetable;
    458 	extern int etext __asm("_etext");
    459 	extern int end __asm("_end");
    460 	uint32_t kerneldatasize;
    461 	struct btinfo_magic *bi_magic = arg;
    462 	struct btinfo_bootstring *bi_bootstring;
    463 	struct btinfo_symtab *bi_symtab;
    464 
    465 	boothowto = 0;
    466 
    467 	/* Copy bootinfo from boot loader into kernel memory where it remains.
    468 	 */
    469 	if (bi_magic != 0x0 && bi_magic->magic == BOOTINFO_MAGIC) {
    470 		memcpy(bootinfo, bi_magic, sizeof(bootinfo));
    471 	} else {
    472 		memset(bootinfo, 0, sizeof(bootinfo));
    473 	}
    474 
    475 	/* Extract boot_args from bootinfo */
    476 	bi_bootstring = lookup_bootinfo(BTINFO_BOOTSTRING);
    477 	if (bi_bootstring ) {
    478 		printf("Bootloader args are %s\n", bi_bootstring->bootstring);
    479 		boot_args = bi_bootstring->bootstring;
    480 		parse_mi_bootargs(boot_args);
    481 	}
    482 
    483 #define pdatb (*(volatile uint8_t *)(S3C2440_GPIO_BASE+GPIO_PBDAT))
    484 
    485 // 0x1E0 is the mask for GPB5, GPB6, GPB7, and GPB8
    486 #define __LED(x)  (pdatb = (pdatb & ~0x1e0) | (~(1<<(x+5)) & 0x1e0))
    487 
    488 	__LED(0);
    489 
    490 	/*
    491 	 * Heads up ... Setup the CPU / MMU / TLB functions
    492 	 */
    493 	if (set_cpufuncs())
    494 		panic("cpu not recognized!");
    495 
    496 	/*
    497 	 * Map I/O registers that are used in startup.  Now we are
    498 	 * still using page table prepared by bootloader.  Later we'll
    499 	 * map those registers at the same address in the kernel page
    500 	 * table.
    501 	 */
    502 	pmap_devmap_bootstrap((vaddr_t)read_ttb(), mini2440_devmap);
    503 
    504 #undef	pdatb
    505 #define pdatb (*(volatile uint8_t *)(GPIO_VBASE+GPIO_PBDAT))
    506 
    507 	/* Disable all peripheral interrupts */
    508 	ioreg_write32(INTCTL_VBASE + INTCTL_INTMSK, ~0);
    509 
    510 	__LED(1);
    511 
    512 	/* initialize some variables so that splfoo() doesn't
    513 	   touch illegal address.  */
    514 	s3c2xx0_intr_bootstrap(INTCTL_VBASE);
    515 
    516 	__LED(2);
    517 	consinit();
    518 	__LED(3);
    519 
    520 	/* Extract information from the bootloader configuration */
    521 	bi_rdev = lookup_bootinfo(BTINFO_ROOTDEVICE);
    522 	bi_net = lookup_bootinfo(BTINFO_NET);
    523 	bi_path = lookup_bootinfo(BTINFO_BOOTPATH);
    524 
    525 #ifdef VERBOSE_INIT_ARM
    526 	printf("consinit done\n");
    527 #endif
    528 
    529 #ifdef KGDB
    530 	kgdb_port_init();
    531 #endif
    532 
    533 #ifdef VERBOSE_INIT_ARM
    534 	/* Talk to the user */
    535 	printf("\nNetBSD/evbarm (MINI2440) booting ...\n");
    536 #endif
    537 	/*
    538 	 * Ok we have the following memory map
    539 	 *
    540 	 * Physical Address Range     Description
    541 	 * -----------------------    ----------------------------------
    542 	 * 0x30000000 - 0x33ffffff    SDRAM (64MB)
    543          *
    544          * Kernel is loaded by bootloader at 0x30200000
    545 	 *
    546 	 * The initarm() has the responsibility for creating the kernel
    547 	 * page tables.
    548 	 * It must also set up various memory pointers that are used
    549 	 * by pmap etc.
    550 	 */
    551 
    552 	/* Fake bootconfig structure for the benefit of pmap.c */
    553 	/* XXX must make the memory description h/w independent */
    554 	bootconfig.dramblocks = 1;
    555 	bootconfig.dram[0].address = SDRAM_START;
    556 	bootconfig.dram[0].pages = SDRAM_SIZE / PAGE_SIZE;
    557 
    558 	/*
    559 	 * Set up the variables that define the availablilty of
    560 	 * physical memory.
    561          * We use the 2MB between the physical start and the kernel to
    562          * begin with. Allocating from 0x30200000 and downwards
    563 	 * If we get too close to the bottom of SDRAM, we
    564 	 * will panic.  We will update physical_freestart and
    565 	 * physical_freeend later to reflect what pmap_bootstrap()
    566 	 * wants to see.
    567 	 *
    568 	 * XXX pmap_bootstrap() needs an enema.
    569 	 */
    570 	physical_start = bootconfig.dram[0].address;
    571 	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
    572 
    573 	physical_freestart = SDRAM_START;	/* XXX */
    574 	physical_freeend = SDRAM_START + KERNEL_OFFSET;
    575 
    576 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    577 
    578 #ifdef VERBOSE_INIT_ARM
    579 	/* Tell the user about the memory */
    580 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    581 	    physical_start, physical_end - 1);
    582 	printf("phys_end: 0x%08lx\n", physical_end);
    583 #endif
    584 
    585 	/*
    586 	 * XXX
    587 	 * Okay, the kernel starts 2MB in from the bottom of physical
    588 	 * memory.  We are going to allocate our bootstrap pages downwards
    589 	 * from there.
    590 	 *
    591 	 * We need to allocate some fixed page tables to get the kernel
    592 	 * going.  We allocate one page directory and a number of page
    593 	 * tables and store the physical addresses in the kernel_pt_table
    594 	 * array.
    595 	 *
    596 	 * The kernel page directory must be on a 16K boundary.  The page
    597 	 * tables must be on 4K boundaries.  What we do is allocate the
    598 	 * page directory on the first 16K boundary that we encounter, and
    599 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    600 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    601 	 * least one 16K aligned region.
    602 	 */
    603 
    604 #ifdef VERBOSE_INIT_ARM
    605 	printf("Allocating page tables\n");
    606 #endif
    607 
    608 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    609 
    610 #ifdef VERBOSE_INIT_ARM
    611 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x), freeend = 0x%08lx\n",
    612 	    physical_freestart, free_pages, free_pages, physical_freeend);
    613 #endif
    614 
    615 	/* Define a macro to simplify memory allocation */
    616 #define	valloc_pages(var, np)				\
    617 	alloc_pages((var).pv_pa, (np));			\
    618 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    619 
    620 #define alloc_pages(var, np)				\
    621 	physical_freeend -= ((np) * PAGE_SIZE);		\
    622 	if (physical_freeend < physical_freestart)	\
    623 		panic("initarm: out of memory");	\
    624 	(var) = physical_freeend;			\
    625 	free_pages -= (np);				\
    626 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    627 
    628 	loop1 = 0;
    629 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    630 		/* Are we 16KB aligned for an L1 ? */
    631 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    632 		    && kernel_l1pt.pv_pa == 0) {
    633 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    634 		} else {
    635 			valloc_pages(kernel_pt_table[loop1],
    636 			    L2_TABLE_SIZE / PAGE_SIZE);
    637 			++loop1;
    638 		}
    639 	}
    640 
    641 	/* This should never be able to happen but better confirm that. */
    642 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE - 1)) != 0)
    643 		panic("initarm: Failed to align the kernel page directory\n");
    644 
    645 	/*
    646 	 * Allocate a page for the system page mapped to V0x00000000
    647 	 * This page will just contain the system vectors and can be
    648 	 * shared by all processes.
    649 	 */
    650 	alloc_pages(systempage.pv_pa, 1);
    651 
    652 	/* Allocate stacks for all modes */
    653 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    654 	valloc_pages(abtstack, ABT_STACK_SIZE);
    655 	valloc_pages(undstack, UND_STACK_SIZE);
    656 	valloc_pages(kernelstack, UPAGES);
    657 
    658 #ifdef VERBOSE_INIT_ARM
    659 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    660 	    irqstack.pv_va);
    661 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    662 	    abtstack.pv_va);
    663 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    664 	    undstack.pv_va);
    665 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    666 	    kernelstack.pv_va);
    667 	printf("Free memory in bootstrap region: %ld bytes\n", physical_freeend - physical_freestart);
    668 #endif
    669 
    670 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    671 
    672 	physical_freeend_low = physical_freeend;
    673 
    674 	/*
    675 	 * Ok we have allocated physical pages for the primary kernel
    676 	 * page tables
    677 	 */
    678 
    679 #ifdef VERBOSE_INIT_ARM
    680 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    681 #endif
    682 
    683 	/*
    684 	 * Now we start construction of the L1 page table
    685 	 * We start by mapping the L2 page tables into the L1.
    686 	 * This means that we can replace L1 mappings later on if necessary
    687 	 */
    688 	l1pagetable = kernel_l1pt.pv_pa;
    689 
    690 	/* Map the L2 pages tables in the L1 page table */
    691 	pmap_link_l2pt(l1pagetable, 0x00000000,
    692 	    &kernel_pt_table[KERNEL_PT_SYS]);
    693 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    694 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    695 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    696 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    697 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    698 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    699 
    700 	/* update the top of the kernel VM */
    701 	pmap_curmaxkvaddr =
    702 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    703 
    704 #ifdef VERBOSE_INIT_ARM
    705 	printf("Mapping kernel\n");
    706 #endif
    707 
    708 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    709 	{
    710 		/* Total size must include symbol table, if it exists.
    711 		   The size of the symbol table can be acquired from the ELF
    712 		   header, to which a pointer is passed in the boot info (ssym).
    713 		 */
    714 		size_t textsize = (uintptr_t)&etext - KERNEL_TEXT_BASE;
    715 		kerneldatasize = (uintptr_t)&end - KERNEL_TEXT_BASE;
    716 		u_int logical;
    717 
    718 		bi_symtab = lookup_bootinfo(BTINFO_SYMTAB);
    719 
    720 		if (bi_symtab) {
    721 			Elf_Ehdr *elfHeader;
    722 			Elf_Shdr *sectionHeader;
    723 			int nsection;
    724 			int sz = 0;
    725 
    726 			elfHeader = bi_symtab->ssym;
    727 
    728 #ifdef VERBOSE_INIT_ARM
    729 			printf("Symbol table information provided by bootloader\n");
    730 			printf("ELF header is at %p\n", elfHeader);
    731 #endif
    732 			sectionHeader = (Elf_Shdr*)((char*)(bi_symtab->ssym) +
    733 						     (elfHeader->e_shoff));
    734 			nsection = elfHeader->e_shnum;
    735 #ifdef VERBOSE_INIT_ARM
    736 			printf("Number of sections: %d\n", nsection);
    737 #endif
    738 			for(; nsection > 0; nsection--, sectionHeader++) {
    739 				if (sectionHeader->sh_offset > 0 &&
    740 				    (sectionHeader->sh_offset + sectionHeader->sh_size) > sz)
    741 					sz = sectionHeader->sh_offset + sectionHeader->sh_size;
    742 			}
    743 #ifdef VERBOSE_INIT_ARM
    744 			printf("Max size of sections: %d\n", sz);
    745 #endif
    746 			kerneldatasize += sz;
    747 		}
    748 
    749 #ifdef VERBOSE_INIT_ARM
    750 		printf("Textsize: %u, kerneldatasize: %u\n", (uint)textsize,
    751 		       (uint)kerneldatasize);
    752 		printf("&etext: 0x%x\n", (uint)&etext);
    753 		printf("&end: 0x%x\n", (uint)&end);
    754 		printf("KERNEL_TEXT_BASE: 0x%x\n", KERNEL_TEXT_BASE);
    755 #endif
    756 
    757 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    758 		kerneldatasize = (kerneldatasize + PGOFSET) & ~PGOFSET;
    759 
    760 		logical = KERNEL_OFFSET;	/* offset of kernel in RAM */
    761 
    762 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    763 					  physical_start + logical, textsize,
    764 					  VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    765 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    766 					  physical_start + logical, kerneldatasize - textsize,
    767 					  VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    768 	}
    769 
    770 #ifdef VERBOSE_INIT_ARM
    771 	printf("Constructing L2 page tables\n");
    772 #endif
    773 
    774 	/* Map the stack pages */
    775 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    776 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
    777 	    PTE_CACHE);
    778 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    779 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
    780 	    PTE_CACHE);
    781 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    782 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
    783 	    PTE_CACHE);
    784 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    785 	    UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    786 
    787 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    788 	    L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
    789 
    790 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    791 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    792 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    793 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    794 	}
    795 
    796 	/* Map the vector page. */
    797 #if 0
    798 	/* MULTI-ICE requires that page 0 is NC/NB so that it can download the
    799 	 * cache-clean code there.  */
    800 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    801 	    VM_PROT_READ | VM_PROT_WRITE, PTE_NOCACHE);
    802 #else
    803 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    804 	    VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    805 #endif
    806 
    807 	/*
    808 	 * map integrated peripherals at same address in l1pagetable
    809 	 * so that we can continue to use console.
    810 	 */
    811 	pmap_devmap_bootstrap(l1pagetable, mini2440_devmap);
    812 
    813 	/*
    814 	 * Now we have the real page tables in place so we can switch to them.
    815 	 * Once this is done we will be running with the REAL kernel page
    816 	 * tables.
    817 	 */
    818 	/*
    819 	 * Update the physical_freestart/physical_freeend/free_pages
    820 	 * variables.
    821 	 */
    822 	physical_freestart = physical_start +
    823 	  (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
    824 	physical_freeend = physical_end;
    825 	free_pages =
    826 	  (physical_freeend - physical_freestart) / PAGE_SIZE;
    827 
    828 	/* Switch tables */
    829 #ifdef VERBOSE_INIT_ARM
    830 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    831 	    physical_freestart, free_pages, free_pages);
    832 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    833 #endif
    834 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    835 	cpu_setttb(kernel_l1pt.pv_pa);
    836 	cpu_tlb_flushID();
    837 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    838 
    839 	/*
    840 	 * Moved from cpu_startup() as data_abort_handler() references
    841 	 * this during uvm init
    842 	 */
    843 	uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
    844 
    845 #ifdef VERBOSE_INIT_ARM
    846 	printf("done!\n");
    847 #endif
    848 
    849 #ifdef VERBOSE_INIT_ARM
    850 	printf("bootstrap done.\n");
    851 #endif
    852 
    853 	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
    854 
    855 	/*
    856 	 * Pages were allocated during the secondary bootstrap for the
    857 	 * stacks for different CPU modes.
    858 	 * We must now set the r13 registers in the different CPU modes to
    859 	 * point to these stacks.
    860 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    861 	 * of the stack memory.
    862 	 */
    863 #ifdef VERBOSE_INIT_ARM
    864 	printf("init subsystems: stacks ");
    865 #endif
    866 
    867 	set_stackptr(PSR_IRQ32_MODE,
    868 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    869 	set_stackptr(PSR_ABT32_MODE,
    870 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    871 	set_stackptr(PSR_UND32_MODE,
    872 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    873 
    874 	cpu_idcache_wbinv_all();
    875 
    876 	/*
    877 	 * Well we should set a data abort handler.
    878 	 * Once things get going this will change as we will need a proper
    879 	 * handler.
    880 	 * Until then we will use a handler that just panics but tells us
    881 	 * why.
    882 	 * Initialisation of the vectors will just panic on a data abort.
    883 	 * This just fills in a slightly better one.
    884 	 */
    885 #ifdef VERBOSE_INIT_ARM
    886 	printf("vectors ");
    887 #endif
    888 	data_abort_handler_address = (u_int)data_abort_handler;
    889 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    890 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    891 
    892 	/* Initialise the undefined instruction handlers */
    893 #ifdef VERBOSE_INIT_ARM
    894 	printf("undefined ");
    895 #endif
    896 	undefined_init();
    897 
    898 	/* Load memory into UVM. */
    899 #ifdef VERBOSE_INIT_ARM
    900 	printf("page ");
    901 #endif
    902 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    903 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    904 	    atop(physical_freestart), atop(physical_freeend),
    905 	    VM_FREELIST_DEFAULT);
    906 	uvm_page_physload(atop(SDRAM_START), atop(physical_freeend_low),
    907 	    atop(SDRAM_START), atop(physical_freeend_low),
    908 	    VM_FREELIST_DEFAULT);
    909 
    910 
    911 	/* Boot strap pmap telling it where the kernel page table is */
    912 #ifdef VERBOSE_INIT_ARM
    913 	printf("pmap ");
    914 #endif
    915 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    916 
    917 #ifdef VERBOSE_INIT_ARM
    918 	printf("done.\n");
    919 #endif
    920 
    921 #ifdef BOOTHOWTO
    922 	boothowto |= BOOTHOWTO;
    923 #endif
    924 
    925 #ifdef KGDB
    926 	if (boothowto & RB_KDB) {
    927 		kgdb_debug_init = 1;
    928 		kgdb_connect(1);
    929 	}
    930 #endif
    931 
    932 	mini2440_ksyms(bi_symtab);
    933 
    934 #ifdef DDB
    935 	/*db_machine_init();*/
    936 	if (boothowto & RB_KDB)
    937 		Debugger();
    938 #endif
    939 
    940 	evbarm_device_register = mini2440_device_register;
    941 
    942 	/* We return the new stack pointer address */
    943 	return (kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    944 }
    945 
    946 void
    947 consinit(void)
    948 {
    949 	static int consinit_done = 0;
    950 #if defined(SSCOM0CONSOLE) || defined(SSCOM1CONSOLE)
    951 	bus_space_tag_t iot = &s3c2xx0_bs_tag;
    952 #endif
    953 	int pclk;
    954 
    955 	if (consinit_done != 0)
    956 		return;
    957 
    958 	consinit_done = 1;
    959 
    960 	s3c24x0_clock_freq2(CLKMAN_VBASE, NULL, NULL, &pclk);
    961 
    962 #if NSSCOM > 0
    963 #ifdef SSCOM0CONSOLE
    964 	if (0 == s3c2440_sscom_cnattach(iot, 0, comcnspeed,
    965 		pclk, comcnmode))
    966 		return;
    967 #endif
    968 #ifdef SSCOM1CONSOLE
    969 	if (0 == s3c2440_sscom_cnattach(iot, 1, comcnspeed,
    970 		pclk, comcnmode))
    971 		return;
    972 #endif
    973 #endif				/* NSSCOM */
    974 #if NCOM>0 && defined(CONCOMADDR)
    975 	if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
    976 		COM_FREQ, COM_TYPE_NORMAL, comcnmode))
    977 		panic("can't init serial console @%x", CONCOMADDR);
    978 	return;
    979 #endif
    980 
    981 	consinit_done = 0;
    982 }
    983 
    984 
    985 #ifdef KGDB
    986 
    987 #if (NSSCOM > 0)
    988 
    989 #ifdef KGDB_DEVNAME
    990 const char kgdb_devname[] = KGDB_DEVNAME;
    991 #else
    992 const char kgdb_devname[] = "";
    993 #endif
    994 
    995 #ifndef KGDB_DEVMODE
    996 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE|CSTOPB|PARENB))|CS8) /* 8N1 */
    997 #endif
    998 int kgdb_sscom_mode = KGDB_DEVMODE;
    999 
   1000 #endif				/* NSSCOM */
   1001 
   1002 void
   1003 kgdb_port_init(void)
   1004 {
   1005 #if (NSSCOM > 0)
   1006 	int unit = -1;
   1007 	int pclk;
   1008 
   1009 	if (strcmp(kgdb_devname, "sscom0") == 0)
   1010 		unit = 0;
   1011 	else if (strcmp(kgdb_devname, "sscom1") == 0)
   1012 		unit = 1;
   1013 
   1014 	if (unit >= 0) {
   1015 		s3c24x0_clock_freq2(CLKMAN_VBASE, NULL, NULL, &pclk);
   1016 
   1017 		s3c2440_sscom_kgdb_attach(&s3c2xx0_bs_tag,
   1018 		    unit, kgdb_rate, pclk, kgdb_sscom_mode);
   1019 	}
   1020 #endif
   1021 }
   1022 #endif
   1023 
   1024 
   1025 static struct arm32_dma_range mini2440_dma_ranges[1];
   1026 
   1027 bus_dma_tag_t
   1028 s3c2xx0_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
   1029 {
   1030 	extern paddr_t physical_start, physical_end;
   1031 	struct arm32_bus_dma_tag *dmat;
   1032 
   1033 	mini2440_dma_ranges[0].dr_sysbase = physical_start;
   1034 	mini2440_dma_ranges[0].dr_busbase = physical_start;
   1035 	mini2440_dma_ranges[0].dr_len = physical_end - physical_start;
   1036 
   1037 #if 1
   1038 	dmat = dma_tag_template;
   1039 #else
   1040 	dmat = malloc(sizeof *dmat, M_DEVBUF, M_NOWAIT);
   1041 	if (dmat == NULL)
   1042 		return NULL;
   1043 	*dmat =  *dma_tag_template;
   1044 #endif
   1045 
   1046 	dmat->_ranges = mini2440_dma_ranges;
   1047 	dmat->_nranges = 1;
   1048 
   1049 	return dmat;
   1050 }
   1051 
   1052 void
   1053 mini2440_ksyms(struct btinfo_symtab *bi_symtab)
   1054 {
   1055 #if NKSYMS || defined(DDB) || defined(LKM)
   1056 	extern int end;
   1057 
   1058 #ifdef DDB
   1059 	db_machine_init();
   1060 #endif
   1061 	if (bi_symtab == NULL) {
   1062 		return;
   1063 	}
   1064 #ifdef VERBOSE_INIT_ARM
   1065 	printf("Got symbol table. nsym=%d, ssym=%p, esym=%p\n",
   1066 	       bi_symtab->nsym,
   1067 	       bi_symtab->ssym,
   1068 	       bi_symtab->esym);
   1069 #endif
   1070 
   1071 	ksyms_addsyms_elf(bi_symtab->nsym,
   1072 			  (int*)bi_symtab->ssym,
   1073 			  (int*)bi_symtab->esym);
   1074 #endif
   1075 }
   1076 
   1077 void *
   1078 lookup_bootinfo(int type)
   1079 {
   1080 	struct btinfo_common *bt;
   1081 	struct btinfo_common *help = (struct btinfo_common *)bootinfo;
   1082 
   1083 	if (help->next == 0)
   1084 		return (NULL);  /* bootinfo[] was not made */
   1085 	do {
   1086 		bt = help;
   1087 		if (bt->type == type)
   1088 			return (help);
   1089 		help = (struct btinfo_common *)((char*)help + bt->next);
   1090 	} while (bt->next &&
   1091 		 (size_t)help < (size_t)bootinfo + BOOTINFO_MAXSIZE);
   1092 
   1093 	return (NULL);
   1094 }
   1095 
   1096 
   1097 extern char *booted_kernel;
   1098 
   1099 static void
   1100 mini2440_device_register(device_t dev, void *aux) {
   1101 	if (device_class(dev) == DV_IFNET) {
   1102 #ifndef MEMORY_DISK_IS_ROOT
   1103 		if (bi_rdev != NULL && device_is_a(dev, bi_rdev->devname) ) {
   1104 			booted_device = dev;
   1105 			rootfstype = MOUNT_NFS;
   1106 			if( bi_path != NULL ) {
   1107 				booted_kernel = bi_path->bootpath;
   1108 			}
   1109 		}
   1110 #endif
   1111 		if (bi_net != NULL && device_is_a(dev, bi_net->devname)) {
   1112 			prop_data_t pd;
   1113 			pd = prop_data_create_data_nocopy(bi_net->mac_address, ETHER_ADDR_LEN);
   1114 			KASSERT(pd != NULL);
   1115 			if (prop_dictionary_set(device_properties(dev), "mac-address", pd) == false) {
   1116 				printf("WARNING: Unable to set mac-address property for %s\n", device_xname(dev));
   1117 			}
   1118 			prop_object_release(pd);
   1119 			bi_net = NULL;
   1120 		}
   1121 	}
   1122 #ifndef MEMORY_DISK_IS_ROOT
   1123 	if (bi_rdev != NULL && device_class(dev) == DV_DISK
   1124 	    && device_is_a(dev, bi_rdev->devname)
   1125 	    && device_unit(dev) == bi_rdev->cookie) {
   1126 		booted_device = dev;
   1127 		booted_partition = bi_rdev->partition;
   1128 		rootfstype = ROOT_FSTYPE_ANY;
   1129 		if( bi_path != NULL ) {
   1130 			booted_kernel = bi_path->bootpath;
   1131 		}
   1132 	}
   1133 #endif
   1134 }
   1135