X86 platform drivers
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Mark Pearson <markpearson@lenovo.com>
Cc: mgross@linux.intel.com, platform-driver-x86@vger.kernel.org,
	divya.bharathi@dell.com, prasanth.ksr@dell.com,
	mario.limonciello@dell.com
Subject: Re: [PATCH v2 1/3] platform/x86: firmware_attributes_class: Create helper file for handling firmware-attributes class registration events
Date: Wed, 19 May 2021 18:15:48 +0200	[thread overview]
Message-ID: <5eafa0be-e44c-e8fd-a9ea-db5e30c47788@redhat.com> (raw)
In-Reply-To: <20210509015708.112766-1-markpearson@lenovo.com>

Hi Mark,

On 5/9/21 3:57 AM, Mark Pearson wrote:
> 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 (hope
> that's correct).

Yes that is correct; and thank you for taking care of making
the code for registering the firmware_attribute class shared.

> 
>  drivers/platform/x86/Kconfig                  |  6 +++
>  drivers/platform/x86/Makefile                 |  1 +
>  .../platform/x86/firmware_attributes_class.c  | 51 +++++++++++++++++++
>  .../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..b0e1e5f65 100644
> --- a/drivers/platform/x86/Kconfig
> +++ b/drivers/platform/x86/Kconfig
> @@ -1076,6 +1076,12 @@ 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"> +	help
> +	  This option should be enabled by any modules using the firmware
> +	  attributes class.

My idea here was to have this be a kernel-library which drivers which need it
select. In this case it should not be visible to end-users and does not need a
help text, so this should look like this:

config FW_ATTR_CLASS
	tristate
	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..4ed959d6c
> --- /dev/null
> +++ b/drivers/platform/x86/firmware_attributes_class.c
> @@ -0,0 +1,51 @@
> +// 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);
> +bool fw_attr_inuse;
> +
> +static struct class firmware_attributes_class = {
> +	.name = "firmware-attributes",
> +};
> +
> +int fw_attributes_class_register(struct class **fw_attr_class)
> +{
> +	int err;
> +
> +	mutex_lock(&fw_attr_lock);
> +	/* We can only have one active FW attribute class */
> +	if (fw_attr_inuse) {
> +		mutex_unlock(&fw_attr_lock);
> +		return -EEXIST;
> +	}

I think it should be allowed to have multiple drivers
using the firmware_attributes class, e.g. besides the main system
BIOS an Ethermet or FiberChannel; card with an option ROM which supports
booting from iSCSI/FCoE or FiberChannel SCSI disks / LUNs could expose
settings to configure which disk/LUN to boot from this way.

And there is nothing wrong with multiple drivers calling device_create
with the same class.

So I suggest renaming fw_attributes_class_register to
fw_attributes_class_get (and unregister to put) and to make
fw_attr_inuse a counter and create the class when the counter
goes from 0 -> 1 and free it when it goes from 1 to 0 again.

Otherwise this looks good. I like that you already thought about
races and have protected fw_attr_inuse with a mutex.

Regards,

Hans






> +
> +	err = class_register(&firmware_attributes_class);
> +	if (err) {
> +		mutex_unlock(&fw_attr_lock);
> +		return err;
> +	}
> +	fw_attr_inuse = true;
> +	*fw_attr_class = &firmware_attributes_class;
> +	mutex_unlock(&fw_attr_lock);
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(fw_attributes_class_register);
> +
> +void fw_attributes_class_remove(void)
> +{
> +	mutex_lock(&fw_attr_lock);
> +	fw_attr_inuse = false;
> +	class_unregister(&firmware_attributes_class);
> +	mutex_unlock(&fw_attr_lock);
> +}
> +EXPORT_SYMBOL_GPL(fw_attributes_class_remove);
> +
> +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..e479a5720
> --- /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_register(struct class **fw_attr_class);
> +void fw_attributes_class_remove(void);
> +
> +#endif /* FW_ATTR_CLASS_H */
> +
> +
> 


  parent reply	other threads:[~2021-05-19 16:15 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-09  1:57 [PATCH v2 1/3] platform/x86: firmware_attributes_class: Create helper file for handling firmware-attributes class registration events Mark Pearson
2021-05-09  1:57 ` [PATCH v2 2/3] platform/x86: dell-wmi-sysman: Use firmware_attributes_class helper Mark Pearson
2021-05-19 16:17   ` Hans de Goede
2021-05-09  1:57 ` [PATCH v2 3/3] platform/x86: think-lmi: Add WMI interface support on Lenovo platforms Mark Pearson
2021-05-19 17:06   ` Hans de Goede
2021-05-20 17:18     ` [External] " Mark Pearson
2021-05-21  8:10       ` Hans de Goede
2021-05-21  9:37         ` Hans de Goede
2021-05-21 15:55         ` Mark Pearson
2021-05-21 16:55           ` Hans de Goede
2021-05-21 19:00             ` Mark Pearson
2021-05-24 10:19             ` Ksr, Prasanth
2021-05-24 15:27               ` Hans de Goede
2021-05-25 14:02                 ` Mark Pearson
2021-05-22 11:04   ` Andy Shevchenko
2021-05-25 15:14     ` [External] " Mark Pearson
2021-05-25 16:18       ` Andy Shevchenko
2021-05-25 16:50         ` Mark Pearson
2021-05-25 16:29       ` Hans de Goede
2021-05-25 16:52         ` Mark Pearson
2021-05-19 16:15 ` Hans de Goede [this message]
2021-05-19 16:45   ` [External] Re: [PATCH v2 1/3] platform/x86: firmware_attributes_class: Create helper file for handling firmware-attributes class registration events Mark Pearson
2021-05-19 16:19 ` Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5eafa0be-e44c-e8fd-a9ea-db5e30c47788@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=divya.bharathi@dell.com \
    --cc=mario.limonciello@dell.com \
    --cc=markpearson@lenovo.com \
    --cc=mgross@linux.intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=prasanth.ksr@dell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox