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