1 /****************************************************************************** 2 * 3 * Module Name: dtcompiler.h - header for data table compiler 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2018, 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 MERCHANTIBILITY 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 /* 107 * Structure used for individual subtables within an ACPI table 108 */ 109 typedef struct dt_subtable 110 { 111 struct dt_subtable *Parent; 112 struct dt_subtable *Child; 113 struct dt_subtable *Peer; 114 struct dt_subtable *StackTop; 115 UINT8 *Buffer; 116 UINT8 *LengthField; 117 char *Name; 118 UINT32 Length; 119 UINT32 TotalLength; 120 UINT32 SizeOfLengthField; 121 UINT16 Depth; 122 UINT8 Flags; 123 124 } DT_SUBTABLE; 125 126 127 /* 128 * Globals 129 */ 130 131 /* List of all field names and values from the input source */ 132 133 DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*Gbl_FieldList, NULL); 134 135 /* List of all compiled tables and subtables */ 136 137 DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*Gbl_RootTable, NULL); 138 139 /* Stack for subtables */ 140 141 DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*Gbl_SubtableStack, NULL); 142 143 /* List for defined labels */ 144 145 DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*Gbl_LabelList, NULL); 146 147 /* Current offset within the binary output table */ 148 149 DT_EXTERN UINT32 DT_INIT_GLOBAL (Gbl_CurrentTableOffset, 0); 150 151 /* Local caches */ 152 153 DT_EXTERN UINT32 DT_INIT_GLOBAL (Gbl_SubtableCount, 0); 154 DT_EXTERN ASL_CACHE_INFO DT_INIT_GLOBAL (*Gbl_SubtableCacheList, NULL); 155 DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*Gbl_SubtableCacheNext, NULL); 156 DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*Gbl_SubtableCacheLast, NULL); 157 158 DT_EXTERN UINT32 DT_INIT_GLOBAL (Gbl_FieldCount, 0); 159 DT_EXTERN ASL_CACHE_INFO DT_INIT_GLOBAL (*Gbl_FieldCacheList, NULL); 160 DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*Gbl_FieldCacheNext, NULL); 161 DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*Gbl_FieldCacheLast, NULL); 162 163 164 /* dtcompiler - main module */ 165 166 ACPI_STATUS 167 DtCompileTable ( 168 DT_FIELD **Field, 169 ACPI_DMTABLE_INFO *Info, 170 DT_SUBTABLE **RetSubtable); 171 172 ACPI_STATUS 173 DtCompileTwoSubtables ( 174 void **List, 175 ACPI_DMTABLE_INFO *TableInfo1, 176 ACPI_DMTABLE_INFO *TableInfo2); 177 178 ACPI_STATUS 179 DtCompilePadding ( 180 UINT32 Length, 181 DT_SUBTABLE **RetSubtable); 182 183 184 /* dtio - binary and text input/output */ 185 186 UINT32 187 DtGetNextLine ( 188 FILE *Handle, 189 UINT32 Flags); 190 191 /* Flags for DtGetNextLine */ 192 193 #define DT_ALLOW_MULTILINE_QUOTES 0x01 194 195 196 DT_FIELD * 197 DtScanFile ( 198 FILE *Handle); 199 200 void 201 DtOutputBinary ( 202 DT_SUBTABLE *RootTable); 203 204 void 205 DtDumpSubtableList ( 206 void); 207 208 void 209 DtDumpFieldList ( 210 DT_FIELD *Field); 211 212 void 213 DtWriteFieldToListing ( 214 UINT8 *Buffer, 215 DT_FIELD *Field, 216 UINT32 Length); 217 218 void 219 DtWriteTableToListing ( 220 void); 221 222 223 /* dtsubtable - compile subtables */ 224 225 void 226 DtCreateSubtable ( 227 UINT8 *Buffer, 228 UINT32 Length, 229 DT_SUBTABLE **RetSubtable); 230 231 UINT32 232 DtGetSubtableLength ( 233 DT_FIELD *Field, 234 ACPI_DMTABLE_INFO *Info); 235 236 void 237 DtSetSubtableLength ( 238 DT_SUBTABLE *Subtable); 239 240 void 241 DtPushSubtable ( 242 DT_SUBTABLE *Subtable); 243 244 void 245 DtPopSubtable ( 246 void); 247 248 DT_SUBTABLE * 249 DtPeekSubtable ( 250 void); 251 252 void 253 DtInsertSubtable ( 254 DT_SUBTABLE *ParentTable, 255 DT_SUBTABLE *Subtable); 256 257 DT_SUBTABLE * 258 DtGetNextSubtable ( 259 DT_SUBTABLE *ParentTable, 260 DT_SUBTABLE *ChildTable); 261 262 DT_SUBTABLE * 263 DtGetParentSubtable ( 264 DT_SUBTABLE *Subtable); 265 266 267 /* dtexpress - Integer expressions and labels */ 268 269 ACPI_STATUS 270 DtResolveIntegerExpression ( 271 DT_FIELD *Field, 272 UINT64 *ReturnValue); 273 274 UINT64 275 DtDoOperator ( 276 UINT64 LeftValue, 277 UINT32 Operator, 278 UINT64 RightValue); 279 280 UINT64 281 DtResolveLabel ( 282 char *LabelString); 283 284 void 285 DtDetectAllLabels ( 286 DT_FIELD *FieldList); 287 288 289 /* dtfield - Compile individual fields within a table */ 290 291 void 292 DtCompileOneField ( 293 UINT8 *Buffer, 294 DT_FIELD *Field, 295 UINT32 ByteLength, 296 UINT8 Type, 297 UINT8 Flags); 298 299 void 300 DtCompileInteger ( 301 UINT8 *Buffer, 302 DT_FIELD *Field, 303 UINT32 ByteLength, 304 UINT8 Flags); 305 306 UINT32 307 DtCompileBuffer ( 308 UINT8 *Buffer, 309 char *Value, 310 DT_FIELD *Field, 311 UINT32 ByteLength); 312 313 void 314 DtCompileFlag ( 315 UINT8 *Buffer, 316 DT_FIELD *Field, 317 ACPI_DMTABLE_INFO *Info); 318 319 320 /* dtparser - lex/yacc files */ 321 322 UINT64 323 DtEvaluateExpression ( 324 char *ExprString); 325 326 int 327 DtInitLexer ( 328 char *String); 329 330 void 331 DtTerminateLexer ( 332 void); 333 334 char * 335 DtGetOpName ( 336 UINT32 ParseOpcode); 337 338 339 /* dtutils - Miscellaneous utilities */ 340 341 typedef 342 void (*DT_WALK_CALLBACK) ( 343 DT_SUBTABLE *Subtable, 344 void *Context, 345 void *ReturnValue); 346 347 void 348 DtWalkTableTree ( 349 DT_SUBTABLE *StartTable, 350 DT_WALK_CALLBACK UserFunction, 351 void *Context, 352 void *ReturnValue); 353 354 void 355 DtError ( 356 UINT8 Level, 357 UINT16 MessageId, 358 DT_FIELD *FieldObject, 359 char *ExtraMessage); 360 361 void 362 DtNameError ( 363 UINT8 Level, 364 UINT16 MessageId, 365 DT_FIELD *FieldObject, 366 char *ExtraMessage); 367 368 void 369 DtFatal ( 370 UINT16 MessageId, 371 DT_FIELD *FieldObject, 372 char *ExtraMessage); 373 374 UINT64 375 DtDoConstant ( 376 char *String); 377 378 char* 379 DtGetFieldValue ( 380 DT_FIELD *Field); 381 382 UINT8 383 DtGetFieldType ( 384 ACPI_DMTABLE_INFO *Info); 385 386 UINT32 387 DtGetBufferLength ( 388 char *Buffer); 389 390 UINT32 391 DtGetFieldLength ( 392 DT_FIELD *Field, 393 ACPI_DMTABLE_INFO *Info); 394 395 void 396 DtSetTableChecksum ( 397 UINT8 *ChecksumPointer); 398 399 void 400 DtSetTableLength( 401 void); 402 403 404 /* dttable - individual table compilation */ 405 406 ACPI_STATUS 407 DtCompileFacs ( 408 DT_FIELD **PFieldList); 409 410 ACPI_STATUS 411 DtCompileRsdp ( 412 DT_FIELD **PFieldList); 413 414 ACPI_STATUS 415 DtCompileAsf ( 416 void **PFieldList); 417 418 ACPI_STATUS 419 DtCompileCpep ( 420 void **PFieldList); 421 422 ACPI_STATUS 423 DtCompileCsrt ( 424 void **PFieldList); 425 426 ACPI_STATUS 427 DtCompileDbg2 ( 428 void **PFieldList); 429 430 ACPI_STATUS 431 DtCompileDmar ( 432 void **PFieldList); 433 434 ACPI_STATUS 435 DtCompileDrtm ( 436 void **PFieldList); 437 438 ACPI_STATUS 439 DtCompileEinj ( 440 void **PFieldList); 441 442 ACPI_STATUS 443 DtCompileErst ( 444 void **PFieldList); 445 446 ACPI_STATUS 447 DtCompileFadt ( 448 void **PFieldList); 449 450 ACPI_STATUS 451 DtCompileFpdt ( 452 void **PFieldList); 453 454 ACPI_STATUS 455 DtCompileGtdt ( 456 void **PFieldList); 457 458 ACPI_STATUS 459 DtCompileHest ( 460 void **PFieldList); 461 462 ACPI_STATUS 463 DtCompileHmat ( 464 void **PFieldList); 465 466 ACPI_STATUS 467 DtCompileIort ( 468 void **PFieldList); 469 470 ACPI_STATUS 471 DtCompileIvrs ( 472 void **PFieldList); 473 474 ACPI_STATUS 475 DtCompileLpit ( 476 void **PFieldList); 477 478 ACPI_STATUS 479 DtCompileMadt ( 480 void **PFieldList); 481 482 ACPI_STATUS 483 DtCompileMcfg ( 484 void **PFieldList); 485 486 ACPI_STATUS 487 DtCompileMpst ( 488 void **PFieldList); 489 490 ACPI_STATUS 491 DtCompileMsct ( 492 void **PFieldList); 493 494 ACPI_STATUS 495 DtCompileMtmr ( 496 void **PFieldList); 497 498 ACPI_STATUS 499 DtCompileNfit ( 500 void **PFieldList); 501 502 ACPI_STATUS 503 DtCompilePcct ( 504 void **PFieldList); 505 506 ACPI_STATUS 507 DtCompilePdtt ( 508 void **PFieldList); 509 510 ACPI_STATUS 511 DtCompilePmtt ( 512 void **PFieldList); 513 514 ACPI_STATUS 515 DtCompilePptt ( 516 void **PFieldList); 517 518 ACPI_STATUS 519 DtCompileRsdt ( 520 void **PFieldList); 521 522 ACPI_STATUS 523 DtCompileS3pt ( 524 DT_FIELD **PFieldList); 525 526 ACPI_STATUS 527 DtCompileSdev ( 528 void **PFieldList); 529 530 ACPI_STATUS 531 DtCompileSlic ( 532 void **PFieldList); 533 534 ACPI_STATUS 535 DtCompileSlit ( 536 void **PFieldList); 537 538 ACPI_STATUS 539 DtCompileSrat ( 540 void **PFieldList); 541 542 ACPI_STATUS 543 DtCompileStao ( 544 void **PFieldList); 545 546 ACPI_STATUS 547 DtCompileTcpa ( 548 void **PFieldList); 549 550 ACPI_STATUS 551 DtCompileTpm2 ( 552 void **PFieldList); 553 554 ACPI_STATUS 555 DtCompileUefi ( 556 void **PFieldList); 557 558 ACPI_STATUS 559 DtCompileVrtc ( 560 void **PFieldList); 561 562 ACPI_STATUS 563 DtCompileWdat ( 564 void **PFieldList); 565 566 ACPI_STATUS 567 DtCompileWpbt ( 568 void **PFieldList); 569 570 ACPI_STATUS 571 DtCompileXsdt ( 572 void **PFieldList); 573 574 ACPI_STATUS 575 DtCompileGeneric ( 576 void **PFieldList, 577 char *TermFieldName, 578 UINT32 *PFieldLength); 579 580 ACPI_DMTABLE_INFO * 581 DtGetGenericTableInfo ( 582 char *Name); 583 584 /* ACPI Table templates */ 585 586 extern const unsigned char TemplateAsf[]; 587 extern const unsigned char TemplateBoot[]; 588 extern const unsigned char TemplateBert[]; 589 extern const unsigned char TemplateBgrt[]; 590 extern const unsigned char TemplateCpep[]; 591 extern const unsigned char TemplateCsrt[]; 592 extern const unsigned char TemplateDbg2[]; 593 extern const unsigned char TemplateDbgp[]; 594 extern const unsigned char TemplateDmar[]; 595 extern const unsigned char TemplateDrtm[]; 596 extern const unsigned char TemplateEcdt[]; 597 extern const unsigned char TemplateEinj[]; 598 extern const unsigned char TemplateErst[]; 599 extern const unsigned char TemplateFadt[]; 600 extern const unsigned char TemplateFpdt[]; 601 extern const unsigned char TemplateGtdt[]; 602 extern const unsigned char TemplateHest[]; 603 extern const unsigned char TemplateHmat[]; 604 extern const unsigned char TemplateHpet[]; 605 extern const unsigned char TemplateIort[]; 606 extern const unsigned char TemplateIvrs[]; 607 extern const unsigned char TemplateLpit[]; 608 extern const unsigned char TemplateMadt[]; 609 extern const unsigned char TemplateMcfg[]; 610 extern const unsigned char TemplateMchi[]; 611 extern const unsigned char TemplateMpst[]; 612 extern const unsigned char TemplateMsct[]; 613 extern const unsigned char TemplateMsdm[]; 614 extern const unsigned char TemplateMtmr[]; 615 extern const unsigned char TemplateNfit[]; 616 extern const unsigned char TemplatePcct[]; 617 extern const unsigned char TemplatePdtt[]; 618 extern const unsigned char TemplatePmtt[]; 619 extern const unsigned char TemplatePptt[]; 620 extern const unsigned char TemplateRasf[]; 621 extern const unsigned char TemplateRsdt[]; 622 extern const unsigned char TemplateS3pt[]; 623 extern const unsigned char TemplateSbst[]; 624 extern const unsigned char TemplateSdei[]; 625 extern const unsigned char TemplateSdev[]; 626 extern const unsigned char TemplateSlic[]; 627 extern const unsigned char TemplateSlit[]; 628 extern const unsigned char TemplateSpcr[]; 629 extern const unsigned char TemplateSpmi[]; 630 extern const unsigned char TemplateSrat[]; 631 extern const unsigned char TemplateStao[]; 632 extern const unsigned char TemplateTcpa[]; 633 extern const unsigned char TemplateTpm2[]; 634 extern const unsigned char TemplateUefi[]; 635 extern const unsigned char TemplateVrtc[]; 636 extern const unsigned char TemplateWaet[]; 637 extern const unsigned char TemplateWdat[]; 638 extern const unsigned char TemplateWddt[]; 639 extern const unsigned char TemplateWdrt[]; 640 extern const unsigned char TemplateWpbt[]; 641 extern const unsigned char TemplateWsmt[]; 642 extern const unsigned char TemplateXenv[]; 643 extern const unsigned char TemplateXsdt[]; 644 645 #endif 646