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 #include <linux/init.h>
43 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/pci.h>
47 #include <linux/pci_hotplug.h>
48 #include <linux/pci-acpi.h>
49 #include <linux/mutex.h>
50 #include <linux/slab.h>
51 #include <linux/acpi.h>
56 static LIST_HEAD(bridge_list);
57 static DEFINE_MUTEX(bridge_mutex);
58 static DEFINE_MUTEX(acpiphp_context_lock);
60 #define MY_NAME "acpiphp_glue"
62 static void handle_hotplug_event(acpi_handle handle, u32 type, void *data);
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(acpi_handle handle, u32 type, void *data);
66 static void free_bridge(struct kref *kref);
68 static void acpiphp_context_handler(acpi_handle handle, void *context)
70 /* Intentionally empty. */
74 * acpiphp_init_context - Create hotplug context and grab a reference to it.
75 * @handle: ACPI object handle to create the context for.
77 * Call under acpiphp_context_lock.
79 static struct acpiphp_context *acpiphp_init_context(acpi_handle handle)
81 struct acpiphp_context *context;
84 context = kzalloc(sizeof(*context), GFP_KERNEL);
88 context->handle = handle;
89 context->refcount = 1;
90 status = acpi_attach_data(handle, acpiphp_context_handler, context);
91 if (ACPI_FAILURE(status)) {
99 * acpiphp_get_context - Get hotplug context and grab a reference to it.
100 * @handle: ACPI object handle to get the context for.
102 * Call under acpiphp_context_lock.
104 static struct acpiphp_context *acpiphp_get_context(acpi_handle handle)
106 struct acpiphp_context *context = NULL;
110 status = acpi_get_data(handle, acpiphp_context_handler, &data);
111 if (ACPI_SUCCESS(status)) {
119 * acpiphp_put_context - Drop a reference to ACPI hotplug context.
120 * @handle: ACPI object handle to put the context for.
122 * The context object is removed if there are no more references to it.
124 * Call under acpiphp_context_lock.
126 static void acpiphp_put_context(struct acpiphp_context *context)
128 if (--context->refcount)
131 WARN_ON(context->bridge);
132 acpi_detach_data(context->handle, acpiphp_context_handler);
136 static inline void get_bridge(struct acpiphp_bridge *bridge)
138 kref_get(&bridge->ref);
141 static inline void put_bridge(struct acpiphp_bridge *bridge)
143 kref_put(&bridge->ref, free_bridge);
146 static void free_bridge(struct kref *kref)
148 struct acpiphp_context *context;
149 struct acpiphp_bridge *bridge;
150 struct acpiphp_slot *slot, *next;
151 struct acpiphp_func *func, *tmp;
153 mutex_lock(&acpiphp_context_lock);
155 bridge = container_of(kref, struct acpiphp_bridge, ref);
157 list_for_each_entry_safe(slot, next, &bridge->slots, node) {
158 list_for_each_entry_safe(func, tmp, &slot->funcs, sibling)
159 acpiphp_put_context(func_to_context(func));
164 context = bridge->context;
165 /* Root bridges will not have hotplug context. */
167 /* Release the reference taken by acpiphp_enumerate_slots(). */
168 put_bridge(context->func.parent);
169 context->bridge = NULL;
170 acpiphp_put_context(context);
173 put_device(&bridge->pci_bus->dev);
174 pci_dev_put(bridge->pci_dev);
177 mutex_unlock(&acpiphp_context_lock);
181 * the _DCK method can do funny things... and sometimes not
184 * TBD - figure out a way to only call fixups for
185 * systems that require them.
187 static void post_dock_fixups(acpi_handle not_used, u32 event, void *data)
189 struct acpiphp_context *context = data;
190 struct pci_bus *bus = context->func.slot->bus;
196 /* fixup bad _DCK function that rewrites
197 * secondary bridge on slot
199 pci_read_config_dword(bus->self,
203 if (((buses >> 8) & 0xff) != bus->busn_res.start) {
204 buses = (buses & 0xff000000)
205 | ((unsigned int)(bus->primary) << 0)
206 | ((unsigned int)(bus->busn_res.start) << 8)
207 | ((unsigned int)(bus->busn_res.end) << 16);
208 pci_write_config_dword(bus->self, PCI_PRIMARY_BUS, buses);
213 static const struct acpi_dock_ops acpiphp_dock_ops = {
214 .fixup = post_dock_fixups,
215 .handler = hotplug_event,
218 /* Check whether the PCI device is managed by native PCIe hotplug driver */
219 static bool device_is_managed_by_native_pciehp(struct pci_dev *pdev)
223 struct acpi_pci_root *root;
225 /* Check whether the PCIe port supports native PCIe hotplug */
226 if (pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP, ®32))
228 if (!(reg32 & PCI_EXP_SLTCAP_HPC))
232 * Check whether native PCIe hotplug has been enabled for
233 * this PCIe hierarchy.
235 tmp = acpi_find_root_bridge_handle(pdev);
238 root = acpi_pci_find_root(tmp);
241 if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL))
247 static void acpiphp_dock_init(void *data)
249 struct acpiphp_context *context = data;
251 get_bridge(context->func.parent);
254 static void acpiphp_dock_release(void *data)
256 struct acpiphp_context *context = data;
258 put_bridge(context->func.parent);
261 /* callback routine to register each ACPI PCI slot object */
262 static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data,
265 struct acpiphp_bridge *bridge = data;
266 struct acpiphp_context *context;
267 struct acpiphp_slot *slot;
268 struct acpiphp_func *newfunc;
269 acpi_status status = AE_OK;
270 unsigned long long adr;
271 int device, function;
272 struct pci_bus *pbus = bridge->pci_bus;
273 struct pci_dev *pdev = bridge->pci_dev;
276 if (pdev && device_is_managed_by_native_pciehp(pdev))
279 status = acpi_evaluate_integer(handle, "_ADR", NULL, &adr);
280 if (ACPI_FAILURE(status)) {
281 acpi_handle_warn(handle, "can't evaluate _ADR (%#x)\n", status);
285 device = (adr >> 16) & 0xffff;
286 function = adr & 0xffff;
288 mutex_lock(&acpiphp_context_lock);
289 context = acpiphp_init_context(handle);
291 mutex_unlock(&acpiphp_context_lock);
292 acpi_handle_err(handle, "No hotplug context\n");
295 newfunc = &context->func;
296 newfunc->function = function;
297 newfunc->parent = bridge;
298 mutex_unlock(&acpiphp_context_lock);
300 if (acpi_has_method(handle, "_EJ0"))
301 newfunc->flags = FUNC_HAS_EJ0;
303 if (acpi_has_method(handle, "_STA"))
304 newfunc->flags |= FUNC_HAS_STA;
306 if (acpi_has_method(handle, "_DCK"))
307 newfunc->flags |= FUNC_HAS_DCK;
309 /* search for objects that share the same slot */
310 list_for_each_entry(slot, &bridge->slots, node)
311 if (slot->device == device)
314 slot = kzalloc(sizeof(struct acpiphp_slot), GFP_KERNEL);
316 status = AE_NO_MEMORY;
320 slot->bus = bridge->pci_bus;
321 slot->device = device;
322 INIT_LIST_HEAD(&slot->funcs);
323 mutex_init(&slot->crit_sect);
325 mutex_lock(&bridge_mutex);
326 list_add_tail(&slot->node, &bridge->slots);
327 mutex_unlock(&bridge_mutex);
329 /* Register slots for ejectable funtions only. */
330 if (acpi_pci_check_ejectable(pbus, handle) || is_dock_device(handle)) {
331 unsigned long long sun;
335 status = acpi_evaluate_integer(handle, "_SUN", NULL, &sun);
336 if (ACPI_FAILURE(status))
337 sun = bridge->nr_slots;
339 dbg("found ACPI PCI Hotplug slot %llu at PCI %04x:%02x:%02x\n",
340 sun, pci_domain_nr(pbus), pbus->number, device);
342 retval = acpiphp_register_hotplug_slot(slot, sun);
345 if (retval == -EBUSY)
346 warn("Slot %llu already registered by another "
347 "hotplug driver\n", sun);
349 warn("acpiphp_register_hotplug_slot failed "
350 "(err code = 0x%x)\n", retval);
352 /* Even if the slot registration fails, we can still use it. */
356 newfunc->slot = slot;
357 mutex_lock(&bridge_mutex);
358 list_add_tail(&newfunc->sibling, &slot->funcs);
359 mutex_unlock(&bridge_mutex);
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 dbg("failed to register dock device\n");
377 /* install notify handler */
378 if (!(newfunc->flags & FUNC_HAS_DCK)) {
379 status = acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
380 handle_hotplug_event,
382 if (ACPI_FAILURE(status))
383 acpi_handle_err(handle,
384 "failed to install notify handler\n");
390 mutex_lock(&acpiphp_context_lock);
391 acpiphp_put_context(context);
392 mutex_unlock(&acpiphp_context_lock);
396 static struct acpiphp_bridge *acpiphp_handle_to_bridge(acpi_handle handle)
398 struct acpiphp_context *context;
399 struct acpiphp_bridge *bridge = NULL;
401 mutex_lock(&acpiphp_context_lock);
402 context = acpiphp_get_context(handle);
404 bridge = context->bridge;
408 acpiphp_put_context(context);
410 mutex_unlock(&acpiphp_context_lock);
414 static void cleanup_bridge(struct acpiphp_bridge *bridge)
416 struct acpiphp_slot *slot;
417 struct acpiphp_func *func;
420 list_for_each_entry(slot, &bridge->slots, node) {
421 list_for_each_entry(func, &slot->funcs, sibling) {
422 acpi_handle handle = func_to_handle(func);
424 if (is_dock_device(handle))
425 unregister_hotplug_dock_device(handle);
427 if (!(func->flags & FUNC_HAS_DCK)) {
428 status = acpi_remove_notify_handler(handle,
430 handle_hotplug_event);
431 if (ACPI_FAILURE(status))
432 err("failed to remove notify handler\n");
435 acpiphp_unregister_hotplug_slot(slot);
438 mutex_lock(&bridge_mutex);
439 list_del(&bridge->list);
440 mutex_unlock(&bridge_mutex);
444 * acpiphp_max_busnr - return the highest reserved bus number under the given bus.
445 * @bus: bus to start search with
447 static unsigned char acpiphp_max_busnr(struct pci_bus *bus)
449 struct list_head *tmp;
450 unsigned char max, n;
453 * pci_bus_max_busnr will return the highest
454 * reserved busnr for all these children.
455 * that is equivalent to the bus->subordinate
456 * value. We don't want to use the parent's
457 * bus->subordinate value because it could have
460 max = bus->busn_res.start;
462 list_for_each(tmp, &bus->children) {
463 n = pci_bus_max_busnr(pci_bus_b(tmp));
471 * acpiphp_bus_trim - Trim device objects in an ACPI namespace subtree.
472 * @handle: ACPI device object handle to start from.
474 static void acpiphp_bus_trim(acpi_handle handle)
476 struct acpi_device *adev = NULL;
478 acpi_bus_get_device(handle, &adev);
484 * acpiphp_bus_add - Scan ACPI namespace subtree.
485 * @handle: ACPI object handle to start the scan from.
487 static void acpiphp_bus_add(acpi_handle handle)
489 struct acpi_device *adev = NULL;
491 acpiphp_bus_trim(handle);
492 acpi_bus_scan(handle);
493 acpi_bus_get_device(handle, &adev);
495 acpi_device_set_power(adev, ACPI_STATE_D0);
498 static void acpiphp_set_acpi_region(struct acpiphp_slot *slot)
500 struct acpiphp_func *func;
501 union acpi_object params[2];
502 struct acpi_object_list arg_list;
504 list_for_each_entry(func, &slot->funcs, sibling) {
506 arg_list.pointer = params;
507 params[0].type = ACPI_TYPE_INTEGER;
508 params[0].integer.value = ACPI_ADR_SPACE_PCI_CONFIG;
509 params[1].type = ACPI_TYPE_INTEGER;
510 params[1].integer.value = 1;
511 /* _REG is optional, we don't care about if there is failure */
512 acpi_evaluate_object(func_to_handle(func), "_REG", &arg_list,
517 static void check_hotplug_bridge(struct acpiphp_slot *slot, struct pci_dev *dev)
519 struct acpiphp_func *func;
521 /* quirk, or pcie could set it already */
522 if (dev->is_hotplug_bridge)
525 list_for_each_entry(func, &slot->funcs, sibling) {
526 if (PCI_FUNC(dev->devfn) == func->function) {
527 dev->is_hotplug_bridge = 1;
534 * enable_device - enable, configure a slot
535 * @slot: slot to be enabled
537 * This function should be called per *physical slot*,
538 * not per each slot object in ACPI namespace.
540 static int __ref enable_device(struct acpiphp_slot *slot)
543 struct pci_bus *bus = slot->bus;
544 struct acpiphp_func *func;
548 list_for_each_entry(func, &slot->funcs, sibling)
549 acpiphp_bus_add(func_to_handle(func));
551 pci_scan_slot(bus, PCI_DEVFN(slot->device, 0));
553 max = acpiphp_max_busnr(bus);
554 for (pass = 0; pass < 2; pass++) {
555 list_for_each_entry(dev, &bus->devices, bus_list) {
556 if (PCI_SLOT(dev->devfn) != slot->device)
558 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
559 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
560 max = pci_scan_bridge(bus, dev, max, pass);
561 if (pass && dev->subordinate) {
562 check_hotplug_bridge(slot, dev);
563 pcibios_resource_survey_bus(dev->subordinate);
564 __pci_bus_size_bridges(dev->subordinate,
571 __pci_bus_assign_resources(bus, &add_list, NULL);
572 acpiphp_sanitize_bus(bus);
573 acpiphp_set_hpp_values(bus);
574 acpiphp_set_acpi_region(slot);
575 pci_enable_bridges(bus);
577 list_for_each_entry(dev, &bus->devices, bus_list) {
578 /* Assume that newly added devices are powered on already. */
580 dev->current_state = PCI_D0;
583 pci_bus_add_devices(bus);
585 slot->flags |= SLOT_ENABLED;
586 list_for_each_entry(func, &slot->funcs, sibling) {
587 dev = pci_get_slot(bus, PCI_DEVFN(slot->device,
590 /* Do not set SLOT_ENABLED flag if some funcs
592 slot->flags &= (~SLOT_ENABLED);
600 /* return first device in slot, acquiring a reference on it */
601 static struct pci_dev *dev_in_slot(struct acpiphp_slot *slot)
603 struct pci_bus *bus = slot->bus;
605 struct pci_dev *ret = NULL;
607 down_read(&pci_bus_sem);
608 list_for_each_entry(dev, &bus->devices, bus_list)
609 if (PCI_SLOT(dev->devfn) == slot->device) {
610 ret = pci_dev_get(dev);
613 up_read(&pci_bus_sem);
619 * disable_device - disable a slot
620 * @slot: ACPI PHP slot
622 static int disable_device(struct acpiphp_slot *slot)
624 struct acpiphp_func *func;
625 struct pci_dev *pdev;
628 * enable_device() enumerates all functions in this device via
629 * pci_scan_slot(), whether they have associated ACPI hotplug
630 * methods (_EJ0, etc.) or not. Therefore, we remove all functions
633 while ((pdev = dev_in_slot(slot))) {
634 pci_stop_and_remove_bus_device(pdev);
638 list_for_each_entry(func, &slot->funcs, sibling)
639 acpiphp_bus_trim(func_to_handle(func));
641 slot->flags &= (~SLOT_ENABLED);
648 * get_slot_status - get ACPI slot status
649 * @slot: ACPI PHP slot
651 * If a slot has _STA for each function and if any one of them
652 * returned non-zero status, return it.
654 * If a slot doesn't have _STA and if any one of its functions'
655 * configuration space is configured, return 0x0f as a _STA.
657 * Otherwise return 0.
659 static unsigned int get_slot_status(struct acpiphp_slot *slot)
661 unsigned long long sta = 0;
662 struct acpiphp_func *func;
664 list_for_each_entry(func, &slot->funcs, sibling) {
665 if (func->flags & FUNC_HAS_STA) {
668 status = acpi_evaluate_integer(func_to_handle(func),
670 if (ACPI_SUCCESS(status) && sta)
675 pci_bus_read_config_dword(slot->bus,
676 PCI_DEVFN(slot->device,
678 PCI_VENDOR_ID, &dvid);
679 if (dvid != 0xffffffff) {
686 return (unsigned int)sta;
690 * acpiphp_check_bridge - re-enumerate devices
691 * @bridge: where to begin re-enumeration
693 * Iterate over all slots under this bridge and make sure that if a
694 * card is present they are enabled, and if not they are disabled.
696 static int acpiphp_check_bridge(struct acpiphp_bridge *bridge)
698 struct acpiphp_slot *slot;
700 int enabled, disabled;
702 enabled = disabled = 0;
704 list_for_each_entry(slot, &bridge->slots, node) {
705 unsigned int status = get_slot_status(slot);
706 if (slot->flags & SLOT_ENABLED) {
707 if (status == ACPI_STA_ALL)
710 retval = acpiphp_disable_and_eject_slot(slot);
716 if (status != ACPI_STA_ALL)
718 retval = acpiphp_enable_slot(slot);
720 err("Error occurred in enabling\n");
727 dbg("%s: %d enabled, %d disabled\n", __func__, enabled, disabled);
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(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
770 check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
772 struct acpiphp_bridge *bridge;
774 struct acpi_buffer buffer = { .length = sizeof(objname),
775 .pointer = objname };
777 bridge = acpiphp_handle_to_bridge(handle);
779 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
780 dbg("%s: re-enumerating slots under %s\n",
782 acpiphp_check_bridge(bridge);
788 void acpiphp_check_host_bridge(acpi_handle handle)
790 struct acpiphp_bridge *bridge;
792 bridge = acpiphp_handle_to_bridge(handle);
794 acpiphp_check_bridge(bridge);
798 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
799 ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL, NULL);
802 static void hotplug_event(acpi_handle handle, u32 type, void *data)
804 struct acpiphp_context *context = data;
805 struct acpiphp_func *func = &context->func;
806 struct acpiphp_bridge *bridge;
808 struct acpi_buffer buffer = { .length = sizeof(objname),
809 .pointer = objname };
811 mutex_lock(&acpiphp_context_lock);
812 bridge = context->bridge;
816 mutex_unlock(&acpiphp_context_lock);
818 acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
821 case ACPI_NOTIFY_BUS_CHECK:
822 /* bus re-enumerate */
823 dbg("%s: Bus check notify on %s\n", __func__, objname);
824 dbg("%s: re-enumerating slots under %s\n", __func__, objname);
826 acpiphp_check_bridge(bridge);
827 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
828 ACPI_UINT32_MAX, check_sub_bridges,
831 acpiphp_enable_slot(func->slot);
835 case ACPI_NOTIFY_DEVICE_CHECK:
837 dbg("%s: Device check notify on %s\n", __func__, objname);
839 acpiphp_check_bridge(bridge);
841 acpiphp_check_bridge(func->parent);
845 case ACPI_NOTIFY_EJECT_REQUEST:
846 /* request device eject */
847 dbg("%s: Device eject notify on %s\n", __func__, objname);
848 acpiphp_disable_and_eject_slot(func->slot);
856 static void hotplug_event_work(struct work_struct *work)
858 struct acpiphp_context *context;
859 struct acpi_hp_work *hp_work;
861 hp_work = container_of(work, struct acpi_hp_work, work);
862 context = hp_work->context;
863 acpi_scan_lock_acquire();
865 hotplug_event(hp_work->handle, hp_work->type, context);
867 acpi_scan_lock_release();
868 kfree(hp_work); /* allocated in handle_hotplug_event() */
869 put_bridge(context->func.parent);
873 * handle_hotplug_event - handle ACPI hotplug event
874 * @handle: Notify()'ed acpi_handle
876 * @data: pointer to acpiphp_context structure
878 * Handles ACPI event notification on slots.
880 static void handle_hotplug_event(acpi_handle handle, u32 type, void *data)
882 struct acpiphp_context *context;
885 case ACPI_NOTIFY_BUS_CHECK:
886 case ACPI_NOTIFY_DEVICE_CHECK:
887 case ACPI_NOTIFY_EJECT_REQUEST:
890 case ACPI_NOTIFY_DEVICE_WAKE:
893 case ACPI_NOTIFY_FREQUENCY_MISMATCH:
894 acpi_handle_err(handle, "Device cannot be configured due "
895 "to a frequency mismatch\n");
898 case ACPI_NOTIFY_BUS_MODE_MISMATCH:
899 acpi_handle_err(handle, "Device cannot be configured due "
900 "to a bus mode mismatch\n");
903 case ACPI_NOTIFY_POWER_FAULT:
904 acpi_handle_err(handle, "Device has suffered a power fault\n");
908 acpi_handle_warn(handle, "Unsupported event type 0x%x\n", type);
912 mutex_lock(&acpiphp_context_lock);
913 context = acpiphp_get_context(handle);
915 get_bridge(context->func.parent);
916 acpiphp_put_context(context);
917 alloc_acpi_hp_work(handle, type, context, hotplug_event_work);
919 mutex_unlock(&acpiphp_context_lock);
923 * Create hotplug slots for the PCI bus.
924 * It should always return 0 to avoid skipping following notifiers.
926 void acpiphp_enumerate_slots(struct pci_bus *bus)
928 struct acpiphp_bridge *bridge;
932 if (acpiphp_disabled)
935 handle = ACPI_HANDLE(bus->bridge);
939 bridge = kzalloc(sizeof(struct acpiphp_bridge), GFP_KERNEL);
941 acpi_handle_err(handle, "No memory for bridge object\n");
945 INIT_LIST_HEAD(&bridge->slots);
946 kref_init(&bridge->ref);
947 bridge->pci_dev = pci_dev_get(bus->self);
948 bridge->pci_bus = bus;
951 * Grab a ref to the subordinate PCI bus in case the bus is
952 * removed via PCI core logical hotplug. The ref pins the bus
953 * (which we access during module unload).
955 get_device(&bus->dev);
957 if (!pci_is_root_bus(bridge->pci_bus)) {
958 struct acpiphp_context *context;
961 * This bridge should have been registered as a hotplug function
962 * under its parent, so the context has to be there. If not, we
965 mutex_lock(&acpiphp_context_lock);
966 context = acpiphp_get_context(handle);
967 if (WARN_ON(!context)) {
968 mutex_unlock(&acpiphp_context_lock);
969 put_device(&bus->dev);
973 bridge->context = context;
974 context->bridge = bridge;
975 /* Get a reference to the parent bridge. */
976 get_bridge(context->func.parent);
977 mutex_unlock(&acpiphp_context_lock);
980 /* must be added to the list prior to calling register_slot */
981 mutex_lock(&bridge_mutex);
982 list_add(&bridge->list, &bridge_list);
983 mutex_unlock(&bridge_mutex);
985 /* register all slot objects under this bridge */
986 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
987 register_slot, NULL, bridge, NULL);
988 if (ACPI_FAILURE(status)) {
989 acpi_handle_err(handle, "failed to register slots\n");
990 cleanup_bridge(bridge);
995 /* Destroy hotplug slots associated with the PCI bus */
996 void acpiphp_remove_slots(struct pci_bus *bus)
998 struct acpiphp_bridge *bridge, *tmp;
1000 if (acpiphp_disabled)
1003 list_for_each_entry_safe(bridge, tmp, &bridge_list, list)
1004 if (bridge->pci_bus == bus) {
1005 cleanup_bridge(bridge);
1012 * acpiphp_enable_slot - power on slot
1013 * @slot: ACPI PHP slot
1015 int acpiphp_enable_slot(struct acpiphp_slot *slot)
1019 mutex_lock(&slot->crit_sect);
1021 /* configure all functions */
1022 if (!(slot->flags & SLOT_ENABLED))
1023 retval = enable_device(slot);
1025 mutex_unlock(&slot->crit_sect);
1030 * acpiphp_disable_and_eject_slot - power off and eject slot
1031 * @slot: ACPI PHP slot
1033 int acpiphp_disable_and_eject_slot(struct acpiphp_slot *slot)
1035 struct acpiphp_func *func;
1038 mutex_lock(&slot->crit_sect);
1040 /* unconfigure all functions */
1041 retval = disable_device(slot);
1045 list_for_each_entry(func, &slot->funcs, sibling)
1046 if (func->flags & FUNC_HAS_EJ0) {
1047 acpi_handle handle = func_to_handle(func);
1049 if (ACPI_FAILURE(acpi_evaluate_ej0(handle)))
1050 acpi_handle_err(handle, "_EJ0 failed\n");
1056 mutex_unlock(&slot->crit_sect);
1065 u8 acpiphp_get_power_status(struct acpiphp_slot *slot)
1067 return (slot->flags & SLOT_ENABLED);
1075 u8 acpiphp_get_latch_status(struct acpiphp_slot *slot)
1079 sta = get_slot_status(slot);
1081 return (sta & ACPI_STA_DEVICE_UI) ? 0 : 1;
1086 * adapter presence : 1
1089 u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot)
1093 sta = get_slot_status(slot);
1095 return (sta == 0) ? 0 : 1;