Re: rfc: acpi wmi diff

2013-11-17 Thread Alexey E. Suslikov
Kyle R W Milz kyle at getaddrinfo.net writes:

 
 tech at ,
 
 Here is an initial implementation of a generic acpi wmi framework and a
 single consumer for the framework that lets the volume adjustment keys
 on an asus ux31e work.
 
 The generic framework could be used to support hotkeys found in
 different acer, dell, hp, msi, other laptops.
 
 This is by no means complete as wmi can do all sorts of other stupid
 things like blink leds, toggle radios, control backlights, etc. The code
 has some style(9) issues.
 
 Looking for feedback before I go any further.
 
 Index: arch/amd64/conf/GENERIC
 ===
 RCS file: /cvs/src/sys/arch/amd64/conf/GENERIC,v
 retrieving revision 1.352
 diff -u -p -r1.352 GENERIC
 --- arch/amd64/conf/GENERIC   4 Nov 2013 14:07:15 -   1.352
 +++ arch/amd64/conf/GENERIC   17 Nov 2013 05:53:40 -
  at  at  -58,6 +58,8  at  at  acpitoshiba*at acpi?
  acpivideo*   at acpi?
  acpivout*at acpivideo?
  acpipwrres*  at acpi?
 +acpiwmi* at acpi?
 +acpiwmi_asus*at acpiwmi?

afaik, using underscore in device name is against OpenBSD conventions.

also, if WMI maybe used to implement different vendors' features, would
it be useful to use

acpiwmi* at acpi?
wmiasus* at acpiwmi?

model to have common WMI abstraction under acpiwmi and vendor-specific
stuff under wmivendor (like acpi(4) and acpiasus(4) for instance)?



rfc: acpi wmi diff

2013-11-16 Thread Kyle R W Milz
tech@,

Here is an initial implementation of a generic acpi wmi framework and a
single consumer for the framework that lets the volume adjustment keys
on an asus ux31e work.

The generic framework could be used to support hotkeys found in
different acer, dell, hp, msi, other laptops.

This is by no means complete as wmi can do all sorts of other stupid
things like blink leds, toggle radios, control backlights, etc. The code
has some style(9) issues.

Looking for feedback before I go any further.


Index: arch/amd64/conf/GENERIC
===
RCS file: /cvs/src/sys/arch/amd64/conf/GENERIC,v
retrieving revision 1.352
diff -u -p -r1.352 GENERIC
--- arch/amd64/conf/GENERIC 4 Nov 2013 14:07:15 -   1.352
+++ arch/amd64/conf/GENERIC 17 Nov 2013 05:53:40 -
@@ -58,6 +58,8 @@ acpitoshiba*  at acpi?
 acpivideo* at acpi?
 acpivout*  at acpivideo?
 acpipwrres*at acpi?
+acpiwmi*   at acpi?
+acpiwmi_asus*  at acpiwmi?
 aibs*  at acpi?
 
 mpbios0at bios0
Index: dev/acpi/acpi.c
===
RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.247
diff -u -p -r1.247 acpi.c
--- dev/acpi/acpi.c 6 Nov 2013 10:40:36 -   1.247
+++ dev/acpi/acpi.c 17 Nov 2013 05:53:42 -
@@ -2429,7 +2429,8 @@ acpi_foundhid(struct aml_node *node, voi
!strcmp(dev, ACPI_DEV_TOSHIBA_SPA40)) {
aaa.aaa_name = acpitoshiba;
acpi_toshiba_enabled = 1;
-   }
+   } else if (!strcmp(dev, ACPI_DEV_WMI))
+   aaa.aaa_name = acpiwmi;
 
 
if (aaa.aaa_name)
Index: dev/acpi/acpidev.h
===
RCS file: /cvs/src/sys/dev/acpi/acpidev.h,v
retrieving revision 1.33
diff -u -p -r1.33 acpidev.h
--- dev/acpi/acpidev.h  13 Jul 2012 10:37:40 -  1.33
+++ dev/acpi/acpidev.h  17 Nov 2013 05:53:42 -
@@ -22,6 +22,7 @@
 #include sys/sensors.h
 #include sys/rwlock.h
 #include dev/acpi/acpireg.h
