blob: dd9ebb9fda4224e9413916984afa82d74dcebdd9 [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
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070046#define _COMPONENT ACPI_PCI_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050047ACPI_MODULE_NAME("pci_link");
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define ACPI_PCI_LINK_CLASS "pci_irq_routing"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define ACPI_PCI_LINK_DEVICE_NAME "PCI Interrupt Link"
50#define ACPI_PCI_LINK_FILE_INFO "info"
51#define ACPI_PCI_LINK_FILE_STATUS "state"
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070052#define ACPI_PCI_LINK_MAX_POSSIBLE 16
53
Len Brown4be44fc2005-08-05 00:44:28 -040054static int acpi_pci_link_add(struct acpi_device *device);
55static int acpi_pci_link_remove(struct acpi_device *device, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Thomas Renninger1ba90e32007-07-23 14:44:41 +020057static struct acpi_device_id link_device_ids[] = {
58 {"PNP0C0F", 0},
59 {"", 0},
60};
61MODULE_DEVICE_TABLE(acpi, link_device_ids);
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static struct acpi_driver acpi_pci_link_driver = {
Len Brownc2b67052007-02-12 23:33:40 -050064 .name = "pci_link",
Len Brown4be44fc2005-08-05 00:44:28 -040065 .class = ACPI_PCI_LINK_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020066 .ids = link_device_ids,
Len Brown4be44fc2005-08-05 00:44:28 -040067 .ops = {
68 .add = acpi_pci_link_add,
69 .remove = acpi_pci_link_remove,
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070070 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070071};
72
David Shaohua Li87bec662005-07-27 23:02:00 -040073/*
74 * If a link is initialized, we never change its active and initialized
75 * later even the link is disable. Instead, we just repick the active irq
76 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077struct acpi_pci_link_irq {
Len Brown4be44fc2005-08-05 00:44:28 -040078 u8 active; /* Current IRQ */
Bob Moore50eca3e2005-09-30 19:03:00 -040079 u8 triggering; /* All IRQs */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070080 u8 polarity; /* All IRQs */
Len Brown4be44fc2005-08-05 00:44:28 -040081 u8 resource_type;
82 u8 possible_count;
83 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
84 u8 initialized:1;
85 u8 reserved:7;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086};
87
88struct acpi_pci_link {
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070089 struct list_head node;
90 struct acpi_device *device;
91 struct acpi_pci_link_irq irq;
92 int refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093};
94
95static struct {
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070096 int count;
97 struct list_head entries;
Len Brown4be44fc2005-08-05 00:44:28 -040098} acpi_link;
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 list_head *node;
483 struct acpi_pci_link *link;
484 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 /*
487 * Update penalties to facilitate IRQ balancing.
488 */
489 list_for_each(node, &acpi_link.entries) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 link = list_entry(node, struct acpi_pci_link, node);
491 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400492 printk(KERN_ERR PREFIX "Invalid link context\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 continue;
494 }
495
496 /*
497 * reflect the possible and active irqs in the penalty table --
498 * useful for breaking ties.
499 */
500 if (link->irq.possible_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400501 int penalty =
502 PIRQ_PENALTY_PCI_POSSIBLE /
503 link->irq.possible_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 for (i = 0; i < link->irq.possible_count; i++) {
506 if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ)
Len Brown4be44fc2005-08-05 00:44:28 -0400507 acpi_irq_penalty[link->irq.
508 possible[i]] +=
509 penalty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
511
512 } else if (link->irq.active) {
Len Brown4be44fc2005-08-05 00:44:28 -0400513 acpi_irq_penalty[link->irq.active] +=
514 PIRQ_PENALTY_PCI_POSSIBLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
516 }
517 /* Add a penalty for the SCI */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300518 acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING;
Patrick Mocheld550d982006-06-27 00:41:40 -0400519 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
521
Bjorn Helgaas32836252008-11-05 16:17:52 -0700522static int acpi_irq_balance = -1; /* 0: static, 1: balance */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Len Brown4be44fc2005-08-05 00:44:28 -0400524static int acpi_pci_link_allocate(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Len Brown4be44fc2005-08-05 00:44:28 -0400526 int irq;
527 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
David Shaohua Li87bec662005-07-27 23:02:00 -0400529 if (link->irq.initialized) {
530 if (link->refcnt == 0)
531 /* This means the link is disabled but initialized */
532 acpi_pci_link_set(link, link->irq.active);
Patrick Mocheld550d982006-06-27 00:41:40 -0400533 return 0;
David Shaohua Li87bec662005-07-27 23:02:00 -0400534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 /*
537 * search for active IRQ in list of possible IRQs.
538 */
539 for (i = 0; i < link->irq.possible_count; ++i) {
540 if (link->irq.active == link->irq.possible[i])
541 break;
542 }
543 /*
544 * forget active IRQ that is not in possible list
545 */
546 if (i == link->irq.possible_count) {
547 if (acpi_strict)
Len Browncece9292006-06-26 23:04:31 -0400548 printk(KERN_WARNING PREFIX "_CRS %d not found"
549 " in _PRS\n", link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 link->irq.active = 0;
551 }
552
553 /*
554 * if active found, use it; else pick entry from end of possible list.
555 */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700556 if (link->irq.active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 irq = link->irq.active;
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700558 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 irq = link->irq.possible[link->irq.possible_count - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
561 if (acpi_irq_balance || !link->irq.active) {
562 /*
563 * Select the best IRQ. This is done in reverse to promote
564 * the use of IRQs 9, 10, 11, and >15.
565 */
566 for (i = (link->irq.possible_count - 1); i >= 0; i--) {
Len Brown4be44fc2005-08-05 00:44:28 -0400567 if (acpi_irq_penalty[irq] >
568 acpi_irq_penalty[link->irq.possible[i]])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 irq = link->irq.possible[i];
570 }
571 }
572
573 /* Attempt to enable the link device at this IRQ. */
574 if (acpi_pci_link_set(link, irq)) {
Len Brown64684632006-06-26 23:41:38 -0400575 printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. "
576 "Try pci=noacpi or acpi=off\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400577 acpi_device_name(link->device),
Len Brown64684632006-06-26 23:41:38 -0400578 acpi_device_bid(link->device));
Patrick Mocheld550d982006-06-27 00:41:40 -0400579 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 } else {
581 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
Frank Seidel4d939152009-02-04 17:03:07 +0100582 printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400583 acpi_device_name(link->device),
584 acpi_device_bid(link->device), link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
587 link->irq.initialized = 1;
Patrick Mocheld550d982006-06-27 00:41:40 -0400588 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
590
591/*
David Shaohua Li87bec662005-07-27 23:02:00 -0400592 * acpi_pci_link_allocate_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 * success: return IRQ >= 0
594 * failure: return -1
595 */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700596int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering,
597 int *polarity, char **name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700599 int result;
600 struct acpi_device *device;
601 struct acpi_pci_link *link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 result = acpi_bus_get_device(handle, &device);
604 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400605 printk(KERN_ERR PREFIX "Invalid link device\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400606 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
608
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200609 link = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400611 printk(KERN_ERR PREFIX "Invalid link context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400612 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614
615 /* TBD: Support multiple index (IRQ) entries per Link Device */
616 if (index) {
Len Brown64684632006-06-26 23:41:38 -0400617 printk(KERN_ERR PREFIX "Invalid index %d\n", index);
Patrick Mocheld550d982006-06-27 00:41:40 -0400618 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
620
Ingo Molnar36e43092006-04-27 05:25:00 -0400621 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400622 if (acpi_pci_link_allocate(link)) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400623 mutex_unlock(&acpi_link_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400624 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400625 }
Len Brown4be44fc2005-08-05 00:44:28 -0400626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 if (!link->irq.active) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400628 mutex_unlock(&acpi_link_lock);
Len Brown64684632006-06-26 23:41:38 -0400629 printk(KERN_ERR PREFIX "Link active IRQ is 0!\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400630 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
Len Brown4be44fc2005-08-05 00:44:28 -0400632 link->refcnt++;
Ingo Molnar36e43092006-04-27 05:25:00 -0400633 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Bob Moore50eca3e2005-09-30 19:03:00 -0400635 if (triggering)
636 *triggering = link->irq.triggering;
637 if (polarity)
638 *polarity = link->irq.polarity;
Len Brown4be44fc2005-08-05 00:44:28 -0400639 if (name)
640 *name = acpi_device_bid(link->device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400641 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400642 "Link %s is referenced\n",
643 acpi_device_bid(link->device)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400644 return (link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645}
646
David Shaohua Li87bec662005-07-27 23:02:00 -0400647/*
648 * We don't change link's irq information here. After it is reenabled, we
649 * continue use the info
650 */
Len Brown4be44fc2005-08-05 00:44:28 -0400651int acpi_pci_link_free_irq(acpi_handle handle)
David Shaohua Li87bec662005-07-27 23:02:00 -0400652{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700653 struct acpi_device *device;
654 struct acpi_pci_link *link;
Len Brown4be44fc2005-08-05 00:44:28 -0400655 acpi_status result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
David Shaohua Li87bec662005-07-27 23:02:00 -0400657 result = acpi_bus_get_device(handle, &device);
658 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400659 printk(KERN_ERR PREFIX "Invalid link device\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400660 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400661 }
662
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200663 link = acpi_driver_data(device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400664 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400665 printk(KERN_ERR PREFIX "Invalid link context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400666 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400667 }
668
Ingo Molnar36e43092006-04-27 05:25:00 -0400669 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400670 if (!link->irq.initialized) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400671 mutex_unlock(&acpi_link_lock);
Len Brown64684632006-06-26 23:41:38 -0400672 printk(KERN_ERR PREFIX "Link isn't initialized\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400673 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400674 }
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400675#ifdef FUTURE_USE
676 /*
677 * The Link reference count allows us to _DISable an unused link
678 * and suspend time, and set it again on resume.
679 * However, 2.6.12 still has irq_router.resume
680 * which blindly restores the link state.
681 * So we disable the reference count method
682 * to prevent duplicate acpi_pci_link_set()
683 * which would harm some systems
684 */
Len Brown4be44fc2005-08-05 00:44:28 -0400685 link->refcnt--;
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400686#endif
David Shaohua Li87bec662005-07-27 23:02:00 -0400687 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400688 "Link %s is dereferenced\n",
689 acpi_device_bid(link->device)));
David Shaohua Li87bec662005-07-27 23:02:00 -0400690
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700691 if (link->refcnt == 0)
donald.d.dugger@intel.com383d7a12008-10-17 07:49:50 -0700692 acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL);
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700693
Ingo Molnar36e43092006-04-27 05:25:00 -0400694 mutex_unlock(&acpi_link_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400695 return (link->irq.active);
David Shaohua Li87bec662005-07-27 23:02:00 -0400696}
Len Brown4be44fc2005-08-05 00:44:28 -0400697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698/* --------------------------------------------------------------------------
699 Driver Interface
700 -------------------------------------------------------------------------- */
701
Len Brown4be44fc2005-08-05 00:44:28 -0400702static int acpi_pci_link_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700704 int result;
705 struct acpi_pci_link *link;
706 int i;
Len Brown4be44fc2005-08-05 00:44:28 -0400707 int found = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Burman Yan36bcbec2006-12-19 12:56:11 -0800709 link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 if (!link)
Patrick Mocheld550d982006-06-27 00:41:40 -0400711 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713 link->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
715 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700716 device->driver_data = link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Ingo Molnar36e43092006-04-27 05:25:00 -0400718 mutex_lock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 result = acpi_pci_link_get_possible(link);
720 if (result)
721 goto end;
722
723 /* query and set link->irq.active */
724 acpi_pci_link_get_current(link);
725
Dan Aloni0dc070b2007-07-09 11:33:18 -0700726 printk(KERN_INFO PREFIX "%s [%s] (IRQs", acpi_device_name(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400727 acpi_device_bid(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 for (i = 0; i < link->irq.possible_count; i++) {
729 if (link->irq.active == link->irq.possible[i]) {
730 printk(" *%d", link->irq.possible[i]);
731 found = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400732 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 printk(" %d", link->irq.possible[i]);
734 }
735
736 printk(")");
737
738 if (!found)
739 printk(" *%d", link->irq.active);
740
Len Brown4be44fc2005-08-05 00:44:28 -0400741 if (!link->device->status.enabled)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 printk(", disabled.");
743
744 printk("\n");
745
746 /* TBD: Acquire/release lock */
747 list_add_tail(&link->node, &acpi_link.entries);
748 acpi_link.count++;
749
Len Brown4be44fc2005-08-05 00:44:28 -0400750 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 /* disable all links -- to be activated on use */
donald.d.dugger@intel.com383d7a12008-10-17 07:49:50 -0700752 acpi_evaluate_object(device->handle, "_DIS", NULL, NULL);
Ingo Molnar36e43092006-04-27 05:25:00 -0400753 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755 if (result)
756 kfree(link);
757
Patrick Mocheld550d982006-06-27 00:41:40 -0400758 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759}
760
Len Brown4be44fc2005-08-05 00:44:28 -0400761static int acpi_pci_link_resume(struct acpi_pci_link *link)
Linus Torvalds697a2d62005-08-01 12:37:54 -0700762{
Linus Torvalds697a2d62005-08-01 12:37:54 -0700763 if (link->refcnt && link->irq.active && link->irq.initialized)
Patrick Mocheld550d982006-06-27 00:41:40 -0400764 return (acpi_pci_link_set(link, link->irq.active));
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700765
766 return 0;
Linus Torvalds697a2d62005-08-01 12:37:54 -0700767}
768
Len Brown4be44fc2005-08-05 00:44:28 -0400769static int irqrouter_resume(struct sys_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700771 struct list_head *node;
772 struct acpi_pci_link *link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 list_for_each(node, &acpi_link.entries) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 link = list_entry(node, struct acpi_pci_link, node);
776 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400777 printk(KERN_ERR PREFIX "Invalid link context\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 continue;
779 }
Linus Torvalds697a2d62005-08-01 12:37:54 -0700780 acpi_pci_link_resume(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400782 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783}
784
Len Brown4be44fc2005-08-05 00:44:28 -0400785static int acpi_pci_link_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700787 struct acpi_pci_link *link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200789 link = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Ingo Molnar36e43092006-04-27 05:25:00 -0400791 mutex_lock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 list_del(&link->node);
Ingo Molnar36e43092006-04-27 05:25:00 -0400793 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795 kfree(link);
Patrick Mocheld550d982006-06-27 00:41:40 -0400796 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797}
798
799/*
800 * modify acpi_irq_penalty[] from cmdline
801 */
802static int __init acpi_irq_penalty_update(char *str, int used)
803{
804 int i;
805
806 for (i = 0; i < 16; i++) {
807 int retval;
808 int irq;
809
Len Brown4be44fc2005-08-05 00:44:28 -0400810 retval = get_option(&str, &irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 if (!retval)
813 break; /* no number found */
814
815 if (irq < 0)
816 continue;
Len Brown4be44fc2005-08-05 00:44:28 -0400817
Bjorn Helgaasfa46d352008-08-01 15:58:17 -0600818 if (irq >= ARRAY_SIZE(acpi_irq_penalty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 continue;
820
821 if (used)
822 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
823 else
824 acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE;
825
826 if (retval != 2) /* no next number */
827 break;
828 }
829 return 1;
830}
831
832/*
833 * We'd like PNP to call this routine for the
834 * single ISA_USED value for each legacy device.
835 * But instead it calls us with each POSSIBLE setting.
836 * There is no ISA_POSSIBLE weight, so we simply use
837 * the (small) PCI_USING penalty.
838 */
David Shaohua Lic9c3e452005-04-01 00:07:31 -0500839void acpi_penalize_isa_irq(int irq, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
Bjorn Helgaasfa46d352008-08-01 15:58:17 -0600841 if (irq >= 0 && irq < ARRAY_SIZE(acpi_irq_penalty)) {
842 if (active)
843 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
844 else
845 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING;
846 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847}
848
849/*
850 * Over-ride default table to reserve additional IRQs for use by ISA
851 * e.g. acpi_irq_isa=5
852 * Useful for telling ACPI how not to interfere with your ISA sound card.
853 */
854static int __init acpi_irq_isa(char *str)
855{
856 return acpi_irq_penalty_update(str, 1);
857}
Len Brown4be44fc2005-08-05 00:44:28 -0400858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859__setup("acpi_irq_isa=", acpi_irq_isa);
860
861/*
862 * Over-ride default table to free additional IRQs for use by PCI
863 * e.g. acpi_irq_pci=7,15
864 * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing.
865 */
866static int __init acpi_irq_pci(char *str)
867{
868 return acpi_irq_penalty_update(str, 0);
869}
Len Brown4be44fc2005-08-05 00:44:28 -0400870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871__setup("acpi_irq_pci=", acpi_irq_pci);
872
873static int __init acpi_irq_nobalance_set(char *str)
874{
875 acpi_irq_balance = 0;
876 return 1;
877}
Len Brown4be44fc2005-08-05 00:44:28 -0400878
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879__setup("acpi_irq_nobalance", acpi_irq_nobalance_set);
880
Roel Kluin8a383ef2008-12-09 20:45:30 +0100881static int __init acpi_irq_balance_set(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882{
883 acpi_irq_balance = 1;
884 return 1;
885}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Len Brown4be44fc2005-08-05 00:44:28 -0400887__setup("acpi_irq_balance", acpi_irq_balance_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
David Shaohua Li87bec662005-07-27 23:02:00 -0400889/* FIXME: we will remove this interface after all drivers call pci_disable_device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890static struct sysdev_class irqrouter_sysdev_class = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +0100891 .name = "irqrouter",
Len Brown4be44fc2005-08-05 00:44:28 -0400892 .resume = irqrouter_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893};
894
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895static struct sys_device device_irqrouter = {
Len Brown4be44fc2005-08-05 00:44:28 -0400896 .id = 0,
897 .cls = &irqrouter_sysdev_class,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898};
899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900static int __init irqrouter_init_sysfs(void)
901{
902 int error;
903
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 if (acpi_disabled || acpi_noirq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400905 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
907 error = sysdev_class_register(&irqrouter_sysdev_class);
908 if (!error)
909 error = sysdev_register(&device_irqrouter);
910
Patrick Mocheld550d982006-06-27 00:41:40 -0400911 return error;
Len Brown4be44fc2005-08-05 00:44:28 -0400912}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
914device_initcall(irqrouter_init_sysfs);
915
Len Brown4be44fc2005-08-05 00:44:28 -0400916static int __init acpi_pci_link_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 if (acpi_noirq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400919 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
Bjorn Helgaas32836252008-11-05 16:17:52 -0700921 if (acpi_irq_balance == -1) {
922 /* no command line switch: enable balancing in IOAPIC mode */
923 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
924 acpi_irq_balance = 1;
925 else
926 acpi_irq_balance = 0;
927 }
928
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 acpi_link.count = 0;
930 INIT_LIST_HEAD(&acpi_link.entries);
931
932 if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0)
Patrick Mocheld550d982006-06-27 00:41:40 -0400933 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Patrick Mocheld550d982006-06-27 00:41:40 -0400935 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
938subsys_initcall(acpi_pci_link_init);