mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] platform/x86: wmi: Add driver_override support
@ 2024-06-24 17:31 Armin Wolf
  2024-06-24 17:31 ` [PATCH v2 1/2] " Armin Wolf
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Armin Wolf @ 2024-06-24 17:31 UTC (permalink / raw)
  To: hdegoede, ilpo.jarvinen
  Cc: corbet, platform-driver-x86, linux-doc, linux-kernel

This patch series add support for using the driver_override sysfs
attribute with WMI devices. The reason for this is that there will
exist a couple of generic WMI drivers in the future for allowing
driver developers to directly access the underlying WMI device.

Since those generic WMI drivers do not have an ID table, the
driver_override mechanism is used to bind them to WMI devices.

Changes since v1:
- Add Reviewed-by tags
- Add line breaks and implement requested changes in the documentation
  of the driver_override attr

Armin Wolf (2):
  platform/x86: wmi: Add driver_override support
  platform/x86: wmi: Add bus ABI documentation

 Documentation/ABI/testing/sysfs-bus-wmi | 81 +++++++++++++++++++++++++
 MAINTAINERS                             |  1 +
 drivers/platform/x86/wmi.c              | 33 ++++++++++
 include/linux/wmi.h                     |  4 ++
 4 files changed, 119 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-wmi

--
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] platform/x86: wmi: Add driver_override support
  2024-06-24 17:31 [PATCH v2 0/2] platform/x86: wmi: Add driver_override support Armin Wolf
@ 2024-06-24 17:31 ` Armin Wolf
  2024-06-24 17:31 ` [PATCH v2 2/2] platform/x86: wmi: Add bus ABI documentation Armin Wolf
  2024-06-24 17:40 ` [PATCH v2 0/2] platform/x86: wmi: Add driver_override support Ilpo Järvinen
  2 siblings, 0 replies; 4+ messages in thread
From: Armin Wolf @ 2024-06-24 17:31 UTC (permalink / raw)
  To: hdegoede, ilpo.jarvinen
  Cc: corbet, platform-driver-x86, linux-doc, linux-kernel

Add support for forcing the WMI driver core to bind
a certain WMI driver to a WMI device. This will be
necessary to support generic WMI drivers without an
ID table

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/platform/x86/wmi.c | 33 +++++++++++++++++++++++++++++++++
 include/linux/wmi.h        |  4 ++++
 2 files changed, 37 insertions(+)

diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index d21f3fa25823..6bfae28b962a 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -772,11 +772,39 @@ static ssize_t expensive_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(expensive);

+static ssize_t driver_override_show(struct device *dev, struct device_attribute *attr,
+				    char *buf)
+{
+	struct wmi_device *wdev = to_wmi_device(dev);
+	ssize_t ret;
+
+	device_lock(dev);
+	ret = sysfs_emit(buf, "%s\n", wdev->driver_override);
+	device_unlock(dev);
+
+	return ret;
+}
+
+static ssize_t driver_override_store(struct device *dev, struct device_attribute *attr,
+				     const char *buf, size_t count)
+{
+	struct wmi_device *wdev = to_wmi_device(dev);
+	int ret;
+
+	ret = driver_set_override(dev, &wdev->driver_override, buf, count);
+	if (ret < 0)
+		return ret;
+
+	return count;
+}
+static DEVICE_ATTR_RW(driver_override);
+
 static struct attribute *wmi_attrs[] = {
 	&dev_attr_modalias.attr,
 	&dev_attr_guid.attr,
 	&dev_attr_instance_count.attr,
 	&dev_attr_expensive.attr,
+	&dev_attr_driver_override.attr,
 	NULL
 };
 ATTRIBUTE_GROUPS(wmi);
@@ -845,6 +873,7 @@ static void wmi_dev_release(struct device *dev)
 {
 	struct wmi_block *wblock = dev_to_wblock(dev);

+	kfree(wblock->dev.driver_override);
 	kfree(wblock);
 }

@@ -854,6 +883,10 @@ static int wmi_dev_match(struct device *dev, struct device_driver *driver)
 	struct wmi_block *wblock = dev_to_wblock(dev);
 	const struct wmi_device_id *id = wmi_driver->id_table;

