Home | History | Annotate | Line # | Download | only in mini2440
mini2440_machdep.c revision 1.1
      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.1 2012/01/30 03:28:34 nisimura 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 int physmem = 0;
    241 
    242 /*int debug_flags;*/
    243 #ifndef PMAP_STATIC_L1S
    244 int max_processes = 64;		/* Default number */
    245 #endif				/* !PMAP_STATIC_L1S */
    246 
    247 /* Physical and virtual addresses for some global pages */
    248 pv_addr_t irqstack;
    249 pv_addr_t undstack;
    250 pv_addr_t abtstack;
    251 pv_addr_t kernelstack;
    252 
    253 vm_offset_t msgbufphys;
    254 
    255 extern u_int data_abort_handler_address;
    256 extern u_int prefetch_abort_handler_address;
    257 extern u_int undefined_handler_address;
    258 
    259 #ifdef PMAP_DEBUG
    260 extern int pmap_debug_level;
    261 #endif
    262 
    263 #define KERNEL_PT_SYS		0	/* L2 table for mapping zero page */
    264 #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
    265 #define	KERNEL_PT_KERNEL_NUM	2	/* L2 tables for mapping kernel VM */
    266 
    267 #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    268 
    269 #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    270 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    271 
    272 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    273 
    274 struct user *proc0paddr;
    275 
    276 /* Prototypes */
    277 
    278 void consinit(void);
    279 void kgdb_port_init(void);
    280 static void mini2440_ksyms(struct btinfo_symtab *bi_symtab);
    281 static void *lookup_bootinfo(int type);
    282 static void mini2440_device_register(device_t dev, void *aux);
    283 
    284 
    285 #include "com.h"
    286 #if NCOM > 0
    287 #include <dev/ic/comreg.h>
    288 #include <dev/ic/comvar.h>
    289 #endif
    290 
    291 #include "sscom.h"
    292 #if NSSCOM > 0
    293 #include "opt_sscom.h"
    294 #include <arm/s3c2xx0/sscom_var.h>
    295 #endif
    296 
    297 /*
    298  * Define the default console speed for the board.  This is generally
    299  * what the firmware provided with the board defaults to.
    300  */
    301 #ifndef CONSPEED
    302 #define CONSPEED B115200	/* TTYDEF_SPEED */
    303 #endif
    304 #ifndef CONMODE
    305 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)   /* 8N1 */
    306 #endif
    307 
    308 int comcnspeed = CONSPEED;
    309 int comcnmode = CONMODE;
    310 
    311 /*
    312  * void cpu_reboot(int howto, char *bootstr)
    313  *
    314  * Reboots the system
    315  *
    316  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    317  * then reset the CPU.
    318  */
    319 void
    320 cpu_reboot(int howto, char *bootstr)
    321 {
    322 #ifdef DIAGNOSTIC
    323 	/* info */
    324 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    325 #endif
    326 
    327 	cpu_reset_address = vtophys((u_int)s3c2440_softreset);
    328 
    329 	/*
    330 	 * If we are still cold then hit the air brakes
    331 	 * and crash to earth fast
    332 	 */
    333 	if (cold) {
    334 		doshutdownhooks();
    335 		printf("The operating system has halted.\n");
    336 		printf("Please press any key to reboot.\n\n");
    337 		cngetc();
    338 		printf("rebooting...\n");
    339 		cpu_reset();
    340 		/* NOTREACHED */
    341 	}
    342 	/* Disable console buffering */
    343 
    344 	/*
    345 	 * If RB_NOSYNC was not specified sync the discs.
    346 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    347 	 * unmount.  It looks like syslogd is getting woken up only to find
    348 	 * that it cannot page part of the binary in as the filesystem has
    349 	 * been unmounted.
    350 	 */
    351 	if (!(howto & RB_NOSYNC))
    352 		bootsync();
    353 
    354 	/* Say NO to interrupts */
    355 	splhigh();
    356 
    357 	/* Do a dump if requested. */
    358 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    359 		dumpsys();
    360 
    361 	/* Run any shutdown hooks */
    362 	doshutdownhooks();
    363 
    364 	/* Make sure IRQ's are disabled */
    365 	IRQdisable;
    366 
    367 	if (howto & RB_HALT) {
    368 		printf("The operating system has halted.\n");
    369 		printf("Please press any key to reboot.\n\n");
    370 		cngetc();
    371 	}
    372 	printf("rebooting...\n");
    373 	cpu_reset();
    374 	/* NOTREACHED */
    375 }
    376 
    377 /*
    378  * Static device mappings. These peripheral registers are mapped at
    379  * fixed virtual addresses very early in initarm() so that we can use
    380  * them while booting the kernel , and stay at the same address
    381  * throughout whole kernel's life time.
    382  *
    383  * We use this table twice; once with bootstrap page table, and once
    384  * with kernel's page table which we build up in initarm().
    385  *
    386  * Since we map these registers into the bootstrap page table using
    387  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    388  * registers segment-aligned and segment-rounded in order to avoid
    389  * using the 2nd page tables.
    390  */
    391 
    392 #define	_A(a)	((a) & ~L1_S_OFFSET)
    393 #define	_S(s)	(((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    394 
    395 #define	_V(n)	(MINI2440_IO_VBASE + (n) * L1_S_SIZE)
    396 
    397 #define	GPIO_VBASE	_V(0)
    398 #define	INTCTL_VBASE	_V(1)
    399 #define	CLKMAN_VBASE	_V(2)
    400 #define	UART_VBASE	_V(3)
    401 
    402 static const struct pmap_devmap mini2440_devmap[] = {
    403 	/* GPIO registers */
    404 	{
    405 		GPIO_VBASE,
    406 		_A(S3C2440_GPIO_BASE),
    407 		_S(S3C2440_GPIO_SIZE),
    408 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    409 	},
    410 	{
    411 		INTCTL_VBASE,
    412 		_A(S3C2440_INTCTL_BASE),
    413 		_S(S3C2440_INTCTL_SIZE),
    414 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    415 	},
    416 	{
    417 		CLKMAN_VBASE,
    418 		_A(S3C2440_CLKMAN_BASE),
    419 		_S(S3C24X0_CLKMAN_SIZE),
    420 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    421 	},
    422 	{	/* UART registers for UART0, 1, 2. */
    423 		UART_VBASE,
    424 		_A(S3C2440_UART0_BASE),
    425 		_S(S3C2440_UART_BASE(3) - S3C2440_UART0_BASE),
    426 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    427 	},
    428 
    429 	{ 0, 0, 0, 0 }
    430 };
    431 
    432 #undef	_A
    433 #undef	_S
    434 
    435 static inline	pd_entry_t *
    436 read_ttb(void)
    437 {
    438 	long ttb;
    439 
    440 	__asm volatile("mrc	p15, 0, %0, c2, c0, 0" : "=r"(ttb));
    441 
    442 
    443 	return (pd_entry_t *)(ttb & ~((1 << 14) - 1));
    444 }
    445 
    446 
    447 #define	ioreg_write32(a,v)  	(*(volatile uint32_t *)(a)=(v))
    448 
    449 /*
    450  * u_int initarm(...)
    451  *
    452  * Initial entry point on startup. This gets called before main() is
    453  * entered.
    454  * It should be responsible for setting up everything that must be
    455  * in place when main is called.
    456  * This includes
    457  *   Taking a copy of the boot configuration structure.
    458  *   Initialising the physical console so characters can be printed.
    459  *   Setting up page tables for the kernel
    460  *   Relocating the kernel to the bottom of physical memory
    461  */
    462 
    463 u_int
    464 initarm(void *arg)
    465 {
    466 	int loop;
    467 	int loop1;
    468 	u_int l1pagetable;
    469 	extern int etext __asm("_etext");
    470 	extern int end __asm("_end");
    471 	uint32_t kerneldatasize;
    472 	struct btinfo_magic *bi_magic = arg;
    473 	struct btinfo_bootstring *bi_bootstring;
    474 	struct btinfo_symtab *bi_symtab;
    475 
    476 	boothowto = 0;
    477 
    478 	/* Copy bootinfo from boot loader into kernel memory where it remains.
    479 	 */
    480 	if (bi_magic != 0x0 && bi_magic->magic == BOOTINFO_MAGIC) {
    481 		memcpy(bootinfo, bi_magic, sizeof(bootinfo));
    482 	} else {
    483 		memset(bootinfo, 0, sizeof(bootinfo));
    484 	}
    485 
    486 	/* Extract boot_args from bootinfo */
    487 	bi_bootstring = lookup_bootinfo(BTINFO_BOOTSTRING);
    488 	if (bi_bootstring ) {
    489 		printf("Bootloader args are %s\n", bi_bootstring->bootstring);
    490 		boot_args = bi_bootstring->bootstring;
    491 		parse_mi_bootargs(boot_args);
    492 	}
    493 
    494 #define pdatb (*(volatile uint8_t *)(S3C2440_GPIO_BASE+GPIO_PBDAT))
    495 
    496 // 0x1E0 is the mask for GPB5, GPB6, GPB7, and GPB8
    497 #define __LED(x)  (pdatb = (pdatb & ~0x1e0) | (~(1<<(x+5)) & 0x1e0))
    498 
    499 	__LED(0);
    500 
    501 	/*
    502 	 * Heads up ... Setup the CPU / MMU / TLB functions
    503 	 */
    504 	if (set_cpufuncs())
    505 		panic("cpu not recognized!");
    506 
    507 	/*
    508 	 * Map I/O registers that are used in startup.  Now we are
    509 	 * still using page table prepared by bootloader.  Later we'll
    510 	 * map those registers at the same address in the kernel page
    511 	 * table.
    512 	 */
    513 	pmap_devmap_bootstrap((vaddr_t)read_ttb(), mini2440_devmap);
    514 
    515 #undef	pdatb
    516 #define pdatb (*(volatile uint8_t *)(GPIO_VBASE+GPIO_PBDAT))
    517 
    518 	/* Disable all peripheral interrupts */
    519 	ioreg_write32(INTCTL_VBASE + INTCTL_INTMSK, ~0);
    520 
    521 	__LED(1);
    522 
    523 	/* initialize some variables so that splfoo() doesn't
    524 	   touch illegal address.  */
    525 	s3c2xx0_intr_bootstrap(INTCTL_VBASE);
    526 
    527 	__LED(2);
    528 	consinit();
    529 	__LED(3);
    530 
    531 	/* Extract information from the bootloader configuration */
    532 	bi_rdev = lookup_bootinfo(BTINFO_ROOTDEVICE);
    533 	bi_net = lookup_bootinfo(BTINFO_NET);
    534 	bi_path = lookup_bootinfo(BTINFO_BOOTPATH);
    535 
    536 #ifdef VERBOSE_INIT_ARM
    537 	printf("consinit done\n");
    538 #endif
    539 
    540 #ifdef KGDB
    541 	kgdb_port_init();
    542 #endif
    543 
    544 #ifdef VERBOSE_INIT_ARM
    545 	/* Talk to the user */
    546 	printf("\nNetBSD/evbarm (MINI2440) booting ...\n");
    547 #endif
    548 	/*
    549 	 * Ok we have the following memory map
    550 	 *
    551 	 * Physical Address Range     Description
    552 	 * -----------------------    ----------------------------------
    553 	 * 0x30000000 - 0x33ffffff    SDRAM (64MB)
    554          *
    555          * Kernel is loaded by bootloader at 0x30200000
    556 	 *
    557 	 * The initarm() has the responsibility for creating the kernel
    558 	 * page tables.
    559 	 * It must also set up various memory pointers that are used
    560 	 * by pmap etc.
    561 	 */
    562 
    563 	/* Fake bootconfig structure for the benefit of pmap.c */
    564 	/* XXX must make the memory description h/w independent */
    565 	bootconfig.dramblocks = 1;
    566 	bootconfig.dram[0].address = SDRAM_START;
    567 	bootconfig.dram[0].pages = SDRAM_SIZE / PAGE_SIZE;
    568 
    569 	/*
    570 	 * Set up the variables that define the availablilty of
    571 	 * physical memory.
    572          * We use the 2MB between the physical start and the kernel to
    573          * begin with. Allocating from 0x30200000 and downwards
    574 	 * If we get too close to the bottom of SDRAM, we
    575 	 * will panic.  We will update physical_freestart and
    576 	 * physical_freeend later to reflect what pmap_bootstrap()
    577 	 * wants to see.
    578 	 *
    579 	 * XXX pmap_bootstrap() needs an enema.
    580 	 */
    581 	physical_start = bootconfig.dram[0].address;
    582 	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
    583 
    584 	physical_freestart = SDRAM_START;	/* XXX */
    585 	physical_freeend = SDRAM_START + KERNEL_OFFSET;
    586 
    587 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    588 
    589 #ifdef VERBOSE_INIT_ARM
    590 	/* Tell the user about the memory */
    591 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    592 	    physical_start, physical_end - 1);
    593 	printf("phys_end: 0x%08lx\n", physical_end);
    594 #endif
    595 
    596 	/*
    597 	 * XXX
    598 	 * Okay, the kernel starts 2MB in from the bottom of physical
    599 	 * memory.  We are going to allocate our bootstrap pages downwards
    600 	 * from there.
    601 	 *
    602 	 * We need to allocate some fixed page tables to get the kernel
    603 	 * going.  We allocate one page directory and a number of page
    604 	 * tables and store the physical addresses in the kernel_pt_table
    605 	 * array.
    606 	 *
    607 	 * The kernel page directory must be on a 16K boundary.  The page
    608 	 * tables must be on 4K boundaries.  What we do is allocate the
    609 	 * page directory on the first 16K boundary that we encounter, and
    610 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    611 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    612 	 * least one 16K aligned region.
    613 	 */
    614 
    615 #ifdef VERBOSE_INIT_ARM
    616 	printf("Allocating page tables\n");
    617 #endif
    618 
    619 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    620 
    621 #ifdef VERBOSE_INIT_ARM
    622 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x), freeend = 0x%08lx\n",
    623 	    physical_freestart, free_pages, free_pages, physical_freeend);
    624 #endif
    625 
    626 	/* Define a macro to simplify memory allocation */
    627 #define	valloc_pages(var, np)				\
    628 	alloc_pages((var).pv_pa, (np));			\
    629 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    630 
    631 #define alloc_pages(var, np)				\
    632 	physical_freeend -= ((np) * PAGE_SIZE);		\
    633 	if (physical_freeend < physical_freestart)	\
    634 		panic("initarm: out of memory");	\
    635 	(var) = physical_freeend;			\
    636 	free_pages -= (np);				\
    637 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    638 
    639 	loop1 = 0;
    640 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    641 		/* Are we 16KB aligned for an L1 ? */
    642 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    643 		    && kernel_l1pt.pv_pa == 0) {
    644 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    645 		} else {
    646 			valloc_pages(kernel_pt_table[loop1],
    647 			    L2_TABLE_SIZE / PAGE_SIZE);
    648 			++loop1;
    649 		}
    650 	}
    651 
    652 	/* This should never be able to happen but better confirm that. */
    653 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE - 1)) != 0)
    654 		panic("initarm: Failed to align the kernel page directory\n");
    655 
    656 	/*
    657 	 * Allocate a page for the system page mapped to V0x00000000
    658 	 * This page will just contain the system vectors and can be
    659 	 * shared by all processes.
    660 	 */
    661 	alloc_pages(systempage.pv_pa, 1);
    662 
    663 	/* Allocate stacks for all modes */
    664 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    665 	valloc_pages(abtstack, ABT_STACK_SIZE);
    666 	valloc_pages(undstack, UND_STACK_SIZE);
    667 	valloc_pages(kernelstack, UPAGES);
    668 
    669 #ifdef VERBOSE_INIT_ARM
    670 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    671 	    irqstack.pv_va);
    672 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    673 	    abtstack.pv_va);
    674 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    675 	    undstack.pv_va);
    676 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    677 	    kernelstack.pv_va);
    678 	printf("Free memory in bootstrap region: %ld bytes\n", physical_freeend - physical_freestart);
    679 #endif
    680 
    681 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    682 
    683 	physical_freeend_low = physical_freeend;
    684 
    685 	/*
    686 	 * Ok we have allocated physical pages for the primary kernel
    687 	 * page tables
    688 	 */
    689 
    690 #ifdef VERBOSE_INIT_ARM
    691 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    692 #endif
    693 
    694 	/*
    695 	 * Now we start construction of the L1 page table
    696 	 * We start by mapping the L2 page tables into the L1.
    697 	 * This means that we can replace L1 mappings later on if necessary
    698 	 */
    699 	l1pagetable = kernel_l1pt.pv_pa;
    700 
    701 	/* Map the L2 pages tables in the L1 page table */
    702 	pmap_link_l2pt(l1pagetable, 0x00000000,
    703 	    &kernel_pt_table[KERNEL_PT_SYS]);
    704 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    705 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    706 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    707 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    708 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    709 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    710 
    711 	/* update the top of the kernel VM */
    712 	pmap_curmaxkvaddr =
    713 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    714 
    715 #ifdef VERBOSE_INIT_ARM
    716 	printf("Mapping kernel\n");
    717 #endif
    718 
    719 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    720 	{
    721 		/* Total size must include symbol table, if it exists.
    722 		   The size of the symbol table can be acquired from the ELF
    723 		   header, to which a pointer is passed in the boot info (ssym).
    724 		 */
    725 		size_t textsize = (uintptr_t)&etext - KERNEL_TEXT_BASE;
    726 		kerneldatasize = (uintptr_t)&end - KERNEL_TEXT_BASE;
    727 		u_int logical;
    728 
    729 		bi_symtab = lookup_bootinfo(BTINFO_SYMTAB);
    730 
    731 		if (bi_symtab) {
    732 			Elf_Ehdr *elfHeader;
    733 			Elf_Shdr *sectionHeader;
    734 			int nsection;
    735 			int sz = 0;
    736 
    737 			elfHeader = bi_symtab->ssym;
    738 
    739 #ifdef VERBOSE_INIT_ARM
    740 			printf("Symbol table information provided by bootloader\n");
    741 			printf("ELF header is at %p\n", elfHeader);
    742 #endif
    743 			sectionHeader = (Elf_Shdr*)((char*)(bi_symtab->ssym) +
    744 						     (elfHeader->e_shoff));
    745 			nsection = elfHeader->e_shnum;
    746 #ifdef VERBOSE_INIT_ARM
    747 			printf("Number of sections: %d\n", nsection);
    748 #endif
    749 			for(; nsection > 0; nsection--, sectionHeader++) {
    750 				if (sectionHeader->sh_offset > 0 &&
    751 				    (sectionHeader->sh_offset + sectionHeader->sh_size) > sz)
    752 					sz = sectionHeader->sh_offset + sectionHeader->sh_size;
    753 			}
    754 #ifdef VERBOSE_INIT_ARM
    755 			printf("Max size of sections: %d\n", sz);
    756 #endif
    757 			kerneldatasize += sz;
    758 		}
    759 
    760 #ifdef VERBOSE_INIT_ARM
    761 		printf("Textsize: %u, kerneldatasize: %u\n", (uint)textsize,
    762 		       (uint)kerneldatasize);
    763 		printf("&etext: 0x%x\n", (uint)&etext);
    764 		printf("&end: 0x%x\n", (uint)&end);
    765 		printf("KERNEL_TEXT_BASE: 0x%x\n", KERNEL_TEXT_BASE);
    766 #endif
    767 
    768 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    769 		kerneldatasize = (kerneldatasize + PGOFSET) & ~PGOFSET;
    770 
    771 		logical = KERNEL_OFFSET;	/* offset of kernel in RAM */
    772 
    773 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    774 					  physical_start + logical, textsize,
    775 					  VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    776 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    777 					  physical_start + logical, kerneldatasize - textsize,
    778 					  VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    779 	}
    780 
    781 #ifdef VERBOSE_INIT_ARM
    782 	printf("Constructing L2 page tables\n");
    783 #endif
    784 
    785 	/* Map the stack pages */
    786 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    787 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
    788 	    PTE_CACHE);
    789 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    790 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
    791 	    PTE_CACHE);
    792 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    793 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE,
    794 	    PTE_CACHE);
    795 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    796 	    UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    797 
    798 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    799 	    L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
    800 
    801 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    802 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    803 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    804 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    805 	}
    806 
    807 	/* Map the vector page. */
    808 #if 0
    809 	/* MULTI-ICE requires that page 0 is NC/NB so that it can download the
    810 	 * cache-clean code there.  */
    811 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    812 	    VM_PROT_READ | VM_PROT_WRITE, PTE_NOCACHE);
    813 #else
    814 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    815 	    VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    816 #endif
    817 
    818 	/*
    819 	 * map integrated peripherals at same address in l1pagetable
    820 	 * so that we can continue to use console.
    821 	 */
    822 	pmap_devmap_bootstrap(l1pagetable, mini2440_devmap);
    823 
    824 	/*
    825 	 * Now we have the real page tables in place so we can switch to them.
    826 	 * Once this is done we will be running with the REAL kernel page
    827 	 * tables.
    828 	 */
    829 	/*
    830 	 * Update the physical_freestart/physical_freeend/free_pages
    831 	 * variables.
    832 	 */
    833 	physical_freestart = physical_start +
    834 	  (KERNEL_TEXT_BASE - KERNEL_BASE) + kerneldatasize;
    835 	physical_freeend = physical_end;
    836 	free_pages =
    837 	  (physical_freeend - physical_freestart) / PAGE_SIZE;
    838 
    839 	/* Switch tables */
    840 #ifdef VERBOSE_INIT_ARM
    841 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    842 	    physical_freestart, free_pages, free_pages);
    843 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    844 #endif
    845 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    846 	cpu_setttb(kernel_l1pt.pv_pa);
    847 	cpu_tlb_flushID();
    848 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    849 
    850 	/*
    851 	 * Moved from cpu_startup() as data_abort_handler() references
    852 	 * this during uvm init
    853 	 */
    854 	uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
    855 
    856 #ifdef VERBOSE_INIT_ARM
    857 	printf("done!\n");
    858 #endif
    859 
    860 #ifdef VERBOSE_INIT_ARM
    861 	printf("bootstrap done.\n");
    862 #endif
    863 
    864 	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
    865 
    866 	/*
    867 	 * Pages were allocated during the secondary bootstrap for the
    868 	 * stacks for different CPU modes.
    869 	 * We must now set the r13 registers in the different CPU modes to
    870 	 * point to these stacks.
    871 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    872 	 * of the stack memory.
    873 	 */
    874 #ifdef VERBOSE_INIT_ARM
    875 	printf("init subsystems: stacks ");
    876 #endif
    877 
    878 	set_stackptr(PSR_IRQ32_MODE,
    879 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    880 	set_stackptr(PSR_ABT32_MODE,
    881 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    882 	set_stackptr(PSR_UND32_MODE,
    883 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    884 
    885 	cpu_idcache_wbinv_all();
    886 
    887 	/*
    888 	 * Well we should set a data abort handler.
    889 	 * Once things get going this will change as we will need a proper
    890 	 * handler.
    891 	 * Until then we will use a handler that just panics but tells us
    892 	 * why.
    893 	 * Initialisation of the vectors will just panic on a data abort.
    894 	 * This just fills in a slightly better one.
    895 	 */
    896 #ifdef VERBOSE_INIT_ARM
    897 	printf("vectors ");
    898 #endif
    899 	data_abort_handler_address = (u_int)data_abort_handler;
    900 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    901 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    902 
    903 	/* Initialise the undefined instruction handlers */
    904 #ifdef VERBOSE_INIT_ARM
    905 	printf("undefined ");
    906 #endif
    907 	undefined_init();
    908 
    909 	/* Load memory into UVM. */
    910 #ifdef VERBOSE_INIT_ARM
    911 	printf("page ");
    912 #endif
    913 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    914 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    915 	    atop(physical_freestart), atop(physical_freeend),
    916 	    VM_FREELIST_DEFAULT);
    917 	uvm_page_physload(atop(SDRAM_START), atop(physical_freeend_low),
    918 	    atop(SDRAM_START), atop(physical_freeend_low),
    919 	    VM_FREELIST_DEFAULT);
    920 
    921 
    922 	/* Boot strap pmap telling it where the kernel page table is */
    923 #ifdef VERBOSE_INIT_ARM
    924 	printf("pmap ");
    925 #endif
    926 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    927 
    928 #ifdef VERBOSE_INIT_ARM
    929 	printf("done.\n");
    930 #endif
    931 
    932 #ifdef BOOTHOWTO
    933 	boothowto |= BOOTHOWTO;
    934 #endif
    935 
    936 #ifdef KGDB
    937 	if (boothowto & RB_KDB) {
    938 		kgdb_debug_init = 1;
    939 		kgdb_connect(1);
    940 	}
    941 #endif
    942 
    943 	mini2440_ksyms(bi_symtab);
    944 
    945 #ifdef DDB
    946 	/*db_machine_init();*/
    947 	if (boothowto & RB_KDB)
    948 		Debugger();
    949 #endif
    950 
    951 	evbarm_device_register = mini2440_device_register;
    952 
    953 	/* We return the new stack pointer address */
    954 	return (kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    955 }
    956 
    957 void
    958 consinit(void)
    959 {
    960 	static int consinit_done = 0;
    961 #if defined(SSCOM0CONSOLE) || defined(SSCOM1CONSOLE)
    962 	bus_space_tag_t iot = &s3c2xx0_bs_tag;
    963 #endif
    964 	int pclk;
    965 
    966 	if (consinit_done != 0)
    967 		return;
    968 
    969 	consinit_done = 1;
    970 
    971 	s3c24x0_clock_freq2(CLKMAN_VBASE, NULL, NULL, &pclk);
    972 
    973 #if NSSCOM > 0
    974 #ifdef SSCOM0CONSOLE
    975 	if (0 == s3c2440_sscom_cnattach(iot, 0, comcnspeed,
    976 		pclk, comcnmode))
    977 		return;
    978 #endif
    979 #ifdef SSCOM1CONSOLE
    980 	if (0 == s3c2440_sscom_cnattach(iot, 1, comcnspeed,
    981 		pclk, comcnmode))
    982 		return;
    983 #endif
    984 #endif				/* NSSCOM */
    985 #if NCOM>0 && defined(CONCOMADDR)
    986 	if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
    987 		COM_FREQ, COM_TYPE_NORMAL, comcnmode))
    988 		panic("can't init serial console @%x", CONCOMADDR);
    989 	return;
    990 #endif
    991 
    992 	consinit_done = 0;
    993 }
    994 
    995 
    996 #ifdef KGDB
    997 
    998 #if (NSSCOM > 0)
    999 
   1000 #ifdef KGDB_DEVNAME
   1001 const char kgdb_devname[] = KGDB_DEVNAME;
   1002 #else
   1003 const char kgdb_devname[] = "";
   1004 #endif
   1005 
   1006 #ifndef KGDB_DEVMODE
   1007 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE|CSTOPB|PARENB))|CS8) /* 8N1 */
   1008 #endif
   1009 int kgdb_sscom_mode = KGDB_DEVMODE;
   1010 
   1011 #endif				/* NSSCOM */
   1012 
   1013 void
   1014 kgdb_port_init(void)
   1015 {
   1016 #if (NSSCOM > 0)
   1017 	int unit = -1;
   1018 	int pclk;
   1019 
   1020 	if (strcmp(kgdb_devname, "sscom0") == 0)
   1021 		unit = 0;
   1022 	else if (strcmp(kgdb_devname, "sscom1") == 0)
   1023 		unit = 1;
   1024 
   1025 	if (unit >= 0) {
   1026 		s3c24x0_clock_freq2(CLKMAN_VBASE, NULL, NULL, &pclk);
   1027 
   1028 		s3c2440_sscom_kgdb_attach(&s3c2xx0_bs_tag,
   1029 		    unit, kgdb_rate, pclk, kgdb_sscom_mode);
   1030 	}
   1031 #endif
   1032 }
   1033 #endif
   1034 
   1035 
   1036 static struct arm32_dma_range mini2440_dma_ranges[1];
   1037 
   1038 bus_dma_tag_t
   1039 s3c2xx0_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
   1040 {
   1041 	extern paddr_t physical_start, physical_end;
   1042 	struct arm32_bus_dma_tag *dmat;
   1043 
   1044 	mini2440_dma_ranges[0].dr_sysbase = physical_start;
   1045 	mini2440_dma_ranges[0].dr_busbase = physical_start;
   1046 	mini2440_dma_ranges[0].dr_len = physical_end - physical_start;
   1047 
   1048 #if 1
   1049 	dmat = dma_tag_template;
   1050 #else
   1051 	dmat = malloc(sizeof *dmat, M_DEVBUF, M_NOWAIT);
   1052 	if (dmat == NULL)
   1053 		return NULL;
   1054 	*dmat =  *dma_tag_template;
   1055 #endif
   1056 
   1057 	dmat->_ranges = mini2440_dma_ranges;
   1058 	dmat->_nranges = 1;
   1059 
   1060 	return dmat;
   1061 }
   1062 
   1063 void
   1064 mini2440_ksyms(struct btinfo_symtab *bi_symtab)
   1065 {
   1066 #if NKSYMS || defined(DDB) || defined(LKM)
   1067 	extern int end;
   1068 
   1069 #ifdef DDB
   1070 	db_machine_init();
   1071 #endif
   1072 	if (bi_symtab == NULL) {
   1073 		return;
   1074 	}
   1075 #ifdef VERBOSE_INIT_ARM
   1076 	printf("Got symbol table. nsym=%d, ssym=%p, esym=%p\n",
   1077 	       bi_symtab->nsym,
   1078 	       bi_symtab->ssym,
   1079 	       bi_symtab->esym);
   1080 #endif
   1081 
   1082 	ksyms_addsyms_elf(bi_symtab->nsym,
   1083 			  (int*)bi_symtab->ssym,
   1084 			  (int*)bi_symtab->esym);
   1085 #endif
   1086 }
   1087 
   1088 void *
   1089 lookup_bootinfo(int type)
   1090 {
   1091 	struct btinfo_common *bt;
   1092 	struct btinfo_common *help = (struct btinfo_common *)bootinfo;
   1093 
   1094 	if (help->next == 0)
   1095 		return (NULL);  /* bootinfo[] was not made */
   1096 	do {
   1097 		bt = help;
   1098 		if (bt->type == type)
   1099 			return (help);
   1100 		help = (struct btinfo_common *)((char*)help + bt->next);
   1101 	} while (bt->next &&
   1102 		 (size_t)help < (size_t)bootinfo + BOOTINFO_MAXSIZE);
   1103 
   1104 	return (NULL);
   1105 }
   1106 
   1107 
   1108 extern char *booted_kernel;
   1109 
   1110 static void
   1111 mini2440_device_register(device_t dev, void *aux) {
   1112 	if (device_class(dev) == DV_IFNET) {
   1113 		if (bi_rdev != NULL && device_is_a(dev, bi_rdev->devname) ) {
   1114 			booted_device = dev;
   1115 			rootfstype = MOUNT_NFS;
   1116 			if( bi_path != NULL ) {
   1117 				booted_kernel = bi_path->bootpath;
   1118 			}
   1119 		}
   1120 		if (bi_net != NULL && device_is_a(dev, bi_net->devname)) {
   1121 			prop_data_t pd;
   1122 			pd = prop_data_create_data_nocopy(bi_net->mac_address, ETHER_ADDR_LEN);
   1123 			KASSERT(pd != NULL);
   1124 			if (prop_dictionary_set(device_properties(dev), "mac-address", pd) == false) {
   1125 				printf("WARNING: Unable to set mac-address property for %s\n", device_xname(dev));
   1126 			}
   1127 			prop_object_release(pd);
   1128 			bi_net = NULL;
   1129 		}
   1130 	}
   1131 	if (bi_rdev != NULL && device_class(dev) == DV_DISK
   1132 	    && device_is_a(dev, bi_rdev->devname)
   1133 	    && device_unit(dev) == bi_rdev->cookie) {
   1134 		booted_device = dev;
   1135 		booted_partition = bi_rdev->partition;
   1136 		rootfstype = ROOT_FSTYPE_ANY;
   1137 		if( bi_path != NULL ) {
   1138 			booted_kernel = bi_path->bootpath;
   1139 		}
   1140 	}
   1141 }
   1142