Subject: split x86/pci/pci_machdep.c
To: None <port-i386@netbsd.org, port-amd64@netbsd.org>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: port-i386
Date: 01/29/2006 01:10:59
--n8g4imXOkfNTN/H1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,
would someone object if I commit the attached change ?
It splits interrupt handling from PCI configuration. Xen3 needs a special
interrupt setting, but PCI bus config and access is standard. With this
change, I can use x86/pci/pci_machdep.c without duplicate code,
I just need a xen-specific pci_intr_machdep.c

-- 
Manuel Bouyer <bouyer@antioche.eu.org>
     NetBSD: 26 ans d'experience feront toujours la difference
--

--n8g4imXOkfNTN/H1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff

Index: conf/files.x86
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/conf/files.x86,v
retrieving revision 1.15
diff -u -r1.15 files.x86
--- conf/files.x86	30 Dec 2005 13:37:57 -0000	1.15
+++ conf/files.x86	29 Jan 2006 00:07:17 -0000
@@ -43,6 +43,7 @@
 file    arch/x86/x86/acpi_machdep.c	acpi
 
 file	arch/x86/pci/pci_machdep.c	pci
+file	arch/x86/pci/pci_intr_machdep.c	pci
 
 file	arch/x86/isa/isa_machdep.c	isa
 
Index: pci/pci_intr_machdep.c
===================================================================
RCS file: pci/pci_intr_machdep.c
diff -N pci/pci_intr_machdep.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ pci/pci_intr_machdep.c	29 Jan 2006 00:07:17 -0000
@@ -0,0 +1,266 @@
+/*	$NetBSD: pci_machdep.c,v 1.12 2005/11/16 16:08:36 christos Exp $	*/
+
+/*-
+ * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the NetBSD
+ *	Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
+ * Copyright (c) 1994 Charles M. Hannum.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by Charles M. Hannum.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Machine-specific functions for PCI autoconfiguration.
+ *
+ * On PCs, there are two methods of generating PCI configuration cycles.
+ * We try to detect the appropriate mechanism for this machine and set
+ * up a few function pointers to access the correct method directly.
+ *
+ * The configuration method can be hard-coded in the config file by
+ * using `options PCI_CONF_MODE=N', where `N' is the configuration mode
+ * as defined section 3.6.4.1, `Generating Configuration Cycles'.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.12 2005/11/16 16:08:36 christos Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/systm.h>
+#include <sys/errno.h>
+#include <sys/device.h>
+#include <sys/lock.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/intr.h>
+
+#include <dev/pci/pcivar.h>
+
+#include "ioapic.h"
+#include "eisa.h"
+#include "opt_mpbios.h"
+#include "opt_mpacpi.h"
+
+#if NIOAPIC > 0
+#include <machine/i82093var.h>
+#include <machine/mpbiosvar.h>
+#include <machine/pic.h>
+#endif
+
+#ifdef MPBIOS
+#include <machine/mpbiosvar.h>
+#endif
+
+#ifdef MPACPI
+#include <machine/mpacpi.h>
+#endif
+
+int
+pci_intr_map(pa, ihp)
+	struct pci_attach_args *pa;
+	pci_intr_handle_t *ihp;
+{
+	int pin = pa->pa_intrpin;
+	int line = pa->pa_intrline;
+#if NIOAPIC > 0
+	int rawpin = pa->pa_rawintrpin;
+	pci_chipset_tag_t pc = pa->pa_pc;
+	int bus, dev, func;
+#endif
+
+	if (pin == 0) {
+		/* No IRQ used. */
+		goto bad;
+	}
+
+	if (pin > PCI_INTERRUPT_PIN_MAX) {
+		printf("pci_intr_map: bad interrupt pin %d\n", pin);
+		goto bad;
+	}
+
+#if NIOAPIC > 0
+	pci_decompose_tag(pc, pa->pa_tag, &bus, &dev, &func);
+	if (mp_busses != NULL) {
+		if (intr_find_mpmapping(bus, (dev<<2)|(rawpin-1), ihp) == 0) {
+			*ihp |= line;
+			return 0;
+		}
+		/*
+		 * No explicit PCI mapping found. This is not fatal,
+		 * we'll try the ISA (or possibly EISA) mappings next.
+		 */
+	}
+#endif
+
+	/*
+	 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
+	 * `unknown' or `no connection' on a PC.  We assume that a device with
+	 * `no connection' either doesn't have an interrupt (in which case the
+	 * pin number should be 0, and would have been noticed above), or
+	 * wasn't configured by the BIOS (in which case we punt, since there's
+	 * no real way we can know how the interrupt lines are mapped in the
+	 * hardware).
+	 *
+	 * XXX
+	 * Since IRQ 0 is only used by the clock, and we can't actually be sure
+	 * that the BIOS did its job, we also recognize that as meaning that
+	 * the BIOS has not configured the device.
+	 */
+	if (line == 0 || line == X86_PCI_INTERRUPT_LINE_NO_CONNECTION) {
+		printf("pci_intr_map: no mapping for pin %c (line=%02x)\n",
+		       '@' + pin, line);
+		goto bad;
+	} else {
+		if (line >= NUM_LEGACY_IRQS) {
+			printf("pci_intr_map: bad interrupt line %d\n", line);
+			goto bad;
+		}
+		if (line == 2) {
+			printf("pci_intr_map: changed line 2 to line 9\n");
+			line = 9;
+		}
+	}
+#if NIOAPIC > 0
+	if (mp_busses != NULL) {
+		if (intr_find_mpmapping(mp_isa_bus, line, ihp) == 0) {
+			*ihp |= line;
+			return 0;
+		}
+#if NEISA > 0
+		if (intr_find_mpmapping(mp_eisa_bus, line, ihp) == 0) {
+			*ihp |= line;
+			return 0;
+		}
+#endif
+		printf("pci_intr_map: bus %d dev %d func %d pin %d; line %d\n",
+		    bus, dev, func, pin, line);
+		printf("pci_intr_map: no MP mapping found\n");
+	}
+#endif
+
+	*ihp = line;
+	return 0;
+
+bad:
+	*ihp = -1;
+	return 1;
+}
+
+const char *
+pci_intr_string(pc, ih)
+	pci_chipset_tag_t pc;
+	pci_intr_handle_t ih;
+{
+	return intr_string(ih);
+}
+
+
+const struct evcnt *
+pci_intr_evcnt(pc, ih)
+	pci_chipset_tag_t pc;
+	pci_intr_handle_t ih;
+{
+
+	/* XXX for now, no evcnt parent reported */
+	return NULL;
+}
+
+void *
+pci_intr_establish(pc, ih, level, func, arg)
+	pci_chipset_tag_t pc;
+	pci_intr_handle_t ih;
+	int level, (*func) __P((void *));
+	void *arg;
+{
+	int pin, irq;
+	struct pic *pic;
+
+	pic = &i8259_pic;
+	pin = irq = ih;
+
+#if NIOAPIC > 0
+	if (ih & APIC_INT_VIA_APIC) {
+		pic = (struct pic *)ioapic_find(APIC_IRQ_APIC(ih));
+		if (pic == NULL) {
+			printf("pci_intr_establish: bad ioapic %d\n",
+			    APIC_IRQ_APIC(ih));
+			return NULL;
+		}
+		pin = APIC_IRQ_PIN(ih);
+		irq = APIC_IRQ_LEGACY_IRQ(ih);
+		if (irq < 0 || irq >= NUM_LEGACY_IRQS)
+			irq = -1;
+	}
+#endif
+
+	return intr_establish(irq, pic, pin, IST_LEVEL, level, func, arg);
+}
+
+void
+pci_intr_disestablish(pc, cookie)
+	pci_chipset_tag_t pc;
+	void *cookie;
+{
+
+	intr_disestablish(cookie);
+}
Index: pci/pci_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/pci/pci_machdep.c,v
retrieving revision 1.12
diff -u -r1.12 pci_machdep.c
--- pci/pci_machdep.c	16 Nov 2005 16:08:36 -0000	1.12
+++ pci/pci_machdep.c	29 Jan 2006 00:07:17 -0000
@@ -96,7 +96,6 @@
 #include <machine/bus_private.h>
 
 #include <machine/pio.h>
-#include <machine/intr.h>
 
 #include <dev/isa/isareg.h>
 #include <dev/isa/isavar.h>
@@ -104,25 +103,6 @@
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcidevs.h>
 
-#include "ioapic.h"
-#include "eisa.h"
-#include "opt_mpbios.h"
-#include "opt_mpacpi.h"
-
-#if NIOAPIC > 0
-#include <machine/i82093var.h>
-#include <machine/mpbiosvar.h>
-#include <machine/pic.h>
-#endif
-
-#ifdef MPBIOS
-#include <machine/mpbiosvar.h>
-#endif
-
-#ifdef MPACPI
-#include <machine/mpacpi.h>
-#endif
-
 #include "opt_pci_conf_mode.h"
 
 int pci_mode = -1;
@@ -536,156 +516,6 @@
 #endif
 }
 
