FreeBSD/sys/contrib/dev/acpica/components/executer/exconvrt.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiExConvertToInteger
 *
 * PARAMETERS:  ObjDesc         - Object to be converted. Must be an
 *                                Integer, Buffer, or String
 *              ResultDesc      - Where the new Integer object is returned
 *              Flags           - Used for string conversion
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Convert an ACPI Object to an integer.
 *
 ******************************************************************************/
AcpiExConvertToInteger
PARAMETERS:  ObjDesc         - Object to be converted. Must be an
Integer, Buffer, or String
ResultDesc      - Where the new Integer object is returned
Flags           - Used for string conversion

Status

Convert an ACPI Object to an integer.
AcpiExConvertToInteger PARAMETERS : ObjDesc - Object to be converted . Must be an Integer Buffer or String ResultDesc - Where the new Integer object is returned Flags - Used for string conversion Status Convert an ACPI Object to an integer .
ACPI_STATUS
AcpiExConvertToInteger (
    ACPI_OPERAND_OBJECT     *ObjDesc,
    ACPI_OPERAND_OBJECT     **ResultDesc,
    UINT32                  Flags)
{
    ACPI_OPERAND_OBJECT     *ReturnDesc;
    UINT8                   *Pointer;
    UINT64                  Result;
    UINT32                  i;
    UINT32                  Count;
    ACPI_STATUS             Status;
    ACPI_FUNCTION_TRACE_PTR (ExConvertToInteger, ObjDesc);
    switch (ObjDesc->Common.Type)
    {
    case ACPI_TYPE_INTEGER:
        *ResultDesc = ObjDesc;
        return_ACPI_STATUS (AE_OK);
    case ACPI_TYPE_BUFFER:
    case ACPI_TYPE_STRING:
        Pointer = ObjDesc->Buffer.Pointer;
        Count   = ObjDesc->Buffer.Length;
        break;
    default:
        return_ACPI_STATUS (AE_TYPE);
    }
    Result = 0;
    switch (ObjDesc->Common.Type)
    {
    case ACPI_TYPE_STRING:
        Status = AcpiUtStrtoul64 ((char *) Pointer, Flags,
            AcpiGbl_IntegerByteWidth, &Result);
        if (ACPI_FAILURE (Status))
        {
            return_ACPI_STATUS (Status);
        }
        break;
    case ACPI_TYPE_BUFFER:
        if (!Count)
        {
            return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
        }
        if (Count > AcpiGbl_IntegerByteWidth)
        {
            Count = AcpiGbl_IntegerByteWidth;
        }
        for (i = 0; i < Count; i++)
        {
            Result |= (((UINT64) Pointer[i]) << (i * 8));
        }
        break;
    default:
        break;
    }
    ReturnDesc = AcpiUtCreateIntegerObject (Result);
    if (!ReturnDesc)
    {
        return_ACPI_STATUS (AE_NO_MEMORY);
    }
    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
        ACPI_FORMAT_UINT64 (Result)));
    (void) AcpiExTruncateFor32bitTable (ReturnDesc);
    *ResultDesc = ReturnDesc;
    return_ACPI_STATUS (AE_OK);
}
ACPI_STATUS AcpiExConvertToInteger ( ACPI_OPERAND_OBJECT * ObjDesc , ACPI_OPERAND_OBJECT * * ResultDesc , UINT32 Flags ) { ACPI_OPERAND_OBJECT * ReturnDesc ; UINT8 * Pointer ; UINT64 Result ; UINT32 i ; UINT32 Count ; ACPI_STATUS Status ; ACPI_FUNCTION_TRACE_PTR ( ExConvertToInteger , ObjDesc ) ; switch ( ObjDesc -> Common . Type ) { case ACPI_TYPE_INTEGER : * ResultDesc = ObjDesc ; return_ACPI_STATUS ( AE_OK ) ; case ACPI_TYPE_BUFFER : case ACPI_TYPE_STRING : Pointer = ObjDesc -> Buffer . Pointer ; Count = ObjDesc -> Buffer . Length ; break ; default : return_ACPI_STATUS ( AE_TYPE ) ; } Result = 0 ; switch ( ObjDesc -> Common . Type ) { case ACPI_TYPE_STRING : Status = AcpiUtStrtoul64 ( ( char * ) Pointer , Flags , AcpiGbl_IntegerByteWidth , & Result ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } break ; case ACPI_TYPE_BUFFER : if ( ! Count ) { return_ACPI_STATUS ( AE_AML_BUFFER_LIMIT ) ; } if ( Count > AcpiGbl_IntegerByteWidth ) { Count = AcpiGbl_IntegerByteWidth ; } for ( i = 0 ; i < Count ; i ++ ) { Result |= ( ( ( UINT64 ) Pointer [ i ] ) << ( i * 8 ) ) ; } break ; default : break ; } ReturnDesc = AcpiUtCreateIntegerObject ( Result ) ; if ( ! ReturnDesc ) { return_ACPI_STATUS ( AE_NO_MEMORY ) ; } ACPI_DEBUG_PRINT ( ( ACPI_DB_EXEC , " \n " , ACPI_FORMAT_UINT64 ( Result ) ) ) ; ( void ) AcpiExTruncateFor32bitTable ( ReturnDesc ) ; * ResultDesc = ReturnDesc ; return_ACPI_STATUS ( AE_OK ) ; }
FUNCTION:    AcpiExConvertToInteger
 PARAMETERS:  ObjDesc         - Object to be converted.
FUNCTION : AcpiExConvertToInteger PARAMETERS : ObjDesc - Object to be converted .
/* No conversion necessary */ /* Note: Takes advantage of common buffer/string fields */ /*
     * Convert the buffer/string to an integer. Note that both buffers and
     * strings are treated as raw data - we don't convert ascii to hex for
     * strings.
     *
     * There are two terminating conditions for the loop:
     * 1) The size of an integer has been reached, or
     * 2) The end of the buffer or string has been reached
     */ /* String conversion is different than Buffer conversion */ /*
         * Convert string to an integer - for most cases, the string must be
         * hexadecimal as per the ACPI specification. The only exception (as
         * of ACPI 3.0) is that the ToInteger() operator allows both decimal
         * and hexadecimal strings (hex prefixed with "0x").
         */ /* Check for zero-length buffer */ /* Transfer no more than an integer's worth of data */ /*
         * Convert buffer to an integer - we simply grab enough raw data
         * from the buffer to fill an integer
         */ /*
             * Get next byte and shift it into the Result.
             * Little endian is used, meaning that the first byte of the buffer
             * is the LSB of the integer
             */ /* No other types can get here */ /* Create a new integer */ /* Save the Result */