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