1a88e22b7SJung-uk Kim /****************************************************************************** 2a88e22b7SJung-uk Kim * 3a88e22b7SJung-uk Kim * Module Name: dttemplate - ACPI table template generation 4a88e22b7SJung-uk Kim * 5a88e22b7SJung-uk Kim *****************************************************************************/ 6a88e22b7SJung-uk Kim 70d84335fSJung-uk Kim /****************************************************************************** 80d84335fSJung-uk Kim * 90d84335fSJung-uk Kim * 1. Copyright Notice 100d84335fSJung-uk Kim * 11*804fe266SJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp. 12a88e22b7SJung-uk Kim * All rights reserved. 13a88e22b7SJung-uk Kim * 140d84335fSJung-uk Kim * 2. License 150d84335fSJung-uk Kim * 160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property 170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided 180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual 190d84335fSJung-uk Kim * property rights. 200d84335fSJung-uk Kim * 210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an 230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy, 250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered 260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and 270d84335fSJung-uk Kim * 280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel 300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell, 310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof 320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright 330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions 340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right 350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise; 360d84335fSJung-uk Kim * 370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following 380d84335fSJung-uk Kim * conditions are met: 390d84335fSJung-uk Kim * 400d84335fSJung-uk Kim * 3. Conditions 410d84335fSJung-uk Kim * 420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source. 430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include 450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions, 460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition, 470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to 480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered 490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the 500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee 510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived, 520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code. 530d84335fSJung-uk Kim * 540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered 560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must 570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the 580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In 590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any 600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the 610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual 620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and 630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may 640d84335fSJung-uk Kim * make. 650d84335fSJung-uk Kim * 660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any 670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the 680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance 690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the 700d84335fSJung-uk Kim * distribution. 710d84335fSJung-uk Kim * 720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original 730d84335fSJung-uk Kim * Intel Code. 740d84335fSJung-uk Kim * 750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by 760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or 770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code 780d84335fSJung-uk Kim * without prior written authorization from Intel. 790d84335fSJung-uk Kim * 800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance 810d84335fSJung-uk Kim * 820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 880d84335fSJung-uk Kim * PARTICULAR PURPOSE. 890d84335fSJung-uk Kim * 900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 970d84335fSJung-uk Kim * LIMITED REMEDY. 980d84335fSJung-uk Kim * 990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this 1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any 1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or 1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the 1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or 1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall 1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in 1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the 1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor 1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process, 1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the 1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license, 1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining 1120d84335fSJung-uk Kim * such license, approval or letter. 1130d84335fSJung-uk Kim * 1140d84335fSJung-uk Kim ***************************************************************************** 1150d84335fSJung-uk Kim * 1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 1170d84335fSJung-uk Kim * following license: 1180d84335fSJung-uk Kim * 119d244b227SJung-uk Kim * Redistribution and use in source and binary forms, with or without 120d244b227SJung-uk Kim * modification, are permitted provided that the following conditions 121d244b227SJung-uk Kim * are met: 122d244b227SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 123d244b227SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 124d244b227SJung-uk Kim * without modification. 125d244b227SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126d244b227SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 127d244b227SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 128d244b227SJung-uk Kim * including a substantially similar Disclaimer requirement for further 129d244b227SJung-uk Kim * binary redistribution. 130d244b227SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 131d244b227SJung-uk Kim * of any contributors may be used to endorse or promote products derived 132d244b227SJung-uk Kim * from this software without specific prior written permission. 133a88e22b7SJung-uk Kim * 1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1450d84335fSJung-uk Kim * 1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the 147d244b227SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 148d244b227SJung-uk Kim * Software Foundation. 149a88e22b7SJung-uk Kim * 1500d84335fSJung-uk Kim *****************************************************************************/ 151a88e22b7SJung-uk Kim 152a88e22b7SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h> 153a88e22b7SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h> 154a88e22b7SJung-uk Kim #include <contrib/dev/acpica/compiler/dttemplate.h> /* Contains the hex ACPI table templates */ 155a88e22b7SJung-uk Kim 156a88e22b7SJung-uk Kim #define _COMPONENT DT_COMPILER 157a88e22b7SJung-uk Kim ACPI_MODULE_NAME ("dttemplate") 158a88e22b7SJung-uk Kim 159a88e22b7SJung-uk Kim 160a88e22b7SJung-uk Kim /* Local prototypes */ 161a88e22b7SJung-uk Kim 162a88e22b7SJung-uk Kim static BOOLEAN 163a88e22b7SJung-uk Kim AcpiUtIsSpecialTable ( 164a88e22b7SJung-uk Kim char *Signature); 165a88e22b7SJung-uk Kim 166a88e22b7SJung-uk Kim static ACPI_STATUS 167f8146b88SJung-uk Kim DtCreateOneTemplateFile ( 168f8146b88SJung-uk Kim char *Signature, 169f8146b88SJung-uk Kim UINT32 TableCount); 170f8146b88SJung-uk Kim 171f8146b88SJung-uk Kim static ACPI_STATUS 172a88e22b7SJung-uk Kim DtCreateOneTemplate ( 173a88e22b7SJung-uk Kim char *Signature, 174f8146b88SJung-uk Kim UINT32 TableCount, 175a371a5fdSJung-uk Kim const ACPI_DMTABLE_DATA *TableData); 176a88e22b7SJung-uk Kim 177a88e22b7SJung-uk Kim static ACPI_STATUS 178a88e22b7SJung-uk Kim DtCreateAllTemplates ( 179a88e22b7SJung-uk Kim void); 180a88e22b7SJung-uk Kim 181f8146b88SJung-uk Kim static int 182f8146b88SJung-uk Kim DtEmitDefinitionBlock ( 183f8146b88SJung-uk Kim FILE *File, 184f8146b88SJung-uk Kim char *Filename, 185f8146b88SJung-uk Kim char *Signature, 186f8146b88SJung-uk Kim UINT32 Instance); 187f8146b88SJung-uk Kim 188a88e22b7SJung-uk Kim 189a88e22b7SJung-uk Kim /******************************************************************************* 190a88e22b7SJung-uk Kim * 191a88e22b7SJung-uk Kim * FUNCTION: AcpiUtIsSpecialTable 192a88e22b7SJung-uk Kim * 193a88e22b7SJung-uk Kim * PARAMETERS: Signature - ACPI table signature 194a88e22b7SJung-uk Kim * 195a88e22b7SJung-uk Kim * RETURN: TRUE if signature is a special ACPI table 196a88e22b7SJung-uk Kim * 197a88e22b7SJung-uk Kim * DESCRIPTION: Check for valid ACPI tables that are not in the main ACPI 198a88e22b7SJung-uk Kim * table data structure (AcpiDmTableData). 199a88e22b7SJung-uk Kim * 200a88e22b7SJung-uk Kim ******************************************************************************/ 201a88e22b7SJung-uk Kim 202a88e22b7SJung-uk Kim static BOOLEAN 203a88e22b7SJung-uk Kim AcpiUtIsSpecialTable ( 204a88e22b7SJung-uk Kim char *Signature) 205a88e22b7SJung-uk Kim { 206a88e22b7SJung-uk Kim 207278f0de6SJung-uk Kim if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_DSDT) || 208278f0de6SJung-uk Kim ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_OSDT) || 209278f0de6SJung-uk Kim ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_SSDT) || 210278f0de6SJung-uk Kim ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_FACS) || 211278f0de6SJung-uk Kim ACPI_COMPARE_NAMESEG (Signature, ACPI_RSDP_NAME)) 212a88e22b7SJung-uk Kim { 213a88e22b7SJung-uk Kim return (TRUE); 214a88e22b7SJung-uk Kim } 215a88e22b7SJung-uk Kim 216a88e22b7SJung-uk Kim return (FALSE); 217a88e22b7SJung-uk Kim } 218a88e22b7SJung-uk Kim 219a88e22b7SJung-uk Kim 220a88e22b7SJung-uk Kim /******************************************************************************* 221a88e22b7SJung-uk Kim * 222a88e22b7SJung-uk Kim * FUNCTION: DtCreateTemplates 223a88e22b7SJung-uk Kim * 224f8146b88SJung-uk Kim * PARAMETERS: argv - Standard command line arguments 225a88e22b7SJung-uk Kim * 226a88e22b7SJung-uk Kim * RETURN: Status 227a88e22b7SJung-uk Kim * 228a88e22b7SJung-uk Kim * DESCRIPTION: Create one or more template files. 229a88e22b7SJung-uk Kim * 230a88e22b7SJung-uk Kim ******************************************************************************/ 231a88e22b7SJung-uk Kim 232a88e22b7SJung-uk Kim ACPI_STATUS 233a88e22b7SJung-uk Kim DtCreateTemplates ( 234f8146b88SJung-uk Kim char **argv) 235a88e22b7SJung-uk Kim { 236f8146b88SJung-uk Kim char *Signature; 237f8146b88SJung-uk Kim char *End; 238f8146b88SJung-uk Kim unsigned long TableCount; 239f8146b88SJung-uk Kim ACPI_STATUS Status = AE_OK; 240a88e22b7SJung-uk Kim 241a88e22b7SJung-uk Kim 242a88e22b7SJung-uk Kim AslInitializeGlobals (); 243bf6fac21SJung-uk Kim 244f8146b88SJung-uk Kim Status = AdInitialize (); 245f8146b88SJung-uk Kim if (ACPI_FAILURE (Status)) 246bf6fac21SJung-uk Kim { 247f8146b88SJung-uk Kim return (Status); 248bf6fac21SJung-uk Kim } 249bf6fac21SJung-uk Kim 250f8146b88SJung-uk Kim /* 251f8146b88SJung-uk Kim * Special cases for DSDT, ALL, and '*' 252f8146b88SJung-uk Kim */ 253f8146b88SJung-uk Kim 254f8146b88SJung-uk Kim /* Default (no signature option) is DSDT */ 255f8146b88SJung-uk Kim 256f8146b88SJung-uk Kim if (AcpiGbl_Optind < 3) 257f8146b88SJung-uk Kim { 258385fb5d9SJung-uk Kim fprintf (stderr, "Creating default template: [DSDT]\n"); 259f8146b88SJung-uk Kim Status = DtCreateOneTemplateFile (ACPI_SIG_DSDT, 0); 260f8146b88SJung-uk Kim goto Exit; 261f8146b88SJung-uk Kim } 262f8146b88SJung-uk Kim 263f8146b88SJung-uk Kim AcpiGbl_Optind--; 264f8146b88SJung-uk Kim Signature = argv[AcpiGbl_Optind]; 265a88e22b7SJung-uk Kim AcpiUtStrupr (Signature); 266f8146b88SJung-uk Kim 267f8146b88SJung-uk Kim /* 268f8146b88SJung-uk Kim * Multiple SSDT support (-T <ssdt count>) 269f8146b88SJung-uk Kim */ 270f8146b88SJung-uk Kim TableCount = strtoul (Signature, &End, 0); 271f8146b88SJung-uk Kim if (Signature != End) 272f8146b88SJung-uk Kim { 273f8146b88SJung-uk Kim /* The count is used for table ID and method name - max is 254(+1) */ 274f8146b88SJung-uk Kim 275f8146b88SJung-uk Kim if (TableCount > 254) 276f8146b88SJung-uk Kim { 277f8146b88SJung-uk Kim fprintf (stderr, "%u SSDTs requested, maximum is 254\n", 278f8146b88SJung-uk Kim (unsigned int) TableCount); 279f8146b88SJung-uk Kim 280f8146b88SJung-uk Kim Status = AE_LIMIT; 281f8146b88SJung-uk Kim goto Exit; 282f8146b88SJung-uk Kim } 283f8146b88SJung-uk Kim 284f8146b88SJung-uk Kim Status = DtCreateOneTemplateFile (ACPI_SIG_DSDT, TableCount); 285f8146b88SJung-uk Kim goto Exit; 286f8146b88SJung-uk Kim } 287f8146b88SJung-uk Kim 288f8146b88SJung-uk Kim if (!strcmp (Signature, "ALL")) 289a88e22b7SJung-uk Kim { 290bf6fac21SJung-uk Kim /* Create all available/known templates */ 291bf6fac21SJung-uk Kim 292a88e22b7SJung-uk Kim Status = DtCreateAllTemplates (); 293f8146b88SJung-uk Kim goto Exit; 294f8146b88SJung-uk Kim } 295f8146b88SJung-uk Kim 296f8146b88SJung-uk Kim /* 297f8146b88SJung-uk Kim * Normal case: Create template for each signature 298f8146b88SJung-uk Kim */ 299f8146b88SJung-uk Kim while (argv[AcpiGbl_Optind]) 300f8146b88SJung-uk Kim { 301f8146b88SJung-uk Kim Signature = argv[AcpiGbl_Optind]; 302f8146b88SJung-uk Kim AcpiUtStrupr (Signature); 303f8146b88SJung-uk Kim 304f8146b88SJung-uk Kim Status = DtCreateOneTemplateFile (Signature, 0); 305f8146b88SJung-uk Kim if (ACPI_FAILURE (Status)) 306f8146b88SJung-uk Kim { 307f8146b88SJung-uk Kim goto Exit; 308f8146b88SJung-uk Kim } 309f8146b88SJung-uk Kim 310f8146b88SJung-uk Kim AcpiGbl_Optind++; 311f8146b88SJung-uk Kim } 312f8146b88SJung-uk Kim 313f8146b88SJung-uk Kim 314f8146b88SJung-uk Kim Exit: 315f8146b88SJung-uk Kim /* Shutdown ACPICA subsystem */ 316f8146b88SJung-uk Kim 317f8146b88SJung-uk Kim (void) AcpiTerminate (); 31867d9aa44SJung-uk Kim UtDeleteLocalCaches (); 319a88e22b7SJung-uk Kim return (Status); 320a88e22b7SJung-uk Kim } 321a88e22b7SJung-uk Kim 322f8146b88SJung-uk Kim 323f8146b88SJung-uk Kim /******************************************************************************* 324f8146b88SJung-uk Kim * 325f8146b88SJung-uk Kim * FUNCTION: DtCreateOneTemplateFile 326f8146b88SJung-uk Kim * 327f8146b88SJung-uk Kim * PARAMETERS: Signature - ACPI table signature 328f8146b88SJung-uk Kim * 329f8146b88SJung-uk Kim * RETURN: Status 330f8146b88SJung-uk Kim * 331f8146b88SJung-uk Kim * DESCRIPTION: Create one template file of the requested signature. 332f8146b88SJung-uk Kim * 333f8146b88SJung-uk Kim ******************************************************************************/ 334f8146b88SJung-uk Kim 335f8146b88SJung-uk Kim static ACPI_STATUS 336f8146b88SJung-uk Kim DtCreateOneTemplateFile ( 337f8146b88SJung-uk Kim char *Signature, 338f8146b88SJung-uk Kim UINT32 TableCount) 339f8146b88SJung-uk Kim { 340f8146b88SJung-uk Kim const ACPI_DMTABLE_DATA *TableData; 341f8146b88SJung-uk Kim ACPI_STATUS Status; 342f8146b88SJung-uk Kim 343f8146b88SJung-uk Kim 344a88e22b7SJung-uk Kim /* 345a88e22b7SJung-uk Kim * Validate signature and get the template data: 346a88e22b7SJung-uk Kim * 1) Signature must be 4 characters 347a88e22b7SJung-uk Kim * 2) Signature must be a recognized ACPI table 348a88e22b7SJung-uk Kim * 3) There must be a template associated with the signature 349a88e22b7SJung-uk Kim */ 350278f0de6SJung-uk Kim if (strlen (Signature) != ACPI_NAMESEG_SIZE) 351a88e22b7SJung-uk Kim { 352bf6fac21SJung-uk Kim fprintf (stderr, 353f8146b88SJung-uk Kim "%s: Invalid ACPI table signature " 354f8146b88SJung-uk Kim "(length must be 4 characters)\n", Signature); 355a88e22b7SJung-uk Kim return (AE_ERROR); 356a88e22b7SJung-uk Kim } 357a88e22b7SJung-uk Kim 358a88e22b7SJung-uk Kim /* 359a88e22b7SJung-uk Kim * Some slack for the two strange tables whose name is different than 360a88e22b7SJung-uk Kim * their signatures: MADT->APIC and FADT->FACP. 361a88e22b7SJung-uk Kim */ 362a88e22b7SJung-uk Kim if (!strcmp (Signature, "MADT")) 363a88e22b7SJung-uk Kim { 364a88e22b7SJung-uk Kim Signature = "APIC"; 365a88e22b7SJung-uk Kim } 366a88e22b7SJung-uk Kim else if (!strcmp (Signature, "FADT")) 367a88e22b7SJung-uk Kim { 368a88e22b7SJung-uk Kim Signature = "FACP"; 369a88e22b7SJung-uk Kim } 370a88e22b7SJung-uk Kim 371f8146b88SJung-uk Kim /* TableData will point to the template */ 372f8146b88SJung-uk Kim 373a88e22b7SJung-uk Kim TableData = AcpiDmGetTableData (Signature); 374a88e22b7SJung-uk Kim if (TableData) 375a88e22b7SJung-uk Kim { 376a88e22b7SJung-uk Kim if (!TableData->Template) 377a88e22b7SJung-uk Kim { 378bf6fac21SJung-uk Kim fprintf (stderr, "%4.4s: No template available\n", Signature); 379a88e22b7SJung-uk Kim return (AE_ERROR); 380a88e22b7SJung-uk Kim } 381a88e22b7SJung-uk Kim } 382a88e22b7SJung-uk Kim else if (!AcpiUtIsSpecialTable (Signature)) 383a88e22b7SJung-uk Kim { 384a88e22b7SJung-uk Kim fprintf (stderr, 385bf6fac21SJung-uk Kim "%4.4s: Unrecognized ACPI table signature\n", Signature); 386a88e22b7SJung-uk Kim return (AE_ERROR); 387a88e22b7SJung-uk Kim } 388a88e22b7SJung-uk Kim 389f8146b88SJung-uk Kim Status = DtCreateOneTemplate (Signature, TableCount, TableData); 390a88e22b7SJung-uk Kim return (Status); 391a88e22b7SJung-uk Kim } 392a88e22b7SJung-uk Kim 393a88e22b7SJung-uk Kim 394a88e22b7SJung-uk Kim /******************************************************************************* 395a88e22b7SJung-uk Kim * 396a88e22b7SJung-uk Kim * FUNCTION: DtCreateAllTemplates 397a88e22b7SJung-uk Kim * 398a88e22b7SJung-uk Kim * PARAMETERS: None 399a88e22b7SJung-uk Kim * 400a88e22b7SJung-uk Kim * RETURN: Status 401a88e22b7SJung-uk Kim * 402a88e22b7SJung-uk Kim * DESCRIPTION: Create all currently defined template files 403a88e22b7SJung-uk Kim * 404a88e22b7SJung-uk Kim ******************************************************************************/ 405a88e22b7SJung-uk Kim 406a88e22b7SJung-uk Kim static ACPI_STATUS 407a88e22b7SJung-uk Kim DtCreateAllTemplates ( 408a88e22b7SJung-uk Kim void) 409a88e22b7SJung-uk Kim { 410a371a5fdSJung-uk Kim const ACPI_DMTABLE_DATA *TableData; 411a88e22b7SJung-uk Kim ACPI_STATUS Status; 412a88e22b7SJung-uk Kim 413a88e22b7SJung-uk Kim 414a88e22b7SJung-uk Kim fprintf (stderr, "Creating all supported Template files\n"); 415a88e22b7SJung-uk Kim 416a88e22b7SJung-uk Kim /* Walk entire ACPI table data structure */ 417a88e22b7SJung-uk Kim 418a88e22b7SJung-uk Kim for (TableData = AcpiDmTableData; TableData->Signature; TableData++) 419a88e22b7SJung-uk Kim { 420a88e22b7SJung-uk Kim /* If table has a template, create the template file */ 421a88e22b7SJung-uk Kim 422a88e22b7SJung-uk Kim if (TableData->Template) 423a88e22b7SJung-uk Kim { 424a88e22b7SJung-uk Kim Status = DtCreateOneTemplate (TableData->Signature, 425f8146b88SJung-uk Kim 0, TableData); 426a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status)) 427a88e22b7SJung-uk Kim { 428a88e22b7SJung-uk Kim return (Status); 429a88e22b7SJung-uk Kim } 430a88e22b7SJung-uk Kim } 431a88e22b7SJung-uk Kim } 432a88e22b7SJung-uk Kim 433a88e22b7SJung-uk Kim /* 434f38b0f21SJung-uk Kim * Create the special ACPI tables: 435a88e22b7SJung-uk Kim * 1) DSDT/SSDT are AML tables, not data tables 436a88e22b7SJung-uk Kim * 2) FACS and RSDP have non-standard headers 437a88e22b7SJung-uk Kim */ 438f8146b88SJung-uk Kim Status = DtCreateOneTemplate (ACPI_SIG_DSDT, 0, NULL); 439a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status)) 440a88e22b7SJung-uk Kim { 441a88e22b7SJung-uk Kim return (Status); 442a88e22b7SJung-uk Kim } 443a88e22b7SJung-uk Kim 444f8146b88SJung-uk Kim Status = DtCreateOneTemplate (ACPI_SIG_SSDT, 0, NULL); 445a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status)) 446a88e22b7SJung-uk Kim { 447a88e22b7SJung-uk Kim return (Status); 448a88e22b7SJung-uk Kim } 449a88e22b7SJung-uk Kim 450f8146b88SJung-uk Kim Status = DtCreateOneTemplate (ACPI_SIG_OSDT, 0, NULL); 451a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status)) 452a88e22b7SJung-uk Kim { 453a88e22b7SJung-uk Kim return (Status); 454a88e22b7SJung-uk Kim } 455a88e22b7SJung-uk Kim 456f8146b88SJung-uk Kim Status = DtCreateOneTemplate (ACPI_SIG_FACS, 0, NULL); 457f8146b88SJung-uk Kim if (ACPI_FAILURE (Status)) 458f8146b88SJung-uk Kim { 459f8146b88SJung-uk Kim return (Status); 460f8146b88SJung-uk Kim } 461f8146b88SJung-uk Kim 462f8146b88SJung-uk Kim Status = DtCreateOneTemplate (ACPI_RSDP_NAME, 0, NULL); 463a88e22b7SJung-uk Kim if (ACPI_FAILURE (Status)) 464a88e22b7SJung-uk Kim { 465a88e22b7SJung-uk Kim return (Status); 466a88e22b7SJung-uk Kim } 467a88e22b7SJung-uk Kim 468a88e22b7SJung-uk Kim return (AE_OK); 469a88e22b7SJung-uk Kim } 470a88e22b7SJung-uk Kim 471a88e22b7SJung-uk Kim 472a88e22b7SJung-uk Kim /******************************************************************************* 473a88e22b7SJung-uk Kim * 474a88e22b7SJung-uk Kim * FUNCTION: DtCreateOneTemplate 475a88e22b7SJung-uk Kim * 476a88e22b7SJung-uk Kim * PARAMETERS: Signature - ACPI signature, NULL terminated. 477f8146b88SJung-uk Kim * TableCount - Used for SSDTs in same file as DSDT 478a88e22b7SJung-uk Kim * TableData - Entry in ACPI table data structure. 479a88e22b7SJung-uk Kim * NULL if a special ACPI table. 480a88e22b7SJung-uk Kim * 481a88e22b7SJung-uk Kim * RETURN: Status 482a88e22b7SJung-uk Kim * 483a88e22b7SJung-uk Kim * DESCRIPTION: Create one template source file for the requested ACPI table. 484a88e22b7SJung-uk Kim * 485a88e22b7SJung-uk Kim ******************************************************************************/ 486a88e22b7SJung-uk Kim 487a88e22b7SJung-uk Kim static ACPI_STATUS 488a88e22b7SJung-uk Kim DtCreateOneTemplate ( 489a88e22b7SJung-uk Kim char *Signature, 490f8146b88SJung-uk Kim UINT32 TableCount, 491a371a5fdSJung-uk Kim const ACPI_DMTABLE_DATA *TableData) 492a88e22b7SJung-uk Kim { 493a88e22b7SJung-uk Kim char *DisasmFilename; 494a88e22b7SJung-uk Kim FILE *File; 495a88e22b7SJung-uk Kim ACPI_STATUS Status = AE_OK; 496f8146b88SJung-uk Kim int Actual; 497f8146b88SJung-uk Kim UINT32 i; 498a88e22b7SJung-uk Kim 499a88e22b7SJung-uk Kim 500a88e22b7SJung-uk Kim /* New file will have a .asl suffix */ 501a88e22b7SJung-uk Kim 502a88e22b7SJung-uk Kim DisasmFilename = FlGenerateFilename ( 503a88e22b7SJung-uk Kim Signature, FILE_SUFFIX_ASL_CODE); 504a88e22b7SJung-uk Kim if (!DisasmFilename) 505a88e22b7SJung-uk Kim { 506a88e22b7SJung-uk Kim fprintf (stderr, "Could not generate output filename\n"); 507a88e22b7SJung-uk Kim return (AE_ERROR); 508a88e22b7SJung-uk Kim } 509a88e22b7SJung-uk Kim 510a88e22b7SJung-uk Kim AcpiUtStrlwr (DisasmFilename); 511f8146b88SJung-uk Kim if (!UtQueryForOverwrite (DisasmFilename)) 512f8146b88SJung-uk Kim { 513a009b7dcSJung-uk Kim return (AE_OK); 514f8146b88SJung-uk Kim } 515f8146b88SJung-uk Kim 516a88e22b7SJung-uk Kim File = fopen (DisasmFilename, "w+"); 517a88e22b7SJung-uk Kim if (!File) 518a88e22b7SJung-uk Kim { 519f8146b88SJung-uk Kim fprintf (stderr, "Could not open output file %s\n", 520f8146b88SJung-uk Kim DisasmFilename); 521a88e22b7SJung-uk Kim return (AE_ERROR); 522a88e22b7SJung-uk Kim } 523a88e22b7SJung-uk Kim 524a88e22b7SJung-uk Kim /* Emit the common file header */ 525a88e22b7SJung-uk Kim 526a88e22b7SJung-uk Kim AcpiOsRedirectOutput (File); 527a88e22b7SJung-uk Kim 5283c1812acSJung-uk Kim AcpiOsPrintf ("/*\n"); 5293c1812acSJung-uk Kim AcpiOsPrintf (ACPI_COMMON_HEADER ("iASL Compiler/Disassembler", " * ")); 5303c1812acSJung-uk Kim 531f8146b88SJung-uk Kim if (TableCount == 0) 532f8146b88SJung-uk Kim { 5335ef50723SJung-uk Kim AcpiOsPrintf (" * Template for [%4.4s] ACPI Table", 534a88e22b7SJung-uk Kim Signature); 535f8146b88SJung-uk Kim } 536f8146b88SJung-uk Kim else 537f8146b88SJung-uk Kim { 538f8146b88SJung-uk Kim AcpiOsPrintf (" * Template for [%4.4s] and %u [SSDT] ACPI Tables", 539f8146b88SJung-uk Kim Signature, TableCount); 540f8146b88SJung-uk Kim } 541a88e22b7SJung-uk Kim 542a88e22b7SJung-uk Kim /* Dump the actual ACPI table */ 543a88e22b7SJung-uk Kim 544a88e22b7SJung-uk Kim if (TableData) 545a88e22b7SJung-uk Kim { 546a88e22b7SJung-uk Kim /* Normal case, tables that appear in AcpiDmTableData */ 547a88e22b7SJung-uk Kim 5485ef50723SJung-uk Kim AcpiOsPrintf (" (static data table)\n"); 5495ef50723SJung-uk Kim 5506f1f1a63SJung-uk Kim if (AslGbl_VerboseTemplates) 551a88e22b7SJung-uk Kim { 552a88e22b7SJung-uk Kim AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]" 553a88e22b7SJung-uk Kim " FieldName : HexFieldValue\n */\n\n"); 554a88e22b7SJung-uk Kim } 555a88e22b7SJung-uk Kim else 556a88e22b7SJung-uk Kim { 557a88e22b7SJung-uk Kim AcpiOsPrintf (" * Format: [ByteLength]" 5585ef50723SJung-uk Kim " FieldName : HexFieldValue\n */\n"); 559a88e22b7SJung-uk Kim } 560a88e22b7SJung-uk Kim 561a88e22b7SJung-uk Kim AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, 562a88e22b7SJung-uk Kim TableData->Template)); 563a88e22b7SJung-uk Kim } 564a88e22b7SJung-uk Kim else 565a88e22b7SJung-uk Kim { 566f8146b88SJung-uk Kim /* Special ACPI tables - DSDT, SSDT, OSDT, FACS, RSDP */ 567a88e22b7SJung-uk Kim 5685ef50723SJung-uk Kim AcpiOsPrintf (" (AML byte code table)\n"); 5695ef50723SJung-uk Kim AcpiOsPrintf (" */\n"); 570f8146b88SJung-uk Kim 571278f0de6SJung-uk Kim if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_DSDT)) 572a88e22b7SJung-uk Kim { 573f8146b88SJung-uk Kim Actual = DtEmitDefinitionBlock ( 574f8146b88SJung-uk Kim File, DisasmFilename, ACPI_SIG_DSDT, 1); 575f8146b88SJung-uk Kim if (Actual < 0) 576ed17e06eSJung-uk Kim { 577f8146b88SJung-uk Kim Status = AE_ERROR; 578f8146b88SJung-uk Kim goto Cleanup; 579f8146b88SJung-uk Kim } 580f8146b88SJung-uk Kim 581f8146b88SJung-uk Kim /* Emit any requested SSDTs into the same file */ 582f8146b88SJung-uk Kim 583f8146b88SJung-uk Kim for (i = 1; i <= TableCount; i++) 584f8146b88SJung-uk Kim { 585f8146b88SJung-uk Kim Actual = DtEmitDefinitionBlock ( 586f8146b88SJung-uk Kim File, DisasmFilename, ACPI_SIG_SSDT, i + 1); 587f8146b88SJung-uk Kim if (Actual < 0) 588f8146b88SJung-uk Kim { 589ed17e06eSJung-uk Kim Status = AE_ERROR; 590ed17e06eSJung-uk Kim goto Cleanup; 591ed17e06eSJung-uk Kim } 592a88e22b7SJung-uk Kim } 593f8146b88SJung-uk Kim } 594278f0de6SJung-uk Kim else if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_SSDT)) 595a88e22b7SJung-uk Kim { 596f8146b88SJung-uk Kim Actual = DtEmitDefinitionBlock ( 597f8146b88SJung-uk Kim File, DisasmFilename, ACPI_SIG_SSDT, 1); 598f8146b88SJung-uk Kim if (Actual < 0) 599ed17e06eSJung-uk Kim { 600ed17e06eSJung-uk Kim Status = AE_ERROR; 601ed17e06eSJung-uk Kim goto Cleanup; 602a88e22b7SJung-uk Kim } 603ed17e06eSJung-uk Kim } 604278f0de6SJung-uk Kim else if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_OSDT)) 6055ef50723SJung-uk Kim { 606f8146b88SJung-uk Kim Actual = DtEmitDefinitionBlock ( 607f8146b88SJung-uk Kim File, DisasmFilename, ACPI_SIG_OSDT, 1); 608f8146b88SJung-uk Kim if (Actual < 0) 6095ef50723SJung-uk Kim { 6105ef50723SJung-uk Kim Status = AE_ERROR; 6115ef50723SJung-uk Kim goto Cleanup; 6125ef50723SJung-uk Kim } 6135ef50723SJung-uk Kim } 614278f0de6SJung-uk Kim else if (ACPI_COMPARE_NAMESEG (Signature, ACPI_SIG_FACS)) 615a88e22b7SJung-uk Kim { 616a88e22b7SJung-uk Kim AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, 617a88e22b7SJung-uk Kim TemplateFacs)); 618a88e22b7SJung-uk Kim } 619278f0de6SJung-uk Kim else if (ACPI_COMPARE_NAMESEG (Signature, ACPI_RSDP_NAME)) 620a88e22b7SJung-uk Kim { 621a88e22b7SJung-uk Kim AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, 622a88e22b7SJung-uk Kim TemplateRsdp)); 623a88e22b7SJung-uk Kim } 624a88e22b7SJung-uk Kim else 625a88e22b7SJung-uk Kim { 626a88e22b7SJung-uk Kim fprintf (stderr, 627a88e22b7SJung-uk Kim "%4.4s, Unrecognized ACPI table signature\n", Signature); 628ed17e06eSJung-uk Kim Status = AE_ERROR; 629ed17e06eSJung-uk Kim goto Cleanup; 630a88e22b7SJung-uk Kim } 631a88e22b7SJung-uk Kim } 632a88e22b7SJung-uk Kim 633f8146b88SJung-uk Kim if (TableCount == 0) 634f8146b88SJung-uk Kim { 635a88e22b7SJung-uk Kim fprintf (stderr, 636f8146b88SJung-uk Kim "Created ACPI table template for [%4.4s], " 637f8146b88SJung-uk Kim "written to \"%s\"\n", 638a88e22b7SJung-uk Kim Signature, DisasmFilename); 639f8146b88SJung-uk Kim } 640f8146b88SJung-uk Kim else 641f8146b88SJung-uk Kim { 642f8146b88SJung-uk Kim fprintf (stderr, 643f8146b88SJung-uk Kim "Created ACPI table templates for [%4.4s] " 644385fb5d9SJung-uk Kim "and %u [SSDT] in same file, written to \"%s\"\n", 645f8146b88SJung-uk Kim Signature, TableCount, DisasmFilename); 646f8146b88SJung-uk Kim } 647a88e22b7SJung-uk Kim 648ed17e06eSJung-uk Kim Cleanup: 649a88e22b7SJung-uk Kim fclose (File); 650a88e22b7SJung-uk Kim AcpiOsRedirectOutput (stdout); 651a88e22b7SJung-uk Kim return (Status); 652a88e22b7SJung-uk Kim } 653f8146b88SJung-uk Kim 654f8146b88SJung-uk Kim 655f8146b88SJung-uk Kim /******************************************************************************* 656f8146b88SJung-uk Kim * 657f8146b88SJung-uk Kim * FUNCTION: DtEmitDefinitionBlock 658f8146b88SJung-uk Kim * 659f8146b88SJung-uk Kim * PARAMETERS: File - An open file for the block 660f8146b88SJung-uk Kim * Filename - Filename for same, for error msg(s) 661f8146b88SJung-uk Kim * Signature - ACPI signature for the block 662f8146b88SJung-uk Kim * Instance - Used for multiple SSDTs in the same file 663f8146b88SJung-uk Kim * 664f8146b88SJung-uk Kim * RETURN: Status from fprintf 665f8146b88SJung-uk Kim * 666f8146b88SJung-uk Kim * DESCRIPTION: Emit the raw ASL for a complete Definition Block (DSDT or SSDT) 667f8146b88SJung-uk Kim * 668f8146b88SJung-uk Kim * Note: The AMLFileName parameter for DefinitionBlock is left as a NULL 669f8146b88SJung-uk Kim * string. This allows the compiler to create the output AML filename from 670f8146b88SJung-uk Kim * the input filename. 671f8146b88SJung-uk Kim * 672f8146b88SJung-uk Kim ******************************************************************************/ 673f8146b88SJung-uk Kim 674f8146b88SJung-uk Kim static int 675f8146b88SJung-uk Kim DtEmitDefinitionBlock ( 676f8146b88SJung-uk Kim FILE *File, 677f8146b88SJung-uk Kim char *Filename, 678f8146b88SJung-uk Kim char *Signature, 679f8146b88SJung-uk Kim UINT32 Instance) 680f8146b88SJung-uk Kim { 681f8146b88SJung-uk Kim int Status; 682f8146b88SJung-uk Kim 683f8146b88SJung-uk Kim 684f8146b88SJung-uk Kim Status = fprintf (File, 685f8146b88SJung-uk Kim "DefinitionBlock (\"\", \"%4.4s\", 2, \"Intel\", \"_%4.4s_%.2X\", 0x00000001)\n" 686f8146b88SJung-uk Kim "{\n" 687f8146b88SJung-uk Kim " Method (%2.2s%.2X)\n" 688f8146b88SJung-uk Kim " {\n" 689f8146b88SJung-uk Kim " }\n" 690f8146b88SJung-uk Kim "}\n\n", 691f8146b88SJung-uk Kim Signature, Signature, Instance, Signature, Instance); 692f8146b88SJung-uk Kim 693f8146b88SJung-uk Kim if (Status < 0) 694f8146b88SJung-uk Kim { 695f8146b88SJung-uk Kim fprintf (stderr, 696f8146b88SJung-uk Kim "Could not write %4.4s to output file %s\n", 697f8146b88SJung-uk Kim Signature, Filename); 698f8146b88SJung-uk Kim } 699f8146b88SJung-uk Kim 700f8146b88SJung-uk Kim return (Status); 701f8146b88SJung-uk Kim } 702