/*  ARGSUSED - this line tells the compiler not to warn about unused args */
IRES_Handle IRESMAN_EDMA3CHAN_getHandles( IALG_Handle algHandle,
        IRES_ProtocolArgs * protocolArgs, Int scratchGroupId,
        IRES_Status * status)
{
    EDMA3_ResDesc resObj;
    IALG_MemRec protocolMemRecs[IRESMAN_PROTOCOL_EDMA3CHAN_MAX_MEMRECS];
    IALG_MemRec constructHandleMemRec;
    Int numMemRecs;
    EDMA3_Handle rmHandle;
    
    short reqEdma = IRES_EDMA3CHAN_CHAN_NONE;
    short reqQdma = IRES_EDMA3CHAN_CHAN_NONE;

    short edma3Chan = IRES_EDMA3CHAN_CHAN_NONE;
    short qdmaChan = IRES_EDMA3CHAN_CHAN_NONE;
    short numPaRams = 0;
    short numTccs = 0;
    short paRamArray[IRES_EDMA3CHAN_MAXPARAMS] = { EDMA3_RES_ANY };
    short tccArray[IRES_EDMA3CHAN_MAXTCCS] = { EDMA3_RES_ANY };
    short toFreeTccs = 0;
    short toFreeParams = 0;
    short reqParam = IRES_EDMA3CHAN_PARAM_NONE;
    short reqTcc = IRES_EDMA3CHAN_TCC_NONE;
    unsigned int cccfg = 0x0;
    int i = 0;

    IRESMAN_EDMA3CHAN_ConstructHandleArgs * constructArgs = NULL;
    IRES_Handle resourceHandle = NULL;

    /*
     * Cast the protocolArgs 
     */
    IRES_EDMA3CHAN_ProtocolArgs * configArgs = 
            (IRES_EDMA3CHAN_ProtocolArgs *) protocolArgs;

    GT_assert(CURTRACE, protocolArgs);

    GT_2trace(CURTRACE, GT_ENTER, 
            "IRESMAN_EDMA3CHAN_getHandles> Enter (protocolArgs=0x%x, "
            "scratchGroupId=%d)\n", protocolArgs, scratchGroupId);

    if (_initialized != 1) {

        GT_0trace(CURTRACE, GT_7CLASS, 
                "IRESMAN_EDMA3CHAN_getHandles> RMAN_register call has not "
                "happened successfully\n. Please register EDMA3CHAN resource "
                "with RMAN before assigning resources\n");

        *status =  IRES_ENORESOURCE;
        return (NULL);
    }

    if (configArgs->mode == IRES_PERSISTENT) {
        scratchGroupId = -1;
    } else if (configArgs->mode == IRES_LATEACQUIRE) {
        //Set to MAX SCRATCH GROUPS
        scratchGroupId = EDMA3_LATEACQUIREGROUP;  
        GT_0trace(CURTRACE, GT_4CLASS,
                "IRESMAN_EDMA3CHAN_getHandles> Requested IRES_LATEACQUIRE "
                "HDVICP resources. Ensure you \"lock\" resources using "
                "IRES RESUTILS API before using them for correct operation\n");

    } 
    
    rmHandle = EDMA3_getResourceManager(algHandle, scratchGroupId);

    if (NULL == rmHandle) {

        *status =  IRES_ENORESOURCE;

        GT_0trace(CURTRACE, GT_7CLASS, 
                "IRESMAN_EDMA3CHAN_getHandles> Error obtaining Low level "
                "Resource Manager Handle.\n");

        GT_0trace(CURTRACE, GT_ENTER, 
                "IRESMAN_EDMA3CHAN_getHandles> Exit (handle=NULL, "
                "status=IRES_ENORESOURCE)\n");

        return (NULL);
    }

    if (EDMA3_SOK != EDMA3_getCCRegister( rmHandle , 4, &cccfg)) {

        *status =  IRES_EFAIL;

        GT_0trace(CURTRACE, GT_7CLASS, 
                "IRESMAN_EDMA3CHAN_getHandles> Error reading EDMA3's CCCFG "
                "Register.\n");

        GT_0trace(CURTRACE, GT_ENTER, 
                "IRESMAN_EDMA3CHAN_getHandles> Exit (handle=NULL, "
                "status=IRES_EFAIL)\n");

        if (EDMA3_SOK != EDMA3_releaseResourceManager(algHandle, 
                scratchGroupId)) {

            *status = IRES_EFAIL; 

            GT_0trace(CURTRACE, GT_7CLASS, 
                    "IRESMAN_EDMA3CHAN_getHandles> Error releasing Low level "
                    "Resource Manager Handle.\n");
        }

        return (NULL);
    }

    _dchmapExists = IRES_EDMA3CHAN_EDMA3REGISTERLAYER_CHMAPEXIST(cccfg);

    if (_dchmapExists) {

        GT_0trace(CURTRACE, GT_2CLASS,
                "IRESMAN_EDMA3CHAN_getHandles> DCHMAP exists on device ??\n"); 

        GT_assert(CURTRACE, 0);
    }

    numPaRams = configArgs->numPaRams;
    numTccs = configArgs->numTccs;

        GT_assert(CURTRACE, numPaRams <= IRES_EDMA3CHAN_MAXPARAMS);
        GT_assert(CURTRACE, numTccs <= IRES_EDMA3CHAN_MAXTCCS);

    reqEdma = configArgs->edmaChan;
    reqQdma = configArgs->qdmaChan;

    if (configArgs->numPaRams != 0) { 
        reqParam = configArgs->paRamIndex;
    }

    if (configArgs->numTccs != 0) {
        reqTcc = configArgs->tccIndex;
    }

    if (IRES_EDMA3CHAN_TCC_NONE == reqTcc) {
        GT_assert(CURTRACE, numTccs == 0);
    } 

    if (IRES_EDMA3CHAN_PARAM_NONE == reqParam) {
        GT_assert(CURTRACE, numPaRams == 0);
    } 

        if ((reqEdma != IRES_EDMA3CHAN_EDMACHAN_ANY) && 
                        (reqEdma != IRES_EDMA3CHAN_CHAN_NONE) && 
                        ((reqEdma < 0) || 
                        (reqEdma >= 64 ))) {

        GT_0trace(CURTRACE, GT_6CLASS,
                "IRESMAN_EDMA3CHAN_getHandles> Bad request for EDMA channel. "
                "Will not grant request EDMA channel\n");

                reqEdma = IRES_EDMA3CHAN_CHAN_NONE;               
        }

        if ((reqQdma != IRES_EDMA3CHAN_QDMACHAN_ANY) && 
                        (reqQdma != IRES_EDMA3CHAN_CHAN_NONE) && 
                        ((reqQdma < 0) ||
                        (reqQdma >= 8))) {

        GT_0trace(CURTRACE, GT_6CLASS,
                "IRESMAN_QDMA3CHAN_getHandles> Bad request for EDMA channel. "
                "Will not grant request QDMA channel\n");

                reqQdma = IRES_EDMA3CHAN_CHAN_NONE;               
        }

/*
  1. Couple request into Logical EDMA channel request 
  2. Couple request into Logical QDMA channel request
  3. Couple request  for multiple (or the rest of the paRams) into contigPaRams
     request
  4. Request rest of the QDMA channels required -> will waste resources
  5. Request rest of the TCCs required  -> will waste resources
*/

    if ((numPaRams > 0) && (numTccs > 0)) {

        /* 1. */
        if (IRES_EDMA3CHAN_CHAN_NONE != reqEdma) {

            /* If request is for EDMA N, then PaRam and TCC should be requested                of the same number or ANY */
            if ((reqEdma != IRES_EDMA3CHAN_EDMACHAN_ANY) && 
                    ((IRES_EDMA3CHAN_PARAM_ANY == reqParam) || 
                     (reqEdma == reqParam)) && 
                    ((IRES_EDMA3CHAN_TCC_ANY == reqTcc) || 
                     (reqEdma == reqTcc))) {
    
                /* Allocate Logical E Channel N and decrement numTccs and 
                   numPaRams and change reqEdma to NONE ? */ 
                resObj.type = EDMA3_RES_DMA_CHANNEL; 
                resObj.resId = reqEdma;
                tccArray[toFreeTccs] = reqEdma;  /* Requesting tcc == edma */ 
                paRamArray[toFreeParams] = reqEdma;
    
                if (EDMA3_SOK != EDMA3_allocLogicalChannel(rmHandle, 
                        &resObj, (unsigned int *)&paRamArray[toFreeParams], 
                        (unsigned int *)&tccArray[toFreeTccs])) {

                    *status =  IRES_ENORESOURCE;
                    goto getResmanHandleFail;
                }
                edma3Chan = resObj.resId;
                toFreeParams++;
                toFreeTccs++;
                numPaRams--;
                numTccs--;
                reqEdma = IRES_EDMA3CHAN_CHAN_NONE;
            }

            /* If request is for EDMA ANY and P N or ANY and TCC N or any */
            else if ((IRES_EDMA3CHAN_TCC_ANY == reqTcc) || 
                    (reqParam == IRES_EDMA3CHAN_PARAM_ANY) ||
                    (reqParam == reqTcc)) {
    
                /* Allocate logical E Channel #"TCC/PaRAM/ANY" and decrement 
                   numTccs and numPaRams */
                resObj.type = EDMA3_RES_DMA_CHANNEL; 
                resObj.resId = ((IRES_EDMA3CHAN_PARAM_ANY == 
                        reqParam) ?  
                        ((IRES_EDMA3CHAN_TCC_ANY == reqTcc) ? 
                        EDMA3_RES_ANY : reqTcc) : 
                        reqParam);
                tccArray[toFreeTccs] = resObj.resId; /* Requesting tcc = edma */
                paRamArray[toFreeParams] = resObj.resId;
                
                if (EDMA3_SOK != EDMA3_allocLogicalChannel(rmHandle, 
                        &resObj, (unsigned int *)&paRamArray[toFreeParams], 
                        (unsigned int *)&tccArray[toFreeTccs])) {

                    *status =  IRES_ENORESOURCE;
                    goto getResmanHandleFail;
                }
                edma3Chan = resObj.resId;
                toFreeParams++;
                toFreeTccs++;
                numPaRams--;
                numTccs--;
                reqEdma = IRES_EDMA3CHAN_CHAN_NONE;
                /* If a logical channel was requested, then any other param 
                   request cannot have a specific param number */ 
                reqParam = IRES_EDMA3CHAN_PARAM_ANY;
                reqTcc = IRES_EDMA3CHAN_TCC_ANY;
            }
        }
        /* 2. */
        else if (IRES_EDMA3CHAN_CHAN_NONE != reqQdma) {
            
            /* If request is for QDMA N  or QDMA Any, P should be ANY */
            if (IRES_EDMA3CHAN_PARAM_ANY == reqParam) {
    
                 /* Allocate Logical Q Channel N and decrement numTccs and 
                    numPaRams */ 
                resObj.type = EDMA3_RES_QDMA_CHANNEL; 
                resObj.resId = ((IRES_EDMA3CHAN_QDMACHAN_ANY == reqQdma) ?  
                        EDMA3_RES_ANY : reqQdma);
                /* Requesting tcc as required*/ 
                tccArray[toFreeTccs] = 
                        (IRES_EDMA3CHAN_TCC_ANY == reqTcc) ? 
                        EDMA3_RES_ANY : reqTcc; 

                paRamArray[toFreeParams] = EDMA3_RES_ANY; 
                if (EDMA3_SOK != EDMA3_allocLogicalChannel(rmHandle, 
                        &resObj, (unsigned int *)&paRamArray[toFreeParams], 
                        (unsigned int *)&tccArray[toFreeTccs])) {

                    *status =  IRES_ENORESOURCE;
                    goto getResmanHandleFail;
                }
                qdmaChan = resObj.resId;
                toFreeParams++;
                toFreeTccs++;
                numPaRams--;
                numTccs--;
                reqQdma = IRES_EDMA3CHAN_CHAN_NONE;
                /* If a logical channel was requested, then any other param 
                   request cannot have a specific param number */ 
                reqParam = IRES_EDMA3CHAN_PARAM_ANY;
                reqTcc = IRES_EDMA3CHAN_TCC_ANY;
            }
        }
    }

    /* 3. */
    /* Alloc contiguous or Not P */
    if (numPaRams > 0) {

        resObj.type = EDMA3_RES_PARAM_SET;

        if ((numPaRams > 1) && configArgs->contiguousAllocation) {

            GT_0trace(CURTRACE, GT_4CLASS,
                    "IRESMAN_EDMA3CHAN_getHandles> Contiguous PaRams "
                    "requested\n"); 

            resObj.resId = (reqParam == 
                    IRES_EDMA3CHAN_PARAM_ANY)? EDMA3_RES_ANY: 
                    reqParam;

            if (EDMA3_SOK != EDMA3_allocContiguousResource(
                    rmHandle, &resObj, numPaRams)) {

                    *status =  IRES_ENORESOURCE;
                    goto getResmanHandleFail;
            }
            else {

                for (i = 0; i < numPaRams; i++) {
                    paRamArray[i+toFreeParams] = resObj.resId + i;
                }

                GT_2trace(CURTRACE, GT_4CLASS,
                        "IRESMAN_EDMA3CHAN_getHandles> Obtained %d PaRams "
                        "starting at %d \n", numPaRams, 
                        paRamArray[toFreeParams]); 

                toFreeParams += numPaRams;
            }

            numPaRams = 0; 
        }
        else {

            GT_0trace(CURTRACE, GT_4CLASS,
                    "IRESMAN_EDMA3CHAN_getHandles> Contiguous PaRams "
                    "NOT required\n"); 

            if (numPaRams == 1) {

                resObj.resId =(reqParam == 
                        IRES_EDMA3CHAN_PARAM_ANY)? EDMA3_RES_ANY:
                        reqParam;
            }
            else {
                /* Multiple non-contig PaRams should always be requested as
                   ANY */
                resObj.resId = EDMA3_RES_ANY;
            }

            /*
             * Allocate the PaRams individually
             */
            for (i = 0; i < numPaRams; i++) {

                if (EDMA3_SOK != EDMA3_allocResource( rmHandle,&resObj)) {

                    *status =  IRES_ENORESOURCE;
                    goto getResmanHandleFail;
                }
                else {

                    paRamArray[toFreeParams] = resObj.resId;
    
                    GT_1trace(CURTRACE, GT_4CLASS, 
                            "IRESMAN_EDMA3CHAN_getHandles> Obtained Param %d\n"
                            , paRamArray[toFreeParams]);

                    toFreeParams++;
                    resObj.resId = EDMA3_RES_ANY;
                }
            }
            numPaRams = 0;
        }
    }

    /* 4 */
    if (IRES_EDMA3CHAN_CHAN_NONE != reqEdma) {

        resObj.type = EDMA3_RES_DMA_CHANNEL;
        resObj.resId = ( IRES_EDMA3CHAN_EDMACHAN_ANY == reqEdma) ? 
                EDMA3_RES_ANY: reqEdma; 

        GT_1trace(CURTRACE, GT_2CLASS, 
                "IRESMAN_EDMA3CHAN_getHandles> Requesting individual EDMA "
                "channel %d, might cause resource wastage !\n", resObj.resId);

        if (EDMA3_SOK != EDMA3_allocResource( rmHandle,&resObj)) {

            *status =  IRES_ENORESOURCE;
            goto getResmanHandleFail;
        }
        reqEdma = IRES_EDMA3CHAN_CHAN_NONE;
        edma3Chan = resObj.resId;
            
    }

    if (IRES_EDMA3CHAN_CHAN_NONE != reqQdma) {

        resObj.type = EDMA3_RES_QDMA_CHANNEL;
        resObj.resId = (IRES_EDMA3CHAN_QDMACHAN_ANY == reqQdma) ? 
                EDMA3_RES_ANY: reqQdma; 

        GT_1trace(CURTRACE, GT_2CLASS, 
                "IRESMAN_EDMA3CHAN_getHandles> Requesting individual Qdma "
                "channel %d, might cause resource wastage !\n", resObj.resId);

        if (EDMA3_SOK != EDMA3_allocResource( rmHandle,&resObj)) {

            *status =  IRES_ENORESOURCE;
            goto getResmanHandleFail;
        }

        reqQdma = IRES_EDMA3CHAN_CHAN_NONE;
        qdmaChan = resObj.resId;
    }

    if (numTccs > 0) {

         resObj.type = EDMA3_RES_TCC;

        if ((toFreeTccs > 0) || (numTccs > 1)) {
            /* If requesting multiple TCCs then use ANY to request */
            resObj.resId = EDMA3_RES_ANY;
        }
        else {
            resObj.resId = ((reqTcc == IRES_EDMA3CHAN_TCC_ANY)?
                    EDMA3_RES_ANY:((unsigned int)reqTcc));
        }
    
        GT_1trace(CURTRACE, GT_2CLASS, 
                "IRESMAN_EDMA3CHAN_getHandles> Requesting %d individual Tcc(s),"
                "might cause resource wastage !\n", numTccs);

        for(i = 0 ; i < numTccs; i++) {

            if (EDMA3_SOK != EDMA3_allocResource( rmHandle, &resObj)) {

                *status =  IRES_ENORESOURCE;
                goto getResmanHandleFail;
            }

            tccArray[toFreeTccs] = resObj.resId;
                        resObj.resId = EDMA3_RES_ANY;

            GT_1trace(CURTRACE, GT_4CLASS,
                    "IRESMAN_EDMA3CHAN_getHandles> Obtained TCC %d\n", 
                    tccArray[toFreeTccs]); 

            toFreeTccs++;
        }

        numTccs = 0;
    }


    /* Do construct handle stuff here */
    /*
     * To call the Construct handle protocol interface, first construct the 
     * arguments that need to be passed IRES_EDMA3CHAN_ConstructHandleArgs
     * This has the list of actual params that need to be sent back as handle 
     */

    /*
     * Allocate memory for the constructHandle Arguments
     */
    constructHandleMemRec.size = sizeof(IRESMAN_EDMA3CHAN_ConstructHandleArgs);
    constructHandleMemRec.alignment = 4;
    constructHandleMemRec.space = IALG_EXTERNAL;
    constructHandleMemRec.attrs = IALG_PERSIST;

    if (FALSE == _allocFxn(&constructHandleMemRec, 1)) {

        *status =  IRES_ENOMEM;

        GT_1trace(CURTRACE, GT_7CLASS, 
                "IRESMAN_EDMA3CHAN_getHandles> Memory allocation for size 0x%x,"
                " of Persistent External memory failed\n",  
                constructHandleMemRec.size);

        goto getResmanHandleFail;
    }
    GT_assert(CURTRACE, IALG_EXTERNAL == constructHandleMemRec.space);

    constructArgs = constructHandleMemRec.base; 
    constructArgs->numPaRams = toFreeParams;
    constructArgs->paRamIndex = paRamArray;
    constructArgs->edma3Chan = edma3Chan;
    constructArgs->qdmaChan = qdmaChan;
    constructArgs->tccIndex = tccArray;
        constructArgs->numTccs = toFreeTccs;

    if (scratchGroupId == -1) { 
        constructArgs->persistent = TRUE;
    }
    else {
        constructArgs->persistent = FALSE;
    }

    if ( EDMA3_SOK != EDMA3_getBaseAddress(rmHandle, EDMA3_CC_PHY_ADDR,
            &(constructArgs->edma3CCBaseAddress))) {

        _freeFxn(&constructHandleMemRec, 1); 

        GT_0trace(CURTRACE, GT_7CLASS, 
                "IRESMAN_EDMA3CHAN_getHandles> Call to obtain base address "
                "of EDMA3 device failed\n");  

        *status =  IRES_EFAIL;

        goto getResmanHandleFail;
    }

    /*
     * Get IRES_EDMA3CHAN_RESOURCEPROTOCOL's memory requirements
     */
    numMemRecs = IRESMAN_EDMA3CHAN_CONSTRUCTFXNS.getNumMemRecs
            ((IRES_ProtocolArgs *) protocolArgs);

    GT_assert(CURTRACE, numMemRecs <= IRESMAN_PROTOCOL_EDMA3CHAN_MAX_MEMRECS);

    /*
     * Get the memory requirements of the protocol in resMemRecs
     */
    IRESMAN_EDMA3CHAN_CONSTRUCTFXNS.getMemRecs((IRES_Handle)NULL,
            (IRES_ProtocolArgs *) protocolArgs, protocolMemRecs);

    /*
     * Allocate that memory 
     */
    if (FALSE == _allocFxn(protocolMemRecs, numMemRecs)) {

        _freeFxn(&constructHandleMemRec, 1); 

        *status = IRES_ENOMEM;

        GT_1trace(CURTRACE, GT_7CLASS, 
                "IRESMAN_EDMA3CHAN_getHandles> Memory allocation for size 0x%x,"
                " of Persistent External memory failed\n",  
                protocolMemRecs[0].size);

        goto getResmanHandleFail;
    }

    for (i=0; i < numMemRecs; i++) {
        GT_assert(CURTRACE, protocolMemRecs[i].space == IALG_EXTERNAL);
    }

    /*
     * Construct the resource protocol handle
     */
    resourceHandle = IRESMAN_EDMA3CHAN_CONSTRUCTFXNS.constructHandle(
             protocolArgs, protocolMemRecs, 
             (IRESMAN_ConstructArgs *)constructArgs, status); 

    GT_assert(CURTRACE, resourceHandle != NULL);

    /*
     * Free constructArgs memory, that was just to pass the arguments
     */
    _freeFxn(&constructHandleMemRec, 1); 

    *status = IRES_OK;

    GT_1trace(CURTRACE, GT_ENTER, 
           "IRESMAN_EDMA3CHAN_getHandles> Exit (handle=0x%x, "
           "status=IRES_OK)\n", resourceHandle);

    /* return */
    return (resourceHandle);

getResmanHandleFail:

    /* fail code comes here, free resources and leave */
    _freeResource(algHandle, scratchGroupId, edma3Chan, qdmaChan, toFreeParams, 
            paRamArray, toFreeTccs, tccArray, configArgs->contiguousAllocation);

    GT_2trace(CURTRACE, GT_7CLASS, 
            "IRESMAN_EDMA3CHAN_getHandles> Could not allocate requested "
            "resource of type %d Id %d\n", resObj.type, resObj.resId);

    if (EDMA3_SOK != EDMA3_releaseResourceManager(algHandle, 
        scratchGroupId)) {

        *status = IRES_EFAIL; 

        GT_0trace(CURTRACE, GT_7CLASS, 
                "IRESMAN_EDMA3CHAN_getHandles> Error releasing Low "
                "level Resource Manager Handle.\n");
    }

    *status =  IRES_ENORESOURCE;

    GT_1trace(CURTRACE, GT_ENTER, 
            "IRESMAN_EDMA3CHAN_getHandles> Exit (handle=NULL, status=%d)\n", 
            *status);

    return (NULL);
}
Beispiel #2
0
/*
 *  ======== Memory_free ========
 */
Bool Memory_free(Ptr addr, UInt size, Memory_AllocParams *params)
{
    GT_2trace(curTrace, GT_ENTER, "Memory_free(0x%lx, 0x%lx)\n", addr, size);

    return (Memory_segFree(DEFAULTSEGMENT, addr, size));
}
Beispiel #3
0
/*!
 *  @brief  Function to invoke the APIs through ioctl.
 *
 *  @param  cmd     Command for driver ioctl
 *  @param  args    Arguments for the ioctl command
 *
 *  @sa
 */
Int
NotifyDrvUsr_ioctl (UInt32 cmd, Ptr args)
{
    Int status      = Notify_S_SUCCESS;
    int osStatus    = -1;

    GT_2trace (curTrace, GT_ENTER, "NotifyDrvUsr_ioctl", cmd, args);

    GT_assert (curTrace, (NotifyDrvUsr_refCount > 0));

	 switch (cmd) {

			case CMD_NOTIFY_SENDEVENT:
			{
				 osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_SENDEVENT, args, sizeof(Notify_CmdArgsSendEvent), NULL);
			}
			break;

			case CMD_NOTIFY_DISABLE:
			{
				 osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_DISABLE, args, sizeof(Notify_CmdArgsDisable), NULL);
			}
			break;

			case CMD_NOTIFY_RESTORE:
			{
				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_RESTORE, args, sizeof(Notify_CmdArgsRestore), NULL);
			}
			break;

			case CMD_NOTIFY_DISABLEEVENT:
			{
				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_DISABLEEVENT, args, sizeof(Notify_CmdArgsDisableEvent), NULL);
			}
			break;

			case CMD_NOTIFY_ENABLEEVENT:
			{
				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_ENABLEEVENT, args, sizeof(Notify_CmdArgsEnableEvent), NULL);
			}
			break;

			case CMD_NOTIFY_REGISTEREVENTSINGLE:
			{
				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_REGISTEREVENTSINGLE, args, sizeof(Notify_CmdArgsRegisterEvent), NULL);
			}
			break;

			case CMD_NOTIFY_REGISTEREVENT:
			{

				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_REGISTEREVENT, args, sizeof(Notify_CmdArgsRegisterEvent), NULL);
			}
			break;

			case CMD_NOTIFY_UNREGISTEREVENTSINGLE:
			{
				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_UNREGISTEREVENTSINGLE, args, sizeof(Notify_CmdArgsUnregisterEvent), NULL);
			}
			break;

			case CMD_NOTIFY_UNREGISTEREVENT:
			{
				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_UNREGISTEREVENT, args, sizeof(Notify_CmdArgsUnregisterEvent), NULL);
			}
			break;

			case CMD_NOTIFY_GETCONFIG:
			{
				Notify_CmdArgsGetConfig *cargs = (Notify_CmdArgsGetConfig *)args;

				iov_t notify_getconfig_iov[2];

				SETIOV( &notify_getconfig_iov[0], cargs, sizeof(Notify_CmdArgsGetConfig) );
				SETIOV( &notify_getconfig_iov[1], cargs->cfg, sizeof(Notify_Config) );

				/* the osal_drv handle is used instead of ipcdrv_handle as the ipcdrc_handle is not yet initialized */
				osStatus = devctlv( OsalDrv_handle, DCMD_NOTIFY_GETCONFIG, 2, 2, notify_getconfig_iov, notify_getconfig_iov, NULL);
			}
			break;

			case CMD_NOTIFY_SETUP:
			{

				Notify_CmdArgsSetup *cargs = (Notify_CmdArgsSetup *)args;

				iov_t notify_setup_iov[2];

				SETIOV( &notify_setup_iov[0], cargs, sizeof(Notify_CmdArgsSetup) );
				SETIOV( &notify_setup_iov[1], cargs->cfg, sizeof(Notify_Config) );

				osStatus = devctlv( IpcDrv_handle, DCMD_NOTIFY_SETUP, 2, 2, notify_setup_iov, notify_setup_iov, NULL);
			}
			break;

			case CMD_NOTIFY_DESTROY:
			{
				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_DESTROY, args, sizeof(Notify_CmdArgsDestroy), NULL);
			}
			break;
			case CMD_NOTIFY_ATTACH:
			{
				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_ATTACH, args, sizeof(Notify_CmdArgsAttach), NULL);
			}
			break;
			case CMD_NOTIFY_DETACH:
			{
				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_DETACH, args, sizeof(Notify_CmdArgsDetach), NULL);
			}
			break;
			case CMD_NOTIFY_SHAREDMEMREQ:
			{
				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_SHAREDMEMREQ, args, sizeof(Notify_CmdArgsSharedMemReq), NULL);
			}
			break;

			case CMD_NOTIFY_INTLINEREGISTERED:
			{

				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_INTLINEREGISTERED, args, sizeof(Notify_CmdArgsIntLineRegistered), NULL);
			}
			break;

			case CMD_NOTIFY_EVENTAVAILABLE:
			{

				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_EVENTAVAILABLE, args, sizeof(Notify_CmdArgsEventAvailable), NULL);
			}
			break;

			case CMD_NOTIFY_THREADATTACH:
			{
				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_THREADATTACH, args, sizeof(Notify_CmdArgsThreadAttach), NULL);
			}
			break;

			case CMD_NOTIFY_THREADDETACH:
			{

				osStatus = devctl( IpcDrv_handle, DCMD_NOTIFY_THREADDETACH, args, sizeof(Notify_CmdArgsThreadDetach), NULL);
			}
			break;

			default:
			{
				/* This does not impact return status of this function, so retVal
				 * comment is not used.
				 */
				status = Notify_E_INVALIDARG;
				GT_setFailureReason (curTrace,
									 GT_4CLASS,
									 "NotifyDrv_ioctl",
									 status,
									 "Unsupported ioctl command specified");
			}
			break;
		}


    if (osStatus != 0) {
        /*! @retval Notify_E_OSFAILURE Driver ioctl failed */
        status = Notify_E_OSFAILURE;
        GT_setFailureReason (curTrace,
                             GT_4CLASS,
                             "NotifyDrvUsr_ioctl",
                             status,
                             "Driver ioctl failed!");
    }
    else {
        /* First field in the structure is the API status. */
        status = ((Notify_CmdArgs *) args)->apiStatus; // TODO: THIS WILL NEED TO BE MODIFIED FOR IOCTL THAT DO NOT USE COMMOM CMD ARGS
    }

    GT_1trace(curTrace, GT_LEAVE, "NotifyDrvUsr_ioctl", status);

    return status;
}
Beispiel #4
0
/*
 *  ======== control ========
 *  This is the stub-implementation for the control method
 */
static XDAS_Int32 control(ISPHDEC_Handle h, ISPHDEC_Cmd id,
     ISPHDEC_DynamicParams *params, ISPHDEC_Status *status)
{
    XDAS_Int32 retVal;
    VISA_Handle visa = (VISA_Handle)h;
    _SPHDEC_Msg *msg;
    ISPHDEC_Status *pMsgStatus;
    Int payloadSize;

    /*
     * Validate arguments.  Do we want to do this _every_ time, or just in
     * checked builds?
     */
    if ((params == NULL) || (params->size < sizeof(ISPHDEC_DynamicParams)) ||
        (status == NULL) || (status->size < sizeof(ISPHDEC_Status))) {

        /* invalid args, could even assert here, it's a spec violation. */
        return (SPHDEC_EFAIL);
    }

    /* make sure it'll all fit! */
    payloadSize = sizeof(VISA_MsgHeader) + sizeof(id) + params->size +
            status->size;

    if (payloadSize > VISA_getMaxMsgSize(visa)) {
        /* Can't handle these large extended args. */
        GT_2trace(CURTRACE, GT_6CLASS,
                "process> invalid arguments - too big (0x%x > 0x%x).  "
                "Validate .size fields\n", payloadSize,
                VISA_getMaxMsgSize(visa));

        return (SPHDEC_EFAIL);
    }

    /* get a message appropriate for this algorithm */
    if ((msg = (_SPHDEC_Msg *)VISA_allocMsg(visa)) == NULL) {
        return (ISPHDEC_ERUNTIME);
    }

    /* marshall the command */
    msg->visa.cmd = _SPHDEC_CCONTROL;

    msg->cmd.control.id = id;

    /* params has no pointers so simply memcpy "size" bytes into the msg */
    memcpy(&(msg->cmd.control.params), params, params->size);

    /* unmarshall status based on the "size" of params */
    pMsgStatus = (ISPHDEC_Status *)((UInt)(&(msg->cmd.control.params)) +
        params->size);

    /* set the size field - the rest is filled in by the codec */
    /* TODO:H probably want to zero out the rest of the status struct */
    pMsgStatus->size = status->size;

    /* send the message to the skeleton and wait for completion */
    retVal = VISA_call(visa, (VISA_Msg *)&msg);

    /* ensure we get CCONTROL msg (ensure async CPROCESS pipeline drained) */
    GT_assert(CURTRACE, msg->visa.cmd == _SPHDEC_CCONTROL);

    /* unmarshall status */
    pMsgStatus = (ISPHDEC_Status *)((UInt)(&(msg->cmd.control.params)) +
        params->size);

    if (VISA_isChecked()) {
        /* ensure codec didn't modify status->size */
        GT_assert(CURTRACE, pMsgStatus->size == status->size);
    }
    memcpy(status, pMsgStatus, status->size);

    VISA_freeMsg(visa, (VISA_Msg)msg);

    return (retVal);
}
Beispiel #5
0
/*
 *  ======== STRM_Open ========
 *  Purpose:
 *      Open a stream for sending/receiving data buffers to/from a task or
 *      XDAIS socket node on the DSP.
 */
DSP_STATUS STRM_Open(struct NODE_OBJECT *hNode, u32 uDir, u32 uIndex,
		    IN struct STRM_ATTR *pAttr, OUT struct STRM_OBJECT **phStrm)
{
	struct STRM_MGR *hStrmMgr;
	struct WMD_DRV_INTERFACE *pIntfFxns;
	u32 ulChnlId;
	struct STRM_OBJECT *pStrm = NULL;
	CHNL_MODE uMode;
	struct CHNL_ATTRS chnlAttrs;
	DSP_STATUS status = DSP_SOK;
	struct CMM_OBJECT *hCmmMgr = NULL;	/* Shared memory manager hndl */

	#ifndef RES_CLEANUP_DISABLE
	DSP_STATUS res_status = DSP_SOK;
       u32                  hProcess;
	HANDLE	     pCtxt = NULL;
	HANDLE	     hDrvObject;
	HANDLE 		    hSTRMRes;
	#endif
	DBC_Require(cRefs > 0);
	DBC_Require(phStrm != NULL);
	DBC_Require(pAttr != NULL);
	GT_5trace(STRM_debugMask, GT_ENTER,
		 "STRM_Open: hNode: 0x%x\tuDir: 0x%x\t"
		 "uIndex: 0x%x\tpAttr: 0x%x\tphStrm: 0x%x\n",
		 hNode, uDir, uIndex, pAttr, phStrm);
	*phStrm = NULL;
	if (uDir != DSP_TONODE && uDir != DSP_FROMNODE) {
		status = DSP_EDIRECTION;
	} else {
		/* Get the channel id from the node (set in NODE_Connect()) */
		status = NODE_GetChannelId(hNode, uDir, uIndex, &ulChnlId);
	}
	if (DSP_SUCCEEDED(status))
		status = NODE_GetStrmMgr(hNode, &hStrmMgr);

	if (DSP_SUCCEEDED(status)) {
		MEM_AllocObject(pStrm, struct STRM_OBJECT, STRM_SIGNATURE);
		if (pStrm == NULL) {
			status = DSP_EMEMORY;
			GT_0trace(STRM_debugMask, GT_6CLASS,
				 "STRM_Open: MEM_AllocObject() failed!\n ");
		} else {
			pStrm->hStrmMgr = hStrmMgr;
			pStrm->uDir = uDir;
			pStrm->strmState = STREAM_IDLE;
			pStrm->hUserEvent = pAttr->hUserEvent;
			if (pAttr->pStreamAttrIn != NULL) {
				pStrm->uTimeout = pAttr->pStreamAttrIn->
						  uTimeout;
				pStrm->uNumBufs = pAttr->pStreamAttrIn->
						  uNumBufs;
				pStrm->lMode = pAttr->pStreamAttrIn->lMode;
				pStrm->uSegment = pAttr->pStreamAttrIn->
						  uSegment;
				pStrm->uAlignment = pAttr->pStreamAttrIn->
						    uAlignment;
				pStrm->uDMAChnlId = pAttr->pStreamAttrIn->
						    uDMAChnlId;
				pStrm->uDMAPriority = pAttr->pStreamAttrIn->
						      uDMAPriority;
				chnlAttrs.uIOReqs = pAttr->pStreamAttrIn->
						    uNumBufs;
			} else {
				pStrm->uTimeout = DEFAULTTIMEOUT;
				pStrm->uNumBufs = DEFAULTNUMBUFS;
				pStrm->lMode = STRMMODE_PROCCOPY;
				pStrm->uSegment = 0;	/* local memory */
				pStrm->uAlignment = 0;
				pStrm->uDMAChnlId = 0;
				pStrm->uDMAPriority = 0;
				chnlAttrs.uIOReqs = DEFAULTNUMBUFS;
			}
			chnlAttrs.hReserved1 = NULL;
			/* DMA chnl flush timeout */
			chnlAttrs.hReserved2 = pStrm->uTimeout;
			chnlAttrs.hEvent = NULL;
			if (pAttr->hUserEvent != NULL)
				chnlAttrs.hEvent = pAttr->hUserEvent;

		}
	}
	if (DSP_FAILED(status))
		goto func_cont;

	if ((pAttr->pVirtBase == NULL) || !(pAttr->ulVirtSize > 0))
		goto func_cont;

	DBC_Assert(pStrm->lMode != STRMMODE_LDMA);	/* no System DMA */
	/* Get the shared mem mgr for this streams dev object */
	status = DEV_GetCmmMgr(hStrmMgr->hDev, &hCmmMgr);
	if (DSP_FAILED(status)) {
		GT_1trace(STRM_debugMask, GT_6CLASS, "STRM_Open: Failed to get "
			 "CMM Mgr handle: 0x%x\n", status);
	} else {
		/*Allocate a SM addr translator for this strm.*/
		status = CMM_XlatorCreate(&pStrm->hXlator, hCmmMgr, NULL);
		if (DSP_FAILED(status)) {
			GT_1trace(STRM_debugMask, GT_6CLASS,
				 "STRM_Open: Failed to "
				 "create SM translator: 0x%x\n", status);
		} else {
			DBC_Assert(pStrm->uSegment > 0);
			/*  Set translators Virt Addr attributes */
			status = CMM_XlatorInfo(pStrm->hXlator,
				 (u8 **)&pAttr->pVirtBase, pAttr->ulVirtSize,
				 pStrm->uSegment, true);
			if (status != DSP_SOK) {
				GT_0trace(STRM_debugMask, GT_6CLASS,
					 "STRM_Open: ERROR: "
					 "in setting CMM_XlatorInfo.\n");
			}
		}
	}
func_cont:
	if (DSP_SUCCEEDED(status)) {
		/* Open channel */
		uMode = (uDir == DSP_TONODE) ?
			CHNL_MODETODSP : CHNL_MODEFROMDSP;
		pIntfFxns = hStrmMgr->pIntfFxns;
		status = (*pIntfFxns->pfnChnlOpen) (&(pStrm->hChnl),
			 hStrmMgr->hChnlMgr, uMode, ulChnlId, &chnlAttrs);
		if (DSP_FAILED(status)) {
			/*
			 * over-ride non-returnable status codes so we return
			 * something documented
			 */
			if (status != DSP_EMEMORY && status !=
			   DSP_EINVALIDARG && status != DSP_EFAIL) {
				/*
				 * We got a status that's not return-able.
				 * Assert that we got something we were
				 * expecting (DSP_EHANDLE isn't acceptable,
				 * hStrmMgr->hChnlMgr better be valid or we
				 * assert here), and then return DSP_EFAIL.
				 */
				DBC_Assert(status == CHNL_E_OUTOFSTREAMS ||
					   status == CHNL_E_BADCHANID ||
					   status == CHNL_E_CHANBUSY ||
					   status == CHNL_E_NOIORPS);
				status = DSP_EFAIL;
			}
			GT_2trace(STRM_debugMask, GT_6CLASS,
				  "STRM_Open: Channel open failed, "
				  "chnl id = %d, status = 0x%x\n", ulChnlId,
				  status);
		}
	}
	if (DSP_SUCCEEDED(status))
		*phStrm = pStrm;
	else
		(void)DeleteStrm(pStrm);

#ifndef RES_CLEANUP_DISABLE
       /* Return PID instead of process handle */
       hProcess = current->pid;

	res_status = CFG_GetObject((u32 *)&hDrvObject, REG_DRV_OBJECT);
	if (DSP_SUCCEEDED(res_status)) {
               DRV_GetProcContext(hProcess,
				 (struct DRV_OBJECT *)hDrvObject, &pCtxt,
				 hNode, 0);
		if (pCtxt != NULL)
			DRV_ProcInsertSTRMResElement(*phStrm, &hSTRMRes, pCtxt);

	}
#endif

	 /* ensure we return a documented error code */
	DBC_Ensure((DSP_SUCCEEDED(status) &&
		  MEM_IsValidHandle((*phStrm), STRM_SIGNATURE)) ||
		  (*phStrm == NULL && (status == DSP_EHANDLE ||
		  status == DSP_EDIRECTION || status == DSP_EVALUE ||
		  status == DSP_EFAIL)));
	return status;
}
Beispiel #6
0
/*
 *  ======== SPHENC_process ========
 *  This method must be the same for both local and remote invocation;
 *  each call site in the client might be calling different implementations
 *  (one that marshalls & sends and one that simply calls).  This API
 *  abstracts *all* speech encoders (both high and low complexity
 *  encoders are invoked using this method).
 */
XDAS_Int32 SPHENC_process(SPHENC_Handle handle, XDM_BufDesc *inBufs,
        XDM_BufDesc *outBufs, ISPHENC_InArgs *inArgs, ISPHENC_OutArgs *outArgs)
{
    XDAS_Int32 retVal = SPHENC_EFAIL;

    SPHENC_InArgs refInArgs;

    /*
     * Note, we assign "VISA_isChecked()" results to a local variable
     * rather than repeatedly query it throughout this fxn because
     * someday we may allow dynamically changing the global
     * 'VISA_isChecked()' value on the fly.  If we allow that, we need
     * to ensure the value stays consistent in the context of this
     * call.
     */
    Bool checked = VISA_isChecked();

    if (checked) {
        /* Ensure inArgs and outArgs are non-NULL, per the XDM spec */

        if ((!(XdmUtils_validateExtendedStruct(inArgs, sizeof(*inArgs),
                "inArgs"))) || (!(XdmUtils_validateExtendedStruct(outArgs,
                sizeof(*outArgs), "outArgs")))) {
            /* for safety, return here before dereferencing and crashing */
            return (retVal);
        }
    }

    GT_5trace(CURTRACE, GT_ENTER, "SPHENC_process> "
        "Enter (handle=0x%x, inBufs=0x%x, outBufs=0x%x, inArgs=0x%x, "
        "outArgs=0x%x)\n", handle, inBufs, outBufs, inArgs, outArgs);

    if (handle) {
        ISPHENC_Fxns *fxns =
            (ISPHENC_Fxns *)VISA_getAlgFxns((VISA_Handle)handle);
        ISPHENC_Handle alg = VISA_getAlgHandle((VISA_Handle)handle);

        if ((fxns != NULL) && (alg != NULL)) {
            Log_printf(ti_sdo_ce_dvtLog, "%s", (Arg)"SPHENC:process",
                (Arg)handle, (Arg)0);

            if (checked) {
                /*
                 * Zero out the outArgs struct (except for .size field);
                 * it's write-only to the codec, so the app shouldn't pass
                 * values through it, nor should the codec expect to
                 * receive values through it.
                 */
                memset((void *)((XDAS_Int32)(outArgs) + sizeof(outArgs->size)),
                    0, (sizeof(*outArgs) - sizeof(outArgs->size)));

                /*
                 * Make a reference copy of inArgs so we can check that
                 * the codec didn't modify them during process().
                 */
                refInArgs = *inArgs;
            }

            VISA_enter((VISA_Handle)handle);
            retVal = fxns->process(alg, inBufs, outBufs, inArgs, outArgs);
            VISA_exit((VISA_Handle)handle);

            if (checked) {
                /* ensure the codec didn't modify the read-only inArgs */
                if (memcmp(&refInArgs, inArgs, sizeof(*inArgs)) != 0) {
                    GT_1trace(CURTRACE, GT_7CLASS,
                        "ERROR> codec (0x%x) modified read-only inArgs "
                        "struct!\n", handle);
                }
            }

        }
    }

    GT_2trace(CURTRACE, GT_ENTER, "SPHENC_process> "
        "Exit (handle=0x%x, retVal=0x%x)\n", handle, retVal);

    return (retVal);
}
Beispiel #7
0
/*
 *  ======== modifyDefaultLinkCfgObjectBasedOnUserCfgData ========
 */
