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