blob: 415b2628fe856996fe24390d94ac754530afb1da [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
110 ACPI_FUNCTION_TRACE("acpi_pci_link_check_possible");
111
Len Browneca008c2005-09-22 00:25:18 -0400112 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400113 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return_ACPI_STATUS(AE_OK);
Bob Moore50eca3e2005-09-30 19:03:00 -0400115 case ACPI_RESOURCE_TYPE_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400116 {
117 struct acpi_resource_irq *p = &resource->data.irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400118 if (!p || !p->interrupt_count) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400119 ACPI_WARNING((AE_INFO, "Blank IRQ resource"));
Len Brown4be44fc2005-08-05 00:44:28 -0400120 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
Len Brown4be44fc2005-08-05 00:44:28 -0400122 for (i = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400123 (i < p->interrupt_count
Len Brown4be44fc2005-08-05 00:44:28 -0400124 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
125 if (!p->interrupts[i]) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400126 ACPI_WARNING((AE_INFO, "Invalid IRQ %d",
127 p->interrupts[i]));
Len Brown4be44fc2005-08-05 00:44:28 -0400128 continue;
129 }
130 link->irq.possible[i] = p->interrupts[i];
131 link->irq.possible_count++;
132 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400133 link->irq.triggering = p->triggering;
134 link->irq.polarity = p->polarity;
135 link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ;
Len Brown4be44fc2005-08-05 00:44:28 -0400136 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400138 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400139 {
Bob Moore50eca3e2005-09-30 19:03:00 -0400140 struct acpi_resource_extended_irq *p =
Len Brown4be44fc2005-08-05 00:44:28 -0400141 &resource->data.extended_irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400142 if (!p || !p->interrupt_count) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400143 ACPI_WARNING((AE_INFO,
144 "Blank EXT IRQ resource"));
Len Brown4be44fc2005-08-05 00:44:28 -0400145 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
Len Brown4be44fc2005-08-05 00:44:28 -0400147 for (i = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400148 (i < p->interrupt_count
Len Brown4be44fc2005-08-05 00:44:28 -0400149 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
150 if (!p->interrupts[i]) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400151 ACPI_WARNING((AE_INFO, "Invalid IRQ %d",
152 p->interrupts[i]));
Len Brown4be44fc2005-08-05 00:44:28 -0400153 continue;
154 }
155 link->irq.possible[i] = p->interrupts[i];
156 link->irq.possible_count++;
157 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400158 link->irq.triggering = p->triggering;
159 link->irq.polarity = p->polarity;
160 link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
Len Brown4be44fc2005-08-05 00:44:28 -0400161 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 default:
Thomas Renningera6fc6722006-06-26 23:58:43 -0400164 ACPI_ERROR((AE_INFO, "Resource is not an IRQ entry\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 return_ACPI_STATUS(AE_OK);
166 }
167
168 return_ACPI_STATUS(AE_CTRL_TERMINATE);
169}
170
Len Brown4be44fc2005-08-05 00:44:28 -0400171static int acpi_pci_link_get_possible(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Len Brown4be44fc2005-08-05 00:44:28 -0400173 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 ACPI_FUNCTION_TRACE("acpi_pci_link_get_possible");
176
177 if (!link)
178 return_VALUE(-EINVAL);
179
180 status = acpi_walk_resources(link->handle, METHOD_NAME__PRS,
Len Brown4be44fc2005-08-05 00:44:28 -0400181 acpi_pci_link_check_possible, link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400183 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 return_VALUE(-ENODEV);
185 }
186
Len Brown4be44fc2005-08-05 00:44:28 -0400187 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
188 "Found %d possible IRQs\n",
189 link->irq.possible_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 return_VALUE(0);
192}
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400195acpi_pci_link_check_current(struct acpi_resource *resource, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Len Brown4be44fc2005-08-05 00:44:28 -0400197 int *irq = (int *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 ACPI_FUNCTION_TRACE("acpi_pci_link_check_current");
200
Len Browneca008c2005-09-22 00:25:18 -0400201 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400202 case ACPI_RESOURCE_TYPE_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400203 {
204 struct acpi_resource_irq *p = &resource->data.irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400205 if (!p || !p->interrupt_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400206 /*
207 * IRQ descriptors may have no IRQ# bits set,
208 * particularly those those w/ _STA disabled
209 */
210 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
211 "Blank IRQ resource\n"));
212 return_ACPI_STATUS(AE_OK);
213 }
214 *irq = p->interrupts[0];
215 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400217 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400218 {
Bob Moore50eca3e2005-09-30 19:03:00 -0400219 struct acpi_resource_extended_irq *p =
Len Brown4be44fc2005-08-05 00:44:28 -0400220 &resource->data.extended_irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400221 if (!p || !p->interrupt_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400222 /*
223 * extended IRQ descriptors must
224 * return at least 1 IRQ
225 */
Thomas Renningera6fc6722006-06-26 23:58:43 -0400226 ACPI_WARNING((AE_INFO,
227 "Blank EXT IRQ resource"));
Len Brown4be44fc2005-08-05 00:44:28 -0400228 return_ACPI_STATUS(AE_OK);
229 }
230 *irq = p->interrupts[0];
231 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
Len Brownd4ec6c72006-01-26 17:23:38 -0500233 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 default:
Thomas Renningera6fc6722006-06-26 23:58:43 -0400235 ACPI_ERROR((AE_INFO, "Resource %d isn't an IRQ", resource->type));
Len Brownd4ec6c72006-01-26 17:23:38 -0500236 case ACPI_RESOURCE_TYPE_END_TAG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return_ACPI_STATUS(AE_OK);
238 }
239 return_ACPI_STATUS(AE_CTRL_TERMINATE);
240}
241
242/*
243 * Run _CRS and set link->irq.active
244 *
245 * return value:
246 * 0 - success
247 * !0 - failure
248 */
Len Brown4be44fc2005-08-05 00:44:28 -0400249static int acpi_pci_link_get_current(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Len Brown4be44fc2005-08-05 00:44:28 -0400251 int result = 0;
252 acpi_status status = AE_OK;
253 int irq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 ACPI_FUNCTION_TRACE("acpi_pci_link_get_current");
256
257 if (!link || !link->handle)
258 return_VALUE(-EINVAL);
259
260 link->irq.active = 0;
261
262 /* in practice, status disabled is meaningless, ignore it */
263 if (acpi_strict) {
264 /* Query _STA, set link->device->status */
265 result = acpi_bus_get_status(link->device);
266 if (result) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400267 ACPI_ERROR((AE_INFO, "Unable to read status"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 goto end;
269 }
270
271 if (!link->device->status.enabled) {
272 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n"));
273 return_VALUE(0);
274 }
275 }
276
277 /*
278 * Query and parse _CRS to get the current IRQ assignment.
279 */
280
281 status = acpi_walk_resources(link->handle, METHOD_NAME__CRS,
Len Brown4be44fc2005-08-05 00:44:28 -0400282 acpi_pci_link_check_current, &irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400284 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 result = -ENODEV;
286 goto end;
287 }
288
289 if (acpi_strict && !irq) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400290 ACPI_ERROR((AE_INFO, "_CRS returned 0"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 result = -ENODEV;
292 }
293
294 link->irq.active = irq;
295
296 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active));
297
Len Brown4be44fc2005-08-05 00:44:28 -0400298 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 return_VALUE(result);
300}
301
Len Brown4be44fc2005-08-05 00:44:28 -0400302static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Len Brown4be44fc2005-08-05 00:44:28 -0400304 int result = 0;
305 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 struct {
Len Brown4be44fc2005-08-05 00:44:28 -0400307 struct acpi_resource res;
308 struct acpi_resource end;
309 } *resource;
310 struct acpi_buffer buffer = { 0, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312 ACPI_FUNCTION_TRACE("acpi_pci_link_set");
313
314 if (!link || !irq)
315 return_VALUE(-EINVAL);
316
Dave Jonesa64882e2005-12-12 00:37:40 -0800317 resource = kmalloc(sizeof(*resource) + 1, GFP_ATOMIC);
Len Brown4be44fc2005-08-05 00:44:28 -0400318 if (!resource)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 return_VALUE(-ENOMEM);
320
Len Brown4be44fc2005-08-05 00:44:28 -0400321 memset(resource, 0, sizeof(*resource) + 1);
322 buffer.length = sizeof(*resource) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 buffer.pointer = resource;
324
Len Brown4be44fc2005-08-05 00:44:28 -0400325 switch (link->irq.resource_type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400326 case ACPI_RESOURCE_TYPE_IRQ:
327 resource->res.type = ACPI_RESOURCE_TYPE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 resource->res.length = sizeof(struct acpi_resource);
Bob Moore50eca3e2005-09-30 19:03:00 -0400329 resource->res.data.irq.triggering = link->irq.triggering;
330 resource->res.data.irq.polarity =
331 link->irq.polarity;
332 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
333 resource->res.data.irq.sharable =
Len Brown4be44fc2005-08-05 00:44:28 -0400334 ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400336 resource->res.data.irq.sharable = ACPI_SHARED;
337 resource->res.data.irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 resource->res.data.irq.interrupts[0] = irq;
339 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400340
Bob Moore50eca3e2005-09-30 19:03:00 -0400341 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
342 resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 resource->res.length = sizeof(struct acpi_resource);
Len Brown4be44fc2005-08-05 00:44:28 -0400344 resource->res.data.extended_irq.producer_consumer =
345 ACPI_CONSUMER;
Bob Moore50eca3e2005-09-30 19:03:00 -0400346 resource->res.data.extended_irq.triggering =
347 link->irq.triggering;
348 resource->res.data.extended_irq.polarity =
349 link->irq.polarity;
350 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
351 resource->res.data.irq.sharable =
Len Brown4be44fc2005-08-05 00:44:28 -0400352 ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400354 resource->res.data.irq.sharable = ACPI_SHARED;
355 resource->res.data.extended_irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 resource->res.data.extended_irq.interrupts[0] = irq;
357 /* ignore resource_source, it's optional */
358 break;
359 default:
Thomas Renningera6fc6722006-06-26 23:58:43 -0400360 ACPI_ERROR((AE_INFO, "Invalid Resource_type %d\n", link->irq.resource_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 result = -EINVAL;
362 goto end;
363
364 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400365 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 /* Attempt to set the resource */
368 status = acpi_set_current_resources(link->handle, &buffer);
369
370 /* check for total failure */
371 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400372 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 result = -ENODEV;
374 goto end;
375 }
376
377 /* Query _STA, set device->status */
378 result = acpi_bus_get_status(link->device);
379 if (result) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400380 ACPI_ERROR((AE_INFO, "Unable to read status"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 goto end;
382 }
383 if (!link->device->status.enabled) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400384 ACPI_WARNING((AE_INFO,
385 "%s [%s] disabled and referenced, BIOS bug",
386 acpi_device_name(link->device),
387 acpi_device_bid(link->device)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 }
389
390 /* Query _CRS, set link->irq.active */
391 result = acpi_pci_link_get_current(link);
392 if (result) {
393 goto end;
394 }
395
396 /*
397 * Is current setting not what we set?
398 * set link->irq.active
399 */
400 if (link->irq.active != irq) {
401 /*
402 * policy: when _CRS doesn't return what we just _SRS
403 * assume _SRS worked and override _CRS value.
404 */
Thomas Renningera6fc6722006-06-26 23:58:43 -0400405 ACPI_WARNING((AE_INFO,
406 "%s [%s] BIOS reported IRQ %d, using IRQ %d",
407 acpi_device_name(link->device),
408 acpi_device_bid(link->device), link->irq.active, irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 link->irq.active = irq;
410 }
411
412 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d\n", link->irq.active));
Len Brown4be44fc2005-08-05 00:44:28 -0400413
414 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 kfree(resource);
416 return_VALUE(result);
417}
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419/* --------------------------------------------------------------------------
420 PCI Link IRQ Management
421 -------------------------------------------------------------------------- */
422
423/*
424 * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt
425 * Link Devices to move the PIRQs around to minimize sharing.
426 *
427 * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs
428 * that the BIOS has already set to active. This is necessary because
429 * ACPI has no automatic means of knowing what ISA IRQs are used. Note that
430 * if the BIOS doesn't set a Link Device active, ACPI needs to program it
431 * even if acpi_irq_nobalance is set.
432 *
433 * A tables of penalties avoids directing PCI interrupts to well known
434 * ISA IRQs. Boot params are available to over-ride the default table:
435 *
436 * List interrupts that are free for PCI use.
437 * acpi_irq_pci=n[,m]
438 *
439 * List interrupts that should not be used for PCI:
440 * acpi_irq_isa=n[,m]
441 *
442 * Note that PCI IRQ routers have a list of possible IRQs,
443 * which may not include the IRQs this table says are available.
444 *
445 * Since this heuristic can't tell the difference between a link
446 * that no device will attach to, vs. a link which may be shared
447 * by multiple active devices -- it is not optimal.
448 *
449 * If interrupt performance is that important, get an IO-APIC system
450 * with a pin dedicated to each device. Or for that matter, an MSI
451 * enabled system.
452 */
453
454#define ACPI_MAX_IRQS 256
455#define ACPI_MAX_ISA_IRQ 16
456
457#define PIRQ_PENALTY_PCI_AVAILABLE (0)
458#define PIRQ_PENALTY_PCI_POSSIBLE (16*16)
459#define PIRQ_PENALTY_PCI_USING (16*16*16)
460#define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16)
461#define PIRQ_PENALTY_ISA_USED (16*16*16*16*16)
462#define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16)
463
464static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
465 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ0 timer */
466 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ1 keyboard */
467 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ2 cascade */
Len Brown4be44fc2005-08-05 00:44:28 -0400468 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ3 serial */
469 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ4 serial */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ5 sometimes SoundBlaster */
471 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ6 */
472 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ7 parallel, spurious */
473 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ8 rtc, sometimes */
474 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */
475 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */
476 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */
477 PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */
478 PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */
479 PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */
480 PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */
Len Brown4be44fc2005-08-05 00:44:28 -0400481 /* >IRQ15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482};
483
Len Brown4be44fc2005-08-05 00:44:28 -0400484int __init acpi_irq_penalty_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
Len Brown4be44fc2005-08-05 00:44:28 -0400486 struct list_head *node = NULL;
487 struct acpi_pci_link *link = NULL;
488 int i = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 ACPI_FUNCTION_TRACE("acpi_irq_penalty_init");
491
492 /*
493 * Update penalties to facilitate IRQ balancing.
494 */
495 list_for_each(node, &acpi_link.entries) {
496
497 link = list_entry(node, struct acpi_pci_link, node);
498 if (!link) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400499 ACPI_ERROR((AE_INFO, "Invalid link context"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 continue;
501 }
502
503 /*
504 * reflect the possible and active irqs in the penalty table --
505 * useful for breaking ties.
506 */
507 if (link->irq.possible_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400508 int penalty =
509 PIRQ_PENALTY_PCI_POSSIBLE /
510 link->irq.possible_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 for (i = 0; i < link->irq.possible_count; i++) {
513 if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ)
Len Brown4be44fc2005-08-05 00:44:28 -0400514 acpi_irq_penalty[link->irq.
515 possible[i]] +=
516 penalty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 }
518
519 } else if (link->irq.active) {
Len Brown4be44fc2005-08-05 00:44:28 -0400520 acpi_irq_penalty[link->irq.active] +=
521 PIRQ_PENALTY_PCI_POSSIBLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 }
523 }
524 /* Add a penalty for the SCI */
525 acpi_irq_penalty[acpi_fadt.sci_int] += PIRQ_PENALTY_PCI_USING;
526
527 return_VALUE(0);
528}
529
530static int acpi_irq_balance; /* 0: static, 1: balance */
531
Len Brown4be44fc2005-08-05 00:44:28 -0400532static int acpi_pci_link_allocate(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533{
Len Brown4be44fc2005-08-05 00:44:28 -0400534 int irq;
535 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate");
538
David Shaohua Li87bec662005-07-27 23:02:00 -0400539 if (link->irq.initialized) {
540 if (link->refcnt == 0)
541 /* This means the link is disabled but initialized */
542 acpi_pci_link_set(link, link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return_VALUE(0);
David Shaohua Li87bec662005-07-27 23:02:00 -0400544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 /*
547 * search for active IRQ in list of possible IRQs.
548 */
549 for (i = 0; i < link->irq.possible_count; ++i) {
550 if (link->irq.active == link->irq.possible[i])
551 break;
552 }
553 /*
554 * forget active IRQ that is not in possible list
555 */
556 if (i == link->irq.possible_count) {
557 if (acpi_strict)
Thomas Renningera6fc6722006-06-26 23:58:43 -0400558 ACPI_WARNING((AE_INFO, "_CRS %d not found"
559 " in _PRS", link->irq.active));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 link->irq.active = 0;
561 }
562
563 /*
564 * if active found, use it; else pick entry from end of possible list.
565 */
566 if (link->irq.active) {
567 irq = link->irq.active;
568 } else {
569 irq = link->irq.possible[link->irq.possible_count - 1];
570 }
571
572 if (acpi_irq_balance || !link->irq.active) {
573 /*
574 * Select the best IRQ. This is done in reverse to promote
575 * the use of IRQs 9, 10, 11, and >15.
576 */
577 for (i = (link->irq.possible_count - 1); i >= 0; i--) {
Len Brown4be44fc2005-08-05 00:44:28 -0400578 if (acpi_irq_penalty[irq] >
579 acpi_irq_penalty[link->irq.possible[i]])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 irq = link->irq.possible[i];
581 }
582 }
583
584 /* Attempt to enable the link device at this IRQ. */
585 if (acpi_pci_link_set(link, irq)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400586 ACPI_ERROR((AE_INFO, "Unable to set IRQ for %s [%s]. "
587 "Try pci=noacpi or acpi=off",
588 acpi_device_name(link->device),
589 acpi_device_bid(link->device)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 return_VALUE(-ENODEV);
591 } else {
592 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
Len Brown4be44fc2005-08-05 00:44:28 -0400593 printk(PREFIX "%s [%s] enabled at IRQ %d\n",
594 acpi_device_name(link->device),
595 acpi_device_bid(link->device), link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 }
597
598 link->irq.initialized = 1;
599
600 return_VALUE(0);
601}
602
603/*
David Shaohua Li87bec662005-07-27 23:02:00 -0400604 * acpi_pci_link_allocate_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 * success: return IRQ >= 0
606 * failure: return -1
607 */
608
609int
Len Brown4be44fc2005-08-05 00:44:28 -0400610acpi_pci_link_allocate_irq(acpi_handle handle,
611 int index,
Bob Moore50eca3e2005-09-30 19:03:00 -0400612 int *triggering, int *polarity, char **name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
Len Brown4be44fc2005-08-05 00:44:28 -0400614 int result = 0;
615 struct acpi_device *device = NULL;
616 struct acpi_pci_link *link = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
David Shaohua Li87bec662005-07-27 23:02:00 -0400618 ACPI_FUNCTION_TRACE("acpi_pci_link_allocate_irq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 result = acpi_bus_get_device(handle, &device);
621 if (result) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400622 ACPI_ERROR((AE_INFO, "Invalid link device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 return_VALUE(-1);
624 }
625
Len Brown4be44fc2005-08-05 00:44:28 -0400626 link = (struct acpi_pci_link *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 if (!link) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400628 ACPI_ERROR((AE_INFO, "Invalid link context"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return_VALUE(-1);
630 }
631
632 /* TBD: Support multiple index (IRQ) entries per Link Device */
633 if (index) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400634 ACPI_ERROR((AE_INFO, "Invalid index %d", index));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 return_VALUE(-1);
636 }
637
Ingo Molnar36e43092006-04-27 05:25:00 -0400638 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400639 if (acpi_pci_link_allocate(link)) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400640 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 return_VALUE(-1);
David Shaohua Li87bec662005-07-27 23:02:00 -0400642 }
Len Brown4be44fc2005-08-05 00:44:28 -0400643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 if (!link->irq.active) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400645 mutex_unlock(&acpi_link_lock);
Thomas Renningera6fc6722006-06-26 23:58:43 -0400646 ACPI_ERROR((AE_INFO, "Link active IRQ is 0!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 return_VALUE(-1);
648 }
Len Brown4be44fc2005-08-05 00:44:28 -0400649 link->refcnt++;
Ingo Molnar36e43092006-04-27 05:25:00 -0400650 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Bob Moore50eca3e2005-09-30 19:03:00 -0400652 if (triggering)
653 *triggering = link->irq.triggering;
654 if (polarity)
655 *polarity = link->irq.polarity;
Len Brown4be44fc2005-08-05 00:44:28 -0400656 if (name)
657 *name = acpi_device_bid(link->device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400658 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400659 "Link %s is referenced\n",
660 acpi_device_bid(link->device)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 return_VALUE(link->irq.active);
662}
663
David Shaohua Li87bec662005-07-27 23:02:00 -0400664/*
665 * We don't change link's irq information here. After it is reenabled, we
666 * continue use the info
667 */
Len Brown4be44fc2005-08-05 00:44:28 -0400668int acpi_pci_link_free_irq(acpi_handle handle)
David Shaohua Li87bec662005-07-27 23:02:00 -0400669{
Len Brown4be44fc2005-08-05 00:44:28 -0400670 struct acpi_device *device = NULL;
671 struct acpi_pci_link *link = NULL;
672 acpi_status result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
David Shaohua Li87bec662005-07-27 23:02:00 -0400674 ACPI_FUNCTION_TRACE("acpi_pci_link_free_irq");
675
676 result = acpi_bus_get_device(handle, &device);
677 if (result) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400678 ACPI_ERROR((AE_INFO, "Invalid link device"));
David Shaohua Li87bec662005-07-27 23:02:00 -0400679 return_VALUE(-1);
680 }
681
Len Brown4be44fc2005-08-05 00:44:28 -0400682 link = (struct acpi_pci_link *)acpi_driver_data(device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400683 if (!link) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400684 ACPI_ERROR((AE_INFO, "Invalid link context"));
David Shaohua Li87bec662005-07-27 23:02:00 -0400685 return_VALUE(-1);
686 }
687
Ingo Molnar36e43092006-04-27 05:25:00 -0400688 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400689 if (!link->irq.initialized) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400690 mutex_unlock(&acpi_link_lock);
Thomas Renningera6fc6722006-06-26 23:58:43 -0400691 ACPI_ERROR((AE_INFO, "Link isn't initialized"));
David Shaohua Li87bec662005-07-27 23:02:00 -0400692 return_VALUE(-1);
693 }
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400694#ifdef FUTURE_USE
695 /*
696 * The Link reference count allows us to _DISable an unused link
697 * and suspend time, and set it again on resume.
698 * However, 2.6.12 still has irq_router.resume
699 * which blindly restores the link state.
700 * So we disable the reference count method
701 * to prevent duplicate acpi_pci_link_set()
702 * which would harm some systems
703 */
Len Brown4be44fc2005-08-05 00:44:28 -0400704 link->refcnt--;
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400705#endif
David Shaohua Li87bec662005-07-27 23:02:00 -0400706 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400707 "Link %s is dereferenced\n",
708 acpi_device_bid(link->device)));
David Shaohua Li87bec662005-07-27 23:02:00 -0400709
710 if (link->refcnt == 0) {
711 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL);
712 }
Ingo Molnar36e43092006-04-27 05:25:00 -0400713 mutex_unlock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400714 return_VALUE(link->irq.active);
715}
Len Brown4be44fc2005-08-05 00:44:28 -0400716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717/* --------------------------------------------------------------------------
718 Driver Interface
719 -------------------------------------------------------------------------- */
720
Len Brown4be44fc2005-08-05 00:44:28 -0400721static int acpi_pci_link_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
Len Brown4be44fc2005-08-05 00:44:28 -0400723 int result = 0;
724 struct acpi_pci_link *link = NULL;
725 int i = 0;
726 int found = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 ACPI_FUNCTION_TRACE("acpi_pci_link_add");
729
730 if (!device)
731 return_VALUE(-EINVAL);
732
733 link = kmalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
734 if (!link)
735 return_VALUE(-ENOMEM);
736 memset(link, 0, sizeof(struct acpi_pci_link));
737
738 link->device = device;
739 link->handle = device->handle;
740 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
741 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
742 acpi_driver_data(device) = link;
743
Ingo Molnar36e43092006-04-27 05:25:00 -0400744 mutex_lock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 result = acpi_pci_link_get_possible(link);
746 if (result)
747 goto end;
748
749 /* query and set link->irq.active */
750 acpi_pci_link_get_current(link);
751
752 printk(PREFIX "%s [%s] (IRQs", acpi_device_name(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400753 acpi_device_bid(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 for (i = 0; i < link->irq.possible_count; i++) {
755 if (link->irq.active == link->irq.possible[i]) {
756 printk(" *%d", link->irq.possible[i]);
757 found = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400758 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 printk(" %d", link->irq.possible[i]);
760 }
761
762 printk(")");
763
764 if (!found)
765 printk(" *%d", link->irq.active);
766
Len Brown4be44fc2005-08-05 00:44:28 -0400767 if (!link->device->status.enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 printk(", disabled.");
769
770 printk("\n");
771
772 /* TBD: Acquire/release lock */
773 list_add_tail(&link->node, &acpi_link.entries);
774 acpi_link.count++;
775
Len Brown4be44fc2005-08-05 00:44:28 -0400776 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 /* disable all links -- to be activated on use */
778 acpi_ut_evaluate_object(link->handle, "_DIS", 0, NULL);
Ingo Molnar36e43092006-04-27 05:25:00 -0400779 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 if (result)
782 kfree(link);
783
784 return_VALUE(result);
785}
786
Len Brown4be44fc2005-08-05 00:44:28 -0400787static int acpi_pci_link_resume(struct acpi_pci_link *link)
Linus Torvalds697a2d62005-08-01 12:37:54 -0700788{
789 ACPI_FUNCTION_TRACE("acpi_pci_link_resume");
790
791 if (link->refcnt && link->irq.active && link->irq.initialized)
792 return_VALUE(acpi_pci_link_set(link, link->irq.active));
793 else
794 return_VALUE(0);
795}
796
David Shaohua Li11e981f2005-08-03 23:46:33 -0400797/*
798 * FIXME: this is a workaround to avoid nasty warning. It will be removed
799 * after every device calls pci_disable_device in .resume.
800 */
801int acpi_in_resume;
Len Brown4be44fc2005-08-05 00:44:28 -0400802static int irqrouter_resume(struct sys_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
Len Brown4be44fc2005-08-05 00:44:28 -0400804 struct list_head *node = NULL;
805 struct acpi_pci_link *link = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Linus Torvalds697a2d62005-08-01 12:37:54 -0700807 ACPI_FUNCTION_TRACE("irqrouter_resume");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Linus Torvalds56035092006-06-19 18:05:09 -0700809 /* Make sure SCI is enabled again (Apple firmware bug?) */
810 acpi_set_register(ACPI_BITREG_SCI_ENABLE, 1, ACPI_MTX_DO_NOT_LOCK);
811
David Shaohua Li11e981f2005-08-03 23:46:33 -0400812 acpi_in_resume = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 list_for_each(node, &acpi_link.entries) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 link = list_entry(node, struct acpi_pci_link, node);
815 if (!link) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400816 ACPI_ERROR((AE_INFO, "Invalid link context"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 continue;
818 }
Linus Torvalds697a2d62005-08-01 12:37:54 -0700819 acpi_pci_link_resume(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 }
David Shaohua Li11e981f2005-08-03 23:46:33 -0400821 acpi_in_resume = 0;
Linus Torvalds697a2d62005-08-01 12:37:54 -0700822 return_VALUE(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
Len Brown4be44fc2005-08-05 00:44:28 -0400825static int acpi_pci_link_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
827 struct acpi_pci_link *link = NULL;
828
829 ACPI_FUNCTION_TRACE("acpi_pci_link_remove");
830
831 if (!device || !acpi_driver_data(device))
832 return_VALUE(-EINVAL);
833
Len Brown4be44fc2005-08-05 00:44:28 -0400834 link = (struct acpi_pci_link *)acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Ingo Molnar36e43092006-04-27 05:25:00 -0400836 mutex_lock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 list_del(&link->node);
Ingo Molnar36e43092006-04-27 05:25:00 -0400838 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 kfree(link);
841
842 return_VALUE(0);
843}
844
845/*
846 * modify acpi_irq_penalty[] from cmdline
847 */
848static int __init acpi_irq_penalty_update(char *str, int used)
849{
850 int i;
851
852 for (i = 0; i < 16; i++) {
853 int retval;
854 int irq;
855
Len Brown4be44fc2005-08-05 00:44:28 -0400856 retval = get_option(&str, &irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 if (!retval)
859 break; /* no number found */
860
861 if (irq < 0)
862 continue;
Len Brown4be44fc2005-08-05 00:44:28 -0400863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 if (irq >= ACPI_MAX_IRQS)
865 continue;
866
867 if (used)
868 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
869 else
870 acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE;
871
872 if (retval != 2) /* no next number */
873 break;
874 }
875 return 1;
876}
877
878/*
879 * We'd like PNP to call this routine for the
880 * single ISA_USED value for each legacy device.
881 * But instead it calls us with each POSSIBLE setting.
882 * There is no ISA_POSSIBLE weight, so we simply use
883 * the (small) PCI_USING penalty.
884 */
David Shaohua Lic9c3e452005-04-01 00:07:31 -0500885void acpi_penalize_isa_irq(int irq, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886{
David Shaohua Lic9c3e452005-04-01 00:07:31 -0500887 if (active)
888 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
889 else
890 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891}
892
893/*
894 * Over-ride default table to reserve additional IRQs for use by ISA
895 * e.g. acpi_irq_isa=5
896 * Useful for telling ACPI how not to interfere with your ISA sound card.
897 */
898static int __init acpi_irq_isa(char *str)
899{
900 return acpi_irq_penalty_update(str, 1);
901}
Len Brown4be44fc2005-08-05 00:44:28 -0400902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903__setup("acpi_irq_isa=", acpi_irq_isa);
904
905/*
906 * Over-ride default table to free additional IRQs for use by PCI
907 * e.g. acpi_irq_pci=7,15
908 * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing.
909 */
910static int __init acpi_irq_pci(char *str)
911{
912 return acpi_irq_penalty_update(str, 0);
913}
Len Brown4be44fc2005-08-05 00:44:28 -0400914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915__setup("acpi_irq_pci=", acpi_irq_pci);
916
917static int __init acpi_irq_nobalance_set(char *str)
918{
919 acpi_irq_balance = 0;
920 return 1;
921}
Len Brown4be44fc2005-08-05 00:44:28 -0400922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923__setup("acpi_irq_nobalance", acpi_irq_nobalance_set);
924
925int __init acpi_irq_balance_set(char *str)
926{
927 acpi_irq_balance = 1;
928 return 1;
929}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Len Brown4be44fc2005-08-05 00:44:28 -0400931__setup("acpi_irq_balance", acpi_irq_balance_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
David Shaohua Li87bec662005-07-27 23:02:00 -0400933/* FIXME: we will remove this interface after all drivers call pci_disable_device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934static struct sysdev_class irqrouter_sysdev_class = {
Len Brown4be44fc2005-08-05 00:44:28 -0400935 set_kset_name("irqrouter"),
936 .resume = irqrouter_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937};
938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939static struct sys_device device_irqrouter = {
Len Brown4be44fc2005-08-05 00:44:28 -0400940 .id = 0,
941 .cls = &irqrouter_sysdev_class,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942};
943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944static int __init irqrouter_init_sysfs(void)
945{
946 int error;
947
948 ACPI_FUNCTION_TRACE("irqrouter_init_sysfs");
949
950 if (acpi_disabled || acpi_noirq)
951 return_VALUE(0);
952
953 error = sysdev_class_register(&irqrouter_sysdev_class);
954 if (!error)
955 error = sysdev_register(&device_irqrouter);
956
957 return_VALUE(error);
Len Brown4be44fc2005-08-05 00:44:28 -0400958}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
960device_initcall(irqrouter_init_sysfs);
961
Len Brown4be44fc2005-08-05 00:44:28 -0400962static int __init acpi_pci_link_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963{
964 ACPI_FUNCTION_TRACE("acpi_pci_link_init");
965
966 if (acpi_noirq)
967 return_VALUE(0);
968
969 acpi_link.count = 0;
970 INIT_LIST_HEAD(&acpi_link.entries);
971
972 if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0)
973 return_VALUE(-ENODEV);
974
975 return_VALUE(0);
976}
977
978subsys_initcall(acpi_pci_link_init);