Home | History | Annotate | Line # | Download | only in hdl_g
hdlg_machdep.c revision 1.16
      1  1.16    dyoung /*	$NetBSD: hdlg_machdep.c,v 1.16 2011/07/01 20:39:34 dyoung Exp $	*/
      2   1.1    nonaka 
      3   1.1    nonaka /*
      4   1.1    nonaka  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
      5   1.1    nonaka  * All rights reserved.
      6   1.1    nonaka  *
      7   1.1    nonaka  * Written by Jason R. Thorpe and Steve C. Woodford for Wasabi Systems, Inc.
      8   1.1    nonaka  *
      9   1.1    nonaka  * Redistribution and use in source and binary forms, with or without
     10   1.1    nonaka  * modification, are permitted provided that the following conditions
     11   1.1    nonaka  * are met:
     12   1.1    nonaka  * 1. Redistributions of source code must retain the above copyright
     13   1.1    nonaka  *    notice, this list of conditions and the following disclaimer.
     14   1.1    nonaka  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1    nonaka  *    notice, this list of conditions and the following disclaimer in the
     16   1.1    nonaka  *    documentation and/or other materials provided with the distribution.
     17   1.1    nonaka  * 3. All advertising materials mentioning features or use of this software
     18   1.1    nonaka  *    must display the following acknowledgement:
     19   1.1    nonaka  *	This product includes software developed for the NetBSD Project by
     20   1.1    nonaka  *	Wasabi Systems, Inc.
     21   1.1    nonaka  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22   1.1    nonaka  *    or promote products derived from this software without specific prior
     23   1.1    nonaka  *    written permission.
     24   1.1    nonaka  *
     25   1.1    nonaka  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26   1.1    nonaka  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27   1.1    nonaka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28   1.1    nonaka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29   1.1    nonaka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30   1.1    nonaka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31   1.1    nonaka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32   1.1    nonaka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33   1.1    nonaka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34   1.1    nonaka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35   1.1    nonaka  * POSSIBILITY OF SUCH DAMAGE.
     36   1.1    nonaka  */
     37   1.1    nonaka 
     38   1.1    nonaka /*
     39   1.1    nonaka  * Copyright (c) 1997,1998 Mark Brinicombe.
     40   1.1    nonaka  * Copyright (c) 1997,1998 Causality Limited.
     41   1.1    nonaka  * All rights reserved.
     42   1.1    nonaka  *
     43   1.1    nonaka  * Redistribution and use in source and binary forms, with or without
     44   1.1    nonaka  * modification, are permitted provided that the following conditions
     45   1.1    nonaka  * are met:
     46   1.1    nonaka  * 1. Redistributions of source code must retain the above copyright
     47   1.1    nonaka  *    notice, this list of conditions and the following disclaimer.
     48   1.1    nonaka  * 2. Redistributions in binary form must reproduce the above copyright
     49   1.1    nonaka  *    notice, this list of conditions and the following disclaimer in the
     50   1.1    nonaka  *    documentation and/or other materials provided with the distribution.
     51   1.1    nonaka  * 3. All advertising materials mentioning features or use of this software
     52   1.1    nonaka  *    must display the following acknowledgement:
     53   1.1    nonaka  *	This product includes software developed by Mark Brinicombe
     54   1.1    nonaka  *	for the NetBSD Project.
     55   1.1    nonaka  * 4. The name of the company nor the name of the author may be used to
     56   1.1    nonaka  *    endorse or promote products derived from this software without specific
     57   1.1    nonaka  *    prior written permission.
     58   1.1    nonaka  *
     59   1.1    nonaka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     60   1.1    nonaka  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     61   1.1    nonaka  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     62   1.1    nonaka  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     63   1.1    nonaka  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     64   1.1    nonaka  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     65   1.1    nonaka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66   1.1    nonaka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67   1.1    nonaka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68   1.1    nonaka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69   1.1    nonaka  * SUCH DAMAGE.
     70   1.1    nonaka  *
     71  1.15       wiz  * Machine dependent functions for kernel setup for GigaLANDISK
     72   1.1    nonaka  * using RedBoot firmware.
     73   1.1    nonaka  */
     74   1.1    nonaka 
     75   1.1    nonaka #include <sys/cdefs.h>
     76  1.16    dyoung __KERNEL_RCSID(0, "$NetBSD: hdlg_machdep.c,v 1.16 2011/07/01 20:39:34 dyoung Exp $");
     77   1.1    nonaka 
     78   1.1    nonaka #include "opt_ddb.h"
     79   1.1    nonaka #include "opt_kgdb.h"
     80   1.1    nonaka #include "opt_pmap_debug.h"
     81   1.1    nonaka 
     82   1.1    nonaka #include <sys/param.h>
     83   1.1    nonaka #include <sys/device.h>
     84   1.1    nonaka #include <sys/systm.h>
     85   1.1    nonaka #include <sys/kernel.h>
     86   1.1    nonaka #include <sys/exec.h>
     87   1.1    nonaka #include <sys/proc.h>
     88   1.1    nonaka #include <sys/msgbuf.h>
     89   1.1    nonaka #include <sys/reboot.h>
     90   1.1    nonaka #include <sys/termios.h>
     91   1.1    nonaka #include <sys/ksyms.h>
     92   1.1    nonaka 
     93   1.1    nonaka #include <uvm/uvm_extern.h>
     94   1.1    nonaka 
     95   1.1    nonaka #include <dev/cons.h>
     96   1.1    nonaka 
     97   1.1    nonaka #include <machine/db_machdep.h>
     98   1.1    nonaka #include <ddb/db_sym.h>
     99   1.1    nonaka #include <ddb/db_extern.h>
    100   1.1    nonaka 
    101   1.1    nonaka #include <machine/bootconfig.h>
    102  1.16    dyoung #include <sys/bus.h>
    103   1.1    nonaka #include <machine/cpu.h>
    104   1.1    nonaka #include <machine/frame.h>
    105   1.1    nonaka #include <arm/undefined.h>
    106   1.1    nonaka 
    107   1.1    nonaka #include <arm/arm32/machdep.h>
    108   1.1    nonaka 
    109   1.1    nonaka #include <arm/xscale/i80321reg.h>
    110   1.1    nonaka #include <arm/xscale/i80321var.h>
    111   1.1    nonaka 
    112   1.1    nonaka #include <dev/pci/ppbreg.h>
    113   1.1    nonaka 
    114   1.1    nonaka #include <evbarm/hdl_g/hdlgreg.h>
    115   1.1    nonaka #include <evbarm/hdl_g/hdlgvar.h>
    116   1.1    nonaka #include <evbarm/hdl_g/obiovar.h>
    117   1.1    nonaka 
    118   1.1    nonaka #include "ksyms.h"
    119   1.1    nonaka 
    120   1.1    nonaka /* Kernel text starts 2MB in from the bottom of the kernel address space. */
    121   1.1    nonaka #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
    122   1.1    nonaka #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    123   1.1    nonaka 
    124   1.1    nonaka /*
    125   1.1    nonaka  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
    126   1.1    nonaka  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    127   1.1    nonaka  */
    128   1.1    nonaka #define KERNEL_VM_SIZE		0x0C000000
    129   1.1    nonaka 
    130   1.1    nonaka /*
    131   1.1    nonaka  * Address to call from cpu_reset() to reset the machine.
    132  1.15       wiz  * This is machine architecture dependent as it varies depending
    133   1.1    nonaka  * on where the ROM appears when you turn the MMU off.
    134   1.1    nonaka  *
    135   1.1    nonaka  * XXX Not actually used on hdlg -- clean up the generic
    136   1.1    nonaka  * ARM code.
    137   1.1    nonaka  */
    138   1.1    nonaka u_int cpu_reset_address = 0x00000000;
    139   1.1    nonaka 
    140   1.1    nonaka /* Define various stack sizes in pages */
    141   1.1    nonaka #define IRQ_STACK_SIZE	1
    142   1.1    nonaka #define ABT_STACK_SIZE	1
    143   1.1    nonaka #define UND_STACK_SIZE	1
    144   1.1    nonaka 
    145   1.1    nonaka BootConfig bootconfig;		/* Boot config storage */
    146   1.1    nonaka char *boot_args = NULL;
    147   1.1    nonaka char *boot_file = NULL;
    148   1.1    nonaka 
    149   1.1    nonaka vm_offset_t physical_start;
    150   1.1    nonaka vm_offset_t physical_freestart;
    151   1.1    nonaka vm_offset_t physical_freeend;
    152   1.1    nonaka vm_offset_t physical_end;
    153   1.1    nonaka u_int free_pages;
    154   1.1    nonaka 
    155   1.1    nonaka /*int debug_flags;*/
    156   1.1    nonaka #ifndef PMAP_STATIC_L1S
    157   1.1    nonaka int max_processes = 64;			/* Default number */
    158   1.1    nonaka #endif	/* !PMAP_STATIC_L1S */
    159   1.1    nonaka 
    160   1.1    nonaka /* Physical and virtual addresses for some global pages */
    161   1.1    nonaka pv_addr_t irqstack;
    162   1.1    nonaka pv_addr_t undstack;
    163   1.1    nonaka pv_addr_t abtstack;
    164   1.1    nonaka pv_addr_t kernelstack;
    165   1.1    nonaka pv_addr_t minidataclean;
    166   1.1    nonaka 
    167   1.1    nonaka vm_offset_t msgbufphys;
    168   1.1    nonaka 
    169   1.1    nonaka extern u_int data_abort_handler_address;
    170   1.1    nonaka extern u_int prefetch_abort_handler_address;
    171   1.1    nonaka extern u_int undefined_handler_address;
    172   1.1    nonaka 
    173   1.1    nonaka #ifdef PMAP_DEBUG
    174   1.1    nonaka extern int pmap_debug_level;
    175   1.1    nonaka #endif
    176   1.1    nonaka 
    177   1.1    nonaka #define KERNEL_PT_SYS		0	/* L2 table for mapping zero page */
    178   1.1    nonaka 
    179   1.1    nonaka #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
    180   1.1    nonaka #define	KERNEL_PT_KERNEL_NUM	4
    181   1.1    nonaka 
    182   1.1    nonaka 					/* L2 table for mapping i80321 */
    183   1.1    nonaka #define	KERNEL_PT_IOPXS		(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    184   1.1    nonaka 
    185   1.1    nonaka 					/* L2 tables for mapping kernel VM */
    186   1.1    nonaka #define KERNEL_PT_VMDATA	(KERNEL_PT_IOPXS + 1)
    187   1.1    nonaka #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    188   1.1    nonaka #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    189   1.1    nonaka 
    190   1.1    nonaka pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    191   1.1    nonaka 
    192   1.1    nonaka /* Prototypes */
    193   1.1    nonaka void consinit(void);
    194   1.1    nonaka 
    195   1.1    nonaka /* Static device mappings. */
    196   1.1    nonaka static const struct pmap_devmap hdlg_devmap[] = {
    197   1.1    nonaka     /*
    198   1.1    nonaka      * Map the on-board devices VA == PA so that we can access them
    199   1.1    nonaka      * with the MMU on or off.
    200   1.1    nonaka      */
    201   1.1    nonaka     {
    202   1.1    nonaka 	HDLG_OBIO_BASE,
    203   1.1    nonaka 	HDLG_OBIO_BASE,
    204   1.1    nonaka 	HDLG_OBIO_SIZE,
    205   1.1    nonaka 	VM_PROT_READ|VM_PROT_WRITE,
    206   1.1    nonaka 	PTE_NOCACHE,
    207   1.1    nonaka     },
    208   1.1    nonaka 
    209   1.1    nonaka     {
    210   1.1    nonaka 	HDLG_IOW_VBASE,
    211   1.1    nonaka 	VERDE_OUT_XLATE_IO_WIN0_BASE,
    212   1.1    nonaka 	VERDE_OUT_XLATE_IO_WIN_SIZE,
    213   1.1    nonaka 	VM_PROT_READ|VM_PROT_WRITE,
    214   1.1    nonaka 	PTE_NOCACHE,
    215   1.1    nonaka    },
    216   1.1    nonaka 
    217   1.1    nonaka    {
    218   1.1    nonaka 	HDLG_80321_VBASE,
    219   1.1    nonaka 	VERDE_PMMR_BASE,
    220   1.1    nonaka 	VERDE_PMMR_SIZE,
    221   1.1    nonaka 	VM_PROT_READ|VM_PROT_WRITE,
    222   1.1    nonaka 	PTE_NOCACHE,
    223   1.1    nonaka    },
    224   1.1    nonaka 
    225   1.1    nonaka    {
    226   1.1    nonaka 	0,
    227   1.1    nonaka 	0,
    228   1.1    nonaka 	0,
    229   1.1    nonaka 	0,
    230   1.1    nonaka 	0,
    231   1.1    nonaka     }
    232   1.1    nonaka };
    233   1.1    nonaka 
    234   1.1    nonaka static void
    235   1.1    nonaka hardclock_hook(void)
    236   1.1    nonaka {
    237   1.1    nonaka 
    238   1.1    nonaka 	/* Nothing to do */
    239   1.1    nonaka }
    240   1.1    nonaka 
    241   1.1    nonaka /*
    242   1.1    nonaka  * u_int initarm(...)
    243   1.1    nonaka  *
    244   1.1    nonaka  * Initial entry point on startup. This gets called before main() is
    245   1.1    nonaka  * entered.
    246   1.1    nonaka  * It should be responsible for setting up everything that must be
    247   1.1    nonaka  * in place when main is called.
    248   1.1    nonaka  * This includes
    249   1.1    nonaka  *   Taking a copy of the boot configuration structure.
    250   1.1    nonaka  *   Initialising the physical console so characters can be printed.
    251   1.1    nonaka  *   Setting up page tables for the kernel
    252   1.1    nonaka  *   Relocating the kernel to the bottom of physical memory
    253   1.1    nonaka  */
    254   1.1    nonaka u_int
    255   1.1    nonaka initarm(void *arg)
    256   1.1    nonaka {
    257   1.1    nonaka 	extern vaddr_t xscale_cache_clean_addr;
    258   1.1    nonaka #ifdef DIAGNOSTIC
    259   1.1    nonaka 	extern vsize_t xscale_minidata_clean_size;
    260   1.1    nonaka #endif
    261   1.1    nonaka 	int loop;
    262   1.1    nonaka 	int loop1;
    263   1.1    nonaka 	u_int l1pagetable;
    264   1.1    nonaka 	paddr_t memstart;
    265   1.1    nonaka 	psize_t memsize;
    266   1.1    nonaka 
    267   1.1    nonaka 	/* Calibrate the delay loop. */
    268   1.1    nonaka 	i80321_calibrate_delay();
    269   1.1    nonaka 	i80321_hardclock_hook = hardclock_hook;
    270   1.1    nonaka 
    271   1.1    nonaka 	/*
    272   1.1    nonaka 	 * Since we map the on-board devices VA==PA, and the kernel
    273   1.1    nonaka 	 * is running VA==PA, it's possible for us to initialize
    274   1.1    nonaka 	 * the console now.
    275   1.1    nonaka 	 */
    276   1.1    nonaka 	consinit();
    277   1.1    nonaka 
    278   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    279   1.1    nonaka 	/* Talk to the user */
    280   1.4    nonaka 	printf("\nNetBSD/evbarm (HDL-G) booting ...\n");
    281   1.1    nonaka #endif
    282   1.1    nonaka 
    283   1.1    nonaka 	/*
    284   1.1    nonaka 	 * Heads up ... Setup the CPU / MMU / TLB functions
    285   1.1    nonaka 	 */
    286   1.1    nonaka 	if (set_cpufuncs())
    287   1.1    nonaka 		panic("CPU not recognized!");
    288   1.1    nonaka 
    289   1.1    nonaka 	/*
    290   1.1    nonaka 	 * We are currently running with the MMU enabled and the
    291   1.1    nonaka 	 * entire address space mapped VA==PA, except for the
    292   1.1    nonaka 	 * first 64M of RAM is also double-mapped at 0xc0000000.
    293   1.1    nonaka 	 * There is an L1 page table at 0xa0004000.
    294   1.1    nonaka 	 */
    295   1.1    nonaka 
    296   1.1    nonaka 	/*
    297   1.1    nonaka 	 * Fetch the SDRAM start/size from the i80321 SDRAM configuration
    298   1.1    nonaka 	 * registers.
    299   1.1    nonaka 	 */
    300   1.1    nonaka 	i80321_sdram_bounds(&obio_bs_tag, VERDE_PMMR_BASE + VERDE_MCU_BASE,
    301   1.1    nonaka 	    &memstart, &memsize);
    302   1.1    nonaka 
    303   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    304   1.1    nonaka 	printf("initarm: Configuring system ...\n");
    305   1.1    nonaka #endif
    306   1.1    nonaka 
    307   1.1    nonaka 	/* Fake bootconfig structure for the benefit of pmap.c */
    308   1.3       wiz 	/* XXX must make the memory description h/w independent */
    309   1.1    nonaka 	bootconfig.dramblocks = 1;
    310   1.1    nonaka 	bootconfig.dram[0].address = memstart;
    311   1.1    nonaka 	bootconfig.dram[0].pages = memsize / PAGE_SIZE;
    312   1.1    nonaka 
    313   1.1    nonaka 	/*
    314   1.1    nonaka 	 * Set up the variables that define the availablilty of
    315   1.1    nonaka 	 * physical memory.  For now, we're going to set
    316   1.1    nonaka 	 * physical_freestart to 0xa0200000 (where the kernel
    317   1.1    nonaka 	 * was loaded), and allocate the memory we need downwards.
    318   1.1    nonaka 	 * If we get too close to the L1 table that we set up, we
    319   1.1    nonaka 	 * will panic.  We will update physical_freestart and
    320   1.1    nonaka 	 * physical_freeend later to reflect what pmap_bootstrap()
    321   1.1    nonaka 	 * wants to see.
    322   1.1    nonaka 	 *
    323   1.1    nonaka 	 * XXX pmap_bootstrap() needs an enema.
    324   1.1    nonaka 	 */
    325   1.1    nonaka 	physical_start = bootconfig.dram[0].address;
    326   1.1    nonaka 	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
    327   1.1    nonaka 
    328   1.1    nonaka 	physical_freestart = 0xa0009000UL;
    329   1.1    nonaka 	physical_freeend = 0xa0200000UL;
    330   1.1    nonaka 
    331   1.1    nonaka 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    332   1.1    nonaka 
    333   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    334   1.1    nonaka 	/* Tell the user about the memory */
    335   1.1    nonaka 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    336   1.1    nonaka 	    physical_start, physical_end - 1);
    337   1.1    nonaka #endif
    338   1.1    nonaka 
    339   1.1    nonaka 	/*
    340   1.1    nonaka 	 * Okay, the kernel starts 2MB in from the bottom of physical
    341   1.1    nonaka 	 * memory.  We are going to allocate our bootstrap pages downwards
    342   1.1    nonaka 	 * from there.
    343   1.1    nonaka 	 *
    344   1.1    nonaka 	 * We need to allocate some fixed page tables to get the kernel
    345   1.1    nonaka 	 * going.  We allocate one page directory and a number of page
    346   1.1    nonaka 	 * tables and store the physical addresses in the kernel_pt_table
    347   1.1    nonaka 	 * array.
    348   1.1    nonaka 	 *
    349   1.1    nonaka 	 * The kernel page directory must be on a 16K boundary.  The page
    350   1.1    nonaka 	 * tables must be on 4K boundaries.  What we do is allocate the
    351   1.1    nonaka 	 * page directory on the first 16K boundary that we encounter, and
    352   1.1    nonaka 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    353   1.1    nonaka 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    354   1.1    nonaka 	 * least one 16K aligned region.
    355   1.1    nonaka 	 */
    356   1.1    nonaka 
    357   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    358   1.1    nonaka 	printf("Allocating page tables\n");
    359   1.1    nonaka #endif
    360   1.1    nonaka 
    361   1.1    nonaka 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    362   1.1    nonaka 
    363   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    364   1.1    nonaka 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    365   1.1    nonaka 	       physical_freestart, free_pages, free_pages);
    366   1.1    nonaka #endif
    367   1.1    nonaka 
    368   1.1    nonaka 	/* Define a macro to simplify memory allocation */
    369   1.1    nonaka #define	valloc_pages(var, np)				\
    370   1.1    nonaka 	alloc_pages((var).pv_pa, (np));			\
    371   1.1    nonaka 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    372   1.1    nonaka 
    373   1.1    nonaka #define alloc_pages(var, np)				\
    374   1.1    nonaka 	physical_freeend -= ((np) * PAGE_SIZE);		\
    375   1.1    nonaka 	if (physical_freeend < physical_freestart)	\
    376   1.1    nonaka 		panic("initarm: out of memory");	\
    377   1.1    nonaka 	(var) = physical_freeend;			\
    378   1.1    nonaka 	free_pages -= (np);				\
    379   1.1    nonaka 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    380   1.1    nonaka 
    381   1.1    nonaka 	loop1 = 0;
    382   1.1    nonaka 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    383   1.1    nonaka 		/* Are we 16KB aligned for an L1 ? */
    384   1.1    nonaka 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    385   1.1    nonaka 		    && kernel_l1pt.pv_pa == 0) {
    386   1.1    nonaka 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    387   1.1    nonaka 		} else {
    388   1.1    nonaka 			valloc_pages(kernel_pt_table[loop1],
    389   1.1    nonaka 			    L2_TABLE_SIZE / PAGE_SIZE);
    390   1.1    nonaka 			++loop1;
    391   1.1    nonaka 		}
    392   1.1    nonaka 	}
    393   1.1    nonaka 
    394   1.1    nonaka 	/* This should never be able to happen but better confirm that. */
    395   1.1    nonaka 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    396   1.1    nonaka 		panic("initarm: Failed to align the kernel page directory");
    397   1.1    nonaka 
    398   1.1    nonaka 	/*
    399   1.1    nonaka 	 * Allocate a page for the system page mapped to V0x00000000
    400   1.1    nonaka 	 * This page will just contain the system vectors and can be
    401   1.1    nonaka 	 * shared by all processes.
    402   1.1    nonaka 	 */
    403   1.1    nonaka 	alloc_pages(systempage.pv_pa, 1);
    404   1.1    nonaka 
    405   1.1    nonaka 	/* Allocate stacks for all modes */
    406   1.1    nonaka 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    407   1.1    nonaka 	valloc_pages(abtstack, ABT_STACK_SIZE);
    408   1.1    nonaka 	valloc_pages(undstack, UND_STACK_SIZE);
    409   1.1    nonaka 	valloc_pages(kernelstack, UPAGES);
    410   1.1    nonaka 
    411   1.1    nonaka 	/* Allocate enough pages for cleaning the Mini-Data cache. */
    412   1.1    nonaka 	KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
    413   1.1    nonaka 	valloc_pages(minidataclean, 1);
    414   1.1    nonaka 
    415   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    416   1.1    nonaka 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    417   1.1    nonaka 	    irqstack.pv_va);
    418   1.1    nonaka 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    419   1.1    nonaka 	    abtstack.pv_va);
    420   1.1    nonaka 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    421   1.1    nonaka 	    undstack.pv_va);
    422   1.1    nonaka 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    423   1.1    nonaka 	    kernelstack.pv_va);
    424   1.1    nonaka #endif
    425   1.1    nonaka 
    426   1.1    nonaka 	/*
    427   1.1    nonaka 	 * XXX Defer this to later so that we can reclaim the memory
    428   1.1    nonaka 	 * XXX used by the RedBoot page tables.
    429   1.1    nonaka 	 */
    430   1.1    nonaka 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    431   1.1    nonaka 
    432   1.1    nonaka 	/*
    433   1.1    nonaka 	 * Ok we have allocated physical pages for the primary kernel
    434   1.1    nonaka 	 * page tables
    435   1.1    nonaka 	 */
    436   1.1    nonaka 
    437   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    438   1.1    nonaka 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    439   1.1    nonaka #endif
    440   1.1    nonaka 
    441   1.1    nonaka 	/*
    442   1.1    nonaka 	 * Now we start construction of the L1 page table
    443   1.1    nonaka 	 * We start by mapping the L2 page tables into the L1.
    444   1.1    nonaka 	 * This means that we can replace L1 mappings later on if necessary
    445   1.1    nonaka 	 */
    446   1.1    nonaka 	l1pagetable = kernel_l1pt.pv_pa;
    447   1.1    nonaka 
    448   1.1    nonaka 	/* Map the L2 pages tables in the L1 page table */
    449   1.1    nonaka 	pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
    450   1.1    nonaka 	    &kernel_pt_table[KERNEL_PT_SYS]);
    451   1.1    nonaka 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    452   1.1    nonaka 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    453   1.1    nonaka 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    454   1.1    nonaka 	pmap_link_l2pt(l1pagetable, HDLG_IOPXS_VBASE,
    455   1.1    nonaka 	    &kernel_pt_table[KERNEL_PT_IOPXS]);
    456   1.1    nonaka 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    457   1.1    nonaka 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    458   1.1    nonaka 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    459   1.1    nonaka 
    460   1.1    nonaka 	/* update the top of the kernel VM */
    461   1.1    nonaka 	pmap_curmaxkvaddr =
    462   1.1    nonaka 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    463   1.1    nonaka 
    464   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    465   1.1    nonaka 	printf("Mapping kernel\n");
    466   1.1    nonaka #endif
    467   1.1    nonaka 
    468   1.1    nonaka 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    469   1.1    nonaka 	{
    470   1.1    nonaka 		extern char etext[], _end[];
    471   1.1    nonaka 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    472   1.1    nonaka 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    473   1.1    nonaka 		u_int logical;
    474   1.1    nonaka 
    475   1.1    nonaka 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    476   1.1    nonaka 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    477   1.1    nonaka 
    478   1.1    nonaka 		logical = 0x00200000;	/* offset of kernel in RAM */
    479   1.1    nonaka 
    480   1.1    nonaka 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    481   1.1    nonaka 		    physical_start + logical, textsize,
    482   1.1    nonaka 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    483   1.1    nonaka 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    484   1.1    nonaka 		    physical_start + logical, totalsize - textsize,
    485   1.1    nonaka 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    486   1.1    nonaka 	}
    487   1.1    nonaka 
    488   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    489   1.1    nonaka 	printf("Constructing L2 page tables\n");
    490   1.1    nonaka #endif
    491   1.1    nonaka 
    492   1.1    nonaka 	/* Map the stack pages */
    493   1.1    nonaka 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    494   1.1    nonaka 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    495   1.1    nonaka 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    496   1.1    nonaka 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    497   1.1    nonaka 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    498   1.1    nonaka 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    499   1.1    nonaka 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    500   1.1    nonaka 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    501   1.1    nonaka 
    502   1.1    nonaka 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    503   1.1    nonaka 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    504   1.1    nonaka 
    505   1.1    nonaka 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    506   1.1    nonaka 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    507   1.1    nonaka 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    508   1.1    nonaka 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    509   1.1    nonaka 	}
    510   1.1    nonaka 
    511   1.1    nonaka 	/* Map the Mini-Data cache clean area. */
    512   1.1    nonaka 	xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
    513   1.1    nonaka 	    minidataclean.pv_pa);
    514   1.1    nonaka 
    515   1.1    nonaka 	/* Map the vector page. */
    516   1.1    nonaka 	pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
    517   1.1    nonaka 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    518   1.1    nonaka 
    519   1.1    nonaka 	/* Map the statically mapped devices. */
    520   1.1    nonaka 	pmap_devmap_bootstrap(l1pagetable, hdlg_devmap);
    521   1.1    nonaka 
    522   1.1    nonaka 	/*
    523   1.1    nonaka 	 * Give the XScale global cache clean code an appropriately
    524   1.1    nonaka 	 * sized chunk of unmapped VA space starting at 0xff000000
    525   1.1    nonaka 	 * (our device mappings end before this address).
    526   1.1    nonaka 	 */
    527   1.1    nonaka 	xscale_cache_clean_addr = 0xff000000U;
    528   1.1    nonaka 
    529   1.1    nonaka 	/*
    530   1.1    nonaka 	 * Now we have the real page tables in place so we can switch to them.
    531   1.1    nonaka 	 * Once this is done we will be running with the REAL kernel page
    532   1.1    nonaka 	 * tables.
    533   1.1    nonaka 	 */
    534   1.1    nonaka 
    535   1.1    nonaka 	/*
    536   1.1    nonaka 	 * Update the physical_freestart/physical_freeend/free_pages
    537   1.1    nonaka 	 * variables.
    538   1.1    nonaka 	 */
    539   1.1    nonaka 	{
    540   1.1    nonaka 		extern char _end[];
    541   1.1    nonaka 
    542   1.1    nonaka 		physical_freestart = physical_start +
    543   1.1    nonaka 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    544   1.1    nonaka 		     KERNEL_BASE);
    545   1.1    nonaka 		physical_freeend = physical_end;
    546   1.1    nonaka 		free_pages =
    547   1.1    nonaka 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    548   1.1    nonaka 	}
    549   1.1    nonaka 
    550   1.1    nonaka 	/* Switch tables */
    551   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    552   1.1    nonaka 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    553   1.1    nonaka 	       physical_freestart, free_pages, free_pages);
    554   1.1    nonaka 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    555   1.1    nonaka #endif
    556   1.1    nonaka 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    557  1.14  uebayasi 	cpu_setttb(kernel_l1pt.pv_pa);
    558   1.1    nonaka 	cpu_tlb_flushID();
    559   1.1    nonaka 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    560   1.1    nonaka 
    561   1.1    nonaka 	/*
    562   1.1    nonaka 	 * Moved from cpu_startup() as data_abort_handler() references
    563   1.1    nonaka 	 * this during uvm init
    564   1.1    nonaka 	 */
    565  1.12     rmind 	uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
    566   1.1    nonaka 
    567   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    568   1.1    nonaka 	printf("done!\n");
    569   1.1    nonaka #endif
    570   1.1    nonaka 
    571   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    572   1.1    nonaka 	printf("bootstrap done.\n");
    573   1.1    nonaka #endif
    574   1.1    nonaka 
    575   1.1    nonaka 	arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
    576   1.1    nonaka 
    577   1.1    nonaka 	/*
    578   1.1    nonaka 	 * Pages were allocated during the secondary bootstrap for the
    579   1.1    nonaka 	 * stacks for different CPU modes.
    580   1.1    nonaka 	 * We must now set the r13 registers in the different CPU modes to
    581   1.1    nonaka 	 * point to these stacks.
    582   1.1    nonaka 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    583   1.1    nonaka 	 * of the stack memory.
    584   1.1    nonaka 	 */
    585   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    586   1.1    nonaka 	printf("init subsystems: stacks ");
    587   1.1    nonaka #endif
    588   1.1    nonaka 
    589   1.1    nonaka 	set_stackptr(PSR_IRQ32_MODE,
    590   1.1    nonaka 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    591   1.1    nonaka 	set_stackptr(PSR_ABT32_MODE,
    592   1.1    nonaka 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    593   1.1    nonaka 	set_stackptr(PSR_UND32_MODE,
    594   1.1    nonaka 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    595   1.1    nonaka 
    596   1.1    nonaka 	/*
    597   1.1    nonaka 	 * Well we should set a data abort handler.
    598   1.1    nonaka 	 * Once things get going this will change as we will need a proper
    599   1.1    nonaka 	 * handler.
    600   1.1    nonaka 	 * Until then we will use a handler that just panics but tells us
    601   1.1    nonaka 	 * why.
    602   1.1    nonaka 	 * Initialisation of the vectors will just panic on a data abort.
    603   1.1    nonaka 	 * This just fills in a slightly better one.
    604   1.1    nonaka 	 */
    605   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    606   1.1    nonaka 	printf("vectors ");
    607   1.1    nonaka #endif
    608   1.1    nonaka 	data_abort_handler_address = (u_int)data_abort_handler;
    609   1.1    nonaka 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    610   1.1    nonaka 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    611   1.1    nonaka 
    612   1.1    nonaka 	/* Initialise the undefined instruction handlers */
    613   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    614   1.1    nonaka 	printf("undefined ");
    615   1.1    nonaka #endif
    616   1.1    nonaka 	undefined_init();
    617   1.1    nonaka 
    618   1.1    nonaka 	/* Load memory into UVM. */
    619   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    620   1.1    nonaka 	printf("page ");
    621   1.1    nonaka #endif
    622   1.1    nonaka 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    623   1.1    nonaka 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    624   1.1    nonaka 	    atop(physical_freestart), atop(physical_freeend),
    625   1.1    nonaka 	    VM_FREELIST_DEFAULT);
    626   1.1    nonaka 
    627   1.1    nonaka 	/* Boot strap pmap telling it where the kernel page table is */
    628   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    629   1.1    nonaka 	printf("pmap ");
    630   1.1    nonaka #endif
    631   1.6      matt 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    632   1.1    nonaka 
    633   1.1    nonaka 	/* Setup the IRQ system */
    634   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    635   1.1    nonaka 	printf("irq ");
    636   1.1    nonaka #endif
    637   1.1    nonaka 	i80321_intr_init();
    638   1.1    nonaka 
    639   1.1    nonaka #ifdef VERBOSE_INIT_ARM
    640   1.1    nonaka 	printf("done.\n");
    641   1.1    nonaka #endif
    642   1.1    nonaka 
    643   1.1    nonaka #ifdef BOOTHOWTO
    644   1.1    nonaka 	boothowto = BOOTHOWTO;
    645   1.1    nonaka #endif
    646   1.1    nonaka 
    647   1.1    nonaka #ifdef DDB
    648   1.1    nonaka 	db_machine_init();
    649   1.1    nonaka 	if (boothowto & RB_KDB)
    650   1.1    nonaka 		Debugger();
    651   1.1    nonaka #endif
    652   1.1    nonaka 
    653   1.1    nonaka 	/* We return the new stack pointer address */
    654   1.1    nonaka 	return (kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    655   1.1    nonaka }
    656   1.1    nonaka 
    657   1.1    nonaka /*
    658   1.1    nonaka  * void cpu_reboot(int howto, char *bootstr)
    659   1.1    nonaka  *
    660   1.1    nonaka  * Reboots the system
    661   1.1    nonaka  *
    662   1.1    nonaka  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    663   1.1    nonaka  * then reset the CPU.
    664   1.1    nonaka  */
    665   1.1    nonaka void
    666   1.1    nonaka cpu_reboot(int howto, char *bootstr)
    667   1.1    nonaka {
    668   1.1    nonaka 
    669   1.1    nonaka 	/*
    670   1.1    nonaka 	 * If we are still cold then hit the air brakes
    671   1.1    nonaka 	 * and crash to earth fast
    672   1.1    nonaka 	 */
    673   1.1    nonaka 	if (cold) {
    674   1.1    nonaka 		*(volatile uint8_t *)HDLG_LEDCTRL |= LEDCTRL_STAT_RED;
    675   1.1    nonaka 		howto |= RB_HALT;
    676   1.1    nonaka 		goto haltsys;
    677   1.1    nonaka 	}
    678   1.1    nonaka 
    679   1.1    nonaka 	/* Disable console buffering */
    680   1.1    nonaka 
    681   1.1    nonaka 	/*
    682   1.1    nonaka 	 * If RB_NOSYNC was not specified sync the discs.
    683   1.1    nonaka 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    684   1.1    nonaka 	 * unmount.  It looks like syslogd is getting woken up only to find
    685   1.1    nonaka 	 * that it cannot page part of the binary in as the filesystem has
    686   1.1    nonaka 	 * been unmounted.
    687   1.1    nonaka 	 */
    688   1.1    nonaka 	if ((howto & RB_NOSYNC) == 0) {
    689   1.1    nonaka 		bootsync();
    690   1.1    nonaka 		/*resettodr();*/
    691   1.1    nonaka 	}
    692   1.1    nonaka 
    693   1.1    nonaka 	/* wait 1s */
    694   1.1    nonaka 	delay(1 * 1000 * 1000);
    695   1.1    nonaka 
    696   1.1    nonaka 	/* Say NO to interrupts */
    697   1.1    nonaka 	splhigh();
    698   1.1    nonaka 
    699   1.1    nonaka 	/* Do a dump if requested. */
    700   1.1    nonaka 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) {
    701   1.1    nonaka 		dumpsys();
    702   1.1    nonaka 	}
    703   1.1    nonaka 
    704   1.1    nonaka haltsys:
    705   1.1    nonaka 	/* Run any shutdown hooks */
    706   1.1    nonaka 	doshutdownhooks();
    707   1.1    nonaka 
    708   1.7    dyoung 	pmf_system_shutdown(boothowto);
    709   1.7    dyoung 
    710   1.1    nonaka 	/* Make sure IRQ's are disabled */
    711   1.1    nonaka 	IRQdisable;
    712   1.1    nonaka 
    713   1.1    nonaka 	if (howto & RB_HALT) {
    714   1.1    nonaka 		*(volatile uint8_t *)HDLG_PWRMNG = PWRMNG_POWOFF;
    715   1.1    nonaka 		delay(3 * 1000 * 1000);	/* wait 3s */
    716   1.1    nonaka 
    717   1.1    nonaka 		printf("SHUTDOWN FAILED!\n");
    718   1.1    nonaka 		printf("The operating system has halted.\n");
    719   1.1    nonaka 		printf("Please press any key to reboot.\n\n");
    720   1.1    nonaka 		cngetc();
    721   1.1    nonaka 	}
    722   1.1    nonaka 
    723   1.1    nonaka 	printf("rebooting...\n\r");
    724   1.1    nonaka 
    725   1.1    nonaka 	(void)disable_interrupts(I32_bit|F32_bit);
    726   1.1    nonaka 	cpu_idcache_wbinv_all();
    727   1.1    nonaka 	cpu_drain_writebuf();
    728   1.1    nonaka 
    729   1.1    nonaka 	*(volatile uint8_t *)HDLG_PWRMNG = PWRMNG_RESET;
    730   1.1    nonaka 	delay(1 * 1000 * 1000);	/* wait 1s */
    731   1.1    nonaka 
    732   1.1    nonaka 	/* ...and if that didn't work, just croak. */
    733   1.1    nonaka 	printf("RESET FAILED!\n");
    734   1.1    nonaka 	for (;;) {
    735   1.1    nonaka 		continue;
    736   1.1    nonaka 	}
    737   1.1    nonaka }
    738   1.1    nonaka 
    739   1.1    nonaka /*
    740   1.1    nonaka  * console
    741   1.1    nonaka  */
    742   1.1    nonaka #include "com.h"
    743   1.1    nonaka #if NCOM > 0
    744   1.1    nonaka #include <dev/ic/comreg.h>
    745   1.1    nonaka #include <dev/ic/comvar.h>
    746   1.1    nonaka #endif
    747   1.1    nonaka 
    748   1.1    nonaka /*
    749   1.1    nonaka  * Define the default console speed for the board.  This is generally
    750   1.1    nonaka  * what the firmware provided with the board defaults to.
    751   1.1    nonaka  */
    752   1.1    nonaka #ifndef CONSPEED
    753   1.1    nonaka #define CONSPEED B115200
    754   1.1    nonaka #endif /* ! CONSPEED */
    755   1.1    nonaka 
    756   1.1    nonaka #ifndef CONUNIT
    757   1.1    nonaka #define	CONUNIT	0
    758   1.1    nonaka #endif
    759   1.1    nonaka 
    760   1.1    nonaka #ifndef CONMODE
    761   1.1    nonaka #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    762   1.1    nonaka #endif
    763   1.1    nonaka 
    764   1.1    nonaka int comcnspeed = CONSPEED;
    765   1.1    nonaka int comcnmode = CONMODE;
    766   1.1    nonaka int comcnunit = CONUNIT;
    767   1.1    nonaka 
    768   1.1    nonaka #if KGDB
    769   1.1    nonaka #ifndef KGDB_DEVNAME
    770   1.1    nonaka #error Must define KGDB_DEVNAME
    771   1.1    nonaka #endif
    772   1.1    nonaka const char kgdb_devname[] = KGDB_DEVNAME;
    773   1.1    nonaka 
    774   1.1    nonaka #ifndef KGDB_DEVADDR
    775   1.1    nonaka #error Must define KGDB_DEVADDR
    776   1.1    nonaka #endif
    777   1.1    nonaka unsigned long kgdb_devaddr = KGDB_DEVADDR;
    778   1.1    nonaka 
    779   1.1    nonaka #ifndef KGDB_DEVRATE
    780   1.1    nonaka #define KGDB_DEVRATE	CONSPEED
    781   1.1    nonaka #endif
    782   1.1    nonaka int kgdb_devrate = KGDB_DEVRATE;
    783   1.1    nonaka 
    784   1.1    nonaka #ifndef KGDB_DEVMODE
    785   1.1    nonaka #define KGDB_DEVMODE	CONMODE
    786   1.1    nonaka #endif
    787   1.1    nonaka int kgdb_devmode = KGDB_DEVMODE;
    788   1.1    nonaka #endif /* KGDB */
    789   1.1    nonaka 
    790   1.1    nonaka void
    791   1.1    nonaka consinit(void)
    792   1.1    nonaka {
    793   1.1    nonaka 	static const bus_addr_t comcnaddrs[] = {
    794   1.1    nonaka 		HDLG_UART1,		/* com0 */
    795   1.1    nonaka 	};
    796   1.1    nonaka 	static int consinit_called;
    797   1.1    nonaka 
    798   1.1    nonaka 	if (consinit_called)
    799   1.1    nonaka 		return;
    800   1.1    nonaka 	consinit_called = 1;
    801   1.1    nonaka 
    802   1.1    nonaka 	/*
    803   1.1    nonaka 	 * Console devices are mapped VA==PA.  Our devmap reflects
    804   1.1    nonaka 	 * this, so register it now so drivers can map the console
    805   1.1    nonaka 	 * device.
    806   1.1    nonaka 	 */
    807   1.1    nonaka 	pmap_devmap_register(hdlg_devmap);
    808   1.1    nonaka 
    809   1.1    nonaka #if NCOM > 0
    810   1.1    nonaka 	if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
    811   1.1    nonaka 	    COM_FREQ, COM_TYPE_NORMAL, comcnmode))
    812   1.1    nonaka 		panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
    813   1.1    nonaka #else
    814   1.1    nonaka 	panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
    815   1.1    nonaka #endif
    816   1.1    nonaka #if KGDB
    817   1.1    nonaka #if NCOM > 0
    818   1.1    nonaka 	if (strcmp(kgdb_devname, "com") == 0) {
    819   1.1    nonaka 		com_kgdb_attach(&obio_bs_tag, kgdb_devaddr, kgdb_devrate,
    820   1.1    nonaka 				COM_FREQ, COM_TYPE_NORMAL, kgdb_devmode);
    821   1.1    nonaka 	}
    822   1.1    nonaka #endif	/* NCOM > 0 */
    823   1.1    nonaka #endif	/* KGDB */
    824   1.1    nonaka }
    825