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