Home | History | Annotate | Line # | Download | only in pci
pci_intr_machdep.c revision 1.4
      1 /*	$NetBSD: pci_intr_machdep.c,v 1.4 2006/07/04 18:46:42 christos 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_intr_machdep.c,v 1.4 2006/07/04 18:46:42 christos 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 #include <machine/intr.h>
     96 
     97 #include <dev/pci/pcivar.h>
     98 
     99 #include "ioapic.h"
    100 #include "eisa.h"
    101 #include "acpi.h"
    102 #include "opt_mpbios.h"
    103 #include "opt_acpi.h"
    104 
    105 #if NIOAPIC > 0 || NACPI > 0
    106 #include <machine/i82093var.h>
    107 #include <machine/mpconfig.h>
    108 #include <machine/mpbiosvar.h>
    109 #include <machine/pic.h>
    110 #endif
    111 
    112 #ifdef MPBIOS
    113 #include <machine/mpbiosvar.h>
    114 #endif
    115 
    116 #if NACPI > 0
    117 #include <machine/mpacpi.h>
    118 #endif
    119 
    120 int
    121 pci_intr_map(pa, ihp)
    122 	struct pci_attach_args *pa;
    123 	pci_intr_handle_t *ihp;
    124 {
    125 	int pin = pa->pa_intrpin;
    126 	int line = pa->pa_intrline;
    127 #if NIOAPIC > 0 || NACPI > 0
    128 	int rawpin = pa->pa_rawintrpin;
    129 	pci_chipset_tag_t pc = pa->pa_pc;
    130 	int bus, dev, func;
    131 #endif
    132 
    133 	if (pin == 0) {
    134 		/* No IRQ used. */
    135 		goto bad;
    136 	}
    137 
    138 	*ihp = 0;
    139 
    140 	if (pin > PCI_INTERRUPT_PIN_MAX) {
    141 		printf("pci_intr_map: bad interrupt pin %d\n", pin);
    142 		goto bad;
    143 	}
    144 
    145 #if NIOAPIC > 0 || NACPI > 0
    146 	pci_decompose_tag(pc, pa->pa_tag, &bus, &dev, &func);
    147 	if (mp_busses != NULL) {
    148 		if (intr_find_mpmapping(bus, (dev<<2)|(rawpin-1), ihp) == 0) {
    149 			if ((*ihp & 0xff) == 0)
    150 				*ihp |= line;
    151 			return 0;
    152 		}
    153 		/*
    154 		 * No explicit PCI mapping found. This is not fatal,
    155 		 * we'll try the ISA (or possibly EISA) mappings next.
    156 		 */
    157 	}
    158 #endif
    159 
    160 	/*
    161 	 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
    162 	 * `unknown' or `no connection' on a PC.  We assume that a device with
    163 	 * `no connection' either doesn't have an interrupt (in which case the
    164 	 * pin number should be 0, and would have been noticed above), or
    165 	 * wasn't configured by the BIOS (in which case we punt, since there's
    166 	 * no real way we can know how the interrupt lines are mapped in the
    167 	 * hardware).
    168 	 *
    169 	 * XXX
    170 	 * Since IRQ 0 is only used by the clock, and we can't actually be sure
    171 	 * that the BIOS did its job, we also recognize that as meaning that
    172 	 * the BIOS has not configured the device.
    173 	 */
    174 	if (line == 0 || line == X86_PCI_INTERRUPT_LINE_NO_CONNECTION) {
    175 		printf("pci_intr_map: no mapping for pin %c (line=%02x)\n",
    176 		       '@' + pin, line);
    177 		goto bad;
    178 	} else {
    179 		if (line >= NUM_LEGACY_IRQS) {
    180 			printf("pci_intr_map: bad interrupt line %d\n", line);
    181 			goto bad;
    182 		}
    183 		if (line == 2) {
    184 			printf("pci_intr_map: changed line 2 to line 9\n");
    185 			line = 9;
    186 		}
    187 	}
    188 #if NIOAPIC > 0 || NACPI > 0
    189 	if (mp_busses != NULL) {
    190 		if (intr_find_mpmapping(mp_isa_bus, line, ihp) == 0) {
    191 			if ((*ihp & 0xff) == 0)
    192 				*ihp |= line;
    193 			return 0;
    194 		}
    195 #if NEISA > 0
    196 		if (intr_find_mpmapping(mp_eisa_bus, line, ihp) == 0) {
    197 			if ((*ihp & 0xff) == 0)
    198 				*ihp |= line;
    199 			return 0;
    200 		}
    201 #endif
    202 		printf("pci_intr_map: bus %d dev %d func %d pin %d; line %d\n",
    203 		    bus, dev, func, pin, line);
    204 		printf("pci_intr_map: no MP mapping found\n");
    205 	}
    206 #endif
    207 
    208 	*ihp = line;
    209 	return 0;
    210 
    211 bad:
    212 	*ihp = -1;
    213 	return 1;
    214 }
    215 
    216 const char *
    217 pci_intr_string(pc, ih)
    218 	pci_chipset_tag_t pc;
    219 	pci_intr_handle_t ih;
    220 {
    221 	return intr_string(ih);
    222 }
    223 
    224 
    225 const struct evcnt *
    226 pci_intr_evcnt(pc, ih)
    227 	pci_chipset_tag_t pc;
    228 	pci_intr_handle_t ih;
    229 {
    230 
    231 	/* XXX for now, no evcnt parent reported */
    232 	return NULL;
    233 }
    234 
    235 void *
    236 pci_intr_establish(pc, ih, level, func, arg)
    237 	pci_chipset_tag_t pc;
    238 	pci_intr_handle_t ih;
    239 	int level, (*func) __P((void *));
    240 	void *arg;
    241 {
    242 	int pin, irq;
    243 	struct pic *pic;
    244 
    245 	pic = &i8259_pic;
    246 	pin = irq = ih;
    247 
    248 #if NIOAPIC > 0
    249 	if (ih & APIC_INT_VIA_APIC) {
    250 		pic = (struct pic *)ioapic_find(APIC_IRQ_APIC(ih));
    251 		if (pic == NULL) {
    252 			printf("pci_intr_establish: bad ioapic %d\n",
    253 			    APIC_IRQ_APIC(ih));
    254 			return NULL;
    255 		}
    256 		pin = APIC_IRQ_PIN(ih);
    257 		irq = APIC_IRQ_LEGACY_IRQ(ih);
    258 		if (irq < 0 || irq >= NUM_LEGACY_IRQS)
    259 			irq = -1;
    260 	}
    261 #endif
    262 
    263 	return intr_establish(irq, pic, pin, IST_LEVEL, level, func, arg);
    264 }
    265 
    266 void
    267 pci_intr_disestablish(pc, cookie)
    268 	pci_chipset_tag_t pc;
    269 	void *cookie;
    270 {
    271 
    272 	intr_disestablish(cookie);
    273 }
    274