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