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