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