int acpi_pcib_attach(device_t dev, ACPI_BUFFER *prt, int busno) { ACPI_STATUS status; int error; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); /* * Don't attach if we're not really there. * * XXX: This isn't entirely correct since we may be a PCI bus * on a hot-plug docking station, etc. */ if (!acpi_DeviceIsPresent(dev)) return_VALUE(ENXIO); /* * Get the PCI interrupt routing table for this bus. If we can't * get it, this is not an error but may reduce functionality. There * are several valid bridges in the field that do not have a _PRT, so * only warn about missing tables if bootverbose is set. */ prt->Length = ACPI_ALLOCATE_BUFFER; status = AcpiGetIrqRoutingTable(acpi_get_handle(dev), prt); if (ACPI_FAILURE(status) && (bootverbose || status != AE_NOT_FOUND)) device_printf(dev, "could not get PCI interrupt routing table for %s - %s\n", acpi_name(acpi_get_handle(dev)), AcpiFormatException(status)); /* * Attach the PCI bus proper. */ if (device_add_child(dev, "pci", busno) == NULL) { device_printf(device_get_parent(dev), "couldn't attach pci bus\n"); return_VALUE(ENXIO); } /* * Now go scan the bus. */ prt_walk_table(prt, prt_attach_devices, dev); error = bus_generic_attach(dev); return_VALUE(error); }
int acpi_pcib_attach(device_t dev, ACPI_BUFFER *prt, int busno) { device_t child; ACPI_STATUS status; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); if (!acpi_DeviceIsPresent(dev)) { /* Caller should already have checked it */ panic("%s device is not present", __func__); } ACPI_SERIAL_INIT(pcib); /* * Get the PCI interrupt routing table for this bus. If we can't * get it, this is not an error but may reduce functionality. There * are several valid bridges in the field that do not have a _PRT, so * only warn about missing tables if bootverbose is set. */ prt->Length = ACPI_ALLOCATE_BUFFER; status = AcpiGetIrqRoutingTable(acpi_get_handle(dev), prt); if (ACPI_FAILURE(status) && (bootverbose || status != AE_NOT_FOUND)) device_printf(dev, "could not get PCI interrupt routing table for %s - %s\n", acpi_name(acpi_get_handle(dev)), AcpiFormatException(status)); /* * Attach the PCI bus proper. */ if ((child = device_add_child(dev, "pci", busno)) == NULL) { device_printf(device_get_parent(dev), "couldn't attach pci bus\n"); return_VALUE(ENXIO); } /* * Now go scan the bus. */ prt_walk_table(prt, prt_attach_devices, dev); return_VALUE (bus_generic_attach(dev)); }
/* * Route an interrupt for a child of the bridge. */ int acpi_pcib_route_interrupt(device_t pcib, device_t dev, int pin, ACPI_BUFFER *prtbuf) { ACPI_PCI_ROUTING_TABLE *prt; struct prt_lookup_request pr; ACPI_HANDLE lnkdev; int interrupt; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); interrupt = PCI_INVALID_IRQ; /* ACPI numbers pins 0-3, not 1-4 like the BIOS. */ pin--; ACPI_SERIAL_BEGIN(pcib); /* 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) { 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 = 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 != NULL && prt->Source[0] != '\0') printf(" (src %s:%u)", prt->Source, prt->SourceIndex); printf("\n"); } /* * If source is empty/NULL, the source index is a global IRQ number * and it's hard-wired so we're done. * * XXX: If the source index is non-zero, ignore the source device and * assume that this is a hard-wired entry. */ if (prt->Source == NULL || prt->Source[0] == '\0' || prt->SourceIndex != 0) { if (bootverbose) device_printf(pcib, "slot %d INT%c hardwired to IRQ %d\n", pci_get_slot(dev), 'A' + pin, prt->SourceIndex); if (prt->SourceIndex) { interrupt = prt->SourceIndex; BUS_CONFIG_INTR(dev, interrupt, INTR_TRIGGER_LEVEL, INTR_POLARITY_LOW); } else device_printf(pcib, "error: invalid hard-wired IRQ of 0\n"); goto out; } /* * We have to find the source device (PCI interrupt link device). */ 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; } 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(lnkdev)); out: ACPI_SERIAL_END(pcib); return_VALUE(interrupt); }