Home | History | Annotate | Line # | Download | only in imx31
imx31lk_machdep.c revision 1.4
      1  1.4  dyoung /* $NetBSD: imx31lk_machdep.c,v 1.4 2008/11/11 06:46:41 dyoung Exp $ */
      2  1.2    matt 
      3  1.2    matt /*
      4  1.2    matt  * Startup routines for the ZOOM iMX31 LITEKIT.
      5  1.2    matt  * Below you can trace the increasingly impressive lineage ;)
      6  1.2    matt  */
      7  1.2    matt 
      8  1.2    matt /*
      9  1.2    matt  * Copyright (c) 2002, 2003, 2005  Genetec Corporation.  All rights reserved.
     10  1.2    matt  * Written by Hiroyuki Bessho for Genetec Corporation.
     11  1.2    matt  *
     12  1.2    matt  * Redistribution and use in source and binary forms, with or without
     13  1.2    matt  * modification, are permitted provided that the following conditions
     14  1.2    matt  * are met:
     15  1.2    matt  * 1. Redistributions of source code must retain the above copyright
     16  1.2    matt  *    notice, this list of conditions and the following disclaimer.
     17  1.2    matt  * 2. Redistributions in binary form must reproduce the above copyright
     18  1.2    matt  *    notice, this list of conditions and the following disclaimer in the
     19  1.2    matt  *    documentation and/or other materials provided with the distribution.
     20  1.2    matt  * 3. The name of Genetec Corporation may not be used to endorse or
     21  1.2    matt  *    promote products derived from this software without specific prior
     22  1.2    matt  *    written permission.
     23  1.2    matt  *
     24  1.2    matt  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     25  1.2    matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26  1.2    matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     27  1.2    matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     28  1.2    matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29  1.2    matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30  1.2    matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     31  1.2    matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     32  1.2    matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     33  1.2    matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34  1.2    matt  * POSSIBILITY OF SUCH DAMAGE.
     35  1.2    matt  *
     36  1.2    matt  * Machine dependant functions for kernel setup for
     37  1.2    matt  * Intel DBPXA250 evaluation board (a.k.a. Lubbock).
     38  1.2    matt  * Based on iq80310_machhdep.c
     39  1.2    matt  */
     40  1.2    matt /*
     41  1.2    matt  * Copyright (c) 2001 Wasabi Systems, Inc.
     42  1.2    matt  * All rights reserved.
     43  1.2    matt  *
     44  1.2    matt  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
     45  1.2    matt  *
     46  1.2    matt  * Redistribution and use in source and binary forms, with or without
     47  1.2    matt  * modification, are permitted provided that the following conditions
     48  1.2    matt  * are met:
     49  1.2    matt  * 1. Redistributions of source code must retain the above copyright
     50  1.2    matt  *    notice, this list of conditions and the following disclaimer.
     51  1.2    matt  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.2    matt  *    notice, this list of conditions and the following disclaimer in the
     53  1.2    matt  *    documentation and/or other materials provided with the distribution.
     54  1.2    matt  * 3. All advertising materials mentioning features or use of this software
     55  1.2    matt  *    must display the following acknowledgement:
     56  1.2    matt  *	This product includes software developed for the NetBSD Project by
     57  1.2    matt  *	Wasabi Systems, Inc.
     58  1.2    matt  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     59  1.2    matt  *    or promote products derived from this software without specific prior
     60  1.2    matt  *    written permission.
     61  1.2    matt  *
     62  1.2    matt  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     63  1.2    matt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     64  1.2    matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     65  1.2    matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     66  1.2    matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     67  1.2    matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     68  1.2    matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     69  1.2    matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     70  1.2    matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     71  1.2    matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     72  1.2    matt  * POSSIBILITY OF SUCH DAMAGE.
     73  1.2    matt  */
     74  1.2    matt 
     75  1.2    matt /*
     76  1.2    matt  * Copyright (c) 1997,1998 Mark Brinicombe.
     77  1.2    matt  * Copyright (c) 1997,1998 Causality Limited.
     78  1.2    matt  * All rights reserved.
     79  1.2    matt  *
     80  1.2    matt  * Redistribution and use in source and binary forms, with or without
     81  1.2    matt  * modification, are permitted provided that the following conditions
     82  1.2    matt  * are met:
     83  1.2    matt  * 1. Redistributions of source code must retain the above copyright
     84  1.2    matt  *    notice, this list of conditions and the following disclaimer.
     85  1.2    matt  * 2. Redistributions in binary form must reproduce the above copyright
     86  1.2    matt  *    notice, this list of conditions and the following disclaimer in the
     87  1.2    matt  *    documentation and/or other materials provided with the distribution.
     88  1.2    matt  * 3. All advertising materials mentioning features or use of this software
     89  1.2    matt  *    must display the following acknowledgement:
     90  1.2    matt  *	This product includes software developed by Mark Brinicombe
     91  1.2    matt  *	for the NetBSD Project.
     92  1.2    matt  * 4. The name of the company nor the name of the author may be used to
     93  1.2    matt  *    endorse or promote products derived from this software without specific
     94  1.2    matt  *    prior written permission.
     95  1.2    matt  *
     96  1.2    matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     97  1.2    matt  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     98  1.2    matt  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     99  1.2    matt  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    100  1.2    matt  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    101  1.2    matt  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    102  1.2    matt  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    103  1.2    matt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    104  1.2    matt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    105  1.2    matt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    106  1.2    matt  * SUCH DAMAGE.
    107  1.2    matt  *
    108  1.2    matt  * Machine dependant functions for kernel setup for Intel IQ80310 evaluation
    109  1.2    matt  * boards using RedBoot firmware.
    110  1.2    matt  */
    111  1.2    matt 
    112  1.2    matt #include <sys/cdefs.h>
    113  1.4  dyoung __KERNEL_RCSID(0, "$NetBSD: imx31lk_machdep.c,v 1.4 2008/11/11 06:46:41 dyoung Exp $");
    114  1.2    matt 
    115  1.2    matt #include "opt_ddb.h"
    116  1.2    matt #include "opt_kgdb.h"
    117  1.2    matt #include "opt_ipkdb.h"
    118  1.2    matt #include "opt_pmap_debug.h"
    119  1.2    matt #include "opt_md.h"
    120  1.2    matt #include "opt_com.h"
    121  1.2    matt #include "md.h"
    122  1.2    matt 
    123  1.2    matt #include <sys/param.h>
    124  1.2    matt #include <sys/device.h>
    125  1.2    matt #include <sys/systm.h>
    126  1.2    matt #include <sys/kernel.h>
    127  1.2    matt #include <sys/exec.h>
    128  1.2    matt #include <sys/proc.h>
    129  1.2    matt #include <sys/msgbuf.h>
    130  1.2    matt #include <sys/reboot.h>
    131  1.2    matt #include <sys/termios.h>
    132  1.2    matt #include <sys/ksyms.h>
    133  1.2    matt 
    134  1.2    matt #include <uvm/uvm_extern.h>
    135  1.2    matt 
    136  1.2    matt #include <sys/conf.h>
    137  1.2    matt #include <dev/cons.h>
    138  1.2    matt #include <dev/md.h>
    139  1.2    matt 
    140  1.2    matt #include <machine/db_machdep.h>
    141  1.2    matt #include <ddb/db_sym.h>
    142  1.2    matt #include <ddb/db_extern.h>
    143  1.2    matt #ifdef KGDB
    144  1.2    matt #include <sys/kgdb.h>
    145  1.2    matt #endif
    146  1.2    matt 
    147  1.2    matt #include <machine/bootconfig.h>
    148  1.2    matt #include <machine/bus.h>
    149  1.2    matt #include <machine/cpu.h>
    150  1.2    matt #include <machine/frame.h>
    151  1.2    matt #include <arm/undefined.h>
    152  1.2    matt 
    153  1.2    matt #include <arm/arm32/pte.h>
    154  1.2    matt #include <arm/arm32/machdep.h>
    155  1.2    matt 
    156  1.2    matt #include <arm/imx/imxuartreg.h>
    157  1.2    matt #include <arm/imx/imxuartvar.h>
    158  1.2    matt #include <evbarm/imx31/imx31lk_reg.h>
    159  1.2    matt 
    160  1.2    matt /* Kernel text starts 1MB in from the bottom of the kernel address space. */
    161  1.2    matt #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00100000)
    162  1.2    matt #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
    163  1.2    matt 
    164  1.2    matt /*
    165  1.2    matt  * The range 0x81000000 - 0x8cffffff is available for kernel VM space
    166  1.2    matt  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
    167  1.2    matt  */
    168  1.2    matt #define KERNEL_VM_SIZE		0x0C000000
    169  1.2    matt 
    170  1.2    matt 
    171  1.2    matt /*
    172  1.2    matt  * Address to call from cpu_reset() to reset the machine.
    173  1.2    matt  * This is machine architecture dependant as it varies depending
    174  1.2    matt  * on where the ROM appears when you turn the MMU off.
    175  1.2    matt  */
    176  1.2    matt 
    177  1.2    matt u_int cpu_reset_address = 0;
    178  1.2    matt 
    179  1.2    matt /* Define various stack sizes in pages */
    180  1.2    matt #define IRQ_STACK_SIZE	1
    181  1.2    matt #define ABT_STACK_SIZE	1
    182  1.2    matt #ifdef IPKDB
    183  1.2    matt #define UND_STACK_SIZE	2
    184  1.2    matt #else
    185  1.2    matt #define UND_STACK_SIZE	1
    186  1.2    matt #endif
    187  1.2    matt 
    188  1.2    matt BootConfig bootconfig;		/* Boot config storage */
    189  1.2    matt char *boot_args = NULL;
    190  1.2    matt char *boot_file = NULL;
    191  1.2    matt 
    192  1.2    matt vm_offset_t physical_start;
    193  1.2    matt vm_offset_t physical_freestart;
    194  1.2    matt vm_offset_t physical_freeend;
    195  1.2    matt vm_offset_t physical_end;
    196  1.2    matt u_int free_pages;
    197  1.2    matt vm_offset_t pagetables_start;
    198  1.2    matt int physmem = 0;
    199  1.2    matt 
    200  1.2    matt /*int debug_flags;*/
    201  1.2    matt #ifndef PMAP_STATIC_L1S
    202  1.2    matt int max_processes = 64;			/* Default number */
    203  1.2    matt #endif	/* !PMAP_STATIC_L1S */
    204  1.2    matt 
    205  1.2    matt /* Physical and virtual addresses for some global pages */
    206  1.2    matt pv_addr_t irqstack;
    207  1.2    matt pv_addr_t undstack;
    208  1.2    matt pv_addr_t abtstack;
    209  1.2    matt pv_addr_t kernelstack;
    210  1.2    matt 
    211  1.2    matt vm_offset_t msgbufphys;
    212  1.2    matt 
    213  1.2    matt extern u_int data_abort_handler_address;
    214  1.2    matt extern u_int prefetch_abort_handler_address;
    215  1.2    matt extern u_int undefined_handler_address;
    216  1.2    matt 
    217  1.2    matt #ifdef PMAP_DEBUG
    218  1.2    matt extern int pmap_debug_level;
    219  1.2    matt #endif
    220  1.2    matt 
    221  1.2    matt #define KERNEL_PT_SYS		0	/* Page table for mapping proc0 zero page */
    222  1.2    matt #define KERNEL_PT_KERNEL	1	/* Page table for mapping kernel */
    223  1.2    matt #define	KERNEL_PT_KERNEL_NUM	4
    224  1.2    matt #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL+KERNEL_PT_KERNEL_NUM)
    225  1.2    matt 				        /* Page tables for mapping kernel VM */
    226  1.2    matt #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    227  1.2    matt #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    228  1.2    matt 
    229  1.2    matt pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    230  1.2    matt 
    231  1.2    matt struct user *proc0paddr;
    232  1.2    matt 
    233  1.2    matt /* Prototypes */
    234  1.2    matt 
    235  1.2    matt #if 0
    236  1.2    matt void	process_kernel_args(char *);
    237  1.2    matt #endif
    238  1.2    matt 
    239  1.2    matt void	imx31lk_consinit(int);
    240  1.2    matt void	kgdb_port_init(void);
    241  1.2    matt void	change_clock(uint32_t v);
    242  1.2    matt 
    243  1.2    matt bs_protos(bs_notimpl);
    244  1.2    matt 
    245  1.2    matt #include "com.h"
    246  1.2    matt #if NCOM > 0
    247  1.2    matt #include <dev/ic/comreg.h>
    248  1.2    matt #include <dev/ic/comvar.h>
    249  1.2    matt #endif
    250  1.2    matt 
    251  1.2    matt #ifndef CONSPEED
    252  1.2    matt #define CONSPEED B115200	/* What RedBoot uses */
    253  1.2    matt #endif
    254  1.2    matt #ifndef CONMODE
    255  1.2    matt #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    256  1.2    matt #endif
    257  1.2    matt 
    258  1.2    matt int comcnspeed = CONSPEED;
    259  1.2    matt int comcnmode = CONMODE;
    260  1.2    matt 
    261  1.2    matt /*
    262  1.2    matt  * void cpu_reboot(int howto, char *bootstr)
    263  1.2    matt  *
    264  1.2    matt  * Reboots the system
    265  1.2    matt  *
    266  1.2    matt  * Deal with any syncing, unmounting, dumping and shutdown hooks,
    267  1.2    matt  * then reset the CPU.
    268  1.2    matt  */
    269  1.2    matt void
    270  1.2    matt cpu_reboot(int howto, char *bootstr)
    271  1.2    matt {
    272  1.2    matt #ifdef DIAGNOSTIC
    273  1.2    matt 	/* info */
    274  1.2    matt 	printf("boot: howto=%08x curproc=%p\n", howto, curproc);
    275  1.2    matt #endif
    276  1.2    matt 
    277  1.2    matt 	/*
    278  1.2    matt 	 * If we are still cold then hit the air brakes
    279  1.2    matt 	 * and crash to earth fast
    280  1.2    matt 	 */
    281  1.2    matt 	if (cold) {
    282  1.2    matt 		doshutdownhooks();
    283  1.4  dyoung 		pmf_system_shutdown(boothowto);
    284  1.2    matt 		printf("The operating system has halted.\n");
    285  1.2    matt 		printf("Please press any key to reboot.\n\n");
    286  1.2    matt 		cngetc();
    287  1.2    matt 		printf("rebooting...\n");
    288  1.2    matt 		cpu_reset();
    289  1.2    matt 		/*NOTREACHED*/
    290  1.2    matt 	}
    291  1.2    matt 
    292  1.2    matt 	/* Disable console buffering */
    293  1.2    matt /*	cnpollc(1);*/
    294  1.2    matt 
    295  1.2    matt 	/*
    296  1.2    matt 	 * If RB_NOSYNC was not specified sync the discs.
    297  1.2    matt 	 * Note: Unless cold is set to 1 here, syslogd will die during the
    298  1.2    matt 	 * unmount.  It looks like syslogd is getting woken up only to find
    299  1.2    matt 	 * that it cannot page part of the binary in as the filesystem has
    300  1.2    matt 	 * been unmounted.
    301  1.2    matt 	 */
    302  1.2    matt 	if (!(howto & RB_NOSYNC))
    303  1.2    matt 		bootsync();
    304  1.2    matt 
    305  1.2    matt 	/* Say NO to interrupts */
    306  1.2    matt 	splhigh();
    307  1.2    matt 
    308  1.2    matt 	/* Do a dump if requested. */
    309  1.2    matt 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
    310  1.2    matt 		dumpsys();
    311  1.2    matt 
    312  1.2    matt 	/* Run any shutdown hooks */
    313  1.2    matt 	doshutdownhooks();
    314  1.2    matt 
    315  1.4  dyoung 	pmf_system_shutdown(boothowto);
    316  1.4  dyoung 
    317  1.2    matt 	/* Make sure IRQ's are disabled */
    318  1.2    matt 	IRQdisable;
    319  1.2    matt 
    320  1.2    matt 	if (howto & RB_HALT) {
    321  1.2    matt 		printf("The operating system has halted.\n");
    322  1.2    matt 		printf("Please press any key to reboot.\n\n");
    323  1.2    matt 		cngetc();
    324  1.2    matt 	}
    325  1.2    matt 
    326  1.2    matt 	printf("rebooting...\n");
    327  1.2    matt 	cpu_reset();
    328  1.2    matt 	/*NOTREACHED*/
    329  1.2    matt }
    330  1.2    matt 
    331  1.2    matt /*
    332  1.2    matt  * Static device mappings. These peripheral registers are mapped at
    333  1.2    matt  * fixed virtual addresses very early in imx31lk_start() so that we
    334  1.2    matt  * can use them while booting the kernel, and stay at the same address
    335  1.2    matt  * throughout whole kernel's life time.
    336  1.2    matt  *
    337  1.2    matt  * We use this table twice; once with bootstrap page table, and once
    338  1.2    matt  * with kernel's page table which we build up in initarm().
    339  1.2    matt  */
    340  1.2    matt 
    341  1.2    matt #define _A(a)   ((a) & ~L1_S_OFFSET)
    342  1.2    matt #define _S(s)   (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
    343  1.2    matt 
    344  1.2    matt static const struct pmap_devmap imx31lk_devmap[] = {
    345  1.2    matt     {
    346  1.2    matt 	IMX31LITEKIT_UART1_VBASE,
    347  1.2    matt 	_A(IMX_UART1_BASE),
    348  1.2    matt 	_S(L1_S_SIZE),
    349  1.2    matt 	VM_PROT_READ|VM_PROT_WRITE,
    350  1.2    matt 	PTE_NOCACHE,
    351  1.2    matt     },
    352  1.2    matt 	{0, 0, 0, 0, 0 }
    353  1.2    matt };
    354  1.2    matt 
    355  1.2    matt #ifndef MEMSTART
    356  1.2    matt #define MEMSTART	0x80000000
    357  1.2    matt #endif
    358  1.2    matt #ifndef MEMSIZE
    359  1.2    matt #define MEMSIZE		0x8000000
    360  1.2    matt #endif
    361  1.2    matt 
    362  1.2    matt /*
    363  1.2    matt  * u_int initarm(...)
    364  1.2    matt  *
    365  1.2    matt  * Initial entry point on startup. This gets called before main() is
    366  1.2    matt  * entered.
    367  1.2    matt  * It should be responsible for setting up everything that must be
    368  1.2    matt  * in place when main is called.
    369  1.2    matt  * This includes
    370  1.2    matt  *   Taking a copy of the boot configuration structure.
    371  1.2    matt  *   Initialising the physical console so characters can be printed.
    372  1.2    matt  *   Setting up page tables for the kernel
    373  1.2    matt  *   Relocating the kernel to the bottom of physical memory
    374  1.2    matt  */
    375  1.2    matt u_int
    376  1.2    matt initarm(void *arg)
    377  1.2    matt {
    378  1.2    matt 	int loop;
    379  1.2    matt 	int loop1;
    380  1.2    matt 	vaddr_t l1pagetable;
    381  1.2    matt 
    382  1.2    matt 	disable_interrupts(I32_bit|F32_bit);
    383  1.2    matt 		/* XXX move to imx31lk_start.S */
    384  1.2    matt 
    385  1.2    matt 	/* Register devmap for devices we mapped in start */
    386  1.2    matt 	pmap_devmap_register(imx31lk_devmap);
    387  1.2    matt 
    388  1.2    matt #ifdef NOTYET
    389  1.2    matt 	/* start 32.768 kHz OSC */
    390  1.2    matt 	ioreg_write(VIPER_CLKMAN_VBASE + 0x08, 2);
    391  1.2    matt 	/* Get ready for splfoo() */
    392  1.2    matt 	imx31_intr_bootstrap(IMX31_INTCTL_VBASE);
    393  1.2    matt #endif
    394  1.2    matt 
    395  1.2    matt 	/*
    396  1.2    matt 	 * Heads up ... Setup the CPU / MMU / TLB functions
    397  1.2    matt 	 */
    398  1.2    matt 	if (set_cpufuncs())
    399  1.2    matt 		panic("cpu not recognized!");
    400  1.2    matt 
    401  1.2    matt #if 0
    402  1.2    matt 	/* Calibrate the delay loop. */
    403  1.2    matt #endif
    404  1.2    matt 
    405  1.2    matt 	imx31lk_consinit(1);
    406  1.2    matt 
    407  1.2    matt #ifdef KGDB
    408  1.2    matt 	kgdb_port_init();
    409  1.2    matt #endif
    410  1.2    matt 	/* Talk to the user */
    411  1.2    matt 	printf("\nNetBSD/evbarm (imx31lk) booting ...\n");
    412  1.2    matt 
    413  1.2    matt #if 0
    414  1.2    matt 	/*
    415  1.2    matt 	 * Examine the boot args string for options we need to know about
    416  1.2    matt 	 * now.
    417  1.2    matt 	 */
    418  1.2    matt 	process_kernel_args((char *)nwbootinfo.bt_args);
    419  1.2    matt #endif
    420  1.2    matt 
    421  1.2    matt 	printf("initarm: Configuring system ...\n");
    422  1.2    matt 
    423  1.2    matt 	/* Fake bootconfig structure for the benefit of pmap.c */
    424  1.2    matt 	/* XXX must make the memory description h/w independent */
    425  1.2    matt 	bootconfig.dramblocks = 1;
    426  1.2    matt 	bootconfig.dram[0].address = MEMSTART;
    427  1.2    matt 	bootconfig.dram[0].pages = MEMSIZE / PAGE_SIZE;
    428  1.2    matt 
    429  1.2    matt 	/*
    430  1.2    matt 	 * Set up the variables that define the availablilty of
    431  1.2    matt 	 * physical memory.  For now, we're going to set
    432  1.2    matt 	 * physical_freeend to 0x80100000UL (where the kernel
    433  1.2    matt 	 * was loaded) and allocate the memory we need downwards.
    434  1.2    matt 	 * If we get too close to the page tables that LoLo
    435  1.2    matt 	 * set up, we will panic.  We will update physical_freestart
    436  1.2    matt 	 * and physical_freeend later to reflect what pmap_bootstrap()
    437  1.2    matt 	 * wants to see.
    438  1.2    matt 	 *
    439  1.2    matt 	 * XXX pmap_bootstrap() needs an enema.
    440  1.2    matt 	 * (now that would be truly hardcore XXX)
    441  1.2    matt 	 */
    442  1.2    matt 	physical_start = bootconfig.dram[0].address;
    443  1.2    matt 	physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
    444  1.2    matt 
    445  1.2    matt 	physical_freestart = 0x800c0000UL;	/* top of LoLo */
    446  1.2    matt 	physical_freeend =   0x80100000UL;	/* base of kernel */
    447  1.2    matt 
    448  1.2    matt 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    449  1.2    matt 
    450  1.2    matt #ifdef VERBOSE_INIT_ARM
    451  1.2    matt 	/* Tell the user about the memory */
    452  1.2    matt 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    453  1.2    matt 	    physical_start, physical_end - 1);
    454  1.2    matt #endif
    455  1.2    matt 
    456  1.2    matt 	/*
    457  1.2    matt 	 * Okay, the kernel starts 1MB in from the bottom of physical
    458  1.2    matt 	 * memory.  We are going to allocate our bootstrap pages downwards
    459  1.2    matt 	 * from there.
    460  1.2    matt 	 *
    461  1.2    matt 	 * We need to allocate some fixed page tables to get the kernel
    462  1.2    matt 	 * going.  We allocate one page directory and a number of page
    463  1.2    matt 	 * tables and store the physical addresses in the kernel_pt_table
    464  1.2    matt 	 * array.
    465  1.2    matt 	 *
    466  1.2    matt 	 * The kernel page directory must be on a 16K boundary.  The page
    467  1.2    matt 	 * tables must be on 4K boundaries.  What we do is allocate the
    468  1.2    matt 	 * page directory on the first 16K boundary that we encounter, and
    469  1.2    matt 	 * the page tables on 4K boundaries otherwise.  Since we allocate
    470  1.2    matt 	 * at least 3 L2 page tables, we are guaranteed to encounter at
    471  1.2    matt 	 * least one 16K aligned region.
    472  1.2    matt 	 */
    473  1.2    matt 
    474  1.2    matt #ifdef VERBOSE_INIT_ARM
    475  1.2    matt 	printf("Allocating page tables\n");
    476  1.2    matt #endif
    477  1.2    matt 
    478  1.2    matt 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    479  1.2    matt 
    480  1.2    matt #ifdef VERBOSE_INIT_ARM
    481  1.2    matt 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    482  1.2    matt 	       physical_freestart, free_pages, free_pages);
    483  1.2    matt #endif
    484  1.2    matt 
    485  1.2    matt 	/* Define a macro to simplify memory allocation */
    486  1.2    matt #define	valloc_pages(var, np)				\
    487  1.2    matt 	alloc_pages((var).pv_pa, (np));			\
    488  1.2    matt 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    489  1.2    matt 
    490  1.2    matt #define alloc_pages(var, np)				\
    491  1.2    matt 	physical_freeend -= ((np) * PAGE_SIZE);		\
    492  1.2    matt 	if (physical_freeend < physical_freestart)	\
    493  1.2    matt 		panic("initarm: out of memory");	\
    494  1.2    matt 	(var) = physical_freeend;			\
    495  1.2    matt 	free_pages -= (np);				\
    496  1.2    matt 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    497  1.2    matt 
    498  1.2    matt 	loop1 = 0;
    499  1.2    matt 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    500  1.2    matt 		/* Are we 16KB aligned for an L1 ? */
    501  1.2    matt 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    502  1.2    matt 		    && kernel_l1pt.pv_pa == 0) {
    503  1.2    matt 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    504  1.2    matt 		} else {
    505  1.2    matt 			valloc_pages(kernel_pt_table[loop1],
    506  1.2    matt 			    L2_TABLE_SIZE / PAGE_SIZE);
    507  1.2    matt 			++loop1;
    508  1.2    matt 		}
    509  1.2    matt 	}
    510  1.2    matt 
    511  1.2    matt 	/* This should never be able to happen but better confirm that. */
    512  1.2    matt 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    513  1.2    matt 		panic("initarm: Failed to align the kernel page directory");
    514  1.2    matt 
    515  1.2    matt 	/*
    516  1.2    matt 	 * Allocate a page for the system page mapped to V0x00000000
    517  1.2    matt 	 * This page will just contain the system vectors and can be
    518  1.2    matt 	 * shared by all processes.
    519  1.2    matt 	 */
    520  1.2    matt 	alloc_pages(systempage.pv_pa, 1);
    521  1.2    matt 
    522  1.2    matt 	/* Allocate stacks for all modes */
    523  1.2    matt 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    524  1.2    matt 	valloc_pages(abtstack, ABT_STACK_SIZE);
    525  1.2    matt 	valloc_pages(undstack, UND_STACK_SIZE);
    526  1.2    matt 	valloc_pages(kernelstack, UPAGES);
    527  1.2    matt 
    528  1.2    matt #ifdef VERBOSE_INIT_ARM
    529  1.2    matt 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    530  1.2    matt 	    irqstack.pv_va);
    531  1.2    matt 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    532  1.2    matt 	    abtstack.pv_va);
    533  1.2    matt 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    534  1.2    matt 	    undstack.pv_va);
    535  1.2    matt 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    536  1.2    matt 	    kernelstack.pv_va);
    537  1.2    matt #endif
    538  1.2    matt 
    539  1.2    matt 	/*
    540  1.2    matt 	 * XXX Defer this to later so that we can reclaim the memory
    541  1.2    matt 	 * XXX used by the LoLo page tables.
    542  1.2    matt 	 */
    543  1.2    matt 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    544  1.2    matt 
    545  1.2    matt 	/*
    546  1.2    matt 	 * Ok we have allocated physical pages for the primary kernel
    547  1.2    matt 	 * page tables
    548  1.2    matt 	 */
    549  1.2    matt 
    550  1.2    matt #ifdef VERBOSE_INIT_ARM
    551  1.2    matt 	printf("Creating L1 page table at p0x%08lx v0x%08lx\n",
    552  1.2    matt 		kernel_l1pt.pv_pa, kernel_l1pt.pv_va);
    553  1.2    matt #endif
    554  1.2    matt 
    555  1.2    matt 	/*
    556  1.2    matt 	 * Now we start construction of the L1 page table
    557  1.2    matt 	 * We start by mapping the L2 page tables into the L1.
    558  1.2    matt 	 * This means that we can replace L1 mappings later on if necessary
    559  1.2    matt 	 */
    560  1.2    matt 	l1pagetable = kernel_l1pt.pv_pa;
    561  1.2    matt 
    562  1.2    matt 	/* Map the L2 pages tables in the L1 page table */
    563  1.2    matt 	pmap_link_l2pt(l1pagetable, 0x00000000,
    564  1.2    matt 	    &kernel_pt_table[KERNEL_PT_SYS]);
    565  1.2    matt 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    566  1.2    matt 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    567  1.2    matt 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    568  1.2    matt 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    569  1.2    matt 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    570  1.2    matt 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    571  1.2    matt 
    572  1.2    matt 	/* update the top of the kernel VM */
    573  1.2    matt 	pmap_curmaxkvaddr =
    574  1.2    matt 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    575  1.2    matt 
    576  1.2    matt #ifdef VERBOSE_INIT_ARM
    577  1.2    matt 	printf("Mapping kernel\n");
    578  1.2    matt #endif
    579  1.2    matt 
    580  1.2    matt 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    581  1.2    matt #define round_L_page(x) (((x) + L2_L_OFFSET) & L2_L_FRAME)
    582  1.2    matt 	{
    583  1.2    matt 		extern char etext[], _end[];
    584  1.2    matt 		size_t textsize = round_L_page((size_t)etext - KERNEL_TEXT_BASE);
    585  1.2    matt 		size_t totalsize = round_L_page((size_t)_end - KERNEL_TEXT_BASE);
    586  1.2    matt 		u_int logical;
    587  1.2    matt 
    588  1.2    matt 
    589  1.2    matt printf("%s: etext %lx, _end %lx\n",
    590  1.3   perry 	__func__, (uintptr_t)etext, (uintptr_t)_end);
    591  1.2    matt printf("%s: textsize %#lx, totalsize %#lx\n",
    592  1.3   perry 	__func__, textsize, totalsize);
    593  1.2    matt 
    594  1.2    matt 		logical = 0x00100000;	/* offset of kernel in RAM */
    595  1.2    matt 
    596  1.2    matt 		/* Map text section read-only. */
    597  1.2    matt 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    598  1.2    matt 		    physical_start + logical, textsize,
    599  1.2    matt 		    VM_PROT_READ|VM_PROT_EXECUTE, PTE_CACHE);
    600  1.2    matt 
    601  1.2    matt 		/* Map data and bss sections read-write. */
    602  1.2    matt 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    603  1.2    matt 		    physical_start + logical, totalsize - textsize,
    604  1.2    matt 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    605  1.2    matt 	}
    606  1.2    matt 
    607  1.2    matt #ifdef VERBOSE_INIT_ARM
    608  1.2    matt 	printf("Constructing L2 page tables\n");
    609  1.2    matt #endif
    610  1.2    matt 
    611  1.2    matt 	/* Map the stack pages */
    612  1.2    matt 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    613  1.2    matt 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    614  1.2    matt 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    615  1.2    matt 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    616  1.2    matt 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    617  1.2    matt 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    618  1.2    matt 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    619  1.2    matt 	    UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
    620  1.2    matt 
    621  1.2    matt 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    622  1.2    matt 	    L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
    623  1.2    matt 
    624  1.2    matt 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    625  1.2    matt 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    626  1.2    matt 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    627  1.2    matt 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    628  1.2    matt 	}
    629  1.2    matt 
    630  1.2    matt 	/* Map the vector page. */
    631  1.2    matt #if 1
    632  1.2    matt 	/* MULTI-ICE requires that page 0 is NC/NB so that it can download the
    633  1.2    matt 	 * cache-clean code there.  */
    634  1.2    matt 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    635  1.2    matt 	    VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
    636  1.2    matt #else
    637  1.2    matt 	pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
    638  1.2    matt 	    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    639  1.2    matt #endif
    640  1.2    matt 
    641  1.2    matt 	/*
    642  1.2    matt 	 * map integrated peripherals at same address in l1pagetable
    643  1.2    matt 	 * so that we can continue to use console.
    644  1.2    matt 	 */
    645  1.2    matt 	pmap_devmap_bootstrap(l1pagetable, imx31lk_devmap);
    646  1.2    matt 
    647  1.2    matt 	/*
    648  1.2    matt 	 * Now we have the real page tables in place so we can switch to them.
    649  1.2    matt 	 * Once this is done we will be running with the REAL kernel page
    650  1.2    matt 	 * tables.
    651  1.2    matt 	 */
    652  1.2    matt 
    653  1.2    matt 	/*
    654  1.2    matt 	 * Update the physical_freestart/physical_freeend/free_pages
    655  1.2    matt 	 * variables.
    656  1.2    matt 	 */
    657  1.2    matt 	{
    658  1.2    matt 		extern char _end[];
    659  1.2    matt 
    660  1.2    matt 		physical_freestart = physical_start +
    661  1.2    matt 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    662  1.2    matt 		     KERNEL_BASE);
    663  1.2    matt 		physical_freeend = physical_end;
    664  1.2    matt 		free_pages =
    665  1.2    matt 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    666  1.2    matt 	}
    667  1.2    matt 
    668  1.2    matt 	/* Switch tables */
    669  1.2    matt #ifdef VERBOSE_INIT_ARM
    670  1.2    matt 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    671  1.2    matt 	       physical_freestart, free_pages, free_pages);
    672  1.2    matt 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    673  1.2    matt #endif
    674  1.2    matt 
    675  1.2    matt 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    676  1.2    matt 	setttb(kernel_l1pt.pv_pa);
    677  1.2    matt 	cpu_tlb_flushID();
    678  1.2    matt 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    679  1.2    matt 	imx31lk_consinit(2);
    680  1.2    matt 
    681  1.2    matt 	/*
    682  1.2    matt 	 * Moved from cpu_startup() as data_abort_handler() references
    683  1.2    matt 	 * this during uvm init
    684  1.2    matt 	 */
    685  1.2    matt 	proc0paddr = (struct user *)kernelstack.pv_va;
    686  1.2    matt 	lwp0.l_addr = proc0paddr;
    687  1.2    matt 
    688  1.2    matt #ifdef VERBOSE_INIT_ARM
    689  1.2    matt 	printf("bootstrap done.\n");
    690  1.2    matt #endif
    691  1.2    matt 
    692  1.2    matt 	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
    693  1.2    matt 
    694  1.2    matt 	/*
    695  1.2    matt 	 * Pages were allocated during the secondary bootstrap for the
    696  1.2    matt 	 * stacks for different CPU modes.
    697  1.2    matt 	 * We must now set the r13 registers in the different CPU modes to
    698  1.2    matt 	 * point to these stacks.
    699  1.2    matt 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    700  1.2    matt 	 * of the stack memory.
    701  1.2    matt 	 */
    702  1.2    matt 	printf("init subsystems: stacks ");
    703  1.2    matt 
    704  1.2    matt 	set_stackptr(PSR_IRQ32_MODE, irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    705  1.2    matt 	set_stackptr(PSR_ABT32_MODE, abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    706  1.2    matt 	set_stackptr(PSR_UND32_MODE, undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    707  1.2    matt 
    708  1.2    matt 	/*
    709  1.2    matt 	 * Well we should set a data abort handler.
    710  1.2    matt 	 * Once things get going this will change as we will need a proper
    711  1.2    matt 	 * handler.
    712  1.2    matt 	 * Until then we will use a handler that just panics but tells us
    713  1.2    matt 	 * why.
    714  1.2    matt 	 * Initialisation of the vectors will just panic on a data abort.
    715  1.2    matt 	 * This just fills in a slightly better one.
    716  1.2    matt 	 */
    717  1.2    matt 	printf("vectors ");
    718  1.2    matt 	data_abort_handler_address = (u_int)data_abort_handler;
    719  1.2    matt 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    720  1.2    matt 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    721  1.2    matt 
    722  1.2    matt 	/* Initialise the undefined instruction handlers */
    723  1.2    matt 	printf("undefined ");
    724  1.2    matt 	undefined_init();
    725  1.2    matt 
    726  1.2    matt 	/* Load memory into UVM. */
    727  1.2    matt 	printf("page ");
    728  1.2    matt 	uvm_setpagesize();        /* initialize PAGE_SIZE-dependent variables */
    729  1.2    matt 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    730  1.2    matt 	    atop(physical_freestart), atop(physical_freeend),
    731  1.2    matt 	    VM_FREELIST_DEFAULT);
    732  1.2    matt 
    733  1.2    matt 	/* Boot strap pmap telling it where the kernel page table is */
    734  1.2    matt 	printf("pmap ");
    735  1.2    matt 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    736  1.2    matt 
    737  1.2    matt #ifdef __HAVE_MEMORY_DISK__
    738  1.2    matt 	md_root_setconf(memory_disk, sizeof memory_disk);
    739  1.2    matt #endif
    740  1.2    matt 
    741  1.2    matt #ifdef IPKDB
    742  1.2    matt 	/* Initialise ipkdb */
    743  1.2    matt 	ipkdb_init();
    744  1.2    matt 	if (boothowto & RB_KDB)
    745  1.2    matt 		ipkdb_connect(0);
    746  1.2    matt #endif
    747  1.2    matt 
    748  1.2    matt #ifdef KGDB
    749  1.2    matt 	if (boothowto & RB_KDB) {
    750  1.2    matt 		kgdb_debug_init = 1;
    751  1.2    matt 		kgdb_connect(1);
    752  1.2    matt 	}
    753  1.2    matt #endif
    754  1.2    matt 
    755  1.2    matt #ifdef DDB
    756  1.2    matt 	printf("ddb ");
    757  1.2    matt 	db_machine_init();
    758  1.2    matt 
    759  1.2    matt 	/* Firmware doesn't load symbols. */
    760  1.2    matt 	ddb_init(0, NULL, NULL);
    761  1.2    matt 
    762  1.2    matt 	if (boothowto & RB_KDB)
    763  1.2    matt 		Debugger();
    764  1.2    matt #endif
    765  1.2    matt 	/* We return the new stack pointer address */
    766  1.2    matt 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    767  1.2    matt }
    768  1.2    matt 
    769  1.2    matt #if 0
    770  1.2    matt void
    771  1.2    matt process_kernel_args(char *args)
    772  1.2    matt {
    773  1.2    matt 
    774  1.2    matt 	boothowto = 0;
    775  1.2    matt 
    776  1.2    matt 	/* Make a local copy of the bootargs */
    777  1.2    matt 	strncpy(bootargs, args, MAX_BOOT_STRING);
    778  1.2    matt 
    779  1.2    matt 	args = bootargs;
    780  1.2    matt 	boot_file = bootargs;
    781  1.2    matt 
    782  1.2    matt 	/* Skip the kernel image filename */
    783  1.2    matt 	while (*args != ' ' && *args != 0)
    784  1.2    matt 		++args;
    785  1.2    matt 
    786  1.2    matt 	if (*args != 0)
    787  1.2    matt 		*args++ = 0;
    788  1.2    matt 
    789  1.2    matt 	while (*args == ' ')
    790  1.2    matt 		++args;
    791  1.2    matt 
    792  1.2    matt 	boot_args = args;
    793  1.2    matt 
    794  1.2    matt 	printf("bootfile: %s\n", boot_file);
    795  1.2    matt 	printf("bootargs: %s\n", boot_args);
    796  1.2    matt 
    797  1.2    matt 	parse_mi_bootargs(boot_args);
    798  1.2    matt }
    799  1.2    matt #endif
    800  1.2    matt 
    801  1.2    matt #ifdef KGDB
    802  1.2    matt #ifndef KGDB_DEVNAME
    803  1.2    matt #define KGDB_DEVNAME "ffuart"
    804  1.2    matt #endif
    805  1.2    matt const char kgdb_devname[] = KGDB_DEVNAME;
    806  1.2    matt 
    807  1.2    matt #if (NCOM > 0)
    808  1.2    matt #ifndef KGDB_DEVMODE
    809  1.2    matt #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    810  1.2    matt #endif
    811  1.2    matt int comkgdbmode = KGDB_DEVMODE;
    812  1.2    matt #endif /* NCOM */
    813  1.2    matt 
    814  1.2    matt #endif /* KGDB */
    815  1.2    matt 
    816  1.2    matt 
    817  1.2    matt void
    818  1.2    matt imx31lk_consinit(int phase)
    819  1.2    matt {
    820  1.2    matt 	static int ophase = 0;
    821  1.2    matt 	intptr_t bh;
    822  1.2    matt 
    823  1.2    matt 	if (ophase != phase) {
    824  1.2    matt 		ophase = phase;
    825  1.2    matt 		switch (phase) {
    826  1.2    matt 		case 1:
    827  1.2    matt 			imxuart_init(0, IMX_UART1_BASE);
    828  1.2    matt 			break;
    829  1.2    matt 		case 2:
    830  1.2    matt 			bh = IMX31LITEKIT_UART1_VBASE;
    831  1.2    matt 			bh |= (IMX_UART1_BASE & ~_A(IMX_UART1_BASE));
    832  1.2    matt 			imxuart_init(0, bh);
    833  1.2    matt 			break;
    834  1.2    matt 		}
    835  1.2    matt 	}
    836  1.2    matt }
    837  1.2    matt 
    838  1.2    matt void
    839  1.2    matt consinit(void)
    840  1.2    matt {
    841  1.2    matt 	imx31lk_consinit(2);
    842  1.2    matt }
    843  1.2    matt 
    844  1.2    matt void consinit_test(void);
    845  1.2    matt void
    846  1.2    matt consinit_test(void)
    847  1.2    matt {
    848  1.2    matt 	imxuart_softc_t *sc, softc;
    849  1.2    matt 	extern int imxuart_puts(imxuart_softc_t *sc, const char *s);
    850  1.2    matt 
    851  1.3   perry 	printf("\n%s start\n", __func__);
    852  1.2    matt 	sc = &softc;
    853  1.2    matt 	sc->sc_init_cnt = 0;
    854  1.2    matt 	imxuart_init(sc, IMX_UART1_BASE);
    855  1.2    matt 	imxuart_puts(sc, "test1\r\n");
    856  1.2    matt 	imxuart_init(sc,
    857  1.2    matt 	    IMX31LITEKIT_UART1_VBASE|(IMX_UART1_BASE & ~_A(IMX_UART1_BASE)));
    858  1.2    matt 	imxuart_puts(sc, "test2\r\n");
    859  1.3   perry 	printf("%s done\n", __func__);
    860  1.2    matt }
    861  1.2    matt 
    862  1.2    matt #ifdef KGDB
    863  1.2    matt void
    864  1.2    matt kgdb_port_init(void)
    865  1.2    matt {
    866  1.2    matt #if (NCOM > 0) && defined(COM_PXA2X0)
    867  1.2    matt 	paddr_t paddr = 0;
    868  1.2    matt 	uint32_t ckenreg = ioreg_read(VIPER_CLKMAN_VBASE+CLKMAN_CKEN);
    869  1.2    matt 
    870  1.2    matt 	if (0 == strcmp(kgdb_devname, "ffuart")) {
    871  1.2    matt 		paddr = PXA2X0_FFUART_BASE;
    872  1.2    matt 		ckenreg |= CKEN_FFUART;
    873  1.2    matt 	}
    874  1.2    matt 	else if (0 == strcmp(kgdb_devname, "btuart")) {
    875  1.2    matt 		paddr = PXA2X0_BTUART_BASE;
    876  1.2    matt 		ckenreg |= CKEN_BTUART;
    877  1.2    matt 	}
    878  1.2    matt 
    879  1.2    matt 	if (paddr &&
    880  1.2    matt 	    0 == com_kgdb_attach(&imx31_a4x_bs_tag, paddr,
    881  1.2    matt 		kgdb_rate, PXA2X0_COM_FREQ, COM_TYPE_PXA2x0, comkgdbmode)) {
    882  1.2    matt 
    883  1.2    matt 		ioreg_write(VIPER_CLKMAN_VBASE+CLKMAN_CKEN, ckenreg);
    884  1.2    matt 	}
    885  1.2    matt #endif
    886  1.2    matt }
    887  1.2    matt #endif
    888