Home | History | Annotate | Line # | Download | only in armadillo
armadillo9_machdep.c revision 1.10.8.1
      1  1.10.8.1      yamt /*	$NetBSD: armadillo9_machdep.c,v 1.10.8.1 2008/05/18 12:31:47 yamt Exp $	*/
      2       1.1  hamajima 
      3       1.1  hamajima /*
      4       1.1  hamajima  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
      5       1.1  hamajima  * All rights reserved.
      6       1.1  hamajima  *
      7       1.1  hamajima  * Based on code written by Jason R. Thorpe and Steve C. Woodford for
      8       1.1  hamajima  * Wasabi Systems, Inc.
      9       1.1  hamajima  *
     10       1.1  hamajima  * Redistribution and use in source and binary forms, with or without
     11       1.1  hamajima  * modification, are permitted provided that the following conditions
     12       1.1  hamajima  * are met:
     13       1.1  hamajima  * 1. Redistributions of source code must retain the above copyright
     14       1.1  hamajima  *    notice, this list of conditions and the following disclaimer.
     15       1.1  hamajima  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1  hamajima  *    notice, this list of conditions and the following disclaimer in the
     17       1.1  hamajima  *    documentation and/or other materials provided with the distribution.
     18       1.1  hamajima  * 3. All advertising materials mentioning features or use of this software
     19       1.1  hamajima  *    must display the following acknowledgement:
     20       1.1  hamajima  *	This product includes software developed for the NetBSD Project by
     21       1.1  hamajima  *	Wasabi Systems, Inc.
     22       1.1  hamajima  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     23       1.1  hamajima  *    or promote products derived from this software without specific prior
     24       1.1  hamajima  *    written permission.
     25       1.1  hamajima  *
     26       1.1  hamajima  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     27       1.1  hamajima  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1  hamajima  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1  hamajima  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     30       1.1  hamajima  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1  hamajima  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1  hamajima  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1  hamajima  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1  hamajima  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1  hamajima  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1  hamajima  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1  hamajima  */
     38       1.1  hamajima 
     39       1.1  hamajima /*
     40       1.1  hamajima  * Copyright (c) 1997,1998 Mark Brinicombe.
     41       1.1  hamajima  * Copyright (c) 1997,1998 Causality Limited.
     42       1.1  hamajima  * All rights reserved.
     43       1.1  hamajima  *
     44       1.1  hamajima  * Redistribution and use in source and binary forms, with or without
     45       1.1  hamajima  * modification, are permitted provided that the following conditions
     46       1.1  hamajima  * are met:
     47       1.1  hamajima  * 1. Redistributions of source code must retain the above copyright
     48       1.1  hamajima  *    notice, this list of conditions and the following disclaimer.
     49       1.1  hamajima  * 2. Redistributions in binary form must reproduce the above copyright
     50       1.1  hamajima  *    notice, this list of conditions and the following disclaimer in the
     51       1.1  hamajima  *    documentation and/or other materials provided with the distribution.
     52       1.1  hamajima  * 3. All advertising materials mentioning features or use of this software
     53       1.1  hamajima  *    must display the following acknowledgement:
     54       1.1  hamajima  *	This product includes software developed by Mark Brinicombe
     55       1.1  hamajima  *	for the NetBSD Project.
     56       1.1  hamajima  * 4. The name of the company nor the name of the author may be used to
     57       1.1  hamajima  *    endorse or promote products derived from this software without specific
     58       1.1  hamajima  *    prior written permission.
     59       1.1  hamajima  *
     60       1.1  hamajima  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     61       1.1  hamajima  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     62       1.1  hamajima  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     63       1.1  hamajima  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     64       1.1  hamajima  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     65       1.1  hamajima  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     66       1.1  hamajima  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67       1.1  hamajima  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68       1.1  hamajima  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69       1.1  hamajima  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70       1.1  hamajima  * SUCH DAMAGE.
     71       1.1  hamajima  *
     72       1.3  hamajima  * Machine dependant functions for kernel setup for Armadillo.
     73       1.1  hamajima  */
     74       1.1  hamajima 
     75       1.1  hamajima /*	Armadillo-9 physical memory map
     76       1.1  hamajima 	0000 0000 - 0fff ffff	reserved
     77       1.1  hamajima 	1000 0000 - 1000 000f	I/O Control Register
     78       1.1  hamajima 	1000 0010 - 11dd ffff	reserved
     79       1.1  hamajima 	1200 0000 - 1200 ffff	PC/104 I/O space (8bit)
     80       1.1  hamajima 	1201 0000 - 12ff ffff	reserved
     81       1.1  hamajima 	1300 0000 - 13ff ffff	PC/104 Memory space (8bit)
     82       1.1  hamajima 	1400 0000 - 1fff ffff	reserved
     83       1.1  hamajima 	2000 0000 - 21ff ffff	reserved
     84       1.1  hamajima 	2200 0000 - 2200 ffff	PC/104 I/O space (16bit)
     85       1.1  hamajima 	2201 0000 - 22ff ffff	reserved
     86       1.1  hamajima 	2300 0000 - 23ff ffff	PC/104 Memory space (16bit)
     87       1.1  hamajima 	2400 0000 - 2fff ffff	reserved
     88       1.1  hamajima 	3000 0000 - 3fff ffff	reserved
     89       1.1  hamajima 	4000 0000 - 43ff ffff	Compact Flash I/O space
     90       1.1  hamajima 	4400 0000 - 47ff ffff	reserved
     91       1.1  hamajima 	4800 0000 - 4bff ffff	Compact Flash Attribute space
     92       1.1  hamajima 	4c00 0000 - 4fff ffff	Compact Flash memory space
     93       1.1  hamajima 	5000 0000 - 5fff ffff	reserved
     94       1.1  hamajima 	6000 0000 - 607f ffff	Flash Memory (8MByte)
     95       1.1  hamajima 	6080 0000 - 6fff ffff	reserved
     96       1.1  hamajima 	7000 0000 - 7fff ffff	reserved
     97       1.1  hamajima 	8000 0000 - 8008 ffff	EP9315 Internal Register (AHB)
     98       1.1  hamajima 	8009 0000 - 8009 3fff	Internal Boot ROM (16kByte)
     99       1.1  hamajima 	8009 4000 - 8009 ffff	reserved
    100       1.1  hamajima 	800a 0000 - 800f ffff	EP9315 Internal Register (AHB)
    101       1.1  hamajima 	8010 0000 - 807f ffff	reserved
    102       1.1  hamajima 	8080 0000 - 8094 ffff	EP9315 Internal Register (APB)
    103       1.1  hamajima 	8095 0000 - 8fff ffff	reserved
    104       1.1  hamajima 	9000 0000 - bfff ffff	reserved
    105       1.1  hamajima 	c000 0000 - c1ff ffff	SDRAM (32MByte)
    106       1.1  hamajima 	c200 0000 - c3ff ffff	reserved
    107       1.1  hamajima 	c400 0000 - c5ff ffff	SDRAM (32MByte)
    108       1.1  hamajima 	c600 0000 - cfff ffff	reserved
    109       1.1  hamajima 	d000 0000 - ffff ffff	reserved
    110       1.1  hamajima */
    111       1.1  hamajima 
    112       1.1  hamajima #include <sys/cdefs.h>
    113  1.10.8.1      yamt __KERNEL_RCSID(0, "$NetBSD: armadillo9_machdep.c,v 1.10.8.1 2008/05/18 12:31:47 yamt Exp $");
    114       1.1  hamajima 
    115       1.1  hamajima #include "opt_ddb.h"
    116       1.1  hamajima #include "opt_kgdb.h"
    117       1.1  hamajima #include "opt_pmap_debug.h"
    118       1.1  hamajima 
    119       1.1  hamajima #include <sys/param.h>
    120       1.1  hamajima #include <sys/device.h>
    121       1.1  hamajima #include <sys/systm.h>
    122       1.1  hamajima #include <sys/kernel.h>
    123       1.1  hamajima #include <sys/exec.h>
    124       1.1  hamajima #include <sys/proc.h>
    125       1.1  hamajima #include <sys/msgbuf.h>
    126       1.1  hamajima #include <sys/reboot.h>
    127       1.1  hamajima #include <sys/termios.h>
    128       1.1  hamajima #include <sys/ksyms.h>
    129       1.1  hamajima 
    130       1.5   thorpej #include <net/if.h>
    131       1.5   thorpej #include <net/if_ether.h>
    132       1.5   thorpej 
    133       1.1  hamajima #include <uvm/uvm_extern.h>
    134       1.1  hamajima 
    135       1.1  hamajima #include <dev/cons.h>
    136       1.1  hamajima 
    137       1.1  hamajima #include <machine/db_machdep.h>
    138       1.1  hamajima #include <ddb/db_sym.h>
    139       1.1  hamajima #include <ddb/db_extern.h>
    140       1.1  hamajima 
    141       1.3  hamajima #define	DRAM_BLOCKS	4
    142       1.1  hamajima #include <machine/bootconfig.h>
    143       1.5   thorpej #include <machine/autoconf.h>
    144       1.1  hamajima #include <machine/bus.h>
    145       1.1  hamajima #include <machine/cpu.h>
    146       1.1  hamajima #include <machine/frame.h>
    147       1.1  hamajima #include <arm/undefined.h>
    148       1.1  hamajima 
    149       1.1  hamajima #include <arm/arm32/machdep.h>
    150       1.1  hamajima 
    151       1.1  hamajima #include <arm/ep93xx/ep93xxreg.h>
    152       1.1  hamajima #include <arm/ep93xx/ep93xxvar.h>
    153       1.1  hamajima 
    154       1.1  hamajima #include "epwdog.h"
    155       1.1  hamajima #if NEPWDOG > 0
    156       1.1  hamajima #include <arm/ep93xx/epwdogvar.h>
    157       1.1  hamajima #endif
    158       1.1  hamajima #include <arm/ep93xx/epwdogreg.h>
    159       1.1  hamajima 
    160       1.1  hamajima #include <dev/ic/comreg.h>
    161       1.1  hamajima #include <dev/ic/comvar.h>
    162       1.1  hamajima 
    163       1.1  hamajima #include "epcom.h"
    164       1.1  hamajima #if NEPCOM > 0
    165       1.1  hamajima #include <arm/ep93xx/epcomvar.h>
    166       1.1  hamajima #endif
    167       1.1  hamajima 
    168       1.1  hamajima #include "isa.h"
    169       1.1  hamajima #if NISA > 0
    170       1.1  hamajima #include <dev/isa/isareg.h>
    171       1.1  hamajima #include <dev/isa/isavar.h>
    172       1.1  hamajima #endif
    173       1.1  hamajima 
    174       1.1  hamajima #include <machine/isa_machdep.h>
    175       1.1  hamajima 
    176       1.1  hamajima #include <evbarm/armadillo/armadillo9reg.h>
    177       1.4  hamajima #include <evbarm/armadillo/armadillo9var.h>
    178       1.4  hamajima 
    179       1.4  hamajima struct armadillo_model_t *armadillo_model = 0;
    180       1.4  hamajima static struct armadillo_model_t armadillo_model_table[] = {
    181       1.4  hamajima 	{ DEVCFG_ARMADILLO9, "Armadillo-9" },
    182       1.4  hamajima 	{ DEVCFG_ARMADILLO210, "Armadillo-210" },
    183       1.4  hamajima 	{ 0, "Armadillo(unknown model)" } };
    184       1.1  hamajima 
    185       1.1  hamajima #include "ksyms.h"
    186       1.1  hamajima 
    187       1.1  hamajima /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    188       1.1  hamajima #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
    189       1.1  hamajima #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    190       1.1  hamajima 
    191       1.1  hamajima /*
    192       1.1  hamajima  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    193       1.1  hamajima  * Core-logic registers and I/O mappings occupy 0xf0000000 - 0xffffffff
    194       1.1  hamajima  */
    195       1.1  hamajima #define KERNEL_VM_SIZE		0x0c000000
    196       1.1  hamajima 
    197       1.1  hamajima /*
    198       1.1  hamajima  * Address to call from cpu_reset() to reset the machine.
    199       1.1  hamajima  * This is machine architecture dependant as it varies depending
    200       1.1  hamajima  * on where the ROM appears when you turn the MMU off.
    201       1.1  hamajima  */
    202       1.1  hamajima 
    203       1.1  hamajima u_int cpu_reset_address = 0x80090000;
    204       1.1  hamajima 
    205       1.1  hamajima /* Define various stack sizes in pages */
    206       1.1  hamajima #define IRQ_STACK_SIZE	8
    207       1.1  hamajima #define ABT_STACK_SIZE	8
    208       1.1  hamajima #define UND_STACK_SIZE	8
    209       1.1  hamajima 
    210       1.1  hamajima BootConfig bootconfig;	/* Boot config storage */
    211       1.1  hamajima char *boot_args = NULL;
    212       1.1  hamajima char *boot_file = NULL;
    213       1.1  hamajima 
    214       1.1  hamajima vm_offset_t physical_start;
    215       1.1  hamajima vm_offset_t physical_freestart;
    216       1.1  hamajima vm_offset_t physical_freeend;
    217       1.1  hamajima vm_offset_t physical_freeend_low;
    218       1.1  hamajima vm_offset_t physical_end;
    219       1.1  hamajima u_int free_pages;
    220       1.1  hamajima int physmem = 0;
    221       1.1  hamajima 
    222       1.1  hamajima /* Physical and virtual addresses for some global pages */
    223       1.1  hamajima pv_addr_t systempage;
    224       1.1  hamajima pv_addr_t irqstack;
    225       1.1  hamajima pv_addr_t undstack;
    226       1.1  hamajima pv_addr_t abtstack;
    227       1.1  hamajima pv_addr_t kernelstack;
    228       1.1  hamajima 
    229       1.1  hamajima vm_offset_t msgbufphys;
    230       1.1  hamajima 
    231       1.1  hamajima static struct arm32_dma_range armadillo9_dma_ranges[4];
    232       1.1  hamajima 
    233       1.1  hamajima #if NISA > 0
    234       1.1  hamajima extern void isa_armadillo9_init(u_int, u_int);
    235       1.1  hamajima #endif
    236       1.1  hamajima 
    237       1.1  hamajima extern u_int data_abort_handler_address;
    238       1.1  hamajima extern u_int prefetch_abort_handler_address;
    239       1.1  hamajima extern u_int undefined_handler_address;
    240       1.1  hamajima 
    241       1.1  hamajima #ifdef PMAP_DEBUG
    242       1.1  hamajima extern int pmap_debug_level;
    243       1.1  hamajima #endif
    244       1.1  hamajima 
    245       1.1  hamajima #define KERNEL_PT_SYS		0	/* L2 table for mapping vectors page */
    246       1.1  hamajima 
    247       1.1  hamajima #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
    248       1.1  hamajima #define	KERNEL_PT_KERNEL_NUM	4
    249       1.1  hamajima 					/* L2 tables for mapping kernel VM */
    250       1.1  hamajima #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    251       1.1  hamajima 
    252       1.1  hamajima #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    253       1.1  hamajima #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    254       1.1  hamajima 
    255       1.1  hamajima pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    256       1.1  hamajima 
    257       1.1  hamajima struct user *proc0paddr;
    258       1.1  hamajima 
    259       1.1  hamajima /* Prototypes */
    260       1.1  hamajima 
    261       1.1  hamajima void	consinit(void);
    262       1.1  hamajima /*
    263       1.1  hamajima  * Define the default console speed for the machine.
    264       1.1  hamajima  */
    265       1.4  hamajima #if NEPCOM > 0
    266       1.1  hamajima #ifndef CONSPEED
    267       1.1  hamajima #define CONSPEED B115200
    268       1.1  hamajima #endif /* ! CONSPEED */
    269       1.1  hamajima 
    270       1.1  hamajima #ifndef CONMODE
    271       1.1  hamajima #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    272       1.1  hamajima #endif
    273       1.1  hamajima 
    274       1.4  hamajima #ifndef CONUNIT
    275       1.4  hamajima #define	CONUNIT	0
    276       1.4  hamajima #endif
    277       1.4  hamajima 
    278       1.1  hamajima int comcnspeed = CONSPEED;
    279       1.1  hamajima int comcnmode = CONMODE;
    280       1.4  hamajima const unsigned long comaddr[] = {
    281       1.4  hamajima 	EP93XX_APB_UART1, EP93XX_APB_UART2 };
    282       1.4  hamajima #endif
    283       1.1  hamajima 
    284       1.1  hamajima #if KGDB
    285       1.1  hamajima #ifndef KGDB_DEVNAME
    286       1.1  hamajima #error Must define KGDB_DEVNAME
    287       1.1  hamajima #endif
    288       1.1  hamajima const char kgdb_devname[] = KGDB_DEVNAME;
    289       1.1  hamajima 
    290       1.1  hamajima #ifndef KGDB_DEVADDR
    291       1.1  hamajima #error Must define KGDB_DEVADDR
    292       1.1  hamajima #endif
    293       1.1  hamajima unsigned long kgdb_devaddr = KGDB_DEVADDR;
    294       1.1  hamajima 
    295       1.1  hamajima #ifndef KGDB_DEVRATE
    296       1.1  hamajima #define KGDB_DEVRATE	CONSPEED
    297       1.1  hamajima #endif
    298       1.1  hamajima int kgdb_devrate = KGDB_DEVRATE;
    299       1.1  hamajima 
    300       1.1  hamajima #ifndef KGDB_DEVMODE
    301       1.1  hamajima #define KGDB_DEVMODE	CONMODE
    302       1.1  hamajima #endif
    303       1.1  hamajima int kgdb_devmode = KGDB_DEVMODE;
    304       1.1  hamajima #endif /* KGDB */
    305       1.1  hamajima 
    306       1.1  hamajima /*
    307       1.5   thorpej  * MAC address for the built-in Ethernet.
    308       1.5   thorpej  */
    309       1.5   thorpej uint8_t	armadillo9_ethaddr[ETHER_ADDR_LEN];
    310       1.5   thorpej 
    311       1.5   thorpej static void
    312       1.5   thorpej armadillo9_device_register(device_t dev, void *aux)
    313       1.5   thorpej {
    314       1.5   thorpej 
    315       1.5   thorpej 	/* MAC address for the built-in Ethernet. */
    316       1.6   thorpej 	if (device_is_a(dev, "epe")) {
    317       1.7   thorpej 		prop_data_t pd = prop_data_create_data_nocopy(
    318       1.7   thorpej 		    armadillo9_ethaddr, ETHER_ADDR_LEN);
    319       1.7   thorpej 		KASSERT(pd != NULL);
    320       1.7   thorpej 		if (prop_dictionary_set(device_properties(dev),
    321       1.9   thorpej 					"mac-addr", pd) == false) {
    322       1.5   thorpej 			printf("WARNING: unable to set mac-addr property "
    323       1.5   thorpej 			    "for %s\n", dev->dv_xname);
    324       1.5   thorpej 		}
    325       1.7   thorpej 		prop_object_release(pd);
    326       1.5   thorpej 	}
    327       1.5   thorpej }
    328       1.5   thorpej 
    329       1.5   thorpej /*
    330       1.1  hamajima  * void cpu_reboot(int howto, char *bootstr)
    331       1.1  hamajima  *
    332       1.1  hamajima  * Reboots the system
    333       1.1  hamajima  *
    334       1.1  hamajima  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    335       1.1  hamajima  * then reset the CPU.
    336       1.1  hamajima  */
    337       1.1  hamajima void
    338       1.1  hamajima cpu_reboot(int howto, char *bootstr)
    339       1.1  hamajima {
    340       1.1  hamajima 	/*
    341       1.1  hamajima 	 * If we are still cold then hit the air brakes
    342       1.1  hamajima 	 * and crash to earth fast
    343       1.1  hamajima 	 */
    344       1.1  hamajima 	if (cold) {
    345       1.1  hamajima 		doshutdownhooks();
    346       1.1  hamajima 		printf("\r\n");
    347       1.1  hamajima 		printf("The operating system has halted.\r\n");
    348       1.1  hamajima 		printf("Please press any key to reboot.\r\n");
    349       1.1  hamajima 		cngetc();
    350       1.1  hamajima 		printf("\r\nrebooting...\r\n");
    351       1.1  hamajima 		goto reset;
    352       1.1  hamajima 	}
    353       1.1  hamajima 
    354       1.1  hamajima 	/* Disable console buffering */
    355       1.1  hamajima 
    356       1.1  hamajima 	/*
    357       1.1  hamajima 	 * If RB_NOSYNC was not specified sync the discs.
    358       1.1  hamajima 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    359       1.1  hamajima 	 * unmount.  It looks like syslogd is getting woken up only to find
    360       1.1  hamajima 	 * that it cannot page part of the binary in as the filesystem has
    361       1.1  hamajima 	 * been unmounted.
    362       1.1  hamajima 	 */
    363       1.1  hamajima 	if (!(howto & RB_NOSYNC))
    364       1.1  hamajima 		bootsync();
    365       1.1  hamajima 
    366       1.1  hamajima 	/* Say NO to interrupts */
    367       1.1  hamajima 	splhigh();
    368       1.1  hamajima 
    369       1.1  hamajima 	/* Do a dump if requested. */
    370       1.1  hamajima 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    371       1.1  hamajima 		dumpsys();
    372       1.1  hamajima 
    373       1.1  hamajima 	/* Run any shutdown hooks */
    374       1.1  hamajima 	doshutdownhooks();
    375       1.1  hamajima 
    376       1.1  hamajima 	/* Make sure IRQ's are disabled */
    377       1.1  hamajima 	IRQdisable;
    378       1.1  hamajima 
    379       1.1  hamajima 	if (howto & RB_HALT) {
    380       1.1  hamajima 		printf("\r\n");
    381       1.1  hamajima 		printf("The operating system has halted.\r\n");
    382       1.1  hamajima 		printf("Please press any key to reboot.\r\n");
    383       1.1  hamajima 		cngetc();
    384       1.1  hamajima 	}
    385       1.1  hamajima 
    386       1.1  hamajima 	printf("\r\nrebooting...\r\n");
    387       1.1  hamajima  reset:
    388       1.1  hamajima 	/*
    389       1.1  hamajima 	 * Make really really sure that all interrupts are disabled,
    390       1.1  hamajima 	 * and poke the Internal Bus and Peripheral Bus reset lines.
    391       1.1  hamajima 	 */
    392       1.1  hamajima 	(void) disable_interrupts(I32_bit|F32_bit);
    393       1.1  hamajima #if NEPWDOG > 0
    394       1.1  hamajima 	epwdog_reset();
    395       1.1  hamajima #else
    396       1.1  hamajima 	{
    397       1.1  hamajima 	u_int32_t ctrl = EP93XX_APB_VBASE + EP93XX_APB_WDOG + EP93XX_WDOG_Ctrl;
    398       1.1  hamajima 	u_int32_t val = EP93XX_WDOG_ENABLE;
    399       1.2     perry 	__asm volatile (
    400       1.1  hamajima 		"str %1, [%0]\n"
    401       1.1  hamajima 		:
    402       1.1  hamajima 		: "r" (ctrl), "r" (val)
    403       1.1  hamajima 	);
    404       1.1  hamajima 	}
    405       1.1  hamajima #endif
    406       1.1  hamajima 	for (;;);
    407       1.1  hamajima }
    408       1.1  hamajima 
    409       1.1  hamajima /* Static device mappings. */
    410       1.1  hamajima static const struct pmap_devmap armadillo9_devmap[] = {
    411       1.1  hamajima     {
    412       1.1  hamajima 	EP93XX_AHB_VBASE,
    413       1.1  hamajima 	EP93XX_AHB_HWBASE,
    414       1.1  hamajima 	EP93XX_AHB_SIZE,
    415       1.1  hamajima 	VM_PROT_READ|VM_PROT_WRITE,
    416       1.1  hamajima 	PTE_NOCACHE,
    417       1.1  hamajima     },
    418       1.1  hamajima 
    419       1.1  hamajima     {
    420       1.1  hamajima 	EP93XX_APB_VBASE,
    421       1.1  hamajima 	EP93XX_APB_HWBASE,
    422       1.1  hamajima 	EP93XX_APB_SIZE,
    423       1.1  hamajima 	VM_PROT_READ|VM_PROT_WRITE,
    424       1.1  hamajima 	PTE_NOCACHE,
    425       1.1  hamajima     },
    426       1.1  hamajima 
    427       1.1  hamajima     {
    428       1.1  hamajima 	EP93XX_PCMCIA0_VBASE,
    429       1.1  hamajima 	EP93XX_PCMCIA0_HWBASE,
    430       1.1  hamajima 	EP93XX_PCMCIA_SIZE,
    431       1.1  hamajima 	VM_PROT_READ|VM_PROT_WRITE,
    432       1.1  hamajima 	PTE_NOCACHE,
    433       1.1  hamajima     },
    434       1.1  hamajima 
    435       1.1  hamajima 	/*
    436       1.1  hamajima 	 * IO8 and IO16 space *must* be mapped contiguously with
    437       1.1  hamajima 	 * IO8_VA == IO16_VA - 64 Mbytes.  ISA busmap driver depends
    438       1.1  hamajima 	 * on that!
    439       1.1  hamajima 	 */
    440       1.1  hamajima     {
    441       1.1  hamajima 	ARMADILLO9_IO8_VBASE,
    442       1.1  hamajima 	ARMADILLO9_IO8_HWBASE,
    443       1.1  hamajima 	ARMADILLO9_IO8_SIZE,
    444       1.1  hamajima 	VM_PROT_READ|VM_PROT_WRITE,
    445       1.1  hamajima 	PTE_NOCACHE,
    446       1.1  hamajima     },
    447       1.1  hamajima 
    448       1.1  hamajima     {
    449       1.1  hamajima 	ARMADILLO9_IO16_VBASE,
    450       1.1  hamajima 	ARMADILLO9_IO16_HWBASE,
    451       1.1  hamajima 	ARMADILLO9_IO16_SIZE,
    452       1.1  hamajima 	VM_PROT_READ|VM_PROT_WRITE,
    453       1.1  hamajima 	PTE_NOCACHE,
    454       1.1  hamajima     },
    455       1.1  hamajima 
    456       1.1  hamajima    {
    457       1.1  hamajima 	0,
    458       1.1  hamajima 	0,
    459       1.1  hamajima 	0,
    460       1.1  hamajima 	0,
    461       1.1  hamajima 	0,
    462       1.1  hamajima     }
    463       1.1  hamajima };
    464       1.1  hamajima 
    465       1.1  hamajima /*
    466       1.1  hamajima  * u_int initarm(...)
    467       1.1  hamajima  *
    468       1.1  hamajima  * Initial entry point on startup. This gets called before main() is
    469       1.1  hamajima  * entered.
    470       1.1  hamajima  * It should be responsible for setting up everything that must be
    471       1.1  hamajima  * in place when main is called.
    472       1.1  hamajima  * This includes
    473       1.1  hamajima  *   Taking a copy of the boot configuration structure.
    474       1.1  hamajima  *   Initialising the physical console so characters can be printed.
    475       1.1  hamajima  *   Setting up page tables for the kernel
    476       1.1  hamajima  *   Initialising interrupt controllers to a sane default state
    477       1.1  hamajima  */
    478       1.1  hamajima u_int
    479       1.1  hamajima initarm(void *arg)
    480       1.1  hamajima {
    481       1.1  hamajima 	int loop;
    482       1.1  hamajima 	int loop1;
    483       1.1  hamajima 	u_int l1pagetable;
    484       1.4  hamajima 	struct bootparam_tag *bootparam_p;
    485       1.4  hamajima 	unsigned long devcfg;
    486       1.1  hamajima 
    487       1.1  hamajima 	/*
    488       1.1  hamajima 	 * Since we map the on-board devices VA==PA, and the kernel
    489       1.1  hamajima 	 * is running VA==PA, it's possible for us to initialize
    490       1.1  hamajima 	 * the console now.
    491       1.1  hamajima 	 */
    492       1.1  hamajima 	consinit();
    493       1.1  hamajima 
    494       1.4  hamajima 	/* identify model */
    495       1.4  hamajima 	devcfg = *((volatile unsigned long*)(EP93XX_APB_HWBASE
    496       1.4  hamajima 					     + EP93XX_APB_SYSCON
    497       1.4  hamajima 					     + EP93XX_SYSCON_DeviceCfg));
    498       1.4  hamajima 	for (armadillo_model = &armadillo_model_table[0];
    499       1.4  hamajima 				armadillo_model->devcfg; armadillo_model++)
    500       1.4  hamajima 		if (devcfg == armadillo_model->devcfg)
    501       1.4  hamajima 			break;
    502       1.4  hamajima 
    503       1.4  hamajima 	/* Talk to the user */
    504       1.4  hamajima 	printf("\nNetBSD/%s booting ...\n", armadillo_model->name);
    505       1.4  hamajima 
    506       1.4  hamajima 	/* set some informations from bootloader */
    507       1.4  hamajima 	bootparam_p = (struct bootparam_tag *)bootparam;
    508       1.4  hamajima 	bootconfig.dramblocks = 0;
    509       1.4  hamajima 	while (bootparam_p->hdr.tag != BOOTPARAM_TAG_NONE) {
    510       1.4  hamajima 		switch (bootparam_p->hdr.tag) {
    511       1.4  hamajima 		case BOOTPARAM_TAG_MEM:
    512       1.4  hamajima 			if (bootconfig.dramblocks < DRAM_BLOCKS) {
    513       1.4  hamajima #ifdef VERBOSE_INIT_ARM
    514       1.4  hamajima 			printf("dram[%d]: address=0x%08lx, size=0x%08lx\n",
    515       1.4  hamajima 						bootconfig.dramblocks,
    516       1.4  hamajima 						bootparam_p->u.mem.start,
    517       1.4  hamajima 						bootparam_p->u.mem.size);
    518       1.4  hamajima #endif
    519       1.4  hamajima 				bootconfig.dram[bootconfig.dramblocks].address =
    520       1.4  hamajima 					bootparam_p->u.mem.start;
    521       1.4  hamajima 				bootconfig.dram[bootconfig.dramblocks].pages =
    522       1.4  hamajima 					bootparam_p->u.mem.size / PAGE_SIZE;
    523       1.4  hamajima 				bootconfig.dramblocks++;
    524       1.4  hamajima 			}
    525       1.4  hamajima 			break;
    526       1.4  hamajima 		case BOOTPARAM_TAG_CMDLINE:
    527       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    528       1.4  hamajima 			printf("cmdline: %s\n", bootparam_p->u.cmdline.cmdline);
    529       1.1  hamajima #endif
    530       1.4  hamajima 			parse_mi_bootargs(bootparam_p->u.cmdline.cmdline);
    531       1.4  hamajima 			break;
    532       1.4  hamajima 		}
    533       1.4  hamajima 		bootparam_p = bootparam_tag_next(bootparam_p);
    534       1.4  hamajima 	}
    535       1.1  hamajima 
    536       1.1  hamajima 	/*
    537       1.1  hamajima 	 * Heads up ... Setup the CPU / MMU / TLB functions
    538       1.1  hamajima 	 */
    539       1.1  hamajima 	if (set_cpufuncs())
    540       1.1  hamajima 		panic("cpu not recognized!");
    541       1.1  hamajima 
    542       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    543       1.1  hamajima 	printf("initarm: Configuring system ...\n");
    544       1.1  hamajima #endif
    545       1.1  hamajima 	/*
    546       1.1  hamajima 	 * Set up the variables that define the availablilty of
    547       1.1  hamajima 	 * physical memory.  For now, we're going to set
    548       1.1  hamajima 	 * physical_freestart to 0xc0200000 (where the kernel
    549       1.1  hamajima 	 * was loaded), and allocate the memory we need downwards.
    550       1.1  hamajima 	 * If we get too close to the L1 table that we set up, we
    551       1.1  hamajima 	 * will panic.  We will update physical_freestart and
    552       1.1  hamajima 	 * physical_freeend later to reflect what pmap_bootstrap()
    553       1.1  hamajima 	 * wants to see.
    554       1.1  hamajima 	 *
    555       1.1  hamajima 	 * XXX pmap_bootstrap() needs an enema.
    556       1.1  hamajima 	 */
    557       1.1  hamajima 	physical_start = bootconfig.dram[0].address;
    558       1.1  hamajima 	physical_end = bootconfig.dram[0].address
    559       1.1  hamajima 			+ (bootconfig.dram[0].pages * PAGE_SIZE);
    560       1.1  hamajima 
    561       1.1  hamajima 	physical_freestart = 0xc0018000UL;
    562       1.1  hamajima 	physical_freeend = 0xc0200000UL;
    563       1.1  hamajima 
    564       1.1  hamajima 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    565       1.1  hamajima 
    566       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    567       1.1  hamajima 	/* Tell the user about the memory */
    568       1.1  hamajima 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    569       1.1  hamajima 	    physical_start, physical_end - 1);
    570       1.1  hamajima #endif
    571       1.1  hamajima 
    572       1.1  hamajima 	/*
    573       1.1  hamajima 	 * Okay, the kernel starts 2MB in from the bottom of physical
    574       1.1  hamajima 	 * memory.  We are going to allocate our bootstrap pages downwards
    575       1.1  hamajima 	 * from there.
    576       1.1  hamajima 	 *
    577       1.1  hamajima 	 * We need to allocate some fixed page tables to get the kernel
    578       1.1  hamajima 	 * going.  We allocate one page directory and a number of page
    579       1.1  hamajima 	 * tables and store the physical addresses in the kernel_pt_table
    580       1.1  hamajima 	 * array.
    581       1.1  hamajima 	 *
    582       1.1  hamajima 	 * The kernel page directory must be on a 16K boundary.  The page
    583       1.1  hamajima 	 * tables must be on 4K bounaries.  What we do is allocate the
    584       1.1  hamajima 	 * page directory on the first 16K boundary that we encounter, and
    585       1.1  hamajima 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    586       1.1  hamajima 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    587       1.1  hamajima 	 * least one 16K aligned region.
    588       1.1  hamajima 	 */
    589       1.1  hamajima 
    590       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    591       1.1  hamajima 	printf("Allocating page tables\n");
    592       1.1  hamajima #endif
    593       1.1  hamajima 
    594       1.1  hamajima 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    595       1.1  hamajima 
    596       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    597       1.1  hamajima 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    598       1.1  hamajima 	       physical_freestart, free_pages, free_pages);
    599       1.1  hamajima #endif
    600       1.1  hamajima 
    601       1.1  hamajima 	/* Define a macro to simplify memory allocation */
    602       1.1  hamajima #define	valloc_pages(var, np)				\
    603       1.1  hamajima 	alloc_pages((var).pv_pa, (np));			\
    604       1.1  hamajima 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    605       1.1  hamajima 
    606       1.1  hamajima #define alloc_pages(var, np)				\
    607       1.1  hamajima 	physical_freeend -= ((np) * PAGE_SIZE);		\
    608       1.1  hamajima 	if (physical_freeend < physical_freestart)	\
    609       1.1  hamajima 		panic("initarm: out of memory");	\
    610       1.1  hamajima 	(var) = physical_freeend;			\
    611       1.1  hamajima 	free_pages -= (np);				\
    612       1.1  hamajima 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    613       1.1  hamajima 
    614       1.1  hamajima 	loop1 = 0;
    615       1.1  hamajima 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    616       1.1  hamajima 		/* Are we 16KB aligned for an L1 ? */
    617       1.1  hamajima 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    618       1.1  hamajima 		    && kernel_l1pt.pv_pa == 0) {
    619       1.1  hamajima 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    620       1.1  hamajima 		} else {
    621       1.1  hamajima 			valloc_pages(kernel_pt_table[loop1],
    622       1.1  hamajima 			    L2_TABLE_SIZE / PAGE_SIZE);
    623       1.1  hamajima 			++loop1;
    624       1.1  hamajima 		}
    625       1.1  hamajima 	}
    626       1.1  hamajima 
    627       1.1  hamajima 	/* This should never be able to happen but better confirm that. */
    628       1.1  hamajima 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    629       1.1  hamajima 		panic("initarm: Failed to align the kernel page directory");
    630       1.1  hamajima 
    631       1.1  hamajima 	/*
    632       1.1  hamajima 	 * Allocate a page for the system vectors page
    633       1.1  hamajima 	 */
    634       1.1  hamajima 	alloc_pages(systempage.pv_pa, 1);
    635       1.1  hamajima 
    636       1.1  hamajima 	/* Allocate stacks for all modes */
    637       1.1  hamajima 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    638       1.1  hamajima 	valloc_pages(abtstack, ABT_STACK_SIZE);
    639       1.1  hamajima 	valloc_pages(undstack, UND_STACK_SIZE);
    640       1.1  hamajima 	valloc_pages(kernelstack, UPAGES);
    641       1.1  hamajima 
    642       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    643       1.1  hamajima 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    644       1.1  hamajima 	    irqstack.pv_va);
    645       1.1  hamajima 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    646       1.1  hamajima 	    abtstack.pv_va);
    647       1.1  hamajima 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    648       1.1  hamajima 	    undstack.pv_va);
    649       1.1  hamajima 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    650       1.1  hamajima 	    kernelstack.pv_va);
    651       1.1  hamajima #endif
    652       1.1  hamajima 
    653       1.1  hamajima 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    654       1.1  hamajima 
    655       1.1  hamajima 	/*
    656       1.1  hamajima 	 * Ok we have allocated physical pages for the primary kernel
    657       1.1  hamajima 	 * page tables.  Save physical_freeend for when we give whats left
    658       1.1  hamajima 	 * of memory below 2Mbyte to UVM.
    659       1.1  hamajima 	 */
    660       1.1  hamajima 
    661       1.1  hamajima 	physical_freeend_low = physical_freeend;
    662       1.1  hamajima 
    663       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    664       1.1  hamajima 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    665       1.1  hamajima #endif
    666       1.1  hamajima 
    667       1.1  hamajima 	/*
    668       1.1  hamajima 	 * Now we start construction of the L1 page table
    669       1.1  hamajima 	 * We start by mapping the L2 page tables into the L1.
    670       1.1  hamajima 	 * This means that we can replace L1 mappings later on if necessary
    671       1.1  hamajima 	 */
    672       1.1  hamajima 	l1pagetable = kernel_l1pt.pv_pa;
    673       1.1  hamajima 
    674       1.1  hamajima 	/* Map the L2 pages tables in the L1 page table */
    675       1.1  hamajima 	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
    676       1.1  hamajima 	    &kernel_pt_table[KERNEL_PT_SYS]);
    677       1.1  hamajima 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    678       1.1  hamajima 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    679       1.1  hamajima 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    680       1.1  hamajima 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    681       1.1  hamajima 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    682       1.1  hamajima 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    683       1.1  hamajima 
    684       1.1  hamajima 	/* update the top of the kernel VM */
    685       1.1  hamajima 	pmap_curmaxkvaddr =
    686       1.1  hamajima 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    687       1.1  hamajima 
    688       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    689       1.1  hamajima 	printf("Mapping kernel\n");
    690       1.1  hamajima #endif
    691       1.1  hamajima 
    692       1.1  hamajima 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    693       1.1  hamajima 	{
    694       1.1  hamajima 		extern char etext[], _end[];
    695       1.1  hamajima 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    696       1.1  hamajima 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    697       1.1  hamajima 		u_int logical;
    698       1.1  hamajima 
    699       1.1  hamajima 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    700       1.1  hamajima 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    701       1.1  hamajima 
    702       1.1  hamajima 		logical = 0x00200000;	/* offset of kernel in RAM */
    703       1.1  hamajima 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    704       1.1  hamajima 		    physical_start + logical, textsize,
    705       1.1  hamajima 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    706       1.1  hamajima 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    707       1.1  hamajima 		    physical_start + logical, totalsize - textsize,
    708       1.1  hamajima 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    709       1.1  hamajima 	}
    710       1.1  hamajima 
    711       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    712       1.1  hamajima 	printf("Constructing L2 page tables\n");
    713       1.1  hamajima #endif
    714       1.1  hamajima 
    715       1.1  hamajima 	/* Map the stack pages */
    716       1.1  hamajima 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    717       1.1  hamajima 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    718       1.1  hamajima 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    719       1.1  hamajima 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    720       1.1  hamajima 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    721       1.1  hamajima 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    722       1.1  hamajima 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    723       1.1  hamajima 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    724       1.1  hamajima 
    725       1.1  hamajima 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    726       1.1  hamajima 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    727       1.1  hamajima 
    728       1.1  hamajima 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    729       1.1  hamajima 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    730       1.1  hamajima 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    731       1.1  hamajima 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    732       1.1  hamajima 	}
    733       1.1  hamajima 
    734       1.1  hamajima 	/* Map the vector page. */
    735       1.1  hamajima 	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
    736       1.1  hamajima 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    737       1.1  hamajima 
    738       1.1  hamajima 	/* Map the statically mapped devices. */
    739       1.1  hamajima 	pmap_devmap_bootstrap(l1pagetable, armadillo9_devmap);
    740       1.1  hamajima 
    741       1.1  hamajima 	/*
    742       1.1  hamajima 	 * Update the physical_freestart/physical_freeend/free_pages
    743       1.1  hamajima 	 * variables.
    744       1.1  hamajima 	 */
    745       1.1  hamajima 	{
    746       1.1  hamajima 		extern char _end[];
    747       1.1  hamajima 
    748       1.1  hamajima 		physical_freestart = physical_start +
    749       1.1  hamajima 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    750       1.1  hamajima 		     KERNEL_BASE);
    751       1.1  hamajima 		physical_freeend = physical_end;
    752       1.1  hamajima 		free_pages =
    753       1.1  hamajima 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    754       1.1  hamajima 	}
    755       1.1  hamajima 
    756       1.1  hamajima 	/*
    757       1.1  hamajima 	 * Now we have the real page tables in place so we can switch to them.
    758       1.1  hamajima 	 * Once this is done we will be running with the REAL kernel page
    759       1.1  hamajima 	 * tables.
    760       1.1  hamajima 	 */
    761       1.1  hamajima 
    762       1.1  hamajima 	/* Switch tables */
    763       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    764       1.1  hamajima 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    765       1.1  hamajima 	       physical_freestart, free_pages, free_pages);
    766       1.1  hamajima 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    767       1.1  hamajima #endif
    768       1.1  hamajima 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    769       1.1  hamajima 	setttb(kernel_l1pt.pv_pa);
    770       1.1  hamajima 	cpu_tlb_flushID();
    771       1.1  hamajima 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    772       1.1  hamajima 
    773       1.1  hamajima 	/*
    774       1.1  hamajima 	 * Moved from cpu_startup() as data_abort_handler() references
    775       1.1  hamajima 	 * this during uvm init
    776       1.1  hamajima 	 */
    777       1.1  hamajima 	proc0paddr = (struct user *)kernelstack.pv_va;
    778       1.1  hamajima 	lwp0.l_addr = proc0paddr;
    779       1.1  hamajima 
    780       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    781       1.1  hamajima 	printf("done!\n");
    782       1.1  hamajima #endif
    783       1.1  hamajima 
    784       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    785       1.1  hamajima 	printf("bootstrap done.\n");
    786       1.1  hamajima #endif
    787       1.1  hamajima 
    788       1.1  hamajima 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    789       1.1  hamajima 
    790       1.1  hamajima 	/*
    791       1.1  hamajima 	 * Pages were allocated during the secondary bootstrap for the
    792       1.1  hamajima 	 * stacks for different CPU modes.
    793       1.1  hamajima 	 * We must now set the r13 registers in the different CPU modes to
    794       1.1  hamajima 	 * point to these stacks.
    795       1.1  hamajima 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    796       1.1  hamajima 	 * of the stack memory.
    797       1.1  hamajima 	 */
    798       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    799       1.1  hamajima 	printf("init subsystems: stacks ");
    800       1.1  hamajima #endif
    801       1.1  hamajima 
    802       1.1  hamajima 	set_stackptr(PSR_IRQ32_MODE,
    803       1.1  hamajima 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    804       1.1  hamajima 	set_stackptr(PSR_ABT32_MODE,
    805       1.1  hamajima 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    806       1.1  hamajima 	set_stackptr(PSR_UND32_MODE,
    807       1.1  hamajima 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    808       1.1  hamajima 
    809       1.1  hamajima 	/*
    810       1.1  hamajima 	 * Well we should set a data abort handler.
    811       1.1  hamajima 	 * Once things get going this will change as we will need a proper
    812       1.1  hamajima 	 * handler.
    813       1.1  hamajima 	 * Until then we will use a handler that just panics but tells us
    814       1.1  hamajima 	 * why.
    815       1.1  hamajima 	 * Initialisation of the vectors will just panic on a data abort.
    816       1.1  hamajima 	 * This just fills in a slightly better one.
    817       1.1  hamajima 	 */
    818       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    819       1.1  hamajima 	printf("vectors ");
    820       1.1  hamajima #endif
    821       1.1  hamajima 	data_abort_handler_address = (u_int)data_abort_handler;
    822       1.1  hamajima 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    823       1.1  hamajima 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    824       1.1  hamajima 
    825       1.1  hamajima 	/* Initialise the undefined instruction handlers */
    826       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    827       1.1  hamajima 	printf("undefined ");
    828       1.1  hamajima #endif
    829       1.1  hamajima 	undefined_init();
    830       1.1  hamajima 
    831       1.1  hamajima 	/* Load memory into UVM. */
    832       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    833       1.1  hamajima 	printf("page ");
    834       1.1  hamajima #endif
    835       1.1  hamajima 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    836       1.1  hamajima 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    837       1.1  hamajima 	    atop(physical_freestart), atop(physical_freeend),
    838       1.1  hamajima 	    VM_FREELIST_DEFAULT);
    839       1.1  hamajima 	uvm_page_physload(atop(0xc0000000), atop(physical_freeend_low),
    840       1.1  hamajima 	    atop(0xc0000000), atop(physical_freeend_low),
    841       1.1  hamajima 	    VM_FREELIST_DEFAULT);
    842       1.3  hamajima 	physmem = bootconfig.dram[0].pages;
    843       1.3  hamajima 	for (loop = 1; loop < bootconfig.dramblocks; ++loop) {
    844       1.3  hamajima 		size_t start = bootconfig.dram[loop].address;
    845       1.3  hamajima 		size_t size = bootconfig.dram[loop].pages * PAGE_SIZE;
    846       1.3  hamajima 		uvm_page_physload(atop(start), atop(start + size),
    847       1.3  hamajima 				  atop(start), atop(start + size),
    848       1.3  hamajima 				  VM_FREELIST_DEFAULT);
    849       1.3  hamajima 		physmem += bootconfig.dram[loop].pages;
    850       1.3  hamajima 	}
    851       1.1  hamajima 
    852       1.1  hamajima 	/* Boot strap pmap telling it where the kernel page table is */
    853       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    854       1.1  hamajima 	printf("pmap ");
    855       1.1  hamajima #endif
    856  1.10.8.1      yamt 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    857       1.1  hamajima 
    858       1.1  hamajima 	/* Setup the IRQ system */
    859       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    860       1.1  hamajima 	printf("irq ");
    861       1.1  hamajima #endif
    862       1.1  hamajima 	ep93xx_intr_init();
    863       1.1  hamajima #if NISA > 0
    864       1.1  hamajima 	isa_intr_init();
    865       1.1  hamajima 
    866       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    867       1.1  hamajima 	printf("isa ");
    868       1.1  hamajima #endif
    869       1.1  hamajima 	isa_armadillo9_init(ARMADILLO9_IO16_VBASE + ARMADILLO9_ISAIO,
    870       1.1  hamajima 		ARMADILLO9_IO16_VBASE + ARMADILLO9_ISAMEM);
    871       1.1  hamajima #endif
    872       1.1  hamajima 
    873       1.1  hamajima #ifdef VERBOSE_INIT_ARM
    874       1.1  hamajima 	printf("done.\n");
    875       1.1  hamajima #endif
    876       1.1  hamajima 
    877       1.1  hamajima #ifdef BOOTHOWTO
    878       1.1  hamajima 	boothowto = BOOTHOWTO;
    879       1.1  hamajima #endif
    880       1.1  hamajima 
    881       1.1  hamajima #if NKSYMS || defined(DDB) || defined(LKM)
    882       1.1  hamajima 	/* Firmware doesn't load symbols. */
    883       1.1  hamajima 	ksyms_init(0, NULL, NULL);
    884       1.1  hamajima #endif
    885       1.1  hamajima 
    886       1.1  hamajima #ifdef DDB
    887       1.1  hamajima 	db_machine_init();
    888       1.1  hamajima 	if (boothowto & RB_KDB)
    889       1.1  hamajima 		Debugger();
    890       1.1  hamajima #endif
    891       1.1  hamajima 
    892       1.5   thorpej 	/* We have our own device_register() */
    893       1.5   thorpej 	evbarm_device_register = armadillo9_device_register;
    894       1.5   thorpej 
    895       1.1  hamajima 	/* We return the new stack pointer address */
    896       1.1  hamajima 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    897       1.1  hamajima }
    898       1.1  hamajima 
    899       1.1  hamajima void
    900       1.1  hamajima consinit(void)
    901       1.1  hamajima {
    902       1.1  hamajima 	static int consinit_called;
    903       1.1  hamajima #if NEPCOM > 0
    904       1.1  hamajima 	bus_space_handle_t ioh;
    905       1.1  hamajima #endif
    906       1.1  hamajima 
    907       1.1  hamajima 	if (consinit_called != 0)
    908       1.1  hamajima 		return;
    909       1.1  hamajima 
    910       1.1  hamajima 	consinit_called = 1;
    911       1.1  hamajima 
    912       1.1  hamajima 	/*
    913       1.1  hamajima 	 * Console devices are already mapped in VA.  Our devmap reflects
    914       1.1  hamajima 	 * this, so register it now so drivers can map the console
    915       1.1  hamajima 	 * device.
    916       1.1  hamajima 	 */
    917       1.1  hamajima 	pmap_devmap_register(armadillo9_devmap);
    918       1.1  hamajima 
    919       1.1  hamajima #if NEPCOM > 0
    920       1.4  hamajima 	bus_space_map(&ep93xx_bs_tag, EP93XX_APB_HWBASE + comaddr[CONUNIT],
    921       1.1  hamajima 		EP93XX_APB_UART_SIZE, 0, &ioh);
    922       1.4  hamajima         if (epcomcnattach(&ep93xx_bs_tag, EP93XX_APB_HWBASE + comaddr[CONUNIT],
    923       1.1  hamajima 		ioh, comcnspeed, comcnmode))
    924       1.1  hamajima 	{
    925       1.1  hamajima 		panic("can't init serial console");
    926       1.1  hamajima 	}
    927       1.1  hamajima #else
    928       1.1  hamajima 	panic("serial console not configured");
    929       1.1  hamajima #endif
    930       1.1  hamajima #if KGDB
    931       1.1  hamajima #if NEPCOM > 0
    932       1.1  hamajima 	if (strcmp(kgdb_devname, "epcom") == 0) {
    933       1.1  hamajima 		com_kgdb_attach(&ep93xx_bs_tag, kgdb_devaddr, kgdb_devrate,
    934       1.1  hamajima 			kgdb_devmode);
    935       1.1  hamajima 	}
    936       1.1  hamajima #endif	/* NEPCOM > 0 */
    937       1.1  hamajima #endif	/* KGDB */
    938       1.1  hamajima }
    939       1.1  hamajima 
    940       1.1  hamajima 
    941       1.1  hamajima bus_dma_tag_t
    942       1.1  hamajima ep93xx_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
    943       1.1  hamajima {
    944       1.1  hamajima 	int i;
    945       1.1  hamajima 	struct arm32_bus_dma_tag *dmat;
    946       1.1  hamajima 
    947       1.1  hamajima 	for (i = 0; i < bootconfig.dramblocks; i++) {
    948       1.1  hamajima 		armadillo9_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
    949       1.1  hamajima 		armadillo9_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
    950       1.1  hamajima 		armadillo9_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
    951       1.1  hamajima 			PAGE_SIZE;
    952       1.1  hamajima 	}
    953       1.1  hamajima 
    954       1.1  hamajima 	dmat = dma_tag_template;
    955       1.1  hamajima 
    956       1.1  hamajima 	dmat->_ranges = armadillo9_dma_ranges;
    957       1.1  hamajima 	dmat->_nranges = bootconfig.dramblocks;
    958       1.1  hamajima 
    959       1.1  hamajima 	return dmat;
    960       1.1  hamajima }
    961