acpi_pcib.c revision 133500
1/*- 2 * Copyright (c) 2000 Michael Smith 3 * Copyright (c) 2000 BSDi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> 29__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_pcib.c 133500 2004-08-11 14:52:50Z njl $"); 30 31#include "opt_acpi.h" 32#include <sys/param.h> 33#include <sys/bus.h> 34#include <sys/malloc.h> 35#include <sys/kernel.h> 36 37#include "acpi.h" 38#include <dev/acpica/acpivar.h> 39#include <dev/acpica/acpi_pcibvar.h> 40 41#include <dev/pci/pcivar.h> 42#include "pcib_if.h" 43 44/* Hooks for the ACPI CA debugging infrastructure. */ 45#define _COMPONENT ACPI_BUS 46ACPI_MODULE_NAME("PCI") 47 48int 49acpi_pcib_attach(device_t dev, ACPI_BUFFER *prt, int busno) 50{ 51 device_t child; 52 ACPI_STATUS status; 53 54 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 55 56 /* 57 * Don't attach if we're not really there. 58 * 59 * XXX: This isn't entirely correct since we may be a PCI bus 60 * on a hot-plug docking station, etc. 61 */ 62 if (!acpi_DeviceIsPresent(dev)) 63 return_VALUE(ENXIO); 64 65 /* 66 * Get the PCI interrupt routing table for this bus. If we can't 67 * get it, this is not an error but may reduce functionality. 68 */ 69 prt->Length = ACPI_ALLOCATE_BUFFER; 70 status = AcpiGetIrqRoutingTable(acpi_get_handle(dev), prt); 71 if (ACPI_FAILURE(status)) 72 device_printf(dev, 73 "could not get PCI interrupt routing table for %s - %s\n", 74 acpi_name(acpi_get_handle(dev)), AcpiFormatException(status)); 75 76 /* 77 * Attach the PCI bus proper. 78 */ 79 if ((child = device_add_child(dev, "pci", busno)) == NULL) { 80 device_printf(device_get_parent(dev), "couldn't attach pci bus\n"); 81 return_VALUE(ENXIO); 82 } 83 84 /* 85 * Now go scan the bus. 86 */ 87 acpi_pci_link_config(dev, prt, busno); 88 89 return_VALUE (bus_generic_attach(dev)); 90} 91 92int 93acpi_pcib_resume(device_t dev) 94{ 95 acpi_pci_link_resume(dev); 96 return (bus_generic_resume(dev)); 97} 98 99/* 100 * Route an interrupt for a child of the bridge. 101 */ 102int 103acpi_pcib_route_interrupt(device_t pcib, device_t dev, int pin) 104{ 105 struct acpi_prt_entry *entry; 106 int i, interrupt; 107 struct acpi_pci_link_entry *link; 108 ACPI_PCI_ROUTING_TABLE *prt; 109 110 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); 111 112 interrupt = PCI_INVALID_IRQ; 113 114 /* ACPI numbers pins 0-3, not 1-4 like the BIOS. */ 115 pin--; 116 117 /* Look up the PRT entry for this device. */ 118 entry = acpi_pci_find_prt(pcib, dev, pin); 119 if (entry == NULL) 120 goto out; 121 prt = &entry->prt; 122 link = entry->pci_link; 123 if (bootverbose) 124 device_printf(pcib, "matched entry for %d.%d.INT%c (src %s)\n", 125 pci_get_bus(dev), pci_get_slot(dev), 'A' + pin, 126 acpi_name(entry->prt_source)); 127 128 /* 129 * If source is empty/NULL, the source index is a global IRQ number 130 * and it's hard-wired so we're done. 131 */ 132 if (prt->Source == NULL || prt->Source[0] == '\0') { 133 if (bootverbose) 134 device_printf(pcib, "slot %d INT%c hardwired to IRQ %d\n", 135 pci_get_slot(dev), 'A' + pin, prt->SourceIndex); 136 if (prt->SourceIndex) 137 interrupt = prt->SourceIndex; 138 else 139 device_printf(pcib, "error: invalid hard-wired IRQ of 0\n"); 140 goto out; 141 } 142 143 /* XXX Support for multiple resources must be added to the link code. */ 144 if (prt->SourceIndex) { 145 device_printf(pcib, "src index %d not yet supported\n", 146 prt->SourceIndex); 147 goto out; 148 } 149 150 /* There has to be at least one interrupt available. */ 151 if (link->number_of_interrupts == 0) { 152 device_printf(pcib, "device has no interrupts\n"); 153 goto out; 154 } 155 156 /* 157 * If the current interrupt has been routed, we're done. This is the 158 * case when the BIOS initializes it and we didn't disable it. 159 */ 160 if (link->flags & ACPI_LINK_ROUTED) { 161 interrupt = link->current_irq; 162 if (bootverbose) 163 device_printf(pcib, "slot %d INT%c is already routed to irq %d\n", 164 pci_get_slot(dev), 'A' + pin, interrupt); 165 goto out; 166 } 167 168 if (bootverbose) { 169 device_printf(pcib, "possible interrupts:"); 170 for (i = 0; i < link->number_of_interrupts; i++) 171 printf("%3d", link->interrupts[i]); 172 printf("\n"); 173 } 174 175 /* 176 * Perform the link routing. The link code will pick the best IRQ 177 * for this pin and configure it. 178 */ 179 interrupt = acpi_pci_link_route(dev, entry); 180 181 if (bootverbose && PCI_INTERRUPT_VALID(interrupt)) 182 device_printf(pcib, "slot %d INT%c routed to irq %d via %s\n", 183 pci_get_slot(dev), 'A' + pin, interrupt, 184 acpi_name(entry->prt_source)); 185 186out: 187 188 return_VALUE (interrupt); 189} 190