Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ACPI PCI HotPlug glue functions to ACPI CA subsystem |
| 3 | * |
| 4 | * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com) |
| 5 | * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com) |
| 6 | * Copyright (C) 2002,2003 NEC Corporation |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 7 | * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com) |
| 8 | * Copyright (C) 2003-2005 Hewlett Packard |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 9 | * Copyright (C) 2005 Rajesh Shah (rajesh.shah@intel.com) |
| 10 | * Copyright (C) 2005 Intel Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | * All rights reserved. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or (at |
| 17 | * your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, but |
| 20 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 22 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 23 | * details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License |
| 26 | * along with this program; if not, write to the Free Software |
| 27 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 28 | * |
Kristen Carlson Accardi | 998be20 | 2006-07-26 10:52:33 -0700 | [diff] [blame] | 29 | * Send feedback to <kristen.c.accardi@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * |
| 31 | */ |
| 32 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 33 | /* |
| 34 | * Lifetime rules for pci_dev: |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 35 | * - The one in acpiphp_bridge has its refcount elevated by pci_get_slot() |
| 36 | * when the bridge is scanned and it loses a refcount when the bridge |
| 37 | * is removed. |
Alex Chiang | 5d4a4b2 | 2009-03-30 10:50:14 -0600 | [diff] [blame] | 38 | * - When a P2P bridge is present, we elevate the refcount on the subordinate |
| 39 | * bus. It loses the refcount when the the driver unloads. |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 40 | */ |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/init.h> |
| 43 | #include <linux/module.h> |
| 44 | |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/pci.h> |
Greg Kroah-Hartman | 7a54f25 | 2006-10-13 20:05:19 -0700 | [diff] [blame] | 47 | #include <linux/pci_hotplug.h> |
Kenji Kaneshige | e8c331e | 2008-12-17 12:09:12 +0900 | [diff] [blame] | 48 | #include <linux/pci-acpi.h> |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 49 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 50 | #include <linux/slab.h> |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 51 | #include <linux/acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | #include "../pci.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include "acpiphp.h" |
| 55 | |
| 56 | static LIST_HEAD(bridge_list); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 57 | static DEFINE_MUTEX(bridge_mutex); |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 58 | static DEFINE_MUTEX(acpiphp_context_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | #define MY_NAME "acpiphp_glue" |
| 61 | |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 62 | static void handle_hotplug_event(acpi_handle handle, u32 type, void *data); |
Kristen Accardi | 8e5dce3 | 2005-10-18 17:21:40 -0700 | [diff] [blame] | 63 | static void acpiphp_sanitize_bus(struct pci_bus *bus); |
Bjorn Helgaas | fca6825 | 2009-09-14 16:35:10 -0600 | [diff] [blame] | 64 | static void acpiphp_set_hpp_values(struct pci_bus *bus); |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 65 | static void hotplug_event(acpi_handle handle, u32 type, void *data); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 66 | static void free_bridge(struct kref *kref); |
Kristen Accardi | 8e5dce3 | 2005-10-18 17:21:40 -0700 | [diff] [blame] | 67 | |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 68 | static void acpiphp_context_handler(acpi_handle handle, void *context) |
| 69 | { |
| 70 | /* Intentionally empty. */ |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * acpiphp_init_context - Create hotplug context and grab a reference to it. |
| 75 | * @handle: ACPI object handle to create the context for. |
| 76 | * |
| 77 | * Call under acpiphp_context_lock. |
| 78 | */ |
| 79 | static struct acpiphp_context *acpiphp_init_context(acpi_handle handle) |
| 80 | { |
| 81 | struct acpiphp_context *context; |
| 82 | acpi_status status; |
| 83 | |
| 84 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 85 | if (!context) |
| 86 | return NULL; |
| 87 | |
| 88 | context->handle = handle; |
| 89 | context->refcount = 1; |
| 90 | status = acpi_attach_data(handle, acpiphp_context_handler, context); |
| 91 | if (ACPI_FAILURE(status)) { |
| 92 | kfree(context); |
| 93 | return NULL; |
| 94 | } |
| 95 | return context; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * acpiphp_get_context - Get hotplug context and grab a reference to it. |
| 100 | * @handle: ACPI object handle to get the context for. |
| 101 | * |
| 102 | * Call under acpiphp_context_lock. |
| 103 | */ |
| 104 | static struct acpiphp_context *acpiphp_get_context(acpi_handle handle) |
| 105 | { |
| 106 | struct acpiphp_context *context = NULL; |
| 107 | acpi_status status; |
| 108 | void *data; |
| 109 | |
| 110 | status = acpi_get_data(handle, acpiphp_context_handler, &data); |
| 111 | if (ACPI_SUCCESS(status)) { |
| 112 | context = data; |
| 113 | context->refcount++; |
| 114 | } |
| 115 | return context; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * acpiphp_put_context - Drop a reference to ACPI hotplug context. |
| 120 | * @handle: ACPI object handle to put the context for. |
| 121 | * |
| 122 | * The context object is removed if there are no more references to it. |
| 123 | * |
| 124 | * Call under acpiphp_context_lock. |
| 125 | */ |
| 126 | static void acpiphp_put_context(struct acpiphp_context *context) |
| 127 | { |
| 128 | if (--context->refcount) |
| 129 | return; |
| 130 | |
Rafael J. Wysocki | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 131 | WARN_ON(context->bridge); |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 132 | acpi_detach_data(context->handle, acpiphp_context_handler); |
| 133 | kfree(context); |
| 134 | } |
| 135 | |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 136 | static inline void get_bridge(struct acpiphp_bridge *bridge) |
| 137 | { |
| 138 | kref_get(&bridge->ref); |
| 139 | } |
| 140 | |
| 141 | static inline void put_bridge(struct acpiphp_bridge *bridge) |
| 142 | { |
| 143 | kref_put(&bridge->ref, free_bridge); |
| 144 | } |
| 145 | |
| 146 | static void free_bridge(struct kref *kref) |
| 147 | { |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 148 | struct acpiphp_context *context; |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 149 | struct acpiphp_bridge *bridge; |
| 150 | struct acpiphp_slot *slot, *next; |
| 151 | struct acpiphp_func *func, *tmp; |
| 152 | |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 153 | mutex_lock(&acpiphp_context_lock); |
| 154 | |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 155 | bridge = container_of(kref, struct acpiphp_bridge, ref); |
| 156 | |
| 157 | list_for_each_entry_safe(slot, next, &bridge->slots, node) { |
Rafael J. Wysocki | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 158 | list_for_each_entry_safe(func, tmp, &slot->funcs, sibling) |
| 159 | acpiphp_put_context(func_to_context(func)); |
| 160 | |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 161 | kfree(slot); |
| 162 | } |
| 163 | |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 164 | context = bridge->context; |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 165 | /* Root bridges will not have hotplug context. */ |
| 166 | if (context) { |
| 167 | /* Release the reference taken by acpiphp_enumerate_slots(). */ |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 168 | put_bridge(context->func.parent); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 169 | context->bridge = NULL; |
| 170 | acpiphp_put_context(context); |
| 171 | } |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 172 | |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 173 | put_device(&bridge->pci_bus->dev); |
| 174 | pci_dev_put(bridge->pci_dev); |
| 175 | kfree(bridge); |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 176 | |
| 177 | mutex_unlock(&acpiphp_context_lock); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 180 | /* |
| 181 | * the _DCK method can do funny things... and sometimes not |
| 182 | * hah-hah funny. |
| 183 | * |
| 184 | * TBD - figure out a way to only call fixups for |
| 185 | * systems that require them. |
| 186 | */ |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 187 | static void post_dock_fixups(acpi_handle not_used, u32 event, void *data) |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 188 | { |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 189 | struct acpiphp_context *context = data; |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 190 | struct pci_bus *bus = context->func.slot->bus; |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 191 | u32 buses; |
| 192 | |
| 193 | if (!bus->self) |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 194 | return; |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 195 | |
| 196 | /* fixup bad _DCK function that rewrites |
| 197 | * secondary bridge on slot |
| 198 | */ |
| 199 | pci_read_config_dword(bus->self, |
| 200 | PCI_PRIMARY_BUS, |
| 201 | &buses); |
| 202 | |
Yinghai Lu | b918c62 | 2012-05-17 18:51:11 -0700 | [diff] [blame] | 203 | if (((buses >> 8) & 0xff) != bus->busn_res.start) { |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 204 | buses = (buses & 0xff000000) |
Alex Chiang | 2a9d352 | 2008-12-11 11:17:55 -0700 | [diff] [blame] | 205 | | ((unsigned int)(bus->primary) << 0) |
Yinghai Lu | b918c62 | 2012-05-17 18:51:11 -0700 | [diff] [blame] | 206 | | ((unsigned int)(bus->busn_res.start) << 8) |
| 207 | | ((unsigned int)(bus->busn_res.end) << 16); |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 208 | pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses); |
| 209 | } |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | |
Vasiliy Kulikov | 9c8b04b | 2011-06-25 21:07:52 +0400 | [diff] [blame] | 213 | static const struct acpi_dock_ops acpiphp_dock_ops = { |
Rafael J. Wysocki | f09ce74 | 2013-07-05 03:03:25 +0200 | [diff] [blame] | 214 | .fixup = post_dock_fixups, |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 215 | .handler = hotplug_event, |
Shaohua Li | 1253f7a | 2008-08-28 10:06:16 +0800 | [diff] [blame] | 216 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Jiang Liu | 5ba113f | 2012-08-22 23:16:45 +0800 | [diff] [blame] | 218 | /* Check whether the PCI device is managed by native PCIe hotplug driver */ |
| 219 | static bool device_is_managed_by_native_pciehp(struct pci_dev *pdev) |
| 220 | { |
| 221 | u32 reg32; |
| 222 | acpi_handle tmp; |
| 223 | struct acpi_pci_root *root; |
| 224 | |
| 225 | /* Check whether the PCIe port supports native PCIe hotplug */ |
| 226 | if (pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, ®32)) |
| 227 | return false; |
| 228 | if (!(reg32 & PCI_EXP_SLTCAP_HPC)) |
| 229 | return false; |
| 230 | |
| 231 | /* |
| 232 | * Check whether native PCIe hotplug has been enabled for |
| 233 | * this PCIe hierarchy. |
| 234 | */ |
| 235 | tmp = acpi_find_root_bridge_handle(pdev); |
| 236 | if (!tmp) |
| 237 | return false; |
| 238 | root = acpi_pci_find_root(tmp); |
| 239 | if (!root) |
| 240 | return false; |
| 241 | if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL)) |
| 242 | return false; |
| 243 | |
| 244 | return true; |
| 245 | } |
| 246 | |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 247 | static void acpiphp_dock_init(void *data) |
| 248 | { |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 249 | struct acpiphp_context *context = data; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 250 | |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 251 | get_bridge(context->func.parent); |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static void acpiphp_dock_release(void *data) |
| 255 | { |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 256 | struct acpiphp_context *context = data; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 257 | |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 258 | put_bridge(context->func.parent); |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 259 | } |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | /* callback routine to register each ACPI PCI slot object */ |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 262 | static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, |
| 263 | void **rv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 265 | struct acpiphp_bridge *bridge = data; |
| 266 | struct acpiphp_context *context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | struct acpiphp_slot *slot; |
| 268 | struct acpiphp_func *newfunc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | acpi_status status = AE_OK; |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 270 | unsigned long long adr; |
| 271 | int device, function; |
Kenji Kaneshige | e8c331e | 2008-12-17 12:09:12 +0900 | [diff] [blame] | 272 | struct pci_bus *pbus = bridge->pci_bus; |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 273 | struct pci_dev *pdev = bridge->pci_dev; |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 274 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 276 | if (pdev && device_is_managed_by_native_pciehp(pdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | return AE_OK; |
| 278 | |
Bjorn Helgaas | dfb117b | 2012-06-20 16:18:29 -0600 | [diff] [blame] | 279 | status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr); |
| 280 | if (ACPI_FAILURE(status)) { |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 281 | acpi_handle_warn(handle, "can't evaluate _ADR (%#x)\n", status); |
Bjorn Helgaas | dfb117b | 2012-06-20 16:18:29 -0600 | [diff] [blame] | 282 | return AE_OK; |
| 283 | } |
| 284 | |
| 285 | device = (adr >> 16) & 0xffff; |
| 286 | function = adr & 0xffff; |
| 287 | |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 288 | mutex_lock(&acpiphp_context_lock); |
| 289 | context = acpiphp_init_context(handle); |
| 290 | if (!context) { |
| 291 | mutex_unlock(&acpiphp_context_lock); |
| 292 | acpi_handle_err(handle, "No hotplug context\n"); |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 293 | return AE_NOT_EXIST; |
| 294 | } |
Rafael J. Wysocki | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 295 | newfunc = &context->func; |
Rafael J. Wysocki | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 296 | newfunc->function = function; |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 297 | newfunc->parent = bridge; |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 298 | mutex_unlock(&acpiphp_context_lock); |
| 299 | |
Jiang Liu | ecd046d | 2013-06-29 00:24:43 +0800 | [diff] [blame] | 300 | if (acpi_has_method(handle, "_EJ0")) |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 301 | newfunc->flags = FUNC_HAS_EJ0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
Jiang Liu | ecd046d | 2013-06-29 00:24:43 +0800 | [diff] [blame] | 303 | if (acpi_has_method(handle, "_STA")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | newfunc->flags |= FUNC_HAS_STA; |
| 305 | |
Jiang Liu | ecd046d | 2013-06-29 00:24:43 +0800 | [diff] [blame] | 306 | if (acpi_has_method(handle, "_PS0")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | newfunc->flags |= FUNC_HAS_PS0; |
| 308 | |
Jiang Liu | ecd046d | 2013-06-29 00:24:43 +0800 | [diff] [blame] | 309 | if (acpi_has_method(handle, "_PS3")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | newfunc->flags |= FUNC_HAS_PS3; |
| 311 | |
Jiang Liu | ecd046d | 2013-06-29 00:24:43 +0800 | [diff] [blame] | 312 | if (acpi_has_method(handle, "_DCK")) |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 313 | newfunc->flags |= FUNC_HAS_DCK; |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | /* search for objects that share the same slot */ |
Yijing Wang | ad41dd9 | 2013-04-12 05:44:27 +0000 | [diff] [blame] | 316 | list_for_each_entry(slot, &bridge->slots, node) |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 317 | if (slot->device == device) |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 318 | goto slot_found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 320 | slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL); |
| 321 | if (!slot) { |
| 322 | status = AE_NO_MEMORY; |
| 323 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 326 | slot->bus = bridge->pci_bus; |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 327 | slot->device = device; |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 328 | INIT_LIST_HEAD(&slot->funcs); |
| 329 | mutex_init(&slot->crit_sect); |
| 330 | |
| 331 | mutex_lock(&bridge_mutex); |
| 332 | list_add_tail(&slot->node, &bridge->slots); |
| 333 | mutex_unlock(&bridge_mutex); |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 334 | |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 335 | /* Register slots for ejectable funtions only. */ |
| 336 | if (acpi_pci_check_ejectable(pbus, handle) || is_dock_device(handle)) { |
| 337 | unsigned long long sun; |
| 338 | int retval; |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 339 | |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 340 | bridge->nr_slots++; |
| 341 | status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun); |
| 342 | if (ACPI_FAILURE(status)) |
| 343 | sun = bridge->nr_slots; |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 344 | |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 345 | dbg("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n", |
Rafael J. Wysocki | 7342798 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 346 | sun, pci_domain_nr(pbus), pbus->number, device); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 347 | |
Rafael J. Wysocki | 7342798 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 348 | retval = acpiphp_register_hotplug_slot(slot, sun); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 349 | if (retval) { |
| 350 | bridge->nr_slots--; |
| 351 | if (retval == -EBUSY) |
| 352 | warn("Slot %llu already registered by another " |
Rafael J. Wysocki | 7342798 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 353 | "hotplug driver\n", sun); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 354 | else |
| 355 | warn("acpiphp_register_hotplug_slot failed " |
| 356 | "(err code = 0x%x)\n", retval); |
| 357 | } |
| 358 | /* Even if the slot registration fails, we can still use it. */ |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | slot_found: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | newfunc->slot = slot; |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 363 | mutex_lock(&bridge_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | list_add_tail(&newfunc->sibling, &slot->funcs); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 365 | mutex_unlock(&bridge_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 367 | if (pci_bus_read_dev_vendor_id(pbus, PCI_DEVFN(device, function), |
| 368 | &val, 60*1000)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 371 | if (is_dock_device(handle)) { |
| 372 | /* we don't want to call this device's _EJ0 |
| 373 | * because we want the dock notify handler |
| 374 | * to call it after it calls _DCK |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 375 | */ |
| 376 | newfunc->flags &= ~FUNC_HAS_EJ0; |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 377 | if (register_hotplug_dock_device(handle, |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 378 | &acpiphp_dock_ops, context, |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 379 | acpiphp_dock_init, acpiphp_dock_release)) |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 380 | dbg("failed to register dock device\n"); |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /* install notify handler */ |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 384 | if (!(newfunc->flags & FUNC_HAS_DCK)) { |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 385 | status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, |
| 386 | handle_hotplug_event, |
| 387 | context); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 388 | if (ACPI_FAILURE(status)) |
| 389 | acpi_handle_err(handle, |
| 390 | "failed to install notify handler\n"); |
Rafael J. Wysocki | 2e862c5 | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 391 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Rafael J. Wysocki | 2e862c5 | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 393 | return AE_OK; |
MUNEDA Takahiro | e27da38 | 2006-02-23 17:56:08 -0800 | [diff] [blame] | 394 | |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 395 | err: |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 396 | mutex_lock(&acpiphp_context_lock); |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 397 | acpiphp_put_context(context); |
| 398 | mutex_unlock(&acpiphp_context_lock); |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 399 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 402 | static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) |
| 403 | { |
Rafael J. Wysocki | ed13feb | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 404 | struct acpiphp_context *context; |
| 405 | struct acpiphp_bridge *bridge = NULL; |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 406 | |
Rafael J. Wysocki | ed13feb | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 407 | mutex_lock(&acpiphp_context_lock); |
| 408 | context = acpiphp_get_context(handle); |
| 409 | if (context) { |
| 410 | bridge = context->bridge; |
| 411 | if (bridge) |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 412 | get_bridge(bridge); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 413 | |
Rafael J. Wysocki | ed13feb | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 414 | acpiphp_put_context(context); |
| 415 | } |
| 416 | mutex_unlock(&acpiphp_context_lock); |
| 417 | return bridge; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 418 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Rajesh Shah | 364d509 | 2005-04-28 00:25:54 -0700 | [diff] [blame] | 420 | static void cleanup_bridge(struct acpiphp_bridge *bridge) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 422 | struct acpiphp_slot *slot; |
| 423 | struct acpiphp_func *func; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 424 | acpi_status status; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 425 | |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 426 | list_for_each_entry(slot, &bridge->slots, node) { |
| 427 | list_for_each_entry(func, &slot->funcs, sibling) { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 428 | acpi_handle handle = func_to_handle(func); |
| 429 | |
| 430 | if (is_dock_device(handle)) |
| 431 | unregister_hotplug_dock_device(handle); |
| 432 | |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 433 | if (!(func->flags & FUNC_HAS_DCK)) { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 434 | status = acpi_remove_notify_handler(handle, |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 435 | ACPI_SYSTEM_NOTIFY, |
| 436 | handle_hotplug_event); |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 437 | if (ACPI_FAILURE(status)) |
| 438 | err("failed to remove notify handler\n"); |
| 439 | } |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 440 | } |
MUNEDA Takahiro | e27da38 | 2006-02-23 17:56:08 -0800 | [diff] [blame] | 441 | acpiphp_unregister_hotplug_slot(slot); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 444 | mutex_lock(&bridge_mutex); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 445 | list_del(&bridge->list); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 446 | mutex_unlock(&bridge_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | static int power_on_slot(struct acpiphp_slot *slot) |
| 450 | { |
| 451 | acpi_status status; |
| 452 | struct acpiphp_func *func; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | int retval = 0; |
| 454 | |
| 455 | /* if already enabled, just skip */ |
| 456 | if (slot->flags & SLOT_POWEREDON) |
| 457 | goto err_exit; |
| 458 | |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 459 | list_for_each_entry(func, &slot->funcs, sibling) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | if (func->flags & FUNC_HAS_PS0) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 461 | dbg("%s: executing _PS0\n", __func__); |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 462 | status = acpi_evaluate_object(func_to_handle(func), |
| 463 | "_PS0", NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | if (ACPI_FAILURE(status)) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 465 | warn("%s: _PS0 failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | retval = -1; |
| 467 | goto err_exit; |
| 468 | } else |
| 469 | break; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | /* TBD: evaluate _STA to check if the slot is enabled */ |
| 474 | |
| 475 | slot->flags |= SLOT_POWEREDON; |
| 476 | |
| 477 | err_exit: |
| 478 | return retval; |
| 479 | } |
| 480 | |
| 481 | |
| 482 | static int power_off_slot(struct acpiphp_slot *slot) |
| 483 | { |
| 484 | acpi_status status; |
| 485 | struct acpiphp_func *func; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
| 487 | int retval = 0; |
| 488 | |
| 489 | /* if already disabled, just skip */ |
| 490 | if ((slot->flags & SLOT_POWEREDON) == 0) |
| 491 | goto err_exit; |
| 492 | |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 493 | list_for_each_entry(func, &slot->funcs, sibling) { |
Rajesh Shah | 2f523b1 | 2005-04-28 00:25:55 -0700 | [diff] [blame] | 494 | if (func->flags & FUNC_HAS_PS3) { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 495 | status = acpi_evaluate_object(func_to_handle(func), |
| 496 | "_PS3", NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | if (ACPI_FAILURE(status)) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 498 | warn("%s: _PS3 failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | retval = -1; |
| 500 | goto err_exit; |
| 501 | } else |
| 502 | break; |
| 503 | } |
| 504 | } |
| 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | /* TBD: evaluate _STA to check if the slot is disabled */ |
| 507 | |
| 508 | slot->flags &= (~SLOT_POWEREDON); |
| 509 | |
| 510 | err_exit: |
| 511 | return retval; |
| 512 | } |
| 513 | |
| 514 | |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 515 | |
| 516 | /** |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 517 | * acpiphp_max_busnr - return the highest reserved bus number under the given bus. |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 518 | * @bus: bus to start search with |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 519 | */ |
| 520 | static unsigned char acpiphp_max_busnr(struct pci_bus *bus) |
| 521 | { |
| 522 | struct list_head *tmp; |
| 523 | unsigned char max, n; |
| 524 | |
| 525 | /* |
| 526 | * pci_bus_max_busnr will return the highest |
| 527 | * reserved busnr for all these children. |
| 528 | * that is equivalent to the bus->subordinate |
| 529 | * value. We don't want to use the parent's |
| 530 | * bus->subordinate value because it could have |
| 531 | * padding in it. |
| 532 | */ |
Yinghai Lu | b918c62 | 2012-05-17 18:51:11 -0700 | [diff] [blame] | 533 | max = bus->busn_res.start; |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 534 | |
| 535 | list_for_each(tmp, &bus->children) { |
| 536 | n = pci_bus_max_busnr(pci_bus_b(tmp)); |
| 537 | if (n > max) |
| 538 | max = n; |
| 539 | } |
| 540 | return max; |
| 541 | } |
| 542 | |
| 543 | |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 544 | /** |
| 545 | * acpiphp_bus_add - add a new bus to acpi subsystem |
| 546 | * @func: acpiphp_func of the bridge |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 547 | */ |
| 548 | static int acpiphp_bus_add(struct acpiphp_func *func) |
| 549 | { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 550 | acpi_handle handle = func_to_handle(func); |
Rafael J. Wysocki | 636458d | 2012-12-21 00:36:47 +0100 | [diff] [blame] | 551 | struct acpi_device *device; |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 552 | int ret_val; |
| 553 | |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 554 | if (!acpi_bus_get_device(handle, &device)) { |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 555 | dbg("bus exists... trim\n"); |
| 556 | /* this shouldn't be in here, so remove |
| 557 | * the bus then re-add it... |
| 558 | */ |
Rafael J. Wysocki | bfee26d | 2013-01-26 00:27:44 +0100 | [diff] [blame] | 559 | acpi_bus_trim(device); |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 562 | ret_val = acpi_bus_scan(handle); |
Rafael J. Wysocki | 0cd6ac5 | 2012-12-21 00:36:49 +0100 | [diff] [blame] | 563 | if (!ret_val) |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 564 | ret_val = acpi_bus_get_device(handle, &device); |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 565 | |
Rafael J. Wysocki | 0cd6ac5 | 2012-12-21 00:36:49 +0100 | [diff] [blame] | 566 | if (ret_val) |
| 567 | dbg("error adding bus, %x\n", -ret_val); |
| 568 | |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 569 | return ret_val; |
| 570 | } |
| 571 | |
| 572 | |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 573 | /** |
| 574 | * acpiphp_bus_trim - trim a bus from acpi subsystem |
| 575 | * @handle: handle to acpi namespace |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 576 | */ |
Adrian Bunk | 6d47a5e | 2006-08-14 23:07:38 -0700 | [diff] [blame] | 577 | static int acpiphp_bus_trim(acpi_handle handle) |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 578 | { |
| 579 | struct acpi_device *device; |
| 580 | int retval; |
| 581 | |
| 582 | retval = acpi_bus_get_device(handle, &device); |
| 583 | if (retval) { |
| 584 | dbg("acpi_device not found\n"); |
| 585 | return retval; |
| 586 | } |
| 587 | |
Rafael J. Wysocki | bfee26d | 2013-01-26 00:27:44 +0100 | [diff] [blame] | 588 | acpi_bus_trim(device); |
| 589 | return 0; |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 590 | } |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 591 | |
Shaohua Li | d060705 | 2010-02-25 10:59:34 +0800 | [diff] [blame] | 592 | static void acpiphp_set_acpi_region(struct acpiphp_slot *slot) |
| 593 | { |
| 594 | struct acpiphp_func *func; |
| 595 | union acpi_object params[2]; |
| 596 | struct acpi_object_list arg_list; |
| 597 | |
| 598 | list_for_each_entry(func, &slot->funcs, sibling) { |
| 599 | arg_list.count = 2; |
| 600 | arg_list.pointer = params; |
| 601 | params[0].type = ACPI_TYPE_INTEGER; |
| 602 | params[0].integer.value = ACPI_ADR_SPACE_PCI_CONFIG; |
| 603 | params[1].type = ACPI_TYPE_INTEGER; |
| 604 | params[1].integer.value = 1; |
| 605 | /* _REG is optional, we don't care about if there is failure */ |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 606 | acpi_evaluate_object(func_to_handle(func), "_REG", &arg_list, |
| 607 | NULL); |
Shaohua Li | d060705 | 2010-02-25 10:59:34 +0800 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
Yinghai Lu | 1f96a96 | 2013-01-21 13:20:42 -0800 | [diff] [blame] | 611 | static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev) |
| 612 | { |
| 613 | struct acpiphp_func *func; |
| 614 | |
| 615 | if (!dev->subordinate) |
| 616 | return; |
| 617 | |
| 618 | /* quirk, or pcie could set it already */ |
| 619 | if (dev->is_hotplug_bridge) |
| 620 | return; |
| 621 | |
| 622 | if (PCI_SLOT(dev->devfn) != slot->device) |
| 623 | return; |
| 624 | |
| 625 | list_for_each_entry(func, &slot->funcs, sibling) { |
| 626 | if (PCI_FUNC(dev->devfn) == func->function) { |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 627 | dev->is_hotplug_bridge = 1; |
Yinghai Lu | 1f96a96 | 2013-01-21 13:20:42 -0800 | [diff] [blame] | 628 | break; |
| 629 | } |
| 630 | } |
| 631 | } |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | /** |
| 634 | * enable_device - enable, configure a slot |
| 635 | * @slot: slot to be enabled |
| 636 | * |
| 637 | * This function should be called per *physical slot*, |
| 638 | * not per each slot object in ACPI namespace. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | */ |
Sam Ravnborg | 0ab2b57 | 2008-02-17 10:45:28 +0100 | [diff] [blame] | 640 | static int __ref enable_device(struct acpiphp_slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | struct pci_dev *dev; |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 643 | struct pci_bus *bus = slot->bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | struct acpiphp_func *func; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 645 | int num, max, pass; |
Jiang Liu | d66ecb7 | 2013-06-23 01:01:35 +0200 | [diff] [blame] | 646 | LIST_HEAD(add_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
| 648 | if (slot->flags & SLOT_ENABLED) |
| 649 | goto err_exit; |
| 650 | |
Jiang Liu | 2ca344e | 2013-01-31 00:10:09 +0800 | [diff] [blame] | 651 | list_for_each_entry(func, &slot->funcs, sibling) |
| 652 | acpiphp_bus_add(func); |
| 653 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 654 | num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0)); |
| 655 | if (num == 0) { |
Amos Kong | f382a08 | 2011-11-25 15:03:07 +0800 | [diff] [blame] | 656 | /* Maybe only part of funcs are added. */ |
| 657 | dbg("No new device found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | goto err_exit; |
| 659 | } |
| 660 | |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 661 | max = acpiphp_max_busnr(bus); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 662 | for (pass = 0; pass < 2; pass++) { |
| 663 | list_for_each_entry(dev, &bus->devices, bus_list) { |
| 664 | if (PCI_SLOT(dev->devfn) != slot->device) |
| 665 | continue; |
| 666 | if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || |
Kristen Accardi | c64b5ee | 2005-12-14 09:37:26 -0800 | [diff] [blame] | 667 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 668 | max = pci_scan_bridge(bus, dev, max, pass); |
Yinghai Lu | 1f96a96 | 2013-01-21 13:20:42 -0800 | [diff] [blame] | 669 | if (pass && dev->subordinate) { |
| 670 | check_hotplug_bridge(slot, dev); |
Jiang Liu | d66ecb7 | 2013-06-23 01:01:35 +0200 | [diff] [blame] | 671 | pcibios_resource_survey_bus(dev->subordinate); |
| 672 | __pci_bus_size_bridges(dev->subordinate, |
| 673 | &add_list); |
Yinghai Lu | 1f96a96 | 2013-01-21 13:20:42 -0800 | [diff] [blame] | 674 | } |
Kristen Accardi | c64b5ee | 2005-12-14 09:37:26 -0800 | [diff] [blame] | 675 | } |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Jiang Liu | d66ecb7 | 2013-06-23 01:01:35 +0200 | [diff] [blame] | 679 | __pci_bus_assign_resources(bus, &add_list, NULL); |
Kristen Accardi | 8e5dce3 | 2005-10-18 17:21:40 -0700 | [diff] [blame] | 680 | acpiphp_sanitize_bus(bus); |
Bjorn Helgaas | fca6825 | 2009-09-14 16:35:10 -0600 | [diff] [blame] | 681 | acpiphp_set_hpp_values(bus); |
Shaohua Li | d060705 | 2010-02-25 10:59:34 +0800 | [diff] [blame] | 682 | acpiphp_set_acpi_region(slot); |
Kristen Accardi | 8e5dce3 | 2005-10-18 17:21:40 -0700 | [diff] [blame] | 683 | pci_enable_bridges(bus); |
Ian Campbell | 69643e4 | 2011-05-11 17:00:32 +0100 | [diff] [blame] | 684 | |
| 685 | list_for_each_entry(dev, &bus->devices, bus_list) { |
| 686 | /* Assume that newly added devices are powered on already. */ |
| 687 | if (!dev->is_added) |
| 688 | dev->current_state = PCI_D0; |
| 689 | } |
| 690 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 691 | pci_bus_add_devices(bus); |
| 692 | |
Amos Kong | f382a08 | 2011-11-25 15:03:07 +0800 | [diff] [blame] | 693 | slot->flags |= SLOT_ENABLED; |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 694 | list_for_each_entry(func, &slot->funcs, sibling) { |
Alex Chiang | 9d911d7 | 2009-05-21 16:21:15 -0600 | [diff] [blame] | 695 | dev = pci_get_slot(bus, PCI_DEVFN(slot->device, |
| 696 | func->function)); |
Amos Kong | f382a08 | 2011-11-25 15:03:07 +0800 | [diff] [blame] | 697 | if (!dev) { |
| 698 | /* Do not set SLOT_ENABLED flag if some funcs |
| 699 | are not added. */ |
| 700 | slot->flags &= (~SLOT_ENABLED); |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 701 | continue; |
Amos Kong | f382a08 | 2011-11-25 15:03:07 +0800 | [diff] [blame] | 702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | err_exit: |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 707 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Amos Kong | ce29ca3 | 2012-05-23 10:20:35 -0600 | [diff] [blame] | 710 | /* return first device in slot, acquiring a reference on it */ |
| 711 | static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot) |
| 712 | { |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 713 | struct pci_bus *bus = slot->bus; |
Amos Kong | ce29ca3 | 2012-05-23 10:20:35 -0600 | [diff] [blame] | 714 | struct pci_dev *dev; |
| 715 | struct pci_dev *ret = NULL; |
| 716 | |
| 717 | down_read(&pci_bus_sem); |
| 718 | list_for_each_entry(dev, &bus->devices, bus_list) |
| 719 | if (PCI_SLOT(dev->devfn) == slot->device) { |
| 720 | ret = pci_dev_get(dev); |
| 721 | break; |
| 722 | } |
| 723 | up_read(&pci_bus_sem); |
| 724 | |
| 725 | return ret; |
| 726 | } |
| 727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | /** |
| 729 | * disable_device - disable a slot |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 730 | * @slot: ACPI PHP slot |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | */ |
| 732 | static int disable_device(struct acpiphp_slot *slot) |
| 733 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | struct acpiphp_func *func; |
Alex Chiang | 9d911d7 | 2009-05-21 16:21:15 -0600 | [diff] [blame] | 735 | struct pci_dev *pdev; |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 736 | |
Amos Kong | ce29ca3 | 2012-05-23 10:20:35 -0600 | [diff] [blame] | 737 | /* |
| 738 | * enable_device() enumerates all functions in this device via |
| 739 | * pci_scan_slot(), whether they have associated ACPI hotplug |
| 740 | * methods (_EJ0, etc.) or not. Therefore, we remove all functions |
| 741 | * here. |
| 742 | */ |
| 743 | while ((pdev = dev_in_slot(slot))) { |
Bjorn Helgaas | 34e5484 | 2012-08-17 10:03:47 -0600 | [diff] [blame] | 744 | pci_stop_and_remove_bus_device(pdev); |
Amos Kong | ce29ca3 | 2012-05-23 10:20:35 -0600 | [diff] [blame] | 745 | pci_dev_put(pdev); |
Satoru Takeuchi | 600812e | 2006-09-12 10:22:53 -0700 | [diff] [blame] | 746 | } |
Satoru Takeuchi | 0dad351 | 2006-09-12 10:17:46 -0700 | [diff] [blame] | 747 | |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 748 | list_for_each_entry(func, &slot->funcs, sibling) |
| 749 | acpiphp_bus_trim(func_to_handle(func)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
| 751 | slot->flags &= (~SLOT_ENABLED); |
| 752 | |
Alex Chiang | 9d911d7 | 2009-05-21 16:21:15 -0600 | [diff] [blame] | 753 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | |
| 757 | /** |
| 758 | * get_slot_status - get ACPI slot status |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 759 | * @slot: ACPI PHP slot |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 761 | * If a slot has _STA for each function and if any one of them |
| 762 | * returned non-zero status, return it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 764 | * If a slot doesn't have _STA and if any one of its functions' |
| 765 | * configuration space is configured, return 0x0f as a _STA. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 767 | * Otherwise return 0. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | */ |
| 769 | static unsigned int get_slot_status(struct acpiphp_slot *slot) |
| 770 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 771 | unsigned long long sta = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | struct acpiphp_func *func; |
| 773 | |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 774 | list_for_each_entry(func, &slot->funcs, sibling) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | if (func->flags & FUNC_HAS_STA) { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 776 | acpi_status status; |
| 777 | |
| 778 | status = acpi_evaluate_integer(func_to_handle(func), |
| 779 | "_STA", NULL, &sta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | if (ACPI_SUCCESS(status) && sta) |
| 781 | break; |
| 782 | } else { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 783 | u32 dvid; |
| 784 | |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 785 | pci_bus_read_config_dword(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | PCI_DEVFN(slot->device, |
| 787 | func->function), |
| 788 | PCI_VENDOR_ID, &dvid); |
| 789 | if (dvid != 0xffffffff) { |
| 790 | sta = ACPI_STA_ALL; |
| 791 | break; |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | return (unsigned int)sta; |
| 797 | } |
| 798 | |
| 799 | /** |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 800 | * acpiphp_eject_slot - physically eject the slot |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 801 | * @slot: ACPI PHP slot |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 802 | */ |
Gary Hade | bfceafc | 2007-07-05 11:10:46 -0700 | [diff] [blame] | 803 | int acpiphp_eject_slot(struct acpiphp_slot *slot) |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 804 | { |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 805 | struct acpiphp_func *func; |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 806 | |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 807 | list_for_each_entry(func, &slot->funcs, sibling) { |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 808 | /* We don't want to call _EJ0 on non-existing functions. */ |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 809 | if (!(func->flags & FUNC_HAS_EJ0)) |
| 810 | continue; |
| 811 | |
| 812 | if (ACPI_FAILURE(acpi_evaluate_ej0(func_to_handle(func)))) |
| 813 | return -1; |
| 814 | else |
| 815 | break; |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 816 | } |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | * acpiphp_check_bridge - re-enumerate devices |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 822 | * @bridge: where to begin re-enumeration |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | * |
| 824 | * Iterate over all slots under this bridge and make sure that if a |
| 825 | * card is present they are enabled, and if not they are disabled. |
| 826 | */ |
| 827 | static int acpiphp_check_bridge(struct acpiphp_bridge *bridge) |
| 828 | { |
| 829 | struct acpiphp_slot *slot; |
| 830 | int retval = 0; |
| 831 | int enabled, disabled; |
| 832 | |
| 833 | enabled = disabled = 0; |
| 834 | |
Yijing Wang | ad41dd9 | 2013-04-12 05:44:27 +0000 | [diff] [blame] | 835 | list_for_each_entry(slot, &bridge->slots, node) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | unsigned int status = get_slot_status(slot); |
| 837 | if (slot->flags & SLOT_ENABLED) { |
| 838 | if (status == ACPI_STA_ALL) |
| 839 | continue; |
| 840 | retval = acpiphp_disable_slot(slot); |
| 841 | if (retval) { |
| 842 | err("Error occurred in disabling\n"); |
| 843 | goto err_exit; |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 844 | } else { |
| 845 | acpiphp_eject_slot(slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | } |
| 847 | disabled++; |
| 848 | } else { |
| 849 | if (status != ACPI_STA_ALL) |
| 850 | continue; |
| 851 | retval = acpiphp_enable_slot(slot); |
| 852 | if (retval) { |
| 853 | err("Error occurred in enabling\n"); |
| 854 | goto err_exit; |
| 855 | } |
| 856 | enabled++; |
| 857 | } |
| 858 | } |
| 859 | |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 860 | dbg("%s: %d enabled, %d disabled\n", __func__, enabled, disabled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
| 862 | err_exit: |
| 863 | return retval; |
| 864 | } |
| 865 | |
Bjorn Helgaas | fca6825 | 2009-09-14 16:35:10 -0600 | [diff] [blame] | 866 | static void acpiphp_set_hpp_values(struct pci_bus *bus) |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 867 | { |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 868 | struct pci_dev *dev; |
| 869 | |
Bjorn Helgaas | e81995b | 2009-09-14 16:35:35 -0600 | [diff] [blame] | 870 | list_for_each_entry(dev, &bus->devices, bus_list) |
| 871 | pci_configure_slot(dev); |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /* |
| 875 | * Remove devices for which we could not assign resources, call |
| 876 | * arch specific code to fix-up the bus |
| 877 | */ |
| 878 | static void acpiphp_sanitize_bus(struct pci_bus *bus) |
| 879 | { |
Yijing Wang | d65eba6 | 2013-04-12 05:44:17 +0000 | [diff] [blame] | 880 | struct pci_dev *dev, *tmp; |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 881 | int i; |
| 882 | unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM; |
| 883 | |
Yijing Wang | d65eba6 | 2013-04-12 05:44:17 +0000 | [diff] [blame] | 884 | list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) { |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 885 | for (i=0; i<PCI_BRIDGE_RESOURCES; i++) { |
| 886 | struct resource *res = &dev->resource[i]; |
| 887 | if ((res->flags & type_mask) && !res->start && |
| 888 | res->end) { |
| 889 | /* Could not assign a required resources |
| 890 | * for this device, remove it */ |
Yinghai Lu | 210647a | 2012-02-25 13:54:20 -0800 | [diff] [blame] | 891 | pci_stop_and_remove_bus_device(dev); |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 892 | break; |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | } |
| 897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | /* |
| 899 | * ACPI event handlers |
| 900 | */ |
| 901 | |
Gary Hade | 0bbd642 | 2007-07-05 11:10:48 -0700 | [diff] [blame] | 902 | static acpi_status |
Gary Hade | 0bbd642 | 2007-07-05 11:10:48 -0700 | [diff] [blame] | 903 | check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 904 | { |
| 905 | struct acpiphp_bridge *bridge; |
| 906 | char objname[64]; |
| 907 | struct acpi_buffer buffer = { .length = sizeof(objname), |
| 908 | .pointer = objname }; |
| 909 | |
| 910 | bridge = acpiphp_handle_to_bridge(handle); |
| 911 | if (bridge) { |
| 912 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 913 | dbg("%s: re-enumerating slots under %s\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 914 | __func__, objname); |
Gary Hade | 0bbd642 | 2007-07-05 11:10:48 -0700 | [diff] [blame] | 915 | acpiphp_check_bridge(bridge); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 916 | put_bridge(bridge); |
Gary Hade | 0bbd642 | 2007-07-05 11:10:48 -0700 | [diff] [blame] | 917 | } |
| 918 | return AE_OK ; |
| 919 | } |
| 920 | |
Yinghai Lu | 3f327e3 | 2013-05-07 11:06:03 -0600 | [diff] [blame] | 921 | void acpiphp_check_host_bridge(acpi_handle handle) |
| 922 | { |
| 923 | struct acpiphp_bridge *bridge; |
| 924 | |
| 925 | bridge = acpiphp_handle_to_bridge(handle); |
| 926 | if (bridge) { |
| 927 | acpiphp_check_bridge(bridge); |
| 928 | put_bridge(bridge); |
| 929 | } |
| 930 | |
| 931 | acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, |
| 932 | ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL, NULL); |
| 933 | } |
| 934 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 935 | static void hotplug_event(acpi_handle handle, u32 type, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | { |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 937 | struct acpiphp_context *context = data; |
Rafael J. Wysocki | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 938 | struct acpiphp_func *func = &context->func; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | struct acpiphp_bridge *bridge; |
| 940 | char objname[64]; |
| 941 | struct acpi_buffer buffer = { .length = sizeof(objname), |
| 942 | .pointer = objname }; |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 943 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 944 | mutex_lock(&acpiphp_context_lock); |
Rafael J. Wysocki | c8ebcf1 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 945 | bridge = context->bridge; |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 946 | if (bridge) |
| 947 | get_bridge(bridge); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 949 | mutex_unlock(&acpiphp_context_lock); |
Rafael J. Wysocki | 3757b94 | 2013-02-13 14:36:47 +0100 | [diff] [blame] | 950 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 952 | |
| 953 | switch (type) { |
| 954 | case ACPI_NOTIFY_BUS_CHECK: |
| 955 | /* bus re-enumerate */ |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 956 | dbg("%s: Bus check notify on %s\n", __func__, objname); |
Jiang Liu | be6d286 | 2013-01-31 00:10:10 +0800 | [diff] [blame] | 957 | dbg("%s: re-enumerating slots under %s\n", __func__, objname); |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 958 | if (bridge) { |
| 959 | acpiphp_check_bridge(bridge); |
| 960 | acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, |
| 961 | ACPI_UINT32_MAX, check_sub_bridges, |
| 962 | NULL, NULL, NULL); |
| 963 | } else { |
| 964 | acpiphp_enable_slot(func->slot); |
| 965 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | break; |
| 967 | |
| 968 | case ACPI_NOTIFY_DEVICE_CHECK: |
| 969 | /* device check */ |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 970 | dbg("%s: Device check notify on %s\n", __func__, objname); |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 971 | if (bridge) |
| 972 | acpiphp_check_bridge(bridge); |
| 973 | else |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 974 | acpiphp_check_bridge(func->parent); |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 975 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | break; |
| 977 | |
| 978 | case ACPI_NOTIFY_DEVICE_WAKE: |
| 979 | /* wake event */ |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 980 | dbg("%s: Device wake notify on %s\n", __func__, objname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | break; |
| 982 | |
| 983 | case ACPI_NOTIFY_EJECT_REQUEST: |
| 984 | /* request device eject */ |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 985 | dbg("%s: Device eject notify on %s\n", __func__, objname); |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 986 | if (!(acpiphp_disable_slot(func->slot))) |
| 987 | acpiphp_eject_slot(func->slot); |
| 988 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | break; |
| 990 | |
| 991 | case ACPI_NOTIFY_FREQUENCY_MISMATCH: |
| 992 | printk(KERN_ERR "Device %s cannot be configured due" |
| 993 | " to a frequency mismatch\n", objname); |
| 994 | break; |
| 995 | |
| 996 | case ACPI_NOTIFY_BUS_MODE_MISMATCH: |
| 997 | printk(KERN_ERR "Device %s cannot be configured due" |
| 998 | " to a bus mode mismatch\n", objname); |
| 999 | break; |
| 1000 | |
| 1001 | case ACPI_NOTIFY_POWER_FAULT: |
| 1002 | printk(KERN_ERR "Device %s has suffered a power fault\n", |
| 1003 | objname); |
| 1004 | break; |
| 1005 | |
| 1006 | default: |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1007 | warn("notify_handler: unknown event type 0x%x for %s\n", type, |
| 1008 | objname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | break; |
| 1010 | } |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1011 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1012 | if (bridge) |
| 1013 | put_bridge(bridge); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1016 | static void hotplug_event_work(struct work_struct *work) |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 1017 | { |
Rafael J. Wysocki | c8ebcf1 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1018 | struct acpiphp_context *context; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 1019 | struct acpi_hp_work *hp_work; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 1020 | |
| 1021 | hp_work = container_of(work, struct acpi_hp_work, work); |
Rafael J. Wysocki | c8ebcf1 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1022 | context = hp_work->context; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 1023 | acpi_scan_lock_acquire(); |
| 1024 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1025 | hotplug_event(hp_work->handle, hp_work->type, context); |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1026 | |
Rafael J. Wysocki | 3757b94 | 2013-02-13 14:36:47 +0100 | [diff] [blame] | 1027 | acpi_scan_lock_release(); |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1028 | kfree(hp_work); /* allocated in handle_hotplug_event() */ |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 1029 | put_bridge(context->func.parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1032 | /** |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1033 | * handle_hotplug_event - handle ACPI hotplug event |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1034 | * @handle: Notify()'ed acpi_handle |
| 1035 | * @type: Notify code |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1036 | * @data: pointer to acpiphp_context structure |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1037 | * |
| 1038 | * Handles ACPI event notification on slots. |
| 1039 | */ |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1040 | static void handle_hotplug_event(acpi_handle handle, u32 type, void *data) |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1041 | { |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1042 | struct acpiphp_context *context; |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1043 | |
| 1044 | mutex_lock(&acpiphp_context_lock); |
| 1045 | context = acpiphp_get_context(handle); |
| 1046 | if (context) { |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 1047 | get_bridge(context->func.parent); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1048 | acpiphp_put_context(context); |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1049 | } |
| 1050 | mutex_unlock(&acpiphp_context_lock); |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1051 | /* |
| 1052 | * Currently the code adds all hotplug events to the kacpid_wq |
| 1053 | * queue when it should add hotplug events to the kacpi_hotplug_wq. |
| 1054 | * The proper way to fix this is to reorganize the code so that |
| 1055 | * drivers (dock, etc.) do not call acpi_os_execute(), etc. |
| 1056 | * For now just re-add this work to the kacpi_hotplug_wq so we |
| 1057 | * don't deadlock on hotplug actions. |
| 1058 | */ |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1059 | if (context) |
| 1060 | alloc_acpi_hp_work(handle, type, context, hotplug_event_work); |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1061 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1063 | /* |
| 1064 | * Create hotplug slots for the PCI bus. |
| 1065 | * It should always return 0 to avoid skipping following notifiers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | */ |
Rafael J. Wysocki | be1c9de | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 1067 | void acpiphp_enumerate_slots(struct pci_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | { |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1069 | struct acpiphp_bridge *bridge; |
Rafael J. Wysocki | 2552002a | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 1070 | acpi_handle handle; |
| 1071 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1073 | if (acpiphp_disabled) |
| 1074 | return; |
| 1075 | |
Rafael J. Wysocki | be1c9de | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 1076 | handle = ACPI_HANDLE(bus->bridge); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1077 | if (!handle) |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1078 | return; |
| 1079 | |
| 1080 | bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL); |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1081 | if (!bridge) { |
| 1082 | acpi_handle_err(handle, "No memory for bridge object\n"); |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1083 | return; |
| 1084 | } |
| 1085 | |
Yijing Wang | ad41dd9 | 2013-04-12 05:44:27 +0000 | [diff] [blame] | 1086 | INIT_LIST_HEAD(&bridge->slots); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 1087 | kref_init(&bridge->ref); |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1088 | bridge->pci_dev = pci_dev_get(bus->self); |
| 1089 | bridge->pci_bus = bus; |
| 1090 | |
| 1091 | /* |
| 1092 | * Grab a ref to the subordinate PCI bus in case the bus is |
| 1093 | * removed via PCI core logical hotplug. The ref pins the bus |
| 1094 | * (which we access during module unload). |
| 1095 | */ |
| 1096 | get_device(&bus->dev); |
| 1097 | |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1098 | if (!pci_is_root_bus(bridge->pci_bus)) { |
| 1099 | struct acpiphp_context *context; |
| 1100 | |
| 1101 | /* |
| 1102 | * This bridge should have been registered as a hotplug function |
| 1103 | * under its parent, so the context has to be there. If not, we |
| 1104 | * are in deep goo. |
| 1105 | */ |
| 1106 | mutex_lock(&acpiphp_context_lock); |
| 1107 | context = acpiphp_get_context(handle); |
Rafael J. Wysocki | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 1108 | if (WARN_ON(!context)) { |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1109 | mutex_unlock(&acpiphp_context_lock); |
| 1110 | put_device(&bus->dev); |
| 1111 | kfree(bridge); |
| 1112 | return; |
| 1113 | } |
| 1114 | bridge->context = context; |
| 1115 | context->bridge = bridge; |
| 1116 | /* Get a reference to the parent bridge. */ |
Rafael J. Wysocki | bda46db | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 1117 | get_bridge(context->func.parent); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1118 | mutex_unlock(&acpiphp_context_lock); |
| 1119 | } |
| 1120 | |
Rafael J. Wysocki | 2552002a | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 1121 | /* must be added to the list prior to calling register_slot */ |
| 1122 | mutex_lock(&bridge_mutex); |
| 1123 | list_add(&bridge->list, &bridge_list); |
| 1124 | mutex_unlock(&bridge_mutex); |
| 1125 | |
| 1126 | /* register all slot objects under this bridge */ |
Rafael J. Wysocki | 89373a5 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 1127 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1, |
Rafael J. Wysocki | 2552002a | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 1128 | register_slot, NULL, bridge, NULL); |
| 1129 | if (ACPI_FAILURE(status)) { |
Rafael J. Wysocki | 89373a5 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 1130 | acpi_handle_err(handle, "failed to register slots\n"); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1131 | cleanup_bridge(bridge); |
| 1132 | put_bridge(bridge); |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1133 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1136 | /* Destroy hotplug slots associated with the PCI bus */ |
| 1137 | void acpiphp_remove_slots(struct pci_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | { |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1139 | struct acpiphp_bridge *bridge, *tmp; |
| 1140 | |
| 1141 | if (acpiphp_disabled) |
| 1142 | return; |
| 1143 | |
| 1144 | list_for_each_entry_safe(bridge, tmp, &bridge_list, list) |
| 1145 | if (bridge->pci_bus == bus) { |
| 1146 | cleanup_bridge(bridge); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 1147 | put_bridge(bridge); |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1148 | break; |
| 1149 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | /** |
| 1153 | * acpiphp_enable_slot - power on slot |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 1154 | * @slot: ACPI PHP slot |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | */ |
| 1156 | int acpiphp_enable_slot(struct acpiphp_slot *slot) |
| 1157 | { |
| 1158 | int retval; |
| 1159 | |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1160 | mutex_lock(&slot->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | |
| 1162 | /* wake up all functions */ |
| 1163 | retval = power_on_slot(slot); |
| 1164 | if (retval) |
| 1165 | goto err_exit; |
| 1166 | |
MUNEDA Takahiro | cde0e5d | 2006-03-22 14:49:33 +0900 | [diff] [blame] | 1167 | if (get_slot_status(slot) == ACPI_STA_ALL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | /* configure all functions */ |
| 1169 | retval = enable_device(slot); |
MUNEDA Takahiro | cde0e5d | 2006-03-22 14:49:33 +0900 | [diff] [blame] | 1170 | if (retval) |
| 1171 | power_off_slot(slot); |
| 1172 | } else { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 1173 | dbg("%s: Slot status is not ACPI_STA_ALL\n", __func__); |
MUNEDA Takahiro | cde0e5d | 2006-03-22 14:49:33 +0900 | [diff] [blame] | 1174 | power_off_slot(slot); |
| 1175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | |
| 1177 | err_exit: |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1178 | mutex_unlock(&slot->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | return retval; |
| 1180 | } |
| 1181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | /** |
| 1183 | * acpiphp_disable_slot - power off slot |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 1184 | * @slot: ACPI PHP slot |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | */ |
| 1186 | int acpiphp_disable_slot(struct acpiphp_slot *slot) |
| 1187 | { |
| 1188 | int retval = 0; |
| 1189 | |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1190 | mutex_lock(&slot->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
| 1192 | /* unconfigure all functions */ |
| 1193 | retval = disable_device(slot); |
| 1194 | if (retval) |
| 1195 | goto err_exit; |
| 1196 | |
| 1197 | /* power off all functions */ |
| 1198 | retval = power_off_slot(slot); |
| 1199 | if (retval) |
| 1200 | goto err_exit; |
| 1201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | err_exit: |
Ingo Molnar | 6aa4cdd | 2006-01-13 16:02:15 +0100 | [diff] [blame] | 1203 | mutex_unlock(&slot->crit_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | return retval; |
| 1205 | } |
| 1206 | |
| 1207 | |
| 1208 | /* |
| 1209 | * slot enabled: 1 |
| 1210 | * slot disabled: 0 |
| 1211 | */ |
| 1212 | u8 acpiphp_get_power_status(struct acpiphp_slot *slot) |
| 1213 | { |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 1214 | return (slot->flags & SLOT_POWEREDON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | /* |
MUNEDA Takahiro | 35ae61a | 2006-10-25 11:44:57 -0700 | [diff] [blame] | 1219 | * latch open: 1 |
| 1220 | * latch closed: 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | */ |
| 1222 | u8 acpiphp_get_latch_status(struct acpiphp_slot *slot) |
| 1223 | { |
| 1224 | unsigned int sta; |
| 1225 | |
| 1226 | sta = get_slot_status(slot); |
| 1227 | |
Jiang Liu | ce15d87 | 2013-04-12 05:44:19 +0000 | [diff] [blame] | 1228 | return (sta & ACPI_STA_DEVICE_UI) ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | /* |
| 1233 | * adapter presence : 1 |
| 1234 | * absence : 0 |
| 1235 | */ |
| 1236 | u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot) |
| 1237 | { |
| 1238 | unsigned int sta; |
| 1239 | |
| 1240 | sta = get_slot_status(slot); |
| 1241 | |
| 1242 | return (sta == 0) ? 0 : 1; |
| 1243 | } |