Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi Add support for reading _DSD string property va...



details:   https://anonhg.NetBSD.org/src/rev/5e17483e886c
branches:  trunk
changeset: 967956:5e17483e886c
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Dec 29 13:45:11 2019 +0000

description:
Add support for reading _DSD string property values.

diffstat:

 sys/dev/acpi/acpi_util.c |  66 ++++++++++++++++++++++++++++++++++-------------
 sys/dev/acpi/acpi_util.h |   3 +-
 2 files changed, 49 insertions(+), 20 deletions(-)

diffs (131 lines):

diff -r 150d82d80748 -r 5e17483e886c sys/dev/acpi/acpi_util.c
--- a/sys/dev/acpi/acpi_util.c  Sun Dec 29 12:49:03 2019 +0000
+++ b/sys/dev/acpi/acpi_util.c  Sun Dec 29 13:45:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_util.c,v 1.16 2019/12/22 15:57:07 thorpej Exp $ */
+/*     $NetBSD: acpi_util.c,v 1.17 2019/12/29 13:45:11 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.16 2019/12/22 15:57:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.17 2019/12/29 13:45:11 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -633,23 +633,19 @@
        0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01
 };
 
-ACPI_STATUS
-acpi_dsd_integer(ACPI_HANDLE handle, const char *prop, ACPI_INTEGER *val)
+static ACPI_STATUS
+acpi_dsd_property(ACPI_HANDLE handle, const char *prop, ACPI_BUFFER *pbuf, ACPI_OBJECT_TYPE type, ACPI_OBJECT **ret)
 {
        ACPI_OBJECT *obj, *uuid, *props, *pobj, *propkey, *propval;
        ACPI_STATUS rv;
-       ACPI_BUFFER buf;
        int n;
 
-       buf.Pointer = NULL;
-       buf.Length = ACPI_ALLOCATE_BUFFER;
-
-       rv = AcpiEvaluateObjectTyped(handle, "_DSD", NULL, &buf, ACPI_TYPE_PACKAGE);
+       rv = AcpiEvaluateObjectTyped(handle, "_DSD", NULL, pbuf, ACPI_TYPE_PACKAGE);
        if (ACPI_FAILURE(rv))
                return rv;
 
        props = NULL;
-       obj = (ACPI_OBJECT *)buf.Pointer;
+       obj = (ACPI_OBJECT *)pbuf->Pointer;
        for (n = 0; (n + 1) < obj->Package.Count; n += 2) {
                uuid = &obj->Package.Elements[n];
                if (uuid->Buffer.Length == ACPI_UUID_LENGTH &&
@@ -658,10 +654,8 @@
                        break;
                }
        }
-       if (props == NULL) {
-               rv = AE_NOT_FOUND;
-               goto done;
-       }
+       if (props == NULL)
+               return AE_NOT_FOUND;
 
        for (n = 0; n < props->Package.Count; n++) {
                pobj = &props->Package.Elements[n];
@@ -674,16 +668,50 @@
                if (strcmp(propkey->String.Pointer, prop) != 0)
                        continue;
 
-               if (propval->Type != ACPI_TYPE_INTEGER) {
-                       rv = AE_TYPE;
+               if (propval->Type != type) {
+                       return AE_TYPE;
                } else {
-                       *val = propval->Integer.Value;
-                       rv = AE_OK;
+                       *ret = propval;
+                       return AE_OK;
                }
                break;
        }
 
-done:
+       return AE_NOT_FOUND;
+}
+
+ACPI_STATUS
+acpi_dsd_integer(ACPI_HANDLE handle, const char *prop, ACPI_INTEGER *val)
+{
+       ACPI_OBJECT *propval;
+       ACPI_STATUS rv;
+       ACPI_BUFFER buf;
+
+       buf.Pointer = NULL;
+       buf.Length = ACPI_ALLOCATE_BUFFER;
+
+       rv = acpi_dsd_property(handle, prop, &buf, ACPI_TYPE_INTEGER, &propval);
+       if (ACPI_SUCCESS(rv))
+               *val = propval->Integer.Value;
+
        ACPI_FREE(buf.Pointer);
        return rv;
 }
+
+ACPI_STATUS
+acpi_dsd_string(ACPI_HANDLE handle, const char *prop, char **val)
+{
+       ACPI_OBJECT *propval;
+       ACPI_STATUS rv;
+       ACPI_BUFFER buf;
+
+       buf.Pointer = NULL;
+       buf.Length = ACPI_ALLOCATE_BUFFER;
+
+       rv = acpi_dsd_property(handle, prop, &buf, ACPI_TYPE_STRING, &propval);
+       if (ACPI_SUCCESS(rv))
+               *val = kmem_strdup(propval->String.Pointer, KM_SLEEP);
+
+       ACPI_FREE(buf.Pointer);
+       return rv;
+}
diff -r 150d82d80748 -r 5e17483e886c sys/dev/acpi/acpi_util.h
--- a/sys/dev/acpi/acpi_util.h  Sun Dec 29 12:49:03 2019 +0000
+++ b/sys/dev/acpi/acpi_util.h  Sun Dec 29 13:45:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_util.h,v 1.7 2018/12/21 14:51:12 jmcneill Exp $ */
+/*     $NetBSD: acpi_util.h,v 1.8 2019/12/29 13:45:11 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -89,5 +89,6 @@
 struct cpu_info *acpi_match_cpu_handle(ACPI_HANDLE);
 
 ACPI_STATUS     acpi_dsd_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *);
+ACPI_STATUS     acpi_dsd_string(ACPI_HANDLE, const char *, char **);
 
 #endif /* !_SYS_DEV_ACPI_ACPI_UTIL_H */



Home | Main Index | Thread Index | Old Index