Exemplo n.º 1
0
/*********************************************************************************
 * FUNCTION PURPOSE: Free EdmaMgr handle
 *********************************************************************************
  DESCRIPTION:      This function frees an EDMA channel

  Parameters :      Inputs: h   : EdmaMgr handle

                    Output: EdmaMgr_SUCCESS if free is successful;
                            Error code otherwise.
 *********************************************************************************/
int32_t EdmaMgr_free(EdmaMgr_Handle h)
{
    EdmaMgr_Channel *chan = (EdmaMgr_Channel *)h;
    IRES_ResourceDescriptor resDesc;
    IRES_Status ires_status;
    int32_t scratchId = -1;
    int32_t i, ret_val = EdmaMgr_SUCCESS;

    /* Make sure all transfers have completed */
    EdmaMgr_wait(h);

    /* While loop for freeing chained channels. */
    while ( chan != NULL ) {
      EdmaMgr_Channel *chainedChan = chan->chainedChannel;

      /* Verify that this is a valid handle? */
      for (i = 0; i < EDMA_MGR_MAX_NUM_CHANNELS; i++)
          if (chan == &EdmaMgr_channels[i])
              break;

      if (i >= EDMA_MGR_MAX_NUM_CHANNELS)
          return EdmaMgr_ERROR_INVHANDLE;

      /* Prepare IRES resource descriptor */
      resDesc.resourceName = IRES_EDMA3CHAN_PROTOCOLNAME;
      resDesc.revision = &_iresEDMA3ChanRevision;
      resDesc.protocolArgs = (IRES_ProtocolArgs *)&(chan->edmaArgs);
      resDesc.handle = (IRES_Handle)chan->edmaHandle;

      ECPY_deleteHandle(chan->ecpyHandle);

      ires_status =
              RMAN_freeAllocatedResources((Int)EdmaMgr_channels, &resDesc, 1,
              scratchId);
      if (ires_status != IRES_OK) {
          ret_val = EdmaMgr_ERROR_FREE;
      }

      chan->ecpyHandle = NULL;
      chan->edmaHandle = NULL;
      chan->xferPending = FALSE;

      chan->edmaArgs.numPaRams = 0;
      chan->chainedChannel = NULL;

      if ( chan->addrTable.base ) {
          chan->addrTable.base = NULL;
          chan->addrTable.size = 0;
      }

      chan = chainedChan;
    }

    return ret_val;
}
Exemplo n.º 2
0
/*********************************************************************************
 * FUNCTION PURPOSE: Allocate EdmaMgr handle
 *********************************************************************************
  DESCRIPTION:      This function allocates an EDMA channel

  Parameters :      Inputs: max_linked_transfer  : maximum number of linked
                                                   transfers required for the
                                                   channel.

                    Output: Valid EdmaMgr handle on success;
                            NULL handle if there is an error.
 *********************************************************************************/
EdmaMgr_Handle EdmaMgr_alloc(int32_t max_linked_transfers)
{
    IRES_ResourceDescriptor resDesc;
    IRES_Status ires_status;
    int32_t scratchId = -1;
    int32_t i;

    /* Find free channel */
    for (i = 0; i < EDMA_MGR_MAX_NUM_CHANNELS; i++)
        if (EdmaMgr_channels[i].edmaArgs.numPaRams == 0)
            break;

    if (i >= EDMA_MGR_MAX_NUM_CHANNELS)
        return ((EdmaMgr_Handle)NULL);

    EdmaMgr_channels[i].edmaArgs.numPaRams = max_linked_transfers;

    /* Prepare IRES resource descriptor */
    resDesc.resourceName = IRES_EDMA3CHAN_PROTOCOLNAME;
    resDesc.revision = &_iresEDMA3ChanRevision;
    resDesc.protocolArgs = (IRES_ProtocolArgs *)&(EdmaMgr_channels[i].edmaArgs);
    resDesc.handle = (IRES_Handle)EdmaMgr_channels[i].edmaHandle;

    /* Allocate EDMA Resources */
    ires_status =
            RMAN_allocateResources((Int)EdmaMgr_channels, &resDesc, 1,
            scratchId);
    if (ires_status != IRES_OK) {
        EdmaMgr_channels[i].edmaArgs.numPaRams = 0;
        return ((EdmaMgr_Handle)NULL);
    }
    EdmaMgr_channels[i].edmaHandle = (IRES_EDMA3CHAN_Handle) resDesc.handle;

    /* Create ECPY handle */
    EdmaMgr_channels[i].ecpyHandle =
            ECPY_createHandle((IRES_EDMA3CHAN2_Handle)resDesc.handle,
            (IALG_Handle)&EdmaMgr_channels[i]);
    if (EdmaMgr_channels[i].ecpyHandle == NULL) {
        RMAN_freeAllocatedResources((Int)EdmaMgr_channels, &resDesc, 1,
                scratchId);
        EdmaMgr_channels[i].edmaHandle = NULL;
        EdmaMgr_channels[i].edmaArgs.numPaRams = 0;
        return ((EdmaMgr_Handle)NULL);
    }
    EdmaMgr_channels[i].xferPending = FALSE;

    /* HW assign */
    ECPY_activate(EdmaMgr_channels[i].ecpyHandle);
    ECPY_setEarlyCompletionMode(EdmaMgr_channels[i].ecpyHandle, FALSE);

    return ((EdmaMgr_Handle)&EdmaMgr_channels[i]);
}
Exemplo n.º 3
0
/*
 *  ======== RMAN_allocateResources ========
 *  Directly allocate IRES resources by client without implementing IRES_Fxns
 */
