1 /******************************************************************************
3 * Module Name: dttemplate - ACPI table template generation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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 (
62 const ACPI_DMTABLE_DATA *TableData);
65 DtCreateAllTemplates (
69 /*******************************************************************************
71 * FUNCTION: AcpiUtIsSpecialTable
73 * PARAMETERS: Signature - ACPI table signature
75 * RETURN: TRUE if signature is a special ACPI table
77 * DESCRIPTION: Check for valid ACPI tables that are not in the main ACPI
78 * table data structure (AcpiDmTableData).
80 ******************************************************************************/
83 AcpiUtIsSpecialTable (
87 if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT) ||
88 ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT) ||
89 ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS) ||
90 ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME))
99 /*******************************************************************************
101 * FUNCTION: DtCreateTemplates
103 * PARAMETERS: Signature - ACPI table signature
107 * DESCRIPTION: Create one or more template files.
109 ******************************************************************************/
115 const ACPI_DMTABLE_DATA *TableData;
119 AslInitializeGlobals ();
121 /* Default (no signature) is DSDT */
129 AcpiUtStrupr (Signature);
130 if (!ACPI_STRCMP (Signature, "ALL") ||
131 !ACPI_STRCMP (Signature, "*"))
133 /* Create all available/known templates */
135 Status = DtCreateAllTemplates ();
140 * Validate signature and get the template data:
141 * 1) Signature must be 4 characters
142 * 2) Signature must be a recognized ACPI table
143 * 3) There must be a template associated with the signature
145 if (strlen (Signature) != ACPI_NAME_SIZE)
148 "%s: Invalid ACPI table signature (length must be 4 characters)\n",
154 * Some slack for the two strange tables whose name is different than
155 * their signatures: MADT->APIC and FADT->FACP.
157 if (!strcmp (Signature, "MADT"))
161 else if (!strcmp (Signature, "FADT"))
167 TableData = AcpiDmGetTableData (Signature);
170 if (!TableData->Template)
172 fprintf (stderr, "%4.4s: No template available\n", Signature);
176 else if (!AcpiUtIsSpecialTable (Signature))
179 "%4.4s: Unrecognized ACPI table signature\n", Signature);
183 Status = AdInitialize ();
184 if (ACPI_FAILURE (Status))
189 Status = DtCreateOneTemplate (Signature, TableData);
192 /* Shutdown ACPICA subsystem */
194 (void) AcpiTerminate ();
200 /*******************************************************************************
202 * FUNCTION: DtCreateAllTemplates
208 * DESCRIPTION: Create all currently defined template files
210 ******************************************************************************/
213 DtCreateAllTemplates (
216 const ACPI_DMTABLE_DATA *TableData;
220 Status = AdInitialize ();
221 if (ACPI_FAILURE (Status))
226 fprintf (stderr, "Creating all supported Template files\n");
228 /* Walk entire ACPI table data structure */
230 for (TableData = AcpiDmTableData; TableData->Signature; TableData++)
232 /* If table has a template, create the template file */
234 if (TableData->Template)
236 Status = DtCreateOneTemplate (TableData->Signature,
238 if (ACPI_FAILURE (Status))
246 * Create the special ACPI tables:
247 * 1) DSDT/SSDT are AML tables, not data tables
248 * 2) FACS and RSDP have non-standard headers
250 Status = DtCreateOneTemplate (ACPI_SIG_DSDT, NULL);
251 if (ACPI_FAILURE (Status))
256 Status = DtCreateOneTemplate (ACPI_SIG_SSDT, NULL);
257 if (ACPI_FAILURE (Status))
262 Status = DtCreateOneTemplate (ACPI_SIG_FACS, NULL);
263 if (ACPI_FAILURE (Status))
268 Status = DtCreateOneTemplate (ACPI_RSDP_NAME, NULL);
269 if (ACPI_FAILURE (Status))
278 /*******************************************************************************
280 * FUNCTION: DtCreateOneTemplate
282 * PARAMETERS: Signature - ACPI signature, NULL terminated.
283 * TableData - Entry in ACPI table data structure.
284 * NULL if a special ACPI table.
288 * DESCRIPTION: Create one template source file for the requested ACPI table.
290 ******************************************************************************/
293 DtCreateOneTemplate (
295 const ACPI_DMTABLE_DATA *TableData)
297 char *DisasmFilename;
299 ACPI_STATUS Status = AE_OK;
303 /* New file will have a .asl suffix */
305 DisasmFilename = FlGenerateFilename (
306 Signature, FILE_SUFFIX_ASL_CODE);
309 fprintf (stderr, "Could not generate output filename\n");
313 /* Probably should prompt to overwrite the file */
315 AcpiUtStrlwr (DisasmFilename);
316 File = fopen (DisasmFilename, "w+");
319 fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
323 /* Emit the common file header */
325 AcpiOsRedirectOutput (File);
327 AcpiOsPrintf ("/*\n");
328 AcpiOsPrintf (ACPI_COMMON_HEADER ("iASL Compiler/Disassembler", " * "));
330 AcpiOsPrintf (" * Template for [%4.4s] ACPI Table\n",
333 /* Dump the actual ACPI table */
337 /* Normal case, tables that appear in AcpiDmTableData */
339 if (Gbl_VerboseTemplates)
341 AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]"
342 " FieldName : HexFieldValue\n */\n\n");
346 AcpiOsPrintf (" * Format: [ByteLength]"
347 " FieldName : HexFieldValue\n */\n\n");
350 AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
351 TableData->Template));
355 /* Special ACPI tables - DSDT, SSDT, FADT, RSDP */
357 AcpiOsPrintf (" */\n\n");
358 if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT))
360 Actual = fwrite (TemplateDsdt, 1, sizeof (TemplateDsdt) -1, File);
361 if (Actual != sizeof (TemplateDsdt) -1)
364 "Could not write to output file %s\n", DisasmFilename);
369 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT))
371 Actual = fwrite (TemplateSsdt, 1, sizeof (TemplateSsdt) -1, File);
372 if (Actual != sizeof (TemplateSsdt) -1)
375 "Could not write to output file %s\n", DisasmFilename);
380 else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS)) /* FADT */
382 AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
385 else if (ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME))
387 AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER,
393 "%4.4s, Unrecognized ACPI table signature\n", Signature);
400 "Created ACPI table template for [%4.4s], written to \"%s\"\n",
401 Signature, DisasmFilename);
405 AcpiOsRedirectOutput (stdout);