Subversion Repositories Kolibri OS

Rev

Rev 1498 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /******************************************************************************
  2.  *
  3.  * Module Name: dtcompiler.h - header for data table compiler
  4.  *
  5.  *****************************************************************************/
  6.  
  7. /******************************************************************************
  8.  *
  9.  * 1. Copyright Notice
  10.  *
  11.  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
  12.  * All rights reserved.
  13.  *
  14.  * 2. License
  15.  *
  16.  * 2.1. This is your license from Intel Corp. under its intellectual property
  17.  * rights.  You may have additional license terms from the party that provided
  18.  * you this software, covering your right to use that party's intellectual
  19.  * property rights.
  20.  *
  21.  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
  22.  * copy of the source code appearing in this file ("Covered Code") an
  23.  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
  24.  * base code distributed originally by Intel ("Original Intel Code") to copy,
  25.  * make derivatives, distribute, use and display any portion of the Covered
  26.  * Code in any form, with the right to sublicense such rights; and
  27.  *
  28.  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
  29.  * license (with the right to sublicense), under only those claims of Intel
  30.  * patents that are infringed by the Original Intel Code, to make, use, sell,
  31.  * offer to sell, and import the Covered Code and derivative works thereof
  32.  * solely to the minimum extent necessary to exercise the above copyright
  33.  * license, and in no event shall the patent license extend to any additions
  34.  * to or modifications of the Original Intel Code.  No other license or right
  35.  * is granted directly or by implication, estoppel or otherwise;
  36.  *
  37.  * The above copyright and patent license is granted only if the following
  38.  * conditions are met:
  39.  *
  40.  * 3. Conditions
  41.  *
  42.  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
  43.  * Redistribution of source code of any substantial portion of the Covered
  44.  * Code or modification with rights to further distribute source must include
  45.  * the above Copyright Notice, the above License, this list of Conditions,
  46.  * and the following Disclaimer and Export Compliance provision.  In addition,
  47.  * Licensee must cause all Covered Code to which Licensee contributes to
  48.  * contain a file documenting the changes Licensee made to create that Covered
  49.  * Code and the date of any change.  Licensee must include in that file the
  50.  * documentation of any changes made by any predecessor Licensee.  Licensee
  51.  * must include a prominent statement that the modification is derived,
  52.  * directly or indirectly, from Original Intel Code.
  53.  *
  54.  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
  55.  * Redistribution of source code of any substantial portion of the Covered
  56.  * Code or modification without rights to further distribute source must
  57.  * include the following Disclaimer and Export Compliance provision in the
  58.  * documentation and/or other materials provided with distribution.  In
  59.  * addition, Licensee may not authorize further sublicense of source of any
  60.  * portion of the Covered Code, and must include terms to the effect that the
  61.  * license from Licensee to its licensee is limited to the intellectual
  62.  * property embodied in the software Licensee provides to its licensee, and
  63.  * not to intellectual property embodied in modifications its licensee may
  64.  * make.
  65.  *
  66.  * 3.3. Redistribution of Executable. Redistribution in executable form of any
  67.  * substantial portion of the Covered Code or modification must reproduce the
  68.  * above Copyright Notice, and the following Disclaimer and Export Compliance
  69.  * provision in the documentation and/or other materials provided with the
  70.  * distribution.
  71.  *
  72.  * 3.4. Intel retains all right, title, and interest in and to the Original
  73.  * Intel Code.
  74.  *
  75.  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
  76.  * Intel shall be used in advertising or otherwise to promote the sale, use or
  77.  * other dealings in products derived from or relating to the Covered Code
  78.  * without prior written authorization from Intel.
  79.  *
  80.  * 4. Disclaimer and Export Compliance
  81.  *
  82.  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
  83.  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
  84.  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
  85.  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
  86.  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
  87.  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
  88.  * PARTICULAR PURPOSE.
  89.  *
  90.  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
  91.  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
  92.  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
  93.  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
  94.  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
  95.  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
  96.  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
  97.  * LIMITED REMEDY.
  98.  *
  99.  * 4.3. Licensee shall not export, either directly or indirectly, any of this
  100.  * software or system incorporating such software without first obtaining any
  101.  * required license or other approval from the U. S. Department of Commerce or
  102.  * any other agency or department of the United States Government.  In the
  103.  * event Licensee exports any such software from the United States or
  104.  * re-exports any such software from a foreign destination, Licensee shall
  105.  * ensure that the distribution and export/re-export of the software is in
  106.  * compliance with all laws, regulations, orders, or other restrictions of the
  107.  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
  108.  * any of its subsidiaries will export/re-export any technical data, process,
  109.  * software, or service, directly or indirectly, to any country for which the
  110.  * United States government or any agency thereof requires an export license,
  111.  * other governmental approval, or letter of assurance, without first obtaining
  112.  * such license, approval or letter.
  113.  *
  114.  *****************************************************************************/
  115.  
  116. #define __DTCOMPILER_H__
  117.  
  118. #ifndef _DTCOMPILER
  119. #define _DTCOMPILER
  120.  
  121. #include <stdio.h>
  122. #include "acdisasm.h"
  123.  
  124.  
  125. #undef DT_EXTERN
  126.  
  127. #ifdef _DECLARE_DT_GLOBALS
  128. #define DT_EXTERN
  129. #define DT_INIT_GLOBAL(a,b)         (a)=(b)
  130. #else
  131. #define DT_EXTERN                   extern
  132. #define DT_INIT_GLOBAL(a,b)         (a)
  133. #endif
  134.  
  135.  
  136. /* Types for individual fields (one per input line) */
  137.  
  138. #define DT_FIELD_TYPE_STRING            0
  139. #define DT_FIELD_TYPE_INTEGER           1
  140. #define DT_FIELD_TYPE_BUFFER            2
  141. #define DT_FIELD_TYPE_PCI_PATH          3
  142. #define DT_FIELD_TYPE_FLAG              4
  143. #define DT_FIELD_TYPE_FLAGS_INTEGER     5
  144. #define DT_FIELD_TYPE_INLINE_SUBTABLE   6
  145. #define DT_FIELD_TYPE_UUID              7
  146. #define DT_FIELD_TYPE_UNICODE           8
  147. #define DT_FIELD_TYPE_DEVICE_PATH       9
  148. #define DT_FIELD_TYPE_LABEL             10
  149.  
  150.  
  151. /*
  152.  * Structure used for each individual field within an ACPI table
  153.  */
  154. typedef struct dt_field
  155. {
  156.     char                    *Name;      /* Field name (from name : value) */
  157.     char                    *Value;     /* Field value (from name : value) */
  158.     struct dt_field         *Next;      /* Next field */
  159.     struct dt_field         *NextLabel; /* If field is a label, next label */
  160.     UINT32                  Line;       /* Line number for this field */
  161.     UINT32                  ByteOffset; /* Offset in source file for field */
  162.     UINT32                  NameColumn; /* Start column for field name */
  163.     UINT32                  Column;     /* Start column for field value */
  164.     UINT32                  TableOffset;/* Binary offset within ACPI table */
  165.     UINT8                   Flags;
  166.  
  167. } DT_FIELD;
  168.  
  169. /* Flags for above */
  170.  
  171. #define DT_FIELD_NOT_ALLOCATED      1
  172.  
  173.  
  174. /*
  175.  * Structure used for individual subtables within an ACPI table
  176.  */
  177. typedef struct dt_subtable
  178. {
  179.     struct dt_subtable      *Parent;
  180.     struct dt_subtable      *Child;
  181.     struct dt_subtable      *Peer;
  182.     struct dt_subtable      *StackTop;
  183.     UINT8                   *Buffer;
  184.     UINT8                   *LengthField;
  185.     UINT32                  Length;
  186.     UINT32                  TotalLength;
  187.     UINT32                  SizeOfLengthField;
  188.     UINT8                   Flags;
  189.  
  190. } DT_SUBTABLE;
  191.  
  192.  
  193. /*
  194.  * Globals
  195.  */
  196.  
  197. /* List of all field names and values from the input source */
  198.  
  199. DT_EXTERN DT_FIELD          DT_INIT_GLOBAL (*Gbl_FieldList, NULL);
  200.  
  201. /* List of all compiled tables and subtables */
  202.  
  203. DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*Gbl_RootTable, NULL);
  204.  
  205. /* Stack for subtables */
  206.  
  207. DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*Gbl_SubtableStack, NULL);
  208.  
  209. /* List for defined labels */
  210.  
  211. DT_EXTERN DT_FIELD          DT_INIT_GLOBAL (*Gbl_LabelList, NULL);
  212.  
  213. /* Current offset within the binary output table */
  214.  
  215. DT_EXTERN UINT32            DT_INIT_GLOBAL (Gbl_CurrentTableOffset, 0);
  216.  
  217.  
  218. /* dtcompiler - main module */
  219.  
  220. ACPI_STATUS
  221. DtCompileTable (
  222.     DT_FIELD                **Field,
  223.     ACPI_DMTABLE_INFO       *Info,
  224.     DT_SUBTABLE             **RetSubtable,
  225.     BOOLEAN                 Required);
  226.  
  227.  
  228. /* dtio - binary and text input/output */
  229.  
  230. DT_FIELD *
  231. DtScanFile (
  232.     FILE                    *Handle);
  233.  
  234. void
  235. DtOutputBinary (
  236.     DT_SUBTABLE             *RootTable);
  237.  
  238. void
  239. DtWriteFieldToListing (
  240.     UINT8                   *Buffer,
  241.     DT_FIELD                *Field,
  242.     UINT32                  Length);
  243.  
  244. void
  245. DtWriteTableToListing (
  246.     void);
  247.  
  248.  
  249. /* dtsubtable - compile subtables */
  250.  
  251. void
  252. DtCreateSubtable (
  253.     UINT8                   *Buffer,
  254.     UINT32                  Length,
  255.     DT_SUBTABLE             **RetSubtable);
  256.  
  257. UINT32
  258. DtGetSubtableLength (
  259.     DT_FIELD                *Field,
  260.     ACPI_DMTABLE_INFO       *Info);
  261.  
  262. void
  263. DtSetSubtableLength (
  264.     DT_SUBTABLE             *Subtable);
  265.  
  266. void
  267. DtPushSubtable (
  268.     DT_SUBTABLE             *Subtable);
  269.  
  270. void
  271. DtPopSubtable (
  272.     void);
  273.  
  274. DT_SUBTABLE *
  275. DtPeekSubtable (
  276.     void);
  277.  
  278. void
  279. DtInsertSubtable (
  280.     DT_SUBTABLE             *ParentTable,
  281.     DT_SUBTABLE             *Subtable);
  282.  
  283. DT_SUBTABLE *
  284. DtGetNextSubtable (
  285.     DT_SUBTABLE             *ParentTable,
  286.     DT_SUBTABLE             *ChildTable);
  287.  
  288. DT_SUBTABLE *
  289. DtGetParentSubtable (
  290.     DT_SUBTABLE             *Subtable);
  291.  
  292.  
  293. /* dtexpress - Integer expressions and labels */
  294.  
  295. ACPI_STATUS
  296. DtResolveIntegerExpression (
  297.     DT_FIELD                *Field,
  298.     UINT64                  *ReturnValue);
  299.  
  300. UINT64
  301. DtDoOperator (
  302.     UINT64                  LeftValue,
  303.     UINT32                  Operator,
  304.     UINT64                  RightValue);
  305.  
  306. UINT64
  307. DtResolveLabel (
  308.     char                    *LabelString);
  309.  
  310. void
  311. DtDetectAllLabels (
  312.     DT_FIELD                *FieldList);
  313.  
  314.  
  315. /* dtfield - Compile individual fields within a table */
  316.  
  317. void
  318. DtCompileOneField (
  319.     UINT8                   *Buffer,
  320.     DT_FIELD                *Field,
  321.     UINT32                  ByteLength,
  322.     UINT8                   Type,
  323.     UINT8                   Flags);
  324.  
  325. void
  326. DtCompileInteger (
  327.     UINT8                   *Buffer,
  328.     DT_FIELD                *Field,
  329.     UINT32                  ByteLength,
  330.     UINT8                   Flags);
  331.  
  332. UINT32
  333. DtCompileBuffer (
  334.     UINT8                   *Buffer,
  335.     char                    *Value,
  336.     DT_FIELD                *Field,
  337.     UINT32                  ByteLength);
  338.  
  339. void
  340. DtCompileFlag (
  341.     UINT8                   *Buffer,
  342.     DT_FIELD                *Field,
  343.     ACPI_DMTABLE_INFO       *Info);
  344.  
  345.  
  346. /* dtparser - lex/yacc files */
  347.  
  348. UINT64
  349. DtEvaluateExpression (
  350.     char                    *ExprString);
  351.  
  352. int
  353. DtInitLexer (
  354.     char                    *String);
  355.  
  356. void
  357. DtTerminateLexer (
  358.     void);
  359.  
  360. char *
  361. DtGetOpName (
  362.     UINT32                  ParseOpcode);
  363.  
  364.  
  365. /* dtutils - Miscellaneous utilities */
  366.  
  367. typedef
  368. void (*DT_WALK_CALLBACK) (
  369.     DT_SUBTABLE             *Subtable,
  370.     void                    *Context,
  371.     void                    *ReturnValue);
  372.  
  373. void
  374. DtWalkTableTree (
  375.     DT_SUBTABLE             *StartTable,
  376.     DT_WALK_CALLBACK        UserFunction,
  377.     void                    *Context,
  378.     void                    *ReturnValue);
  379.  
  380. void
  381. DtError (
  382.     UINT8                   Level,
  383.     UINT8                   MessageId,
  384.     DT_FIELD                *FieldObject,
  385.     char                    *ExtraMessage);
  386.  
  387. void
  388. DtNameError (
  389.     UINT8                   Level,
  390.     UINT8                   MessageId,
  391.     DT_FIELD                *FieldObject,
  392.     char                    *ExtraMessage);
  393.  
  394. void
  395. DtFatal (
  396.     UINT8                   MessageId,
  397.     DT_FIELD                *FieldObject,
  398.     char                    *ExtraMessage);
  399.  
  400. ACPI_STATUS
  401. DtStrtoul64 (
  402.     char                    *String,
  403.     UINT64                  *ReturnInteger);
  404.  
  405. UINT32
  406. DtGetFileSize (
  407.     FILE                    *Handle);
  408.  
  409. char*
  410. DtGetFieldValue (
  411.     DT_FIELD                *Field);
  412.  
  413. UINT8
  414. DtGetFieldType (
  415.     ACPI_DMTABLE_INFO       *Info);
  416.  
  417. UINT32
  418. DtGetBufferLength (
  419.     char                    *Buffer);
  420.  
  421. UINT32
  422. DtGetFieldLength (
  423.     DT_FIELD                *Field,
  424.     ACPI_DMTABLE_INFO       *Info);
  425.  
  426. void
  427. DtSetTableChecksum (
  428.     UINT8                   *ChecksumPointer);
  429.  
  430. void
  431. DtSetTableLength(
  432.     void);
  433.  
  434. void
  435. DtFreeFieldList (
  436.     void);
  437.  
  438.  
  439. /* dttable - individual table compilation */
  440.  
  441. ACPI_STATUS
  442. DtCompileFacs (
  443.     DT_FIELD                **PFieldList);
  444.  
  445. ACPI_STATUS
  446. DtCompileRsdp (
  447.     DT_FIELD                **PFieldList);
  448.  
  449. ACPI_STATUS
  450. DtCompileAsf (
  451.     void                    **PFieldList);
  452.  
  453. ACPI_STATUS
  454. DtCompileCpep (
  455.     void                    **PFieldList);
  456.  
  457. ACPI_STATUS
  458. DtCompileDmar (
  459.     void                    **PFieldList);
  460.  
  461. ACPI_STATUS
  462. DtCompileEinj (
  463.     void                    **PFieldList);
  464.  
  465. ACPI_STATUS
  466. DtCompileErst (
  467.     void                    **PFieldList);
  468.  
  469. ACPI_STATUS
  470. DtCompileFadt (
  471.     void                    **PFieldList);
  472.  
  473. ACPI_STATUS
  474. DtCompileHest (
  475.     void                    **PFieldList);
  476.  
  477. ACPI_STATUS
  478. DtCompileIvrs (
  479.     void                    **PFieldList);
  480.  
  481. ACPI_STATUS
  482. DtCompileMadt (
  483.     void                    **PFieldList);
  484.  
  485. ACPI_STATUS
  486. DtCompileMcfg (
  487.     void                    **PFieldList);
  488.  
  489. ACPI_STATUS
  490. DtCompileMsct (
  491.     void                    **PFieldList);
  492.  
  493. ACPI_STATUS
  494. DtCompileRsdt (
  495.     void                    **PFieldList);
  496.  
  497. ACPI_STATUS
  498. DtCompileSlic (
  499.     void                    **PFieldList);
  500.  
  501. ACPI_STATUS
  502. DtCompileSlit (
  503.     void                    **PFieldList);
  504.  
  505. ACPI_STATUS
  506. DtCompileSrat (
  507.     void                    **PFieldList);
  508.  
  509. ACPI_STATUS
  510. DtCompileUefi (
  511.     void                    **PFieldList);
  512.  
  513. ACPI_STATUS
  514. DtCompileWdat (
  515.     void                    **PFieldList);
  516.  
  517. ACPI_STATUS
  518. DtCompileXsdt (
  519.     void                    **PFieldList);
  520.  
  521. ACPI_STATUS
  522. DtCompileGeneric (
  523.     void                    **PFieldList);
  524.  
  525. ACPI_DMTABLE_INFO *
  526. DtGetGenericTableInfo (
  527.     char                    *Name);
  528.  
  529. /* ACPI Table templates */
  530.  
  531. extern const unsigned char  TemplateAsf[];
  532. extern const unsigned char  TemplateBoot[];
  533. extern const unsigned char  TemplateBert[];
  534. extern const unsigned char  TemplateCpep[];
  535. extern const unsigned char  TemplateDbgp[];
  536. extern const unsigned char  TemplateDmar[];
  537. extern const unsigned char  TemplateEcdt[];
  538. extern const unsigned char  TemplateEinj[];
  539. extern const unsigned char  TemplateErst[];
  540. extern const unsigned char  TemplateFadt[];
  541. extern const unsigned char  TemplateHest[];
  542. extern const unsigned char  TemplateHpet[];
  543. extern const unsigned char  TemplateIvrs[];
  544. extern const unsigned char  TemplateMadt[];
  545. extern const unsigned char  TemplateMcfg[];
  546. extern const unsigned char  TemplateMchi[];
  547. extern const unsigned char  TemplateMsct[];
  548. extern const unsigned char  TemplateRsdt[];
  549. extern const unsigned char  TemplateSbst[];
  550. extern const unsigned char  TemplateSlic[];
  551. extern const unsigned char  TemplateSlit[];
  552. extern const unsigned char  TemplateSpcr[];
  553. extern const unsigned char  TemplateSpmi[];
  554. extern const unsigned char  TemplateSrat[];
  555. extern const unsigned char  TemplateTcpa[];
  556. extern const unsigned char  TemplateUefi[];
  557. extern const unsigned char  TemplateWaet[];
  558. extern const unsigned char  TemplateWdat[];
  559. extern const unsigned char  TemplateWddt[];
  560. extern const unsigned char  TemplateWdrt[];
  561. extern const unsigned char  TemplateXsdt[];
  562.  
  563. #endif
  564.