/* * ======== RMAN_exit ======== * Exit the generic IRES RMAN and free the memory back to the Memory manager * using which it was created. */ IRES_Status RMAN_exit() { IArg key; Int i; IRES_Status status = IRES_OK; if (rmanInit == 0) { return (IRES_ENOINIT); } Log_print0(Diags_ENTRY, "[+E] RMAN_exit> Enter "); rmanInternalState->info.refCount--; if (--rmanInit == 0) { if (initStatus != IRES_OK) { Log_print0(Diags_USER7, "[+7] RMAN_exit> RMAN_init call didn't " "happen successfully. RMAN_exit will not unregister " "any resources."); status = IRES_ENOINIT; } else { key = IGateProvider_enter(gate); Log_print1(Diags_EXIT, "[+X] RMAN_exit> tableIndex = %d", (IArg)(resTable.tableIndex)); /* Unregister the entries */ Log_print0(Diags_EXIT, "[+X] RMAN_exit> Unregistering resources"); for (i = 0; i < resTable.tableIndex; i++) { if (RMAN_TABLE[i] != NULL) { /* Even if there is an error, unregister the rest */ if ((status = RMAN_TABLE[i]->exit()) != IRES_OK) { Log_print2(Diags_USER7, "[+7] RMAN_exit> Error " "unregistering the IRESMAN implementation " "0x%x, status = %d", (IArg)(RMAN_TABLE[i]), (IArg)status); status = IRES_EFAIL; } } } /* Free the RMAN object */ freeInternalState(); initStatus = IRES_ENOINIT; /* Free the gate after leaving it */ IGateProvider_leave(gate, key); OsalSupport_deleteGate(gate); gate = NULL; } } Log_print1(Diags_EXIT, "[+X] RMAN_exit> Exit (status=%d)", (IArg)status); return (status); }
/* * ======== MessageQ_Instance_finalize ======== */ Void ti_sdo_ipc_MessageQ_Instance_finalize( ti_sdo_ipc_MessageQ_Object* obj, Int status) { UInt key; MessageQ_QueueIndex index = (MessageQ_QueueIndex)(obj->queue); List_Handle listHandle; if (obj->syncSemHandle != NULL) { SyncSem_delete(&obj->syncSemHandle); } listHandle = ti_sdo_ipc_MessageQ_Instance_State_normalList(obj); /* Destruct the list */ List_destruct(List_struct(listHandle)); listHandle = ti_sdo_ipc_MessageQ_Instance_State_highList(obj); /* Destruct the list */ List_destruct(List_struct(listHandle)); /* lock */ key = IGateProvider_enter(MessageQ_module->gate); /* Null out entry in the array. */ MessageQ_module->queues[index] = NULL; /* unlock scheduler */ IGateProvider_leave(MessageQ_module->gate, key); if (obj->nsKey != NULL) { NameServer_removeEntry((NameServer_Handle)MessageQ_module->nameServer, obj->nsKey); } }
/* * ======== getResman ======== * Searches through valid entries of RMAN_TABLE to find a RESMAN corresponding * to the name and revision of the protocol. */ static IRESMAN_Fxns * getResman(String name, IRES_ProtocolRevision * rev) { IRESMAN_Fxns *fxns = NULL; Int j; IArg key; key = IGateProvider_enter(gate); /* * For each non-NULL RMAN_TABLE entry, compare protocolName and version * number. */ for (j = 0; j < resTable.tableIndex; j++) { if ((RMAN_TABLE[j]) && !strcmp(name, RMAN_TABLE[j]->getProtocolName()) && checkResMgrAlgRevision(RMAN_TABLE[j]->getProtocolRevision(), rev)) { /* Found a match */ fxns = RMAN_TABLE[j]; break; } } IGateProvider_leave(gate, key); return (fxns); }
/* * ======== GateHWSem_enter ======== */ IArg GateHWSem_enter(GateHWSem_Object *obj) { IArg key; volatile UInt32 *baseAddr = (volatile UInt32 *)GateHWSem_baseAddr; key = IGateProvider_enter(obj->localGate); /* If the gate object has already been entered, return the nested value */ obj->nested++; if (obj->nested > 1) { return (key); } /* Enter the hardware lock */ while (baseAddr[obj->semNum] != 1) { obj->nested--; /* Restore state of delegate object */ IGateProvider_leave(obj->localGate, key); key = IGateProvider_enter(obj->localGate); obj->nested++; /* Re-nest the gate */ } return (key); }
/* * ======== GateAAMonitor_enter ======== */ IArg GateAAMonitor_enter(GateAAMonitor_Object *obj) { IArg key; key = IGateProvider_enter(obj->localGate); /* If the gate object has already been entered, return the nested value */ obj->nested++; if (obj->nested > 1) { return (key); } /* Enter the monitor */ GateAAMonitor_getLock((Ptr)obj->sharedAddr); return (key); }
/* * ======== GatePetersonN_enter ======== */ IArg GatePetersonN_enter(GatePetersonN_Object *obj) { IArg key; SizeT numProcessors; SizeT myProcId; Int32 curStage; SizeT proc; /* Enter local gate */ key = IGateProvider_enter(obj->localGate); /* If the gate object has already been entered, return the key */ obj->nested++; if (obj->nested > 1) { return (key); } numProcessors = obj->numProcessors; myProcId = obj->selfId; for (curStage=0; curStage < (numProcessors - 1); curStage++) { *(obj->enteredStage[myProcId]) = curStage; *(obj->lastProcEnteringStage[curStage]) = myProcId; if (obj->cacheEnabled) { Cache_wbInv((Ptr)obj->enteredStage[myProcId], obj->cacheLineSize, Cache_Type_ALL, FALSE); Cache_wbInv((Ptr)obj->lastProcEnteringStage[curStage], obj->cacheLineSize, Cache_Type_ALL, TRUE); } for (proc=0; proc < numProcessors; proc++) { if (proc != myProcId) { if (obj->cacheEnabled) { Cache_inv((Ptr)obj->enteredStage[proc], obj->cacheLineSize, Cache_Type_ALL, FALSE); Cache_inv((Ptr)obj->lastProcEnteringStage[curStage], obj->cacheLineSize, Cache_Type_ALL, TRUE); } while ((*(obj->enteredStage[proc]) >= curStage) && (*(obj->lastProcEnteringStage[curStage]) == myProcId)) { /* wait till 'proc' leaves or another 'proc' enters stage */ if (obj->cacheEnabled) { Cache_inv((Ptr)obj->enteredStage[proc], obj->cacheLineSize, Cache_Type_ALL, FALSE); Cache_inv((Ptr)obj->lastProcEnteringStage[curStage], obj->cacheLineSize, Cache_Type_ALL, TRUE); } } } } } /* stages */ return (key); }
/* * ======== MessageQ_Instance_init ======== */ Int ti_sdo_ipc_MessageQ_Instance_init(ti_sdo_ipc_MessageQ_Object *obj, String name, const ti_sdo_ipc_MessageQ_Params *params, Error_Block *eb) { Int i; UInt16 start; UInt16 count; UInt key; Bool found = FALSE; List_Handle listHandle; SyncSem_Handle syncSemHandle; MessageQ_QueueIndex queueIndex; /* lock */ key = IGateProvider_enter(MessageQ_module->gate); start = ti_sdo_ipc_MessageQ_Object_count(); count = MessageQ_module->numQueues; /* Search the dynamic array for any holes */ for (i = start; (i < count) && (found == FALSE); i++) { if (MessageQ_module->queues[i] == NULL) { MessageQ_module->queues[i] = obj; queueIndex = i; found = TRUE; } } /* * If no free slot was found: * - if no growth allowed, raise and error * - if growth is allowed, grow the array */ if (found == FALSE) { if (ti_sdo_ipc_MessageQ_maxRuntimeEntries != NameServer_ALLOWGROWTH) { /* unlock scheduler */ IGateProvider_leave(MessageQ_module->gate, key); Error_raise(eb, ti_sdo_ipc_MessageQ_E_maxReached, ti_sdo_ipc_MessageQ_maxRuntimeEntries, 0); return (1); } else { queueIndex = MessageQ_grow(obj, eb); if (queueIndex == MessageQ_INVALIDMESSAGEQ) { /* unlock scheduler */ IGateProvider_leave(MessageQ_module->gate, key); return (2); } } } /* create default sync if not specified */ if (params->synchronizer == NULL) { /* Create a SyncSem as the synchronizer */ syncSemHandle = SyncSem_create(NULL, eb); if (syncSemHandle == NULL) { /* unlock scheduler */ IGateProvider_leave(MessageQ_module->gate, key); return (3); } /* store handle for use in finalize ... */ obj->syncSemHandle = syncSemHandle; obj->synchronizer = SyncSem_Handle_upCast(syncSemHandle); } else { obj->syncSemHandle = NULL; obj->synchronizer = params->synchronizer; } /* unlock scheduler */ IGateProvider_leave(MessageQ_module->gate, key); /* Fill in the message queue object */ listHandle = ti_sdo_ipc_MessageQ_Instance_State_normalList(obj); List_construct(List_struct(listHandle), NULL); listHandle = ti_sdo_ipc_MessageQ_Instance_State_highList(obj); List_construct(List_struct(listHandle), NULL); obj->queue = ((MessageQ_QueueId)(MultiProc_self()) << 16) | queueIndex; obj->unblocked = FALSE; /* Add into NameServer */ if (name != NULL) { obj->nsKey = NameServer_addUInt32( (NameServer_Handle)MessageQ_module->nameServer, name, obj->queue); if (obj->nsKey == NULL) { Error_raise(eb, ti_sdo_ipc_MessageQ_E_nameFailed, name, 0); return (4); } } return (0); }
/*! * @brief Function to delete an instance of this PwrMgr. * * The user provided pointer to the handle is reset after * successful completion of this function. * * @param handlePtr Pointer to Handle to the PwrMgr instance * * @sa DM8168DUCATIPWR_create */ Int DM8168DUCATIPWR_delete (DM8168DUCATIPWR_Handle * handlePtr) { Int status = PWRMGR_SUCCESS; DM8168DUCATIPWR_Object * object = NULL; PwrMgr_Object * handle; IArg key; GT_1trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_delete", handlePtr); GT_assert (curTrace, (handlePtr != NULL)); GT_assert (curTrace, ((handlePtr != NULL) && (*handlePtr != NULL))); GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0)); #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) if (DM8168DUCATIPWR_state.refCount == 0) { GT_setFailureReason (curTrace, GT_4CLASS, "DM8168DUCATIPWR_delete", DM8168DUCATIPWR_E_INVALIDSTATE, "Module was not initialized!"); } else if (handlePtr == NULL) { /*! @retval PWRMGR_E_INVALIDARG Invalid NULL handlePtr specified*/ status = PWRMGR_E_INVALIDARG; GT_setFailureReason (curTrace, GT_4CLASS, "DM8168DUCATIPWR_delete", status, "Invalid NULL handlePtr specified"); } else if (*handlePtr == NULL) { /*! @retval PWRMGR_E_HANDLE Invalid NULL *handlePtr specified */ status = PWRMGR_E_HANDLE; GT_setFailureReason (curTrace, GT_4CLASS, "DM8168DUCATIPWR_delete", status, "Invalid NULL *handlePtr specified"); } else { #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */ handle = (PwrMgr_Object *) (*handlePtr); /* Enter critical section protection. */ key = IGateProvider_enter (DM8168DUCATIPWR_state.gateHandle); /* Reset handle in PwrMgr handle array. */ GT_assert (curTrace, IS_VALID_PROCID (handle->procId)); DM8168DUCATIPWR_state.pwrHandles [handle->procId] = NULL; object = (DM8168DUCATIPWR_Object *) handle->object; /* Free memory used for the DM8168DUCATIPWR object. */ if (handle->object != NULL) { /* Free memory used for the clock handle */ #if defined (SYSLINK_BUILDOS_LINUX) LinuxClock_delete(((DM8168DUCATIPWR_Object *)handle->object)->clockHandle); #endif /* #if defined (SYSLINK_BUILDOS_LINUX) */ #if defined (SYSLINK_BUILD_RTOS) DM8168CLOCK_delete(((DM8168DUCATIPWR_Object *)handle->object)->clockHandle); #endif /* #if defined (SYSLINK_BUILD_RTOS) */ Memory_free (NULL, object, sizeof (DM8168DUCATIPWR_Object)); handle->object = NULL; } /* Free memory used for the PwrMgr object. */ Memory_free (NULL, handle, sizeof (PwrMgr_Object)); *handlePtr = NULL; /* Leave critical section protection. */ IGateProvider_leave (DM8168DUCATIPWR_state.gateHandle, key); #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) } #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */ GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_delete", status); /*! @retval PWRMGR_SUCCESS Operation successful */ return (status); }
/*! * @brief Function to create an instance of this PwrMgr. * * @param procId Processor ID addressed by this PwrMgr instance. * @param params Configuration parameters. * * @sa DM8168DUCATIPWR_delete */ DM8168DUCATIPWR_Handle DM8168DUCATIPWR_create ( UInt16 procId, const DM8168DUCATIPWR_Params * params) { Int status = PWRMGR_SUCCESS; PwrMgr_Object * handle = NULL; IArg key; GT_2trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_create", procId, params); GT_assert (curTrace, IS_VALID_PROCID (procId)); GT_assert (curTrace, (params != NULL)); GT_assert (curTrace, (DM8168DUCATIPWR_state.refCount != 0)); #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) if (DM8168DUCATIPWR_state.refCount == 0) { GT_setFailureReason (curTrace, GT_4CLASS, "DM8168DUCATIPWR_create", DM8168DUCATIPWR_E_INVALIDSTATE, "Module was not initialized!"); } else if (!IS_VALID_PROCID (procId)) { /* Not setting status here since this function does not return status.*/ GT_setFailureReason (curTrace, GT_4CLASS, "DM8168DUCATIPWR_create", PWRMGR_E_INVALIDARG, "Invalid procId specified"); } else if (params == NULL) { GT_setFailureReason (curTrace, GT_4CLASS, "DM8168DUCATIPWR_create", PWRMGR_E_INVALIDARG, "params passed is null!"); } else { #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */ /* Enter critical section protection. */ key = IGateProvider_enter (DM8168DUCATIPWR_state.gateHandle); #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) /* Check if the PwrMgr already exists for specified procId. */ if (DM8168DUCATIPWR_state.pwrHandles [procId] != NULL) { status = PWRMGR_E_ALREADYEXIST; GT_setFailureReason (curTrace, GT_4CLASS, "DM8168DUCATIPWR_create", status, "PwrMgr already exists for specified procId!"); } else { #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */ /* Allocate memory for the handle */ handle = (PwrMgr_Object *) Memory_calloc (NULL, sizeof (PwrMgr_Object), 0, NULL); if (handle == NULL) { GT_setFailureReason (curTrace, GT_4CLASS, "DM8168DUCATIPWR_create", PWRMGR_E_MEMORY, "Memory allocation failed for handle!"); } else { /* Populate the handle fields */ handle->pwrFxnTable.attach = &DM8168DUCATIPWR_attach; handle->pwrFxnTable.detach = &DM8168DUCATIPWR_detach; handle->pwrFxnTable.on = &DM8168DUCATIPWR_on; handle->pwrFxnTable.off = &DM8168DUCATIPWR_off; /* TBD: Other functions */ /* Allocate memory for the DM8168DUCATIPWR handle */ handle->object = Memory_calloc (NULL, sizeof (DM8168DUCATIPWR_Object), 0, NULL); if (handle == NULL) { status = PWRMGR_E_MEMORY; GT_setFailureReason (curTrace, GT_4CLASS, "DM8168DUCATIPWR_create", status, "Memory allocation failed for handle!"); } else { #if defined (SYSLINK_BUILDOS_LINUX) ((DM8168DUCATIPWR_Object *)handle->object)->clockHandle = (ClockOps_Handle) LinuxClock_create(); #endif/* #if defined (SYSLINK_BUILDOS_LINUX) */ #if defined (SYSLINK_BUILD_RTOS) ((DM8168DUCATIPWR_Object *)handle->object)->clockHandle = (ClockOps_Handle) DM8168CLOCK_create(); #endif/* #if defined (SYSLINK_BUILD_RTOS) */ handle->procId = procId; DM8168DUCATIPWR_state.pwrHandles [procId] = (DM8168DUCATIPWR_Handle) handle; } } #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) } #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */ /* Leave critical section protection. */ IGateProvider_leave (DM8168DUCATIPWR_state.gateHandle, key); #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) } #endif /* #if !defined(SYSLINK_BUILD_OPTIMIZE) && defined (SYSLINK_BUILD_HLOS) */ if (status < 0) { if (handle != NULL) { if (handle->object != NULL) { Memory_free (NULL, handle->object, sizeof (DM8168DUCATIPWR_Object)); } Memory_free (NULL, handle, sizeof (PwrMgr_Object)); } /*! @retval NULL Function failed */ handle = NULL; } GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_create", handle); /*! @retval Valid-Handle Operation successful */ return (DM8168DUCATIPWR_Handle) handle; }
/* * ======== RMAN_register ======== * Register the protocol/protocol revision and the device specific resource * manager implementation with the Resource Registry of the RMAN */ IRES_Status RMAN_register(IRESMAN_Fxns * resmanFxns, IRESMAN_Params * initArgs) { Int index = -1; Int i = 0; IRESMAN_Fxns * resman = NULL; String protocolName = NULL; IRES_Status status = IRES_OK; IArg key; IRES_ProtocolRevision * revNo; if (initStatus != IRES_OK) { Log_print0(Diags_USER7, "[+7] RMAN_register> RMAN_init call " "hasn't happened successfully. Please initialize RMAN " "before registering resources"); Log_print0(Diags_EXIT, "[+X] RMAN_register> Exit " "(status=IRES_ENOINIT)"); return (IRES_ENOINIT); } Log_print2(Diags_ENTRY, "[+E] RMAN_register> Enter (resmanFxns=0x%x, " "initArgs=0x%x)", (IArg)resmanFxns, (IArg)initArgs); Assert_isTrue(resmanFxns != NULL, (Assert_Id)NULL); protocolName = resmanFxns->getProtocolName(); Assert_isTrue(protocolName != NULL, (Assert_Id)NULL); revNo = resmanFxns->getProtocolRevision(); Log_print4(Diags_USER4, "[+4] RMAN_register> Registering protocol %s " "revision (%d.%d.%d)", (IArg)protocolName, (IArg)(revNo->Major), (IArg)(revNo->Source), (IArg)(revNo->Radius)); /* * Use the protocolName and revisionNo to log the Resman Implementation * in the ResourceRegistry table. */ key = IGateProvider_enter(gate); /* * First check the entire table to see if there are any duplicates */ for (i = 0; i < resTable.tableIndex; i++) { if ((resman = RMAN_TABLE[i]) && !strcmp(protocolName, RMAN_TABLE[i]->getProtocolName()) && checkResMgrAlgRevision(RMAN_TABLE[i]->getProtocolRevision(), revNo)) { /* Found a match */ if (resmanFxns == RMAN_TABLE[i]) { /* Re-registering the same protocol, do nothing. */ IGateProvider_leave(gate, key); Log_print0(Diags_EXIT, "[+X] RMAN_register> " "Exit (status=IRES_EEXISTS)"); return (IRES_EEXISTS); } /* * Re-registering a different protocol for an existing entry. * Replace current entry with new entry */ index = i; if ((status = resman->exit()) != IRES_OK) { IGateProvider_leave(gate, key); Log_print2(Diags_USER7, "[+7] RMAN_register> Exit failed on" "IRESMAN implementation 0x%x, status: %d", (IArg)resman, (IArg)status); Log_print0(Diags_EXIT, "[+X] RMAN_register> Exit " "(status=IRES_EFAIL)"); return (IRES_EFAIL); } break; } } /* Registering a new protocol */ if ((status = resmanFxns->init(initArgs)) != IRES_OK) { IGateProvider_leave(gate, key); Log_print2(Diags_USER7, "[+7] RMAN_register> Init failed on " "IRESMAN implementation 0x%x, status: %d", (IArg)resman, (IArg)status); Log_print0(Diags_EXIT, "[+X] RMAN_register> Exit " "(status=IRES_ENORESOURCE)"); return (IRES_ENORESOURCE); } if (index == -1) { /* Not found in table. Check for available entry in freeIndex table */ if (-1 != resTable.freeIndex) { index = RMAN_FREE_ENTRIES[resTable.freeIndex]; resTable.freeIndex--; } else { /* No free entries available, use new one in the registry table */ /* Should never exceed pre configured table size */ Assert_isTrue(index < resTable.tableSize, (Assert_Id)NULL); index = resTable.tableIndex; resTable.tableIndex++; } } /* Add the actual entry to the Resource table */ RMAN_TABLE[index] = resmanFxns; IGateProvider_leave(gate, key); Log_print0(Diags_EXIT, "[+X] RMAN_register> Exit (status=IRES_OK)"); return (IRES_OK); }
/* * ======== RMAN_freeAllocatedResources ======== * Free resources that were directly allocated by RMAN_allocateResources */ IRES_Status RMAN_freeAllocatedResources (Int requestId, IRES_ResourceDescriptor * resDesc, Int numResources, Int scratchGroupId) { short i; IRESMAN_Fxns * resman = NULL; IArg key; IRES_Status status = IRES_OK; if (initStatus != IRES_OK) { Log_print0(Diags_USER7, "[+7] RMAN_freeAllocatedResources> " "RMAN_init call hasn't happened successfully. Please " "initialize RMAN before calling any other RMAN API"); Log_print0(Diags_EXIT, "[+X] RMAN_freeAllocatedResources> " "Exit (status=IRES_ENOINIT)"); return (IRES_ENOINIT); } Assert_isTrue(RMAN_PARAMS.allocFxn != NULL, (Assert_Id)NULL); Assert_isTrue(RMAN_PARAMS.freeFxn != NULL, (Assert_Id)NULL); Log_print4(Diags_ENTRY, "[+E] RMAN_freeAllocatedResources> Enter " "requestId=%d, (resDesc=0x%x, numResources=%d, scratchGroupId=%d)", (IArg)requestId, (IArg)resDesc, (IArg)numResources, (IArg)scratchGroupId); for (i = 0 ; i < numResources; i++) { resman = getResman(resDesc[i].resourceName, resDesc[i].revision); if (NULL == resman) { Log_print2(Diags_USER7, "[+7] RMAN_freeAllocatedResources> IRESMAN " "handle not found for resource %s version 0x%x", (IArg)(resDesc[i].resourceName), (IArg)(resDesc[i].revision)); status = IRES_ENOTFOUND; } else { /* * Call freeHandle on resman Implementation and deinit * resources held by the algorithm */ key = IGateProvider_enter(gate); status = resman->freeHandle((IALG_Handle)requestId, resDesc[i].handle, &resDesc[i], scratchGroupId); IGateProvider_leave(gate, key); if (status != IRES_OK) { /* TODO: Some SYS ABORT type error here */ Log_print1(Diags_USER7, "[+7] RMAN_freeAllocatedResources> Free handle failed " "on IRESMAN implementation 0x%x", (IArg)resman); status = IRES_EFAIL; } } } //if (FALSE == freeVTableEntry((IALG_Fxns *)alg->fxns, resFxns)) { if (FALSE == freeVTableEntry((IALG_Handle)requestId, (IRES_Fxns *)NULL)) { /* TODO: Add trace */ status = IRES_EFAIL; } Log_print1(Diags_EXIT, "[+X] RMAN_freeResources> Exit (status=%d)", (IArg)status); return (status); }
/* * ======== RMAN_freeResources ======== * Free resources held by the algorithm resource handle */ IRES_Status RMAN_freeResources(IALG_Handle alg, IRES_Fxns * resFxns, Int scratchGroupId) { short numResources; short i; size_t resDescSize; IRESMAN_Fxns * resman = NULL; IArg key; IRES_Status status = IRES_OK; IRES_ResourceDescriptor * resDesc = NULL; if (initStatus != IRES_OK) { Log_print0(Diags_USER7, "[+7] RMAN_freeResources> " "RMAN_init call hasn't happened successfully. Please " "initialize RMAN before calling any other RMAN API"); Log_print0(Diags_EXIT, "[+X] RMAN_freeResources> " "Exit (status=IRES_ENOINIT)"); return (IRES_ENOINIT); } Assert_isTrue(resFxns != NULL, (Assert_Id)NULL); Assert_isTrue(RMAN_PARAMS.allocFxn != NULL, (Assert_Id)NULL); Assert_isTrue(RMAN_PARAMS.freeFxn != NULL, (Assert_Id)NULL); Log_print3(Diags_ENTRY, "[+E] RMAN_freeResources> Enter " "(alg=0x%x, resFxns=0x%x, scratchGroupId=%d)", (IArg)alg, (IArg)resFxns, (IArg)scratchGroupId); /* * Get resource descriptors held by the algorithm */ numResources = (resFxns->numResourceDescriptors)(alg); resDescSize = numResources * sizeof(IRES_ResourceDescriptor); /* Allocate memory for algorithm's resource descriptors */ if ((resDesc = myAlloc(resDescSize, 0)) == NULL) { Log_print0(Diags_USER7, "[+7] RMAN_freeResources> Memory " "allocation failed"); status = IRES_ENOMEM; } if (status == IRES_OK) { if (IRES_OK != (resFxns->getResourceDescriptors(alg, resDesc))) { Log_print2(Diags_USER7, "[+7] RMAN_freeResources> Error " "obtaining Resource Descriptors from alg 0x%x with IRES " "interface 0x%x", (IArg)alg, (IArg)resDesc); status = IRES_ENORESOURCE; } } if (status == IRES_OK) { /* Deinit the Resources that were granted to the algorithm */ if (IRES_OK != (resFxns->deinitResources(alg, resDesc))) { Log_print2(Diags_USER7, "[+7] RMAN_freeResources> " "De-init failed on alg 0x%x IRES interface 0x%x", (IArg)alg, (IArg)resDesc); status = IRES_EALG; } for (i = 0 ; i < numResources; i++) { resman = getResman(resDesc[i].resourceName, resDesc[i].revision); if (NULL == resman) { Log_print2(Diags_USER7, "[+7] RMAN_freeResources> IRESMAN " "handle not found for resource %s version 0x%x", (IArg)(resDesc[i].resourceName), (IArg)(resDesc[i].revision)); status = IRES_ENOTFOUND; } else { /* * Call freeHandle on resman Implementation and deinit * resources held by the algorithm */ key = IGateProvider_enter(gate); status = resman->freeHandle(alg, resDesc[i].handle, &resDesc[i], scratchGroupId); IGateProvider_leave(gate, key); if (status != IRES_OK) { /* TODO: Some SYS ABORT type error here */ Log_print1(Diags_USER7, "[+7] RMAN_freeResources> Free handle failed on IRESMAN" " implementation 0x%x", (IArg)resman); status = IRES_EFAIL; } } } } //if (FALSE == freeVTableEntry((IALG_Fxns *)alg->fxns, resFxns)) { if (FALSE == freeVTableEntry((IALG_Handle )alg, resFxns)) { /* TODO: Add trace */ status = IRES_EFAIL; } if (resDesc) { myFree(resDesc, resDescSize); } Log_print1(Diags_EXIT, "[+X] RMAN_freeResources> Exit (status=%d)", (IArg)status); return (status); }
/* * ======== RMAN_allocateResources ======== * Directly allocate IRES resources by client without implementing IRES_Fxns */ IRES_Status RMAN_allocateResources(Int requestId, IRES_ResourceDescriptor * resDesc, Int numResources, Int scratchGroupId) { Int n = 0; IRESMAN_Fxns * resman = NULL; IRES_Status status = IRES_OK; IArg key; if (initStatus != IRES_OK) { Log_print0(Diags_USER7, "[+7] RMAN_allocateResources> " "RMAN_init call hasn't happened successfully. Please " "initialize RMAN before calling any other RMAN API"); Log_print0(Diags_EXIT, "[+X] RMAN_allocateResource> " "Exit (status=IRES_ENOINIT)"); return (IRES_ENOINIT); } Assert_isTrue(resDesc != NULL, (Assert_Id)NULL); Assert_isTrue(numResources >=1, (Assert_Id)NULL); Assert_isTrue(RMAN_PARAMS.allocFxn != NULL, (Assert_Id)NULL); Assert_isTrue(RMAN_PARAMS.freeFxn != NULL, (Assert_Id)NULL); Log_print4(Diags_ENTRY, "[+E] RMAN_allocateResources> Enter " "requestId=%d, (resDesc=0x%x, numResources=%d, scratchGroupId=%d)", (IArg)requestId, (IArg)resDesc, (IArg)numResources, (IArg)scratchGroupId); /* * Allocate requested resources one by one. */ if (status == IRES_OK) { /* For each requested resource */ for (n = 0 ; n < numResources; n++) { /* If someone populated the resource descriptor improperly, bail */ if ((resDesc[n].resourceName == NULL) || (resDesc[n].revision == NULL)) { Log_print0(Diags_USER7, "[+7] RMAN_allocateResources> " "Resource protocol and/or version were NULL. " "Most likely an issue with the algorithm's " "getResourceRequestDescriptor implementation."); status = IRES_EALG; break; } resman = getResman(resDesc[n].resourceName, resDesc[n].revision); if (resman != NULL) { /* * Call getHandle on the IRESMAN implementation using * the protocolArgs extracted. */ Log_print1(Diags_USER2, "[+2] RMAN_allocateResources> Call " "getHandle on the IRESMAN implementation 0x%x", (IArg)resman); /* Acquire lock */ key = IGateProvider_enter(gate); resDesc[n].handle = resman->getHandle((IALG_Handle)requestId, &resDesc[n], scratchGroupId, &status); /* Release lock */ IGateProvider_leave(gate, key); if (IRES_OK != status) { break; } } else { Log_print2(Diags_USER7, "[+7] RMAN_allocateResources> " "Resource protocol %s and version 0x%x didn't match " "any registered protocol.", (IArg)(resDesc[n].resourceName), (IArg)(resDesc[n].revision)); status = IRES_ENOTFOUND; break; } } } /* * Return those handles to IALG using the appropriate IRES call */ if (FALSE == addVTableEntry((IALG_Handle)requestId, (IRES_Fxns *)NULL)) { /* TODO: Add trace */ status = IRES_EFAIL; RMAN_freeAllocatedResources(requestId, resDesc, numResources, scratchGroupId); } Log_print1(Diags_EXIT, "[+X] RMAN_allocateResources> Exit (status=%d)", (IArg)status); return (status); }
/* * ======== RMAN_assignResources ======== * Assign resources to the algorithm indicated by alg. The resource * requirements can be determined by using the IRES_Fxns implementation */ IRES_Status RMAN_assignResources(IALG_Handle alg, IRES_Fxns * resFxns, Int scratchGroupId) { Int numResources; Int k; Int n = 0; size_t resDescSize; IRESMAN_Fxns * resman = NULL; IRES_Status status = IRES_OK; IRES_Status freeStatus = IRES_OK; IRES_Status algStatus = IRES_OK; IRES_YieldFxn yieldFxn = NULL; IRES_YieldArgs * yieldArgs = NULL; IRES_ResourceDescriptor * resDesc = NULL; IArg key; if (initStatus != IRES_OK) { Log_print0(Diags_USER7, "[+7] RMAN_assignResources> " "RMAN_init call hasn't happened successfully. Please " "initialize RMAN before calling any other RMAN API"); Log_print0(Diags_EXIT, "[+X] RMAN_assignResources> " "Exit (status=IRES_ENOINIT)"); return (IRES_ENOINIT); } Assert_isTrue(resFxns != NULL, (Assert_Id)NULL); Assert_isTrue(RMAN_PARAMS.allocFxn != NULL, (Assert_Id)NULL); Assert_isTrue(RMAN_PARAMS.freeFxn != NULL, (Assert_Id)NULL); Log_print3(Diags_ENTRY, "[+E] RMAN_assignResources> " "Enter (alg=0x%x, resFxns=0x%x, scratchGroupId=%d)", (IArg)alg, (IArg)resFxns, (IArg)scratchGroupId); /* * Get resource requirements of the algorithm */ numResources = (resFxns->numResourceDescriptors)(alg); resDescSize = numResources * sizeof(IRES_ResourceDescriptor); /* Allocate memory to hold algorithm's resource descriptors */ if ((resDesc = myAlloc(resDescSize, 0)) == NULL) { Log_print1(Diags_USER7, "[+7] RMAN_assignResources> " "Could not allocate memory size 0x%x in space " "IALG_EXTERNAL of type IALG_PERSIST", (IArg)resDescSize); Log_print0(Diags_EXIT, "[+X] RMAN_assignResources> " "Exit (status=IRES_ENOMEM)"); return (IRES_ENOMEM); } algStatus = resFxns->getResourceDescriptors(alg, resDesc); if (algStatus != IRES_OK) { Log_print3(Diags_USER7, "[+7] RMAN_assignResources> Error obtaining " "Resource Descriptors [status: %d] from alg 0x%x, " "IRES interface 0x%x", (IArg)algStatus, (IArg)alg, (IArg)resDesc); status = IRES_EALG; } if (status == IRES_OK) { /* For each requested resource */ for (n = 0 ; n < numResources; n++) { /* If someone populated the resource descriptor improperly, bail */ if ((resDesc[n].resourceName == NULL) || (resDesc[n].revision == NULL)) { Log_print0(Diags_USER7, "[+7] RMAN_assignResources> " "Resource protocol and/or version were NULL. " "Most likely an issue with the algorithm's " "getResourceRequestDescriptor implementation."); status = IRES_EALG; break; } resman = getResman(resDesc[n].resourceName, resDesc[n].revision); if (resman != NULL) { /* * Call getHandle on the IRESMAN implementation using * the protocolArgs extracted. */ Log_print1(Diags_USER2, "[+2] RMAN_assignResources> Call " "getHandle on the IRESMAN implementation 0x%x", (IArg)resman); /* Acquire lock */ key = IGateProvider_enter(gate); resDesc[n].handle = resman->getHandle(alg, &resDesc[n], scratchGroupId, &status); /* Release lock */ IGateProvider_leave(gate, key); if (IRES_OK != status) { break; } } else { Log_print2(Diags_USER7, "[+7] RMAN_assignResources> " "Resource protocol %s and version 0x%x didn't match " "any registered protocol.", (IArg)(resDesc[n].resourceName), (IArg)(resDesc[n].revision)); status = IRES_ENOTFOUND; break; } } } /* n = number of resources allocated */ /* * Return those handles to IALG using the appropriate IRES call */ if (IRES_OK == status) { if ((RMAN_PARAMS.yieldFxn != NULL) && (ti_sdo_fc_rman_RMAN_setYieldArgs != NULL)) { yieldFxn = RMAN_PARAMS.yieldFxn; yieldArgs = ti_sdo_fc_rman_RMAN_setYieldArgs(scratchGroupId, RMAN_PARAMS.yieldSamePriority); } /* Acquire lock */ key = IGateProvider_enter(gate); algStatus = resFxns->initResources(alg, resDesc, yieldFxn, yieldArgs); /* Release lock */ IGateProvider_leave(gate, key); if (algStatus != IRES_OK) { Log_print1(Diags_USER7, "[+7] RMAN_assignResources> " "resFxns->initResources() failed [%d]", (IArg)algStatus); status = IRES_EALG; } } if (status != IRES_OK) { /* * Error somewhere in initialization of resource handles * Free all allocated handles. */ for (k = 0; k < n; k++) { resman = getResman(resDesc[k].resourceName, resDesc[k].revision); if (NULL == resman) { /* Resource table is messed up - bail out */ Log_print2(Diags_USER7, "[+7] RMAN_assignResources> Could " "not find IRESMAN matching resource %s version 0x%x", (IArg)(resDesc[k].resourceName), (IArg)(resDesc[k].revision)); status = IRES_EFAIL; break; } /* Acquire lock */ key = IGateProvider_enter(gate); freeStatus = resman->freeHandle(alg, resDesc[k].handle, &resDesc[k], scratchGroupId); /* Release lock */ IGateProvider_leave(gate, key); if (freeStatus != IRES_OK) { /* * If we can't free the resource handle, something is really * messed up. Don't try to free anything else. */ status = IRES_EFAIL; Log_print2(Diags_USER7, "[+7] RMAN_assignResources> Free " "handle failed [%d] on IRESMAN implementation 0x%x", (IArg)status, (IArg)resman); break; } } } else { /* Status is OKAY, add entry to table */ /* if (FALSE == addVTableEntry((IALG_Fxns *)alg->fxns, resFxns)) { */ if (FALSE == addVTableEntry((IALG_Handle)alg, resFxns)) { /* TODO: Add trace */ status = IRES_EFAIL; RMAN_freeResources(alg, resFxns, scratchGroupId); } } if (resDesc) { myFree(resDesc, resDescSize); } Log_print1(Diags_EXIT, "[+X] RMAN_assignResources> Exit (status=%d)", (IArg)status); return (status); }
/* * ======== RMAN_unregister ======== * Unregister the protocol and the corresponding resource manager * implementation from the Resource Registry */ IRES_Status RMAN_unregister(IRESMAN_Fxns * resmanFxns) { Int i = 0; String protocolName = NULL; IArg key; IRES_ProtocolRevision * revNo; if (initStatus != IRES_OK) { Log_print0(Diags_USER7, "[+7] RMAN_unregister> " "RMAN_init call hasn't happened successfully. Please " "initialize RMAN before calling other RMAN APIs"); Log_print0(Diags_EXIT, "[+X] RMAN_unregister> " "Exit (status=IRES_ENOINIT)"); return (IRES_ENOINIT); } Log_print1(Diags_ENTRY, "[+E] RMAN_unregister> Enter (resmanFxns=0x%x)", (IArg)resmanFxns); protocolName = resmanFxns->getProtocolName(); revNo = resmanFxns->getProtocolRevision(); Assert_isTrue(protocolName != NULL, (Assert_Id)NULL); key = IGateProvider_enter(gate); /* * Search the table matching the protocolName and revision Number * with the entries */ for (i = 0; i < resTable.tableIndex; i++) { /* Check for NULL before checking for protocol and revision */ if ((RMAN_TABLE[i]) && checkResMgrAlgRevision(RMAN_TABLE[i]->getProtocolRevision(), revNo) && !strncmp(protocolName, RMAN_TABLE[i]->getProtocolName(), RMAN_PROTOCOLNAMESIZE)) { /* Found a match */ break; } } if (i == resTable.tableIndex) { /* Entry not found */ IGateProvider_leave(gate, key); Log_print0(Diags_USER7, "[+7] RMAN_unregister> Entry not found " "in table of registered IRESMAN implementations"); Log_print0(Diags_EXIT, "[+X] RMAN_unregister> Exit " "(status=IRES_ENOTFOUND)"); return (IRES_ENOTFOUND); } /* * Call the exit interface of the specific IResman implementation and * delete that entry from the table */ if (IRES_OK != (RMAN_TABLE[i])->exit()) { IGateProvider_leave(gate, key); Log_print1(Diags_USER7, "[+7] RMAN_unregister> Exit " "failed on IRESMAN implementation 0x%x", (IArg)(RMAN_TABLE[i])); Log_print0(Diags_EXIT, "[+X] RMAN_unregister> Exit (status=IRES_EFAIL)"); return (IRES_EFAIL); } /* Reset this entry in the entries table */ RMAN_TABLE[i] = NULL; /* Since this table index is now available, add it to the freeTable */ resTable.freeIndex++; /* Should never run out of space in free Table */ Assert_isTrue(resTable.freeIndex < resTable.tableSize, (Assert_Id)NULL); RMAN_FREE_ENTRIES[resTable.freeIndex] = i; IGateProvider_leave(gate, key); Log_print0(Diags_EXIT, "[+X] RMAN_unregister> Exit (status=IRES_OK)"); return (IRES_OK); }