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 

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_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  9 Nov 2013 05:18:33 -
@@ -0,0 +1,63 @@
+/* $OpenBSD$ */
+
+#include sys/param.h
+#include sys/device.h
+#include sys/systm.h
+#include sys/workq.h
+
+#include dev/acpi/acpireg.h
+#include dev/acpi/acpivar.h
+#include dev/acpi/acpidev.h
+#include dev/acpi/amltypes.h
+#include dev/acpi/dsdt.h
+
+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;
+
+   

Re: rman.h

2013-09-18 Thread Kyle R W Milz
On Wed, Sep 18, 2013 at 08:04:16PM +, Miod Vallat wrote:
  I was porting over some freebsd kernel code and came across a struct
  rman and some rman_* utility functions, defined in fbsd's sys/rman.h .
  
  Does obsd have an equivalent interface?
 
 The ``get some ranges from a global resource'' functionality is achieved
 under OpenBSD by using extent(9).

OK was looking at that too, seemed to be similar.

 The ``tie various handles and cookies to a resource'' functionality is
 not available, and has to be done by hand, or differently.

Miod you're a boss, thanks.

 Miod



Re: rman.h

2013-09-18 Thread Kyle R W Milz
On Wed, Sep 18, 2013 at 02:01:10PM +, Ted Unangst wrote:
 On Tue, Sep 17, 2013 at 13:54, Kyle R W Milz wrote:
  tech@,
  
  I was porting over some freebsd kernel code and came across a struct
  rman and some rman_* utility functions, defined in fbsd's sys/rman.h .
  
  Does obsd have an equivalent interface?
 
 Maybe something like bus_space. Find a FreeBSD driver that's already been
 ported and compare is your best bet.

Yeah good idea will do that, thanks.



rman.h

2013-09-17 Thread Kyle R W Milz
tech@,

I was porting over some freebsd kernel code and came across a struct
rman and some rman_* utility functions, defined in fbsd's sys/rman.h .

Does obsd have an equivalent interface?



Patriot Wireless N USB Adapter

2013-09-14 Thread Kyle R. W. Milz
Tech,

Recently purchased the Patriot PCUSBW1150 wireless adapter and it works
great with the urtwn driver. Perchance it can be added to the HARDWARE
section of the man page?

urtwn0 at uhub1 port 2 Realtek 802.11n WLAN Adapter rev 2.00/2.00 addr 3
urtwn0: MAC/BB RTL8188CUS, RF 6052 1T1R, address mac addr scrubbed



Re: Patriot Wireless N USB Adapter

2013-09-14 Thread Kyle R. W. Milz
I'll stop being lazy, maybe this will make things easier for you.  Full
disclosure: first patch I've sent to this list.


Index: share/man/man4/urtwn.4
===
RCS file: /cvs/src/share/man/man4/urtwn.4,v
retrieving revision 1.24
diff -u -p -r1.24 urtwn.4
--- share/man/man4/urtwn.4  20 Aug 2013 13:46:54 -  1.24
+++ share/man/man4/urtwn.4  14 Sep 2013 17:30:35 -
@@ -106,6 +106,7 @@ The following adapters should work:
 .It Hercules Wireless N USB Pico HWNUp-150
 .It IO-DATA WN-G150UM
 .It Netgear WNA1000A
+.It Patriot PCUSBW1150
 .It Planex GW-USEco300
 .It Planex GW-USNano2
 .It Planex GW-USValue-EZ



Re: Patriot Wireless N USB Adapter

2013-09-14 Thread Kyle R W Milz
On Sat, Sep 14, 2013 at 07:05:53PM +0059, Jason McIntyre wrote:
 On Sat, Sep 14, 2013 at 07:52:51PM +0200, David Coppa wrote:
  On Sat, Sep 14, 2013 at 7:48 PM, Kyle R. W. Milz k...@getaddrinfo.net 
  wrote:
   I'll stop being lazy, maybe this will make things easier for you.  Full
   disclosure: first patch I've sent to this list.
  
  
   Index: share/man/man4/urtwn.4
   ===
   RCS file: /cvs/src/share/man/man4/urtwn.4,v
   retrieving revision 1.24
   diff -u -p -r1.24 urtwn.4
   --- share/man/man4/urtwn.4  20 Aug 2013 13:46:54 -  1.24
   +++ share/man/man4/urtwn.4  14 Sep 2013 17:30:35 -
   @@ -106,6 +106,7 @@ The following adapters should work:
.It Hercules Wireless N USB Pico HWNUp-150
.It IO-DATA WN-G150UM
.It Netgear WNA1000A
   +.It Patriot PCUSBW1150
.It Planex GW-USEco300
.It Planex GW-USNano2
.It Planex GW-USValue-EZ
  
  
  jmc already committed it.
  
 
 yeah, my mail wasn;t entirely clear. i was trying to match the wizardry
 of kyle's perchance. it's a hard one to follow...

Hah, wizardry. Will use plainer language next time :)

 anyway, as david said, i did commit this. still, diffs attached to mails
 are so much better, and always clearer.

ack.

 jmc