linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Darren Hart <dvhart@infradead.org>
To: platform-driver-x86@vger.kernel.org
Cc: "Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Andy Lutomirski" <luto@kernel.org>,
	"Andy Lutomirski" <luto@amacapital.net>,
	"Mario Limonciello" <mario_limonciello@dell.com>,
	"Pali Rohár" <pali.rohar@gmail.com>,
	"Rafael Wysocki" <rjw@rjwysocki.net>,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
	"Darren Hart" <dvhart@infradead.org>
Subject: [PATCH 10/16] platform/x86: wmi: Incorporate acpi_install_notify_handler
Date: Fri, 26 May 2017 22:31:24 -0700	[thread overview]
Message-ID: <a868fcacf5342c40371084d183b205fc1d19bc88.1495862272.git.dvhart@infradead.org> (raw)
In-Reply-To: <cover.1495862272.git.dvhart@infradead.org>
In-Reply-To: <cover.1495862272.git.dvhart@infradead.org>

From: Andy Lutomirski <luto@kernel.org>

As a platform driver, acpi_driver.notify will not be available,
so use acpi_install_notify_handler as we will be converting to a
platform driver.

This gives event drivers a simple way to handle events. It
also seems closer to what the Windows docs suggest that Windows
does: it sounds like, in Windows, the mapper is responsible for
called _WED before dispatching to the subdriver.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
[dvhart: merge two development commits and update commit message]
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Mario Limonciello <mario_limonciello@dell.com>
Cc: Pali Rohár <pali.rohar@gmail.com>
Cc: Rafael Wysocki <rjw@rjwysocki.net>
Cc: linux-kernel@vger.kernel.org
Cc: platform-driver-x86@vger.kernel.org
Cc: linux-acpi@vger.kernel.org
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
---
 drivers/platform/x86/wmi.c | 89 +++++++++++++++++++++++++++++++++++++---------
 include/linux/wmi.h        |  1 +
 2 files changed, 73 insertions(+), 17 deletions(-)

diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index bfc0a3f..208e187 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -93,7 +93,6 @@ MODULE_PARM_DESC(debug_dump_wdg,
 
 static int acpi_wmi_remove(struct acpi_device *device);
 static int acpi_wmi_add(struct acpi_device *device);
-static void acpi_wmi_notify(struct acpi_device *device, u32 event);
 
 static const struct acpi_device_id wmi_device_ids[] = {
 	{"PNP0C14", 0},
@@ -109,7 +108,6 @@ static struct acpi_driver acpi_wmi_driver = {
 	.ops = {
 		.add = acpi_wmi_add,
 		.remove = acpi_wmi_remove,
-		.notify = acpi_wmi_notify,
 	},
 };
 
@@ -1023,36 +1021,80 @@ acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address,
 	}
 }
 
