Home | History | Annotate | Line # | Download | only in at91
at91bus.c revision 1.1.20.3
      1  1.1.20.3  yamt /*	$NetBSD: at91bus.c,v 1.1.20.3 2010/03/11 15:02:04 yamt Exp $	*/
      2  1.1.20.1  yamt 
      3  1.1.20.1  yamt /*
      4  1.1.20.1  yamt  * Copyright (c) 2007 Embedtronics Oy
      5  1.1.20.1  yamt  * All rights reserved.
      6  1.1.20.1  yamt  *
      7  1.1.20.1  yamt  * Redistribution and use in source and binary forms, with or without
      8  1.1.20.1  yamt  * modification, are permitted provided that the following conditions
      9  1.1.20.1  yamt  * are met:
     10  1.1.20.1  yamt  * 1. Redistributions of source code must retain the above copyright
     11  1.1.20.1  yamt  *    notice, this list of conditions and the following disclaimer.
     12  1.1.20.1  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1.20.1  yamt  *    notice, this list of conditions and the following disclaimer in the
     14  1.1.20.1  yamt  *    documentation and/or other materials provided with the distribution.
     15  1.1.20.1  yamt  *
     16  1.1.20.1  yamt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1.20.1  yamt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1.20.1  yamt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1.20.1  yamt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1.20.1  yamt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1.20.1  yamt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1.20.1  yamt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1.20.1  yamt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1.20.1  yamt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1.20.1  yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1.20.1  yamt  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1.20.1  yamt  */
     28  1.1.20.1  yamt 
     29  1.1.20.1  yamt #include <sys/cdefs.h>
     30  1.1.20.3  yamt __KERNEL_RCSID(0, "$NetBSD: at91bus.c,v 1.1.20.3 2010/03/11 15:02:04 yamt Exp $");
     31  1.1.20.1  yamt 
     32  1.1.20.1  yamt #include "opt_ddb.h"
     33  1.1.20.1  yamt #include "opt_kgdb.h"
     34  1.1.20.1  yamt #include "opt_pmap_debug.h"
     35  1.1.20.1  yamt 
     36  1.1.20.1  yamt #include <sys/param.h>
     37  1.1.20.1  yamt #include <sys/device.h>
     38  1.1.20.1  yamt #include <sys/systm.h>
     39  1.1.20.1  yamt #include <sys/kernel.h>
     40  1.1.20.1  yamt #include <sys/exec.h>
     41  1.1.20.1  yamt #include <sys/proc.h>
     42  1.1.20.1  yamt #include <sys/msgbuf.h>
     43  1.1.20.1  yamt #include <sys/reboot.h>
     44  1.1.20.1  yamt #include <sys/termios.h>
     45  1.1.20.1  yamt #include <sys/ksyms.h>
     46  1.1.20.1  yamt 
     47  1.1.20.1  yamt #include <machine/bootconfig.h>
     48  1.1.20.1  yamt #include <uvm/uvm_extern.h>
     49  1.1.20.1  yamt 
     50  1.1.20.1  yamt #include <dev/cons.h>
     51  1.1.20.1  yamt 
     52  1.1.20.1  yamt #include <machine/db_machdep.h>
     53  1.1.20.1  yamt #include <ddb/db_sym.h>
     54  1.1.20.1  yamt #include <ddb/db_extern.h>
     55  1.1.20.1  yamt 
     56  1.1.20.1  yamt #include <machine/bus.h>
     57  1.1.20.1  yamt #include <machine/cpu.h>
     58  1.1.20.1  yamt #include <machine/frame.h>
     59  1.1.20.1  yamt #include <arm/undefined.h>
     60  1.1.20.1  yamt 
     61  1.1.20.1  yamt #include <arm/arm32/machdep.h>
     62  1.1.20.1  yamt #include <arm/cpufunc.h>
     63  1.1.20.1  yamt 
     64  1.1.20.1  yamt #include <arm/at91/at91var.h>
     65  1.1.20.1  yamt #include <arm/at91/at91busvar.h>
     66  1.1.20.1  yamt #include <arm/at91/at91dbgureg.h>
     67  1.1.20.1  yamt 
     68  1.1.20.1  yamt //#include <dev/cons.h>
     69  1.1.20.1  yamt #include <sys/termios.h>
     70  1.1.20.1  yamt 
     71  1.1.20.1  yamt #include "locators.h"
     72  1.1.20.1  yamt 
     73  1.1.20.1  yamt /* console stuff: */
     74  1.1.20.1  yamt #ifndef	CONSPEED
     75  1.1.20.1  yamt #define	CONSPEED B115200
     76  1.1.20.1  yamt #endif
     77  1.1.20.1  yamt 
     78  1.1.20.1  yamt #ifndef	CONMODE
     79  1.1.20.1  yamt #define	CONMODE	((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
     80  1.1.20.1  yamt #endif
     81  1.1.20.1  yamt 
     82  1.1.20.1  yamt int cnspeed = CONSPEED;
     83  1.1.20.1  yamt int cnmode = CONMODE;
     84  1.1.20.1  yamt 
     85  1.1.20.1  yamt 
     86  1.1.20.1  yamt /* kernel mapping: */
     87  1.1.20.1  yamt #define	KERNEL_BASE_PHYS	0x20200000
     88  1.1.20.1  yamt #define	KERNEL_TEXT_BASE	(KERNEL_BASE + 0x00200000)
     89  1.1.20.1  yamt #define	KERNEL_VM_BASE		(KERNEL_BASE + 0x01000000)
     90  1.1.20.1  yamt #define	KERNEL_VM_SIZE		0x0C000000
     91  1.1.20.1  yamt 
     92  1.1.20.1  yamt 
     93  1.1.20.1  yamt 
     94  1.1.20.1  yamt /* Define various stack sizes in pages */
     95  1.1.20.1  yamt #define IRQ_STACK_SIZE	8
     96  1.1.20.1  yamt #define ABT_STACK_SIZE	8
     97  1.1.20.1  yamt #ifdef IPKDB
     98  1.1.20.1  yamt #define UND_STACK_SIZE	16
     99  1.1.20.1  yamt #else
    100  1.1.20.1  yamt #define UND_STACK_SIZE	8
    101  1.1.20.1  yamt #endif
    102  1.1.20.1  yamt 
    103  1.1.20.1  yamt /* boot configuration: */
    104  1.1.20.1  yamt vm_offset_t physical_start;
    105  1.1.20.1  yamt vm_offset_t physical_freestart;
    106  1.1.20.1  yamt vm_offset_t physical_freeend;
    107  1.1.20.1  yamt vm_offset_t physical_freeend_low;
    108  1.1.20.1  yamt vm_offset_t physical_end;
    109  1.1.20.1  yamt u_int free_pages;
    110  1.1.20.1  yamt 
    111  1.1.20.1  yamt /* Physical and virtual addresses for some global pages */
    112  1.1.20.1  yamt pv_addr_t irqstack;
    113  1.1.20.1  yamt pv_addr_t undstack;
    114  1.1.20.1  yamt pv_addr_t abtstack;
    115  1.1.20.1  yamt pv_addr_t kernelstack;
    116  1.1.20.1  yamt 
    117  1.1.20.1  yamt vm_offset_t msgbufphys;
    118  1.1.20.1  yamt 
    119  1.1.20.1  yamt //static struct arm32_dma_range dma_ranges[4];
    120  1.1.20.1  yamt 
    121  1.1.20.1  yamt extern u_int data_abort_handler_address;
    122  1.1.20.1  yamt extern u_int prefetch_abort_handler_address;
    123  1.1.20.1  yamt extern u_int undefined_handler_address;
    124  1.1.20.1  yamt 
    125  1.1.20.1  yamt #ifdef PMAP_DEBUG
    126  1.1.20.1  yamt extern int pmap_debug_level;
    127  1.1.20.1  yamt #endif
    128  1.1.20.1  yamt 
    129  1.1.20.1  yamt #define KERNEL_PT_SYS		0	/* L2 table for mapping vectors page */
    130  1.1.20.1  yamt 
    131  1.1.20.1  yamt #define KERNEL_PT_KERNEL	1	/* L2 table for mapping kernel */
    132  1.1.20.1  yamt #define	KERNEL_PT_KERNEL_NUM	4
    133  1.1.20.1  yamt 					/* L2 tables for mapping kernel VM */
    134  1.1.20.1  yamt #define KERNEL_PT_VMDATA	(KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
    135  1.1.20.1  yamt 
    136  1.1.20.1  yamt #define	KERNEL_PT_VMDATA_NUM	4	/* start with 16MB of KVM */
    137  1.1.20.1  yamt #define NUM_KERNEL_PTS		(KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
    138  1.1.20.1  yamt 
    139  1.1.20.1  yamt pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
    140  1.1.20.1  yamt 
    141  1.1.20.1  yamt /* prototypes: */
    142  1.1.20.1  yamt void		consinit(void);
    143  1.1.20.1  yamt static int	at91bus_match(device_t, cfdata_t, void *);
    144  1.1.20.1  yamt static void	at91bus_attach(device_t, device_t, void *);
    145  1.1.20.1  yamt static int	at91bus_search(device_t, cfdata_t,
    146  1.1.20.1  yamt 			       const int *, void *);
    147  1.1.20.1  yamt static int	at91bus_print(void *, const char *);
    148  1.1.20.1  yamt static int	at91bus_submatch(device_t, cfdata_t,
    149  1.1.20.1  yamt 				 const int *, void *);
    150  1.1.20.1  yamt 
    151  1.1.20.1  yamt 
    152  1.1.20.1  yamt CFATTACH_DECL(at91bus, sizeof(struct at91bus_softc), at91bus_match, at91bus_attach, NULL, NULL);
    153  1.1.20.1  yamt 
    154  1.1.20.1  yamt struct at91bus_clocks at91bus_clocks = {0};
    155  1.1.20.1  yamt struct at91bus_softc *at91bus_sc = NULL;
    156  1.1.20.1  yamt 
    157  1.1.20.1  yamt #include "opt_at91types.h"
    158  1.1.20.1  yamt 
    159  1.1.20.1  yamt #ifdef	AT91RM9200
    160  1.1.20.1  yamt #include <arm/at91/at91rm9200busvar.h>
    161  1.1.20.1  yamt #endif
    162  1.1.20.1  yamt 
    163  1.1.20.1  yamt #ifdef	AT91SAM9261
    164  1.1.20.1  yamt #include <arm/at91/at91sam9261busvar.h>
    165  1.1.20.1  yamt #endif
    166  1.1.20.1  yamt 
    167  1.1.20.1  yamt static const struct {
    168  1.1.20.1  yamt 	u_int32_t	cidr;
    169  1.1.20.1  yamt 	const char *	name;
    170  1.1.20.1  yamt 	const struct at91bus_machdep *machdep;
    171  1.1.20.1  yamt } at91_types[] = {
    172  1.1.20.1  yamt 	{
    173  1.1.20.1  yamt 		DBGU_CIDR_AT91RM9200,
    174  1.1.20.1  yamt 		"AT91RM9200"
    175  1.1.20.1  yamt #ifdef	AT91RM9200
    176  1.1.20.1  yamt 		, &at91rm9200bus
    177  1.1.20.1  yamt #endif
    178  1.1.20.1  yamt 	},
    179  1.1.20.1  yamt 	{
    180  1.1.20.1  yamt 		DBGU_CIDR_AT91SAM9260,
    181  1.1.20.1  yamt 		"AT91SAM9260"
    182  1.1.20.1  yamt 	},
    183  1.1.20.1  yamt 	{
    184  1.1.20.1  yamt 		DBGU_CIDR_AT91SAM9260,
    185  1.1.20.1  yamt 		"AT91SAM9261"
    186  1.1.20.1  yamt #ifdef	AT91SAM9261
    187  1.1.20.1  yamt 		, &at91sam9261bus
    188  1.1.20.1  yamt #endif
    189  1.1.20.1  yamt 	},
    190  1.1.20.1  yamt 	{
    191  1.1.20.1  yamt 		DBGU_CIDR_AT91SAM9260,
    192  1.1.20.1  yamt 		"AT91SAM9263"
    193  1.1.20.1  yamt 	},
    194  1.1.20.1  yamt 	{
    195  1.1.20.1  yamt 		0,
    196  1.1.20.1  yamt 		0,
    197  1.1.20.1  yamt 		0
    198  1.1.20.1  yamt 	}
    199  1.1.20.1  yamt };
    200  1.1.20.1  yamt 
    201  1.1.20.1  yamt u_int32_t at91_chip_id;
    202  1.1.20.1  yamt static int at91_chip_ndx = -1;
    203  1.1.20.1  yamt struct at91bus_machdep at91bus_machdep = { 0 };
    204  1.1.20.1  yamt at91bus_tag_t at91bus_tag = 0;
    205  1.1.20.1  yamt 
    206  1.1.20.1  yamt static int
    207  1.1.20.1  yamt match_cid(void)
    208  1.1.20.1  yamt {
    209  1.1.20.1  yamt 	u_int32_t		cidr;
    210  1.1.20.1  yamt 	int			i;
    211  1.1.20.1  yamt 
    212  1.1.20.1  yamt 	/* get chip id */
    213  1.1.20.1  yamt 	cidr = DBGUREG(DBGU_CIDR);
    214  1.1.20.1  yamt 	at91_chip_id = cidr;
    215  1.1.20.1  yamt 
    216  1.1.20.1  yamt 	/* do we know it? */
    217  1.1.20.1  yamt 	for (i = 0; at91_types[i].name; i++) {
    218  1.1.20.1  yamt 		if (cidr == at91_types[i].cidr)
    219  1.1.20.1  yamt 			return i;
    220  1.1.20.1  yamt 	}
    221  1.1.20.1  yamt 
    222  1.1.20.1  yamt 	return -1;
    223  1.1.20.1  yamt }
    224  1.1.20.1  yamt 
    225  1.1.20.1  yamt int
    226  1.1.20.1  yamt at91bus_init(void)
    227  1.1.20.1  yamt {
    228  1.1.20.1  yamt 	int i = at91_chip_ndx = match_cid();
    229  1.1.20.1  yamt 
    230  1.1.20.1  yamt 	if (i < 0)
    231  1.1.20.1  yamt 		panic("%s: unknown chip", __FUNCTION__);
    232  1.1.20.1  yamt 
    233  1.1.20.1  yamt 	if (!at91_types[i].machdep)
    234  1.1.20.1  yamt 		panic("%s: %s is not supported", __FUNCTION__, at91_types[i].name);
    235  1.1.20.1  yamt 
    236  1.1.20.1  yamt 	memcpy(&at91bus_machdep, at91_types[i].machdep, sizeof(at91bus_machdep));
    237  1.1.20.1  yamt 	at91bus_tag = &at91bus_machdep;
    238  1.1.20.1  yamt 
    239  1.1.20.1  yamt 	return 0;
    240  1.1.20.1  yamt }
    241  1.1.20.1  yamt 
    242  1.1.20.1  yamt u_int
    243  1.1.20.1  yamt at91bus_setup(BootConfig *mem)
    244  1.1.20.1  yamt {
    245  1.1.20.1  yamt 	int loop;
    246  1.1.20.1  yamt 	int loop1;
    247  1.1.20.1  yamt 	u_int l1pagetable;
    248  1.1.20.1  yamt 
    249  1.1.20.1  yamt 	consinit();
    250  1.1.20.1  yamt 
    251  1.1.20.1  yamt #ifdef	VERBOSE_INIT_ARM
    252  1.1.20.1  yamt 	printf("\nNetBSD/AT91 booting ...\n");
    253  1.1.20.1  yamt #endif
    254  1.1.20.1  yamt 
    255  1.1.20.1  yamt 	// setup the CPU / MMU / TLB functions:
    256  1.1.20.1  yamt 	if (set_cpufuncs())
    257  1.1.20.1  yamt 		panic("%s: cpu not recognized", __FUNCTION__);
    258  1.1.20.1  yamt 
    259  1.1.20.1  yamt #ifdef	VERBOSE_INIT_ARM
    260  1.1.20.1  yamt 	printf("%s: configuring system...\n", __FUNCTION__);
    261  1.1.20.1  yamt #endif
    262  1.1.20.1  yamt 
    263  1.1.20.1  yamt 	/*
    264  1.1.20.1  yamt 	 * Setup the variables that define the availability of
    265  1.1.20.1  yamt 	 * physical memory.
    266  1.1.20.1  yamt 	 */
    267  1.1.20.1  yamt 	physical_start = mem->dram[0].address;
    268  1.1.20.1  yamt 	physical_end = mem->dram[0].address + mem->dram[0].pages * PAGE_SIZE;
    269  1.1.20.1  yamt 
    270  1.1.20.1  yamt 	physical_freestart = mem->dram[0].address + 0x9000ULL;
    271  1.1.20.1  yamt 	physical_freeend = KERNEL_BASE_PHYS;
    272  1.1.20.1  yamt 	physmem = (physical_end - physical_start) / PAGE_SIZE;
    273  1.1.20.1  yamt 
    274  1.1.20.1  yamt #ifdef	VERBOSE_INIT_ARM
    275  1.1.20.1  yamt 	printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
    276  1.1.20.1  yamt 	       physical_start, physical_end - 1);
    277  1.1.20.1  yamt #endif
    278  1.1.20.1  yamt 
    279  1.1.20.1  yamt 	free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
    280  1.1.20.1  yamt 
    281  1.1.20.1  yamt #ifdef	VERBOSE_INIT_ARM
    282  1.1.20.1  yamt 	printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
    283  1.1.20.1  yamt 	       physical_freestart, free_pages, free_pages);
    284  1.1.20.1  yamt #endif
    285  1.1.20.1  yamt 	/* Define a macro to simplify memory allocation */
    286  1.1.20.1  yamt #define	valloc_pages(var, np)				\
    287  1.1.20.1  yamt 	alloc_pages((var).pv_pa, (np));			\
    288  1.1.20.1  yamt 	(var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
    289  1.1.20.1  yamt 
    290  1.1.20.1  yamt #define alloc_pages(var, np)				\
    291  1.1.20.1  yamt 	physical_freeend -= ((np) * PAGE_SIZE);		\
    292  1.1.20.1  yamt 	if (physical_freeend < physical_freestart)	\
    293  1.1.20.1  yamt 		panic("initarm: out of memory");	\
    294  1.1.20.1  yamt 	(var) = physical_freeend;			\
    295  1.1.20.1  yamt 	free_pages -= (np);				\
    296  1.1.20.1  yamt 	memset((char *)(var), 0, ((np) * PAGE_SIZE));
    297  1.1.20.1  yamt 
    298  1.1.20.1  yamt 	loop1 = 0;
    299  1.1.20.1  yamt 	for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
    300  1.1.20.1  yamt 		/* Are we 16KB aligned for an L1 ? */
    301  1.1.20.1  yamt 		if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
    302  1.1.20.1  yamt 		    && kernel_l1pt.pv_pa == 0) {
    303  1.1.20.1  yamt 			valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
    304  1.1.20.1  yamt 		} else {
    305  1.1.20.1  yamt 			valloc_pages(kernel_pt_table[loop1],
    306  1.1.20.1  yamt 			    L2_TABLE_SIZE / PAGE_SIZE);
    307  1.1.20.1  yamt 			++loop1;
    308  1.1.20.1  yamt 		}
    309  1.1.20.1  yamt 	}
    310  1.1.20.1  yamt 
    311  1.1.20.1  yamt 	/* This should never be able to happen but better confirm that. */
    312  1.1.20.1  yamt 	if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
    313  1.1.20.1  yamt 		panic("initarm: Failed to align the kernel page directory");
    314  1.1.20.1  yamt 
    315  1.1.20.1  yamt 	/*
    316  1.1.20.1  yamt 	 * Allocate a page for the system vectors page
    317  1.1.20.1  yamt 	 */
    318  1.1.20.1  yamt 	valloc_pages(systempage, 1);
    319  1.1.20.1  yamt 	systempage.pv_va = 0x00000000;
    320  1.1.20.1  yamt 
    321  1.1.20.1  yamt 	/* Allocate stacks for all modes */
    322  1.1.20.1  yamt 	valloc_pages(irqstack, IRQ_STACK_SIZE);
    323  1.1.20.1  yamt 	valloc_pages(abtstack, ABT_STACK_SIZE);
    324  1.1.20.1  yamt 	valloc_pages(undstack, UND_STACK_SIZE);
    325  1.1.20.1  yamt 	valloc_pages(kernelstack, UPAGES);
    326  1.1.20.1  yamt 
    327  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    328  1.1.20.1  yamt 	printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
    329  1.1.20.1  yamt 	    irqstack.pv_va);
    330  1.1.20.1  yamt 	printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
    331  1.1.20.1  yamt 	    abtstack.pv_va);
    332  1.1.20.1  yamt 	printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
    333  1.1.20.1  yamt 	    undstack.pv_va);
    334  1.1.20.1  yamt 	printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
    335  1.1.20.1  yamt 	    kernelstack.pv_va);
    336  1.1.20.1  yamt #endif
    337  1.1.20.1  yamt 
    338  1.1.20.1  yamt 	alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
    339  1.1.20.1  yamt 
    340  1.1.20.1  yamt 	/*
    341  1.1.20.1  yamt 	 * Ok we have allocated physical pages for the primary kernel
    342  1.1.20.1  yamt 	 * page tables.  Save physical_freeend for when we give whats left
    343  1.1.20.1  yamt 	 * of memory below 2Mbyte to UVM.
    344  1.1.20.1  yamt 	 */
    345  1.1.20.1  yamt 
    346  1.1.20.1  yamt 	physical_freeend_low = physical_freeend;
    347  1.1.20.1  yamt 
    348  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    349  1.1.20.1  yamt 	printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
    350  1.1.20.1  yamt #endif
    351  1.1.20.1  yamt 
    352  1.1.20.1  yamt 	/*
    353  1.1.20.1  yamt 	 * Now we start construction of the L1 page table
    354  1.1.20.1  yamt 	 * We start by mapping the L2 page tables into the L1.
    355  1.1.20.1  yamt 	 * This means that we can replace L1 mappings later on if necessary
    356  1.1.20.1  yamt 	 */
    357  1.1.20.1  yamt 	l1pagetable = kernel_l1pt.pv_pa;
    358  1.1.20.1  yamt 
    359  1.1.20.1  yamt 	/* Map the L2 pages tables in the L1 page table */
    360  1.1.20.1  yamt 	pmap_link_l2pt(l1pagetable, 0x00000000, &kernel_pt_table[KERNEL_PT_SYS]);
    361  1.1.20.1  yamt 	for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
    362  1.1.20.1  yamt 		pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
    363  1.1.20.1  yamt 		    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
    364  1.1.20.1  yamt 	for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
    365  1.1.20.1  yamt 		pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
    366  1.1.20.1  yamt 		    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
    367  1.1.20.1  yamt 
    368  1.1.20.1  yamt 	/* update the top of the kernel VM */
    369  1.1.20.1  yamt 	pmap_curmaxkvaddr =
    370  1.1.20.1  yamt 	    KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
    371  1.1.20.1  yamt 
    372  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    373  1.1.20.1  yamt 	printf("Mapping kernel\n");
    374  1.1.20.1  yamt #endif
    375  1.1.20.1  yamt 
    376  1.1.20.1  yamt 	/* Now we fill in the L2 pagetable for the kernel static code/data */
    377  1.1.20.1  yamt 	{
    378  1.1.20.1  yamt 		extern char etext[], _end[];
    379  1.1.20.1  yamt 		size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
    380  1.1.20.1  yamt 		size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
    381  1.1.20.1  yamt 		u_int logical;
    382  1.1.20.1  yamt 
    383  1.1.20.1  yamt 		textsize = (textsize + PGOFSET) & ~PGOFSET;
    384  1.1.20.1  yamt 		totalsize = (totalsize + PGOFSET) & ~PGOFSET;
    385  1.1.20.1  yamt 
    386  1.1.20.1  yamt 		logical = KERNEL_BASE_PHYS - mem->dram[0].address;	/* offset of kernel in RAM */
    387  1.1.20.1  yamt 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    388  1.1.20.1  yamt 		    physical_start + logical, textsize,
    389  1.1.20.1  yamt 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    390  1.1.20.1  yamt 		logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
    391  1.1.20.1  yamt 		    physical_start + logical, totalsize - textsize,
    392  1.1.20.1  yamt 		    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    393  1.1.20.1  yamt 	}
    394  1.1.20.1  yamt 
    395  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    396  1.1.20.1  yamt 	printf("Constructing L2 page tables\n");
    397  1.1.20.1  yamt #endif
    398  1.1.20.1  yamt 
    399  1.1.20.1  yamt 	/* Map the stack pages */
    400  1.1.20.1  yamt 	pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
    401  1.1.20.1  yamt 	    IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    402  1.1.20.1  yamt 	pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
    403  1.1.20.1  yamt 	    ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    404  1.1.20.1  yamt 	pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
    405  1.1.20.1  yamt 	    UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    406  1.1.20.1  yamt 	pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
    407  1.1.20.1  yamt 	    UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    408  1.1.20.1  yamt 
    409  1.1.20.1  yamt 	pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
    410  1.1.20.1  yamt 	    L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    411  1.1.20.1  yamt 
    412  1.1.20.1  yamt 	for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
    413  1.1.20.1  yamt 		pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
    414  1.1.20.1  yamt 		    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
    415  1.1.20.1  yamt 		    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
    416  1.1.20.1  yamt 	}
    417  1.1.20.1  yamt 
    418  1.1.20.1  yamt 	/* Map the vector page. */
    419  1.1.20.1  yamt 	pmap_map_entry(l1pagetable, ARM_VECTORS_LOW, systempage.pv_pa,
    420  1.1.20.1  yamt 		       VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
    421  1.1.20.1  yamt 
    422  1.1.20.1  yamt 	/* Map the statically mapped devices. */
    423  1.1.20.1  yamt 	pmap_devmap_bootstrap(l1pagetable, at91_devmap());
    424  1.1.20.1  yamt 
    425  1.1.20.1  yamt 	/*
    426  1.1.20.1  yamt 	 * Update the physical_freestart/physical_freeend/free_pages
    427  1.1.20.1  yamt 	 * variables.
    428  1.1.20.1  yamt 	 */
    429  1.1.20.1  yamt 	{
    430  1.1.20.1  yamt 		extern char _end[];
    431  1.1.20.1  yamt 
    432  1.1.20.1  yamt 		physical_freestart = physical_start +
    433  1.1.20.1  yamt 		    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
    434  1.1.20.1  yamt 		     KERNEL_BASE);
    435  1.1.20.1  yamt 		physical_freeend = physical_end;
    436  1.1.20.1  yamt 		free_pages =
    437  1.1.20.1  yamt 		    (physical_freeend - physical_freestart) / PAGE_SIZE;
    438  1.1.20.1  yamt 	}
    439  1.1.20.1  yamt 
    440  1.1.20.1  yamt 	/*
    441  1.1.20.1  yamt 	 * Now we have the real page tables in place so we can switch to them.
    442  1.1.20.1  yamt 	 * Once this is done we will be running with the REAL kernel page
    443  1.1.20.1  yamt 	 * tables.
    444  1.1.20.1  yamt 	 */
    445  1.1.20.1  yamt 
    446  1.1.20.1  yamt 	/* Switch tables */
    447  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    448  1.1.20.1  yamt 	printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
    449  1.1.20.1  yamt 	       physical_freestart, free_pages, free_pages);
    450  1.1.20.1  yamt 	printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
    451  1.1.20.1  yamt #endif
    452  1.1.20.1  yamt 	cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
    453  1.1.20.3  yamt 	cpu_setttb(kernel_l1pt.pv_pa);
    454  1.1.20.1  yamt 	cpu_tlb_flushID();
    455  1.1.20.1  yamt 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
    456  1.1.20.1  yamt 
    457  1.1.20.1  yamt 	/*
    458  1.1.20.1  yamt 	 * Moved from cpu_startup() as data_abort_handler() references
    459  1.1.20.1  yamt 	 * this during uvm init
    460  1.1.20.1  yamt 	 */
    461  1.1.20.3  yamt 	uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
    462  1.1.20.1  yamt 
    463  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    464  1.1.20.1  yamt 	printf("done!\n");
    465  1.1.20.1  yamt #endif
    466  1.1.20.1  yamt 
    467  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    468  1.1.20.1  yamt 	printf("bootstrap done.\n");
    469  1.1.20.1  yamt #endif
    470  1.1.20.1  yamt 
    471  1.1.20.1  yamt 	/* @@@@ check this out: @@@ */
    472  1.1.20.1  yamt 	arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
    473  1.1.20.1  yamt 
    474  1.1.20.1  yamt 	/*
    475  1.1.20.1  yamt 	 * Pages were allocated during the secondary bootstrap for the
    476  1.1.20.1  yamt 	 * stacks for different CPU modes.
    477  1.1.20.1  yamt 	 * We must now set the r13 registers in the different CPU modes to
    478  1.1.20.1  yamt 	 * point to these stacks.
    479  1.1.20.1  yamt 	 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
    480  1.1.20.1  yamt 	 * of the stack memory.
    481  1.1.20.1  yamt 	 */
    482  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    483  1.1.20.1  yamt 	printf("init subsystems: stacks ");
    484  1.1.20.1  yamt #endif
    485  1.1.20.1  yamt 
    486  1.1.20.1  yamt 	set_stackptr(PSR_IRQ32_MODE,
    487  1.1.20.1  yamt 	    irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
    488  1.1.20.1  yamt 	set_stackptr(PSR_ABT32_MODE,
    489  1.1.20.1  yamt 	    abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
    490  1.1.20.1  yamt 	set_stackptr(PSR_UND32_MODE,
    491  1.1.20.1  yamt 	    undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
    492  1.1.20.1  yamt 
    493  1.1.20.1  yamt 	/*
    494  1.1.20.1  yamt 	 * Well we should set a data abort handler.
    495  1.1.20.1  yamt 	 * Once things get going this will change as we will need a proper
    496  1.1.20.1  yamt 	 * handler.
    497  1.1.20.1  yamt 	 * Until then we will use a handler that just panics but tells us
    498  1.1.20.1  yamt 	 * why.
    499  1.1.20.1  yamt 	 * Initialisation of the vectors will just panic on a data abort.
    500  1.1.20.1  yamt 	 * This just fills in a slightly better one.
    501  1.1.20.1  yamt 	 */
    502  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    503  1.1.20.1  yamt 	printf("vectors ");
    504  1.1.20.1  yamt #endif
    505  1.1.20.1  yamt 	data_abort_handler_address = (u_int)data_abort_handler;
    506  1.1.20.1  yamt 	prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
    507  1.1.20.1  yamt 	undefined_handler_address = (u_int)undefinedinstruction_bounce;
    508  1.1.20.1  yamt 
    509  1.1.20.1  yamt 	/* Initialise the undefined instruction handlers */
    510  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    511  1.1.20.1  yamt 	printf("undefined ");
    512  1.1.20.1  yamt #endif
    513  1.1.20.1  yamt 	undefined_init();
    514  1.1.20.1  yamt 
    515  1.1.20.1  yamt 	/* Load memory into UVM. */
    516  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    517  1.1.20.1  yamt 	printf("page ");
    518  1.1.20.1  yamt #endif
    519  1.1.20.1  yamt 	uvm_setpagesize();	/* initialize PAGE_SIZE-dependent variables */
    520  1.1.20.1  yamt 	uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
    521  1.1.20.1  yamt 	    atop(physical_freestart), atop(physical_freeend),
    522  1.1.20.1  yamt 	    VM_FREELIST_DEFAULT);
    523  1.1.20.1  yamt 	uvm_page_physload(atop(physical_start), atop(physical_freeend_low),
    524  1.1.20.1  yamt 	    atop(physical_start), atop(physical_freeend_low),
    525  1.1.20.1  yamt 	    VM_FREELIST_DEFAULT);
    526  1.1.20.1  yamt 
    527  1.1.20.1  yamt 	/* Boot strap pmap telling it where the kernel page table is */
    528  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    529  1.1.20.1  yamt 	printf("pmap ");
    530  1.1.20.1  yamt #endif
    531  1.1.20.1  yamt 	pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
    532  1.1.20.1  yamt 
    533  1.1.20.1  yamt 	/* Setup the IRQ system */
    534  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    535  1.1.20.1  yamt 	printf("irq ");
    536  1.1.20.1  yamt #endif
    537  1.1.20.1  yamt 	at91_intr_init();
    538  1.1.20.1  yamt 
    539  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    540  1.1.20.1  yamt 	printf("done.\n");
    541  1.1.20.1  yamt #endif
    542  1.1.20.1  yamt 
    543  1.1.20.1  yamt #ifdef BOOTHOWTO
    544  1.1.20.1  yamt 	boothowto = BOOTHOWTO;
    545  1.1.20.1  yamt #endif
    546  1.1.20.1  yamt 	boothowto = AB_VERBOSE | AB_DEBUG; // @@@@
    547  1.1.20.1  yamt 
    548  1.1.20.1  yamt #ifdef IPKDB
    549  1.1.20.1  yamt 	/* Initialise ipkdb */
    550  1.1.20.1  yamt 	ipkdb_init();
    551  1.1.20.1  yamt 	if (boothowto & RB_KDB)
    552  1.1.20.1  yamt 		ipkdb_connect(0);
    553  1.1.20.1  yamt #endif
    554  1.1.20.1  yamt 
    555  1.1.20.1  yamt #ifdef DDB
    556  1.1.20.1  yamt 	db_machine_init();
    557  1.1.20.1  yamt 	if (boothowto & RB_KDB)
    558  1.1.20.1  yamt 		Debugger();
    559  1.1.20.1  yamt #endif
    560  1.1.20.1  yamt #if 0
    561  1.1.20.1  yamt 	printf("test data abort...\n");
    562  1.1.20.1  yamt 	*((volatile uint32_t*)(0x1234567F)) = 0xdeadbeef;
    563  1.1.20.1  yamt #endif
    564  1.1.20.1  yamt 
    565  1.1.20.1  yamt #ifdef VERBOSE_INIT_ARM
    566  1.1.20.1  yamt   	printf("%s: returning new stack pointer 0x%lX\n", __FUNCTION__, (kernelstack.pv_va + USPACE_SVC_STACK_TOP));
    567  1.1.20.1  yamt #endif
    568  1.1.20.1  yamt 
    569  1.1.20.1  yamt 	/* We return the new stack pointer address */
    570  1.1.20.1  yamt 	return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
    571  1.1.20.1  yamt }
    572  1.1.20.1  yamt 
    573  1.1.20.1  yamt static int
    574  1.1.20.1  yamt at91bus_match(device_t parent, cfdata_t match, void *aux)
    575  1.1.20.1  yamt {
    576  1.1.20.1  yamt 	// we could detect the device here...
    577  1.1.20.1  yamt 	if (strcmp(match->cf_name, "at91bus") == 0)
    578  1.1.20.1  yamt 		return 1;
    579  1.1.20.1  yamt 	return 0;
    580  1.1.20.1  yamt }
    581  1.1.20.1  yamt 
    582  1.1.20.1  yamt static device_t
    583  1.1.20.1  yamt at91bus_found(device_t self, bus_addr_t addr, int pid)
    584  1.1.20.1  yamt {
    585  1.1.20.1  yamt 	int locs[AT91BUSCF_NLOCS];
    586  1.1.20.1  yamt 	struct at91bus_attach_args sa;
    587  1.1.20.1  yamt 	struct at91bus_softc *sc;
    588  1.1.20.1  yamt 
    589  1.1.20.1  yamt 	memset(&locs, 0, sizeof(locs));
    590  1.1.20.1  yamt 	memset(&sa, 0, sizeof(sa));
    591  1.1.20.1  yamt 
    592  1.1.20.1  yamt 	locs[AT91BUSCF_ADDR] = addr;
    593  1.1.20.1  yamt 	locs[AT91BUSCF_PID]  = pid;
    594  1.1.20.1  yamt 
    595  1.1.20.1  yamt 	sc = (struct at91bus_softc*) self;
    596  1.1.20.1  yamt 	sa.sa_iot = sc->sc_iot;
    597  1.1.20.1  yamt 	sa.sa_dmat = sc->sc_dmat;
    598  1.1.20.1  yamt 	sa.sa_addr = addr;
    599  1.1.20.1  yamt 	sa.sa_size = 1;
    600  1.1.20.1  yamt 	sa.sa_pid = pid;
    601  1.1.20.1  yamt 
    602  1.1.20.1  yamt 	return config_found_sm_loc(self, "at91bus", locs, &sa,
    603  1.1.20.1  yamt 				   at91bus_print, at91bus_submatch);
    604  1.1.20.1  yamt }
    605  1.1.20.1  yamt 
    606  1.1.20.1  yamt static void
    607  1.1.20.1  yamt at91bus_attach(device_t parent, device_t self, void *aux)
    608  1.1.20.1  yamt {
    609  1.1.20.1  yamt 	struct at91bus_softc	*sc;
    610  1.1.20.1  yamt 
    611  1.1.20.1  yamt 	if (at91_chip_ndx < 0)
    612  1.1.20.1  yamt 		panic("%s: at91bus_init() has not been called!", __FUNCTION__);
    613  1.1.20.1  yamt 
    614  1.1.20.1  yamt 	sc = (struct at91bus_softc*) self;
    615  1.1.20.1  yamt 
    616  1.1.20.1  yamt         /* initialize bus space and bus dma things... */
    617  1.1.20.1  yamt 	sc->sc_iot = &at91_bs_tag;
    618  1.1.20.1  yamt         sc->sc_dmat = at91_bus_dma_init(&at91_bd_tag);
    619  1.1.20.1  yamt 
    620  1.1.20.1  yamt 	if (at91bus_sc == NULL)
    621  1.1.20.1  yamt 		at91bus_sc = sc;
    622  1.1.20.1  yamt 
    623  1.1.20.1  yamt 	printf(": %s, sclk %u.%03u kHz, mclk %u.%03u MHz, pclk %u.%03u MHz, mstclk %u.%03u, plla %u.%03u, pllb %u.%03u MHz\n",
    624  1.1.20.1  yamt 	       at91_types[at91_chip_ndx].name,
    625  1.1.20.1  yamt 	       AT91_SCLK / 1000U, AT91_SCLK % 1000U,
    626  1.1.20.1  yamt 	       AT91_MCLK / 1000000U, (AT91_MCLK / 1000U) % 1000U,
    627  1.1.20.1  yamt 	       AT91_PCLK / 1000000U, (AT91_PCLK / 1000U) % 1000U,
    628  1.1.20.1  yamt 	       AT91_MSTCLK / 1000000U, (AT91_MSTCLK / 1000U) % 1000U,
    629  1.1.20.1  yamt 	       AT91_PLLACLK / 1000000U, (AT91_PLLACLK / 1000U) % 1000U,
    630  1.1.20.1  yamt 	       AT91_PLLBCLK / 1000000U, (AT91_PLLBCLK / 1000U) % 1000U);
    631  1.1.20.1  yamt 
    632  1.1.20.1  yamt 	/*
    633  1.1.20.1  yamt 	 *  Attach devices
    634  1.1.20.1  yamt 	 */
    635  1.1.20.1  yamt 	at91_search_peripherals(self, at91bus_found);
    636  1.1.20.1  yamt 
    637  1.1.20.1  yamt 
    638  1.1.20.1  yamt 	struct at91bus_attach_args sa;
    639  1.1.20.1  yamt 	memset(&sa, 0, sizeof(sa));
    640  1.1.20.1  yamt 	sa.sa_iot = sc->sc_iot;
    641  1.1.20.1  yamt 	sa.sa_dmat = sc->sc_dmat;
    642  1.1.20.1  yamt 	config_search_ia(at91bus_search, self, "at91bus", &sa);
    643  1.1.20.1  yamt }
    644  1.1.20.1  yamt 
    645  1.1.20.1  yamt int
    646  1.1.20.1  yamt at91bus_submatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    647  1.1.20.1  yamt {
    648  1.1.20.1  yamt 	struct at91bus_attach_args *sa = aux;
    649  1.1.20.1  yamt 
    650  1.1.20.1  yamt 	if (cf->cf_loc[AT91BUSCF_ADDR] == ldesc[AT91BUSCF_ADDR]
    651  1.1.20.1  yamt 	    && cf->cf_loc[AT91BUSCF_PID] == ldesc[AT91BUSCF_PID]) {
    652  1.1.20.1  yamt 		sa->sa_addr = cf->cf_loc[AT91BUSCF_ADDR];
    653  1.1.20.1  yamt 		sa->sa_size = cf->cf_loc[AT91BUSCF_SIZE];
    654  1.1.20.1  yamt 		sa->sa_pid  = cf->cf_loc[AT91BUSCF_PID];
    655  1.1.20.1  yamt 		return (config_match(parent, cf, aux));
    656  1.1.20.1  yamt 	} else
    657  1.1.20.1  yamt 		return (0);
    658  1.1.20.1  yamt }
    659  1.1.20.1  yamt 
    660  1.1.20.1  yamt int
    661  1.1.20.1  yamt at91bus_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    662  1.1.20.1  yamt {
    663  1.1.20.1  yamt 	struct at91bus_attach_args *sa = aux;
    664  1.1.20.1  yamt 
    665  1.1.20.1  yamt 	sa->sa_addr = cf->cf_loc[AT91BUSCF_ADDR];
    666  1.1.20.1  yamt 	sa->sa_size = cf->cf_loc[AT91BUSCF_SIZE];
    667  1.1.20.1  yamt 	sa->sa_pid  = cf->cf_loc[AT91BUSCF_PID];
    668  1.1.20.1  yamt 
    669  1.1.20.1  yamt 	if (config_match(parent, cf, aux) > 0)
    670  1.1.20.1  yamt 		config_attach(parent, cf, aux, at91bus_print);
    671  1.1.20.1  yamt 
    672  1.1.20.1  yamt 	return (0);
    673  1.1.20.1  yamt }
    674  1.1.20.1  yamt 
    675  1.1.20.1  yamt static int
    676  1.1.20.1  yamt at91bus_print(void *aux, const char *name)
    677  1.1.20.1  yamt {
    678  1.1.20.1  yamt         struct at91bus_attach_args *sa = (struct at91bus_attach_args*)aux;
    679  1.1.20.1  yamt 
    680  1.1.20.1  yamt 	if (name)
    681  1.1.20.1  yamt 		aprint_normal("%s at %s", sa->sa_pid >= 0 ? at91_peripheral_name(sa->sa_pid) : "device", name);
    682  1.1.20.1  yamt 
    683  1.1.20.1  yamt 	if (sa->sa_size)
    684  1.1.20.1  yamt 		aprint_normal(" at addr 0x%lx", sa->sa_addr);
    685  1.1.20.1  yamt 	if (sa->sa_size > 1)
    686  1.1.20.1  yamt 		aprint_normal("-0x%lx", sa->sa_addr + sa->sa_size - 1);
    687  1.1.20.1  yamt 	if (sa->sa_pid >= 0)
    688  1.1.20.1  yamt 		aprint_normal(" pid %d", sa->sa_pid);
    689  1.1.20.1  yamt 
    690  1.1.20.1  yamt 	return (UNCONF);
    691  1.1.20.1  yamt }
    692  1.1.20.1  yamt 
    693  1.1.20.1  yamt void	consinit(void)
    694  1.1.20.1  yamt {
    695  1.1.20.1  yamt 	static int consinit_called;
    696  1.1.20.1  yamt 
    697  1.1.20.1  yamt 	if (consinit_called != 0)
    698  1.1.20.1  yamt 		return;
    699  1.1.20.1  yamt 
    700  1.1.20.1  yamt 	consinit_called = 1;
    701  1.1.20.1  yamt 
    702  1.1.20.1  yamt 	if (at91_chip_ndx < 0)
    703  1.1.20.1  yamt 		panic("%s: at91_init() has not been called!", __FUNCTION__);
    704  1.1.20.1  yamt 
    705  1.1.20.1  yamt 	// call machine specific bus initialization code
    706  1.1.20.1  yamt 	(*at91bus_tag->init)(&at91bus_clocks);
    707  1.1.20.1  yamt 
    708  1.1.20.1  yamt 	// attach console
    709  1.1.20.1  yamt 	(*at91bus_tag->attach_cn)(&at91_bs_tag, cnspeed, cnmode);
    710  1.1.20.1  yamt }
    711