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 | |
| 27 | #include <linux/config.h> |
| 28 | |
| 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 | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 42 | ACPI_MODULE_NAME("pci_irq") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 44 | static struct acpi_prt_list acpi_prt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | static DEFINE_SPINLOCK(acpi_prt_lock); |
| 46 | |
| 47 | /* -------------------------------------------------------------------------- |
| 48 | PCI IRQ Routing Table (PRT) Support |
| 49 | -------------------------------------------------------------------------- */ |
| 50 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | static struct acpi_prt_entry *acpi_pci_irq_find_prt_entry(int segment, |
| 52 | int bus, |
| 53 | int device, int pin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 55 | struct list_head *node = NULL; |
| 56 | struct acpi_prt_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | ACPI_FUNCTION_TRACE("acpi_pci_irq_find_prt_entry"); |
| 59 | |
| 60 | if (!acpi_prt.count) |
| 61 | return_PTR(NULL); |
| 62 | |
| 63 | /* |
| 64 | * Parse through all PRT entries looking for a match on the specified |
| 65 | * PCI device's segment, bus, device, and pin (don't care about func). |
| 66 | * |
| 67 | */ |
| 68 | spin_lock(&acpi_prt_lock); |
| 69 | list_for_each(node, &acpi_prt.entries) { |
| 70 | entry = list_entry(node, struct acpi_prt_entry, node); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 71 | if ((segment == entry->id.segment) |
| 72 | && (bus == entry->id.bus) |
| 73 | && (device == entry->id.device) |
| 74 | && (pin == entry->pin)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | spin_unlock(&acpi_prt_lock); |
| 76 | return_PTR(entry); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | spin_unlock(&acpi_prt_lock); |
| 81 | return_PTR(NULL); |
| 82 | } |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | acpi_pci_irq_add_entry(acpi_handle handle, |
| 86 | int segment, int bus, struct acpi_pci_routing_table *prt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | struct acpi_prt_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | ACPI_FUNCTION_TRACE("acpi_pci_irq_add_entry"); |
| 91 | |
| 92 | if (!prt) |
| 93 | return_VALUE(-EINVAL); |
| 94 | |
| 95 | entry = kmalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL); |
| 96 | if (!entry) |
| 97 | return_VALUE(-ENOMEM); |
| 98 | memset(entry, 0, sizeof(struct acpi_prt_entry)); |
| 99 | |
| 100 | entry->id.segment = segment; |
| 101 | entry->id.bus = bus; |
| 102 | entry->id.device = (prt->address >> 16) & 0xFFFF; |
| 103 | entry->id.function = prt->address & 0xFFFF; |
| 104 | entry->pin = prt->pin; |
| 105 | |
| 106 | /* |
| 107 | * Type 1: Dynamic |
| 108 | * --------------- |
| 109 | * The 'source' field specifies the PCI interrupt link device used to |
| 110 | * configure the IRQ assigned to this slot|dev|pin. The 'source_index' |
| 111 | * indicates which resource descriptor in the resource template (of |
| 112 | * the link device) this interrupt is allocated from. |
| 113 | * |
| 114 | * NOTE: Don't query the Link Device for IRQ information at this time |
| 115 | * because Link Device enumeration may not have occurred yet |
| 116 | * (e.g. exists somewhere 'below' this _PRT entry in the ACPI |
| 117 | * namespace). |
| 118 | */ |
| 119 | if (prt->source[0]) { |
| 120 | acpi_get_handle(handle, prt->source, &entry->link.handle); |
| 121 | entry->link.index = prt->source_index; |
| 122 | } |
| 123 | /* |
| 124 | * Type 2: Static |
| 125 | * -------------- |
| 126 | * The 'source' field is NULL, and the 'source_index' field specifies |
| 127 | * the IRQ value, which is hardwired to specific interrupt inputs on |
| 128 | * the interrupt controller. |
| 129 | */ |
| 130 | else |
| 131 | entry->link.index = prt->source_index; |
| 132 | |
| 133 | ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 134 | " %02X:%02X:%02X[%c] -> %s[%d]\n", |
| 135 | entry->id.segment, entry->id.bus, |
| 136 | entry->id.device, ('A' + entry->pin), prt->source, |
| 137 | entry->link.index)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | spin_lock(&acpi_prt_lock); |
| 140 | list_add_tail(&entry->node, &acpi_prt.entries); |
| 141 | acpi_prt.count++; |
| 142 | spin_unlock(&acpi_prt_lock); |
| 143 | |
| 144 | return_VALUE(0); |
| 145 | } |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 148 | 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] | 149 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | if (segment == entry->id.segment && bus == entry->id.bus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | acpi_prt.count--; |
| 152 | list_del(&entry->node); |
| 153 | kfree(entry); |
| 154 | } |
| 155 | } |
| 156 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | 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] | 158 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | acpi_status status = AE_OK; |
| 160 | char *pathname = NULL; |
| 161 | struct acpi_buffer buffer = { 0, NULL }; |
| 162 | struct acpi_pci_routing_table *prt = NULL; |
| 163 | struct acpi_pci_routing_table *entry = NULL; |
| 164 | static int first_time = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | ACPI_FUNCTION_TRACE("acpi_pci_irq_add_prt"); |
| 167 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 168 | pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); |
| 169 | if (!pathname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | return_VALUE(-ENOMEM); |
| 171 | memset(pathname, 0, ACPI_PATHNAME_MAX); |
| 172 | |
| 173 | if (first_time) { |
| 174 | acpi_prt.count = 0; |
| 175 | INIT_LIST_HEAD(&acpi_prt.entries); |
| 176 | first_time = 0; |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * NOTE: We're given a 'handle' to the _PRT object's parent device |
| 181 | * (either a PCI root bridge or PCI-PCI bridge). |
| 182 | */ |
| 183 | |
| 184 | buffer.length = ACPI_PATHNAME_MAX; |
| 185 | buffer.pointer = pathname; |
| 186 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 187 | |
| 188 | printk(KERN_DEBUG "ACPI: PCI Interrupt Routing Table [%s._PRT]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 189 | pathname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * Evaluate this _PRT and add its entries to our global list (acpi_prt). |
| 193 | */ |
| 194 | |
| 195 | buffer.length = 0; |
| 196 | buffer.pointer = NULL; |
| 197 | kfree(pathname); |
| 198 | status = acpi_get_irq_routing_table(handle, &buffer); |
| 199 | if (status != AE_BUFFER_OVERFLOW) { |
| 200 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | acpi_format_exception(status))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | return_VALUE(-ENODEV); |
| 203 | } |
| 204 | |
| 205 | prt = kmalloc(buffer.length, GFP_KERNEL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | if (!prt) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | return_VALUE(-ENOMEM); |
| 208 | } |
| 209 | memset(prt, 0, buffer.length); |
| 210 | buffer.pointer = prt; |
| 211 | |
| 212 | status = acpi_get_irq_routing_table(handle, &buffer); |
| 213 | if (ACPI_FAILURE(status)) { |
| 214 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRT [%s]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | acpi_format_exception(status))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | kfree(buffer.pointer); |
| 217 | return_VALUE(-ENODEV); |
| 218 | } |
| 219 | |
| 220 | entry = prt; |
| 221 | |
| 222 | while (entry && (entry->length > 0)) { |
| 223 | acpi_pci_irq_add_entry(handle, segment, bus, entry); |
| 224 | entry = (struct acpi_pci_routing_table *) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | ((unsigned long)entry + entry->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | kfree(prt); |
| 229 | |
| 230 | return_VALUE(0); |
| 231 | } |
| 232 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | void acpi_pci_irq_del_prt(int segment, int bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 235 | struct list_head *node = NULL, *n = NULL; |
| 236 | struct acpi_prt_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 238 | if (!acpi_prt.count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return; |
| 240 | } |
| 241 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | printk(KERN_DEBUG |
| 243 | "ACPI: Delete PCI Interrupt Routing Table for %x:%x\n", segment, |
| 244 | bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | spin_lock(&acpi_prt_lock); |
| 246 | list_for_each_safe(node, n, &acpi_prt.entries) { |
| 247 | entry = list_entry(node, struct acpi_prt_entry, node); |
| 248 | |
| 249 | acpi_pci_irq_del_entry(segment, bus, entry); |
| 250 | } |
| 251 | spin_unlock(&acpi_prt_lock); |
| 252 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | /* -------------------------------------------------------------------------- |
| 255 | PCI Interrupt Routing Support |
| 256 | -------------------------------------------------------------------------- */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 257 | typedef int (*irq_lookup_func) (struct acpi_prt_entry *, int *, int *, char **); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 259 | static int |
| 260 | acpi_pci_allocate_irq(struct acpi_prt_entry *entry, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 261 | int *triggering, int *polarity, char **link) |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 262 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 263 | int irq; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 264 | |
| 265 | ACPI_FUNCTION_TRACE("acpi_pci_allocate_irq"); |
| 266 | |
| 267 | if (entry->link.handle) { |
| 268 | irq = acpi_pci_link_allocate_irq(entry->link.handle, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 269 | entry->link.index, triggering, |
| 270 | polarity, link); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 271 | if (irq < 0) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 272 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, |
| 273 | "Invalid IRQ link routing entry\n")); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 274 | return_VALUE(-1); |
| 275 | } |
| 276 | } else { |
| 277 | irq = entry->link.index; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 278 | *triggering = ACPI_LEVEL_SENSITIVE; |
| 279 | *polarity = ACPI_ACTIVE_LOW; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found IRQ %d\n", irq)); |
| 283 | return_VALUE(irq); |
| 284 | } |
| 285 | |
| 286 | static int |
| 287 | acpi_pci_free_irq(struct acpi_prt_entry *entry, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 288 | int *triggering, int *polarity, char **link) |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 289 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 290 | int irq; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 291 | |
| 292 | ACPI_FUNCTION_TRACE("acpi_pci_free_irq"); |
| 293 | if (entry->link.handle) { |
| 294 | irq = acpi_pci_link_free_irq(entry->link.handle); |
| 295 | } else { |
| 296 | irq = entry->link.index; |
| 297 | } |
| 298 | return_VALUE(irq); |
| 299 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | /* |
| 302 | * acpi_pci_irq_lookup |
| 303 | * success: return IRQ >= 0 |
| 304 | * failure: return -1 |
| 305 | */ |
| 306 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | acpi_pci_irq_lookup(struct pci_bus *bus, |
| 308 | int device, |
| 309 | int pin, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 310 | int *triggering, |
| 311 | int *polarity, char **link, irq_lookup_func func) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 313 | struct acpi_prt_entry *entry = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | int segment = pci_domain_nr(bus); |
| 315 | int bus_nr = bus->number; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 316 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
| 318 | ACPI_FUNCTION_TRACE("acpi_pci_irq_lookup"); |
| 319 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 321 | "Searching for PRT entry for %02x:%02x:%02x[%c]\n", |
| 322 | segment, bus_nr, device, ('A' + pin))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 324 | entry = acpi_pci_irq_find_prt_entry(segment, bus_nr, device, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | if (!entry) { |
| 326 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PRT entry not found\n")); |
| 327 | return_VALUE(-1); |
| 328 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 330 | ret = func(entry, triggering, polarity, link); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 331 | return_VALUE(ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /* |
| 335 | * acpi_pci_irq_derive |
| 336 | * success: return IRQ >= 0 |
| 337 | * failure: return < 0 |
| 338 | */ |
| 339 | static int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | acpi_pci_irq_derive(struct pci_dev *dev, |
| 341 | int pin, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 342 | int *triggering, |
| 343 | int *polarity, char **link, irq_lookup_func func) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | struct pci_dev *bridge = dev; |
| 346 | int irq = -1; |
| 347 | u8 bridge_pin = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
| 349 | ACPI_FUNCTION_TRACE("acpi_pci_irq_derive"); |
| 350 | |
| 351 | if (!dev) |
| 352 | return_VALUE(-EINVAL); |
| 353 | |
| 354 | /* |
| 355 | * Attempt to derive an IRQ for this device from a parent bridge's |
| 356 | * PCI interrupt routing entry (eg. yenta bridge and add-in card bridge). |
| 357 | */ |
| 358 | while (irq < 0 && bridge->bus->self) { |
| 359 | pin = (pin + PCI_SLOT(bridge->devfn)) % 4; |
| 360 | bridge = bridge->bus->self; |
| 361 | |
| 362 | if ((bridge->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS) { |
| 363 | /* PC card has the same IRQ as its cardbridge */ |
Kristen Accardi | 8015a01 | 2005-11-02 16:24:35 -0800 | [diff] [blame] | 364 | bridge_pin = bridge->pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | if (!bridge_pin) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 366 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 367 | "No interrupt pin configured for device %s\n", |
| 368 | pci_name(bridge))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return_VALUE(-1); |
| 370 | } |
| 371 | /* Pin is from 0 to 3 */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 372 | bridge_pin--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | pin = bridge_pin; |
| 374 | } |
| 375 | |
| 376 | irq = acpi_pci_irq_lookup(bridge->bus, PCI_SLOT(bridge->devfn), |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 377 | pin, triggering, polarity, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 378 | link, func); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | if (irq < 0) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 382 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, |
| 383 | "Unable to derive IRQ for device %s\n", |
| 384 | pci_name(dev))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | return_VALUE(-1); |
| 386 | } |
| 387 | |
| 388 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Derive IRQ %d for device %s from %s\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 | irq, pci_name(dev), pci_name(bridge))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | return_VALUE(irq); |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * acpi_pci_irq_enable |
| 396 | * success: return 0 |
| 397 | * failure: return < 0 |
| 398 | */ |
| 399 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | int acpi_pci_irq_enable(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 402 | int irq = 0; |
| 403 | u8 pin = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 404 | int triggering = ACPI_LEVEL_SENSITIVE; |
| 405 | int polarity = ACPI_ACTIVE_LOW; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | char *link = NULL; |
| 407 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | ACPI_FUNCTION_TRACE("acpi_pci_irq_enable"); |
| 410 | |
| 411 | if (!dev) |
| 412 | return_VALUE(-EINVAL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 413 | |
Kristen Accardi | 8015a01 | 2005-11-02 16:24:35 -0800 | [diff] [blame] | 414 | pin = dev->pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | if (!pin) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 417 | "No interrupt pin configured for device %s\n", |
| 418 | pci_name(dev))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | return_VALUE(0); |
| 420 | } |
| 421 | pin--; |
| 422 | |
| 423 | if (!dev->bus) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 424 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 425 | "Invalid (NULL) 'bus' field\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | return_VALUE(-ENODEV); |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | * First we check the PCI IRQ routing table (PRT) for an IRQ. PRT |
| 431 | * values override any BIOS-assigned IRQs set during boot. |
| 432 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 433 | irq = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 434 | &triggering, &polarity, &link, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 435 | acpi_pci_allocate_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
| 437 | /* |
| 438 | * If no PRT entry was found, we'll try to derive an IRQ from the |
| 439 | * device's parent bridge. |
| 440 | */ |
| 441 | if (irq < 0) |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 442 | irq = acpi_pci_irq_derive(dev, pin, &triggering, |
| 443 | &polarity, &link, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 444 | acpi_pci_allocate_irq); |
| 445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | /* |
| 447 | * No IRQ known to the ACPI subsystem - maybe the BIOS / |
| 448 | * driver reported one, then use it. Exit in any case. |
| 449 | */ |
| 450 | if (irq < 0) { |
| 451 | printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: no GSI", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 452 | pci_name(dev), ('A' + pin)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | /* Interrupt Line values above 0xF are forbidden */ |
Linus Torvalds | 44f8e1a | 2005-07-02 10:35:33 -0700 | [diff] [blame] | 454 | if (dev->irq > 0 && (dev->irq <= 0xF)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | printk(" - using IRQ %d\n", dev->irq); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 456 | acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE, |
| 457 | ACPI_ACTIVE_LOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | return_VALUE(0); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 459 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | printk("\n"); |
| 461 | return_VALUE(0); |
| 462 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 463 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 465 | rc = acpi_register_gsi(irq, triggering, polarity); |
Kenji Kaneshige | 349f0d5 | 2005-07-28 14:42:00 -0400 | [diff] [blame] | 466 | if (rc < 0) { |
| 467 | printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: failed " |
| 468 | "to register GSI\n", pci_name(dev), ('A' + pin)); |
| 469 | return_VALUE(rc); |
| 470 | } |
| 471 | dev->irq = rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
| 473 | printk(KERN_INFO PREFIX "PCI Interrupt %s[%c] -> ", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 474 | pci_name(dev), 'A' + pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | if (link) |
| 477 | printk("Link [%s] -> ", link); |
| 478 | |
| 479 | printk("GSI %u (%s, %s) -> IRQ %d\n", irq, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 480 | (triggering == ACPI_LEVEL_SENSITIVE) ? "level" : "edge", |
| 481 | (polarity == ACPI_ACTIVE_LOW) ? "low" : "high", dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
| 483 | return_VALUE(0); |
| 484 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | EXPORT_SYMBOL(acpi_pci_irq_enable); |
| 487 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 488 | /* FIXME: implement x86/x86_64 version */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 489 | void __attribute__ ((weak)) acpi_unregister_gsi(u32 i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | void acpi_pci_irq_disable(struct pci_dev *dev) |
| 494 | { |
| 495 | int gsi = 0; |
| 496 | u8 pin = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 497 | int triggering = ACPI_LEVEL_SENSITIVE; |
| 498 | int polarity = ACPI_ACTIVE_LOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | ACPI_FUNCTION_TRACE("acpi_pci_irq_disable"); |
| 501 | |
Kenji Kaneshige | 5f0110f | 2005-09-03 00:34:32 -0400 | [diff] [blame] | 502 | if (!dev || !dev->bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | return_VOID; |
| 504 | |
Kristen Accardi | 8015a01 | 2005-11-02 16:24:35 -0800 | [diff] [blame] | 505 | pin = dev->pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | if (!pin) |
| 507 | return_VOID; |
| 508 | pin--; |
| 509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | /* |
| 511 | * First we check the PCI IRQ routing table (PRT) for an IRQ. |
| 512 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 513 | gsi = acpi_pci_irq_lookup(dev->bus, PCI_SLOT(dev->devfn), pin, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 514 | &triggering, &polarity, NULL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 515 | acpi_pci_free_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | /* |
| 517 | * If no PRT entry was found, we'll try to derive an IRQ from the |
| 518 | * device's parent bridge. |
| 519 | */ |
| 520 | if (gsi < 0) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 521 | gsi = acpi_pci_irq_derive(dev, pin, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 522 | &triggering, &polarity, NULL, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 523 | acpi_pci_free_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | if (gsi < 0) |
| 525 | return_VOID; |
| 526 | |
| 527 | /* |
| 528 | * TBD: It might be worth clearing dev->irq by magic constant |
| 529 | * (e.g. PCI_UNDEFINED_IRQ). |
| 530 | */ |
| 531 | |
| 532 | printk(KERN_INFO PREFIX "PCI interrupt for device %s disabled\n", |
| 533 | pci_name(dev)); |
| 534 | |
| 535 | acpi_unregister_gsi(gsi); |
| 536 | |
| 537 | return_VOID; |
| 538 | } |