1 1.1 jruoho /****************************************************************************** 2 1.1 jruoho * 3 1.1 jruoho * Module Name: dtcompile.c - Front-end for data table compiler 4 1.1 jruoho * 5 1.1 jruoho *****************************************************************************/ 6 1.1 jruoho 7 1.21 christos /****************************************************************************** 8 1.21 christos * 9 1.21 christos * 1. Copyright Notice 10 1.21 christos * 11 1.22 christos * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp. 12 1.1 jruoho * All rights reserved. 13 1.1 jruoho * 14 1.21 christos * 2. License 15 1.21 christos * 16 1.21 christos * 2.1. This is your license from Intel Corp. under its intellectual property 17 1.21 christos * rights. You may have additional license terms from the party that provided 18 1.21 christos * you this software, covering your right to use that party's intellectual 19 1.21 christos * property rights. 20 1.21 christos * 21 1.21 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 1.21 christos * copy of the source code appearing in this file ("Covered Code") an 23 1.21 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 1.21 christos * base code distributed originally by Intel ("Original Intel Code") to copy, 25 1.21 christos * make derivatives, distribute, use and display any portion of the Covered 26 1.21 christos * Code in any form, with the right to sublicense such rights; and 27 1.21 christos * 28 1.21 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 1.21 christos * license (with the right to sublicense), under only those claims of Intel 30 1.21 christos * patents that are infringed by the Original Intel Code, to make, use, sell, 31 1.21 christos * offer to sell, and import the Covered Code and derivative works thereof 32 1.21 christos * solely to the minimum extent necessary to exercise the above copyright 33 1.21 christos * license, and in no event shall the patent license extend to any additions 34 1.21 christos * to or modifications of the Original Intel Code. No other license or right 35 1.21 christos * is granted directly or by implication, estoppel or otherwise; 36 1.21 christos * 37 1.21 christos * The above copyright and patent license is granted only if the following 38 1.21 christos * conditions are met: 39 1.21 christos * 40 1.21 christos * 3. Conditions 41 1.21 christos * 42 1.21 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 1.21 christos * Redistribution of source code of any substantial portion of the Covered 44 1.21 christos * Code or modification with rights to further distribute source must include 45 1.21 christos * the above Copyright Notice, the above License, this list of Conditions, 46 1.21 christos * and the following Disclaimer and Export Compliance provision. In addition, 47 1.21 christos * Licensee must cause all Covered Code to which Licensee contributes to 48 1.21 christos * contain a file documenting the changes Licensee made to create that Covered 49 1.21 christos * Code and the date of any change. Licensee must include in that file the 50 1.21 christos * documentation of any changes made by any predecessor Licensee. Licensee 51 1.21 christos * must include a prominent statement that the modification is derived, 52 1.21 christos * directly or indirectly, from Original Intel Code. 53 1.21 christos * 54 1.21 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 1.21 christos * Redistribution of source code of any substantial portion of the Covered 56 1.21 christos * Code or modification without rights to further distribute source must 57 1.21 christos * include the following Disclaimer and Export Compliance provision in the 58 1.21 christos * documentation and/or other materials provided with distribution. In 59 1.21 christos * addition, Licensee may not authorize further sublicense of source of any 60 1.21 christos * portion of the Covered Code, and must include terms to the effect that the 61 1.21 christos * license from Licensee to its licensee is limited to the intellectual 62 1.21 christos * property embodied in the software Licensee provides to its licensee, and 63 1.21 christos * not to intellectual property embodied in modifications its licensee may 64 1.21 christos * make. 65 1.21 christos * 66 1.21 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 1.21 christos * substantial portion of the Covered Code or modification must reproduce the 68 1.21 christos * above Copyright Notice, and the following Disclaimer and Export Compliance 69 1.21 christos * provision in the documentation and/or other materials provided with the 70 1.21 christos * distribution. 71 1.21 christos * 72 1.21 christos * 3.4. Intel retains all right, title, and interest in and to the Original 73 1.21 christos * Intel Code. 74 1.21 christos * 75 1.21 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 1.21 christos * Intel shall be used in advertising or otherwise to promote the sale, use or 77 1.21 christos * other dealings in products derived from or relating to the Covered Code 78 1.21 christos * without prior written authorization from Intel. 79 1.21 christos * 80 1.21 christos * 4. Disclaimer and Export Compliance 81 1.21 christos * 82 1.21 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 1.21 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 1.21 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 1.21 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 1.21 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 1.21 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 1.21 christos * PARTICULAR PURPOSE. 89 1.21 christos * 90 1.21 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 1.21 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 1.21 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 1.21 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 1.21 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 1.21 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 1.21 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 1.21 christos * LIMITED REMEDY. 98 1.21 christos * 99 1.21 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 1.21 christos * software or system incorporating such software without first obtaining any 101 1.21 christos * required license or other approval from the U. S. Department of Commerce or 102 1.21 christos * any other agency or department of the United States Government. In the 103 1.21 christos * event Licensee exports any such software from the United States or 104 1.21 christos * re-exports any such software from a foreign destination, Licensee shall 105 1.21 christos * ensure that the distribution and export/re-export of the software is in 106 1.21 christos * compliance with all laws, regulations, orders, or other restrictions of the 107 1.21 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 1.21 christos * any of its subsidiaries will export/re-export any technical data, process, 109 1.21 christos * software, or service, directly or indirectly, to any country for which the 110 1.21 christos * United States government or any agency thereof requires an export license, 111 1.21 christos * other governmental approval, or letter of assurance, without first obtaining 112 1.21 christos * such license, approval or letter. 113 1.21 christos * 114 1.21 christos ***************************************************************************** 115 1.21 christos * 116 1.21 christos * Alternatively, you may choose to be licensed under the terms of the 117 1.21 christos * following license: 118 1.21 christos * 119 1.2 christos * Redistribution and use in source and binary forms, with or without 120 1.2 christos * modification, are permitted provided that the following conditions 121 1.2 christos * are met: 122 1.2 christos * 1. Redistributions of source code must retain the above copyright 123 1.2 christos * notice, this list of conditions, and the following disclaimer, 124 1.2 christos * without modification. 125 1.2 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 1.2 christos * substantially similar to the "NO WARRANTY" disclaimer below 127 1.2 christos * ("Disclaimer") and any redistribution must be conditioned upon 128 1.2 christos * including a substantially similar Disclaimer requirement for further 129 1.2 christos * binary redistribution. 130 1.2 christos * 3. Neither the names of the above-listed copyright holders nor the names 131 1.2 christos * of any contributors may be used to endorse or promote products derived 132 1.2 christos * from this software without specific prior written permission. 133 1.2 christos * 134 1.2 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 1.2 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 1.17 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 1.2 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 1.21 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 1.21 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 1.21 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 1.21 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 1.21 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 1.21 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 1.21 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 1.21 christos * 146 1.21 christos * Alternatively, you may choose to be licensed under the terms of the 147 1.21 christos * GNU General Public License ("GPL") version 2 as published by the Free 148 1.21 christos * Software Foundation. 149 1.21 christos * 150 1.21 christos *****************************************************************************/ 151 1.1 jruoho 152 1.1 jruoho #define _DECLARE_DT_GLOBALS 153 1.1 jruoho 154 1.1 jruoho #include "aslcompiler.h" 155 1.1 jruoho 156 1.1 jruoho #define _COMPONENT DT_COMPILER 157 1.1 jruoho ACPI_MODULE_NAME ("dtcompile") 158 1.1 jruoho 159 1.1 jruoho static char VersionString[9]; 160 1.1 jruoho 161 1.1 jruoho 162 1.1 jruoho /* Local prototypes */ 163 1.1 jruoho 164 1.14 christos void 165 1.1 jruoho DtInitialize ( 166 1.1 jruoho void); 167 1.1 jruoho 168 1.1 jruoho static ACPI_STATUS 169 1.1 jruoho DtCompileDataTable ( 170 1.1 jruoho DT_FIELD **Field); 171 1.1 jruoho 172 1.1 jruoho static void 173 1.1 jruoho DtInsertCompilerIds ( 174 1.1 jruoho DT_FIELD *FieldList); 175 1.1 jruoho 176 1.1 jruoho 177 1.1 jruoho /****************************************************************************** 178 1.1 jruoho * 179 1.1 jruoho * FUNCTION: DtDoCompile 180 1.1 jruoho * 181 1.1 jruoho * PARAMETERS: None 182 1.1 jruoho * 183 1.1 jruoho * RETURN: Status 184 1.1 jruoho * 185 1.1 jruoho * DESCRIPTION: Main entry point for the data table compiler. 186 1.1 jruoho * 187 1.12 christos * Note: Assumes AslGbl_Files[ASL_FILE_INPUT] is initialized and the file is 188 1.1 jruoho * open at seek offset zero. 189 1.1 jruoho * 190 1.1 jruoho *****************************************************************************/ 191 1.1 jruoho 192 1.1 jruoho ACPI_STATUS 193 1.1 jruoho DtDoCompile ( 194 1.1 jruoho void) 195 1.1 jruoho { 196 1.1 jruoho ACPI_STATUS Status; 197 1.1 jruoho UINT8 Event; 198 1.1 jruoho DT_FIELD *FieldList; 199 1.14 christos ASL_GLOBAL_FILE_NODE *FileNode; 200 1.1 jruoho 201 1.1 jruoho 202 1.1 jruoho /* Initialize globals */ 203 1.1 jruoho 204 1.14 christos DtInitialize (); 205 1.2 christos 206 1.2 christos /* Preprocessor */ 207 1.2 christos 208 1.12 christos if (AslGbl_PreprocessFlag) 209 1.5 christos { 210 1.5 christos /* Preprocessor */ 211 1.5 christos 212 1.5 christos Event = UtBeginEvent ("Preprocess input file"); 213 1.5 christos PrDoPreprocess (); 214 1.5 christos UtEndEvent (Event); 215 1.2 christos 216 1.12 christos if (AslGbl_PreprocessOnly) 217 1.5 christos { 218 1.5 christos return (AE_OK); 219 1.5 christos } 220 1.2 christos } 221 1.1 jruoho 222 1.14 christos /* Compile the parse tree */ 223 1.14 christos 224 1.14 christos if (AslGbl_DtLexBisonPrototype) 225 1.14 christos { 226 1.14 christos Event = UtBeginEvent ("Parse data table in prototype mode"); 227 1.14 christos 228 1.14 christos DtCompilerInitLexer (AslGbl_Files[ASL_FILE_INPUT].Handle); 229 1.14 christos DtCompilerParserparse (); 230 1.14 christos FieldList = AslGbl_FieldList; 231 1.14 christos DtCompilerTerminateLexer (); 232 1.14 christos 233 1.14 christos UtEndEvent (Event); 234 1.14 christos } 235 1.14 christos else 236 1.14 christos { 237 1.14 christos /* 238 1.14 christos * Scan the input file (file is already open) and 239 1.14 christos * build the parse tree 240 1.14 christos */ 241 1.14 christos Event = UtBeginEvent ("Scan and parse input file"); 242 1.14 christos FieldList = DtScanFile (AslGbl_Files[ASL_FILE_INPUT].Handle); 243 1.14 christos UtEndEvent (Event); 244 1.14 christos } 245 1.1 jruoho 246 1.1 jruoho /* Did the parse tree get successfully constructed? */ 247 1.1 jruoho 248 1.1 jruoho if (!FieldList) 249 1.1 jruoho { 250 1.1 jruoho /* TBD: temporary error message. Msgs should come from function above */ 251 1.1 jruoho 252 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL, 253 1.2 christos "Input file does not appear to be an ASL or data table source file"); 254 1.2 christos 255 1.13 christos return (AE_ERROR); 256 1.1 jruoho } 257 1.1 jruoho 258 1.1 jruoho Event = UtBeginEvent ("Compile parse tree"); 259 1.1 jruoho 260 1.1 jruoho Status = DtCompileDataTable (&FieldList); 261 1.1 jruoho UtEndEvent (Event); 262 1.1 jruoho 263 1.14 christos FileNode = FlGetCurrentFileNode (); 264 1.15 christos 265 1.15 christos FileNode->TotalLineCount = AslGbl_CurrentLineNumber; 266 1.15 christos FileNode->OriginalInputFileSize = AslGbl_InputByteCount; 267 1.15 christos DbgPrint (ASL_PARSE_OUTPUT, "Line count: %u input file size: %u\n", 268 1.15 christos FileNode->TotalLineCount, FileNode->OriginalInputFileSize); 269 1.14 christos 270 1.1 jruoho if (ACPI_FAILURE (Status)) 271 1.1 jruoho { 272 1.14 christos FileNode->ParserErrorDetected = TRUE; 273 1.14 christos 274 1.1 jruoho /* TBD: temporary error message. Msgs should come from function above */ 275 1.1 jruoho 276 1.1 jruoho DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL, 277 1.1 jruoho "Could not compile input file"); 278 1.2 christos 279 1.13 christos return (Status); 280 1.1 jruoho } 281 1.1 jruoho 282 1.1 jruoho /* Create/open the binary output file */ 283 1.1 jruoho 284 1.12 christos AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL; 285 1.12 christos Status = FlOpenAmlOutputFile (AslGbl_OutputFilenamePrefix); 286 1.1 jruoho if (ACPI_FAILURE (Status)) 287 1.1 jruoho { 288 1.13 christos return (Status); 289 1.1 jruoho } 290 1.1 jruoho 291 1.1 jruoho /* Write the binary, then the optional hex file */ 292 1.1 jruoho 293 1.12 christos DtOutputBinary (AslGbl_RootTable); 294 1.2 christos HxDoHexOutput (); 295 1.2 christos DtWriteTableToListing (); 296 1.1 jruoho 297 1.14 christos /* Save the compile time statistics to the current file node */ 298 1.14 christos 299 1.15 christos FileNode->TotalFields = AslGbl_InputFieldCount; 300 1.15 christos FileNode->OutputByteLength = AslGbl_TableLength; 301 1.14 christos 302 1.1 jruoho return (Status); 303 1.1 jruoho } 304 1.1 jruoho 305 1.1 jruoho 306 1.1 jruoho /****************************************************************************** 307 1.1 jruoho * 308 1.1 jruoho * FUNCTION: DtInitialize 309 1.1 jruoho * 310 1.1 jruoho * PARAMETERS: None 311 1.1 jruoho * 312 1.2 christos * RETURN: Status 313 1.1 jruoho * 314 1.1 jruoho * DESCRIPTION: Initialize data table compiler globals. Enables multiple 315 1.1 jruoho * compiles per invocation. 316 1.1 jruoho * 317 1.1 jruoho *****************************************************************************/ 318 1.1 jruoho 319 1.14 christos void 320 1.1 jruoho DtInitialize ( 321 1.1 jruoho void) 322 1.1 jruoho { 323 1.2 christos 324 1.2 christos 325 1.9 christos AcpiUtSetIntegerWidth (2); /* Set width to 64 bits */ 326 1.9 christos 327 1.12 christos AslGbl_FieldList = NULL; 328 1.12 christos AslGbl_RootTable = NULL; 329 1.12 christos AslGbl_SubtableStack = NULL; 330 1.1 jruoho 331 1.3 tron snprintf (VersionString, sizeof(VersionString), "%X", 332 1.2 christos (UINT32) ACPI_CA_VERSION); 333 1.14 christos return; 334 1.1 jruoho } 335 1.1 jruoho 336 1.1 jruoho 337 1.1 jruoho /****************************************************************************** 338 1.1 jruoho * 339 1.1 jruoho * FUNCTION: DtInsertCompilerIds 340 1.1 jruoho * 341 1.1 jruoho * PARAMETERS: FieldList - Current field list pointer 342 1.1 jruoho * 343 1.1 jruoho * RETURN: None 344 1.1 jruoho * 345 1.1 jruoho * DESCRIPTION: Insert the IDs (Name, Version) of the current compiler into 346 1.1 jruoho * the original ACPI table header. 347 1.1 jruoho * 348 1.1 jruoho *****************************************************************************/ 349 1.1 jruoho 350 1.1 jruoho static void 351 1.1 jruoho DtInsertCompilerIds ( 352 1.1 jruoho DT_FIELD *FieldList) 353 1.1 jruoho { 354 1.1 jruoho DT_FIELD *Next; 355 1.1 jruoho UINT32 i; 356 1.1 jruoho 357 1.1 jruoho 358 1.1 jruoho /* 359 1.1 jruoho * Don't insert current compiler ID if requested. Used for compiler 360 1.1 jruoho * debug/validation only. 361 1.1 jruoho */ 362 1.12 christos if (AslGbl_UseOriginalCompilerId) 363 1.1 jruoho { 364 1.1 jruoho return; 365 1.1 jruoho } 366 1.1 jruoho 367 1.1 jruoho /* Walk to the Compiler fields at the end of the header */ 368 1.1 jruoho 369 1.1 jruoho Next = FieldList; 370 1.1 jruoho for (i = 0; i < 7; i++) 371 1.1 jruoho { 372 1.1 jruoho Next = Next->Next; 373 1.1 jruoho } 374 1.1 jruoho 375 1.2 christos Next->Value = ASL_CREATOR_ID; 376 1.1 jruoho Next->Flags = DT_FIELD_NOT_ALLOCATED; 377 1.1 jruoho 378 1.1 jruoho Next = Next->Next; 379 1.1 jruoho Next->Value = VersionString; 380 1.1 jruoho Next->Flags = DT_FIELD_NOT_ALLOCATED; 381 1.1 jruoho } 382 1.1 jruoho 383 1.1 jruoho 384 1.1 jruoho /****************************************************************************** 385 1.1 jruoho * 386 1.1 jruoho * FUNCTION: DtCompileDataTable 387 1.1 jruoho * 388 1.1 jruoho * PARAMETERS: FieldList - Current field list pointer 389 1.1 jruoho * 390 1.1 jruoho * RETURN: Status 391 1.1 jruoho * 392 1.1 jruoho * DESCRIPTION: Entry point to compile one data table 393 1.1 jruoho * 394 1.1 jruoho *****************************************************************************/ 395 1.1 jruoho 396 1.1 jruoho static ACPI_STATUS 397 1.1 jruoho DtCompileDataTable ( 398 1.1 jruoho DT_FIELD **FieldList) 399 1.1 jruoho { 400 1.6 christos const ACPI_DMTABLE_DATA *TableData; 401 1.1 jruoho DT_SUBTABLE *Subtable; 402 1.1 jruoho char *Signature; 403 1.1 jruoho ACPI_TABLE_HEADER *AcpiTableHeader; 404 1.1 jruoho ACPI_STATUS Status; 405 1.2 christos DT_FIELD *RootField = *FieldList; 406 1.1 jruoho 407 1.1 jruoho 408 1.1 jruoho /* Verify that we at least have a table signature and save it */ 409 1.1 jruoho 410 1.2 christos Signature = DtGetFieldValue (*FieldList); 411 1.1 jruoho if (!Signature) 412 1.1 jruoho { 413 1.12 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Expected \"%s\"", "Signature"); 414 1.2 christos DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME, 415 1.12 christos *FieldList, AslGbl_MsgBuffer); 416 1.1 jruoho return (AE_ERROR); 417 1.1 jruoho } 418 1.1 jruoho 419 1.12 christos AslGbl_Signature = UtLocalCacheCalloc (strlen (Signature) + 1); 420 1.12 christos strcpy (AslGbl_Signature, Signature); 421 1.1 jruoho 422 1.1 jruoho /* 423 1.1 jruoho * Handle tables that don't use the common ACPI table header structure. 424 1.1 jruoho * Currently, these are the FACS and RSDP. Also check for an OEMx table, 425 1.1 jruoho * these tables have user-defined contents. 426 1.1 jruoho */ 427 1.13 christos if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_FACS)) 428 1.1 jruoho { 429 1.1 jruoho Status = DtCompileFacs (FieldList); 430 1.1 jruoho if (ACPI_FAILURE (Status)) 431 1.1 jruoho { 432 1.1 jruoho return (Status); 433 1.1 jruoho } 434 1.1 jruoho 435 1.1 jruoho DtSetTableLength (); 436 1.1 jruoho return (Status); 437 1.1 jruoho } 438 1.2 christos else if (ACPI_VALIDATE_RSDP_SIG (Signature)) 439 1.1 jruoho { 440 1.1 jruoho Status = DtCompileRsdp (FieldList); 441 1.1 jruoho return (Status); 442 1.1 jruoho } 443 1.13 christos else if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_S3PT)) 444 1.1 jruoho { 445 1.2 christos Status = DtCompileS3pt (FieldList); 446 1.2 christos if (ACPI_FAILURE (Status)) 447 1.2 christos { 448 1.2 christos return (Status); 449 1.2 christos } 450 1.2 christos 451 1.2 christos DtSetTableLength (); 452 1.2 christos return (Status); 453 1.1 jruoho } 454 1.1 jruoho 455 1.1 jruoho /* 456 1.19 christos * If the first field is named "CDAT Table Length" (not "Signature"), 457 1.19 christos * assume that we have a CDAT table (whose table header does not have 458 1.19 christos * a signature). Instead, the TableLength field is where the 459 1.19 christos * signature would (normally) be. 460 1.19 christos */ 461 1.19 christos else if (!strcmp ((*FieldList)->Name, "CDAT Table Length")) 462 1.19 christos { 463 1.19 christos /* No longer true: (However, use this technique in the disassembler) 464 1.19 christos * We are assuming that there 465 1.19 christos * should be at least one non-ASCII byte in the 4-character 466 1.19 christos * Signature field, (At least the high-order byte should be zero). 467 1.19 christos */ 468 1.19 christos Status = DtCompileTable (FieldList, AcpiDmTableInfoCdatTableHdr, 469 1.19 christos &AslGbl_RootTable); 470 1.19 christos if (ACPI_FAILURE (Status)) 471 1.19 christos { 472 1.19 christos return (Status); 473 1.19 christos } 474 1.19 christos 475 1.19 christos /* Compile the CDAT */ 476 1.19 christos 477 1.19 christos DtPushSubtable (AslGbl_RootTable); 478 1.19 christos Status = DtCompileCdat ((void **) FieldList); 479 1.19 christos if (ACPI_FAILURE (Status)) 480 1.19 christos { 481 1.19 christos return (Status); 482 1.19 christos } 483 1.19 christos 484 1.19 christos /* 485 1.19 christos * Set the overall table length and the table checksum. 486 1.19 christos * The entire compiled table (including the CDAT table header with 487 1.19 christos * the table length and checksum) is in AslGbl_RootTable->Buffer. 488 1.19 christos */ 489 1.19 christos DtSetTableLength (); 490 1.19 christos DtSetTableChecksum (&ACPI_CAST_PTR (ACPI_TABLE_CDAT, AslGbl_RootTable->Buffer)->Checksum); 491 1.19 christos 492 1.19 christos DtDumpFieldList (RootField); 493 1.19 christos DtDumpSubtableList (); 494 1.19 christos return (AE_OK); 495 1.19 christos } 496 1.19 christos 497 1.19 christos /* 498 1.1 jruoho * All other tables must use the common ACPI table header. Insert the 499 1.1 jruoho * current iASL IDs (name, version), and compile the header now. 500 1.1 jruoho */ 501 1.1 jruoho DtInsertCompilerIds (*FieldList); 502 1.1 jruoho 503 1.1 jruoho Status = DtCompileTable (FieldList, AcpiDmTableInfoHeader, 504 1.12 christos &AslGbl_RootTable); 505 1.1 jruoho if (ACPI_FAILURE (Status)) 506 1.1 jruoho { 507 1.1 jruoho return (Status); 508 1.1 jruoho } 509 1.1 jruoho 510 1.12 christos DtPushSubtable (AslGbl_RootTable); 511 1.1 jruoho 512 1.2 christos /* Validate the signature via the ACPI table list */ 513 1.1 jruoho 514 1.1 jruoho TableData = AcpiDmGetTableData (Signature); 515 1.12 christos if (!TableData || AslGbl_CompileGeneric) 516 1.1 jruoho { 517 1.6 christos /* Unknown table signature and/or force generic compile */ 518 1.6 christos 519 1.6 christos DtCompileGeneric ((void **) FieldList, NULL, NULL); 520 1.2 christos goto FinishHeader; 521 1.1 jruoho } 522 1.1 jruoho 523 1.2 christos /* Dispatch to per-table compile */ 524 1.2 christos 525 1.1 jruoho if (TableData->CmTableHandler) 526 1.1 jruoho { 527 1.1 jruoho /* Complex table, has a handler */ 528 1.1 jruoho 529 1.1 jruoho Status = TableData->CmTableHandler ((void **) FieldList); 530 1.1 jruoho if (ACPI_FAILURE (Status)) 531 1.1 jruoho { 532 1.1 jruoho return (Status); 533 1.1 jruoho } 534 1.1 jruoho } 535 1.1 jruoho else if (TableData->TableInfo) 536 1.1 jruoho { 537 1.9 christos /* Simple table, just walk the info table, unless its empty */ 538 1.1 jruoho 539 1.9 christos if (FieldList && *FieldList) 540 1.1 jruoho { 541 1.9 christos Subtable = NULL; 542 1.9 christos Status = DtCompileTable (FieldList, TableData->TableInfo, 543 1.11 christos &Subtable); 544 1.9 christos if (ACPI_FAILURE (Status)) 545 1.9 christos { 546 1.9 christos return (Status); 547 1.9 christos } 548 1.9 christos 549 1.12 christos DtInsertSubtable (AslGbl_RootTable, Subtable); 550 1.9 christos DtPopSubtable (); 551 1.1 jruoho } 552 1.1 jruoho } 553 1.1 jruoho else 554 1.1 jruoho { 555 1.1 jruoho DtFatal (ASL_MSG_COMPILER_INTERNAL, *FieldList, 556 1.1 jruoho "Missing table dispatch info"); 557 1.1 jruoho return (AE_ERROR); 558 1.1 jruoho } 559 1.1 jruoho 560 1.2 christos FinishHeader: 561 1.2 christos 562 1.1 jruoho /* Set the final table length and then the checksum */ 563 1.1 jruoho 564 1.1 jruoho DtSetTableLength (); 565 1.1 jruoho AcpiTableHeader = ACPI_CAST_PTR ( 566 1.12 christos ACPI_TABLE_HEADER, AslGbl_RootTable->Buffer); 567 1.1 jruoho DtSetTableChecksum (&AcpiTableHeader->Checksum); 568 1.1 jruoho 569 1.2 christos DtDumpFieldList (RootField); 570 1.2 christos DtDumpSubtableList (); 571 1.1 jruoho return (AE_OK); 572 1.1 jruoho } 573 1.1 jruoho 574 1.1 jruoho 575 1.1 jruoho /****************************************************************************** 576 1.1 jruoho * 577 1.1 jruoho * FUNCTION: DtCompileTable 578 1.1 jruoho * 579 1.1 jruoho * PARAMETERS: Field - Current field list pointer 580 1.1 jruoho * Info - Info table for this ACPI table 581 1.1 jruoho * RetSubtable - Compile result of table 582 1.1 jruoho * 583 1.1 jruoho * RETURN: Status 584 1.1 jruoho * 585 1.1 jruoho * DESCRIPTION: Compile a subtable 586 1.1 jruoho * 587 1.1 jruoho *****************************************************************************/ 588 1.1 jruoho 589 1.1 jruoho ACPI_STATUS 590 1.1 jruoho DtCompileTable ( 591 1.1 jruoho DT_FIELD **Field, 592 1.1 jruoho ACPI_DMTABLE_INFO *Info, 593 1.11 christos DT_SUBTABLE **RetSubtable) 594 1.1 jruoho { 595 1.1 jruoho DT_FIELD *LocalField; 596 1.1 jruoho UINT32 Length; 597 1.1 jruoho DT_SUBTABLE *Subtable; 598 1.6 christos DT_SUBTABLE *InlineSubtable = NULL; 599 1.1 jruoho UINT32 FieldLength = 0; 600 1.1 jruoho UINT8 FieldType; 601 1.1 jruoho UINT8 *Buffer; 602 1.1 jruoho UINT8 *FlagBuffer = NULL; 603 1.4 christos char *String; 604 1.2 christos UINT32 CurrentFlagByteOffset = 0; 605 1.6 christos ACPI_STATUS Status = AE_OK; 606 1.1 jruoho 607 1.1 jruoho 608 1.15 christos if (!Field || !Info) 609 1.1 jruoho { 610 1.1 jruoho return (AE_BAD_PARAMETER); 611 1.1 jruoho } 612 1.11 christos if (!*Field) 613 1.11 christos { 614 1.11 christos /* 615 1.11 christos * The field list is empty, this means that we are out of fields to 616 1.11 christos * parse. In other words, we are at the end of the table. 617 1.11 christos */ 618 1.11 christos return (AE_END_OF_TABLE); 619 1.11 christos } 620 1.1 jruoho 621 1.2 christos /* Ignore optional subtable if name does not match */ 622 1.2 christos 623 1.2 christos if ((Info->Flags & DT_OPTIONAL) && 624 1.6 christos strcmp ((*Field)->Name, Info->Name)) 625 1.2 christos { 626 1.2 christos *RetSubtable = NULL; 627 1.2 christos return (AE_OK); 628 1.2 christos } 629 1.2 christos 630 1.1 jruoho Length = DtGetSubtableLength (*Field, Info); 631 1.2 christos if (Length == ASL_EOF) 632 1.2 christos { 633 1.2 christos return (AE_ERROR); 634 1.2 christos } 635 1.2 christos 636 1.4 christos Subtable = UtSubtableCacheCalloc (); 637 1.1 jruoho 638 1.2 christos if (Length > 0) 639 1.2 christos { 640 1.10 christos String = UtLocalCacheCalloc (Length); 641 1.4 christos Subtable->Buffer = ACPI_CAST_PTR (UINT8, String); 642 1.2 christos } 643 1.4 christos 644 1.1 jruoho Subtable->Length = Length; 645 1.1 jruoho Subtable->TotalLength = Length; 646 1.1 jruoho Buffer = Subtable->Buffer; 647 1.1 jruoho 648 1.1 jruoho LocalField = *Field; 649 1.6 christos Subtable->Name = LocalField->Name; 650 1.1 jruoho 651 1.1 jruoho /* 652 1.1 jruoho * Main loop walks the info table for this ACPI table or subtable 653 1.1 jruoho */ 654 1.1 jruoho for (; Info->Name; Info++) 655 1.1 jruoho { 656 1.2 christos if (Info->Opcode == ACPI_DMT_EXTRA_TEXT) 657 1.2 christos { 658 1.2 christos continue; 659 1.2 christos } 660 1.2 christos 661 1.1 jruoho if (!LocalField) 662 1.1 jruoho { 663 1.12 christos snprintf (AslGbl_MsgBuffer, sizeof(AslGbl_MsgBuffer), "Found NULL field - Field name \"%s\" needed", 664 1.1 jruoho Info->Name); 665 1.12 christos DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer); 666 1.1 jruoho Status = AE_BAD_DATA; 667 1.1 jruoho goto Error; 668 1.1 jruoho } 669 1.1 jruoho 670 1.2 christos /* Maintain table offsets */ 671 1.1 jruoho 672 1.12 christos LocalField->TableOffset = AslGbl_CurrentTableOffset; 673 1.2 christos FieldLength = DtGetFieldLength (LocalField, Info); 674 1.12 christos AslGbl_CurrentTableOffset += FieldLength; 675 1.1 jruoho 676 1.1 jruoho FieldType = DtGetFieldType (Info); 677 1.12 christos AslGbl_InputFieldCount++; 678 1.1 jruoho 679 1.15 christos if (FieldType != DT_FIELD_TYPE_INLINE_SUBTABLE && 680 1.15 christos strcmp (Info->Name, LocalField->Name)) 681 1.15 christos { 682 1.15 christos sprintf (AslGbl_MsgBuffer, "found \"%s\" expected \"%s\"", 683 1.15 christos LocalField->Name, Info->Name); 684 1.15 christos DtError (ASL_ERROR, ASL_MSG_INVALID_LABEL, LocalField, AslGbl_MsgBuffer); 685 1.15 christos } 686 1.15 christos 687 1.1 jruoho switch (FieldType) 688 1.1 jruoho { 689 1.1 jruoho case DT_FIELD_TYPE_FLAGS_INTEGER: 690 1.1 jruoho /* 691 1.1 jruoho * Start of the definition of a flags field. 692 1.1 jruoho * This master flags integer starts at value zero, in preparation 693 1.1 jruoho * to compile and insert the flag fields from the individual bits 694 1.1 jruoho */ 695 1.1 jruoho LocalField = LocalField->Next; 696 1.1 jruoho *Field = LocalField; 697 1.1 jruoho 698 1.1 jruoho FlagBuffer = Buffer; 699 1.2 christos CurrentFlagByteOffset = Info->Offset; 700 1.1 jruoho break; 701 1.1 jruoho 702 1.1 jruoho case DT_FIELD_TYPE_FLAG: 703 1.1 jruoho 704 1.1 jruoho /* Individual Flag field, can be multiple bits */ 705 1.1 jruoho 706 1.1 jruoho if (FlagBuffer) 707 1.1 jruoho { 708 1.2 christos /* 709 1.2 christos * We must increment the FlagBuffer when we have crossed 710 1.2 christos * into the next flags byte within the flags field 711 1.2 christos * of type DT_FIELD_TYPE_FLAGS_INTEGER. 712 1.2 christos */ 713 1.2 christos FlagBuffer += (Info->Offset - CurrentFlagByteOffset); 714 1.2 christos CurrentFlagByteOffset = Info->Offset; 715 1.2 christos 716 1.2 christos DtCompileFlag (FlagBuffer, LocalField, Info); 717 1.1 jruoho } 718 1.1 jruoho else 719 1.1 jruoho { 720 1.1 jruoho /* TBD - this is an internal error */ 721 1.1 jruoho } 722 1.1 jruoho 723 1.1 jruoho LocalField = LocalField->Next; 724 1.1 jruoho *Field = LocalField; 725 1.1 jruoho break; 726 1.1 jruoho 727 1.1 jruoho case DT_FIELD_TYPE_INLINE_SUBTABLE: 728 1.1 jruoho /* 729 1.1 jruoho * Recursion (one level max): compile GAS (Generic Address) 730 1.1 jruoho * or Notify in-line subtable 731 1.1 jruoho */ 732 1.1 jruoho *Field = LocalField; 733 1.1 jruoho 734 1.6 christos switch (Info->Opcode) 735 1.1 jruoho { 736 1.6 christos case ACPI_DMT_GAS: 737 1.6 christos 738 1.1 jruoho Status = DtCompileTable (Field, AcpiDmTableInfoGas, 739 1.11 christos &InlineSubtable); 740 1.6 christos break; 741 1.6 christos 742 1.6 christos case ACPI_DMT_HESTNTFY: 743 1.6 christos 744 1.1 jruoho Status = DtCompileTable (Field, AcpiDmTableInfoHestNotify, 745 1.11 christos &InlineSubtable); 746 1.6 christos break; 747 1.6 christos 748 1.6 christos case ACPI_DMT_IORTMEM: 749 1.6 christos 750 1.6 christos Status = DtCompileTable (Field, AcpiDmTableInfoIortAcc, 751 1.11 christos &InlineSubtable); 752 1.6 christos break; 753 1.6 christos 754 1.6 christos default: 755 1.12 christos sprintf (AslGbl_MsgBuffer, "Invalid DMT opcode: 0x%.2X", 756 1.6 christos Info->Opcode); 757 1.12 christos DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, AslGbl_MsgBuffer); 758 1.6 christos Status = AE_BAD_DATA; 759 1.6 christos break; 760 1.1 jruoho } 761 1.1 jruoho 762 1.1 jruoho if (ACPI_FAILURE (Status)) 763 1.1 jruoho { 764 1.1 jruoho goto Error; 765 1.1 jruoho } 766 1.1 jruoho 767 1.2 christos DtSetSubtableLength (InlineSubtable); 768 1.2 christos 769 1.6 christos memcpy (Buffer, InlineSubtable->Buffer, FieldLength); 770 1.1 jruoho LocalField = *Field; 771 1.1 jruoho break; 772 1.1 jruoho 773 1.2 christos case DT_FIELD_TYPE_LABEL: 774 1.2 christos 775 1.2 christos DtWriteFieldToListing (Buffer, LocalField, 0); 776 1.2 christos LocalField = LocalField->Next; 777 1.2 christos break; 778 1.2 christos 779 1.1 jruoho default: 780 1.1 jruoho 781 1.1 jruoho /* Normal case for most field types (Integer, String, etc.) */ 782 1.1 jruoho 783 1.1 jruoho DtCompileOneField (Buffer, LocalField, 784 1.1 jruoho FieldLength, FieldType, Info->Flags); 785 1.2 christos 786 1.2 christos DtWriteFieldToListing (Buffer, LocalField, FieldLength); 787 1.1 jruoho LocalField = LocalField->Next; 788 1.1 jruoho 789 1.1 jruoho if (Info->Flags & DT_LENGTH) 790 1.1 jruoho { 791 1.1 jruoho /* Field is an Integer that will contain a subtable length */ 792 1.1 jruoho 793 1.1 jruoho Subtable->LengthField = Buffer; 794 1.1 jruoho Subtable->SizeOfLengthField = FieldLength; 795 1.1 jruoho } 796 1.1 jruoho break; 797 1.1 jruoho } 798 1.1 jruoho 799 1.1 jruoho Buffer += FieldLength; 800 1.1 jruoho } 801 1.1 jruoho 802 1.1 jruoho *Field = LocalField; 803 1.1 jruoho *RetSubtable = Subtable; 804 1.1 jruoho return (AE_OK); 805 1.1 jruoho 806 1.1 jruoho Error: 807 1.1 jruoho ACPI_FREE (Subtable->Buffer); 808 1.1 jruoho ACPI_FREE (Subtable); 809 1.1 jruoho return (Status); 810 1.1 jruoho } 811 1.6 christos 812 1.6 christos 813 1.6 christos /****************************************************************************** 814 1.6 christos * 815 1.7 christos * FUNCTION: DtCompileTwoSubtables 816 1.7 christos * 817 1.7 christos * PARAMETERS: List - Current field list pointer 818 1.7 christos * TableInfo1 - Info table 1 819 1.7 christos * TableInfo1 - Info table 2 820 1.7 christos * 821 1.7 christos * RETURN: Status 822 1.7 christos * 823 1.7 christos * DESCRIPTION: Compile tables with a header and one or more same subtables. 824 1.7 christos * Include CPEP, EINJ, ERST, MCFG, MSCT, WDAT 825 1.7 christos * 826 1.7 christos *****************************************************************************/ 827 1.7 christos 828 1.7 christos ACPI_STATUS 829 1.7 christos DtCompileTwoSubtables ( 830 1.7 christos void **List, 831 1.7 christos ACPI_DMTABLE_INFO *TableInfo1, 832 1.7 christos ACPI_DMTABLE_INFO *TableInfo2) 833 1.7 christos { 834 1.7 christos ACPI_STATUS Status; 835 1.7 christos DT_SUBTABLE *Subtable; 836 1.7 christos DT_SUBTABLE *ParentTable; 837 1.7 christos DT_FIELD **PFieldList = (DT_FIELD **) List; 838 1.7 christos 839 1.7 christos 840 1.11 christos Status = DtCompileTable (PFieldList, TableInfo1, &Subtable); 841 1.7 christos if (ACPI_FAILURE (Status)) 842 1.7 christos { 843 1.7 christos return (Status); 844 1.7 christos } 845 1.7 christos 846 1.7 christos ParentTable = DtPeekSubtable (); 847 1.7 christos DtInsertSubtable (ParentTable, Subtable); 848 1.7 christos 849 1.7 christos while (*PFieldList) 850 1.7 christos { 851 1.11 christos Status = DtCompileTable (PFieldList, TableInfo2, &Subtable); 852 1.7 christos if (ACPI_FAILURE (Status)) 853 1.7 christos { 854 1.7 christos return (Status); 855 1.7 christos } 856 1.7 christos 857 1.7 christos DtInsertSubtable (ParentTable, Subtable); 858 1.7 christos } 859 1.7 christos 860 1.7 christos return (AE_OK); 861 1.7 christos } 862 1.7 christos 863 1.7 christos 864 1.7 christos /****************************************************************************** 865 1.7 christos * 866 1.6 christos * FUNCTION: DtCompilePadding 867 1.6 christos * 868 1.6 christos * PARAMETERS: Length - Padding field size 869 1.6 christos * RetSubtable - Compile result of table 870 1.6 christos * 871 1.6 christos * RETURN: Status 872 1.6 christos * 873 1.6 christos * DESCRIPTION: Compile a subtable for padding purpose 874 1.6 christos * 875 1.6 christos *****************************************************************************/ 876 1.6 christos 877 1.6 christos ACPI_STATUS 878 1.6 christos DtCompilePadding ( 879 1.6 christos UINT32 Length, 880 1.6 christos DT_SUBTABLE **RetSubtable) 881 1.6 christos { 882 1.6 christos DT_SUBTABLE *Subtable; 883 1.6 christos /* UINT8 *Buffer; */ 884 1.6 christos char *String; 885 1.6 christos 886 1.6 christos 887 1.6 christos Subtable = UtSubtableCacheCalloc (); 888 1.6 christos 889 1.6 christos if (Length > 0) 890 1.6 christos { 891 1.10 christos String = UtLocalCacheCalloc (Length); 892 1.6 christos Subtable->Buffer = ACPI_CAST_PTR (UINT8, String); 893 1.6 christos } 894 1.6 christos 895 1.6 christos Subtable->Length = Length; 896 1.6 christos Subtable->TotalLength = Length; 897 1.6 christos /* Buffer = Subtable->Buffer; */ 898 1.6 christos 899 1.6 christos *RetSubtable = Subtable; 900 1.6 christos return (AE_OK); 901 1.6 christos } 902