Added memory allocation macros

date	2001.06.29.20.10.00;	author rmoore1;	state Exp;
This commit is contained in:
aystarik 2005-06-29 17:56:00 +00:00
parent aeb464b076
commit 9c4c364e52

View File

@ -1,8 +1,8 @@
/******************************************************************************
*
* Module Name: amstorob - AML Interpreter object store support, store to object
* $Revision: 1.28 $
* Module Name: exstorob - AML Interpreter object store support, store to object
* $Revision: 1.33 $
*
*****************************************************************************/
@ -115,7 +115,7 @@
*
*****************************************************************************/
#define __AMSTOROB_C__
#define __EXSTOROB_C__
#include "acpi.h"
#include "acparser.h"
@ -127,12 +127,12 @@
#define _COMPONENT ACPI_EXECUTER
MODULE_NAME ("amstorob")
MODULE_NAME ("exstorob")
/*******************************************************************************
*
* FUNCTION: AcpiAmlCopyBufferToBuffer
* FUNCTION: AcpiExCopyBufferToBuffer
*
* PARAMETERS: SourceDesc - Source object to copy
* TargetDesc - Destination object of the copy
@ -144,7 +144,7 @@
******************************************************************************/
ACPI_STATUS
AcpiAmlCopyBufferToBuffer (
AcpiExCopyBufferToBuffer (
ACPI_OPERAND_OBJECT *SourceDesc,
ACPI_OPERAND_OBJECT *TargetDesc)
{
@ -164,7 +164,7 @@ AcpiAmlCopyBufferToBuffer (
*/
if (TargetDesc->Buffer.Length == 0)
{
TargetDesc->Buffer.Pointer = AcpiCmAllocate (Length);
TargetDesc->Buffer.Pointer = ACPI_MEM_ALLOCATE (Length);
if (!TargetDesc->Buffer.Pointer)
{
return (AE_NO_MEMORY);
@ -181,8 +181,8 @@ AcpiAmlCopyBufferToBuffer (
{
/* Clear existing buffer and copy in the new one */
MEMSET(TargetDesc->Buffer.Pointer, 0, TargetDesc->Buffer.Length);
MEMCPY(TargetDesc->Buffer.Pointer, Buffer, Length);
MEMSET (TargetDesc->Buffer.Pointer, 0, TargetDesc->Buffer.Length);
MEMCPY (TargetDesc->Buffer.Pointer, Buffer, Length);
}
else
@ -190,10 +190,10 @@ AcpiAmlCopyBufferToBuffer (
/*
* Truncate the source, copy only what will fit
*/
MEMCPY(TargetDesc->Buffer.Pointer, Buffer, TargetDesc->Buffer.Length);
MEMCPY (TargetDesc->Buffer.Pointer, Buffer, TargetDesc->Buffer.Length);
DEBUG_PRINT (ACPI_INFO,
("AmlCopyBufferToBuffer: Truncating src buffer from %X to %X\n",
("ExCopyBufferToBuffer: Truncating src buffer from %X to %X\n",
Length, TargetDesc->Buffer.Length));
}
@ -203,7 +203,7 @@ AcpiAmlCopyBufferToBuffer (
/*******************************************************************************
*
* FUNCTION: AcpiAmlCopyStringToString
* FUNCTION: AcpiExCopyStringToString
*
* PARAMETERS: SourceDesc - Source object to copy
* TargetDesc - Destination object of the copy
@ -215,7 +215,7 @@ AcpiAmlCopyBufferToBuffer (
******************************************************************************/
ACPI_STATUS
AcpiAmlCopyStringToString (
AcpiExCopyStringToString (
ACPI_OPERAND_OBJECT *SourceDesc,
ACPI_OPERAND_OBJECT *TargetDesc)
{
@ -236,8 +236,8 @@ AcpiAmlCopyStringToString (
{
/* Clear old string and copy in the new one */
MEMSET(TargetDesc->String.Pointer, 0, TargetDesc->String.Length);
MEMCPY(TargetDesc->String.Pointer, Buffer, Length);
MEMSET (TargetDesc->String.Pointer, 0, TargetDesc->String.Length);
MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
}
else
@ -252,10 +252,10 @@ AcpiAmlCopyStringToString (
/*
* Only free if not a pointer into the DSDT
*/
AcpiCmFree(TargetDesc->String.Pointer);
ACPI_MEM_FREE (TargetDesc->String.Pointer);
}
TargetDesc->String.Pointer = AcpiCmAllocate (Length + 1);
TargetDesc->String.Pointer = ACPI_MEM_ALLOCATE (Length + 1);
if (!TargetDesc->String.Pointer)
{
return (AE_NO_MEMORY);
@ -263,321 +263,10 @@ AcpiAmlCopyStringToString (
TargetDesc->String.Length = Length;
MEMCPY(TargetDesc->String.Pointer, Buffer, Length);
MEMCPY (TargetDesc->String.Pointer, Buffer, Length);
}
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: AcpiAmlCopyIntegerToIndexField
*
* PARAMETERS: SourceDesc - Source object to copy
* TargetDesc - Destination object of the copy
*
* RETURN: Status
*
* DESCRIPTION: Write an Integer to an Index Field
*
******************************************************************************/
ACPI_STATUS
AcpiAmlCopyIntegerToIndexField (
ACPI_OPERAND_OBJECT *SourceDesc,
ACPI_OPERAND_OBJECT *TargetDesc)
{
ACPI_STATUS Status;
BOOLEAN Locked;
/*
* Get the global lock if needed
*/
Locked = AcpiAmlAcquireGlobalLock (TargetDesc->IndexField.LockRule);
/*
* Set Index value to select proper Data register
* perform the update (Set index)
*/
Status = AcpiAmlAccessNamedField (ACPI_WRITE,
TargetDesc->IndexField.Index,
&TargetDesc->IndexField.Value,
sizeof (TargetDesc->IndexField.Value));
if (ACPI_SUCCESS (Status))
{
/* SetIndex was successful, next set Data value */
Status = AcpiAmlAccessNamedField (ACPI_WRITE,
TargetDesc->IndexField.Data,
&SourceDesc->Integer.Value,
sizeof (SourceDesc->Integer.Value));
DEBUG_PRINT (ACPI_INFO,
("AmlCopyIntegerToIndexField: IndexField: set data returned %s\n",
AcpiCmFormatException (Status)));
}
else
{
DEBUG_PRINT (ACPI_INFO,
("AmlCopyIntegerToIndexField: IndexField: set index returned %s\n",
AcpiCmFormatException (Status)));
}
/*
* Release global lock if we acquired it earlier
*/
AcpiAmlReleaseGlobalLock (Locked);
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiAmlCopyIntegerToBankField
*
* PARAMETERS: SourceDesc - Source object to copy
* TargetDesc - Destination object of the copy
*
* RETURN: Status
*
* DESCRIPTION: Write an Integer to a Bank Field
*
******************************************************************************/
ACPI_STATUS
AcpiAmlCopyIntegerToBankField (
ACPI_OPERAND_OBJECT *SourceDesc,
ACPI_OPERAND_OBJECT *TargetDesc)
{
ACPI_STATUS Status;
BOOLEAN Locked;
/*
* Get the global lock if needed
*/
Locked = AcpiAmlAcquireGlobalLock (TargetDesc->IndexField.LockRule);
/*
* Set Bank value to select proper Bank
* Perform the update (Set Bank Select)
*/
Status = AcpiAmlAccessNamedField (ACPI_WRITE,
TargetDesc->BankField.BankSelect,
&TargetDesc->BankField.Value,
sizeof (TargetDesc->BankField.Value));
if (ACPI_SUCCESS (Status))
{
/* Set bank select successful, set data value */
Status = AcpiAmlAccessNamedField (ACPI_WRITE,
TargetDesc->BankField.BankSelect,
&SourceDesc->BankField.Value,
sizeof (SourceDesc->BankField.Value));
}
else
{
DEBUG_PRINT (ACPI_INFO,
("AmlCopyIntegerToBankField: BankField: set bank returned %s\n",
AcpiCmFormatException (Status)));
}
/*
* Release global lock if we acquired it earlier
*/
AcpiAmlReleaseGlobalLock (Locked);
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiAmlCopyDataToNamedField
*
* PARAMETERS: SourceDesc - Source object to copy
* Node - Destination Namespace node
*
* RETURN: Status
*
* DESCRIPTION: Copy raw data to a Named Field. No implicit conversion
* is performed on the source object
*
******************************************************************************/
ACPI_STATUS
AcpiAmlCopyDataToNamedField (
ACPI_OPERAND_OBJECT *SourceDesc,
ACPI_NAMESPACE_NODE *Node)
{
ACPI_STATUS Status;
BOOLEAN Locked;
UINT32 Length;
UINT8 *Buffer;
/*
* Named fields (CreateXxxField) - We don't perform any conversions on the
* source operand, just use the raw data
*/
switch (SourceDesc->Common.Type)
{
case ACPI_TYPE_INTEGER:
Buffer = (UINT8 *) &SourceDesc->Integer.Value;
Length = sizeof (SourceDesc->Integer.Value);
break;
case ACPI_TYPE_BUFFER:
Buffer = (UINT8 *) SourceDesc->Buffer.Pointer;
Length = SourceDesc->Buffer.Length;
break;
case ACPI_TYPE_STRING:
Buffer = (UINT8 *) SourceDesc->String.Pointer;
Length = SourceDesc->String.Length;
break;
default:
return (AE_TYPE);
}
/*
* Get the global lock if needed before the update
* TBD: not needed!
*/
Locked = AcpiAmlAcquireGlobalLock (SourceDesc->Field.LockRule);
Status = AcpiAmlAccessNamedField (ACPI_WRITE,
Node, Buffer, Length);
AcpiAmlReleaseGlobalLock (Locked);
return (Status);
}
/*******************************************************************************
*
* FUNCTION: AcpiAmlCopyIntegerToFieldUnit
*
* PARAMETERS: SourceDesc - Source object to copy
* TargetDesc - Destination object of the copy
*
* RETURN: Status
*
* DESCRIPTION: Write an Integer to a Field Unit.
*
******************************************************************************/
ACPI_STATUS
AcpiAmlCopyIntegerToFieldUnit (
ACPI_OPERAND_OBJECT *SourceDesc,
ACPI_OPERAND_OBJECT *TargetDesc)
{
ACPI_STATUS Status = AE_OK;
UINT8 *Location = NULL;
UINT32 Mask;
UINT32 NewValue;
BOOLEAN Locked = FALSE;
FUNCTION_TRACE ("AmlCopyIntegerToFieldUnit");
/*
* If the Field Buffer and Index have not been previously evaluated,
* evaluate them and save the results.
*/
if (!(TargetDesc->Common.Flags & AOPOBJ_DATA_VALID))
{
Status = AcpiDsGetFieldUnitArguments (TargetDesc);
if (ACPI_FAILURE (Status))
{
return_ACPI_STATUS (Status);
}
}
if ((!TargetDesc->FieldUnit.Container ||
ACPI_TYPE_BUFFER != TargetDesc->FieldUnit.Container->Common.Type))
{
DEBUG_PRINT (ACPI_ERROR,
("Null Container or wrong type: %p", TargetDesc->FieldUnit.Container));
if (TargetDesc->FieldUnit.Container)
{
DEBUG_PRINT_RAW (ACPI_ERROR, (" Type %X",
TargetDesc->FieldUnit.Container->Common.Type));
}
DEBUG_PRINT_RAW (ACPI_ERROR, ("\n"));
return_ACPI_STATUS (AE_AML_INTERNAL);
}
/*
* Get the global lock if needed
*/
Locked = AcpiAmlAcquireGlobalLock (TargetDesc->FieldUnit.LockRule);
/*
* TBD: [Unhandled] REMOVE this limitation
* Make sure the operation is within the limits of our implementation
* this is not a Spec limitation!!
*/
if (TargetDesc->FieldUnit.Length + TargetDesc->FieldUnit.BitOffset > 32)
{
DEBUG_PRINT (ACPI_ERROR,
("AmlCopyIntegerToFieldUnit: FieldUnit: Implementation limitation - Field exceeds UINT32\n"));
AcpiAmlReleaseGlobalLock (Locked);
return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
}
/* Field location is (base of buffer) + (byte offset) */
Location = TargetDesc->FieldUnit.Container->Buffer.Pointer
+ TargetDesc->FieldUnit.Offset;
/*
* Construct Mask with 1 bits where the field is,
* 0 bits elsewhere
*/
Mask = ((UINT32) 1 << TargetDesc->FieldUnit.Length) - ((UINT32)1
<< TargetDesc->FieldUnit.BitOffset);
DEBUG_PRINT (TRACE_EXEC,
("** Store %lx in buffer %p byte %ld bit %X width %d addr %p mask %08lx\n",
SourceDesc->Integer.Value,
TargetDesc->FieldUnit.Container->Buffer.Pointer,
TargetDesc->FieldUnit.Offset, TargetDesc->FieldUnit.BitOffset,
TargetDesc->FieldUnit.Length,Location, Mask));
/* Zero out the field in the buffer */
MOVE_UNALIGNED32_TO_32 (&NewValue, Location);
NewValue &= ~Mask;
/*
* Shift and mask the new value into position,
* and or it into the buffer.
*/
NewValue |= (SourceDesc->Integer.Value << TargetDesc->FieldUnit.BitOffset) &
Mask;
/* Store back the value */
MOVE_UNALIGNED32_TO_32 (Location, &NewValue);
AcpiAmlReleaseGlobalLock (Locked);
DEBUG_PRINT (TRACE_EXEC, ("New Field value %08lx\n", NewValue));
return_ACPI_STATUS (AE_OK);
}