1 /****************************************************************************** 2 * 3 * Module Name: dtcompiler.h - header for data table compiler 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2022, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44 #define __DTCOMPILER_H__ 45 46 #ifndef _DTCOMPILER 47 #define _DTCOMPILER 48 49 #include "acdisasm.h" 50 51 52 #define ASL_FIELD_CACHE_SIZE 512 53 #define ASL_SUBTABLE_CACHE_SIZE 128 54 55 56 #undef DT_EXTERN 57 58 #ifdef _DECLARE_DT_GLOBALS 59 #define DT_EXTERN 60 #define DT_INIT_GLOBAL(a,b) (a)=(b) 61 #else 62 #define DT_EXTERN extern 63 #define DT_INIT_GLOBAL(a,b) (a) 64 #endif 65 66 67 /* Types for individual fields (one per input line) */ 68 69 #define DT_FIELD_TYPE_STRING 0 70 #define DT_FIELD_TYPE_INTEGER 1 71 #define DT_FIELD_TYPE_BUFFER 2 72 #define DT_FIELD_TYPE_PCI_PATH 3 73 #define DT_FIELD_TYPE_FLAG 4 74 #define DT_FIELD_TYPE_FLAGS_INTEGER 5 75 #define DT_FIELD_TYPE_INLINE_SUBTABLE 6 76 #define DT_FIELD_TYPE_UUID 7 77 #define DT_FIELD_TYPE_UNICODE 8 78 #define DT_FIELD_TYPE_DEVICE_PATH 9 79 #define DT_FIELD_TYPE_LABEL 10 80 81 82 /* 83 * Structure used for each individual field within an ACPI table 84 */ 85 typedef struct dt_field 86 { 87 char *Name; /* Field name (from name : value) */ 88 char *Value; /* Field value (from name : value) */ 89 UINT32 StringLength; /* Length of Value */ 90 struct dt_field *Next; /* Next field */ 91 struct dt_field *NextLabel; /* If field is a label, next label */ 92 UINT32 Line; /* Line number for this field */ 93 UINT32 ByteOffset; /* Offset in source file for field */ 94 UINT32 NameColumn; /* Start column for field name */ 95 UINT32 Column; /* Start column for field value */ 96 UINT32 TableOffset; /* Binary offset within ACPI table */ 97 UINT8 Flags; 98 99 } DT_FIELD; 100 101 /* Flags for above */ 102 103 #define DT_FIELD_NOT_ALLOCATED 1 104 105 /* 106 * Structure used for each individual key or value 107 */ 108 typedef struct dt_table_unit 109 { 110 char *Value; /* Field value (from name : value) */ 111 UINT32 Line; /* Line number for this field */ 112 UINT32 Column; /* Start column for field value */ 113 114 } DT_TABLE_UNIT; 115 116 117 /* 118 * Structure used for individual subtables within an ACPI table 119 */ 120 typedef struct dt_subtable 121 { 122 struct dt_subtable *Parent; 123 struct dt_subtable *Child; 124 struct dt_subtable *Peer; 125 struct dt_subtable *StackTop; 126 UINT8 *Buffer; 127 UINT8 *LengthField; 128 char *Name; 129 UINT32 Length; 130 UINT32 TotalLength; 131 UINT32 SizeOfLengthField; 132 UINT16 Depth; 133 UINT8 Flags; 134 135 } DT_SUBTABLE; 136 137 138 /* 139 * Globals 140 */ 141 142 /* List of all field names and values from the input source */ 143 144 DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*AslGbl_FieldList, NULL); 145 146 /* List of all compiled tables and subtables */ 147 148 DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*AslGbl_RootTable, NULL); 149 150 /* Stack for subtables */ 151 152 DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*AslGbl_SubtableStack, NULL); 153 154 /* List for defined labels */ 155 156 DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*AslGbl_LabelList, NULL); 157 158 /* Current offset within the binary output table */ 159 160 DT_EXTERN UINT32 DT_INIT_GLOBAL (AslGbl_CurrentTableOffset, 0); 161 162 /* Data table compiler Flex/Bison prototype */ 163 164 DT_EXTERN BOOLEAN DT_INIT_GLOBAL (AslGbl_DtLexBisonPrototype, FALSE); 165 166 /* Local caches */ 167 168 DT_EXTERN UINT32 DT_INIT_GLOBAL (AslGbl_SubtableCount, 0); 169 DT_EXTERN ASL_CACHE_INFO DT_INIT_GLOBAL (*AslGbl_SubtableCacheList, NULL); 170 DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*AslGbl_SubtableCacheNext, NULL); 171 DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*AslGbl_SubtableCacheLast, NULL); 172 173 DT_EXTERN UINT32 DT_INIT_GLOBAL (AslGbl_FieldCount, 0); 174 DT_EXTERN ASL_CACHE_INFO DT_INIT_GLOBAL (*AslGbl_FieldCacheList, NULL); 175 DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*AslGbl_FieldCacheNext, NULL); 176 DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*AslGbl_FieldCacheLast, NULL); 177 178 179 /* dtcompiler - main module */ 180 181 ACPI_STATUS 182 DtCompileTable ( 183 DT_FIELD **Field, 184 ACPI_DMTABLE_INFO *Info, 185 DT_SUBTABLE **RetSubtable); 186 187 ACPI_STATUS 188 DtCompileTwoSubtables ( 189 void **List, 190 ACPI_DMTABLE_INFO *TableInfo1, 191 ACPI_DMTABLE_INFO *TableInfo2); 192 193 ACPI_STATUS 194 DtCompilePadding ( 195 UINT32 Length, 196 DT_SUBTABLE **RetSubtable); 197 198 199 /* dtio - binary and text input/output */ 200 201 UINT32 202 DtGetNextLine ( 203 FILE *Handle, 204 UINT32 Flags); 205 206 /* Flags for DtGetNextLine */ 207 208 #define DT_ALLOW_MULTILINE_QUOTES 0x01 209 210 211 DT_FIELD * 212 DtScanFile ( 213 FILE *Handle); 214 215 void 216 DtOutputBinary ( 217 DT_SUBTABLE *RootTable); 218 219 void 220 DtDumpSubtableList ( 221 void); 222 223 void 224 DtDumpFieldList ( 225 DT_FIELD *Field); 226 227 void 228 DtWriteFieldToListing ( 229 UINT8 *Buffer, 230 DT_FIELD *Field, 231 UINT32 Length); 232 233 void 234 DtWriteTableToListing ( 235 void); 236 237 238 /* dtsubtable - compile subtables */ 239 240 void 241 DtCreateSubtable ( 242 UINT8 *Buffer, 243 UINT32 Length, 244 DT_SUBTABLE **RetSubtable); 245 246 UINT32 247 DtGetSubtableLength ( 248 DT_FIELD *Field, 249 ACPI_DMTABLE_INFO *Info); 250 251 void 252 DtSetSubtableLength ( 253 DT_SUBTABLE *Subtable); 254 255 void 256 DtPushSubtable ( 257 DT_SUBTABLE *Subtable); 258 259 void 260 DtPopSubtable ( 261 void); 262 263 DT_SUBTABLE * 264 DtPeekSubtable ( 265 void); 266 267 void 268 DtInsertSubtable ( 269 DT_SUBTABLE *ParentTable, 270 DT_SUBTABLE *Subtable); 271 272 DT_SUBTABLE * 273 DtGetNextSubtable ( 274 DT_SUBTABLE *ParentTable, 275 DT_SUBTABLE *ChildTable); 276 277 DT_SUBTABLE * 278 DtGetParentSubtable ( 279 DT_SUBTABLE *Subtable); 280 281 282 /* dtexpress - Integer expressions and labels */ 283 284 ACPI_STATUS 285 DtResolveIntegerExpression ( 286 DT_FIELD *Field, 287 UINT64 *ReturnValue); 288 289 UINT64 290 DtDoOperator ( 291 UINT64 LeftValue, 292 UINT32 Operator, 293 UINT64 RightValue); 294 295 UINT64 296 DtResolveLabel ( 297 char *LabelString); 298 299 void 300 DtDetectAllLabels ( 301 DT_FIELD *FieldList); 302 303 304 /* dtfield - Compile individual fields within a table */ 305 306 void 307 DtCompileOneField ( 308 UINT8 *Buffer, 309 DT_FIELD *Field, 310 UINT32 ByteLength, 311 UINT8 Type, 312 UINT8 Flags); 313 314 void 315 DtCompileInteger ( 316 UINT8 *Buffer, 317 DT_FIELD *Field, 318 UINT32 ByteLength, 319 UINT8 Flags); 320 321 UINT32 322 DtCompileBuffer ( 323 UINT8 *Buffer, 324 char *Value, 325 DT_FIELD *Field, 326 UINT32 ByteLength); 327 328 void 329 DtCompileFlag ( 330 UINT8 *Buffer, 331 DT_FIELD *Field, 332 ACPI_DMTABLE_INFO *Info); 333 334 335 /* dtfield - DT_FIELD operations */ 336 337 void 338 DtLinkField ( 339 DT_FIELD *Field); 340 341 void 342 DtCreateField ( 343 DT_TABLE_UNIT *FieldKey, 344 DT_TABLE_UNIT *FieldValue, 345 UINT32 Offset); 346 347 DT_TABLE_UNIT * 348 DtCreateTableUnit ( 349 char *Data, 350 UINT32 Line, 351 UINT32 Column); 352 353 354 /* dtparser - lex/yacc files */ 355 356 int 357 DtCompilerParserparse ( 358 void); 359 360 UINT64 361 DtEvaluateExpression ( 362 char *ExprString); 363 364 void 365 DtCompilerInitLexer ( 366 FILE *inFile); 367 368 void 369 DtCompilerTerminateLexer ( 370 void); 371 372 int 373 DtInitLexer ( 374 char *String); 375 376 void 377 DtTerminateLexer ( 378 void); 379 380 char * 381 DtGetOpName ( 382 UINT32 ParseOpcode); 383 384 385 /* dtutils - Miscellaneous utilities */ 386 387 typedef 388 void (*DT_WALK_CALLBACK) ( 389 DT_SUBTABLE *Subtable, 390 void *Context, 391 void *ReturnValue); 392 393 void 394 DtWalkTableTree ( 395 DT_SUBTABLE *StartTable, 396 DT_WALK_CALLBACK UserFunction, 397 void *Context, 398 void *ReturnValue); 399 400 void 401 DtError ( 402 UINT8 Level, 403 UINT16 MessageId, 404 DT_FIELD *FieldObject, 405 char *ExtraMessage); 406 407 void 408 DtNameError ( 409 UINT8 Level, 410 UINT16 MessageId, 411 DT_FIELD *FieldObject, 412 char *ExtraMessage); 413 414 void 415 DtFatal ( 416 UINT16 MessageId, 417 DT_FIELD *FieldObject, 418 char *ExtraMessage); 419 420 UINT64 421 DtDoConstant ( 422 char *String); 423 424 char* 425 DtGetFieldValue ( 426 DT_FIELD *Field); 427 428 UINT8 429 DtGetFieldType ( 430 ACPI_DMTABLE_INFO *Info); 431 432 UINT32 433 DtGetBufferLength ( 434 char *Buffer); 435 436 UINT32 437 DtGetFieldLength ( 438 DT_FIELD *Field, 439 ACPI_DMTABLE_INFO *Info); 440 441 void 442 DtSetTableChecksum ( 443 UINT8 *ChecksumPointer); 444 445 void 446 DtSetTableLength( 447 void); 448 449 450 /* dttable - individual table compilation */ 451 452 ACPI_STATUS 453 DtCompileFacs ( 454 DT_FIELD **PFieldList); 455 456 ACPI_STATUS 457 DtCompileRsdp ( 458 DT_FIELD **PFieldList); 459 460 ACPI_STATUS 461 DtCompileAest ( 462 void **PFieldList); 463 464 ACPI_STATUS 465 DtCompileApmt ( 466 void **PFieldList); 467 468 ACPI_STATUS 469 DtCompileAsf ( 470 void **PFieldList); 471 472 ACPI_STATUS 473 DtCompileCdat ( 474 void **PFieldList); 475 476 ACPI_STATUS 477 DtCompileCedt ( 478 void **PFieldList); 479 480 ACPI_STATUS 481 DtCompileCpep ( 482 void **PFieldList); 483 484 ACPI_STATUS 485 DtCompileCsrt ( 486 void **PFieldList); 487 488 ACPI_STATUS 489 DtCompileDbg2 ( 490 void **PFieldList); 491 492 ACPI_STATUS 493 DtCompileDmar ( 494 void **PFieldList); 495 496 ACPI_STATUS 497 DtCompileDrtm ( 498 void **PFieldList); 499 500 ACPI_STATUS 501 DtCompileEinj ( 502 void **PFieldList); 503 504 ACPI_STATUS 505 DtCompileErst ( 506 void **PFieldList); 507 508 ACPI_STATUS 509 DtCompileFadt ( 510 void **PFieldList); 511 512 ACPI_STATUS 513 DtCompileFpdt ( 514 void **PFieldList); 515 516 ACPI_STATUS 517 DtCompileGtdt ( 518 void **PFieldList); 519 520 ACPI_STATUS 521 DtCompileHest ( 522 void **PFieldList); 523 524 ACPI_STATUS 525 DtCompileHmat ( 526 void **PFieldList); 527 528 ACPI_STATUS 529 DtCompileIort ( 530 void **PFieldList); 531 532 ACPI_STATUS 533 DtCompileIvrs ( 534 void **PFieldList); 535 536 ACPI_STATUS 537 DtCompileLpit ( 538 void **PFieldList); 539 540 ACPI_STATUS 541 DtCompileMadt ( 542 void **PFieldList); 543 544 ACPI_STATUS 545 DtCompileMcfg ( 546 void **PFieldList); 547 548 ACPI_STATUS 549 DtCompileMpst ( 550 void **PFieldList); 551 552 ACPI_STATUS 553 DtCompileMsct ( 554 void **PFieldList); 555 556 ACPI_STATUS 557 DtCompileNfit ( 558 void **PFieldList); 559 560 ACPI_STATUS 561 DtCompileNhlt ( 562 void **PFieldList); 563 564 ACPI_STATUS 565 DtCompilePcct ( 566 void **PFieldList); 567 568 ACPI_STATUS 569 DtCompilePdtt ( 570 void **PFieldList); 571 572 ACPI_STATUS 573 DtCompilePhat ( 574 void **PFieldList); 575 576 ACPI_STATUS 577 DtCompilePmtt ( 578 void **PFieldList); 579 580 ACPI_STATUS 581 DtCompilePptt ( 582 void **PFieldList); 583 584 ACPI_STATUS 585 DtCompilePrmt ( 586 void **PFieldList); 587 588 ACPI_STATUS 589 DtCompileRgrt ( 590 void **PFieldList); 591 592 ACPI_STATUS 593 DtCompileRsdt ( 594 void **PFieldList); 595 596 ACPI_STATUS 597 DtCompileS3pt ( 598 DT_FIELD **PFieldList); 599 600 ACPI_STATUS 601 DtCompileSdev ( 602 void **PFieldList); 603 604 ACPI_STATUS 605 DtCompileSlic ( 606 void **PFieldList); 607 608 ACPI_STATUS 609 DtCompileSlit ( 610 void **PFieldList); 611 612 ACPI_STATUS 613 DtCompileSrat ( 614 void **PFieldList); 615 616 ACPI_STATUS 617 DtCompileStao ( 618 void **PFieldList); 619 620 ACPI_STATUS 621 DtCompileSvkl ( 622 void **PFieldList); 623 624 ACPI_STATUS 625 DtCompileTcpa ( 626 void **PFieldList); 627 628 ACPI_STATUS 629 DtCompileTpm2 ( 630 void **PFieldList); 631 632 ACPI_STATUS 633 DtCompileUefi ( 634 void **PFieldList); 635 636 ACPI_STATUS 637 DtCompileViot ( 638 void **PFieldList); 639 640 ACPI_STATUS 641 DtCompileWdat ( 642 void **PFieldList); 643 644 ACPI_STATUS 645 DtCompileWpbt ( 646 void **PFieldList); 647 648 ACPI_STATUS 649 DtCompileXsdt ( 650 void **PFieldList); 651 652 ACPI_STATUS 653 DtCompileGeneric ( 654 void **PFieldList, 655 char *TermFieldName, 656 UINT32 *PFieldLength); 657 658 ACPI_DMTABLE_INFO * 659 DtGetGenericTableInfo ( 660 char *Name); 661 662 /* ACPI Table templates */ 663 664 extern const unsigned char TemplateAest[]; 665 extern const unsigned char TemplateAgdi[]; 666 extern const unsigned char TemplateApmt[]; 667 extern const unsigned char TemplateAsf[]; 668 extern const unsigned char TemplateBoot[]; 669 extern const unsigned char TemplateBdat[]; 670 extern const unsigned char TemplateBert[]; 671 extern const unsigned char TemplateBgrt[]; 672 extern const unsigned char TemplateCcel[]; 673 extern const unsigned char TemplateCdat[]; 674 extern const unsigned char TemplateCedt[]; 675 extern const unsigned char TemplateCpep[]; 676 extern const unsigned char TemplateCsrt[]; 677 extern const unsigned char TemplateDbg2[]; 678 extern const unsigned char TemplateDbgp[]; 679 extern const unsigned char TemplateDmar[]; 680 extern const unsigned char TemplateDrtm[]; 681 extern const unsigned char TemplateEcdt[]; 682 extern const unsigned char TemplateEinj[]; 683 extern const unsigned char TemplateErst[]; 684 extern const unsigned char TemplateFadt[]; 685 extern const unsigned char TemplateFpdt[]; 686 extern const unsigned char TemplateGtdt[]; 687 extern const unsigned char TemplateHest[]; 688 extern const unsigned char TemplateHmat[]; 689 extern const unsigned char TemplateHpet[]; 690 extern const unsigned char TemplateIort[]; 691 extern const unsigned char TemplateIvrs[]; 692 extern const unsigned char TemplateLpit[]; 693 extern const unsigned char TemplateMadt[]; 694 extern const unsigned char TemplateMcfg[]; 695 extern const unsigned char TemplateMchi[]; 696 extern const unsigned char TemplateMpst[]; 697 extern const unsigned char TemplateMsct[]; 698 extern const unsigned char TemplateMsdm[]; 699 extern const unsigned char TemplateNfit[]; 700 extern const unsigned char TemplateNhlt[]; 701 extern const unsigned char TemplatePcct[]; 702 extern const unsigned char TemplatePdtt[]; 703 extern const unsigned char TemplatePhat[]; 704 extern const unsigned char TemplatePmtt[]; 705 extern const unsigned char TemplatePptt[]; 706 extern const unsigned char TemplatePrmt[]; 707 extern const unsigned char TemplateRasf[]; 708 extern const unsigned char TemplateRgrt[]; 709 extern const unsigned char TemplateRsdt[]; 710 extern const unsigned char TemplateS3pt[]; 711 extern const unsigned char TemplateSbst[]; 712 extern const unsigned char TemplateSdei[]; 713 extern const unsigned char TemplateSdev[]; 714 extern const unsigned char TemplateSlic[]; 715 extern const unsigned char TemplateSlit[]; 716 extern const unsigned char TemplateSpcr[]; 717 extern const unsigned char TemplateSpmi[]; 718 extern const unsigned char TemplateSrat[]; 719 extern const unsigned char TemplateStao[]; 720 extern const unsigned char TemplateSvkl[]; 721 extern const unsigned char TemplateTcpa[]; 722 extern const unsigned char TemplateTdel[]; 723 extern const unsigned char TemplateTpm2[]; 724 extern const unsigned char TemplateUefi[]; 725 extern const unsigned char TemplateViot[]; 726 extern const unsigned char TemplateWaet[]; 727 extern const unsigned char TemplateWdat[]; 728 extern const unsigned char TemplateWddt[]; 729 extern const unsigned char TemplateWdrt[]; 730 extern const unsigned char TemplateWpbt[]; 731 extern const unsigned char TemplateWsmt[]; 732 extern const unsigned char TemplateXenv[]; 733 extern const unsigned char TemplateXsdt[]; 734 735 #endif 736