diff options
author | Jung-uk Kim <jkim@FreeBSD.org> | 2012-02-16 00:24:10 +0000 |
---|---|---|
committer | Jung-uk Kim <jkim@FreeBSD.org> | 2012-02-16 00:24:10 +0000 |
commit | 5437485bdb98c4b00f15969e013c454426e9c862 (patch) | |
tree | 71526afe7e3c45a4c88ba7b5d8d57d1e469feec2 /source/tools | |
parent | 234358d94982312d34c80b868fea481307fb3a48 (diff) | |
download | src-5437485bdb98c4b00f15969e013c454426e9c862.tar.gz src-5437485bdb98c4b00f15969e013c454426e9c862.zip |
Import ACPICA 20120215.vendor/acpica/20120215
Notes
Notes:
svn path=/vendor-sys/acpica/dist/; revision=231798
svn path=/vendor-sys/acpica/20120215/; revision=231799; tag=vendor/acpica/20120215
Diffstat (limited to 'source/tools')
37 files changed, 16063 insertions, 0 deletions
diff --git a/source/tools/acpibin/Makefile b/source/tools/acpibin/Makefile new file mode 100644 index 000000000000..f15141bb2d78 --- /dev/null +++ b/source/tools/acpibin/Makefile @@ -0,0 +1,129 @@ +# +# acpibin - Binary ACPI table utility +# +# NOTE: This makefile is intended to be used within the native +# ACPICA source tree. +# + +# +# Configuration +# Notes: +# gcc should be version 4 or greater, otherwise some of the options +# used will not be recognized. +# Global optimization flags (such as -O2, -Os) are not used, since +# they cause issues on some compilers. +# The _GNU_SOURCE symbol is required for many hosts. +# +PROG = acpibin + +HOST = _LINUX +NOMAN = YES +COMPILE = $(CC) -c $(CFLAGS) $(CWARNINGFLAGS) -o$@ $< + +ACPICA_SRC = ../../../source +ACPICA_COMMON = $(ACPICA_SRC)/common +ACPICA_TOOLS = $(ACPICA_SRC)/tools +ACPICA_OSL = $(ACPICA_SRC)/os_specific/service_layers +ACPICA_CORE = $(ACPICA_SRC)/components +ACPICA_INCLUDE = $(ACPICA_SRC)/include +ACPICA_DEBUGGER = $(ACPICA_CORE)/debugger +ACPICA_DISASSEMBLER = $(ACPICA_CORE)/disassembler +ACPICA_DISPATCHER = $(ACPICA_CORE)/dispatcher +ACPICA_EVENTS = $(ACPICA_CORE)/events +ACPICA_EXECUTER = $(ACPICA_CORE)/executer +ACPICA_HARDWARE = $(ACPICA_CORE)/hardware +ACPICA_NAMESPACE = $(ACPICA_CORE)/namespace +ACPICA_PARSER = $(ACPICA_CORE)/parser +ACPICA_RESOURCES = $(ACPICA_CORE)/resources +ACPICA_TABLES = $(ACPICA_CORE)/tables +ACPICA_UTILITIES = $(ACPICA_CORE)/utilities +ACPIBIN = $(ACPICA_TOOLS)/acpibin +INSTALLDIR = /usr/bin +INSTALLPROG = cp --remove-destination $(PROG) $(INSTALLDIR) + +ACPICA_HEADERS = \ + $(wildcard $(ACPICA_INCLUDE)/*.h) \ + $(wildcard $(ACPICA_INCLUDE)/platform/*.h) + +# +# Search paths for source files +# +vpath %.c \ + $(ACPIBIN) \ + $(ACPICA_UTILITIES) \ + $(ACPICA_COMMON) \ + $(ACPICA_OSL) + +HEADERS = \ + $(wildcard $(ACPIBIN)/*.h) + +OBJECTS = \ + abcompare.o \ + abmain.o \ + utalloc.o \ + utcache.o \ + utdebug.o \ + utdecode.o \ + utglobal.o \ + utlock.o \ + utmath.o \ + utmisc.o \ + utmutex.o \ + utstate.o \ + utxferror.o \ + osunixxf.o \ + getopt.o + +CFLAGS+= \ + -D$(HOST) \ + -D_GNU_SOURCE \ + -DACPI_BIN_APP \ + -I$(ACPICA_INCLUDE) + +CWARNINGFLAGS = \ + -ansi \ + -Wall \ + -Wbad-function-cast \ + -Wdeclaration-after-statement \ + -Werror \ + -Wformat=2 \ + -Wmissing-declarations \ + -Wmissing-prototypes \ + -Wstrict-aliasing=0 \ + -Wstrict-prototypes \ + -Wswitch-default \ + -Wpointer-arith \ + -Wundef + +# +# gcc 4+ flags +# +CWARNINGFLAGS += \ + -Waddress \ + -Waggregate-return \ + -Wchar-subscripts \ + -Wempty-body \ + -Wlogical-op \ + -Wmissing-declarations \ + -Wmissing-field-initializers \ + -Wmissing-parameter-type \ + -Wnested-externs \ + -Wold-style-declaration \ + -Wold-style-definition \ + -Wredundant-decls \ + -Wtype-limits + +# +# Rules +# +$(PROG) : $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) -o $(PROG) + +%.o : %.c $(HEADERS) $(ACPICA_HEADERS) + $(COMPILE) + +clean : + rm -f $(PROG) $(PROG).exe $(OBJECTS) + +install : + $(INSTALLPROG) diff --git a/source/tools/acpibin/abcompare.c b/source/tools/acpibin/abcompare.c new file mode 100644 index 000000000000..46122274d4a9 --- /dev/null +++ b/source/tools/acpibin/abcompare.c @@ -0,0 +1,767 @@ + +/****************************************************************************** + * + * Module Name: abcompare - compare AML files + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpibin.h" + + +FILE *File1; +FILE *File2; +ACPI_TABLE_HEADER Header1; +ACPI_TABLE_HEADER Header2; +struct stat Gbl_StatBuf; + +#define BUFFER_SIZE 256 +char Buffer[BUFFER_SIZE]; + + +/* Local prototypes */ + +static BOOLEAN +AbValidateHeader ( + ACPI_TABLE_HEADER *Header); + +static UINT8 +AcpiTbSumTable ( + void *Buffer, + UINT32 Length); + +static char * +AbGetFile ( + char *Filename, + UINT32 *FileSize); + +static void +AbPrintHeaderInfo ( + ACPI_TABLE_HEADER *Header); + +ACPI_PHYSICAL_ADDRESS +AeLocalGetRootPointer ( + void); + + +/******************************************************************************* + * + * FUNCTION: UtHexCharToValue + * + * PARAMETERS: HexChar - Hex character in Ascii + * + * RETURN: The binary value of the hex character + * + * DESCRIPTION: Perform ascii-to-hex translation + * + ******************************************************************************/ + +static UINT8 +UtHexCharToValue ( + int HexChar, + UINT8 *OutBinary) +{ + + if (HexChar >= 0x30 && HexChar <= 0x39) + { + *OutBinary = (UINT8) (HexChar - 0x30); + return (1); + } + + else if (HexChar >= 0x41 && HexChar <= 0x46) + { + *OutBinary = (UINT8) (HexChar - 0x37); + return (1); + } + + else if (HexChar >= 0x61 && HexChar <= 0x66) + { + *OutBinary = (UINT8) (HexChar - 0x57); + return (1); + } + return (0); +} + +static UINT8 +AbHexByteToBinary ( + char *HexString, + char *OutBinary) +{ + UINT8 Local1; + UINT8 Local2; + + + if (!UtHexCharToValue (HexString[0], &Local1)) + { + return (0); + } + if (!UtHexCharToValue (HexString[1], &Local2)) + { + return (0); + } + + *OutBinary = (UINT8) ((Local1 << 4) | Local2); + return (2); + +} + + +/****************************************************************************** + * + * FUNCTION: AbValidateHeader + * + * DESCRIPTION: Check for valid ACPI table header + * + ******************************************************************************/ + +static BOOLEAN +AbValidateHeader ( + ACPI_TABLE_HEADER *Header) +{ + + if (!AcpiUtValidAcpiName (* (UINT32 *) &Header->Signature)) + { + printf ("Header signature is invalid\n"); + return FALSE; + } + + return TRUE; +} + + +/******************************************************************************* + * + * FUNCTION: AcpiTbSumTable + * + * PARAMETERS: Buffer - Buffer to checksum + * Length - Size of the buffer + * + * RETURNS 8 bit checksum of buffer + * + * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it. + * + ******************************************************************************/ + +static UINT8 +AcpiTbSumTable ( + void *Buffer, + UINT32 Length) +{ + const UINT8 *limit; + const UINT8 *rover; + UINT8 sum = 0; + + + if (Buffer && Length) + { + /* Buffer and Length are valid */ + + limit = (UINT8 *) Buffer + Length; + + for (rover = Buffer; rover < limit; rover++) + { + sum = (UINT8) (sum + *rover); + } + } + return (sum); +} + + +/******************************************************************************* + * + * FUNCTION: AbPrintHeaderInfo + * + * PARAMETERS: Header - An ACPI table header + * + * RETURNS None. + * + * DESCRIPTION: Format and display header contents. + * + ******************************************************************************/ + +static void +AbPrintHeaderInfo ( + ACPI_TABLE_HEADER *Header) +{ + + /* Display header information */ + + printf ("Signature : %4.4s\n", Header->Signature); + printf ("Length : %8.8X\n", Header->Length); + printf ("Revision : %2.2X\n", Header->Revision); + printf ("Checksum : %2.2X\n", Header->Checksum); + printf ("OEM ID : %6.6s\n", Header->OemId); + printf ("OEM Table ID : %8.8s\n", Header->OemTableId); + printf ("OEM Revision : %8.8X\n", Header->OemRevision); + printf ("ASL Compiler ID : %4.4s\n", Header->AslCompilerId); + printf ("Compiler Revision : %8.8X\n", Header->AslCompilerRevision); + printf ("\n"); +} + + +/****************************************************************************** + * + * FUNCTION: AbDisplayHeader + * + * DESCRIPTION: Display an ACPI table header + * + ******************************************************************************/ + +void +AbDisplayHeader ( + char *File1Path) +{ + UINT32 Actual1; + + + File1 = fopen (File1Path, "rb"); + if (!File1) + { + printf ("Could not open file %s\n", File1Path); + return; + } + + Actual1 = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1); + if (Actual1 < sizeof (ACPI_TABLE_HEADER)) + { + printf ("File %s does not contain an ACPI table header\n", File1Path); + return; + } + + if (!AbValidateHeader (&Header1)) + { + return; + } + + AbPrintHeaderInfo (&Header1); +} + + +/****************************************************************************** + * + * FUNCTION: AbComputeChecksum + * + * DESCRIPTION: Compute proper checksum for an ACPI table + * + ******************************************************************************/ + +void +AbComputeChecksum ( + char *File1Path) +{ + UINT32 Actual1; + ACPI_TABLE_HEADER *Table; + UINT8 Checksum; + + + File1 = fopen (File1Path, "rb"); + if (!File1) + { + printf ("Could not open file %s\n", File1Path); + return; + } + + Actual1 = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1); + if (Actual1 < sizeof (ACPI_TABLE_HEADER)) + { + printf ("File %s does not contain an ACPI table header\n", File1Path); + return; + } + + if (!AbValidateHeader (&Header1)) + { + return; + } + + if (!Gbl_TerseMode) + { + AbPrintHeaderInfo (&Header1); + } + + /* Allocate a buffer to hold the entire table */ + + Table = AcpiOsAllocate (Header1.Length); + if (!Table) + { + printf ("could not allocate\n"); + return; + } + + /* Read the entire table, including header */ + + fseek (File1, 0, SEEK_SET); + Actual1 = fread (Table, 1, Header1.Length, File1); + if (Actual1 < Header1.Length) + { + printf ("could not read table\n"); + return; + } + + /* Compute the checksum for the table */ + + Table->Checksum = 0; + + Checksum = (UINT8) (0 - AcpiTbSumTable (Table, Table->Length)); + printf ("Computed checksum: 0x%X\n\n", Checksum); + + if (Header1.Checksum == Checksum) + { + printf ("Checksum ok in AML file, not updating\n"); + return; + } + + /* Open the target file for writing, to update checksum */ + + fclose (File1); + File1 = fopen (File1Path, "r+b"); + if (!File1) + { + printf ("Could not open file %s for writing\n", File1Path); + return; + } + + /* Set the checksum, write the new header */ + + Header1.Checksum = Checksum; + + Actual1 = fwrite (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1); + if (Actual1 < sizeof (ACPI_TABLE_HEADER)) + { + printf ("Could not write updated table header\n"); + return; + } + + printf ("Wrote new checksum\n"); + return; +} + + +/****************************************************************************** + * + * FUNCTION: AbCompareAmlFiles + * + * DESCRIPTION: Compare two AML files + * + ******************************************************************************/ + +int +AbCompareAmlFiles ( + char *File1Path, + char *File2Path) +{ + UINT32 Actual1; + UINT32 Actual2; + UINT32 Offset; + UINT8 Char1; + UINT8 Char2; + UINT8 Mismatches = 0; + BOOLEAN HeaderMismatch = FALSE; + + + File1 = fopen (File1Path, "rb"); + if (!File1) + { + printf ("Could not open file %s\n", File1Path); + return -1; + } + + File2 = fopen (File2Path, "rb"); + if (!File2) + { + printf ("Could not open file %s\n", File2Path); + return -1; + } + + /* Read the ACPI header from each file */ + + Actual1 = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1); + if (Actual1 < sizeof (ACPI_TABLE_HEADER)) + { + printf ("File %s does not contain an ACPI table header\n", File1Path); + return -1; + } + + Actual2 = fread (&Header2, 1, sizeof (ACPI_TABLE_HEADER), File2); + if (Actual2 < sizeof (ACPI_TABLE_HEADER)) + { + printf ("File %s does not contain an ACPI table header\n", File2Path); + return -1; + } + + if ((!AbValidateHeader (&Header1)) || + (!AbValidateHeader (&Header2))) + { + return -1; + } + + /* Table signatures must match */ + + if (*((UINT32 *) Header1.Signature) != *((UINT32 *) Header2.Signature)) + { + printf ("Table signatures do not match\n"); + return -1; + } + + if (!Gbl_TerseMode) + { + /* Display header information */ + + AbPrintHeaderInfo (&Header1); + AbPrintHeaderInfo (&Header2); + } + + if (memcmp (Header1.Signature, Header2.Signature, sizeof (ACPI_TABLE_HEADER))) + { + printf ("Headers do not match exactly\n"); + HeaderMismatch = TRUE; + } + + /* Do the byte-by-byte compare */ + + Actual1 = fread (&Char1, 1, 1, File1); + Actual2 = fread (&Char2, 1, 1, File2); + Offset = sizeof (ACPI_TABLE_HEADER); + + while (Actual1 && Actual2) + { + if (Char1 != Char2) + { + printf ("Error - Byte mismatch at offset %8.8X: 0x%2.2X 0x%2.2X\n", + Offset, Char1, Char2); + Mismatches++; + if (Mismatches > 100) + { + printf ("100 Mismatches: Too many mismatches\n"); + return -1; + } + } + + Offset++; + Actual1 = fread (&Char1, 1, 1, File1); + Actual2 = fread (&Char2, 1, 1, File2); + } + + if (Actual1) + { + printf ("Error - file %s is longer than file %s\n", File1Path, File2Path); + Mismatches++; + } + else if (Actual2) + { + printf ("Error - file %s is shorter than file %s\n", File1Path, File2Path); + Mismatches++; + } + else if (!Mismatches) + { + if (HeaderMismatch) + { + printf ("Files compare exactly after header\n"); + } + else + { + printf ("Files compare exactly\n"); + } + } + + printf ("%u Mismatches found\n", Mismatches); + return 0; +} + + +/****************************************************************************** + * + * FUNCTION: AsGetFile + * + * DESCRIPTION: Open a file and read it entirely into a new buffer + * + ******************************************************************************/ + +static char * +AbGetFile ( + char *Filename, + UINT32 *FileSize) +{ + int FileHandle; + UINT32 Size; + char *Buffer = NULL; + + + /* Binary mode does not alter CR/LF pairs */ + + FileHandle = open (Filename, O_BINARY | O_RDONLY); + if (!FileHandle) + { + printf ("Could not open %s\n", Filename); + return NULL; + } + + /* Need file size to allocate a buffer */ + + if (fstat (FileHandle, &Gbl_StatBuf)) + { + printf ("Could not get file status for %s\n", Filename); + goto ErrorExit; + } + + /* Allocate a buffer for the entire file */ + + Size = Gbl_StatBuf.st_size; + Buffer = calloc (Size, 1); + if (!Buffer) + { + printf ("Could not allocate buffer of size %u\n", Size); + goto ErrorExit; + } + + /* Read the entire file */ + + Size = read (FileHandle, Buffer, Size); + if (Size == -1) + { + printf ("Could not read the input file %s\n", Filename); + free (Buffer); + Buffer = NULL; + goto ErrorExit; + } + + *FileSize = Size; + +ErrorExit: + close (FileHandle); + + return (Buffer); +} + + +/****************************************************************************** + * + * FUNCTION: AbDumpAmlFile + * + * DESCRIPTION: Dump a binary AML file to a text file + * + ******************************************************************************/ + +int +AbDumpAmlFile ( + char *File1Path, + char *File2Path) +{ + char *FileBuffer; + UINT32 FileSize = 0; + FILE *FileOutHandle; + + + /* Get the entire AML file, validate header */ + + FileBuffer = AbGetFile (File1Path, &FileSize); + printf ("File %s contains 0x%X bytes\n\n", File1Path, FileSize); + + FileOutHandle = fopen (File2Path, "wb"); + if (!FileOutHandle) + { + printf ("Could not open %s\n", File2Path); + return -1; + } + + if (!AbValidateHeader ((ACPI_TABLE_HEADER *) FileBuffer)) + { + return -1; + } + + /* Convert binary AML to text, using common dump buffer routine */ + + AcpiGbl_DebugFile = FileOutHandle; + AcpiGbl_DbOutputFlags = ACPI_DB_REDIRECTABLE_OUTPUT; + + AcpiOsPrintf ("%4.4s\n", ((ACPI_TABLE_HEADER *) FileBuffer)->Signature); + AcpiDbgLevel = ACPI_UINT32_MAX; + AcpiUtDumpBuffer ((UINT8 *) FileBuffer, FileSize, + DB_BYTE_DISPLAY, ACPI_UINT32_MAX); + + return 0; +} + + +/****************************************************************************** + * + * FUNCTION: AbExtractAmlFile + * + * DESCRIPTION: Extract a binary AML file from a text file (as produced by the + * DumpAmlFile procedure or the "acpidmp" table utility. + * + ******************************************************************************/ + +int +AbExtractAmlFile ( + char *TableSig, + char *File1Path, + char *File2Path) +{ + char *Table; + char Value; + UINT32 i; + FILE *FileHandle; + FILE *FileOutHandle; + UINT32 Count = 0; + int Scanned; + + + /* Open in/out files. input is in text mode, output is in binary mode */ + + FileHandle = fopen (File1Path, "rt"); + if (!FileHandle) + { + printf ("Could not open %s\n", File1Path); + return -1; + } + + FileOutHandle = fopen (File2Path, "w+b"); + if (!FileOutHandle) + { + printf ("Could not open %s\n", File2Path); + return -1; + } + + /* Force input table sig to uppercase */ + + AcpiUtStrupr (TableSig); + + + /* TBD: examine input for ASCII */ + + + /* We have an ascii file, grab one line at a time */ + + while (fgets (Buffer, BUFFER_SIZE, FileHandle)) + { + /* The 4-char ACPI signature appears at the beginning of a line */ + + if (!strncmp (Buffer, TableSig, 4)) + { + printf ("Found table [%4.4s]\n", TableSig); + + /* + * Eat all lines in the table, of the form: + * <offset>: <16 bytes of hex data, separated by spaces> <ASCII representation> <newline> + * + * Example: + * + * 02C0: 5F 53 42 5F 4C 4E 4B 44 00 12 13 04 0C FF FF 08 _SB_LNKD........ + * + */ + while (fgets (Buffer, BUFFER_SIZE, FileHandle)) + { + /* Get past the offset, terminated by a colon */ + + Table = strchr (Buffer, ':'); + if (!Table) + { + /* No colon, all done */ + goto Exit; + } + + Table += 2; /* Eat the colon + space */ + + for (i = 0; i < 16; i++) + { + Scanned = AbHexByteToBinary (Table, &Value); + if (!Scanned) + { + goto Exit; + } + + Table += 3; /* Go past this hex byte and space */ + + /* Write the converted (binary) byte */ + + fwrite (&Value, 1, 1, FileOutHandle); + Count++; + } + } + + /* No more lines, EOF, all done */ + + goto Exit; + } + } + + /* Searched entire file, no match to table signature */ + + printf ("Could not match table signature\n"); + fclose (FileHandle); + return -1; + +Exit: + printf ("%u (0x%X) bytes written to %s\n", Count, Count, File2Path); + fclose (FileHandle); + fclose (FileOutHandle); + return 0; +} + + +/****************************************************************************** + * + * FUNCTION: Stubs + * + * DESCRIPTION: For linkage + * + ******************************************************************************/ + +ACPI_PHYSICAL_ADDRESS +AeLocalGetRootPointer ( + void) +{ + return AE_OK; +} + +ACPI_THREAD_ID +AcpiOsGetThreadId ( + void) +{ + return (0xFFFF); +} + +ACPI_STATUS +AcpiOsExecute ( + ACPI_EXECUTE_TYPE Type, + ACPI_OSD_EXEC_CALLBACK Function, + void *Context) +{ + return (AE_SUPPORT); +} diff --git a/source/tools/acpibin/abmain.c b/source/tools/acpibin/abmain.c new file mode 100644 index 000000000000..cb9c329521f0 --- /dev/null +++ b/source/tools/acpibin/abmain.c @@ -0,0 +1,186 @@ + +/****************************************************************************** + * + * Module Name: abmain - Main module for the acpi binary utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#define _DECLARE_GLOBALS +#include "acpibin.h" +#include "acapps.h" + +/* Local prototypes */ + +static void +AbDisplayUsage ( + UINT8 OptionCount); + + +/****************************************************************************** + * + * FUNCTION: AbDisplayUsage + * + * DESCRIPTION: Usage message + * + ******************************************************************************/ + +static void +AbDisplayUsage ( + UINT8 OptionCount) +{ + + if (OptionCount) + { + printf ("Option requires %u arguments\n\n", OptionCount); + } + + ACPI_USAGE_HEADER ("acpibin [options]"); + + ACPI_OPTION ("-c <File1><File2>", "Compare two AML files"); + ACPI_OPTION ("-d <In><Out>", "Dump AML binary to text file"); + ACPI_OPTION ("-e <Sig><In><Out>", "Extract binary AML table from AcpiDmp file"); + ACPI_OPTION ("-h <File>", "Display table header for binary AML file"); + ACPI_OPTION ("-s <File>", "Update checksum for binary AML file"); + ACPI_OPTION ("-t", "Terse mode"); +} + + +/****************************************************************************** + * + * FUNCTION: main + * + * DESCRIPTION: C main function + * + ******************************************************************************/ + +int ACPI_SYSTEM_XFACE +main ( + int argc, + char *argv[]) +{ + int j; + int Status = AE_OK; + + + AcpiGbl_DebugFile = NULL; + AcpiGbl_DbOutputFlags = DB_CONSOLE_OUTPUT ; + + AcpiOsInitialize (); + printf (ACPI_COMMON_SIGNON ("ACPI Binary AML File Utility")); + + if (argc < 2) + { + AbDisplayUsage (0); + return 0; + } + + /* Command line options */ + + while ((j = AcpiGetopt (argc, argv, "c:d:e:h:s:t")) != EOF) switch(j) + { + case 'c': /* Compare Files */ + + if (argc < 4) + { + AbDisplayUsage (2); + return -1; + } + + Status = AbCompareAmlFiles (AcpiGbl_Optarg, argv[AcpiGbl_Optind]); + break; + + case 'd': /* Dump AML file */ + + if (argc < 4) + { + AbDisplayUsage (2); + return -1; + } + + Status = AbDumpAmlFile (AcpiGbl_Optarg, argv[AcpiGbl_Optind]); + break; + + case 'e': /* Extract AML text file */ + + if (argc < 5) + { + AbDisplayUsage (3); + return -1; + } + + Status = AbExtractAmlFile (AcpiGbl_Optarg, argv[AcpiGbl_Optind], + argv[AcpiGbl_Optind+1]); + break; + + case 'h': /* Display ACPI table header */ + + if (argc < 3) + { + AbDisplayUsage (1); + return -1; + } + + AbDisplayHeader (AcpiGbl_Optarg); + return (0); + + case 's': /* Compute/update checksum */ + + if (argc < 3) + { + AbDisplayUsage (1); + return -1; + } + + AbComputeChecksum (AcpiGbl_Optarg); + return (0); + + case 't': /* Enable terse mode */ + + Gbl_TerseMode = TRUE; + break; + + default: + AbDisplayUsage (0); + return -1; + } + + return Status; +} diff --git a/source/tools/acpibin/acpibin.h b/source/tools/acpibin/acpibin.h new file mode 100644 index 000000000000..63109cc738cf --- /dev/null +++ b/source/tools/acpibin/acpibin.h @@ -0,0 +1,113 @@ + +/****************************************************************************** + * + * Module Name: acpibinh - Include file for AcpiBin utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpi.h" +#include "accommon.h" + +#include <stdio.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> +#include <ctype.h> +#include <errno.h> + +#ifdef WIN32 +#include <stdlib.h> +#include <io.h> +#include <direct.h> +#endif + +/* O_BINARY is not always defined */ +#ifndef O_BINARY +#define O_BINARY 0x0 +#endif + +#define DB_CONSOLE_OUTPUT 0x02 +#define ACPI_DB_REDIRECTABLE_OUTPUT 0x01 + +/* + * Global variables. Defined in main.c only, externed in all other files + */ + +#ifdef _DECLARE_GLOBALS +#define EXTERN +#define INIT_GLOBAL(a,b) a=b +#else +#define EXTERN extern +#define INIT_GLOBAL(a,b) a +#endif + + +/* Globals */ + +EXTERN BOOLEAN INIT_GLOBAL (Gbl_TerseMode, FALSE); +EXTERN FILE INIT_GLOBAL (*AcpiGbl_DebugFile, NULL); + + +/* Prototypes */ + +int +AbCompareAmlFiles ( + char *File1Path, + char *File2Path); + +int +AbExtractAmlFile ( + char *TableSig, + char *File1Path, + char *File2Path); + +int +AbDumpAmlFile ( + char *File1Path, + char *File2Path); + +void +AbComputeChecksum ( + char *File1Path); + +void +AbDisplayHeader ( + char *File1Path); + diff --git a/source/tools/acpiexec/Makefile b/source/tools/acpiexec/Makefile new file mode 100644 index 000000000000..65a1d84411d6 --- /dev/null +++ b/source/tools/acpiexec/Makefile @@ -0,0 +1,286 @@ +# +# acpiexec: ACPI execution simulator. Runs ACPICA code in user +# space. Loads ACPI tables, displays the namespace, and allows +# execution of control methods. +# +# NOTE: This makefile is intended to be used within the native +# ACPICA source tree. +# + +# +# Configuration +# Notes: +# gcc should be version 4 or greater, otherwise some of the options +# used will not be recognized. +# Global optimization flags (such as -O2, -Os) are not used, since +# they cause issues on some compilers. +# The _GNU_SOURCE symbol is required for many hosts. +# +PROG = acpiexec + +HOST = _LINUX +NOMAN = YES +COMPILE = $(CC) -c $(CFLAGS) $(CWARNINGFLAGS) -o$@ $< +LDFLAGS += -lpthread -lrt + +ACPICA_SRC = ../../../source +ACPICA_COMMON = $(ACPICA_SRC)/common +ACPICA_TOOLS = $(ACPICA_SRC)/tools +ACPICA_OSL = $(ACPICA_SRC)/os_specific/service_layers +ACPICA_CORE = $(ACPICA_SRC)/components +ACPICA_INCLUDE = $(ACPICA_SRC)/include +ACPICA_DEBUGGER = $(ACPICA_CORE)/debugger +ACPICA_DISASSEMBLER = $(ACPICA_CORE)/disassembler +ACPICA_DISPATCHER = $(ACPICA_CORE)/dispatcher +ACPICA_EVENTS = $(ACPICA_CORE)/events +ACPICA_EXECUTER = $(ACPICA_CORE)/executer +ACPICA_HARDWARE = $(ACPICA_CORE)/hardware +ACPICA_NAMESPACE = $(ACPICA_CORE)/namespace +ACPICA_PARSER = $(ACPICA_CORE)/parser +ACPICA_RESOURCES = $(ACPICA_CORE)/resources +ACPICA_TABLES = $(ACPICA_CORE)/tables +ACPICA_UTILITIES = $(ACPICA_CORE)/utilities +ACPIEXEC = $(ACPICA_TOOLS)/acpiexec +INSTALLDIR = /usr/bin +INSTALLPROG = cp --remove-destination $(PROG) $(INSTALLDIR) + +ACPICA_HEADERS = \ + $(wildcard $(ACPICA_INCLUDE)/*.h) \ + $(wildcard $(ACPICA_INCLUDE)/platform/*.h) + +# +# Search paths for source files +# +vpath %.c \ + $(ACPIEXEC) \ + $(ACPICA_DEBUGGER) \ + $(ACPICA_DISASSEMBLER) \ + $(ACPICA_DISPATCHER) \ + $(ACPICA_EVENTS) \ + $(ACPICA_EXECUTER) \ + $(ACPICA_HARDWARE) \ + $(ACPICA_NAMESPACE) \ + $(ACPICA_PARSER) \ + $(ACPICA_RESOURCES) \ + $(ACPICA_TABLES) \ + $(ACPICA_UTILITIES) \ + $(ACPICA_COMMON) \ + $(ACPICA_OSL) + +HEADERS = \ + $(wildcard $(ACPIEXEC)/*.h) + +OBJECTS = \ + aeexec.o \ + aehandlers.o \ + aemain.o \ + aetables.o \ + dbcmds.o \ + dbdisply.o \ + dbexec.o \ + dbfileio.o \ + dbhistry.o \ + dbinput.o \ + dbmethod.o \ + dbnames.o \ + dbstats.o \ + dbutils.o \ + dbxface.o \ + dmbuffer.o \ + dmnames.o \ + dmobject.o \ + dmopcode.o \ + dmresrc.o \ + dmresrcl.o \ + dmresrcl2.o \ + dmresrcs.o \ + dmutils.o \ + dmwalk.o \ + dsargs.o \ + dscontrol.o \ + dsfield.o \ + dsinit.o \ + dsmethod.o \ + dsmthdat.o \ + dsobject.o \ + dsopcode.o \ + dsutils.o \ + dswexec.o \ + dswload.o \ + dswload2.o \ + dswscope.o \ + dswstate.o \ + evevent.o \ + evglock.o \ + evgpe.o \ + evgpeblk.o \ + evgpeinit.o \ + evgpeutil.o \ + evmisc.o \ + evregion.o \ + evrgnini.o \ + evsci.o \ + evxface.o \ + evxfevnt.o \ + evxfgpe.o \ + evxfregn.o \ + exconfig.o \ + exconvrt.o \ + excreate.o \ + exdebug.o \ + exdump.o \ + exfield.o \ + exfldio.o \ + exmisc.o \ + exmutex.o \ + exnames.o \ + exoparg1.o \ + exoparg2.o \ + exoparg3.o \ + exoparg6.o \ + exprep.o \ + exregion.o \ + exresnte.o \ + exresolv.o \ + exresop.o \ + exstore.o \ + exstoren.o \ + exstorob.o \ + exsystem.o \ + exutils.o \ + getopt.o \ + hwacpi.o \ + hwesleep.o \ + hwgpe.o \ + hwpci.o \ + hwregs.o \ + hwsleep.o \ + hwvalid.o \ + hwxface.o \ + hwxfsleep.o \ + nsaccess.o \ + nsalloc.o \ + nsdump.o \ + nsdumpdv.o \ + nseval.o \ + nsinit.o \ + nsload.o \ + nsnames.o \ + nsobject.o \ + nsparse.o \ + nspredef.o \ + nsrepair.o \ + nsrepair2.o \ + nssearch.o \ + nsutils.o \ + nswalk.o \ + nsxfeval.o \ + nsxfname.o \ + nsxfobj.o \ + osunixxf.o \ + psargs.o \ + psloop.o \ + psopcode.o \ + psparse.o \ + psscope.o \ + pstree.o \ + psutils.o \ + pswalk.o \ + psxface.o \ + rsaddr.o \ + rscalc.o \ + rscreate.o \ + rsdump.o \ + rsinfo.o \ + rsio.o \ + rsirq.o \ + rslist.o \ + rsmemory.o \ + rsserial.o \ + rsmisc.o \ + rsutils.o \ + rsxface.o \ + tbfadt.o \ + tbfind.o \ + tbinstal.o \ + tbutils.o \ + tbxface.o \ + tbxfroot.o \ + utaddress.o \ + utalloc.o \ + utcache.o \ + utcopy.o \ + utdebug.o \ + utdecode.o \ + utdelete.o \ + uteval.o \ + utglobal.o \ + utids.o \ + utinit.o \ + utlock.o \ + utmath.o \ + utmisc.o \ + utmutex.o \ + utobject.o \ + utresrc.o \ + utstate.o \ + uttrack.o \ + utosi.o \ + utxferror.o \ + utxface.o \ + utxfmutex.o + +CFLAGS+= \ + -D$(HOST) \ + -D_GNU_SOURCE \ + -DACPI_EXEC_APP \ + -I$(ACPICA_INCLUDE) + +CWARNINGFLAGS = \ + -ansi \ + -Wall \ + -Wbad-function-cast \ + -Wdeclaration-after-statement \ + -Werror \ + -Wformat=2 \ + -Wmissing-declarations \ + -Wmissing-prototypes \ + -Wstrict-aliasing=0 \ + -Wstrict-prototypes \ + -Wswitch-default \ + -Wpointer-arith \ + -Wundef + +# +# gcc 4+ flags +# +CWARNINGFLAGS += \ + -Waddress \ + -Waggregate-return \ + -Wchar-subscripts \ + -Wempty-body \ + -Wlogical-op \ + -Wmissing-declarations \ + -Wmissing-field-initializers \ + -Wmissing-parameter-type \ + -Wnested-externs \ + -Wold-style-declaration \ + -Wold-style-definition \ + -Wredundant-decls \ + -Wtype-limits + +# +# Rules +# +$(PROG) : $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) -o $(PROG) + $(COPYPROG) + +%.o : %.c $(HEADERS) $(ACPICA_HEADERS) + $(COMPILE) + +clean : + rm -f $(PROG) $(PROG).exe $(OBJECTS) + +install : + $(INSTALLPROG) diff --git a/source/tools/acpiexec/aecommon.h b/source/tools/acpiexec/aecommon.h new file mode 100644 index 000000000000..0f1b4c1e7569 --- /dev/null +++ b/source/tools/acpiexec/aecommon.h @@ -0,0 +1,199 @@ +/****************************************************************************** + * + * Module Name: aecommon - common include for the AcpiExec utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#ifndef _AECOMMON +#define _AECOMMON + +#ifdef _MSC_VER /* disable some level-4 warnings */ +#pragma warning(disable:4100) /* warning C4100: unreferenced formal parameter */ +#endif + +#include "acpi.h" +#include "accommon.h" +#include "acparser.h" +#include "amlcode.h" +#include "acnamesp.h" +#include "acdebug.h" +#include "actables.h" +#include "acinterp.h" +#include "acapps.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <signal.h> + +extern FILE *AcpiGbl_DebugFile; +extern BOOLEAN AcpiGbl_IgnoreErrors; +extern UINT8 AcpiGbl_RegionFillValue; +extern UINT8 AcpiGbl_UseHwReducedFadt; +extern BOOLEAN AcpiGbl_DisplayRegionAccess; + +/* Check for unexpected exceptions */ + +#define AE_CHECK_STATUS(Name, Status, Expected) \ + if (Status != Expected) \ + { \ + AcpiOsPrintf ("Unexpected %s from %s (%s-%d)\n", \ + AcpiFormatException (Status), #Name, _AcpiModuleName, __LINE__); \ + } + +/* Check for unexpected non-AE_OK errors */ + +#define AE_CHECK_OK(Name, Status) AE_CHECK_STATUS (Name, Status, AE_OK); + +typedef struct ae_table_desc +{ + ACPI_TABLE_HEADER *Table; + struct ae_table_desc *Next; + +} AE_TABLE_DESC; + +/* + * Debug Regions + */ +typedef struct ae_region +{ + ACPI_PHYSICAL_ADDRESS Address; + UINT32 Length; + void *Buffer; + void *NextRegion; + UINT8 SpaceId; + +} AE_REGION; + +typedef struct ae_debug_regions +{ + UINT32 NumberOfRegions; + AE_REGION *RegionList; + +} AE_DEBUG_REGIONS; + + +#define TEST_OUTPUT_LEVEL(lvl) if ((lvl) & OutputLevel) + +#define OSD_PRINT(lvl,fp) TEST_OUTPUT_LEVEL(lvl) {\ + AcpiOsPrintf PARAM_LIST(fp);} + +void ACPI_SYSTEM_XFACE +AeCtrlCHandler ( + int Sig); + +ACPI_STATUS +AeBuildLocalTables ( + UINT32 TableCount, + AE_TABLE_DESC *TableList); + +ACPI_STATUS +AeInstallTables ( + void); + +void +AeDumpNamespace ( + void); + +void +AeDumpObject ( + char *MethodName, + ACPI_BUFFER *ReturnObj); + +void +AeDumpBuffer ( + UINT32 Address); + +void +AeExecute ( + char *Name); + +void +AeSetScope ( + char *Name); + +void +AeCloseDebugFile ( + void); + +void +AeOpenDebugFile ( + char *Name); + +ACPI_STATUS +AeDisplayAllMethods ( + UINT32 DisplayCount); + +ACPI_STATUS +AeInstallEarlyHandlers ( + void); + +ACPI_STATUS +AeInstallLateHandlers ( + void); + +void +AeMiscellaneousTests ( + void); + +ACPI_STATUS +AeRegionHandler ( + UINT32 Function, + ACPI_PHYSICAL_ADDRESS Address, + UINT32 BitWidth, + UINT64 *Value, + void *HandlerContext, + void *RegionContext); + +UINT32 +AeGpeHandler ( + ACPI_HANDLE GpeDevice, + UINT32 GpeNumber, + void *Context); + +void +AeGlobalEventHandler ( + UINT32 Type, + ACPI_HANDLE GpeDevice, + UINT32 EventNumber, + void *Context); + +#endif /* _AECOMMON */ + diff --git a/source/tools/acpiexec/aeexec.c b/source/tools/acpiexec/aeexec.c new file mode 100644 index 000000000000..407519f9648e --- /dev/null +++ b/source/tools/acpiexec/aeexec.c @@ -0,0 +1,720 @@ +/****************************************************************************** + * + * Module Name: aeexec - Support routines for AcpiExec utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "aecommon.h" + +#define _COMPONENT ACPI_TOOLS + ACPI_MODULE_NAME ("aeexec") + +/* Local prototypes */ + +static ACPI_STATUS +AeSetupConfiguration ( + void *RegionAddr); + +static void +AeTestBufferArgument ( + void); + +static void +AeTestPackageArgument ( + void); + +static ACPI_STATUS +AeGetDevices ( + ACPI_HANDLE ObjHandle, + UINT32 NestingLevel, + void *Context, + void **ReturnValue); + +static ACPI_STATUS +ExecuteOSI ( + char *OsiString, + UINT32 ExpectedResult); + +static void +AeMutexInterfaces ( + void); + +static void +AeHardwareInterfaces ( + void); + +static void +AeGenericRegisters ( + void); + +#if (!ACPI_REDUCED_HARDWARE) +static void +AfInstallGpeBlock ( + void); +#endif /* !ACPI_REDUCED_HARDWARE */ + +extern unsigned char Ssdt3Code[]; + + +/****************************************************************************** + * + * FUNCTION: AeSetupConfiguration + * + * PARAMETERS: RegionAddr - Address for an ACPI table to be loaded + * dynamically. Test purposes only. + * + * RETURN: Status + * + * DESCRIPTION: Call AML _CFG configuration control method + * + *****************************************************************************/ + +static ACPI_STATUS +AeSetupConfiguration ( + void *RegionAddr) +{ + ACPI_OBJECT_LIST ArgList; + ACPI_OBJECT Arg[3]; + + + /* + * Invoke _CFG method if present + */ + ArgList.Count = 1; + ArgList.Pointer = Arg; + + Arg[0].Type = ACPI_TYPE_INTEGER; + Arg[0].Integer.Value = ACPI_TO_INTEGER (RegionAddr); + + (void) AcpiEvaluateObject (NULL, "\\_CFG", &ArgList, NULL); + return (AE_OK); +} + + +#if (!ACPI_REDUCED_HARDWARE) +/****************************************************************************** + * + * FUNCTION: AfInstallGpeBlock + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Test GPE block device initialization. Requires test ASL with + * A \GPE2 device. + * + *****************************************************************************/ + +static void +AfInstallGpeBlock ( + void) +{ + ACPI_STATUS Status; + ACPI_HANDLE Handle; + ACPI_HANDLE Handle2 = NULL; + ACPI_HANDLE Handle3 = NULL; + ACPI_GENERIC_ADDRESS BlockAddress; + ACPI_HANDLE GpeDevice; + + + Status = AcpiGetHandle (NULL, "\\_GPE", &Handle); + if (ACPI_FAILURE (Status)) + { + return; + } + + ACPI_MEMSET (&BlockAddress, 0, sizeof (ACPI_GENERIC_ADDRESS)); + BlockAddress.SpaceId = ACPI_ADR_SPACE_SYSTEM_MEMORY; + BlockAddress.Address = 0x76540000; + + Status = AcpiGetHandle (NULL, "\\GPE2", &Handle2); + if (ACPI_SUCCESS (Status)) + { + Status = AcpiInstallGpeBlock (Handle2, &BlockAddress, 7, 8); + AE_CHECK_OK (AcpiInstallGpeBlock, Status); + + Status = AcpiInstallGpeHandler (Handle2, 8, + ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL); + AE_CHECK_OK (AcpiInstallGpeHandler, Status); + + Status = AcpiEnableGpe (Handle2, 8); + AE_CHECK_OK (AcpiEnableGpe, Status); + + Status = AcpiGetGpeDevice (0x30, &GpeDevice); + AE_CHECK_OK (AcpiGetGpeDevice, Status); + + Status = AcpiGetGpeDevice (0x42, &GpeDevice); + AE_CHECK_OK (AcpiGetGpeDevice, Status); + + Status = AcpiGetGpeDevice (AcpiCurrentGpeCount-1, &GpeDevice); + AE_CHECK_OK (AcpiGetGpeDevice, Status); + + Status = AcpiGetGpeDevice (AcpiCurrentGpeCount, &GpeDevice); + AE_CHECK_STATUS (AcpiGetGpeDevice, Status, AE_NOT_EXIST); + + Status = AcpiRemoveGpeHandler (Handle2, 8, AeGpeHandler); + AE_CHECK_OK (AcpiRemoveGpeHandler, Status); + } + + Status = AcpiGetHandle (NULL, "\\GPE3", &Handle3); + if (ACPI_SUCCESS (Status)) + { + Status = AcpiInstallGpeBlock (Handle3, &BlockAddress, 8, 11); + AE_CHECK_OK (AcpiInstallGpeBlock, Status); + } +} +#endif /* !ACPI_REDUCED_HARDWARE */ + + +/* Test using a Buffer object as a method argument */ + +static void +AeTestBufferArgument ( + void) +{ + ACPI_OBJECT_LIST Params; + ACPI_OBJECT BufArg; + UINT8 Buffer[] = { + 0,0,0,0, + 4,0,0,0, + 1,2,3,4}; + + + BufArg.Type = ACPI_TYPE_BUFFER; + BufArg.Buffer.Length = 12; + BufArg.Buffer.Pointer = Buffer; + + Params.Count = 1; + Params.Pointer = &BufArg; + + (void) AcpiEvaluateObject (NULL, "\\BUF", &Params, NULL); +} + + +static ACPI_OBJECT PkgArg; +static ACPI_OBJECT PkgElements[5]; +static ACPI_OBJECT Pkg2Elements[5]; +static ACPI_OBJECT_LIST Params; + + +/* + * Test using a Package object as an method argument + */ +static void +AeTestPackageArgument ( + void) +{ + + /* Main package */ + + PkgArg.Type = ACPI_TYPE_PACKAGE; + PkgArg.Package.Count = 4; + PkgArg.Package.Elements = PkgElements; + + /* Main package elements */ + + PkgElements[0].Type = ACPI_TYPE_INTEGER; + PkgElements[0].Integer.Value = 0x22228888; + + PkgElements[1].Type = ACPI_TYPE_STRING; + PkgElements[1].String.Length = sizeof ("Top-level package"); + PkgElements[1].String.Pointer = "Top-level package"; + + PkgElements[2].Type = ACPI_TYPE_BUFFER; + PkgElements[2].Buffer.Length = sizeof ("XXXX"); + PkgElements[2].Buffer.Pointer = (UINT8 *) "XXXX"; + + PkgElements[3].Type = ACPI_TYPE_PACKAGE; + PkgElements[3].Package.Count = 2; + PkgElements[3].Package.Elements = Pkg2Elements; + + /* Sub-package elements */ + + Pkg2Elements[0].Type = ACPI_TYPE_INTEGER; + Pkg2Elements[0].Integer.Value = 0xAAAABBBB; + + Pkg2Elements[1].Type = ACPI_TYPE_STRING; + Pkg2Elements[1].String.Length = sizeof ("Nested Package"); + Pkg2Elements[1].String.Pointer = "Nested Package"; + + /* Parameter object */ + + Params.Count = 1; + Params.Pointer = &PkgArg; + + (void) AcpiEvaluateObject (NULL, "\\_PKG", &Params, NULL); +} + + +static ACPI_STATUS +AeGetDevices ( + ACPI_HANDLE ObjHandle, + UINT32 NestingLevel, + void *Context, + void **ReturnValue) +{ + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: ExecuteOSI + * + * PARAMETERS: OsiString - String passed to _OSI method + * ExpectedResult - 0 (FALSE) or 0xFFFFFFFF (TRUE) + * + * RETURN: Status + * + * DESCRIPTION: Execute the internally implemented (in ACPICA) _OSI method. + * + *****************************************************************************/ + +static ACPI_STATUS +ExecuteOSI ( + char *OsiString, + UINT32 ExpectedResult) +{ + ACPI_STATUS Status; + ACPI_OBJECT_LIST ArgList; + ACPI_OBJECT Arg[1]; + ACPI_BUFFER ReturnValue; + ACPI_OBJECT *Obj; + + + /* Setup input argument */ + + ArgList.Count = 1; + ArgList.Pointer = Arg; + + Arg[0].Type = ACPI_TYPE_STRING; + Arg[0].String.Pointer = OsiString; + Arg[0].String.Length = strlen (Arg[0].String.Pointer); + + /* Ask ACPICA to allocate space for the return object */ + + ReturnValue.Length = ACPI_ALLOCATE_BUFFER; + + Status = AcpiEvaluateObject (NULL, "\\_OSI", &ArgList, &ReturnValue); + + if (ACPI_FAILURE (Status)) + { + AcpiOsPrintf ("Could not execute _OSI method, %s\n", + AcpiFormatException (Status)); + return (Status); + } + + if (ReturnValue.Length < sizeof (ACPI_OBJECT)) + { + AcpiOsPrintf ("Return value from _OSI method too small, %.8X\n", + ReturnValue.Length); + return (AE_ERROR); + } + + Obj = ReturnValue.Pointer; + if (Obj->Type != ACPI_TYPE_INTEGER) + { + AcpiOsPrintf ("Invalid return type from _OSI method, %.2X\n", Obj->Type); + return (AE_ERROR); + } + + if (Obj->Integer.Value != ExpectedResult) + { + AcpiOsPrintf ("Invalid return value from _OSI, expected %.8X found %.8X\n", + ExpectedResult, (UINT32) Obj->Integer.Value); + return (AE_ERROR); + } + + /* Reset the OSI data */ + + AcpiGbl_OsiData = 0; + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AeGenericRegisters + * + * DESCRIPTION: Call the AcpiRead/Write interfaces. + * + *****************************************************************************/ + +static ACPI_GENERIC_ADDRESS GenericRegister; + +static void +AeGenericRegisters ( + void) +{ + ACPI_STATUS Status; + UINT64 Value; + + + GenericRegister.Address = 0x1234; + GenericRegister.BitWidth = 64; + GenericRegister.BitOffset = 0; + GenericRegister.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO; + + Status = AcpiRead (&Value, &GenericRegister); + AE_CHECK_OK (AcpiRead, Status); + + Status = AcpiWrite (Value, &GenericRegister); + AE_CHECK_OK (AcpiWrite, Status); + + GenericRegister.Address = 0x12345678; + GenericRegister.BitOffset = 0; + GenericRegister.SpaceId = ACPI_ADR_SPACE_SYSTEM_MEMORY; + + Status = AcpiRead (&Value, &GenericRegister); + AE_CHECK_OK (AcpiRead, Status); + + Status = AcpiWrite (Value, &GenericRegister); + AE_CHECK_OK (AcpiWrite, Status); +} + + +/****************************************************************************** + * + * FUNCTION: AeMutexInterfaces + * + * DESCRIPTION: Exercise the AML mutex access interfaces + * + *****************************************************************************/ + +static void +AeMutexInterfaces ( + void) +{ + ACPI_STATUS Status; + ACPI_HANDLE MutexHandle; + + + /* Get a handle to an AML mutex */ + + Status = AcpiGetHandle (NULL, "\\MTX1", &MutexHandle); + if (Status == AE_NOT_FOUND) + { + return; + } + + AE_CHECK_OK (AcpiGetHandle, Status); + if (ACPI_FAILURE (Status)) + { + return; + } + + /* Acquire the mutex */ + + Status = AcpiAcquireMutex (NULL, "\\MTX1", 0xFFFF); + AE_CHECK_OK (AcpiAcquireMutex, Status); + if (ACPI_FAILURE (Status)) + { + return; + } + + /* Release mutex with different parameters */ + + Status = AcpiReleaseMutex (MutexHandle, NULL); + AE_CHECK_OK (AcpiReleaseMutex, Status); +} + + +/****************************************************************************** + * + * FUNCTION: AeHardwareInterfaces + * + * DESCRIPTION: Call various hardware support interfaces + * + *****************************************************************************/ + +static void +AeHardwareInterfaces ( + void) +{ +#if (!ACPI_REDUCED_HARDWARE) + + ACPI_STATUS Status; + UINT32 Value; + + + /* If Hardware Reduced flag is set, we are all done */ + + if (AcpiGbl_ReducedHardware) + { + return; + } + + Status = AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS, 1); + AE_CHECK_OK (AcpiWriteBitRegister, Status); + + Status = AcpiWriteBitRegister (ACPI_BITREG_GLOBAL_LOCK_ENABLE, 1); + AE_CHECK_OK (AcpiWriteBitRegister, Status); + + Status = AcpiWriteBitRegister (ACPI_BITREG_SLEEP_ENABLE, 1); + AE_CHECK_OK (AcpiWriteBitRegister, Status); + + Status = AcpiWriteBitRegister (ACPI_BITREG_ARB_DISABLE, 1); + AE_CHECK_OK (AcpiWriteBitRegister, Status); + + + Status = AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS, &Value); + AE_CHECK_OK (AcpiReadBitRegister, Status); + + Status = AcpiReadBitRegister (ACPI_BITREG_GLOBAL_LOCK_ENABLE, &Value); + AE_CHECK_OK (AcpiReadBitRegister, Status); + + Status = AcpiReadBitRegister (ACPI_BITREG_SLEEP_ENABLE, &Value); + AE_CHECK_OK (AcpiReadBitRegister, Status); + + Status = AcpiReadBitRegister (ACPI_BITREG_ARB_DISABLE, &Value); + AE_CHECK_OK (AcpiReadBitRegister, Status); + +#endif /* !ACPI_REDUCED_HARDWARE */ +} + + +/****************************************************************************** + * + * FUNCTION: AeMiscellaneousTests + * + * DESCRIPTION: Various ACPICA validation tests. + * + *****************************************************************************/ + +void +AeMiscellaneousTests ( + void) +{ + ACPI_BUFFER ReturnBuf; + char Buffer[32]; + ACPI_STATUS Status; + ACPI_STATISTICS Stats; + +#if (!ACPI_REDUCED_HARDWARE) + ACPI_HANDLE Handle; + ACPI_VENDOR_UUID Uuid = {0, {ACPI_INIT_UUID (0,0,0,0,0,0,0,0,0,0,0)}}; + UINT32 LockHandle1; + UINT32 LockHandle2; +#endif /* !ACPI_REDUCED_HARDWARE */ + + + AeHardwareInterfaces (); + AeGenericRegisters (); + AeSetupConfiguration (Ssdt3Code); + + AeTestBufferArgument(); + AeTestPackageArgument (); + AeMutexInterfaces (); + + Status = AcpiInstallInterface (""); + AE_CHECK_STATUS (AcpiInstallInterface, Status, AE_BAD_PARAMETER); + + Status = AcpiInstallInterface ("TestString"); + AE_CHECK_OK (AcpiInstallInterface, Status); + + Status = AcpiInstallInterface ("TestString"); + AE_CHECK_STATUS (AcpiInstallInterface, Status, AE_ALREADY_EXISTS); + + Status = AcpiRemoveInterface ("Windows 2006"); + AE_CHECK_OK (AcpiRemoveInterface, Status); + + Status = AcpiRemoveInterface ("TestString"); + AE_CHECK_OK (AcpiRemoveInterface, Status); + + Status = AcpiRemoveInterface ("XXXXXX"); + AE_CHECK_STATUS (AcpiRemoveInterface, Status, AE_NOT_EXIST); + + Status = AcpiInstallInterface ("AnotherTestString"); + AE_CHECK_OK (AcpiInstallInterface, Status); + + + Status = ExecuteOSI ("Windows 2001", 0xFFFFFFFF); + AE_CHECK_OK (ExecuteOSI, Status); + + Status = ExecuteOSI ("MichiganTerminalSystem", 0); + AE_CHECK_OK (ExecuteOSI, Status); + + + ReturnBuf.Length = 32; + ReturnBuf.Pointer = Buffer; + + Status = AcpiGetName (AcpiGbl_RootNode, ACPI_FULL_PATHNAME, &ReturnBuf); + AE_CHECK_OK (AcpiGetName, Status); + + /* Get Devices */ + + Status = AcpiGetDevices (NULL, AeGetDevices, NULL, NULL); + AE_CHECK_OK (AcpiGetDevices, Status); + + Status = AcpiGetStatistics (&Stats); + AE_CHECK_OK (AcpiGetStatistics, Status); + + +#if (!ACPI_REDUCED_HARDWARE) + + Status = AcpiInstallGlobalEventHandler (AeGlobalEventHandler, NULL); + AE_CHECK_OK (AcpiInstallGlobalEventHandler, Status); + + /* If Hardware Reduced flag is set, we are all done */ + + if (AcpiGbl_ReducedHardware) + { + return; + } + + Status = AcpiEnableEvent (ACPI_EVENT_GLOBAL, 0); + AE_CHECK_OK (AcpiEnableEvent, Status); + + /* + * GPEs: Handlers, enable/disable, etc. + */ + Status = AcpiInstallGpeHandler (NULL, 0, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL); + AE_CHECK_OK (AcpiInstallGpeHandler, Status); + + Status = AcpiEnableGpe (NULL, 0); + AE_CHECK_OK (AcpiEnableGpe, Status); + + Status = AcpiRemoveGpeHandler (NULL, 0, AeGpeHandler); + AE_CHECK_OK (AcpiRemoveGpeHandler, Status); + + Status = AcpiInstallGpeHandler (NULL, 0, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL); + AE_CHECK_OK (AcpiInstallGpeHandler, Status); + + Status = AcpiEnableGpe (NULL, 0); + AE_CHECK_OK (AcpiEnableGpe, Status); + + Status = AcpiSetGpe (NULL, 0, ACPI_GPE_DISABLE); + AE_CHECK_OK (AcpiSetGpe, Status); + + Status = AcpiSetGpe (NULL, 0, ACPI_GPE_ENABLE); + AE_CHECK_OK (AcpiSetGpe, Status); + + + Status = AcpiInstallGpeHandler (NULL, 1, ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL); + AE_CHECK_OK (AcpiInstallGpeHandler, Status); + + Status = AcpiEnableGpe (NULL, 1); + AE_CHECK_OK (AcpiEnableGpe, Status); + + + Status = AcpiInstallGpeHandler (NULL, 2, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL); + AE_CHECK_OK (AcpiInstallGpeHandler, Status); + + Status = AcpiEnableGpe (NULL, 2); + AE_CHECK_OK (AcpiEnableGpe, Status); + + + Status = AcpiInstallGpeHandler (NULL, 3, ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL); + AE_CHECK_OK (AcpiInstallGpeHandler, Status); + + Status = AcpiInstallGpeHandler (NULL, 4, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL); + AE_CHECK_OK (AcpiInstallGpeHandler, Status); + + Status = AcpiInstallGpeHandler (NULL, 5, ACPI_GPE_EDGE_TRIGGERED, AeGpeHandler, NULL); + AE_CHECK_OK (AcpiInstallGpeHandler, Status); + + Status = AcpiGetHandle (NULL, "\\_SB", &Handle); + AE_CHECK_OK (AcpiGetHandle, Status); + + Status = AcpiSetupGpeForWake (Handle, NULL, 5); + AE_CHECK_OK (AcpiSetupGpeForWake, Status); + + Status = AcpiSetGpeWakeMask (NULL, 5, ACPI_GPE_ENABLE); + AE_CHECK_OK (AcpiGpeWakeup, Status); + + Status = AcpiSetupGpeForWake (Handle, NULL, 6); + AE_CHECK_OK (AcpiSetupGpeForWake, Status); + + Status = AcpiSetupGpeForWake (Handle, NULL, 9); + AE_CHECK_OK (AcpiSetupGpeForWake, Status); + + Status = AcpiInstallGpeHandler (NULL, 0x19, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL); + AE_CHECK_OK (AcpiInstallGpeHandler, Status); + + Status = AcpiEnableGpe (NULL, 0x19); + AE_CHECK_OK (AcpiEnableGpe, Status); + + + Status = AcpiInstallGpeHandler (NULL, 0x62, ACPI_GPE_LEVEL_TRIGGERED, AeGpeHandler, NULL); + AE_CHECK_OK (AcpiInstallGpeHandler, Status); + + Status = AcpiEnableGpe (NULL, 0x62); + AE_CHECK_OK (AcpiEnableGpe, Status); + + Status = AcpiDisableGpe (NULL, 0x62); + AE_CHECK_OK (AcpiDisableGpe, Status); + + AfInstallGpeBlock (); + + /* Here is where the GPEs are actually "enabled" */ + + Status = AcpiUpdateAllGpes (); + AE_CHECK_OK (AcpiUpdateAllGpes, Status); + + Status = AcpiGetHandle (NULL, "RSRC", &Handle); + if (ACPI_SUCCESS (Status)) + { + ReturnBuf.Length = ACPI_ALLOCATE_BUFFER; + + Status = AcpiGetVendorResource (Handle, "_CRS", &Uuid, &ReturnBuf); + if (ACPI_SUCCESS (Status)) + { + AcpiOsFree (ReturnBuf.Pointer); + } + } + + /* Test global lock */ + + Status = AcpiAcquireGlobalLock (0xFFFF, &LockHandle1); + AE_CHECK_OK (AcpiAcquireGlobalLock, Status); + + Status = AcpiAcquireGlobalLock (0x5, &LockHandle2); + AE_CHECK_OK (AcpiAcquireGlobalLock, Status); + + Status = AcpiReleaseGlobalLock (LockHandle1); + AE_CHECK_OK (AcpiReleaseGlobalLock, Status); + + Status = AcpiReleaseGlobalLock (LockHandle2); + AE_CHECK_OK (AcpiReleaseGlobalLock, Status); + +#endif /* !ACPI_REDUCED_HARDWARE */ +} + diff --git a/source/tools/acpiexec/aehandlers.c b/source/tools/acpiexec/aehandlers.c new file mode 100644 index 000000000000..f41dd53d31ed --- /dev/null +++ b/source/tools/acpiexec/aehandlers.c @@ -0,0 +1,1251 @@ +/****************************************************************************** + * + * Module Name: aehandlers - Various handlers for acpiexec + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "aecommon.h" + +#define _COMPONENT ACPI_TOOLS + ACPI_MODULE_NAME ("aehandlers") + +/* Local prototypes */ + +static void +AeNotifyHandler ( + ACPI_HANDLE Device, + UINT32 Value, + void *Context); + +static void +AeDeviceNotifyHandler ( + ACPI_HANDLE Device, + UINT32 Value, + void *Context); + +static ACPI_STATUS +AeExceptionHandler ( + ACPI_STATUS AmlStatus, + ACPI_NAME Name, + UINT16 Opcode, + UINT32 AmlOffset, + void *Context); + +static ACPI_STATUS +AeTableHandler ( + UINT32 Event, + void *Table, + void *Context); + +static ACPI_STATUS +AeRegionInit ( + ACPI_HANDLE RegionHandle, + UINT32 Function, + void *HandlerContext, + void **RegionContext); + +static void +AeAttachedDataHandler ( + ACPI_HANDLE Object, + void *Data); + +static UINT32 +AeInterfaceHandler ( + ACPI_STRING InterfaceName, + UINT32 Supported); + +#if (!ACPI_REDUCED_HARDWARE) +static UINT32 +AeEventHandler ( + void *Context); + +static char *TableEvents[] = +{ + "LOAD", + "UNLOAD", + "UNKNOWN" +}; +#endif /* !ACPI_REDUCED_HARDWARE */ + +static UINT32 SigintCount = 0; +static AE_DEBUG_REGIONS AeRegions; +BOOLEAN AcpiGbl_DisplayRegionAccess = FALSE; + + +/* + * We will override some of the default region handlers, especially the + * SystemMemory handler, which must be implemented locally. Do not override + * the PCI_Config handler since we would like to exercise the default handler + * code. These handlers are installed "early" - before any _REG methods + * are executed - since they are special in the sense that tha ACPI spec + * declares that they must "always be available". Cannot override the + * DataTable region handler either -- needed for test execution. + */ +static ACPI_ADR_SPACE_TYPE DefaultSpaceIdList[] = +{ + ACPI_ADR_SPACE_SYSTEM_MEMORY, + ACPI_ADR_SPACE_SYSTEM_IO +}; + +/* + * We will install handlers for some of the various address space IDs. + * Test one user-defined address space (used by aslts.) + */ +#define ACPI_ADR_SPACE_USER_DEFINED1 0x80 +#define ACPI_ADR_SPACE_USER_DEFINED2 0xE4 + +static ACPI_ADR_SPACE_TYPE SpaceIdList[] = +{ + ACPI_ADR_SPACE_EC, + ACPI_ADR_SPACE_SMBUS, + ACPI_ADR_SPACE_GSBUS, + ACPI_ADR_SPACE_GPIO, + ACPI_ADR_SPACE_PCI_BAR_TARGET, + ACPI_ADR_SPACE_IPMI, + ACPI_ADR_SPACE_FIXED_HARDWARE, + ACPI_ADR_SPACE_USER_DEFINED1, + ACPI_ADR_SPACE_USER_DEFINED2 +}; + + +static ACPI_CONNECTION_INFO AeMyContext; + +/****************************************************************************** + * + * FUNCTION: AeCtrlCHandler + * + * PARAMETERS: Sig + * + * RETURN: none + * + * DESCRIPTION: Control-C handler. Abort running control method if any. + * + *****************************************************************************/ + +void ACPI_SYSTEM_XFACE +AeCtrlCHandler ( + int Sig) +{ + + signal (SIGINT, SIG_IGN); + SigintCount++; + + AcpiOsPrintf ("Caught a ctrl-c (#%u)\n\n", SigintCount); + + if (AcpiGbl_MethodExecuting) + { + AcpiGbl_AbortMethod = TRUE; + signal (SIGINT, AeCtrlCHandler); + + if (SigintCount < 10) + { + return; + } + } + + exit (0); +} + + +/****************************************************************************** + * + * FUNCTION: AeNotifyHandler + * + * PARAMETERS: Standard notify handler parameters + * + * RETURN: Status + * + * DESCRIPTION: System notify handler for AcpiExec utility. Used by the ASL + * test suite(s) to communicate errors and other information to + * this utility via the Notify() operator. + * + *****************************************************************************/ + +static void +AeNotifyHandler ( + ACPI_HANDLE Device, + UINT32 Value, + void *Context) +{ + + switch (Value) + { +#if 0 + case 0: + printf ("[AcpiExec] Method Error 0x%X: Results not equal\n", Value); + if (AcpiGbl_DebugFile) + { + AcpiOsPrintf ("[AcpiExec] Method Error: Results not equal\n"); + } + break; + + + case 1: + printf ("[AcpiExec] Method Error: Incorrect numeric result\n"); + if (AcpiGbl_DebugFile) + { + AcpiOsPrintf ("[AcpiExec] Method Error: Incorrect numeric result\n"); + } + break; + + + case 2: + printf ("[AcpiExec] Method Error: An operand was overwritten\n"); + if (AcpiGbl_DebugFile) + { + AcpiOsPrintf ("[AcpiExec] Method Error: An operand was overwritten\n"); + } + break; + +#endif + + default: + printf ("[AcpiExec] Received a System Notify on [%4.4s] %p Value 0x%2.2X (%s)\n", + AcpiUtGetNodeName (Device), Device, Value, + AcpiUtGetNotifyName (Value)); + if (AcpiGbl_DebugFile) + { + AcpiOsPrintf ("[AcpiExec] Received a system notify, Value 0x%2.2X\n", Value); + } + + (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL); + break; + } +} + + +/****************************************************************************** + * + * FUNCTION: AeDeviceNotifyHandler + * + * PARAMETERS: Standard notify handler parameters + * + * RETURN: Status + * + * DESCRIPTION: Device notify handler for AcpiExec utility. Used by the ASL + * test suite(s) to communicate errors and other information to + * this utility via the Notify() operator. + * + *****************************************************************************/ + +static void +AeDeviceNotifyHandler ( + ACPI_HANDLE Device, + UINT32 Value, + void *Context) +{ + + printf ("[AcpiExec] Received a Device Notify on [%4.4s] %p Value 0x%2.2X (%s)\n", + AcpiUtGetNodeName (Device), Device, Value, + AcpiUtGetNotifyName (Value)); + if (AcpiGbl_DebugFile) + { + AcpiOsPrintf ("[AcpiExec] Received a device notify, Value 0x%2.2X\n", Value); + } + + (void) AcpiEvaluateObject (Device, "_NOT", NULL, NULL); +} + + +/****************************************************************************** + * + * FUNCTION: AeExceptionHandler + * + * PARAMETERS: Standard exception handler parameters + * + * RETURN: Status + * + * DESCRIPTION: System exception handler for AcpiExec utility. + * + *****************************************************************************/ + +static ACPI_STATUS +AeExceptionHandler ( + ACPI_STATUS AmlStatus, + ACPI_NAME Name, + UINT16 Opcode, + UINT32 AmlOffset, + void *Context) +{ + ACPI_STATUS NewAmlStatus = AmlStatus; + ACPI_STATUS Status; + ACPI_BUFFER ReturnObj; + ACPI_OBJECT_LIST ArgList; + ACPI_OBJECT Arg[3]; + const char *Exception; + + + Exception = AcpiFormatException (AmlStatus); + AcpiOsPrintf ("[AcpiExec] Exception %s during execution ", Exception); + if (Name) + { + AcpiOsPrintf ("of method [%4.4s]", (char *) &Name); + } + else + { + AcpiOsPrintf ("at module level (table load)"); + } + AcpiOsPrintf (" Opcode [%s] @%X\n", AcpiPsGetOpcodeName (Opcode), AmlOffset); + + /* + * Invoke the _ERR method if present + * + * Setup parameter object + */ + ArgList.Count = 3; + ArgList.Pointer = Arg; + + Arg[0].Type = ACPI_TYPE_INTEGER; + Arg[0].Integer.Value = AmlStatus; + + Arg[1].Type = ACPI_TYPE_STRING; + Arg[1].String.Pointer = ACPI_CAST_PTR (char, Exception); + Arg[1].String.Length = ACPI_STRLEN (Exception); + + Arg[2].Type = ACPI_TYPE_INTEGER; + Arg[2].Integer.Value = AcpiOsGetThreadId(); + + /* Setup return buffer */ + + ReturnObj.Pointer = NULL; + ReturnObj.Length = ACPI_ALLOCATE_BUFFER; + + Status = AcpiEvaluateObject (NULL, "\\_ERR", &ArgList, &ReturnObj); + if (ACPI_SUCCESS (Status)) + { + if (ReturnObj.Pointer) + { + /* Override original status */ + + NewAmlStatus = (ACPI_STATUS) + ((ACPI_OBJECT *) ReturnObj.Pointer)->Integer.Value; + + AcpiOsFree (ReturnObj.Pointer); + } + } + else if (Status != AE_NOT_FOUND) + { + AcpiOsPrintf ("[AcpiExec] Could not execute _ERR method, %s\n", + AcpiFormatException (Status)); + } + + /* Global override */ + + if (AcpiGbl_IgnoreErrors) + { + NewAmlStatus = AE_OK; + } + + if (NewAmlStatus != AmlStatus) + { + AcpiOsPrintf ("[AcpiExec] Exception override, new status %s\n", + AcpiFormatException (NewAmlStatus)); + } + + return (NewAmlStatus); +} + + +/****************************************************************************** + * + * FUNCTION: AeTableHandler + * + * PARAMETERS: Table handler + * + * RETURN: Status + * + * DESCRIPTION: System table handler for AcpiExec utility. + * + *****************************************************************************/ + +static ACPI_STATUS +AeTableHandler ( + UINT32 Event, + void *Table, + void *Context) +{ +#if (!ACPI_REDUCED_HARDWARE) + ACPI_STATUS Status; +#endif /* !ACPI_REDUCED_HARDWARE */ + + + if (Event > ACPI_NUM_TABLE_EVENTS) + { + Event = ACPI_NUM_TABLE_EVENTS; + } + +#if (!ACPI_REDUCED_HARDWARE) + /* Enable any GPEs associated with newly-loaded GPE methods */ + + Status = AcpiUpdateAllGpes (); + AE_CHECK_OK (AcpiUpdateAllGpes, Status); + + printf ("[AcpiExec] Table Event %s, [%4.4s] %p\n", + TableEvents[Event], ((ACPI_TABLE_HEADER *) Table)->Signature, Table); +#endif /* !ACPI_REDUCED_HARDWARE */ + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AeGpeHandler + * + * DESCRIPTION: Common GPE handler for acpiexec + * + *****************************************************************************/ + +UINT32 +AeGpeHandler ( + ACPI_HANDLE GpeDevice, + UINT32 GpeNumber, + void *Context) +{ + ACPI_NAMESPACE_NODE *DeviceNode = (ACPI_NAMESPACE_NODE *) GpeDevice; + + + AcpiOsPrintf ("[AcpiExec] GPE Handler received GPE%02X (GPE block %4.4s)\n", + GpeNumber, GpeDevice ? DeviceNode->Name.Ascii : "FADT"); + + return (ACPI_REENABLE_GPE); +} + + +/****************************************************************************** + * + * FUNCTION: AeGlobalEventHandler + * + * DESCRIPTION: Global GPE/Fixed event handler + * + *****************************************************************************/ + +void +AeGlobalEventHandler ( + UINT32 Type, + ACPI_HANDLE Device, + UINT32 EventNumber, + void *Context) +{ + char *TypeName; + + + switch (Type) + { + case ACPI_EVENT_TYPE_GPE: + TypeName = "GPE"; + break; + + case ACPI_EVENT_TYPE_FIXED: + TypeName = "FixedEvent"; + break; + + default: + TypeName = "UNKNOWN"; + break; + } + + AcpiOsPrintf ("[AcpiExec] Global Event Handler received: Type %s Number %.2X Dev %p\n", + TypeName, EventNumber, Device); +} + + +/****************************************************************************** + * + * FUNCTION: AeAttachedDataHandler + * + * DESCRIPTION: Handler for deletion of nodes with attached data (attached via + * AcpiAttachData) + * + *****************************************************************************/ + +static void +AeAttachedDataHandler ( + ACPI_HANDLE Object, + void *Data) +{ + ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Data); + + + AcpiOsPrintf ("Received an attached data deletion on %4.4s\n", + Node->Name.Ascii); +} + + +/****************************************************************************** + * + * FUNCTION: AeInterfaceHandler + * + * DESCRIPTION: Handler for _OSI invocations + * + *****************************************************************************/ + +static UINT32 +AeInterfaceHandler ( + ACPI_STRING InterfaceName, + UINT32 Supported) +{ + ACPI_FUNCTION_NAME (AeInterfaceHandler); + + + ACPI_DEBUG_PRINT ((ACPI_DB_INFO, + "Received _OSI (\"%s\"), is %ssupported\n", + InterfaceName, Supported == 0 ? "not " : "")); + + return (Supported); +} + + +#if (!ACPI_REDUCED_HARDWARE) +/****************************************************************************** + * + * FUNCTION: AeEventHandler + * + * DESCRIPTION: Handler for Fixed Events + * + *****************************************************************************/ + +static UINT32 +AeEventHandler ( + void *Context) +{ + return (0); +} +#endif /* !ACPI_REDUCED_HARDWARE */ + + +/****************************************************************************** + * + * FUNCTION: AeRegionInit + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Opregion init function. + * + *****************************************************************************/ + +static ACPI_STATUS +AeRegionInit ( + ACPI_HANDLE RegionHandle, + UINT32 Function, + void *HandlerContext, + void **RegionContext) +{ + /* + * Real simple, set the RegionContext to the RegionHandle + */ + *RegionContext = RegionHandle; + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AeInstallLateHandlers + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Install handlers for the AcpiExec utility. + * + *****************************************************************************/ + +ACPI_STATUS +AeInstallLateHandlers ( + void) +{ + ACPI_STATUS Status; + UINT32 i; + + +#if (!ACPI_REDUCED_HARDWARE) + if (!AcpiGbl_ReducedHardware) + { + /* Install some fixed event handlers */ + + Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL, AeEventHandler, NULL); + AE_CHECK_OK (AcpiInstallFixedEventHandler, Status); + + Status = AcpiInstallFixedEventHandler (ACPI_EVENT_RTC, AeEventHandler, NULL); + AE_CHECK_OK (AcpiInstallFixedEventHandler, Status); + } +#endif /* !ACPI_REDUCED_HARDWARE */ + + AeMyContext.Connection = NULL; + AeMyContext.AccessLength = 0xA5; + + /* + * Install handlers for some of the "device driver" address spaces + * such as EC, SMBus, etc. + */ + for (i = 0; i < ACPI_ARRAY_LENGTH (SpaceIdList); i++) + { + /* Install handler at the root object */ + + Status = AcpiInstallAddressSpaceHandler (AcpiGbl_RootNode, + SpaceIdList[i], AeRegionHandler, + AeRegionInit, &AeMyContext); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, + "Could not install an OpRegion handler for %s space(%u)", + AcpiUtGetRegionName((UINT8) SpaceIdList[i]), SpaceIdList[i])); + return (Status); + } + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AeInstallEarlyHandlers + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Install handlers for the AcpiExec utility. + * + * Notes: Don't install handler for PCI_Config, we want to use the + * default handler to exercise that code. + * + *****************************************************************************/ + +ACPI_STATUS +AeInstallEarlyHandlers ( + void) +{ + ACPI_STATUS Status; + UINT32 i; + ACPI_HANDLE Handle; + + + ACPI_FUNCTION_ENTRY (); + + + Status = AcpiInstallInterfaceHandler (AeInterfaceHandler); + if (ACPI_FAILURE (Status)) + { + printf ("Could not install interface handler, %s\n", + AcpiFormatException (Status)); + } + + Status = AcpiInstallTableHandler (AeTableHandler, NULL); + if (ACPI_FAILURE (Status)) + { + printf ("Could not install table handler, %s\n", + AcpiFormatException (Status)); + } + + Status = AcpiInstallExceptionHandler (AeExceptionHandler); + if (ACPI_FAILURE (Status)) + { + printf ("Could not install exception handler, %s\n", + AcpiFormatException (Status)); + } + + /* Install global notify handler */ + + Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, + AeNotifyHandler, NULL); + if (ACPI_FAILURE (Status)) + { + printf ("Could not install a global notify handler, %s\n", + AcpiFormatException (Status)); + } + + Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_DEVICE_NOTIFY, + AeDeviceNotifyHandler, NULL); + if (ACPI_FAILURE (Status)) + { + printf ("Could not install a global notify handler, %s\n", + AcpiFormatException (Status)); + } + + Status = AcpiGetHandle (NULL, "\\_SB", &Handle); + if (ACPI_SUCCESS (Status)) + { + Status = AcpiInstallNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY, + AeNotifyHandler, NULL); + if (ACPI_FAILURE (Status)) + { + printf ("Could not install a notify handler, %s\n", + AcpiFormatException (Status)); + } + + Status = AcpiRemoveNotifyHandler (Handle, ACPI_SYSTEM_NOTIFY, + AeNotifyHandler); + if (ACPI_FAILURE (Status)) + { + printf ("Could not remove a notify handler, %s\n", + AcpiFormatException (Status)); + } + + Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY, + AeNotifyHandler, NULL); + AE_CHECK_OK (AcpiInstallNotifyHandler, Status); + + Status = AcpiRemoveNotifyHandler (Handle, ACPI_ALL_NOTIFY, + AeNotifyHandler); + AE_CHECK_OK (AcpiRemoveNotifyHandler, Status); + + Status = AcpiInstallNotifyHandler (Handle, ACPI_ALL_NOTIFY, + AeNotifyHandler, NULL); + if (ACPI_FAILURE (Status)) + { + printf ("Could not install a notify handler, %s\n", + AcpiFormatException (Status)); + } + + Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle); + AE_CHECK_OK (AcpiAttachData, Status); + + Status = AcpiDetachData (Handle, AeAttachedDataHandler); + AE_CHECK_OK (AcpiDetachData, Status); + + Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle); + AE_CHECK_OK (AcpiAttachData, Status); + } + else + { + printf ("No _SB_ found, %s\n", AcpiFormatException (Status)); + } + + + /* + * Install handlers that will override the default handlers for some of + * the space IDs. + */ + for (i = 0; i < ACPI_ARRAY_LENGTH (DefaultSpaceIdList); i++) + { + /* Install handler at the root object */ + + Status = AcpiInstallAddressSpaceHandler (AcpiGbl_RootNode, + DefaultSpaceIdList[i], AeRegionHandler, + AeRegionInit, &AeMyContext); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, + "Could not install a default OpRegion handler for %s space(%u)", + AcpiUtGetRegionName ((UINT8) DefaultSpaceIdList[i]), + DefaultSpaceIdList[i])); + return (Status); + } + } + + /* + * Initialize the global Region Handler space + * MCW 3/23/00 + */ + AeRegions.NumberOfRegions = 0; + AeRegions.RegionList = NULL; + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: AeRegionHandler + * + * PARAMETERS: Standard region handler parameters + * + * RETURN: Status + * + * DESCRIPTION: Test handler - Handles some dummy regions via memory that can + * be manipulated in Ring 3. Simulates actual reads and writes. + * + *****************************************************************************/ + +ACPI_STATUS +AeRegionHandler ( + UINT32 Function, + ACPI_PHYSICAL_ADDRESS Address, + UINT32 BitWidth, + UINT64 *Value, + void *HandlerContext, + void *RegionContext) +{ + + ACPI_OPERAND_OBJECT *RegionObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, RegionContext); + UINT8 *Buffer = ACPI_CAST_PTR (UINT8, Value); + ACPI_PHYSICAL_ADDRESS BaseAddress; + ACPI_SIZE Length; + BOOLEAN BufferExists; + AE_REGION *RegionElement; + void *BufferValue; + ACPI_STATUS Status; + UINT32 ByteWidth; + UINT32 i; + UINT8 SpaceId; + ACPI_CONNECTION_INFO *MyContext; + UINT32 Value1; + UINT32 Value2; + ACPI_RESOURCE *Resource; + + + ACPI_FUNCTION_NAME (AeRegionHandler); + + /* + * If the object is not a region, simply return + */ + if (RegionObject->Region.Type != ACPI_TYPE_REGION) + { + return (AE_OK); + } + + /* Check that we actually got back our context parameter */ + + if (HandlerContext != &AeMyContext) + { + printf ("Region handler received incorrect context %p, should be %p\n", + HandlerContext, &AeMyContext); + } + + MyContext = ACPI_CAST_PTR (ACPI_CONNECTION_INFO, HandlerContext); + + /* + * Find the region's address space and length before searching + * the linked list. + */ + BaseAddress = RegionObject->Region.Address; + Length = (ACPI_SIZE) RegionObject->Region.Length; + SpaceId = RegionObject->Region.SpaceId; + + ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, "Operation Region request on %s at 0x%X\n", + AcpiUtGetRegionName (RegionObject->Region.SpaceId), + (UINT32) Address)); + + /* + * Region support can be disabled with the -do option. + * We use this to support dynamically loaded tables where we pass a valid + * address to the AML. + */ + if (AcpiGbl_DbOpt_NoRegionSupport) + { + BufferValue = ACPI_TO_POINTER (Address); + ByteWidth = (BitWidth / 8); + + if (BitWidth % 8) + { + ByteWidth += 1; + } + goto DoFunction; + } + + switch (SpaceId) + { + case ACPI_ADR_SPACE_SYSTEM_IO: + /* + * For I/O space, exercise the port validation + * Note: ReadPort currently always returns all ones, length=BitLength + */ + switch (Function & ACPI_IO_MASK) + { + case ACPI_READ: + + if (BitWidth == 64) + { + /* Split the 64-bit request into two 32-bit requests */ + + Status = AcpiHwReadPort (Address, &Value1, 32); + AE_CHECK_OK (AcpiHwReadPort, Status); + Status = AcpiHwReadPort (Address+4, &Value2, 32); + AE_CHECK_OK (AcpiHwReadPort, Status); + + *Value = Value1 | ((UINT64) Value2 << 32); + } + else + { + Status = AcpiHwReadPort (Address, &Value1, BitWidth); + AE_CHECK_OK (AcpiHwReadPort, Status); + *Value = (UINT64) Value1; + } + break; + + case ACPI_WRITE: + + if (BitWidth == 64) + { + /* Split the 64-bit request into two 32-bit requests */ + + Status = AcpiHwWritePort (Address, ACPI_LODWORD (*Value), 32); + AE_CHECK_OK (AcpiHwWritePort, Status); + Status = AcpiHwWritePort (Address+4, ACPI_HIDWORD (*Value), 32); + AE_CHECK_OK (AcpiHwWritePort, Status); + } + else + { + Status = AcpiHwWritePort (Address, (UINT32) *Value, BitWidth); + AE_CHECK_OK (AcpiHwWritePort, Status); + } + break; + + default: + Status = AE_BAD_PARAMETER; + break; + } + + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Now go ahead and simulate the hardware */ + break; + + /* + * SMBus and GenericSerialBus support the various bidirectional + * protocols. + */ + case ACPI_ADR_SPACE_SMBUS: + case ACPI_ADR_SPACE_GSBUS: /* ACPI 5.0 */ + + Length = 0; + + switch (Function & ACPI_IO_MASK) + { + case ACPI_READ: + switch (Function >> 16) + { + case AML_FIELD_ATTRIB_QUICK: + case AML_FIELD_ATTRIB_SEND_RCV: + case AML_FIELD_ATTRIB_BYTE: + Length = 1; + break; + + case AML_FIELD_ATTRIB_WORD: + case AML_FIELD_ATTRIB_WORD_CALL: + Length = 2; + break; + + case AML_FIELD_ATTRIB_BLOCK: + case AML_FIELD_ATTRIB_BLOCK_CALL: + Length = 32; + break; + + + case AML_FIELD_ATTRIB_MULTIBYTE: + case AML_FIELD_ATTRIB_RAW_BYTES: + case AML_FIELD_ATTRIB_RAW_PROCESS: + + /* (-2) for status/length */ + Length = MyContext->AccessLength - 2; + break; + + default: + break; + } + break; + + case ACPI_WRITE: + switch (Function >> 16) + { + case AML_FIELD_ATTRIB_QUICK: + case AML_FIELD_ATTRIB_SEND_RCV: + case AML_FIELD_ATTRIB_BYTE: + case AML_FIELD_ATTRIB_WORD: + case AML_FIELD_ATTRIB_BLOCK: + Length = 0; + break; + + case AML_FIELD_ATTRIB_WORD_CALL: + Length = 2; + break; + + case AML_FIELD_ATTRIB_BLOCK_CALL: + Length = 32; + break; + + case AML_FIELD_ATTRIB_MULTIBYTE: + case AML_FIELD_ATTRIB_RAW_BYTES: + case AML_FIELD_ATTRIB_RAW_PROCESS: + + /* (-2) for status/length */ + Length = MyContext->AccessLength - 2; + break; + + default: + break; + } + break; + + default: + break; + } + + if (AcpiGbl_DisplayRegionAccess) + { + AcpiOsPrintf ("AcpiExec: %s " + "%s: Attr %X Addr %.4X BaseAddr %.4X Len %.2X Width %X BufLen %X", + AcpiUtGetRegionName (SpaceId), + (Function & ACPI_IO_MASK) ? "Write" : "Read ", + (UINT32) (Function >> 16), + (UINT32) Address, (UINT32) BaseAddress, + Length, BitWidth, Buffer[1]); + + /* GenericSerialBus has a Connection() parameter */ + + if (SpaceId == ACPI_ADR_SPACE_GSBUS) + { + Status = AcpiBufferToResource (MyContext->Connection, + MyContext->Length, &Resource); + + AcpiOsPrintf (" [AccLen %.2X Conn %p]", + MyContext->AccessLength, MyContext->Connection); + } + AcpiOsPrintf ("\n"); + } + + /* Setup the return buffer. Note: ASLTS depends on these fill values */ + + for (i = 0; i < Length; i++) + { + Buffer[i+2] = (UINT8) (0xA0 + i); + } + + Buffer[0] = 0x7A; + Buffer[1] = (UINT8) Length; + return (AE_OK); + + + case ACPI_ADR_SPACE_IPMI: /* ACPI 4.0 */ + + if (AcpiGbl_DisplayRegionAccess) + { + AcpiOsPrintf ("AcpiExec: IPMI " + "%s: Attr %X Addr %.4X BaseAddr %.4X Len %.2X Width %X BufLen %X\n", + (Function & ACPI_IO_MASK) ? "Write" : "Read ", + (UINT32) (Function >> 16), (UINT32) Address, (UINT32) BaseAddress, + Length, BitWidth, Buffer[1]); + } + + /* + * Regardless of a READ or WRITE, this handler is passed a 66-byte + * buffer in which to return the IPMI status/length/data. + * + * Return some example data to show use of the bidirectional buffer + */ + Buffer[0] = 0; /* Status byte */ + Buffer[1] = 64; /* Return buffer data length */ + Buffer[2] = 0; /* Completion code */ + Buffer[3] = 0; /* Reserved */ + + /* + * Fill the 66-byte buffer with the return data. + * Note: ASLTS depends on these fill values. + */ + for (i = 4; i < 66; i++) + { + Buffer[i] = (UINT8) (i); + } + return (AE_OK); + + default: + break; + } + + /* + * Search through the linked list for this region's buffer + */ + BufferExists = FALSE; + RegionElement = AeRegions.RegionList; + + if (AeRegions.NumberOfRegions) + { + while (!BufferExists && RegionElement) + { + if (RegionElement->Address == BaseAddress && + RegionElement->Length == Length && + RegionElement->SpaceId == SpaceId) + { + BufferExists = TRUE; + } + else + { + RegionElement = RegionElement->NextRegion; + } + } + } + + /* + * If the Region buffer does not exist, create it now + */ + if (!BufferExists) + { + /* + * Do the memory allocations first + */ + RegionElement = AcpiOsAllocate (sizeof (AE_REGION)); + if (!RegionElement) + { + return (AE_NO_MEMORY); + } + + RegionElement->Buffer = AcpiOsAllocate (Length); + if (!RegionElement->Buffer) + { + AcpiOsFree (RegionElement); + return (AE_NO_MEMORY); + } + + /* Initialize the region with the default fill value */ + + ACPI_MEMSET (RegionElement->Buffer, AcpiGbl_RegionFillValue, Length); + + RegionElement->Address = BaseAddress; + RegionElement->Length = Length; + RegionElement->SpaceId = SpaceId; + RegionElement->NextRegion = NULL; + + /* + * Increment the number of regions and put this one + * at the head of the list as it will probably get accessed + * more often anyway. + */ + AeRegions.NumberOfRegions += 1; + + if (AeRegions.RegionList) + { + RegionElement->NextRegion = AeRegions.RegionList; + } + + AeRegions.RegionList = RegionElement; + } + + /* + * Calculate the size of the memory copy + */ + ByteWidth = (BitWidth / 8); + + if (BitWidth % 8) + { + ByteWidth += 1; + } + + /* + * The buffer exists and is pointed to by RegionElement. + * We now need to verify the request is valid and perform the operation. + * + * NOTE: RegionElement->Length is in bytes, therefore it we compare against + * ByteWidth (see above) + */ + if (((UINT64) Address + ByteWidth) > + ((UINT64)(RegionElement->Address) + RegionElement->Length)) + { + ACPI_WARNING ((AE_INFO, + "Request on [%4.4s] is beyond region limit Req-0x%X+0x%X, Base=0x%X, Len-0x%X", + (RegionObject->Region.Node)->Name.Ascii, (UINT32) Address, + ByteWidth, (UINT32)(RegionElement->Address), + RegionElement->Length)); + + return (AE_AML_REGION_LIMIT); + } + + /* + * Get BufferValue to point to the "address" in the buffer + */ + BufferValue = ((UINT8 *) RegionElement->Buffer + + ((UINT64) Address - (UINT64) RegionElement->Address)); + +DoFunction: + /* + * Perform a read or write to the buffer space + */ + switch (Function) + { + case ACPI_READ: + /* + * Set the pointer Value to whatever is in the buffer + */ + ACPI_MEMCPY (Value, BufferValue, ByteWidth); + break; + + case ACPI_WRITE: + /* + * Write the contents of Value to the buffer + */ + ACPI_MEMCPY (BufferValue, Value, ByteWidth); + break; + + default: + return (AE_BAD_PARAMETER); + } + + if (AcpiGbl_DisplayRegionAccess) + { + switch (SpaceId) + { + case ACPI_ADR_SPACE_SYSTEM_MEMORY: + + AcpiOsPrintf ("AcpiExec: SystemMemory " + "%s: Val %.8X Addr %.4X Width %X [REGION: BaseAddr %.4X Len %.2X]\n", + (Function & ACPI_IO_MASK) ? "Write" : "Read ", + (UINT32) *Value, (UINT32) Address, BitWidth, (UINT32) BaseAddress, Length); + break; + + case ACPI_ADR_SPACE_GPIO: /* ACPI 5.0 */ + + /* This space is required to always be ByteAcc */ + + Status = AcpiBufferToResource (MyContext->Connection, + MyContext->Length, &Resource); + + AcpiOsPrintf ("AcpiExec: GeneralPurposeIo " + "%s: Val %.8X Addr %.4X BaseAddr %.4X Len %.2X Width %X AccLen %.2X Conn %p\n", + (Function & ACPI_IO_MASK) ? "Write" : "Read ", (UINT32) *Value, + (UINT32) Address, (UINT32) BaseAddress, Length, BitWidth, + MyContext->AccessLength, MyContext->Connection); + break; + + default: + break; + } + } + + return (AE_OK); +} + + diff --git a/source/tools/acpiexec/aemain.c b/source/tools/acpiexec/aemain.c new file mode 100644 index 000000000000..a5d519c1e178 --- /dev/null +++ b/source/tools/acpiexec/aemain.c @@ -0,0 +1,700 @@ +/****************************************************************************** + * + * Module Name: aemain - Main routine for the AcpiExec utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "aecommon.h" + +#ifdef _DEBUG +#include <crtdbg.h> +#endif + +#define _COMPONENT PARSER + ACPI_MODULE_NAME ("aemain") + + +UINT8 AcpiGbl_RegionFillValue = 0; +BOOLEAN AcpiGbl_IgnoreErrors = FALSE; +BOOLEAN AcpiGbl_DbOpt_NoRegionSupport = FALSE; +BOOLEAN AcpiGbl_DebugTimeout = FALSE; +UINT8 AcpiGbl_UseHwReducedFadt = FALSE; + +static UINT8 AcpiGbl_BatchMode = 0; +static char BatchBuffer[128]; +static AE_TABLE_DESC *AeTableListHead = NULL; + +#define ASL_MAX_FILES 256 +static char *FileList[ASL_MAX_FILES]; + + +#define AE_SUPPORTED_OPTIONS "?b:d:e:f:gm^orv:x:" + + +/****************************************************************************** + * + * FUNCTION: usage + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Print a usage message + * + *****************************************************************************/ + +static void +usage (void) +{ + + ACPI_USAGE_HEADER ("acpiexec [options] AMLfile1 AMLfile2 ..."); + + ACPI_OPTION ("-?", "Display this message"); + ACPI_OPTION ("-b <CommandLine>", "Batch mode command execution"); + ACPI_OPTION ("-m [Method]", "Batch mode method execution. Default=MAIN"); + printf ("\n"); + + ACPI_OPTION ("-da", "Disable method abort on error"); + ACPI_OPTION ("-di", "Disable execution of STA/INI methods during init"); + ACPI_OPTION ("-do", "Disable Operation Region address simulation"); + ACPI_OPTION ("-dr", "Disable repair of method return values"); + ACPI_OPTION ("-dt", "Disable allocation tracking (performance)"); + printf ("\n"); + + ACPI_OPTION ("-ef", "Enable display of final memory statistics"); + ACPI_OPTION ("-em", "Enable Interpreter Serialized Mode"); + ACPI_OPTION ("-es", "Enable Interpreter Slack Mode"); + ACPI_OPTION ("-et", "Enable debug semaphore timeout"); + printf ("\n"); + + ACPI_OPTION ("-f <Value>", "Operation Region initialization fill value"); + ACPI_OPTION ("-r", "Use hardware-reduced FADT V5"); + ACPI_OPTION ("-vi", "Verbose initialization output"); + ACPI_OPTION ("-vr", "Verbose region handler output"); + ACPI_OPTION ("-x <DebugLevel>", "Debug output level"); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiDbRunBatchMode + * + * PARAMETERS: BatchCommandLine - A semicolon separated list of commands + * to be executed. + * Use only commas to separate elements of + * particular command. + * RETURN: Status + * + * DESCRIPTION: For each command of list separated by ';' prepare the command + * buffer and pass it to AcpiDbCommandDispatch. + * + *****************************************************************************/ + +static ACPI_STATUS +AcpiDbRunBatchMode ( + void) +{ + ACPI_STATUS Status; + char *Ptr = BatchBuffer; + char *Cmd = Ptr; + UINT8 Run = 0; + + + AcpiGbl_MethodExecuting = FALSE; + AcpiGbl_StepToNextCall = FALSE; + + while (*Ptr) + { + if (*Ptr == ',') + { + /* Convert commas to spaces */ + *Ptr = ' '; + } + else if (*Ptr == ';') + { + *Ptr = '\0'; + Run = 1; + } + + Ptr++; + + if (Run || (*Ptr == '\0')) + { + (void) AcpiDbCommandDispatch (Cmd, NULL, NULL); + Run = 0; + Cmd = Ptr; + } + } + + Status = AcpiTerminate (); + return (Status); +} + + +/******************************************************************************* + * + * FUNCTION: FlStrdup + * + * DESCRIPTION: Local strdup function + * + ******************************************************************************/ + +static char * +FlStrdup ( + char *String) +{ + char *NewString; + + + NewString = AcpiOsAllocate (strlen (String) + 1); + if (!NewString) + { + return (NULL); + } + + strcpy (NewString, String); + return (NewString); +} + + +/******************************************************************************* + * + * FUNCTION: FlSplitInputPathname + * + * PARAMETERS: InputFilename - The user-specified ASL source file to be + * compiled + * OutDirectoryPath - Where the directory path prefix is + * returned + * OutFilename - Where the filename part is returned + * + * RETURN: Status + * + * DESCRIPTION: Split the input path into a directory and filename part + * 1) Directory part used to open include files + * 2) Filename part used to generate output filenames + * + ******************************************************************************/ + +ACPI_STATUS +FlSplitInputPathname ( + char *InputPath, + char **OutDirectoryPath, + char **OutFilename) +{ + char *Substring; + char *DirectoryPath; + char *Filename; + + + *OutDirectoryPath = NULL; + *OutFilename = NULL; + + if (!InputPath) + { + return (AE_OK); + } + + /* Get the path to the input filename's directory */ + + DirectoryPath = FlStrdup (InputPath); + if (!DirectoryPath) + { + return (AE_NO_MEMORY); + } + + Substring = strrchr (DirectoryPath, '\\'); + if (!Substring) + { + Substring = strrchr (DirectoryPath, '/'); + if (!Substring) + { + Substring = strrchr (DirectoryPath, ':'); + } + } + + if (!Substring) + { + DirectoryPath[0] = 0; + Filename = FlStrdup (InputPath); + } + else + { + Filename = FlStrdup (Substring + 1); + *(Substring+1) = 0; + } + + if (!Filename) + { + return (AE_NO_MEMORY); + } + + *OutDirectoryPath = DirectoryPath; + *OutFilename = Filename; + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AsDoWildcard + * + * PARAMETERS: DirectoryPathname - Path to parent directory + * FileSpecifier - the wildcard specification (*.c, etc.) + * + * RETURN: Pointer to a list of filenames + * + * DESCRIPTION: Process files via wildcards. This function is for the Windows + * case only. + * + ******************************************************************************/ + +static char ** +AsDoWildcard ( + char *DirectoryPathname, + char *FileSpecifier) +{ +#ifdef WIN32 + void *DirInfo; + char *Filename; + int FileCount; + + + FileCount = 0; + + /* Open parent directory */ + + DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY); + if (!DirInfo) + { + /* Either the directory or file does not exist */ + + printf ("File or directory %s%s does not exist\n", DirectoryPathname, FileSpecifier); + return (NULL); + } + + /* Process each file that matches the wildcard specification */ + + while ((Filename = AcpiOsGetNextFilename (DirInfo))) + { + /* Add the filename to the file list */ + + FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1); + strcpy (FileList[FileCount], Filename); + FileCount++; + + if (FileCount >= ASL_MAX_FILES) + { + printf ("Max files reached\n"); + FileList[0] = NULL; + return (FileList); + } + } + + /* Cleanup */ + + AcpiOsCloseDirectory (DirInfo); + FileList[FileCount] = NULL; + return (FileList); + +#else + if (!FileSpecifier) + { + return (NULL); + } + + /* + * Linux/Unix cases - Wildcards are expanded by the shell automatically. + * Just return the filename in a null terminated list + */ + FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1); + strcpy (FileList[0], FileSpecifier); + FileList[1] = NULL; + + return (FileList); +#endif +} + + +/****************************************************************************** + * + * FUNCTION: main + * + * PARAMETERS: argc, argv + * + * RETURN: Status + * + * DESCRIPTION: Main routine for AcpiDump utility + * + *****************************************************************************/ + +int ACPI_SYSTEM_XFACE +main ( + int argc, + char **argv) +{ + int j; + ACPI_STATUS Status; + UINT32 InitFlags; + ACPI_TABLE_HEADER *Table = NULL; + UINT32 TableCount; + AE_TABLE_DESC *TableDesc; + char **WildcardList; + char *Filename; + char *Directory; + char *FullPathname; + + +#ifdef _DEBUG + _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | + _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); +#endif + + printf (ACPI_COMMON_SIGNON ("AML Execution/Debug Utility")); + + if (argc < 2) + { + usage (); + return (0); + } + + signal (SIGINT, AeCtrlCHandler); + + /* Init globals */ + + AcpiDbgLevel = ACPI_NORMAL_DEFAULT; + AcpiDbgLayer = 0xFFFFFFFF; + + /* Init ACPI and start debugger thread */ + + Status = AcpiInitializeSubsystem (); + AE_CHECK_OK (AcpiInitializeSubsystem, Status); + + /* Get the command line options */ + + while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch(j) + { + case 'b': + if (strlen (AcpiGbl_Optarg) > 127) + { + printf ("**** The length of command line (%u) exceeded maximum (127)\n", + (UINT32) strlen (AcpiGbl_Optarg)); + return (-1); + } + AcpiGbl_BatchMode = 1; + strcpy (BatchBuffer, AcpiGbl_Optarg); + break; + + case 'd': + switch (AcpiGbl_Optarg[0]) + { + case 'a': + AcpiGbl_IgnoreErrors = TRUE; + break; + + case 'i': + AcpiGbl_DbOpt_ini_methods = FALSE; + break; + + case 'o': + AcpiGbl_DbOpt_NoRegionSupport = TRUE; + break; + + case 'r': + AcpiGbl_DisableAutoRepair = TRUE; + break; + + case 't': + #ifdef ACPI_DBG_TRACK_ALLOCATIONS + AcpiGbl_DisableMemTracking = TRUE; + #endif + break; + + default: + printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + case 'e': + switch (AcpiGbl_Optarg[0]) + { + case 'f': + #ifdef ACPI_DBG_TRACK_ALLOCATIONS + AcpiGbl_DisplayFinalMemStats = TRUE; + #endif + break; + + case 'm': + AcpiGbl_AllMethodsSerialized = TRUE; + printf ("Enabling AML Interpreter serialized mode\n"); + break; + + case 's': + AcpiGbl_EnableInterpreterSlack = TRUE; + printf ("Enabling AML Interpreter slack mode\n"); + break; + + case 't': + AcpiGbl_DebugTimeout = TRUE; + break; + + default: + printf ("Unknown option: -e%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + case 'f': + AcpiGbl_RegionFillValue = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); + break; + + case 'g': + AcpiGbl_DbOpt_tables = TRUE; + AcpiGbl_DbFilename = NULL; + break; + + case 'm': + AcpiGbl_BatchMode = 2; + switch (AcpiGbl_Optarg[0]) + { + case '^': + strcpy (BatchBuffer, "MAIN"); + break; + + default: + strcpy (BatchBuffer, AcpiGbl_Optarg); + break; + } + break; + + case 'o': + AcpiGbl_DbOpt_disasm = TRUE; + AcpiGbl_DbOpt_stats = TRUE; + break; + + case 'r': + AcpiGbl_UseHwReducedFadt = TRUE; + printf ("Using ACPI 5.0 Hardware Reduced Mode via version 5 FADT\n"); + break; + + case 'v': + switch (AcpiGbl_Optarg[0]) + { + case 'i': + AcpiDbgLevel |= ACPI_LV_INIT_NAMES; + break; + + case 'r': + AcpiGbl_DisplayRegionAccess = TRUE; + break; + + default: + printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + case 'x': + AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 0); + AcpiGbl_DbConsoleDebugLevel = AcpiDbgLevel; + printf ("Debug Level: 0x%8.8X\n", AcpiDbgLevel); + break; + + case '?': + case 'h': + default: + usage(); + return (-1); + } + + + InitFlags = (ACPI_NO_HANDLER_INIT | ACPI_NO_ACPI_ENABLE); + if (!AcpiGbl_DbOpt_ini_methods) + { + InitFlags |= (ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT); + } + + /* The remaining arguments are filenames for ACPI tables */ + + if (argv[AcpiGbl_Optind]) + { + AcpiGbl_DbOpt_tables = TRUE; + TableCount = 0; + + /* Get each of the ACPI table files on the command line */ + + while (argv[AcpiGbl_Optind]) + { + /* Split incoming path into a directory/filename combo */ + + Status = FlSplitInputPathname (argv[AcpiGbl_Optind], &Directory, &Filename); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Expand wildcards (Windows only) */ + + WildcardList = AsDoWildcard (Directory, Filename); + if (!WildcardList) + { + return (-1); + } + + while (*WildcardList) + { + FullPathname = AcpiOsAllocate ( + strlen (Directory) + strlen (*WildcardList) + 1); + + /* Construct a full path to the file */ + + strcpy (FullPathname, Directory); + strcat (FullPathname, *WildcardList); + + /* Get one table */ + + Status = AcpiDbReadTableFromFile (FullPathname, &Table); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not get input table %s, %s\n", FullPathname, + AcpiFormatException (Status)); + goto enterloop; + } + + AcpiOsFree (FullPathname); + AcpiOsFree (*WildcardList); + *WildcardList = NULL; + WildcardList++; + + /* Ignore non-AML tables, we can't use them. Except for an FADT */ + + if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_FADT) && + !AcpiUtIsAmlTable (Table)) + { + ACPI_WARNING ((AE_INFO,"Table %4.4s is not an AML table, ignoring", + Table->Signature)); + AcpiOsFree (Table); + continue; + } + + /* Allocate and link a table descriptor */ + + TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC)); + TableDesc->Table = Table; + TableDesc->Next = AeTableListHead; + AeTableListHead = TableDesc; + + TableCount++; + } + + AcpiGbl_Optind++; + } + + /* Build a local RSDT with all tables and let ACPICA process the RSDT */ + + Status = AeBuildLocalTables (TableCount, AeTableListHead); + if (ACPI_FAILURE (Status)) + { + return (-1); + } + + Status = AeInstallTables (); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not load ACPI tables, %s\n", AcpiFormatException (Status)); + goto enterloop; + } + + /* + * Install most of the handlers. + * Override some default region handlers, especially SystemMemory + */ + Status = AeInstallEarlyHandlers (); + if (ACPI_FAILURE (Status)) + { + goto enterloop; + } + + /* + * TBD: Need a way to call this after the "LOAD" command + */ + Status = AcpiEnableSubsystem (InitFlags); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not EnableSubsystem, %s\n", AcpiFormatException (Status)); + goto enterloop; + } + + Status = AcpiInitializeObjects (InitFlags); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not InitializeObjects, %s\n", AcpiFormatException (Status)); + goto enterloop; + } + + /* + * Install handlers for "device driver" space IDs (EC,SMBus, etc.) + * and fixed event handlers + */ + AeInstallLateHandlers (); + AeMiscellaneousTests (); + } + +enterloop: + + if (AcpiGbl_BatchMode == 1) + { + AcpiDbRunBatchMode (); + } + else if (AcpiGbl_BatchMode == 2) + { + AcpiDbExecute (BatchBuffer, NULL, NULL, EX_NO_SINGLE_STEP); + } + else + { + /* Enter the debugger command loop */ + + AcpiDbUserCommands (ACPI_DEBUGGER_COMMAND_PROMPT, NULL); + } + + return (0); +} + diff --git a/source/tools/acpiexec/aetables.c b/source/tools/acpiexec/aetables.c new file mode 100644 index 000000000000..afada0d71417 --- /dev/null +++ b/source/tools/acpiexec/aetables.c @@ -0,0 +1,464 @@ +/****************************************************************************** + * + * Module Name: aetables - ACPI table setup/install for acpiexec utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "aecommon.h" +#include "aetables.h" + +#define _COMPONENT ACPI_TOOLS + ACPI_MODULE_NAME ("aetables") + +/* Local prototypes */ + +void +AeTableOverride ( + ACPI_TABLE_HEADER *ExistingTable, + ACPI_TABLE_HEADER **NewTable); + +ACPI_PHYSICAL_ADDRESS +AeLocalGetRootPointer ( + void); + +/* User table (DSDT) */ + +static ACPI_TABLE_HEADER *DsdtToInstallOverride; + +/* Non-AML tables that are constructed locally and installed */ + +static ACPI_TABLE_RSDP LocalRSDP; +static ACPI_TABLE_FACS LocalFACS; +static ACPI_TABLE_HEADER LocalTEST; +static ACPI_TABLE_HEADER LocalBADTABLE; + +/* + * We need a local FADT so that the hardware subcomponent will function, + * even though the underlying OSD HW access functions don't do anything. + */ +static ACPI_TABLE_FADT LocalFADT; + +/* + * Use XSDT so that both 32- and 64-bit versions of this utility will + * function automatically. + */ +static ACPI_TABLE_XSDT *LocalXSDT; + +#define BASE_XSDT_TABLES 8 +#define BASE_XSDT_SIZE (sizeof (ACPI_TABLE_XSDT) + \ + ((BASE_XSDT_TABLES -1) * sizeof (UINT64))) + +#define ACPI_MAX_INIT_TABLES (32) +static ACPI_TABLE_DESC Tables[ACPI_MAX_INIT_TABLES]; + + +/****************************************************************************** + * + * FUNCTION: AeTableOverride + * + * DESCRIPTION: Local implementation of AcpiOsTableOverride. + * Exercise the override mechanism + * + *****************************************************************************/ + +void +AeTableOverride ( + ACPI_TABLE_HEADER *ExistingTable, + ACPI_TABLE_HEADER **NewTable) +{ + + /* This code exercises the table override mechanism in the core */ + + if (ACPI_COMPARE_NAME (ExistingTable->Signature, ACPI_SIG_DSDT)) + { + *NewTable = DsdtToInstallOverride; + } + + /* This code tests override of dynamically loaded tables */ + + else if (ACPI_COMPARE_NAME (ExistingTable->Signature, "OEM9")) + { + *NewTable = ACPI_CAST_PTR (ACPI_TABLE_HEADER, Ssdt3Code); + } +} + + +/****************************************************************************** + * + * FUNCTION: AeBuildLocalTables + * + * PARAMETERS: TableCount - Number of tables on the command line + * TableList - List of actual tables from files + * + * RETURN: Status + * + * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT, + * FADT, and several other test tables. + * + *****************************************************************************/ + +ACPI_STATUS +AeBuildLocalTables ( + UINT32 TableCount, + AE_TABLE_DESC *TableList) +{ + ACPI_PHYSICAL_ADDRESS DsdtAddress = 0; + UINT32 XsdtSize; + AE_TABLE_DESC *NextTable; + UINT32 NextIndex; + ACPI_TABLE_FADT *ExternalFadt = NULL; + + + /* + * Update the table count. For DSDT, it is not put into the XSDT. For + * FADT, this is already accounted for since we usually install a + * local FADT. + */ + NextTable = TableList; + while (NextTable) + { + if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT) || + ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT)) + { + TableCount--; + } + NextTable = NextTable->Next; + } + + XsdtSize = BASE_XSDT_SIZE + (TableCount * sizeof (UINT64)); + + /* Build an XSDT */ + + LocalXSDT = AcpiOsAllocate (XsdtSize); + if (!LocalXSDT) + { + return (AE_NO_MEMORY); + } + + ACPI_MEMSET (LocalXSDT, 0, XsdtSize); + ACPI_STRNCPY (LocalXSDT->Header.Signature, ACPI_SIG_XSDT, 4); + LocalXSDT->Header.Length = XsdtSize; + LocalXSDT->Header.Revision = 1; + + LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalTEST); + LocalXSDT->TableOffsetEntry[1] = ACPI_PTR_TO_PHYSADDR (&LocalBADTABLE); + LocalXSDT->TableOffsetEntry[2] = ACPI_PTR_TO_PHYSADDR (&LocalFADT); + + /* Install two SSDTs to test multiple table support */ + + LocalXSDT->TableOffsetEntry[3] = ACPI_PTR_TO_PHYSADDR (&Ssdt1Code); + LocalXSDT->TableOffsetEntry[4] = ACPI_PTR_TO_PHYSADDR (&Ssdt2Code); + + /* Install the OEM1 table to test LoadTable */ + + LocalXSDT->TableOffsetEntry[5] = ACPI_PTR_TO_PHYSADDR (&Oem1Code); + + /* Install the OEMx table to test LoadTable */ + + LocalXSDT->TableOffsetEntry[6] = ACPI_PTR_TO_PHYSADDR (&OemxCode); + + /* Install the ECDT table to test _REG */ + + LocalXSDT->TableOffsetEntry[7] = ACPI_PTR_TO_PHYSADDR (&EcdtCode); + + /* + * Install the user tables. The DSDT must be installed in the FADT. + * All other tables are installed directly into the XSDT. + */ + NextIndex = BASE_XSDT_TABLES; + NextTable = TableList; + while (NextTable) + { + /* + * Incoming DSDT or FADT are special cases. All other tables are + * just immediately installed into the XSDT. + */ + if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT)) + { + if (DsdtAddress) + { + printf ("Already found a DSDT, only one allowed\n"); + return (AE_ALREADY_EXISTS); + } + + /* The incoming user table is a DSDT */ + + DsdtAddress = ACPI_PTR_TO_PHYSADDR (&DsdtCode); + DsdtToInstallOverride = NextTable->Table; + } + else if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT)) + { + ExternalFadt = ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table); + LocalXSDT->TableOffsetEntry[2] = ACPI_PTR_TO_PHYSADDR (NextTable->Table); + } + else + { + /* Install the table in the XSDT */ + + LocalXSDT->TableOffsetEntry[NextIndex] = ACPI_PTR_TO_PHYSADDR (NextTable->Table); + NextIndex++; + } + + NextTable = NextTable->Next; + } + + /* Build an RSDP */ + + ACPI_MEMSET (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP)); + ACPI_MEMCPY (LocalRSDP.Signature, ACPI_SIG_RSDP, 8); + ACPI_MEMCPY (LocalRSDP.OemId, "I_TEST", 6); + LocalRSDP.Revision = 2; + LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT); + LocalRSDP.Length = sizeof (ACPI_TABLE_XSDT); + + /* Set checksums for both XSDT and RSDP */ + + LocalXSDT->Header.Checksum = (UINT8) -AcpiTbChecksum ( + (void *) LocalXSDT, LocalXSDT->Header.Length); + LocalRSDP.Checksum = (UINT8) -AcpiTbChecksum ( + (void *) &LocalRSDP, ACPI_RSDP_CHECKSUM_LENGTH); + + if (!DsdtAddress) + { + /* Use the local DSDT because incoming table(s) are all SSDT(s) */ + + DsdtAddress = ACPI_PTR_TO_PHYSADDR (LocalDsdtCode); + DsdtToInstallOverride = ACPI_CAST_PTR (ACPI_TABLE_HEADER, LocalDsdtCode); + } + + if (ExternalFadt) + { + /* + * Use the external FADT, but we must update the DSDT/FACS addresses + * as well as the checksum + */ + ExternalFadt->Dsdt = DsdtAddress; + if (!AcpiGbl_ReducedHardware) + { + ExternalFadt->Facs = ACPI_PTR_TO_PHYSADDR (&LocalFACS); + } + + if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (&ExternalFadt->XDsdt, ExternalFadt)) + { + ExternalFadt->XDsdt = DsdtAddress; + + if (!AcpiGbl_ReducedHardware) + { + ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS); + } + } + + /* Complete the FADT with the checksum */ + + ExternalFadt->Header.Checksum = 0; + ExternalFadt->Header.Checksum = (UINT8) -AcpiTbChecksum ( + (void *) ExternalFadt, ExternalFadt->Header.Length); + } + else if (AcpiGbl_UseHwReducedFadt) + { + ACPI_MEMCPY (&LocalFADT, HwReducedFadtCode, sizeof (ACPI_TABLE_FADT)); + LocalFADT.Dsdt = DsdtAddress; + LocalFADT.XDsdt = DsdtAddress; + + LocalFADT.Header.Checksum = 0; + LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum ( + (void *) &LocalFADT, LocalFADT.Header.Length); + } + else + { + /* + * Build a local FADT so we can test the hardware/event init + */ + ACPI_MEMSET (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT)); + ACPI_STRNCPY (LocalFADT.Header.Signature, ACPI_SIG_FADT, 4); + + /* Setup FADT header and DSDT/FACS addresses */ + + LocalFADT.Dsdt = 0; + LocalFADT.Facs = 0; + + LocalFADT.XDsdt = DsdtAddress; + LocalFADT.XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS); + + LocalFADT.Header.Revision = 3; + LocalFADT.Header.Length = sizeof (ACPI_TABLE_FADT); + + /* Miscellaneous FADT fields */ + + LocalFADT.Gpe0BlockLength = 16; + LocalFADT.Gpe0Block = 0x00001234; + + LocalFADT.Gpe1BlockLength = 6; + LocalFADT.Gpe1Block = 0x00005678; + LocalFADT.Gpe1Base = 96; + + LocalFADT.Pm1EventLength = 4; + LocalFADT.Pm1aEventBlock = 0x00001aaa; + LocalFADT.Pm1bEventBlock = 0x00001bbb; + + LocalFADT.Pm1ControlLength = 2; + LocalFADT.Pm1aControlBlock = 0xB0; + + LocalFADT.PmTimerLength = 4; + LocalFADT.PmTimerBlock = 0xA0; + + LocalFADT.Pm2ControlBlock = 0xC0; + LocalFADT.Pm2ControlLength = 1; + + /* Setup one example X-64 field */ + + LocalFADT.XPm1bEventBlock.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO; + LocalFADT.XPm1bEventBlock.Address = LocalFADT.Pm1bEventBlock; + LocalFADT.XPm1bEventBlock.BitWidth = (UINT8) ACPI_MUL_8 (LocalFADT.Pm1EventLength); + + /* Complete the FADT with the checksum */ + + LocalFADT.Header.Checksum = 0; + LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum ( + (void *) &LocalFADT, LocalFADT.Header.Length); + } + + /* Build a FACS */ + + ACPI_MEMSET (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS)); + ACPI_STRNCPY (LocalFACS.Signature, ACPI_SIG_FACS, 4); + + LocalFACS.Length = sizeof (ACPI_TABLE_FACS); + LocalFACS.GlobalLock = 0x11AA0011; + + /* + * Build a fake table [TEST] so that we make sure that the + * ACPICA core ignores it + */ + ACPI_MEMSET (&LocalTEST, 0, sizeof (ACPI_TABLE_HEADER)); + ACPI_STRNCPY (LocalTEST.Signature, "TEST", 4); + + LocalTEST.Revision = 1; + LocalTEST.Length = sizeof (ACPI_TABLE_HEADER); + LocalTEST.Checksum = (UINT8) -AcpiTbChecksum ( + (void *) &LocalTEST, LocalTEST.Length); + + /* + * Build a fake table with a bad signature [BAD!] so that we make + * sure that the ACPICA core ignores it + */ + ACPI_MEMSET (&LocalBADTABLE, 0, sizeof (ACPI_TABLE_HEADER)); + ACPI_STRNCPY (LocalBADTABLE.Signature, "BAD!", 4); + + LocalBADTABLE.Revision = 1; + LocalBADTABLE.Length = sizeof (ACPI_TABLE_HEADER); + LocalBADTABLE.Checksum = (UINT8) -AcpiTbChecksum ( + (void *) &LocalBADTABLE, LocalBADTABLE.Length); + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AeInstallTables + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Install the various ACPI tables + * + *****************************************************************************/ + +ACPI_STATUS +AeInstallTables ( + void) +{ + ACPI_STATUS Status; + + + Status = AcpiInitializeTables (Tables, ACPI_MAX_INIT_TABLES, TRUE); + AE_CHECK_OK (AcpiInitializeTables, Status); + + Status = AcpiReallocateRootTable (); + AE_CHECK_OK (AcpiReallocateRootTable, Status); + + Status = AcpiLoadTables (); + AE_CHECK_OK (AcpiLoadTables, Status); + + /* + * Test run-time control method installation. Do it twice to test code + * for an existing name. + */ + Status = AcpiInstallMethod (MethodCode); + if (ACPI_FAILURE (Status)) + { + AcpiOsPrintf ("%s, Could not install method\n", + AcpiFormatException (Status)); + } + + Status = AcpiInstallMethod (MethodCode); + if (ACPI_FAILURE (Status)) + { + AcpiOsPrintf ("%s, Could not install method\n", + AcpiFormatException (Status)); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AeLocalGetRootPointer + * + * PARAMETERS: Flags - not used + * Address - Where the root pointer is returned + * + * RETURN: Status + * + * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the + * standard ACPI mechanism. + * + *****************************************************************************/ + +ACPI_PHYSICAL_ADDRESS +AeLocalGetRootPointer ( + void) +{ + + return ((ACPI_PHYSICAL_ADDRESS) &LocalRSDP); +} diff --git a/source/tools/acpiexec/aetables.h b/source/tools/acpiexec/aetables.h new file mode 100644 index 000000000000..16b3e896d699 --- /dev/null +++ b/source/tools/acpiexec/aetables.h @@ -0,0 +1,371 @@ +/****************************************************************************** + * + * Module Name: aetables.h - Precompiled AML ACPI tables for acpiexec + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#ifndef __AETABLES_H__ +#define __AETABLES_H__ + + +/* + * Miscellaneous pre-compiled AML ACPI tables to be installed + */ + +/* Default DSDT. This will be replaced with the input DSDT */ + +static unsigned char DsdtCode[] = +{ + 0x44,0x53,0x44,0x54,0x24,0x00,0x00,0x00, /* 00000000 "DSDT$..." */ + 0x02,0x6F,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 ".oIntel." */ + 0x4E,0x75,0x6C,0x6C,0x44,0x53,0x44,0x54, /* 00000010 "NullDSDT" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x04,0x12,0x08,0x20, +}; + +static unsigned char LocalDsdtCode[] = +{ + 0x44,0x53,0x44,0x54,0x24,0x00,0x00,0x00, /* 00000000 "DSDT$..." */ + 0x02,0x2C,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 ".,Intel." */ + 0x4C,0x6F,0x63,0x61,0x6C,0x00,0x00,0x00, /* 00000010 "Local..." */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x30,0x07,0x09,0x20, +}; + +/* Several example SSDTs */ + +static unsigned char Ssdt1Code[] = /* Has method _T98 */ +{ + 0x53,0x53,0x44,0x54,0x30,0x00,0x00,0x00, /* 00000000 "SSDT0..." */ + 0x01,0xB8,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 "..Intel." */ + 0x4D,0x61,0x6E,0x79,0x00,0x00,0x00,0x00, /* 00000010 "Many...." */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x24,0x04,0x03,0x20,0x14,0x0B,0x5F,0x54, /* 00000020 "$.. .._T" */ + 0x39,0x38,0x00,0x70,0x0A,0x04,0x60,0xA4, /* 00000028 "98.p..`." */ +}; + +static unsigned char Ssdt2Code[] = /* Has method _T99 */ +{ + 0x53,0x53,0x44,0x54,0x30,0x00,0x00,0x00, /* 00000000 "SSDT0..." */ + 0x01,0xB7,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 "..Intel." */ + 0x4D,0x61,0x6E,0x79,0x00,0x00,0x00,0x00, /* 00000010 "Many...." */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x24,0x04,0x03,0x20,0x14,0x0B,0x5F,0x54, /* 00000020 "$.. .._T" */ + 0x39,0x39,0x00,0x70,0x0A,0x04,0x60,0xA4, /* 00000028 "99.p..`." */ +}; + +unsigned char Ssdt3Code[] = /* OEM9: Has method _T97 */ +{ + 0x4F,0x45,0x4D,0x39,0x30,0x00,0x00,0x00, /* 00000000 "OEM10..." */ + 0x01,0xDD,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 "..Intel." */ + 0x4D,0x61,0x6E,0x79,0x00,0x00,0x00,0x00, /* 00000010 "Many...." */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x24,0x04,0x03,0x20,0x14,0x0B,0x5F,0x54, /* 00000020 "$.. .._T" */ + 0x39,0x37,0x00,0x70,0x0A,0x04,0x60,0xA4, /* 00000028 "97.p..`." */ +}; + +/* "Hardware-Reduced" ACPI 5.0 FADT (No FACS, no ACPI hardware) */ + +unsigned char HwReducedFadtCode[] = +{ + 0x46,0x41,0x43,0x50,0x0C,0x01,0x00,0x00, /* 00000000 "FACP...." */ + 0x05,0x8C,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x41,0x43,0x50,0x49,0x35,0x30,0x20,0x20, /* 00000010 "ACPI50 " */ + 0x00,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x13,0x04,0x11,0x20,0x00,0x00,0x00,0x00, /* 00000020 "... ...." */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000048 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000050 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000060 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000068 "........" */ + 0x00,0x00,0x78,0x00,0x01,0x08,0x00,0x01, /* 00000070 "..x....." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000078 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000080 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000088 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x20,0x00,0x02, /* 00000090 "..... .." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000098 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000A0 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x10,0x00,0x02, /* 000000A8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000B0 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000B8 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x08,0x00,0x00, /* 000000C0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000C8 "........" */ + 0x01,0x20,0x00,0x03,0x00,0x00,0x00,0x00, /* 000000D0 ". ......" */ + 0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x01, /* 000000D8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E0 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E8 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x08,0x00,0x01, /* 000000F0 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000F8 "........" */ + 0x01,0x08,0x00,0x01,0x01,0x00,0x00,0x00, /* 00000100 "........" */ + 0x00,0x00,0x00,0x00 /* 00000108 "........" */ +}; + +/* Example OEM table */ + +static unsigned char Oem1Code[] = +{ + 0x4F,0x45,0x4D,0x31,0x38,0x00,0x00,0x00, /* 00000000 "OEM18..." */ + 0x01,0x4B,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 ".KIntel." */ + 0x4D,0x61,0x6E,0x79,0x00,0x00,0x00,0x00, /* 00000010 "Many...." */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x18,0x09,0x03,0x20,0x08,0x5F,0x58,0x54, /* 00000020 "... ._XT" */ + 0x32,0x0A,0x04,0x14,0x0C,0x5F,0x58,0x54, /* 00000028 "2...._XT" */ + 0x31,0x00,0x70,0x01,0x5F,0x58,0x54,0x32, /* 00000030 "1.p._XT2" */ +}; + +/* ASL source for this table is at the end of this file */ + +static unsigned char OemxCode[] = +{ + 0x4F,0x45,0x4D,0x58,0xB0,0x00,0x00,0x00, /* 00000000 "OEMX...." */ + 0x02,0x54,0x4D,0x79,0x4F,0x45,0x4D,0x00, /* 00000008 ".TMyOEM." */ + 0x54,0x65,0x73,0x74,0x00,0x00,0x00,0x00, /* 00000010 "Test...." */ + 0x32,0x04,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "2...INTL" */ + 0x31,0x03,0x10,0x20,0x14,0x1D,0x5F,0x49, /* 00000020 "1.. .._I" */ + 0x4E,0x49,0x00,0x70,0x0D,0x54,0x61,0x62, /* 00000028 "NI.p.Tab" */ + 0x6C,0x65,0x20,0x4F,0x45,0x4D,0x58,0x20, /* 00000030 "le OEMX " */ + 0x72,0x75,0x6E,0x6E,0x69,0x6E,0x67,0x00, /* 00000038 "running." */ + 0x5B,0x31,0x10,0x22,0x5C,0x5F,0x47,0x50, /* 00000040 "[1."\_GP" */ + 0x45,0x14,0x06,0x5F,0x45,0x30,0x37,0x00, /* 00000048 "E.._E07." */ + 0x14,0x06,0x5F,0x45,0x32,0x32,0x00,0x14, /* 00000050 ".._E22.." */ + 0x06,0x5F,0x4C,0x33,0x31,0x00,0x14,0x06, /* 00000058 "._L31..." */ + 0x5F,0x4C,0x36,0x36,0x00,0x5B,0x82,0x10, /* 00000060 "_L66.[.." */ + 0x4F,0x45,0x4D,0x31,0x08,0x5F,0x50,0x52, /* 00000068 "OEM1._PR" */ + 0x57,0x12,0x05,0x02,0x0A,0x07,0x00,0x5B, /* 00000070 "W......[" */ + 0x82,0x10,0x4F,0x45,0x4D,0x32,0x08,0x5F, /* 00000078 "..OEM2._" */ + 0x50,0x52,0x57,0x12,0x05,0x02,0x0A,0x66, /* 00000080 "PRW....f" */ + 0x00,0x10,0x26,0x5C,0x47,0x50,0x45,0x32, /* 00000088 "..&\GPE2" */ + 0x14,0x06,0x5F,0x4C,0x30,0x31,0x00,0x14, /* 00000090 ".._L01.." */ + 0x06,0x5F,0x45,0x30,0x37,0x00,0x08,0x5F, /* 00000098 "._E07.._" */ + 0x50,0x52,0x57,0x12,0x0C,0x02,0x12,0x08, /* 000000A0 "PRW....." */ + 0x02,0x5C,0x47,0x50,0x45,0x32,0x01,0x00 /* 000000A8 ".\GPE2.." */ +}; + +/* Example ECDT */ + +unsigned char EcdtCode[] = +{ + 0x45,0x43,0x44,0x54,0x4E,0x00,0x00,0x00, /* 00000000 "ECDTN..." */ + 0x01,0x94,0x20,0x49,0x6E,0x74,0x65,0x6C, /* 00000008 ".. Intel" */ + 0x54,0x65,0x6D,0x70,0x6C,0x61,0x74,0x65, /* 00000010 "Template" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x16,0x03,0x11,0x20,0x01,0x08,0x00,0x00, /* 00000020 "... ...." */ + 0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "f......." */ + 0x01,0x08,0x00,0x00,0x62,0x00,0x00,0x00, /* 00000030 "....b..." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x09,0x5C,0x5F,0x53,0x42,0x2E,0x50,0x43, /* 00000040 ".\_SB.PC" */ + 0x49,0x30,0x2E,0x45,0x43,0x00 /* 00000048 "I0.EC." */ +}; + + +/* + * Example installable control method + * + * DefinitionBlock ("", "DSDT", 2, "Intel", "MTHDTEST", 0x20090512) + * { + * Method (\_SI_._T97, 1, Serialized) + * { + * Store ("Example installed method", Debug) + * Store (Arg0, Debug) + * Return () + * } + * } + * + * Compiled byte code below. + */ +static unsigned char MethodCode[] = +{ + 0x44,0x53,0x44,0x54,0x53,0x00,0x00,0x00, /* 00000000 "DSDTS..." */ + 0x02,0xF9,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 "..Intel." */ + 0x4D,0x54,0x48,0x44,0x54,0x45,0x53,0x54, /* 00000010 "MTHDTEST" */ + 0x12,0x05,0x09,0x20,0x49,0x4E,0x54,0x4C, /* 00000018 "... INTL" */ + 0x22,0x04,0x09,0x20,0x14,0x2E,0x2E,0x5F, /* 00000020 "".. ..._" */ + 0x54,0x49,0x5F,0x5F,0x54,0x39,0x37,0x09, /* 00000028 "SI__T97." */ + 0x70,0x0D,0x45,0x78,0x61,0x6D,0x70,0x6C, /* 00000030 "p.Exampl" */ + 0x65,0x20,0x69,0x6E,0x73,0x74,0x61,0x6C, /* 00000038 "e instal" */ + 0x6C,0x65,0x64,0x20,0x6D,0x65,0x74,0x68, /* 00000040 "led meth" */ + 0x6F,0x64,0x00,0x5B,0x31,0x70,0x68,0x5B, /* 00000048 "od.[1ph[" */ + 0x31,0xA4,0x00, +}; + + +#if 0 +/****************************************************************************** + * + * DESCRIPTION: ASL tables that are used in RSDT/XSDT, also used to test + * Load/LoadTable operators. + * + *****************************************************************************/ + +DefinitionBlock ("", "OEMX", 2, "MyOEM", "Test", 0x00000432) +{ + External (GPE2, DeviceObj) + + Method (_INI) + { + Store ("Table OEMX running", Debug) + } + + Scope (\_GPE) + { + Method (_E07) {} + Method (_E22) {} + Method (_L31) {} + Method (_L66) {} + } + + Device (OEM1) + { + Name (_PRW, Package(){7,0}) + } + Device (OEM2) + { + Name (_PRW, Package(){0x66,0}) + } + + Scope (\GPE2) + { + Method (_L01) {} + Method (_E07) {} + + Name (_PRW, Package() {Package() {\GPE2, 1}, 0}) + } +} + +/* Parent gr.asl file */ + +DefinitionBlock ("", "DSDT", 2, "Intel", "Many", 0x00000001) +{ + Name (BUF1, Buffer() + { + 0x4F,0x45,0x4D,0x58,0xB0,0x00,0x00,0x00, /* 00000000 "OEMX...." */ + 0x02,0x54,0x4D,0x79,0x4F,0x45,0x4D,0x00, /* 00000008 ".TMyOEM." */ + 0x54,0x65,0x73,0x74,0x00,0x00,0x00,0x00, /* 00000010 "Test...." */ + 0x32,0x04,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "2...INTL" */ + 0x31,0x03,0x10,0x20,0x14,0x1D,0x5F,0x49, /* 00000020 "1.. .._I" */ + 0x4E,0x49,0x00,0x70,0x0D,0x54,0x61,0x62, /* 00000028 "NI.p.Tab" */ + 0x6C,0x65,0x20,0x4F,0x45,0x4D,0x58,0x20, /* 00000030 "le OEMX " */ + 0x72,0x75,0x6E,0x6E,0x69,0x6E,0x67,0x00, /* 00000038 "running." */ + 0x5B,0x31,0x10,0x22,0x5C,0x5F,0x47,0x50, /* 00000040 "[1."\_GP" */ + 0x45,0x14,0x06,0x5F,0x45,0x30,0x37,0x00, /* 00000048 "E.._E07." */ + 0x14,0x06,0x5F,0x45,0x32,0x32,0x00,0x14, /* 00000050 ".._E22.." */ + 0x06,0x5F,0x4C,0x33,0x31,0x00,0x14,0x06, /* 00000058 "._L31..." */ + 0x5F,0x4C,0x36,0x36,0x00,0x5B,0x82,0x10, /* 00000060 "_L66.[.." */ + 0x4F,0x45,0x4D,0x31,0x08,0x5F,0x50,0x52, /* 00000068 "OEM1._PR" */ + 0x57,0x12,0x05,0x02,0x0A,0x07,0x00,0x5B, /* 00000070 "W......[" */ + 0x82,0x10,0x4F,0x45,0x4D,0x32,0x08,0x5F, /* 00000078 "..OEM2._" */ + 0x50,0x52,0x57,0x12,0x05,0x02,0x0A,0x66, /* 00000080 "PRW....f" */ + 0x00,0x10,0x26,0x5C,0x47,0x50,0x45,0x32, /* 00000088 "..&\GPE2" */ + 0x14,0x06,0x5F,0x4C,0x30,0x31,0x00,0x14, /* 00000090 ".._L01.." */ + 0x06,0x5F,0x45,0x30,0x37,0x00,0x08,0x5F, /* 00000098 "._E07.._" */ + 0x50,0x52,0x57,0x12,0x0C,0x02,0x12,0x08, /* 000000A0 "PRW....." */ + 0x02,0x5C,0x47,0x50,0x45,0x32,0x01,0x00 /* 000000A8 ".\GPE2.." */ + }) + + Name (HNDL, 0) + Method (LD) + { + Load (BUF1, HNDL) + Store ("Load operator, handle:", Debug) + Store (HNDL, Debug) + } + + Method (MAIN, 0, NotSerialized) + { + Store ("Loading OEMX table", Debug) + Store (LoadTable ("OEMX", "MyOEM", "Test"), Debug) + } + + Scope (\_GPE) + { + Method (_L08) {} + Method (_E08) {} + Method (_L0B) {} + } + + Device (DEV0) + { + Name (_PRW, Package() {0x11, 0}) + } + + Device (\GPE2) + { + Method (_L00) {} + } +} + +/* Example ECDT */ + +[000h 0000 4] Signature : "ECDT" /* Embedded Controller Boot Resources Table */ +[004h 0004 4] Table Length : 0000004E +[008h 0008 1] Revision : 01 +[009h 0009 1] Checksum : 14 +[00Ah 0010 6] Oem ID : " Intel" +[010h 0016 8] Oem Table ID : "Template" +[018h 0024 4] Oem Revision : 00000001 +[01Ch 0028 4] Asl Compiler ID : "INTL" +[020h 0032 4] Asl Compiler Revision : 20110316 + + +[024h 0036 12] Command/Status Register : <Generic Address Structure> +[024h 0036 1] Space ID : 01 (SystemIO) +[025h 0037 1] Bit Width : 08 +[026h 0038 1] Bit Offset : 00 +[027h 0039 1] Encoded Access Width : 00 (Undefined/Legacy) +[028h 0040 8] Address : 0000000000000066 + +[030h 0048 12] Data Register : <Generic Address Structure> +[030h 0048 1] Space ID : 01 (SystemIO) +[031h 0049 1] Bit Width : 08 +[032h 0050 1] Bit Offset : 00 +[033h 0051 1] Encoded Access Width : 00 (Undefined/Legacy) +[034h 0052 8] Address : 0000000000000062 + +[03Ch 0060 4] UID : 00000000 +[040h 0064 1] GPE Number : 09 +[041h 0065 13] Namepath : "\_SB.PCI0.EC" + +#endif + +#endif /* __AETABLES_H__ */ diff --git a/source/tools/acpihelp/Makefile b/source/tools/acpihelp/Makefile new file mode 100644 index 000000000000..481f9c2fa35f --- /dev/null +++ b/source/tools/acpihelp/Makefile @@ -0,0 +1,121 @@ +# +# acpihelp - ACPI Help utility. Displays ASL operator syntax and +# information about ACPI predefined names. +# +# NOTE: This makefile is intended to be used within the native +# ACPICA source tree. +# + +# +# Configuration +# Notes: +# gcc should be version 4 or greater, otherwise some of the options +# used will not be recognized. +# Global optimization flags (such as -O2, -Os) are not used, since +# they cause issues on some compilers. +# The _GNU_SOURCE symbol is required for many hosts. +# +PROG = acpihelp + +HOST = _LINUX +NOMAN = YES +COMPILE = $(CC) -c $(CFLAGS) $(CWARNINGFLAGS) -o$@ $< + +ACPICA_SRC = ../../../source +ACPICA_COMMON = $(ACPICA_SRC)/common +ACPICA_TOOLS = $(ACPICA_SRC)/tools +ACPICA_OSL = $(ACPICA_SRC)/os_specific/service_layers +ACPICA_CORE = $(ACPICA_SRC)/components +ACPICA_INCLUDE = $(ACPICA_SRC)/include +ACPICA_DEBUGGER = $(ACPICA_CORE)/debugger +ACPICA_DISASSEMBLER = $(ACPICA_CORE)/disassembler +ACPICA_DISPATCHER = $(ACPICA_CORE)/dispatcher +ACPICA_EVENTS = $(ACPICA_CORE)/events +ACPICA_EXECUTER = $(ACPICA_CORE)/executer +ACPICA_HARDWARE = $(ACPICA_CORE)/hardware +ACPICA_NAMESPACE = $(ACPICA_CORE)/namespace +ACPICA_PARSER = $(ACPICA_CORE)/parser +ACPICA_RESOURCES = $(ACPICA_CORE)/resources +ACPICA_TABLES = $(ACPICA_CORE)/tables +ACPICA_UTILITIES = $(ACPICA_CORE)/utilities +ACPIHELP = $(ACPICA_TOOLS)/acpihelp +INSTALLDIR = /usr/bin +INSTALLPROG = cp --remove-destination $(PROG) $(INSTALLDIR) + +ACPICA_HEADERS = \ + $(wildcard $(ACPICA_INCLUDE)/*.h) \ + $(wildcard $(ACPICA_INCLUDE)/platform/*.h) + +# +# Search paths for source files +# +vpath %.c \ + $(ACPIHELP) \ + $(ACPICA_COMMON) + +HEADERS = \ + $(wildcard $(ACPIHELP)/*.h) + +OBJECTS = \ + ahamlops.o \ + ahaslkey.o \ + ahaslops.o \ + ahdecode.o \ + ahpredef.o \ + ahmain.o \ + getopt.o + +CFLAGS+= \ + -D$(HOST) \ + -D_GNU_SOURCE \ + -DACPI_HELP_APP \ + -I$(ACPICA_INCLUDE) + +CWARNINGFLAGS = \ + -ansi \ + -Wall \ + -Wbad-function-cast \ + -Wdeclaration-after-statement \ + -Werror \ + -Wformat=2 \ + -Wmissing-declarations \ + -Wmissing-prototypes \ + -Wstrict-aliasing=0 \ + -Wstrict-prototypes \ + -Wswitch-default \ + -Wpointer-arith \ + -Wundef + +# +# gcc 4+ flags +# +CWARNINGFLAGS += \ + -Waddress \ + -Waggregate-return \ + -Wchar-subscripts \ + -Wempty-body \ + -Wlogical-op \ + -Wmissing-declarations \ + -Wmissing-field-initializers \ + -Wmissing-parameter-type \ + -Wnested-externs \ + -Wold-style-declaration \ + -Wold-style-definition \ + -Wredundant-decls \ + -Wtype-limits + +# +# Rules +# +$(PROG) : $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) -o $(PROG) + $(COPYPROG) + +%.o : %.c $(HEADERS) $(ACPICA_HEADERS) + $(COMPILE) + +clean : + rm -f $(PROG) $(PROG).exe $(OBJECTS) + +install : + $(INSTALLPROG) diff --git a/source/tools/acpihelp/acpihelp.h b/source/tools/acpihelp/acpihelp.h new file mode 100644 index 000000000000..427353a06b51 --- /dev/null +++ b/source/tools/acpihelp/acpihelp.h @@ -0,0 +1,156 @@ +/****************************************************************************** + * + * Module Name: acpihelp.h - Include file for AcpiHelp utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#ifndef __ACPIHELP_H +#define __ACPIHELP_H + + +#include "acpi.h" +#include "accommon.h" +#include "acapps.h" + +#include <stdio.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> +#include <ctype.h> +#include <string.h> +#ifdef WIN32 +#include <io.h> +#include <direct.h> +#endif +#include <errno.h> + + +#define AH_DECODE_DEFAULT 0 +#define AH_DECODE_ASL 1 +#define AH_DECODE_ASL_KEYWORD 2 +#define AH_DECODE_PREDEFINED_NAME 3 +#define AH_DECODE_AML 4 +#define AH_DECODE_AML_OPCODE 5 +#define AH_DISPLAY_DEVICE_IDS 6 + +#define AH_MAX_ASL_LINE_LENGTH 70 +#define AH_MAX_AML_LINE_LENGTH 100 + + +typedef struct ah_aml_opcode +{ + UINT16 OpcodeRangeStart; + UINT16 OpcodeRangeEnd; + char *OpcodeString; + char *OpcodeName; + char *Type; + char *FixedArguments; + char *VariableArguments; + char *Grammar; + +} AH_AML_OPCODE; + +typedef struct ah_asl_operator +{ + char *Name; + char *Syntax; + char *Description; + +} AH_ASL_OPERATOR; + +typedef struct ah_asl_keyword +{ + char *Name; + char *Description; + char *KeywordList; + +} AH_ASL_KEYWORD; + +typedef struct ah_predefined_name +{ + char *Name; + char *Description; + char *Action; + +} AH_PREDEFINED_NAME; + +typedef struct ah_device_id +{ + char *Name; + char *Description; + +} AH_DEVICE_ID; + + +extern const AH_AML_OPCODE AmlOpcodeInfo[]; +extern const AH_ASL_OPERATOR AslOperatorInfo[]; +extern const AH_ASL_KEYWORD AslKeywordInfo[]; +extern const AH_PREDEFINED_NAME AslPredefinedInfo[]; +extern BOOLEAN AhDisplayAll; + +void +AhStrupr ( + char *SrcString); + +void +AhFindAmlOpcode ( + char *Name); + +void +AhDecodeAmlOpcode ( + char *Name); + +void +AhFindPredefinedNames ( + char *Name); + +void +AhFindAslOperators ( + char *Name); + +void +AhFindAslKeywords ( + char *Name); + +void +AhDisplayDeviceIds ( + void); + +#endif /* __ACPIHELP_H */ diff --git a/source/tools/acpihelp/ahamlops.c b/source/tools/acpihelp/ahamlops.c new file mode 100644 index 000000000000..222eb3454df1 --- /dev/null +++ b/source/tools/acpihelp/ahamlops.c @@ -0,0 +1,325 @@ +/****************************************************************************** + * + * Module Name: ahamlops - Table of all known AML opcodes + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpihelp.h" + +/* + * AML opcodes with related syntax and grammar information. + * This table was extracted from the ACPI specification. + */ +const AH_AML_OPCODE AmlOpcodeInfo[] = +{ + {0x00, 0x00, "0x00", "ZeroOp", "DataObject", NULL, NULL, + NULL}, + {0x01, 0x01, "0x01", "OneOp", "DataObject", NULL, NULL, + NULL}, + {0x02, 0x05, "0x02-0x05", NULL, NULL, NULL, NULL, + NULL}, + {0x06, 0x06, "0x06", "AliasOp", "TermObject", "NameString NameString", NULL, + "DefAlias := AliasOp NameString NameString"}, + {0x07, 0x07, "0x07", NULL, NULL, NULL, NULL, + NULL}, + {0x08, 0x08, "0x08", "NameOp", "TermObject", "NameString DataRefObject", NULL, + "DefName := NameOp NameString DataRefObject"}, + {0x09, 0x09, "0x09", NULL, NULL, NULL, NULL, + NULL}, + {0x0A, 0x0A, "0x0A", "BytePrefix", "DataObject", "ByteData", NULL, + "ByteConst := BytePrefix ByteData"}, + {0x0B, 0x0B, "0x0B", "WordPrefix", "DataObject", "WordData", NULL, + "WordConst := WordPrefix WordData"}, + {0x0C, 0x0C, "0x0C", "DWordPrefix", "DataObject", "DWordData", NULL, + "DWordConst := DWordPrefix DWordData"}, + {0x0D, 0x0D, "0x0D", "StringPrefix", "DataObject", "AsciiCharList NullChar", NULL, + "String := StringPrefix AsciiCharList NullChar"}, + {0x0E, 0x0E, "0x0E", "QWordPrefix", "DataObject", "QWordData", NULL, + "QWordConst := QWordPrefix QWordData"}, + {0x0F, 0x0F, "0x0F", NULL, NULL, NULL, NULL, + NULL}, + {0x10, 0x10, "0x10", "ScopeOp", "TermObject", "NameString", "TermList", + "DefScope := ScopeOp PkgLength NameString TermList"}, + {0x11, 0x11, "0x11", "BufferOp", "TermObject", "TermArg", "ByteList", + "DefBuffer := BufferOp PkgLength BufferSize ByteList"}, + {0x12, 0x12, "0x12", "PackageOp", "TermObject", "ByteData", "Package TermList", + "DefPackage := PackageOp PkgLength NumElements PackageElementList"}, + {0x13, 0x13, "0x13", "VarPackageOp", "TermObject", "TermArg", "Package TermList", + "DefVarPackage := VarPackageOp PkgLength VarNumElements PackageElementList"}, + {0x14, 0x14, "0x14", "MethodOp", "TermObject", "NameString ByteData", "TermList", + "DefMethod := MethodOp PkgLength NameString MethodFlags TermList"}, + {0x15, 0x2D, "0x15-0x2D", NULL, NULL, NULL, NULL, + NULL}, + {0x2E, 0x2E, "0x2E", "DualNamePrefix", "NameObject", "NameSeg NameSeg", NULL, + "DualNamePath := DualNamePrefix NameSeg NameSeg"}, + {0x2F, 0x2F, "0x2F", "MultiNamePrefix", "NameObject", "ByteData NameSeg", NULL, + "MultiNamePath := MultiNamePrefix SegCount NameSeg(SegCount)"}, + {0x30, 0x39, "0x30-0x39", "DigitChar", "NameObject", NULL, NULL, + NULL}, + {0x3A, 0x40, "0x3A-0x40", NULL, NULL, NULL, NULL, + NULL}, + {0x41, 0x5A, "0x41-0x5A", "NameChar", "NameObject", NULL, NULL, + NULL}, + {0x5B, 0x5B, "0x5B", "ExtOpPrefix", "DataObject", "ByteData", NULL, + NULL}, + {0x5B00, 0x5B00, "0x5B00", NULL, NULL, NULL, NULL, + NULL}, + {0x5B01, 0x5B01, "0x5B01", "MutexOp", "TermObject", "NameString ByteData", NULL, + "DefMutex := MutexOp NameString SyncFlags"}, + {0x5B02, 0x5B02, "0x5B02", "EventOp", "TermObject", "NameString", NULL, + "DefEvent := EventOp NameString"}, + {0x5B12, 0x5B12, "0x5B12", "CondRefOfOp", "TermObject", "SuperName SuperName", NULL, + "DefCondRefOf := CondRefOfOp SuperName Target"}, + {0x5B13, 0x5B13, "0x5B13", "CreateFieldOp", "TermObject", "TermArg TermArg TermArg NameString", NULL, + "DefCreateField := CreateFieldOp SourceBuff BitIndex NumBits NameString"}, + {0x5B1F, 0x5B1F, "0x5B1F", "LoadTableOp", "TermObject", "TermArg TermArg TermArg TermArg TermArg TermArg", NULL, + "DefLoadTable := LoadTableOp TermArg TermArg TermArg TermArg TermArg TermArg"}, + {0x5B20, 0x5B20, "0x5B20", "LoadOp", "TermObject", "NameString SuperName", NULL, + "DefLoad := LoadOp NameString DDBHandleObject"}, + {0x5B21, 0x5B21, "0x5B21", "StallOp", "TermObject", "TermArg", NULL, + "DefStall := StallOp UsecTime"}, + {0x5B22, 0x5B22, "0x5B22", "SleepOp", "TermObject", "TermArg", NULL, + "DefSleep := SleepOp MsecTime"}, + {0x5B23, 0x5B23, "0x5B23", "AcquireOp", "TermObject", "SuperName WordData", NULL, + "DefAcquire := AcquireOp MutexObject Timeout"}, + {0x5B24, 0x5B24, "0x5B24", "SignalOp", "TermObject", "SuperName", NULL, + "DefSignal := SignalOp EventObject"}, + {0x5B25, 0x5B25, "0x5B25", "WaitOp", "TermObject", "SuperName TermArg", NULL, + "DefWait := WaitOp EventObject Operand"}, + {0x5B26, 0x5B26, "0x5B26", "ResetOp", "TermObject", "SuperName", NULL, + "DefReset := ResetOp EventObject"}, + {0x5B27, 0x5B27, "0x5B27", "ReleaseOp", "TermObject", "SuperName", NULL, + "DefRelease := ReleaseOp MutexObject"}, + {0x5B28, 0x5B28, "0x5B28", "FromBCDOp", "TermObject", "TermArg Target", NULL, + "DefFromBCD := FromBCDOp BCDValue Target"}, + {0x5B29, 0x5B29, "0x5B29", "ToBCD", "TermObject", "TermArg Target", NULL, + "DefToBCD := ToBCDOp Operand Target"}, + {0x5B2A, 0x5B2A, "0x5B2A", "UnloadOp", "TermObject", "SuperName", NULL, + "DefUnload := UnloadOp DDBHandleObject"}, + {0x5B30, 0x5B30, "0x5B30", "RevisionOp", "DataObject", NULL, NULL, + NULL}, + {0x5B31, 0x5B31, "0x5B31", "DebugOp", "DebugObject", NULL, NULL, + NULL}, + {0x5B32, 0x5B32, "0x5B32", "FatalOp", "TermObject", "ByteData DWordData TermArg", NULL, + "DefFatal := FatalOp FatalType FatalCode FatalArg"}, + {0x5B33, 0x5B33, "0x5B33", "TimerOp", "TermObject", NULL, NULL, + "DefTimer := TimerOp"}, + {0x5B80, 0x5B80, "0x5B80", "OpRegionOp", "TermObject", "NameString ByteData TermArg TermArg", NULL, + "DefOpRegion := OpRegionOp NameString RegionSpace RegionOffset RegionLen"}, + {0x5B81, 0x5B81, "0x5B81", "FieldOp", "TermObject", "NameString ByteData", "FieldList", + "DefField := FieldOp PkgLength NameString FieldFlags FieldList"}, + {0x5B82, 0x5B82, "0x5B82", "DeviceOp", "TermObject", "NameString", "ObjectList", + "DefDevice := DeviceOp PkgLength NameString ObjectList"}, + {0x5B83, 0x5B83, "0x5B83", "ProcessorOp", "TermObject", "NameString ByteData DWordData ByteData", "ObjectList", + "DefProcessor := ProcessorOp PkgLength NameString ProcID PblkAddr PblkLen ObjectList"}, + {0x5B84, 0x5B84, "0x5B84", "PowerResOp", "TermObject", "NameString ByteData WordData", "ObjectList", + "DefPowerRes := PowerResOp PkgLength NameString SystemLevel ResourceOrder ObjectList"}, + {0x5B85, 0x5B85, "0x5B85", "ThermalZoneOp", "TermObject", "NameString", "ObjectList", + "DefThermalZone := ThermalZoneOp PkgLength NameString ObjectList"}, + {0x5B86, 0x5B86, "0x5B86", "IndexFieldOp", "TermObject", "NameString NameString ByteData", "FieldList", + "DefIndexField := IndexFieldOp PkgLength NameString NameString FieldFlags FieldList"}, + {0x5B87, 0x5B87, "0x5B87", "BankFieldOp", "TermObject", "NameString NameString TermArg ByteData", "FieldList", + "DefBankField := BankFieldOp PkgLength NameString NameString BankValue FieldFlags FieldList"}, + {0x5B88, 0x5B88, "0x5B88", "DataRegionOp", "TermObject", "NameString TermArg TermArg TermArg", NULL, + "DefDataRegion := DataRegionOp NameString TermArg TermArg TermArg"}, + {0x5B89, 0x5BFF, "0x5B89-0x5BFF", NULL, NULL, NULL, NULL, + NULL}, + {0x5C, 0x5C, "0x5C", "RootChar", "NameObject", NULL, NULL, + NULL}, + {0x5D, 0x5D, "0x5D", NULL, NULL, NULL, NULL, + NULL}, + {0x5E, 0x5E, "0x5E", "ParentPrefixChar", "NameObject", NULL, NULL, + NULL}, + {0x5F, 0x5F, "0x5F", "NameChar", "NameObject", NULL, NULL, + NULL}, + {0x60, 0x60, "0x60", "Local0Op", "LocalObject", NULL, NULL, + NULL}, + {0x61, 0x61, "0x61", "Local1Op", "LocalObject", NULL, NULL, + NULL}, + {0x62, 0x62, "0x62", "Local2Op", "LocalObject", NULL, NULL, + NULL}, + {0x63, 0x63, "0x63", "Local3Op", "LocalObject", NULL, NULL, + NULL}, + {0x64, 0x64, "0x64", "Local4Op", "LocalObject", NULL, NULL, + NULL}, + {0x65, 0x65, "0x65", "Local5Op", "LocalObject", NULL, NULL, + NULL}, + {0x66, 0x66, "0x66", "Local6Op", "LocalObject", NULL, NULL, + NULL}, + {0x67, 0x67, "0x67", "Local7Op", "LocalObject", NULL, NULL, + NULL}, + {0x68, 0x68, "0x68", "Arg0Op", "ArgObject", NULL, NULL, + NULL}, + {0x69, 0x69, "0x69", "Arg1Op", "ArgObject", NULL, NULL, + NULL}, + {0x6A, 0x6A, "0x6A", "Arg2Op", "ArgObject", NULL, NULL, + NULL}, + {0x6B, 0x6B, "0x6B", "Arg3Op", "ArgObject", NULL, NULL, + NULL}, + {0x6C, 0x6C, "0x6C", "Arg4Op", "ArgObject", NULL, NULL, + NULL}, + {0x6D, 0x6D, "0x6D", "Arg5Op", "ArgObject", NULL, NULL, + NULL}, + {0x6E, 0x6E, "0x6E", "Arg6Op", "ArgObject", NULL, NULL, + NULL}, + {0x6F, 0x6F, "0x6F", NULL, NULL, NULL, NULL, + NULL}, + {0x70, 0x70, "0x70", "StoreOp", "TermObject", "TermArg SuperName", NULL, + "DefStore := StoreOp TermArg SuperName"}, + {0x71, 0x71, "0x71", "RefOfOp", "TermObject", "SuperName ", NULL, + "DefRefOf := RefOfOp SuperName"}, + {0x72, 0x72, "0x72", "AddOp", "TermObject", "TermArg TermArg Target", NULL, + "DefAdd := AddOp Operand Operand Target"}, + {0x73, 0x73, "0x73", "ConcatOp", "TermObject", "TermArg TermArg Target", NULL, + "DefConcat := ConcatOp Data Data Target"}, + {0x74, 0x74, "0x74", "SubtractOp", "TermObject", "TermArg TermArg Target", NULL, + "DefSubtract := SubtractOp Operand Operand Target"}, + {0x75, 0x75, "0x75", "IncrementOp", "TermObject", "SuperName", NULL, + "DefIncrement := IncrementOp SuperName"}, + {0x76, 0x76, "0x76", "DecrementOp", "TermObject", "SuperName", NULL, + "DefDecrement := DecrementOp SuperName"}, + {0x77, 0x77, "0x77", "MultiplyOp", "TermObject", "TermArg TermArg Target", NULL, + "DefMultiply := MultiplyOp Operand Operand Target"}, + {0x78, 0x78, "0x78", "DivideOp", "TermObject", "TermArg TermArg Target Target", NULL, + "DefDivide := DivideOp Dividend Divisor Remainder Quotient"}, + {0x79, 0x79, "0x79", "ShiftLeftOp", "TermObject", "TermArg TermArg Target", NULL, + "DefShiftLeft := ShiftLeftOp Operand ShiftCount Target"}, + {0x7A, 0x7A, "0x7A", "ShiftRightOp", "TermObject", "TermArg TermArg Target", NULL, + "DefShiftRight := ShiftRightOp Operand ShiftCount Target"}, + {0x7B, 0x7B, "0x7B", "AndOp", "TermObject", "TermArg TermArg Target", NULL, + "DefAnd := AndOp Operand Operand Target"}, + {0x7C, 0x7C, "0x7C", "NandOp", "TermObject", "TermArg TermArg Target", NULL, + "DefNAnd := NandOp Operand Operand Target"}, + {0x7D, 0x7D, "0x7D", "OrOp", "TermObject", "TermArg TermArg Target", NULL, + "DefOr := OrOp Operand Operand Target"}, + {0x7E, 0x7E, "0x7E", "NorOp", "TermObject", "TermArg TermArg Target", NULL, + "DefNOr := NorOp Operand Operand Target"}, + {0x7F, 0x7F, "0x7F", "XorOp", "TermObject", "TermArg TermArg Target", NULL, + "DefXOr := XorOp Operand Operand Target"}, + {0x80, 0x80, "0x80", "NotOp", "TermObject", "TermArg Target", NULL, + "DefNot := NotOp Operand Target"}, + {0x81, 0x81, "0x81", "FindSetLeftBitOp", "TermObject", "TermArg Target", NULL, + "DefFindSetLeftBit := FindSetLeftBitOp Operand Target"}, + {0x82, 0x82, "0x82", "FindSetRightBitOp", "TermObject", "TermArg Target", NULL, + "DefFindSetRightBit := FindSetRightBitOp Operand Target"}, + {0x83, 0x83, "0x83", "DerefOfOp", "TermObject", "TermArg", NULL, + "DefDerefOf := DerefOfOp ObjReference"}, + {0x84, 0x84, "0x84", "ConcatResOp", "TermObject", "TermArg TermArg Target", NULL, + "DefConcatRes := ConcatResOp BufData BufData Target"}, + {0x85, 0x85, "0x85", "ModOp", "TermObject", "TermArg TermArg Target", NULL, + "DefMod := ModOp Dividend Divisor Target"}, + {0x86, 0x86, "0x86", "NotifyOp", "TermObject", "SuperName TermArg", NULL, + "DefNotify := NotifyOp NotifyObject NotifyValue"}, + {0x87, 0x87, "0x87", "SizeOfOp", "TermObject", "SuperName", NULL, + "DefSizeOf := SizeOfOp SuperName"}, + {0x88, 0x88, "0x88", "IndexOp", "TermObject", "TermArg TermArg Target", NULL, + "DefIndex := IndexOp BuffPkgStrObj IndexValue Target"}, + {0x89, 0x89, "0x89", "MatchOp", "TermObject", "TermArg ByteData TermArg ByteData TermArg TermArg", NULL, + "DefMatch := MatchOp SearchPkg MatchOpcode Operand MatchOpcode Operand StartIndex"}, + {0x8A, 0x8A, "0x8A", "CreateDWordFieldOp", "TermObject", "TermArg TermArg NameString", NULL, + "DefCreateDWordField := CreateDWordFieldOp SourceBuff ByteIndex NameString"}, + {0x8B, 0x8B, "0x8B", "CreateWordFieldOp", "TermObject", "TermArg TermArg NameString", NULL, + "DefCreateWordField := CreateWordFieldOp SourceBuff ByteIndex NameString"}, + {0x8C, 0x8C, "0x8C", "CreateByteFieldOp", "TermObject", "TermArg TermArg NameString", NULL, + "DefCreateByteField := CreateByteFieldOp SourceBuff ByteIndex NameString"}, + {0x8D, 0x8D, "0x8D", "CreateBitFieldOp", "TermObject", "TermArg TermArg NameString", NULL, + "DefCreateBitField := CreateBitFieldOp SourceBuff BitIndex NameString"}, + {0x8E, 0x8E, "0x8E", "ObjectTypeOp", "TermObject", "SuperName", NULL, + "DefObjectType := ObjectTypeOp SuperName"}, + {0x8F, 0x8F, "0x8F", "CreateQWordFieldOp", "TermObject", "TermArg TermArg NameString", NULL, + "DefCreateQWordField := CreateQWordFieldOp SourceBuff ByteIndex NameString"}, + {0x90, 0x90, "0x90", "LAndOp", "TermObject", "TermArg TermArg", NULL, + "DefLAnd := LandOp Operand Operand"}, + {0x91, 0x91, "0x91", "LOrOp", "TermObject", "TermArg TermArg", NULL, + "DefLOr := LorOp Operand Operand"}, + {0x92, 0x92, "0x92", "LNotOp", "TermObject", "TermArg", NULL, + "DefLNot := LnotOp Operand"}, + {0x9293, 0x9293, "0x9293", "LNotEqualOp", "TermObject", "TermArg TermArg", NULL, + "DefLNotEqual := LnotEqualOp Operand Operand"}, + {0x9294, 0x9294, "0x9294", "LLessEqualOp", "TermObject", "TermArg TermArg", NULL, + "DefLLessEqual := LlessEqualOp Operand Operand"}, + {0x9295, 0x9295, "0x9295", "LGreaterEqualOp", "TermObject", "TermArg TermArg", NULL, + "DefLGreaterEqual := LgreaterEqualOp Operand Operand"}, + {0x93, 0x93, "0x93", "LEqualOp", "TermObject", "TermArg TermArg", NULL, + "DefLEqual := LequalOp Operand Operand"}, + {0x94, 0x94, "0x94", "LGreaterOp", "TermObject", "TermArg TermArg", NULL, + "DefLGreater := LgreaterOp Operand Operand"}, + {0x95, 0x95, "0x95", "LLessOp", "TermObject", "TermArg TermArg", NULL, + "DefLLess := LlessOp Operand Operand"}, + {0x96, 0x96, "0x96", "ToBufferOp", "TermObject", "TermArg Target", NULL, + "DefToBuffer := ToBufferOp Operand Target"}, + {0x97, 0x97, "0x97", "ToDecimalStringOp", "TermObject", "TermArg Target", NULL, + "DefToDecimalString := ToDecimalStringOp Operand Target"}, + {0x98, 0x98, "0x98", "ToHexStringOp", "TermObject", "TermArg Target", NULL, + "DefToHexString := ToHexStringOp Operand Target"}, + {0x99, 0x99, "0x99", "ToIntegerOp", "TermObject", "TermArg Target", NULL, + "DefToInteger := ToIntegerOp Operand Target"}, + {0x9A, 0x9B, "0x9A-0x9B", NULL, NULL, NULL, NULL, + NULL}, + {0x9C, 0x9C, "0x9C", "ToStringOp", "TermObject", "TermArg TermArg Target", NULL, + "DefToString := ToStringOp TermArg LengthArg Target"}, + {0x9D, 0x9D, "0x9D", "CopyObjectOp", "TermObject", "TermArg SimpleName", NULL, + "DefCopyObject := CopyObjectOp TermArg SimpleName"}, + {0x9E, 0x9E, "0x9E", "MidOp", "TermObject", "TermArg TermArg TermArg Target", NULL, + "DefMid := MidOp MidObj TermArg TermArg Target"}, + {0x9F, 0x9F, "0x9F", "ContinueOp", "TermObject", NULL, NULL, + "DefContinue := ContinueOp"}, + {0xA0, 0xA0, "0xA0", "IfOp", "TermObject", "TermArg", "TermList", + "DefIfElse := IfOp PkgLength Predicate TermList DefElse"}, + {0xA1, 0xA1, "0xA1", "ElseOp", "TermObject", NULL, "TermList", + "DefElse := Nothing | <ElseOp PkgLength TermList>"}, + {0xA2, 0xA2, "0xA2", "WhileOp", "TermObject", "TermArg", "TermList", + "DefWhile := WhileOp PkgLength Predicate TermList"}, + {0xA3, 0xA3, "0xA3", "NoopOp", "TermObject", NULL, NULL, + "DefNoop := NoopOp"}, + {0xA4, 0xA4, "0xA4", "ReturnOp", "TermObject", "TermArg", NULL, + "DefReturn := ReturnOp ArgObject"}, + {0xA5, 0xA5, "0xA5", "BreakOp", "TermObject", NULL, NULL, + "DefBreak := BreakOp"}, + {0xA6, 0xCB, "0xA6-0xCB", NULL, NULL, NULL, NULL, + NULL}, + {0xCC, 0xCC, "0xCC", "BreakPointOp", "TermObject", NULL, NULL, + "DefBreakPoint := BreakPointOp"}, + {0xCD, 0xFE, "0xCD-0xFE", NULL, NULL, NULL, NULL, + NULL}, + {0xFF, 0xFF, "0xFF", "OnesOp", "DataObject", NULL, NULL, + NULL}, + {0, 0, NULL, NULL, NULL, NULL, NULL, NULL} +}; diff --git a/source/tools/acpihelp/ahaslkey.c b/source/tools/acpihelp/ahaslkey.c new file mode 100644 index 000000000000..65adc5b44a77 --- /dev/null +++ b/source/tools/acpihelp/ahaslkey.c @@ -0,0 +1,149 @@ +/****************************************************************************** + * + * Module Name: ahaslkey - Table of all known ASL non-operator keywords + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpihelp.h" + +/* + * ASL Keyword types and associated actual keywords. + * This table was extracted from the ACPI specification. + */ +const AH_ASL_KEYWORD AslKeywordInfo[] = +{ + {"AccessAttribKeyword", "Serial Bus Attributes (with legacy SMBus aliases)", + ":= AttribQuick (SMBusQuick) | AttribSendReceive (SMBusSendReceive) | " + "AttribByte (SMBusByte) | AttribWord (SMBusWord) | " + "AttribBlock (SMBusBlock) | AttribProcessCall (SMBusProcessCall) | " + "AttribBlockProcessCall (SMBusProcessCall)"}, + {"AccessTypeKeyword", "Field Access Types", + ":= AnyAcc | ByteAcc | WordAcc | DWordAcc | QWordAcc | BufferAcc"}, + {"AddressingModeKeyword", "Mode - Resource Descriptors", + ":= AddressingMode7Bit | AddressingMode10Bit"}, + {"AddressKeyword", "ACPI memory range types", + ":= AddressRangeMemory | AddressRangeReserved | " + "AddressRangeNVS | AddressRangeACPI"}, + {"AddressSpaceKeyword", "Operation Region Address Space Types", + ":= RegionSpaceKeyword | FFixedHW"}, + {"BusMasterKeyword", "DMA Bus Mastering", + ":= BusMaster | NotBusMaster"}, + {"ByteLengthKeyword", "Bits per Byte - Resource Descriptors", + ":= DataBitsFive | DataBitsSix | DataBitsSeven | DataBitsEight | DataBitsNine"}, + {"ClockPhaseKeyword", "Resource Descriptors", + ":= ClockPhaseFirst | ClockPhaseSecond"}, + {"ClockPolarityKeyword", "Resource Descriptors", + ":= ClockPolarityLow | ClockPolarityHigh"}, + {"DecodeKeyword", "Type of Memory Decoding - Resource Descriptors", + ":= SubDecode | PosDecode"}, + {"DmaTypeKeyword", "DMA Types - DMA Resource Descriptor", + ":= Compatibility | TypeA | TypeB | TypeF"}, + {"EndianKeyword", "Endian type - Resource Descriptor", + ":= BigEndian | LittleEndian"}, + {"ExtendedAttribKeyword", "Extended Bus Attributes", + ":= AttribBytes (AccessLength) | AttribRawBytes (AccessLength) | " + "AttribRawProcessBytes (AccessLength)"}, + {"FlowControlKeyword", "Resource Descriptor", + ":= FlowControlNone | FlowControlXon | FlowControlHardware"}, + {"InterruptLevelKeyword", "Interrupt Active Types", + ":= ActiveHigh | ActiveLow | ActiveBoth"}, + {"InterruptTypeKeyword", "Interrupt Types", + ":= Edge | Level"}, + {"IoDecodeKeyword", "I/O Decoding - IO Resource Descriptor", + ":= Decode16 | Decode10"}, + {"IoRestrictionKeyword", "I/O Restriction - GPIO Resource Descriptors", + ":= IoRestrictionNone | IoRestrictionInputOnly | " + "IoRestrictionOutputOnly | IoRestrictionNoneAndPreserve"}, + {"LockRuleKeyword", "Global Lock use for Field Operator", + ":= Lock | NoLock"}, + {"MatchOpKeyword", "Types for Match Operator", + ":= MTR | MEQ | MLE | MLT | MGE | MGT"}, + {"MaxKeyword", "Max Range Type - Resource Descriptors", + ":= MaxFixed | MaxNotFixed"}, + {"MemTypeKeyword", "Memory Types - Resource Descriptors", + ":= Cacheable | WriteCombining | Prefetchable | NonCacheable"}, + {"MinKeyword", "Min Range Type - Resource Descriptors", + ":= MinFixed | MinNotFixed"}, + {"ObjectTypeKeyword", "ACPI Object Types", + ":= UnknownObj | IntObj | StrObj | BuffObj | PkgObj | FieldUnitObj | " + "DeviceObj | EventObj | MethodObj | MutexObj | OpRegionObj | PowerResObj | " + "ProcessorObj | ThermalZoneObj | BuffFieldObj | DDBHandleObj"}, + {"ParityKeyword", "Resource Descriptors", + ":= ParityTypeNone | ParityTypeSpace | ParityTypeMark | " + "ParityTypeOdd | ParityTypeEven"}, + {"PinConfigKeyword", "Pin Configuration - GPIO Resource Descriptors", + ":= PullDefault | PullUp | PullDown | PullNone"}, + {"PolarityKeyword", "Resource Descriptors", + ":= PolarityHigh | PolarityLow"}, + {"RangeTypeKeyword", "I/O Range Types - Resource Descriptors", + ":= ISAOnlyRanges | NonISAOnlyRanges | EntireRange"}, + {"ReadWriteKeyword", "Memory Access Types - Resource Descriptors", + ":= ReadWrite | ReadOnly"}, + {"RegionSpaceKeyword", "Operation Region Address Space Types", + ":= UserDefRegionSpace | SystemIO | SystemMemory | PCI_Config | " + "EmbeddedControl | SMBus | SystemCMOS | PciBarTarget | IPMI | " + "GeneralPurposeIo, GenericSerialBus"}, + {"ResourceTypeKeyword", "Resource Usage - Resource Descriptors", + ":= ResourceConsumer | ResourceProducer"}, + {"SerializeRuleKeyword", "Control Method Serialization", + ":= Serialized | NotSerialized"}, + {"ShareTypeKeyword", "Interrupt Sharing - Resource Descriptors", + ":= Shared | Exclusive | SharedAndWake | ExclusiveAndWake"}, + {"SlaveModeKeyword", "Resource Descriptors", + ":= ControllerInitiated | DeviceInitiated"}, + {"StopBitsKeyword", "Resource Descriptors", + ":= StopBitsZero | StopBitsOne | StopBitsOnePlusHalf | StopBitsTwo"}, + {"TransferWidthKeyword", "DMA Widths - Fixed DMA Resource Descriptor", + ":= Width8bit | Width16bit | Width32bit | Width64bit | " + "Width128bit | Width256bit"}, + {"TranslationKeyword", "Translation Density Types - Resource Descriptors", + ":= SparseTranslation | DenseTranslation"}, + {"TypeKeyword", "Translation Types - Resource Descriptors", + ":= TypeTranslation | TypeStatic"}, + {"UpdateRuleKeyword", "Field Update Rules", + ":= Preserve | WriteAsOnes | WriteAsZeros"}, + {"UserDefRegionSpace", "User defined address spaces", + ":= IntegerData => 0x80 - 0xFF"}, + {"WireModeKeyword", "SPI Wire Mode - Resource Descriptors", + ":= ThreeWireMode | FourWireMode"}, + {"XferTypeKeyword", "DMA Transfer Types", + ":= Transfer8 | Transfer16 | Transfer8_16"}, + {NULL, NULL, NULL} +}; diff --git a/source/tools/acpihelp/ahaslops.c b/source/tools/acpihelp/ahaslops.c new file mode 100644 index 000000000000..80ea1d2dcd03 --- /dev/null +++ b/source/tools/acpihelp/ahaslops.c @@ -0,0 +1,425 @@ +/****************************************************************************** + * + * Module Name: ahaslops - Table of all known ASL operators + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpihelp.h" + +/* + * ASL operators with syntax (directly from ACPI specification). + * Note: All tokens require a space separator. + * Long lines are automatically split during output. + */ +const AH_ASL_OPERATOR AslOperatorInfo[] = +{ + {"AccessAs", "(AccessType, AccessAttribKeyword | " + "ExtendedAttribKeyword (AccessLength))", + "ChangeFieldUnitAccess"}, + {"Acquire", "(SyncObject, TimeoutValue) => Boolean", + "Acquire a mutex"}, + {"Add", "(Addend1, Addend2, Result) => Integer", + "Integer Add"}, + {"Alias", "(SourceObject, AliasObject)", + "Define a name alias"}, + {"And", "(Source1, Source2, Result) => Integer", + "Integer Bitwise And"}, + {"Arg", "Arg0 - Arg6", + "Method argument data objects"}, + {"BankField", "(RegionName, BankName, BankValue, " + "AccessTypeKeyword, LockRuleKeyword, " + "UpdateRuleKeyword) {FieldUnitList}", + "Declare fields in a banked configuration object"}, + {"Break", "No parameters", + "Continue following the innermost enclosing While"}, + {"BreakPoint", "No parameters", + "Used for debugging, stops execution in the debugger"}, + {"Buffer", "(BufferSize) {String or ByteList} => Buffer", + "Declare Buffer object"}, + {"Case", "(Value) {TermList}", + "Expression for conditional execution"}, + {"Concatenate", "(Source1, Source2, Result) => ComputationalData", + "Concatenate two strings}, integers or buffers"}, + {"ConcatenateResTemplate", "(Source1, Source2, Result) => Buffer", + "Concatenate two resource templates"}, + {"CondRefOf", "(Source, Result) => Boolean", + "Conditional reference to an object"}, + {"Connection", "(ResourceMacro)", + "Associate connection with FieldUnits within a Field object"}, + {"Continue", "No parameters", + "Continue innermost enclosing While loop"}, + {"CopyObject", "(Source, Destination) => DataRefObject", + "Copy and existing object"}, + {"CreateBitField", "(SourceBuffer, BitIndex, BitFieldName)", + "Declare a bit field object of a buffer object"}, + {"CreateByteField", "(SourceBuffer, ByteIndex, ByteFieldName)", + "Declare a byte field object of a buffer object"}, + {"CreateDWordField", "(SourceBuffer, ByteIndex, DWordFieldName)", + "Declare a DWord field object of a buffer object"}, + {"CreateField", "(SourceBuffer, BitIndex, NumBits, FieldName)", + "Declare an arbitrary length bit field of a buffer object"}, + {"CreateQWordField", "(SourceBuffer, ByteIndex, QWordFieldName)", + "Declare a QWord field object of a buffer object"}, + {"CreateWordField", "(SourceBuffer, ByteIndex, WordFieldName)", + "Declare a Word field object of a buffer object"}, + {"DataTableRegion", "(RegionName, SignatureString, OemIDString, OemTableIDString)", + "Declare a Data Table Region"}, + {"Debug", "No parameters", + "Debugger output"}, + {"Decrement", "(Minuend) => Integer", + "Decrement an Integer"}, + {"Default", "{TermList}", + "Default execution path in Switch()"}, + {"DefinitionBlock", "(AMLFileName, TableSignature, ComplianceRevision, " + "OEMID, TableID, OEMRevision) {TermList}", + "Declare a Definition Block"}, + {"DerefOf", "(Source) => Object", + "Dereference an object reference"}, + {"Device", "(DeviceName) {ObjectList}", + "Declare a bus/device object"}, + {"Divide", "(Dividend, Divisor, Remainder, Result) => Integer", + "Integer Divide"}, + {"DMA", "(DmaTypeKeyword, BusMasterKeyword, XferTypeKeyword, " + "DescriptorName) {DmaChannelList} => Buffer", + "DMA Resource Descriptor macro"}, + {"DWordIO", "(ResourceTypeKeyword, MinKeyword, MaxKeyword, " + "DecodeKeyword, RangeTypeKeyword, AddressGranularity, " + "AddressMinimum, AddressMaximum, AddressTranslation, " + "RangeLength, ResourceSourceIndex, " + "ResourceSource, DescriptorName, TypeKeyword, TranslationKeyword)", + "DWord IO Resource Descriptor macro"}, + {"DWordMemory", "(ResourceTypeKeyword, DecodeKeyword, MinKeyword, " + "MaxKeyword, MemTypeKeyword, ReadWriteKeyword, " + "AddressGranularity, AddressMinimum, AddressMaximum, AddressTranslation, " + "RangeLength, ResourceSourceIndex, ResourceSource, DescriptorName, AddressKeyword, " + "TypeKeyword)", + "DWord Memory Resource Descriptor macro"}, + {"DWordSpace", "(ResourceType, ResourceTypeKeyword, DecodeKeyword, " + "MinKeyword, MaxKeyword, TypeSpecificFlags, " + "AddressGranularity, AddressMinimum, AddressMaximum, " + "AddressTranslation, RangeLength, " + "ResourceSourceIndex, ResourceSource, DescriptorName)", + "DWord Space Resource Descriptor macro"}, + {"EISAID", "(EisaIdString) => DWordConst", + "EISA ID String to Integer conversion macro"}, + {"Else", "{TermList}", + "Alternate conditional execution"}, + {"ElseIf", "(Predicate)", + "Conditional execution"}, + {"EndDependentFn", "() => Buffer", + "End Dependent Function Resource Descriptor macro"}, + {"Event", "(EventName)", + "Declare an event synchronization object"}, + {"ExtendedIO", "(ResourceTypeKeyword, MinKeyword, MaxKeyword, " + "DecodeKeyword, RangeTypeKeyword, AddressGranularity, " + "AddressMinimum, AddressMaximum, AddressTranslation, RangeLength, " + "TypeSpecificAttributes, DescriptorName, TypeKeyword, TranslationKeyword)", + "Extended IO Resource Descriptor macro"}, + {"ExtendedMemory", "(ResourceTypeKeyword, DecodeKeyword, MinKeyword, " + "MaxKeyword, MemTypeKeyword, ReadWriteKeyword, " + "AddressGranularity, AddressMinimum, AddressMaximum, AddressTranslation, " + "RangeLength, TypeSpecificAttributes, DescriptorName, " + "AddressKeyword, TypeKeyword)", + "Extended Memory Resource Descriptor macro"}, + {"ExtendedSpace", "(ResourceType, ResourceTypeKeyword, DecodeKeyword, " + "MinKeyword, MaxKeyword, TypeSpecificFlags, " + "AddressGranularity, AddressMinimum, AddressMaximum, AddressTranslation, " + "RangeLength, TypeSpecificAttributes, DescriptorName)", + "Extended Space Resource Descriptor macro"}, + {"External", "(ObjectName, ObjectTypeKeyword, ReturnType, ParameterTypes)", + "Declare external objects"}, + {"Fatal", "(Type, Code, Arg)", + "Fatal error check"}, + {"Field", "(RegionName, AccessTypeKeyword, LockRuleKeyword, " + "UpdateRuleKeyword) {FieldUnitList}", + "Declare fields of an operation region object"}, + {"FindSetLeftBit", "(Source, Result) => Integer", + "Index of first least significant bit set"}, + {"FindSetRightBit", "(Source, Result) => Integer", + "Index of first most significant bit set"}, + {"FixedDMA", "(DmaRequestLine, Channel, TransferWidthKeyword, DescriptorName) => Buffer", + "Fixed DMA Resource Descriptor macro"}, + {"FixedIO", "(AddressBase, RangeLength, DescriptorName) => Buffer", + "Fixed I/O Resource Descriptor macro"}, + {"FromBCD", "(BCDValue, Result) => Integer", + "Convert from BCD to numeric"}, + {"Function", "(FunctionName, ReturnType, ParameterTypes) {TermList}", + "Declare control method"}, + {"GpioInt", "(InterruptTypeKeyword, InterruptLevelKeyword, " + "ShareTypeKeyword, PinConfigKeyword, " + "DebounceTimeout, ResourceSource, " + "ResourceSourceIndex, ResourceTypeKeyword, DescriptorName, " + "RawDataBuffer() {VendorData}) {Pin}", + "GPIO Interrupt Connection Resource Descriptor Macro"}, + {"GpioIo", "(ShareTypeKeyword, PinConfigKeyword, DebounceTimeout, DriveStrength, " + "IoRestrictionKeyword, ResourceSource, " + "ResourceSourceIndex, ResourceTypeKeyword, DescriptorName, " + "RawDataBuffer() {VendorData}) {PinList}", + "GPIO I/O Connection Resource Descriptor Macro"}, + {"I2cSerialBus", "(SlaveAddress, SlaveModeKeyword, ConnectionSpeed, " + "AddressingModeKeyword, ResourceSource, " + "ResourceSourceIndex, ResourceTypeKeyword, DescriptorName, " + "RawDataBuffer() {VendorData})", + "I2C Serial Bus Connection Resource Descriptor Macro"}, + {"If", "(Predicate) {TermList}", + "Conditional execution"}, + {"Include", "(FilePathName)", + "Include another ASL file"}, + {"Increment", "(Addend) => Integer", + "Increment a Integer"}, + {"Index", "(Source, Index, Destination) => ObjectReference", + "Indexed Reference to member object"}, + {"IndexField", "(IndexName, DataName, AccessTypeKeyword, LockRuleKeyword, " + "UpdateRuleKeyword) {FieldUnitList}", + "Declare Index/Data Fields"}, + {"Interrupt", "(ResourceTypeKeyword, InterruptTypeKeyword, InterruptLevelKeyword, " + "ShareTypeKeyword, ResourceSourceIndex, " + "ResourceSource, DescriptorName) {InterruptList} => Buffer", + "Interrupt Resource Descriptor macro"}, + {"IO", "(IoDecodeKeyword, AddressMin, AddressMax, AddressAlignment, " + "RangeLength, DescriptorName) => Buffer", + "IO Resource Descriptor macro"}, + {"IRQ", "(InterruptTypeKeyword, InterruptLevelKeyword, ShareTypeKeyword, " + "DescriptorName) {InterruptList} => Buffer", + "Interrupt Resource Descriptor macro"}, + {"IRQNoFlags", "(DescriptorName) {InterruptList} => Buffer", + "Short Interrupt Resource Descriptor macro"}, + {"LAnd", "(Source1, Source2) => Boolean", + "Logical And"}, + {"LEqual", "(Source1, Source2) => Boolean", + "Logical Equal"}, + {"LGreater", "(Source1, Source2) => Boolean", + "Logical Greater"}, + {"LGreaterEqual", "(Source1, Source2) => Boolean", + "Logical Not less"}, + {"LLess", "(Source1, Source2) => Boolean", + "Logical Less"}, + {"LLessEqual", "(Source1, Source2) => Boolean", + "Logical Not greater"}, + {"LNot", "(Source) => Boolean", + "Logical Not"}, + {"LNotEqual", "(Source1, Source2) => Boolean", + "Logical Not equal"}, + {"Load", "(Object, DDBHandle)", + "Load differentiating definition block"}, + {"LoadTable", "(SignatureString, OEMIDString, OEMTableIDString, RootPathString, " + "ParameterPathString, ParameterData) => DDBHandle", + "Load Table from RSDT/XSDT"}, + {"Local", "Local0 - Local 7", + "Method local data objects"}, + {"LOr", "(Source1, Source2) => Boolean", + "Logical Or"}, + {"Match", "(SearchPackage, MatchOpKeyword, MatchObject1, MatchOpKeyword, " + "MatchObject2, StartIndex) => Ones | Integer", + "Search for match in package array"}, + {"Memory24", "(ReadWriteKeyword, AddressMinimum, AddressMaximum, AddressAlignment, " + "RangeLength, DescriptorName)", + "Memory Resource Descriptor macro"}, + {"Memory32", "(ReadWriteKeyword, AddressMinimum, AddressMaximum, AddressAlignment, " + "RangeLength, DescriptorName)", + "Memory Resource Descriptor macro"}, + {"Memory32Fixed", "(ReadWriteKeyword, AddressBase, RangeLength, DescriptorName)", + "Memory Resource Descriptor macro"}, + {"Method", "(MethodName, NumArgs, SerializeRuleKeyword, " + "SyncLevel, ReturnType, ParameterTypes) " + "{TermList}", + "Declare a control method"}, + {"Mid", "(Source, Index, Length, Result) => Buffer or String", + "Return a portion of buffer or string"}, + {"Mod", "(Dividend, Divisor, Result) => Integer", + "Integer Modulo"}, + {"Multiply", "(Multiplicand, Multiplier, Result) => Integer", + "Integer Multiply"}, + {"Mutex", "(MutexName, SyncLevel)", + "Declare a mutex synchronization object"}, + {"Name", "(ObjectName, Object)", + "Declare a Named object"}, + {"NAnd", "(Source1, Source2, Result) => Integer", + "Integer Bitwise Nand"}, + {"NoOp", "No parameters", + "No operation"}, + {"NOr", "(Source1, Source2, Result) => Integer", + "Integer Bitwise Nor"}, + {"Not", "(Source, Result) => Integer", + "Integer Bitwise Not"}, + {"Notify", "(Object, NotificationValue)", + "Notify Object of event"}, + {"ObjectType", "(Object) => Integer", + "Type of object"}, + {"Offset", "(ByteOffset)", + "Change Current Field Unit Offset"}, + {"One", "=> Integer", + "Constant One Object (1)"}, + {"Ones", "=> Integer", + "Constant Ones Object (-1)"}, + {"OperationRegion", "(RegionName, RegionSpaceKeyword, Offset, Length)", + "Declare an operational region"}, + {"Or", "(Source1, Source2, Result) => Integer", + "Integer Bitwise Or"}, + {"Package", "(NumElements) {PackageList} => Package", + "Declare a package object"}, + {"PowerResource", "(ResourceName, SystemLevel, ResourceOrder) {ObjectList}", + "Declare a power resource object"}, + {"Processor", "(ProcessorName, ProcessorID, PBlockAddress, PblockLength) {ObjectList}", + "Declare a processor package"}, + {"QWordIO", "(ResourceTypeKeyword, MinKeyword, MaxKeyword, DecodeKeyword, " + "RangeTypeKeyword, AddressGranularity, " + "AddressMinimum, AddressMaximum, AddressTranslation, RangeLength, " + "ResourceSourceIndex, ResourceSource, DescriptorName, TypeKeyword, " + "TranslationKeyword)", + "QWord IO Resource Descriptor macro"}, + {"QWordMemory", "(ResourceTypeKeyword, DecodeKeyword, MinKeyword, MaxKeyword, " + "MemTypeKeyword, ReadWriteKeyword, " + "AddressGranularity, AddressMinimum, AddressMaximum, AddressTranslation, " + "RangeLength, ResourceSourceIndex, ResourceSource, " + "DescriptorName, AddressKeyword, " + "TypeKeyword)", + "QWord Memory Resource Descriptor macro"}, + {"QWordSpace", "(ResourceType, ResourceTypeKeyword, DecodeKeyword, " + "MinKeyword, MaxKeyword, TypeSpecificFlags, " + "AddressGranularity, AddressMinimum, AddressMaximum, AddressTranslation, " + "RangeLength, ResourceSourceIndex, ResourceSource, DescriptorName)", + "Qword Space Resource Descriptor macro"}, + {"RawDataBuffer", "(BufferSize) {ByteList} => RawDataBuffer", + "Create a raw data buffer (does not use Buffer AML opcode)"}, + {"RefOf", "(Object) => ObjectReference", + "Create Reference to an object"}, + {"Register", "(AddressSpaceKeyword, RegisterBitWidth, " + "RegisterBitOffset, RegisterAddress, " + "AccessSize, DescriptorName)", + "Generic register Resource Descriptor macro"}, + {"Release", "(SyncObject)", + "Release a synchronization object"}, + {"Reset", "(SyncObject)", + "Reset a synchronization object"}, + {"ResourceTemplate", "() {ResourceMacroList} => Buffer", + "Resource to buffer conversion macro"}, + {"Return", "None | () | (ReturnArg)", + "Return from method execution"}, + {"Revision", "=> Integer", + "Constant revision object"}, + {"Scope", "(Location) {ObjectList}", + "Open named scope "}, + {"ShiftLeft", "(Source, ShiftCount, Result) => Integer", + "Integer shift value left"}, + {"ShiftRight", "(Source, ShiftCount, Result) => Integer", + "Integer shift value right"}, + {"Signal", "(SyncObject)", + "Signal a synchronization object"}, + {"SizeOf", "(ObjectName) => Integer", + "Get the size of a buffer}, string}, or package"}, + {"Sleep", "(MilliSeconds)", + "Sleep n milliseconds (yields the processor)"}, + {"SpiSerialBus", "(DeviceSelection, PolarityKeyword, WireModeKeyword, " + "DataBitLength, SlaveModeKeyword, " + "ConnectionSpeed, ClockPolarityKeyword, ClockPhaseKeyword, " + "ResourceSource, ResourceSourceIndex, " + "ResourceTypeKeyword, DescriptorName, RawDataBuffer() {VendorData})", + "SPI Serial Bus Connection Resource Descriptor Macro"}, + {"Stall", "(MicroSeconds)", + "Delay n microseconds (does not yield the processor)"}, + {"StartDependentFn", "(CompatibilityPriority, PerformancePriority) {ResourceList}", + "Start Dependent Function Resource Descriptor macro"}, + {"StartDependentFnNoPri", "() {ResourceList}", + "Start Dependent Function Resource Descriptor macro"}, + {"Store", "(Source, Destination) => DataRefObject", + "Store object"}, + {"Subtract", "(Minuend, Subtrahend, Result) => Integer", + "Integer Subtract"}, + {"Switch", "(Expression) {CaseTermList}", + "Select code to execute based on expression value"}, + {"ThermalZone", "(ThermalZoneName) {ObjectList}", + "Declare a thermal zone package"}, + {"Timer", "=> Integer", + "Get 64-bit timer value"}, + {"ToBCD", "(Value, Result) => Integer", + "Convert Integer to BCD"}, + {"ToBuffer", "(Data, Result) => Buffer", + "Convert data type to buffer"}, + {"ToDecimalString", "(Data, Result) => String", + "Convert data type to decimal string"}, + {"ToHexString", "(Data, Result) => String", + "Convert data type to hexadecimal string"}, + {"ToInteger", "(Data, Result) => Integer", + "Convert data type to integer"}, + {"ToString", "(Source, Length, Result) => String", + "Copy ASCII string from buffer"}, + {"ToUUID", "(AsciiString) => Buffer", + "Convert Ascii string to UUID"}, + {"UartSerialBus", "(ConnectionSpeed, ByteLengthKeyword, StopBitsKeyword, " + "LinesInUse, EndianKeyword, ParityKeyword, " + "FlowControlKeyword, ReceiveBufferSize, TransmitBufferSize, ResourceSource, " + "ResourceSourceIndex, ResourceTypeKeyword, DescriptorName, " + "RawDataBuffer() {VendorData})", + "UART Serial Bus Connection Resource Descriptor Macro"}, + {"Unicode", "(String) => Buffer", + "String to Unicode conversion macro"}, + {"Unload", "(Handle)", + "Unload definition block"}, + {"VendorLong", "(DescriptorName) {VendorByteList}", + "Vendor Resource Descriptor"}, + {"VendorShort", "(DescriptorName) {VendorByteList}", + "Vendor Resource Descriptor"}, + {"Wait", "(SyncObject, TimeoutValue) => Boolean", + "Wait on an Event"}, + {"While", "(Predicate) {TermList}", + "Conditional loop"}, + {"WordBusNumber", "(ResourceTypeKeyword, MinKeyword, MaxKeyword, DecodeKeyword, " + "AddressGranularity, AddressMinimum, " + "AddressMaximum, AddressTranslation, RangeLength, ResourceSourceIndex, " + "ResourceSource, DescriptorName)", + "Word Bus number Resource Descriptor macro"}, + {"WordIO", "(ResourceTypeKeyword, MinKeyword, MaxKeyword, DecodeKeyword, " + "RangeTypeKeyword, AddressGranularity, " + "AddressMinimum, AddressMaximum, AddressTranslation, RangeLength, " + "ResourceSourceIndex, ResourceSource, DescriptorName, TypeKeyword, " + "TranslationKeyword)", + "Word IO Resource Descriptor macro"}, + {"WordSpace", "(ResourceType, ResourceTypeKeyword, DecodeKeyword, MinKeyword, " + "MaxKeyword, TypeSpecificFlags, " + "AddressGranularity, AddressMinimum, AddressMaximum, AddressTranslation, " + "RangeLength, ResourceSourceIndex, ResourceSource, DescriptorName)", + "Word Space Resource Descriptor macro"}, + {"XOr", "(Source1, Source2, Result) => Integer", + "Integer Bitwise Xor"}, + {"Zero", "=> Integer", + "Constant Zero object (0)"}, + {NULL, NULL, NULL} +}; diff --git a/source/tools/acpihelp/ahdecode.c b/source/tools/acpihelp/ahdecode.c new file mode 100644 index 000000000000..a61eccfe0beb --- /dev/null +++ b/source/tools/acpihelp/ahdecode.c @@ -0,0 +1,855 @@ +/****************************************************************************** + * + * Module Name: ahdecode - Operator/Opcode decoding for acpihelp utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpihelp.h" + +#define ACPI_CREATE_PREDEFINED_TABLE +#include "acpredef.h" + +#define BUFFER_LENGTH 128 +#define LINE_BUFFER_LENGTH 512 + +static char Gbl_Buffer[BUFFER_LENGTH]; +static char Gbl_LineBuffer[LINE_BUFFER_LENGTH]; +static const char *AcpiRtypeNames[] = +{ + "/Integer", + "/String", + "/Buffer", + "/Package", + "/Reference", +}; + + +/* Local prototypes */ + +static BOOLEAN +AhDisplayPredefinedName ( + char *Name, + UINT32 Length); + +static void +AhDisplayPredefinedInfo ( + char *Name); + +static void +AhGetExpectedTypes ( + char *Buffer, + UINT32 ExpectedBtypes); + +static void +AhDisplayAmlOpcode ( + const AH_AML_OPCODE *Op); + +static void +AhDisplayAslOperator ( + const AH_ASL_OPERATOR *Op); + +static void +AhDisplayOperatorKeywords ( + const AH_ASL_OPERATOR *Op); + +static void +AhDisplayAslKeyword ( + const AH_ASL_KEYWORD *Op); + +static void +AhPrintOneField ( + UINT32 Indent, + UINT32 CurrentPosition, + UINT32 MaxPosition, + const char *Field); + + +/******************************************************************************* + * + * FUNCTION: AhFindPredefinedNames (entry point for predefined name search) + * + * PARAMETERS: NamePrefix - Name or prefix to find. Must start with + * an underscore. NULL means "find all" + * + * RETURN: None + * + * DESCRIPTION: Find and display all ACPI predefined names that match the + * input name or prefix. Includes the required number of arguments + * and the expected return type, if any. + * + ******************************************************************************/ + +void +AhFindPredefinedNames ( + char *NamePrefix) +{ + UINT32 Length; + BOOLEAN Found; + char Name[9]; + + + if (!NamePrefix) + { + Found = AhDisplayPredefinedName (Name, 0); + return; + } + + /* Contruct a local name or name prefix */ + + AhStrupr (NamePrefix); + if (*NamePrefix == '_') + { + NamePrefix++; + } + + Name[0] = '_'; + strncpy (&Name[1], NamePrefix, 7); + + Length = strlen (Name); + if (Length > 4) + { + printf ("%.8s: Predefined name must be 4 characters maximum\n", Name); + return; + } + + Found = AhDisplayPredefinedName (Name, Length); + if (!Found) + { + printf ("%s, no matching predefined names\n", Name); + } +} + + +/******************************************************************************* + * + * FUNCTION: AhDisplayPredefinedName + * + * PARAMETERS: Name - Name or name prefix + * + * RETURN: TRUE if any names matched, FALSE otherwise + * + * DESCRIPTION: Display information about ACPI predefined names that match + * the input name or name prefix. + * + ******************************************************************************/ + +static BOOLEAN +AhDisplayPredefinedName ( + char *Name, + UINT32 Length) +{ + const AH_PREDEFINED_NAME *Info; + BOOLEAN Found = FALSE; + BOOLEAN Matched; + UINT32 i; + + + /* Find/display all names that match the input name prefix */ + + for (Info = AslPredefinedInfo; Info->Name; Info++) + { + if (!Name) + { + Found = TRUE; + printf ("%s: <%s>\n", Info->Name, Info->Description); + printf ("%*s%s\n", 6, " ", Info->Action); + + AhDisplayPredefinedInfo (Info->Name); + continue; + } + + Matched = TRUE; + for (i = 0; i < Length; i++) + { + if (Info->Name[i] != Name[i]) + { + Matched = FALSE; + break; + } + } + + if (Matched) + { + Found = TRUE; + printf ("%s: <%s>\n", Info->Name, Info->Description); + printf ("%*s%s\n", 6, " ", Info->Action); + + AhDisplayPredefinedInfo (Info->Name); + } + } + + return (Found); +} + + +/******************************************************************************* + * + * FUNCTION: AhDisplayPredefinedInfo + * + * PARAMETERS: Name - Exact 4-character ACPI name. + * + * RETURN: None + * + * DESCRIPTION: Find the name in the main ACPICA predefined info table and + * display the # of arguments and the return value type. + * + * Note: Resource Descriptor field names do not appear in this + * table -- thus, nothing will be displayed for them. + * + ******************************************************************************/ + +static void +AhDisplayPredefinedInfo ( + char *Name) +{ + const ACPI_PREDEFINED_INFO *ThisName; + BOOLEAN Matched; + UINT32 i; + + + /* Find/display only the exact input name */ + + for (ThisName = PredefinedNames; ThisName->Info.Name[0]; ThisName++) + { + Matched = TRUE; + for (i = 0; i < ACPI_NAME_SIZE; i++) + { + if (ThisName->Info.Name[i] != Name[i]) + { + Matched = FALSE; + break; + } + } + + if (Matched) + { + AhGetExpectedTypes (Gbl_Buffer, ThisName->Info.ExpectedBtypes); + + printf ("%*s%4.4s has %u arguments, returns: %s\n", + 6, " ", ThisName->Info.Name, ThisName->Info.ParamCount, + ThisName->Info.ExpectedBtypes ? Gbl_Buffer : "-Nothing-"); + return; + } + + if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE) + { + ThisName++; + } + } +} + + +/******************************************************************************* + * + * FUNCTION: AhGetExpectedTypes + * + * PARAMETERS: Buffer - Where the formatted string is returned + * ExpectedBTypes - Bitfield of expected data types + * + * RETURN: Formatted string in Buffer. + * + * DESCRIPTION: Format the expected object types into a printable string. + * + ******************************************************************************/ + +static void +AhGetExpectedTypes ( + char *Buffer, + UINT32 ExpectedBtypes) +{ + UINT32 ThisRtype; + UINT32 i; + UINT32 j; + + + j = 1; + Buffer[0] = 0; + ThisRtype = ACPI_RTYPE_INTEGER; + + for (i = 0; i < ACPI_NUM_RTYPES; i++) + { + /* If one of the expected types, concatenate the name of this type */ + + if (ExpectedBtypes & ThisRtype) + { + strcat (Buffer, &AcpiRtypeNames[i][j]); + j = 0; /* Use name separator from now on */ + } + ThisRtype <<= 1; /* Next Rtype */ + } +} + + +/******************************************************************************* + * + * FUNCTION: AhFindAmlOpcode (entry point for AML opcode name search) + * + * PARAMETERS: Name - Name or prefix for an AML opcode. + * NULL means "find all" + * + * RETURN: None + * + * DESCRIPTION: Find all AML opcodes that match the input Name or name + * prefix. + * + ******************************************************************************/ + +void +AhFindAmlOpcode ( + char *Name) +{ + const AH_AML_OPCODE *Op; + BOOLEAN Found = FALSE; + + + AhStrupr (Name); + + /* Find/display all opcode names that match the input name prefix */ + + for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++) + { + if (!Op->OpcodeName) /* Unused opcodes */ + { + continue; + } + + if (!Name) + { + AhDisplayAmlOpcode (Op); + Found = TRUE; + continue; + } + + /* Upper case the opcode name before substring compare */ + + strcpy (Gbl_Buffer, Op->OpcodeName); + AhStrupr (Gbl_Buffer); + + if (strstr (Gbl_Buffer, Name) == Gbl_Buffer) + { + AhDisplayAmlOpcode (Op); + Found = TRUE; + } + } + + if (!Found) + { + printf ("%s, no matching AML operators\n", Name); + } +} + + +/******************************************************************************* + * + * FUNCTION: AhDecodeAmlOpcode (entry point for AML opcode search) + * + * PARAMETERS: OpcodeString - String version of AML opcode + * + * RETURN: None + * + * DESCRIPTION: Display information about the input AML opcode + * + ******************************************************************************/ + +void +AhDecodeAmlOpcode ( + char *OpcodeString) +{ + const AH_AML_OPCODE *Op; + UINT32 Opcode; + UINT8 Prefix; + + + if (!OpcodeString) + { + AhFindAmlOpcode (NULL); + return; + } + + Opcode = ACPI_STRTOUL (OpcodeString, NULL, 16); + if (Opcode > ACPI_UINT16_MAX) + { + printf ("Invalid opcode (more than 16 bits)\n"); + return; + } + + /* Only valid opcode extension is 0x5B */ + + Prefix = (Opcode & 0x0000FF00) >> 8; + if (Prefix && (Prefix != 0x5B)) + { + printf ("Invalid opcode (invalid extension prefix 0x%X)\n", + Prefix); + return; + } + + /* Find/Display the opcode. May fall within an opcode range */ + + for (Op = AmlOpcodeInfo; Op->OpcodeString; Op++) + { + if ((Opcode >= Op->OpcodeRangeStart) && + (Opcode <= Op->OpcodeRangeEnd)) + { + AhDisplayAmlOpcode (Op); + } + } +} + + +/******************************************************************************* + * + * FUNCTION: AhDisplayAmlOpcode + * + * PARAMETERS: Op - An opcode info struct + * + * RETURN: None + * + * DESCRIPTION: Display the contents of an AML opcode information struct + * + ******************************************************************************/ + +static void +AhDisplayAmlOpcode ( + const AH_AML_OPCODE *Op) +{ + + if (!Op->OpcodeName) + { + printf ("%18s: Opcode=%-9s\n", "Reserved opcode", Op->OpcodeString); + return; + } + + /* Opcode name and value(s) */ + + printf ("%18s: Opcode=%-9s Type (%s)", + Op->OpcodeName, Op->OpcodeString, Op->Type); + + /* Optional fixed/static arguments */ + + if (Op->FixedArguments) + { + printf (" FixedArgs ("); + AhPrintOneField (37, 36 + 7 + strlen (Op->Type) + 12, + AH_MAX_AML_LINE_LENGTH, Op->FixedArguments); + printf (")"); + } + + /* Optional variable-length argument list */ + + if (Op->VariableArguments) + { + if (Op->FixedArguments) + { + printf ("\n%*s", 36, " "); + } + printf (" VariableArgs ("); + AhPrintOneField (37, 15, AH_MAX_AML_LINE_LENGTH, Op->VariableArguments); + printf (")"); + } + printf ("\n"); + + /* Grammar specification */ + + if (Op->Grammar) + { + AhPrintOneField (37, 0, AH_MAX_AML_LINE_LENGTH, Op->Grammar); + printf ("\n"); + } +} + + +/******************************************************************************* + * + * FUNCTION: AhFindAslKeywords (entry point for ASL keyword search) + * + * PARAMETERS: Name - Name or prefix for an ASL keyword. + * NULL means "find all" + * + * RETURN: None + * + * DESCRIPTION: Find all ASL keywords that match the input Name or name + * prefix. + * + ******************************************************************************/ + +void +AhFindAslKeywords ( + char *Name) +{ + const AH_ASL_KEYWORD *Keyword; + BOOLEAN Found = FALSE; + + + AhStrupr (Name); + + for (Keyword = AslKeywordInfo; Keyword->Name; Keyword++) + { + if (!Name) + { + AhDisplayAslKeyword (Keyword); + Found = TRUE; + continue; + } + + /* Upper case the operator name before substring compare */ + + strcpy (Gbl_Buffer, Keyword->Name); + AhStrupr (Gbl_Buffer); + + if (strstr (Gbl_Buffer, Name) == Gbl_Buffer) + { + AhDisplayAslKeyword (Keyword); + Found = TRUE; + } + } + + if (!Found) + { + printf ("%s, no matching ASL keywords\n", Name); + } +} + + +/******************************************************************************* + * + * FUNCTION: AhDisplayAslKeyword + * + * PARAMETERS: Op - Pointer to ASL keyword with syntax info + * + * RETURN: None + * + * DESCRIPTION: Format and display syntax info for an ASL keyword. Splits + * long lines appropriately for reading. + * + ******************************************************************************/ + +static void +AhDisplayAslKeyword ( + const AH_ASL_KEYWORD *Op) +{ + + /* ASL keyword name and description */ + + printf ("%22s: %s\n", Op->Name, Op->Description); + if (!Op->KeywordList) + { + return; + } + + /* List of actual keywords */ + + AhPrintOneField (24, 0, AH_MAX_ASL_LINE_LENGTH, Op->KeywordList); + printf ("\n"); +} + + +/******************************************************************************* + * + * FUNCTION: AhFindAslOperators (entry point for ASL operator search) + * + * PARAMETERS: Name - Name or prefix for an ASL operator. + * NULL means "find all" + * + * RETURN: None + * + * DESCRIPTION: Find all ASL operators that match the input Name or name + * prefix. + * + ******************************************************************************/ + +void +AhFindAslOperators ( + char *Name) +{ + const AH_ASL_OPERATOR *Operator; + BOOLEAN Found = FALSE; + + + AhStrupr (Name); + + /* Find/display all names that match the input name prefix */ + + for (Operator = AslOperatorInfo; Operator->Name; Operator++) + { + if (!Name) + { + AhDisplayAslOperator (Operator); + Found = TRUE; + continue; + } + + /* Upper case the operator name before substring compare */ + + strcpy (Gbl_Buffer, Operator->Name); + AhStrupr (Gbl_Buffer); + + if (strstr (Gbl_Buffer, Name) == Gbl_Buffer) + { + AhDisplayAslOperator (Operator); + Found = TRUE; + } + } + + if (!Found) + { + printf ("%s, no matching ASL operators\n", Name); + } +} + + +/******************************************************************************* + * + * FUNCTION: AhDisplayAslOperator + * + * PARAMETERS: Op - Pointer to ASL operator with syntax info + * + * RETURN: None + * + * DESCRIPTION: Format and display syntax info for an ASL operator. Splits + * long lines appropriately for reading. + * + ******************************************************************************/ + +static void +AhDisplayAslOperator ( + const AH_ASL_OPERATOR *Op) +{ + + /* ASL operator name and description */ + + printf ("%16s: %s\n", Op->Name, Op->Description); + if (!Op->Syntax) + { + return; + } + + /* Syntax for the operator */ + + AhPrintOneField (18, 0, AH_MAX_ASL_LINE_LENGTH, Op->Syntax); + printf ("\n"); + + AhDisplayOperatorKeywords (Op); + printf ("\n"); +} + + +/******************************************************************************* + * + * FUNCTION: AhDisplayOperatorKeywords + * + * PARAMETERS: Op - Pointer to ASL keyword with syntax info + * + * RETURN: None + * + * DESCRIPTION: Display any/all keywords that are associated with the ASL + * operator. + * + ******************************************************************************/ + +static void +AhDisplayOperatorKeywords ( + const AH_ASL_OPERATOR *Op) +{ + char *Token; + char *Separators = "(){}, "; + BOOLEAN FirstKeyword = TRUE; + + + if (!Op || !Op->Syntax) + { + return; + } + + /* + * Find all parameters that have the word "keyword" within, and then + * display the info about that keyword + */ + strcpy (Gbl_LineBuffer, Op->Syntax); + Token = strtok (Gbl_LineBuffer, Separators); + while (Token) + { + if (strstr (Token, "Keyword")) + { + if (FirstKeyword) + { + printf ("\n"); + FirstKeyword = FALSE; + } + + /* Found a keyword, display keyword information */ + + AhFindAslKeywords (Token); + } + + Token = strtok (NULL, Separators); + } +} + + +/******************************************************************************* + * + * FUNCTION: AhPrintOneField + * + * PARAMETERS: Indent - Indent length for new line(s) + * CurrentPosition - Position on current line + * MaxPosition - Max allowed line length + * Field - Data to output + * + * RETURN: Line position after field is written + * + * DESCRIPTION: Split long lines appropriately for ease of reading. + * + ******************************************************************************/ + +static void +AhPrintOneField ( + UINT32 Indent, + UINT32 CurrentPosition, + UINT32 MaxPosition, + const char *Field) +{ + UINT32 Position; + UINT32 TokenLength; + const char *This; + const char *Next; + const char *Last; + + + This = Field; + Position = CurrentPosition; + + if (Position == 0) + { + printf ("%*s", (int) Indent, " "); + Position = Indent; + } + + Last = This + strlen (This); + while ((Next = strpbrk (This, " "))) + { + TokenLength = Next - This; + Position += TokenLength; + + /* Split long lines */ + + if (Position > MaxPosition) + { + printf ("\n%*s", (int) Indent, " "); + Position = TokenLength; + } + + printf ("%.*s ", (int) TokenLength, This); + This = Next + 1; + } + + /* Handle last token on the input line */ + + TokenLength = Last - This; + if (TokenLength > 0) + { + Position += TokenLength; + if (Position > MaxPosition) + { + printf ("\n%*s", (int) Indent, " "); + } + printf ("%s", This); + } +} + + +/******************************************************************************* + * + * FUNCTION: AhDisplayDeviceIds + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Display all PNP* and ACPI* device IDs defined in the ACPI spec. + * + ******************************************************************************/ + +static const AH_DEVICE_ID AhDeviceIds[] = +{ + {"PNP0A05", "Generic Container Device"}, + {"PNP0A06", "Generic Container Device"}, + {"PNP0C08", "ACPI core hardware"}, + {"PNP0C09", "Embedded Controller Device"}, + {"PNP0C0A", "Control Method Battery"}, + {"PNP0C0B", "Fan"}, + {"PNP0C0C", "Power Button Device"}, + {"PNP0C0D", "Lid Device"}, + {"PNP0C0E", "Sleep Button Device"}, + {"PNP0C0F", "PCI Interrupt Link Device"}, + {"PNP0C80", "Memory Device"}, + + {"ACPI0001", "SMBus 1.0 Host Controller"}, + {"ACPI0002", "Smart Battery Subsystem"}, + {"ACPI0003", "Power Source Device"}, + {"ACPI0004", "Module Device"}, + {"ACPI0005", "SMBus 2.0 Host Controller"}, + {"ACPI0006", "GPE Block Device"}, + {"ACPI0007", "Processor Device"}, + {"ACPI0008", "Ambient Light Sensor Device"}, + {"ACPI0009", "I/O xAPIC Device"}, + {"ACPI000A", "I/O APIC Device"}, + {"ACPI000B", "I/O SAPIC Device"}, + {"ACPI000C", "Processor Aggregator Device"}, + {"ACPI000D", "Power Meter Device"}, + {"ACPI000E", "Time/Alarm Device"}, + {"ACPI000F", "User Presence Detection Device"}, + + {NULL, NULL} +}; + +void +AhDisplayDeviceIds ( + void) +{ + const AH_DEVICE_ID *DeviceId = AhDeviceIds; + + + printf ("ACPI and PNP Device IDs defined in the ACPI specification:\n\n"); + while (DeviceId->Name) + { + printf ("%8s %s\n", DeviceId->Name, DeviceId->Description); + DeviceId++; + } +} diff --git a/source/tools/acpihelp/ahmain.c b/source/tools/acpihelp/ahmain.c new file mode 100644 index 000000000000..e45a0b61a4e5 --- /dev/null +++ b/source/tools/acpihelp/ahmain.c @@ -0,0 +1,229 @@ +/****************************************************************************** + * + * Module Name: ahmain - Main module for the acpi help utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpihelp.h" + + +/* Local prototypes */ + +static void +AhDisplayUsage ( + void); + + +/****************************************************************************** + * + * FUNCTION: AhDisplayUsage + * + * DESCRIPTION: Usage message + * + ******************************************************************************/ + +static void +AhDisplayUsage ( + void) +{ + + ACPI_USAGE_HEADER ("acpihelp <options> [NamePrefix | HexValue]"); + ACPI_OPTION ("-h", "Display help"); + ACPI_OPTION ("-i", "Display known ACPI Device IDs (_HID)"); + ACPI_OPTION ("-k [NamePrefix]", "Find/Display ASL non-operator keyword(s)"); + ACPI_OPTION ("-m [NamePrefix]", "Find/Display AML opcode name(s)"); + ACPI_OPTION ("-o [HexValue]", "Decode hex AML opcode"); + ACPI_OPTION ("-p [NamePrefix]", "Find/Display ASL predefined method name(s)"); + ACPI_OPTION ("-s [NamePrefix]", "Find/Display ASL operator name(s)"); + printf ("\nNamePrefix/HexValue not specified means \"Display All\"\n"); + printf ("\nDefault search with NamePrefix and no options:\n"); + printf (" Find ASL operator names - if NamePrefix does not start with underscore\n"); + printf (" Find ASL predefined method names - if NamePrefix starts with underscore\n"); +} + + +/****************************************************************************** + * + * FUNCTION: main + * + * DESCRIPTION: C main function for AcpiHelp utility. + * + ******************************************************************************/ + +int ACPI_SYSTEM_XFACE +main ( + int argc, + char *argv[]) +{ + char *Name; + UINT32 DecodeType; + int j; + + + printf (ACPI_COMMON_SIGNON ("ACPI Help Utility")); + DecodeType = AH_DECODE_DEFAULT; + + if (argc < 2) + { + AhDisplayUsage (); + return (0); + } + + /* Command line options */ + + while ((j = AcpiGetopt (argc, argv, "hikmops")) != EOF) switch (j) + { + case 'i': + DecodeType = AH_DISPLAY_DEVICE_IDS; + break; + + case 'k': + DecodeType = AH_DECODE_ASL_KEYWORD; + break; + + case 'm': + DecodeType = AH_DECODE_AML; + break; + + case 'o': + DecodeType = AH_DECODE_AML_OPCODE; + break; + + case 'p': + DecodeType = AH_DECODE_PREDEFINED_NAME; + break; + + case 's': + DecodeType = AH_DECODE_ASL; + break; + + case 'h': + default: + AhDisplayUsage (); + return (-1); + } + + /* Missing (null) name means "display all" */ + + Name = argv[AcpiGbl_Optind]; + + switch (DecodeType) + { + case AH_DECODE_AML: + AhFindAmlOpcode (Name); + break; + + case AH_DECODE_AML_OPCODE: + AhDecodeAmlOpcode (Name); + break; + + case AH_DECODE_PREDEFINED_NAME: + AhFindPredefinedNames (Name); + break; + + case AH_DECODE_ASL: + AhFindAslOperators (Name); + break; + + case AH_DECODE_ASL_KEYWORD: + AhFindAslKeywords (Name); + break; + + case AH_DISPLAY_DEVICE_IDS: + AhDisplayDeviceIds (); + break; + + default: + if (!Name) + { + AhFindAslOperators (Name); + break; + } + + if (*Name == '_') + { + AhFindPredefinedNames (Name); + } + else + { + AhFindAslOperators (Name); + } + break; + } + + return (0); +} + + +/******************************************************************************* + * + * FUNCTION: AhStrupr (strupr) + * + * PARAMETERS: SrcString - The source string to convert + * + * RETURN: None + * + * DESCRIPTION: Convert string to uppercase + * + * NOTE: This is not a POSIX function, so it appears here, not in utclib.c + * + ******************************************************************************/ + +void +AhStrupr ( + char *SrcString) +{ + char *String; + + + if (!SrcString) + { + return; + } + + /* Walk entire string, uppercasing the letters */ + + for (String = SrcString; *String; String++) + { + *String = (char) toupper ((int) *String); + } + + return; +} diff --git a/source/tools/acpihelp/ahpredef.c b/source/tools/acpihelp/ahpredef.c new file mode 100644 index 000000000000..2baf711ab8f5 --- /dev/null +++ b/source/tools/acpihelp/ahpredef.c @@ -0,0 +1,312 @@ +/****************************************************************************** + * + * Module Name: ahpredef - Table of all known ACPI predefined names + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpihelp.h" + +/* + * Predefined ACPI names, with short description and return value. + * This table was extracted directly from the ACPI specification. + */ +const AH_PREDEFINED_NAME AslPredefinedInfo[] = +{ + {"_ACx", "Active Cooling", "Returns the active cooling policy threshold values"}, + {"_ADR", "Address", "Returns the address of a device on its parent bus"}, + {"_AEI", "ACPI Event Interrupts", "Returns a list of GPIO events to be used as ACPI events"}, + {"_ALC", "Ambient Light Chromaticity", "Returns the ambient light color chromaticity"}, + {"_ALI", "Ambient Light Illuminance", "Returns the ambient light brightness"}, + {"_ALN", "Alignment", "Base alignment, Resource Descriptor field"}, + {"_ALP", "Ambient Light Polling", "Returns the ambient light sensor polling frequency"}, + {"_ALR", "Ambient Light Response", "Returns the ambient light brightness to display brightness mappings"}, + {"_ALT", "Ambient Light Temperature", "Returns the ambient light color temperature"}, + {"_ALx", "Active List", "Returns a list of active cooling device objects"}, + {"_ART", "Active cooling Relationship Table", "Returns thermal relationship information between platform devices and fan devices"}, + {"_ASI", "Address Space Id", "Resource Descriptor field"}, + {"_ASZ", "Access Size", "Resource Descriptor field"}, + {"_ATT", "Type-Specific Attribute", "Resource Descriptor field"}, + {"_BAS", "Base Address", "Range base address, Resource Descriptor field"}, + {"_BBN", "Bios Bus Number", "Returns the PCI bus number returned by the BIOS"}, + {"_BCL", "Brightness Control Levels", "Returns a list of supported brightness control levels"}, + {"_BCM", "Brightness Control Method", "Sets the brightness level of the display device"}, + {"_BCT", "Battery Charge Time", "Returns time remaining to complete charging battery"}, + {"_BDN", "Bios Dock Name", "Returns the Dock ID returned by the BIOS"}, + {"_BFS", "Back From Sleep", "Inform AML of a wake event"}, + {"_BIF", "Battery Information", "Returns a Control Method Battery information block"}, + {"_BIX", "Battery Information Extended", "Returns a Control Method Battery extended information block"}, + {"_BLT", "Battery Level Threshold", "Set battery level threshold preferences"}, + {"_BM_", "Bus Master", "Resource Descriptor field"}, + {"_BMA", "Battery Measurement Averaging Interval", "Sets battery measurement averaging interval"}, + {"_BMC", "Battery Maintenance Control", "Sets battery maintenance and control features"}, + {"_BMD", "Battery Maintenance Data", "Returns battery maintenance, control, and state data"}, + {"_BMS", "Battery Measurement Sampling Time", "Sets the battery measurement sampling time"}, + {"_BQC", "Brightness Query Current", "Returns the current display brightness level"}, + {"_BST", "Battery Status", "Returns a Control Method Battery status block"}, + {"_BTM", "Battery Time", "Returns the battery runtime"}, + {"_BTP", "Battery Trip Point", "Sets a Control Method Battery trip point"}, + {"_CBA", "Configuration Base Address", "Sets the CBA for a PCI Express host bridge"}, + {"_CDM", "Clock Domain", "Returns a logical processor's clock domain identifier"}, + {"_CID", "Compatible ID", "Returns a device's Plug and Play Compatible ID list"}, + {"_CLS", "Class Code", "Returns PCI class code and subclass"}, + {"_CPC", "Continuous Performance Control", "Returns a list of performance control interfaces"}, + {"_CRS", "Current Resource Settings", "Returns the current resource settings for a device"}, + {"_CRT", "Critical Temperature", "Returns the shutdown critical temperature"}, + {"_CSD", "C State Dependencies", "Returns a list of C-state dependencies"}, + {"_CST", "C States", "Returns a list of supported C-states"}, + {"_CWS", "Clear Wake Alarm Status", "Clear the status of wake alarms"}, + {"_DBT", "Debounce Timeout", "Timeout value, Resource Descriptor field"}, + {"_DCK", "Dock", "Sets docking isolation. Presence indicates device is a docking station"}, + {"_DCS", "Display Current Status", "Returns status of the display output device"}, + {"_DDC", "Display Data Current", "Returns the EDID for the display output device"}, + {"_DDN", "Dos Device Name", "Returns a device logical name"}, + {"_DEC", "Decode", "Device decoding type, Resource Descriptor field"}, + {"_DEP", "Dependencies", "Returns a list of operation region dependencies"}, + {"_DGS", "Display Graphics State", "Return the current state of the output device"}, + {"_DIS", "Disable", "Disables a device"}, + {"_DLM", "Device Lock Mutex", "Defines mutex for OS/AML sharing"}, + {"_DMA", "Direct Memory Access", "Returns a device's current resources for DMA transactions"}, + {"_DOD", "Display Output Devices", "Enumerate all devices attached to the display adapter"}, + {"_DOS", "Disable Output Switching", "Sets the display output switching mode"}, + {"_DPL", "Device Selection Polarity", "Polarity of Device Selection signal, Resource Descriptor field"}, + {"_DRS", "Drive Strength", "Drive Strength setting for GPIO connection, Resource Descriptor field"}, + {"_DSM", "Device Specific Method", "Executes device-specific functions"}, + {"_DSS", "Device Set State", "Sets the display device state"}, + {"_DSW", "Device Sleep Wake", "Sets the sleep and wake transition states for a device"}, + {"_DTI", "Device Temperature Indication", "Conveys native device temperature to the platform"}, + {"_Exx", "Edge GPE", "Method executed as a result of a general-purpose event"}, + {"_EC_", "Embedded Controller", "returns EC offset and query information"}, + {"_EDL", "Eject Device List", "Returns a list of devices that are dependent on a device (docking)"}, + {"_EJD", "Ejection Dependent Device", "Returns the name of dependent (parent) device (docking)"}, + {"_EJx", "Eject", "Begin or cancel a device ejection request (docking)"}, + {"_END", "Endian-ness", "Endian orientation, Resource Descriptor field"}, + {"_EVT", "Event", "Event method for GPIO events"}, + {"_FDE", "Floppy Disk Enumerate", "Returns floppy disk configuration information"}, + {"_FDI", "Floppy Drive Information", "Returns a floppy drive information block"}, + {"_FDM", "Floppy Drive Mode", "Sets a floppy drive speed"}, + {"_FIF", "Fan Information", "Returns fan device information"}, + {"_FIX", "Fixed Register Resource Provider", "Returns a list of devices that implement FADT register blocks"}, + {"_FLC", "Flow Control", "Flow control, Resource Descriptor field"}, + {"_FPS", "Fan Performance States", "Returns a list of supported fan performance states"}, + {"_FSL", "Fan Set Level", "Control method that sets the fan device's speed level (performance state)"}, + {"_FST", "Fan Status", "Returns current status information for a fan device"}, + {"_GAI", "Get Averaging Interval", "Returns the power meter averaging interval"}, + {"_GCP", "Get Capability", "Get device time capabilities"}, + {"_GHL", "Get Hardware Limit", "Returns the hardware limit enforced by the power meter"}, + {"_GL_", "Global Lock", "OS-defined Global Lock mutex object"}, + {"_GLK", "Global Lock", "Returns a device's Global Lock requirement for device access"}, + {"_GPD", "Get Post Data", "Returns the value of the VGA device that will be posted at boot"}, + {"_GPE", "General Purpose Events", "(1) predefined Scope (\\_GPE.)"}, + {"_GRA", "Granularity", "Address space granularity, Resource Descriptor field"}, + {"_GSB", "Global System Interrupt Base", "Returns the GSB for a I/O APIC device"}, + {"_GRT", "Get Real Time", "Returns current time-of-day"}, + {"_GTF", "Get Task File", "Returns a list of ATA commands to restore a drive to default state"}, + {"_GTM", "Get Timing Mode", "Returns a list of IDE controller timing information"}, + {"_GTS", "Going To Sleep", "Inform AML of pending sleep"}, + {"_GWS", "Get Wake Status", "Return status of wake alarms"}, + {"_HE_", "High-Edge", "Interrupt triggering, Resource Descriptor field"}, + {"_HID", "Hardware ID", "Returns a device's Plug and Play Hardware ID"}, + {"_HOT", "Hot Temperature", "Returns the critical temperature for sleep (entry to S4)"}, + {"_HPP", "Hot Plug Parameters", "Returns a list of hot-plug information for a PCI device"}, + {"_HPX", "Hot Plug Parameter Extensions", "Returns a list of hot-plug information for a PCI device. Supersedes _HPP"}, + {"_HRV", "Hardware Revision", "Returns a hardware revision value"}, + {"_IFT", "IPMI Interface Type", "See the Intelligent Platform Management Interface Specification"}, + {"_INI", "Initialize", "Performs device specific initialization"}, + {"_INT", "Interrupts", "Interrupt mask bits, Resource Descriptor field"}, + {"_IOR", "I/O Restriction", "Restriction type, Resource Descriptor field"}, + {"_IRC", "Inrush Current", "Presence indicates that a device has a significant inrush current draw"}, + {"_Lxx", "Level GPE", "Control method executed as a result of a general-purpose event"}, + {"_LCK", "Lock", "Locks or unlocks a device (docking)"}, + {"_LEN", "Length", "Range length, Resource Descriptor field"}, + {"_LID", "Lid", "Returns the open/closed status of the lid on a mobile system"}, + {"_LIN", "Lines In Use", "Handshake lines, Resource Descriptor field"}, + {"_LL_", "Low Level", "Interrupt polarity, Resource Descriptor field"}, + {"_MAF", "Maximum Address Fixed", "Resource Descriptor field"}, + {"_MAT", "Multiple Apic Table Entry", "Returns a list of MADT APIC structure entries"}, + {"_MAX", "Maximum Base Address", "Resource Descriptor field"}, + {"_MBM", "Memory Bandwidth Monitoring Data", "Returns bandwidth monitoring data for a memory device"}, + {"_MEM", "Memory Attributes", "Resource Descriptor field"}, + {"_MIF", "Minimum Address Fixed", "Resource Descriptor field"}, + {"_MIN", "Minimum Base Address", "Resource Descriptor field"}, + {"_MLS", "Multiple Language String", "Returns a device description in multiple languages"}, + {"_MOD", "Mode", "Interrupt mode, Resource Descriptor field"}, + {"_MSG", "Message", "Sets the system message waiting status indicator"}, + {"_MSM", "Memory Set Monitoring", "Sets bandwidth monitoring parameters for a memory device"}, + {"_MTP", "Memory Type", "Resource Descriptor field"}, + {"_NTT", "Notification Temperature Threshold", "Returns a threshold for device temperature change that requires platform notification"}, + {"_OFF", "Off", "Sets a power resource to the off state"}, + {"_ON_", "On", "Sets a power resource to the on state"}, + {"_OS_", "Operating System", "Returns a string that identifies the operating system"}, + {"_OSC", "Operating System Capabilities", "Inform AML of host features and capabilities"}, + {"_OSI", "Operating System Interfaces", "Returns supported interfaces, behaviors, and features"}, + {"_OST", "Ospm Status Indication", "Inform AML of event processing status"}, + {"_PAI", "Power Averaging Interval", "Sets the averaging interval for a power meter"}, + {"_PAR", "Parity", "Parity bits, Resource Descriptor field"}, + {"_PCL", "Power Consumer List", "Returns a list of devices powered by a power source"}, + {"_PCT", "Performance Control", "Returns processor performance control and status registers"}, + {"_PDC", "Processor Driver Capabilities", "Inform AML of processor driver capabilities"}, + {"_PDL", "P-state Depth Limit", "Returns the lowest available performance P-state"}, + {"_PHA", "Phase", "Clock phase, Resource Descriptor field"}, + {"_PIC", "PIC", "Inform AML of the interrupt model in use"}, + {"_PIF", "Power Source Information", "Returns a Power Source information block"}, + {"_PIN", "Pins", "Pin list, Resource Descriptor field"}, + {"_PLD", "Physical Device Location", "Returns a device's physical location information"}, + {"_PMC", "Power Meter Capabilities", "Returns a list of Power Meter capabilities info"}, + {"_PMD", "Power Metered Devices", "Returns a list of devices that are measured by the power meter device"}, + {"_PMM", "Power Meter Measurement", "Returns the current value of the Power Meter"}, + {"_POL", "Polarity", "Interrupt polarity, Resource Descriptor field"}, + {"_PPC", "Performance Present Capabilites", "Returns a list of the performance states currently supported by the platform"}, + {"_PPE", "Polling for Platform Error", "Returns the polling interval to retrieve Corrected Platform Error information"}, + {"_PPI", "Pin Configuration", "Resource Descriptor field"}, + {"_PR", "Processor", "Predefined scope for processor objects"}, + {"_PR0", "Power Resources for D0", "Returns a list of dependent power resources to enter state D0 (fully on)"}, + {"_PR1", "Power Resources for D1", "Returns a list of dependent power resources to enter state D1"}, + {"_PR2", "Power Resources for D2", "Returns a list of dependent power resources to enter state D2"}, + {"_PR3", "Power Resources for D3hot", "Returns a list of dependent power resources to enter state D3hot"}, + {"_PRE", "Power Resources for Enumeration", "Returns a list of dependent power resources to enumerate devices on a bus"}, + {"_PRL", "Power Source Redundancy List", "Returns a list of power source devices in the same redundancy grouping"}, + {"_PRS", "Possible Resource Settings", "Returns a list of a device's possible resource settings"}, + {"_PRT", "Pci Routing Table", "Returns a list of PCI interrupt mappings"}, + {"_PRW", "Power Resources for Wake", "Returns a list of dependent power resources for waking"}, + {"_PS0", "Power State 0", "Sets a device's power state to D0 (device fully on)"}, + {"_PS1", "Power State 1", "Sets a device's power state to D1"}, + {"_PS2", "Power State 2", "Sets a device's power state to D2"}, + {"_PS3", "Power State 3", "Sets a device's power state to D3 (device off)"}, + {"_PSC", "Power State Current", "Returns a device's current power state"}, + {"_PSD", "Processor State Dependencies", "Returns processor P-State dependencies"}, + {"_PSE", "Power State for Enumeration", "Put a bus into enumeration power mode"}, + {"_PSL", "Passive List", "Returns a list of passive cooling device objects"}, + {"_PSR", "Power Source", "Returns the power source device currently in use"}, + {"_PSS", "Performance Supported States", "Returns a list of supported processor performance states"}, + {"_PSV", "Passive", "Returns the passive trip point temperature"}, + {"_PSW", "Power State Wake", "Sets a device's wake function"}, + {"_PTC", "Processor Throttling Control", "Returns throttling control and status registers"}, + {"_PTP", "Power Trip Points", "Sets trip points for the Power Meter device"}, + {"_PTS", "Prepare To Sleep", "Inform the platform of an impending sleep transition"}, + {"_PUR", "Processor Utilization Request", "Returns the number of processors that the platform would like to idle"}, + {"_PXM", "Proximity", "Returns a device's proximity domain identifier"}, + {"_Qxx", "Query", "Embedded Controller query and SMBus Alarm control method"}, + {"_RBO", "Register Bit Offset", "Resource Descriptor field"}, + {"_RBW", "Register Bit Width", "Resource Descriptor field"}, + {"_REG", "Region", "Inform AML code of an operation region availability change"}, + {"_REV", "Revision", "Returns the revision of the ACPI specification that is implemented"}, + {"_RMV", "Remove", "Returns a device's removal ability status (docking)"}, + {"_RNG", "Range", "Memory range type, Resource Descriptor field"}, + {"_ROM", "Read-Only Memory", "Returns a copy of the ROM data for a display device"}, + {"_RT_", "Resource Type", "Resource Descriptor field"}, + {"_RTV", "Relative Temperature Values", "Returns temperature value information"}, + {"_RW_", "Read-Write Status", "Resource Descriptor field"}, + {"_RXL", "Receive Buffer Size", "Serial channel buffer, Resource Descriptor field"}, + {"_S0_", "S0 System State", "Returns values to enter the system into the S0 state"}, + {"_S1_", "S1 System State", "Returns values to enter the system into the S1 state"}, + {"_S2_", "S2 System State", "Returns values to enter the system into the S2 state"}, + {"_S3_", "S3 System State", "Returns values to enter the system into the S3 state"}, + {"_S4_", "S4 System State", "Returns values to enter the system into the S4 state"}, + {"_S5_", "S5 System State", "Returns values to enter the system into the S5 state"}, + {"_S1D", "S1 Device State", "Returns the highest D-state supported by a device when in the S1 state"}, + {"_S2D", "S2 Device State", "Returns the highest D-state supported by a device when in the S2 state"}, + {"_S3D", "S3 Device State", "Returns the highest D-state supported by a device when in the S3 state"}, + {"_S4D", "S4 Device State", "Returns the highest D-state supported by a device when in the S4 state"}, + {"_S0W", "S0 Device Wake State", "Returns the lowest D-state that the device can wake itself from S0"}, + {"_S1W", "S1 Device Wake State", "Returns the lowest D-state for this device that can wake the system from S1"}, + {"_S2W", "S2 Device Wake State", "Returns the lowest D-state for this device that can wake the system from S2"}, + {"_S3W", "S3 Device Wake State", "Returns the lowest D-state for this device that can wake the system from S3"}, + {"_S4W", "S4 Device Wake State", "Returns the lowest D-state for this device that can wake the system from S4"}, + {"_SB_", "System Bus", "Scope for device and bus objects"}, + {"_SBS", "Smart Battery Subsystem", "Returns the subsystem configuration"}, + {"_SCP", "Set Cooling Policy", "Sets the cooling policy (active or passive)"}, + {"_SDD", "Set Device Data", "Sets data for a SATA device"}, + {"_SEG", "Segment", "Returns a device's PCI Segment Group number"}, + {"_SHL", "Set Hardware Limit", "Sets the hardware limit enforced by the Power Meter"}, + {"_SHR", "Sharable", "Interrupt share status, Resource Descriptor field"}, + {"_SI_", "System Indicators", "Predefined scope"}, + {"_SIZ", "Size", "DMA transfer size, Resource Descriptor field"}, + {"_SLI", "System Locality Information", "Returns a list of NUMA system localities"}, + {"_SLV", "Slave Mode", "Mode setting, Resource Descriptor field"}, + {"_SPD", "Set Post Device", "Sets which video device will be posted at boot"}, + {"_SPE", "Speed", "Connection speed, Resource Descriptor field"}, + {"_SRS", "Set Resource Settings", "Sets a device's resource allocation"}, + {"_SRT", "Set Real Time", "Interrupt triggering, Resource Descriptor field"}, + {"_SRV", "IPMI Spec Revision", "See the Intelligent Platform Management Interface Specification"}, + {"_SST", "System Status", "Sets the system status indicator"}, + {"_STA", "Status", " (1) returns the current status of a device"}, + {"_STB", "Stop Bits", "Serial channel stop bits, Resource Descriptor field"}, + {"_STM", "Set Timing Mode", "Sets an IDE controller transfer timings"}, + {"_STP", "Set Expired Timer Wake Policy", "Sets expired timer policies of the wake alarm device"}, + {"_STR", "String", "Returns a device's description string"}, + {"_STV", "Set Timer Value", "Set timer values of the wake alarm device"}, + {"_SUB", "Subsystem ID", "Returns the subsystem ID for a device"}, + {"_SUN", "Slot User Number", "Returns the slot unique ID number"}, + {"_SWS", "System Wake Source", "Returns the source event that caused the system to wake"}, + {"_T_x", "Temporary", "Reserved for use by ASL compilers"}, + {"_TC1", "Thermal Constant 1", "Returns TC1 for the passive cooling formula"}, + {"_TC2", "Thermal Constant 2", "Returns TC2 for the passive cooling formula"}, + {"_TDL", "T-State Depth Limit", "Returns the _TSS entry number of the lowest power throttling state"}, + {"_TIP", "Expired Timer Wake Policy", "Returns timer policies of the wake alarm device"}, + {"_TIV", "Timer Values", "Returns remaining time of the wake alarm device"}, + {"_TMP", "Temperature", "Returns a thermal zone's current temperature"}, + {"_TPC", "Throttling Present Capabilities", "Returns the current number of supported throttling states"}, + {"_TPT", "Trip Point Temperature", "Inform AML that a device's embedded temperature sensor has crossed a temperature trip point"}, + {"_TRA", "Translation", "Address translation offset, Resource Descriptor field"}, + {"_TRS", "Translation Sparse", "Sparse/dense flag, Resource Descriptor field"}, + {"_TRT", "Thermal Relationship Table", "Returns thermal relationships between platform devices"}, + {"_TSD", "Throttling State Dependencies", "Returns a list of T-state dependencies"}, + {"_TSF", "Type-Specific Flags", "Resource Descriptor field"}, + {"_TSP", "Thermal Sampling Period", "Returns the thermal sampling period for passive cooling"}, + {"_TSS", "Throttling Supported States", "Returns supported throttling state information"}, + {"_TST", "Temperature Sensor Threshold", "Returns the minimum separation for a device's temperature trip points"}, + {"_TTP", "Translation Type", "Translation/static flag, Resource Descriptor field"}, + {"_TTS", "Transition To State", "Inform AML of an S-state transition"}, + {"_TXL", "Transmit Buffer Size", "Serial Channel buffer, Resource Descriptor field"}, + {"_TYP", "Type", "DMA channel type (speed), Resource Descriptor field"}, + {"_TZ_", "Thermal Zone", "Predefined scope: ACPI 1.0"}, + {"_TZD", "Thermal Zone Devices", "Returns a list of device names associated with a Thermal Zone"}, + {"_TZM", "Thermal Zone Member", "Returns a reference to the thermal zone of which a device is a member"}, + {"_TZP", "Thermal Zone Polling", "Returns a Thermal zone's polling frequency"}, + {"_UID", "Unique ID", "Return a device's unique persistent ID"}, + {"_UPC", "USB Port Capabilities", "Returns a list of USB port capabilities"}, + {"_UPD", "User Presence Detect", "Returns user detection information"}, + {"_UPP", "User Presence Polling", "Returns the recommended user presence polling interval"}, + {"_VEN", "Vendor Data", "Resource Descriptor field"}, + {"_VPO", "Video Post Options", "Returns the implemented video post options"}, + {"_WAK", "Wake", "Inform AML that the system has just awakened"}, + {"_Wxx", "Wake Event", "Method executed as a result of a wake event"}, + {NULL, NULL, NULL} +}; diff --git a/source/tools/acpinames/Makefile b/source/tools/acpinames/Makefile new file mode 100644 index 000000000000..bdd2d260c494 --- /dev/null +++ b/source/tools/acpinames/Makefile @@ -0,0 +1,189 @@ +# +# acpinames - Load ACPI table and dump namespace. This is a subset +# of the AcpiExec functionality, it is intended to demonstrate +# the configurability of ACPICA. +# +# NOTE: This makefile is intended to be used in the Linux environment, +# with the Linux directory structure. It will not work directly +# on the native ACPICA source tree. +# + +# +# Configuration +# Notes: +# gcc should be version 4 or greater, otherwise some of the options +# used will not be recognized. +# Global optimization flags (such as -O2, -Os) are not used, since +# they cause issues on some compilers. +# The _GNU_SOURCE symbol is required for many hosts. +# +PROG = acpinames + +HOST = _LINUX +NOMAN = YES +COMPILE = $(CC) -c $(CFLAGS) $(CWARNINGFLAGS) -o$@ $< + +ACPICA_SRC = ../../../source +ACPICA_COMMON = $(ACPICA_SRC)/common +ACPICA_TOOLS = $(ACPICA_SRC)/tools +ACPICA_OSL = $(ACPICA_SRC)/os_specific/service_layers +ACPICA_CORE = $(ACPICA_SRC)/components +ACPICA_INCLUDE = $(ACPICA_SRC)/include +ACPICA_DEBUGGER = $(ACPICA_CORE)/debugger +ACPICA_DISASSEMBLER = $(ACPICA_CORE)/disassembler +ACPICA_DISPATCHER = $(ACPICA_CORE)/dispatcher +ACPICA_EVENTS = $(ACPICA_CORE)/events +ACPICA_EXECUTER = $(ACPICA_CORE)/executer +ACPICA_HARDWARE = $(ACPICA_CORE)/hardware +ACPICA_NAMESPACE = $(ACPICA_CORE)/namespace +ACPICA_PARSER = $(ACPICA_CORE)/parser +ACPICA_RESOURCES = $(ACPICA_CORE)/resources +ACPICA_TABLES = $(ACPICA_CORE)/tables +ACPICA_UTILITIES = $(ACPICA_CORE)/utilities +ACPINAMES = $(ACPICA_TOOLS)/acpinames +INSTALLDIR = /usr/bin +INSTALLPROG = cp --remove-destination $(PROG) $(INSTALLDIR) + +ACPICA_HEADERS = \ + $(wildcard $(ACPICA_INCLUDE)/*.h) \ + $(wildcard $(ACPICA_INCLUDE)/platform/*.h) + +# +# Search paths for source files +# +vpath %.c \ + $(ACPINAMES) \ + $(ACPICA_DEBUGGER) \ + $(ACPICA_DISPATCHER) \ + $(ACPICA_EXECUTER) \ + $(ACPICA_NAMESPACE) \ + $(ACPICA_PARSER) \ + $(ACPICA_TABLES) \ + $(ACPICA_UTILITIES) \ + $(ACPICA_COMMON) \ + $(ACPICA_OSL) + +HEADERS = \ + $(wildcard $(ACPINAMES)/*.h) + +OBJECTS = \ + anmain.o \ + anstubs.o \ + antables.o \ + dbfileio.o \ + dsfield.o \ + dsmthdat.o \ + dsobject.o \ + dsutils.o \ + dswload.o \ + dswload2.o \ + dswscope.o \ + dswstate.o \ + excreate.o \ + exnames.o \ + exresnte.o \ + exresolv.o \ + exutils.o \ + getopt.o \ + nsaccess.o \ + nsalloc.o \ + nsdump.o \ + nsinit.o \ + nsload.o \ + nsnames.o \ + nsobject.o \ + nsparse.o \ + nssearch.o \ + nsutils.o \ + nswalk.o \ + nsxfeval.o \ + nsxfname.o \ + nsxfobj.o \ + osunixxf.o \ + psargs.o \ + psloop.o \ + psopcode.o \ + psparse.o \ + psscope.o \ + pstree.o \ + psutils.o \ + pswalk.o \ + psxface.o \ + tbfadt.o \ + tbfind.o \ + tbinstal.o \ + tbutils.o \ + tbxface.o \ + tbxfroot.o \ + utaddress.o \ + utalloc.o \ + utcache.o \ + utdebug.o \ + utdecode.o \ + utdelete.o \ + utglobal.o \ + utlock.o \ + utmath.o \ + utmisc.o \ + utmutex.o \ + utobject.o \ + utstate.o \ + utosi.o \ + utxferror.o \ + utxface.o + +CFLAGS+= \ + -D$(HOST) \ + -D_GNU_SOURCE \ + -DACPI_NAMES_APP \ + -I$(ACPICA_INCLUDE) \ + -I$(ACPINAMES) + +CWARNINGFLAGS = \ + -ansi \ + -Wall \ + -Wbad-function-cast \ + -Wdeclaration-after-statement \ + -Werror \ + -Wformat=2 \ + -Wmissing-declarations \ + -Wmissing-prototypes \ + -Wstrict-aliasing=0 \ + -Wstrict-prototypes \ + -Wswitch-default \ + -Wpointer-arith \ + -Wundef + +# +# gcc 4+ flags +# +CWARNINGFLAGS += \ + -Waddress \ + -Waggregate-return \ + -Wchar-subscripts \ + -Wempty-body \ + -Wlogical-op \ + -Wmissing-declarations \ + -Wmissing-field-initializers \ + -Wmissing-parameter-type \ + -Wnested-externs \ + -Wold-style-declaration \ + -Wold-style-definition \ + -Wredundant-decls \ + -Wtype-limits + +# +# Rules +# +$(PROG) : $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) -o $(PROG) + $(COPYPROG) + +%.o : %.c $(HEADERS) $(ACPICA_HEADERS) + $(COMPILE) + +clean : + rm -f $(PROG) $(PROG).exe $(OBJECTS) + +install : + $(INSTALLPROG) diff --git a/source/tools/acpinames/acpinames.h b/source/tools/acpinames/acpinames.h new file mode 100644 index 000000000000..260124af8ee6 --- /dev/null +++ b/source/tools/acpinames/acpinames.h @@ -0,0 +1,57 @@ +/****************************************************************************** + * + * Module Name: acpinames.h - Common include for AcpiNames utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#ifndef _ACPINAMES_H +#define _ACPINAMES_H + +#include "acpi.h" +#include "accommon.h" +#include "acapps.h" +#include "../acpiexec/aecommon.h" + +#include <stdio.h> + +#define ACPI_MAX_INIT_TABLES (32) + +#endif + diff --git a/source/tools/acpinames/anmain.c b/source/tools/acpinames/anmain.c new file mode 100644 index 000000000000..682cc5f61570 --- /dev/null +++ b/source/tools/acpinames/anmain.c @@ -0,0 +1,275 @@ +/****************************************************************************** + * + * Module Name: anmain - Main routine for the AcpiNames utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpinames.h" + +#define _COMPONENT ACPI_TOOLS + ACPI_MODULE_NAME ("anmain") + + +extern ACPI_TABLE_DESC Tables[]; + +FILE *AcpiGbl_DebugFile; +static AE_TABLE_DESC *AeTableListHead = NULL; + + +#define AE_SUPPORTED_OPTIONS "?h" + + +/****************************************************************************** + * + * FUNCTION: usage + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Print a usage message + * + *****************************************************************************/ + +static void +usage ( + void) +{ + + ACPI_USAGE_HEADER ("AcpiNames [options] AMLfile"); + ACPI_OPTION ("-?", "Display this message"); +} + + +/****************************************************************************** + * + * FUNCTION: NsDumpEntireNamespace + * + * PARAMETERS: AmlFilename - Filename for DSDT or SSDT AML table + * + * RETURN: Status (pass/fail) + * + * DESCRIPTION: Build an ACPI namespace for the input AML table, and dump the + * formatted namespace contents. + * + *****************************************************************************/ + +static int +NsDumpEntireNamespace ( + char *AmlFilename) +{ + ACPI_STATUS Status; + ACPI_TABLE_HEADER *Table = NULL; + UINT32 TableCount = 0; + AE_TABLE_DESC *TableDesc; + ACPI_HANDLE Handle; + + + /* Open the binary AML file and read the entire table */ + + Status = AcpiDbReadTableFromFile (AmlFilename, &Table); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not get input table %s, %s\n", AmlFilename, + AcpiFormatException (Status)); + return (-1); + } + + /* Table must be a DSDT. SSDTs are not currently supported */ + + if (!ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT)) + { + printf ("**** Input table signature is [%4.4s], must be [DSDT]\n", + Table->Signature); + return (-1); + } + + /* + * Allocate and link a table descriptor (allows for future expansion to + * multiple input files) + */ + TableDesc = AcpiOsAllocate (sizeof (AE_TABLE_DESC)); + TableDesc->Table = Table; + TableDesc->Next = AeTableListHead; + AeTableListHead = TableDesc; + + TableCount++; + + /* + * Build a local XSDT with all tables. Normally, here is where the + * RSDP search is performed to find the ACPI tables + */ + Status = AeBuildLocalTables (TableCount, AeTableListHead); + if (ACPI_FAILURE (Status)) + { + return (-1); + } + + /* Initialize table manager, get XSDT */ + + Status = AcpiInitializeTables (Tables, ACPI_MAX_INIT_TABLES, TRUE); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not initialize ACPI table manager, %s\n", + AcpiFormatException (Status)); + return (-1); + } + + /* Reallocate root table to dynamic memory */ + + Status = AcpiReallocateRootTable (); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not reallocate root table, %s\n", + AcpiFormatException (Status)); + return (-1); + } + + /* Load the ACPI namespace */ + + Status = AcpiLoadTables (); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not load ACPI tables, %s\n", + AcpiFormatException (Status)); + return (-1); + } + + /* + * Enable ACPICA. These calls don't do much for this + * utility, since we only dump the namespace. There is no + * hardware or event manager code underneath. + */ + Status = AcpiEnableSubsystem ( + ACPI_NO_ACPI_ENABLE | + ACPI_NO_ADDRESS_SPACE_INIT | + ACPI_NO_EVENT_INIT | + ACPI_NO_HANDLER_INIT); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not EnableSubsystem, %s\n", + AcpiFormatException (Status)); + return (-1); + } + + Status = AcpiInitializeObjects ( + ACPI_NO_ADDRESS_SPACE_INIT | + ACPI_NO_DEVICE_INIT | + ACPI_NO_EVENT_INIT); + if (ACPI_FAILURE (Status)) + { + printf ("**** Could not InitializeObjects, %s\n", + AcpiFormatException (Status)); + return (-1); + } + + /* + * Perform a namespace walk to dump the contents + */ + AcpiOsPrintf ("\nACPI Namespace:\n"); + + AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_SUMMARY, ACPI_UINT32_MAX, + ACPI_OWNER_ID_MAX, AcpiGbl_RootNode); + + + /* Example: get a handle to the _GPE scope */ + + Status = AcpiGetHandle (NULL, "\\_GPE", &Handle); + AE_CHECK_OK (AcpiGetHandle, Status); + + return (0); +} + + +/****************************************************************************** + * + * FUNCTION: main + * + * PARAMETERS: argc, argv + * + * RETURN: Status (pass/fail) + * + * DESCRIPTION: Main routine for NsDump utility + * + *****************************************************************************/ + +int ACPI_SYSTEM_XFACE +main ( + int argc, + char **argv) +{ + ACPI_STATUS Status; + int j; + + + printf (ACPI_COMMON_SIGNON ("ACPI Namespace Dump Utility")); + + if (argc < 2) + { + usage (); + return (0); + } + + /* Init globals and ACPICA */ + + AcpiDbgLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES; + AcpiDbgLayer = 0xFFFFFFFF; + + Status = AcpiInitializeSubsystem (); + AE_CHECK_OK (AcpiInitializeSubsystem, Status); + + /* Get the command line options */ + + while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch(j) + { + case '?': + case 'h': + default: + usage(); + return (0); + } + + /* + * The next argument is the filename for the DSDT or SSDT. + * Open the file, build namespace and dump it. + */ + return (NsDumpEntireNamespace (argv[AcpiGbl_Optind])); +} + diff --git a/source/tools/acpinames/anstubs.c b/source/tools/acpinames/anstubs.c new file mode 100644 index 000000000000..a69c425e3776 --- /dev/null +++ b/source/tools/acpinames/anstubs.c @@ -0,0 +1,441 @@ +/****************************************************************************** + * + * Module Name: anstubs - Stub routines for the AcpiNames utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpinames.h" + +#include <acutils.h> +#include <acevents.h> +#include <acdispat.h> + +#define _COMPONENT ACPI_TOOLS + ACPI_MODULE_NAME ("anstubs") + + +/****************************************************************************** + * + * DESCRIPTION: Stubs used to facilitate linkage of the NsDump utility. + * + *****************************************************************************/ + + +/* Utilities */ + +void +AcpiUtSubsystemShutdown ( + void) +{ +} + +ACPI_STATUS +AcpiUtExecute_STA ( + ACPI_NAMESPACE_NODE *DeviceNode, + UINT32 *StatusFlags) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiUtExecute_HID ( + ACPI_NAMESPACE_NODE *DeviceNode, + ACPI_DEVICE_ID **ReturnId) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiUtExecute_CID ( + ACPI_NAMESPACE_NODE *DeviceNode, + ACPI_DEVICE_ID_LIST **ReturnCidList) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiUtExecute_UID ( + ACPI_NAMESPACE_NODE *DeviceNode, + ACPI_DEVICE_ID **ReturnId) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiUtExecutePowerMethods ( + ACPI_NAMESPACE_NODE *DeviceNode, + const char **MethodNames, + UINT8 MethodCount, + UINT8 *OutValues) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiUtEvaluateNumericObject ( + char *ObjectName, + ACPI_NAMESPACE_NODE *DeviceNode, + UINT64 *Value) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiUtCopyIobjectToEobject ( + ACPI_OPERAND_OBJECT *Obj, + ACPI_BUFFER *RetBuffer) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiUtCopyEobjectToIobject ( + ACPI_OBJECT *Obj, + ACPI_OPERAND_OBJECT **InternalObj) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiUtCopyIobjectToIobject ( + ACPI_OPERAND_OBJECT *SourceDesc, + ACPI_OPERAND_OBJECT **DestDesc, + ACPI_WALK_STATE *WalkState) +{ + return (AE_NOT_IMPLEMENTED); +} + + +/* Hardware manager */ + +UINT32 +AcpiHwGetMode ( + void) +{ + return (0); +} + + +/* Event manager */ + +ACPI_STATUS +AcpiEvInstallXruptHandlers ( + void) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiEvInitializeEvents ( + void) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiEvInstallRegionHandlers ( + void) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiEvInitializeOpRegions ( + void) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiEvInitializeRegion ( + ACPI_OPERAND_OBJECT *RegionObj, + BOOLEAN AcpiNsLocked) +{ + return (AE_OK); +} + +#if (!ACPI_REDUCED_HARDWARE) +ACPI_STATUS +AcpiEvDeleteGpeBlock ( + ACPI_GPE_BLOCK_INFO *GpeBlock) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiEnable ( + void) +{ + return (AE_OK); +} +#endif /* !ACPI_REDUCED_HARDWARE */ + + +/* AML Interpreter */ + +void +AcpiExUnlinkMutex ( + ACPI_OPERAND_OBJECT *ObjDesc) +{ +} + +void +AcpiExReleaseAllMutexes ( + ACPI_THREAD_STATE *Thread) +{ +} + +ACPI_STATUS +AcpiExReadDataFromField ( + ACPI_WALK_STATE *WalkState, + ACPI_OPERAND_OBJECT *ObjDesc, + ACPI_OPERAND_OBJECT **RetBufferDesc) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiExWriteDataToField ( + ACPI_OPERAND_OBJECT *SourceDesc, + ACPI_OPERAND_OBJECT *ObjDesc, + ACPI_OPERAND_OBJECT **ResultDesc) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiExPrepFieldValue ( + ACPI_CREATE_FIELD_INFO *Info) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiExAcquireMutexObject ( + UINT16 Timeout, + ACPI_OPERAND_OBJECT *ObjDesc, + ACPI_THREAD_ID ThreadId) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiExReleaseMutexObject ( + ACPI_OPERAND_OBJECT *ObjDesc) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiExStoreObjectToNode ( + ACPI_OPERAND_OBJECT *SourceDesc, + ACPI_NAMESPACE_NODE *Node, + ACPI_WALK_STATE *WalkState, + UINT8 ImplicitConversion) +{ + return (AE_NOT_IMPLEMENTED); +} + + +/* Namespace manager */ + +ACPI_STATUS +AcpiNsEvaluate ( + ACPI_EVALUATE_INFO *Info) +{ + return (AE_NOT_IMPLEMENTED); +} + +void +AcpiNsExecModuleCodeList ( + void) +{ +} + + +/* Dispatcher */ + +ACPI_STATUS +AcpiDsInitializeObjects ( + UINT32 TableIndex, + ACPI_NAMESPACE_NODE *StartNode) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiDsCallControlMethod ( + ACPI_THREAD_STATE *Thread, + ACPI_WALK_STATE *WalkState, + ACPI_PARSE_OBJECT *Op) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiDsRestartControlMethod ( + ACPI_WALK_STATE *WalkState, + ACPI_OPERAND_OBJECT *ReturnDesc) +{ + return (AE_NOT_IMPLEMENTED); +} + +void +AcpiDsTerminateControlMethod ( + ACPI_OPERAND_OBJECT *MethodDesc, + ACPI_WALK_STATE *WalkState) +{ +} + +ACPI_STATUS +AcpiDsMethodError ( + ACPI_STATUS Status, + ACPI_WALK_STATE *WalkState) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiDsBeginMethodExecution ( + ACPI_NAMESPACE_NODE *MethodNode, + ACPI_OPERAND_OBJECT *ObjDesc, + ACPI_WALK_STATE *WalkState) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiDsGetPredicateValue ( + ACPI_WALK_STATE *WalkState, + ACPI_OPERAND_OBJECT *ResultObj) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiDsGetBufferFieldArguments ( + ACPI_OPERAND_OBJECT *ObjDesc) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiDsGetBankFieldArguments ( + ACPI_OPERAND_OBJECT *ObjDesc) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiDsGetRegionArguments ( + ACPI_OPERAND_OBJECT *RgnDesc) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiDsGetBufferArguments ( + ACPI_OPERAND_OBJECT *ObjDesc) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiDsGetPackageArguments ( + ACPI_OPERAND_OBJECT *ObjDesc) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiDsExecBeginOp ( + ACPI_WALK_STATE *WalkState, + ACPI_PARSE_OBJECT **OutOp) +{ + return (AE_NOT_IMPLEMENTED); +} + +ACPI_STATUS +AcpiDsExecEndOp ( + ACPI_WALK_STATE *State) +{ + return (AE_NOT_IMPLEMENTED); +} + + +/* AML Debugger */ + +void +AcpiDbDisplayArgumentObject ( + ACPI_OPERAND_OBJECT *ObjDesc, + ACPI_WALK_STATE *WalkState) +{ +} + +ACPI_STATUS +AcpiDbInitialize ( + void) +{ + return (AE_OK); +} + +void +AcpiDbTerminate ( + void) +{ +} + +/* OSL interfaces */ + +ACPI_THREAD_ID +AcpiOsGetThreadId ( + void) +{ + return (0xFFFF); +} + +ACPI_STATUS +AcpiOsExecute ( + ACPI_EXECUTE_TYPE Type, + ACPI_OSD_EXEC_CALLBACK Function, + void *Context) +{ + return (AE_SUPPORT); +} diff --git a/source/tools/acpinames/antables.c b/source/tools/acpinames/antables.c new file mode 100644 index 000000000000..37fa24ae5f9f --- /dev/null +++ b/source/tools/acpinames/antables.c @@ -0,0 +1,304 @@ +/****************************************************************************** + * + * Module Name: antables - ACPI table setup/install for AcpiNames utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpinames.h" + +#define _COMPONENT ACPI_TOOLS + ACPI_MODULE_NAME ("antables") + +/* Local prototypes */ + +ACPI_PHYSICAL_ADDRESS +AeLocalGetRootPointer ( + void); + +/* Non-AML tables that are constructed locally and installed */ + +static ACPI_TABLE_RSDP LocalRSDP; +static ACPI_TABLE_FACS LocalFACS; + +/* + * We need a local FADT so that the hardware subcomponent will function, + * even though the underlying OSD HW access functions don't do anything. + */ +static ACPI_TABLE_FADT LocalFADT; + +/* + * Use XSDT so that both 32- and 64-bit versions of this utility will + * function automatically. + */ +static ACPI_TABLE_XSDT *LocalXSDT; + +#define BASE_XSDT_TABLES 1 +#define BASE_XSDT_SIZE (sizeof (ACPI_TABLE_XSDT) + \ + ((BASE_XSDT_TABLES -1) * sizeof (UINT64))) + +ACPI_TABLE_DESC Tables[ACPI_MAX_INIT_TABLES]; + + +/****************************************************************************** + * + * FUNCTION: AeBuildLocalTables + * + * PARAMETERS: TableCount - Number of tables on the command line + * TableList - List of actual tables from files + * + * RETURN: Status + * + * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT, + * FADT, FACS, and the input DSDT/SSDT. + * + *****************************************************************************/ + +ACPI_STATUS +AeBuildLocalTables ( + UINT32 TableCount, + AE_TABLE_DESC *TableList) +{ + ACPI_PHYSICAL_ADDRESS DsdtAddress = 0; + UINT32 XsdtSize; + AE_TABLE_DESC *NextTable; + UINT32 NextIndex; + ACPI_TABLE_FADT *ExternalFadt = NULL; + + + /* + * Update the table count. For DSDT, it is not put into the XSDT. For + * FADT, this is already accounted for since we usually install a + * local FADT. + */ + NextTable = TableList; + while (NextTable) + { + if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT) || + ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT)) + { + TableCount--; + } + NextTable = NextTable->Next; + } + + XsdtSize = BASE_XSDT_SIZE + (TableCount * sizeof (UINT64)); + + /* Build an XSDT */ + + LocalXSDT = AcpiOsAllocate (XsdtSize); + if (!LocalXSDT) + { + return (AE_NO_MEMORY); + } + + ACPI_MEMSET (LocalXSDT, 0, XsdtSize); + ACPI_STRNCPY (LocalXSDT->Header.Signature, ACPI_SIG_XSDT, 4); + LocalXSDT->Header.Length = XsdtSize; + LocalXSDT->Header.Revision = 1; + + LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalFADT); + + /* + * Install the user tables. The DSDT must be installed in the FADT. + * All other tables are installed directly into the XSDT. + */ + NextIndex = BASE_XSDT_TABLES; + NextTable = TableList; + while (NextTable) + { + /* + * Incoming DSDT or FADT are special cases. All other tables are + * just immediately installed into the XSDT. + */ + if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT)) + { + if (DsdtAddress) + { + printf ("Already found a DSDT, only one allowed\n"); + return (AE_ALREADY_EXISTS); + } + + /* The incoming user table is a DSDT */ + + DsdtAddress = ACPI_PTR_TO_PHYSADDR (NextTable->Table); + } + else if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT)) + { + ExternalFadt = ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table); + LocalXSDT->TableOffsetEntry[2] = ACPI_PTR_TO_PHYSADDR (NextTable->Table); + } + else + { + /* Install the table in the XSDT */ + + LocalXSDT->TableOffsetEntry[NextIndex] = ACPI_PTR_TO_PHYSADDR (NextTable->Table); + NextIndex++; + } + + NextTable = NextTable->Next; + } + + /* Build an RSDP */ + + ACPI_MEMSET (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP)); + ACPI_MEMCPY (LocalRSDP.Signature, ACPI_SIG_RSDP, 8); + ACPI_MEMCPY (LocalRSDP.OemId, "I_TEST", 6); + LocalRSDP.Revision = 2; + LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT); + LocalRSDP.Length = sizeof (ACPI_TABLE_XSDT); + + /* Set checksums for both XSDT and RSDP */ + + LocalXSDT->Header.Checksum = (UINT8) -AcpiTbChecksum ( + (void *) LocalXSDT, LocalXSDT->Header.Length); + LocalRSDP.Checksum = (UINT8) -AcpiTbChecksum ( + (void *) &LocalRSDP, ACPI_RSDP_CHECKSUM_LENGTH); + + if (!DsdtAddress) + { + return (AE_SUPPORT); + } + + if (ExternalFadt) + { + /* + * Use the external FADT, but we must update the DSDT/FACS addresses + * as well as the checksum + */ + ExternalFadt->Dsdt = DsdtAddress; + ExternalFadt->Facs = ACPI_PTR_TO_PHYSADDR (&LocalFACS); + + if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (&ExternalFadt->XDsdt, ExternalFadt)) + { + ExternalFadt->XDsdt = DsdtAddress; + ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS); + } + /* Complete the FADT with the checksum */ + + ExternalFadt->Header.Checksum = 0; + ExternalFadt->Header.Checksum = (UINT8) -AcpiTbChecksum ( + (void *) ExternalFadt, ExternalFadt->Header.Length); + } + else + { + /* + * Build a local FADT so we can test the hardware/event init + */ + ACPI_MEMSET (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT)); + ACPI_STRNCPY (LocalFADT.Header.Signature, ACPI_SIG_FADT, 4); + + /* Setup FADT header and DSDT/FACS addresses */ + + LocalFADT.Dsdt = 0; + LocalFADT.Facs = 0; + + LocalFADT.XDsdt = DsdtAddress; + LocalFADT.XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS); + + LocalFADT.Header.Revision = 3; + LocalFADT.Header.Length = sizeof (ACPI_TABLE_FADT); + + /* Miscellaneous FADT fields */ + + LocalFADT.Gpe0BlockLength = 16; + LocalFADT.Gpe0Block = 0x00001234; + + LocalFADT.Gpe1BlockLength = 6; + LocalFADT.Gpe1Block = 0x00005678; + LocalFADT.Gpe1Base = 96; + + LocalFADT.Pm1EventLength = 4; + LocalFADT.Pm1aEventBlock = 0x00001aaa; + LocalFADT.Pm1bEventBlock = 0x00001bbb; + + LocalFADT.Pm1ControlLength = 2; + LocalFADT.Pm1aControlBlock = 0xB0; + + LocalFADT.PmTimerLength = 4; + LocalFADT.PmTimerBlock = 0xA0; + + LocalFADT.Pm2ControlBlock = 0xC0; + LocalFADT.Pm2ControlLength = 1; + + /* Setup one example X-64 field */ + + LocalFADT.XPm1bEventBlock.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO; + LocalFADT.XPm1bEventBlock.Address = LocalFADT.Pm1bEventBlock; + LocalFADT.XPm1bEventBlock.BitWidth = (UINT8) ACPI_MUL_8 (LocalFADT.Pm1EventLength); + + /* Complete the FADT with the checksum */ + + LocalFADT.Header.Checksum = 0; + LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum ( + (void *) &LocalFADT, LocalFADT.Header.Length); + } + + /* Build a FACS */ + + ACPI_MEMSET (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS)); + ACPI_STRNCPY (LocalFACS.Signature, ACPI_SIG_FACS, 4); + + LocalFACS.Length = sizeof (ACPI_TABLE_FACS); + LocalFACS.GlobalLock = 0x11AA0011; + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AeLocalGetRootPointer + * + * PARAMETERS: None + * + * RETURN: Address of the RSDP + * + * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the + * standard ACPI mechanism. + * + *****************************************************************************/ + +ACPI_PHYSICAL_ADDRESS +AeLocalGetRootPointer ( + void) +{ + + return ((ACPI_PHYSICAL_ADDRESS) &LocalRSDP); +} diff --git a/source/tools/acpisrc/Makefile b/source/tools/acpisrc/Makefile new file mode 100644 index 000000000000..58a8654e350c --- /dev/null +++ b/source/tools/acpisrc/Makefile @@ -0,0 +1,124 @@ +# +# acpisrc - ACPICA source code conversion utility +# +# NOTE: This makefile is intended to be used in the Linux environment, +# with the Linux directory structure. It will not work directly +# on the native ACPICA source tree. +# + +# +# Configuration +# Notes: +# gcc should be version 4 or greater, otherwise some of the options +# used will not be recognized. +# Global optimization flags (such as -O2, -Os) are not used, since +# they cause issues on some compilers. +# The _GNU_SOURCE symbol is required for many hosts. +# +PROG = acpisrc + +HOST = _LINUX +NOMAN = YES +COMPILE = $(CC) -c $(CFLAGS) $(CWARNINGFLAGS) -o$@ $< + +ACPICA_SRC = ../../../source +ACPICA_COMMON = $(ACPICA_SRC)/common +ACPICA_TOOLS = $(ACPICA_SRC)/tools +ACPICA_OSL = $(ACPICA_SRC)/os_specific/service_layers +ACPICA_CORE = $(ACPICA_SRC)/components +ACPICA_INCLUDE = $(ACPICA_SRC)/include +ACPICA_DEBUGGER = $(ACPICA_CORE)/debugger +ACPICA_DISASSEMBLER = $(ACPICA_CORE)/disassembler +ACPICA_DISPATCHER = $(ACPICA_CORE)/dispatcher +ACPICA_EVENTS = $(ACPICA_CORE)/events +ACPICA_EXECUTER = $(ACPICA_CORE)/executer +ACPICA_HARDWARE = $(ACPICA_CORE)/hardware +ACPICA_NAMESPACE = $(ACPICA_CORE)/namespace +ACPICA_PARSER = $(ACPICA_CORE)/parser +ACPICA_RESOURCES = $(ACPICA_CORE)/resources +ACPICA_TABLES = $(ACPICA_CORE)/tables +ACPICA_UTILITIES = $(ACPICA_CORE)/utilities +ACPISRC = $(ACPICA_TOOLS)/acpisrc +INSTALLDIR = /usr/bin +INSTALLPROG = cp --remove-destination $(PROG) $(INSTALLDIR) + +ACPICA_HEADERS = \ + $(wildcard $(ACPICA_INCLUDE)/*.h) \ + $(wildcard $(ACPICA_INCLUDE)/platform/*.h) + +# +# Search path for source files and individual source files +# +vpath %.c \ + $(ACPISRC) \ + $(ACPICA_COMMON) \ + $(ACPICA_OSL) + +HEADERS = \ + $(wildcard $(ACPISRC)/*.h) + +OBJECTS = \ + ascase.o \ + asconvrt.o \ + asfile.o \ + asmain.o \ + asremove.o \ + astable.o \ + asutils.o \ + osunixdir.o \ + getopt.o + +CFLAGS+= \ + -D$(HOST) \ + -D_GNU_SOURCE \ + -DACPI_SRC_APP \ + -I$(ACPISRC) \ + -I$(ACPICA_INCLUDE) + +CWARNINGFLAGS = \ + -ansi \ + -Wall \ + -Wbad-function-cast \ + -Wdeclaration-after-statement \ + -Werror \ + -Wformat=2 \ + -Wmissing-declarations \ + -Wmissing-prototypes \ + -Wstrict-aliasing=0 \ + -Wstrict-prototypes \ + -Wswitch-default \ + -Wpointer-arith \ + -Wundef + +# +# gcc 4+ flags +# +CWARNINGFLAGS += \ + -Waddress \ + -Waggregate-return \ + -Wchar-subscripts \ + -Wempty-body \ + -Wlogical-op \ + -Wmissing-declarations \ + -Wmissing-field-initializers \ + -Wmissing-parameter-type \ + -Wnested-externs \ + -Wold-style-declaration \ + -Wold-style-definition \ + -Wredundant-decls \ + -Wtype-limits + +# +# Rules +# +$(PROG) : $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) -o $(PROG) + +%.o : %.c $(HEADERS) $(ACPICA_HEADERS) + $(COMPILE) + +clean : + rm -f $(PROG) $(PROG).exe $(OBJECTS) + +install : + $(INSTALLPROG) diff --git a/source/tools/acpisrc/acpisrc.h b/source/tools/acpisrc/acpisrc.h new file mode 100644 index 000000000000..3c0e5dc01d05 --- /dev/null +++ b/source/tools/acpisrc/acpisrc.h @@ -0,0 +1,405 @@ + +/****************************************************************************** + * + * Module Name: acpisrc.h - Include file for AcpiSrc utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#define LINES_IN_LEGAL_HEADER 105 /* See above */ +#define LEGAL_HEADER_SIGNATURE " * 2.1. This is your license from Intel Corp. under its intellectual property" +#define LINES_IN_LINUX_HEADER 34 +#define LINUX_HEADER_SIGNATURE " * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS" +#define LINES_IN_ASL_HEADER 29 /* Header as output from disassembler */ + +#include "acpi.h" +#include "accommon.h" + +#include <stdio.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> +#include <ctype.h> +#ifdef WIN32 +#include <io.h> +#include <direct.h> +#endif +#include <errno.h> + + +/* O_BINARY is not always defined */ +#ifndef O_BINARY +#define O_BINARY 0x0 +#endif + +/* Fixups for non-Win32 compilation */ +#ifndef WIN32 +#define mkdir(x) mkdir(x, 0770) +char * strlwr(char* str); +#endif + + +/* Constants */ + +#define ASRC_MAX_FILE_SIZE (1024 * 100) + +#define FILE_TYPE_SOURCE 1 +#define FILE_TYPE_HEADER 2 +#define FILE_TYPE_DIRECTORY 3 + +#define CVT_COUNT_TABS 0x00000001 +#define CVT_COUNT_NON_ANSI_COMMENTS 0x00000002 +#define CVT_TRIM_LINES 0x00000004 +#define CVT_CHECK_BRACES 0x00000008 +#define CVT_COUNT_LINES 0x00000010 +#define CVT_BRACES_ON_SAME_LINE 0x00000020 +#define CVT_MIXED_CASE_TO_UNDERSCORES 0x00000040 +#define CVT_LOWER_CASE_IDENTIFIERS 0x00000080 +#define CVT_REMOVE_DEBUG_MACROS 0x00000100 +#define CVT_TRIM_WHITESPACE 0x00000200 /* Should be after all line removal */ +#define CVT_REMOVE_EMPTY_BLOCKS 0x00000400 /* Should be after trimming lines */ +#define CVT_REDUCE_TYPEDEFS 0x00000800 +#define CVT_COUNT_SHORTMULTILINE_COMMENTS 0x00001000 +#define CVT_SPACES_TO_TABS4 0x40000000 /* Tab conversion should be last */ +#define CVT_SPACES_TO_TABS8 0x80000000 /* Tab conversion should be last */ + +#define FLG_DEFAULT_FLAGS 0x00000000 +#define FLG_NO_CARRIAGE_RETURNS 0x00000001 +#define FLG_NO_FILE_OUTPUT 0x00000002 +#define FLG_LOWERCASE_DIRNAMES 0x00000004 + +#define AS_START_IGNORE "/*!" +#define AS_STOP_IGNORE "!*/" + + +/* Globals */ + +extern UINT32 Gbl_Files; +extern UINT32 Gbl_MissingBraces; +extern UINT32 Gbl_Tabs; +extern UINT32 Gbl_NonAnsiComments; +extern UINT32 Gbl_SourceLines; +extern UINT32 Gbl_WhiteLines; +extern UINT32 Gbl_CommentLines; +extern UINT32 Gbl_LongLines; +extern UINT32 Gbl_TotalLines; +extern UINT32 Gbl_HeaderSize; +extern UINT32 Gbl_HeaderLines; +extern struct stat Gbl_StatBuf; +extern char *Gbl_FileBuffer; +extern UINT32 Gbl_TotalSize; +extern UINT32 Gbl_FileSize; +extern UINT32 Gbl_FileType; +extern BOOLEAN Gbl_VerboseMode; +extern BOOLEAN Gbl_QuietMode; +extern BOOLEAN Gbl_BatchMode; +extern BOOLEAN Gbl_MadeChanges; +extern BOOLEAN Gbl_Overwrite; +extern BOOLEAN Gbl_WidenDeclarations; +extern BOOLEAN Gbl_IgnoreLoneLineFeeds; +extern BOOLEAN Gbl_HasLoneLineFeeds; +extern void *Gbl_StructDefs; + +#define PARAM_LIST(pl) pl +#define TERSE_PRINT(a) if (!Gbl_VerboseMode) printf PARAM_LIST(a) +#define VERBOSE_PRINT(a) if (Gbl_VerboseMode) printf PARAM_LIST(a) + +#define REPLACE_WHOLE_WORD 0x00 +#define REPLACE_SUBSTRINGS 0x01 +#define REPLACE_MASK 0x01 + +#define EXTRA_INDENT_C 0x02 + + +/* Conversion table structs */ + +typedef struct acpi_string_table +{ + char *Target; + char *Replacement; + UINT8 Type; + +} ACPI_STRING_TABLE; + + +typedef struct acpi_typed_identifier_table +{ + char *Identifier; + UINT8 Type; + +} ACPI_TYPED_IDENTIFIER_TABLE; + +#define SRC_TYPE_SIMPLE 0 +#define SRC_TYPE_STRUCT 1 +#define SRC_TYPE_UNION 2 + + +typedef struct acpi_identifier_table +{ + char *Identifier; + +} ACPI_IDENTIFIER_TABLE; + +typedef struct acpi_conversion_table +{ + char *NewHeader; + UINT32 Flags; + + ACPI_TYPED_IDENTIFIER_TABLE *LowerCaseTable; + + ACPI_STRING_TABLE *SourceStringTable; + ACPI_IDENTIFIER_TABLE *SourceLineTable; + ACPI_IDENTIFIER_TABLE *SourceConditionalTable; + ACPI_IDENTIFIER_TABLE *SourceMacroTable; + ACPI_TYPED_IDENTIFIER_TABLE *SourceStructTable; + UINT32 SourceFunctions; + + ACPI_STRING_TABLE *HeaderStringTable; + ACPI_IDENTIFIER_TABLE *HeaderLineTable; + ACPI_IDENTIFIER_TABLE *HeaderConditionalTable; + ACPI_IDENTIFIER_TABLE *HeaderMacroTable; + ACPI_TYPED_IDENTIFIER_TABLE *HeaderStructTable; + UINT32 HeaderFunctions; + +} ACPI_CONVERSION_TABLE; + + +/* Conversion tables */ + +extern ACPI_CONVERSION_TABLE LinuxConversionTable; +extern ACPI_CONVERSION_TABLE CleanupConversionTable; +extern ACPI_CONVERSION_TABLE StatsConversionTable; +extern ACPI_CONVERSION_TABLE CustomConversionTable; +extern ACPI_CONVERSION_TABLE LicenseConversionTable; + + +/* Prototypes */ + +char * +AsSkipUntilChar ( + char *Buffer, + char Target); + +char * +AsSkipPastChar ( + char *Buffer, + char Target); + +char * +AsReplaceData ( + char *Buffer, + UINT32 LengthToRemove, + char *BufferToAdd, + UINT32 LengthToAdd); + +int +AsReplaceString ( + char *Target, + char *Replacement, + UINT8 Type, + char *Buffer); + +int +AsLowerCaseString ( + char *Target, + char *Buffer); + +void +AsRemoveLine ( + char *Buffer, + char *Keyword); + +void +AsRemoveMacro ( + char *Buffer, + char *Keyword); + +void +AsCheckForBraces ( + char *Buffer, + char *Filename); + +void +AsTrimLines ( + char *Buffer, + char *Filename); + +void +AsMixedCaseToUnderscores ( + char *Buffer); + +void +AsCountTabs ( + char *Buffer, + char *Filename); + +void +AsBracesOnSameLine ( + char *Buffer); + +void +AsLowerCaseIdentifiers ( + char *Buffer); + +void +AsReduceTypedefs ( + char *Buffer, + char *Keyword); + +void +AsRemoveDebugMacros ( + char *Buffer); + +void +AsRemoveEmptyBlocks ( + char *Buffer, + char *Filename); + +void +AsCountSourceLines ( + char *Buffer, + char *Filename); + +void +AsCountNonAnsiComments ( + char *Buffer, + char *Filename); + +void +AsTrimWhitespace ( + char *Buffer); + +void +AsTabify4 ( + char *Buffer); + +void +AsTabify8 ( + char *Buffer); + +void +AsRemoveConditionalCompile ( + char *Buffer, + char *Keyword); + +ACPI_NATIVE_INT +AsProcessTree ( + ACPI_CONVERSION_TABLE *ConversionTable, + char *SourcePath, + char *TargetPath); + +int +AsGetFile ( + char *FileName, + char **FileBuffer, + UINT32 *FileSize); + +int +AsPutFile ( + char *Pathname, + char *FileBuffer, + UINT32 SystemFlags); + +void +AsReplaceHeader ( + char *Buffer, + char *NewHeader); + +void +AsConvertFile ( + ACPI_CONVERSION_TABLE *ConversionTable, + char *FileBuffer, + char *Filename, + ACPI_NATIVE_INT FileType); + +ACPI_NATIVE_INT +AsProcessOneFile ( + ACPI_CONVERSION_TABLE *ConversionTable, + char *SourcePath, + char *TargetPath, + int MaxPathLength, + char *Filename, + ACPI_NATIVE_INT FileType); + +ACPI_NATIVE_INT +AsCheckForDirectory ( + char *SourceDirPath, + char *TargetDirPath, + char *Filename, + char **SourcePath, + char **TargetPath); + +BOOLEAN +AsMatchExactWord ( + char *Word, + UINT32 WordLength); + +void +AsPrint ( + char *Message, + UINT32 Count, + char *Filename); + +void +AsInsertPrefix ( + char *Buffer, + char *Keyword, + UINT8 Type); + +char * +AsInsertData ( + char *Buffer, + char *BufferToAdd, + UINT32 LengthToAdd); + +char * +AsRemoveData ( + char *StartPointer, + char *EndPointer); + +void +AsInsertCarriageReturns ( + char *Buffer); + +void +AsConvertToLineFeeds ( + char *Buffer); + + diff --git a/source/tools/acpisrc/ascase.c b/source/tools/acpisrc/ascase.c new file mode 100644 index 000000000000..232ebe8b18fc --- /dev/null +++ b/source/tools/acpisrc/ascase.c @@ -0,0 +1,574 @@ + +/****************************************************************************** + * + * Module Name: ascase - Source conversion - lower/upper case utilities + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpisrc.h" + +/* Local prototypes */ + +void +AsUppercaseTokens ( + char *Buffer, + char *PrefixString); + + +/****************************************************************************** + * + * FUNCTION: AsLowerCaseString + * + * DESCRIPTION: LowerCase all instances of a target string with a replacement + * string. Returns count of the strings replaced. + * + ******************************************************************************/ + +int +AsLowerCaseString ( + char *Target, + char *Buffer) +{ + char *SubString1; + char *SubString2; + char *SubBuffer; + int TargetLength; + int LowerCaseCount = 0; + int i; + + + TargetLength = strlen (Target); + + SubBuffer = Buffer; + SubString1 = Buffer; + + while (SubString1) + { + /* Find the target string */ + + SubString1 = strstr (SubBuffer, Target); + if (!SubString1) + { + return LowerCaseCount; + } + + /* + * Check for translation escape string -- means to ignore + * blocks of code while replacing + */ + SubString2 = strstr (SubBuffer, AS_START_IGNORE); + + if ((SubString2) && + (SubString2 < SubString1)) + { + /* Find end of the escape block starting at "Substring2" */ + + SubString2 = strstr (SubString2, AS_STOP_IGNORE); + if (!SubString2) + { + /* Didn't find terminator */ + + return LowerCaseCount; + } + + /* Move buffer to end of escape block and continue */ + + SubBuffer = SubString2; + } + + /* Do the actual replace if the target was found */ + + else + { + if (!AsMatchExactWord (SubString1, TargetLength)) + { + SubBuffer = SubString1 + 1; + continue; + } + + for (i = 0; i < TargetLength; i++) + { + SubString1[i] = (char) tolower ((int) SubString1[i]); + } + + SubBuffer = SubString1 + TargetLength; + + if ((Gbl_WidenDeclarations) && (!Gbl_StructDefs)) + { + if ((SubBuffer[0] == ' ') && (SubBuffer[1] == ' ')) + { + AsInsertData (SubBuffer, " ", 8); + } + } + + LowerCaseCount++; + } + } + + return LowerCaseCount; +} + + +/****************************************************************************** + * + * FUNCTION: AsMixedCaseToUnderscores + * + * DESCRIPTION: Converts mixed case identifiers to underscored identifiers. + * for example, + * + * ThisUsefullyNamedIdentifier becomes: + * + * this_usefully_named_identifier + * + ******************************************************************************/ + +void +AsMixedCaseToUnderscores ( + char *Buffer) +{ + UINT32 Length; + char *SubBuffer = Buffer; + char *TokenEnd; + char *TokenStart = NULL; + char *SubString; + BOOLEAN HasLowerCase = FALSE; + + + while (*SubBuffer) + { + /* Ignore whitespace */ + + if (*SubBuffer == ' ') + { + while (*SubBuffer == ' ') + { + SubBuffer++; + } + TokenStart = NULL; + HasLowerCase = FALSE; + continue; + } + + /* Ignore commas */ + + if ((*SubBuffer == ',') || + (*SubBuffer == '>') || + (*SubBuffer == ')')) + { + SubBuffer++; + TokenStart = NULL; + HasLowerCase = FALSE; + continue; + } + + /* Check for quoted string -- ignore */ + + if (*SubBuffer == '"') + { + SubBuffer++; + while (*SubBuffer != '"') + { + if (!*SubBuffer) + { + return; + } + + /* Handle embedded escape sequences */ + + if (*SubBuffer == '\\') + { + SubBuffer++; + } + SubBuffer++; + } + SubBuffer++; + continue; + } + + if (islower ((int) *SubBuffer)) + { + HasLowerCase = TRUE; + } + + /* + * Check for translation escape string -- means to ignore + * blocks of code while replacing + */ + if ((SubBuffer[0] == '/') && + (SubBuffer[1] == '*') && + (SubBuffer[2] == '!')) + { + SubBuffer = strstr (SubBuffer, "!*/"); + if (!SubBuffer) + { + return; + } + continue; + } + + /* Ignore hex constants */ + + if (SubBuffer[0] == '0') + { + if ((SubBuffer[1] == 'x') || + (SubBuffer[1] == 'X')) + { + SubBuffer += 2; + while (isxdigit ((int) *SubBuffer)) + { + SubBuffer++; + } + continue; + } + } + +/* OBSOLETE CODE, all quoted strings now completely ignored. */ +#if 0 + /* Ignore format specification fields */ + + if (SubBuffer[0] == '%') + { + SubBuffer++; + + while ((isalnum (*SubBuffer)) || (*SubBuffer == '.')) + { + SubBuffer++; + } + + continue; + } +#endif + + /* Ignore standard escape sequences (\n, \r, etc.) Not Hex or Octal escapes */ + + if (SubBuffer[0] == '\\') + { + SubBuffer += 2; + continue; + } + + /* + * Ignore identifiers that already contain embedded underscores + * These are typically C macros or defines (all upper case) + * Note: there are some cases where identifiers have underscores + * AcpiGbl_* for example. HasLowerCase flag handles these. + */ + if ((*SubBuffer == '_') && (!HasLowerCase) && (TokenStart)) + { + /* Check the rest of the identifier for any lower case letters */ + + SubString = SubBuffer; + while ((isalnum ((int) *SubString)) || (*SubString == '_')) + { + if (islower ((int) *SubString)) + { + HasLowerCase = TRUE; + } + SubString++; + } + + /* If no lower case letters, we can safely ignore the entire token */ + + if (!HasLowerCase) + { + SubBuffer = SubString; + continue; + } + } + + /* A capital letter may indicate the start of a token; save it */ + + if (isupper ((int) SubBuffer[0])) + { + TokenStart = SubBuffer; + } + + /* + * Convert each pair of letters that matches the form: + * + * <LowerCase><UpperCase> + * to + * <LowerCase><Underscore><LowerCase> + */ + else if ((islower ((int) SubBuffer[0]) || isdigit ((int) SubBuffer[0])) && + (isupper ((int) SubBuffer[1]))) + { + if (isdigit ((int) SubBuffer[0])) + { + /* Ignore <UpperCase><Digit><UpperCase> */ + /* Ignore <Underscore><Digit><UpperCase> */ + + if (isupper ((int) *(SubBuffer-1)) || + *(SubBuffer-1) == '_') + { + SubBuffer++; + continue; + } + } + + /* + * Matched the pattern. + * Find the end of this identifier (token) + */ + TokenEnd = SubBuffer; + while ((isalnum ((int) *TokenEnd)) || (*TokenEnd == '_')) + { + TokenEnd++; + } + + /* Force the UpperCase letter (#2) to lower case */ + + Gbl_MadeChanges = TRUE; + SubBuffer[1] = (char) tolower ((int) SubBuffer[1]); + + SubString = TokenEnd; + Length = 0; + + while (*SubString != '\n') + { + /* + * If we have at least two trailing spaces, we can get rid of + * one to make up for the newly inserted underscore. This will + * help preserve the alignment of the text + */ + if ((SubString[0] == ' ') && + (SubString[1] == ' ')) + { + Length = SubString - SubBuffer - 2; + break; + } + + SubString++; + } + + if (!Length) + { + Length = strlen (&SubBuffer[1]); + } + + memmove (&SubBuffer[2], &SubBuffer[1], Length + 1); + SubBuffer[1] = '_'; + SubBuffer +=2; + + /* Lower case the leading character of the token */ + + if (TokenStart) + { + *TokenStart = (char) tolower ((int) *TokenStart); + TokenStart = NULL; + } + } + + SubBuffer++; + } +} + + +/****************************************************************************** + * + * FUNCTION: AsLowerCaseIdentifiers + * + * DESCRIPTION: Converts mixed case identifiers to lower case. Leaves comments, + * quoted strings, and all-upper-case macros alone. + * + ******************************************************************************/ + +void +AsLowerCaseIdentifiers ( + char *Buffer) +{ + char *SubBuffer = Buffer; + + + while (*SubBuffer) + { + /* + * Check for translation escape string -- means to ignore + * blocks of code while replacing + */ + if ((SubBuffer[0] == '/') && + (SubBuffer[1] == '*') && + (SubBuffer[2] == '!')) + { + SubBuffer = strstr (SubBuffer, "!*/"); + if (!SubBuffer) + { + return; + } + } + + /* Ignore comments */ + + if ((SubBuffer[0] == '/') && + (SubBuffer[1] == '*')) + { + SubBuffer = strstr (SubBuffer, "*/"); + if (!SubBuffer) + { + return; + } + + SubBuffer += 2; + } + + /* Ignore quoted strings */ + + if ((SubBuffer[0] == '\"') && (SubBuffer[1] != '\'')) + { + SubBuffer++; + + /* Find the closing quote */ + + while (SubBuffer[0]) + { + /* Ignore escaped quote characters */ + + if (SubBuffer[0] == '\\') + { + SubBuffer++; + } + else if (SubBuffer[0] == '\"') + { + SubBuffer++; + break; + } + SubBuffer++; + } + } + + if (!SubBuffer[0]) + { + return; + } + + /* + * Only lower case if we have an upper followed by a lower + * This leaves the all-uppercase things (macros, etc.) intact + */ + if ((isupper ((int) SubBuffer[0])) && + (islower ((int) SubBuffer[1]))) + { + Gbl_MadeChanges = TRUE; + *SubBuffer = (char) tolower ((int) *SubBuffer); + } + + SubBuffer++; + } +} + + +/****************************************************************************** + * + * FUNCTION: AsUppercaseTokens + * + * DESCRIPTION: Force to uppercase all tokens that begin with the prefix string. + * used to convert mixed-case macros and constants to uppercase. + * + ******************************************************************************/ + +void +AsUppercaseTokens ( + char *Buffer, + char *PrefixString) +{ + char *SubBuffer; + char *TokenEnd; + char *SubString; + int i; + UINT32 Length; + + + SubBuffer = Buffer; + + while (SubBuffer) + { + SubBuffer = strstr (SubBuffer, PrefixString); + if (SubBuffer) + { + TokenEnd = SubBuffer; + while ((isalnum ((int) *TokenEnd)) || (*TokenEnd == '_')) + { + TokenEnd++; + } + + for (i = 0; i < (TokenEnd - SubBuffer); i++) + { + if ((islower ((int) SubBuffer[i])) && + (isupper ((int) SubBuffer[i+1]))) + { + + SubString = TokenEnd; + Length = 0; + + while (*SubString != '\n') + { + if ((SubString[0] == ' ') && + (SubString[1] == ' ')) + { + Length = SubString - &SubBuffer[i] - 2; + break; + } + + SubString++; + } + + if (!Length) + { + Length = strlen (&SubBuffer[i+1]); + } + + memmove (&SubBuffer[i+2], &SubBuffer[i+1], (Length+1)); + SubBuffer[i+1] = '_'; + i +=2; + TokenEnd++; + } + } + + for (i = 0; i < (TokenEnd - SubBuffer); i++) + { + SubBuffer[i] = (char) toupper ((int) SubBuffer[i]); + } + + SubBuffer = TokenEnd; + } + } +} + + diff --git a/source/tools/acpisrc/asconvrt.c b/source/tools/acpisrc/asconvrt.c new file mode 100644 index 000000000000..1669f9d20e79 --- /dev/null +++ b/source/tools/acpisrc/asconvrt.c @@ -0,0 +1,1448 @@ + +/****************************************************************************** + * + * Module Name: asconvrt - Source conversion code + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpisrc.h" + +/* Local prototypes */ + +char * +AsCheckAndSkipLiterals ( + char *Buffer, + UINT32 *TotalLines); + +UINT32 +AsCountLines ( + char *Buffer, + char *Filename); + +/* Opening signature of the Intel legal header */ + +char *HeaderBegin = "/******************************************************************************\n *\n * 1. Copyright Notice"; + + +/****************************************************************************** + * + * FUNCTION: AsMatchExactWord + * + * DESCRIPTION: Check previous and next characters for whitespace + * + ******************************************************************************/ + +BOOLEAN +AsMatchExactWord ( + char *Word, + UINT32 WordLength) +{ + char NextChar; + char PrevChar; + + + NextChar = Word[WordLength]; + PrevChar = * (Word -1); + + if (isalnum ((int) NextChar) || + (NextChar == '_') || + isalnum ((int) PrevChar) || + (PrevChar == '_')) + { + return (FALSE); + } + + return (TRUE); +} + + +/****************************************************************************** + * + * FUNCTION: AsPrint + * + * DESCRIPTION: Common formatted print + * + ******************************************************************************/ + +void +AsPrint ( + char *Message, + UINT32 Count, + char *Filename) +{ + + if (Gbl_QuietMode) + { + return; + } + + printf ("-- %4u %28.28s : %s\n", Count, Message, Filename); +} + + +/****************************************************************************** + * + * FUNCTION: AsCheckAndSkipLiterals + * + * DESCRIPTION: Generic routine to skip comments and quoted string literals. + * Keeps a line count. + * + ******************************************************************************/ + +char * +AsCheckAndSkipLiterals ( + char *Buffer, + UINT32 *TotalLines) +{ + UINT32 NewLines = 0; + char *SubBuffer = Buffer; + char *LiteralEnd; + + + /* Ignore comments */ + + if ((SubBuffer[0] == '/') && + (SubBuffer[1] == '*')) + { + LiteralEnd = strstr (SubBuffer, "*/"); + SubBuffer += 2; /* Get past comment opening */ + + if (!LiteralEnd) + { + return SubBuffer; + } + + while (SubBuffer < LiteralEnd) + { + if (*SubBuffer == '\n') + { + NewLines++; + } + + SubBuffer++; + } + + SubBuffer += 2; /* Get past comment close */ + } + + /* Ignore quoted strings */ + + else if (*SubBuffer == '\"') + { + SubBuffer++; + LiteralEnd = AsSkipPastChar (SubBuffer, '\"'); + if (!LiteralEnd) + { + return SubBuffer; + } + } + + if (TotalLines) + { + (*TotalLines) += NewLines; + } + return SubBuffer; +} + + +/****************************************************************************** + * + * FUNCTION: AsAsCheckForBraces + * + * DESCRIPTION: Check for an open brace after each if statement + * + ******************************************************************************/ + +void +AsCheckForBraces ( + char *Buffer, + char *Filename) +{ + char *SubBuffer = Buffer; + char *NextBrace; + char *NextSemicolon; + char *NextIf; + UINT32 TotalLines = 1; + + + while (*SubBuffer) + { + + SubBuffer = AsCheckAndSkipLiterals (SubBuffer, &TotalLines); + + if (*SubBuffer == '\n') + { + TotalLines++; + } + else if (!(strncmp (" if", SubBuffer, 3))) + { + SubBuffer += 2; + NextBrace = strstr (SubBuffer, "{"); + NextSemicolon = strstr (SubBuffer, ";"); + NextIf = strstr (SubBuffer, " if"); + + if ((!NextBrace) || + (NextSemicolon && (NextBrace > NextSemicolon)) || + (NextIf && (NextBrace > NextIf))) + { + Gbl_MissingBraces++; + + if (!Gbl_QuietMode) + { + printf ("Missing braces for <if>, line %u: %s\n", TotalLines, Filename); + } + } + } + else if (!(strncmp (" else if", SubBuffer, 8))) + { + SubBuffer += 7; + NextBrace = strstr (SubBuffer, "{"); + NextSemicolon = strstr (SubBuffer, ";"); + NextIf = strstr (SubBuffer, " if"); + + if ((!NextBrace) || + (NextSemicolon && (NextBrace > NextSemicolon)) || + (NextIf && (NextBrace > NextIf))) + { + Gbl_MissingBraces++; + + if (!Gbl_QuietMode) + { + printf ("Missing braces for <if>, line %u: %s\n", TotalLines, Filename); + } + } + } + else if (!(strncmp (" else", SubBuffer, 5))) + { + SubBuffer += 4; + NextBrace = strstr (SubBuffer, "{"); + NextSemicolon = strstr (SubBuffer, ";"); + NextIf = strstr (SubBuffer, " if"); + + if ((!NextBrace) || + (NextSemicolon && (NextBrace > NextSemicolon)) || + (NextIf && (NextBrace > NextIf))) + { + Gbl_MissingBraces++; + + if (!Gbl_QuietMode) + { + printf ("Missing braces for <else>, line %u: %s\n", TotalLines, Filename); + } + } + } + + SubBuffer++; + } +} + + +/****************************************************************************** + * + * FUNCTION: AsTrimLines + * + * DESCRIPTION: Remove extra blanks from the end of source lines. Does not + * check for tabs. + * + ******************************************************************************/ + +void +AsTrimLines ( + char *Buffer, + char *Filename) +{ + char *SubBuffer = Buffer; + char *StartWhiteSpace = NULL; + UINT32 SpaceCount = 0; + + + while (*SubBuffer) + { + while (*SubBuffer != '\n') + { + if (!*SubBuffer) + { + goto Exit; + } + + if (*SubBuffer == ' ') + { + if (!StartWhiteSpace) + { + StartWhiteSpace = SubBuffer; + } + } + else + { + StartWhiteSpace = NULL; + } + + SubBuffer++; + } + + if (StartWhiteSpace) + { + SpaceCount += (SubBuffer - StartWhiteSpace); + + /* Remove the spaces */ + + SubBuffer = AsRemoveData (StartWhiteSpace, SubBuffer); + StartWhiteSpace = NULL; + } + + SubBuffer++; + } + + +Exit: + if (SpaceCount) + { + Gbl_MadeChanges = TRUE; + AsPrint ("Extraneous spaces removed", SpaceCount, Filename); + } +} + + +/****************************************************************************** + * + * FUNCTION: AsTrimWhitespace + * + * DESCRIPTION: Remove "excess" blank lines - any more than 2 blank lines. + * this can happen during the translation when lines are removed. + * + ******************************************************************************/ + +void +AsTrimWhitespace ( + char *Buffer) +{ + int ReplaceCount = 1; + + + while (ReplaceCount) + { + ReplaceCount = AsReplaceString ("\n\n\n\n", "\n\n\n", REPLACE_SUBSTRINGS, Buffer); + } +} + + +/****************************************************************************** + * + * FUNCTION: AsReplaceHeader + * + * DESCRIPTION: Replace the default Intel legal header with a new header + * + ******************************************************************************/ + +void +AsReplaceHeader ( + char *Buffer, + char *NewHeader) +{ + char *SubBuffer; + char *TokenEnd; + + + /* Find the original header */ + + SubBuffer = strstr (Buffer, HeaderBegin); + if (!SubBuffer) + { + return; + } + + /* Find the end of the original header */ + + TokenEnd = strstr (SubBuffer, "*/"); + TokenEnd = AsSkipPastChar (TokenEnd, '\n'); + + /* Delete old header, insert new one */ + + AsReplaceData (SubBuffer, TokenEnd - SubBuffer, NewHeader, strlen (NewHeader)); +} + + +/****************************************************************************** + * + * FUNCTION: AsReplaceString + * + * DESCRIPTION: Replace all instances of a target string with a replacement + * string. Returns count of the strings replaced. + * + ******************************************************************************/ + +int +AsReplaceString ( + char *Target, + char *Replacement, + UINT8 Type, + char *Buffer) +{ + char *SubString1; + char *SubString2; + char *SubBuffer; + int TargetLength; + int ReplacementLength; + int ReplaceCount = 0; + + + TargetLength = strlen (Target); + ReplacementLength = strlen (Replacement); + + SubBuffer = Buffer; + SubString1 = Buffer; + + while (SubString1) + { + /* Find the target string */ + + SubString1 = strstr (SubBuffer, Target); + if (!SubString1) + { + return ReplaceCount; + } + + /* + * Check for translation escape string -- means to ignore + * blocks of code while replacing + */ + SubString2 = strstr (SubBuffer, AS_START_IGNORE); + + if ((SubString2) && + (SubString2 < SubString1)) + { + /* Find end of the escape block starting at "Substring2" */ + + SubString2 = strstr (SubString2, AS_STOP_IGNORE); + if (!SubString2) + { + /* Didn't find terminator */ + + return ReplaceCount; + } + + /* Move buffer to end of escape block and continue */ + + SubBuffer = SubString2; + } + + /* Do the actual replace if the target was found */ + + else + { + if ((Type & REPLACE_MASK) == REPLACE_WHOLE_WORD) + { + if (!AsMatchExactWord (SubString1, TargetLength)) + { + SubBuffer = SubString1 + 1; + continue; + } + } + + SubBuffer = AsReplaceData (SubString1, TargetLength, Replacement, ReplacementLength); + + if ((Type & EXTRA_INDENT_C) && + (!Gbl_StructDefs)) + { + SubBuffer = AsInsertData (SubBuffer, " ", 8); + } + + ReplaceCount++; + } + } + + return ReplaceCount; +} + + +/****************************************************************************** + * + * FUNCTION: AsConvertToLineFeeds + * + * DESCRIPTION: + * + ******************************************************************************/ + +void +AsConvertToLineFeeds ( + char *Buffer) +{ + char *SubString; + char *SubBuffer; + + + SubBuffer = Buffer; + SubString = Buffer; + + while (SubString) + { + /* Find the target string */ + + SubString = strstr (SubBuffer, "\r\n"); + if (!SubString) + { + return; + } + + SubBuffer = AsReplaceData (SubString, 1, NULL, 0); + } + return; +} + + +/****************************************************************************** + * + * FUNCTION: AsInsertCarriageReturns + * + * DESCRIPTION: + * + ******************************************************************************/ + +void +AsInsertCarriageReturns ( + char *Buffer) +{ + char *SubString; + char *SubBuffer; + + + SubBuffer = Buffer; + SubString = Buffer; + + while (SubString) + { + /* Find the target string */ + + SubString = strstr (SubBuffer, "\n"); + if (!SubString) + { + return; + } + + SubBuffer = AsInsertData (SubString, "\r", 1); + SubBuffer += 1; + } + return; +} + + +/****************************************************************************** + * + * FUNCTION: AsBracesOnSameLine + * + * DESCRIPTION: Move opening braces up to the same line as an if, for, else, + * or while statement (leave function opening brace on separate + * line). + * + ******************************************************************************/ + +void +AsBracesOnSameLine ( + char *Buffer) +{ + char *SubBuffer = Buffer; + char *Beginning; + char *StartOfThisLine; + char *Next; + BOOLEAN BlockBegin = TRUE; + + + while (*SubBuffer) + { + /* Ignore comments */ + + if ((SubBuffer[0] == '/') && + (SubBuffer[1] == '*')) + { + SubBuffer = strstr (SubBuffer, "*/"); + if (!SubBuffer) + { + return; + } + + SubBuffer += 2; + continue; + } + + /* Ignore quoted strings */ + + if (*SubBuffer == '\"') + { + SubBuffer++; + SubBuffer = AsSkipPastChar (SubBuffer, '\"'); + if (!SubBuffer) + { + return; + } + } + + if (!strncmp ("\n}", SubBuffer, 2)) + { + /* + * A newline followed by a closing brace closes a function + * or struct or initializer block + */ + BlockBegin = TRUE; + } + + /* + * Move every standalone brace up to the previous line + * Check for digit will ignore initializer lists surrounded by braces. + * This will work until we we need more complex detection. + */ + if ((*SubBuffer == '{') && !isdigit ((int) SubBuffer[1])) + { + if (BlockBegin) + { + BlockBegin = FALSE; + } + else + { + /* + * Backup to previous non-whitespace + */ + Beginning = SubBuffer - 1; + while ((*Beginning == ' ') || + (*Beginning == '\n')) + { + Beginning--; + } + + StartOfThisLine = Beginning; + while (*StartOfThisLine != '\n') + { + StartOfThisLine--; + } + + /* + * Move the brace up to the previous line, UNLESS: + * + * 1) There is a conditional compile on the line (starts with '#') + * 2) Previous line ends with an '=' (Start of initializer block) + * 3) Previous line ends with a comma (part of an init list) + * 4) Previous line ends with a backslash (part of a macro) + */ + if ((StartOfThisLine[1] != '#') && + (*Beginning != '\\') && + (*Beginning != '/') && + (*Beginning != '{') && + (*Beginning != '=') && + (*Beginning != ',')) + { + Beginning++; + SubBuffer++; + + Gbl_MadeChanges = TRUE; + +#ifdef ADD_EXTRA_WHITESPACE + AsReplaceData (Beginning, SubBuffer - Beginning, " {\n", 3); +#else + /* Find non-whitespace start of next line */ + + Next = SubBuffer + 1; + while ((*Next == ' ') || + (*Next == '\t')) + { + Next++; + } + + /* Find non-whitespace start of this line */ + + StartOfThisLine++; + while ((*StartOfThisLine == ' ') || + (*StartOfThisLine == '\t')) + { + StartOfThisLine++; + } + + /* + * Must be a single-line comment to need more whitespace + * Even then, we don't need more if the previous statement + * is an "else". + */ + if ((Next[0] == '/') && + (Next[1] == '*') && + (Next[2] != '\n') && + + (!strncmp (StartOfThisLine, "else if", 7) || + !strncmp (StartOfThisLine, "else while", 10) || + strncmp (StartOfThisLine, "else", 4))) + { + AsReplaceData (Beginning, SubBuffer - Beginning, " {\n", 3); + } + else + { + AsReplaceData (Beginning, SubBuffer - Beginning, " {", 2); + } +#endif + } + } + } + + SubBuffer++; + } +} + + +/****************************************************************************** + * + * FUNCTION: AsTabify4 + * + * DESCRIPTION: Convert the text to tabbed text. Alignment of text is + * preserved. + * + ******************************************************************************/ + +void +AsTabify4 ( + char *Buffer) +{ + char *SubBuffer = Buffer; + char *NewSubBuffer; + UINT32 SpaceCount = 0; + UINT32 Column = 0; + + + while (*SubBuffer) + { + if (*SubBuffer == '\n') + { + Column = 0; + } + else + { + Column++; + } + + /* Ignore comments */ + + if ((SubBuffer[0] == '/') && + (SubBuffer[1] == '*')) + { + SubBuffer = strstr (SubBuffer, "*/"); + if (!SubBuffer) + { + return; + } + + SubBuffer += 2; + continue; + } + + /* Ignore quoted strings */ + + if (*SubBuffer == '\"') + { + SubBuffer++; + SubBuffer = AsSkipPastChar (SubBuffer, '\"'); + if (!SubBuffer) + { + return; + } + SpaceCount = 0; + } + + if (*SubBuffer == ' ') + { + SpaceCount++; + + if (SpaceCount >= 4) + { + SpaceCount = 0; + + NewSubBuffer = (SubBuffer + 1) - 4; + *NewSubBuffer = '\t'; + NewSubBuffer++; + + /* Remove the spaces */ + + SubBuffer = AsRemoveData (NewSubBuffer, SubBuffer + 1); + } + + if ((Column % 4) == 0) + { + SpaceCount = 0; + } + } + else + { + SpaceCount = 0; + } + + SubBuffer++; + } +} + + +/****************************************************************************** + * + * FUNCTION: AsTabify8 + * + * DESCRIPTION: Convert the text to tabbed text. Alignment of text is + * preserved. + * + ******************************************************************************/ + +void +AsTabify8 ( + char *Buffer) +{ + char *SubBuffer = Buffer; + char *NewSubBuffer; + char *CommentEnd = NULL; + UINT32 SpaceCount = 0; + UINT32 Column = 0; + UINT32 TabCount = 0; + UINT32 LastLineTabCount = 0; + UINT32 LastLineColumnStart = 0; + UINT32 ThisColumnStart = 0; + UINT32 ThisTabCount = 0; + char *FirstNonBlank = NULL; + + + while (*SubBuffer) + { + if (*SubBuffer == '\n') + { + /* This is a standalone blank line */ + + FirstNonBlank = NULL; + Column = 0; + SpaceCount = 0; + TabCount = 0; + SubBuffer++; + continue; + } + + if (!FirstNonBlank) + { + /* Find the first non-blank character on this line */ + + FirstNonBlank = SubBuffer; + while (*FirstNonBlank == ' ') + { + FirstNonBlank++; + } + + /* + * This mechanism limits the difference in tab counts from + * line to line. It helps avoid the situation where a second + * continuation line (which was indented correctly for tabs=4) would + * get indented off the screen if we just blindly converted to tabs. + */ + ThisColumnStart = FirstNonBlank - SubBuffer; + + if (LastLineTabCount == 0) + { + ThisTabCount = 0; + } + else if (ThisColumnStart == LastLineColumnStart) + { + ThisTabCount = LastLineTabCount -1; + } + else + { + ThisTabCount = LastLineTabCount + 1; + } + } + + Column++; + + /* Check if we are in a comment */ + + if ((SubBuffer[0] == '*') && + (SubBuffer[1] == '/')) + { + SpaceCount = 0; + SubBuffer += 2; + + if (*SubBuffer == '\n') + { + if (TabCount > 0) + { + LastLineTabCount = TabCount; + TabCount = 0; + } + FirstNonBlank = NULL; + LastLineColumnStart = ThisColumnStart; + SubBuffer++; + } + + continue; + } + + /* Check for comment open */ + + if ((SubBuffer[0] == '/') && + (SubBuffer[1] == '*')) + { + /* Find the end of the comment, it must exist */ + + CommentEnd = strstr (SubBuffer, "*/"); + if (!CommentEnd) + { + return; + } + + /* Toss the rest of this line or single-line comment */ + + while ((SubBuffer < CommentEnd) && + (*SubBuffer != '\n')) + { + SubBuffer++; + } + + if (*SubBuffer == '\n') + { + if (TabCount > 0) + { + LastLineTabCount = TabCount; + TabCount = 0; + } + FirstNonBlank = NULL; + LastLineColumnStart = ThisColumnStart; + } + + SpaceCount = 0; + continue; + } + + /* Ignore quoted strings */ + + if ((!CommentEnd) && (*SubBuffer == '\"')) + { + SubBuffer++; + SubBuffer = AsSkipPastChar (SubBuffer, '\"'); + if (!SubBuffer) + { + return; + } + SpaceCount = 0; + } + + if (*SubBuffer != ' ') + { + /* Not a space, skip to end of line */ + + SubBuffer = AsSkipUntilChar (SubBuffer, '\n'); + if (!SubBuffer) + { + return; + } + if (TabCount > 0) + { + LastLineTabCount = TabCount; + TabCount = 0; + } + + FirstNonBlank = NULL; + LastLineColumnStart = ThisColumnStart; + Column = 0; + SpaceCount = 0; + } + else + { + /* Another space */ + + SpaceCount++; + + if (SpaceCount >= 4) + { + /* Replace this group of spaces with a tab character */ + + SpaceCount = 0; + + NewSubBuffer = SubBuffer - 3; + + if (TabCount <= ThisTabCount ? (ThisTabCount +1) : 0) + { + *NewSubBuffer = '\t'; + NewSubBuffer++; + SubBuffer++; + TabCount++; + } + + /* Remove the spaces */ + + SubBuffer = AsRemoveData (NewSubBuffer, SubBuffer); + continue; + } + } + + SubBuffer++; + } +} + + +/****************************************************************************** + * + * FUNCTION: AsCountLines + * + * DESCRIPTION: Count the number of lines in the input buffer. Also count + * the number of long lines (lines longer than 80 chars). + * + ******************************************************************************/ + +UINT32 +AsCountLines ( + char *Buffer, + char *Filename) +{ + char *SubBuffer = Buffer; + char *EndOfLine; + UINT32 LineCount = 0; + UINT32 LongLineCount = 0; + + + while (*SubBuffer) + { + EndOfLine = AsSkipUntilChar (SubBuffer, '\n'); + if (!EndOfLine) + { + Gbl_TotalLines += LineCount; + return LineCount; + } + + if ((EndOfLine - SubBuffer) > 80) + { + LongLineCount++; + VERBOSE_PRINT (("long: %.80s\n", SubBuffer)); + } + + LineCount++; + SubBuffer = EndOfLine + 1; + } + + if (LongLineCount) + { + VERBOSE_PRINT (("%u Lines longer than 80 found in %s\n", LongLineCount, Filename)); + Gbl_LongLines += LongLineCount; + } + + Gbl_TotalLines += LineCount; + return LineCount; +} + + +/****************************************************************************** + * + * FUNCTION: AsCountTabs + * + * DESCRIPTION: Simply count the number of tabs in the input file buffer + * + ******************************************************************************/ + +void +AsCountTabs ( + char *Buffer, + char *Filename) +{ + UINT32 i; + UINT32 TabCount = 0; + + + for (i = 0; Buffer[i]; i++) + { + if (Buffer[i] == '\t') + { + TabCount++; + } + } + + if (TabCount) + { + AsPrint ("Tabs found", TabCount, Filename); + Gbl_Tabs += TabCount; + } + + AsCountLines (Buffer, Filename); +} + + +/****************************************************************************** + * + * FUNCTION: AsCountNonAnsiComments + * + * DESCRIPTION: Count the number of "//" comments. This type of comment is + * non-ANSI C. + * + ******************************************************************************/ + +void +AsCountNonAnsiComments ( + char *Buffer, + char *Filename) +{ + char *SubBuffer = Buffer; + UINT32 CommentCount = 0; + + + while (SubBuffer) + { + SubBuffer = strstr (SubBuffer, "//"); + if (SubBuffer) + { + CommentCount++; + SubBuffer += 2; + } + } + + if (CommentCount) + { + AsPrint ("Non-ANSI Comments found", CommentCount, Filename); + Gbl_NonAnsiComments += CommentCount; + } +} + + +/****************************************************************************** + * + * FUNCTION: AsCountSourceLines + * + * DESCRIPTION: Count the number of C source lines. Defined by 1) not a + * comment, and 2) not a blank line. + * + ******************************************************************************/ + +void +AsCountSourceLines ( + char *Buffer, + char *Filename) +{ + char *SubBuffer = Buffer; + UINT32 LineCount = 0; + UINT32 WhiteCount = 0; + UINT32 CommentCount = 0; + + + while (*SubBuffer) + { + /* Detect comments (// comments are not used, non-ansii) */ + + if ((SubBuffer[0] == '/') && + (SubBuffer[1] == '*')) + { + SubBuffer += 2; + + /* First line of multi-line comment is often just whitespace */ + + if (SubBuffer[0] == '\n') + { + WhiteCount++; + SubBuffer++; + } + else + { + CommentCount++; + } + + /* Find end of comment */ + + while (SubBuffer[0] && SubBuffer[1] && + !(((SubBuffer[0] == '*') && + (SubBuffer[1] == '/')))) + { + if (SubBuffer[0] == '\n') + { + CommentCount++; + } + + SubBuffer++; + } + } + + /* A linefeed followed by a non-linefeed is a valid source line */ + + else if ((SubBuffer[0] == '\n') && + (SubBuffer[1] != '\n')) + { + LineCount++; + } + + /* Two back-to-back linefeeds indicate a whitespace line */ + + else if ((SubBuffer[0] == '\n') && + (SubBuffer[1] == '\n')) + { + WhiteCount++; + } + + SubBuffer++; + } + + /* Adjust comment count for legal header */ + + if (Gbl_HeaderSize < CommentCount) + { + CommentCount -= Gbl_HeaderSize; + Gbl_HeaderLines += Gbl_HeaderSize; + } + + Gbl_SourceLines += LineCount; + Gbl_WhiteLines += WhiteCount; + Gbl_CommentLines += CommentCount; + + VERBOSE_PRINT (("%u Comment %u White %u Code %u Lines in %s\n", + CommentCount, WhiteCount, LineCount, LineCount+WhiteCount+CommentCount, Filename)); +} + + +/****************************************************************************** + * + * FUNCTION: AsInsertPrefix + * + * DESCRIPTION: Insert struct or union prefixes + * + ******************************************************************************/ + +void +AsInsertPrefix ( + char *Buffer, + char *Keyword, + UINT8 Type) +{ + char *SubString; + char *SubBuffer; + char *EndKeyword; + int InsertLength; + char *InsertString; + int TrailingSpaces; + char LowerKeyword[128]; + int KeywordLength; + + + switch (Type) + { + case SRC_TYPE_STRUCT: + InsertString = "struct "; + break; + + case SRC_TYPE_UNION: + InsertString = "union "; + break; + + default: + return; + } + + strcpy (LowerKeyword, Keyword); + strlwr (LowerKeyword); + + SubBuffer = Buffer; + SubString = Buffer; + InsertLength = strlen (InsertString); + KeywordLength = strlen (Keyword); + + + while (SubString) + { + /* Find an instance of the keyword */ + + SubString = strstr (SubBuffer, LowerKeyword); + if (!SubString) + { + return; + } + + SubBuffer = SubString; + + /* Must be standalone word, not a substring */ + + if (AsMatchExactWord (SubString, KeywordLength)) + { + /* Make sure the keyword isn't already prefixed with the insert */ + + if (!strncmp (SubString - InsertLength, InsertString, InsertLength)) + { + /* Add spaces if not already at the end-of-line */ + + if (*(SubBuffer + KeywordLength) != '\n') + { + /* Already present, add spaces after to align structure members */ + +#if 0 +/* ONLY FOR C FILES */ + AsInsertData (SubBuffer + KeywordLength, " ", 8); +#endif + } + goto Next; + } + + /* Make sure the keyword isn't at the end of a struct/union */ + /* Note: This code depends on a single space after the brace */ + + if (*(SubString - 2) == '}') + { + goto Next; + } + + /* Prefix the keyword with the insert string */ + + Gbl_MadeChanges = TRUE; + + /* Is there room for insertion */ + + EndKeyword = SubString + strlen (LowerKeyword); + + TrailingSpaces = 0; + while (EndKeyword[TrailingSpaces] == ' ') + { + TrailingSpaces++; + } + + /* + * Use "if (TrailingSpaces > 1)" if we want to ignore casts + */ + SubBuffer = SubString + InsertLength; + + if (TrailingSpaces > InsertLength) + { + /* Insert the keyword */ + + memmove (SubBuffer, SubString, KeywordLength); + + /* Insert the keyword */ + + memmove (SubString, InsertString, InsertLength); + } + else + { + AsInsertData (SubString, InsertString, InsertLength); + } + } + +Next: + SubBuffer += KeywordLength; + } +} + +#ifdef ACPI_FUTURE_IMPLEMENTATION +/****************************************************************************** + * + * FUNCTION: AsTrimComments + * + * DESCRIPTION: Finds 3-line comments with only a single line of text + * + ******************************************************************************/ + +void +AsTrimComments ( + char *Buffer, + char *Filename) +{ + char *SubBuffer = Buffer; + char *Ptr1; + char *Ptr2; + UINT32 LineCount; + UINT32 ShortCommentCount = 0; + + + while (1) + { + /* Find comment open, within procedure level */ + + SubBuffer = strstr (SubBuffer, " /*"); + if (!SubBuffer) + { + goto Exit; + } + + /* Find comment terminator */ + + Ptr1 = strstr (SubBuffer, "*/"); + if (!Ptr1) + { + goto Exit; + } + + /* Find next EOL (from original buffer) */ + + Ptr2 = strstr (SubBuffer, "\n"); + if (!Ptr2) + { + goto Exit; + } + + /* Ignore one-line comments */ + + if (Ptr1 < Ptr2) + { + /* Normal comment, ignore and continue; */ + + SubBuffer = Ptr2; + continue; + } + + /* Examine multi-line comment */ + + LineCount = 1; + while (Ptr1 > Ptr2) + { + /* Find next EOL */ + + Ptr2++; + Ptr2 = strstr (Ptr2, "\n"); + if (!Ptr2) + { + goto Exit; + } + + LineCount++; + } + + SubBuffer = Ptr1; + + if (LineCount <= 3) + { + ShortCommentCount++; + } + } + + +Exit: + + if (ShortCommentCount) + { + AsPrint ("Short Comments found", ShortCommentCount, Filename); + } +} +#endif + + diff --git a/source/tools/acpisrc/asfile.c b/source/tools/acpisrc/asfile.c new file mode 100644 index 000000000000..ce26adc3d8e4 --- /dev/null +++ b/source/tools/acpisrc/asfile.c @@ -0,0 +1,815 @@ + +/****************************************************************************** + * + * Module Name: asfile - Main module for the acpi source processor utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpisrc.h" + +/* Local prototypes */ + +void +AsDoWildcard ( + ACPI_CONVERSION_TABLE *ConversionTable, + char *SourcePath, + char *TargetPath, + int MaxPathLength, + int FileType, + char *WildcardSpec); + +BOOLEAN +AsDetectLoneLineFeeds ( + char *Filename, + char *Buffer); + +static ACPI_INLINE int +AsMaxInt (int a, int b) +{ + return (a > b ? a : b); +} + + +/****************************************************************************** + * + * FUNCTION: AsDoWildcard + * + * DESCRIPTION: Process files via wildcards + * + ******************************************************************************/ + +void +AsDoWildcard ( + ACPI_CONVERSION_TABLE *ConversionTable, + char *SourcePath, + char *TargetPath, + int MaxPathLength, + int FileType, + char *WildcardSpec) +{ + void *DirInfo; + char *Filename; + char *SourceDirPath; + char *TargetDirPath; + char RequestedFileType; + + + if (FileType == FILE_TYPE_DIRECTORY) + { + RequestedFileType = REQUEST_DIR_ONLY; + } + else + { + RequestedFileType = REQUEST_FILE_ONLY; + } + + VERBOSE_PRINT (("Checking for %s source files in directory \"%s\"\n", + WildcardSpec, SourcePath)); + + /* Open the directory for wildcard search */ + + DirInfo = AcpiOsOpenDirectory (SourcePath, WildcardSpec, RequestedFileType); + if (DirInfo) + { + /* + * Get all of the files that match both the + * wildcard and the requested file type + */ + while ((Filename = AcpiOsGetNextFilename (DirInfo))) + { + /* Looking for directory files, must check file type */ + + switch (RequestedFileType) + { + case REQUEST_DIR_ONLY: + + /* If we actually have a dir, process the subtree */ + + if (!AsCheckForDirectory (SourcePath, TargetPath, Filename, + &SourceDirPath, &TargetDirPath)) + { + VERBOSE_PRINT (("Subdirectory: %s\n", Filename)); + + AsProcessTree (ConversionTable, SourceDirPath, TargetDirPath); + free (SourceDirPath); + free (TargetDirPath); + } + break; + + case REQUEST_FILE_ONLY: + + /* Otherwise, this is a file, not a directory */ + + VERBOSE_PRINT (("File: %s\n", Filename)); + + AsProcessOneFile (ConversionTable, SourcePath, TargetPath, + MaxPathLength, Filename, FileType); + break; + + default: + break; + } + } + + /* Cleanup */ + + AcpiOsCloseDirectory (DirInfo); + } +} + + +/****************************************************************************** + * + * FUNCTION: AsProcessTree + * + * DESCRIPTION: Process the directory tree. Files with the extension ".C" and + * ".H" are processed as the tree is traversed. + * + ******************************************************************************/ + +ACPI_NATIVE_INT +AsProcessTree ( + ACPI_CONVERSION_TABLE *ConversionTable, + char *SourcePath, + char *TargetPath) +{ + int MaxPathLength; + + + MaxPathLength = AsMaxInt (strlen (SourcePath), strlen (TargetPath)); + + if (!(ConversionTable->Flags & FLG_NO_FILE_OUTPUT)) + { + if (ConversionTable->Flags & FLG_LOWERCASE_DIRNAMES) + { + strlwr (TargetPath); + } + + VERBOSE_PRINT (("Creating Directory \"%s\"\n", TargetPath)); + if (mkdir (TargetPath)) + { + if (errno != EEXIST) + { + printf ("Could not create target directory\n"); + return -1; + } + } + } + + /* Do the C source files */ + + AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, + FILE_TYPE_SOURCE, "*.c"); + + /* Do the C header files */ + + AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, + FILE_TYPE_HEADER, "*.h"); + + /* Do the Lex file(s) */ + + AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, + FILE_TYPE_SOURCE, "*.l"); + + /* Do the yacc file(s) */ + + AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, + FILE_TYPE_SOURCE, "*.y"); + + /* Do any ASL files */ + + AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, + FILE_TYPE_HEADER, "*.asl"); + + /* Do any subdirectories */ + + AsDoWildcard (ConversionTable, SourcePath, TargetPath, MaxPathLength, + FILE_TYPE_DIRECTORY, "*"); + + return 0; +} + + +/****************************************************************************** + * + * FUNCTION: AsDetectLoneLineFeeds + * + * DESCRIPTION: Find LF without CR. + * + ******************************************************************************/ + +BOOLEAN +AsDetectLoneLineFeeds ( + char *Filename, + char *Buffer) +{ + UINT32 i = 1; + UINT32 LfCount = 0; + UINT32 LineCount = 0; + + + if (!Buffer[0]) + { + return FALSE; + } + + while (Buffer[i]) + { + if (Buffer[i] == 0x0A) + { + if (Buffer[i-1] != 0x0D) + { + LfCount++; + } + LineCount++; + } + i++; + } + + if (LfCount) + { + if (LineCount == LfCount) + { + if (!Gbl_IgnoreLoneLineFeeds) + { + printf ("%s: ****File has UNIX format**** (LF only, not CR/LF) %u lines\n", + Filename, LfCount); + } + } + else + { + printf ("%s: %u lone linefeeds in file\n", Filename, LfCount); + } + return TRUE; + } + + return (FALSE); +} + + +/****************************************************************************** + * + * FUNCTION: AsConvertFile + * + * DESCRIPTION: Perform the requested transforms on the file buffer (as + * determined by the ConversionTable and the FileType). + * + ******************************************************************************/ + +void +AsConvertFile ( + ACPI_CONVERSION_TABLE *ConversionTable, + char *FileBuffer, + char *Filename, + ACPI_NATIVE_INT FileType) +{ + UINT32 i; + UINT32 Functions; + ACPI_STRING_TABLE *StringTable; + ACPI_IDENTIFIER_TABLE *ConditionalTable; + ACPI_IDENTIFIER_TABLE *LineTable; + ACPI_IDENTIFIER_TABLE *MacroTable; + ACPI_TYPED_IDENTIFIER_TABLE *StructTable; + + + switch (FileType) + { + case FILE_TYPE_SOURCE: + Functions = ConversionTable->SourceFunctions; + StringTable = ConversionTable->SourceStringTable; + LineTable = ConversionTable->SourceLineTable; + ConditionalTable = ConversionTable->SourceConditionalTable; + MacroTable = ConversionTable->SourceMacroTable; + StructTable = ConversionTable->SourceStructTable; + break; + + case FILE_TYPE_HEADER: + Functions = ConversionTable->HeaderFunctions; + StringTable = ConversionTable->HeaderStringTable; + LineTable = ConversionTable->HeaderLineTable; + ConditionalTable = ConversionTable->HeaderConditionalTable; + MacroTable = ConversionTable->HeaderMacroTable; + StructTable = ConversionTable->HeaderStructTable; + break; + + default: + printf ("Unknown file type, cannot process\n"); + return; + } + + + Gbl_StructDefs = strstr (FileBuffer, "/* acpisrc:StructDefs"); + Gbl_Files++; + VERBOSE_PRINT (("Processing %u bytes\n", + (unsigned int) strlen (FileBuffer))); + + if (ConversionTable->LowerCaseTable) + { + for (i = 0; ConversionTable->LowerCaseTable[i].Identifier; i++) + { + AsLowerCaseString (ConversionTable->LowerCaseTable[i].Identifier, + FileBuffer); + } + } + + /* Process all the string replacements */ + + if (StringTable) + { + for (i = 0; StringTable[i].Target; i++) + { + AsReplaceString (StringTable[i].Target, StringTable[i].Replacement, + StringTable[i].Type, FileBuffer); + } + } + + if (LineTable) + { + for (i = 0; LineTable[i].Identifier; i++) + { + AsRemoveLine (FileBuffer, LineTable[i].Identifier); + } + } + + if (ConditionalTable) + { + for (i = 0; ConditionalTable[i].Identifier; i++) + { + AsRemoveConditionalCompile (FileBuffer, ConditionalTable[i].Identifier); + } + } + + if (MacroTable) + { + for (i = 0; MacroTable[i].Identifier; i++) + { + AsRemoveMacro (FileBuffer, MacroTable[i].Identifier); + } + } + + if (StructTable) + { + for (i = 0; StructTable[i].Identifier; i++) + { + AsInsertPrefix (FileBuffer, StructTable[i].Identifier, StructTable[i].Type); + } + } + + /* Process the function table */ + + for (i = 0; i < 32; i++) + { + /* Decode the function bitmap */ + + switch ((1 << i) & Functions) + { + case 0: + /* This function not configured */ + break; + + + case CVT_COUNT_TABS: + + AsCountTabs (FileBuffer, Filename); + break; + + + case CVT_COUNT_NON_ANSI_COMMENTS: + + AsCountNonAnsiComments (FileBuffer, Filename); + break; + + + case CVT_CHECK_BRACES: + + AsCheckForBraces (FileBuffer, Filename); + break; + + + case CVT_TRIM_LINES: + + AsTrimLines (FileBuffer, Filename); + break; + + + case CVT_COUNT_LINES: + + AsCountSourceLines (FileBuffer, Filename); + break; + + + case CVT_BRACES_ON_SAME_LINE: + + AsBracesOnSameLine (FileBuffer); + break; + + + case CVT_MIXED_CASE_TO_UNDERSCORES: + + AsMixedCaseToUnderscores (FileBuffer); + break; + + + case CVT_LOWER_CASE_IDENTIFIERS: + + AsLowerCaseIdentifiers (FileBuffer); + break; + + + case CVT_REMOVE_DEBUG_MACROS: + + AsRemoveDebugMacros (FileBuffer); + break; + + + case CVT_TRIM_WHITESPACE: + + AsTrimWhitespace (FileBuffer); + break; + + + case CVT_REMOVE_EMPTY_BLOCKS: + + AsRemoveEmptyBlocks (FileBuffer, Filename); + break; + + + case CVT_REDUCE_TYPEDEFS: + + AsReduceTypedefs (FileBuffer, "typedef union"); + AsReduceTypedefs (FileBuffer, "typedef struct"); + break; + + + case CVT_SPACES_TO_TABS4: + + AsTabify4 (FileBuffer); + break; + + + case CVT_SPACES_TO_TABS8: + + AsTabify8 (FileBuffer); + break; + + case CVT_COUNT_SHORTMULTILINE_COMMENTS: + +#ifdef ACPI_FUTURE_IMPLEMENTATION + AsTrimComments (FileBuffer, Filename); +#endif + break; + + default: + + printf ("Unknown conversion subfunction opcode\n"); + break; + } + } + + if (ConversionTable->NewHeader) + { + AsReplaceHeader (FileBuffer, ConversionTable->NewHeader); + } +} + + +/****************************************************************************** + * + * FUNCTION: AsProcessOneFile + * + * DESCRIPTION: Process one source file. The file is opened, read entirely + * into a buffer, converted, then written to a new file. + * + ******************************************************************************/ + +ACPI_NATIVE_INT +AsProcessOneFile ( + ACPI_CONVERSION_TABLE *ConversionTable, + char *SourcePath, + char *TargetPath, + int MaxPathLength, + char *Filename, + ACPI_NATIVE_INT FileType) +{ + char *Pathname; + char *OutPathname = NULL; + + + /* Allocate a file pathname buffer for both source and target */ + + Pathname = calloc (MaxPathLength + strlen (Filename) + 2, 1); + if (!Pathname) + { + printf ("Could not allocate buffer for file pathnames\n"); + return -1; + } + + Gbl_FileType = FileType; + + /* Generate the source pathname and read the file */ + + if (SourcePath) + { + strcpy (Pathname, SourcePath); + strcat (Pathname, "/"); + } + + strcat (Pathname, Filename); + + if (AsGetFile (Pathname, &Gbl_FileBuffer, &Gbl_FileSize)) + { + return -1; + } + + Gbl_HeaderSize = 0; + if (strstr (Filename, ".asl")) + { + Gbl_HeaderSize = LINES_IN_ASL_HEADER; /* Lines in default ASL header */ + } + else if (strstr (Gbl_FileBuffer, LEGAL_HEADER_SIGNATURE)) + { + Gbl_HeaderSize = LINES_IN_LEGAL_HEADER; /* Normal C file and H header */ + } + else if (strstr (Gbl_FileBuffer, LINUX_HEADER_SIGNATURE)) + { + Gbl_HeaderSize = LINES_IN_LINUX_HEADER; /* Linuxized C file and H header */ + } + + /* Process the file in the buffer */ + + Gbl_MadeChanges = FALSE; + if (!Gbl_IgnoreLoneLineFeeds && Gbl_HasLoneLineFeeds) + { + /* + * All lone LFs will be converted to CR/LF + * (when file is written, Windows version only) + */ + printf ("Converting lone linefeeds\n"); + Gbl_MadeChanges = TRUE; + } + + AsConvertFile (ConversionTable, Gbl_FileBuffer, Pathname, FileType); + + if (!(ConversionTable->Flags & FLG_NO_FILE_OUTPUT)) + { + if (!(Gbl_Overwrite && !Gbl_MadeChanges)) + { + /* Generate the target pathname and write the file */ + + OutPathname = calloc (MaxPathLength + strlen (Filename) + 2 + strlen (TargetPath), 1); + if (!OutPathname) + { + printf ("Could not allocate buffer for file pathnames\n"); + return -1; + } + + strcpy (OutPathname, TargetPath); + if (SourcePath) + { + strcat (OutPathname, "/"); + strcat (OutPathname, Filename); + } + + AsPutFile (OutPathname, Gbl_FileBuffer, ConversionTable->Flags); + } + } + + free (Gbl_FileBuffer); + free (Pathname); + if (OutPathname) + { + free (OutPathname); + } + + return 0; +} + + +/****************************************************************************** + * + * FUNCTION: AsCheckForDirectory + * + * DESCRIPTION: Check if the current file is a valid directory. If not, + * construct the full pathname for the source and target paths. + * Checks for the dot and dot-dot files (they are ignored) + * + ******************************************************************************/ + +ACPI_NATIVE_INT +AsCheckForDirectory ( + char *SourceDirPath, + char *TargetDirPath, + char *Filename, + char **SourcePath, + char **TargetPath) +{ + char *SrcPath; + char *TgtPath; + + + if (!(strcmp (Filename, ".")) || + !(strcmp (Filename, ".."))) + { + return -1; + } + + SrcPath = calloc (strlen (SourceDirPath) + strlen (Filename) + 2, 1); + if (!SrcPath) + { + printf ("Could not allocate buffer for directory source pathname\n"); + return -1; + } + + TgtPath = calloc (strlen (TargetDirPath) + strlen (Filename) + 2, 1); + if (!TgtPath) + { + printf ("Could not allocate buffer for directory target pathname\n"); + free (SrcPath); + return -1; + } + + strcpy (SrcPath, SourceDirPath); + strcat (SrcPath, "/"); + strcat (SrcPath, Filename); + + strcpy (TgtPath, TargetDirPath); + strcat (TgtPath, "/"); + strcat (TgtPath, Filename); + + *SourcePath = SrcPath; + *TargetPath = TgtPath; + return 0; +} + + +/****************************************************************************** + * + * FUNCTION: AsGetFile + * + * DESCRIPTION: Open a file and read it entirely into a an allocated buffer + * + ******************************************************************************/ + +int +AsGetFile ( + char *Filename, + char **FileBuffer, + UINT32 *FileSize) +{ + + int FileHandle; + UINT32 Size; + char *Buffer; + + + /* Binary mode leaves CR/LF pairs */ + + FileHandle = open (Filename, O_BINARY | O_RDONLY); + if (!FileHandle) + { + printf ("Could not open %s\n", Filename); + return -1; + } + + if (fstat (FileHandle, &Gbl_StatBuf)) + { + printf ("Could not get file status for %s\n", Filename); + goto ErrorExit; + } + + /* + * Create a buffer for the entire file + * Add plenty extra buffer to accomodate string replacements + */ + Size = Gbl_StatBuf.st_size; + Gbl_TotalSize += Size; + + Buffer = calloc (Size * 2, 1); + if (!Buffer) + { + printf ("Could not allocate buffer of size %u\n", Size * 2); + goto ErrorExit; + } + + /* Read the entire file */ + + Size = read (FileHandle, Buffer, Size); + if (Size == -1) + { + printf ("Could not read the input file %s\n", Filename); + goto ErrorExit; + } + + Buffer [Size] = 0; /* Null terminate the buffer */ + close (FileHandle); + + /* Check for unix contamination */ + + Gbl_HasLoneLineFeeds = AsDetectLoneLineFeeds (Filename, Buffer); + + /* + * Convert all CR/LF pairs to LF only. We do this locally so that + * this code is portable across operating systems. + */ + AsConvertToLineFeeds (Buffer); + + *FileBuffer = Buffer; + *FileSize = Size; + + return 0; + + +ErrorExit: + + close (FileHandle); + return -1; +} + + +/****************************************************************************** + * + * FUNCTION: AsPutFile + * + * DESCRIPTION: Create a new output file and write the entire contents of the + * buffer to the new file. Buffer must be a zero terminated string + * + ******************************************************************************/ + +int +AsPutFile ( + char *Pathname, + char *FileBuffer, + UINT32 SystemFlags) +{ + UINT32 FileSize; + int DestHandle; + int OpenFlags; + + + /* Create the target file */ + + OpenFlags = O_TRUNC | O_CREAT | O_WRONLY | O_BINARY; + + if (!(SystemFlags & FLG_NO_CARRIAGE_RETURNS)) + { + /* Put back the CR before each LF */ + + AsInsertCarriageReturns (FileBuffer); + } + + DestHandle = open (Pathname, OpenFlags, S_IREAD | S_IWRITE); + if (DestHandle == -1) + { + perror ("Could not create destination file"); + printf ("Could not create destination file \"%s\"\n", Pathname); + return -1; + } + + /* Write the buffer to the file */ + + FileSize = strlen (FileBuffer); + write (DestHandle, FileBuffer, FileSize); + + close (DestHandle); + + return 0; +} + + diff --git a/source/tools/acpisrc/asmain.c b/source/tools/acpisrc/asmain.c new file mode 100644 index 000000000000..baf4e2fc34c7 --- /dev/null +++ b/source/tools/acpisrc/asmain.c @@ -0,0 +1,457 @@ + +/****************************************************************************** + * + * Module Name: asmain - Main module for the acpi source processor utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include "acpisrc.h" +#include "acapps.h" + +/* Local prototypes */ + +int +AsStricmp ( + char *String1, + char *String2); + +int +AsExaminePaths ( + ACPI_CONVERSION_TABLE *ConversionTable, + char *Source, + char *Target, + UINT32 *SourceFileType); + +void +AsDisplayStats ( + void); + +void +AsDisplayUsage ( + void); + +/* Globals */ + +UINT32 Gbl_Tabs = 0; +UINT32 Gbl_MissingBraces = 0; +UINT32 Gbl_NonAnsiComments = 0; +UINT32 Gbl_Files = 0; +UINT32 Gbl_WhiteLines = 0; +UINT32 Gbl_CommentLines = 0; +UINT32 Gbl_SourceLines = 0; +UINT32 Gbl_LongLines = 0; +UINT32 Gbl_TotalLines = 0; +UINT32 Gbl_TotalSize = 0; +UINT32 Gbl_HeaderLines = 0; +UINT32 Gbl_HeaderSize = 0; +void *Gbl_StructDefs = NULL; + +struct stat Gbl_StatBuf; +char *Gbl_FileBuffer; +UINT32 Gbl_FileSize; +UINT32 Gbl_FileType; +BOOLEAN Gbl_VerboseMode = FALSE; +BOOLEAN Gbl_QuietMode = FALSE; +BOOLEAN Gbl_BatchMode = FALSE; +BOOLEAN Gbl_DebugStatementsMode = FALSE; +BOOLEAN Gbl_MadeChanges = FALSE; +BOOLEAN Gbl_Overwrite = FALSE; +BOOLEAN Gbl_WidenDeclarations = FALSE; +BOOLEAN Gbl_IgnoreLoneLineFeeds = FALSE; +BOOLEAN Gbl_HasLoneLineFeeds = FALSE; + + +/****************************************************************************** + * + * FUNCTION: AsStricmp + * + * DESCRIPTION: Implementation of the non-ANSI stricmp function (compare + * strings with no case sensitivity) + * + ******************************************************************************/ + +int +AsStricmp ( + char *String1, + char *String2) +{ + int c1; + int c2; + + + do + { + c1 = tolower ((int) *String1); + c2 = tolower ((int) *String2); + + String1++; + String2++; + } + while ((c1 == c2) && (c1)); + + return (c1 - c2); +} + + +/****************************************************************************** + * + * FUNCTION: AsExaminePaths + * + * DESCRIPTION: Source and Target pathname verification and handling + * + ******************************************************************************/ + +int +AsExaminePaths ( + ACPI_CONVERSION_TABLE *ConversionTable, + char *Source, + char *Target, + UINT32 *SourceFileType) +{ + int Status; + char Response; + + + Status = stat (Source, &Gbl_StatBuf); + if (Status) + { + printf ("Source path \"%s\" does not exist\n", Source); + return -1; + } + + /* Return the filetype -- file or a directory */ + + *SourceFileType = 0; + if (Gbl_StatBuf.st_mode & S_IFDIR) + { + *SourceFileType = S_IFDIR; + } + + /* + * If we are in no-output mode or in batch mode, we are done + */ + if ((ConversionTable->Flags & FLG_NO_FILE_OUTPUT) || + (Gbl_BatchMode)) + { + return 0; + } + + if (!AsStricmp (Source, Target)) + { + printf ("Target path is the same as the source path, overwrite?\n"); + scanf ("%c", &Response); + + /* Check response */ + + if ((char) Response != 'y') + { + return -1; + } + + Gbl_Overwrite = TRUE; + } + else + { + Status = stat (Target, &Gbl_StatBuf); + if (!Status) + { + printf ("Target path already exists, overwrite?\n"); + scanf ("%c", &Response); + + /* Check response */ + + if ((char) Response != 'y') + { + return -1; + } + } + } + + return 0; +} + + +/****************************************************************************** + * + * FUNCTION: AsDisplayStats + * + * DESCRIPTION: Display global statistics gathered during translation + * + ******************************************************************************/ + +void +AsDisplayStats ( + void) +{ + + if (Gbl_QuietMode) + { + return; + } + + printf ("\nAcpiSrc statistics:\n\n"); + printf ("%8u Files processed\n", Gbl_Files); + + if (!Gbl_Files) + { + return; + } + + printf ("%8u Total bytes (%.1fK/file)\n", + Gbl_TotalSize, ((double) Gbl_TotalSize/Gbl_Files)/1024); + printf ("%8u Tabs found\n", Gbl_Tabs); + printf ("%8u Missing if/else braces\n", Gbl_MissingBraces); + printf ("%8u Non-ANSI comments found\n", Gbl_NonAnsiComments); + printf ("%8u Total Lines\n", Gbl_TotalLines); + printf ("%8u Lines of code\n", Gbl_SourceLines); + printf ("%8u Lines of non-comment whitespace\n", Gbl_WhiteLines); + printf ("%8u Lines of comments\n", Gbl_CommentLines); + printf ("%8u Long lines found\n", Gbl_LongLines); + printf ("%8.1f Ratio of code to whitespace\n", + ((float) Gbl_SourceLines / (float) Gbl_WhiteLines)); + printf ("%8.1f Ratio of code to comments\n", + ((float) Gbl_SourceLines / (float) (Gbl_CommentLines + Gbl_NonAnsiComments))); + + if (!Gbl_TotalLines) + { + return; + } + + printf (" %u%% code, %u%% comments, %u%% whitespace, %u%% headers\n", + (Gbl_SourceLines * 100) / Gbl_TotalLines, + (Gbl_CommentLines * 100) / Gbl_TotalLines, + (Gbl_WhiteLines * 100) / Gbl_TotalLines, + (Gbl_HeaderLines * 100) / Gbl_TotalLines); + return; +} + + +/****************************************************************************** + * + * FUNCTION: AsDisplayUsage + * + * DESCRIPTION: Usage message + * + ******************************************************************************/ + +void +AsDisplayUsage ( + void) +{ + + ACPI_USAGE_HEADER ("acpisrc [-c|l|u] [-dsvy] <SourceDir> <DestinationDir>"); + + ACPI_OPTION ("-c", "Generate cleaned version of the source"); + ACPI_OPTION ("-h", "Insert dual-license header into all modules"); + ACPI_OPTION ("-l", "Generate Linux version of the source"); + ACPI_OPTION ("-u", "Generate Custom source translation"); + + printf ("\n"); + ACPI_OPTION ("-d", "Leave debug statements in code"); + ACPI_OPTION ("-s", "Generate source statistics only"); + ACPI_OPTION ("-v", "Verbose mode"); + ACPI_OPTION ("-y", "Suppress file overwrite prompts"); +} + + +/****************************************************************************** + * + * FUNCTION: main + * + * DESCRIPTION: C main function + * + ******************************************************************************/ + +int ACPI_SYSTEM_XFACE +main ( + int argc, + char *argv[]) +{ + int j; + ACPI_CONVERSION_TABLE *ConversionTable = NULL; + char *SourcePath; + char *TargetPath; + UINT32 FileType; + + + printf (ACPI_COMMON_SIGNON ("ACPI Source Code Conversion Utility")); + + if (argc < 2) + { + AsDisplayUsage (); + return 0; + } + + /* Command line options */ + + while ((j = AcpiGetopt (argc, argv, "cdhlqsuvy")) != EOF) switch(j) + { + case 'l': + /* Linux code generation */ + + printf ("Creating Linux source code\n"); + ConversionTable = &LinuxConversionTable; + Gbl_WidenDeclarations = TRUE; + Gbl_IgnoreLoneLineFeeds = TRUE; + break; + + case 'c': + /* Cleanup code */ + + printf ("Code cleanup\n"); + ConversionTable = &CleanupConversionTable; + break; + + case 'h': + /* Inject Dual-license header */ + + printf ("Inserting Dual-license header to all modules\n"); + ConversionTable = &LicenseConversionTable; + break; + + case 's': + /* Statistics only */ + + break; + + case 'u': + /* custom conversion */ + + printf ("Custom source translation\n"); + ConversionTable = &CustomConversionTable; + break; + + case 'v': + /* Verbose mode */ + + Gbl_VerboseMode = TRUE; + break; + + case 'y': + /* Batch mode */ + + Gbl_BatchMode = TRUE; + break; + + case 'd': + /* Leave debug statements in */ + + Gbl_DebugStatementsMode = TRUE; + break; + + case 'q': + /* Quiet mode */ + + Gbl_QuietMode = TRUE; + break; + + default: + AsDisplayUsage (); + return -1; + } + + + SourcePath = argv[AcpiGbl_Optind]; + if (!SourcePath) + { + printf ("Missing source path\n"); + AsDisplayUsage (); + return -1; + } + + TargetPath = argv[AcpiGbl_Optind+1]; + + if (!ConversionTable) + { + /* Just generate statistics. Ignore target path */ + + TargetPath = SourcePath; + + printf ("Source code statistics only\n"); + ConversionTable = &StatsConversionTable; + } + else if (!TargetPath) + { + TargetPath = SourcePath; + } + + if (Gbl_DebugStatementsMode) + { + ConversionTable->SourceFunctions &= ~CVT_REMOVE_DEBUG_MACROS; + } + + /* Check source and target paths and files */ + + if (AsExaminePaths (ConversionTable, SourcePath, TargetPath, &FileType)) + { + return -1; + } + + /* Source/target can be either directories or a files */ + + if (FileType == S_IFDIR) + { + /* Process the directory tree */ + + AsProcessTree (ConversionTable, SourcePath, TargetPath); + } + else + { + /* Process a single file */ + + /* Differentiate between source and header files */ + + if (strstr (SourcePath, ".h")) + { + AsProcessOneFile (ConversionTable, NULL, TargetPath, 0, SourcePath, FILE_TYPE_HEADER); + } + else + { + AsProcessOneFile (ConversionTable, NULL, TargetPath, 0, SourcePath, FILE_TYPE_SOURCE); + } + } + + /* Always display final summary and stats */ + + AsDisplayStats (); + + return 0; +} diff --git a/source/tools/acpisrc/asremove.c b/source/tools/acpisrc/asremove.c new file mode 100644 index 000000000000..8fe29e158a2a --- /dev/null +++ b/source/tools/acpisrc/asremove.c @@ -0,0 +1,616 @@ + +/****************************************************************************** + * + * Module Name: asremove - Source conversion - removal functions + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpisrc.h" + +/* Local prototypes */ + +void +AsRemoveStatement ( + char *Buffer, + char *Keyword, + UINT32 Type); + + +/****************************************************************************** + * + * FUNCTION: AsRemoveStatement + * + * DESCRIPTION: Remove all statements that contain the given keyword. + * Limitations: Removes text from the start of the line that + * contains the keyword to the next semicolon. Currently + * doesn't ignore comments. + * + ******************************************************************************/ + +void +AsRemoveStatement ( + char *Buffer, + char *Keyword, + UINT32 Type) +{ + char *SubString; + char *SubBuffer; + int KeywordLength; + + + KeywordLength = strlen (Keyword); + SubBuffer = Buffer; + SubString = Buffer; + + + while (SubString) + { + SubString = strstr (SubBuffer, Keyword); + + if (SubString) + { + SubBuffer = SubString; + + if ((Type == REPLACE_WHOLE_WORD) && + (!AsMatchExactWord (SubString, KeywordLength))) + { + SubBuffer++; + continue; + } + + /* Find start of this line */ + + while (*SubString != '\n') + { + SubString--; + } + SubString++; + + /* Find end of this statement */ + + SubBuffer = AsSkipPastChar (SubBuffer, ';'); + if (!SubBuffer) + { + return; + } + + /* Find end of this line */ + + SubBuffer = AsSkipPastChar (SubBuffer, '\n'); + if (!SubBuffer) + { + return; + } + + /* If next line is blank, remove it too */ + + if (*SubBuffer == '\n') + { + SubBuffer++; + } + + /* Remove the lines */ + + SubBuffer = AsRemoveData (SubString, SubBuffer); + } + } +} + + +/****************************************************************************** + * + * FUNCTION: AsRemoveConditionalCompile + * + * DESCRIPTION: Remove a "#ifdef" statement, and all text that it encompasses. + * Limitations: cannot handle nested ifdefs. + * + ******************************************************************************/ + +void +AsRemoveConditionalCompile ( + char *Buffer, + char *Keyword) +{ + char *SubString; + char *SubBuffer; + char *IfPtr; + char *EndifPtr; + char *ElsePtr; + char *Comment; + int KeywordLength; + + + KeywordLength = strlen (Keyword); + SubBuffer = Buffer; + SubString = Buffer; + + + while (SubString) + { + SubBuffer = strstr (SubString, Keyword); + if (!SubBuffer) + { + return; + } + + /* + * Check for translation escape string -- means to ignore + * blocks of code while replacing + */ + Comment = strstr (SubString, AS_START_IGNORE); + + if ((Comment) && + (Comment < SubBuffer)) + { + SubString = strstr (Comment, AS_STOP_IGNORE); + if (!SubString) + { + return; + } + + SubString += 3; + continue; + } + + /* Check for ordinary comment */ + + Comment = strstr (SubString, "/*"); + + if ((Comment) && + (Comment < SubBuffer)) + { + SubString = strstr (Comment, "*/"); + if (!SubString) + { + return; + } + + SubString += 2; + continue; + } + + SubString = SubBuffer; + if (!AsMatchExactWord (SubString, KeywordLength)) + { + SubString++; + continue; + } + + /* Find start of this line */ + + while (*SubString != '\n' && (SubString > Buffer)) + { + SubString--; + } + SubString++; + + /* Find the "#ifxxxx" */ + + IfPtr = strstr (SubString, "#if"); + if (!IfPtr) + { + return; + } + + if (IfPtr > SubBuffer) + { + /* Not the right #if */ + + SubString = SubBuffer + strlen (Keyword); + continue; + } + + /* Find closing #endif or #else */ + + EndifPtr = strstr (SubBuffer, "#endif"); + if (!EndifPtr) + { + /* There has to be an #endif */ + + return; + } + + ElsePtr = strstr (SubBuffer, "#else"); + if ((ElsePtr) && + (EndifPtr > ElsePtr)) + { + /* This #ifdef contains an #else clause */ + /* Find end of this line */ + + SubBuffer = AsSkipPastChar (ElsePtr, '\n'); + if (!SubBuffer) + { + return; + } + + /* Remove the #ifdef .... #else code */ + + AsRemoveData (SubString, SubBuffer); + + /* Next, we will remove the #endif statement */ + + EndifPtr = strstr (SubString, "#endif"); + if (!EndifPtr) + { + /* There has to be an #endif */ + + return; + } + + SubString = EndifPtr; + } + + /* Remove the ... #endif part */ + /* Find end of this line */ + + SubBuffer = AsSkipPastChar (EndifPtr, '\n'); + if (!SubBuffer) + { + return; + } + + /* Remove the lines */ + + SubBuffer = AsRemoveData (SubString, SubBuffer); + } +} + + +/****************************************************************************** + * + * FUNCTION: AsRemoveMacro + * + * DESCRIPTION: Remove every line that contains the keyword. Does not + * skip comments. + * + ******************************************************************************/ + +void +AsRemoveMacro ( + char *Buffer, + char *Keyword) +{ + char *SubString; + char *SubBuffer; + int NestLevel; + + + SubBuffer = Buffer; + SubString = Buffer; + + + while (SubString) + { + SubString = strstr (SubBuffer, Keyword); + + if (SubString) + { + SubBuffer = SubString; + + /* Find start of the macro parameters */ + + while (*SubString != '(') + { + SubString++; + } + SubString++; + + /* Remove the macro name and opening paren */ + + SubString = AsRemoveData (SubBuffer, SubString); + + NestLevel = 1; + while (*SubString) + { + if (*SubString == '(') + { + NestLevel++; + } + else if (*SubString == ')') + { + NestLevel--; + } + + SubString++; + + if (NestLevel == 0) + { + break; + } + } + + /* Remove the closing paren */ + + SubBuffer = AsRemoveData (SubString-1, SubString); + } + } +} + + +/****************************************************************************** + * + * FUNCTION: AsRemoveLine + * + * DESCRIPTION: Remove every line that contains the keyword. Does not + * skip comments. + * + ******************************************************************************/ + +void +AsRemoveLine ( + char *Buffer, + char *Keyword) +{ + char *SubString; + char *SubBuffer; + + + SubBuffer = Buffer; + SubString = Buffer; + + + while (SubString) + { + SubString = strstr (SubBuffer, Keyword); + + if (SubString) + { + SubBuffer = SubString; + + /* Find start of this line */ + + while (*SubString != '\n') + { + SubString--; + } + SubString++; + + /* Find end of this line */ + + SubBuffer = AsSkipPastChar (SubBuffer, '\n'); + if (!SubBuffer) + { + return; + } + + /* Remove the line */ + + SubBuffer = AsRemoveData (SubString, SubBuffer); + } + } +} + + +/****************************************************************************** + * + * FUNCTION: AsReduceTypedefs + * + * DESCRIPTION: Eliminate certain typedefs + * + ******************************************************************************/ + +void +AsReduceTypedefs ( + char *Buffer, + char *Keyword) +{ + char *SubString; + char *SubBuffer; + int NestLevel; + + + SubBuffer = Buffer; + SubString = Buffer; + + + while (SubString) + { + SubString = strstr (SubBuffer, Keyword); + + if (SubString) + { + /* Remove the typedef itself */ + + SubBuffer = SubString + strlen ("typedef") + 1; + SubBuffer = AsRemoveData (SubString, SubBuffer); + + /* Find the opening brace of the struct or union */ + + while (*SubString != '{') + { + SubString++; + } + SubString++; + + /* Find the closing brace. Handles nested braces */ + + NestLevel = 1; + while (*SubString) + { + if (*SubString == '{') + { + NestLevel++; + } + else if (*SubString == '}') + { + NestLevel--; + } + + SubString++; + + if (NestLevel == 0) + { + break; + } + } + + /* Remove an extra line feed if present */ + + if (!strncmp (SubString - 3, "\n\n", 2)) + { + *(SubString -2) = '}'; + SubString--; + } + + /* Find the end of the typedef name */ + + SubBuffer = AsSkipUntilChar (SubString, ';'); + + /* And remove the typedef name */ + + SubBuffer = AsRemoveData (SubString, SubBuffer); + } + } +} + + +/****************************************************************************** + * + * FUNCTION: AsRemoveEmptyBlocks + * + * DESCRIPTION: Remove any C blocks (e.g., if {}) that contain no code. This + * can happen as a result of removing lines such as DEBUG_PRINT. + * + ******************************************************************************/ + +void +AsRemoveEmptyBlocks ( + char *Buffer, + char *Filename) +{ + char *SubBuffer; + char *BlockStart; + BOOLEAN EmptyBlock = TRUE; + BOOLEAN AnotherPassRequired = TRUE; + UINT32 BlockCount = 0; + + + while (AnotherPassRequired) + { + SubBuffer = Buffer; + AnotherPassRequired = FALSE; + + while (*SubBuffer) + { + if (*SubBuffer == '{') + { + BlockStart = SubBuffer; + EmptyBlock = TRUE; + + SubBuffer++; + while (*SubBuffer != '}') + { + if ((*SubBuffer != ' ') && + (*SubBuffer != '\n')) + { + EmptyBlock = FALSE; + break; + } + SubBuffer++; + } + + if (EmptyBlock) + { + /* Find start of the first line of the block */ + + while (*BlockStart != '\n') + { + BlockStart--; + } + + /* Find end of the last line of the block */ + + SubBuffer = AsSkipUntilChar (SubBuffer, '\n'); + if (!SubBuffer) + { + break; + } + + /* Remove the block */ + + SubBuffer = AsRemoveData (BlockStart, SubBuffer); + BlockCount++; + AnotherPassRequired = TRUE; + continue; + } + } + + SubBuffer++; + } + } + + if (BlockCount) + { + Gbl_MadeChanges = TRUE; + AsPrint ("Code blocks deleted", BlockCount, Filename); + } +} + + +/****************************************************************************** + * + * FUNCTION: AsRemoveDebugMacros + * + * DESCRIPTION: Remove all "Debug" macros -- macros that produce debug output. + * + ******************************************************************************/ + +void +AsRemoveDebugMacros ( + char *Buffer) +{ + AsRemoveConditionalCompile (Buffer, "ACPI_DEBUG_OUTPUT"); + + AsRemoveStatement (Buffer, "ACPI_DEBUG_PRINT", REPLACE_WHOLE_WORD); + AsRemoveStatement (Buffer, "ACPI_DEBUG_PRINT_RAW", REPLACE_WHOLE_WORD); + AsRemoveStatement (Buffer, "DEBUG_EXEC", REPLACE_WHOLE_WORD); + AsRemoveStatement (Buffer, "FUNCTION_ENTRY", REPLACE_WHOLE_WORD); + AsRemoveStatement (Buffer, "PROC_NAME", REPLACE_WHOLE_WORD); + AsRemoveStatement (Buffer, "FUNCTION_TRACE", REPLACE_SUBSTRINGS); + AsRemoveStatement (Buffer, "DUMP_", REPLACE_SUBSTRINGS); + + AsReplaceString ("return_VOID", "return", REPLACE_WHOLE_WORD, Buffer); + AsReplaceString ("return_PTR", "return", REPLACE_WHOLE_WORD, Buffer); + AsReplaceString ("return_ACPI_STATUS", "return", REPLACE_WHOLE_WORD, Buffer); + AsReplaceString ("return_acpi_status", "return", REPLACE_WHOLE_WORD, Buffer); + AsReplaceString ("return_VALUE", "return", REPLACE_WHOLE_WORD, Buffer); +} + + diff --git a/source/tools/acpisrc/astable.c b/source/tools/acpisrc/astable.c new file mode 100644 index 000000000000..a1d96d32a83a --- /dev/null +++ b/source/tools/acpisrc/astable.c @@ -0,0 +1,870 @@ + +/****************************************************************************** + * + * Module Name: astable - Tables used for source conversion + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include "acpisrc.h" +#include "acapps.h" + + +/****************************************************************************** + * + * Standard/Common translation tables + * + ******************************************************************************/ + + +ACPI_STRING_TABLE StandardDataTypes[] = { + + /* Declarations first */ + + {"UINT32 ", "unsigned int", REPLACE_SUBSTRINGS}, + {"UINT16 ", "unsigned short", REPLACE_SUBSTRINGS}, + {"UINT8 ", "unsigned char", REPLACE_SUBSTRINGS}, + {"BOOLEAN ", "unsigned char", REPLACE_SUBSTRINGS}, + + /* Now do embedded typecasts */ + + {"UINT32", "unsigned int", REPLACE_SUBSTRINGS}, + {"UINT16", "unsigned short", REPLACE_SUBSTRINGS}, + {"UINT8", "unsigned char", REPLACE_SUBSTRINGS}, + {"BOOLEAN", "unsigned char", REPLACE_SUBSTRINGS}, + + {"INT32 ", "int ", REPLACE_SUBSTRINGS}, + {"INT32", "int", REPLACE_SUBSTRINGS}, + {"INT16", "short", REPLACE_SUBSTRINGS}, + {"INT8", "char", REPLACE_SUBSTRINGS}, + + /* Put back anything we broke (such as anything with _INT32_ in it) */ + + {"_int_", "_INT32_", REPLACE_SUBSTRINGS}, + {"_unsigned int_", "_UINT32_", REPLACE_SUBSTRINGS}, + {NULL, NULL, 0} +}; + + +/****************************************************************************** + * + * Linux-specific translation tables + * + ******************************************************************************/ + +char DualLicenseHeader[] = +"/*\n" +" * Copyright (C) 2000 - 2012, Intel Corp.\n" +" * All rights reserved.\n" +" *\n" +" * Redistribution and use in source and binary forms, with or without\n" +" * modification, are permitted provided that the following conditions\n" +" * are met:\n" +" * 1. Redistributions of source code must retain the above copyright\n" +" * notice, this list of conditions, and the following disclaimer,\n" +" * without modification.\n" +" * 2. Redistributions in binary form must reproduce at minimum a disclaimer\n" +" * substantially similar to the \"NO WARRANTY\" disclaimer below\n" +" * (\"Disclaimer\") and any redistribution must be conditioned upon\n" +" * including a substantially similar Disclaimer requirement for further\n" +" * binary redistribution.\n" +" * 3. Neither the names of the above-listed copyright holders nor the names\n" +" * of any contributors may be used to endorse or promote products derived\n" +" * from this software without specific prior written permission.\n" +" *\n" +" * Alternatively, this software may be distributed under the terms of the\n" +" * GNU General Public License (\"GPL\") version 2 as published by the Free\n" +" * Software Foundation.\n" +" *\n" +" * NO WARRANTY\n" +" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n" +" * \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n" +" * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR\n" +" * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n" +" * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n" +" * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n" +" * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n" +" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n" +" * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\n" +" * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n" +" * POSSIBILITY OF SUCH DAMAGES.\n" +" */\n"; + +ACPI_STRING_TABLE LinuxDataTypes[] = { + +/* + * Extra space is added after the type so there is room to add "struct", "union", + * etc. when the existing struct typedefs are eliminated. + */ + + /* Declarations first - ACPI types and standard C types */ + + {"INT64 ", "s64 ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"UINT64 ", "u64 ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"UINT32 ", "u32 ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"INT32 ", "s32 ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"UINT16 ", "u16 ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"INT16 ", "s16 ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"UINT8 ", "u8 ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"BOOLEAN ", "u8 ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"char ", "char ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"void ", "void ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"char * ", "char * ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"void * ", "void * ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"int ", "int ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"FILE ", "FILE ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + {"size_t ", "size_t ", REPLACE_WHOLE_WORD | EXTRA_INDENT_C}, + + /* Now do embedded typecasts */ + + {"UINT64", "u64", REPLACE_WHOLE_WORD}, + {"UINT32", "u32", REPLACE_WHOLE_WORD}, + {"UINT16", "u16", REPLACE_WHOLE_WORD}, + {"UINT8", "u8", REPLACE_WHOLE_WORD}, + {"BOOLEAN", "u8", REPLACE_WHOLE_WORD}, + + {"INT64 ", "s64 ", REPLACE_WHOLE_WORD}, + {"INT64", "s64", REPLACE_WHOLE_WORD}, + {"INT32 ", "s32 ", REPLACE_WHOLE_WORD}, + {"INT32", "s32", REPLACE_WHOLE_WORD}, + {"INT16 ", "s16 ", REPLACE_WHOLE_WORD}, + {"INT8 ", "s8 ", REPLACE_WHOLE_WORD}, + {"INT16", "s16", REPLACE_WHOLE_WORD}, + {"INT8", "s8", REPLACE_WHOLE_WORD}, + + /* Include file paths */ + + {"\"acpi.h\"", "<acpi/acpi.h>", REPLACE_WHOLE_WORD}, + + {NULL, NULL, 0} +}; + +ACPI_TYPED_IDENTIFIER_TABLE AcpiIdentifiers[] = { + + {"ACPI_ADR_SPACE_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_ADR_SPACE_SETUP", SRC_TYPE_SIMPLE}, + {"ACPI_ADR_SPACE_TYPE", SRC_TYPE_SIMPLE}, + {"ACPI_AML_OPERANDS", SRC_TYPE_UNION}, + {"ACPI_BIT_REGISTER_INFO", SRC_TYPE_STRUCT}, + {"ACPI_BUFFER", SRC_TYPE_STRUCT}, + {"ACPI_BUS_ATTRIBUTE", SRC_TYPE_STRUCT}, + {"ACPI_CACHE_T", SRC_TYPE_SIMPLE}, + {"ACPI_CMTABLE_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_COMMON_FACS", SRC_TYPE_STRUCT}, + {"ACPI_COMMON_STATE", SRC_TYPE_STRUCT}, + {"ACPI_COMMON_DESCRIPTOR", SRC_TYPE_STRUCT}, + {"ACPI_COMPATIBLE_ID", SRC_TYPE_STRUCT}, + {"ACPI_CONNECTION_INFO", SRC_TYPE_STRUCT}, + {"ACPI_CONTROL_STATE", SRC_TYPE_STRUCT}, + {"ACPI_CONVERSION_TABLE", SRC_TYPE_STRUCT}, + {"ACPI_CPU_FLAGS", SRC_TYPE_SIMPLE}, + {"ACPI_CREATE_FIELD_INFO", SRC_TYPE_STRUCT}, + {"ACPI_DB_METHOD_INFO", SRC_TYPE_STRUCT}, + {"ACPI_DEBUG_MEM_BLOCK", SRC_TYPE_STRUCT}, + {"ACPI_DEBUG_MEM_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_DEBUG_PRINT_INFO", SRC_TYPE_STRUCT}, + {"ACPI_DESCRIPTOR", SRC_TYPE_UNION}, + {"ACPI_DEVICE_ID", SRC_TYPE_STRUCT}, + {"ACPI_DEVICE_ID_LIST", SRC_TYPE_STRUCT}, + {"ACPI_DEVICE_INFO", SRC_TYPE_STRUCT}, + {"ACPI_DEVICE_WALK_INFO", SRC_TYPE_STRUCT}, + {"ACPI_DMTABLE_DATA", SRC_TYPE_STRUCT}, + {"ACPI_DMTABLE_INFO", SRC_TYPE_STRUCT}, + {"ACPI_DMTABLE_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_EVALUATE_INFO", SRC_TYPE_STRUCT}, + {"ACPI_EVENT_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_EVENT_STATUS", SRC_TYPE_SIMPLE}, + {"ACPI_EVENT_TYPE", SRC_TYPE_SIMPLE}, + {"ACPI_EXCEPTION_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_EXDUMP_INFO", SRC_TYPE_STRUCT}, + {"ACPI_EXECUTE_OP", SRC_TYPE_SIMPLE}, + {"ACPI_EXECUTE_TYPE", SRC_TYPE_SIMPLE}, + {"ACPI_EXECUTE_WALK", SRC_TYPE_STRUCT}, + {"ACPI_EXTERNAL_LIST", SRC_TYPE_STRUCT}, + {"ACPI_EXTERNAL_FILE", SRC_TYPE_STRUCT}, + {"ACPI_FADT_INFO", SRC_TYPE_STRUCT}, + {"ACPI_FADT_PM_INFO", SRC_TYPE_STRUCT}, + {"ACPI_FIELD_INFO", SRC_TYPE_STRUCT}, + {"ACPI_FIND_CONTEXT", SRC_TYPE_STRUCT}, + {"ACPI_FIXED_EVENT_HANDLER", SRC_TYPE_STRUCT}, + {"ACPI_FIXED_EVENT_INFO", SRC_TYPE_STRUCT}, + {"ACPI_GBL_EVENT_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_GENERIC_ADDRESS", SRC_TYPE_STRUCT}, + {"ACPI_GENERIC_STATE", SRC_TYPE_UNION}, + {"ACPI_GET_DEVICES_INFO", SRC_TYPE_STRUCT}, + {"ACPI_GPE_BLOCK_INFO", SRC_TYPE_STRUCT}, + {"ACPI_GPE_CALLBACK", SRC_TYPE_SIMPLE}, + {"ACPI_GPE_DEVICE_INFO", SRC_TYPE_STRUCT}, + {"ACPI_GPE_EVENT_INFO", SRC_TYPE_STRUCT}, + {"ACPI_GPE_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_GPE_HANDLER_INFO", SRC_TYPE_STRUCT}, + {"ACPI_GPE_INDEX_INFO", SRC_TYPE_STRUCT}, + {"ACPI_GPE_REGISTER_INFO", SRC_TYPE_STRUCT}, + {"ACPI_GPE_WALK_INFO", SRC_TYPE_STRUCT}, + {"ACPI_GPE_XRUPT_INFO", SRC_TYPE_STRUCT}, + {"ACPI_HANDLE", SRC_TYPE_SIMPLE}, + {"ACPI_HANDLER_INFO", SRC_TYPE_STRUCT}, + {"ACPI_INIT_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_INTERFACE_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_IDENTIFIER_TABLE", SRC_TYPE_STRUCT}, + {"ACPI_INIT_WALK_INFO", SRC_TYPE_STRUCT}, + {"ACPI_INTEGER", SRC_TYPE_SIMPLE}, + {"ACPI_INTEGER_OVERLAY", SRC_TYPE_STRUCT}, + {"ACPI_INTEGRITY_INFO", SRC_TYPE_STRUCT}, + {"ACPI_INTERFACE_INFO", SRC_TYPE_STRUCT}, + {"ACPI_INTERNAL_METHOD", SRC_TYPE_SIMPLE}, + {"ACPI_INTERPRETER_MODE", SRC_TYPE_SIMPLE}, + {"ACPI_IO_ADDRESS", SRC_TYPE_SIMPLE}, + {"ACPI_IO_ATTRIBUTE", SRC_TYPE_STRUCT}, + {"ACPI_MEM_SPACE_CONTEXT", SRC_TYPE_STRUCT}, + {"ACPI_MEMORY_ATTRIBUTE", SRC_TYPE_STRUCT}, + {"ACPI_MEMORY_LIST", SRC_TYPE_STRUCT}, + {"ACPI_MUTEX", SRC_TYPE_SIMPLE}, + {"ACPI_MUTEX_HANDLE", SRC_TYPE_SIMPLE}, + {"ACPI_MUTEX_INFO", SRC_TYPE_STRUCT}, + {"ACPI_NAME", SRC_TYPE_SIMPLE}, + {"ACPI_NAME_INFO", SRC_TYPE_STRUCT}, + {"ACPI_NAME_UNION", SRC_TYPE_UNION}, + {"ACPI_NAMESPACE_NODE", SRC_TYPE_STRUCT}, + {"ACPI_NAMESTRING_INFO", SRC_TYPE_STRUCT}, + {"ACPI_NATIVE_INT", SRC_TYPE_SIMPLE}, + {"ACPI_NATIVE_UINT", SRC_TYPE_SIMPLE}, + {"ACPI_NOTIFY_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_NOTIFY_INFO", SRC_TYPE_STRUCT}, + {"ACPI_NS_SEARCH_DATA", SRC_TYPE_STRUCT}, + {"ACPI_OBJ_INFO_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT", SRC_TYPE_UNION}, + {"ACPI_OBJECT_ADDR_HANDLER", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_BANK_FIELD", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_BUFFER", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_BUFFER_FIELD", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_CACHE_LIST", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_COMMON", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_DATA", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_DEVICE", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_EVENT", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_EXTRA", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_FIELD_COMMON", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_OBJECT_INDEX_FIELD", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_INTEGER", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_LIST", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_METHOD", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_MUTEX", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_NOTIFY_COMMON", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_NOTIFY_HANDLER", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_PACKAGE", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_POWER_RESOURCE", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_PROCESSOR", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_REFERENCE", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_REGION", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_REGION_FIELD", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_STRING", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_THERMAL_ZONE", SRC_TYPE_STRUCT}, + {"ACPI_OBJECT_TYPE", SRC_TYPE_SIMPLE}, + {"ACPI_OBJECT_TYPE8", SRC_TYPE_SIMPLE}, + {"ACPI_OP_WALK_INFO", SRC_TYPE_STRUCT}, + {"ACPI_OPCODE_INFO", SRC_TYPE_STRUCT}, + {"ACPI_OPERAND_OBJECT", SRC_TYPE_UNION}, + {"ACPI_OSD_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_OSD_EXEC_CALLBACK", SRC_TYPE_SIMPLE}, + {"ACPI_OWNER_ID", SRC_TYPE_SIMPLE}, + {"ACPI_PACKAGE_INFO", SRC_TYPE_STRUCT}, + {"ACPI_PACKAGE_INFO2", SRC_TYPE_STRUCT}, + {"ACPI_PACKAGE_INFO3", SRC_TYPE_STRUCT}, + {"ACPI_PARSE_DOWNWARDS", SRC_TYPE_SIMPLE}, + {"ACPI_PARSE_OBJ_ASL", SRC_TYPE_STRUCT}, + {"ACPI_PARSE_OBJ_COMMON", SRC_TYPE_STRUCT}, + {"ACPI_PARSE_OBJ_NAMED", SRC_TYPE_STRUCT}, + {"ACPI_PARSE_OBJECT", SRC_TYPE_UNION}, + {"ACPI_PARSE_STATE", SRC_TYPE_STRUCT}, + {"ACPI_PARSE_UPWARDS", SRC_TYPE_SIMPLE}, + {"ACPI_PARSE_VALUE", SRC_TYPE_UNION}, + {"ACPI_PCI_DEVICE", SRC_TYPE_STRUCT}, + {"ACPI_PCI_ID", SRC_TYPE_STRUCT}, + {"ACPI_PCI_ROUTING_TABLE", SRC_TYPE_STRUCT}, + {"ACPI_PHYSICAL_ADDRESS", SRC_TYPE_SIMPLE}, + {"ACPI_PKG_CALLBACK", SRC_TYPE_SIMPLE}, + {"ACPI_PKG_INFO", SRC_TYPE_STRUCT}, + {"ACPI_PKG_STATE", SRC_TYPE_STRUCT}, + {"ACPI_PMTT_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_POINTER", SRC_TYPE_STRUCT}, + {"ACPI_POINTERS", SRC_TYPE_UNION}, + {"ACPI_PORT_INFO", SRC_TYPE_STRUCT}, + {"ACPI_PREDEFINED_DATA", SRC_TYPE_STRUCT}, + {"ACPI_PREDEFINED_INFO", SRC_TYPE_UNION}, + {"ACPI_PREDEFINED_NAMES", SRC_TYPE_STRUCT}, + {"ACPI_PSCOPE_STATE", SRC_TYPE_STRUCT}, + {"ACPI_REPAIR_FUNCTION", SRC_TYPE_SIMPLE}, + {"ACPI_REPAIR_INFO", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_RESOURCE_ADDRESS", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_ADDRESS16", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_ADDRESS32", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_ADDRESS64", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_COMMON_SERIALBUS", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_EXTENDED_ADDRESS64", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_ATTRIBUTE", SRC_TYPE_UNION}, + {"ACPI_RESOURCE_DATA", SRC_TYPE_UNION}, + {"ACPI_RESOURCE_DMA", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_END_TAG", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_EXTENDED_IRQ", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_FIXED_DMA", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_FIXED_IO", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_FIXED_MEMORY32", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_GENERIC_REGISTER", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_GPIO", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_I2C_SERIALBUS", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_INFO", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_IO", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_IRQ", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_MEMORY24", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_MEMORY32", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_SOURCE", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_SPI_SERIALBUS", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_START_DEPENDENT", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_TAG", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_TYPE", SRC_TYPE_SIMPLE}, + {"ACPI_RESOURCE_UART_SERIALBUS", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_VENDOR", SRC_TYPE_STRUCT}, + {"ACPI_RESOURCE_VENDOR_TYPED", SRC_TYPE_STRUCT}, + {"ACPI_RESULT_VALUES", SRC_TYPE_STRUCT}, + {"ACPI_ROUND_UP_TO_32_BIT", SRC_TYPE_SIMPLE}, + {"ACPI_RSCONVERT_INFO", SRC_TYPE_STRUCT}, + {"ACPI_RSDUMP_INFO", SRC_TYPE_STRUCT}, + {"ACPI_RW_LOCK", SRC_TYPE_STRUCT}, + {"ACPI_S3PT_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_SCOPE_STATE", SRC_TYPE_STRUCT}, + {"ACPI_SEMAPHORE", SRC_TYPE_SIMPLE}, + {"ACPI_SIGNAL_FATAL_INFO", SRC_TYPE_STRUCT}, + {"ACPI_SIZE", SRC_TYPE_SIMPLE}, + {"ACPI_SLEEP_FUNCTION", SRC_TYPE_SIMPLE}, + {"ACPI_SLEEP_FUNCTIONS", SRC_TYPE_STRUCT}, + {"ACPI_SPINLOCK", SRC_TYPE_SIMPLE}, + {"ACPI_STATISTICS", SRC_TYPE_STRUCT}, + {"ACPI_STATUS", SRC_TYPE_SIMPLE}, + {"ACPI_STRING", SRC_TYPE_SIMPLE}, + {"ACPI_STRING_TABLE", SRC_TYPE_STRUCT}, + {"ACPI_SUBTABLE_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_SYSTEM_INFO", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_DESC", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_HANDLER", SRC_TYPE_SIMPLE}, + {"ACPI_TABLE_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_INFO", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_LIST", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_SUPPORT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_TYPE", SRC_TYPE_SIMPLE}, + {"ACPI_TAG_INFO", SRC_TYPE_STRUCT}, + {"ACPI_THREAD_ID", SRC_TYPE_SIMPLE}, + {"ACPI_THREAD_STATE", SRC_TYPE_STRUCT}, + {"ACPI_TYPED_IDENTIFIER_TABLE", SRC_TYPE_STRUCT}, + {"ACPI_UINTPTR_T", SRC_TYPE_SIMPLE}, + {"ACPI_UPDATE_STATE", SRC_TYPE_STRUCT}, + {"ACPI_UUID", SRC_TYPE_STRUCT}, + {"ACPI_VENDOR_UUID", SRC_TYPE_STRUCT}, + {"ACPI_VENDOR_WALK_INFO", SRC_TYPE_STRUCT}, + {"ACPI_WALK_AML_CALLBACK", SRC_TYPE_SIMPLE}, + {"ACPI_WALK_CALLBACK", SRC_TYPE_SIMPLE}, + {"ACPI_WALK_RESOURCE_CALLBACK", SRC_TYPE_SIMPLE}, + {"ACPI_WALK_INFO", SRC_TYPE_STRUCT}, + {"ACPI_WALK_STATE", SRC_TYPE_STRUCT}, + {"ACPI_WHEA_HEADER", SRC_TYPE_STRUCT}, + + {"ACPI_RS_LENGTH", SRC_TYPE_SIMPLE}, + {"ACPI_RSDESC_SIZE", SRC_TYPE_SIMPLE}, + + {"AML_RESOURCE", SRC_TYPE_UNION}, + {"AML_RESOURCE_ADDRESS", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_ADDRESS16", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_ADDRESS32", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_ADDRESS64", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_COMMON_SERIALBUS", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_DMA", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_END_DEPENDENT", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_END_TAG", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_EXTENDED_ADDRESS64", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_EXTENDED_IRQ", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_FIXED_DMA", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_FIXED_IO", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_FIXED_MEMORY32", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_GENERIC_REGISTER", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_GPIO", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_IO", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_I2C_SERIALBUS", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_IRQ", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_IRQ_NOFLAGS", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_LARGE_HEADER", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_MEMORY24", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_MEMORY32", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_SMALL_HEADER", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_SPI_SERIALBUS", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_START_DEPENDENT", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_START_DEPENDENT_NOPRIO", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_UART_SERIALBUS", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_VENDOR_LARGE", SRC_TYPE_STRUCT}, + {"AML_RESOURCE_VENDOR_SMALL", SRC_TYPE_STRUCT}, + + {"APIC_HEADER", SRC_TYPE_STRUCT}, + {"ARGUMENT_INFO", SRC_TYPE_STRUCT}, + {"AE_DEBUG_REGIONS", SRC_TYPE_STRUCT}, + {"AE_REGION", SRC_TYPE_STRUCT}, + {"AE_TABLE_DESC", SRC_TYPE_STRUCT}, + {"ASL_ANALYSIS_WALK_INFO", SRC_TYPE_STRUCT}, + {"ASL_ERROR_MSG", SRC_TYPE_STRUCT}, + {"ASL_EVENT_INFO", SRC_TYPE_STRUCT}, + {"ASL_FILE_INFO", SRC_TYPE_STRUCT}, + {"ASL_FILE_STATUS", SRC_TYPE_STRUCT}, + {"ASL_INCLUDE_DIR", SRC_TYPE_STRUCT}, + {"ASL_LISTING_NODE", SRC_TYPE_STRUCT}, + {"ASL_MAPPING_ENTRY", SRC_TYPE_STRUCT}, + {"ASL_METHOD_INFO", SRC_TYPE_STRUCT}, + {"ASL_RESERVED_INFO", SRC_TYPE_STRUCT}, + {"ASL_RESOURCE_NODE", SRC_TYPE_STRUCT}, + {"ASL_WALK_CALLBACK", SRC_TYPE_SIMPLE}, + {"COMMAND_INFO", SRC_TYPE_STRUCT}, + {"UINT64_OVERLAY", SRC_TYPE_UNION}, + {"UINT64_STRUCT", SRC_TYPE_STRUCT}, + + /* + * Acpi table definition names. + */ + {"ACPI_TABLE_ASF", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_BERT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_BGRT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_BOOT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_CPEP", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_DBGP", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_DMAR", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_DRTM", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_ECDT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_EINJ", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_ERST", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_FACS", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_FADT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_FPDT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_HEST", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_HPET", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_IBFT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_IVRS", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_MADT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_MCFG", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_MCHI", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_MPST", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_MSCT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_PCCT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_RSDP", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_RSDT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_MCHI", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_S3PT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_SBST", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_SLIC", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_SLIT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_SPCR", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_SPMI", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_SRAT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_TCPA", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_UEFI", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_WAET", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_WDAT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_WDDT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_WDRT", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_XSDT", SRC_TYPE_STRUCT}, + + {"ACPI_ASF_ADDRESS", SRC_TYPE_STRUCT}, + {"ACPI_ASF_ALERT", SRC_TYPE_STRUCT}, + {"ACPI_ASF_ALERT_DATA", SRC_TYPE_STRUCT}, + {"ACPI_ASF_CONTROL_DATA", SRC_TYPE_STRUCT}, + {"ACPI_ASF_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_ASF_INFO", SRC_TYPE_STRUCT}, + {"ACPI_ASF_REMOTE", SRC_TYPE_STRUCT}, + {"ACPI_ASF_RMCP", SRC_TYPE_STRUCT}, + {"ACPI_BERT_REGION", SRC_TYPE_STRUCT}, + {"ACPI_CPEP_POLLING", SRC_TYPE_STRUCT}, + {"ACPI_DMAR_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_DMAR_DEVICE_SCOPE", SRC_TYPE_STRUCT}, + {"ACPI_DMAR_ATSR", SRC_TYPE_STRUCT}, + {"ACPI_DMAR_RHSA", SRC_TYPE_STRUCT}, + {"ACPI_DMAR_HARDWARE_UNIT", SRC_TYPE_STRUCT}, + {"ACPI_DMAR_RESERVED_MEMORY", SRC_TYPE_STRUCT}, + {"ACPI_EINJ_ENTRY", SRC_TYPE_STRUCT}, + {"ACPI_EINJ_TRIGGER", SRC_TYPE_STRUCT}, + {"ACPI_FPDT_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_FPDT_BOOT", SRC_TYPE_STRUCT}, + {"ACPI_FPDT_S3PT_PTR", SRC_TYPE_STRUCT}, + {"ACPI_ERST_ENTRY", SRC_TYPE_STRUCT}, + {"ACPI_ERST_INFO", SRC_TYPE_STRUCT}, + {"ACPI_HEST_AER_COMMON", SRC_TYPE_STRUCT}, + {"ACPI_HEST_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_HEST_NOTIFY", SRC_TYPE_STRUCT}, + {"ACPI_HEST_IA_ERROR_BANK", SRC_TYPE_STRUCT}, + {"ACPI_HEST_IA_MACHINE_CHECK", SRC_TYPE_STRUCT}, + {"ACPI_HEST_IA_CORRECTED", SRC_TYPE_STRUCT}, + {"ACPI_HEST_IA_NMI", SRC_TYPE_STRUCT}, + {"ACPI_HEST_AER_ROOT", SRC_TYPE_STRUCT}, + {"ACPI_HEST_AER", SRC_TYPE_STRUCT}, + {"ACPI_HEST_AER_BRIDGE", SRC_TYPE_STRUCT}, + {"ACPI_HEST_GENERIC", SRC_TYPE_STRUCT}, + {"ACPI_HEST_GENERIC_STATUS", SRC_TYPE_STRUCT}, + {"ACPI_HEST_GENERIC_DATA", SRC_TYPE_STRUCT}, + {"ACPI_IBFT_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_IBFT_CONTROL", SRC_TYPE_STRUCT}, + {"ACPI_IBFT_INITIATOR", SRC_TYPE_STRUCT}, + {"ACPI_IBFT_NIC", SRC_TYPE_STRUCT}, + {"ACPI_IBFT_TARGET", SRC_TYPE_STRUCT}, + {"ACPI_IVRS_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_IVRS_HARDWARE", SRC_TYPE_STRUCT}, + {"ACPI_IVRS_DE_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_IVRS_DEVICE4", SRC_TYPE_STRUCT}, + {"ACPI_IVRS_DEVICE8A", SRC_TYPE_STRUCT}, + {"ACPI_IVRS_DEVICE8B", SRC_TYPE_STRUCT}, + {"ACPI_IVRS_DEVICE8C", SRC_TYPE_STRUCT}, + {"ACPI_IVRS_MEMORY", SRC_TYPE_STRUCT}, + {"ACPI_MADT_ADDRESS_OVERRIDE", SRC_TYPE_STRUCT}, + {"ACPI_MADT_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_MADT_IO_APIC", SRC_TYPE_STRUCT}, + {"ACPI_MADT_IO_SAPIC", SRC_TYPE_STRUCT}, + {"ACPI_MADT_LOCAL_APIC", SRC_TYPE_STRUCT}, + {"ACPI_MADT_LOCAL_APIC_NMI", SRC_TYPE_STRUCT}, + {"ACPI_MADT_LOCAL_APIC_OVERRIDE", SRC_TYPE_STRUCT}, + {"ACPI_MADT_LOCAL_SAPIC", SRC_TYPE_STRUCT}, + {"ACPI_MADT_LOCAL_X2APIC", SRC_TYPE_STRUCT}, + {"ACPI_MADT_LOCAL_X2APIC_NMI", SRC_TYPE_STRUCT}, + {"ACPI_MADT_GENERIC_DISTRIBUTOR", SRC_TYPE_STRUCT}, + {"ACPI_MADT_GENERIC_INTERRUPT", SRC_TYPE_STRUCT}, + {"ACPI_MADT_INTERRUPT_OVERRIDE", SRC_TYPE_STRUCT}, + {"ACPI_MADT_INTERRUPT_SOURCE", SRC_TYPE_STRUCT}, + {"ACPI_MADT_NMI_SOURCE", SRC_TYPE_STRUCT}, + {"ACPI_MADT_PROCESSOR_APIC", SRC_TYPE_STRUCT}, + {"ACPI_MPST_COMPONENT", SRC_TYPE_STRUCT}, + {"ACPI_MPST_DATA_HDR", SRC_TYPE_STRUCT}, + {"ACPI_MPST_POWER_DATA", SRC_TYPE_STRUCT}, + {"ACPI_MPST_POWER_NODE", SRC_TYPE_STRUCT}, + {"ACPI_MPST_POWER_STATE", SRC_TYPE_STRUCT}, + {"ACPI_MCFG_ALLOCATION", SRC_TYPE_STRUCT}, + {"ACPI_MSCT_PROXIMITY", SRC_TYPE_STRUCT}, + {"ACPI_PCCT_SUBSPACE", SRC_TYPE_STRUCT}, + {"ACPI_RSDP_COMMON", SRC_TYPE_STRUCT}, + {"ACPI_RSDP_EXTENSION", SRC_TYPE_STRUCT}, + {"ACPI_S3PT_RESUME", SRC_TYPE_STRUCT}, + {"ACPI_S3PT_SUSPEND", SRC_TYPE_STRUCT}, + {"ACPI_SLIC_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_SLIC_KEY", SRC_TYPE_STRUCT}, + {"ACPI_SLIC_MARKER", SRC_TYPE_STRUCT}, + {"ACPI_SRAT_CPU_AFFINITY", SRC_TYPE_STRUCT}, + {"ACPI_SRAT_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_SRAT_MEM_AFFINITY", SRC_TYPE_STRUCT}, + {"ACPI_SRAT_X2APIC_CPU_AFFINITY", SRC_TYPE_STRUCT}, + {"ACPI_WDAT_ENTRY", SRC_TYPE_STRUCT}, + + /* Data Table compiler */ + + {"DT_FIELD", SRC_TYPE_STRUCT}, + {"DT_SUBTABLE", SRC_TYPE_STRUCT}, + {"DT_WALK_CALLBACK", SRC_TYPE_SIMPLE}, + + /* AcpiHelp utility */ + + {"AH_AML_OPCODE", SRC_TYPE_STRUCT}, + {"AH_ASL_OPERATOR", SRC_TYPE_STRUCT}, + {"AH_ASL_KEYWORD", SRC_TYPE_STRUCT}, + {"AH_PREDEFINED_NAME", SRC_TYPE_STRUCT}, + + /* AcpiXtract utility */ + + {"AX_TABLE_INFO", SRC_TYPE_STRUCT}, + + {NULL, 0} +}; + + +ACPI_IDENTIFIER_TABLE LinuxAddStruct[] = { + {"acpi_namespace_node"}, + {"acpi_parse_object"}, + {"acpi_table_desc"}, + {"acpi_walk_state"}, + {NULL} +}; + + +ACPI_IDENTIFIER_TABLE LinuxEliminateMacros[] = { + + {"ACPI_GET_ADDRESS"}, + {"ACPI_VALID_ADDRESS"}, + {NULL} +}; + + +ACPI_IDENTIFIER_TABLE LinuxEliminateLines_C[] = { + + {"#define __"}, + {NULL} +}; + + +ACPI_IDENTIFIER_TABLE LinuxEliminateLines_H[] = { + + {NULL} +}; + + +ACPI_IDENTIFIER_TABLE LinuxConditionalIdentifiers[] = { + +/* {"ACPI_USE_STANDARD_HEADERS"}, */ + {"WIN32"}, + {"_MSC_VER"}, + {NULL} +}; + +ACPI_CONVERSION_TABLE LinuxConversionTable = { + + DualLicenseHeader, + FLG_NO_CARRIAGE_RETURNS | FLG_LOWERCASE_DIRNAMES, + + AcpiIdentifiers, + + /* C source files */ + + LinuxDataTypes, + LinuxEliminateLines_C, + NULL, + LinuxEliminateMacros, + AcpiIdentifiers, + (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES | + CVT_CHECK_BRACES | CVT_TRIM_LINES | CVT_BRACES_ON_SAME_LINE | + CVT_MIXED_CASE_TO_UNDERSCORES | CVT_LOWER_CASE_IDENTIFIERS | + CVT_REMOVE_DEBUG_MACROS | CVT_TRIM_WHITESPACE | + CVT_REMOVE_EMPTY_BLOCKS | CVT_SPACES_TO_TABS8), + + /* C header files */ + + LinuxDataTypes, + LinuxEliminateLines_H, + LinuxConditionalIdentifiers, + NULL, + AcpiIdentifiers, + (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES | + CVT_TRIM_LINES | CVT_MIXED_CASE_TO_UNDERSCORES | + CVT_LOWER_CASE_IDENTIFIERS | CVT_TRIM_WHITESPACE | + CVT_REMOVE_EMPTY_BLOCKS| CVT_REDUCE_TYPEDEFS | CVT_SPACES_TO_TABS8), +}; + + +/****************************************************************************** + * + * Code cleanup translation tables + * + ******************************************************************************/ + +ACPI_CONVERSION_TABLE CleanupConversionTable = { + + NULL, + FLG_DEFAULT_FLAGS, + NULL, + /* C source files */ + + NULL, + NULL, + NULL, + NULL, + NULL, + (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES | + CVT_CHECK_BRACES | CVT_TRIM_LINES | CVT_TRIM_WHITESPACE), + + /* C header files */ + + NULL, + NULL, + NULL, + NULL, + NULL, + (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES | + CVT_TRIM_LINES | CVT_TRIM_WHITESPACE), +}; + + +ACPI_CONVERSION_TABLE StatsConversionTable = { + + NULL, + FLG_NO_FILE_OUTPUT, + NULL, + + /* C source files */ + + NULL, + NULL, + NULL, + NULL, + NULL, + (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES | + CVT_COUNT_SHORTMULTILINE_COMMENTS), + + /* C header files */ + + NULL, + NULL, + NULL, + NULL, + NULL, + (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES | + CVT_COUNT_SHORTMULTILINE_COMMENTS), +}; + + +/****************************************************************************** + * + * Dual License injection translation table + * + ******************************************************************************/ + +ACPI_CONVERSION_TABLE LicenseConversionTable = { + + DualLicenseHeader, + FLG_DEFAULT_FLAGS, + NULL, + + /* C source files */ + + NULL, + NULL, + NULL, + NULL, + NULL, + (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES | + CVT_COUNT_SHORTMULTILINE_COMMENTS), + + /* C header files */ + + NULL, + NULL, + NULL, + NULL, + NULL, + (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES | + CVT_COUNT_SHORTMULTILINE_COMMENTS), +}; + + +/****************************************************************************** + * + * Customizable translation tables + * + ******************************************************************************/ + +ACPI_STRING_TABLE CustomReplacements[] = { + + + {"(c) 1999 - 2012", "(c) 1999 - 2012", REPLACE_WHOLE_WORD}, /* Main ACPICA source */ + {"(c) 2006 - 2012", "(c) 2006 - 2012", REPLACE_WHOLE_WORD}, /* Test suites */ + +#if 0 + {"(ACPI_INTEGER)", "(UINT64)", REPLACE_WHOLE_WORD}, + {"ACPI_INTEGER ", "UINT64 ", REPLACE_WHOLE_WORD}, + {"ACPI_INTEGER", "UINT64", REPLACE_WHOLE_WORD}, + {"ACPI_INTEGER_MAX", "ACPI_UINT64_MAX", REPLACE_WHOLE_WORD}, + {"#include \"acpi.h\"", "#include \"acpi.h\"\n#include \"accommon.h\"", REPLACE_SUBSTRINGS}, + {"AcpiTbSumTable", "AcpiTbSumTable", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_BOOT", "ACPI_SIG_BOOT", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_DBGP", "ACPI_SIG_DBGP", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_DSDT", "ACPI_SIG_DSDT", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_ECDT", "ACPI_SIG_ECDT", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_FACS", "ACPI_SIG_FACS", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_FADT", "ACPI_SIG_FADT", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_HPET", "ACPI_SIG_HPET", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_MADT", "ACPI_SIG_MADT", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_MCFG", "ACPI_SIG_MCFG", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_PSDT", "ACPI_SIG_PSDT", REPLACE_WHOLE_WORD}, + {"ACPI_NAME_RSDP", "ACPI_NAME_RSDP", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_RSDP", "ACPI_SIG_RSDP", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_RSDT", "ACPI_SIG_RSDT", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_SBST", "ACPI_SIG_SBST", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_SLIT", "ACPI_SIG_SLIT", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_SPCR", "ACPI_SIG_SPCR", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_SPIC", "ACPI_SIG_SPIC", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_SPMI", "ACPI_SIG_SPMI", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_SRAT", "ACPI_SIG_SRAT", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_SSDT", "ACPI_SIG_SSDT", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_TCPA", "ACPI_SIG_TCPA", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_WDRT", "ACPI_SIG_WDRT", REPLACE_WHOLE_WORD}, + {"ACPI_SIG_XSDT", "ACPI_SIG_XSDT", REPLACE_WHOLE_WORD}, + + {"ACPI_ALLOCATE_ZEROED", "ACPI_ALLOCATE_ZEROED", REPLACE_WHOLE_WORD}, + {"ACPI_ALLOCATE", "ACPI_ALLOCATE", REPLACE_WHOLE_WORD}, + {"ACPI_FREE", "ACPI_FREE", REPLACE_WHOLE_WORD}, + + "ACPI_NATIVE_UINT", "ACPI_NATIVE_UINT", REPLACE_WHOLE_WORD, + "ACPI_NATIVE_UINT *", "ACPI_NATIVE_UINT *", REPLACE_WHOLE_WORD, + "ACPI_NATIVE_UINT", "ACPI_NATIVE_UINT", REPLACE_WHOLE_WORD, + "ACPI_NATIVE_INT", "ACPI_NATIVE_INT", REPLACE_WHOLE_WORD, + "ACPI_NATIVE_INT *", "ACPI_NATIVE_INT *", REPLACE_WHOLE_WORD, + "ACPI_NATIVE_INT", "ACPI_NATIVE_INT", REPLACE_WHOLE_WORD, +#endif + + {NULL, NULL, 0} +}; + + +ACPI_CONVERSION_TABLE CustomConversionTable = { + + NULL, + FLG_DEFAULT_FLAGS, + NULL, + + /* C source files */ + + CustomReplacements, + LinuxEliminateLines_H, + NULL, + NULL, + NULL, + (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES | + CVT_TRIM_LINES | CVT_TRIM_WHITESPACE), + + /* C header files */ + + CustomReplacements, + LinuxEliminateLines_H, + NULL, + NULL, + NULL, + (CVT_COUNT_TABS | CVT_COUNT_NON_ANSI_COMMENTS | CVT_COUNT_LINES | + CVT_TRIM_LINES | CVT_TRIM_WHITESPACE), +}; + diff --git a/source/tools/acpisrc/asutils.c b/source/tools/acpisrc/asutils.c new file mode 100644 index 000000000000..a596ea8cee06 --- /dev/null +++ b/source/tools/acpisrc/asutils.c @@ -0,0 +1,234 @@ + +/****************************************************************************** + * + * Module Name: asutils - common utilities + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpisrc.h" + + +/****************************************************************************** + * + * FUNCTION: AsSkipUntilChar + * + * DESCRIPTION: Find the next instance of the input character + * + ******************************************************************************/ + +char * +AsSkipUntilChar ( + char *Buffer, + char Target) +{ + + while (*Buffer != Target) + { + if (!*Buffer) + { + return NULL; + } + + Buffer++; + } + + return (Buffer); +} + + +/****************************************************************************** + * + * FUNCTION: AsSkipPastChar + * + * DESCRIPTION: Find the next instance of the input character, return a buffer + * pointer to this character+1. + * + ******************************************************************************/ + +char * +AsSkipPastChar ( + char *Buffer, + char Target) +{ + + while (*Buffer != Target) + { + if (!*Buffer) + { + return NULL; + } + + Buffer++; + } + + Buffer++; + + return (Buffer); +} + + +/****************************************************************************** + * + * FUNCTION: AsReplaceData + * + * DESCRIPTION: This function inserts and removes data from the file buffer. + * if more data is inserted than is removed, the data in the buffer + * is moved to make room. If less data is inserted than is removed, + * the remaining data is moved to close the hole. + * + ******************************************************************************/ + +char * +AsReplaceData ( + char *Buffer, + UINT32 LengthToRemove, + char *BufferToAdd, + UINT32 LengthToAdd) +{ + UINT32 BufferLength; + + + /* + * Buffer is a string, so the length must include the terminating zero + */ + BufferLength = strlen (Buffer) + 1; + + if (LengthToRemove != LengthToAdd) + { + /* + * Move some of the existing data + * 1) If adding more bytes than removing, make room for the new data + * 2) if removing more bytes than adding, delete the extra space + */ + if (LengthToRemove > 0) + { + Gbl_MadeChanges = TRUE; + memmove ((Buffer + LengthToAdd), (Buffer + LengthToRemove), (BufferLength - LengthToRemove)); + } + } + + /* + * Now we can move in the new data + */ + if (LengthToAdd > 0) + { + Gbl_MadeChanges = TRUE; + memmove (Buffer, BufferToAdd, LengthToAdd); + } + + return (Buffer + LengthToAdd); +} + + +/****************************************************************************** + * + * FUNCTION: AsInsertData + * + * DESCRIPTION: This function inserts and removes data from the file buffer. + * if more data is inserted than is removed, the data in the buffer + * is moved to make room. If less data is inserted than is removed, + * the remaining data is moved to close the hole. + * + ******************************************************************************/ + +char * +AsInsertData ( + char *Buffer, + char *BufferToAdd, + UINT32 LengthToAdd) +{ + UINT32 BufferLength; + + + if (LengthToAdd > 0) + { + /* + * Buffer is a string, so the length must include the terminating zero + */ + BufferLength = strlen (Buffer) + 1; + + /* + * Move some of the existing data + * 1) If adding more bytes than removing, make room for the new data + * 2) if removing more bytes than adding, delete the extra space + */ + Gbl_MadeChanges = TRUE; + memmove ((Buffer + LengthToAdd), Buffer, BufferLength); + + /* + * Now we can move in the new data + */ + memmove (Buffer, BufferToAdd, LengthToAdd); + } + + return (Buffer + LengthToAdd); +} + + +/****************************************************************************** + * + * FUNCTION: AsRemoveData + * + * DESCRIPTION: This function inserts and removes data from the file buffer. + * if more data is inserted than is removed, the data in the buffer + * is moved to make room. If less data is inserted than is removed, + * the remaining data is moved to close the hole. + * + ******************************************************************************/ + +char * +AsRemoveData ( + char *StartPointer, + char *EndPointer) +{ + UINT32 BufferLength; + + + /* + * Buffer is a string, so the length must include the terminating zero + */ + BufferLength = strlen (EndPointer) + 1; + + Gbl_MadeChanges = TRUE; + memmove (StartPointer, EndPointer, BufferLength); + + return (StartPointer); +} + diff --git a/source/tools/acpixtract/Makefile b/source/tools/acpixtract/Makefile new file mode 100644 index 000000000000..d5db832a7394 --- /dev/null +++ b/source/tools/acpixtract/Makefile @@ -0,0 +1,116 @@ +# +# acpixtract - extract binary ACPI tables from acpidump text output +# +# NOTE: This makefile is intended to be used within the native +# ACPICA source tree. +# + +# +# Configuration +# Notes: +# gcc should be version 4 or greater, otherwise some of the options +# used will not be recognized. +# Global optimization flags (such as -O2, -Os) are not used, since +# they cause issues on some compilers. +# The _GNU_SOURCE symbol is required for many hosts. +# +PROG = acpixtract + +HOST = _LINUX +NOMAN = YES +COMPILE = $(CC) -c $(CFLAGS) $(CWARNINGFLAGS) -o$@ $< + +ACPICA_SRC = ../../../source +ACPICA_COMMON = $(ACPICA_SRC)/common +ACPICA_TOOLS = $(ACPICA_SRC)/tools +ACPICA_OSL = $(ACPICA_SRC)/os_specific/service_layers +ACPICA_CORE = $(ACPICA_SRC)/components +ACPICA_INCLUDE = $(ACPICA_SRC)/include +ACPICA_DEBUGGER = $(ACPICA_CORE)/debugger +ACPICA_DISASSEMBLER = $(ACPICA_CORE)/disassembler +ACPICA_DISPATCHER = $(ACPICA_CORE)/dispatcher +ACPICA_EVENTS = $(ACPICA_CORE)/events +ACPICA_EXECUTER = $(ACPICA_CORE)/executer +ACPICA_HARDWARE = $(ACPICA_CORE)/hardware +ACPICA_NAMESPACE = $(ACPICA_CORE)/namespace +ACPICA_PARSER = $(ACPICA_CORE)/parser +ACPICA_RESOURCES = $(ACPICA_CORE)/resources +ACPICA_TABLES = $(ACPICA_CORE)/tables +ACPICA_UTILITIES = $(ACPICA_CORE)/utilities +ACPIXTRACT = $(ACPICA_TOOLS)/acpixtract +INSTALLDIR = /usr/bin +INSTALLPROG = cp --remove-destination $(PROG) $(INSTALLDIR) + +ACPICA_HEADERS = \ + $(wildcard $(ACPICA_INCLUDE)/*.h) \ + $(wildcard $(ACPICA_INCLUDE)/platform/*.h) + +# +# Search paths for source files +# +vpath %.c \ + $(ACPIXTRACT) \ + $(ACPICA_COMMON) + +HEADERS = \ + $(wildcard $(ACPIXTRACT)/*.h) + +OBJECTS = \ + acpixtract.o \ + axmain.o \ + getopt.o + +CFLAGS+= \ + -D$(HOST) \ + -D_GNU_SOURCE \ + -DACPI_XTRACT_APP \ + -I$(ACPICA_INCLUDE) + +CWARNINGFLAGS = \ + -ansi \ + -Wall \ + -Wbad-function-cast \ + -Wdeclaration-after-statement \ + -Werror \ + -Wformat=2 \ + -Wmissing-declarations \ + -Wmissing-prototypes \ + -Wstrict-aliasing=0 \ + -Wstrict-prototypes \ + -Wswitch-default \ + -Wpointer-arith \ + -Wundef + +# +# gcc 4+ flags +# +CWARNINGFLAGS += \ + -Waddress \ + -Waggregate-return \ + -Wchar-subscripts \ + -Wempty-body \ + -Wlogical-op \ + -Wmissing-declarations \ + -Wmissing-field-initializers \ + -Wmissing-parameter-type \ + -Wnested-externs \ + -Wold-style-declaration \ + -Wold-style-definition \ + -Wredundant-decls \ + -Wtype-limits + +# +# Rules +# +$(PROG) : $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) -o $(PROG) + $(COPYPROG) + +%.o : %.c $(HEADERS) $(ACPICA_HEADERS) + $(COMPILE) + +clean : + rm -f $(PROG) $(PROG).exe $(OBJECTS) + +install : + $(INSTALLPROG) diff --git a/source/tools/acpixtract/acpixtract.c b/source/tools/acpixtract/acpixtract.c new file mode 100644 index 000000000000..85ce346af152 --- /dev/null +++ b/source/tools/acpixtract/acpixtract.c @@ -0,0 +1,740 @@ +/****************************************************************************** + * + * Module Name: acpixtract - convert ascii ACPI tables to binary + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpi.h" +#include "accommon.h" +#include "acapps.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + +/* Local prototypes */ + +static void +AxStrlwr ( + char *String); + +static void +AxCheckAscii ( + char *Name, + int Count); + +static void +AxNormalizeSignature ( + char *Signature); + +static unsigned int +AxGetNextInstance ( + char *InputPathname, + char *Signature); + +static size_t +AxGetTableHeader ( + FILE *InputFile, + unsigned char *OutputData); + +static unsigned int +AxCountTableInstances ( + char *InputPathname, + char *Signature); + +int +AxExtractTables ( + char *InputPathname, + char *Signature, + unsigned int MinimumInstances); + +int +AxListTables ( + char *InputPathname); + +static size_t +AxConvertLine ( + char *InputLine, + unsigned char *OutputData); + + +typedef struct AxTableInfo +{ + UINT32 Signature; + unsigned int Instances; + unsigned int NextInstance; + struct AxTableInfo *Next; + +} AX_TABLE_INFO; + +/* Extraction states */ + +#define AX_STATE_FIND_HEADER 0 +#define AX_STATE_EXTRACT_DATA 1 + +/* Miscellaneous constants */ + +#define AX_LINE_BUFFER_SIZE 256 +#define AX_MIN_TABLE_NAME_LENGTH 6 /* strlen ("DSDT @") */ + + +static AX_TABLE_INFO *AxTableListHead = NULL; +static char Filename[16]; +static unsigned char Data[16]; +static char LineBuffer[AX_LINE_BUFFER_SIZE]; +static char HeaderBuffer[AX_LINE_BUFFER_SIZE]; +static char InstanceBuffer[AX_LINE_BUFFER_SIZE]; + + +/******************************************************************************* + * + * FUNCTION: AxStrlwr + * + * PARAMETERS: String - Ascii string + * + * RETURN: None + * + * DESCRIPTION: String lowercase function. + * + ******************************************************************************/ + +static void +AxStrlwr ( + char *String) +{ + + while (*String) + { + *String = (char) tolower ((int) *String); + String++; + } +} + + +/******************************************************************************* + * + * FUNCTION: AxCheckAscii + * + * PARAMETERS: Name - Ascii string, at least as long as Count + * Count - Number of characters to check + * + * RETURN: None + * + * DESCRIPTION: Ensure that the requested number of characters are printable + * Ascii characters. Sets non-printable and null chars to <space>. + * + ******************************************************************************/ + +static void +AxCheckAscii ( + char *Name, + int Count) +{ + int i; + + + for (i = 0; i < Count; i++) + { + if (!Name[i] || !isprint ((int) Name[i])) + { + Name[i] = ' '; + } + } +} + + +/******************************************************************************* + * + * FUNCTION: AxNormalizeSignature + * + * PARAMETERS: Name - Ascii string containing an ACPI signature + * + * RETURN: None + * + * DESCRIPTION: Change "RSD PTR" to "RSDP" + * + ******************************************************************************/ + +static void +AxNormalizeSignature ( + char *Signature) +{ + + if (!strncmp (Signature, "RSD ", 4)) + { + Signature[3] = 'P'; + } +} + + +/****************************************************************************** + * + * FUNCTION: AxConvertLine + * + * PARAMETERS: InputLine - One line from the input acpidump file + * OutputData - Where the converted data is returned + * + * RETURN: The number of bytes actually converted + * + * DESCRIPTION: Convert one line of ascii text binary (up to 16 bytes) + * + ******************************************************************************/ + +static size_t +AxConvertLine ( + char *InputLine, + unsigned char *OutputData) +{ + char *End; + int BytesConverted; + int Converted[16]; + int i; + + + /* Terminate the input line at the end of the actual data (for sscanf) */ + + End = strstr (InputLine + 2, " "); + if (!End) + { + return (0); /* Don't understand the format */ + } + *End = 0; + + /* + * Convert one line of table data, of the form: + * <offset>: <up to 16 bytes of hex data> <ASCII representation> <newline> + * + * Example: + * 02C0: 5F 53 42 5F 4C 4E 4B 44 00 12 13 04 0C FF FF 08 _SB_LNKD........ + */ + BytesConverted = sscanf (InputLine, + "%*s %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x", + &Converted[0], &Converted[1], &Converted[2], &Converted[3], + &Converted[4], &Converted[5], &Converted[6], &Converted[7], + &Converted[8], &Converted[9], &Converted[10], &Converted[11], + &Converted[12], &Converted[13], &Converted[14], &Converted[15]); + + /* Pack converted data into a byte array */ + + for (i = 0; i < BytesConverted; i++) + { + OutputData[i] = (unsigned char) Converted[i]; + } + + return ((size_t) BytesConverted); +} + + +/****************************************************************************** + * + * FUNCTION: AxGetTableHeader + * + * PARAMETERS: InputFile - Handle for the input acpidump file + * OutputData - Where the table header is returned + * + * RETURN: The actual number of bytes converted + * + * DESCRIPTION: Extract and convert an ACPI table header + * + ******************************************************************************/ + +static size_t +AxGetTableHeader ( + FILE *InputFile, + unsigned char *OutputData) +{ + size_t BytesConverted; + size_t TotalConverted = 0; + int i; + + + /* Get the full 36 byte ACPI table header, requires 3 input text lines */ + + for (i = 0; i < 3; i++) + { + if (!fgets (HeaderBuffer, AX_LINE_BUFFER_SIZE, InputFile)) + { + return (TotalConverted); + } + + BytesConverted = AxConvertLine (HeaderBuffer, OutputData); + TotalConverted += BytesConverted; + OutputData += 16; + + if (BytesConverted != 16) + { + return (TotalConverted); + } + } + + return (TotalConverted); +} + + +/****************************************************************************** + * + * FUNCTION: AxCountTableInstances + * + * PARAMETERS: InputPathname - Filename for acpidump file + * Signature - Requested signature to count + * + * RETURN: The number of instances of the signature + * + * DESCRIPTION: Count the instances of tables with the given signature within + * the input acpidump file. + * + ******************************************************************************/ + +static unsigned int +AxCountTableInstances ( + char *InputPathname, + char *Signature) +{ + FILE *InputFile; + unsigned int Instances = 0; + + + InputFile = fopen (InputPathname, "rt"); + if (!InputFile) + { + printf ("Could not open %s\n", InputPathname); + return (0); + } + + /* Count the number of instances of this signature */ + + while (fgets (InstanceBuffer, AX_LINE_BUFFER_SIZE, InputFile)) + { + /* Ignore empty lines and lines that start with a space */ + + if ((InstanceBuffer[0] == ' ') || + (InstanceBuffer[0] == '\n')) + { + continue; + } + + AxNormalizeSignature (InstanceBuffer); + if (!strncmp (InstanceBuffer, Signature, 4)) + { + Instances++; + } + } + + fclose (InputFile); + return (Instances); +} + + +/****************************************************************************** + * + * FUNCTION: AxGetNextInstance + * + * PARAMETERS: InputPathname - Filename for acpidump file + * Signature - Requested ACPI signature + * + * RETURN: The next instance number for this signature. Zero if this + * is the first instance of this signature. + * + * DESCRIPTION: Get the next instance number of the specified table. If this + * is the first instance of the table, create a new instance + * block. Note: only SSDT and PSDT tables can have multiple + * instances. + * + ******************************************************************************/ + +static unsigned int +AxGetNextInstance ( + char *InputPathname, + char *Signature) +{ + AX_TABLE_INFO *Info; + + + Info = AxTableListHead; + while (Info) + { + if (*(UINT32 *) Signature == Info->Signature) + { + break; + } + + Info = Info->Next; + } + + if (!Info) + { + /* Signature not found, create new table info block */ + + Info = malloc (sizeof (AX_TABLE_INFO)); + if (!Info) + { + printf ("Could not allocate memory\n"); + exit (0); + } + + Info->Signature = *(UINT32 *) Signature; + Info->Instances = AxCountTableInstances (InputPathname, Signature); + Info->NextInstance = 1; + Info->Next = AxTableListHead; + AxTableListHead = Info; + } + + if (Info->Instances > 1) + { + return (Info->NextInstance++); + } + + return (0); +} + + +/****************************************************************************** + * + * FUNCTION: AxExtractTables + * + * PARAMETERS: InputPathname - Filename for acpidump file + * Signature - Requested ACPI signature to extract. + * NULL means extract ALL tables. + * MinimumInstances - Min instances that are acceptable + * + * RETURN: Status + * + * DESCRIPTION: Convert text ACPI tables to binary + * + ******************************************************************************/ + +int +AxExtractTables ( + char *InputPathname, + char *Signature, + unsigned int MinimumInstances) +{ + FILE *InputFile; + FILE *OutputFile = NULL; + size_t BytesWritten; + size_t TotalBytesWritten = 0; + size_t BytesConverted; + unsigned int State = AX_STATE_FIND_HEADER; + unsigned int FoundTable = 0; + unsigned int Instances = 0; + unsigned int ThisInstance; + char ThisSignature[4]; + int Status = 0; + + + /* Open input in text mode, output is in binary mode */ + + InputFile = fopen (InputPathname, "rt"); + if (!InputFile) + { + printf ("Could not open %s\n", InputPathname); + return (-1); + } + + if (Signature) + { + /* Are there enough instances of the table to continue? */ + + AxNormalizeSignature (Signature); + + Instances = AxCountTableInstances (InputPathname, Signature); + if (Instances < MinimumInstances) + { + printf ("Table %s was not found in %s\n", Signature, InputPathname); + Status = -1; + goto CleanupAndExit; + } + + if (Instances == 0) + { + goto CleanupAndExit; + } + } + + /* Convert all instances of the table to binary */ + + while (fgets (LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) + { + switch (State) + { + case AX_STATE_FIND_HEADER: + + /* Ignore lines that are too short to be header lines */ + + if (strlen (LineBuffer) < AX_MIN_TABLE_NAME_LENGTH) + { + continue; + } + + /* Ignore empty lines and lines that start with a space */ + + if ((LineBuffer[0] == ' ') || + (LineBuffer[0] == '\n')) + { + continue; + } + + /* + * Ignore lines that are not of the form <sig> @ <addr>. + * Examples of lines that must be supported: + * + * DSDT @ 0x737e4000 + * XSDT @ 0x737f2fff + * RSD PTR @ 0xf6cd0 + * SSDT @ (nil) + */ + if (!strstr (LineBuffer, " @ ")) + { + continue; + } + + AxNormalizeSignature (LineBuffer); + strncpy (ThisSignature, LineBuffer, 4); + + if (Signature) + { + /* Ignore signatures that don't match */ + + if (strncmp (ThisSignature, Signature, 4)) + { + continue; + } + } + + /* + * Get the instance number for this signature. Only the + * SSDT and PSDT tables can have multiple instances. + */ + ThisInstance = AxGetNextInstance (InputPathname, ThisSignature); + + /* Build an output filename and create/open the output file */ + + if (ThisInstance > 0) + { + sprintf (Filename, "%4.4s%u.dat", ThisSignature, ThisInstance); + } + else + { + sprintf (Filename, "%4.4s.dat", ThisSignature); + } + + AxStrlwr (Filename); + OutputFile = fopen (Filename, "w+b"); + if (!OutputFile) + { + printf ("Could not open %s\n", Filename); + Status = -1; + goto CleanupAndExit; + } + + State = AX_STATE_EXTRACT_DATA; + TotalBytesWritten = 0; + FoundTable = 1; + continue; + + case AX_STATE_EXTRACT_DATA: + + /* Empty line or non-data line terminates the data */ + + if ((LineBuffer[0] == '\n') || + (LineBuffer[0] != ' ')) + { + fclose (OutputFile); + OutputFile = NULL; + State = AX_STATE_FIND_HEADER; + + printf ("Acpi table [%4.4s] - %u bytes written to %s\n", + ThisSignature, (unsigned int) TotalBytesWritten, Filename); + continue; + } + + /* Convert the ascii data (one line of text) to binary */ + + BytesConverted = AxConvertLine (LineBuffer, Data); + + /* Write the binary data */ + + BytesWritten = fwrite (Data, 1, BytesConverted, OutputFile); + if (BytesWritten != BytesConverted) + { + printf ("Write error on %s\n", Filename); + fclose (OutputFile); + OutputFile = NULL; + Status = -1; + goto CleanupAndExit; + } + + TotalBytesWritten += BytesConverted; + continue; + + default: + Status = -1; + goto CleanupAndExit; + } + } + + if (!FoundTable) + { + printf ("Table %s was not found in %s\n", Signature, InputPathname); + } + + +CleanupAndExit: + + if (OutputFile) + { + fclose (OutputFile); + if (State == AX_STATE_EXTRACT_DATA) + { + /* Received an EOF while extracting data */ + + printf ("Acpi table [%4.4s] - %u bytes written to %s\n", + ThisSignature, (unsigned int) TotalBytesWritten, Filename); + } + } + + fclose (InputFile); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: AxListTables + * + * PARAMETERS: InputPathname - Filename for acpidump file + * + * RETURN: Status + * + * DESCRIPTION: Display info for all ACPI tables found in input. Does not + * perform an actual extraction of the tables. + * + ******************************************************************************/ + +int +AxListTables ( + char *InputPathname) +{ + FILE *InputFile; + size_t HeaderSize; + unsigned char Header[48]; + int TableCount = 0; + ACPI_TABLE_HEADER *TableHeader = (ACPI_TABLE_HEADER *) (void *) Header; + + + /* Open input in text mode, output is in binary mode */ + + InputFile = fopen (InputPathname, "rt"); + if (!InputFile) + { + printf ("Could not open %s\n", InputPathname); + return (-1); + } + + /* Dump the headers for all tables found in the input file */ + + printf ("\nSignature Length Revision OemId OemTableId" + " OemRevision CompilerId CompilerRevision\n\n"); + + while (fgets (LineBuffer, AX_LINE_BUFFER_SIZE, InputFile)) + { + /* Ignore empty lines and lines that start with a space */ + + if ((LineBuffer[0] == ' ') || + (LineBuffer[0] == '\n')) + { + continue; + } + + /* Get the 36 byte header and display the fields */ + + HeaderSize = AxGetTableHeader (InputFile, Header); + if (HeaderSize < 16) + { + continue; + } + + /* RSDP has an oddball signature and header */ + + if (!strncmp (TableHeader->Signature, "RSD PTR ", 8)) + { + AxCheckAscii ((char *) &Header[9], 6); + printf ("%8.4s \"%6.6s\"\n", "RSDP", &Header[9]); + TableCount++; + continue; + } + + /* Minimum size for table with standard header */ + + if (HeaderSize < sizeof (ACPI_TABLE_HEADER)) + { + continue; + } + + /* Signature and Table length */ + + TableCount++; + printf ("%8.4s % 7d", TableHeader->Signature, TableHeader->Length); + + /* FACS has only signature and length */ + + if (!strncmp (TableHeader->Signature, "FACS", 4)) + { + printf ("\n"); + continue; + } + + /* OEM IDs and Compiler IDs */ + + AxCheckAscii (TableHeader->OemId, 6); + AxCheckAscii (TableHeader->OemTableId, 8); + AxCheckAscii (TableHeader->AslCompilerId, 4); + + printf (" %2.2X \"%6.6s\" \"%8.8s\" %8.8X \"%4.4s\" %8.8X\n", + TableHeader->Revision, TableHeader->OemId, + TableHeader->OemTableId, TableHeader->OemRevision, + TableHeader->AslCompilerId, TableHeader->AslCompilerRevision); + } + + printf ("\nFound %u ACPI tables\n", TableCount); + fclose (InputFile); + return (0); +} diff --git a/source/tools/acpixtract/axmain.c b/source/tools/acpixtract/axmain.c new file mode 100644 index 000000000000..5d275802916e --- /dev/null +++ b/source/tools/acpixtract/axmain.c @@ -0,0 +1,191 @@ +/****************************************************************************** + * + * Module Name: axmain - main module for acpixtract utility + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpi.h" +#include "accommon.h" +#include "acapps.h" +#include <stdio.h> + + +static void +DisplayUsage ( + void); + +int +AxExtractTables ( + char *InputPathname, + char *Signature, + unsigned int MinimumInstances); + +int +AxListTables ( + char *InputPathname); + + +/* Options */ + +#define AX_EXTRACT_ALL 0 +#define AX_LIST_ALL 1 +#define AX_EXTRACT_SIGNATURE 2 +#define AX_EXTRACT_AML_TABLES 3 + +static int AxAction = AX_EXTRACT_AML_TABLES; /* DSDT & SSDTs */ + +#define AX_OPTIONAL_TABLES 0 +#define AX_REQUIRED_TABLE 1 + + +/****************************************************************************** + * + * FUNCTION: DisplayUsage + * + * DESCRIPTION: Usage message + * + ******************************************************************************/ + +static void +DisplayUsage ( + void) +{ + + ACPI_USAGE_HEADER ("acpixtract [option] <InputFile>"); + + ACPI_OPTION ("-a", "Extract all tables, not just DSDT/SSDT"); + ACPI_OPTION ("-l", "List table summaries, do not extract"); + ACPI_OPTION ("-s <signature>", "Extract all tables with <signature>"); + + printf ("\nExtract binary ACPI tables from text acpidump output\n"); + printf ("Default invocation extracts the DSDT and all SSDTs\n"); +} + + +/****************************************************************************** + * + * FUNCTION: main + * + * DESCRIPTION: C main function + * + ******************************************************************************/ + +int +main ( + int argc, + char *argv[]) +{ + char *Filename; + int Status; + int j; + + + printf (ACPI_COMMON_SIGNON ("ACPI Binary Table Extraction Utility")); + + if (argc < 2) + { + DisplayUsage (); + return (0); + } + + /* Command line options */ + + while ((j = AcpiGetopt (argc, argv, "ahls:")) != EOF) switch (j) + { + case 'a': + AxAction = AX_EXTRACT_ALL; /* Extract all tables found */ + break; + + case 'l': + AxAction = AX_LIST_ALL; /* List tables only, do not extract */ + break; + + case 's': + AxAction = AX_EXTRACT_SIGNATURE; /* Extract only tables with this sig */ + break; + + case 'h': + default: + DisplayUsage (); + return (0); + } + + /* Input filename is always required */ + + Filename = argv[AcpiGbl_Optind]; + if (!Filename) + { + printf ("Missing required input filename\n"); + return (-1); + } + + /* Perform requested action */ + + switch (AxAction) + { + case AX_EXTRACT_ALL: + Status = AxExtractTables (Filename, NULL, AX_OPTIONAL_TABLES); + break; + + case AX_LIST_ALL: + Status = AxListTables (Filename); + break; + + case AX_EXTRACT_SIGNATURE: + Status = AxExtractTables (Filename, AcpiGbl_Optarg, AX_REQUIRED_TABLE); + break; + + default: + /* + * Default output is the DSDT and all SSDTs. One DSDT is required, + * any SSDTs are optional. + */ + Status = AxExtractTables (Filename, "DSDT", AX_REQUIRED_TABLE); + if (Status) + { + return (Status); + } + + Status = AxExtractTables (Filename, "SSDT", AX_OPTIONAL_TABLES); + break; + } + + return (Status); +} diff --git a/source/tools/examples/examples.c b/source/tools/examples/examples.c new file mode 100644 index 000000000000..570683e29311 --- /dev/null +++ b/source/tools/examples/examples.c @@ -0,0 +1,449 @@ +/****************************************************************************** + * + * Module Name: examples - Example ACPICA code + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +/* Set the ACPICA application type for use in include/platform/acenv.h */ + +#ifndef WIN32 +#define WIN32 +#endif + +#define ACPI_DEBUG_OUTPUT + +/* ACPICA public headers */ + +#include "acpi.h" + +#define _COMPONENT ACPI_EXAMPLE + ACPI_MODULE_NAME ("examples") + + +/****************************************************************************** + * + * ACPICA Example Code + * + * This module contains examples of how the host OS should interface to the + * ACPICA subsystem. + * + * 1) How to use the platform/acenv.h file and how to set configuration + * options. + * + * 2) main - using the debug output mechanism and the error/warning output + * macros. + * + * 3) Two examples of the ACPICA initialization sequence. The first is a + * initialization with no "early" ACPI table access. The second shows + * how to use ACPICA to obtain the tables very early during kernel + * initialization, even before dynamic memory is available. + * + * 4) How to invoke a control method, including argument setup and how to + * access the return value. + * + *****************************************************************************/ + +/* Standard Clib headers */ + +#include <stdio.h> +#include <string.h> + +/* Local Prototypes */ + +ACPI_STATUS +InitializeFullAcpi (void); + +ACPI_STATUS +InstallHandlers (void); + +void +ExecuteOSI (void); + + +/****************************************************************************** + * + * FUNCTION: main + * + * PARAMETERS: argc, argv + * + * RETURN: Status + * + * DESCRIPTION: Main routine. Shows the use of the various output macros, as + * well as the use of the debug layer/level globals. + * + *****************************************************************************/ + +int ACPI_SYSTEM_XFACE +main ( + int argc, + char **argv) +{ + ACPI_FUNCTION_NAME (Examples-main); + + + InitializeFullAcpi (); + + /* Enable debug output, example debug print */ + + AcpiDbgLayer = ACPI_EXAMPLE; + AcpiDbgLevel = ACPI_LV_INIT; + ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "Example Debug output\n")); + + /* Example warning and error output */ + + ACPI_INFO ((AE_INFO, "ACPICA example info message")); + ACPI_WARNING ((AE_INFO, "ACPICA example warning message")); + ACPI_ERROR ((AE_INFO, "ACPICA example error message")); + ACPI_EXCEPTION ((AE_INFO, AE_AML_OPERAND_TYPE, "Example exception message")); + + ExecuteOSI (); + return (0); +} + + +/****************************************************************************** + * + * Example ACPICA initialization code. This shows a full initialization with + * no early ACPI table access. + * + *****************************************************************************/ + +ACPI_STATUS +InitializeFullAcpi (void) +{ + ACPI_STATUS Status; + + + /* Initialize the ACPICA subsystem */ + + Status = AcpiInitializeSubsystem (); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, "While initializing ACPICA")); + return (Status); + } + + /* Initialize the ACPICA Table Manager and get all ACPI tables */ + + Status = AcpiInitializeTables (NULL, 16, FALSE); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, "While initializing Table Manager")); + return (Status); + } + + /* Create the ACPI namespace from ACPI tables */ + + Status = AcpiLoadTables (); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, "While loading ACPI tables")); + return (Status); + } + + /* Install local handlers */ + + Status = InstallHandlers (); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, "While installing handlers")); + return (Status); + } + + /* Initialize the ACPI hardware */ + + Status = AcpiEnableSubsystem (ACPI_FULL_INITIALIZATION); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, "While enabling ACPICA")); + return (Status); + } + + /* Complete the ACPI namespace object initialization */ + + Status = AcpiInitializeObjects (ACPI_FULL_INITIALIZATION); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, "While initializing ACPICA objects")); + return (Status); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * Example ACPICA initialization code with early ACPI table access. This shows + * an initialization that requires early access to ACPI tables (before + * kernel dynamic memory is available) + * + *****************************************************************************/ + +/* + * The purpose of this static table array is to avoid the use of kernel + * dynamic memory which may not be available during early ACPI table + * access. + */ +#define ACPI_MAX_INIT_TABLES 16 +static ACPI_TABLE_DESC TableArray[ACPI_MAX_INIT_TABLES]; + + +/* + * This function would be called early in kernel initialization. After this + * is called, all ACPI tables are available to the host. + */ +ACPI_STATUS +InitializeAcpiTables (void) +{ + ACPI_STATUS Status; + + + /* Initialize the ACPICA Table Manager and get all ACPI tables */ + + Status = AcpiInitializeTables (TableArray, ACPI_MAX_INIT_TABLES, TRUE); + return (Status); +} + + +/* + * This function would be called after the kernel is initialized and + * dynamic/virtual memory is available. It completes the initialization of + * the ACPICA subsystem. + */ +ACPI_STATUS +InitializeAcpi (void) +{ + ACPI_STATUS Status; + + + /* Initialize the ACPICA subsystem */ + + Status = AcpiInitializeSubsystem (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Copy the root table list to dynamic memory */ + + Status = AcpiReallocateRootTable (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Create the ACPI namespace from ACPI tables */ + + Status = AcpiLoadTables (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Install local handlers */ + + Status = InstallHandlers (); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, "While installing handlers")); + return (Status); + } + + /* Initialize the ACPI hardware */ + + Status = AcpiEnableSubsystem (ACPI_FULL_INITIALIZATION); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Complete the ACPI namespace object initialization */ + + Status = AcpiInitializeObjects (ACPI_FULL_INITIALIZATION); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * Example ACPICA handler and handler installation + * + *****************************************************************************/ + +void +NotifyHandler ( + ACPI_HANDLE Device, + UINT32 Value, + void *Context) +{ + + ACPI_INFO ((AE_INFO, "Received a notify 0x%X", Value)); +} + + +ACPI_STATUS +InstallHandlers (void) +{ + ACPI_STATUS Status; + + + /* Install global notify handler */ + + Status = AcpiInstallNotifyHandler (ACPI_ROOT_OBJECT, ACPI_SYSTEM_NOTIFY, + NotifyHandler, NULL); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, "While installing Notify handler")); + return (Status); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * Example control method execution. + * + * _OSI is a predefined method that is implemented internally within ACPICA. + * + * Shows the following elements: + * + * 1) How to setup a control method argument and argument list + * 2) How to setup the return value object + * 3) How to invoke AcpiEvaluateObject + * 4) How to check the returned ACPI_STATUS + * 5) How to analyze the return value + * + *****************************************************************************/ + +void +ExecuteOSI (void) +{ + ACPI_STATUS Status; + ACPI_OBJECT_LIST ArgList; + ACPI_OBJECT Arg[1]; + ACPI_BUFFER ReturnValue; + ACPI_OBJECT *Object; + + + ACPI_INFO ((AE_INFO, "Executing OSI method")); + + /* Setup input argument */ + + ArgList.Count = 1; + ArgList.Pointer = Arg; + + Arg[0].Type = ACPI_TYPE_STRING; + Arg[0].String.Pointer = "Windows 2001"; + Arg[0].String.Length = strlen (Arg[0].String.Pointer); + + /* Ask ACPICA to allocate space for the return object */ + + ReturnValue.Length = ACPI_ALLOCATE_BUFFER; + + Status = AcpiEvaluateObject (NULL, "\\_OSI", &ArgList, &ReturnValue); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, "While executing _OSI")); + return; + } + + /* Ensure that the return object is large enough */ + + if (ReturnValue.Length < sizeof (ACPI_OBJECT)) + { + AcpiOsPrintf ("Return value from _OSI method too small, %.8X\n", + ReturnValue.Length); + return; + } + + /* Expect an integer return value from execution of _OSI */ + + Object = ReturnValue.Pointer; + if (Object->Type != ACPI_TYPE_INTEGER) + { + AcpiOsPrintf ("Invalid return type from _OSI, %.2X\n", Object->Type); + } + + ACPI_INFO ((AE_INFO, "_OSI returned 0x%8.8X", (UINT32) Object->Integer.Value)); + AcpiOsFree (Object); + return; +} + + +/****************************************************************************** + * + * OSL support (only needed to link to the windows OSL) + * + *****************************************************************************/ + +FILE *AcpiGbl_DebugFile; + +ACPI_PHYSICAL_ADDRESS +AeLocalGetRootPointer ( + void) +{ + + return (0); +} + +ACPI_THREAD_ID +AcpiOsGetThreadId ( + void) +{ + return (0xFFFF); +} + +ACPI_STATUS +AcpiOsExecute ( + ACPI_EXECUTE_TYPE Type, + ACPI_OSD_EXEC_CALLBACK Function, + void *Context) +{ + return (AE_SUPPORT); +} |