예제 #1
0
/*!
******************************************************************************

 @Function				RMAN_Deinitialise

******************************************************************************/
IMG_VOID RMAN_Deinitialise(IMG_VOID)
{
    IMG_UINT32				i;

    /* Make sure no other cpu is using the shared resources.  */
    SYSOSKM_DisableInt();

    /* If initialised...*/
    if (gInitialised)
    {
        /* Destroy the golbal resource bucket...*/
        RMAN_DestroyBucket(gpsGlobalResBucket);

        /* Destroy the shared resource bucket...*/
        RMAN_DestroyBucket(gpsSharedResBucket);

        /* Make sure we destroy the mutex after destroying the bucket. */
        SYSOSKM_DestroyMutex(globalMutext);

        /* Destroy mutex...*/
        SYSOSKM_DestroyMutex(ghSharedResMutexHandle);

        /* Check all buckets destroyed...*/
        for (i=0; i<RMAN_CRESID_MAX_BUCKET_INDEX; i++)
        {
            IMG_ASSERT(gapsBucket[i] == IMG_NULL);
        }

        /* Reset initialised flag...*/
        gInitialised = IMG_FALSE;
    }

    SYSOSKM_EnableInt();
}
예제 #2
0
/*!
******************************************************************************

 @Function                POOL_PoolCreate

******************************************************************************/
IMG_RESULT POOL_PoolCreate(
    IMG_HANDLE *  phPoolHandle
)
{
    POOL_sResPool *  psResPool;
    IMG_UINT32       ui32Result;

    IMG_ASSERT(gInitialised);

    /* Allocate a pool structure...*/
    psResPool = IMG_MALLOC(sizeof(*psResPool));
    IMG_ASSERT(psResPool != IMG_NULL);
    if (psResPool == IMG_NULL)
    {
        return IMG_ERROR_OUT_OF_MEMORY;
    }
    IMG_MEMSET(psResPool, 0, sizeof(*psResPool));

    /* Initialise the pool info...*/
    LST_init(&psResPool->sFreeResList);
    LST_init(&psResPool->sActResList);

    /* Create mutex...*/
    ui32Result = SYSOSKM_CreateMutex(&psResPool->hMutexHandle);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_create_mutex;
    }

    /* Create context for the Id generator...*/
    ui32Result = IDGEN_CreateContext(POOL_IDGEN_MAX_ID, POOL_IDGEN_BLOCK_SIZE,IMG_FALSE, &psResPool->hIdGenHandle);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_create_context;
    }

    /* Disable interrupts.  */
    SYSOSKM_DisableInt();

    /* Add to list of pools...*/
    LST_add(&gsPoolList, psResPool);

    /* Enable interrupts.  */
    SYSOSKM_EnableInt();

    /* Return handle to pool...*/
    *phPoolHandle = psResPool;

    return IMG_SUCCESS;

    /* Error handling. */
error_create_context:
    SYSOSKM_DestroyMutex(psResPool->hMutexHandle);
error_create_mutex:
    IMG_FREE(psResPool);

    return ui32Result;
}
/*!
******************************************************************************

 @Function      perflog_DeinitialiseFile

 @Description

 Deinitialises file.

 @Input    pFileHandler : file to be deinitialised

 @Return    IMG_SUCCESS in case when file has been deinitialised successfully,
            error code otherwise

******************************************************************************/
static IMG_VOID perflog_DeinitialiseFile(
    perflog_FileHandler *pFileHandler
)
{
    if(pFileHandler == IMG_NULL)
    {
        REPORT(REPORT_MODULE_PERFLOG, REPORT_ERR,
                "Performance logger cannot deinitialise file: invalid parameters");
        return;
    }

    SYSOSKM_LockMutex(pFileHandler->hMutexHandle);

    //removes file from debug filesystem...
    debugfs_remove(pFileHandler->psFile);

    //removes all internal structures
    perflog_CleanFile(pFileHandler);

    SYSOSKM_UnlockMutex(pFileHandler->hMutexHandle);

    //and file mutex
    SYSOSKM_DestroyMutex(pFileHandler->hMutexHandle);

}
예제 #4
0
/*!
******************************************************************************

 @Function				SYSDEVU_Deinitialise

******************************************************************************/
IMG_VOID SYSDEVU_Deinitialise(IMG_VOID)
{
	if (gSysDevInitialised)
	{
		SYSOSKM_DestroyMutex(hNextDeviceIdMutex);
		gSysDevInitialised = IMG_FALSE;
	}
}
/*!
 ******************************************************************************

 @Function				DMANKM_UnRegisterDevice

 ******************************************************************************/
