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 char* 377 DtGetFieldValue ( 378 DT_FIELD *Field); 379 380 UINT8 381 DtGetFieldType ( 382 ACPI_DMTABLE_INFO *Info); 383 384 UINT32 385 DtGetBufferLength ( 386 char *Buffer); 387 388 UINT32 389 DtGetFieldLength ( 390 DT_FIELD *Field, 391 ACPI_DMTABLE_INFO *Info); 392 393 void 394 DtSetTableChecksum ( 395 UINT8 *ChecksumPointer); 396 397 void 398 DtSetTableLength( 399 void); 400 401 DT_SUBTABLE * 402 UtSubtableCacheCalloc ( 403 void); 404 405 DT_FIELD * 406 UtFieldCacheCalloc ( 407 void); 408 409 void 410 DtDeleteCaches ( 411 void); 412 413 414 /* dttable - individual table compilation */ 415 416 ACPI_STATUS 417 DtCompileFacs ( 418 DT_FIELD **PFieldList); 419 420 ACPI_STATUS 421 DtCompileRsdp ( 422 DT_FIELD **PFieldList); 423 424 ACPI_STATUS 425 DtCompileAsf ( 426 void **PFieldList); 427 428 ACPI_STATUS 429 DtCompileCpep ( 430 void **PFieldList); 431 432 ACPI_STATUS 433 DtCompileCsrt ( 434 void **PFieldList); 435 436 ACPI_STATUS 437 DtCompileDbg2 ( 438 void **PFieldList); 439 440 ACPI_STATUS 441 DtCompileDmar ( 442 void **PFieldList); 443 444 ACPI_STATUS 445 DtCompileDrtm ( 446 void **PFieldList); 447 448 ACPI_STATUS 449 DtCompileEinj ( 450 void **PFieldList); 451 452 ACPI_STATUS 453 DtCompileErst ( 454 void **PFieldList); 455 456 ACPI_STATUS 457 DtCompileFadt ( 458 void **PFieldList); 459 460 ACPI_STATUS 461 DtCompileFpdt ( 462 void **PFieldList); 463 464 ACPI_STATUS 465 DtCompileGtdt ( 466 void **PFieldList); 467 468 ACPI_STATUS 469 DtCompileHest ( 470 void **PFieldList); 471 472 ACPI_STATUS 473 DtCompileIort ( 474 void **PFieldList); 475 476 ACPI_STATUS 477 DtCompileIvrs ( 478 void **PFieldList); 479 480 ACPI_STATUS 481 DtCompileLpit ( 482 void **PFieldList); 483 484 ACPI_STATUS 485 DtCompileMadt ( 486 void **PFieldList); 487 488 ACPI_STATUS 489 DtCompileMcfg ( 490 void **PFieldList); 491 492 ACPI_STATUS 493 DtCompileMpst ( 494 void **PFieldList); 495 496 ACPI_STATUS 497 DtCompileMsct ( 498 void **PFieldList); 499 500 ACPI_STATUS 501 DtCompileMtmr ( 502 void **PFieldList); 503 504 ACPI_STATUS 505 DtCompileNfit ( 506 void **PFieldList); 507 508 ACPI_STATUS 509 DtCompilePmtt ( 510 void **PFieldList); 511 512 ACPI_STATUS 513 DtCompilePcct ( 514 void **PFieldList); 515 516 ACPI_STATUS 517 DtCompileRsdt ( 518 void **PFieldList); 519 520 ACPI_STATUS 521 DtCompileS3pt ( 522 DT_FIELD **PFieldList); 523 524 ACPI_STATUS 525 DtCompileSlic ( 526 void **PFieldList); 527 528 ACPI_STATUS 529 DtCompileSlit ( 530 void **PFieldList); 531 532 ACPI_STATUS 533 DtCompileSrat ( 534 void **PFieldList); 535 536 ACPI_STATUS 537 DtCompileStao ( 538 void **PFieldList); 539 540 ACPI_STATUS 541 DtCompileTcpa ( 542 void **PFieldList); 543 544 ACPI_STATUS 545 DtCompileUefi ( 546 void **PFieldList); 547 548 ACPI_STATUS 549 DtCompileVrtc ( 550 void **PFieldList); 551 552 ACPI_STATUS 553 DtCompileWdat ( 554 void **PFieldList); 555 556 ACPI_STATUS 557 DtCompileWpbt ( 558 void **PFieldList); 559 560 ACPI_STATUS 561 DtCompileXsdt ( 562 void **PFieldList); 563 564 ACPI_STATUS 565 DtCompileGeneric ( 566 void **PFieldList, 567 char *TermFieldName, 568 UINT32 *PFieldLength); 569 570 ACPI_DMTABLE_INFO * 571 DtGetGenericTableInfo ( 572 char *Name); 573 574 /* ACPI Table templates */ 575 576 extern const unsigned char TemplateAsf[]; 577 extern const unsigned char TemplateBoot[]; 578 extern const unsigned char TemplateBert[]; 579 extern const unsigned char TemplateBgrt[]; 580 extern const unsigned char TemplateCpep[]; 581 extern const unsigned char TemplateCsrt[]; 582 extern const unsigned char TemplateDbg2[]; 583 extern const unsigned char TemplateDbgp[]; 584 extern const unsigned char TemplateDmar[]; 585 extern const unsigned char TemplateDrtm[]; 586 extern const unsigned char TemplateEcdt[]; 587 extern const unsigned char TemplateEinj[]; 588 extern const unsigned char TemplateErst[]; 589 extern const unsigned char TemplateFadt[]; 590 extern const unsigned char TemplateFpdt[]; 591 extern const unsigned char TemplateGtdt[]; 592 extern const unsigned char TemplateHest[]; 593 extern const unsigned char TemplateHpet[]; 594 extern const unsigned char TemplateIort[]; 595 extern const unsigned char TemplateIvrs[]; 596 extern const unsigned char TemplateLpit[]; 597 extern const unsigned char TemplateMadt[]; 598 extern const unsigned char TemplateMcfg[]; 599 extern const unsigned char TemplateMchi[]; 600 extern const unsigned char TemplateMpst[]; 601 extern const unsigned char TemplateMsct[]; 602 extern const unsigned char TemplateMsdm[]; 603 extern const unsigned char TemplateMtmr[]; 604 extern const unsigned char TemplateNfit[]; 605 extern const unsigned char TemplatePcct[]; 606 extern const unsigned char TemplatePmtt[]; 607 extern const unsigned char TemplateRasf[]; 608 extern const unsigned char TemplateRsdt[]; 609 extern const unsigned char TemplateS3pt[]; 610 extern const unsigned char TemplateSbst[]; 611 extern const unsigned char TemplateSlic[]; 612 extern const unsigned char TemplateSlit[]; 613 extern const unsigned char TemplateSpcr[]; 614 extern const unsigned char TemplateSpmi[]; 615 extern const unsigned char TemplateSrat[]; 616 extern const unsigned char TemplateStao[]; 617 extern const unsigned char TemplateTcpa[]; 618 extern const unsigned char TemplateTpm2[]; 619 extern const unsigned char TemplateUefi[]; 620 extern const unsigned char TemplateVrtc[]; 621 extern const unsigned char TemplateWaet[]; 622 extern const unsigned char TemplateWdat[]; 623 extern const unsigned char TemplateWddt[]; 624 extern const unsigned char TemplateWdrt[]; 625 extern const unsigned char TemplateWpbt[]; 626 extern const unsigned char TemplateXenv[]; 627 extern const unsigned char TemplateXsdt[]; 628 629 #endif 630