blob: 0f683c8c6fbc76676b193241e5af457118c7915f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Molnar36e43092006-04-27 05:25:00 -040041#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#include <acpi/acpi_bus.h>
44#include <acpi/acpi_drivers.h>
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define _COMPONENT ACPI_PCI_COMPONENT
Len Brown4be44fc2005-08-05 00:44:28 -040047ACPI_MODULE_NAME("pci_link")
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#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 Torvalds1da177e2005-04-16 15:20:36 -070054#define ACPI_PCI_LINK_MAX_POSSIBLE 16
Len Brown4be44fc2005-08-05 00:44:28 -040055static int acpi_pci_link_add(struct acpi_device *device);
56static int acpi_pci_link_remove(struct acpi_device *device, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58static struct acpi_driver acpi_pci_link_driver = {
Len Brown4be44fc2005-08-05 00:44:28 -040059 .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 Torvalds1da177e2005-04-16 15:20:36 -070066};
67
David Shaohua Li87bec662005-07-27 23:02:00 -040068/*
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 Torvalds1da177e2005-04-16 15:20:36 -070072struct acpi_pci_link_irq {
Len Brown4be44fc2005-08-05 00:44:28 -040073 u8 active; /* Current IRQ */
Bob Moore50eca3e2005-09-30 19:03:00 -040074 u8 triggering; /* All IRQs */
75 u8 polarity; /* All IRQs */
Len Brown4be44fc2005-08-05 00:44:28 -040076 u8 resource_type;
77 u8 possible_count;
78 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
79 u8 initialized:1;
80 u8 reserved:7;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
82
83struct acpi_pci_link {
Len Brown4be44fc2005-08-05 00:44:28 -040084 struct list_head node;
85 struct acpi_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 struct acpi_pci_link_irq irq;
Len Brown4be44fc2005-08-05 00:44:28 -040087 int refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088};
89
90static struct {
Len Brown4be44fc2005-08-05 00:44:28 -040091 int count;
92 struct list_head entries;
93} acpi_link;
Ingo Molnar36e43092006-04-27 05:25:00 -040094DEFINE_MUTEX(acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/* --------------------------------------------------------------------------
97 PCI Link Device Management
98 -------------------------------------------------------------------------- */
99
100/*
101 * set context (link) possible list from resource list
102 */
103static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400104acpi_pci_link_check_possible(struct acpi_resource *resource, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200106 struct acpi_pci_link *link = context;
Len Brown4be44fc2005-08-05 00:44:28 -0400107 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Len Browneca008c2005-09-22 00:25:18 -0400110 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400111 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
Patrick Mocheld550d982006-06-27 00:41:40 -0400112 return AE_OK;
Bob Moore50eca3e2005-09-30 19:03:00 -0400113 case ACPI_RESOURCE_TYPE_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400114 {
115 struct acpi_resource_irq *p = &resource->data.irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400116 if (!p || !p->interrupt_count) {
Len Browncece9292006-06-26 23:04:31 -0400117 printk(KERN_WARNING PREFIX "Blank IRQ resource\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400118 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
Len Brown4be44fc2005-08-05 00:44:28 -0400120 for (i = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400121 (i < p->interrupt_count
Len Brown4be44fc2005-08-05 00:44:28 -0400122 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
123 if (!p->interrupts[i]) {
Len Browncece9292006-06-26 23:04:31 -0400124 printk(KERN_WARNING PREFIX "Invalid IRQ %d\n",
125 p->interrupts[i]);
Len Brown4be44fc2005-08-05 00:44:28 -0400126 continue;
127 }
128 link->irq.possible[i] = p->interrupts[i];
129 link->irq.possible_count++;
130 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400131 link->irq.triggering = p->triggering;
132 link->irq.polarity = p->polarity;
133 link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ;
Len Brown4be44fc2005-08-05 00:44:28 -0400134 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400136 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400137 {
Bob Moore50eca3e2005-09-30 19:03:00 -0400138 struct acpi_resource_extended_irq *p =
Len Brown4be44fc2005-08-05 00:44:28 -0400139 &resource->data.extended_irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400140 if (!p || !p->interrupt_count) {
Len Browncece9292006-06-26 23:04:31 -0400141 printk(KERN_WARNING PREFIX
142 "Blank EXT IRQ resource\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400143 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
Len Brown4be44fc2005-08-05 00:44:28 -0400145 for (i = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400146 (i < p->interrupt_count
Len Brown4be44fc2005-08-05 00:44:28 -0400147 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
148 if (!p->interrupts[i]) {
Len Browncece9292006-06-26 23:04:31 -0400149 printk(KERN_WARNING PREFIX "Invalid IRQ %d\n",
150 p->interrupts[i]);
Len Brown4be44fc2005-08-05 00:44:28 -0400151 continue;
152 }
153 link->irq.possible[i] = p->interrupts[i];
154 link->irq.possible_count++;
155 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400156 link->irq.triggering = p->triggering;
157 link->irq.polarity = p->polarity;
158 link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
Len Brown4be44fc2005-08-05 00:44:28 -0400159 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 default:
Len Brown64684632006-06-26 23:41:38 -0400162 printk(KERN_ERR PREFIX "Resource is not an IRQ entry\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400163 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 }
165
Patrick Mocheld550d982006-06-27 00:41:40 -0400166 return AE_CTRL_TERMINATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167}
168
Len Brown4be44fc2005-08-05 00:44:28 -0400169static int acpi_pci_link_get_possible(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
Len Brown4be44fc2005-08-05 00:44:28 -0400171 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 if (!link)
Patrick Mocheld550d982006-06-27 00:41:40 -0400175 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Patrick Mochel67a71362006-05-19 16:54:42 -0400177 status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS,
Len Brown4be44fc2005-08-05 00:44:28 -0400178 acpi_pci_link_check_possible, link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400180 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400181 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 }
183
Len Brown4be44fc2005-08-05 00:44:28 -0400184 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
185 "Found %d possible IRQs\n",
186 link->irq.possible_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Patrick Mocheld550d982006-06-27 00:41:40 -0400188 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400192acpi_pci_link_check_current(struct acpi_resource *resource, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
Len Brown4be44fc2005-08-05 00:44:28 -0400194 int *irq = (int *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Len Browneca008c2005-09-22 00:25:18 -0400197 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400198 case ACPI_RESOURCE_TYPE_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400199 {
200 struct acpi_resource_irq *p = &resource->data.irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400201 if (!p || !p->interrupt_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400202 /*
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 Mocheld550d982006-06-27 00:41:40 -0400208 return AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400209 }
210 *irq = p->interrupts[0];
211 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400213 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400214 {
Bob Moore50eca3e2005-09-30 19:03:00 -0400215 struct acpi_resource_extended_irq *p =
Len Brown4be44fc2005-08-05 00:44:28 -0400216 &resource->data.extended_irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400217 if (!p || !p->interrupt_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400218 /*
219 * extended IRQ descriptors must
220 * return at least 1 IRQ
221 */
Len Browncece9292006-06-26 23:04:31 -0400222 printk(KERN_WARNING PREFIX
223 "Blank EXT IRQ resource\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400224 return AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400225 }
226 *irq = p->interrupts[0];
227 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
Len Brownd4ec6c72006-01-26 17:23:38 -0500229 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 default:
Len Brown64684632006-06-26 23:41:38 -0400231 printk(KERN_ERR PREFIX "Resource %d isn't an IRQ\n", resource->type);
Len Brownd4ec6c72006-01-26 17:23:38 -0500232 case ACPI_RESOURCE_TYPE_END_TAG:
Patrick Mocheld550d982006-06-27 00:41:40 -0400233 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400235 return AE_CTRL_TERMINATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236}
237
238/*
239 * Run _CRS and set link->irq.active
240 *
241 * return value:
242 * 0 - success
243 * !0 - failure
244 */
Len Brown4be44fc2005-08-05 00:44:28 -0400245static int acpi_pci_link_get_current(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Len Brown4be44fc2005-08-05 00:44:28 -0400247 int result = 0;
248 acpi_status status = AE_OK;
249 int irq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Patrick Mochele0e4e112006-05-19 16:54:50 -0400251 if (!link)
Patrick Mocheld550d982006-06-27 00:41:40 -0400252 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
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 Brown64684632006-06-26 23:41:38 -0400261 printk(KERN_ERR PREFIX "Unable to read status\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 goto end;
263 }
264
265 if (!link->device->status.enabled) {
266 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400267 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269 }
270
271 /*
272 * Query and parse _CRS to get the current IRQ assignment.
273 */
274
Patrick Mochel67a71362006-05-19 16:54:42 -0400275 status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS,
Len Brown4be44fc2005-08-05 00:44:28 -0400276 acpi_pci_link_check_current, &irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400278 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 result = -ENODEV;
280 goto end;
281 }
282
283 if (acpi_strict && !irq) {
Len Brown64684632006-06-26 23:41:38 -0400284 printk(KERN_ERR PREFIX "_CRS returned 0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 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 Brown4be44fc2005-08-05 00:44:28 -0400292 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400293 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294}
295
Len Brown4be44fc2005-08-05 00:44:28 -0400296static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Len Brown4be44fc2005-08-05 00:44:28 -0400298 int result = 0;
299 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 struct {
Len Brown4be44fc2005-08-05 00:44:28 -0400301 struct acpi_resource res;
302 struct acpi_resource end;
303 } *resource;
304 struct acpi_buffer buffer = { 0, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 if (!link || !irq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400308 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Burman Yan36bcbec2006-12-19 12:56:11 -0800310 resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
Len Brown4be44fc2005-08-05 00:44:28 -0400311 if (!resource)
Patrick Mocheld550d982006-06-27 00:41:40 -0400312 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 buffer.length = sizeof(*resource) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 buffer.pointer = resource;
316
Len Brown4be44fc2005-08-05 00:44:28 -0400317 switch (link->irq.resource_type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400318 case ACPI_RESOURCE_TYPE_IRQ:
319 resource->res.type = ACPI_RESOURCE_TYPE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 resource->res.length = sizeof(struct acpi_resource);
Bob Moore50eca3e2005-09-30 19:03:00 -0400321 resource->res.data.irq.triggering = link->irq.triggering;
322 resource->res.data.irq.polarity =
323 link->irq.polarity;
324 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
325 resource->res.data.irq.sharable =
Len Brown4be44fc2005-08-05 00:44:28 -0400326 ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400328 resource->res.data.irq.sharable = ACPI_SHARED;
329 resource->res.data.irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 resource->res.data.irq.interrupts[0] = irq;
331 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400332
Bob Moore50eca3e2005-09-30 19:03:00 -0400333 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
334 resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 resource->res.length = sizeof(struct acpi_resource);
Len Brown4be44fc2005-08-05 00:44:28 -0400336 resource->res.data.extended_irq.producer_consumer =
337 ACPI_CONSUMER;
Bob Moore50eca3e2005-09-30 19:03:00 -0400338 resource->res.data.extended_irq.triggering =
339 link->irq.triggering;
340 resource->res.data.extended_irq.polarity =
341 link->irq.polarity;
342 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
343 resource->res.data.irq.sharable =
Len Brown4be44fc2005-08-05 00:44:28 -0400344 ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400346 resource->res.data.irq.sharable = ACPI_SHARED;
347 resource->res.data.extended_irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 resource->res.data.extended_irq.interrupts[0] = irq;
349 /* ignore resource_source, it's optional */
350 break;
351 default:
Len Brown64684632006-06-26 23:41:38 -0400352 printk(KERN_ERR PREFIX "Invalid Resource_type %d\n", link->irq.resource_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 result = -EINVAL;
354 goto end;
355
356 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400357 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 /* Attempt to set the resource */
Patrick Mochel67a71362006-05-19 16:54:42 -0400360 status = acpi_set_current_resources(link->device->handle, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 /* check for total failure */
363 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400364 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 result = -ENODEV;
366 goto end;
367 }
368
369 /* Query _STA, set device->status */
370 result = acpi_bus_get_status(link->device);
371 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400372 printk(KERN_ERR PREFIX "Unable to read status\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 goto end;
374 }
375 if (!link->device->status.enabled) {
Len Browncece9292006-06-26 23:04:31 -0400376 printk(KERN_WARNING PREFIX
377 "%s [%s] disabled and referenced, BIOS bug\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400378 acpi_device_name(link->device),
Len Browncece9292006-06-26 23:04:31 -0400379 acpi_device_bid(link->device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 }
381
382 /* Query _CRS, set link->irq.active */
383 result = acpi_pci_link_get_current(link);
384 if (result) {
385 goto end;
386 }
387
388 /*
389 * Is current setting not what we set?
390 * set link->irq.active
391 */
392 if (link->irq.active != irq) {
393 /*
394 * policy: when _CRS doesn't return what we just _SRS
395 * assume _SRS worked and override _CRS value.
396 */
Len Browncece9292006-06-26 23:04:31 -0400397 printk(KERN_WARNING PREFIX
398 "%s [%s] BIOS reported IRQ %d, using IRQ %d\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400399 acpi_device_name(link->device),
Len Browncece9292006-06-26 23:04:31 -0400400 acpi_device_bid(link->device), link->irq.active, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 link->irq.active = irq;
402 }
403
404 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d\n", link->irq.active));
Len Brown4be44fc2005-08-05 00:44:28 -0400405
406 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 kfree(resource);
Patrick Mocheld550d982006-06-27 00:41:40 -0400408 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411/* --------------------------------------------------------------------------
412 PCI Link IRQ Management
413 -------------------------------------------------------------------------- */
414
415/*
416 * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt
417 * Link Devices to move the PIRQs around to minimize sharing.
418 *
419 * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs
420 * that the BIOS has already set to active. This is necessary because
421 * ACPI has no automatic means of knowing what ISA IRQs are used. Note that
422 * if the BIOS doesn't set a Link Device active, ACPI needs to program it
423 * even if acpi_irq_nobalance is set.
424 *
425 * A tables of penalties avoids directing PCI interrupts to well known
426 * ISA IRQs. Boot params are available to over-ride the default table:
427 *
428 * List interrupts that are free for PCI use.
429 * acpi_irq_pci=n[,m]
430 *
431 * List interrupts that should not be used for PCI:
432 * acpi_irq_isa=n[,m]
433 *
434 * Note that PCI IRQ routers have a list of possible IRQs,
435 * which may not include the IRQs this table says are available.
436 *
437 * Since this heuristic can't tell the difference between a link
438 * that no device will attach to, vs. a link which may be shared
439 * by multiple active devices -- it is not optimal.
440 *
441 * If interrupt performance is that important, get an IO-APIC system
442 * with a pin dedicated to each device. Or for that matter, an MSI
443 * enabled system.
444 */
445
446#define ACPI_MAX_IRQS 256
447#define ACPI_MAX_ISA_IRQ 16
448
449#define PIRQ_PENALTY_PCI_AVAILABLE (0)
450#define PIRQ_PENALTY_PCI_POSSIBLE (16*16)
451#define PIRQ_PENALTY_PCI_USING (16*16*16)
452#define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16)
453#define PIRQ_PENALTY_ISA_USED (16*16*16*16*16)
454#define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16)
455
456static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
457 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ0 timer */
458 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ1 keyboard */
459 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ2 cascade */
Len Brown4be44fc2005-08-05 00:44:28 -0400460 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ3 serial */
461 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ4 serial */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ5 sometimes SoundBlaster */
463 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ6 */
464 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ7 parallel, spurious */
465 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ8 rtc, sometimes */
466 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */
467 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */
468 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */
469 PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */
470 PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */
471 PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */
472 PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */
Len Brown4be44fc2005-08-05 00:44:28 -0400473 /* >IRQ15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474};
475
Len Brown4be44fc2005-08-05 00:44:28 -0400476int __init acpi_irq_penalty_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Len Brown4be44fc2005-08-05 00:44:28 -0400478 struct list_head *node = NULL;
479 struct acpi_pci_link *link = NULL;
480 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 /*
484 * Update penalties to facilitate IRQ balancing.
485 */
486 list_for_each(node, &acpi_link.entries) {
487
488 link = list_entry(node, struct acpi_pci_link, node);
489 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400490 printk(KERN_ERR PREFIX "Invalid link context\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 continue;
492 }
493
494 /*
495 * reflect the possible and active irqs in the penalty table --
496 * useful for breaking ties.
497 */
498 if (link->irq.possible_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400499 int penalty =
500 PIRQ_PENALTY_PCI_POSSIBLE /
501 link->irq.possible_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 for (i = 0; i < link->irq.possible_count; i++) {
504 if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ)
Len Brown4be44fc2005-08-05 00:44:28 -0400505 acpi_irq_penalty[link->irq.
506 possible[i]] +=
507 penalty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 }
509
510 } else if (link->irq.active) {
Len Brown4be44fc2005-08-05 00:44:28 -0400511 acpi_irq_penalty[link->irq.active] +=
512 PIRQ_PENALTY_PCI_POSSIBLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514 }
515 /* Add a penalty for the SCI */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300516 acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Patrick Mocheld550d982006-06-27 00:41:40 -0400518 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519}
520
521static int acpi_irq_balance; /* 0: static, 1: balance */
522
Len Brown4be44fc2005-08-05 00:44:28 -0400523static int acpi_pci_link_allocate(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
Len Brown4be44fc2005-08-05 00:44:28 -0400525 int irq;
526 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
David Shaohua Li87bec662005-07-27 23:02:00 -0400529 if (link->irq.initialized) {
530 if (link->refcnt == 0)
531 /* This means the link is disabled but initialized */
532 acpi_pci_link_set(link, link->irq.active);
Patrick Mocheld550d982006-06-27 00:41:40 -0400533 return 0;
David Shaohua Li87bec662005-07-27 23:02:00 -0400534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 /*
537 * search for active IRQ in list of possible IRQs.
538 */
539 for (i = 0; i < link->irq.possible_count; ++i) {
540 if (link->irq.active == link->irq.possible[i])
541 break;
542 }
543 /*
544 * forget active IRQ that is not in possible list
545 */
546 if (i == link->irq.possible_count) {
547 if (acpi_strict)
Len Browncece9292006-06-26 23:04:31 -0400548 printk(KERN_WARNING PREFIX "_CRS %d not found"
549 " in _PRS\n", link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 link->irq.active = 0;
551 }
552
553 /*
554 * if active found, use it; else pick entry from end of possible list.
555 */
556 if (link->irq.active) {
557 irq = link->irq.active;
558 } else {
559 irq = link->irq.possible[link->irq.possible_count - 1];
560 }
561
562 if (acpi_irq_balance || !link->irq.active) {
563 /*
564 * Select the best IRQ. This is done in reverse to promote
565 * the use of IRQs 9, 10, 11, and >15.
566 */
567 for (i = (link->irq.possible_count - 1); i >= 0; i--) {
Len Brown4be44fc2005-08-05 00:44:28 -0400568 if (acpi_irq_penalty[irq] >
569 acpi_irq_penalty[link->irq.possible[i]])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 irq = link->irq.possible[i];
571 }
572 }
573
574 /* Attempt to enable the link device at this IRQ. */
575 if (acpi_pci_link_set(link, irq)) {
Len Brown64684632006-06-26 23:41:38 -0400576 printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. "
577 "Try pci=noacpi or acpi=off\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400578 acpi_device_name(link->device),
Len Brown64684632006-06-26 23:41:38 -0400579 acpi_device_bid(link->device));
Patrick Mocheld550d982006-06-27 00:41:40 -0400580 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 } else {
582 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
Len Brown4be44fc2005-08-05 00:44:28 -0400583 printk(PREFIX "%s [%s] enabled at IRQ %d\n",
584 acpi_device_name(link->device),
585 acpi_device_bid(link->device), link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 }
587
588 link->irq.initialized = 1;
589
Patrick Mocheld550d982006-06-27 00:41:40 -0400590 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
592
593/*
David Shaohua Li87bec662005-07-27 23:02:00 -0400594 * acpi_pci_link_allocate_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 * success: return IRQ >= 0
596 * failure: return -1
597 */
598
599int
Len Brown4be44fc2005-08-05 00:44:28 -0400600acpi_pci_link_allocate_irq(acpi_handle handle,
601 int index,
Bob Moore50eca3e2005-09-30 19:03:00 -0400602 int *triggering, int *polarity, char **name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Len Brown4be44fc2005-08-05 00:44:28 -0400604 int result = 0;
605 struct acpi_device *device = NULL;
606 struct acpi_pci_link *link = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 result = acpi_bus_get_device(handle, &device);
610 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400611 printk(KERN_ERR PREFIX "Invalid link device\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400612 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200615 link = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400617 printk(KERN_ERR PREFIX "Invalid link context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400618 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
620
621 /* TBD: Support multiple index (IRQ) entries per Link Device */
622 if (index) {
Len Brown64684632006-06-26 23:41:38 -0400623 printk(KERN_ERR PREFIX "Invalid index %d\n", index);
Patrick Mocheld550d982006-06-27 00:41:40 -0400624 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
626
Ingo Molnar36e43092006-04-27 05:25:00 -0400627 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400628 if (acpi_pci_link_allocate(link)) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400629 mutex_unlock(&acpi_link_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400630 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400631 }
Len Brown4be44fc2005-08-05 00:44:28 -0400632
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 if (!link->irq.active) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400634 mutex_unlock(&acpi_link_lock);
Len Brown64684632006-06-26 23:41:38 -0400635 printk(KERN_ERR PREFIX "Link active IRQ is 0!\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400636 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
Len Brown4be44fc2005-08-05 00:44:28 -0400638 link->refcnt++;
Ingo Molnar36e43092006-04-27 05:25:00 -0400639 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Bob Moore50eca3e2005-09-30 19:03:00 -0400641 if (triggering)
642 *triggering = link->irq.triggering;
643 if (polarity)
644 *polarity = link->irq.polarity;
Len Brown4be44fc2005-08-05 00:44:28 -0400645 if (name)
646 *name = acpi_device_bid(link->device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400647 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400648 "Link %s is referenced\n",
649 acpi_device_bid(link->device)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400650 return (link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651}
652
David Shaohua Li87bec662005-07-27 23:02:00 -0400653/*
654 * We don't change link's irq information here. After it is reenabled, we
655 * continue use the info
656 */
Len Brown4be44fc2005-08-05 00:44:28 -0400657int acpi_pci_link_free_irq(acpi_handle handle)
David Shaohua Li87bec662005-07-27 23:02:00 -0400658{
Len Brown4be44fc2005-08-05 00:44:28 -0400659 struct acpi_device *device = NULL;
660 struct acpi_pci_link *link = NULL;
661 acpi_status result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
David Shaohua Li87bec662005-07-27 23:02:00 -0400663
664 result = acpi_bus_get_device(handle, &device);
665 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400666 printk(KERN_ERR PREFIX "Invalid link device\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400667 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400668 }
669
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200670 link = acpi_driver_data(device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400671 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400672 printk(KERN_ERR PREFIX "Invalid link context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400673 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400674 }
675
Ingo Molnar36e43092006-04-27 05:25:00 -0400676 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400677 if (!link->irq.initialized) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400678 mutex_unlock(&acpi_link_lock);
Len Brown64684632006-06-26 23:41:38 -0400679 printk(KERN_ERR PREFIX "Link isn't initialized\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400680 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400681 }
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400682#ifdef FUTURE_USE
683 /*
684 * The Link reference count allows us to _DISable an unused link
685 * and suspend time, and set it again on resume.
686 * However, 2.6.12 still has irq_router.resume
687 * which blindly restores the link state.
688 * So we disable the reference count method
689 * to prevent duplicate acpi_pci_link_set()
690 * which would harm some systems
691 */
Len Brown4be44fc2005-08-05 00:44:28 -0400692 link->refcnt--;
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400693#endif
David Shaohua Li87bec662005-07-27 23:02:00 -0400694 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400695 "Link %s is dereferenced\n",
696 acpi_device_bid(link->device)));
David Shaohua Li87bec662005-07-27 23:02:00 -0400697
698 if (link->refcnt == 0) {
Patrick Mochel67a71362006-05-19 16:54:42 -0400699 acpi_ut_evaluate_object(link->device->handle, "_DIS", 0, NULL);
David Shaohua Li87bec662005-07-27 23:02:00 -0400700 }
Ingo Molnar36e43092006-04-27 05:25:00 -0400701 mutex_unlock(&acpi_link_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400702 return (link->irq.active);
David Shaohua Li87bec662005-07-27 23:02:00 -0400703}
Len Brown4be44fc2005-08-05 00:44:28 -0400704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705/* --------------------------------------------------------------------------
706 Driver Interface
707 -------------------------------------------------------------------------- */
708
Len Brown4be44fc2005-08-05 00:44:28 -0400709static int acpi_pci_link_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Len Brown4be44fc2005-08-05 00:44:28 -0400711 int result = 0;
712 struct acpi_pci_link *link = NULL;
713 int i = 0;
714 int found = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400718 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Burman Yan36bcbec2006-12-19 12:56:11 -0800720 link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 if (!link)
Patrick Mocheld550d982006-06-27 00:41:40 -0400722 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 link->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
726 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
727 acpi_driver_data(device) = link;
728
Ingo Molnar36e43092006-04-27 05:25:00 -0400729 mutex_lock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 result = acpi_pci_link_get_possible(link);
731 if (result)
732 goto end;
733
734 /* query and set link->irq.active */
735 acpi_pci_link_get_current(link);
736
737 printk(PREFIX "%s [%s] (IRQs", acpi_device_name(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400738 acpi_device_bid(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 for (i = 0; i < link->irq.possible_count; i++) {
740 if (link->irq.active == link->irq.possible[i]) {
741 printk(" *%d", link->irq.possible[i]);
742 found = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400743 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 printk(" %d", link->irq.possible[i]);
745 }
746
747 printk(")");
748
749 if (!found)
750 printk(" *%d", link->irq.active);
751
Len Brown4be44fc2005-08-05 00:44:28 -0400752 if (!link->device->status.enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 printk(", disabled.");
754
755 printk("\n");
756
757 /* TBD: Acquire/release lock */
758 list_add_tail(&link->node, &acpi_link.entries);
759 acpi_link.count++;
760
Len Brown4be44fc2005-08-05 00:44:28 -0400761 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 /* disable all links -- to be activated on use */
Patrick Mochel67a71362006-05-19 16:54:42 -0400763 acpi_ut_evaluate_object(device->handle, "_DIS", 0, NULL);
Ingo Molnar36e43092006-04-27 05:25:00 -0400764 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766 if (result)
767 kfree(link);
768
Patrick Mocheld550d982006-06-27 00:41:40 -0400769 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770}
771
Len Brown4be44fc2005-08-05 00:44:28 -0400772static int acpi_pci_link_resume(struct acpi_pci_link *link)
Linus Torvalds697a2d62005-08-01 12:37:54 -0700773{
Linus Torvalds697a2d62005-08-01 12:37:54 -0700774
775 if (link->refcnt && link->irq.active && link->irq.initialized)
Patrick Mocheld550d982006-06-27 00:41:40 -0400776 return (acpi_pci_link_set(link, link->irq.active));
Linus Torvalds697a2d62005-08-01 12:37:54 -0700777 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400778 return 0;
Linus Torvalds697a2d62005-08-01 12:37:54 -0700779}
780
Len Brown4be44fc2005-08-05 00:44:28 -0400781static int irqrouter_resume(struct sys_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782{
Len Brown4be44fc2005-08-05 00:44:28 -0400783 struct list_head *node = NULL;
784 struct acpi_pci_link *link = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
Linus Torvalds56035092006-06-19 18:05:09 -0700787 /* Make sure SCI is enabled again (Apple firmware bug?) */
Bob Moored8c71b62007-02-02 19:48:21 +0300788 acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1);
Linus Torvalds56035092006-06-19 18:05:09 -0700789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 list_for_each(node, &acpi_link.entries) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 link = list_entry(node, struct acpi_pci_link, node);
792 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400793 printk(KERN_ERR PREFIX "Invalid link context\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 continue;
795 }
Linus Torvalds697a2d62005-08-01 12:37:54 -0700796 acpi_pci_link_resume(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400798 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799}
800
Len Brown4be44fc2005-08-05 00:44:28 -0400801static int acpi_pci_link_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
803 struct acpi_pci_link *link = NULL;
804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400807 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200809 link = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Ingo Molnar36e43092006-04-27 05:25:00 -0400811 mutex_lock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 list_del(&link->node);
Ingo Molnar36e43092006-04-27 05:25:00 -0400813 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
815 kfree(link);
816
Patrick Mocheld550d982006-06-27 00:41:40 -0400817 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
820/*
821 * modify acpi_irq_penalty[] from cmdline
822 */
823static int __init acpi_irq_penalty_update(char *str, int used)
824{
825 int i;
826
827 for (i = 0; i < 16; i++) {
828 int retval;
829 int irq;
830
Len Brown4be44fc2005-08-05 00:44:28 -0400831 retval = get_option(&str, &irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 if (!retval)
834 break; /* no number found */
835
836 if (irq < 0)
837 continue;
Len Brown4be44fc2005-08-05 00:44:28 -0400838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 if (irq >= ACPI_MAX_IRQS)
840 continue;
841
842 if (used)
843 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
844 else
845 acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE;
846
847 if (retval != 2) /* no next number */
848 break;
849 }
850 return 1;
851}
852
853/*
854 * We'd like PNP to call this routine for the
855 * single ISA_USED value for each legacy device.
856 * But instead it calls us with each POSSIBLE setting.
857 * There is no ISA_POSSIBLE weight, so we simply use
858 * the (small) PCI_USING penalty.
859 */
David Shaohua Lic9c3e452005-04-01 00:07:31 -0500860void acpi_penalize_isa_irq(int irq, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
David Shaohua Lic9c3e452005-04-01 00:07:31 -0500862 if (active)
863 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
864 else
865 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866}
867
868/*
869 * Over-ride default table to reserve additional IRQs for use by ISA
870 * e.g. acpi_irq_isa=5
871 * Useful for telling ACPI how not to interfere with your ISA sound card.
872 */
873static int __init acpi_irq_isa(char *str)
874{
875 return acpi_irq_penalty_update(str, 1);
876}
Len Brown4be44fc2005-08-05 00:44:28 -0400877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878__setup("acpi_irq_isa=", acpi_irq_isa);
879
880/*
881 * Over-ride default table to free additional IRQs for use by PCI
882 * e.g. acpi_irq_pci=7,15
883 * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing.
884 */
885static int __init acpi_irq_pci(char *str)
886{
887 return acpi_irq_penalty_update(str, 0);
888}
Len Brown4be44fc2005-08-05 00:44:28 -0400889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890__setup("acpi_irq_pci=", acpi_irq_pci);
891
892static int __init acpi_irq_nobalance_set(char *str)
893{
894 acpi_irq_balance = 0;
895 return 1;
896}
Len Brown4be44fc2005-08-05 00:44:28 -0400897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898__setup("acpi_irq_nobalance", acpi_irq_nobalance_set);
899
900int __init acpi_irq_balance_set(char *str)
901{
902 acpi_irq_balance = 1;
903 return 1;
904}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Len Brown4be44fc2005-08-05 00:44:28 -0400906__setup("acpi_irq_balance", acpi_irq_balance_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
David Shaohua Li87bec662005-07-27 23:02:00 -0400908/* FIXME: we will remove this interface after all drivers call pci_disable_device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909static struct sysdev_class irqrouter_sysdev_class = {
Len Brown4be44fc2005-08-05 00:44:28 -0400910 set_kset_name("irqrouter"),
911 .resume = irqrouter_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912};
913
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914static struct sys_device device_irqrouter = {
Len Brown4be44fc2005-08-05 00:44:28 -0400915 .id = 0,
916 .cls = &irqrouter_sysdev_class,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917};
918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919static int __init irqrouter_init_sysfs(void)
920{
921 int error;
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 if (acpi_disabled || acpi_noirq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400925 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927 error = sysdev_class_register(&irqrouter_sysdev_class);
928 if (!error)
929 error = sysdev_register(&device_irqrouter);
930
Patrick Mocheld550d982006-06-27 00:41:40 -0400931 return error;
Len Brown4be44fc2005-08-05 00:44:28 -0400932}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934device_initcall(irqrouter_init_sysfs);
935
Len Brown4be44fc2005-08-05 00:44:28 -0400936static int __init acpi_pci_link_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 if (acpi_noirq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400940 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 acpi_link.count = 0;
943 INIT_LIST_HEAD(&acpi_link.entries);
944
945 if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -0400946 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Patrick Mocheld550d982006-06-27 00:41:40 -0400948 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949}
950
951subsys_initcall(acpi_pci_link_init);