diff options
author | Jung-uk Kim <jkim@FreeBSD.org> | 2020-03-26 21:13:14 +0000 |
---|---|---|
committer | Jung-uk Kim <jkim@FreeBSD.org> | 2020-03-26 21:13:14 +0000 |
commit | a117a0a6c82c5a5030040bd2b75704a1366741d6 (patch) | |
tree | 29eb5a43c2eeafbdaada31b2f23a7b96f623b260 /source/tools/acpiexec/aeinitfile.c | |
parent | aa36cd6999384cddbfa0d030bcdd44e8bf9c7779 (diff) | |
download | src-a117a0a6c82c5a5030040bd2b75704a1366741d6.tar.gz src-a117a0a6c82c5a5030040bd2b75704a1366741d6.zip |
Notes
Diffstat (limited to 'source/tools/acpiexec/aeinitfile.c')
-rw-r--r-- | source/tools/acpiexec/aeinitfile.c | 220 |
1 files changed, 137 insertions, 83 deletions
diff --git a/source/tools/acpiexec/aeinitfile.c b/source/tools/acpiexec/aeinitfile.c index 0813c8739db4..ce758ed1b9fb 100644 --- a/source/tools/acpiexec/aeinitfile.c +++ b/source/tools/acpiexec/aeinitfile.c @@ -151,24 +151,17 @@ #include "aecommon.h" #include "acdispat.h" +#include "acnamesp.h" + #define _COMPONENT ACPI_TOOLS ACPI_MODULE_NAME ("aeinitfile") -/* Local prototypes */ - -static void -AeEnterInitFileEntry ( - INIT_FILE_ENTRY InitEntry, - ACPI_WALK_STATE *WalkState); - - #define AE_FILE_BUFFER_SIZE 512 static char LineBuffer[AE_FILE_BUFFER_SIZE]; static char NameBuffer[AE_FILE_BUFFER_SIZE]; -static char ValueBuffer[AE_FILE_BUFFER_SIZE]; static FILE *InitFile; @@ -211,23 +204,23 @@ AeOpenInitializationFile ( * RETURN: None * * DESCRIPTION: Read the initialization file and perform all namespace - * initializations. AcpiGbl_InitEntries will be used for region - * field initialization. + * initializations. AcpiGbl_InitEntries will be used for all + * object initialization. * * NOTE: The format of the file is multiple lines, each of format: - * <ACPI-pathname> <Integer Value> + * <ACPI-pathname> <New Value> * *****************************************************************************/ -void -AeProcessInitFile( +ACPI_STATUS +AeProcessInitFile ( void) { ACPI_WALK_STATE *WalkState; UINT64 idx; - ACPI_STATUS Status; + ACPI_STATUS Status = AE_OK; char *Token; - char *ObjectBuffer; + char *ValueBuffer; char *TempNameBuffer; ACPI_OBJECT_TYPE Type; ACPI_OBJECT TempObject; @@ -235,13 +228,14 @@ AeProcessInitFile( if (!InitFile) { - return; + return (AE_OK); } /* Create needed objects to be reused for each init entry */ WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL); NameBuffer[0] = '\\'; + NameBuffer[1] = 0; while (fgets (LineBuffer, AE_FILE_BUFFER_SIZE, InitFile) != NULL) { @@ -249,12 +243,20 @@ AeProcessInitFile( } rewind (InitFile); + /* + * Allocate and populate the Gbl_InitEntries array + */ AcpiGbl_InitEntries = - AcpiOsAllocate (sizeof (INIT_FILE_ENTRY) * AcpiGbl_InitFileLineCount); + AcpiOsAllocateZeroed (sizeof (INIT_FILE_ENTRY) * AcpiGbl_InitFileLineCount); for (idx = 0; fgets (LineBuffer, AE_FILE_BUFFER_SIZE, InitFile); ++idx) { - TempNameBuffer = AcpiDbGetNextToken (LineBuffer, &Token, &Type); + if (!TempNameBuffer) + { + AcpiGbl_InitEntries[idx].Name = NULL; + continue; + } + if (LineBuffer[0] == '\\') { strcpy (NameBuffer, TempNameBuffer); @@ -266,48 +268,67 @@ AeProcessInitFile( strcpy (NameBuffer + 1, TempNameBuffer); } + AcpiNsNormalizePathname (NameBuffer); AcpiGbl_InitEntries[idx].Name = AcpiOsAllocateZeroed (strnlen (NameBuffer, AE_FILE_BUFFER_SIZE) + 1); - strcpy (AcpiGbl_InitEntries[idx].Name, NameBuffer); - ObjectBuffer = AcpiDbGetNextToken (Token, &Token, &Type); + ValueBuffer = AcpiDbGetNextToken (Token, &Token, &Type); + if (!ValueBuffer) + { + AcpiGbl_InitEntries[idx].Value = NULL; + continue; + } + + AcpiGbl_InitEntries[idx].Value = + AcpiOsAllocateZeroed (strnlen (ValueBuffer, AE_FILE_BUFFER_SIZE) + 1); + strcpy (AcpiGbl_InitEntries[idx].Value, ValueBuffer); if (Type == ACPI_TYPE_FIELD_UNIT) { - Status = AcpiDbConvertToObject (ACPI_TYPE_BUFFER, ObjectBuffer, + Status = AcpiDbConvertToObject (ACPI_TYPE_BUFFER, ValueBuffer, &TempObject); } else { - Status = AcpiDbConvertToObject (Type, ObjectBuffer, &TempObject); + Status = AcpiDbConvertToObject (Type, ValueBuffer, &TempObject); + } + + if (ACPI_FAILURE (Status)) + { + AcpiOsPrintf ("%s[%s]: %s\n", NameBuffer, AcpiUtGetTypeName (Type), + AcpiFormatException (Status)); + goto CleanupAndExit; } Status = AcpiUtCopyEobjectToIobject (&TempObject, &AcpiGbl_InitEntries[idx].ObjDesc); - if (Type == ACPI_TYPE_BUFFER || Type == ACPI_TYPE_FIELD_UNIT) + /* Cleanup the external object created by DbConvertToObject above */ + + if (ACPI_SUCCESS (Status)) { - ACPI_FREE (TempObject.Buffer.Pointer); + if (Type == ACPI_TYPE_BUFFER || Type == ACPI_TYPE_FIELD_UNIT) + { + ACPI_FREE (TempObject.Buffer.Pointer); + } + else if (Type == ACPI_TYPE_PACKAGE) + { + AcpiDbDeleteObjects (1, &TempObject); + } } - - if (ACPI_FAILURE (Status)) + else { - AcpiOsPrintf ("%s %s\n", ValueBuffer, + AcpiOsPrintf ("%s[%s]: %s\n", NameBuffer, AcpiUtGetTypeName (Type), AcpiFormatException (Status)); goto CleanupAndExit; } /* - * Special case for field units. Field units are dependent on the - * parent region. This parent region has yet to be created so defer the - * initialization until the dispatcher. For all other types, initialize - * the namespace node with the value found in the init file. + * Initialize the namespace node with the value found in the init file. */ - if (Type != ACPI_TYPE_FIELD_UNIT) - { - AeEnterInitFileEntry (AcpiGbl_InitEntries[idx], WalkState); - } + AcpiOsPrintf ("Namespace object init from file: %16s, Value \"%s\", Type %s\n", + AcpiGbl_InitEntries[idx].Name, AcpiGbl_InitEntries[idx].Value, AcpiUtGetTypeName (Type)); } /* Cleanup */ @@ -315,97 +336,130 @@ AeProcessInitFile( CleanupAndExit: fclose (InitFile); AcpiDsDeleteWalkState (WalkState); + return (Status); } /****************************************************************************** * - * FUNCTION: AeInitFileEntry - * - * PARAMETERS: InitEntry - Entry of the init file - * WalkState - Used for the Store operation + * FUNCTION: AeLookupInitFileEntry * - * RETURN: None + * PARAMETERS: Pathname - AML namepath in external format + * ObjDesc - Where the object is returned if it exists * - * DESCRIPTION: Perform initialization of a single namespace object + * RETURN: Status. AE_OK if a match was found * - * Note: namespace of objects are limited to integers and region - * fields units of 8 bytes at this time. + * DESCRIPTION: Search the init file for a particular name and its value. * *****************************************************************************/ -static void -AeEnterInitFileEntry ( - INIT_FILE_ENTRY InitEntry, - ACPI_WALK_STATE *WalkState) +ACPI_STATUS +AeLookupInitFileEntry ( + char *Pathname, + ACPI_OPERAND_OBJECT **ObjDesc) { - char *Pathname = InitEntry.Name; - ACPI_OPERAND_OBJECT *ObjDesc = InitEntry.ObjDesc; - ACPI_NAMESPACE_NODE *NewNode; - ACPI_STATUS Status; + UINT32 i; + ACPI_FUNCTION_TRACE (AeLookupInitFileEntry); - Status = AcpiNsLookup (NULL, Pathname, ObjDesc->Common.Type, - ACPI_IMODE_LOAD_PASS2, ACPI_NS_ERROR_IF_FOUND | ACPI_NS_NO_UPSEARCH | - ACPI_NS_EARLY_INIT, NULL, &NewNode); - if (ACPI_FAILURE (Status)) + ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Lookup: %s\n", Pathname)); + + if (!AcpiGbl_InitEntries) { - ACPI_EXCEPTION ((AE_INFO, Status, - "While creating name from namespace initialization file: %s", - Pathname)); - return; + return (AE_NOT_FOUND); } - /* Store pointer to value descriptor in the Node */ + AcpiNsNormalizePathname (Pathname); - Status = AcpiNsAttachObject (NewNode, ObjDesc, - ObjDesc->Common.Type); - if (ACPI_FAILURE (Status)) + for (i = 0; i < AcpiGbl_InitFileLineCount; ++i) { - ACPI_EXCEPTION ((AE_INFO, Status, - "While attaching object to node from namespace initialization file: %s", - Pathname)); - return; + if (AcpiGbl_InitEntries[i].Name && + !strcmp (AcpiGbl_InitEntries[i].Name, Pathname)) + { + *ObjDesc = AcpiGbl_InitEntries[i].ObjDesc; + AcpiGbl_InitEntries[i].IsUsed = TRUE; + ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Found match: %s, %p\n", Pathname, *ObjDesc)); + return_ACPI_STATUS (AE_OK); + } } - /* Remove local reference to the object */ + ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "No match found: %s\n", Pathname)); + return_ACPI_STATUS (AE_NOT_FOUND); +} + + +/****************************************************************************** + * + * FUNCTION: AeDisplayUnusedInitFileItems + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Display all init file items that have not been referenced + * (i.e., items that have not been found in the namespace). + * + *****************************************************************************/ + +void +AeDisplayUnusedInitFileItems ( + void) +{ + UINT32 i; + + + if (!AcpiGbl_InitEntries) + { + return; + } - AcpiUtRemoveReference (ObjDesc); + for (i = 0; i < AcpiGbl_InitFileLineCount; ++i) + { + if (AcpiGbl_InitEntries[i].Name && + !AcpiGbl_InitEntries[i].IsUsed) + { + AcpiOsPrintf ("Init file entry not found in namespace " + "(or is a non-data type): %s\n", + AcpiGbl_InitEntries[i].Name); + } + } } /****************************************************************************** * - * FUNCTION: AeLookupInitFileEntry + * FUNCTION: AeDeleteInitFileList * - * PARAMETERS: Pathname - AML namepath in external format - * ValueString - value of the namepath if it exitst + * PARAMETERS: None * * RETURN: None * - * DESCRIPTION: Search the init file for a particular name and its value. + * DESCRIPTION: Delete the global namespace initialization file data * *****************************************************************************/ -ACPI_STATUS -AeLookupInitFileEntry ( - char *Pathname, - ACPI_OPERAND_OBJECT **ObjDesc) +void +AeDeleteInitFileList ( + void) { UINT32 i; + if (!AcpiGbl_InitEntries) { - return AE_NOT_FOUND; + return; } for (i = 0; i < AcpiGbl_InitFileLineCount; ++i) { - if (!strcmp(AcpiGbl_InitEntries[i].Name, Pathname)) + + if ((AcpiGbl_InitEntries[i].ObjDesc) && (AcpiGbl_InitEntries[i].Value)) { - *ObjDesc = AcpiGbl_InitEntries[i].ObjDesc; - return AE_OK; + /* Remove one reference on the object (and all subobjects) */ + + AcpiUtRemoveReference (AcpiGbl_InitEntries[i].ObjDesc); } } - return AE_NOT_FOUND; + + AcpiOsFree (AcpiGbl_InitEntries); } |