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