Home | History | Annotate | Line # | Download | only in gumstix
gumstix_machdep.c revision 1.17
      1 /*	$NetBSD: gumstix_machdep.c,v 1.17 2009/11/21 08:41:38 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 
    224 /*int debug_flags;*/
    225 #ifndef PMAP_STATIC_L1S
    226 int max_processes = 64;			/* Default number */
    227 #endif	/* !PMAP_STATIC_L1S */
    228 
    229 /* Physical and virtual addresses for some global pages */
    230 pv_addr_t irqstack;
    231 pv_addr_t undstack;
    232 pv_addr_t abtstack;
    233 pv_addr_t kernelstack;
    234 pv_addr_t minidataclean;
    235 
    236 vm_offset_t msgbufphys;
    237 
    238 extern u_int data_abort_handler_address;
    239 extern u_int prefetch_abort_handler_address;
    240 extern u_int undefined_handler_address;
    241 
    242 #ifdef PMAP_DEBUG
    243 extern int pmap_debug_level;
    244 #endif
    245 
    246 #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    247 #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    248 #define	KERNEL_PT_KERNEL_NUM	4
    249 #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
    250 				        /* Page tables for mapping kernel VM */
    251 #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    252 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    253 
    254 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    255 
    256 struct user *proc0paddr;
    257 
    258 /* Prototypes */
    259 static void	read_system_serial(void);
    260 static void	process_kernel_args(int, char *[]);
    261 static void	process_kernel_args_line(char *);
    262 #ifdef KGDB
    263 static void	kgdb_port_init(void);
    264 #endif
    265 
    266 bs_protos(bs_notimpl);
    267 
    268 #include "com.h"
    269 #if NCOM > 0
    270 #include <dev/ic/comreg.h>
    271 #include <dev/ic/comvar.h>
    272 #endif
    273 
    274 #include "lcd.h"
    275 
    276 #ifndef CONSPEED
    277 #define CONSPEED B115200	/* It's a setting of the default of u-boot */
    278 #endif
    279 #ifndef CONMODE
    280 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    281 #endif
    282 
    283 int comcnspeed = CONSPEED;
    284 int comcnmode = CONMODE;
    285 
    286 extern void gxio_config_pin(void);
    287 extern void gxio_config_expansion(char *);
    288 
    289 /*
    290  * void cpu_reboot(int howto, char *bootstr)
    291  *
    292  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    293  * then reset the CPU.
    294  */
    295 void
    296 cpu_reboot(int howto, char *bootstr)
    297 {
    298 
    299 #ifdef DIAGNOSTIC
    300 	/* info */
    301 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    302 #endif
    303 
    304 	/*
    305 	 * If we are still cold then hit the air brakes
    306 	 * and crash to earth fast
    307 	 */
    308 	if (cold) {
    309 		doshutdownhooks();
    310 		pmf_system_shutdown(boothowto);
    311 		printf("The operating system has halted.\n");
    312 		printf("Please press any key to reboot.\n\n");
    313 		cngetc();
    314 		printf("rebooting...\n");
    315 		cpu_reset();
    316 		/*NOTREACHED*/
    317 	}
    318 
    319 	/*
    320 	 * If RB_NOSYNC was not specified sync the discs.
    321 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    322 	 * unmount.  It looks like syslogd is getting woken up only to find
    323 	 * that it cannot page part of the binary in as the filesystem has
    324 	 * been unmounted.
    325 	 */
    326 	if (!(howto & RB_NOSYNC))
    327 		bootsync();
    328 
    329 	/* Say NO to interrupts */
    330 	splhigh();
    331 
    332 	/* Do a dump if requested. */
    333 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    334 		dumpsys();
    335 
    336 	/* Run any shutdown hooks */
    337 	doshutdownhooks();
    338 
    339 	pmf_system_shutdown(boothowto);
    340 
    341 	/* Make sure IRQ's are disabled */
    342 	IRQdisable;
    343 
    344 	if (howto & RB_HALT) {
    345 		printf("The operating system has halted.\n");
    346 		printf("Please press any key to reboot.\n\n");
    347 		cngetc();
    348 	}
    349 
    350 	printf("rebooting...\n");
    351 	cpu_reset();
    352 	/*NOTREACHED*/
    353 }
    354 
    355 static inline
    356 pd_entry_t *
    357 read_ttb(void)
    358 {
    359   long ttb;
    360 
    361   __asm volatile("mrc	p15, 0, %0, c2, c0, 0" : "=r" (ttb));
    362 
    363 
    364   return (pd_entry_t *)(ttb & ~((1<<14)-1));
    365 }
    366 
    367 /*
    368  * Static device mappings. These peripheral registers are mapped at
    369  * fixed virtual addresses very early in initarm() so that we can use
    370  * them while booting the kernel, and stay at the same address
    371  * throughout whole kernel's life time.
    372  *
    373  * We use this table twice; once with bootstrap page table, and once
    374  * with kernel's page table which we build up in initarm().
    375  *
    376  * Since we map these registers into the bootstrap page table using
    377  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    378  * registers segment-aligned and segment-rounded in order to avoid
    379  * using the 2nd page tables.
    380  */
    381 
    382 #define	_A(a)	((a) & ~L1_S_OFFSET)
    383 #define	_S(s)	(((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    384 
    385 static const struct pmap_devmap gumstix_devmap[] = {
    386 	{
    387 		GUMSTIX_GPIO_VBASE,
    388 		_A(PXA2X0_GPIO_BASE),
    389 		_S(PXA250_GPIO_SIZE),
    390 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    391 	},
    392 	{
    393 		GUMSTIX_CLKMAN_VBASE,
    394 		_A(PXA2X0_CLKMAN_BASE),
    395 		_S(PXA2X0_CLKMAN_SIZE),
    396 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    397 	},
    398 	{
    399 		GUMSTIX_INTCTL_VBASE,
    400 		_A(PXA2X0_INTCTL_BASE),
    401 		_S(PXA2X0_INTCTL_SIZE),
    402 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    403 	},
    404 	{
    405 		GUMSTIX_FFUART_VBASE,
    406 		_A(PXA2X0_FFUART_BASE),
    407 		_S(4 * COM_NPORTS),
    408 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    409 	},
    410 	{
    411 		GUMSTIX_STUART_VBASE,
    412 		_A(PXA2X0_STUART_BASE),
    413 		_S(4 * COM_NPORTS),
    414 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    415 	},
    416 	{
    417 		GUMSTIX_BTUART_VBASE,
    418 		_A(PXA2X0_BTUART_BASE),
    419 		_S(4 * COM_NPORTS),
    420 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    421 	},
    422 	{
    423 		GUMSTIX_HWUART_VBASE,
    424 		_A(PXA2X0_HWUART_BASE),
    425 		_S(4 * COM_NPORTS),
    426 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    427 	},
    428 	{
    429 		GUMSTIX_LCDC_VBASE,
    430 		_A(PXA2X0_LCDC_BASE),
    431 		_S(4 * COM_NPORTS),
    432 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    433 	},
    434 	{0, 0, 0, 0, 0}
    435 };
    436 
    437 #undef	_A
    438 #undef	_S
    439 
    440 
    441 /*
    442  * u_int initarm(...)
    443  *
    444  * Initial entry point on startup. This gets called before main() is
    445  * entered.
    446  * It should be responsible for setting up everything that must be
    447  * in place when main is called.
    448  * This includes
    449  *   Taking a copy of the boot configuration structure.
    450  *   Initialising the physical console so characters can be printed.
    451  *   Setting up page tables for the kernel
    452  *   Relocating the kernel to the bottom of physical memory
    453  */
    454 u_int
    455 initarm(void *arg)
    456 {
    457 	extern vaddr_t xscale_cache_clean_addr;
    458 	extern uint32_t *u_boot_args[];
    459 	extern uint32_t ram_size;
    460 	enum { r0 = 0, r1 = 1, r2 = 2, r3 = 3 }; /* args from u-boot */
    461 	int loop;
    462 	int loop1;
    463 	u_int l1pagetable;
    464 	paddr_t memstart;
    465 	psize_t memsize;
    466 #ifdef DIAGNOSTIC
    467 	extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
    468 #endif
    469 
    470 	/* map some peripheral registers at static I/O area */
    471 	pmap_devmap_bootstrap((vaddr_t)read_ttb(), gumstix_devmap);
    472 
    473 	/* start 32.768kHz OSC */
    474 	ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_OSCC, OSCC_OON);
    475 
    476 	/* Get ready for splfoo() */
    477 	pxa2x0_intr_bootstrap(GUMSTIX_INTCTL_VBASE);
    478 
    479 	/*
    480 	 * Heads up ... Setup the CPU / MMU / TLB functions
    481 	 */
    482 	if (set_cpufuncs())
    483 		panic("cpu not recognized!");
    484 
    485 	/*
    486 	 * U-Boot doesn't use the virtual memory.
    487 	 *
    488 	 * Physical Address Range     Description
    489 	 * -----------------------    ----------------------------------
    490 	 * 0x00000000 - 0x00ffffff    flash Memory   (16MB or 4MB)
    491 	 * 0x40000000 - 0x480fffff    Processor Registers
    492 	 * 0xa0000000 - 0xa3ffffff    SDRAM Bank 0 (64MB)
    493 	 */
    494 
    495 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    496 
    497 	/* setup GPIO for {FF,ST,HW}UART. */
    498 	pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
    499 
    500 	/* configure GPIOs. */
    501 	gxio_config_pin();
    502 
    503 	consinit();
    504 #ifdef KGDB
    505 	kgdb_port_init();
    506 #endif
    507 
    508 	/* Talk to the user */
    509 	printf("\nNetBSD/evbarm (gumstix) booting ...\n");
    510 
    511 	/* Read system serial */
    512 	read_system_serial();
    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_line((char *)u_boot_args[r3]);
    529 
    530 	memstart = SDRAM_START;
    531 	memsize = ram_size;
    532 
    533 #ifdef VERBOSE_INIT_ARM
    534 	printf("initarm: Configuring system ...\n");
    535 #endif
    536 
    537 	/* Fake bootconfig structure for the benefit of pmap.c */
    538 	/* XXX must make the memory description h/w independent */
    539 	bootconfig.dramblocks = 1;
    540 	bootconfig.dram[0].address = memstart;
    541 	bootconfig.dram[0].pages = memsize / PAGE_SIZE;
    542 
    543 	/*
    544 	 * Set up the variables that define the availablilty of
    545 	 * physical memory.  For now, we're going to set
    546 	 * physical_freestart to 0xa0200000 (where the kernel
    547 	 * was loaded), and allocate the memory we need downwards.
    548 	 * If we get too close to the L1 table that we set up, we
    549 	 * will panic.  We will update physical_freestart and
    550 	 * physical_freeend later to reflect what pmap_bootstrap()
    551 	 * wants to see.
    552 	 *
    553 	 * XXX pmap_bootstrap() needs an enema.
    554 	 */
    555 	physical_start = bootconfig.dram[0].address;
    556 	physical_end = physical_start + memsize;
    557 
    558 	physical_freestart = 0xa0009000UL;
    559 	physical_freeend = 0xa0200000UL;
    560 
    561 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    562 
    563 #ifdef VERBOSE_INIT_ARM
    564 	/* Tell the user about the memory */
    565 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    566 	    physical_start, physical_end - 1);
    567 #endif
    568 
    569 	/*
    570 	 * Okay, the kernel starts 2MB in from the bottom of physical
    571 	 * memory.  We are going to allocate our bootstrap pages downwards
    572 	 * from there.
    573 	 *
    574 	 * We need to allocate some fixed page tables to get the kernel
    575 	 * going.  We allocate one page directory and a number of page
    576 	 * tables and store the physical addresses in the kernel_pt_table
    577 	 * array.
    578 	 *
    579 	 * The kernel page directory must be on a 16K boundary.  The page
    580 	 * tables must be on 4K bounaries.  What we do is allocate the
    581 	 * page directory on the first 16K boundary that we encounter, and
    582 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    583 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    584 	 * least one 16K aligned region.
    585 	 */
    586 
    587 #ifdef VERBOSE_INIT_ARM
    588 	printf("Allocating page tables\n");
    589 #endif
    590 
    591 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    592 
    593 #ifdef VERBOSE_INIT_ARM
    594 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    595 	       physical_freestart, free_pages, free_pages);
    596 #endif
    597 
    598 	/* Define a macro to simplify memory allocation */
    599 #define	valloc_pages(var, np)				\
    600 	alloc_pages((var).pv_pa, (np));			\
    601 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    602 
    603 #define alloc_pages(var, np)				\
    604 	physical_freeend -= ((np) * PAGE_SIZE);		\
    605 	if (physical_freeend < physical_freestart)	\
    606 		panic("initarm: out of memory");	\
    607 	(var) = physical_freeend;			\
    608 	free_pages -= (np);				\
    609 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    610 
    611 	loop1 = 0;
    612 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    613 		/* Are we 16KB aligned for an L1 ? */
    614 		if ((physical_freeend & (L1_TABLE_SIZE - 1)) == 0 &&
    615 		    kernel_l1pt.pv_pa == 0) {
    616 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    617 		} else {
    618 			valloc_pages(kernel_pt_table[loop1],
    619 			    L2_TABLE_SIZE / PAGE_SIZE);
    620 			++loop1;
    621 		}
    622 	}
    623 
    624 	/* This should never be able to happen but better confirm that. */
    625 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    626 		panic("initarm: Failed to align the kernel page directory");
    627 
    628 	/*
    629 	 * Allocate a page for the system page mapped to V0x00000000
    630 	 * This page will just contain the system vectors and can be
    631 	 * shared by all processes.
    632 	 */
    633 	alloc_pages(systempage.pv_pa, 1);
    634 
    635 	/* Allocate stacks for all modes */
    636 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    637 	valloc_pages(abtstack, ABT_STACK_SIZE);
    638 	valloc_pages(undstack, UND_STACK_SIZE);
    639 	valloc_pages(kernelstack, UPAGES);
    640 
    641 	/* Allocate enough pages for cleaning the Mini-Data cache. */
    642 	KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
    643 	valloc_pages(minidataclean, 1);
    644 
    645 #ifdef VERBOSE_INIT_ARM
    646 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    647 	    irqstack.pv_va);
    648 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    649 	    abtstack.pv_va);
    650 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    651 	    undstack.pv_va);
    652 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    653 	    kernelstack.pv_va);
    654 #endif
    655 
    656 	/*
    657 	 * XXX Defer this to later so that we can reclaim the memory
    658 	 * XXX used by the RedBoot page tables.
    659 	 */
    660 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    661 
    662 	/*
    663 	 * Ok we have allocated physical pages for the primary kernel
    664 	 * page tables
    665 	 */
    666 
    667 #ifdef VERBOSE_INIT_ARM
    668 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    669 #endif
    670 
    671 	/*
    672 	 * Now we start construction of the L1 page table
    673 	 * We start by mapping the L2 page tables into the L1.
    674 	 * This means that we can replace L1 mappings later on if necessary
    675 	 */
    676 	l1pagetable = kernel_l1pt.pv_va;
    677 
    678 	/* Map the L2 pages tables in the L1 page table */
    679 	pmap_link_l2pt(l1pagetable, 0x00000000,
    680 	    &kernel_pt_table[KERNEL_PT_SYS]);
    681 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    682 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    683 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    684 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    685 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    686 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    687 
    688 	/* update the top of the kernel VM */
    689 	pmap_curmaxkvaddr =
    690 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    691 
    692 #ifdef VERBOSE_INIT_ARM
    693 	printf("Mapping kernel\n");
    694 #endif
    695 
    696 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    697 	{
    698 		extern char etext[], _end[];
    699 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    700 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    701 		u_int logical;
    702 
    703 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    704 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    705 
    706 		logical = 0x00200000;	/* offset of kernel in RAM */
    707 
    708 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    709 		    physical_start + logical, textsize,
    710 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    711 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    712 		    physical_start + logical, totalsize - textsize,
    713 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    714 	}
    715 
    716 #ifdef VERBOSE_INIT_ARM
    717 	printf("Constructing L2 page tables\n");
    718 #endif
    719 
    720 	/* Map the stack pages */
    721 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    722 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    723 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    724 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    725 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    726 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    727 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    728 	    UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    729 
    730 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    731 	    L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
    732 
    733 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    734 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    735 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    736 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    737 	}
    738 
    739 	/* Map the Mini-Data cache clean area. */
    740 	xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
    741 	    minidataclean.pv_pa);
    742 
    743 	/* Map the vector page. */
    744 #if 1
    745 	/* MULTI-ICE requires that page 0 is NC/NB so that it can download the
    746 	 * cache-clean code there.  */
    747 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    748 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    749 #else
    750 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    751 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    752 #endif
    753 
    754 	/*
    755 	 * map integrated peripherals at same address in l1pagetable
    756 	 * so that we can continue to use console.
    757 	 */
    758 	pmap_devmap_bootstrap(l1pagetable, gumstix_devmap);
    759 
    760 	/*
    761 	 * Give the XScale global cache clean code an appropriately
    762 	 * sized chunk of unmapped VA space starting at 0xff000000
    763 	 * (our device mappings end before this address).
    764 	 */
    765 	xscale_cache_clean_addr = 0xff000000U;
    766 
    767 	/*
    768 	 * Now we have the real page tables in place so we can switch to them.
    769 	 * Once this is done we will be running with the REAL kernel page
    770 	 * tables.
    771 	 */
    772 
    773 	/*
    774 	 * Update the physical_freestart/physical_freeend/free_pages
    775 	 * variables.
    776 	 */
    777 	{
    778 		extern char _end[];
    779 
    780 		physical_freestart = physical_start +
    781 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    782 		     KERNEL_BASE);
    783 		physical_freeend = physical_end;
    784 		free_pages =
    785 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    786 	}
    787 
    788 	/* Switch tables */
    789 #ifdef VERBOSE_INIT_ARM
    790 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    791 	       physical_freestart, free_pages, free_pages);
    792 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    793 #endif
    794 
    795 	setttb(kernel_l1pt.pv_pa);
    796 	cpu_tlb_flushID();
    797 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    798 
    799 	/*
    800 	 * Moved from cpu_startup() as data_abort_handler() references
    801 	 * this during uvm init
    802 	 */
    803 	proc0paddr = (struct user *)kernelstack.pv_va;
    804 	lwp0.l_addr = proc0paddr;
    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 #if defined(FFUARTCONSOLE) || defined(STUARTCONSOLE) || \
   1028     defined(BTUARTCONSOLE) || defined(HWUARTCONSOLE)
   1029 	uint32_t ckenreg = ioreg_read(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN);
   1030 #endif
   1031 
   1032 	if (consinit_called != 0)
   1033 		return;
   1034 
   1035 	consinit_called = 1;
   1036 
   1037 #if NCOM > 0
   1038 
   1039 #ifdef FFUARTCONSOLE
   1040 #ifdef KGDB
   1041 	if (0 == strcmp(kgdb_devname, "ffuart")){
   1042 		/* port is reserved for kgdb */
   1043 	} else
   1044 #endif
   1045 	{
   1046 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
   1047 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1048 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1049 			    ckenreg|CKEN_FFUART);
   1050 
   1051 			return;
   1052 		}
   1053 	}
   1054 #endif /* FFUARTCONSOLE */
   1055 
   1056 #ifdef STUARTCONSOLE
   1057 #ifdef KGDB
   1058 	if (0 == strcmp(kgdb_devname, "stuart")) {
   1059 		/* port is reserved for kgdb */
   1060 	} else
   1061 #endif
   1062 	{
   1063 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE,
   1064 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1065 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1066 			    ckenreg|CKEN_STUART);
   1067 			return;
   1068 		}
   1069 	}
   1070 #endif /* STUARTCONSOLE */
   1071 
   1072 #ifdef BTUARTCONSOLE
   1073 #ifdef KGDB
   1074 	if (0 == strcmp(kgdb_devname, "btuart")) {
   1075 		/* port is reserved for kgdb */
   1076 	} else
   1077 #endif
   1078 	{
   1079 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
   1080 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1081 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1082 			    ckenreg|CKEN_BTUART);
   1083 			return;
   1084 		}
   1085 	}
   1086 #endif /* BTUARTCONSOLE */
   1087 
   1088 #ifdef HWUARTCONSOLE
   1089 #ifdef KGDB
   1090 	if (0 == strcmp(kgdb_devname, "hwuart")) {
   1091 		/* port is reserved for kgdb */
   1092 	} else
   1093 #endif
   1094 	{
   1095 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE,
   1096 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1097 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1098 			    ckenreg|CKEN_HWUART);
   1099 			return;
   1100 		}
   1101 	}
   1102 #endif /* HWUARTCONSOLE */
   1103 
   1104 #endif /* NCOM */
   1105 
   1106 #if NLCD > 0
   1107 	{
   1108 		extern void gxlcd_cnattach(void);
   1109 
   1110 		gxlcd_cnattach();
   1111 	}
   1112 #endif
   1113 }
   1114 
   1115 #ifdef KGDB
   1116 static void
   1117 kgdb_port_init(void)
   1118 {
   1119 #if (NCOM > 0) && defined(COM_PXA2X0)
   1120 	paddr_t paddr = 0;
   1121 	uint32_t ckenreg = ioreg_read(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN);
   1122 
   1123 	if (0 == strcmp(kgdb_devname, "ffuart")) {
   1124 		paddr = PXA2X0_FFUART_BASE;
   1125 		ckenreg |= CKEN_FFUART;
   1126 	} else if (0 == strcmp(kgdb_devname, "stuart")) {
   1127 		paddr = PXA2X0_STUART_BASE;
   1128 		ckenreg |= CKEN_STUART;
   1129 	} else if (0 == strcmp(kgdb_devname, "btuart")) {
   1130 		paddr = PXA2X0_BTUART_BASE;
   1131 		ckenreg |= CKEN_BTUART;
   1132 	} else if (0 == strcmp(kgdb_devname, "hwuart")) {
   1133 		paddr = PXA2X0_HWUART_BASE;
   1134 		ckenreg |= CKEN_HWUART;
   1135 	}
   1136 
   1137 	if (paddr &&
   1138 	    0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
   1139 		kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
   1140 
   1141 		ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN, ckenreg);
   1142 
   1143 	}
   1144 
   1145 #endif
   1146 }
   1147 #endif
   1148