static Void modifyDefaultLinkCfgObjectBasedOnUserCfgData( String serverName )
{
    LINKCFG_MemEntry *  linkcfgMemTable;
    LINKCFG_MemEntry *  e;
    static LINKCFG_MemEntry * linkcfgMemTables[] = { NULL /* to be set */ };
    Global_ArmDspLinkConfig * armDspLinkConfig = NULL;
    Global_ArmDspLinkConfigMemTableEntry *mte;
    DSP_BootMode    staticCfgDspCtl;
    DSP_BootMode    newCfgDspCtl;
    Int    serverNameIndex;
    UInt32 cmemPhysBase;
    size_t cmemSize;
    Int    status;

    /* MODIFY MEMORY CONFIGURATION */
    CMEM_BlockAttrs   blockAttrs;
    Int    numMemTableEntries, i = 0;
    Int    numMemEntries = 0;
    Int    memEntryIdx;
    Int    numCmemBlocks = 0;
    Bool   addCmemBlocks = FALSE;

    /* first locate our server in the list of server names */
    for (serverNameIndex = 0;;serverNameIndex++) {
        if (!strcmp(ti_sdo_ce_ipc_armDspLinkConfigServerNames[serverNameIndex],
            serverName)) {
                break;
        }
        if (ti_sdo_ce_ipc_armDspLinkConfigServerNames[serverNameIndex] ==
            NULL ) {
            GT_1trace(curTrace, GT_7CLASS, "Processor_create_d> "
                "ERROR: Cannot find DspLink configuration data for the server "
                "named '%s' -- verify that the name was specified correctly in "
                "the application configuration file.\n", serverName);
            return;
        }
    }

    GT_2trace(curTrace, GT_2CLASS, "Processor_create_d> "
        "Using DspLink config data for entry #%d [server '%s']\n",
        serverNameIndex, serverName );

    armDspLinkConfig = ti_sdo_ce_ipc_armDspLinkConfigs[ serverNameIndex ];

    ti_sdo_ce_ipc_Processor_linkcfg.dspConfigs[0]->memTables = linkcfgMemTables;
    ti_sdo_ce_ipc_Processor_linkcfg.dspConfigs[0]->memTables[0] = NULL;

    /*
     *  Count the number of CMEM blocks, so we can add entries for these,
     *  if needed.
     */
    status = CMEM_getNumBlocks(&numCmemBlocks);
    if (status != 0) {
        /* TODO: Is this always an error? */
        GT_0trace(curTrace, GT_6CLASS, "Processor_create_d> "
                "CMEM_getNumBlocks() failed!");
        numCmemBlocks = 0;
    }
    else {
        GT_1trace(curTrace, GT_2CLASS, "Processor_create_d> Number of CMEM "
                "blocks: %d\n", numCmemBlocks);
    }

    for (;armDspLinkConfig->memTable[i].segmentName != NULL; i++);

    /*
     *  Add a few extra entries in case we need to map CMEM blocks. The
     *  app's config will have at most one CMEM entry with base and length
     *  set to 0. We'll use CMEM_getBlockAttrs to get the base and length
     *  of all CMEM blocks. (Note: We will allocate at least one more entry
     *  then is actually needed, but this is easier than checking the
     *  memTable for "CMEM", and subtracting '1' from the nuber to allocate
     *  if "CMEM" is found.)
     */
    numMemEntries = i;
    numMemTableEntries = numMemEntries + numCmemBlocks;

    /* anything allocated here must be deallocated in procDelete */
    linkcfgMemTable = (LINKCFG_MemEntry *) Memory_alloc(
            sizeof(LINKCFG_MemEntry) * numMemTableEntries, NULL);

    if (linkcfgMemTable == NULL) {
        GT_0trace(curTrace, GT_7CLASS, "Processor_create_d> "
            "ERROR: Memory_alloc failed\n");
        return;
    }

    /* point link config memTables only entry to our list of memTable entries */
    ti_sdo_ce_ipc_Processor_linkcfg.dspConfigs[0]->memTables[0] = linkcfgMemTable;

    for (i = 0, memEntryIdx = 0; i < numMemEntries; i++) {
        e   = &linkcfgMemTable[memEntryIdx];
        mte = &armDspLinkConfig->memTable[i];
        GT_4trace(curTrace, GT_2CLASS, "Processor_create_d> Adding memTable "
                "entry for %s, physAddr = 0x%x, dspAddr = 0x%x, size = 0x%x\n",
                mte->segmentName, mte->gppAddress, mte->startAddress,
                mte->sizeInBytes);

        if (!strcmp("CMEM", mte->segmentName)) {
            /* Skip CMEM entry, we'll add CMEM blocks later */
            addCmemBlocks = TRUE;
            continue;
        }

        e->entry        = memEntryIdx; //i;
        strncpy( e->name, mte->segmentName, DSP_MAX_STRLEN );
        e->physAddr     = mte->gppAddress; // gpp physical address
        e->dspVirtAddr  = mte->startAddress; // dsp view (physical or virtual)
        e->gppVirtAddr  = (UInt32)-1;
        e->size         = mte->sizeInBytes;
        e->shared       = mte->shared;
        e->syncd        = mte->syncd;

        memEntryIdx++;

        GT_6trace(curTrace, GT_2CLASS, "Processor_create_d> "
            "Adding DSP segment #%d to Link configuration: "
            "name='%s', startAddress=0x%x, sizeInBytes=0x%x, shared=%d, "
            "syncd=%d\n",
            i, e->name, e->physAddr, e->size, e->shared, e->syncd);
    }

    /* Now add the CMEM blocks if needed */
    if (addCmemBlocks) {
        for (i = 0; i < numCmemBlocks; i++) {
            e = &linkcfgMemTable[memEntryIdx];
            status = CMEM_getBlockAttrs(i, &blockAttrs);
            if (status != 0) {
                GT_1trace(curTrace, GT_7CLASS, "Processor_create_d> "
                        "ERROR: failed to get CMEM attrs of block %d\n", i);
                break;
            }
            sprintf(e->name, "CMEM_BLOCK%d", i);
            e->physAddr = blockAttrs.phys_base;
            e->dspVirtAddr = blockAttrs.phys_base;
            e->size = blockAttrs.size;
            memEntryIdx++;
        }
    }

    /* set number of memTable entries */
    ti_sdo_ce_ipc_Processor_linkcfg.dspConfigs[0]->dspObject[0].memEntries =
        memEntryIdx; //numMemTableEntries;

    /* RESET vector is always #3 in the list (that's how Global.xdt arranges it;
     * read its start address and size and adjust some other params in the
     * dsplink config object. (Note: third in the list is index [2].
     */
    ti_sdo_ce_ipc_Processor_linkcfg.dspConfigs[0]->dspObject[0].resumeAddr =
        armDspLinkConfig->memTable[2].startAddress + 0x20;
    ti_sdo_ce_ipc_Processor_linkcfg.dspConfigs[0]->dspObject[0].resetVector =
        armDspLinkConfig->memTable[2].startAddress;
    ti_sdo_ce_ipc_Processor_linkcfg.dspConfigs[0]->dspObject[0].resetCodeSize =
        armDspLinkConfig->memTable[2].sizeInBytes;

    /* SET DOPOWERCONTROL PER CE CONFIGURATION */
    staticCfgDspCtl =
        ti_sdo_ce_ipc_Processor_linkcfg.dspConfigs[0]->dspObject[0].doDspCtrl;

    if (armDspLinkConfig->doDspCtrl == BootNoPwr) {
        newCfgDspCtl = DSP_BootMode_Boot_NoPwr;
    }
    else if (armDspLinkConfig->doDspCtrl == BootPwr) {
        newCfgDspCtl = DSP_BootMode_Boot_Pwr;
    }
    else if (armDspLinkConfig->doDspCtrl == NoLoadNoPwr) {
        newCfgDspCtl = DSP_BootMode_NoLoad_NoPwr;
    }
    else if (armDspLinkConfig->doDspCtrl == NoLoadPwr) {
        newCfgDspCtl = DSP_BootMode_NoLoad_Pwr;
    }
    else { /* NoBoot */
        newCfgDspCtl = DSP_BootMode_NoBoot;
    }

    ti_sdo_ce_ipc_Processor_linkcfg.dspConfigs[0]->dspObject[0].doDspCtrl =
        newCfgDspCtl;
    GT_2trace(curTrace, GT_2CLASS, "Processor_create_d> "
            "DODSPCTRL was=%d; now=%d\n", staticCfgDspCtl, newCfgDspCtl);
}
/*
 *  ======== VIDENCCOPY_TI_process ========
 */
XDAS_Int32 VIDENCCOPY_TI_process(IVIDENC_Handle h, XDM_BufDesc *inBufs,
    XDM_BufDesc *outBufs, IVIDENC_InArgs *inArgs, IVIDENC_OutArgs *outArgs)
{
    XDAS_Int32 curBuf;
    XDAS_UInt32 minSamples;

#ifdef USE_ACPY3
    const Uint32 maxTransferChunkSize       = 0xffff;
    Uint32       thisTransferChunkSize      = 0x0;
    Uint32       remainingTransferChunkSize;
    Uint32       thisTransferSrcAddr, thisTransferDstAddr;

    ACPY3_Params params;
    VIDENCCOPY_TI_Obj *videncObj = (VIDENCCOPY_TI_Obj *)h;
#endif

    GT_5trace(curTrace, GT_ENTER, "VIDENCCOPY_TI_process(0x%x, 0x%x, 0x%x, "
        "0x%x, 0x%x)\n", h, inBufs, outBufs, inArgs, outArgs);

    /* validate arguments - this codec only supports "base" xDM. */
    if ((inArgs->size != sizeof(*inArgs)) ||
        (outArgs->size != sizeof(*outArgs))) {

        GT_2trace(curTrace, GT_ENTER,
            "VIDENCCOPY_TI_process, unsupported size "
            "(0x%x, 0x%x)\n", inArgs->size, outArgs->size);

        return (IVIDENC_EFAIL);
    }

#ifdef USE_ACPY3
    /*
     * Activate Channel  scratch DMA channels.
     */
    ACPY3_activate(videncObj->dmaHandle1D1D8B);
#endif

    /* outArgs->bytesGenerated reports the total number of bytes generated */
    outArgs->bytesGenerated = 0;

    /*
     * A couple constraints for this simple "copy" codec:
     *    - Video encoding presumes a single input buffer, so only one input
     *      buffer will be encoded, regardless of inBufs->numBufs.
     *    - Given a different size of an input and output buffers, only
     *      encode (i.e., copy) the lesser of the sizes.
     */

    for (curBuf = 0; (curBuf < inBufs->numBufs) &&
        (curBuf < outBufs->numBufs); curBuf++) {

        /* there's an available in and out buffer, how many samples? */
        minSamples = inBufs->bufSizes[curBuf] < outBufs->bufSizes[curBuf] ?
            inBufs->bufSizes[curBuf] : outBufs->bufSizes[curBuf];

#ifdef USE_ACPY3

        thisTransferSrcAddr        = (Uint32)inBufs->bufs[curBuf];
        thisTransferDstAddr        = (Uint32)outBufs->bufs[curBuf];
        remainingTransferChunkSize = minSamples;

        while (remainingTransferChunkSize > 0) {

            if (remainingTransferChunkSize > maxTransferChunkSize) {
               thisTransferChunkSize = maxTransferChunkSize;
            }
            else {
               thisTransferChunkSize = remainingTransferChunkSize;
            }

            /* Configure the logical channel */
            params.transferType = ACPY3_1D1D;
            params.srcAddr      = (void *)thisTransferSrcAddr;
            params.dstAddr      = (void *)thisTransferDstAddr;
            params.elementSize  = thisTransferChunkSize;
            params.numElements  = 1;
            params.waitId       = 0;
            params.numFrames    = 1;

            remainingTransferChunkSize -= thisTransferChunkSize;
            thisTransferSrcAddr += thisTransferChunkSize;
            thisTransferDstAddr += thisTransferChunkSize;

            /* Configure logical dma channel */
            ACPY3_configure(videncObj->dmaHandle1D1D8B, &params, 0);

            /* Use DMA to copy data */
            ACPY3_start(videncObj->dmaHandle1D1D8B);

            /* wait for transfer to finish  */
            ACPY3_wait(videncObj->dmaHandle1D1D8B);
        }
        GT_1trace(curTrace, GT_2CLASS, "VIDENCCOPY_TI_process> "
               "ACPY3 Processed %d bytes.\n", minSamples);
#else
        GT_3trace(curTrace, GT_2CLASS, "VIDENCCOPY_TI_process> "
               "memcpy (0x%x, 0x%x, %d)\n",
               outBufs->bufs[curBuf], inBufs->bufs[curBuf], minSamples);

        /* process the data: read input, produce output */
        memcpy(outBufs->bufs[curBuf], inBufs->bufs[curBuf], minSamples);
#endif

        outArgs->bytesGenerated += minSamples;
    }

    /* Fill out the rest of the outArgs struct */
    outArgs->extendedError = 0;
    outArgs->encodedFrameType = 0;    /* TODO */
    outArgs->inputFrameSkip = IVIDEO_FRAME_ENCODED;
    outArgs->reconBufs.numBufs = 0;   /* important: indicate no reconBufs */

    return (IVIDENC_EOK);
}
Beispiel #9
0
/*
 *  ======== regsupSetValue ========
 *  Purpose:
 *      Sets the value of the entry having the given name.
 */
DSP_STATUS regsupSetValue(char *valName, void *pBuf, u32 dataSize)
{
	DSP_STATUS retVal = DSP_EFAIL;
	u32 i;

	GT_2trace(REG_debugMask, GT_2CLASS, "S %s DATA %x ", valName,
		  *(u32 *)pBuf);
	printS((u8 *)pBuf);

	/*  Need to search through the entries looking for the right one.  */
	for (i = 0; i < pRegKey->numValueEntries; i++) {
		/*  See if the name matches.  */
               if (strncmp(pRegKey->values[i].name, valName,
		    BRIDGE_MAX_NAME_SIZE) == 0) {
			/*  Make sure the new data size is the same.  */
			if (dataSize != pRegKey->values[i].dataSize) {
				/*  The caller needs a different data size!  */
				MEM_Free(pRegKey->values[i].pData);
				pRegKey->values[i].pData = MEM_Alloc(dataSize,
							   MEM_NONPAGED);
				if (pRegKey->values[i].pData == NULL)
					break;

			}

			/*  We have a match!  Copy out the data.  */
			memcpy(pRegKey->values[i].pData, pBuf, dataSize);

			/* Reset datasize - overwrite if new or same */
			pRegKey->values[i].dataSize = dataSize;

			/*  Set our status to good and exit.  */
			retVal = DSP_SOK;
			break;
		}
	}

	/*  See if we found a match or if this is a new entry  */
	if (i == pRegKey->numValueEntries) {
		/*  No match, need to make a new entry  */
		/*  First check to see if we can make any more entries.  */
		if (pRegKey->numValueEntries < BRIDGE_MAX_NUM_REG_ENTRIES) {
			char *tmp_name =
				pRegKey->values[pRegKey->numValueEntries].name;
			strncpy(tmp_name, valName, BRIDGE_MAX_NAME_SIZE - 1);
			tmp_name[BRIDGE_MAX_NAME_SIZE - 1] = '\0';
			pRegKey->values[pRegKey->numValueEntries].pData =
					MEM_Alloc(dataSize, MEM_NONPAGED);
			if (pRegKey->values[pRegKey->numValueEntries].pData !=
									NULL) {
				memcpy(pRegKey->
					values[pRegKey->numValueEntries].pData,
					pBuf, dataSize);
				pRegKey->
				    values[pRegKey->numValueEntries].dataSize =
				    dataSize;
				pRegKey->numValueEntries++;
				retVal = DSP_SOK;
			}
		} else {
			GT_0trace(REG_debugMask, GT_7CLASS,
				  "MAX NUM REG ENTRIES REACHED\n");
		}
	}

	return retVal;
}
/*!
 *  @brief      Allocate memory for remote processor application
 *
 *              This function  is called by remote processor application to
 *              Allocate a buffer.
 *
 *  @param      dataSize    Size of the marshalled data packet
 *  @param      data        Marshalled data packet
 *
 *  @sa         SysLinkMemUtils_free
 */
Int32
SysLinkMemUtils_alloc (UInt32 dataSize, UInt32 * data)
{

    AllocArgs                     * args            = (AllocArgs *)data;
    Int                             i;
    MemAllocBlock                 * memBlock        = NULL;
    Ptr                             allocedPtr      = NULL;
    UInt32                          retAddr         = 0;
    UInt32                          size            = 0;
    Int32                           status          = PROCMGR_SUCCESS;
    SyslinkMemUtils_MpuAddrToMap    mpuAddrList [1];

    GT_2trace (curTrace, GT_ENTER, "SysLinkMemUtils_alloc", dataSize, data);

    memBlock = Memory_calloc (NULL, sizeof (MemAllocBlock) * args->numBuffers,
                                0);
    if (!memBlock) {
        status = PROCMGR_E_MEMORY;
#if !defined(SYSLINK_BUILD_OPTIMIZE)
        GT_setFailureReason (curTrace,
                             GT_4CLASS,
                             (Char *)__func__,
                             status,
                             "Error allocating memBlock");
#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
    }
    else {
        for (i = 0; i < args->numBuffers; i++) {
            memBlock [i].pixelFormat = args->params [i].pixelFormat;
            memBlock [i].dim.area.width = args->params [i].width;
            memBlock [i].dim.area.height = args->params [i].height;
            memBlock [i].dim.len = args->params [i].length;
        }
    }

    if (status == PROCMGR_SUCCESS) {
        /* Allocation */
        allocedPtr = MemMgr_Alloc (memBlock, args->numBuffers);
        if (!allocedPtr) {
            status = PROCMGR_E_MEMORY;
#if !defined(SYSLINK_BUILD_OPTIMIZE)
            GT_setFailureReason (curTrace,
                                 GT_4CLASS,
                                 (Char *)__func__,
                                 status,
                                 "Error MemMgr buffer");
#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
        }
    }

    if (status == PROCMGR_SUCCESS) {
        for (i = 0; i < args->numBuffers; i++) {
            args->params [i].stride = memBlock [i].stride;
            args->params [i].ptr = memBlock [i].ptr;
        }
        size = _SysLinkMemUtils_bufferSize (memBlock, args->numBuffers);
        mpuAddrList [0].mpuAddr = (UInt32)allocedPtr;
        mpuAddrList [0].size = size;
        status = SysLinkMemUtils_map (mpuAddrList, 1, &retAddr,
                                      ProcMgr_MapType_Tiler, PROC_SYSM3);
#if !defined(SYSLINK_BUILD_OPTIMIZE)
        if (status != PROCMGR_SUCCESS) {
            GT_setFailureReason (curTrace,
                                 GT_4CLASS,
                                 (Char *)__func__,
                                 status,
                                 "Error in SysLinkMemUtils_map");
        }
#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
    }

    if (status == PROCMGR_SUCCESS) {
        status = _SysLinkMemUtils_insertMapElement ((Ptr)retAddr,
                                                        allocedPtr, size);
#if !defined(SYSLINK_BUILD_OPTIMIZE)
        if (status != PROCMGR_SUCCESS) {
            GT_setFailureReason (curTrace,
                                 GT_4CLASS,
                                 (Char *)__func__,
                                 status,
                                 "Error in SysLinkMemUtils_InsertMapElement");
        }
#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
    }

    if (status != PROCMGR_SUCCESS) {
        if (retAddr) {
            SysLinkMemUtils_unmap (retAddr, PROC_SYSM3);
        }
        if (allocedPtr) {
            MemMgr_Free (allocedPtr);
        }
    }

    if (memBlock)
        Memory_free (NULL, memBlock, 1);

    GT_1trace (curTrace, GT_LEAVE, "SysLinkMemUtils_alloc", retAddr);

    return retAddr;
}
/*
 *  ======== ACPY3_activate ========
 */
Void ACPY3_activate(IDMA3_Handle handle)
{
    Int    numPaRamsM1;
    ACPY3_MoreEnv *env;
#ifndef _ACPY3_CPUCOPY_
    Int    i;
    Uns    paRam;
    Uns    begPaRam;
    Uns    endPaRam;
    unsigned short qdmaChan;
    volatile Uns   *paRamRegs;
    volatile Uns   *lastPaRam;
    Uns    triggerIdx;
    Uns    nullPaRam = ACPY3_QDMA.nullPaRamIndex;
#endif

    GT_0trace(CURTRACE, GT_ENTER, "ACPY3_activate> Enter\n");

    env = (ACPY3_MoreEnv *)(handle->env);

    GT_1trace(CURTRACE, GT_2CLASS, "ACPY3_activate> env = 0x%x\n", env);

#ifndef _ACPY3_CPUCOPY_
    qdmaChan = handle->qdmaChan;
#endif
    /* Set CCNT to 1 in all physical PaRams owned by this channel */
    numPaRamsM1 = env->numPaRams - 1;

#ifndef _ACPY3_CPUCOPY_
    /*
     * If any other QDMA channel uses the current PaRam set for this channel,
     * Modify it to use paRam 0 or 127 instead.
     * This shouldn't really happen, but we really need to avoid it.
     */
    endPaRam = ((Uns)handle->paRamAddr) - (Uns)ACPY3_QDMA_PARAM_BASE;
    begPaRam = endPaRam - (numPaRamsM1 << 5);

    GT_2trace(CURTRACE, GT_2CLASS, "ACPY3_activate> begPaRam ="
            "0x%x, endPaRam = 0x%x\n", begPaRam, endPaRam);

    /* Enter critical section for accessing QCHMAP */
    LockMP_acquire(_ACPY3_lock);

    GT_0trace(CURTRACE, GT_2CLASS,"ACPY3_activate> Acquired a LockMP\n");

    for (i = 0; i < ACPY3_NUM_QDMA_CHANNELS; i++) {
        if (i == qdmaChan) {
            continue;
        }
        paRam = (ACPY3_QCHMAP[i] & 0x3fe0);
        if ((paRam >= begPaRam) && (paRam <= endPaRam)) {
            /*
             *  Set trigger word of other channels to a paRam not in use
             *  (trigger word is ccnt of the null PaRam)
             */
            GT_2trace(CURTRACE, GT_2CLASS,"ACPY3_activate>"
                    "QDMA channel %d pointing to PaRam assigned to ACPY3, "
                    "map it %d to nullPaRam %d\n", i, nullPaRam);

            ACPY3_QCHMAP[i] = (Uns)(nullPaRam << 5) | (0x7 << 2);
        }
    }


    /*
     *  TODO: Make sure all linked transfers have completed on the mapped
     *  PaRam, before changing QCHMAP.
     */

    /*
     *  Set the QCHMAP for this channel to the null PaRam, since the static bit
     *  will always be set for it (and we know there is no transfer in progress
     *  on first call to ACPY3_start()).
     */
    GT_2trace(CURTRACE, GT_2CLASS,"ACPY3_activate> Mapping "
            "QDMA channel %d to nullPaRam %d\n", qdmaChan, nullPaRam);

    ACPY3_QCHMAP[qdmaChan] = (Uns)(nullPaRam << 5) | (0x7 << 2);
    GT_1trace(CURTRACE, GT_2CLASS,"Enabling QEESR for QDMA channel %d \n",
            qdmaChan);

    /* Enable QEER */
    *ACPY3_QEESR = 0x1 << (qdmaChan);

    /*
     * Set the last two elements of each real allocated paRam to their
     * expected values.  They should never get written again as long as
     * this handle is activated.
     */
    lastPaRam = (Uns *)((Uns)ACPY3_QDMA_PARAM_BASE +
            (ACPY3_QCHMAP[qdmaChan] & 0x3fe0));
    triggerIdx = (ACPY3_QCHMAP[qdmaChan] & (0x7 << 2))  >> 2;

    for (i = env->numPaRams - 1; i >= 0; i--) {
        paRamRegs = (Uns *)ACPY3_getPaRamPhysicalAddress(handle, i);

        if ((paRamRegs == lastPaRam) && (triggerIdx >= 6)) {
            /* set trigger word to link|bCntrld of 1st paRam */
            ACPY3_QCHMAP[qdmaChan] = (Uns)(handle->paRamAddr) | (0x5 << 2);
        }
        paRamRegs[0x6] = 0; /* frame indices = 0 */
        paRamRegs[0x7] = 1; /* ccnt=1, rsvd=0 */
    }

    /* Exit critical section */
    LockMP_release(_ACPY3_lock);
    GT_0trace(CURTRACE, GT_2CLASS, "Released LockMP\n");

#endif /* _ACPY3_CPUCOPY_ */

    handle->transferPending = FALSE;
    handle->numPaRams = numPaRamsM1 + 1;
    handle->numTccs = env->numTccs;

    GT_0trace(CURTRACE, GT_ENTER, "ACPY3_activate> Exit\n");

    return;
}
/*!
 *  @brief      Function to control reset operations
 *
 *  @param      halObj  Pointer to the HAL object
 *  @param      cmd     Reset control command
 *  @param      arg     Arguments specific to the reset control command
 *
 *  @sa
 */
