FreeBSD/sys/contrib/dev/acpica/compiler/aslrestype2.c
/*******************************************************************************
 *
 * FUNCTION:    RsDoInterruptDescriptor
 *
 * PARAMETERS:  Info                - Parse Op and resource template offset
 *
 * RETURN:      Completed resource node
 *
 * DESCRIPTION: Construct a long "Interrupt" descriptor
 *
 ******************************************************************************/
RsDoInterruptDescriptor
PARAMETERS:  Info                - Parse Op and resource template offset

Completed resource node

Construct a long "Interrupt" descriptor
RsDoInterruptDescriptor PARAMETERS : Info - Parse Op and resource template offset Completed resource node Construct a long " Interrupt " descriptor
ASL_RESOURCE_NODE *
RsDoInterruptDescriptor (
    ASL_RESOURCE_INFO       *Info)
{
    AML_RESOURCE            *Descriptor;
    AML_RESOURCE            *Rover = NULL;
    ACPI_PARSE_OBJECT       *InitializerOp;
    ASL_RESOURCE_NODE       *Rnode;
    UINT16                  StringLength = 0;
    UINT32                  OptionIndex = 0;
    UINT32                  CurrentByteOffset;
    UINT32                  i;
    BOOLEAN                 HasResSourceIndex = FALSE;
    UINT8                   ResSourceIndex = 0;
    UINT8                   *ResSourceString = NULL;
    InitializerOp = Info->DescriptorTypeOp->Asl.Child;
    CurrentByteOffset = Info->CurrentByteOffset;
    StringLength = RsGetStringDataLength (InitializerOp);
    for (i = 0; InitializerOp; i++)
    {
        InitializerOp = ASL_GET_PEER_NODE (InitializerOp);
        if (i <= 6)
        {
            if (i == 3 &&
                InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
            {
                OptionIndex++;
            }
            continue;
        }
        OptionIndex += 4;
    }
    InitializerOp = Info->DescriptorTypeOp->Asl.Child;
    Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_EXTENDED_IRQ) +
        1 + OptionIndex + StringLength);
    Descriptor = Rnode->Buffer;
    Descriptor->ExtendedIrq.DescriptorType = ACPI_RESOURCE_NAME_EXTENDED_IRQ;
    Descriptor->ExtendedIrq.ResourceLength  = 2;  
    Descriptor->ExtendedIrq.InterruptCount  = 0;
    Rover = ACPI_CAST_PTR (AML_RESOURCE,
        (&(Descriptor->ExtendedIrq.Interrupts[0])));
    for (i = 0; InitializerOp; i++)
    {
        switch (i)
        {
        case 0: 
            RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 0, 1);
            break;
        case 1: 
            RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 1, 0);
            RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTTYPE,
                CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 1);
            break;
        case 2: 
            RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 2, 0);
            RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTLEVEL,
                CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 2);
            break;
        case 3: 
            RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 3, 0);
            RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTSHARE,
                CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 3);
            break;
        case 4: 
            if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
            {
                HasResSourceIndex = TRUE;
                ResSourceIndex = (UINT8) InitializerOp->Asl.Value.Integer;
            }
            break;
        case 5: 
            if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) &&
                (InitializerOp->Asl.Value.String))
            {
                if (StringLength)
                {
                    ResSourceString = (UINT8 *) InitializerOp->Asl.Value.String;
                }
                if (!HasResSourceIndex)
                {
                    AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX,
                        InitializerOp, NULL);
                }
            }
#if 0
            else if (HasResSourceIndex)
            {
                AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE,
                    InitializerOp, NULL);
            }
