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

Completed resource node

Construct a long "GpioIo" descriptor
RsDoGpioIoDescriptor PARAMETERS : Info - Parse Op and resource template offset Completed resource node Construct a long " GpioIo " descriptor
ASL_RESOURCE_NODE *
RsDoGpioIoDescriptor (
    ASL_RESOURCE_INFO       *Info)
{
    AML_RESOURCE            *Descriptor;
    ACPI_PARSE_OBJECT       *InitializerOp;
    ASL_RESOURCE_NODE       *Rnode;
    char                    *ResourceSource = NULL;
    UINT8                   *VendorData = NULL;
    UINT16                  *InterruptList = NULL;
    UINT16                  *PinList = NULL;
    UINT16                  ResSourceLength;
    UINT16                  VendorLength;
    UINT16                  InterruptLength;
    UINT16                  DescriptorSize;
    UINT32                  CurrentByteOffset;
    UINT32                  PinCount = 0;
    UINT32                  i;
    InitializerOp = Info->DescriptorTypeOp->Asl.Child;
    CurrentByteOffset = Info->CurrentByteOffset;
    ResSourceLength = RsGetStringDataLength (InitializerOp);
    VendorLength = RsGetBufferDataLength (InitializerOp);
    InterruptLength = RsGetInterruptDataLength (InitializerOp);
    PinList = InterruptList;
    DescriptorSize = ACPI_AML_SIZE_LARGE (AML_RESOURCE_GPIO) +
        ResSourceLength + VendorLength + InterruptLength;
    Rnode = RsAllocateResourceNode (DescriptorSize +
        sizeof (AML_RESOURCE_LARGE_HEADER));
    Descriptor = Rnode->Buffer;
    Descriptor->Gpio.ResourceLength = DescriptorSize;
    Descriptor->Gpio.DescriptorType = ACPI_RESOURCE_NAME_GPIO;
    Descriptor->Gpio.RevisionId = AML_RESOURCE_GPIO_REVISION;
    Descriptor->Gpio.ConnectionType = AML_RESOURCE_GPIO_TYPE_IO;
    InterruptList = ACPI_ADD_PTR (UINT16, Descriptor, sizeof (AML_RESOURCE_GPIO));
    PinList = InterruptList;
    ResourceSource = ACPI_ADD_PTR (char, InterruptList, InterruptLength);
    VendorData = ACPI_ADD_PTR (UINT8, ResourceSource, ResSourceLength);
    Descriptor->Gpio.PinTableOffset = (UINT16)
        ACPI_PTR_DIFF (InterruptList, Descriptor);
    Descriptor->Gpio.ResSourceOffset = (UINT16)
        ACPI_PTR_DIFF (ResourceSource, Descriptor);
    for (i = 0; InitializerOp; i++)
    {
        switch (i)
        {
        case 0: 
            RsSetFlagBits16 (&Descriptor->Gpio.IntFlags, InitializerOp, 3, 0);
            RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTSHARE,
                CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.IntFlags), 3);
            break;
        case 1: 
            Descriptor->Gpio.PinConfig = (UINT8) InitializerOp->Asl.Value.Integer;
            RsCreateByteField (InitializerOp, ACPI_RESTAG_PINCONFIG,
                CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.PinConfig));
            break;
        case 2: 
            Descriptor->Gpio.DebounceTimeout = (UINT16) InitializerOp->Asl.Value.Integer;
            RsCreateWordField (InitializerOp, ACPI_RESTAG_DEBOUNCETIME,
                CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.DebounceTimeout));
            break;
        case 3: 
            Descriptor->Gpio.DriveStrength = (UINT16) InitializerOp->Asl.Value.Integer;
            RsCreateWordField (InitializerOp, ACPI_RESTAG_DRIVESTRENGTH,
                CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.DriveStrength));
            break;
        case 4: 
            RsSetFlagBits16 (&Descriptor->Gpio.IntFlags, InitializerOp, 0, 0);
            RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_IORESTRICTION,
                CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.IntFlags), 0, 2);
            break;
        case 5: 
            if (ResSourceLength)
            {
                strcpy (ResourceSource,
                    InitializerOp->Asl.Value.String);
            }
            break;
        case 6: 
            if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)
            {
                Descriptor->Gpio.ResSourceIndex = (UINT8) InitializerOp->Asl.Value.Integer;
            }
            break;
        case 7: 
            RsSetFlagBits16 (&Descriptor->Gpio.Flags, InitializerOp, 0, 1);
            break;
        case 8: 
            UtAttachNamepathToOwner (Info->DescriptorTypeOp, InitializerOp);
            break;
        case 9: 
            Descriptor->Gpio.VendorOffset = (UINT16)
                ACPI_PTR_DIFF (VendorData, Descriptor);
            if (RsGetVendorData (InitializerOp, VendorData,
                (CurrentByteOffset + Descriptor->Gpio.VendorOffset)))
            {
                Descriptor->Gpio.VendorLength = VendorLength;
            }
            break;
        default:
            *InterruptList = (UINT16) InitializerOp->Asl.Value.Integer;
            InterruptList++;
            PinCount++;
            if (i == 10)
            {
                if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)
                {
                    AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_LIST_MIN,
                        InitializerOp, NULL);
                }
                RsCheckListForDuplicates (InitializerOp);
                RsCreateWordField (InitializerOp, ACPI_RESTAG_PIN,
                    CurrentByteOffset + Descriptor->Gpio.PinTableOffset);
            }
            break;
        }
        InitializerOp = RsCompleteNodeAndGetNext (InitializerOp);
    }
    MpSaveGpioInfo (Info->MappingOp, Descriptor,
        PinCount, PinList, ResourceSource);
    return (Rnode);
}
ASL_RESOURCE_NODE * RsDoGpioIoDescriptor ( ASL_RESOURCE_INFO * Info ) { AML_RESOURCE * Descriptor ; ACPI_PARSE_OBJECT * InitializerOp ; ASL_RESOURCE_NODE * Rnode ; char * ResourceSource = NULL ; UINT8 * VendorData = NULL ; UINT16 * InterruptList = NULL ; UINT16 * PinList = NULL ; UINT16 ResSourceLength ; UINT16 VendorLength ; UINT16 InterruptLength ; UINT16 DescriptorSize ; UINT32 CurrentByteOffset ; UINT32 PinCount = 0 ; UINT32 i ; InitializerOp = Info -> DescriptorTypeOp -> Asl . Child ; CurrentByteOffset = Info -> CurrentByteOffset ; ResSourceLength = RsGetStringDataLength ( InitializerOp ) ; VendorLength = RsGetBufferDataLength ( InitializerOp ) ; InterruptLength = RsGetInterruptDataLength ( InitializerOp ) ; PinList = InterruptList ; DescriptorSize = ACPI_AML_SIZE_LARGE ( AML_RESOURCE_GPIO ) + ResSourceLength + VendorLength + InterruptLength ; Rnode = RsAllocateResourceNode ( DescriptorSize + sizeof ( AML_RESOURCE_LARGE_HEADER ) ) ; Descriptor = Rnode -> Buffer ; Descriptor -> Gpio . ResourceLength = DescriptorSize ; Descriptor -> Gpio . DescriptorType = ACPI_RESOURCE_NAME_GPIO ; Descriptor -> Gpio . RevisionId = AML_RESOURCE_GPIO_REVISION ; Descriptor -> Gpio . ConnectionType = AML_RESOURCE_GPIO_TYPE_IO ; InterruptList = ACPI_ADD_PTR ( UINT16 , Descriptor , sizeof ( AML_RESOURCE_GPIO ) ) ; PinList = InterruptList ; ResourceSource = ACPI_ADD_PTR ( char , InterruptList , InterruptLength ) ; VendorData = ACPI_ADD_PTR ( UINT8 , ResourceSource , ResSourceLength ) ; Descriptor -> Gpio . PinTableOffset = ( UINT16 ) ACPI_PTR_DIFF ( InterruptList , Descriptor ) ; Descriptor -> Gpio . ResSourceOffset = ( UINT16 ) ACPI_PTR_DIFF ( ResourceSource , Descriptor ) ; for ( i = 0 ; InitializerOp ; i ++ ) { switch ( i ) { case 0 : RsSetFlagBits16 ( & Descriptor -> Gpio . IntFlags , InitializerOp , 3 , 0 ) ; RsCreateBitField ( InitializerOp , ACPI_RESTAG_INTERRUPTSHARE , CurrentByteOffset + ASL_RESDESC_OFFSET ( Gpio . IntFlags ) , 3 ) ; break ; case 1 : Descriptor -> Gpio . PinConfig = ( UINT8 ) InitializerOp -> Asl . Value . Integer ; RsCreateByteField ( InitializerOp , ACPI_RESTAG_PINCONFIG , CurrentByteOffset + ASL_RESDESC_OFFSET ( Gpio . PinConfig ) ) ; break ; case 2 : Descriptor -> Gpio . DebounceTimeout = ( UINT16 ) InitializerOp -> Asl . Value . Integer ; RsCreateWordField ( InitializerOp , ACPI_RESTAG_DEBOUNCETIME , CurrentByteOffset + ASL_RESDESC_OFFSET ( Gpio . DebounceTimeout ) ) ; break ; case 3 : Descriptor -> Gpio . DriveStrength = ( UINT16 ) InitializerOp -> Asl . Value . Integer ; RsCreateWordField ( InitializerOp , ACPI_RESTAG_DRIVESTRENGTH , CurrentByteOffset + ASL_RESDESC_OFFSET ( Gpio . DriveStrength ) ) ; break ; case 4 : RsSetFlagBits16 ( & Descriptor -> Gpio . IntFlags , InitializerOp , 0 , 0 ) ; RsCreateMultiBitField ( InitializerOp , ACPI_RESTAG_IORESTRICTION , CurrentByteOffset + ASL_RESDESC_OFFSET ( Gpio . IntFlags ) , 0 , 2 ) ; break ; case 5 : if ( ResSourceLength ) { strcpy ( ResourceSource , InitializerOp -> Asl . Value . String ) ; } break ; case 6 : if ( InitializerOp -> Asl . ParseOpcode != PARSEOP_DEFAULT_ARG ) { Descriptor -> Gpio . ResSourceIndex = ( UINT8 ) InitializerOp -> Asl . Value . Integer ; } break ; case 7 : RsSetFlagBits16 ( & Descriptor -> Gpio . Flags , InitializerOp , 0 , 1 ) ; break ; case 8 : UtAttachNamepathToOwner ( Info -> DescriptorTypeOp , InitializerOp ) ; break ; case 9 : Descriptor -> Gpio . VendorOffset = ( UINT16 ) ACPI_PTR_DIFF ( VendorData , Descriptor ) ; if ( RsGetVendorData ( InitializerOp , VendorData , ( CurrentByteOffset + Descriptor -> Gpio . VendorOffset ) ) ) { Descriptor -> Gpio . VendorLength = VendorLength ; } break ; default : * InterruptList = ( UINT16 ) InitializerOp -> Asl . Value . Integer ; InterruptList ++ ; PinCount ++ ; if ( i == 10 ) { if ( InitializerOp -> Asl . ParseOpcode == PARSEOP_DEFAULT_ARG ) { AslError ( ASL_ERROR , ASL_MSG_EX_INTERRUPT_LIST_MIN , InitializerOp , NULL ) ; } RsCheckListForDuplicates ( InitializerOp ) ; RsCreateWordField ( InitializerOp , ACPI_RESTAG_PIN , CurrentByteOffset + Descriptor -> Gpio . PinTableOffset ) ; } break ; } InitializerOp = RsCompleteNodeAndGetNext ( InitializerOp ) ; } MpSaveGpioInfo ( Info -> MappingOp , Descriptor , PinCount , PinList , ResourceSource ) ; return ( Rnode ) ; }
FUNCTION:    RsDoGpioIoDescriptor
 PARAMETERS:  Info                - Parse Op and resource template offset
