All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/3] platform/x86: firmware_attributes_class: Create helper file for handling firmware-attributes class registration events
@ 2021-05-26 20:14 Mark Pearson
  2021-05-26 20:14 ` [PATCH v4 2/3] platform/x86: dell-wmi-sysman: Use firmware_attributes_class helper Mark Pearson
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Mark Pearson @ 2021-05-26 20:14 UTC (permalink / raw)
  To: markpearson
  Cc: hdegoede, andy.shevchenko, prasanth.ksr, divya.bharathi,
	Dell.Client.Kernel, platform-driver-x86

This will be used by the Dell and Lenovo WMI management drivers to
prevent both drivers being active.

Signed-off-by: Mark Pearson <markpearson@lenovo.com>
---
Changes in v2:
 - This is a new file requested as part of the review of the proposed
think_lmi.c driver. Labeling as V2 to keep series consistent

Changes in v3:
 - Set default in Kconfig, and removed help text
 - Allow multiple modules to register with module. Change API names to
    better reflect this.

Changes in v4:
 - version bump for consistency in series

 drivers/platform/x86/Kconfig                  |  4 ++
 drivers/platform/x86/Makefile                 |  1 +
 .../platform/x86/firmware_attributes_class.c  | 53 +++++++++++++++++++
 .../platform/x86/firmware_attributes_class.h  | 13 +++++
 4 files changed, 71 insertions(+)
 create mode 100644 drivers/platform/x86/firmware_attributes_class.c
 create mode 100644 drivers/platform/x86/firmware_attributes_class.h

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 2714f7c38..57da8352d 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -1076,6 +1076,10 @@ config TOUCHSCREEN_DMI
 	  the OS-image for the device. This option supplies the missing info.
 	  Enable this for x86 tablets with Silead or Chipone touchscreens.
 
+config FW_ATTR_CLASS
+	tristate "Firmware attributes class helper module"
+	default n
+
 config INTEL_IMR
 	bool "Intel Isolated Memory Region support"
 	depends on X86_INTEL_QUARK && IOSF_MBI
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index dcc8cdb95..147573f69 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -115,6 +115,7 @@ obj-$(CONFIG_TOPSTAR_LAPTOP)	+= topstar-laptop.o
 obj-$(CONFIG_I2C_MULTI_INSTANTIATE)	+= i2c-multi-instantiate.o
 obj-$(CONFIG_MLX_PLATFORM)		+= mlx-platform.o
 obj-$(CONFIG_TOUCHSCREEN_DMI)		+= touchscreen_dmi.o
+obj-$(CONFIG_FW_ATTR_CLASS)             += firmware_attributes_class.o
 
 # Intel uncore drivers
 obj-$(CONFIG_INTEL_IPS)				+= intel_ips.o
diff --git a/drivers/platform/x86/firmware_attributes_class.c b/drivers/platform/x86/firmware_attributes_class.c
new file mode 100644
index 000000000..31393ce4d
--- /dev/null
+++ b/drivers/platform/x86/firmware_attributes_class.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/* Firmware attributes class helper module */
+
+#include <linux/mutex.h>
+#include <linux/device/class.h>
+#include <linux/module.h>
+
+static DEFINE_MUTEX(fw_attr_lock);
+int fw_attr_inuse;
+
+static struct class firmware_attributes_class = {
+	.name = "firmware-attributes",
+};
+
+int fw_attributes_class_get(struct class **fw_attr_class)
+{
+	int err;
+
+	mutex_lock(&fw_attr_lock);
+	if (!fw_attr_inuse) { /*first time class is being used*/
+		err = class_register(&firmware_attributes_class);
+		if (err) {
+			mutex_unlock(&fw_attr_lock);
+			return err;
+		}
+	}
+	fw_attr_inuse++;
+	*fw_attr_class = &firmware_attributes_class;
+	mutex_unlock(&fw_attr_lock);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(fw_attributes_class_get);
+
+int fw_attributes_class_put(void)
+{
+	mutex_lock(&fw_attr_lock);
+	if (!fw_attr_inuse) {
+		mutex_unlock(&fw_attr_lock);
+		return -EINVAL;
+	}
+	fw_attr_inuse--;
+	if (!fw_attr_inuse) /* No more consumers */
+		class_unregister(&firmware_attributes_class);
+	mutex_unlock(&fw_attr_lock);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(fw_attributes_class_put);
+
+MODULE_AUTHOR("Mark Pearson <markpearson@lenovo.com>");
+MODULE_LICENSE("GPL");
+
+
diff --git a/drivers/platform/x86/firmware_attributes_class.h b/drivers/platform/x86/firmware_attributes_class.h
new file mode 100644
index 000000000..802f12b45
--- /dev/null
+++ b/drivers/platform/x86/firmware_attributes_class.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/* Firmware attributes class helper module */
+
+#ifndef FW_ATTR_CLASS_H
+#define FW_ATTR_CLASS_H
+
+int fw_attributes_class_get(struct class **fw_attr_class);
+int fw_attributes_class_put(void);
+
+#endif /* FW_ATTR_CLASS_H */
+
+
-- 
2.31.1


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

end of thread, other threads:[~2021-05-28 18:19 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-26 20:14 [PATCH v4 1/3] platform/x86: firmware_attributes_class: Create helper file for handling firmware-attributes class registration events Mark Pearson
2021-05-26 20:14 ` [PATCH v4 2/3] platform/x86: dell-wmi-sysman: Use firmware_attributes_class helper Mark Pearson
2021-05-26 20:14 ` [PATCH v4 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms Mark Pearson
2021-05-27  9:17   ` Hans de Goede
2021-05-27 12:20     ` [External] " Mark Pearson
2021-05-27 14:18     ` Andy Shevchenko
2021-05-27  9:19   ` Hans de Goede
2021-05-27 12:21     ` [External] " Mark Pearson
2021-05-27 14:16   ` Andy Shevchenko
2021-05-27 14:36     ` Hans de Goede
2021-05-27 14:54       ` Andy Shevchenko
2021-05-28 17:36     ` [External] " Mark Pearson
2021-05-28 18:19       ` Andy Shevchenko
2021-05-27  9:12 ` [PATCH v4 1/3] platform/x86: firmware_attributes_class: Create helper file for handling firmware-attributes class registration events Hans de Goede
2021-05-27 12:24   ` [External] " Mark Pearson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.