Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi acpi: Support DT link device ID



details:   https://anonhg.NetBSD.org/src/rev/f4581b9ffe27
branches:  trunk
changeset: 1029189:f4581b9ffe27
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Dec 26 14:34:39 2021 +0000

description:
acpi: Support DT link device ID

The PRP0001 device ID is used to tell the OS to match a driver against
the "compatible" _DSD property. Make acpi_compatible_match aware of this
special device ID and match device compatible entries against the
compatible property when applicable.

diffstat:

 sys/dev/acpi/acpi_util.c |  46 +++++++++++++++++++++++++++++++++++++++-------
 sys/dev/acpi/acpivar.h   |   6 ++++--
 2 files changed, 43 insertions(+), 9 deletions(-)

diffs (113 lines):

diff -r df0059768527 -r f4581b9ffe27 sys/dev/acpi/acpi_util.c
--- a/sys/dev/acpi/acpi_util.c  Sun Dec 26 08:41:29 2021 +0000
+++ b/sys/dev/acpi/acpi_util.c  Sun Dec 26 14:34:39 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_util.c,v 1.27 2021/12/20 11:17:40 skrll Exp $ */
+/*     $NetBSD: acpi_util.c,v 1.28 2021/12/26 14:34:39 jmcneill 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.27 2021/12/20 11:17:40 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.28 2021/12/26 14:34:39 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -89,6 +89,11 @@
        NULL
 };
 
+static const struct device_compatible_entry dtlink_compat_data[] = {
+       { .compat = "PRP0001" },
+       DEVICE_COMPAT_EOL
+};
+
 /*
  * ACPI device handle support.
  */
@@ -445,6 +450,9 @@
 {
        const char *strings[ACPI_COMPATSTR_MAX * sizeof(const char *)];
        const char **cpp;
+       bool dtlink = false;
+       ACPI_STATUS ret;
+       int rv;
 
        if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) {
                return 0;
@@ -459,23 +467,47 @@
                if (device_compatible_pmatch(strings, 1, dce) != 0) {
                        return ACPI_MATCHSCORE_HID;
                }
+
+               if (device_compatible_pmatch(strings, 1,
+                                            dtlink_compat_data) != 0) {
+                       dtlink = true;
+               }
        }
 
        if ((ad->Valid & ACPI_VALID_CID) != 0) {
                cpp = acpi_compatible_alloc_strarray(ad->CompatibleIdList.Ids,
                    ad->CompatibleIdList.Count, strings);
-               int rv;
 
                rv = device_compatible_pmatch(cpp,
                    ad->CompatibleIdList.Count, dce);
+               if (!dtlink &&
+                   device_compatible_pmatch(cpp, ad->CompatibleIdList.Count,
+                                            dtlink_compat_data) != 0) {
+                       dtlink = true;
+               }
                acpi_compatible_free_strarray(cpp, ad->CompatibleIdList.Count,
                    strings);
                if (rv) {
                        rv = (rv - 1) + ACPI_MATCHSCORE_CID;
-                       if (rv > ACPI_MATCHSCORE_CID_MAX) {
-                               rv = ACPI_MATCHSCORE_CID_MAX;
-                       }
-                       return rv;
+                       return imin(rv, ACPI_MATCHSCORE_CID_MAX);
+               }
+       }
+
+       if (dtlink) {
+               char *compatible;
+
+               ret = acpi_dsd_string(aa->aa_node->ad_handle,
+                   "compatible", &compatible);
+               if (ACPI_FAILURE(ret)) {
+                       return 0;
+               }
+
+               strings[0] = compatible;
+               rv = device_compatible_pmatch(strings, 1, dce);
+               kmem_strfree(compatible);
+               if (rv) {
+                       rv = (rv - 1) + ACPI_MATCHSCORE_CID;
+                       return imin(rv, ACPI_MATCHSCORE_CID_MAX);
                }
        }
 
diff -r df0059768527 -r f4581b9ffe27 sys/dev/acpi/acpivar.h
--- a/sys/dev/acpi/acpivar.h    Sun Dec 26 08:41:29 2021 +0000
+++ b/sys/dev/acpi/acpivar.h    Sun Dec 26 14:34:39 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpivar.h,v 1.88 2021/12/20 11:17:40 skrll Exp $       */
+/*     $NetBSD: acpivar.h,v 1.89 2021/12/26 14:34:39 jmcneill Exp $    */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -198,7 +198,9 @@
 /* ACPI driver matching scores. */
 #define        ACPI_MATCHSCORE_HID             100     /* matched _HID */
 #define        ACPI_MATCHSCORE_CID_MAX         49
-#define        ACPI_MATCHSCORE_CID             10      /* matched _CID */
+#define        ACPI_MATCHSCORE_CID             10      /* matched _CID or _DSD
+                                                * "compatible"
+                                                */
 #define        ACPI_MATCHSCORE_CLS             1       /* matched _CLS */
 
 /*



Home | Main Index | Thread Index | Old Index