1 /****************************************************************************** 2 * 3 * Module Name: dtutils.c - Utility routines for the data table compiler 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp. 12 * All rights reserved. 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 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include <contrib/dev/acpica/compiler/aslcompiler.h> 153 #include <contrib/dev/acpica/compiler/dtcompiler.h> 154 #include <contrib/dev/acpica/include/actables.h> 155 156 #define _COMPONENT DT_COMPILER 157 ACPI_MODULE_NAME ("dtutils") 158 159 /* Local prototypes */ 160 161 static void 162 DtSum ( 163 DT_SUBTABLE *Subtable, 164 void *Context, 165 void *ReturnValue); 166 167 168 /****************************************************************************** 169 * 170 * FUNCTION: DtError 171 * 172 * PARAMETERS: Level - Seriousness (Warning/error, etc.) 173 * MessageId - Index into global message buffer 174 * Op - Parse node where error happened 175 * ExtraMessage - additional error message 176 * 177 * RETURN: None 178 * 179 * DESCRIPTION: Common error interface for data table compiler 180 * 181 *****************************************************************************/ 182 183 void 184 DtError ( 185 UINT8 Level, 186 UINT16 MessageId, 187 DT_FIELD *FieldObject, 188 char *ExtraMessage) 189 { 190 191 /* Check if user wants to ignore this exception */ 192 193 if (AslIsExceptionDisabled (Level, MessageId)) 194 { 195 return; 196 } 197 198 if (FieldObject) 199 { 200 AslCommonError (Level, MessageId, 201 FieldObject->Line, 202 FieldObject->Line, 203 FieldObject->ByteOffset, 204 FieldObject->Column, 205 Gbl_Files[ASL_FILE_INPUT].Filename, ExtraMessage); 206 } 207 else 208 { 209 AslCommonError (Level, MessageId, 0, 210 0, 0, 0, 0, ExtraMessage); 211 } 212 } 213 214 215 /****************************************************************************** 216 * 217 * FUNCTION: DtNameError 218 * 219 * PARAMETERS: Level - Seriousness (Warning/error, etc.) 220 * MessageId - Index into global message buffer 221 * Op - Parse node where error happened 222 * ExtraMessage - additional error message 223 * 224 * RETURN: None 225 * 226 * DESCRIPTION: Error interface for named objects 227 * 228 *****************************************************************************/ 229 230 void 231 DtNameError ( 232 UINT8 Level, 233 UINT16 MessageId, 234 DT_FIELD *FieldObject, 235 char *ExtraMessage) 236 { 237 238 switch (Level) 239 { 240 case ASL_WARNING2: 241 case ASL_WARNING3: 242 243 if (Gbl_WarningLevel < Level) 244 { 245 return; 246 } 247 break; 248 249 default: 250 251 break; 252 } 253 254 if (FieldObject) 255 { 256 AslCommonError (Level, MessageId, 257 FieldObject->Line, 258 FieldObject->Line, 259 FieldObject->ByteOffset, 260 FieldObject->NameColumn, 261 Gbl_Files[ASL_FILE_INPUT].Filename, ExtraMessage); 262 } 263 else 264 { 265 AslCommonError (Level, MessageId, 0, 266 0, 0, 0, 0, ExtraMessage); 267 } 268 } 269 270 271 /******************************************************************************* 272 * 273 * FUNCTION: DtFatal 274 * 275 * PARAMETERS: None 276 * 277 * RETURN: None 278 * 279 * DESCRIPTION: Dump the error log and abort the compiler. Used for serious 280 * compile or I/O errors 281 * 282 ******************************************************************************/ 283 284 void 285 DtFatal ( 286 UINT16 MessageId, 287 DT_FIELD *FieldObject, 288 char *ExtraMessage) 289 { 290 291 DtError (ASL_ERROR, MessageId, FieldObject, ExtraMessage); 292 293 /* 294 * TBD: remove this entire function, DtFatal 295 * 296 * We cannot abort the compiler on error, because we may be compiling a 297 * list of files. We must move on to the next file. 298 */ 299 #ifdef __OBSOLETE 300 CmCleanupAndExit (); 301 exit (1); 302 #endif 303 } 304 305 306 /****************************************************************************** 307 * 308 * FUNCTION: DtGetFieldValue 309 * 310 * PARAMETERS: Field - Current field list pointer 311 * 312 * RETURN: Field value 313 * 314 * DESCRIPTION: Get field value 315 * 316 *****************************************************************************/ 317 318 char * 319 DtGetFieldValue ( 320 DT_FIELD *Field) 321 { 322 if (!Field) 323 { 324 return (NULL); 325 } 326 327 return (Field->Value); 328 } 329 330 331 /****************************************************************************** 332 * 333 * FUNCTION: DtGetFieldType 334 * 335 * PARAMETERS: Info - Data table info 336 * 337 * RETURN: Field type 338 * 339 * DESCRIPTION: Get field type 340 * 341 *****************************************************************************/ 342 343 UINT8 344 DtGetFieldType ( 345 ACPI_DMTABLE_INFO *Info) 346 { 347 UINT8 Type; 348 349 350 /* DT_FLAG means that this is the start of a block of flag bits */ 351 /* TBD - we can make these a separate opcode later */ 352 353 if (Info->Flags & DT_FLAG) 354 { 355 return (DT_FIELD_TYPE_FLAGS_INTEGER); 356 } 357 358 /* Type is based upon the opcode for this field in the info table */ 359 360 switch (Info->Opcode) 361 { 362 case ACPI_DMT_FLAG0: 363 case ACPI_DMT_FLAG1: 364 case ACPI_DMT_FLAG2: 365 case ACPI_DMT_FLAG3: 366 case ACPI_DMT_FLAG4: 367 case ACPI_DMT_FLAG5: 368 case ACPI_DMT_FLAG6: 369 case ACPI_DMT_FLAG7: 370 case ACPI_DMT_FLAGS0: 371 case ACPI_DMT_FLAGS1: 372 case ACPI_DMT_FLAGS2: 373 case ACPI_DMT_FLAGS4: 374 375 Type = DT_FIELD_TYPE_FLAG; 376 break; 377 378 case ACPI_DMT_NAME4: 379 case ACPI_DMT_SIG: 380 case ACPI_DMT_NAME6: 381 case ACPI_DMT_NAME8: 382 case ACPI_DMT_STRING: 383 384 Type = DT_FIELD_TYPE_STRING; 385 break; 386 387 case ACPI_DMT_BUFFER: 388 case ACPI_DMT_RAW_BUFFER: 389 case ACPI_DMT_BUF7: 390 case ACPI_DMT_BUF10: 391 case ACPI_DMT_BUF12: 392 case ACPI_DMT_BUF16: 393 case ACPI_DMT_BUF128: 394 case ACPI_DMT_PCI_PATH: 395 396 Type = DT_FIELD_TYPE_BUFFER; 397 break; 398 399 case ACPI_DMT_GAS: 400 case ACPI_DMT_HESTNTFY: 401 case ACPI_DMT_IORTMEM: 402 403 Type = DT_FIELD_TYPE_INLINE_SUBTABLE; 404 break; 405 406 case ACPI_DMT_UNICODE: 407 408 Type = DT_FIELD_TYPE_UNICODE; 409 break; 410 411 case ACPI_DMT_UUID: 412 413 Type = DT_FIELD_TYPE_UUID; 414 break; 415 416 case ACPI_DMT_DEVICE_PATH: 417 418 Type = DT_FIELD_TYPE_DEVICE_PATH; 419 break; 420 421 case ACPI_DMT_LABEL: 422 423 Type = DT_FIELD_TYPE_LABEL; 424 break; 425 426 default: 427 428 Type = DT_FIELD_TYPE_INTEGER; 429 break; 430 } 431 432 return (Type); 433 } 434 435 436 /****************************************************************************** 437 * 438 * FUNCTION: DtGetBufferLength 439 * 440 * PARAMETERS: Buffer - List of integers, 441 * for example "10 3A 4F 2E" 442 * 443 * RETURN: Count of integer 444 * 445 * DESCRIPTION: Get length of bytes needed to store the integers 446 * 447 *****************************************************************************/ 448 449 UINT32 450 DtGetBufferLength ( 451 char *Buffer) 452 { 453 UINT32 ByteLength = 0; 454 455 456 while (*Buffer) 457 { 458 if (*Buffer == ' ') 459 { 460 ByteLength++; 461 462 while (*Buffer == ' ') 463 { 464 Buffer++; 465 } 466 } 467 468 Buffer++; 469 } 470 471 return (++ByteLength); 472 } 473 474 475 /****************************************************************************** 476 * 477 * FUNCTION: DtGetFieldLength 478 * 479 * PARAMETERS: Field - Current field 480 * Info - Data table info 481 * 482 * RETURN: Field length 483 * 484 * DESCRIPTION: Get length of bytes needed to compile the field 485 * 486 * Note: This function must remain in sync with AcpiDmDumpTable. 487 * 488 *****************************************************************************/ 489 490 UINT32 491 DtGetFieldLength ( 492 DT_FIELD *Field, 493 ACPI_DMTABLE_INFO *Info) 494 { 495 UINT32 ByteLength = 0; 496 char *Value; 497 498 499 /* Length is based upon the opcode for this field in the info table */ 500 501 switch (Info->Opcode) 502 { 503 case ACPI_DMT_FLAG0: 504 case ACPI_DMT_FLAG1: 505 case ACPI_DMT_FLAG2: 506 case ACPI_DMT_FLAG3: 507 case ACPI_DMT_FLAG4: 508 case ACPI_DMT_FLAG5: 509 case ACPI_DMT_FLAG6: 510 case ACPI_DMT_FLAG7: 511 case ACPI_DMT_FLAGS0: 512 case ACPI_DMT_FLAGS1: 513 case ACPI_DMT_FLAGS2: 514 case ACPI_DMT_FLAGS4: 515 case ACPI_DMT_LABEL: 516 case ACPI_DMT_EXTRA_TEXT: 517 518 ByteLength = 0; 519 break; 520 521 case ACPI_DMT_UINT8: 522 case ACPI_DMT_CHKSUM: 523 case ACPI_DMT_SPACEID: 524 case ACPI_DMT_ACCWIDTH: 525 case ACPI_DMT_IVRS: 526 case ACPI_DMT_GTDT: 527 case ACPI_DMT_MADT: 528 case ACPI_DMT_PCCT: 529 case ACPI_DMT_PMTT: 530 case ACPI_DMT_SRAT: 531 case ACPI_DMT_ASF: 532 case ACPI_DMT_HESTNTYP: 533 case ACPI_DMT_FADTPM: 534 case ACPI_DMT_EINJACT: 535 case ACPI_DMT_EINJINST: 536 case ACPI_DMT_ERSTACT: 537 case ACPI_DMT_ERSTINST: 538 case ACPI_DMT_DMAR_SCOPE: 539 540 ByteLength = 1; 541 break; 542 543 case ACPI_DMT_UINT16: 544 case ACPI_DMT_DMAR: 545 case ACPI_DMT_HEST: 546 case ACPI_DMT_NFIT: 547 case ACPI_DMT_PCI_PATH: 548 549 ByteLength = 2; 550 break; 551 552 case ACPI_DMT_UINT24: 553 554 ByteLength = 3; 555 break; 556 557 case ACPI_DMT_UINT32: 558 case ACPI_DMT_NAME4: 559 case ACPI_DMT_SIG: 560 case ACPI_DMT_LPIT: 561 562 ByteLength = 4; 563 break; 564 565 case ACPI_DMT_UINT40: 566 567 ByteLength = 5; 568 break; 569 570 case ACPI_DMT_UINT48: 571 case ACPI_DMT_NAME6: 572 573 ByteLength = 6; 574 break; 575 576 case ACPI_DMT_UINT56: 577 case ACPI_DMT_BUF7: 578 579 ByteLength = 7; 580 break; 581 582 case ACPI_DMT_UINT64: 583 case ACPI_DMT_NAME8: 584 585 ByteLength = 8; 586 break; 587 588 case ACPI_DMT_STRING: 589 590 Value = DtGetFieldValue (Field); 591 if (Value) 592 { 593 ByteLength = strlen (Value) + 1; 594 } 595 else 596 { /* At this point, this is a fatal error */ 597 598 sprintf (MsgBuffer, "Expected \"%s\"", Info->Name); 599 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer); 600 return (0); 601 } 602 break; 603 604 case ACPI_DMT_GAS: 605 606 ByteLength = sizeof (ACPI_GENERIC_ADDRESS); 607 break; 608 609 case ACPI_DMT_HESTNTFY: 610 611 ByteLength = sizeof (ACPI_HEST_NOTIFY); 612 break; 613 614 case ACPI_DMT_IORTMEM: 615 616 ByteLength = sizeof (ACPI_IORT_MEMORY_ACCESS); 617 break; 618 619 case ACPI_DMT_BUFFER: 620 case ACPI_DMT_RAW_BUFFER: 621 622 Value = DtGetFieldValue (Field); 623 if (Value) 624 { 625 ByteLength = DtGetBufferLength (Value); 626 } 627 else 628 { /* At this point, this is a fatal error */ 629 630 sprintf (MsgBuffer, "Expected \"%s\"", Info->Name); 631 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer); 632 return (0); 633 } 634 break; 635 636 case ACPI_DMT_BUF10: 637 638 ByteLength = 10; 639 break; 640 641 case ACPI_DMT_BUF12: 642 643 ByteLength = 12; 644 break; 645 646 case ACPI_DMT_BUF16: 647 case ACPI_DMT_UUID: 648 649 ByteLength = 16; 650 break; 651 652 case ACPI_DMT_BUF128: 653 654 ByteLength = 128; 655 break; 656 657 case ACPI_DMT_UNICODE: 658 659 Value = DtGetFieldValue (Field); 660 661 /* TBD: error if Value is NULL? (as below?) */ 662 663 ByteLength = (strlen (Value) + 1) * sizeof(UINT16); 664 break; 665 666 default: 667 668 DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid table opcode"); 669 return (0); 670 } 671 672 return (ByteLength); 673 } 674 675 676 /****************************************************************************** 677 * 678 * FUNCTION: DtSum 679 * 680 * PARAMETERS: DT_WALK_CALLBACK: 681 * Subtable - Subtable 682 * Context - Unused 683 * ReturnValue - Store the checksum of subtable 684 * 685 * RETURN: Status 686 * 687 * DESCRIPTION: Get the checksum of subtable 688 * 689 *****************************************************************************/ 690 691 static void 692 DtSum ( 693 DT_SUBTABLE *Subtable, 694 void *Context, 695 void *ReturnValue) 696 { 697 UINT8 Checksum; 698 UINT8 *Sum = ReturnValue; 699 700 701 Checksum = AcpiTbChecksum (Subtable->Buffer, Subtable->Length); 702 *Sum = (UINT8) (*Sum + Checksum); 703 } 704 705 706 /****************************************************************************** 707 * 708 * FUNCTION: DtSetTableChecksum 709 * 710 * PARAMETERS: ChecksumPointer - Where to return the checksum 711 * 712 * RETURN: None 713 * 714 * DESCRIPTION: Set checksum of the whole data table into the checksum field 715 * 716 *****************************************************************************/ 717 718 void 719 DtSetTableChecksum ( 720 UINT8 *ChecksumPointer) 721 { 722 UINT8 Checksum = 0; 723 UINT8 OldSum; 724 725 726 DtWalkTableTree (Gbl_RootTable, DtSum, NULL, &Checksum); 727 728 OldSum = *ChecksumPointer; 729 Checksum = (UINT8) (Checksum - OldSum); 730 731 /* Compute the final checksum */ 732 733 Checksum = (UINT8) (0 - Checksum); 734 *ChecksumPointer = Checksum; 735 } 736 737 738 /****************************************************************************** 739 * 740 * FUNCTION: DtSetTableLength 741 * 742 * PARAMETERS: None 743 * 744 * RETURN: None 745 * 746 * DESCRIPTION: Walk the subtables and set all the length fields 747 * 748 *****************************************************************************/ 749 750 void 751 DtSetTableLength ( 752 void) 753 { 754 DT_SUBTABLE *ParentTable; 755 DT_SUBTABLE *ChildTable; 756 757 758 ParentTable = Gbl_RootTable; 759 ChildTable = NULL; 760 761 if (!ParentTable) 762 { 763 return; 764 } 765 766 DtSetSubtableLength (ParentTable); 767 768 while (1) 769 { 770 ChildTable = DtGetNextSubtable (ParentTable, ChildTable); 771 if (ChildTable) 772 { 773 if (ChildTable->LengthField) 774 { 775 DtSetSubtableLength (ChildTable); 776 } 777 778 if (ChildTable->Child) 779 { 780 ParentTable = ChildTable; 781 ChildTable = NULL; 782 } 783 else 784 { 785 ParentTable->TotalLength += ChildTable->TotalLength; 786 if (ParentTable->LengthField) 787 { 788 DtSetSubtableLength (ParentTable); 789 } 790 } 791 } 792 else 793 { 794 ChildTable = ParentTable; 795 796 if (ChildTable == Gbl_RootTable) 797 { 798 break; 799 } 800 801 ParentTable = DtGetParentSubtable (ParentTable); 802 803 ParentTable->TotalLength += ChildTable->TotalLength; 804 if (ParentTable->LengthField) 805 { 806 DtSetSubtableLength (ParentTable); 807 } 808 } 809 } 810 } 811 812 813 /****************************************************************************** 814 * 815 * FUNCTION: DtWalkTableTree 816 * 817 * PARAMETERS: StartTable - Subtable in the tree where walking begins 818 * UserFunction - Called during the walk 819 * Context - Passed to user function 820 * ReturnValue - The return value of UserFunction 821 * 822 * RETURN: None 823 * 824 * DESCRIPTION: Performs a depth-first walk of the subtable tree 825 * 826 *****************************************************************************/ 827 828 void 829 DtWalkTableTree ( 830 DT_SUBTABLE *StartTable, 831 DT_WALK_CALLBACK UserFunction, 832 void *Context, 833 void *ReturnValue) 834 { 835 DT_SUBTABLE *ParentTable; 836 DT_SUBTABLE *ChildTable; 837 838 839 ParentTable = StartTable; 840 ChildTable = NULL; 841 842 if (!ParentTable) 843 { 844 return; 845 } 846 847 UserFunction (ParentTable, Context, ReturnValue); 848 849 while (1) 850 { 851 ChildTable = DtGetNextSubtable (ParentTable, ChildTable); 852 if (ChildTable) 853 { 854 UserFunction (ChildTable, Context, ReturnValue); 855 856 if (ChildTable->Child) 857 { 858 ParentTable = ChildTable; 859 ChildTable = NULL; 860 } 861 } 862 else 863 { 864 ChildTable = ParentTable; 865 if (ChildTable == Gbl_RootTable) 866 { 867 break; 868 } 869 870 ParentTable = DtGetParentSubtable (ParentTable); 871 872 if (ChildTable->Peer == StartTable) 873 { 874 break; 875 } 876 } 877 } 878 } 879 880 881 /******************************************************************************* 882 * 883 * FUNCTION: UtSubtableCacheCalloc 884 * 885 * PARAMETERS: None 886 * 887 * RETURN: Pointer to the buffer. Aborts on allocation failure 888 * 889 * DESCRIPTION: Allocate a subtable object buffer. Bypass the local 890 * dynamic memory manager for performance reasons (This has a 891 * major impact on the speed of the compiler.) 892 * 893 ******************************************************************************/ 894 895 DT_SUBTABLE * 896 UtSubtableCacheCalloc ( 897 void) 898 { 899 ASL_CACHE_INFO *Cache; 900 901 902 if (Gbl_SubtableCacheNext >= Gbl_SubtableCacheLast) 903 { 904 /* Allocate a new buffer */ 905 906 Cache = UtLocalCalloc (sizeof (Cache->Next) + 907 (sizeof (DT_SUBTABLE) * ASL_SUBTABLE_CACHE_SIZE)); 908 909 /* Link new cache buffer to head of list */ 910 911 Cache->Next = Gbl_SubtableCacheList; 912 Gbl_SubtableCacheList = Cache; 913 914 /* Setup cache management pointers */ 915 916 Gbl_SubtableCacheNext = ACPI_CAST_PTR (DT_SUBTABLE, Cache->Buffer); 917 Gbl_SubtableCacheLast = Gbl_SubtableCacheNext + ASL_SUBTABLE_CACHE_SIZE; 918 } 919 920 Gbl_SubtableCount++; 921 return (Gbl_SubtableCacheNext++); 922 } 923 924 925 /******************************************************************************* 926 * 927 * FUNCTION: UtFieldCacheCalloc 928 * 929 * PARAMETERS: None 930 * 931 * RETURN: Pointer to the buffer. Aborts on allocation failure 932 * 933 * DESCRIPTION: Allocate a field object buffer. Bypass the local 934 * dynamic memory manager for performance reasons (This has a 935 * major impact on the speed of the compiler.) 936 * 937 ******************************************************************************/ 938 939 DT_FIELD * 940 UtFieldCacheCalloc ( 941 void) 942 { 943 ASL_CACHE_INFO *Cache; 944 945 946 if (Gbl_FieldCacheNext >= Gbl_FieldCacheLast) 947 { 948 /* Allocate a new buffer */ 949 950 Cache = UtLocalCalloc (sizeof (Cache->Next) + 951 (sizeof (DT_FIELD) * ASL_FIELD_CACHE_SIZE)); 952 953 /* Link new cache buffer to head of list */ 954 955 Cache->Next = Gbl_FieldCacheList; 956 Gbl_FieldCacheList = Cache; 957 958 /* Setup cache management pointers */ 959 960 Gbl_FieldCacheNext = ACPI_CAST_PTR (DT_FIELD, Cache->Buffer); 961 Gbl_FieldCacheLast = Gbl_FieldCacheNext + ASL_FIELD_CACHE_SIZE; 962 } 963 964 Gbl_FieldCount++; 965 return (Gbl_FieldCacheNext++); 966 } 967 968 969 /******************************************************************************* 970 * 971 * FUNCTION: DtDeleteCaches 972 * 973 * PARAMETERS: None 974 * 975 * RETURN: None 976 * 977 * DESCRIPTION: Delete all local cache buffer blocks 978 * 979 ******************************************************************************/ 980 981 void 982 DtDeleteCaches ( 983 void) 984 { 985 UINT32 BufferCount; 986 ASL_CACHE_INFO *Next; 987 988 989 /* Field cache */ 990 991 BufferCount = 0; 992 while (Gbl_FieldCacheList) 993 { 994 Next = Gbl_FieldCacheList->Next; 995 ACPI_FREE (Gbl_FieldCacheList); 996 Gbl_FieldCacheList = Next; 997 BufferCount++; 998 } 999 1000 DbgPrint (ASL_DEBUG_OUTPUT, 1001 "%u Fields, Buffer size: %u fields (%u bytes), %u Buffers\n", 1002 Gbl_FieldCount, ASL_FIELD_CACHE_SIZE, 1003 (sizeof (DT_FIELD) * ASL_FIELD_CACHE_SIZE), BufferCount); 1004 1005 Gbl_FieldCount = 0; 1006 Gbl_FieldCacheNext = NULL; 1007 Gbl_FieldCacheLast = NULL; 1008 1009 /* Subtable cache */ 1010 1011 BufferCount = 0; 1012 while (Gbl_SubtableCacheList) 1013 { 1014 Next = Gbl_SubtableCacheList->Next; 1015 ACPI_FREE (Gbl_SubtableCacheList); 1016 Gbl_SubtableCacheList = Next; 1017 BufferCount++; 1018 } 1019 1020 DbgPrint (ASL_DEBUG_OUTPUT, 1021 "%u Subtables, Buffer size: %u subtables (%u bytes), %u Buffers\n", 1022 Gbl_SubtableCount, ASL_SUBTABLE_CACHE_SIZE, 1023 (sizeof (DT_SUBTABLE) * ASL_SUBTABLE_CACHE_SIZE), BufferCount); 1024 1025 Gbl_SubtableCount = 0; 1026 Gbl_SubtableCacheNext = NULL; 1027 Gbl_SubtableCacheLast = NULL; 1028 } 1029