summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2006-07-04 00:30:21 +0000
committerchristos <christos@NetBSD.org>2006-07-04 00:30:21 +0000
commit01158ea892acbf260b6ecbef4947155d650651a5 (patch)
tree2a9c348572d8ebfbcfe87d297cdd4b092b38d726 /sys
parent8fed18e20052f24107bd2870c271f6ec1dbd16f1 (diff)
Apply fvdl's acpi pci interrupt configuration code.
- MPACPI is no more. - MPACPI_SCANPCI -> ACPI_SCANPCI
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/amd64/amd64/mainbus.c29
-rw-r--r--sys/arch/amd64/conf/GENERIC8
-rw-r--r--sys/arch/amd64/conf/GENERIC_ACPI3
-rw-r--r--sys/arch/amd64/conf/INSTALL_ACPI3
-rw-r--r--sys/arch/i386/conf/GENERIC8
-rw-r--r--sys/arch/i386/conf/GENERIC.MP4
-rw-r--r--sys/arch/i386/conf/GENERIC.MPACPI4
-rw-r--r--sys/arch/i386/conf/INSTALL.MP4
-rw-r--r--sys/arch/i386/conf/VIRTUALPC8
-rw-r--r--sys/arch/i386/i386/mainbus.c26
-rw-r--r--sys/arch/x86/conf/files.x865
-rw-r--r--sys/arch/x86/include/intr.h3
-rw-r--r--sys/arch/x86/include/mpacpi.h7
-rw-r--r--sys/arch/x86/include/mpbiosvar.h4
-rw-r--r--sys/arch/x86/include/mpconfig.h6
-rw-r--r--sys/arch/x86/include/pic.h4
-rw-r--r--sys/arch/x86/pci/pci_intr_machdep.c29
-rw-r--r--sys/arch/x86/pci/pci_machdep.c13
-rw-r--r--sys/arch/x86/x86/acpi_machdep.c21
-rw-r--r--sys/arch/x86/x86/i8259.c6
-rw-r--r--sys/arch/x86/x86/intr.c40
-rw-r--r--sys/arch/x86/x86/ioapic.c33
-rw-r--r--sys/arch/x86/x86/mpacpi.c342
-rw-r--r--sys/arch/x86/x86/mpbios.c44
-rw-r--r--sys/dev/acpi/acpi.c249
-rw-r--r--sys/dev/acpi/acpi_pci_link.c1189
-rw-r--r--sys/dev/acpi/acpi_quirks.c82
-rw-r--r--sys/dev/acpi/acpivar.h31
-rw-r--r--sys/dev/acpi/files.acpi8
-rw-r--r--sys/dev/pci/pccbb.c9
30 files changed, 1778 insertions, 444 deletions
diff --git a/sys/arch/amd64/amd64/mainbus.c b/sys/arch/amd64/amd64/mainbus.c
index 2a3f4df484e..39a566fd80b 100644
--- a/sys/arch/amd64/amd64/mainbus.c
+++ b/sys/arch/amd64/amd64/mainbus.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.c,v 1.11 2006/02/16 10:56:58 kochi Exp $ */
+/* $NetBSD: mainbus.c,v 1.12 2006/07/04 00:30:21 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.11 2006/02/16 10:56:58 kochi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.12 2006/07/04 00:30:21 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -49,7 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.11 2006/02/16 10:56:58 kochi Exp $");
#include "isadma.h"
#include "acpi.h"
-#include "opt_mpacpi.h"
+#include "opt_acpi.h"
#include "opt_mpbios.h"
#include <machine/cpuvar.h>
@@ -99,7 +99,7 @@ struct isabus_attach_args mba_iba = {
};
#endif
-#if defined(MPBIOS) || defined(MPACPI)
+#if defined(MPBIOS) || NACPI > 0
struct mp_bus *mp_busses;
int mp_nbus;
struct mp_intr_map *mp_intrs;
@@ -146,7 +146,13 @@ mainbus_attach(parent, self, aux)
#ifdef MPBIOS
int mpbios_present = 0;
#endif
+#if NACPI > 0
int mpacpi_active = 0;
+#endif
+ int numcpus = 0;
+#if NACPI > 0 || defined(MPBIOS)
+ int numioapics = 0;
+#endif
printf("\n");
@@ -160,24 +166,22 @@ mainbus_attach(parent, self, aux)
#if NACPI > 0
acpi_present = acpi_probe();
-#ifdef MPACPI
/*
* First, see if the MADT contains CPUs, and possibly I/O APICs.
* Building the interrupt routing structures can only
* be done later (via a callback).
*/
if (acpi_present)
- mpacpi_active = mpacpi_scan_apics(self);
-#endif
+ mpacpi_active = mpacpi_scan_apics(self, &numcpus, &numioapics);
#endif
if (!mpacpi_active) {
#ifdef MPBIOS
if (mpbios_present)
- mpbios_scan(self);
+ mpbios_scan(self, &numcpus, &numioapics);
else
#endif
- {
+ if (numcpus == 0) {
struct cpu_attach_args caa;
memset(&caa, 0, sizeof(caa));
@@ -223,7 +227,7 @@ mainbus_attach(parent, self, aux)
mba.mba_pba.pba_flags = pci_bus_flags();
mba.mba_pba.pba_bus = 0;
mba.mba_pba.pba_bridgetag = NULL;
-#if defined(MPACPI) && defined(MPACPI_SCANPCI)
+#if NACPI > 0 && defined(ACPI_SCANPCI)
if (mpacpi_active)
mpacpi_scan_pci(self, &mba.mba_pba, pcibusprint);
else
@@ -235,6 +239,11 @@ mainbus_attach(parent, self, aux)
#endif
config_found_ia(self, "pcibus", &mba.mba_pba, pcibusprint);
+#if NACPI > 0
+ if (mp_verbose)
+ acpi_pci_link_state();
+#endif
+
}
#endif
diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC
index 620045e9f07..54a52e90ca6 100644
--- a/sys/arch/amd64/conf/GENERIC
+++ b/sys/arch/amd64/conf/GENERIC
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.96 2006/07/01 19:55:32 xtraeme Exp $
+# $NetBSD: GENERIC,v 1.97 2006/07/04 00:30:22 christos Exp $
#
# GENERIC machine description file
#
@@ -22,7 +22,7 @@ include "arch/amd64/conf/std.amd64"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "GENERIC-$Revision: 1.96 $"
+#ident "GENERIC-$Revision: 1.97 $"
maxusers 32 # estimated number of users
@@ -228,9 +228,7 @@ config netbsd root on ? type ?
mainbus0 at root
#acpi0 at mainbus0
-#options MPACPI # configure CPUs and APICs using ACPI
- # (acpi at mainbus must also be enabled)
-#options MPACPI_SCANPCI # find PCI roots using MPACPI
+#options ACPI_SCANPCI # find PCI roots using ACPI
options MPBIOS # configure CPUs and APICs using MPBIOS
options MPBIOS_SCANPCI # MPBIOS configures PCI roots
#options PCI_INTR_FIXUP # PCI interrupt routing via ACPI
diff --git a/sys/arch/amd64/conf/GENERIC_ACPI b/sys/arch/amd64/conf/GENERIC_ACPI
index 1e54ea84fc9..4f1c2430caf 100644
--- a/sys/arch/amd64/conf/GENERIC_ACPI
+++ b/sys/arch/amd64/conf/GENERIC_ACPI
@@ -1,9 +1,8 @@
-# $NetBSD: GENERIC_ACPI,v 1.1 2005/12/30 11:27:07 rjs Exp $
+# $NetBSD: GENERIC_ACPI,v 1.2 2006/07/04 00:30:22 christos Exp $
#
# GENERIC_ACPI machine description file
include "arch/amd64/conf/GENERIC"
no options MPBIOS_SCANPCI
-options MPACPI
acpi0 at mainbus0
diff --git a/sys/arch/amd64/conf/INSTALL_ACPI b/sys/arch/amd64/conf/INSTALL_ACPI
index f7200a9d492..773fdcce97a 100644
--- a/sys/arch/amd64/conf/INSTALL_ACPI
+++ b/sys/arch/amd64/conf/INSTALL_ACPI
@@ -1,9 +1,8 @@
-# $NetBSD: INSTALL_ACPI,v 1.30 2005/12/11 12:16:21 christos Exp $
+# $NetBSD: INSTALL_ACPI,v 1.31 2006/07/04 00:30:22 christos Exp $
#
# INSTALL_ACPI machine description file
include "arch/amd64/conf/INSTALL"
no options MPBIOS_SCANPCI
-options MPACPI
acpi0 at mainbus0
diff --git a/sys/arch/i386/conf/GENERIC b/sys/arch/i386/conf/GENERIC
index 0fae62f8089..b668572e17e 100644
--- a/sys/arch/i386/conf/GENERIC
+++ b/sys/arch/i386/conf/GENERIC
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.759 2006/06/28 15:19:28 liamjfoy Exp $
+# $NetBSD: GENERIC,v 1.760 2006/07/04 00:30:22 christos Exp $
#
# GENERIC machine description file
#
@@ -22,7 +22,7 @@ include "arch/i386/conf/std.i386"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "GENERIC-$Revision: 1.759 $"
+#ident "GENERIC-$Revision: 1.760 $"
maxusers 32 # estimated number of users
@@ -319,9 +319,7 @@ cpu* at mainbus?
# To use the I/O APIC(s), enable the ioapic line above.
#options MPBIOS # configure CPUs and APICs using MPBIOS
#options MPBIOS_SCANPCI # find PCI roots using MPBIOS
-#options MPACPI # configure CPUs and APICs using ACPI
- # (acpi at mainbus must also be enabled)
-#options MPACPI_SCANPCI # find PCI roots using MPACPI
+#options ACPI_SCANPCI # find PCI roots using ACPI
#acpi0 at mainbus0
diff --git a/sys/arch/i386/conf/GENERIC.MP b/sys/arch/i386/conf/GENERIC.MP
index 209a7778176..fc91a2a6826 100644
--- a/sys/arch/i386/conf/GENERIC.MP
+++ b/sys/arch/i386/conf/GENERIC.MP
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC.MP,v 1.7 2005/12/27 00:46:38 chs Exp $
+# $NetBSD: GENERIC.MP,v 1.8 2006/07/04 00:30:22 christos Exp $
#
# GENERIC.MP -- Generic, plus enable Multiprocessor support.
#
@@ -14,7 +14,5 @@ options APM_NO_IDLE
#options MPVERBOSE
#options DEBUG
options MPBIOS # configure CPUs and APICs using MPBIOS
-#options MPACPI # configure CPUs and APICs using ACPI
- # (acpi at mainbus must also be enabled)
ioapic* at mainbus? apid ?
diff --git a/sys/arch/i386/conf/GENERIC.MPACPI b/sys/arch/i386/conf/GENERIC.MPACPI
index aa0d07d95b0..5e556d3f462 100644
--- a/sys/arch/i386/conf/GENERIC.MPACPI
+++ b/sys/arch/i386/conf/GENERIC.MPACPI
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC.MPACPI,v 1.58 2006/02/21 15:07:03 thorpej Exp $
+# $NetBSD: GENERIC.MPACPI,v 1.59 2006/07/04 00:30:22 christos Exp $
#
# GENERIC.MP -- Generic, plus enable Multiprocessor support.
#
@@ -13,8 +13,6 @@ options APM_NO_IDLE
#options MPDEBUG
#options MPVERBOSE
#options DEBUG
-options MPACPI # configure CPUs and APICs using ACPI
- # (acpi at mainbus must also be enabled)
options ACPIVERBOSE
ioapic* at mainbus? apid ?
diff --git a/sys/arch/i386/conf/INSTALL.MP b/sys/arch/i386/conf/INSTALL.MP
index 6aa17b6e08c..29a38a548d6 100644
--- a/sys/arch/i386/conf/INSTALL.MP
+++ b/sys/arch/i386/conf/INSTALL.MP
@@ -1,4 +1,4 @@
-# $NetBSD: INSTALL.MP,v 1.5 2005/12/27 00:46:38 chs Exp $
+# $NetBSD: INSTALL.MP,v 1.6 2006/07/04 00:30:22 christos Exp $
#
# INSTALL.MP -- Install, plus enable Multiprocessor support.
# Mostly to let people test-boot MP systems.
@@ -14,7 +14,5 @@ options MPDEBUG
options MPVERBOSE
options DEBUG
options MPBIOS # configure CPUs and APICs using MPBIOS
-#options MPACPI # configure CPUs and APICs using ACPI
- # (acpi at mainbus must also be enabled)
ioapic* at mainbus? apid ?
diff --git a/sys/arch/i386/conf/VIRTUALPC b/sys/arch/i386/conf/VIRTUALPC
index 32187c5f0bb..20f5ac26f3d 100644
--- a/sys/arch/i386/conf/VIRTUALPC
+++ b/sys/arch/i386/conf/VIRTUALPC
@@ -1,4 +1,4 @@
-# $NetBSD: VIRTUALPC,v 1.42 2006/06/16 06:41:13 simonb Exp $
+# $NetBSD: VIRTUALPC,v 1.43 2006/07/04 00:30:22 christos Exp $
#
# VIRTUALPC machine description file --
#
@@ -11,7 +11,7 @@ include "arch/i386/conf/std.i386"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "VIRTUALPC-$Revision: 1.42 $"
+#ident "VIRTUALPC-$Revision: 1.43 $"
maxusers 32 # estimated number of users
@@ -273,9 +273,7 @@ cpu* at mainbus?
# To use the I/O APIC(s), enable the ioapic line above.
#options MPBIOS # configure CPUs and APICs using MPBIOS
#options MPBIOS_SCANPCI # find PCI roots using MPBIOS
-#options MPACPI # configure CPUs and APICs using ACPI
- # (acpi at mainbus must also be enabled)
-#options MPACPI_SCANPCI # find PCI roots using MPACPI
+#options ACPI_SCANPCI # find PCI roots using ACPI
#acpi0 at mainbus0
diff --git a/sys/arch/i386/i386/mainbus.c b/sys/arch/i386/i386/mainbus.c
index 133bca74916..d9f7973dcae 100644
--- a/sys/arch/i386/i386/mainbus.c
+++ b/sys/arch/i386/i386/mainbus.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mainbus.c,v 1.62 2006/02/19 14:59:22 thorpej Exp $ */
+/* $NetBSD: mainbus.c,v 1.63 2006/07/04 00:30:22 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.62 2006/02/19 14:59:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.63 2006/07/04 00:30:22 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -55,7 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.62 2006/02/19 14:59:22 thorpej Exp $")
#include "acpi.h"
#include "vesabios.h"
-#include "opt_mpacpi.h"
+#include "opt_acpi.h"
#include "opt_mpbios.h"
#include "opt_pcifixup.h"
@@ -140,7 +140,7 @@ struct isabus_attach_args mba_iba = {
*/
int eisa_has_been_seen;
-#if defined(MPBIOS) || defined(MPACPI)
+#if defined(MPBIOS) || NACPI > 0
struct mp_bus *mp_busses;
int mp_nbus;
struct mp_intr_map *mp_intrs;
@@ -185,10 +185,14 @@ mainbus_attach(parent, self, aux)
#ifdef MPBIOS
int mpbios_present = 0;
#endif
+#if NACPI > 0 || defined(MPBIOS)
+ int numioapics = 0;
+#endif
#if defined(PCI_BUS_FIXUP)
int pci_maxbus = 0;
#endif
int mpacpi_active = 0;
+ int numcpus = 0;
aprint_naive("\n");
aprint_normal("\n");
@@ -215,24 +219,22 @@ mainbus_attach(parent, self, aux)
#if NACPI > 0
acpi_present = acpi_probe();
-#ifdef MPACPI
/*
* First, see if the MADT contains CPUs, and possibly I/O APICs.
* Building the interrupt routing structures can only
* be done later (via a callback).
*/
if (acpi_present)
- mpacpi_active = mpacpi_scan_apics(self);
-#endif
+ mpacpi_active = mpacpi_scan_apics(self, &numcpus, &numioapics);
#endif
if (!mpacpi_active) {
#ifdef MPBIOS
if (mpbios_present)
- mpbios_scan(self);
+ mpbios_scan(self, &numcpus, &numioapics);
else
#endif
- {
+ if (numcpus == 0) {
struct cpu_attach_args caa;
memset(&caa, 0, sizeof(caa));
@@ -307,7 +309,7 @@ mainbus_attach(parent, self, aux)
mba.mba_pba.pba_flags = pci_bus_flags();
mba.mba_pba.pba_bus = 0;
mba.mba_pba.pba_bridgetag = NULL;
-#if defined(MPACPI) && defined(MPACPI_SCANPCI)
+#if NACPI > 0 && defined(ACPI_SCANPCI)
if (mpacpi_active)
mpacpi_scan_pci(self, &mba.mba_pba, pcibusprint);
else
@@ -318,6 +320,10 @@ mainbus_attach(parent, self, aux)
else
#endif
config_found_ia(self, "pcibus", &mba.mba_pba, pcibusprint);
+#if NACPI > 0
+ if (mp_verbose)
+ acpi_pci_link_state();
+#endif
}
#endif
diff --git a/sys/arch/x86/conf/files.x86 b/sys/arch/x86/conf/files.x86
index f9075d79cf3..7989b07e701 100644
--- a/sys/arch/x86/conf/files.x86
+++ b/sys/arch/x86/conf/files.x86
@@ -1,8 +1,7 @@
-# $NetBSD: files.x86,v 1.16 2006/02/03 19:58:20 bouyer Exp $
+# $NetBSD: files.x86,v 1.17 2006/07/04 00:30:22 christos Exp $
# options for MP configuration through the MP spec
defflag opt_mpbios.h MPBIOS MPVERBOSE MPDEBUG MPBIOS_SCANPCI
-defflag opt_mpacpi.h MPACPI MPACPI_SCANPCI
# MTRR support
defflag MTRR
@@ -38,7 +37,7 @@ file arch/x86/x86/ioapic.c ioapic needs-flag
file arch/x86/x86/mpbios.c mpbios
# MP configuration using ACPI
-file arch/x86/x86/mpacpi.c mpacpi & acpi
+file arch/x86/x86/mpacpi.c acpi
file arch/x86/x86/acpi_machdep.c acpi
diff --git a/sys/arch/x86/include/intr.h b/sys/arch/x86/include/intr.h
index c4b814f206b..fbcf10bd3a7 100644
--- a/sys/arch/x86/include/intr.h
+++ b/sys/arch/x86/include/intr.h
@@ -1,4 +1,4 @@
-/* $NetBSD: intr.h,v 1.20 2006/02/16 20:17:15 perry Exp $ */
+/* $NetBSD: intr.h,v 1.21 2006/07/04 00:30:22 christos Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -235,6 +235,7 @@ void intr_add_pcibus(struct pcibus_attach_args *);
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
diff --git a/sys/arch/x86/include/mpacpi.h b/sys/arch/x86/include/mpacpi.h
index 7e60475d463..f1eec0c3553 100644
--- a/sys/arch/x86/include/mpacpi.h
+++ b/sys/arch/x86/include/mpacpi.h
@@ -1,14 +1,17 @@
-/* $NetBSD: mpacpi.h,v 1.3 2005/04/16 07:45:59 yamt Exp $ */
+/* $NetBSD: mpacpi.h,v 1.4 2006/07/04 00:30:22 christos Exp $ */
#ifndef _X86_MPACPI_H_
#define _X86_MPACPI_H_
struct pcibus_attach_args;
-int mpacpi_scan_apics(struct device *);
+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_ */
diff --git a/sys/arch/x86/include/mpbiosvar.h b/sys/arch/x86/include/mpbiosvar.h
index fbf84f85702..0a60d37dcc1 100644
--- a/sys/arch/x86/include/mpbiosvar.h
+++ b/sys/arch/x86/include/mpbiosvar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: mpbiosvar.h,v 1.3 2003/05/29 20:22:32 fvdl Exp $ */
+/* $NetBSD: mpbiosvar.h,v 1.4 2006/07/04 00:30:22 christos Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
struct pcibus_attach_args;
#if defined(_KERNEL)
-void mpbios_scan(struct device *);
+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 *);
diff --git a/sys/arch/x86/include/mpconfig.h b/sys/arch/x86/include/mpconfig.h
index 0e6a515ce1b..2d6301fc737 100644
--- a/sys/arch/x86/include/mpconfig.h
+++ b/sys/arch/x86/include/mpconfig.h
@@ -1,4 +1,4 @@
-/* $NetBSD: mpconfig.h,v 1.8 2005/05/29 21:37:02 christos Exp $ */
+/* $NetBSD: mpconfig.h,v 1.9 2006/07/04 00:30:22 christos Exp $ */
/*
* Definitions originally from the mpbios code, but now used for ACPI
@@ -53,7 +53,7 @@ struct mp_intr_map
struct mp_intr_map *next;
struct mp_bus *bus;
int bus_pin;
- struct ioapic_softc *ioapic;
+ struct pic *ioapic;
int ioapic_pin;
int ioapic_ih; /* int handle, for apic_intr_est */
int type; /* from mp spec intr record */
@@ -62,6 +62,8 @@ struct mp_intr_map
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 */
diff --git a/sys/arch/x86/include/pic.h b/sys/arch/x86/include/pic.h
index c9791557f63..13158d58990 100644
--- a/sys/arch/x86/include/pic.h
+++ b/sys/arch/x86/include/pic.h
@@ -1,4 +1,4 @@
-/* $NetBSD: pic.h,v 1.1 2003/02/26 21:26:11 fvdl Exp $ */
+/* $NetBSD: pic.h,v 1.2 2006/07/04 00:30:22 christos Exp $ */
#ifndef _X86_PIC_H
#define _X86_PIC_H
@@ -14,6 +14,8 @@ struct cpu_info;
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);
diff --git a/sys/arch/x86/pci/pci_intr_machdep.c b/sys/arch/x86/pci/pci_intr_machdep.c
index 8b6a8e5c203..8db039edb5a 100644
--- a/sys/arch/x86/pci/pci_intr_machdep.c
+++ b/sys/arch/x86/pci/pci_intr_machdep.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_intr_machdep.c,v 1.1 2006/02/03 19:58:21 bouyer Exp $ */
+/* $NetBSD: pci_intr_machdep.c,v 1.2 2006/07/04 00:30:23 christos Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.1 2006/02/03 19:58:21 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.2 2006/07/04 00:30:23 christos Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -98,11 +98,13 @@ __KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.1 2006/02/03 19:58:21 bouyer
#include "ioapic.h"
#include "eisa.h"
+#include "acpi.h"
#include "opt_mpbios.h"
-#include "opt_mpacpi.h"
+#include "opt_acpi.h"
-#if NIOAPIC > 0
+#if NIOAPIC > 0 || !defined(MPBIOS)
#include <machine/i82093var.h>
+#include <machine/mpconfig.h>
#include <machine/mpbiosvar.h>
#include <machine/pic.h>
#endif
@@ -111,7 +113,7 @@ __KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.1 2006/02/03 19:58:21 bouyer
#include <machine/mpbiosvar.h>
#endif
-#ifdef MPACPI
+#if NACPI > 0
#include <machine/mpacpi.h>
#endif
@@ -122,7 +124,7 @@ pci_intr_map(pa, ihp)
{
int pin = pa->pa_intrpin;
int line = pa->pa_intrline;
-#if NIOAPIC > 0
+#if NIOAPIC > 0 || !defined(MPBIOS)
int rawpin = pa->pa_rawintrpin;
pci_chipset_tag_t pc = pa->pa_pc;
int bus, dev, func;
@@ -133,16 +135,19 @@ pci_intr_map(pa, ihp)
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
+#if NIOAPIC > 0 || !defined(MPBIOS)
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;
+ if ((*ihp & 0xff) == 0)
+ *ihp |= line;
return 0;
}
/*
@@ -180,15 +185,17 @@ pci_intr_map(pa, ihp)
line = 9;
}
}
-#if NIOAPIC > 0
+#if NIOAPIC > 0 || !defined(MPBIOS)
if (mp_busses != NULL) {
if (intr_find_mpmapping(mp_isa_bus, line, ihp) == 0) {
- *ihp |= line;
+ if ((*ihp & 0xff) == 0)
+ *ihp |= line;
return 0;
}
#if NEISA > 0
if (intr_find_mpmapping(mp_eisa_bus, line, ihp) == 0) {
- *ihp |= line;
+ if ((*ihp & 0xff) == 0)
+ *ihp |= line;
return 0;
}
#endif
diff --git a/sys/arch/x86/pci/pci_machdep.c b/sys/arch/x86/pci/pci_machdep.c
index ad18a6e4b01..0948e792c83 100644
--- a/sys/arch/x86/pci/pci_machdep.c
+++ b/sys/arch/x86/pci/pci_machdep.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_machdep.c,v 1.15 2006/06/25 03:46:56 soren Exp $ */
+/* $NetBSD: pci_machdep.c,v 1.16 2006/07/04 00:30:23 christos Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.15 2006/06/25 03:46:56 soren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.16 2006/07/04 00:30:23 christos Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -103,17 +103,20 @@ __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.15 2006/06/25 03:46:56 soren Exp $
#include <dev/pci/pcireg.h>
#include <dev/pci/pcidevs.h>
+#include "acpi.h"
#include "opt_mpbios.h"
-#include "opt_mpacpi.h"
+#include "opt_acpi.h"
#ifdef MPBIOS
#include <machine/mpbiosvar.h>
#endif
-#ifdef MPACPI
+#if NACPI > 0
#include <machine/mpacpi.h>
#endif
+#include <machine/mpconfig.h>
+
#include "opt_pci_conf_mode.h"
int pci_mode = -1;
@@ -240,7 +243,7 @@ pci_attach_hook(parent, self, pba)
#ifdef MPBIOS
mpbios_pci_attach_hook(parent, self, pba);
#endif
-#ifdef MPACPI
+#if NACPI > 0
mpacpi_pci_attach_hook(parent, self, pba);
#endif
}
diff --git a/sys/arch/x86/x86/acpi_machdep.c b/sys/arch/x86/x86/acpi_machdep.c
index 88443cc8213..3a1c0d0813b 100644
--- a/sys/arch/x86/x86/acpi_machdep.c
+++ b/sys/arch/x86/x86/acpi_machdep.c
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_machdep.c,v 1.9 2006/02/16 09:22:16 kochi Exp $ */
+/* $NetBSD: acpi_machdep.c,v 1.10 2006/07/04 00:30:23 christos Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.9 2006/02/16 09:22:16 kochi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.10 2006/07/04 00:30:23 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -69,8 +69,9 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_machdep.c,v 1.9 2006/02/16 09:22:16 kochi Exp $
#include "ioapic.h"
-#include "opt_mpacpi.h"
+#include "acpi.h"
#include "opt_mpbios.h"
+#include "opt_acpi.h"
static int acpi_intrcold = 1;
@@ -117,12 +118,12 @@ acpi_md_OsInstallInterruptHandler(UINT32 InterruptNumber,
int irq, pin, trigger;
struct acpi_intr_defer *aip;
#if NIOAPIC > 0
-#ifdef MPACPI
+#if NACPI > 0
int i, h;
#endif
struct ioapic_softc *sc;
#endif
-#if defined(MPACPI) || NIOAPIC > 0
+#if NACPI > 0 || NIOAPIC > 0
struct mp_intr_map *mip = NULL;
#endif
@@ -141,10 +142,10 @@ acpi_md_OsInstallInterruptHandler(UINT32 InterruptNumber,
trigger = IST_LEVEL;
-#if defined(MPACPI) && NIOAPIC > 0
+#if NACPI > 0 && NIOAPIC > 0
/*
* Can only match on ACPI global interrupt numbers if the ACPI
- * interrupt info was extracted, which is in the MPACPI case.
+ * interrupt info was extracted, which is in the ACPI case.
*/
if (mp_busses == NULL)
goto nomap;
@@ -197,11 +198,11 @@ nomap:
irq = pin = (int)InterruptNumber;
}
-#if defined(MPACPI) && NIOAPIC > 0
+#if NACPI > 0 && NIOAPIC > 0
found:
#endif
-#if defined(MPACPI) || NIOAPIC > 0
+#if NACPI > 0 || NIOAPIC > 0
/*
* If there was no ACPI interrupt source override,
* mark the SCI interrupt as active low in the
@@ -334,7 +335,7 @@ acpi_md_callback(struct device *acpi)
{
struct acpi_intr_defer *aip;
-#ifdef MPACPI
+#if NACPI > 0
#ifdef MPBIOS
if (!mpbios_scanned)
#endif
diff --git a/sys/arch/x86/x86/i8259.c b/sys/arch/x86/x86/i8259.c
index 20f16cf53e9..fa8dd21ab40 100644
--- a/sys/arch/x86/x86/i8259.c
+++ b/sys/arch/x86/x86/i8259.c
@@ -1,4 +1,4 @@
-/* $NetBSD: i8259.c,v 1.7 2006/05/19 13:59:50 tsutsui Exp $ */
+/* $NetBSD: i8259.c,v 1.8 2006/07/04 00:30:23 christos Exp $ */
/*
* Copyright 2002 (c) Wasabi Systems, Inc.
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.7 2006/05/19 13:59:50 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i8259.c,v 1.8 2006/07/04 00:30:23 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -112,6 +112,8 @@ struct pic i8259_pic = {
.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,
diff --git a/sys/arch/x86/x86/intr.c b/sys/arch/x86/x86/intr.c
index 886ad0fce3f..0378cf4c859 100644
--- a/sys/arch/x86/x86/intr.c
+++ b/sys/arch/x86/x86/intr.c
@@ -1,4 +1,4 @@
-/* $NetBSD: intr.c,v 1.22 2005/12/11 12:19:47 christos Exp $ */
+/* $NetBSD: intr.c,v 1.23 2006/07/04 00:30:23 christos Exp $ */
/*
* Copyright 2002 (c) Wasabi Systems, Inc.
@@ -104,9 +104,12 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.22 2005/12/11 12:19:47 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.23 2006/07/04 00:30:23 christos Exp $");
+
+#define INTRDEBUG
#include "opt_multiprocessor.h"
+#include "opt_acpi.h"
#include <sys/cdefs.h>
#include <sys/param.h>
@@ -126,10 +129,12 @@ __KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.22 2005/12/11 12:19:47 christos Exp $");
#include "ioapic.h"
#include "lapic.h"
#include "pci.h"
+#include "acpi.h"
-#if NIOAPIC > 0
+#if NIOAPIC > 0 || NACPI > 0
#include <machine/i82093var.h>
#include <machine/mpbiosvar.h>
+#include <machine/mpacpi.h>
#endif
#if NLAPIC > 0
@@ -145,10 +150,12 @@ struct pic softintr_pic = {
.dv_xname = "softintr_fakepic",
},
.pic_type = PIC_SOFT,
+ .pic_vecbase = 0,
+ .pic_apicid = 0,
.pic_lock = __SIMPLELOCK_UNLOCKED,
};
-#if NIOAPIC > 0
+#if NIOAPIC > 0 || NACPI > 0
static int intr_scan_bus(int, int, int *);
#if NPCI > 0
static int intr_find_pcibridge(int, pcitag_t *, pci_chipset_tag_t *);
@@ -253,7 +260,7 @@ intr_calculatemasks(struct cpu_info *ci)
*
* XXX should maintain one list, not an array and a linked list.
*/
-#if (NPCI > 0) && (NIOAPIC > 0)
+#if (NPCI > 0) && ((NIOAPIC > 0) || NACPI > 0)
struct intr_extra_bus {
int bus;
pcitag_t *pci_bridge_tag;
@@ -313,7 +320,7 @@ intr_find_pcibridge(int bus, pcitag_t *pci_bridge_tag,
/*
* XXX if defined(MULTIPROCESSOR) && .. ?
*/
-#if NIOAPIC > 0
+#if NIOAPIC > 0 || NACPI > 0
int
intr_find_mpmapping(int bus, int pin, int *handle)
{
@@ -355,6 +362,11 @@ intr_scan_bus(int bus, int pin, int *handle)
for (mip = intrs; mip != NULL; mip = mip->next) {
if (mip->bus_pin == pin) {
+#if NACPI > 0
+ if (mip->linkdev != NULL)
+ if (mpacpi_findintr_linkdev(mip) != 0)
+ continue;
+#endif
*handle = mip->ioapic_ih;
return 0;
}
@@ -539,6 +551,22 @@ intr_biglock_wrapper(void *vp)
}
#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)
diff --git a/sys/arch/x86/x86/ioapic.c b/sys/arch/x86/x86/ioapic.c
index 53cd86ac69a..af6eb3a3312 100644
--- a/sys/arch/x86/x86/ioapic.c
+++ b/sys/arch/x86/x86/ioapic.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ioapic.c,v 1.12 2005/12/24 20:07:42 perry Exp $ */
+/* $NetBSD: ioapic.c,v 1.13 2006/07/04 00:30:23 christos Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -72,7 +72,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.12 2005/12/24 20:07:42 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.13 2006/07/04 00:30:23 christos Exp $");
#include "opt_ddb.h"
@@ -95,11 +95,12 @@ __KERNEL_RCSID(0, "$NetBSD: ioapic.c,v 1.12 2005/12/24 20:07:42 perry Exp $");
#include <machine/mpbiosvar.h>
+#include "acpi.h"
#include "opt_mpbios.h"
-#include "opt_mpacpi.h"
+#include "opt_acpi.h"
-#if !defined(MPBIOS) && !defined(MPACPI)
-#error "ioapic needs at least one of the MPBIOS or MPACPI options"
+#if !defined(MPBIOS) && NACPI == 0
+#error "ioapic needs at least one of the MPBIOS or ACPI options"
#endif
/*
@@ -208,7 +209,7 @@ ioapic_find(int apicid)
}
for (sc = ioapics; sc != NULL; sc = sc->sc_next)
- if (sc->sc_apicid == apicid)
+ if (sc->sc_pic.pic_apicid == apicid)
return sc;
return NULL;
@@ -224,8 +225,8 @@ ioapic_find_bybase(int vec)
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))
+ if (vec >= sc->sc_pic.pic_vecbase &&
+ vec < (sc->sc_pic.pic_vecbase + sc->sc_apic_sz))
return sc;
}
@@ -282,7 +283,7 @@ ioapic_attach(struct device *parent, struct device *self, void *aux)
int i;
sc->sc_flags = aaa->flags;
- sc->sc_apicid = aaa->apic_id;
+ sc->sc_pic.pic_apicid = aaa->apic_id;
printf(" apid %d (I/O APIC)\n", aaa->apic_id);
@@ -320,13 +321,13 @@ ioapic_attach(struct device *parent, struct device *self, void *aux)
sc->sc_apic_sz++;
if (aaa->apic_vecbase != -1)
- sc->sc_apic_vecbase = aaa->apic_vecbase;
+ 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_apic_vecbase = ioapic_vecbase;
+ sc->sc_pic.pic_vecbase = ioapic_vecbase;
ioapic_vecbase += sc->sc_apic_sz;
}
@@ -353,23 +354,23 @@ ioapic_attach(struct device *parent, struct device *self, void *aux)
* Maybe we should record the original ID for interrupt
* mapping later ...
*/
- if (apic_id != sc->sc_apicid) {
+ 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_apicid<<IOAPIC_ID_SHIFT));
+ |(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_apicid) {
+ 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_apicid);
+ sc->sc_pic.pic_apicid);
} else {
printf("%s: remapped to apic %d\n",
sc->sc_pic.pic_dev.dv_xname,
- sc->sc_apicid);
+ sc->sc_pic.pic_apicid);
}
}
#if 0
diff --git a/sys/arch/x86/x86/mpacpi.c b/sys/arch/x86/x86/mpacpi.c
index ab7b81cc7d6..342bb5577da 100644
--- a/sys/arch/x86/x86/mpacpi.c
+++ b/sys/arch/x86/x86/mpacpi.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mpacpi.c,v 1.35 2005/12/11 12:19:47 christos Exp $ */
+/* $NetBSD: mpacpi.c,v 1.36 2006/07/04 00:30:23 christos Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,10 +36,12 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpacpi.c,v 1.35 2005/12/11 12:19:47 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpacpi.c,v 1.36 2006/07/04 00:30:23 christos Exp $");
+#include "acpi.h"
#include "opt_acpi.h"
#include "opt_mpbios.h"
+#include "opt_multiprocessor.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -70,7 +72,10 @@ __KERNEL_RCSID(0, "$NetBSD: mpacpi.c,v 1.35 2005/12/11 12:19:47 christos Exp $")
#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,6 +124,8 @@ static void mpacpi_config_irouting(struct acpi_softc *);
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,6 +139,9 @@ static int mpacpi_npciroots;
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,28 +174,37 @@ mpacpi_nonpci_intr(APIC_HEADER *hdrp, void *aux)
MADT_NMI_SOURCE *ioapic_nmi;
MADT_LOCAL_APIC_NMI *lapic_nmi;
MADT_INTERRUPT_OVERRIDE *isa_ovr;
- struct ioapic_softc *ioapic;
+ struct pic *pic;
switch (hdrp->Type) {
case APIC_NMI:
ioapic_nmi = (MADT_NMI_SOURCE *)hdrp;
- ioapic = ioapic_find_bybase(ioapic_nmi->Interrupt);
- if (ioapic == NULL)
+ 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 = ioapic;
- pin = ioapic_nmi->Interrupt - ioapic->sc_apic_vecbase;
+ 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);
- 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);
+#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,10 +226,14 @@ mpacpi_nonpci_intr(APIC_HEADER *hdrp, void *aux)
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)
+ pic = intr_findpic(isa_ovr->Interrupt);
+ if (pic == NULL)
+ break;
+#if NIOAPIC == 0
+ if (pic->pic_type == PIC_IOAPIC)
break;
- pin = isa_ovr->Interrupt - ioapic->sc_apic_vecbase;
+#endif
+ pin = isa_ovr->Interrupt - pic->pic_vecbase;
lindex = isa_ovr->Source;
/*
* IRQ 2 was skipped in the default setup.
@@ -218,10 +241,16 @@ mpacpi_nonpci_intr(APIC_HEADER *hdrp, void *aux)
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);
+#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,7 +274,10 @@ mpacpi_nonpci_intr(APIC_HEADER *hdrp, void *aux)
break;
}
mpi->flags = isa_ovr->Polarity | (isa_ovr->TriggerMode << 2);
- ioapic->sc_pins[pin].ip_map = mpi;
+#if NIOAPIC > 0
+ if (pic->pic_type == PIC_IOAPIC)
+ ((struct ioapic_softc *)pic)->sc_pins[pin].ip_map = mpi;
+#endif
default:
break;
}
@@ -287,14 +319,20 @@ mpacpi_config_cpu(APIC_HEADER *hdrp, void *aux)
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 == lapic_cpu_number())
- caa.cpu_role = CPU_ROLE_BP;
- else
+ 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,7 +365,7 @@ mpacpi_config_ioapic(APIC_HEADER *hdrp, void *aux)
}
int
-mpacpi_scan_apics(struct device *self)
+mpacpi_scan_apics(struct device *self, int *ncpu, int *napic)
{
int rv = 0;
@@ -337,7 +375,9 @@ mpacpi_scan_apics(struct device *self)
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,11 +391,14 @@ mpacpi_scan_apics(struct device *self)
* 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)
+ 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,10 +646,11 @@ static int
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 ioapic_softc *ioapic;
+ struct pic *pic;
unsigned dev;
int pin;
@@ -627,37 +671,78 @@ mpacpi_pciroute(struct mpacpi_pcibus *mpr)
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->bus = mpb;
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);
+ 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;
- 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 */
+ if (mp_verbose > 1)
+ printf("pciroute: done\n");
+
return 0;
}
@@ -695,7 +780,7 @@ mpacpi_config_irouting(struct acpi_softc *acpi)
int i;
struct mp_bus *mbp;
struct mp_intr_map *mpi;
- struct ioapic_softc *ioapic;
+ struct pic *pic;
nintr = mpacpi_nintsrc + NUM_LEGACY_IRQS - 1;
#if NPCI > 0
@@ -728,9 +813,13 @@ mpacpi_config_irouting(struct acpi_softc *acpi)
mbp->mb_intrs = &mp_intrs[0];
mbp->mb_data = 0;
- ioapic = ioapic_find_bybase(0);
- if (ioapic == NULL)
- panic("can't find first ioapic");
+ 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,30 +835,44 @@ mpacpi_config_irouting(struct acpi_softc *acpi)
mpi->bus = mbp;
mpi->bus_pin = i;
mpi->ioapic_pin = i;
- mpi->ioapic = ioapic;
+ mpi->ioapic = pic;
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->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;
- 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");
+ mpacpi_user_continue("done setting up mp_bus array and ISA maps");
- acpi_madt_walk(mpacpi_nonpci_intr, &mpacpi_intr_index);
- acpi_madt_unmap();
+ 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,7 +906,7 @@ mpacpi_print_intr(struct mp_intr_map *mpi)
{
char buf[256];
int pin;
- struct ioapic_softc *sc;
+ struct pic *sc;
const char *busname;
sc = mpi->ioapic;
@@ -827,9 +930,13 @@ mpacpi_print_intr(struct mp_intr_map *mpi)
}
}
- printf("%s: pin %d attached to %s",
- sc ? sc->sc_pic.pic_dev.dv_xname : "local apic",
- pin, busname);
+ 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,9 +955,11 @@ mpacpi_print_intr(struct mp_intr_map *mpi)
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,26 +973,28 @@ mpacpi_find_interrupts(void *self)
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 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,7 +1015,7 @@ mpacpi_pci_attach_hook(struct device *parent, struct device *self,
struct mp_bus *mpb;
#ifdef MPBIOS
- if (mpbios_scanned != 0 || mpacpi_nioapic == 0)
+ if (mpbios_scanned != 0)
return ENOENT;
#endif
@@ -919,8 +1030,10 @@ mpacpi_pci_attach_hook(struct device *parent, struct device *self,
* 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!");
+ 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,6 +1051,11 @@ mpacpi_pci_attach_hook(struct device *parent, struct device *self,
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,3 +1083,67 @@ mpacpi_scan_pci(struct device *self, struct pcibus_attach_args *pba,
}
#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();
+}
diff --git a/sys/arch/x86/x86/mpbios.c b/sys/arch/x86/x86/mpbios.c
index 7e6b0f8354e..c5bfd1fed5d 100644
--- a/sys/arch/x86/x86/mpbios.c
+++ b/sys/arch/x86/x86/mpbios.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mpbios.c,v 1.27 2005/12/11 12:19:47 christos Exp $ */
+/* $NetBSD: mpbios.c,v 1.28 2006/07/04 00:30:23 christos Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -103,9 +103,10 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpbios.c,v 1.27 2005/12/11 12:19:47 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpbios.c,v 1.28 2006/07/04 00:30:23 christos Exp $");
-#include "opt_mpacpi.h"
+#include "acpi.h"
+#include "opt_acpi.h"
#include "opt_mpbios.h"
#include <sys/param.h>
@@ -132,11 +133,14 @@ __KERNEL_RCSID(0, "$NetBSD: mpbios.c,v 1.27 2005/12/11 12:19:47 christos Exp $")
#include <dev/eisa/eisavar.h> /* for ELCR* def'ns */
#endif
-#ifdef MPACPI
+#if NACPI > 0
extern int mpacpi_ncpu;
extern int mpacpi_nioapic;
#endif
+int mpbios_ncpu;
+int mpbios_nioapic;
+
#include "pci.h"
#if NPCI > 0
@@ -500,8 +504,7 @@ static struct mp_bus nmi_bus = {
* nintrs
*/
void
-mpbios_scan(self)
- struct device *self;
+mpbios_scan(struct device *self, int *ncpu, int *napic)
{
const uint8_t *position, *end;
int count;
@@ -531,7 +534,7 @@ mpbios_scan(self)
* XXX is this the right place??
*/
-#ifdef MPACPI
+#if NACPI > 0
if (mpacpi_ncpu == 0) {
#endif
lapic_base = LAPIC_BASE;
@@ -539,7 +542,7 @@ mpbios_scan(self)
lapic_base = (paddr_t)mp_cth->apic_address;
lapic_boot_init(lapic_base);
-#ifdef MPACPI
+#if NACPI > 0
}
#endif
@@ -549,12 +552,12 @@ mpbios_scan(self)
printf("\n%s: MP default configuration %d\n",
self->dv_xname, mp_fps->mpfb1);
-#ifdef MPACPI
+#if NACPI > 0
if (mpacpi_ncpu == 0)
#endif
mpbios_cpus(self);
-#ifdef MPACPI
+#if NACPI > 0
if (mpacpi_nioapic == 0)
#endif
mpbios_ioapic((uint8_t *)&default_ioapic, self);
@@ -631,7 +634,7 @@ mpbios_scan(self)
while ((count--) && (position < end)) {
switch (type = *position) {
case MPS_MCT_CPU:
-#ifdef MPACPI
+#if NACPI > 0
/* ACPI has done this for us */
if (mpacpi_ncpu)
break;
@@ -642,7 +645,7 @@ mpbios_scan(self)
mpbios_bus(position, self);
break;
case MPS_MCT_IOAPIC:
-#ifdef MPACPI
+#if NACPI > 0
/* ACPI has done this for us */
if (mpacpi_nioapic)
break;
@@ -690,6 +693,9 @@ mpbios_scan(self)
mpbios_unmap (&mp_cfg_table_map);
}
mpbios_scanned = 1;
+
+ *ncpu = mpbios_ncpu;
+ *napic = mpbios_nioapic;
}
static void
@@ -705,6 +711,8 @@ mpbios_cpu(ent, self)
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,6 +1024,8 @@ mpbios_ioapic(ent, self)
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,7 +1109,7 @@ mpbios_int(ent, enttype, mpi)
* number.
*/
if (pin >= sc->sc_apic_sz) {
- sc2 = ioapic_find_bybase(pin);
+ sc2 = (struct ioapic_softc *)intr_findpic(pin);
if (sc2 != sc) {
printf("mpbios: bad pin %d for apic %d\n",
pin, id);
@@ -1110,7 +1120,7 @@ mpbios_int(ent, enttype, mpi)
pin -= sc->sc_apic_vecbase;
}
- mpi->ioapic = sc;
+ mpi->ioapic = (struct pic *)sc;
mpi->ioapic_pin = pin;
altmpi = sc->sc_pins[pin].ip_map;
@@ -1167,7 +1177,7 @@ mpbios_pci_attach_hook(struct device *parent, struct device *self,
if (mpbios_scanned == 0)
return ENOENT;
- if (pba->pba_bus >= mp_nbus) {
+ if (pba->pba_bus >= mp_isa_bus) {
intr_add_pcibus(pba);
return 0;
}
@@ -1179,6 +1189,10 @@ mpbios_pci_attach_hook(struct device *parent, struct device *self,
} 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;
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c
index 50b29e12832..ecae52d79a5 100644
--- a/sys/dev/acpi/acpi.c
+++ b/sys/dev/acpi/acpi.c
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi.c,v 1.92 2006/07/01 21:44:13 christos Exp $ */
+/* $NetBSD: acpi.c,v 1.93 2006/07/04 00:30:23 christos Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.92 2006/07/01 21:44:13 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.93 2006/07/04 00:30:23 christos Exp $");
#include "opt_acpi.h"
#include "opt_pcifixup.h"
@@ -100,10 +100,10 @@ __KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.92 2006/07/01 21:44:13 christos Exp $");
#endif
#if defined(ACPI_PCI_FIXUP)
-#error The option ACPI_PCI_FIXUP has been obsoleted by PCI_INTR_FIXUP. Please adjust your kernel configuration file.
+#error The option ACPI_PCI_FIXUP has been obsoleted by PCI_INTR_FIXUP_DISABLED. Please adjust your kernel configuration file.
#endif
-#ifdef PCI_INTR_FIXUP
+#ifdef PCI_INTR_FIXUP_DISABLED
#include <dev/pci/pcidevs.h>
#endif
@@ -139,6 +139,7 @@ CFATTACH_DECL(acpi, sizeof(struct acpi_softc),
* 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
@@ -168,12 +169,6 @@ static void acpi_build_tree(struct acpi_softc *);
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
/*
* acpi_probe:
@@ -224,6 +219,19 @@ acpi_probe(void)
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!
*/
@@ -355,14 +363,6 @@ acpi_attach(struct device *parent, struct device *self, void *aux)
acpitimer_init();
/*
- * 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
@@ -1114,204 +1114,15 @@ acpi_enter_sleep_state(struct acpi_softc *sc, int state)
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)
+#if defined(ACPI_ACTIVATE_DEV)
/* XXX This very incomplete */
-static ACPI_STATUS
+ACPI_STATUS
acpi_allocate_resources(ACPI_HANDLE handle)
{
ACPI_BUFFER bufp, bufc, bufn;
ACPI_RESOURCE *resp, *resc, *resn;
ACPI_RESOURCE_IRQ *irq;
+ ACPI_RESOURCE_EXTENDED_IRQ *xirq;
ACPI_STATUS rv;
uint delta;
@@ -1346,6 +1157,22 @@ acpi_allocate_resources(ACPI_HANDLE handle)
irq->InterruptCount = 1;
resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_IRQ);
break;
+ case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
+ memcpy(&resn->Data, &resp->Data,
+ sizeof(ACPI_RESOURCE_EXTENDED_IRQ));
+ xirq = (ACPI_RESOURCE_EXTENDED_IRQ *)&resn->Data;
+#if 0
+ /*
+ * XXX not duplicating the interrupt logic above
+ * because its not clear what it accomplishes.
+ */
+ xirq->Interrupts[0] =
+ ((ACPI_RESOURCE_EXT_IRQ *)&resp->Data)->
+ Interrupts[irq->NumberOfInterrupts-1];
+ xirq->NumberOfInterrupts = 1;
+#endif
+ resn->Length = ACPI_RS_SIZE(ACPI_RESOURCE_EXTENDED_IRQ);
+ break;
case ACPI_RESOURCE_TYPE_IO:
memcpy(&resn->Data, &resp->Data,
sizeof(ACPI_RESOURCE_IO));
@@ -1390,7 +1217,7 @@ out1:
out:
return rv;
}
-#endif /* PCI_INTR_FIXUP || ACPI_ACTIVATE_DEV */
+#endif /* ACPI_ACTIVATE_DEV */
SYSCTL_SETUP(sysctl_acpi_setup, "sysctl hw.acpi subtree setup")
{
diff --git a/sys/dev/acpi/acpi_pci_link.c b/sys/dev/acpi/acpi_pci_link.c
new file mode 100644
index 00000000000..f148f6c19ea
--- /dev/null
+++ b/sys/dev/acpi/acpi_pci_link.c
@@ -0,0 +1,1189 @@
+/* $NetBSD: acpi_pci_link.c,v 1.1 2006/07/04 00:30:23 christos Exp $ */
+
+/*-
+ * Copyright (c) 2002 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+
+#include "opt_acpi.h"
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/queue.h>
+#include <sys/reboot.h>
+
+#include <dev/acpi/acpica.h>
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+#define NUM_ISA_INTERRUPTS 16
+#define NUM_ACPI_INTERRUPTS 256
+
+#define PCI_INVALID_IRQ 255
+#define PCI_INTERRUPT_VALID(x) ((x) != PCI_INVALID_IRQ && (x) != 0)
+
+#define ACPI_SERIAL_BEGIN(x)
+#define ACPI_SERIAL_END(x)
+
+/*
+ * An ACPI PCI link device may contain multiple links. Each link has its
+ * own ACPI resource. _PRT entries specify which link is being used via
+ * the Source Index.
+ *
+ * XXX: A note about Source Indices and DPFs: Currently we assume that
+ * the DPF start and end tags are not counted towards the index that
+ * Source Index corresponds to. Also, we assume that when DPFs are in use
+ * they various sets overlap in terms of Indices. Here's an example
+ * resource list indicating these assumptions:
+ *
+ * Resource Index
+ * -------- -----
+ * I/O Port 0
+ * Start DPF -
+ * IRQ 1
+ * MemIO 2
+ * Start DPF -
+ * IRQ 1
+ * MemIO 2
+ * End DPF -
+ * DMA Channel 3
+ *
+ * The XXX is because I'm not sure if this is a valid assumption to make.
+ */
+
+/* States during DPF processing. */
+#define DPF_OUTSIDE 0
+#define DPF_FIRST 1
+#define DPF_IGNORE 2
+
+struct link;
+
+struct acpi_pci_link_softc {
+ int pl_num_links;
+ int pl_crs_bad;
+ struct link *pl_links;
+ char pl_name[32];
+ ACPI_HANDLE pl_handle;
+ void *pl_powerhook;
+ TAILQ_ENTRY(acpi_pci_link_softc) pl_list;
+};
+
+static TAILQ_HEAD(, acpi_pci_link_softc) acpi_pci_linkdevs =
+ TAILQ_HEAD_INITIALIZER(acpi_pci_linkdevs);
+
+
+struct link {
+ struct acpi_pci_link_softc *l_sc;
+ uint8_t l_bios_irq;
+ uint8_t l_irq;
+ uint8_t l_trig;
+ uint8_t l_pol;
+ uint8_t l_initial_irq;
+ int l_res_index;
+ int l_num_irqs;
+ int *l_irqs;
+ int l_references;
+ int l_routed:1;
+ int l_isa_irq:1;
+ ACPI_RESOURCE l_prs_template;
+};
+
+struct link_count_request {
+ int in_dpf;
+ int count;
+};
+
+struct link_res_request {
+ struct acpi_pci_link_softc *sc;
+ int in_dpf;
+ int res_index;
+ int link_index;
+};
+
+MALLOC_DEFINE(M_PCI_LINK, "pci_link", "ACPI PCI Link structures");
+
+static int pci_link_interrupt_weights[NUM_ACPI_INTERRUPTS];
+static int pci_link_bios_isa_irqs;
+
+static ACPI_STATUS acpi_count_irq_resources(ACPI_RESOURCE *, void *);
+static ACPI_STATUS link_add_crs(ACPI_RESOURCE *, void *);
+static ACPI_STATUS link_add_prs(ACPI_RESOURCE *, void *);
+static int link_valid_irq(struct link *, int);
+static void acpi_pci_link_dump(struct acpi_pci_link_softc *);
+static int acpi_pci_link_attach(struct acpi_pci_link_softc *);
+static uint8_t acpi_pci_link_search_irq(struct acpi_pci_link_softc *, int, int,
+ int);
+static void acpi_pci_link_resume(int, void *);
+static struct link *acpi_pci_link_lookup(struct acpi_pci_link_softc *, int);
+static ACPI_STATUS acpi_pci_link_srs(struct acpi_pci_link_softc *,
+ ACPI_BUFFER *);
+static ACPI_STATUS acpi_AppendBufferResource(ACPI_BUFFER *, ACPI_RESOURCE *);
+
+static ACPI_STATUS
+acpi_count_irq_resources(ACPI_RESOURCE *res, void *context)
+{
+ struct link_count_request *req;
+
+ req = (struct link_count_request *)context;
+ switch (res->Type) {
+ case ACPI_RESOURCE_TYPE_START_DEPENDENT:
+ switch (req->in_dpf) {
+ case DPF_OUTSIDE:
+ /* We've started the first DPF. */
+ req->in_dpf = DPF_FIRST;
+ break;
+ case DPF_FIRST:
+ /* We've started the second DPF. */
+ req->in_dpf = DPF_IGNORE;
+ break;
+ }
+ break;
+ case ACPI_RESOURCE_TYPE_END_DEPENDENT:
+ /* We are finished with DPF parsing. */
+ KASSERT(req->in_dpf != DPF_OUTSIDE);
+ req->in_dpf = DPF_OUTSIDE;
+ break;
+ case ACPI_RESOURCE_TYPE_IRQ:
+ case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
+ /*
+ * Don't count resources if we are in a DPF set that we are
+ * ignoring.
+ */
+ if (req->in_dpf != DPF_IGNORE)
+ req->count++;
+ }
+ return (AE_OK);
+}
+
+static ACPI_STATUS
+link_add_crs(ACPI_RESOURCE *res, void *context)
+{
+ struct link_res_request *req;
+ struct link *link;
+
+ req = (struct link_res_request *)context;
+ switch (res->Type) {
+ case ACPI_RESOURCE_TYPE_START_DEPENDENT:
+ switch (req->in_dpf) {
+ case DPF_OUTSIDE:
+ /* We've started the first DPF. */
+ req->in_dpf = DPF_FIRST;
+ break;
+ case DPF_FIRST:
+ /* We've started the second DPF. */
+ panic(
+ "%s: Multiple dependent functions within a current resource",
+ __func__);
+ break;
+ }
+ break;
+ case ACPI_RESOURCE_TYPE_END_DEPENDENT:
+ /* We are finished with DPF parsing. */
+ KASSERT(req->in_dpf != DPF_OUTSIDE);
+ req->in_dpf = DPF_OUTSIDE;
+ break;
+ case ACPI_RESOURCE_TYPE_IRQ:
+ case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
+ KASSERT(req->link_index < req->sc->pl_num_links);
+ link = &req->sc->pl_links[req->link_index];
+ link->l_res_index = req->res_index;
+ req->link_index++;
+ req->res_index++;
+
+ /*
+ * Only use the current value if there's one IRQ. Some
+ * systems return multiple IRQs (which is nonsense for _CRS)
+ * when the link hasn't been programmed.
+ */
+ if (res->Type == ACPI_RESOURCE_TYPE_IRQ) {
+ if (res->Data.Irq.InterruptCount == 1) {
+ link->l_irq = res->Data.Irq.Interrupts[0];
+ link->l_trig = res->Data.Irq.Triggering;
+ link->l_pol = res->Data.Irq.Polarity;
+ }
+ } else if (res->Data.ExtendedIrq.InterruptCount == 1) {
+ link->l_irq = res->Data.ExtendedIrq.Interrupts[0];
+ link->l_trig = res->Data.ExtendedIrq.Triggering;
+ link->l_pol = res->Data.ExtendedIrq.Polarity;
+ }
+
+ /*
+ * An IRQ of zero means that the link isn't routed.
+ */
+ if (link->l_irq == 0)
+ link->l_irq = PCI_INVALID_IRQ;
+ break;
+ default:
+ req->res_index++;
+ }
+ return (AE_OK);
+}
+
+/*
+ * Populate the set of possible IRQs for each device.
+ */
+static ACPI_STATUS
+link_add_prs(ACPI_RESOURCE *res, void *context)
+{
+ struct link_res_request *req;
+ struct link *link;
+ UINT8 *irqs = NULL;
+ UINT32 *ext_irqs = NULL;
+ int i, is_ext_irq = 1;
+
+ req = (struct link_res_request *)context;
+ switch (res->Type) {
+ case ACPI_RESOURCE_TYPE_START_DEPENDENT:
+ switch (req->in_dpf) {
+ case DPF_OUTSIDE:
+ /* We've started the first DPF. */
+ req->in_dpf = DPF_FIRST;
+ break;
+ case DPF_FIRST:
+ /* We've started the second DPF. */
+ req->in_dpf = DPF_IGNORE;
+ break;
+ }
+ break;
+ case ACPI_RESOURCE_TYPE_END_DEPENDENT:
+ /* We are finished with DPF parsing. */
+ KASSERT(req->in_dpf != DPF_OUTSIDE);
+ req->in_dpf = DPF_OUTSIDE;
+ break;
+ case ACPI_RESOURCE_TYPE_IRQ:
+ is_ext_irq = 0;
+ /* fall through */
+ case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
+ /*
+ * Don't parse resources if we are in a DPF set that we are
+ * ignoring.
+ */
+ if (req->in_dpf == DPF_IGNORE)
+ break;
+
+ KASSERT(req->link_index < req->sc->pl_num_links);
+ link = &req->sc->pl_links[req->link_index];
+ if (link->l_res_index == -1) {
+ KASSERT(req->sc->pl_crs_bad);
+ link->l_res_index = req->res_index;
+ }
+ req->link_index++;
+ req->res_index++;
+
+ /*
+ * Stash a copy of the resource for later use when doing
+ * _SRS.
+ */
+ memcpy(&link->l_prs_template, res, sizeof(ACPI_RESOURCE));
+ if (is_ext_irq) {
+ link->l_num_irqs =
+ res->Data.ExtendedIrq.InterruptCount;
+ link->l_trig = res->Data.ExtendedIrq.Triggering;
+ link->l_pol = res->Data.ExtendedIrq.Polarity;
+ ext_irqs = res->Data.ExtendedIrq.Interrupts;
+ } else {
+ link->l_num_irqs = res->Data.Irq.InterruptCount;
+ link->l_trig = res->Data.Irq.Triggering;
+ link->l_pol = res->Data.Irq.Polarity;
+ irqs = res->Data.Irq.Interrupts;
+ }
+ if (link->l_num_irqs == 0)
+ break;
+
+ /*
+ * Save a list of the valid IRQs. Also, if all of the
+ * valid IRQs are ISA IRQs, then mark this link as
+ * routed via an ISA interrupt.
+ */
+ link->l_isa_irq = TRUE;
+ link->l_irqs = malloc(sizeof(int) * link->l_num_irqs,
+ M_PCI_LINK, M_WAITOK | M_ZERO);
+ for (i = 0; i < link->l_num_irqs; i++) {
+ if (is_ext_irq) {
+ link->l_irqs[i] = ext_irqs[i];
+ if (ext_irqs[i] >= NUM_ISA_INTERRUPTS)
+ link->l_isa_irq = FALSE;
+ } else {
+ link->l_irqs[i] = irqs[i];
+ if (irqs[i] >= NUM_ISA_INTERRUPTS)
+ link->l_isa_irq = FALSE;
+ }
+ }
+ break;
+ default:
+ if (req->in_dpf == DPF_IGNORE)
+ break;
+ if (req->sc->pl_crs_bad)
+ aprint_normal("%s: Warning: possible resource %d "
+ "will be lost during _SRS\n", req->sc->pl_name,
+ req->res_index);
+ req->res_index++;
+ }
+ return (AE_OK);
+}
+
+static int
+link_valid_irq(struct link *link, int irq)
+{
+ int i;
+
+ /* Invalid interrupts are never valid. */
+ if (!PCI_INTERRUPT_VALID(irq))
+ return (FALSE);
+
+ /* Any interrupt in the list of possible interrupts is valid. */
+ for (i = 0; i < link->l_num_irqs; i++)
+ if (link->l_irqs[i] == irq)
+ return (TRUE);
+
+ /*
+ * For links routed via an ISA interrupt, if the SCI is routed via
+ * an ISA interrupt, the SCI is always treated as a valid IRQ.
+ */
+ if (link->l_isa_irq && AcpiGbl_FADT->SciInt == irq &&
+ irq < NUM_ISA_INTERRUPTS)
+ return (TRUE);
+
+ /* If the interrupt wasn't found in the list it is not valid. */
+ return (FALSE);
+}
+
+void
+acpi_pci_link_state(void)
+{
+ struct acpi_pci_link_softc *sc;
+
+ TAILQ_FOREACH(sc, &acpi_pci_linkdevs, pl_list) {
+ acpi_pci_link_dump(sc);
+ }
+}
+
+static void
+acpi_pci_link_dump(struct acpi_pci_link_softc *sc)
+{
+ struct link *link;
+ int i, j;
+
+ printf("Link Device %s:\n", sc->pl_name);
+ printf("Index IRQ Rtd Ref IRQs\n");
+ for (i = 0; i < sc->pl_num_links; i++) {
+ link = &sc->pl_links[i];
+ printf("%5d %3d %c %3d ", i, link->l_irq,
+ link->l_routed ? 'Y' : 'N', link->l_references);
+ if (link->l_num_irqs == 0)
+ printf(" none");
+ else for (j = 0; j < link->l_num_irqs; j++)
+ printf(" %d", link->l_irqs[j]);
+ printf("\n");
+ }
+ printf("\n");
+}
+
+static int
+acpi_pci_link_attach(struct acpi_pci_link_softc *sc)
+{
+ struct link_count_request creq;
+ struct link_res_request rreq;
+ ACPI_STATUS status;
+ int i;
+
+ ACPI_SERIAL_BEGIN(pci_link);
+
+ /*
+ * Count the number of current resources so we know how big of
+ * a link array to allocate. On some systems, _CRS is broken,
+ * so for those systems try to derive the count from _PRS instead.
+ */
+ creq.in_dpf = DPF_OUTSIDE;
+ creq.count = 0;
+ status = AcpiWalkResources(sc->pl_handle, "_CRS",
+ acpi_count_irq_resources, &creq);
+ sc->pl_crs_bad = ACPI_FAILURE(status);
+ if (sc->pl_crs_bad) {
+ creq.in_dpf = DPF_OUTSIDE;
+ creq.count = 0;
+ status = AcpiWalkResources(sc->pl_handle, "_PRS",
+ acpi_count_irq_resources, &creq);
+ if (ACPI_FAILURE(status)) {
+ aprint_error("%s: Unable to parse _CRS or _PRS: %s\n",
+ sc->pl_name, AcpiFormatException(status));
+ ACPI_SERIAL_END(pci_link);
+ return (ENXIO);
+ }
+ }
+ sc->pl_num_links = creq.count;
+ if (creq.count == 0) {
+ ACPI_SERIAL_END(pci_link);
+ return (0);
+ }
+ sc->pl_links = malloc(sizeof(struct link) * sc->pl_num_links,
+ M_PCI_LINK, M_WAITOK | M_ZERO);
+
+ /* Initialize the child links. */
+ for (i = 0; i < sc->pl_num_links; i++) {
+ sc->pl_links[i].l_irq = PCI_INVALID_IRQ;
+ sc->pl_links[i].l_bios_irq = PCI_INVALID_IRQ;
+ sc->pl_links[i].l_sc = sc;
+ sc->pl_links[i].l_isa_irq = FALSE;
+ sc->pl_links[i].l_res_index = -1;
+ }
+
+ /* Try to read the current settings from _CRS if it is valid. */
+ if (!sc->pl_crs_bad) {
+ rreq.in_dpf = DPF_OUTSIDE;
+ rreq.link_index = 0;
+ rreq.res_index = 0;
+ rreq.sc = sc;
+ status = AcpiWalkResources(sc->pl_handle, "_CRS",
+ link_add_crs, &rreq);
+ if (ACPI_FAILURE(status)) {
+ aprint_error("%s: Unable to parse _CRS: %s\n",
+ sc->pl_name, AcpiFormatException(status));
+ goto fail;
+ }
+ }
+
+ /*
+ * Try to read the possible settings from _PRS. Note that if the
+ * _CRS is toast, we depend on having a working _PRS. However, if
+ * _CRS works, then it is ok for _PRS to be missing.
+ */
+ rreq.in_dpf = DPF_OUTSIDE;
+ rreq.link_index = 0;
+ rreq.res_index = 0;
+ rreq.sc = sc;
+ status = AcpiWalkResources(sc->pl_handle, "_PRS",
+ link_add_prs, &rreq);
+ if (ACPI_FAILURE(status) &&
+ (status != AE_NOT_FOUND || sc->pl_crs_bad)) {
+ aprint_error("%s: Unable to parse _PRS: %s\n",
+ sc->pl_name, AcpiFormatException(status));
+ goto fail;
+ }
+ if (boothowto & AB_VERBOSE) {
+ aprint_normal("%s: Links after initial probe:\n", sc->pl_name);
+ acpi_pci_link_dump(sc);
+ }
+
+ /* Verify initial IRQs if we have _PRS. */
+ if (status != AE_NOT_FOUND)
+ for (i = 0; i < sc->pl_num_links; i++)
+ if (!link_valid_irq(&sc->pl_links[i],
+ sc->pl_links[i].l_irq))
+ sc->pl_links[i].l_irq = PCI_INVALID_IRQ;
+ if (boothowto & AB_VERBOSE) {
+ printf("%s: Links after initial validation:\n", sc->pl_name);
+ acpi_pci_link_dump(sc);
+ }
+
+ /* Save initial IRQs. */
+ for (i = 0; i < sc->pl_num_links; i++)
+ sc->pl_links[i].l_initial_irq = sc->pl_links[i].l_irq;
+
+ /*
+ * Try to disable this link. If successful, set the current IRQ to
+ * zero and flags to indicate this link is not routed. If we can't
+ * run _DIS (i.e., the method doesn't exist), assume the initial
+ * IRQ was routed by the BIOS.
+ */
+ if (ACPI_SUCCESS(AcpiEvaluateObject(sc->pl_handle, "_DIS", NULL,
+ NULL)))
+ for (i = 0; i < sc->pl_num_links; i++)
+ sc->pl_links[i].l_irq = PCI_INVALID_IRQ;
+ else
+ for (i = 0; i < sc->pl_num_links; i++)
+ if (PCI_INTERRUPT_VALID(sc->pl_links[i].l_irq))
+ sc->pl_links[i].l_routed = TRUE;
+ if (boothowto & AB_VERBOSE) {
+ printf("%s: Links after disable:\n", sc->pl_name);
+ acpi_pci_link_dump(sc);
+ }
+ ACPI_SERIAL_END(pci_link);
+ return (0);
+fail:
+ ACPI_SERIAL_END(pci_link);
+ for (i = 0; i < sc->pl_num_links; i++)
+ if (sc->pl_links[i].l_irqs != NULL)
+ free(sc->pl_links[i].l_irqs, M_PCI_LINK);
+ free(sc->pl_links, M_PCI_LINK);
+ return (ENXIO);
+}
+
+static uint8_t
+acpi_pci_link_search_irq(struct acpi_pci_link_softc *sc, int bus, int device,
+ int pin)
+{
+ uint32_t value;
+ uint8_t func, maxfunc, ipin, iline;
+ pcitag_t tag;
+
+ tag = pci_make_tag(acpi_softc->sc_pc, bus, device, 0);
+ /* See if we have a valid device at function 0. */
+ value = pci_conf_read(acpi_softc->sc_pc, tag, PCI_BHLC_REG);
+ if (PCI_HDRTYPE_TYPE(value) > PCI_HDRTYPE_PCB)
+ return (PCI_INVALID_IRQ);
+ if (PCI_HDRTYPE_MULTIFN(value))
+ maxfunc = 7;
+ else
+ maxfunc = 0;
+
+ /* Scan all possible functions at this device. */
+ for (func = 0; func <= maxfunc; func++) {
+ tag = pci_make_tag(acpi_softc->sc_pc, bus, device, func);
+ value = pci_conf_read(acpi_softc->sc_pc, tag, PCI_ID_REG);
+ if (PCI_VENDOR(value) == 0xffff)
+ continue;
+ value = pci_conf_read(acpi_softc->sc_pc, tag,
+ PCI_INTERRUPT_REG);
+ ipin = PCI_INTERRUPT_PIN(value);
+ iline = PCI_INTERRUPT_LINE(value);
+
+ /*
+ * See if it uses the pin in question. Note that the passed
+ * in pin uses 0 for A, .. 3 for D whereas the intpin
+ * register uses 0 for no interrupt, 1 for A, .. 4 for D.
+ */
+ if (ipin != pin + 1)
+ continue;
+ aprint_verbose(
+ "%s: ACPI: Found matching pin for %d.%d.INT%c"
+ " at func %d: %d\n",
+ sc->pl_name, bus, device, pin + 'A', func, iline);
+ if (PCI_INTERRUPT_VALID(iline))
+ return (iline);
+ }
+ return (PCI_INVALID_IRQ);
+}
+
+/*
+ * Find the link structure that corresponds to the resource index passed in
+ * via 'source_index'.
+ */
+static struct link *
+acpi_pci_link_lookup(struct acpi_pci_link_softc *sc, int source_index)
+{
+ int i;
+
+ for (i = 0; i < sc->pl_num_links; i++)
+ if (sc->pl_links[i].l_res_index == source_index)
+ return (&sc->pl_links[i]);
+ return (NULL);
+}
+
+void
+acpi_pci_link_add_reference(void *v, int index, int bus, int slot, int pin)
+{
+ struct acpi_pci_link_softc *sc = v;
+ struct link *link;
+ uint8_t bios_irq;
+
+ /* Bump the reference count. */
+ ACPI_SERIAL_BEGIN(pci_link);
+ link = acpi_pci_link_lookup(sc, index);
+ if (link == NULL) {
+ printf("%s: apparently invalid index %d\n", sc->pl_name, index);
+ ACPI_SERIAL_END(pci_link);
+ return;
+ }
+ link->l_references++;
+ if (link->l_routed)
+ pci_link_interrupt_weights[link->l_irq]++;
+
+ /*
+ * The BIOS only routes interrupts via ISA IRQs using the ATPICs
+ * (8259As). Thus, if this link is routed via an ISA IRQ, go
+ * look to see if the BIOS routed an IRQ for this link at the
+ * indicated (bus, slot, pin). If so, we prefer that IRQ for
+ * this link and add that IRQ to our list of known-good IRQs.
+ * This provides a good work-around for link devices whose _CRS
+ * method is either broken or bogus. We only use the value
+ * returned by _CRS if we can't find a valid IRQ via this method
+ * in fact.
+ *
+ * If this link is not routed via an ISA IRQ (because we are using
+ * APIC for example), then don't bother looking up the BIOS IRQ
+ * as if we find one it won't be valid anyway.
+ */
+ if (!link->l_isa_irq) {
+ ACPI_SERIAL_END(pci_link);
+ return;
+ }
+
+ /* Try to find a BIOS IRQ setting from any matching devices. */
+ bios_irq = acpi_pci_link_search_irq(sc, bus, slot, pin);
+ if (!PCI_INTERRUPT_VALID(bios_irq)) {
+ ACPI_SERIAL_END(pci_link);
+ return;
+ }
+
+ /* Validate the BIOS IRQ. */
+ if (!link_valid_irq(link, bios_irq)) {
+ printf("%s: BIOS IRQ %u for %d.%d.INT%c is invalid\n",
+ sc->pl_name, bios_irq, (int)bus, slot, pin + 'A');
+ } else if (!PCI_INTERRUPT_VALID(link->l_bios_irq)) {
+ link->l_bios_irq = bios_irq;
+ if (bios_irq < NUM_ISA_INTERRUPTS)
+ pci_link_bios_isa_irqs |= (1 << bios_irq);
+ if (bios_irq != link->l_initial_irq &&
+ PCI_INTERRUPT_VALID(link->l_initial_irq))
+ printf(
+ "%s: BIOS IRQ %u does not match initial IRQ %u\n",
+ sc->pl_name, bios_irq, link->l_initial_irq);
+ } else if (bios_irq != link->l_bios_irq)
+ printf(
+ "%s: BIOS IRQ %u for %d.%d.INT%c does not match "
+ "previous BIOS IRQ %u\n",
+ sc->pl_name, bios_irq, (int)bus, slot, pin + 'A',
+ link->l_bios_irq);
+ ACPI_SERIAL_END(pci_link);
+}
+
+static ACPI_STATUS
+acpi_pci_link_srs_from_crs(struct acpi_pci_link_softc *sc, ACPI_BUFFER *srsbuf)
+{
+ ACPI_RESOURCE *resource, *end, newres, *resptr;
+ ACPI_BUFFER crsbuf;
+ ACPI_STATUS status;
+ struct link *link;
+ int i, in_dpf;
+
+ /* Fetch the _CRS. */
+ crsbuf.Pointer = NULL;
+ crsbuf.Length = ACPI_ALLOCATE_BUFFER;
+ status = AcpiGetCurrentResources(sc->pl_handle, &crsbuf);
+ if (ACPI_SUCCESS(status) && crsbuf.Pointer == NULL)
+ status = AE_NO_MEMORY;
+ if (ACPI_FAILURE(status)) {
+ aprint_verbose("%s: Unable to fetch current resources: %s\n",
+ sc->pl_name, AcpiFormatException(status));
+ return (status);
+ }
+
+ /* Fill in IRQ resources via link structures. */
+ srsbuf->Pointer = NULL;
+ link = sc->pl_links;
+ i = 0;
+ in_dpf = DPF_OUTSIDE;
+ resource = (ACPI_RESOURCE *)crsbuf.Pointer;
+ end = (ACPI_RESOURCE *)((char *)crsbuf.Pointer + crsbuf.Length);
+ for (;;) {
+ switch (resource->Type) {
+ case ACPI_RESOURCE_TYPE_START_DEPENDENT:
+ switch (in_dpf) {
+ case DPF_OUTSIDE:
+ /* We've started the first DPF. */
+ in_dpf = DPF_FIRST;
+ break;
+ case DPF_FIRST:
+ /* We've started the second DPF. */
+ panic(
+ "%s: Multiple dependent functions within a current resource",
+ __func__);
+ break;
+ }
+ resptr = NULL;
+ break;
+ case ACPI_RESOURCE_TYPE_END_DEPENDENT:
+ /* We are finished with DPF parsing. */
+ KASSERT(in_dpf != DPF_OUTSIDE);
+ in_dpf = DPF_OUTSIDE;
+ resptr = NULL;
+ break;
+ case ACPI_RESOURCE_TYPE_IRQ:
+ newres = link->l_prs_template;
+ resptr = &newres;
+ resptr->Data.Irq.InterruptCount = 1;
+ if (PCI_INTERRUPT_VALID(link->l_irq)) {
+ KASSERT(link->l_irq < NUM_ISA_INTERRUPTS);
+ resptr->Data.Irq.Interrupts[0] = link->l_irq;
+ resptr->Data.Irq.Triggering = link->l_trig;
+ resptr->Data.Irq.Polarity = link->l_pol;
+ } else
+ resptr->Data.Irq.Interrupts[0] = 0;
+ link++;
+ i++;
+ break;
+ case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
+ newres = link->l_prs_template;
+ resptr = &newres;
+ resptr->Data.ExtendedIrq.InterruptCount = 1;
+ if (PCI_INTERRUPT_VALID(link->l_irq)) {
+ resptr->Data.ExtendedIrq.Interrupts[0] =
+ link->l_irq;
+ resptr->Data.ExtendedIrq.Triggering =
+ link->l_trig;
+ resptr->Data.ExtendedIrq.Polarity = link->l_pol;
+ } else
+ resptr->Data.ExtendedIrq.Interrupts[0] = 0;
+ link++;
+ i++;
+ break;
+ default:
+ resptr = resource;
+ }
+ if (resptr != NULL) {
+ status = acpi_AppendBufferResource(srsbuf, resptr);
+ if (ACPI_FAILURE(status)) {
+ printf("%s: Unable to build resources: %s\n",
+ sc->pl_name, AcpiFormatException(status));
+ if (srsbuf->Pointer != NULL)
+ AcpiOsFree(srsbuf->Pointer);
+ AcpiOsFree(crsbuf.Pointer);
+ return (status);
+ }
+ }
+ if (resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
+ break;
+ resource = ACPI_NEXT_RESOURCE(resource);
+ if (resource >= end)
+ break;
+ }
+ AcpiOsFree(crsbuf.Pointer);
+ return (AE_OK);
+}
+
+static ACPI_STATUS
+acpi_pci_link_srs_from_links(struct acpi_pci_link_softc *sc,
+ ACPI_BUFFER *srsbuf)
+{
+ ACPI_RESOURCE newres;
+ ACPI_STATUS status;
+ struct link *link;
+ int i;
+
+ /* Start off with an empty buffer. */
+ srsbuf->Pointer = NULL;
+ link = sc->pl_links;
+ for (i = 0; i < sc->pl_num_links; i++) {
+
+ /* Add a new IRQ resource from each link. */
+ link = &sc->pl_links[i];
+ newres = link->l_prs_template;
+ if (newres.Type == ACPI_RESOURCE_TYPE_IRQ) {
+
+ /* Build an IRQ resource. */
+ newres.Data.Irq.InterruptCount = 1;
+ if (PCI_INTERRUPT_VALID(link->l_irq)) {
+ KASSERT(link->l_irq < NUM_ISA_INTERRUPTS);
+ newres.Data.Irq.Interrupts[0] = link->l_irq;
+ newres.Data.Irq.Triggering = link->l_trig;
+ newres.Data.Irq.Polarity = link->l_pol;
+ } else
+ newres.Data.Irq.Interrupts[0] = 0;
+ } else {
+
+ /* Build an ExtIRQ resuorce. */
+ newres.Data.ExtendedIrq.InterruptCount = 1;
+ if (PCI_INTERRUPT_VALID(link->l_irq)) {
+ newres.Data.ExtendedIrq.Interrupts[0] =
+ link->l_irq;
+ newres.Data.ExtendedIrq.Triggering =
+ link->l_trig;
+ newres.Data.ExtendedIrq.Polarity =
+ link->l_pol;
+ } else {
+ newres.Data.ExtendedIrq.Interrupts[0] = 0;
+ }
+ }
+
+ /* Add the new resource to the end of the _SRS buffer. */
+ status = acpi_AppendBufferResource(srsbuf, &newres);
+ if (ACPI_FAILURE(status)) {
+ printf("%s: Unable to build resources: %s\n",
+ sc->pl_name, AcpiFormatException(status));
+ if (srsbuf->Pointer != NULL)
+ AcpiOsFree(srsbuf->Pointer);
+ return (status);
+ }
+ }
+ return (AE_OK);
+}
+
+static ACPI_STATUS
+acpi_pci_link_srs(struct acpi_pci_link_softc *sc, ACPI_BUFFER *srsbuf)
+{
+ ACPI_STATUS status;
+
+ if (sc->pl_crs_bad)
+ status = acpi_pci_link_srs_from_links(sc, srsbuf);
+ else
+ status = acpi_pci_link_srs_from_crs(sc, srsbuf);
+
+ /* Write out new resources via _SRS. */
+ return AcpiSetCurrentResources(sc->pl_handle, srsbuf);
+}
+
+static ACPI_STATUS
+acpi_pci_link_route_irqs(struct acpi_pci_link_softc *sc, int *irq, int *pol,
+ int *trig)
+{
+ ACPI_RESOURCE *resource, *end;
+ ACPI_BUFFER srsbuf;
+ ACPI_STATUS status;
+ struct link *link;
+ int i, is_ext = 0;
+
+ status = acpi_pci_link_srs(sc, &srsbuf);
+ if (ACPI_FAILURE(status)) {
+ printf("%s: _SRS failed: %s\n",
+ sc->pl_name, AcpiFormatException(status));
+ return (status);
+ }
+ /*
+ * Perform acpi_config_intr() on each IRQ resource if it was just
+ * routed for the first time.
+ */
+ link = sc->pl_links;
+ i = 0;
+ resource = (ACPI_RESOURCE *)srsbuf.Pointer;
+ end = (ACPI_RESOURCE *)((char *)srsbuf.Pointer + srsbuf.Length);
+ for (;;) {
+ if (resource->Type == ACPI_RESOURCE_TYPE_END_TAG)
+ break;
+ switch (resource->Type) {
+ case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
+ is_ext = 1;
+ /* FALLTHROUGH */
+ case ACPI_RESOURCE_TYPE_IRQ:
+ /*
+ * Only configure the interrupt and update the
+ * weights if this link has a valid IRQ and was
+ * previously unrouted.
+ */
+ if (!link->l_routed &&
+ PCI_INTERRUPT_VALID(link->l_irq)) {
+ *trig = is_ext ?
+ resource->Data.ExtendedIrq.Triggering :
+ resource->Data.Irq.Triggering;
+ *pol = is_ext ?
+ resource->Data.ExtendedIrq.Polarity :
+ resource->Data.Irq.Polarity;
+ *irq = is_ext ?
+ resource->Data.ExtendedIrq.Interrupts[0] :
+ resource->Data.Irq.Interrupts[0];
+ link->l_routed = TRUE;
+ pci_link_interrupt_weights[link->l_irq] +=
+ link->l_references;
+ }
+ link++;
+ i++;
+ break;
+ }
+ resource = ACPI_NEXT_RESOURCE(resource);
+ if (resource >= end)
+ break;
+ }
+ AcpiOsFree(srsbuf.Pointer);
+ return (AE_OK);
+}
+
+static void
+acpi_pci_link_resume(int why, void *arg)
+{
+ struct acpi_pci_link_softc *sc = arg;
+ ACPI_BUFFER srsbuf;
+
+ switch (why) {
+ case PWR_RESUME:
+ ACPI_SERIAL_BEGIN(pci_link);
+ if (ACPI_SUCCESS(acpi_pci_link_srs(sc, &srsbuf)))
+ AcpiOsFree(srsbuf.Pointer);
+ ACPI_SERIAL_END(pci_link);
+ default:
+ break;
+ }
+}
+
+/*
+ * Pick an IRQ to use for this unrouted link.
+ */
+static uint8_t
+acpi_pci_link_choose_irq(struct acpi_pci_link_softc *sc, struct link *link)
+{
+ u_int8_t best_irq, pos_irq;
+ int best_weight, pos_weight, i;
+
+ KASSERT(!link->l_routed);
+ KASSERT(!PCI_INTERRUPT_VALID(link->l_irq));
+
+ /*
+ * If we have a valid BIOS IRQ, use that. We trust what the BIOS
+ * says it routed over what _CRS says the link thinks is routed.
+ */
+ if (PCI_INTERRUPT_VALID(link->l_bios_irq))
+ return (link->l_bios_irq);
+
+ /*
+ * If we don't have a BIOS IRQ but do have a valid IRQ from _CRS,
+ * then use that.
+ */
+ if (PCI_INTERRUPT_VALID(link->l_initial_irq))
+ return (link->l_initial_irq);
+
+ /*
+ * Ok, we have no useful hints, so we have to pick from the
+ * possible IRQs. For ISA IRQs we only use interrupts that
+ * have already been used by the BIOS.
+ */
+ best_irq = PCI_INVALID_IRQ;
+ best_weight = INT_MAX;
+ for (i = 0; i < link->l_num_irqs; i++) {
+ pos_irq = link->l_irqs[i];
+ if (pos_irq < NUM_ISA_INTERRUPTS &&
+ (pci_link_bios_isa_irqs & 1 << pos_irq) == 0)
+ continue;
+ pos_weight = pci_link_interrupt_weights[pos_irq];
+ if (pos_weight < best_weight) {
+ best_weight = pos_weight;
+ best_irq = pos_irq;
+ }
+ }
+
+ /*
+ * If this is an ISA IRQ, try using the SCI if it is also an ISA
+ * interrupt as a fallback.
+ */
+ if (link->l_isa_irq) {
+ pos_irq = AcpiGbl_FADT->SciInt;
+ pos_weight = pci_link_interrupt_weights[pos_irq];
+ if (pos_weight < best_weight) {
+ best_weight = pos_weight;
+ best_irq = pos_irq;
+ }
+ }
+
+ if (PCI_INTERRUPT_VALID(best_irq)) {
+ aprint_verbose("%s: Picked IRQ %u with weight %d\n",
+ sc->pl_name, best_irq, best_weight);
+ } else
+ printf("%s: Unable to choose an IRQ\n", sc->pl_name);
+ return (best_irq);
+}
+
+int
+acpi_pci_link_route_interrupt(void *v, int index, int *irq, int *pol, int *trig)
+{
+ struct acpi_pci_link_softc *sc = v;
+ struct link *link;
+
+ ACPI_SERIAL_BEGIN(pci_link);
+ link = acpi_pci_link_lookup(sc, index);
+ if (link == NULL)
+ panic("%s: apparently invalid index %d", __func__, index);
+
+ /*
+ * If this link device is already routed to an interrupt, just return
+ * the interrupt it is routed to.
+ */
+ if (link->l_routed) {
+ KASSERT(PCI_INTERRUPT_VALID(link->l_irq));
+ ACPI_SERIAL_END(pci_link);
+ *irq = link->l_irq;
+ *pol = link->l_pol;
+ *trig = link->l_trig;
+ return (link->l_irq);
+ }
+
+ /* Choose an IRQ if we need one. */
+ if (!PCI_INTERRUPT_VALID(link->l_irq)) {
+ link->l_irq = acpi_pci_link_choose_irq(sc, link);
+
+ /*
+ * Try to route the interrupt we picked. If it fails, then
+ * assume the interrupt is not routed.
+ */
+ if (PCI_INTERRUPT_VALID(link->l_irq)) {
+ acpi_pci_link_route_irqs(sc, irq, pol, trig);
+ if (!link->l_routed)
+ link->l_irq = PCI_INVALID_IRQ;
+ else {
+ link->l_pol = *pol;
+ link->l_trig = *trig;
+ }
+ }
+ }
+ ACPI_SERIAL_END(pci_link);
+
+ return (link->l_irq);
+}
+
+/*
+ * This is gross, but we abuse the identify routine to perform one-time
+ * SYSINIT() style initialization for the driver.
+ */
+static void
+acpi_pci_link_init(struct acpi_pci_link_softc *sc)
+{
+ ACPI_BUFFER buf;
+
+ /*
+ * If the SCI is an ISA IRQ, add it to the bitmask of known good
+ * ISA IRQs.
+ *
+ * XXX: If we are using the APIC, the SCI might have been
+ * rerouted to an APIC pin in which case this is invalid. However,
+ * if we are using the APIC, we also shouldn't be having any PCI
+ * interrupts routed via ISA IRQs, so this is probably ok.
+ */
+ if (AcpiGbl_FADT->SciInt < NUM_ISA_INTERRUPTS)
+ pci_link_bios_isa_irqs |= (1 << AcpiGbl_FADT->SciInt);
+
+ sc->pl_powerhook = powerhook_establish(acpi_pci_link_resume, sc);
+ if (sc->pl_powerhook == NULL)
+ aprint_normal("can't establish powerhook\n");
+
+ buf.Length = sizeof (sc->pl_name);
+ buf.Pointer = sc->pl_name;
+
+ if (ACPI_FAILURE(AcpiGetName(sc->pl_handle, ACPI_SINGLE_NAME, &buf)))
+ snprintf(sc->pl_name, sizeof (sc->pl_name), "%s",
+ "ACPI link device");
+
+ acpi_pci_link_attach(sc);
+}
+
+void *
+acpi_pci_link_devbyhandle(ACPI_HANDLE handle)
+{
+ struct acpi_pci_link_softc *sc;
+
+ TAILQ_FOREACH(sc, &acpi_pci_linkdevs, pl_list) {
+ if (sc->pl_handle == handle)
+ return sc;
+ }
+
+ sc = malloc(sizeof (*sc), M_PCI_LINK, M_NOWAIT|M_ZERO);
+ if (sc == NULL)
+ return NULL;
+
+ sc->pl_handle = handle;
+
+ acpi_pci_link_init(sc);
+
+ TAILQ_INSERT_TAIL(&acpi_pci_linkdevs, sc, pl_list);
+
+ return (void *)sc;
+}
+
+ACPI_HANDLE
+acpi_pci_link_handle(void *v)
+{
+ struct acpi_pci_link_softc *sc = v;
+
+ return sc->pl_handle;
+}
+
+char *
+acpi_pci_link_name(void *v)
+{
+ struct acpi_pci_link_softc *sc = v;
+
+ return sc->pl_name;
+}
+
+
+/*
+ * Append an ACPI_RESOURCE to an ACPI_BUFFER.
+ *
+ * Given a pointer to an ACPI_RESOURCE structure, expand the ACPI_BUFFER
+ * provided to contain it. If the ACPI_BUFFER is empty, allocate a sensible
+ * backing block. If the ACPI_RESOURCE is NULL, return an empty set of
+ * resources.
+ */
+#define ACPI_INITIAL_RESOURCE_BUFFER_SIZE 512
+
+static ACPI_STATUS
+acpi_AppendBufferResource(ACPI_BUFFER *buf, ACPI_RESOURCE *res)
+{
+ ACPI_RESOURCE *rp;
+ void *newp;
+
+ /* Initialise the buffer if necessary. */
+ if (buf->Pointer == NULL) {
+ buf->Length = ACPI_INITIAL_RESOURCE_BUFFER_SIZE;
+ if ((buf->Pointer = AcpiOsAllocate(buf->Length)) == NULL)
+ return (AE_NO_MEMORY);
+ rp = (ACPI_RESOURCE *)buf->Pointer;
+ rp->Type = ACPI_RESOURCE_TYPE_END_TAG;
+ rp->Length = 0;
+ }
+
+ if (res == NULL)
+ return (AE_OK);
+
+ /*
+ * Scan the current buffer looking for the terminator.
+ * This will either find the terminator or hit the end
+ * of the buffer and return an error.
+ */
+ rp = (ACPI_RESOURCE *)buf->Pointer;
+ for (;;) {
+ /* Range check, don't go outside the buffer */
+ if (rp >= (ACPI_RESOURCE *)((u_int8_t *)buf->Pointer +
+ buf->Length))
+ return (AE_BAD_PARAMETER);
+ if (rp->Type == ACPI_RESOURCE_TYPE_END_TAG || rp->Length == 0)
+ break;
+ rp = ACPI_NEXT_RESOURCE(rp);
+ }
+
+ /*
+ * Check the size of the buffer and expand if required.
+ *
+ * Required size is:
+ * size of existing resources before terminator +
+ * size of new resource and header +
+ * size of terminator.
+ *
+ * Note that this loop should really only run once, unless
+ * for some reason we are stuffing a *really* huge resource.
+ */
+ while ((((u_int8_t *)rp - (u_int8_t *)buf->Pointer) +
+ res->Length + ACPI_RS_SIZE_NO_DATA +
+ ACPI_RS_SIZE_MIN) >= buf->Length) {
+ if ((newp = AcpiOsAllocate(buf->Length * 2)) == NULL)
+ return (AE_NO_MEMORY);
+ memcpy(newp, buf->Pointer, buf->Length);
+ rp = (ACPI_RESOURCE *)((u_int8_t *)newp +
+ ((u_int8_t *)rp - (u_int8_t *)buf->Pointer));
+ AcpiOsFree(buf->Pointer);
+ buf->Pointer = newp;
+ buf->Length += buf->Length;
+ }
+
+ /* Insert the new resource. */
+ memcpy(rp, res, res->Length + ACPI_RS_SIZE_NO_DATA);
+
+ /* And add the terminator. */
+ rp = ACPI_NEXT_RESOURCE(rp);
+ rp->Type = ACPI_RESOURCE_TYPE_END_TAG;
+ rp->Length = 0;
+
+ return (AE_OK);
+}
diff --git a/sys/dev/acpi/acpi_quirks.c b/sys/dev/acpi/acpi_quirks.c
index 3f31c87d3f8..818a38b7ca0 100644
--- a/sys/dev/acpi/acpi_quirks.c
+++ b/sys/dev/acpi/acpi_quirks.c
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_quirks.c,v 1.6 2005/12/11 12:21:02 christos Exp $ */
+/* $NetBSD: acpi_quirks.c,v 1.7 2006/07/04 00:30:23 christos Exp $ */
/*
* Copyright 2002 Wasabi Systems, Inc.
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_quirks.c,v 1.6 2005/12/11 12:21:02 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_quirks.c,v 1.7 2006/07/04 00:30:23 christos Exp $");
#include "opt_acpi.h"
@@ -52,20 +52,49 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_quirks.c,v 1.6 2005/12/11 12:21:02 christos Exp
#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[] = {
- /*
- * 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 },
+ { 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,14 +104,35 @@ acpi_find_quirks(void)
{
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];
- if (!strncmp(aqp->aq_oemid, AcpiGbl_XSDT->OemId, strlen(aqp->aq_oemid)) &&
- aqp->aq_oemrev == AcpiGbl_XSDT->OemRevision)
- return aqp->aq_quirks;
+ /* 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;
}
diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h
index ea07e9397e6..fd3417aa41f 100644
--- a/sys/dev/acpi/acpivar.h
+++ b/sys/dev/acpi/acpivar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: acpivar.h,v 1.25 2005/12/12 15:04:50 cube Exp $ */
+/* $NetBSD: acpivar.h,v 1.26 2006/07/04 00:30:23 christos Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -276,9 +276,20 @@ ACPI_STATUS acpi_resource_parse(struct device *, ACPI_HANDLE, const char *,
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,12 +316,22 @@ ACPI_STATUS acpi_enter_sleep_state(struct acpi_softc *, int);
* quirk handling
*/
struct acpi_quirk {
- const char *aq_oemid; /* compared against the X/RSDT OemId */
- int aq_oemrev; /* compared against the X/RSDT OemRev */
+ 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 ACPI_QUIRK_BADPCI 0x00000001 /* bad PCI hierarchy */
-#define ACPI_QUIRK_BADIRQ 0x00000002 /* bad IRQ information */
+#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);
diff --git a/sys/dev/acpi/files.acpi b/sys/dev/acpi/files.acpi
index 445341523ae..4a0ff6b3166 100644
--- a/sys/dev/acpi/files.acpi
+++ b/sys/dev/acpi/files.acpi
@@ -1,8 +1,9 @@
-# $NetBSD: files.acpi,v 1.36 2006/06/21 17:47:23 drochner Exp $
+# $NetBSD: files.acpi,v 1.37 2006/07/04 00:30:23 christos Exp $
include "dev/acpi/acpica/files.acpica"
-defflag opt_acpi.h ACPIVERBOSE ACPI_DEBUG ACPI_ACTIVATE_DEV ACPI_DSDT_OVERRIDE
+defflag opt_acpi.h ACPIVERBOSE ACPI_DEBUG ACPI_ACTIVATE_DEV
+ ACPI_DSDT_OVERRIDE ACPI_SCANPCI
defparam opt_acpi.h ACPI_DSDT_FILE
device acpi { }: sysmon_power, sysmon_taskq
@@ -10,7 +11,8 @@ attach acpi at acpibus
file dev/acpi/acpi.c acpi needs-flag
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_madt.c acpi
+file dev/acpi/acpi_pci_link.c acpi
file dev/acpi/acpi_quirks.c acpi
file dev/acpi/acpi_timer.c acpi
diff --git a/sys/dev/pci/pccbb.c b/sys/dev/pci/pccbb.c
index 59db2077090..7cda103af2e 100644
--- a/sys/dev/pci/pccbb.c
+++ b/sys/dev/pci/pccbb.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pccbb.c,v 1.129 2006/06/17 17:06:51 jmcneill Exp $ */
+/* $NetBSD: pccbb.c,v 1.130 2006/07/04 00:30:23 christos Exp $ */
/*
* Copyright (c) 1998, 1999 and 2000
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pccbb.c,v 1.129 2006/06/17 17:06:51 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pccbb.c,v 1.130 2006/07/04 00:30:23 christos Exp $");
/*
#define CBB_DEBUG
@@ -80,6 +80,7 @@ __KERNEL_RCSID(0, "$NetBSD: pccbb.c,v 1.129 2006/06/17 17:06:51 jmcneill Exp $")
#if defined(__i386__)
#include "ioapic.h"
+#include "acpi.h"
#endif
#ifndef __NetBSD_Version__
@@ -525,9 +526,7 @@ pccbbattach(parent, self, aux)
* 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 NIOAPIC == 0 && ACPI == 0
if ((0 == pa->pa_intrline) || (255 == pa->pa_intrline)) {
printf("%s: NOT USED because of unconfigured interrupt\n",
sc->sc_dev.dv_xname);