Re: rfc: acpi wmi diff

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

> 
> 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?

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 
 #include 
 #include 
+#include 
 
 #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_LD"PNP0C0D"   /* 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 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+intacpiwmi_match(struct device *, void *, void *);
+void

acpi wmi diff

2013-11-08 Thread Kyle R W Milz
tech@

The diff here is the start of an ACPI WMI implementation to try and
support the hotkeys on my newer asus laptop. I wanted to get some
feedback on this before I went any further.

With this patch I get a line like this in dmesg:

acpiwmi at acpi0 not configured

so I think it is detecting correctly. Ignore the junk in acpiwmi.c.


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 9 Nov 2013 05:18:31 -
@@ -58,6 +58,7 @@ acpitoshiba*  at acpi?
 acpivideo* at acpi?
 acpivout*  at acpivideo?
 acpipwrres*at acpi?
+acpiwmi*   at acpi?
 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 9 Nov 2013 05:18:33 -
@@ -124,6 +124,7 @@ int acpi_foundtmp(struct aml_node *, voi
 intacpi_foundprw(struct aml_node *, void *);
 intacpi_foundvideo(struct aml_node *, void *);
 intacpi_foundsony(struct aml_node *node, void *arg);
+intacpi_foundwmi(struct aml_node *, void *);
 
 intacpi_foundide(struct aml_node *node, void *arg);
 intacpiide_notify(struct aml_node *, int, void *);
@@ -945,6 +946,9 @@ acpi_attach(struct device *parent, struc
/* attach docks */
aml_find_node(&aml_root, "_DCK", acpi_founddock, sc);
 
+   /* check if WMI present */
+   aml_find_node(&aml_root, "_WDG", acpi_foundwmi, sc);
+
/* check if we're running on a sony */
aml_find_node(&aml_root, "GBRT", acpi_foundsony, sc);
 
@@ -2490,6 +2494,26 @@ acpi_foundsony(struct aml_node *node, vo
aaa.aaa_memt = sc->sc_memt;
aaa.aaa_node = node->parent;
aaa.aaa_name = "acpisony";
+
+   config_found(self, &aaa, acpi_print);
+
+   return 0;
+}
+
+int
+acpi_foundwmi(struct aml_node *node, void *arg)
+{
+   struct acpi_softc   *sc = (struct acpi_softc *)arg;
+   struct device   *self = (struct device *)arg;
+   struct acpi_attach_args aaa;
+
+   dnprintf(10, "found wmi entry: %s\n", node->parent->name);
+
+   memset(&aaa, 0, sizeof(aaa));
+   aaa.aaa_iot = sc->sc_iot;
+   aaa.aaa_memt = sc->sc_memt;
+   aaa.aaa_node = node->parent;
+   aaa.aaa_name = "acpiwmi";
 
config_found(self, &aaa, acpi_print);
 
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  9 Nov 2013 05:18:33 -
@@ -728,6 +728,7 @@ struct acpi_ivrs {
 #define ACPI_DEV_LD"PNP0C0D"   /* 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  9 Nov 2013 05:18:33 -
@@ -0,0 +1,63 @@
+/* $OpenBSD$ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct acpiwmi_softc {
+   struct device   sc_dev;
+
+   struct acpi_softc   *sc_acpi;
+   struct aml_node *sc_devnode;
+};
+
+intacpiwmi_match(struct device *, void *, void *);
+void   acpiwmi_attach(struct device *, struct device *, void *);
+intacpiwmi_activate(struct device *, int);
+
+struct cfattach acpiwmi_ca = {
+   sizeof(struct acpiwmi_softc),
+   acpiwmi_match,
+   acpiwmi_attach,
+   acpiwmi_activate
+};
+
+struct cfdriver acpiwmi_cd = {
+   NULL, "acpiwmi", DV_DULL
+};
+
+const char *acpiwmi_hids[] = { ACPI_DEV_WMI, 0 };
+
+int
+acpiwmi_match(struct device *parent, void *match, void *aux)
+{
+   struct acpi_attach_args *aa = aux;
+   struct cfdata *cf = match;
+
+   return (acpi_matchhids(aa, acpiwmi_hids, cf->cf_driver->cd_name));
+}
+
+void
+acpiwmi_attach(struct device *parent, struct device *self, void *aux)
+{
+   struct acpiwmi_softc *sc = (struct acpiwmi_softc *)self;
+   struct acpi_attach_args *aa = aux;
+
+   sc->sc_acpi = (struct acpi_softc *)parent;
+   sc->sc_devnode = aa->aaa_node;
+
+