blob: cfd7581cc19fa24c37d1a3fb7cb370e33a63c760 [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
Rafael J. Wysockic3146df2011-03-12 22:16:51 +010032#include <linux/syscore_ops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/spinlock.h>
38#include <linux/pm.h>
39#include <linux/pci.h>
Ingo Molnar36e43092006-04-27 05:25:00 -040040#include <linux/mutex.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Lv Zheng8b484632013-12-03 08:49:16 +080042#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Rashikac071b6042013-12-17 14:58:31 +053044#include "internal.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
Rafael J. Wysocki4daeaf62013-01-30 14:27:37 +010054static int acpi_pci_link_add(struct acpi_device *device,
55 const struct acpi_device_id *not_used);
56static void acpi_pci_link_remove(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Márton Némethc97adf92010-01-10 17:15:36 +010058static const struct acpi_device_id link_device_ids[] = {
Thomas Renninger1ba90e32007-07-23 14:44:41 +020059 {"PNP0C0F", 0},
60 {"", 0},
61};
Thomas Renninger1ba90e32007-07-23 14:44:41 +020062
Rafael J. Wysocki4daeaf62013-01-30 14:27:37 +010063static struct acpi_scan_handler pci_link_handler = {
Thomas Renninger1ba90e32007-07-23 14:44:41 +020064 .ids = link_device_ids,
Rafael J. Wysocki4daeaf62013-01-30 14:27:37 +010065 .attach = acpi_pci_link_add,
66 .detach = acpi_pci_link_remove,
Linus Torvalds1da177e2005-04-16 15:20:36 -070067};
68
David Shaohua Li87bec662005-07-27 23:02:00 -040069/*
70 * If a link is initialized, we never change its active and initialized
71 * later even the link is disable. Instead, we just repick the active irq
72 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070073struct acpi_pci_link_irq {
Len Brown4be44fc2005-08-05 00:44:28 -040074 u8 active; /* Current IRQ */
Bob Moore50eca3e2005-09-30 19:03:00 -040075 u8 triggering; /* All IRQs */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070076 u8 polarity; /* All IRQs */
Len Brown4be44fc2005-08-05 00:44:28 -040077 u8 resource_type;
78 u8 possible_count;
79 u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE];
80 u8 initialized:1;
81 u8 reserved:7;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082};
83
84struct acpi_pci_link {
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -070085 struct list_head list;
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -070086 struct acpi_device *device;
87 struct acpi_pci_link_irq irq;
88 int refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089};
90
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -070091static LIST_HEAD(acpi_link_list);
Adrian Bunke5685b92007-10-24 18:24:42 +020092static DEFINE_MUTEX(acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/* --------------------------------------------------------------------------
95 PCI Link Device Management
96 -------------------------------------------------------------------------- */
97
98/*
99 * set context (link) possible list from resource list
100 */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700101static acpi_status acpi_pci_link_check_possible(struct acpi_resource *resource,
102 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200104 struct acpi_pci_link *link = context;
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700105 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Len Browneca008c2005-09-22 00:25:18 -0400107 switch (resource->type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400108 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600109 case ACPI_RESOURCE_TYPE_END_TAG:
Patrick Mocheld550d982006-06-27 00:41:40 -0400110 return AE_OK;
Bob Moore50eca3e2005-09-30 19:03:00 -0400111 case ACPI_RESOURCE_TYPE_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400112 {
113 struct acpi_resource_irq *p = &resource->data.irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400114 if (!p || !p->interrupt_count) {
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600115 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
116 "Blank _PRS IRQ resource\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400117 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
Len Brown4be44fc2005-08-05 00:44:28 -0400119 for (i = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400120 (i < p->interrupt_count
Len Brown4be44fc2005-08-05 00:44:28 -0400121 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
122 if (!p->interrupts[i]) {
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600123 printk(KERN_WARNING PREFIX
124 "Invalid _PRS IRQ %d\n",
125 p->interrupts[i]);
Len Brown4be44fc2005-08-05 00:44:28 -0400126 continue;
127 }
128 link->irq.possible[i] = p->interrupts[i];
129 link->irq.possible_count++;
130 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400131 link->irq.triggering = p->triggering;
132 link->irq.polarity = p->polarity;
133 link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ;
Len Brown4be44fc2005-08-05 00:44:28 -0400134 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400136 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400137 {
Bob Moore50eca3e2005-09-30 19:03:00 -0400138 struct acpi_resource_extended_irq *p =
Len Brown4be44fc2005-08-05 00:44:28 -0400139 &resource->data.extended_irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400140 if (!p || !p->interrupt_count) {
Len Browncece9292006-06-26 23:04:31 -0400141 printk(KERN_WARNING PREFIX
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600142 "Blank _PRS EXT IRQ resource\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400143 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
Len Brown4be44fc2005-08-05 00:44:28 -0400145 for (i = 0;
Bob Moore50eca3e2005-09-30 19:03:00 -0400146 (i < p->interrupt_count
Len Brown4be44fc2005-08-05 00:44:28 -0400147 && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) {
148 if (!p->interrupts[i]) {
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600149 printk(KERN_WARNING PREFIX
150 "Invalid _PRS IRQ %d\n",
151 p->interrupts[i]);
Len Brown4be44fc2005-08-05 00:44:28 -0400152 continue;
153 }
154 link->irq.possible[i] = p->interrupts[i];
155 link->irq.possible_count++;
156 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400157 link->irq.triggering = p->triggering;
158 link->irq.polarity = p->polarity;
159 link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
Len Brown4be44fc2005-08-05 00:44:28 -0400160 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 default:
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600163 printk(KERN_ERR PREFIX "_PRS resource type 0x%x isn't an IRQ\n",
164 resource->type);
Patrick Mocheld550d982006-06-27 00:41:40 -0400165 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 }
167
Patrick Mocheld550d982006-06-27 00:41:40 -0400168 return AE_CTRL_TERMINATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
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
Patrick Mochel67a71362006-05-19 16:54:42 -0400175 status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS,
Len Brown4be44fc2005-08-05 00:44:28 -0400176 acpi_pci_link_check_possible, link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400178 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400179 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 }
181
Len Brown4be44fc2005-08-05 00:44:28 -0400182 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
183 "Found %d possible IRQs\n",
184 link->irq.possible_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Patrick Mocheld550d982006-06-27 00:41:40 -0400186 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187}
188
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700189static acpi_status acpi_pci_link_check_current(struct acpi_resource *resource,
190 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700192 int *irq = context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Len Browneca008c2005-09-22 00:25:18 -0400194 switch (resource->type) {
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600195 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
196 case ACPI_RESOURCE_TYPE_END_TAG:
197 return AE_OK;
Bob Moore50eca3e2005-09-30 19:03:00 -0400198 case ACPI_RESOURCE_TYPE_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400199 {
200 struct acpi_resource_irq *p = &resource->data.irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400201 if (!p || !p->interrupt_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400202 /*
203 * IRQ descriptors may have no IRQ# bits set,
204 * particularly those those w/ _STA disabled
205 */
206 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600207 "Blank _CRS IRQ resource\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400208 return AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400209 }
210 *irq = p->interrupts[0];
211 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400213 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
Len Brown4be44fc2005-08-05 00:44:28 -0400214 {
Bob Moore50eca3e2005-09-30 19:03:00 -0400215 struct acpi_resource_extended_irq *p =
Len Brown4be44fc2005-08-05 00:44:28 -0400216 &resource->data.extended_irq;
Bob Moore50eca3e2005-09-30 19:03:00 -0400217 if (!p || !p->interrupt_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400218 /*
219 * extended IRQ descriptors must
220 * return at least 1 IRQ
221 */
Len Browncece9292006-06-26 23:04:31 -0400222 printk(KERN_WARNING PREFIX
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600223 "Blank _CRS EXT IRQ resource\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400224 return AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400225 }
226 *irq = p->interrupts[0];
227 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
Len Brownd4ec6c72006-01-26 17:23:38 -0500229 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 default:
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600231 printk(KERN_ERR PREFIX "_CRS resource type 0x%x isn't an IRQ\n",
232 resource->type);
Patrick Mocheld550d982006-06-27 00:41:40 -0400233 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
Bjorn Helgaas4a5e3632008-07-15 09:42:57 -0600235
Patrick Mocheld550d982006-06-27 00:41:40 -0400236 return AE_CTRL_TERMINATE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237}
238
239/*
240 * Run _CRS and set link->irq.active
241 *
242 * return value:
243 * 0 - success
244 * !0 - failure
245 */
Len Brown4be44fc2005-08-05 00:44:28 -0400246static int acpi_pci_link_get_current(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Len Brown4be44fc2005-08-05 00:44:28 -0400248 int result = 0;
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700249 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400250 int irq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 link->irq.active = 0;
253
254 /* in practice, status disabled is meaningless, ignore it */
255 if (acpi_strict) {
256 /* Query _STA, set link->device->status */
257 result = acpi_bus_get_status(link->device);
258 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400259 printk(KERN_ERR PREFIX "Unable to read status\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 goto end;
261 }
262
263 if (!link->device->status.enabled) {
264 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400265 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
267 }
268
269 /*
270 * Query and parse _CRS to get the current IRQ assignment.
271 */
272
Patrick Mochel67a71362006-05-19 16:54:42 -0400273 status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS,
Len Brown4be44fc2005-08-05 00:44:28 -0400274 acpi_pci_link_check_current, &irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400276 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 result = -ENODEV;
278 goto end;
279 }
280
281 if (acpi_strict && !irq) {
Len Brown64684632006-06-26 23:41:38 -0400282 printk(KERN_ERR PREFIX "_CRS returned 0\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 result = -ENODEV;
284 }
285
286 link->irq.active = irq;
287
288 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active));
289
Len Brown4be44fc2005-08-05 00:44:28 -0400290 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400291 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700296 int result;
297 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 struct {
Len Brown4be44fc2005-08-05 00:44:28 -0400299 struct acpi_resource res;
300 struct acpi_resource end;
301 } *resource;
302 struct acpi_buffer buffer = { 0, NULL };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Bjorn Helgaas6eca4b42009-02-17 14:00:50 -0700304 if (!irq)
Patrick Mocheld550d982006-06-27 00:41:40 -0400305 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Burman Yan36bcbec2006-12-19 12:56:11 -0800307 resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
Len Brown4be44fc2005-08-05 00:44:28 -0400308 if (!resource)
Patrick Mocheld550d982006-06-27 00:41:40 -0400309 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Len Brown4be44fc2005-08-05 00:44:28 -0400311 buffer.length = sizeof(*resource) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 buffer.pointer = resource;
313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 switch (link->irq.resource_type) {
Bob Moore50eca3e2005-09-30 19:03:00 -0400315 case ACPI_RESOURCE_TYPE_IRQ:
316 resource->res.type = ACPI_RESOURCE_TYPE_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 resource->res.length = sizeof(struct acpi_resource);
Bob Moore50eca3e2005-09-30 19:03:00 -0400318 resource->res.data.irq.triggering = link->irq.triggering;
319 resource->res.data.irq.polarity =
320 link->irq.polarity;
321 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
322 resource->res.data.irq.sharable =
Len Brown4be44fc2005-08-05 00:44:28 -0400323 ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400325 resource->res.data.irq.sharable = ACPI_SHARED;
326 resource->res.data.irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 resource->res.data.irq.interrupts[0] = irq;
328 break;
Len Brown4be44fc2005-08-05 00:44:28 -0400329
Bob Moore50eca3e2005-09-30 19:03:00 -0400330 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
331 resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 resource->res.length = sizeof(struct acpi_resource);
Len Brown4be44fc2005-08-05 00:44:28 -0400333 resource->res.data.extended_irq.producer_consumer =
334 ACPI_CONSUMER;
Bob Moore50eca3e2005-09-30 19:03:00 -0400335 resource->res.data.extended_irq.triggering =
336 link->irq.triggering;
337 resource->res.data.extended_irq.polarity =
338 link->irq.polarity;
339 if (link->irq.triggering == ACPI_EDGE_SENSITIVE)
340 resource->res.data.irq.sharable =
Len Brown4be44fc2005-08-05 00:44:28 -0400341 ACPI_EXCLUSIVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 else
Bob Moore50eca3e2005-09-30 19:03:00 -0400343 resource->res.data.irq.sharable = ACPI_SHARED;
344 resource->res.data.extended_irq.interrupt_count = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 resource->res.data.extended_irq.interrupts[0] = irq;
346 /* ignore resource_source, it's optional */
347 break;
348 default:
Len Brown64684632006-06-26 23:41:38 -0400349 printk(KERN_ERR PREFIX "Invalid Resource_type %d\n", link->irq.resource_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 result = -EINVAL;
351 goto end;
352
353 }
Bob Moore50eca3e2005-09-30 19:03:00 -0400354 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
Yinghai Luf084dbb2013-03-23 19:16:37 +0000355 resource->end.length = sizeof(struct acpi_resource);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 /* Attempt to set the resource */
Patrick Mochel67a71362006-05-19 16:54:42 -0400358 status = acpi_set_current_resources(link->device->handle, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 /* check for total failure */
361 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -0400362 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 result = -ENODEV;
364 goto end;
365 }
366
367 /* Query _STA, set device->status */
368 result = acpi_bus_get_status(link->device);
369 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400370 printk(KERN_ERR PREFIX "Unable to read status\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 goto end;
372 }
373 if (!link->device->status.enabled) {
Len Browncece9292006-06-26 23:04:31 -0400374 printk(KERN_WARNING PREFIX
375 "%s [%s] disabled and referenced, BIOS bug\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400376 acpi_device_name(link->device),
Len Browncece9292006-06-26 23:04:31 -0400377 acpi_device_bid(link->device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 }
379
380 /* Query _CRS, set link->irq.active */
381 result = acpi_pci_link_get_current(link);
382 if (result) {
383 goto end;
384 }
385
386 /*
387 * Is current setting not what we set?
388 * set link->irq.active
389 */
390 if (link->irq.active != irq) {
391 /*
392 * policy: when _CRS doesn't return what we just _SRS
393 * assume _SRS worked and override _CRS value.
394 */
Len Browncece9292006-06-26 23:04:31 -0400395 printk(KERN_WARNING PREFIX
396 "%s [%s] BIOS reported IRQ %d, using IRQ %d\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400397 acpi_device_name(link->device),
Len Browncece9292006-06-26 23:04:31 -0400398 acpi_device_bid(link->device), link->irq.active, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 link->irq.active = irq;
400 }
401
402 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d\n", link->irq.active));
Len Brown4be44fc2005-08-05 00:44:28 -0400403
404 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 kfree(resource);
Patrick Mocheld550d982006-06-27 00:41:40 -0400406 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409/* --------------------------------------------------------------------------
410 PCI Link IRQ Management
411 -------------------------------------------------------------------------- */
412
413/*
414 * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt
415 * Link Devices to move the PIRQs around to minimize sharing.
416 *
417 * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs
418 * that the BIOS has already set to active. This is necessary because
419 * ACPI has no automatic means of knowing what ISA IRQs are used. Note that
420 * if the BIOS doesn't set a Link Device active, ACPI needs to program it
421 * even if acpi_irq_nobalance is set.
422 *
423 * A tables of penalties avoids directing PCI interrupts to well known
424 * ISA IRQs. Boot params are available to over-ride the default table:
425 *
426 * List interrupts that are free for PCI use.
427 * acpi_irq_pci=n[,m]
428 *
429 * List interrupts that should not be used for PCI:
430 * acpi_irq_isa=n[,m]
431 *
432 * Note that PCI IRQ routers have a list of possible IRQs,
433 * which may not include the IRQs this table says are available.
434 *
435 * Since this heuristic can't tell the difference between a link
436 * that no device will attach to, vs. a link which may be shared
437 * by multiple active devices -- it is not optimal.
438 *
439 * If interrupt performance is that important, get an IO-APIC system
440 * with a pin dedicated to each device. Or for that matter, an MSI
441 * enabled system.
442 */
443
444#define ACPI_MAX_IRQS 256
445#define ACPI_MAX_ISA_IRQ 16
446
447#define PIRQ_PENALTY_PCI_AVAILABLE (0)
448#define PIRQ_PENALTY_PCI_POSSIBLE (16*16)
449#define PIRQ_PENALTY_PCI_USING (16*16*16)
450#define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16)
451#define PIRQ_PENALTY_ISA_USED (16*16*16*16*16)
452#define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16)
453
454static int acpi_irq_penalty[ACPI_MAX_IRQS] = {
455 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ0 timer */
456 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ1 keyboard */
457 PIRQ_PENALTY_ISA_ALWAYS, /* IRQ2 cascade */
Len Brown4be44fc2005-08-05 00:44:28 -0400458 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ3 serial */
459 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ4 serial */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ5 sometimes SoundBlaster */
461 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ6 */
462 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ7 parallel, spurious */
463 PIRQ_PENALTY_ISA_TYPICAL, /* IRQ8 rtc, sometimes */
464 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */
465 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */
466 PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700467 PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */
468 PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */
469 PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */
470 PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */
Len Brown4be44fc2005-08-05 00:44:28 -0400471 /* >IRQ15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472};
473
Len Brown4be44fc2005-08-05 00:44:28 -0400474int __init acpi_irq_penalty_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700476 struct acpi_pci_link *link;
477 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 /*
480 * Update penalties to facilitate IRQ balancing.
481 */
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -0700482 list_for_each_entry(link, &acpi_link_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 /*
485 * reflect the possible and active irqs in the penalty table --
486 * useful for breaking ties.
487 */
488 if (link->irq.possible_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400489 int penalty =
490 PIRQ_PENALTY_PCI_POSSIBLE /
491 link->irq.possible_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 for (i = 0; i < link->irq.possible_count; i++) {
494 if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ)
Len Brown4be44fc2005-08-05 00:44:28 -0400495 acpi_irq_penalty[link->irq.
496 possible[i]] +=
497 penalty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499
500 } else if (link->irq.active) {
Len Brown4be44fc2005-08-05 00:44:28 -0400501 acpi_irq_penalty[link->irq.active] +=
502 PIRQ_PENALTY_PCI_POSSIBLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
504 }
505 /* Add a penalty for the SCI */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300506 acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING;
Patrick Mocheld550d982006-06-27 00:41:40 -0400507 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508}
509
Bjorn Helgaas32836252008-11-05 16:17:52 -0700510static int acpi_irq_balance = -1; /* 0: static, 1: balance */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Len Brown4be44fc2005-08-05 00:44:28 -0400512static int acpi_pci_link_allocate(struct acpi_pci_link *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
Len Brown4be44fc2005-08-05 00:44:28 -0400514 int irq;
515 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
David Shaohua Li87bec662005-07-27 23:02:00 -0400517 if (link->irq.initialized) {
518 if (link->refcnt == 0)
519 /* This means the link is disabled but initialized */
520 acpi_pci_link_set(link, link->irq.active);
Patrick Mocheld550d982006-06-27 00:41:40 -0400521 return 0;
David Shaohua Li87bec662005-07-27 23:02:00 -0400522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 /*
525 * search for active IRQ in list of possible IRQs.
526 */
527 for (i = 0; i < link->irq.possible_count; ++i) {
528 if (link->irq.active == link->irq.possible[i])
529 break;
530 }
531 /*
532 * forget active IRQ that is not in possible list
533 */
534 if (i == link->irq.possible_count) {
535 if (acpi_strict)
Len Browncece9292006-06-26 23:04:31 -0400536 printk(KERN_WARNING PREFIX "_CRS %d not found"
537 " in _PRS\n", link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 link->irq.active = 0;
539 }
540
541 /*
542 * if active found, use it; else pick entry from end of possible list.
543 */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700544 if (link->irq.active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 irq = link->irq.active;
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700546 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 irq = link->irq.possible[link->irq.possible_count - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 if (acpi_irq_balance || !link->irq.active) {
550 /*
551 * Select the best IRQ. This is done in reverse to promote
552 * the use of IRQs 9, 10, 11, and >15.
553 */
554 for (i = (link->irq.possible_count - 1); i >= 0; i--) {
Len Brown4be44fc2005-08-05 00:44:28 -0400555 if (acpi_irq_penalty[irq] >
556 acpi_irq_penalty[link->irq.possible[i]])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 irq = link->irq.possible[i];
558 }
559 }
560
561 /* Attempt to enable the link device at this IRQ. */
562 if (acpi_pci_link_set(link, irq)) {
Len Brown64684632006-06-26 23:41:38 -0400563 printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. "
564 "Try pci=noacpi or acpi=off\n",
Thomas Renningera6fc6722006-06-26 23:58:43 -0400565 acpi_device_name(link->device),
Len Brown64684632006-06-26 23:41:38 -0400566 acpi_device_bid(link->device));
Patrick Mocheld550d982006-06-27 00:41:40 -0400567 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 } else {
569 acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING;
Frank Seidel4d939152009-02-04 17:03:07 +0100570 printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400571 acpi_device_name(link->device),
572 acpi_device_bid(link->device), link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 }
574
575 link->irq.initialized = 1;
Patrick Mocheld550d982006-06-27 00:41:40 -0400576 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
579/*
David Shaohua Li87bec662005-07-27 23:02:00 -0400580 * acpi_pci_link_allocate_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 * success: return IRQ >= 0
582 * failure: return -1
583 */
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700584int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering,
585 int *polarity, char **name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700587 int result;
588 struct acpi_device *device;
589 struct acpi_pci_link *link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 result = acpi_bus_get_device(handle, &device);
592 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400593 printk(KERN_ERR PREFIX "Invalid link device\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400594 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
596
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200597 link = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400599 printk(KERN_ERR PREFIX "Invalid link context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400600 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
602
603 /* TBD: Support multiple index (IRQ) entries per Link Device */
604 if (index) {
Len Brown64684632006-06-26 23:41:38 -0400605 printk(KERN_ERR PREFIX "Invalid index %d\n", index);
Patrick Mocheld550d982006-06-27 00:41:40 -0400606 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
608
Ingo Molnar36e43092006-04-27 05:25:00 -0400609 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400610 if (acpi_pci_link_allocate(link)) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400611 mutex_unlock(&acpi_link_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400612 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400613 }
Len Brown4be44fc2005-08-05 00:44:28 -0400614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 if (!link->irq.active) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400616 mutex_unlock(&acpi_link_lock);
Len Brown64684632006-06-26 23:41:38 -0400617 printk(KERN_ERR PREFIX "Link active IRQ is 0!\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400618 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
Len Brown4be44fc2005-08-05 00:44:28 -0400620 link->refcnt++;
Ingo Molnar36e43092006-04-27 05:25:00 -0400621 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Bob Moore50eca3e2005-09-30 19:03:00 -0400623 if (triggering)
624 *triggering = link->irq.triggering;
625 if (polarity)
626 *polarity = link->irq.polarity;
Len Brown4be44fc2005-08-05 00:44:28 -0400627 if (name)
628 *name = acpi_device_bid(link->device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400629 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400630 "Link %s is referenced\n",
631 acpi_device_bid(link->device)));
Patrick Mocheld550d982006-06-27 00:41:40 -0400632 return (link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633}
634
David Shaohua Li87bec662005-07-27 23:02:00 -0400635/*
636 * We don't change link's irq information here. After it is reenabled, we
637 * continue use the info
638 */
Len Brown4be44fc2005-08-05 00:44:28 -0400639int acpi_pci_link_free_irq(acpi_handle handle)
David Shaohua Li87bec662005-07-27 23:02:00 -0400640{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700641 struct acpi_device *device;
642 struct acpi_pci_link *link;
Len Brown4be44fc2005-08-05 00:44:28 -0400643 acpi_status result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
David Shaohua Li87bec662005-07-27 23:02:00 -0400645 result = acpi_bus_get_device(handle, &device);
646 if (result) {
Len Brown64684632006-06-26 23:41:38 -0400647 printk(KERN_ERR PREFIX "Invalid link device\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400648 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400649 }
650
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200651 link = acpi_driver_data(device);
David Shaohua Li87bec662005-07-27 23:02:00 -0400652 if (!link) {
Len Brown64684632006-06-26 23:41:38 -0400653 printk(KERN_ERR PREFIX "Invalid link context\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400654 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400655 }
656
Ingo Molnar36e43092006-04-27 05:25:00 -0400657 mutex_lock(&acpi_link_lock);
David Shaohua Li87bec662005-07-27 23:02:00 -0400658 if (!link->irq.initialized) {
Ingo Molnar36e43092006-04-27 05:25:00 -0400659 mutex_unlock(&acpi_link_lock);
Len Brown64684632006-06-26 23:41:38 -0400660 printk(KERN_ERR PREFIX "Link isn't initialized\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400661 return -1;
David Shaohua Li87bec662005-07-27 23:02:00 -0400662 }
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400663#ifdef FUTURE_USE
664 /*
665 * The Link reference count allows us to _DISable an unused link
666 * and suspend time, and set it again on resume.
667 * However, 2.6.12 still has irq_router.resume
668 * which blindly restores the link state.
669 * So we disable the reference count method
670 * to prevent duplicate acpi_pci_link_set()
671 * which would harm some systems
672 */
Len Brown4be44fc2005-08-05 00:44:28 -0400673 link->refcnt--;
David Shaohua Liecc21eb2005-08-03 11:00:11 -0400674#endif
David Shaohua Li87bec662005-07-27 23:02:00 -0400675 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400676 "Link %s is dereferenced\n",
677 acpi_device_bid(link->device)));
David Shaohua Li87bec662005-07-27 23:02:00 -0400678
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700679 if (link->refcnt == 0)
donald.d.dugger@intel.com383d7a12008-10-17 07:49:50 -0700680 acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL);
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700681
Ingo Molnar36e43092006-04-27 05:25:00 -0400682 mutex_unlock(&acpi_link_lock);
Patrick Mocheld550d982006-06-27 00:41:40 -0400683 return (link->irq.active);
David Shaohua Li87bec662005-07-27 23:02:00 -0400684}
Len Brown4be44fc2005-08-05 00:44:28 -0400685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686/* --------------------------------------------------------------------------
687 Driver Interface
688 -------------------------------------------------------------------------- */
689
Rafael J. Wysocki4daeaf62013-01-30 14:27:37 +0100690static int acpi_pci_link_add(struct acpi_device *device,
691 const struct acpi_device_id *not_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700693 int result;
694 struct acpi_pci_link *link;
695 int i;
Len Brown4be44fc2005-08-05 00:44:28 -0400696 int found = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Burman Yan36bcbec2006-12-19 12:56:11 -0800698 link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 if (!link)
Patrick Mocheld550d982006-06-27 00:41:40 -0400700 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
702 link->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
704 strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -0700705 device->driver_data = link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Ingo Molnar36e43092006-04-27 05:25:00 -0400707 mutex_lock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 result = acpi_pci_link_get_possible(link);
709 if (result)
710 goto end;
711
712 /* query and set link->irq.active */
713 acpi_pci_link_get_current(link);
714
Dan Aloni0dc070b2007-07-09 11:33:18 -0700715 printk(KERN_INFO PREFIX "%s [%s] (IRQs", acpi_device_name(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400716 acpi_device_bid(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 for (i = 0; i < link->irq.possible_count; i++) {
718 if (link->irq.active == link->irq.possible[i]) {
Kay Sieversbe964472012-05-08 17:24:20 +0200719 printk(KERN_CONT " *%d", link->irq.possible[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 found = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400721 } else
Kay Sieversbe964472012-05-08 17:24:20 +0200722 printk(KERN_CONT " %d", link->irq.possible[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
724
Kay Sieversbe964472012-05-08 17:24:20 +0200725 printk(KERN_CONT ")");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
727 if (!found)
Kay Sieversbe964472012-05-08 17:24:20 +0200728 printk(KERN_CONT " *%d", link->irq.active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Len Brown4be44fc2005-08-05 00:44:28 -0400730 if (!link->device->status.enabled)
Kay Sieversbe964472012-05-08 17:24:20 +0200731 printk(KERN_CONT ", disabled.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Kay Sieversbe964472012-05-08 17:24:20 +0200733 printk(KERN_CONT "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -0700735 list_add_tail(&link->list, &acpi_link_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Len Brown4be44fc2005-08-05 00:44:28 -0400737 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 /* disable all links -- to be activated on use */
donald.d.dugger@intel.com383d7a12008-10-17 07:49:50 -0700739 acpi_evaluate_object(device->handle, "_DIS", NULL, NULL);
Ingo Molnar36e43092006-04-27 05:25:00 -0400740 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 if (result)
743 kfree(link);
744
Rafael J. Wysocki4daeaf62013-01-30 14:27:37 +0100745 return result < 0 ? result : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746}
747
Len Brown4be44fc2005-08-05 00:44:28 -0400748static int acpi_pci_link_resume(struct acpi_pci_link *link)
Linus Torvalds697a2d62005-08-01 12:37:54 -0700749{
Linus Torvalds697a2d62005-08-01 12:37:54 -0700750 if (link->refcnt && link->irq.active && link->irq.initialized)
Patrick Mocheld550d982006-06-27 00:41:40 -0400751 return (acpi_pci_link_set(link, link->irq.active));
Bjorn Helgaas1c9ca3a2009-02-17 14:00:40 -0700752
753 return 0;
Linus Torvalds697a2d62005-08-01 12:37:54 -0700754}
755
Rafael J. Wysockic3146df2011-03-12 22:16:51 +0100756static void irqrouter_resume(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700758 struct acpi_pci_link *link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -0700760 list_for_each_entry(link, &acpi_link_list, list) {
Linus Torvalds697a2d62005-08-01 12:37:54 -0700761 acpi_pci_link_resume(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763}
764
Rafael J. Wysocki4daeaf62013-01-30 14:27:37 +0100765static void acpi_pci_link_remove(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
Bjorn Helgaasc9d62442009-02-17 14:00:45 -0700767 struct acpi_pci_link *link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200769 link = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Ingo Molnar36e43092006-04-27 05:25:00 -0400771 mutex_lock(&acpi_link_lock);
Bjorn Helgaas5f0dcca2009-02-17 14:00:55 -0700772 list_del(&link->list);
Ingo Molnar36e43092006-04-27 05:25:00 -0400773 mutex_unlock(&acpi_link_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775 kfree(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776}
777
778/*
779 * modify acpi_irq_penalty[] from cmdline
780 */
781static int __init acpi_irq_penalty_update(char *str, int used)
782{
783 int i;
784
785 for (i = 0; i < 16; i++) {
786 int retval;
787 int irq;
788
Len Brown4be44fc2005-08-05 00:44:28 -0400789 retval = get_option(&str, &irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 if (!retval)
792 break; /* no number found */
793
794 if (irq < 0)
795 continue;
Len Brown4be44fc2005-08-05 00:44:28 -0400796
Bjorn Helgaasfa46d352008-08-01 15:58:17 -0600797 if (irq >= ARRAY_SIZE(acpi_irq_penalty))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 continue;
799
800 if (used)
801 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
802 else
803 acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE;
804
805 if (retval != 2) /* no next number */
806 break;
807 }
808 return 1;
809}
810
811/*
812 * We'd like PNP to call this routine for the
813 * single ISA_USED value for each legacy device.
814 * But instead it calls us with each POSSIBLE setting.
815 * There is no ISA_POSSIBLE weight, so we simply use
816 * the (small) PCI_USING penalty.
817 */
David Shaohua Lic9c3e452005-04-01 00:07:31 -0500818void acpi_penalize_isa_irq(int irq, int active)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819{
Bjorn Helgaasfa46d352008-08-01 15:58:17 -0600820 if (irq >= 0 && irq < ARRAY_SIZE(acpi_irq_penalty)) {
821 if (active)
822 acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED;
823 else
824 acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING;
825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826}
827
828/*
829 * Over-ride default table to reserve additional IRQs for use by ISA
830 * e.g. acpi_irq_isa=5
831 * Useful for telling ACPI how not to interfere with your ISA sound card.
832 */
833static int __init acpi_irq_isa(char *str)
834{
835 return acpi_irq_penalty_update(str, 1);
836}
Len Brown4be44fc2005-08-05 00:44:28 -0400837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838__setup("acpi_irq_isa=", acpi_irq_isa);
839
840/*
841 * Over-ride default table to free additional IRQs for use by PCI
842 * e.g. acpi_irq_pci=7,15
843 * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing.
844 */
845static int __init acpi_irq_pci(char *str)
846{
847 return acpi_irq_penalty_update(str, 0);
848}
Len Brown4be44fc2005-08-05 00:44:28 -0400849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850__setup("acpi_irq_pci=", acpi_irq_pci);
851
852static int __init acpi_irq_nobalance_set(char *str)
853{
854 acpi_irq_balance = 0;
855 return 1;
856}
Len Brown4be44fc2005-08-05 00:44:28 -0400857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858__setup("acpi_irq_nobalance", acpi_irq_nobalance_set);
859
Roel Kluin8a383ef2008-12-09 20:45:30 +0100860static int __init acpi_irq_balance_set(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
862 acpi_irq_balance = 1;
863 return 1;
864}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Len Brown4be44fc2005-08-05 00:44:28 -0400866__setup("acpi_irq_balance", acpi_irq_balance_set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Rafael J. Wysockic3146df2011-03-12 22:16:51 +0100868static struct syscore_ops irqrouter_syscore_ops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400869 .resume = irqrouter_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870};
871
Rafael J. Wysocki4daeaf62013-01-30 14:27:37 +0100872void __init acpi_pci_link_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 if (acpi_noirq)
Rafael J. Wysocki4daeaf62013-01-30 14:27:37 +0100875 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
Bjorn Helgaas32836252008-11-05 16:17:52 -0700877 if (acpi_irq_balance == -1) {
878 /* no command line switch: enable balancing in IOAPIC mode */
879 if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
880 acpi_irq_balance = 1;
881 else
882 acpi_irq_balance = 0;
883 }
Rafael J. Wysocki4daeaf62013-01-30 14:27:37 +0100884 register_syscore_ops(&irqrouter_syscore_ops);
885 acpi_scan_add_handler(&pci_link_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886}