Skip to contentSkip to conversation

platform/x86: wmi: Allow retrieving the number of WMI object instances

RFC Superseded Armin Wolf 2 participants 2 messages Apr 26, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Armin Wolf

author
#0 lore raw

RFC 1/1 platform/x86: wmi: Allow retrieving the number of WMI object instances

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.

---
 drivers/platform/x86/wmi.c | 40 ++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h       |  2 ++
 include/linux/wmi.h        |  2 ++
 3 files changed, 44 insertions(+)
drivers/platform/x86/wmi.c +40 -0
index c226dd4163a1..7c1a904dec5f 100644
@@ -263,6 +263,46 @@ 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
+ * @instance_count: variable to hold the instance count
+ *
+ * Get the number of WMI object instances.
+ *
+ * Returns: acpi_status signaling success or error.
+ */
+acpi_status wmi_instance_count(const char *guid_string, u8 *instance_count)
+{
+	struct wmi_block *wblock;
+	acpi_status status;
+
+	status = find_guid(guid_string, &wblock);
+	if (ACPI_FAILURE(status))
+		return status;
+
+	*instance_count = wmidev_instance_count(&wblock->dev);
+
+	return AE_OK;
+}
+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
include/linux/acpi.h +2 -0
index efff750f326d..ab2a4b23e7a3 100644
@@ -412,6 +412,8 @@ extern bool acpi_is_pnp_device(struct acpi_device *);
 
 typedef void (*wmi_notify_handler) (u32 value, void *context);
 
+acpi_status wmi_instance_count(const char *guid, u8 *instance_count);
+
 extern acpi_status wmi_evaluate_method(const char *guid, u8 instance,
 					u32 method_id,
 					const struct acpi_buffer *in,
include/linux/wmi.h +2 -0
index c1a3bd4e4838..763bd382cf2d 100644
@@ -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);
 
 /**

--
2.30.2

#1 lore raw

[Public]

Quoted 11 lines

-----Original Message-----
From: Armin Wolf <[email protected]>
Sent: Wednesday, April 26, 2023 16:04
To: [email protected]; [email protected]
Cc: Limonciello, Mario <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]
Subject: [RFC] platform/x86: wmi: Allow retrieving the number of WMI object instances

Quoted 7 lines

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.

Makes sense to me. I think that you'll want to also update the dell driver in the same series to use this instead.

Quoted 94 lines
---
 drivers/platform/x86/wmi.c | 40
++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h       |  2 ++
 include/linux/wmi.h        |  2 ++
 3 files changed, 44 insertions(+)
drivers/platform/x86/wmi.c +3 -0
index c226dd4163a1..7c1a904dec5f 100644
@@ -263,6 +263,46 @@ 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
+ * @instance_count: variable to hold the instance count
+ *
+ * Get the number of WMI object instances.
+ *
+ * Returns: acpi_status signaling success or error.
+ */
+acpi_status wmi_instance_count(const char *guid_string, u8 *instance_count)

drivers/platform/x86/wmi.c +25 -0
+{
+	struct wmi_block *wblock;
+	acpi_status status;
+
+	status = find_guid(guid_string, &wblock);
+	if (ACPI_FAILURE(status))
+		return status;
+
+	*instance_count = wmidev_instance_count(&wblock->dev);
+
+	return AE_OK;
+}
+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);

drivers/platform/x86/wmi.c +5 -0
+
+	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

include/linux/acpi.h +2 -0
index efff750f326d..ab2a4b23e7a3 100644
@@ -412,6 +412,8 @@ extern bool acpi_is_pnp_device(struct acpi_device
 *);
 
 typedef void (*wmi_notify_handler) (u32 value, void *context);
 
+acpi_status wmi_instance_count(const char *guid, u8 *instance_count);
+
 extern acpi_status wmi_evaluate_method(const char *guid, u8 instance,
 					u32 method_id,
include/linux/acpi.h +0 -0
 					const struct acpi_buffer *in,
include/linux/wmi.h +2 -0
index c1a3bd4e4838..763bd382cf2d 100644
@@ -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);
 

/**
--
2.30.2