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