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