Home | History | Annotate | Line # | Download | only in gumstix
gumstix_machdep.c revision 1.48
      1  1.48  kiyohara /*	$NetBSD: gumstix_machdep.c,v 1.48 2013/09/26 16:14:34 kiyohara 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.17  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.17  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.36       wiz  * Machine dependent functions for kernel setup for Genetec G4250EBX
     64   1.1  kiyohara  * evaluation board.
     65  1.17  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.36       wiz  * Machine dependent 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.29  kiyohara #include "opt_evbarm_boardtype.h"
    141  1.27  kiyohara #include "opt_cputypes.h"
    142  1.31  kiyohara #include "opt_gumstix.h"
    143  1.31  kiyohara #ifdef OVERO
    144  1.30  kiyohara #include "opt_omap.h"
    145  1.32  kiyohara #include "prcm.h"
    146  1.31  kiyohara #endif
    147   1.1  kiyohara #include "opt_ddb.h"
    148   1.1  kiyohara #include "opt_kgdb.h"
    149   1.1  kiyohara #include "opt_pmap_debug.h"
    150   1.1  kiyohara #include "opt_md.h"
    151  1.13       apb #include "opt_modular.h"
    152   1.1  kiyohara #include "opt_com.h"
    153   1.1  kiyohara 
    154   1.1  kiyohara #include <sys/param.h>
    155  1.26  kiyohara #include <sys/conf.h>
    156   1.1  kiyohara #include <sys/device.h>
    157  1.26  kiyohara #include <sys/exec.h>
    158   1.1  kiyohara #include <sys/kernel.h>
    159  1.26  kiyohara #include <sys/ksyms.h>
    160  1.26  kiyohara #include <sys/msgbuf.h>
    161   1.1  kiyohara #include <sys/proc.h>
    162   1.1  kiyohara #include <sys/reboot.h>
    163  1.26  kiyohara #include <sys/systm.h>
    164   1.1  kiyohara #include <sys/termios.h>
    165  1.47      matt #include <sys/bus.h>
    166  1.47      matt #include <sys/cpu.h>
    167   1.1  kiyohara 
    168  1.27  kiyohara #include <machine/autoconf.h>
    169   1.1  kiyohara #include <machine/bootconfig.h>
    170  1.26  kiyohara #include <machine/db_machdep.h>
    171  1.47      matt #include <arm/locore.h>
    172  1.47      matt #include <arm/undefined.h>
    173   1.1  kiyohara 
    174   1.1  kiyohara #include <arm/arm32/machdep.h>
    175  1.45      matt #ifdef OVERO
    176  1.30  kiyohara #include <arm/omap/omap2_gpmcreg.h>
    177  1.32  kiyohara #include <arm/omap/omap2_prcm.h>
    178  1.27  kiyohara #include <arm/omap/omap2_reg.h>
    179  1.27  kiyohara #include <arm/omap/omap_var.h>
    180  1.27  kiyohara #include <arm/omap/omap_com.h>
    181  1.45      matt #endif
    182   1.1  kiyohara #include <arm/xscale/pxa2x0reg.h>
    183   1.1  kiyohara #include <arm/xscale/pxa2x0var.h>
    184   1.1  kiyohara #include <arm/xscale/pxa2x0_gpio.h>
    185   1.1  kiyohara #include <evbarm/gumstix/gumstixreg.h>
    186   1.1  kiyohara #include <evbarm/gumstix/gumstixvar.h>
    187   1.1  kiyohara 
    188  1.26  kiyohara #include <uvm/uvm_extern.h>
    189  1.26  kiyohara 
    190  1.26  kiyohara #include <dev/cons.h>
    191  1.26  kiyohara #include <dev/md.h>
    192  1.26  kiyohara 
    193  1.26  kiyohara #include <ddb/db_sym.h>
    194  1.26  kiyohara #include <ddb/db_extern.h>
    195  1.26  kiyohara #ifdef KGDB
    196  1.26  kiyohara #include <sys/kgdb.h>
    197  1.26  kiyohara #endif
    198  1.26  kiyohara 
    199   1.1  kiyohara /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    200   1.1  kiyohara #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
    201  1.24  kiyohara #ifndef KERNEL_VM_BASE
    202   1.1  kiyohara #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    203  1.24  kiyohara #endif
    204   1.1  kiyohara 
    205   1.1  kiyohara /*
    206   1.1  kiyohara  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    207   1.1  kiyohara  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    208   1.1  kiyohara  */
    209   1.1  kiyohara #define KERNEL_VM_SIZE		0x0C000000
    210   1.1  kiyohara 
    211   1.1  kiyohara BootConfig bootconfig;		/* Boot config storage */
    212   1.1  kiyohara static char bootargs[MAX_BOOT_STRING];
    213  1.38       mrg const size_t bootargs_len = sizeof(bootargs) - 1;	/* without nul */
    214   1.1  kiyohara char *boot_args = NULL;
    215   1.1  kiyohara 
    216   1.1  kiyohara uint32_t system_serial_high;
    217   1.1  kiyohara uint32_t system_serial_low;
    218   1.1  kiyohara 
    219   1.1  kiyohara vm_offset_t physical_start;
    220   1.1  kiyohara vm_offset_t physical_freestart;
    221   1.1  kiyohara vm_offset_t physical_freeend;
    222   1.1  kiyohara vm_offset_t physical_end;
    223   1.1  kiyohara u_int free_pages;
    224   1.1  kiyohara 
    225   1.1  kiyohara /*int debug_flags;*/
    226   1.1  kiyohara #ifndef PMAP_STATIC_L1S
    227   1.1  kiyohara int max_processes = 64;			/* Default number */
    228   1.1  kiyohara #endif	/* !PMAP_STATIC_L1S */
    229   1.1  kiyohara 
    230  1.40      matt pv_addr_t minidataclean;
    231  1.40      matt 
    232   1.1  kiyohara vm_offset_t msgbufphys;
    233   1.1  kiyohara 
    234   1.1  kiyohara #ifdef PMAP_DEBUG
    235   1.1  kiyohara extern int pmap_debug_level;
    236   1.1  kiyohara #endif
    237   1.1  kiyohara 
    238   1.1  kiyohara #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    239   1.1  kiyohara #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    240  1.24  kiyohara #define	KERNEL_PT_KERNEL_NUM	((KERNEL_VM_BASE - KERNEL_BASE) >> 22)
    241   1.1  kiyohara #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
    242   1.1  kiyohara 				        /* Page tables for mapping kernel VM */
    243   1.1  kiyohara #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    244   1.1  kiyohara #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    245   1.1  kiyohara 
    246   1.1  kiyohara pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    247   1.1  kiyohara 
    248   1.1  kiyohara /* Prototypes */
    249  1.27  kiyohara #if defined(GUMSTIX)
    250   1.3  kiyohara static void	read_system_serial(void);
    251  1.48  kiyohara #elif defined(OVERO)
    252  1.48  kiyohara static void	find_cpu_clock(void);
    253  1.27  kiyohara #endif
    254   1.3  kiyohara static void	process_kernel_args(int, char *[]);
    255  1.25  kiyohara static void	process_kernel_args_liner(char *);
    256   1.3  kiyohara #ifdef KGDB
    257   1.3  kiyohara static void	kgdb_port_init(void);
    258   1.3  kiyohara #endif
    259  1.28  kiyohara static void	gumstix_device_register(device_t, void *);
    260   1.1  kiyohara 
    261   1.1  kiyohara bs_protos(bs_notimpl);
    262   1.1  kiyohara 
    263   1.1  kiyohara #include "com.h"
    264   1.1  kiyohara #if NCOM > 0
    265   1.1  kiyohara #include <dev/ic/comreg.h>
    266   1.1  kiyohara #include <dev/ic/comvar.h>
    267   1.1  kiyohara #endif
    268   1.1  kiyohara 
    269  1.27  kiyohara #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
    270  1.15  kiyohara #include "lcd.h"
    271  1.27  kiyohara #endif
    272  1.15  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.25  kiyohara #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    284  1.25  kiyohara static char console[16];
    285  1.25  kiyohara #endif
    286  1.25  kiyohara 
    287   1.3  kiyohara extern void gxio_config_pin(void);
    288   1.5  kiyohara extern void gxio_config_expansion(char *);
    289   1.3  kiyohara 
    290   1.1  kiyohara /*
    291   1.1  kiyohara  * void cpu_reboot(int howto, char *bootstr)
    292   1.1  kiyohara  *
    293   1.1  kiyohara  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    294   1.1  kiyohara  * then reset the CPU.
    295   1.1  kiyohara  */
    296   1.1  kiyohara void
    297   1.1  kiyohara cpu_reboot(int howto, char *bootstr)
    298   1.1  kiyohara {
    299   1.6  kiyohara 
    300   1.1  kiyohara #ifdef DIAGNOSTIC
    301   1.1  kiyohara 	/* info */
    302   1.1  kiyohara 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    303   1.1  kiyohara #endif
    304   1.1  kiyohara 
    305   1.1  kiyohara 	/*
    306   1.1  kiyohara 	 * If we are still cold then hit the air brakes
    307   1.1  kiyohara 	 * and crash to earth fast
    308   1.1  kiyohara 	 */
    309   1.1  kiyohara 	if (cold) {
    310   1.1  kiyohara 		doshutdownhooks();
    311  1.10    dyoung 		pmf_system_shutdown(boothowto);
    312   1.1  kiyohara 		printf("The operating system has halted.\n");
    313   1.1  kiyohara 		printf("Please press any key to reboot.\n\n");
    314   1.1  kiyohara 		cngetc();
    315   1.1  kiyohara 		printf("rebooting...\n");
    316  1.32  kiyohara #if defined(OMAP_3530) && NPRCM > 0
    317  1.32  kiyohara 		prcm_cold_reset();
    318  1.32  kiyohara #endif
    319   1.1  kiyohara 		cpu_reset();
    320   1.1  kiyohara 		/*NOTREACHED*/
    321   1.1  kiyohara 	}
    322   1.1  kiyohara 
    323   1.1  kiyohara 	/*
    324   1.1  kiyohara 	 * If RB_NOSYNC was not specified sync the discs.
    325   1.1  kiyohara 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    326   1.1  kiyohara 	 * unmount.  It looks like syslogd is getting woken up only to find
    327   1.1  kiyohara 	 * that it cannot page part of the binary in as the filesystem has
    328   1.1  kiyohara 	 * been unmounted.
    329   1.1  kiyohara 	 */
    330   1.1  kiyohara 	if (!(howto & RB_NOSYNC))
    331   1.1  kiyohara 		bootsync();
    332   1.1  kiyohara 
    333   1.1  kiyohara 	/* Say NO to interrupts */
    334   1.1  kiyohara 	splhigh();
    335   1.1  kiyohara 
    336   1.1  kiyohara 	/* Do a dump if requested. */
    337   1.1  kiyohara 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    338   1.1  kiyohara 		dumpsys();
    339  1.27  kiyohara 
    340   1.1  kiyohara 	/* Run any shutdown hooks */
    341   1.1  kiyohara 	doshutdownhooks();
    342   1.1  kiyohara 
    343  1.10    dyoung 	pmf_system_shutdown(boothowto);
    344  1.10    dyoung 
    345   1.1  kiyohara 	/* Make sure IRQ's are disabled */
    346   1.1  kiyohara 	IRQdisable;
    347   1.1  kiyohara 
    348   1.1  kiyohara 	if (howto & RB_HALT) {
    349   1.1  kiyohara 		printf("The operating system has halted.\n");
    350   1.1  kiyohara 		printf("Please press any key to reboot.\n\n");
    351   1.1  kiyohara 		cngetc();
    352   1.1  kiyohara 	}
    353   1.1  kiyohara 
    354   1.1  kiyohara 	printf("rebooting...\n");
    355  1.32  kiyohara #if defined(OMAP_3530) && NPRCM > 0
    356  1.32  kiyohara 	prcm_cold_reset();
    357  1.32  kiyohara #endif
    358   1.1  kiyohara 	cpu_reset();
    359   1.1  kiyohara 	/*NOTREACHED*/
    360   1.1  kiyohara }
    361   1.1  kiyohara 
    362  1.25  kiyohara static inline pd_entry_t *
    363   1.1  kiyohara read_ttb(void)
    364   1.1  kiyohara {
    365  1.27  kiyohara 	long ttb;
    366   1.1  kiyohara 
    367  1.27  kiyohara 	__asm volatile("mrc	p15, 0, %0, c2, c0, 0" : "=r" (ttb));
    368   1.1  kiyohara 
    369  1.27  kiyohara 	return (pd_entry_t *)(ttb & ~((1<<14)-1));
    370   1.1  kiyohara }
    371   1.1  kiyohara 
    372   1.1  kiyohara /*
    373   1.1  kiyohara  * Static device mappings. These peripheral registers are mapped at
    374   1.1  kiyohara  * fixed virtual addresses very early in initarm() so that we can use
    375   1.1  kiyohara  * them while booting the kernel, and stay at the same address
    376   1.1  kiyohara  * throughout whole kernel's life time.
    377   1.1  kiyohara  *
    378   1.1  kiyohara  * We use this table twice; once with bootstrap page table, and once
    379   1.1  kiyohara  * with kernel's page table which we build up in initarm().
    380   1.1  kiyohara  *
    381   1.1  kiyohara  * Since we map these registers into the bootstrap page table using
    382   1.1  kiyohara  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    383   1.1  kiyohara  * registers segment-aligned and segment-rounded in order to avoid
    384   1.1  kiyohara  * using the 2nd page tables.
    385   1.1  kiyohara  */
    386   1.1  kiyohara 
    387   1.1  kiyohara #define	_A(a)	((a) & ~L1_S_OFFSET)
    388   1.1  kiyohara #define	_S(s)	(((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    389   1.1  kiyohara 
    390   1.1  kiyohara static const struct pmap_devmap gumstix_devmap[] = {
    391  1.27  kiyohara #if defined(GUMSTIX)
    392   1.1  kiyohara 	{
    393   1.1  kiyohara 		GUMSTIX_GPIO_VBASE,
    394   1.1  kiyohara 		_A(PXA2X0_GPIO_BASE),
    395   1.1  kiyohara 		_S(PXA250_GPIO_SIZE),
    396  1.27  kiyohara 		VM_PROT_READ | VM_PROT_WRITE,
    397  1.27  kiyohara 		PTE_NOCACHE,
    398   1.1  kiyohara 	},
    399   1.1  kiyohara 	{
    400  1.12     cliff 		GUMSTIX_CLKMAN_VBASE,
    401  1.12     cliff 		_A(PXA2X0_CLKMAN_BASE),
    402  1.12     cliff 		_S(PXA2X0_CLKMAN_SIZE),
    403  1.27  kiyohara 		VM_PROT_READ | VM_PROT_WRITE,
    404  1.27  kiyohara 		PTE_NOCACHE,
    405   1.1  kiyohara 	},
    406   1.1  kiyohara 	{
    407   1.1  kiyohara 		GUMSTIX_INTCTL_VBASE,
    408   1.1  kiyohara 		_A(PXA2X0_INTCTL_BASE),
    409   1.1  kiyohara 		_S(PXA2X0_INTCTL_SIZE),
    410  1.27  kiyohara 		VM_PROT_READ | VM_PROT_WRITE,
    411  1.27  kiyohara 		PTE_NOCACHE,
    412   1.1  kiyohara 	},
    413   1.1  kiyohara 	{
    414   1.1  kiyohara 		GUMSTIX_FFUART_VBASE,
    415   1.1  kiyohara 		_A(PXA2X0_FFUART_BASE),
    416   1.1  kiyohara 		_S(4 * COM_NPORTS),
    417  1.27  kiyohara 		VM_PROT_READ | VM_PROT_WRITE,
    418  1.27  kiyohara 		PTE_NOCACHE,
    419   1.1  kiyohara 	},
    420   1.1  kiyohara 	{
    421   1.3  kiyohara 		GUMSTIX_STUART_VBASE,
    422   1.3  kiyohara 		_A(PXA2X0_STUART_BASE),
    423   1.3  kiyohara 		_S(4 * COM_NPORTS),
    424  1.27  kiyohara 		VM_PROT_READ | VM_PROT_WRITE,
    425  1.27  kiyohara 		PTE_NOCACHE,
    426   1.3  kiyohara 	},
    427   1.3  kiyohara 	{
    428   1.1  kiyohara 		GUMSTIX_BTUART_VBASE,
    429   1.1  kiyohara 		_A(PXA2X0_BTUART_BASE),
    430   1.1  kiyohara 		_S(4 * COM_NPORTS),
    431  1.27  kiyohara 		VM_PROT_READ | VM_PROT_WRITE,
    432  1.27  kiyohara 		PTE_NOCACHE,
    433   1.1  kiyohara 	},
    434   1.3  kiyohara 	{
    435   1.3  kiyohara 		GUMSTIX_HWUART_VBASE,
    436   1.3  kiyohara 		_A(PXA2X0_HWUART_BASE),
    437   1.3  kiyohara 		_S(4 * COM_NPORTS),
    438  1.27  kiyohara 		VM_PROT_READ | VM_PROT_WRITE,
    439  1.27  kiyohara 		PTE_NOCACHE,
    440   1.3  kiyohara 	},
    441  1.15  kiyohara 	{
    442  1.15  kiyohara 		GUMSTIX_LCDC_VBASE,
    443  1.15  kiyohara 		_A(PXA2X0_LCDC_BASE),
    444  1.15  kiyohara 		_S(4 * COM_NPORTS),
    445  1.27  kiyohara 		VM_PROT_READ | VM_PROT_WRITE,
    446  1.27  kiyohara 		PTE_NOCACHE,
    447  1.27  kiyohara 	},
    448  1.27  kiyohara #elif defined(OVERO)
    449  1.27  kiyohara 	{
    450  1.27  kiyohara 		OVERO_L4_PERIPHERAL_VBASE,
    451  1.27  kiyohara 		_A(OMAP3530_L4_PERIPHERAL_BASE),
    452  1.27  kiyohara 		_S(OMAP3530_L4_PERIPHERAL_SIZE),
    453  1.27  kiyohara 		VM_PROT_READ | VM_PROT_WRITE,
    454  1.27  kiyohara 		PTE_NOCACHE
    455  1.15  kiyohara 	},
    456  1.30  kiyohara 	{
    457  1.30  kiyohara 		OVERO_GPMC_VBASE,
    458  1.30  kiyohara 		_A(GPMC_BASE),
    459  1.30  kiyohara 		_S(GPMC_SIZE),
    460  1.30  kiyohara 		VM_PROT_READ | VM_PROT_WRITE,
    461  1.30  kiyohara 		PTE_NOCACHE
    462  1.30  kiyohara 	},
    463  1.27  kiyohara #endif
    464  1.27  kiyohara 	{ 0, 0, 0, 0, 0 }
    465   1.1  kiyohara };
    466   1.1  kiyohara 
    467   1.1  kiyohara #undef	_A
    468   1.1  kiyohara #undef	_S
    469   1.1  kiyohara 
    470   1.1  kiyohara 
    471   1.1  kiyohara /*
    472   1.1  kiyohara  * u_int initarm(...)
    473   1.1  kiyohara  *
    474   1.1  kiyohara  * Initial entry point on startup. This gets called before main() is
    475   1.1  kiyohara  * entered.
    476   1.1  kiyohara  * It should be responsible for setting up everything that must be
    477   1.1  kiyohara  * in place when main is called.
    478   1.1  kiyohara  * This includes
    479   1.1  kiyohara  *   Taking a copy of the boot configuration structure.
    480   1.1  kiyohara  *   Initialising the physical console so characters can be printed.
    481   1.1  kiyohara  *   Setting up page tables for the kernel
    482   1.1  kiyohara  *   Relocating the kernel to the bottom of physical memory
    483   1.1  kiyohara  */
    484   1.1  kiyohara u_int
    485   1.1  kiyohara initarm(void *arg)
    486   1.1  kiyohara {
    487  1.27  kiyohara #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
    488  1.27  kiyohara #ifdef DIAGNOSTIC
    489  1.27  kiyohara 	extern vsize_t xscale_minidata_clean_size; /* used in KASSERT */
    490  1.27  kiyohara #endif
    491   1.1  kiyohara 	extern vaddr_t xscale_cache_clean_addr;
    492  1.27  kiyohara #endif
    493   1.1  kiyohara 	extern uint32_t *u_boot_args[];
    494  1.15  kiyohara 	extern uint32_t ram_size;
    495  1.15  kiyohara 	enum { r0 = 0, r1 = 1, r2 = 2, r3 = 3 }; /* args from u-boot */
    496   1.1  kiyohara 	int loop;
    497   1.1  kiyohara 	int loop1;
    498   1.1  kiyohara 	u_int l1pagetable;
    499   1.1  kiyohara 	paddr_t memstart;
    500   1.1  kiyohara 	psize_t memsize;
    501  1.27  kiyohara 
    502  1.27  kiyohara 	/*
    503  1.48  kiyohara 	 * We mapped PA == VA in gumstix_start.S.
    504  1.48  kiyohara 	 * Also mapped SDRAM to KERNEL_BASE first 64Mbyte only with cachable.
    505  1.27  kiyohara 	 *
    506  1.27  kiyohara 	 * Gumstix (basix, connex, verdex, verdex-pro):
    507  1.27  kiyohara 	 * Physical Address Range     Description
    508  1.27  kiyohara 	 * -----------------------    ----------------------------------
    509  1.27  kiyohara 	 * 0x00000000 - 0x00ffffff    flash Memory   (16MB or 4MB)
    510  1.27  kiyohara 	 * 0x40000000 - 0x480fffff    Processor Registers
    511  1.27  kiyohara 	 * 0xa0000000 - 0xa3ffffff    SDRAM Bank 0 (64MB or 128MB)
    512  1.48  kiyohara 	 * 0xc0000000 - 0xc3ffffff    KERNEL_BASE
    513  1.27  kiyohara 	 *
    514  1.27  kiyohara 	 * Overo:
    515  1.27  kiyohara 	 * Physical Address Range     Description
    516  1.27  kiyohara 	 * -----------------------    ----------------------------------
    517  1.48  kiyohara 	 * 0x80000000 - 0x8fffffff    SDRAM Bank 0 (256MB, 512MB or 1024MB)
    518  1.48  kiyohara 	 * 0x80000000 - 0x83ffffff    KERNEL_BASE
    519  1.27  kiyohara 	 */
    520  1.27  kiyohara 
    521  1.48  kiyohara #if defined(OVERO)
    522  1.48  kiyohara 	find_cpu_clock();	// find our CPU speed.
    523  1.48  kiyohara #endif
    524  1.48  kiyohara 
    525  1.27  kiyohara 	/*
    526  1.27  kiyohara 	 * Heads up ... Setup the CPU / MMU / TLB functions
    527  1.27  kiyohara 	 */
    528  1.27  kiyohara 	if (set_cpufuncs())
    529  1.27  kiyohara 		panic("cpu not recognized!");
    530   1.1  kiyohara 
    531   1.1  kiyohara 	/* map some peripheral registers at static I/O area */
    532   1.1  kiyohara 	pmap_devmap_bootstrap((vaddr_t)read_ttb(), gumstix_devmap);
    533   1.1  kiyohara 
    534  1.27  kiyohara #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
    535   1.1  kiyohara 	/* start 32.768kHz OSC */
    536  1.12     cliff 	ioreg_write(GUMSTIX_CLKMAN_VBASE + CLKMAN_OSCC, OSCC_OON);
    537   1.1  kiyohara 
    538   1.1  kiyohara 	/* Get ready for splfoo() */
    539   1.1  kiyohara 	pxa2x0_intr_bootstrap(GUMSTIX_INTCTL_VBASE);
    540   1.1  kiyohara 
    541  1.27  kiyohara 	/* setup GPIO for {FF,ST,HW}UART. */
    542  1.27  kiyohara 	pxa2x0_gpio_bootstrap(GUMSTIX_GPIO_VBASE);
    543  1.27  kiyohara 
    544  1.27  kiyohara 	pxa2x0_clkman_bootstrap(GUMSTIX_CLKMAN_VBASE);
    545  1.42      matt #elif defined(CPU_CORTEX)
    546  1.42      matt 	cortex_pmc_ccnt_init();
    547  1.27  kiyohara #endif
    548   1.1  kiyohara 
    549   1.1  kiyohara 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    550   1.1  kiyohara 
    551   1.3  kiyohara 	/* configure GPIOs. */
    552   1.3  kiyohara 	gxio_config_pin();
    553   1.1  kiyohara 
    554  1.21  kiyohara 
    555  1.25  kiyohara #ifndef GUMSTIX_NETBSD_ARGS_CONSOLE
    556   1.1  kiyohara 	consinit();
    557  1.25  kiyohara #endif
    558   1.1  kiyohara #ifdef KGDB
    559   1.1  kiyohara 	kgdb_port_init();
    560   1.1  kiyohara #endif
    561   1.1  kiyohara 
    562  1.46  kiyohara 	/*
    563   1.1  kiyohara 	 * Examine the boot args string for options we need to know about
    564   1.1  kiyohara 	 * now.
    565   1.1  kiyohara 	 */
    566  1.27  kiyohara #if defined(GUMSTIX)
    567  1.15  kiyohara #define SDRAM_START	0xa0000000UL
    568  1.27  kiyohara #elif defined(OVERO)
    569  1.27  kiyohara #define SDRAM_START	0x80000000UL
    570  1.27  kiyohara #endif
    571  1.15  kiyohara 	if (((uint32_t)u_boot_args[r0] & 0xf0000000) != SDRAM_START)
    572  1.15  kiyohara 		/* Maybe r0 is 'argc'.  We are booted by command 'go'. */
    573  1.15  kiyohara 		process_kernel_args((int)u_boot_args[r0],
    574  1.15  kiyohara 		    (char **)u_boot_args[r1]);
    575  1.15  kiyohara 	else
    576  1.15  kiyohara 		/*
    577  1.15  kiyohara 		 * Maybe r3 is 'boot args string' of 'bootm'.  This string is
    578  1.15  kiyohara 		 * linely.
    579  1.15  kiyohara 		 */
    580  1.25  kiyohara 		process_kernel_args_liner((char *)u_boot_args[r3]);
    581  1.25  kiyohara #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
    582  1.25  kiyohara 	consinit();
    583  1.25  kiyohara #endif
    584  1.25  kiyohara 
    585  1.25  kiyohara 	/* Talk to the user */
    586  1.29  kiyohara #define BDSTR(s)	_BDSTR(s)
    587  1.29  kiyohara #define _BDSTR(s)	#s
    588  1.29  kiyohara 	printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
    589  1.25  kiyohara 
    590  1.25  kiyohara 	/* Read system serial */
    591  1.27  kiyohara #if defined(GUMSTIX)
    592  1.25  kiyohara 	read_system_serial();
    593  1.27  kiyohara #endif
    594   1.1  kiyohara 
    595  1.15  kiyohara 	memstart = SDRAM_START;
    596  1.15  kiyohara 	memsize = ram_size;
    597   1.1  kiyohara 
    598   1.6  kiyohara #ifdef VERBOSE_INIT_ARM
    599   1.1  kiyohara 	printf("initarm: Configuring system ...\n");
    600   1.6  kiyohara #endif
    601   1.1  kiyohara 
    602   1.1  kiyohara 	/* Fake bootconfig structure for the benefit of pmap.c */
    603   1.2       wiz 	/* XXX must make the memory description h/w independent */
    604   1.1  kiyohara 	bootconfig.dramblocks = 1;
    605   1.1  kiyohara 	bootconfig.dram[0].address = memstart;
    606   1.1  kiyohara 	bootconfig.dram[0].pages = memsize / PAGE_SIZE;
    607   1.1  kiyohara 
    608   1.1  kiyohara 	/*
    609   1.1  kiyohara 	 * Set up the variables that define the availablilty of
    610   1.1  kiyohara 	 * physical memory.  For now, we're going to set
    611   1.1  kiyohara 	 * physical_freestart to 0xa0200000 (where the kernel
    612   1.1  kiyohara 	 * was loaded), and allocate the memory we need downwards.
    613   1.1  kiyohara 	 * If we get too close to the L1 table that we set up, we
    614   1.1  kiyohara 	 * will panic.  We will update physical_freestart and
    615   1.1  kiyohara 	 * physical_freeend later to reflect what pmap_bootstrap()
    616   1.1  kiyohara 	 * wants to see.
    617   1.1  kiyohara 	 *
    618   1.1  kiyohara 	 * XXX pmap_bootstrap() needs an enema.
    619   1.1  kiyohara 	 */
    620   1.1  kiyohara 	physical_start = bootconfig.dram[0].address;
    621   1.6  kiyohara 	physical_end = physical_start + memsize;
    622   1.1  kiyohara 
    623  1.27  kiyohara #if defined(GUMSTIX)
    624   1.1  kiyohara 	physical_freestart = 0xa0009000UL;
    625   1.1  kiyohara 	physical_freeend = 0xa0200000UL;
    626  1.27  kiyohara #elif defined(OVERO)
    627  1.27  kiyohara 	physical_freestart = 0x80009000UL;
    628  1.27  kiyohara 	physical_freeend = 0x80200000UL;
    629  1.27  kiyohara #endif
    630   1.1  kiyohara 
    631   1.1  kiyohara 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    632   1.1  kiyohara 
    633   1.1  kiyohara #ifdef VERBOSE_INIT_ARM
    634   1.1  kiyohara 	/* Tell the user about the memory */
    635   1.1  kiyohara 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    636   1.1  kiyohara 	    physical_start, physical_end - 1);
    637   1.1  kiyohara #endif
    638   1.1  kiyohara 
    639   1.1  kiyohara 	/*
    640   1.1  kiyohara 	 * Okay, the kernel starts 2MB in from the bottom of physical
    641   1.1  kiyohara 	 * memory.  We are going to allocate our bootstrap pages downwards
    642   1.1  kiyohara 	 * from there.
    643   1.1  kiyohara 	 *
    644   1.1  kiyohara 	 * We need to allocate some fixed page tables to get the kernel
    645   1.1  kiyohara 	 * going.  We allocate one page directory and a number of page
    646   1.1  kiyohara 	 * tables and store the physical addresses in the kernel_pt_table
    647   1.1  kiyohara 	 * array.
    648   1.1  kiyohara 	 *
    649   1.1  kiyohara 	 * The kernel page directory must be on a 16K boundary.  The page
    650   1.1  kiyohara 	 * tables must be on 4K bounaries.  What we do is allocate the
    651   1.1  kiyohara 	 * page directory on the first 16K boundary that we encounter, and
    652   1.1  kiyohara 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    653   1.1  kiyohara 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    654   1.1  kiyohara 	 * least one 16K aligned region.
    655   1.1  kiyohara 	 */
    656   1.1  kiyohara 
    657   1.1  kiyohara #ifdef VERBOSE_INIT_ARM
    658   1.1  kiyohara 	printf("Allocating page tables\n");
    659   1.1  kiyohara #endif
    660   1.1  kiyohara 
    661   1.1  kiyohara 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    662   1.1  kiyohara 
    663   1.1  kiyohara #ifdef VERBOSE_INIT_ARM
    664   1.1  kiyohara 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    665  1.46  kiyohara 	    physical_freestart, free_pages, free_pages);
    666   1.1  kiyohara #endif
    667   1.1  kiyohara 
    668   1.1  kiyohara 	/* Define a macro to simplify memory allocation */
    669   1.1  kiyohara #define	valloc_pages(var, np)				\
    670   1.1  kiyohara 	alloc_pages((var).pv_pa, (np));			\
    671   1.1  kiyohara 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    672   1.1  kiyohara 
    673   1.1  kiyohara #define alloc_pages(var, np)				\
    674   1.1  kiyohara 	physical_freeend -= ((np) * PAGE_SIZE);		\
    675   1.1  kiyohara 	if (physical_freeend < physical_freestart)	\
    676   1.1  kiyohara 		panic("initarm: out of memory");	\
    677   1.1  kiyohara 	(var) = physical_freeend;			\
    678   1.1  kiyohara 	free_pages -= (np);				\
    679   1.1  kiyohara 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    680   1.1  kiyohara 
    681   1.1  kiyohara 	loop1 = 0;
    682   1.1  kiyohara 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    683   1.1  kiyohara 		/* Are we 16KB aligned for an L1 ? */
    684   1.6  kiyohara 		if ((physical_freeend & (L1_TABLE_SIZE - 1)) == 0 &&
    685   1.6  kiyohara 		    kernel_l1pt.pv_pa == 0) {
    686   1.1  kiyohara 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    687   1.1  kiyohara 		} else {
    688   1.1  kiyohara 			valloc_pages(kernel_pt_table[loop1],
    689   1.1  kiyohara 			    L2_TABLE_SIZE / PAGE_SIZE);
    690   1.1  kiyohara 			++loop1;
    691   1.1  kiyohara 		}
    692   1.1  kiyohara 	}
    693   1.1  kiyohara 
    694   1.1  kiyohara 	/* This should never be able to happen but better confirm that. */
    695   1.1  kiyohara 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    696   1.1  kiyohara 		panic("initarm: Failed to align the kernel page directory");
    697   1.1  kiyohara 
    698   1.1  kiyohara 	/*
    699   1.1  kiyohara 	 * Allocate a page for the system page mapped to V0x00000000
    700   1.1  kiyohara 	 * This page will just contain the system vectors and can be
    701   1.1  kiyohara 	 * shared by all processes.
    702   1.1  kiyohara 	 */
    703   1.1  kiyohara 	alloc_pages(systempage.pv_pa, 1);
    704  1.27  kiyohara #if defined(CPU_CORTEXA8)
    705  1.27  kiyohara 	systempage.pv_va = ARM_VECTORS_HIGH;
    706  1.27  kiyohara #endif
    707   1.1  kiyohara 
    708   1.1  kiyohara 	/* Allocate stacks for all modes */
    709   1.1  kiyohara 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    710   1.1  kiyohara 	valloc_pages(abtstack, ABT_STACK_SIZE);
    711   1.1  kiyohara 	valloc_pages(undstack, UND_STACK_SIZE);
    712   1.1  kiyohara 	valloc_pages(kernelstack, UPAGES);
    713   1.1  kiyohara 
    714   1.1  kiyohara 	/* Allocate enough pages for cleaning the Mini-Data cache. */
    715  1.27  kiyohara #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
    716   1.1  kiyohara 	KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
    717  1.27  kiyohara #endif
    718   1.1  kiyohara 	valloc_pages(minidataclean, 1);
    719   1.1  kiyohara 
    720   1.1  kiyohara #ifdef VERBOSE_INIT_ARM
    721   1.1  kiyohara 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    722  1.17  kiyohara 	    irqstack.pv_va);
    723   1.1  kiyohara 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    724  1.17  kiyohara 	    abtstack.pv_va);
    725   1.1  kiyohara 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    726  1.17  kiyohara 	    undstack.pv_va);
    727   1.1  kiyohara 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    728  1.17  kiyohara 	    kernelstack.pv_va);
    729   1.1  kiyohara #endif
    730   1.1  kiyohara 
    731   1.1  kiyohara 	/*
    732   1.1  kiyohara 	 * XXX Defer this to later so that we can reclaim the memory
    733   1.1  kiyohara 	 * XXX used by the RedBoot page tables.
    734   1.1  kiyohara 	 */
    735   1.1  kiyohara 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    736   1.1  kiyohara 
    737   1.1  kiyohara 	/*
    738   1.1  kiyohara 	 * Ok we have allocated physical pages for the primary kernel
    739   1.1  kiyohara 	 * page tables
    740   1.1  kiyohara 	 */
    741   1.1  kiyohara 
    742   1.1  kiyohara #ifdef VERBOSE_INIT_ARM
    743   1.1  kiyohara 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    744   1.1  kiyohara #endif
    745   1.1  kiyohara 
    746   1.1  kiyohara 	/*
    747   1.1  kiyohara 	 * Now we start construction of the L1 page table
    748   1.1  kiyohara 	 * We start by mapping the L2 page tables into the L1.
    749   1.1  kiyohara 	 * This means that we can replace L1 mappings later on if necessary
    750   1.1  kiyohara 	 */
    751   1.1  kiyohara 	l1pagetable = kernel_l1pt.pv_va;
    752   1.1  kiyohara 
    753   1.1  kiyohara 	/* Map the L2 pages tables in the L1 page table */
    754  1.27  kiyohara #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
    755   1.1  kiyohara 	pmap_link_l2pt(l1pagetable, 0x00000000,
    756   1.1  kiyohara 	    &kernel_pt_table[KERNEL_PT_SYS]);
    757  1.27  kiyohara #elif defined(CPU_CORTEXA8)
    758  1.27  kiyohara 	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
    759  1.27  kiyohara 	    &kernel_pt_table[KERNEL_PT_SYS]);
    760  1.27  kiyohara #endif
    761   1.1  kiyohara 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    762   1.1  kiyohara 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    763   1.1  kiyohara 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    764   1.1  kiyohara 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    765   1.1  kiyohara 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    766   1.1  kiyohara 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    767   1.1  kiyohara 
    768   1.1  kiyohara 	/* update the top of the kernel VM */
    769   1.1  kiyohara 	pmap_curmaxkvaddr =
    770   1.1  kiyohara 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    771   1.1  kiyohara 
    772   1.1  kiyohara #ifdef VERBOSE_INIT_ARM
    773   1.1  kiyohara 	printf("Mapping kernel\n");
    774   1.1  kiyohara #endif
    775   1.1  kiyohara 
    776   1.1  kiyohara 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    777   1.1  kiyohara 	{
    778   1.1  kiyohara 		extern char etext[], _end[];
    779   1.1  kiyohara 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    780   1.1  kiyohara 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    781   1.1  kiyohara 		u_int logical;
    782   1.1  kiyohara 
    783   1.1  kiyohara 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    784   1.1  kiyohara 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    785  1.27  kiyohara 
    786   1.1  kiyohara 		logical = 0x00200000;	/* offset of kernel in RAM */
    787   1.1  kiyohara 
    788   1.1  kiyohara 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    789   1.1  kiyohara 		    physical_start + logical, textsize,
    790   1.1  kiyohara 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    791   1.1  kiyohara 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    792   1.1  kiyohara 		    physical_start + logical, totalsize - textsize,
    793   1.1  kiyohara 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    794   1.1  kiyohara 	}
    795   1.1  kiyohara 
    796   1.1  kiyohara #ifdef VERBOSE_INIT_ARM
    797   1.1  kiyohara 	printf("Constructing L2 page tables\n");
    798   1.1  kiyohara #endif
    799   1.1  kiyohara 
    800   1.1  kiyohara 	/* Map the stack pages */
    801   1.1  kiyohara 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    802   1.1  kiyohara 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    803   1.1  kiyohara 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    804   1.1  kiyohara 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    805   1.1  kiyohara 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    806   1.1  kiyohara 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    807   1.1  kiyohara 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    808   1.1  kiyohara 	    UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    809   1.1  kiyohara 
    810   1.1  kiyohara 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    811   1.1  kiyohara 	    L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
    812   1.1  kiyohara 
    813   1.1  kiyohara 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    814   1.1  kiyohara 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    815   1.1  kiyohara 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    816   1.1  kiyohara 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    817   1.1  kiyohara 	}
    818   1.1  kiyohara 
    819   1.1  kiyohara 	/* Map the Mini-Data cache clean area. */
    820  1.27  kiyohara #if defined(GUMSTIX)
    821   1.1  kiyohara 	xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
    822   1.1  kiyohara 	    minidataclean.pv_pa);
    823  1.27  kiyohara #endif
    824   1.1  kiyohara 
    825   1.1  kiyohara 	/* Map the vector page. */
    826  1.27  kiyohara #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
    827   1.1  kiyohara #if 1
    828   1.1  kiyohara 	/* MULTI-ICE requires that page 0 is NC/NB so that it can download the
    829   1.1  kiyohara 	 * cache-clean code there.  */
    830   1.1  kiyohara 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    831   1.1  kiyohara 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    832   1.1  kiyohara #else
    833   1.1  kiyohara 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    834   1.1  kiyohara 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    835   1.1  kiyohara #endif
    836  1.27  kiyohara #elif defined(CPU_CORTEXA8)
    837  1.27  kiyohara 	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
    838  1.27  kiyohara 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    839  1.27  kiyohara #endif
    840   1.1  kiyohara 
    841   1.1  kiyohara 	/*
    842   1.1  kiyohara 	 * map integrated peripherals at same address in l1pagetable
    843   1.1  kiyohara 	 * so that we can continue to use console.
    844   1.1  kiyohara 	 */
    845   1.1  kiyohara 	pmap_devmap_bootstrap(l1pagetable, gumstix_devmap);
    846   1.1  kiyohara 
    847  1.27  kiyohara #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
    848   1.1  kiyohara 	/*
    849   1.1  kiyohara 	 * Give the XScale global cache clean code an appropriately
    850   1.1  kiyohara 	 * sized chunk of unmapped VA space starting at 0xff000000
    851   1.1  kiyohara 	 * (our device mappings end before this address).
    852   1.1  kiyohara 	 */
    853   1.1  kiyohara 	xscale_cache_clean_addr = 0xff000000U;
    854  1.27  kiyohara #endif
    855   1.1  kiyohara 
    856   1.1  kiyohara 	/*
    857   1.1  kiyohara 	 * Now we have the real page tables in place so we can switch to them.
    858   1.1  kiyohara 	 * Once this is done we will be running with the REAL kernel page
    859   1.1  kiyohara 	 * tables.
    860   1.1  kiyohara 	 */
    861   1.1  kiyohara 
    862   1.1  kiyohara 	/*
    863   1.1  kiyohara 	 * Update the physical_freestart/physical_freeend/free_pages
    864   1.1  kiyohara 	 * variables.
    865   1.1  kiyohara 	 */
    866   1.1  kiyohara 	{
    867   1.1  kiyohara 		extern char _end[];
    868   1.1  kiyohara 
    869   1.1  kiyohara 		physical_freestart = physical_start +
    870   1.1  kiyohara 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    871   1.1  kiyohara 		     KERNEL_BASE);
    872   1.1  kiyohara 		physical_freeend = physical_end;
    873   1.1  kiyohara 		free_pages =
    874   1.1  kiyohara 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    875   1.1  kiyohara 	}
    876   1.1  kiyohara 
    877   1.1  kiyohara 	/* Switch tables */
    878   1.1  kiyohara #ifdef VERBOSE_INIT_ARM
    879   1.1  kiyohara 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    880  1.46  kiyohara 	    physical_freestart, free_pages, free_pages);
    881   1.1  kiyohara 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    882   1.1  kiyohara #endif
    883   1.1  kiyohara 
    884  1.43      matt 	cpu_setttb(kernel_l1pt.pv_pa, true);
    885   1.1  kiyohara 	cpu_tlb_flushID();
    886   1.1  kiyohara 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    887   1.1  kiyohara 
    888   1.1  kiyohara 	/*
    889   1.1  kiyohara 	 * Moved from cpu_startup() as data_abort_handler() references
    890   1.1  kiyohara 	 * this during uvm init
    891   1.1  kiyohara 	 */
    892  1.20     rmind 	uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
    893   1.1  kiyohara 
    894   1.1  kiyohara #ifdef VERBOSE_INIT_ARM
    895   1.1  kiyohara 	printf("bootstrap done.\n");
    896   1.1  kiyohara #endif
    897   1.1  kiyohara 
    898  1.27  kiyohara #if defined(CPU_XSCALE_PXA250) || defined(CPU_XSCALE_PXA270)
    899   1.1  kiyohara 	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
    900  1.27  kiyohara #elif defined(CPU_CORTEXA8)
    901  1.27  kiyohara 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    902  1.27  kiyohara #endif
    903   1.1  kiyohara 
    904   1.1  kiyohara 	/*
    905   1.1  kiyohara 	 * Pages were allocated during the secondary bootstrap for the
    906   1.1  kiyohara 	 * stacks for different CPU modes.
    907   1.1  kiyohara 	 * We must now set the r13 registers in the different CPU modes to
    908   1.1  kiyohara 	 * point to these stacks.
    909   1.1  kiyohara 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    910   1.1  kiyohara 	 * of the stack memory.
    911   1.1  kiyohara 	 */
    912   1.1  kiyohara #ifdef	VERBOSE_INIT_ARM
    913   1.1  kiyohara 	printf("init subsystems: stacks ");
    914   1.1  kiyohara #endif
    915   1.1  kiyohara 
    916   1.1  kiyohara 	set_stackptr(PSR_IRQ32_MODE,
    917   1.1  kiyohara 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    918   1.1  kiyohara 	set_stackptr(PSR_ABT32_MODE,
    919   1.1  kiyohara 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    920   1.1  kiyohara 	set_stackptr(PSR_UND32_MODE,
    921   1.1  kiyohara 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    922   1.1  kiyohara 
    923   1.1  kiyohara 	/*
    924   1.1  kiyohara 	 * Well we should set a data abort handler.
    925   1.1  kiyohara 	 * Once things get going this will change as we will need a proper
    926   1.1  kiyohara 	 * handler.
    927   1.1  kiyohara 	 * Until then we will use a handler that just panics but tells us
    928   1.1  kiyohara 	 * why.
    929   1.1  kiyohara 	 * Initialisation of the vectors will just panic on a data abort.
    930   1.1  kiyohara 	 * This just fills in a slighly better one.
    931   1.1  kiyohara 	 */
    932   1.1  kiyohara #ifdef	VERBOSE_INIT_ARM
    933   1.1  kiyohara 	printf("vectors ");
    934   1.1  kiyohara #endif
    935   1.1  kiyohara 	data_abort_handler_address = (u_int)data_abort_handler;
    936   1.1  kiyohara 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    937   1.1  kiyohara 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    938   1.1  kiyohara 
    939   1.1  kiyohara 	/* Initialise the undefined instruction handlers */
    940   1.1  kiyohara #ifdef	VERBOSE_INIT_ARM
    941   1.1  kiyohara 	printf("undefined ");
    942   1.1  kiyohara #endif
    943   1.1  kiyohara 	undefined_init();
    944   1.1  kiyohara 
    945   1.1  kiyohara 	/* Load memory into UVM. */
    946   1.1  kiyohara #ifdef	VERBOSE_INIT_ARM
    947   1.1  kiyohara 	printf("page ");
    948   1.1  kiyohara #endif
    949   1.1  kiyohara 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    950   1.1  kiyohara 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    951   1.1  kiyohara 	    atop(physical_freestart), atop(physical_freeend),
    952   1.1  kiyohara 	    VM_FREELIST_DEFAULT);
    953   1.1  kiyohara 
    954   1.1  kiyohara 	/* Boot strap pmap telling it where the kernel page table is */
    955   1.1  kiyohara #ifdef	VERBOSE_INIT_ARM
    956   1.1  kiyohara 	printf("pmap ");
    957   1.1  kiyohara #endif
    958   1.9      matt 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    959   1.1  kiyohara 
    960   1.1  kiyohara #ifdef __HAVE_MEMORY_DISK__
    961   1.1  kiyohara 	md_root_setconf(memory_disk, sizeof memory_disk);
    962   1.1  kiyohara #endif
    963   1.1  kiyohara 
    964   1.1  kiyohara #ifdef BOOTHOWTO
    965   1.1  kiyohara 	boothowto |= BOOTHOWTO;
    966   1.1  kiyohara #endif
    967   1.1  kiyohara 
    968   1.1  kiyohara #ifdef KGDB
    969   1.1  kiyohara 	if (boothowto & RB_KDB) {
    970   1.1  kiyohara 		kgdb_debug_init = 1;
    971   1.1  kiyohara 		kgdb_connect(1);
    972   1.1  kiyohara 	}
    973   1.1  kiyohara #endif
    974   1.1  kiyohara 
    975  1.11        ad #if NKSYMS || defined(DDB) || defined(MODULAR)
    976   1.1  kiyohara 	/* Firmware doesn't load symbols. */
    977   1.1  kiyohara 	ddb_init(0, NULL, NULL);
    978   1.6  kiyohara #endif
    979   1.1  kiyohara 
    980   1.6  kiyohara #ifdef DDB
    981   1.6  kiyohara 	db_machine_init();
    982   1.1  kiyohara 	if (boothowto & RB_KDB)
    983   1.1  kiyohara 		Debugger();
    984   1.1  kiyohara #endif
    985   1.1  kiyohara 
    986  1.28  kiyohara 	/* We have our own device_register() */
    987  1.28  kiyohara 	evbarm_device_register = gumstix_device_register;
    988  1.28  kiyohara 
    989   1.1  kiyohara 	/* We return the new stack pointer address */
    990   1.1  kiyohara 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    991   1.1  kiyohara }
    992   1.1  kiyohara 
    993  1.27  kiyohara #if defined(GUMSTIX)
    994   1.3  kiyohara static void
    995  1.14    cegger read_system_serial(void)
    996   1.1  kiyohara {
    997   1.1  kiyohara #define GUMSTIX_SYSTEM_SERIAL_ADDR	0
    998   1.1  kiyohara #define GUMSTIX_SYSTEM_SERIAL_SIZE	8
    999   1.1  kiyohara #define FLASH_OFFSET_INTEL_PROTECTION	0x81
   1000   1.1  kiyohara #define FLASH_OFFSET_USER_PROTECTION	0x85
   1001   1.1  kiyohara #define FLASH_CMD_READ_ID		0x90
   1002   1.1  kiyohara #define FLASH_CMD_RESET			0xff
   1003   1.1  kiyohara 	int i;
   1004   1.1  kiyohara 	char system_serial[GUMSTIX_SYSTEM_SERIAL_SIZE], *src;
   1005   1.1  kiyohara 	char x;
   1006   1.1  kiyohara 
   1007   1.1  kiyohara 	src = (char *)(FLASH_OFFSET_USER_PROTECTION * 2 /*word*/);
   1008   1.1  kiyohara 	*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
   1009   1.1  kiyohara 	memcpy(system_serial,
   1010   1.1  kiyohara 	    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
   1011   1.1  kiyohara 	*(volatile uint16_t *)0 = FLASH_CMD_RESET;
   1012   1.1  kiyohara 
   1013   1.1  kiyohara 	for (i = 1, x = system_serial[0]; i < sizeof (system_serial); i++)
   1014   1.1  kiyohara 		x &= system_serial[i];
   1015   1.1  kiyohara 	if (x == 0xff) {
   1016   1.1  kiyohara 		src = (char *)(FLASH_OFFSET_INTEL_PROTECTION * 2 /*word*/);
   1017   1.1  kiyohara 		*(volatile uint16_t *)0 = FLASH_CMD_READ_ID;
   1018   1.1  kiyohara 		memcpy(system_serial,
   1019   1.1  kiyohara 		    src + GUMSTIX_SYSTEM_SERIAL_ADDR, sizeof (system_serial));
   1020   1.1  kiyohara 		*(volatile uint16_t *)0 = FLASH_CMD_RESET;
   1021   1.1  kiyohara 
   1022   1.1  kiyohara 		/*
   1023   1.1  kiyohara 		 * XXXX: Don't need ???
   1024   1.1  kiyohara 		 * gumstix_serial_hash(system_serial);
   1025   1.1  kiyohara 		 */
   1026   1.1  kiyohara 	}
   1027   1.1  kiyohara 	system_serial_high = system_serial[0] << 24 | system_serial[1] << 16 |
   1028   1.1  kiyohara 	    system_serial[2] << 8 | system_serial[3];
   1029   1.1  kiyohara 	system_serial_low = system_serial[4] << 24 | system_serial[5] << 16 |
   1030   1.1  kiyohara 	    system_serial[6] << 8 | system_serial[7];
   1031   1.1  kiyohara 
   1032   1.1  kiyohara 	printf("system serial: 0x");
   1033   1.1  kiyohara 	for (i = 0; i < sizeof (system_serial); i++)
   1034   1.1  kiyohara 		printf("%02x", system_serial[i]);
   1035   1.1  kiyohara 	printf("\n");
   1036   1.1  kiyohara }
   1037  1.48  kiyohara #elif defined(OVERO)
   1038  1.48  kiyohara static void
   1039  1.48  kiyohara find_cpu_clock(void)
   1040  1.48  kiyohara {
   1041  1.48  kiyohara 	const vaddr_t prm_base = OMAP2_PRM_BASE;
   1042  1.48  kiyohara 	const vaddr_t cm_base = OMAP2_CM_BASE;
   1043  1.48  kiyohara 	const uint32_t prm_clksel =
   1044  1.48  kiyohara 	    *(volatile uint32_t *)(prm_base + PLL_MOD + OMAP3_PRM_CLKSEL);
   1045  1.48  kiyohara 	static const uint32_t prm_clksel_freqs[] = OMAP3_PRM_CLKSEL_FREQS;
   1046  1.48  kiyohara 	const uint32_t sys_clk =
   1047  1.48  kiyohara 	    prm_clksel_freqs[__SHIFTOUT(prm_clksel, OMAP3_PRM_CLKSEL_CLKIN)];
   1048  1.48  kiyohara 	const uint32_t dpll1 =
   1049  1.48  kiyohara 	    *(volatile uint32_t *)(cm_base + OMAP3_CM_CLKSEL1_PLL_MPU);
   1050  1.48  kiyohara 	const uint32_t dpll2 =
   1051  1.48  kiyohara 	    *(volatile uint32_t *)(cm_base + OMAP3_CM_CLKSEL2_PLL_MPU);
   1052  1.48  kiyohara 	const uint32_t m =
   1053  1.48  kiyohara 	    __SHIFTOUT(dpll1, OMAP3_CM_CLKSEL1_PLL_MPU_DPLL_MULT);
   1054  1.48  kiyohara 	const uint32_t n = __SHIFTOUT(dpll1, OMAP3_CM_CLKSEL1_PLL_MPU_DPLL_DIV);
   1055  1.48  kiyohara 	const uint32_t m2 =
   1056  1.48  kiyohara 	    __SHIFTOUT(dpll2, OMAP3_CM_CLKSEL2_PLL_MPU_DPLL_CLKOUT_DIV);
   1057  1.48  kiyohara 
   1058  1.48  kiyohara 	/*
   1059  1.48  kiyohara 	 * MPU_CLK supplies ARM_FCLK which is twice the CPU frequency.
   1060  1.48  kiyohara 	 */
   1061  1.48  kiyohara 	curcpu()->ci_data.cpu_cc_freq =
   1062  1.48  kiyohara 	    ((sys_clk * m) / ((n + 1) * m2 * 2)) * OMAP3_PRM_CLKSEL_MULT;
   1063  1.48  kiyohara 	omap_sys_clk = sys_clk * OMAP3_PRM_CLKSEL_MULT;
   1064  1.48  kiyohara }
   1065  1.27  kiyohara #endif
   1066   1.1  kiyohara 
   1067  1.25  kiyohara #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
   1068  1.15  kiyohara static const char busheader_name[] = "busheader=";
   1069  1.25  kiyohara #endif
   1070  1.30  kiyohara #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
   1071  1.30  kiyohara     defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
   1072  1.30  kiyohara static const char expansion_name[] = "expansion=";
   1073  1.30  kiyohara #endif
   1074  1.25  kiyohara #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
   1075  1.25  kiyohara static const char console_name[] = "console=";
   1076  1.25  kiyohara #endif
   1077   1.3  kiyohara static void
   1078   1.1  kiyohara process_kernel_args(int argc, char *argv[])
   1079   1.1  kiyohara {
   1080   1.5  kiyohara 	int gxio_configured = 0, i, j;
   1081   1.1  kiyohara 
   1082   1.1  kiyohara 	boothowto = 0;
   1083   1.1  kiyohara 
   1084   1.1  kiyohara 	for (i = 1, j = 0; i < argc; i++) {
   1085  1.25  kiyohara #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
   1086   1.1  kiyohara 		if (!strncmp(argv[i], busheader_name, strlen(busheader_name))) {
   1087  1.30  kiyohara 			/* Configure for GPIOs of busheader side */
   1088   1.5  kiyohara 			gxio_config_expansion(argv[i] + strlen(busheader_name));
   1089   1.5  kiyohara 			gxio_configured = 1;
   1090   1.1  kiyohara 			continue;
   1091   1.1  kiyohara 		}
   1092  1.25  kiyohara #endif
   1093  1.30  kiyohara #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
   1094  1.30  kiyohara     defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
   1095  1.30  kiyohara 		if (!strncmp(argv[i], expansion_name, strlen(expansion_name))) {
   1096  1.30  kiyohara 			/* Configure expansion */
   1097  1.30  kiyohara 			gxio_config_expansion(argv[i] + strlen(expansion_name));
   1098  1.30  kiyohara 			gxio_configured = 1;
   1099  1.30  kiyohara 			continue;
   1100  1.30  kiyohara 		}
   1101  1.30  kiyohara #endif
   1102  1.25  kiyohara #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
   1103  1.25  kiyohara 		if (!strncmp(argv[i], console_name, strlen(console_name))) {
   1104  1.25  kiyohara 			strncpy(console, argv[i] + strlen(console_name),
   1105  1.25  kiyohara 			    sizeof(console));
   1106  1.25  kiyohara 			consinit();
   1107  1.25  kiyohara 		}
   1108  1.25  kiyohara #endif
   1109  1.38       mrg 		if (j == bootargs_len) {
   1110   1.1  kiyohara 			*(bootargs + j) = '\0';
   1111   1.1  kiyohara 			continue;
   1112   1.1  kiyohara 		}
   1113   1.1  kiyohara 		if (j != 0)
   1114   1.1  kiyohara 			*(bootargs + j++) = ' ';
   1115  1.38       mrg 		strncpy(bootargs + j, argv[i], bootargs_len - j);
   1116  1.38       mrg 		bootargs[bootargs_len] = '\0';
   1117   1.1  kiyohara 		j += strlen(argv[i]);
   1118   1.1  kiyohara 	}
   1119   1.1  kiyohara 	boot_args = bootargs;
   1120   1.1  kiyohara 
   1121   1.1  kiyohara 	parse_mi_bootargs(boot_args);
   1122   1.5  kiyohara 
   1123   1.5  kiyohara 	if (!gxio_configured)
   1124   1.5  kiyohara 		gxio_config_expansion(NULL);
   1125   1.1  kiyohara }
   1126   1.1  kiyohara 
   1127  1.15  kiyohara static void
   1128  1.25  kiyohara process_kernel_args_liner(char *args)
   1129  1.15  kiyohara {
   1130  1.30  kiyohara 	int i = 0;
   1131  1.25  kiyohara 	char *p = NULL;
   1132  1.15  kiyohara 
   1133  1.15  kiyohara 	boothowto = 0;
   1134  1.15  kiyohara 
   1135  1.15  kiyohara 	strncpy(bootargs, args, sizeof(bootargs));
   1136  1.30  kiyohara #if defined(GUMSTIX_NETBSD_ARGS_BUSHEADER) || \
   1137  1.30  kiyohara     defined(GUMSTIX_NETBSD_ARGS_EXPANSION)
   1138  1.30  kiyohara 	{
   1139  1.30  kiyohara 		char *q;
   1140  1.30  kiyohara 
   1141  1.30  kiyohara 		if ((p = strstr(bootargs, expansion_name)))
   1142  1.30  kiyohara 			q = p + strlen(expansion_name);
   1143  1.25  kiyohara #ifdef GUMSTIX_NETBSD_ARGS_BUSHEADER
   1144  1.31  kiyohara 		else if ((p = strstr(bootargs, busheader_name)))
   1145  1.30  kiyohara 			q = p + strlen(busheader_name);
   1146  1.30  kiyohara #endif
   1147  1.30  kiyohara 		if (p) {
   1148  1.30  kiyohara 			char expansion[256], c;
   1149  1.25  kiyohara 
   1150  1.30  kiyohara 			i = 0;
   1151  1.30  kiyohara 			do {
   1152  1.30  kiyohara 				c = *(q + i);
   1153  1.30  kiyohara 				if (c == ' ')
   1154  1.30  kiyohara 					c = '\0';
   1155  1.30  kiyohara 				expansion[i++] = c;
   1156  1.30  kiyohara 			} while (c != '\0' && i < sizeof(expansion));
   1157  1.30  kiyohara 			gxio_config_expansion(expansion);
   1158  1.30  kiyohara 			strcpy(p, q + i);
   1159  1.30  kiyohara 		}
   1160  1.15  kiyohara 	}
   1161  1.25  kiyohara #endif
   1162  1.27  kiyohara 	if (p == NULL)
   1163  1.25  kiyohara 		gxio_config_expansion(NULL);
   1164  1.25  kiyohara #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
   1165  1.25  kiyohara 	p = strstr(bootargs, console_name);
   1166  1.25  kiyohara 	if (p != NULL) {
   1167  1.25  kiyohara 		char c;
   1168  1.25  kiyohara 
   1169  1.30  kiyohara 		i = 0;
   1170  1.25  kiyohara 		do {
   1171  1.25  kiyohara 			c = *(p + strlen(console_name) + i);
   1172  1.25  kiyohara 			if (c == ' ')
   1173  1.25  kiyohara 				c = '\0';
   1174  1.25  kiyohara 			console[i++] = c;
   1175  1.25  kiyohara 		} while (c != '\0' && i < sizeof(console));
   1176  1.25  kiyohara 		consinit();
   1177  1.30  kiyohara 		strcpy(p, p + strlen(console_name) + i);
   1178  1.25  kiyohara 	}
   1179  1.25  kiyohara #endif
   1180  1.15  kiyohara 	boot_args = bootargs;
   1181  1.15  kiyohara 
   1182  1.15  kiyohara 	parse_mi_bootargs(boot_args);
   1183  1.15  kiyohara }
   1184  1.15  kiyohara 
   1185   1.1  kiyohara #ifdef KGDB
   1186   1.1  kiyohara #ifndef KGDB_DEVNAME
   1187   1.6  kiyohara #define KGDB_DEVNAME	"ffuart"
   1188   1.1  kiyohara #endif
   1189   1.1  kiyohara const char kgdb_devname[] = KGDB_DEVNAME;
   1190   1.1  kiyohara 
   1191   1.6  kiyohara #ifndef KGDB_DEVRATE
   1192   1.6  kiyohara #define KGDB_DEVRATE	CONSPEED
   1193   1.6  kiyohara #endif
   1194   1.6  kiyohara int kgdb_devrate = KGDB_DEVRATE;
   1195   1.6  kiyohara 
   1196   1.1  kiyohara #if (NCOM > 0)
   1197   1.1  kiyohara #ifndef KGDB_DEVMODE
   1198   1.6  kiyohara #define KGDB_DEVMODE	CONMODE
   1199   1.1  kiyohara #endif
   1200   1.1  kiyohara int comkgdbmode = KGDB_DEVMODE;
   1201   1.1  kiyohara #endif /* NCOM */
   1202   1.1  kiyohara 
   1203   1.1  kiyohara #endif /* KGDB */
   1204   1.1  kiyohara 
   1205   1.1  kiyohara 
   1206   1.1  kiyohara void
   1207   1.1  kiyohara consinit(void)
   1208   1.1  kiyohara {
   1209   1.1  kiyohara 	static int consinit_called = 0;
   1210   1.1  kiyohara 
   1211   1.1  kiyohara 	if (consinit_called != 0)
   1212   1.1  kiyohara 		return;
   1213   1.1  kiyohara 
   1214   1.1  kiyohara 	consinit_called = 1;
   1215   1.1  kiyohara 
   1216   1.1  kiyohara #if NCOM > 0
   1217   1.1  kiyohara 
   1218  1.33  kiyohara #ifdef GUMSTIX_NETBSD_ARGS_CONSOLE
   1219  1.33  kiyohara 	/* Maybe passed Linux's bootargs 'console=ttyS?,<speed>...' */
   1220  1.33  kiyohara 	if (strncmp(console, "ttyS", 4) == 0 && console[5] == ',') {
   1221  1.33  kiyohara 		int i;
   1222  1.33  kiyohara 
   1223  1.33  kiyohara 		comcnspeed = 0;
   1224  1.33  kiyohara 		for (i = 6; i < strlen(console) && isdigit(console[i]); i++)
   1225  1.33  kiyohara 			comcnspeed = comcnspeed * 10 + (console[i] - '0');
   1226  1.33  kiyohara 	}
   1227  1.33  kiyohara #endif
   1228  1.33  kiyohara 
   1229  1.27  kiyohara #if defined(GUMSTIX)
   1230  1.27  kiyohara 
   1231   1.1  kiyohara #ifdef FFUARTCONSOLE
   1232   1.1  kiyohara #ifdef KGDB
   1233  1.25  kiyohara 	if (strcmp(kgdb_devname, "ffuart") == 0){
   1234   1.1  kiyohara 		/* port is reserved for kgdb */
   1235  1.17  kiyohara 	} else
   1236   1.1  kiyohara #endif
   1237  1.25  kiyohara #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
   1238  1.33  kiyohara 	if (console[0] == '\0' || strcasecmp(console, "ffuart") == 0 ||
   1239  1.33  kiyohara 	    strncmp(console, "ttyS0,", 6) == 0)
   1240  1.25  kiyohara #endif
   1241   1.3  kiyohara 	{
   1242  1.27  kiyohara 		int rv;
   1243  1.27  kiyohara 
   1244  1.25  kiyohara 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_FFUART_BASE,
   1245  1.25  kiyohara 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
   1246  1.25  kiyohara 		if (rv == 0) {
   1247  1.21  kiyohara 			pxa2x0_clkman_config(CKEN_FFUART, 1);
   1248   1.3  kiyohara 			return;
   1249   1.3  kiyohara 		}
   1250   1.1  kiyohara 	}
   1251   1.1  kiyohara #endif /* FFUARTCONSOLE */
   1252   1.1  kiyohara 
   1253   1.3  kiyohara #ifdef STUARTCONSOLE
   1254   1.3  kiyohara #ifdef KGDB
   1255  1.25  kiyohara 	if (strcmp(kgdb_devname, "stuart") == 0) {
   1256   1.3  kiyohara 		/* port is reserved for kgdb */
   1257   1.3  kiyohara 	} else
   1258   1.3  kiyohara #endif
   1259  1.25  kiyohara #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
   1260  1.25  kiyohara 	if (console[0] == '\0' || strcasecmp(console, "stuart") == 0)
   1261  1.25  kiyohara #endif
   1262   1.3  kiyohara 	{
   1263  1.27  kiyohara 		int rv;
   1264  1.27  kiyohara 
   1265  1.25  kiyohara 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_STUART_BASE,
   1266  1.25  kiyohara 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
   1267  1.25  kiyohara 		if (rv == 0) {
   1268  1.21  kiyohara 			pxa2x0_clkman_config(CKEN_STUART, 1);
   1269   1.3  kiyohara 			return;
   1270   1.3  kiyohara 		}
   1271   1.3  kiyohara 	}
   1272   1.3  kiyohara #endif /* STUARTCONSOLE */
   1273   1.3  kiyohara 
   1274   1.1  kiyohara #ifdef BTUARTCONSOLE
   1275   1.1  kiyohara #ifdef KGDB
   1276  1.25  kiyohara 	if (strcmp(kgdb_devname, "btuart") == 0) {
   1277   1.1  kiyohara 		/* port is reserved for kgdb */
   1278   1.1  kiyohara 	} else
   1279   1.1  kiyohara #endif
   1280  1.25  kiyohara #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
   1281  1.25  kiyohara 	if (console[0] == '\0' || strcasecmp(console, "btuart") == 0)
   1282  1.25  kiyohara #endif
   1283   1.3  kiyohara 	{
   1284  1.27  kiyohara 		int rv;
   1285  1.27  kiyohara 
   1286  1.25  kiyohara 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_BTUART_BASE,
   1287  1.25  kiyohara 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
   1288  1.25  kiyohara 		if (rv == 0) {
   1289  1.21  kiyohara 			pxa2x0_clkman_config(CKEN_BTUART, 1);
   1290   1.3  kiyohara 			return;
   1291   1.3  kiyohara 		}
   1292   1.1  kiyohara 	}
   1293   1.1  kiyohara #endif /* BTUARTCONSOLE */
   1294   1.1  kiyohara 
   1295   1.3  kiyohara #ifdef HWUARTCONSOLE
   1296   1.3  kiyohara #ifdef KGDB
   1297  1.25  kiyohara 	if (strcmp(kgdb_devname, "hwuart") == 0) {
   1298   1.3  kiyohara 		/* port is reserved for kgdb */
   1299   1.3  kiyohara 	} else
   1300   1.3  kiyohara #endif
   1301  1.25  kiyohara #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
   1302  1.25  kiyohara 	if (console[0] == '\0' || strcasecmp(console, "hwuart") == 0)
   1303  1.25  kiyohara #endif
   1304   1.3  kiyohara 	{
   1305  1.25  kiyohara 		rv = comcnattach(&pxa2x0_a4x_bs_tag, PXA2X0_HWUART_BASE,
   1306  1.25  kiyohara 		    comcnspeed, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comcnmode);
   1307  1.25  kiyohara 		if (rv == 0) {
   1308  1.21  kiyohara 			pxa2x0_clkman_config(CKEN_HWUART, 1);
   1309   1.3  kiyohara 			return;
   1310   1.3  kiyohara 		}
   1311   1.3  kiyohara 	}
   1312   1.3  kiyohara #endif /* HWUARTCONSOLE */
   1313   1.1  kiyohara 
   1314  1.27  kiyohara #elif defined(OVERO)
   1315  1.27  kiyohara 
   1316  1.27  kiyohara 	if (comcnattach(&omap_a4x_bs_tag, 0x49020000, comcnspeed,
   1317  1.27  kiyohara 	    OMAP_COM_FREQ, COM_TYPE_NORMAL, comcnmode) == 0)
   1318  1.27  kiyohara 		return;
   1319  1.27  kiyohara 
   1320  1.27  kiyohara #endif /* GUMSTIX or OVERO */
   1321  1.27  kiyohara 
   1322   1.1  kiyohara #endif /* NCOM */
   1323   1.1  kiyohara 
   1324  1.15  kiyohara #if NLCD > 0
   1325  1.25  kiyohara #if defined(GUMSTIX_NETBSD_ARGS_CONSOLE)
   1326  1.25  kiyohara 	if (console[0] == '\0' || strcasecmp(console, "lcd") == 0)
   1327  1.25  kiyohara #endif
   1328  1.25  kiyohara 	{
   1329  1.25  kiyohara 		gxlcd_cnattach();
   1330  1.25  kiyohara 	}
   1331  1.15  kiyohara #endif
   1332   1.1  kiyohara }
   1333   1.1  kiyohara 
   1334   1.1  kiyohara #ifdef KGDB
   1335   1.3  kiyohara static void
   1336   1.1  kiyohara kgdb_port_init(void)
   1337   1.1  kiyohara {
   1338   1.1  kiyohara #if (NCOM > 0) && defined(COM_PXA2X0)
   1339   1.1  kiyohara 	paddr_t paddr = 0;
   1340  1.21  kiyohara 	int cken = 0;
   1341   1.1  kiyohara 
   1342   1.1  kiyohara 	if (0 == strcmp(kgdb_devname, "ffuart")) {
   1343   1.1  kiyohara 		paddr = PXA2X0_FFUART_BASE;
   1344  1.21  kiyohara 		cken = CKEN_FFUART;
   1345   1.3  kiyohara 	} else if (0 == strcmp(kgdb_devname, "stuart")) {
   1346   1.3  kiyohara 		paddr = PXA2X0_STUART_BASE;
   1347  1.21  kiyohara 		cken = CKEN_STUART;
   1348   1.3  kiyohara 	} else if (0 == strcmp(kgdb_devname, "btuart")) {
   1349   1.1  kiyohara 		paddr = PXA2X0_BTUART_BASE;
   1350  1.21  kiyohara 		cken = CKEN_BTUART;
   1351   1.3  kiyohara 	} else if (0 == strcmp(kgdb_devname, "hwuart")) {
   1352   1.3  kiyohara 		paddr = PXA2X0_HWUART_BASE;
   1353  1.21  kiyohara 		cken = CKEN_HWUART;
   1354   1.1  kiyohara 	}
   1355   1.1  kiyohara 
   1356   1.1  kiyohara 	if (paddr &&
   1357   1.1  kiyohara 	    0 == com_kgdb_attach(&pxa2x0_a4x_bs_tag, paddr,
   1358   1.6  kiyohara 		kgdb_devrate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
   1359   1.1  kiyohara 
   1360  1.21  kiyohara 		pxa2x0_clkman_config(cken, 1);
   1361   1.1  kiyohara 	}
   1362   1.1  kiyohara 
   1363   1.1  kiyohara #endif
   1364   1.1  kiyohara }
   1365   1.1  kiyohara #endif
   1366  1.28  kiyohara 
   1367  1.28  kiyohara static void
   1368  1.28  kiyohara gumstix_device_register(device_t dev, void *aux)
   1369  1.28  kiyohara {
   1370  1.46  kiyohara 	prop_dictionary_t dict = device_properties(dev);
   1371  1.28  kiyohara 
   1372  1.46  kiyohara 	if (device_is_a(dev, "ehci")) {
   1373  1.46  kiyohara 		prop_dictionary_set_cstring(dict, "port0-mode", "none");
   1374  1.46  kiyohara 		prop_dictionary_set_cstring(dict, "port1-mode", "phy");
   1375  1.46  kiyohara 		prop_dictionary_set_cstring(dict, "port2-mode", "none");
   1376  1.46  kiyohara 		prop_dictionary_set_bool(dict, "phy-reset", true);
   1377  1.46  kiyohara 		prop_dictionary_set_int16(dict, "port0-gpio", -1);
   1378  1.46  kiyohara 		prop_dictionary_set_int16(dict, "port1-gpio", 183);
   1379  1.46  kiyohara 		prop_dictionary_set_int16(dict, "port2-gpio", -1);
   1380  1.48  kiyohara 		prop_dictionary_set_uint16(dict, "dpll5-m", 443);
   1381  1.48  kiyohara 		prop_dictionary_set_uint16(dict, "dpll5-n", 11);
   1382  1.48  kiyohara 		prop_dictionary_set_uint16(dict, "dpll5-m2", 4);
   1383  1.46  kiyohara 	}
   1384  1.28  kiyohara 	if (device_is_a(dev, "ohci")) {
   1385  1.46  kiyohara 		if (prop_dictionary_set_bool(dict,
   1386  1.28  kiyohara 		    "Ganged-power-mask-on-port1", 1) == false) {
   1387  1.28  kiyohara 			printf("WARNING: unable to set power-mask for port1"
   1388  1.44       chs 			    " property for %s\n", device_xname(dev));
   1389  1.28  kiyohara 		}
   1390  1.46  kiyohara 		if (prop_dictionary_set_bool(dict,
   1391  1.28  kiyohara 		    "Ganged-power-mask-on-port2", 1) == false) {
   1392  1.28  kiyohara 			printf("WARNING: unable to set power-mask for port2"
   1393  1.44       chs 			    " property for %s\n", device_xname(dev));
   1394  1.28  kiyohara 		}
   1395  1.46  kiyohara 		if (prop_dictionary_set_bool(dict,
   1396  1.28  kiyohara 		    "Ganged-power-mask-on-port3", 1) == false) {
   1397  1.28  kiyohara 			printf("WARNING: unable to set power-mask for port3"
   1398  1.44       chs 			    " property for %s\n", device_xname(dev));
   1399  1.28  kiyohara 		}
   1400  1.28  kiyohara 	}
   1401  1.28  kiyohara }
   1402