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