ACPI: WMI: Patches
Subsystems (2)
v7 cover ACPI: WMI: Patches
Yet again time for another release of WMI-ACPI.
The major changes since the last release (v6) are:
* Converted back to a module
* Added documentation
My comments from the main two patches in v6 (patches 1 and 3 in this series) are repeated ad-verbatim, since they are still applicable.
-Carlos
===
Patch 1 (Add driver and in kernel interface):
Len:
IMNSHO, this patch is ready for more mainstream testing . Ideally, I'd like to see it go up to -mm and start crash^^^^^working on other systems (the main thing to test here, really, is that WMI can properly parse the _WDG method on all systems).
(Of course, outside review is always appreciated - reviewing my own patches is getting a tad boring).
(As a mild aside - the driver is currently available on all ACPI enabled architectures. However, if there are no ia64 systems with WMI-ACPI devices, we could limit the driver to just x86).
===
Patch 2 (Export struct_kset acpi_subsys):
This is a temporary workaround - necessary to allow the sysfs bits of the next patch work in a module.
For 2.6.25, the ACPI interrupt statistics patch series does the necessary work in this area anyway (so this shouldn't be needed then).
If those patches are not applied, then I will resubmit a new version of this patch for 2.6.25-rcX, once Greg KH's sysfs work hits the ACPI tree.
===
Patch 3 (Add sysfs userspace interface):
This patch is the one that really needs another pair of eyes looking over it. It _works_, but I'm not sure if it's the best way to expose WMI ACPI to userspace.
In particular, I'm not sure now about creating kobjects for all the instances of each GUID, then having separate variables and data pointers for each instance; the alternative would be to add more sysfs files under each GUID kobject to handle the instance to call, in a similar way to how method_id is specified to methods. However, that starts making data queries/ writes more complicated, let alone method calls.
===
Patch 4 (Add documentation):
Adds some basic documentation for WMI driver & userspace writers.
Signature · 3 lines
E-Mail: [email protected] Web: strangeworlds.co.uk GPG Key ID: 0x23EE722D
PATCH v7 1/4 ACPI: WMI: Add WMI-ACPI mapper driver
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).
What it won't do:
Unicode - The MS article[1] calls for converting between ASCII and Unicode (or vice versa) if a GUID is marked as "string". This is left up to the calling driver.
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.
v6 (2007-11-07)
* Split out userspace into a different patch
v7 (2007-11-20)
* Fix driver to handle multiple PNP0C14 devices - store all GUIDs using the kernel's built in list functions, and just keep adding to the list every time we handle a PNP0C14 devices - GUIDs will always be unique, and WMI callers do not know or care about different devices.
* Change WMI event handler registration to use its' own event handling struct; we should not pass an acpi_handle down to any WMI based drivers
- they should be able to function with only the calls provided in WMI.
* Update my e-mail address
v8 (2007-11-28)
* Convert back to a module.
* Update Kconfig to default to building as a module.
* Remove an erroneous printk.
* Simply comments for string flag (since we now leave the handling to the caller).
--- MAINTAINERS | 7 + drivers/acpi/Kconfig | 11 + drivers/acpi/Makefile | 1 + drivers/acpi/wmi.c | 642 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 20 ++ 5 files changed, 681 insertions(+), 0 deletions(-) create mode 100644 drivers/acpi/wmi.c
MAINTAINERS +7 -0
@@ -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
@@ -195,6 +195,17 @@ config ACPI_NUMA depends on (X86 || IA64) default y if IA64_GENERIC || IA64_SGI_SN2 +config ACPI_WMI + tristate "WMI (EXPERIMENTAL)" + depends on EXPERIMENTAL + default m + 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
@@ -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 +642 -0
642 lines not on this page · raw message
include/linux/acpi.h +20 -0
@@ -190,6 +190,26 @@ extern int ec_transaction(u8 command,#endif /*CONFIG_ACPI_EC*/ +#if defined(CONFIG_ACPI_WMI ) || defined(CONFIG_ACPI_WMI_MODULE ) + +typedef void (*wmi_notify_handler ) (u32 value,void *context); + +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 (wmi_notify_handler handler, +void *data); +extern acpi_status wmi_remove_notify_handler (void ); +extern acpi_status wmi_get_event_data (u32 event,struct acpi_buffer *out); +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
PATCH v7 2/4 ACPI: Export struct kset acpi_subsys
In reply to Carlos CorbachoExport acpi_subsys so it can be used by modules that want to hook into /sys/firmware/acpi
--- drivers/acpi/bus.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/acpi/bus.c +2 -0
@@ -779,4 +779,6 @@ static int __init acpi_init(void)return result; } +EXPORT_SYMBOL (acpi_subsys); +subsys_initcall (acpi_init);
Signature · 1 line
1.5.3.4
PATCH v7 3/4 ACPI: WMI: Add sysfs userspace interface
In reply to Carlos CorbachoUserspace:
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)
===
ChangeLog
==
v1 (2007-11-03)
* Initial release
v2 (2007-11-07)
* Split out into a separate patch
v3 (2007-11-20)
* Convert kobject storage to using kernel list structures.
* Change instance handling - store input data on a per instance basis, rather than a per GUID.
* Add locking to methods - method_id (write) and data (read & write) should all be mutually exclusive - we do not want the input data to change when we are trying to execute a method.
* Change method calling semantics: when input is written to 'data', store it, but don't execute the method until 'data' is read. This is due to the fact that it is perfectly acceptable to have a WMI method that does not take any input (and it is easier to trigger an execute on reading the file, and not return anything if there is nothing to return, rather than trying to write values that aren't required, or may cause ACPI evaluation to fail on the method).
* Do not try and convert String's from ASCII to Unicode - instead, only handle ASCII (as per ACPI), and leave it up to userspace to convert to/ from whatever encoding they wish to use.
v4 (2007-11-28)
* Add code to remove sysfs files on module removal
--- drivers/acpi/wmi.c | 431 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 430 insertions(+), 1 deletions(-)
drivers/acpi/wmi.c +430 -1
@@ -66,15 +66,31 @@ struct guid_blocku8 flags; }; +struct wmi_instance +{ +struct kobject kobj; +u32 method_id; +void *pointer; +acpi_size length; +}; +struct wmi_block {struct list_head list;struct guid_block gblock;acpi_handle handle; +struct kobject kobj; +struct wmi_instance *instances; };static struct wmi_block wmi_blocks; +/* +* Temporary list - hold contents of each WMI device for sysfs initialisation, +* before adding to wmi_blocks +*/ +static struct wmi_block wmi_block_sysfs; +static wmi_notify_handler wmi_external_handler;static void *wmi_external_data;
@@ -201,6 +217,33 @@ static bool wmi_parse_guid(const u8 *src, u8 *dest)return true; } +/* +* Convert a raw GUID to the ACII string representation +*/ +static int wmi_gtoa (const char *in,char *out) +{ +int i; + +for (i =3 ; i >=0 ; i--) + out +=sprintf (out,"%02X" , in[i] &0xFF ); + + out +=sprintf (out,"-" ); + out +=sprintf (out,"%02X" , in[5 ] &0xFF ); + out +=sprintf (out,"%02X" , in[4 ] &0xFF ); + out +=sprintf (out,"-" ); + out +=sprintf (out,"%02X" , in[7 ] &0xFF ); + out +=sprintf (out,"%02X" , in[6 ] &0xFF ); + out +=sprintf (out,"-" ); + out +=sprintf (out,"%02X" , in[8 ] &0xFF ); + out +=sprintf (out,"%02X" , in[9 ] &0xFF ); + out +=sprintf (out,"-" ); + +for (i =10 ; i <=15 ; i++) + out +=sprintf (out,"%02X" , in[i] &0xFF ); + +return 0 ; +} +static bool find_guid (const char *guid_string,struct wmi_block **out) {char tmp[16 ], guid_input[16 ];
@@ -503,6 +546,371 @@ bool wmi_has_guid(const char *guid_string) }EXPORT_SYMBOL_GPL (wmi_has_guid); +/* +* sysfs interface +*/ +struct wmi_attribute { +struct attribute attr; +ssize_t (*show)(struct kobject *kobj,char *buf); +ssize_t (*store)(struct kobject *kobj,const char *buf,ssize_t count); +}; + +#define WMI_ATTR (_name, _mode, _show, _store) \ +struct wmi_attribute wmi_attr_##_name = __ATTR(_name, _mode, _show, _store); + +#define to_attr (a) container_of(a, struct wmi_attribute, attr) + +static ssize_t show (struct kobject *kobj,struct attribute *attr,char *buf) +{ +struct wmi_attribute *wmi_attr =to_attr (attr); +ssize_t ret =0 ; + +if (wmi_attr->show) + ret = wmi_attr->show (kobj, buf); +return ret; +} + +static ssize_t store (struct kobject *kobj,struct attribute *attr,const +char *buf,size_t count) +{ +struct wmi_attribute *wmi_attr =to_attr (attr); +ssize_t ret =0 ; + +if (wmi_attr->store) + ret = wmi_attr->store (kobj, buf, count); +return ret; +} + +static struct sysfs_ops wmi_sysfs_ops = { + .show = show, + .store = store, +}; + +static struct kobj_type ktype_wmi = { + .sysfs_ops = &wmi_sysfs_ops, +}; + +static struct kobject wmi_kobj; + +static ssize_t wmi_data_read (struct kobject *kobj,struct bin_attribute + *bin_attr,char *buf,loff_t offset,size_t count) { +u8 instance; +const char *guid; +struct acpi_buffer in; +struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER ,NULL }; +acpi_status status; +union acpi_object *obj; +struct wmi_block *block; +struct wmi_instance *iblock; + + guid =kobject_name (kobj->parent); + + block = container_of(kobj->parent, struct wmi_block, kobj); +if (!block) +return -EINVAL ; + + iblock = container_of(kobj, struct wmi_instance, kobj); +if (!iblock) +return -EINVAL ; + + instance =simple_strtoul (kobject_name (kobj),NULL ,10 ); + +if (block->gblock.flags &ACPI_WMI_METHOD ) { +mutex_lock (&wmi_data_lock); +if (iblock->pointer) { + in.pointer = iblock->pointer; + in.length = iblock->length; + status =wmi_evaluate_method (guid, instance, + iblock->method_id, &in, &out); + }else { + status =wmi_evaluate_method (guid, instance, + iblock->method_id,NULL , &out); + } +mutex_unlock (&wmi_data_lock); + }else { + status =wmi_query_block (guid, instance, &out); + } + + obj = (union acpi_object *) out.pointer; + +switch (obj->type) { +case (ACPI_TYPE_STRING ): +case (ACPI_TYPE_BUFFER ): + buf = obj->buffer.pointer; +break ; +default : +return -EIO ; + } + +return 0 ; +} + +static ssize_t wmi_data_write (struct kobject *kobj,struct bin_attribute + *bin_attr,char *buf,loff_t offset,size_t count){ +struct wmi_block *wblock =NULL ; +struct wmi_instance *iblock =NULL ; +struct acpi_buffer in; +acpi_status status; +const char *guid; +u8 inst; + + guid =kobject_name (kobj->parent); + inst =simple_strtoul (kobject_name (kobj),NULL ,10 ); + + wblock = container_of(kobj->parent, struct wmi_block, kobj); +if (!wblock) +return -EINVAL ; + + iblock = container_of(kobj, struct wmi_instance, kobj); +if (!iblock) +return -EINVAL ; + +if (count ==0 ) +return count; + +if (wblock->gblock.flags &ACPI_WMI_METHOD ) { + iblock->pointer =kzalloc (count,GFP_KERNEL ); +if (!iblock->pointer) +return count; + +memcpy (iblock->pointer, buf, count); + + iblock->length = count; + }else { + in.pointer = buf; + in.length = count; + status =wmi_set_block (guid, inst, &in); + } + +return count; +} + +static struct bin_attribute wmi_attr_data = { + .attr = {.name ="data" , .mode =0600 }, + .size =0 , + .read = wmi_data_read, + .write = wmi_data_write, +}; + +static ssize_t wmi_event_data_read (struct kobject *kobj,struct bin_attribute + *bin_attr,char *buf,loff_t offset,size_t count) { +struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *obj; +struct wmi_block *block; + + block = container_of(kobj, struct wmi_block, kobj); +wmi_get_event_data (block->gblock.notify_id, &out); + + obj = (union acpi_object *) out.pointer; + buf = obj->buffer.pointer; + +return 0 ; +} + +static struct bin_attribute wmi_attr_event_data = { + .attr = {.name ="data" , .mode =0400 }, + .size =0 , + .read = wmi_event_data_read, +}; + +/* sysfs calls */ +static ssize_t show_guid_type (struct kobject *kobj,char *buf) +{ +struct guid_block *block; +struct wmi_block *wblock; +bool result; + + result =find_guid (kobject_name (kobj), &wblock); +if (result == false) +return sprintf (buf,"Error\n" ); + + block = &wblock->gblock; + +if (block->flags &ACPI_WMI_METHOD ) { +return sprintf (buf,"method\n" ); + }else if (block->flags &ACPI_WMI_EVENT ) { +return sprintf (buf,"event\n" ); + }else { +return sprintf (buf,"data\n" ); + } +} +static WMI_ATTR(type, S_IRUGO, show_guid_type, NULL); + +static ssize_t show_guid_method_id (struct kobject *kobj,char *buf) +{ +struct wmi_instance *block; + + block = container_of(kobj, struct wmi_instance, kobj); +if (!block) +return sprintf (buf,"Error\n" ); + +return sprintf (buf,"%d\n" , block->method_id); +} + +static ssize_t set_guid_method_id (struct kobject *kobj,const char *buf, +ssize_t count) +{ +struct wmi_instance *block; +u8 method_id; + + method_id =simple_strtoul (buf,NULL ,10 ); + +mutex_lock (&wmi_data_lock); + + block = container_of(kobj, struct wmi_instance, kobj); +if (!block) { +mutex_unlock (&wmi_data_lock); +return -EINVAL ; + } + + block->method_id = method_id; +mutex_unlock (&wmi_data_lock); +return count; +} +static WMI_ATTR(method_id, S_IWUGO | S_IRUGO, show_guid_method_id, + set_guid_method_id); + +static ssize_t show_event_notification (struct kobject *kobj,char *buf) +{ +struct wmi_block *block; +struct guid_block *gblock; + + block = container_of(kobj, struct wmi_block, kobj); + gblock = &block->gblock; + +return sprintf (buf,"%d\n" , gblock->notify_id &0xFF ); +} +static WMI_ATTR(notification, S_IRUGO, show_event_notification, NULL); + +static int wmi_sysfs_init (void ) +{ +int i, result; +u8 instances; +char guid_string[37 ]; +char inst_string[4 ]; +struct kobject *guid_kobj, *inst_kobj; +struct guid_block *gblock; +struct wmi_block *wblock; +struct list_head *p; + +/* Create directories for all the GUIDs */ +list_for_each (p, &wmi_block_sysfs.list) { + wblock = list_entry(p, struct wmi_block, list); + guid_kobj = &wblock->kobj; + guid_kobj->parent = &wmi_kobj; + guid_kobj->ktype = &ktype_wmi; + + gblock = &wblock->gblock; +wmi_gtoa (gblock->guid, guid_string); + + result =kobject_set_name (guid_kobj, guid_string); +if (result) +return result; + + result =kobject_register (guid_kobj); +if (result) +return result; + + result =sysfs_create_file (guid_kobj, &wmi_attr_type.attr); +if (result) +return result; + +if (gblock->flags &ACPI_WMI_EVENT ) { + result =sysfs_create_file (guid_kobj, + &wmi_attr_notification.attr); +if (result) +return result; + + result =sysfs_create_bin_file (guid_kobj, + &wmi_attr_event_data); +if (result) +return result; +break ; + } + +/* Create directories for all the instances */ + instances = gblock->instance_count; +for (i =0 ; i < instances; i++) { + inst_kobj = &wblock->instances[i].kobj; + inst_kobj->parent = guid_kobj; + inst_kobj->ktype = &ktype_wmi; +sprintf (inst_string,"%d" , i+1 ); + result =kobject_set_name (inst_kobj, inst_string); +if (result) +return result; + + result =kobject_register (inst_kobj); +if (result) +return result; + +/* Create the relevant files under each instance */ + result =sysfs_create_bin_file (inst_kobj, + &wmi_attr_data); +if (result) +return result; + +if (gblock->flags &ACPI_WMI_METHOD ) { + result =sysfs_create_file (inst_kobj, + &wmi_attr_method_id.attr); +if (result) +return result; + } + } + } + +list_splice_init (&wmi_block_sysfs.list, &wmi_blocks.list); + +return 0 ; +} + +static int wmi_sysfs_exit (void ) +{ +int i; +u8 instances; +struct kobject *guid_kobj, *inst_kobj; +struct guid_block *gblock; +struct wmi_block *wblock; +struct list_head *p; + +/* Create directories for all the GUIDs */ +list_for_each (p, &wmi_blocks.list) { + wblock = list_entry(p, struct wmi_block, list); + guid_kobj = &wblock->kobj; + gblock = &wblock->gblock; + +sysfs_remove_file (guid_kobj, &wmi_attr_type.attr); + +if (gblock->flags &ACPI_WMI_EVENT ) { +sysfs_remove_file (guid_kobj, + &wmi_attr_notification.attr); + +sysfs_remove_bin_file (guid_kobj, + &wmi_attr_event_data); + }else { +/* Create directories for all the instances */ + instances = gblock->instance_count; +for (i =0 ; i < instances; i++) { + inst_kobj = &wblock->instances[i].kobj; + +/* Remove the files under each instance */ +sysfs_remove_bin_file (inst_kobj, + &wmi_attr_data); + +if (gblock->flags &ACPI_WMI_METHOD ) { +sysfs_remove_file (inst_kobj, + &wmi_attr_method_id.attr); + } + +kobject_unregister (inst_kobj); +kfree (wblock->instances); + } + } +kobject_unregister (guid_kobj); + } + +return 0 ; +} +/** * parse_wdg - Parse the _WDG method for the GUID data blocks */
@@ -538,9 +946,14 @@ static __init acpi_status parse_wdg(acpi_handle handle)if (!wblock)return AE_NO_MEMORY ; + wblock->instances =kzalloc (gblock[i].instance_count * +sizeof (struct wmi_instance ),GFP_KERNEL ); +if (!wblock->instances) +return AE_NO_MEMORY ; + wblock->gblock = gblock[i]; wblock->handle = handle; -list_add_tail (&wblock->list, &wmi_blocks.list); +list_add_tail (&wblock->list, &wmi_block_sysfs.list); }kfree (out.pointer);
@@ -599,6 +1012,8 @@ static int __init acpi_wmi_add(struct acpi_device *device)if (ACPI_FAILURE (status))return -ENODEV ; + result =wmi_sysfs_init (); +return result; }
@@ -609,7 +1024,18 @@ static int __init acpi_wmi_init(void)if (acpi_disabled)return -ENODEV ; + wmi_kobj.parent = &acpi_subsys.kobj; + wmi_kobj.ktype = &ktype_wmi; + result =kobject_set_name (&wmi_kobj,"wmi" ); +if (result) +return result; + + result =kobject_register (&wmi_kobj); +if (result) +return result; +INIT_LIST_HEAD (&wmi_blocks.list); +INIT_LIST_HEAD (&wmi_block_sysfs.list); result =acpi_bus_register_driver (&acpi_wmi_driver);
@@ -628,6 +1054,9 @@ static void __exit acpi_wmi_exit(void)acpi_bus_unregister_driver (&acpi_wmi_driver); +wmi_sysfs_exit (); +kobject_unregister (&wmi_kobj); +list_for_each_safe (p, tmp, &wmi_blocks.list) { wblock = list_entry(p, struct wmi_block, list);
Signature · 1 line
1.5.3.4
PATCH v7 4/4 ACPI: WMI: Add documentation
In reply to Carlos CorbachoAdd documentation for WMI-ACPI, giving basic information for WMI driver and userspace writers.
===
ChangeLog
v1 (2007-11-28)
Initial version
--- Documentation/acpi/wmi.txt | 82 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 82 insertions(+), 0 deletions(-) create mode 100644 Documentation/acpi/wmi.txt
Documentation/acpi/wmi.txt new file +82 -0
@@ -0,0 +1,82 @@ +WMI-ACPI mapping driver + +Copyright (C) 2007 Carlos Corbacho <[email protected]> + +Updated: 28th November 2007 + +1) About this guide + +This guide is a basic introduction on how to interact with the WMI-ACPI mapper +driver in the kernel - it presumes you already have a basic knowledge of +WMI-ACPI, ACPI and the hardware you are writing the driver for. + +2) What is WMI-ACPI + +At its simplest, WMI-ACPI is a proprietary extension to the ACPI specification +from Microsoft to allow WMI (their implementation of WBEM) to access +instrumentation data and methods in ACPI from userspace, via the ACPI _HID +device PNP0C14. + +3) What is the WMI-ACPI mapper + +The Linux WMI to ACPI mapper is the implementation of the kernel part of the +WMI-ACPI specification. + +NOTE: The mapper does not do anything itself with the WMIACPI devices - it +simply makes their methods and data available to other drivers and userspace. + +Userspace: + +WMI-ACPI is exposed to userspace via sysfs and netlink. Data and methods are +exposed through sysfs, events are sent via netlink. + +Accessing WMI-ACPI directly through sysfs is generally not recommended - +ideally, this should be done by a userspace library, which could also deal +with the netlink events. + +The sysfs interface is in /sys/firmware/acpi/wmi for WMI methods and data, as +follows: + +/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) + +Kernel interface: + +For drivers that want to bypass userspace (either because WBEM is overkill, +or a userspace application is not really appropriate for want you want to do), +and talk directly to WMI-ACPI, then the mapper also exports functions +to do this - these are essentially thin wrappers around ACPI, so if you are +familiar with writing an ACPI driver, then writing a WMI driver is not much more +of a stretch. + +The exported WMIACPI functions can be found in <linux/acpi.h> + +The most important differences between WMI-ACPI and WMI are: + +A) WMI based drivers should be platform drivers, not ACPI drivers. + +B) ACPI details such as handles and/ or path names are hidden; you use GUIDs as + the unique identifier to call methods instead (you don't need to care either + about multiple PNP0C14 devices exiting - the GUIDs are always unique, and + these are what you will work with). + +C) In your probe() function, you should use wmi_has_guid() to look for the + GUID(s) you need for your driver. + +[1] http://www.microsoft.com/whdc/system/pnppwr/wmi/wmi-acpi.mspx
Signature · 1 line
1.5.3.4