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