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