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