+#include dev/acpi/amltypes.h
 
 #define DEVNAME(s)  ((s)-sc_dev.dv_xname)
 
@@ -337,4 +338,48 @@ struct acpiec_softc {
 
 void   acpibtn_disable_psw(void);
 void   acpibtn_enable_psw(void);
+
+struct acpiwmi_guid {
+   char guid[16];
+   union {
+   char object_id[2];
+   struct {
+   unsigned char notify_id;
+   unsigned char reserved;
+   };
+   };
+   uint8_t instance_count;
+   uint8_t flags;
+#define ACPI_WMI_EXPENSIVE   0x1
+#define ACPI_WMI_METHOD  0x2   /* GUID is a method */
+#define ACPI_WMI_STRING  0x4   /* GUID takes  returns a string */
+#define ACPI_WMI_EVENT   0x8   /* GUID is an event */
+};
+
+typedef void (*wmi_notify_handler) (uint32_t, void *);
+
+struct acpiwmi_block {
+   struct acpiwmi_guid guid_block;
+   char guid_string[37];
+   /* acpi_handle handle; */
+   wmi_notify_handler handler;
+   void *handler_data;
+   struct device dev;
+
+   SIMPLEQ_ENTRY(acpiwmi_block) wmi_link;
+};
+
+struct acpiwmi_softc {
+   struct device   sc_dev;
+
+   struct acpi_softc   *sc_acpi;
+   struct aml_node *sc_devnode;
+
+   SIMPLEQ_HEAD(, acpiwmi_block) wmi_head;
+};
+
+int acpiwmi_guid_match(struct device *, const char *);
+int acpiwmi_install_notify_handler(struct acpiwmi_softc *, const char *, 
wmi_notify_handler, void *);
+int acpiwmi_evaluate_method(struct acpiwmi_softc *, const char *, uint8_t, 
uint32_t, const struct aml_value *, struct aml_value *);
+int acpiwmi_get_event_data(struct acpiwmi_softc *, uint32_t, struct aml_value 
*);
 #endif /* __DEV_ACPI_ACPIDEV_H__ */
Index: dev/acpi/acpireg.h
===
RCS file: /cvs/src/sys/dev/acpi/acpireg.h,v
retrieving revision 1.29
diff -u -p -r1.29 acpireg.h
--- dev/acpi/acpireg.h  6 Nov 2013 10:40:36 -   1.29
+++ dev/acpi/acpireg.h  17 Nov 2013 05:53:42 -
@@ -728,6 +728,7 @@ struct acpi_ivrs {
 #define ACPI_DEV_LDPNP0C0D   /* Lid Device */
 #define ACPI_DEV_SBD   PNP0C0E   /* Sleep Button Device */
 #define ACPI_DEV_PILD  PNP0C0F   /* PCI Interrupt Link Device */
+#define ACPI_DEV_WMI   pnp0c14   /* Windows Management Instrumentation */
 #define ACPI_DEV_MEMD  PNP0C80   /* Memory Device */
 #define ACPI_DEV_SHC   ACPI0001  /* SMBus 1.0 Host Controller */
 #define ACPI_DEV_SMS1  ACPI0002  /* Smart Battery Subsystem */
Index: dev/acpi/acpiwmi.c
===
RCS file: dev/acpi/acpiwmi.c
diff -N dev/acpi/acpiwmi.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ dev/acpi/acpiwmi.c  17 Nov 2013 05:53:42 -
@@ -0,0 +1,389 @@
+#include sys/param.h
+#include sys/device.h
+#include sys/malloc.h
+#include sys/systm.h
+#include sys/workq.h
+
+#include