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 | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 168 | put_bridge(context->func.slot->bridge); |
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 | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 190 | struct pci_bus *bus = context->func.slot->bridge->pci_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 | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 251 | get_bridge(context->func.slot->bridge); |
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 | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 258 | put_bridge(context->func.slot->bridge); |
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 | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 297 | mutex_unlock(&acpiphp_context_lock); |
| 298 | |
Jiang Liu | ecd046d | 2013-06-29 00:24:43 +0800 | [diff] [blame] | 299 | if (acpi_has_method(handle, "_EJ0")) |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 300 | newfunc->flags = FUNC_HAS_EJ0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Jiang Liu | ecd046d | 2013-06-29 00:24:43 +0800 | [diff] [blame] | 302 | if (acpi_has_method(handle, "_STA")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | newfunc->flags |= FUNC_HAS_STA; |
| 304 | |
Jiang Liu | ecd046d | 2013-06-29 00:24:43 +0800 | [diff] [blame] | 305 | if (acpi_has_method(handle, "_PS0")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | newfunc->flags |= FUNC_HAS_PS0; |
| 307 | |
Jiang Liu | ecd046d | 2013-06-29 00:24:43 +0800 | [diff] [blame] | 308 | if (acpi_has_method(handle, "_PS3")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | newfunc->flags |= FUNC_HAS_PS3; |
| 310 | |
Jiang Liu | ecd046d | 2013-06-29 00:24:43 +0800 | [diff] [blame] | 311 | if (acpi_has_method(handle, "_DCK")) |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 312 | newfunc->flags |= FUNC_HAS_DCK; |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | /* search for objects that share the same slot */ |
Yijing Wang | ad41dd9 | 2013-04-12 05:44:27 +0000 | [diff] [blame] | 315 | list_for_each_entry(slot, &bridge->slots, node) |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 316 | if (slot->device == device) |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 317 | goto slot_found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 319 | slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL); |
| 320 | if (!slot) { |
| 321 | status = AE_NO_MEMORY; |
| 322 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 325 | slot->bridge = bridge; |
| 326 | slot->device = device; |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 327 | INIT_LIST_HEAD(&slot->funcs); |
| 328 | mutex_init(&slot->crit_sect); |
| 329 | |
| 330 | mutex_lock(&bridge_mutex); |
| 331 | list_add_tail(&slot->node, &bridge->slots); |
| 332 | mutex_unlock(&bridge_mutex); |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 333 | |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 334 | /* Register slots for ejectable funtions only. */ |
| 335 | if (acpi_pci_check_ejectable(pbus, handle) || is_dock_device(handle)) { |
| 336 | unsigned long long sun; |
| 337 | int retval; |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 338 | |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 339 | bridge->nr_slots++; |
| 340 | status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun); |
| 341 | if (ACPI_FAILURE(status)) |
| 342 | sun = bridge->nr_slots; |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 343 | |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 344 | 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] | 345 | sun, pci_domain_nr(pbus), pbus->number, device); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 346 | |
Rafael J. Wysocki | 7342798 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 347 | retval = acpiphp_register_hotplug_slot(slot, sun); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 348 | if (retval) { |
| 349 | bridge->nr_slots--; |
| 350 | if (retval == -EBUSY) |
| 351 | warn("Slot %llu already registered by another " |
Rafael J. Wysocki | 7342798 | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 352 | "hotplug driver\n", sun); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 353 | else |
| 354 | warn("acpiphp_register_hotplug_slot failed " |
| 355 | "(err code = 0x%x)\n", retval); |
| 356 | } |
| 357 | /* Even if the slot registration fails, we can still use it. */ |
Rafael J. Wysocki | ac37233 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | slot_found: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | newfunc->slot = slot; |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 362 | mutex_lock(&bridge_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | list_add_tail(&newfunc->sibling, &slot->funcs); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 364 | mutex_unlock(&bridge_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 366 | if (pci_bus_read_dev_vendor_id(pbus, PCI_DEVFN(device, function), |
| 367 | &val, 60*1000)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | slot->flags |= (SLOT_ENABLED | SLOT_POWEREDON); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 370 | if (is_dock_device(handle)) { |
| 371 | /* we don't want to call this device's _EJ0 |
| 372 | * because we want the dock notify handler |
| 373 | * to call it after it calls _DCK |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 374 | */ |
| 375 | newfunc->flags &= ~FUNC_HAS_EJ0; |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 376 | if (register_hotplug_dock_device(handle, |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 377 | &acpiphp_dock_ops, context, |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 378 | acpiphp_dock_init, acpiphp_dock_release)) |
Kristen Accardi | 4e8662b | 2006-06-28 03:08:06 -0400 | [diff] [blame] | 379 | dbg("failed to register dock device\n"); |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 380 | } |
| 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | /* install notify handler */ |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 383 | if (!(newfunc->flags & FUNC_HAS_DCK)) { |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 384 | status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, |
| 385 | handle_hotplug_event, |
| 386 | context); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 387 | if (ACPI_FAILURE(status)) |
| 388 | acpi_handle_err(handle, |
| 389 | "failed to install notify handler\n"); |
Rafael J. Wysocki | 2e862c5 | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Rafael J. Wysocki | 2e862c5 | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 392 | return AE_OK; |
MUNEDA Takahiro | e27da38 | 2006-02-23 17:56:08 -0800 | [diff] [blame] | 393 | |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 394 | err: |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 395 | mutex_lock(&acpiphp_context_lock); |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 396 | acpiphp_put_context(context); |
| 397 | mutex_unlock(&acpiphp_context_lock); |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 398 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 401 | static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle) |
| 402 | { |
Rafael J. Wysocki | ed13feb | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 403 | struct acpiphp_context *context; |
| 404 | struct acpiphp_bridge *bridge = NULL; |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 405 | |
Rafael J. Wysocki | ed13feb | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 406 | mutex_lock(&acpiphp_context_lock); |
| 407 | context = acpiphp_get_context(handle); |
| 408 | if (context) { |
| 409 | bridge = context->bridge; |
| 410 | if (bridge) |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 411 | get_bridge(bridge); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 412 | |
Rafael J. Wysocki | ed13feb | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 413 | acpiphp_put_context(context); |
| 414 | } |
| 415 | mutex_unlock(&acpiphp_context_lock); |
| 416 | return bridge; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 417 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Rajesh Shah | 364d509 | 2005-04-28 00:25:54 -0700 | [diff] [blame] | 419 | static void cleanup_bridge(struct acpiphp_bridge *bridge) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | { |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 421 | struct acpiphp_slot *slot; |
| 422 | struct acpiphp_func *func; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 423 | acpi_status status; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 424 | |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 425 | list_for_each_entry(slot, &bridge->slots, node) { |
| 426 | list_for_each_entry(func, &slot->funcs, sibling) { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 427 | acpi_handle handle = func_to_handle(func); |
| 428 | |
| 429 | if (is_dock_device(handle)) |
| 430 | unregister_hotplug_dock_device(handle); |
| 431 | |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 432 | if (!(func->flags & FUNC_HAS_DCK)) { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 433 | status = acpi_remove_notify_handler(handle, |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 434 | ACPI_SYSTEM_NOTIFY, |
| 435 | handle_hotplug_event); |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 436 | if (ACPI_FAILURE(status)) |
| 437 | err("failed to remove notify handler\n"); |
| 438 | } |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 439 | } |
MUNEDA Takahiro | e27da38 | 2006-02-23 17:56:08 -0800 | [diff] [blame] | 440 | acpiphp_unregister_hotplug_slot(slot); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 443 | mutex_lock(&bridge_mutex); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 444 | list_del(&bridge->list); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 445 | mutex_unlock(&bridge_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | static int power_on_slot(struct acpiphp_slot *slot) |
| 449 | { |
| 450 | acpi_status status; |
| 451 | struct acpiphp_func *func; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | int retval = 0; |
| 453 | |
| 454 | /* if already enabled, just skip */ |
| 455 | if (slot->flags & SLOT_POWEREDON) |
| 456 | goto err_exit; |
| 457 | |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 458 | list_for_each_entry(func, &slot->funcs, sibling) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | if (func->flags & FUNC_HAS_PS0) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 460 | dbg("%s: executing _PS0\n", __func__); |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 461 | status = acpi_evaluate_object(func_to_handle(func), |
| 462 | "_PS0", NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | if (ACPI_FAILURE(status)) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 464 | warn("%s: _PS0 failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | retval = -1; |
| 466 | goto err_exit; |
| 467 | } else |
| 468 | break; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | /* TBD: evaluate _STA to check if the slot is enabled */ |
| 473 | |
| 474 | slot->flags |= SLOT_POWEREDON; |
| 475 | |
| 476 | err_exit: |
| 477 | return retval; |
| 478 | } |
| 479 | |
| 480 | |
| 481 | static int power_off_slot(struct acpiphp_slot *slot) |
| 482 | { |
| 483 | acpi_status status; |
| 484 | struct acpiphp_func *func; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
| 486 | int retval = 0; |
| 487 | |
| 488 | /* if already disabled, just skip */ |
| 489 | if ((slot->flags & SLOT_POWEREDON) == 0) |
| 490 | goto err_exit; |
| 491 | |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 492 | list_for_each_entry(func, &slot->funcs, sibling) { |
Rajesh Shah | 2f523b1 | 2005-04-28 00:25:55 -0700 | [diff] [blame] | 493 | if (func->flags & FUNC_HAS_PS3) { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 494 | status = acpi_evaluate_object(func_to_handle(func), |
| 495 | "_PS3", NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | if (ACPI_FAILURE(status)) { |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 497 | warn("%s: _PS3 failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | retval = -1; |
| 499 | goto err_exit; |
| 500 | } else |
| 501 | break; |
| 502 | } |
| 503 | } |
| 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | /* TBD: evaluate _STA to check if the slot is disabled */ |
| 506 | |
| 507 | slot->flags &= (~SLOT_POWEREDON); |
| 508 | |
| 509 | err_exit: |
| 510 | return retval; |
| 511 | } |
| 512 | |
| 513 | |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 514 | |
| 515 | /** |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 516 | * 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] | 517 | * @bus: bus to start search with |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 518 | */ |
| 519 | static unsigned char acpiphp_max_busnr(struct pci_bus *bus) |
| 520 | { |
| 521 | struct list_head *tmp; |
| 522 | unsigned char max, n; |
| 523 | |
| 524 | /* |
| 525 | * pci_bus_max_busnr will return the highest |
| 526 | * reserved busnr for all these children. |
| 527 | * that is equivalent to the bus->subordinate |
| 528 | * value. We don't want to use the parent's |
| 529 | * bus->subordinate value because it could have |
| 530 | * padding in it. |
| 531 | */ |
Yinghai Lu | b918c62 | 2012-05-17 18:51:11 -0700 | [diff] [blame] | 532 | max = bus->busn_res.start; |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 533 | |
| 534 | list_for_each(tmp, &bus->children) { |
| 535 | n = pci_bus_max_busnr(pci_bus_b(tmp)); |
| 536 | if (n > max) |
| 537 | max = n; |
| 538 | } |
| 539 | return max; |
| 540 | } |
| 541 | |
| 542 | |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 543 | /** |
| 544 | * acpiphp_bus_add - add a new bus to acpi subsystem |
| 545 | * @func: acpiphp_func of the bridge |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 546 | */ |
| 547 | static int acpiphp_bus_add(struct acpiphp_func *func) |
| 548 | { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 549 | acpi_handle handle = func_to_handle(func); |
Rafael J. Wysocki | 636458d | 2012-12-21 00:36:47 +0100 | [diff] [blame] | 550 | struct acpi_device *device; |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 551 | int ret_val; |
| 552 | |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 553 | if (!acpi_bus_get_device(handle, &device)) { |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 554 | dbg("bus exists... trim\n"); |
| 555 | /* this shouldn't be in here, so remove |
| 556 | * the bus then re-add it... |
| 557 | */ |
Rafael J. Wysocki | bfee26d | 2013-01-26 00:27:44 +0100 | [diff] [blame] | 558 | acpi_bus_trim(device); |
Kristen Accardi | 20416ea | 2006-02-23 17:56:03 -0800 | [diff] [blame] | 559 | } |
| 560 | |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 561 | ret_val = acpi_bus_scan(handle); |
Rafael J. Wysocki | 0cd6ac5 | 2012-12-21 00:36:49 +0100 | [diff] [blame] | 562 | if (!ret_val) |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 563 | ret_val = acpi_bus_get_device(handle, &device); |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 564 | |
Rafael J. Wysocki | 0cd6ac5 | 2012-12-21 00:36:49 +0100 | [diff] [blame] | 565 | if (ret_val) |
| 566 | dbg("error adding bus, %x\n", -ret_val); |
| 567 | |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 568 | return ret_val; |
| 569 | } |
| 570 | |
| 571 | |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 572 | /** |
| 573 | * acpiphp_bus_trim - trim a bus from acpi subsystem |
| 574 | * @handle: handle to acpi namespace |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 575 | */ |
Adrian Bunk | 6d47a5e | 2006-08-14 23:07:38 -0700 | [diff] [blame] | 576 | static int acpiphp_bus_trim(acpi_handle handle) |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 577 | { |
| 578 | struct acpi_device *device; |
| 579 | int retval; |
| 580 | |
| 581 | retval = acpi_bus_get_device(handle, &device); |
| 582 | if (retval) { |
| 583 | dbg("acpi_device not found\n"); |
| 584 | return retval; |
| 585 | } |
| 586 | |
Rafael J. Wysocki | bfee26d | 2013-01-26 00:27:44 +0100 | [diff] [blame] | 587 | acpi_bus_trim(device); |
| 588 | return 0; |
MUNEDA Takahiro | 92c9be9 | 2006-03-22 14:49:09 +0900 | [diff] [blame] | 589 | } |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 590 | |
Shaohua Li | d060705 | 2010-02-25 10:59:34 +0800 | [diff] [blame] | 591 | static void acpiphp_set_acpi_region(struct acpiphp_slot *slot) |
| 592 | { |
| 593 | struct acpiphp_func *func; |
| 594 | union acpi_object params[2]; |
| 595 | struct acpi_object_list arg_list; |
| 596 | |
| 597 | list_for_each_entry(func, &slot->funcs, sibling) { |
| 598 | arg_list.count = 2; |
| 599 | arg_list.pointer = params; |
| 600 | params[0].type = ACPI_TYPE_INTEGER; |
| 601 | params[0].integer.value = ACPI_ADR_SPACE_PCI_CONFIG; |
| 602 | params[1].type = ACPI_TYPE_INTEGER; |
| 603 | params[1].integer.value = 1; |
| 604 | /* _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^] | 605 | acpi_evaluate_object(func_to_handle(func), "_REG", &arg_list, |
| 606 | NULL); |
Shaohua Li | d060705 | 2010-02-25 10:59:34 +0800 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
Yinghai Lu | 1f96a96 | 2013-01-21 13:20:42 -0800 | [diff] [blame] | 610 | static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev) |
| 611 | { |
| 612 | struct acpiphp_func *func; |
| 613 | |
| 614 | if (!dev->subordinate) |
| 615 | return; |
| 616 | |
| 617 | /* quirk, or pcie could set it already */ |
| 618 | if (dev->is_hotplug_bridge) |
| 619 | return; |
| 620 | |
| 621 | if (PCI_SLOT(dev->devfn) != slot->device) |
| 622 | return; |
| 623 | |
| 624 | list_for_each_entry(func, &slot->funcs, sibling) { |
| 625 | if (PCI_FUNC(dev->devfn) == func->function) { |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 626 | dev->is_hotplug_bridge = 1; |
Yinghai Lu | 1f96a96 | 2013-01-21 13:20:42 -0800 | [diff] [blame] | 627 | break; |
| 628 | } |
| 629 | } |
| 630 | } |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | /** |
| 633 | * enable_device - enable, configure a slot |
| 634 | * @slot: slot to be enabled |
| 635 | * |
| 636 | * This function should be called per *physical slot*, |
| 637 | * not per each slot object in ACPI namespace. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | */ |
Sam Ravnborg | 0ab2b57 | 2008-02-17 10:45:28 +0100 | [diff] [blame] | 639 | static int __ref enable_device(struct acpiphp_slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | struct pci_dev *dev; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 642 | struct pci_bus *bus = slot->bridge->pci_bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | struct acpiphp_func *func; |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 644 | int num, max, pass; |
Jiang Liu | d66ecb7 | 2013-06-23 01:01:35 +0200 | [diff] [blame] | 645 | LIST_HEAD(add_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
| 647 | if (slot->flags & SLOT_ENABLED) |
| 648 | goto err_exit; |
| 649 | |
Jiang Liu | 2ca344e | 2013-01-31 00:10:09 +0800 | [diff] [blame] | 650 | list_for_each_entry(func, &slot->funcs, sibling) |
| 651 | acpiphp_bus_add(func); |
| 652 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 653 | num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0)); |
| 654 | if (num == 0) { |
Amos Kong | f382a08 | 2011-11-25 15:03:07 +0800 | [diff] [blame] | 655 | /* Maybe only part of funcs are added. */ |
| 656 | dbg("No new device found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | goto err_exit; |
| 658 | } |
| 659 | |
Kristen Accardi | 15a1ae7 | 2006-02-23 17:55:58 -0800 | [diff] [blame] | 660 | max = acpiphp_max_busnr(bus); |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 661 | for (pass = 0; pass < 2; pass++) { |
| 662 | list_for_each_entry(dev, &bus->devices, bus_list) { |
| 663 | if (PCI_SLOT(dev->devfn) != slot->device) |
| 664 | continue; |
| 665 | if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || |
Kristen Accardi | c64b5ee | 2005-12-14 09:37:26 -0800 | [diff] [blame] | 666 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 667 | max = pci_scan_bridge(bus, dev, max, pass); |
Yinghai Lu | 1f96a96 | 2013-01-21 13:20:42 -0800 | [diff] [blame] | 668 | if (pass && dev->subordinate) { |
| 669 | check_hotplug_bridge(slot, dev); |
Jiang Liu | d66ecb7 | 2013-06-23 01:01:35 +0200 | [diff] [blame] | 670 | pcibios_resource_survey_bus(dev->subordinate); |
| 671 | __pci_bus_size_bridges(dev->subordinate, |
| 672 | &add_list); |
Yinghai Lu | 1f96a96 | 2013-01-21 13:20:42 -0800 | [diff] [blame] | 673 | } |
Kristen Accardi | c64b5ee | 2005-12-14 09:37:26 -0800 | [diff] [blame] | 674 | } |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 675 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Jiang Liu | d66ecb7 | 2013-06-23 01:01:35 +0200 | [diff] [blame] | 678 | __pci_bus_assign_resources(bus, &add_list, NULL); |
Kristen Accardi | 8e5dce3 | 2005-10-18 17:21:40 -0700 | [diff] [blame] | 679 | acpiphp_sanitize_bus(bus); |
Bjorn Helgaas | fca6825 | 2009-09-14 16:35:10 -0600 | [diff] [blame] | 680 | acpiphp_set_hpp_values(bus); |
Shaohua Li | d060705 | 2010-02-25 10:59:34 +0800 | [diff] [blame] | 681 | acpiphp_set_acpi_region(slot); |
Kristen Accardi | 8e5dce3 | 2005-10-18 17:21:40 -0700 | [diff] [blame] | 682 | pci_enable_bridges(bus); |
Ian Campbell | 69643e4 | 2011-05-11 17:00:32 +0100 | [diff] [blame] | 683 | |
| 684 | list_for_each_entry(dev, &bus->devices, bus_list) { |
| 685 | /* Assume that newly added devices are powered on already. */ |
| 686 | if (!dev->is_added) |
| 687 | dev->current_state = PCI_D0; |
| 688 | } |
| 689 | |
Rajesh Shah | 42f49a6 | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 690 | pci_bus_add_devices(bus); |
| 691 | |
Amos Kong | f382a08 | 2011-11-25 15:03:07 +0800 | [diff] [blame] | 692 | slot->flags |= SLOT_ENABLED; |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 693 | list_for_each_entry(func, &slot->funcs, sibling) { |
Alex Chiang | 9d911d7 | 2009-05-21 16:21:15 -0600 | [diff] [blame] | 694 | dev = pci_get_slot(bus, PCI_DEVFN(slot->device, |
| 695 | func->function)); |
Amos Kong | f382a08 | 2011-11-25 15:03:07 +0800 | [diff] [blame] | 696 | if (!dev) { |
| 697 | /* Do not set SLOT_ENABLED flag if some funcs |
| 698 | are not added. */ |
| 699 | slot->flags &= (~SLOT_ENABLED); |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 700 | continue; |
Amos Kong | f382a08 | 2011-11-25 15:03:07 +0800 | [diff] [blame] | 701 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | } |
| 703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | err_exit: |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 706 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Amos Kong | ce29ca3 | 2012-05-23 10:20:35 -0600 | [diff] [blame] | 709 | /* return first device in slot, acquiring a reference on it */ |
| 710 | static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot) |
| 711 | { |
| 712 | struct pci_bus *bus = slot->bridge->pci_bus; |
| 713 | struct pci_dev *dev; |
| 714 | struct pci_dev *ret = NULL; |
| 715 | |
| 716 | down_read(&pci_bus_sem); |
| 717 | list_for_each_entry(dev, &bus->devices, bus_list) |
| 718 | if (PCI_SLOT(dev->devfn) == slot->device) { |
| 719 | ret = pci_dev_get(dev); |
| 720 | break; |
| 721 | } |
| 722 | up_read(&pci_bus_sem); |
| 723 | |
| 724 | return ret; |
| 725 | } |
| 726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | /** |
| 728 | * disable_device - disable a slot |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 729 | * @slot: ACPI PHP slot |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | */ |
| 731 | static int disable_device(struct acpiphp_slot *slot) |
| 732 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | struct acpiphp_func *func; |
Alex Chiang | 9d911d7 | 2009-05-21 16:21:15 -0600 | [diff] [blame] | 734 | struct pci_dev *pdev; |
MUNEDA Takahiro | 551bcb7 | 2006-03-22 14:49:20 +0900 | [diff] [blame] | 735 | |
Amos Kong | ce29ca3 | 2012-05-23 10:20:35 -0600 | [diff] [blame] | 736 | /* |
| 737 | * enable_device() enumerates all functions in this device via |
| 738 | * pci_scan_slot(), whether they have associated ACPI hotplug |
| 739 | * methods (_EJ0, etc.) or not. Therefore, we remove all functions |
| 740 | * here. |
| 741 | */ |
| 742 | while ((pdev = dev_in_slot(slot))) { |
Bjorn Helgaas | 34e5484 | 2012-08-17 10:03:47 -0600 | [diff] [blame] | 743 | pci_stop_and_remove_bus_device(pdev); |
Amos Kong | ce29ca3 | 2012-05-23 10:20:35 -0600 | [diff] [blame] | 744 | pci_dev_put(pdev); |
Satoru Takeuchi | 600812e | 2006-09-12 10:22:53 -0700 | [diff] [blame] | 745 | } |
Satoru Takeuchi | 0dad351 | 2006-09-12 10:17:46 -0700 | [diff] [blame] | 746 | |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 747 | list_for_each_entry(func, &slot->funcs, sibling) |
| 748 | acpiphp_bus_trim(func_to_handle(func)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
| 750 | slot->flags &= (~SLOT_ENABLED); |
| 751 | |
Alex Chiang | 9d911d7 | 2009-05-21 16:21:15 -0600 | [diff] [blame] | 752 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | |
| 756 | /** |
| 757 | * get_slot_status - get ACPI slot status |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 758 | * @slot: ACPI PHP slot |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 760 | * If a slot has _STA for each function and if any one of them |
| 761 | * returned non-zero status, return it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 763 | * If a slot doesn't have _STA and if any one of its functions' |
| 764 | * configuration space is configured, return 0x0f as a _STA. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | * |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 766 | * Otherwise return 0. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | */ |
| 768 | static unsigned int get_slot_status(struct acpiphp_slot *slot) |
| 769 | { |
Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 770 | unsigned long long sta = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | struct acpiphp_func *func; |
| 772 | |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 773 | list_for_each_entry(func, &slot->funcs, sibling) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | if (func->flags & FUNC_HAS_STA) { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 775 | acpi_status status; |
| 776 | |
| 777 | status = acpi_evaluate_integer(func_to_handle(func), |
| 778 | "_STA", NULL, &sta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | if (ACPI_SUCCESS(status) && sta) |
| 780 | break; |
| 781 | } else { |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 782 | u32 dvid; |
| 783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | pci_bus_read_config_dword(slot->bridge->pci_bus, |
| 785 | PCI_DEVFN(slot->device, |
| 786 | func->function), |
| 787 | PCI_VENDOR_ID, &dvid); |
| 788 | if (dvid != 0xffffffff) { |
| 789 | sta = ACPI_STA_ALL; |
| 790 | break; |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | return (unsigned int)sta; |
| 796 | } |
| 797 | |
| 798 | /** |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 799 | * acpiphp_eject_slot - physically eject the slot |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 800 | * @slot: ACPI PHP slot |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 801 | */ |
Gary Hade | bfceafc | 2007-07-05 11:10:46 -0700 | [diff] [blame] | 802 | int acpiphp_eject_slot(struct acpiphp_slot *slot) |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 803 | { |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 804 | struct acpiphp_func *func; |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 805 | |
Alex Chiang | 58c0862 | 2009-10-26 21:25:27 -0600 | [diff] [blame] | 806 | list_for_each_entry(func, &slot->funcs, sibling) { |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 807 | /* We don't want to call _EJ0 on non-existing functions. */ |
Rafael J. Wysocki | 5a3bc57 | 2013-07-13 23:27:25 +0200 | [diff] [blame^] | 808 | if (!(func->flags & FUNC_HAS_EJ0)) |
| 809 | continue; |
| 810 | |
| 811 | if (ACPI_FAILURE(acpi_evaluate_ej0(func_to_handle(func)))) |
| 812 | return -1; |
| 813 | else |
| 814 | break; |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 815 | } |
| 816 | return 0; |
| 817 | } |
| 818 | |
| 819 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | * acpiphp_check_bridge - re-enumerate devices |
Randy Dunlap | 26e6c66 | 2007-11-28 09:04:30 -0800 | [diff] [blame] | 821 | * @bridge: where to begin re-enumeration |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | * |
| 823 | * Iterate over all slots under this bridge and make sure that if a |
| 824 | * card is present they are enabled, and if not they are disabled. |
| 825 | */ |
| 826 | static int acpiphp_check_bridge(struct acpiphp_bridge *bridge) |
| 827 | { |
| 828 | struct acpiphp_slot *slot; |
| 829 | int retval = 0; |
| 830 | int enabled, disabled; |
| 831 | |
| 832 | enabled = disabled = 0; |
| 833 | |
Yijing Wang | ad41dd9 | 2013-04-12 05:44:27 +0000 | [diff] [blame] | 834 | list_for_each_entry(slot, &bridge->slots, node) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | unsigned int status = get_slot_status(slot); |
| 836 | if (slot->flags & SLOT_ENABLED) { |
| 837 | if (status == ACPI_STA_ALL) |
| 838 | continue; |
| 839 | retval = acpiphp_disable_slot(slot); |
| 840 | if (retval) { |
| 841 | err("Error occurred in disabling\n"); |
| 842 | goto err_exit; |
Rajesh Shah | 8d50e33 | 2005-04-28 00:25:57 -0700 | [diff] [blame] | 843 | } else { |
| 844 | acpiphp_eject_slot(slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | } |
| 846 | disabled++; |
| 847 | } else { |
| 848 | if (status != ACPI_STA_ALL) |
| 849 | continue; |
| 850 | retval = acpiphp_enable_slot(slot); |
| 851 | if (retval) { |
| 852 | err("Error occurred in enabling\n"); |
| 853 | goto err_exit; |
| 854 | } |
| 855 | enabled++; |
| 856 | } |
| 857 | } |
| 858 | |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 859 | dbg("%s: %d enabled, %d disabled\n", __func__, enabled, disabled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
| 861 | err_exit: |
| 862 | return retval; |
| 863 | } |
| 864 | |
Bjorn Helgaas | fca6825 | 2009-09-14 16:35:10 -0600 | [diff] [blame] | 865 | static void acpiphp_set_hpp_values(struct pci_bus *bus) |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 866 | { |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 867 | struct pci_dev *dev; |
| 868 | |
Bjorn Helgaas | e81995b | 2009-09-14 16:35:35 -0600 | [diff] [blame] | 869 | list_for_each_entry(dev, &bus->devices, bus_list) |
| 870 | pci_configure_slot(dev); |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /* |
| 874 | * Remove devices for which we could not assign resources, call |
| 875 | * arch specific code to fix-up the bus |
| 876 | */ |
| 877 | static void acpiphp_sanitize_bus(struct pci_bus *bus) |
| 878 | { |
Yijing Wang | d65eba6 | 2013-04-12 05:44:17 +0000 | [diff] [blame] | 879 | struct pci_dev *dev, *tmp; |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 880 | int i; |
| 881 | unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM; |
| 882 | |
Yijing Wang | d65eba6 | 2013-04-12 05:44:17 +0000 | [diff] [blame] | 883 | list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) { |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 884 | for (i=0; i<PCI_BRIDGE_RESOURCES; i++) { |
| 885 | struct resource *res = &dev->resource[i]; |
| 886 | if ((res->flags & type_mask) && !res->start && |
| 887 | res->end) { |
| 888 | /* Could not assign a required resources |
| 889 | * for this device, remove it */ |
Yinghai Lu | 210647a | 2012-02-25 13:54:20 -0800 | [diff] [blame] | 890 | pci_stop_and_remove_bus_device(dev); |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 891 | break; |
| 892 | } |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | /* |
| 898 | * ACPI event handlers |
| 899 | */ |
| 900 | |
Gary Hade | 0bbd642 | 2007-07-05 11:10:48 -0700 | [diff] [blame] | 901 | static acpi_status |
Gary Hade | 0bbd642 | 2007-07-05 11:10:48 -0700 | [diff] [blame] | 902 | check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv) |
| 903 | { |
| 904 | struct acpiphp_bridge *bridge; |
| 905 | char objname[64]; |
| 906 | struct acpi_buffer buffer = { .length = sizeof(objname), |
| 907 | .pointer = objname }; |
| 908 | |
| 909 | bridge = acpiphp_handle_to_bridge(handle); |
| 910 | if (bridge) { |
| 911 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 912 | dbg("%s: re-enumerating slots under %s\n", |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 913 | __func__, objname); |
Gary Hade | 0bbd642 | 2007-07-05 11:10:48 -0700 | [diff] [blame] | 914 | acpiphp_check_bridge(bridge); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 915 | put_bridge(bridge); |
Gary Hade | 0bbd642 | 2007-07-05 11:10:48 -0700 | [diff] [blame] | 916 | } |
| 917 | return AE_OK ; |
| 918 | } |
| 919 | |
Yinghai Lu | 3f327e3 | 2013-05-07 11:06:03 -0600 | [diff] [blame] | 920 | void acpiphp_check_host_bridge(acpi_handle handle) |
| 921 | { |
| 922 | struct acpiphp_bridge *bridge; |
| 923 | |
| 924 | bridge = acpiphp_handle_to_bridge(handle); |
| 925 | if (bridge) { |
| 926 | acpiphp_check_bridge(bridge); |
| 927 | put_bridge(bridge); |
| 928 | } |
| 929 | |
| 930 | acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, |
| 931 | ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL, NULL); |
| 932 | } |
| 933 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 934 | static void hotplug_event(acpi_handle handle, u32 type, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | { |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 936 | struct acpiphp_context *context = data; |
Rafael J. Wysocki | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 937 | struct acpiphp_func *func = &context->func; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | struct acpiphp_bridge *bridge; |
| 939 | char objname[64]; |
| 940 | struct acpi_buffer buffer = { .length = sizeof(objname), |
| 941 | .pointer = objname }; |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 942 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 943 | mutex_lock(&acpiphp_context_lock); |
Rafael J. Wysocki | c8ebcf1 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 944 | bridge = context->bridge; |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 945 | if (bridge) |
| 946 | get_bridge(bridge); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 948 | mutex_unlock(&acpiphp_context_lock); |
Rafael J. Wysocki | 3757b94 | 2013-02-13 14:36:47 +0100 | [diff] [blame] | 949 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); |
| 951 | |
| 952 | switch (type) { |
| 953 | case ACPI_NOTIFY_BUS_CHECK: |
| 954 | /* bus re-enumerate */ |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 955 | dbg("%s: Bus check notify on %s\n", __func__, objname); |
Jiang Liu | be6d286 | 2013-01-31 00:10:10 +0800 | [diff] [blame] | 956 | dbg("%s: re-enumerating slots under %s\n", __func__, objname); |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 957 | if (bridge) { |
| 958 | acpiphp_check_bridge(bridge); |
| 959 | acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, |
| 960 | ACPI_UINT32_MAX, check_sub_bridges, |
| 961 | NULL, NULL, NULL); |
| 962 | } else { |
| 963 | acpiphp_enable_slot(func->slot); |
| 964 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | break; |
| 966 | |
| 967 | case ACPI_NOTIFY_DEVICE_CHECK: |
| 968 | /* device check */ |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 969 | dbg("%s: Device check notify on %s\n", __func__, objname); |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 970 | if (bridge) |
| 971 | acpiphp_check_bridge(bridge); |
| 972 | else |
| 973 | acpiphp_check_bridge(func->slot->bridge); |
| 974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | break; |
| 976 | |
| 977 | case ACPI_NOTIFY_DEVICE_WAKE: |
| 978 | /* wake event */ |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 979 | dbg("%s: Device wake notify on %s\n", __func__, objname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | break; |
| 981 | |
| 982 | case ACPI_NOTIFY_EJECT_REQUEST: |
| 983 | /* request device eject */ |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 984 | dbg("%s: Device eject notify on %s\n", __func__, objname); |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 985 | if (!(acpiphp_disable_slot(func->slot))) |
| 986 | acpiphp_eject_slot(func->slot); |
| 987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | break; |
| 989 | |
| 990 | case ACPI_NOTIFY_FREQUENCY_MISMATCH: |
| 991 | printk(KERN_ERR "Device %s cannot be configured due" |
| 992 | " to a frequency mismatch\n", objname); |
| 993 | break; |
| 994 | |
| 995 | case ACPI_NOTIFY_BUS_MODE_MISMATCH: |
| 996 | printk(KERN_ERR "Device %s cannot be configured due" |
| 997 | " to a bus mode mismatch\n", objname); |
| 998 | break; |
| 999 | |
| 1000 | case ACPI_NOTIFY_POWER_FAULT: |
| 1001 | printk(KERN_ERR "Device %s has suffered a power fault\n", |
| 1002 | objname); |
| 1003 | break; |
| 1004 | |
| 1005 | default: |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1006 | warn("notify_handler: unknown event type 0x%x for %s\n", type, |
| 1007 | objname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | break; |
| 1009 | } |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1010 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1011 | if (bridge) |
| 1012 | put_bridge(bridge); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1015 | static void hotplug_event_work(struct work_struct *work) |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 1016 | { |
Rafael J. Wysocki | c8ebcf1 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1017 | struct acpiphp_context *context; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 1018 | struct acpi_hp_work *hp_work; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 1019 | |
| 1020 | hp_work = container_of(work, struct acpi_hp_work, work); |
Rafael J. Wysocki | c8ebcf1 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1021 | context = hp_work->context; |
Rafael J. Wysocki | 21a3101 | 2013-06-24 11:22:53 +0200 | [diff] [blame] | 1022 | acpi_scan_lock_acquire(); |
| 1023 | |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1024 | hotplug_event(hp_work->handle, hp_work->type, context); |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1025 | |
Rafael J. Wysocki | 3757b94 | 2013-02-13 14:36:47 +0100 | [diff] [blame] | 1026 | acpi_scan_lock_release(); |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1027 | kfree(hp_work); /* allocated in handle_hotplug_event() */ |
Rafael J. Wysocki | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 1028 | put_bridge(context->func.slot->bridge); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1031 | /** |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1032 | * handle_hotplug_event - handle ACPI hotplug event |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1033 | * @handle: Notify()'ed acpi_handle |
| 1034 | * @type: Notify code |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1035 | * @data: pointer to acpiphp_context structure |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1036 | * |
| 1037 | * Handles ACPI event notification on slots. |
| 1038 | */ |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1039 | static void handle_hotplug_event(acpi_handle handle, u32 type, void *data) |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1040 | { |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1041 | struct acpiphp_context *context; |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1042 | |
| 1043 | mutex_lock(&acpiphp_context_lock); |
| 1044 | context = acpiphp_get_context(handle); |
| 1045 | if (context) { |
Rafael J. Wysocki | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 1046 | get_bridge(context->func.slot->bridge); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1047 | acpiphp_put_context(context); |
Rafael J. Wysocki | 8783127 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1048 | } |
| 1049 | mutex_unlock(&acpiphp_context_lock); |
Prarit Bhargava | 6af8bef | 2011-09-28 19:40:53 -0400 | [diff] [blame] | 1050 | /* |
| 1051 | * Currently the code adds all hotplug events to the kacpid_wq |
| 1052 | * queue when it should add hotplug events to the kacpi_hotplug_wq. |
| 1053 | * The proper way to fix this is to reorganize the code so that |
| 1054 | * drivers (dock, etc.) do not call acpi_os_execute(), etc. |
| 1055 | * For now just re-add this work to the kacpi_hotplug_wq so we |
| 1056 | * don't deadlock on hotplug actions. |
| 1057 | */ |
Rafael J. Wysocki | 43e5c09 | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1058 | if (context) |
| 1059 | alloc_acpi_hp_work(handle, type, context, hotplug_event_work); |
Rajesh Shah | 8e7561c | 2005-04-28 00:25:56 -0700 | [diff] [blame] | 1060 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1062 | /* |
| 1063 | * Create hotplug slots for the PCI bus. |
| 1064 | * It should always return 0 to avoid skipping following notifiers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | */ |
Rafael J. Wysocki | be1c9de | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 1066 | void acpiphp_enumerate_slots(struct pci_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | { |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1068 | struct acpiphp_bridge *bridge; |
Rafael J. Wysocki | 2552002a | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 1069 | acpi_handle handle; |
| 1070 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1072 | if (acpiphp_disabled) |
| 1073 | return; |
| 1074 | |
Rafael J. Wysocki | be1c9de | 2013-07-13 23:27:23 +0200 | [diff] [blame] | 1075 | handle = ACPI_HANDLE(bus->bridge); |
Rafael J. Wysocki | bbd34fc | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1076 | if (!handle) |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1077 | return; |
| 1078 | |
| 1079 | bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL); |
Rafael J. Wysocki | cb7b8ce | 2013-07-13 23:27:24 +0200 | [diff] [blame] | 1080 | if (!bridge) { |
| 1081 | acpi_handle_err(handle, "No memory for bridge object\n"); |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1082 | return; |
| 1083 | } |
| 1084 | |
Yijing Wang | ad41dd9 | 2013-04-12 05:44:27 +0000 | [diff] [blame] | 1085 | INIT_LIST_HEAD(&bridge->slots); |
Jiang Liu | 3d54a31 | 2013-04-12 05:44:28 +0000 | [diff] [blame] | 1086 | kref_init(&bridge->ref); |
Jiang Liu | 3b63aaa | 2013-04-12 05:44:26 +0000 | [diff] [blame] | 1087 | bridge->handle = handle; |
| 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 | bd4674d | 2013-07-13 23:27:25 +0200 | [diff] [blame] | 1117 | get_bridge(context->func.slot->bridge); |
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 */ |
| 1127 | status = acpi_walk_namespace(ACPI_TYPE_DEVICE, bridge->handle, 1, |
| 1128 | register_slot, NULL, bridge, NULL); |
| 1129 | if (ACPI_FAILURE(status)) { |
| 1130 | acpi_handle_err(bridge->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 | } |