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