]> git.proxmox.com Git - mirror_edk2.git/blob - DynamicTablesPkg/Library/Common/AmlLib/ResourceData/AmlResourceData.c
DynamicTablesPkg: Apply uncrustify changes
[mirror_edk2.git] / DynamicTablesPkg / Library / Common / AmlLib / ResourceData / AmlResourceData.c
1 /** @file
2 AML Resource Data.
3
4 Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 @par Glossary:
9 - Rd or RD - Resource Data
10 - Rds or RDS - Resource Data Small
11 - Rdl or RDL - Resource Data Large
12 **/
13
14 #include <ResourceData/AmlResourceData.h>
15
16 /** Check whether the resource data has the input descriptor Id.
17
18 The small/large bit is included in the descriptor Id,
19 but the size bits are not included for small resource data elements.
20
21 @param [in] Header Pointer to the first byte of a resource data
22 element.
23 @param [in] DescriptorId The descriptor to check against.
24
25 @retval TRUE The resource data has the descriptor Id.
26 @retval FALSE Otherwise.
27 **/
28 BOOLEAN
29 EFIAPI
30 AmlRdCompareDescId (
31 IN CONST AML_RD_HEADER *Header,
32 IN AML_RD_HEADER DescriptorId
33 )
34 {
35 if (Header == NULL) {
36 ASSERT (0);
37 return FALSE;
38 }
39
40 if (AML_RD_IS_LARGE (Header)) {
41 return ((*Header ^ DescriptorId) == 0);
42 } else {
43 return (((*Header & AML_RD_SMALL_ID_MASK) ^ DescriptorId) == 0);
44 }
45 }
46
47 /** Get the descriptor Id of the resource data.
48
49 The small/large bit is included in the descriptor Id,
50 but the size bits are not included for small resource data elements.
51
52 @param [in] Header Pointer to the first byte of a resource data.
53
54 @return A descriptor Id.
55 **/
56 AML_RD_HEADER
57 EFIAPI
58 AmlRdGetDescId (
59 IN CONST AML_RD_HEADER *Header
60 )
61 {
62 if (Header == NULL) {
63 ASSERT (0);
64 return FALSE;
65 }
66
67 if (AML_RD_IS_LARGE (Header)) {
68 return *Header;
69 }
70
71 // Header is a small resource data element.
72 return *Header & AML_RD_SMALL_ID_MASK;
73 }
74
75 /** Get the size of a resource data element.
76
77 If the resource data element is of the large type, the Header
78 is expected to be at least 3 bytes long.
79
80 @param [in] Header Pointer to the first byte of a resource data.
81
82 @return The size of the resource data element.
83 **/
84 UINT32
85 EFIAPI
86 AmlRdGetSize (
87 IN CONST AML_RD_HEADER *Header
88 )
89 {
90 if (Header == NULL) {
91 ASSERT (0);
92 return FALSE;
93 }
94
95 if (AML_RD_IS_LARGE (Header)) {
96 return ((ACPI_LARGE_RESOURCE_HEADER *)Header)->Length +
97 sizeof (ACPI_LARGE_RESOURCE_HEADER);
98 }
99
100 // Header is a small resource data element.
101 return ((ACPI_SMALL_RESOURCE_HEADER *)Header)->Bits.Length +
102 sizeof (ACPI_SMALL_RESOURCE_HEADER);
103 }
104
105 /** Set the Checksum of an EndTag resource data.
106
107 ACPI 6.4, s6.4.2.9 "End Tag":
108 "This checksum is generated such that adding it to the sum of all the data
109 bytes will produce a zero sum."
110 "If the checksum field is zero, the resource data is treated as if the
111 checksum operation succeeded. Configuration proceeds normally."
112
113 @param [in] Header Pointer to the first byte of a resource data.
114 @param [in] CheckSum Checksum value to set.
115
116 @retval EFI_SUCCESS The function completed successfully.
117 @retval EFI_INVALID_PARAMETER Invalid parameter.
118 **/
119 EFI_STATUS
120 EFIAPI
121 AmlRdSetEndTagChecksum (
122 IN CONST AML_RD_HEADER *Header,
123 IN UINT8 CheckSum
124 )
125 {
126 if ((Header == NULL) ||
127 !AmlRdCompareDescId (
128 Header,
129 AML_RD_BUILD_SMALL_DESC_ID (ACPI_SMALL_END_TAG_DESCRIPTOR_NAME)
130 ))
131 {
132 ASSERT (0);
133 return EFI_INVALID_PARAMETER;
134 }
135
136 ((EFI_ACPI_END_TAG_DESCRIPTOR *)Header)->Checksum = CheckSum;
137 return EFI_SUCCESS;
138 }