]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlChild.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / AcpiTableDxe / AmlChild.c
1 /** @file
2 ACPI Sdt Protocol Driver
3
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "AcpiTable.h"
10
11 /**
12 Return the child objects buffer from AML Handle's buffer.
13
14 @param[in] AmlParentHandle Parent handle.
15 @param[in] CurrentBuffer The current child buffer.
16 @param[out] Buffer On return, points to the next returned child buffer or NULL if there are no
17 child buffer.
18
19 @retval EFI_SUCCESS Success
20 @retval EFI_INVALID_PARAMETER AmlParentHandle does not refer to a valid ACPI object.
21 **/
22 EFI_STATUS
23 AmlGetChildFromObjectBuffer (
24 IN EFI_AML_HANDLE *AmlParentHandle,
25 IN UINT8 *CurrentBuffer,
26 OUT VOID **Buffer
27 )
28 {
29 AML_BYTE_ENCODING *AmlByteEncoding;
30 UINTN DataSize;
31
32 //
33 // Root is considered as SCOPE, which has TermList.
34 // We need return only Object in TermList.
35 //
36 while ((UINTN)CurrentBuffer < (UINTN)(AmlParentHandle->Buffer + AmlParentHandle->Size)) {
37 AmlByteEncoding = AmlSearchByOpByte (CurrentBuffer);
38 if (AmlByteEncoding == NULL) {
39 return EFI_INVALID_PARAMETER;
40 }
41
42 //
43 // NOTE: We need return everything, because user might need parse the returned object.
44 //
45 if ((AmlByteEncoding->Attribute & AML_IS_NAME_CHAR) == 0) {
46 *Buffer = CurrentBuffer;
47 return EFI_SUCCESS;
48 }
49
50 DataSize = AmlGetObjectSize (
51 AmlByteEncoding,
52 CurrentBuffer,
53 (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size - (UINTN)CurrentBuffer
54 );
55 if (DataSize == 0) {
56 return EFI_INVALID_PARAMETER;
57 }
58
59 CurrentBuffer += DataSize;
60 }
61
62 //
63 // No more
64 //
65 *Buffer = NULL;
66 return EFI_SUCCESS;
67 }
68
69 /**
70 Return the child ACPI objects from Root Handle.
71
72 @param[in] AmlParentHandle Parent handle. It is Root Handle.
73 @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
74 @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
75 child objects.
76
77 @retval EFI_SUCCESS Success
78 @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
79 **/
80 EFI_STATUS
81 AmlGetChildFromRoot (
82 IN EFI_AML_HANDLE *AmlParentHandle,
83 IN EFI_AML_HANDLE *AmlHandle,
84 OUT VOID **Buffer
85 )
86 {
87 UINT8 *CurrentBuffer;
88
89 if (AmlHandle == NULL) {
90 //
91 // First One
92 //
93 CurrentBuffer = (VOID *)AmlParentHandle->Buffer;
94 } else {
95 CurrentBuffer = (VOID *)(AmlHandle->Buffer + AmlHandle->Size);
96 }
97
98 return AmlGetChildFromObjectBuffer (AmlParentHandle, CurrentBuffer, Buffer);
99 }
100
101 /**
102 Return the child objects buffer from AML Handle's option list.
103
104 @param[in] AmlParentHandle Parent handle.
105 @param[in] AmlHandle The current child handle.
106 @param[out] Buffer On return, points to the next returned child buffer or NULL if there are no
107 child buffer.
108
109 @retval EFI_SUCCESS Success
110 @retval EFI_INVALID_PARAMETER AmlParentHandle does not refer to a valid ACPI object.
111 **/
112 EFI_STATUS
113 AmlGetChildFromOptionList (
114 IN EFI_AML_HANDLE *AmlParentHandle,
115 IN EFI_AML_HANDLE *AmlHandle,
116 OUT VOID **Buffer
117 )
118 {
119 EFI_ACPI_DATA_TYPE DataType;
120 VOID *Data;
121 UINTN DataSize;
122 AML_OP_PARSE_INDEX Index;
123 EFI_STATUS Status;
124 AML_OP_PARSE_INDEX MaxTerm;
125
126 Index = AML_OP_PARSE_INDEX_GET_TERM1;
127 MaxTerm = AmlParentHandle->AmlByteEncoding->MaxIndex;
128 while (Index <= MaxTerm) {
129 Status = AmlParseOptionHandleCommon (
130 AmlParentHandle,
131 (AML_OP_PARSE_INDEX)Index,
132 &DataType,
133 (VOID **)&Data,
134 &DataSize
135 );
136 if (EFI_ERROR (Status)) {
137 return EFI_INVALID_PARAMETER;
138 }
139
140 if (DataType == EFI_ACPI_DATA_TYPE_NONE) {
141 //
142 // Not found
143 //
144 break;
145 }
146
147 //
148 // Find it, and Check Data
149 //
150 if ((DataType == EFI_ACPI_DATA_TYPE_CHILD) &&
151 ((UINTN)AmlHandle->Buffer < (UINTN)Data))
152 {
153 //
154 // Buffer < Data means current node is next one
155 //
156 *Buffer = Data;
157 return EFI_SUCCESS;
158 }
159
160 //
161 // Not Child
162 //
163 Index++;
164 }
165
166 *Buffer = NULL;
167 return EFI_SUCCESS;
168 }
169
170 /**
171 Return the child objects buffer from AML Handle's object child list.
172
173 @param[in] AmlParentHandle Parent handle.
174 @param[in] AmlHandle The current child handle.
175 @param[out] Buffer On return, points to the next returned child buffer or NULL if there are no
176 child buffer.
177
178 @retval EFI_SUCCESS Success
179 @retval EFI_INVALID_PARAMETER AmlParentHandle does not refer to a valid ACPI object.
180 **/
181 EFI_STATUS
182 AmlGetChildFromObjectChildList (
183 IN EFI_AML_HANDLE *AmlParentHandle,
184 IN EFI_AML_HANDLE *AmlHandle,
185 OUT VOID **Buffer
186 )
187 {
188 EFI_STATUS Status;
189 UINT8 *CurrentBuffer;
190
191 CurrentBuffer = NULL;
192
193 if ((AmlParentHandle->AmlByteEncoding->Attribute & AML_HAS_CHILD_OBJ) == 0) {
194 //
195 // No ObjectList
196 //
197 *Buffer = NULL;
198 return EFI_SUCCESS;
199 }
200
201 //
202 // Do we need add node within METHOD?
203 // Yes, just add Object is OK. But we need filter NameString for METHOD invoke.
204 //
205
206 //
207 // Now, we get the last node.
208 //
209 Status = AmlGetOffsetAfterLastOption (AmlParentHandle, &CurrentBuffer);
210 if (EFI_ERROR (Status)) {
211 return EFI_INVALID_PARAMETER;
212 }
213
214 //
215 // Go through all the reset buffer.
216 //
217 if ((UINTN)AmlHandle->Buffer < (UINTN)CurrentBuffer) {
218 //
219 // Buffer < Data means next node is first object
220 //
221 } else if ((UINTN)AmlHandle->Buffer + AmlHandle->Size < (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size) {
222 //
223 // There is still more node
224 //
225 CurrentBuffer = AmlHandle->Buffer + AmlHandle->Size;
226 } else {
227 //
228 // No more data
229 //
230 *Buffer = NULL;
231 return EFI_SUCCESS;
232 }
233
234 return AmlGetChildFromObjectBuffer (AmlParentHandle, CurrentBuffer, Buffer);
235 }
236
237 /**
238 Return the child ACPI objects from Non-Root Handle.
239
240 @param[in] AmlParentHandle Parent handle. It is Non-Root Handle.
241 @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
242 @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
243 child objects.
244
245 @retval EFI_SUCCESS Success
246 @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
247 **/
248 EFI_STATUS
249 AmlGetChildFromNonRoot (
250 IN EFI_AML_HANDLE *AmlParentHandle,
251 IN EFI_AML_HANDLE *AmlHandle,
252 OUT VOID **Buffer
253 )
254 {
255 EFI_STATUS Status;
256
257 if (AmlHandle == NULL) {
258 //
259 // NULL means first one
260 //
261 AmlHandle = AmlParentHandle;
262 }
263
264 //
265 // 1. Get Option
266 //
267 Status = AmlGetChildFromOptionList (AmlParentHandle, AmlHandle, Buffer);
268 if (EFI_ERROR (Status)) {
269 return EFI_INVALID_PARAMETER;
270 }
271
272 if (*Buffer != NULL) {
273 return EFI_SUCCESS;
274 }
275
276 //
277 // 2. search ObjectList
278 //
279 return AmlGetChildFromObjectChildList (AmlParentHandle, AmlHandle, Buffer);
280 }