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