summaryrefslogtreecommitdiffstats
path: root/sys/dev/acpica/acpi_pcib.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2004-11-23 22:26:44 +0000
committerjhb <jhb@FreeBSD.org>2004-11-23 22:26:44 +0000
commitfb979fee7e3df1dfcf653e7ecb6dfd0d5e29d725 (patch)
treeb12db010cf220f4fc5b064dcbaea39d6686d6afa /sys/dev/acpica/acpi_pcib.c
parent278f52e7a7437df96f1c2a2f1513356a05dcc7dc (diff)
downloadFreeBSD-src-fb979fee7e3df1dfcf653e7ecb6dfd0d5e29d725.zip
FreeBSD-src-fb979fee7e3df1dfcf653e7ecb6dfd0d5e29d725.tar.gz
Rework the ACPI PCI link code.
- Use a new-bus device driver for the ACPI PCI link devices. The devices are called pci_linkX. The driver includes suspend/resume support so that the ACPI bridge drivers no longer have to poke the links to get them to handle suspend/resume. Also, the code to handle which IRQs a link is routed to and choosing an IRQ when a link is not already routed is all contained in the link driver. The PCI bridge drivers now ask the link driver which IRQ to use once they determine that a _PRT entry does not use a hardwired interrupt number. - The new link driver includes support for multiple IRQ resources per link device as well as preserving any non-IRQ resources when adjusting the IRQ that a link is routed to. - The entire approach to routing when using a link device is now link-centric rather than pci bus/device/pin specific. Thus, when using a tunable to override the default IRQ settings, one now uses a single tunable to route an entire link rather than routing a single device that uses the link (which has great foot-shooting potential if the user tries to route the same link to two different IRQs using two different pci bus/device/pin hints). For example, to adjust the IRQ that \_SB_.LNKA uses, one would set 'hw.pci.link.LNKA.irq=10' from the loader. - As a side effect of having the link driver, unused link devices will now be disabled when they are probed. - The algorithm for choosing an IRQ for a link that doesn't already have an IRQ assigned is now much closer to the one used in $PIR routing. When a link is routed via an ISA IRQ, only known-good IRQs that the BIOS has already used are used for routing instead of using probabilities to guess at which IRQs are probably not used by an ISA device. One change from $PIR is that the SCI is always considered a viable ISA IRQ, so that if the BIOS does not setup any IRQs the kernel will degenerate to routing all interrupts over the SCI. For non ISA IRQs, interrupts are picked from the possible pool using a simplistic weighting algorithm. Tested by: ru, scottl, others on acpi@ Reviewed by: njl
Diffstat (limited to 'sys/dev/acpica/acpi_pcib.c')
-rw-r--r--sys/dev/acpica/acpi_pcib.c170
1 files changed, 116 insertions, 54 deletions
diff --git a/sys/dev/acpica/acpi_pcib.c b/sys/dev/acpica/acpi_pcib.c
index 0a41ddc..51c3207 100644
--- a/sys/dev/acpica/acpi_pcib.c
+++ b/sys/dev/acpica/acpi_pcib.c
@@ -51,6 +51,73 @@ ACPI_SERIAL_DECL(pcib, "ACPI PCI bus methods");
* For locking, we assume the caller is not concurrent since this is
* triggered by newbus methods.
*/
+
+struct prt_lookup_request {
+ ACPI_PCI_ROUTING_TABLE *pr_entry;
+ u_int pr_pin;
+ u_int pr_slot;
+};
+
+typedef void prt_entry_handler(ACPI_PCI_ROUTING_TABLE *entry, void *arg);
+
+static void prt_attach_devices(ACPI_PCI_ROUTING_TABLE *entry, void *arg);
+static void prt_lookup_device(ACPI_PCI_ROUTING_TABLE *entry, void *arg);
+static void prt_walk_table(ACPI_BUFFER *prt, prt_entry_handler *handler,
+ void *arg);
+
+static void
+prt_walk_table(ACPI_BUFFER *prt, prt_entry_handler *handler, void *arg)
+{
+ ACPI_PCI_ROUTING_TABLE *entry;
+ char *prtptr;
+
+ /* First check to see if there is a table to walk. */
+ if (prt == NULL || prt->Pointer == NULL)
+ return;
+
+ /* Walk the table executing the handler function for each entry. */
+ prtptr = prt->Pointer;
+ entry = (ACPI_PCI_ROUTING_TABLE *)prtptr;
+ while (entry->Length != 0) {
+ handler(entry, arg);
+ prtptr += entry->Length;
+ entry = (ACPI_PCI_ROUTING_TABLE *)prtptr;
+ }
+}
+
+static void
+prt_attach_devices(ACPI_PCI_ROUTING_TABLE *entry, void *arg)
+{
+ ACPI_HANDLE handle;
+ device_t child, pcib;
+ int error;
+
+ /* We only care about entries that reference a link device. */
+ if (entry->Source == NULL || entry->Source[0] == '\0')
+ return;
+
+ /* Lookup the associated handle and device. */
+ pcib = (device_t)arg;
+ if (ACPI_FAILURE(AcpiGetHandle(acpi_get_handle(pcib), entry->Source,
+ &handle)))
+ return;
+ child = acpi_get_device(handle);
+ if (child == NULL)
+ return;
+
+ /* If the device hasn't been probed yet, force it to do so. */
+ error = device_probe_and_attach(child);
+ if (error != 0) {
+ device_printf((device_t)arg, "failed to force attach of %s\n",
+ acpi_name(handle));
+ return;
+ }
+
+ /* Add a reference for a specific bus/device/pin tuple. */
+ acpi_pci_link_add_reference(child, entry->SourceIndex, pcib,
+ ACPI_ADR_PCI_SLOT(entry->Address), entry->Pin);
+}
+
int
acpi_pcib_attach(device_t dev, ACPI_BUFFER *prt, int busno)
{
@@ -92,7 +159,7 @@ acpi_pcib_attach(device_t dev, ACPI_BUFFER *prt, int busno)
/*
* Now go scan the bus.
*/
- acpi_pci_link_config(dev, prt, busno);
+ prt_walk_table(prt, prt_attach_devices, dev);
return_VALUE (bus_generic_attach(dev));
}
@@ -100,20 +167,43 @@ acpi_pcib_attach(device_t dev, ACPI_BUFFER *prt, int busno)
int
acpi_pcib_resume(device_t dev)
{
- acpi_pci_link_resume(dev);
+
return (bus_generic_resume(dev));
}
+static void
+prt_lookup_device(ACPI_PCI_ROUTING_TABLE *entry, void *arg)
+{
+ struct prt_lookup_request *pr;
+
+ pr = (struct prt_lookup_request *)arg;
+ if (pr->pr_entry != NULL)
+ return;
+
+ /*
+ * Compare the slot number (high word of Address) and pin number
+ * (note that ACPI uses 0 for INTA) to check for a match.
+ *
+ * Note that the low word of the Address field (function number)
+ * is required by the specification to be 0xffff. We don't risk
+ * checking it here.
+ */
+ if (ACPI_ADR_PCI_SLOT(entry->Address) == pr->pr_slot &&
+ entry->Pin == pr->pr_pin)
+ pr->pr_entry = entry;
+}
+
/*
* Route an interrupt for a child of the bridge.
*/
int
-acpi_pcib_route_interrupt(device_t pcib, device_t dev, int pin)
+acpi_pcib_route_interrupt(device_t pcib, device_t dev, int pin,
+ ACPI_BUFFER *prtbuf)
{
- struct acpi_prt_entry *entry;
- int i, interrupt;
- struct acpi_pci_link_entry *link;
- ACPI_PCI_ROUTING_TABLE *prt;
+ ACPI_PCI_ROUTING_TABLE *prt;
+ struct prt_lookup_request pr;
+ ACPI_HANDLE lnkdev;
+ int interrupt;
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
@@ -124,20 +214,20 @@ acpi_pcib_route_interrupt(device_t pcib, device_t dev, int pin)
ACPI_SERIAL_BEGIN(pcib);
- /* Look up the PRT entry for this device. */
- entry = acpi_pci_find_prt(pcib, dev, pin);
- if (entry == NULL) {
- device_printf(pcib, "no PRT entry for %d.%d.INT%c\n", pci_get_bus(dev),
- pci_get_slot(dev), 'A' + pin);
- goto out;
- }
- prt = &entry->prt;
- link = entry->pci_link;
+ /* Search for a matching entry in the routing table. */
+ pr.pr_entry = NULL;
+ pr.pr_pin = pin;
+ pr.pr_slot = pci_get_slot(dev);
+ prt_walk_table(prtbuf, prt_lookup_device, &pr);
+ if (pr.pr_entry == NULL)
+ return (PCI_INVALID_IRQ);
+ prt = pr.pr_entry;
+
if (bootverbose) {
device_printf(pcib, "matched entry for %d.%d.INT%c",
pci_get_bus(dev), pci_get_slot(dev), 'A' + pin);
- if (prt->Source[0] != '\0')
- printf(" (src %s)", acpi_name(entry->prt_source));
+ if (prt->Source != NULL && prt->Source[0] != '\0')
+ printf(" (src %s:%u)", prt->Source, prt->SourceIndex);
printf("\n");
}
@@ -156,48 +246,20 @@ acpi_pcib_route_interrupt(device_t pcib, device_t dev, int pin)
goto out;
}
- /* XXX Support for multiple resources must be added to the link code. */
- if (prt->SourceIndex) {
- device_printf(pcib, "src index %d not yet supported\n",
- prt->SourceIndex);
- goto out;
- }
-
- /* There has to be at least one interrupt available. */
- if (link->number_of_interrupts == 0) {
- device_printf(pcib, "device has no interrupts\n");
- goto out;
- }
-
- /*
- * If the current interrupt has been routed, we're done. This is the
- * case when the BIOS initializes it and we didn't disable it.
+ /*
+ * We have to find the source device (PCI interrupt link device).
*/
- if (link->flags & ACPI_LINK_ROUTED) {
- interrupt = link->current_irq;
- if (bootverbose)
- device_printf(pcib, "slot %d INT%c is already routed to irq %d\n",
- pci_get_slot(dev), 'A' + pin, interrupt);
+ if (ACPI_FAILURE(AcpiGetHandle(ACPI_ROOT_OBJECT, prt->Source, &lnkdev))) {
+ device_printf(pcib, "couldn't find PCI interrupt link device %s\n",
+ prt->Source);
goto out;
}
-
- if (bootverbose) {
- device_printf(pcib, "possible interrupts:");
- for (i = 0; i < link->number_of_interrupts; i++)
- printf("%3d", link->interrupts[i]);
- printf("\n");
- }
-
- /*
- * Perform the link routing. The link code will pick the best IRQ
- * for this pin and configure it.
- */
- interrupt = acpi_pci_link_route(dev, entry);
+ interrupt = acpi_pci_link_route_interrupt(acpi_get_device(lnkdev),
+ prt->SourceIndex);
if (bootverbose && PCI_INTERRUPT_VALID(interrupt))
device_printf(pcib, "slot %d INT%c routed to irq %d via %s\n",
- pci_get_slot(dev), 'A' + pin, interrupt,
- acpi_name(entry->prt_source));
+ pci_get_slot(dev), 'A' + pin, interrupt, acpi_name(lnkdev));
out:
ACPI_SERIAL_END(pcib);
OpenPOWER on IntegriCloud