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 hotplug_event(u32 type, struct acpiphp_context *context);
65 static void free_bridge(struct kref *kref);
68 * acpiphp_init_context - Create hotplug context and grab a reference to it.
69 * @adev: ACPI device object to create the context for.
71 * Call under acpi_hp_context_lock.
73 static struct acpiphp_context *acpiphp_init_context(struct acpi_device *adev)
75 struct acpiphp_context *context;
77 context = kzalloc(sizeof(*context), GFP_KERNEL);
81 context->refcount = 1;
82 context->hp.notify = acpiphp_hotplug_notify;
83 context->hp.fixup = acpiphp_post_dock_fixup;
84 acpi_set_hp_context(adev, &context->hp);
89 * acpiphp_get_context - Get hotplug context and grab a reference to it.
90 * @adev: ACPI device object to get the context for.
92 * Call under acpi_hp_context_lock.
94 static struct acpiphp_context *acpiphp_get_context(struct acpi_device *adev)
96 struct acpiphp_context *context;
101 context = to_acpiphp_context(adev->hp);
107 * acpiphp_put_context - Drop a reference to ACPI hotplug context.
108 * @context: ACPI hotplug context to drop a reference to.
110 * The context object is removed if there are no more references to it.
112 * Call under acpi_hp_context_lock.
114 static void acpiphp_put_context(struct acpiphp_context *context)
116 if (--context->refcount)
119 WARN_ON(context->bridge);
120 context->hp.self->hp = NULL;
124 static inline void get_bridge(struct acpiphp_bridge *bridge)
126 kref_get(&bridge->ref);
129 static inline void put_bridge(struct acpiphp_bridge *bridge)
131 kref_put(&bridge->ref, free_bridge);
134 static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev)
136 struct acpiphp_context *context;
138 acpi_lock_hp_context();
139 context = acpiphp_get_context(adev);
140 if (!context || context->func.parent->is_going_away) {
141 acpi_unlock_hp_context();
144 get_bridge(context->func.parent);
145 acpiphp_put_context(context);
146 acpi_unlock_hp_context();
150 static void acpiphp_let_context_go(struct acpiphp_context *context)
152 put_bridge(context->func.parent);
155 static void free_bridge(struct kref *kref)
157 struct acpiphp_context *context;
158 struct acpiphp_bridge *bridge;
159 struct acpiphp_slot *slot, *next;
160 struct acpiphp_func *func, *tmp;
162 acpi_lock_hp_context();
164 bridge = container_of(kref, struct acpiphp_bridge, ref);
166 list_for_each_entry_safe(slot, next, &bridge->slots, node) {
167 list_for_each_entry_safe(func, tmp, &slot->funcs, sibling)
168 acpiphp_put_context(func_to_context(func));
173 context = bridge->context;
174 /* Root bridges will not have hotplug context. */
176 /* Release the reference taken by acpiphp_enumerate_slots(). */
177 put_bridge(context->func.parent);
178 context->bridge = NULL;
179 acpiphp_put_context(context);
182 put_device(&bridge->pci_bus->dev);
183 pci_dev_put(bridge->pci_dev);
186 acpi_unlock_hp_context();
190 * acpiphp_post_dock_fixup - Post-dock fixups for PCI devices.
191 * @adev: ACPI device object corresponding to a PCI device.
193 * TBD - figure out a way to only call fixups for systems that require them.
195 static void acpiphp_post_dock_fixup(struct acpi_device *adev)
197 struct acpiphp_context *context = acpiphp_grab_context(adev);
204 bus = context->func.slot->bus;
208 /* fixup bad _DCK function that rewrites
209 * secondary bridge on slot
211 pci_read_config_dword(bus->self, PCI_PRIMARY_BUS, &buses);
213 if (((buses >> 8) & 0xff) != bus->busn_res.start) {
214 buses = (buses & 0xff000000)
215 | ((unsigned int)(bus->primary) << 0)
216 | ((unsigned int)(bus->busn_res.start) << 8)
217 | ((unsigned int)(bus->busn_res.end) << 16);
218 pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses);
222 acpiphp_let_context_go(context);
226 * acpiphp_add_context - Add ACPIPHP context to an ACPI device object.
227 * @handle: ACPI handle of the object to add a context to.
229 * @data: The object's parent ACPIPHP bridge.
232 static acpi_status acpiphp_add_context(acpi_handle handle, u32 lvl, void *data,
235 struct acpiphp_bridge *bridge = data;
236 struct acpiphp_context *context;
237 struct acpi_device *adev;
238 struct acpiphp_slot *slot;
239 struct acpiphp_func *newfunc;
240 acpi_status status = AE_OK;
241 unsigned long long adr;
242 int device, function;
243 struct pci_bus *pbus = bridge->pci_bus;
244 struct pci_dev *pdev = bridge->pci_dev;
247 status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
248 if (ACPI_FAILURE(status)) {
249 if (status != AE_NOT_FOUND)
250 acpi_handle_warn(handle,
251 "can't evaluate _ADR (%#x)\n", status);
254 if (acpi_bus_get_device(handle, &adev))
257 device = (adr >> 16) & 0xffff;
258 function = adr & 0xffff;
260 acpi_lock_hp_context();
261 context = acpiphp_init_context(adev);
263 acpi_unlock_hp_context();
264 acpi_handle_err(handle, "No hotplug context\n");
267 newfunc = &context->func;
268 newfunc->function = function;
269 newfunc->parent = bridge;
270 acpi_unlock_hp_context();
273 * If this is a dock device, its _EJ0 should be executed by the dock
274 * notify handler after calling _DCK.
276 if (!is_dock_device(adev) && acpi_has_method(handle, "_EJ0"))
277 newfunc->flags = FUNC_HAS_EJ0;
279 if (acpi_has_method(handle, "_STA"))
280 newfunc->flags |= FUNC_HAS_STA;
282 /* search for objects that share the same slot */
283 list_for_each_entry(slot, &bridge->slots, node)
284 if (slot->device == device)
287 slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
289 acpi_lock_hp_context();
290 acpiphp_put_context(context);
291 acpi_unlock_hp_context();
295 slot->bus = bridge->pci_bus;
296 slot->device = device;
297 INIT_LIST_HEAD(&slot->funcs);
299 list_add_tail(&slot->node, &bridge->slots);
302 * Expose slots to user space for functions that have _EJ0 or _RMV or
303 * are located in dock stations. Do not expose them for devices handled
304 * by the native PCIe hotplug (PCIeHP), becuase that code is supposed to
305 * expose slots to user space in those cases.
307 if ((acpi_pci_check_ejectable(pbus, handle) || is_dock_device(adev))
308 && !(pdev && pdev->is_hotplug_bridge && pciehp_is_native(pdev))) {
309 unsigned long long sun;
313 status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
314 if (ACPI_FAILURE(status))
315 sun = bridge->nr_slots;
317 pr_debug("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
318 sun, pci_domain_nr(pbus), pbus->number, device);
320 retval = acpiphp_register_hotplug_slot(slot, sun);
324 if (retval == -EBUSY)
325 pr_warn("Slot %llu already registered by another hotplug driver\n", sun);
327 pr_warn("acpiphp_register_hotplug_slot failed (err code = 0x%x)\n", retval);
329 /* Even if the slot registration fails, we can still use it. */
333 newfunc->slot = slot;
334 list_add_tail(&newfunc->sibling, &slot->funcs);
336 if (pci_bus_read_dev_vendor_id(pbus, PCI_DEVFN(device, function),
338 slot->flags |= SLOT_ENABLED;
343 static void cleanup_bridge(struct acpiphp_bridge *bridge)
345 struct acpiphp_slot *slot;
346 struct acpiphp_func *func;
348 list_for_each_entry(slot, &bridge->slots, node) {
349 list_for_each_entry(func, &slot->funcs, sibling) {
350 struct acpi_device *adev = func_to_acpi_device(func);
352 acpi_lock_hp_context();
353 adev->hp->notify = NULL;
354 adev->hp->fixup = NULL;
355 acpi_unlock_hp_context();
357 slot->flags |= SLOT_IS_GOING_AWAY;
359 acpiphp_unregister_hotplug_slot(slot);
362 mutex_lock(&bridge_mutex);
363 list_del(&bridge->list);
364 mutex_unlock(&bridge_mutex);
366 acpi_lock_hp_context();
367 bridge->is_going_away = true;
368 acpi_unlock_hp_context();
372 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
373 * @bus: bus to start search with
375 static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
378 unsigned char max, n;
381 * pci_bus_max_busnr will return the highest
382 * reserved busnr for all these children.
383 * that is equivalent to the bus->subordinate
384 * value. We don't want to use the parent's
385 * bus->subordinate value because it could have
388 max = bus->busn_res.start;
390 list_for_each_entry(tmp, &bus->children, node) {
391 n = pci_bus_max_busnr(tmp);
398 static void acpiphp_set_acpi_region(struct acpiphp_slot *slot)
400 struct acpiphp_func *func;
401 union acpi_object params[2];
402 struct acpi_object_list arg_list;
404 list_for_each_entry(func, &slot->funcs, sibling) {
406 arg_list.pointer = params;
407 params[0].type = ACPI_TYPE_INTEGER;
408 params[0].integer.value = ACPI_ADR_SPACE_PCI_CONFIG;
409 params[1].type = ACPI_TYPE_INTEGER;
410 params[1].integer.value = 1;
411 /* _REG is optional, we don't care about if there is failure */
412 acpi_evaluate_object(func_to_handle(func), "_REG", &arg_list,
417 static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev)
419 struct acpiphp_func *func;
421 /* quirk, or pcie could set it already */
422 if (dev->is_hotplug_bridge)
425 list_for_each_entry(func, &slot->funcs, sibling) {
426 if (PCI_FUNC(dev->devfn) == func->function) {
427 dev->is_hotplug_bridge = 1;
433 static int acpiphp_rescan_slot(struct acpiphp_slot *slot)
435 struct acpiphp_func *func;
437 list_for_each_entry(func, &slot->funcs, sibling) {
438 struct acpi_device *adev = func_to_acpi_device(func);
440 acpi_bus_scan(adev->handle);
441 if (acpi_device_enumerated(adev))
442 acpi_device_set_power(adev, ACPI_STATE_D0);
444 return pci_scan_slot(slot->bus, PCI_DEVFN(slot->device, 0));
448 * enable_slot - enable, configure a slot
449 * @slot: slot to be enabled
451 * This function should be called per *physical slot*,
452 * not per each slot object in ACPI namespace.
454 static void enable_slot(struct acpiphp_slot *slot)
457 struct pci_bus *bus = slot->bus;
458 struct acpiphp_func *func;
462 acpiphp_rescan_slot(slot);
463 max = acpiphp_max_busnr(bus);
464 for (pass = 0; pass < 2; pass++) {
465 list_for_each_entry(dev, &bus->devices, bus_list) {
466 if (PCI_SLOT(dev->devfn) != slot->device)
469 if (pci_is_bridge(dev)) {
470 max = pci_scan_bridge(bus, dev, max, pass);
471 if (pass && dev->subordinate) {
472 check_hotplug_bridge(slot, dev);
473 pcibios_resource_survey_bus(dev->subordinate);
474 __pci_bus_size_bridges(dev->subordinate,
480 __pci_bus_assign_resources(bus, &add_list, NULL);
482 acpiphp_sanitize_bus(bus);
483 pcie_bus_configure_settings(bus);
484 acpiphp_set_acpi_region(slot);
486 list_for_each_entry(dev, &bus->devices, bus_list) {
487 /* Assume that newly added devices are powered on already. */
489 dev->current_state = PCI_D0;
492 pci_bus_add_devices(bus);
494 slot->flags |= SLOT_ENABLED;
495 list_for_each_entry(func, &slot->funcs, sibling) {
496 dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
499 /* Do not set SLOT_ENABLED flag if some funcs
501 slot->flags &= (~SLOT_ENABLED);
508 * disable_slot - disable a slot
509 * @slot: ACPI PHP slot
511 static void disable_slot(struct acpiphp_slot *slot)
513 struct pci_bus *bus = slot->bus;
514 struct pci_dev *dev, *prev;
515 struct acpiphp_func *func;
518 * enable_slot() enumerates all functions in this device via
519 * pci_scan_slot(), whether they have associated ACPI hotplug
520 * methods (_EJ0, etc.) or not. Therefore, we remove all functions
523 list_for_each_entry_safe_reverse(dev, prev, &bus->devices, bus_list)
524 if (PCI_SLOT(dev->devfn) == slot->device)
525 pci_stop_and_remove_bus_device(dev);
527 list_for_each_entry(func, &slot->funcs, sibling)
528 acpi_bus_trim(func_to_acpi_device(func));
530 slot->flags &= (~SLOT_ENABLED);
533 static bool slot_no_hotplug(struct acpiphp_slot *slot)
535 struct pci_bus *bus = slot->bus;
538 list_for_each_entry(dev, &bus->devices, bus_list) {
539 if (PCI_SLOT(dev->devfn) == slot->device && dev->ignore_hotplug)
546 * get_slot_status - get ACPI slot status
547 * @slot: ACPI PHP slot
549 * If a slot has _STA for each function and if any one of them
550 * returned non-zero status, return it.
552 * If a slot doesn't have _STA and if any one of its functions'
553 * configuration space is configured, return 0x0f as a _STA.
555 * Otherwise return 0.
557 static unsigned int get_slot_status(struct acpiphp_slot *slot)
559 unsigned long long sta = 0;
560 struct acpiphp_func *func;
562 list_for_each_entry(func, &slot->funcs, sibling) {
563 if (func->flags & FUNC_HAS_STA) {
566 status = acpi_evaluate_integer(func_to_handle(func),
568 if (ACPI_SUCCESS(status) && sta)
573 pci_bus_read_config_dword(slot->bus,
574 PCI_DEVFN(slot->device,
576 PCI_VENDOR_ID, &dvid);
577 if (dvid != 0xffffffff) {
584 return (unsigned int)sta;
587 static inline bool device_status_valid(unsigned int sta)
590 * ACPI spec says that _STA may return bit 0 clear with bit 3 set
591 * if the device is valid but does not require a device driver to be
592 * loaded (Section 6.3.7 of ACPI 5.0A).
594 unsigned int mask = ACPI_STA_DEVICE_ENABLED | ACPI_STA_DEVICE_FUNCTIONING;
595 return (sta & mask) == mask;
599 * trim_stale_devices - remove PCI devices that are not responding.
600 * @dev: PCI device to start walking the hierarchy from.
602 static void trim_stale_devices(struct pci_dev *dev)
604 struct acpi_device *adev = ACPI_COMPANION(&dev->dev);
605 struct pci_bus *bus = dev->subordinate;
606 bool alive = dev->ignore_hotplug;
610 unsigned long long sta;
612 status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
613 alive = alive || (ACPI_SUCCESS(status) && device_status_valid(sta));
616 alive = pci_device_is_present(dev);
619 pci_stop_and_remove_bus_device(dev);
623 struct pci_dev *child, *tmp;
625 /* The device is a bridge. so check the bus below it. */
626 pm_runtime_get_sync(&dev->dev);
627 list_for_each_entry_safe_reverse(child, tmp, &bus->devices, bus_list)
628 trim_stale_devices(child);
630 pm_runtime_put(&dev->dev);
635 * acpiphp_check_bridge - re-enumerate devices
636 * @bridge: where to begin re-enumeration
638 * Iterate over all slots under this bridge and make sure that if a
639 * card is present they are enabled, and if not they are disabled.
641 static void acpiphp_check_bridge(struct acpiphp_bridge *bridge)
643 struct acpiphp_slot *slot;
645 /* Bail out if the bridge is going away. */
646 if (bridge->is_going_away)
650 pm_runtime_get_sync(&bridge->pci_dev->dev);
652 list_for_each_entry(slot, &bridge->slots, node) {
653 struct pci_bus *bus = slot->bus;
654 struct pci_dev *dev, *tmp;
656 if (slot_no_hotplug(slot)) {
658 } else if (device_status_valid(get_slot_status(slot))) {
659 /* remove stale devices if any */
660 list_for_each_entry_safe_reverse(dev, tmp,
661 &bus->devices, bus_list)
662 if (PCI_SLOT(dev->devfn) == slot->device)
663 trim_stale_devices(dev);
665 /* configure all functions */
673 pm_runtime_put(&bridge->pci_dev->dev);
677 * Remove devices for which we could not assign resources, call
678 * arch specific code to fix-up the bus
680 static void acpiphp_sanitize_bus(struct pci_bus *bus)
682 struct pci_dev *dev, *tmp;
684 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
686 list_for_each_entry_safe_reverse(dev, tmp, &bus->devices, bus_list) {
687 for (i = 0; i < PCI_BRIDGE_RESOURCES; i++) {
688 struct resource *res = &dev->resource[i];
689 if ((res->flags & type_mask) && !res->start &&
691 /* Could not assign a required resources
692 * for this device, remove it */
693 pci_stop_and_remove_bus_device(dev);
701 * ACPI event handlers
704 void acpiphp_check_host_bridge(struct acpi_device *adev)
706 struct acpiphp_bridge *bridge = NULL;
708 acpi_lock_hp_context();
710 bridge = to_acpiphp_root_context(adev->hp)->root_bridge;
714 acpi_unlock_hp_context();
716 pci_lock_rescan_remove();
718 acpiphp_check_bridge(bridge);
720 pci_unlock_rescan_remove();
725 static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot);
727 static void hotplug_event(u32 type, struct acpiphp_context *context)
729 acpi_handle handle = context->hp.self->handle;
730 struct acpiphp_func *func = &context->func;
731 struct acpiphp_slot *slot = func->slot;
732 struct acpiphp_bridge *bridge;
734 acpi_lock_hp_context();
735 bridge = context->bridge;
739 acpi_unlock_hp_context();
741 pci_lock_rescan_remove();
744 case ACPI_NOTIFY_BUS_CHECK:
745 /* bus re-enumerate */
746 acpi_handle_debug(handle, "Bus check in %s()\n", __func__);
748 acpiphp_check_bridge(bridge);
749 else if (!(slot->flags & SLOT_IS_GOING_AWAY))
754 case ACPI_NOTIFY_DEVICE_CHECK:
756 acpi_handle_debug(handle, "Device check in %s()\n", __func__);
758 acpiphp_check_bridge(bridge);
759 } else if (!(slot->flags & SLOT_IS_GOING_AWAY)) {
761 * Check if anything has changed in the slot and rescan
762 * from the parent if that's the case.
764 if (acpiphp_rescan_slot(slot))
765 acpiphp_check_bridge(func->parent);
769 case ACPI_NOTIFY_EJECT_REQUEST:
770 /* request device eject */
771 acpi_handle_debug(handle, "Eject request in %s()\n", __func__);
772 acpiphp_disable_and_eject_slot(slot);
776 pci_unlock_rescan_remove();
781 static int acpiphp_hotplug_notify(struct acpi_device *adev, u32 type)
783 struct acpiphp_context *context;
785 context = acpiphp_grab_context(adev);
789 hotplug_event(type, context);
790 acpiphp_let_context_go(context);
795 * acpiphp_enumerate_slots - Enumerate PCI slots for a given bus.
796 * @bus: PCI bus to enumerate the slots for.
798 * A "slot" is an object associated with a PCI device number. All functions
799 * (PCI devices) with the same bus and device number belong to the same slot.
801 void acpiphp_enumerate_slots(struct pci_bus *bus)
803 struct acpiphp_bridge *bridge;
804 struct acpi_device *adev;
808 if (acpiphp_disabled)
811 adev = ACPI_COMPANION(bus->bridge);
815 handle = adev->handle;
816 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
818 acpi_handle_err(handle, "No memory for bridge object\n");
822 INIT_LIST_HEAD(&bridge->slots);
823 kref_init(&bridge->ref);
824 bridge->pci_dev = pci_dev_get(bus->self);
825 bridge->pci_bus = bus;
828 * Grab a ref to the subordinate PCI bus in case the bus is
829 * removed via PCI core logical hotplug. The ref pins the bus
830 * (which we access during module unload).
832 get_device(&bus->dev);
834 acpi_lock_hp_context();
835 if (pci_is_root_bus(bridge->pci_bus)) {
836 struct acpiphp_root_context *root_context;
838 root_context = kzalloc(sizeof(*root_context), GFP_KERNEL);
842 root_context->root_bridge = bridge;
843 acpi_set_hp_context(adev, &root_context->hp);
845 struct acpiphp_context *context;
848 * This bridge should have been registered as a hotplug function
849 * under its parent, so the context should be there, unless the
850 * parent is going to be handled by pciehp, in which case this
851 * bridge is not interesting to us either.
853 context = acpiphp_get_context(adev);
857 bridge->context = context;
858 context->bridge = bridge;
859 /* Get a reference to the parent bridge. */
860 get_bridge(context->func.parent);
862 acpi_unlock_hp_context();
864 /* Must be added to the list prior to calling acpiphp_add_context(). */
865 mutex_lock(&bridge_mutex);
866 list_add(&bridge->list, &bridge_list);
867 mutex_unlock(&bridge_mutex);
869 /* register all slot objects under this bridge */
870 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
871 acpiphp_add_context, NULL, bridge, NULL);
872 if (ACPI_FAILURE(status)) {
873 acpi_handle_err(handle, "failed to register slots\n");
874 cleanup_bridge(bridge);
880 acpi_unlock_hp_context();
881 put_device(&bus->dev);
882 pci_dev_put(bridge->pci_dev);
886 static void acpiphp_drop_bridge(struct acpiphp_bridge *bridge)
888 if (pci_is_root_bus(bridge->pci_bus)) {
889 struct acpiphp_root_context *root_context;
890 struct acpi_device *adev;
892 acpi_lock_hp_context();
893 adev = ACPI_COMPANION(bridge->pci_bus->bridge);
894 root_context = to_acpiphp_root_context(adev->hp);
896 acpi_unlock_hp_context();
899 cleanup_bridge(bridge);
904 * acpiphp_remove_slots - Remove slot objects associated with a given bus.
905 * @bus: PCI bus to remove the slot objects for.
907 void acpiphp_remove_slots(struct pci_bus *bus)
909 struct acpiphp_bridge *bridge;
911 if (acpiphp_disabled)
914 mutex_lock(&bridge_mutex);
915 list_for_each_entry(bridge, &bridge_list, list)
916 if (bridge->pci_bus == bus) {
917 mutex_unlock(&bridge_mutex);
918 acpiphp_drop_bridge(bridge);
922 mutex_unlock(&bridge_mutex);
926 * acpiphp_enable_slot - power on slot
927 * @slot: ACPI PHP slot
929 int acpiphp_enable_slot(struct acpiphp_slot *slot)
931 pci_lock_rescan_remove();
933 if (slot->flags & SLOT_IS_GOING_AWAY) {
934 pci_unlock_rescan_remove();
938 /* configure all functions */
939 if (!(slot->flags & SLOT_ENABLED))
942 pci_unlock_rescan_remove();
947 * acpiphp_disable_and_eject_slot - power off and eject slot
948 * @slot: ACPI PHP slot
950 static int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot)
952 struct acpiphp_func *func;
954 if (slot->flags & SLOT_IS_GOING_AWAY)
957 /* unconfigure all functions */
960 list_for_each_entry(func, &slot->funcs, sibling)
961 if (func->flags & FUNC_HAS_EJ0) {
962 acpi_handle handle = func_to_handle(func);
964 if (ACPI_FAILURE(acpi_evaluate_ej0(handle)))
965 acpi_handle_err(handle, "_EJ0 failed\n");
973 int acpiphp_disable_slot(struct acpiphp_slot *slot)
978 * Acquire acpi_scan_lock to ensure that the execution of _EJ0 in
979 * acpiphp_disable_and_eject_slot() will be synchronized properly.
981 acpi_scan_lock_acquire();
982 pci_lock_rescan_remove();
983 ret = acpiphp_disable_and_eject_slot(slot);
984 pci_unlock_rescan_remove();
985 acpi_scan_lock_release();
993 u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
995 return (slot->flags & SLOT_ENABLED);
1002 u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1004 return !(get_slot_status(slot) & ACPI_STA_DEVICE_UI);
1008 * adapter presence : 1
1011 u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1013 return !!get_slot_status(slot);