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