aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Wunner <lukas@wunner.de>2015-11-25 15:19:55 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-12-08 19:31:41 -0500
commit2d12b6b381ba059d5f92798f5ea739672a2f5fcf (patch)
tree43b44ae5508885d7170fc074d394f9e4aad7ca0b
parentca9dc8d42b30e2d766b471fe5ecf0c71fd309c8f (diff)
ACPI / utils: Add acpi_dev_present()
There's an idiom in use by 7 Linux drivers to detect the presence of a particular ACPI HID by walking the namespace with acpi_get_devices(). The callback passed to acpi_get_devices() is mostly identical across the drivers, leading to lots of duplicate code. Add acpi_dev_present(), the ACPI equivalent to pci_dev_present(), allowing us to deduplicate all that boilerplate in the drivers. Signed-off-by: Lukas Wunner <lukas@wunner.de> Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/internal.h8
-rw-r--r--drivers/acpi/scan.c8
-rw-r--r--drivers/acpi/utils.c31
-rw-r--r--include/acpi/acpi_bus.h2
4 files changed, 42 insertions, 7 deletions
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 11d87bf67e73..60bda0d2cf9a 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -86,6 +86,14 @@ bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent);
86#define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \ 86#define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \
87 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING) 87 ACPI_STA_DEVICE_UI | ACPI_STA_DEVICE_FUNCTIONING)
88 88
89extern struct list_head acpi_bus_id_list;
90
91struct acpi_device_bus_id{
92 char bus_id[15];
93 unsigned int instance_no;
94 struct list_head node;
95};
96
89int acpi_device_add(struct acpi_device *device, 97int acpi_device_add(struct acpi_device *device,
90 void (*release)(struct device *)); 98 void (*release)(struct device *));
91void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, 99void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index be1fc12a17ee..407a3760e8de 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -39,7 +39,7 @@ static const char *dummy_hid = "device";
39 39
40static LIST_HEAD(acpi_dep_list); 40static LIST_HEAD(acpi_dep_list);
41static DEFINE_MUTEX(acpi_dep_list_lock); 41static DEFINE_MUTEX(acpi_dep_list_lock);
42static LIST_HEAD(acpi_bus_id_list); 42LIST_HEAD(acpi_bus_id_list);
43static DEFINE_MUTEX(acpi_scan_lock); 43static DEFINE_MUTEX(acpi_scan_lock);
44static LIST_HEAD(acpi_scan_handlers_list); 44static LIST_HEAD(acpi_scan_handlers_list);
45DEFINE_MUTEX(acpi_device_lock); 45DEFINE_MUTEX(acpi_device_lock);
@@ -52,12 +52,6 @@ struct acpi_dep_data {
52 acpi_handle slave; 52 acpi_handle slave;
53}; 53};
54 54
55struct acpi_device_bus_id{
56 char bus_id[15];
57 unsigned int instance_no;
58 struct list_head node;
59};
60
61void acpi_scan_lock_acquire(void) 55void acpi_scan_lock_acquire(void)
62{ 56{
63 mutex_lock(&acpi_scan_lock); 57 mutex_lock(&acpi_scan_lock);
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 475c9079bf85..f2f9873bb5c3 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -29,6 +29,7 @@
29#include <linux/dynamic_debug.h> 29#include <linux/dynamic_debug.h>
30 30
31#include "internal.h" 31#include "internal.h"
32#include "sleep.h"
32 33
33#define _COMPONENT ACPI_BUS_COMPONENT 34#define _COMPONENT ACPI_BUS_COMPONENT
34ACPI_MODULE_NAME("utils"); 35ACPI_MODULE_NAME("utils");
@@ -709,6 +710,36 @@ bool acpi_check_dsm(acpi_handle handle, const u8 *uuid, int rev, u64 funcs)
709} 710}
710EXPORT_SYMBOL(acpi_check_dsm); 711EXPORT_SYMBOL(acpi_check_dsm);
711 712
713/**
714 * acpi_dev_present - Detect presence of a given ACPI device in the system.
715 * @hid: Hardware ID of the device.
716 *
717 * Return %true if the device was present at the moment of invocation.
718 * Note that if the device is pluggable, it may since have disappeared.
719 *
720 * For this function to work, acpi_bus_scan() must have been executed
721 * which happens in the subsys_initcall() subsection. Hence, do not
722 * call from a subsys_initcall() or earlier (use acpi_get_devices()
723 * instead). Calling from module_init() is fine (which is synonymous
724 * with device_initcall()).
725 */
726bool acpi_dev_present(const char *hid)
727{
728 struct acpi_device_bus_id *acpi_device_bus_id;
729 bool found = false;
730
731 mutex_lock(&acpi_device_lock);
732 list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node)
733 if (!strcmp(acpi_device_bus_id->bus_id, hid)) {
734 found = true;
735 break;
736 }
737 mutex_unlock(&acpi_device_lock);
738
739 return found;
740}
741EXPORT_SYMBOL(acpi_dev_present);
742
712/* 743/*
713 * acpi_backlight= handling, this is done here rather then in video_detect.c 744 * acpi_backlight= handling, this is done here rather then in video_detect.c
714 * because __setup cannot be used in modules. 745 * because __setup cannot be used in modules.
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index ad0a5ff3d4cd..0fe7babf9c24 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -87,6 +87,8 @@ acpi_evaluate_dsm_typed(acpi_handle handle, const u8 *uuid, int rev, int func,
87 .package.elements = (eles) \ 87 .package.elements = (eles) \
88 } 88 }
89 89
90bool acpi_dev_present(const char *hid);
91
90#ifdef CONFIG_ACPI 92#ifdef CONFIG_ACPI
91 93
92#include <linux/proc_fs.h> 94#include <linux/proc_fs.h>