Home | History | Annotate | Line # | Download | only in walnut
machdep.c revision 1.45.2.2
      1  1.45.2.2     rmind /*	$NetBSD: machdep.c,v 1.45.2.2 2011/03/05 20:50:18 rmind Exp $	*/
      2       1.1       scw 
      3       1.1       scw /*
      4       1.1       scw  * Copyright 2001, 2002 Wasabi Systems, Inc.
      5       1.1       scw  * All rights reserved.
      6       1.1       scw  *
      7       1.1       scw  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      8       1.1       scw  *
      9       1.1       scw  * Redistribution and use in source and binary forms, with or without
     10       1.1       scw  * modification, are permitted provided that the following conditions
     11       1.1       scw  * are met:
     12       1.1       scw  * 1. Redistributions of source code must retain the above copyright
     13       1.1       scw  *    notice, this list of conditions and the following disclaimer.
     14       1.1       scw  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1       scw  *    notice, this list of conditions and the following disclaimer in the
     16       1.1       scw  *    documentation and/or other materials provided with the distribution.
     17       1.1       scw  * 3. All advertising materials mentioning features or use of this software
     18       1.1       scw  *    must display the following acknowledgement:
     19       1.1       scw  *      This product includes software developed for the NetBSD Project by
     20       1.1       scw  *      Wasabi Systems, Inc.
     21       1.1       scw  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22       1.1       scw  *    or promote products derived from this software without specific prior
     23       1.1       scw  *    written permission.
     24       1.1       scw  *
     25       1.1       scw  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26       1.1       scw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27       1.1       scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28       1.1       scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29       1.1       scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30       1.1       scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31       1.1       scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32       1.1       scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33       1.1       scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34       1.1       scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35       1.1       scw  * POSSIBILITY OF SUCH DAMAGE.
     36       1.1       scw  */
     37       1.1       scw 
     38       1.1       scw /*
     39       1.1       scw  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     40       1.1       scw  * Copyright (C) 1995, 1996 TooLs GmbH.
     41       1.1       scw  * All rights reserved.
     42       1.1       scw  *
     43       1.1       scw  * Redistribution and use in source and binary forms, with or without
     44       1.1       scw  * modification, are permitted provided that the following conditions
     45       1.1       scw  * are met:
     46       1.1       scw  * 1. Redistributions of source code must retain the above copyright
     47       1.1       scw  *    notice, this list of conditions and the following disclaimer.
     48       1.1       scw  * 2. Redistributions in binary form must reproduce the above copyright
     49       1.1       scw  *    notice, this list of conditions and the following disclaimer in the
     50       1.1       scw  *    documentation and/or other materials provided with the distribution.
     51       1.1       scw  * 3. All advertising materials mentioning features or use of this software
     52       1.1       scw  *    must display the following acknowledgement:
     53       1.1       scw  *	This product includes software developed by TooLs GmbH.
     54       1.1       scw  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     55       1.1       scw  *    derived from this software without specific prior written permission.
     56       1.1       scw  *
     57       1.1       scw  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     58       1.1       scw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59       1.1       scw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60       1.1       scw  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     61       1.1       scw  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     62       1.1       scw  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     63       1.1       scw  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     64       1.1       scw  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     65       1.1       scw  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     66       1.1       scw  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67       1.1       scw  */
     68      1.14     lukem 
     69      1.14     lukem #include <sys/cdefs.h>
     70  1.45.2.2     rmind __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.45.2.2 2011/03/05 20:50:18 rmind Exp $");
     71       1.1       scw 
     72       1.1       scw #include "opt_compat_netbsd.h"
     73       1.1       scw #include "opt_ddb.h"
     74       1.1       scw #include "opt_ipkdb.h"
     75      1.40       apb #include "opt_modular.h"
     76       1.1       scw 
     77       1.1       scw #include <sys/param.h>
     78       1.1       scw #include <sys/buf.h>
     79       1.1       scw #include <sys/exec.h>
     80       1.1       scw #include <sys/malloc.h>
     81       1.1       scw #include <sys/mbuf.h>
     82       1.1       scw #include <sys/mount.h>
     83       1.1       scw #include <sys/msgbuf.h>
     84       1.1       scw #include <sys/proc.h>
     85       1.1       scw #include <sys/reboot.h>
     86       1.1       scw #include <sys/syscallargs.h>
     87       1.1       scw #include <sys/syslog.h>
     88       1.1       scw #include <sys/systm.h>
     89       1.1       scw #include <sys/kernel.h>
     90       1.1       scw #include <sys/boot_flag.h>
     91       1.9     ragge #include <sys/ksyms.h>
     92      1.37    dyoung #include <sys/device.h>
     93       1.1       scw 
     94       1.1       scw #include <uvm/uvm_extern.h>
     95       1.1       scw 
     96       1.1       scw #include <net/netisr.h>
     97       1.1       scw 
     98      1.27   thorpej #include <prop/proplib.h>
     99      1.27   thorpej 
    100       1.1       scw #include <machine/bus.h>
    101       1.1       scw #include <machine/powerpc.h>
    102       1.1       scw #include <machine/trap.h>
    103       1.1       scw #include <machine/walnut.h>
    104  1.45.2.2     rmind #include <machine/pcb.h>
    105       1.1       scw 
    106       1.1       scw #include <powerpc/spr.h>
    107      1.45      matt #include <powerpc/ibm4xx/spr.h>
    108  1.45.2.1     rmind #include <powerpc/ibm4xx/dcr4xx.h>
    109       1.1       scw 
    110       1.1       scw #include <dev/cons.h>
    111  1.45.2.1     rmind #include <dev/pci/pcivar.h>
    112  1.45.2.1     rmind #include <dev/pci/pciconf.h>
    113       1.1       scw 
    114       1.9     ragge #include "ksyms.h"
    115       1.9     ragge 
    116       1.9     ragge #if defined(DDB)
    117       1.1       scw #include <machine/db_machdep.h>
    118       1.1       scw #include <ddb/db_extern.h>
    119       1.1       scw #endif
    120       1.1       scw 
    121      1.30  kiyohara 
    122      1.30  kiyohara #define TLB_PG_SIZE 	(16*1024*1024)
    123      1.30  kiyohara 
    124       1.1       scw /*
    125       1.1       scw  * Global variables used here and there
    126       1.1       scw  */
    127       1.1       scw struct vm_map *phys_map = NULL;
    128       1.1       scw 
    129       1.1       scw /*
    130       1.1       scw  * This should probably be in autoconf!				XXX
    131       1.1       scw  */
    132       1.1       scw char cpu_model[80];
    133       1.1       scw char machine[] = MACHINE;		/* from <machine/param.h> */
    134       1.1       scw char machine_arch[] = MACHINE_ARCH;	/* from <machine/param.h> */
    135       1.1       scw 
    136       1.1       scw char bootpath[256];
    137       1.1       scw paddr_t msgbuf_paddr;
    138       1.1       scw vaddr_t msgbuf_vaddr;
    139       1.1       scw 
    140      1.38        ad #if NKSYMS || defined(DDB) || defined(MODULAR)
    141       1.1       scw void *startsym, *endsym;
    142       1.1       scw #endif
    143       1.1       scw 
    144       1.1       scw int lcsplx(int);
    145       1.1       scw void initppc(u_int, u_int, char *, void *);
    146       1.1       scw 
    147       1.1       scw static void dumpsys(void);
    148       1.1       scw static void install_extint(void (*)(void));
    149       1.1       scw 
    150       1.1       scw #define MEMREGIONS	8
    151       1.1       scw struct mem_region physmemr[MEMREGIONS];		/* Hard code memory */
    152       1.1       scw struct mem_region availmemr[MEMREGIONS];	/* Who's supposed to set these up? */
    153       1.1       scw 
    154       1.1       scw struct board_cfg_data board_data;
    155       1.1       scw 
    156       1.1       scw void
    157       1.1       scw initppc(u_int startkernel, u_int endkernel, char *args, void *info_block)
    158       1.1       scw {
    159       1.1       scw 	extern int defaulttrap, defaultsize;
    160       1.1       scw 	extern int sctrap, scsize;
    161       1.1       scw 	extern int alitrap, alisize;
    162       1.1       scw 	extern int dsitrap, dsisize;
    163       1.1       scw 	extern int isitrap, isisize;
    164       1.1       scw 	extern int mchktrap, mchksize;
    165       1.1       scw 	extern int tlbimiss4xx, tlbim4size;
    166       1.1       scw 	extern int tlbdmiss4xx, tlbdm4size;
    167       1.1       scw 	extern int pitfitwdog, pitfitwdogsize;
    168       1.1       scw 	extern int debugtrap, debugsize;
    169       1.1       scw 	extern int errata51handler, errata51size;
    170       1.1       scw #ifdef DDB
    171       1.1       scw 	extern int ddblow, ddbsize;
    172       1.1       scw #endif
    173       1.1       scw #ifdef IPKDB
    174       1.1       scw 	extern int ipkdblow, ipkdbsize;
    175       1.1       scw #endif
    176      1.30  kiyohara 	vaddr_t va;
    177      1.20    simonb 	int exc, dbcr0;
    178       1.6      matt 	struct cpu_info * const ci = curcpu();
    179       1.1       scw 
    180       1.1       scw 	/* Disable all external interrupts */
    181  1.45.2.1     rmind 	mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, 0);
    182       1.1       scw 
    183       1.1       scw         /* Initialize cache info for memcpy, etc. */
    184       1.1       scw         cpu_probe_cache();
    185       1.1       scw 
    186       1.1       scw 	/* Save info block */
    187       1.1       scw 	memcpy(&board_data, info_block, sizeof(board_data));
    188       1.1       scw 
    189       1.1       scw 	memset(physmemr, 0, sizeof physmemr);
    190       1.1       scw 	memset(availmemr, 0, sizeof availmemr);
    191       1.1       scw 	physmemr[0].start = 0;
    192       1.1       scw 	physmemr[0].size = board_data.mem_size & ~PGOFSET;
    193       1.1       scw 	/* Lower memory reserved by eval board BIOS */
    194  1.45.2.1     rmind 	availmemr[0].start = startkernel;
    195       1.1       scw 	availmemr[0].size = board_data.mem_size - availmemr[0].start;
    196       1.1       scw 
    197      1.31     freza 	/* Linear map kernel memory */
    198      1.31     freza 	for (va = 0; va < endkernel; va += TLB_PG_SIZE)
    199      1.30  kiyohara 		ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
    200      1.30  kiyohara 
    201      1.31     freza 	/* Map console after physmem (see pmap_tlbmiss()) */
    202      1.31     freza 	ppc4xx_tlb_reserve(0xef000000, roundup(physmemr[0].size, TLB_PG_SIZE),
    203      1.31     freza 	    TLB_PG_SIZE, TLB_I | TLB_G);
    204      1.30  kiyohara 
    205       1.3   thorpej 	/*
    206       1.3   thorpej 	 * Initialize lwp0 and current pcb and pmap pointers.
    207       1.3   thorpej 	 */
    208       1.3   thorpej 	lwp0.l_cpu = ci;
    209       1.1       scw 
    210      1.43     rmind 	curpcb = lwp_getpcb(&lwp0);
    211      1.43     rmind 	memset(curpcb, 0, sizeof(struct pcb));
    212      1.17      matt 	curpcb->pcb_pm = pmap_kernel();
    213       1.1       scw 
    214       1.1       scw 	/*
    215       1.1       scw 	 * Set up trap vectors
    216       1.1       scw 	 */
    217       1.1       scw 	for (exc = EXC_RSVD; exc <= EXC_LAST; exc += 0x100)
    218       1.1       scw 		switch (exc) {
    219       1.1       scw 		default:
    220       1.1       scw 			memcpy((void *)exc, &defaulttrap, (size_t)&defaultsize);
    221       1.1       scw 			break;
    222       1.1       scw 		case EXC_EXI:
    223       1.1       scw 			/*
    224       1.1       scw 			 * This one is (potentially) installed during autoconf
    225       1.1       scw 			 */
    226       1.1       scw 			break;
    227       1.1       scw 		case EXC_SC:
    228       1.1       scw 			memcpy((void *)EXC_SC, &sctrap, (size_t)&scsize);
    229       1.1       scw 			break;
    230       1.1       scw 		case EXC_ALI:
    231       1.1       scw 			memcpy((void *)EXC_ALI, &alitrap, (size_t)&alisize);
    232       1.1       scw 			break;
    233       1.1       scw 		case EXC_DSI:
    234       1.1       scw 			memcpy((void *)EXC_DSI, &dsitrap, (size_t)&dsisize);
    235       1.1       scw 			break;
    236       1.1       scw 		case EXC_ISI:
    237       1.1       scw 			memcpy((void *)EXC_ISI, &isitrap, (size_t)&isisize);
    238       1.1       scw 			break;
    239       1.1       scw 		case EXC_MCHK:
    240       1.1       scw 			memcpy((void *)EXC_MCHK, &mchktrap, (size_t)&mchksize);
    241       1.1       scw 			break;
    242       1.1       scw 		case EXC_ITMISS:
    243       1.1       scw 			memcpy((void *)EXC_ITMISS, &tlbimiss4xx,
    244       1.1       scw 				(size_t)&tlbim4size);
    245       1.1       scw 			break;
    246       1.1       scw 		case EXC_DTMISS:
    247       1.1       scw 			memcpy((void *)EXC_DTMISS, &tlbdmiss4xx,
    248       1.1       scw 				(size_t)&tlbdm4size);
    249       1.1       scw 			break;
    250  1.45.2.1     rmind 		/*
    251  1.45.2.1     rmind 		 * EXC_PIT, EXC_FIT, EXC_WDOG handlers
    252  1.45.2.1     rmind 		 * are spaced by 0x10 bytes only..
    253       1.1       scw 		 */
    254  1.45.2.1     rmind 		case EXC_PIT:
    255       1.1       scw 			memcpy((void *)EXC_PIT, &pitfitwdog,
    256       1.1       scw 				(size_t)&pitfitwdogsize);
    257       1.1       scw 			break;
    258       1.1       scw 		case EXC_DEBUG:
    259       1.1       scw 			memcpy((void *)EXC_DEBUG, &debugtrap,
    260       1.1       scw 				(size_t)&debugsize);
    261       1.1       scw 			break;
    262       1.1       scw 		case EXC_DTMISS|EXC_ALI:
    263  1.45.2.1     rmind                         /* PPC405GP Rev D errata item 51 */
    264       1.1       scw 			memcpy((void *)(EXC_DTMISS|EXC_ALI), &errata51handler,
    265       1.1       scw 				(size_t)&errata51size);
    266       1.1       scw 			break;
    267       1.2   thorpej #if defined(DDB) || defined(IPKDB)
    268       1.1       scw 		case EXC_PGM:
    269       1.1       scw #if defined(DDB)
    270       1.1       scw 			memcpy((void *)exc, &ddblow, (size_t)&ddbsize);
    271       1.1       scw #elif defined(IPKDB)
    272       1.1       scw 			memcpy((void *)exc, &ipkdblow, (size_t)&ipkdbsize);
    273       1.1       scw #endif
    274       1.2   thorpej #endif /* DDB | IPKDB */
    275       1.1       scw 			break;
    276       1.1       scw 		}
    277       1.1       scw 
    278       1.1       scw 	__syncicache((void *)EXC_RST, EXC_LAST - EXC_RST + 0x100);
    279       1.1       scw 	mtspr(SPR_EVPR, 0);		/* Set Exception vector base */
    280      1.29    simonb 
    281       1.1       scw 	consinit();
    282       1.1       scw 
    283       1.1       scw 	/* Handle trap instruction as PGM exception */
    284      1.25     perry 	__asm volatile("mfspr %0,%1":"=r"(dbcr0):"K"(SPR_DBCR0));
    285      1.25     perry 	__asm volatile("mtspr %0,%1"::"K"(SPR_DBCR0),"r"(dbcr0 & ~DBCR0_TDE));
    286       1.1       scw 
    287       1.1       scw 	/*
    288       1.1       scw 	 * external interrupt handler install
    289       1.1       scw 	 */
    290       1.1       scw 	install_extint(ext_intr);
    291       1.1       scw 
    292       1.1       scw 	/*
    293       1.1       scw 	 * Now enable translation (and machine checks/recoverable interrupts).
    294       1.1       scw 	 */
    295      1.25     perry 	__asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0; isync"
    296  1.45.2.1     rmind 		      : : "r"(0), "K"(PSL_IR|PSL_DR));
    297       1.1       scw 	/* XXXX PSL_ME - With ME set kernel gets stuck... */
    298       1.1       scw 
    299       1.1       scw 	uvm_setpagesize();
    300       1.1       scw 
    301       1.1       scw 	/*
    302       1.1       scw 	 * Initialize pmap module.
    303       1.1       scw 	 */
    304       1.1       scw 	pmap_bootstrap(startkernel, endkernel);
    305       1.1       scw 
    306       1.1       scw #ifdef DEBUG
    307       1.1       scw 	printf("Board config data:\n");
    308       1.1       scw 	printf("  usr_config_ver = %s\n", board_data.usr_config_ver);
    309       1.1       scw 	printf("  rom_sw_ver = %s\n", board_data.rom_sw_ver);
    310       1.1       scw 	printf("  mem_size = %u\n", board_data.mem_size);
    311       1.1       scw 	printf("  mac_address_local = %02x:%02x:%02x:%02x:%02x:%02x\n",
    312       1.1       scw 	    board_data.mac_address_local[0], board_data.mac_address_local[1],
    313       1.1       scw 	    board_data.mac_address_local[2], board_data.mac_address_local[3],
    314       1.1       scw 	    board_data.mac_address_local[4], board_data.mac_address_local[5]);
    315       1.1       scw 	printf("  mac_address_pci = %02x:%02x:%02x:%02x:%02x:%02x\n",
    316       1.1       scw 	    board_data.mac_address_pci[0], board_data.mac_address_pci[1],
    317       1.1       scw 	    board_data.mac_address_pci[2], board_data.mac_address_pci[3],
    318       1.1       scw 	    board_data.mac_address_pci[4], board_data.mac_address_pci[5]);
    319       1.1       scw 	printf("  processor_speed = %u\n", board_data.processor_speed);
    320       1.1       scw 	printf("  plb_speed = %u\n", board_data.plb_speed);
    321       1.1       scw 	printf("  pci_speed = %u\n", board_data.pci_speed);
    322       1.1       scw #endif
    323       1.1       scw 
    324      1.38        ad #if NKSYMS || defined(DDB) || defined(MODULAR)
    325      1.39    martin 	ksyms_addsyms_elf((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
    326       1.9     ragge #endif
    327       1.1       scw #ifdef DDB
    328       1.1       scw 	if (boothowto & RB_KDB)
    329       1.1       scw 		Debugger();
    330       1.1       scw #endif
    331       1.1       scw #ifdef IPKDB
    332       1.1       scw 	/*
    333       1.1       scw 	 * Now trap to IPKDB
    334       1.1       scw 	 */
    335       1.1       scw 	ipkdb_init();
    336       1.1       scw 	if (boothowto & RB_KDB)
    337       1.1       scw 		ipkdb_connect(0);
    338       1.1       scw #endif
    339       1.1       scw }
    340       1.1       scw 
    341       1.1       scw static void
    342       1.1       scw install_extint(void (*handler)(void))
    343       1.1       scw {
    344       1.1       scw 	extern int extint, extsize;
    345       1.1       scw 	extern u_long extint_call;
    346       1.1       scw 	u_long offset = (u_long)handler - (u_long)&extint_call;
    347      1.13    simonb 	int msr;
    348       1.1       scw 
    349       1.1       scw #ifdef	DIAGNOSTIC
    350       1.1       scw 	if (offset > 0x1ffffff)
    351       1.1       scw 		panic("install_extint: too far away");
    352       1.1       scw #endif
    353      1.25     perry 	__asm volatile ("mfmsr %0; wrteei 0" : "=r"(msr));
    354       1.1       scw 	extint_call = (extint_call & 0xfc000003) | offset;
    355       1.1       scw 	memcpy((void *)EXC_EXI, &extint, (size_t)&extsize);
    356       1.1       scw 	__syncicache((void *)&extint_call, sizeof extint_call);
    357       1.1       scw 	__syncicache((void *)EXC_EXI, (int)&extsize);
    358      1.25     perry 	__asm volatile ("mtmsr %0" :: "r"(msr));
    359       1.1       scw }
    360       1.1       scw 
    361       1.1       scw /*
    362       1.1       scw  * Machine dependent startup code.
    363       1.1       scw  */
    364       1.1       scw 
    365       1.1       scw char msgbuf[MSGBUFSIZE];
    366       1.1       scw 
    367       1.1       scw void
    368       1.1       scw cpu_startup(void)
    369       1.1       scw {
    370       1.1       scw 	vaddr_t minaddr, maxaddr;
    371      1.27   thorpej 	prop_number_t pn;
    372      1.27   thorpej 	prop_data_t pd;
    373       1.1       scw 	char pbuf[9];
    374       1.1       scw 
    375       1.1       scw 	/*
    376       1.1       scw 	 * Initialize error message buffer (at end of core).
    377       1.1       scw 	 */
    378       1.1       scw #if 0	/* For some reason this fails... --Artem
    379       1.1       scw 	 * Besides, do we really have to put it at the end of core?
    380       1.1       scw 	 * Let's use static buffer for now
    381       1.1       scw 	 */
    382      1.22      yamt 	if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE), 0,
    383      1.22      yamt 	    UVM_KMF_VAONLY)))
    384       1.1       scw 		panic("startup: no room for message buffer");
    385       1.1       scw 	for (i = 0; i < btoc(MSGBUFSIZE); i++)
    386       1.8   thorpej 		pmap_kenter_pa(msgbuf_vaddr + i * PAGE_SIZE,
    387      1.41    cegger 		    msgbuf_paddr + i * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, 0);
    388      1.35  christos 	initmsgbuf((void *)msgbuf_vaddr, round_page(MSGBUFSIZE));
    389       1.1       scw #else
    390      1.35  christos 	initmsgbuf((void *)msgbuf, round_page(MSGBUFSIZE));
    391       1.1       scw #endif
    392       1.1       scw 
    393      1.23     lukem 	printf("%s%s", copyright, version);
    394       1.1       scw 	printf("Walnut PowerPC 405GP Evaluation Board\n");
    395       1.1       scw 
    396       1.1       scw 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    397       1.1       scw 	printf("total memory = %s\n", pbuf);
    398       1.1       scw 
    399       1.1       scw 	minaddr = 0;
    400       1.1       scw 	/*
    401       1.1       scw 	 * Allocate a submap for physio
    402       1.1       scw 	 */
    403       1.1       scw 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    404      1.34   thorpej 				 VM_PHYS_SIZE, 0, false, NULL);
    405       1.1       scw 
    406       1.1       scw 	/*
    407       1.1       scw 	 * No need to allocate an mbuf cluster submap.  Mbuf clusters
    408       1.1       scw 	 * are allocated via the pool allocator, and we use direct-mapped
    409       1.1       scw 	 * pool pages.
    410       1.1       scw 	 */
    411       1.1       scw 
    412       1.1       scw 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    413       1.1       scw 	printf("avail memory = %s\n", pbuf);
    414       1.1       scw 
    415       1.1       scw 	/*
    416      1.27   thorpej 	 * Set up the board properties dictionary.
    417       1.1       scw 	 */
    418      1.27   thorpej 	board_properties = prop_dictionary_create();
    419      1.27   thorpej 	KASSERT(board_properties != NULL);
    420       1.1       scw 
    421      1.27   thorpej 	pn = prop_number_create_integer(board_data.mem_size);
    422      1.27   thorpej 	KASSERT(pn != NULL);
    423      1.34   thorpej 	if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
    424       1.1       scw 		panic("setting mem-size");
    425      1.27   thorpej 	prop_object_release(pn);
    426      1.27   thorpej 
    427      1.27   thorpej 	pd = prop_data_create_data_nocopy(board_data.mac_address_local,
    428      1.27   thorpej 					  sizeof(board_data.mac_address_local));
    429      1.27   thorpej 	KASSERT(pd != NULL);
    430      1.27   thorpej 	if (prop_dictionary_set(board_properties, "emac0-mac-addr",
    431      1.34   thorpej 				pd) == false)
    432      1.26   thorpej 		panic("setting emac0-mac-addr");
    433      1.27   thorpej 	prop_object_release(pd);
    434      1.27   thorpej 
    435      1.27   thorpej 	pd = prop_data_create_data_nocopy(board_data.mac_address_pci,
    436      1.27   thorpej 					  sizeof(board_data.mac_address_pci));
    437      1.27   thorpej 	KASSERT(pd != NULL);
    438      1.27   thorpej 	if (prop_dictionary_set(board_properties, "sip0-mac-addr",
    439      1.34   thorpej 				pd) == false)
    440       1.1       scw 		panic("setting sip0-mac-addr");
    441      1.27   thorpej 	prop_object_release(pd);
    442      1.27   thorpej 
    443      1.27   thorpej 	pn = prop_number_create_integer(board_data.processor_speed);
    444      1.27   thorpej 	KASSERT(pn != NULL);
    445      1.27   thorpej 	if (prop_dictionary_set(board_properties, "processor-frequency",
    446      1.34   thorpej 				pn) == false)
    447       1.1       scw 		panic("setting processor-frequency");
    448      1.27   thorpej 	prop_object_release(pn);
    449      1.16       scw 
    450      1.16       scw 	/*
    451      1.16       scw 	 * Now that we have VM, malloc()s are OK in bus_space.
    452      1.16       scw 	 */
    453      1.16       scw 	bus_space_mallocok();
    454      1.16       scw 	fake_mapiodev = 0;
    455       1.1       scw }
    456       1.1       scw 
    457       1.1       scw 
    458       1.1       scw static void
    459       1.1       scw dumpsys(void)
    460       1.1       scw {
    461       1.1       scw 
    462       1.1       scw 	printf("dumpsys: TBD\n");
    463       1.1       scw }
    464       1.1       scw 
    465       1.1       scw /*
    466       1.1       scw  * Halt or reboot the machine after syncing/dumping according to howto.
    467       1.1       scw  */
    468       1.1       scw void
    469       1.1       scw cpu_reboot(int howto, char *what)
    470       1.1       scw {
    471       1.1       scw 	static int syncing;
    472       1.1       scw 	static char str[256];
    473       1.1       scw 	char *ap = str, *ap1 = ap;
    474       1.1       scw 
    475       1.1       scw 	boothowto = howto;
    476       1.1       scw 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    477       1.1       scw 		syncing = 1;
    478       1.1       scw 		vfs_shutdown();		/* sync */
    479       1.1       scw 		resettodr();		/* set wall clock */
    480       1.1       scw 	}
    481       1.1       scw 
    482       1.1       scw 	splhigh();
    483       1.1       scw 
    484       1.1       scw 	if (!cold && (howto & RB_DUMP))
    485       1.1       scw 		dumpsys();
    486       1.1       scw 
    487       1.1       scw 	doshutdownhooks();
    488       1.1       scw 
    489      1.37    dyoung 	pmf_system_shutdown(boothowto);
    490      1.37    dyoung 
    491       1.1       scw 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    492       1.1       scw 	  /* Power off here if we know how...*/
    493       1.1       scw 	}
    494       1.1       scw 
    495       1.1       scw 	if (howto & RB_HALT) {
    496       1.1       scw 		printf("halted\n\n");
    497       1.1       scw 
    498       1.1       scw 		goto reboot;	/* XXX for now... */
    499       1.1       scw 
    500       1.1       scw #ifdef DDB
    501       1.1       scw 		printf("dropping to debugger\n");
    502       1.1       scw 		while(1)
    503       1.1       scw 			Debugger();
    504       1.1       scw #endif
    505       1.1       scw 	}
    506       1.1       scw 
    507       1.1       scw 	printf("rebooting\n\n");
    508       1.1       scw 	if (what && *what) {
    509       1.1       scw 		if (strlen(what) > sizeof str - 5)
    510       1.1       scw 			printf("boot string too large, ignored\n");
    511       1.1       scw 		else {
    512       1.1       scw 			strcpy(str, what);
    513       1.1       scw 			ap1 = ap = str + strlen(str);
    514       1.1       scw 			*ap++ = ' ';
    515       1.1       scw 		}
    516       1.1       scw 	}
    517       1.1       scw 	*ap++ = '-';
    518       1.1       scw 	if (howto & RB_SINGLE)
    519       1.1       scw 		*ap++ = 's';
    520       1.1       scw 	if (howto & RB_KDB)
    521       1.1       scw 		*ap++ = 'd';
    522       1.1       scw 	*ap++ = 0;
    523       1.1       scw 	if (ap[-2] == '-')
    524       1.1       scw 		*ap1 = 0;
    525       1.1       scw 
    526       1.1       scw 	/* flush cache for msgbuf */
    527       1.1       scw 	__syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
    528       1.1       scw 
    529       1.1       scw  reboot:
    530       1.1       scw 	ppc4xx_reset();
    531       1.1       scw 
    532       1.1       scw 	printf("ppc4xx_reset() failed!\n");
    533       1.1       scw #ifdef DDB
    534       1.1       scw 	while(1)
    535       1.1       scw 		Debugger();
    536       1.1       scw #else
    537       1.1       scw 	while (1)
    538       1.1       scw 		/* nothing */;
    539       1.1       scw #endif
    540       1.1       scw }
    541       1.1       scw 
    542       1.1       scw int
    543       1.1       scw lcsplx(int ipl)
    544       1.1       scw {
    545       1.1       scw 
    546       1.1       scw 	return spllower(ipl); 	/* XXX */
    547       1.1       scw }
    548       1.1       scw 
    549       1.1       scw void
    550       1.1       scw mem_regions(struct mem_region **mem, struct mem_region **avail)
    551       1.1       scw {
    552       1.1       scw 
    553       1.1       scw 	*mem = physmemr;
    554       1.1       scw 	*avail = availmemr;
    555       1.1       scw }
    556  1.45.2.1     rmind 
    557  1.45.2.1     rmind 
    558  1.45.2.1     rmind int
    559  1.45.2.1     rmind pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
    560  1.45.2.1     rmind {
    561  1.45.2.1     rmind 
    562  1.45.2.1     rmind 	/*
    563  1.45.2.1     rmind 	 * Bus number is irrelevant.  Configuration Mechanism 1 is in
    564  1.45.2.1     rmind 	 * use, can have devices 0-32 (i.e. the `normal' range).
    565  1.45.2.1     rmind 	 */
    566  1.45.2.1     rmind 	return 5;
    567  1.45.2.1     rmind }
    568  1.45.2.1     rmind 
    569  1.45.2.1     rmind int
    570  1.45.2.1     rmind pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    571  1.45.2.1     rmind {
    572  1.45.2.1     rmind 	int pin = pa->pa_intrpin;
    573  1.45.2.1     rmind 	int dev = pa->pa_device;
    574  1.45.2.1     rmind 
    575  1.45.2.1     rmind 	if (pin == 0)
    576  1.45.2.1     rmind 		/* No IRQ used. */
    577  1.45.2.1     rmind 		goto bad;
    578  1.45.2.1     rmind 
    579  1.45.2.1     rmind 	if (pin > 4) {
    580  1.45.2.1     rmind 		printf("pci_intr_map: bad interrupt pin %d\n", pin);
    581  1.45.2.1     rmind 		goto bad;
    582  1.45.2.1     rmind 	}
    583  1.45.2.1     rmind 
    584  1.45.2.1     rmind 	/*
    585  1.45.2.1     rmind 	 * We need to map the interrupt pin to the interrupt bit in the UIC
    586  1.45.2.1     rmind 	 * associated with it.  This is highly machine-dependent.
    587  1.45.2.1     rmind 	 */
    588  1.45.2.1     rmind 	switch(dev) {
    589  1.45.2.1     rmind 	case 1:
    590  1.45.2.1     rmind 	case 2:
    591  1.45.2.1     rmind 	case 3:
    592  1.45.2.1     rmind 	case 4:
    593  1.45.2.1     rmind 		*ihp = 27 + dev;
    594  1.45.2.1     rmind 		break;
    595  1.45.2.1     rmind 	default:
    596  1.45.2.1     rmind 		printf("Hmm.. PCI device %d should not exist on this board\n",
    597  1.45.2.1     rmind 			dev);
    598  1.45.2.1     rmind 		goto bad;
    599  1.45.2.1     rmind 	}
    600  1.45.2.1     rmind 	return 0;
    601  1.45.2.1     rmind 
    602  1.45.2.1     rmind bad:
    603  1.45.2.1     rmind 	*ihp = -1;
    604  1.45.2.1     rmind 	return 1;
    605  1.45.2.1     rmind }
    606  1.45.2.1     rmind 
    607  1.45.2.1     rmind void
    608  1.45.2.1     rmind pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin,
    609  1.45.2.1     rmind 		   int swiz, int *iline)
    610  1.45.2.1     rmind {
    611  1.45.2.1     rmind 
    612  1.45.2.1     rmind 	if (bus == 0)
    613  1.45.2.1     rmind 		switch(dev) {
    614  1.45.2.1     rmind 		case 1:
    615  1.45.2.1     rmind 		case 2:
    616  1.45.2.1     rmind 		case 3:
    617  1.45.2.1     rmind 		case 4:
    618  1.45.2.1     rmind 			*iline = 31 - dev;
    619  1.45.2.1     rmind 		}
    620  1.45.2.1     rmind 	else
    621  1.45.2.1     rmind 		*iline = 20 + ((swiz + dev + 1) & 3);
    622  1.45.2.1     rmind }
    623