IMG_RESULT DMANKM_UnRegisterDevice(IMG_CHAR * pszDeviceName) 
{
	DMANKM_sDevContext *devContext;
	DMANKM_sConnContext *devConnection;
	IMG_RESULT ui32Result;

	devContext = (DMANKM_sDevContext *) LST_first(&gsDevList);
	while (devContext != IMG_NULL ) {
		if (!strcmp(devContext->pszDeviceName, pszDeviceName)) {
			devConnection = (DMANKM_sConnContext *) LST_first(
					&devContext->sConnList);
			while (devConnection != IMG_NULL ) {
				/* If this is the init connection....*/
				if (devConnection->bInitConn) {
					devConnection = (DMANKM_sConnContext *) LST_next(
							&devContext->sConnList);
				} else {
					/* Lock the device...*/
					DMANKM_LockDeviceContext(devContext);

					/* Call on to the kernel function...*/
					ui32Result = DMANKM_CloseDevice(devContext, devConnection,
							DMAN_DCONN_ABORT);
					IMG_ASSERT(ui32Result == IMG_SUCCESS);

					// NOTE: We do not unlock the device as this will be done by
					//	     DMANKM_DevDisconnectComplete().
					//					/* Unlock the device...*/
					//					DMANKM_UnlockDeviceContext(hDevHandle);

					/* Move to next connection...*/
					devConnection = (DMANKM_sConnContext *) LST_first(
							&devContext->sConnList);
				}
			}

			SYSOSKM_DestroyMutex(devContext->hMutexHandle);

			/* Remove entries in debug file system */
#ifdef IMG_KERNEL_MODULE
			//if (devContext->psDgRoot) {
			//	debugfs_remove_recursive(devContext->psDgRoot);
			//}
#endif
			LST_remove(&gsDevList, devContext);

			IMG_FREE(devContext->pszDeviceName);
			IMG_FREE(devContext);

			return IMG_SUCCESS;
		}
		devContext = LST_next(devContext);
	}
	return IMG_ERROR_GENERIC_FAILURE;
}
/*!
******************************************************************************

 @Function				SYSDEVU_Deinitialise

******************************************************************************/
IMG_VOID SYSDEVU_Deinitialise(IMG_VOID)
{
	if (gSysDevInitialised)
	{
		SYSOSKM_DestroyMutex(hNextDeviceIdMutex);

		IMG_ASSERT(SYSOSKM_ReadAtomic(gsActiveOpenCnt) == 0);
		SYSOSKM_DestroyAtomic(gsActiveOpenCnt);

		gSysDevInitialised = IMG_FALSE;
	}
}
/*!
******************************************************************************

 @Function      perflog_InitialiseFile

 @Description

 Initialises new file in performance logger directory.

 @Output    pFileHandler : file to be initialised

 @Input     pszFileName : name of created file

 @Input     psPerfLogDir : directory where new file will be stored

 @Return    IMG_SUCCESS in case when file has been initialised successfully,
            error code otherwise

******************************************************************************/
static IMG_RESULT perflog_InitialiseFile(
    perflog_FileHandler *pFileHandler,
    const IMG_CHAR *pszFileName,
    struct dentry *psPerfLogDir
)
{
    if(pFileHandler == NULL || pszFileName == NULL || psPerfLogDir == NULL)
    {
        REPORT(REPORT_MODULE_PERFLOG, REPORT_ERR,
                "Performance logger cannot create buffer: invalid parameters");
        return IMG_ERROR_INVALID_PARAMETERS;
    }

    //creates mutex that sync access to list of buffers
    if( SYSOSKM_CreateMutex(&pFileHandler->hMutexHandle) != IMG_SUCCESS)
    {
        REPORT(REPORT_MODULE_PERFLOG, REPORT_ERR,
               "Performance logger cannot create internal mutex");
        return IMG_ERROR_FATAL;
    }

    //initialises list of buffers
    LST_init(&pFileHandler->sBufferList);

    //creates new file in debug file system
    pFileHandler->psFile = debugfs_create_file(pszFileName, 0644, psPerfLogDir, NULL, &perflog_FileOps);
    IMG_ASSERT(pFileHandler->psFile != IMG_NULL);
    if(pFileHandler->psFile == IMG_NULL)
    {
        SYSOSKM_DestroyMutex(pFileHandler->hMutexHandle);
        REPORT(REPORT_MODULE_PERFLOG, REPORT_ERR,
               "Performance logger cannot create file in debug file system");
        return IMG_ERROR_FATAL;
    }

    return IMG_SUCCESS;
}
/*!
 ******************************************************************************

 @Function				DMANKM_RegisterDevice

 ******************************************************************************/
