platform/x86: Allow retrieving the number of WMI object instances
Subsystems (3)
v2 cover platform/x86: Allow retrieving the number of WMI object instances
This experimental patch series allows WMI drivers to retrieve the number of WMI object instances. This functionallity 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.
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 | 15 ++++--- drivers/platform/x86/wmi.c | 40 +++++++++++++++++++ include/linux/acpi.h | 2 + include/linux/wmi.h | 2 + 4 files changed, 51 insertions(+), 8 deletions(-)
--
2.30.2
RFC v2 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 | 40 ++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 2 ++ include/linux/wmi.h | 2 ++ 3 files changed, 44 insertions(+)
drivers/platform/x86/wmi.c +40 -0
@@ -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
@@ -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
@@ -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
Re: [RFC v2 1/2] platform/x86: wmi: Allow retrieving the number of WMI object instances
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()andwmidev_instance_count()to allow WMI drivers to get the number of WMI object instances.Signed-off-by Armin Wolf <[email protected]>
Re: [RFC v2 1/2] platform/x86: wmi: Allow retrieving the number of WMI object instances
In reply to Armin WolfHi Armin,
Thank you for your work on this.
Quoted 35 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()andwmidev_instance_count()to allow WMI drivers to get the number of WMI object instances.Signed-off-by Armin Wolf <[email protected]>--- 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 +13
-0@@ -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;
drivers/platform/x86/wmi.c int set_required_buffer_size(struct wmi_device *wdev, u64 length) · line 288
Quoted 10 lines
drivers/platform/x86/wmi.c +10
-0+ + 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);
I would prefer this to have a normal kernel function prototype which returns -errno rather then returning an acpi_status. E.g. :
/**
* 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: The number of WMI object instances, 0 if the GUID is not found. */
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))
return 0;
return wmidev_instance_count(&wblock->dev);
}EXPORT_SYMBOL_GPL(wmi_instance_count);
This will also allow this to completely replace the get_instance_count() function in dell-wmi-sysman.
Note I have just gone with always returning 0 here on error. I guess you could look at the status and return 0 for not-found and -errno for other errors but I don't think any callers will care for the difference, so just always returning 0 seems easier for callers to deal with.
As always this is just a suggestion, let me know if you think this is a bad idea.
Regards,
Hans
Quoted 49 lines
drivers/platform/x86/wmi.c +17
-0+ +/** +* 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@@ -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
-1@@ -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
Re: [RFC v2 1/2] platform/x86: wmi: Allow retrieving the number of WMI object instances
Am 27.04.23 um 11:43 schrieb Hans de Goede:
Quoted 84 lines
Hi Armin,
Thank you for your work on this.
Quoted 35 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()andwmidev_instance_count()to allow WMI drivers to get the number of WMI object instances.Signed-off-by Armin Wolf <[email protected]>--- 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 +13
-0@@ -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;drivers/platform/x86/wmi.c int set_required_buffer_size(struct wmi_device *wdev, u64 length) · line 288
Quoted 10 lines
drivers/platform/x86/wmi.c +10
-0+ + 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);I would prefer this to have a normal kernel function prototype which returns -errno rather then returning an
acpi_status. E.g. :/**
*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: The number of WMI object instances, 0 if the GUID is not found. */
intwmi_instance_count(const char *guid_string){ struct wmi_block *wblock; acpi_status status; status = find_guid(guid_string, &wblock); if (ACPI_FAILURE(status)) return 0; return wmidev_instance_count(&wblock->dev); }
EXPORT_SYMBOL_GPL(wmi_instance_count);This will also allow this to completely replace the
get_instance_count()function in dell-wmi-sysman.Note I have just gone with always returning 0 here on error. I guess you could look at the status and return 0 for not-found and -errno for other errors but I don't think any callers will care for the difference, so just always returning 0 seems easier for callers to deal with.
Quoted 7 lines
As always this is just a suggestion, let me know if you think this is a bad idea.
Regards,
Hans
I like this idea. Returning a negative errno on error would allow drivers to distinguish between "WMI object not found" and "zero instances found", which might be useful for some drivers.
Maybe a function for converting ACPI errors to POSIX errors already exists, otherwise i will just write one myself.
Armin Wolf
Quoted 50 lines
Quoted 50 lines
drivers/platform/x86/wmi.c +17
-0+ +/** +* 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@@ -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
-1@@ -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
Re: [RFC v2 1/2] platform/x86: wmi: Allow retrieving the number of WMI object instances
Hi,
Quoted 91 lines · Armin Wolf
Am 27.04.23 um 11:43 schrieb Hans de Goede:
Quoted 89 lines
Hi Armin,
Thank you for your work on this.
Quoted 35 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()andwmidev_instance_count()to allow WMI drivers to get the number of WMI object instances.Signed-off-by Armin Wolf <[email protected]>---
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 +13
-0@@ -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;drivers/platform/x86/wmi.c int set_required_buffer_size(struct wmi_device *wdev, u64 length) · line 288
Quoted 10 lines
drivers/platform/x86/wmi.c +10
-0+ + 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);I would prefer this to have a normal kernel function prototype which returns -errno rather then returning an
acpi_status. E.g. :/**
*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: The number of WMI object instances, 0 if the GUID is not found. */
intwmi_instance_count(const char *guid_string)
{
structwmi_block*wblock;
acpi_status status;status =
find_guid(guid_string, &wblock);
if (ACPI_FAILURE(status))
return 0;return
wmidev_instance_count(&wblock->dev);
}EXPORT_SYMBOL_GPL(wmi_instance_count);This will also allow this to completely replace the
get_instance_count()function in dell-wmi-sysman.Note I have just gone with always returning 0 here on error. I guess you could look at the status and return 0 for not-found and -errno for other errors but I don't think any callers will care for the difference, so just always returning 0 seems easier for callers to deal with.
As always this is just a suggestion, let me know if you think this is a bad idea.
Regards,
Quoted 8 lines
Quoted 2 lines
Hans
I like this idea. Returning a negative errno on error would allow drivers to distinguish between "WMI object not found" and "zero instances found", which might be useful for some drivers.
Maybe a function for converting ACPI errors to POSIX errors already exists, otherwise i will just write one myself.
Ok, that sounds good to me. I'm looking forward to a non RFC submission of these changes.
Regards,
Hans
RFC v2 2/2 platform/x86: dell-sysman: Improve instance detection
In reply to Armin WolfThe 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.
--- .../platform/x86/dell/dell-wmi-sysman/sysman.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/platform/x86/dell/dell-wmi-sysman/sysman.c +7 -8
@@ -7,6 +7,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/acpi.h> #include <linux/fs.h> #include <linux/dmi.h> #include <linux/module.h>
@@ -303,16 +304,14 @@ 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 ; +acpi_status status; +u8 instance_count; -do { -kfree (wmi_obj); - wmi_obj =get_wmiobj_pointer (i, guid_string); - i++; - }while (wmi_obj); + status =wmi_instance_count (guid_string, &instance_count); +if (ACPI_FAILURE (status)) +return 0 ; -return (i-1 ); +return instance_count; }/**
--
2.30.2