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