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 case ACPI_DMT_FLAGS4_0: 375 case ACPI_DMT_FLAGS4_4: 376 case ACPI_DMT_FLAGS4_8: 377 case ACPI_DMT_FLAGS4_12: 378 case ACPI_DMT_FLAGS16_16: 379 380 Type = DT_FIELD_TYPE_FLAG; 381 break; 382 383 case ACPI_DMT_NAME4: 384 case ACPI_DMT_SIG: 385 case ACPI_DMT_NAME6: 386 case ACPI_DMT_NAME8: 387 case ACPI_DMT_STRING: 388 389 Type = DT_FIELD_TYPE_STRING; 390 break; 391 392 case ACPI_DMT_BUFFER: 393 case ACPI_DMT_RAW_BUFFER: 394 case ACPI_DMT_BUF7: 395 case ACPI_DMT_BUF10: 396 case ACPI_DMT_BUF12: 397 case ACPI_DMT_BUF16: 398 case ACPI_DMT_BUF128: 399 case ACPI_DMT_PCI_PATH: 400 401 Type = DT_FIELD_TYPE_BUFFER; 402 break; 403 404 case ACPI_DMT_GAS: 405 case ACPI_DMT_HESTNTFY: 406 case ACPI_DMT_IORTMEM: 407 408 Type = DT_FIELD_TYPE_INLINE_SUBTABLE; 409 break; 410 411 case ACPI_DMT_UNICODE: 412 413 Type = DT_FIELD_TYPE_UNICODE; 414 break; 415 416 case ACPI_DMT_UUID: 417 418 Type = DT_FIELD_TYPE_UUID; 419 break; 420 421 case ACPI_DMT_DEVICE_PATH: 422 423 Type = DT_FIELD_TYPE_DEVICE_PATH; 424 break; 425 426 case ACPI_DMT_LABEL: 427 428 Type = DT_FIELD_TYPE_LABEL; 429 break; 430 431 default: 432 433 Type = DT_FIELD_TYPE_INTEGER; 434 break; 435 } 436 437 return (Type); 438 } 439 440 441 /****************************************************************************** 442 * 443 * FUNCTION: DtGetBufferLength 444 * 445 * PARAMETERS: Buffer - List of integers, 446 * for example "10 3A 4F 2E" 447 * 448 * RETURN: Count of integer 449 * 450 * DESCRIPTION: Get length of bytes needed to store the integers 451 * 452 *****************************************************************************/ 453 454 UINT32 455 DtGetBufferLength ( 456 char *Buffer) 457 { 458 UINT32 ByteLength = 0; 459 460 461 while (*Buffer) 462 { 463 if (*Buffer == ' ') 464 { 465 ByteLength++; 466 467 while (*Buffer == ' ') 468 { 469 Buffer++; 470 } 471 } 472 473 Buffer++; 474 } 475 476 return (++ByteLength); 477 } 478 479 480 /****************************************************************************** 481 * 482 * FUNCTION: DtGetFieldLength 483 * 484 * PARAMETERS: Field - Current field 485 * Info - Data table info 486 * 487 * RETURN: Field length 488 * 489 * DESCRIPTION: Get length of bytes needed to compile the field 490 * 491 * Note: This function must remain in sync with AcpiDmDumpTable. 492 * 493 *****************************************************************************/ 494 495 UINT32 496 DtGetFieldLength ( 497 DT_FIELD *Field, 498 ACPI_DMTABLE_INFO *Info) 499 { 500 UINT32 ByteLength = 0; 501 char *Value; 502 503 504 /* Length is based upon the opcode for this field in the info table */ 505 506 switch (Info->Opcode) 507 { 508 case ACPI_DMT_FLAG0: 509 case ACPI_DMT_FLAG1: 510 case ACPI_DMT_FLAG2: 511 case ACPI_DMT_FLAG3: 512 case ACPI_DMT_FLAG4: 513 case ACPI_DMT_FLAG5: 514 case ACPI_DMT_FLAG6: 515 case ACPI_DMT_FLAG7: 516 case ACPI_DMT_FLAGS0: 517 case ACPI_DMT_FLAGS1: 518 case ACPI_DMT_FLAGS2: 519 case ACPI_DMT_FLAGS4: 520 case ACPI_DMT_FLAGS4_0: 521 case ACPI_DMT_FLAGS4_4: 522 case ACPI_DMT_FLAGS4_8: 523 case ACPI_DMT_FLAGS4_12: 524 case ACPI_DMT_FLAGS16_16: 525 case ACPI_DMT_LABEL: 526 case ACPI_DMT_EXTRA_TEXT: 527 528 ByteLength = 0; 529 break; 530 531 case ACPI_DMT_UINT8: 532 case ACPI_DMT_CHKSUM: 533 case ACPI_DMT_SPACEID: 534 case ACPI_DMT_ACCWIDTH: 535 case ACPI_DMT_IVRS: 536 case ACPI_DMT_GTDT: 537 case ACPI_DMT_MADT: 538 case ACPI_DMT_PCCT: 539 case ACPI_DMT_PMTT: 540 case ACPI_DMT_PPTT: 541 case ACPI_DMT_SRAT: 542 case ACPI_DMT_ASF: 543 case ACPI_DMT_HESTNTYP: 544 case ACPI_DMT_FADTPM: 545 case ACPI_DMT_EINJACT: 546 case ACPI_DMT_EINJINST: 547 case ACPI_DMT_ERSTACT: 548 case ACPI_DMT_ERSTINST: 549 case ACPI_DMT_DMAR_SCOPE: 550 551 ByteLength = 1; 552 break; 553 554 case ACPI_DMT_UINT16: 555 case ACPI_DMT_DMAR: 556 case ACPI_DMT_HEST: 557 case ACPI_DMT_HMAT: 558 case ACPI_DMT_NFIT: 559 case ACPI_DMT_PCI_PATH: 560 561 ByteLength = 2; 562 break; 563 564 case ACPI_DMT_UINT24: 565 566 ByteLength = 3; 567 break; 568 569 case ACPI_DMT_UINT32: 570 case ACPI_DMT_NAME4: 571 case ACPI_DMT_SIG: 572 case ACPI_DMT_LPIT: 573 574 ByteLength = 4; 575 break; 576 577 case ACPI_DMT_UINT40: 578 579 ByteLength = 5; 580 break; 581 582 case ACPI_DMT_UINT48: 583 case ACPI_DMT_NAME6: 584 585 ByteLength = 6; 586 break; 587 588 case ACPI_DMT_UINT56: 589 case ACPI_DMT_BUF7: 590 591 ByteLength = 7; 592 break; 593 594 case ACPI_DMT_UINT64: 595 case ACPI_DMT_NAME8: 596 597 ByteLength = 8; 598 break; 599 600 case ACPI_DMT_STRING: 601 602 Value = DtGetFieldValue (Field); 603 if (Value) 604 { 605 ByteLength = strlen (Value) + 1; 606 } 607 else 608 { /* At this point, this is a fatal error */ 609 610 sprintf (MsgBuffer, "Expected \"%s\"", Info->Name); 611 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer); 612 return (0); 613 } 614 break; 615 616 case ACPI_DMT_GAS: 617 618 ByteLength = sizeof (ACPI_GENERIC_ADDRESS); 619 break; 620 621 case ACPI_DMT_HESTNTFY: 622 623 ByteLength = sizeof (ACPI_HEST_NOTIFY); 624 break; 625 626 case ACPI_DMT_IORTMEM: 627 628 ByteLength = sizeof (ACPI_IORT_MEMORY_ACCESS); 629 break; 630 631 case ACPI_DMT_BUFFER: 632 case ACPI_DMT_RAW_BUFFER: 633 634 Value = DtGetFieldValue (Field); 635 if (Value) 636 { 637 ByteLength = DtGetBufferLength (Value); 638 } 639 else 640 { /* At this point, this is a fatal error */ 641 642 sprintf (MsgBuffer, "Expected \"%s\"", Info->Name); 643 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer); 644 return (0); 645 } 646 break; 647 648 case ACPI_DMT_BUF10: 649 650 ByteLength = 10; 651 break; 652 653 case ACPI_DMT_BUF12: 654 655 ByteLength = 12; 656 break; 657 658 case ACPI_DMT_BUF16: 659 case ACPI_DMT_UUID: 660 661 ByteLength = 16; 662 break; 663 664 case ACPI_DMT_BUF128: 665 666 ByteLength = 128; 667 break; 668 669 case ACPI_DMT_UNICODE: 670 671 Value = DtGetFieldValue (Field); 672 673 /* TBD: error if Value is NULL? (as below?) */ 674 675 ByteLength = (strlen (Value) + 1) * sizeof(UINT16); 676 break; 677 678 default: 679 680 DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid table opcode"); 681 return (0); 682 } 683 684 return (ByteLength); 685 } 686 687 688 /****************************************************************************** 689 * 690 * FUNCTION: DtSum 691 * 692 * PARAMETERS: DT_WALK_CALLBACK: 693 * Subtable - Subtable 694 * Context - Unused 695 * ReturnValue - Store the checksum of subtable 696 * 697 * RETURN: Status 698 * 699 * DESCRIPTION: Get the checksum of subtable 700 * 701 *****************************************************************************/ 702 703 static void 704 DtSum ( 705 DT_SUBTABLE *Subtable, 706 void *Context, 707 void *ReturnValue) 708 { 709 UINT8 Checksum; 710 UINT8 *Sum = ReturnValue; 711 712 713 Checksum = AcpiTbChecksum (Subtable->Buffer, Subtable->Length); 714 *Sum = (UINT8) (*Sum + Checksum); 715 } 716 717 718 /****************************************************************************** 719 * 720 * FUNCTION: DtSetTableChecksum 721 * 722 * PARAMETERS: ChecksumPointer - Where to return the checksum 723 * 724 * RETURN: None 725 * 726 * DESCRIPTION: Set checksum of the whole data table into the checksum field 727 * 728 *****************************************************************************/ 729 730 void 731 DtSetTableChecksum ( 732 UINT8 *ChecksumPointer) 733 { 734 UINT8 Checksum = 0; 735 UINT8 OldSum; 736 737 738 DtWalkTableTree (Gbl_RootTable, DtSum, NULL, &Checksum); 739 740 OldSum = *ChecksumPointer; 741 Checksum = (UINT8) (Checksum - OldSum); 742 743 /* Compute the final checksum */ 744 745 Checksum = (UINT8) (0 - Checksum); 746 *ChecksumPointer = Checksum; 747 } 748 749 750 /****************************************************************************** 751 * 752 * FUNCTION: DtSetTableLength 753 * 754 * PARAMETERS: None 755 * 756 * RETURN: None 757 * 758 * DESCRIPTION: Walk the subtables and set all the length fields 759 * 760 *****************************************************************************/ 761 762 void 763 DtSetTableLength ( 764 void) 765 { 766 DT_SUBTABLE *ParentTable; 767 DT_SUBTABLE *ChildTable; 768 769 770 ParentTable = Gbl_RootTable; 771 ChildTable = NULL; 772 773 if (!ParentTable) 774 { 775 return; 776 } 777 778 DtSetSubtableLength (ParentTable); 779 780 while (1) 781 { 782 ChildTable = DtGetNextSubtable (ParentTable, ChildTable); 783 if (ChildTable) 784 { 785 if (ChildTable->LengthField) 786 { 787 DtSetSubtableLength (ChildTable); 788 } 789 790 if (ChildTable->Child) 791 { 792 ParentTable = ChildTable; 793 ChildTable = NULL; 794 } 795 else 796 { 797 ParentTable->TotalLength += ChildTable->TotalLength; 798 if (ParentTable->LengthField) 799 { 800 DtSetSubtableLength (ParentTable); 801 } 802 } 803 } 804 else 805 { 806 ChildTable = ParentTable; 807 808 if (ChildTable == Gbl_RootTable) 809 { 810 break; 811 } 812 813 ParentTable = DtGetParentSubtable (ParentTable); 814 815 ParentTable->TotalLength += ChildTable->TotalLength; 816 if (ParentTable->LengthField) 817 { 818 DtSetSubtableLength (ParentTable); 819 } 820 } 821 } 822 } 823 824 825 /****************************************************************************** 826 * 827 * FUNCTION: DtWalkTableTree 828 * 829 * PARAMETERS: StartTable - Subtable in the tree where walking begins 830 * UserFunction - Called during the walk 831 * Context - Passed to user function 832 * ReturnValue - The return value of UserFunction 833 * 834 * RETURN: None 835 * 836 * DESCRIPTION: Performs a depth-first walk of the subtable tree 837 * 838 *****************************************************************************/ 839 840 void 841 DtWalkTableTree ( 842 DT_SUBTABLE *StartTable, 843 DT_WALK_CALLBACK UserFunction, 844 void *Context, 845 void *ReturnValue) 846 { 847 DT_SUBTABLE *ParentTable; 848 DT_SUBTABLE *ChildTable; 849 850 851 ParentTable = StartTable; 852 ChildTable = NULL; 853 854 if (!ParentTable) 855 { 856 return; 857 } 858 859 UserFunction (ParentTable, Context, ReturnValue); 860 861 while (1) 862 { 863 ChildTable = DtGetNextSubtable (ParentTable, ChildTable); 864 if (ChildTable) 865 { 866 UserFunction (ChildTable, Context, ReturnValue); 867 868 if (ChildTable->Child) 869 { 870 ParentTable = ChildTable; 871 ChildTable = NULL; 872 } 873 } 874 else 875 { 876 ChildTable = ParentTable; 877 if (ChildTable == Gbl_RootTable) 878 { 879 break; 880 } 881 882 ParentTable = DtGetParentSubtable (ParentTable); 883 884 if (ChildTable->Peer == StartTable) 885 { 886 break; 887 } 888 } 889 } 890 } 891 892 893 /******************************************************************************* 894 * 895 * FUNCTION: UtSubtableCacheCalloc 896 * 897 * PARAMETERS: None 898 * 899 * RETURN: Pointer to the buffer. Aborts on allocation failure 900 * 901 * DESCRIPTION: Allocate a subtable object buffer. Bypass the local 902 * dynamic memory manager for performance reasons (This has a 903 * major impact on the speed of the compiler.) 904 * 905 ******************************************************************************/ 906 907 DT_SUBTABLE * 908 UtSubtableCacheCalloc ( 909 void) 910 { 911 ASL_CACHE_INFO *Cache; 912 913 914 if (Gbl_SubtableCacheNext >= Gbl_SubtableCacheLast) 915 { 916 /* Allocate a new buffer */ 917 918 Cache = UtLocalCalloc (sizeof (Cache->Next) + 919 (sizeof (DT_SUBTABLE) * ASL_SUBTABLE_CACHE_SIZE)); 920 921 /* Link new cache buffer to head of list */ 922 923 Cache->Next = Gbl_SubtableCacheList; 924 Gbl_SubtableCacheList = Cache; 925 926 /* Setup cache management pointers */ 927 928 Gbl_SubtableCacheNext = ACPI_CAST_PTR (DT_SUBTABLE, Cache->Buffer); 929 Gbl_SubtableCacheLast = Gbl_SubtableCacheNext + ASL_SUBTABLE_CACHE_SIZE; 930 } 931 932 Gbl_SubtableCount++; 933 return (Gbl_SubtableCacheNext++); 934 } 935 936 937 /******************************************************************************* 938 * 939 * FUNCTION: UtFieldCacheCalloc 940 * 941 * PARAMETERS: None 942 * 943 * RETURN: Pointer to the buffer. Aborts on allocation failure 944 * 945 * DESCRIPTION: Allocate a field object buffer. Bypass the local 946 * dynamic memory manager for performance reasons (This has a 947 * major impact on the speed of the compiler.) 948 * 949 ******************************************************************************/ 950 951 DT_FIELD * 952 UtFieldCacheCalloc ( 953 void) 954 { 955 ASL_CACHE_INFO *Cache; 956 957 958 if (Gbl_FieldCacheNext >= Gbl_FieldCacheLast) 959 { 960 /* Allocate a new buffer */ 961 962 Cache = UtLocalCalloc (sizeof (Cache->Next) + 963 (sizeof (DT_FIELD) * ASL_FIELD_CACHE_SIZE)); 964 965 /* Link new cache buffer to head of list */ 966 967 Cache->Next = Gbl_FieldCacheList; 968 Gbl_FieldCacheList = Cache; 969 970 /* Setup cache management pointers */ 971 972 Gbl_FieldCacheNext = ACPI_CAST_PTR (DT_FIELD, Cache->Buffer); 973 Gbl_FieldCacheLast = Gbl_FieldCacheNext + ASL_FIELD_CACHE_SIZE; 974 } 975 976 Gbl_FieldCount++; 977 return (Gbl_FieldCacheNext++); 978 } 979 980 981 /******************************************************************************* 982 * 983 * FUNCTION: DtDeleteCaches 984 * 985 * PARAMETERS: None 986 * 987 * RETURN: None 988 * 989 * DESCRIPTION: Delete all local cache buffer blocks 990 * 991 ******************************************************************************/ 992 993 void 994 DtDeleteCaches ( 995 void) 996 { 997 UINT32 BufferCount; 998 ASL_CACHE_INFO *Next; 999 1000 1001 /* Field cache */ 1002 1003 BufferCount = 0; 1004 while (Gbl_FieldCacheList) 1005 { 1006 Next = Gbl_FieldCacheList->Next; 1007 ACPI_FREE (Gbl_FieldCacheList); 1008 Gbl_FieldCacheList = Next; 1009 BufferCount++; 1010 } 1011 1012 DbgPrint (ASL_DEBUG_OUTPUT, 1013 "%u Fields, Buffer size: %u fields (%u bytes), %u Buffers\n", 1014 Gbl_FieldCount, ASL_FIELD_CACHE_SIZE, 1015 (sizeof (DT_FIELD) * ASL_FIELD_CACHE_SIZE), BufferCount); 1016 1017 Gbl_FieldCount = 0; 1018 Gbl_FieldCacheNext = NULL; 1019 Gbl_FieldCacheLast = NULL; 1020 1021 /* Subtable cache */ 1022 1023 BufferCount = 0; 1024 while (Gbl_SubtableCacheList) 1025 { 1026 Next = Gbl_SubtableCacheList->Next; 1027 ACPI_FREE (Gbl_SubtableCacheList); 1028 Gbl_SubtableCacheList = Next; 1029 BufferCount++; 1030 } 1031 1032 DbgPrint (ASL_DEBUG_OUTPUT, 1033 "%u Subtables, Buffer size: %u subtables (%u bytes), %u Buffers\n", 1034 Gbl_SubtableCount, ASL_SUBTABLE_CACHE_SIZE, 1035 (sizeof (DT_SUBTABLE) * ASL_SUBTABLE_CACHE_SIZE), BufferCount); 1036 1037 Gbl_SubtableCount = 0; 1038 Gbl_SubtableCacheNext = NULL; 1039 Gbl_SubtableCacheLast = NULL; 1040 } 1041