Skip to contentSkip to conversation

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

PATCH In review Armin Wolf 2 participants 7 messages Apr 30, 2023 – May 9, 2023

Subsystems (3)
lore
Share & tools
lore

Armin Wolf

author
#0 lore raw

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

This patch series allows WMI drivers to retrieve the number of WMI object instances. This functionality benefits several current and upcoming WMI drivers, the dell-wmi-sysman driver is converted to use this new API as an example.

The changes are compile-tested only, the change to the dell-wmi-sysman driver also needs to be tested on real hardware.

Changes since RFC v2:
- modify wmi_instance_count() to return an integer

Armin Wolf (2):
platform/x86: wmi: Allow retrieving the number of WMI object instances platform/x86: dell-sysman: Improve instance detection

 .../x86/dell/dell-wmi-sysman/sysman.c         | 13 +++---
 drivers/platform/x86/wmi.c                    | 41 +++++++++++++++++++
 include/linux/acpi.h                          |  2 +
 include/linux/wmi.h                           |  2 +
 4 files changed, 50 insertions(+), 8 deletions(-)

--
2.30.2

author
#1 lore raw

PATCH 1/2 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 | 41 ++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h       |  2 ++
 include/linux/wmi.h        |  2 ++
 3 files changed, 45 insertions(+)
drivers/platform/x86/wmi.c +41 -0
index c226dd4163a1..5b95d7aa5c2f 100644
@@ -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
include/linux/acpi.h +2 -0
index efff750f326d..e52bf2742eaf 100644
@@ -412,6 +412,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,
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

#2 lore raw

Re: [PATCH 1/2] platform/x86: wmi: Allow retrieving the number of WMI object instances

Hi Armin,

Quoted 8 lines · Armin Wolf

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.

Thank you for your work on this.

Quoted 23 lines
---
 drivers/platform/x86/wmi.c | 41 ++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h       |  2 ++
 include/linux/wmi.h        |  2 ++
 3 files changed, 45 insertions(+)
drivers/platform/x86/wmi.c +9 -0
index c226dd4163a1..5b95d7aa5c2f 100644
@@ -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)

drivers/platform/x86/wmi.c int set_required_buffer_size(struct wmi_device *wdev, u64 length) · line 284

Quoted 10 lines
drivers/platform/x86/wmi.c +10 -0
+{
+	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;

Maybe just return 0 here ?

The GUID not existing at all does not seem like an error to me, but rather a case of there being 0 instances.

This will also allow patch 2/2 to completely drop the get_instance_count() function and replace its callers with direct calls to wmi_instance_count() as the code is known to always pass a valid GUID, so it won't hit the -EINVAL path.

Regards,

Hans

Quoted 54 lines
drivers/platform/x86/wmi.c +22 -0
+	}
+
+	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
include/linux/acpi.h +2 -0
index efff750f326d..e52bf2742eaf 100644
@@ -412,6 +412,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,
include/linux/wmi.h +2 -1
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

author
#3 lore raw

Re: [PATCH 1/2] platform/x86: wmi: Allow retrieving the number of WMI object instances

Am 30.04.23 um 22:41 schrieb Hans de Goede:

Quoted 59 lines

Hi Armin,

Quoted 8 lines · Armin Wolf

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.

Thank you for your work on this.

Quoted 23 lines
---
  drivers/platform/x86/wmi.c | 41 ++++++++++++++++++++++++++++++++++++++
  include/linux/acpi.h       |  2 ++
  include/linux/wmi.h        |  2 ++
  3 files changed, 45 insertions(+)
drivers/platform/x86/wmi.c +9 -0
index c226dd4163a1..5b95d7aa5c2f 100644
@@ -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)

drivers/platform/x86/wmi.c int set_required_buffer_size(struct wmi_device *wdev, u64 length) · line 284

Quoted 10 lines
drivers/platform/x86/wmi.c +10 -0
+{
+	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;

Maybe just return 0 here ?

The GUID not existing at all does not seem like an error to me, but rather a case of there being 0 instances.

This will also allow patch 2/2 to completely drop the get_instance_count() function and replace its callers with direct calls to wmi_instance_count() as the code is known to always pass a valid GUID, so it won't hit the -EINVAL path.

Quoted 4 lines

Regards,

Hans

Hi,

i would prefer returning -ENODEV instead of 0, so WMI drivers can distinguish between "not found" and "zero instances". Also i do not think that relying on the parameter of get_instance_count() always being a valid GUID is a good idea, just in case wmi_instance_count() is later modified to be able to encounter runtime errors.

Armin Wolf

Quoted 55 lines
Quoted 55 lines
drivers/platform/x86/wmi.c +22 -0
+	}
+
+	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
include/linux/acpi.h +2 -0
index efff750f326d..e52bf2742eaf 100644
@@ -412,6 +412,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,
include/linux/wmi.h +2 -1
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

