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