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