Sun Dec 29 13:45:11 2019 UTC ()
Add support for reading _DSD string property values.


(jmcneill)
diff -r1.16 -r1.17 src/sys/dev/acpi/acpi_util.c
diff -r1.7 -r1.8 src/sys/dev/acpi/acpi_util.h

cvs diff -r1.16 -r1.17 src/sys/dev/acpi/acpi_util.c (expand / switch to unified diff)

--- src/sys/dev/acpi/acpi_util.c 2019/12/22 15:57:07 1.16
+++ src/sys/dev/acpi/acpi_util.c 2019/12/29 13:45:11 1.17
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: acpi_util.c,v 1.16 2019/12/22 15:57:07 thorpej Exp $ */ 1/* $NetBSD: acpi_util.c,v 1.17 2019/12/29 13:45:11 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum of By Noon Software, Inc. 8 * by Charles M. Hannum of By Noon Software, Inc.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -55,27 +55,27 @@ @@ -55,27 +55,27 @@
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 56 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 57 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
58 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 58 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 59 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 * POSSIBILITY OF SUCH DAMAGE. 64 * POSSIBILITY OF SUCH DAMAGE.
65 */ 65 */
66 66
67#include <sys/cdefs.h> 67#include <sys/cdefs.h>
68__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.16 2019/12/22 15:57:07 thorpej Exp $"); 68__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.17 2019/12/29 13:45:11 jmcneill Exp $");
69 69
70#include <sys/param.h> 70#include <sys/param.h>
71#include <sys/kmem.h> 71#include <sys/kmem.h>
72#include <sys/cpu.h> 72#include <sys/cpu.h>
73 73
74#include <dev/acpi/acpireg.h> 74#include <dev/acpi/acpireg.h>
75#include <dev/acpi/acpivar.h> 75#include <dev/acpi/acpivar.h>
76#include <dev/acpi/acpi_intr.h> 76#include <dev/acpi/acpi_intr.h>
77 77
78#include <machine/acpi_machdep.h> 78#include <machine/acpi_machdep.h>
79 79
80#define _COMPONENT ACPI_BUS_COMPONENT 80#define _COMPONENT ACPI_BUS_COMPONENT
81ACPI_MODULE_NAME ("acpi_util") 81ACPI_MODULE_NAME ("acpi_util")
@@ -623,67 +623,95 @@ acpi_intr_string(void *c, char *buf, siz @@ -623,67 +623,95 @@ acpi_intr_string(void *c, char *buf, siz
623 623
624 return intr_string(ih, buf, size); 624 return intr_string(ih, buf, size);
625} 625}
626 626
627/* 627/*
628 * USB Device-Specific Data (_DSD) support 628 * USB Device-Specific Data (_DSD) support
629 */ 629 */
630 630
631static UINT8 acpi_dsd_uuid[ACPI_UUID_LENGTH] = { 631static UINT8 acpi_dsd_uuid[ACPI_UUID_LENGTH] = {
632 0x14, 0xd8, 0xff, 0xda, 0xba, 0x6e, 0x8c, 0x4d, 632 0x14, 0xd8, 0xff, 0xda, 0xba, 0x6e, 0x8c, 0x4d,
633 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01 633 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01
634}; 634};
635 635
636ACPI_STATUS 636static ACPI_STATUS
637acpi_dsd_integer(ACPI_HANDLE handle, const char *prop, ACPI_INTEGER *val) 637acpi_dsd_property(ACPI_HANDLE handle, const char *prop, ACPI_BUFFER *pbuf, ACPI_OBJECT_TYPE type, ACPI_OBJECT **ret)
638{ 638{
639 ACPI_OBJECT *obj, *uuid, *props, *pobj, *propkey, *propval; 639 ACPI_OBJECT *obj, *uuid, *props, *pobj, *propkey, *propval;
640 ACPI_STATUS rv; 640 ACPI_STATUS rv;
641 ACPI_BUFFER buf; 
642 int n; 641 int n;
643 642
644 buf.Pointer = NULL; 643 rv = AcpiEvaluateObjectTyped(handle, "_DSD", NULL, pbuf, ACPI_TYPE_PACKAGE);
645 buf.Length = ACPI_ALLOCATE_BUFFER; 
646 
647 rv = AcpiEvaluateObjectTyped(handle, "_DSD", NULL, &buf, ACPI_TYPE_PACKAGE); 
648 if (ACPI_FAILURE(rv)) 644 if (ACPI_FAILURE(rv))
649 return rv; 645 return rv;
650 646
651 props = NULL; 647 props = NULL;
652 obj = (ACPI_OBJECT *)buf.Pointer; 648 obj = (ACPI_OBJECT *)pbuf->Pointer;
653 for (n = 0; (n + 1) < obj->Package.Count; n += 2) { 649 for (n = 0; (n + 1) < obj->Package.Count; n += 2) {
654 uuid = &obj->Package.Elements[n]; 650 uuid = &obj->Package.Elements[n];
655 if (uuid->Buffer.Length == ACPI_UUID_LENGTH && 651 if (uuid->Buffer.Length == ACPI_UUID_LENGTH &&
656 memcmp(uuid->Buffer.Pointer, acpi_dsd_uuid, ACPI_UUID_LENGTH) == 0) { 652 memcmp(uuid->Buffer.Pointer, acpi_dsd_uuid, ACPI_UUID_LENGTH) == 0) {
657 props = &obj->Package.Elements[n + 1]; 653 props = &obj->Package.Elements[n + 1];
658 break; 654 break;
659 } 655 }
660 } 656 }
661 if (props == NULL) { 657 if (props == NULL)
662 rv = AE_NOT_FOUND; 658 return AE_NOT_FOUND;
663 goto done; 
664 } 
665 659
666 for (n = 0; n < props->Package.Count; n++) { 660 for (n = 0; n < props->Package.Count; n++) {
667 pobj = &props->Package.Elements[n]; 661 pobj = &props->Package.Elements[n];
668 if (pobj->Type != ACPI_TYPE_PACKAGE || pobj->Package.Count != 2) 662 if (pobj->Type != ACPI_TYPE_PACKAGE || pobj->Package.Count != 2)
669 continue; 663 continue;
670 propkey = (ACPI_OBJECT *)&pobj->Package.Elements[0]; 664 propkey = (ACPI_OBJECT *)&pobj->Package.Elements[0];
671 propval = (ACPI_OBJECT *)&pobj->Package.Elements[1]; 665 propval = (ACPI_OBJECT *)&pobj->Package.Elements[1];
672 if (propkey->Type != ACPI_TYPE_STRING) 666 if (propkey->Type != ACPI_TYPE_STRING)
673 continue; 667 continue;
674 if (strcmp(propkey->String.Pointer, prop) != 0) 668 if (strcmp(propkey->String.Pointer, prop) != 0)
675 continue; 669 continue;
676 670
677 if (propval->Type != ACPI_TYPE_INTEGER) { 671 if (propval->Type != type) {
678 rv = AE_TYPE; 672 return AE_TYPE;
679 } else { 673 } else {
680 *val = propval->Integer.Value; 674 *ret = propval;
681 rv = AE_OK; 675 return AE_OK;
682 } 676 }
683 break; 677 break;
684 } 678 }
685 679
686done: 680 return AE_NOT_FOUND;
 681}
 682
 683ACPI_STATUS
 684acpi_dsd_integer(ACPI_HANDLE handle, const char *prop, ACPI_INTEGER *val)
 685{
 686 ACPI_OBJECT *propval;
 687 ACPI_STATUS rv;
 688 ACPI_BUFFER buf;
 689
 690 buf.Pointer = NULL;
 691 buf.Length = ACPI_ALLOCATE_BUFFER;
 692
 693 rv = acpi_dsd_property(handle, prop, &buf, ACPI_TYPE_INTEGER, &propval);
 694 if (ACPI_SUCCESS(rv))
 695 *val = propval->Integer.Value;
 696
 697 ACPI_FREE(buf.Pointer);
 698 return rv;
 699}
 700
 701ACPI_STATUS
 702acpi_dsd_string(ACPI_HANDLE handle, const char *prop, char **val)
 703{
 704 ACPI_OBJECT *propval;
 705 ACPI_STATUS rv;
 706 ACPI_BUFFER buf;
 707
 708 buf.Pointer = NULL;
 709 buf.Length = ACPI_ALLOCATE_BUFFER;
 710
 711 rv = acpi_dsd_property(handle, prop, &buf, ACPI_TYPE_STRING, &propval);
 712 if (ACPI_SUCCESS(rv))
 713 *val = kmem_strdup(propval->String.Pointer, KM_SLEEP);
 714
687 ACPI_FREE(buf.Pointer); 715 ACPI_FREE(buf.Pointer);
688 return rv; 716 return rv;
689} 717}