Int
OMAP5430BENELLI_halResetCtrl (Ptr halObj, Processor_ResetCtrlCmd cmd)
{
    Int                  status    = PROCESSOR_SUCCESS;
    OMAP5430BENELLI_HalObject * halObject = NULL;
    UINT32 pa;
    int counter = 10;
    UINT32 IPURstCtrl;
    UINT32 IPUClkCtrl;
    UINT32 IPURstSt;
    UINT32 IPUClkStCtrl;
    UINT32 DSPRstCtrl;
    UINT32 DSPClkCtrl;
    UINT32 DSPPwrStCtrl;
    UINT32 DSPPwrSt;
    UINT32 DSPRstSt;
    UINT32 DSPClkStCtrl;
    Int ret;

    GT_2trace (curTrace, GT_ENTER, "OMAP5430BENELLI_halResetCtrl", halObj, cmd);

    GT_assert (curTrace, (halObj != NULL));
    GT_assert (curTrace, (cmd < Processor_ResetCtrlCmd_EndValue));

    ULONG reg = 0;
    ULONG resets = 0;
    pa = RM_IPU_RSTCTRL;
    IPURstCtrl = (UINT32)OsalDrv_ioMap(pa, sizeof(ULONG));

    pa = CM_IPU_IPU_CLKCTRL;
    IPUClkCtrl = (UINT32)OsalDrv_ioMap(pa, sizeof(ULONG));

    pa = RM_IPU_RSTST;
    IPURstSt = (UINT32)OsalDrv_ioMap(pa, sizeof(ULONG));
    pa = CM_IPU_CLKSTCTRL;
    IPUClkStCtrl = (UINT32)OsalDrv_ioMap(pa, sizeof(ULONG));

    pa = PM_DSP_PWRSTCTRL;
    DSPPwrStCtrl = (UINT32)OsalDrv_ioMap(pa,sizeof(ULONG));

    pa = PM_DSP_PWRSTST;
    DSPPwrSt = (UINT32)OsalDrv_ioMap(pa,sizeof(ULONG));

    pa = RM_DSP_RSTCTRL;
    DSPRstCtrl = (UINT32)OsalDrv_ioMap(pa,sizeof(ULONG));

    pa = RM_DSP_RSTST;
    DSPRstSt = (UINT32)OsalDrv_ioMap(pa,sizeof(ULONG));

    pa = CM_DSP_DSP_CLKCTRL;
    DSPClkCtrl = (UINT32)OsalDrv_ioMap(pa,sizeof(ULONG));

    pa = CM_DSP_CLKSTCTRL;
    DSPClkStCtrl = (UINT32)OsalDrv_ioMap(pa,sizeof(ULONG));

    halObject = (OMAP5430BENELLI_HalObject *) halObj ;

    switch (cmd) {
        case Processor_ResetCtrlCmd_Reset:
        {
            switch (halObject->procId) {
                case PROCTYPE_IPU0:
#ifdef SYSLINK_SYSBIOS_SMP
                    /* Put IPU core 1 into reset */
                    SETBITREG32(IPURstCtrl, RM_IPU_RST2_BIT);
#endif
                    /* Put IPU core 0 into reset */
                    SETBITREG32(IPURstCtrl, RM_IPU_RST1_BIT);
                    /* Read back the reset control register */
                    reg = INREG32(IPURstCtrl);
#ifndef OMAP5430_VIRTIO // skip this for now, not using gptimers
                    /* Disable the GPT3 clock, which is used by CORE0 */
                    ret = ipu_pm_gpt_stop(GPTIMER_3);
                    if (ret != EOK) {
                        status = PROCESSOR_E_FAIL;
                        GT_setFailureReason (curTrace, GT_4CLASS,
                                             "OMAP4430DUCATI_halResetCtrl",
                                             status,
                                             "Failed to stop gpt 3");
                    }
                    ret = ipu_pm_gpt_disable(GPTIMER_3);
                    if (ret != EOK) {
                        status = PROCESSOR_E_FAIL;
                        GT_setFailureReason (curTrace, GT_4CLASS,
                                             "OMAP4430DUCATI_halResetCtrl",
                                             status,
                                             "Failed to disable gpt 3");
                    }
#endif
                    break;
#ifndef SYSLINK_SYSBIOS_SMP
                case PROCTYPE_IPU1:
                    /* Put IPU core 1 into reset */
                    SETBITREG32(IPURstCtrl, RM_IPU_RST2_BIT);
#ifndef OMAP5430_VIRTIO // skip this check, reset status not modeled properly
                    /* Disable the GPT4 clock, which is used by CORE1 */
                    ret = ipu_pm_gpt_stop(GPTIMER_4);
                    if (ret != EOK) {
                        status = PROCESSOR_E_FAIL;
                        GT_setFailureReason (curTrace, GT_4CLASS,
                                             "OMAP4430DUCATI_halResetCtrl",
                                             status,
                                             "Failed to stop gpt 4");
                    }
                    ret = ipu_pm_gpt_disable(GPTIMER_4);
                    if (ret != EOK) {
                        status = PROCESSOR_E_FAIL;
                        GT_setFailureReason (curTrace, GT_4CLASS,
                                             "OMAP4430DUCATI_halResetCtrl",
                                             status,
                                             "Failed to disable gpt 4");
                    }
#endif
                    break;
#endif
                case PROCTYPE_DSP:
                    SETBITREG32(DSPRstCtrl, RM_DSP_RSTCTRL_BIT);
                    ret = ipu_pm_gpt_stop(GPTIMER_5);
                    if (ret != EOK) {
                        status = PROCESSOR_E_FAIL;
                        GT_setFailureReason (curTrace, GT_4CLASS,
                                             "OMAP4430DUCATI_halResetCtrl",
                                             status,
                                             "Failed to stop gpt 5");
                    }
                    ret = ipu_pm_gpt_disable(GPTIMER_5);
                    if (ret != EOK) {
                        status = PROCESSOR_E_FAIL;
                        GT_setFailureReason (curTrace, GT_4CLASS,
                                             "OMAP4430DUCATI_halResetCtrl",
                                             status,
                                             "Failed to disable gpt 5");
                    }
                    break;
                default:
                    break;
            }
        }
        break;

        case Processor_ResetCtrlCmd_MMU_Reset:
        {
            switch (halObject->procId) {
                case PROCTYPE_IPU0:
                    /* Put IPU MMU into reset */
                    SETBITREG32(IPURstCtrl, RM_IPU_RST3_BIT);
                    /* Disable the IPU clock */
                    OUTREG32(IPUClkCtrl, 0x01);
                    break;
#ifndef SYSLINK_SYSBIOS_SMP
                case PROCTYPE_IPU1:
                    break;
#endif
                case PROCTYPE_DSP:
                    SETBITREG32(DSPRstCtrl, RM_DSP_MMU_RSTCTRL_BIT);
                    break;
                default:
                    break;
            }
        }
        break;

        case Processor_ResetCtrlCmd_MMU_Release:
        {
            if(halObject->procId != PROCTYPE_DSP) {
                reg = INREG32(IPURstSt);
                if (reg != 0x0) {
                    Osal_printf("OMAP5430BENELLI_halResetCtrl: clearing reset status!");
                    OUTREG32(IPURstSt, reg);
                    do {
                        if ((reg = INREG32(IPURstSt)) == 0x0)
                        break;
                    } while (--counter);

                    if (reg == 0x0) {
                        Osal_printf("OMAP5430BENELLI_halResetCtrl: reset state reset!");
                    }
                    else {
                        status = PROCESSOR_E_FAIL;
                        GT_setFailureReason (curTrace, GT_4CLASS,
                                             "OMAP5430BENELLI_halResetCtrl", status,
                                             "Failed to clear reset status");
                    }
                }
            }
            if (status >= 0) {

                switch (halObject->procId) {
                    case PROCTYPE_IPU0:
                        /* Module is managed automatically by HW */
                        OUTREG32(IPUClkCtrl,
                                  CM_IPU_IPU_CLKCTRL_MODULEMODE_HWAUTO);
                        /* Enable the IPU clock */
                        OUTREG32(IPUClkStCtrl, CM_IPU_CLKSTCTRL_CTRL_SW_WKUP);

                        counter = 10;
                        do {
                            if (TESTBITREG32(IPUClkStCtrl,
                                             CM_IPU_CLKSTCTRL_CLKACTIVITY_BIT)) {
                                Osal_printf("IPU clock enabled:"
                                            "CORE_CM_IPU_CLKSTCTRL = 0x%x",
                                            INREG32(IPUClkStCtrl));
                                break;
                            }
                        } while (--counter);

#ifndef OMAP5430_VIRTIO // skip this check
                        if (counter == 0) {
                            Osal_printf("FAILED TO ENABLE IPU CLOCK !");
                            return PROCESSOR_E_OSFAILURE;
                        }
#endif

                        /* Check that releasing resets would indeed be
                         * effective */
                        reg =  INREG32(IPURstCtrl);
                        resets = RM_IPU_RST3 | RM_IPU_RST2 | RM_IPU_RST1;
                        if (reg != resets) {
                            Osal_printf("OMAP5430BENELLI_halResetCtrl: "
                                        "Resets in not proper state! [0x%x]",
                                        reg);
                            OUTREG32(IPURstCtrl,resets);
                            counter = 10;
                            do {
                                if ((INREG32(IPURstCtrl) & resets) == resets)
                                    break;
                            } while (--counter);

                            if (counter == 0) {
                                status = PROCESSOR_E_FAIL;
                                GT_setFailureReason (curTrace, GT_4CLASS,
                                        "OMAP5430BENELLI_halResetCtrl",
                                        status,
                                        "Failed to put resets in proper state");
                            }
                        }

                        if (status >= 0) {
                            /* De-assert RST3, and clear the Reset status */
                            Osal_printf("De-assert RST3");
                            CLRBITREG32(IPURstCtrl, RM_IPU_RST3_BIT);

#ifndef OMAP5430_VIRTIO // skip this check, reset status not modeled properly
                            counter = 10;
                            do {
                                if (INREG32(IPURstSt) & RM_IPU_RST3ST)
                                    break;
                            } while (--counter);
                            if (counter == 0) {
                                status = PROCESSOR_E_FAIL;
                                GT_setFailureReason (curTrace, GT_4CLASS,
                                                  "OMAP5430BENELLI_halResetCtrl",
                                                  status,
                                                  "Failed to release RST3");
                            }
                            else {
                                Osal_printf("RST3 released!");
                                SETBITREG32(IPURstSt, RM_IPU_RST3ST_BIT);
                            }
                        }
#endif
                        break;
#ifndef SYSLINK_SYSBIOS_SMP
                    case PROCTYPE_IPU1:
                        break;
#endif
                    case PROCTYPE_DSP:
                         /* Enable the GPT5 clock, which is used by DSP */
                        ret = ipu_pm_gpt_enable(GPTIMER_5);
                        if (ret != EOK) {
                            status = PROCESSOR_E_FAIL;
                            GT_setFailureReason (curTrace, GT_4CLASS,
                                                 "OMAP5430BENELLI_halResetCtrl",
                                                 status,
                                                 "Failed to enable gpt 5");
                        }
                        else {
                            restore_gpt_context(GPTIMER_5);
                            ipu_pm_gpt_start(GPTIMER_5);
                            reg = INREG32(DSPRstSt);
                            if (reg != 0x0) {
                                Osal_printf("OMAP5430BENELLI_halResetCtrl: clearing DSP reset status!");
                                OUTREG32(DSPRstSt, reg);
                                counter = 10;
                                do {
                                    if (INREG32(DSPRstSt) == 0x0)
                                        break;
                                } while (--counter);
                                if (counter == 0) {
                                    status = PROCESSOR_E_FAIL;
                                    GT_setFailureReason (curTrace, GT_4CLASS,
                                                      "OMAP5430BENELLI_halResetCtrl",
                                                      status,
                                                      "Failed to release RST3");
                                }
                                else {
                                    Osal_printf("OMAP5430BENELLI_halResetCtrl: DSP reset state reset!");
                                }
                            }
                        }

                        if (status >= 0) {
                            reg = INREG32(DSPPwrStCtrl);
                            reg |= 0x7;
                            OUTREG32(DSPPwrStCtrl, reg);
                            reg = INREG32(DSPPwrSt);
                            /* Module is managed automatically by HW */
                            OUTREG32(DSPClkCtrl, 0x01);
                            /* Enable the DSP clock */
                            OUTREG32(DSPClkStCtrl, 0x03);
                            counter = 10;
                            do {
                                reg = INREG32(DSPClkStCtrl);
                                if (reg & 0x100) {
                                    Osal_printf("DSP clock enabled:DSP_CLKSTCTRL = 0x%x", reg);
                                    break;
                                }
                            } while (--counter);
                            if (counter == 0) {
                                status = PROCESSOR_E_FAIL;
                                GT_setFailureReason (curTrace, GT_4CLASS,
                                                     "OMAP5430BENELLI_halResetCtrl",
                                                     status,
                                                     "FAILED TO ENABLE DSP CLOCK");
                            }
                        }

                        if (status >= 0) {
                            /* Check that releasing resets would indeed be effective */
                            reg =  INREG32(DSPRstCtrl);
                            if (reg != 3) {
                                Osal_printf("proc4430_start: DSP Resets in not proper state! [0x%x]", reg);
                                OUTREG32(DSPRstCtrl,0x3);
                                counter = 1000;
                                while ((--counter)&&((INREG32(DSPRstCtrl) & 0x3) != 0x3));
                                if (counter == 0) {
                                    status = PROCESSOR_E_FAIL;
                                    GT_setFailureReason (curTrace, GT_4CLASS,
                                                         "OMAP5430BENELLI_halResetCtrl",
                                                         status,
                                                         "RESET bits not set in DSP reset Ctrl");
                                }
                            }
                            if (status >= 0) {
                                /* De-assert RST3, and clear the Reset status */
                                OUTREG32(DSPRstCtrl,0x1);
                                counter = 10;
                                do {
                                    if (INREG32(DSPRstSt) & 0x2)
                                        break;
                                } while (--counter);
                                if (counter == 0) {
                                    status = PROCESSOR_E_FAIL;
                                    GT_setFailureReason (curTrace, GT_4CLASS,
                                                         "OMAP5430BENELLI_halResetCtrl",
                                                         status,
                                                         "Failed to deassert reset 3");
                                }
                                else {
                                    /* De-assert RST3, and clear the Reset status */
                                    OUTREG32(DSPRstCtrl,0x1);
                                    counter = 10;
                                    do {
                                        if (INREG32(DSPRstSt) & 0x2)
                                            break;
                                    } while (--counter);
                                    if (counter == 0) {
                                        status = PROCESSOR_E_FAIL;
                                        GT_setFailureReason (curTrace, GT_4CLASS,
                                                             "OMAP5430BENELLI_halResetCtrl",
                                                             status,
                                                             "Failed to deassert reset 3");
                                    }
                                    else {
                                        Osal_printf("DSP:RST2 released!");
                                        OUTREG32(DSPRstSt,0x2);
                                    }
                                }
                            }
                        }
                        break;
                    default:
                        Osal_printf("proc4430_start: ERROR input");
                        break;
                }
            }
        }
        break;

        case Processor_ResetCtrlCmd_Release:
        {
            switch (halObject->procId) {
                case PROCTYPE_IPU0:
#ifndef OMAP5430_VIRTIO // skip this for now, not using gptimers
                    /* Enable the GPT3 clock, which is used by CORE0 */
                    ret = ipu_pm_gpt_enable(GPTIMER_3);
                    if (ret != EOK) {
                        status = PROCESSOR_E_FAIL;
                        GT_setFailureReason (curTrace, GT_4CLASS,
                                             "OMAP5430BENELLI_halResetCtrl",
                                             status,
                                             "Failed to enable gpt 3");
                    }
                    else {
                        restore_gpt_context(GPTIMER_3);
                        ret = ipu_pm_gpt_start(GPTIMER_3);
                        if (ret != EOK) {
                            status = PROCESSOR_E_FAIL;
                            GT_setFailureReason (curTrace, GT_4CLASS,
                                                 "OMAP5430BENELLI_halResetCtrl",
                                                 status,
                                                 "Failed to start gpt 3");
                        }
                        else {
#endif // ifndef OMAP5430_VIRTIO
                            /* De-assert RST1, and clear the Reset status */
                            Osal_printf("De-assert RST1");
                            CLRBITREG32(IPURstCtrl, RM_IPU_RST1_BIT);

#ifndef OMAP5430_VIRTIO // skip this check for now
                            counter = 10;
                            do {
                                if (INREG32(IPURstSt) & RM_IPU_RST1)
                                    break;
                            } while (--counter);
                            if (counter == 0) {
                                status = PROCESSOR_E_FAIL;
                                GT_setFailureReason (curTrace, GT_4CLASS,
                                                  "OMAP5430BENNELI_halResetCtrl",
                                                  status,
                                                  "Failed to release RST1");
                            }
                            else {
#endif // ifndef OMAP5430_VIRTIO
                                Osal_printf("RST1 released!");
                                SETBITREG32(IPURstSt, RM_IPU_RST1ST_BIT);

                                /* Setting to HW_AUTO Mode */
                                reg = INREG32(IPUClkStCtrl);
                                reg &= ~CM_IPU_CLKSTCTRL_CTRL_BITMASK;
                                reg |= CM_IPU_CLKSTCTRL_CTRL_HW_AUTO;
                                OUTREG32(IPUClkStCtrl, reg);
#ifdef SYSLINK_SYSBIOS_SMP
                                /* De-assert RST2, and clear the Reset status */
                                CLRBITREG32(IPURstCtrl, RM_IPU_RST2_BIT);
#ifndef OMAP5430_VIRTIO // skip this check for now
                                counter = 10;
                                do {
                                    if (INREG32(IPURstSt) & RM_IPU_RST2)
                                        break;
                                } while (--counter);
                                if (counter == 0) {
                                    status = PROCESSOR_E_FAIL;
                                    GT_setFailureReason (curTrace, GT_4CLASS,
                                                         "OMAP5430BENELLI_halResetCtrl",
                                                         status,
                                                         "Failed to release RST2");
                                }
                                else {
#endif // ifndef OMAP5430_VIRTIO
                                    Osal_printf("RST2 released!");
                                    SETBITREG32(IPURstSt, RM_IPU_RST2ST_BIT);
#ifndef OMAP5430_VIRTIO // skip this check for now
                                }
#endif // ifndef OMAP5430_VIRTIO
#endif // ifdef SYSLINK_SYSBIOS_SMP
#ifndef OMAP5430_VIRTIO // skip this check for now
                            }
                        }
                    }
#endif // ifndef OMAP5430_VIRTIO
                    break;
#ifndef SYSLINK_SYSBIOS_SMP
                case PROCTYPE_IPU1:
#ifndef OMAP5430_VIRTIO // skip this for now, not using gptimers
                    /* Enable the GPT4 clock, which is used by CORE1 */
                    ret = ipu_pm_gpt_enable(GPTIMER_4);
                    if (ret != EOK) {
                        status = PROCESSOR_E_FAIL;
                        GT_setFailureReason (curTrace, GT_4CLASS,
                                             "OMAP5430BENELLI_halResetCtrl",
                                             status,
                                             "Failed to enable gpt 4");
                    }
                    else {
                        restore_gpt_context(GPTIMER_4);
                        ipu_pm_gpt_start(GPTIMER_4);
#endif

                        /* De-assert RST2, and clear the Reset status */
                        CLRBITREG32(IPURstCtrl, RM_IPU_RST2_BIT);

#ifndef OMAP5430_VIRTIO // skip this check for now
                        counter = 10;
                        do {
                            if (INREG32(IPURstSt) & RM_IPU_RST2)
                                break;
                        } while (--counter);
                        if (counter == 0) {
                            status = PROCESSOR_E_FAIL;
                            GT_setFailureReason (curTrace, GT_4CLASS,
                                                 "OMAP5430BENELLI_halResetCtrl",
                                                 status,
                                                 "Failed to release RST2");
                        }
                        else {
                            Osal_printf("RST2 released!");
                            SETBITREG32(IPURstSt, RM_IPU_RST2ST_BIT);
#endif
                            /* Wait until benelli is in idle */
                            //while(TESTBITREG32(IPUClkStCtrl,
                            //               CM_IPU_CLKSTCTRL_CLKACTIVITY_BIT));
#ifndef OMAP5430_VIRTIO // skip this check for now
                        }
#endif
                    }
                    break;
#endif
                case PROCTYPE_DSP:
                    /*De-assert RST2 and clear the Reset Status */
                    Osal_printf("De-assert DSP RST1");
                    OUTREG32(DSPRstCtrl, 0x0);
                    Osal_printf("DSP:RST2 released!");
                    OUTREG32(DSPRstSt,0x1);
                    break;
                default:
                    Osal_printf("OMAP5430BENELLI_halResetCtrl: ERROR input");
                    break;
            }
        }
        break;

        default:
        {
            /*! @retval PROCESSOR_E_INVALIDARG Invalid argument */
            status = PROCESSOR_E_INVALIDARG;
            GT_setFailureReason (curTrace,
                                 GT_4CLASS,
                                 "OMAP5430BENELLI_halResetCtrl",
                                 status,
                                 "Unsupported reset ctrl cmd specified");
        }
        break;
    }
    OsalDrv_ioUnmap(IPUClkStCtrl, sizeof(ULONG));
    OsalDrv_ioUnmap(IPUClkCtrl, sizeof(ULONG));
    OsalDrv_ioUnmap(IPURstCtrl, sizeof(ULONG));
    OsalDrv_ioUnmap(IPURstSt, sizeof(ULONG));
    OsalDrv_ioUnmap(DSPClkStCtrl, sizeof(ULONG));
    OsalDrv_ioUnmap(DSPClkCtrl, sizeof(ULONG));
    OsalDrv_ioUnmap(DSPRstCtrl, sizeof(ULONG));
    OsalDrv_ioUnmap(DSPRstSt, sizeof(ULONG));
    OsalDrv_ioUnmap(DSPPwrSt, sizeof(ULONG));
    OsalDrv_ioUnmap(DSPPwrStCtrl, sizeof(ULONG));
    GT_1trace (curTrace, GT_LEAVE, "OMAP5430BENELLI_halResetCtrl", status);

    /*! @retval PROCESSOR_SUCCESS Operation successful */

    return status;
}
Beispiel #13
0
/*
 *  ======== control ========
 *  This is the stub-implementation for the control method
 */
static XDAS_Int32 control(IIMGENC1_Handle h, IIMGENC1_Cmd id,
    IIMGENC1_DynamicParams *dynParams, IIMGENC1_Status *status)
{
    XDAS_Int32 retVal;
    VISA_Handle visa = (VISA_Handle)h;
    _IMGENC1_Msg *msg;
    IIMGENC1_Status *pMsgStatus;
    XDAS_Int8 *virtAddr = NULL;
    Int payloadSize;

    /*
     * Validate arguments.  Do we want to do this _every_ time, or just in
     * checked builds?
     */
    if ((dynParams == NULL) ||
            (dynParams->size < sizeof(IIMGENC1_DynamicParams)) ||
            (status == NULL) || (status->size < sizeof(IIMGENC1_Status))) {

        /* invalid args, could even assert here, it's a spec violation. */
        return (IIMGENC1_EFAIL);
    }

    /* make sure it'll all fit! */
    payloadSize = sizeof(VISA_MsgHeader) + sizeof(id) + dynParams->size +
            status->size;

    if (payloadSize > VISA_getMaxMsgSize(visa)) {
        /* Can't handle these large extended args. */
        GT_2trace(CURTRACE, GT_6CLASS,
                "process> invalid arguments - too big (0x%x > 0x%x).  "
                "Validate .size fields\n", payloadSize,
                VISA_getMaxMsgSize(visa));

        return (IIMGENC1_EUNSUPPORTED);
    }

    /* get a message appropriate for this algorithm */
    if ((msg = (_IMGENC1_Msg *)VISA_allocMsg(visa)) == NULL) {
        return (IIMGENC1_EFAIL);
    }

    /* marshall the command */
    msg->visa.cmd = _IMGENC1_CCONTROL;

    msg->cmd.control.id = id;

    /* dynParams has no pointers so simply memcpy "size" bytes into the msg */
    memcpy(&(msg->cmd.control.params), dynParams, dynParams->size);

    /* unmarshall status based on the "size" of params */
    pMsgStatus = (IIMGENC1_Status *)((UInt)(&(msg->cmd.control.params)) +
            dynParams->size);

    /*
     * Initialize the .size and .data fields - the rest are filled in by
     * the codec.
     */
    pMsgStatus->size = status->size;

    if (status->data.buf != NULL) {
        pMsgStatus->data.bufSize = status->data.bufSize;

        /* save it for later */
        virtAddr = status->data.buf;

        pMsgStatus->data.buf = (XDAS_Int8 *)
            Memory_getBufferPhysicalAddress(status->data.buf,
                status->data.bufSize, NULL);

        if (pMsgStatus->data.buf == NULL) {
            retVal = IIMGENC1_EFAIL;
            goto exit;
        }
    }
    else {
        /* Place null into the msg so the skel knows it's invalid */
        pMsgStatus->data.buf = NULL;
    }

    /* send the message to the skeleton and wait for completion */
    retVal = VISA_call(visa, (VISA_Msg *)&msg);

    /* ensure we get CCONTROL msg (ensure async CPROCESS pipeline drained) */
    GT_assert(CURTRACE, msg->visa.cmd == _IMGENC1_CCONTROL);

    /* unmarshall status */
    pMsgStatus = (IIMGENC1_Status *)((UInt)(&(msg->cmd.control.params)) +
        dynParams->size);

    if (VISA_isChecked()) {
        /* ensure codec didn't modify status->size */
        GT_assert(CURTRACE, pMsgStatus->size == status->size);

        /*
         * TODO:L  Should we also check that pMsgStatus->data.buf is the same
         * after the call as before?
         */
    }
    memcpy(status, pMsgStatus, status->size);

    /*
     * And finally, restore status->data.buf to its original value.  Note that
     * this works even when status->data.buf was NULL because virtAddr is
     * initialized to NULL.
     *
     * While potentially more confusing, this is just as correct as
     * (and faster than!) calling Memory_getVirtualBuffer().
     */
    status->data.buf = virtAddr;

    /* Clear .accessMask; the local processor didn't access the buffer */
    status->data.accessMask = 0;

exit:
    VISA_freeMsg(visa, (VISA_Msg)msg);

    return (retVal);
}
/*
 *  ======== VIDDECCOPY_TI_process ========
 */
