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