diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/Makefile | 8 | ||||
-rw-r--r-- | compiler/aslanalyze.c | 2 | ||||
-rw-r--r-- | compiler/aslcompile.c | 65 | ||||
-rw-r--r-- | compiler/aslcompiler.h | 21 | ||||
-rw-r--r-- | compiler/aslcompiler.l | 2 | ||||
-rw-r--r-- | compiler/aslcompiler.y | 2 | ||||
-rw-r--r-- | compiler/asldefine.h | 7 | ||||
-rw-r--r-- | compiler/aslerror.c | 2 | ||||
-rw-r--r-- | compiler/aslfiles.c | 8 | ||||
-rw-r--r-- | compiler/aslglobal.h | 7 | ||||
-rw-r--r-- | compiler/asllookup.c | 4 | ||||
-rw-r--r-- | compiler/aslmain.c | 16 | ||||
-rw-r--r-- | compiler/aslopt.c | 2 | ||||
-rw-r--r-- | compiler/aslpredef.c | 6 | ||||
-rw-r--r-- | compiler/aslstartup.c | 185 | ||||
-rw-r--r-- | compiler/asltransform.c | 2 | ||||
-rw-r--r-- | compiler/asltree.c | 12 | ||||
-rw-r--r-- | compiler/asltypes.h | 35 | ||||
-rw-r--r-- | compiler/aslutils.c | 56 | ||||
-rw-r--r-- | compiler/dtcompile.c | 614 | ||||
-rw-r--r-- | compiler/dtcompiler.h | 455 | ||||
-rw-r--r-- | compiler/dtfield.c | 543 | ||||
-rw-r--r-- | compiler/dtio.c | 512 | ||||
-rw-r--r-- | compiler/dtsubtable.c | 400 | ||||
-rw-r--r-- | compiler/dttable.c | 1399 | ||||
-rw-r--r-- | compiler/dtutils.c | 894 |
26 files changed, 5156 insertions, 103 deletions
diff --git a/compiler/Makefile b/compiler/Makefile index 2bdd0d31d264..6b6ac5c5105d 100644 --- a/compiler/Makefile +++ b/compiler/Makefile @@ -32,6 +32,12 @@ SRCS= \ asltransform.c \ asltree.c \ aslutils.c \ + dtcompile.c \ + dtfield.c \ + dtio.c \ + dtsubtable.c \ + dttable.c \ + dtutils.c \ ../common/getopt.c \ ../utilities/utalloc.c \ ../utilities/utcache.c \ @@ -119,7 +125,7 @@ SRCS= \ ../osunixxf.c NOMAN= YES -CFLAGS+= -Wall -O2 -Wstrict-prototypes -D_LINUX -DACPI_ASL_COMPILER -I../include +CFLAGS+= -Wall -O2 -Wstrict-prototypes -D_LINUX -DACPI_ASL_COMPILER -I../include -I../compiler #YACC= yacc YACC= bison diff --git a/compiler/aslanalyze.c b/compiler/aslanalyze.c index 19440c875c3b..9679d904c8cf 100644 --- a/compiler/aslanalyze.c +++ b/compiler/aslanalyze.c @@ -531,7 +531,7 @@ AnGetBtype ( if (!Node) { DbgPrint (ASL_DEBUG_OUTPUT, - "No attached Nsnode: [%s] at line %d name [%s], ignoring typecheck\n", + "No attached Nsnode: [%s] at line %u name [%s], ignoring typecheck\n", Op->Asl.ParseOpName, Op->Asl.LineNumber, Op->Asl.ExternalName); return ACPI_UINT32_MAX; diff --git a/compiler/aslcompile.c b/compiler/aslcompile.c index d6cb8adc7387..56663b571247 100644 --- a/compiler/aslcompile.c +++ b/compiler/aslcompile.c @@ -127,10 +127,6 @@ static void CmFlushSourceCode ( void); -static ACPI_STATUS -FlCheckForAscii ( - ASL_FILE_INFO *FileInfo); - void FlConsumeAnsiComment ( ASL_FILE_INFO *FileInfo, @@ -433,7 +429,7 @@ FlConsumeNewComment ( * ******************************************************************************/ -static ACPI_STATUS +ACPI_STATUS FlCheckForAscii ( ASL_FILE_INFO *FileInfo) { @@ -543,31 +539,6 @@ CmDoCompile ( FullCompile = UtBeginEvent ("*** Total Compile time ***"); Event = UtBeginEvent ("Open input and output files"); - - /* Open the required input and output files */ - - Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename); - if (ACPI_FAILURE (Status)) - { - AePrintErrorLog (ASL_FILE_STDERR); - return -1; - } - - /* Check for 100% ASCII source file (comments are ignored) */ - - Status = FlCheckForAscii (&Gbl_Files[ASL_FILE_INPUT]); - if (ACPI_FAILURE (Status)) - { - AePrintErrorLog (ASL_FILE_STDERR); - return -1; - } - - Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix); - if (ACPI_FAILURE (Status)) - { - AePrintErrorLog (ASL_FILE_STDERR); - return -1; - } UtEndEvent (Event); /* Build the parse tree */ @@ -888,19 +859,24 @@ CmCleanupAndExit ( if (Gbl_NsLookupCount) { - DbgPrint (ASL_DEBUG_OUTPUT, "\n\nMiscellaneous compile statistics\n\n"); - DbgPrint (ASL_DEBUG_OUTPUT, "%32s : %d\n", "Total Namespace searches", + DbgPrint (ASL_DEBUG_OUTPUT, + "\n\nMiscellaneous compile statistics\n\n"); + + DbgPrint (ASL_DEBUG_OUTPUT, + "%32s : %u\n", "Total Namespace searches", Gbl_NsLookupCount); - DbgPrint (ASL_DEBUG_OUTPUT, "%32s : %d usec\n", "Time per search", - ((UINT32) (AslGbl_Events[AslGbl_NamespaceEvent].EndTime - - AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / - 10) / Gbl_NsLookupCount); - } + DbgPrint (ASL_DEBUG_OUTPUT, + "%32s : %u usec\n", "Time per search", ((UINT32) + (AslGbl_Events[AslGbl_NamespaceEvent].EndTime - + AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) / + Gbl_NsLookupCount); + } if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) { - printf ("\nMaximum error count (%d) exceeded\n", ASL_MAX_ERROR_COUNT); + printf ("\nMaximum error count (%u) exceeded\n", + ASL_MAX_ERROR_COUNT); } UtDisplaySummary (ASL_FILE_STDOUT); @@ -914,9 +890,15 @@ CmCleanupAndExit ( /* Delete AML file if there are errors */ - if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors)) + if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors) && + Gbl_Files[ASL_FILE_AML_OUTPUT].Handle) { - remove (Gbl_Files[ASL_FILE_AML_OUTPUT].Filename); + if (remove (Gbl_Files[ASL_FILE_AML_OUTPUT].Filename)) + { + printf ("%s: ", + Gbl_Files[ASL_FILE_AML_OUTPUT].Filename); + perror ("Could not delete AML file"); + } } /* @@ -928,8 +910,9 @@ CmCleanupAndExit ( { if (remove (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename)) { - printf ("Could not remove SRC file, %s\n", + printf ("%s: ", Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename); + perror ("Could not delete SRC file"); } } } diff --git a/compiler/aslcompiler.h b/compiler/aslcompiler.h index 804713b00d97..02adaa4764f2 100644 --- a/compiler/aslcompiler.h +++ b/compiler/aslcompiler.h @@ -222,6 +222,10 @@ void CmCleanupAndExit ( void); +ACPI_STATUS +FlCheckForAscii ( + ASL_FILE_INFO *FileInfo); + /* * aslanalyze - semantic analysis @@ -426,6 +430,16 @@ CgGenerateAmlOutput ( /* + * aslfile + */ +void +FlOpenFile ( + UINT32 FileId, + char *Filename, + char *Mode); + + +/* * asllength - calculate/adjust AML package lengths */ ACPI_STATUS @@ -1003,5 +1017,12 @@ RsDoWordBusNumberDescriptor ( ACPI_PARSE_OBJECT *Op, UINT32 CurrentByteOffset); +/* + * Entry to data table compiler subsystem + */ +ACPI_STATUS +DtDoCompile( + void); + #endif /* __ASLCOMPILER_H */ diff --git a/compiler/aslcompiler.l b/compiler/aslcompiler.l index dd0473c75717..574eb9037598 100644 --- a/compiler/aslcompiler.l +++ b/compiler/aslcompiler.l @@ -725,7 +725,7 @@ InsertLineBuffer ( * Warning if we have split a long source line. * <Probably overkill> */ - sprintf (MsgBuffer, "Max %d", ASL_LINE_BUFFER_SIZE); + sprintf (MsgBuffer, "Max %u", ASL_LINE_BUFFER_SIZE); AslCommonError (ASL_WARNING, ASL_MSG_LONG_LINE, Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, Gbl_CurrentLineOffset, Gbl_CurrentColumn, diff --git a/compiler/aslcompiler.y b/compiler/aslcompiler.y index 3c12a3dfc344..a77dc1b1b9ce 100644 --- a/compiler/aslcompiler.y +++ b/compiler/aslcompiler.y @@ -3164,7 +3164,7 @@ AslLocalAllocate (unsigned int Size) void *Mem; - DbgPrint (ASL_PARSE_OUTPUT, "\nAslLocalAllocate: Expanding Stack to %d\n\n", Size); + DbgPrint (ASL_PARSE_OUTPUT, "\nAslLocalAllocate: Expanding Stack to %u\n\n", Size); Mem = ACPI_ALLOCATE_ZEROED (Size); if (!Mem) diff --git a/compiler/asldefine.h b/compiler/asldefine.h index cff4ecf410e4..a146f77f01a1 100644 --- a/compiler/asldefine.h +++ b/compiler/asldefine.h @@ -184,6 +184,13 @@ #define FILE_SUFFIX_C_INCLUDE "h" +/* Types for input files */ + +#define ASL_INPUT_TYPE_BINARY 0 +#define ASL_INPUT_TYPE_ASCII_ASL 1 +#define ASL_INPUT_TYPE_ASCII_DATA 2 + + /* Misc */ #define ASL_EXTERNAL_METHOD 255 diff --git a/compiler/aslerror.c b/compiler/aslerror.c index f90df3807f72..4b9a04fa57cf 100644 --- a/compiler/aslerror.c +++ b/compiler/aslerror.c @@ -525,7 +525,7 @@ AslCommonError ( Gbl_ExceptionCount[Level]++; if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) { - printf ("\nMaximum error count (%d) exceeded\n", ASL_MAX_ERROR_COUNT); + printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT); Gbl_SourceLine = 0; Gbl_NextError = Gbl_ErrorLog; diff --git a/compiler/aslfiles.c b/compiler/aslfiles.c index 8f498a1b9df7..c9f87f7f1310 100644 --- a/compiler/aslfiles.c +++ b/compiler/aslfiles.c @@ -122,12 +122,6 @@ /* Local prototypes */ -static void -FlOpenFile ( - UINT32 FileId, - char *Filename, - char *Mode); - FILE * FlOpenIncludeWithPrefix ( char *PrefixDir, @@ -212,7 +206,7 @@ FlFileError ( * ******************************************************************************/ -static void +void FlOpenFile ( UINT32 FileId, char *Filename, diff --git a/compiler/aslglobal.h b/compiler/aslglobal.h index 85bb3e2d9e6b..6df7466af333 100644 --- a/compiler/aslglobal.h +++ b/compiler/aslglobal.h @@ -145,7 +145,7 @@ extern const ASL_MAPPING_ENTRY AslKeywordMapping[]; extern char *AslCompilertext; extern char HexLookup[]; -#define ASL_LINE_BUFFER_SIZE 512 +#define ASL_LINE_BUFFER_SIZE 1024 #define ASL_MSG_BUFFER_SIZE 4096 #define HEX_TABLE_LINE_SIZE 8 #define HEX_LISTING_LINE_SIZE 8 @@ -196,6 +196,8 @@ ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_ReferenceOptimizationFl ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DisplayRemarks, TRUE); ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DisplayOptimizations, FALSE); ASL_EXTERN UINT8 ASL_INIT_GLOBAL (Gbl_WarningLevel, ASL_WARNING); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_UseOriginalCompilerId, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DataTableCompilerAvailable, FALSE); #define HEX_OUTPUT_NONE 0 @@ -223,6 +225,7 @@ ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_HasIncludeFiles, FALSE) /* Statistics */ ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_InputByteCount, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_InputFieldCount, 0); ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_NsLookupCount, 0); ASL_EXTERN UINT32 ASL_INIT_GLOBAL (TotalKeywords, 0); ASL_EXTERN UINT32 ASL_INIT_GLOBAL (TotalNamedObjects, 0); @@ -247,6 +250,8 @@ ASL_EXTERN ACPI_PARSE_OBJECT ASL_INIT_GLOBAL (*Gbl_NodeCacheLast, NULL); ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_StringCacheNext, NULL); ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_StringCacheLast, NULL); ASL_EXTERN ACPI_PARSE_OBJECT *Gbl_FirstLevelInsertionNode; +ASL_EXTERN UINT8 ASL_INIT_GLOBAL (Gbl_FileType, 0); +ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_Signature, NULL); ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentHexColumn, 0); diff --git a/compiler/asllookup.c b/compiler/asllookup.c index 2c1253d2d4b6..7cc723240603 100644 --- a/compiler/asllookup.c +++ b/compiler/asllookup.c @@ -216,7 +216,7 @@ LsDoOneNamespaceObject ( Gbl_NumNamespaceObjects++; - FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5d [%d] %*s %4.4s - %s", + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u [%u] %*s %4.4s - %s", Gbl_NumNamespaceObjects, Level, (Level * 3), " ", &Node->Name, AcpiUtGetTypeName (Node->Type)); @@ -1245,7 +1245,7 @@ LkNamespaceLocateBegin ( */ if (PassedArgs != Node->Value) { - sprintf (MsgBuffer, "%s requires %d", Op->Asl.ExternalName, + sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, Node->Value); if (PassedArgs < Node->Value) diff --git a/compiler/aslmain.c b/compiler/aslmain.c index 42127c096185..406f67b2a9fa 100644 --- a/compiler/aslmain.c +++ b/compiler/aslmain.c @@ -167,7 +167,7 @@ AslDoResponseFile ( #define ASL_TOKEN_SEPARATORS " \t\n" -#define ASL_SUPPORTED_OPTIONS "@:2b:c:d^e:fgh^i^I:l^no:p:r:s:t:v:w:x:" +#define ASL_SUPPORTED_OPTIONS "@:2b:c:d^e:fgh^i^I:l^no:p:r:s:t:v:w:x:yz" /******************************************************************************* @@ -268,6 +268,8 @@ HelpMessage ( printf (" -n Parse only, no output generation\n"); printf (" -ot Display compile times\n"); printf (" -x<level> Set debug level for trace output\n"); + printf (" -y Temporary: Enable data table compiler\n"); + printf (" -z Do not insert new compiler ID for DataTables\n"); } @@ -831,6 +833,18 @@ AslDoOptions ( break; + case 'y': + + Gbl_DataTableCompilerAvailable = TRUE; + break; + + + case 'z': + + Gbl_UseOriginalCompilerId = TRUE; + break; + + default: return (-1); diff --git a/compiler/aslopt.c b/compiler/aslopt.c index 6f0b756c0f81..19bbb1237d07 100644 --- a/compiler/aslopt.c +++ b/compiler/aslopt.c @@ -339,7 +339,7 @@ OptBuildShortestPath ( } } - ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " COMMON: %d", + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " COMMON: %u", NumCommonSegments)); /* There must be at least 1 common NameSeg in order to optimize */ diff --git a/compiler/aslpredef.c b/compiler/aslpredef.c index ae1b77381480..49056edd180e 100644 --- a/compiler/aslpredef.c +++ b/compiler/aslpredef.c @@ -251,7 +251,7 @@ ApCheckForPredefinedMethod ( if (MethodInfo->NumArguments != 0) { - sprintf (MsgBuffer, "%s requires %d", Op->Asl.ExternalName, 0); + sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0); AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op, MsgBuffer); @@ -274,7 +274,7 @@ ApCheckForPredefinedMethod ( if ((MethodInfo->NumArguments != RequiredArgsCurrent) && (MethodInfo->NumArguments != RequiredArgsOld)) { - sprintf (MsgBuffer, "%4.4s requires %d", + sprintf (MsgBuffer, "%4.4s requires %u", PredefinedNames[Index].Info.Name, RequiredArgsCurrent); if (MethodInfo->NumArguments > RequiredArgsCurrent) @@ -731,7 +731,7 @@ ApDisplayReservedNames ( ThisName = PredefinedNames; while (ThisName->Info.Name[0]) { - printf ("%4.4s Requires %d arguments, ", + printf ("%4.4s Requires %u arguments, ", ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F); if (ThisName->Info.ExpectedBtypes) diff --git a/compiler/aslstartup.c b/compiler/aslstartup.c index ea61c9e392a4..2588ccbdf8dd 100644 --- a/compiler/aslstartup.c +++ b/compiler/aslstartup.c @@ -140,6 +140,10 @@ AsDoWildcard ( char *DirectoryPathname, char *FileSpecifier); +UINT8 +AslDetectSourceFileType ( + ASL_FILE_INFO *Info); + /******************************************************************************* * @@ -167,10 +171,13 @@ AslInitializeGlobals ( Gbl_CurrentLineNumber = 1; Gbl_LogicalLineNumber = 1; Gbl_CurrentLineOffset = 0; + Gbl_InputFieldCount = 0; Gbl_LineBufPtr = Gbl_CurrentLineBuffer; Gbl_ErrorLog = NULL; Gbl_NextError = NULL; + Gbl_Signature = NULL; + Gbl_FileType = 0; AslGbl_NextEvent = 0; for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++) @@ -179,6 +186,7 @@ AslInitializeGlobals ( } Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL; + Gbl_Files[ASL_FILE_AML_OUTPUT].Handle = NULL; } @@ -259,6 +267,77 @@ AsDoWildcard ( /******************************************************************************* * + * FUNCTION: AslDetectSourceFileType + * + * PARAMETERS: Info - Name/Handle for the file (must be open) + * + * RETURN: File Type + * + * DESCRIPTION: Determine the type of the input file. Either binary (contains + * non-ASCII characters), ASL file, or an ACPI Data Table file. + * + ******************************************************************************/ + +UINT8 +AslDetectSourceFileType ( + ASL_FILE_INFO *Info) +{ + char *FileChar; + UINT8 Type; + ACPI_STATUS Status; + + + /* Check for 100% ASCII source file (comments are ignored) */ + + Status = FlCheckForAscii (Info); + if (ACPI_FAILURE (Status)) + { + printf ("Non-ascii input file - %s\n", Info->Filename); + Type = ASL_INPUT_TYPE_BINARY; + goto Cleanup; + } + + /* + * File is ASCII. Determine if this is an ASL file or an ACPI data + * table file. + */ + while (fgets (Gbl_CurrentLineBuffer, ASL_LINE_BUFFER_SIZE, Info->Handle)) + { + /* Uppercase the buffer for caseless compare */ + + FileChar = Gbl_CurrentLineBuffer; + while (*FileChar) + { + *FileChar = (char) toupper ((int) *FileChar); + FileChar++; + } + + /* Presence of "DefinitionBlock" indicates actual ASL code */ + + if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK")) + { + /* Appears to be an ASL file */ + + Type = ASL_INPUT_TYPE_ASCII_ASL; + goto Cleanup; + } + } + + /* Not an ASL source file, default to a data table source file */ + + Type = ASL_INPUT_TYPE_ASCII_DATA; + +Cleanup: + + /* Must seek back to the start of the file */ + + fseek (Info->Handle, 0, SEEK_SET); + return (Type); +} + + +/******************************************************************************* + * * FUNCTION: AslDoOneFile * * PARAMETERS: Filename - Name of the file @@ -287,7 +366,7 @@ AslDoOneFile ( */ if (Gbl_DisasmFlag || Gbl_GetAllTables) { - /* ACPI CA subsystem initialization */ + /* ACPICA subsystem initialization */ Status = AdInitialize (); if (ACPI_FAILURE (Status)) @@ -330,23 +409,89 @@ AslDoOneFile ( AcpiOsPrintf ("\nCompiling \"%s\"\n", Gbl_Files[ASL_FILE_INPUT].Filename); } + else + { + Gbl_Files[ASL_FILE_INPUT].Filename = NULL; + return (AE_OK); + } } /* - * ASL Compilation (Optional) + * Open the input file. Here, this should be an ASCII source file, + * either an ASL file or a Data Table file + */ + Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename); + if (ACPI_FAILURE (Status)) + { + AePrintErrorLog (ASL_FILE_STDERR); + return (AE_ERROR); + } + + /* Determine input file type */ + + Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]); + if (Gbl_FileType == ASL_INPUT_TYPE_BINARY) + { + return (AE_ERROR); + } + + /* + * If -p not specified, we will use the input filename as the + * output filename prefix + */ + if (Gbl_UseDefaultAmlFilename) + { + Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename; + } + + /* Open the optional output files (listings, etc.) */ + + Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix); + if (ACPI_FAILURE (Status)) + { + AePrintErrorLog (ASL_FILE_STDERR); + return (AE_ERROR); + } + + /* + * Compilation of ASL source versus DataTable source uses different + * compiler subsystems */ - if (Gbl_DoCompile) + switch (Gbl_FileType) { + /* + * Data Table Compilation + */ + case ASL_INPUT_TYPE_ASCII_DATA: + /* - * If -p not specified, we will use the input filename as the - * output filename prefix + * Require use of command-line option to enable the data table + * compiler -- for now, until development of the compiler is + * complete. */ - if (Gbl_UseDefaultAmlFilename) + if (!Gbl_DataTableCompilerAvailable) + { + printf ("Data Table Compiler is not available yet\n"); + return (AE_SUPPORT); + } + + Status = DtDoCompile (); + + if (Gbl_Signature) { - Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename; + ACPI_FREE (Gbl_Signature); + Gbl_Signature = NULL; } + AeClearErrorLog (); + return (Status); + + /* + * ASL Compilation (Optional) + */ + case ASL_INPUT_TYPE_ASCII_ASL: - /* ACPI CA subsystem initialization (Must be re-initialized) */ + + /* ACPICA subsystem initialization */ Status = AdInitialize (); if (ACPI_FAILURE (Status)) @@ -367,9 +512,17 @@ AslDoOneFile ( } AeClearErrorLog (); - } + return (AE_OK); + + case ASL_INPUT_TYPE_BINARY: - return (AE_OK); + AePrintErrorLog (ASL_FILE_STDERR); + return (AE_ERROR); + + default: + printf ("Unknown file type %X\n", Gbl_FileType); + return (AE_ERROR); + } } @@ -391,7 +544,7 @@ ACPI_STATUS AslDoOnePathname ( char *Pathname) { - ACPI_STATUS Status; + ACPI_STATUS Status = AE_OK; char **FileList; char *Filename; char *FullPathname; @@ -427,11 +580,9 @@ AslDoOnePathname ( Gbl_OutputFilenamePrefix = FullPathname; } - Status = AslDoOneFile (FullPathname); - if (ACPI_FAILURE (Status)) - { - return (Status); - } + /* Save status from all compiles */ + + Status |= AslDoOneFile (FullPathname); ACPI_FREE (FullPathname); ACPI_FREE (*FileList); @@ -441,6 +592,6 @@ AslDoOnePathname ( ACPI_FREE (Gbl_DirectoryPath); ACPI_FREE (Filename); - return (AE_OK); + return (Status); } diff --git a/compiler/asltransform.c b/compiler/asltransform.c index 5327a907231c..5613c349794a 100644 --- a/compiler/asltransform.c +++ b/compiler/asltransform.c @@ -674,7 +674,7 @@ TrDoSwitch ( { /* Unknown peer opcode */ - AcpiOsPrintf ("Unknown parse opcode for switch statement: %s (%d)\n", + AcpiOsPrintf ("Unknown parse opcode for switch statement: %s (%u)\n", Next->Asl.ParseOpName, Next->Asl.ParseOpcode); } } diff --git a/compiler/asltree.c b/compiler/asltree.c index 1167f51bec71..e1af074598df 100644 --- a/compiler/asltree.c +++ b/compiler/asltree.c @@ -466,7 +466,7 @@ TrCreateLeafNode ( Op = TrAllocateNode (ParseOpcode); DbgPrint (ASL_PARSE_OUTPUT, - "\nCreateLeafNode Ln/Col %d/%d NewNode %p Op %s\n\n", + "\nCreateLeafNode Ln/Col %u/%u NewNode %p Op %s\n\n", Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode)); return Op; @@ -498,7 +498,7 @@ TrCreateValuedLeafNode ( Op = TrAllocateNode (ParseOpcode); DbgPrint (ASL_PARSE_OUTPUT, - "\nCreateValuedLeafNode Ln/Col %d/%d NewNode %p Op %s Value %8.8X%8.8X ", + "\nCreateValuedLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X ", Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode), ACPI_FORMAT_UINT64 (Value)); Op->Asl.Value.Integer = Value; @@ -575,7 +575,7 @@ TrCreateNode ( Op = TrAllocateNode (ParseOpcode); DbgPrint (ASL_PARSE_OUTPUT, - "\nCreateNode Ln/Col %d/%d NewParent %p Child %d Op %s ", + "\nCreateNode Ln/Col %u/%u NewParent %p Child %u Op %s ", Op->Asl.LineNumber, Op->Asl.Column, Op, NumChildren, UtGetOpName(ParseOpcode)); /* Some extra debug output based on the parse opcode */ @@ -694,7 +694,7 @@ TrLinkChildren ( TrSetEndLineNumber (Op); DbgPrint (ASL_PARSE_OUTPUT, - "\nLinkChildren Line [%d to %d] NewParent %p Child %d Op %s ", + "\nLinkChildren Line [%u to %u] NewParent %p Child %u Op %s ", Op->Asl.LineNumber, Op->Asl.EndLine, Op, NumChildren, UtGetOpName(Op->Asl.ParseOpcode)); @@ -882,7 +882,7 @@ TrLinkPeerNodes ( DbgPrint (ASL_PARSE_OUTPUT, - "\nLinkPeerNodes: (%d) ", NumPeers); + "\nLinkPeerNodes: (%u) ", NumPeers); va_start (ap, NumPeers); This = va_arg (ap, ACPI_PARSE_OBJECT *); @@ -893,7 +893,7 @@ TrLinkPeerNodes ( */ for (i = 0; i < (NumPeers -1); i++) { - DbgPrint (ASL_PARSE_OUTPUT, "%d=%p ", (i+1), This); + DbgPrint (ASL_PARSE_OUTPUT, "%u=%p ", (i+1), This); while (This->Asl.Next) { diff --git a/compiler/asltypes.h b/compiler/asltypes.h index 815763499d51..f4e5f4625258 100644 --- a/compiler/asltypes.h +++ b/compiler/asltypes.h @@ -279,11 +279,17 @@ typedef struct asl_listing_node /* Callback interface for a parse tree walk */ +/* + * TBD - another copy of this is in adisasm.h, fix + */ +#ifndef ASL_WALK_CALLBACK_DEFINED typedef ACPI_STATUS (*ASL_WALK_CALLBACK) ( ACPI_PARSE_OBJECT *Op, UINT32 Level, void *Context); +#define ASL_WALK_CALLBACK_DEFINED +#endif typedef struct asl_event_info @@ -429,14 +435,24 @@ typedef enum ASL_MSG_INVALID_GRANULARITY, ASL_MSG_INVALID_GRAN_FIXED, ASL_MSG_INVALID_ACCESS_SIZE, - ASL_MSG_INVALID_ADDR_FLAGS + ASL_MSG_INVALID_ADDR_FLAGS, + ASL_MSG_INVALID_FIELD_NAME, + ASL_MSG_INTEGER_SIZE, + ASL_MSG_INVALID_HEX_INTEGER, + ASL_MSG_BUFFER_ELEMENT, + ASL_MSG_RESERVED_VALUE, + ASL_MSG_FLAG_VALUE, + ASL_MSG_ZERO_VALUE, + ASL_MSG_UNKNOWN_TABLE, + ASL_MSG_UNKNOWN_SUBTABLE, + ASL_MSG_OEM_TABLE } ASL_MESSAGE_IDS; #ifdef ASL_EXCEPTIONS char *AslMessages [] = { -/* The zeroth message is resesrved */ "", +/* The zeroth message is reserved */ "", /* ASL_MSG_ALPHANUMERIC_STRING */ "String must be entirely alphanumeric", /* ASL_MSG_AML_NOT_IMPLEMENTED */ "Opcode is not implemented in compiler AML code generator", /* ASL_MSG_ARG_COUNT_HI */ "Too many arguments", @@ -558,7 +574,20 @@ char *AslMessages [] = { /* ASL_MSG_INVALID_GRANULARITY */ "Granularity must be zero or a power of two minus one", /* ASL_MSG_INVALID_GRAN_FIXED */ "Granularity must be zero for fixed Min/Max", /* ASL_MSG_INVALID_ACCESS_SIZE */ "Invalid AccessSize (Maximum is 4 - QWord access)", -/* ASL_MSG_INVALID_ADDR_FLAGS */ "Invalid combination of Length and Min/Max fixed flags" +/* ASL_MSG_INVALID_ADDR_FLAGS */ "Invalid combination of Length and Min/Max fixed flags", + +/* These messages are used by the data table compiler only */ + +/* ASL_MSG_INVALID_FIELD_NAME */ "Invalid Field Name", +/* ASL_MSG_INTEGER_SIZE */ "Integer too large for target", +/* ASL_MSG_INVALID_HEX_INTEGER */ "Invalid hex integer constant", +/* ASL_MSG_BUFFER_ELEMENT */ "Invalid element in buffer initializer list", +/* ASL_MSG_RESERVED_VALUE */ "Reserved field must be zero", +/* ASL_MSG_FLAG_VALUE */ "Flag value is too large", +/* ASL_MSG_ZERO_VALUE */ "Value must be non-zero", +/* ASL_MSG_UNKNOWN_TABLE */ "Unknown ACPI table signature", +/* ASL_MSG_UNKNOWN_SUBTABLE */ "Unknown subtable type", +/* ASL_MSG_OEM_TABLE */ "OEM table - unknown contents" }; diff --git a/compiler/aslutils.c b/compiler/aslutils.c index 01db90a3066c..e8d61babc785 100644 --- a/compiler/aslutils.c +++ b/compiler/aslutils.c @@ -214,6 +214,8 @@ UtLocalCalloc ( Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, Gbl_InputByteCount, Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename, NULL); + + CmCleanupAndExit (); exit (1); } @@ -523,33 +525,57 @@ UtDisplaySummary ( CompilerId, (UINT32) ACPI_CA_VERSION, __DATE__); } - /* Input/Output summary */ - - FlPrintFile (FileId, - "ASL Input: %s - %d lines, %d bytes, %d keywords\n", - Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber, - Gbl_InputByteCount, TotalKeywords); - - /* AML summary */ + if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) + { + FlPrintFile (FileId, + "Table Input: %s - %u lines, %u bytes, %u fields\n", + Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber, + Gbl_InputByteCount, Gbl_InputFieldCount); - if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors)) + if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors)) + { + FlPrintFile (FileId, + "Binary Output: %s - %u bytes\n\n", + Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength); + } + } + else { + /* Input/Output summary */ + FlPrintFile (FileId, - "AML Output: %s - %d bytes, %d named objects, %d executable opcodes\n\n", - Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength, - TotalNamedObjects, TotalExecutableOpcodes); + "ASL Input: %s - %u lines, %u bytes, %u keywords\n", + Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber, + Gbl_InputByteCount, TotalKeywords); + + /* AML summary */ + + if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors)) + { + FlPrintFile (FileId, + "AML Output: %s - %u bytes, %u named objects, %u executable opcodes\n\n", + Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength, + TotalNamedObjects, TotalExecutableOpcodes); + } } /* Error summary */ FlPrintFile (FileId, - "Compilation complete. %d Errors, %d Warnings, %d Remarks, %d Optimizations\n", + "Compilation complete. %u Errors, %u Warnings, %u Remarks", Gbl_ExceptionCount[ASL_ERROR], Gbl_ExceptionCount[ASL_WARNING] + Gbl_ExceptionCount[ASL_WARNING2] + Gbl_ExceptionCount[ASL_WARNING3], - Gbl_ExceptionCount[ASL_REMARK], - Gbl_ExceptionCount[ASL_OPTIMIZATION]); + Gbl_ExceptionCount[ASL_REMARK]); + + if (Gbl_FileType != ASL_INPUT_TYPE_ASCII_DATA) + { + FlPrintFile (FileId, + ", %u Optimizations", Gbl_ExceptionCount[ASL_OPTIMIZATION]); + } + + FlPrintFile (FileId, "\n"); } diff --git a/compiler/dtcompile.c b/compiler/dtcompile.c new file mode 100644 index 000000000000..351d9cc83f35 --- /dev/null +++ b/compiler/dtcompile.c @@ -0,0 +1,614 @@ +/****************************************************************************** + * + * Module Name: dtcompile.c - Front-end for data table compiler + * + *****************************************************************************/ + +/****************************************************************************** + * + * 1. Copyright Notice + * + * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. + * All rights reserved. + * + * 2. License + * + * 2.1. This is your license from Intel Corp. under its intellectual property + * rights. You may have additional license terms from the party that provided + * you this software, covering your right to use that party's intellectual + * property rights. + * + * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a + * copy of the source code appearing in this file ("Covered Code") an + * irrevocable, perpetual, worldwide license under Intel's copyrights in the + * base code distributed originally by Intel ("Original Intel Code") to copy, + * make derivatives, distribute, use and display any portion of the Covered + * Code in any form, with the right to sublicense such rights; and + * + * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent + * license (with the right to sublicense), under only those claims of Intel + * patents that are infringed by the Original Intel Code, to make, use, sell, + * offer to sell, and import the Covered Code and derivative works thereof + * solely to the minimum extent necessary to exercise the above copyright + * license, and in no event shall the patent license extend to any additions + * to or modifications of the Original Intel Code. No other license or right + * is granted directly or by implication, estoppel or otherwise; + * + * The above copyright and patent license is granted only if the following + * conditions are met: + * + * 3. Conditions + * + * 3.1. Redistribution of Source with Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification with rights to further distribute source must include + * the above Copyright Notice, the above License, this list of Conditions, + * and the following Disclaimer and Export Compliance provision. In addition, + * Licensee must cause all Covered Code to which Licensee contributes to + * contain a file documenting the changes Licensee made to create that Covered + * Code and the date of any change. Licensee must include in that file the + * documentation of any changes made by any predecessor Licensee. Licensee + * must include a prominent statement that the modification is derived, + * directly or indirectly, from Original Intel Code. + * + * 3.2. Redistribution of Source with no Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification without rights to further distribute source must + * include the following Disclaimer and Export Compliance provision in the + * documentation and/or other materials provided with distribution. In + * addition, Licensee may not authorize further sublicense of source of any + * portion of the Covered Code, and must include terms to the effect that the + * license from Licensee to its licensee is limited to the intellectual + * property embodied in the software Licensee provides to its licensee, and + * not to intellectual property embodied in modifications its licensee may + * make. + * + * 3.3. Redistribution of Executable. Redistribution in executable form of any + * substantial portion of the Covered Code or modification must reproduce the + * above Copyright Notice, and the following Disclaimer and Export Compliance + * provision in the documentation and/or other materials provided with the + * distribution. + * + * 3.4. Intel retains all right, title, and interest in and to the Original + * Intel Code. + * + * 3.5. Neither the name Intel nor any other trademark owned or controlled by + * Intel shall be used in advertising or otherwise to promote the sale, use or + * other dealings in products derived from or relating to the Covered Code + * without prior written authorization from Intel. + * + * 4. Disclaimer and Export Compliance + * + * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED + * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE + * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, + * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY + * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A + * PARTICULAR PURPOSE. + * + * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES + * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR + * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, + * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY + * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL + * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS + * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY + * LIMITED REMEDY. + * + * 4.3. Licensee shall not export, either directly or indirectly, any of this + * software or system incorporating such software without first obtaining any + * required license or other approval from the U. S. Department of Commerce or + * any other agency or department of the United States Government. In the + * event Licensee exports any such software from the United States or + * re-exports any such software from a foreign destination, Licensee shall + * ensure that the distribution and export/re-export of the software is in + * compliance with all laws, regulations, orders, or other restrictions of the + * U.S. Export Administration Regulations. Licensee agrees that neither it nor + * any of its subsidiaries will export/re-export any technical data, process, + * software, or service, directly or indirectly, to any country for which the + * United States government or any agency thereof requires an export license, + * other governmental approval, or letter of assurance, without first obtaining + * such license, approval or letter. + * + *****************************************************************************/ + +#define __DTCOMPILE_C__ +#define _DECLARE_DT_GLOBALS + +#include "aslcompiler.h" +#include "dtcompiler.h" + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtcompile") + +static char VersionString[9]; + + +/* Local prototypes */ + +static void +DtInitialize ( + void); + +static ACPI_STATUS +DtCompileDataTable ( + DT_FIELD **Field); + +static void +DtInsertCompilerIds ( + DT_FIELD *FieldList); + + +/****************************************************************************** + * + * FUNCTION: DtDoCompile + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Main entry point for the data table compiler. + * + * Note: Assumes Gbl_Files[ASL_FILE_INPUT] is initialized and the file is + * open at seek offset zero. + * + *****************************************************************************/ + +ACPI_STATUS +DtDoCompile ( + void) +{ + ACPI_STATUS Status; + UINT8 Event; + DT_FIELD *FieldList; + + + /* Initialize globals */ + + DtInitialize (); + + /* + * Scan the input file (file is already open) and + * build the parse tree + */ + Event = UtBeginEvent ("Scan and parse input file"); + FieldList = DtScanFile (Gbl_Files[ASL_FILE_INPUT].Handle); + UtEndEvent (Event); + + /* Did the parse tree get successfully constructed? */ + + if (!FieldList) + { + /* TBD: temporary error message. Msgs should come from function above */ + + DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL, + "Could not parse input file"); + return (AE_ERROR); + } + + Event = UtBeginEvent ("Compile parse tree"); + + /* + * Compile the parse tree + */ + Status = DtCompileDataTable (&FieldList); + UtEndEvent (Event); + + DtFreeFieldList (); + + if (ACPI_FAILURE (Status)) + { + /* TBD: temporary error message. Msgs should come from function above */ + + DtError (ASL_ERROR, ASL_MSG_SYNTAX, NULL, + "Could not compile input file"); + goto CleanupAndExit; + } + + /* Create/open the binary output file */ + + Gbl_Files[ASL_FILE_AML_OUTPUT].Filename = NULL; + Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix); + if (ACPI_FAILURE (Status)) + { + goto CleanupAndExit; + } + + /* Write the binary, then the optional hex file */ + + DtOutputBinary (Gbl_RootTable); + LsDoHexOutput (); + +CleanupAndExit: + + CmCleanupAndExit (); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtInitialize + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Initialize data table compiler globals. Enables multiple + * compiles per invocation. + * + *****************************************************************************/ + +static void +DtInitialize ( + void) +{ + + Gbl_FieldList = NULL; + Gbl_RootTable = NULL; + Gbl_SubtableStack = NULL; + + sprintf (VersionString, "%X", (UINT32) ACPI_CA_VERSION); +} + + +/****************************************************************************** + * + * FUNCTION: DtInsertCompilerIds + * + * PARAMETERS: FieldList - Current field list pointer + * + * RETURN: None + * + * DESCRIPTION: Insert the IDs (Name, Version) of the current compiler into + * the original ACPI table header. + * + *****************************************************************************/ + +static void +DtInsertCompilerIds ( + DT_FIELD *FieldList) +{ + DT_FIELD *Next; + UINT32 i; + + + /* + * Don't insert current compiler ID if requested. Used for compiler + * debug/validation only. + */ + if (Gbl_UseOriginalCompilerId) + { + return; + } + + /* Walk to the Compiler fields at the end of the header */ + + Next = FieldList; + for (i = 0; i < 7; i++) + { + Next = Next->Next; + } + + Next->Value = CompilerCreatorId; + Next->Flags = DT_FIELD_NOT_ALLOCATED; + + Next = Next->Next; + Next->Value = VersionString; + Next->Flags = DT_FIELD_NOT_ALLOCATED; +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileDataTable + * + * PARAMETERS: FieldList - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Entry point to compile one data table + * + *****************************************************************************/ + +static ACPI_STATUS +DtCompileDataTable ( + DT_FIELD **FieldList) +{ + ACPI_DMTABLE_DATA *TableData; + DT_SUBTABLE *Subtable; + char *Signature; + ACPI_TABLE_HEADER *AcpiTableHeader; + ACPI_STATUS Status; + + + /* Verify that we at least have a table signature and save it */ + + Signature = DtGetFieldValue (*FieldList, "Signature"); + if (!Signature) + { + DtError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, *FieldList, NULL); + return (AE_ERROR); + } + + Gbl_Signature = UtLocalCalloc (ACPI_STRLEN (Signature) + 1); + strcpy (Gbl_Signature, Signature); + + /* + * Handle tables that don't use the common ACPI table header structure. + * Currently, these are the FACS and RSDP. Also check for an OEMx table, + * these tables have user-defined contents. + */ + if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS)) + { + Status = DtCompileFacs (FieldList); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtSetTableLength (); + return (Status); + } + else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_RSDP)) + { + Status = DtCompileRsdp (FieldList); + return (Status); + } + else if (!ACPI_STRNCMP (Signature, "OEM", 3)) + { + DtFatal (ASL_MSG_OEM_TABLE, *FieldList, Signature); + return (AE_ERROR); + } + + /* + * All other tables must use the common ACPI table header. Insert the + * current iASL IDs (name, version), and compile the header now. + */ + DtInsertCompilerIds (*FieldList); + + Status = DtCompileTable (FieldList, AcpiDmTableInfoHeader, + &Gbl_RootTable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtPushSubtable (Gbl_RootTable); + + /* Match signature and dispatch appropriately */ + + TableData = AcpiDmGetTableData (Signature); + if (!TableData) + { + DtFatal (ASL_MSG_UNKNOWN_TABLE, *FieldList, Signature); + return (AE_ERROR); + } + + if (TableData->CmTableHandler) + { + /* Complex table, has a handler */ + + Status = TableData->CmTableHandler ((void **) FieldList); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + } + else if (TableData->TableInfo) + { + /* Simple table, just walk the info table */ + + Subtable = NULL; + Status = DtCompileTable (FieldList, TableData->TableInfo, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (Gbl_RootTable, Subtable); + DtPopSubtable (); + } + else + { + DtFatal (ASL_MSG_COMPILER_INTERNAL, *FieldList, + "Missing table dispatch info"); + return (AE_ERROR); + } + + /* Set the final table length and then the checksum */ + + DtSetTableLength (); + AcpiTableHeader = ACPI_CAST_PTR ( + ACPI_TABLE_HEADER, Gbl_RootTable->Buffer); + DtSetTableChecksum (&AcpiTableHeader->Checksum); + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileTable + * + * PARAMETERS: Field - Current field list pointer + * Info - Info table for this ACPI table + * RetSubtable - Compile result of table + * Required - If this subtable must exist + * + * RETURN: Status + * + * DESCRIPTION: Compile a subtable + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileTable ( + DT_FIELD **Field, + ACPI_DMTABLE_INFO *Info, + DT_SUBTABLE **RetSubtable, + BOOLEAN Required) +{ + DT_FIELD *LocalField; + UINT32 Length; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *InlineSubtable; + UINT32 FieldLength = 0; + UINT8 FieldType; + UINT8 *Buffer; + UINT8 *FlagBuffer = NULL; + UINT32 FlagBitPosition = 0; + ACPI_STATUS Status; + + + if (!Field || !*Field) + { + return (AE_BAD_PARAMETER); + } + + Length = DtGetSubtableLength (*Field, Info); + Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE)); + + Subtable->Buffer = UtLocalCalloc (Length); + Subtable->Length = Length; + Subtable->TotalLength = Length; + Buffer = Subtable->Buffer; + + LocalField = *Field; + + /* + * Main loop walks the info table for this ACPI table or subtable + */ + for (; Info->Name; Info++) + { + if (!LocalField) + { + sprintf (MsgBuffer, "Found NULL field - Field name \"%s\" needed", + Info->Name); + DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer); + Status = AE_BAD_DATA; + goto Error; + } + + /* Does input field name match what is expected? */ + + if (ACPI_STRCMP (LocalField->Name, Info->Name)) + { + /* + * If Required = TRUE, the subtable must exist. + * If Required = FALSE, the subtable is optional + * (For example, AcpiDmTableInfoDmarScope in DMAR table is + * optional) + */ + if (Required) + { + sprintf (MsgBuffer, "Expected \"%s\"", Info->Name); + DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME, + LocalField, MsgBuffer); + } + else + { + Status = AE_NOT_FOUND; + goto Error; + } + } + + FieldLength = DtGetFieldLength (LocalField, Info); + FieldType = DtGetFieldType (Info); + Gbl_InputFieldCount++; + + switch (FieldType) + { + case DT_FIELD_TYPE_FLAGS_INTEGER: + /* + * Start of the definition of a flags field. + * This master flags integer starts at value zero, in preparation + * to compile and insert the flag fields from the individual bits + */ + LocalField = LocalField->Next; + *Field = LocalField; + + FlagBitPosition = 0; + FlagBuffer = Buffer; + break; + + case DT_FIELD_TYPE_FLAG: + + /* Individual Flag field, can be multiple bits */ + + if (FlagBuffer) + { + FlagBitPosition = DtCompileFlag (FlagBuffer, + LocalField, Info, FlagBitPosition); + } + else + { + /* TBD - this is an internal error */ + } + + LocalField = LocalField->Next; + *Field = LocalField; + break; + + case DT_FIELD_TYPE_INLINE_SUBTABLE: + /* + * Recursion (one level max): compile GAS (Generic Address) + * or Notify in-line subtable + */ + LocalField = LocalField->Next; + *Field = LocalField; + + if (Info->Opcode == ACPI_DMT_GAS) + { + Status = DtCompileTable (Field, AcpiDmTableInfoGas, + &InlineSubtable, TRUE); + } + else + { + Status = DtCompileTable (Field, AcpiDmTableInfoHestNotify, + &InlineSubtable, TRUE); + } + + if (ACPI_FAILURE (Status)) + { + goto Error; + } + + ACPI_MEMCPY (Buffer, InlineSubtable->Buffer, FieldLength); + ACPI_FREE (InlineSubtable->Buffer); + ACPI_FREE (InlineSubtable); + LocalField = *Field; + break; + + default: + + /* Normal case for most field types (Integer, String, etc.) */ + + DtCompileOneField (Buffer, LocalField, + FieldLength, FieldType, Info->Flags); + LocalField = LocalField->Next; + + if (Info->Flags & DT_LENGTH) + { + /* Field is an Integer that will contain a subtable length */ + + Subtable->LengthField = Buffer; + Subtable->SizeOfLengthField = FieldLength; + } + break; + } + + Buffer += FieldLength; + } + + *Field = LocalField; + *RetSubtable = Subtable; + return (AE_OK); + +Error: + ACPI_FREE (Subtable->Buffer); + ACPI_FREE (Subtable); + return (Status); +} diff --git a/compiler/dtcompiler.h b/compiler/dtcompiler.h new file mode 100644 index 000000000000..75d641190882 --- /dev/null +++ b/compiler/dtcompiler.h @@ -0,0 +1,455 @@ +/****************************************************************************** + * + * Module Name: dtcompiler.h - header for data table compiler + * + *****************************************************************************/ + +/****************************************************************************** + * + * 1. Copyright Notice + * + * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. + * All rights reserved. + * + * 2. License + * + * 2.1. This is your license from Intel Corp. under its intellectual property + * rights. You may have additional license terms from the party that provided + * you this software, covering your right to use that party's intellectual + * property rights. + * + * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a + * copy of the source code appearing in this file ("Covered Code") an + * irrevocable, perpetual, worldwide license under Intel's copyrights in the + * base code distributed originally by Intel ("Original Intel Code") to copy, + * make derivatives, distribute, use and display any portion of the Covered + * Code in any form, with the right to sublicense such rights; and + * + * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent + * license (with the right to sublicense), under only those claims of Intel + * patents that are infringed by the Original Intel Code, to make, use, sell, + * offer to sell, and import the Covered Code and derivative works thereof + * solely to the minimum extent necessary to exercise the above copyright + * license, and in no event shall the patent license extend to any additions + * to or modifications of the Original Intel Code. No other license or right + * is granted directly or by implication, estoppel or otherwise; + * + * The above copyright and patent license is granted only if the following + * conditions are met: + * + * 3. Conditions + * + * 3.1. Redistribution of Source with Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification with rights to further distribute source must include + * the above Copyright Notice, the above License, this list of Conditions, + * and the following Disclaimer and Export Compliance provision. In addition, + * Licensee must cause all Covered Code to which Licensee contributes to + * contain a file documenting the changes Licensee made to create that Covered + * Code and the date of any change. Licensee must include in that file the + * documentation of any changes made by any predecessor Licensee. Licensee + * must include a prominent statement that the modification is derived, + * directly or indirectly, from Original Intel Code. + * + * 3.2. Redistribution of Source with no Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification without rights to further distribute source must + * include the following Disclaimer and Export Compliance provision in the + * documentation and/or other materials provided with distribution. In + * addition, Licensee may not authorize further sublicense of source of any + * portion of the Covered Code, and must include terms to the effect that the + * license from Licensee to its licensee is limited to the intellectual + * property embodied in the software Licensee provides to its licensee, and + * not to intellectual property embodied in modifications its licensee may + * make. + * + * 3.3. Redistribution of Executable. Redistribution in executable form of any + * substantial portion of the Covered Code or modification must reproduce the + * above Copyright Notice, and the following Disclaimer and Export Compliance + * provision in the documentation and/or other materials provided with the + * distribution. + * + * 3.4. Intel retains all right, title, and interest in and to the Original + * Intel Code. + * + * 3.5. Neither the name Intel nor any other trademark owned or controlled by + * Intel shall be used in advertising or otherwise to promote the sale, use or + * other dealings in products derived from or relating to the Covered Code + * without prior written authorization from Intel. + * + * 4. Disclaimer and Export Compliance + * + * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED + * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE + * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, + * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY + * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A + * PARTICULAR PURPOSE. + * + * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES + * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR + * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, + * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY + * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL + * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS + * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY + * LIMITED REMEDY. + * + * 4.3. Licensee shall not export, either directly or indirectly, any of this + * software or system incorporating such software without first obtaining any + * required license or other approval from the U. S. Department of Commerce or + * any other agency or department of the United States Government. In the + * event Licensee exports any such software from the United States or + * re-exports any such software from a foreign destination, Licensee shall + * ensure that the distribution and export/re-export of the software is in + * compliance with all laws, regulations, orders, or other restrictions of the + * U.S. Export Administration Regulations. Licensee agrees that neither it nor + * any of its subsidiaries will export/re-export any technical data, process, + * software, or service, directly or indirectly, to any country for which the + * United States government or any agency thereof requires an export license, + * other governmental approval, or letter of assurance, without first obtaining + * such license, approval or letter. + * + *****************************************************************************/ + +#define __DTCOMPILER_H__ + +#ifndef _DTCOMPILER +#define _DTCOMPILER + +#include <stdio.h> +#include "acdisasm.h" + + +#undef DT_EXTERN + +#ifdef _DECLARE_DT_GLOBALS +#define DT_EXTERN +#define DT_INIT_GLOBAL(a,b) (a)=(b) +#else +#define DT_EXTERN extern +#define DT_INIT_GLOBAL(a,b) (a) +#endif + + +/* Types for individual fields (one per input line) */ + +#define DT_FIELD_TYPE_STRING 0 +#define DT_FIELD_TYPE_INTEGER 1 +#define DT_FIELD_TYPE_BUFFER 2 +#define DT_FIELD_TYPE_PCI_PATH 3 +#define DT_FIELD_TYPE_FLAG 4 +#define DT_FIELD_TYPE_FLAGS_INTEGER 5 +#define DT_FIELD_TYPE_INLINE_SUBTABLE 6 + + +/* + * Structure used for each individual field within an ACPI table + */ +typedef struct dt_field +{ + char *Name; + char *Value; + struct dt_field *Next; + UINT32 Line; /* Line number for this field */ + UINT32 ByteOffset; /* Offset in source file for field */ + UINT32 NameColumn; /* Start column for field name */ + UINT32 Column; /* Start column for field value */ + UINT8 Flags; + +} DT_FIELD; + +/* Flags for above */ + +#define DT_FIELD_NOT_ALLOCATED 1 + + +/* + * Structure used for individual subtables within an ACPI table + */ +typedef struct dt_subtable +{ + struct dt_subtable *Parent; + struct dt_subtable *Child; + struct dt_subtable *Peer; + struct dt_subtable *StackTop; + UINT8 *Buffer; + UINT8 *LengthField; + UINT32 Length; + UINT32 TotalLength; + UINT32 SizeOfLengthField; + UINT8 Flags; + +} DT_SUBTABLE; + + +/* + * Globals + */ + +/* List of all field names and values from the input source */ + +DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*Gbl_FieldList, NULL); + +/* List of all compiled tables and subtables */ + +DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*Gbl_RootTable, NULL); + +/* Stack for subtables */ + +DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*Gbl_SubtableStack, NULL); + + +/* dtcompiler - main module */ + +ACPI_STATUS +DtCompileTable ( + DT_FIELD **Field, + ACPI_DMTABLE_INFO *Info, + DT_SUBTABLE **RetSubtable, + BOOLEAN Required); + + +/* dtio - binary and text input/output */ + +DT_FIELD * +DtScanFile ( + FILE *Handle); + +void +DtOutputBinary ( + DT_SUBTABLE *RootTable); + + +/* dtsubtable - compile subtables */ + +void +DtCreateSubtable ( + UINT8 *Buffer, + UINT32 Length, + DT_SUBTABLE **RetSubtable); + +UINT32 +DtGetSubtableLength ( + DT_FIELD *Field, + ACPI_DMTABLE_INFO *Info); + +void +DtSetSubtableLength ( + DT_SUBTABLE *Subtable); + +void +DtPushSubtable ( + DT_SUBTABLE *Subtable); + +void +DtPopSubtable ( + void); + +DT_SUBTABLE * +DtPeekSubtable ( + void); + +void +DtInsertSubtable ( + DT_SUBTABLE *ParentTable, + DT_SUBTABLE *Subtable); + +DT_SUBTABLE * +DtGetNextSubtable ( + DT_SUBTABLE *ParentTable, + DT_SUBTABLE *ChildTable); + +DT_SUBTABLE * +DtGetParentSubtable ( + DT_SUBTABLE *Subtable); + + +/* dtfield - Compile individual fields within a table */ + +void +DtCompileOneField ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength, + UINT8 Type, + UINT8 Flags); + +void +DtCompileInteger ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength, + UINT8 Flags); + +UINT32 +DtCompileBuffer ( + UINT8 *Buffer, + char *Value, + DT_FIELD *Field, + UINT32 ByteLength); + +UINT32 +DtCompileFlag ( + UINT8 *Buffer, + DT_FIELD *Field, + ACPI_DMTABLE_INFO *Info, + UINT32 BitPosition); + + +/* dtutils - Miscellaneous utilities */ + +typedef +void (*DT_WALK_CALLBACK) ( + DT_SUBTABLE *Subtable, + void *Context, + void *ReturnValue); + +void +DtWalkTableTree ( + DT_SUBTABLE *StartTable, + DT_WALK_CALLBACK UserFunction, + void *Context, + void *ReturnValue); + +void +DtError ( + UINT8 Level, + UINT8 MessageId, + DT_FIELD *FieldObject, + char *ExtraMessage); + +void +DtNameError ( + UINT8 Level, + UINT8 MessageId, + DT_FIELD *FieldObject, + char *ExtraMessage); + +void +DtFatal ( + UINT8 MessageId, + DT_FIELD *FieldObject, + char *ExtraMessage); + +ACPI_STATUS +DtStrtoul64 ( + char *String, + UINT64 *ReturnInteger); + +UINT32 +DtGetFileSize ( + FILE *Handle); + +char* +DtGetFieldValue ( + DT_FIELD *Field, + char *Name); + +UINT8 +DtGetFieldType ( + ACPI_DMTABLE_INFO *Info); + +UINT32 +DtGetBufferLength ( + char *Buffer); + +UINT32 +DtGetFieldLength ( + DT_FIELD *Field, + ACPI_DMTABLE_INFO *Info); + +void +DtSetTableChecksum ( + UINT8 *ChecksumPointer); + +void +DtSetTableLength( + void); + +void +DtFreeFieldList ( + void); + + +/* dttable - individual table compilation */ + +ACPI_STATUS +DtCompileFacs ( + DT_FIELD **PFieldList); + +ACPI_STATUS +DtCompileRsdp ( + DT_FIELD **PFieldList); + +ACPI_STATUS +DtCompileAsf ( + void **PFieldList); + +ACPI_STATUS +DtCompileCpep ( + void **PFieldList); + +ACPI_STATUS +DtCompileDmar ( + void **PFieldList); + +ACPI_STATUS +DtCompileEinj ( + void **PFieldList); + +ACPI_STATUS +DtCompileErst ( + void **PFieldList); + +ACPI_STATUS +DtCompileFadt ( + void **PFieldList); + +ACPI_STATUS +DtCompileHest ( + void **PFieldList); + +ACPI_STATUS +DtCompileIvrs ( + void **PFieldList); + +ACPI_STATUS +DtCompileMadt ( + void **PFieldList); + +ACPI_STATUS +DtCompileMcfg ( + void **PFieldList); + +ACPI_STATUS +DtCompileMsct ( + void **PFieldList); + +ACPI_STATUS +DtCompileRsdt ( + void **PFieldList); + +ACPI_STATUS +DtCompileSlit ( + void **PFieldList); + +ACPI_STATUS +DtCompileSrat ( + void **PFieldList); + +ACPI_STATUS +DtCompileWdat ( + void **PFieldList); + +ACPI_STATUS +DtCompileXsdt ( + void **PFieldList); + + +/* Debug */ + +#define MYDEBUG printf + +#endif diff --git a/compiler/dtfield.c b/compiler/dtfield.c new file mode 100644 index 000000000000..d3f32a44152d --- /dev/null +++ b/compiler/dtfield.c @@ -0,0 +1,543 @@ +/****************************************************************************** + * + * Module Name: dtfield.c - Code generation for individual source fields + * + *****************************************************************************/ + +/****************************************************************************** + * + * 1. Copyright Notice + * + * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. + * All rights reserved. + * + * 2. License + * + * 2.1. This is your license from Intel Corp. under its intellectual property + * rights. You may have additional license terms from the party that provided + * you this software, covering your right to use that party's intellectual + * property rights. + * + * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a + * copy of the source code appearing in this file ("Covered Code") an + * irrevocable, perpetual, worldwide license under Intel's copyrights in the + * base code distributed originally by Intel ("Original Intel Code") to copy, + * make derivatives, distribute, use and display any portion of the Covered + * Code in any form, with the right to sublicense such rights; and + * + * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent + * license (with the right to sublicense), under only those claims of Intel + * patents that are infringed by the Original Intel Code, to make, use, sell, + * offer to sell, and import the Covered Code and derivative works thereof + * solely to the minimum extent necessary to exercise the above copyright + * license, and in no event shall the patent license extend to any additions + * to or modifications of the Original Intel Code. No other license or right + * is granted directly or by implication, estoppel or otherwise; + * + * The above copyright and patent license is granted only if the following + * conditions are met: + * + * 3. Conditions + * + * 3.1. Redistribution of Source with Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification with rights to further distribute source must include + * the above Copyright Notice, the above License, this list of Conditions, + * and the following Disclaimer and Export Compliance provision. In addition, + * Licensee must cause all Covered Code to which Licensee contributes to + * contain a file documenting the changes Licensee made to create that Covered + * Code and the date of any change. Licensee must include in that file the + * documentation of any changes made by any predecessor Licensee. Licensee + * must include a prominent statement that the modification is derived, + * directly or indirectly, from Original Intel Code. + * + * 3.2. Redistribution of Source with no Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification without rights to further distribute source must + * include the following Disclaimer and Export Compliance provision in the + * documentation and/or other materials provided with distribution. In + * addition, Licensee may not authorize further sublicense of source of any + * portion of the Covered Code, and must include terms to the effect that the + * license from Licensee to its licensee is limited to the intellectual + * property embodied in the software Licensee provides to its licensee, and + * not to intellectual property embodied in modifications its licensee may + * make. + * + * 3.3. Redistribution of Executable. Redistribution in executable form of any + * substantial portion of the Covered Code or modification must reproduce the + * above Copyright Notice, and the following Disclaimer and Export Compliance + * provision in the documentation and/or other materials provided with the + * distribution. + * + * 3.4. Intel retains all right, title, and interest in and to the Original + * Intel Code. + * + * 3.5. Neither the name Intel nor any other trademark owned or controlled by + * Intel shall be used in advertising or otherwise to promote the sale, use or + * other dealings in products derived from or relating to the Covered Code + * without prior written authorization from Intel. + * + * 4. Disclaimer and Export Compliance + * + * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED + * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE + * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, + * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY + * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A + * PARTICULAR PURPOSE. + * + * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES + * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR + * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, + * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY + * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL + * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS + * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY + * LIMITED REMEDY. + * + * 4.3. Licensee shall not export, either directly or indirectly, any of this + * software or system incorporating such software without first obtaining any + * required license or other approval from the U. S. Department of Commerce or + * any other agency or department of the United States Government. In the + * event Licensee exports any such software from the United States or + * re-exports any such software from a foreign destination, Licensee shall + * ensure that the distribution and export/re-export of the software is in + * compliance with all laws, regulations, orders, or other restrictions of the + * U.S. Export Administration Regulations. Licensee agrees that neither it nor + * any of its subsidiaries will export/re-export any technical data, process, + * software, or service, directly or indirectly, to any country for which the + * United States government or any agency thereof requires an export license, + * other governmental approval, or letter of assurance, without first obtaining + * such license, approval or letter. + * + *****************************************************************************/ + +#define __DTFIELD_C__ + +#include "aslcompiler.h" +#include "dtcompiler.h" + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtfield") + + +/* Local prototypes */ + +static void +DtCompileString ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength); + +static char * +DtPciPathToBuffer ( + char *PciPath); + +static void +DtCompilePciPath ( + UINT8 *Buffer, + char *StringValue, + DT_FIELD *Field, + UINT32 ByteLength); + + +/****************************************************************************** + * + * FUNCTION: DtCompileOneField + * + * PARAMETERS: Buffer - Output buffer + * Field - Field to be compiled + * ByteLength - Byte length of the field + * Type - Field type + * + * RETURN: None + * + * DESCRIPTION: Compile a field value to binary + * + *****************************************************************************/ + +void +DtCompileOneField ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength, + UINT8 Type, + UINT8 Flags) +{ + + switch (Type) + { + case DT_FIELD_TYPE_INTEGER: + DtCompileInteger (Buffer, Field, ByteLength, Flags); + break; + + case DT_FIELD_TYPE_STRING: + DtCompileString (Buffer, Field, ByteLength); + break; + + case DT_FIELD_TYPE_BUFFER: + DtCompileBuffer (Buffer, Field->Value, Field, ByteLength); + break; + + case DT_FIELD_TYPE_PCI_PATH: + DtCompilePciPath (Buffer, Field->Value, Field, ByteLength); + break; + + default: + DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid field type"); + break; + } +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileString + * + * PARAMETERS: Buffer - Output buffer + * Field - String to be copied to buffer + * ByteLength - Maximum length of string + * + * RETURN: None + * + * DESCRIPTION: Copy string to the buffer + * + *****************************************************************************/ + +static void +DtCompileString ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength) +{ + UINT32 Length; + + + Length = ACPI_STRLEN (Field->Value); + + /* Check if the string is too long for the field */ + + if (Length > ByteLength) + { + sprintf (MsgBuffer, "Maximum %u characters", ByteLength); + DtError (ASL_ERROR, ASL_MSG_STRING_LENGTH, Field, MsgBuffer); + Length = ByteLength; + } + + /* If input string is shorter than ByteLength, pad with blanks */ + + ACPI_MEMSET (Buffer, 0x20, ByteLength); + ACPI_MEMCPY (Buffer, Field->Value, Length); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileInteger + * + * PARAMETERS: Buffer - Output buffer + * Field - Field obj with Integer to be compiled + * ByteLength - Byte length of the integer + * + * RETURN: None + * + * DESCRIPTION: Compile an integer + * + *****************************************************************************/ + +void +DtCompileInteger ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength, + UINT8 Flags) +{ + UINT64 Value = 0; + UINT64 MaxValue; + UINT8 *Hex; + char *Message = NULL; + ACPI_STATUS Status; + int i; + + + /* Byte length must be in range 1-8 */ + + if ((ByteLength > 8) || (ByteLength == 0)) + { + DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, + "Invalid internal Byte length"); + return; + } + + /* Convert string to an actual integer */ + + Status = DtStrtoul64 (Field->Value, &Value); + if (ACPI_FAILURE (Status)) + { + if (Status == AE_LIMIT) + { + Message = "Constant larger than 64 bits"; + } + else if (Status == AE_BAD_CHARACTER) + { + Message = "Invalid character in constant"; + } + + DtError (ASL_ERROR, ASL_MSG_INVALID_HEX_INTEGER, Field, Message); + goto Exit; + } + + /* Ensure that reserved fields are set to zero */ + /* TBD: should we set to zero, or just make this an ERROR? */ + /* TBD: Probably better to use a flag */ + + if (!ACPI_STRCMP (Field->Name, "Reserved") && + (Value != 0)) + { + DtError (ASL_WARNING, ASL_MSG_RESERVED_VALUE, Field, + "Setting to zero"); + Value = 0; + } + + /* Check if the value must be non-zero */ + + if ((Value == 0) && (Flags & DT_NON_ZERO)) + { + DtError (ASL_ERROR, ASL_MSG_ZERO_VALUE, Field, NULL); + } + + /* + * Generate the maximum value for the data type (ByteLength) + * Note: construct chosen for maximum portability + */ + MaxValue = ((UINT64) (-1)) >> (64 - (ByteLength * 8)); + + /* Validate that the input value is within range of the target */ + + if (Value > MaxValue) + { + sprintf (MsgBuffer, "Maximum %u bytes", ByteLength); + DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, MsgBuffer); + } + + /* + * TBD: hard code for ASF! Capabilites field. + * + * This field is actually a buffer, not a 56-bit integer -- + * so, the ordering is reversed. Something should be fixed + * so we don't need this code. + */ + if (ByteLength == 7) + { + Hex = ACPI_CAST_PTR (UINT8, &Value); + for (i = 6; i >= 0; i--) + { + Buffer[i] = *Hex; + Hex++; + } + return; + } + +Exit: + ACPI_MEMCPY (Buffer, &Value, ByteLength); + return; +} + + +/****************************************************************************** + * + * FUNCTION: DtPciPathToBuffer + * + * PARAMETERS: PciPath - DMAR "PCI Path" field + * + * RETURN: Strings of PCI path + * + * DESCRIPTION: Remove brackets and comma from DMAR "PCI Path" string, for + * example: [1D, 01] ==> 1D 01 + * + *****************************************************************************/ + +static char * +DtPciPathToBuffer ( + char *PciPath) +{ + char *Buffer; + + + Buffer = UtLocalCalloc (6); + + Buffer[0] = PciPath[1]; + Buffer[1] = PciPath[2]; + Buffer[2] = ' '; + Buffer[3] = PciPath[5]; + Buffer[4] = PciPath[6]; + + return (Buffer); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileBuffer + * + * PARAMETERS: Buffer - Output buffer + * StringValue - Integer list to be compiled + * Field - Current field object + * ByteLength - Byte length of the integer list + * + * RETURN: Count of remaining data in the input list + * + * DESCRIPTION: Compile and pack an integer list, for example + * "AA 1F 20 3B" ==> Buffer[] = {0xAA,0x1F,0x20,0x3B} + * + *****************************************************************************/ + +UINT32 +DtCompileBuffer ( + UINT8 *Buffer, + char *StringValue, + DT_FIELD *Field, + UINT32 ByteLength) +{ + ACPI_STATUS Status; + char Hex[3]; + UINT64 Value; + UINT32 i; + UINT32 Count; + + + Count = ACPI_STRLEN (StringValue) / 3 + 1; + + Hex[2] = 0; + for (i = 0; i < Count; i++) + { + Hex[0] = StringValue[0]; + Hex[1] = StringValue[1]; + + /* Convert one hex byte */ + + Value = 0; + Status = DtStrtoul64 (Hex, &Value); + if (ACPI_FAILURE (Status)) + { + DtError (ASL_ERROR, ASL_MSG_BUFFER_ELEMENT, Field, MsgBuffer); + return (ByteLength - Count); + } + + Buffer[i] = (UINT8) Value; + StringValue += 3; + } + + return (ByteLength - Count); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompilePciPath + * + * PARAMETERS: Buffer - Output buffer + * StringValue - DMAR pci path string + * ByteLength - Byte length of DMAR pci path string, 2 + * + * RETURN: None + * + * DESCRIPTION: Compile DMAR PCI path string to binary + * + *****************************************************************************/ + +static void +DtCompilePciPath ( + UINT8 *Buffer, + char *StringValue, + DT_FIELD *Field, + UINT32 ByteLength) +{ + char *PciPathBuffer; + + + /* Parse path to simple hex digits, then convert to binary */ + + PciPathBuffer = DtPciPathToBuffer (StringValue); + + DtCompileBuffer (Buffer, PciPathBuffer, Field, ByteLength); + ACPI_FREE (PciPathBuffer); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileFlag + * + * PARAMETERS: Buffer - Output buffer + * Field - Field to be compiled + * Info - Flag info + * BitPosition - Flag bit position + * + * RETURN: Next flag bit position + * + * DESCRIPTION: Compile a flag + * + *****************************************************************************/ + +UINT32 +DtCompileFlag ( + UINT8 *Buffer, + DT_FIELD *Field, + ACPI_DMTABLE_INFO *Info, + UINT32 BitPosition) +{ + UINT64 Value = 0; + UINT32 BitLength = 1; + ACPI_STATUS Status; + + + Status = DtStrtoul64 (Field->Value, &Value); + if (ACPI_FAILURE (Status)) + { + DtError (ASL_ERROR, ASL_MSG_INVALID_HEX_INTEGER, Field, NULL); + } + + switch (Info->Opcode) + { + case ACPI_DMT_FLAG0: + case ACPI_DMT_FLAG1: + case ACPI_DMT_FLAG2: + case ACPI_DMT_FLAG3: + case ACPI_DMT_FLAG4: + case ACPI_DMT_FLAG5: + case ACPI_DMT_FLAG6: + case ACPI_DMT_FLAG7: + + BitLength = 1; + break; + + case ACPI_DMT_FLAGS0: + case ACPI_DMT_FLAGS2: + + BitLength = 2; + break; + + default: + + DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid flag opcode"); + break; + } + + /* Check range of the input flag value */ + + if (Value >= ((UINT64) 1 << BitLength)) + { + sprintf (MsgBuffer, "Maximum %u bit", BitLength); + DtError (ASL_ERROR, ASL_MSG_FLAG_VALUE, Field, MsgBuffer); + Value = 0; + } + + /* Insert the flag, return next flag bit position */ + + Buffer += ACPI_DIV_8 (BitPosition); + *Buffer |= (UINT8) (Value << ACPI_MOD_8 (BitPosition)); + + return (BitPosition + BitLength); +} diff --git a/compiler/dtio.c b/compiler/dtio.c new file mode 100644 index 000000000000..469cea60917d --- /dev/null +++ b/compiler/dtio.c @@ -0,0 +1,512 @@ +/****************************************************************************** + * + * Module Name: dtio.c - File I/O support for data table compiler + * + *****************************************************************************/ + +/****************************************************************************** + * + * 1. Copyright Notice + * + * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. + * All rights reserved. + * + * 2. License + * + * 2.1. This is your license from Intel Corp. under its intellectual property + * rights. You may have additional license terms from the party that provided + * you this software, covering your right to use that party's intellectual + * property rights. + * + * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a + * copy of the source code appearing in this file ("Covered Code") an + * irrevocable, perpetual, worldwide license under Intel's copyrights in the + * base code distributed originally by Intel ("Original Intel Code") to copy, + * make derivatives, distribute, use and display any portion of the Covered + * Code in any form, with the right to sublicense such rights; and + * + * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent + * license (with the right to sublicense), under only those claims of Intel + * patents that are infringed by the Original Intel Code, to make, use, sell, + * offer to sell, and import the Covered Code and derivative works thereof + * solely to the minimum extent necessary to exercise the above copyright + * license, and in no event shall the patent license extend to any additions + * to or modifications of the Original Intel Code. No other license or right + * is granted directly or by implication, estoppel or otherwise; + * + * The above copyright and patent license is granted only if the following + * conditions are met: + * + * 3. Conditions + * + * 3.1. Redistribution of Source with Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification with rights to further distribute source must include + * the above Copyright Notice, the above License, this list of Conditions, + * and the following Disclaimer and Export Compliance provision. In addition, + * Licensee must cause all Covered Code to which Licensee contributes to + * contain a file documenting the changes Licensee made to create that Covered + * Code and the date of any change. Licensee must include in that file the + * documentation of any changes made by any predecessor Licensee. Licensee + * must include a prominent statement that the modification is derived, + * directly or indirectly, from Original Intel Code. + * + * 3.2. Redistribution of Source with no Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification without rights to further distribute source must + * include the following Disclaimer and Export Compliance provision in the + * documentation and/or other materials provided with distribution. In + * addition, Licensee may not authorize further sublicense of source of any + * portion of the Covered Code, and must include terms to the effect that the + * license from Licensee to its licensee is limited to the intellectual + * property embodied in the software Licensee provides to its licensee, and + * not to intellectual property embodied in modifications its licensee may + * make. + * + * 3.3. Redistribution of Executable. Redistribution in executable form of any + * substantial portion of the Covered Code or modification must reproduce the + * above Copyright Notice, and the following Disclaimer and Export Compliance + * provision in the documentation and/or other materials provided with the + * distribution. + * + * 3.4. Intel retains all right, title, and interest in and to the Original + * Intel Code. + * + * 3.5. Neither the name Intel nor any other trademark owned or controlled by + * Intel shall be used in advertising or otherwise to promote the sale, use or + * other dealings in products derived from or relating to the Covered Code + * without prior written authorization from Intel. + * + * 4. Disclaimer and Export Compliance + * + * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED + * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE + * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, + * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY + * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A + * PARTICULAR PURPOSE. + * + * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES + * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR + * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, + * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY + * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL + * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS + * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY + * LIMITED REMEDY. + * + * 4.3. Licensee shall not export, either directly or indirectly, any of this + * software or system incorporating such software without first obtaining any + * required license or other approval from the U. S. Department of Commerce or + * any other agency or department of the United States Government. In the + * event Licensee exports any such software from the United States or + * re-exports any such software from a foreign destination, Licensee shall + * ensure that the distribution and export/re-export of the software is in + * compliance with all laws, regulations, orders, or other restrictions of the + * U.S. Export Administration Regulations. Licensee agrees that neither it nor + * any of its subsidiaries will export/re-export any technical data, process, + * software, or service, directly or indirectly, to any country for which the + * United States government or any agency thereof requires an export license, + * other governmental approval, or letter of assurance, without first obtaining + * such license, approval or letter. + * + *****************************************************************************/ + +#define __DTIO_C__ + +#include "aslcompiler.h" +#include "dtcompiler.h" + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtio") + + +/****************************************************************************** + * + * FUNCTION: DtIsComment + * + * PARAMETERS: Line - Current source code line + * + * RETURN: TRUE if comment, FALSE otherwise + * + * DESCRIPTION: Detect a comment in the source module + * + *****************************************************************************/ + +/* TBD: Temporary: very simple code to detect comments */ + +static int +DtIsComment( + char *Line) +{ + + if (!ACPI_STRNCMP (Line, "/*", 2) || + !ACPI_STRNCMP (Line, " *", 2)) + { + return 1; + } + + return 0; +} + + +/****************************************************************************** + * + * FUNCTION: DtTrim + * + * PARAMETERS: String - Current source code line to trim + * + * RETURN: Trimmed line. Must be freed by caller. + * + * DESCRIPTION: Trim left and right spaces + * + *****************************************************************************/ + +static char * +DtTrim ( + char *String) +{ + char *Start; + char *End; + char *ReturnString; + ACPI_SIZE Length; + + + /* Skip lines that start with a space */ + + if (!ACPI_STRCMP (String, " ")) + { + ReturnString = UtLocalCalloc (1); + return (ReturnString); + } + + /* Setup pointers to start and end of input string */ + + Start = String; + End = String + ACPI_STRLEN (String) - 1; + + /* Find first non-whitespace character */ + + while ((Start <= End) && ((*Start == ' ') || (*Start == '\t'))) + { + Start++; + } + + /* Find last non-space character */ + + while (End >= Start) + { + if (*End == '\r' || *End == '\n') + { + End--; + continue; + } + + if (*End != ' ') + { + break; + } + + End--; + } + + /* Remove any quotes around the string */ + + if (*Start == '\"') + { + Start++; + } + if (*End == '\"') + { + End--; + } + + /* Create the trimmed return string */ + + Length = ACPI_PTR_DIFF (End, Start) + 1; + ReturnString = UtLocalCalloc (Length + 1); + if (ACPI_STRLEN (Start)) + { + ACPI_STRNCPY (ReturnString, Start, Length); + } + + ReturnString[Length] = 0; + return (ReturnString); +} + + +/****************************************************************************** + * + * FUNCTION: DtLinkField + * + * PARAMETERS: Field - New field object to link + * + * RETURN: None + * + * DESCRIPTION: Link one field name and value to the list + * + *****************************************************************************/ + +static void +DtLinkField ( + DT_FIELD *Field) +{ + DT_FIELD *Prev; + DT_FIELD *Next; + + + Prev = Next = Gbl_FieldList; + + while (Next) + { + Prev = Next; + Next = Next->Next; + } + + if (Prev) + { + Prev->Next = Field; + } + else + { + Gbl_FieldList = Field; + } +} + + +/****************************************************************************** + * + * FUNCTION: DtParseLine + * + * PARAMETERS: LineBuffer - Current source code line + * Line - Current line number in the source + * Offset - Current byte offset of the line + * + * RETURN: None + * + * DESCRIPTION: Parse one source line + * + *****************************************************************************/ + +static void +DtParseLine ( + char *LineBuffer, + UINT32 Line, + UINT32 Offset) +{ + char *Start; + char *End; + char *TmpName; + char *TmpValue; + char *Name; + char *Value; + char *Colon; + UINT32 Length; + DT_FIELD *Field; + UINT32 Column; + UINT32 NameColumn; + + + if (!LineBuffer || DtIsComment (LineBuffer)) + { + return; + } + + Colon = strchr (LineBuffer, ':'); + if (!Colon || *(Colon - 1) != ' ') + { + return; + } + + Start = LineBuffer; + End = Colon; + + while (Start < Colon) + { + if (*Start == ' ') + { + Start++; + continue; + } + + /* Found left bracket, go to the right bracket */ + + if (*Start == '[') + { + while (Start < Colon && *Start != ']') + { + Start++; + } + + if (Start == Colon) + { + MYDEBUG ("ERROR: right bracket reaches colon position\n"); + break; + } + + Start++; + continue; + } + + break; + } + + /* + * There are two column values. One for the field name, + * and one for the field value. + */ + Column = ACPI_PTR_DIFF (Colon, LineBuffer) + 3; + NameColumn = ACPI_PTR_DIFF (Start, LineBuffer) + 1; + + Length = ACPI_PTR_DIFF (End, Start); + + TmpName = UtLocalCalloc (Length + 1); + ACPI_STRNCPY (TmpName, Start, Length); + Name = DtTrim (TmpName); + ACPI_FREE (TmpName); + + Start = End = (Colon + 1); + + while (*End) + { + /* Found left quotation, go to the right quotation and break */ + + if (*End == '"') + { + End++; + while (*End && *End != '"') + { + End++; + } + + End++; + break; + } + + if (*End == '(' || + *End == '<' || + *End == '/') + { + break; + } + + End++; + } + + Length = ACPI_PTR_DIFF (End, Start); + TmpValue = UtLocalCalloc (Length + 1); + ACPI_STRNCPY (TmpValue, Start, Length); + Value = DtTrim (TmpValue); + ACPI_FREE (TmpValue); + + if (Name && Value) + { + Field = UtLocalCalloc (sizeof (DT_FIELD)); + Field->Name = Name; + Field->Value = Value; + Field->Line = Line; + Field->ByteOffset = Offset; + Field->NameColumn = NameColumn; + Field->Column = Column; + + DtLinkField (Field); + } +} + + +/****************************************************************************** + * + * FUNCTION: DtScanFile + * + * PARAMETERS: Handle - Open file handle for the source file + * + * RETURN: Pointer to start of the constructed parse tree. + * + * DESCRIPTION: Scan source file, link all field name and value + * to the global parse tree: Gbl_FieldList + * + *****************************************************************************/ + +DT_FIELD * +DtScanFile ( + FILE *Handle) +{ + UINT32 Line = 0; + UINT32 Offset = 0; + + + /* Get the file size */ + + Gbl_InputByteCount = DtGetFileSize (Handle); + + /* Scan line-by-line */ + + while (fgets (Gbl_CurrentLineBuffer, ASL_LINE_BUFFER_SIZE, Handle)) + { + Line++; + Gbl_CurrentLineNumber++; + DtParseLine (Gbl_CurrentLineBuffer, Line, Offset); + + Offset = (UINT32) ftell (Handle); + } + + return (Gbl_FieldList); +} + + +/* + * Output functions + */ + + +/****************************************************************************** + * + * FUNCTION: DtWriteBinary + * + * PARAMETERS: DT_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Write one subtable of a binary ACPI table + * + *****************************************************************************/ + +static void +DtWriteBinary ( + DT_SUBTABLE *Subtable, + void *Context, + void *ReturnValue) +{ + + FlWriteFile (ASL_FILE_AML_OUTPUT, Subtable->Buffer, Subtable->Length); +} + + +/****************************************************************************** + * + * FUNCTION: DtOutputBinary + * + * PARAMETERS: + * + * RETURN: Status + * + * DESCRIPTION: Write entire binary ACPI table (result of compilation) + * + *****************************************************************************/ + +void +DtOutputBinary ( + DT_SUBTABLE *RootTable) +{ + + if (!RootTable) + { + return; + } + + /* Walk the entire parse tree, emitting the binary data */ + + DtWalkTableTree (RootTable, DtWriteBinary, NULL, NULL); + Gbl_TableLength = DtGetFileSize (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle); +} diff --git a/compiler/dtsubtable.c b/compiler/dtsubtable.c new file mode 100644 index 000000000000..9bbb4b463c19 --- /dev/null +++ b/compiler/dtsubtable.c @@ -0,0 +1,400 @@ +/****************************************************************************** + * + * Module Name: dtsubtable.c - handling of subtables within ACPI tables + * + *****************************************************************************/ + +/****************************************************************************** + * + * 1. Copyright Notice + * + * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. + * All rights reserved. + * + * 2. License + * + * 2.1. This is your license from Intel Corp. under its intellectual property + * rights. You may have additional license terms from the party that provided + * you this software, covering your right to use that party's intellectual + * property rights. + * + * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a + * copy of the source code appearing in this file ("Covered Code") an + * irrevocable, perpetual, worldwide license under Intel's copyrights in the + * base code distributed originally by Intel ("Original Intel Code") to copy, + * make derivatives, distribute, use and display any portion of the Covered + * Code in any form, with the right to sublicense such rights; and + * + * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent + * license (with the right to sublicense), under only those claims of Intel + * patents that are infringed by the Original Intel Code, to make, use, sell, + * offer to sell, and import the Covered Code and derivative works thereof + * solely to the minimum extent necessary to exercise the above copyright + * license, and in no event shall the patent license extend to any additions + * to or modifications of the Original Intel Code. No other license or right + * is granted directly or by implication, estoppel or otherwise; + * + * The above copyright and patent license is granted only if the following + * conditions are met: + * + * 3. Conditions + * + * 3.1. Redistribution of Source with Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification with rights to further distribute source must include + * the above Copyright Notice, the above License, this list of Conditions, + * and the following Disclaimer and Export Compliance provision. In addition, + * Licensee must cause all Covered Code to which Licensee contributes to + * contain a file documenting the changes Licensee made to create that Covered + * Code and the date of any change. Licensee must include in that file the + * documentation of any changes made by any predecessor Licensee. Licensee + * must include a prominent statement that the modification is derived, + * directly or indirectly, from Original Intel Code. + * + * 3.2. Redistribution of Source with no Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification without rights to further distribute source must + * include the following Disclaimer and Export Compliance provision in the + * documentation and/or other materials provided with distribution. In + * addition, Licensee may not authorize further sublicense of source of any + * portion of the Covered Code, and must include terms to the effect that the + * license from Licensee to its licensee is limited to the intellectual + * property embodied in the software Licensee provides to its licensee, and + * not to intellectual property embodied in modifications its licensee may + * make. + * + * 3.3. Redistribution of Executable. Redistribution in executable form of any + * substantial portion of the Covered Code or modification must reproduce the + * above Copyright Notice, and the following Disclaimer and Export Compliance + * provision in the documentation and/or other materials provided with the + * distribution. + * + * 3.4. Intel retains all right, title, and interest in and to the Original + * Intel Code. + * + * 3.5. Neither the name Intel nor any other trademark owned or controlled by + * Intel shall be used in advertising or otherwise to promote the sale, use or + * other dealings in products derived from or relating to the Covered Code + * without prior written authorization from Intel. + * + * 4. Disclaimer and Export Compliance + * + * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED + * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE + * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, + * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY + * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A + * PARTICULAR PURPOSE. + * + * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES + * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR + * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, + * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY + * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL + * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS + * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY + * LIMITED REMEDY. + * + * 4.3. Licensee shall not export, either directly or indirectly, any of this + * software or system incorporating such software without first obtaining any + * required license or other approval from the U. S. Department of Commerce or + * any other agency or department of the United States Government. In the + * event Licensee exports any such software from the United States or + * re-exports any such software from a foreign destination, Licensee shall + * ensure that the distribution and export/re-export of the software is in + * compliance with all laws, regulations, orders, or other restrictions of the + * U.S. Export Administration Regulations. Licensee agrees that neither it nor + * any of its subsidiaries will export/re-export any technical data, process, + * software, or service, directly or indirectly, to any country for which the + * United States government or any agency thereof requires an export license, + * other governmental approval, or letter of assurance, without first obtaining + * such license, approval or letter. + * + *****************************************************************************/ + +#define __DTSUBTABLE_C__ + +#include "aslcompiler.h" +#include "dtcompiler.h" + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtsubtable") + + +/****************************************************************************** + * + * FUNCTION: DtCreateSubtable + * + * PARAMETERS: Buffer - Input buffer + * Length - Buffer length + * RetSubtable - Returned newly created subtable + * + * RETURN: None + * + * DESCRIPTION: Create a subtable that is not listed with ACPI_DMTABLE_INFO + * For example, FACS has 24 bytes reserved at the end + * and it's not listed at AcpiDmTableInfoFacs + * + *****************************************************************************/ + +void +DtCreateSubtable ( + UINT8 *Buffer, + UINT32 Length, + DT_SUBTABLE **RetSubtable) +{ + DT_SUBTABLE *Subtable; + + + Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE)); + + /* Create a new buffer for the subtable data */ + + Subtable->Buffer = UtLocalCalloc (Length); + ACPI_MEMCPY (Subtable->Buffer, Buffer, Length); + + Subtable->Length = Length; + Subtable->TotalLength = Length; + + *RetSubtable = Subtable; +} + + +/****************************************************************************** + * + * FUNCTION: DtInsertSubtable + * + * PARAMETERS: ParentTable - The Parent of the new subtable + * Subtable - The new subtable to insert + * + * RETURN: None + * + * DESCRIPTION: Insert the new subtable to the parent table + * + *****************************************************************************/ + +void +DtInsertSubtable ( + DT_SUBTABLE *ParentTable, + DT_SUBTABLE *Subtable) +{ + DT_SUBTABLE *ChildTable; + + + Subtable->Peer = NULL; + Subtable->Parent = ParentTable; + + /* Link the new entry into the child list */ + + if (!ParentTable->Child) + { + ParentTable->Child = Subtable; + } + else + { + /* Walk to the end of the child list */ + + ChildTable = ParentTable->Child; + while (ChildTable->Peer) + { + ChildTable = ChildTable->Peer; + } + + /* Add new subtable at the end of the child list */ + + ChildTable->Peer = Subtable; + } +} + + +/****************************************************************************** + * + * FUNCTION: DtPushSubtable + * + * PARAMETERS: Subtable - Subtable to push + * + * RETURN: None + * + * DESCRIPTION: Push a subtable onto a subtable stack + * + *****************************************************************************/ + +void +DtPushSubtable ( + DT_SUBTABLE *Subtable) +{ + + Subtable->StackTop = Gbl_SubtableStack; + Gbl_SubtableStack = Subtable; +} + + +/****************************************************************************** + * + * FUNCTION: DtPopSubtable + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Pop a subtable from a subtable stack. Uses global SubtableStack + * + *****************************************************************************/ + +void +DtPopSubtable ( + void) +{ + DT_SUBTABLE *Subtable; + + + Subtable = Gbl_SubtableStack; + + if (Subtable) + { + Gbl_SubtableStack = Subtable->StackTop; + } +} + + +/****************************************************************************** + * + * FUNCTION: DtPeekSubtable + * + * PARAMETERS: None + * + * RETURN: The subtable on top of stack + * + * DESCRIPTION: Get the subtable on top of stack + * + *****************************************************************************/ + +DT_SUBTABLE * +DtPeekSubtable ( + void) +{ + + return (Gbl_SubtableStack); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetNextSubtable + * + * PARAMETERS: ParentTable - Parent table whose children we are + * getting + * ChildTable - Previous child that was found. + * The NEXT child will be returned + * + * RETURN: Pointer to the NEXT child or NULL if none is found. + * + * DESCRIPTION: Return the next peer subtable within the tree. + * + *****************************************************************************/ + +DT_SUBTABLE * +DtGetNextSubtable ( + DT_SUBTABLE *ParentTable, + DT_SUBTABLE *ChildTable) +{ + ACPI_FUNCTION_ENTRY (); + + + if (!ChildTable) + { + /* It's really the parent's _scope_ that we want */ + + return (ParentTable->Child); + } + + /* Otherwise just return the next peer (NULL if at end-of-list) */ + + return (ChildTable->Peer); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetParentSubtable + * + * PARAMETERS: Subtable - Current subtable + * + * RETURN: Parent of the given subtable + * + * DESCRIPTION: Get the parent of the given subtable in the tree + * + *****************************************************************************/ + +DT_SUBTABLE * +DtGetParentSubtable ( + DT_SUBTABLE *Subtable) +{ + + if (!Subtable) + { + return (NULL); + } + + return (Subtable->Parent); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetSubtableLength + * + * PARAMETERS: Field - Current field list pointer + * Info - Data table info + * + * RETURN: Subtable length + * + * DESCRIPTION: Get length of bytes needed to compile the subtable + * + *****************************************************************************/ + +UINT32 +DtGetSubtableLength ( + DT_FIELD *Field, + ACPI_DMTABLE_INFO *Info) +{ + UINT32 ByteLength = 0; + + + /* Walk entire Info table; Null name terminates */ + + for (; Info->Name; Info++) + { + ByteLength += DtGetFieldLength (Field, Info); + } + + return (ByteLength); +} + + +/****************************************************************************** + * + * FUNCTION: DtSetSubtableLength + * + * PARAMETERS: Subtable - Subtable + * + * RETURN: None + * + * DESCRIPTION: Set length of the subtable into its length field + * + *****************************************************************************/ + +void +DtSetSubtableLength ( + DT_SUBTABLE *Subtable) +{ + + if (!Subtable->LengthField) + { + return; + } + + ACPI_MEMCPY (Subtable->LengthField, &Subtable->TotalLength, + Subtable->SizeOfLengthField); +} diff --git a/compiler/dttable.c b/compiler/dttable.c new file mode 100644 index 000000000000..2ab6b9ef6612 --- /dev/null +++ b/compiler/dttable.c @@ -0,0 +1,1399 @@ +/****************************************************************************** + * + * Module Name: dttable.c - handling for specific ACPI tables + * + *****************************************************************************/ + +/****************************************************************************** + * + * 1. Copyright Notice + * + * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. + * All rights reserved. + * + * 2. License + * + * 2.1. This is your license from Intel Corp. under its intellectual property + * rights. You may have additional license terms from the party that provided + * you this software, covering your right to use that party's intellectual + * property rights. + * + * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a + * copy of the source code appearing in this file ("Covered Code") an + * irrevocable, perpetual, worldwide license under Intel's copyrights in the + * base code distributed originally by Intel ("Original Intel Code") to copy, + * make derivatives, distribute, use and display any portion of the Covered + * Code in any form, with the right to sublicense such rights; and + * + * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent + * license (with the right to sublicense), under only those claims of Intel + * patents that are infringed by the Original Intel Code, to make, use, sell, + * offer to sell, and import the Covered Code and derivative works thereof + * solely to the minimum extent necessary to exercise the above copyright + * license, and in no event shall the patent license extend to any additions + * to or modifications of the Original Intel Code. No other license or right + * is granted directly or by implication, estoppel or otherwise; + * + * The above copyright and patent license is granted only if the following + * conditions are met: + * + * 3. Conditions + * + * 3.1. Redistribution of Source with Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification with rights to further distribute source must include + * the above Copyright Notice, the above License, this list of Conditions, + * and the following Disclaimer and Export Compliance provision. In addition, + * Licensee must cause all Covered Code to which Licensee contributes to + * contain a file documenting the changes Licensee made to create that Covered + * Code and the date of any change. Licensee must include in that file the + * documentation of any changes made by any predecessor Licensee. Licensee + * must include a prominent statement that the modification is derived, + * directly or indirectly, from Original Intel Code. + * + * 3.2. Redistribution of Source with no Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification without rights to further distribute source must + * include the following Disclaimer and Export Compliance provision in the + * documentation and/or other materials provided with distribution. In + * addition, Licensee may not authorize further sublicense of source of any + * portion of the Covered Code, and must include terms to the effect that the + * license from Licensee to its licensee is limited to the intellectual + * property embodied in the software Licensee provides to its licensee, and + * not to intellectual property embodied in modifications its licensee may + * make. + * + * 3.3. Redistribution of Executable. Redistribution in executable form of any + * substantial portion of the Covered Code or modification must reproduce the + * above Copyright Notice, and the following Disclaimer and Export Compliance + * provision in the documentation and/or other materials provided with the + * distribution. + * + * 3.4. Intel retains all right, title, and interest in and to the Original + * Intel Code. + * + * 3.5. Neither the name Intel nor any other trademark owned or controlled by + * Intel shall be used in advertising or otherwise to promote the sale, use or + * other dealings in products derived from or relating to the Covered Code + * without prior written authorization from Intel. + * + * 4. Disclaimer and Export Compliance + * + * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED + * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE + * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, + * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY + * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A + * PARTICULAR PURPOSE. + * + * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES + * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR + * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, + * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY + * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL + * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS + * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY + * LIMITED REMEDY. + * + * 4.3. Licensee shall not export, either directly or indirectly, any of this + * software or system incorporating such software without first obtaining any + * required license or other approval from the U. S. Department of Commerce or + * any other agency or department of the United States Government. In the + * event Licensee exports any such software from the United States or + * re-exports any such software from a foreign destination, Licensee shall + * ensure that the distribution and export/re-export of the software is in + * compliance with all laws, regulations, orders, or other restrictions of the + * U.S. Export Administration Regulations. Licensee agrees that neither it nor + * any of its subsidiaries will export/re-export any technical data, process, + * software, or service, directly or indirectly, to any country for which the + * United States government or any agency thereof requires an export license, + * other governmental approval, or letter of assurance, without first obtaining + * such license, approval or letter. + * + *****************************************************************************/ + +#define __DTTABLE_C__ + +/* Compile all complex data tables */ + +#include "aslcompiler.h" +#include "dtcompiler.h" + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dttable") + + +/* TBD: merge these into dmtbinfo.c? */ + +static ACPI_DMTABLE_INFO TableInfoAsfAddress[] = +{ + {ACPI_DMT_BUFFER, 0, "Addresses", 0}, + {ACPI_DMT_EXIT, 0, NULL, 0} +}; + +static ACPI_DMTABLE_INFO TableInfoDmarPciPath[] = +{ + {ACPI_DMT_PCI_PATH, 0, "PCI Path", 0}, + {ACPI_DMT_EXIT, 0, NULL, 0} +}; + + +/* TBD: move to acmacros.h */ + +#define ACPI_SUB_PTR(t, a, b) \ + ACPI_CAST_PTR (t, (ACPI_CAST_PTR (UINT8, (a)) - (ACPI_SIZE)(b))) + + +/* Local prototypes */ + +static ACPI_STATUS +DtCompileTwoSubtables ( + void **List, + ACPI_DMTABLE_INFO *TableInfo1, + ACPI_DMTABLE_INFO *TableInfo2); + + +/****************************************************************************** + * + * FUNCTION: DtCompileTwoSubtables + * + * PARAMETERS: List - Current field list pointer + * TableInfo1 - Info table 1 + * TableInfo1 - Info table 2 + * + * RETURN: Status + * + * DESCRIPTION: Compile tables with a header and one or more same subtables. + * Include CPEP, EINJ, ERST, MCFG, MSCT, WDAT + * + *****************************************************************************/ + +static ACPI_STATUS +DtCompileTwoSubtables ( + void **List, + ACPI_DMTABLE_INFO *TableInfo1, + ACPI_DMTABLE_INFO *TableInfo2) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + + + Status = DtCompileTable (PFieldList, TableInfo1, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + Status = DtCompileTable (PFieldList, TableInfo2, &Subtable, FALSE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileFacs + * + * PARAMETERS: PFieldList - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile FACS. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileFacs ( + DT_FIELD **PFieldList) +{ + DT_SUBTABLE *Subtable; + UINT8 *ReservedBuffer; + ACPI_STATUS Status; + UINT32 ReservedSize; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoFacs, + &Gbl_RootTable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Large FACS reserved area at the end of the table */ + + ReservedSize = (UINT32) sizeof (((ACPI_TABLE_FACS *) NULL)->Reserved1); + ReservedBuffer = UtLocalCalloc (ReservedSize); + + DtCreateSubtable (ReservedBuffer, ReservedSize, &Subtable); + + ACPI_FREE (ReservedBuffer); + DtInsertSubtable (Gbl_RootTable, Subtable); + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileRsdp + * + * PARAMETERS: PFieldList - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile RSDP. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileRsdp ( + DT_FIELD **PFieldList) +{ + DT_SUBTABLE *Subtable; + ACPI_TABLE_RSDP *Table; + ACPI_STATUS Status; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoRsdp1, + &Gbl_RootTable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + Table = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Gbl_RootTable->Buffer); + DtSetTableChecksum (&Table->Checksum); + + if (Table->Revision > 0) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoRsdp2, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (Gbl_RootTable, Subtable); + DtSetTableChecksum (&Table->ExtendedChecksum); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileAsf + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile ASF!. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileAsf ( + void **List) +{ + ACPI_ASF_INFO *AsfTable; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + ACPI_DMTABLE_INFO *InfoTable; + ACPI_DMTABLE_INFO *DataInfoTable = NULL; + UINT32 DataCount = 0; + ACPI_STATUS Status; + UINT32 i; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoAsfHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + AsfTable = ACPI_CAST_PTR (ACPI_ASF_INFO, Subtable->Buffer); + + switch (AsfTable->Header.Type & 0x7F) /* Mask off top bit */ + { + case ACPI_ASF_TYPE_INFO: + InfoTable = AcpiDmTableInfoAsf0; + break; + + case ACPI_ASF_TYPE_ALERT: + InfoTable = AcpiDmTableInfoAsf1; + break; + + case ACPI_ASF_TYPE_CONTROL: + InfoTable = AcpiDmTableInfoAsf2; + break; + + case ACPI_ASF_TYPE_BOOT: + InfoTable = AcpiDmTableInfoAsf3; + break; + + case ACPI_ASF_TYPE_ADDRESS: + InfoTable = AcpiDmTableInfoAsf4; + break; + + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "ASF!"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + switch (AsfTable->Header.Type & 0x7F) /* Mask off top bit */ + { + case ACPI_ASF_TYPE_INFO: + DataInfoTable = NULL; + break; + + case ACPI_ASF_TYPE_ALERT: + DataInfoTable = AcpiDmTableInfoAsf1a; + DataCount = ACPI_CAST_PTR (ACPI_ASF_ALERT, + ACPI_SUB_PTR (UINT8, Subtable->Buffer, + sizeof (ACPI_ASF_HEADER)))->Alerts; + break; + + case ACPI_ASF_TYPE_CONTROL: + DataInfoTable = AcpiDmTableInfoAsf2a; + DataCount = ACPI_CAST_PTR (ACPI_ASF_REMOTE, + ACPI_SUB_PTR (UINT8, Subtable->Buffer, + sizeof (ACPI_ASF_HEADER)))->Controls; + break; + + case ACPI_ASF_TYPE_BOOT: + DataInfoTable = NULL; + break; + + case ACPI_ASF_TYPE_ADDRESS: + DataInfoTable = TableInfoAsfAddress; + DataCount = ACPI_CAST_PTR (ACPI_ASF_ADDRESS, + ACPI_SUB_PTR (UINT8, Subtable->Buffer, + sizeof (ACPI_ASF_HEADER)))->Devices; + break; + + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "ASF!"); + return (AE_ERROR); + } + + if (DataInfoTable) + { + switch (AsfTable->Header.Type & 0x7F) + { + case ACPI_ASF_TYPE_ADDRESS: + + while (DataCount > 0) + { + Status = DtCompileTable (PFieldList, DataInfoTable, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + DataCount = DataCount - Subtable->Length; + } + break; + + default: + + for (i = 0; i < DataCount; i++) + { + Status = DtCompileTable (PFieldList, DataInfoTable, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + } + break; + } + } + + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileCpep + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile CPEP. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileCpep ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoCpep, AcpiDmTableInfoCpep0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileDmar + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile DMAR. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileDmar ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_DMTABLE_INFO *InfoTable; + ACPI_DMAR_HEADER *DmarHeader; + UINT8 *ReservedBuffer; + UINT32 ReservedSize; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoDmar, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + /* DMAR Reserved area */ + + ReservedSize = (UINT32) sizeof (((ACPI_TABLE_DMAR *) NULL)->Reserved); + ReservedBuffer = UtLocalCalloc (ReservedSize); + + DtCreateSubtable (ReservedBuffer, ReservedSize, &Subtable); + + ACPI_FREE (ReservedBuffer); + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + /* DMAR Header */ + + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoDmarHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + DmarHeader = ACPI_CAST_PTR (ACPI_DMAR_HEADER, Subtable->Buffer); + + switch (DmarHeader->Type) + { + case ACPI_DMAR_TYPE_HARDWARE_UNIT: + InfoTable = AcpiDmTableInfoDmar0; + break; + case ACPI_DMAR_TYPE_RESERVED_MEMORY: + InfoTable = AcpiDmTableInfoDmar1; + break; + case ACPI_DMAR_TYPE_ATSR: + InfoTable = AcpiDmTableInfoDmar2; + break; + case ACPI_DMAR_HARDWARE_AFFINITY: + InfoTable = AcpiDmTableInfoDmar3; + break; + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "DMAR"); + return (AE_ERROR); + } + + /* DMAR Subtable */ + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + /* Optional Device Scope subtables */ + + while (*PFieldList) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoDmarScope, + &Subtable, FALSE); + if (Status == AE_NOT_FOUND) + { + break; + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + /* Optional PCI Paths */ + + while (*PFieldList) + { + Status = DtCompileTable (PFieldList, TableInfoDmarPciPath, + &Subtable, FALSE); + if (Status == AE_NOT_FOUND) + { + DtPopSubtable (); + break; + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + } + } + + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileEinj + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile EINJ. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileEinj ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoEinj, AcpiDmTableInfoEinj0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileErst + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile ERST. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileErst ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoErst, AcpiDmTableInfoEinj0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileFadt + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile FADT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileFadt ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + ACPI_TABLE_HEADER *Table; + UINT8 Revision; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt1, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + Table = ACPI_CAST_PTR (ACPI_TABLE_HEADER, ParentTable->Buffer); + Revision = Table->Revision; + + if (Revision == 2) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt2, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + } + else if (Revision >= 2) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt3, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileHest + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile HEST. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileHest ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_DMTABLE_INFO *InfoTable; + UINT16 Type; + UINT32 BankCount; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoHest, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + /* Get subtable type */ + + SubtableStart = *PFieldList; + DtCompileInteger ((UINT8 *) &Type, *PFieldList, 2, 0); + + switch (Type) + { + case ACPI_HEST_TYPE_IA32_CHECK: + InfoTable = AcpiDmTableInfoHest0; + break; + + case ACPI_HEST_TYPE_IA32_CORRECTED_CHECK: + InfoTable = AcpiDmTableInfoHest1; + break; + + case ACPI_HEST_TYPE_IA32_NMI: + InfoTable = AcpiDmTableInfoHest2; + break; + + case ACPI_HEST_TYPE_AER_ROOT_PORT: + InfoTable = AcpiDmTableInfoHest6; + break; + + case ACPI_HEST_TYPE_AER_ENDPOINT: + InfoTable = AcpiDmTableInfoHest7; + break; + + case ACPI_HEST_TYPE_AER_BRIDGE: + InfoTable = AcpiDmTableInfoHest8; + break; + + case ACPI_HEST_TYPE_GENERIC_ERROR: + InfoTable = AcpiDmTableInfoHest9; + break; + + default: + /* Cannot continue on unknown type */ + + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "HEST"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + + /* + * Additional subtable data - IA32 Error Bank(s) + */ + BankCount = 0; + switch (Type) + { + case ACPI_HEST_TYPE_IA32_CHECK: + BankCount = (ACPI_CAST_PTR (ACPI_HEST_IA_MACHINE_CHECK, + Subtable->Buffer))->NumHardwareBanks; + break; + + case ACPI_HEST_TYPE_IA32_CORRECTED_CHECK: + BankCount = (ACPI_CAST_PTR (ACPI_HEST_IA_CORRECTED, + Subtable->Buffer))->NumHardwareBanks; + break; + + default: + break; + } + + while (BankCount) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoHestBank, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + BankCount--; + } + } + + return AE_OK; +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileIvrs + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile IVRS. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileIvrs ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_DMTABLE_INFO *InfoTable; + ACPI_IVRS_HEADER *IvrsHeader; + UINT8 EntryType; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoIvrs, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoIvrsHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + IvrsHeader = ACPI_CAST_PTR (ACPI_IVRS_HEADER, Subtable->Buffer); + + switch (IvrsHeader->Type) + { + case ACPI_IVRS_TYPE_HARDWARE: + InfoTable = AcpiDmTableInfoIvrs0; + break; + + case ACPI_IVRS_TYPE_MEMORY1: + case ACPI_IVRS_TYPE_MEMORY2: + case ACPI_IVRS_TYPE_MEMORY3: + InfoTable = AcpiDmTableInfoIvrs1; + break; + + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "IVRS"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + if (IvrsHeader->Type == ACPI_IVRS_TYPE_HARDWARE) + { + while (*PFieldList && + !ACPI_STRCMP ((*PFieldList)->Name, "Entry Type")) + { + SubtableStart = *PFieldList; + DtCompileInteger (&EntryType, *PFieldList, 1, 0); + + switch (EntryType) + { + /* 4-byte device entries */ + + case ACPI_IVRS_TYPE_PAD4: + case ACPI_IVRS_TYPE_ALL: + case ACPI_IVRS_TYPE_SELECT: + case ACPI_IVRS_TYPE_START: + case ACPI_IVRS_TYPE_END: + + InfoTable = AcpiDmTableInfoIvrs4; + break; + + /* 8-byte entries, type A */ + + case ACPI_IVRS_TYPE_ALIAS_SELECT: + case ACPI_IVRS_TYPE_ALIAS_START: + + InfoTable = AcpiDmTableInfoIvrs8a; + break; + + /* 8-byte entries, type B */ + + case ACPI_IVRS_TYPE_PAD8: + case ACPI_IVRS_TYPE_EXT_SELECT: + case ACPI_IVRS_TYPE_EXT_START: + + InfoTable = AcpiDmTableInfoIvrs8b; + break; + + /* 8-byte entries, type C */ + + case ACPI_IVRS_TYPE_SPECIAL: + + InfoTable = AcpiDmTableInfoIvrs8c; + break; + + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, + "IVRS Device Entry"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + } + } + + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileMadt + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile MADT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileMadt ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_SUBTABLE_HEADER *MadtHeader; + ACPI_DMTABLE_INFO *InfoTable; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoMadt, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoMadtHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + MadtHeader = ACPI_CAST_PTR (ACPI_SUBTABLE_HEADER, Subtable->Buffer); + + switch (MadtHeader->Type) + { + case ACPI_MADT_TYPE_LOCAL_APIC: + InfoTable = AcpiDmTableInfoMadt0; + break; + case ACPI_MADT_TYPE_IO_APIC: + InfoTable = AcpiDmTableInfoMadt1; + break; + case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE: + InfoTable = AcpiDmTableInfoMadt2; + break; + case ACPI_MADT_TYPE_NMI_SOURCE: + InfoTable = AcpiDmTableInfoMadt3; + break; + case ACPI_MADT_TYPE_LOCAL_APIC_NMI: + InfoTable = AcpiDmTableInfoMadt4; + break; + case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE: + InfoTable = AcpiDmTableInfoMadt5; + break; + case ACPI_MADT_TYPE_IO_SAPIC: + InfoTable = AcpiDmTableInfoMadt6; + break; + case ACPI_MADT_TYPE_LOCAL_SAPIC: + InfoTable = AcpiDmTableInfoMadt7; + break; + case ACPI_MADT_TYPE_INTERRUPT_SOURCE: + InfoTable = AcpiDmTableInfoMadt8; + break; + case ACPI_MADT_TYPE_LOCAL_X2APIC: + InfoTable = AcpiDmTableInfoMadt9; + break; + case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI: + InfoTable = AcpiDmTableInfoMadt10; + break; + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "MADT"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileMcfg + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile MCFG. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileMcfg ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoMcfg, AcpiDmTableInfoMcfg0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileMsct + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile MSCT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileMsct ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoMsct, AcpiDmTableInfoMsct0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileRsdt + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile RSDT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileRsdt ( + void **List) +{ + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD *FieldList = *(DT_FIELD **) List; + UINT32 Address; + + + ParentTable = DtPeekSubtable (); + + while (FieldList) + { + DtCompileInteger ((UINT8 *) &Address, FieldList, 4, DT_NON_ZERO); + + DtCreateSubtable ((UINT8 *) &Address, 4, &Subtable); + DtInsertSubtable (ParentTable, Subtable); + FieldList = FieldList->Next; + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileSlit + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile SLIT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileSlit ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *FieldList; + UINT32 Localities; + UINT8 *LocalityBuffer; + UINT32 RemainingData; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoSlit, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + Localities = *ACPI_CAST_PTR (UINT32, Subtable->Buffer); + LocalityBuffer = UtLocalCalloc (Localities); + + FieldList = *PFieldList; + while (FieldList) + { + /* Handle multiple-line buffer */ + + RemainingData = Localities; + while (RemainingData && FieldList) + { + RemainingData = DtCompileBuffer ( + LocalityBuffer + (Localities - RemainingData), + FieldList->Value, FieldList, RemainingData); + FieldList = FieldList->Next; + } + + DtCreateSubtable (LocalityBuffer, Localities, &Subtable); + DtInsertSubtable (ParentTable, Subtable); + } + + ACPI_FREE (LocalityBuffer); + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileSrat + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile SRAT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileSrat ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_SUBTABLE_HEADER *SratHeader; + ACPI_DMTABLE_INFO *InfoTable; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoSrat, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoSratHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + SratHeader = ACPI_CAST_PTR (ACPI_SUBTABLE_HEADER, Subtable->Buffer); + + switch (SratHeader->Type) + { + case ACPI_SRAT_TYPE_CPU_AFFINITY: + InfoTable = AcpiDmTableInfoSrat0; + break; + case ACPI_SRAT_TYPE_MEMORY_AFFINITY: + InfoTable = AcpiDmTableInfoSrat1; + break; + case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY: + InfoTable = AcpiDmTableInfoSrat2; + break; + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "SRAT"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileWdat + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile WDAT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileWdat ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoWdat, AcpiDmTableInfoWdat0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileXsdt + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile XSDT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileXsdt ( + void **List) +{ + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD *FieldList = *(DT_FIELD **) List; + UINT64 Address; + + ParentTable = DtPeekSubtable (); + + while (FieldList) + { + DtCompileInteger ((UINT8 *) &Address, FieldList, 8, DT_NON_ZERO); + + DtCreateSubtable ((UINT8 *) &Address, 8, &Subtable); + DtInsertSubtable (ParentTable, Subtable); + FieldList = FieldList->Next; + } + + return (AE_OK); +} diff --git a/compiler/dtutils.c b/compiler/dtutils.c new file mode 100644 index 000000000000..c3a4a85cd094 --- /dev/null +++ b/compiler/dtutils.c @@ -0,0 +1,894 @@ +/****************************************************************************** + * + * Module Name: dtutils.c - Utility routines for the data table compiler + * + *****************************************************************************/ + +/****************************************************************************** + * + * 1. Copyright Notice + * + * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. + * All rights reserved. + * + * 2. License + * + * 2.1. This is your license from Intel Corp. under its intellectual property + * rights. You may have additional license terms from the party that provided + * you this software, covering your right to use that party's intellectual + * property rights. + * + * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a + * copy of the source code appearing in this file ("Covered Code") an + * irrevocable, perpetual, worldwide license under Intel's copyrights in the + * base code distributed originally by Intel ("Original Intel Code") to copy, + * make derivatives, distribute, use and display any portion of the Covered + * Code in any form, with the right to sublicense such rights; and + * + * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent + * license (with the right to sublicense), under only those claims of Intel + * patents that are infringed by the Original Intel Code, to make, use, sell, + * offer to sell, and import the Covered Code and derivative works thereof + * solely to the minimum extent necessary to exercise the above copyright + * license, and in no event shall the patent license extend to any additions + * to or modifications of the Original Intel Code. No other license or right + * is granted directly or by implication, estoppel or otherwise; + * + * The above copyright and patent license is granted only if the following + * conditions are met: + * + * 3. Conditions + * + * 3.1. Redistribution of Source with Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification with rights to further distribute source must include + * the above Copyright Notice, the above License, this list of Conditions, + * and the following Disclaimer and Export Compliance provision. In addition, + * Licensee must cause all Covered Code to which Licensee contributes to + * contain a file documenting the changes Licensee made to create that Covered + * Code and the date of any change. Licensee must include in that file the + * documentation of any changes made by any predecessor Licensee. Licensee + * must include a prominent statement that the modification is derived, + * directly or indirectly, from Original Intel Code. + * + * 3.2. Redistribution of Source with no Rights to Further Distribute Source. + * Redistribution of source code of any substantial portion of the Covered + * Code or modification without rights to further distribute source must + * include the following Disclaimer and Export Compliance provision in the + * documentation and/or other materials provided with distribution. In + * addition, Licensee may not authorize further sublicense of source of any + * portion of the Covered Code, and must include terms to the effect that the + * license from Licensee to its licensee is limited to the intellectual + * property embodied in the software Licensee provides to its licensee, and + * not to intellectual property embodied in modifications its licensee may + * make. + * + * 3.3. Redistribution of Executable. Redistribution in executable form of any + * substantial portion of the Covered Code or modification must reproduce the + * above Copyright Notice, and the following Disclaimer and Export Compliance + * provision in the documentation and/or other materials provided with the + * distribution. + * + * 3.4. Intel retains all right, title, and interest in and to the Original + * Intel Code. + * + * 3.5. Neither the name Intel nor any other trademark owned or controlled by + * Intel shall be used in advertising or otherwise to promote the sale, use or + * other dealings in products derived from or relating to the Covered Code + * without prior written authorization from Intel. + * + * 4. Disclaimer and Export Compliance + * + * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED + * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE + * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, + * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY + * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY + * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A + * PARTICULAR PURPOSE. + * + * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES + * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR + * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, + * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY + * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL + * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS + * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY + * LIMITED REMEDY. + * + * 4.3. Licensee shall not export, either directly or indirectly, any of this + * software or system incorporating such software without first obtaining any + * required license or other approval from the U. S. Department of Commerce or + * any other agency or department of the United States Government. In the + * event Licensee exports any such software from the United States or + * re-exports any such software from a foreign destination, Licensee shall + * ensure that the distribution and export/re-export of the software is in + * compliance with all laws, regulations, orders, or other restrictions of the + * U.S. Export Administration Regulations. Licensee agrees that neither it nor + * any of its subsidiaries will export/re-export any technical data, process, + * software, or service, directly or indirectly, to any country for which the + * United States government or any agency thereof requires an export license, + * other governmental approval, or letter of assurance, without first obtaining + * such license, approval or letter. + * + *****************************************************************************/ + +#define __DTUTILS_C__ + +#include "aslcompiler.h" +#include "dtcompiler.h" +#include "actables.h" + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtutils") + +/* Local prototypes */ + +static void +DtSum ( + DT_SUBTABLE *Subtable, + void *Context, + void *ReturnValue); + + +/****************************************************************************** + * + * FUNCTION: DtError + * + * PARAMETERS: Level - Seriousness (Warning/error, etc.) + * MessageId - Index into global message buffer + * Op - Parse node where error happened + * ExtraMessage - additional error message + * + * RETURN: None + * + * DESCRIPTION: Common error interface for data table compiler + * + *****************************************************************************/ + +void +DtError ( + UINT8 Level, + UINT8 MessageId, + DT_FIELD *FieldObject, + char *ExtraMessage) +{ + + switch (Level) + { + case ASL_WARNING2: + case ASL_WARNING3: + if (Gbl_WarningLevel < Level) + { + return; + } + break; + + default: + break; + } + + if (FieldObject) + { + AslCommonError (Level, MessageId, + FieldObject->Line, + FieldObject->Line, + FieldObject->ByteOffset, + FieldObject->Column, + Gbl_Files[ASL_FILE_INPUT].Filename, ExtraMessage); + } + else + { + AslCommonError (Level, MessageId, 0, + 0, 0, 0, 0, ExtraMessage); + } +} + + +/****************************************************************************** + * + * FUNCTION: DtNameError + * + * PARAMETERS: Level - Seriousness (Warning/error, etc.) + * MessageId - Index into global message buffer + * Op - Parse node where error happened + * ExtraMessage - additional error message + * + * RETURN: None + * + * DESCRIPTION: Error interface for named objects + * + *****************************************************************************/ + +void +DtNameError ( + UINT8 Level, + UINT8 MessageId, + DT_FIELD *FieldObject, + char *ExtraMessage) +{ + + switch (Level) + { + case ASL_WARNING2: + case ASL_WARNING3: + if (Gbl_WarningLevel < Level) + { + return; + } + break; + + default: + break; + } + + if (FieldObject) + { + AslCommonError (Level, MessageId, + FieldObject->Line, + FieldObject->Line, + FieldObject->ByteOffset, + FieldObject->NameColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, ExtraMessage); + } + else + { + AslCommonError (Level, MessageId, 0, + 0, 0, 0, 0, ExtraMessage); + } +} + + +/******************************************************************************* + * + * FUNCTION: DtFatal + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Dump the error log and abort the compiler. Used for serious + * compile or I/O errors + * + ******************************************************************************/ + +void +DtFatal ( + UINT8 MessageId, + DT_FIELD *FieldObject, + char *ExtraMessage) +{ + + DtError (ASL_ERROR, MessageId, FieldObject, ExtraMessage); + + CmCleanupAndExit (); + exit (1); +} + + +/****************************************************************************** + * + * FUNCTION: DtStrtoul64 + * + * PARAMETERS: String - Null terminated string + * ReturnInteger - Where the converted integer is returned + * + * RETURN: Status + * + * DESCRIPTION: Simple conversion of a string hex integer constant to unsigned + * value. Assumes no leading "0x" for the constant. + * + * Portability note: The reason this function exists is because a 64-bit + * sscanf is not available in all environments. + * + *****************************************************************************/ + +ACPI_STATUS +DtStrtoul64 ( + char *String, + UINT64 *ReturnInteger) +{ + char *ThisChar = String; + UINT32 ThisDigit; + UINT64 ReturnValue = 0; + int DigitCount = 0; + + + /* Skip over any white space in the buffer */ + + while ((*ThisChar == ' ') || (*ThisChar == '\t')) + { + ThisChar++; + } + + /* Skip leading zeros */ + + while ((*ThisChar) == '0') + { + ThisChar++; + } + + /* Convert character-by-character */ + + while (*ThisChar) + { + if (ACPI_IS_DIGIT (*ThisChar)) + { + /* Convert ASCII 0-9 to Decimal value */ + + ThisDigit = ((UINT8) *ThisChar) - '0'; + } + else /* Letter */ + { + ThisDigit = (UINT32) ACPI_TOUPPER (*ThisChar); + if (!ACPI_IS_XDIGIT ((char) ThisDigit)) + { + /* Not A-F */ + + return (AE_BAD_CHARACTER); + } + + /* Convert ASCII Hex char (A-F) to value */ + + ThisDigit = (ThisDigit - 'A') + 10; + } + + /* Insert the 4-bit hex digit */ + + ReturnValue <<= 4; + ReturnValue += ThisDigit; + + ThisChar++; + DigitCount++; + if (DigitCount > 16) + { + /* Value is too large (> 64 bits/8 bytes/16 hex digits) */ + + return (AE_LIMIT); + } + } + + *ReturnInteger = ReturnValue; + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetFileSize + * + * PARAMETERS: Handle - Open file handler + * + * RETURN: Current file size + * + * DESCRIPTION: Get the current size of a file. Seek to the EOF and get the + * offset. Seek back to the original location. + * + *****************************************************************************/ + +UINT32 +DtGetFileSize ( + FILE *Handle) +{ + int CurrentOffset; + int LastOffset; + + + CurrentOffset = ftell (Handle); + fseek (Handle, 0, SEEK_END); + LastOffset = ftell (Handle); + fseek (Handle, CurrentOffset, SEEK_SET); + + return ((UINT32) LastOffset); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetFieldValue + * + * PARAMETERS: Field - Current field list pointer + * Name - Field name + * + * RETURN: Field value + * + * DESCRIPTION: Get field value + * + *****************************************************************************/ + +char * +DtGetFieldValue ( + DT_FIELD *Field, + char *Name) +{ + + /* Search the field list for the name */ + + while (Field) + { + if (!ACPI_STRCMP (Name, Field->Name)) + { + return (Field->Value); + } + + Field = Field->Next; + } + + return (NULL); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetFieldType + * + * PARAMETERS: Info - Data table info + * + * RETURN: Field type + * + * DESCRIPTION: Get field type + * + *****************************************************************************/ + +UINT8 +DtGetFieldType ( + ACPI_DMTABLE_INFO *Info) +{ + UINT8 Type; + + + /* DT_FLAG means that this is the start of a block of flag bits */ + /* TBD - we can make these a separate opcode later */ + + if (Info->Flags & DT_FLAG) + { + return (DT_FIELD_TYPE_FLAGS_INTEGER); + } + + /* Type is based upon the opcode for this field in the info table */ + + switch (Info->Opcode) + { + case ACPI_DMT_FLAG0: + case ACPI_DMT_FLAG1: + case ACPI_DMT_FLAG2: + case ACPI_DMT_FLAG3: + case ACPI_DMT_FLAG4: + case ACPI_DMT_FLAG5: + case ACPI_DMT_FLAG6: + case ACPI_DMT_FLAG7: + case ACPI_DMT_FLAGS0: + case ACPI_DMT_FLAGS2: + Type = DT_FIELD_TYPE_FLAG; + break; + + case ACPI_DMT_NAME4: + case ACPI_DMT_SIG: + case ACPI_DMT_NAME6: + case ACPI_DMT_NAME8: + case ACPI_DMT_STRING: + Type = DT_FIELD_TYPE_STRING; + break; + + case ACPI_DMT_BUFFER: + case ACPI_DMT_BUF16: + Type = DT_FIELD_TYPE_BUFFER; + break; + + case ACPI_DMT_PCI_PATH: + Type = DT_FIELD_TYPE_PCI_PATH; + break; + + case ACPI_DMT_GAS: + case ACPI_DMT_HESTNTFY: + Type = DT_FIELD_TYPE_INLINE_SUBTABLE; + break; + + default: + Type = DT_FIELD_TYPE_INTEGER; + break; + } + + return (Type); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetBufferLength + * + * PARAMETERS: Buffer - List of integers, + * for example "10 3A 4F 2E" + * + * RETURN: Count of integer + * + * DESCRIPTION: Get length of bytes needed to store the integers + * + *****************************************************************************/ + +UINT32 +DtGetBufferLength ( + char *Buffer) +{ + UINT32 ByteLength = 0; + + + while (*Buffer) + { + if (*Buffer == ' ') + { + ByteLength++; + + while (*Buffer == ' ') + { + Buffer++; + } + } + + Buffer++; + } + + return (++ByteLength); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetFieldLength + * + * PARAMETERS: Field - Current field list pointer + * Info - Data table info + * + * RETURN: Field length + * + * DESCRIPTION: Get length of bytes needed to compile the field + * + *****************************************************************************/ + +UINT32 +DtGetFieldLength ( + DT_FIELD *Field, + ACPI_DMTABLE_INFO *Info) +{ + UINT32 ByteLength = 0; + char *Value; + + + /* Length is based upon the opcode for this field in the info table */ + + switch (Info->Opcode) + { + case ACPI_DMT_FLAG0: + case ACPI_DMT_FLAG1: + case ACPI_DMT_FLAG2: + case ACPI_DMT_FLAG3: + case ACPI_DMT_FLAG4: + case ACPI_DMT_FLAG5: + case ACPI_DMT_FLAG6: + case ACPI_DMT_FLAG7: + case ACPI_DMT_FLAGS0: + case ACPI_DMT_FLAGS2: + ByteLength = 0; + break; + + case ACPI_DMT_UINT8: + case ACPI_DMT_CHKSUM: + case ACPI_DMT_SPACEID: + case ACPI_DMT_MADT: + case ACPI_DMT_SRAT: + case ACPI_DMT_ASF: + case ACPI_DMT_HESTNTYP: + case ACPI_DMT_FADTPM: + case ACPI_DMT_IVRS: + ByteLength = 1; + break; + + case ACPI_DMT_UINT16: + case ACPI_DMT_DMAR: + case ACPI_DMT_HEST: + case ACPI_DMT_PCI_PATH: + ByteLength = 2; + break; + + case ACPI_DMT_UINT24: + ByteLength = 3; + break; + + case ACPI_DMT_UINT32: + case ACPI_DMT_NAME4: + case ACPI_DMT_SIG: + ByteLength = 4; + break; + + case ACPI_DMT_NAME6: + ByteLength = 6; + break; + + case ACPI_DMT_UINT56: + ByteLength = 7; + break; + + case ACPI_DMT_UINT64: + case ACPI_DMT_NAME8: + ByteLength = 8; + break; + + case ACPI_DMT_STRING: + Value = DtGetFieldValue (Field, Info->Name); + + /* TBD: error if Value is NULL? (as below?) */ + + ByteLength = ACPI_STRLEN (Value) + 1; + break; + + case ACPI_DMT_GAS: + ByteLength = sizeof (ACPI_GENERIC_ADDRESS); + break; + + case ACPI_DMT_HESTNTFY: + ByteLength = sizeof (ACPI_HEST_NOTIFY); + break; + + case ACPI_DMT_BUFFER: + Value = DtGetFieldValue (Field, Info->Name); + if (Value) + { + ByteLength = DtGetBufferLength (Value); + } + else + { /* At this point, this is a fatal error */ + + sprintf (MsgBuffer, "Expected \"%s\"", Info->Name); + DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer); + } + break; + + case ACPI_DMT_BUF16: + ByteLength = 16; + break; + + default: + DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid table opcode"); + break; + } + + return (ByteLength); +} + + +/****************************************************************************** + * + * FUNCTION: DtSum + * + * PARAMETERS: DT_WALK_CALLBACK: + * Subtable - Subtable + * Context - Unused + * ReturnValue - Store the checksum of subtable + * + * RETURN: Status + * + * DESCRIPTION: Get the checksum of subtable + * + *****************************************************************************/ + +static void +DtSum ( + DT_SUBTABLE *Subtable, + void *Context, + void *ReturnValue) +{ + UINT8 Checksum; + UINT8 *Sum = ReturnValue; + + + Checksum = AcpiTbChecksum (Subtable->Buffer, Subtable->Length); + *Sum = (UINT8) (*Sum + Checksum); +} + + +/****************************************************************************** + * + * FUNCTION: DtSetTableChecksum + * + * PARAMETERS: ChecksumPointer - Where to return the checksum + * + * RETURN: None + * + * DESCRIPTION: Set checksum of the whole data table into the checksum field + * + *****************************************************************************/ + +void +DtSetTableChecksum ( + UINT8 *ChecksumPointer) +{ + UINT8 Checksum = 0; + UINT8 OldSum; + + + DtWalkTableTree (Gbl_RootTable, DtSum, NULL, &Checksum); + + OldSum = *ChecksumPointer; + Checksum = (UINT8) (Checksum - OldSum); + + /* Compute the final checksum */ + + Checksum = (UINT8) (0 - Checksum); + *ChecksumPointer = Checksum; +} + + +/****************************************************************************** + * + * FUNCTION: DtSetTableLength + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Walk the subtables and set all the length fields + * + *****************************************************************************/ + +void +DtSetTableLength ( + void) +{ + DT_SUBTABLE *ParentTable; + DT_SUBTABLE *ChildTable; + + + ParentTable = Gbl_RootTable; + ChildTable = NULL; + + if (!ParentTable) + { + return; + } + + DtSetSubtableLength (ParentTable); + + while (1) + { + ChildTable = DtGetNextSubtable (ParentTable, ChildTable); + if (ChildTable) + { + if (ChildTable->Child) + { + ParentTable = ChildTable; + ChildTable = NULL; + } + else + { + ParentTable->TotalLength += ChildTable->TotalLength; + if (ParentTable->LengthField) + { + DtSetSubtableLength (ParentTable); + } + } + } + else + { + ChildTable = ParentTable; + + if (ChildTable == Gbl_RootTable) + { + break; + } + + ParentTable = DtGetParentSubtable (ParentTable); + + ParentTable->TotalLength += ChildTable->TotalLength; + if (ParentTable->LengthField) + { + DtSetSubtableLength (ParentTable); + } + } + } +} + + +/****************************************************************************** + * + * FUNCTION: DtWalkTableTree + * + * PARAMETERS: StartTable - Subtable in the tree where walking begins + * UserFunction - Called during the walk + * Context - Passed to user function + * ReturnValue - The return value of UserFunction + * + * RETURN: None + * + * DESCRIPTION: Performs a depth-first walk of the subtable tree + * + *****************************************************************************/ + +void +DtWalkTableTree ( + DT_SUBTABLE *StartTable, + DT_WALK_CALLBACK UserFunction, + void *Context, + void *ReturnValue) +{ + DT_SUBTABLE *ParentTable; + DT_SUBTABLE *ChildTable; + + + ParentTable = StartTable; + ChildTable = NULL; + + if (!ParentTable) + { + return; + } + + UserFunction (ParentTable, Context, ReturnValue); + + while (1) + { + ChildTable = DtGetNextSubtable (ParentTable, ChildTable); + if (ChildTable) + { + UserFunction (ChildTable, Context, ReturnValue); + + if (ChildTable->Child) + { + ParentTable = ChildTable; + ChildTable = NULL; + } + } + else + { + ChildTable = ParentTable; + if (ChildTable == Gbl_RootTable) + { + break; + } + + ParentTable = DtGetParentSubtable (ParentTable); + + if (ChildTable->Peer == StartTable) + { + break; + } + } + } +} + + +/****************************************************************************** + * + * FUNCTION: DtFreeFieldList + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Free the field list + * + *****************************************************************************/ + +void +DtFreeFieldList ( + void) +{ + DT_FIELD *Field = Gbl_FieldList; + DT_FIELD *NextField; + + + /* Walk and free entire field list */ + + while (Field) + { + NextField = Field->Next; /* Save link */ + + if (!(Field->Flags & DT_FIELD_NOT_ALLOCATED)) + { + ACPI_FREE (Field->Name); + ACPI_FREE (Field->Value); + } + + ACPI_FREE (Field); + Field = NextField; + } +} |