From: "Pali Rohár" <pali.rohar@gmail.com>
To: Andy Lutomirski <luto@kernel.org>
Cc: Darren Hart <dvhart@infradead.org>, platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH 3/3] platform/wmi: Expose the raw WDG data in sysfs
Date: Tue, 1 Aug 2017 17:46:13 +0200 [thread overview]
Message-ID: <20170801154613.GC25574@pali> (raw)
In-Reply-To: <e6df9d038af0a0ce4d4119395aaea58366ade26d.1501601667.git.luto@kernel.org>
On Tuesday 01 August 2017 08:37:28 Andy Lutomirski wrote:
> This adds a sysfs binary attribute 'wdg' on the bus device
> (i.e. /sys/class/wmi_bus/wmi_bus-*/wdg) that contains the raw _WDG
> data from ACPI. This can be used along with the wmi-bmof driver to
> decode the raw interface data from ACPI.
>
> There is very little new information here, as most of the contents
> were already exposed in sysfs attributes on the wmi devices.
>
> Signed-off-by: Andy Lutomirski <luto@kernel.org>
> ---
> drivers/platform/x86/wmi.c | 63 ++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 61 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
> index 1a764e311e11..37ca56aa6025 100644
> --- a/drivers/platform/x86/wmi.c
> +++ b/drivers/platform/x86/wmi.c
> @@ -76,6 +76,11 @@ struct wmi_block {
> bool read_takes_no_args;
> };
>
> +struct wmi_bus_priv {
> + union acpi_object *wdg_obj;
> + struct bin_attribute wdg_bin_attr;
> + bool wdg_bin_attr_created;
> +};
>
> /*
> * If the GUID data block is marked as expensive, we must enable and
> @@ -938,6 +943,7 @@ static bool guid_already_parsed(struct acpi_device *device,
> */
> static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
> {
> + struct wmi_bus_priv *priv = dev_get_drvdata(wmi_bus_dev);
> struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
> const struct guid_block *gblock;
> struct wmi_block *wblock, *next;
> @@ -1017,11 +1023,35 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
> }
> }
>
> + priv->wdg_obj = obj;
> + return 0;
> +
> out_free_pointer:
> kfree(out.pointer);
> return retval;
> }
>
> +static ssize_t
> +read_wdg(struct file *filp, struct kobject *kobj,
> + struct bin_attribute *attr,
> + char *buf, loff_t off, size_t count)
> +{
> + struct wmi_bus_priv *priv =
> + container_of(attr, struct wmi_bus_priv, wdg_bin_attr);
> +
> + if (off < 0)
> + return -EINVAL;
> +
> + if (off >= priv->wdg_obj->buffer.length)
> + return 0;
> +
> + if (count > priv->wdg_obj->buffer.length - off)
> + count = priv->wdg_obj->buffer.length - off;
> +
> + memcpy(buf, priv->wdg_obj->buffer.pointer + off, count);
> + return count;
> +}
> +
> /*
> * WMI can have EmbeddedControl access regions. In which case, we just want to
> * hand these off to the EC driver.
> @@ -1138,6 +1168,8 @@ static void acpi_wmi_notify_handler(acpi_handle handle, u32 event,
>
> static int acpi_wmi_remove(struct platform_device *device)
> {
> + struct device *wmi_bus_dev = dev_get_drvdata(&device->dev);
> + struct wmi_bus_priv *priv = dev_get_drvdata(wmi_bus_dev);
> struct acpi_device *acpi_device = ACPI_COMPANION(&device->dev);
>
> acpi_remove_notify_handler(acpi_device->handle, ACPI_DEVICE_NOTIFY,
> @@ -1145,7 +1177,13 @@ static int acpi_wmi_remove(struct platform_device *device)
> acpi_remove_address_space_handler(acpi_device->handle,
> ACPI_ADR_SPACE_EC, &acpi_wmi_ec_space_handler);
> wmi_free_devices(acpi_device);
> - device_unregister((struct device *)dev_get_drvdata(&device->dev));
> +
> + if (priv->wdg_bin_attr_created)
> + sysfs_remove_bin_file(&wmi_bus_dev->kobj,
> + &priv->wdg_bin_attr);
> + kfree(priv->wdg_obj);
> + kfree(priv);
> + device_unregister(wmi_bus_dev);
>
> return 0;
> }
> @@ -1154,6 +1192,7 @@ static int acpi_wmi_probe(struct platform_device *device)
> {
> struct acpi_device *acpi_device;
> struct device *wmi_bus_dev;
> + struct wmi_bus_priv *priv;
> acpi_status status;
> int error;
>
> @@ -1190,14 +1229,34 @@ static int acpi_wmi_probe(struct platform_device *device)
> }
> dev_set_drvdata(&device->dev, wmi_bus_dev);
>
> + priv = kzalloc(sizeof(struct wmi_bus_priv), GFP_KERNEL);
> + if (!priv) {
> + error = -ENOMEM;
> + goto err_remove_busdev;
> + }
> + dev_set_drvdata(wmi_bus_dev, priv);
> +
> error = parse_wdg(wmi_bus_dev, acpi_device);
> if (error) {
> pr_err("Failed to parse WDG method\n");
> - goto err_remove_busdev;
> + goto err_free_priv;
> }
>
> + sysfs_bin_attr_init(&priv->wdg_bin_attr);
> + priv->wdg_bin_attr.attr.name = "wdg";
> + priv->wdg_bin_attr.attr.mode = 0400;
> + priv->wdg_bin_attr.read = read_wdg;
> + priv->wdg_bin_attr.size = priv->wdg_obj->buffer.length;
> +
> + /* A failure here isn't fatal. */
> + if (sysfs_create_bin_file(&wmi_bus_dev->kobj, &priv->wdg_bin_attr) == 0)
> + priv->wdg_bin_attr_created = true;
There should be at least some warning...
> +
> return 0;
>
> +err_free_priv:
> + kfree(priv);
> +
> err_remove_busdev:
> device_unregister(wmi_bus_dev);
>
--
Pali Rohár
pali.rohar@gmail.com
next prev parent reply other threads:[~2017-08-01 15:46 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-01 15:37 [PATCH 0/3] Three WMI improvements Andy Lutomirski
2017-08-01 15:37 ` [PATCH 1/3] platform/dell-wmi: Fix driver interface version query Andy Lutomirski
2017-08-01 15:43 ` Pali Rohár
2017-08-01 18:08 ` Andy Lutomirski
2017-08-01 19:54 ` Darren Hart
2017-08-01 20:45 ` Pali Rohár
2017-08-01 20:59 ` Darren Hart
2017-08-01 21:16 ` Pali Rohár
2017-08-02 2:25 ` Andy Lutomirski
2017-08-02 2:54 ` Darren Hart
2017-08-01 19:52 ` Darren Hart
2017-08-01 20:06 ` Darren Hart
2017-08-01 20:36 ` Pali Rohár
2017-08-01 15:37 ` [PATCH 2/3] platform/dell-wmi: Update dell_wmi_check_descriptor_buffer() to new model Andy Lutomirski
2017-08-01 15:44 ` Pali Rohár
2017-08-19 0:14 ` Darren Hart
2017-08-01 15:37 ` [PATCH 3/3] platform/wmi: Expose the raw WDG data in sysfs Andy Lutomirski
2017-08-01 15:46 ` Pali Rohár [this message]
2017-08-01 18:29 ` Andy Lutomirski
2017-08-01 20:03 ` Darren Hart
2017-08-01 20:19 ` Andy Lutomirski
2017-08-01 20:40 ` Pali Rohár
2017-08-01 21:17 ` Darren Hart
2017-08-01 21:20 ` Rafael J. Wysocki
2017-08-01 21:36 ` Pali Rohár
2017-08-01 21:32 ` Rafael J. Wysocki
2017-08-01 22:06 ` Darren Hart
2017-08-01 21:31 ` Pali Rohár
2017-08-01 22:39 ` Darren Hart
2017-08-01 23:51 ` Andy Lutomirski
2017-08-02 2:22 ` Darren Hart
2017-08-02 7:49 ` Pali Rohár
2017-08-04 15:03 ` Andy Lutomirski
2017-08-06 21:36 ` Pali Rohár
2017-08-06 22:09 ` Andy Lutomirski
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=20170801154613.GC25574@pali \
--to=pali.rohar@gmail.com \
--cc=dvhart@infradead.org \
--cc=luto@kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
/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