Home | History | Annotate | Line # | Download | only in gemini
gemini_machdep.c revision 1.24
      1  1.24     rin /*	$NetBSD: gemini_machdep.c,v 1.24 2016/12/30 07:35:14 rin Exp $	*/
      2   1.1    matt 
      3   1.1    matt /* adapted from:
      4   1.1    matt  *	NetBSD: sdp24xx_machdep.c,v 1.4 2008/08/27 11:03:10 matt Exp
      5   1.1    matt  */
      6   1.1    matt 
      7   1.1    matt /*
      8   1.1    matt  * Machine dependent functions for kernel setup for TI OSK5912 board.
      9   1.1    matt  * Based on lubbock_machdep.c which in turn was based on iq80310_machhdep.c
     10   1.1    matt  *
     11   1.1    matt  * Copyright (c) 2002, 2003, 2005  Genetec Corporation.  All rights reserved.
     12   1.1    matt  * Written by Hiroyuki Bessho for Genetec Corporation.
     13   1.1    matt  *
     14   1.1    matt  * Redistribution and use in source and binary forms, with or without
     15   1.1    matt  * modification, are permitted provided that the following conditions
     16   1.1    matt  * are met:
     17   1.1    matt  * 1. Redistributions of source code must retain the above copyright
     18   1.1    matt  *    notice, this list of conditions and the following disclaimer.
     19   1.1    matt  * 2. Redistributions in binary form must reproduce the above copyright
     20   1.1    matt  *    notice, this list of conditions and the following disclaimer in the
     21   1.1    matt  *    documentation and/or other materials provided with the distribution.
     22   1.1    matt  * 3. The name of Genetec Corporation may not be used to endorse or
     23   1.1    matt  *    promote products derived from this software without specific prior
     24   1.1    matt  *    written permission.
     25   1.1    matt  *
     26   1.1    matt  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     27   1.1    matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1    matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1    matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     30   1.1    matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1    matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1    matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1    matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1    matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1    matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1    matt  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1    matt  *
     38   1.1    matt  * Copyright (c) 2001 Wasabi Systems, Inc.
     39   1.1    matt  * All rights reserved.
     40   1.1    matt  *
     41   1.1    matt  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     42   1.1    matt  *
     43   1.1    matt  * Redistribution and use in source and binary forms, with or without
     44   1.1    matt  * modification, are permitted provided that the following conditions
     45   1.1    matt  * are met:
     46   1.1    matt  * 1. Redistributions of source code must retain the above copyright
     47   1.1    matt  *    notice, this list of conditions and the following disclaimer.
     48   1.1    matt  * 2. Redistributions in binary form must reproduce the above copyright
     49   1.1    matt  *    notice, this list of conditions and the following disclaimer in the
     50   1.1    matt  *    documentation and/or other materials provided with the distribution.
     51   1.1    matt  * 3. All advertising materials mentioning features or use of this software
     52   1.1    matt  *    must display the following acknowledgement:
     53   1.1    matt  *	This product includes software developed for the NetBSD Project by
     54   1.1    matt  *	Wasabi Systems, Inc.
     55   1.1    matt  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     56   1.1    matt  *    or promote products derived from this software without specific prior
     57   1.1    matt  *    written permission.
     58   1.1    matt  *
     59   1.1    matt  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     60   1.1    matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     61   1.1    matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     62   1.1    matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     63   1.1    matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     64   1.1    matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     65   1.1    matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     66   1.1    matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     67   1.1    matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     68   1.1    matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     69   1.1    matt  * POSSIBILITY OF SUCH DAMAGE.
     70   1.1    matt  *
     71   1.1    matt  * Copyright (c) 1997,1998 Mark Brinicombe.
     72   1.1    matt  * Copyright (c) 1997,1998 Causality Limited.
     73   1.1    matt  * All rights reserved.
     74   1.1    matt  *
     75   1.1    matt  * Redistribution and use in source and binary forms, with or without
     76   1.1    matt  * modification, are permitted provided that the following conditions
     77   1.1    matt  * are met:
     78   1.1    matt  * 1. Redistributions of source code must retain the above copyright
     79   1.1    matt  *    notice, this list of conditions and the following disclaimer.
     80   1.1    matt  * 2. Redistributions in binary form must reproduce the above copyright
     81   1.1    matt  *    notice, this list of conditions and the following disclaimer in the
     82   1.1    matt  *    documentation and/or other materials provided with the distribution.
     83   1.1    matt  * 3. All advertising materials mentioning features or use of this software
     84   1.1    matt  *    must display the following acknowledgement:
     85   1.1    matt  *	This product includes software developed by Mark Brinicombe
     86   1.1    matt  *	for the NetBSD Project.
     87   1.1    matt  * 4. The name of the company nor the name of the author may be used to
     88   1.1    matt  *    endorse or promote products derived from this software without specific
     89   1.1    matt  *    prior written permission.
     90   1.1    matt  *
     91   1.1    matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     92   1.1    matt  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     93   1.1    matt  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     94   1.1    matt  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     95   1.1    matt  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     96   1.1    matt  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     97   1.1    matt  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     98   1.1    matt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     99   1.1    matt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    100   1.1    matt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    101   1.1    matt  * SUCH DAMAGE.
    102   1.1    matt  *
    103   1.1    matt  * Copyright (c) 2007 Microsoft
    104   1.1    matt  * All rights reserved.
    105   1.1    matt  *
    106   1.1    matt  * Redistribution and use in source and binary forms, with or without
    107   1.1    matt  * modification, are permitted provided that the following conditions
    108   1.1    matt  * are met:
    109   1.1    matt  * 1. Redistributions of source code must retain the above copyright
    110   1.1    matt  *    notice, this list of conditions and the following disclaimer.
    111   1.1    matt  * 2. Redistributions in binary form must reproduce the above copyright
    112   1.1    matt  *    notice, this list of conditions and the following disclaimer in the
    113   1.1    matt  *    documentation and/or other materials provided with the distribution.
    114   1.1    matt  * 3. All advertising materials mentioning features or use of this software
    115   1.1    matt  *    must display the following acknowledgement:
    116   1.1    matt  *	This product includes software developed by Microsoft
    117   1.1    matt  *
    118   1.1    matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
    119   1.1    matt  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    120   1.1    matt  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    121   1.1    matt  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTERS BE LIABLE FOR ANY DIRECT,
    122   1.1    matt  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    123   1.1    matt  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    124   1.1    matt  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    125   1.1    matt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    126   1.1    matt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    127   1.1    matt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    128   1.1    matt  * SUCH DAMAGE.
    129   1.1    matt  */
    130   1.1    matt 
    131   1.1    matt #include <sys/cdefs.h>
    132  1.24     rin __KERNEL_RCSID(0, "$NetBSD: gemini_machdep.c,v 1.24 2016/12/30 07:35:14 rin Exp $");
    133   1.1    matt 
    134   1.1    matt #include "opt_machdep.h"
    135   1.1    matt #include "opt_ddb.h"
    136   1.1    matt #include "opt_kgdb.h"
    137   1.1    matt #include "opt_ipkdb.h"
    138   1.1    matt #include "opt_md.h"
    139   1.1    matt #include "opt_com.h"
    140   1.1    matt #include "opt_gemini.h"
    141   1.1    matt #include "geminiwdt.h"
    142  1.11   cliff #include "geminiipm.h"
    143   1.1    matt 
    144   1.1    matt #include <sys/param.h>
    145   1.1    matt #include <sys/device.h>
    146   1.1    matt #include <sys/systm.h>
    147   1.1    matt #include <sys/kernel.h>
    148   1.1    matt #include <sys/exec.h>
    149   1.1    matt #include <sys/proc.h>
    150   1.1    matt #include <sys/msgbuf.h>
    151   1.1    matt #include <sys/reboot.h>
    152   1.1    matt #include <sys/termios.h>
    153   1.1    matt #include <sys/ksyms.h>
    154  1.22    matt #include <sys/bus.h>
    155  1.22    matt #include <sys/cpu.h>
    156  1.22    matt #include <sys/conf.h>
    157   1.1    matt 
    158   1.1    matt #include <uvm/uvm_extern.h>
    159   1.1    matt 
    160   1.1    matt #include <dev/cons.h>
    161   1.1    matt #include <dev/md.h>
    162   1.1    matt 
    163   1.1    matt #include <machine/db_machdep.h>
    164   1.1    matt #include <ddb/db_sym.h>
    165   1.1    matt #include <ddb/db_extern.h>
    166   1.1    matt #ifdef KGDB
    167   1.1    matt #include <sys/kgdb.h>
    168   1.1    matt #endif
    169   1.1    matt 
    170  1.22    matt #include <arm/locore.h>
    171   1.1    matt #include <arm/undefined.h>
    172   1.1    matt 
    173   1.1    matt #include <arm/arm32/machdep.h>
    174   1.1    matt 
    175  1.22    matt #include <machine/bootconfig.h>
    176  1.22    matt 
    177   1.1    matt #include <arm/gemini/gemini_reg.h>
    178   1.1    matt #include <arm/gemini/gemini_var.h>
    179   1.1    matt #include <arm/gemini/gemini_wdtvar.h>
    180   1.1    matt #include <arm/gemini/gemini_com.h>
    181   1.6   cliff #include <arm/gemini/lpc_com.h>
    182   1.1    matt 
    183   1.1    matt #include <evbarm/gemini/gemini.h>
    184   1.1    matt 
    185   1.6   cliff #if defined(VERBOSE_INIT_ARM)
    186   1.5   cliff # define GEMINI_PUTCHAR(c)	gemini_putchar(c)
    187   1.5   cliff # define GEMINI_PUTHEX(n)	gemini_puthex(n)
    188   1.5   cliff #else	/* VERBOSE_INIT_ARM */
    189   1.5   cliff # define GEMINI_PUTCHAR(c)
    190   1.5   cliff # define GEMINI_PUTHEX(n)
    191   1.5   cliff #endif	/* VERBOSE_INIT_ARM */
    192   1.5   cliff 
    193   1.1    matt BootConfig bootconfig;		/* Boot config storage */
    194   1.1    matt char *boot_args = NULL;
    195   1.1    matt char *boot_file = NULL;
    196   1.1    matt 
    197   1.1    matt /* Physical address of the beginning of SDRAM. */
    198   1.1    matt paddr_t physical_start;
    199   1.1    matt /* Physical address of the first byte after the end of SDRAM. */
    200   1.1    matt paddr_t physical_end;
    201   1.1    matt 
    202   1.1    matt /* Same things, but for the free (unused by the kernel) memory. */
    203   1.1    matt static paddr_t physical_freestart, physical_freeend;
    204   1.1    matt static u_int free_pages;
    205   1.1    matt 
    206   1.1    matt /* Physical address of the message buffer. */
    207   1.1    matt paddr_t msgbufphys;
    208   1.1    matt 
    209   1.1    matt extern char KERNEL_BASE_phys[];
    210   1.1    matt extern char KERNEL_BASE_virt[];
    211   1.1    matt extern char etext[], __data_start[], _edata[], __bss_start[], __bss_end__[];
    212   1.1    matt extern char _end[];
    213   1.1    matt 
    214   1.1    matt #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    215   1.1    matt #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    216   1.1    matt #define	KERNEL_PT_KERNEL_NUM	4
    217   1.1    matt #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
    218   1.1    matt 				        /* Page tables for mapping kernel VM */
    219   1.1    matt #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    220   1.1    matt #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    221   1.1    matt 
    222   1.1    matt pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    223   1.1    matt 
    224  1.11   cliff 
    225  1.11   cliff #if (NGEMINIIPM > 0)
    226  1.11   cliff pv_addr_t ipmq_pt;		/* L2 Page table for mapping IPM queues */
    227  1.11   cliff #if defined(DEBUG) || 1
    228  1.11   cliff unsigned long gemini_ipmq_pbase = GEMINI_IPMQ_PBASE;
    229  1.11   cliff unsigned long gemini_ipmq_vbase = GEMINI_IPMQ_VBASE;
    230  1.11   cliff #endif	/* DEBUG */
    231  1.11   cliff #endif	/* NGEMINIIPM > 0 */
    232  1.11   cliff 
    233  1.11   cliff 
    234   1.1    matt /*
    235   1.1    matt  * Macros to translate between physical and virtual for a subset of the
    236   1.1    matt  * kernel address space.  *Not* for general use.
    237   1.1    matt  */
    238   1.1    matt #define KERNEL_BASE_PHYS ((paddr_t)&KERNEL_BASE_phys)
    239   1.1    matt 
    240   1.1    matt #define KERN_VTOPHYS(va) \
    241   1.1    matt 	((paddr_t)((vaddr_t)va - KERNEL_BASE + GEMINI_DRAM_BASE))
    242   1.1    matt #define KERN_PHYSTOV(pa) \
    243   1.1    matt 	((vaddr_t)((paddr_t)pa - GEMINI_DRAM_BASE + KERNEL_BASE))
    244   1.1    matt 
    245   1.1    matt /* Prototypes */
    246   1.1    matt 
    247   1.1    matt void gemini_intr_init(bus_space_tag_t);
    248   1.1    matt void consinit(void);
    249   1.1    matt #ifdef KGDB
    250   1.1    matt static void kgdb_port_init(void);
    251   1.1    matt #endif
    252   1.1    matt 
    253   1.1    matt static void setup_real_page_tables(void);
    254   1.1    matt static void init_clocks(void);
    255   1.1    matt 
    256   1.1    matt bs_protos(bs_notimpl);
    257   1.1    matt 
    258   1.1    matt #include "com.h"
    259   1.1    matt #if NCOM > 0
    260   1.1    matt #include <dev/ic/comreg.h>
    261   1.1    matt #include <dev/ic/comvar.h>
    262   1.1    matt #endif
    263   1.1    matt 
    264   1.3   cliff 
    265   1.3   cliff static void gemini_global_reset(void) __attribute__ ((noreturn));
    266   1.8   cliff static void gemini_cpu1_start(void);
    267   1.9   cliff static void gemini_memchk(void);
    268   1.3   cliff 
    269   1.3   cliff static void
    270   1.3   cliff gemini_global_reset(void)
    271   1.3   cliff {
    272   1.8   cliff #if defined(GEMINI_MASTER) || defined(GEMINI_SINGLE)
    273   1.3   cliff 	volatile uint32_t *rp;
    274   1.3   cliff 	uint32_t r;
    275   1.3   cliff 
    276   1.3   cliff 	rp = (volatile uint32_t *)
    277   1.3   cliff 		(GEMINI_GLOBAL_VBASE + GEMINI_GLOBAL_RESET_CTL);
    278   1.3   cliff 	r = *rp;
    279   1.3   cliff 	r |= GLOBAL_RESET_GLOBAL;
    280   1.3   cliff 	*rp = r;
    281   1.8   cliff #endif
    282   1.3   cliff 	for(;;);
    283   1.3   cliff 	/* NOTREACHED */
    284   1.3   cliff }
    285   1.3   cliff 
    286   1.8   cliff static void
    287   1.8   cliff gemini_cpu1_start(void)
    288   1.8   cliff {
    289   1.8   cliff #ifdef GEMINI_MASTER
    290   1.8   cliff 	volatile uint32_t *rp;
    291   1.8   cliff 	uint32_t r;
    292   1.8   cliff 
    293   1.8   cliff 	rp = (volatile uint32_t *)
    294   1.8   cliff 		(GEMINI_GLOBAL_VBASE + GEMINI_GLOBAL_RESET_CTL);
    295   1.8   cliff 	r = *rp;
    296   1.8   cliff 	r &= ~GLOBAL_RESET_CPU1;
    297   1.8   cliff 	*rp = r;
    298   1.8   cliff #endif
    299   1.8   cliff }
    300   1.8   cliff 
    301   1.9   cliff static void
    302   1.9   cliff gemini_memchk(void)
    303   1.9   cliff {
    304   1.9   cliff 	volatile uint32_t *rp;
    305   1.9   cliff 	uint32_t r;
    306   1.9   cliff 	uint32_t base;
    307   1.9   cliff 	uint32_t size;
    308   1.9   cliff 
    309   1.9   cliff 	rp = (volatile uint32_t *)
    310   1.9   cliff 		(GEMINI_DRAMC_VBASE + GEMINI_DRAMC_RMCR);
    311   1.9   cliff 	r = *rp;
    312   1.9   cliff 	base = (r & DRAMC_RMCR_RMBAR) >> DRAMC_RMCR_RMBAR_SHFT;
    313   1.9   cliff 	size = (r & DRAMC_RMCR_RMSZR) >> DRAMC_RMCR_RMSZR_SHFT;
    314  1.10   cliff #if defined(GEMINI_SINGLE)
    315  1.10   cliff 	if (r != 0)
    316  1.10   cliff 		panic("%s: RMCR %#x, MEMSIZE %d mismatch\n",
    317  1.10   cliff 			__FUNCTION__, r, MEMSIZE);
    318  1.10   cliff #elif defined(GEMINI_MASTER)
    319   1.9   cliff 	if (base != MEMSIZE)
    320   1.9   cliff 		panic("%s: RMCR %#x, MEMSIZE %d mismatch\n",
    321   1.9   cliff 			__FUNCTION__, r, MEMSIZE);
    322  1.10   cliff #elif defined(GEMINI_SLAVE)
    323   1.9   cliff 	if (size != MEMSIZE)
    324   1.9   cliff 		panic("%s: RMCR %#x, MEMSIZE %d mismatch\n",
    325   1.9   cliff 			__FUNCTION__, r, MEMSIZE);
    326   1.9   cliff #endif
    327   1.9   cliff #if defined(VERBOSE_INIT_ARM) || 1
    328   1.9   cliff 	printf("DRAM Remap: base=%dMB, size=%dMB\n", base, size);
    329   1.9   cliff #endif
    330   1.9   cliff }
    331   1.9   cliff 
    332   1.1    matt /*
    333   1.1    matt  * void cpu_reboot(int howto, char *bootstr)
    334   1.1    matt  *
    335   1.1    matt  * Reboots the system
    336   1.1    matt  *
    337   1.1    matt  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    338   1.1    matt  * then reset the CPU.
    339   1.1    matt  */
    340   1.1    matt void
    341   1.1    matt cpu_reboot(int howto, char *bootstr)
    342   1.1    matt {
    343   1.5   cliff 	extern struct geminitmr_softc *ref_sc;
    344   1.5   cliff 
    345   1.1    matt #ifdef DIAGNOSTIC
    346   1.1    matt 	/* info */
    347   1.1    matt 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    348   1.1    matt #endif
    349   1.1    matt 
    350   1.1    matt 	/*
    351   1.1    matt 	 * If we are still cold then hit the air brakes
    352   1.1    matt 	 * and crash to earth fast
    353   1.1    matt 	 */
    354   1.1    matt 	if (cold) {
    355   1.1    matt 		doshutdownhooks();
    356   1.7  dyoung 		pmf_system_shutdown(boothowto);
    357   1.1    matt 		printf("The operating system has halted.\n");
    358   1.1    matt 		printf("Please press any key to reboot.\n\n");
    359   1.1    matt 		cngetc();
    360   1.1    matt 		printf("rebooting...\n");
    361   1.5   cliff 		if (ref_sc != NULL)
    362   1.5   cliff 			delay(2000);			/* cnflush(); */
    363   1.3   cliff 		gemini_global_reset();
    364   1.1    matt 		/*NOTREACHED*/
    365   1.1    matt 	}
    366   1.1    matt 
    367   1.1    matt 	/* Disable console buffering */
    368   1.8   cliff 	cnpollc(1);
    369   1.1    matt 
    370   1.1    matt 	/*
    371   1.1    matt 	 * If RB_NOSYNC was not specified sync the discs.
    372   1.1    matt 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    373   1.1    matt 	 * unmount.  It looks like syslogd is getting woken up only to find
    374   1.1    matt 	 * that it cannot page part of the binary in as the filesystem has
    375   1.1    matt 	 * been unmounted.
    376   1.1    matt 	 */
    377   1.1    matt 	if (!(howto & RB_NOSYNC))
    378   1.1    matt 		bootsync();
    379   1.1    matt 
    380   1.1    matt 	/* Say NO to interrupts */
    381   1.1    matt 	splhigh();
    382   1.1    matt 
    383   1.1    matt 	/* Do a dump if requested. */
    384   1.1    matt 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    385   1.1    matt 		dumpsys();
    386   1.1    matt 
    387   1.1    matt 	/* Run any shutdown hooks */
    388   1.1    matt 	doshutdownhooks();
    389   1.1    matt 
    390   1.7  dyoung 	pmf_system_shutdown(boothowto);
    391   1.7  dyoung 
    392   1.1    matt 	/* Make sure IRQ's are disabled */
    393   1.1    matt 	IRQdisable;
    394   1.1    matt 
    395   1.1    matt 	if (howto & RB_HALT) {
    396   1.1    matt 		printf("The operating system has halted.\n");
    397   1.1    matt 		printf("Please press any key to reboot.\n\n");
    398   1.1    matt 		cngetc();
    399   1.1    matt 	}
    400   1.1    matt 
    401   1.1    matt 	printf("rebooting...\n");
    402   1.5   cliff 	if (ref_sc != NULL)
    403   1.5   cliff 		delay(2000);			/* cnflush(); */
    404   1.3   cliff 	gemini_global_reset();
    405   1.1    matt 	/*NOTREACHED*/
    406   1.1    matt }
    407   1.1    matt 
    408   1.1    matt /*
    409   1.1    matt  * Static device mappings. These peripheral registers are mapped at
    410   1.1    matt  * fixed virtual addresses very early in initarm() so that we can use
    411   1.1    matt  * them while booting the kernel, and stay at the same address
    412   1.1    matt  * throughout whole kernel's life time.
    413   1.1    matt  *
    414   1.1    matt  * We use this table twice; once with bootstrap page table, and once
    415   1.1    matt  * with kernel's page table which we build up in initarm().
    416   1.1    matt  *
    417   1.1    matt  * Since we map these registers into the bootstrap page table using
    418   1.1    matt  * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
    419   1.1    matt  * registers segment-aligned and segment-rounded in order to avoid
    420   1.1    matt  * using the 2nd page tables.
    421   1.1    matt  */
    422   1.1    matt 
    423   1.1    matt #define	_A(a)	((a) & ~L1_S_OFFSET)
    424   1.1    matt #define	_S(s)	(((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    425   1.1    matt 
    426   1.1    matt static const struct pmap_devmap devmap[] = {
    427   1.3   cliff 	/* Global regs */
    428   1.3   cliff 	{
    429   1.3   cliff 		.pd_va = _A(GEMINI_GLOBAL_VBASE),
    430   1.3   cliff 		.pd_pa = _A(GEMINI_GLOBAL_BASE),
    431   1.3   cliff 		.pd_size = _S(L1_S_SIZE),
    432   1.3   cliff 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    433   1.3   cliff 		.pd_cache = PTE_NOCACHE
    434   1.3   cliff 	},
    435   1.3   cliff 
    436   1.1    matt 	/* Watchdog */
    437   1.1    matt 	{
    438   1.1    matt 		.pd_va = _A(GEMINI_WATCHDOG_VBASE),
    439   1.1    matt 		.pd_pa = _A(GEMINI_WATCHDOG_BASE),
    440   1.1    matt 		.pd_size = _S(L1_S_SIZE),
    441   1.1    matt 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    442   1.1    matt 		.pd_cache = PTE_NOCACHE
    443   1.1    matt 	},
    444   1.1    matt 
    445   1.1    matt 	/* UART */
    446   1.1    matt 	{
    447   1.6   cliff 		.pd_va = _A(GEMINI_UART_VBASE),
    448   1.6   cliff 		.pd_pa = _A(GEMINI_UART_BASE),
    449   1.1    matt 		.pd_size = _S(L1_S_SIZE),
    450   1.1    matt 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    451   1.1    matt 		.pd_cache = PTE_NOCACHE
    452   1.1    matt 	},
    453   1.1    matt 
    454   1.5   cliff 	/* LPCHC */
    455   1.5   cliff 	{
    456   1.5   cliff 		.pd_va = _A(GEMINI_LPCHC_VBASE),
    457   1.5   cliff 		.pd_pa = _A(GEMINI_LPCHC_BASE),
    458   1.5   cliff 		.pd_size = _S(L1_S_SIZE),
    459   1.5   cliff 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    460   1.5   cliff 		.pd_cache = PTE_NOCACHE
    461   1.5   cliff 	},
    462   1.5   cliff 
    463   1.5   cliff 	/* LPCIO */
    464   1.5   cliff 	{
    465   1.5   cliff 		.pd_va = _A(GEMINI_LPCIO_VBASE),
    466   1.5   cliff 		.pd_pa = _A(GEMINI_LPCIO_BASE),
    467   1.5   cliff 		.pd_size = _S(L1_S_SIZE),
    468   1.5   cliff 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    469   1.5   cliff 		.pd_cache = PTE_NOCACHE
    470   1.5   cliff 	},
    471   1.5   cliff 
    472   1.1    matt 	/* Timers */
    473   1.1    matt 	{
    474   1.1    matt 		.pd_va = _A(GEMINI_TIMER_VBASE),
    475   1.1    matt 		.pd_pa = _A(GEMINI_TIMER_BASE),
    476   1.1    matt 		.pd_size = _S(L1_S_SIZE),
    477   1.1    matt 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    478   1.1    matt 		.pd_cache = PTE_NOCACHE
    479   1.1    matt 	},
    480   1.1    matt 
    481   1.9   cliff 	/* DRAM Controller */
    482   1.9   cliff 	{
    483   1.9   cliff 		.pd_va = _A(GEMINI_DRAMC_VBASE),
    484   1.9   cliff 		.pd_pa = _A(GEMINI_DRAMC_BASE),
    485   1.9   cliff 		.pd_size = _S(L1_S_SIZE),
    486   1.9   cliff 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    487   1.9   cliff 		.pd_cache = PTE_NOCACHE
    488   1.9   cliff 	},
    489   1.9   cliff 
    490   1.5   cliff #if defined(MEMORY_DISK_DYNAMIC)
    491   1.5   cliff 	/* Ramdisk */
    492   1.5   cliff 	{
    493   1.5   cliff 		.pd_va = _A(GEMINI_RAMDISK_VBASE),
    494   1.5   cliff 		.pd_pa = _A(GEMINI_RAMDISK_PBASE),
    495   1.5   cliff 		.pd_size = _S(GEMINI_RAMDISK_SIZE),
    496   1.5   cliff 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,
    497   1.5   cliff 		.pd_cache = PTE_NOCACHE
    498   1.5   cliff 	},
    499   1.5   cliff #endif
    500   1.5   cliff 
    501   1.1    matt 	{0}	/* list terminator */
    502   1.1    matt };
    503   1.1    matt 
    504   1.1    matt #undef	_A
    505   1.1    matt #undef	_S
    506   1.1    matt 
    507   1.1    matt #ifdef DDB
    508   1.1    matt static void gemini_db_trap(int where)
    509   1.1    matt {
    510   1.1    matt #if  NGEMINIWDT > 0
    511   1.1    matt 	static int oldwatchdogstate;
    512   1.1    matt 
    513   1.1    matt 	if (where) {
    514   1.1    matt 		oldwatchdogstate = geminiwdt_enable(0);
    515   1.1    matt 	} else {
    516   1.1    matt 		geminiwdt_enable(oldwatchdogstate);
    517   1.1    matt 	}
    518   1.1    matt #endif
    519   1.1    matt }
    520   1.1    matt #endif
    521   1.1    matt 
    522   1.6   cliff #if defined(VERBOSE_INIT_ARM) || 1
    523   1.1    matt void gemini_putchar(char c);
    524   1.1    matt void
    525   1.1    matt gemini_putchar(char c)
    526   1.1    matt {
    527   1.6   cliff 	unsigned char *com0addr = (unsigned char *)GEMINI_UART_VBASE;
    528   1.1    matt 	int timo = 150000;
    529   1.1    matt 
    530   1.1    matt 	while ((com0addr[COM_REG_LSR * 4] & LSR_TXRDY) == 0)
    531   1.1    matt 		if (--timo == 0)
    532   1.1    matt 			break;
    533   1.1    matt 
    534   1.1    matt 	com0addr[COM_REG_TXDATA] = c;
    535   1.1    matt 
    536   1.1    matt 	while ((com0addr[COM_REG_LSR * 4] & LSR_TSRE) == 0)
    537   1.1    matt 		if (--timo == 0)
    538   1.1    matt 			break;
    539   1.1    matt }
    540   1.1    matt 
    541   1.1    matt void gemini_puthex(unsigned int);
    542   1.1    matt void
    543   1.1    matt gemini_puthex(unsigned int val)
    544   1.1    matt {
    545   1.1    matt 	char hexc[] = "0123456789abcdef";
    546   1.1    matt 
    547   1.1    matt 	gemini_putchar('0');
    548   1.1    matt 	gemini_putchar('x');
    549   1.1    matt 	gemini_putchar(hexc[(val >> 28) & 0xf]);
    550   1.1    matt 	gemini_putchar(hexc[(val >> 24) & 0xf]);
    551   1.1    matt 	gemini_putchar(hexc[(val >> 20) & 0xf]);
    552   1.1    matt 	gemini_putchar(hexc[(val >> 16) & 0xf]);
    553   1.1    matt 	gemini_putchar(hexc[(val >> 12) & 0xf]);
    554   1.1    matt 	gemini_putchar(hexc[(val >> 8) & 0xf]);
    555   1.1    matt 	gemini_putchar(hexc[(val >> 4) & 0xf]);
    556   1.1    matt 	gemini_putchar(hexc[(val >> 0) & 0xf]);
    557   1.1    matt }
    558   1.5   cliff #endif	/* VERBOSE_INIT_ARM */
    559   1.1    matt 
    560   1.1    matt /*
    561   1.1    matt  * u_int initarm(...)
    562   1.1    matt  *
    563   1.1    matt  * Initial entry point on startup. This gets called before main() is
    564   1.1    matt  * entered.
    565   1.1    matt  * It should be responsible for setting up everything that must be
    566   1.1    matt  * in place when main is called.
    567   1.1    matt  * This includes
    568   1.1    matt  *   Taking a copy of the boot configuration structure.
    569   1.1    matt  *   Initialising the physical console so characters can be printed.
    570   1.1    matt  *   Setting up page tables for the kernel
    571   1.1    matt  *   Relocating the kernel to the bottom of physical memory
    572   1.1    matt  */
    573   1.1    matt u_int
    574   1.1    matt initarm(void *arg)
    575   1.1    matt {
    576   1.5   cliff 	GEMINI_PUTCHAR('0');
    577   1.3   cliff 
    578   1.1    matt 	/*
    579   1.8   cliff 	 * start cpu#1 now
    580   1.8   cliff 	 */
    581   1.8   cliff 	gemini_cpu1_start();
    582   1.8   cliff 
    583   1.8   cliff 	/*
    584   1.1    matt 	 * When we enter here, we are using a temporary first level
    585   1.1    matt 	 * translation table with section entries in it to cover the OBIO
    586   1.1    matt 	 * peripherals and SDRAM.  The temporary first level translation table
    587   1.1    matt 	 * is at the end of SDRAM.
    588   1.1    matt 	 */
    589   1.1    matt 
    590   1.1    matt 	/* Heads up ... Setup the CPU / MMU / TLB functions. */
    591   1.5   cliff 	GEMINI_PUTCHAR('1');
    592   1.1    matt 	if (set_cpufuncs())
    593   1.1    matt 		panic("cpu not recognized!");
    594   1.1    matt 
    595   1.5   cliff 	GEMINI_PUTCHAR('2');
    596   1.1    matt 	init_clocks();
    597   1.5   cliff 	GEMINI_PUTCHAR('3');
    598   1.1    matt 
    599   1.1    matt 	/* The console is going to try to map things.  Give pmap a devmap. */
    600   1.1    matt 	pmap_devmap_register(devmap);
    601   1.5   cliff 	GEMINI_PUTCHAR('4');
    602   1.1    matt 	consinit();
    603   1.5   cliff 	GEMINI_PUTCHAR('5');
    604   1.1    matt #ifdef KGDB
    605   1.1    matt 	kgdb_port_init();
    606   1.1    matt #endif
    607   1.1    matt 
    608   1.1    matt 	/* Talk to the user */
    609   1.1    matt 	printf("\nNetBSD/evbarm (gemini) booting ...\n");
    610   1.1    matt 
    611   1.1    matt #ifdef BOOT_ARGS
    612   1.1    matt 	char mi_bootargs[] = BOOT_ARGS;
    613   1.1    matt 	parse_mi_bootargs(mi_bootargs);
    614   1.1    matt #endif
    615   1.1    matt 
    616   1.1    matt #ifdef VERBOSE_INIT_ARM
    617   1.1    matt 	printf("initarm: Configuring system ...\n");
    618   1.1    matt #endif
    619   1.1    matt 
    620   1.1    matt 	/*
    621   1.1    matt 	 * Set up the variables that define the availability of physical
    622   1.1    matt 	 * memory.
    623   1.1    matt 	 */
    624   1.9   cliff 	gemini_memchk();
    625   1.1    matt 	physical_start = GEMINI_DRAM_BASE;
    626   1.1    matt #define	MEMSIZE_BYTES 	(MEMSIZE * 1024 * 1024)
    627   1.1    matt 	physical_end = (physical_start & ~(0x400000-1)) + MEMSIZE_BYTES;
    628   1.1    matt 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    629   1.1    matt 
    630   1.1    matt 	/* Fake bootconfig structure for the benefit of pmap.c. */
    631   1.1    matt 	bootconfig.dramblocks = 1;
    632   1.1    matt 	bootconfig.dram[0].address = physical_start;
    633   1.1    matt 	bootconfig.dram[0].pages = physmem;
    634   1.1    matt 
    635   1.1    matt 	/*
    636   1.1    matt 	 * Our kernel is at the beginning of memory, so set our free space to
    637   1.1    matt 	 * all the memory after the kernel.
    638   1.1    matt 	 */
    639   1.1    matt 	physical_freestart = KERN_VTOPHYS(round_page((vaddr_t) _end));
    640   1.1    matt 	physical_freeend = physical_end;
    641   1.1    matt 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    642   1.1    matt 
    643   1.1    matt 	/*
    644   1.1    matt 	 * This is going to do all the hard work of setting up the first and
    645   1.1    matt 	 * and second level page tables.  Pages of memory will be allocated
    646   1.1    matt 	 * and mapped for other structures that are required for system
    647   1.1    matt 	 * operation.  When it returns, physical_freestart and free_pages will
    648   1.1    matt 	 * have been updated to reflect the allocations that were made.  In
    649   1.1    matt 	 * addition, kernel_l1pt, kernel_pt_table[], systempage, irqstack,
    650   1.1    matt 	 * abtstack, undstack, kernelstack, msgbufphys will be set to point to
    651   1.1    matt 	 * the memory that was allocated for them.
    652   1.1    matt 	 */
    653   1.1    matt 	setup_real_page_tables();
    654   1.1    matt 
    655   1.1    matt 	/*
    656   1.1    matt 	 * Moved from cpu_startup() as data_abort_handler() references
    657   1.1    matt 	 * this during uvm init.
    658   1.1    matt 	 */
    659  1.14   rmind 	uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
    660   1.1    matt 
    661   1.1    matt #ifdef VERBOSE_INIT_ARM
    662   1.1    matt 	printf("bootstrap done.\n");
    663   1.1    matt #endif
    664   1.1    matt 
    665   1.1    matt 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    666   1.1    matt 
    667   1.1    matt 	/*
    668   1.1    matt 	 * Pages were allocated during the secondary bootstrap for the
    669   1.1    matt 	 * stacks for different CPU modes.
    670   1.1    matt 	 * We must now set the r13 registers in the different CPU modes to
    671   1.1    matt 	 * point to these stacks.
    672   1.1    matt 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    673   1.1    matt 	 * of the stack memory.
    674   1.1    matt 	 */
    675   1.1    matt #ifdef VERBOSE_INIT_ARM
    676   1.1    matt 	printf("init subsystems: stacks ");
    677   1.1    matt #endif
    678   1.1    matt 
    679   1.1    matt 	set_stackptr(PSR_FIQ32_MODE, fiqstack.pv_va + FIQ_STACK_SIZE * PAGE_SIZE);
    680   1.1    matt 	set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    681   1.1    matt 	set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    682   1.1    matt 	set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    683   1.1    matt 
    684   1.1    matt 	/*
    685   1.1    matt 	 * Well we should set a data abort handler.
    686   1.1    matt 	 * Once things get going this will change as we will need a proper
    687   1.1    matt 	 * handler.
    688   1.1    matt 	 * Until then we will use a handler that just panics but tells us
    689   1.1    matt 	 * why.
    690   1.1    matt 	 * Initialisation of the vectors will just panic on a data abort.
    691   1.1    matt 	 * This just fills in a slightly better one.
    692   1.1    matt 	 */
    693   1.1    matt #ifdef VERBOSE_INIT_ARM
    694   1.1    matt 	printf("vectors ");
    695   1.1    matt #endif
    696   1.1    matt 	data_abort_handler_address = (u_int)data_abort_handler;
    697   1.1    matt 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    698   1.1    matt 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    699   1.1    matt 
    700   1.1    matt 	/* Initialise the undefined instruction handlers */
    701   1.1    matt #ifdef VERBOSE_INIT_ARM
    702   1.1    matt 	printf("undefined ");
    703   1.1    matt #endif
    704   1.1    matt 	undefined_init();
    705   1.1    matt 
    706   1.1    matt 	/* Load memory into UVM. */
    707   1.1    matt #ifdef VERBOSE_INIT_ARM
    708   1.1    matt 	printf("page ");
    709   1.1    matt #endif
    710  1.23  cherry 	uvm_md_init();
    711   1.5   cliff 
    712  1.11   cliff #if (GEMINI_RAM_RESV_PBASE != 0)
    713  1.11   cliff 	uvm_page_physload(atop(physical_freestart), atop(GEMINI_RAM_RESV_PBASE),
    714  1.11   cliff 	    atop(physical_freestart), atop(GEMINI_RAM_RESV_PBASE),
    715   1.5   cliff 	    VM_FREELIST_DEFAULT);
    716  1.11   cliff 	uvm_page_physload(atop(GEMINI_RAM_RESV_PEND), atop(physical_freeend),
    717  1.11   cliff 	    atop(GEMINI_RAM_RESV_PEND), atop(physical_freeend),
    718   1.5   cliff 	    VM_FREELIST_DEFAULT);
    719   1.5   cliff #else
    720   1.1    matt 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    721   1.1    matt 	    atop(physical_freestart), atop(physical_freeend),
    722   1.1    matt 	    VM_FREELIST_DEFAULT);
    723   1.5   cliff #endif
    724   1.2   cliff 	uvm_page_physload(atop(GEMINI_DRAM_BASE), atop(KERNEL_BASE_phys),
    725   1.2   cliff 	    atop(GEMINI_DRAM_BASE), atop(KERNEL_BASE_phys),
    726   1.2   cliff 	    VM_FREELIST_DEFAULT);
    727   1.1    matt 
    728   1.1    matt 	/* Boot strap pmap telling it where the kernel page table is */
    729   1.1    matt #ifdef VERBOSE_INIT_ARM
    730   1.1    matt 	printf("pmap ");
    731   1.1    matt #endif
    732   1.1    matt 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    733   1.1    matt 
    734   1.1    matt #ifdef VERBOSE_INIT_ARM
    735   1.1    matt 	printf("done.\n");
    736   1.1    matt #endif
    737   1.1    matt 
    738   1.1    matt #ifdef IPKDB
    739   1.1    matt 	/* Initialise ipkdb */
    740   1.1    matt 	ipkdb_init();
    741   1.1    matt 	if (boothowto & RB_KDB)
    742   1.1    matt 		ipkdb_connect(0);
    743   1.1    matt #endif
    744   1.1    matt 
    745   1.5   cliff #if defined(MEMORY_DISK_DYNAMIC)
    746   1.5   cliff 	md_root_setconf((char *)GEMINI_RAMDISK_VBASE, GEMINI_RAMDISK_SIZE);
    747   1.5   cliff #endif
    748   1.5   cliff 
    749   1.1    matt #ifdef KGDB
    750   1.1    matt 	if (boothowto & RB_KDB) {
    751   1.1    matt 		kgdb_debug_init = 1;
    752   1.1    matt 		kgdb_connect(1);
    753   1.1    matt 	}
    754   1.1    matt #endif
    755   1.1    matt 
    756   1.1    matt #ifdef DDB
    757   1.1    matt 	db_trap_callback = gemini_db_trap;
    758   1.1    matt 	db_machine_init();
    759   1.1    matt 
    760   1.1    matt 	/* Firmware doesn't load symbols. */
    761   1.1    matt 	ddb_init(0, NULL, NULL);
    762   1.1    matt 
    763   1.1    matt 	if (boothowto & RB_KDB)
    764   1.1    matt 		Debugger();
    765   1.1    matt #endif
    766   1.1    matt 	printf("initarm done.\n");
    767   1.1    matt 
    768   1.1    matt 	/* We return the new stack pointer address */
    769   1.1    matt 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    770   1.1    matt }
    771   1.1    matt 
    772   1.1    matt static void
    773   1.1    matt init_clocks(void)
    774   1.1    matt {
    775   1.1    matt }
    776   1.1    matt 
    777   1.1    matt #ifndef CONSADDR
    778   1.1    matt #error Specify the address of the console UART with the CONSADDR option.
    779   1.1    matt #endif
    780   1.1    matt #ifndef CONSPEED
    781   1.1    matt #define CONSPEED 19200
    782   1.1    matt #endif
    783   1.1    matt #ifndef CONMODE
    784   1.1    matt #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    785   1.1    matt #endif
    786   1.1    matt 
    787   1.1    matt static const bus_addr_t consaddr = CONSADDR;
    788   1.1    matt static const int conspeed = CONSPEED;
    789   1.1    matt static const int conmode = CONMODE;
    790   1.1    matt 
    791   1.6   cliff #if CONSADDR==0x42000000
    792   1.6   cliff /*
    793   1.6   cliff  * console initialization for obio com console
    794   1.6   cliff  */
    795   1.1    matt void
    796   1.1    matt consinit(void)
    797   1.1    matt {
    798   1.1    matt 	static int consinit_called = 0;
    799   1.1    matt 
    800   1.1    matt 	if (consinit_called != 0)
    801   1.1    matt 		return;
    802   1.1    matt 	consinit_called = 1;
    803   1.1    matt 
    804   1.1    matt 	if (comcnattach(&gemini_a4x_bs_tag, consaddr, conspeed,
    805   1.1    matt 		GEMINI_COM_FREQ, COM_TYPE_16550_NOERS, conmode))
    806   1.1    matt 			panic("Serial console can not be initialized.");
    807   1.6   cliff }
    808   1.6   cliff 
    809   1.6   cliff #elif CONSADDR==0x478003f8
    810   1.6   cliff # include <arm/gemini/gemini_lpcvar.h>
    811   1.6   cliff /*
    812   1.6   cliff  * console initialization for lpc com console
    813   1.6   cliff  */
    814   1.6   cliff void
    815   1.6   cliff consinit(void)
    816   1.6   cliff {
    817   1.6   cliff 	static int consinit_called = 0;
    818   1.6   cliff 	bus_space_tag_t iot = &gemini_bs_tag;
    819   1.6   cliff 	bus_space_handle_t lpchc_ioh;
    820   1.6   cliff 	bus_space_handle_t lpcio_ioh;
    821   1.6   cliff 	bus_size_t sz = L1_S_SIZE;
    822   1.6   cliff 	gemini_lpc_softc_t lpcsoftc;
    823   1.6   cliff 	gemini_lpc_bus_ops_t *ops;
    824   1.6   cliff 	void *lpctag = &lpcsoftc;
    825   1.6   cliff 	uint32_t r;
    826   1.6   cliff 	extern gemini_lpc_bus_ops_t gemini_lpc_bus_ops;
    827   1.6   cliff 
    828   1.6   cliff 	ops = &gemini_lpc_bus_ops;
    829   1.6   cliff 
    830   1.6   cliff 	if (consinit_called != 0)
    831   1.6   cliff 		return;
    832   1.6   cliff 	consinit_called = 1;
    833   1.6   cliff 
    834   1.6   cliff 	if (bus_space_map(iot, GEMINI_LPCHC_BASE, sz, 0, &lpchc_ioh))
    835   1.6   cliff 		panic("consinit: LPCHC can not be mapped.");
    836   1.6   cliff 
    837   1.6   cliff 	if (bus_space_map(iot, GEMINI_LPCIO_BASE, sz, 0, &lpcio_ioh))
    838   1.6   cliff 		panic("consinit: LPCIO can not be mapped.");
    839   1.6   cliff 
    840   1.6   cliff 	/* enable the LPC bus */
    841   1.6   cliff 	r = bus_space_read_4(iot, lpchc_ioh, GEMINI_LPCHC_CSR);
    842   1.6   cliff 	r |= LPCHC_CSR_BEN;
    843   1.6   cliff 	bus_space_write_4(iot, lpchc_ioh, GEMINI_LPCHC_CSR, r);
    844   1.6   cliff 
    845   1.6   cliff 	memset(&lpcsoftc, 0, sizeof(lpcsoftc));
    846   1.6   cliff 	lpcsoftc.sc_iot = iot;
    847   1.6   cliff 	lpcsoftc.sc_ioh = lpcio_ioh;
    848   1.6   cliff 
    849   1.6   cliff 	/* activate Serial Port 1 */
    850   1.6   cliff 	(*ops->lpc_pnp_enter)(lpctag);
    851   1.6   cliff 	(*ops->lpc_pnp_write)(lpctag, 1, 0x30, 0x01);
    852   1.6   cliff 	(*ops->lpc_pnp_exit)(lpctag);
    853   1.6   cliff 
    854   1.6   cliff 	if (comcnattach(iot, consaddr, conspeed,
    855   1.6   cliff 		IT8712F_COM_FREQ, COM_TYPE_NORMAL, conmode)) {
    856   1.6   cliff 			panic("Serial console can not be initialized.");
    857   1.6   cliff 	}
    858   1.1    matt 
    859   1.6   cliff 	bus_space_unmap(iot, lpcio_ioh, sz);
    860   1.6   cliff 	bus_space_unmap(iot, lpchc_ioh, sz);
    861   1.1    matt }
    862   1.6   cliff #else
    863   1.6   cliff # error unknown console
    864   1.6   cliff #endif
    865   1.1    matt 
    866   1.1    matt #ifdef KGDB
    867   1.1    matt #ifndef KGDB_DEVADDR
    868   1.1    matt #error Specify the address of the kgdb UART with the KGDB_DEVADDR option.
    869   1.1    matt #endif
    870   1.1    matt #ifndef KGDB_DEVRATE
    871   1.1    matt #define KGDB_DEVRATE 19200
    872   1.1    matt #endif
    873   1.1    matt 
    874   1.1    matt #ifndef KGDB_DEVMODE
    875   1.1    matt #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    876   1.1    matt #endif
    877   1.1    matt static const vaddr_t comkgdbaddr = KGDB_DEVADDR;
    878   1.1    matt static const int comkgdbspeed = KGDB_DEVRATE;
    879   1.1    matt static const int comkgdbmode = KGDB_DEVMODE;
    880   1.1    matt 
    881   1.1    matt void
    882   1.1    matt static kgdb_port_init(void)
    883   1.1    matt {
    884   1.1    matt 	static int kgdbsinit_called = 0;
    885   1.1    matt 
    886   1.1    matt 	if (kgdbsinit_called != 0)
    887   1.1    matt 		return;
    888   1.1    matt 
    889   1.1    matt 	kgdbsinit_called = 1;
    890   1.1    matt 
    891   1.1    matt 	bus_space_handle_t bh;
    892   1.1    matt 	if (bus_space_map(&gemini_a4x_bs_tag, comkgdbaddr,
    893   1.1    matt 		GEMINI_UART_SIZE, 0, &bh))
    894   1.1    matt 			panic("kgdb port can not be mapped.");
    895   1.1    matt 
    896   1.1    matt 	if (com_kgdb_attach(&gemini_a4x_bs_tag, comkgdbaddr, comkgdbspeed,
    897   1.1    matt 		GEMINI_UART_SIZE, COM_TYPE_16550_NOERS, comkgdbmode))
    898   1.1    matt 			panic("KGDB uart can not be initialized.");
    899   1.1    matt 
    900   1.1    matt 	bus_space_unmap(&gemini_a4x_bs_tag, bh, GEMINI_UART_SIZE);
    901   1.1    matt }
    902   1.1    matt #endif
    903   1.1    matt 
    904   1.1    matt static void
    905   1.1    matt setup_real_page_tables(void)
    906   1.1    matt {
    907   1.1    matt 	/*
    908   1.1    matt 	 * We need to allocate some fixed page tables to get the kernel going.
    909   1.1    matt 	 *
    910   1.1    matt 	 * We are going to allocate our bootstrap pages from the beginning of
    911   1.1    matt 	 * the free space that we just calculated.  We allocate one page
    912   1.1    matt 	 * directory and a number of page tables and store the physical
    913   1.1    matt 	 * addresses in the kernel_pt_table array.
    914   1.1    matt 	 *
    915   1.1    matt 	 * The kernel page directory must be on a 16K boundary.  The page
    916   1.1    matt 	 * tables must be on 4K boundaries.  What we do is allocate the
    917   1.1    matt 	 * page directory on the first 16K boundary that we encounter, and
    918   1.1    matt 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    919   1.1    matt 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    920   1.1    matt 	 * least one 16K aligned region.
    921   1.1    matt 	 */
    922   1.1    matt 
    923   1.1    matt #ifdef VERBOSE_INIT_ARM
    924   1.1    matt 	printf("Allocating page tables\n");
    925   1.1    matt #endif
    926   1.1    matt 
    927   1.1    matt 	/*
    928   1.1    matt 	 * Define a macro to simplify memory allocation.  As we allocate the
    929   1.1    matt 	 * memory, make sure that we don't walk over our temporary first level
    930   1.1    matt 	 * translation table.
    931   1.1    matt 	 */
    932   1.1    matt #define valloc_pages(var, np)						\
    933   1.1    matt 	(var).pv_pa = physical_freestart;				\
    934   1.1    matt 	physical_freestart += ((np) * PAGE_SIZE);			\
    935   1.1    matt 	if (physical_freestart > (physical_freeend - L1_TABLE_SIZE))	\
    936   1.1    matt 		panic("initarm: out of memory");			\
    937   1.1    matt 	free_pages -= (np);						\
    938   1.1    matt 	(var).pv_va = KERN_PHYSTOV((var).pv_pa);			\
    939   1.1    matt 	memset((char *)(var).pv_va, 0, ((np) * PAGE_SIZE));
    940   1.1    matt 
    941   1.1    matt 	int loop, pt_index;
    942   1.1    matt 
    943   1.1    matt 	pt_index = 0;
    944   1.1    matt 	kernel_l1pt.pv_pa = 0;
    945   1.1    matt 	kernel_l1pt.pv_va = 0;
    946   1.5   cliff #ifdef VERBOSE_INIT_ARM
    947   1.5   cliff 	printf("%s: physical_freestart %#lx\n", __func__, physical_freestart);
    948   1.5   cliff #endif
    949   1.1    matt 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    950   1.1    matt 		/* Are we 16KB aligned for an L1 ? */
    951   1.1    matt 		if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0
    952   1.1    matt 		    && kernel_l1pt.pv_pa == 0) {
    953   1.1    matt 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    954   1.1    matt 		} else {
    955   1.1    matt 			valloc_pages(kernel_pt_table[pt_index],
    956   1.1    matt 			    L2_TABLE_SIZE / PAGE_SIZE);
    957   1.1    matt 			++pt_index;
    958   1.1    matt 		}
    959   1.1    matt 	}
    960   1.5   cliff 
    961  1.11   cliff #if (NGEMINIIPM > 0)
    962  1.11   cliff 	valloc_pages(ipmq_pt, L2_TABLE_SIZE / PAGE_SIZE);
    963  1.11   cliff #endif
    964  1.11   cliff 
    965   1.5   cliff #ifdef VERBOSE_INIT_ARM
    966   1.5   cliff 	pt_index=0;
    967   1.5   cliff 	printf("%s: kernel_l1pt: %#lx:%#lx\n",
    968   1.5   cliff 		__func__, kernel_l1pt.pv_va, kernel_l1pt.pv_pa);
    969   1.5   cliff 	printf("%s: kernel_pt_table:\n", __func__);
    970   1.5   cliff 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    971   1.5   cliff 		printf("\t%#lx:%#lx\n", kernel_pt_table[pt_index].pv_va,
    972   1.5   cliff 			kernel_pt_table[pt_index].pv_pa);
    973   1.5   cliff 		++pt_index;
    974   1.5   cliff 	}
    975  1.11   cliff #if (NGEMINIIPM > 0)
    976  1.11   cliff 	printf("%s: ipmq_pt:\n", __func__);
    977  1.11   cliff 	printf("\t%#lx:%#lx\n", ipmq_pt.pv_va, ipmq_pt.pv_pa);
    978  1.11   cliff #endif
    979   1.5   cliff #endif
    980   1.1    matt 
    981   1.1    matt 	/* This should never be able to happen but better confirm that. */
    982   1.1    matt 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    983   1.1    matt 		panic("initarm: Failed to align the kernel page directory");
    984   1.1    matt 
    985   1.1    matt 	/*
    986   1.1    matt 	 * Allocate a page for the system page mapped to V0x00000000
    987   1.1    matt 	 * This page will just contain the system vectors and can be
    988   1.1    matt 	 * shared by all processes.
    989   1.1    matt 	 */
    990   1.1    matt 	valloc_pages(systempage, 1);
    991   1.1    matt 	systempage.pv_va = ARM_VECTORS_HIGH;
    992   1.1    matt 
    993   1.1    matt 	/* Allocate stacks for all modes */
    994   1.1    matt 	valloc_pages(fiqstack, FIQ_STACK_SIZE);
    995   1.1    matt 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    996   1.1    matt 	valloc_pages(abtstack, ABT_STACK_SIZE);
    997   1.1    matt 	valloc_pages(undstack, UND_STACK_SIZE);
    998   1.1    matt 	valloc_pages(kernelstack, UPAGES);
    999   1.1    matt 
   1000   1.1    matt 	/* Allocate the message buffer. */
   1001   1.1    matt 	pv_addr_t msgbuf;
   1002   1.1    matt 	int msgbuf_pgs = round_page(MSGBUFSIZE) / PAGE_SIZE;
   1003   1.1    matt 	valloc_pages(msgbuf, msgbuf_pgs);
   1004   1.1    matt 	msgbufphys = msgbuf.pv_pa;
   1005   1.1    matt 
   1006   1.1    matt 	/*
   1007   1.1    matt 	 * Ok we have allocated physical pages for the primary kernel
   1008   1.1    matt 	 * page tables
   1009   1.1    matt 	 */
   1010   1.1    matt 
   1011   1.1    matt #ifdef VERBOSE_INIT_ARM
   1012   1.1    matt 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
   1013   1.1    matt #endif
   1014   1.1    matt 
   1015   1.1    matt 	/*
   1016   1.1    matt 	 * Now we start construction of the L1 page table
   1017   1.1    matt 	 * We start by mapping the L2 page tables into the L1.
   1018   1.1    matt 	 * This means that we can replace L1 mappings later on if necessary
   1019   1.1    matt 	 */
   1020   1.1    matt 	vaddr_t l1_va = kernel_l1pt.pv_va;
   1021   1.1    matt 	paddr_t l1_pa = kernel_l1pt.pv_pa;
   1022   1.1    matt 
   1023   1.1    matt 	/* Map the L2 pages tables in the L1 page table */
   1024   1.1    matt 	pmap_link_l2pt(l1_va, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
   1025   1.1    matt 		       &kernel_pt_table[KERNEL_PT_SYS]);
   1026   1.1    matt 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
   1027   1.1    matt 		pmap_link_l2pt(l1_va, KERNEL_BASE + loop * 0x00400000,
   1028   1.1    matt 			       &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
   1029   1.1    matt 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
   1030   1.1    matt 		pmap_link_l2pt(l1_va, KERNEL_VM_BASE + loop * 0x00400000,
   1031   1.1    matt 			       &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
   1032   1.1    matt 
   1033   1.1    matt 	/* update the top of the kernel VM */
   1034   1.1    matt 	pmap_curmaxkvaddr =
   1035   1.1    matt 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
   1036   1.1    matt 
   1037  1.11   cliff #if (NGEMINIIPM > 0)
   1038  1.11   cliff printf("%s:%d: pmap_link_l2pt ipmq_pt\n", __FUNCTION__, __LINE__);
   1039  1.11   cliff 	pmap_link_l2pt(l1_va, GEMINI_IPMQ_VBASE, &ipmq_pt);
   1040  1.11   cliff #endif
   1041  1.11   cliff 
   1042   1.1    matt #ifdef VERBOSE_INIT_ARM
   1043   1.1    matt 	printf("Mapping kernel\n");
   1044   1.1    matt #endif
   1045   1.1    matt 
   1046   1.1    matt 	/* Now we fill in the L2 pagetable for the kernel static code/data */
   1047   1.1    matt #define round_L_page(x) (((x) + L2_L_OFFSET) & L2_L_FRAME)
   1048   1.1    matt 	size_t textsize = round_L_page(etext - KERNEL_BASE_virt);
   1049   1.1    matt 	size_t totalsize = round_L_page(_end - KERNEL_BASE_virt);
   1050   1.1    matt 	/* offset of kernel in RAM */
   1051   1.1    matt 	u_int offset = (u_int)KERNEL_BASE_virt - KERNEL_BASE;
   1052   1.1    matt 
   1053   1.9   cliff #ifdef DDB
   1054   1.9   cliff 	/* Map text section read-write. */
   1055   1.9   cliff 	offset += pmap_map_chunk(l1_va,
   1056   1.9   cliff 				(vaddr_t)KERNEL_BASE + offset,
   1057   1.9   cliff 				 physical_start + offset, textsize,
   1058   1.9   cliff 				 VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE,
   1059   1.9   cliff 				 PTE_CACHE);
   1060   1.9   cliff #else
   1061   1.1    matt 	/* Map text section read-only. */
   1062   1.1    matt 	offset += pmap_map_chunk(l1_va,
   1063   1.1    matt 				(vaddr_t)KERNEL_BASE + offset,
   1064   1.1    matt 				 physical_start + offset, textsize,
   1065   1.1    matt 				 VM_PROT_READ|VM_PROT_EXECUTE, PTE_CACHE);
   1066   1.9   cliff #endif
   1067   1.1    matt 	/* Map data and bss sections read-write. */
   1068   1.1    matt 	offset += pmap_map_chunk(l1_va,
   1069   1.1    matt 				(vaddr_t)KERNEL_BASE + offset,
   1070   1.1    matt 				 physical_start + offset, totalsize - textsize,
   1071   1.1    matt 				 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1072   1.1    matt 
   1073   1.1    matt #ifdef VERBOSE_INIT_ARM
   1074   1.1    matt 	printf("Constructing L2 page tables\n");
   1075   1.1    matt #endif
   1076   1.1    matt 
   1077   1.1    matt 	/* Map the stack pages */
   1078   1.1    matt 	pmap_map_chunk(l1_va, fiqstack.pv_va, fiqstack.pv_pa,
   1079   1.1    matt 	    FIQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1080   1.1    matt 	pmap_map_chunk(l1_va, irqstack.pv_va, irqstack.pv_pa,
   1081   1.1    matt 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1082   1.1    matt 	pmap_map_chunk(l1_va, abtstack.pv_va, abtstack.pv_pa,
   1083   1.1    matt 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1084   1.1    matt 	pmap_map_chunk(l1_va, undstack.pv_va, undstack.pv_pa,
   1085   1.1    matt 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1086   1.1    matt 	pmap_map_chunk(l1_va, kernelstack.pv_va, kernelstack.pv_pa,
   1087   1.1    matt 	    UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
   1088   1.1    matt 
   1089   1.1    matt 	pmap_map_chunk(l1_va, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
   1090   1.1    matt 	    L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
   1091   1.1    matt 
   1092   1.1    matt 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
   1093   1.1    matt 		pmap_map_chunk(l1_va, kernel_pt_table[loop].pv_va,
   1094   1.1    matt 			       kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
   1095   1.1    matt 			       VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
   1096   1.1    matt 	}
   1097   1.1    matt 
   1098   1.1    matt 	/* Map the vector page. */
   1099   1.1    matt 	pmap_map_entry(l1_va, ARM_VECTORS_HIGH, systempage.pv_pa,
   1100   1.1    matt 		       VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1101   1.1    matt 
   1102  1.11   cliff #if (NGEMINIIPM > 0)
   1103  1.11   cliff 	/* Map the IPM queue l2pt */
   1104  1.11   cliff 	pmap_map_chunk(l1_va, ipmq_pt.pv_va, ipmq_pt.pv_pa,
   1105  1.11   cliff 		L2_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
   1106  1.11   cliff 
   1107  1.11   cliff 	/* Map the IPM queue pages */
   1108  1.11   cliff 	pmap_map_chunk(l1_va, GEMINI_IPMQ_VBASE, GEMINI_IPMQ_PBASE,
   1109  1.11   cliff 	    GEMINI_IPMQ_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
   1110  1.11   cliff 
   1111  1.11   cliff #ifdef GEMINI_SLAVE
   1112  1.11   cliff 	/*
   1113  1.11   cliff 	 * Map all memory, incluuding that owned by other core
   1114  1.11   cliff 	 * take into account the RAM remap, so view in this region
   1115  1.11   cliff 	 * is consistent with MASTER
   1116  1.11   cliff 	 */
   1117  1.11   cliff 	pmap_map_chunk(l1_va,
   1118  1.11   cliff 	    GEMINI_ALLMEM_VBASE,
   1119  1.11   cliff 	    GEMINI_ALLMEM_PBASE + ((GEMINI_ALLMEM_SIZE - MEMSIZE) * 1024 * 1024),
   1120  1.11   cliff 	    (GEMINI_ALLMEM_SIZE - MEMSIZE) * 1024 * 1024,
   1121  1.11   cliff 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1122  1.11   cliff 	pmap_map_chunk(l1_va,
   1123  1.11   cliff 	    GEMINI_ALLMEM_VBASE + GEMINI_BUSBASE * 1024 * 1024,
   1124  1.11   cliff 	    GEMINI_ALLMEM_PBASE,
   1125  1.11   cliff 	    (MEMSIZE * 1024 * 1024),
   1126  1.11   cliff 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1127  1.11   cliff #else
   1128  1.11   cliff 	/* Map all memory, incluuding that owned by other core */
   1129  1.11   cliff 	pmap_map_chunk(l1_va, GEMINI_ALLMEM_VBASE, GEMINI_ALLMEM_PBASE,
   1130  1.11   cliff 	    GEMINI_ALLMEM_SIZE * 1024 * 1024, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
   1131  1.11   cliff #endif	/* GEMINI_SLAVE */
   1132  1.11   cliff #endif	/* NGEMINIIPM */
   1133  1.11   cliff 
   1134   1.1    matt 	/*
   1135   1.1    matt 	 * Map integrated peripherals at same address in first level page
   1136   1.1    matt 	 * table so that we can continue to use console.
   1137   1.1    matt 	 */
   1138   1.1    matt 	pmap_devmap_bootstrap(l1_va, devmap);
   1139   1.1    matt 
   1140   1.1    matt 
   1141   1.1    matt #ifdef VERBOSE_INIT_ARM
   1142   1.1    matt 	/* Tell the user about where all the bits and pieces live. */
   1143   1.1    matt 	printf("%22s       Physical              Virtual        Num\n", " ");
   1144   1.1    matt 	printf("%22s Starting    Ending    Starting    Ending   Pages\n", " ");
   1145   1.1    matt 
   1146   1.1    matt 	static const char mem_fmt[] =
   1147   1.1    matt 	    "%20s: 0x%08lx 0x%08lx 0x%08lx 0x%08lx %d\n";
   1148   1.1    matt 	static const char mem_fmt_nov[] =
   1149   1.1    matt 	    "%20s: 0x%08lx 0x%08lx                       %d\n";
   1150   1.1    matt 
   1151   1.1    matt 	printf(mem_fmt, "SDRAM", physical_start, physical_end-1,
   1152   1.1    matt 	    KERN_PHYSTOV(physical_start), KERN_PHYSTOV(physical_end-1),
   1153  1.24     rin 	    (int)physmem);
   1154   1.1    matt 	printf(mem_fmt, "text section",
   1155   1.1    matt 	       KERN_VTOPHYS(KERNEL_BASE_virt), KERN_VTOPHYS(etext-1),
   1156   1.1    matt 	       (vaddr_t)KERNEL_BASE_virt, (vaddr_t)etext-1,
   1157   1.1    matt 	       (int)(textsize / PAGE_SIZE));
   1158   1.1    matt 	printf(mem_fmt, "data section",
   1159   1.1    matt 	       KERN_VTOPHYS(__data_start), KERN_VTOPHYS(_edata),
   1160   1.1    matt 	       (vaddr_t)__data_start, (vaddr_t)_edata,
   1161   1.1    matt 	       (int)((round_page((vaddr_t)_edata)
   1162   1.1    matt 		      - trunc_page((vaddr_t)__data_start)) / PAGE_SIZE));
   1163   1.1    matt 	printf(mem_fmt, "bss section",
   1164   1.1    matt 	       KERN_VTOPHYS(__bss_start), KERN_VTOPHYS(__bss_end__),
   1165   1.1    matt 	       (vaddr_t)__bss_start, (vaddr_t)__bss_end__,
   1166   1.1    matt 	       (int)((round_page((vaddr_t)__bss_end__)
   1167   1.1    matt 		      - trunc_page((vaddr_t)__bss_start)) / PAGE_SIZE));
   1168   1.1    matt 	printf(mem_fmt, "L1 page directory",
   1169   1.1    matt 	    kernel_l1pt.pv_pa, kernel_l1pt.pv_pa + L1_TABLE_SIZE - 1,
   1170   1.1    matt 	    kernel_l1pt.pv_va, kernel_l1pt.pv_va + L1_TABLE_SIZE - 1,
   1171   1.1    matt 	    L1_TABLE_SIZE / PAGE_SIZE);
   1172   1.1    matt 	printf(mem_fmt, "Exception Vectors",
   1173   1.1    matt 	    systempage.pv_pa, systempage.pv_pa + PAGE_SIZE - 1,
   1174   1.1    matt 	    (vaddr_t)ARM_VECTORS_HIGH, (vaddr_t)ARM_VECTORS_HIGH + PAGE_SIZE - 1,
   1175   1.1    matt 	    1);
   1176   1.1    matt 	printf(mem_fmt, "FIQ stack",
   1177   1.1    matt 	    fiqstack.pv_pa, fiqstack.pv_pa + (FIQ_STACK_SIZE * PAGE_SIZE) - 1,
   1178   1.1    matt 	    fiqstack.pv_va, fiqstack.pv_va + (FIQ_STACK_SIZE * PAGE_SIZE) - 1,
   1179   1.1    matt 	    FIQ_STACK_SIZE);
   1180   1.1    matt 	printf(mem_fmt, "IRQ stack",
   1181   1.1    matt 	    irqstack.pv_pa, irqstack.pv_pa + (IRQ_STACK_SIZE * PAGE_SIZE) - 1,
   1182   1.1    matt 	    irqstack.pv_va, irqstack.pv_va + (IRQ_STACK_SIZE * PAGE_SIZE) - 1,
   1183   1.1    matt 	    IRQ_STACK_SIZE);
   1184   1.1    matt 	printf(mem_fmt, "ABT stack",
   1185   1.1    matt 	    abtstack.pv_pa, abtstack.pv_pa + (ABT_STACK_SIZE * PAGE_SIZE) - 1,
   1186   1.1    matt 	    abtstack.pv_va, abtstack.pv_va + (ABT_STACK_SIZE * PAGE_SIZE) - 1,
   1187   1.1    matt 	    ABT_STACK_SIZE);
   1188   1.1    matt 	printf(mem_fmt, "UND stack",
   1189   1.1    matt 	    undstack.pv_pa, undstack.pv_pa + (UND_STACK_SIZE * PAGE_SIZE) - 1,
   1190   1.1    matt 	    undstack.pv_va, undstack.pv_va + (UND_STACK_SIZE * PAGE_SIZE) - 1,
   1191   1.1    matt 	    UND_STACK_SIZE);
   1192   1.1    matt 	printf(mem_fmt, "SVC stack",
   1193   1.1    matt 	    kernelstack.pv_pa, kernelstack.pv_pa + (UPAGES * PAGE_SIZE) - 1,
   1194   1.1    matt 	    kernelstack.pv_va, kernelstack.pv_va + (UPAGES * PAGE_SIZE) - 1,
   1195   1.1    matt 	    UPAGES);
   1196   1.1    matt 	printf(mem_fmt_nov, "Message Buffer",
   1197   1.1    matt 	    msgbufphys, msgbufphys + msgbuf_pgs * PAGE_SIZE - 1, msgbuf_pgs);
   1198   1.1    matt 	printf(mem_fmt, "Free Memory", physical_freestart, physical_freeend-1,
   1199   1.1    matt 	    KERN_PHYSTOV(physical_freestart), KERN_PHYSTOV(physical_freeend-1),
   1200   1.1    matt 	    free_pages);
   1201   1.1    matt #endif
   1202   1.1    matt 
   1203   1.1    matt 	/*
   1204   1.1    matt 	 * Now we have the real page tables in place so we can switch to them.
   1205   1.1    matt 	 * Once this is done we will be running with the REAL kernel page
   1206   1.1    matt 	 * tables.
   1207   1.1    matt 	 */
   1208   1.1    matt 
   1209   1.1    matt 	/* Switch tables */
   1210   1.1    matt #ifdef VERBOSE_INIT_ARM
   1211   1.1    matt 	printf("switching to new L1 page table  @%#lx...", l1_pa);
   1212   1.1    matt #endif
   1213   1.1    matt 
   1214   1.1    matt 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
   1215  1.21    matt 	cpu_setttb(l1_pa, true);
   1216   1.1    matt 	cpu_tlb_flushID();
   1217   1.1    matt 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
   1218   1.1    matt 
   1219   1.1    matt #ifdef VERBOSE_INIT_ARM
   1220   1.1    matt 	printf("OK.\n");
   1221   1.1    matt #endif
   1222   1.1    matt }
   1223