XDAS_Int32 VIDDECCOPY_TI_process(IVIDDEC_Handle h, XDM_BufDesc *inBufs,
    XDM_BufDesc *outBufs, IVIDDEC_InArgs *inArgs, IVIDDEC_OutArgs *outArgs)
{
    XDAS_Int32 curBuf;
    XDAS_Int32 minSamples;

    GT_5trace(curTrace, GT_ENTER, "VIDDECCOPY_TI_process(0x%lx, 0x%lx, 0x%lx, "
        "0x%lx, 0x%lx)\n", h, inBufs, outBufs, inArgs, outArgs);

    /* validate arguments - this codec only supports "base" xDM. */
    if ((inArgs->size != sizeof(*inArgs)) ||
        (outArgs->size != sizeof(*outArgs))) {

        GT_2trace(curTrace, GT_ENTER, "VIDDECCOPY_TI_process, unsupported size "
            "(0x%lx, 0x%lx)\n", inArgs->size, outArgs->size);

        return (IVIDDEC_EFAIL);
    }

    /* outArgs->bytesConsumed reports the total number of bytes consumed */
    outArgs->bytesConsumed = 0;

    /*
     * A couple constraints for this simple "copy" codec:
     *    - Given a different number of input and output buffers, only
     *      decode (i.e., copy) the lesser number of buffers.
     *    - Given a different size of an input and output buffers, only
     *      decode (i.e., copy) the lesser of the sizes.
     */

    for (curBuf = 0; (curBuf < inBufs->numBufs) &&
        (curBuf < outBufs->numBufs); curBuf++) {

        /* there's an available in and out buffer, how many samples? */
        //minSamples = inBufs->bufSizes[curBuf] < outBufs->bufSizes[curBuf] ? inBufs->bufSizes[curBuf] : outBufs->bufSizes[curBuf];

        /* process the data: read input, produce output */
        //memcpy(outBufs->bufs[curBuf], inBufs->bufs[curBuf], minSamples);



        /* RGB24 to gray_8_bit*/
        GrayScaler((unsigned char *)inBufs->bufs[curBuf],(unsigned char *)outBufs->bufs[curBuf], 320, 240);
       
        /*Sobel Alg*/
        Sobel_Alg((unsigned char *)outBufs->bufs[curBuf],(unsigned char *)outBufs->bufs[curBuf], 320, 240);








        GT_1trace( curTrace, GT_2CLASS, "VIDDECCOPY_TI_process> "
               "Processed %d bytes.\n", minSamples );
        outArgs->bytesConsumed += minSamples;
    }

    /* Fill out the rest of the outArgs struct */
    outArgs->extendedError = 0;
    outArgs->decodedFrameType = 0;     /* TODO */
    outArgs->outputID = inArgs->inputID;
    outArgs->displayBufs.numBufs = 0;  /* important: indicate no displayBufs */

    return (IVIDDEC_EOK);
}
/*
 *  ======== analyze ========
 */
static Void analyze(VIDANALYTICS_Handle analyzer, FILE *in, FILE *out)
{
    Int                         n;
    Int32                       result;

    VIDANALYTICS_InArgs         inArgs;
    VIDANALYTICS_OutArgs        outArgs;
    VIDANALYTICS_DynamicParams  dynParams;
    VIDANALYTICS_Status         status;

    XDM1_BufDesc                inBufDesc;
    XDM1_BufDesc                outBufDesc;

    /* clear and initialize the buffer descriptors */
    inBufDesc.numBufs = outBufDesc.numBufs = 1;

    inBufDesc.descs[0].bufSize = outBufDesc.descs[0].bufSize = NSAMPLES;

    inBufDesc.descs[0].buf = inBuf;
    outBufDesc.descs[0].buf = outBuf;

    /* initialize all "sized" fields */
    inArgs.size    = sizeof(inArgs);
    outArgs.size   = sizeof(outArgs);
    dynParams.size = sizeof(dynParams);
    status.size    = sizeof(status);

    /* if the codecs support it, dump their versions */
    status.data.numBufs = 1;
    status.data.descs[0].buf = versionBuf;
    status.data.descs[0].bufSize = MAXVERSIONSIZE;

    result = VIDANALYTICS_control(analyzer, XDM_GETVERSION, &dynParams,
        &status);
    GT_1trace(curMask, GT_1CLASS, "Analyzer version:  %s\n",
        (result == VIDANALYTICS_EOK ?
            ((char *)status.data.descs[0].buf) : "[unknown]"));

    /*
     * This app expects the analyzer to accept 1 buf in and provide 1 buf out,
     * and the buf sizes of the in and out buffer must be able to handle
     * NSAMPLES bytes of data.
     */
    status.data.numBufs = 0;
    status.data.descs[0].buf = NULL;
    result = VIDANALYTICS_control(analyzer, XDM_GETBUFINFO, &dynParams,
        &status);
    if (result != VIDANALYTICS_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "VIDANALYTICS control status = %ld\n",
            status);
        return;
    }

    /* Validate this analyzer will meet our buffer requirements */
    if ((inBufDesc.numBufs < status.bufInfo.minNumInBufs) ||
        (IFRAMESIZE < status.bufInfo.minInBufSize[0]) ||
        (outBufDesc.numBufs < status.bufInfo.minNumOutBufs) ||
        (OFRAMESIZE < status.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "Error:  analyzer codec feature conflict\n");
        return;
    }

    /*
     * Read complete frames from in, analyze, and write to out.
     */
    for (n = 0; fread(inBuf, IFRAMESIZE, 1, in) == 1; n++) {

#ifdef CACHE_ENABLED
#ifdef xdc_target__isaCompatible_64P
        /*
         *  fread() on this processor is implemented using CCS's stdio, which
         *  is known to write into the cache, not physical memory.  To meet
         *  xDAIS DMA Rule 7, we must writeback the cache into physical
         *  memory.  Also, per DMA Rule 7, we must invalidate the buffer's
         *  cache before providing it to any xDAIS algorithm.
         */
        Memory_cacheWbInv(inBuf, IFRAMESIZE);
#else
#error Unvalidated config - add appropriate fread-related cache maintenance
#endif
        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(outBuf, OFRAMESIZE);
#endif

        GT_1trace(curMask, GT_1CLASS, "App-> Processing frame %d...\n", n);

        /*
         * Analyze the frame.
         */
        result = VIDANALYTICS_process(analyzer, &inBufDesc, &outBufDesc,
            &inArgs, &outArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Analyzer frame %d process returned - 0x%x)\n", n, result);

        if (result != VIDANALYTICS_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Analyzer frame %d processing FAILED, result = 0x%x, "
                "extendedError = 0x%x\n", n, result, outArgs.extendedError);
            break;
        }

#ifdef CACHE_ENABLED
        /*
         * Conditionally writeback the analyzed buf from the previous
         * call.
         */
        if (XDM_ISACCESSMODE_WRITE(outBufDesc.descs[0].accessMask)) {
            Memory_cacheWb(outBuf, OFRAMESIZE);
        }
#endif

        /* write to file */
        fwrite(outBufDesc.descs[0].buf, OFRAMESIZE, 1, out);
    }

    GT_1trace(curMask, GT_1CLASS, "%d frames analyzed\n", n);
}
/*
 *  ======== encode_decode ========
 */
static Void encode_decode(IMGENC1_Handle enc, IMGDEC1_Handle dec, FILE *in,
    FILE *out)
{
    Int                         n;
    Int32                       status;

    IMGDEC1_InArgs              decInArgs;
    IMGDEC1_OutArgs             decOutArgs;
    IMGDEC1_DynamicParams       decDynParams;
    IMGDEC1_Status              decStatus;

    IMGENC1_InArgs              encInArgs;
    IMGENC1_OutArgs             encOutArgs;
    IMGENC1_DynamicParams       encDynParams;
    IMGENC1_Status              encStatus;

    XDM1_BufDesc                inBufDesc;
    XDM1_BufDesc                encodedBufDesc;
    XDM1_BufDesc                outBufDesc;

    /* initialize the buffer descriptors */
    inBufDesc.numBufs = encodedBufDesc.numBufs = outBufDesc.numBufs = 1;
    inBufDesc.descs[0].bufSize = encodedBufDesc.descs[0].bufSize =
        outBufDesc.descs[0].bufSize = NSAMPLES;

    inBufDesc.descs[0].buf      = inBuf;
    encodedBufDesc.descs[0].buf = encodedBuf;
    outBufDesc.descs[0].buf     = outBuf;

    /* initialize all "sized" fields */
    encInArgs.size    = sizeof(encInArgs);
    decInArgs.size    = sizeof(decInArgs);
    encOutArgs.size   = sizeof(encOutArgs);
    decOutArgs.size   = sizeof(decOutArgs);
    encDynParams.size = sizeof(encDynParams);
    decDynParams.size = sizeof(decDynParams);
    encStatus.size    = sizeof(encStatus);
    decStatus.size    = sizeof(decStatus);

    /*
     * Note that we use versionBuf in both the encoder and decoder.  In this
     * application, this is okay, as there is always only one user of
     * the buffer.  Not all applications can make this assumption.
     */
    encStatus.data.buf     = decStatus.data.buf     = versionBuf;
    encStatus.data.bufSize = decStatus.data.bufSize = MAXVERSIONSIZE;

    /* if the codecs support it, dump their versions */
    status = IMGDEC1_control(dec, XDM_GETVERSION, &decDynParams, &decStatus);
    GT_1trace(curMask, GT_1CLASS, "Decoder version:  %s\n",
        (status == IMGDEC1_EOK ? ((char *)decStatus.data.buf) : "[unknown]"));

    status = IMGENC1_control(enc, XDM_GETVERSION, &encDynParams, &encStatus);
    GT_1trace(curMask, GT_1CLASS, "Encoder version:  %s\n",
        (status == IMGENC1_EOK ? ((char *)encStatus.data.buf) : "[unknown]"));

    /*
     * This app expects the encoder to accept 1 buf in and get 1 buf out,
     * and the buf sizes of the in and out buffer must be able to handle
     * NSAMPLES bytes of data.
     */
    status = IMGENC1_control(enc, XDM_GETBUFINFO, &encDynParams, &encStatus);
    if (status != IMGENC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "encode control status = 0x%x\n", status);
        return;
    }

    /* Validate this encoder codec will meet our buffer requirements */
    if ((inBufDesc.numBufs < encStatus.bufInfo.minNumInBufs) ||
        (IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) ||
        (encodedBufDesc.numBufs < encStatus.bufInfo.minNumOutBufs) ||
        (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "Error:  encoder codec feature conflict\n");
        return;
    }

    status = IMGDEC1_control(dec, XDM_GETBUFINFO, &decDynParams, &decStatus);
    if (status != IMGDEC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "decode control status = 0x%x\n", status);
        return;
    }

    /* Validate this decoder codec will meet our buffer requirements */
    if ((encodedBufDesc.numBufs < decStatus.bufInfo.minNumInBufs) ||
        (EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) ||
        (outBufDesc.numBufs < decStatus.bufInfo.minNumOutBufs) ||
        (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "App-> ERROR: decoder does not meet buffer requirements.\n");
        return;
    }

    /*
     * Read complete frames from in, encode, decode, and write to out.
     */
    for (n = 0; fread(inBuf, IFRAMESIZE, 1, in) == 1; n++) {

        if (appPause) {
            printf("About to start frame %d. Press Enter to continue...\n", n);
            appPause = ('c' == getchar() ? 0 : 1);
        }

        /* Deal with cache issues, if necessary */
#ifdef CACHE_ENABLED
#ifdef xdc_target__isaCompatible_64P
        /*
         *  fread() on this processor is implemented using CCS's stdio, which
         *  is known to write into the cache, not physical memory.  To meet
         *  xDAIS DMA Rule 7, we must writeback the cache into physical
         *  memory.  Also, per DMA Rule 7, we must invalidate the buffer's
         *  cache before providing it to any xDAIS algorithm.
         */
        Memory_cacheWbInv(inBuf, IFRAMESIZE);
#else
#error Unvalidated config - add appropriate fread-related cache maintenance
#endif
        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(encodedBuf, EFRAMESIZE);
#endif

        GT_1trace(curMask, GT_1CLASS, "App-> Processing frame %d...\n", n);

        /* encode the frame */
        status = IMGENC1_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs,
            &encOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Encoder frame %d process returned - 0x%x)\n",
            n, status);

#ifdef CACHE_ENABLED
        /* Writeback this outBuf from the previous call.  Also, as encodedBuf
         * is an inBuf to the next process call, we must invalidate it also, to
         * clean buffer lines.
         */
        Memory_cacheWbInv(encodedBuf, EFRAMESIZE);

        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(outBuf, OFRAMESIZE);
#endif

        if (status != IMGENC1_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Encoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, encOutArgs.extendedError);
            break;
        }

        /* decode the frame */
        decInArgs.numBytes = encOutArgs.bytesGenerated;
        status = IMGDEC1_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs,
           &decOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Decoder frame %d process returned - 0x%x)\n",
            n, status);

        if (status != IMGDEC1_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Decoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, decOutArgs.extendedError);
            break;
        }

#ifdef CACHE_ENABLED
        /* Writeback the outBuf. */
        Memory_cacheWb(outBuf, OFRAMESIZE);
#endif
        /* write to file */
        fwrite(outBuf, OFRAMESIZE, 1, out);

#ifdef USE_POWER_MANAGEMENT
        if (Global_usePowerManagement) {
            if (appPause) {
                printf("About to hibernate. Press Enter to continue...\n");
                appPause = ('c' == getchar() ? 0 : 1);
            }

            LPM_Status  lpmStat = LPM_SOK;
            GT_0trace(curMask, GT_2CLASS, "Turning DSP off\n");
            lpmStat = LPM_setPowerState(lpmHandle, LPM_HIBERNATE);
            if (lpmStat != LPM_SOK) {
                fprintf(stderr, "Error: LPM_setPowerState() failed\n");
                return;
            }

            if (appPause) {
                printf("DSP is off: Press Enter to continue...\n");
                appPause = ('c' == getchar() ? 0 : 1);
            }
            else {
                struct timeval tv;
                tv.tv_sec = 0;
                tv.tv_usec = 200000;  /* 200 msec */

                if (select(0, NULL, NULL, NULL, &tv) == -1) {
                    fprintf(stderr, "Error: select() failed\n");
                    return;
                }
            }

            GT_0trace(curMask, GT_1CLASS, "Turning DSP on\n");
            lpmStat = LPM_resume(lpmHandle);
            if (lpmStat != LPM_SOK) {
                fprintf(stderr, "Error: LPM_resume() failed\n");
                return;
            }

            if (appPause) {
                printf("DSP is on: Press Enter to continue...\n");
                appPause = ('c' == getchar() ? 0 : 1);
            }
        }
#endif
    }

    GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n);
}
Beispiel #17
0
/*!
 *  @brief  Function to invoke the APIs through ioctl.
 *
 *  @param  cmd     Command for driver ioctl
 *  @param  args    Arguments for the ioctl command
 *
 *  @sa
 */
Int GateMPDrv_ioctl(UInt32 cmd, Ptr args)
{
    Int                     status = GateMP_S_SUCCESS;
    Int                     osStatus = 0;
    GateMPDrv_CmdArgs * cargs = (GateMPDrv_CmdArgs *)args;

    GT_2trace (curTrace, GT_ENTER, "GateMPDrv_ioctl", cmd, args);

    switch (cmd) {

      case CMD_GATEMP_GETFREERES:
      {
          osStatus = devctl(IpcDrv_handle, DCMD_GATEMP_GETFREERES, cargs,
              sizeof(GateMPDrv_CmdArgs), NULL);

          if (osStatus != 0) {
              status = GateMP_E_OSFAILURE;
          }
      }
      break;

      case CMD_GATEMP_RELRES:
      {
          osStatus = devctl(IpcDrv_handle, DCMD_GATEMP_RELRES, cargs,
              sizeof(GateMPDrv_CmdArgs), NULL);

          if (osStatus != 0) {
              status = GateMP_E_OSFAILURE;
          }
      }
      break;

      case CMD_GATEMP_GETNUMRES:
      {
          osStatus = devctl(IpcDrv_handle, DCMD_GATEMP_GETNUMRES, cargs,
              sizeof(GateMPDrv_CmdArgs), NULL);

          if (osStatus != 0) {
              status = GateMP_E_OSFAILURE;
          }
      }
      break;

      case CMD_GATEMP_START:
      {
          osStatus = devctl(IpcDrv_handle, DCMD_GATEMP_START, cargs,
              sizeof(GateMPDrv_CmdArgs), NULL);

          if (osStatus != 0) {
              status = GateMP_E_OSFAILURE;
          }
      }
      break;

      case CMD_GATEMP_ISSETUP:
      {
          osStatus = devctl(IpcDrv_handle, DCMD_GATEMP_ISSETUP, cargs,
              sizeof(GateMPDrv_CmdArgs), NULL);

          if (osStatus != 0) {
              status = GateMP_E_OSFAILURE;
          }
      }
      break;

      default:
      {
          status = GateMP_E_INVALIDARG;
          GT_setFailureReason (curTrace,
                               GT_4CLASS,
                               "GateMPDrv_ioctl",
                               status,
                               "Unsupported ioctl command specified");
      }
      break;
    }

    if (status == GateMP_S_SUCCESS) {
        status = cargs->apiStatus;
    }

    GT_1trace(curTrace, GT_LEAVE, "GateMPDrv_ioctl", status);

    return (status);
}
Beispiel #18
0
/*
 *  ======== encode_decode ========
 */
static Void encode_decode(AUDENC1_Handle enc, AUDDEC1_Handle dec, FILE *in,
    FILE *out)
{
    Bool                        last;
    Int                         i;
    Int                         n;
    Int32                       status;
    Int                         decProcessIn = 0;
    Int                         decWaitIn = 0;
    Int                         decProcessOut = 0;
    Int                         decWaitOut = 0;
    Int                         encProcessIn = 0;
    Int                         encProcessOut = 0;

    for (i = 0; i < NBUFFERS; i++) {
        inBufDesc[i].descs[0].buf = inBuf[i];
        outBufDesc[i].descs[0].buf = outBuf[i];
        encodedBufDesc[i].descs[0].buf = encodedBuf[i];
        inBufDesc[i].numBufs = encodedBufDesc[i].numBufs =
          outBufDesc[i].numBufs = 1;
        inBufDesc[i].descs[0].bufSize = encodedBufDesc[i].descs[0].bufSize =
          outBufDesc[i].descs[0].bufSize = NSAMPLES;

        /* initialize all "sized" fields */
        encInArgs[i].size    = sizeof(encInArgs[i]);
        decInArgs[i].size    = sizeof(decInArgs[i]);
        encOutArgs[i].size   = sizeof(encOutArgs[i]);
        decOutArgs[i].size   = sizeof(decOutArgs[i]);

        /* ancillary data to encode */
#if USE_ANCDATA
        encInArgs[i].ancData.buf = ancBuf[i];
        encInArgs[i].ancData.bufSize = ENCANCBUFSIZE;
#else
        /* Be sure to initialize these to NULL! */
        encInArgs[i].ancData.buf = NULL;
        encInArgs[i].ancData.bufSize = 0;
#endif
    }
    encodedBufDesc[NBUFFERS].descs[0].buf = encodedBuf[NBUFFERS];
    encodedBufDesc[NBUFFERS].numBufs = 1;
    encodedBufDesc[NBUFFERS].descs[0].bufSize = NSAMPLES;
    encOutArgs[NBUFFERS].size = sizeof(encOutArgs[NBUFFERS]);
    decInArgs[NBUFFERS].size = sizeof(decInArgs[NBUFFERS]);

    encDynParams.size = sizeof(encDynParams);
    decDynParams.size = sizeof(decDynParams);
    encStatus.size    = sizeof(encStatus);
    decStatus.size    = sizeof(decStatus);

    /*
     * Note that we use versionBuf in both the encoder and decoder.  In this
     * application, this is okay, as there is always only one user of
     * the buffer.  Not all applications can make this assumption.
     */
    encStatus.data.buf     = decStatus.data.buf     = versionBuf;
    encStatus.data.bufSize = decStatus.data.bufSize = MAXVERSIONSIZE;

    /* if the codecs support it, dump their versions */
    status = AUDDEC1_control(dec, XDM_GETVERSION, &decDynParams, &decStatus);
    GT_1trace(curMask, GT_1CLASS, "Decoder version:  %s\n",
        (status == AUDDEC1_EOK ? ((char *)decStatus.data.buf) : "[unknown]"));

    status = AUDENC1_control(enc, XDM_GETVERSION, &encDynParams, &encStatus);
    GT_1trace(curMask, GT_1CLASS, "Encoder version:  %s\n",
        (status == AUDENC1_EOK ? ((char *)encStatus.data.buf) : "[unknown]"));

    /*
     * This app expects the encoder to accept 1 buf in and get 1 buf out,
     * and the buf sizes of the in and out buffer must be able to handle
     * NSAMPLES bytes of data.
     */
    status = AUDENC1_control(enc, XDM_GETBUFINFO, &encDynParams, &encStatus);
    if (status != AUDENC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "encode control status = %ld\n", status);
        return;
    }

    /* Validate this encoder codec will meet our buffer requirements */
    if ((inBufDesc[0].numBufs < encStatus.bufInfo.minNumInBufs) ||
        (IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) ||
        (encodedBufDesc[0].numBufs < encStatus.bufInfo.minNumOutBufs) ||
        (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "Error:  encoder codec feature conflict\n");
        return;
    }

    status = AUDDEC1_control(dec, XDM_GETBUFINFO, &decDynParams, &decStatus);
    if (status != AUDDEC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "decode control status = %ld\n", status);
        return;
    }

    /* Validate this decoder codec will meet our buffer requirements */
    if ((encodedBufDesc[0].numBufs < decStatus.bufInfo.minNumInBufs) ||
        (EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) ||
        (outBufDesc[0].numBufs < decStatus.bufInfo.minNumOutBufs) ||
        (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "App-> ERROR: decoder does not meet buffer requirements.\n");
        return;
    }

    /*
     * Read complete frames from in, encode, decode, and write to out.
     */
    for (n = 0; fread(inBuf[encProcessIn], IFRAMESIZE, 1, in) == 1; n++) {

        GT_1trace(curMask, GT_1CLASS, "App-> Processing encode frame %d...\n",
                  n);
        status = encodeIssue(enc, encProcessIn, encProcessOut);
        if (status != AUDENC1_EOK) {
            goto done;
        }

        UPDATE_INDEX(encProcessIn, NBUFFERS);
        UPDATE_INDEX(encProcessOut, NBUFFERS + 1);

        if (n == 0) {
            /*
             *  "Poor man's prologue" - need to feed encoder two buffers of
             *  input before reclaiming encoded data.
             */
            continue;
        }

        GT_1trace(curMask, GT_1CLASS, "App-> Waiting for encoded frame %d...\n",
                  n - 1);
        status = encodeReclaim(enc, decProcessOut, decProcessIn);
        if (status != AUDENC1_EOK) {
            goto done;
        }

        GT_1trace(curMask, GT_1CLASS, "App-> Processing decode frame %d...\n",
                  n - 1);
        status = decodeIssue(dec, decProcessIn, decProcessOut);
        if (status != AUDDEC1_EOK) {
            goto done;
        }

        UPDATE_INDEX(decProcessIn, NBUFFERS + 1);
        UPDATE_INDEX(decProcessOut, NBUFFERS);

        if (n == 1) {
            /*
             *  "Poor man's prologue" - need to feed decoder two buffers of
             *  input before reclaiming decoded data.
             */
            continue;
        }

        GT_1trace(curMask, GT_1CLASS, "App-> Waiting for decoded frame %d...\n",
                  n - 2);
        status = decodeReclaim(dec, decWaitIn, decWaitOut);
        if (status != AUDDEC1_EOK) {
            goto done;
        }

        GT_2trace(curMask, GT_1CLASS, "App-> Writing outBuf[%d]=%#x\n",
                  decWaitOut, outBuf[decWaitOut]);

        /* write to file */
        fwrite(outBuf[decWaitOut], OFRAMESIZE, 1, out);

        UPDATE_INDEX(decWaitIn, NBUFFERS + 1);
        UPDATE_INDEX(decWaitOut, NBUFFERS);
    }

    /*
     *  Due to the buffering achieved with async calls, at this point we still
     *  need to:
     *     - drain one buffer from the encoder
     *     - feed encoded buffer to the decoder
     *     - drain two buffers from the decoder
     *     - write decoded buffers to file
     */
    GT_1trace(curMask, GT_1CLASS, "App-> Waiting for encoded frame %d...\n",
              n - 1);
    status = encodeReclaim(enc, decProcessOut, decProcessIn);
    if (status != AUDENC1_EOK) {
        goto done;
    }

    /* decode the frame */
    GT_1trace(curMask, GT_1CLASS, "App-> Processing decode frame %d...\n",
              n - 1);
    status = decodeIssue(dec, decProcessIn, decProcessOut);
    if (status != AUDDEC1_EOK) {
        goto done;
    }

    UPDATE_INDEX(decProcessIn, NBUFFERS + 1);
    UPDATE_INDEX(decProcessOut, NBUFFERS);

    last = TRUE;

