aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/power.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-01-24 06:50:09 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-01-24 06:50:09 -0500
commitb1c0f99bfb89cd9b42e3119ab822a8102fa87909 (patch)
tree4a6f07a25ca239bb579cc583c67b92ab451d40b7 /drivers/acpi/power.c
parent836aedb1414d4724b2ec68dd19810960c593720c (diff)
ACPI / PM: Expose current status of ACPI power resources
Since ACPI power resources are going to be used more extensively on new hardware platforms, it becomes necessary for user space (powertop in particular) to observe some properties of those resources for diagnostics purposes. For this reason, expose the current status of each ACPI power resource to user space via sysfs by adding a new resource_in_use attribute to the sysfs directory representing the given power resource. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/acpi/power.c')
-rw-r--r--drivers/acpi/power.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 3f16dd4db23e..946720a4db57 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -87,6 +87,12 @@ static DEFINE_MUTEX(power_resource_list_lock);
87 Power Resource Management 87 Power Resource Management
88 -------------------------------------------------------------------------- */ 88 -------------------------------------------------------------------------- */
89 89
90static inline
91struct acpi_power_resource *to_power_resource(struct acpi_device *device)
92{
93 return container_of(device, struct acpi_power_resource, device);
94}
95
90static struct acpi_power_resource *acpi_power_get_context(acpi_handle handle) 96static struct acpi_power_resource *acpi_power_get_context(acpi_handle handle)
91{ 97{
92 struct acpi_device *device; 98 struct acpi_device *device;
@@ -94,7 +100,7 @@ static struct acpi_power_resource *acpi_power_get_context(acpi_handle handle)
94 if (acpi_bus_get_device(handle, &device)) 100 if (acpi_bus_get_device(handle, &device))
95 return NULL; 101 return NULL;
96 102
97 return container_of(device, struct acpi_power_resource, device); 103 return to_power_resource(device);
98} 104}
99 105
100static int acpi_power_resources_list_add(acpi_handle handle, 106static int acpi_power_resources_list_add(acpi_handle handle,
@@ -678,6 +684,21 @@ static void acpi_release_power_resource(struct device *dev)
678 kfree(resource); 684 kfree(resource);
679} 685}
680 686
687static ssize_t acpi_power_in_use_show(struct device *dev,
688 struct device_attribute *attr,
689 char *buf) {
690 struct acpi_power_resource *resource;
691
692 resource = to_power_resource(to_acpi_device(dev));
693 return sprintf(buf, "%u\n", !!resource->ref_count);
694}
695static DEVICE_ATTR(resource_in_use, 0444, acpi_power_in_use_show, NULL);
696
697static void acpi_power_sysfs_remove(struct acpi_device *device)
698{
699 device_remove_file(&device->dev, &dev_attr_resource_in_use);
700}
701
681int acpi_add_power_resource(acpi_handle handle) 702int acpi_add_power_resource(acpi_handle handle)
682{ 703{
683 struct acpi_power_resource *resource; 704 struct acpi_power_resource *resource;
@@ -725,6 +746,9 @@ int acpi_add_power_resource(acpi_handle handle)
725 if (result) 746 if (result)
726 goto err; 747 goto err;
727 748
749 if (!device_create_file(&device->dev, &dev_attr_resource_in_use))
750 device->remove = acpi_power_sysfs_remove;
751
728 mutex_lock(&power_resource_list_lock); 752 mutex_lock(&power_resource_list_lock);
729 list_add(&resource->list_node, &acpi_power_resource_list); 753 list_add(&resource->list_node, &acpi_power_resource_list);
730 mutex_unlock(&power_resource_list_lock); 754 mutex_unlock(&power_resource_list_lock);