Index: arch/amd64/amd64/mainbus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/amd64/amd64/mainbus.c,v
retrieving revision 1.11
diff -c -r1.11 mainbus.c
*** arch/amd64/amd64/mainbus.c	16 Feb 2006 10:56:58 -0000	1.11
--- arch/amd64/amd64/mainbus.c	22 Mar 2006 23:25:19 -0000
***************
*** 147,152 ****
--- 147,154 ----
  	int mpbios_present = 0;
  #endif
  	int mpacpi_active = 0;
+ 	int numcpus = 1;
+ 	int numioapics = 0;
  
  	printf("\n");
  
***************
*** 167,183 ****
  	 * be done later (via a callback).
  	 */
  	if (acpi_present)
! 		mpacpi_active = mpacpi_scan_apics(self);
  #endif
  #endif
  
  	if (!mpacpi_active) {
  #ifdef MPBIOS
  		if (mpbios_present)
! 			mpbios_scan(self);
  		else
  #endif
! 		{
  			struct cpu_attach_args caa;
                          
  			memset(&caa, 0, sizeof(caa));
--- 169,185 ----
  	 * be done later (via a callback).
  	 */
  	if (acpi_present)
! 		mpacpi_active = mpacpi_scan_apics(self, &numcpus, &numioapics);
  #endif
  #endif
  
  	if (!mpacpi_active) {
  #ifdef MPBIOS
  		if (mpbios_present)
! 			mpbios_scan(self, &numcpus, &numioapics);
  		else
  #endif
! 		if (numcpus == 0) {
  			struct cpu_attach_args caa;
                          
  			memset(&caa, 0, sizeof(caa));
***************
*** 235,240 ****
--- 237,247 ----
  #endif
  		config_found_ia(self, "pcibus", &mba.mba_pba, pcibusprint);
  
+ #ifdef MPACPI
+ 		if (mp_verbose)
+ 			acpi_pci_link_state();
+ #endif
+ 
  	}
  #endif
  
Index: arch/i386/i386/mainbus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/i386/mainbus.c,v
retrieving revision 1.62
diff -c -r1.62 mainbus.c
*** arch/i386/i386/mainbus.c	19 Feb 2006 14:59:22 -0000	1.62
--- arch/i386/i386/mainbus.c	22 Mar 2006 23:25:21 -0000
***************
*** 189,194 ****
--- 189,196 ----
  	int pci_maxbus = 0;
  #endif
  	int mpacpi_active = 0;
+ 	int numcpus = 1;
+ 	int numioapics = 0;
  
  	aprint_naive("\n");
  	aprint_normal("\n");
***************
*** 222,238 ****
  	 * be done later (via a callback).
  	 */
  	if (acpi_present)
! 		mpacpi_active = mpacpi_scan_apics(self);
  #endif
  #endif
  
  	if (!mpacpi_active) {
  #ifdef MPBIOS
  		if (mpbios_present)
! 			mpbios_scan(self);
  		else
  #endif
! 		{
  			struct cpu_attach_args caa;
  
  			memset(&caa, 0, sizeof(caa));
--- 224,240 ----
  	 * be done later (via a callback).
  	 */
  	if (acpi_present)
! 		mpacpi_active = mpacpi_scan_apics(self, &numcpus, &numioapics);
  #endif
  #endif
  
  	if (!mpacpi_active) {
  #ifdef MPBIOS
  		if (mpbios_present)
! 			mpbios_scan(self, &numcpus, &numioapics);
  		else
  #endif
! 		if (numcpus == 0) {
  			struct cpu_attach_args caa;
  
  			memset(&caa, 0, sizeof(caa));
***************
*** 318,323 ****
--- 320,329 ----
  		else
  #endif
  		config_found_ia(self, "pcibus", &mba.mba_pba, pcibusprint);
+ #ifdef MPACPI
+ 		if (mp_verbose)
+ 			acpi_pci_link_state();
+ #endif
  	}
  #endif
  
Index: arch/x86/include/intr.h
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/include/intr.h,v
retrieving revision 1.20
diff -c -r1.20 intr.h
*** arch/x86/include/intr.h	16 Feb 2006 20:17:15 -0000	1.20
--- arch/x86/include/intr.h	22 Mar 2006 23:25:23 -0000
***************
*** 235,240 ****
--- 235,241 ----
  const char *intr_string(int);
  void cpu_intr_init(struct cpu_info *);
  int intr_find_mpmapping(int, int, int *);
+ struct pic *intr_findpic(int);
  #ifdef INTRDEBUG
  void intr_printconfig(void);
  #endif
Index: arch/x86/include/mpacpi.h
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/include/mpacpi.h,v
retrieving revision 1.3
diff -c -r1.3 mpacpi.h
*** arch/x86/include/mpacpi.h	16 Apr 2005 07:45:59 -0000	1.3
--- arch/x86/include/mpacpi.h	22 Mar 2006 23:25:23 -0000
***************
*** 5,14 ****
  
  struct pcibus_attach_args;
  
! int mpacpi_scan_apics(struct device *);
  int mpacpi_find_interrupts(void *);
  int mpacpi_pci_attach_hook(struct device *, struct device *,
  			   struct pcibus_attach_args *);
  int mpacpi_scan_pci(struct device *, struct pcibus_attach_args *, cfprint_t);
  
  #endif /* _X86_MPACPI_H_ */
--- 5,17 ----
  
  struct pcibus_attach_args;
  
! int mpacpi_scan_apics(struct device *, int *, int *);
  int mpacpi_find_interrupts(void *);
  int mpacpi_pci_attach_hook(struct device *, struct device *,
  			   struct pcibus_attach_args *);
  int mpacpi_scan_pci(struct device *, struct pcibus_attach_args *, cfprint_t);
  
+ struct mp_intr_map;
+ int mpacpi_findintr_linkdev(struct mp_intr_map *);
+ 
  #endif /* _X86_MPACPI_H_ */
Index: arch/x86/include/mpbiosvar.h
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/include/mpbiosvar.h,v
retrieving revision 1.3
diff -c -r1.3 mpbiosvar.h
*** arch/x86/include/mpbiosvar.h	29 May 2003 20:22:32 -0000	1.3
--- arch/x86/include/mpbiosvar.h	22 Mar 2006 23:25:23 -0000
***************
*** 52,58 ****
  struct pcibus_attach_args;
  
  #if defined(_KERNEL)
! void mpbios_scan(struct device *);
  int mpbios_probe(struct device *);
  int mpbios_pci_attach_hook(struct device *, struct device *,
  			   struct pcibus_attach_args *);
--- 52,58 ----
  struct pcibus_attach_args;
  
  #if defined(_KERNEL)
! void mpbios_scan(struct device *, int *, int *);
  int mpbios_probe(struct device *);
  int mpbios_pci_attach_hook(struct device *, struct device *,
  			   struct pcibus_attach_args *);
Index: arch/x86/include/mpconfig.h
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/include/mpconfig.h,v
retrieving revision 1.8
diff -c -r1.8 mpconfig.h
*** arch/x86/include/mpconfig.h	29 May 2005 21:37:02 -0000	1.8
--- arch/x86/include/mpconfig.h	22 Mar 2006 23:25:23 -0000
***************
*** 53,59 ****
  	struct mp_intr_map *next;
  	struct mp_bus *bus;
  	int bus_pin;
! 	struct ioapic_softc *ioapic;
  	int ioapic_pin;
  	int ioapic_ih;		/* int handle, for apic_intr_est */
  	int type;		/* from mp spec intr record */
--- 53,59 ----
  	struct mp_intr_map *next;
  	struct mp_bus *bus;
  	int bus_pin;
! 	struct pic *ioapic;
  	int ioapic_pin;
  	int ioapic_ih;		/* int handle, for apic_intr_est */
  	int type;		/* from mp spec intr record */
***************
*** 62,67 ****
--- 62,69 ----
  	int cpu_id;
  	int global_int;		/* ACPI global interrupt number */
  	int sflags;		/* other, software flags (see below) */
+ 	void *linkdev;
+ 	int sourceindex;
  };
  
  #define MPI_OVR		0x0001	/* Was overridden by an ACPI OVR */
Index: arch/x86/include/pic.h
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/include/pic.h,v
retrieving revision 1.1
diff -c -r1.1 pic.h
*** arch/x86/include/pic.h	26 Feb 2003 21:26:11 -0000	1.1
--- arch/x86/include/pic.h	22 Mar 2006 23:25:23 -0000
***************
*** 14,19 ****
--- 14,21 ----
  struct pic {
  	struct device pic_dev;
          int pic_type;
+ 	int pic_vecbase;
+ 	int pic_apicid;
  	__cpu_simple_lock_t pic_lock;
          void (*pic_hwmask)(struct pic *, int);
          void (*pic_hwunmask)(struct pic *, int);
Index: arch/x86/pci/pci_intr_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/pci/pci_intr_machdep.c,v
retrieving revision 1.1
diff -c -r1.1 pci_intr_machdep.c
*** arch/x86/pci/pci_intr_machdep.c	3 Feb 2006 19:58:21 -0000	1.1
--- arch/x86/pci/pci_intr_machdep.c	22 Mar 2006 23:25:23 -0000
***************
*** 101,108 ****
  #include "opt_mpbios.h"
  #include "opt_mpacpi.h"
  
! #if NIOAPIC > 0
  #include <machine/i82093var.h>
  #include <machine/mpbiosvar.h>
  #include <machine/pic.h>
  #endif
--- 101,109 ----
  #include "opt_mpbios.h"
  #include "opt_mpacpi.h"
  
! #if NIOAPIC > 0 || defined(MPACPI)
  #include <machine/i82093var.h>
+ #include <machine/mpconfig.h>
  #include <machine/mpbiosvar.h>
  #include <machine/pic.h>
  #endif
***************
*** 122,128 ****
  {
  	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;
--- 123,129 ----
  {
  	int pin = pa->pa_intrpin;
  	int line = pa->pa_intrline;
! #if NIOAPIC > 0 || defined(MPACPI)
  	int rawpin = pa->pa_rawintrpin;
  	pci_chipset_tag_t pc = pa->pa_pc;
  	int bus, dev, func;
***************
*** 133,148 ****
  		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;
  		}
  		/*
--- 134,152 ----
  		goto bad;
  	}
  
+ 	*ihp = 0;
+ 
  	if (pin > PCI_INTERRUPT_PIN_MAX) {
  		printf("pci_intr_map: bad interrupt pin %d\n", pin);
  		goto bad;
  	}
  
! #if NIOAPIC > 0 || defined(MPACPI)
  	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) {
! 			if ((*ihp & 0xff) == 0)
! 				*ihp |= line;
  			return 0;
  		}
  		/*
***************
*** 180,194 ****
  			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
--- 184,200 ----
  			line = 9;
  		}
  	}
! #if NIOAPIC > 0 || defined(MPACPI)
  	if (mp_busses != NULL) {
  		if (intr_find_mpmapping(mp_isa_bus, line, ihp) == 0) {
! 			if ((*ihp & 0xff) == 0)
! 				*ihp |= line;
  			return 0;
  		}
  #if NEISA > 0
  		if (intr_find_mpmapping(mp_eisa_bus, line, ihp) == 0) {
! 			if ((*ihp & 0xff) == 0)
! 				*ihp |= line;
  			return 0;
  		}
  #endif
Index: arch/x86/pci/pci_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/pci/pci_machdep.c,v
retrieving revision 1.14
diff -c -r1.14 pci_machdep.c
*** arch/x86/pci/pci_machdep.c	7 Feb 2006 20:38:43 -0000	1.14
--- arch/x86/pci/pci_machdep.c	22 Mar 2006 23:25:23 -0000
***************
*** 114,119 ****
--- 114,123 ----
  #include <machine/mpacpi.h>
  #endif
  
+ #if defined(MPBIOS) || defined(MPACPI)
+ #include <machine/mpconfig.h>
+ #endif
+ 
  #include "opt_pci_conf_mode.h"
  
  int pci_mode = -1;
Index: arch/x86/x86/i8259.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/i8259.c,v
retrieving revision 1.6
diff -c -r1.6 i8259.c
*** arch/x86/x86/i8259.c	11 Dec 2005 12:19:47 -0000	1.6
--- arch/x86/x86/i8259.c	22 Mar 2006 23:25:23 -0000
***************
*** 111,116 ****
--- 111,118 ----
  		.dv_xname = "pic0",
  	},
  	.pic_type = PIC_I8259,
+ 	.pic_vecbase = 0,
+ 	.pic_apicid = 0,
  	.pic_lock = __SIMPLELOCK_UNLOCKED,
  	.pic_hwmask = i8259_hwmask,
  	.pic_hwunmask = i8259_hwunmask,
Index: arch/x86/x86/intr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/intr.c,v
retrieving revision 1.22
diff -c -r1.22 intr.c
*** arch/x86/x86/intr.c	11 Dec 2005 12:19:47 -0000	1.22
--- arch/x86/x86/intr.c	22 Mar 2006 23:25:23 -0000
***************
*** 106,112 ****
--- 106,115 ----
  #include <sys/cdefs.h>
  __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.22 2005/12/11 12:19:47 christos Exp $");
  
+ #define INTRDEBUG
+ 
  #include "opt_multiprocessor.h"
+ #include "opt_mpacpi.h"
  
  #include <sys/cdefs.h>
  #include <sys/param.h> 
***************
*** 127,135 ****
  #include "lapic.h"
  #include "pci.h"
  
! #if NIOAPIC > 0
  #include <machine/i82093var.h> 
  #include <machine/mpbiosvar.h>
  #endif
  
  #if NLAPIC > 0
--- 130,139 ----
  #include "lapic.h"
  #include "pci.h"
  
! #if NIOAPIC > 0 || defined(MPACPI)
  #include <machine/i82093var.h> 
  #include <machine/mpbiosvar.h>
+ #include <machine/mpacpi.h>
  #endif
  
  #if NLAPIC > 0
***************
*** 145,154 ****
  		.dv_xname = "softintr_fakepic",
  	},
  	.pic_type = PIC_SOFT,
  	.pic_lock = __SIMPLELOCK_UNLOCKED,
  };
  
! #if NIOAPIC > 0
  static int intr_scan_bus(int, int, int *);
  #if NPCI > 0
  static int intr_find_pcibridge(int, pcitag_t *, pci_chipset_tag_t *);
--- 149,160 ----
  		.dv_xname = "softintr_fakepic",
  	},
  	.pic_type = PIC_SOFT,
+ 	.pic_vecbase = 0,
+ 	.pic_apicid = 0,
  	.pic_lock = __SIMPLELOCK_UNLOCKED,
  };
  
! #if NIOAPIC > 0 || defined(MPACPI)
  static int intr_scan_bus(int, int, int *);
  #if NPCI > 0
  static int intr_find_pcibridge(int, pcitag_t *, pci_chipset_tag_t *);
***************
*** 253,259 ****
   *
   * XXX should maintain one list, not an array and a linked list.
   */
! #if (NPCI > 0) && (NIOAPIC > 0)
  struct intr_extra_bus {
  	int bus;
  	pcitag_t *pci_bridge_tag;
--- 259,265 ----
   *
   * XXX should maintain one list, not an array and a linked list.
   */
! #if (NPCI > 0) && ((NIOAPIC > 0) || defined(MPACPI))
  struct intr_extra_bus {
  	int bus;
  	pcitag_t *pci_bridge_tag;
***************
*** 313,319 ****
  /*
   * XXX if defined(MULTIPROCESSOR) && .. ?
   */
! #if NIOAPIC > 0
  int
  intr_find_mpmapping(int bus, int pin, int *handle)
  {
--- 319,325 ----
  /*
   * XXX if defined(MULTIPROCESSOR) && .. ?
   */
! #if NIOAPIC > 0 || defined(MPACPI)
  int
  intr_find_mpmapping(int bus, int pin, int *handle)
  {
***************
*** 355,360 ****
--- 361,371 ----
  
  	for (mip = intrs; mip != NULL; mip = mip->next) {
  		if (mip->bus_pin == pin) {
+ #ifdef MPACPI
+ 			if (mip->linkdev != NULL)
+ 				if (mpacpi_findintr_linkdev(mip) != 0)
+ 					continue;
+ #endif
  			*handle = mip->ioapic_ih;
  			return 0;
  		}
***************
*** 539,544 ****
--- 550,571 ----
  }
  #endif /* MULTIPROCESSOR */
  
+ struct pic *
+ intr_findpic(int num)
+ {
+ #if NIOAPIC > 0
+ 	struct pic *pic;
+ 
+ 	pic = (struct pic *)ioapic_find_bybase(num);
+ 	if (pic != NULL)
+ 		return pic;
+ #endif
+ 	if (num < NUM_LEGACY_IRQS)
+ 		return &i8259_pic;
+ 
+ 	return NULL;
+ }
+ 
  void *
  intr_establish(int legacy_irq, struct pic *pic, int pin, int type, int level,
  	       int (*handler)(void *), void *arg)
Index: arch/x86/x86/ioapic.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/ioapic.c,v
retrieving revision 1.12
diff -c -r1.12 ioapic.c
*** arch/x86/x86/ioapic.c	24 Dec 2005 20:07:42 -0000	1.12
--- arch/x86/x86/ioapic.c	22 Mar 2006 23:25:23 -0000
***************
*** 208,214 ****
  	}
  
  	for (sc = ioapics; sc != NULL; sc = sc->sc_next)
! 		if (sc->sc_apicid == apicid)
  			return sc;
  
  	return NULL;
--- 208,214 ----
  	}
  
  	for (sc = ioapics; sc != NULL; sc = sc->sc_next)
! 		if (sc->sc_pic.pic_apicid == apicid)
  			return sc;
  
  	return NULL;
***************
*** 224,231 ****
  	struct ioapic_softc *sc;
  
  	for (sc = ioapics; sc != NULL; sc = sc->sc_next) {
! 		if (vec >= sc->sc_apic_vecbase &&
! 		    vec < (sc->sc_apic_vecbase + sc->sc_apic_sz))
  			return sc;
  	}
  
--- 224,231 ----
  	struct ioapic_softc *sc;
  
  	for (sc = ioapics; sc != NULL; sc = sc->sc_next) {
! 		if (vec >= sc->sc_pic.pic_vecbase &&
! 		    vec < (sc->sc_pic.pic_vecbase + sc->sc_apic_sz))
  			return sc;
  	}
  
***************
*** 282,288 ****
  	int i;
  	
  	sc->sc_flags = aaa->flags;
! 	sc->sc_apicid = aaa->apic_id;
  
  	printf(" apid %d (I/O APIC)\n", aaa->apic_id);
  
--- 282,288 ----
  	int i;
  	
  	sc->sc_flags = aaa->flags;
! 	sc->sc_pic.pic_apicid = aaa->apic_id;
  
  	printf(" apid %d (I/O APIC)\n", aaa->apic_id);
  
***************
*** 320,332 ****
  	sc->sc_apic_sz++;
  
  	if (aaa->apic_vecbase != -1)
! 		sc->sc_apic_vecbase = aaa->apic_vecbase;
  	else {
  		/*
  		 * XXX this assumes ordering of ioapics in the table.
  		 * Only needed for broken BIOS workaround (see mpbios.c)
  		 */
! 		sc->sc_apic_vecbase = ioapic_vecbase;
  		ioapic_vecbase += sc->sc_apic_sz;
  	}
  
--- 320,332 ----
  	sc->sc_apic_sz++;
  
  	if (aaa->apic_vecbase != -1)
! 		sc->sc_pic.pic_vecbase = aaa->apic_vecbase;
  	else {
  		/*
  		 * XXX this assumes ordering of ioapics in the table.
  		 * Only needed for broken BIOS workaround (see mpbios.c)
  		 */
! 		sc->sc_pic.pic_vecbase = ioapic_vecbase;
  		ioapic_vecbase += sc->sc_apic_sz;
  	}
  
***************
*** 353,375 ****
  	 * Maybe we should record the original ID for interrupt
  	 * mapping later ...
  	 */
! 	if (apic_id != sc->sc_apicid) {
  		printf("%s: misconfigured as apic %d\n", sc->sc_pic.pic_dev.dv_xname, apic_id);
  
  		ioapic_write(sc,IOAPIC_ID,
  		    (ioapic_read(sc,IOAPIC_ID)&~IOAPIC_ID_MASK)
! 		    |(sc->sc_apicid<<IOAPIC_ID_SHIFT));
  		
  		apic_id = (ioapic_read(sc,IOAPIC_ID)&IOAPIC_ID_MASK)>>IOAPIC_ID_SHIFT;
  		
! 		if (apic_id != sc->sc_apicid) {
  			printf("%s: can't remap to apid %d\n",
  			    sc->sc_pic.pic_dev.dv_xname,
! 			    sc->sc_apicid);
  		} else {
  			printf("%s: remapped to apic %d\n",
  			    sc->sc_pic.pic_dev.dv_xname,
! 			    sc->sc_apicid);
  		}
  	}
  #if 0
--- 353,375 ----
  	 * Maybe we should record the original ID for interrupt
  	 * mapping later ...
  	 */
! 	if (apic_id != sc->sc_pic.pic_apicid) {
  		printf("%s: misconfigured as apic %d\n", sc->sc_pic.pic_dev.dv_xname, apic_id);
  
  		ioapic_write(sc,IOAPIC_ID,
  		    (ioapic_read(sc,IOAPIC_ID)&~IOAPIC_ID_MASK)
! 		    |(sc->sc_pic.pic_apicid<<IOAPIC_ID_SHIFT));
  		
  		apic_id = (ioapic_read(sc,IOAPIC_ID)&IOAPIC_ID_MASK)>>IOAPIC_ID_SHIFT;
  		
! 		if (apic_id != sc->sc_pic.pic_apicid) {
  			printf("%s: can't remap to apid %d\n",
  			    sc->sc_pic.pic_dev.dv_xname,
! 			    sc->sc_pic.pic_apicid);
  		} else {
  			printf("%s: remapped to apic %d\n",
  			    sc->sc_pic.pic_dev.dv_xname,
! 			    sc->sc_pic.pic_apicid);
  		}
  	}
  #if 0
Index: arch/x86/x86/mpacpi.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/mpacpi.c,v
retrieving revision 1.35
diff -c -r1.35 mpacpi.c
*** arch/x86/x86/mpacpi.c	11 Dec 2005 12:19:47 -0000	1.35
--- arch/x86/x86/mpacpi.c	22 Mar 2006 23:25:23 -0000
***************
*** 40,45 ****
--- 40,46 ----
  
  #include "opt_acpi.h"
  #include "opt_mpbios.h"
+ #include "opt_multiprocessor.h"
  
  #include <sys/param.h>
  #include <sys/systm.h>
***************
*** 70,76 ****
--- 71,80 ----
  #include <dev/acpi/acpivar.h>
  #include <dev/acpi/acpi_madt.h>
  
+ #include <dev/cons.h>
+ 
  #include "pci.h"
+ #include "ioapic.h"
  
  #ifdef ACPI_DEBUG_OUTPUT
  #define _COMPONENT ACPI_HARDWARE
***************
*** 119,124 ****
--- 123,130 ----
  static void mpacpi_print_intr(struct mp_intr_map *);
  static void mpacpi_print_isa_intr(int);
  
+ static void mpacpi_user_continue(const char *fmt, ...);
+ 
  int mpacpi_nioapic;			/* number of ioapics */
  int mpacpi_ncpu;			/* number of cpus */
  int mpacpi_nintsrc;			/* number of non-device interrupts */
***************
*** 132,137 ****
--- 138,146 ----
  static int mpacpi_intr_index;
  static paddr_t mpacpi_lapic_base = LAPIC_BASE;
  
+ int mpacpi_step;
+ int mpacpi_force;
+ 
  static int
  mpacpi_print(void *aux, const char *pnp)
  {
***************
*** 164,191 ****
  	MADT_NMI_SOURCE *ioapic_nmi;
  	MADT_LOCAL_APIC_NMI *lapic_nmi;
  	MADT_INTERRUPT_OVERRIDE *isa_ovr;
! 	struct ioapic_softc *ioapic;
  
  	switch (hdrp->Type) {
  	case APIC_NMI:
  		ioapic_nmi = (MADT_NMI_SOURCE *)hdrp;
! 		ioapic = ioapic_find_bybase(ioapic_nmi->Interrupt);
! 		if (ioapic == NULL)
  			break;
  		mpi = &mp_intrs[*index];
  		(*index)++;
  		mpi->next = NULL;
  		mpi->bus = NULL;
  		mpi->type = MPS_INTTYPE_NMI;
! 		mpi->ioapic = ioapic;
! 		pin = ioapic_nmi->Interrupt - ioapic->sc_apic_vecbase;
  		mpi->ioapic_pin = pin;
  		mpi->bus_pin = -1;
  		mpi->redir = (IOAPIC_REDLO_DEL_NMI<<IOAPIC_REDLO_DEL_SHIFT);
! 		ioapic->sc_pins[pin].ip_map = mpi;
! 		mpi->ioapic_ih = APIC_INT_VIA_APIC |
! 		    (ioapic->sc_apicid << APIC_INT_APIC_SHIFT) |
! 		    (pin << APIC_INT_PIN_SHIFT);
  		mpi->flags = ioapic_nmi->Polarity |
  		    (ioapic_nmi->TriggerMode << 2);
  		mpi->global_int = ioapic_nmi->Interrupt;
--- 173,209 ----
  	MADT_NMI_SOURCE *ioapic_nmi;
  	MADT_LOCAL_APIC_NMI *lapic_nmi;
  	MADT_INTERRUPT_OVERRIDE *isa_ovr;
! 	struct pic *pic;
  
  	switch (hdrp->Type) {
  	case APIC_NMI:
  		ioapic_nmi = (MADT_NMI_SOURCE *)hdrp;
! 		pic = intr_findpic(ioapic_nmi->Interrupt);
! 		if (pic == NULL)
  			break;
+ #if NIOAPIC == 0
+ 		if (pic->pic_type == PIC_IOAPIC)
+ 			break;
+ #endif
  		mpi = &mp_intrs[*index];
  		(*index)++;
  		mpi->next = NULL;
  		mpi->bus = NULL;
  		mpi->type = MPS_INTTYPE_NMI;
! 		mpi->ioapic = pic;
! 		pin = ioapic_nmi->Interrupt - pic->pic_vecbase;
  		mpi->ioapic_pin = pin;
  		mpi->bus_pin = -1;
  		mpi->redir = (IOAPIC_REDLO_DEL_NMI<<IOAPIC_REDLO_DEL_SHIFT);
! #if NIOAPIC > 0
! 		if (pic->pic_type == PIC_IOAPIC) {
! 			((struct ioapic_softc *)pic)->sc_pins[pin].ip_map = mpi;
! 			mpi->ioapic_ih = APIC_INT_VIA_APIC |
! 			    (pic->pic_apicid << APIC_INT_APIC_SHIFT) |
! 			    (pin << APIC_INT_PIN_SHIFT);
! 		} else
! #endif
! 			mpi->ioapic_ih = pin;
  		mpi->flags = ioapic_nmi->Polarity |
  		    (ioapic_nmi->TriggerMode << 2);
  		mpi->global_int = ioapic_nmi->Interrupt;
***************
*** 207,216 ****
  		isa_ovr = (MADT_INTERRUPT_OVERRIDE *)hdrp;
  		if (isa_ovr->Source > 15 || isa_ovr->Source == 2)
  			break;
! 		ioapic = ioapic_find_bybase(isa_ovr->Interrupt);
! 		if (ioapic == NULL)
  			break;
! 		pin = isa_ovr->Interrupt - ioapic->sc_apic_vecbase;
  		lindex = isa_ovr->Source;
  		/*
  		 * IRQ 2 was skipped in the default setup.
--- 225,238 ----
  		isa_ovr = (MADT_INTERRUPT_OVERRIDE *)hdrp;
  		if (isa_ovr->Source > 15 || isa_ovr->Source == 2)
  			break;
! 		pic = intr_findpic(isa_ovr->Interrupt);
! 		if (pic == NULL)
! 			break;
! #if NIOAPIC == 0
! 		if (pic->pic_type == PIC_IOAPIC)
  			break;
! #endif
! 		pin = isa_ovr->Interrupt - pic->pic_vecbase;
  		lindex = isa_ovr->Source;
  		/*
  		 * IRQ 2 was skipped in the default setup.
***************
*** 218,227 ****
  		if (lindex > 2)
  			lindex--;
  		mpi = &mp_intrs[lindex];
! 		mpi->ioapic_ih = APIC_INT_VIA_APIC |
! 		    (ioapic->sc_apicid << APIC_INT_APIC_SHIFT) |
! 		    (pin << APIC_INT_PIN_SHIFT);
  		mpi->bus_pin = isa_ovr->Source;
  		mpi->ioapic_pin = pin;
  		mpi->sflags |= MPI_OVR;
  		mpi->redir = 0;
--- 240,255 ----
  		if (lindex > 2)
  			lindex--;
  		mpi = &mp_intrs[lindex];
! #if NIOAPIC > 0
! 		if (pic->pic_type == PIC_IOAPIC) {
! 			mpi->ioapic_ih = APIC_INT_VIA_APIC |
! 			    (pic->pic_apicid << APIC_INT_APIC_SHIFT) |
! 			    (pin << APIC_INT_PIN_SHIFT);
! 		} else
! #endif
! 			mpi->ioapic_ih = pin;
  		mpi->bus_pin = isa_ovr->Source;
+ 		mpi->ioapic = (struct pic *)pic;
  		mpi->ioapic_pin = pin;
  		mpi->sflags |= MPI_OVR;
  		mpi->redir = 0;
***************
*** 245,251 ****
  			break;
  		}
  		mpi->flags = isa_ovr->Polarity | (isa_ovr->TriggerMode << 2);
! 		ioapic->sc_pins[pin].ip_map = mpi;
  	default:
  		break;
  	}
--- 273,282 ----
  			break;
  		}
  		mpi->flags = isa_ovr->Polarity | (isa_ovr->TriggerMode << 2);
! #if NIOAPIC > 0
! 		if (pic->pic_type == PIC_IOAPIC)
! 			((struct ioapic_softc *)pic)->sc_pins[pin].ip_map = mpi;
! #endif
  	default:
  		break;
  	}
***************
*** 287,300 ****
  	struct device *parent = aux;
  	MADT_PROCESSOR_APIC *p;
  	struct cpu_attach_args caa;
  
  	if (hdrp->Type == APIC_PROCESSOR) {
  		p = (MADT_PROCESSOR_APIC *)hdrp;
  		if (p->ProcessorEnabled) {
! 			if (p->LocalApicId == lapic_cpu_number())
! 				caa.cpu_role = CPU_ROLE_BP;
! 			else
  				caa.cpu_role = CPU_ROLE_AP;
  			caa.caa_name = "cpu";
  			caa.cpu_number = p->LocalApicId;
  			caa.cpu_func = &mp_cpu_funcs;
--- 318,337 ----
  	struct device *parent = aux;
  	MADT_PROCESSOR_APIC *p;
  	struct cpu_attach_args caa;
+ 	int cpunum = 0;
+ 
+ #if defined(MULTIPROCESSOR) || defined(IOAPIC)
+ 	if (mpacpi_ncpu > 1)
+ 		cpunum = lapic_cpu_number();
+ #endif
  
  	if (hdrp->Type == APIC_PROCESSOR) {
  		p = (MADT_PROCESSOR_APIC *)hdrp;
  		if (p->ProcessorEnabled) {
! 			if (p->LocalApicId != cpunum)
  				caa.cpu_role = CPU_ROLE_AP;
+ 			else
+ 				caa.cpu_role = CPU_ROLE_BP;
  			caa.caa_name = "cpu";
  			caa.cpu_number = p->LocalApicId;
  			caa.cpu_func = &mp_cpu_funcs;
***************
*** 327,333 ****
  }
  
  int
! mpacpi_scan_apics(struct device *self)
  {
  	int rv = 0;
  
--- 364,370 ----
  }
  
  int
! mpacpi_scan_apics(struct device *self, int *ncpu, int *napic)
  {
  	int rv = 0;
  
***************
*** 337,343 ****
--- 374,382 ----
  	mpacpi_ncpu = mpacpi_nintsrc = mpacpi_nioapic = 0;
  	acpi_madt_walk(mpacpi_count, self);
  
+ #if NIOAPIC > 0
  	lapic_boot_init(mpacpi_lapic_base);
+ #endif
  
  	acpi_madt_walk(mpacpi_config_cpu, self);
  
***************
*** 351,361 ****
  	 * If PCI routing tables can't be built we report failure
  	 * and let MPBIOS do the work.
  	 */
! 	if ((acpi_find_quirks() & (ACPI_QUIRK_BADPCI | ACPI_QUIRK_BADIRQ)) != 0)
  		goto done;
  #endif
  	rv = 1;
  done:
  	acpi_madt_unmap();
  	return rv;
  }
--- 390,403 ----
  	 * If PCI routing tables can't be built we report failure
  	 * and let MPBIOS do the work.
  	 */
! 	if (!mpacpi_force &&
! 	    (acpi_find_quirks() & (ACPI_QUIRK_BADPCI)) != 0)
  		goto done;
  #endif
  	rv = 1;
  done:
+ 	*ncpu = mpacpi_ncpu;
+ 	*napic = mpacpi_nioapic;
  	acpi_madt_unmap();
  	return rv;
  }
***************
*** 603,612 ****
  mpacpi_pciroute(struct mpacpi_pcibus *mpr)
  {
  	ACPI_PCI_ROUTING_TABLE *ptrp;
  	char *p;
  	struct mp_intr_map *mpi;
  	struct mp_bus *mpb;
! 	struct ioapic_softc *ioapic;
  	unsigned dev;
  	int pin;
  
--- 645,655 ----
  mpacpi_pciroute(struct mpacpi_pcibus *mpr)
  {
  	ACPI_PCI_ROUTING_TABLE *ptrp;
+         ACPI_HANDLE linkdev;
  	char *p;
  	struct mp_intr_map *mpi;
  	struct mp_bus *mpb;
! 	struct pic *pic;
  	unsigned dev;
  	int pin;
  
***************
*** 627,663 ****
  		if (ptrp->Length == 0)
  			break;
  		dev = ACPI_HIWORD(ptrp->Address);
! 		if (ptrp->Source[0] != 0)
! 			continue;
! 		ioapic = ioapic_find_bybase(ptrp->SourceIndex);
! 		if (ioapic == NULL)
! 			continue;
  		mpi = &mp_intrs[mpacpi_intr_index++];
- 		mpi->bus = mpb;
  		mpi->bus_pin = (dev << 2) | ptrp->Pin;
  		mpi->type = MPS_INTTYPE_INT;
  
! 		/* Defaults for PCI (active low, level triggered) */
! 		mpi->redir = (IOAPIC_REDLO_DEL_FIXED<<IOAPIC_REDLO_DEL_SHIFT) |
! 		    IOAPIC_REDLO_LEVEL | IOAPIC_REDLO_ACTLO;
! 		mpi->flags = MPS_INTPO_ACTLO | (MPS_INTTR_LEVEL << 2);
  		mpi->cpu_id = 0;
  
- 		pin = ptrp->SourceIndex - ioapic->sc_apic_vecbase;
- 		mpi->ioapic = ioapic;
- 		mpi->ioapic_pin = pin;
- 		mpi->ioapic_ih = APIC_INT_VIA_APIC |
- 		    (ioapic->sc_apicid << APIC_INT_APIC_SHIFT) |
- 		    (pin << APIC_INT_PIN_SHIFT);
- 		ioapic->sc_pins[pin].ip_map = mpi;
  		mpi->next = mpb->mb_intrs;
- 		mpi->global_int = ptrp->SourceIndex;
  		mpb->mb_intrs = mpi;
  	}
  
  	AcpiOsFree(mpr->mpr_buf.Pointer);
  	mpr->mpr_buf.Pointer = NULL;	/* be preventive to bugs */
  
  	return 0;
  }
  
--- 670,747 ----
  		if (ptrp->Length == 0)
  			break;
  		dev = ACPI_HIWORD(ptrp->Address);
! 
  		mpi = &mp_intrs[mpacpi_intr_index++];
  		mpi->bus_pin = (dev << 2) | ptrp->Pin;
+ 		mpi->bus = mpb;
  		mpi->type = MPS_INTTYPE_INT;
  
! 		if (ptrp->Source[0] != 0) {
! 			if (mp_verbose > 1)
! 				printf("pciroute: dev %d INT%c on lnkdev %s\n",
! 				    dev, 'A' + ptrp->Pin, ptrp->Source);
! 			mpi->global_int = -1;
! 			mpi->sourceindex = ptrp->SourceIndex;
! 			if (AcpiGetHandle(ACPI_ROOT_OBJECT, ptrp->Source,
! 			    &linkdev) != AE_OK) {
! 				printf("AcpiGetHandle failed for '%s'\n",
! 				    ptrp->Source);
! 				continue;
! 			}
! 			/* acpi_allocate_resources(linkdev); */
! 			mpi->ioapic_pin = -1;
! 			mpi->linkdev = acpi_pci_link_devbyhandle(linkdev);
! 			acpi_pci_link_add_reference(mpi->linkdev, 0,
! 			    mpr->mpr_bus, dev, ptrp->Pin);
! 			mpi->ioapic = NULL;
! 			mpi->flags = MPS_INTPO_ACTLO | (MPS_INTTR_LEVEL << 2);
! 			if (mp_verbose > 1)
! 				printf("pciroute: done adding entry\n");
! 		} else {
! 			if (mp_verbose > 1)
! 				printf("pciroute: dev %d INT%c on globint %d\n",
! 				    dev, 'A' + ptrp->Pin, ptrp->SourceIndex);
! 			mpi->sourceindex = 0;
! 			mpi->global_int = ptrp->SourceIndex;
! 			pic = intr_findpic(ptrp->SourceIndex);
! 			if (pic == NULL)
! 				continue;
! 			/* Defaults for PCI (active low, level triggered) */
! 			mpi->redir =
! 			    (IOAPIC_REDLO_DEL_FIXED<<IOAPIC_REDLO_DEL_SHIFT) |
! 			    IOAPIC_REDLO_LEVEL | IOAPIC_REDLO_ACTLO;
! 			mpi->ioapic = pic;
! 			pin = ptrp->SourceIndex - pic->pic_vecbase;
! 			if (pic->pic_type == PIC_I8259 && pin > 15)
! 				panic("bad pin %d for legacy IRQ", pin);
! 			mpi->ioapic_pin = pin;
! #if NIOAPIC > 0
! 			if (pic->pic_type == PIC_IOAPIC) {
! 				((struct ioapic_softc *)pic)->sc_pins[pin].ip_map = mpi;
! 				mpi->ioapic_ih = APIC_INT_VIA_APIC |
! 				    (pic->pic_apicid << APIC_INT_APIC_SHIFT) |
! 				    (pin << APIC_INT_PIN_SHIFT);
! 			} else
! #endif
! 				mpi->ioapic_ih = pin;
! 			mpi->linkdev = NULL;
! 			mpi->flags = MPS_INTPO_ACTLO | (MPS_INTTR_LEVEL << 2);
! 			if (mp_verbose > 1)
! 				printf("pciroute: done adding entry\n");
! 		}
! 
  		mpi->cpu_id = 0;
  
  		mpi->next = mpb->mb_intrs;
  		mpb->mb_intrs = mpi;
  	}
  
  	AcpiOsFree(mpr->mpr_buf.Pointer);
  	mpr->mpr_buf.Pointer = NULL;	/* be preventive to bugs */
  
+ 	if (mp_verbose > 1)
+ 		printf("pciroute: done\n");
+ 
  	return 0;
  }
  
***************
*** 695,701 ****
  	int i;
  	struct mp_bus *mbp;
  	struct mp_intr_map *mpi;
! 	struct ioapic_softc *ioapic;
  
  	nintr = mpacpi_nintsrc + NUM_LEGACY_IRQS - 1;
  #if NPCI > 0
--- 779,785 ----
  	int i;
  	struct mp_bus *mbp;
  	struct mp_intr_map *mpi;
! 	struct pic *pic;
  
  	nintr = mpacpi_nintsrc + NUM_LEGACY_IRQS - 1;
  #if NPCI > 0
***************
*** 728,736 ****
  	mbp->mb_intrs = &mp_intrs[0];
  	mbp->mb_data = 0;
  
! 	ioapic = ioapic_find_bybase(0);
! 	if (ioapic == NULL)
! 		panic("can't find first ioapic");
  
  	/*
  	 * Set up default identity mapping for ISA irqs to first ioapic.
--- 812,824 ----
  	mbp->mb_intrs = &mp_intrs[0];
  	mbp->mb_data = 0;
  
! 	pic = intr_findpic(0);
! 	if (pic == NULL)
! 		panic("mpacpi: can't find first PIC");
! #if NIOAPIC == 0
! 	if (pic->pic_type == PIC_IOAPIC)
! 		panic("mpacpi: ioapic but no i8259?");
! #endif
  
  	/*
  	 * Set up default identity mapping for ISA irqs to first ioapic.
***************
*** 746,775 ****
  		mpi->bus = mbp;
  		mpi->bus_pin = i;
  		mpi->ioapic_pin = i;
! 		mpi->ioapic = ioapic;
  		mpi->type = MPS_INTTYPE_INT;
  		mpi->cpu_id = 0;
! 		mpi->ioapic_ih = APIC_INT_VIA_APIC |
! 		    (ioapic->sc_apicid << APIC_INT_APIC_SHIFT) |
! 		    (i << APIC_INT_PIN_SHIFT);
! 		mpi->redir = (IOAPIC_REDLO_DEL_FIXED<<IOAPIC_REDLO_DEL_SHIFT);
  		mpi->flags = MPS_INTPO_DEF | (MPS_INTTR_DEF << 2);
  		mpi->global_int = i;
- 		ioapic->sc_pins[i].ip_map = mpi;
  		mpacpi_intr_index++;
  	}
  
! 	if (acpi_madt_map() != AE_OK)
! 		panic("failed to map the MADT a second time");
  
! 	acpi_madt_walk(mpacpi_nonpci_intr, &mpacpi_intr_index);
! 	acpi_madt_unmap();
  
  #if NPCI > 0
  	TAILQ_FOREACH(mpr, &mpacpi_pcibusses, mpr_list) {
  		mpacpi_pciroute(mpr);
  	}
  #endif
  	mp_nintr = mpacpi_intr_index;
  }
  
--- 834,877 ----
  		mpi->bus = mbp;
  		mpi->bus_pin = i;
  		mpi->ioapic_pin = i;
! 		mpi->ioapic = pic;
  		mpi->type = MPS_INTTYPE_INT;
  		mpi->cpu_id = 0;
! 		mpi->redir = 0;
! #if NIOAPIC > 0
! 		if (pic->pic_type == PIC_IOAPIC) {
! 			mpi->ioapic_ih = APIC_INT_VIA_APIC |
! 			    (pic->pic_apicid << APIC_INT_APIC_SHIFT) |
! 			    (i << APIC_INT_PIN_SHIFT);
! 			mpi->redir =
! 			    (IOAPIC_REDLO_DEL_FIXED<<IOAPIC_REDLO_DEL_SHIFT);
! 			((struct ioapic_softc *)pic)->sc_pins[i].ip_map = mpi;
! 		} else
! #endif
! 			mpi->ioapic_ih = i;
! 
  		mpi->flags = MPS_INTPO_DEF | (MPS_INTTR_DEF << 2);
  		mpi->global_int = i;
  		mpacpi_intr_index++;
  	}
  
! 	mpacpi_user_continue("done setting up mp_bus array and ISA maps");
  
! 	if (acpi_madt_map() == AE_OK) {
! 		acpi_madt_walk(mpacpi_nonpci_intr, &mpacpi_intr_index);
! 		acpi_madt_unmap();
! 	}
! 
! 	mpacpi_user_continue("done with non-PCI interrupts");
  
  #if NPCI > 0
  	TAILQ_FOREACH(mpr, &mpacpi_pcibusses, mpr_list) {
  		mpacpi_pciroute(mpr);
  	}
  #endif
+ 
+ 	mpacpi_user_continue("done routing PCI interrupts");
+ 
  	mp_nintr = mpacpi_intr_index;
  }
  
***************
*** 803,809 ****
  {
  	char buf[256];
  	int pin;
! 	struct ioapic_softc *sc;
  	const char *busname;
  
  	sc = mpi->ioapic;
--- 905,911 ----
  {
  	char buf[256];
  	int pin;
! 	struct pic *sc;
  	const char *busname;
  
  	sc = mpi->ioapic;
***************
*** 827,835 ****
  		}
  	}
  
! 	printf("%s: pin %d attached to %s",
! 	    sc ? sc->sc_pic.pic_dev.dv_xname : "local apic",
! 	    pin, busname);
  
  	if (mpi->bus != NULL) {
  		if (mpi->bus->mb_idx != -1)
--- 929,941 ----
  		}
  	}
  
! 	if (mpi->linkdev != NULL)
! 		printf("linkdev %s attached to %s",
! 		    acpi_pci_link_name(mpi->linkdev), busname);
! 	else
! 		printf("%s: pin %d attached to %s",
! 		    sc ? sc->pic_dev.dv_xname : "local apic",
! 		    pin, busname);
  
  	if (mpi->bus != NULL) {
  		if (mpi->bus->mb_idx != -1)
***************
*** 848,856 ****
--- 954,964 ----
  int
  mpacpi_find_interrupts(void *self)
  {
+ #if NIOAPIC > 0
  	ACPI_OBJECT_LIST arglist;
  	ACPI_OBJECT arg;
  	ACPI_STATUS rv;
+ #endif
  	struct acpi_softc *acpi = self;
  	int i;
  
***************
*** 864,889 ****
  		return 0;
  #endif
  
! 	if (mpacpi_nioapic == 0)
! 		return 0;
! 
! 	/*
! 	 * Switch us into APIC mode by evaluating _PIC(1).
! 	 * Needs to be done now, since it has an effect on
! 	 * the interrupt information we're about to retrieve.
! 	 */
! 	arglist.Count = 1;
! 	arglist.Pointer = &arg;
! 	arg.Type = ACPI_TYPE_INTEGER;
! 	arg.Integer.Value = 1;	/* I/O APIC mode (0 = PIC, 2 = IOSAPIC) */
! 	rv = AcpiEvaluateObject(NULL, "\\_PIC", &arglist, NULL);
! 	if (ACPI_FAILURE(rv)) {
! 		if (mp_verbose)
! 			printf("mpacpi: switch to APIC mode failed\n");
! 		return 0;
  	}
  
  #if NPCI > 0
  	mpacpi_find_pcibusses(acpi);
  	if (mp_verbose)
  		printf("mpacpi: %d PCI busses\n", mpacpi_npci);
--- 972,999 ----
  		return 0;
  #endif
  
! #if NIOAPIC > 0
! 	if (mpacpi_nioapic != 0) {
! 		/*
! 		 * Switch us into APIC mode by evaluating _PIC(1).
! 		 * Needs to be done now, since it has an effect on
! 		 * the interrupt information we're about to retrieve.
! 		 */
! 		arglist.Count = 1;
! 		arglist.Pointer = &arg;
! 		arg.Type = ACPI_TYPE_INTEGER;
! 		arg.Integer.Value = 1;	/* I/O APIC (0 = PIC, 2 = IOSAPIC) */
! 		rv = AcpiEvaluateObject(NULL, "\\_PIC", &arglist, NULL);
! 		if (ACPI_FAILURE(rv)) {
! 			if (mp_verbose)
! 				printf("mpacpi: switch to APIC mode failed\n");
! 			return 0;
! 		}
  	}
+ #endif
  
  #if NPCI > 0
+ 	mpacpi_user_continue("finding PCI busses ");
  	mpacpi_find_pcibusses(acpi);
  	if (mp_verbose)
  		printf("mpacpi: %d PCI busses\n", mpacpi_npci);
***************
*** 904,910 ****
  	struct mp_bus *mpb;
  
  #ifdef MPBIOS
! 	if (mpbios_scanned != 0 || mpacpi_nioapic == 0)
  		return ENOENT;
  #endif
  
--- 1014,1020 ----
  	struct mp_bus *mpb;
  
  #ifdef MPBIOS
! 	if (mpbios_scanned != 0)
  		return ENOENT;
  #endif
  
***************
*** 919,926 ****
  	 *  mp_busses[0 .. mpacpi_maxpci] : PCI
  	 *  mp_busses[mpacpi_maxpci + BUS_BUFFER] : ISA
  	 */
! 	if (pba->pba_bus >= mp_isa_bus)
! 		panic("Increase BUS_BUFFER in mpacpi.c!");
  
  	mpb = &mp_busses[pba->pba_bus];
  	if (mpb->mb_name != NULL) {
--- 1029,1038 ----
  	 *  mp_busses[0 .. mpacpi_maxpci] : PCI
  	 *  mp_busses[mpacpi_maxpci + BUS_BUFFER] : ISA
  	 */
! 	if (pba->pba_bus >= mp_isa_bus) {
! 		intr_add_pcibus(pba);
! 		return 0;
! 	}
  
  	mpb = &mp_busses[pba->pba_bus];
  	if (mpb->mb_name != NULL) {
***************
*** 938,943 ****
--- 1050,1060 ----
  	mpb->mb_pci_bridge_tag = pba->pba_bridgetag;
  	mpb->mb_pci_chipset_tag = pba->pba_pc;
  
+ 	if (mp_verbose)
+ 		printf("%s: added to list as bus %d\n", parent->dv_xname,
+ 		    pba->pba_bus);
+ 
+ 
  	if (pba->pba_bus > mpacpi_maxpci)
  		mpacpi_maxpci = pba->pba_bus;
  
***************
*** 965,967 ****
--- 1082,1148 ----
  }
  
  #endif
+ 
+ int
+ mpacpi_findintr_linkdev(struct mp_intr_map *mip)
+ {
+ 	int irq, line, pol, trig;
+ 	struct pic *pic;
+ 	int pin;
+ 
+ 	if (mip->linkdev == NULL)
+ 		return ENOENT;
+ 
+ 	irq = acpi_pci_link_route_interrupt(mip->linkdev, mip->sourceindex,
+ 	    &line, &pol, &trig);
+ 	if (mp_verbose)
+ 		printf("linkdev %s returned ACPI global int %d\n",
+ 		    acpi_pci_link_name(mip->linkdev), line);
+ 	if (irq == X86_PCI_INTERRUPT_LINE_NO_CONNECTION)
+ 		return ENOENT;
+ 	if (irq != line)
+ 		panic("mpacpi_findintr_linkdev: irq mismatch");
+ 		
+ 	mip->flags = pol | (trig << 2);
+ 	mip->global_int = irq;
+ 	pic = intr_findpic(irq);
+ 	if (pic == NULL)
+ 		return ENOENT;
+ 	mip->ioapic = pic;
+ 	pin = irq - pic->pic_vecbase;
+ 
+ 	if (pic->pic_type == PIC_IOAPIC) {
+ #if NIOAPIC > 0
+ 		mip->redir = (IOAPIC_REDLO_DEL_FIXED<<IOAPIC_REDLO_DEL_SHIFT);
+ 		if (pol ==  MPS_INTPO_ACTLO)
+ 			mip->redir |= IOAPIC_REDLO_ACTLO;
+ 		if (trig ==  MPS_INTTR_LEVEL)
+ 			mip->redir |= IOAPIC_REDLO_LEVEL;
+ 		mip->ioapic_ih = APIC_INT_VIA_APIC |
+ 		    (pic->pic_apicid << APIC_INT_APIC_SHIFT) |
+ 		    (pin << APIC_INT_PIN_SHIFT);
+ 		((struct ioapic_softc *)pic)->sc_pins[pin].ip_map = mip;
+ 		mip->ioapic_pin = pin;
+ #else
+ 		return ENOENT;
+ #endif
+ 	} else
+ 		mip->ioapic_ih = pin;
+ 	return 0;
+ }
+ 
+ static void
+ mpacpi_user_continue(const char *fmt, ...)
+ {
+ 	va_list ap;
+ 
+ 	if (!mpacpi_step)
+ 		return;
+ 
+ 	printf("mpacpi: ");
+ 	va_start(ap, fmt);
+ 	vprintf(fmt, ap);
+ 	va_end(ap);
+ 	printf("<press any key to continue>\n>");
+ 	cngetc();
+ }
Index: arch/x86/x86/mpbios.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/mpbios.c,v
retrieving revision 1.27
diff -c -r1.27 mpbios.c
*** arch/x86/x86/mpbios.c	11 Dec 2005 12:19:47 -0000	1.27
--- arch/x86/x86/mpbios.c	22 Mar 2006 23:25:23 -0000
***************
*** 137,142 ****
--- 137,145 ----
  extern int mpacpi_nioapic;
  #endif
  
+ int mpbios_ncpu;
+ int mpbios_nioapic;
+ 
  #include "pci.h"
  
  #if NPCI > 0
***************
*** 500,507 ****
   *	nintrs
   */
  void
! mpbios_scan(self)
! 	struct device *self;
  {
  	const uint8_t 	*position, *end;
  	int		count;
--- 503,509 ----
   *	nintrs
   */
  void
! mpbios_scan(struct device *self, int *ncpu, int *napic)
  {
  	const uint8_t 	*position, *end;
  	int		count;
***************
*** 690,695 ****
--- 692,700 ----
  		mpbios_unmap (&mp_cfg_table_map);
  	}
  	mpbios_scanned = 1;
+ 
+ 	*ncpu = mpbios_ncpu;
+ 	*napic = mpbios_nioapic;
  }
  
  static void
***************
*** 705,710 ****
--- 710,717 ----
  	if (!(entry->cpu_flags & PROCENTRY_FLAG_EN))
  		return;
  
+ 	mpbios_ncpu++;
+ 
  	/* check for BSP flag */
  	if (entry->cpu_flags & PROCENTRY_FLAG_BP)
  		caa.cpu_role = CPU_ROLE_BP;
***************
*** 1016,1021 ****
--- 1023,1030 ----
  	if (!(entry->apic_flags & IOAPICENTRY_FLAG_EN))
  		return;
  
+ 	mpbios_nioapic++;
+ 
  	aaa.aaa_name   = "ioapic";
  	aaa.apic_id = entry->apic_id;
  	aaa.apic_version = entry->apic_version;
***************
*** 1099,1105 ****
  		 * number.
  		 */
  		if (pin >= sc->sc_apic_sz) {
! 			sc2 = ioapic_find_bybase(pin);
  			if (sc2 != sc) {
  				printf("mpbios: bad pin %d for apic %d\n",
  				    pin, id);
--- 1108,1114 ----
  		 * number.
  		 */
  		if (pin >= sc->sc_apic_sz) {
! 			sc2 = (struct ioapic_softc *)intr_findpic(pin);
  			if (sc2 != sc) {
  				printf("mpbios: bad pin %d for apic %d\n",
  				    pin, id);
***************
*** 1110,1116 ****
  			pin -= sc->sc_apic_vecbase;
  		}
  
! 		mpi->ioapic = sc;
  		mpi->ioapic_pin = pin;
  
  		altmpi = sc->sc_pins[pin].ip_map;
--- 1119,1125 ----
  			pin -= sc->sc_apic_vecbase;
  		}
  
! 		mpi->ioapic = (struct pic *)sc;
  		mpi->ioapic_pin = pin;
  
  		altmpi = sc->sc_pins[pin].ip_map;
***************
*** 1167,1173 ****
  	if (mpbios_scanned == 0)
  		return ENOENT;
  
! 	if (pba->pba_bus >= mp_nbus) {
  		intr_add_pcibus(pba);
  		return 0;
  	}
--- 1176,1182 ----
  	if (mpbios_scanned == 0)
  		return ENOENT;
  
! 	if (pba->pba_bus >= mp_isa_bus) {
  		intr_add_pcibus(pba);
  		return 0;
  	}
***************
*** 1179,1184 ****
--- 1188,1197 ----
  	} else
  		mpb->mb_name = "pci";
  
+ 	if (mp_verbose)
+ 		printf("%s: added to list as bus %d\n", parent->dv_xname,
+ 		    pba->pba_bus);
+ 
  	mpb->mb_configured = 1;
  	mpb->mb_pci_bridge_tag = pba->pba_bridgetag;
  	mpb->mb_pci_chipset_tag = pba->pba_pc;
Index: dev/acpi/acpi.c
===================================================================
RCS file: /cvsroot/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.85
diff -c -r1.85 acpi.c
*** dev/acpi/acpi.c	26 Feb 2006 18:46:04 -0000	1.85
--- dev/acpi/acpi.c	22 Mar 2006 23:25:24 -0000
***************
*** 136,141 ****
--- 136,142 ----
   * subsystems that ACPI supercedes) when ACPI is active.
   */
  int	acpi_active;
+ int	acpi_force_load;
  
  /*
   * Pointer to the ACPI subsystem's state.  There can be only
***************
*** 164,172 ****
  static ACPI_STATUS	acpi_make_devnode(ACPI_HANDLE, UINT32, void *, void **);
  
  static void		acpi_enable_fixed_events(struct acpi_softc *);
- #ifdef PCI_INTR_FIXUP
- void			acpi_pci_fixup(struct acpi_softc *);
- #endif
  #if defined(PCI_INTR_FIXUP) || defined(ACPI_ACTIVATE_DEV)
  static ACPI_STATUS	acpi_allocate_resources(ACPI_HANDLE handle);
  #endif
--- 165,170 ----
***************
*** 220,225 ****
--- 218,236 ----
  		return 0;
  	}
  
+ 
+ 	if (!acpi_force_load && (acpi_find_quirks() & ACPI_QUIRK_BROKEN)) {
+ 		printf("ACPI: BIOS implementation in listed as broken:\n");
+ 		printf("ACPI: X/RSDT: OemId <%6.6s,%8.8s,%08x>, "
+ 		       "AslId <%4.4s,%08x>\n",
+ 			AcpiGbl_XSDT->OemId, AcpiGbl_XSDT->OemTableId,
+ 		        AcpiGbl_XSDT->OemRevision,
+ 			AcpiGbl_XSDT->AslCompilerId,
+ 		        AcpiGbl_XSDT->AslCompilerRevision);
+ 		printf("ACPI: not used. set acpi_force_load to use anyway.\n");
+ 		return 0;
+ 	}
+ 
  	/*
  	 * Looks like we have ACPI!
  	 */
***************
*** 350,363 ****
  	acpi_enable_fixed_events(sc);
  
  	/*
- 	 * Fix up PCI devices.
- 	 */
- #ifdef PCI_INTR_FIXUP
- 	if ((sc->sc_quirks & (ACPI_QUIRK_BADPCI | ACPI_QUIRK_BADIRQ)) == 0)
- 		acpi_pci_fixup(sc);
- #endif
- 
- 	/*
  	 * Scan the namespace and build our device tree.
  	 */
  #ifdef ACPI_DEBUGGER
--- 361,366 ----
***************
*** 1097,1293 ****
  	return ret;
  }
  
! #ifdef PCI_INTR_FIXUP
! ACPI_STATUS acpi_pci_fixup_bus(ACPI_HANDLE, UINT32, void *, void **);
! /*
!  * acpi_pci_fixup:
!  *
!  *	Set up PCI devices that BIOS didn't handle right.
!  *	Iterate through all devices and try to get the _PTR
!  *	(PCI Routing Table).  If it exists then make sure all
!  *	interrupt links that it uses are working.
!  */
! void
! acpi_pci_fixup(struct acpi_softc *sc)
! {
! 	ACPI_HANDLE parent;
! 	ACPI_STATUS rv;
! 
! #ifdef ACPI_DEBUG
! 	printf("acpi_pci_fixup starts:\n");
! #endif
! 	rv = AcpiGetHandle(ACPI_ROOT_OBJECT, "\\_SB_", &parent);
! 	if (ACPI_FAILURE(rv))
! 		return;
! 	sc->sc_pci_bus = 0;
! 	AcpiWalkNamespace(ACPI_TYPE_DEVICE, parent, 100,
! 	    acpi_pci_fixup_bus, sc, NULL);
! }
! 
! static uint
! acpi_get_intr(ACPI_HANDLE handle)
! {
! 	ACPI_BUFFER ret;
! 	ACPI_STATUS rv;
! 	ACPI_RESOURCE *res;
! 	ACPI_RESOURCE_IRQ *irq;
! 	uint intr;
! 
! 	intr = -1;
! 	rv = acpi_get(handle, &ret, AcpiGetCurrentResources);
! 	if (ACPI_FAILURE(rv))
! 		return intr;
! 	for (res = ret.Pointer; res->Type != ACPI_RESOURCE_TYPE_END_TAG;
! 	     res = ACPI_NEXT_RESOURCE(res)) {
! 		if (res->Type == ACPI_RESOURCE_TYPE_IRQ) {
! 			irq = (ACPI_RESOURCE_IRQ *)&res->Data;
! 			if (irq->InterruptCount == 1)
! 				intr = irq->Interrupts[0];
! 			break;
! 		}
! 	}
! 	AcpiOsFree(ret.Pointer);
! 	return intr;
! }
! 
! static void
! acpi_pci_set_line(int bus, int dev, int pin, int line)
! {
! 	ACPI_STATUS err;
! 	ACPI_PCI_ID pid;
! 	UINT32 intr, id, bhlc;
! 	int func, nfunc;
! 
! 	pid.Bus = bus;
! 	pid.Device = dev;
! 	pid.Function = 0;
! 
! 	err = AcpiOsReadPciConfiguration(&pid, PCI_BHLC_REG, &bhlc, 32);
! 	if (err)
! 		return;
! 	if (PCI_HDRTYPE_MULTIFN(bhlc))
! 		nfunc = 8;
! 	else
! 		nfunc = 1;
! 
! 	for (func = 0; func < nfunc; func++) {
! 		pid.Function = func;
! 
! 		err = AcpiOsReadPciConfiguration(&pid, PCI_ID_REG, &id, 32);
! 		if (err || PCI_VENDOR(id) == PCI_VENDOR_INVALID ||
! 		    PCI_VENDOR(id) == 0)
! 			continue;
! 
! 		err = AcpiOsReadPciConfiguration(&pid, PCI_INTERRUPT_REG,
! 			  &intr, 32);
! 		if (err) {
! 			printf("AcpiOsReadPciConfiguration failed %d\n", err);
! 			return;
! 		}
! 		if (pin == PCI_INTERRUPT_PIN(intr) &&
! 		    line != PCI_INTERRUPT_LINE(intr)) {
! #ifdef ACPI_DEBUG
! 			printf("acpi fixup pci intr: %d:%d:%d %c: %d -> %d\n",
! 			       bus, dev, func,
! 			       pin + '@', PCI_INTERRUPT_LINE(intr),
! 			       line);
! #endif
! 			intr &= ~(PCI_INTERRUPT_LINE_MASK <<
! 				  PCI_INTERRUPT_LINE_SHIFT);
! 			intr |= line << PCI_INTERRUPT_LINE_SHIFT;
! 			err = AcpiOsWritePciConfiguration(&pid,
! 				  PCI_INTERRUPT_REG, intr, 32);
! 			if (err) {
! 				printf("AcpiOsWritePciConfiguration failed"
! 				       " %d\n", err);
! 				return;
! 			}
! 		}
! 	}
! }
! 
! ACPI_STATUS
! acpi_pci_fixup_bus(ACPI_HANDLE handle, UINT32 level, void *context,
! 		   void **status)
! {
! 	struct acpi_softc *sc = context;
! 	ACPI_STATUS rv;
! 	ACPI_BUFFER buf;
! 	UINT8 *Buffer;
! 	ACPI_PCI_ROUTING_TABLE *PrtElement;
! 	ACPI_HANDLE link;
! 	uint line;
! 	ACPI_INTEGER val;
! 
! 	rv = acpi_get(handle, &buf, AcpiGetIrqRoutingTable);
! 	if (ACPI_FAILURE(rv))
! 		return AE_OK;
! 
! 	/*
! 	 * If at level 1, this is a PCI root bus. Try the _BBN method
! 	 * to get the right PCI bus numbering for the following
! 	 * busses (this is a depth-first walk). It may fail,
! 	 * for example if there's only one root bus, but that
! 	 * case should be ok, so we'll ignore that.
! 	 */
! 	if (level == 1) {
! 		rv = acpi_eval_integer(handle, METHOD_NAME__BBN, &val);
! 		if (!ACPI_FAILURE(rv)) {
! #ifdef ACPI_DEBUG
! 			printf("%s: fixup: _BBN success, bus # was %d now %d\n",
! 			    sc->sc_dev.dv_xname, sc->sc_pci_bus,
! 			    ACPI_LOWORD(val));
! #endif
! 			sc->sc_pci_bus = ACPI_LOWORD(val);
! 		}
! 	}
! 
! 
! #ifdef ACPI_DEBUG
! 	printf("%s: fixing up PCI bus %d at level %u\n", sc->sc_dev.dv_xname,
! 	    sc->sc_pci_bus, level);
! #endif
! 
!         for (Buffer = buf.Pointer; ; Buffer += PrtElement->Length) {
! 		PrtElement = (ACPI_PCI_ROUTING_TABLE *)Buffer;
! 		if (PrtElement->Length == 0)
! 			break;
! 		if (PrtElement->Source[0] == 0)
! 			continue;
! 
! 		rv = AcpiGetHandle(NULL, PrtElement->Source, &link);
! 		if (ACPI_FAILURE(rv))
! 			continue;
! 		line = acpi_get_intr(link);
! 		if (line == (uint)-1 || line == 0) {
! 			printf("%s: fixing up intr link %s\n",
! 			    sc->sc_dev.dv_xname, PrtElement->Source);
! 			rv = acpi_allocate_resources(link);
! 			if (ACPI_FAILURE(rv)) {
! 				printf("%s: interrupt allocation failed %s\n",
! 				    sc->sc_dev.dv_xname, PrtElement->Source);
! 				continue;
! 			}
! 			line = acpi_get_intr(link);
! 			if (line == (uint)-1) {
! 				printf("%s: get intr failed %s\n",
! 				    sc->sc_dev.dv_xname, PrtElement->Source);
! 				continue;
! 			}
! 		}
! 
! 		acpi_pci_set_line(sc->sc_pci_bus, PrtElement->Address >> 16,
! 		    PrtElement->Pin + 1, line);
! 	}
! 
! 	sc->sc_pci_bus++;
! 
! 	AcpiOsFree(buf.Pointer);
! 	return AE_OK;
! }
! #endif /* PCI_INTR_FIXUP */
! 
! #if defined(PCI_INTR_FIXUP) || defined(ACPI_ACTIVATE_DEV)
  /* XXX This very incomplete */
  static ACPI_STATUS
  acpi_allocate_resources(ACPI_HANDLE handle)
--- 1100,1106 ----
  	return ret;
  }
  
! #if defined(ACPI_ACTIVATE_DEV)
  /* XXX This very incomplete */
  static ACPI_STATUS
  acpi_allocate_resources(ACPI_HANDLE handle)
***************
*** 1372,1378 ****
  out:
  	return rv;
  }
! #endif /* PCI_INTR_FIXUP || ACPI_ACTIVATE_DEV */
  
  SYSCTL_SETUP(sysctl_acpi_setup, "sysctl hw.acpi subtree setup")
  {
--- 1185,1191 ----
  out:
  	return rv;
  }
! #endif /* ACPI_ACTIVATE_DEV */
  
  SYSCTL_SETUP(sysctl_acpi_setup, "sysctl hw.acpi subtree setup")
  {
Index: dev/acpi/acpi_quirks.c
===================================================================
RCS file: /cvsroot/src/sys/dev/acpi/acpi_quirks.c,v
retrieving revision 1.6
diff -c -r1.6 acpi_quirks.c
*** dev/acpi/acpi_quirks.c	11 Dec 2005 12:21:02 -0000	1.6
--- dev/acpi/acpi_quirks.c	22 Mar 2006 23:25:24 -0000
***************
*** 52,71 ****
  #include <dev/acpi/acpireg.h>
  #include <dev/acpi/acpivar.h>
  
  static struct acpi_quirk acpi_quirks[] = {
! 	/*
! 	 * This implementation seems to be in widespread use, but
! 	 * unfortunately, on some systems, it constructs a PCI hierarchy
! 	 * that doesn't match reality at all (like on SuperMicro boards).
! 	 */
! 	{ "PTLTD ", 0x06040000, ACPI_QUIRK_BADPCI | ACPI_QUIRK_BADIRQ },
! 	/*
! 	 * This is on my Appro 1224 Xi. It does not find all the busses
! 	 * in the ACPI tables.
! 	 */
! 	{ "A M I ", 0x02000304, ACPI_QUIRK_BADPCI | ACPI_QUIRK_BADIRQ },
  };
  
  /*
   * Simple function to search the quirk table. Only to be used after
   * AcpiLoadTables has been successfully called.
--- 52,100 ----
  #include <dev/acpi/acpireg.h>
  #include <dev/acpi/acpivar.h>
  
+ static int acpi_rev_cmp(uint32_t, uint32_t, int);
+ 
+ /*
+  * XXX add more
+  */
  static struct acpi_quirk acpi_quirks[] = {
! 	{ ACPI_TABLE_FADT, "PTLTD ", 0x06040000, AQ_LTE, "  FACP  ",
! 	  ACPI_QUIRK_BROKEN },
  };
  
+ static int
+ acpi_rev_cmp(uint32_t tabval, uint32_t wanted, int op)
+ {
+ 	switch (op) {
+ 	case AQ_GT:
+ 		if (tabval > wanted)
+ 			return 0;
+ 		else
+ 			return 1;
+ 	case AQ_LT:
+ 		if (tabval < wanted)
+ 			return 0;
+ 		else
+ 			return 1;
+ 	case AQ_LTE:
+ 		if (tabval <= wanted)
+ 			return 0;
+ 		else
+ 			return 1;
+ 	case AQ_GTE:
+ 		if (tabval >= wanted)
+ 			return 0;
+ 		else
+ 			return 1;
+ 	case AQ_EQ:
+ 		if (tabval == wanted)
+ 			return 0;
+ 		else
+ 			return 1;
+ 	}
+ 	return 1;
+ }
+ 
  /*
   * Simple function to search the quirk table. Only to be used after
   * AcpiLoadTables has been successfully called.
***************
*** 75,88 ****
  {
  	int i, nquirks;
  	struct acpi_quirk *aqp;
  
  	nquirks = sizeof(acpi_quirks) / sizeof(struct acpi_quirk);
  
  	for (i = 0; i < nquirks; i++) {
  		aqp = &acpi_quirks[i];
! 		if (!strncmp(aqp->aq_oemid, AcpiGbl_XSDT->OemId, strlen(aqp->aq_oemid)) &&
! 		    aqp->aq_oemrev == AcpiGbl_XSDT->OemRevision)
! 			return aqp->aq_quirks;
  	}
  	return 0;
  }
--- 104,138 ----
  {
  	int i, nquirks;
  	struct acpi_quirk *aqp;
+ 	ACPI_TABLE_HEADER *hdr;
  
  	nquirks = sizeof(acpi_quirks) / sizeof(struct acpi_quirk);
  
  	for (i = 0; i < nquirks; i++) {
  		aqp = &acpi_quirks[i];
! 		/* XXX AcpiGetTableHeader doesn't work for some reason */
! 		switch (aqp->aq_tabletype) {
! 		case ACPI_TABLE_DSDT:
! 			hdr = (ACPI_TABLE_HEADER *)AcpiGbl_DSDT;
! 			break;
! 		case ACPI_TABLE_XSDT:
! 			hdr = (ACPI_TABLE_HEADER *)AcpiGbl_XSDT;
! 			break;
! 		case ACPI_TABLE_FADT:
! 			hdr = (ACPI_TABLE_HEADER *)AcpiGbl_FADT;
! 			break;
! 		default:
! 			continue;
! 		}
! 		if (strncmp(aqp->aq_oemid, hdr->OemId, strlen(aqp->aq_oemid)))
! 			continue;
! 		if (acpi_rev_cmp(aqp->aq_oemrev, hdr->OemRevision,
! 		    aqp->aq_cmpop))
! 			continue;
! 		if (strncmp(aqp->aq_tabid, hdr->OemTableId,
! 		    strlen(aqp->aq_tabid)))
! 			continue;
! 		return aqp->aq_quirks;
  	}
  	return 0;
  }
Index: dev/acpi/acpivar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/acpi/acpivar.h,v
retrieving revision 1.25
diff -c -r1.25 acpivar.h
*** dev/acpi/acpivar.h	12 Dec 2005 15:04:50 -0000	1.25
--- dev/acpi/acpivar.h	22 Mar 2006 23:25:24 -0000
***************
*** 276,284 ****
--- 276,295 ----
  		    void *, const struct acpi_resource_parse_ops *);
  void		acpi_resource_print(struct device *, struct acpi_resources *);
  void		acpi_resource_cleanup(struct acpi_resources *);
+ ACPI_STATUS	acpi_allocate_resources(ACPI_HANDLE);
  
  ACPI_STATUS	acpi_pwr_switch_consumer(ACPI_HANDLE, int);
  
+ void *		acpi_pci_link_devbyhandle(ACPI_HANDLE);
+ void		acpi_pci_link_add_reference(void *, int, int, int, int);
+ int		acpi_pci_link_route_interrupt(void *, int, int *, int *, int *);
+ char *		acpi_pci_link_name(void *);
+ ACPI_HANDLE	acpi_pci_link_handle(void *);
+ void		acpi_pci_link_state(void);
+ 
+ 
+ 
+ 
  #if defined(_KERNEL_OPT)
  #include "acpiec.h"
  
***************
*** 305,316 ****
   * quirk handling
   */
  struct acpi_quirk {
! 	const char *aq_oemid;	/* compared against the X/RSDT OemId */
! 	int aq_oemrev;		/* compared against the X/RSDT OemRev */
  	int aq_quirks;		/* the actual quirks */
  };
  
! #define ACPI_QUIRK_BADPCI	0x00000001	/* bad PCI hierarchy */
! #define ACPI_QUIRK_BADIRQ	0x00000002	/* bad IRQ information */
  
  int acpi_find_quirks(void);
--- 316,337 ----
   * quirk handling
   */
  struct acpi_quirk {
! 	uint32_t aq_tabletype;	/* what type of table (FADT, DSDT, etc) */
! 	const char *aq_oemid;	/* compared against the table OemId */
! 	int aq_oemrev;		/* compared against the table OemRev */
! 	int aq_cmpop;		/* how to compare the oemrev number */
! 	const char *aq_tabid;	/* compared against the table TableId */
  	int aq_quirks;		/* the actual quirks */
  };
  
! #define AQ_GT		0	/* > */
! #define AQ_LT		1	/* < */
! #define AQ_GTE		2	/* >= */
! #define AQ_LTE		3	/* <= */
! #define AQ_EQ		4	/* == */
! 
! #define ACPI_QUIRK_BROKEN	0x00000001	/* totally broken */
! #define ACPI_QUIRK_BADPCI	0x00000002	/* bad PCI hierarchy */
! #define ACPI_QUIRK_BADBBN	0x00000004	/* _BBN broken */
  
  int acpi_find_quirks(void);
Index: dev/acpi/files.acpi
===================================================================
RCS file: /cvsroot/src/sys/dev/acpi/files.acpi,v
retrieving revision 1.35
diff -c -r1.35 files.acpi
*** dev/acpi/files.acpi	31 Jan 2006 09:30:06 -0000	1.35
--- dev/acpi/files.acpi	22 Mar 2006 23:25:24 -0000
***************
*** 11,16 ****
--- 11,17 ----
  file	dev/acpi/acpi_resource.c	acpi
  file	dev/acpi/acpi_powerres.c	acpi
  file	dev/acpi/acpi_madt.c		acpi & mpacpi
+ file	dev/acpi/acpi_pci_link.c	acpi & mpacpi
  file	dev/acpi/acpi_quirks.c		acpi
  
  # ACPI Embedded Controller
Index: dev/pci/pccbb.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/pccbb.c,v
retrieving revision 1.127
diff -c -r1.127 pccbb.c
*** dev/pci/pccbb.c	18 Dec 2005 11:04:00 -0000	1.127
--- dev/pci/pccbb.c	22 Mar 2006 23:25:25 -0000
***************
*** 80,85 ****
--- 80,86 ----
  
  #if defined(__i386__)
  #include "ioapic.h"
+ #include "opt_mpacpi.h"
  #endif
  
  #ifndef __NetBSD_Version__
***************
*** 525,533 ****
  	 * may well be zero, with the interrupt routed through the apic.
  	 */
  
! #if NIOAPIC > 0
! 	printf("%s: using ioapic for interrupt\n", sc->sc_dev.dv_xname);
! #else
  	if ((0 == pa->pa_intrline) || (255 == pa->pa_intrline)) {
      		printf("%s: NOT USED because of unconfigured interrupt\n",
  		    sc->sc_dev.dv_xname);
--- 526,532 ----
  	 * may well be zero, with the interrupt routed through the apic.
  	 */
  
! #if NIOAPIC == 0 && !defined(MPACPI)
  	if ((0 == pa->pa_intrline) || (255 == pa->pa_intrline)) {
      		printf("%s: NOT USED because of unconfigured interrupt\n",
  		    sc->sc_dev.dv_xname);
