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