#endif
            break;
        case 6: 
            UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
            break;
        default:
            if (Descriptor->ExtendedIrq.InterruptCount == 255)
            {
                AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_LIST,
                    InitializerOp, NULL);
                return (Rnode);
            }
            if (InitializerOp->Asl.Value.Integer > ACPI_UINT32_MAX)
            {
                AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_NUMBER,
                    InitializerOp, NULL);
            }
            Rover->DwordItem = (UINT32) InitializerOp->Asl.Value.Integer;
            Rover = ACPI_ADD_PTR (AML_RESOURCE, &(Rover->DwordItem), 4);
            Descriptor->ExtendedIrq.InterruptCount++;
            Descriptor->ExtendedIrq.ResourceLength += 4;
            if (i == 7)
            {
                if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
                {
                    AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_LIST_MIN,
                        InitializerOp, NULL);
                }
                RsCheckListForDuplicates (InitializerOp);
                RsCreateDwordField (InitializerOp, ACPI_RESTAG_INTERRUPT,
                    CurrentByteOffset +
                    ASL_RESDESC_OFFSET (ExtendedIrq.Interrupts[0]));
            }
        }
        InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
    }
    if (HasResSourceIndex)
    {
        Rover->ByteItem = ResSourceIndex;
        Rover = ACPI_ADD_PTR (AML_RESOURCE, &(Rover->ByteItem), 1);
        Descriptor->ExtendedIrq.ResourceLength += 1;
    }
    if (StringLength && ResSourceString)
    {
        strcpy ((char *) Rover, (char *) ResSourceString);
        Rover = ACPI_ADD_PTR (
                    AML_RESOURCE, &(Rover->ByteItem), StringLength);
        Descriptor->ExtendedIrq.ResourceLength = (UINT16)
            (Descriptor->ExtendedIrq.ResourceLength + StringLength);
    }
    Rnode->BufferLength =
        (ASL_RESDESC_OFFSET (ExtendedIrq.Interrupts[0]) -
        ASL_RESDESC_OFFSET (ExtendedIrq.DescriptorType))
        + OptionIndex + StringLength;
    return (Rnode);
}
ASL_RESOURCE_NODE * RsDoInterruptDescriptor ( ASL_RESOURCE_INFO * Info ) { AML_RESOURCE * Descriptor ; AML_RESOURCE * Rover = NULL ; ACPI_PARSE_OBJECT * InitializerOp ; ASL_RESOURCE_NODE * Rnode ; UINT16 StringLength = 0 ; UINT32 OptionIndex = 0 ; UINT32 CurrentByteOffset ; UINT32 i ; BOOLEAN HasResSourceIndex = FALSE ; UINT8 ResSourceIndex = 0 ; UINT8 * ResSourceString = NULL ; InitializerOp = Info -> DescriptorTypeOp -> Asl . Child ; CurrentByteOffset = Info -> CurrentByteOffset ; StringLength = RsGetStringDataLength ( InitializerOp ) ; for ( i = 0 ; InitializerOp ; i ++ ) { InitializerOp = ASL_GET_PEER_NODE ( InitializerOp ) ; if ( i <= 6 ) { if ( i == 3 && InitializerOp -> Asl . ParseOpcode != PARSEOP_DEFAULT_ARG ) { OptionIndex ++ ; } continue ; } OptionIndex += 4 ; } InitializerOp = Info -> DescriptorTypeOp -> Asl . Child ; Rnode = RsAllocateResourceNode ( sizeof ( AML_RESOURCE_EXTENDED_IRQ ) + 1 + OptionIndex + StringLength ) ; Descriptor = Rnode -> Buffer ; Descriptor -> ExtendedIrq . DescriptorType = ACPI_RESOURCE_NAME_EXTENDED_IRQ ; Descriptor -> ExtendedIrq . ResourceLength = 2 ; Descriptor -> ExtendedIrq . InterruptCount = 0 ; Rover = ACPI_CAST_PTR ( AML_RESOURCE , ( & ( Descriptor -> ExtendedIrq . Interrupts [ 0 ] ) ) ) ; for ( i = 0 ; InitializerOp ; i ++ ) { switch ( i ) { case 0 : RsSetFlagBits ( & Descriptor -> ExtendedIrq . Flags , InitializerOp , 0 , 1 ) ; break ; case 1 : RsSetFlagBits ( & Descriptor -> ExtendedIrq . Flags , InitializerOp , 1 , 0 ) ; RsCreateBitField ( InitializerOp , ACPI_RESTAG_INTERRUPTTYPE , CurrentByteOffset + ASL_RESDESC_OFFSET ( ExtendedIrq . Flags ) , 1 ) ; break ; case 2 : RsSetFlagBits ( & Descriptor -> ExtendedIrq . Flags , InitializerOp , 2 , 0 ) ; RsCreateBitField ( InitializerOp , ACPI_RESTAG_INTERRUPTLEVEL , CurrentByteOffset + ASL_RESDESC_OFFSET ( ExtendedIrq . Flags ) , 2 ) ; break ; case 3 : RsSetFlagBits ( & Descriptor -> ExtendedIrq . Flags , InitializerOp , 3 , 0 ) ; RsCreateBitField ( InitializerOp , ACPI_RESTAG_INTERRUPTSHARE , CurrentByteOffset + ASL_RESDESC_OFFSET ( ExtendedIrq . Flags ) , 3 ) ; break ; case 4 : if ( InitializerOp -> Asl . ParseOpcode != PARSEOP_DEFAULT_ARG ) { HasResSourceIndex = TRUE ; ResSourceIndex = ( UINT8 ) InitializerOp -> Asl . Value . Integer ; } break ; case 5 : if ( ( InitializerOp -> Asl . ParseOpcode != PARSEOP_DEFAULT_ARG ) && ( InitializerOp -> Asl . Value . String ) ) { if ( StringLength ) { ResSourceString = ( UINT8 * ) InitializerOp -> Asl . Value . String ; } if ( ! HasResSourceIndex ) { AslError ( ASL_ERROR , ASL_MSG_RESOURCE_INDEX , InitializerOp , NULL ) ; } } #if 0 else if ( HasResSourceIndex ) { AslError ( ASL_ERROR , ASL_MSG_RESOURCE_SOURCE , InitializerOp , NULL ) ; } #endif break ; case 6 : UtAttachNamepathToOwner ( Info -> DescriptorTypeOp , InitializerOp ) ; break ; default : if ( Descriptor -> ExtendedIrq . InterruptCount == 255 ) { AslError ( ASL_ERROR , ASL_MSG_EX_INTERRUPT_LIST , InitializerOp , NULL ) ; return ( Rnode ) ; } if ( InitializerOp -> Asl . Value . Integer > ACPI_UINT32_MAX ) { AslError ( ASL_ERROR , ASL_MSG_EX_INTERRUPT_NUMBER , InitializerOp , NULL ) ; } Rover -> DwordItem = ( UINT32 ) InitializerOp -> Asl . Value . Integer ; Rover = ACPI_ADD_PTR ( AML_RESOURCE , & ( Rover -> DwordItem ) , 4 ) ; Descriptor -> ExtendedIrq . InterruptCount ++ ; Descriptor -> ExtendedIrq . ResourceLength += 4 ; if ( i == 7 ) { if ( InitializerOp -> Asl . ParseOpcode == PARSEOP_DEFAULT_ARG ) { AslError ( ASL_ERROR , ASL_MSG_EX_INTERRUPT_LIST_MIN , InitializerOp , NULL ) ; } RsCheckListForDuplicates ( InitializerOp ) ; RsCreateDwordField ( InitializerOp , ACPI_RESTAG_INTERRUPT , CurrentByteOffset + ASL_RESDESC_OFFSET ( ExtendedIrq . Interrupts [ 0 ] ) ) ; } } InitializerOp = RsCompleteNodeAndGetNext ( InitializerOp ) ; } if ( HasResSourceIndex ) { Rover -> ByteItem = ResSourceIndex ; Rover = ACPI_ADD_PTR ( AML_RESOURCE , & ( Rover -> ByteItem ) , 1 ) ; Descriptor -> ExtendedIrq . ResourceLength += 1 ; } if ( StringLength && ResSourceString ) { strcpy ( ( char * ) Rover , ( char * ) ResSourceString ) ; Rover = ACPI_ADD_PTR ( AML_RESOURCE , & ( Rover -> ByteItem ) , StringLength ) ; Descriptor -> ExtendedIrq . ResourceLength = ( UINT16 ) ( Descriptor -> ExtendedIrq . ResourceLength + StringLength ) ; } Rnode -> BufferLength = ( ASL_RESDESC_OFFSET ( ExtendedIrq . Interrupts [ 0 ] ) - ASL_RESDESC_OFFSET ( ExtendedIrq . DescriptorType ) ) + OptionIndex + StringLength ; return ( Rnode ) ; }
FUNCTION:    RsDoInterruptDescriptor
 PARAMETERS:  Info                - Parse Op and resource template offset
FUNCTION : RsDoInterruptDescriptor PARAMETERS : Info - Parse Op and resource template offset
/* Count the interrupt numbers */ /*
                 * ResourceSourceIndex was specified, always make room for
                 * it, even if the ResourceSource was omitted.
                 */ /*
     * Initial descriptor length -- may be enlarged if there are
     * optional fields present
     */ /* Flags and table length byte */ /* Process all child initialization nodes */ /* Resource Usage (Default: consumer (1) */ /* Interrupt Type (or Mode - edge/level) */ /* Interrupt Level (or Polarity - Active high/low) */ /* Share Type - Default: exclusive (0) */ /* ResSourceIndex [Optional Field - BYTE] */ /* ResSource [Optional Field - STRING] */ /* ResourceSourceIndex must also be valid */ /*
             * Not a valid ResourceSource, ResourceSourceIndex must also
             * be invalid
             */ /* ResourceTag */ /*
             * Interrupt Numbers come through here, repeatedly
             */ /* Maximum 255 interrupts allowed for this descriptor */ /* Each interrupt number must be a 32-bit value */ /* Save the integer and move pointer to the next one */ /* Case 7: First interrupt number in list */ /* Must be at least one interrupt */ /* Check now for duplicates in list */ /* Create a named field at the start of the list */ /* Add optional ResSourceIndex if present */ /* Add optional ResSource string if present */