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