blob: 8d47a5846aebc192479d943b0a4826030b5a4344 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090042#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#include <acpi/acpi_bus.h>
45#include <acpi/acpi_drivers.h>
46
Len Browna192a952009-07-28 16:45:54 -040047#define PREFIX "ACPI: "
48
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070049#define _COMPONENT ACPI_PCI_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050050ACPI_MODULE_NAME("pci_link");
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define ACPI_PCI_LINK_CLASS "pci_irq_routing"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link"
53#define ACPI_PCI_LINK_FILE_INFO "info"
54#define ACPI_PCI_LINK_FILE_STATUS "state"
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070055#define ACPI_PCI_LINK_MAX_POSSIBLE 16
56
Len Brown4be44fc2005-08-05 00:44:28 -040057static int acpi_pci_link_add(struct acpi_device *device);
58static int acpi_pci_link_remove(struct acpi_device *device, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Márton Némethc97adf92010-01-10 17:15:36 +010060static const struct acpi_device_id link_device_ids[] = {
Thomas Renninger1ba90e32007-07-23 14:44:41 +020061 {"PNP0C0F", 0},
62 {"", 0},
63};
64MODULE_DEVICE_TABLE(acpi, link_device_ids);
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static struct acpi_driver acpi_pci_link_driver = {
Len Brownc2b67052007-02-12 23:33:40 -050067 .name = "pci_link",
Len Brown4be44fc2005-08-05 00:44:28 -040068 .class = ACPI_PCI_LINK_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020069 .ids = link_device_ids,
Len Brown4be44fc2005-08-05 00:44:28 -040070 .ops = {
71 .add = acpi_pci_link_add,
72 .remove = acpi_pci_link_remove,
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070073 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070074};
75
David Shaohua Li87bec662005-07-27 23:02:00 -040076/*
77 * If a link is initialized, we never change its active and initialized
78 * later even the link is disable. Instead, we just repick the active irq
79 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070080struct acpi_pci_link_irq {
Len Brown4be44fc2005-08-05 00:44:28 -040081 u8 active; /* Current IRQ */
Bob Moore50eca3e2005-09-30 19:03:00 -040082 u8 triggering; /* All IRQs */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070083 u8 polarity; /* All IRQs */
Len Brown4be44fc2005-08-05 00:44:28 -040084 u8 resource_type;
85 u8 possible_count;
86 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
87 u8 initialized:1;
88 u8 reserved:7;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089};
90
91struct acpi_pci_link {
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -070092 struct list_head list;
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070093 struct acpi_device *device;
94 struct acpi_pci_link_irq irq;
95 int refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};
97
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -070098static LIST_HEAD(acpi_link_list);
Adrian Bunke5685b92007-10-24 18:24:42 +020099static DEFINE_MUTEX(acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/* --------------------------------------------------------------------------
102 PCI Link Device Management
103 -------------------------------------------------------------------------- */
104
105/*
106 * set context (link) possible list from resource list
107 */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700108static acpi_status acpi_pci_link_check_possible(struct acpi_resource *resource,
109 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200111 struct acpi_pci_link *link = context;
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700112 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Len Browneca008c2005-09-22 00:25:18 -0400114 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400115 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600116 case ACPI_RESOURCE_TYPE_END_TAG:
Patrick Mocheld550d982006-06-27 00:41:40 -0400117 return AE_OK;
Bob Moore50eca3e2005-09-30 19:03:00 -0400118 case ACPI_RESOURCE_TYPE_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400119 {
120 struct acpi_resource_irq *p = &resource->data.irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400121 if (!p || !p->interrupt_count) {
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600122 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
123 "Blank _PRS IRQ resource\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400124 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 }
Len Brown4be44fc2005-08-05 00:44:28 -0400126 for (i = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400127 (i < p->interrupt_count
Len Brown4be44fc2005-08-05 00:44:28 -0400128 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
129 if (!p->interrupts[i]) {
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600130 printk(KERN_WARNING PREFIX
131 "Invalid _PRS IRQ %d\n",
132 p->interrupts[i]);
Len Brown4be44fc2005-08-05 00:44:28 -0400133 continue;
134 }
135 link->irq.possible[i] = p->interrupts[i];
136 link->irq.possible_count++;
137 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400138 link->irq.triggering = p->triggering;
139 link->irq.polarity = p->polarity;
140 link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ;
Len Brown4be44fc2005-08-05 00:44:28 -0400141 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400143 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400144 {
Bob Moore50eca3e2005-09-30 19:03:00 -0400145 struct acpi_resource_extended_irq *p =
Len Brown4be44fc2005-08-05 00:44:28 -0400146 &resource->data.extended_irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400147 if (!p || !p->interrupt_count) {
Len Browncece9292006-06-26 23:04:31 -0400148 printk(KERN_WARNING PREFIX
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600149 "Blank _PRS EXT IRQ resource\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400150 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
Len Brown4be44fc2005-08-05 00:44:28 -0400152 for (i = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400153 (i < p->interrupt_count
Len Brown4be44fc2005-08-05 00:44:28 -0400154 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
155 if (!p->interrupts[i]) {
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600156 printk(KERN_WARNING PREFIX
157 "Invalid _PRS IRQ %d\n",
158 p->interrupts[i]);
Len Brown4be44fc2005-08-05 00:44:28 -0400159 continue;
160 }
161 link->irq.possible[i] = p->interrupts[i];
162 link->irq.possible_count++;
163 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400164 link->irq.triggering = p->triggering;
165 link->irq.polarity = p->polarity;
166 link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
Len Brown4be44fc2005-08-05 00:44:28 -0400167 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 default:
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600170 printk(KERN_ERR PREFIX "_PRS resource type 0x%x isn't an IRQ\n",
171 resource->type);
Patrick Mocheld550d982006-06-27 00:41:40 -0400172 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
174
Patrick Mocheld550d982006-06-27 00:41:40 -0400175 return AE_CTRL_TERMINATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
Len Brown4be44fc2005-08-05 00:44:28 -0400178static int acpi_pci_link_get_possible(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Len Brown4be44fc2005-08-05 00:44:28 -0400180 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Patrick Mochel67a71362006-05-19 16:54:42 -0400182 status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS,
Len Brown4be44fc2005-08-05 00:44:28 -0400183 acpi_pci_link_check_possible, link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400185 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400186 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
Len Brown4be44fc2005-08-05 00:44:28 -0400189 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
190 "Found %d possible IRQs\n",
191 link->irq.possible_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Patrick Mocheld550d982006-06-27 00:41:40 -0400193 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700196static acpi_status acpi_pci_link_check_current(struct acpi_resource *resource,
197 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700199 int *irq = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Len Browneca008c2005-09-22 00:25:18 -0400201 switch (resource->type) {
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600202 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
203 case ACPI_RESOURCE_TYPE_END_TAG:
204 return AE_OK;
Bob Moore50eca3e2005-09-30 19:03:00 -0400205 case ACPI_RESOURCE_TYPE_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400206 {
207 struct acpi_resource_irq *p = &resource->data.irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400208 if (!p || !p->interrupt_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400209 /*
210 * IRQ descriptors may have no IRQ# bits set,
211 * particularly those those w/ _STA disabled
212 */
213 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600214 "Blank _CRS IRQ resource\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400215 return AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400216 }
217 *irq = p->interrupts[0];
218 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400220 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400221 {
Bob Moore50eca3e2005-09-30 19:03:00 -0400222 struct acpi_resource_extended_irq *p =
Len Brown4be44fc2005-08-05 00:44:28 -0400223 &resource->data.extended_irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400224 if (!p || !p->interrupt_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400225 /*
226 * extended IRQ descriptors must
227 * return at least 1 IRQ
228 */
Len Browncece9292006-06-26 23:04:31 -0400229 printk(KERN_WARNING PREFIX
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600230 "Blank _CRS EXT IRQ resource\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400231 return AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400232 }
233 *irq = p->interrupts[0];
234 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 }
Len Brownd4ec6c72006-01-26 17:23:38 -0500236 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 default:
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600238 printk(KERN_ERR PREFIX "_CRS resource type 0x%x isn't an IRQ\n",
239 resource->type);
Patrick Mocheld550d982006-06-27 00:41:40 -0400240 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600242
Patrick Mocheld550d982006-06-27 00:41:40 -0400243 return AE_CTRL_TERMINATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
246/*
247 * Run _CRS and set link->irq.active
248 *
249 * return value:
250 * 0 - success
251 * !0 - failure
252 */
Len Brown4be44fc2005-08-05 00:44:28 -0400253static int acpi_pci_link_get_current(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Len Brown4be44fc2005-08-05 00:44:28 -0400255 int result = 0;
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700256 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400257 int irq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 link->irq.active = 0;
260
261 /* in practice, status disabled is meaningless, ignore it */
262 if (acpi_strict) {
263 /* Query _STA, set link->device->status */
264 result = acpi_bus_get_status(link->device);
265 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400266 printk(KERN_ERR PREFIX "Unable to read status\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 goto end;
268 }
269
270 if (!link->device->status.enabled) {
271 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400272 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274 }
275
276 /*
277 * Query and parse _CRS to get the current IRQ assignment.
278 */
279
Patrick Mochel67a71362006-05-19 16:54:42 -0400280 status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS,
Len Brown4be44fc2005-08-05 00:44:28 -0400281 acpi_pci_link_check_current, &irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400283 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 result = -ENODEV;
285 goto end;
286 }
287
288 if (acpi_strict && !irq) {
Len Brown64684632006-06-26 23:41:38 -0400289 printk(KERN_ERR PREFIX "_CRS returned 0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 result = -ENODEV;
291 }
292
293 link->irq.active = irq;
294
295 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active));
296
Len Brown4be44fc2005-08-05 00:44:28 -0400297 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400298 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300
Len Brown4be44fc2005-08-05 00:44:28 -0400301static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700303 int result;
304 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 struct {
Len Brown4be44fc2005-08-05 00:44:28 -0400306 struct acpi_resource res;
307 struct acpi_resource end;
308 } *resource;
309 struct acpi_buffer buffer = { 0, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Bjorn Helgaas6eca4b42009-02-17 14:00:50 -0700311 if (!irq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400312 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Burman Yan36bcbec2006-12-19 12:56:11 -0800314 resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
Len Brown4be44fc2005-08-05 00:44:28 -0400315 if (!resource)
Patrick Mocheld550d982006-06-27 00:41:40 -0400316 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Len Brown4be44fc2005-08-05 00:44:28 -0400318 buffer.length = sizeof(*resource) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 buffer.pointer = resource;
320
Len Brown4be44fc2005-08-05 00:44:28 -0400321 switch (link->irq.resource_type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400322 case ACPI_RESOURCE_TYPE_IRQ:
323 resource->res.type = ACPI_RESOURCE_TYPE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 resource->res.length = sizeof(struct acpi_resource);
Bob Moore50eca3e2005-09-30 19:03:00 -0400325 resource->res.data.irq.triggering = link->irq.triggering;
326 resource->res.data.irq.polarity =
327 link->irq.polarity;
328 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
329 resource->res.data.irq.sharable =
Len Brown4be44fc2005-08-05 00:44:28 -0400330 ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400332 resource->res.data.irq.sharable = ACPI_SHARED;
333 resource->res.data.irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 resource->res.data.irq.interrupts[0] = irq;
335 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400336
Bob Moore50eca3e2005-09-30 19:03:00 -0400337 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
338 resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 resource->res.length = sizeof(struct acpi_resource);
Len Brown4be44fc2005-08-05 00:44:28 -0400340 resource->res.data.extended_irq.producer_consumer =
341 ACPI_CONSUMER;
Bob Moore50eca3e2005-09-30 19:03:00 -0400342 resource->res.data.extended_irq.triggering =
343 link->irq.triggering;
344 resource->res.data.extended_irq.polarity =
345 link->irq.polarity;
346 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
347 resource->res.data.irq.sharable =
Len Brown4be44fc2005-08-05 00:44:28 -0400348 ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400350 resource->res.data.irq.sharable = ACPI_SHARED;
351 resource->res.data.extended_irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 resource->res.data.extended_irq.interrupts[0] = irq;
353 /* ignore resource_source, it's optional */
354 break;
355 default:
Len Brown64684632006-06-26 23:41:38 -0400356 printk(KERN_ERR PREFIX "Invalid Resource_type %d\n", link->irq.resource_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 result = -EINVAL;
358 goto end;
359
360 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400361 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
363 /* Attempt to set the resource */
Patrick Mochel67a71362006-05-19 16:54:42 -0400364 status = acpi_set_current_resources(link->device->handle, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 /* check for total failure */
367 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400368 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 result = -ENODEV;
370 goto end;
371 }
372
373 /* Query _STA, set device->status */
374 result = acpi_bus_get_status(link->device);
375 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400376 printk(KERN_ERR PREFIX "Unable to read status\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 goto end;
378 }
379 if (!link->device->status.enabled) {
Len Browncece9292006-06-26 23:04:31 -0400380 printk(KERN_WARNING PREFIX
381 "%s [%s] disabled and referenced, BIOS bug\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400382 acpi_device_name(link->device),
Len Browncece9292006-06-26 23:04:31 -0400383 acpi_device_bid(link->device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 }
385
386 /* Query _CRS, set link->irq.active */
387 result = acpi_pci_link_get_current(link);
388 if (result) {
389 goto end;
390 }
391
392 /*
393 * Is current setting not what we set?
394 * set link->irq.active
395 */
396 if (link->irq.active != irq) {
397 /*
398 * policy: when _CRS doesn't return what we just _SRS
399 * assume _SRS worked and override _CRS value.
400 */
Len Browncece9292006-06-26 23:04:31 -0400401 printk(KERN_WARNING PREFIX
402 "%s [%s] BIOS reported IRQ %d, using IRQ %d\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400403 acpi_device_name(link->device),
Len Browncece9292006-06-26 23:04:31 -0400404 acpi_device_bid(link->device), link->irq.active, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 link->irq.active = irq;
406 }
407
408 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d\n", link->irq.active));
Len Brown4be44fc2005-08-05 00:44:28 -0400409
410 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 kfree(resource);
Patrick Mocheld550d982006-06-27 00:41:40 -0400412 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415/* --------------------------------------------------------------------------
416 PCI Link IRQ Management
417 -------------------------------------------------------------------------- */
418
419/*
420 * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt
421 * Link Devices to move the PIRQs around to minimize sharing.
422 *
423 * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs
424 * that the BIOS has already set to active. This is necessary because
425 * ACPI has no automatic means of knowing what ISA IRQs are used. Note that
426 * if the BIOS doesn't set a Link Device active, ACPI needs to program it
427 * even if acpi_irq_nobalance is set.
428 *
429 * A tables of penalties avoids directing PCI interrupts to well known
430 * ISA IRQs. Boot params are available to over-ride the default table:
431 *
432 * List interrupts that are free for PCI use.
433 * acpi_irq_pci=n[,m]
434 *
435 * List interrupts that should not be used for PCI:
436 * acpi_irq_isa=n[,m]
437 *
438 * Note that PCI IRQ routers have a list of possible IRQs,
439 * which may not include the IRQs this table says are available.
440 *
441 * Since this heuristic can't tell the difference between a link
442 * that no device will attach to, vs. a link which may be shared
443 * by multiple active devices -- it is not optimal.
444 *
445 * If interrupt performance is that important, get an IO-APIC system
446 * with a pin dedicated to each device. Or for that matter, an MSI
447 * enabled system.
448 */
449
450#define ACPI_MAX_IRQS 256
451#define ACPI_MAX_ISA_IRQ 16
452
453#define PIRQ_PENALTY_PCI_AVAILABLE (0)
454#define PIRQ_PENALTY_PCI_POSSIBLE (16*16)
455#define PIRQ_PENALTY_PCI_USING (16*16*16)
456#define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16)
457#define PIRQ_PENALTY_ISA_USED (16*16*16*16*16)
458#define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16)
459
460static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
461 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ0 timer */
462 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ1 keyboard */
463 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ2 cascade */
Len Brown4be44fc2005-08-05 00:44:28 -0400464 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ3 serial */
465 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ4 serial */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ5 sometimes SoundBlaster */
467 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ6 */
468 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ7 parallel, spurious */
469 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ8 rtc, sometimes */
470 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */
471 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */
472 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700473 PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */
474 PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */
475 PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */
476 PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */
Len Brown4be44fc2005-08-05 00:44:28 -0400477 /* >IRQ15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478};
479
Len Brown4be44fc2005-08-05 00:44:28 -0400480int __init acpi_irq_penalty_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700482 struct acpi_pci_link *link;
483 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 /*
486 * Update penalties to facilitate IRQ balancing.
487 */
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -0700488 list_for_each_entry(link, &acpi_link_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 /*
491 * reflect the possible and active irqs in the penalty table --
492 * useful for breaking ties.
493 */
494 if (link->irq.possible_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400495 int penalty =
496 PIRQ_PENALTY_PCI_POSSIBLE /
497 link->irq.possible_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 for (i = 0; i < link->irq.possible_count; i++) {
500 if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ)
Len Brown4be44fc2005-08-05 00:44:28 -0400501 acpi_irq_penalty[link->irq.
502 possible[i]] +=
503 penalty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
505
506 } else if (link->irq.active) {
Len Brown4be44fc2005-08-05 00:44:28 -0400507 acpi_irq_penalty[link->irq.active] +=
508 PIRQ_PENALTY_PCI_POSSIBLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
510 }
511 /* Add a penalty for the SCI */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300512 acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING;
Patrick Mocheld550d982006-06-27 00:41:40 -0400513 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514}
515
Bjorn Helgaas32836252008-11-05 16:17:52 -0700516static int acpi_irq_balance = -1; /* 0: static, 1: balance */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Len Brown4be44fc2005-08-05 00:44:28 -0400518static int acpi_pci_link_allocate(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
Len Brown4be44fc2005-08-05 00:44:28 -0400520 int irq;
521 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
David Shaohua Li87bec662005-07-27 23:02:00 -0400523 if (link->irq.initialized) {
524 if (link->refcnt == 0)
525 /* This means the link is disabled but initialized */
526 acpi_pci_link_set(link, link->irq.active);
Patrick Mocheld550d982006-06-27 00:41:40 -0400527 return 0;
David Shaohua Li87bec662005-07-27 23:02:00 -0400528 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 /*
531 * search for active IRQ in list of possible IRQs.
532 */
533 for (i = 0; i < link->irq.possible_count; ++i) {
534 if (link->irq.active == link->irq.possible[i])
535 break;
536 }
537 /*
538 * forget active IRQ that is not in possible list
539 */
540 if (i == link->irq.possible_count) {
541 if (acpi_strict)
Len Browncece9292006-06-26 23:04:31 -0400542 printk(KERN_WARNING PREFIX "_CRS %d not found"
543 " in _PRS\n", link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 link->irq.active = 0;
545 }
546
547 /*
548 * if active found, use it; else pick entry from end of possible list.
549 */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700550 if (link->irq.active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 irq = link->irq.active;
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700552 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 irq = link->irq.possible[link->irq.possible_count - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 if (acpi_irq_balance || !link->irq.active) {
556 /*
557 * Select the best IRQ. This is done in reverse to promote
558 * the use of IRQs 9, 10, 11, and >15.
559 */
560 for (i = (link->irq.possible_count - 1); i >= 0; i--) {
Len Brown4be44fc2005-08-05 00:44:28 -0400561 if (acpi_irq_penalty[irq] >
562 acpi_irq_penalty[link->irq.possible[i]])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 irq = link->irq.possible[i];
564 }
565 }
566
567 /* Attempt to enable the link device at this IRQ. */
568 if (acpi_pci_link_set(link, irq)) {
Len Brown64684632006-06-26 23:41:38 -0400569 printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. "
570 "Try pci=noacpi or acpi=off\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400571 acpi_device_name(link->device),
Len Brown64684632006-06-26 23:41:38 -0400572 acpi_device_bid(link->device));
Patrick Mocheld550d982006-06-27 00:41:40 -0400573 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 } else {
575 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
Frank Seidel4d939152009-02-04 17:03:07 +0100576 printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400577 acpi_device_name(link->device),
578 acpi_device_bid(link->device), link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580
581 link->irq.initialized = 1;
Patrick Mocheld550d982006-06-27 00:41:40 -0400582 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583}
584
585/*
David Shaohua Li87bec662005-07-27 23:02:00 -0400586 * acpi_pci_link_allocate_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 * success: return IRQ >= 0
588 * failure: return -1
589 */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700590int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering,
591 int *polarity, char **name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700593 int result;
594 struct acpi_device *device;
595 struct acpi_pci_link *link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 result = acpi_bus_get_device(handle, &device);
598 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400599 printk(KERN_ERR PREFIX "Invalid link device\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400600 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
602
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200603 link = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400605 printk(KERN_ERR PREFIX "Invalid link context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400606 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
608
609 /* TBD: Support multiple index (IRQ) entries per Link Device */
610 if (index) {
Len Brown64684632006-06-26 23:41:38 -0400611 printk(KERN_ERR PREFIX "Invalid index %d\n", index);
Patrick Mocheld550d982006-06-27 00:41:40 -0400612 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614
Ingo Molnar36e43092006-04-27 05:25:00 -0400615 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400616 if (acpi_pci_link_allocate(link)) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400617 mutex_unlock(&acpi_link_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400618 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400619 }
Len Brown4be44fc2005-08-05 00:44:28 -0400620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 if (!link->irq.active) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400622 mutex_unlock(&acpi_link_lock);
Len Brown64684632006-06-26 23:41:38 -0400623 printk(KERN_ERR PREFIX "Link active IRQ is 0!\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400624 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
Len Brown4be44fc2005-08-05 00:44:28 -0400626 link->refcnt++;
Ingo Molnar36e43092006-04-27 05:25:00 -0400627 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Bob Moore50eca3e2005-09-30 19:03:00 -0400629 if (triggering)
630 *triggering = link->irq.triggering;
631 if (polarity)
632 *polarity = link->irq.polarity;
Len Brown4be44fc2005-08-05 00:44:28 -0400633 if (name)
634 *name = acpi_device_bid(link->device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400635 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400636 "Link %s is referenced\n",
637 acpi_device_bid(link->device)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400638 return (link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639}
640
David Shaohua Li87bec662005-07-27 23:02:00 -0400641/*
642 * We don't change link's irq information here. After it is reenabled, we
643 * continue use the info
644 */
Len Brown4be44fc2005-08-05 00:44:28 -0400645int acpi_pci_link_free_irq(acpi_handle handle)
David Shaohua Li87bec662005-07-27 23:02:00 -0400646{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700647 struct acpi_device *device;
648 struct acpi_pci_link *link;
Len Brown4be44fc2005-08-05 00:44:28 -0400649 acpi_status result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
David Shaohua Li87bec662005-07-27 23:02:00 -0400651 result = acpi_bus_get_device(handle, &device);
652 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400653 printk(KERN_ERR PREFIX "Invalid link device\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400654 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400655 }
656
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200657 link = acpi_driver_data(device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400658 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400659 printk(KERN_ERR PREFIX "Invalid link context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400660 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400661 }
662
Ingo Molnar36e43092006-04-27 05:25:00 -0400663 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400664 if (!link->irq.initialized) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400665 mutex_unlock(&acpi_link_lock);
Len Brown64684632006-06-26 23:41:38 -0400666 printk(KERN_ERR PREFIX "Link isn't initialized\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400667 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400668 }
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400669#ifdef FUTURE_USE
670 /*
671 * The Link reference count allows us to _DISable an unused link
672 * and suspend time, and set it again on resume.
673 * However, 2.6.12 still has irq_router.resume
674 * which blindly restores the link state.
675 * So we disable the reference count method
676 * to prevent duplicate acpi_pci_link_set()
677 * which would harm some systems
678 */
Len Brown4be44fc2005-08-05 00:44:28 -0400679 link->refcnt--;
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400680#endif
David Shaohua Li87bec662005-07-27 23:02:00 -0400681 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400682 "Link %s is dereferenced\n",
683 acpi_device_bid(link->device)));
David Shaohua Li87bec662005-07-27 23:02:00 -0400684
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700685 if (link->refcnt == 0)
donald.d.dugger@intel.com383d7a12008-10-17 07:49:50 -0700686 acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL);
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700687
Ingo Molnar36e43092006-04-27 05:25:00 -0400688 mutex_unlock(&acpi_link_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400689 return (link->irq.active);
David Shaohua Li87bec662005-07-27 23:02:00 -0400690}
Len Brown4be44fc2005-08-05 00:44:28 -0400691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692/* --------------------------------------------------------------------------
693 Driver Interface
694 -------------------------------------------------------------------------- */
695
Len Brown4be44fc2005-08-05 00:44:28 -0400696static int acpi_pci_link_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700698 int result;
699 struct acpi_pci_link *link;
700 int i;
Len Brown4be44fc2005-08-05 00:44:28 -0400701 int found = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Burman Yan36bcbec2006-12-19 12:56:11 -0800703 link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if (!link)
Patrick Mocheld550d982006-06-27 00:41:40 -0400705 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
707 link->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
709 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700710 device->driver_data = link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Ingo Molnar36e43092006-04-27 05:25:00 -0400712 mutex_lock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 result = acpi_pci_link_get_possible(link);
714 if (result)
715 goto end;
716
717 /* query and set link->irq.active */
718 acpi_pci_link_get_current(link);
719
Dan Aloni0dc070b2007-07-09 11:33:18 -0700720 printk(KERN_INFO PREFIX "%s [%s] (IRQs", acpi_device_name(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400721 acpi_device_bid(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 for (i = 0; i < link->irq.possible_count; i++) {
723 if (link->irq.active == link->irq.possible[i]) {
724 printk(" *%d", link->irq.possible[i]);
725 found = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400726 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 printk(" %d", link->irq.possible[i]);
728 }
729
730 printk(")");
731
732 if (!found)
733 printk(" *%d", link->irq.active);
734
Len Brown4be44fc2005-08-05 00:44:28 -0400735 if (!link->device->status.enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 printk(", disabled.");
737
738 printk("\n");
739
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -0700740 list_add_tail(&link->list, &acpi_link_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
Len Brown4be44fc2005-08-05 00:44:28 -0400742 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 /* disable all links -- to be activated on use */
donald.d.dugger@intel.com383d7a12008-10-17 07:49:50 -0700744 acpi_evaluate_object(device->handle, "_DIS", NULL, NULL);
Ingo Molnar36e43092006-04-27 05:25:00 -0400745 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 if (result)
748 kfree(link);
749
Patrick Mocheld550d982006-06-27 00:41:40 -0400750 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751}
752
Len Brown4be44fc2005-08-05 00:44:28 -0400753static int acpi_pci_link_resume(struct acpi_pci_link *link)
Linus Torvalds697a2d62005-08-01 12:37:54 -0700754{
Linus Torvalds697a2d62005-08-01 12:37:54 -0700755 if (link->refcnt && link->irq.active && link->irq.initialized)
Patrick Mocheld550d982006-06-27 00:41:40 -0400756 return (acpi_pci_link_set(link, link->irq.active));
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700757
758 return 0;
Linus Torvalds697a2d62005-08-01 12:37:54 -0700759}
760
Len Brown4be44fc2005-08-05 00:44:28 -0400761static int irqrouter_resume(struct sys_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700763 struct acpi_pci_link *link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -0700765 list_for_each_entry(link, &acpi_link_list, list) {
Linus Torvalds697a2d62005-08-01 12:37:54 -0700766 acpi_pci_link_resume(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400768 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769}
770
Len Brown4be44fc2005-08-05 00:44:28 -0400771static int acpi_pci_link_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700773 struct acpi_pci_link *link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200775 link = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Ingo Molnar36e43092006-04-27 05:25:00 -0400777 mutex_lock(&acpi_link_lock);
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -0700778 list_del(&link->list);
Ingo Molnar36e43092006-04-27 05:25:00 -0400779 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 kfree(link);
Patrick Mocheld550d982006-06-27 00:41:40 -0400782 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783}
784
785/*
786 * modify acpi_irq_penalty[] from cmdline
787 */
788static int __init acpi_irq_penalty_update(char *str, int used)
789{
790 int i;
791
792 for (i = 0; i < 16; i++) {
793 int retval;
794 int irq;
795
Len Brown4be44fc2005-08-05 00:44:28 -0400796 retval = get_option(&str, &irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 if (!retval)
799 break; /* no number found */
800
801 if (irq < 0)
802 continue;
Len Brown4be44fc2005-08-05 00:44:28 -0400803
Bjorn Helgaasfa46d352008-08-01 15:58:17 -0600804 if (irq >= ARRAY_SIZE(acpi_irq_penalty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 continue;
806
807 if (used)
808 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
809 else
810 acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE;
811
812 if (retval != 2) /* no next number */
813 break;
814 }
815 return 1;
816}
817
818/*
819 * We'd like PNP to call this routine for the
820 * single ISA_USED value for each legacy device.
821 * But instead it calls us with each POSSIBLE setting.
822 * There is no ISA_POSSIBLE weight, so we simply use
823 * the (small) PCI_USING penalty.
824 */
David Shaohua Lic9c3e452005-04-01 00:07:31 -0500825void acpi_penalize_isa_irq(int irq, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826{
Bjorn Helgaasfa46d352008-08-01 15:58:17 -0600827 if (irq >= 0 && irq < ARRAY_SIZE(acpi_irq_penalty)) {
828 if (active)
829 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
830 else
831 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING;
832 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
834
835/*
836 * Over-ride default table to reserve additional IRQs for use by ISA
837 * e.g. acpi_irq_isa=5
838 * Useful for telling ACPI how not to interfere with your ISA sound card.
839 */
840static int __init acpi_irq_isa(char *str)
841{
842 return acpi_irq_penalty_update(str, 1);
843}
Len Brown4be44fc2005-08-05 00:44:28 -0400844
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845__setup("acpi_irq_isa=", acpi_irq_isa);
846
847/*
848 * Over-ride default table to free additional IRQs for use by PCI
849 * e.g. acpi_irq_pci=7,15
850 * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing.
851 */
852static int __init acpi_irq_pci(char *str)
853{
854 return acpi_irq_penalty_update(str, 0);
855}
Len Brown4be44fc2005-08-05 00:44:28 -0400856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857__setup("acpi_irq_pci=", acpi_irq_pci);
858
859static int __init acpi_irq_nobalance_set(char *str)
860{
861 acpi_irq_balance = 0;
862 return 1;
863}
Len Brown4be44fc2005-08-05 00:44:28 -0400864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865__setup("acpi_irq_nobalance", acpi_irq_nobalance_set);
866
Roel Kluin8a383ef2008-12-09 20:45:30 +0100867static int __init acpi_irq_balance_set(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868{
869 acpi_irq_balance = 1;
870 return 1;
871}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Len Brown4be44fc2005-08-05 00:44:28 -0400873__setup("acpi_irq_balance", acpi_irq_balance_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
David Shaohua Li87bec662005-07-27 23:02:00 -0400875/* FIXME: we will remove this interface after all drivers call pci_disable_device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876static struct sysdev_class irqrouter_sysdev_class = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +0100877 .name = "irqrouter",
Len Brown4be44fc2005-08-05 00:44:28 -0400878 .resume = irqrouter_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879};
880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881static struct sys_device device_irqrouter = {
Len Brown4be44fc2005-08-05 00:44:28 -0400882 .id = 0,
883 .cls = &irqrouter_sysdev_class,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884};
885
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886static int __init irqrouter_init_sysfs(void)
887{
888 int error;
889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 if (acpi_disabled || acpi_noirq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400891 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
893 error = sysdev_class_register(&irqrouter_sysdev_class);
894 if (!error)
895 error = sysdev_register(&device_irqrouter);
896
Patrick Mocheld550d982006-06-27 00:41:40 -0400897 return error;
Len Brown4be44fc2005-08-05 00:44:28 -0400898}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
900device_initcall(irqrouter_init_sysfs);
901
Len Brown4be44fc2005-08-05 00:44:28 -0400902static int __init acpi_pci_link_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 if (acpi_noirq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400905 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Bjorn Helgaas32836252008-11-05 16:17:52 -0700907 if (acpi_irq_balance == -1) {
908 /* no command line switch: enable balancing in IOAPIC mode */
909 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
910 acpi_irq_balance = 1;
911 else
912 acpi_irq_balance = 0;
913 }
914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -0400916 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
Patrick Mocheld550d982006-06-27 00:41:40 -0400918 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919}
920
921subsys_initcall(acpi_pci_link_init);