Esempio n. 1
0
/*
 *  ======== RMP_delete ========
 */
Void RMP_delete(RMP_Handle handle)
{
#ifdef xdc_target__os_Linux
    Int shmId = handle->sharedMemId;                   /* Shared Mem Id */
#endif
    Void * base = (Void *)(shmAddrs[handle->shmCount]);    /* Base Address */

    /* Decrease the refCount */
    handle->refCount--;

    /* If the referenceCount is zero, call the RMM delete */
    if (0 == handle->refCount) {
        RMM_delete(RMMHANDLE(handle));
    }

#ifdef xdc_target__os_Linux
    /* Free the shared memory segment */
    SHM_freeObj(base, shmId);
#else
    free(base);
#endif
}
Esempio n. 2
0
/*
 *  ======== RMM_create ========
 */
DSP_STATUS RMM_create(struct RMM_TargetObj **pTarget,
		     struct RMM_Segment segTab[], u32 numSegs)
{
	struct RMM_Header *hptr;
	struct RMM_Segment *sptr, *tmp;
	struct RMM_TargetObj *target;
	s32 i;
	DSP_STATUS status = DSP_SOK;

	DBC_Require(pTarget != NULL);
	DBC_Require(numSegs == 0 || segTab != NULL);

	GT_3trace(RMM_debugMask, GT_ENTER,
		 "RMM_create(0x%lx, 0x%lx, 0x%lx)\n",
		 pTarget, segTab, numSegs);

	/* Allocate DBL target object */
	MEM_AllocObject(target, struct RMM_TargetObj, RMM_TARGSIGNATURE);

	if (target == NULL) {
		GT_0trace(RMM_debugMask, GT_6CLASS,
			 "RMM_create: Memory allocation failed\n");
		status = DSP_EMEMORY;
	}
	if (DSP_FAILED(status))
		goto func_cont;

	target->numSegs = numSegs;
	if (!(numSegs > 0))
		goto func_cont;

	/* Allocate the memory for freelist from host's memory */
	target->freeList = MEM_Calloc(numSegs * sizeof(struct RMM_Header *),
				     MEM_PAGED);
	if (target->freeList == NULL) {
		GT_0trace(RMM_debugMask, GT_6CLASS,
			 "RMM_create: Memory allocation failed\n");
		status = DSP_EMEMORY;
	} else {
		/* Allocate headers for each element on the free list */
		for (i = 0; i < (s32) numSegs; i++) {
			target->freeList[i] =
					MEM_Calloc(sizeof(struct RMM_Header),
					MEM_PAGED);
			if (target->freeList[i] == NULL) {
				GT_0trace(RMM_debugMask, GT_6CLASS,
					 "RMM_create: Memory "
					 "allocation failed\n");
				status = DSP_EMEMORY;
				break;
			}
		}
		/* Allocate memory for initial segment table */
		target->segTab = MEM_Calloc(numSegs *
				 sizeof(struct RMM_Segment), MEM_PAGED);
		if (target->segTab == NULL) {
			GT_0trace(RMM_debugMask, GT_6CLASS,
				 "RMM_create: Memory allocation failed\n");
			status = DSP_EMEMORY;
		} else {
			/* Initialize segment table and free list */
			sptr = target->segTab;
			for (i = 0, tmp = segTab; numSegs > 0; numSegs--, i++) {
				*sptr = *tmp;
				hptr = target->freeList[i];
				hptr->addr = tmp->base;
				hptr->size = tmp->length;
				hptr->next = NULL;
				tmp++;
				sptr++;
			}
		}
	}
func_cont:
	/* Initialize overlay memory list */
	if (DSP_SUCCEEDED(status)) {
		target->ovlyList = LST_Create();
		if (target->ovlyList == NULL) {
			GT_0trace(RMM_debugMask, GT_6CLASS,
				 "RMM_create: Memory allocation failed\n");
			status = DSP_EMEMORY;
		}
	}

	if (DSP_SUCCEEDED(status)) {
		*pTarget = target;
	} else {
		*pTarget = NULL;
		if (target)
			RMM_delete(target);

	}

	DBC_Ensure((DSP_SUCCEEDED(status) && MEM_IsValidHandle((*pTarget),
		  RMM_TARGSIGNATURE)) || (DSP_FAILED(status) && *pTarget ==
		  NULL));

	return status;
}