-int
-pci_intr_map(pa, ihp)
-	struct pci_attach_args *pa;
-	pci_intr_handle_t *ihp;
-{
-	int pin = pa->pa_intrpin;
-	int line = pa->pa_intrline;
-#if NIOAPIC > 0
-	int rawpin = pa->pa_rawintrpin;
-	pci_chipset_tag_t pc = pa->pa_pc;
-	int bus, dev, func;
-#endif
-
-	if (pin == 0) {
-		/* No IRQ used. */
-		goto bad;
-	}
-
-	if (pin > PCI_INTERRUPT_PIN_MAX) {
-		printf("pci_intr_map: bad interrupt pin %d\n", pin);
-		goto bad;
-	}
-
-#if NIOAPIC > 0
-	pci_decompose_tag(pc, pa->pa_tag, &bus, &dev, &func);
-	if (mp_busses != NULL) {
-		if (intr_find_mpmapping(bus, (dev<<2)|(rawpin-1), ihp) == 0) {
-			*ihp |= line;
-			return 0;
-		}
-		/*
-		 * No explicit PCI mapping found. This is not fatal,
-		 * we'll try the ISA (or possibly EISA) mappings next.
-		 */
-	}
-#endif
-
-	/*
-	 * Section 6.2.4, `Miscellaneous Functions', says that 255 means
-	 * `unknown' or `no connection' on a PC.  We assume that a device with
-	 * `no connection' either doesn't have an interrupt (in which case the
-	 * pin number should be 0, and would have been noticed above), or
-	 * wasn't configured by the BIOS (in which case we punt, since there's
-	 * no real way we can know how the interrupt lines are mapped in the
-	 * hardware).
-	 *
-	 * XXX
-	 * Since IRQ 0 is only used by the clock, and we can't actually be sure
-	 * that the BIOS did its job, we also recognize that as meaning that
-	 * the BIOS has not configured the device.
-	 */
-	if (line == 0 || line == X86_PCI_INTERRUPT_LINE_NO_CONNECTION) {
-		printf("pci_intr_map: no mapping for pin %c (line=%02x)\n",
-		       '@' + pin, line);
-		goto bad;
-	} else {
-		if (line >= NUM_LEGACY_IRQS) {
-			printf("pci_intr_map: bad interrupt line %d\n", line);
-			goto bad;
-		}
-		if (line == 2) {
-			printf("pci_intr_map: changed line 2 to line 9\n");
-			line = 9;
-		}
-	}
-#if NIOAPIC > 0
-	if (mp_busses != NULL) {
-		if (intr_find_mpmapping(mp_isa_bus, line, ihp) == 0) {
-			*ihp |= line;
-			return 0;
-		}
-#if NEISA > 0
-		if (intr_find_mpmapping(mp_eisa_bus, line, ihp) == 0) {
-			*ihp |= line;
-			return 0;
-		}
-#endif
-		printf("pci_intr_map: bus %d dev %d func %d pin %d; line %d\n",
-		    bus, dev, func, pin, line);
-		printf("pci_intr_map: no MP mapping found\n");
-	}
-#endif
-
-	*ihp = line;
-	return 0;
-
-bad:
-	*ihp = -1;
-	return 1;
-}
-
-const char *
-pci_intr_string(pc, ih)
-	pci_chipset_tag_t pc;
-	pci_intr_handle_t ih;
-{
-	return intr_string(ih);
-}
-
-
-const struct evcnt *
-pci_intr_evcnt(pc, ih)
-	pci_chipset_tag_t pc;
-	pci_intr_handle_t ih;
-{
-
-	/* XXX for now, no evcnt parent reported */
-	return NULL;
-}
-
-void *
-pci_intr_establish(pc, ih, level, func, arg)
-	pci_chipset_tag_t pc;
-	pci_intr_handle_t ih;
-	int level, (*func) __P((void *));
-	void *arg;
-{
-	int pin, irq;
-	struct pic *pic;
-
-	pic = &i8259_pic;
-	pin = irq = ih;
-
-#if NIOAPIC > 0
-	if (ih & APIC_INT_VIA_APIC) {
-		pic = (struct pic *)ioapic_find(APIC_IRQ_APIC(ih));
-		if (pic == NULL) {
-			printf("pci_intr_establish: bad ioapic %d\n",
-			    APIC_IRQ_APIC(ih));
-			return NULL;
-		}
-		pin = APIC_IRQ_PIN(ih);
-		irq = APIC_IRQ_LEGACY_IRQ(ih);
-		if (irq < 0 || irq >= NUM_LEGACY_IRQS)
-			irq = -1;
-	}
-#endif
-
-	return intr_establish(irq, pic, pin, IST_LEVEL, level, func, arg);
-}
-
-void
-pci_intr_disestablish(pc, cookie)
-	pci_chipset_tag_t pc;
-	void *cookie;
-{
-
-	intr_disestablish(cookie);
-}
-
 /*
  * Determine which flags should be passed to the primary PCI bus's
  * autoconfiguration node.  We use this to detect broken chipsets
@@ -818,5 +648,3 @@
 		(*bridge_hook->func)(pc, tag, bridge_hook->arg);
 	}
 }
-
-

--n8g4imXOkfNTN/H1--