xref: /freebsd/sys/contrib/dev/acpica/compiler/dtcompiler.h (revision c243e4902be8df1e643c76b5f18b68bb77cc5268)
1 /******************************************************************************
2  *
3  * Module Name: dtcompiler.h - header for data table compiler
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2012, 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 #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     UINT8                   Flags;
117 
118 } DT_SUBTABLE;
119 
120 
121 /*
122  * Globals
123  */
124 
125 /* List of all field names and values from the input source */
126 
127 DT_EXTERN DT_FIELD          DT_INIT_GLOBAL (*Gbl_FieldList, NULL);
128 
129 /* List of all compiled tables and subtables */
130 
131 DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*Gbl_RootTable, NULL);
132 
133 /* Stack for subtables */
134 
135 DT_EXTERN DT_SUBTABLE       DT_INIT_GLOBAL (*Gbl_SubtableStack, NULL);
136 
137 /* List for defined labels */
138 
139 DT_EXTERN DT_FIELD          DT_INIT_GLOBAL (*Gbl_LabelList, NULL);
140 
141 /* Current offset within the binary output table */
142 
143 DT_EXTERN UINT32            DT_INIT_GLOBAL (Gbl_CurrentTableOffset, 0);
144 
145 
146 /* dtcompiler - main module */
147 
148 ACPI_STATUS
149 DtCompileTable (
150     DT_FIELD                **Field,
151     ACPI_DMTABLE_INFO       *Info,
152     DT_SUBTABLE             **RetSubtable,
153     BOOLEAN                 Required);
154 
155 
156 /* dtio - binary and text input/output */
157 
158 UINT32
159 DtGetNextLine (
160     FILE                    *Handle);
161 
162 DT_FIELD *
163 DtScanFile (
164     FILE                    *Handle);
165 
166 void
167 DtOutputBinary (
168     DT_SUBTABLE             *RootTable);
169 
170 void
171 DtWriteFieldToListing (
172     UINT8                   *Buffer,
173     DT_FIELD                *Field,
174     UINT32                  Length);
175 
176 void
177 DtWriteTableToListing (
178     void);
179 
180 
181 /* dtsubtable - compile subtables */
182 
183 void
184 DtCreateSubtable (
185     UINT8                   *Buffer,
186     UINT32                  Length,
187     DT_SUBTABLE             **RetSubtable);
188 
189 UINT32
190 DtGetSubtableLength (
191     DT_FIELD                *Field,
192     ACPI_DMTABLE_INFO       *Info);
193 
194 void
195 DtSetSubtableLength (
196     DT_SUBTABLE             *Subtable);
197 
198 void
199 DtPushSubtable (
200     DT_SUBTABLE             *Subtable);
201 
202 void
203 DtPopSubtable (
204     void);
205 
206 DT_SUBTABLE *
207 DtPeekSubtable (
208     void);
209 
210 void
211 DtInsertSubtable (
212     DT_SUBTABLE             *ParentTable,
213     DT_SUBTABLE             *Subtable);
214 
215 DT_SUBTABLE *
216 DtGetNextSubtable (
217     DT_SUBTABLE             *ParentTable,
218     DT_SUBTABLE             *ChildTable);
219 
220 DT_SUBTABLE *
221 DtGetParentSubtable (
222     DT_SUBTABLE             *Subtable);
223 
224 
225 /* dtexpress - Integer expressions and labels */
226 
227 ACPI_STATUS
228 DtResolveIntegerExpression (
229     DT_FIELD                *Field,
230     UINT64                  *ReturnValue);
231 
232 UINT64
233 DtDoOperator (
234     UINT64                  LeftValue,
235     UINT32                  Operator,
236     UINT64                  RightValue);
237 
238 UINT64
239 DtResolveLabel (
240     char                    *LabelString);
241 
242 void
243 DtDetectAllLabels (
244     DT_FIELD                *FieldList);
245 
246 
247 /* dtfield - Compile individual fields within a table */
248 
249 void
250 DtCompileOneField (
251     UINT8                   *Buffer,
252     DT_FIELD                *Field,
253     UINT32                  ByteLength,
254     UINT8                   Type,
255     UINT8                   Flags);
256 
257 void
258 DtCompileInteger (
259     UINT8                   *Buffer,
260     DT_FIELD                *Field,
261     UINT32                  ByteLength,
262     UINT8                   Flags);
263 
264 UINT32
265 DtCompileBuffer (
266     UINT8                   *Buffer,
267     char                    *Value,
268     DT_FIELD                *Field,
269     UINT32                  ByteLength);
270 
271 void
272 DtCompileFlag (
273     UINT8                   *Buffer,
274     DT_FIELD                *Field,
275     ACPI_DMTABLE_INFO       *Info);
276 
277 
278 /* dtparser - lex/yacc files */
279 
280 UINT64
281 DtEvaluateExpression (
282     char                    *ExprString);
283 
284 int
285 DtInitLexer (
286     char                    *String);
287 
288 void
289 DtTerminateLexer (
290     void);
291 
292 char *
293 DtGetOpName (
294     UINT32                  ParseOpcode);
295 
296 
297 /* dtutils - Miscellaneous utilities */
298 
299 typedef
300 void (*DT_WALK_CALLBACK) (
301     DT_SUBTABLE             *Subtable,
302     void                    *Context,
303     void                    *ReturnValue);
304 
305 void
306 DtWalkTableTree (
307     DT_SUBTABLE             *StartTable,
308     DT_WALK_CALLBACK        UserFunction,
309     void                    *Context,
310     void                    *ReturnValue);
311 
312 void
313 DtError (
314     UINT8                   Level,
315     UINT8                   MessageId,
316     DT_FIELD                *FieldObject,
317     char                    *ExtraMessage);
318 
319 void
320 DtNameError (
321     UINT8                   Level,
322     UINT8                   MessageId,
323     DT_FIELD                *FieldObject,
324     char                    *ExtraMessage);
325 
326 void
327 DtFatal (
328     UINT8                   MessageId,
329     DT_FIELD                *FieldObject,
330     char                    *ExtraMessage);
331 
332 ACPI_STATUS
333 DtStrtoul64 (
334     char                    *String,
335     UINT64                  *ReturnInteger);
336 
337 UINT32
338 DtGetFileSize (
339     FILE                    *Handle);
340 
341 char*
342 DtGetFieldValue (
343     DT_FIELD                *Field);
344 
345 UINT8
346 DtGetFieldType (
347     ACPI_DMTABLE_INFO       *Info);
348 
349 UINT32
350 DtGetBufferLength (
351     char                    *Buffer);
352 
353 UINT32
354 DtGetFieldLength (
355     DT_FIELD                *Field,
356     ACPI_DMTABLE_INFO       *Info);
357 
358 void
359 DtSetTableChecksum (
360     UINT8                   *ChecksumPointer);
361 
362 void
363 DtSetTableLength(
364     void);
365 
366 void
367 DtFreeFieldList (
368     void);
369 
370 
371 /* dttable - individual table compilation */
372 
373 ACPI_STATUS
374 DtCompileFacs (
375     DT_FIELD                **PFieldList);
376 
377 ACPI_STATUS
378 DtCompileRsdp (
379     DT_FIELD                **PFieldList);
380 
381 ACPI_STATUS
382 DtCompileAsf (
383     void                    **PFieldList);
384 
385 ACPI_STATUS
386 DtCompileCpep (
387     void                    **PFieldList);
388 
389 ACPI_STATUS
390 DtCompileDmar (
391     void                    **PFieldList);
392 
393 ACPI_STATUS
394 DtCompileEinj (
395     void                    **PFieldList);
396 
397 ACPI_STATUS
398 DtCompileErst (
399     void                    **PFieldList);
400 
401 ACPI_STATUS
402 DtCompileFadt (
403     void                    **PFieldList);
404 
405 ACPI_STATUS
406 DtCompileFpdt (
407     void                    **PFieldList);
408 
409 ACPI_STATUS
410 DtCompileHest (
411     void                    **PFieldList);
412 
413 ACPI_STATUS
414 DtCompileIvrs (
415     void                    **PFieldList);
416 
417 ACPI_STATUS
418 DtCompileMadt (
419     void                    **PFieldList);
420 
421 ACPI_STATUS
422 DtCompileMcfg (
423     void                    **PFieldList);
424 
425 ACPI_STATUS
426 DtCompileMpst (
427     void                    **PFieldList);
428 
429 ACPI_STATUS
430 DtCompileMsct (
431     void                    **PFieldList);
432 
433 ACPI_STATUS
434 DtCompilePmtt (
435     void                    **PFieldList);
436 
437 ACPI_STATUS
438 DtCompileRsdt (
439     void                    **PFieldList);
440 
441 ACPI_STATUS
442 DtCompileS3pt (
443     DT_FIELD                **PFieldList);
444 
445 ACPI_STATUS
446 DtCompileSlic (
447     void                    **PFieldList);
448 
449 ACPI_STATUS
450 DtCompileSlit (
451     void                    **PFieldList);
452 
453 ACPI_STATUS
454 DtCompileSrat (
455     void                    **PFieldList);
456 
457 ACPI_STATUS
458 DtCompileUefi (
459     void                    **PFieldList);
460 
461 ACPI_STATUS
462 DtCompileWdat (
463     void                    **PFieldList);
464 
465 ACPI_STATUS
466 DtCompileXsdt (
467     void                    **PFieldList);
468 
469 ACPI_STATUS
470 DtCompileGeneric (
471     void                    **PFieldList);
472 
473 ACPI_DMTABLE_INFO *
474 DtGetGenericTableInfo (
475     char                    *Name);
476 
477 /* ACPI Table templates */
478 
479 extern const unsigned char  TemplateAsf[];
480 extern const unsigned char  TemplateBoot[];
481 extern const unsigned char  TemplateBert[];
482 extern const unsigned char  TemplateBgrt[];
483 extern const unsigned char  TemplateCpep[];
484 extern const unsigned char  TemplateDbgp[];
485 extern const unsigned char  TemplateDmar[];
486 extern const unsigned char  TemplateEcdt[];
487 extern const unsigned char  TemplateEinj[];
488 extern const unsigned char  TemplateErst[];
489 extern const unsigned char  TemplateFadt[];
490 extern const unsigned char  TemplateFpdt[];
491 extern const unsigned char  TemplateGtdt[];
492 extern const unsigned char  TemplateHest[];
493 extern const unsigned char  TemplateHpet[];
494 extern const unsigned char  TemplateIvrs[];
495 extern const unsigned char  TemplateMadt[];
496 extern const unsigned char  TemplateMcfg[];
497 extern const unsigned char  TemplateMchi[];
498 extern const unsigned char  TemplateMpst[];
499 extern const unsigned char  TemplateMsct[];
500 extern const unsigned char  TemplatePmtt[];
501 extern const unsigned char  TemplateRsdt[];
502 extern const unsigned char  TemplateS3pt[];
503 extern const unsigned char  TemplateSbst[];
504 extern const unsigned char  TemplateSlic[];
505 extern const unsigned char  TemplateSlit[];
506 extern const unsigned char  TemplateSpcr[];
507 extern const unsigned char  TemplateSpmi[];
508 extern const unsigned char  TemplateSrat[];
509 extern const unsigned char  TemplateTcpa[];
510 extern const unsigned char  TemplateUefi[];
511 extern const unsigned char  TemplateWaet[];
512 extern const unsigned char  TemplateWdat[];
513 extern const unsigned char  TemplateWddt[];
514 extern const unsigned char  TemplateWdrt[];
515 extern const unsigned char  TemplateXsdt[];
516 
517 #endif
518