2 * ACPI PCI HotPlug glue functions to ACPI CA subsystem
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
7 * Copyright (C) 2003-2005 Matthew Wilcox (matthew.wilcox@hp.com)
8 * Copyright (C) 2003-2005 Hewlett Packard
9 * Copyright (C) 2005 Rajesh Shah (rajesh.shah@intel.com)
10 * Copyright (C) 2005 Intel Corporation
12 * All rights reserved.
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.
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
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.
29 * Send feedback to <kristen.c.accardi@intel.com>
34 * Lifetime rules for pci_dev:
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
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.
42 #define pr_fmt(fmt) "acpiphp_glue: " fmt
44 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/pci.h>
48 #include <linux/pci_hotplug.h>
49 #include <linux/pci-acpi.h>
50 #include <linux/pm_runtime.h>
51 #include <linux/mutex.h>
52 #include <linux/slab.h>
53 #include <linux/acpi.h>
58 static LIST_HEAD(bridge_list);
59 static DEFINE_MUTEX(bridge_mutex);
61 static int acpiphp_hotplug_notify(struct acpi_device *adev, u32 type);
62 static void acpiphp_post_dock_fixup(struct acpi_device *adev);
63 static void acpiphp_sanitize_bus(struct pci_bus *bus);
64 static void acpiphp_set_hpp_values(struct pci_bus *bus);
65 static void hotplug_event(u32 type, struct acpiphp_context *context);
66 static void free_bridge(struct kref *kref);
69 * acpiphp_init_context - Create hotplug context and grab a reference to it.
70 * @adev: ACPI device object to create the context for.
72 * Call under acpi_hp_context_lock.
74 static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev)
76 struct acpiphp_context *context;
78 context = kzalloc(sizeof(*context), GFP_KERNEL);
82 context->refcount = 1;
83 context->hp.notify = acpiphp_hotplug_notify;
84 context->hp.fixup = acpiphp_post_dock_fixup;
85 acpi_set_hp_context(adev, &context->hp);
90 * acpiphp_get_context - Get hotplug context and grab a reference to it.
91 * @adev: ACPI device object to get the context for.
93 * Call under acpi_hp_context_lock.
95 static struct acpiphp_context *acpiphp_get_context(struct acpi_device *adev)
97 struct acpiphp_context *context;
102 context = to_acpiphp_context(adev->hp);
108 * acpiphp_put_context - Drop a reference to ACPI hotplug context.
109 * @context: ACPI hotplug context to drop a reference to.
111 * The context object is removed if there are no more references to it.
113 * Call under acpi_hp_context_lock.
115 static void acpiphp_put_context(struct acpiphp_context *context)
117 if (--context->refcount)
120 WARN_ON(context->bridge);
121 context->hp.self->hp = NULL;
125 static inline void get_bridge(struct acpiphp_bridge *bridge)
127 kref_get(&bridge->ref);
130 static inline void put_bridge(struct acpiphp_bridge *bridge)
132 kref_put(&bridge->ref, free_bridge);
135 static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev)
137 struct acpiphp_context *context;
139 acpi_lock_hp_context();
140 context = acpiphp_get_context(adev);
141 if (!context || context->func.parent->is_going_away) {
142 acpi_unlock_hp_context();
145 get_bridge(context->func.parent);
146 acpiphp_put_context(context);
147 acpi_unlock_hp_context();
151 static void acpiphp_let_context_go(struct acpiphp_context *context)
153 put_bridge(context->func.parent);
156 static void free_bridge(struct kref *kref)
158 struct acpiphp_context *context;
159 struct acpiphp_bridge *bridge;
160 struct acpiphp_slot *slot, *next;
161 struct acpiphp_func *func, *tmp;
163 acpi_lock_hp_context();
165 bridge = container_of(kref, struct acpiphp_bridge, ref);
167 list_for_each_entry_safe(slot, next, &bridge->slots, node) {
168 list_for_each_entry_safe(func, tmp, &slot->funcs, sibling)
169 acpiphp_put_context(func_to_context(func));
174 context = bridge->context;
175 /* Root bridges will not have hotplug context. */
177 /* Release the reference taken by acpiphp_enumerate_slots(). */
178 put_bridge(context->func.parent);
179 context->bridge = NULL;
180 acpiphp_put_context(context);
183 put_device(&bridge->pci_bus->dev);
184 pci_dev_put(bridge->pci_dev);
187 acpi_unlock_hp_context();
191 * acpiphp_post_dock_fixup - Post-dock fixups for PCI devices.
192 * @adev: ACPI device object corresponding to a PCI device.
194 * TBD - figure out a way to only call fixups for systems that require them.
196 static void acpiphp_post_dock_fixup(struct acpi_device *adev)
198 struct acpiphp_context *context = acpiphp_grab_context(adev);
205 bus = context->func.slot->bus;
209 /* fixup bad _DCK function that rewrites
210 * secondary bridge on slot
212 pci_read_config_dword(bus->self, PCI_PRIMARY_BUS, &buses);
214 if (((buses >> 8) & 0xff) != bus->busn_res.start) {
215 buses = (buses & 0xff000000)
216 | ((unsigned int)(bus->primary) << 0)
217 | ((unsigned int)(bus->busn_res.start) << 8)
218 | ((unsigned int)(bus->busn_res.end) << 16);
219 pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses);
223 acpiphp_let_context_go(context);
226 /* Check whether the PCI device is managed by native PCIe hotplug driver */
227 static bool device_is_managed_by_native_pciehp(struct pci_dev *pdev)
231 struct acpi_pci_root *root;
233 /* Check whether the PCIe port supports native PCIe hotplug */
234 if (pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, ®32))
236 if (!(reg32 & PCI_EXP_SLTCAP_HPC))
240 * Check whether native PCIe hotplug has been enabled for
241 * this PCIe hierarchy.
243 tmp = acpi_find_root_bridge_handle(pdev);
246 root = acpi_pci_find_root(tmp);
249 if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL))
256 * acpiphp_add_context - Add ACPIPHP context to an ACPI device object.
257 * @handle: ACPI handle of the object to add a context to.
259 * @data: The object's parent ACPIPHP bridge.
262 static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data,
265 struct acpiphp_bridge *bridge = data;
266 struct acpiphp_context *context;
267 struct acpi_device *adev;
268 struct acpiphp_slot *slot;
269 struct acpiphp_func *newfunc;
270 acpi_status status = AE_OK;
271 unsigned long long adr;
272 int device, function;
273 struct pci_bus *pbus = bridge->pci_bus;
274 struct pci_dev *pdev = bridge->pci_dev;
277 status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
278 if (ACPI_FAILURE(status)) {
279 if (status != AE_NOT_FOUND)
280 acpi_handle_warn(handle,
281 "can't evaluate _ADR (%#x)\n", status);
284 if (acpi_bus_get_device(handle, &adev))
287 device = (adr >> 16) & 0xffff;
288 function = adr & 0xffff;
290 acpi_lock_hp_context();
291 context = acpiphp_init_context(adev);
293 acpi_unlock_hp_context();
294 acpi_handle_err(handle, "No hotplug context\n");
297 newfunc = &context->func;
298 newfunc->function = function;
299 newfunc->parent = bridge;
300 acpi_unlock_hp_context();
303 * If this is a dock device, its _EJ0 should be executed by the dock
304 * notify handler after calling _DCK.
306 if (!is_dock_device(adev) && acpi_has_method(handle, "_EJ0"))
307 newfunc->flags = FUNC_HAS_EJ0;
309 if (acpi_has_method(handle, "_STA"))
310 newfunc->flags |= FUNC_HAS_STA;
312 /* search for objects that share the same slot */
313 list_for_each_entry(slot, &bridge->slots, node)
314 if (slot->device == device)
317 slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
319 acpi_lock_hp_context();
320 acpiphp_put_context(context);
321 acpi_unlock_hp_context();
325 slot->bus = bridge->pci_bus;
326 slot->device = device;
327 INIT_LIST_HEAD(&slot->funcs);
329 list_add_tail(&slot->node, &bridge->slots);
332 * Expose slots to user space for functions that have _EJ0 or _RMV or
333 * are located in dock stations. Do not expose them for devices handled
334 * by the native PCIe hotplug (PCIeHP), becuase that code is supposed to
335 * expose slots to user space in those cases.
337 if ((acpi_pci_check_ejectable(pbus, handle) || is_dock_device(adev))
338 && !(pdev && device_is_managed_by_native_pciehp(pdev))) {
339 unsigned long long sun;
343 status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
344 if (ACPI_FAILURE(status))
345 sun = bridge->nr_slots;
347 pr_debug("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
348 sun, pci_domain_nr(pbus), pbus->number, device);
350 retval = acpiphp_register_hotplug_slot(slot, sun);
354 if (retval == -EBUSY)
355 pr_warn("Slot %llu already registered by another hotplug driver\n", sun);
357 pr_warn("acpiphp_register_hotplug_slot failed (err code = 0x%x)\n", retval);
359 /* Even if the slot registration fails, we can still use it. */
363 newfunc->slot = slot;
364 list_add_tail(&newfunc->sibling, &slot->funcs);
366 if (pci_bus_read_dev_vendor_id(pbus, PCI_DEVFN(device, function),
368 slot->flags |= SLOT_ENABLED;
373 static void cleanup_bridge(struct acpiphp_bridge *bridge)
375 struct acpiphp_slot *slot;
376 struct acpiphp_func *func;
378 list_for_each_entry(slot, &bridge->slots, node) {
379 list_for_each_entry(func, &slot->funcs, sibling) {
380 struct acpi_device *adev = func_to_acpi_device(func);
382 acpi_lock_hp_context();
383 adev->hp->notify = NULL;
384 adev->hp->fixup = NULL;
385 acpi_unlock_hp_context();
387 slot->flags |= SLOT_IS_GOING_AWAY;
389 acpiphp_unregister_hotplug_slot(slot);
392 mutex_lock(&bridge_mutex);
393 list_del(&bridge->list);
394 mutex_unlock(&bridge_mutex);
396 acpi_lock_hp_context();
397 bridge->is_going_away = true;
398 acpi_unlock_hp_context();
402 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
403 * @bus: bus to start search with
405 static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
408 unsigned char max, n;
411 * pci_bus_max_busnr will return the highest
412 * reserved busnr for all these children.
413 * that is equivalent to the bus->subordinate
414 * value. We don't want to use the parent's
415 * bus->subordinate value because it could have
418 max = bus->busn_res.start;
420 list_for_each_entry(tmp, &bus->children, node) {
421 n = pci_bus_max_busnr(tmp);
428 static void acpiphp_set_acpi_region(struct acpiphp_slot *slot)
430 struct acpiphp_func *func;
431 union acpi_object params[2];
432 struct acpi_object_list arg_list;
434 list_for_each_entry(func, &slot->funcs, sibling) {
436 arg_list.pointer = params;
437 params[0].type = ACPI_TYPE_INTEGER;
438 params[0].integer.value = ACPI_ADR_SPACE_PCI_CONFIG;
439 params[1].type = ACPI_TYPE_INTEGER;
440 params[1].integer.value = 1;
441 /* _REG is optional, we don't care about if there is failure */
442 acpi_evaluate_object(func_to_handle(func), "_REG", &arg_list,
447 static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev)
449 struct acpiphp_func *func;
451 /* quirk, or pcie could set it already */
452 if (dev->is_hotplug_bridge)
455 list_for_each_entry(func, &slot->funcs, sibling) {
456 if (PCI_FUNC(dev->devfn) == func->function) {
457 dev->is_hotplug_bridge = 1;
463 static int acpiphp_rescan_slot(struct acpiphp_slot *slot)
465 struct acpiphp_func *func;
467 list_for_each_entry(func, &slot->funcs, sibling) {
468 struct acpi_device *adev = func_to_acpi_device(func);
470 acpi_bus_scan(adev->handle);
471 if (acpi_device_enumerated(adev))
472 acpi_device_set_power(adev, ACPI_STATE_D0);
474 return pci_scan_slot(slot->bus, PCI_DEVFN(slot->device, 0));
478 * enable_slot - enable, configure a slot
479 * @slot: slot to be enabled
481 * This function should be called per *physical slot*,
482 * not per each slot object in ACPI namespace.
484 static void enable_slot(struct acpiphp_slot *slot)
487 struct pci_bus *bus = slot->bus;
488 struct acpiphp_func *func;
492 acpiphp_rescan_slot(slot);
493 max = acpiphp_max_busnr(bus);
494 for (pass = 0; pass < 2; pass++) {
495 list_for_each_entry(dev, &bus->devices, bus_list) {
496 if (PCI_SLOT(dev->devfn) != slot->device)
499 if (pci_is_bridge(dev)) {
500 max = pci_scan_bridge(bus, dev, max, pass);
501 if (pass && dev->subordinate) {
502 check_hotplug_bridge(slot, dev);
503 pcibios_resource_survey_bus(dev->subordinate);
504 __pci_bus_size_bridges(dev->subordinate,
510 __pci_bus_assign_resources(bus, &add_list, NULL);
512 acpiphp_sanitize_bus(bus);
513 acpiphp_set_hpp_values(bus);
514 acpiphp_set_acpi_region(slot);
516 list_for_each_entry(dev, &bus->devices, bus_list) {
517 /* Assume that newly added devices are powered on already. */
519 dev->current_state = PCI_D0;
522 pci_bus_add_devices(bus);
524 slot->flags |= SLOT_ENABLED;
525 list_for_each_entry(func, &slot->funcs, sibling) {
526 dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
529 /* Do not set SLOT_ENABLED flag if some funcs
531 slot->flags &= (~SLOT_ENABLED);
538 * disable_slot - disable a slot
539 * @slot: ACPI PHP slot
541 static void disable_slot(struct acpiphp_slot *slot)
543 struct pci_bus *bus = slot->bus;
544 struct pci_dev *dev, *prev;
545 struct acpiphp_func *func;
548 * enable_slot() enumerates all functions in this device via
549 * pci_scan_slot(), whether they have associated ACPI hotplug
550 * methods (_EJ0, etc.) or not. Therefore, we remove all functions
553 list_for_each_entry_safe_reverse(dev, prev, &bus->devices, bus_list)
554 if (PCI_SLOT(dev->devfn) == slot->device)
555 pci_stop_and_remove_bus_device(dev);
557 list_for_each_entry(func, &slot->funcs, sibling)
558 acpi_bus_trim(func_to_acpi_device(func));
560 slot->flags &= (~SLOT_ENABLED);
563 static bool acpiphp_no_hotplug(struct acpi_device *adev)
565 return adev && adev->flags.no_hotplug;
568 static bool slot_no_hotplug(struct acpiphp_slot *slot)
570 struct acpiphp_func *func;
572 list_for_each_entry(func, &slot->funcs, sibling)
573 if (acpiphp_no_hotplug(func_to_acpi_device(func)))
580 * get_slot_status - get ACPI slot status
581 * @slot: ACPI PHP slot
583 * If a slot has _STA for each function and if any one of them
584 * returned non-zero status, return it.
586 * If a slot doesn't have _STA and if any one of its functions'
587 * configuration space is configured, return 0x0f as a _STA.
589 * Otherwise return 0.
591 static unsigned int get_slot_status(struct acpiphp_slot *slot)
593 unsigned long long sta = 0;
594 struct acpiphp_func *func;
596 list_for_each_entry(func, &slot->funcs, sibling) {
597 if (func->flags & FUNC_HAS_STA) {
600 status = acpi_evaluate_integer(func_to_handle(func),
602 if (ACPI_SUCCESS(status) && sta)
607 pci_bus_read_config_dword(slot->bus,
608 PCI_DEVFN(slot->device,
610 PCI_VENDOR_ID, &dvid);
611 if (dvid != 0xffffffff) {
618 return (unsigned int)sta;
621 static inline bool device_status_valid(unsigned int sta)
624 * ACPI spec says that _STA may return bit 0 clear with bit 3 set
625 * if the device is valid but does not require a device driver to be
626 * loaded (Section 6.3.7 of ACPI 5.0A).
628 unsigned int mask = ACPI_STA_DEVICE_ENABLED | ACPI_STA_DEVICE_FUNCTIONING;
629 return (sta & mask) == mask;
633 * trim_stale_devices - remove PCI devices that are not responding.
634 * @dev: PCI device to start walking the hierarchy from.
636 static void trim_stale_devices(struct pci_dev *dev)
638 struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
639 struct pci_bus *bus = dev->subordinate;
644 unsigned long long sta;
646 status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
647 alive = (ACPI_SUCCESS(status) && device_status_valid(sta))
648 || acpiphp_no_hotplug(adev);
651 alive = pci_device_is_present(dev);
654 pci_stop_and_remove_bus_device(dev);
658 struct pci_dev *child, *tmp;
660 /* The device is a bridge. so check the bus below it. */
661 pm_runtime_get_sync(&dev->dev);
662 list_for_each_entry_safe_reverse(child, tmp, &bus->devices, bus_list)
663 trim_stale_devices(child);
665 pm_runtime_put(&dev->dev);
670 * acpiphp_check_bridge - re-enumerate devices
671 * @bridge: where to begin re-enumeration
673 * Iterate over all slots under this bridge and make sure that if a
674 * card is present they are enabled, and if not they are disabled.
676 static void acpiphp_check_bridge(struct acpiphp_bridge *bridge)
678 struct acpiphp_slot *slot;
680 /* Bail out if the bridge is going away. */
681 if (bridge->is_going_away)
684 list_for_each_entry(slot, &bridge->slots, node) {
685 struct pci_bus *bus = slot->bus;
686 struct pci_dev *dev, *tmp;
688 if (slot_no_hotplug(slot)) {
690 } else if (device_status_valid(get_slot_status(slot))) {
691 /* remove stale devices if any */
692 list_for_each_entry_safe_reverse(dev, tmp,
693 &bus->devices, bus_list)
694 if (PCI_SLOT(dev->devfn) == slot->device)
695 trim_stale_devices(dev);
697 /* configure all functions */
705 static void acpiphp_set_hpp_values(struct pci_bus *bus)
709 list_for_each_entry(dev, &bus->devices, bus_list)
710 pci_configure_slot(dev);
714 * Remove devices for which we could not assign resources, call
715 * arch specific code to fix-up the bus
717 static void acpiphp_sanitize_bus(struct pci_bus *bus)
719 struct pci_dev *dev, *tmp;
721 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
723 list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list) {
724 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
725 struct resource *res = &dev->resource[i];
726 if ((res->flags & type_mask) && !res->start &&
728 /* Could not assign a required resources
729 * for this device, remove it */
730 pci_stop_and_remove_bus_device(dev);
738 * ACPI event handlers
741 void acpiphp_check_host_bridge(struct acpi_device *adev)
743 struct acpiphp_bridge *bridge = NULL;
745 acpi_lock_hp_context();
747 bridge = to_acpiphp_root_context(adev->hp)->root_bridge;
751 acpi_unlock_hp_context();
753 pci_lock_rescan_remove();
755 acpiphp_check_bridge(bridge);
757 pci_unlock_rescan_remove();
762 static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot);
764 static void hotplug_event(u32 type, struct acpiphp_context *context)
766 acpi_handle handle = context->hp.self->handle;
767 struct acpiphp_func *func = &context->func;
768 struct acpiphp_slot *slot = func->slot;
769 struct acpiphp_bridge *bridge;
771 acpi_lock_hp_context();
772 bridge = context->bridge;
776 acpi_unlock_hp_context();
778 pci_lock_rescan_remove();
781 case ACPI_NOTIFY_BUS_CHECK:
782 /* bus re-enumerate */
783 acpi_handle_debug(handle, "Bus check in %s()\n", __func__);
785 acpiphp_check_bridge(bridge);
786 else if (!(slot->flags & SLOT_IS_GOING_AWAY))
791 case ACPI_NOTIFY_DEVICE_CHECK:
793 acpi_handle_debug(handle, "Device check in %s()\n", __func__);
795 acpiphp_check_bridge(bridge);
796 } else if (!(slot->flags & SLOT_IS_GOING_AWAY)) {
798 * Check if anything has changed in the slot and rescan
799 * from the parent if that's the case.
801 if (acpiphp_rescan_slot(slot))
802 acpiphp_check_bridge(func->parent);
806 case ACPI_NOTIFY_EJECT_REQUEST:
807 /* request device eject */
808 acpi_handle_debug(handle, "Eject request in %s()\n", __func__);
809 acpiphp_disable_and_eject_slot(slot);
813 pci_unlock_rescan_remove();
818 static int acpiphp_hotplug_notify(struct acpi_device *adev, u32 type)
820 struct acpiphp_context *context;
822 context = acpiphp_grab_context(adev);
826 hotplug_event(type, context);
827 acpiphp_let_context_go(context);
832 * acpiphp_enumerate_slots - Enumerate PCI slots for a given bus.
833 * @bus: PCI bus to enumerate the slots for.
835 * A "slot" is an object associated with a PCI device number. All functions
836 * (PCI devices) with the same bus and device number belong to the same slot.
838 void acpiphp_enumerate_slots(struct pci_bus *bus)
840 struct acpiphp_bridge *bridge;
841 struct acpi_device *adev;
845 if (acpiphp_disabled)
848 adev = ACPI_COMPANION(bus->bridge);
852 handle = adev->handle;
853 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
855 acpi_handle_err(handle, "No memory for bridge object\n");
859 INIT_LIST_HEAD(&bridge->slots);
860 kref_init(&bridge->ref);
861 bridge->pci_dev = pci_dev_get(bus->self);
862 bridge->pci_bus = bus;
865 * Grab a ref to the subordinate PCI bus in case the bus is
866 * removed via PCI core logical hotplug. The ref pins the bus
867 * (which we access during module unload).
869 get_device(&bus->dev);
871 acpi_lock_hp_context();
872 if (pci_is_root_bus(bridge->pci_bus)) {
873 struct acpiphp_root_context *root_context;
875 root_context = kzalloc(sizeof(*root_context), GFP_KERNEL);
879 root_context->root_bridge = bridge;
880 acpi_set_hp_context(adev, &root_context->hp);
882 struct acpiphp_context *context;
885 * This bridge should have been registered as a hotplug function
886 * under its parent, so the context should be there, unless the
887 * parent is going to be handled by pciehp, in which case this
888 * bridge is not interesting to us either.
890 context = acpiphp_get_context(adev);
894 bridge->context = context;
895 context->bridge = bridge;
896 /* Get a reference to the parent bridge. */
897 get_bridge(context->func.parent);
899 acpi_unlock_hp_context();
901 /* Must be added to the list prior to calling acpiphp_add_context(). */
902 mutex_lock(&bridge_mutex);
903 list_add(&bridge->list, &bridge_list);
904 mutex_unlock(&bridge_mutex);
906 /* register all slot objects under this bridge */
907 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
908 acpiphp_add_context, NULL, bridge, NULL);
909 if (ACPI_FAILURE(status)) {
910 acpi_handle_err(handle, "failed to register slots\n");
911 cleanup_bridge(bridge);
917 acpi_unlock_hp_context();
918 put_device(&bus->dev);
919 pci_dev_put(bridge->pci_dev);
923 static void acpiphp_drop_bridge(struct acpiphp_bridge *bridge)
925 if (pci_is_root_bus(bridge->pci_bus)) {
926 struct acpiphp_root_context *root_context;
927 struct acpi_device *adev;
929 acpi_lock_hp_context();
930 adev = ACPI_COMPANION(bridge->pci_bus->bridge);
931 root_context = to_acpiphp_root_context(adev->hp);
933 acpi_unlock_hp_context();
936 cleanup_bridge(bridge);
941 * acpiphp_remove_slots - Remove slot objects associated with a given bus.
942 * @bus: PCI bus to remove the slot objects for.
944 void acpiphp_remove_slots(struct pci_bus *bus)
946 struct acpiphp_bridge *bridge;
948 if (acpiphp_disabled)
951 mutex_lock(&bridge_mutex);
952 list_for_each_entry(bridge, &bridge_list, list)
953 if (bridge->pci_bus == bus) {
954 mutex_unlock(&bridge_mutex);
955 acpiphp_drop_bridge(bridge);
959 mutex_unlock(&bridge_mutex);
963 * acpiphp_enable_slot - power on slot
964 * @slot: ACPI PHP slot
966 int acpiphp_enable_slot(struct acpiphp_slot *slot)
968 pci_lock_rescan_remove();
970 if (slot->flags & SLOT_IS_GOING_AWAY)
973 /* configure all functions */
974 if (!(slot->flags & SLOT_ENABLED))
977 pci_unlock_rescan_remove();
982 * acpiphp_disable_and_eject_slot - power off and eject slot
983 * @slot: ACPI PHP slot
985 static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot)
987 struct acpiphp_func *func;
989 if (slot->flags & SLOT_IS_GOING_AWAY)
992 /* unconfigure all functions */
995 list_for_each_entry(func, &slot->funcs, sibling)
996 if (func->flags & FUNC_HAS_EJ0) {
997 acpi_handle handle = func_to_handle(func);
999 if (ACPI_FAILURE(acpi_evaluate_ej0(handle)))
1000 acpi_handle_err(handle, "_EJ0 failed\n");
1008 int acpiphp_disable_slot(struct acpiphp_slot *slot)
1013 * Acquire acpi_scan_lock to ensure that the execution of _EJ0 in
1014 * acpiphp_disable_and_eject_slot() will be synchronized properly.
1016 acpi_scan_lock_acquire();
1017 pci_lock_rescan_remove();
1018 ret = acpiphp_disable_and_eject_slot(slot);
1019 pci_unlock_rescan_remove();
1020 acpi_scan_lock_release();
1028 u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
1030 return (slot->flags & SLOT_ENABLED);
1037 u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1039 return !(get_slot_status(slot) & ACPI_STA_DEVICE_UI);
1043 * adapter presence : 1
1046 u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1048 return !!get_slot_status(slot);