dtcompiler.h revision 217365
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 <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
77
78/*
79 * Structure used for each individual field within an ACPI table
80 */
81typedef struct dt_field
82{
83    char                    *Name;
84    char                    *Value;
85    struct dt_field         *Next;
86    UINT32                  Line;       /* Line number for this field */
87    UINT32                  ByteOffset; /* Offset in source file for field */
88    UINT32                  NameColumn; /* Start column for field name */
89    UINT32                  Column;     /* Start column for field value */
90    UINT8                   Flags;
91
92} DT_FIELD;
93
94/* Flags for above */
95
96#define DT_FIELD_NOT_ALLOCATED      1
97
98
99/*
100 * Structure used for individual subtables within an ACPI table
101 */
102typedef struct dt_subtable
103{
104    struct dt_subtable      *Parent;
105    struct dt_subtable      *Child;
106    struct dt_subtable      *Peer;
107    struct dt_subtable      *StackTop;
108    UINT8                   *Buffer;
109    UINT8                   *LengthField;
110    UINT32                  Length;
111    UINT32                  TotalLength;
112    UINT32                  SizeOfLengthField;
113    UINT8                   Flags;
114
115} DT_SUBTABLE;
116
117
118/*
119 * Globals
120 */
121
122/* List of all field names and values from the input source */
123
124DT_EXTERN DT_FIELD          DT_INIT_GLOBAL (*Gbl_FieldList, NULL);
125
126/* List of all compiled tables and subtables */
127
128DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*Gbl_RootTable, NULL);
129
130/* Stack for subtables */
131
132DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*Gbl_SubtableStack, NULL);
133
134
135/* dtcompiler - main module */
136
137ACPI_STATUS
138DtCompileTable (
139    DT_FIELD                **Field,
140    ACPI_DMTABLE_INFO       *Info,
141    DT_SUBTABLE             **RetSubtable,
142    BOOLEAN                 Required);
143
144
145/* dtio - binary and text input/output */
146
147DT_FIELD *
148DtScanFile (
149    FILE                    *Handle);
150
151void
152DtOutputBinary (
153    DT_SUBTABLE             *RootTable);
154
155void
156DtWriteFieldToListing (
157    UINT8                   *Buffer,
158    DT_FIELD                *Field,
159    UINT32                  Length);
160
161void
162DtWriteTableToListing (
163    void);
164
165
166/* dtsubtable - compile subtables */
167
168void
169DtCreateSubtable (
170    UINT8                   *Buffer,
171    UINT32                  Length,
172    DT_SUBTABLE             **RetSubtable);
173
174UINT32
175DtGetSubtableLength (
176    DT_FIELD                *Field,
177    ACPI_DMTABLE_INFO       *Info);
178
179void
180DtSetSubtableLength (
181    DT_SUBTABLE             *Subtable);
182
183void
184DtPushSubtable (
185    DT_SUBTABLE             *Subtable);
186
187void
188DtPopSubtable (
189    void);
190
191DT_SUBTABLE *
192DtPeekSubtable (
193    void);
194
195void
196DtInsertSubtable (
197    DT_SUBTABLE             *ParentTable,
198    DT_SUBTABLE             *Subtable);
199
200DT_SUBTABLE *
201DtGetNextSubtable (
202    DT_SUBTABLE             *ParentTable,
203    DT_SUBTABLE             *ChildTable);
204
205DT_SUBTABLE *
206DtGetParentSubtable (
207    DT_SUBTABLE             *Subtable);
208
209
210/* dtfield - Compile individual fields within a table */
211
212void
213DtCompileOneField (
214    UINT8                   *Buffer,
215    DT_FIELD                *Field,
216    UINT32                  ByteLength,
217    UINT8                   Type,
218    UINT8                   Flags);
219
220void
221DtCompileInteger (
222    UINT8                   *Buffer,
223    DT_FIELD                *Field,
224    UINT32                  ByteLength,
225    UINT8                   Flags);
226
227UINT32
228DtCompileBuffer (
229    UINT8                   *Buffer,
230    char                    *Value,
231    DT_FIELD                *Field,
232    UINT32                  ByteLength);
233
234void
235DtCompileFlag (
236    UINT8                   *Buffer,
237    DT_FIELD                *Field,
238    ACPI_DMTABLE_INFO       *Info);
239
240
241/* dtutils - Miscellaneous utilities */
242
243typedef
244void (*DT_WALK_CALLBACK) (
245    DT_SUBTABLE             *Subtable,
246    void                    *Context,
247    void                    *ReturnValue);
248
249void
250DtWalkTableTree (
251    DT_SUBTABLE             *StartTable,
252    DT_WALK_CALLBACK        UserFunction,
253    void                    *Context,
254    void                    *ReturnValue);
255
256void
257DtError (
258    UINT8                   Level,
259    UINT8                   MessageId,
260    DT_FIELD                *FieldObject,
261    char                    *ExtraMessage);
262
263void
264DtNameError (
265    UINT8                   Level,
266    UINT8                   MessageId,
267    DT_FIELD                *FieldObject,
268    char                    *ExtraMessage);
269
270void
271DtFatal (
272    UINT8                   MessageId,
273    DT_FIELD                *FieldObject,
274    char                    *ExtraMessage);
275
276ACPI_STATUS
277DtStrtoul64 (
278    char                    *String,
279    UINT64                  *ReturnInteger);
280
281UINT32
282DtGetFileSize (
283    FILE                    *Handle);
284
285char*
286DtGetFieldValue (
287    DT_FIELD                *Field,
288    char                    *Name);
289
290UINT8
291DtGetFieldType (
292    ACPI_DMTABLE_INFO       *Info);
293
294UINT32
295DtGetBufferLength (
296    char                    *Buffer);
297
298UINT32
299DtGetFieldLength (
300    DT_FIELD                *Field,
301    ACPI_DMTABLE_INFO       *Info);
302
303void
304DtSetTableChecksum (
305    UINT8                   *ChecksumPointer);
306
307void
308DtSetTableLength(
309    void);
310
311void
312DtFreeFieldList (
313    void);
314
315
316/* dttable - individual table compilation */
317
318ACPI_STATUS
319DtCompileFacs (
320    DT_FIELD                **PFieldList);
321
322ACPI_STATUS
323DtCompileRsdp (
324    DT_FIELD                **PFieldList);
325
326ACPI_STATUS
327DtCompileAsf (
328    void                    **PFieldList);
329
330ACPI_STATUS
331DtCompileCpep (
332    void                    **PFieldList);
333
334ACPI_STATUS
335DtCompileDmar (
336    void                    **PFieldList);
337
338ACPI_STATUS
339DtCompileEinj (
340    void                    **PFieldList);
341
342ACPI_STATUS
343DtCompileErst (
344    void                    **PFieldList);
345
346ACPI_STATUS
347DtCompileFadt (
348    void                    **PFieldList);
349
350ACPI_STATUS
351DtCompileHest (
352    void                    **PFieldList);
353
354ACPI_STATUS
355DtCompileIvrs (
356    void                    **PFieldList);
357
358ACPI_STATUS
359DtCompileMadt (
360    void                    **PFieldList);
361
362ACPI_STATUS
363DtCompileMcfg (
364    void                    **PFieldList);
365
366ACPI_STATUS
367DtCompileMsct (
368    void                    **PFieldList);
369
370ACPI_STATUS
371DtCompileRsdt (
372    void                    **PFieldList);
373
374ACPI_STATUS
375DtCompileSlit (
376    void                    **PFieldList);
377
378ACPI_STATUS
379DtCompileSrat (
380    void                    **PFieldList);
381
382ACPI_STATUS
383DtCompileUefi (
384    void                    **PFieldList);
385
386ACPI_STATUS
387DtCompileWdat (
388    void                    **PFieldList);
389
390ACPI_STATUS
391DtCompileXsdt (
392    void                    **PFieldList);
393
394/* ACPI Table templates */
395
396extern const unsigned char  TemplateAsf[];
397extern const unsigned char  TemplateBoot[];
398extern const unsigned char  TemplateBert[];
399extern const unsigned char  TemplateCpep[];
400extern const unsigned char  TemplateDbgp[];
401extern const unsigned char  TemplateDmar[];
402extern const unsigned char  TemplateEcdt[];
403extern const unsigned char  TemplateEinj[];
404extern const unsigned char  TemplateErst[];
405extern const unsigned char  TemplateFadt[];
406extern const unsigned char  TemplateHest[];
407extern const unsigned char  TemplateHpet[];
408extern const unsigned char  TemplateIvrs[];
409extern const unsigned char  TemplateMadt[];
410extern const unsigned char  TemplateMcfg[];
411extern const unsigned char  TemplateMchi[];
412extern const unsigned char  TemplateMsct[];
413extern const unsigned char  TemplateRsdt[];
414extern const unsigned char  TemplateSbst[];
415extern const unsigned char  TemplateSlic[];
416extern const unsigned char  TemplateSlit[];
417extern const unsigned char  TemplateSpcr[];
418extern const unsigned char  TemplateSpmi[];
419extern const unsigned char  TemplateSrat[];
420extern const unsigned char  TemplateTcpa[];
421extern const unsigned char  TemplateUefi[];
422extern const unsigned char  TemplateWaet[];
423extern const unsigned char  TemplateWdat[];
424extern const unsigned char  TemplateWddt[];
425extern const unsigned char  TemplateWdrt[];
426extern const unsigned char  TemplateXsdt[];
427
428#endif
429