Module Name: src Committed By: thorpej Date: Sat Jul 23 03:08:17 UTC 2022
Modified Files: src/sys/dev/acpi: acpi_i2c.c acpi_util.c acpi_util.h Log Message: - Handle dtlink in acpi_pack_compat_list(). - Don't pass the _HID value as the device name; always use the ACPI node name. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/dev/acpi/acpi_i2c.c cvs rdiff -u -r1.32 -r1.33 src/sys/dev/acpi/acpi_util.c cvs rdiff -u -r1.14 -r1.15 src/sys/dev/acpi/acpi_util.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/acpi/acpi_i2c.c diff -u src/sys/dev/acpi/acpi_i2c.c:1.11 src/sys/dev/acpi/acpi_i2c.c:1.12 --- src/sys/dev/acpi/acpi_i2c.c:1.11 Tue Jan 26 01:23:08 2021 +++ src/sys/dev/acpi/acpi_i2c.c Sat Jul 23 03:08:17 2022 @@ -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 @@ acpi_enter_i2c_device(struct acpi_devnod 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 @@ acpi_enter_i2c_device(struct acpi_devnod 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); Index: src/sys/dev/acpi/acpi_util.c diff -u src/sys/dev/acpi/acpi_util.c:1.32 src/sys/dev/acpi/acpi_util.c:1.33 --- src/sys/dev/acpi/acpi_util.c:1.32 Sat Jan 22 11:49:17 2022 +++ src/sys/dev/acpi/acpi_util.c Sat Jul 23 03:08:17 2022 @@ -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 @@ acpi_name(ACPI_HANDLE handle) * 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; + + 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 ((ad->Valid & ACPI_VALID_CID) != 0) { - for (i = 0; i < ad->CompatibleIdList.Count; i++) { + 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, - ad->CompatibleIdList.Ids[i].String); + obj->Package.Elements[n].String.Pointer); } } + done: + if (buf.Pointer != NULL) { + ACPI_FREE(buf.Pointer); + } *sizep = slsize; return sl; } Index: src/sys/dev/acpi/acpi_util.h diff -u src/sys/dev/acpi/acpi_util.h:1.14 src/sys/dev/acpi/acpi_util.h:1.15 --- src/sys/dev/acpi/acpi_util.h:1.14 Sat Jan 22 11:49:17 2022 +++ src/sys/dev/acpi/acpi_util.h Sat Jul 23 03:08:17 2022 @@ -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 @@ int acpi_match_class(ACPI_HANDLE, uint 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 **);