+	/* When driver_override is set, only bind to the matching driver */
+	if (wblock->dev.driver_override)
+		return !strcmp(wblock->dev.driver_override, driver->name);
+
 	if (id == NULL)
 		return 0;

diff --git a/include/linux/wmi.h b/include/linux/wmi.h
index 63cca3b58d6d..3275470b5531 100644
--- a/include/linux/wmi.h
+++ b/include/linux/wmi.h
@@ -16,12 +16,16 @@
  * struct wmi_device - WMI device structure
  * @dev: Device associated with this WMI device
  * @setable: True for devices implementing the Set Control Method
+ * @driver_override: Driver name to force a match; do not set directly,
+ *		     because core frees it; use driver_set_override() to
+ *		     set or clear it.
  *
  * This represents WMI devices discovered by the WMI driver core.
  */
 struct wmi_device {
 	struct device dev;
 	bool setable;
+	const char *driver_override;
 };

 /**
--
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] platform/x86: wmi: Add bus ABI documentation
  2024-06-24 17:31 [PATCH v2 0/2] platform/x86: wmi: Add driver_override support Armin Wolf
  2024-06-24 17:31 ` [PATCH v2 1/2] " Armin Wolf
@ 2024-06-24 17:31 ` Armin Wolf
  2024-06-24 17:40 ` [PATCH v2 0/2] platform/x86: wmi: Add driver_override support Ilpo Järvinen
  2 siblings, 0 replies; 4+ messages in thread
From: Armin Wolf @ 2024-06-24 17:31 UTC (permalink / raw)
  To: hdegoede, ilpo.jarvinen
  Cc: corbet, platform-driver-x86, linux-doc, linux-kernel

Add documentation for the WMI bus sysfs interface so userspace
applications can use it to access additional data about WMI devices.

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 Documentation/ABI/testing/sysfs-bus-wmi | 81 +++++++++++++++++++++++++
 MAINTAINERS                             |  1 +
 2 files changed, 82 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-wmi

diff --git a/Documentation/ABI/testing/sysfs-bus-wmi b/Documentation/ABI/testing/sysfs-bus-wmi
new file mode 100644
index 000000000000..aadb35b82198
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-wmi
@@ -0,0 +1,81 @@
+What:		/sys/bus/wmi/devices/.../driver_override
+Date:		February 2024
+Contact:	Armin Wolf <W_Armin@gmx.de>
+Description:
+		This file allows the driver for a device to be specified which
+		will override standard ID table matching.
+		When specified, only a driver with a name matching the value
+		written to driver_override will have an opportunity to bind
+		to the device.
+		The override is specified by writing a string to the
+		driver_override file (echo wmi-event-dummy > driver_override).
+		The override may be cleared with an empty string (echo > \
+		driver_override) which returns the device to standard matching
+		rules binding.
+		Writing to driver_override does not automatically unbind the
+		device from its current driver or make any attempt to automatically
+		load the specified driver. If no driver with a matching name is
+		currently loaded in the kernel, the device will not bind to any
+		driver.
+		This also allows devices to opt-out of driver binding using a
+		driver_override name such as "none". Only a single driver may be
+		specified in the override, there is no support for parsing delimiters.
+
+What:		/sys/bus/wmi/devices/.../modalias
+Date:		November 20:15
+Contact:	Andy Lutomirski <luto@kernel.org>
+Description:
+		This file contains the MODALIAS value emitted by uevent for a
+		given WMI device.
+
+		Format: wmi:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.
+
+What:		/sys/bus/wmi/devices/.../guid
+Date:		November 2015
+Contact:	Andy Lutomirski <luto@kernel.org>
+Description:
+		This file contains the GUID used to match WMI devices to
+		compatible WMI drivers. This GUID is not necessarily unique
+		inside a given machine, it is solely used to identify the
+		interface exposed by a given WMI device.
+
+What:		/sys/bus/wmi/devices/.../object_id
+Date:		November 2015
+Contact:	Andy Lutomirski <luto@kernel.org>
+Description:
+		This file contains the WMI object ID used internally to construct
+		the ACPI method names used by non-event WMI devices. It contains
+		two ASCII letters.
+
+What:		/sys/bus/wmi/devices/.../notify_id
+Date:		November 2015
+Contact:	Andy Lutomirski <luto@kernel.org>
+Description:
+		This file contains the WMI notify ID used internally to map ACPI
+		events to WMI event devices. It contains two ASCII letters.
+
+What:		/sys/bus/wmi/devices/.../instance_count
+Date:		November 2015
+Contact:	Andy Lutomirski <luto@kernel.org>
+Description:
+		This file contains the number of WMI object instances being
+		present on a given WMI device. It contains a non-negative
+		number.
+
+What:		/sys/bus/wmi/devices/.../expensive
+Date:		November 2015
+Contact:	Andy Lutomirski <luto@kernel.org>
+Description:
+		This file contains a boolean flag signaling if interacting with
+		the given WMI device will consume significant CPU resources.
+		The WMI driver core will take care of enabling/disabling such
+		WMI devices.
+
+What:		/sys/bus/wmi/devices/.../setable
+Date:		May 2017
+Contact:	Darren Hart (VMware) <dvhart@infradead.org>
+Description:
+		This file contains a boolean flags signaling the data block
+		aassociated with the given WMI device is writable. If the
+		given WMI device is not associated with a data block, then
+		this file will not exist.
diff --git a/MAINTAINERS b/MAINTAINERS
index 09ff0dfd65cb..4f76d6a5d348 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -392,6 +392,7 @@ ACPI WMI DRIVER
 M:	Armin Wolf <W_Armin@gmx.de>
 L:	platform-driver-x86@vger.kernel.org
 S:	Maintained
+F:	Documentation/ABI/testing/sysfs-bus-wmi
 F:	Documentation/driver-api/wmi.rst
 F:	Documentation/wmi/
 F:	drivers/platform/x86/wmi.c
--
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] platform/x86: wmi: Add driver_override support
  2024-06-24 17:31 [PATCH v2 0/2] platform/x86: wmi: Add driver_override support Armin Wolf
  2024-06-24 17:31 ` [PATCH v2 1/2] " Armin Wolf
  2024-06-24 17:31 ` [PATCH v2 2/2] platform/x86: wmi: Add bus ABI documentation Armin Wolf
@ 2024-06-24 17:40 ` Ilpo Järvinen
  2 siblings, 0 replies; 4+ messages in thread
From: Ilpo Järvinen @ 2024-06-24 17:40 UTC (permalink / raw)
  To: hdegoede, Armin Wolf; +Cc: corbet, platform-driver-x86, linux-doc, linux-kernel

On Mon, 24 Jun 2024 19:31:14 +0200, Armin Wolf wrote:

> This patch series add support for using the driver_override sysfs
> attribute with WMI devices. The reason for this is that there will
> exist a couple of generic WMI drivers in the future for allowing
> driver developers to directly access the underlying WMI device.
> 
> Since those generic WMI drivers do not have an ID table, the
> driver_override mechanism is used to bind them to WMI devices.
> 
> [...]


Thank you for your contribution, it has been applied to my local
review-ilpo branch. Note it will show up in the public
platform-drivers-x86/review-ilpo branch only once I've pushed my
local branch there, which might take a while.

The list of commits applied:
[1/2] platform/x86: wmi: Add driver_override support
      commit: 12046f8c77e0ed6d41beabde0edbb729499c970b
[2/2] platform/x86: wmi: Add bus ABI documentation
      commit: 618ba6abfc57bde2c2cea7c2b23e4c27fd5a04b4

--
 i.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-24 17:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-24 17:31 [PATCH v2 0/2] platform/x86: wmi: Add driver_override support Armin Wolf
2024-06-24 17:31 ` [PATCH v2 1/2] " Armin Wolf
2024-06-24 17:31 ` [PATCH v2 2/2] platform/x86: wmi: Add bus ABI documentation Armin Wolf
2024-06-24 17:40 ` [PATCH v2 0/2] platform/x86: wmi: Add driver_override support Ilpo Järvinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®