Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $) |
| 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 | * TBD: |
| 27 | * 1. Support more than one IRQ resource entry per link device (index). |
| 28 | * 2. Implement start/stop mechanism and use ACPI Bus Driver facilities |
| 29 | * for IRQ management (e.g. start()->_SRS). |
| 30 | */ |
| 31 | |
| 32 | #include <linux/sysdev.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/types.h> |
| 37 | #include <linux/proc_fs.h> |
| 38 | #include <linux/spinlock.h> |
| 39 | #include <linux/pm.h> |
| 40 | #include <linux/pci.h> |
| 41 | |
| 42 | #include <acpi/acpi_bus.h> |
| 43 | #include <acpi/acpi_drivers.h> |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define _COMPONENT ACPI_PCI_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 46 | ACPI_MODULE_NAME("pci_link") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define ACPI_PCI_LINK_CLASS "pci_irq_routing" |
| 48 | #define ACPI_PCI_LINK_HID "PNP0C0F" |
| 49 | #define ACPI_PCI_LINK_DRIVER_NAME "ACPI PCI Interrupt Link Driver" |
| 50 | #define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link" |
| 51 | #define ACPI_PCI_LINK_FILE_INFO "info" |
| 52 | #define ACPI_PCI_LINK_FILE_STATUS "state" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define ACPI_PCI_LINK_MAX_POSSIBLE 16 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 54 | static int acpi_pci_link_add(struct acpi_device *device); |
| 55 | static int acpi_pci_link_remove(struct acpi_device *device, int type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | static struct acpi_driver acpi_pci_link_driver = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 58 | .name = ACPI_PCI_LINK_DRIVER_NAME, |
| 59 | .class = ACPI_PCI_LINK_CLASS, |
| 60 | .ids = ACPI_PCI_LINK_HID, |
| 61 | .ops = { |
| 62 | .add = acpi_pci_link_add, |
| 63 | .remove = acpi_pci_link_remove, |
| 64 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 67 | /* |
| 68 | * If a link is initialized, we never change its active and initialized |
| 69 | * later even the link is disable. Instead, we just repick the active irq |
| 70 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | struct acpi_pci_link_irq { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 72 | u8 active; /* Current IRQ */ |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 73 | u8 triggering; /* All IRQs */ |
| 74 | u8 polarity; /* All IRQs */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 75 | u8 resource_type; |
| 76 | u8 possible_count; |
| 77 | u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE]; |
| 78 | u8 initialized:1; |
| 79 | u8 reserved:7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | struct acpi_pci_link { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 83 | struct list_head node; |
| 84 | struct acpi_device *device; |
| 85 | acpi_handle handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | struct acpi_pci_link_irq irq; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 87 | int refcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | static struct { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 91 | int count; |
| 92 | struct list_head entries; |
| 93 | } acpi_link; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 94 | DECLARE_MUTEX(acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | /* -------------------------------------------------------------------------- |
| 97 | PCI Link Device Management |
| 98 | -------------------------------------------------------------------------- */ |
| 99 | |
| 100 | /* |
| 101 | * set context (link) possible list from resource list |
| 102 | */ |
| 103 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | acpi_pci_link_check_possible(struct acpi_resource *resource, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | struct acpi_pci_link *link = (struct acpi_pci_link *)context; |
| 107 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | ACPI_FUNCTION_TRACE("acpi_pci_link_check_possible"); |
| 110 | |
Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 111 | switch (resource->type) { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 112 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | return_ACPI_STATUS(AE_OK); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 114 | case ACPI_RESOURCE_TYPE_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 115 | { |
| 116 | struct acpi_resource_irq *p = &resource->data.irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 117 | if (!p || !p->interrupt_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 118 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, |
| 119 | "Blank IRQ resource\n")); |
| 120 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 122 | for (i = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 123 | (i < p->interrupt_count |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { |
| 125 | if (!p->interrupts[i]) { |
| 126 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, |
| 127 | "Invalid IRQ %d\n", |
| 128 | p->interrupts[i])); |
| 129 | continue; |
| 130 | } |
| 131 | link->irq.possible[i] = p->interrupts[i]; |
| 132 | link->irq.possible_count++; |
| 133 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 134 | link->irq.triggering = p->triggering; |
| 135 | link->irq.polarity = p->polarity; |
| 136 | link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 139 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 141 | struct acpi_resource_extended_irq *p = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 142 | &resource->data.extended_irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 143 | if (!p || !p->interrupt_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 144 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, |
| 145 | "Blank EXT IRQ resource\n")); |
| 146 | return_ACPI_STATUS(AE_OK); |
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 | for (i = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 149 | (i < p->interrupt_count |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { |
| 151 | if (!p->interrupts[i]) { |
| 152 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, |
| 153 | "Invalid IRQ %d\n", |
| 154 | p->interrupts[i])); |
| 155 | continue; |
| 156 | } |
| 157 | link->irq.possible[i] = p->interrupts[i]; |
| 158 | link->irq.possible_count++; |
| 159 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 160 | link->irq.triggering = p->triggering; |
| 161 | link->irq.polarity = p->polarity; |
| 162 | link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | default: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 167 | "Resource is not an IRQ entry\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | return_ACPI_STATUS(AE_OK); |
| 169 | } |
| 170 | |
| 171 | return_ACPI_STATUS(AE_CTRL_TERMINATE); |
| 172 | } |
| 173 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | static int acpi_pci_link_get_possible(struct acpi_pci_link *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | ACPI_FUNCTION_TRACE("acpi_pci_link_get_possible"); |
| 179 | |
| 180 | if (!link) |
| 181 | return_VALUE(-EINVAL); |
| 182 | |
| 183 | status = acpi_walk_resources(link->handle, METHOD_NAME__PRS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 184 | acpi_pci_link_check_possible, link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | if (ACPI_FAILURE(status)) { |
| 186 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PRS\n")); |
| 187 | return_VALUE(-ENODEV); |
| 188 | } |
| 189 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 190 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 191 | "Found %d possible IRQs\n", |
| 192 | link->irq.possible_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | return_VALUE(0); |
| 195 | } |
| 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 198 | acpi_pci_link_check_current(struct acpi_resource *resource, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | int *irq = (int *)context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | ACPI_FUNCTION_TRACE("acpi_pci_link_check_current"); |
| 203 | |
Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 204 | switch (resource->type) { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 205 | case ACPI_RESOURCE_TYPE_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | { |
| 207 | struct acpi_resource_irq *p = &resource->data.irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 208 | if (!p || !p->interrupt_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | /* |
| 210 | * IRQ descriptors may have no IRQ# bits set, |
| 211 | * particularly those those w/ _STA disabled |
| 212 | */ |
| 213 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 214 | "Blank IRQ resource\n")); |
| 215 | return_ACPI_STATUS(AE_OK); |
| 216 | } |
| 217 | *irq = p->interrupts[0]; |
| 218 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 220 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 221 | { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 222 | struct acpi_resource_extended_irq *p = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | &resource->data.extended_irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 224 | if (!p || !p->interrupt_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | /* |
| 226 | * extended IRQ descriptors must |
| 227 | * return at least 1 IRQ |
| 228 | */ |
| 229 | ACPI_DEBUG_PRINT((ACPI_DB_WARN, |
| 230 | "Blank EXT IRQ resource\n")); |
| 231 | return_ACPI_STATUS(AE_OK); |
| 232 | } |
| 233 | *irq = p->interrupts[0]; |
| 234 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
Len Brown | d4ec6c7 | 2006-01-26 17:23:38 -0500 | [diff] [blame] | 236 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | default: |
Len Brown | d4ec6c7 | 2006-01-26 17:23:38 -0500 | [diff] [blame] | 238 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Resource %d isn't an IRQ\n", resource->type)); |
| 239 | case ACPI_RESOURCE_TYPE_END_TAG: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | return_ACPI_STATUS(AE_OK); |
| 241 | } |
| 242 | return_ACPI_STATUS(AE_CTRL_TERMINATE); |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | * Run _CRS and set link->irq.active |
| 247 | * |
| 248 | * return value: |
| 249 | * 0 - success |
| 250 | * !0 - failure |
| 251 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | static int acpi_pci_link_get_current(struct acpi_pci_link *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | int result = 0; |
| 255 | acpi_status status = AE_OK; |
| 256 | int irq = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | ACPI_FUNCTION_TRACE("acpi_pci_link_get_current"); |
| 259 | |
| 260 | if (!link || !link->handle) |
| 261 | return_VALUE(-EINVAL); |
| 262 | |
| 263 | link->irq.active = 0; |
| 264 | |
| 265 | /* in practice, status disabled is meaningless, ignore it */ |
| 266 | if (acpi_strict) { |
| 267 | /* Query _STA, set link->device->status */ |
| 268 | result = acpi_bus_get_status(link->device); |
| 269 | if (result) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 271 | "Unable to read status\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | goto end; |
| 273 | } |
| 274 | |
| 275 | if (!link->device->status.enabled) { |
| 276 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n")); |
| 277 | return_VALUE(0); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * Query and parse _CRS to get the current IRQ assignment. |
| 283 | */ |
| 284 | |
| 285 | status = acpi_walk_resources(link->handle, METHOD_NAME__CRS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 286 | acpi_pci_link_check_current, &irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | if (ACPI_FAILURE(status)) { |
| 288 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _CRS\n")); |
| 289 | result = -ENODEV; |
| 290 | goto end; |
| 291 | } |
| 292 | |
| 293 | if (acpi_strict && !irq) { |
| 294 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "_CRS returned 0\n")); |
| 295 | result = -ENODEV; |
| 296 | } |
| 297 | |
| 298 | link->irq.active = irq; |
| 299 | |
| 300 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active)); |
| 301 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 302 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | return_VALUE(result); |
| 304 | } |
| 305 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 306 | static int acpi_pci_link_set(struct acpi_pci_link *link, int irq) |
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 | int result = 0; |
| 309 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | struct { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 311 | struct acpi_resource res; |
| 312 | struct acpi_resource end; |
| 313 | } *resource; |
| 314 | struct acpi_buffer buffer = { 0, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
| 316 | ACPI_FUNCTION_TRACE("acpi_pci_link_set"); |
| 317 | |
| 318 | if (!link || !irq) |
| 319 | return_VALUE(-EINVAL); |
| 320 | |
Dave Jones | a64882e | 2005-12-12 00:37:40 -0800 | [diff] [blame] | 321 | resource = kmalloc(sizeof(*resource) + 1, GFP_ATOMIC); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | if (!resource) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | return_VALUE(-ENOMEM); |
| 324 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 325 | memset(resource, 0, sizeof(*resource) + 1); |
| 326 | buffer.length = sizeof(*resource) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | buffer.pointer = resource; |
| 328 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | switch (link->irq.resource_type) { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 330 | case ACPI_RESOURCE_TYPE_IRQ: |
| 331 | resource->res.type = ACPI_RESOURCE_TYPE_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | resource->res.length = sizeof(struct acpi_resource); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 333 | resource->res.data.irq.triggering = link->irq.triggering; |
| 334 | resource->res.data.irq.polarity = |
| 335 | link->irq.polarity; |
| 336 | if (link->irq.triggering == ACPI_EDGE_SENSITIVE) |
| 337 | resource->res.data.irq.sharable = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | ACPI_EXCLUSIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | else |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 340 | resource->res.data.irq.sharable = ACPI_SHARED; |
| 341 | resource->res.data.irq.interrupt_count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | resource->res.data.irq.interrupts[0] = irq; |
| 343 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 344 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 345 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
| 346 | resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | resource->res.length = sizeof(struct acpi_resource); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | resource->res.data.extended_irq.producer_consumer = |
| 349 | ACPI_CONSUMER; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 350 | resource->res.data.extended_irq.triggering = |
| 351 | link->irq.triggering; |
| 352 | resource->res.data.extended_irq.polarity = |
| 353 | link->irq.polarity; |
| 354 | if (link->irq.triggering == ACPI_EDGE_SENSITIVE) |
| 355 | resource->res.data.irq.sharable = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 356 | ACPI_EXCLUSIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | else |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 358 | resource->res.data.irq.sharable = ACPI_SHARED; |
| 359 | resource->res.data.extended_irq.interrupt_count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | resource->res.data.extended_irq.interrupts[0] = irq; |
| 361 | /* ignore resource_source, it's optional */ |
| 362 | break; |
| 363 | default: |
| 364 | printk("ACPI BUG: resource_type %d\n", link->irq.resource_type); |
| 365 | result = -EINVAL; |
| 366 | goto end; |
| 367 | |
| 368 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 369 | resource->end.type = ACPI_RESOURCE_TYPE_END_TAG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
| 371 | /* Attempt to set the resource */ |
| 372 | status = acpi_set_current_resources(link->handle, &buffer); |
| 373 | |
| 374 | /* check for total failure */ |
| 375 | if (ACPI_FAILURE(status)) { |
| 376 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _SRS\n")); |
| 377 | result = -ENODEV; |
| 378 | goto end; |
| 379 | } |
| 380 | |
| 381 | /* Query _STA, set device->status */ |
| 382 | result = acpi_bus_get_status(link->device); |
| 383 | if (result) { |
| 384 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to read status\n")); |
| 385 | goto end; |
| 386 | } |
| 387 | if (!link->device->status.enabled) { |
| 388 | printk(KERN_WARNING PREFIX |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 | "%s [%s] disabled and referenced, BIOS bug.\n", |
| 390 | acpi_device_name(link->device), |
| 391 | acpi_device_bid(link->device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /* Query _CRS, set link->irq.active */ |
| 395 | result = acpi_pci_link_get_current(link); |
| 396 | if (result) { |
| 397 | goto end; |
| 398 | } |
| 399 | |
| 400 | /* |
| 401 | * Is current setting not what we set? |
| 402 | * set link->irq.active |
| 403 | */ |
| 404 | if (link->irq.active != irq) { |
| 405 | /* |
| 406 | * policy: when _CRS doesn't return what we just _SRS |
| 407 | * assume _SRS worked and override _CRS value. |
| 408 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 409 | printk(KERN_WARNING PREFIX |
| 410 | "%s [%s] BIOS reported IRQ %d, using IRQ %d\n", |
| 411 | acpi_device_name(link->device), |
| 412 | acpi_device_bid(link->device), link->irq.active, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | link->irq.active = irq; |
| 414 | } |
| 415 | |
| 416 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d\n", link->irq.active)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 417 | |
| 418 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | kfree(resource); |
| 420 | return_VALUE(result); |
| 421 | } |
| 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | /* -------------------------------------------------------------------------- |
| 424 | PCI Link IRQ Management |
| 425 | -------------------------------------------------------------------------- */ |
| 426 | |
| 427 | /* |
| 428 | * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt |
| 429 | * Link Devices to move the PIRQs around to minimize sharing. |
| 430 | * |
| 431 | * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs |
| 432 | * that the BIOS has already set to active. This is necessary because |
| 433 | * ACPI has no automatic means of knowing what ISA IRQs are used. Note that |
| 434 | * if the BIOS doesn't set a Link Device active, ACPI needs to program it |
| 435 | * even if acpi_irq_nobalance is set. |
| 436 | * |
| 437 | * A tables of penalties avoids directing PCI interrupts to well known |
| 438 | * ISA IRQs. Boot params are available to over-ride the default table: |
| 439 | * |
| 440 | * List interrupts that are free for PCI use. |
| 441 | * acpi_irq_pci=n[,m] |
| 442 | * |
| 443 | * List interrupts that should not be used for PCI: |
| 444 | * acpi_irq_isa=n[,m] |
| 445 | * |
| 446 | * Note that PCI IRQ routers have a list of possible IRQs, |
| 447 | * which may not include the IRQs this table says are available. |
| 448 | * |
| 449 | * Since this heuristic can't tell the difference between a link |
| 450 | * that no device will attach to, vs. a link which may be shared |
| 451 | * by multiple active devices -- it is not optimal. |
| 452 | * |
| 453 | * If interrupt performance is that important, get an IO-APIC system |
| 454 | * with a pin dedicated to each device. Or for that matter, an MSI |
| 455 | * enabled system. |
| 456 | */ |
| 457 | |
| 458 | #define ACPI_MAX_IRQS 256 |
| 459 | #define ACPI_MAX_ISA_IRQ 16 |
| 460 | |
| 461 | #define PIRQ_PENALTY_PCI_AVAILABLE (0) |
| 462 | #define PIRQ_PENALTY_PCI_POSSIBLE (16*16) |
| 463 | #define PIRQ_PENALTY_PCI_USING (16*16*16) |
| 464 | #define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16) |
| 465 | #define PIRQ_PENALTY_ISA_USED (16*16*16*16*16) |
| 466 | #define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16) |
| 467 | |
| 468 | static int acpi_irq_penalty[ACPI_MAX_IRQS] = { |
| 469 | PIRQ_PENALTY_ISA_ALWAYS, /* IRQ0 timer */ |
| 470 | PIRQ_PENALTY_ISA_ALWAYS, /* IRQ1 keyboard */ |
| 471 | PIRQ_PENALTY_ISA_ALWAYS, /* IRQ2 cascade */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 472 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ3 serial */ |
| 473 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ4 serial */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ5 sometimes SoundBlaster */ |
| 475 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ6 */ |
| 476 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ7 parallel, spurious */ |
| 477 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ8 rtc, sometimes */ |
| 478 | PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */ |
| 479 | PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */ |
| 480 | PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */ |
| 481 | PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */ |
| 482 | PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */ |
| 483 | PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */ |
| 484 | PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 485 | /* >IRQ15 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | }; |
| 487 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 488 | int __init acpi_irq_penalty_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 490 | struct list_head *node = NULL; |
| 491 | struct acpi_pci_link *link = NULL; |
| 492 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
| 494 | ACPI_FUNCTION_TRACE("acpi_irq_penalty_init"); |
| 495 | |
| 496 | /* |
| 497 | * Update penalties to facilitate IRQ balancing. |
| 498 | */ |
| 499 | list_for_each(node, &acpi_link.entries) { |
| 500 | |
| 501 | link = list_entry(node, struct acpi_pci_link, node); |
| 502 | if (!link) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 503 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 504 | "Invalid link context\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | continue; |
| 506 | } |
| 507 | |
| 508 | /* |
| 509 | * reflect the possible and active irqs in the penalty table -- |
| 510 | * useful for breaking ties. |
| 511 | */ |
| 512 | if (link->irq.possible_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 513 | int penalty = |
| 514 | PIRQ_PENALTY_PCI_POSSIBLE / |
| 515 | link->irq.possible_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
| 517 | for (i = 0; i < link->irq.possible_count; i++) { |
| 518 | if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 519 | acpi_irq_penalty[link->irq. |
| 520 | possible[i]] += |
| 521 | penalty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | } else if (link->irq.active) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 525 | acpi_irq_penalty[link->irq.active] += |
| 526 | PIRQ_PENALTY_PCI_POSSIBLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | /* Add a penalty for the SCI */ |
| 530 | acpi_irq_penalty[acpi_fadt.sci_int] += PIRQ_PENALTY_PCI_USING; |
| 531 | |
| 532 | return_VALUE(0); |
| 533 | } |
| 534 | |
| 535 | static int acpi_irq_balance; /* 0: static, 1: balance */ |
| 536 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 537 | static int acpi_pci_link_allocate(struct acpi_pci_link *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 539 | int irq; |
| 540 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
| 542 | ACPI_FUNCTION_TRACE("acpi_pci_link_allocate"); |
| 543 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 544 | if (link->irq.initialized) { |
| 545 | if (link->refcnt == 0) |
| 546 | /* This means the link is disabled but initialized */ |
| 547 | acpi_pci_link_set(link, link->irq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | return_VALUE(0); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
| 551 | /* |
| 552 | * search for active IRQ in list of possible IRQs. |
| 553 | */ |
| 554 | for (i = 0; i < link->irq.possible_count; ++i) { |
| 555 | if (link->irq.active == link->irq.possible[i]) |
| 556 | break; |
| 557 | } |
| 558 | /* |
| 559 | * forget active IRQ that is not in possible list |
| 560 | */ |
| 561 | if (i == link->irq.possible_count) { |
| 562 | if (acpi_strict) |
| 563 | printk(KERN_WARNING PREFIX "_CRS %d not found" |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 564 | " in _PRS\n", link->irq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | link->irq.active = 0; |
| 566 | } |
| 567 | |
| 568 | /* |
| 569 | * if active found, use it; else pick entry from end of possible list. |
| 570 | */ |
| 571 | if (link->irq.active) { |
| 572 | irq = link->irq.active; |
| 573 | } else { |
| 574 | irq = link->irq.possible[link->irq.possible_count - 1]; |
| 575 | } |
| 576 | |
| 577 | if (acpi_irq_balance || !link->irq.active) { |
| 578 | /* |
| 579 | * Select the best IRQ. This is done in reverse to promote |
| 580 | * the use of IRQs 9, 10, 11, and >15. |
| 581 | */ |
| 582 | for (i = (link->irq.possible_count - 1); i >= 0; i--) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 583 | if (acpi_irq_penalty[irq] > |
| 584 | acpi_irq_penalty[link->irq.possible[i]]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | irq = link->irq.possible[i]; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | /* Attempt to enable the link device at this IRQ. */ |
| 590 | if (acpi_pci_link_set(link, irq)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 591 | printk(PREFIX |
| 592 | "Unable to set IRQ for %s [%s] (likely buggy ACPI BIOS).\n" |
| 593 | "Try pci=noacpi or acpi=off\n", |
| 594 | acpi_device_name(link->device), |
| 595 | acpi_device_bid(link->device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | return_VALUE(-ENODEV); |
| 597 | } else { |
| 598 | acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 599 | printk(PREFIX "%s [%s] enabled at IRQ %d\n", |
| 600 | acpi_device_name(link->device), |
| 601 | acpi_device_bid(link->device), link->irq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | link->irq.initialized = 1; |
| 605 | |
| 606 | return_VALUE(0); |
| 607 | } |
| 608 | |
| 609 | /* |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 610 | * acpi_pci_link_allocate_irq |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | * success: return IRQ >= 0 |
| 612 | * failure: return -1 |
| 613 | */ |
| 614 | |
| 615 | int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 616 | acpi_pci_link_allocate_irq(acpi_handle handle, |
| 617 | int index, |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 618 | int *triggering, int *polarity, char **name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 620 | int result = 0; |
| 621 | struct acpi_device *device = NULL; |
| 622 | struct acpi_pci_link *link = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 624 | ACPI_FUNCTION_TRACE("acpi_pci_link_allocate_irq"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
| 626 | result = acpi_bus_get_device(handle, &device); |
| 627 | if (result) { |
| 628 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link device\n")); |
| 629 | return_VALUE(-1); |
| 630 | } |
| 631 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 632 | link = (struct acpi_pci_link *)acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | if (!link) { |
| 634 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n")); |
| 635 | return_VALUE(-1); |
| 636 | } |
| 637 | |
| 638 | /* TBD: Support multiple index (IRQ) entries per Link Device */ |
| 639 | if (index) { |
| 640 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid index %d\n", index)); |
| 641 | return_VALUE(-1); |
| 642 | } |
| 643 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 644 | down(&acpi_link_lock); |
| 645 | if (acpi_pci_link_allocate(link)) { |
| 646 | up(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | return_VALUE(-1); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 648 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | if (!link->irq.active) { |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 651 | up(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link active IRQ is 0!\n")); |
| 653 | return_VALUE(-1); |
| 654 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 655 | link->refcnt++; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 656 | up(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 658 | if (triggering) |
| 659 | *triggering = link->irq.triggering; |
| 660 | if (polarity) |
| 661 | *polarity = link->irq.polarity; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 662 | if (name) |
| 663 | *name = acpi_device_bid(link->device); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 664 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 665 | "Link %s is referenced\n", |
| 666 | acpi_device_bid(link->device))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | return_VALUE(link->irq.active); |
| 668 | } |
| 669 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 670 | /* |
| 671 | * We don't change link's irq information here. After it is reenabled, we |
| 672 | * continue use the info |
| 673 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 674 | int acpi_pci_link_free_irq(acpi_handle handle) |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 675 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 676 | struct acpi_device *device = NULL; |
| 677 | struct acpi_pci_link *link = NULL; |
| 678 | acpi_status result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 680 | ACPI_FUNCTION_TRACE("acpi_pci_link_free_irq"); |
| 681 | |
| 682 | result = acpi_bus_get_device(handle, &device); |
| 683 | if (result) { |
| 684 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link device\n")); |
| 685 | return_VALUE(-1); |
| 686 | } |
| 687 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 688 | link = (struct acpi_pci_link *)acpi_driver_data(device); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 689 | if (!link) { |
| 690 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid link context\n")); |
| 691 | return_VALUE(-1); |
| 692 | } |
| 693 | |
| 694 | down(&acpi_link_lock); |
| 695 | if (!link->irq.initialized) { |
| 696 | up(&acpi_link_lock); |
| 697 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Link isn't initialized\n")); |
| 698 | return_VALUE(-1); |
| 699 | } |
David Shaohua Li | ecc21eb | 2005-08-03 11:00:11 -0400 | [diff] [blame] | 700 | #ifdef FUTURE_USE |
| 701 | /* |
| 702 | * The Link reference count allows us to _DISable an unused link |
| 703 | * and suspend time, and set it again on resume. |
| 704 | * However, 2.6.12 still has irq_router.resume |
| 705 | * which blindly restores the link state. |
| 706 | * So we disable the reference count method |
| 707 | * to prevent duplicate acpi_pci_link_set() |
| 708 | * which would harm some systems |
| 709 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 710 | link->refcnt--; |
David Shaohua Li | ecc21eb | 2005-08-03 11:00:11 -0400 | [diff] [blame] | 711 | #endif |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 712 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 713 | "Link %s is dereferenced\n", |
| 714 | acpi_device_bid(link->device))); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 715 | |
| 716 | if (link->refcnt == 0) { |
| 717 | acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL); |
| 718 | } |
| 719 | up(&acpi_link_lock); |
| 720 | return_VALUE(link->irq.active); |
| 721 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | /* -------------------------------------------------------------------------- |
| 724 | Driver Interface |
| 725 | -------------------------------------------------------------------------- */ |
| 726 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 727 | static int acpi_pci_link_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 729 | int result = 0; |
| 730 | struct acpi_pci_link *link = NULL; |
| 731 | int i = 0; |
| 732 | int found = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
| 734 | ACPI_FUNCTION_TRACE("acpi_pci_link_add"); |
| 735 | |
| 736 | if (!device) |
| 737 | return_VALUE(-EINVAL); |
| 738 | |
| 739 | link = kmalloc(sizeof(struct acpi_pci_link), GFP_KERNEL); |
| 740 | if (!link) |
| 741 | return_VALUE(-ENOMEM); |
| 742 | memset(link, 0, sizeof(struct acpi_pci_link)); |
| 743 | |
| 744 | link->device = device; |
| 745 | link->handle = device->handle; |
| 746 | strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME); |
| 747 | strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS); |
| 748 | acpi_driver_data(device) = link; |
| 749 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 750 | down(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | result = acpi_pci_link_get_possible(link); |
| 752 | if (result) |
| 753 | goto end; |
| 754 | |
| 755 | /* query and set link->irq.active */ |
| 756 | acpi_pci_link_get_current(link); |
| 757 | |
| 758 | printk(PREFIX "%s [%s] (IRQs", acpi_device_name(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 759 | acpi_device_bid(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | for (i = 0; i < link->irq.possible_count; i++) { |
| 761 | if (link->irq.active == link->irq.possible[i]) { |
| 762 | printk(" *%d", link->irq.possible[i]); |
| 763 | found = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 764 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | printk(" %d", link->irq.possible[i]); |
| 766 | } |
| 767 | |
| 768 | printk(")"); |
| 769 | |
| 770 | if (!found) |
| 771 | printk(" *%d", link->irq.active); |
| 772 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 773 | if (!link->device->status.enabled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | printk(", disabled."); |
| 775 | |
| 776 | printk("\n"); |
| 777 | |
| 778 | /* TBD: Acquire/release lock */ |
| 779 | list_add_tail(&link->node, &acpi_link.entries); |
| 780 | acpi_link.count++; |
| 781 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 782 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | /* disable all links -- to be activated on use */ |
| 784 | acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 785 | up(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | if (result) |
| 788 | kfree(link); |
| 789 | |
| 790 | return_VALUE(result); |
| 791 | } |
| 792 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 793 | static int acpi_pci_link_resume(struct acpi_pci_link *link) |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 794 | { |
| 795 | ACPI_FUNCTION_TRACE("acpi_pci_link_resume"); |
| 796 | |
| 797 | if (link->refcnt && link->irq.active && link->irq.initialized) |
| 798 | return_VALUE(acpi_pci_link_set(link, link->irq.active)); |
| 799 | else |
| 800 | return_VALUE(0); |
| 801 | } |
| 802 | |
David Shaohua Li | 11e981f | 2005-08-03 23:46:33 -0400 | [diff] [blame] | 803 | /* |
| 804 | * FIXME: this is a workaround to avoid nasty warning. It will be removed |
| 805 | * after every device calls pci_disable_device in .resume. |
| 806 | */ |
| 807 | int acpi_in_resume; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 808 | static int irqrouter_resume(struct sys_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 810 | struct list_head *node = NULL; |
| 811 | struct acpi_pci_link *link = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 813 | ACPI_FUNCTION_TRACE("irqrouter_resume"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
Linus Torvalds | 5603509 | 2006-06-19 18:05:09 -0700 | [diff] [blame^] | 815 | /* Make sure SCI is enabled again (Apple firmware bug?) */ |
| 816 | acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1, ACPI_MTX_DO_NOT_LOCK); |
| 817 | |
David Shaohua Li | 11e981f | 2005-08-03 23:46:33 -0400 | [diff] [blame] | 818 | acpi_in_resume = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | list_for_each(node, &acpi_link.entries) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | link = list_entry(node, struct acpi_pci_link, node); |
| 821 | if (!link) { |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 822 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 823 | "Invalid link context\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | continue; |
| 825 | } |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 826 | acpi_pci_link_resume(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | } |
David Shaohua Li | 11e981f | 2005-08-03 23:46:33 -0400 | [diff] [blame] | 828 | acpi_in_resume = 0; |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 829 | return_VALUE(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 832 | static int acpi_pci_link_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | { |
| 834 | struct acpi_pci_link *link = NULL; |
| 835 | |
| 836 | ACPI_FUNCTION_TRACE("acpi_pci_link_remove"); |
| 837 | |
| 838 | if (!device || !acpi_driver_data(device)) |
| 839 | return_VALUE(-EINVAL); |
| 840 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 841 | link = (struct acpi_pci_link *)acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 843 | down(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | list_del(&link->node); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 845 | up(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
| 847 | kfree(link); |
| 848 | |
| 849 | return_VALUE(0); |
| 850 | } |
| 851 | |
| 852 | /* |
| 853 | * modify acpi_irq_penalty[] from cmdline |
| 854 | */ |
| 855 | static int __init acpi_irq_penalty_update(char *str, int used) |
| 856 | { |
| 857 | int i; |
| 858 | |
| 859 | for (i = 0; i < 16; i++) { |
| 860 | int retval; |
| 861 | int irq; |
| 862 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 863 | retval = get_option(&str, &irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | |
| 865 | if (!retval) |
| 866 | break; /* no number found */ |
| 867 | |
| 868 | if (irq < 0) |
| 869 | continue; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | if (irq >= ACPI_MAX_IRQS) |
| 872 | continue; |
| 873 | |
| 874 | if (used) |
| 875 | acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED; |
| 876 | else |
| 877 | acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE; |
| 878 | |
| 879 | if (retval != 2) /* no next number */ |
| 880 | break; |
| 881 | } |
| 882 | return 1; |
| 883 | } |
| 884 | |
| 885 | /* |
| 886 | * We'd like PNP to call this routine for the |
| 887 | * single ISA_USED value for each legacy device. |
| 888 | * But instead it calls us with each POSSIBLE setting. |
| 889 | * There is no ISA_POSSIBLE weight, so we simply use |
| 890 | * the (small) PCI_USING penalty. |
| 891 | */ |
David Shaohua Li | c9c3e45 | 2005-04-01 00:07:31 -0500 | [diff] [blame] | 892 | void acpi_penalize_isa_irq(int irq, int active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | { |
David Shaohua Li | c9c3e45 | 2005-04-01 00:07:31 -0500 | [diff] [blame] | 894 | if (active) |
| 895 | acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED; |
| 896 | else |
| 897 | acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | /* |
| 901 | * Over-ride default table to reserve additional IRQs for use by ISA |
| 902 | * e.g. acpi_irq_isa=5 |
| 903 | * Useful for telling ACPI how not to interfere with your ISA sound card. |
| 904 | */ |
| 905 | static int __init acpi_irq_isa(char *str) |
| 906 | { |
| 907 | return acpi_irq_penalty_update(str, 1); |
| 908 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | __setup("acpi_irq_isa=", acpi_irq_isa); |
| 911 | |
| 912 | /* |
| 913 | * Over-ride default table to free additional IRQs for use by PCI |
| 914 | * e.g. acpi_irq_pci=7,15 |
| 915 | * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing. |
| 916 | */ |
| 917 | static int __init acpi_irq_pci(char *str) |
| 918 | { |
| 919 | return acpi_irq_penalty_update(str, 0); |
| 920 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | __setup("acpi_irq_pci=", acpi_irq_pci); |
| 923 | |
| 924 | static int __init acpi_irq_nobalance_set(char *str) |
| 925 | { |
| 926 | acpi_irq_balance = 0; |
| 927 | return 1; |
| 928 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | __setup("acpi_irq_nobalance", acpi_irq_nobalance_set); |
| 931 | |
| 932 | int __init acpi_irq_balance_set(char *str) |
| 933 | { |
| 934 | acpi_irq_balance = 1; |
| 935 | return 1; |
| 936 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 938 | __setup("acpi_irq_balance", acpi_irq_balance_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 940 | /* FIXME: we will remove this interface after all drivers call pci_disable_device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | static struct sysdev_class irqrouter_sysdev_class = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 942 | set_kset_name("irqrouter"), |
| 943 | .resume = irqrouter_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | }; |
| 945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | static struct sys_device device_irqrouter = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 947 | .id = 0, |
| 948 | .cls = &irqrouter_sysdev_class, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | }; |
| 950 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | static int __init irqrouter_init_sysfs(void) |
| 952 | { |
| 953 | int error; |
| 954 | |
| 955 | ACPI_FUNCTION_TRACE("irqrouter_init_sysfs"); |
| 956 | |
| 957 | if (acpi_disabled || acpi_noirq) |
| 958 | return_VALUE(0); |
| 959 | |
| 960 | error = sysdev_class_register(&irqrouter_sysdev_class); |
| 961 | if (!error) |
| 962 | error = sysdev_register(&device_irqrouter); |
| 963 | |
| 964 | return_VALUE(error); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 965 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
| 967 | device_initcall(irqrouter_init_sysfs); |
| 968 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 969 | static int __init acpi_pci_link_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | { |
| 971 | ACPI_FUNCTION_TRACE("acpi_pci_link_init"); |
| 972 | |
| 973 | if (acpi_noirq) |
| 974 | return_VALUE(0); |
| 975 | |
| 976 | acpi_link.count = 0; |
| 977 | INIT_LIST_HEAD(&acpi_link.entries); |
| 978 | |
| 979 | if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0) |
| 980 | return_VALUE(-ENODEV); |
| 981 | |
| 982 | return_VALUE(0); |
| 983 | } |
| 984 | |
| 985 | subsys_initcall(acpi_pci_link_init); |