Rev 1498 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1498 | serge | 1 | |
2 | * |
||
3 | * Module Name: asllength - Tree walk to determine package and opcode lengths |
||
4 | * |
||
5 | *****************************************************************************/ |
||
6 | |||
7 | |||
8 | * |
||
9 | * 1. Copyright Notice |
||
10 | * |
||
11 | * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp. |
||
2216 | Serge | 12 | * All rights reserved. |
1498 | serge | 13 | * |
14 | * 2. License |
||
15 | * |
||
16 | * 2.1. This is your license from Intel Corp. under its intellectual property |
||
17 | * rights. You may have additional license terms from the party that provided |
||
18 | * you this software, covering your right to use that party's intellectual |
||
19 | * property rights. |
||
20 | * |
||
21 | * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a |
||
22 | * copy of the source code appearing in this file ("Covered Code") an |
||
23 | * irrevocable, perpetual, worldwide license under Intel's copyrights in the |
||
24 | * base code distributed originally by Intel ("Original Intel Code") to copy, |
||
25 | * make derivatives, distribute, use and display any portion of the Covered |
||
26 | * Code in any form, with the right to sublicense such rights; and |
||
27 | * |
||
28 | * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent |
||
29 | * license (with the right to sublicense), under only those claims of Intel |
||
30 | * patents that are infringed by the Original Intel Code, to make, use, sell, |
||
31 | * offer to sell, and import the Covered Code and derivative works thereof |
||
32 | * solely to the minimum extent necessary to exercise the above copyright |
||
33 | * license, and in no event shall the patent license extend to any additions |
||
34 | * to or modifications of the Original Intel Code. No other license or right |
||
35 | * is granted directly or by implication, estoppel or otherwise; |
||
36 | * |
||
37 | * The above copyright and patent license is granted only if the following |
||
38 | * conditions are met: |
||
39 | * |
||
40 | * 3. Conditions |
||
41 | * |
||
42 | * 3.1. Redistribution of Source with Rights to Further Distribute Source. |
||
43 | * Redistribution of source code of any substantial portion of the Covered |
||
44 | * Code or modification with rights to further distribute source must include |
||
45 | * the above Copyright Notice, the above License, this list of Conditions, |
||
46 | * and the following Disclaimer and Export Compliance provision. In addition, |
||
47 | * Licensee must cause all Covered Code to which Licensee contributes to |
||
48 | * contain a file documenting the changes Licensee made to create that Covered |
||
49 | * Code and the date of any change. Licensee must include in that file the |
||
50 | * documentation of any changes made by any predecessor Licensee. Licensee |
||
51 | * must include a prominent statement that the modification is derived, |
||
52 | * directly or indirectly, from Original Intel Code. |
||
53 | * |
||
54 | * 3.2. Redistribution of Source with no Rights to Further Distribute Source. |
||
55 | * Redistribution of source code of any substantial portion of the Covered |
||
56 | * Code or modification without rights to further distribute source must |
||
57 | * include the following Disclaimer and Export Compliance provision in the |
||
58 | * documentation and/or other materials provided with distribution. In |
||
59 | * addition, Licensee may not authorize further sublicense of source of any |
||
60 | * portion of the Covered Code, and must include terms to the effect that the |
||
61 | * license from Licensee to its licensee is limited to the intellectual |
||
62 | * property embodied in the software Licensee provides to its licensee, and |
||
63 | * not to intellectual property embodied in modifications its licensee may |
||
64 | * make. |
||
65 | * |
||
66 | * 3.3. Redistribution of Executable. Redistribution in executable form of any |
||
67 | * substantial portion of the Covered Code or modification must reproduce the |
||
68 | * above Copyright Notice, and the following Disclaimer and Export Compliance |
||
69 | * provision in the documentation and/or other materials provided with the |
||
70 | * distribution. |
||
71 | * |
||
72 | * 3.4. Intel retains all right, title, and interest in and to the Original |
||
73 | * Intel Code. |
||
74 | * |
||
75 | * 3.5. Neither the name Intel nor any other trademark owned or controlled by |
||
76 | * Intel shall be used in advertising or otherwise to promote the sale, use or |
||
77 | * other dealings in products derived from or relating to the Covered Code |
||
78 | * without prior written authorization from Intel. |
||
79 | * |
||
80 | * 4. Disclaimer and Export Compliance |
||
81 | * |
||
82 | * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED |
||
83 | * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE |
||
84 | * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, |
||
85 | * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY |
||
86 | * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY |
||
87 | * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A |
||
88 | * PARTICULAR PURPOSE. |
||
89 | * |
||
90 | * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES |
||
91 | * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR |
||
92 | * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, |
||
93 | * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY |
||
94 | * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL |
||
95 | * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS |
||
96 | * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY |
||
97 | * LIMITED REMEDY. |
||
98 | * |
||
99 | * 4.3. Licensee shall not export, either directly or indirectly, any of this |
||
100 | * software or system incorporating such software without first obtaining any |
||
101 | * required license or other approval from the U. S. Department of Commerce or |
||
102 | * any other agency or department of the United States Government. In the |
||
103 | * event Licensee exports any such software from the United States or |
||
104 | * re-exports any such software from a foreign destination, Licensee shall |
||
105 | * ensure that the distribution and export/re-export of the software is in |
||
106 | * compliance with all laws, regulations, orders, or other restrictions of the |
||
107 | * U.S. Export Administration Regulations. Licensee agrees that neither it nor |
||
108 | * any of its subsidiaries will export/re-export any technical data, process, |
||
109 | * software, or service, directly or indirectly, to any country for which the |
||
110 | * United States government or any agency thereof requires an export license, |
||
111 | * other governmental approval, or letter of assurance, without first obtaining |
||
112 | * such license, approval or letter. |
||
113 | * |
||
114 | *****************************************************************************/ |
||
115 | |||
116 | |||
117 | |||
118 | #include "aslcompiler.y.h" |
||
119 | #include "amlcode.h" |
||
120 | |||
121 | |||
122 | |||
123 | ACPI_MODULE_NAME ("asllength") |
||
124 | |||
125 | |||
126 | |||
127 | |||
128 | CgGetPackageLenByteCount ( |
||
129 | ACPI_PARSE_OBJECT *Op, |
||
130 | UINT32 PackageLength); |
||
131 | |||
132 | |||
133 | CgGenerateAmlOpcodeLength ( |
||
134 | ACPI_PARSE_OBJECT *Op); |
||
135 | |||
136 | |||
137 | |||
138 | void |
||
139 | LnAdjustLengthToRoot ( |
||
140 | ACPI_PARSE_OBJECT *Op, |
||
141 | UINT32 LengthDelta); |
||
142 | #endif |
||
143 | |||
144 | |||
145 | |||
146 | * |
||
147 | * FUNCTION: LnInitLengthsWalk |
||
148 | * |
||
149 | * PARAMETERS: ASL_WALK_CALLBACK |
||
150 | * |
||
151 | * RETURN: Status |
||
152 | * |
||
153 | * DESCRIPTION: Walk callback to initialize (and re-initialize) the node |
||
154 | * subtree length(s) to zero. The Subtree lengths are bubbled |
||
155 | * up to the root node in order to get a total AML length. |
||
156 | * |
||
157 | ******************************************************************************/ |
||
158 | |||
159 | |||
160 | LnInitLengthsWalk ( |
||
161 | ACPI_PARSE_OBJECT *Op, |
||
162 | UINT32 Level, |
||
163 | void *Context) |
||
164 | { |
||
165 | |||
166 | |||
167 | return (AE_OK); |
||
168 | } |
||
169 | |||
170 | |||
171 | |||
172 | * |
||
173 | * FUNCTION: LnPackageLengthWalk |
||
174 | * |
||
175 | * PARAMETERS: ASL_WALK_CALLBACK |
||
176 | * |
||
177 | * RETURN: Status |
||
178 | * |
||
179 | * DESCRIPTION: Walk callback to calculate the total AML length. |
||
180 | * 1) Calculate the AML lengths (opcode, package length, etc.) for |
||
181 | * THIS node. |
||
182 | * 2) Bubbble up all of these lengths to the parent node by summing |
||
183 | * them all into the parent subtree length. |
||
184 | * |
||
185 | * Note: The SubtreeLength represents the total AML length of all child nodes |
||
186 | * in all subtrees under a given node. Therefore, once this walk is |
||
187 | * complete, the Root Node subtree length is the AML length of the entire |
||
188 | * tree (and thus, the entire ACPI table) |
||
189 | * |
||
190 | ******************************************************************************/ |
||
191 | |||
192 | |||
193 | LnPackageLengthWalk ( |
||
194 | ACPI_PARSE_OBJECT *Op, |
||
195 | UINT32 Level, |
||
196 | void *Context) |
||
197 | { |
||
198 | |||
199 | |||
200 | |||
201 | |||
202 | |||
203 | |||
204 | |||
205 | |||
206 | (Op->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)) |
||
207 | { |
||
208 | Op->Asl.Parent->Asl.AmlSubtreeLength += (Op->Asl.AmlLength + |
||
209 | Op->Asl.AmlOpcodeLength + |
||
210 | Op->Asl.AmlPkgLenBytes + |
||
211 | Op->Asl.AmlSubtreeLength); |
||
212 | } |
||
213 | return (AE_OK); |
||
214 | } |
||
215 | |||
216 | |||
217 | |||
218 | * |
||
219 | * FUNCTION: CgGetPackageLenByteCount |
||
220 | * |
||
221 | * PARAMETERS: Op - Parse node |
||
222 | * PackageLength - Length to be encoded |
||
223 | * |
||
224 | * RETURN: Required length of the package length encoding |
||
225 | * |
||
226 | * DESCRIPTION: Calculate the number of bytes required to encode the given |
||
227 | * package length. |
||
228 | * |
||
229 | ******************************************************************************/ |
||
230 | |||
231 | |||
232 | CgGetPackageLenByteCount ( |
||
233 | ACPI_PARSE_OBJECT *Op, |
||
234 | UINT32 PackageLength) |
||
235 | { |
||
236 | |||
237 | |||
238 | * Determine the number of bytes required to encode the package length |
||
239 | * Note: the package length includes the number of bytes used to encode |
||
240 | * the package length, so we must account for this also. |
||
241 | */ |
||
242 | if (PackageLength <= (0x0000003F - 1)) |
||
243 | { |
||
244 | return (1); |
||
245 | } |
||
246 | else if (PackageLength <= (0x00000FFF - 2)) |
||
247 | { |
||
248 | return (2); |
||
249 | } |
||
250 | else if (PackageLength <= (0x000FFFFF - 3)) |
||
251 | { |
||
252 | return (3); |
||
253 | } |
||
254 | else if (PackageLength <= (0x0FFFFFFF - 4)) |
||
255 | { |
||
256 | return (4); |
||
257 | } |
||
258 | else |
||
259 | { |
||
260 | /* Fatal error - the package length is too large to encode */ |
||
261 | |||
262 | |||
263 | } |
||
264 | |||
265 | |||
266 | } |
||
267 | |||
268 | |||
269 | |||
270 | * |
||
271 | * FUNCTION: CgGenerateAmlOpcodeLength |
||
272 | * |
||
273 | * PARAMETERS: Op - Parse node whose AML opcode lengths will be |
||
274 | * calculated |
||
275 | * |
||
276 | * RETURN: None. |
||
277 | * |
||
278 | * DESCRIPTION: Calculate the AmlOpcodeLength, AmlPkgLenBytes, and AmlLength |
||
279 | * fields for this node. |
||
280 | * |
||
281 | ******************************************************************************/ |
||
282 | |||
283 | |||
284 | CgGenerateAmlOpcodeLength ( |
||
285 | ACPI_PARSE_OBJECT *Op) |
||
286 | { |
||
287 | |||
288 | |||
289 | |||
290 | |||
291 | { |
||
292 | Op->Asl.AmlOpcodeLength = 2; |
||
293 | } |
||
294 | else |
||
295 | { |
||
296 | Op->Asl.AmlOpcodeLength = 1; |
||
297 | } |
||
298 | |||
299 | |||
300 | |||
301 | |||
302 | if (Op->Asl.CompileFlags & NODE_AML_PACKAGE) |
||
303 | { |
||
304 | Op->Asl.AmlPkgLenBytes = CgGetPackageLenByteCount ( |
||
305 | Op, Op->Asl.AmlSubtreeLength); |
||
306 | } |
||
307 | |||
308 | |||
309 | |||
310 | |||
311 | { |
||
312 | case AML_BYTE_OP: |
||
313 | |||
314 | |||
315 | break; |
||
316 | |||
317 | |||
318 | |||
319 | |||
320 | break; |
||
321 | |||
322 | |||
323 | |||
324 | |||
325 | break; |
||
326 | |||
327 | |||
328 | |||
329 | |||
330 | break; |
||
331 | |||
332 | |||
333 | /* All data opcodes must be above */ |
||
334 | break; |
||
335 | } |
||
336 | } |
||
337 | |||
338 | |||
339 | |||
340 | * |
||
341 | * FUNCTION: CgGenerateAmlLengths |
||
342 | * |
||
343 | * PARAMETERS: Op - Parse node |
||
344 | * |
||
345 | * RETURN: None. |
||
346 | * |
||
347 | * DESCRIPTION: Generate internal length fields based on the AML opcode or |
||
348 | * parse opcode. |
||
349 | * |
||
350 | ******************************************************************************/ |
||
351 | |||
352 | |||
353 | CgGenerateAmlLengths ( |
||
354 | ACPI_PARSE_OBJECT *Op) |
||
355 | { |
||
356 | char *Buffer; |
||
357 | ACPI_STATUS Status; |
||
358 | |||
359 | |||
360 | |||
361 | { |
||
362 | case AML_RAW_DATA_BYTE: |
||
363 | |||
364 | |||
365 | Op->Asl.AmlLength = 1; |
||
366 | return; |
||
367 | |||
368 | |||
369 | |||
370 | |||
371 | Op->Asl.AmlLength = 2; |
||
372 | return; |
||
373 | |||
374 | |||
375 | |||
376 | |||
377 | Op->Asl.AmlLength = 4; |
||
378 | return; |
||
379 | |||
380 | |||
381 | |||
382 | |||
383 | Op->Asl.AmlLength = 8; |
||
384 | return; |
||
385 | |||
386 | |||
387 | |||
388 | |||
389 | |||
390 | |||
391 | return; |
||
392 | |||
393 | |||
394 | |||
395 | |||
396 | |||
397 | |||
398 | return; |
||
399 | |||
400 | |||
401 | break; |
||
402 | } |
||
403 | |||
404 | |||
405 | { |
||
406 | case PARSEOP_DEFINITIONBLOCK: |
||
407 | |||
408 | |||
409 | Op->Asl.AmlSubtreeLength; |
||
410 | break; |
||
411 | |||
412 | |||
413 | |||
414 | |||
415 | Op->Asl.AmlLength = 4; |
||
416 | Op->Asl.ExternalName = Op->Asl.Value.String; |
||
417 | break; |
||
418 | |||
419 | |||
420 | case PARSEOP_METHODCALL: |
||
421 | |||
422 | |||
423 | { |
||
424 | break; |
||
425 | } |
||
426 | |||
427 | |||
428 | Status = UtInternalizeName (Op->Asl.Value.String, &Buffer); |
||
429 | if (ACPI_FAILURE (Status)) |
||
430 | { |
||
431 | DbgPrint (ASL_DEBUG_OUTPUT, |
||
432 | "Failure from internalize name %X\n", Status); |
||
433 | break; |
||
434 | } |
||
435 | |||
436 | |||
437 | Op->Asl.Value.String = Buffer; |
||
438 | Op->Asl.CompileFlags |= NODE_NAME_INTERNALIZED; |
||
439 | |||
440 | |||
441 | |||
442 | |||
443 | * Check for single backslash reference to root, |
||
444 | * make it a null terminated string in the AML |
||
445 | */ |
||
446 | if (Op->Asl.AmlLength == 1) |
||
447 | { |
||
448 | Op->Asl.AmlLength = 2; |
||
449 | } |
||
450 | break; |
||
451 | |||
452 | |||
453 | |||
454 | |||
455 | |||
456 | |||
457 | |||
458 | |||
459 | break; |
||
460 | |||
461 | |||
462 | |||
463 | |||
464 | Op->Asl.AmlPkgLenBytes = CgGetPackageLenByteCount (Op, |
||
465 | (UINT32) Op->Asl.Value.Integer); |
||
466 | break; |
||
467 | |||
468 | |||
469 | |||
470 | |||
471 | break; |
||
472 | |||
473 | |||
474 | case PARSEOP_EXTERNAL: |
||
475 | case PARSEOP_INCLUDE: |
||
476 | case PARSEOP_INCLUDE_END: |
||
477 | |||
478 | |||
479 | |||
480 | |||
481 | |||
482 | |||
483 | |||
484 | |||
485 | break; |
||
486 | } |
||
487 | } |
||
488 | |||
489 | |||
490 | |||
491 | /******************************************************************************* |
||
492 | * |
||
493 | * FUNCTION: LnAdjustLengthToRoot |
||
494 | * |
||
495 | * PARAMETERS: Op - Node whose Length was changed |
||
496 | * |
||
497 | * RETURN: None. |
||
498 | * |
||
499 | * DESCRIPTION: Change the Subtree length of the given node, and bubble the |
||
500 | * change all the way up to the root node. This allows for |
||
501 | * last second changes to a package length (for example, if the |
||
502 | * package length encoding gets shorter or longer.) |
||
503 | * |
||
504 | ******************************************************************************/ |
||
505 | |||
506 | |||
507 | LnAdjustLengthToRoot ( |
||
508 | ACPI_PARSE_OBJECT *SubtreeOp, |
||
509 | UINT32 LengthDelta) |
||
510 | { |
||
511 | ACPI_PARSE_OBJECT *Op; |
||
512 | |||
513 | |||
514 | |||
515 | |||
516 | |||
517 | while (Op) |
||
518 | { |
||
519 | Op->Asl.AmlSubtreeLength -= LengthDelta; |
||
520 | Op = Op->Asl.Parent; |
||
521 | } |
||
522 | |||
523 | |||
524 | |||
525 | |||
526 | } |
||
527 | #endif=>=>=>=> |
||
528 |