Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * pci_root.c - ACPI PCI Root Bridge Driver ($Revision: 40 $) |
| 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 | * |
| 7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or (at |
| 12 | * your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 22 | * |
| 23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 24 | */ |
| 25 | |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/types.h> |
Taku Izumi | d0020f6 | 2012-09-18 15:21:31 +0900 | [diff] [blame] | 30 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/pm.h> |
Rafael J. Wysocki | b67ea76 | 2010-02-17 23:44:09 +0100 | [diff] [blame] | 32 | #include <linux/pm_runtime.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/pci.h> |
Andrew Patterson | 990a7ac | 2008-11-10 15:30:45 -0700 | [diff] [blame] | 34 | #include <linux/pci-acpi.h> |
Naga Chumbalkar | eca6731 | 2011-03-21 03:29:20 +0000 | [diff] [blame] | 35 | #include <linux/pci-aspm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/acpi.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <acpi/acpi_bus.h> |
| 39 | #include <acpi/acpi_drivers.h> |
Rafael J. Wysocki | 415e12b | 2011-01-07 00:55:09 +0100 | [diff] [blame] | 40 | #include <acpi/apei.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 42 | #define PREFIX "ACPI: " |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define _COMPONENT ACPI_PCI_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 45 | ACPI_MODULE_NAME("pci_root"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #define ACPI_PCI_ROOT_CLASS "pci_bridge" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge" |
Rafael J. Wysocki | 00c43b9 | 2013-01-30 14:27:33 +0100 | [diff] [blame^] | 48 | static int acpi_pci_root_add(struct acpi_device *device, |
| 49 | const struct acpi_device_id *not_used); |
| 50 | static void acpi_pci_root_remove(struct acpi_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Rafael J. Wysocki | 415e12b | 2011-01-07 00:55:09 +0100 | [diff] [blame] | 52 | #define ACPI_PCIE_REQ_SUPPORT (OSC_EXT_PCI_CONFIG_SUPPORT \ |
| 53 | | OSC_ACTIVE_STATE_PWR_SUPPORT \ |
| 54 | | OSC_CLOCK_PWR_CAPABILITY_SUPPORT \ |
| 55 | | OSC_MSI_SUPPORT) |
| 56 | |
Márton Németh | c97adf9 | 2010-01-10 17:15:36 +0100 | [diff] [blame] | 57 | static const struct acpi_device_id root_device_ids[] = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 58 | {"PNP0A03", 0}, |
| 59 | {"", 0}, |
| 60 | }; |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 61 | |
Rafael J. Wysocki | 00c43b9 | 2013-01-30 14:27:33 +0100 | [diff] [blame^] | 62 | static struct acpi_scan_handler pci_root_handler = { |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 63 | .ids = root_device_ids, |
Rafael J. Wysocki | 00c43b9 | 2013-01-30 14:27:33 +0100 | [diff] [blame^] | 64 | .attach = acpi_pci_root_add, |
| 65 | .detach = acpi_pci_root_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Taku Izumi | d0020f6 | 2012-09-18 15:21:31 +0900 | [diff] [blame] | 68 | /* Lock to protect both acpi_pci_roots and acpi_pci_drivers lists */ |
| 69 | static DEFINE_MUTEX(acpi_pci_root_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | static LIST_HEAD(acpi_pci_roots); |
Jiang Liu | 8ee5bdf | 2012-09-18 15:19:49 +0900 | [diff] [blame] | 71 | static LIST_HEAD(acpi_pci_drivers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 73 | static DEFINE_MUTEX(osc_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | int acpi_pci_register_driver(struct acpi_pci_driver *driver) |
| 76 | { |
| 77 | int n = 0; |
Bjorn Helgaas | c1aec83 | 2009-06-18 14:47:02 -0600 | [diff] [blame] | 78 | struct acpi_pci_root *root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Taku Izumi | d0020f6 | 2012-09-18 15:21:31 +0900 | [diff] [blame] | 80 | mutex_lock(&acpi_pci_root_lock); |
Jiang Liu | 8ee5bdf | 2012-09-18 15:19:49 +0900 | [diff] [blame] | 81 | list_add_tail(&driver->node, &acpi_pci_drivers); |
Taku Izumi | d0020f6 | 2012-09-18 15:21:31 +0900 | [diff] [blame] | 82 | if (driver->add) |
| 83 | list_for_each_entry(root, &acpi_pci_roots, node) { |
Taku Izumi | 55bfe3c | 2012-09-18 15:22:35 +0900 | [diff] [blame] | 84 | driver->add(root); |
Taku Izumi | d0020f6 | 2012-09-18 15:21:31 +0900 | [diff] [blame] | 85 | n++; |
| 86 | } |
| 87 | mutex_unlock(&acpi_pci_root_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | return n; |
| 90 | } |
| 91 | EXPORT_SYMBOL(acpi_pci_register_driver); |
| 92 | |
| 93 | void acpi_pci_unregister_driver(struct acpi_pci_driver *driver) |
| 94 | { |
Bjorn Helgaas | c1aec83 | 2009-06-18 14:47:02 -0600 | [diff] [blame] | 95 | struct acpi_pci_root *root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Taku Izumi | d0020f6 | 2012-09-18 15:21:31 +0900 | [diff] [blame] | 97 | mutex_lock(&acpi_pci_root_lock); |
Jiang Liu | 8ee5bdf | 2012-09-18 15:19:49 +0900 | [diff] [blame] | 98 | list_del(&driver->node); |
Taku Izumi | d0020f6 | 2012-09-18 15:21:31 +0900 | [diff] [blame] | 99 | if (driver->remove) |
| 100 | list_for_each_entry(root, &acpi_pci_roots, node) |
Taku Izumi | 55bfe3c | 2012-09-18 15:22:35 +0900 | [diff] [blame] | 101 | driver->remove(root); |
Taku Izumi | d0020f6 | 2012-09-18 15:21:31 +0900 | [diff] [blame] | 102 | mutex_unlock(&acpi_pci_root_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | EXPORT_SYMBOL(acpi_pci_unregister_driver); |
| 105 | |
Justin Chen | d91a007 | 2006-12-06 10:17:10 -0700 | [diff] [blame] | 106 | acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus) |
| 107 | { |
Bjorn Helgaas | c1aec83 | 2009-06-18 14:47:02 -0600 | [diff] [blame] | 108 | struct acpi_pci_root *root; |
Taku Izumi | 6507e6e | 2012-09-18 15:24:40 +0900 | [diff] [blame] | 109 | acpi_handle handle = NULL; |
Justin Chen | d91a007 | 2006-12-06 10:17:10 -0700 | [diff] [blame] | 110 | |
Taku Izumi | 6507e6e | 2012-09-18 15:24:40 +0900 | [diff] [blame] | 111 | mutex_lock(&acpi_pci_root_lock); |
Bjorn Helgaas | c1aec83 | 2009-06-18 14:47:02 -0600 | [diff] [blame] | 112 | list_for_each_entry(root, &acpi_pci_roots, node) |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 113 | if ((root->segment == (u16) seg) && |
Taku Izumi | 6507e6e | 2012-09-18 15:24:40 +0900 | [diff] [blame] | 114 | (root->secondary.start == (u16) bus)) { |
| 115 | handle = root->device->handle; |
| 116 | break; |
| 117 | } |
| 118 | mutex_unlock(&acpi_pci_root_lock); |
| 119 | return handle; |
Justin Chen | d91a007 | 2006-12-06 10:17:10 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle); |
| 123 | |
Alexander Chiang | 2755820 | 2009-06-10 19:55:14 +0000 | [diff] [blame] | 124 | /** |
| 125 | * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge |
| 126 | * @handle - the ACPI CA node in question. |
| 127 | * |
| 128 | * Note: we could make this API take a struct acpi_device * instead, but |
| 129 | * for now, it's more convenient to operate on an acpi_handle. |
| 130 | */ |
| 131 | int acpi_is_root_bridge(acpi_handle handle) |
| 132 | { |
| 133 | int ret; |
| 134 | struct acpi_device *device; |
| 135 | |
| 136 | ret = acpi_bus_get_device(handle, &device); |
| 137 | if (ret) |
| 138 | return 0; |
| 139 | |
| 140 | ret = acpi_match_device_ids(device, root_device_ids); |
| 141 | if (ret) |
| 142 | return 0; |
| 143 | else |
| 144 | return 1; |
| 145 | } |
| 146 | EXPORT_SYMBOL_GPL(acpi_is_root_bridge); |
| 147 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 151 | struct resource *res = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | struct acpi_resource_address64 address; |
| 153 | |
Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 154 | if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 && |
| 155 | resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 && |
| 156 | resource->type != ACPI_RESOURCE_TYPE_ADDRESS64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return AE_OK; |
| 158 | |
| 159 | acpi_resource_to_address64(resource, &address); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 160 | if ((address.address_length > 0) && |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 161 | (address.resource_type == ACPI_BUS_NUMBER_RANGE)) { |
| 162 | res->start = address.minimum; |
| 163 | res->end = address.minimum + address.address_length - 1; |
| 164 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | return AE_OK; |
| 167 | } |
| 168 | |
Bjorn Helgaas | f5eebbe | 2009-06-18 14:46:52 -0600 | [diff] [blame] | 169 | static acpi_status try_get_root_bridge_busnr(acpi_handle handle, |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 170 | struct resource *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
| 172 | acpi_status status; |
| 173 | |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 174 | res->start = -1; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | status = |
| 176 | acpi_walk_resources(handle, METHOD_NAME__CRS, |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 177 | get_root_bridge_busnr_callback, res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | if (ACPI_FAILURE(status)) |
| 179 | return status; |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 180 | if (res->start == -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | return AE_ERROR; |
| 182 | return AE_OK; |
| 183 | } |
| 184 | |
Shaohua Li | 3a9622d | 2009-10-29 11:04:50 +0800 | [diff] [blame] | 185 | static u8 pci_osc_uuid_str[] = "33DB4D5B-1FF7-401C-9657-7441C03DD766"; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 186 | |
| 187 | static acpi_status acpi_pci_run_osc(acpi_handle handle, |
| 188 | const u32 *capbuf, u32 *retval) |
| 189 | { |
Shaohua Li | 3a9622d | 2009-10-29 11:04:50 +0800 | [diff] [blame] | 190 | struct acpi_osc_context context = { |
| 191 | .uuid_str = pci_osc_uuid_str, |
| 192 | .rev = 1, |
| 193 | .cap.length = 12, |
| 194 | .cap.pointer = (void *)capbuf, |
| 195 | }; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 196 | acpi_status status; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 197 | |
Shaohua Li | 3a9622d | 2009-10-29 11:04:50 +0800 | [diff] [blame] | 198 | status = acpi_run_osc(handle, &context); |
| 199 | if (ACPI_SUCCESS(status)) { |
| 200 | *retval = *((u32 *)(context.ret.pointer + 8)); |
| 201 | kfree(context.ret.pointer); |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 202 | } |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 203 | return status; |
| 204 | } |
| 205 | |
Rafael J. Wysocki | ab8e895 | 2010-08-21 01:53:27 +0200 | [diff] [blame] | 206 | static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root, |
| 207 | u32 support, |
| 208 | u32 *control) |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 209 | { |
| 210 | acpi_status status; |
Rafael J. Wysocki | ab8e895 | 2010-08-21 01:53:27 +0200 | [diff] [blame] | 211 | u32 result, capbuf[3]; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 212 | |
Rafael J. Wysocki | ab8e895 | 2010-08-21 01:53:27 +0200 | [diff] [blame] | 213 | support &= OSC_PCI_SUPPORT_MASKS; |
| 214 | support |= root->osc_support_set; |
| 215 | |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 216 | capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE; |
Rafael J. Wysocki | ab8e895 | 2010-08-21 01:53:27 +0200 | [diff] [blame] | 217 | capbuf[OSC_SUPPORT_TYPE] = support; |
| 218 | if (control) { |
| 219 | *control &= OSC_PCI_CONTROL_MASKS; |
| 220 | capbuf[OSC_CONTROL_TYPE] = *control | root->osc_control_set; |
| 221 | } else { |
| 222 | /* Run _OSC query for all possible controls. */ |
| 223 | capbuf[OSC_CONTROL_TYPE] = OSC_PCI_CONTROL_MASKS; |
| 224 | } |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 225 | |
| 226 | status = acpi_pci_run_osc(root->device->handle, capbuf, &result); |
| 227 | if (ACPI_SUCCESS(status)) { |
Rafael J. Wysocki | ab8e895 | 2010-08-21 01:53:27 +0200 | [diff] [blame] | 228 | root->osc_support_set = support; |
Rafael J. Wysocki | 2b8fd91 | 2010-08-23 23:55:59 +0200 | [diff] [blame] | 229 | if (control) |
Rafael J. Wysocki | ab8e895 | 2010-08-21 01:53:27 +0200 | [diff] [blame] | 230 | *control = result; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 231 | } |
| 232 | return status; |
| 233 | } |
| 234 | |
| 235 | static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags) |
| 236 | { |
| 237 | acpi_status status; |
| 238 | acpi_handle tmp; |
| 239 | |
| 240 | status = acpi_get_handle(root->device->handle, "_OSC", &tmp); |
| 241 | if (ACPI_FAILURE(status)) |
| 242 | return status; |
| 243 | mutex_lock(&osc_lock); |
Rafael J. Wysocki | ab8e895 | 2010-08-21 01:53:27 +0200 | [diff] [blame] | 244 | status = acpi_pci_query_osc(root, flags, NULL); |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 245 | mutex_unlock(&osc_lock); |
| 246 | return status; |
| 247 | } |
| 248 | |
Alex Chiang | 76d56de | 2009-07-23 17:03:00 -0600 | [diff] [blame] | 249 | struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle) |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 250 | { |
| 251 | struct acpi_pci_root *root; |
Taku Izumi | cd4faf9 | 2012-09-18 15:23:23 +0900 | [diff] [blame] | 252 | struct acpi_device *device; |
Bjorn Helgaas | c1aec83 | 2009-06-18 14:47:02 -0600 | [diff] [blame] | 253 | |
Taku Izumi | cd4faf9 | 2012-09-18 15:23:23 +0900 | [diff] [blame] | 254 | if (acpi_bus_get_device(handle, &device) || |
| 255 | acpi_match_device_ids(device, root_device_ids)) |
| 256 | return NULL; |
| 257 | |
| 258 | root = acpi_driver_data(device); |
| 259 | |
| 260 | return root; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 261 | } |
Alex Chiang | 76d56de | 2009-07-23 17:03:00 -0600 | [diff] [blame] | 262 | EXPORT_SYMBOL_GPL(acpi_pci_find_root); |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 263 | |
Alexander Chiang | 2f7bbce | 2009-06-10 19:55:20 +0000 | [diff] [blame] | 264 | struct acpi_handle_node { |
| 265 | struct list_head node; |
| 266 | acpi_handle handle; |
| 267 | }; |
| 268 | |
| 269 | /** |
| 270 | * acpi_get_pci_dev - convert ACPI CA handle to struct pci_dev |
| 271 | * @handle: the handle in question |
| 272 | * |
| 273 | * Given an ACPI CA handle, the desired PCI device is located in the |
| 274 | * list of PCI devices. |
| 275 | * |
| 276 | * If the device is found, its reference count is increased and this |
| 277 | * function returns a pointer to its data structure. The caller must |
| 278 | * decrement the reference count by calling pci_dev_put(). |
| 279 | * If no device is found, %NULL is returned. |
| 280 | */ |
| 281 | struct pci_dev *acpi_get_pci_dev(acpi_handle handle) |
| 282 | { |
| 283 | int dev, fn; |
| 284 | unsigned long long adr; |
| 285 | acpi_status status; |
| 286 | acpi_handle phandle; |
| 287 | struct pci_bus *pbus; |
| 288 | struct pci_dev *pdev = NULL; |
| 289 | struct acpi_handle_node *node, *tmp; |
| 290 | struct acpi_pci_root *root; |
| 291 | LIST_HEAD(device_list); |
| 292 | |
| 293 | /* |
| 294 | * Walk up the ACPI CA namespace until we reach a PCI root bridge. |
| 295 | */ |
| 296 | phandle = handle; |
| 297 | while (!acpi_is_root_bridge(phandle)) { |
| 298 | node = kzalloc(sizeof(struct acpi_handle_node), GFP_KERNEL); |
| 299 | if (!node) |
| 300 | goto out; |
| 301 | |
| 302 | INIT_LIST_HEAD(&node->node); |
| 303 | node->handle = phandle; |
| 304 | list_add(&node->node, &device_list); |
| 305 | |
| 306 | status = acpi_get_parent(phandle, &phandle); |
| 307 | if (ACPI_FAILURE(status)) |
| 308 | goto out; |
| 309 | } |
| 310 | |
| 311 | root = acpi_pci_find_root(phandle); |
| 312 | if (!root) |
| 313 | goto out; |
| 314 | |
| 315 | pbus = root->bus; |
| 316 | |
| 317 | /* |
| 318 | * Now, walk back down the PCI device tree until we return to our |
| 319 | * original handle. Assumes that everything between the PCI root |
| 320 | * bridge and the device we're looking for must be a P2P bridge. |
| 321 | */ |
| 322 | list_for_each_entry(node, &device_list, node) { |
| 323 | acpi_handle hnd = node->handle; |
| 324 | status = acpi_evaluate_integer(hnd, "_ADR", NULL, &adr); |
| 325 | if (ACPI_FAILURE(status)) |
| 326 | goto out; |
| 327 | dev = (adr >> 16) & 0xffff; |
| 328 | fn = adr & 0xffff; |
| 329 | |
| 330 | pdev = pci_get_slot(pbus, PCI_DEVFN(dev, fn)); |
Troy Moure | 412af97 | 2009-06-25 17:05:35 -0600 | [diff] [blame] | 331 | if (!pdev || hnd == handle) |
Alexander Chiang | 2f7bbce | 2009-06-10 19:55:20 +0000 | [diff] [blame] | 332 | break; |
| 333 | |
| 334 | pbus = pdev->subordinate; |
| 335 | pci_dev_put(pdev); |
Rafael J. Wysocki | 497fb54 | 2009-10-13 01:01:57 +0200 | [diff] [blame] | 336 | |
| 337 | /* |
| 338 | * This function may be called for a non-PCI device that has a |
| 339 | * PCI parent (eg. a disk under a PCI SATA controller). In that |
| 340 | * case pdev->subordinate will be NULL for the parent. |
| 341 | */ |
| 342 | if (!pbus) { |
| 343 | dev_dbg(&pdev->dev, "Not a PCI-to-PCI bridge\n"); |
| 344 | pdev = NULL; |
| 345 | break; |
| 346 | } |
Alexander Chiang | 2f7bbce | 2009-06-10 19:55:20 +0000 | [diff] [blame] | 347 | } |
| 348 | out: |
| 349 | list_for_each_entry_safe(node, tmp, &device_list, node) |
| 350 | kfree(node); |
| 351 | |
| 352 | return pdev; |
| 353 | } |
| 354 | EXPORT_SYMBOL_GPL(acpi_get_pci_dev); |
| 355 | |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 356 | /** |
Rafael J. Wysocki | 75fb60f | 2010-08-23 23:53:11 +0200 | [diff] [blame] | 357 | * acpi_pci_osc_control_set - Request control of PCI root _OSC features. |
| 358 | * @handle: ACPI handle of a PCI root bridge (or PCIe Root Complex). |
| 359 | * @mask: Mask of _OSC bits to request control of, place to store control mask. |
| 360 | * @req: Mask of _OSC bits the control of is essential to the caller. |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 361 | * |
Rafael J. Wysocki | 75fb60f | 2010-08-23 23:53:11 +0200 | [diff] [blame] | 362 | * Run _OSC query for @mask and if that is successful, compare the returned |
| 363 | * mask of control bits with @req. If all of the @req bits are set in the |
| 364 | * returned mask, run _OSC request for it. |
| 365 | * |
| 366 | * The variable at the @mask address may be modified regardless of whether or |
| 367 | * not the function returns success. On success it will contain the mask of |
| 368 | * _OSC bits the BIOS has granted control of, but its contents are meaningless |
| 369 | * on failure. |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 370 | **/ |
Rafael J. Wysocki | 75fb60f | 2010-08-23 23:53:11 +0200 | [diff] [blame] | 371 | acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 *mask, u32 req) |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 372 | { |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 373 | struct acpi_pci_root *root; |
Rafael J. Wysocki | 75fb60f | 2010-08-23 23:53:11 +0200 | [diff] [blame] | 374 | acpi_status status; |
| 375 | u32 ctrl, capbuf[3]; |
| 376 | acpi_handle tmp; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 377 | |
Rafael J. Wysocki | 75fb60f | 2010-08-23 23:53:11 +0200 | [diff] [blame] | 378 | if (!mask) |
| 379 | return AE_BAD_PARAMETER; |
| 380 | |
| 381 | ctrl = *mask & OSC_PCI_CONTROL_MASKS; |
| 382 | if ((ctrl & req) != req) |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 383 | return AE_TYPE; |
| 384 | |
| 385 | root = acpi_pci_find_root(handle); |
| 386 | if (!root) |
| 387 | return AE_NOT_EXIST; |
| 388 | |
Rafael J. Wysocki | b879dc4 | 2010-08-21 01:52:37 +0200 | [diff] [blame] | 389 | status = acpi_get_handle(handle, "_OSC", &tmp); |
| 390 | if (ACPI_FAILURE(status)) |
| 391 | return status; |
| 392 | |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 393 | mutex_lock(&osc_lock); |
Rafael J. Wysocki | 75fb60f | 2010-08-23 23:53:11 +0200 | [diff] [blame] | 394 | |
| 395 | *mask = ctrl | root->osc_control_set; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 396 | /* No need to evaluate _OSC if the control was already granted. */ |
Rafael J. Wysocki | 75fb60f | 2010-08-23 23:53:11 +0200 | [diff] [blame] | 397 | if ((root->osc_control_set & ctrl) == ctrl) |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 398 | goto out; |
| 399 | |
Rafael J. Wysocki | 75fb60f | 2010-08-23 23:53:11 +0200 | [diff] [blame] | 400 | /* Need to check the available controls bits before requesting them. */ |
| 401 | while (*mask) { |
| 402 | status = acpi_pci_query_osc(root, root->osc_support_set, mask); |
| 403 | if (ACPI_FAILURE(status)) |
| 404 | goto out; |
| 405 | if (ctrl == *mask) |
| 406 | break; |
| 407 | ctrl = *mask; |
| 408 | } |
Rafael J. Wysocki | 2b8fd91 | 2010-08-23 23:55:59 +0200 | [diff] [blame] | 409 | |
Rafael J. Wysocki | 75fb60f | 2010-08-23 23:53:11 +0200 | [diff] [blame] | 410 | if ((ctrl & req) != req) { |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 411 | status = AE_SUPPORT; |
| 412 | goto out; |
| 413 | } |
| 414 | |
| 415 | capbuf[OSC_QUERY_TYPE] = 0; |
| 416 | capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set; |
Rafael J. Wysocki | 75fb60f | 2010-08-23 23:53:11 +0200 | [diff] [blame] | 417 | capbuf[OSC_CONTROL_TYPE] = ctrl; |
| 418 | status = acpi_pci_run_osc(handle, capbuf, mask); |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 419 | if (ACPI_SUCCESS(status)) |
Rafael J. Wysocki | 75fb60f | 2010-08-23 23:53:11 +0200 | [diff] [blame] | 420 | root->osc_control_set = *mask; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 421 | out: |
| 422 | mutex_unlock(&osc_lock); |
| 423 | return status; |
| 424 | } |
Kenji Kaneshige | 9f5404d | 2009-02-09 16:00:04 +0900 | [diff] [blame] | 425 | EXPORT_SYMBOL(acpi_pci_osc_control_set); |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 426 | |
Rafael J. Wysocki | 00c43b9 | 2013-01-30 14:27:33 +0100 | [diff] [blame^] | 427 | static int acpi_pci_root_add(struct acpi_device *device, |
| 428 | const struct acpi_device_id *not_used) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | { |
Bjorn Helgaas | f5eebbe | 2009-06-18 14:46:52 -0600 | [diff] [blame] | 430 | unsigned long long segment, bus; |
| 431 | acpi_status status; |
| 432 | int result; |
| 433 | struct acpi_pci_root *root; |
| 434 | acpi_handle handle; |
Rafael J. Wysocki | 47525cd | 2012-12-21 00:36:45 +0100 | [diff] [blame] | 435 | struct acpi_pci_driver *driver; |
Andrew Patterson | 0ef5f8f | 2008-11-10 15:30:50 -0700 | [diff] [blame] | 436 | u32 flags, base_flags; |
Taku Izumi | 8c33f51 | 2012-10-30 15:27:13 +0900 | [diff] [blame] | 437 | bool is_osc_granted = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 439 | root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL); |
| 440 | if (!root) |
| 441 | return -ENOMEM; |
| 442 | |
Bjorn Helgaas | f5eebbe | 2009-06-18 14:46:52 -0600 | [diff] [blame] | 443 | segment = 0; |
| 444 | status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL, |
| 445 | &segment); |
| 446 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
| 447 | printk(KERN_ERR PREFIX "can't evaluate _SEG\n"); |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 448 | result = -ENODEV; |
| 449 | goto end; |
Bjorn Helgaas | f5eebbe | 2009-06-18 14:46:52 -0600 | [diff] [blame] | 450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Bjorn Helgaas | f5eebbe | 2009-06-18 14:46:52 -0600 | [diff] [blame] | 452 | /* Check _CRS first, then _BBN. If no _BBN, default to zero. */ |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 453 | root->secondary.flags = IORESOURCE_BUS; |
| 454 | status = try_get_root_bridge_busnr(device->handle, &root->secondary); |
Bjorn Helgaas | f5eebbe | 2009-06-18 14:46:52 -0600 | [diff] [blame] | 455 | if (ACPI_FAILURE(status)) { |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 456 | /* |
| 457 | * We need both the start and end of the downstream bus range |
| 458 | * to interpret _CBA (MMCONFIG base address), so it really is |
| 459 | * supposed to be in _CRS. If we don't find it there, all we |
| 460 | * can do is assume [_BBN-0xFF] or [0-0xFF]. |
| 461 | */ |
| 462 | root->secondary.end = 0xFF; |
| 463 | printk(KERN_WARNING FW_BUG PREFIX |
| 464 | "no secondary bus range in _CRS\n"); |
Jon Mason | e545b55 | 2011-06-19 18:51:37 -0500 | [diff] [blame] | 465 | status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN, |
| 466 | NULL, &bus); |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 467 | if (ACPI_SUCCESS(status)) |
| 468 | root->secondary.start = bus; |
| 469 | else if (status == AE_NOT_FOUND) |
| 470 | root->secondary.start = 0; |
| 471 | else { |
| 472 | printk(KERN_ERR PREFIX "can't evaluate _BBN\n"); |
| 473 | result = -ENODEV; |
| 474 | goto end; |
Bjorn Helgaas | f5eebbe | 2009-06-18 14:46:52 -0600 | [diff] [blame] | 475 | } |
| 476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Bjorn Helgaas | f5eebbe | 2009-06-18 14:46:52 -0600 | [diff] [blame] | 478 | INIT_LIST_HEAD(&root->node); |
Patrick Mochel | 32917e5 | 2006-05-19 16:54:39 -0400 | [diff] [blame] | 479 | root->device = device; |
Bjorn Helgaas | 0705495 | 2009-06-18 14:47:07 -0600 | [diff] [blame] | 480 | root->segment = segment & 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME); |
| 482 | strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS); |
Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 483 | device->driver_data = root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Bjorn Helgaas | d4761ba | 2012-10-30 15:24:50 +0900 | [diff] [blame] | 485 | printk(KERN_INFO PREFIX "%s [%s] (domain %04x %pR)\n", |
| 486 | acpi_device_name(device), acpi_device_bid(device), |
| 487 | root->segment, &root->secondary); |
| 488 | |
| 489 | /* |
| 490 | * PCI Routing Table |
| 491 | * ----------------- |
| 492 | * Evaluate and parse _PRT, if exists. |
| 493 | */ |
| 494 | status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); |
| 495 | if (ACPI_SUCCESS(status)) |
| 496 | result = acpi_pci_irq_add_prt(device->handle, root->segment, |
| 497 | root->secondary.start); |
| 498 | |
Jiang Liu | f4b57a3 | 2012-06-22 14:55:16 +0800 | [diff] [blame] | 499 | root->mcfg_addr = acpi_pci_root_get_mcfg_addr(device->handle); |
| 500 | |
Andrew Patterson | 990a7ac | 2008-11-10 15:30:45 -0700 | [diff] [blame] | 501 | /* |
| 502 | * All supported architectures that use ACPI have support for |
| 503 | * PCI domains, so we indicate this in _OSC support capabilities. |
| 504 | */ |
Andrew Patterson | 0ef5f8f | 2008-11-10 15:30:50 -0700 | [diff] [blame] | 505 | flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT; |
Kenji Kaneshige | 63f10f0 | 2009-02-09 15:59:29 +0900 | [diff] [blame] | 506 | acpi_pci_osc_support(root, flags); |
Andrew Patterson | 990a7ac | 2008-11-10 15:30:45 -0700 | [diff] [blame] | 507 | |
Taku Izumi | 8c33f51 | 2012-10-30 15:27:13 +0900 | [diff] [blame] | 508 | /* Indicate support for various _OSC capabilities. */ |
| 509 | if (pci_ext_cfg_avail()) |
| 510 | flags |= OSC_EXT_PCI_CONFIG_SUPPORT; |
| 511 | if (pcie_aspm_support_enabled()) { |
| 512 | flags |= OSC_ACTIVE_STATE_PWR_SUPPORT | |
| 513 | OSC_CLOCK_PWR_CAPABILITY_SUPPORT; |
| 514 | } |
| 515 | if (pci_msi_enabled()) |
| 516 | flags |= OSC_MSI_SUPPORT; |
| 517 | if (flags != base_flags) { |
| 518 | status = acpi_pci_osc_support(root, flags); |
| 519 | if (ACPI_FAILURE(status)) { |
| 520 | dev_info(&device->dev, "ACPI _OSC support " |
| 521 | "notification failed, disabling PCIe ASPM\n"); |
| 522 | pcie_no_aspm(); |
| 523 | flags = base_flags; |
| 524 | } |
| 525 | } |
| 526 | if (!pcie_ports_disabled |
| 527 | && (flags & ACPI_PCIE_REQ_SUPPORT) == ACPI_PCIE_REQ_SUPPORT) { |
| 528 | flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL |
| 529 | | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL |
| 530 | | OSC_PCI_EXPRESS_PME_CONTROL; |
| 531 | |
| 532 | if (pci_aer_available()) { |
| 533 | if (aer_acpi_firmware_first()) |
| 534 | dev_dbg(&device->dev, |
| 535 | "PCIe errors handled by BIOS.\n"); |
| 536 | else |
| 537 | flags |= OSC_PCI_EXPRESS_AER_CONTROL; |
| 538 | } |
| 539 | |
| 540 | dev_info(&device->dev, |
| 541 | "Requesting ACPI _OSC control (0x%02x)\n", flags); |
| 542 | |
| 543 | status = acpi_pci_osc_control_set(device->handle, &flags, |
| 544 | OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); |
| 545 | if (ACPI_SUCCESS(status)) { |
| 546 | is_osc_granted = true; |
| 547 | dev_info(&device->dev, |
| 548 | "ACPI _OSC control (0x%02x) granted\n", flags); |
| 549 | } else { |
| 550 | is_osc_granted = false; |
| 551 | dev_info(&device->dev, |
| 552 | "ACPI _OSC request failed (%s), " |
| 553 | "returned control mask: 0x%02x\n", |
| 554 | acpi_format_exception(status), flags); |
| 555 | } |
| 556 | } else { |
| 557 | dev_info(&device->dev, |
| 558 | "Unable to request _OSC control " |
| 559 | "(_OSC support mask: 0x%02x)\n", flags); |
| 560 | } |
| 561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | /* |
| 563 | * TBD: Need PCI interface for enumeration/configuration of roots. |
| 564 | */ |
| 565 | |
Taku Izumi | 6507e6e | 2012-09-18 15:24:40 +0900 | [diff] [blame] | 566 | mutex_lock(&acpi_pci_root_lock); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 567 | list_add_tail(&root->node, &acpi_pci_roots); |
Taku Izumi | 6507e6e | 2012-09-18 15:24:40 +0900 | [diff] [blame] | 568 | mutex_unlock(&acpi_pci_root_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | /* |
| 571 | * Scan the Root Bridge |
| 572 | * -------------------- |
| 573 | * Must do this prior to any attempt to bind the root device, as the |
| 574 | * PCI namespace does not get created until this call is made (and |
| 575 | * thus the root bridge's pci_dev does not exist). |
| 576 | */ |
Bjorn Helgaas | 5728377 | 2010-03-11 12:20:11 -0700 | [diff] [blame] | 577 | root->bus = pci_acpi_scan_root(root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | if (!root->bus) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 579 | printk(KERN_ERR PREFIX |
| 580 | "Bus %04x:%02x not present in PCI namespace\n", |
Bjorn Helgaas | 6ad9551 | 2010-03-11 12:20:06 -0700 | [diff] [blame] | 581 | root->segment, (unsigned int)root->secondary.start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | result = -ENODEV; |
Taku Izumi | 6507e6e | 2012-09-18 15:24:40 +0900 | [diff] [blame] | 583 | goto out_del_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Taku Izumi | 8c33f51 | 2012-10-30 15:27:13 +0900 | [diff] [blame] | 586 | /* ASPM setting */ |
| 587 | if (is_osc_granted) { |
| 588 | if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM) |
| 589 | pcie_clear_aspm(root->bus); |
Rafael J. Wysocki | a246670 | 2011-04-30 00:21:38 +0200 | [diff] [blame] | 590 | } else { |
Taku Izumi | 8c33f51 | 2012-10-30 15:27:13 +0900 | [diff] [blame] | 591 | pr_info("ACPI _OSC control for PCIe not granted, " |
| 592 | "disabling ASPM\n"); |
| 593 | pcie_no_aspm(); |
Rafael J. Wysocki | 415e12b | 2011-01-07 00:55:09 +0100 | [diff] [blame] | 594 | } |
| 595 | |
Rafael J. Wysocki | b67ea76 | 2010-02-17 23:44:09 +0100 | [diff] [blame] | 596 | pci_acpi_add_bus_pm_notifier(device, root->bus); |
| 597 | if (device->wakeup.flags.run_wake) |
| 598 | device_set_run_wake(root->bus->bridge, true); |
| 599 | |
Yinghai Lu | 62a08c5 | 2012-10-30 14:31:32 -0600 | [diff] [blame] | 600 | if (system_state != SYSTEM_BOOTING) |
| 601 | pci_assign_unassigned_bus_resources(root->bus); |
| 602 | |
Taku Izumi | d0020f6 | 2012-09-18 15:21:31 +0900 | [diff] [blame] | 603 | mutex_lock(&acpi_pci_root_lock); |
Jiang Liu | c8e9afb | 2012-09-18 15:20:34 +0900 | [diff] [blame] | 604 | list_for_each_entry(driver, &acpi_pci_drivers, node) |
| 605 | if (driver->add) |
Taku Izumi | 55bfe3c | 2012-09-18 15:22:35 +0900 | [diff] [blame] | 606 | driver->add(root); |
Taku Izumi | d0020f6 | 2012-09-18 15:21:31 +0900 | [diff] [blame] | 607 | mutex_unlock(&acpi_pci_root_lock); |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 608 | |
Yinghai Lu | 62a08c5 | 2012-10-30 14:31:32 -0600 | [diff] [blame] | 609 | /* need to after hot-added ioapic is registered */ |
| 610 | if (system_state != SYSTEM_BOOTING) |
| 611 | pci_enable_bridges(root->bus); |
| 612 | |
Bjorn Helgaas | caf420c | 2009-06-18 14:46:57 -0600 | [diff] [blame] | 613 | pci_bus_add_devices(root->bus); |
Rafael J. Wysocki | 00c43b9 | 2013-01-30 14:27:33 +0100 | [diff] [blame^] | 614 | return 1; |
Rafael J. Wysocki | 47525cd | 2012-12-21 00:36:45 +0100 | [diff] [blame] | 615 | |
| 616 | out_del_root: |
| 617 | mutex_lock(&acpi_pci_root_lock); |
| 618 | list_del(&root->node); |
| 619 | mutex_unlock(&acpi_pci_root_lock); |
| 620 | |
| 621 | acpi_pci_irq_del_prt(root->segment, root->secondary.start); |
| 622 | end: |
| 623 | kfree(root); |
| 624 | return result; |
Rajesh Shah | c431ada | 2005-04-28 00:25:45 -0700 | [diff] [blame] | 625 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Rafael J. Wysocki | 00c43b9 | 2013-01-30 14:27:33 +0100 | [diff] [blame^] | 627 | static void acpi_pci_root_remove(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | { |
Yinghai Lu | 13b6a91 | 2012-10-30 14:31:48 -0600 | [diff] [blame] | 629 | acpi_status status; |
| 630 | acpi_handle handle; |
Bjorn Helgaas | caf420c | 2009-06-18 14:46:57 -0600 | [diff] [blame] | 631 | struct acpi_pci_root *root = acpi_driver_data(device); |
Jiang Liu | c8e9afb | 2012-09-18 15:20:34 +0900 | [diff] [blame] | 632 | struct acpi_pci_driver *driver; |
| 633 | |
Yinghai Lu | 9738a1f | 2012-10-30 14:31:43 -0600 | [diff] [blame] | 634 | pci_stop_root_bus(root->bus); |
| 635 | |
Taku Izumi | d0020f6 | 2012-09-18 15:21:31 +0900 | [diff] [blame] | 636 | mutex_lock(&acpi_pci_root_lock); |
Yinghai Lu | f426cef | 2012-10-30 14:31:52 -0600 | [diff] [blame] | 637 | list_for_each_entry_reverse(driver, &acpi_pci_drivers, node) |
Jiang Liu | c8e9afb | 2012-09-18 15:20:34 +0900 | [diff] [blame] | 638 | if (driver->remove) |
Taku Izumi | 55bfe3c | 2012-09-18 15:22:35 +0900 | [diff] [blame] | 639 | driver->remove(root); |
Yinghai Lu | 9738a1f | 2012-10-30 14:31:43 -0600 | [diff] [blame] | 640 | mutex_unlock(&acpi_pci_root_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Rafael J. Wysocki | b67ea76 | 2010-02-17 23:44:09 +0100 | [diff] [blame] | 642 | device_set_run_wake(root->bus->bridge, false); |
| 643 | pci_acpi_remove_bus_pm_notifier(device); |
| 644 | |
Yinghai Lu | 13b6a91 | 2012-10-30 14:31:48 -0600 | [diff] [blame] | 645 | status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); |
| 646 | if (ACPI_SUCCESS(status)) |
Bjorn Helgaas | 79c4412 | 2012-10-30 15:24:06 +0900 | [diff] [blame] | 647 | acpi_pci_irq_del_prt(root->segment, root->secondary.start); |
Yinghai Lu | 13b6a91 | 2012-10-30 14:31:48 -0600 | [diff] [blame] | 648 | |
Yinghai Lu | 9738a1f | 2012-10-30 14:31:43 -0600 | [diff] [blame] | 649 | pci_remove_root_bus(root->bus); |
| 650 | |
| 651 | mutex_lock(&acpi_pci_root_lock); |
Taku Izumi | 6507e6e | 2012-09-18 15:24:40 +0900 | [diff] [blame] | 652 | list_del(&root->node); |
| 653 | mutex_unlock(&acpi_pci_root_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | kfree(root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Rafael J. Wysocki | 00c43b9 | 2013-01-30 14:27:33 +0100 | [diff] [blame^] | 657 | void __init acpi_pci_root_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | { |
Rafael J. Wysocki | d3072e6 | 2011-01-16 20:44:22 +0100 | [diff] [blame] | 659 | acpi_hest_init(); |
| 660 | |
Rafael J. Wysocki | 00c43b9 | 2013-01-30 14:27:33 +0100 | [diff] [blame^] | 661 | if (!acpi_pci_disabled) { |
| 662 | pci_acpi_crs_quirks(); |
| 663 | acpi_scan_add_handler(&pci_root_handler); |
| 664 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |