Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * pci_irq.c - ACPI PCI Interrupt Routing ($Revision: 11 $) |
| 3 | * |
| 4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
| 5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
| 6 | * Copyright (C) 2002 Dominik Brodowski <devel@brodo.de> |
| 7 | * |
| 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or (at |
| 13 | * your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 23 | * |
| 24 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 25 | */ |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Bjorn Helgaas | 391df5d | 2008-03-11 13:45:15 -0700 | [diff] [blame] | 28 | #include <linux/dmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/types.h> |
| 33 | #include <linux/proc_fs.h> |
| 34 | #include <linux/spinlock.h> |
| 35 | #include <linux/pm.h> |
| 36 | #include <linux/pci.h> |
| 37 | #include <linux/acpi.h> |
| 38 | #include <acpi/acpi_bus.h> |
| 39 | #include <acpi/acpi_drivers.h> |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define _COMPONENT ACPI_PCI_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 42 | ACPI_MODULE_NAME("pci_irq"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Bjorn Helgaas | f748baf | 2008-12-08 21:30:31 -0700 | [diff] [blame] | 44 | struct acpi_prt_entry { |
| 45 | struct list_head node; |
| 46 | struct acpi_pci_id id; |
| 47 | u8 pin; |
| 48 | struct { |
| 49 | acpi_handle handle; |
| 50 | u32 index; |
| 51 | } link; |
| 52 | u32 irq; |
| 53 | }; |
| 54 | |
| 55 | struct acpi_prt_list { |
| 56 | int count; |
| 57 | struct list_head entries; |
| 58 | }; |
| 59 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 60 | static struct acpi_prt_list acpi_prt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | static DEFINE_SPINLOCK(acpi_prt_lock); |
| 62 | |
Bjorn Helgaas | cf68b80 | 2008-12-08 21:30:36 -0700 | [diff] [blame] | 63 | static inline char pin_name(int pin) |
| 64 | { |
Bjorn Helgaas | e64e9db | 2008-12-08 21:30:41 -0700 | [diff] [blame] | 65 | return 'A' + pin - 1; |
Bjorn Helgaas | cf68b80 | 2008-12-08 21:30:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* -------------------------------------------------------------------------- |
| 69 | PCI IRQ Routing Table (PRT) Support |
| 70 | -------------------------------------------------------------------------- */ |
| 71 | |
Bjorn Helgaas | 063563b | 2008-12-08 21:30:51 -0700 | [diff] [blame] | 72 | static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(struct pci_dev *dev, |
| 73 | int pin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | struct acpi_prt_entry *entry = NULL; |
Bjorn Helgaas | 063563b | 2008-12-08 21:30:51 -0700 | [diff] [blame] | 76 | int segment = pci_domain_nr(dev->bus); |
| 77 | int bus = dev->bus->number; |
| 78 | int device = PCI_SLOT(dev->devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | if (!acpi_prt.count) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 81 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * Parse through all PRT entries looking for a match on the specified |
| 85 | * PCI device's segment, bus, device, and pin (don't care about func). |
| 86 | * |
| 87 | */ |
| 88 | spin_lock(&acpi_prt_lock); |
Matthias Kaehlcke | 1a3b77a | 2008-02-04 23:31:20 -0800 | [diff] [blame] | 89 | list_for_each_entry(entry, &acpi_prt.entries, node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | if ((segment == entry->id.segment) |
| 91 | && (bus == entry->id.bus) |
| 92 | && (device == entry->id.device) |
| 93 | && (pin == entry->pin)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | spin_unlock(&acpi_prt_lock); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 95 | return entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
| 99 | spin_unlock(&acpi_prt_lock); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 100 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Bjorn Helgaas | 391df5d | 2008-03-11 13:45:15 -0700 | [diff] [blame] | 103 | /* http://bugzilla.kernel.org/show_bug.cgi?id=4773 */ |
| 104 | static struct dmi_system_id medion_md9580[] = { |
| 105 | { |
| 106 | .ident = "Medion MD9580-F laptop", |
| 107 | .matches = { |
| 108 | DMI_MATCH(DMI_SYS_VENDOR, "MEDIONNB"), |
| 109 | DMI_MATCH(DMI_PRODUCT_NAME, "A555"), |
| 110 | }, |
| 111 | }, |
| 112 | { } |
| 113 | }; |
| 114 | |
| 115 | /* http://bugzilla.kernel.org/show_bug.cgi?id=5044 */ |
| 116 | static struct dmi_system_id dell_optiplex[] = { |
| 117 | { |
| 118 | .ident = "Dell Optiplex GX1", |
| 119 | .matches = { |
| 120 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), |
| 121 | DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex GX1 600S+"), |
| 122 | }, |
| 123 | }, |
| 124 | { } |
| 125 | }; |
| 126 | |
| 127 | /* http://bugzilla.kernel.org/show_bug.cgi?id=10138 */ |
| 128 | static struct dmi_system_id hp_t5710[] = { |
| 129 | { |
| 130 | .ident = "HP t5710", |
| 131 | .matches = { |
| 132 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), |
| 133 | DMI_MATCH(DMI_PRODUCT_NAME, "hp t5000 series"), |
| 134 | DMI_MATCH(DMI_BOARD_NAME, "098Ch"), |
| 135 | }, |
| 136 | }, |
| 137 | { } |
| 138 | }; |
| 139 | |
| 140 | struct prt_quirk { |
| 141 | struct dmi_system_id *system; |
| 142 | unsigned int segment; |
| 143 | unsigned int bus; |
| 144 | unsigned int device; |
| 145 | unsigned char pin; |
| 146 | char *source; /* according to BIOS */ |
| 147 | char *actual_source; |
| 148 | }; |
| 149 | |
Bjorn Helgaas | c458033 | 2008-12-08 21:30:46 -0700 | [diff] [blame] | 150 | #define PCI_INTX_PIN(c) (c - 'A' + 1) |
| 151 | |
Bjorn Helgaas | 391df5d | 2008-03-11 13:45:15 -0700 | [diff] [blame] | 152 | /* |
| 153 | * These systems have incorrect _PRT entries. The BIOS claims the PCI |
| 154 | * interrupt at the listed segment/bus/device/pin is connected to the first |
| 155 | * link device, but it is actually connected to the second. |
| 156 | */ |
| 157 | static struct prt_quirk prt_quirks[] = { |
Bjorn Helgaas | c458033 | 2008-12-08 21:30:46 -0700 | [diff] [blame] | 158 | { medion_md9580, 0, 0, 9, PCI_INTX_PIN('A'), |
Bjorn Helgaas | b97d480 | 2008-03-25 11:21:11 -0600 | [diff] [blame] | 159 | "\\_SB_.PCI0.ISA_.LNKA", |
| 160 | "\\_SB_.PCI0.ISA_.LNKB"}, |
Bjorn Helgaas | c458033 | 2008-12-08 21:30:46 -0700 | [diff] [blame] | 161 | { dell_optiplex, 0, 0, 0xd, PCI_INTX_PIN('A'), |
Bjorn Helgaas | 391df5d | 2008-03-11 13:45:15 -0700 | [diff] [blame] | 162 | "\\_SB_.LNKB", |
| 163 | "\\_SB_.LNKA"}, |
Bjorn Helgaas | c458033 | 2008-12-08 21:30:46 -0700 | [diff] [blame] | 164 | { hp_t5710, 0, 0, 1, PCI_INTX_PIN('A'), |
Bjorn Helgaas | 391df5d | 2008-03-11 13:45:15 -0700 | [diff] [blame] | 165 | "\\_SB_.PCI0.LNK1", |
| 166 | "\\_SB_.PCI0.LNK3"}, |
| 167 | }; |
| 168 | |
| 169 | static void |
| 170 | do_prt_fixups(struct acpi_prt_entry *entry, struct acpi_pci_routing_table *prt) |
| 171 | { |
| 172 | int i; |
| 173 | struct prt_quirk *quirk; |
| 174 | |
| 175 | for (i = 0; i < ARRAY_SIZE(prt_quirks); i++) { |
| 176 | quirk = &prt_quirks[i]; |
| 177 | |
| 178 | /* All current quirks involve link devices, not GSIs */ |
| 179 | if (!prt->source) |
| 180 | continue; |
| 181 | |
| 182 | if (dmi_check_system(quirk->system) && |
| 183 | entry->id.segment == quirk->segment && |
| 184 | entry->id.bus == quirk->bus && |
| 185 | entry->id.device == quirk->device && |
Bjorn Helgaas | c458033 | 2008-12-08 21:30:46 -0700 | [diff] [blame] | 186 | entry->pin == quirk->pin && |
Bjorn Helgaas | 391df5d | 2008-03-11 13:45:15 -0700 | [diff] [blame] | 187 | !strcmp(prt->source, quirk->source) && |
| 188 | strlen(prt->source) >= strlen(quirk->actual_source)) { |
| 189 | printk(KERN_WARNING PREFIX "firmware reports " |
Bjorn Helgaas | c83642d | 2008-06-27 08:45:39 -0600 | [diff] [blame] | 190 | "%04x:%02x:%02x PCI INT %c connected to %s; " |
Bjorn Helgaas | 391df5d | 2008-03-11 13:45:15 -0700 | [diff] [blame] | 191 | "changing to %s\n", |
| 192 | entry->id.segment, entry->id.bus, |
Bjorn Helgaas | cf68b80 | 2008-12-08 21:30:36 -0700 | [diff] [blame] | 193 | entry->id.device, pin_name(entry->pin), |
Bjorn Helgaas | 391df5d | 2008-03-11 13:45:15 -0700 | [diff] [blame] | 194 | prt->source, quirk->actual_source); |
| 195 | strcpy(prt->source, quirk->actual_source); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | acpi_pci_irq_add_entry(acpi_handle handle, |
| 202 | int segment, int bus, struct acpi_pci_routing_table *prt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | struct acpi_prt_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 206 | entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 208 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Bjorn Helgaas | e64e9db | 2008-12-08 21:30:41 -0700 | [diff] [blame] | 210 | /* |
| 211 | * Note that the _PRT uses 0=INTA, 1=INTB, etc, while PCI uses |
| 212 | * 1=INTA, 2=INTB. We use the PCI encoding throughout, so convert |
| 213 | * it here. |
| 214 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | entry->id.segment = segment; |
| 216 | entry->id.bus = bus; |
| 217 | entry->id.device = (prt->address >> 16) & 0xFFFF; |
Bjorn Helgaas | e64e9db | 2008-12-08 21:30:41 -0700 | [diff] [blame] | 218 | entry->pin = prt->pin + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Bjorn Helgaas | 391df5d | 2008-03-11 13:45:15 -0700 | [diff] [blame] | 220 | do_prt_fixups(entry, prt); |
| 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | /* |
| 223 | * Type 1: Dynamic |
| 224 | * --------------- |
| 225 | * The 'source' field specifies the PCI interrupt link device used to |
| 226 | * configure the IRQ assigned to this slot|dev|pin. The 'source_index' |
| 227 | * indicates which resource descriptor in the resource template (of |
| 228 | * the link device) this interrupt is allocated from. |
| 229 | * |
| 230 | * NOTE: Don't query the Link Device for IRQ information at this time |
| 231 | * because Link Device enumeration may not have occurred yet |
| 232 | * (e.g. exists somewhere 'below' this _PRT entry in the ACPI |
| 233 | * namespace). |
| 234 | */ |
| 235 | if (prt->source[0]) { |
| 236 | acpi_get_handle(handle, prt->source, &entry->link.handle); |
| 237 | entry->link.index = prt->source_index; |
| 238 | } |
| 239 | /* |
| 240 | * Type 2: Static |
| 241 | * -------------- |
| 242 | * The 'source' field is NULL, and the 'source_index' field specifies |
| 243 | * the IRQ value, which is hardwired to specific interrupt inputs on |
| 244 | * the interrupt controller. |
| 245 | */ |
| 246 | else |
| 247 | entry->link.index = prt->source_index; |
| 248 | |
| 249 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO, |
Bjorn Helgaas | 21a5328 | 2008-12-08 21:30:05 -0700 | [diff] [blame] | 250 | " %04x:%02x:%02x[%c] -> %s[%d]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 251 | entry->id.segment, entry->id.bus, |
Bjorn Helgaas | cf68b80 | 2008-12-08 21:30:36 -0700 | [diff] [blame] | 252 | entry->id.device, pin_name(entry->pin), |
| 253 | prt->source, entry->link.index)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | spin_lock(&acpi_prt_lock); |
| 256 | list_add_tail(&entry->node, &acpi_prt.entries); |
| 257 | acpi_prt.count++; |
| 258 | spin_unlock(&acpi_prt_lock); |
| 259 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 260 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 264 | acpi_pci_irq_del_entry(int segment, int bus, struct acpi_prt_entry *entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 266 | if (segment == entry->id.segment && bus == entry->id.bus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | acpi_prt.count--; |
| 268 | list_del(&entry->node); |
| 269 | kfree(entry); |
| 270 | } |
| 271 | } |
| 272 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 273 | int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
Bjorn Helgaas | 2320ac6 | 2008-12-08 21:30:15 -0700 | [diff] [blame] | 275 | acpi_status status; |
| 276 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 277 | struct acpi_pci_routing_table *entry; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 278 | static int first_time = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | if (first_time) { |
| 281 | acpi_prt.count = 0; |
| 282 | INIT_LIST_HEAD(&acpi_prt.entries); |
| 283 | first_time = 0; |
| 284 | } |
| 285 | |
Bjorn Helgaas | 2320ac6 | 2008-12-08 21:30:15 -0700 | [diff] [blame] | 286 | /* 'handle' is the _PRT's parent (root bridge or PCI-PCI bridge) */ |
| 287 | status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 288 | if (ACPI_FAILURE(status)) |
| 289 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n", |
Bjorn Helgaas | 2320ac6 | 2008-12-08 21:30:15 -0700 | [diff] [blame] | 292 | (char *) buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Bjorn Helgaas | 2320ac6 | 2008-12-08 21:30:15 -0700 | [diff] [blame] | 294 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Bjorn Helgaas | 2320ac6 | 2008-12-08 21:30:15 -0700 | [diff] [blame] | 296 | buffer.length = ACPI_ALLOCATE_BUFFER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | buffer.pointer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | status = acpi_get_irq_routing_table(handle, &buffer); |
| 300 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 301 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRT [%s]", |
| 302 | acpi_format_exception(status))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | kfree(buffer.pointer); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 304 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Bjorn Helgaas | 2320ac6 | 2008-12-08 21:30:15 -0700 | [diff] [blame] | 307 | entry = buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | while (entry && (entry->length > 0)) { |
| 309 | acpi_pci_irq_add_entry(handle, segment, bus, entry); |
| 310 | entry = (struct acpi_pci_routing_table *) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 311 | ((unsigned long)entry + entry->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Bjorn Helgaas | 2320ac6 | 2008-12-08 21:30:15 -0700 | [diff] [blame] | 314 | kfree(buffer.pointer); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 315 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 318 | void acpi_pci_irq_del_prt(int segment, int bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | struct list_head *node = NULL, *n = NULL; |
| 321 | struct acpi_prt_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 323 | if (!acpi_prt.count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | return; |
| 325 | } |
| 326 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 327 | printk(KERN_DEBUG |
Bjorn Helgaas | 21a5328 | 2008-12-08 21:30:05 -0700 | [diff] [blame] | 328 | "ACPI: Delete PCI Interrupt Routing Table for %04x:%02x\n", |
| 329 | segment, bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | spin_lock(&acpi_prt_lock); |
| 331 | list_for_each_safe(node, n, &acpi_prt.entries) { |
| 332 | entry = list_entry(node, struct acpi_prt_entry, node); |
| 333 | |
| 334 | acpi_pci_irq_del_entry(segment, bus, entry); |
| 335 | } |
| 336 | spin_unlock(&acpi_prt_lock); |
| 337 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | /* -------------------------------------------------------------------------- |
| 340 | PCI Interrupt Routing Support |
| 341 | -------------------------------------------------------------------------- */ |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 342 | static int |
| 343 | acpi_pci_allocate_irq(struct acpi_prt_entry *entry, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 344 | int *triggering, int *polarity, char **link) |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 345 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 346 | int irq; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 347 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 348 | |
| 349 | if (entry->link.handle) { |
| 350 | irq = acpi_pci_link_allocate_irq(entry->link.handle, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 351 | entry->link.index, triggering, |
| 352 | polarity, link); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 353 | if (irq < 0) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 354 | printk(KERN_WARNING PREFIX |
| 355 | "Invalid IRQ link routing entry\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 356 | return -1; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 357 | } |
| 358 | } else { |
| 359 | irq = entry->link.index; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 360 | *triggering = ACPI_LEVEL_SENSITIVE; |
| 361 | *polarity = ACPI_ACTIVE_LOW; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 362 | } |
| 363 | |
Bjorn Helgaas | c13f889 | 2008-12-08 21:30:26 -0700 | [diff] [blame] | 364 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found GSI %d\n", irq)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 365 | return irq; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | static int |
Bjorn Helgaas | beba8a6 | 2008-12-08 21:31:01 -0700 | [diff] [blame] | 369 | acpi_pci_free_irq(struct acpi_prt_entry *entry) |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 370 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 371 | int irq; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 372 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 373 | if (entry->link.handle) { |
| 374 | irq = acpi_pci_link_free_irq(entry->link.handle); |
| 375 | } else { |
| 376 | irq = entry->link.index; |
| 377 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 378 | return irq; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 379 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 380 | |
Bjorn Helgaas | beba8a6 | 2008-12-08 21:31:01 -0700 | [diff] [blame] | 381 | static struct acpi_prt_entry * |
| 382 | acpi_pci_irq_lookup(struct pci_dev *dev, int pin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
Bjorn Helgaas | beba8a6 | 2008-12-08 21:31:01 -0700 | [diff] [blame] | 384 | struct acpi_prt_entry *entry; |
Bjorn Helgaas | 5697b7c | 2008-12-08 21:31:16 -0700 | [diff] [blame^] | 385 | struct pci_dev *bridge; |
| 386 | u8 bridge_pin, orig_pin = pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Bjorn Helgaas | 063563b | 2008-12-08 21:30:51 -0700 | [diff] [blame] | 388 | entry = acpi_pci_irq_find_prt_entry(dev, pin); |
Bjorn Helgaas | 3b1ea18 | 2008-12-08 21:31:06 -0700 | [diff] [blame] | 389 | if (entry) { |
| 390 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %s[%c] _PRT entry\n", |
Bjorn Helgaas | 1350487 | 2008-12-08 21:30:56 -0700 | [diff] [blame] | 391 | pci_name(dev), pin_name(pin))); |
Bjorn Helgaas | 3b1ea18 | 2008-12-08 21:31:06 -0700 | [diff] [blame] | 392 | return entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | /* |
| 396 | * Attempt to derive an IRQ for this device from a parent bridge's |
| 397 | * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge). |
| 398 | */ |
Bjorn Helgaas | ee40136 | 2008-12-08 21:31:11 -0700 | [diff] [blame] | 399 | bridge = dev->bus->self; |
| 400 | while (bridge) { |
| 401 | pin = (((pin - 1) + PCI_SLOT(dev->devfn)) % 4) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
| 403 | if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) { |
| 404 | /* PC card has the same IRQ as its cardbridge */ |
Kristen Accardi | 8015a01 | 2005-11-02 16:24:35 -0800 | [diff] [blame] | 405 | bridge_pin = bridge->pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | if (!bridge_pin) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 408 | "No interrupt pin configured for device %s\n", |
| 409 | pci_name(bridge))); |
Bjorn Helgaas | beba8a6 | 2008-12-08 21:31:01 -0700 | [diff] [blame] | 410 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | pin = bridge_pin; |
| 413 | } |
| 414 | |
Bjorn Helgaas | 5697b7c | 2008-12-08 21:31:16 -0700 | [diff] [blame^] | 415 | entry = acpi_pci_irq_find_prt_entry(bridge, pin); |
Bjorn Helgaas | 3b1ea18 | 2008-12-08 21:31:06 -0700 | [diff] [blame] | 416 | if (entry) { |
| 417 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 418 | "Derived GSI for %s INT %c from %s\n", |
| 419 | pci_name(dev), pin_name(orig_pin), |
| 420 | pci_name(bridge))); |
| 421 | return entry; |
| 422 | } |
Bjorn Helgaas | ee40136 | 2008-12-08 21:31:11 -0700 | [diff] [blame] | 423 | |
| 424 | dev = bridge; |
| 425 | bridge = dev->bus->self; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Bjorn Helgaas | 3b1ea18 | 2008-12-08 21:31:06 -0700 | [diff] [blame] | 428 | dev_warn(&dev->dev, "can't derive routing for PCI INT %c\n", |
| 429 | pin_name(orig_pin)); |
| 430 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* |
| 434 | * acpi_pci_irq_enable |
| 435 | * success: return 0 |
| 436 | * failure: return < 0 |
| 437 | */ |
| 438 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 439 | int acpi_pci_irq_enable(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
Bjorn Helgaas | beba8a6 | 2008-12-08 21:31:01 -0700 | [diff] [blame] | 441 | struct acpi_prt_entry *entry; |
Bjorn Helgaas | c13f889 | 2008-12-08 21:30:26 -0700 | [diff] [blame] | 442 | int gsi = 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 443 | u8 pin = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 444 | int triggering = ACPI_LEVEL_SENSITIVE; |
| 445 | int polarity = ACPI_ACTIVE_LOW; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 446 | char *link = NULL; |
Bjorn Helgaas | c83642d | 2008-06-27 08:45:39 -0600 | [diff] [blame] | 447 | char link_desc[16]; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 448 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Kristen Accardi | 8015a01 | 2005-11-02 16:24:35 -0800 | [diff] [blame] | 451 | pin = dev->pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | if (!pin) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 453 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 454 | "No interrupt pin configured for device %s\n", |
| 455 | pci_name(dev))); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 456 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Bjorn Helgaas | beba8a6 | 2008-12-08 21:31:01 -0700 | [diff] [blame] | 459 | entry = acpi_pci_irq_lookup(dev, pin); |
Bjorn Helgaas | 5697b7c | 2008-12-08 21:31:16 -0700 | [diff] [blame^] | 460 | if (!entry) { |
Alan Cox | 96c2a87 | 2008-01-10 22:49:58 -0500 | [diff] [blame] | 461 | /* |
| 462 | * IDE legacy mode controller IRQs are magic. Why do compat |
| 463 | * extensions always make such a nasty mess. |
| 464 | */ |
| 465 | if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE && |
| 466 | (dev->class & 0x05) == 0) |
| 467 | return 0; |
| 468 | } |
Bjorn Helgaas | 5697b7c | 2008-12-08 21:31:16 -0700 | [diff] [blame^] | 469 | |
| 470 | if (entry) |
| 471 | gsi = acpi_pci_allocate_irq(entry, &triggering, &polarity, |
| 472 | &link); |
| 473 | else |
| 474 | gsi = -1; |
| 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | /* |
| 477 | * No IRQ known to the ACPI subsystem - maybe the BIOS / |
| 478 | * driver reported one, then use it. Exit in any case. |
| 479 | */ |
Bjorn Helgaas | c13f889 | 2008-12-08 21:30:26 -0700 | [diff] [blame] | 480 | if (gsi < 0) { |
Bjorn Helgaas | cf68b80 | 2008-12-08 21:30:36 -0700 | [diff] [blame] | 481 | dev_warn(&dev->dev, "PCI INT %c: no GSI", pin_name(pin)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | /* Interrupt Line values above 0xF are forbidden */ |
Linus Torvalds | 44f8e1a | 2005-07-02 10:35:33 -0700 | [diff] [blame] | 483 | if (dev->irq > 0 && (dev->irq <= 0xF)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | printk(" - using IRQ %d\n", dev->irq); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 485 | acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE, |
| 486 | ACPI_ACTIVE_LOW); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 487 | return 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 488 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | printk("\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 490 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
Bjorn Helgaas | c13f889 | 2008-12-08 21:30:26 -0700 | [diff] [blame] | 494 | rc = acpi_register_gsi(gsi, triggering, polarity); |
Kenji Kaneshige | 349f0d5 | 2005-07-28 14:42:00 -0400 | [diff] [blame] | 495 | if (rc < 0) { |
Bjorn Helgaas | c83642d | 2008-06-27 08:45:39 -0600 | [diff] [blame] | 496 | dev_warn(&dev->dev, "PCI INT %c: failed to register GSI\n", |
Bjorn Helgaas | cf68b80 | 2008-12-08 21:30:36 -0700 | [diff] [blame] | 497 | pin_name(pin)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 498 | return rc; |
Kenji Kaneshige | 349f0d5 | 2005-07-28 14:42:00 -0400 | [diff] [blame] | 499 | } |
| 500 | dev->irq = rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | if (link) |
Bjorn Helgaas | c83642d | 2008-06-27 08:45:39 -0600 | [diff] [blame] | 503 | snprintf(link_desc, sizeof(link_desc), " -> Link[%s]", link); |
| 504 | else |
| 505 | link_desc[0] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Bjorn Helgaas | c83642d | 2008-06-27 08:45:39 -0600 | [diff] [blame] | 507 | dev_info(&dev->dev, "PCI INT %c%s -> GSI %u (%s, %s) -> IRQ %d\n", |
Bjorn Helgaas | cf68b80 | 2008-12-08 21:30:36 -0700 | [diff] [blame] | 508 | pin_name(pin), link_desc, gsi, |
Bjorn Helgaas | c83642d | 2008-06-27 08:45:39 -0600 | [diff] [blame] | 509 | (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge", |
| 510 | (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 512 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 515 | /* FIXME: implement x86/x86_64 version */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 516 | void __attribute__ ((weak)) acpi_unregister_gsi(u32 i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | void acpi_pci_irq_disable(struct pci_dev *dev) |
| 521 | { |
Bjorn Helgaas | beba8a6 | 2008-12-08 21:31:01 -0700 | [diff] [blame] | 522 | struct acpi_prt_entry *entry; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 523 | int gsi = 0; |
| 524 | u8 pin = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
Kristen Accardi | 8015a01 | 2005-11-02 16:24:35 -0800 | [diff] [blame] | 527 | pin = dev->pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | if (!pin) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 529 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Bjorn Helgaas | beba8a6 | 2008-12-08 21:31:01 -0700 | [diff] [blame] | 531 | entry = acpi_pci_irq_lookup(dev, pin); |
Bjorn Helgaas | beba8a6 | 2008-12-08 21:31:01 -0700 | [diff] [blame] | 532 | if (!entry) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 533 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
Bjorn Helgaas | beba8a6 | 2008-12-08 21:31:01 -0700 | [diff] [blame] | 535 | gsi = acpi_pci_free_irq(entry); |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | /* |
| 538 | * TBD: It might be worth clearing dev->irq by magic constant |
| 539 | * (e.g. PCI_UNDEFINED_IRQ). |
| 540 | */ |
| 541 | |
Bjorn Helgaas | cf68b80 | 2008-12-08 21:30:36 -0700 | [diff] [blame] | 542 | dev_info(&dev->dev, "PCI INT %c disabled\n", pin_name(pin)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | acpi_unregister_gsi(gsi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |