Skip to contentSkip to conversation

ACPI: WMI: Add WMI-ACPI mapper driver

PATCH Superseded Carlos Corbacho 2 participants 5 messages Nov 3, 2007 – Nov 7, 2007 ACPI

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 ACPI: WMI: Add WMI-ACPI mapper driver

From: Carlos Corbacho <[email protected]>

The following is an implementation of the Windows Management Instrumentation (WMI) ACPI interface mapper (PNP0C14).

What it does:

Parses the _WDG method and exports functions to process WMI method calls, data block query/ set commands (both based on GUID) and does basic event handling.

How: WMI presents two interfaces, an in kernel API and a userspace sysfs API.

Kernel: (essentially, a minimal wrapper around ACPI)

(const char *guid assume the 36 character ASCII representation of a GUID - e.g. 67C3371D-95A3-4C37-BB61-DD47B491DAAB)

wmi_evaluate_method(const char *guid, u8 instance, u32 method_id, const struct acpi_buffer *in, struct acpi_buffer *out)

wmi_query_block(const char *guid, u8 instance,
struct acpi_buffer *out)

wmi_set_block(const char *guid, u38 instance,
const struct acpi_buffer *in)

wmi_install_notify_handler(acpi_notify_handler handler);

wmi_remove_notify_handler(void);

wmi_get_event_data(u32 event, struct acpi_buffer *out)

wmi_has_guid(const char guid*)

wmi_has_guid() is a helper function to find if a GUID exists or not on the system (a quick and easy way for WMI dependant drivers to see if the the method/ block they want exists, since GUIDs are supposed to be unique).

Event handling - allow a WMI based driver to register a notifier handler with WMI. When a notification is sent to WMI, the handler registered with WMI is then called (it is left to the caller to ask for the WMI event data, if needed).

Userspace:

There is a userspace interface in /sys/firmware/acpi/wmi for WMI methods and data.

/sys/firmware/acpi/wmi/
|
|-> <GUID>/
|-> type (method, data, event)

Method & data blocks
|-> <instance>/
|-> data (binary data file - write input data to file, read file
to execute method or retrieve data).

Method only

    |-> method_id (write value of method id to execute)

Events - passed to userspace via netlink. However, the extra WMI data associated with an event is exposed through sysfs.

|-> notification (ACPI event value)
|-> data (binary data file - WMI data associated with the event)

What it might be able to do:

Handle reading data block GUIDs marked as "expensive" (e.g. calling WCxx with the correct arguments, before and after querying the block in question). My DSDT does not have any such marked block methods, so this is untested.

What it can't do:

Unicode - The MS article[1] calls for converting between ASCII and Unicode (or vice versa) if a GUID is marked as "string". There is also another problem in that given this specification revolves around Windows, Unicode in this context likely means UTF-16. Since Linux doesn't use this, and since this driver will only be called by on Linux, it may make more sense to treat Unicode here as UTF-8 instead.

What it won't do:

Handle a MOF[1] - the WMI mapper just exports methods, data and events to userspace. MOF handling is down to userspace.

[1] http://www.microsoft.com/whdc/system/pnppwr/wmi/wmi-acpi.mspx

===
ChangeLog
==

v1 (2007-10-02):

* Initial release

v2 (2007-10-05):

* Cleaned up code - split up super "wmi_evaluate_block" -> each external symbol now handles its own ACPI calls, rather than handing off to a "super" method (and in turn, is a lot simpler to read)
* Added a find_guid() symbol - return true if a given GUID exists on the system
* wmi_* functions now return type acpi_status (since they are just fancy wrappers around acpi_evaluate_object())
* Removed extra debug code

v3 (2007-10-27)

* More code clean up - now passes checkpatch.pl
* Change data block calls - ref MS spec, method ID is not required for them, so drop it from the function parameters.
* Const'ify guid in the function call parameters.
* Fix _WDG buffer handling - copy the data to our own private structure.
* Change WMI from tristate to bool - otherwise the external functions are not exported in linux/acpi.h if you try to build WMI as a module.
* Fix more flag comparisons.
* Add a maintainers entry - since I wrote this, I should take the blame for it.

v4 (2007-10-30)

* Add missing brace from after fixing checkpatch errors.
* Rewrote event handling - allow external drivers to register with WMI to handle WMI events
* Clean up flags and sanitise flag handling

v5 (2007-11-03)

* Add sysfs interface for userspace. Export events over netlink again.
* Remove module left overs, fully convert to built-in driver.
* Tweak in-kernel API to use u8 for instance, since this is what the GUID blocks use (so instance cannot be greater than u8).
* Export wmi_get_event_data() for in kernel WMI drivers.

---
I've tested the userspace interface (for methods) with a simple C program, and was able to toggle the mail LED on my laptop quite easily with it.

 MAINTAINERS           |    7 +
 drivers/acpi/Kconfig  |   11 +
 drivers/acpi/Makefile |    1 +
 drivers/acpi/wmi.c    |  906 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/acpi.h  |   17 +
 5 files changed, 942 insertions(+), 0 deletions(-)
 create mode 100644 drivers/acpi/wmi.c
MAINTAINERS +7 -0
index 4a26f83..aab2e54 100644
@@ -261,6 +261,13 @@ L:	[email protected]
 W:	http://acpi.sourceforge.net/
 S:	Supported
 
