aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/hotplug/acpi_pcihp.c
diff options
context:
space:
mode:
authorKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>2008-12-16 22:09:12 -0500
committerJesse Barnes <jbarnes@virtuousgeek.org>2009-01-07 14:13:11 -0500
commite8c331e963c58b83db24b7d0e39e8c07f687dbc6 (patch)
treeda9e7df2441da952dc11bd732b0171d3170fa8bf /drivers/pci/hotplug/acpi_pcihp.c
parente046cbd6c05ee859244245d7beeac395cd0057b3 (diff)
PCI hotplug: introduce functions for ACPI slot detection
Some ACPI related PCI hotplug code can be shared among PCI hotplug drivers. This patch introduces the following functions in drivers/pci/hotplug/acpi_pcihp.c to share the code, and changes acpiphp and pciehp to use them. - int acpi_pci_detect_ejectable(struct pci_bus *pbus) This checks if the specified PCI bus has ejectable slots. - int acpi_pci_check_ejectable(struct pci_bus *pbus, acpi_handle handle) This checks if the specified handle is ejectable ACPI PCI slot. The 'pbus' parameter is needed to check if 'handle' is PCI related ACPI object. This patch also introduces the following inline function in include/linux/pci-acpi.h, which is useful to get ACPI handle of the PCI bridge from struct pci_bus of the bridge's secondary bus. - static inline acpi_handle acpi_pci_get_bridge_handle(struct pci_bus *pbus) This returns ACPI handle of the PCI bridge which generates PCI bus specified by 'pbus'. Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Diffstat (limited to 'drivers/pci/hotplug/acpi_pcihp.c')
-rw-r--r--drivers/pci/hotplug/acpi_pcihp.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/drivers/pci/hotplug/acpi_pcihp.c b/drivers/pci/hotplug/acpi_pcihp.c
index e17ef54f0efc..c62ab8d240aa 100644
--- a/drivers/pci/hotplug/acpi_pcihp.c
+++ b/drivers/pci/hotplug/acpi_pcihp.c
@@ -501,5 +501,74 @@ int acpi_root_bridge(acpi_handle handle)
501} 501}
502EXPORT_SYMBOL_GPL(acpi_root_bridge); 502EXPORT_SYMBOL_GPL(acpi_root_bridge);
503 503
504
505static int is_ejectable(acpi_handle handle)
506{
507 acpi_status status;
508 acpi_handle tmp;
509 unsigned long long removable;
510 status = acpi_get_handle(handle, "_ADR", &tmp);
511 if (ACPI_FAILURE(status))
512 return 0;
513 status = acpi_get_handle(handle, "_EJ0", &tmp);
514 if (ACPI_SUCCESS(status))
515 return 1;
516 status = acpi_evaluate_integer(handle, "_RMV", NULL, &removable);
517 if (ACPI_SUCCESS(status) && removable)
518 return 1;
519 return 0;
520}
521
522/**
523 * acpi_pcihp_check_ejectable - check if handle is ejectable ACPI PCI slot
524 * @pbus: the PCI bus of the PCI slot corresponding to 'handle'
525 * @handle: ACPI handle to check
526 *
527 * Return 1 if handle is ejectable PCI slot, 0 otherwise.
528 */
529int acpi_pci_check_ejectable(struct pci_bus *pbus, acpi_handle handle)
530{
531 acpi_handle bridge_handle, parent_handle;
532
533 if (!(bridge_handle = acpi_pci_get_bridge_handle(pbus)))
534 return 0;
535 if ((ACPI_FAILURE(acpi_get_parent(handle, &parent_handle))))
536 return 0;
537 if (bridge_handle != parent_handle)
538 return 0;
539 return is_ejectable(handle);
540}
541EXPORT_SYMBOL_GPL(acpi_pci_check_ejectable);
542
543static acpi_status
544check_hotplug(acpi_handle handle, u32 lvl, void *context, void **rv)
545{
546 int *found = (int *)context;
547 if (is_ejectable(handle)) {
548 *found = 1;
549 return AE_CTRL_TERMINATE;
550 }
551 return AE_OK;
552}
553
554/**
555 * acpi_pci_detect_ejectable - check if the PCI bus has ejectable slots
556 * @pbus - PCI bus to scan
557 *
558 * Returns 1 if the PCI bus has ACPI based ejectable slots, 0 otherwise.
559 */
560int acpi_pci_detect_ejectable(struct pci_bus *pbus)
561{
562 acpi_handle handle;
563 int found = 0;
564
565 if (!(handle = acpi_pci_get_bridge_handle(pbus)))
566 return 0;
567 acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, (u32)1,
568 check_hotplug, (void *)&found, NULL);
569 return found;
570}
571EXPORT_SYMBOL_GPL(acpi_pci_detect_ejectable);
572
504module_param(debug_acpi, bool, 0644); 573module_param(debug_acpi, bool, 0644);
505MODULE_PARM_DESC(debug_acpi, "Debugging mode for ACPI enabled or not"); 574MODULE_PARM_DESC(debug_acpi, "Debugging mode for ACPI enabled or not");