Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/acpi Move acpiwmi(4) to the "sys/dev/acpi/wmi" -subd...



details:   https://anonhg.NetBSD.org/src/rev/36eb1ca15906
branches:  trunk
changeset: 753732:36eb1ca15906
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Thu Apr 08 12:14:19 2010 +0000

description:
Move acpiwmi(4) to the "sys/dev/acpi/wmi" -subdirectory.

diffstat:

 sys/dev/acpi/files.acpi        |    8 +-
 sys/dev/acpi/wmi/files.wmi     |    9 +-
 sys/dev/acpi/wmi/wmi_acpi.c    |  789 +++++++++++++++++++++++++++++++++++++++++
 sys/dev/acpi/wmi/wmi_acpivar.h |   50 ++
 sys/dev/acpi/wmi/wmi_dell.c    |    6 +-
 sys/dev/acpi/wmi_acpi.c        |  786 ----------------------------------------
 sys/dev/acpi/wmi_acpivar.h     |   50 --
 7 files changed, 851 insertions(+), 847 deletions(-)

diffs (truncated from 1762 to 300 lines):

diff -r bf02e4e7f282 -r 36eb1ca15906 sys/dev/acpi/files.acpi
--- a/sys/dev/acpi/files.acpi   Thu Apr 08 11:51:13 2010 +0000
+++ b/sys/dev/acpi/files.acpi   Thu Apr 08 12:14:19 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.acpi,v 1.69 2010/04/08 09:36:03 jruoho Exp $
+#      $NetBSD: files.acpi,v 1.70 2010/04/08 12:14:19 jruoho Exp $
 
 include "dev/acpi/acpica/files.acpica"
 
@@ -9,7 +9,6 @@
 define acpiapmbus { }
 define acpinodebus { }
 define acpiecdtbus { }
-define acpiwmibus { }
 
 device acpi: acpica, acpiapmbus, acpinodebus, acpiecdtbus, sysmon_power, sysmon_taskq
 attach acpi at acpibus
@@ -146,11 +145,6 @@
 attach wb at acpinodebus with wb_acpi
 file   dev/acpi/wb_acpi.c              wb_acpi
 
-# ACPI-WMI Mapper
-device acpiwmi: acpiwmibus
-attach acpiwmi at acpinodebus
-file   dev/acpi/wmi_acpi.c             acpiwmi
-
 # ASUSTeK AI Booster ATK0110
 device aibs: sysmon_envsys
 attach aibs at acpinodebus
diff -r bf02e4e7f282 -r 36eb1ca15906 sys/dev/acpi/wmi/files.wmi
--- a/sys/dev/acpi/wmi/files.wmi        Thu Apr 08 11:51:13 2010 +0000
+++ b/sys/dev/acpi/wmi/files.wmi        Thu Apr 08 12:14:19 2010 +0000
@@ -1,4 +1,11 @@
-#      $NetBSD: files.wmi,v 1.1 2010/04/08 09:35:15 jruoho Exp $
+#      $NetBSD: files.wmi,v 1.2 2010/04/08 12:14:19 jruoho Exp $
+
+define acpiwmibus { }
+
+# ACPI WMI mapper
+device acpiwmi: acpiwmibus
+attach acpiwmi at acpinodebus
+file   dev/acpi/wmi/wmi_acpi.c         acpiwmi
 
 # Dell WMI mappings
 device wmidell: sysmon_power
