EDMA_Status EDMA_mapBaseAddress(void **pvirtAddr) { Int sharedMemId = -1; if (NULL == state) { #ifdef xdc_target__os_Linux state = ( EDMA_State *)SHM_getObj(EXAMPLE_gate, sizeof(EDMA_State), EDMA_LOCKID, &setInternalState, &sharedMemId); #else state = &myState; setInternalState(state); sharedMemId = 0; #endif state->sharedMemId = sharedMemId; } *pvirtAddr = (void **)(state->edma).edmaAddressSpace; return (EDMA_OK); }
static void getInternalState() { Int sharedMemId = -1; _resmanInternalState = (IRESMAN_MEMTCM_InternalState *)SHM_getObj( _MEMTCM_lock, sizeof(IRESMAN_MEMTCM_InternalState), _MEMTCM_LOCKID, &setInternalState, &sharedMemId); if ((NULL != _resmanInternalState) && (-1 != sharedMemId)) { _resmanInternalState->sharedMemId = sharedMemId; } else { _resmanInternalState = NULL; sharedMemId = -1; } }
static void getInternalState() { #ifdef xdc_target__os_Linux Int sharedMemId = -1; _resmanInternalState = (IRESMAN_HDVICP_InternalState *)SHM_getObj(gate, sizeof(IRESMAN_HDVICP_InternalState), _HDVICP_LOCKID, &setInternalState, &sharedMemId); _resmanInternalState->sharedMemId = sharedMemId; #else __FAR__ static IRESMAN_HDVICP_InternalState _HDVICP_internalState; _resmanInternalState = (IRESMAN_HDVICP_InternalState *) &_HDVICP_internalState; setInternalState(_resmanInternalState); _resmanInternalState->sharedMemId = 0; #endif }
int EDMA_init(void) { Int sharedMemId; #ifdef xdc_target__os_Linux state = ( EDMA_State *)SHM_getObj(EXAMPLE_gate, sizeof(EDMA_State), EDMA_LOCKID, &setInternalState, &sharedMemId); #else state = &myState; setInternalState(state); sharedMemId = 0; #endif state->refCount++; if (NULL != state) { state->sharedMemId = sharedMemId; } return (1); }
static void getInternalState() { Int sharedMemId = -1; #ifdef xdc_target__os_Linux rmanInternalState = (RMAN_InternalState *)SHM_getObj(gate, sizeof(RMAN_InternalState) + (ti_sdo_fc_rman_RMAN_MAXALGS * sizeof(RMAN_VtableEntry)), (key_t)_RMAN_LOCKID, &setInternalState, &sharedMemId); algresVTable = (RMAN_VtableEntry *)((unsigned int)rmanInternalState + (unsigned int) (rmanInternalState->info.vTableOffset)); #else rmanInternalState = (RMAN_InternalState *) &_RMAN_internalState; algresVTable = (RMAN_VtableEntry *)(malloc(ti_sdo_fc_rman_RMAN_MAXALGS * sizeof(RMAN_VtableEntry))); setInternalState(rmanInternalState); sharedMemId = 0; #endif rmanInternalState->info.sharedMemId = sharedMemId; rmanInternalState->info.refCount++; }
/* * ======== RMP_create ======== */ RMP_Handle RMP_create(RMP_Attrs *attrs) { RMP_Obj *handle = NULL; Int shmId = -1; unsigned int shmSize = 0; Void * addr = NULL; RMM_Attrs rmmAttrs; static Int shmCount = 0; /* Create a shared memory object RMP_Obj using the key and the lock Size of this will depend numResources and RMM_Obj etc */ Assert_isTrue(shmCount < RMMP_MAXINSTANCES, (Assert_Id)NULL); shmSize = sizeof(RMP_Obj) + sizeof(RMM_Obj) + sizeof(UInt32); shmSize = ALIGN32(shmSize); shmSize += (attrs->maxFreeListBlocks * sizeof(RMM_Header)); shmSize = ALIGN32(shmSize); #ifdef xdc_target__os_Linux addr = SHM_getObj((GateProcess_Handle_upCast)(attrs->gate), shmSize, (key_t)attrs->key, (SHM_InitFxn)&setInternalState, &shmId); #else addr = (void *)malloc(shmSize); if (NULL != addr) { setInternalState(addr); shmId = 0; } #endif if (shmId != -1) { handle = (RMP_Obj *)addr; if (0 == handle->refCount) { /* RMM_create has to happen */ rmmAttrs.segid = shmCount; /* Use shmCount as segId */ rmmAttrs.base = attrs->base; rmmAttrs.length = attrs->length; rmmAttrs.maxFreeListBlocks = attrs->maxFreeListBlocks; /* My alloc fxn will use the sharedMem address to increment an offset pointer */ rmmAttrs.allocFxn = shmAlloc; rmmAttrs.freeFxn = shmFree; /* Store the shmCount in the SHM_Obj part of the handle */ handle->shmCount = shmCount; shmCount++; } /* Successful acquisition of shared Mem object, so store in array for use by allocFxn */ shmAddrs[handle->shmCount] = (unsigned int)addr; shmIndex[handle->shmCount] = sizeof(RMP_Obj); /* Change this to work for the allocFxn */ if (handle->refCount == 0) { /* Whatever the RMM_create returns, store that as an offset from shmBase */ handle->rmmOffset = OFFSET(handle, RMM_create(&rmmAttrs)); } handle->refCount++; /* Store the sharedMemId in the RMP_Obj */ handle->sharedMemId = shmId; } return (handle); }
EDMA_Status EDMA_getResource(int devId, int *tcc, int *channel, int *param, int nParams) { EDMA_Status status = EDMA_ENOCHANNEL; Bool found = FALSE; Int j = 0; Int temp = -1; Int sharedMemId; if (NULL == state) { #ifdef xdc_target__os_Linux state = ( EDMA_State *)SHM_getObj(EXAMPLE_gate, sizeof(EDMA_State), EDMA_LOCKID, &setInternalState, &sharedMemId); #else state = (EDMA_State *)&myState; setInternalState(state); sharedMemId = 0; #endif state->sharedMemId = sharedMemId; } switch (devId) { case EDMA_EDMAANY: while (state->symIndex < 64) { if ((state->edmaArr[state->symIndex] == 0) && (state->paramArr[state->symIndex] == 0) && (state->tccArr[state->symIndex] == 0)) { *channel = state->symIndex; *param = state->symIndex; *tcc = state->symIndex; state->edmaArr[state->symIndex] = 1; state->paramArr[state->symIndex] = 1; state->tccArr[state->symIndex] = 1; status = EDMA_OK; state->symIndex++; break; } else { state->symIndex++; } } break; case EDMA_QDMAANY: while (state->tccQdmaIndex != state->symIndex) { if (*tcc != EDMA_TCCANY) { temp = state->tccQdmaIndex; state->tccQdmaIndex = *tcc; } if (state->tccArr[state->tccQdmaIndex] == 0) { while ((state->qdmaIndex < 8) && (state->qdmaArr[state->qdmaIndex] == 1)) { state->qdmaIndex++; } while ((state->paramAnyIndex < 512) && (state->paramArr[state->paramAnyIndex] == 1)){ state->paramAnyIndex++; } if ((1 == state->qdmaArr[state->qdmaIndex]) || (1 == state->paramArr[state->paramAnyIndex])) { break; } *channel = EDMA_QDMA0 + state->qdmaIndex; *param = state->paramAnyIndex; *tcc = state->tccQdmaIndex; state->qdmaArr[state->qdmaIndex] = 1; state->paramArr[state->paramAnyIndex] = 1; state->tccArr[state->tccQdmaIndex] = 1; state->qdmaIndex++; state->tccQdmaIndex--; state->paramAnyIndex++; status = EDMA_OK; if (temp != -1) { state->tccQdmaIndex = temp; } break; } else { if (*tcc != EDMA_TCCANY) { break; } state->tccQdmaIndex--; } } if (temp != -1) { state->tccQdmaIndex = temp; } break; case EDMA_PARAMANY: while ((state->paramAnyIndex < 512) && (state->paramArr[state->paramAnyIndex] == 1)) { state->paramAnyIndex++; } if (state->paramAnyIndex + nParams < 512) { for (j = 0; j < nParams; j++) { state->paramArr[state->paramAnyIndex+j] = 1; } *param = state->paramAnyIndex; state->paramAnyIndex += nParams; status = EDMA_OK; break; } break; default: if (devId < 64) { /* Requested and EDMA channel */ if ((state->edmaArr[devId] == 0) && (state->paramArr[devId] == 0) && (state->tccArr[devId] == 0)) { *channel = devId; *param = devId; *tcc = devId; state->edmaArr[devId] = 1; state->paramArr[devId] = 1; state->tccArr[devId] = 1; status = EDMA_OK; break; } } else if (devId < 512) { /* Requested a PARAM channel */ for (j = 0; j < nParams; j++) { if (state->paramArr[devId+j] == 0) { found = TRUE; state->paramArr[devId + j] = 1; } else { found = FALSE; break; } } if (found) { *param = devId; status = EDMA_OK; } } else if (devId <= EDMA_QDMA7) { if (state->qdmaArr[devId-EDMA_QDMA0] == 0) { state->qdmaArr[devId-EDMA_QDMA0] = 1; *channel = devId-EDMA_QDMA0; } while (state->tccQdmaIndex != state->symIndex) { if (state->tccArr[state->tccQdmaIndex] == 0) { while ((state->paramAnyIndex < 512) && (state->paramArr[state->paramAnyIndex] == 1)) { state->paramAnyIndex++; } if (1 == state->paramArr[state->paramAnyIndex]) { break; } *param = state->paramAnyIndex; *tcc = state->tccQdmaIndex; state->paramArr[state->paramAnyIndex] = 1; state->tccArr[state->tccQdmaIndex] = 1; state->tccQdmaIndex--; state->paramAnyIndex++; status = EDMA_OK; break; } else { state->tccQdmaIndex--; } } } } return (status); }
/* * ======== SMGRMP_create ======== */ SMGRMP_Handle SMGRMP_create(SMGRMP_Attrs *attrs) { SMGRMP_Obj *handle; Int shmId = -1; unsigned int shmSize = 0; Void * addr; SMGR_Attrs smgrAttrs; /* Create a shared memory object SMGRMP_Obj using the key and the lock Size of this will depend numResources and SMGR_Obj etc */ GT_assert(CURTRACE, shmCount < SMGRMP_MAXINSTANCES); shmSize = sizeof(SMGRMP_Obj) + sizeof(SMGR_Obj) + sizeof(UInt32); shmSize = ALIGN32(shmSize); shmSize += (sizeof(SMGR_Counter) * attrs->numResources); shmSize = ALIGN32(shmSize); #ifdef xdc_target__os_Linux addr = SHM_getObj(attrs->lock, shmSize, (key_t)attrs->key, (SHM_InitFxn)&setInternalState, &shmId); #else addr = (void *)malloc(shmSize); setInternalState(addr); shmId = 0; #endif if (shmId != -1) { handle = (SMGRMP_Obj *)addr; /* This will return a unique object for each key, and the same object for different processes */ if (0 == handle->refCount) { /* SMGR_create has to happen */ smgrAttrs.segid = shmCount; /* Use shmCount as segId */ smgrAttrs.numResources = attrs->numResources; smgrAttrs.numScratchGroups = attrs->numScratchGroups; smgrAttrs.allocFxn = shmAlloc; smgrAttrs.freeFxn = shmFree; /* Store the shmCount in the SHM_Obj part of the handle */ handle->shmCount = shmCount; shmCount++; shmTotal++; } /* Successful acquisition of shared Mem object, so store in array for use by alloc/free functions */ shmAddrs[handle->shmCount] = (unsigned int)addr; shmIndex[handle->shmCount] = sizeof(SMGRMP_Obj); /* Change this to work for the alloFxn */ if (handle->refCount == 0) { /* Whatever the SMGR_create returns, store that as an offset from shmBase */ handle->smgrOffset = OFFSET(handle, SMGR_create(&smgrAttrs)); } handle->refCount++; /* Store the sharedMemId in the SMGRMP_Obj */ handle->sharedMemId = shmId; return (handle); } else { return (NULL); } }