Skip to content

Commit 35009c8

Browse files
andy-shevrafaeljw
authored andcommitted
ACPI / utils: Introduce acpi_dev_hid_uid_match() helper
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 <[email protected]> Reviewed-by: Mika Westerberg <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent a814dcc commit 35009c8

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

drivers/acpi/utils.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,31 @@ bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs)
701701
}
702702
EXPORT_SYMBOL(acpi_check_dsm);
703703

704+
/**
705+
* acpi_dev_hid_uid_match - Match device by supplied HID and UID
706+
* @adev: ACPI device to match.
707+
* @hid2: Hardware ID of the device.
708+
* @uid2: Unique ID of the device, pass NULL to not check _UID.
709+
*
710+
* Matches HID and UID in @adev with given @hid2 and @uid2.
711+
* Returns true if matches.
712+
*/
713+
bool acpi_dev_hid_uid_match(struct acpi_device *adev,
714+
const char *hid2, const char *uid2)
715+
{
716+
const char *hid1 = acpi_device_hid(adev);
717+
const char *uid1 = acpi_device_uid(adev);
718+
719+
if (strcmp(hid1, hid2))
720+
return false;
721+
722+
if (!uid2)
723+
return true;
724+
725+
return uid1 && !strcmp(uid1, uid2);
726+
}
727+
EXPORT_SYMBOL(acpi_dev_hid_uid_match);
728+
704729
/**
705730
* acpi_dev_found - Detect presence of a given ACPI device in the namespace.
706731
* @hid: Hardware ID of the device.

include/acpi/acpi_bus.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
680680
adev->power.states[ACPI_STATE_D3_HOT].flags.explicit_set);
681681
}
682682

683+
bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
684+
683685
struct acpi_device *
684686
acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv);
685687

include/linux/acpi.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,14 @@ static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
678678
return false;
679679
}
680680

681+
struct acpi_device;
682+
683+
static inline bool
684+
acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2)
685+
{
686+
return false;
687+
}
688+
681689
static inline struct acpi_device *
682690
acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
683691
{

0 commit comments

Comments
 (0)