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 | |
| 32 | #include <linux/sysdev.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/module.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/types.h> |
| 37 | #include <linux/proc_fs.h> |
| 38 | #include <linux/spinlock.h> |
| 39 | #include <linux/pm.h> |
| 40 | #include <linux/pci.h> |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 41 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #include <acpi/acpi_bus.h> |
| 44 | #include <acpi/acpi_drivers.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 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 54 | static int acpi_pci_link_add(struct acpi_device *device); |
| 55 | static int acpi_pci_link_remove(struct acpi_device *device, int type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 57 | static struct acpi_device_id link_device_ids[] = { |
| 58 | {"PNP0C0F", 0}, |
| 59 | {"", 0}, |
| 60 | }; |
| 61 | MODULE_DEVICE_TABLE(acpi, link_device_ids); |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | static struct acpi_driver acpi_pci_link_driver = { |
Len Brown | c2b6705 | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 64 | .name = "pci_link", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 65 | .class = ACPI_PCI_LINK_CLASS, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 66 | .ids = link_device_ids, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 67 | .ops = { |
| 68 | .add = acpi_pci_link_add, |
| 69 | .remove = acpi_pci_link_remove, |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 70 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 73 | /* |
| 74 | * If a link is initialized, we never change its active and initialized |
| 75 | * later even the link is disable. Instead, we just repick the active irq |
| 76 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | struct acpi_pci_link_irq { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | u8 active; /* Current IRQ */ |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 79 | u8 triggering; /* All IRQs */ |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 80 | u8 polarity; /* All IRQs */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | u8 resource_type; |
| 82 | u8 possible_count; |
| 83 | u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE]; |
| 84 | u8 initialized:1; |
| 85 | u8 reserved:7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | struct acpi_pci_link { |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 89 | struct list_head list; |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 90 | struct acpi_device *device; |
| 91 | struct acpi_pci_link_irq irq; |
| 92 | int refcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 95 | static LIST_HEAD(acpi_link_list); |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 96 | static DEFINE_MUTEX(acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* -------------------------------------------------------------------------- |
| 99 | PCI Link Device Management |
| 100 | -------------------------------------------------------------------------- */ |
| 101 | |
| 102 | /* |
| 103 | * set context (link) possible list from resource list |
| 104 | */ |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 105 | static acpi_status acpi_pci_link_check_possible(struct acpi_resource *resource, |
| 106 | void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 108 | struct acpi_pci_link *link = context; |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 109 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 111 | switch (resource->type) { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 112 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 113 | case ACPI_RESOURCE_TYPE_END_TAG: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 114 | return AE_OK; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 115 | case ACPI_RESOURCE_TYPE_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 116 | { |
| 117 | struct acpi_resource_irq *p = &resource->data.irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 118 | if (!p || !p->interrupt_count) { |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 119 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 120 | "Blank _PRS IRQ resource\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 121 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 123 | for (i = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 124 | (i < p->interrupt_count |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { |
| 126 | if (!p->interrupts[i]) { |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 127 | printk(KERN_WARNING PREFIX |
| 128 | "Invalid _PRS IRQ %d\n", |
| 129 | p->interrupts[i]); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | continue; |
| 131 | } |
| 132 | link->irq.possible[i] = p->interrupts[i]; |
| 133 | link->irq.possible_count++; |
| 134 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 135 | link->irq.triggering = p->triggering; |
| 136 | link->irq.polarity = p->polarity; |
| 137 | link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 140 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 142 | struct acpi_resource_extended_irq *p = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | &resource->data.extended_irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 144 | if (!p || !p->interrupt_count) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 145 | printk(KERN_WARNING PREFIX |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 146 | "Blank _PRS EXT IRQ resource\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 147 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | for (i = 0; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 150 | (i < p->interrupt_count |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 151 | && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { |
| 152 | if (!p->interrupts[i]) { |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 153 | printk(KERN_WARNING PREFIX |
| 154 | "Invalid _PRS IRQ %d\n", |
| 155 | p->interrupts[i]); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | continue; |
| 157 | } |
| 158 | link->irq.possible[i] = p->interrupts[i]; |
| 159 | link->irq.possible_count++; |
| 160 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 161 | link->irq.triggering = p->triggering; |
| 162 | link->irq.polarity = p->polarity; |
| 163 | link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | default: |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 167 | printk(KERN_ERR PREFIX "_PRS resource type 0x%x isn't an IRQ\n", |
| 168 | resource->type); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 169 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 172 | return AE_CTRL_TERMINATE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | static int acpi_pci_link_get_possible(struct acpi_pci_link *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Patrick Mochel | 67a7136 | 2006-05-19 16:54:42 -0400 | [diff] [blame] | 179 | status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 180 | acpi_pci_link_check_possible, link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 182 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 183 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 187 | "Found %d possible IRQs\n", |
| 188 | link->irq.possible_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 190 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 193 | static acpi_status acpi_pci_link_check_current(struct acpi_resource *resource, |
| 194 | void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 196 | int *irq = context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 198 | switch (resource->type) { |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 199 | case ACPI_RESOURCE_TYPE_START_DEPENDENT: |
| 200 | case ACPI_RESOURCE_TYPE_END_TAG: |
| 201 | return AE_OK; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 202 | case ACPI_RESOURCE_TYPE_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | { |
| 204 | struct acpi_resource_irq *p = &resource->data.irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 205 | if (!p || !p->interrupt_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | /* |
| 207 | * IRQ descriptors may have no IRQ# bits set, |
| 208 | * particularly those those w/ _STA disabled |
| 209 | */ |
| 210 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 211 | "Blank _CRS IRQ resource\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 212 | return AE_OK; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | } |
| 214 | *irq = p->interrupts[0]; |
| 215 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 217 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 219 | struct acpi_resource_extended_irq *p = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | &resource->data.extended_irq; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 221 | if (!p || !p->interrupt_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 222 | /* |
| 223 | * extended IRQ descriptors must |
| 224 | * return at least 1 IRQ |
| 225 | */ |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 226 | printk(KERN_WARNING PREFIX |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 227 | "Blank _CRS EXT IRQ resource\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 228 | return AE_OK; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 229 | } |
| 230 | *irq = p->interrupts[0]; |
| 231 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
Len Brown | d4ec6c7 | 2006-01-26 17:23:38 -0500 | [diff] [blame] | 233 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | default: |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 235 | printk(KERN_ERR PREFIX "_CRS resource type 0x%x isn't an IRQ\n", |
| 236 | resource->type); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 237 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 239 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 240 | return AE_CTRL_TERMINATE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* |
| 244 | * Run _CRS and set link->irq.active |
| 245 | * |
| 246 | * return value: |
| 247 | * 0 - success |
| 248 | * !0 - failure |
| 249 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | static int acpi_pci_link_get_current(struct acpi_pci_link *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | int result = 0; |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 253 | acpi_status status; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | int irq = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | link->irq.active = 0; |
| 257 | |
| 258 | /* in practice, status disabled is meaningless, ignore it */ |
| 259 | if (acpi_strict) { |
| 260 | /* Query _STA, set link->device->status */ |
| 261 | result = acpi_bus_get_status(link->device); |
| 262 | if (result) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 263 | printk(KERN_ERR PREFIX "Unable to read status\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | goto end; |
| 265 | } |
| 266 | |
| 267 | if (!link->device->status.enabled) { |
| 268 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 269 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
| 273 | /* |
| 274 | * Query and parse _CRS to get the current IRQ assignment. |
| 275 | */ |
| 276 | |
Patrick Mochel | 67a7136 | 2006-05-19 16:54:42 -0400 | [diff] [blame] | 277 | status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 278 | acpi_pci_link_check_current, &irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 280 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | result = -ENODEV; |
| 282 | goto end; |
| 283 | } |
| 284 | |
| 285 | if (acpi_strict && !irq) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 286 | printk(KERN_ERR PREFIX "_CRS returned 0\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | result = -ENODEV; |
| 288 | } |
| 289 | |
| 290 | link->irq.active = irq; |
| 291 | |
| 292 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active)); |
| 293 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 295 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | 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] | 299 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 300 | int result; |
| 301 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | struct { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 303 | struct acpi_resource res; |
| 304 | struct acpi_resource end; |
| 305 | } *resource; |
| 306 | struct acpi_buffer buffer = { 0, NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Bjorn Helgaas | 6eca4b4 | 2009-02-17 14:00:50 -0700 | [diff] [blame] | 308 | if (!irq) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 309 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 311 | resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 312 | if (!resource) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 313 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | buffer.length = sizeof(*resource) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | buffer.pointer = resource; |
| 317 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 318 | switch (link->irq.resource_type) { |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 319 | case ACPI_RESOURCE_TYPE_IRQ: |
| 320 | resource->res.type = ACPI_RESOURCE_TYPE_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | resource->res.length = sizeof(struct acpi_resource); |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 322 | resource->res.data.irq.triggering = link->irq.triggering; |
| 323 | resource->res.data.irq.polarity = |
| 324 | link->irq.polarity; |
| 325 | if (link->irq.triggering == ACPI_EDGE_SENSITIVE) |
| 326 | resource->res.data.irq.sharable = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 327 | ACPI_EXCLUSIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | else |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 329 | resource->res.data.irq.sharable = ACPI_SHARED; |
| 330 | resource->res.data.irq.interrupt_count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | resource->res.data.irq.interrupts[0] = irq; |
| 332 | break; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 334 | case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: |
| 335 | resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | resource->res.length = sizeof(struct acpi_resource); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | resource->res.data.extended_irq.producer_consumer = |
| 338 | ACPI_CONSUMER; |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 339 | resource->res.data.extended_irq.triggering = |
| 340 | link->irq.triggering; |
| 341 | resource->res.data.extended_irq.polarity = |
| 342 | link->irq.polarity; |
| 343 | if (link->irq.triggering == ACPI_EDGE_SENSITIVE) |
| 344 | resource->res.data.irq.sharable = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | ACPI_EXCLUSIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | else |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 347 | resource->res.data.irq.sharable = ACPI_SHARED; |
| 348 | resource->res.data.extended_irq.interrupt_count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | resource->res.data.extended_irq.interrupts[0] = irq; |
| 350 | /* ignore resource_source, it's optional */ |
| 351 | break; |
| 352 | default: |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 353 | 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] | 354 | result = -EINVAL; |
| 355 | goto end; |
| 356 | |
| 357 | } |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 358 | resource->end.type = ACPI_RESOURCE_TYPE_END_TAG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | /* Attempt to set the resource */ |
Patrick Mochel | 67a7136 | 2006-05-19 16:54:42 -0400 | [diff] [blame] | 361 | status = acpi_set_current_resources(link->device->handle, &buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | /* check for total failure */ |
| 364 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 365 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | result = -ENODEV; |
| 367 | goto end; |
| 368 | } |
| 369 | |
| 370 | /* Query _STA, set device->status */ |
| 371 | result = acpi_bus_get_status(link->device); |
| 372 | if (result) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 373 | printk(KERN_ERR PREFIX "Unable to read status\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | goto end; |
| 375 | } |
| 376 | if (!link->device->status.enabled) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 377 | printk(KERN_WARNING PREFIX |
| 378 | "%s [%s] disabled and referenced, BIOS bug\n", |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 379 | acpi_device_name(link->device), |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 380 | acpi_device_bid(link->device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /* Query _CRS, set link->irq.active */ |
| 384 | result = acpi_pci_link_get_current(link); |
| 385 | if (result) { |
| 386 | goto end; |
| 387 | } |
| 388 | |
| 389 | /* |
| 390 | * Is current setting not what we set? |
| 391 | * set link->irq.active |
| 392 | */ |
| 393 | if (link->irq.active != irq) { |
| 394 | /* |
| 395 | * policy: when _CRS doesn't return what we just _SRS |
| 396 | * assume _SRS worked and override _CRS value. |
| 397 | */ |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 398 | printk(KERN_WARNING PREFIX |
| 399 | "%s [%s] BIOS reported IRQ %d, using IRQ %d\n", |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 400 | acpi_device_name(link->device), |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 401 | acpi_device_bid(link->device), link->irq.active, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | link->irq.active = irq; |
| 403 | } |
| 404 | |
| 405 | 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] | 406 | |
| 407 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | kfree(resource); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 409 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | /* -------------------------------------------------------------------------- |
| 413 | PCI Link IRQ Management |
| 414 | -------------------------------------------------------------------------- */ |
| 415 | |
| 416 | /* |
| 417 | * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt |
| 418 | * Link Devices to move the PIRQs around to minimize sharing. |
| 419 | * |
| 420 | * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs |
| 421 | * that the BIOS has already set to active. This is necessary because |
| 422 | * ACPI has no automatic means of knowing what ISA IRQs are used. Note that |
| 423 | * if the BIOS doesn't set a Link Device active, ACPI needs to program it |
| 424 | * even if acpi_irq_nobalance is set. |
| 425 | * |
| 426 | * A tables of penalties avoids directing PCI interrupts to well known |
| 427 | * ISA IRQs. Boot params are available to over-ride the default table: |
| 428 | * |
| 429 | * List interrupts that are free for PCI use. |
| 430 | * acpi_irq_pci=n[,m] |
| 431 | * |
| 432 | * List interrupts that should not be used for PCI: |
| 433 | * acpi_irq_isa=n[,m] |
| 434 | * |
| 435 | * Note that PCI IRQ routers have a list of possible IRQs, |
| 436 | * which may not include the IRQs this table says are available. |
| 437 | * |
| 438 | * Since this heuristic can't tell the difference between a link |
| 439 | * that no device will attach to, vs. a link which may be shared |
| 440 | * by multiple active devices -- it is not optimal. |
| 441 | * |
| 442 | * If interrupt performance is that important, get an IO-APIC system |
| 443 | * with a pin dedicated to each device. Or for that matter, an MSI |
| 444 | * enabled system. |
| 445 | */ |
| 446 | |
| 447 | #define ACPI_MAX_IRQS 256 |
| 448 | #define ACPI_MAX_ISA_IRQ 16 |
| 449 | |
| 450 | #define PIRQ_PENALTY_PCI_AVAILABLE (0) |
| 451 | #define PIRQ_PENALTY_PCI_POSSIBLE (16*16) |
| 452 | #define PIRQ_PENALTY_PCI_USING (16*16*16) |
| 453 | #define PIRQ_PENALTY_ISA_TYPICAL (16*16*16*16) |
| 454 | #define PIRQ_PENALTY_ISA_USED (16*16*16*16*16) |
| 455 | #define PIRQ_PENALTY_ISA_ALWAYS (16*16*16*16*16*16) |
| 456 | |
| 457 | static int acpi_irq_penalty[ACPI_MAX_IRQS] = { |
| 458 | PIRQ_PENALTY_ISA_ALWAYS, /* IRQ0 timer */ |
| 459 | PIRQ_PENALTY_ISA_ALWAYS, /* IRQ1 keyboard */ |
| 460 | PIRQ_PENALTY_ISA_ALWAYS, /* IRQ2 cascade */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 461 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ3 serial */ |
| 462 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ4 serial */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ5 sometimes SoundBlaster */ |
| 464 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ6 */ |
| 465 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ7 parallel, spurious */ |
| 466 | PIRQ_PENALTY_ISA_TYPICAL, /* IRQ8 rtc, sometimes */ |
| 467 | PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ9 PCI, often acpi */ |
| 468 | PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ10 PCI */ |
| 469 | PIRQ_PENALTY_PCI_AVAILABLE, /* IRQ11 PCI */ |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 470 | PIRQ_PENALTY_ISA_USED, /* IRQ12 mouse */ |
| 471 | PIRQ_PENALTY_ISA_USED, /* IRQ13 fpe, sometimes */ |
| 472 | PIRQ_PENALTY_ISA_USED, /* IRQ14 ide0 */ |
| 473 | PIRQ_PENALTY_ISA_USED, /* IRQ15 ide1 */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 474 | /* >IRQ15 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | }; |
| 476 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 477 | int __init acpi_irq_penalty_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 479 | struct acpi_pci_link *link; |
| 480 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | /* |
| 483 | * Update penalties to facilitate IRQ balancing. |
| 484 | */ |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 485 | list_for_each_entry(link, &acpi_link_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
| 487 | /* |
| 488 | * reflect the possible and active irqs in the penalty table -- |
| 489 | * useful for breaking ties. |
| 490 | */ |
| 491 | if (link->irq.possible_count) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 492 | int penalty = |
| 493 | PIRQ_PENALTY_PCI_POSSIBLE / |
| 494 | link->irq.possible_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
| 496 | for (i = 0; i < link->irq.possible_count; i++) { |
| 497 | if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 498 | acpi_irq_penalty[link->irq. |
| 499 | possible[i]] += |
| 500 | penalty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | } else if (link->irq.active) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 504 | acpi_irq_penalty[link->irq.active] += |
| 505 | PIRQ_PENALTY_PCI_POSSIBLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | /* Add a penalty for the SCI */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 509 | acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 510 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Bjorn Helgaas | 3283625 | 2008-11-05 16:17:52 -0700 | [diff] [blame] | 513 | static int acpi_irq_balance = -1; /* 0: static, 1: balance */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 515 | static int acpi_pci_link_allocate(struct acpi_pci_link *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 517 | int irq; |
| 518 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 520 | if (link->irq.initialized) { |
| 521 | if (link->refcnt == 0) |
| 522 | /* This means the link is disabled but initialized */ |
| 523 | acpi_pci_link_set(link, link->irq.active); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 524 | return 0; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 525 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | /* |
| 528 | * search for active IRQ in list of possible IRQs. |
| 529 | */ |
| 530 | for (i = 0; i < link->irq.possible_count; ++i) { |
| 531 | if (link->irq.active == link->irq.possible[i]) |
| 532 | break; |
| 533 | } |
| 534 | /* |
| 535 | * forget active IRQ that is not in possible list |
| 536 | */ |
| 537 | if (i == link->irq.possible_count) { |
| 538 | if (acpi_strict) |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 539 | printk(KERN_WARNING PREFIX "_CRS %d not found" |
| 540 | " in _PRS\n", link->irq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | link->irq.active = 0; |
| 542 | } |
| 543 | |
| 544 | /* |
| 545 | * if active found, use it; else pick entry from end of possible list. |
| 546 | */ |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 547 | if (link->irq.active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | irq = link->irq.active; |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 549 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | irq = link->irq.possible[link->irq.possible_count - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | if (acpi_irq_balance || !link->irq.active) { |
| 553 | /* |
| 554 | * Select the best IRQ. This is done in reverse to promote |
| 555 | * the use of IRQs 9, 10, 11, and >15. |
| 556 | */ |
| 557 | for (i = (link->irq.possible_count - 1); i >= 0; i--) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 558 | if (acpi_irq_penalty[irq] > |
| 559 | acpi_irq_penalty[link->irq.possible[i]]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | irq = link->irq.possible[i]; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | /* Attempt to enable the link device at this IRQ. */ |
| 565 | if (acpi_pci_link_set(link, irq)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 566 | printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. " |
| 567 | "Try pci=noacpi or acpi=off\n", |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 568 | acpi_device_name(link->device), |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 569 | acpi_device_bid(link->device)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 570 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } else { |
| 572 | acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING; |
Frank Seidel | 4d93915 | 2009-02-04 17:03:07 +0100 | [diff] [blame] | 573 | printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 574 | acpi_device_name(link->device), |
| 575 | acpi_device_bid(link->device), link->irq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | link->irq.initialized = 1; |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 579 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | /* |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 583 | * acpi_pci_link_allocate_irq |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | * success: return IRQ >= 0 |
| 585 | * failure: return -1 |
| 586 | */ |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 587 | int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering, |
| 588 | int *polarity, char **name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 590 | int result; |
| 591 | struct acpi_device *device; |
| 592 | struct acpi_pci_link *link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | result = acpi_bus_get_device(handle, &device); |
| 595 | if (result) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 596 | printk(KERN_ERR PREFIX "Invalid link device\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 597 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 600 | link = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | if (!link) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 602 | printk(KERN_ERR PREFIX "Invalid link context\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 603 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | /* TBD: Support multiple index (IRQ) entries per Link Device */ |
| 607 | if (index) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 608 | printk(KERN_ERR PREFIX "Invalid index %d\n", index); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 609 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 612 | mutex_lock(&acpi_link_lock); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 613 | if (acpi_pci_link_allocate(link)) { |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 614 | mutex_unlock(&acpi_link_lock); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 615 | return -1; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 616 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | if (!link->irq.active) { |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 619 | mutex_unlock(&acpi_link_lock); |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 620 | printk(KERN_ERR PREFIX "Link active IRQ is 0!\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 621 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 623 | link->refcnt++; |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 624 | mutex_unlock(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 626 | if (triggering) |
| 627 | *triggering = link->irq.triggering; |
| 628 | if (polarity) |
| 629 | *polarity = link->irq.polarity; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 630 | if (name) |
| 631 | *name = acpi_device_bid(link->device); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 632 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 633 | "Link %s is referenced\n", |
| 634 | acpi_device_bid(link->device))); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 635 | return (link->irq.active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 638 | /* |
| 639 | * We don't change link's irq information here. After it is reenabled, we |
| 640 | * continue use the info |
| 641 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 642 | int acpi_pci_link_free_irq(acpi_handle handle) |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 643 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 644 | struct acpi_device *device; |
| 645 | struct acpi_pci_link *link; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 646 | acpi_status result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 648 | result = acpi_bus_get_device(handle, &device); |
| 649 | if (result) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 650 | printk(KERN_ERR PREFIX "Invalid link device\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 651 | return -1; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 652 | } |
| 653 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 654 | link = acpi_driver_data(device); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 655 | if (!link) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 656 | printk(KERN_ERR PREFIX "Invalid link context\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 657 | return -1; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 658 | } |
| 659 | |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 660 | mutex_lock(&acpi_link_lock); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 661 | if (!link->irq.initialized) { |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 662 | mutex_unlock(&acpi_link_lock); |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 663 | printk(KERN_ERR PREFIX "Link isn't initialized\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 664 | return -1; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 665 | } |
David Shaohua Li | ecc21eb | 2005-08-03 11:00:11 -0400 | [diff] [blame] | 666 | #ifdef FUTURE_USE |
| 667 | /* |
| 668 | * The Link reference count allows us to _DISable an unused link |
| 669 | * and suspend time, and set it again on resume. |
| 670 | * However, 2.6.12 still has irq_router.resume |
| 671 | * which blindly restores the link state. |
| 672 | * So we disable the reference count method |
| 673 | * to prevent duplicate acpi_pci_link_set() |
| 674 | * which would harm some systems |
| 675 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 676 | link->refcnt--; |
David Shaohua Li | ecc21eb | 2005-08-03 11:00:11 -0400 | [diff] [blame] | 677 | #endif |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 678 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 679 | "Link %s is dereferenced\n", |
| 680 | acpi_device_bid(link->device))); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 681 | |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 682 | if (link->refcnt == 0) |
donald.d.dugger@intel.com | 383d7a1 | 2008-10-17 07:49:50 -0700 | [diff] [blame] | 683 | acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL); |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 684 | |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 685 | mutex_unlock(&acpi_link_lock); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 686 | return (link->irq.active); |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 687 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | /* -------------------------------------------------------------------------- |
| 690 | Driver Interface |
| 691 | -------------------------------------------------------------------------- */ |
| 692 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 693 | static int acpi_pci_link_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 695 | int result; |
| 696 | struct acpi_pci_link *link; |
| 697 | int i; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 698 | int found = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 700 | link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | if (!link) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 702 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
| 704 | link->device = device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME); |
| 706 | strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 707 | device->driver_data = link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 709 | mutex_lock(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | result = acpi_pci_link_get_possible(link); |
| 711 | if (result) |
| 712 | goto end; |
| 713 | |
| 714 | /* query and set link->irq.active */ |
| 715 | acpi_pci_link_get_current(link); |
| 716 | |
Dan Aloni | 0dc070b | 2007-07-09 11:33:18 -0700 | [diff] [blame] | 717 | printk(KERN_INFO PREFIX "%s [%s] (IRQs", acpi_device_name(device), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 718 | acpi_device_bid(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | for (i = 0; i < link->irq.possible_count; i++) { |
| 720 | if (link->irq.active == link->irq.possible[i]) { |
| 721 | printk(" *%d", link->irq.possible[i]); |
| 722 | found = 1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 723 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | printk(" %d", link->irq.possible[i]); |
| 725 | } |
| 726 | |
| 727 | printk(")"); |
| 728 | |
| 729 | if (!found) |
| 730 | printk(" *%d", link->irq.active); |
| 731 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 732 | if (!link->device->status.enabled) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | printk(", disabled."); |
| 734 | |
| 735 | printk("\n"); |
| 736 | |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 737 | list_add_tail(&link->list, &acpi_link_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 739 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | /* disable all links -- to be activated on use */ |
donald.d.dugger@intel.com | 383d7a1 | 2008-10-17 07:49:50 -0700 | [diff] [blame] | 741 | acpi_evaluate_object(device->handle, "_DIS", NULL, NULL); |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 742 | mutex_unlock(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | |
| 744 | if (result) |
| 745 | kfree(link); |
| 746 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 747 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 750 | static int acpi_pci_link_resume(struct acpi_pci_link *link) |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 751 | { |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 752 | if (link->refcnt && link->irq.active && link->irq.initialized) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 753 | return (acpi_pci_link_set(link, link->irq.active)); |
Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 754 | |
| 755 | return 0; |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 758 | static int irqrouter_resume(struct sys_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 760 | struct acpi_pci_link *link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 762 | list_for_each_entry(link, &acpi_link_list, list) { |
Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 763 | acpi_pci_link_resume(link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | } |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 765 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 768 | static int acpi_pci_link_remove(struct acpi_device *device, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | { |
Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 770 | struct acpi_pci_link *link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 772 | link = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 774 | mutex_lock(&acpi_link_lock); |
Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 775 | list_del(&link->list); |
Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 776 | mutex_unlock(&acpi_link_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | kfree(link); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 779 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | /* |
| 783 | * modify acpi_irq_penalty[] from cmdline |
| 784 | */ |
| 785 | static int __init acpi_irq_penalty_update(char *str, int used) |
| 786 | { |
| 787 | int i; |
| 788 | |
| 789 | for (i = 0; i < 16; i++) { |
| 790 | int retval; |
| 791 | int irq; |
| 792 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 793 | retval = get_option(&str, &irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
| 795 | if (!retval) |
| 796 | break; /* no number found */ |
| 797 | |
| 798 | if (irq < 0) |
| 799 | continue; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 800 | |
Bjorn Helgaas | fa46d35 | 2008-08-01 15:58:17 -0600 | [diff] [blame] | 801 | if (irq >= ARRAY_SIZE(acpi_irq_penalty)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | continue; |
| 803 | |
| 804 | if (used) |
| 805 | acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED; |
| 806 | else |
| 807 | acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE; |
| 808 | |
| 809 | if (retval != 2) /* no next number */ |
| 810 | break; |
| 811 | } |
| 812 | return 1; |
| 813 | } |
| 814 | |
| 815 | /* |
| 816 | * We'd like PNP to call this routine for the |
| 817 | * single ISA_USED value for each legacy device. |
| 818 | * But instead it calls us with each POSSIBLE setting. |
| 819 | * There is no ISA_POSSIBLE weight, so we simply use |
| 820 | * the (small) PCI_USING penalty. |
| 821 | */ |
David Shaohua Li | c9c3e45 | 2005-04-01 00:07:31 -0500 | [diff] [blame] | 822 | void acpi_penalize_isa_irq(int irq, int active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | { |
Bjorn Helgaas | fa46d35 | 2008-08-01 15:58:17 -0600 | [diff] [blame] | 824 | if (irq >= 0 && irq < ARRAY_SIZE(acpi_irq_penalty)) { |
| 825 | if (active) |
| 826 | acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED; |
| 827 | else |
| 828 | acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING; |
| 829 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | /* |
| 833 | * Over-ride default table to reserve additional IRQs for use by ISA |
| 834 | * e.g. acpi_irq_isa=5 |
| 835 | * Useful for telling ACPI how not to interfere with your ISA sound card. |
| 836 | */ |
| 837 | static int __init acpi_irq_isa(char *str) |
| 838 | { |
| 839 | return acpi_irq_penalty_update(str, 1); |
| 840 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 841 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | __setup("acpi_irq_isa=", acpi_irq_isa); |
| 843 | |
| 844 | /* |
| 845 | * Over-ride default table to free additional IRQs for use by PCI |
| 846 | * e.g. acpi_irq_pci=7,15 |
| 847 | * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing. |
| 848 | */ |
| 849 | static int __init acpi_irq_pci(char *str) |
| 850 | { |
| 851 | return acpi_irq_penalty_update(str, 0); |
| 852 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | __setup("acpi_irq_pci=", acpi_irq_pci); |
| 855 | |
| 856 | static int __init acpi_irq_nobalance_set(char *str) |
| 857 | { |
| 858 | acpi_irq_balance = 0; |
| 859 | return 1; |
| 860 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | __setup("acpi_irq_nobalance", acpi_irq_nobalance_set); |
| 863 | |
Roel Kluin | 8a383ef | 2008-12-09 20:45:30 +0100 | [diff] [blame] | 864 | static int __init acpi_irq_balance_set(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | { |
| 866 | acpi_irq_balance = 1; |
| 867 | return 1; |
| 868 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 870 | __setup("acpi_irq_balance", acpi_irq_balance_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 872 | /* FIXME: we will remove this interface after all drivers call pci_disable_device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | static struct sysdev_class irqrouter_sysdev_class = { |
Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 874 | .name = "irqrouter", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 875 | .resume = irqrouter_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | }; |
| 877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | static struct sys_device device_irqrouter = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 879 | .id = 0, |
| 880 | .cls = &irqrouter_sysdev_class, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | }; |
| 882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | static int __init irqrouter_init_sysfs(void) |
| 884 | { |
| 885 | int error; |
| 886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | if (acpi_disabled || acpi_noirq) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 888 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | |
| 890 | error = sysdev_class_register(&irqrouter_sysdev_class); |
| 891 | if (!error) |
| 892 | error = sysdev_register(&device_irqrouter); |
| 893 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 894 | return error; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 895 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
| 897 | device_initcall(irqrouter_init_sysfs); |
| 898 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 899 | static int __init acpi_pci_link_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | if (acpi_noirq) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 902 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
Bjorn Helgaas | 3283625 | 2008-11-05 16:17:52 -0700 | [diff] [blame] | 904 | if (acpi_irq_balance == -1) { |
| 905 | /* no command line switch: enable balancing in IOAPIC mode */ |
| 906 | if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) |
| 907 | acpi_irq_balance = 1; |
| 908 | else |
| 909 | acpi_irq_balance = 0; |
| 910 | } |
| 911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 913 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 915 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | subsys_initcall(acpi_pci_link_init); |