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