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