dtcompiler.h revision 229989
1/****************************************************************************** 2 * 3 * Module Name: dtcompiler.h - header for data table compiler 4 * 5 *****************************************************************************/ 6 7/* 8 * Copyright (C) 2000 - 2012, 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 UINT8 Flags; 117 118} DT_SUBTABLE; 119 120 121/* 122 * Globals 123 */ 124 125/* List of all field names and values from the input source */ 126 127DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*Gbl_FieldList, NULL); 128 129/* List of all compiled tables and subtables */ 130 131DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*Gbl_RootTable, NULL); 132 133/* Stack for subtables */ 134 135DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*Gbl_SubtableStack, NULL); 136 137/* List for defined labels */ 138 139DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*Gbl_LabelList, NULL); 140 141/* Current offset within the binary output table */ 142 143DT_EXTERN UINT32 DT_INIT_GLOBAL (Gbl_CurrentTableOffset, 0); 144 145 146/* dtcompiler - main module */ 147 148ACPI_STATUS 149DtCompileTable ( 150 DT_FIELD **Field, 151 ACPI_DMTABLE_INFO *Info, 152 DT_SUBTABLE **RetSubtable, 153 BOOLEAN Required); 154 155 156/* dtio - binary and text input/output */ 157 158DT_FIELD * 159DtScanFile ( 160 FILE *Handle); 161 162void 163DtOutputBinary ( 164 DT_SUBTABLE *RootTable); 165 166void 167DtWriteFieldToListing ( 168 UINT8 *Buffer, 169 DT_FIELD *Field, 170 UINT32 Length); 171 172void 173DtWriteTableToListing ( 174 void); 175 176 177/* dtsubtable - compile subtables */ 178 179void 180DtCreateSubtable ( 181 UINT8 *Buffer, 182 UINT32 Length, 183 DT_SUBTABLE **RetSubtable); 184 185UINT32 186DtGetSubtableLength ( 187 DT_FIELD *Field, 188 ACPI_DMTABLE_INFO *Info); 189 190void 191DtSetSubtableLength ( 192 DT_SUBTABLE *Subtable); 193 194void 195DtPushSubtable ( 196 DT_SUBTABLE *Subtable); 197 198void 199DtPopSubtable ( 200 void); 201 202DT_SUBTABLE * 203DtPeekSubtable ( 204 void); 205 206void 207DtInsertSubtable ( 208 DT_SUBTABLE *ParentTable, 209 DT_SUBTABLE *Subtable); 210 211DT_SUBTABLE * 212DtGetNextSubtable ( 213 DT_SUBTABLE *ParentTable, 214 DT_SUBTABLE *ChildTable); 215 216DT_SUBTABLE * 217DtGetParentSubtable ( 218 DT_SUBTABLE *Subtable); 219 220 221/* dtexpress - Integer expressions and labels */ 222 223ACPI_STATUS 224DtResolveIntegerExpression ( 225 DT_FIELD *Field, 226 UINT64 *ReturnValue); 227 228UINT64 229DtDoOperator ( 230 UINT64 LeftValue, 231 UINT32 Operator, 232 UINT64 RightValue); 233 234UINT64 235DtResolveLabel ( 236 char *LabelString); 237 238void 239DtDetectAllLabels ( 240 DT_FIELD *FieldList); 241 242 243/* dtfield - Compile individual fields within a table */ 244 245void 246DtCompileOneField ( 247 UINT8 *Buffer, 248 DT_FIELD *Field, 249 UINT32 ByteLength, 250 UINT8 Type, 251 UINT8 Flags); 252 253void 254DtCompileInteger ( 255 UINT8 *Buffer, 256 DT_FIELD *Field, 257 UINT32 ByteLength, 258 UINT8 Flags); 259 260UINT32 261DtCompileBuffer ( 262 UINT8 *Buffer, 263 char *Value, 264 DT_FIELD *Field, 265 UINT32 ByteLength); 266 267void 268DtCompileFlag ( 269 UINT8 *Buffer, 270 DT_FIELD *Field, 271 ACPI_DMTABLE_INFO *Info); 272 273 274/* dtparser - lex/yacc files */ 275 276UINT64 277DtEvaluateExpression ( 278 char *ExprString); 279 280int 281DtInitLexer ( 282 char *String); 283 284void 285DtTerminateLexer ( 286 void); 287 288char * 289DtGetOpName ( 290 UINT32 ParseOpcode); 291 292 293/* dtutils - Miscellaneous utilities */ 294 295typedef 296void (*DT_WALK_CALLBACK) ( 297 DT_SUBTABLE *Subtable, 298 void *Context, 299 void *ReturnValue); 300 301void 302DtWalkTableTree ( 303 DT_SUBTABLE *StartTable, 304 DT_WALK_CALLBACK UserFunction, 305 void *Context, 306 void *ReturnValue); 307 308void 309DtError ( 310 UINT8 Level, 311 UINT8 MessageId, 312 DT_FIELD *FieldObject, 313 char *ExtraMessage); 314 315void 316DtNameError ( 317 UINT8 Level, 318 UINT8 MessageId, 319 DT_FIELD *FieldObject, 320 char *ExtraMessage); 321 322void 323DtFatal ( 324 UINT8 MessageId, 325 DT_FIELD *FieldObject, 326 char *ExtraMessage); 327 328ACPI_STATUS 329DtStrtoul64 ( 330 char *String, 331 UINT64 *ReturnInteger); 332 333UINT32 334DtGetFileSize ( 335 FILE *Handle); 336 337char* 338DtGetFieldValue ( 339 DT_FIELD *Field); 340 341UINT8 342DtGetFieldType ( 343 ACPI_DMTABLE_INFO *Info); 344 345UINT32 346DtGetBufferLength ( 347 char *Buffer); 348 349UINT32 350DtGetFieldLength ( 351 DT_FIELD *Field, 352 ACPI_DMTABLE_INFO *Info); 353 354void 355DtSetTableChecksum ( 356 UINT8 *ChecksumPointer); 357 358void 359DtSetTableLength( 360 void); 361 362void 363DtFreeFieldList ( 364 void); 365 366 367/* dttable - individual table compilation */ 368 369ACPI_STATUS 370DtCompileFacs ( 371 DT_FIELD **PFieldList); 372 373ACPI_STATUS 374DtCompileRsdp ( 375 DT_FIELD **PFieldList); 376 377ACPI_STATUS 378DtCompileAsf ( 379 void **PFieldList); 380 381ACPI_STATUS 382DtCompileCpep ( 383 void **PFieldList); 384 385ACPI_STATUS 386DtCompileDmar ( 387 void **PFieldList); 388 389ACPI_STATUS 390DtCompileEinj ( 391 void **PFieldList); 392 393ACPI_STATUS 394DtCompileErst ( 395 void **PFieldList); 396 397ACPI_STATUS 398DtCompileFadt ( 399 void **PFieldList); 400 401ACPI_STATUS 402DtCompileFpdt ( 403 void **PFieldList); 404 405ACPI_STATUS 406DtCompileHest ( 407 void **PFieldList); 408 409ACPI_STATUS 410DtCompileIvrs ( 411 void **PFieldList); 412 413ACPI_STATUS 414DtCompileMadt ( 415 void **PFieldList); 416 417ACPI_STATUS 418DtCompileMcfg ( 419 void **PFieldList); 420 421ACPI_STATUS 422DtCompileMpst ( 423 void **PFieldList); 424 425ACPI_STATUS 426DtCompileMsct ( 427 void **PFieldList); 428 429ACPI_STATUS 430DtCompilePmtt ( 431 void **PFieldList); 432 433ACPI_STATUS 434DtCompileRsdt ( 435 void **PFieldList); 436 437ACPI_STATUS 438DtCompileS3pt ( 439 DT_FIELD **PFieldList); 440 441ACPI_STATUS 442DtCompileSlic ( 443 void **PFieldList); 444 445ACPI_STATUS 446DtCompileSlit ( 447 void **PFieldList); 448 449ACPI_STATUS 450DtCompileSrat ( 451 void **PFieldList); 452 453ACPI_STATUS 454DtCompileUefi ( 455 void **PFieldList); 456 457ACPI_STATUS 458DtCompileWdat ( 459 void **PFieldList); 460 461ACPI_STATUS 462DtCompileXsdt ( 463 void **PFieldList); 464 465ACPI_STATUS 466DtCompileGeneric ( 467 void **PFieldList); 468 469ACPI_DMTABLE_INFO * 470DtGetGenericTableInfo ( 471 char *Name); 472 473/* ACPI Table templates */ 474 475extern const unsigned char TemplateAsf[]; 476extern const unsigned char TemplateBoot[]; 477extern const unsigned char TemplateBert[]; 478extern const unsigned char TemplateBgrt[]; 479extern const unsigned char TemplateCpep[]; 480extern const unsigned char TemplateDbgp[]; 481extern const unsigned char TemplateDmar[]; 482extern const unsigned char TemplateEcdt[]; 483extern const unsigned char TemplateEinj[]; 484extern const unsigned char TemplateErst[]; 485extern const unsigned char TemplateFadt[]; 486extern const unsigned char TemplateFpdt[]; 487extern const unsigned char TemplateGtdt[]; 488extern const unsigned char TemplateHest[]; 489extern const unsigned char TemplateHpet[]; 490extern const unsigned char TemplateIvrs[]; 491extern const unsigned char TemplateMadt[]; 492extern const unsigned char TemplateMcfg[]; 493extern const unsigned char TemplateMchi[]; 494extern const unsigned char TemplateMpst[]; 495extern const unsigned char TemplateMsct[]; 496extern const unsigned char TemplatePmtt[]; 497extern const unsigned char TemplateRsdt[]; 498extern const unsigned char TemplateS3pt[]; 499extern const unsigned char TemplateSbst[]; 500extern const unsigned char TemplateSlic[]; 501extern const unsigned char TemplateSlit[]; 502extern const unsigned char TemplateSpcr[]; 503extern const unsigned char TemplateSpmi[]; 504extern const unsigned char TemplateSrat[]; 505extern const unsigned char TemplateTcpa[]; 506extern const unsigned char TemplateUefi[]; 507extern const unsigned char TemplateWaet[]; 508extern const unsigned char TemplateWdat[]; 509extern const unsigned char TemplateWddt[]; 510extern const unsigned char TemplateWdrt[]; 511extern const unsigned char TemplateXsdt[]; 512 513#endif 514