deps/acpica/source/components/utilities/utresrc.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiUtValidateResource
 *
 * PARAMETERS:  WalkState           - Current walk info
 *              Aml                 - Pointer to the raw AML resource descriptor
 *              ReturnIndex         - Where the resource index is returned. NULL
 *                                    if the index is not required.
 *
 * RETURN:      Status, and optionally the Index into the global resource tables
 *
 * DESCRIPTION: Validate an AML resource descriptor by checking the Resource
 *              Type and Resource Length. Returns an index into the global
 *              resource information/dispatch tables for later use.
 *
 ******************************************************************************/
AcpiUtValidateResource
PARAMETERS:  WalkState           - Current walk info
Aml                 - Pointer to the raw AML resource descriptor
ReturnIndex         - Where the resource index is returned. NULL
if the index is not required.

Status, and optionally the Index into the global resource tables

Validate an AML resource descriptor by checking the Resource
Type and Resource Length. Returns an index into the global
resource information/dispatch tables for later use.
AcpiUtValidateResource PARAMETERS : WalkState - Current walk info Aml - Pointer to the raw AML resource descriptor ReturnIndex - Where the resource index is returned . NULL if the index is not required . Status and optionally the Index into the global resource tables Validate an AML resource descriptor by checking the Resource Type and Resource Length . Returns an index into the global resource information / dispatch tables for later use .
ACPI_STATUS
AcpiUtValidateResource (
    ACPI_WALK_STATE         *WalkState,
    void                    *Aml,
    UINT8                   *ReturnIndex)
{
    AML_RESOURCE            *AmlResource;
    UINT8                   ResourceType;
    UINT8                   ResourceIndex;
    ACPI_RS_LENGTH          ResourceLength;
    ACPI_RS_LENGTH          MinimumResourceLength;
    ACPI_FUNCTION_ENTRY ();
    ResourceType = ACPI_GET8 (Aml);
    if (ResourceType & ACPI_RESOURCE_NAME_LARGE)
    {
        if (ResourceType > ACPI_RESOURCE_NAME_LARGE_MAX)
        {
            goto InvalidResource;
        }
        ResourceIndex = (UINT8) (ResourceType - 0x70);
    }
    else
    {
        ResourceIndex = (UINT8)
            ((ResourceType & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3);
    }
    if (!AcpiGbl_ResourceTypes[ResourceIndex])
    {
        goto InvalidResource;
    }
    ResourceLength = AcpiUtGetResourceLength (Aml);
    MinimumResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
    switch (AcpiGbl_ResourceTypes[ResourceIndex])
    {
    case ACPI_FIXED_LENGTH:
        if (ResourceLength != MinimumResourceLength)
        {
            goto BadResourceLength;
        }
        break;
    case ACPI_VARIABLE_LENGTH:
        if (ResourceLength < MinimumResourceLength)
        {
            goto BadResourceLength;
        }
        break;
    case ACPI_SMALL_VARIABLE_LENGTH:
        if ((ResourceLength > MinimumResourceLength) ||
            (ResourceLength < (MinimumResourceLength - 1)))
        {
            goto BadResourceLength;
        }
        break;
    default:
        goto InvalidResource;
    }
    AmlResource = ACPI_CAST_PTR (AML_RESOURCE, Aml);
    if (ResourceType == ACPI_RESOURCE_NAME_SERIAL_BUS)
    {
        if ((AmlResource->CommonSerialBus.Type == 0) ||
            (AmlResource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE))
        {
            if (WalkState)
            {
                ACPI_ERROR ((AE_INFO,
                    "Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X",
                    AmlResource->CommonSerialBus.Type));
            }
            return (AE_AML_INVALID_RESOURCE_TYPE);
        }
    }
    if (ReturnIndex)
    {
        *ReturnIndex = ResourceIndex;
    }
    return (AE_OK);
InvalidResource:
    if (WalkState)
    {
        ACPI_ERROR ((AE_INFO,
            "Invalid/unsupported resource descriptor: Type 0x%2.2X",
            ResourceType));
    }
    return (AE_AML_INVALID_RESOURCE_TYPE);
BadResourceLength:
    if (WalkState)
    {
        ACPI_ERROR ((AE_INFO,
            "Invalid resource descriptor length: Type "
            "0x%2.2X, Length 0x%4.4X, MinLength 0x%4.4X",
            ResourceType, ResourceLength, MinimumResourceLength));
    }
    return (AE_AML_BAD_RESOURCE_LENGTH);
}
ACPI_STATUS AcpiUtValidateResource ( ACPI_WALK_STATE * WalkState , void * Aml , UINT8 * ReturnIndex ) { AML_RESOURCE * AmlResource ; UINT8 ResourceType ; UINT8 ResourceIndex ; ACPI_RS_LENGTH ResourceLength ; ACPI_RS_LENGTH MinimumResourceLength ; ACPI_FUNCTION_ENTRY ( ) ; ResourceType = ACPI_GET8 ( Aml ) ; if ( ResourceType & ACPI_RESOURCE_NAME_LARGE ) { if ( ResourceType > ACPI_RESOURCE_NAME_LARGE_MAX ) { goto InvalidResource ; } ResourceIndex = ( UINT8 ) ( ResourceType - 0x70 ) ; } else { ResourceIndex = ( UINT8 ) ( ( ResourceType & ACPI_RESOURCE_NAME_SMALL_MASK ) >> 3 ) ; } if ( ! AcpiGbl_ResourceTypes [ ResourceIndex ] ) { goto InvalidResource ; } ResourceLength = AcpiUtGetResourceLength ( Aml ) ; MinimumResourceLength = AcpiGbl_ResourceAmlSizes [ ResourceIndex ] ; switch ( AcpiGbl_ResourceTypes [ ResourceIndex ] ) { case ACPI_FIXED_LENGTH : if ( ResourceLength != MinimumResourceLength ) { goto BadResourceLength ; } break ; case ACPI_VARIABLE_LENGTH : if ( ResourceLength < MinimumResourceLength ) { goto BadResourceLength ; } break ; case ACPI_SMALL_VARIABLE_LENGTH : if ( ( ResourceLength > MinimumResourceLength ) || ( ResourceLength < ( MinimumResourceLength - 1 ) ) ) { goto BadResourceLength ; } break ; default : goto InvalidResource ; } AmlResource = ACPI_CAST_PTR ( AML_RESOURCE , Aml ) ; if ( ResourceType == ACPI_RESOURCE_NAME_SERIAL_BUS ) { if ( ( AmlResource -> CommonSerialBus . Type == 0 ) || ( AmlResource -> CommonSerialBus . Type > AML_RESOURCE_MAX_SERIALBUSTYPE ) ) { if ( WalkState ) { ACPI_ERROR ( ( AE_INFO , " " , AmlResource -> CommonSerialBus . Type ) ) ; } return ( AE_AML_INVALID_RESOURCE_TYPE ) ; } } if ( ReturnIndex ) { * ReturnIndex = ResourceIndex ; } return ( AE_OK ) ; InvalidResource : if ( WalkState ) { ACPI_ERROR ( ( AE_INFO , " " , ResourceType ) ) ; } return ( AE_AML_INVALID_RESOURCE_TYPE ) ; BadResourceLength : if ( WalkState ) { ACPI_ERROR ( ( AE_INFO , " " " " , ResourceType , ResourceLength , MinimumResourceLength ) ) ; } return ( AE_AML_BAD_RESOURCE_LENGTH ) ; }
FUNCTION:    AcpiUtValidateResource
 PARAMETERS:  WalkState           - Current walk info
              Aml                 - Pointer to the raw AML resource descriptor
              ReturnIndex         - Where the resource index is returned.
FUNCTION : AcpiUtValidateResource PARAMETERS : WalkState - Current walk info Aml - Pointer to the raw AML resource descriptor ReturnIndex - Where the resource index is returned .
/*
     * 1) Validate the ResourceType field (Byte 0)
     */ /*
     * Byte 0 contains the descriptor name (Resource Type)
     * Examine the large/small bit in the resource header
     */ /* Verify the large resource type (name) against the max */ /*
         * Large Resource Type -- bits 6:0 contain the name
         * Translate range 0x80-0x8B to index range 0x10-0x1B
         */ /*
         * Small Resource Type -- bits 6:3 contain the name
         * Shift range to index range 0x00-0x0F
         */ /*
     * Check validity of the resource type, via AcpiGbl_ResourceTypes. Zero
     * indicates an invalid resource.
     */ /*
     * Validate the ResourceLength field. This ensures that the length
     * is at least reasonable, and guarantees that it is non-zero.
     */ /* Validate based upon the type of resource - fixed length or variable */ /* Fixed length resource, length must match exactly */ /* Variable length resource, length must be at least the minimum */ /* Small variable length resource, length can be (Min) or (Min-1) */ /* Shouldn't happen (because of validation earlier), but be sure */ /* Validate the BusType field */ /* Optionally return the resource table index */