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