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