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