Home | History | Annotate | Line # | Download | only in gumstix
gumstix_machdep.c revision 1.15
      1 /*	$NetBSD: gumstix_machdep.c,v 1.15 2009/08/09 07:10:13 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 #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    189 
    190 /*
    191  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    192  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    193  */
    194 #define KERNEL_VM_SIZE		0x0C000000
    195 
    196 
    197 /*
    198  * Address to call from cpu_reset() to reset the machine.
    199  * This is machine architecture dependant as it varies depending
    200  * on where the ROM appears when you turn the MMU off.
    201  */
    202 
    203 u_int cpu_reset_address = 0;
    204 
    205 /* Define various stack sizes in pages */
    206 #define IRQ_STACK_SIZE	1
    207 #define ABT_STACK_SIZE	1
    208 #define UND_STACK_SIZE	1
    209 
    210 BootConfig bootconfig;		/* Boot config storage */
    211 static char bootargs[MAX_BOOT_STRING];
    212 char *boot_args = NULL;
    213 
    214 uint32_t system_serial_high;
    215 uint32_t system_serial_low;
    216 
    217 vm_offset_t physical_start;
    218 vm_offset_t physical_freestart;
    219 vm_offset_t physical_freeend;
    220 vm_offset_t physical_end;
    221 u_int free_pages;
    222 vm_offset_t pagetables_start;
    223 int physmem = 0;
    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	4
    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 struct user *proc0paddr;
    258 
    259 /* Prototypes */
    260 static void	read_system_serial(void);
    261 static void	process_kernel_args(int, char *[]);
    262 static void	process_kernel_args_line(char *);
    263 #ifdef KGDB
    264 static void	kgdb_port_init(void);
    265 #endif
    266 
    267 bs_protos(bs_notimpl);
    268 
    269 #include "com.h"
    270 #if NCOM > 0
    271 #include <dev/ic/comreg.h>
    272 #include <dev/ic/comvar.h>
    273 #endif
    274 
    275 #include "lcd.h"
    276 
    277 #ifndef CONSPEED
    278 #define CONSPEED B115200	/* It's a setting of the default of u-boot */
    279 #endif
    280 #ifndef CONMODE
    281 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    282 #endif
    283 
    284 int comcnspeed = CONSPEED;
    285 int comcnmode = CONMODE;
    286 
    287 extern void gxio_config_pin(void);
    288 extern void gxio_config_expansion(char *);
    289 
    290 /*
    291  * void cpu_reboot(int howto, char *bootstr)
    292  *
    293  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    294  * then reset the CPU.
    295  */
    296 void
    297 cpu_reboot(int howto, char *bootstr)
    298 {
    299 
    300 #ifdef DIAGNOSTIC
    301 	/* info */
    302 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    303 #endif
    304 
    305 	/*
    306 	 * If we are still cold then hit the air brakes
    307 	 * and crash to earth fast
    308 	 */
    309 	if (cold) {
    310 		doshutdownhooks();
    311 		pmf_system_shutdown(boothowto);
    312 		printf("The operating system has halted.\n");
    313 		printf("Please press any key to reboot.\n\n");
    314 		cngetc();
    315 		printf("rebooting...\n");
    316 		cpu_reset();
    317 		/*NOTREACHED*/
    318 	}
    319 
    320 	/*
    321 	 * If RB_NOSYNC was not specified sync the discs.
    322 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    323 	 * unmount.  It looks like syslogd is getting woken up only to find
    324 	 * that it cannot page part of the binary in as the filesystem has
    325 	 * been unmounted.
    326 	 */
    327 	if (!(howto & RB_NOSYNC))
    328 		bootsync();
    329 
    330 	/* Say NO to interrupts */
    331 	splhigh();
    332 
    333 	/* Do a dump if requested. */
    334 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    335 		dumpsys();
    336 
    337 	/* Run any shutdown hooks */
    338 	doshutdownhooks();
    339 
    340 	pmf_system_shutdown(boothowto);
    341 
    342 	/* Make sure IRQ's are disabled */
    343 	IRQdisable;
    344 
    345 	if (howto & RB_HALT) {
    346 		printf("The operating system has halted.\n");
    347 		printf("Please press any key to reboot.\n\n");
    348 		cngetc();
    349 	}
    350 
    351 	printf("rebooting...\n");
    352 	cpu_reset();
    353 	/*NOTREACHED*/
    354 }
    355 
    356 static inline
    357 pd_entry_t *
    358 read_ttb(void)
    359 {
    360   long ttb;
    361 
    362   __asm volatile("mrc	p15, 0, %0, c2, c0, 0" : "=r" (ttb));
    363 
    364 
    365   return (pd_entry_t *)(ttb & ~((1<<14)-1));
    366 }
    367 
    368 /*
    369  * Static device mappings. These peripheral registers are mapped at
    370  * fixed virtual addresses very early in initarm() so that we can use
    371  * them while booting the kernel, and stay at the same address
    372  * throughout whole kernel's life time.
    373  *
    374  * We use this table twice; once with bootstrap page table, and once
    375  * with kernel's page table which we build up in initarm().
    376  *
    377  * Since we map these registers into the bootstrap page table using
    378  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    379  * registers segment-aligned and segment-rounded in order to avoid
    380  * using the 2nd page tables.
    381  */
    382 
    383 #define	_A(a)	((a) & ~L1_S_OFFSET)
    384 #define	_S(s)	(((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    385 
    386 static const struct pmap_devmap gumstix_devmap[] = {
    387 	{
    388 		GUMSTIX_GPIO_VBASE,
    389 		_A(PXA2X0_GPIO_BASE),
    390 		_S(PXA250_GPIO_SIZE),
    391 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    392 	},
    393 	{
    394 		GUMSTIX_CLKMAN_VBASE,
    395 		_A(PXA2X0_CLKMAN_BASE),
    396 		_S(PXA2X0_CLKMAN_SIZE),
    397 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    398 	},
    399 	{
    400 		GUMSTIX_INTCTL_VBASE,
    401 		_A(PXA2X0_INTCTL_BASE),
    402 		_S(PXA2X0_INTCTL_SIZE),
    403 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    404 	},
    405 	{
    406 		GUMSTIX_FFUART_VBASE,
    407 		_A(PXA2X0_FFUART_BASE),
    408 		_S(4 * COM_NPORTS),
    409 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    410 	},
    411 	{
    412 		GUMSTIX_STUART_VBASE,
    413 		_A(PXA2X0_STUART_BASE),
    414 		_S(4 * COM_NPORTS),
    415 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    416 	},
    417 	{
    418 		GUMSTIX_BTUART_VBASE,
    419 		_A(PXA2X0_BTUART_BASE),
    420 		_S(4 * COM_NPORTS),
    421 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    422 	},
    423 	{
    424 		GUMSTIX_HWUART_VBASE,
    425 		_A(PXA2X0_HWUART_BASE),
    426 		_S(4 * COM_NPORTS),
    427 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    428 	},
    429 	{
    430 		GUMSTIX_LCDC_VBASE,
    431 		_A(PXA2X0_LCDC_BASE),
    432 		_S(4 * COM_NPORTS),
    433 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    434 	},
    435 	{0, 0, 0, 0, 0}
    436 };
    437 
    438 #undef	_A
    439 #undef	_S
    440 
    441 
    442 /*
    443  * u_int initarm(...)
    444  *
    445  * Initial entry point on startup. This gets called before main() is
    446  * entered.
    447  * It should be responsible for setting up everything that must be
    448  * in place when main is called.
    449  * This includes
    450  *   Taking a copy of the boot configuration structure.
    451  *   Initialising the physical console so characters can be printed.
    452  *   Setting up page tables for the kernel
    453  *   Relocating the kernel to the bottom of physical memory
    454  */
    455 u_int
    456 initarm(void *arg)
    457 {
    458 	extern vaddr_t xscale_cache_clean_addr;
    459 	extern uint32_t *u_boot_args[];
    460 	extern uint32_t ram_size;
    461 	enum { r0 = 0, r1 = 1, r2 = 2, r3 = 3 }; /* args from u-boot */
    462 	int loop;
    463 	int loop1;
    464 	u_int l1pagetable;
    465 	paddr_t memstart;
    466 	psize_t memsize;
    467 #ifdef DIAGNOSTIC
    468 	extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
    469 #endif
    470 
    471 	/* map some peripheral registers at static I/O area */
    472 	pmap_devmap_bootstrap((vaddr_t)read_ttb(), gumstix_devmap);
    473 
    474 	/* start 32.768kHz OSC */
    475 	ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_OSCC, OSCC_OON);
    476 
    477 	/* Get ready for splfoo() */
    478 	pxa2x0_intr_bootstrap(GUMSTIX_INTCTL_VBASE);
    479 
    480 	/*
    481 	 * Heads up ... Setup the CPU / MMU / TLB functions
    482 	 */
    483 	if (set_cpufuncs())
    484 		panic("cpu not recognized!");
    485 
    486 	/*
    487 	 * U-Boot doesn't use the virtual memory.
    488 	 *
    489 	 * Physical Address Range     Description
    490 	 * -----------------------    ----------------------------------
    491 	 * 0x00000000 - 0x00ffffff    flash Memory   (16MB or 4MB)
    492 	 * 0x40000000 - 0x480fffff    Processor Registers
    493 	 * 0xa0000000 - 0xa3ffffff    SDRAM Bank 0 (64MB)
    494 	 */
    495 
    496 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    497 
    498 	/* setup GPIO for {FF,ST,HW}UART. */
    499 	pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
    500 
    501 	/* configure GPIOs. */
    502 	gxio_config_pin();
    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 	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 	proc0paddr = (struct user *)kernelstack.pv_va;
    805 	lwp0.l_addr = proc0paddr;
    806 
    807 #ifdef VERBOSE_INIT_ARM
    808 	printf("bootstrap done.\n");
    809 #endif
    810 
    811 	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
    812 
    813 	/*
    814 	 * Pages were allocated during the secondary bootstrap for the
    815 	 * stacks for different CPU modes.
    816 	 * We must now set the r13 registers in the different CPU modes to
    817 	 * point to these stacks.
    818 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    819 	 * of the stack memory.
    820 	 */
    821 #ifdef	VERBOSE_INIT_ARM
    822 	printf("init subsystems: stacks ");
    823 #endif
    824 
    825 	set_stackptr(PSR_IRQ32_MODE,
    826 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    827 	set_stackptr(PSR_ABT32_MODE,
    828 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    829 	set_stackptr(PSR_UND32_MODE,
    830 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    831 
    832 	/*
    833 	 * Well we should set a data abort handler.
    834 	 * Once things get going this will change as we will need a proper
    835 	 * handler.
    836 	 * Until then we will use a handler that just panics but tells us
    837 	 * why.
    838 	 * Initialisation of the vectors will just panic on a data abort.
    839 	 * This just fills in a slighly better one.
    840 	 */
    841 #ifdef	VERBOSE_INIT_ARM
    842 	printf("vectors ");
    843 #endif
    844 	data_abort_handler_address = (u_int)data_abort_handler;
    845 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    846 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    847 
    848 	/* Initialise the undefined instruction handlers */
    849 #ifdef	VERBOSE_INIT_ARM
    850 	printf("undefined ");
    851 #endif
    852 	undefined_init();
    853 
    854 	/* Load memory into UVM. */
    855 #ifdef	VERBOSE_INIT_ARM
    856 	printf("page ");
    857 #endif
    858 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    859 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    860 	    atop(physical_freestart), atop(physical_freeend),
    861 	    VM_FREELIST_DEFAULT);
    862 
    863 	/* Boot strap pmap telling it where the kernel page table is */
    864 #ifdef	VERBOSE_INIT_ARM
    865 	printf("pmap ");
    866 #endif
    867 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    868 
    869 #ifdef __HAVE_MEMORY_DISK__
    870 	md_root_setconf(memory_disk, sizeof memory_disk);
    871 #endif
    872 
    873 #ifdef BOOTHOWTO
    874 	boothowto |= BOOTHOWTO;
    875 #endif
    876 
    877 #ifdef KGDB
    878 	if (boothowto & RB_KDB) {
    879 		kgdb_debug_init = 1;
    880 		kgdb_connect(1);
    881 	}
    882 #endif
    883 
    884 #if NKSYMS || defined(DDB) || defined(MODULAR)
    885 	/* Firmware doesn't load symbols. */
    886 	ddb_init(0, NULL, NULL);
    887 #endif
    888 
    889 #ifdef DDB
    890 	db_machine_init();
    891 	if (boothowto & RB_KDB)
    892 		Debugger();
    893 #endif
    894 
    895 	/* We return the new stack pointer address */
    896 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    897 }
    898 
    899 static void
    900 read_system_serial(void)
    901 {
    902 #define GUMSTIX_SYSTEM_SERIAL_ADDR	0
    903 #define GUMSTIX_SYSTEM_SERIAL_SIZE	8
    904 #define FLASH_OFFSET_INTEL_PROTECTION	0x81
    905 #define FLASH_OFFSET_USER_PROTECTION	0x85
    906 #define FLASH_CMD_READ_ID		0x90
    907 #define FLASH_CMD_RESET			0xff
    908 	int i;
    909 	char system_serial[GUMSTIX_SYSTEM_SERIAL_SIZE], *src;
    910 	char x;
    911 
    912 	src = (char *)(FLASH_OFFSET_USER_PROTECTION * 2 /*word*/);
    913 	*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
    914 	memcpy(system_serial,
    915 	    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
    916 	*(volatile uint16_t *)0 = FLASH_CMD_RESET;
    917 
    918 	for (i = 1, x = system_serial[0]; i < sizeof (system_serial); i++)
    919 		x &= system_serial[i];
    920 	if (x == 0xff) {
    921 		src = (char *)(FLASH_OFFSET_INTEL_PROTECTION * 2 /*word*/);
    922 		*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
    923 		memcpy(system_serial,
    924 		    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
    925 		*(volatile uint16_t *)0 = FLASH_CMD_RESET;
    926 
    927 		/*
    928 		 * XXXX: Don't need ???
    929 		 * gumstix_serial_hash(system_serial);
    930 		 */
    931 	}
    932 	system_serial_high = system_serial[0] << 24 | system_serial[1] << 16 |
    933 	    system_serial[2] << 8 | system_serial[3];
    934 	system_serial_low = system_serial[4] << 24 | system_serial[5] << 16 |
    935 	    system_serial[6] << 8 | system_serial[7];
    936 
    937 	printf("system serial: 0x");
    938 	for (i = 0; i < sizeof (system_serial); i++)
    939 		printf("%02x", system_serial[i]);
    940 	printf("\n");
    941 }
    942 
    943 static const char busheader_name[] = "busheader=";
    944 static void
    945 process_kernel_args(int argc, char *argv[])
    946 {
    947 	int gxio_configured = 0, i, j;
    948 
    949 	boothowto = 0;
    950 
    951 	for (i = 1, j = 0; i < argc; i++) {
    952 		if (!strncmp(argv[i], busheader_name, strlen(busheader_name))) {
    953 			/* configure for GPIOs of busheader side */
    954 			gxio_config_expansion(argv[i] + strlen(busheader_name));
    955 			gxio_configured = 1;
    956 			continue;
    957 		}
    958 		if (j == MAX_BOOT_STRING) {
    959 			*(bootargs + j) = '\0';
    960 			continue;
    961 		}
    962 		if (j != 0)
    963 			*(bootargs + j++) = ' ';
    964 		strncpy(bootargs + j, argv[i], MAX_BOOT_STRING - j);
    965 		j += strlen(argv[i]);
    966 	}
    967 	boot_args = bootargs;
    968 
    969 	parse_mi_bootargs(boot_args);
    970 
    971 	if (!gxio_configured)
    972 		gxio_config_expansion(NULL);
    973 }
    974 
    975 static void
    976 process_kernel_args_line(char *args)
    977 {
    978 	int i;
    979 	char expansion[256], *p, c;
    980 
    981 	boothowto = 0;
    982 
    983 	strncpy(bootargs, args, sizeof(bootargs));
    984 	p = strstr(bootargs, busheader_name);
    985 	if (p == NULL)
    986 		gxio_config_expansion(NULL);
    987 	else {
    988 		i = 0;
    989 		do {
    990 			c = *(p + strlen(busheader_name) + i);
    991 			if (c == ' ')
    992 				c = '\0';
    993 			expansion[i++] = c;
    994 		} while (c != '\0');
    995 		gxio_config_expansion(expansion);
    996 		strcpy(p, p + i);
    997 	}
    998 	boot_args = bootargs;
    999 
   1000 	parse_mi_bootargs(boot_args);
   1001 }
   1002 
   1003 #ifdef KGDB
   1004 #ifndef KGDB_DEVNAME
   1005 #define KGDB_DEVNAME	"ffuart"
   1006 #endif
   1007 const char kgdb_devname[] = KGDB_DEVNAME;
   1008 
   1009 #ifndef KGDB_DEVRATE
   1010 #define KGDB_DEVRATE	CONSPEED
   1011 #endif
   1012 int kgdb_devrate = KGDB_DEVRATE;
   1013 
   1014 #if (NCOM > 0)
   1015 #ifndef KGDB_DEVMODE
   1016 #define KGDB_DEVMODE	CONMODE
   1017 #endif
   1018 int comkgdbmode = KGDB_DEVMODE;
   1019 #endif /* NCOM */
   1020 
   1021 #endif /* KGDB */
   1022 
   1023 
   1024 void
   1025 consinit(void)
   1026 {
   1027 	static int consinit_called = 0;
   1028 	uint32_t ckenreg = ioreg_read(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN);
   1029 
   1030 	if (consinit_called != 0)
   1031 		return;
   1032 
   1033 	consinit_called = 1;
   1034 
   1035 #if NCOM > 0
   1036 
   1037 #ifdef FFUARTCONSOLE
   1038 #ifdef KGDB
   1039 	if (0 == strcmp(kgdb_devname, "ffuart")){
   1040 		/* port is reserved for kgdb */
   1041 	} else
   1042 #endif
   1043 	{
   1044 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
   1045 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1046 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1047 			    ckenreg|CKEN_FFUART);
   1048 
   1049 			return;
   1050 		}
   1051 	}
   1052 #endif /* FFUARTCONSOLE */
   1053 
   1054 #ifdef STUARTCONSOLE
   1055 #ifdef KGDB
   1056 	if (0 == strcmp(kgdb_devname, "stuart")) {
   1057 		/* port is reserved for kgdb */
   1058 	} else
   1059 #endif
   1060 	{
   1061 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE,
   1062 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1063 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1064 			    ckenreg|CKEN_STUART);
   1065 			return;
   1066 		}
   1067 	}
   1068 #endif /* STUARTCONSOLE */
   1069 
   1070 #ifdef BTUARTCONSOLE
   1071 #ifdef KGDB
   1072 	if (0 == strcmp(kgdb_devname, "btuart")) {
   1073 		/* port is reserved for kgdb */
   1074 	} else
   1075 #endif
   1076 	{
   1077 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
   1078 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1079 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1080 			    ckenreg|CKEN_BTUART);
   1081 			return;
   1082 		}
   1083 	}
   1084 #endif /* BTUARTCONSOLE */
   1085 
   1086 #ifdef HWUARTCONSOLE
   1087 #ifdef KGDB
   1088 	if (0 == strcmp(kgdb_devname, "hwuart")) {
   1089 		/* port is reserved for kgdb */
   1090 	} else
   1091 #endif
   1092 	{
   1093 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE,
   1094 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1095 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1096 			    ckenreg|CKEN_HWUART);
   1097 			return;
   1098 		}
   1099 	}
   1100 #endif /* HWUARTCONSOLE */
   1101 
   1102 #endif /* NCOM */
   1103 
   1104 #if NLCD > 0
   1105 	{
   1106 		extern void gxlcd_cnattach(void);
   1107 
   1108 		gxlcd_cnattach();
   1109 	}
   1110 #endif
   1111 }
   1112 
   1113 #ifdef KGDB
   1114 static void
   1115 kgdb_port_init(void)
   1116 {
   1117 #if (NCOM > 0) && defined(COM_PXA2X0)
   1118 	paddr_t paddr = 0;
   1119 	uint32_t ckenreg = ioreg_read(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN);
   1120 
   1121 	if (0 == strcmp(kgdb_devname, "ffuart")) {
   1122 		paddr = PXA2X0_FFUART_BASE;
   1123 		ckenreg |= CKEN_FFUART;
   1124 	} else if (0 == strcmp(kgdb_devname, "stuart")) {
   1125 		paddr = PXA2X0_STUART_BASE;
   1126 		ckenreg |= CKEN_STUART;
   1127 	} else if (0 == strcmp(kgdb_devname, "btuart")) {
   1128 		paddr = PXA2X0_BTUART_BASE;
   1129 		ckenreg |= CKEN_BTUART;
   1130 	} else if (0 == strcmp(kgdb_devname, "hwuart")) {
   1131 		paddr = PXA2X0_HWUART_BASE;
   1132 		ckenreg |= CKEN_HWUART;
   1133 	}
   1134 
   1135 	if (paddr &&
   1136 	    0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
   1137 		kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
   1138 
   1139 		ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN, ckenreg);
   1140 
   1141 	}
   1142 
   1143 #endif
   1144 }
   1145 #endif
   1146