Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi - Handle dtlink in acpi_pack_compat_list().



details:   https://anonhg.NetBSD.org/src/rev/b24d6fdf4fd7
branches:  trunk
changeset: 368637:b24d6fdf4fd7
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Jul 23 03:08:17 2022 +0000

description:
- Handle dtlink in acpi_pack_compat_list().
- Don't pass the _HID value as the device name; always use the ACPI
  node name.

diffstat:

 sys/dev/acpi/acpi_i2c.c  |  13 ++-----
 sys/dev/acpi/acpi_util.c |  76 +++++++++++++++++++++++++++++++++++++++++------
 sys/dev/acpi/acpi_util.h |   4 +-
 3 files changed, 72 insertions(+), 21 deletions(-)

diffs (173 lines):

diff -r 0205af51084a -r b24d6fdf4fd7 sys/dev/acpi/acpi_i2c.c
--- a/sys/dev/acpi/acpi_i2c.c   Sat Jul 23 03:05:27 2022 +0000
+++ b/sys/dev/acpi/acpi_i2c.c   Sat Jul 23 03:08:17 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_i2c.c,v 1.11 2021/01/26 01:23:08 thorpej Exp $ */
+/* $NetBSD: acpi_i2c.c,v 1.12 2022/07/23 03:08:17 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2017, 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.11 2021/01/26 01:23:08 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.12 2022/07/23 03:08:17 thorpej Exp $");
 
 #include <dev/acpi/acpireg.h>
 #include <dev/acpi/acpivar.h>
@@ -75,7 +75,6 @@
        prop_dictionary_t dev;
        struct acpi_i2c_context i2cc;
        ACPI_STATUS rv;
-       const char *name;
        char *clist;
        size_t clist_size;
 
@@ -96,18 +95,14 @@
                    ad->ad_name);
                return;
        }
-       clist = acpi_pack_compat_list(ad->ad_devinfo, &clist_size);
+       clist = acpi_pack_compat_list(ad, &clist_size);
        if (clist == NULL) {
                prop_object_release(dev);
                aprint_error("ignoring device %s (no _HID or _CID)\n",
                    ad->ad_name);
                return;
        }
-       if ((ad->ad_devinfo->Valid & ACPI_VALID_HID) == 0)
-               name = ad->ad_name;
-       else
-               name = ad->ad_devinfo->HardwareId.String;
-       prop_dictionary_set_string(dev, "name", name);
+       prop_dictionary_set_string(dev, "name", ad->ad_name);
        prop_dictionary_set_uint32(dev, "addr", i2cc.i2c_addr);
        prop_dictionary_set_uint64(dev, "cookie", (uintptr_t)ad->ad_handle);
        prop_dictionary_set_uint32(dev, "cookietype", I2C_COOKIE_ACPI);
diff -r 0205af51084a -r b24d6fdf4fd7 sys/dev/acpi/acpi_util.c
--- a/sys/dev/acpi/acpi_util.c  Sat Jul 23 03:05:27 2022 +0000
+++ b/sys/dev/acpi/acpi_util.c  Sat Jul 23 03:08:17 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_util.c,v 1.32 2022/01/22 11:49:17 thorpej Exp $ */
+/*     $NetBSD: acpi_util.c,v 1.33 2022/07/23 03:08:17 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007, 2021 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.32 2022/01/22 11:49:17 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.33 2022/07/23 03:08:17 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -395,25 +395,81 @@
  * string list.
  */
 char *
-acpi_pack_compat_list(ACPI_DEVICE_INFO *ad, size_t *sizep)
+acpi_pack_compat_list(struct acpi_devnode *ad, size_t *sizep)
 {
+       ACPI_DEVICE_INFO *devinfo = ad->ad_devinfo;
+
        KASSERT(sizep != NULL);
 
        char *sl = NULL;
        size_t slsize = 0;
        uint32_t i;
+       bool dtlink = false;
 
-       if ((ad->Valid & ACPI_VALID_HID) != 0) {
-               strlist_append(&sl, &slsize, ad->HardwareId.String);
-       }
+       ACPI_BUFFER buf;
+       ACPI_STATUS ret;
+       ACPI_OBJECT *obj;
+       char *compatible;
+       int n;
 
-       if ((ad->Valid & ACPI_VALID_CID) != 0) {
-               for (i = 0; i < ad->CompatibleIdList.Count; i++) {
-                       strlist_append(&sl, &slsize,
-                           ad->CompatibleIdList.Ids[i].String);
+       buf.Pointer = NULL;
+       buf.Length = ACPI_ALLOCATE_BUFFER;
+
+       if ((devinfo->Valid & ACPI_VALID_HID) != 0) {
+               const char *cp = devinfo->HardwareId.String;
+
+               if (device_compatible_pmatch_strlist(cp, strlen(cp) + 1,
+                                                    dtlink_compat_data)) {
+                       dtlink = true;
+               } else {
+                       strlist_append(&sl, &slsize, cp);
                }
        }
 
+       if ((devinfo->Valid & ACPI_VALID_CID) != 0) {
+               for (i = 0; i < devinfo->CompatibleIdList.Count; i++) {
+                       const char *cp =
+                           devinfo->CompatibleIdList.Ids[i].String;
+
+                       if (device_compatible_pmatch_strlist(cp, strlen(cp) + 1,
+                                                       dtlink_compat_data)) {
+                               dtlink = true;
+                       } else {
+                               strlist_append(&sl, &slsize, cp);
+                       }
+               }
+       }
+
+       if (dtlink) {
+               ret = acpi_dsd_string(ad->ad_handle, "compatible",
+                   &compatible);
+               if (ACPI_SUCCESS(ret)) {
+                       strlist_append(&sl, &slsize, compatible);
+                       kmem_strfree(compatible);
+                       goto done;
+               }
+
+               ret = acpi_dsd_property(ad->ad_handle, "compatible", &buf,
+                   ACPI_TYPE_PACKAGE, &obj);
+               if (ACPI_FAILURE(ret)) {
+                       goto done;
+               }
+               if (obj->Package.Count == 0) {
+                       goto done;
+               }
+               for (n = 0; n < obj->Package.Count; n++) {
+                       if (obj->Package.Elements[n].Type != ACPI_TYPE_STRING) {
+                               continue;
+                       }
+                       strlist_append(&sl, &slsize,
+                           obj->Package.Elements[n].String.Pointer);
+               }
+       }
+
+ done:
+       if (buf.Pointer != NULL) {
+               ACPI_FREE(buf.Pointer);
+       }
        *sizep = slsize;
        return sl;
 }
diff -r 0205af51084a -r b24d6fdf4fd7 sys/dev/acpi/acpi_util.h
--- a/sys/dev/acpi/acpi_util.h  Sat Jul 23 03:05:27 2022 +0000
+++ b/sys/dev/acpi/acpi_util.h  Sat Jul 23 03:08:17 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_util.h,v 1.14 2022/01/22 11:49:17 thorpej Exp $ */
+/*     $NetBSD: acpi_util.h,v 1.15 2022/07/23 03:08:17 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -94,7 +94,7 @@
 ACPI_HANDLE     acpi_match_cpu_info(struct cpu_info *);
 struct cpu_info *acpi_match_cpu_handle(ACPI_HANDLE);
 
-char           *acpi_pack_compat_list(ACPI_DEVICE_INFO *, size_t *);
+char           *acpi_pack_compat_list(struct acpi_devnode *ad, size_t *);
 
 ACPI_STATUS     acpi_dsd_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *);
 ACPI_STATUS     acpi_dsd_string(ACPI_HANDLE, const char *, char **);



Home | Main Index | Thread Index | Old Index