Home | History | Annotate | Line # | Download | only in gumstix
gumstix_machdep.c revision 1.25
      1 /*	$NetBSD: gumstix_machdep.c,v 1.25 2010/03/07 09:18:51 kiyohara Exp $ */
      2 /*
      3  * Copyright (C) 2005, 2006, 2007  WIDE Project and SOUM Corporation.
      4  * All rights reserved.
      5  *
      6  * Written by Takashi Kiyohara and Susumu Miki for WIDE Project and SOUM
      7  * Corporation.
      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. Neither the name of the project nor the name of SOUM Corporation
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT and SOUM CORPORATION ``AS IS''
     22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT AND SOUM CORPORATION
     25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31  * POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 /*
     34  * Copyright (c) 2002, 2003, 2004, 2005  Genetec Corporation.
     35  * All rights reserved.
     36  *
     37  * Written by Hiroyuki Bessho for Genetec Corporation.
     38  *
     39  * Redistribution and use in source and binary forms, with or without
     40  * modification, are permitted provided that the following conditions
     41  * are met:
     42  * 1. Redistributions of source code must retain the above copyright
     43  *    notice, this list of conditions and the following disclaimer.
     44  * 2. Redistributions in binary form must reproduce the above copyright
     45  *    notice, this list of conditions and the following disclaimer in the
     46  *    documentation and/or other materials provided with the distribution.
     47  * 3. The name of Genetec Corporation may not be used to endorse or
     48  *    promote products derived from this software without specific prior
     49  *    written permission.
     50  *
     51  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     52  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     53  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     54  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     55  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     56  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     57  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     58  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     59  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     60  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     61  * POSSIBILITY OF SUCH DAMAGE.
     62  *
     63  * Machine dependant functions for kernel setup for Genetec G4250EBX
     64  * evaluation board.
     65  *
     66  * Based on iq80310_machhdep.c
     67  */
     68 /*
     69  * Copyright (c) 2001 Wasabi Systems, Inc.
     70  * All rights reserved.
     71  *
     72  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     73  *
     74  * Redistribution and use in source and binary forms, with or without
     75  * modification, are permitted provided that the following conditions
     76  * are met:
     77  * 1. Redistributions of source code must retain the above copyright
     78  *    notice, this list of conditions and the following disclaimer.
     79  * 2. Redistributions in binary form must reproduce the above copyright
     80  *    notice, this list of conditions and the following disclaimer in the
     81  *    documentation and/or other materials provided with the distribution.
     82  * 3. All advertising materials mentioning features or use of this software
     83  *    must display the following acknowledgement:
     84  *	This product includes software developed for the NetBSD Project by
     85  *	Wasabi Systems, Inc.
     86  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     87  *    or promote products derived from this software without specific prior
     88  *    written permission.
     89  *
     90  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     91  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     92  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     93  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     94  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     95  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     96  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     97  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     98  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     99  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    100  * POSSIBILITY OF SUCH DAMAGE.
    101  */
    102 
    103 /*
    104  * Copyright (c) 1997,1998 Mark Brinicombe.
    105  * Copyright (c) 1997,1998 Causality Limited.
    106  * All rights reserved.
    107  *
    108  * Redistribution and use in source and binary forms, with or without
    109  * modification, are permitted provided that the following conditions
    110  * are met:
    111  * 1. Redistributions of source code must retain the above copyright
    112  *    notice, this list of conditions and the following disclaimer.
    113  * 2. Redistributions in binary form must reproduce the above copyright
    114  *    notice, this list of conditions and the following disclaimer in the
    115  *    documentation and/or other materials provided with the distribution.
    116  * 3. All advertising materials mentioning features or use of this software
    117  *    must display the following acknowledgement:
    118  *	This product includes software developed by Mark Brinicombe
    119  *	for the NetBSD Project.
    120  * 4. The name of the company nor the name of the author may be used to
    121  *    endorse or promote products derived from this software without specific
    122  *    prior written permission.
    123  *
    124  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
    125  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    126  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    127  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    128  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    129  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    130  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    131  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    132  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    133  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    134  * SUCH DAMAGE.
    135  *
    136  * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
    137  * boards using RedBoot firmware.
    138  */
    139 
    140 #include "opt_gumstix.h"
    141 #include "opt_ddb.h"
    142 #include "opt_kgdb.h"
    143 #include "opt_pmap_debug.h"
    144 #include "opt_md.h"
    145 #include "opt_modular.h"
    146 #include "opt_com.h"
    147 #include "md.h"
    148 
    149 #include <sys/param.h>
    150 #include <sys/device.h>
    151 #include <sys/systm.h>
    152 #include <sys/kernel.h>
    153 #include <sys/exec.h>
    154 #include <sys/proc.h>
    155 #include <sys/msgbuf.h>
    156 #include <sys/reboot.h>
    157 #include <sys/termios.h>
    158 #include <sys/ksyms.h>
    159 
    160 #include <uvm/uvm_extern.h>
    161 
    162 #include <sys/conf.h>
    163 #include <dev/cons.h>
    164 #include <dev/md.h>
    165 
    166 #include <machine/db_machdep.h>
    167 #include <ddb/db_sym.h>
    168 #include <ddb/db_extern.h>
    169 #ifdef KGDB
    170 #include <sys/kgdb.h>
    171 #endif
    172 
    173 #include <machine/bootconfig.h>
    174 #include <machine/bus.h>
    175 #include <machine/cpu.h>
    176 #include <machine/frame.h>
    177 #include <arm/undefined.h>
    178 
    179 #include <arm/arm32/machdep.h>
    180 
    181 #include <arm/xscale/pxa2x0reg.h>
    182 #include <arm/xscale/pxa2x0var.h>
    183 #include <arm/xscale/pxa2x0_gpio.h>
    184 #include <evbarm/gumstix/gumstixreg.h>
    185 #include <evbarm/gumstix/gumstixvar.h>
    186 
    187 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    188 #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
    189 #ifndef KERNEL_VM_BASE
    190 #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    191 #endif
    192 
    193 /*
    194  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    195  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    196  */
    197 #define KERNEL_VM_SIZE		0x0C000000
    198 
    199 
    200 /*
    201  * Address to call from cpu_reset() to reset the machine.
    202  * This is machine architecture dependant as it varies depending
    203  * on where the ROM appears when you turn the MMU off.
    204  */
    205 
    206 u_int cpu_reset_address = 0;
    207 
    208 /* Define various stack sizes in pages */
    209 #define IRQ_STACK_SIZE	1
    210 #define ABT_STACK_SIZE	1
    211 #define UND_STACK_SIZE	1
    212 
    213 BootConfig bootconfig;		/* Boot config storage */
    214 static char bootargs[MAX_BOOT_STRING];
    215 char *boot_args = NULL;
    216 
    217 uint32_t system_serial_high;
    218 uint32_t system_serial_low;
    219 
    220 vm_offset_t physical_start;
    221 vm_offset_t physical_freestart;
    222 vm_offset_t physical_freeend;
    223 vm_offset_t physical_end;
    224 u_int free_pages;
    225 
    226 /*int debug_flags;*/
    227 #ifndef PMAP_STATIC_L1S
    228 int max_processes = 64;			/* Default number */
    229 #endif	/* !PMAP_STATIC_L1S */
    230 
    231 /* Physical and virtual addresses for some global pages */
    232 pv_addr_t irqstack;
    233 pv_addr_t undstack;
    234 pv_addr_t abtstack;
    235 pv_addr_t kernelstack;
    236 pv_addr_t minidataclean;
    237 
    238 vm_offset_t msgbufphys;
    239 
    240 extern u_int data_abort_handler_address;
    241 extern u_int prefetch_abort_handler_address;
    242 extern u_int undefined_handler_address;
    243 
    244 #ifdef PMAP_DEBUG
    245 extern int pmap_debug_level;
    246 #endif
    247 
    248 #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    249 #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    250 #define	KERNEL_PT_KERNEL_NUM	((KERNEL_VM_BASE - KERNEL_BASE) >> 22)
    251 #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
    252 				        /* Page tables for mapping kernel VM */
    253 #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    254 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    255 
    256 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    257 
    258 /* Prototypes */
    259 static void	read_system_serial(void);
    260 static void	process_kernel_args(int, char *[]);
    261 static void	process_kernel_args_liner(char *);
    262 #ifdef KGDB
    263 static void	kgdb_port_init(void);
    264 #endif
    265 
    266 bs_protos(bs_notimpl);
    267 
    268 #include "com.h"
    269 #if NCOM > 0
    270 #include <dev/ic/comreg.h>
    271 #include <dev/ic/comvar.h>
    272 #endif
    273 
    274 #include "lcd.h"
    275 
    276 #ifndef CONSPEED
    277 #define CONSPEED B115200	/* It's a setting of the default of u-boot */
    278 #endif
    279 #ifndef CONMODE
    280 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    281 #endif
    282 
    283 int comcnspeed = CONSPEED;
    284 int comcnmode = CONMODE;
    285 
    286 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    287 static char console[16];
    288 #endif
    289 
    290 extern void gxio_config_pin(void);
    291 extern void gxio_config_expansion(char *);
    292 
    293 /*
    294  * void cpu_reboot(int howto, char *bootstr)
    295  *
    296  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    297  * then reset the CPU.
    298  */
    299 void
    300 cpu_reboot(int howto, char *bootstr)
    301 {
    302 
    303 #ifdef DIAGNOSTIC
    304 	/* info */
    305 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    306 #endif
    307 
    308 	/*
    309 	 * If we are still cold then hit the air brakes
    310 	 * and crash to earth fast
    311 	 */
    312 	if (cold) {
    313 		doshutdownhooks();
    314 		pmf_system_shutdown(boothowto);
    315 		printf("The operating system has halted.\n");
    316 		printf("Please press any key to reboot.\n\n");
    317 		cngetc();
    318 		printf("rebooting...\n");
    319 		cpu_reset();
    320 		/*NOTREACHED*/
    321 	}
    322 
    323 	/*
    324 	 * If RB_NOSYNC was not specified sync the discs.
    325 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    326 	 * unmount.  It looks like syslogd is getting woken up only to find
    327 	 * that it cannot page part of the binary in as the filesystem has
    328 	 * been unmounted.
    329 	 */
    330 	if (!(howto & RB_NOSYNC))
    331 		bootsync();
    332 
    333 	/* Say NO to interrupts */
    334 	splhigh();
    335 
    336 	/* Do a dump if requested. */
    337 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    338 		dumpsys();
    339 
    340 	/* Run any shutdown hooks */
    341 	doshutdownhooks();
    342 
    343 	pmf_system_shutdown(boothowto);
    344 
    345 	/* Make sure IRQ's are disabled */
    346 	IRQdisable;
    347 
    348 	if (howto & RB_HALT) {
    349 		printf("The operating system has halted.\n");
    350 		printf("Please press any key to reboot.\n\n");
    351 		cngetc();
    352 	}
    353 
    354 	printf("rebooting...\n");
    355 	cpu_reset();
    356 	/*NOTREACHED*/
    357 }
    358 
    359 static inline pd_entry_t *
    360 read_ttb(void)
    361 {
    362   long ttb;
    363 
    364   __asm volatile("mrc	p15, 0, %0, c2, c0, 0" : "=r" (ttb));
    365 
    366 
    367   return (pd_entry_t *)(ttb & ~((1<<14)-1));
    368 }
    369 
    370 /*
    371  * Static device mappings. These peripheral registers are mapped at
    372  * fixed virtual addresses very early in initarm() so that we can use
    373  * them while booting the kernel, and stay at the same address
    374  * throughout whole kernel's life time.
    375  *
    376  * We use this table twice; once with bootstrap page table, and once
    377  * with kernel's page table which we build up in initarm().
    378  *
    379  * Since we map these registers into the bootstrap page table using
    380  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    381  * registers segment-aligned and segment-rounded in order to avoid
    382  * using the 2nd page tables.
    383  */
    384 
    385 #define	_A(a)	((a) & ~L1_S_OFFSET)
    386 #define	_S(s)	(((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    387 
    388 static const struct pmap_devmap gumstix_devmap[] = {
    389 	{
    390 		GUMSTIX_GPIO_VBASE,
    391 		_A(PXA2X0_GPIO_BASE),
    392 		_S(PXA250_GPIO_SIZE),
    393 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    394 	},
    395 	{
    396 		GUMSTIX_CLKMAN_VBASE,
    397 		_A(PXA2X0_CLKMAN_BASE),
    398 		_S(PXA2X0_CLKMAN_SIZE),
    399 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    400 	},
    401 	{
    402 		GUMSTIX_INTCTL_VBASE,
    403 		_A(PXA2X0_INTCTL_BASE),
    404 		_S(PXA2X0_INTCTL_SIZE),
    405 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    406 	},
    407 	{
    408 		GUMSTIX_FFUART_VBASE,
    409 		_A(PXA2X0_FFUART_BASE),
    410 		_S(4 * COM_NPORTS),
    411 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    412 	},
    413 	{
    414 		GUMSTIX_STUART_VBASE,
    415 		_A(PXA2X0_STUART_BASE),
    416 		_S(4 * COM_NPORTS),
    417 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    418 	},
    419 	{
    420 		GUMSTIX_BTUART_VBASE,
    421 		_A(PXA2X0_BTUART_BASE),
    422 		_S(4 * COM_NPORTS),
    423 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    424 	},
    425 	{
    426 		GUMSTIX_HWUART_VBASE,
    427 		_A(PXA2X0_HWUART_BASE),
    428 		_S(4 * COM_NPORTS),
    429 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    430 	},
    431 	{
    432 		GUMSTIX_LCDC_VBASE,
    433 		_A(PXA2X0_LCDC_BASE),
    434 		_S(4 * COM_NPORTS),
    435 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    436 	},
    437 	{0, 0, 0, 0, 0}
    438 };
    439 
    440 #undef	_A
    441 #undef	_S
    442 
    443 
    444 /*
    445  * u_int initarm(...)
    446  *
    447  * Initial entry point on startup. This gets called before main() is
    448  * entered.
    449  * It should be responsible for setting up everything that must be
    450  * in place when main is called.
    451  * This includes
    452  *   Taking a copy of the boot configuration structure.
    453  *   Initialising the physical console so characters can be printed.
    454  *   Setting up page tables for the kernel
    455  *   Relocating the kernel to the bottom of physical memory
    456  */
    457 u_int
    458 initarm(void *arg)
    459 {
    460 	extern vaddr_t xscale_cache_clean_addr;
    461 	extern uint32_t *u_boot_args[];
    462 	extern uint32_t ram_size;
    463 	enum { r0 = 0, r1 = 1, r2 = 2, r3 = 3 }; /* args from u-boot */
    464 	int loop;
    465 	int loop1;
    466 	u_int l1pagetable;
    467 	paddr_t memstart;
    468 	psize_t memsize;
    469 #ifdef DIAGNOSTIC
    470 	extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
    471 #endif
    472 
    473 	/* map some peripheral registers at static I/O area */
    474 	pmap_devmap_bootstrap((vaddr_t)read_ttb(), gumstix_devmap);
    475 
    476 	/* start 32.768kHz OSC */
    477 	ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_OSCC, OSCC_OON);
    478 
    479 	/* Get ready for splfoo() */
    480 	pxa2x0_intr_bootstrap(GUMSTIX_INTCTL_VBASE);
    481 
    482 	/*
    483 	 * Heads up ... Setup the CPU / MMU / TLB functions
    484 	 */
    485 	if (set_cpufuncs())
    486 		panic("cpu not recognized!");
    487 
    488 	/*
    489 	 * U-Boot doesn't use the virtual memory.
    490 	 *
    491 	 * Physical Address Range     Description
    492 	 * -----------------------    ----------------------------------
    493 	 * 0x00000000 - 0x00ffffff    flash Memory   (16MB or 4MB)
    494 	 * 0x40000000 - 0x480fffff    Processor Registers
    495 	 * 0xa0000000 - 0xa3ffffff    SDRAM Bank 0 (64MB)
    496 	 */
    497 
    498 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    499 
    500 	/* setup GPIO for {FF,ST,HW}UART. */
    501 	pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
    502 
    503 	/* configure GPIOs. */
    504 	gxio_config_pin();
    505 
    506 	pxa2x0_clkman_bootstrap(GUMSTIX_CLKMAN_VBASE);
    507 
    508 #ifndef GUMSTIX_NETBSD_ARGS_CONSOLE
    509 	consinit();
    510 #endif
    511 #ifdef KGDB
    512 	kgdb_port_init();
    513 #endif
    514 
    515         /*
    516 	 * Examine the boot args string for options we need to know about
    517 	 * now.
    518 	 */
    519 #define SDRAM_START	0xa0000000UL
    520 	if (((uint32_t)u_boot_args[r0] & 0xf0000000) != SDRAM_START)
    521 		/* Maybe r0 is 'argc'.  We are booted by command 'go'. */
    522 		process_kernel_args((int)u_boot_args[r0],
    523 		    (char **)u_boot_args[r1]);
    524 	else
    525 		/*
    526 		 * Maybe r3 is 'boot args string' of 'bootm'.  This string is
    527 		 * linely.
    528 		 */
    529 		process_kernel_args_liner((char *)u_boot_args[r3]);
    530 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    531 	consinit();
    532 #endif
    533 
    534 	/* Talk to the user */
    535 	printf("\nNetBSD/evbarm (gumstix) booting ...\n");
    536 
    537 	/* Read system serial */
    538 	read_system_serial();
    539 
    540 	memstart = SDRAM_START;
    541 	memsize = ram_size;
    542 
    543 #ifdef VERBOSE_INIT_ARM
    544 	printf("initarm: Configuring system ...\n");
    545 #endif
    546 
    547 	/* Fake bootconfig structure for the benefit of pmap.c */
    548 	/* XXX must make the memory description h/w independent */
    549 	bootconfig.dramblocks = 1;
    550 	bootconfig.dram[0].address = memstart;
    551 	bootconfig.dram[0].pages = memsize / PAGE_SIZE;
    552 
    553 	/*
    554 	 * Set up the variables that define the availablilty of
    555 	 * physical memory.  For now, we're going to set
    556 	 * physical_freestart to 0xa0200000 (where the kernel
    557 	 * was loaded), and allocate the memory we need downwards.
    558 	 * If we get too close to the L1 table that we set up, we
    559 	 * will panic.  We will update physical_freestart and
    560 	 * physical_freeend later to reflect what pmap_bootstrap()
    561 	 * wants to see.
    562 	 *
    563 	 * XXX pmap_bootstrap() needs an enema.
    564 	 */
    565 	physical_start = bootconfig.dram[0].address;
    566 	physical_end = physical_start + memsize;
    567 
    568 	physical_freestart = 0xa0009000UL;
    569 	physical_freeend = 0xa0200000UL;
    570 
    571 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    572 
    573 #ifdef VERBOSE_INIT_ARM
    574 	/* Tell the user about the memory */
    575 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    576 	    physical_start, physical_end - 1);
    577 #endif
    578 
    579 	/*
    580 	 * Okay, the kernel starts 2MB in from the bottom of physical
    581 	 * memory.  We are going to allocate our bootstrap pages downwards
    582 	 * from there.
    583 	 *
    584 	 * We need to allocate some fixed page tables to get the kernel
    585 	 * going.  We allocate one page directory and a number of page
    586 	 * tables and store the physical addresses in the kernel_pt_table
    587 	 * array.
    588 	 *
    589 	 * The kernel page directory must be on a 16K boundary.  The page
    590 	 * tables must be on 4K bounaries.  What we do is allocate the
    591 	 * page directory on the first 16K boundary that we encounter, and
    592 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    593 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    594 	 * least one 16K aligned region.
    595 	 */
    596 
    597 #ifdef VERBOSE_INIT_ARM
    598 	printf("Allocating page tables\n");
    599 #endif
    600 
    601 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    602 
    603 #ifdef VERBOSE_INIT_ARM
    604 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    605 	       physical_freestart, free_pages, free_pages);
    606 #endif
    607 
    608 	/* Define a macro to simplify memory allocation */
    609 #define	valloc_pages(var, np)				\
    610 	alloc_pages((var).pv_pa, (np));			\
    611 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    612 
    613 #define alloc_pages(var, np)				\
    614 	physical_freeend -= ((np) * PAGE_SIZE);		\
    615 	if (physical_freeend < physical_freestart)	\
    616 		panic("initarm: out of memory");	\
    617 	(var) = physical_freeend;			\
    618 	free_pages -= (np);				\
    619 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    620 
    621 	loop1 = 0;
    622 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    623 		/* Are we 16KB aligned for an L1 ? */
    624 		if ((physical_freeend & (L1_TABLE_SIZE - 1)) == 0 &&
    625 		    kernel_l1pt.pv_pa == 0) {
    626 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    627 		} else {
    628 			valloc_pages(kernel_pt_table[loop1],
    629 			    L2_TABLE_SIZE / PAGE_SIZE);
    630 			++loop1;
    631 		}
    632 	}
    633 
    634 	/* This should never be able to happen but better confirm that. */
    635 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    636 		panic("initarm: Failed to align the kernel page directory");
    637 
    638 	/*
    639 	 * Allocate a page for the system page mapped to V0x00000000
    640 	 * This page will just contain the system vectors and can be
    641 	 * shared by all processes.
    642 	 */
    643 	alloc_pages(systempage.pv_pa, 1);
    644 
    645 	/* Allocate stacks for all modes */
    646 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    647 	valloc_pages(abtstack, ABT_STACK_SIZE);
    648 	valloc_pages(undstack, UND_STACK_SIZE);
    649 	valloc_pages(kernelstack, UPAGES);
    650 
    651 	/* Allocate enough pages for cleaning the Mini-Data cache. */
    652 	KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
    653 	valloc_pages(minidataclean, 1);
    654 
    655 #ifdef VERBOSE_INIT_ARM
    656 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    657 	    irqstack.pv_va);
    658 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    659 	    abtstack.pv_va);
    660 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    661 	    undstack.pv_va);
    662 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    663 	    kernelstack.pv_va);
    664 #endif
    665 
    666 	/*
    667 	 * XXX Defer this to later so that we can reclaim the memory
    668 	 * XXX used by the RedBoot page tables.
    669 	 */
    670 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    671 
    672 	/*
    673 	 * Ok we have allocated physical pages for the primary kernel
    674 	 * page tables
    675 	 */
    676 
    677 #ifdef VERBOSE_INIT_ARM
    678 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    679 #endif
    680 
    681 	/*
    682 	 * Now we start construction of the L1 page table
    683 	 * We start by mapping the L2 page tables into the L1.
    684 	 * This means that we can replace L1 mappings later on if necessary
    685 	 */
    686 	l1pagetable = kernel_l1pt.pv_va;
    687 
    688 	/* Map the L2 pages tables in the L1 page table */
    689 	pmap_link_l2pt(l1pagetable, 0x00000000,
    690 	    &kernel_pt_table[KERNEL_PT_SYS]);
    691 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    692 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    693 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    694 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    695 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    696 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    697 
    698 	/* update the top of the kernel VM */
    699 	pmap_curmaxkvaddr =
    700 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    701 
    702 #ifdef VERBOSE_INIT_ARM
    703 	printf("Mapping kernel\n");
    704 #endif
    705 
    706 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    707 	{
    708 		extern char etext[], _end[];
    709 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    710 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    711 		u_int logical;
    712 
    713 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    714 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    715 
    716 		logical = 0x00200000;	/* offset of kernel in RAM */
    717 
    718 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    719 		    physical_start + logical, textsize,
    720 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    721 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    722 		    physical_start + logical, totalsize - textsize,
    723 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    724 	}
    725 
    726 #ifdef VERBOSE_INIT_ARM
    727 	printf("Constructing L2 page tables\n");
    728 #endif
    729 
    730 	/* Map the stack pages */
    731 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    732 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    733 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    734 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    735 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    736 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    737 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    738 	    UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    739 
    740 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    741 	    L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
    742 
    743 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    744 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    745 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    746 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    747 	}
    748 
    749 	/* Map the Mini-Data cache clean area. */
    750 	xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
    751 	    minidataclean.pv_pa);
    752 
    753 	/* Map the vector page. */
    754 #if 1
    755 	/* MULTI-ICE requires that page 0 is NC/NB so that it can download the
    756 	 * cache-clean code there.  */
    757 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    758 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    759 #else
    760 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    761 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    762 #endif
    763 
    764 	/*
    765 	 * map integrated peripherals at same address in l1pagetable
    766 	 * so that we can continue to use console.
    767 	 */
    768 	pmap_devmap_bootstrap(l1pagetable, gumstix_devmap);
    769 
    770 	/*
    771 	 * Give the XScale global cache clean code an appropriately
    772 	 * sized chunk of unmapped VA space starting at 0xff000000
    773 	 * (our device mappings end before this address).
    774 	 */
    775 	xscale_cache_clean_addr = 0xff000000U;
    776 
    777 	/*
    778 	 * Now we have the real page tables in place so we can switch to them.
    779 	 * Once this is done we will be running with the REAL kernel page
    780 	 * tables.
    781 	 */
    782 
    783 	/*
    784 	 * Update the physical_freestart/physical_freeend/free_pages
    785 	 * variables.
    786 	 */
    787 	{
    788 		extern char _end[];
    789 
    790 		physical_freestart = physical_start +
    791 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    792 		     KERNEL_BASE);
    793 		physical_freeend = physical_end;
    794 		free_pages =
    795 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    796 	}
    797 
    798 	/* Switch tables */
    799 #ifdef VERBOSE_INIT_ARM
    800 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    801 	       physical_freestart, free_pages, free_pages);
    802 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    803 #endif
    804 
    805 	cpu_setttb(kernel_l1pt.pv_pa);
    806 	cpu_tlb_flushID();
    807 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    808 
    809 	/*
    810 	 * Moved from cpu_startup() as data_abort_handler() references
    811 	 * this during uvm init
    812 	 */
    813 	uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
    814 
    815 #ifdef VERBOSE_INIT_ARM
    816 	printf("bootstrap done.\n");
    817 #endif
    818 
    819 	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
    820 
    821 	/*
    822 	 * Pages were allocated during the secondary bootstrap for the
    823 	 * stacks for different CPU modes.
    824 	 * We must now set the r13 registers in the different CPU modes to
    825 	 * point to these stacks.
    826 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    827 	 * of the stack memory.
    828 	 */
    829 #ifdef	VERBOSE_INIT_ARM
    830 	printf("init subsystems: stacks ");
    831 #endif
    832 
    833 	set_stackptr(PSR_IRQ32_MODE,
    834 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    835 	set_stackptr(PSR_ABT32_MODE,
    836 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    837 	set_stackptr(PSR_UND32_MODE,
    838 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    839 
    840 	/*
    841 	 * Well we should set a data abort handler.
    842 	 * Once things get going this will change as we will need a proper
    843 	 * handler.
    844 	 * Until then we will use a handler that just panics but tells us
    845 	 * why.
    846 	 * Initialisation of the vectors will just panic on a data abort.
    847 	 * This just fills in a slighly better one.
    848 	 */
    849 #ifdef	VERBOSE_INIT_ARM
    850 	printf("vectors ");
    851 #endif
    852 	data_abort_handler_address = (u_int)data_abort_handler;
    853 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    854 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    855 
    856 	/* Initialise the undefined instruction handlers */
    857 #ifdef	VERBOSE_INIT_ARM
    858 	printf("undefined ");
    859 #endif
    860 	undefined_init();
    861 
    862 	/* Load memory into UVM. */
    863 #ifdef	VERBOSE_INIT_ARM
    864 	printf("page ");
    865 #endif
    866 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    867 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    868 	    atop(physical_freestart), atop(physical_freeend),
    869 	    VM_FREELIST_DEFAULT);
    870 
    871 	/* Boot strap pmap telling it where the kernel page table is */
    872 #ifdef	VERBOSE_INIT_ARM
    873 	printf("pmap ");
    874 #endif
    875 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    876 
    877 #ifdef __HAVE_MEMORY_DISK__
    878 	md_root_setconf(memory_disk, sizeof memory_disk);
    879 #endif
    880 
    881 #ifdef BOOTHOWTO
    882 	boothowto |= BOOTHOWTO;
    883 #endif
    884 
    885 #ifdef KGDB
    886 	if (boothowto & RB_KDB) {
    887 		kgdb_debug_init = 1;
    888 		kgdb_connect(1);
    889 	}
    890 #endif
    891 
    892 #if NKSYMS || defined(DDB) || defined(MODULAR)
    893 	/* Firmware doesn't load symbols. */
    894 	ddb_init(0, NULL, NULL);
    895 #endif
    896 
    897 #ifdef DDB
    898 	db_machine_init();
    899 	if (boothowto & RB_KDB)
    900 		Debugger();
    901 #endif
    902 
    903 	/* We return the new stack pointer address */
    904 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    905 }
    906 
    907 static void
    908 read_system_serial(void)
    909 {
    910 #define GUMSTIX_SYSTEM_SERIAL_ADDR	0
    911 #define GUMSTIX_SYSTEM_SERIAL_SIZE	8
    912 #define FLASH_OFFSET_INTEL_PROTECTION	0x81
    913 #define FLASH_OFFSET_USER_PROTECTION	0x85
    914 #define FLASH_CMD_READ_ID		0x90
    915 #define FLASH_CMD_RESET			0xff
    916 	int i;
    917 	char system_serial[GUMSTIX_SYSTEM_SERIAL_SIZE], *src;
    918 	char x;
    919 
    920 	src = (char *)(FLASH_OFFSET_USER_PROTECTION * 2 /*word*/);
    921 	*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
    922 	memcpy(system_serial,
    923 	    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
    924 	*(volatile uint16_t *)0 = FLASH_CMD_RESET;
    925 
    926 	for (i = 1, x = system_serial[0]; i < sizeof (system_serial); i++)
    927 		x &= system_serial[i];
    928 	if (x == 0xff) {
    929 		src = (char *)(FLASH_OFFSET_INTEL_PROTECTION * 2 /*word*/);
    930 		*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
    931 		memcpy(system_serial,
    932 		    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
    933 		*(volatile uint16_t *)0 = FLASH_CMD_RESET;
    934 
    935 		/*
    936 		 * XXXX: Don't need ???
    937 		 * gumstix_serial_hash(system_serial);
    938 		 */
    939 	}
    940 	system_serial_high = system_serial[0] << 24 | system_serial[1] << 16 |
    941 	    system_serial[2] << 8 | system_serial[3];
    942 	system_serial_low = system_serial[4] << 24 | system_serial[5] << 16 |
    943 	    system_serial[6] << 8 | system_serial[7];
    944 
    945 	printf("system serial: 0x");
    946 	for (i = 0; i < sizeof (system_serial); i++)
    947 		printf("%02x", system_serial[i]);
    948 	printf("\n");
    949 }
    950 
    951 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
    952 static const char busheader_name[] = "busheader=";
    953 #endif
    954 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    955 static const char console_name[] = "console=";
    956 #endif
    957 static void
    958 process_kernel_args(int argc, char *argv[])
    959 {
    960 	int gxio_configured = 0, i, j;
    961 
    962 	boothowto = 0;
    963 
    964 	for (i = 1, j = 0; i < argc; i++) {
    965 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
    966 		if (!strncmp(argv[i], busheader_name, strlen(busheader_name))) {
    967 			/* configure for GPIOs of busheader side */
    968 			gxio_config_expansion(argv[i] + strlen(busheader_name));
    969 			gxio_configured = 1;
    970 			continue;
    971 		}
    972 #endif
    973 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    974 		if (!strncmp(argv[i], console_name, strlen(console_name))) {
    975 			strncpy(console, argv[i] + strlen(console_name),
    976 			    sizeof(console));
    977 			consinit();
    978 		}
    979 #endif
    980 		if (j == MAX_BOOT_STRING) {
    981 			*(bootargs + j) = '\0';
    982 			continue;
    983 		}
    984 		if (j != 0)
    985 			*(bootargs + j++) = ' ';
    986 		strncpy(bootargs + j, argv[i], MAX_BOOT_STRING - j);
    987 		j += strlen(argv[i]);
    988 	}
    989 	boot_args = bootargs;
    990 
    991 	parse_mi_bootargs(boot_args);
    992 
    993 	if (!gxio_configured)
    994 		gxio_config_expansion(NULL);
    995 }
    996 
    997 static void
    998 process_kernel_args_liner(char *args)
    999 {
   1000 	int i;
   1001 	char *p = NULL;
   1002 
   1003 	boothowto = 0;
   1004 
   1005 	strncpy(bootargs, args, sizeof(bootargs));
   1006 #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
   1007 	p = strstr(bootargs, busheader_name);
   1008 	if (p) {
   1009 		char expansion[256], c;
   1010 
   1011 		i = 0;
   1012 		do {
   1013 			c = *(p + strlen(busheader_name) + i);
   1014 			if (c == ' ')
   1015 				c = '\0';
   1016 			expansion[i++] = c;
   1017 		} while (c != '\0' && i < sizeof(expansion));
   1018 		gxio_config_expansion(expansion);
   1019 		strcpy(p, p + i);
   1020 	}
   1021 #endif
   1022 	if (p == NULL) {
   1023 		gxio_config_expansion(NULL);
   1024 	}
   1025 #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
   1026 	p = strstr(bootargs, console_name);
   1027 	if (p != NULL) {
   1028 		char c;
   1029 
   1030 		i = 0;
   1031 		do {
   1032 			c = *(p + strlen(console_name) + i);
   1033 			if (c == ' ')
   1034 				c = '\0';
   1035 			console[i++] = c;
   1036 		} while (c != '\0' && i < sizeof(console));
   1037 		consinit();
   1038 		strcpy(p, p + i);
   1039 	}
   1040 #endif
   1041 	boot_args = bootargs;
   1042 
   1043 	parse_mi_bootargs(boot_args);
   1044 }
   1045 
   1046 #ifdef KGDB
   1047 #ifndef KGDB_DEVNAME
   1048 #define KGDB_DEVNAME	"ffuart"
   1049 #endif
   1050 const char kgdb_devname[] = KGDB_DEVNAME;
   1051 
   1052 #ifndef KGDB_DEVRATE
   1053 #define KGDB_DEVRATE	CONSPEED
   1054 #endif
   1055 int kgdb_devrate = KGDB_DEVRATE;
   1056 
   1057 #if (NCOM > 0)
   1058 #ifndef KGDB_DEVMODE
   1059 #define KGDB_DEVMODE	CONMODE
   1060 #endif
   1061 int comkgdbmode = KGDB_DEVMODE;
   1062 #endif /* NCOM */
   1063 
   1064 #endif /* KGDB */
   1065 
   1066 
   1067 void
   1068 consinit(void)
   1069 {
   1070 	static int consinit_called = 0;
   1071 	int rv;
   1072 
   1073 	if (consinit_called != 0)
   1074 		return;
   1075 
   1076 	consinit_called = 1;
   1077 
   1078 #if NCOM > 0
   1079 
   1080 #ifdef FFUARTCONSOLE
   1081 #ifdef KGDB
   1082 	if (strcmp(kgdb_devname, "ffuart") == 0){
   1083 		/* port is reserved for kgdb */
   1084 	} else
   1085 #endif
   1086 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
   1087 	if (console[0] == '\0' || strcasecmp(console, "ffuart") == 0)
   1088 #endif
   1089 	{
   1090 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
   1091 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
   1092 		if (rv == 0) {
   1093 			pxa2x0_clkman_config(CKEN_FFUART, 1);
   1094 			return;
   1095 		}
   1096 	}
   1097 #endif /* FFUARTCONSOLE */
   1098 
   1099 #ifdef STUARTCONSOLE
   1100 #ifdef KGDB
   1101 	if (strcmp(kgdb_devname, "stuart") == 0) {
   1102 		/* port is reserved for kgdb */
   1103 	} else
   1104 #endif
   1105 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
   1106 	if (console[0] == '\0' || strcasecmp(console, "stuart") == 0)
   1107 #endif
   1108 	{
   1109 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE,
   1110 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
   1111 		if (rv == 0) {
   1112 			pxa2x0_clkman_config(CKEN_STUART, 1);
   1113 			return;
   1114 		}
   1115 	}
   1116 #endif /* STUARTCONSOLE */
   1117 
   1118 #ifdef BTUARTCONSOLE
   1119 #ifdef KGDB
   1120 	if (strcmp(kgdb_devname, "btuart") == 0) {
   1121 		/* port is reserved for kgdb */
   1122 	} else
   1123 #endif
   1124 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
   1125 	if (console[0] == '\0' || strcasecmp(console, "btuart") == 0)
   1126 #endif
   1127 	{
   1128 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
   1129 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
   1130 		if (rv == 0) {
   1131 			pxa2x0_clkman_config(CKEN_BTUART, 1);
   1132 			return;
   1133 		}
   1134 	}
   1135 #endif /* BTUARTCONSOLE */
   1136 
   1137 #ifdef HWUARTCONSOLE
   1138 #ifdef KGDB
   1139 	if (strcmp(kgdb_devname, "hwuart") == 0) {
   1140 		/* port is reserved for kgdb */
   1141 	} else
   1142 #endif
   1143 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
   1144 	if (console[0] == '\0' || strcasecmp(console, "hwuart") == 0)
   1145 #endif
   1146 	{
   1147 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE,
   1148 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
   1149 		if (rv == 0) {
   1150 			pxa2x0_clkman_config(CKEN_HWUART, 1);
   1151 			return;
   1152 		}
   1153 	}
   1154 #endif /* HWUARTCONSOLE */
   1155 
   1156 #endif /* NCOM */
   1157 
   1158 #if NLCD > 0
   1159 #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
   1160 	if (console[0] == '\0' || strcasecmp(console, "lcd") == 0)
   1161 #endif
   1162 	{
   1163 		gxlcd_cnattach();
   1164 	}
   1165 #endif
   1166 }
   1167 
   1168 #ifdef KGDB
   1169 static void
   1170 kgdb_port_init(void)
   1171 {
   1172 #if (NCOM > 0) && defined(COM_PXA2X0)
   1173 	paddr_t paddr = 0;
   1174 	int cken = 0;
   1175 
   1176 	if (0 == strcmp(kgdb_devname, "ffuart")) {
   1177 		paddr = PXA2X0_FFUART_BASE;
   1178 		cken = CKEN_FFUART;
   1179 	} else if (0 == strcmp(kgdb_devname, "stuart")) {
   1180 		paddr = PXA2X0_STUART_BASE;
   1181 		cken = CKEN_STUART;
   1182 	} else if (0 == strcmp(kgdb_devname, "btuart")) {
   1183 		paddr = PXA2X0_BTUART_BASE;
   1184 		cken = CKEN_BTUART;
   1185 	} else if (0 == strcmp(kgdb_devname, "hwuart")) {
   1186 		paddr = PXA2X0_HWUART_BASE;
   1187 		cken = CKEN_HWUART;
   1188 	}
   1189 
   1190 	if (paddr &&
   1191 	    0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
   1192 		kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
   1193 
   1194 		pxa2x0_clkman_config(cken, 1);
   1195 	}
   1196 
   1197 #endif
   1198 }
   1199 #endif
   1200