FUNCTION : RsDoGpioIoDescriptor PARAMETERS : Info - Parse Op and resource template offset
/*
     * Calculate lengths for fields that have variable length:
     * 1) Resource Source string
     * 2) Vendor Data buffer
     * 3) PIN (interrupt) list
     */ /* Allocate the local resource node and initialize */ /* Build pointers to optional areas */ /* Setup offsets within the descriptor */ /* Process all child initialization nodes */ /* Share Type [Flags] (_SHR) */ /* Pin Config [BYTE] (_PPI) */ /* Debounce Timeout [WORD] (_DBT) */ /* Drive Strength [WORD] (_DRS) */ /* I/O Restriction [Flag] (_IOR) */ /* ResSource [Optional Field - STRING] */ /* Copy string to the descriptor */ /* Resource Index */ /* Resource Usage (consumer/producer) */ /* Resource Tag (Descriptor Name) */ /* Vendor Data (Optional - Buffer of BYTEs) (_VEN) */ /*
             * Always set the VendorOffset even if there is no Vendor Data.
             * This field is required in order to calculate the length
             * of the ResourceSource at runtime.
             */ /*
             * PINs come through here, repeatedly. Each PIN must be a WORD.
             * NOTE: there is no "length" field for this, so from ACPI spec:
             *  The number of pins in the table can be calculated from:
             *  PinCount = (Resource Source Name Offset - Pin Table Offset) / 2
             *  (implies resource source must immediately follow the pin list.)
             *  Name: _PIN
             */ /* Case 10: 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 */