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