static void AeInitializeTableHeader ( ACPI_TABLE_HEADER *Header, char *Signature, UINT32 Length) { ACPI_MOVE_NAME (Header->Signature, Signature); Header->Length = Length; Header->OemRevision = 0x1001; ACPI_STRNCPY (Header->OemId, "Intel", ACPI_OEM_ID_SIZE); ACPI_STRNCPY (Header->OemTableId, "AcpiExec", ACPI_OEM_TABLE_ID_SIZE); ACPI_STRNCPY (Header->AslCompilerId, "INTL", ACPI_NAME_SIZE); Header->AslCompilerRevision = 0x20131218; }
/****************************************************************************** * * FUNCTION: acpi_get_name * * PARAMETERS: Handle - Handle to be converted to a pathname * name_type - Full pathname or single segment * Buffer - Buffer for returned path * * RETURN: Pointer to a string containing the fully qualified Name. * * DESCRIPTION: This routine returns the fully qualified name associated with * the Handle parameter. This and the acpi_pathname_to_handle are * complementary functions. * ******************************************************************************/ acpi_status acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer) { acpi_status status; struct acpi_namespace_node *node; /* Parameter validation */ if (name_type > ACPI_NAME_TYPE_MAX) { return (AE_BAD_PARAMETER); } status = acpi_ut_validate_buffer(buffer); if (ACPI_FAILURE(status)) { return (status); } if (name_type == ACPI_FULL_PATHNAME) { /* Get the full pathname (From the namespace root) */ status = acpi_ns_handle_to_pathname(handle, buffer); return (status); } /* * Wants the single segment ACPI name. * Validate handle and convert to a namespace Node */ status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); if (ACPI_FAILURE(status)) { return (status); } node = acpi_ns_map_handle_to_node(handle); if (!node) { status = AE_BAD_PARAMETER; goto unlock_and_exit; } /* Validate/Allocate/Clear caller buffer */ status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH); if (ACPI_FAILURE(status)) { goto unlock_and_exit; } /* Just copy the ACPI name from the Node and zero terminate it */ ACPI_STRNCPY(buffer->pointer, acpi_ut_get_node_name(node), ACPI_NAME_SIZE); ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0; status = AE_OK; unlock_and_exit: (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); return (status); }
ACPI_STATUS AcpiOsActualTableOverride ( ACPI_TABLE_HEADER *ExistingTable, ACPI_TABLE_HEADER **NewTable) { #ifndef ACPI_EXEC_APP char TableName[ACPI_NAME_SIZE + 1]; #endif if (!ExistingTable || !NewTable) { return (AE_BAD_PARAMETER); } *NewTable = NULL; #ifdef ACPI_EXEC_APP /* This code exercises the table override mechanism in the core */ #ifdef OBSOLETE_CODE if (ACPI_COMPARE_NAME (ExistingTable->Signature, ACPI_SIG_DSDT)) { /* override DSDT with itself */ *NewTable = AcpiGbl_DbTablePtr; } #endif #else /* Construct a null-terminated string from table signature */ TableName[ACPI_NAME_SIZE] = 0; ACPI_STRNCPY (TableName, ExistingTable->Signature, ACPI_NAME_SIZE); *NewTable = OsGetTable (TableName); if (*NewTable) { AcpiOsPrintf ("%s obtained from registry, %d bytes\n", TableName, (*NewTable)->Length); } else { AcpiOsPrintf ("Could not read %s from registry\n", TableName); } #endif return (AE_OK); }
void acpi_ps_init_op(union acpi_parse_object *op, u16 opcode) { ACPI_FUNCTION_ENTRY(); op->common.descriptor_type = ACPI_DESC_TYPE_PARSER; op->common.aml_opcode = opcode; ACPI_DISASM_ONLY_MEMBERS(ACPI_STRNCPY(op->common.aml_op_name, (acpi_ps_get_opcode_info (opcode))->name, sizeof(op->common.aml_op_name))); }
void AcpiPsInitOp ( ACPI_PARSE_OBJECT *Op, UINT16 Opcode) { ACPI_FUNCTION_ENTRY (); Op->Common.DescriptorType = ACPI_DESC_TYPE_PARSER; Op->Common.AmlOpcode = Opcode; ACPI_DISASM_ONLY_MEMBERS (ACPI_STRNCPY (Op->Common.AmlOpName, (AcpiPsGetOpcodeInfo (Opcode))->Name, sizeof (Op->Common.AmlOpName))); }
ACPI_STATUS AcpiOsTableOverride ( ACPI_TABLE_HEADER *ExistingTable, ACPI_TABLE_HEADER **NewTable) { if (!ExistingTable || !NewTable) { return (AE_BAD_PARAMETER); } *NewTable = NULL; #ifdef ACPI_EXEC_APP /* Call back up to AcpiExec */ AeTableOverride (ExistingTable, NewTable); #endif #ifdef ACPI_ASL_COMPILER /* Attempt to get the table from the registry */ /* Construct a null-terminated string from table signature */ TableName[ACPI_NAME_SIZE] = 0; ACPI_STRNCPY (TableName, ExistingTable->Signature, ACPI_NAME_SIZE); *NewTable = OsGetTable (TableName); if (*NewTable) { AcpiOsPrintf ("Table [%s] obtained from registry, %u bytes\n", TableName, (*NewTable)->Length); } else { AcpiOsPrintf ("Could not read table %s from registry\n", TableName); } #endif return (AE_OK); }
static void acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length) { /* * Workaround for ID strings that have a leading asterisk. This construct * is not allowed by the ACPI specification (ID strings must be * alphanumeric), but enough existing machines have this embedded in their * ID strings that the following code is useful. */ if (*source == '*') { source++; } /* Do the actual copy */ ACPI_STRNCPY(destination, source, max_length); }
static void AcpiUtCopyIdString ( char *Destination, char *Source, ACPI_SIZE MaxLength) { /* * Workaround for ID strings that have a leading asterisk. This construct * is not allowed by the ACPI specification (ID strings must be * alphanumeric), but enough existing machines have this embedded in their * ID strings that the following code is useful. */ if (*Source == '*') { Source++; } /* Do the actual copy */ ACPI_STRNCPY (Destination, Source, MaxLength); }
void AcpiDbOpenDebugFile ( char *Name) { #ifdef ACPI_APPLICATION AcpiDbCloseDebugFile (); AcpiGbl_DebugFile = fopen (Name, "w+"); if (!AcpiGbl_DebugFile) { AcpiOsPrintf ("Could not open debug file %s\n", Name); return; } AcpiOsPrintf ("Debug output file %s opened\n", Name); ACPI_STRNCPY (AcpiGbl_DbDebugFilename, Name, sizeof (AcpiGbl_DbDebugFilename)); AcpiGbl_DbOutputToFile = TRUE; #endif }
ACPI_STATUS AeBuildLocalTables ( UINT32 TableCount, AE_TABLE_DESC *TableList) { ACPI_PHYSICAL_ADDRESS DsdtAddress = 0; UINT32 XsdtSize; AE_TABLE_DESC *NextTable; UINT32 NextIndex; ACPI_TABLE_FADT *ExternalFadt = NULL; /* * Update the table count. For DSDT, it is not put into the XSDT. For * FADT, this is already accounted for since we usually install a * local FADT. */ NextTable = TableList; while (NextTable) { if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT) || ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT)) { TableCount--; } NextTable = NextTable->Next; } XsdtSize = BASE_XSDT_SIZE + (TableCount * sizeof (UINT64)); /* Build an XSDT */ LocalXSDT = AcpiOsAllocate (XsdtSize); if (!LocalXSDT) { return (AE_NO_MEMORY); } ACPI_MEMSET (LocalXSDT, 0, XsdtSize); ACPI_STRNCPY (LocalXSDT->Header.Signature, ACPI_SIG_XSDT, 4); LocalXSDT->Header.Length = XsdtSize; LocalXSDT->Header.Revision = 1; LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalFADT); /* * Install the user tables. The DSDT must be installed in the FADT. * All other tables are installed directly into the XSDT. */ NextIndex = BASE_XSDT_TABLES; NextTable = TableList; while (NextTable) { /* * Incoming DSDT or FADT are special cases. All other tables are * just immediately installed into the XSDT. */ if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT)) { if (DsdtAddress) { printf ("Already found a DSDT, only one allowed\n"); return (AE_ALREADY_EXISTS); } /* The incoming user table is a DSDT */ DsdtAddress = ACPI_PTR_TO_PHYSADDR (NextTable->Table); } else if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT)) { ExternalFadt = ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table); LocalXSDT->TableOffsetEntry[2] = ACPI_PTR_TO_PHYSADDR (NextTable->Table); } else { /* Install the table in the XSDT */ LocalXSDT->TableOffsetEntry[NextIndex] = ACPI_PTR_TO_PHYSADDR (NextTable->Table); NextIndex++; } NextTable = NextTable->Next; } /* Build an RSDP */ ACPI_MEMSET (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP)); ACPI_MEMCPY (LocalRSDP.Signature, ACPI_SIG_RSDP, 8); ACPI_MEMCPY (LocalRSDP.OemId, "I_TEST", 6); LocalRSDP.Revision = 2; LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT); LocalRSDP.Length = sizeof (ACPI_TABLE_XSDT); /* Set checksums for both XSDT and RSDP */ LocalXSDT->Header.Checksum = (UINT8) -AcpiTbChecksum ( (void *) LocalXSDT, LocalXSDT->Header.Length); LocalRSDP.Checksum = (UINT8) -AcpiTbChecksum ( (void *) &LocalRSDP, ACPI_RSDP_CHECKSUM_LENGTH); if (!DsdtAddress) { return (AE_SUPPORT); } if (ExternalFadt) { /* * Use the external FADT, but we must update the DSDT/FACS addresses * as well as the checksum */ ExternalFadt->Dsdt = DsdtAddress; ExternalFadt->Facs = ACPI_PTR_TO_PHYSADDR (&LocalFACS); if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (&ExternalFadt->XDsdt, ExternalFadt)) { ExternalFadt->XDsdt = DsdtAddress; ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS); } /* Complete the FADT with the checksum */ ExternalFadt->Header.Checksum = 0; ExternalFadt->Header.Checksum = (UINT8) -AcpiTbChecksum ( (void *) ExternalFadt, ExternalFadt->Header.Length); } else { /* * Build a local FADT so we can test the hardware/event init */ ACPI_MEMSET (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT)); ACPI_STRNCPY (LocalFADT.Header.Signature, ACPI_SIG_FADT, 4); /* Setup FADT header and DSDT/FACS addresses */ LocalFADT.Dsdt = 0; LocalFADT.Facs = 0; LocalFADT.XDsdt = DsdtAddress; LocalFADT.XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS); LocalFADT.Header.Revision = 3; LocalFADT.Header.Length = sizeof (ACPI_TABLE_FADT); /* Miscellaneous FADT fields */ LocalFADT.Gpe0BlockLength = 16; LocalFADT.Gpe0Block = 0x00001234; LocalFADT.Gpe1BlockLength = 6; LocalFADT.Gpe1Block = 0x00005678; LocalFADT.Gpe1Base = 96; LocalFADT.Pm1EventLength = 4; LocalFADT.Pm1aEventBlock = 0x00001aaa; LocalFADT.Pm1bEventBlock = 0x00001bbb; LocalFADT.Pm1ControlLength = 2; LocalFADT.Pm1aControlBlock = 0xB0; LocalFADT.PmTimerLength = 4; LocalFADT.PmTimerBlock = 0xA0; LocalFADT.Pm2ControlBlock = 0xC0; LocalFADT.Pm2ControlLength = 1; /* Setup one example X-64 field */ LocalFADT.XPm1bEventBlock.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO; LocalFADT.XPm1bEventBlock.Address = LocalFADT.Pm1bEventBlock; LocalFADT.XPm1bEventBlock.BitWidth = (UINT8) ACPI_MUL_8 (LocalFADT.Pm1EventLength); /* Complete the FADT with the checksum */ LocalFADT.Header.Checksum = 0; LocalFADT.Header.Checksum = (UINT8) -AcpiTbChecksum ( (void *) &LocalFADT, LocalFADT.Header.Length); } /* Build a FACS */ ACPI_MEMSET (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS)); ACPI_STRNCPY (LocalFACS.Signature, ACPI_SIG_FACS, 4); LocalFACS.Length = sizeof (ACPI_TABLE_FACS); LocalFACS.GlobalLock = 0x11AA0011; return (AE_OK); }
acpi_status acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc, union acpi_operand_object **result_desc) { union acpi_operand_object *return_desc; u8 *new_buf; ACPI_FUNCTION_TRACE_PTR(ex_convert_to_buffer, obj_desc); switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { case ACPI_TYPE_BUFFER: /* No conversion necessary */ *result_desc = obj_desc; return_ACPI_STATUS(AE_OK); case ACPI_TYPE_INTEGER: /* * Create a new Buffer object. * Need enough space for one integer */ return_desc = acpi_ut_create_buffer_object(acpi_gbl_integer_byte_width); if (!return_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Copy the integer to the buffer, LSB first */ new_buf = return_desc->buffer.pointer; ACPI_MEMCPY(new_buf, &obj_desc->integer.value, acpi_gbl_integer_byte_width); break; case ACPI_TYPE_STRING: /* * Create a new Buffer object * Size will be the string length * * NOTE: Add one to the string length to include the null terminator. * The ACPI spec is unclear on this subject, but there is existing * ASL/AML code that depends on the null being transferred to the new * buffer. */ return_desc = acpi_ut_create_buffer_object((acpi_size) obj_desc->string. length + 1); if (!return_desc) { return_ACPI_STATUS(AE_NO_MEMORY); } /* Copy the string to the buffer */ new_buf = return_desc->buffer.pointer; ACPI_STRNCPY((char *)new_buf, (char *)obj_desc->string.pointer, obj_desc->string.length); break; default: return_ACPI_STATUS(AE_TYPE); } /* Mark buffer initialized */ return_desc->common.flags |= AOPOBJ_DATA_VALID; *result_desc = return_desc; return_ACPI_STATUS(AE_OK); }
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); }
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_STATUS AcpiTbFindTable ( char *Signature, char *OemId, char *OemTableId, UINT32 *TableIndex) { UINT32 i; ACPI_STATUS Status; ACPI_TABLE_HEADER Header; ACPI_FUNCTION_TRACE (TbFindTable); /* Normalize the input strings */ ACPI_MEMSET (&Header, 0, sizeof (ACPI_TABLE_HEADER)); ACPI_MOVE_NAME (Header.Signature, Signature); ACPI_STRNCPY (Header.OemId, OemId, ACPI_OEM_ID_SIZE); ACPI_STRNCPY (Header.OemTableId, OemTableId, ACPI_OEM_TABLE_ID_SIZE); /* Search for the table */ for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i) { if (ACPI_MEMCMP (&(AcpiGbl_RootTableList.Tables[i].Signature), Header.Signature, ACPI_NAME_SIZE)) { /* Not the requested table */ continue; } /* Table with matching signature has been found */ if (!AcpiGbl_RootTableList.Tables[i].Pointer) { /* Table is not currently mapped, map it */ Status = AcpiTbVerifyTable (&AcpiGbl_RootTableList.Tables[i]); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } if (!AcpiGbl_RootTableList.Tables[i].Pointer) { continue; } } /* Check for table match on all IDs */ if (!ACPI_MEMCMP (AcpiGbl_RootTableList.Tables[i].Pointer->Signature, Header.Signature, ACPI_NAME_SIZE) && (!OemId[0] || !ACPI_MEMCMP (AcpiGbl_RootTableList.Tables[i].Pointer->OemId, Header.OemId, ACPI_OEM_ID_SIZE)) && (!OemTableId[0] || !ACPI_MEMCMP (AcpiGbl_RootTableList.Tables[i].Pointer->OemTableId, Header.OemTableId, ACPI_OEM_TABLE_ID_SIZE))) { *TableIndex = i; ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "Found table [%4.4s]\n", Header.Signature)); return_ACPI_STATUS (AE_OK); } } return_ACPI_STATUS (AE_NOT_FOUND); }
acpi_status acpi_tb_find_table(char *signature, char *oem_id, char *oem_table_id, u32 *table_index) { u32 i; acpi_status status; struct acpi_table_header header; ACPI_FUNCTION_TRACE(tb_find_table); /* */ ACPI_MEMSET(&header, 0, sizeof(struct acpi_table_header)); ACPI_STRNCPY(header.signature, signature, ACPI_NAME_SIZE); ACPI_STRNCPY(header.oem_id, oem_id, ACPI_OEM_ID_SIZE); ACPI_STRNCPY(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE); /* */ for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { if (ACPI_MEMCMP(&(acpi_gbl_root_table_list.tables[i].signature), header.signature, ACPI_NAME_SIZE)) { /* */ continue; } /* */ if (!acpi_gbl_root_table_list.tables[i].pointer) { /* */ status = acpi_tb_verify_table(&acpi_gbl_root_table_list. tables[i]); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (!acpi_gbl_root_table_list.tables[i].pointer) { continue; } } /* */ if (!ACPI_MEMCMP (acpi_gbl_root_table_list.tables[i].pointer->signature, header.signature, ACPI_NAME_SIZE) && (!oem_id[0] || !ACPI_MEMCMP (acpi_gbl_root_table_list. tables[i].pointer-> oem_id, header.oem_id, ACPI_OEM_ID_SIZE)) && (!oem_table_id[0] || !ACPI_MEMCMP(acpi_gbl_root_table_list.tables[i]. pointer->oem_table_id, header.oem_table_id, ACPI_OEM_TABLE_ID_SIZE))) { *table_index = i; ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Found table [%4.4s]\n", header.signature)); return_ACPI_STATUS(AE_OK); } } return_ACPI_STATUS(AE_NOT_FOUND); }
ACPI_STATUS AcpiExConvertToBuffer ( ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **ResultDesc) { ACPI_OPERAND_OBJECT *ReturnDesc; UINT8 *NewBuf; ACPI_FUNCTION_TRACE_PTR (ExConvertToBuffer, ObjDesc); switch (ObjDesc->Common.Type) { case ACPI_TYPE_BUFFER: /* No conversion necessary */ *ResultDesc = ObjDesc; return_ACPI_STATUS (AE_OK); case ACPI_TYPE_INTEGER: /* * Create a new Buffer object. * Need enough space for one integer */ ReturnDesc = AcpiUtCreateBufferObject (AcpiGbl_IntegerByteWidth); if (!ReturnDesc) { return_ACPI_STATUS (AE_NO_MEMORY); } /* Copy the integer to the buffer, LSB first */ NewBuf = ReturnDesc->Buffer.Pointer; ACPI_MEMCPY (NewBuf, &ObjDesc->Integer.Value, AcpiGbl_IntegerByteWidth); break; case ACPI_TYPE_STRING: /* * Create a new Buffer object * Size will be the string length * * NOTE: Add one to the string length to include the null terminator. * The ACPI spec is unclear on this subject, but there is existing * ASL/AML code that depends on the null being transferred to the new * buffer. */ ReturnDesc = AcpiUtCreateBufferObject ( (ACPI_SIZE) ObjDesc->String.Length + 1); if (!ReturnDesc) { return_ACPI_STATUS (AE_NO_MEMORY); } /* Copy the string to the buffer */ NewBuf = ReturnDesc->Buffer.Pointer; ACPI_STRNCPY ((char *) NewBuf, (char *) ObjDesc->String.Pointer, ObjDesc->String.Length); break; default: return_ACPI_STATUS (AE_TYPE); } /* Mark buffer initialized */ ReturnDesc->Common.Flags |= AOPOBJ_DATA_VALID; *ResultDesc = ReturnDesc; return_ACPI_STATUS (AE_OK); }
ACPI_STATUS AcpiDsCreateOperand ( ACPI_WALK_STATE *WalkState, ACPI_PARSE_OBJECT *Arg, UINT32 ArgIndex) { ACPI_STATUS Status = AE_OK; char *NameString; UINT32 NameLength; ACPI_OPERAND_OBJECT *ObjDesc; ACPI_PARSE_OBJECT *ParentOp; UINT16 Opcode; ACPI_INTERPRETER_MODE InterpreterMode; const ACPI_OPCODE_INFO *OpInfo; ACPI_FUNCTION_TRACE_PTR (DsCreateOperand, Arg); /* A valid name must be looked up in the namespace */ if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) && (Arg->Common.Value.String) && !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK)) { ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", Arg)); /* Get the entire name string from the AML stream */ Status = AcpiExGetNameString (ACPI_TYPE_ANY, Arg->Common.Value.Buffer, &NameString, &NameLength); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* All prefixes have been handled, and the name is in NameString */ /* * Special handling for BufferField declarations. This is a deferred * opcode that unfortunately defines the field name as the last * parameter instead of the first. We get here when we are performing * the deferred execution, so the actual name of the field is already * in the namespace. We don't want to attempt to look it up again * because we may be executing in a different scope than where the * actual opcode exists. */ if ((WalkState->DeferredNode) && (WalkState->DeferredNode->Type == ACPI_TYPE_BUFFER_FIELD) && (ArgIndex == (UINT32) ((WalkState->Opcode == AML_CREATE_FIELD_OP) ? 3 : 2))) { ObjDesc = ACPI_CAST_PTR ( ACPI_OPERAND_OBJECT, WalkState->DeferredNode); Status = AE_OK; } else /* All other opcodes */ { /* * Differentiate between a namespace "create" operation * versus a "lookup" operation (IMODE_LOAD_PASS2 vs. * IMODE_EXECUTE) in order to support the creation of * namespace objects during the execution of control methods. */ ParentOp = Arg->Common.Parent; OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode); if ((OpInfo->Flags & AML_NSNODE) && (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) && (ParentOp->Common.AmlOpcode != AML_REGION_OP) && (ParentOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP)) { /* Enter name into namespace if not found */ InterpreterMode = ACPI_IMODE_LOAD_PASS2; } else { /* Return a failure if name not found */ InterpreterMode = ACPI_IMODE_EXECUTE; } Status = AcpiNsLookup (WalkState->ScopeInfo, NameString, ACPI_TYPE_ANY, InterpreterMode, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, WalkState, ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc)); /* * The only case where we pass through (ignore) a NOT_FOUND * error is for the CondRefOf opcode. */ if (Status == AE_NOT_FOUND) { if (ParentOp->Common.AmlOpcode == AML_COND_REF_OF_OP) { /* * For the Conditional Reference op, it's OK if * the name is not found; We just need a way to * indicate this to the interpreter, set the * object to the root */ ObjDesc = ACPI_CAST_PTR ( ACPI_OPERAND_OBJECT, AcpiGbl_RootNode); Status = AE_OK; } else if (ParentOp->Common.AmlOpcode == AML_EXTERNAL_OP) { /* TBD: May only be temporary */ ObjDesc = AcpiUtCreateStringObject ((ACPI_SIZE) NameLength); ACPI_STRNCPY (ObjDesc->String.Pointer, NameString, NameLength); Status = AE_OK; } else { /* * We just plain didn't find it -- which is a * very serious error at this point */ Status = AE_AML_NAME_NOT_FOUND; } } if (ACPI_FAILURE (Status)) { ACPI_ERROR_NAMESPACE (NameString, Status); } } /* Free the namestring created above */ ACPI_FREE (NameString); /* Check status from the lookup */ if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Put the resulting object onto the current object stack */ Status = AcpiDsObjStackPush (ObjDesc, WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc, WalkState)); } else { /* Check for null name case */ if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) && !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK)) { /* * If the name is null, this means that this is an * optional result parameter that was not specified * in the original ASL. Create a Zero Constant for a * placeholder. (Store to a constant is a Noop.) */ Opcode = AML_ZERO_OP; /* Has no arguments! */ ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Null namepath: Arg=%p\n", Arg)); } else { Opcode = Arg->Common.AmlOpcode; } /* Get the object type of the argument */ OpInfo = AcpiPsGetOpcodeInfo (Opcode); if (OpInfo->ObjectType == ACPI_TYPE_INVALID) { return_ACPI_STATUS (AE_NOT_IMPLEMENTED); } if ((OpInfo->Flags & AML_HAS_RETVAL) || (Arg->Common.Flags & ACPI_PARSEOP_IN_STACK)) { ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Argument previously created, already stacked\n")); ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject ( WalkState->Operands [WalkState->NumOperands - 1], WalkState)); /* * Use value that was already previously returned * by the evaluation of this argument */ Status = AcpiDsResultPop (&ObjDesc, WalkState); if (ACPI_FAILURE (Status)) { /* * Only error is underflow, and this indicates * a missing or null operand! */ ACPI_EXCEPTION ((AE_INFO, Status, "Missing or null operand")); return_ACPI_STATUS (Status); } } else { /* Create an ACPI_INTERNAL_OBJECT for the argument */ ObjDesc = AcpiUtCreateInternalObject (OpInfo->ObjectType); if (!ObjDesc) { return_ACPI_STATUS (AE_NO_MEMORY); } /* Initialize the new object */ Status = AcpiDsInitObjectFromOp ( WalkState, Arg, Opcode, &ObjDesc); if (ACPI_FAILURE (Status)) { AcpiUtDeleteObjectDesc (ObjDesc); return_ACPI_STATUS (Status); } } /* Put the operand object on the object stack */ Status = AcpiDsObjStackPush (ObjDesc, WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } ACPI_DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc, WalkState)); } return_ACPI_STATUS (AE_OK); }
static void OpcParsePrintf ( ACPI_PARSE_OBJECT *Op, ACPI_PARSE_OBJECT *DestOp) { char *Format; char *StartPosition = NULL; ACPI_PARSE_OBJECT *ArgNode; ACPI_PARSE_OBJECT *NextNode; UINT32 StringLength = 0; char *NewString; BOOLEAN StringToProcess = FALSE; ACPI_PARSE_OBJECT *NewOp; /* Get format string */ Format = ACPI_CAST_PTR (char, Op->Asl.Child->Asl.Value.String); ArgNode = Op->Asl.Child->Asl.Next; /* * Detach argument list so that we can use a NULL check to distinguish * the first concatenation operation we need to make */ Op->Asl.Child = NULL; for (; *Format; ++Format) { if (*Format != '%') { if (!StringToProcess) { /* Mark the beginning of a string */ StartPosition = Format; StringToProcess = TRUE; } ++StringLength; continue; } /* Save string, if any, to new string object and concat it */ if (StringToProcess) { NewString = UtStringCacheCalloc (StringLength + 1); ACPI_STRNCPY (NewString, StartPosition, StringLength); NewOp = TrAllocateNode (PARSEOP_STRING_LITERAL); NewOp->Asl.Value.String = NewString; NewOp->Asl.AmlOpcode = AML_STRING_OP; NewOp->Asl.AcpiBtype = ACPI_BTYPE_STRING; OpcCreateConcatenateNode(Op, NewOp); StringLength = 0; StringToProcess = FALSE; } ++Format; /* * We have a format parameter and will need an argument to go * with it */ if (!ArgNode || ArgNode->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) { AslError(ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, NULL); return; } /* * We do not support sub-specifiers of printf (flags, width, * precision, length). For specifiers we only support %x/%X for * hex or %s for strings. Also, %o for generic "acpi object". */ switch (*Format) { case 's': if (ArgNode->Asl.ParseOpcode != PARSEOP_STRING_LITERAL) { AslError(ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgNode, "String required"); return; } NextNode = ArgNode->Asl.Next; ArgNode->Asl.Next = NULL; OpcCreateConcatenateNode(Op, ArgNode); ArgNode = NextNode; continue; case 'X': case 'x': case 'o': NextNode = ArgNode->Asl.Next; ArgNode->Asl.Next = NULL; /* * Append an empty string if the first argument is * not a string. This will implicitly conver the 2nd * concat source to a string per the ACPI specification. */ if (!Op->Asl.Child) { NewOp = TrAllocateNode (PARSEOP_STRING_LITERAL); NewOp->Asl.Value.String = ""; NewOp->Asl.AmlOpcode = AML_STRING_OP; NewOp->Asl.AcpiBtype = ACPI_BTYPE_STRING; OpcCreateConcatenateNode(Op, NewOp); } OpcCreateConcatenateNode(Op, ArgNode); ArgNode = NextNode; break; default: AslError(ASL_ERROR, ASL_MSG_INVALID_OPERAND, Op, "Unrecognized format specifier"); continue; } } /* Process any remaining string */ if (StringToProcess) { NewString = UtStringCacheCalloc (StringLength + 1); ACPI_STRNCPY (NewString, StartPosition, StringLength); NewOp = TrAllocateNode (PARSEOP_STRING_LITERAL); NewOp->Asl.Value.String = NewString; NewOp->Asl.AcpiBtype = ACPI_BTYPE_STRING; NewOp->Asl.AmlOpcode = AML_STRING_OP; OpcCreateConcatenateNode(Op, NewOp); } /* * If we get here and there's no child node then Format * was an empty string. Just make a no op. */ if (!Op->Asl.Child) { Op->Asl.ParseOpcode = PARSEOP_NOOP; AslError(ASL_WARNING, ASL_MSG_NULL_STRING, Op, "Converted to NOOP"); return; } /* Check for erroneous extra arguments */ if (ArgNode && ArgNode->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) { AslError(ASL_WARNING, ASL_MSG_ARG_COUNT_HI, ArgNode, "Extra arguments ignored"); } /* Change Op to a Store */ Op->Asl.ParseOpcode = PARSEOP_STORE; Op->Common.AmlOpcode = AML_STORE_OP; Op->Asl.CompileFlags = 0; /* Disable further optimization */ Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST; UtSetParseOpName (Op); /* Set Store destination */ Op->Asl.Child->Asl.Next = DestOp; }
acpi_status acpi_tb_find_table(char *signature, char *oem_id, char *oem_table_id, u32 *table_index) { u32 i; acpi_status status; struct acpi_table_header header; ACPI_FUNCTION_TRACE(tb_find_table); /* Normalize the input strings */ ACPI_MEMSET(&header, 0, sizeof(struct acpi_table_header)); ACPI_STRNCPY(header.signature, signature, ACPI_NAME_SIZE); ACPI_STRNCPY(header.oem_id, oem_id, ACPI_OEM_ID_SIZE); ACPI_STRNCPY(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE); /* Search for the table */ for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) { if (ACPI_MEMCMP(&(acpi_gbl_root_table_list.tables[i].signature), header.signature, ACPI_NAME_SIZE)) { /* Not the requested table */ continue; } /* Table with matching signature has been found */ if (!acpi_gbl_root_table_list.tables[i].pointer) { /* Table is not currently mapped, map it */ status = acpi_tb_verify_table(&acpi_gbl_root_table_list. tables[i]); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } if (!acpi_gbl_root_table_list.tables[i].pointer) { continue; } } /* Check for table match on all IDs */ if (!ACPI_MEMCMP (acpi_gbl_root_table_list.tables[i].pointer->signature, header.signature, ACPI_NAME_SIZE) && (!oem_id[0] || !ACPI_MEMCMP (acpi_gbl_root_table_list. tables[i].pointer-> oem_id, header.oem_id, ACPI_OEM_ID_SIZE)) && (!oem_table_id[0] || !ACPI_MEMCMP(acpi_gbl_root_table_list.tables[i]. pointer->oem_table_id, header.oem_table_id, ACPI_OEM_TABLE_ID_SIZE))) { *table_index = i; ACPI_DEBUG_PRINT((ACPI_DB_TABLES, "Found table [%4.4s]\n", header.signature)); return_ACPI_STATUS(AE_OK); } } return_ACPI_STATUS(AE_NOT_FOUND); }
static ACPI_STATUS AcpiUtTrackAllocation ( ACPI_DEBUG_MEM_BLOCK *Allocation, ACPI_SIZE Size, UINT8 AllocType, UINT32 Component, const char *Module, UINT32 Line) { ACPI_MEMORY_LIST *MemList; ACPI_DEBUG_MEM_BLOCK *Element; ACPI_STATUS Status = AE_OK; ACPI_FUNCTION_TRACE_PTR (UtTrackAllocation, Allocation); MemList = AcpiGbl_GlobalList; Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* * Search list for this address to make sure it is not already on the list. * This will catch several kinds of problems. */ Element = AcpiUtFindAllocation (Allocation); if (Element) { ACPI_ERROR ((AE_INFO, "UtTrackAllocation: Allocation already present in list! (%p)", Allocation)); ACPI_ERROR ((AE_INFO, "Element %p Address %p", Element, Allocation)); goto UnlockAndExit; } /* Fill in the instance data. */ Allocation->Size = (UINT32) Size; Allocation->AllocType = AllocType; Allocation->Component = Component; Allocation->Line = Line; ACPI_STRNCPY (Allocation->Module, Module, ACPI_MAX_MODULE_NAME); Allocation->Module[ACPI_MAX_MODULE_NAME-1] = 0; /* Insert at list head */ if (MemList->ListHead) { ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = Allocation; } Allocation->Next = MemList->ListHead; Allocation->Previous = NULL; MemList->ListHead = Allocation; UnlockAndExit: Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY); return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiGetName ( ACPI_HANDLE Handle, UINT32 NameType, ACPI_BUFFER *Buffer) { ACPI_STATUS Status; ACPI_NAMESPACE_NODE *Node; /* Parameter validation */ if (NameType > ACPI_NAME_TYPE_MAX) { return (AE_BAD_PARAMETER); } Status = AcpiUtValidateBuffer (Buffer); if (ACPI_FAILURE (Status)) { return (Status); } if (NameType == ACPI_FULL_PATHNAME) { /* Get the full pathname (From the namespace root) */ Status = AcpiNsHandleToPathname (Handle, Buffer); return (Status); } /* * Wants the single segment ACPI name. * Validate handle and convert to a namespace Node */ Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); if (ACPI_FAILURE (Status)) { return (Status); } Node = AcpiNsMapHandleToNode (Handle); if (!Node) { Status = AE_BAD_PARAMETER; goto UnlockAndExit; } /* Validate/Allocate/Clear caller buffer */ Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH); if (ACPI_FAILURE (Status)) { goto UnlockAndExit; } /* Just copy the ACPI name from the Node and zero terminate it */ ACPI_STRNCPY (Buffer->Pointer, AcpiUtGetNodeName (Node), ACPI_NAME_SIZE); ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0; Status = AE_OK; UnlockAndExit: (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); return (Status); }