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