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