diff --git a/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h b/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h --- a/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h +++ b/sys/compat/linuxkpi/common/include/acpi/acpi_bus.h @@ -29,6 +29,9 @@ #ifndef _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]; struct acpi_bus_event { @@ -38,6 +41,8 @@ }; #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); bool acpi_check_dsm(ACPI_HANDLE handle, const char *uuid, int rev, @@ -50,5 +55,7 @@ uint32_t acpi_target_system_state(void); bool lkpi_acpi_dev_present(const char *hid, const char *uid, 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_ */ diff --git a/sys/compat/linuxkpi/common/include/linux/acpi.h b/sys/compat/linuxkpi/common/include/linux/acpi.h --- a/sys/compat/linuxkpi/common/include/linux/acpi.h +++ b/sys/compat/linuxkpi/common/include/linux/acpi.h @@ -39,6 +39,10 @@ #define ACPI_HANDLE(dev) \ ((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 diff --git a/sys/compat/linuxkpi/common/src/linux_acpi.c b/sys/compat/linuxkpi/common/src/linux_acpi.c --- a/sys/compat/linuxkpi/common/src/linux_acpi.c +++ b/sys/compat/linuxkpi/common/src/linux_acpi.c @@ -180,6 +180,7 @@ const char *hid; const char *uid; int64_t hrv; + struct acpi_device *dev; }; static ACPI_STATUS @@ -187,6 +188,7 @@ void **result) { ACPI_DEVICE_INFO *devinfo; + struct acpi_device *dev; struct acpi_dev_present_ctx *match = context; bool present = false; UINT32 sta, hrv; @@ -230,6 +232,11 @@ return (AE_OK); } + dev = acpi_get_device(handle); + if (dev == NULL) + return (AE_OK); + match->dev = dev; + return (AE_ERROR); } @@ -249,6 +256,24 @@ 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 linux_register_acpi_event_handlers(void *arg __unused) { @@ -322,4 +347,11 @@ 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 */