1/******************************************************************************
2 *
3 * Module Name: dtcompiler.h - header for data table compiler
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2023, 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 MERCHANTABILITY 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 "acdisasm.h"
50
51
52#define ASL_FIELD_CACHE_SIZE            512
53#define ASL_SUBTABLE_CACHE_SIZE         128
54
55
56#undef DT_EXTERN
57
58#ifdef _DECLARE_DT_GLOBALS
59#define DT_EXTERN
60#define DT_INIT_GLOBAL(a,b)         (a)=(b)
61#else
62#define DT_EXTERN                   extern
63#define DT_INIT_GLOBAL(a,b)         (a)
64#endif
65
66
67/* Types for individual fields (one per input line) */
68
69#define DT_FIELD_TYPE_STRING            0
70#define DT_FIELD_TYPE_INTEGER           1
71#define DT_FIELD_TYPE_BUFFER            2
72#define DT_FIELD_TYPE_PCI_PATH          3
73#define DT_FIELD_TYPE_FLAG              4
74#define DT_FIELD_TYPE_FLAGS_INTEGER     5
75#define DT_FIELD_TYPE_INLINE_SUBTABLE   6
76#define DT_FIELD_TYPE_UUID              7
77#define DT_FIELD_TYPE_UNICODE           8
78#define DT_FIELD_TYPE_DEVICE_PATH       9
79#define DT_FIELD_TYPE_LABEL             10
80
81
82/*
83 * Structure used for each individual field within an ACPI table
84 */
85typedef struct dt_field
86{
87    char                    *Name;       /* Field name (from name : value) */
88    char                    *Value;      /* Field value (from name : value) */
89    UINT32                  StringLength; /* Length of Value */
90    struct dt_field         *Next;       /* Next field */
91    struct dt_field         *NextLabel;  /* If field is a label, next label */
92    UINT32                  Line;        /* Line number for this field */
93    UINT32                  ByteOffset;  /* Offset in source file for field */
94    UINT32                  NameColumn;  /* Start column for field name */
95    UINT32                  Column;      /* Start column for field value */
96    UINT32                  TableOffset; /* Binary offset within ACPI table */
97    UINT8                   Flags;
98
99} DT_FIELD;
100
101/* Flags for above */
102
103#define DT_FIELD_NOT_ALLOCATED      1
104
105/*
106 * Structure used for each individual key or value
107 */
108typedef struct dt_table_unit
109{
110    char                    *Value;      /* Field value (from name : value) */
111    UINT32                  Line;        /* Line number for this field */
112    UINT32                  Column;      /* Start column for field value */
113
114} DT_TABLE_UNIT;
115
116
117/*
118 * Structure used for individual subtables within an ACPI table
119 */
120typedef struct dt_subtable
121{
122    struct dt_subtable      *Parent;
123    struct dt_subtable      *Child;
124    struct dt_subtable      *Peer;
125    struct dt_subtable      *StackTop;
126    UINT8                   *Buffer;
127    UINT8                   *LengthField;
128    char                    *Name;
129    UINT32                  Length;
130    UINT32                  TotalLength;
131    UINT32                  SizeOfLengthField;
132    UINT16                  Depth;
133    UINT8                   Flags;
134
135} DT_SUBTABLE;
136
137
138/*
139 * Globals
140 */
141
142/* List of all field names and values from the input source */
143
144DT_EXTERN DT_FIELD          DT_INIT_GLOBAL (*AslGbl_FieldList, NULL);
145
146/* List of all compiled tables and subtables */
147
148DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*AslGbl_RootTable, NULL);
149
150/* Stack for subtables */
151
152DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*AslGbl_SubtableStack, NULL);
153
154/* List for defined labels */
155
156DT_EXTERN DT_FIELD          DT_INIT_GLOBAL (*AslGbl_LabelList, NULL);
157
158/* Current offset within the binary output table */
159
160DT_EXTERN UINT32            DT_INIT_GLOBAL (AslGbl_CurrentTableOffset, 0);
161
162/* Data table compiler Flex/Bison prototype */
163
164DT_EXTERN BOOLEAN           DT_INIT_GLOBAL (AslGbl_DtLexBisonPrototype, FALSE);
165
166/* Local caches */
167
168DT_EXTERN UINT32            DT_INIT_GLOBAL (AslGbl_SubtableCount, 0);
169DT_EXTERN ASL_CACHE_INFO    DT_INIT_GLOBAL (*AslGbl_SubtableCacheList, NULL);
170DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*AslGbl_SubtableCacheNext, NULL);
171DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*AslGbl_SubtableCacheLast, NULL);
172
173DT_EXTERN UINT32            DT_INIT_GLOBAL (AslGbl_FieldCount, 0);
174DT_EXTERN ASL_CACHE_INFO    DT_INIT_GLOBAL (*AslGbl_FieldCacheList, NULL);
175DT_EXTERN DT_FIELD          DT_INIT_GLOBAL (*AslGbl_FieldCacheNext, NULL);
176DT_EXTERN DT_FIELD          DT_INIT_GLOBAL (*AslGbl_FieldCacheLast, NULL);
177
178
179/* dtcompiler - main module */
180
181ACPI_STATUS
182DtCompileTable (
183    DT_FIELD                **Field,
184    ACPI_DMTABLE_INFO       *Info,
185    DT_SUBTABLE             **RetSubtable);
186
187ACPI_STATUS
188DtCompileTwoSubtables (
189    void                    **List,
190    ACPI_DMTABLE_INFO       *TableInfo1,
191    ACPI_DMTABLE_INFO       *TableInfo2);
192
193ACPI_STATUS
194DtCompilePadding (
195    UINT32                  Length,
196    DT_SUBTABLE             **RetSubtable);
197
198
199/* dtio - binary and text input/output */
200
201UINT32
202DtGetNextLine (
203    FILE                    *Handle,
204    UINT32                  Flags);
205
206/* Flags for DtGetNextLine */
207
208#define DT_ALLOW_MULTILINE_QUOTES   0x01
209
210
211DT_FIELD *
212DtScanFile (
213    FILE                    *Handle);
214
215void
216DtOutputBinary (
217    DT_SUBTABLE             *RootTable);
218
219void
220DtDumpSubtableList (
221    void);
222
223void
224DtDumpFieldList (
225    DT_FIELD                *Field);
226
227void
228DtWriteFieldToListing (
229    UINT8                   *Buffer,
230    DT_FIELD                *Field,
231    UINT32                  Length);
232
233void
234DtWriteTableToListing (
235    void);
236
237
238/* dtsubtable - compile subtables */
239
240void
241DtCreateSubtable (
242    UINT8                   *Buffer,
243    UINT32                  Length,
244    DT_SUBTABLE             **RetSubtable);
245
246UINT32
247DtGetSubtableLength (
248    DT_FIELD                *Field,
249    ACPI_DMTABLE_INFO       *Info);
250
251void
252DtSetSubtableLength (
253    DT_SUBTABLE             *Subtable);
254
255void
256DtPushSubtable (
257    DT_SUBTABLE             *Subtable);
258
259void
260DtPopSubtable (
261    void);
262
263DT_SUBTABLE *
264DtPeekSubtable (
265    void);
266
267void
268DtInsertSubtable (
269    DT_SUBTABLE             *ParentTable,
270    DT_SUBTABLE             *Subtable);
271
272DT_SUBTABLE *
273DtGetNextSubtable (
274    DT_SUBTABLE             *ParentTable,
275    DT_SUBTABLE             *ChildTable);
276
277DT_SUBTABLE *
278DtGetParentSubtable (
279    DT_SUBTABLE             *Subtable);
280
281
282/* dtexpress - Integer expressions and labels */
283
284ACPI_STATUS
285DtResolveIntegerExpression (
286    DT_FIELD                *Field,
287    UINT64                  *ReturnValue);
288
289UINT64
290DtDoOperator (
291    UINT64                  LeftValue,
292    UINT32                  Operator,
293    UINT64                  RightValue);
294
295UINT64
296DtResolveLabel (
297    char                    *LabelString);
298
299void
300DtDetectAllLabels (
301    DT_FIELD                *FieldList);
302
303
304/* dtfield - Compile individual fields within a table */
305
306void
307DtCompileOneField (
308    UINT8                   *Buffer,
309    DT_FIELD                *Field,
310    UINT32                  ByteLength,
311    UINT8                   Type,
312    UINT8                   Flags);
313
314void
315DtCompileInteger (
316    UINT8                   *Buffer,
317    DT_FIELD                *Field,
318    UINT32                  ByteLength,
319    UINT8                   Flags);
320
321UINT32
322DtCompileBuffer (
323    UINT8                   *Buffer,
324    char                    *Value,
325    DT_FIELD                *Field,
326    UINT32                  ByteLength);
327
328void
329DtCompileFlag (
330    UINT8                   *Buffer,
331    DT_FIELD                *Field,
332    ACPI_DMTABLE_INFO       *Info);
333
334
335/* dtfield - DT_FIELD operations */
336
337void
338DtLinkField (
339    DT_FIELD                *Field);
340
341void
342DtCreateField (
343    DT_TABLE_UNIT           *FieldKey,
344    DT_TABLE_UNIT           *FieldValue,
345    UINT32                  Offset);
346
347DT_TABLE_UNIT *
348DtCreateTableUnit (
349    char                    *Data,
350    UINT32                  Line,
351    UINT32                  Column);
352
353
354/* dtparser - lex/yacc files */
355
356int
357DtCompilerParserparse (
358    void);
359
360UINT64
361DtEvaluateExpression (
362    char                    *ExprString);
363
364void
365DtCompilerInitLexer (
366    FILE                    *inFile);
367
368void
369DtCompilerTerminateLexer (
370    void);
371
372int
373DtInitLexer (
374    char                    *String);
375
376void
377DtTerminateLexer (
378    void);
379
380char *
381DtGetOpName (
382    UINT32                  ParseOpcode);
383
384
385/* dtutils - Miscellaneous utilities */
386
387typedef
388void (*DT_WALK_CALLBACK) (
389    DT_SUBTABLE             *Subtable,
390    void                    *Context,
391    void                    *ReturnValue);
392
393void
394DtWalkTableTree (
395    DT_SUBTABLE             *StartTable,
396    DT_WALK_CALLBACK        UserFunction,
397    void                    *Context,
398    void                    *ReturnValue);
399
400void
401DtError (
402    UINT8                   Level,
403    UINT16                  MessageId,
404    DT_FIELD                *FieldObject,
405    char                    *ExtraMessage);
406
407void
408DtNameError (
409    UINT8                   Level,
410    UINT16                  MessageId,
411    DT_FIELD                *FieldObject,
412    char                    *ExtraMessage);
413
414void
415DtFatal (
416    UINT16                  MessageId,
417    DT_FIELD                *FieldObject,
418    char                    *ExtraMessage);
419
420UINT64
421DtDoConstant (
422    char                    *String);
423
424char*
425DtGetFieldValue (
426    DT_FIELD                *Field);
427
428UINT8
429DtGetFieldType (
430    ACPI_DMTABLE_INFO       *Info);
431
432UINT32
433DtGetBufferLength (
434    char                    *Buffer);
435
436UINT32
437DtGetFieldLength (
438    DT_FIELD                *Field,
439    ACPI_DMTABLE_INFO       *Info);
440
441void
442DtSetTableChecksum (
443    UINT8                   *ChecksumPointer);
444
445void
446DtSetTableLength(
447    void);
448
449
450/* dttable - individual table compilation */
451
452ACPI_STATUS
453DtCompileFacs (
454    DT_FIELD                **PFieldList);
455
456ACPI_STATUS
457DtCompileRsdp (
458    DT_FIELD                **PFieldList);
459
460ACPI_STATUS
461DtCompileAest (
462    void                    **PFieldList);
463
464ACPI_STATUS
465DtCompileApmt (
466    void                    **PFieldList);
467
468ACPI_STATUS
469DtCompileAsf (
470    void                    **PFieldList);
471
472ACPI_STATUS
473DtCompileAspt (
474    void                    **PFieldList);
475
476ACPI_STATUS
477DtCompileCdat (
478    void                    **PFieldList);
479
480ACPI_STATUS
481DtCompileCedt (
482    void                    **PFieldList);
483
484ACPI_STATUS
485DtCompileCpep (
486    void                    **PFieldList);
487
488ACPI_STATUS
489DtCompileCsrt (
490    void                    **PFieldList);
491
492ACPI_STATUS
493DtCompileDbg2 (
494    void                    **PFieldList);
495
496ACPI_STATUS
497DtCompileDmar (
498    void                    **PFieldList);
499
500ACPI_STATUS
501DtCompileDrtm (
502    void                    **PFieldList);
503
504ACPI_STATUS
505DtCompileEinj (
506    void                    **PFieldList);
507
508ACPI_STATUS
509DtCompileErst (
510    void                    **PFieldList);
511
512ACPI_STATUS
513DtCompileFadt (
514    void                    **PFieldList);
515
516ACPI_STATUS
517DtCompileFpdt (
518    void                    **PFieldList);
519
520ACPI_STATUS
521DtCompileGtdt (
522    void                    **PFieldList);
523
524ACPI_STATUS
525DtCompileHest (
526    void                    **PFieldList);
527
528ACPI_STATUS
529DtCompileHmat (
530    void                    **PFieldList);
531
532ACPI_STATUS
533DtCompileIort (
534    void                    **PFieldList);
535
536ACPI_STATUS
537DtCompileIvrs (
538    void                    **PFieldList);
539
540ACPI_STATUS
541DtCompileLpit (
542    void                    **PFieldList);
543
544ACPI_STATUS
545DtCompileMadt (
546    void                    **PFieldList);
547
548ACPI_STATUS
549DtCompileMcfg (
550    void                    **PFieldList);
551
552ACPI_STATUS
553DtCompileMpam (
554    void                    **PFieldList);
555
556ACPI_STATUS
557DtCompileMpst (
558    void                    **PFieldList);
559
560ACPI_STATUS
561DtCompileMsct (
562    void                    **PFieldList);
563
564ACPI_STATUS
565DtCompileNfit (
566    void                    **PFieldList);
567
568ACPI_STATUS
569DtCompileNhlt (
570    void                    **PFieldList);
571
572ACPI_STATUS
573DtCompilePcct (
574    void                    **PFieldList);
575
576ACPI_STATUS
577DtCompilePdtt (
578    void                    **PFieldList);
579
580ACPI_STATUS
581DtCompilePhat (
582    void                    **PFieldList);
583
584ACPI_STATUS
585DtCompilePmtt (
586    void                    **PFieldList);
587
588ACPI_STATUS
589DtCompilePptt (
590    void                    **PFieldList);
591
592ACPI_STATUS
593DtCompilePrmt (
594    void                    **PFieldList);
595
596ACPI_STATUS
597DtCompileRgrt (
598    void                    **PFieldList);
599
600ACPI_STATUS
601DtCompileRhct (
602    void                    **PFieldList);
603
604ACPI_STATUS
605DtCompileRsdt (
606    void                    **PFieldList);
607
608ACPI_STATUS
609DtCompileS3pt (
610    DT_FIELD                **PFieldList);
611
612ACPI_STATUS
613DtCompileSdev (
614    void                    **PFieldList);
615
616ACPI_STATUS
617DtCompileSlic (
618    void                    **PFieldList);
619
620ACPI_STATUS
621DtCompileSlit (
622    void                    **PFieldList);
623
624ACPI_STATUS
625DtCompileSrat (
626    void                    **PFieldList);
627
628ACPI_STATUS
629DtCompileStao (
630    void                    **PFieldList);
631
632ACPI_STATUS
633DtCompileSvkl (
634    void                    **PFieldList);
635
636ACPI_STATUS
637DtCompileTcpa (
638    void                    **PFieldList);
639
640ACPI_STATUS
641DtCompileTpm2 (
642    void                    **PFieldList);
643
644ACPI_STATUS
645DtCompileUefi (
646    void                    **PFieldList);
647
648ACPI_STATUS
649DtCompileViot (
650    void                    **PFieldList);
651
652ACPI_STATUS
653DtCompileWdat (
654    void                    **PFieldList);
655
656ACPI_STATUS
657DtCompileWpbt (
658    void                    **PFieldList);
659
660ACPI_STATUS
661DtCompileXsdt (
662    void                    **PFieldList);
663
664ACPI_STATUS
665DtCompileGeneric (
666    void                    **PFieldList,
667    char                    *TermFieldName,
668    UINT32                  *PFieldLength);
669
670ACPI_DMTABLE_INFO *
671DtGetGenericTableInfo (
672    char                    *Name);
673
674/* ACPI Table templates */
675
676extern const unsigned char  TemplateAest[];
677extern const unsigned char  TemplateAgdi[];
678extern const unsigned char  TemplateApmt[];
679extern const unsigned char  TemplateAsf[];
680extern const unsigned char  TemplateAspt[];
681extern const unsigned char  TemplateBoot[];
682extern const unsigned char  TemplateBdat[];
683extern const unsigned char  TemplateBert[];
684extern const unsigned char  TemplateBgrt[];
685extern const unsigned char  TemplateCcel[];
686extern const unsigned char  TemplateCdat[];
687extern const unsigned char  TemplateCedt[];
688extern const unsigned char  TemplateCpep[];
689extern const unsigned char  TemplateCsrt[];
690extern const unsigned char  TemplateDbg2[];
691extern const unsigned char  TemplateDbgp[];
692extern const unsigned char  TemplateDmar[];
693extern const unsigned char  TemplateDrtm[];
694extern const unsigned char  TemplateEcdt[];
695extern const unsigned char  TemplateEinj[];
696extern const unsigned char  TemplateErst[];
697extern const unsigned char  TemplateFadt[];
698extern const unsigned char  TemplateFpdt[];
699extern const unsigned char  TemplateGtdt[];
700extern const unsigned char  TemplateHest[];
701extern const unsigned char  TemplateHmat[];
702extern const unsigned char  TemplateHpet[];
703extern const unsigned char  TemplateIort[];
704extern const unsigned char  TemplateIvrs[];
705extern const unsigned char  TemplateLpit[];
706extern const unsigned char  TemplateMadt[];
707extern const unsigned char  TemplateMcfg[];
708extern const unsigned char  TemplateMchi[];
709extern const unsigned char  TemplateMpam[];
710extern const unsigned char  TemplateMpst[];
711extern const unsigned char  TemplateMsct[];
712extern const unsigned char  TemplateMsdm[];
713extern const unsigned char  TemplateNfit[];
714extern const unsigned char  TemplateNhlt[];
715extern const unsigned char  TemplatePcct[];
716extern const unsigned char  TemplatePdtt[];
717extern const unsigned char  TemplatePhat[];
718extern const unsigned char  TemplatePmtt[];
719extern const unsigned char  TemplatePptt[];
720extern const unsigned char  TemplatePrmt[];
721extern const unsigned char  TemplateRasf[];
722extern const unsigned char  TemplateRgrt[];
723extern const unsigned char  TemplateRhct[];
724extern const unsigned char  TemplateRsdt[];
725extern const unsigned char  TemplateS3pt[];
726extern const unsigned char  TemplateSbst[];
727extern const unsigned char  TemplateSdei[];
728extern const unsigned char  TemplateSdev[];
729extern const unsigned char  TemplateSlic[];
730extern const unsigned char  TemplateSlit[];
731extern const unsigned char  TemplateSpcr[];
732extern const unsigned char  TemplateSpmi[];
733extern const unsigned char  TemplateSrat[];
734extern const unsigned char  TemplateStao[];
735extern const unsigned char  TemplateSvkl[];
736extern const unsigned char  TemplateTcpa[];
737extern const unsigned char  TemplateTdel[];
738extern const unsigned char  TemplateTpm2[];
739extern const unsigned char  TemplateUefi[];
740extern const unsigned char  TemplateViot[];
741extern const unsigned char  TemplateWaet[];
742extern const unsigned char  TemplateWdat[];
743extern const unsigned char  TemplateWddt[];
744extern const unsigned char  TemplateWdrt[];
745extern const unsigned char  TemplateWpbt[];
746extern const unsigned char  TemplateWsmt[];
747extern const unsigned char  TemplateXenv[];
748extern const unsigned char  TemplateXsdt[];
749
750#endif
751