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;
300 acpi_unlock_hp_context();
302 if (acpi_has_method(handle, "_EJ0"))
303 newfunc->flags = FUNC_HAS_EJ0;
305 if (acpi_has_method(handle, "_STA"))
306 newfunc->flags |= FUNC_HAS_STA;
308 if (acpi_has_method(handle, "_DCK"))
309 newfunc->flags |= FUNC_HAS_DCK;
311 /* search for objects that share the same slot */
312 list_for_each_entry(slot, &bridge->slots, node)
313 if (slot->device == device)
316 slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
318 acpi_lock_hp_context();
319 acpiphp_put_context(context);
320 acpi_unlock_hp_context();
324 slot->bus = bridge->pci_bus;
325 slot->device = device;
326 INIT_LIST_HEAD(&slot->funcs);
328 list_add_tail(&slot->node, &bridge->slots);
330 /* Register slots for ejectable functions only. */
331 if (acpi_pci_check_ejectable(pbus, handle) || is_dock_device(handle)) {
332 unsigned long long sun;
336 status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
337 if (ACPI_FAILURE(status))
338 sun = bridge->nr_slots;
340 pr_debug("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
341 sun, pci_domain_nr(pbus), pbus->number, device);
343 retval = acpiphp_register_hotplug_slot(slot, sun);
347 if (retval == -EBUSY)
348 pr_warn("Slot %llu already registered by another "
349 "hotplug driver\n", sun);
351 pr_warn("acpiphp_register_hotplug_slot failed "
352 "(err code = 0x%x)\n", retval);
354 /* Even if the slot registration fails, we can still use it. */
358 newfunc->slot = slot;
359 list_add_tail(&newfunc->sibling, &slot->funcs);
361 if (pci_bus_read_dev_vendor_id(pbus, PCI_DEVFN(device, function),
363 slot->flags |= SLOT_ENABLED;
365 if (is_dock_device(handle)) {
366 /* we don't want to call this device's _EJ0
367 * because we want the dock notify handler
368 * to call it after it calls _DCK
370 newfunc->flags &= ~FUNC_HAS_EJ0;
371 if (register_hotplug_dock_device(handle,
372 &acpiphp_dock_ops, context,
373 acpiphp_dock_init, acpiphp_dock_release))
374 pr_debug("failed to register dock device\n");
377 /* install notify handler */
378 if (!(newfunc->flags & FUNC_HAS_DCK))
379 acpi_install_hotplug_notify_handler(handle, NULL);
384 static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
386 struct acpi_device *adev = acpi_bus_get_acpi_device(handle);
387 struct acpiphp_context *context;
388 struct acpiphp_bridge *bridge = NULL;
393 acpi_lock_hp_context();
394 context = acpiphp_get_context(adev);
396 bridge = context->bridge;
400 acpiphp_put_context(context);
402 acpi_unlock_hp_context();
403 acpi_bus_put_acpi_device(adev);
407 static void cleanup_bridge(struct acpiphp_bridge *bridge)
409 struct acpiphp_slot *slot;
410 struct acpiphp_func *func;
412 list_for_each_entry(slot, &bridge->slots, node) {
413 list_for_each_entry(func, &slot->funcs, sibling) {
414 acpi_handle handle = func_to_handle(func);
416 if (is_dock_device(handle))
417 unregister_hotplug_dock_device(handle);
419 if (!(func->flags & FUNC_HAS_DCK))
420 acpi_remove_hotplug_notify_handler(handle);
422 slot->flags |= SLOT_IS_GOING_AWAY;
424 acpiphp_unregister_hotplug_slot(slot);
427 mutex_lock(&bridge_mutex);
428 list_del(&bridge->list);
429 mutex_unlock(&bridge_mutex);
431 acpi_lock_hp_context();
432 bridge->is_going_away = true;
433 acpi_unlock_hp_context();
437 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
438 * @bus: bus to start search with
440 static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
442 struct list_head *tmp;
443 unsigned char max, n;
446 * pci_bus_max_busnr will return the highest
447 * reserved busnr for all these children.
448 * that is equivalent to the bus->subordinate
449 * value. We don't want to use the parent's
450 * bus->subordinate value because it could have
453 max = bus->busn_res.start;
455 list_for_each(tmp, &bus->children) {
456 n = pci_bus_max_busnr(pci_bus_b(tmp));
463 static void acpiphp_set_acpi_region(struct acpiphp_slot *slot)
465 struct acpiphp_func *func;
466 union acpi_object params[2];
467 struct acpi_object_list arg_list;
469 list_for_each_entry(func, &slot->funcs, sibling) {
471 arg_list.pointer = params;
472 params[0].type = ACPI_TYPE_INTEGER;
473 params[0].integer.value = ACPI_ADR_SPACE_PCI_CONFIG;
474 params[1].type = ACPI_TYPE_INTEGER;
475 params[1].integer.value = 1;
476 /* _REG is optional, we don't care about if there is failure */
477 acpi_evaluate_object(func_to_handle(func), "_REG", &arg_list,
482 static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev)
484 struct acpiphp_func *func;
486 /* quirk, or pcie could set it already */
487 if (dev->is_hotplug_bridge)
490 list_for_each_entry(func, &slot->funcs, sibling) {
491 if (PCI_FUNC(dev->devfn) == func->function) {
492 dev->is_hotplug_bridge = 1;
498 static int acpiphp_rescan_slot(struct acpiphp_slot *slot)
500 struct acpiphp_func *func;
502 list_for_each_entry(func, &slot->funcs, sibling) {
503 struct acpi_device *adev = func_to_acpi_device(func);
505 acpi_bus_scan(adev->handle);
506 if (acpi_device_enumerated(adev))
507 acpi_device_set_power(adev, ACPI_STATE_D0);
509 return pci_scan_slot(slot->bus, PCI_DEVFN(slot->device, 0));
513 * enable_slot - enable, configure a slot
514 * @slot: slot to be enabled
516 * This function should be called per *physical slot*,
517 * not per each slot object in ACPI namespace.
519 static void __ref enable_slot(struct acpiphp_slot *slot)
522 struct pci_bus *bus = slot->bus;
523 struct acpiphp_func *func;
527 acpiphp_rescan_slot(slot);
528 max = acpiphp_max_busnr(bus);
529 for (pass = 0; pass < 2; pass++) {
530 list_for_each_entry(dev, &bus->devices, bus_list) {
531 if (PCI_SLOT(dev->devfn) != slot->device)
534 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
535 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
536 max = pci_scan_bridge(bus, dev, max, pass);
537 if (pass && dev->subordinate) {
538 check_hotplug_bridge(slot, dev);
539 pcibios_resource_survey_bus(dev->subordinate);
540 __pci_bus_size_bridges(dev->subordinate,
546 __pci_bus_assign_resources(bus, &add_list, NULL);
548 acpiphp_sanitize_bus(bus);
549 acpiphp_set_hpp_values(bus);
550 acpiphp_set_acpi_region(slot);
552 list_for_each_entry(dev, &bus->devices, bus_list) {
553 /* Assume that newly added devices are powered on already. */
555 dev->current_state = PCI_D0;
558 pci_bus_add_devices(bus);
560 slot->flags |= SLOT_ENABLED;
561 list_for_each_entry(func, &slot->funcs, sibling) {
562 dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
565 /* Do not set SLOT_ENABLED flag if some funcs
567 slot->flags &= (~SLOT_ENABLED);
574 * disable_slot - disable a slot
575 * @slot: ACPI PHP slot
577 static void disable_slot(struct acpiphp_slot *slot)
579 struct pci_bus *bus = slot->bus;
580 struct pci_dev *dev, *prev;
581 struct acpiphp_func *func;
584 * enable_slot() enumerates all functions in this device via
585 * pci_scan_slot(), whether they have associated ACPI hotplug
586 * methods (_EJ0, etc.) or not. Therefore, we remove all functions
589 list_for_each_entry_safe_reverse(dev, prev, &bus->devices, bus_list)
590 if (PCI_SLOT(dev->devfn) == slot->device)
591 pci_stop_and_remove_bus_device(dev);
593 list_for_each_entry(func, &slot->funcs, sibling)
594 acpi_bus_trim(func_to_acpi_device(func));
596 slot->flags &= (~SLOT_ENABLED);
599 static bool acpiphp_no_hotplug(struct acpi_device *adev)
601 return adev && adev->flags.no_hotplug;
604 static bool slot_no_hotplug(struct acpiphp_slot *slot)
606 struct acpiphp_func *func;
608 list_for_each_entry(func, &slot->funcs, sibling)
609 if (acpiphp_no_hotplug(func_to_acpi_device(func)))
616 * get_slot_status - get ACPI slot status
617 * @slot: ACPI PHP slot
619 * If a slot has _STA for each function and if any one of them
620 * returned non-zero status, return it.
622 * If a slot doesn't have _STA and if any one of its functions'
623 * configuration space is configured, return 0x0f as a _STA.
625 * Otherwise return 0.
627 static unsigned int get_slot_status(struct acpiphp_slot *slot)
629 unsigned long long sta = 0;
630 struct acpiphp_func *func;
632 list_for_each_entry(func, &slot->funcs, sibling) {
633 if (func->flags & FUNC_HAS_STA) {
636 status = acpi_evaluate_integer(func_to_handle(func),
638 if (ACPI_SUCCESS(status) && sta)
643 pci_bus_read_config_dword(slot->bus,
644 PCI_DEVFN(slot->device,
646 PCI_VENDOR_ID, &dvid);
647 if (dvid != 0xffffffff) {
654 return (unsigned int)sta;
658 * trim_stale_devices - remove PCI devices that are not responding.
659 * @dev: PCI device to start walking the hierarchy from.
661 static void trim_stale_devices(struct pci_dev *dev)
663 struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
664 struct pci_bus *bus = dev->subordinate;
669 unsigned long long sta;
671 status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
672 alive = (ACPI_SUCCESS(status) && sta == ACPI_STA_ALL)
673 || acpiphp_no_hotplug(adev);
678 /* Check if the device responds. */
679 alive = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &v, 0);
682 pci_stop_and_remove_bus_device(dev);
686 struct pci_dev *child, *tmp;
688 /* The device is a bridge. so check the bus below it. */
689 pm_runtime_get_sync(&dev->dev);
690 list_for_each_entry_safe_reverse(child, tmp, &bus->devices, bus_list)
691 trim_stale_devices(child);
693 pm_runtime_put(&dev->dev);
698 * acpiphp_check_bridge - re-enumerate devices
699 * @bridge: where to begin re-enumeration
701 * Iterate over all slots under this bridge and make sure that if a
702 * card is present they are enabled, and if not they are disabled.
704 static void acpiphp_check_bridge(struct acpiphp_bridge *bridge)
706 struct acpiphp_slot *slot;
708 /* Bail out if the bridge is going away. */
709 if (bridge->is_going_away)
712 list_for_each_entry(slot, &bridge->slots, node) {
713 struct pci_bus *bus = slot->bus;
714 struct pci_dev *dev, *tmp;
716 if (slot_no_hotplug(slot)) {
718 } else if (get_slot_status(slot) == ACPI_STA_ALL) {
719 /* remove stale devices if any */
720 list_for_each_entry_safe_reverse(dev, tmp,
721 &bus->devices, bus_list)
722 if (PCI_SLOT(dev->devfn) == slot->device)
723 trim_stale_devices(dev);
725 /* configure all functions */
733 static void acpiphp_set_hpp_values(struct pci_bus *bus)
737 list_for_each_entry(dev, &bus->devices, bus_list)
738 pci_configure_slot(dev);
742 * Remove devices for which we could not assign resources, call
743 * arch specific code to fix-up the bus
745 static void acpiphp_sanitize_bus(struct pci_bus *bus)
747 struct pci_dev *dev, *tmp;
749 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
751 list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list) {
752 for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {
753 struct resource *res = &dev->resource[i];
754 if ((res->flags & type_mask) && !res->start &&
756 /* Could not assign a required resources
757 * for this device, remove it */
758 pci_stop_and_remove_bus_device(dev);
766 * ACPI event handlers
769 void acpiphp_check_host_bridge(acpi_handle handle)
771 struct acpiphp_bridge *bridge;
773 bridge = acpiphp_handle_to_bridge(handle);
775 pci_lock_rescan_remove();
777 acpiphp_check_bridge(bridge);
779 pci_unlock_rescan_remove();
784 static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot);
786 static void hotplug_event(u32 type, struct acpiphp_context *context)
788 acpi_handle handle = context->hp.self->handle;
789 struct acpiphp_func *func = &context->func;
790 struct acpiphp_slot *slot = func->slot;
791 struct acpiphp_bridge *bridge;
793 acpi_lock_hp_context();
794 bridge = context->bridge;
798 acpi_unlock_hp_context();
800 pci_lock_rescan_remove();
803 case ACPI_NOTIFY_BUS_CHECK:
804 /* bus re-enumerate */
805 acpi_handle_debug(handle, "Bus check in %s()\n", __func__);
807 acpiphp_check_bridge(bridge);
808 else if (!(slot->flags & SLOT_IS_GOING_AWAY))
813 case ACPI_NOTIFY_DEVICE_CHECK:
815 acpi_handle_debug(handle, "Device check in %s()\n", __func__);
817 acpiphp_check_bridge(bridge);
818 } else if (!(slot->flags & SLOT_IS_GOING_AWAY)) {
820 * Check if anything has changed in the slot and rescan
821 * from the parent if that's the case.
823 if (acpiphp_rescan_slot(slot))
824 acpiphp_check_bridge(func->parent);
828 case ACPI_NOTIFY_EJECT_REQUEST:
829 /* request device eject */
830 acpi_handle_debug(handle, "Eject request in %s()\n", __func__);
831 acpiphp_disable_and_eject_slot(slot);
835 pci_unlock_rescan_remove();
840 static int acpiphp_hotplug_event(struct acpi_device *adev, u32 type)
842 struct acpiphp_context *context;
844 acpi_lock_hp_context();
845 context = acpiphp_get_context(adev);
846 if (!context || context->func.parent->is_going_away) {
847 acpi_unlock_hp_context();
850 get_bridge(context->func.parent);
851 acpiphp_put_context(context);
852 acpi_unlock_hp_context();
854 hotplug_event(type, context);
856 put_bridge(context->func.parent);
861 * acpiphp_enumerate_slots - Enumerate PCI slots for a given bus.
862 * @bus: PCI bus to enumerate the slots for.
864 * A "slot" is an object associated with a PCI device number. All functions
865 * (PCI devices) with the same bus and device number belong to the same slot.
867 void acpiphp_enumerate_slots(struct pci_bus *bus)
869 struct acpiphp_bridge *bridge;
870 struct acpi_device *adev;
874 if (acpiphp_disabled)
877 adev = ACPI_COMPANION(bus->bridge);
881 handle = adev->handle;
882 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
884 acpi_handle_err(handle, "No memory for bridge object\n");
888 INIT_LIST_HEAD(&bridge->slots);
889 kref_init(&bridge->ref);
890 bridge->pci_dev = pci_dev_get(bus->self);
891 bridge->pci_bus = bus;
894 * Grab a ref to the subordinate PCI bus in case the bus is
895 * removed via PCI core logical hotplug. The ref pins the bus
896 * (which we access during module unload).
898 get_device(&bus->dev);
900 if (!pci_is_root_bus(bridge->pci_bus)) {
901 struct acpiphp_context *context;
904 * This bridge should have been registered as a hotplug function
905 * under its parent, so the context should be there, unless the
906 * parent is going to be handled by pciehp, in which case this
907 * bridge is not interesting to us either.
909 acpi_lock_hp_context();
910 context = acpiphp_get_context(adev);
912 acpi_unlock_hp_context();
913 put_device(&bus->dev);
914 pci_dev_put(bridge->pci_dev);
918 bridge->context = context;
919 context->bridge = bridge;
920 /* Get a reference to the parent bridge. */
921 get_bridge(context->func.parent);
922 acpi_unlock_hp_context();
925 /* must be added to the list prior to calling register_slot */
926 mutex_lock(&bridge_mutex);
927 list_add(&bridge->list, &bridge_list);
928 mutex_unlock(&bridge_mutex);
930 /* register all slot objects under this bridge */
931 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
932 register_slot, NULL, bridge, NULL);
933 if (ACPI_FAILURE(status)) {
934 acpi_handle_err(handle, "failed to register slots\n");
935 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 cleanup_bridge(bridge);
960 mutex_unlock(&bridge_mutex);
964 * acpiphp_enable_slot - power on slot
965 * @slot: ACPI PHP slot
967 int acpiphp_enable_slot(struct acpiphp_slot *slot)
969 pci_lock_rescan_remove();
971 if (slot->flags & SLOT_IS_GOING_AWAY)
974 /* configure all functions */
975 if (!(slot->flags & SLOT_ENABLED))
978 pci_unlock_rescan_remove();
983 * acpiphp_disable_and_eject_slot - power off and eject slot
984 * @slot: ACPI PHP slot
986 static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot)
988 struct acpiphp_func *func;
990 if (slot->flags & SLOT_IS_GOING_AWAY)
993 /* unconfigure all functions */
996 list_for_each_entry(func, &slot->funcs, sibling)
997 if (func->flags & FUNC_HAS_EJ0) {
998 acpi_handle handle = func_to_handle(func);
1000 if (ACPI_FAILURE(acpi_evaluate_ej0(handle)))
1001 acpi_handle_err(handle, "_EJ0 failed\n");
1009 int acpiphp_disable_slot(struct acpiphp_slot *slot)
1013 pci_lock_rescan_remove();
1014 ret = acpiphp_disable_and_eject_slot(slot);
1015 pci_unlock_rescan_remove();
1023 u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
1025 return (slot->flags & SLOT_ENABLED);
1032 u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1034 return !(get_slot_status(slot) & ACPI_STA_DEVICE_UI);
1038 * adapter presence : 1
1041 u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1043 return !!get_slot_status(slot);