-static void acpi_wmi_notify(struct acpi_device *device, u32 event)
+static void acpi_wmi_notify_handler(acpi_handle handle, u32 event,
+				    void *context)
 {
 	struct guid_block *block;
 	struct wmi_block *wblock;
 	struct list_head *p;
+	bool found_it = false;
 
 	list_for_each(p, &wmi_block_list) {
 		wblock = list_entry(p, struct wmi_block, list);
 		block = &wblock->gblock;
 
-		if (wblock->acpi_device == device &&
+		if (wblock->acpi_device->handle == handle &&
 		    (block->flags & ACPI_WMI_EVENT) &&
-		    (block->notify_id == event)) {
-			if (wblock->handler)
-				wblock->handler(event, wblock->handler_data);
-			if (debug_event) {
-				pr_info("DEBUG Event GUID: %pUL\n",
-					wblock->gblock.guid);
-			}
-
-			acpi_bus_generate_netlink_event(
-				device->pnp.device_class, dev_name(&device->dev),
-				event, 0);
+		    (block->notify_id == event))
+		{
+			found_it = true;
 			break;
 		}
 	}
+
+	if (!found_it)
+		return;
+
+	/* If a driver is bound, then notify the driver. */
+	if (wblock->dev.dev.driver) {
+		struct wmi_driver *driver;
+		struct acpi_object_list input;
+		union acpi_object params[1];
+		struct acpi_buffer evdata = { ACPI_ALLOCATE_BUFFER, NULL };
+		acpi_status status;
+
+		driver = container_of(wblock->dev.dev.driver,
+				      struct wmi_driver, driver);
+
+		input.count = 1;
+		input.pointer = params;
+		params[0].type = ACPI_TYPE_INTEGER;
+		params[0].integer.value = event;
+
+		status = acpi_evaluate_object(wblock->acpi_device->handle,
+					      "_WED", &input, &evdata);
+		if (ACPI_FAILURE(status)) {
+			dev_warn(&wblock->dev.dev,
+				 "failed to get event data\n");
+			return;
+		}
+
+		if (driver->notify)
+			driver->notify(&wblock->dev,
+				       (union acpi_object *)evdata.pointer);
+
+		kfree(evdata.pointer);
+	} else if (wblock->handler) {
+		/* Legacy handler */
+		wblock->handler(event, wblock->handler_data);
+	}
+
+	if (debug_event) {
+		pr_info("DEBUG Event GUID: %pUL\n",
+			wblock->gblock.guid);
+	}
+
+	acpi_bus_generate_netlink_event(
+		wblock->acpi_device->pnp.device_class,
+		dev_name(&wblock->dev.dev),
+		event, 0);
+
 }
 
 static int acpi_wmi_remove(struct acpi_device *device)
 {
+	acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
+				   acpi_wmi_notify_handler);
 	acpi_remove_address_space_handler(device->handle,
 				ACPI_ADR_SPACE_EC, &acpi_wmi_ec_space_handler);
 	wmi_free_devices(device);
@@ -1077,11 +1119,20 @@ static int acpi_wmi_add(struct acpi_device *device)
 		return -ENODEV;
 	}
 
+	status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
+					     acpi_wmi_notify_handler,
+					     NULL);
+	if (ACPI_FAILURE(status)) {
+		dev_err(&device->dev, "Error installing notify handler\n");
+		error = -ENODEV;
+		goto err_remove_ec_handler;
+	}
+
 	wmi_bus_dev = device_create(&wmi_bus_class, &device->dev, MKDEV(0, 0),
 				    NULL, "wmi_bus-%s", dev_name(&device->dev));
 	if (IS_ERR(wmi_bus_dev)) {
 		error = PTR_ERR(wmi_bus_dev);
-		goto err_remove_handler;
+		goto err_remove_notify_handler;
 	}
 	device->driver_data = wmi_bus_dev;
 
@@ -1096,7 +1147,11 @@ static int acpi_wmi_add(struct acpi_device *device)
 err_remove_busdev:
 	device_unregister(wmi_bus_dev);
 
-err_remove_handler:
+err_remove_notify_handler:
+	acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
+				   acpi_wmi_notify_handler);
+
+err_remove_ec_handler:
 	acpi_remove_address_space_handler(device->handle,
 					  ACPI_ADR_SPACE_EC,
 					  &acpi_wmi_ec_space_handler);
