1 /******************************************************************************
3 * Module Name: dttemplate - ACPI table template generation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include <contrib/dev/acpica/include/acapps.h>
46 #include <contrib/dev/acpica/compiler/dtcompiler.h>
47 #include <contrib/dev/acpica/compiler/dttemplate.h> /* Contains the hex ACPI table templates */
49 #define _COMPONENT DT_COMPILER
50 ACPI_MODULE_NAME ("dttemplate")
53 /* Local prototypes */
56 AcpiUtIsSpecialTable (
60 DtCreateOneTemplateFile (
68 const ACPI_DMTABLE_DATA *TableData);
71 DtCreateAllTemplates (
75 DtEmitDefinitionBlock (
82 /*******************************************************************************
84 * FUNCTION: AcpiUtIsSpecialTable
86 * PARAMETERS: Signature - ACPI table signature
88 * RETURN: TRUE if signature is a special ACPI table
90 * DESCRIPTION: Check for valid ACPI tables that are not in the main ACPI
91 * table data structure (AcpiDmTableData).
93 ******************************************************************************/
96 AcpiUtIsSpecialTable (
100 if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT) ||
101 ACPI_COMPARE_NAME (Signature, ACPI_SIG_OSDT) ||
102 ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT) ||
103 ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS) ||
104 ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME))
113 /*******************************************************************************
115 * FUNCTION: DtCreateTemplates
117 * PARAMETERS: argv - Standard command line arguments
121 * DESCRIPTION: Create one or more template files.
123 ******************************************************************************/
131 unsigned long TableCount;
132 ACPI_STATUS Status = AE_OK;
135 AslInitializeGlobals ();
137 Status = AdInitialize ();
138 if (ACPI_FAILURE (Status))
144 * Special cases for DSDT, ALL, and '*'
147 /* Default (no signature option) is DSDT */
149 if (AcpiGbl_Optind < 3)
151 Status = DtCreateOneTemplateFile (ACPI_SIG_DSDT, 0);
156 Signature = argv[AcpiGbl_Optind];
157 AcpiUtStrupr (Signature);
160 * Multiple SSDT support (-T <ssdt count>)
162 TableCount = strtoul (Signature, &End, 0);
163 if (Signature != End)
165 /* The count is used for table ID and method name - max is 254(+1) */
167 if (TableCount > 254)
169 fprintf (stderr, "%u SSDTs requested, maximum is 254\n",
170 (unsigned int) TableCount);
176 Status = DtCreateOneTemplateFile (ACPI_SIG_DSDT, TableCount);
180 if (!strcmp (Signature, "ALL"))
182 /* Create all available/known templates */
184 Status = DtCreateAllTemplates ();
189 * Normal case: Create template for each signature
191 while (argv[AcpiGbl_Optind])
193 Signature = argv[AcpiGbl_Optind];
194 AcpiUtStrupr (Signature);
196 Status = DtCreateOneTemplateFile (Signature, 0);
197 if (ACPI_FAILURE (Status))
207 /* Shutdown ACPICA subsystem */
209 (void) AcpiTerminate ();
215 /*******************************************************************************
217 * FUNCTION: DtCreateOneTemplateFile
219 * PARAMETERS: Signature - ACPI table signature
223 * DESCRIPTION: Create one template file of the requested signature.
225 ******************************************************************************/
228 DtCreateOneTemplateFile (
232 const ACPI_DMTABLE_DATA *TableData;
237 * Validate signature and get the template data:
238 * 1) Signature must be 4 characters
239 * 2) Signature must be a recognized ACPI table
240 * 3) There must be a template associated with the signature
242 if (strlen (Signature) != ACPI_NAME_SIZE)
245 "%s: Invalid ACPI table signature "
246 "(length must be 4 characters)\n", Signature);
251 * Some slack for the two strange tables whose name is different than
252 * their signatures: MADT->APIC and FADT->FACP.
254 if (!strcmp (Signature, "MADT"))
258 else if (!strcmp (Signature, "FADT"))
263 /* TableData will point to the template */
265 TableData = AcpiDmGetTableData (Signature);
268 if (!TableData->Template)
270 fprintf (stderr, "%4.4s: No template available\n", Signature);
274 else if (!AcpiUtIsSpecialTable (Signature))
277 "%4.4s: Unrecognized ACPI table signature\n", Signature);
281 Status = DtCreateOneTemplate (Signature, TableCount, TableData);
286 /*******************************************************************************
288 * FUNCTION: DtCreateAllTemplates
294 * DESCRIPTION: Create all currently defined template files
296 ******************************************************************************/
299 DtCreateAllTemplates (
302 const ACPI_DMTABLE_DATA *TableData;
306 fprintf (stderr, "Creating all supported Template files\n");
308 /* Walk entire ACPI table data structure */
310 for (TableData = AcpiDmTableData; TableData->Signature; TableData++)
312 /* If table has a template, create the template file */
314 if (TableData->Template)
316 Status = DtCreateOneTemplate (TableData->Signature,
318 if (ACPI_FAILURE (Status))
326 * Create the special ACPI tables:
327 * 1) DSDT/SSDT are AML tables, not data tables
328 * 2) FACS and RSDP have non-standard headers
330 Status = DtCreateOneTemplate (ACPI_SIG_DSDT, 0, NULL);
331 if (ACPI_FAILURE (Status))
336 Status = DtCreateOneTemplate (ACPI_SIG_SSDT, 0, NULL);
337 if (ACPI_FAILURE (Status))
342 Status = DtCreateOneTemplate (ACPI_SIG_OSDT, 0, NULL);
343 if (ACPI_FAILURE (Status))
348 Status = DtCreateOneTemplate (ACPI_SIG_FACS, 0, NULL);
349 if (ACPI_FAILURE (Status))
354 Status = DtCreateOneTemplate (ACPI_RSDP_NAME, 0, NULL);
355 if (ACPI_FAILURE (Status))
364 /*******************************************************************************
366 * FUNCTION: DtCreateOneTemplate
368 * PARAMETERS: Signature - ACPI signature, NULL terminated.
369 * TableCount - Used for SSDTs in same file as DSDT
370 * TableData - Entry in ACPI table data structure.
371 * NULL if a special ACPI table.
375 * DESCRIPTION: Create one template source file for the requested ACPI table.
377 ******************************************************************************/
380 DtCreateOneTemplate (
383 const ACPI_DMTABLE_DATA *TableData)
385 char *DisasmFilename;
387 ACPI_STATUS Status = AE_OK;
392 /* New file will have a .asl suffix */
394 DisasmFilename = FlGenerateFilename (
395 Signature, FILE_SUFFIX_ASL_CODE);
398 fprintf (stderr, "Could not generate output filename\n");
402 AcpiUtStrlwr (DisasmFilename);
403 if (!UtQueryForOverwrite (DisasmFilename))
408 File = fopen (DisasmFilename, "w+");
411 fprintf (stderr, "Could not open output file %s\n",
416 /* Emit the common file header */
418 AcpiOsRedirectOutput (File);
420 AcpiOsPrintf ("/*\n");
421 AcpiOsPrintf (ACPI_COMMON_HEADER ("iASL Compiler/Disassembler", " * "));
425 AcpiOsPrintf (" * Template for [%4.4s] ACPI Table",
430 AcpiOsPrintf (" * Template for [%4.4s] and %u [SSDT] ACPI Tables",
431 Signature, TableCount);
434 /* Dump the actual ACPI table */
438 /* Normal case, tables that appear in AcpiDmTableData */
440 AcpiOsPrintf (" (static data table)\n");
442 if (Gbl_VerboseTemplates)
444 AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]"
445 " FieldName : HexFieldValue\n */\n\n");
449 AcpiOsPrintf (" * Format: [ByteLength]"
450 " FieldName : HexFieldValue\n */\n");
453 AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
454 TableData->Template));
458 /* Special ACPI tables - DSDT, SSDT, OSDT, FACS, RSDP */
460 AcpiOsPrintf (" (AML byte code table)\n");
461 AcpiOsPrintf (" */\n");
463 if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT))
465 Actual = DtEmitDefinitionBlock (
466 File, DisasmFilename, ACPI_SIG_DSDT, 1);
473 /* Emit any requested SSDTs into the same file */
475 for (i = 1; i <= TableCount; i++)
477 Actual = DtEmitDefinitionBlock (
478 File, DisasmFilename, ACPI_SIG_SSDT, i + 1);
486 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT))
488 Actual = DtEmitDefinitionBlock (
489 File, DisasmFilename, ACPI_SIG_SSDT, 1);
496 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_OSDT))
498 Actual = DtEmitDefinitionBlock (
499 File, DisasmFilename, ACPI_SIG_OSDT, 1);
506 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS))
508 AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
511 else if (ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME))
513 AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
519 "%4.4s, Unrecognized ACPI table signature\n", Signature);
528 "Created ACPI table template for [%4.4s], "
529 "written to \"%s\"\n",
530 Signature, DisasmFilename);
535 "Created ACPI table templates for [%4.4s] "
536 "and %u [SSDT], written to \"%s\"\n",
537 Signature, TableCount, DisasmFilename);
542 AcpiOsRedirectOutput (stdout);
547 /*******************************************************************************
549 * FUNCTION: DtEmitDefinitionBlock
551 * PARAMETERS: File - An open file for the block
552 * Filename - Filename for same, for error msg(s)
553 * Signature - ACPI signature for the block
554 * Instance - Used for multiple SSDTs in the same file
556 * RETURN: Status from fprintf
558 * DESCRIPTION: Emit the raw ASL for a complete Definition Block (DSDT or SSDT)
560 * Note: The AMLFileName parameter for DefinitionBlock is left as a NULL
561 * string. This allows the compiler to create the output AML filename from
562 * the input filename.
564 ******************************************************************************/
567 DtEmitDefinitionBlock (
576 Status = fprintf (File,
577 "DefinitionBlock (\"\", \"%4.4s\", 2, \"Intel\", \"_%4.4s_%.2X\", 0x00000001)\n"
579 " Method (%2.2s%.2X)\n"
583 Signature, Signature, Instance, Signature, Instance);
588 "Could not write %4.4s to output file %s\n",
589 Signature, Filename);