Home | History | Annotate | Line # | Download | only in pci
pci_machdep.c revision 1.4
      1 /*	$NetBSD: pci_machdep.c,v 1.4 2003/05/29 20:22:32 fvdl Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
     42  * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
     43  *
     44  * Redistribution and use in source and binary forms, with or without
     45  * modification, are permitted provided that the following conditions
     46  * are met:
     47  * 1. Redistributions of source code must retain the above copyright
     48  *    notice, this list of conditions and the following disclaimer.
     49  * 2. Redistributions in binary form must reproduce the above copyright
     50  *    notice, this list of conditions and the following disclaimer in the
     51  *    documentation and/or other materials provided with the distribution.
     52  * 3. All advertising materials mentioning features or use of this software
     53  *    must display the following acknowledgement:
     54  *	This product includes software developed by Charles M. Hannum.
     55  * 4. The name of the author may not be used to endorse or promote products
     56  *    derived from this software without specific prior written permission.
     57  *
     58  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     59  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     62  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     63  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     64  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     65  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     66  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     67  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68  */
     69 
     70 /*
     71  * Machine-specific functions for PCI autoconfiguration.
     72  *
     73  * On PCs, there are two methods of generating PCI configuration cycles.
     74  * We try to detect the appropriate mechanism for this machine and set
     75  * up a few function pointers to access the correct method directly.
     76  *
     77  * The configuration method can be hard-coded in the config file by
     78  * using `options PCI_CONF_MODE=N', where `N' is the configuration mode
     79  * as defined section 3.6.4.1, `Generating Configuration Cycles'.
     80  */
     81 
     82 #include <sys/cdefs.h>
     83 __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.4 2003/05/29 20:22:32 fvdl Exp $");
     84 
     85 #include <sys/types.h>
     86 #include <sys/param.h>
     87 #include <sys/time.h>
     88 #include <sys/systm.h>
     89 #include <sys/errno.h>
     90 #include <sys/device.h>
     91 #include <sys/lock.h>
     92 
     93 #include <uvm/uvm_extern.h>
     94 
     95 #define _X86_BUS_DMA_PRIVATE
     96 #include <machine/bus.h>
     97 
     98 #include <machine/pio.h>
     99 #include <machine/intr.h>
    100 
    101 #include <dev/isa/isareg.h>
    102 #include <dev/isa/isavar.h>
    103 #include <dev/pci/pcivar.h>
    104 #include <dev/pci/pcireg.h>
    105 #include <dev/pci/pcidevs.h>
    106 
    107 #include "ioapic.h"
    108 #include "eisa.h"
    109 #include "opt_mpbios.h"
    110 #include "opt_mpacpi.h"
    111 
    112 #if NIOAPIC > 0
    113 #include <machine/i82093var.h>
    114 #include <machine/mpbiosvar.h>
    115 #endif
    116 
    117 #ifdef MPBIOS
    118 #include <machine/mpbiosvar.h>
    119 #endif
    120 
    121 #ifdef MPACPI
    122 #include <machine/mpacpi.h>
    123 #endif
    124 
    125 #include "opt_pci_conf_mode.h"
    126 
    127 int pci_mode = -1;
    128 
    129 struct simplelock pci_conf_slock = SIMPLELOCK_INITIALIZER;
    130 
    131 #define	PCI_CONF_LOCK(s)						\
    132 do {									\
    133 	(s) = splhigh();						\
    134 	simple_lock(&pci_conf_slock);					\
    135 } while (0)
    136 
    137 #define	PCI_CONF_UNLOCK(s)						\
    138 do {									\
    139 	simple_unlock(&pci_conf_slock);					\
    140 	splx((s));							\
    141 } while (0)
    142 
    143 #define	PCI_MODE1_ENABLE	0x80000000UL
    144 #define	PCI_MODE1_ADDRESS_REG	0x0cf8
    145 #define	PCI_MODE1_DATA_REG	0x0cfc
    146 
    147 #define	PCI_MODE2_ENABLE_REG	0x0cf8
    148 #define	PCI_MODE2_FORWARD_REG	0x0cfa
    149 
    150 #define _m1tag(b, d, f) \
    151 	(PCI_MODE1_ENABLE | ((b) << 16) | ((d) << 11) | ((f) << 8))
    152 #define _qe(bus, dev, fcn, vend, prod) \
    153 	{_m1tag(bus, dev, fcn), PCI_ID_CODE(vend, prod)}
    154 struct {
    155 	u_int32_t tag;
    156 	pcireg_t id;
    157 } pcim1_quirk_tbl[] = {
    158 	_qe(0, 0, 0, PCI_VENDOR_COMPAQ, PCI_PRODUCT_COMPAQ_TRIFLEX1),
    159 	/* XXX Triflex2 not tested */
    160 	_qe(0, 0, 0, PCI_VENDOR_COMPAQ, PCI_PRODUCT_COMPAQ_TRIFLEX2),
    161 	_qe(0, 0, 0, PCI_VENDOR_COMPAQ, PCI_PRODUCT_COMPAQ_TRIFLEX4),
    162 	/* Triton needed for Connectix Virtual PC */
    163 	_qe(0, 0, 0, PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82437FX),
    164 	/* Connectix Virtual PC 5 has a 440BX */
    165 	_qe(0, 0, 0, PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82443BX_NOAGP),
    166 	{0, 0xffffffff} /* patchable */
    167 };
    168 #undef _m1tag
    169 #undef _id
    170 #undef _qe
    171 
    172 /*
    173  * PCI doesn't have any special needs; just use the generic versions
    174  * of these functions.
    175  */
    176 struct x86_bus_dma_tag pci_bus_dma_tag = {
    177 #if defined(_LP64) || defined(PAE)
    178 	PCI32_DMA_BOUNCE_THRESHOLD,	/* bounce_thresh */
    179 	ISA_DMA_BOUNCE_THRESHOLD,	/* bounce_alloclo */
    180 	PCI32_DMA_BOUNCE_THRESHOLD,	/* bounce_allochi */
    181 #else
    182 	0,
    183 	0,
    184 	0,
    185 #endif
    186 	NULL,			/* _may_bounce */
    187 	_bus_dmamap_create,
    188 	_bus_dmamap_destroy,
    189 	_bus_dmamap_load,
    190 	_bus_dmamap_load_mbuf,
    191 	_bus_dmamap_load_uio,
    192 	_bus_dmamap_load_raw,
    193 	_bus_dmamap_unload,
    194 #if defined(_LP64) || defined(PAE)
    195 	_bus_dmamap_sync,
    196 #else
    197 	NULL,
    198 #endif
    199 	_bus_dmamem_alloc,
    200 	_bus_dmamem_free,
    201 	_bus_dmamem_map,
    202 	_bus_dmamem_unmap,
    203 	_bus_dmamem_mmap,
    204 };
    205 
    206 void
    207 pci_attach_hook(parent, self, pba)
    208 	struct device *parent, *self;
    209 	struct pcibus_attach_args *pba;
    210 {
    211 
    212 	if (pba->pba_bus == 0)
    213 		printf(": configuration mode %d", pci_mode);
    214 #ifdef MPBIOS
    215 	mpbios_pci_attach_hook(parent, self, pba);
    216 #endif
    217 #ifdef MPACPI
    218 	mpacpi_pci_attach_hook(parent, self, pba);
    219 #endif
    220 }
    221 
    222 int
    223 pci_bus_maxdevs(pc, busno)
    224 	pci_chipset_tag_t pc;
    225 	int busno;
    226 {
    227 
    228 	/*
    229 	 * Bus number is irrelevant.  If Configuration Mechanism 2 is in
    230 	 * use, can only have devices 0-15 on any bus.  If Configuration
    231 	 * Mechanism 1 is in use, can have devices 0-32 (i.e. the `normal'
    232 	 * range).
    233 	 */
    234 	if (pci_mode == 2)
    235 		return (16);
    236 	else
    237 		return (32);
    238 }
    239 
    240 pcitag_t
    241 pci_make_tag(pc, bus, device, function)
    242 	pci_chipset_tag_t pc;
    243 	int bus, device, function;
    244 {
    245 	pcitag_t tag;
    246 
    247 #ifndef PCI_CONF_MODE
    248 	switch (pci_mode) {
    249 	case 1:
    250 		goto mode1;
    251 	case 2:
    252 		goto mode2;
    253 	default:
    254 		panic("pci_make_tag: mode not configured");
    255 	}
    256 #endif
    257 
    258 #if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 1)
    259 #ifndef PCI_CONF_MODE
    260 mode1:
    261 #endif
    262 	if (bus >= 256 || device >= 32 || function >= 8)
    263 		panic("pci_make_tag: bad request");
    264 
    265 	tag.mode1 = PCI_MODE1_ENABLE |
    266 		    (bus << 16) | (device << 11) | (function << 8);
    267 	return tag;
    268 #endif
    269 
    270 #if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 2)
    271 #ifndef PCI_CONF_MODE
    272 mode2:
    273 #endif
    274 	if (bus >= 256 || device >= 16 || function >= 8)
    275 		panic("pci_make_tag: bad request");
    276 
    277 	tag.mode2.port = 0xc000 | (device << 8);
    278 	tag.mode2.enable = 0xf0 | (function << 1);
    279 	tag.mode2.forward = bus;
    280 	return tag;
    281 #endif
    282 }
    283 
    284 void
    285 pci_decompose_tag(pc, tag, bp, dp, fp)
    286 	pci_chipset_tag_t pc;
    287 	pcitag_t tag;
    288 	int *bp, *dp, *fp;
    289 {
    290 
    291 #ifndef PCI_CONF_MODE
    292 	switch (pci_mode) {
    293 	case 1:
    294 		goto mode1;
    295 	case 2:
    296 		goto mode2;
    297 	default:
    298 		panic("pci_decompose_tag: mode not configured");
    299 	}
    300 #endif
    301 
    302 #if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 1)
    303 #ifndef PCI_CONF_MODE
    304 mode1:
    305 #endif
    306 	if (bp != NULL)
    307 		*bp = (tag.mode1 >> 16) & 0xff;
    308 	if (dp != NULL)
    309 		*dp = (tag.mode1 >> 11) & 0x1f;
    310 	if (fp != NULL)
    311 		*fp = (tag.mode1 >> 8) & 0x7;
    312 	return;
    313 #endif
    314 
    315 #if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 2)
    316 #ifndef PCI_CONF_MODE
    317 mode2:
    318 #endif
    319 	if (bp != NULL)
    320 		*bp = tag.mode2.forward & 0xff;
    321 	if (dp != NULL)
    322 		*dp = (tag.mode2.port >> 8) & 0xf;
    323 	if (fp != NULL)
    324 		*fp = (tag.mode2.enable >> 1) & 0x7;
    325 #endif
    326 }
    327 
    328 pcireg_t
    329 pci_conf_read(pc, tag, reg)
    330 	pci_chipset_tag_t pc;
    331 	pcitag_t tag;
    332 	int reg;
    333 {
    334 	pcireg_t data;
    335 	int s;
    336 
    337 #ifndef PCI_CONF_MODE
    338 	switch (pci_mode) {
    339 	case 1:
    340 		goto mode1;
    341 	case 2:
    342 		goto mode2;
    343 	default:
    344 		panic("pci_conf_read: mode not configured");
    345 	}
    346 #endif
    347 
    348 #if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 1)
    349 #ifndef PCI_CONF_MODE
    350 mode1:
    351 #endif
    352 	PCI_CONF_LOCK(s);
    353 	outl(PCI_MODE1_ADDRESS_REG, tag.mode1 | reg);
    354 	data = inl(PCI_MODE1_DATA_REG);
    355 	outl(PCI_MODE1_ADDRESS_REG, 0);
    356 	PCI_CONF_UNLOCK(s);
    357 	return data;
    358 #endif
    359 
    360 #if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 2)
    361 #ifndef PCI_CONF_MODE
    362 mode2:
    363 #endif
    364 	PCI_CONF_LOCK(s);
    365 	outb(PCI_MODE2_ENABLE_REG, tag.mode2.enable);
    366 	outb(PCI_MODE2_FORWARD_REG, tag.mode2.forward);
    367 	data = inl(tag.mode2.port | reg);
    368 	outb(PCI_MODE2_ENABLE_REG, 0);
    369 	PCI_CONF_UNLOCK(s);
    370 	return data;
    371 #endif
    372 }
    373 
    374 void
    375 pci_conf_write(pc, tag, reg, data)
    376 	pci_chipset_tag_t pc;
    377 	pcitag_t tag;
    378 	int reg;
    379 	pcireg_t data;
    380 {
    381 	int s;
    382 
    383 #ifndef PCI_CONF_MODE
    384 	switch (pci_mode) {
    385 	case 1:
    386 		goto mode1;
    387 	case 2:
    388 		goto mode2;
    389 	default:
    390 		panic("pci_conf_write: mode not configured");
    391 	}
    392 #endif
    393 
    394 #if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 1)
    395 #ifndef PCI_CONF_MODE
    396 mode1:
    397 #endif
    398 	PCI_CONF_LOCK(s);
    399 	outl(PCI_MODE1_ADDRESS_REG, tag.mode1 | reg);
    400 	outl(PCI_MODE1_DATA_REG, data);
    401 	outl(PCI_MODE1_ADDRESS_REG, 0);
    402 	PCI_CONF_UNLOCK(s);
    403 	return;
    404 #endif
    405 
    406 #if !defined(PCI_CONF_MODE) || (PCI_CONF_MODE == 2)
    407 #ifndef PCI_CONF_MODE
    408 mode2:
    409 #endif
    410 	PCI_CONF_LOCK(s);
    411 	outb(PCI_MODE2_ENABLE_REG, tag.mode2.enable);
    412 	outb(PCI_MODE2_FORWARD_REG, tag.mode2.forward);
    413 	outl(tag.mode2.port | reg, data);
    414 	outb(PCI_MODE2_ENABLE_REG, 0);
    415 	PCI_CONF_UNLOCK(s);
    416 #endif
    417 }
    418 
    419 int
    420 pci_mode_detect()
    421 {
    422 
    423 #ifdef PCI_CONF_MODE
    424 #if (PCI_CONF_MODE == 1) || (PCI_CONF_MODE == 2)
    425 	return (pci_mode = PCI_CONF_MODE);
    426 #else
    427 #error Invalid PCI configuration mode.
    428 #endif
    429 #else
    430 	u_int32_t sav, val;
    431 	int i;
    432 	pcireg_t idreg;
    433 
    434 	if (pci_mode != -1)
    435 		return pci_mode;
    436 
    437 	/*
    438 	 * We try to divine which configuration mode the host bridge wants.
    439 	 */
    440 
    441 	sav = inl(PCI_MODE1_ADDRESS_REG);
    442 
    443 	pci_mode = 1; /* assume this for now */
    444 	/*
    445 	 * catch some known buggy implementations of mode 1
    446 	 */
    447 	for (i = 0; i < sizeof(pcim1_quirk_tbl) / sizeof(pcim1_quirk_tbl[0]);
    448 	     i++) {
    449 		pcitag_t t;
    450 
    451 		if (!pcim1_quirk_tbl[i].tag)
    452 			break;
    453 		t.mode1 = pcim1_quirk_tbl[i].tag;
    454 		idreg = pci_conf_read(0, t, PCI_ID_REG); /* needs "pci_mode" */
    455 		if (idreg == pcim1_quirk_tbl[i].id) {
    456 #ifdef DEBUG
    457 			printf("known mode 1 PCI chipset (%08x)\n",
    458 			       idreg);
    459 #endif
    460 			return (pci_mode);
    461 		}
    462 	}
    463 
    464 	/*
    465 	 * Strong check for standard compliant mode 1:
    466 	 * 1. bit 31 ("enable") can be set
    467 	 * 2. byte/word access does not affect register
    468 	 */
    469 	outl(PCI_MODE1_ADDRESS_REG, PCI_MODE1_ENABLE);
    470 	outb(PCI_MODE1_ADDRESS_REG + 3, 0);
    471 	outw(PCI_MODE1_ADDRESS_REG + 2, 0);
    472 	val = inl(PCI_MODE1_ADDRESS_REG);
    473 	if ((val & 0x80fffffc) != PCI_MODE1_ENABLE) {
    474 #ifdef DEBUG
    475 		printf("pci_mode_detect: mode 1 enable failed (%x)\n",
    476 		       val);
    477 #endif
    478 		goto not1;
    479 	}
    480 	outl(PCI_MODE1_ADDRESS_REG, 0);
    481 	val = inl(PCI_MODE1_ADDRESS_REG);
    482 	if ((val & 0x80fffffc) != 0)
    483 		goto not1;
    484 	return (pci_mode);
    485 not1:
    486 	outl(PCI_MODE1_ADDRESS_REG, sav);
    487 
    488 	/*
    489 	 * This mode 2 check is quite weak (and known to give false
    490 	 * positives on some Compaq machines).
    491 	 * However, this doesn't matter, because this is the
    492 	 * last test, and simply no PCI devices will be found if
    493 	 * this happens.
    494 	 */
    495 	outb(PCI_MODE2_ENABLE_REG, 0);
    496 	outb(PCI_MODE2_FORWARD_REG, 0);
    497 	if (inb(PCI_MODE2_ENABLE_REG) != 0 ||
    498 	    inb(PCI_MODE2_FORWARD_REG) != 0)
    499 		goto not2;
    500 	return (pci_mode = 2);
    501 not2:
    502 
    503 	return (pci_mode = 0);
    504 #endif
    505 }
    506 
    507 int
    508 pci_intr_map(pa, ihp)
    509 	struct pci_attach_args *pa;
    510 	pci_intr_handle_t *ihp;
    511 {
    512 	int pin = pa->pa_intrpin;
    513 	int line = pa->pa_intrline;
    514 #if NIOAPIC > 0
    515 	int rawpin = pa->pa_rawintrpin;
    516 	pci_chipset_tag_t pc = pa->pa_pc;
    517 	int bus, dev, func;
    518 #endif
    519 
    520 	if (pin == 0) {
    521 		/* No IRQ used. */
    522 		goto bad;
    523 	}
    524 
    525 	if (pin > PCI_INTERRUPT_PIN_MAX) {
    526 		printf("pci_intr_map: bad interrupt pin %d\n", pin);
    527 		goto bad;
    528 	}
    529 
    530 #if NIOAPIC > 0
    531 	pci_decompose_tag(pc, pa->pa_tag, &bus, &dev, &func);
    532 	if (mp_busses != NULL) {
    533 		if (intr_find_mpmapping(bus, (dev<<2)|(rawpin-1), ihp) == 0) {
    534 			*ihp |= line;
    535 			return 0;
    536 		}
    537 		/*
    538 		 * No explicit PCI mapping found. This is not fatal,
    539 		 * we'll try the ISA (or possibly EISA) mappings next.
    540 		 */
    541 	}
    542 #endif
    543 
    544 	/*
    545 	 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
    546 	 * `unknown' or `no connection' on a PC.  We assume that a device with
    547 	 * `no connection' either doesn't have an interrupt (in which case the
    548 	 * pin number should be 0, and would have been noticed above), or
    549 	 * wasn't configured by the BIOS (in which case we punt, since there's
    550 	 * no real way we can know how the interrupt lines are mapped in the
    551 	 * hardware).
    552 	 *
    553 	 * XXX
    554 	 * Since IRQ 0 is only used by the clock, and we can't actually be sure
    555 	 * that the BIOS did its job, we also recognize that as meaning that
    556 	 * the BIOS has not configured the device.
    557 	 */
    558 	if (line == 0 || line == X86_PCI_INTERRUPT_LINE_NO_CONNECTION) {
    559 		printf("pci_intr_map: no mapping for pin %c (line=%02x)\n",
    560 		       '@' + pin, line);
    561 		goto bad;
    562 	} else {
    563 		if (line >= NUM_LEGACY_IRQS) {
    564 			printf("pci_intr_map: bad interrupt line %d\n", line);
    565 			goto bad;
    566 		}
    567 		if (line == 2) {
    568 			printf("pci_intr_map: changed line 2 to line 9\n");
    569 			line = 9;
    570 		}
    571 	}
    572 #if NIOAPIC > 0
    573 	if (mp_busses != NULL) {
    574 		if (intr_find_mpmapping(mp_isa_bus, line, ihp) == 0) {
    575 			*ihp |= line;
    576 			return 0;
    577 		}
    578 #if NEISA > 0
    579 		if (intr_find_mpmapping(mp_eisa_bus, line, ihp) == 0) {
    580 			*ihp |= line;
    581 			return 0;
    582 		}
    583 #endif
    584 		printf("pci_intr_map: bus %d dev %d func %d pin %d; line %d\n",
    585 		    bus, dev, func, pin, line);
    586 		printf("pci_intr_map: no MP mapping found\n");
    587 	}
    588 #endif
    589 
    590 	*ihp = line;
    591 	return 0;
    592 
    593 bad:
    594 	*ihp = -1;
    595 	return 1;
    596 }
    597 
    598 const char *
    599 pci_intr_string(pc, ih)
    600 	pci_chipset_tag_t pc;
    601 	pci_intr_handle_t ih;
    602 {
    603 	static char irqstr[64];
    604 
    605 	if (ih == 0)
    606 		panic("pci_intr_string: bogus handle 0x%x", ih);
    607 
    608 
    609 #if NIOAPIC > 0
    610 	if (ih & APIC_INT_VIA_APIC)
    611 		sprintf(irqstr, "apic %d int %d (irq %d)",
    612 		    APIC_IRQ_APIC(ih),
    613 		    APIC_IRQ_PIN(ih),
    614 		    ih&0xff);
    615 	else
    616 		sprintf(irqstr, "irq %d", ih&0xff);
    617 #else
    618 
    619 	sprintf(irqstr, "irq %d", ih&0xff);
    620 #endif
    621 	return (irqstr);
    622 
    623 }
    624 
    625 const struct evcnt *
    626 pci_intr_evcnt(pc, ih)
    627 	pci_chipset_tag_t pc;
    628 	pci_intr_handle_t ih;
    629 {
    630 
    631 	/* XXX for now, no evcnt parent reported */
    632 	return NULL;
    633 }
    634 
    635 void *
    636 pci_intr_establish(pc, ih, level, func, arg)
    637 	pci_chipset_tag_t pc;
    638 	pci_intr_handle_t ih;
    639 	int level, (*func) __P((void *));
    640 	void *arg;
    641 {
    642 	int pin, irq;
    643 	struct pic *pic;
    644 
    645 	pic = &i8259_pic;
    646 	pin = irq = ih;
    647 
    648 #if NIOAPIC > 0
    649 	if (ih & APIC_INT_VIA_APIC) {
    650 		pic = (struct pic *)ioapic_find(APIC_IRQ_APIC(ih));
    651 		if (pic == NULL) {
    652 			printf("pci_intr_establish: bad ioapic %d\n",
    653 			    APIC_IRQ_APIC(ih));
    654 			return NULL;
    655 		}
    656 		pin = APIC_IRQ_PIN(ih);
    657 		irq = APIC_IRQ_LEGACY_IRQ(ih);
    658 		if (irq < 0 || irq >= NUM_LEGACY_IRQS)
    659 			irq = -1;
    660 	}
    661 #endif
    662 
    663 	return intr_establish(irq, pic, pin, IST_LEVEL, level, func, arg);
    664 }
    665 
    666 void
    667 pci_intr_disestablish(pc, cookie)
    668 	pci_chipset_tag_t pc;
    669 	void *cookie;
    670 {
    671 
    672 	intr_disestablish(cookie);
    673 }
    674 
    675 /*
    676  * Determine which flags should be passed to the primary PCI bus's
    677  * autoconfiguration node.  We use this to detect broken chipsets
    678  * which cannot safely use memory-mapped device access.
    679  */
    680 int
    681 pci_bus_flags()
    682 {
    683 	int rval = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
    684 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    685 	int device, maxndevs;
    686 	pcitag_t tag;
    687 	pcireg_t id;
    688 
    689 	maxndevs = pci_bus_maxdevs(NULL, 0);
    690 
    691 	for (device = 0; device < maxndevs; device++) {
    692 		tag = pci_make_tag(NULL, 0, device, 0);
    693 		id = pci_conf_read(NULL, tag, PCI_ID_REG);
    694 
    695 		/* Invalid vendor ID value? */
    696 		if (PCI_VENDOR(id) == PCI_VENDOR_INVALID)
    697 			continue;
    698 		/* XXX Not invalid, but we've done this ~forever. */
    699 		if (PCI_VENDOR(id) == 0)
    700 			continue;
    701 
    702 		switch (PCI_VENDOR(id)) {
    703 		case PCI_VENDOR_SIS:
    704 			switch (PCI_PRODUCT(id)) {
    705 			case PCI_PRODUCT_SIS_85C496:
    706 				goto disable_mem;
    707 			}
    708 			break;
    709 		}
    710 	}
    711 
    712 	return (rval);
    713 
    714  disable_mem:
    715 	printf("Warning: broken PCI-Host bridge detected; "
    716 	    "disabling memory-mapped access\n");
    717 	rval &= ~(PCI_FLAGS_MEM_ENABLED|PCI_FLAGS_MRL_OKAY|PCI_FLAGS_MRM_OKAY|
    718 	    PCI_FLAGS_MWI_OKAY);
    719 	return (rval);
    720 }
    721