FreeBSD/sys/contrib/dev/acpica/compiler/dtutils.c
/******************************************************************************
 *
 * FUNCTION:    DtGetFieldLength
 *
 * PARAMETERS:  Field               - Current field
 *              Info                - Data table info
 *
 * RETURN:      Field length
 *
 * DESCRIPTION: Get length of bytes needed to compile the field
 *
 * Note: This function must remain in sync with AcpiDmDumpTable.
 *
 *****************************************************************************/
DtGetFieldLength
PARAMETERS:  Field               - Current field
Info                - Data table info

Field length

Get length of bytes needed to compile the field

This function must remain in sync with AcpiDmDumpTable.
DtGetFieldLength PARAMETERS : Field - Current field Info - Data table info Field length Get length of bytes needed to compile the field This function must remain in sync with AcpiDmDumpTable .
UINT32
DtGetFieldLength (
    DT_FIELD                *Field,
    ACPI_DMTABLE_INFO       *Info)
{
    UINT32                  ByteLength = 0;
    char                    *Value;
    switch (Info->Opcode)
    {
    case ACPI_DMT_FLAG0:
    case ACPI_DMT_FLAG1:
    case ACPI_DMT_FLAG2:
    case ACPI_DMT_FLAG3:
    case ACPI_DMT_FLAG4:
    case ACPI_DMT_FLAG5:
    case ACPI_DMT_FLAG6:
    case ACPI_DMT_FLAG7:
    case ACPI_DMT_FLAGS0:
    case ACPI_DMT_FLAGS1:
    case ACPI_DMT_FLAGS2:
    case ACPI_DMT_FLAGS4:
    case ACPI_DMT_LABEL:
    case ACPI_DMT_EXTRA_TEXT:
        ByteLength = 0;
        break;
    case ACPI_DMT_UINT8:
    case ACPI_DMT_CHKSUM:
    case ACPI_DMT_SPACEID:
    case ACPI_DMT_ACCWIDTH:
    case ACPI_DMT_IVRS:
    case ACPI_DMT_GTDT:
    case ACPI_DMT_MADT:
    case ACPI_DMT_PCCT:
    case ACPI_DMT_PMTT:
    case ACPI_DMT_SRAT:
    case ACPI_DMT_ASF:
    case ACPI_DMT_HESTNTYP:
    case ACPI_DMT_FADTPM:
    case ACPI_DMT_EINJACT:
    case ACPI_DMT_EINJINST:
    case ACPI_DMT_ERSTACT:
    case ACPI_DMT_ERSTINST:
    case ACPI_DMT_DMAR_SCOPE:
        ByteLength = 1;
        break;
    case ACPI_DMT_UINT16:
    case ACPI_DMT_DMAR:
    case ACPI_DMT_HEST:
    case ACPI_DMT_NFIT:
    case ACPI_DMT_PCI_PATH:
        ByteLength = 2;
        break;
    case ACPI_DMT_UINT24:
        ByteLength = 3;
        break;
    case ACPI_DMT_UINT32:
    case ACPI_DMT_NAME4:
    case ACPI_DMT_SIG:
    case ACPI_DMT_LPIT:
        ByteLength = 4;
        break;
    case ACPI_DMT_UINT40:
        ByteLength = 5;
        break;
    case ACPI_DMT_UINT48:
    case ACPI_DMT_NAME6:
        ByteLength = 6;
        break;
    case ACPI_DMT_UINT56:
    case ACPI_DMT_BUF7:
        ByteLength = 7;
        break;
    case ACPI_DMT_UINT64:
    case ACPI_DMT_NAME8:
        ByteLength = 8;
        break;
    case ACPI_DMT_STRING:
        Value = DtGetFieldValue (Field);
        if (Value)
        {
            ByteLength = strlen (Value) + 1;
        }
        else
        {   
            sprintf (MsgBuffer, "Expected \"%s\"", Info->Name);
            DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
            return (0);
        }
        break;
    case ACPI_DMT_GAS:
        ByteLength = sizeof (ACPI_GENERIC_ADDRESS);
        break;
    case ACPI_DMT_HESTNTFY:
        ByteLength = sizeof (ACPI_HEST_NOTIFY);
        break;
    case ACPI_DMT_IORTMEM:
        ByteLength = sizeof (ACPI_IORT_MEMORY_ACCESS);
        break;
    case ACPI_DMT_BUFFER:
    case ACPI_DMT_RAW_BUFFER:
        Value = DtGetFieldValue (Field);
        if (Value)
        {
            ByteLength = DtGetBufferLength (Value);
        }
        else
        {   
            sprintf (MsgBuffer, "Expected \"%s\"", Info->Name);
            DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
            return (0);
        }
        break;
    case ACPI_DMT_BUF10:
        ByteLength = 10;
        break;
    case ACPI_DMT_BUF16:
    case ACPI_DMT_UUID:
        ByteLength = 16;
        break;
    case ACPI_DMT_BUF128:
        ByteLength = 128;
        break;
    case ACPI_DMT_UNICODE:
        Value = DtGetFieldValue (Field);
        ByteLength = (strlen (Value) + 1) * sizeof(UINT16);
        break;
    default:
        DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid table opcode");
        return (0);
    }
    return (ByteLength);
}
UINT32 DtGetFieldLength ( DT_FIELD * Field , ACPI_DMTABLE_INFO * Info ) { UINT32 ByteLength = 0 ; char * Value ; switch ( Info -> Opcode ) { case ACPI_DMT_FLAG0 : case ACPI_DMT_FLAG1 : case ACPI_DMT_FLAG2 : case ACPI_DMT_FLAG3 : case ACPI_DMT_FLAG4 : case ACPI_DMT_FLAG5 : case ACPI_DMT_FLAG6 : case ACPI_DMT_FLAG7 : case ACPI_DMT_FLAGS0 : case ACPI_DMT_FLAGS1 : case ACPI_DMT_FLAGS2 : case ACPI_DMT_FLAGS4 : case ACPI_DMT_LABEL : case ACPI_DMT_EXTRA_TEXT : ByteLength = 0 ; break ; case ACPI_DMT_UINT8 : case ACPI_DMT_CHKSUM : case ACPI_DMT_SPACEID : case ACPI_DMT_ACCWIDTH : case ACPI_DMT_IVRS : case ACPI_DMT_GTDT : case ACPI_DMT_MADT : case ACPI_DMT_PCCT : case ACPI_DMT_PMTT : case ACPI_DMT_SRAT : case ACPI_DMT_ASF : case ACPI_DMT_HESTNTYP : case ACPI_DMT_FADTPM : case ACPI_DMT_EINJACT : case ACPI_DMT_EINJINST : case ACPI_DMT_ERSTACT : case ACPI_DMT_ERSTINST : case ACPI_DMT_DMAR_SCOPE : ByteLength = 1 ; break ; case ACPI_DMT_UINT16 : case ACPI_DMT_DMAR : case ACPI_DMT_HEST : case ACPI_DMT_NFIT : case ACPI_DMT_PCI_PATH : ByteLength = 2 ; break ; case ACPI_DMT_UINT24 : ByteLength = 3 ; break ; case ACPI_DMT_UINT32 : case ACPI_DMT_NAME4 : case ACPI_DMT_SIG : case ACPI_DMT_LPIT : ByteLength = 4 ; break ; case ACPI_DMT_UINT40 : ByteLength = 5 ; break ; case ACPI_DMT_UINT48 : case ACPI_DMT_NAME6 : ByteLength = 6 ; break ; case ACPI_DMT_UINT56 : case ACPI_DMT_BUF7 : ByteLength = 7 ; break ; case ACPI_DMT_UINT64 : case ACPI_DMT_NAME8 : ByteLength = 8 ; break ; case ACPI_DMT_STRING : Value = DtGetFieldValue ( Field ) ; if ( Value ) { ByteLength = strlen ( Value ) + 1 ; } else { sprintf ( MsgBuffer , " \" \" " , Info -> Name ) ; DtFatal ( ASL_MSG_COMPILER_INTERNAL , NULL , MsgBuffer ) ; return ( 0 ) ; } break ; case ACPI_DMT_GAS : ByteLength = sizeof ( ACPI_GENERIC_ADDRESS ) ; break ; case ACPI_DMT_HESTNTFY : ByteLength = sizeof ( ACPI_HEST_NOTIFY ) ; break ; case ACPI_DMT_IORTMEM : ByteLength = sizeof ( ACPI_IORT_MEMORY_ACCESS ) ; break ; case ACPI_DMT_BUFFER : case ACPI_DMT_RAW_BUFFER : Value = DtGetFieldValue ( Field ) ; if ( Value ) { ByteLength = DtGetBufferLength ( Value ) ; } else { sprintf ( MsgBuffer , " \" \" " , Info -> Name ) ; DtFatal ( ASL_MSG_COMPILER_INTERNAL , NULL , MsgBuffer ) ; return ( 0 ) ; } break ; case ACPI_DMT_BUF10 : ByteLength = 10 ; break ; case ACPI_DMT_BUF16 : case ACPI_DMT_UUID : ByteLength = 16 ; break ; case ACPI_DMT_BUF128 : ByteLength = 128 ; break ; case ACPI_DMT_UNICODE : Value = DtGetFieldValue ( Field ) ; ByteLength = ( strlen ( Value ) + 1 ) * sizeof ( UINT16 ) ; break ; default : DtFatal ( ASL_MSG_COMPILER_INTERNAL , Field , " " ) ; return ( 0 ) ; } return ( ByteLength ) ; }
FUNCTION:    DtGetFieldLength
 PARAMETERS:  Field               - Current field
              Info                - Data table info
FUNCTION : DtGetFieldLength PARAMETERS : Field - Current field Info - Data table info
/* Length is based upon the opcode for this field in the info table */ /* At this point, this is a fatal error */ /* At this point, this is a fatal error */ /* TBD: error if Value is NULL? (as below?) */