LinuxKPI: Add acpi_dev_get_first_match_dev and acpi_device_handle

acpi_dev_get_first_match_dev returns the first match of ACPI device
and acpi_device_handle returns its ACPI handle.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D45847
This commit is contained in:
Vladimir Kondratyev 2024-07-21 16:09:37 +03:00
parent 5b1171a0b7
commit 3e90716331
3 changed files with 43 additions and 0 deletions

View File

@ -29,6 +29,9 @@
#ifndef _LINUXKPI_ACPI_ACPI_BUS_H_ #ifndef _LINUXKPI_ACPI_ACPI_BUS_H_
#define _LINUXKPI_ACPI_ACPI_BUS_H_ #define _LINUXKPI_ACPI_ACPI_BUS_H_
/* Aliase struct acpi_device to device_t */
#define acpi_device _device
typedef char acpi_device_class[20]; typedef char acpi_device_class[20];
struct acpi_bus_event { struct acpi_bus_event {
@ -38,6 +41,8 @@ struct acpi_bus_event {
}; };
#define acpi_dev_present(...) lkpi_acpi_dev_present(__VA_ARGS__) #define acpi_dev_present(...) lkpi_acpi_dev_present(__VA_ARGS__)
#define acpi_dev_get_first_match_dev(...) \
lkpi_acpi_dev_get_first_match_dev(__VA_ARGS__)
ACPI_HANDLE bsd_acpi_get_handle(device_t bsddev); ACPI_HANDLE bsd_acpi_get_handle(device_t bsddev);
bool acpi_check_dsm(ACPI_HANDLE handle, const char *uuid, int rev, bool acpi_check_dsm(ACPI_HANDLE handle, const char *uuid, int rev,
@ -50,5 +55,7 @@ int unregister_acpi_notifier(struct notifier_block *nb);
uint32_t acpi_target_system_state(void); uint32_t acpi_target_system_state(void);
bool lkpi_acpi_dev_present(const char *hid, const char *uid, bool lkpi_acpi_dev_present(const char *hid, const char *uid,
int64_t hrv); int64_t hrv);
struct acpi_device *lkpi_acpi_dev_get_first_match_dev(const char *hid,
const char *uid, int64_t hrv);
#endif /* _LINUXKPI_ACPI_ACPI_BUS_H_ */ #endif /* _LINUXKPI_ACPI_ACPI_BUS_H_ */

View File

@ -39,6 +39,10 @@
#define ACPI_HANDLE(dev) \ #define ACPI_HANDLE(dev) \
((dev)->bsddev != NULL ? bsd_acpi_get_handle((dev)->bsddev) : NULL) ((dev)->bsddev != NULL ? bsd_acpi_get_handle((dev)->bsddev) : NULL)
#define acpi_device_handle(dev) \
((dev) != NULL ? bsd_acpi_get_handle(dev) : NULL)
static inline void acpi_dev_put(struct acpi_device *adev) {}
#define acpi_handle_debug(handle, fmt, ...)
#endif #endif

View File

@ -180,6 +180,7 @@ struct acpi_dev_present_ctx {
const char *hid; const char *hid;
const char *uid; const char *uid;
int64_t hrv; int64_t hrv;
struct acpi_device *dev;
}; };
static ACPI_STATUS static ACPI_STATUS
@ -187,6 +188,7 @@ acpi_dev_present_cb(ACPI_HANDLE handle, UINT32 level, void *context,
void **result) void **result)
{ {
ACPI_DEVICE_INFO *devinfo; ACPI_DEVICE_INFO *devinfo;
struct acpi_device *dev;
struct acpi_dev_present_ctx *match = context; struct acpi_dev_present_ctx *match = context;
bool present = false; bool present = false;
UINT32 sta, hrv; UINT32 sta, hrv;
@ -230,6 +232,11 @@ acpi_dev_present_cb(ACPI_HANDLE handle, UINT32 level, void *context,
return (AE_OK); return (AE_OK);
} }
dev = acpi_get_device(handle);
if (dev == NULL)
return (AE_OK);
match->dev = dev;
return (AE_ERROR); return (AE_ERROR);
} }
@ -249,6 +256,24 @@ lkpi_acpi_dev_present(const char *hid, const char *uid, int64_t hrv)
return (rv == AE_ERROR); return (rv == AE_ERROR);
} }
struct acpi_device *
lkpi_acpi_dev_get_first_match_dev(const char *hid, const char *uid,
int64_t hrv)
{
struct acpi_dev_present_ctx match;
int rv;
match.hid = hid;
match.uid = uid;
match.hrv = hrv;
match.dev = NULL;
rv = AcpiWalkNamespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
ACPI_UINT32_MAX, acpi_dev_present_cb, NULL, &match, NULL);
return (rv == AE_ERROR ? match.dev : NULL);
}
static void static void
linux_register_acpi_event_handlers(void *arg __unused) linux_register_acpi_event_handlers(void *arg __unused)
{ {
@ -322,4 +347,11 @@ lkpi_acpi_dev_present(const char *hid, const char *uid, int64_t hrv)
return (false); return (false);
} }
struct acpi_device *
lkpi_acpi_dev_get_first_match_dev(const char *hid, const char *uid,
int64_t hrv)
{
return (NULL);
}
#endif /* !DEV_ACPI */ #endif /* !DEV_ACPI */