diff --git a/include/linux/wmi.h b/include/linux/wmi.h
index 5309500..c6eedfd 100644
--- a/include/linux/wmi.h
+++ b/include/linux/wmi.h
@@ -39,6 +39,7 @@ struct wmi_driver {
 
 	int (*probe)(struct wmi_device *wdev);
 	int (*remove)(struct wmi_device *wdev);
+	void (*notify)(struct wmi_device *device, union acpi_object *data);
 };
 
 extern int __must_check __wmi_driver_register(struct wmi_driver *driver,
-- 
2.9.4

  parent reply	other threads:[~2017-05-27  5:31 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-27  5:31 [PATCH 00/16] Convert WMI to a proper bus Darren Hart
2017-05-27  5:31 ` [PATCH 01/16] platform/x86: wmi: Drop "Mapper (un)loaded" messages Darren Hart
2017-05-27  5:31 ` [PATCH 02/16] platform/x86: wmi: Pass the acpi_device through to parse_wdg Darren Hart
2017-05-27  5:31 ` [PATCH 03/16] platform/x86: wmi: Clean up acpi_wmi_add Darren Hart
2017-05-27  5:31 ` [PATCH 04/16] platform/x86: wmi: Track wmi devices per ACPI device Darren Hart
2017-05-27  5:31 ` [PATCH 05/16] platform/x86: wmi: Turn WMI into a bus driver Darren Hart
2017-05-27  5:31 ` [PATCH 06/16] platform/x86: wmi: Fix error handling when creating devices Darren Hart
2017-05-27  5:31 ` [PATCH 07/16] platform/x86: wmi: Split devices into types and add basic sysfs attributes Darren Hart
2017-05-27  5:31 ` [PATCH 08/16] platform/x86: wmi: Probe data objects for read and write capabilities Darren Hart
2017-05-27  5:31 ` [PATCH 09/16] platform/x86: wmi: Instantiate all devices before adding them Darren Hart
2017-06-01 20:43   ` Michał Kępień
2017-06-06  3:03     ` Darren Hart
2017-06-06 16:03       ` Andy Lutomirski
2017-06-08  4:43         ` Michał Kępień
2017-05-27  5:31 ` Darren Hart [this message]
2017-05-27  5:31 ` [PATCH 11/16] platform/x86: wmi: Add a new interface to read block data Darren Hart
2017-05-27  5:31 ` [PATCH 12/16] platform/x86: wmi: Bind the platform device, not the ACPI node Darren Hart
2017-05-27  5:31 ` [PATCH 13/16] platform/x86: wmi: Add an interface for subdrivers to access sibling devices Darren Hart
2017-05-27  5:31 ` [PATCH 14/16] platform/x86: wmi: Require query for data blocks, rename writable to setable Darren Hart
2017-05-27  5:31 ` [PATCH 15/16] platform/x86: wmi-mof: New driver to expose embedded WMI MOF metadata Darren Hart
2017-05-27 11:14   ` Pali Rohár
2017-05-27 21:07     ` Andy Lutomirski
2017-05-30 15:24       ` Andy Shevchenko
2017-05-30 16:46         ` Darren Hart
2017-05-30 17:03         ` Pali Rohár
2017-05-30 17:21           ` Andy Shevchenko
2017-06-05 22:14     ` Darren Hart
2017-06-05 22:19       ` Pali Rohár
2017-06-05 22:39         ` Andy Lutomirski
2017-06-06 11:05           ` Pali Rohár
2017-06-06 13:46             ` Mario.Limonciello
2017-06-06 13:56               ` Pali Rohár
2017-06-07 17:39                 ` Pali Rohár
2017-06-07 20:23                   ` Mario.Limonciello
2017-06-07 20:50                     ` Pali Rohár
2017-06-09 15:46                       ` Mario.Limonciello
2017-06-09 21:51                         ` Pali Rohár
2017-06-15 16:46                           ` Pali Rohár
2017-06-06  2:33         ` Darren Hart
2017-05-27  5:31 ` [PATCH 16/16] platform/x86: dell-wmi: Convert to the WMI bus infrastructure Darren Hart
2017-05-27 10:50   ` Pali Rohár
2017-05-27 16:04     ` Andy Lutomirski
2017-05-27 16:17       ` Dmitry Torokhov
2017-05-27 18:40         ` Andy Lutomirski
2017-05-30  2:45           ` Dmitry Torokhov
2017-06-06  3:04             ` Darren Hart
2017-05-27 19:49 ` [PATCH 00/16] Convert WMI to a proper bus Rafael J. Wysocki
2017-05-27 20:01   ` Andy Shevchenko
2017-06-06 17:23 ` Darren Hart

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=a868fcacf5342c40371084d183b205fc1d19bc88.1495862272.git.dvhart@infradead.org \
    --to=dvhart@infradead.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=mario_limonciello@dell.com \
    --cc=pali.rohar@gmail.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /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;
as well as URLs for NNTP newsgroup(s).