+ACPI WMI DRIVER
+P:      Carlos Corbacho
+M:      [email protected]
+L:      [email protected]
+W:      http://www.lesswatts.org/projects/acpi/
+S:      Supported
+
 ADM1025 HARDWARE MONITOR DRIVER
 P:	Jean Delvare
 M:	[email protected]
drivers/acpi/Kconfig +11 -0
index da3a08f..3bdcfcf 100644
@@ -181,6 +181,17 @@ config ACPI_NUMA
 	depends on (X86 || IA64)
 	default y if IA64_GENERIC || IA64_SGI_SN2
 
+config ACPI_WMI
+	bool "WMI (EXPERIMENTAL)"
+	depends on EXPERIMENTAL
+	default y
+	help
+	  This driver adds support for the WMI ACPI mapper device (PNP0C14)
+	  found on some systems.
+
+	  NOTE: You will need another driver or userspace application on top of
+	  this to actually use anything defined in the WMI ACPI mapper.
+
 config ACPI_ASUS
         tristate "ASUS/Medion Laptop Extras"
 	depends on X86
drivers/acpi/Makefile +1 -0
index 54e3ab0..9e9aa39 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_ACPI_THERMAL)	+= thermal.o
 obj-$(CONFIG_ACPI_SYSTEM)	+= system.o event.o
 obj-$(CONFIG_ACPI_DEBUG)	+= debug.o
 obj-$(CONFIG_ACPI_NUMA)		+= numa.o
+obj-$(CONFIG_ACPI_WMI)		+= wmi.o
 obj-$(CONFIG_ACPI_ASUS)		+= asus_acpi.o
 obj-$(CONFIG_ACPI_TOSHIBA)	+= toshiba_acpi.o
 obj-$(CONFIG_ACPI_HOTPLUG_MEMORY)	+= acpi_memhotplug.o
drivers/acpi/wmi.c new file +906 -0

906 lines not on this page · raw message

include/linux/acpi.h +17 -0
index 8ccedf7..36c91b3 100644
@@ -186,6 +186,23 @@ extern int ec_transaction(u8 command,
 
 #endif /*CONFIG_ACPI_EC*/
 
+#ifdef CONFIG_ACPI_WMI
+
+extern acpi_status wmi_evaluate_method(const char *guid, u8 instance,
+					u32 method_id,
+					const struct acpi_buffer *in,
+					struct acpi_buffer *out);
+extern acpi_status wmi_query_block(const char *guid, u8 instance,
+					struct acpi_buffer *out);
+extern acpi_status wmi_set_block(const char *guid, u8 instance,
+					const struct acpi_buffer *in);
+extern acpi_status wmi_install_notify_handler(acpi_notify_handler handler,
+					void *data);
+extern acpi_status wmi_remove_notify_handler(void);
+extern bool wmi_has_guid(const char *guid);
+
+#endif	/* CONFIG_ACPI_WMI */
+
 extern int acpi_blacklisted(void);
 extern void acpi_bios_year(char *s);
 
Signature · 1 line
1.5.3.4
#1 lore raw

Apologies for having spammed the mailing list and your inboxes - unfortunately, my mail provider decided to mark my outgoing mail as spam (the multiple e-mails are the result of trying to 'persuade' the system that my original e-mail wasn't spam, and ended up resending it five times...).

Fingers crossed, it won't happen again.

-Carlos

#3 lore raw
Quoted 5 lines · On Wednesday 07 November 2007 04:54:22 Matthew Garrett wrote:
Quoted 2 lines · Carlos Corbacho

Handle a MOF[1] - the WMI mapper just exports methods, data and events to userspace. MOF handling is down to userspace.

How does userspace obtain the MOF from the ACPI tables?

Normally, userspace does not obtain the MOF from the ACPI tables.

Basically, there are four possible ways to otain a MOF:

1) A method in the WMI-ACPI implementation - _some_ (very few) implementations have a method in WMI-ACPI that will return a binary MOF (since the MS spec suggests this is just one _possible_ way to provide the MOF, but that it is not required).

2) Ask the hardware manufacturer or BIOS writer to provide it

3) Reverse engineer Windows software - try and extract the MOF from Windows software (we managed to do this on some newer Acer laptops just using 'strings', where the MOF was not converted to the binary MOF format).

4) Write your own MOF via experimentation, reverse engineering and guesswork

If you want, you can of course just bypass the whole MOF nonsense and start talking to WMI-ACPI, if you know what you're doing; a MOF file is really only required for a 'true' WBEM implementation - if you don't care about WBEM, then a MOF is really just a specification which tells you (roughly) what the interface does.

-Carlos

Signature · 3 lines
E-Mail: [email protected]
Web: strangeworlds.co.uk
GPG Key ID: 0x23EE722D
#4 lore raw
Quoted 6 lines · Carlos Corbacho

On Wednesday 07 November 2007 04:54:22 Matthew Garrett wrote:

1) A method in the WMI-ACPI implementation - _some_ (very few) implementations have a method in WMI-ACPI that will return a binary MOF (since the MS spec suggests this is just one _possible_ way to provide the MOF, but that it is not required).

Ah, sorry, I'd misread the spec - I thought the MOF was at a defined name rather than just being returned via a normal WMI method. The functionality in this version looks fine, so I'll try to find time to test it this week.

Signature · 1 line
Matthew Garrett | [email protected]