]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ACPI / utils: Introduce acpi_dev_hid_uid_match() helper
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 1 Oct 2019 14:27:22 +0000 (17:27 +0300)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 15 Oct 2019 10:06:23 +0000 (12:06 +0200)
There are users outside of ACPI realm which reimplementing the comparator
function to check if the given device matches to given HID and UID.

For better utilization, introduce a helper for everyone to use.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/utils.c
include/acpi/acpi_bus.h
include/linux/acpi.h

index dbd1c4cfd7d102d805b627cf67a56aa724158629..804ac0df58ec0ed9d15a1ebc85d804889d74358d 100644 (file)
@@ -701,6 +701,31 @@ bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs)
 }
 EXPORT_SYMBOL(acpi_check_dsm);
 
+/**
+ * acpi_dev_hid_uid_match - Match device by supplied HID and UID
+ * @adev: ACPI device to match.
+ * @hid2: Hardware ID of the device.
+ * @uid2: Unique ID of the device, pass NULL to not check _UID.
+ *
+ * Matches HID and UID in @adev with given @hid2 and @uid2.
+ * Returns true if matches.
+ */
+bool acpi_dev_hid_uid_match(struct acpi_device *adev,
+                           const char *hid2, const char *uid2)
+{
+       const char *hid1 = acpi_device_hid(adev);
+       const char *uid1 = acpi_device_uid(adev);
+
+       if (strcmp(hid1, hid2))
+               return false;
+
+       if (!uid2)
+               return true;
+
+       return uid1 && !strcmp(uid1, uid2);
+}
+EXPORT_SYMBOL(acpi_dev_hid_uid_match);
+
 /**
  * acpi_dev_found - Detect presence of a given ACPI device in the namespace.
  * @hid: Hardware ID of the device.
index 3f6fddeb75199ec21f49443c2ee230f11850ea25..0c23fd0548d1a0edc5151a341ddd6d0732789b68 100644 (file)
@@ -680,6 +680,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
                adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
 }
 
+bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
+
 struct acpi_device *
 acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
 
index 8b4e516bac0095debf1cba96318950d87ef0e16b..0f37a7d5fa7748c91fccf4778f093f863907850a 100644 (file)
@@ -678,6 +678,14 @@ static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
        return false;
 }
 
+struct acpi_device;
+
+static inline bool
+acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2)
+{
+       return false;
+}
+
 static inline struct acpi_device *
 acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
 {