/*! ****************************************************************************** @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 SYSDEVU_Initialise ******************************************************************************/ IMG_RESULT SYSDEVU_Initialise(IMG_VOID) { /* If not initialised...*/ if (!gSysDevInitialised) { IMG_RESULT eResult; eResult = SYSOSKM_CreateAtomic(&gsActiveOpenCnt); IMG_ASSERT(eResult == IMG_SUCCESS); if (eResult != IMG_SUCCESS) { return eResult; } LST_init(&gsDevList); eResult = SYSOSKM_CreateMutex(&hNextDeviceIdMutex); IMG_ASSERT(eResult == IMG_SUCCESS); if (eResult != IMG_SUCCESS) { return eResult; } /* use a magic number to help detect dereferences of DeviceId when (wrongly) casted as a pointer */ gui32NextDeviceId = 0xbeef00; /* Now we are initialised...*/ gSysDevInitialised = IMG_TRUE; } return IMG_SUCCESS; }
/*! ****************************************************************************** @Function RMAN_Initialise ******************************************************************************/ IMG_RESULT RMAN_Initialise(IMG_VOID) { IMG_UINT32 ui32Result; /* If not initialised...*/ if (!gInitialised) { /* Initialise the active buckets list...*/ IMG_MEMSET(&gapsBucket[0], 0, sizeof(gapsBucket)); /* Create mutex...*/ ui32Result = SYSOSKM_CreateMutex(&ghSharedResMutexHandle); IMG_ASSERT(ui32Result == IMG_SUCCESS); if (ui32Result != IMG_SUCCESS) { return ui32Result; } /* Set initialised flag...*/ gInitialised = IMG_TRUE; /* Create the global resource bucket...*/ ui32Result = RMAN_CreateBucket((IMG_HANDLE *)&gpsGlobalResBucket); IMG_ASSERT(ui32Result == IMG_SUCCESS); if (ui32Result != IMG_SUCCESS) { return ui32Result; } /* Create the shared resource bucket...*/ ui32Result = RMAN_CreateBucket((IMG_HANDLE *)&gpsSharedResBucket); IMG_ASSERT(ui32Result == IMG_SUCCESS); if (ui32Result != IMG_SUCCESS) { return ui32Result; } SYSOSKM_CreateMutex(&globalMutext); } /* Return success...*/ return IMG_SUCCESS; }
/*! ****************************************************************************** @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; }