IMG_RESULT DMANKM_RegisterDevice(IMG_CHAR * pszDeviceName,
		DMANKM_pfnDevRegister pfnDevRegister) 
{
	DMANKM_sDevContext * psDevContext;
	IMG_UINT32 ui32Result;

	/* If the device context list is not initialised...*/
	if (!gbDevListInitialised) {
		/* Initialise the device context list...*/
		LST_init(&gsDevList);

		gbDevListInitialised = IMG_TRUE;
	}

	/* Locate the device - ensure it's not registered twice...*/
	ui32Result = DMANKM_LocateDevice(pszDeviceName,
			(IMG_HANDLE *) &psDevContext);
	if (ui32Result != IMG_ERROR_DEVICE_NOT_FOUND) {
        IMG_ASSERT(ui32Result == IMG_ERROR_DEVICE_NOT_FOUND);
		return IMG_ERROR_GENERIC_FAILURE;
	}

	/* Allocate a device context structure...*/
	psDevContext = IMG_MALLOC(sizeof(*psDevContext));
	if (psDevContext == IMG_NULL ) 
    {
        IMG_ASSERT(psDevContext != IMG_NULL);
		return IMG_ERROR_OUT_OF_MEMORY;
	}

	IMG_MEMSET(psDevContext, 0, sizeof(*psDevContext));

	/* Setup the device context...*/
	psDevContext->ui32DeviceId = gui32NextDeviceID;
	gui32NextDeviceID++;
	psDevContext->pszDeviceName = IMG_STRDUP(pszDeviceName);
	if (psDevContext->pszDeviceName == IMG_NULL ) 
    {
        IMG_ASSERT(psDevContext->pszDeviceName != IMG_NULL);
		ui32Result = IMG_ERROR_OUT_OF_MEMORY;
		goto error_dev_name;
	}
	psDevContext->pfnDevRegister = pfnDevRegister;
	psDevContext->ui8ApmPpmFlags = 0;
	ui32Result = SYSOSKM_CreateMutex(&psDevContext->hMutexHandle);
	IMG_ASSERT(ui32Result == IMG_SUCCESS);
	if (ui32Result != IMG_SUCCESS) {
		goto error_create_mutex;
	}
	LST_init(&psDevContext->sConnList);

	/* Disable interrupts...*/
	SYSOSKM_DisableInt();

	/* Add device to list...*/
	LST_add(&gsDevList, psDevContext);

	/* Re-enable interrupts...*/
	SYSOSKM_EnableInt();

	/* If initialised...*/
	if (gDmanKmInitialised) {
		/* Call device registration function...*/
		ui32Result = psDevContext->pfnDevRegister(&psDevContext->sDevRegister);
		IMG_ASSERT(ui32Result == IMG_SUCCESS);
		if (ui32Result != IMG_SUCCESS) {
			goto error_dev_register;
		}

		/* Set default if required...*/
		if (psDevContext->sDevRegister.ui32ConnFlags == 0) {
			psDevContext->sDevRegister.ui32ConnFlags = DMAN_CFLAG_EXCLUSIVE;
		}
	}

	/* Return success...*/
	return IMG_SUCCESS;

	/* Error handling. */
	error_dev_register: SYSOSKM_DisableInt();
	LST_remove(&gsDevList, psDevContext);
	SYSOSKM_EnableInt();
	SYSOSKM_DestroyMutex(psDevContext->hMutexHandle);
	error_create_mutex:
	IMG_FREE(psDevContext->pszDeviceName);
	error_dev_name:
	IMG_FREE(psDevContext);

	return ui32Result;
}
예제 #9
0
/*!
******************************************************************************

 @Function                POOL_PoolDestroy

******************************************************************************/
IMG_RESULT POOL_PoolDestroy(
    IMG_HANDLE  hPoolHandle
)
{
    POOL_sResPool *   psResPool = hPoolHandle;
    POOL_sResource *  psResource;
    POOL_sResource *  psCloneResource;
    IMG_UINT32        ui32Result;

    IMG_ASSERT(gInitialised);
    IMG_ASSERT(psResPool != IMG_NULL);

    if (!gInitialised ||
        psResPool == IMG_NULL)
    {
        ui32Result = IMG_ERROR_INVALID_PARAMETERS;
        goto error_nolock;
    }

    /* Lock the pool...*/
    SYSOSKM_LockMutex(psResPool->hMutexHandle);

    /* Disable interrupts.  */
    SYSOSKM_DisableInt();

    /* Remove the pool from the active list...*/
    LST_remove(&gsPoolList, psResPool);

    /* Enable interrupts.  */
    SYSOSKM_EnableInt();

    /* Destroy any resources in the free list...*/
    psResource = (POOL_sResource *)LST_removeHead(&psResPool->sFreeResList);
    while (psResource != IMG_NULL)
    {
        psResource->pfnDestructor(psResource->pvParam);
        IMG_FREE(psResource);

        psResource = (POOL_sResource *)LST_removeHead(&psResPool->sFreeResList);
    }

    /* Destroy any resources in the active list...*/
    psResource = (POOL_sResource *)LST_removeHead(&psResPool->sActResList);
    while (psResource != IMG_NULL)
    {
        psCloneResource = (POOL_sResource *)LST_removeHead(&psResource->sCloneResList);
        while (psCloneResource != IMG_NULL)
        {
            /* If we created a copy of the resources pvParam then free it...*/
            if (psCloneResource->pvParam != IMG_NULL)
            {
                IMG_FREE(psCloneResource->pvParam );
            }
            IMG_FREE(psCloneResource);
            psCloneResource = (POOL_sResource *)LST_removeHead(&psResource->sCloneResList);
        }

        /* Call the resource destructor...*/
        psResource->pfnDestructor(psResource->pvParam);
        IMG_FREE(psResource);

        psResource = (POOL_sResource *)LST_removeHead(&psResPool->sActResList);
    }

    /* Destroy the context for the Id generator...*/
    if (psResPool->hIdGenHandle != IMG_NULL)
    {
        ui32Result = IDGEN_DestroyContext(psResPool->hIdGenHandle);
        IMG_ASSERT(ui32Result == IMG_SUCCESS);
    }

    /* Unlock the pool...*/
    SYSOSKM_UnlockMutex(psResPool->hMutexHandle);

    /* Destroy mutex...*/
    SYSOSKM_DestroyMutex(psResPool->hMutexHandle);

    /* Free the pool structure */
    IMG_FREE(psResPool);
    
	return IMG_SUCCESS;

error_nolock:
    return ui32Result;
}