db5d306d21107442672cac6e1f1a914643235f30
[dragonfly.git] / sys / contrib / dev / acpica / source / compiler / dtcompiler.h
1 /******************************************************************************
2  *
3  * Module Name: dtcompiler.h - header for data table compiler
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2014, 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 "acdisasm.h"
51
52
53 #undef DT_EXTERN
54
55 #ifdef _DECLARE_DT_GLOBALS
56 #define DT_EXTERN
57 #define DT_INIT_GLOBAL(a,b)         (a)=(b)
58 #else
59 #define DT_EXTERN                   extern
60 #define DT_INIT_GLOBAL(a,b)         (a)
61 #endif
62
63
64 /* Types for individual fields (one per input line) */
65
66 #define DT_FIELD_TYPE_STRING            0
67 #define DT_FIELD_TYPE_INTEGER           1
68 #define DT_FIELD_TYPE_BUFFER            2
69 #define DT_FIELD_TYPE_PCI_PATH          3
70 #define DT_FIELD_TYPE_FLAG              4
71 #define DT_FIELD_TYPE_FLAGS_INTEGER     5
72 #define DT_FIELD_TYPE_INLINE_SUBTABLE   6
73 #define DT_FIELD_TYPE_UUID              7
74 #define DT_FIELD_TYPE_UNICODE           8
75 #define DT_FIELD_TYPE_DEVICE_PATH       9
76 #define DT_FIELD_TYPE_LABEL             10
77
78
79 /*
80  * Structure used for each individual field within an ACPI table
81  */
82 typedef struct dt_field
83 {
84     char                    *Name;      /* Field name (from name : value) */
85     char                    *Value;     /* Field value (from name : value) */
86     struct dt_field         *Next;      /* Next field */
87     struct dt_field         *NextLabel; /* If field is a label, next label */
88     UINT32                  Line;       /* Line number for this field */
89     UINT32                  ByteOffset; /* Offset in source file for field */
90     UINT32                  NameColumn; /* Start column for field name */
91     UINT32                  Column;     /* Start column for field value */
92     UINT32                  TableOffset;/* Binary offset within ACPI table */
93     UINT8                   Flags;
94
95 } DT_FIELD;
96
97 /* Flags for above */
98
99 #define DT_FIELD_NOT_ALLOCATED      1
100
101
102 /*
103  * Structure used for individual subtables within an ACPI table
104  */
105 typedef struct dt_subtable
106 {
107     struct dt_subtable      *Parent;
108     struct dt_subtable      *Child;
109     struct dt_subtable      *Peer;
110     struct dt_subtable      *StackTop;
111     UINT8                   *Buffer;
112     UINT8                   *LengthField;
113     UINT32                  Length;
114     UINT32                  TotalLength;
115     UINT32                  SizeOfLengthField;
116     UINT16                  Depth;
117     UINT8                   Flags;
118
119 } DT_SUBTABLE;
120
121
122 /*
123  * Globals
124  */
125
126 /* List of all field names and values from the input source */
127
128 DT_EXTERN DT_FIELD          DT_INIT_GLOBAL (*Gbl_FieldList, NULL);
129
130 /* List of all compiled tables and subtables */
131
132 DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*Gbl_RootTable, NULL);
133
134 /* Stack for subtables */
135
136 DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*Gbl_SubtableStack, NULL);
137
138 /* List for defined labels */
139
140 DT_EXTERN DT_FIELD          DT_INIT_GLOBAL (*Gbl_LabelList, NULL);
141
142 /* Current offset within the binary output table */
143
144 DT_EXTERN UINT32            DT_INIT_GLOBAL (Gbl_CurrentTableOffset, 0);
145
146
147 /* dtcompiler - main module */
148
149 ACPI_STATUS
150 DtCompileTable (
151     DT_FIELD                **Field,
152     ACPI_DMTABLE_INFO       *Info,
153     DT_SUBTABLE             **RetSubtable,
154     BOOLEAN                 Required);
155
156
157 /* dtio - binary and text input/output */
158
159 UINT32
160 DtGetNextLine (
161     FILE                    *Handle);
162
163 DT_FIELD *
164 DtScanFile (
165     FILE                    *Handle);
166
167 void
168 DtOutputBinary (
169     DT_SUBTABLE             *RootTable);
170
171 void
172 DtDumpSubtableList (
173     void);
174
175 void
176 DtDumpFieldList (
177     DT_FIELD                *Field);
178
179 void
180 DtWriteFieldToListing (
181     UINT8                   *Buffer,
182     DT_FIELD                *Field,
183     UINT32                  Length);
184
185 void
186 DtWriteTableToListing (
187     void);
188
189
190 /* dtsubtable - compile subtables */
191
192 void
193 DtCreateSubtable (
194     UINT8                   *Buffer,
195     UINT32                  Length,
196     DT_SUBTABLE             **RetSubtable);
197
198 UINT32
199 DtGetSubtableLength (
200     DT_FIELD                *Field,
201     ACPI_DMTABLE_INFO       *Info);
202
203 void
204 DtSetSubtableLength (
205     DT_SUBTABLE             *Subtable);
206
207 void
208 DtPushSubtable (
209     DT_SUBTABLE             *Subtable);
210
211 void
212 DtPopSubtable (
213     void);
214
215 DT_SUBTABLE *
216 DtPeekSubtable (
217     void);
218
219 void
220 DtInsertSubtable (
221     DT_SUBTABLE             *ParentTable,
222     DT_SUBTABLE             *Subtable);
223
224 DT_SUBTABLE *
225 DtGetNextSubtable (
226     DT_SUBTABLE             *ParentTable,
227     DT_SUBTABLE             *ChildTable);
228
229 DT_SUBTABLE *
230 DtGetParentSubtable (
231     DT_SUBTABLE             *Subtable);
232
233
234 /* dtexpress - Integer expressions and labels */
235
236 ACPI_STATUS
237 DtResolveIntegerExpression (
238     DT_FIELD                *Field,
239     UINT64                  *ReturnValue);
240
241 UINT64
242 DtDoOperator (
243     UINT64                  LeftValue,
244     UINT32                  Operator,
245     UINT64                  RightValue);
246
247 UINT64
248 DtResolveLabel (
249     char                    *LabelString);
250
251 void
252 DtDetectAllLabels (
253     DT_FIELD                *FieldList);
254
255
256 /* dtfield - Compile individual fields within a table */
257
258 void
259 DtCompileOneField (
260     UINT8                   *Buffer,
261     DT_FIELD                *Field,
262     UINT32                  ByteLength,
263     UINT8                   Type,
264     UINT8                   Flags);
265
266 void
267 DtCompileInteger (
268     UINT8                   *Buffer,
269     DT_FIELD                *Field,
270     UINT32                  ByteLength,
271     UINT8                   Flags);
272
273 UINT32
274 DtCompileBuffer (
275     UINT8                   *Buffer,
276     char                    *Value,
277     DT_FIELD                *Field,
278     UINT32                  ByteLength);
279
280 void
281 DtCompileFlag (
282     UINT8                   *Buffer,
283     DT_FIELD                *Field,
284     ACPI_DMTABLE_INFO       *Info);
285
286
287 /* dtparser - lex/yacc files */
288
289 UINT64
290 DtEvaluateExpression (
291     char                    *ExprString);
292
293 int
294 DtInitLexer (
295     char                    *String);
296
297 void
298 DtTerminateLexer (
299     void);
300
301 char *
302 DtGetOpName (
303     UINT32                  ParseOpcode);
304
305
306 /* dtutils - Miscellaneous utilities */
307
308 typedef
309 void (*DT_WALK_CALLBACK) (
310     DT_SUBTABLE             *Subtable,
311     void                    *Context,
312     void                    *ReturnValue);
313
314 void
315 DtWalkTableTree (
316     DT_SUBTABLE             *StartTable,
317     DT_WALK_CALLBACK        UserFunction,
318     void                    *Context,
319     void                    *ReturnValue);
320
321 void
322 DtError (
323     UINT8                   Level,
324     UINT16                  MessageId,
325     DT_FIELD                *FieldObject,
326     char                    *ExtraMessage);
327
328 void
329 DtNameError (
330     UINT8                   Level,
331     UINT16                  MessageId,
332     DT_FIELD                *FieldObject,
333     char                    *ExtraMessage);
334
335 void
336 DtFatal (
337     UINT16                  MessageId,
338     DT_FIELD                *FieldObject,
339     char                    *ExtraMessage);
340
341 ACPI_STATUS
342 DtStrtoul64 (
343     char                    *String,
344     UINT64                  *ReturnInteger);
345
346 char*
347 DtGetFieldValue (
348     DT_FIELD                *Field);
349
350 UINT8
351 DtGetFieldType (
352     ACPI_DMTABLE_INFO       *Info);
353
354 UINT32
355 DtGetBufferLength (
356     char                    *Buffer);
357
358 UINT32
359 DtGetFieldLength (
360     DT_FIELD                *Field,
361     ACPI_DMTABLE_INFO       *Info);
362
363 void
364 DtSetTableChecksum (
365     UINT8                   *ChecksumPointer);
366
367 void
368 DtSetTableLength(
369     void);
370
371 void
372 DtFreeFieldList (
373     void);
374
375
376 /* dttable - individual table compilation */
377
378 ACPI_STATUS
379 DtCompileFacs (
380     DT_FIELD                **PFieldList);
381
382 ACPI_STATUS
383 DtCompileRsdp (
384     DT_FIELD                **PFieldList);
385
386 ACPI_STATUS
387 DtCompileAsf (
388     void                    **PFieldList);
389
390 ACPI_STATUS
391 DtCompileCpep (
392     void                    **PFieldList);
393
394 ACPI_STATUS
395 DtCompileCsrt (
396     void                    **PFieldList);
397
398 ACPI_STATUS
399 DtCompileDbg2 (
400     void                    **PFieldList);
401
402 ACPI_STATUS
403 DtCompileDmar (
404     void                    **PFieldList);
405
406 ACPI_STATUS
407 DtCompileEinj (
408     void                    **PFieldList);
409
410 ACPI_STATUS
411 DtCompileErst (
412     void                    **PFieldList);
413
414 ACPI_STATUS
415 DtCompileFadt (
416     void                    **PFieldList);
417
418 ACPI_STATUS
419 DtCompileFpdt (
420     void                    **PFieldList);
421
422 ACPI_STATUS
423 DtCompileHest (
424     void                    **PFieldList);
425
426 ACPI_STATUS
427 DtCompileIvrs (
428     void                    **PFieldList);
429
430 ACPI_STATUS
431 DtCompileLpit (
432     void                    **PFieldList);
433
434 ACPI_STATUS
435 DtCompileMadt (
436     void                    **PFieldList);
437
438 ACPI_STATUS
439 DtCompileMcfg (
440     void                    **PFieldList);
441
442 ACPI_STATUS
443 DtCompileMpst (
444     void                    **PFieldList);
445
446 ACPI_STATUS
447 DtCompileMsct (
448     void                    **PFieldList);
449
450 ACPI_STATUS
451 DtCompileMtmr (
452     void                    **PFieldList);
453
454 ACPI_STATUS
455 DtCompilePmtt (
456     void                    **PFieldList);
457
458 ACPI_STATUS
459 DtCompilePcct (
460     void                    **PFieldList);
461
462 ACPI_STATUS
463 DtCompileRsdt (
464     void                    **PFieldList);
465
466 ACPI_STATUS
467 DtCompileS3pt (
468     DT_FIELD                **PFieldList);
469
470 ACPI_STATUS
471 DtCompileSlic (
472     void                    **PFieldList);
473
474 ACPI_STATUS
475 DtCompileSlit (
476     void                    **PFieldList);
477
478 ACPI_STATUS
479 DtCompileSrat (
480     void                    **PFieldList);
481
482 ACPI_STATUS
483 DtCompileUefi (
484     void                    **PFieldList);
485
486 ACPI_STATUS
487 DtCompileVrtc (
488     void                    **PFieldList);
489
490 ACPI_STATUS
491 DtCompileWdat (
492     void                    **PFieldList);
493
494 ACPI_STATUS
495 DtCompileXsdt (
496     void                    **PFieldList);
497
498 ACPI_STATUS
499 DtCompileGeneric (
500     void                    **PFieldList);
501
502 ACPI_DMTABLE_INFO *
503 DtGetGenericTableInfo (
504     char                    *Name);
505
506 /* ACPI Table templates */
507
508 extern const unsigned char  TemplateAsf[];
509 extern const unsigned char  TemplateBoot[];
510 extern const unsigned char  TemplateBert[];
511 extern const unsigned char  TemplateBgrt[];
512 extern const unsigned char  TemplateCpep[];
513 extern const unsigned char  TemplateCsrt[];
514 extern const unsigned char  TemplateDbg2[];
515 extern const unsigned char  TemplateDbgp[];
516 extern const unsigned char  TemplateDmar[];
517 extern const unsigned char  TemplateEcdt[];
518 extern const unsigned char  TemplateEinj[];
519 extern const unsigned char  TemplateErst[];
520 extern const unsigned char  TemplateFadt[];
521 extern const unsigned char  TemplateFpdt[];
522 extern const unsigned char  TemplateGtdt[];
523 extern const unsigned char  TemplateHest[];
524 extern const unsigned char  TemplateHpet[];
525 extern const unsigned char  TemplateIvrs[];
526 extern const unsigned char  TemplateLpit[];
527 extern const unsigned char  TemplateMadt[];
528 extern const unsigned char  TemplateMcfg[];
529 extern const unsigned char  TemplateMchi[];
530 extern const unsigned char  TemplateMpst[];
531 extern const unsigned char  TemplateMsct[];
532 extern const unsigned char  TemplateMtmr[];
533 extern const unsigned char  TemplatePcct[];
534 extern const unsigned char  TemplatePmtt[];
535 extern const unsigned char  TemplateRsdt[];
536 extern const unsigned char  TemplateS3pt[];
537 extern const unsigned char  TemplateSbst[];
538 extern const unsigned char  TemplateSlic[];
539 extern const unsigned char  TemplateSlit[];
540 extern const unsigned char  TemplateSpcr[];
541 extern const unsigned char  TemplateSpmi[];
542 extern const unsigned char  TemplateSrat[];
543 extern const unsigned char  TemplateTcpa[];
544 extern const unsigned char  TemplateTpm2[];
545 extern const unsigned char  TemplateUefi[];
546 extern const unsigned char  TemplateVrtc[];
547 extern const unsigned char  TemplateWaet[];
548 extern const unsigned char  TemplateWdat[];
549 extern const unsigned char  TemplateWddt[];
550 extern const unsigned char  TemplateWdrt[];
551 extern const unsigned char  TemplateXsdt[];
552
553 #endif