diff -r bf02e4e7f282 -r 36eb1ca15906 sys/dev/acpi/wmi/wmi_acpi.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/acpi/wmi/wmi_acpi.c       Thu Apr 08 12:14:19 2010 +0000
@@ -0,0 +1,789 @@
+/*     $NetBSD: wmi_acpi.c,v 1.1 2010/04/08 12:14:19 jruoho Exp $      */
+
+/*-
+ * Copyright (c) 2009, 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: wmi_acpi.c,v 1.1 2010/04/08 12:14:19 jruoho Exp $");
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/endian.h>
+#include <sys/kmem.h>
+#include <sys/systm.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+#include <dev/acpi/wmi/wmi_acpivar.h>
+
+#define _COMPONENT          ACPI_RESOURCE_COMPONENT
+ACPI_MODULE_NAME            ("wmi_acpi")
+
+/*
+ * This implements something called "Microsoft Windows Management
+ * Instrumentation" (WMI). This subset of ACPI is desribed in:
+ *
+ * http://www.microsoft.com/whdc/system/pnppwr/wmi/wmi-acpi.mspx
+ *
+ * (Obtained on Thu Feb 12 18:21:44 EET 2009.)
+ */
+struct guid_t {
+
+       /*
+        * The GUID itself. The used format is the usual 32-16-16-64-bit
+        * representation. All except the fourth field are in native byte
+        * order. A 32-16-16-16-48-bit hexadecimal notation with hyphens
+        * is used for human-readable GUIDs.
+        */
+       struct {
+               uint32_t data1;
+               uint16_t data2;
+               uint16_t data3;
+               uint8_t  data4[8];
+       } __packed;
+
+       union {
+               char oid[2];            /* ACPI object ID. */
+
+               struct {
+                       uint8_t nid;    /* Notification value. */
+                       uint8_t res;    /* Reserved. */
+               } __packed;
+       } __packed;
+
+       uint8_t count;                  /* Number of instances. */
+       uint8_t flags;                  /* Additional flags. */
+
+} __packed;
+
+struct wmi_t {
+       struct guid_t         guid;
+       bool                  eevent;
+
+       SIMPLEQ_ENTRY(wmi_t)  wmi_link;
+};
+
+struct acpi_wmi_softc {
+       device_t              sc_dev;
+       device_t              sc_child;
+        ACPI_NOTIFY_HANDLER   sc_handler;
+       struct acpi_devnode  *sc_node;
+
+       SIMPLEQ_HEAD(, wmi_t) wmi_head;
+};
+
+#define ACPI_WMI_FLAG_EXPENSIVE 0x01
+#define ACPI_WMI_FLAG_METHOD    0x02
+#define ACPI_WMI_FLAG_STRING    0x04
+#define ACPI_WMI_FLAG_EVENT     0x08
+#define ACPI_WMI_FLAG_DATA      (ACPI_WMI_FLAG_EXPENSIVE |             \
+                                ACPI_WMI_FLAG_STRING)
+
+#define UGET16(x)   (*(uint16_t *)(x))
+#define UGET64(x)   (*(uint64_t *)(x))
+
+#define HEXCHAR(x)  (((x) >= '0' && (x) <= '9') ||                     \
+                    ((x) >= 'a' && (x) <= 'f') ||                      \
+                    ((x) >= 'A' && (x) <= 'F'))
+
+#define GUIDCMP(a, b)                                                  \
+       ((a)->data1 == (b)->data1 &&                                    \
+        (a)->data2 == (b)->data2 &&                                    \
+        (a)->data3 == (b)->data3 &&                                    \
+        UGET64((a)->data4) == UGET64((b)->data4))
+
+static int         acpi_wmi_match(device_t, cfdata_t, void *);
+static void        acpi_wmi_attach(device_t, device_t, void *);
+static int         acpi_wmi_detach(device_t, int);
+static int         acpi_wmi_print(void *, const char *);
+static bool        acpi_wmi_init(struct acpi_wmi_softc *);
+static bool        acpi_wmi_add(struct acpi_wmi_softc *, ACPI_OBJECT *);
+static void        acpi_wmi_del(struct acpi_wmi_softc *);
+
+#ifdef ACPIVERBOSE
+static void        acpi_wmi_dump(struct acpi_wmi_softc *);
+#endif
+
+static ACPI_STATUS acpi_wmi_guid_get(struct acpi_wmi_softc *,
+                                     const char *, struct wmi_t **);
+static ACPI_STATUS acpi_wmi_event_add(struct acpi_wmi_softc *);
+static ACPI_STATUS acpi_wmi_event_del(struct acpi_wmi_softc *);
+static void        acpi_wmi_event_handler(ACPI_HANDLE, uint32_t, void *);
+static bool        acpi_wmi_suspend(device_t, const pmf_qual_t *);
+static bool        acpi_wmi_resume(device_t, const pmf_qual_t *);
+static ACPI_STATUS acpi_wmi_enable(ACPI_HANDLE, const char *, bool, bool);
+static bool        acpi_wmi_input(struct wmi_t *, uint8_t, uint8_t);
+
+const char * const acpi_wmi_ids[] = {
+       "PNP0C14",
+       NULL
+};
+
+CFATTACH_DECL_NEW(acpiwmi, sizeof(struct acpi_wmi_softc),
+    acpi_wmi_match, acpi_wmi_attach, acpi_wmi_detach, NULL);
+
+static int
+acpi_wmi_match(device_t parent, cfdata_t match, void *aux)
+{
+       struct acpi_attach_args *aa = aux;
+
+       if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
+               return 0;
+
+       return acpi_match_hid(aa->aa_node->ad_devinfo, acpi_wmi_ids);
+}
+
+static void
+acpi_wmi_attach(device_t parent, device_t self, void *aux)
+{
+       struct acpi_wmi_softc *sc = device_private(self);
+       struct acpi_attach_args *aa = aux;
+
+       sc->sc_dev = self;
+       sc->sc_node = aa->aa_node;
+
+       sc->sc_child = NULL;
+       sc->sc_handler = NULL;
+
+       aprint_naive("\n");
+       aprint_normal(": ACPI WMI Interface\n");
+
+       if (acpi_wmi_init(sc) != true)
+               return;
+
+#ifdef ACPIVERBOSE
+       acpi_wmi_dump(sc);
+#endif
+
+       (void)acpi_wmi_event_add(sc);
+       (void)pmf_device_register(self, acpi_wmi_suspend, acpi_wmi_resume);
+
+       sc->sc_child = config_found_ia(self, "acpiwmibus",
+           NULL, acpi_wmi_print);
+}
+
+static int
+acpi_wmi_detach(device_t self, int flags)
+{
+       struct acpi_wmi_softc *sc = device_private(self);
+       ACPI_STATUS rv;
+
+       rv = acpi_wmi_event_del(sc);
+
+       if (ACPI_FAILURE(rv))
+               return EBUSY;
+
+       if (sc->sc_child != NULL)
+               (void)config_detach(sc->sc_child, flags);
+
+       acpi_wmi_del(sc);
+       pmf_device_deregister(self);
+
+       return 0;
+}
+
+static int
+acpi_wmi_print(void *aux, const char *pnp)
+{
+
+       if (pnp != NULL)
+               aprint_normal("acpiwmibus at %s", pnp);
+
+       return UNCONF;
+}
+
+static bool
+acpi_wmi_init(struct acpi_wmi_softc *sc)
+{
+       ACPI_OBJECT *obj;
+       ACPI_BUFFER buf;
+       ACPI_STATUS rv;
+       uint32_t len;
+
+       rv = acpi_eval_struct(sc->sc_node->ad_handle, "_WDG", &buf);
+
+       if (ACPI_FAILURE(rv))
+               goto fail;
+
+       obj = buf.Pointer;
+
+       if (obj->Type != ACPI_TYPE_BUFFER) {
+               rv = AE_TYPE;
+               goto fail;
+       }
+
+       len = obj->Buffer.Length;
+
+       if (len != obj->Package.Count) {
+               rv = AE_BAD_VALUE;
+               goto fail;
+       }
+
+       CTASSERT(sizeof(struct guid_t) == 20);
+
+       if (len < sizeof(struct guid_t) ||
+           len % sizeof(struct guid_t) != 0) {
+               rv = AE_BAD_DATA;
+               goto fail;
+       }



Home | Main Index | Thread Index | Old Index