void PrSetLineNumber ( UINT32 OriginalLineNumber, UINT32 PreprocessorLineNumber) { UINT32 Entry; PR_LINE_MAPPING *Block; UINT32 Index; UINT32 i; Entry = PreprocessorLineNumber / PR_LINES_PER_BLOCK; Index = PreprocessorLineNumber % PR_LINES_PER_BLOCK; Block = Gbl_MapBlockHead; for (i = 0; i < Entry; i++) { /* Allocate new mapping blocks as necessary */ if (!Block->Next) { Block->Next = UtLocalCalloc (sizeof (PR_LINE_MAPPING)); Block->Next->Map = UtLocalCalloc (PR_LINES_PER_BLOCK * sizeof (UINT32)); } Block = Block->Next; } Block->Map[Index] = OriginalLineNumber; }
char * UtStringCacheCalloc ( UINT32 Length) { char *Buffer; ASL_CACHE_INFO *Cache; UINT32 CacheSize = ASL_STRING_CACHE_SIZE; if (Length > CacheSize) { CacheSize = Length; if (Gbl_StringCacheList) { Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize); /* Link new cache buffer just following head of list */ Cache->Next = Gbl_StringCacheList->Next; Gbl_StringCacheList->Next = Cache; /* Leave cache management pointers alone as they pertain to head */ Gbl_StringCount++; Gbl_StringSize += Length; return (Cache->Buffer); } } if ((Gbl_StringCacheNext + Length) >= Gbl_StringCacheLast) { /* Allocate a new buffer */ Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize); /* Link new cache buffer to head of list */ Cache->Next = Gbl_StringCacheList; Gbl_StringCacheList = Cache; /* Setup cache management pointers */ Gbl_StringCacheNext = Cache->Buffer; Gbl_StringCacheLast = Gbl_StringCacheNext + CacheSize; } Gbl_StringCount++; Gbl_StringSize += Length; Buffer = Gbl_StringCacheNext; Gbl_StringCacheNext += Length; return (Buffer); }
void DtWriteTableToListing ( void) { UINT8 *Buffer; if (!Gbl_ListingFlag) { return; } /* Read the entire table from the output file */ Buffer = UtLocalCalloc (Gbl_TableLength); FlSeekFile (ASL_FILE_AML_OUTPUT, 0); FlReadFile (ASL_FILE_AML_OUTPUT, Buffer, Gbl_TableLength); /* Dump the raw table data */ AcpiOsRedirectOutput (Gbl_Files[ASL_FILE_LISTING_OUTPUT].Handle); AcpiOsPrintf ("\n%s: Length %d (0x%X)\n\n", ACPI_RAW_TABLE_DATA_HEADER, Gbl_TableLength, Gbl_TableLength); AcpiUtDumpBuffer2 (Buffer, Gbl_TableLength, DB_BYTE_DISPLAY); AcpiOsRedirectOutput (stdout); }
DT_FIELD * UtFieldCacheCalloc ( void) { ASL_CACHE_INFO *Cache; if (Gbl_FieldCacheNext >= Gbl_FieldCacheLast) { /* Allocate a new buffer */ Cache = UtLocalCalloc (sizeof (Cache->Next) + (sizeof (DT_FIELD) * ASL_FIELD_CACHE_SIZE)); /* Link new cache buffer to head of list */ Cache->Next = Gbl_FieldCacheList; Gbl_FieldCacheList = Cache; /* Setup cache management pointers */ Gbl_FieldCacheNext = ACPI_CAST_PTR (DT_FIELD, Cache->Buffer); Gbl_FieldCacheLast = Gbl_FieldCacheNext + ASL_FIELD_CACHE_SIZE; } Gbl_FieldCount++; return (Gbl_FieldCacheNext++); }
static ACPI_PARSE_OBJECT * TrGetNextNode ( void) { ASL_CACHE_INFO *Cache; if (Gbl_ParseOpCacheNext >= Gbl_ParseOpCacheLast) { /* Allocate a new buffer */ Cache = UtLocalCalloc (sizeof (Cache->Next) + (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE)); /* Link new cache buffer to head of list */ Cache->Next = Gbl_ParseOpCacheList; Gbl_ParseOpCacheList = Cache; /* Setup cache management pointers */ Gbl_ParseOpCacheNext = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, Cache->Buffer); Gbl_ParseOpCacheLast = Gbl_ParseOpCacheNext + ASL_PARSEOP_CACHE_SIZE; } Gbl_ParseOpCount++; return (Gbl_ParseOpCacheNext++); }
void PrPushInputFileStack ( FILE *InputFile, char *Filename) { PR_FILE_NODE *Fnode; /* Save the current state in an Fnode */ Fnode = UtLocalCalloc (sizeof (PR_FILE_NODE)); Fnode->File = Gbl_Files[ASL_FILE_INPUT].Handle; Fnode->Next = Gbl_InputFileList; Fnode->Filename = Gbl_Files[ASL_FILE_INPUT].Filename; Fnode->CurrentLineNumber = Gbl_CurrentLineNumber; /* Push it on the stack */ Gbl_InputFileList = Fnode; DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "Push InputFile Stack, returning %p\n\n", Gbl_CurrentLineNumber, InputFile); /* Reset the global line count and filename */ Gbl_Files[ASL_FILE_INPUT].Filename = Filename; Gbl_Files[ASL_FILE_INPUT].Handle = InputFile; Gbl_CurrentLineNumber = 1; }
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); }
static void OpcDoUnicode ( ACPI_PARSE_OBJECT *Op) { ACPI_PARSE_OBJECT *InitializerOp; UINT32 Length; UINT32 Count; UINT32 i; UINT8 *AsciiString; UINT16 *UnicodeString; ACPI_PARSE_OBJECT *BufferLengthOp; /* Change op into a buffer object */ Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST; Op->Asl.ParseOpcode = PARSEOP_BUFFER; UtSetParseOpName (Op); /* Buffer Length is first, followed by the string */ BufferLengthOp = Op->Asl.Child; InitializerOp = BufferLengthOp->Asl.Next; AsciiString = (UINT8 *) InitializerOp->Asl.Value.String; /* Create a new buffer for the Unicode string */ Count = strlen (InitializerOp->Asl.Value.String) + 1; Length = Count * sizeof (UINT16); UnicodeString = UtLocalCalloc (Length); /* Convert to Unicode string (including null terminator) */ for (i = 0; i < Count; i++) { UnicodeString[i] = (UINT16) AsciiString[i]; } /* * Just set the buffer size node to be the buffer length, regardless * of whether it was previously an integer or a default_arg placeholder */ BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER; BufferLengthOp->Asl.AmlOpcode = AML_DWORD_OP; BufferLengthOp->Asl.Value.Integer = Length; UtSetParseOpName (BufferLengthOp); (void) OpcSetOptimalIntegerSize (BufferLengthOp); /* The Unicode string is a raw data buffer */ InitializerOp->Asl.Value.Buffer = (UINT8 *) UnicodeString; InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER; InitializerOp->Asl.AmlLength = Length; InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; InitializerOp->Asl.Child = NULL; UtSetParseOpName (InitializerOp); }
ASL_RESOURCE_NODE * RsAllocateResourceNode ( UINT32 Size) { ASL_RESOURCE_NODE *Rnode; /* Allocate the node */ Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE)); /* Allocate the resource descriptor itself */ Rnode->Buffer = UtLocalCalloc (Size); Rnode->BufferLength = Size; return (Rnode); }
static void OpcDoUuId ( ACPI_PARSE_OBJECT *Op) { char *InString; UINT8 *Buffer; ACPI_STATUS Status = AE_OK; ACPI_PARSE_OBJECT *NewOp; InString = (char *) Op->Asl.Value.String; Buffer = UtLocalCalloc (16); Status = AuValidateUuid (InString); if (ACPI_FAILURE (Status)) { AslError (ASL_ERROR, ASL_MSG_INVALID_UUID, Op, Op->Asl.Value.String); } else { AcpiUtConvertStringToUuid (InString, Buffer); } /* Change Op to a Buffer */ Op->Asl.ParseOpcode = PARSEOP_BUFFER; Op->Common.AmlOpcode = AML_BUFFER_OP; /* Disable further optimization */ Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST; UtSetParseOpName (Op); /* Child node is the buffer length */ NewOp = TrAllocateNode (PARSEOP_INTEGER); NewOp->Asl.AmlOpcode = AML_BYTE_OP; NewOp->Asl.Value.Integer = 16; NewOp->Asl.Parent = Op; Op->Asl.Child = NewOp; Op = NewOp; /* Peer to the child is the raw buffer data */ NewOp = TrAllocateNode (PARSEOP_RAW_DATA); NewOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER; NewOp->Asl.AmlLength = 16; NewOp->Asl.Value.String = (char *) Buffer; NewOp->Asl.Parent = Op->Asl.Parent; Op->Asl.Next = NewOp; }
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; }
static char * DtNormalizeBuffer ( char *Buffer, UINT32 *Count) { char *NewBuffer; char *TmpBuffer; UINT32 BufferCount = 0; BOOLEAN Separator = TRUE; char c; NewBuffer = UtLocalCalloc (ACPI_STRLEN (Buffer) + 1); TmpBuffer = NewBuffer; while ((c = *Buffer++)) { switch (c) { /* Valid separators */ case '[': case ']': case ' ': case ',': Separator = TRUE; break; default: if (Separator) { /* Insert blank as the standard separator */ if (NewBuffer[0]) { *TmpBuffer++ = ' '; BufferCount++; } Separator = FALSE; } *TmpBuffer++ = c; break; } } *Count = BufferCount + 1; return (NewBuffer); }
char * UtStringCacheCalloc ( UINT32 Length) { char *Buffer; ASL_CACHE_INFO *Cache; if (Length > ASL_STRING_CACHE_SIZE) { Buffer = UtLocalCalloc (Length); return (Buffer); } if ((Gbl_StringCacheNext + Length) >= Gbl_StringCacheLast) { /* Allocate a new buffer */ Cache = UtLocalCalloc (sizeof (Cache->Next) + ASL_STRING_CACHE_SIZE); /* Link new cache buffer to head of list */ Cache->Next = Gbl_StringCacheList; Gbl_StringCacheList = Cache; /* Setup cache management pointers */ Gbl_StringCacheNext = Cache->Buffer; Gbl_StringCacheLast = Gbl_StringCacheNext + ASL_STRING_CACHE_SIZE; } Gbl_StringCount++; Gbl_StringSize += Length; Buffer = Gbl_StringCacheNext; Gbl_StringCacheNext += Length; return (Buffer); }
static ACPI_PARSE_OBJECT * TrGetNextNode ( void) { if (Gbl_NodeCacheNext >= Gbl_NodeCacheLast) { Gbl_NodeCacheNext = UtLocalCalloc (sizeof (ACPI_PARSE_OBJECT) * ASL_NODE_CACHE_SIZE); Gbl_NodeCacheLast = Gbl_NodeCacheNext + ASL_NODE_CACHE_SIZE; } return (Gbl_NodeCacheNext++); }
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); }
char * UtGetStringBuffer ( UINT32 Length) { char *Buffer; if ((Gbl_StringCacheNext + Length) >= Gbl_StringCacheLast) { Gbl_StringCacheNext = UtLocalCalloc (ASL_STRING_CACHE_SIZE + Length); Gbl_StringCacheLast = Gbl_StringCacheNext + ASL_STRING_CACHE_SIZE + Length; } Buffer = Gbl_StringCacheNext; Gbl_StringCacheNext += Length; return (Buffer); }
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; 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); /* Compile each locality buffer */ FieldList = *PFieldList; while (FieldList) { DtCompileBuffer (LocalityBuffer, FieldList->Value, FieldList, Localities); DtCreateSubtable (LocalityBuffer, Localities, &Subtable); DtInsertSubtable (ParentTable, Subtable); FieldList = FieldList->Next; } ACPI_FREE (LocalityBuffer); return (AE_OK); }
void PrPushInputFileStack ( FILE *InputFile, char *Filename) { PR_FILE_NODE *Fnode; Gbl_HasIncludeFiles = TRUE; /* Save the current state in an Fnode */ Fnode = UtLocalCalloc (sizeof (PR_FILE_NODE)); Fnode->File = Gbl_Files[ASL_FILE_INPUT].Handle; Fnode->Next = Gbl_InputFileList; Fnode->Filename = Gbl_Files[ASL_FILE_INPUT].Filename; Fnode->CurrentLineNumber = Gbl_CurrentLineNumber; /* Push it on the stack */ Gbl_InputFileList = Fnode; DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID "Push InputFile Stack: handle %p\n\n", Gbl_CurrentLineNumber, InputFile); /* Reset the global line count and filename */ Gbl_Files[ASL_FILE_INPUT].Filename = UtStringCacheCalloc (strlen (Filename) + 1); strcpy (Gbl_Files[ASL_FILE_INPUT].Filename, Filename); Gbl_Files[ASL_FILE_INPUT].Handle = InputFile; Gbl_CurrentLineNumber = 1; /* Emit a new #line directive for the include file */ Gbl_CurrentLineNumber = 1; FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n", 1, Filename); }
void LsPushNode ( char *Filename) { ASL_LISTING_NODE *Lnode; /* Create a new node */ Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE)); /* Initialize */ Lnode->Filename = Filename; Lnode->LineNumber = 0; /* Link (push) */ Lnode->Next = Gbl_ListingNode; Gbl_ListingNode = Lnode; }
static char * TrAmlGetNextTempName ( ACPI_PARSE_OBJECT *Op, UINT8 *TempCount) { char *TempName; if (*TempCount >= (10 + 26)) /* 0-35 valid: 0-9 and A-Z for TempName[3] */ { /* Too many temps */ AslError (ASL_ERROR, ASL_MSG_TOO_MANY_TEMPS, Op, NULL); return (NULL); } TempName = UtLocalCalloc (5); if (*TempCount < 10) /* 0-9 */ { TempName[3] = (char) (*TempCount + '0'); } else /* 10-35: A-Z */ { TempName[3] = (char) (*TempCount + ('A' - 10)); } (*TempCount)++; /* First three characters are always "_T_" */ TempName[0] = '_'; TempName[1] = 'T'; TempName[2] = '_'; return (TempName); }
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 CurrentFlagByteOffset = 0; ACPI_STATUS Status; if (!Field || !*Field) { return (AE_BAD_PARAMETER); } /* Ignore optional subtable if name does not match */ if ((Info->Flags & DT_OPTIONAL) && ACPI_STRCMP ((*Field)->Name, Info->Name)) { *RetSubtable = NULL; return (AE_OK); } Length = DtGetSubtableLength (*Field, Info); if (Length == ASL_EOF) { return (AE_ERROR); } Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE)); if (Length > 0) { 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 (Info->Opcode == ACPI_DMT_EXTRA_TEXT) { continue; } 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; } /* Maintain table offsets */ LocalField->TableOffset = Gbl_CurrentTableOffset; FieldLength = DtGetFieldLength (LocalField, Info); Gbl_CurrentTableOffset += FieldLength; 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; FlagBuffer = Buffer; CurrentFlagByteOffset = Info->Offset; break; case DT_FIELD_TYPE_FLAG: /* Individual Flag field, can be multiple bits */ if (FlagBuffer) { /* * We must increment the FlagBuffer when we have crossed * into the next flags byte within the flags field * of type DT_FIELD_TYPE_FLAGS_INTEGER. */ FlagBuffer += (Info->Offset - CurrentFlagByteOffset); CurrentFlagByteOffset = Info->Offset; DtCompileFlag (FlagBuffer, LocalField, Info); } 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 */ *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; } DtSetSubtableLength (InlineSubtable); ACPI_MEMCPY (Buffer, InlineSubtable->Buffer, FieldLength); ACPI_FREE (InlineSubtable->Buffer); ACPI_FREE (InlineSubtable); LocalField = *Field; break; case DT_FIELD_TYPE_LABEL: DtWriteFieldToListing (Buffer, LocalField, 0); LocalField = LocalField->Next; break; default: /* Normal case for most field types (Integer, String, etc.) */ DtCompileOneField (Buffer, LocalField, FieldLength, FieldType, Info->Flags); DtWriteFieldToListing (Buffer, LocalField, FieldLength); 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); }
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); }
static ACPI_STATUS DtCompileDataTable ( DT_FIELD **FieldList) { ACPI_DMTABLE_DATA *TableData; DT_SUBTABLE *Subtable; char *Signature; ACPI_TABLE_HEADER *AcpiTableHeader; ACPI_STATUS Status; DT_FIELD *RootField = *FieldList; /* Verify that we at least have a table signature and save it */ Signature = DtGetFieldValue (*FieldList); if (!Signature) { sprintf (MsgBuffer, "Expected \"%s\"", "Signature"); DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME, *FieldList, MsgBuffer); 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_VALIDATE_RSDP_SIG (Signature)) { Status = DtCompileRsdp (FieldList); return (Status); } else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_S3PT)) { Status = DtCompileS3pt (FieldList); if (ACPI_FAILURE (Status)) { return (Status); } DtSetTableLength (); return (Status); } /* * 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); /* Validate the signature via the ACPI table list */ TableData = AcpiDmGetTableData (Signature); if (!TableData || Gbl_CompileGeneric) { DtCompileGeneric ((void **) FieldList); goto FinishHeader; } /* Dispatch to per-table compile */ 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); } FinishHeader: /* Set the final table length and then the checksum */ DtSetTableLength (); AcpiTableHeader = ACPI_CAST_PTR ( ACPI_TABLE_HEADER, Gbl_RootTable->Buffer); DtSetTableChecksum (&AcpiTableHeader->Checksum); DtDumpFieldList (RootField); DtDumpSubtableList (); return (AE_OK); }
ACPI_STATUS MtMethodAnalysisWalkBegin ( ACPI_PARSE_OBJECT *Op, UINT32 Level, void *Context) { ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context; ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack; ACPI_PARSE_OBJECT *Next; UINT32 RegisterNumber; UINT32 i; char LocalName[] = "Local0"; char ArgName[] = "Arg0"; ACPI_PARSE_OBJECT *ArgNode; ACPI_PARSE_OBJECT *NextType; ACPI_PARSE_OBJECT *NextParamType; UINT8 ActualArgs = 0; switch (Op->Asl.ParseOpcode) { case PARSEOP_METHOD: TotalMethods++; /* Create and init method info */ MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO)); MethodInfo->Next = WalkInfo->MethodStack; MethodInfo->Op = Op; WalkInfo->MethodStack = MethodInfo; /* * Special handling for _PSx methods. Dependency rules (same scope): * * 1) _PS0 - One of these must exist: _PS1, _PS2, _PS3 * 2) _PS1/_PS2/_PS3: A _PS0 must exist */ if (ACPI_COMPARE_NAME (METHOD_NAME__PS0, Op->Asl.NameSeg)) { /* For _PS0, one of _PS1/_PS2/_PS3 must exist */ if ((!ApFindNameInScope (METHOD_NAME__PS1, Op)) && (!ApFindNameInScope (METHOD_NAME__PS2, Op)) && (!ApFindNameInScope (METHOD_NAME__PS3, Op))) { AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, "_PS0 requires one of _PS1/_PS2/_PS3 in same scope"); } } else if ( ACPI_COMPARE_NAME (METHOD_NAME__PS1, Op->Asl.NameSeg) || ACPI_COMPARE_NAME (METHOD_NAME__PS2, Op->Asl.NameSeg) || ACPI_COMPARE_NAME (METHOD_NAME__PS3, Op->Asl.NameSeg)) { /* For _PS1/_PS2/_PS3, a _PS0 must exist */ if (!ApFindNameInScope (METHOD_NAME__PS0, Op)) { sprintf (MsgBuffer, "%4.4s requires _PS0 in same scope", Op->Asl.NameSeg); AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, MsgBuffer); } } /* Get the name node */ Next = Op->Asl.Child; /* Get the NumArguments node */ Next = Next->Asl.Next; MethodInfo->NumArguments = (UINT8) (((UINT8) Next->Asl.Value.Integer) & 0x07); /* Get the SerializeRule and SyncLevel nodes, ignored here */ Next = Next->Asl.Next; MethodInfo->ShouldBeSerialized = (UINT8) Next->Asl.Value.Integer; Next = Next->Asl.Next; ArgNode = Next; /* Get the ReturnType node */ Next = Next->Asl.Next; NextType = Next->Asl.Child; while (NextType) { /* Get and map each of the ReturnTypes */ MethodInfo->ValidReturnTypes |= AnMapObjTypeToBtype (NextType); NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; NextType = NextType->Asl.Next; } /* Get the ParameterType node */ Next = Next->Asl.Next; NextType = Next->Asl.Child; while (NextType) { if (NextType->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) { NextParamType = NextType->Asl.Child; while (NextParamType) { MethodInfo->ValidArgTypes[ActualArgs] |= AnMapObjTypeToBtype (NextParamType); NextParamType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; NextParamType = NextParamType->Asl.Next; } } else { MethodInfo->ValidArgTypes[ActualArgs] = AnMapObjTypeToBtype (NextType); NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; ActualArgs++; } NextType = NextType->Asl.Next; } if ((MethodInfo->NumArguments) && (MethodInfo->NumArguments != ActualArgs)) { /* error: Param list did not match number of args */ } /* Allow numarguments == 0 for Function() */ if ((!MethodInfo->NumArguments) && (ActualArgs)) { MethodInfo->NumArguments = ActualArgs; ArgNode->Asl.Value.Integer |= ActualArgs; } /* * Actual arguments are initialized at method entry. * All other ArgX "registers" can be used as locals, so we * track their initialization. */ for (i = 0; i < MethodInfo->NumArguments; i++) { MethodInfo->ArgInitialized[i] = TRUE; } break; case PARSEOP_METHODCALL: if (MethodInfo && (Op->Asl.Node == MethodInfo->Op->Asl.Node)) { AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName); } break; case PARSEOP_LOCAL0: case PARSEOP_LOCAL1: case PARSEOP_LOCAL2: case PARSEOP_LOCAL3: case PARSEOP_LOCAL4: case PARSEOP_LOCAL5: case PARSEOP_LOCAL6: case PARSEOP_LOCAL7: if (!MethodInfo) { /* * Local was used outside a control method, or there was an error * in the method declaration. */ AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName); return (AE_ERROR); } RegisterNumber = (Op->Asl.AmlOpcode & 0x0007); /* * If the local is being used as a target, mark the local * initialized */ if (Op->Asl.CompileFlags & NODE_IS_TARGET) { MethodInfo->LocalInitialized[RegisterNumber] = TRUE; } /* * Otherwise, this is a reference, check if the local * has been previously initialized. * * The only operator that accepts an uninitialized value is ObjectType() */ else if ((!MethodInfo->LocalInitialized[RegisterNumber]) && (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE)) { LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30); AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName); } break; case PARSEOP_ARG0: case PARSEOP_ARG1: case PARSEOP_ARG2: case PARSEOP_ARG3: case PARSEOP_ARG4: case PARSEOP_ARG5: case PARSEOP_ARG6: if (!MethodInfo) { /* * Arg was used outside a control method, or there was an error * in the method declaration. */ AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName); return (AE_ERROR); } RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8; ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30); /* * If the Arg is being used as a target, mark the local * initialized */ if (Op->Asl.CompileFlags & NODE_IS_TARGET) { MethodInfo->ArgInitialized[RegisterNumber] = TRUE; } /* * Otherwise, this is a reference, check if the Arg * has been previously initialized. * * The only operator that accepts an uninitialized value is ObjectType() */ else if ((!MethodInfo->ArgInitialized[RegisterNumber]) && (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE)) { AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName); } /* Flag this arg if it is not a "real" argument to the method */ if (RegisterNumber >= MethodInfo->NumArguments) { AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName); } break; case PARSEOP_RETURN: if (!MethodInfo) { /* * Probably was an error in the method declaration, * no additional error here */ ACPI_WARNING ((AE_INFO, "%p, No parent method", Op)); return (AE_ERROR); } /* * A child indicates a possible return value. A simple Return or * Return() is marked with NODE_IS_NULL_RETURN by the parser so * that it is not counted as a "real" return-with-value, although * the AML code that is actually emitted is Return(0). The AML * definition of Return has a required parameter, so we are * forced to convert a null return to Return(0). */ if ((Op->Asl.Child) && (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && (!(Op->Asl.Child->Asl.CompileFlags & NODE_IS_NULL_RETURN))) { MethodInfo->NumReturnWithValue++; } else { MethodInfo->NumReturnNoValue++; } break; case PARSEOP_BREAK: case PARSEOP_CONTINUE: Next = Op->Asl.Parent; while (Next) { if (Next->Asl.ParseOpcode == PARSEOP_WHILE) { break; } Next = Next->Asl.Parent; } if (!Next) { AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL); } break; case PARSEOP_STALL: /* We can range check if the argument is an integer */ if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) && (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX)) { AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL); } break; case PARSEOP_DEVICE: Next = Op->Asl.Child; if (!ApFindNameInScope (METHOD_NAME__HID, Next) && !ApFindNameInScope (METHOD_NAME__ADR, Next)) { AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, "Device object requires a _HID or _ADR in same scope"); } break; case PARSEOP_EVENT: case PARSEOP_MUTEX: case PARSEOP_OPERATIONREGION: case PARSEOP_POWERRESOURCE: case PARSEOP_PROCESSOR: case PARSEOP_THERMALZONE: /* * The first operand is a name to be created in the namespace. * Check against the reserved list. */ i = ApCheckForPredefinedName (Op, Op->Asl.NameSeg); if (i < ACPI_VALID_RESERVED_NAME_MAX) { AslError (ASL_ERROR, ASL_MSG_RESERVED_USE, Op, Op->Asl.ExternalName); } break; case PARSEOP_NAME: /* Typecheck any predefined names statically defined with Name() */ ApCheckForPredefinedObject (Op, Op->Asl.NameSeg); /* Special typechecking for _HID */ if (!strcmp (METHOD_NAME__HID, Op->Asl.NameSeg)) { Next = Op->Asl.Child->Asl.Next; AnCheckId (Next, ASL_TYPE_HID); } /* Special typechecking for _CID */ else if (!strcmp (METHOD_NAME__CID, Op->Asl.NameSeg)) { Next = Op->Asl.Child->Asl.Next; if ((Next->Asl.ParseOpcode == PARSEOP_PACKAGE) || (Next->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)) { Next = Next->Asl.Child; while (Next) { AnCheckId (Next, ASL_TYPE_CID); Next = Next->Asl.Next; } } else { AnCheckId (Next, ASL_TYPE_CID); } } break; default: break; } /* Check for named object creation within a non-serialized method */ MtCheckNamedObjectInMethod (Op, MethodInfo); return (AE_OK); }
static ACPI_STATUS XfNamespaceLocateBegin ( ACPI_PARSE_OBJECT *Op, UINT32 Level, void *Context) { ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; ACPI_NAMESPACE_NODE *Node; ACPI_STATUS Status; ACPI_OBJECT_TYPE ObjectType; char *Path; UINT8 PassedArgs; ACPI_PARSE_OBJECT *NextOp; ACPI_PARSE_OBJECT *OwningOp; ACPI_PARSE_OBJECT *SpaceIdOp; UINT32 MinimumLength; UINT32 Offset; UINT32 FieldBitLength; UINT32 TagBitLength; UINT8 Message = 0; const ACPI_OPCODE_INFO *OpInfo; UINT32 Flags; ASL_METHOD_LOCAL *MethodLocals = NULL; ASL_METHOD_LOCAL *MethodArgs = NULL; int RegisterNumber; UINT32 i; ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op); if ((Op->Asl.AmlOpcode == AML_METHOD_OP) && Op->Asl.Node) { Node = Op->Asl.Node; /* Support for method LocalX/ArgX analysis */ if (!Node->MethodLocals) { /* Create local/arg info blocks */ MethodLocals = UtLocalCalloc ( sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_LOCALS); Node->MethodLocals = MethodLocals; MethodArgs = UtLocalCalloc ( sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_ARGS); Node->MethodArgs = MethodArgs; /* * Get the method argument count * First, get the name node */ NextOp = Op->Asl.Child; /* Get the NumArguments node */ NextOp = NextOp->Asl.Next; Node->ArgCount = (UINT8) (((UINT8) NextOp->Asl.Value.Integer) & 0x07); /* We will track all possible ArgXs */ for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) { if (i < Node->ArgCount) { /* Real Args are always "initialized" */ MethodArgs[i].Flags = ASL_ARG_INITIALIZED; } else { /* Other ArgXs can be used as locals */ MethodArgs[i].Flags = ASL_ARG_IS_LOCAL; } MethodArgs[i].Op = Op; } } } /* * If this node is the actual declaration of a name * [such as the XXXX name in "Method (XXXX)"], * we are not interested in it here. We only care about names that are * references to other objects within the namespace and the parent objects * of name declarations */ if (Op->Asl.CompileFlags & OP_IS_NAME_DECLARATION) { return_ACPI_STATUS (AE_OK); } OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); /* Check method LocalX variables */ if (OpInfo->Type == AML_TYPE_LOCAL_VARIABLE) { /* Find parent method Op */ NextOp = XfGetParentMethod (Op); if (!NextOp) { return_ACPI_STATUS (AE_OK); } /* Get method node */ Node = NextOp->Asl.Node; RegisterNumber = Op->Asl.AmlOpcode & 0x0007; /* 0x60 through 0x67 */ MethodLocals = Node->MethodLocals; if (Op->Asl.CompileFlags & OP_IS_TARGET) { /* Local is being initialized */ MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_INITIALIZED; MethodLocals[RegisterNumber].Op = Op; return_ACPI_STATUS (AE_OK); } /* Mark this Local as referenced */ MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_REFERENCED; MethodLocals[RegisterNumber].Op = Op; return_ACPI_STATUS (AE_OK); } /* Check method ArgX variables */ if (OpInfo->Type == AML_TYPE_METHOD_ARGUMENT) { /* Find parent method Op */ NextOp = XfGetParentMethod (Op); if (!NextOp) { return_ACPI_STATUS (AE_OK); } /* Get method node */ Node = NextOp->Asl.Node; /* Get Arg # */ RegisterNumber = Op->Asl.AmlOpcode - AML_ARG0; /* 0x68 through 0x6F */ MethodArgs = Node->MethodArgs; /* Mark this Arg as referenced */ MethodArgs[RegisterNumber].Flags |= ASL_ARG_REFERENCED; MethodArgs[RegisterNumber].Op = Op; if (Op->Asl.CompileFlags & OP_IS_TARGET) { /* Arg is being initialized */ MethodArgs[RegisterNumber].Flags |= ASL_ARG_INITIALIZED; } return_ACPI_STATUS (AE_OK); } /* * After method ArgX and LocalX, we are only interested in opcodes * that have an associated name */ if ((!(OpInfo->Flags & AML_NAMED)) && (!(OpInfo->Flags & AML_CREATE)) && (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) && (Op->Asl.ParseOpcode != PARSEOP_NAMESEG) && (Op->Asl.ParseOpcode != PARSEOP_METHODCALL) && (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL)) { return_ACPI_STATUS (AE_OK); } /* * One special case: CondRefOf operator - we don't care if the name exists * or not at this point, just ignore it, the point of the operator is to * determine if the name exists at runtime. */ if ((Op->Asl.Parent) && (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)) { return_ACPI_STATUS (AE_OK); } /* * We must enable the "search-to-root" for single NameSegs, but * we have to be very careful about opening up scopes */ Flags = ACPI_NS_SEARCH_PARENT; if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) || (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL)) { /* * These are name references, do not push the scope stack * for them. */ Flags |= ACPI_NS_DONT_OPEN_SCOPE; } /* Get the NamePath from the appropriate place */ if (OpInfo->Flags & AML_NAMED) { /* For nearly all NAMED operators, the name reference is the first child */ Path = Op->Asl.Child->Asl.Value.String; if (Op->Asl.AmlOpcode == AML_ALIAS_OP) { /* * ALIAS is the only oddball opcode, the name declaration * (alias name) is the second operand */ Path = Op->Asl.Child->Asl.Next->Asl.Value.String; } } else if (OpInfo->Flags & AML_CREATE) { /* Name must appear as the last parameter */ NextOp = Op->Asl.Child; while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION)) { NextOp = NextOp->Asl.Next; } Path = NextOp->Asl.Value.String; } else { Path = Op->Asl.Value.String; } ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Type=%s\n", AcpiUtGetTypeName (ObjectType))); /* * Lookup the name in the namespace. Name must exist at this point, or it * is an invalid reference. * * The namespace is also used as a lookup table for references to resource * descriptors and the fields within them. */ AslGbl_NsLookupCount++; Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType, ACPI_IMODE_EXECUTE, Flags, WalkState, &Node); if (ACPI_FAILURE (Status)) { if (Status == AE_NOT_FOUND) { /* * We didn't find the name reference by path -- we can qualify this * a little better before we print an error message */ if (strlen (Path) == ACPI_NAME_SIZE) { /* A simple, one-segment ACPI name */ if (XfObjectExists (Path)) { /* * There exists such a name, but we couldn't get to it * from this scope */ AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op, Op->Asl.ExternalName); } else { /* The name doesn't exist, period */ AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op, Op->Asl.ExternalName); } } else { /* The NamePath contains multiple NameSegs */ if ((OpInfo->Flags & AML_CREATE) || (OpInfo->ObjectType == ACPI_TYPE_LOCAL_ALIAS)) { /* * The new name is the last parameter. For the * CreateXXXXField and Alias operators */ NextOp = Op->Asl.Child; while (!(NextOp->Asl.CompileFlags & OP_IS_NAME_DECLARATION)) { NextOp = NextOp->Asl.Next; } AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, NextOp, NextOp->Asl.ExternalName); } else if (OpInfo->Flags & AML_NAMED) { /* The new name is the first parameter */ AslError (ASL_ERROR, ASL_MSG_PREFIX_NOT_EXIST, Op, Op->Asl.ExternalName); } else if (Path[0] == AML_ROOT_PREFIX) { /* Full namepath from root, the object does not exist */ AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op, Op->Asl.ExternalName); } else { /* * Generic "not found" error. Cannot determine whether it * doesn't exist or just can't be reached. However, we * can differentiate between a NameSeg vs. NamePath. */ if (strlen (Op->Asl.ExternalName) == ACPI_NAME_SIZE) { AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op, Op->Asl.ExternalName); } else { AslError (ASL_ERROR, ASL_MSG_NAMEPATH_NOT_EXIST, Op, Op->Asl.ExternalName); } } } Status = AE_OK; } return_ACPI_STATUS (Status); } /* Check for an attempt to access an object in another method */ if (!XfValidateCrossReference (Op, OpInfo, Node)) { AslError (ASL_ERROR, ASL_MSG_TEMPORARY_OBJECT, Op, Op->Asl.ExternalName); return_ACPI_STATUS (Status); } /* Object was found above, check for an illegal forward reference */ if (Op->Asl.CompileFlags & OP_NOT_FOUND_DURING_LOAD) { /* * During the load phase, this Op was flagged as a possible * illegal forward reference * * Note: Allow "forward references" from within a method to an * object that is not within any method (module-level code) */ if (!WalkState->ScopeInfo || (UtGetParentMethod (Node) && !UtNodeIsDescendantOf (WalkState->ScopeInfo->Scope.Node, UtGetParentMethod (Node)))) { AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op, Op->Asl.ExternalName); } } /* Check for a reference vs. name declaration */ if (!(OpInfo->Flags & AML_NAMED) && !(OpInfo->Flags & AML_CREATE)) { /* This node has been referenced, mark it for reference check */ Node->Flags |= ANOBJ_IS_REFERENCED; } /* Attempt to optimize the NamePath */ OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node); /* * 1) Dereference an alias (A name reference that is an alias) * Aliases are not nested, the alias always points to the final object */ if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) && (Node->Type == ACPI_TYPE_LOCAL_ALIAS)) { /* This node points back to the original PARSEOP_ALIAS */ NextOp = Node->Op; /* The first child is the alias target op */ NextOp = NextOp->Asl.Child; /* That in turn points back to original target alias node */ if (NextOp->Asl.Node) { Node = NextOp->Asl.Node; } /* Else - forward reference to alias, will be resolved later */ } /* 2) Check for a reference to a resource descriptor */ if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) || (Node->Type == ACPI_TYPE_LOCAL_RESOURCE)) { /* * This was a reference to a field within a resource descriptor. * Extract the associated field offset (either a bit or byte * offset depending on the field type) and change the named * reference into an integer for AML code generation */ Offset = Node->Value; TagBitLength = Node->Length; /* * If a field is being created, generate the length (in bits) of * the field. Note: Opcodes other than CreateXxxField and Index * can come through here. For other opcodes, we just need to * convert the resource tag reference to an integer offset. */ switch (Op->Asl.Parent->Asl.AmlOpcode) { case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */ /* * We know the length operand is an integer constant because * we know that it contains a reference to a resource * descriptor tag. */ FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer; break; case AML_CREATE_BIT_FIELD_OP: FieldBitLength = 1; break; case AML_CREATE_BYTE_FIELD_OP: case AML_INDEX_OP: FieldBitLength = 8; break; case AML_CREATE_WORD_FIELD_OP: FieldBitLength = 16; break; case AML_CREATE_DWORD_FIELD_OP: FieldBitLength = 32; break; case AML_CREATE_QWORD_FIELD_OP: FieldBitLength = 64; break; default: FieldBitLength = 0; break; } /* Check the field length against the length of the resource tag */ if (FieldBitLength) { if (TagBitLength < FieldBitLength) { Message = ASL_MSG_TAG_SMALLER; } else if (TagBitLength > FieldBitLength) { Message = ASL_MSG_TAG_LARGER; } if (Message) { sprintf (AslGbl_MsgBuffer, "Size mismatch, Tag: %u bit%s, Field: %u bit%s", TagBitLength, (TagBitLength > 1) ? "s" : "", FieldBitLength, (FieldBitLength > 1) ? "s" : ""); AslError (ASL_WARNING, Message, Op, AslGbl_MsgBuffer); } } /* Convert the BitOffset to a ByteOffset for certain opcodes */ switch (Op->Asl.Parent->Asl.AmlOpcode) { case AML_CREATE_BYTE_FIELD_OP: case AML_CREATE_WORD_FIELD_OP: case AML_CREATE_DWORD_FIELD_OP: case AML_CREATE_QWORD_FIELD_OP: case AML_INDEX_OP: Offset = ACPI_DIV_8 (Offset); break; default: break; } /* Now convert this node to an integer whose value is the field offset */ Op->Asl.AmlLength = 0; Op->Asl.ParseOpcode = PARSEOP_INTEGER; Op->Asl.Value.Integer = (UINT64) Offset; Op->Asl.CompileFlags |= OP_IS_RESOURCE_FIELD; OpcGenerateAmlOpcode (Op); } /* 3) Check for a method invocation */ else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) && (Node->Type == ACPI_TYPE_METHOD) && (Op->Asl.Parent) && (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD)) || (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)) { /* * A reference to a method within one of these opcodes is not an * invocation of the method, it is simply a reference to the method. * * September 2016: Removed DeRefOf from this list */ if ((Op->Asl.Parent) && ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF) || (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_PACKAGE) || (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)|| (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE))) { return_ACPI_STATUS (AE_OK); } /* * There are two types of method invocation: * 1) Invocation with arguments -- the parser recognizes this * as a METHODCALL. * 2) Invocation with no arguments --the parser cannot determine that * this is a method invocation, therefore we have to figure it out * here. */ if (Node->Type != ACPI_TYPE_METHOD) { sprintf (AslGbl_MsgBuffer, "%s is a %s", Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type)); AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, AslGbl_MsgBuffer); return_ACPI_STATUS (AE_OK); } /* Save the method node in the caller's op */ Op->Asl.Node = Node; if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF) { return_ACPI_STATUS (AE_OK); } /* * This is a method invocation, with or without arguments. * Count the number of arguments, each appears as a child * under the parent node */ Op->Asl.ParseOpcode = PARSEOP_METHODCALL; UtSetParseOpName (Op); PassedArgs = 0; NextOp = Op->Asl.Child; while (NextOp) { PassedArgs++; NextOp = NextOp->Asl.Next; } if (Node->Value != ASL_EXTERNAL_METHOD && Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL) { /* * Check the parsed arguments with the number expected by the * method declaration itself */ if (PassedArgs != Node->Value) { sprintf (AslGbl_MsgBuffer, "%s requires %u", Op->Asl.ExternalName, Node->Value); if (PassedArgs < Node->Value) { AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, AslGbl_MsgBuffer); } else { AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, AslGbl_MsgBuffer); } } } } /* 4) Check for an ASL Field definition */ else if ((Op->Asl.Parent) && ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD) || (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD))) { /* * Offset checking for fields. If the parent operation region has a * constant length (known at compile time), we can check fields * defined in that region against the region length. This will catch * fields and field units that cannot possibly fit within the region. * * Note: Index fields do not directly reference an operation region, * thus they are not included in this check. */ if (Op == Op->Asl.Parent->Asl.Child) { /* * This is the first child of the field node, which is * the name of the region. Get the parse node for the * region -- which contains the length of the region. */ OwningOp = Node->Op; Op->Asl.Parent->Asl.ExtraValue = ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer); /* Examine the field access width */ switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer) { case AML_FIELD_ACCESS_ANY: case AML_FIELD_ACCESS_BYTE: case AML_FIELD_ACCESS_BUFFER: default: MinimumLength = 1; break; case AML_FIELD_ACCESS_WORD: MinimumLength = 2; break; case AML_FIELD_ACCESS_DWORD: MinimumLength = 4; break; case AML_FIELD_ACCESS_QWORD: MinimumLength = 8; break; } /* * Is the region at least as big as the access width? * Note: DataTableRegions have 0 length */ if (((UINT32) OwningOp->Asl.Value.Integer) && ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength)) { AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL); } /* * Check EC/CMOS/SMBUS fields to make sure that the correct * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS) */ SpaceIdOp = OwningOp->Asl.Child->Asl.Next; switch ((UINT32) SpaceIdOp->Asl.Value.Integer) { case ACPI_ADR_SPACE_EC: case ACPI_ADR_SPACE_CMOS: case ACPI_ADR_SPACE_GPIO: if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BYTE) { AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL); } break; case ACPI_ADR_SPACE_SMBUS: case ACPI_ADR_SPACE_IPMI: case ACPI_ADR_SPACE_GSBUS: if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BUFFER) { AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL); } break; default: /* Nothing to do for other address spaces */ break; } } else { /* * This is one element of the field list. Check to make sure * that it does not go beyond the end of the parent operation region. * * In the code below: * Op->Asl.Parent->Asl.ExtraValue - Region Length (bits) * Op->Asl.ExtraValue - Field start offset (bits) * Op->Asl.Child->Asl.Value.Integer32 - Field length (bits) * Op->Asl.Child->Asl.ExtraValue - Field access width (bits) */ if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child) { XfCheckFieldRange (Op, Op->Asl.Parent->Asl.ExtraValue, Op->Asl.ExtraValue, (UINT32) Op->Asl.Child->Asl.Value.Integer, Op->Asl.Child->Asl.ExtraValue); } } } /* 5) Check for a connection object */ #if 0 else if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION) { return_ACPI_STATUS (Status); } #endif Op->Asl.Node = Node; return_ACPI_STATUS (Status); }
static ACPI_STATUS 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; BOOLEAN IsNullString = FALSE; if (!LineBuffer) { return (AE_OK); } /* All lines after "Raw Table Data" are ingored */ if (strstr (LineBuffer, ACPI_RAW_TABLE_DATA_HEADER)) { return (AE_NOT_FOUND); } Colon = strchr (LineBuffer, ':'); if (!Colon) { return (AE_OK); } 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) { 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++; /* Check for an explicit null string */ if (*End == '"') { IsNullString = TRUE; } while (*End && (*End != '"')) { End++; } End++; break; } /* * Special "comment" fields at line end, ignore them. * Note: normal slash-slash and slash-asterisk comments are * stripped already by the DtGetNextLine parser. * * TBD: Perhaps DtGetNextLine should parse the following type * of comments also. */ if (*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); /* Create a new field object only if we have a valid value field */ if ((Value && *Value) || IsNullString) { 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); } else /* Ignore this field, it has no valid data */ { ACPI_FREE (Name); ACPI_FREE (Value); } return (AE_OK); }
void AslCommonError ( UINT8 Level, UINT16 MessageId, UINT32 CurrentLineNumber, UINT32 LogicalLineNumber, UINT32 LogicalByteOffset, UINT32 Column, char *Filename, char *ExtraMessage) { char *MessageBuffer = NULL; ASL_ERROR_MSG *Enode; Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG)); if (ExtraMessage) { /* Allocate a buffer for the message and a new error node */ MessageBuffer = UtLocalCalloc (strlen (ExtraMessage) + 1); /* Keep a copy of the extra message */ ACPI_STRCPY (MessageBuffer, ExtraMessage); } /* Initialize the error node */ if (Filename) { Enode->Filename = Filename; Enode->FilenameLength = strlen (Filename); if (Enode->FilenameLength < 6) { Enode->FilenameLength = 6; } } Enode->MessageId = MessageId; Enode->Level = Level; Enode->LineNumber = CurrentLineNumber; Enode->LogicalLineNumber = LogicalLineNumber; Enode->LogicalByteOffset = LogicalByteOffset; Enode->Column = Column; Enode->Message = MessageBuffer; Enode->SourceLine = NULL; /* Add the new node to the error node list */ AeAddToErrorLog (Enode); if (Gbl_DebugFlag) { /* stderr is a file, send error to it immediately */ AePrintException (ASL_FILE_STDERR, Enode, NULL); } Gbl_ExceptionCount[Level]++; if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) { printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT); Gbl_SourceLine = 0; Gbl_NextError = Gbl_ErrorLog; CmCleanupAndExit (); exit(1); } return; }
void AslCommonError2 ( UINT8 Level, UINT16 MessageId, UINT32 LineNumber, UINT32 Column, char *SourceLine, char *Filename, char *ExtraMessage) { char *MessageBuffer = NULL; char *LineBuffer; ASL_ERROR_MSG *Enode; Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG)); if (ExtraMessage) { /* Allocate a buffer for the message and a new error node */ MessageBuffer = UtLocalCalloc (strlen (ExtraMessage) + 1); /* Keep a copy of the extra message */ ACPI_STRCPY (MessageBuffer, ExtraMessage); } LineBuffer = UtLocalCalloc (strlen (SourceLine) + 1); ACPI_STRCPY (LineBuffer, SourceLine); /* Initialize the error node */ if (Filename) { Enode->Filename = Filename; Enode->FilenameLength = strlen (Filename); if (Enode->FilenameLength < 6) { Enode->FilenameLength = 6; } } Enode->MessageId = MessageId; Enode->Level = Level; Enode->LineNumber = LineNumber; Enode->LogicalLineNumber = LineNumber; Enode->LogicalByteOffset = 0; Enode->Column = Column; Enode->Message = MessageBuffer; Enode->SourceLine = LineBuffer; /* Add the new node to the error node list */ AeAddToErrorLog (Enode); if (Gbl_DebugFlag) { /* stderr is a file, send error to it immediately */ AePrintException (ASL_FILE_STDERR, Enode, NULL); } Gbl_ExceptionCount[Level]++; }
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); }
ACPI_PARSE_OBJECT * TrCreateConstantLeafNode ( UINT32 ParseOpcode) { ACPI_PARSE_OBJECT *Op = NULL; time_t CurrentTime; char *StaticTimeString; char *TimeString; char *Path; char *Filename; switch (ParseOpcode) { case PARSEOP___LINE__: Op = TrAllocateNode (PARSEOP_INTEGER); Op->Asl.Value.Integer = Op->Asl.LineNumber; break; case PARSEOP___PATH__: Op = TrAllocateNode (PARSEOP_STRING_LITERAL); /* Op.Asl.Filename contains the full pathname to the file */ Op->Asl.Value.String = Op->Asl.Filename; break; case PARSEOP___FILE__: Op = TrAllocateNode (PARSEOP_STRING_LITERAL); /* Get the simple filename from the full path */ FlSplitInputPathname (Op->Asl.Filename, &Path, &Filename); ACPI_FREE (Path); Op->Asl.Value.String = Filename; break; case PARSEOP___DATE__: Op = TrAllocateNode (PARSEOP_STRING_LITERAL); /* Get a copy of the current time */ CurrentTime = time (NULL); StaticTimeString = ctime (&CurrentTime); TimeString = UtLocalCalloc (strlen (StaticTimeString) + 1); strcpy (TimeString, StaticTimeString); TimeString[strlen(TimeString) -1] = 0; /* Remove trailing newline */ Op->Asl.Value.String = TimeString; break; default: /* This would be an internal error */ return (NULL); } DbgPrint (ASL_PARSE_OUTPUT, "\nCreateConstantLeafNode 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 (Op->Asl.Value.Integer)); return (Op); }