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/init.h>
45 #include <linux/module.h>
47 #include <linux/kernel.h>
48 #include <linux/pci.h>
49 #include <linux/pci_hotplug.h>
50 #include <linux/pci-acpi.h>
51 #include <linux/pm_runtime.h>
52 #include <linux/mutex.h>
53 #include <linux/slab.h>
54 #include <linux/acpi.h>
59 static LIST_HEAD(bridge_list);
60 static DEFINE_MUTEX(bridge_mutex);
62 static int acpiphp_hotplug_event(struct acpi_device *adev, u32 type);
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 acpi_set_hp_context(adev, &context->hp, acpiphp_hotplug_event);
88 * acpiphp_get_context - Get hotplug context and grab a reference to it.
89 * @adev: ACPI device object to get the context for.
91 * Call under acpi_hp_context_lock.
93 static struct acpiphp_context *acpiphp_get_context(struct acpi_device *adev)
95 struct acpiphp_context *context;
100 context = to_acpiphp_context(adev->hp);
106 * acpiphp_put_context - Drop a reference to ACPI hotplug context.
107 * @context: ACPI hotplug context to drop a reference to.
109 * The context object is removed if there are no more references to it.
111 * Call under acpi_hp_context_lock.
113 static void acpiphp_put_context(struct acpiphp_context *context)
115 if (--context->refcount)
118 WARN_ON(context->bridge);
119 context->hp.self->hp = NULL;
123 static inline void get_bridge(struct acpiphp_bridge *bridge)
125 kref_get(&bridge->ref);
128 static inline void put_bridge(struct acpiphp_bridge *bridge)
130 kref_put(&bridge->ref, free_bridge);
133 static void free_bridge(struct kref *kref)
135 struct acpiphp_context *context;
136 struct acpiphp_bridge *bridge;
137 struct acpiphp_slot *slot, *next;
138 struct acpiphp_func *func, *tmp;
140 acpi_lock_hp_context();
142 bridge = container_of(kref, struct acpiphp_bridge, ref);
144 list_for_each_entry_safe(slot, next, &bridge->slots, node) {
145 list_for_each_entry_safe(func, tmp, &slot->funcs, sibling)
146 acpiphp_put_context(func_to_context(func));
151 context = bridge->context;
152 /* Root bridges will not have hotplug context. */
154 /* Release the reference taken by acpiphp_enumerate_slots(). */
155 put_bridge(context->func.parent);
156 context->bridge = NULL;
157 acpiphp_put_context(context);
160 put_device(&bridge->pci_bus->dev);
161 pci_dev_put(bridge->pci_dev);
164 acpi_unlock_hp_context();
168 * the _DCK method can do funny things... and sometimes not
171 * TBD - figure out a way to only call fixups for
172 * systems that require them.
174 static void post_dock_fixups(acpi_handle not_used, u32 event, void *data)
176 struct acpiphp_context *context = data;
177 struct pci_bus *bus = context->func.slot->bus;
183 /* fixup bad _DCK function that rewrites
184 * secondary bridge on slot
186 pci_read_config_dword(bus->self,
190 if (((buses >> 8) & 0xff) != bus->busn_res.start) {
191 buses = (buses & 0xff000000)
192 | ((unsigned int)(bus->primary) << 0)
193 | ((unsigned int)(bus->busn_res.start) << 8)
194 | ((unsigned int)(bus->busn_res.end) << 16);
195 pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses);
199 static void dock_event(acpi_handle handle, u32 type, void *data)
201 struct acpi_device *adev;
203 adev = acpi_bus_get_acpi_device(handle);
205 acpiphp_hotplug_event(adev, type);
206 acpi_bus_put_acpi_device(adev);
210 static const struct acpi_dock_ops acpiphp_dock_ops = {
211 .fixup = post_dock_fixups,
212 .handler = dock_event,
215 /* Check whether the PCI device is managed by native PCIe hotplug driver */
216 static bool device_is_managed_by_native_pciehp(struct pci_dev *pdev)
220 struct acpi_pci_root *root;
222 /* Check whether the PCIe port supports native PCIe hotplug */
223 if (pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, ®32))
225 if (!(reg32 & PCI_EXP_SLTCAP_HPC))
229 * Check whether native PCIe hotplug has been enabled for
230 * this PCIe hierarchy.
232 tmp = acpi_find_root_bridge_handle(pdev);
235 root = acpi_pci_find_root(tmp);
238 if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL))
244 static void acpiphp_dock_init(void *data)
246 struct acpiphp_context *context = data;
248 get_bridge(context->func.parent);
251 static void acpiphp_dock_release(void *data)
253 struct acpiphp_context *context = data;
255 put_bridge(context->func.parent);
258 /* callback routine to register each ACPI PCI slot object */
259 static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data,
262 struct acpiphp_bridge *bridge = data;
263 struct acpiphp_context *context;
264 struct acpi_device *adev;
265 struct acpiphp_slot *slot;
266 struct acpiphp_func *newfunc;
267 acpi_status status = AE_OK;
268 unsigned long long adr;
269 int device, function;
270 struct pci_bus *pbus = bridge->pci_bus;
271 struct pci_dev *pdev = bridge->pci_dev;
274 if (pdev && device_is_managed_by_native_pciehp(pdev))
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;
301 if (acpi_has_method(handle, "_EJ0"))
302 newfunc->flags = FUNC_HAS_EJ0;
304 if (acpi_has_method(handle, "_STA"))
305 newfunc->flags |= FUNC_HAS_STA;
308 * Dock stations' notify handler should be used for dock devices instead
309 * of the common one, so clear hp.event in their contexts.
311 if (acpi_has_method(handle, "_DCK"))
312 context->hp.event = NULL;
314 acpi_unlock_hp_context();
316 /* search for objects that share the same slot */
317 list_for_each_entry(slot, &bridge->slots, node)
318 if (slot->device == device)
321 slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
323 acpi_lock_hp_context();
324 acpiphp_put_context(context);
325 acpi_unlock_hp_context();
329 slot->bus = bridge->pci_bus;
330 slot->device = device;
331 INIT_LIST_HEAD(&slot->funcs);
333 list_add_tail(&slot->node, &bridge->slots);
335 /* Register slots for ejectable functions only. */
336 if (acpi_pci_check_ejectable(pbus, handle) || is_dock_device(handle)) {
337 unsigned long long sun;
341 status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
342 if (ACPI_FAILURE(status))
343 sun = bridge->nr_slots;
345 pr_debug("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
346 sun, pci_domain_nr(pbus), pbus->number, device);
348 retval = acpiphp_register_hotplug_slot(slot, sun);
352 if (retval == -EBUSY)
353 pr_warn("Slot %llu already registered by another "
354 "hotplug driver\n", sun);
356 pr_warn("acpiphp_register_hotplug_slot failed "
357 "(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;
370 if (is_dock_device(handle)) {
371 /* we don't want to call this device's _EJ0
372 * because we want the dock notify handler
373 * to call it after it calls _DCK
375 newfunc->flags &= ~FUNC_HAS_EJ0;
376 if (register_hotplug_dock_device(handle,
377 &acpiphp_dock_ops, context,
378 acpiphp_dock_init, acpiphp_dock_release))
379 pr_debug("failed to register dock device\n");
385 static struct acpiphp_bridge *acpiphp_dev_to_bridge(struct acpi_device *adev)
387 struct acpiphp_context *context;
388 struct acpiphp_bridge *bridge = NULL;
390 acpi_lock_hp_context();
391 context = acpiphp_get_context(adev);
393 bridge = context->bridge;
397 acpiphp_put_context(context);
399 acpi_unlock_hp_context();
403 static void cleanup_bridge(struct acpiphp_bridge *bridge)
405 struct acpiphp_slot *slot;
406 struct acpiphp_func *func;
408 list_for_each_entry(slot, &bridge->slots, node) {
409 list_for_each_entry(func, &slot->funcs, sibling) {
410 struct acpi_device *adev = func_to_acpi_device(func);
412 if (is_dock_device(adev->handle))
413 unregister_hotplug_dock_device(adev->handle);
415 acpi_lock_hp_context();
416 adev->hp->event = NULL;
417 acpi_unlock_hp_context();
419 slot->flags |= SLOT_IS_GOING_AWAY;
421 acpiphp_unregister_hotplug_slot(slot);
424 mutex_lock(&bridge_mutex);
425 list_del(&bridge->list);
426 mutex_unlock(&bridge_mutex);
428 acpi_lock_hp_context();
429 bridge->is_going_away = true;
430 acpi_unlock_hp_context();
434 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
435 * @bus: bus to start search with
437 static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
439 struct list_head *tmp;
440 unsigned char max, n;
443 * pci_bus_max_busnr will return the highest
444 * reserved busnr for all these children.
445 * that is equivalent to the bus->subordinate
446 * value. We don't want to use the parent's
447 * bus->subordinate value because it could have
450 max = bus->busn_res.start;
452 list_for_each(tmp, &bus->children) {
453 n = pci_bus_max_busnr(pci_bus_b(tmp));
460 static void acpiphp_set_acpi_region(struct acpiphp_slot *slot)
462 struct acpiphp_func *func;
463 union acpi_object params[2];
464 struct acpi_object_list arg_list;
466 list_for_each_entry(func, &slot->funcs, sibling) {
468 arg_list.pointer = params;
469 params[0].type = ACPI_TYPE_INTEGER;
470 params[0].integer.value = ACPI_ADR_SPACE_PCI_CONFIG;
471 params[1].type = ACPI_TYPE_INTEGER;
472 params[1].integer.value = 1;
473 /* _REG is optional, we don't care about if there is failure */
474 acpi_evaluate_object(func_to_handle(func), "_REG", &arg_list,
479 static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev)
481 struct acpiphp_func *func;
483 /* quirk, or pcie could set it already */
484 if (dev->is_hotplug_bridge)
487 list_for_each_entry(func, &slot->funcs, sibling) {
488 if (PCI_FUNC(dev->devfn) == func->function) {
489 dev->is_hotplug_bridge = 1;
495 static int acpiphp_rescan_slot(struct acpiphp_slot *slot)
497 struct acpiphp_func *func;
499 list_for_each_entry(func, &slot->funcs, sibling) {
500 struct acpi_device *adev = func_to_acpi_device(func);
502 acpi_bus_scan(adev->handle);
503 if (acpi_device_enumerated(adev))
504 acpi_device_set_power(adev, ACPI_STATE_D0);
506 return pci_scan_slot(slot->bus, PCI_DEVFN(slot->device, 0));
510 * enable_slot - enable, configure a slot
511 * @slot: slot to be enabled
513 * This function should be called per *physical slot*,
514 * not per each slot object in ACPI namespace.
516 static void __ref enable_slot(struct acpiphp_slot *slot)
519 struct pci_bus *bus = slot->bus;
520 struct acpiphp_func *func;
524 acpiphp_rescan_slot(slot);
525 max = acpiphp_max_busnr(bus);
526 for (pass = 0; pass < 2; pass++) {
527 list_for_each_entry(dev, &bus->devices, bus_list) {
528 if (PCI_SLOT(dev->devfn) != slot->device)
531 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
532 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
533 max = pci_scan_bridge(bus, dev, max, pass);
534 if (pass && dev->subordinate) {
535 check_hotplug_bridge(slot, dev);
536 pcibios_resource_survey_bus(dev->subordinate);
537 __pci_bus_size_bridges(dev->subordinate,
543 __pci_bus_assign_resources(bus, &add_list, NULL);
545 acpiphp_sanitize_bus(bus);
546 acpiphp_set_hpp_values(bus);
547 acpiphp_set_acpi_region(slot);
549 list_for_each_entry(dev, &bus->devices, bus_list) {
550 /* Assume that newly added devices are powered on already. */
552 dev->current_state = PCI_D0;
555 pci_bus_add_devices(bus);
557 slot->flags |= SLOT_ENABLED;
558 list_for_each_entry(func, &slot->funcs, sibling) {
559 dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
562 /* Do not set SLOT_ENABLED flag if some funcs
564 slot->flags &= (~SLOT_ENABLED);
571 * disable_slot - disable a slot
572 * @slot: ACPI PHP slot
574 static void disable_slot(struct acpiphp_slot *slot)
576 struct pci_bus *bus = slot->bus;
577 struct pci_dev *dev, *prev;
578 struct acpiphp_func *func;
581 * enable_slot() enumerates all functions in this device via
582 * pci_scan_slot(), whether they have associated ACPI hotplug
583 * methods (_EJ0, etc.) or not. Therefore, we remove all functions
586 list_for_each_entry_safe_reverse(dev, prev, &bus->devices, bus_list)
587 if (PCI_SLOT(dev->devfn) == slot->device)
588 pci_stop_and_remove_bus_device(dev);
590 list_for_each_entry(func, &slot->funcs, sibling)
591 acpi_bus_trim(func_to_acpi_device(func));
593 slot->flags &= (~SLOT_ENABLED);
596 static bool acpiphp_no_hotplug(struct acpi_device *adev)
598 return adev && adev->flags.no_hotplug;
601 static bool slot_no_hotplug(struct acpiphp_slot *slot)
603 struct acpiphp_func *func;
605 list_for_each_entry(func, &slot->funcs, sibling)
606 if (acpiphp_no_hotplug(func_to_acpi_device(func)))
613 * get_slot_status - get ACPI slot status
614 * @slot: ACPI PHP slot
616 * If a slot has _STA for each function and if any one of them
617 * returned non-zero status, return it.
619 * If a slot doesn't have _STA and if any one of its functions'
620 * configuration space is configured, return 0x0f as a _STA.
622 * Otherwise return 0.
624 static unsigned int get_slot_status(struct acpiphp_slot *slot)
626 unsigned long long sta = 0;
627 struct acpiphp_func *func;
629 list_for_each_entry(func, &slot->funcs, sibling) {
630 if (func->flags & FUNC_HAS_STA) {
633 status = acpi_evaluate_integer(func_to_handle(func),
635 if (ACPI_SUCCESS(status) && sta)
640 pci_bus_read_config_dword(slot->bus,
641 PCI_DEVFN(slot->device,
643 PCI_VENDOR_ID, &dvid);
644 if (dvid != 0xffffffff) {
651 return (unsigned int)sta;
655 * trim_stale_devices - remove PCI devices that are not responding.
656 * @dev: PCI device to start walking the hierarchy from.
658 static void trim_stale_devices(struct pci_dev *dev)
660 struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
661 struct pci_bus *bus = dev->subordinate;
666 unsigned long long sta;
668 status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
669 alive = (ACPI_SUCCESS(status) && sta == ACPI_STA_ALL)
670 || acpiphp_no_hotplug(adev);
675 /* Check if the device responds. */
676 alive = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &v, 0);
679 pci_stop_and_remove_bus_device(dev);
683 struct pci_dev *child, *tmp;
685 /* The device is a bridge. so check the bus below it. */
686 pm_runtime_get_sync(&dev->dev);
687 list_for_each_entry_safe_reverse(child, tmp, &bus->devices, bus_list)
688 trim_stale_devices(child);
690 pm_runtime_put(&dev->dev);
695 * acpiphp_check_bridge - re-enumerate devices
696 * @bridge: where to begin re-enumeration
698 * Iterate over all slots under this bridge and make sure that if a
699 * card is present they are enabled, and if not they are disabled.
701 static void acpiphp_check_bridge(struct acpiphp_bridge *bridge)
703 struct acpiphp_slot *slot;
705 /* Bail out if the bridge is going away. */
706 if (bridge->is_going_away)
709 list_for_each_entry(slot, &bridge->slots, node) {
710 struct pci_bus *bus = slot->bus;
711 struct pci_dev *dev, *tmp;
713 if (slot_no_hotplug(slot)) {
715 } else if (get_slot_status(slot) == ACPI_STA_ALL) {
716 /* remove stale devices if any */
717 list_for_each_entry_safe_reverse(dev, tmp,
718 &bus->devices, bus_list)
719 if (PCI_SLOT(dev->devfn) == slot->device)
720 trim_stale_devices(dev);
722 /* configure all functions */
730 static void acpiphp_set_hpp_values(struct pci_bus *bus)
734 list_for_each_entry(dev, &bus->devices, bus_list)
735 pci_configure_slot(dev);
739 * Remove devices for which we could not assign resources, call
740 * arch specific code to fix-up the bus
742 static void acpiphp_sanitize_bus(struct pci_bus *bus)
744 struct pci_dev *dev, *tmp;
746 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
748 list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list) {
749 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
750 struct resource *res = &dev->resource[i];
751 if ((res->flags & type_mask) && !res->start &&
753 /* Could not assign a required resources
754 * for this device, remove it */
755 pci_stop_and_remove_bus_device(dev);
763 * ACPI event handlers
766 void acpiphp_check_host_bridge(struct acpi_device *adev)
768 struct acpiphp_bridge *bridge;
770 bridge = acpiphp_dev_to_bridge(adev);
772 pci_lock_rescan_remove();
774 acpiphp_check_bridge(bridge);
776 pci_unlock_rescan_remove();
781 static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot);
783 static void hotplug_event(u32 type, struct acpiphp_context *context)
785 acpi_handle handle = context->hp.self->handle;
786 struct acpiphp_func *func = &context->func;
787 struct acpiphp_slot *slot = func->slot;
788 struct acpiphp_bridge *bridge;
790 acpi_lock_hp_context();
791 bridge = context->bridge;
795 acpi_unlock_hp_context();
797 pci_lock_rescan_remove();
800 case ACPI_NOTIFY_BUS_CHECK:
801 /* bus re-enumerate */
802 acpi_handle_debug(handle, "Bus check in %s()\n", __func__);
804 acpiphp_check_bridge(bridge);
805 else if (!(slot->flags & SLOT_IS_GOING_AWAY))
810 case ACPI_NOTIFY_DEVICE_CHECK:
812 acpi_handle_debug(handle, "Device check in %s()\n", __func__);
814 acpiphp_check_bridge(bridge);
815 } else if (!(slot->flags & SLOT_IS_GOING_AWAY)) {
817 * Check if anything has changed in the slot and rescan
818 * from the parent if that's the case.
820 if (acpiphp_rescan_slot(slot))
821 acpiphp_check_bridge(func->parent);
825 case ACPI_NOTIFY_EJECT_REQUEST:
826 /* request device eject */
827 acpi_handle_debug(handle, "Eject request in %s()\n", __func__);
828 acpiphp_disable_and_eject_slot(slot);
832 pci_unlock_rescan_remove();
837 static int acpiphp_hotplug_event(struct acpi_device *adev, u32 type)
839 struct acpiphp_context *context;
841 acpi_lock_hp_context();
842 context = acpiphp_get_context(adev);
843 if (!context || context->func.parent->is_going_away) {
844 acpi_unlock_hp_context();
847 get_bridge(context->func.parent);
848 acpiphp_put_context(context);
849 acpi_unlock_hp_context();
851 hotplug_event(type, context);
853 put_bridge(context->func.parent);
858 * acpiphp_enumerate_slots - Enumerate PCI slots for a given bus.
859 * @bus: PCI bus to enumerate the slots for.
861 * A "slot" is an object associated with a PCI device number. All functions
862 * (PCI devices) with the same bus and device number belong to the same slot.
864 void acpiphp_enumerate_slots(struct pci_bus *bus)
866 struct acpiphp_bridge *bridge;
867 struct acpi_device *adev;
871 if (acpiphp_disabled)
874 adev = ACPI_COMPANION(bus->bridge);
878 handle = adev->handle;
879 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
881 acpi_handle_err(handle, "No memory for bridge object\n");
885 INIT_LIST_HEAD(&bridge->slots);
886 kref_init(&bridge->ref);
887 bridge->pci_dev = pci_dev_get(bus->self);
888 bridge->pci_bus = bus;
891 * Grab a ref to the subordinate PCI bus in case the bus is
892 * removed via PCI core logical hotplug. The ref pins the bus
893 * (which we access during module unload).
895 get_device(&bus->dev);
897 if (!pci_is_root_bus(bridge->pci_bus)) {
898 struct acpiphp_context *context;
901 * This bridge should have been registered as a hotplug function
902 * under its parent, so the context should be there, unless the
903 * parent is going to be handled by pciehp, in which case this
904 * bridge is not interesting to us either.
906 acpi_lock_hp_context();
907 context = acpiphp_get_context(adev);
909 acpi_unlock_hp_context();
910 put_device(&bus->dev);
911 pci_dev_put(bridge->pci_dev);
915 bridge->context = context;
916 context->bridge = bridge;
917 /* Get a reference to the parent bridge. */
918 get_bridge(context->func.parent);
919 acpi_unlock_hp_context();
922 /* must be added to the list prior to calling register_slot */
923 mutex_lock(&bridge_mutex);
924 list_add(&bridge->list, &bridge_list);
925 mutex_unlock(&bridge_mutex);
927 /* register all slot objects under this bridge */
928 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
929 register_slot, NULL, bridge, NULL);
930 if (ACPI_FAILURE(status)) {
931 acpi_handle_err(handle, "failed to register slots\n");
932 cleanup_bridge(bridge);
938 * acpiphp_remove_slots - Remove slot objects associated with a given bus.
939 * @bus: PCI bus to remove the slot objects for.
941 void acpiphp_remove_slots(struct pci_bus *bus)
943 struct acpiphp_bridge *bridge;
945 if (acpiphp_disabled)
948 mutex_lock(&bridge_mutex);
949 list_for_each_entry(bridge, &bridge_list, list)
950 if (bridge->pci_bus == bus) {
951 mutex_unlock(&bridge_mutex);
952 cleanup_bridge(bridge);
957 mutex_unlock(&bridge_mutex);
961 * acpiphp_enable_slot - power on slot
962 * @slot: ACPI PHP slot
964 int acpiphp_enable_slot(struct acpiphp_slot *slot)
966 pci_lock_rescan_remove();
968 if (slot->flags & SLOT_IS_GOING_AWAY)
971 /* configure all functions */
972 if (!(slot->flags & SLOT_ENABLED))
975 pci_unlock_rescan_remove();
980 * acpiphp_disable_and_eject_slot - power off and eject slot
981 * @slot: ACPI PHP slot
983 static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot)
985 struct acpiphp_func *func;
987 if (slot->flags & SLOT_IS_GOING_AWAY)
990 /* unconfigure all functions */
993 list_for_each_entry(func, &slot->funcs, sibling)
994 if (func->flags & FUNC_HAS_EJ0) {
995 acpi_handle handle = func_to_handle(func);
997 if (ACPI_FAILURE(acpi_evaluate_ej0(handle)))
998 acpi_handle_err(handle, "_EJ0 failed\n");
1006 int acpiphp_disable_slot(struct acpiphp_slot *slot)
1011 * Acquire acpi_scan_lock to ensure that the execution of _EJ0 in
1012 * acpiphp_disable_and_eject_slot() will be synchronized properly.
1014 acpi_scan_lock_acquire();
1015 pci_lock_rescan_remove();
1016 ret = acpiphp_disable_and_eject_slot(slot);
1017 pci_unlock_rescan_remove();
1018 acpi_scan_lock_release();
1026 u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
1028 return (slot->flags & SLOT_ENABLED);
1035 u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1037 return !(get_slot_status(slot) & ACPI_STA_DEVICE_UI);
1041 * adapter presence : 1
1044 u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1046 return !!get_slot_status(slot);