Home | History | Annotate | Line # | Download | only in pci
pci_intr_machdep.c revision 1.4
      1  1.4  christos /*	$NetBSD: pci_intr_machdep.c,v 1.4 2006/07/04 18:46:42 christos Exp $	*/
      2  1.1    bouyer 
      3  1.1    bouyer /*-
      4  1.1    bouyer  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5  1.1    bouyer  * All rights reserved.
      6  1.1    bouyer  *
      7  1.1    bouyer  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1    bouyer  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.1    bouyer  * NASA Ames Research Center.
     10  1.1    bouyer  *
     11  1.1    bouyer  * Redistribution and use in source and binary forms, with or without
     12  1.1    bouyer  * modification, are permitted provided that the following conditions
     13  1.1    bouyer  * are met:
     14  1.1    bouyer  * 1. Redistributions of source code must retain the above copyright
     15  1.1    bouyer  *    notice, this list of conditions and the following disclaimer.
     16  1.1    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1    bouyer  *    notice, this list of conditions and the following disclaimer in the
     18  1.1    bouyer  *    documentation and/or other materials provided with the distribution.
     19  1.1    bouyer  * 3. All advertising materials mentioning features or use of this software
     20  1.1    bouyer  *    must display the following acknowledgement:
     21  1.1    bouyer  *	This product includes software developed by the NetBSD
     22  1.1    bouyer  *	Foundation, Inc. and its contributors.
     23  1.1    bouyer  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1    bouyer  *    contributors may be used to endorse or promote products derived
     25  1.1    bouyer  *    from this software without specific prior written permission.
     26  1.1    bouyer  *
     27  1.1    bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1    bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1    bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1    bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1    bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1    bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1    bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1    bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1    bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1    bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1    bouyer  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1    bouyer  */
     39  1.1    bouyer 
     40  1.1    bouyer /*
     41  1.1    bouyer  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
     42  1.1    bouyer  * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
     43  1.1    bouyer  *
     44  1.1    bouyer  * Redistribution and use in source and binary forms, with or without
     45  1.1    bouyer  * modification, are permitted provided that the following conditions
     46  1.1    bouyer  * are met:
     47  1.1    bouyer  * 1. Redistributions of source code must retain the above copyright
     48  1.1    bouyer  *    notice, this list of conditions and the following disclaimer.
     49  1.1    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     50  1.1    bouyer  *    notice, this list of conditions and the following disclaimer in the
     51  1.1    bouyer  *    documentation and/or other materials provided with the distribution.
     52  1.1    bouyer  * 3. All advertising materials mentioning features or use of this software
     53  1.1    bouyer  *    must display the following acknowledgement:
     54  1.1    bouyer  *	This product includes software developed by Charles M. Hannum.
     55  1.1    bouyer  * 4. The name of the author may not be used to endorse or promote products
     56  1.1    bouyer  *    derived from this software without specific prior written permission.
     57  1.1    bouyer  *
     58  1.1    bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     59  1.1    bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60  1.1    bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61  1.1    bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     62  1.1    bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     63  1.1    bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     64  1.1    bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     65  1.1    bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     66  1.1    bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     67  1.1    bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68  1.1    bouyer  */
     69  1.1    bouyer 
     70  1.1    bouyer /*
     71  1.1    bouyer  * Machine-specific functions for PCI autoconfiguration.
     72  1.1    bouyer  *
     73  1.1    bouyer  * On PCs, there are two methods of generating PCI configuration cycles.
     74  1.1    bouyer  * We try to detect the appropriate mechanism for this machine and set
     75  1.1    bouyer  * up a few function pointers to access the correct method directly.
     76  1.1    bouyer  *
     77  1.1    bouyer  * The configuration method can be hard-coded in the config file by
     78  1.1    bouyer  * using `options PCI_CONF_MODE=N', where `N' is the configuration mode
     79  1.1    bouyer  * as defined section 3.6.4.1, `Generating Configuration Cycles'.
     80  1.1    bouyer  */
     81  1.1    bouyer 
     82  1.1    bouyer #include <sys/cdefs.h>
     83  1.4  christos __KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.4 2006/07/04 18:46:42 christos Exp $");
     84  1.1    bouyer 
     85  1.1    bouyer #include <sys/types.h>
     86  1.1    bouyer #include <sys/param.h>
     87  1.1    bouyer #include <sys/time.h>
     88  1.1    bouyer #include <sys/systm.h>
     89  1.1    bouyer #include <sys/errno.h>
     90  1.1    bouyer #include <sys/device.h>
     91  1.1    bouyer #include <sys/lock.h>
     92  1.1    bouyer 
     93  1.1    bouyer #include <uvm/uvm_extern.h>
     94  1.1    bouyer 
     95  1.1    bouyer #include <machine/intr.h>
     96  1.1    bouyer 
     97  1.1    bouyer #include <dev/pci/pcivar.h>
     98  1.1    bouyer 
     99  1.1    bouyer #include "ioapic.h"
    100  1.1    bouyer #include "eisa.h"
    101  1.2  christos #include "acpi.h"
    102  1.1    bouyer #include "opt_mpbios.h"
    103  1.2  christos #include "opt_acpi.h"
    104  1.1    bouyer 
    105  1.4  christos #if NIOAPIC > 0 || NACPI > 0
    106  1.1    bouyer #include <machine/i82093var.h>
    107  1.2  christos #include <machine/mpconfig.h>
    108  1.1    bouyer #include <machine/mpbiosvar.h>
    109  1.1    bouyer #include <machine/pic.h>
    110  1.1    bouyer #endif
    111  1.1    bouyer 
    112  1.1    bouyer #ifdef MPBIOS
    113  1.1    bouyer #include <machine/mpbiosvar.h>
    114  1.1    bouyer #endif
    115  1.1    bouyer 
    116  1.2  christos #if NACPI > 0
    117  1.1    bouyer #include <machine/mpacpi.h>
    118  1.1    bouyer #endif
    119  1.1    bouyer 
    120  1.1    bouyer int
    121  1.1    bouyer pci_intr_map(pa, ihp)
    122  1.1    bouyer 	struct pci_attach_args *pa;
    123  1.1    bouyer 	pci_intr_handle_t *ihp;
    124  1.1    bouyer {
    125  1.1    bouyer 	int pin = pa->pa_intrpin;
    126  1.1    bouyer 	int line = pa->pa_intrline;
    127  1.3  christos #if NIOAPIC > 0 || NACPI > 0
    128  1.1    bouyer 	int rawpin = pa->pa_rawintrpin;
    129  1.1    bouyer 	pci_chipset_tag_t pc = pa->pa_pc;
    130  1.1    bouyer 	int bus, dev, func;
    131  1.1    bouyer #endif
    132  1.1    bouyer 
    133  1.1    bouyer 	if (pin == 0) {
    134  1.1    bouyer 		/* No IRQ used. */
    135  1.1    bouyer 		goto bad;
    136  1.1    bouyer 	}
    137  1.1    bouyer 
    138  1.2  christos 	*ihp = 0;
    139  1.2  christos 
    140  1.1    bouyer 	if (pin > PCI_INTERRUPT_PIN_MAX) {
    141  1.1    bouyer 		printf("pci_intr_map: bad interrupt pin %d\n", pin);
    142  1.1    bouyer 		goto bad;
    143  1.1    bouyer 	}
    144  1.1    bouyer 
    145  1.4  christos #if NIOAPIC > 0 || NACPI > 0
    146  1.1    bouyer 	pci_decompose_tag(pc, pa->pa_tag, &bus, &dev, &func);
    147  1.1    bouyer 	if (mp_busses != NULL) {
    148  1.1    bouyer 		if (intr_find_mpmapping(bus, (dev<<2)|(rawpin-1), ihp) == 0) {
    149  1.2  christos 			if ((*ihp & 0xff) == 0)
    150  1.2  christos 				*ihp |= line;
    151  1.1    bouyer 			return 0;
    152  1.1    bouyer 		}
    153  1.1    bouyer 		/*
    154  1.1    bouyer 		 * No explicit PCI mapping found. This is not fatal,
    155  1.1    bouyer 		 * we'll try the ISA (or possibly EISA) mappings next.
    156  1.1    bouyer 		 */
    157  1.1    bouyer 	}
    158  1.1    bouyer #endif
    159  1.1    bouyer 
    160  1.1    bouyer 	/*
    161  1.1    bouyer 	 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
    162  1.1    bouyer 	 * `unknown' or `no connection' on a PC.  We assume that a device with
    163  1.1    bouyer 	 * `no connection' either doesn't have an interrupt (in which case the
    164  1.1    bouyer 	 * pin number should be 0, and would have been noticed above), or
    165  1.1    bouyer 	 * wasn't configured by the BIOS (in which case we punt, since there's
    166  1.1    bouyer 	 * no real way we can know how the interrupt lines are mapped in the
    167  1.1    bouyer 	 * hardware).
    168  1.1    bouyer 	 *
    169  1.1    bouyer 	 * XXX
    170  1.1    bouyer 	 * Since IRQ 0 is only used by the clock, and we can't actually be sure
    171  1.1    bouyer 	 * that the BIOS did its job, we also recognize that as meaning that
    172  1.1    bouyer 	 * the BIOS has not configured the device.
    173  1.1    bouyer 	 */
    174  1.1    bouyer 	if (line == 0 || line == X86_PCI_INTERRUPT_LINE_NO_CONNECTION) {
    175  1.1    bouyer 		printf("pci_intr_map: no mapping for pin %c (line=%02x)\n",
    176  1.1    bouyer 		       '@' + pin, line);
    177  1.1    bouyer 		goto bad;
    178  1.1    bouyer 	} else {
    179  1.1    bouyer 		if (line >= NUM_LEGACY_IRQS) {
    180  1.1    bouyer 			printf("pci_intr_map: bad interrupt line %d\n", line);
    181  1.1    bouyer 			goto bad;
    182  1.1    bouyer 		}
    183  1.1    bouyer 		if (line == 2) {
    184  1.1    bouyer 			printf("pci_intr_map: changed line 2 to line 9\n");
    185  1.1    bouyer 			line = 9;
    186  1.1    bouyer 		}
    187  1.1    bouyer 	}
    188  1.4  christos #if NIOAPIC > 0 || NACPI > 0
    189  1.1    bouyer 	if (mp_busses != NULL) {
    190  1.1    bouyer 		if (intr_find_mpmapping(mp_isa_bus, line, ihp) == 0) {
    191  1.2  christos 			if ((*ihp & 0xff) == 0)
    192  1.2  christos 				*ihp |= line;
    193  1.1    bouyer 			return 0;
    194  1.1    bouyer 		}
    195  1.1    bouyer #if NEISA > 0
    196  1.1    bouyer 		if (intr_find_mpmapping(mp_eisa_bus, line, ihp) == 0) {
    197  1.2  christos 			if ((*ihp & 0xff) == 0)
    198  1.2  christos 				*ihp |= line;
    199  1.1    bouyer 			return 0;
    200  1.1    bouyer 		}
    201  1.1    bouyer #endif
    202  1.1    bouyer 		printf("pci_intr_map: bus %d dev %d func %d pin %d; line %d\n",
    203  1.1    bouyer 		    bus, dev, func, pin, line);
    204  1.1    bouyer 		printf("pci_intr_map: no MP mapping found\n");
    205  1.1    bouyer 	}
    206  1.1    bouyer #endif
    207  1.1    bouyer 
    208  1.1    bouyer 	*ihp = line;
    209  1.1    bouyer 	return 0;
    210  1.1    bouyer 
    211  1.1    bouyer bad:
    212  1.1    bouyer 	*ihp = -1;
    213  1.1    bouyer 	return 1;
    214  1.1    bouyer }
    215  1.1    bouyer 
    216  1.1    bouyer const char *
    217  1.1    bouyer pci_intr_string(pc, ih)
    218  1.1    bouyer 	pci_chipset_tag_t pc;
    219  1.1    bouyer 	pci_intr_handle_t ih;
    220  1.1    bouyer {
    221  1.1    bouyer 	return intr_string(ih);
    222  1.1    bouyer }
    223  1.1    bouyer 
    224  1.1    bouyer 
    225  1.1    bouyer const struct evcnt *
    226  1.1    bouyer pci_intr_evcnt(pc, ih)
    227  1.1    bouyer 	pci_chipset_tag_t pc;
    228  1.1    bouyer 	pci_intr_handle_t ih;
    229  1.1    bouyer {
    230  1.1    bouyer 
    231  1.1    bouyer 	/* XXX for now, no evcnt parent reported */
    232  1.1    bouyer 	return NULL;
    233  1.1    bouyer }
    234  1.1    bouyer 
    235  1.1    bouyer void *
    236  1.1    bouyer pci_intr_establish(pc, ih, level, func, arg)
    237  1.1    bouyer 	pci_chipset_tag_t pc;
    238  1.1    bouyer 	pci_intr_handle_t ih;
    239  1.1    bouyer 	int level, (*func) __P((void *));
    240  1.1    bouyer 	void *arg;
    241  1.1    bouyer {
    242  1.1    bouyer 	int pin, irq;
    243  1.1    bouyer 	struct pic *pic;
    244  1.1    bouyer 
    245  1.1    bouyer 	pic = &i8259_pic;
    246  1.1    bouyer 	pin = irq = ih;
    247  1.1    bouyer 
    248  1.1    bouyer #if NIOAPIC > 0
    249  1.1    bouyer 	if (ih & APIC_INT_VIA_APIC) {
    250  1.1    bouyer 		pic = (struct pic *)ioapic_find(APIC_IRQ_APIC(ih));
    251  1.1    bouyer 		if (pic == NULL) {
    252  1.1    bouyer 			printf("pci_intr_establish: bad ioapic %d\n",
    253  1.1    bouyer 			    APIC_IRQ_APIC(ih));
    254  1.1    bouyer 			return NULL;
    255  1.1    bouyer 		}
    256  1.1    bouyer 		pin = APIC_IRQ_PIN(ih);
    257  1.1    bouyer 		irq = APIC_IRQ_LEGACY_IRQ(ih);
    258  1.1    bouyer 		if (irq < 0 || irq >= NUM_LEGACY_IRQS)
    259  1.1    bouyer 			irq = -1;
    260  1.1    bouyer 	}
    261  1.1    bouyer #endif
    262  1.1    bouyer 
    263  1.1    bouyer 	return intr_establish(irq, pic, pin, IST_LEVEL, level, func, arg);
    264  1.1    bouyer }
    265  1.1    bouyer 
    266  1.1    bouyer void
    267  1.1    bouyer pci_intr_disestablish(pc, cookie)
    268  1.1    bouyer 	pci_chipset_tag_t pc;
    269  1.1    bouyer 	void *cookie;
    270  1.1    bouyer {
    271  1.1    bouyer 
    272  1.1    bouyer 	intr_disestablish(cookie);
    273  1.1    bouyer }
    274