cvs diff -r1.7 -r1.8 src/sys/dev/acpi/acpi_util.h (expand / switch to unified diff)

--- src/sys/dev/acpi/acpi_util.h 2018/12/21 14:51:12 1.7
+++ src/sys/dev/acpi/acpi_util.h 2019/12/29 13:45:11 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: acpi_util.h,v 1.7 2018/12/21 14:51:12 jmcneill Exp $ */ 1/* $NetBSD: acpi_util.h,v 1.8 2019/12/29 13:45:11 jmcneill Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum of By Noon Software, Inc. 8 * by Charles M. Hannum of By Noon Software, Inc.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -79,15 +79,16 @@ ACPI_STATUS acpi_foreach_package_object( @@ -79,15 +79,16 @@ ACPI_STATUS acpi_foreach_package_object(
79ACPI_STATUS acpi_get(ACPI_HANDLE, ACPI_BUFFER *, 79ACPI_STATUS acpi_get(ACPI_HANDLE, ACPI_BUFFER *,
80 ACPI_STATUS (*)(ACPI_HANDLE, ACPI_BUFFER *)); 80 ACPI_STATUS (*)(ACPI_HANDLE, ACPI_BUFFER *));
81 81
82struct acpi_devnode *acpi_match_node(ACPI_HANDLE handle); 82struct acpi_devnode *acpi_match_node(ACPI_HANDLE handle);
83void acpi_match_node_init(struct acpi_devnode *ad); 83void acpi_match_node_init(struct acpi_devnode *ad);
84 84
85const char *acpi_name(ACPI_HANDLE); 85const char *acpi_name(ACPI_HANDLE);
86int acpi_match_hid(ACPI_DEVICE_INFO *, const char * const *); 86int acpi_match_hid(ACPI_DEVICE_INFO *, const char * const *);
87int acpi_match_class(ACPI_HANDLE, uint8_t, uint8_t, uint8_t); 87int acpi_match_class(ACPI_HANDLE, uint8_t, uint8_t, uint8_t);
88ACPI_HANDLE acpi_match_cpu_info(struct cpu_info *); 88ACPI_HANDLE acpi_match_cpu_info(struct cpu_info *);
89struct cpu_info *acpi_match_cpu_handle(ACPI_HANDLE); 89struct cpu_info *acpi_match_cpu_handle(ACPI_HANDLE);
90 90
91ACPI_STATUS acpi_dsd_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *); 91ACPI_STATUS acpi_dsd_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *);
 92ACPI_STATUS acpi_dsd_string(ACPI_HANDLE, const char *, char **);
92 93
93#endif /* !_SYS_DEV_ACPI_ACPI_UTIL_H */ 94#endif /* !_SYS_DEV_ACPI_ACPI_UTIL_H */