| @@ -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 |
81 | ACPI_MODULE_NAME ("acpi_util") | | 81 | ACPI_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 | |
631 | static UINT8 acpi_dsd_uuid[ACPI_UUID_LENGTH] = { | | 631 | static 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 | |
636 | ACPI_STATUS | | 636 | static ACPI_STATUS |
637 | acpi_dsd_integer(ACPI_HANDLE handle, const char *prop, ACPI_INTEGER *val) | | 637 | acpi_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 | |
686 | done: | | 680 | return AE_NOT_FOUND; |
| | | 681 | } |
| | | 682 | |
| | | 683 | ACPI_STATUS |
| | | 684 | acpi_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 | |
| | | 701 | ACPI_STATUS |
| | | 702 | acpi_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 | } |