#4 lore raw

Re: [PATCH 1/2] platform/x86: wmi: Allow retrieving the number of WMI object instances

Hi,

Quoted 61 lines · Armin Wolf

Am 30.04.23 um 22:41 schrieb Hans de Goede:

Quoted 59 lines

Hi Armin,

Quoted 8 lines · Armin Wolf

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.

Thank you for your work on this.

Quoted 23 lines

---
  drivers/platform/x86/wmi.c | 41 ++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h       |  2 ++
  include/linux/wmi.h        |  2 ++

  3 files changed, 45 insertions(+)
drivers/platform/x86/wmi.c +9 -0
index c226dd4163a1..5b95d7aa5c2f 100644
@@ -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)

drivers/platform/x86/wmi.c int set_required_buffer_size(struct wmi_device *wdev, u64 length) · line 284

Quoted 10 lines
drivers/platform/x86/wmi.c +10 -0
+{
+    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;

Maybe just return 0 here ?

The GUID not existing at all does not seem like an error to me, but rather a case of there being 0 instances.

This will also allow patch 2/2 to completely drop the get_instance_count() function and replace its callers with direct calls to wmi_instance_count() as the code is known to always pass a valid GUID, so it won't hit the -EINVAL path.

Quoted 8 lines
Quoted 4 lines

Regards,

Hans

Hi,

i would prefer returning -ENODEV instead of 0, so WMI drivers can distinguish between "not found" and "zero instances".

Ah right, that is a good point, ok lets keep this as is then.

Regards,

Hans

Quoted 63 lines

Also i do not
think that relying on the parameter of get_instance_count() always being a valid GUID is a good idea, just in case wmi_instance_count() is later modified to be able to encounter runtime errors.

Armin Wolf

Quoted 55 lines
Quoted 55 lines
drivers/platform/x86/wmi.c +22 -0
+    }
+
+    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
include/linux/acpi.h +2 -0
index efff750f326d..e52bf2742eaf 100644
@@ -412,6 +412,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,
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);
 
   /**
Signature · 1 line
2.30.2
author
#5 lore raw

PATCH 2/2 platform/x86: dell-sysman: Improve instance detection

In reply to Armin Wolf

The WMI driver core already knows how many WMI object instances are available, use this information instead of probing the WMI object manually.

Compile-tested only.

---
 drivers/platform/x86/dell/dell-wmi-sysman/sysman.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +5 -8
index 0285b47d99d1..b68dd11cb892 100644
@@ -303,16 +303,13 @@ union acpi_object *get_wmiobj_pointer(int instance_id, const char *guid_string)
  */
 int get_instance_count(const char *guid_string)
 {
-	union acpi_object *wmi_obj = NULL;
-	int i = 0;
+	int ret;
 
-	do {
-		kfree(wmi_obj);
-		wmi_obj = get_wmiobj_pointer(i, guid_string);
-		i++;
-	} while (wmi_obj);
+	ret = wmi_instance_count(guid_string);
+	if (ret < 0)
+		return 0;
 
-	return (i-1);
+	return ret;
 }
 
 /**

--
2.30.2

#6 lore raw
In reply to Armin Wolf

Hi,

Quoted 10 lines · Armin Wolf

This patch series allows WMI drivers to retrieve the number of WMI object instances. This functionality benefits several current and upcoming WMI drivers, the dell-wmi-sysman driver is converted to use this new API as an example.

The changes are compile-tested only, the change to the dell-wmi-sysman driver also needs to be tested on real hardware.

Changes since RFC v2:
- modify wmi_instance_count() to return an integer

Thank you for your patch-series, I've applied the series to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.

Regards,

Hans

Quoted 13 lines

Armin Wolf (2):
platform/x86: wmi: Allow retrieving the number of WMI object instances platform/x86: dell-sysman: Improve instance detection

 .../x86/dell/dell-wmi-sysman/sysman.c         | 13 +++---
 drivers/platform/x86/wmi.c                    | 41 +++++++++++++++++++
 include/linux/acpi.h                          |  2 +
 include/linux/wmi.h                           |  2 +
 4 files changed, 50 insertions(+), 8 deletions(-)

--
2.30.2