IRES_Status RMAN_allocateResources(Int requestId,
        IRES_ResourceDescriptor * resDesc, Int numResources, Int scratchGroupId)
{
    Int              n = 0;
    IRESMAN_Fxns   * resman = NULL;
    IRES_Status      status = IRES_OK;
    IArg             key;


    if (initStatus != IRES_OK) {
        Log_print0(Diags_USER7, "[+7] RMAN_allocateResources> "
                "RMAN_init call hasn't happened successfully. Please "
                "initialize RMAN before calling any other RMAN API");

        Log_print0(Diags_EXIT, "[+X] RMAN_allocateResource> "
                "Exit (status=IRES_ENOINIT)");
        return (IRES_ENOINIT);
    }

    Assert_isTrue(resDesc != NULL, (Assert_Id)NULL);
    Assert_isTrue(numResources >=1, (Assert_Id)NULL);
    Assert_isTrue(RMAN_PARAMS.allocFxn != NULL, (Assert_Id)NULL);
    Assert_isTrue(RMAN_PARAMS.freeFxn != NULL, (Assert_Id)NULL);

    Log_print4(Diags_ENTRY, "[+E] RMAN_allocateResources> Enter "
            "requestId=%d, (resDesc=0x%x, numResources=%d, scratchGroupId=%d)",
            (IArg)requestId, (IArg)resDesc, (IArg)numResources,
            (IArg)scratchGroupId);

    /*
     *  Allocate requested resources one by one.
     */
    if (status == IRES_OK) {
        /* For each requested resource */
        for (n = 0 ; n < numResources; n++) {
            /* If someone populated the resource descriptor improperly, bail */
            if ((resDesc[n].resourceName == NULL) ||
                    (resDesc[n].revision == NULL)) {

                Log_print0(Diags_USER7, "[+7] RMAN_allocateResources> "
                        "Resource protocol and/or version were NULL. "
                        "Most likely an issue  with the algorithm's "
                        "getResourceRequestDescriptor implementation.");

                status = IRES_EALG;
                break;
            }

            resman = getResman(resDesc[n].resourceName, resDesc[n].revision);

            if (resman != NULL) {
                /*
                 *  Call getHandle on the IRESMAN implementation using
                 *  the protocolArgs extracted.
                 */
                Log_print1(Diags_USER2, "[+2] RMAN_allocateResources> Call "
                        "getHandle on the IRESMAN implementation 0x%x",
                        (IArg)resman);

                /* Acquire lock */
                key = IGateProvider_enter(gate);

                resDesc[n].handle = resman->getHandle((IALG_Handle)requestId,
                        &resDesc[n], scratchGroupId, &status);

                /* Release lock */
                IGateProvider_leave(gate, key);

                if (IRES_OK != status) {
                    break;
                }
            }
            else {
                Log_print2(Diags_USER7, "[+7] RMAN_allocateResources> "
                        "Resource protocol %s and version 0x%x didn't match "
                        "any registered protocol.",
                        (IArg)(resDesc[n].resourceName),
                        (IArg)(resDesc[n].revision));

                status = IRES_ENOTFOUND;
                break;
            }
        }
    }

    /*
     * Return those handles to IALG using the appropriate IRES call
     */
    if (FALSE == addVTableEntry((IALG_Handle)requestId, (IRES_Fxns *)NULL)) {
    /* TODO: Add trace */
            status = IRES_EFAIL;

            RMAN_freeAllocatedResources(requestId, resDesc, numResources,
                    scratchGroupId);
    }

    Log_print1(Diags_EXIT, "[+X] RMAN_allocateResources> Exit (status=%d)",
            (IArg)status);

    return (status);
}