last_frame:
    GT_1trace(curMask, GT_1CLASS, "App-> Waiting for decoded frame %d...\n",
              n - 2);
    status = decodeReclaim(dec, decWaitIn, decWaitOut);
    if (status != AUDDEC1_EOK) {
        goto done;
    }

    GT_2trace(curMask, GT_1CLASS, "App-> Writing outBuf[%d]=%#x\n",
              decWaitOut, outBuf[decWaitOut]);

    /* write to file */
    fwrite(outBuf[decWaitOut], OFRAMESIZE, 1, out);

    UPDATE_INDEX(decWaitIn, NBUFFERS + 1);
    UPDATE_INDEX(decWaitOut, NBUFFERS);

    if (last) {
        /*
         *  "Poor man's epilogue" - need to reclaim and write last
         *  decoded buffer.
         */
        n++;
        last = FALSE;
        goto last_frame;
    }

done:
    GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n - 2);
}
Beispiel #19
0
/*
 *  ======== SPHENC_control ========
 *  This method must be the same for both local and remote invocation;
 *  each call site in the client might be calling different implementations
 *  (one that marshalls & sends and one that simply calls).  This API
 *  abstracts *all* speech encoders (both high and low complexity
 *  encoders are envoked using this method).
 */
XDAS_Int32 SPHENC_control(SPHENC_Handle handle, ISPHENC_Cmd id,
        ISPHENC_DynamicParams *dynParams, ISPHENC_Status *status)
{
    XDAS_Int32 retVal = SPHENC_EFAIL;

    SPHENC_DynamicParams refDynParams;
    XDAS_Int32 refStatusSize;

    /*
     * Note, we assign "VISA_isChecked()" results to a local variable
     * rather than repeatedly query it throughout this fxn because
     * someday we may allow dynamically changing the global
     * 'VISA_isChecked()' value on the fly.  If we allow that, we need
     * to ensure the value stays consistent in the context of this
     * call.
     */
    Bool checked = VISA_isChecked();

    if (checked) {
        /* Ensure dynParams and status are non-NULL, per the XDM spec */

        if ((!(XdmUtils_validateExtendedStruct(dynParams, sizeof(*dynParams),
                "dynParams"))) || (!(XdmUtils_validateExtendedStruct(status,
                sizeof(*status), "status")))) {
            /* for safety, return here before dereferencing and crashing */
            return (retVal);
        }
    }

    GT_6trace(CURTRACE, GT_ENTER, "SPHENC_control> "
        "Enter (handle=0x%x, id=%d, dynParams=0x%x (size=0x%x), "
        "status=0x%x (size=0x%x)\n",
        handle, id, dynParams, dynParams->size, status, status->size);

    if (handle) {
        ISPHENC_Fxns *fxns =
            (ISPHENC_Fxns *)VISA_getAlgFxns((VISA_Handle)handle);
        ISPHENC_Handle alg = VISA_getAlgHandle((VISA_Handle)handle);

        if ((fxns != NULL) && (alg != NULL)) {
            Log_printf(ti_sdo_ce_dvtLog, "%s", (Arg)"SPHENC:control",
                (Arg)handle, (Arg)0);

            if (checked) {

                /*
                 * Make a reference copy of dynParams, status->size, and
                 * status->data.bufSize so we can check that the codec
                 * didn't modify these read-only fields during control().
                 */
                refDynParams = *dynParams;
                refStatusSize = status->size;
            }

            VISA_enter((VISA_Handle)handle);
            retVal = fxns->control(alg, id, dynParams, status);
            VISA_exit((VISA_Handle)handle);

            if (checked) {
                /* ensure the codec didn't modify the read-only dynParams */
                if (memcmp(&refDynParams, dynParams, sizeof(*dynParams)) != 0) {
                    GT_1trace(CURTRACE, GT_7CLASS,
                        "ERROR> codec (0x%x) modified read-only dynParams "
                        "struct!\n", handle);
                }

                /* ensure the codec didn't change status->size */
                if (status->size != refStatusSize) {
                    GT_1trace(CURTRACE, GT_7CLASS,
                        "ERROR> codec (0x%x) modified read-only status->size "
                        "field!\n", handle);
                }
            }
        }
    }

    GT_2trace(CURTRACE, GT_ENTER, "SPHENC_control> "
        "Exit (handle=0x%x, retVal=0x%x)\n", handle, retVal);

    return (retVal);
}
Beispiel #20
0
/*
 *  ======== encode_decode ========
 */
static Void encode_decode(SPHENC_Handle enc, SPHDEC_Handle dec, FILE *in,
    FILE *out)
{
    Int                         n;
    Int32                       status;

    SPHDEC_InArgs               decInArgs;
    SPHDEC_OutArgs              decOutArgs;
    SPHDEC_DynamicParams        decDynParams;
    SPHDEC_Status               decStatus;

    SPHENC_InArgs               encInArgs;
    SPHENC_OutArgs              encOutArgs;
    SPHENC_DynamicParams        encDynParams;
    SPHENC_Status               encStatus;

    XDM_BufDesc                 inBufDesc;
    XDAS_Int8                  *src[XDM_MAX_IO_BUFFERS];
    XDAS_Int32                  inBufSizes[XDM_MAX_IO_BUFFERS];

    XDM_BufDesc                 encodedBufDesc;
    XDAS_Int8                  *encoded[XDM_MAX_IO_BUFFERS];
    XDAS_Int32                  encBufSizes[XDM_MAX_IO_BUFFERS];

    XDM_BufDesc                 outBufDesc;
    XDAS_Int8                  *dst[XDM_MAX_IO_BUFFERS];
    XDAS_Int32                  outBufSizes[XDM_MAX_IO_BUFFERS];

    /* clear and initialize the buffer descriptors */
    memset(src,     0, sizeof(src[0])     * XDM_MAX_IO_BUFFERS);
    memset(encoded, 0, sizeof(encoded[0]) * XDM_MAX_IO_BUFFERS);
    memset(dst,     0, sizeof(dst[0])     * XDM_MAX_IO_BUFFERS);

    src[0]     = inBuf;
    encoded[0] = encodedBuf;
    dst[0]     = outBuf;

    inBufDesc.numBufs = encodedBufDesc.numBufs = outBufDesc.numBufs = 1;

    inBufDesc.bufSizes      = inBufSizes;
    encodedBufDesc.bufSizes = encBufSizes;
    outBufDesc.bufSizes     = outBufSizes;

    inBufSizes[0] = encBufSizes[0] = outBufSizes[0] = NSAMPLES;

    inBufDesc.bufs      = src;
    encodedBufDesc.bufs = encoded;
    outBufDesc.bufs     = dst;

    /* initialize all "sized" fields */
    encInArgs.size    = sizeof(encInArgs);
    decInArgs.size    = sizeof(decInArgs);
    encOutArgs.size   = sizeof(encOutArgs);
    decOutArgs.size   = sizeof(decOutArgs);
    encDynParams.size = sizeof(encDynParams);
    decDynParams.size = sizeof(decDynParams);
    encStatus.size    = sizeof(encStatus);
    decStatus.size    = sizeof(decStatus);

    /*
     * Query the encoder and decoder.
     * This app expects the encoder to provide 1 buf in and get 1 buf out,
     * and the buf sizes of the in and out buffer must be able to handle
     * NSAMPLES bytes of data.
     */
    status = SPHENC_control(enc, XDM_GETBUFINFO, &encDynParams, &encStatus);
    if (status != SPHENC_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "encode control status = 0x%x\n", status);
        return;
    }

    /* Validate this encoder codec will meet our buffer requirements */
    if ((inBufDesc.numBufs < encStatus.bufInfo.minNumInBufs) ||
        (IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) ||
        (encodedBufDesc.numBufs < encStatus.bufInfo.minNumOutBufs) ||
        (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "Error:  encoder codec feature conflict\n");
        return;
    }

    status = SPHDEC_control(dec, XDM_GETBUFINFO, &decDynParams, &decStatus);
    if (status != SPHDEC_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "decode control status = 0x%x\n", status);
        return;
    }

    /* Validate this decoder codec will meet our buffer requirements */
    if ((encodedBufDesc.numBufs < decStatus.bufInfo.minNumInBufs) ||
        (EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) ||
        (outBufDesc.numBufs < decStatus.bufInfo.minNumOutBufs) ||
        (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "App-> ERROR: decoder does not meet buffer requirements.\n");
        return;
    }

    /*
     * Read complete frames from in, encode, decode, and write to out.
     */
    for (n = 0; fread(inBuf, IFRAMESIZE, 1, in) == 1; n++) {

#ifdef CACHE_ENABLED
#ifdef xdc_target__isaCompatible_64P
        /*
         *  fread() on this processor is implemented using CCS's stdio, which
         *  is known to write into the cache, not physical memory.  To meet
         *  xDAIS DMA Rule 7, we must writeback the cache into physical
         *  memory.  Also, per DMA Rule 7, we must invalidate the buffer's
         *  cache before providing it to any xDAIS algorithm.
         */
        Memory_cacheWbInv(inBuf, IFRAMESIZE);
#else
#error Unvalidated config - add appropriate fread-related cache maintenance
#endif
        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(encodedBuf, EFRAMESIZE);
#endif

        GT_1trace(curMask, GT_1CLASS, "App-> Processing frame %d...\n", n);

        /* encode the frame */
        status = SPHENC_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs,
            &encOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Encoder frame %d process returned - 0x%x\n",
            n, status);

#ifdef CACHE_ENABLED
        /* Writeback this outBuf from the previous call.  Also, as encodedBuf
         * is an inBuf to the next process call, we must invalidate it also, to
         * clean buffer lines.
         */
        Memory_cacheWbInv(encodedBuf, EFRAMESIZE);

        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(outBuf, OFRAMESIZE);
#endif

        if (status != SPHENC_EOK) {
            GT_2trace(curMask, GT_7CLASS,
                "App-> Encoder frame %d processing FAILED, status = 0x%x\n",
                n, status);
            break;
        }

        /* decode the frame */
        decInArgs.inBufferSize = encOutArgs.outbufferSize;
        status = SPHDEC_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs,
           &decOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Decoder frame %d process returned - 0x%x\n",
            n, status);

        if (status != SPHDEC_EOK) {
            GT_2trace(curMask, GT_7CLASS,
                "App-> Decoder frame %d processing FAILED, status = 0x%x\n",
                n, status);
            break;
        }

#ifdef CACHE_ENABLED
        /* Writeback the outBuf. */
        Memory_cacheWb(outBuf, OFRAMESIZE);
#endif
        /* write to file */
        fwrite(dst[0], OFRAMESIZE, 1, out);
    }

    GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n);
}
Beispiel #21
0
/*
 *  ======== procCreate ========
 */
static Bool procCreate(Processor_Handle proc)
{
    DSP_STATUS      status = DSP_SOK;
    ZcpyMqtAttrs    mqtAttrs;
    Bool            retVal;

    GT_1trace(curTrace, GT_ENTER, "Processor_create_d> Enter(proc=0x%x)\n",
            proc);

    /* TODO:L ignoring cpuId string, using 0 for cpuId */
    proc->cpuId = 0;

    /* call power on function -- either the real one, or the empty
     * stub defined by Global.xdt if power is not used.
     */
    if (Power_on(&proc->powerHandle) == Power_EFAIL) {
        retVal = FALSE;
        GT_0trace(curTrace, GT_6CLASS,
            "Processor_create_d> Power_on failed.\n");
        goto procCreate_return;
    }

    /* if using LAD: connect to LAD, startup DSP, attach with Link */
    if (Global_useLinkArbiter) {

        /* connect to LAD */
        ladStatus = LAD_connect(&handle);
        GT_2trace(curTrace, GT_2CLASS, "Processor_create_d> "
            "LAD_connect status = %x, handle = %x\n", ladStatus, handle);

        if (ladStatus != LAD_SUCCESS) {
            GT_1trace(curTrace, GT_7CLASS, "Processor_create_d> "
               "LAD_connect FAILED, status = [0x%x]\n", ladStatus);
            goto ladfail;
        }

        /* startup the DSP (if it isn't already started) */
        GT_2trace(curTrace, GT_2CLASS, "Processor_create_d> "
            "Loading %s on DSP, linkConfigName= %s ...\n", proc->imageName,
            proc->linkConfigName);
        ladStatus = LAD_startupDsp(handle, proc->cpuId, proc->linkConfigName,
            proc->imageName);
        GT_1trace(curTrace, GT_2CLASS, "Processor_create_d> "
            "LAD_startupDsp status = %x\n", ladStatus);

        /* on success, continue */
        if ((ladStatus == LAD_SUCCESS) || (ladStatus == LAD_ALREADYRUNNING)) {
#ifndef WIN32
            /*
             *  Must still call PROC_Attach from this app's process. (For
             *  WinCE, LAD runs in the same process, so PROC_Attach() returns
             *  an error.)
             */
            status = PROC_Attach(proc->cpuId, NULL);
            if (!DSP_SUCCEEDED(status)) {
                GT_1trace(curTrace, GT_7CLASS, "Processor_create_d> "
                    "PROC_Attach following LAD_startupDsp FAILED, "
                    "status=[0x%x]\n", (Uns) status);
                goto ladfail;
            }

            /* must still call POOL_Open from this app (NULL attributes) */
            status = POOL_Open (Global_cePoolId, NULL) ;
            if (!DSP_SUCCEEDED(status)) {
                GT_1trace(curTrace, GT_7CLASS, "Processor_create_d> "
                    "POOL_Open following LAD_startupDsp FAILED, "
                    "status=[0x%x]\n", (Uns) status);
            }
#endif
        }
        /* else, on fail, abort */
        else {
            GT_1trace(curTrace, GT_7CLASS, "Processor_create_d> "
                "LAD_startupDsp FAILED, status = [0x%x]\n", ladStatus);
            goto ladfail;
        }
    } /* end of 'if using LAD' */

    /* else, if no LAD, call Link's startup APIs directly */
    else {

        /*
         *  Create and initialize the PROC object.
         */
        GT_0trace(curTrace, GT_2CLASS, "Processor_create_d> "
            "Initializing DSP PROC...\n");

        modifyDefaultLinkCfgObjectForCENeeds();
        modifyDefaultLinkCfgObjectBasedOnUserCfgData(proc->imageName);

    dumpLinkCfgObj(&ti_sdo_ce_ipc_Processor_linkcfg);

        status = PROC_setup( &ti_sdo_ce_ipc_Processor_linkcfg );

        if (!DSP_SUCCEEDED(status)) {
            goto fail;
        }

        /*
         *  Attach the Dsp.
         */
        GT_0trace(curTrace, GT_2CLASS, "Processor_create_d> "
            "Attaching to DSP PROC...\n");

        status = PROC_Attach(proc->cpuId, NULL);
        if (!DSP_SUCCEEDED(status)) {
            goto fail;
        }

        /*
         *  Open a pool with buffers for both the control messages use by the
         *  transport and the application.
         */
        GT_0trace(curTrace, GT_2CLASS, "Processor_create_d> "
            "Opening MSGQ pool...\n");

        status = POOL_Open(Global_cePoolId, &Global_cePoolAttrs);
        if (!DSP_SUCCEEDED(status)) {
            goto fail;
        }

        /*
         *  Load the executable on the DSP.
         */
        GT_2trace(curTrace, GT_2CLASS, "Processor_create_d> "
            "Loading %s on DSP (%d args)...\n", proc->imageName,
            proc->attrs.argc);

        status = PROC_Load(proc->cpuId, proc->imageName,
            proc->attrs.argc, proc->attrs.argv);
        if (!DSP_SUCCEEDED(status)) {
            goto fail;
        }

        /*
         *  Start execution on DSP.
         */
        GT_0trace(curTrace, GT_2CLASS, "Processor_create_d> "
            "Starting DSP PROC...\n");

        status = PROC_Start(proc->cpuId);
        if (!DSP_SUCCEEDED(status)) {
            goto fail;
        }

        /*
         *  Open the remote transport to the DSP.
         */
        GT_0trace(curTrace, GT_2CLASS, "Processor_create_d> "
            "Opening remote transport...\n");
        /* tell the transport which open pool id to use for ctrl messages */
        mqtAttrs.poolId = Global_cePoolId;

        status = MSGQ_TransportOpen(proc->cpuId, &mqtAttrs);
        if (!DSP_SUCCEEDED(status)) {
            goto fail;
        }

    }  /* end of else to using LAD */

    /*
     *  Connect to the Power on the DSP
     */
    if (Power_connect(proc->powerHandle) == Power_EFAIL) {
        goto fail;
    }

    proc->connected = TRUE;

    if (Global_getenv("CE_DSPDEBUG") != NULL) {
        printf("Codec Engine system message (b/c CE_DSPDEBUG=1) : DSP image "
                "loaded and started, press Enter to continue: ");
        getchar();
    }

    retVal = TRUE;
    goto procCreate_return;

    /* TODO:[4] should try those asyncErrorHandlers that link supports?
     * (MSGQ_SetErrorHandler)
     */

fail:
    GT_4trace(curTrace, GT_7CLASS, "Processor_create_d> "
        "Loading and starting DSP server '%s' FAILED, status=[0x%x] "
        "(look for error code 'DSP_EBASE + 0x%x' in "
        "dsplink*/packages/dsplink/gpp/inc/usr/errbase.h) %s\n",
        proc->imageName, status,
        status & 0x7fff, status == DSP_ERANGE ?
            "This error code typically indicates a problem with the DSP memory "
            "map, i.e. it is different from what the Arm side specified; check "
            "the DSP server's memory map in your Arm application .cfg script, "
            "and make sure you have set 'armDspLinkConfig' "
            "configuration variable correctly (for details, refer to the "
            "documentation for ti.sdo.ce.Engine.xdc). Also, verify that "
            "the DSPLINKMEM segment on the DSP is large enough. "
            : ""
         );

ladfail:

    procDelete(proc);

    retVal = FALSE;

procCreate_return:

    GT_1trace(curTrace, GT_2CLASS, "Processor_create_d> return (%d)\n", retVal);

    return retVal;
}
Beispiel #22
0
/*
 *  ======== VIDDEC2FRONT_process ========
 *  This method must be the same for both local and remote invocation;
 *  each call site in the client might be calling different implementations
 *  (one that marshalls & sends and one that simply calls).  This API
 *  abstracts *all* video decoders (both high and low complexity
 *  decoders are envoked using this method).
 */
XDAS_Int32 VIDDEC2FRONT_process(VIDDEC2FRONT_Handle handle,
        VIDDEC2_InArgs *inArgs, XDM_Context *context,
        VIDDEC2FRONT_OutArgs *outArgs)
{
    XDAS_Int32 retVal = VIDDEC2_EFAIL;

    VIDDEC2_InArgs refInArgs;

    /*
     * Note, we do this because someday we may allow dynamically changing
     * the global 'VISA_isChecked()' value on the fly.  If we allow that,
     * we need to ensure the value stays consistent in the context of this call.
     */
    Bool checked = VISA_isChecked();

    GT_4trace(CURTRACE, GT_ENTER, "VIDDEC2FRONT_process> "
            "Enter (handle=0x%x, inArgs=0x%x, context=0x%x, outArgs=0x%x)\n",
            handle, inArgs, context, outArgs);

    if (handle) {
        IVIDDEC2FRONT_Fxns *fxns =
            (IVIDDEC2FRONT_Fxns *)VISA_getAlgFxns((VISA_Handle)handle);
        IVIDDEC2FRONT_Handle alg = VISA_getAlgHandle((VISA_Handle)handle);

        if (fxns && (alg != NULL)) {
            Log_printf(ti_sdo_ce_dvtLog, "%s", (Arg)"VIDDEC2FRONT:process",
                (Arg)handle, (Arg)0);

            if (checked) {

                /* validate inArgs with ranges. */
                if (inArgs->inputID == 0) {

                    GT_2trace(CURTRACE, GT_7CLASS,
                            "ERROR> app provided codec (0x%x) with out of range"
                            " inArgs->inputID field (0x%x)\n",
                            alg, inArgs->inputID);
                }

                /*
                 * Validate inBufs and outBufs.
                 */
//                XdmUtils_validateSparseBufDesc1(inBufs, "inBufs");
//                XdmUtils_validateSparseBufDesc(outBufs, "outBufs");

                /*
                 * Make a reference copy of inArgs so we can check that
                 * the codec didn't modify them during process().
                 */
                refInArgs = *inArgs;

                /* inArgs->inputID == 0 is an application error */
                if (inArgs->inputID == 0) {
                    GT_1trace(CURTRACE, GT_7CLASS,
                            "ERROR> codec (0x%x) received invalid "
                            "inArgs->inputID == 0!\n", handle);
                }
            }

            VISA_enter((VISA_Handle)handle);
            retVal = fxns->process(alg, inArgs, context, outArgs);
            VISA_exit((VISA_Handle)handle);

            if (checked) {
                /* ensure the codec didn't modify the read-only inArgs */
                if (memcmp(&refInArgs, inArgs, sizeof(*inArgs)) != 0) {
                    GT_1trace(CURTRACE, GT_7CLASS,
                            "ERROR> codec (0x%x) modified read-only inArgs "
                            "struct!\n", handle);
                }
            }

        }
    }

    GT_2trace(CURTRACE, GT_ENTER, "VIDDEC2FRONT_process> "
            "Exit (handle=0x%x, retVal=0x%x)\n", handle, retVal);

    return (retVal);
}
Beispiel #23
0
/*
 *  ======== marshallMsg ========
 */
