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