[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1349537256-21670-11-git-send-email-jiang.liu@huawei.com>
Date: Sat, 6 Oct 2012 23:27:18 +0800
From: Jiang Liu <liuj97@...il.com>
To: Yinghai Lu <yinghai@...nel.org>,
Yasuaki Ishimatsu <isimatu.yasuaki@...fujitsu.com>,
Kenji Kaneshige <kaneshige.kenji@...fujitsu.com>,
Wen Congyang <wency@...fujitsu.com>,
Tang Chen <tangchen@...fujitsu.com>,
Taku Izumi <izumi.taku@...fujitsu.com>
Cc: Hanjun Guo <guohanjun@...wei.com>,
Yijing Wang <wangyijing@...wei.com>,
Gong Chen <gong.chen@...ux.intel.com>,
Jiang Liu <jiang.liu@...wei.com>,
Tony Luck <tony.luck@...el.com>,
Huang Ying <ying.huang@...el.com>,
Bob Moore <robert.moore@...el.com>,
Len Brown <lenb@...nel.org>,
"Srivatsa S . Bhat" <srivatsa.bhat@...ux.vnet.ibm.com>,
Bjorn Helgaas <bhelgaas@...gle.com>,
linux-kernel@...r.kernel.org, linux-acpi@...r.kernel.org,
linux-pci@...r.kernel.org
Subject: [RFC PATCH v3 10/28] ACPIHP: implement utility functions to support system device hotplug
This patch implements some utility functions to support system device hotplug.
Signed-off-by: Jiang Liu <jiang.liu@...wei.com>
Signed-off-by: Hanjun Guo <guohanjun@...wei.com>
---
drivers/acpi/hotplug/core.c | 77 +++++++++++++++++++++++++++++++++++++++++++
include/acpi/acpi_hotplug.h | 9 +++++
2 files changed, 86 insertions(+)
diff --git a/drivers/acpi/hotplug/core.c b/drivers/acpi/hotplug/core.c
index ffd3b54..ffc9e40 100644
--- a/drivers/acpi/hotplug/core.c
+++ b/drivers/acpi/hotplug/core.c
@@ -605,6 +605,83 @@ int acpihp_remove_device_list(struct klist *dev_list)
}
EXPORT_SYMBOL_GPL(acpihp_remove_device_list);
+bool acpihp_slot_present(struct acpihp_slot *slot)
+{
+ acpi_status status;
+ unsigned long long sta;
+
+ status = acpihp_slot_get_status(slot, &sta);
+ if (ACPI_FAILURE(status)) {
+ ACPIHP_SLOT_WARN(slot, "fails to get status.\n");
+ return false;
+ }
+
+ return !!(sta & ACPI_STA_DEVICE_PRESENT);
+}
+EXPORT_SYMBOL_GPL(acpihp_slot_present);
+
+bool acpihp_slot_powered(struct acpihp_slot *slot)
+{
+ acpi_status status;
+ unsigned long long sta;
+
+ /* hotplug slot must implement _STA method */
+ status = acpihp_slot_get_status(slot, &sta);
+ if (ACPI_FAILURE(status)) {
+ ACPIHP_SLOT_WARN(slot, "fails to get status.\n");
+ return false;
+ }
+
+ if ((sta & ACPI_STA_DEVICE_PRESENT) &&
+ ((sta & ACPI_STA_DEVICE_ENABLED) ||
+ (sta & ACPI_STA_DEVICE_FUNCTIONING)))
+ return true;
+
+ return false;
+}
+EXPORT_SYMBOL_GPL(acpihp_slot_powered);
+
+void acpihp_slot_set_flag(struct acpihp_slot *slot, u32 flags)
+{
+ mutex_lock(&slot->slot_mutex);
+ slot->flags |= flags;
+ mutex_unlock(&slot->slot_mutex);
+}
+EXPORT_SYMBOL_GPL(acpihp_slot_set_flag);
+
+void acpihp_slot_clear_flag(struct acpihp_slot *slot, u32 flags)
+{
+ mutex_lock(&slot->slot_mutex);
+ slot->flags &= ~flags;
+ mutex_unlock(&slot->slot_mutex);
+}
+EXPORT_SYMBOL_GPL(acpihp_slot_clear_flag);
+
+u32 acpihp_slot_get_flag(struct acpihp_slot *slot, u32 flags)
+{
+ mutex_lock(&slot->slot_mutex);
+ flags &= slot->flags;
+ mutex_unlock(&slot->slot_mutex);
+
+ return flags;
+}
+EXPORT_SYMBOL_GPL(acpihp_slot_get_flag);
+
+void acpihp_slot_change_state(struct acpihp_slot *slot,
+ enum acpihp_slot_state state)
+{
+ if (state < ACPIHP_SLOT_STATE_UNKNOWN ||
+ state > ACPIHP_SLOT_STATE_MAX) {
+ ACPIHP_SLOT_WARN(slot, "slot state %d is invalid.\n", state);
+ BUG_ON(state);
+ }
+
+ mutex_lock(&slot->slot_mutex);
+ slot->state = state;
+ mutex_unlock(&slot->slot_mutex);
+}
+EXPORT_SYMBOL_GPL(acpihp_slot_change_state);
+
/* SYSFS interfaces */
static ssize_t acpihp_slot_object_show(struct device *d,
struct device_attribute *attr, char *buf)
diff --git a/include/acpi/acpi_hotplug.h b/include/acpi/acpi_hotplug.h
index 97febcb..0506f73 100644
--- a/include/acpi/acpi_hotplug.h
+++ b/include/acpi/acpi_hotplug.h
@@ -289,6 +289,15 @@ extern int acpihp_slot_remove_device(struct acpihp_slot *slot,
struct device *dev);
extern int acpihp_remove_device_list(struct klist *dev_list);
+/* Utility Functions */
+extern bool acpihp_slot_present(struct acpihp_slot *slot);
+extern bool acpihp_slot_powered(struct acpihp_slot *slot);
+extern void acpihp_slot_set_flag(struct acpihp_slot *slot, u32 flags);
+extern void acpihp_slot_clear_flag(struct acpihp_slot *slot, u32 flags);
+extern u32 acpihp_slot_get_flag(struct acpihp_slot *slot, u32 flags);
+extern void acpihp_slot_change_state(struct acpihp_slot *slot,
+ enum acpihp_slot_state state);
+
extern int acpihp_debug;
#define ACPIHP_WARN(fmt, ...) \
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists