FreeBSD/sys/contrib/dev/acpica/components/debugger/dbtest.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiDbTestBufferType
 *
 * PARAMETERS:  Node                - Parent NS node for the object
 *              BitLength           - Actual length of the object.
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Test read/write for an Buffer-valued object. Performs a
 *              write/read/compare of an arbitrary new value, then performs
 *              a write/read/compare of the original value.
 *
 ******************************************************************************/
AcpiDbTestBufferType
PARAMETERS:  Node                - Parent NS node for the object
BitLength           - Actual length of the object.

Status

Test read/write for an Buffer-valued object. Performs a
write/read/compare of an arbitrary new value, then performs
a write/read/compare of the original value.
AcpiDbTestBufferType PARAMETERS : Node - Parent NS node for the object BitLength - Actual length of the object . Status Test read / write for an Buffer - valued object . Performs a write / read / compare of an arbitrary new value then performs a write / read / compare of the original value .
static ACPI_STATUS
AcpiDbTestBufferType (
    ACPI_NAMESPACE_NODE     *Node,
    UINT32                  BitLength)
{
    ACPI_OBJECT             *Temp1 = NULL;
    ACPI_OBJECT             *Temp2 = NULL;
    ACPI_OBJECT             *Temp3 = NULL;
    UINT8                   *Buffer;
    ACPI_OBJECT             WriteValue;
    ACPI_STATUS             Status;
    UINT32                  ByteLength;
    UINT32                  i;
    UINT8                   ExtraBits;
    ByteLength = ACPI_ROUND_BITS_UP_TO_BYTES (BitLength);
    if (ByteLength == 0)
    {
        AcpiOsPrintf (" Ignoring zero length buffer");
        return (AE_OK);
    }
    Buffer = ACPI_ALLOCATE_ZEROED (ByteLength);
    if (!Buffer)
    {
        return (AE_NO_MEMORY);
    }
    Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp1);
    if (ACPI_FAILURE (Status))
    {
        goto Exit;
    }
    AcpiOsPrintf (" (%4.4X/%3.3X)", BitLength, Temp1->Buffer.Length);
    for (i = 0; ((i < 4) && (i < ByteLength)); i++)
    {
        AcpiOsPrintf (" %2.2X", Temp1->Buffer.Pointer[i]);
    }
    AcpiOsPrintf ("...  ");
    memset (Buffer, BUFFER_FILL_VALUE, ByteLength);
    ExtraBits = BitLength % 8;
    if (ExtraBits)
    {
        Buffer [ByteLength - 1] = ACPI_MASK_BITS_ABOVE (ExtraBits);
    }
    WriteValue.Type = ACPI_TYPE_BUFFER;
    WriteValue.Buffer.Length = ByteLength;
    WriteValue.Buffer.Pointer = Buffer;
    Status = AcpiDbWriteToObject (Node, &WriteValue);
    if (ACPI_FAILURE (Status))
    {
        goto Exit;
    }
    Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp2);
    if (ACPI_FAILURE (Status))
    {
        goto Exit;
    }
    if (memcmp (Temp2->Buffer.Pointer, Buffer, ByteLength))
    {
        AcpiOsPrintf (" MISMATCH 2: New buffer value");
    }
    WriteValue.Buffer.Length = ByteLength;
    WriteValue.Buffer.Pointer = Temp1->Buffer.Pointer;
    Status = AcpiDbWriteToObject (Node, &WriteValue);
    if (ACPI_FAILURE (Status))
    {
        goto Exit;
    }
    Status = AcpiDbReadFromObject (Node, ACPI_TYPE_BUFFER, &Temp3);
    if (ACPI_FAILURE (Status))
    {
        goto Exit;
    }
    if (memcmp (Temp1->Buffer.Pointer,
            Temp3->Buffer.Pointer, ByteLength))
    {
        AcpiOsPrintf (" MISMATCH 3: While restoring original buffer");
    }
Exit:
    ACPI_FREE (Buffer);
    if (Temp1) {AcpiOsFree (Temp1);}
    if (Temp2) {AcpiOsFree (Temp2);}
    if (Temp3) {AcpiOsFree (Temp3);}
    return (Status);
}
static ACPI_STATUS AcpiDbTestBufferType ( ACPI_NAMESPACE_NODE * Node , UINT32 BitLength ) { ACPI_OBJECT * Temp1 = NULL ; ACPI_OBJECT * Temp2 = NULL ; ACPI_OBJECT * Temp3 = NULL ; UINT8 * Buffer ; ACPI_OBJECT WriteValue ; ACPI_STATUS Status ; UINT32 ByteLength ; UINT32 i ; UINT8 ExtraBits ; ByteLength = ACPI_ROUND_BITS_UP_TO_BYTES ( BitLength ) ; if ( ByteLength == 0 ) { AcpiOsPrintf ( " " ) ; return ( AE_OK ) ; } Buffer = ACPI_ALLOCATE_ZEROED ( ByteLength ) ; if ( ! Buffer ) { return ( AE_NO_MEMORY ) ; } Status = AcpiDbReadFromObject ( Node , ACPI_TYPE_BUFFER , & Temp1 ) ; if ( ACPI_FAILURE ( Status ) ) { goto Exit ; } AcpiOsPrintf ( " " , BitLength , Temp1 -> Buffer . Length ) ; for ( i = 0 ; ( ( i < 4 ) && ( i < ByteLength ) ) ; i ++ ) { AcpiOsPrintf ( " " , Temp1 -> Buffer . Pointer [ i ] ) ; } AcpiOsPrintf ( " " ) ; memset ( Buffer , BUFFER_FILL_VALUE , ByteLength ) ; ExtraBits = BitLength % 8 ; if ( ExtraBits ) { Buffer [ ByteLength - 1 ] = ACPI_MASK_BITS_ABOVE ( ExtraBits ) ; } WriteValue . Type = ACPI_TYPE_BUFFER ; WriteValue . Buffer . Length = ByteLength ; WriteValue . Buffer . Pointer = Buffer ; Status = AcpiDbWriteToObject ( Node , & WriteValue ) ; if ( ACPI_FAILURE ( Status ) ) { goto Exit ; } Status = AcpiDbReadFromObject ( Node , ACPI_TYPE_BUFFER , & Temp2 ) ; if ( ACPI_FAILURE ( Status ) ) { goto Exit ; } if ( memcmp ( Temp2 -> Buffer . Pointer , Buffer , ByteLength ) ) { AcpiOsPrintf ( " " ) ; } WriteValue . Buffer . Length = ByteLength ; WriteValue . Buffer . Pointer = Temp1 -> Buffer . Pointer ; Status = AcpiDbWriteToObject ( Node , & WriteValue ) ; if ( ACPI_FAILURE ( Status ) ) { goto Exit ; } Status = AcpiDbReadFromObject ( Node , ACPI_TYPE_BUFFER , & Temp3 ) ; if ( ACPI_FAILURE ( Status ) ) { goto Exit ; } if ( memcmp ( Temp1 -> Buffer . Pointer , Temp3 -> Buffer . Pointer , ByteLength ) ) { AcpiOsPrintf ( " " ) ; } Exit : ACPI_FREE ( Buffer ) ; if ( Temp1 ) { AcpiOsFree ( Temp1 ) ; } if ( Temp2 ) { AcpiOsFree ( Temp2 ) ; } if ( Temp3 ) { AcpiOsFree ( Temp3 ) ; } return ( Status ) ; }
FUNCTION:    AcpiDbTestBufferType
 PARAMETERS:  Node                - Parent NS node for the object
              BitLength           - Actual length of the object.
FUNCTION : AcpiDbTestBufferType PARAMETERS : Node - Parent NS node for the object BitLength - Actual length of the object .
/* Allocate a local buffer */ /* Read the original value */ /* Emit a few bytes of the buffer */ /*
     * Write a new value.
     *
     * Handle possible extra bits at the end of the buffer. Can
     * happen for FieldUnits larger than an integer, but the bit
     * count is not an integral number of bytes. Zero out the
     * unused bits.
     */ /* Ensure that we can read back the new value */ /* Write back the original value */ /* Ensure that we can read back the original value */