static XDAS_Int32 marshallMsg(ISPHDEC_Handle h, XDM_BufDesc *inBufs,
    XDM_BufDesc *outBufs, ISPHDEC_InArgs *inArgs, ISPHDEC_OutArgs *outArgs,
    _SPHDEC_Msg **pmsg)
{
    XDAS_Int32 retVal = SPHDEC_EOK;
    VISA_Handle visa = (VISA_Handle)h;
    _SPHDEC_Msg *msg;
    Int i;
    ISPHDEC_OutArgs *pMsgOutArgs;
    Int payloadSize;

    /*
     * Validate arguments.  Do we want to do this _every_ time, or just in
     * checked builds?
     */
    if ((inArgs == NULL) || (inArgs->size < sizeof(ISPHDEC_InArgs)) ||
        (outArgs == NULL) || (outArgs->size < sizeof(ISPHDEC_OutArgs))) {

        /* invalid args, could even assert here, it's a spec violation. */
        return (SPHDEC_EFAIL);
    }

    if (pmsg == NULL) {
        return (SPHDEC_EFAIL);
    }

    /* make sure it'll all fit! */
    payloadSize = sizeof(VISA_MsgHeader) +
            (sizeof(msg->cmd.process.inBufs) * XDM_MAX_IO_BUFFERS) +
            sizeof(msg->cmd.process.numInBufs) +
            (sizeof(msg->cmd.process.inBufSizes[0]) * XDM_MAX_IO_BUFFERS) +
            (sizeof(msg->cmd.process.outBufs) * XDM_MAX_IO_BUFFERS) +
            sizeof(msg->cmd.process.numOutBufs) +
            (sizeof(msg->cmd.process.outBufSizes[0]) * XDM_MAX_IO_BUFFERS) +
            inArgs->size + outArgs->size;

    if (payloadSize > VISA_getMaxMsgSize(visa)) {
        /* Can't handle these large extended args. */
        GT_2trace(CURTRACE, GT_6CLASS,
                "process> invalid arguments - too big (0x%x > 0x%x).  "
                "Validate .size fields\n", payloadSize,
                VISA_getMaxMsgSize(visa));

        return (SPHDEC_EFAIL);
    }

    /* get a message appropriate for this algorithm */
    if ((msg = (_SPHDEC_Msg *)VISA_allocMsg(visa)) == NULL) {
        return (ISPHDEC_ERUNTIME);
    }

    /*
     * Marshall the command: copy the client-passed arguments into flattened
     * message data structures, converting every pointer address to alg.
     * data buffer into physical address.
     */

    /* First specify the processing command that the skeleton should do */
    msg->visa.cmd = _SPHDEC_CPROCESS;

    /* commentary follows for marshalling the inBufs argument: */

    /* 1) inBufs->numBufs is a plain integer, we just copy it */
    msg->cmd.process.numInBufs = inBufs->numBufs;

    /* 2) inBufs->bufSizes is an array of integers, we copy them all */
    for (i = 0; i < inBufs->numBufs; i++) {
        msg->cmd.process.inBufSizes[i] = inBufs->bufSizes[i];
    }

    /* 3) inBufs->bufs is a pointer to an array of pointers, so we take
     * individual pointers, convert them, and store in the the message
     * counterpart of inBufs->bufs
     */
    for (i = 0; i < inBufs->numBufs; i++) {
        msg->cmd.process.inBufs[i] = (XDAS_Int8 *)
            Memory_getBufferPhysicalAddress(inBufs->bufs[i],
                inBufs->bufSizes[i], NULL);

        if (msg->cmd.process.inBufs[i] == NULL) {
            retVal = SPHDEC_ERUNTIME;
            goto exit;
        }
    }

    /* we're done (with inBufs). Because msg->cmd.process is non-cacheable
     * and contiguous (it has been allocated by MSGQ), we don't have to do
     * anything else.
     */

    /* Now we repeat the procedure for outBufs. Note that
     * inArgs and outArgs contain no pointers, so we can simply copy the
     * entire original structure, accounting for the first "size" field.
     */
    msg->cmd.process.numOutBufs = outBufs->numBufs;
    for (i = 0; i < outBufs->numBufs; i++) {
        msg->cmd.process.outBufSizes[i] = outBufs->bufSizes[i];
    }

    for (i = 0; i < outBufs->numBufs; i++) {
        msg->cmd.process.outBufs[i] = (XDAS_Int8 *)
            Memory_getBufferPhysicalAddress(outBufs->bufs[i],
                outBufs->bufSizes[i], NULL);

        if (msg->cmd.process.outBufs[i] == NULL) {
            retVal = SPHDEC_ERUNTIME;
            goto exit;
        }
    }

    /* inArgs has no pointers so simply memcpy "size" bytes into the msg */
    memcpy(&(msg->cmd.process.inArgs), inArgs, inArgs->size);

    /* point at outArgs and set the "size" */
    pMsgOutArgs = (ISPHDEC_OutArgs *)((UInt)(&(msg->cmd.process.inArgs)) +
        inArgs->size);

    /* set the size field - the rest is filled in by the codec */
    /* TODO:H probably want to zero out the rest of the outArgs struct */
    pMsgOutArgs->size = outArgs->size;

    *pmsg = msg;

    return (retVal);

exit:
    VISA_freeMsg(visa, (VISA_Msg)msg);

    return (retVal);
}
Beispiel #24
0
/*
 *  ======== encode_decode ========
 */
static Void encode_decode(SPHENC1_Handle enc, SPHDEC1_Handle dec, FILE *in,
    FILE *out)
{
    Int                         n;
    Int32                       status;

    SPHDEC1_InArgs              decInArgs;
    SPHDEC1_OutArgs             decOutArgs;
    SPHDEC1_DynamicParams       decDynParams;
    SPHDEC1_Status              decStatus;

    SPHENC1_InArgs              encInArgs;
    SPHENC1_OutArgs             encOutArgs;
    SPHENC1_DynamicParams       encDynParams;
    SPHENC1_Status              encStatus;

    XDM1_SingleBufDesc          inBufDesc;
    XDM1_SingleBufDesc          encodedBufDesc;
    XDM1_SingleBufDesc          outBufDesc;

    /* init buffer descriptor settings that don't change during processing */
    inBufDesc.bufSize = IFRAMESIZE;
    inBufDesc.buf = inBuf;
    encodedBufDesc.buf = encodedBuf;
    outBufDesc.buf = outBuf;

    /* initialize all "sized" fields */
    encInArgs.size    = sizeof(encInArgs);
    decInArgs.size    = sizeof(decInArgs);
    encOutArgs.size   = sizeof(encOutArgs);
    decOutArgs.size   = sizeof(decOutArgs);
    encDynParams.size = sizeof(encDynParams);
    decDynParams.size = sizeof(decDynParams);
    encStatus.size    = sizeof(encStatus);
    decStatus.size    = sizeof(decStatus);

    /*
     * We never use the decoder or encoder's inArgs.data fields, so
     * initialize them NULL.
     */
    decInArgs.data.buf = NULL;
    encInArgs.data.buf = NULL;

    /*
     * Note that we use versionBuf in both the encoder and decoder.  In this
     * application, this is okay, as there is always only one user of
     * the buffer.  Not all applications can make this assumption.
     */
    encStatus.data.buf     = decStatus.data.buf     = versionBuf;
    encStatus.data.bufSize = decStatus.data.bufSize = MAXVERSIONSIZE;

    /* if the codecs support it, dump their versions */
    status = SPHDEC1_control(dec, XDM_GETVERSION, &decDynParams, &decStatus);
    GT_1trace(curMask, GT_1CLASS, "Decoder version:  %s\n",
        (status == SPHDEC1_EOK ? ((char *)decStatus.data.buf) : "[unknown]"));

    status = SPHENC1_control(enc, XDM_GETVERSION, &encDynParams, &encStatus);
    GT_1trace(curMask, GT_1CLASS, "Encoder version:  %s\n",
        (status == SPHENC1_EOK ? ((char *)encStatus.data.buf) : "[unknown]"));

    /*
     * This app expects the encoder to provide 1 buf in and get 1 buf out,
     * and the buf sizes of the in and out buffer must be able to handle
     * NSAMPLES bytes of data.
     */
    status = SPHENC1_control(enc, XDM_GETSTATUS, &encDynParams, &encStatus);
    if (status != SPHENC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "encode control status = %ld\n", status);
        return;
    }

    /* Validate this encoder codec will meet our buffer requirements */
    if ((IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) ||
        (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "Error:  encoder codec feature conflict\n");
        return;
    }

    status = SPHDEC1_control(dec, XDM_GETSTATUS, &decDynParams, &decStatus);
    if (status != SPHDEC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "decode control status = %ld\n", status);
        return;
    }

    /* Validate this decoder codec will meet our buffer requirements */
    if ((EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) ||
        (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "App-> ERROR: decoder does not meet buffer requirements.\n");
        return;
    }

    /*
     * Read complete frames from in, encode, decode, and write to out.
     */
    for (n = 0; fread(inBuf, IFRAMESIZE, 1, in) == 1; n++) {

        /* reset potentially changed 'output' buffers to actual buf sizes. */
        encodedBufDesc.bufSize = EFRAMESIZE;
        outBufDesc.bufSize = OFRAMESIZE;


#ifdef CACHE_ENABLED
#ifdef xdc_target__isaCompatible_64P
        /*
         *  fread() on this processor is implemented using CCS's stdio, which
         *  is known to write into the cache, not physical memory.  To meet
         *  xDAIS DMA Rule 7, we must writeback the cache into physical
         *  memory.  Also, per DMA Rule 7, we must invalidate the buffer's
         *  cache before providing it to any xDAIS algorithm.
         */
        Memory_cacheWbInv(inBuf, IFRAMESIZE);
#else
#error Unvalidated config - add appropriate fread-related cache maintenance
#endif
        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(encodedBuf, encodedBufDesc.bufSize);
#endif

        GT_1trace(curMask, GT_1CLASS, "App-> Processing frame %d...\n", n);

        /* encode the frame */
        status = SPHENC1_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs,
            &encOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Encoder frame %d process returned - 0x%x)\n",
            n, status);

#ifdef CACHE_ENABLED
        /* Writeback this outBuf from the previous call.  Also, as encodedBuf
         * is an inBuf to the next process call, we must invalidate it also, to
         * clean buffer lines.
         */
        Memory_cacheWbInv(encodedBuf, encodedBufDesc.bufSize);

        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(outBuf, outBufDesc.bufSize);
#endif

        if (status != SPHENC1_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Encoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, encOutArgs.extendedError);
            break;
        }

        /* decode the frame */
        status = SPHDEC1_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs,
           &decOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Decoder frame %d process returned - 0x%x)\n",
            n, status);

        if (status != SPHDEC1_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Decoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, decOutArgs.extendedError);
            break;
        }

#ifdef CACHE_ENABLED
        /* Writeback the outBuf. */
        Memory_cacheWb(outBuf, outBufDesc.bufSize);
#endif
        /* write to file */
        fwrite(outBuf, outBufDesc.bufSize, 1, out);
    }

    GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n);
}
/*
 *  ======== encode_decode ========
 */
static Void encode_decode(AUDENC1_Handle enc, AUDDEC1_Handle dec, FILE *in,
    FILE *out)
{
    Int                         n;
    Int32                       status;

    AUDDEC1_InArgs              decInArgs;
    AUDDEC1_OutArgs             decOutArgs;
    AUDDEC1_DynamicParams       decDynParams;
    AUDDEC1_Status              decStatus;

    AUDENC1_InArgs              encInArgs;
    AUDENC1_OutArgs             encOutArgs;
    AUDENC1_DynamicParams       encDynParams;
    AUDENC1_Status              encStatus;

    XDM1_BufDesc                inBufDesc;
    XDM1_BufDesc                encodedBufDesc;
    XDM1_BufDesc                outBufDesc;

    /* initialize the buffer descriptors */
    inBufDesc.numBufs = encodedBufDesc.numBufs = outBufDesc.numBufs = 1;
    inBufDesc.descs[0].bufSize = encodedBufDesc.descs[0].bufSize =
        outBufDesc.descs[0].bufSize = NSAMPLES;

    inBufDesc.descs[0].buf      = inBuf;
    encodedBufDesc.descs[0].buf = encodedBuf;
    outBufDesc.descs[0].buf     = outBuf;

    /* initialize all "sized" fields */
    encInArgs.size    = sizeof(encInArgs);
    decInArgs.size    = sizeof(decInArgs);
    encOutArgs.size   = sizeof(encOutArgs);
    decOutArgs.size   = sizeof(decOutArgs);
    encDynParams.size = sizeof(encDynParams);
    decDynParams.size = sizeof(decDynParams);
    encStatus.size    = sizeof(encStatus);
    decStatus.size    = sizeof(decStatus);

    /* ancillary data to encode */
#if USE_ANCDATA
    encInArgs.ancData.buf = ancBuf;
    encInArgs.ancData.bufSize = ENCANCBUFSIZE;
#else
    /* Be sure to initialize these to NULL! */
    encInArgs.ancData.buf = NULL;
    encInArgs.ancData.bufSize = 0;
#endif
    /*
     * Note that we use versionBuf in both the encoder and decoder.  In this
     * application, this is okay, as there is always only one user of
     * the buffer.  Not all applications can make this assumption.
     */
    encStatus.data.buf     = decStatus.data.buf     = versionBuf;
    encStatus.data.bufSize = decStatus.data.bufSize = MAXVERSIONSIZE;

    /* if the codecs support it, dump their versions */
    status = AUDDEC1_control(dec, XDM_GETVERSION, &decDynParams, &decStatus);
    GT_1trace(curMask, GT_1CLASS, "Decoder version:  %s\n",
        (status == AUDDEC1_EOK ? ((char *)decStatus.data.buf) : "[unknown]"));

    status = AUDENC1_control(enc, XDM_GETVERSION, &encDynParams, &encStatus);
    GT_1trace(curMask, GT_1CLASS, "Encoder version:  %s\n",
        (status == AUDENC1_EOK ? ((char *)encStatus.data.buf) : "[unknown]"));

    /*
     * This app expects the encoder to accept 1 buf in and get 1 buf out,
     * and the buf sizes of the in and out buffer must be able to handle
     * NSAMPLES bytes of data.
     */
    status = AUDENC1_control(enc, XDM_GETBUFINFO, &encDynParams, &encStatus);
    if (status != AUDENC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "encode control status = %ld\n", status);
        return;
    }

    /* Validate this encoder codec will meet our buffer requirements */
    if ((inBufDesc.numBufs < encStatus.bufInfo.minNumInBufs) ||
        (IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) ||
        (encodedBufDesc.numBufs < encStatus.bufInfo.minNumOutBufs) ||
        (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "Error:  encoder codec feature conflict\n");
        return;
    }

    status = AUDDEC1_control(dec, XDM_GETBUFINFO, &decDynParams, &decStatus);
    if (status != AUDDEC1_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "decode control status = %ld\n", status);
        return;
    }

    /* Validate this decoder codec will meet our buffer requirements */
    if ((encodedBufDesc.numBufs < decStatus.bufInfo.minNumInBufs) ||
        (EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) ||
        (outBufDesc.numBufs < decStatus.bufInfo.minNumOutBufs) ||
        (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "App-> ERROR: decoder does not meet buffer requirements.\n");
        return;
    }

    /*
     * Read complete frames from in, encode, decode, and write to out.
     */
    for (n = 0; fread(inBuf, IFRAMESIZE, 1, in) == 1; n++) {

#if USE_ANCDATA
        /* we send the same data as inBuf as ancillory data */
        memcpy(ancBuf, inBuf, ENCANCBUFSIZE);
#endif

        /* Deal with cache issues, if necessary */
#ifdef CACHE_ENABLED
#ifdef xdc_target__isaCompatible_64P
        /*
         *  fread() on this processor is implemented using CCS's stdio, which
         *  is known to write into the cache, not physical memory.  To meet
         *  xDAIS DMA Rule 7, we must writeback the cache into physical
         *  memory.  Also, per DMA Rule 7, we must invalidate the buffer's
         *  cache before providing it to any xDAIS algorithm.
         */
        Memory_cacheWbInv(inBuf, IFRAMESIZE);
#else
#error Unvalidated config - add appropriate fread-related cache maintenance
#endif

#if USE_ANCDATA
        /* ancBuf is an inBuf, filled via memcpy (i.e. CPU writes) */
        Memory_cacheWbInv(ancBuf, ENCANCBUFSIZE);
#endif

        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(encodedBuf, EFRAMESIZE);
#endif

        GT_1trace(curMask, GT_1CLASS, "App-> Processing frame %d...\n", n);

        /*
         * Encode the frame.  Note that .numInSamples is the number of
         * _samples_ not bytes.  IFRAMESIZE is in 8-bit bytes, so there's a
         * little math here to get .numInSamples right.
         */
        encInArgs.numInSamples =
            (IFRAMESIZE / (ENCBITSPERSAMPLE / (8 /* bits per byte */)));
        status = AUDENC1_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs,
            &encOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Encoder frame %d process returned - 0x%x)\n",
            n, status);

#ifdef CACHE_ENABLED
        /* Writeback this outBuf from the previous call.  Also, as encodedBuf
         * is an inBuf to the next process call, we must invalidate it also, to
         * clean buffer lines.
         */
        Memory_cacheWbInv(encodedBuf, EFRAMESIZE);

        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(outBuf, OFRAMESIZE);
#endif

        if (status != AUDENC1_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Encoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, encOutArgs.extendedError);
            break;
        }

        /* decode the frame */
        decInArgs.numBytes = EFRAMESIZE;
        status = AUDDEC1_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs,
           &decOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Decoder frame %d process returned - 0x%x)\n",
            n, status);

        if (status != AUDDEC1_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Decoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, decOutArgs.extendedError);
            break;
        }

#ifdef CACHE_ENABLED
        /* Writeback the outBuf. */
        Memory_cacheWb(outBuf, OFRAMESIZE);
#endif
        /* write to file */
        fwrite(outBuf, OFRAMESIZE, 1, out);
    }

    GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n);
}
Beispiel #26
0
/*
 *  ======== MEM_Calloc ========
 *  Purpose:
 *      Allocate zero-initialized memory from the paged or non-paged pools.
 */
void *MEM_Calloc(u32 cBytes, enum MEM_POOLATTRS type)
{
	struct memInfo *pMem = NULL;

	GT_2trace(MEM_debugMask, GT_ENTER,
		  "MEM_Calloc: cBytes 0x%x\ttype 0x%x\n",
		  cBytes, type);

	if (cBytes > 0) {
		switch (type) {
		case MEM_NONPAGED:
		/* If non-paged memory required, see note at top of file. */
		case MEM_PAGED:
#ifndef MEM_CHECK
			pMem = kmalloc(cBytes,
				(in_atomic()) ? GFP_ATOMIC : GFP_KERNEL);
			if (pMem)
				memset(pMem, 0, cBytes);

#else
			pMem = kmalloc(cBytes + sizeof(struct memInfo),
				(in_atomic()) ? GFP_ATOMIC : GFP_KERNEL);
			if (pMem) {
				memset((void *)((u32)pMem +
					sizeof(struct memInfo)), 0, cBytes);
				pMem->size = cBytes;
				pMem->caller = __builtin_return_address(0);
				pMem->dwSignature = memInfoSign;
				spin_lock(&mMan.lock);
				MLST_PutTail(&mMan.lst,
					(struct LST_ELEM *) pMem);
				spin_unlock(&mMan.lock);
				pMem = (void *)((u32)pMem +
					sizeof(struct memInfo));
			}
#endif
			break;
		case MEM_LARGEVIRTMEM:
#ifndef MEM_CHECK
			/* FIXME - Replace with 'vmalloc' after BP fix */
			pMem = __vmalloc(cBytes,
			(in_atomic()) ? GFP_ATOMIC : GFP_KERNEL, PAGE_KERNEL);
			if (pMem)
				memset(pMem, 0, cBytes);

#else
			/* FIXME - Replace with 'vmalloc' after BP fix */
			pMem = __vmalloc(cBytes + sizeof(struct memInfo),
			(in_atomic()) ? GFP_ATOMIC : GFP_KERNEL, PAGE_KERNEL);
			if (pMem) {
				memset((void *)((u32)pMem +
					sizeof(struct memInfo)), 0, cBytes);
				pMem->size = cBytes;
				pMem->caller = __builtin_return_address(0);
				pMem->dwSignature = memInfoSign;
				spin_lock(&mMan.lock);
				MLST_PutTail(&mMan.lst, (struct LST_ELEM *)
					pMem);
				spin_unlock(&mMan.lock);
				pMem = (void *)((u32)pMem +
					sizeof(struct memInfo));
			}
#endif
			break;
		default:
			GT_1trace(MEM_debugMask, GT_6CLASS,
				  "MEM_Calloc: unexpected "
				  "MEM_POOLATTRS value 0x%x\n", type);
			break;
		}
	}

	return pMem;
}
/*!
 *  @brief  Function to invoke the APIs through ioctl.
 *
 *  @param  cmd     Command for driver ioctl
 *  @param  args    Arguments for the ioctl command
 *
 *  @sa
 */
