Home | History | Annotate | Line # | Download | only in gumstix
gumstix_machdep.c revision 1.14
      1 /*	$NetBSD: gumstix_machdep.c,v 1.14 2009/03/18 10:22:27 cegger Exp $ */
      2 /*
      3  * Copyright (C) 2005, 2006, 2007  WIDE Project and SOUM Corporation.
      4  * All rights reserved.
      5  *
      6  * Written by Takashi Kiyohara and Susumu Miki for WIDE Project and SOUM
      7  * Corporation.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. Neither the name of the project nor the name of SOUM Corporation
     18  *    may be used to endorse or promote products derived from this software
     19  *    without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT and SOUM CORPORATION ``AS IS''
     22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT AND SOUM CORPORATION
     25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31  * POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 /*
     34  * Copyright (c) 2002, 2003, 2004, 2005  Genetec Corporation.
     35  * All rights reserved.
     36  *
     37  * Written by Hiroyuki Bessho for Genetec Corporation.
     38  *
     39  * Redistribution and use in source and binary forms, with or without
     40  * modification, are permitted provided that the following conditions
     41  * are met:
     42  * 1. Redistributions of source code must retain the above copyright
     43  *    notice, this list of conditions and the following disclaimer.
     44  * 2. Redistributions in binary form must reproduce the above copyright
     45  *    notice, this list of conditions and the following disclaimer in the
     46  *    documentation and/or other materials provided with the distribution.
     47  * 3. The name of Genetec Corporation may not be used to endorse or
     48  *    promote products derived from this software without specific prior
     49  *    written permission.
     50  *
     51  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     52  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     53  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     54  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     55  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     56  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     57  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     58  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     59  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     60  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     61  * POSSIBILITY OF SUCH DAMAGE.
     62  *
     63  * Machine dependant functions for kernel setup for Genetec G4250EBX
     64  * evaluation board.
     65  *
     66  * Based on iq80310_machhdep.c
     67  */
     68 /*
     69  * Copyright (c) 2001 Wasabi Systems, Inc.
     70  * All rights reserved.
     71  *
     72  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     73  *
     74  * Redistribution and use in source and binary forms, with or without
     75  * modification, are permitted provided that the following conditions
     76  * are met:
     77  * 1. Redistributions of source code must retain the above copyright
     78  *    notice, this list of conditions and the following disclaimer.
     79  * 2. Redistributions in binary form must reproduce the above copyright
     80  *    notice, this list of conditions and the following disclaimer in the
     81  *    documentation and/or other materials provided with the distribution.
     82  * 3. All advertising materials mentioning features or use of this software
     83  *    must display the following acknowledgement:
     84  *	This product includes software developed for the NetBSD Project by
     85  *	Wasabi Systems, Inc.
     86  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     87  *    or promote products derived from this software without specific prior
     88  *    written permission.
     89  *
     90  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     91  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     92  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     93  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     94  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     95  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     96  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     97  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     98  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     99  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    100  * POSSIBILITY OF SUCH DAMAGE.
    101  */
    102 
    103 /*
    104  * Copyright (c) 1997,1998 Mark Brinicombe.
    105  * Copyright (c) 1997,1998 Causality Limited.
    106  * All rights reserved.
    107  *
    108  * Redistribution and use in source and binary forms, with or without
    109  * modification, are permitted provided that the following conditions
    110  * are met:
    111  * 1. Redistributions of source code must retain the above copyright
    112  *    notice, this list of conditions and the following disclaimer.
    113  * 2. Redistributions in binary form must reproduce the above copyright
    114  *    notice, this list of conditions and the following disclaimer in the
    115  *    documentation and/or other materials provided with the distribution.
    116  * 3. All advertising materials mentioning features or use of this software
    117  *    must display the following acknowledgement:
    118  *	This product includes software developed by Mark Brinicombe
    119  *	for the NetBSD Project.
    120  * 4. The name of the company nor the name of the author may be used to
    121  *    endorse or promote products derived from this software without specific
    122  *    prior written permission.
    123  *
    124  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
    125  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    126  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    127  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    128  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    129  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    130  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    131  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    132  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    133  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    134  * SUCH DAMAGE.
    135  *
    136  * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
    137  * boards using RedBoot firmware.
    138  */
    139 
    140 #include "opt_ddb.h"
    141 #include "opt_kgdb.h"
    142 #include "opt_pmap_debug.h"
    143 #include "opt_md.h"
    144 #include "opt_modular.h"
    145 #include "opt_com.h"
    146 #include "md.h"
    147 
    148 #include <sys/param.h>
    149 #include <sys/device.h>
    150 #include <sys/systm.h>
    151 #include <sys/kernel.h>
    152 #include <sys/exec.h>
    153 #include <sys/proc.h>
    154 #include <sys/msgbuf.h>
    155 #include <sys/reboot.h>
    156 #include <sys/termios.h>
    157 #include <sys/ksyms.h>
    158 
    159 #include <uvm/uvm_extern.h>
    160 
    161 #include <sys/conf.h>
    162 #include <dev/cons.h>
    163 #include <dev/md.h>
    164 
    165 #include <machine/db_machdep.h>
    166 #include <ddb/db_sym.h>
    167 #include <ddb/db_extern.h>
    168 #ifdef KGDB
    169 #include <sys/kgdb.h>
    170 #endif
    171 
    172 #include <machine/bootconfig.h>
    173 #include <machine/bus.h>
    174 #include <machine/cpu.h>
    175 #include <machine/frame.h>
    176 #include <arm/undefined.h>
    177 
    178 #include <arm/arm32/machdep.h>
    179 
    180 #include <arm/xscale/pxa2x0reg.h>
    181 #include <arm/xscale/pxa2x0var.h>
    182 #include <arm/xscale/pxa2x0_gpio.h>
    183 #include <evbarm/gumstix/gumstixreg.h>
    184 #include <evbarm/gumstix/gumstixvar.h>
    185 
    186 /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    187 #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
    188 #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    189 
    190 /*
    191  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    192  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    193  */
    194 #define KERNEL_VM_SIZE		0x0C000000
    195 
    196 
    197 /*
    198  * Address to call from cpu_reset() to reset the machine.
    199  * This is machine architecture dependant as it varies depending
    200  * on where the ROM appears when you turn the MMU off.
    201  */
    202 
    203 u_int cpu_reset_address = 0;
    204 
    205 /* Define various stack sizes in pages */
    206 #define IRQ_STACK_SIZE	1
    207 #define ABT_STACK_SIZE	1
    208 #define UND_STACK_SIZE	1
    209 
    210 BootConfig bootconfig;		/* Boot config storage */
    211 static char bootargs[MAX_BOOT_STRING];
    212 char *boot_args = NULL;
    213 
    214 uint32_t system_serial_high;
    215 uint32_t system_serial_low;
    216 
    217 vm_offset_t physical_start;
    218 vm_offset_t physical_freestart;
    219 vm_offset_t physical_freeend;
    220 vm_offset_t physical_end;
    221 u_int free_pages;
    222 vm_offset_t pagetables_start;
    223 int physmem = 0;
    224 
    225 /*int debug_flags;*/
    226 #ifndef PMAP_STATIC_L1S
    227 int max_processes = 64;			/* Default number */
    228 #endif	/* !PMAP_STATIC_L1S */
    229 
    230 /* Physical and virtual addresses for some global pages */
    231 pv_addr_t irqstack;
    232 pv_addr_t undstack;
    233 pv_addr_t abtstack;
    234 pv_addr_t kernelstack;
    235 pv_addr_t minidataclean;
    236 
    237 vm_offset_t msgbufphys;
    238 
    239 extern u_int data_abort_handler_address;
    240 extern u_int prefetch_abort_handler_address;
    241 extern u_int undefined_handler_address;
    242 
    243 #ifdef PMAP_DEBUG
    244 extern int pmap_debug_level;
    245 #endif
    246 
    247 #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    248 #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    249 #define	KERNEL_PT_KERNEL_NUM	4
    250 #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
    251 				        /* Page tables for mapping kernel VM */
    252 #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    253 #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    254 
    255 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    256 
    257 struct user *proc0paddr;
    258 
    259 /* Prototypes */
    260 static void	read_system_serial(void);
    261 static void	process_kernel_args(int, char *[]);
    262 #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 		pmf_system_shutdown(boothowto);
    309 		printf("The operating system has halted.\n");
    310 		printf("Please press any key to reboot.\n\n");
    311 		cngetc();
    312 		printf("rebooting...\n");
    313 		cpu_reset();
    314 		/*NOTREACHED*/
    315 	}
    316 
    317 	/*
    318 	 * If RB_NOSYNC was not specified sync the discs.
    319 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    320 	 * unmount.  It looks like syslogd is getting woken up only to find
    321 	 * that it cannot page part of the binary in as the filesystem has
    322 	 * been unmounted.
    323 	 */
    324 	if (!(howto & RB_NOSYNC))
    325 		bootsync();
    326 
    327 	/* Say NO to interrupts */
    328 	splhigh();
    329 
    330 	/* Do a dump if requested. */
    331 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    332 		dumpsys();
    333 
    334 	/* Run any shutdown hooks */
    335 	doshutdownhooks();
    336 
    337 	pmf_system_shutdown(boothowto);
    338 
    339 	/* Make sure IRQ's are disabled */
    340 	IRQdisable;
    341 
    342 	if (howto & RB_HALT) {
    343 		printf("The operating system has halted.\n");
    344 		printf("Please press any key to reboot.\n\n");
    345 		cngetc();
    346 	}
    347 
    348 	printf("rebooting...\n");
    349 	cpu_reset();
    350 	/*NOTREACHED*/
    351 }
    352 
    353 static inline
    354 pd_entry_t *
    355 read_ttb(void)
    356 {
    357   long ttb;
    358 
    359   __asm volatile("mrc	p15, 0, %0, c2, c0, 0" : "=r" (ttb));
    360 
    361 
    362   return (pd_entry_t *)(ttb & ~((1<<14)-1));
    363 }
    364 
    365 /*
    366  * Static device mappings. These peripheral registers are mapped at
    367  * fixed virtual addresses very early in initarm() so that we can use
    368  * them while booting the kernel, and stay at the same address
    369  * throughout whole kernel's life time.
    370  *
    371  * We use this table twice; once with bootstrap page table, and once
    372  * with kernel's page table which we build up in initarm().
    373  *
    374  * Since we map these registers into the bootstrap page table using
    375  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    376  * registers segment-aligned and segment-rounded in order to avoid
    377  * using the 2nd page tables.
    378  */
    379 
    380 #define	_A(a)	((a) & ~L1_S_OFFSET)
    381 #define	_S(s)	(((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    382 
    383 static const struct pmap_devmap gumstix_devmap[] = {
    384 	{
    385 		GUMSTIX_GPIO_VBASE,
    386 		_A(PXA2X0_GPIO_BASE),
    387 		_S(PXA250_GPIO_SIZE),
    388 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    389 	},
    390 	{
    391 		GUMSTIX_CLKMAN_VBASE,
    392 		_A(PXA2X0_CLKMAN_BASE),
    393 		_S(PXA2X0_CLKMAN_SIZE),
    394 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    395 	},
    396 	{
    397 		GUMSTIX_INTCTL_VBASE,
    398 		_A(PXA2X0_INTCTL_BASE),
    399 		_S(PXA2X0_INTCTL_SIZE),
    400 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    401 	},
    402 	{
    403 		GUMSTIX_FFUART_VBASE,
    404 		_A(PXA2X0_FFUART_BASE),
    405 		_S(4 * COM_NPORTS),
    406 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    407 	},
    408 	{
    409 		GUMSTIX_STUART_VBASE,
    410 		_A(PXA2X0_STUART_BASE),
    411 		_S(4 * COM_NPORTS),
    412 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    413 	},
    414 	{
    415 		GUMSTIX_BTUART_VBASE,
    416 		_A(PXA2X0_BTUART_BASE),
    417 		_S(4 * COM_NPORTS),
    418 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    419 	},
    420 	{
    421 		GUMSTIX_HWUART_VBASE,
    422 		_A(PXA2X0_HWUART_BASE),
    423 		_S(4 * COM_NPORTS),
    424 		VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE,
    425 	},
    426 	{0, 0, 0, 0, 0}
    427 };
    428 
    429 #undef	_A
    430 #undef	_S
    431 
    432 
    433 /*
    434  * u_int initarm(...)
    435  *
    436  * Initial entry point on startup. This gets called before main() is
    437  * entered.
    438  * It should be responsible for setting up everything that must be
    439  * in place when main is called.
    440  * This includes
    441  *   Taking a copy of the boot configuration structure.
    442  *   Initialising the physical console so characters can be printed.
    443  *   Setting up page tables for the kernel
    444  *   Relocating the kernel to the bottom of physical memory
    445  */
    446 u_int
    447 initarm(void *arg)
    448 {
    449 	extern vaddr_t xscale_cache_clean_addr;
    450 	extern uint32_t *u_boot_args[];
    451 	enum { r3 = 0, r4 = 1, r5 = 2, r6 = 3 };	/* args from u-boot */
    452 	int loop;
    453 	int loop1;
    454 	u_int l1pagetable;
    455 	paddr_t memstart;
    456 	psize_t memsize;
    457 #ifdef DIAGNOSTIC
    458 	extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
    459 #endif
    460 
    461 	/* map some peripheral registers at static I/O area */
    462 	pmap_devmap_bootstrap((vaddr_t)read_ttb(), gumstix_devmap);
    463 
    464 	/* start 32.768kHz OSC */
    465 	ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_OSCC, OSCC_OON);
    466 
    467 	/* Get ready for splfoo() */
    468 	pxa2x0_intr_bootstrap(GUMSTIX_INTCTL_VBASE);
    469 
    470 	/*
    471 	 * Heads up ... Setup the CPU / MMU / TLB functions
    472 	 */
    473 	if (set_cpufuncs())
    474 		panic("cpu not recognized!");
    475 
    476 	/*
    477 	 * U-Boot doesn't use the virtual memory.
    478 	 *
    479 	 * Physical Address Range     Description
    480 	 * -----------------------    ----------------------------------
    481 	 * 0x00000000 - 0x00ffffff    flash Memory   (16MB or 4MB)
    482 	 * 0x40000000 - 0x480fffff    Processor Registers
    483 	 * 0xa0000000 - 0xa3ffffff    SDRAM Bank 0 (64MB)
    484 	 */
    485 
    486 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    487 
    488 	/* setup GPIO for {FF,ST,HW}UART. */
    489 	pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
    490 
    491 	/* configure GPIOs. */
    492 	gxio_config_pin();
    493 
    494 	consinit();
    495 #ifdef KGDB
    496 	kgdb_port_init();
    497 #endif
    498 
    499 	/* Talk to the user */
    500 	printf("\nNetBSD/evbarm (gumstix) booting ...\n");
    501 
    502 	/* Read system serial */
    503 	read_system_serial();
    504 
    505         /*
    506 	 * Examine the boot args string for options we need to know about
    507 	 * now.
    508 	 */
    509 	process_kernel_args((int)u_boot_args[r6], (char **)u_boot_args[r5]);
    510 
    511 	memstart = 0xa0000000UL;
    512 	memsize = 0x04000000UL;		/* 64MB */
    513 
    514 #ifdef VERBOSE_INIT_ARM
    515 	printf("initarm: Configuring system ...\n");
    516 #endif
    517 
    518 	/* Fake bootconfig structure for the benefit of pmap.c */
    519 	/* XXX must make the memory description h/w independent */
    520 	bootconfig.dramblocks = 1;
    521 	bootconfig.dram[0].address = memstart;
    522 	bootconfig.dram[0].pages = memsize / PAGE_SIZE;
    523 
    524 	/*
    525 	 * Set up the variables that define the availablilty of
    526 	 * physical memory.  For now, we're going to set
    527 	 * physical_freestart to 0xa0200000 (where the kernel
    528 	 * was loaded), and allocate the memory we need downwards.
    529 	 * If we get too close to the L1 table that we set up, we
    530 	 * will panic.  We will update physical_freestart and
    531 	 * physical_freeend later to reflect what pmap_bootstrap()
    532 	 * wants to see.
    533 	 *
    534 	 * XXX pmap_bootstrap() needs an enema.
    535 	 */
    536 	physical_start = bootconfig.dram[0].address;
    537 	physical_end = physical_start + memsize;
    538 
    539 	physical_freestart = 0xa0009000UL;
    540 	physical_freeend = 0xa0200000UL;
    541 
    542 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    543 
    544 #ifdef VERBOSE_INIT_ARM
    545 	/* Tell the user about the memory */
    546 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    547 	    physical_start, physical_end - 1);
    548 #endif
    549 
    550 	/*
    551 	 * Okay, the kernel starts 2MB in from the bottom of physical
    552 	 * memory.  We are going to allocate our bootstrap pages downwards
    553 	 * from there.
    554 	 *
    555 	 * We need to allocate some fixed page tables to get the kernel
    556 	 * going.  We allocate one page directory and a number of page
    557 	 * tables and store the physical addresses in the kernel_pt_table
    558 	 * array.
    559 	 *
    560 	 * The kernel page directory must be on a 16K boundary.  The page
    561 	 * tables must be on 4K bounaries.  What we do is allocate the
    562 	 * page directory on the first 16K boundary that we encounter, and
    563 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    564 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    565 	 * least one 16K aligned region.
    566 	 */
    567 
    568 #ifdef VERBOSE_INIT_ARM
    569 	printf("Allocating page tables\n");
    570 #endif
    571 
    572 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    573 
    574 #ifdef VERBOSE_INIT_ARM
    575 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    576 	       physical_freestart, free_pages, free_pages);
    577 #endif
    578 
    579 	/* Define a macro to simplify memory allocation */
    580 #define	valloc_pages(var, np)				\
    581 	alloc_pages((var).pv_pa, (np));			\
    582 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    583 
    584 #define alloc_pages(var, np)				\
    585 	physical_freeend -= ((np) * PAGE_SIZE);		\
    586 	if (physical_freeend < physical_freestart)	\
    587 		panic("initarm: out of memory");	\
    588 	(var) = physical_freeend;			\
    589 	free_pages -= (np);				\
    590 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    591 
    592 	loop1 = 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(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    848 
    849 #ifdef __HAVE_MEMORY_DISK__
    850 	md_root_setconf(memory_disk, sizeof memory_disk);
    851 #endif
    852 
    853 #ifdef BOOTHOWTO
    854 	boothowto |= BOOTHOWTO;
    855 #endif
    856 
    857 #ifdef KGDB
    858 	if (boothowto & RB_KDB) {
    859 		kgdb_debug_init = 1;
    860 		kgdb_connect(1);
    861 	}
    862 #endif
    863 
    864 #if NKSYMS || defined(DDB) || defined(MODULAR)
    865 	/* Firmware doesn't load symbols. */
    866 	ddb_init(0, NULL, NULL);
    867 #endif
    868 
    869 #ifdef DDB
    870 	db_machine_init();
    871 	if (boothowto & RB_KDB)
    872 		Debugger();
    873 #endif
    874 
    875 	/* We return the new stack pointer address */
    876 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    877 }
    878 
    879 static void
    880 read_system_serial(void)
    881 {
    882 #define GUMSTIX_SYSTEM_SERIAL_ADDR	0
    883 #define GUMSTIX_SYSTEM_SERIAL_SIZE	8
    884 #define FLASH_OFFSET_INTEL_PROTECTION	0x81
    885 #define FLASH_OFFSET_USER_PROTECTION	0x85
    886 #define FLASH_CMD_READ_ID		0x90
    887 #define FLASH_CMD_RESET			0xff
    888 	int i;
    889 	char system_serial[GUMSTIX_SYSTEM_SERIAL_SIZE], *src;
    890 	char x;
    891 
    892 	src = (char *)(FLASH_OFFSET_USER_PROTECTION * 2 /*word*/);
    893 	*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
    894 	memcpy(system_serial,
    895 	    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
    896 	*(volatile uint16_t *)0 = FLASH_CMD_RESET;
    897 
    898 	for (i = 1, x = system_serial[0]; i < sizeof (system_serial); i++)
    899 		x &= system_serial[i];
    900 	if (x == 0xff) {
    901 		src = (char *)(FLASH_OFFSET_INTEL_PROTECTION * 2 /*word*/);
    902 		*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
    903 		memcpy(system_serial,
    904 		    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
    905 		*(volatile uint16_t *)0 = FLASH_CMD_RESET;
    906 
    907 		/*
    908 		 * XXXX: Don't need ???
    909 		 * gumstix_serial_hash(system_serial);
    910 		 */
    911 	}
    912 	system_serial_high = system_serial[0] << 24 | system_serial[1] << 16 |
    913 	    system_serial[2] << 8 | system_serial[3];
    914 	system_serial_low = system_serial[4] << 24 | system_serial[5] << 16 |
    915 	    system_serial[6] << 8 | system_serial[7];
    916 
    917 	printf("system serial: 0x");
    918 	for (i = 0; i < sizeof (system_serial); i++)
    919 		printf("%02x", system_serial[i]);
    920 	printf("\n");
    921 }
    922 
    923 static void
    924 process_kernel_args(int argc, char *argv[])
    925 {
    926 	static const char busheader_name[] = "busheader=";
    927 	int gxio_configured = 0, i, j;
    928 
    929 	boothowto = 0;
    930 
    931 	/*
    932 	 * XXXXX: The value of argc is wrong.  The number of arguments is
    933 	 * corrected in the do_go() of u-boot.  However, it is not actually
    934 	 * corrected.
    935 	 */
    936 	argc --;
    937 
    938 	for (i = 1, j = 0; i < argc; i++) {
    939 		if (!strncmp(argv[i], busheader_name, strlen(busheader_name))) {
    940 			/* configure for GPIOs of busheader side */
    941 			gxio_config_expansion(argv[i] + strlen(busheader_name));
    942 			gxio_configured = 1;
    943 			continue;
    944 		}
    945 		if (j == MAX_BOOT_STRING) {
    946 			*(bootargs + j) = '\0';
    947 			continue;
    948 		}
    949 		if (j != 0)
    950 			*(bootargs + j++) = ' ';
    951 		strncpy(bootargs + j, argv[i], MAX_BOOT_STRING - j);
    952 		j += strlen(argv[i]);
    953 	}
    954 	boot_args = bootargs;
    955 
    956 	parse_mi_bootargs(boot_args);
    957 
    958 	if (!gxio_configured)
    959 		gxio_config_expansion(NULL);
    960 }
    961 
    962 #ifdef KGDB
    963 #ifndef KGDB_DEVNAME
    964 #define KGDB_DEVNAME	"ffuart"
    965 #endif
    966 const char kgdb_devname[] = KGDB_DEVNAME;
    967 
    968 #ifndef KGDB_DEVRATE
    969 #define KGDB_DEVRATE	CONSPEED
    970 #endif
    971 int kgdb_devrate = KGDB_DEVRATE;
    972 
    973 #if (NCOM > 0)
    974 #ifndef KGDB_DEVMODE
    975 #define KGDB_DEVMODE	CONMODE
    976 #endif
    977 int comkgdbmode = KGDB_DEVMODE;
    978 #endif /* NCOM */
    979 
    980 #endif /* KGDB */
    981 
    982 
    983 void
    984 consinit(void)
    985 {
    986 	static int consinit_called = 0;
    987 	uint32_t ckenreg = ioreg_read(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN);
    988 
    989 	if (consinit_called != 0)
    990 		return;
    991 
    992 	consinit_called = 1;
    993 
    994 #if NCOM > 0
    995 
    996 #ifdef FFUARTCONSOLE
    997 #ifdef KGDB
    998 	if (0 == strcmp(kgdb_devname, "ffuart")){
    999 		/* port is reserved for kgdb */
   1000 	} else
   1001 #endif
   1002 	{
   1003 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
   1004 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1005 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1006 			    ckenreg|CKEN_FFUART);
   1007 
   1008 			return;
   1009 		}
   1010 	}
   1011 #endif /* FFUARTCONSOLE */
   1012 
   1013 #ifdef STUARTCONSOLE
   1014 #ifdef KGDB
   1015 	if (0 == strcmp(kgdb_devname, "stuart")) {
   1016 		/* port is reserved for kgdb */
   1017 	} else
   1018 #endif
   1019 	{
   1020 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE,
   1021 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1022 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1023 			    ckenreg|CKEN_STUART);
   1024 			return;
   1025 		}
   1026 	}
   1027 #endif /* STUARTCONSOLE */
   1028 
   1029 #ifdef BTUARTCONSOLE
   1030 #ifdef KGDB
   1031 	if (0 == strcmp(kgdb_devname, "btuart")) {
   1032 		/* port is reserved for kgdb */
   1033 	} else
   1034 #endif
   1035 	{
   1036 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
   1037 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1038 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1039 			    ckenreg|CKEN_BTUART);
   1040 			return;
   1041 		}
   1042 	}
   1043 #endif /* BTUARTCONSOLE */
   1044 
   1045 #ifdef HWUARTCONSOLE
   1046 #ifdef KGDB
   1047 	if (0 == strcmp(kgdb_devname, "hwuart")) {
   1048 		/* port is reserved for kgdb */
   1049 	} else
   1050 #endif
   1051 	{
   1052 		if (0 == comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE,
   1053 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode)) {
   1054 			ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN,
   1055 			    ckenreg|CKEN_HWUART);
   1056 			return;
   1057 		}
   1058 	}
   1059 #endif /* HWUARTCONSOLE */
   1060 
   1061 #endif /* NCOM */
   1062 
   1063 }
   1064 
   1065 #ifdef KGDB
   1066 static void
   1067 kgdb_port_init(void)
   1068 {
   1069 #if (NCOM > 0) && defined(COM_PXA2X0)
   1070 	paddr_t paddr = 0;
   1071 	uint32_t ckenreg = ioreg_read(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN);
   1072 
   1073 	if (0 == strcmp(kgdb_devname, "ffuart")) {
   1074 		paddr = PXA2X0_FFUART_BASE;
   1075 		ckenreg |= CKEN_FFUART;
   1076 	} else if (0 == strcmp(kgdb_devname, "stuart")) {
   1077 		paddr = PXA2X0_STUART_BASE;
   1078 		ckenreg |= CKEN_STUART;
   1079 	} else if (0 == strcmp(kgdb_devname, "btuart")) {
   1080 		paddr = PXA2X0_BTUART_BASE;
   1081 		ckenreg |= CKEN_BTUART;
   1082 	} else if (0 == strcmp(kgdb_devname, "hwuart")) {
   1083 		paddr = PXA2X0_HWUART_BASE;
   1084 		ckenreg |= CKEN_HWUART;
   1085 	}
   1086 
   1087 	if (paddr &&
   1088 	    0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
   1089 		kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
   1090 
   1091 		ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_CKEN, ckenreg);
   1092 
   1093 	}
   1094 
   1095 #endif
   1096 }
   1097 #endif
   1098