2000-10-28 06:59:48 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 Michael Smith
|
|
|
|
* Copyright (c) 2000 BSDi
|
|
|
|
* 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.
|
|
|
|
*/
|
2003-08-24 17:55:58 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-10-28 06:59:48 +00:00
|
|
|
#include "opt_acpi.h"
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/bus.h>
|
2001-07-05 07:20:51 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
#include "acpi.h"
|
|
|
|
#include <dev/acpica/acpivar.h>
|
2002-08-26 18:30:27 +00:00
|
|
|
#include <dev/acpica/acpi_pcibvar.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2003-08-22 06:06:16 +00:00
|
|
|
#include <dev/pci/pcivar.h>
|
2000-10-28 06:59:48 +00:00
|
|
|
#include "pcib_if.h"
|
|
|
|
|
2004-03-22 20:32:27 +00:00
|
|
|
/* Hooks for the ACPI CA debugging infrastructure. */
|
2001-06-29 20:32:29 +00:00
|
|
|
#define _COMPONENT ACPI_BUS
|
2002-02-23 05:27:49 +00:00
|
|
|
ACPI_MODULE_NAME("PCI")
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2004-08-13 06:22:07 +00:00
|
|
|
ACPI_SERIAL_DECL(pcib, "ACPI PCI bus methods");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For locking, we assume the caller is not concurrent since this is
|
|
|
|
* triggered by newbus methods.
|
|
|
|
*/
|
2002-08-26 18:30:27 +00:00
|
|
|
int
|
|
|
|
acpi_pcib_attach(device_t dev, ACPI_BUFFER *prt, int busno)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
|
|
|
device_t child;
|
|
|
|
ACPI_STATUS status;
|
2000-12-08 09:16:20 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't attach if we're not really there.
|
|
|
|
*
|
2002-08-26 18:30:27 +00:00
|
|
|
* XXX: This isn't entirely correct since we may be a PCI bus
|
2000-10-28 06:59:48 +00:00
|
|
|
* on a hot-plug docking station, etc.
|
|
|
|
*/
|
|
|
|
if (!acpi_DeviceIsPresent(dev))
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VALUE(ENXIO);
|
2000-10-28 06:59:48 +00:00
|
|
|
|
2001-07-05 07:20:51 +00:00
|
|
|
/*
|
2004-03-22 20:32:27 +00:00
|
|
|
* Get the PCI interrupt routing table for this bus. If we can't
|
|
|
|
* get it, this is not an error but may reduce functionality.
|
2001-07-05 07:20:51 +00:00
|
|
|
*/
|
2002-08-26 18:30:27 +00:00
|
|
|
prt->Length = ACPI_ALLOCATE_BUFFER;
|
|
|
|
status = AcpiGetIrqRoutingTable(acpi_get_handle(dev), prt);
|
|
|
|
if (ACPI_FAILURE(status))
|
2002-10-04 00:32:09 +00:00
|
|
|
device_printf(dev,
|
|
|
|
"could not get PCI interrupt routing table for %s - %s\n",
|
|
|
|
acpi_name(acpi_get_handle(dev)), AcpiFormatException(status));
|
2001-07-05 07:20:51 +00:00
|
|
|
|
2000-12-01 10:18:57 +00:00
|
|
|
/*
|
|
|
|
* Attach the PCI bus proper.
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
2002-08-26 18:30:27 +00:00
|
|
|
if ((child = device_add_child(dev, "pci", busno)) == NULL) {
|
2002-10-29 19:08:55 +00:00
|
|
|
device_printf(device_get_parent(dev), "couldn't attach pci bus\n");
|
2000-12-08 09:16:20 +00:00
|
|
|
return_VALUE(ENXIO);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-12-02 01:14:14 +00:00
|
|
|
* Now go scan the bus.
|
2000-10-28 06:59:48 +00:00
|
|
|
*/
|
2002-10-05 02:01:05 +00:00
|
|
|
acpi_pci_link_config(dev, prt, busno);
|
2004-03-22 20:32:27 +00:00
|
|
|
|
|
|
|
return_VALUE (bus_generic_attach(dev));
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|
|
|
|
|
2002-10-05 02:01:05 +00:00
|
|
|
int
|
2004-08-11 14:52:50 +00:00
|
|
|
acpi_pcib_resume(device_t dev)
|
2002-10-05 02:01:05 +00:00
|
|
|
{
|
2004-08-11 14:52:50 +00:00
|
|
|
acpi_pci_link_resume(dev);
|
2002-10-05 02:01:05 +00:00
|
|
|
return (bus_generic_resume(dev));
|
|
|
|
}
|
|
|
|
|
2001-07-05 07:20:51 +00:00
|
|
|
/*
|
|
|
|
* Route an interrupt for a child of the bridge.
|
|
|
|
*/
|
2002-08-26 18:30:27 +00:00
|
|
|
int
|
2004-08-11 14:52:50 +00:00
|
|
|
acpi_pcib_route_interrupt(device_t pcib, device_t dev, int pin)
|
2000-10-28 06:59:48 +00:00
|
|
|
{
|
2004-08-11 14:52:50 +00:00
|
|
|
struct acpi_prt_entry *entry;
|
|
|
|
int i, interrupt;
|
|
|
|
struct acpi_pci_link_entry *link;
|
2002-02-23 05:27:49 +00:00
|
|
|
ACPI_PCI_ROUTING_TABLE *prt;
|
2001-08-26 22:50:15 +00:00
|
|
|
|
2002-05-19 06:16:47 +00:00
|
|
|
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
|
2004-08-11 14:52:50 +00:00
|
|
|
|
2004-06-07 17:36:22 +00:00
|
|
|
interrupt = PCI_INVALID_IRQ;
|
2001-07-05 07:20:51 +00:00
|
|
|
|
2004-03-22 20:32:27 +00:00
|
|
|
/* ACPI numbers pins 0-3, not 1-4 like the BIOS. */
|
2001-07-05 07:20:51 +00:00
|
|
|
pin--;
|
|
|
|
|
2004-08-13 06:22:07 +00:00
|
|
|
ACPI_SERIAL_BEGIN(pcib);
|
|
|
|
|
2004-08-11 14:52:50 +00:00
|
|
|
/* Look up the PRT entry for this device. */
|
|
|
|
entry = acpi_pci_find_prt(pcib, dev, pin);
|
2004-08-12 02:06:19 +00:00
|
|
|
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);
|
2001-07-05 07:20:51 +00:00
|
|
|
goto out;
|
2004-08-12 02:06:19 +00:00
|
|
|
}
|
2004-08-11 14:52:50 +00:00
|
|
|
prt = &entry->prt;
|
|
|
|
link = entry->pci_link;
|
2004-08-12 17:04:19 +00:00
|
|
|
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));
|
|
|
|
printf("\n");
|
|
|
|
}
|
2001-07-05 07:20:51 +00:00
|
|
|
|
|
|
|
/*
|
2004-08-11 14:52:50 +00:00
|
|
|
* If source is empty/NULL, the source index is a global IRQ number
|
|
|
|
* and it's hard-wired so we're done.
|
2001-07-05 07:20:51 +00:00
|
|
|
*/
|
2004-03-22 20:32:27 +00:00
|
|
|
if (prt->Source == NULL || prt->Source[0] == '\0') {
|
2001-10-07 18:25:43 +00:00
|
|
|
if (bootverbose)
|
2004-08-11 14:52:50 +00:00
|
|
|
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;
|
|
|
|
else
|
|
|
|
device_printf(pcib, "error: invalid hard-wired IRQ of 0\n");
|
2001-07-05 07:20:51 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2004-08-11 14:52:50 +00:00
|
|
|
/* 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);
|
2001-07-05 07:20:51 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2004-08-11 14:52:50 +00:00
|
|
|
/* There has to be at least one interrupt available. */
|
|
|
|
if (link->number_of_interrupts == 0) {
|
|
|
|
device_printf(pcib, "device has no interrupts\n");
|
2001-07-05 07:20:51 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-08-11 14:52:50 +00:00
|
|
|
* 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.
|
2001-07-05 07:20:51 +00:00
|
|
|
*/
|
2004-08-11 14:52:50 +00:00
|
|
|
if (link->flags & ACPI_LINK_ROUTED) {
|
|
|
|
interrupt = link->current_irq;
|
2004-07-01 07:46:29 +00:00
|
|
|
if (bootverbose)
|
2004-08-11 14:52:50 +00:00
|
|
|
device_printf(pcib, "slot %d INT%c is already routed to irq %d\n",
|
|
|
|
pci_get_slot(dev), 'A' + pin, interrupt);
|
2001-07-05 07:20:51 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2004-07-01 07:46:29 +00:00
|
|
|
if (bootverbose) {
|
|
|
|
device_printf(pcib, "possible interrupts:");
|
2004-08-11 14:52:50 +00:00
|
|
|
for (i = 0; i < link->number_of_interrupts; i++)
|
|
|
|
printf("%3d", link->interrupts[i]);
|
2004-07-01 07:46:29 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
2001-07-30 09:01:18 +00:00
|
|
|
|
2004-08-11 14:52:50 +00:00
|
|
|
/*
|
|
|
|
* 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);
|
2004-03-22 20:32:27 +00:00
|
|
|
|
2004-08-11 14:52:50 +00:00
|
|
|
if (bootverbose && PCI_INTERRUPT_VALID(interrupt))
|
2004-07-01 07:46:29 +00:00
|
|
|
device_printf(pcib, "slot %d INT%c routed to irq %d via %s\n",
|
2004-08-11 14:52:50 +00:00
|
|
|
pci_get_slot(dev), 'A' + pin, interrupt,
|
|
|
|
acpi_name(entry->prt_source));
|
2001-07-05 07:20:51 +00:00
|
|
|
|
2004-03-22 20:32:27 +00:00
|
|
|
out:
|
2004-08-13 06:22:07 +00:00
|
|
|
ACPI_SERIAL_END(pcib);
|
2001-07-05 07:20:51 +00:00
|
|
|
|
2004-03-22 20:32:27 +00:00
|
|
|
return_VALUE (interrupt);
|
2000-10-28 06:59:48 +00:00
|
|
|
}
|