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