Int
SharedRegionDrv_ioctl (UInt32 cmd, Ptr args)
{
    Int                       status   = SharedRegion_S_SUCCESS;
    int                       osStatus = -1;
    SharedRegionDrv_CmdArgs * cargs    = (SharedRegionDrv_CmdArgs *) args;
    SharedRegion_Region    *  regions  = NULL;
    SharedRegion_Config *     config;
    Memory_MapInfo            mapInfo;
    UInt16                    i;

    GT_2trace (curTrace, GT_ENTER, "SharedRegionDrv_ioctl", cmd, args);

/*  TODO: SharedRegionDrv_refCount not defined in QNX build
 *  GT_assert (curTrace, (SharedRegionDrv_refCount > 0));
 */

    switch (cmd) {

        case CMD_SHAREDREGION_GETCONFIG:
        {
			SharedRegionDrv_CmdArgs *cargs = (SharedRegionDrv_CmdArgs *)args;
			iov_t sharedregion_getconfig_iov[2];
			SharedRegion_Config * shreg_config = cargs->args.getConfig.config;

			SETIOV( &sharedregion_getconfig_iov[0], cargs, sizeof(SharedRegionDrv_CmdArgs) );
			SETIOV( &sharedregion_getconfig_iov[1], cargs->args.getConfig.config, sizeof(SharedRegion_Config) );

			/* the osal_drv handle is used instead of ipcdrv_handle as the ipcdrc_handle is not yet initialized */
			osStatus = devctlv( OsalDrv_handle, DCMD_SHAREDREGION_GETCONFIG, 1, 2, sharedregion_getconfig_iov, sharedregion_getconfig_iov, NULL);

			if ( osStatus == 0 ){
				cargs->args.getConfig.config = shreg_config;
			}
        }
        break;

        case CMD_SHAREDREGION_SETUP:
        {
			SharedRegionDrv_CmdArgs *cargs = (SharedRegionDrv_CmdArgs *)args;
			iov_t sharedregion_setup_iov[3];

			SETIOV( &sharedregion_setup_iov[0], cargs, sizeof(SharedRegionDrv_CmdArgs) );
			SETIOV( &sharedregion_setup_iov[1], cargs->args.setup.config, sizeof(SharedRegion_Config) );
			SETIOV( &sharedregion_setup_iov[2], cargs->args.setup.regions, cargs->args.setup.config->numEntries * sizeof(SharedRegion_Region) );

			osStatus = devctlv( IpcDrv_handle, DCMD_SHAREDREGION_SETUP, 2, 3, sharedregion_setup_iov, sharedregion_setup_iov, NULL);
        }
        break;


        case CMD_SHAREDREGION_GETREGIONINFO:
        {
			SharedRegionDrv_CmdArgs *cargs = (SharedRegionDrv_CmdArgs *)args;
			iov_t sharedregion_getregconfig_iov[2];	/* no of max shared region entries + 1 */
            //UInt16              i=0;
            SharedRegion_Config   config;

            SharedRegion_getConfig (&config);
			SETIOV( &sharedregion_getregconfig_iov[0], cargs, sizeof(SharedRegionDrv_CmdArgs) );
			SETIOV( &sharedregion_getregconfig_iov[1], cargs->args.getRegionInfo.regions, (sizeof(SharedRegion_Region) * config.numEntries));

			//for (i = 1; i< cargs->args.getConfig.config->numEntries+1;i++) {
			//	SETIOV( &sharedregion_getregconfig_iov[i], &cargs->args.setup.regions[i-1], sizeof(SharedRegion_Region) );
			//}

//			SETIOV( &sharedregion_getregconfig_iov[1], cargs->args.setup.regions, (sizeof(SharedRegion_Region) * cargs->args.getConfig.config->numEntries));

			//osStatus = devctlv( IpcDrv_handle, DCMD_SHAREDREGION_GETREGIONINFO, 1, cargs->args.getConfig.config->numEntries + 1, sharedregion_getregconfig_iov, sharedregion_getregconfig_iov, NULL);
			osStatus = devctlv( IpcDrv_handle, DCMD_SHAREDREGION_GETREGIONINFO, 2, 2, sharedregion_getregconfig_iov, sharedregion_getregconfig_iov, NULL);
        }
        break;

        case CMD_SHAREDREGION_DESTROY:
        {
			osStatus = devctl( IpcDrv_handle, DCMD_SHAREDREGION_DESTROY, cargs, sizeof(SharedRegionDrv_CmdArgs), NULL);
        }
        break;

        case CMD_SHAREDREGION_START:
        {
			osStatus = devctl( IpcDrv_handle, DCMD_SHAREDREGION_START, cargs, sizeof(SharedRegionDrv_CmdArgs), NULL);
        }
        break;

        case CMD_SHAREDREGION_STOP:
        {
			osStatus = devctl( IpcDrv_handle, DCMD_SHAREDREGION_STOP, cargs, sizeof(SharedRegionDrv_CmdArgs), NULL);
        }
        break;

        case CMD_SHAREDREGION_ATTACH:
        {
			osStatus = devctl( IpcDrv_handle, DCMD_SHAREDREGION_ATTACH, cargs, sizeof(SharedRegionDrv_CmdArgs), NULL);
        }
        break;

        case CMD_SHAREDREGION_DETACH:
        {
			osStatus = devctl( IpcDrv_handle, DCMD_SHAREDREGION_DETACH, cargs, sizeof(SharedRegionDrv_CmdArgs), NULL);
        }
        break;

        case CMD_SHAREDREGION_SETENTRY:
        {

			SharedRegionDrv_CmdArgs *cargs = (SharedRegionDrv_CmdArgs *)args;

			iov_t sharedregion_getregsetentry_iov[2];

			SETIOV( &sharedregion_getregsetentry_iov[0], cargs, sizeof(SharedRegionDrv_CmdArgs) );
			SETIOV( &sharedregion_getregsetentry_iov[1], &cargs->args.setEntry.entry, sizeof(SharedRegion_Entry) );

			osStatus = devctlv( IpcDrv_handle, DCMD_SHAREDREGION_SETENTRY, 2, 1, sharedregion_getregsetentry_iov, sharedregion_getregsetentry_iov, NULL);
		}
        break;

        case CMD_SHAREDREGION_CLEARENTRY:
        {
			osStatus = devctl( IpcDrv_handle, DCMD_SHAREDREGION_CLEARENTRY, cargs, sizeof(SharedRegionDrv_CmdArgs), NULL);
        }
        break;

        case CMD_SHAREDREGION_GETHEAP:
        {

			osStatus = devctl( IpcDrv_handle, DCMD_SHAREDREGION_GETHEAP, cargs, sizeof(SharedRegionDrv_CmdArgs), NULL);
        }
        break;

        case CMD_SHAREDREGION_RESERVEMEMORY:
        {
			osStatus = devctl( IpcDrv_handle, DCMD_SHAREDREGION_RESERVEMEMORY, cargs, sizeof(SharedRegionDrv_CmdArgs), NULL);
        }
        break;

        case CMD_SHAREDREGION_CLEARRESERVEDMEMORY:
        {
			osStatus = devctl( IpcDrv_handle, DCMD_SHAREDREGION_CLEARRESERVEDMEMORY, cargs, sizeof(SharedRegionDrv_CmdArgs), NULL);
        }
        break;

        default:
        {
            /* This does not impact return status of this function, so retVal
             * comment is not used.
             */
            status = SharedRegion_E_INVALIDARG;
            GT_setFailureReason (curTrace,
                                 GT_4CLASS,
                                 "SharedRegionDrv_ioctl",
                                 status,
                                 "Unsupported ioctl command specified");
        }
        break;
    }

    if (osStatus != 0) {
        /*! @retval SharedRegion_E_OSFAILURE Driver ioctl failed */
        status = SharedRegion_E_OSFAILURE;
        GT_setFailureReason (curTrace,
                             GT_4CLASS,
                             "SharedRegionDrv_ioctl",
                             status,
                             "Driver ioctl failed!");
    }
    else {
        /* First field in the structure is the API status. */
        status = ((SharedRegionDrv_CmdArgs *) cargs)->apiStatus;

        /* Convert the base address to user virtual address */
        if (cmd == CMD_SHAREDREGION_SETUP) {
            config = cargs->args.setup.config;
            for (i = 0u; (   (i < config->numEntries) && (status >= 0)); i++) {
                regions = &(cargs->args.setup.regions [i]);
                if (regions->entry.isValid == TRUE) {
                    mapInfo.src  = (UInt32) regions->entry.base;
                    mapInfo.size = regions->entry.len;
                    status = Memory_map (&mapInfo);
                    if (status < 0) {
                        GT_setFailureReason (curTrace,
                                             GT_4CLASS,
                                             "SharedRegionDrv_ioctl",
                                             status,
                                             "Memory_map failed!");
                    }
                    else {
                        regions->entry.base = (Ptr) mapInfo.dst;
                    }
                }
            }
        }
        else {
            /* TBD: Need to do Memory_unmap in destroy. */
        }
    }

    GT_1trace (curTrace, GT_LEAVE, "SharedRegionDrv_ioctl", status);

/*! @retval SharedRegion_S_SUCCESS Operation successfully completed. */
    return status;
}
Beispiel #28
0
/*!
 *  @brief  Function to invoke the APIs through devctl.
 *
 *  @param  cmd     Command for driver ioctl
 *  @param  args    Arguments for the ioctl command
 *
 *  @sa
 */
Int
MultiProcDrv_ioctl (UInt32 cmd, Ptr args)
{
    Int status      = MultiProc_S_SUCCESS;
    int osStatus    = 0;

	MultiProcDrv_CmdArgs *	cargs	 = (MultiProcDrv_CmdArgs *) args;

    GT_2trace (curTrace, GT_ENTER, "MultiProcDrv_ioctl", cmd, args);

	switch (cmd) {

		   case CMD_MULTIPROC_SETUP:
		   {
			   iov_t setup_iov[2];

			   SETIOV( &setup_iov[0], cargs, sizeof(MultiProcDrv_CmdArgs) );
			   SETIOV( &setup_iov[1], cargs->args.setup.config, sizeof(MultiProc_Config) );

			   osStatus = devctlv( IpcDrv_handle, DCMD_MULTIPROC_SETUP, 2, 2, setup_iov, setup_iov, NULL);

				if ( osStatus != 0 ){
					status = MultiProc_E_OSFAILURE;
				}

		   }
		   break;

		   case CMD_MULTIPROC_DESTROY:
		   {
			   	osStatus = devctl( IpcDrv_handle, DCMD_MULTIPROC_DESTROY, cargs, sizeof(MultiProcDrv_CmdArgs), NULL);

				if ( osStatus != 0 ){
					status = MultiProc_E_OSFAILURE;
				}
		   }
		   break;
		   case CMD_MULTIPROC_GETCONFIG:
		   {
  				iov_t		multiproc_getconfig_iov[2];

				MultiProc_Config *	save_multiprocconfig = (MultiProc_Config *)cargs->args.getConfig.config;

  				SETIOV( &multiproc_getconfig_iov[0], cargs, sizeof(MultiProcDrv_CmdArgs) );
  				SETIOV( &multiproc_getconfig_iov[1], cargs->args.getConfig.config, sizeof(MultiProc_Config) );

				/* the osal_drv handle is used instead of ipcdrv_handle as the ipcdrc_handle is not yet initialized */
				osStatus = devctlv( OsalDrv_handle, DCMD_MULTIPROC_GETCONFIG, 2, 2, multiproc_getconfig_iov, multiproc_getconfig_iov, NULL);

				if ( osStatus != 0 ){
					status = MultiProc_E_OSFAILURE;
    			}
    			else{
    				cargs->args.getConfig.config= (MultiProc_Config *) (save_multiprocconfig);
    			}
		   }
		   break;
		   case CMD_MULTIPROC_SETLOCALID:
		   		osStatus = devctl( IpcDrv_handle, DCMD_MULTIPROC_SETLOCALID, cargs, sizeof(MultiProcDrv_CmdArgs), NULL);

				if ( osStatus != 0 ){
					status = MultiProc_E_OSFAILURE;
				}
		   break;
		   default:
		   {
			   /* This does not impact return status of this function, so retVal
				* comment is not used.
				*/
			   status = MultiProc_E_FAIL;
			   GT_setFailureReason (curTrace,
									GT_4CLASS,
									"MultiProcDrv_ioctl",
									status,
									"Unsupported ioctl command specified");
		   }
		   break;

	   }


	if ( osStatus != 0 ){
		status = MultiProc_E_OSFAILURE;
	}
    else {
        /* First field in the structure is the API status. */
        status = ((MultiProcDrv_CmdArgs *) cargs)->apiStatus;
    }

    GT_1trace (curTrace, GT_LEAVE, "MultiProcDrv_ioctl", status);

    /*! @retval MultiProc_S_SUCCESS Operation successfully completed. */
    return status;
}
Beispiel #29
0
/*!
 *  @brief      Wait for an event to be signaled for some specified time.
 *              It is possible to wait infinitely, this calls Blocks and does
 *              not Spin.
 *
 *  @param      allocated event object handle.
 *
 *  @retval     Int as success if succedded otherwise failure
 */
Int OsalEvent_wait (OsalEvent_Handle handle, UInt32 timeout)
{
    Int status = OSALEVENT_SUCCESS ;
    Int32 osStatus = 0u;
    UInt32 lockKey = 0u;

    OsalEvent_Object* event = (OsalEvent_Object*) handle;

    GT_2trace (curTrace, GT_ENTER,"OsalEvent_wait", event, timeout );

    GT_assert (curTrace, (NULL != event) );

    if (OSAL_WAIT_NONE == timeout)
    {
        lockKey = OsalSpinlock_enter (event->lock) ;
        if (event->value == 0u) {
            /*! @retval OSALEVENT_SYNC_FAIL when value is found zero. */
            status = OSALEVENT_E_SYNCFAIL ;
            GT_setFailureReason(curTrace, GT_4CLASS,
                "OsalEvent_wait",OSALEVENT_E_SYNCFAIL,"Wrong combination");
        }
        OsalSpinlock_leave (event->lock, lockKey) ;
    }
    else {
        lockKey = OsalSpinlock_enter (event->lock) ;
        if (!event->value) {
            DECLARE_WAITQUEUE (wait, current) ;
            /* Add the current process to wait queue */
            add_wait_queue_exclusive (&event->list, &wait) ;
            /* Set the current task status as interrutible */
            do {
                set_current_state (TASK_INTERRUPTIBLE) ;
                /* Release the lock */
                OsalSpinlock_leave (event->lock, lockKey) ;
                /* Schedule out for given timeout */
                osStatus = schedule_timeout( \
                    (OSAL_WAIT_FOREVER == timeout)?MAX_SCHEDULE_TIMEOUT:\
                     msecs_to_jiffies (timeout) ) ;
                /* Take the lock again */
                lockKey = OsalSpinlock_enter (event->lock) ;
                /* Check for status */
                if (osStatus == 0) {
                    /*! @retval OSALEVENT_E_TIMEOUT when timeout occurs on
                        wait state */
                    status = OSALEVENT_E_TIMEOUT ;
                    GT_setFailureReason(curTrace, GT_4CLASS,
                        "OsalEvent_wait",OSALEVENT_E_TIMEOUT,
                        "Timeout occured");
                    break ;
                }
                if (osStatus == -ERESTARTSYS) {
                    /*! @retval When we are inerrupted because of the this
                        system call*/
                    status = OSALEVENT_E_RESTARTSYS ;
                    GT_setFailureReason(curTrace, GT_4CLASS,
                        "OsalEvent_wait",OSALEVENT_E_RESTARTSYS,
                        "Interrupted ");
                    break ;
                }
            } while (0) ;
            /* Remove from wait list */
            remove_wait_queue (&event->list, &wait) ;
            /* Set the current task status as running */
            set_current_state (TASK_RUNNING) ;
        }
        /* End the lock */
        OsalSpinlock_leave (event->lock, lockKey) ;
    }

    GT_1trace (curTrace, GT_LEAVE,"OsalEvent_wait",status);

    return status;
}
/*
 *  ======== encode_decode ========
 */
static Void encode_decode(VIDENC_Handle enc, VIDDEC_Handle dec, FILE *in,
    FILE *out)
{
    Int                         n;
    Int32                       status;

    VIDDEC_InArgs               decInArgs;
    VIDDEC_OutArgs              decOutArgs;
    VIDDEC_DynamicParams        decDynParams;
    VIDDEC_Status               decStatus;

    VIDENC_InArgs               encInArgs;
    VIDENC_OutArgs              encOutArgs;
    VIDENC_DynamicParams        encDynParams;
    VIDENC_Status               encStatus;

    XDM_BufDesc                 inBufDesc;
    XDAS_Int8                  *src[XDM_MAX_IO_BUFFERS];
    XDAS_Int32                  inBufSizes[XDM_MAX_IO_BUFFERS];

    XDM_BufDesc                 encodedBufDesc;
    XDAS_Int8                  *encoded[XDM_MAX_IO_BUFFERS];
    XDAS_Int32                  encBufSizes[XDM_MAX_IO_BUFFERS];

    XDM_BufDesc                 outBufDesc;
    XDAS_Int8                  *dst[XDM_MAX_IO_BUFFERS];
    XDAS_Int32                  outBufSizes[XDM_MAX_IO_BUFFERS];

    /* clear and initialize the buffer descriptors */
    memset(src,     0, sizeof(src[0])     * XDM_MAX_IO_BUFFERS);
    memset(encoded, 0, sizeof(encoded[0]) * XDM_MAX_IO_BUFFERS);
    memset(dst,     0, sizeof(dst[0])     * XDM_MAX_IO_BUFFERS);

    src[0]     = inBuf;
    encoded[0] = encodedBuf;
    dst[0]     = outBuf;

    inBufDesc.numBufs = encodedBufDesc.numBufs = outBufDesc.numBufs = 1;
   


    inBufDesc.bufSizes      = inBufSizes;
    encodedBufDesc.bufSizes = encBufSizes;
    outBufDesc.bufSizes     = outBufSizes;

    //Note , this declaration is tell the memtab how much need to  allocate the buf sizes  
    inBufSizes[0] = IFRAMESIZE;
    encBufSizes[0] = EFRAMESIZE;
    outBufSizes[0] = OFRAMESIZE;

    inBufDesc.bufs      = src;
    encodedBufDesc.bufs = encoded;
    outBufDesc.bufs     = dst;

    /* initialize all "sized" fields */
    encInArgs.size    = sizeof(encInArgs);
    decInArgs.size    = sizeof(decInArgs);
    encOutArgs.size   = sizeof(encOutArgs);
    decOutArgs.size   = sizeof(decOutArgs);
    encDynParams.size = sizeof(encDynParams);
    decDynParams.size = sizeof(decDynParams);
    encStatus.size    = sizeof(encStatus);
    decStatus.size    = sizeof(decStatus);

    /*
     * Query the encoder and decoder.
     * This app expects the encoder to provide 1 buf in and get 1 buf out,
     * and the buf sizes of the in and out buffer must be able to handle
     * NSAMPLES bytes of data.
     */
    status = VIDENC_control(enc, XDM_GETSTATUS, &encDynParams, &encStatus);
    if (status != VIDENC_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "encode control status = 0x%x\n", status);
        return;
    }

    /* Validate this encoder codec will meet our buffer requirements */
    if ((inBufDesc.numBufs < encStatus.bufInfo.minNumInBufs) ||
        (IFRAMESIZE < encStatus.bufInfo.minInBufSize[0]) ||
        (encodedBufDesc.numBufs < encStatus.bufInfo.minNumOutBufs) ||
        (EFRAMESIZE < encStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "Error:  encoder codec feature conflict\n");
        return;
    }


//#if 0
    status = VIDDEC_control(dec, XDM_GETSTATUS, &decDynParams, &decStatus);
    if (status != VIDDEC_EOK) {
        /* failure, report error and exit */
        GT_1trace(curMask, GT_7CLASS, "decode control status = 0x%x\n", status);
        return;
    }
//#endif


    /* Validate this decoder codec will meet our buffer requirements */
    if ((encodedBufDesc.numBufs < decStatus.bufInfo.minNumInBufs) ||
        (EFRAMESIZE < decStatus.bufInfo.minInBufSize[0]) ||
        (outBufDesc.numBufs < decStatus.bufInfo.minNumOutBufs) ||
        (OFRAMESIZE < decStatus.bufInfo.minOutBufSize[0])) {

        /* failure, report error and exit */
        GT_0trace(curMask, GT_7CLASS,
            "App-> ERROR: decoder does not meet buffer requirements.\n");
        return;
    }



    /*
     * Read complete frames from in, encode, decode, and write to out.
     */


    /* opencv create init image */
#ifdef USE_OPENCV_DISPLAY
    cvNamedWindow("sobel",CV_WINDOW_AUTOSIZE);
    cvResizeWindow("sobel",320,240);//怕畫面太大讓人看不完,所以顯示視窗設小一點
#endif
    CvSize size=cvSize(320,240);
    frame=cvCreateImage(size,IPL_DEPTH_8U,3);
    frame_gray=cvCreateImage(size,IPL_DEPTH_8U,1);
    frame_Smooth=cvCreateImage(size,IPL_DEPTH_8U,1);
    frame_sobel=cvCreateImage(size,IPL_DEPTH_16S,1);
    frame_sobel_8U=cvCreateImage(size,IPL_DEPTH_8U,1);

    /* v4l2 init */
     int count=0;

     deviceOpen();
     deviceInit();
     /*start capturing*/
     captureStart();


    /*===============v4l2 grab frame by Camera======================*/
    while(1){
        mainLoop(); /*this is the v4l2grab frame*/
        memcpy(inBuf,buffers[0].start,IFRAMESIZE);

#ifdef CACHE_ENABLED
#ifdef xdc_target__isaCompatible_64P
        /*
         *  fread() on this processor is implemented using CCS's stdio, which
         *  is known to write into the cache, not physical memory.  To meet
         *  xDAIS DMA Rule 7, we must writeback the cache into physical
         *  memory.  Also, per DMA Rule 7, we must invalidate the buffer's
         *  cache before providing it to any xDAIS algorithm.
         */
        Memory_cacheWbInv(inBuf, IFRAMESIZE);
#else
#error Unvalidated config - add appropriate fread-related cache maintenance
#endif
        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(encodedBuf, EFRAMESIZE);
#endif

        GT_1trace(curMask, GT_1CLASS, "App-> Processing frame %d...\n", count);

        /* encode the frame */
        status = VIDENC_process(enc, &inBufDesc, &encodedBufDesc, &encInArgs,
            &encOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Encoder frame %d process returned - 0x%x)\n",
            count, status);

#ifdef CACHE_ENABLED
        /* Writeback this outBuf from the previous call.  Also, as encodedBuf
         * is an inBuf to the next process call, we must invalidate it also, to
         * clean buffer lines.
         */
        Memory_cacheWbInv(encodedBuf, EFRAMESIZE);

        /* Per DMA Rule 7, our output buffer cache lines must be cleaned */
        Memory_cacheInv(outBuf, OFRAMESIZE);
#endif

        if (status != VIDENC_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Encoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", count, status, encOutArgs.extendedError);
            break;
        }


/***************************decode part (Unuse)***********************************/
/************************** decode the frame**************************************/
        status = VIDDEC_process(dec, &encodedBufDesc, &outBufDesc, &decInArgs,
           &decOutArgs);

        GT_2trace(curMask, GT_2CLASS,
            "App-> Decoder frame %d process returned - 0x%x)\n",
            n, status);

        if (status != VIDDEC_EOK) {
            GT_3trace(curMask, GT_7CLASS,
                "App-> Decoder frame %d processing FAILED, status = 0x%x, "
                "extendedError = 0x%x\n", n, status, decOutArgs.extendedError);
            break;
        }


#ifdef CACHE_ENABLED
        /* Writeback the outBuf. */
        Memory_cacheWb(outBuf, OFRAMESIZE);
#endif

        /* write to file */
        //fwrite(encodedBuf, EFRAMESIZE, 1, out);

        frame->imageData =  encoded[0];
        frame_gray->imageData = dst[0];
        //cvCvtColor(frame,frame_gray,CV_BGR2GRAY);

#ifdef USE_OPENCV_DISPLAY
        cvShowImage("sobel",frame_gray);
        int key=cvWaitKey(33);
#endif 
        //cvSaveImage("22.bmp",frame_gray,0);
        printf("the %d frame are completed \n",count);
        count++;

    }/*end while*/

#ifdef USE_OPENCV_DISPLAY
    cvDestroyWindow("sobel"); 
#endif 
    cvReleaseImage(&frame);
    cvReleaseImage(&frame_gray);
    cvReleaseImage(&frame_Smooth);
    cvReleaseImage(&frame_sobel);
    cvReleaseImage(&frame_sobel_8U);

    GT_1trace(curMask, GT_1CLASS, "%d frames encoded/decoded\n", n);
}