]>
Commit | Line | Data |
---|---|---|
3dc8585e JY |
1 | /** @file\r |
2 | ACPI Sdt Protocol Driver\r | |
3 | \r | |
4 | Copyright (c) 2010, Intel Corporation. All rights reserved. <BR>\r | |
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 | |
28 | EFI_STATUS\r | |
29 | AmlGetChildFromObjectBuffer (\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 | |
84 | EFI_STATUS\r | |
85 | AmlGetChildFromRoot (\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 | |
116 | EFI_STATUS\r | |
117 | AmlGetChildFromOptionList (\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 | |
182 | EFI_STATUS\r | |
183 | AmlGetChildFromObjectChildList (\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 | |
192 | if ((AmlParentHandle->AmlByteEncoding->Attribute & AML_HAS_CHILD_OBJ) == 0) {\r | |
193 | //\r | |
194 | // No ObjectList\r | |
195 | //\r | |
196 | *Buffer = NULL;\r | |
197 | return EFI_SUCCESS;\r | |
198 | }\r | |
199 | \r | |
200 | //\r | |
201 | // Do we need add node within METHOD?\r | |
202 | // Yes, just add Object is OK. But we need filter NameString for METHOD invoke.\r | |
203 | //\r | |
204 | \r | |
205 | //\r | |
206 | // Now, we get the last node.\r | |
207 | //\r | |
208 | Status = AmlGetOffsetAfterLastOption (AmlParentHandle, &CurrentBuffer);\r | |
209 | if (EFI_ERROR (Status)) {\r | |
210 | return EFI_INVALID_PARAMETER;\r | |
211 | }\r | |
212 | \r | |
213 | //\r | |
214 | // Go through all the reset buffer.\r | |
215 | //\r | |
216 | if ((UINTN)AmlHandle->Buffer < (UINTN)CurrentBuffer) {\r | |
217 | //\r | |
218 | // Buffer < Data means next node is first object\r | |
219 | //\r | |
220 | } else if ((UINTN)AmlHandle->Buffer + AmlHandle->Size < (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size) {\r | |
221 | //\r | |
222 | // There is still more node\r | |
223 | //\r | |
224 | CurrentBuffer = AmlHandle->Buffer + AmlHandle->Size;\r | |
225 | } else {\r | |
226 | //\r | |
227 | // No more data\r | |
228 | //\r | |
229 | *Buffer = NULL;\r | |
230 | return EFI_SUCCESS;\r | |
231 | }\r | |
232 | \r | |
233 | return AmlGetChildFromObjectBuffer (AmlParentHandle, CurrentBuffer, Buffer);\r | |
234 | }\r | |
235 | \r | |
236 | /**\r | |
237 | Return the child ACPI objects from Non-Root Handle.\r | |
238 | \r | |
239 | @param[in] AmlParentHandle Parent handle. It is Non-Root Handle.\r | |
240 | @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.\r | |
241 | @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no\r | |
242 | child objects.\r | |
243 | \r | |
244 | @retval EFI_SUCCESS Success\r | |
245 | @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object. \r | |
246 | **/\r | |
247 | EFI_STATUS\r | |
248 | AmlGetChildFromNonRoot (\r | |
249 | IN EFI_AML_HANDLE *AmlParentHandle,\r | |
250 | IN EFI_AML_HANDLE *AmlHandle,\r | |
251 | OUT VOID **Buffer\r | |
252 | )\r | |
253 | {\r | |
254 | EFI_STATUS Status;\r | |
255 | \r | |
256 | if (AmlHandle == NULL) {\r | |
257 | //\r | |
258 | // NULL means first one\r | |
259 | //\r | |
260 | AmlHandle = AmlParentHandle;\r | |
261 | }\r | |
262 | \r | |
263 | //\r | |
264 | // 1. Get Option\r | |
265 | //\r | |
266 | Status = AmlGetChildFromOptionList (AmlParentHandle, AmlHandle, Buffer);\r | |
267 | if (EFI_ERROR (Status)) {\r | |
268 | return EFI_INVALID_PARAMETER;\r | |
269 | }\r | |
270 | if (*Buffer != NULL) {\r | |
271 | return EFI_SUCCESS;\r | |
272 | }\r | |
273 | \r | |
274 | //\r | |
275 | // 2. search ObjectList\r | |
276 | //\r | |
277 | return AmlGetChildFromObjectChildList (AmlParentHandle, AmlHandle, Buffer);\r | |
278 | }\r |