Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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. Wysocki | c3146df | 2011-03-12 22:16:51 +0100 | [diff] [blame] | 32 | #include <linux/syscore_ops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/kernel.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/spinlock.h> |
| 38 | #include <linux/pm.h> |
| 39 | #include <linux/pci.h> |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 40 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 42 | #include <linux/acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Rashika | c071b604 | 2013-12-17 14:58:31 +0530 | [diff] [blame] | 44 | #include "internal.h" |
| 45 | |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 46 | #define _COMPONENT ACPI_PCI_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 47 | ACPI_MODULE_NAME("pci_link"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define ACPI_PCI_LINK_CLASS "pci_irq_routing" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #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 Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 52 | #define ACPI_PCI_LINK_MAX_POSSIBLE 16 |
| 53 | |
Rafael J. Wysocki | 4daeaf6 | 2013-01-30 14:27:37 +0100 | [diff] [blame] | 54 | static int acpi_pci_link_add(struct acpi_device *device, |
| 55 | const struct acpi_device_id *not_used); |
| 56 | static void acpi_pci_link_remove(struct acpi_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Márton Németh | c97adf9 | 2010-01-10 17:15:36 +0100 | [diff] [blame] | 58 | static const struct acpi_device_id link_device_ids[] = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 59 | {"PNP0C0F", 0}, |
| 60 | {"", 0}, |
| 61 | }; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 62 | |
Rafael J. Wysocki | 4daeaf6 | 2013-01-30 14:27:37 +0100 | [diff] [blame] | 63 | static struct acpi_scan_handler pci_link_handler = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 64 | .ids = link_device_ids, |
Rafael J. Wysocki | 4daeaf6 | 2013-01-30 14:27:37 +0100 | [diff] [blame] | 65 | .attach = acpi_pci_link_add, |
| 66 | .detach = acpi_pci_link_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 69 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | struct acpi_pci_link_irq { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 74 | u8 active; /* Current IRQ */ |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 75 | u8 triggering; /* All IRQs */ |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 76 | u8 polarity; /* All IRQs */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 77 | u8 resource_type; |
| 78 | u8 possible_count; |
| 79 | u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE]; |
| 80 | u8 initialized:1; |
| 81 | u8 reserved:7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | struct acpi_pci_link { |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 85 | struct list_head list; |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 86 | struct acpi_device *device; |
| 87 | struct acpi_pci_link_irq irq; |
| 88 | int refcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 91 | static LIST_HEAD(acpi_link_list); |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 92 | static DEFINE_MUTEX(acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | /* -------------------------------------------------------------------------- |
| 95 | PCI Link Device Management |
| 96 | -------------------------------------------------------------------------- */ |
| 97 | |
| 98 | /* |
| 99 | * set context (link) possible list from resource list |
| 100 | */ |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 101 | static acpi_status acpi_pci_link_check_possible(struct acpi_resource *resource, |
| 102 | void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 104 | struct acpi_pci_link *link = context; |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 105 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 107 | switch (resource->type) { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 108 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 109 | case ACPI_RESOURCE_TYPE_END_TAG: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 110 | return AE_OK; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 111 | case ACPI_RESOURCE_TYPE_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | { |
| 113 | struct acpi_resource_irq *p = &resource->data.irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 114 | if (!p || !p->interrupt_count) { |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 115 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 116 | "Blank _PRS IRQ resource\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 117 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 119 | for (i = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 120 | (i < p->interrupt_count |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 121 | && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { |
| 122 | if (!p->interrupts[i]) { |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 123 | printk(KERN_WARNING PREFIX |
| 124 | "Invalid _PRS IRQ %d\n", |
| 125 | p->interrupts[i]); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | continue; |
| 127 | } |
| 128 | link->irq.possible[i] = p->interrupts[i]; |
| 129 | link->irq.possible_count++; |
| 130 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 131 | link->irq.triggering = p->triggering; |
| 132 | link->irq.polarity = p->polarity; |
| 133 | link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 134 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 136 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 138 | struct acpi_resource_extended_irq *p = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 139 | &resource->data.extended_irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 140 | if (!p || !p->interrupt_count) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 141 | printk(KERN_WARNING PREFIX |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 142 | "Blank _PRS EXT IRQ resource\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 143 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | for (i = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 146 | (i < p->interrupt_count |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { |
| 148 | if (!p->interrupts[i]) { |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 149 | printk(KERN_WARNING PREFIX |
| 150 | "Invalid _PRS IRQ %d\n", |
| 151 | p->interrupts[i]); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 152 | continue; |
| 153 | } |
| 154 | link->irq.possible[i] = p->interrupts[i]; |
| 155 | link->irq.possible_count++; |
| 156 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 157 | link->irq.triggering = p->triggering; |
| 158 | link->irq.polarity = p->polarity; |
| 159 | link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 160 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | default: |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 163 | printk(KERN_ERR PREFIX "_PRS resource type 0x%x isn't an IRQ\n", |
| 164 | resource->type); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 165 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 168 | return AE_CTRL_TERMINATE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | static int acpi_pci_link_get_possible(struct acpi_pci_link *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 173 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Patrick Mochel | 67a7136 | 2006-05-19 16:54:42 -0400 | [diff] [blame] | 175 | status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | acpi_pci_link_check_possible, link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 178 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 179 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 183 | "Found %d possible IRQs\n", |
| 184 | link->irq.possible_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 186 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 189 | static acpi_status acpi_pci_link_check_current(struct acpi_resource *resource, |
| 190 | void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 192 | int *irq = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 194 | switch (resource->type) { |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 195 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
| 196 | case ACPI_RESOURCE_TYPE_END_TAG: |
| 197 | return AE_OK; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 198 | case ACPI_RESOURCE_TYPE_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 199 | { |
| 200 | struct acpi_resource_irq *p = &resource->data.irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 201 | if (!p || !p->interrupt_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | /* |
| 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 Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 207 | "Blank _CRS IRQ resource\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 208 | return AE_OK; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 209 | } |
| 210 | *irq = p->interrupts[0]; |
| 211 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 213 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 215 | struct acpi_resource_extended_irq *p = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | &resource->data.extended_irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 217 | if (!p || !p->interrupt_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | /* |
| 219 | * extended IRQ descriptors must |
| 220 | * return at least 1 IRQ |
| 221 | */ |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 222 | printk(KERN_WARNING PREFIX |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 223 | "Blank _CRS EXT IRQ resource\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 224 | return AE_OK; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | } |
| 226 | *irq = p->interrupts[0]; |
| 227 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
Len Brown | d4ec6c7 | 2006-01-26 17:23:38 -0500 | [diff] [blame] | 229 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | default: |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 231 | printk(KERN_ERR PREFIX "_CRS resource type 0x%x isn't an IRQ\n", |
| 232 | resource->type); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 233 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 235 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 236 | return AE_CTRL_TERMINATE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | /* |
| 240 | * Run _CRS and set link->irq.active |
| 241 | * |
| 242 | * return value: |
| 243 | * 0 - success |
| 244 | * !0 - failure |
| 245 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 246 | static int acpi_pci_link_get_current(struct acpi_pci_link *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | int result = 0; |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 249 | acpi_status status; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | int irq = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | 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 Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 259 | printk(KERN_ERR PREFIX "Unable to read status\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | goto end; |
| 261 | } |
| 262 | |
| 263 | if (!link->device->status.enabled) { |
| 264 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 265 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * Query and parse _CRS to get the current IRQ assignment. |
| 271 | */ |
| 272 | |
Patrick Mochel | 67a7136 | 2006-05-19 16:54:42 -0400 | [diff] [blame] | 273 | status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | acpi_pci_link_check_current, &irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 276 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | result = -ENODEV; |
| 278 | goto end; |
| 279 | } |
| 280 | |
| 281 | if (acpi_strict && !irq) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 282 | printk(KERN_ERR PREFIX "_CRS returned 0\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 290 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 291 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | static int acpi_pci_link_set(struct acpi_pci_link *link, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 296 | int result; |
| 297 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | struct { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | struct acpi_resource res; |
| 300 | struct acpi_resource end; |
| 301 | } *resource; |
| 302 | struct acpi_buffer buffer = { 0, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Bjorn Helgaas | 6eca4b4 | 2009-02-17 14:00:50 -0700 | [diff] [blame] | 304 | if (!irq) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 305 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 307 | resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | if (!resource) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 309 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 311 | buffer.length = sizeof(*resource) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | buffer.pointer = resource; |
| 313 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 314 | switch (link->irq.resource_type) { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 315 | case ACPI_RESOURCE_TYPE_IRQ: |
| 316 | resource->res.type = ACPI_RESOURCE_TYPE_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | resource->res.length = sizeof(struct acpi_resource); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 318 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 323 | ACPI_EXCLUSIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | else |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 325 | resource->res.data.irq.sharable = ACPI_SHARED; |
| 326 | resource->res.data.irq.interrupt_count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | resource->res.data.irq.interrupts[0] = irq; |
| 328 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 330 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
| 331 | resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | resource->res.length = sizeof(struct acpi_resource); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | resource->res.data.extended_irq.producer_consumer = |
| 334 | ACPI_CONSUMER; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 335 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 341 | ACPI_EXCLUSIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | else |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 343 | resource->res.data.irq.sharable = ACPI_SHARED; |
| 344 | resource->res.data.extended_irq.interrupt_count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | resource->res.data.extended_irq.interrupts[0] = irq; |
| 346 | /* ignore resource_source, it's optional */ |
| 347 | break; |
| 348 | default: |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 349 | printk(KERN_ERR PREFIX "Invalid Resource_type %d\n", link->irq.resource_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | result = -EINVAL; |
| 351 | goto end; |
| 352 | |
| 353 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 354 | resource->end.type = ACPI_RESOURCE_TYPE_END_TAG; |
Yinghai Lu | f084dbb | 2013-03-23 19:16:37 +0000 | [diff] [blame] | 355 | resource->end.length = sizeof(struct acpi_resource); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | /* Attempt to set the resource */ |
Patrick Mochel | 67a7136 | 2006-05-19 16:54:42 -0400 | [diff] [blame] | 358 | status = acpi_set_current_resources(link->device->handle, &buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | /* check for total failure */ |
| 361 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 362 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | 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 Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 370 | printk(KERN_ERR PREFIX "Unable to read status\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | goto end; |
| 372 | } |
| 373 | if (!link->device->status.enabled) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 374 | printk(KERN_WARNING PREFIX |
| 375 | "%s [%s] disabled and referenced, BIOS bug\n", |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 376 | acpi_device_name(link->device), |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 377 | acpi_device_bid(link->device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 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 Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 395 | printk(KERN_WARNING PREFIX |
| 396 | "%s [%s] BIOS reported IRQ %d, using IRQ %d\n", |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 397 | acpi_device_name(link->device), |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 398 | acpi_device_bid(link->device), link->irq.active, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | link->irq.active = irq; |
| 400 | } |
| 401 | |
| 402 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d\n", link->irq.active)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 403 | |
| 404 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | kfree(resource); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 406 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | /* -------------------------------------------------------------------------- |
| 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 | |
| 454 | static 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 458 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ3 serial */ |
| 459 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ4 serial */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | 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 Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 467 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 471 | /* >IRQ15 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | }; |
| 473 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 474 | int __init acpi_irq_penalty_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 476 | struct acpi_pci_link *link; |
| 477 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /* |
| 480 | * Update penalties to facilitate IRQ balancing. |
| 481 | */ |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 482 | list_for_each_entry(link, &acpi_link_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 489 | int penalty = |
| 490 | PIRQ_PENALTY_PCI_POSSIBLE / |
| 491 | link->irq.possible_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | for (i = 0; i < link->irq.possible_count; i++) { |
| 494 | if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 495 | acpi_irq_penalty[link->irq. |
| 496 | possible[i]] += |
| 497 | penalty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | } else if (link->irq.active) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 501 | acpi_irq_penalty[link->irq.active] += |
| 502 | PIRQ_PENALTY_PCI_POSSIBLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | /* Add a penalty for the SCI */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 506 | acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 507 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Bjorn Helgaas | 3283625 | 2008-11-05 16:17:52 -0700 | [diff] [blame] | 510 | static int acpi_irq_balance = -1; /* 0: static, 1: balance */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 512 | static int acpi_pci_link_allocate(struct acpi_pci_link *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | int irq; |
| 515 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 517 | 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 Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 521 | return 0; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
| 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 Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 536 | printk(KERN_WARNING PREFIX "_CRS %d not found" |
| 537 | " in _PRS\n", link->irq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | link->irq.active = 0; |
| 539 | } |
| 540 | |
| 541 | /* |
| 542 | * if active found, use it; else pick entry from end of possible list. |
| 543 | */ |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 544 | if (link->irq.active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | irq = link->irq.active; |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 546 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | irq = link->irq.possible[link->irq.possible_count - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
| 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 555 | if (acpi_irq_penalty[irq] > |
| 556 | acpi_irq_penalty[link->irq.possible[i]]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | 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 Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 563 | printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. " |
| 564 | "Try pci=noacpi or acpi=off\n", |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 565 | acpi_device_name(link->device), |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 566 | acpi_device_bid(link->device)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 567 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } else { |
| 569 | acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING; |
Frank Seidel | 4d93915 | 2009-02-04 17:03:07 +0100 | [diff] [blame] | 570 | printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 571 | acpi_device_name(link->device), |
| 572 | acpi_device_bid(link->device), link->irq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | link->irq.initialized = 1; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 576 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /* |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 580 | * acpi_pci_link_allocate_irq |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | * success: return IRQ >= 0 |
| 582 | * failure: return -1 |
| 583 | */ |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 584 | int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering, |
| 585 | int *polarity, char **name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 587 | int result; |
| 588 | struct acpi_device *device; |
| 589 | struct acpi_pci_link *link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | result = acpi_bus_get_device(handle, &device); |
| 592 | if (result) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 593 | printk(KERN_ERR PREFIX "Invalid link device\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 594 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 597 | link = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | if (!link) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 599 | printk(KERN_ERR PREFIX "Invalid link context\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 600 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | /* TBD: Support multiple index (IRQ) entries per Link Device */ |
| 604 | if (index) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 605 | printk(KERN_ERR PREFIX "Invalid index %d\n", index); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 606 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 609 | mutex_lock(&acpi_link_lock); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 610 | if (acpi_pci_link_allocate(link)) { |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 611 | mutex_unlock(&acpi_link_lock); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 612 | return -1; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 613 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | if (!link->irq.active) { |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 616 | mutex_unlock(&acpi_link_lock); |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 617 | printk(KERN_ERR PREFIX "Link active IRQ is 0!\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 618 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 620 | link->refcnt++; |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 621 | mutex_unlock(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 623 | if (triggering) |
| 624 | *triggering = link->irq.triggering; |
| 625 | if (polarity) |
| 626 | *polarity = link->irq.polarity; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 627 | if (name) |
| 628 | *name = acpi_device_bid(link->device); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 629 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 630 | "Link %s is referenced\n", |
| 631 | acpi_device_bid(link->device))); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 632 | return (link->irq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
| 634 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 635 | /* |
| 636 | * We don't change link's irq information here. After it is reenabled, we |
| 637 | * continue use the info |
| 638 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 639 | int acpi_pci_link_free_irq(acpi_handle handle) |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 640 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 641 | struct acpi_device *device; |
| 642 | struct acpi_pci_link *link; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 643 | acpi_status result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 645 | result = acpi_bus_get_device(handle, &device); |
| 646 | if (result) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 647 | printk(KERN_ERR PREFIX "Invalid link device\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 648 | return -1; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 649 | } |
| 650 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 651 | link = acpi_driver_data(device); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 652 | if (!link) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 653 | printk(KERN_ERR PREFIX "Invalid link context\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 654 | return -1; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 655 | } |
| 656 | |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 657 | mutex_lock(&acpi_link_lock); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 658 | if (!link->irq.initialized) { |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 659 | mutex_unlock(&acpi_link_lock); |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 660 | printk(KERN_ERR PREFIX "Link isn't initialized\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 661 | return -1; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 662 | } |
David Shaohua Li | ecc21eb | 2005-08-03 11:00:11 -0400 | [diff] [blame] | 663 | #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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 673 | link->refcnt--; |
David Shaohua Li | ecc21eb | 2005-08-03 11:00:11 -0400 | [diff] [blame] | 674 | #endif |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 675 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 676 | "Link %s is dereferenced\n", |
| 677 | acpi_device_bid(link->device))); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 678 | |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 679 | if (link->refcnt == 0) |
donald.d.dugger@intel.com | 383d7a1 | 2008-10-17 07:49:50 -0700 | [diff] [blame] | 680 | acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL); |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 681 | |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 682 | mutex_unlock(&acpi_link_lock); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 683 | return (link->irq.active); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 684 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | /* -------------------------------------------------------------------------- |
| 687 | Driver Interface |
| 688 | -------------------------------------------------------------------------- */ |
| 689 | |
Rafael J. Wysocki | 4daeaf6 | 2013-01-30 14:27:37 +0100 | [diff] [blame] | 690 | static int acpi_pci_link_add(struct acpi_device *device, |
| 691 | const struct acpi_device_id *not_used) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 693 | int result; |
| 694 | struct acpi_pci_link *link; |
| 695 | int i; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 696 | int found = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 698 | link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | if (!link) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 700 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
| 702 | link->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME); |
| 704 | strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 705 | device->driver_data = link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 707 | mutex_lock(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | 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 Aloni | 0dc070b | 2007-07-09 11:33:18 -0700 | [diff] [blame] | 715 | printk(KERN_INFO PREFIX "%s [%s] (IRQs", acpi_device_name(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 716 | acpi_device_bid(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | for (i = 0; i < link->irq.possible_count; i++) { |
| 718 | if (link->irq.active == link->irq.possible[i]) { |
Kay Sievers | be96447 | 2012-05-08 17:24:20 +0200 | [diff] [blame] | 719 | printk(KERN_CONT " *%d", link->irq.possible[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | found = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 721 | } else |
Kay Sievers | be96447 | 2012-05-08 17:24:20 +0200 | [diff] [blame] | 722 | printk(KERN_CONT " %d", link->irq.possible[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
| 724 | |
Kay Sievers | be96447 | 2012-05-08 17:24:20 +0200 | [diff] [blame] | 725 | printk(KERN_CONT ")"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | |
| 727 | if (!found) |
Kay Sievers | be96447 | 2012-05-08 17:24:20 +0200 | [diff] [blame] | 728 | printk(KERN_CONT " *%d", link->irq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 730 | if (!link->device->status.enabled) |
Kay Sievers | be96447 | 2012-05-08 17:24:20 +0200 | [diff] [blame] | 731 | printk(KERN_CONT ", disabled."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Kay Sievers | be96447 | 2012-05-08 17:24:20 +0200 | [diff] [blame] | 733 | printk(KERN_CONT "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 735 | list_add_tail(&link->list, &acpi_link_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 737 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | /* disable all links -- to be activated on use */ |
donald.d.dugger@intel.com | 383d7a1 | 2008-10-17 07:49:50 -0700 | [diff] [blame] | 739 | acpi_evaluate_object(device->handle, "_DIS", NULL, NULL); |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 740 | mutex_unlock(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | |
| 742 | if (result) |
| 743 | kfree(link); |
| 744 | |
Rafael J. Wysocki | 4daeaf6 | 2013-01-30 14:27:37 +0100 | [diff] [blame] | 745 | return result < 0 ? result : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 748 | static int acpi_pci_link_resume(struct acpi_pci_link *link) |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 749 | { |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 750 | if (link->refcnt && link->irq.active && link->irq.initialized) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 751 | return (acpi_pci_link_set(link, link->irq.active)); |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 752 | |
| 753 | return 0; |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Rafael J. Wysocki | c3146df | 2011-03-12 22:16:51 +0100 | [diff] [blame] | 756 | static void irqrouter_resume(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 758 | struct acpi_pci_link *link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 760 | list_for_each_entry(link, &acpi_link_list, list) { |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 761 | acpi_pci_link_resume(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | } |
| 764 | |
Rafael J. Wysocki | 4daeaf6 | 2013-01-30 14:27:37 +0100 | [diff] [blame] | 765 | static void acpi_pci_link_remove(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 767 | struct acpi_pci_link *link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 769 | link = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 771 | mutex_lock(&acpi_link_lock); |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 772 | list_del(&link->list); |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 773 | mutex_unlock(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
| 775 | kfree(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | /* |
| 779 | * modify acpi_irq_penalty[] from cmdline |
| 780 | */ |
| 781 | static 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 789 | retval = get_option(&str, &irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | if (!retval) |
| 792 | break; /* no number found */ |
| 793 | |
| 794 | if (irq < 0) |
| 795 | continue; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 796 | |
Bjorn Helgaas | fa46d35 | 2008-08-01 15:58:17 -0600 | [diff] [blame] | 797 | if (irq >= ARRAY_SIZE(acpi_irq_penalty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | 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 Li | c9c3e45 | 2005-04-01 00:07:31 -0500 | [diff] [blame] | 818 | void acpi_penalize_isa_irq(int irq, int active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | { |
Bjorn Helgaas | fa46d35 | 2008-08-01 15:58:17 -0600 | [diff] [blame] | 820 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | } |
| 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 | */ |
| 833 | static int __init acpi_irq_isa(char *str) |
| 834 | { |
| 835 | return acpi_irq_penalty_update(str, 1); |
| 836 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | __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 | */ |
| 845 | static int __init acpi_irq_pci(char *str) |
| 846 | { |
| 847 | return acpi_irq_penalty_update(str, 0); |
| 848 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | __setup("acpi_irq_pci=", acpi_irq_pci); |
| 851 | |
| 852 | static int __init acpi_irq_nobalance_set(char *str) |
| 853 | { |
| 854 | acpi_irq_balance = 0; |
| 855 | return 1; |
| 856 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | __setup("acpi_irq_nobalance", acpi_irq_nobalance_set); |
| 859 | |
Roel Kluin | 8a383ef | 2008-12-09 20:45:30 +0100 | [diff] [blame] | 860 | static int __init acpi_irq_balance_set(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | { |
| 862 | acpi_irq_balance = 1; |
| 863 | return 1; |
| 864 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 866 | __setup("acpi_irq_balance", acpi_irq_balance_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
Rafael J. Wysocki | c3146df | 2011-03-12 22:16:51 +0100 | [diff] [blame] | 868 | static struct syscore_ops irqrouter_syscore_ops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 869 | .resume = irqrouter_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | }; |
| 871 | |
Rafael J. Wysocki | 4daeaf6 | 2013-01-30 14:27:37 +0100 | [diff] [blame] | 872 | void __init acpi_pci_link_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | if (acpi_noirq) |
Rafael J. Wysocki | 4daeaf6 | 2013-01-30 14:27:37 +0100 | [diff] [blame] | 875 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
Bjorn Helgaas | 3283625 | 2008-11-05 16:17:52 -0700 | [diff] [blame] | 877 | 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. Wysocki | 4daeaf6 | 2013-01-30 14:27:37 +0100 | [diff] [blame] | 884 | register_syscore_ops(&irqrouter_syscore_ops); |
| 885 | acpi_scan_add_handler(&pci_link_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | } |