platform/x86: wmi: Allow retrieving the number of WMI object instances
authorArmin Wolf <W_Armin@gmx.de>
Sun, 30 Apr 2023 20:31:52 +0000 (22:31 +0200)
committerHans de Goede <hdegoede@redhat.com>
Tue, 9 May 2023 10:07:25 +0000 (12:07 +0200)
Currently, the WMI driver core knows how many instances of a given
WMI object exist, but WMI drivers cannot access this information.
At the same time, some current and upcoming WMI drivers want to
have access to this information. Add wmi_instance_count() and
wmidev_instance_count() to allow WMI drivers to get the number of
WMI object instances.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Link: https://lore.kernel.org/r/20230430203153.5587-2-W_Armin@gmx.de
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/platform/x86/wmi.c
include/linux/acpi.h
include/linux/wmi.h

index c226dd4163a1c97bddc302a446063be7d42d553d..5b95d7aa5c2f1a1263fd1e6ca14ec115e74d39ed 100644 (file)
@@ -263,6 +263,47 @@ int set_required_buffer_size(struct wmi_device *wdev, u64 length)
 }
 EXPORT_SYMBOL_GPL(set_required_buffer_size);
 
+/**
+ * wmi_instance_count - Get number of WMI object instances
+ * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
+ *
+ * Get the number of WMI object instances.
+ *
+ * Returns: Number of WMI object instances or negative error code.
+ */
+int wmi_instance_count(const char *guid_string)
+{
+       struct wmi_block *wblock;
+       acpi_status status;
+
+       status = find_guid(guid_string, &wblock);
+       if (ACPI_FAILURE(status)) {
+               if (status == AE_BAD_PARAMETER)
+                       return -EINVAL;
+
+               return -ENODEV;
+       }
+
+       return wmidev_instance_count(&wblock->dev);
+}
+EXPORT_SYMBOL_GPL(wmi_instance_count);
+
+/**
+ * wmidev_instance_count - Get number of WMI object instances
+ * @wdev: A wmi bus device from a driver
+ *
+ * Get the number of WMI object instances.
+ *
+ * Returns: Number of WMI object instances.
+ */
+u8 wmidev_instance_count(struct wmi_device *wdev)
+{
+       struct wmi_block *wblock = container_of(wdev, struct wmi_block, dev);
+
+       return wblock->gblock.instance_count;
+}
+EXPORT_SYMBOL_GPL(wmidev_instance_count);
+
 /**
  * wmi_evaluate_method - Evaluate a WMI method (deprecated)
  * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
index 7b71dd74baeb3523e825784cacf51536e8f59874..5b9353f5692819c4da46d8e8141cf0999124f958 100644 (file)
@@ -414,6 +414,8 @@ extern bool acpi_is_pnp_device(struct acpi_device *);
 
 typedef void (*wmi_notify_handler) (u32 value, void *context);
 
+int wmi_instance_count(const char *guid);
+
 extern acpi_status wmi_evaluate_method(const char *guid, u8 instance,
                                        u32 method_id,
                                        const struct acpi_buffer *in,
index c1a3bd4e4838f8bbf43443e50b8a6f8adf6d2714..763bd382cf2d12ebf238df4dde899e1c721fd625 100644 (file)
@@ -35,6 +35,8 @@ extern acpi_status wmidev_evaluate_method(struct wmi_device *wdev,
 extern union acpi_object *wmidev_block_query(struct wmi_device *wdev,
                                             u8 instance);
 
+u8 wmidev_instance_count(struct wmi_device *wdev);
+
 extern int set_required_buffer_size(struct wmi_device *wdev, u64 length);
 
 /**