blob: 68ee80a6e6f7e198ab64f7fd6a7cf51c1624a6ce [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;
86 acpi_handle handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 struct acpi_pci_link_irq irq;
Len Brown4be44fc2005-08-05 00:44:28 -040088 int refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089};
90
91static struct {
Len Brown4be44fc2005-08-05 00:44:28 -040092 int count;
93 struct list_head entries;
94} acpi_link;
Ingo Molnar36e43092006-04-27 05:25:00 -040095DEFINE_MUTEX(acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097/* --------------------------------------------------------------------------
98 PCI Link Device Management
99 -------------------------------------------------------------------------- */
100
101/*
102 * set context (link) possible list from resource list
103 */
104static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400105acpi_pci_link_check_possible(struct acpi_resource *resource, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Len Brown4be44fc2005-08-05 00:44:28 -0400107 struct acpi_pci_link *link = (struct acpi_pci_link *)context;
108 u32 i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Len Browneca008c2005-09-22 00:25:18 -0400111 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400112 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
Patrick Mocheld550d982006-06-27 00:41:40 -0400113 return AE_OK;
Bob Moore50eca3e2005-09-30 19:03:00 -0400114 case ACPI_RESOURCE_TYPE_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400115 {
116 struct acpi_resource_irq *p = &resource->data.irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400117 if (!p || !p->interrupt_count) {
Len Browncece9292006-06-26 23:04:31 -0400118 printk(KERN_WARNING PREFIX "Blank IRQ resource\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400119 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
Len Brown4be44fc2005-08-05 00:44:28 -0400121 for (i = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400122 (i < p->interrupt_count
Len Brown4be44fc2005-08-05 00:44:28 -0400123 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
124 if (!p->interrupts[i]) {
Len Browncece9292006-06-26 23:04:31 -0400125 printk(KERN_WARNING PREFIX "Invalid IRQ %d\n",
126 p->interrupts[i]);
Len Brown4be44fc2005-08-05 00:44:28 -0400127 continue;
128 }
129 link->irq.possible[i] = p->interrupts[i];
130 link->irq.possible_count++;
131 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400132 link->irq.triggering = p->triggering;
133 link->irq.polarity = p->polarity;
134 link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ;
Len Brown4be44fc2005-08-05 00:44:28 -0400135 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400137 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400138 {
Bob Moore50eca3e2005-09-30 19:03:00 -0400139 struct acpi_resource_extended_irq *p =
Len Brown4be44fc2005-08-05 00:44:28 -0400140 &resource->data.extended_irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400141 if (!p || !p->interrupt_count) {
Len Browncece9292006-06-26 23:04:31 -0400142 printk(KERN_WARNING PREFIX
143 "Blank EXT IRQ resource\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400144 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 }
Len Brown4be44fc2005-08-05 00:44:28 -0400146 for (i = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400147 (i < p->interrupt_count
Len Brown4be44fc2005-08-05 00:44:28 -0400148 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
149 if (!p->interrupts[i]) {
Len Browncece9292006-06-26 23:04:31 -0400150 printk(KERN_WARNING PREFIX "Invalid IRQ %d\n",
151 p->interrupts[i]);
Len Brown4be44fc2005-08-05 00:44:28 -0400152 continue;
153 }
154 link->irq.possible[i] = p->interrupts[i];
155 link->irq.possible_count++;
156 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400157 link->irq.triggering = p->triggering;
158 link->irq.polarity = p->polarity;
159 link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
Len Brown4be44fc2005-08-05 00:44:28 -0400160 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 default:
Len Brown64684632006-06-26 23:41:38 -0400163 printk(KERN_ERR PREFIX "Resource is not an IRQ entry\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400164 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
166
Patrick Mocheld550d982006-06-27 00:41:40 -0400167 return AE_CTRL_TERMINATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170static int acpi_pci_link_get_possible(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Len Brown4be44fc2005-08-05 00:44:28 -0400172 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 if (!link)
Patrick Mocheld550d982006-06-27 00:41:40 -0400176 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Patrick Mochel67a71362006-05-19 16:54:42 -0400178 status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS,
Len Brown4be44fc2005-08-05 00:44:28 -0400179 acpi_pci_link_check_possible, link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400181 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400182 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 }
184
Len Brown4be44fc2005-08-05 00:44:28 -0400185 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
186 "Found %d possible IRQs\n",
187 link->irq.possible_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Patrick Mocheld550d982006-06-27 00:41:40 -0400189 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400193acpi_pci_link_check_current(struct acpi_resource *resource, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Len Brown4be44fc2005-08-05 00:44:28 -0400195 int *irq = (int *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Len Browneca008c2005-09-22 00:25:18 -0400198 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400199 case ACPI_RESOURCE_TYPE_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400200 {
201 struct acpi_resource_irq *p = &resource->data.irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400202 if (!p || !p->interrupt_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400203 /*
204 * IRQ descriptors may have no IRQ# bits set,
205 * particularly those those w/ _STA disabled
206 */
207 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
208 "Blank IRQ resource\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400209 return AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400210 }
211 *irq = p->interrupts[0];
212 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400214 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400215 {
Bob Moore50eca3e2005-09-30 19:03:00 -0400216 struct acpi_resource_extended_irq *p =
Len Brown4be44fc2005-08-05 00:44:28 -0400217 &resource->data.extended_irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400218 if (!p || !p->interrupt_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400219 /*
220 * extended IRQ descriptors must
221 * return at least 1 IRQ
222 */
Len Browncece9292006-06-26 23:04:31 -0400223 printk(KERN_WARNING PREFIX
224 "Blank EXT IRQ resource\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400225 return AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400226 }
227 *irq = p->interrupts[0];
228 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
Len Brownd4ec6c72006-01-26 17:23:38 -0500230 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 default:
Len Brown64684632006-06-26 23:41:38 -0400232 printk(KERN_ERR PREFIX "Resource %d isn't an IRQ\n", resource->type);
Len Brownd4ec6c72006-01-26 17:23:38 -0500233 case ACPI_RESOURCE_TYPE_END_TAG:
Patrick Mocheld550d982006-06-27 00:41:40 -0400234 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400236 return AE_CTRL_TERMINATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
239/*
240 * Run _CRS and set link->irq.active
241 *
242 * return value:
243 * 0 - success
244 * !0 - failure
245 */
Len Brown4be44fc2005-08-05 00:44:28 -0400246static int acpi_pci_link_get_current(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Len Brown4be44fc2005-08-05 00:44:28 -0400248 int result = 0;
249 acpi_status status = AE_OK;
250 int irq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 if (!link || !link->handle)
Patrick Mocheld550d982006-06-27 00:41:40 -0400254 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 link->irq.active = 0;
257
258 /* in practice, status disabled is meaningless, ignore it */
259 if (acpi_strict) {
260 /* Query _STA, set link->device->status */
261 result = acpi_bus_get_status(link->device);
262 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400263 printk(KERN_ERR PREFIX "Unable to read status\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 goto end;
265 }
266
267 if (!link->device->status.enabled) {
268 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400269 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
271 }
272
273 /*
274 * Query and parse _CRS to get the current IRQ assignment.
275 */
276
Patrick Mochel67a71362006-05-19 16:54:42 -0400277 status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS,
Len Brown4be44fc2005-08-05 00:44:28 -0400278 acpi_pci_link_check_current, &irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400280 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 result = -ENODEV;
282 goto end;
283 }
284
285 if (acpi_strict && !irq) {
Len Brown64684632006-06-26 23:41:38 -0400286 printk(KERN_ERR PREFIX "_CRS returned 0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 result = -ENODEV;
288 }
289
290 link->irq.active = irq;
291
292 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active));
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400295 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
Len Brown4be44fc2005-08-05 00:44:28 -0400298static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
Len Brown4be44fc2005-08-05 00:44:28 -0400300 int result = 0;
301 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 struct {
Len Brown4be44fc2005-08-05 00:44:28 -0400303 struct acpi_resource res;
304 struct acpi_resource end;
305 } *resource;
306 struct acpi_buffer buffer = { 0, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 if (!link || !irq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400310 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Dave Jonesa64882e2005-12-12 00:37:40 -0800312 resource = kmalloc(sizeof(*resource) + 1, GFP_ATOMIC);
Len Brown4be44fc2005-08-05 00:44:28 -0400313 if (!resource)
Patrick Mocheld550d982006-06-27 00:41:40 -0400314 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Len Brown4be44fc2005-08-05 00:44:28 -0400316 memset(resource, 0, sizeof(*resource) + 1);
317 buffer.length = sizeof(*resource) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 buffer.pointer = resource;
319
Len Brown4be44fc2005-08-05 00:44:28 -0400320 switch (link->irq.resource_type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400321 case ACPI_RESOURCE_TYPE_IRQ:
322 resource->res.type = ACPI_RESOURCE_TYPE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 resource->res.length = sizeof(struct acpi_resource);
Bob Moore50eca3e2005-09-30 19:03:00 -0400324 resource->res.data.irq.triggering = link->irq.triggering;
325 resource->res.data.irq.polarity =
326 link->irq.polarity;
327 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
328 resource->res.data.irq.sharable =
Len Brown4be44fc2005-08-05 00:44:28 -0400329 ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400331 resource->res.data.irq.sharable = ACPI_SHARED;
332 resource->res.data.irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 resource->res.data.irq.interrupts[0] = irq;
334 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400335
Bob Moore50eca3e2005-09-30 19:03:00 -0400336 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
337 resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 resource->res.length = sizeof(struct acpi_resource);
Len Brown4be44fc2005-08-05 00:44:28 -0400339 resource->res.data.extended_irq.producer_consumer =
340 ACPI_CONSUMER;
Bob Moore50eca3e2005-09-30 19:03:00 -0400341 resource->res.data.extended_irq.triggering =
342 link->irq.triggering;
343 resource->res.data.extended_irq.polarity =
344 link->irq.polarity;
345 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
346 resource->res.data.irq.sharable =
Len Brown4be44fc2005-08-05 00:44:28 -0400347 ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400349 resource->res.data.irq.sharable = ACPI_SHARED;
350 resource->res.data.extended_irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 resource->res.data.extended_irq.interrupts[0] = irq;
352 /* ignore resource_source, it's optional */
353 break;
354 default:
Len Brown64684632006-06-26 23:41:38 -0400355 printk(KERN_ERR PREFIX "Invalid Resource_type %d\n", link->irq.resource_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 result = -EINVAL;
357 goto end;
358
359 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400360 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 /* Attempt to set the resource */
Patrick Mochel67a71362006-05-19 16:54:42 -0400363 status = acpi_set_current_resources(link->device->handle, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
365 /* check for total failure */
366 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400367 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 result = -ENODEV;
369 goto end;
370 }
371
372 /* Query _STA, set device->status */
373 result = acpi_bus_get_status(link->device);
374 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400375 printk(KERN_ERR PREFIX "Unable to read status\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 goto end;
377 }
378 if (!link->device->status.enabled) {
Len Browncece9292006-06-26 23:04:31 -0400379 printk(KERN_WARNING PREFIX
380 "%s [%s] disabled and referenced, BIOS bug\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400381 acpi_device_name(link->device),
Len Browncece9292006-06-26 23:04:31 -0400382 acpi_device_bid(link->device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 }
384
385 /* Query _CRS, set link->irq.active */
386 result = acpi_pci_link_get_current(link);
387 if (result) {
388 goto end;
389 }
390
391 /*
392 * Is current setting not what we set?
393 * set link->irq.active
394 */
395 if (link->irq.active != irq) {
396 /*
397 * policy: when _CRS doesn't return what we just _SRS
398 * assume _SRS worked and override _CRS value.
399 */
Len Browncece9292006-06-26 23:04:31 -0400400 printk(KERN_WARNING PREFIX
401 "%s [%s] BIOS reported IRQ %d, using IRQ %d\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400402 acpi_device_name(link->device),
Len Browncece9292006-06-26 23:04:31 -0400403 acpi_device_bid(link->device), link->irq.active, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 link->irq.active = irq;
405 }
406
407 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d\n", link->irq.active));
Len Brown4be44fc2005-08-05 00:44:28 -0400408
409 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 kfree(resource);
Patrick Mocheld550d982006-06-27 00:41:40 -0400411 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414/* --------------------------------------------------------------------------
415 PCI Link IRQ Management
416 -------------------------------------------------------------------------- */
417
418/*
419 * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt
420 * Link Devices to move the PIRQs around to minimize sharing.
421 *
422 * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs
423 * that the BIOS has already set to active. This is necessary because
424 * ACPI has no automatic means of knowing what ISA IRQs are used. Note that
425 * if the BIOS doesn't set a Link Device active, ACPI needs to program it
426 * even if acpi_irq_nobalance is set.
427 *
428 * A tables of penalties avoids directing PCI interrupts to well known
429 * ISA IRQs. Boot params are available to over-ride the default table:
430 *
431 * List interrupts that are free for PCI use.
432 * acpi_irq_pci=n[,m]
433 *
434 * List interrupts that should not be used for PCI:
435 * acpi_irq_isa=n[,m]
436 *
437 * Note that PCI IRQ routers have a list of possible IRQs,
438 * which may not include the IRQs this table says are available.
439 *
440 * Since this heuristic can't tell the difference between a link
441 * that no device will attach to, vs. a link which may be shared
442 * by multiple active devices -- it is not optimal.
443 *
444 * If interrupt performance is that important, get an IO-APIC system
445 * with a pin dedicated to each device. Or for that matter, an MSI
446 * enabled system.
447 */
448
449#define ACPI_MAX_IRQS 256
450#define ACPI_MAX_ISA_IRQ 16
451
452#define PIRQ_PENALTY_PCI_AVAILABLE (0)
453#define PIRQ_PENALTY_PCI_POSSIBLE (16*16)
454#define PIRQ_PENALTY_PCI_USING (16*16*16)
455#define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16)
456#define PIRQ_PENALTY_ISA_USED (16*16*16*16*16)
457#define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16)
458
459static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
460 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ0 timer */
461 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ1 keyboard */
462 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ2 cascade */
Len Brown4be44fc2005-08-05 00:44:28 -0400463 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ3 serial */
464 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ4 serial */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ5 sometimes SoundBlaster */
466 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ6 */
467 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ7 parallel, spurious */
468 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ8 rtc, sometimes */
469 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */
470 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */
471 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */
472 PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */
473 PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */
474 PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */
475 PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */
Len Brown4be44fc2005-08-05 00:44:28 -0400476 /* >IRQ15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477};
478
Len Brown4be44fc2005-08-05 00:44:28 -0400479int __init acpi_irq_penalty_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Len Brown4be44fc2005-08-05 00:44:28 -0400481 struct list_head *node = NULL;
482 struct acpi_pci_link *link = NULL;
483 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486 /*
487 * Update penalties to facilitate IRQ balancing.
488 */
489 list_for_each(node, &acpi_link.entries) {
490
491 link = list_entry(node, struct acpi_pci_link, node);
492 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400493 printk(KERN_ERR PREFIX "Invalid link context\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 continue;
495 }
496
497 /*
498 * reflect the possible and active irqs in the penalty table --
499 * useful for breaking ties.
500 */
501 if (link->irq.possible_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400502 int penalty =
503 PIRQ_PENALTY_PCI_POSSIBLE /
504 link->irq.possible_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 for (i = 0; i < link->irq.possible_count; i++) {
507 if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ)
Len Brown4be44fc2005-08-05 00:44:28 -0400508 acpi_irq_penalty[link->irq.
509 possible[i]] +=
510 penalty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512
513 } else if (link->irq.active) {
Len Brown4be44fc2005-08-05 00:44:28 -0400514 acpi_irq_penalty[link->irq.active] +=
515 PIRQ_PENALTY_PCI_POSSIBLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517 }
518 /* Add a penalty for the SCI */
519 acpi_irq_penalty[acpi_fadt.sci_int] += PIRQ_PENALTY_PCI_USING;
520
Patrick Mocheld550d982006-06-27 00:41:40 -0400521 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
523
524static int acpi_irq_balance; /* 0: static, 1: balance */
525
Len Brown4be44fc2005-08-05 00:44:28 -0400526static int acpi_pci_link_allocate(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
Len Brown4be44fc2005-08-05 00:44:28 -0400528 int irq;
529 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
David Shaohua Li87bec662005-07-27 23:02:00 -0400532 if (link->irq.initialized) {
533 if (link->refcnt == 0)
534 /* This means the link is disabled but initialized */
535 acpi_pci_link_set(link, link->irq.active);
Patrick Mocheld550d982006-06-27 00:41:40 -0400536 return 0;
David Shaohua Li87bec662005-07-27 23:02:00 -0400537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539 /*
540 * search for active IRQ in list of possible IRQs.
541 */
542 for (i = 0; i < link->irq.possible_count; ++i) {
543 if (link->irq.active == link->irq.possible[i])
544 break;
545 }
546 /*
547 * forget active IRQ that is not in possible list
548 */
549 if (i == link->irq.possible_count) {
550 if (acpi_strict)
Len Browncece9292006-06-26 23:04:31 -0400551 printk(KERN_WARNING PREFIX "_CRS %d not found"
552 " in _PRS\n", link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 link->irq.active = 0;
554 }
555
556 /*
557 * if active found, use it; else pick entry from end of possible list.
558 */
559 if (link->irq.active) {
560 irq = link->irq.active;
561 } else {
562 irq = link->irq.possible[link->irq.possible_count - 1];
563 }
564
565 if (acpi_irq_balance || !link->irq.active) {
566 /*
567 * Select the best IRQ. This is done in reverse to promote
568 * the use of IRQs 9, 10, 11, and >15.
569 */
570 for (i = (link->irq.possible_count - 1); i >= 0; i--) {
Len Brown4be44fc2005-08-05 00:44:28 -0400571 if (acpi_irq_penalty[irq] >
572 acpi_irq_penalty[link->irq.possible[i]])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 irq = link->irq.possible[i];
574 }
575 }
576
577 /* Attempt to enable the link device at this IRQ. */
578 if (acpi_pci_link_set(link, irq)) {
Len Brown64684632006-06-26 23:41:38 -0400579 printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. "
580 "Try pci=noacpi or acpi=off\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400581 acpi_device_name(link->device),
Len Brown64684632006-06-26 23:41:38 -0400582 acpi_device_bid(link->device));
Patrick Mocheld550d982006-06-27 00:41:40 -0400583 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 } else {
585 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
Len Brown4be44fc2005-08-05 00:44:28 -0400586 printk(PREFIX "%s [%s] enabled at IRQ %d\n",
587 acpi_device_name(link->device),
588 acpi_device_bid(link->device), link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 }
590
591 link->irq.initialized = 1;
592
Patrick Mocheld550d982006-06-27 00:41:40 -0400593 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594}
595
596/*
David Shaohua Li87bec662005-07-27 23:02:00 -0400597 * acpi_pci_link_allocate_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 * success: return IRQ >= 0
599 * failure: return -1
600 */
601
602int
Len Brown4be44fc2005-08-05 00:44:28 -0400603acpi_pci_link_allocate_irq(acpi_handle handle,
604 int index,
Bob Moore50eca3e2005-09-30 19:03:00 -0400605 int *triggering, int *polarity, char **name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
Len Brown4be44fc2005-08-05 00:44:28 -0400607 int result = 0;
608 struct acpi_device *device = NULL;
609 struct acpi_pci_link *link = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 result = acpi_bus_get_device(handle, &device);
613 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400614 printk(KERN_ERR PREFIX "Invalid link device\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400615 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 }
617
Len Brown4be44fc2005-08-05 00:44:28 -0400618 link = (struct acpi_pci_link *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400620 printk(KERN_ERR PREFIX "Invalid link context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400621 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 }
623
624 /* TBD: Support multiple index (IRQ) entries per Link Device */
625 if (index) {
Len Brown64684632006-06-26 23:41:38 -0400626 printk(KERN_ERR PREFIX "Invalid index %d\n", index);
Patrick Mocheld550d982006-06-27 00:41:40 -0400627 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
629
Ingo Molnar36e43092006-04-27 05:25:00 -0400630 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400631 if (acpi_pci_link_allocate(link)) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400632 mutex_unlock(&acpi_link_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400633 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400634 }
Len Brown4be44fc2005-08-05 00:44:28 -0400635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 if (!link->irq.active) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400637 mutex_unlock(&acpi_link_lock);
Len Brown64684632006-06-26 23:41:38 -0400638 printk(KERN_ERR PREFIX "Link active IRQ is 0!\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400639 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
Len Brown4be44fc2005-08-05 00:44:28 -0400641 link->refcnt++;
Ingo Molnar36e43092006-04-27 05:25:00 -0400642 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Bob Moore50eca3e2005-09-30 19:03:00 -0400644 if (triggering)
645 *triggering = link->irq.triggering;
646 if (polarity)
647 *polarity = link->irq.polarity;
Len Brown4be44fc2005-08-05 00:44:28 -0400648 if (name)
649 *name = acpi_device_bid(link->device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400650 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400651 "Link %s is referenced\n",
652 acpi_device_bid(link->device)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400653 return (link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654}
655
David Shaohua Li87bec662005-07-27 23:02:00 -0400656/*
657 * We don't change link's irq information here. After it is reenabled, we
658 * continue use the info
659 */
Len Brown4be44fc2005-08-05 00:44:28 -0400660int acpi_pci_link_free_irq(acpi_handle handle)
David Shaohua Li87bec662005-07-27 23:02:00 -0400661{
Len Brown4be44fc2005-08-05 00:44:28 -0400662 struct acpi_device *device = NULL;
663 struct acpi_pci_link *link = NULL;
664 acpi_status result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
David Shaohua Li87bec662005-07-27 23:02:00 -0400666
667 result = acpi_bus_get_device(handle, &device);
668 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400669 printk(KERN_ERR PREFIX "Invalid link device\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400670 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400671 }
672
Len Brown4be44fc2005-08-05 00:44:28 -0400673 link = (struct acpi_pci_link *)acpi_driver_data(device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400674 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400675 printk(KERN_ERR PREFIX "Invalid link context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400676 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400677 }
678
Ingo Molnar36e43092006-04-27 05:25:00 -0400679 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400680 if (!link->irq.initialized) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400681 mutex_unlock(&acpi_link_lock);
Len Brown64684632006-06-26 23:41:38 -0400682 printk(KERN_ERR PREFIX "Link isn't initialized\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400683 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400684 }
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400685#ifdef FUTURE_USE
686 /*
687 * The Link reference count allows us to _DISable an unused link
688 * and suspend time, and set it again on resume.
689 * However, 2.6.12 still has irq_router.resume
690 * which blindly restores the link state.
691 * So we disable the reference count method
692 * to prevent duplicate acpi_pci_link_set()
693 * which would harm some systems
694 */
Len Brown4be44fc2005-08-05 00:44:28 -0400695 link->refcnt--;
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400696#endif
David Shaohua Li87bec662005-07-27 23:02:00 -0400697 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400698 "Link %s is dereferenced\n",
699 acpi_device_bid(link->device)));
David Shaohua Li87bec662005-07-27 23:02:00 -0400700
701 if (link->refcnt == 0) {
Patrick Mochel67a71362006-05-19 16:54:42 -0400702 acpi_ut_evaluate_object(link->device->handle, "_DIS", 0, NULL);
David Shaohua Li87bec662005-07-27 23:02:00 -0400703 }
Ingo Molnar36e43092006-04-27 05:25:00 -0400704 mutex_unlock(&acpi_link_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400705 return (link->irq.active);
David Shaohua Li87bec662005-07-27 23:02:00 -0400706}
Len Brown4be44fc2005-08-05 00:44:28 -0400707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708/* --------------------------------------------------------------------------
709 Driver Interface
710 -------------------------------------------------------------------------- */
711
Len Brown4be44fc2005-08-05 00:44:28 -0400712static int acpi_pci_link_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713{
Len Brown4be44fc2005-08-05 00:44:28 -0400714 int result = 0;
715 struct acpi_pci_link *link = NULL;
716 int i = 0;
717 int found = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400721 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723 link = kmalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
724 if (!link)
Patrick Mocheld550d982006-06-27 00:41:40 -0400725 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 memset(link, 0, sizeof(struct acpi_pci_link));
727
728 link->device = device;
729 link->handle = device->handle;
730 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
731 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
732 acpi_driver_data(device) = link;
733
Ingo Molnar36e43092006-04-27 05:25:00 -0400734 mutex_lock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 result = acpi_pci_link_get_possible(link);
736 if (result)
737 goto end;
738
739 /* query and set link->irq.active */
740 acpi_pci_link_get_current(link);
741
742 printk(PREFIX "%s [%s] (IRQs", acpi_device_name(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400743 acpi_device_bid(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 for (i = 0; i < link->irq.possible_count; i++) {
745 if (link->irq.active == link->irq.possible[i]) {
746 printk(" *%d", link->irq.possible[i]);
747 found = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400748 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 printk(" %d", link->irq.possible[i]);
750 }
751
752 printk(")");
753
754 if (!found)
755 printk(" *%d", link->irq.active);
756
Len Brown4be44fc2005-08-05 00:44:28 -0400757 if (!link->device->status.enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 printk(", disabled.");
759
760 printk("\n");
761
762 /* TBD: Acquire/release lock */
763 list_add_tail(&link->node, &acpi_link.entries);
764 acpi_link.count++;
765
Len Brown4be44fc2005-08-05 00:44:28 -0400766 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 /* disable all links -- to be activated on use */
Patrick Mochel67a71362006-05-19 16:54:42 -0400768 acpi_ut_evaluate_object(device->handle, "_DIS", 0, NULL);
Ingo Molnar36e43092006-04-27 05:25:00 -0400769 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
771 if (result)
772 kfree(link);
773
Patrick Mocheld550d982006-06-27 00:41:40 -0400774 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
776
Len Brown4be44fc2005-08-05 00:44:28 -0400777static int acpi_pci_link_resume(struct acpi_pci_link *link)
Linus Torvalds697a2d62005-08-01 12:37:54 -0700778{
Linus Torvalds697a2d62005-08-01 12:37:54 -0700779
780 if (link->refcnt && link->irq.active && link->irq.initialized)
Patrick Mocheld550d982006-06-27 00:41:40 -0400781 return (acpi_pci_link_set(link, link->irq.active));
Linus Torvalds697a2d62005-08-01 12:37:54 -0700782 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400783 return 0;
Linus Torvalds697a2d62005-08-01 12:37:54 -0700784}
785
David Shaohua Li11e981f2005-08-03 23:46:33 -0400786/*
787 * FIXME: this is a workaround to avoid nasty warning. It will be removed
788 * after every device calls pci_disable_device in .resume.
789 */
790int acpi_in_resume;
Len Brown4be44fc2005-08-05 00:44:28 -0400791static int irqrouter_resume(struct sys_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792{
Len Brown4be44fc2005-08-05 00:44:28 -0400793 struct list_head *node = NULL;
794 struct acpi_pci_link *link = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Linus Torvalds56035092006-06-19 18:05:09 -0700797 /* Make sure SCI is enabled again (Apple firmware bug?) */
798 acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1, ACPI_MTX_DO_NOT_LOCK);
799
David Shaohua Li11e981f2005-08-03 23:46:33 -0400800 acpi_in_resume = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 list_for_each(node, &acpi_link.entries) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 link = list_entry(node, struct acpi_pci_link, node);
803 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400804 printk(KERN_ERR PREFIX "Invalid link context\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 continue;
806 }
Linus Torvalds697a2d62005-08-01 12:37:54 -0700807 acpi_pci_link_resume(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 }
David Shaohua Li11e981f2005-08-03 23:46:33 -0400809 acpi_in_resume = 0;
Patrick Mocheld550d982006-06-27 00:41:40 -0400810 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811}
812
Len Brown4be44fc2005-08-05 00:44:28 -0400813static int acpi_pci_link_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
815 struct acpi_pci_link *link = NULL;
816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400819 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Len Brown4be44fc2005-08-05 00:44:28 -0400821 link = (struct acpi_pci_link *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Ingo Molnar36e43092006-04-27 05:25:00 -0400823 mutex_lock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 list_del(&link->node);
Ingo Molnar36e43092006-04-27 05:25:00 -0400825 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 kfree(link);
828
Patrick Mocheld550d982006-06-27 00:41:40 -0400829 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830}
831
832/*
833 * modify acpi_irq_penalty[] from cmdline
834 */
835static int __init acpi_irq_penalty_update(char *str, int used)
836{
837 int i;
838
839 for (i = 0; i < 16; i++) {
840 int retval;
841 int irq;
842
Len Brown4be44fc2005-08-05 00:44:28 -0400843 retval = get_option(&str, &irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
845 if (!retval)
846 break; /* no number found */
847
848 if (irq < 0)
849 continue;
Len Brown4be44fc2005-08-05 00:44:28 -0400850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 if (irq >= ACPI_MAX_IRQS)
852 continue;
853
854 if (used)
855 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
856 else
857 acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE;
858
859 if (retval != 2) /* no next number */
860 break;
861 }
862 return 1;
863}
864
865/*
866 * We'd like PNP to call this routine for the
867 * single ISA_USED value for each legacy device.
868 * But instead it calls us with each POSSIBLE setting.
869 * There is no ISA_POSSIBLE weight, so we simply use
870 * the (small) PCI_USING penalty.
871 */
David Shaohua Lic9c3e452005-04-01 00:07:31 -0500872void acpi_penalize_isa_irq(int irq, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873{
David Shaohua Lic9c3e452005-04-01 00:07:31 -0500874 if (active)
875 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
876 else
877 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878}
879
880/*
881 * Over-ride default table to reserve additional IRQs for use by ISA
882 * e.g. acpi_irq_isa=5
883 * Useful for telling ACPI how not to interfere with your ISA sound card.
884 */
885static int __init acpi_irq_isa(char *str)
886{
887 return acpi_irq_penalty_update(str, 1);
888}
Len Brown4be44fc2005-08-05 00:44:28 -0400889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890__setup("acpi_irq_isa=", acpi_irq_isa);
891
892/*
893 * Over-ride default table to free additional IRQs for use by PCI
894 * e.g. acpi_irq_pci=7,15
895 * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing.
896 */
897static int __init acpi_irq_pci(char *str)
898{
899 return acpi_irq_penalty_update(str, 0);
900}
Len Brown4be44fc2005-08-05 00:44:28 -0400901
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902__setup("acpi_irq_pci=", acpi_irq_pci);
903
904static int __init acpi_irq_nobalance_set(char *str)
905{
906 acpi_irq_balance = 0;
907 return 1;
908}
Len Brown4be44fc2005-08-05 00:44:28 -0400909
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910__setup("acpi_irq_nobalance", acpi_irq_nobalance_set);
911
912int __init acpi_irq_balance_set(char *str)
913{
914 acpi_irq_balance = 1;
915 return 1;
916}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Len Brown4be44fc2005-08-05 00:44:28 -0400918__setup("acpi_irq_balance", acpi_irq_balance_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
David Shaohua Li87bec662005-07-27 23:02:00 -0400920/* FIXME: we will remove this interface after all drivers call pci_disable_device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921static struct sysdev_class irqrouter_sysdev_class = {
Len Brown4be44fc2005-08-05 00:44:28 -0400922 set_kset_name("irqrouter"),
923 .resume = irqrouter_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924};
925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926static struct sys_device device_irqrouter = {
Len Brown4be44fc2005-08-05 00:44:28 -0400927 .id = 0,
928 .cls = &irqrouter_sysdev_class,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929};
930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931static int __init irqrouter_init_sysfs(void)
932{
933 int error;
934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 if (acpi_disabled || acpi_noirq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400937 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 error = sysdev_class_register(&irqrouter_sysdev_class);
940 if (!error)
941 error = sysdev_register(&device_irqrouter);
942
Patrick Mocheld550d982006-06-27 00:41:40 -0400943 return error;
Len Brown4be44fc2005-08-05 00:44:28 -0400944}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946device_initcall(irqrouter_init_sysfs);
947
Len Brown4be44fc2005-08-05 00:44:28 -0400948static int __init acpi_pci_link_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951 if (acpi_noirq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400952 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
954 acpi_link.count = 0;
955 INIT_LIST_HEAD(&acpi_link.entries);
956
957 if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -0400958 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
Patrick Mocheld550d982006-06-27 00:41:40 -0400960 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961}
962
963subsys_initcall(acpi_pci_link_init);