Esempio n. 1
0
void testPools(size_t size, int block)
{
    int rv;
    int num_buffers;
    int i;
    CMEM_AllocParams params;

    printf("allocating pool buffers from CMEM memory block %d...\n", block);
    printf("    (will end with expected failed allocation)\n");

    num_buffers = 0;
    params.type = CMEM_POOL;
    params.flags = CMEM_NONCACHED;
    params.alignment = 0;
    while (num_buffers < NUMHEAPPTRS) {
	ptrs[num_buffers] = CMEM_alloc2(block, size, &params);
	if (ptrs[num_buffers] == NULL) {
	    break;
	}
	num_buffers++;
    }
    printf("...done, %d allocated\n", num_buffers);

    if (non_interactive_flag == FALSE) {
	printf("Press ENTER to continue\n");
	getchar();
    }

    printf("freeing pool blocks...\n");
    for (i = 0; i < num_buffers; i++) {
	rv = CMEM_free(ptrs[i], &params);
	if (rv < 0) {
	    printf("error freeing blocks\n");
	    break;
	}
	ptrs[i] = NULL;
    }

    /* make sure we can still allocate num_buffers after freeing */
    printf("allocating %d pool blocks...\n", num_buffers);
    for (i = 0; i < num_buffers; i++) {
	ptrs[i] = CMEM_alloc2(block, size, &params);
	if (ptrs[i] == NULL) {
	    printf("error re-allocating %d heap blocks\n", num_buffers);
	    break;
	}
    }
    printf("...done, freeing pool blocks...\n");
    for (i = 0; i < num_buffers; i++) {
	rv = CMEM_free(ptrs[i], &params);
	if (rv < 0) {
	    printf("error freeing blocks\n");
	    break;
	}
    }
    printf("...done\n");
}
Esempio n. 2
0
static void close_video(AVFormatContext *oc, AVStream *st)
{
    avcodec_close(st->codec);
    CMEM_free(picture->data[0], &alloc_params);
    av_free(picture);
    if (tmp_picture) {
        CMEM_free(tmp_picture->data[0], &alloc_params);
        av_free(tmp_picture);
    }
    CMEM_free(video_outbuf, &alloc_params);
}
Esempio n. 3
0
void testHeap(int size, int block)
{
    int rv;
    int num_buffers;
    int i;
    CMEM_AllocParams params;

    printf("allocating heap buffers from CMEM memory block %d...\n", block);
    num_buffers = 0;
    params.type = CMEM_HEAP;
    params.flags = CMEM_NONCACHED;
    params.alignment = 0;
    while (num_buffers < NUMHEAPPTRS) {
        heap_ptrs[num_buffers] = CMEM_alloc2(block, size, &params);
        if (heap_ptrs[num_buffers] == NULL) {
            break;
        }
        num_buffers++;
    }
    printf("...done, %d allocated\n", num_buffers);

    printf("Press ENTER to continue (after 'cat /proc/cmem' if desired).\n");
    getchar();

    printf("freeing heap blocks...\n");
    for (i = 0; i < num_buffers; i++) {
        rv = CMEM_free(heap_ptrs[i], &params);
        if (rv < 0) {
            printf("error freeing blocks\n");
            break;
        }
        heap_ptrs[i] = NULL;
    }

    /* make sure we can still allocate num_buffers after freeing */
    printf("allocating %d heap blocks...\n", num_buffers);
    for (i = 0; i < num_buffers; i++) {
        heap_ptrs[i] = CMEM_alloc2(block, size, &params);
        if (heap_ptrs[i] == NULL) {
            printf("error re-allocating %d heap blocks\n", num_buffers);
            break;
        }
    }
    printf("...done, freeing heap blocks...\n");
    for (i = 0; i < num_buffers; i++) {
        rv = CMEM_free(heap_ptrs[i], &params);
        if (rv < 0) {
            printf("error freeing blocks\n");
            break;
        }
    }

    printf("...done\n");
}
Esempio n. 4
0
int writereadCMA(size_t size)
{
    int rv;
    unsigned int i;
    CMEM_AllocParams params;
    char *heap_ptr;

    printf("allocating write-read heap buffer from CMA memory block...\n");
    params.type = CMEM_HEAP;
    params.flags = CMEM_NONCACHED;
    params.alignment = 0;
    heap_ptr = CMEM_alloc2(CMEM_CMABLOCKID, size, &params);
    if (heap_ptr == NULL) {
	printf("...failed\n");
	return -1;
    }
    else {
	printf("...done, allocated buffer at virtp %p\n", heap_ptr);
    }

    printf("Performing write-read test on CMA buffer...\n");
    for (i = 0; i < size; i++) {
	heap_ptr[i] = i % 256;
    }
    for (i = 0; i < size; i++) {
	if (heap_ptr[i] != (i % 256)) {
	    printf("write-read error: read 0x%x, should be 0x%x\n",
	           heap_ptr[i], i % 256);
	    if (non_interactive_flag == FALSE) {
		printf("Press ENTER to continue\n");
		getchar();
	    }
	    break;
	}
    }
    if (i == size) {
	if (non_interactive_flag == FALSE) {
	    printf("...succeeded, press ENTER to continue\n");
	    getchar();
	}	    
	else {
	    printf("...succeeded\n");
	}
    }

    printf("calling CMEM_cacheInv(heap_ptr, size)...\n");
    CMEM_cacheInv(heap_ptr, size);
    printf("...done\n");

    printf("freeing heap buffer...\n");
    rv = CMEM_free(heap_ptr, &params);
    if (rv < 0) {
	printf("error freeing buffer\n");
    }
    printf("...done\n");

    return 0;
}
Esempio n. 5
0
void common_delete_native_pixmap(
			NATIVE_PIXMAP_STRUCT *pNativePixmap)
{
#ifdef _ENABLE_CMEM
	if(!pNativePixmap) return;
	if(pNativePixmap->lAddress)
		CMEM_free((void*)pNativePixmap->lAddress, NULL);
	//delete the pixmap itself
	free(pNativePixmap);
#endif //ENABLE_CMEM
}
Esempio n. 6
0
/*
 *  ======== _ALG_freeMemory ========
 */
Void _ALG1_freeMemory(IALG_MemRec memTab[], Int n)
{
    Int i;

    for (i = 0; i < n; i++) {
        if (memTab[i].base != NULL) {
            CMEM_free(memTab[i].base, &memParams);

        }
    }
}
XDAS_Int32 BUFFMGR_Init(XDAS_Int32 totBufSize)
{
    XDAS_UInt32 tmpCnt;
/* Memory allocation params required in linux */
        CMEM_AllocParams memParams;

        /* Allocation params */
        memParams.type=CMEM_POOL;
        memParams.flags=CMEM_CACHED;
        memParams.alignment=256;
    /* total buffer size allocatable is divided into three parts one part goes
     * to luma buffers and the other two parts go to luma buffers */
    chromaGlobalBufferSize = (totBufSize/3);
    lumaGlobalBufferSize = (chromaGlobalBufferSize*2);

    if(lumaGlobalBufferHandle == NULL)
    {
    /* Allocate the global buffers */
    lumaGlobalBufferHandle = CMEM_alloc(lumaGlobalBufferSize, &memParams);
    if(lumaGlobalBufferHandle == NULL)
    {
        return -1;
    }
    chromaGlobalBufferHandle = CMEM_alloc(chromaGlobalBufferSize, &memParams);
    if(chromaGlobalBufferHandle == NULL)
    {
        CMEM_free(lumaGlobalBufferHandle,&memParams);
        return -1;
    }
    }
    memset(lumaGlobalBufferHandle, 0x66, lumaGlobalBufferSize);
    memset(chromaGlobalBufferHandle, 0x66, chromaGlobalBufferSize);
    /* Initialise the elements in the global buffer array */
    for(tmpCnt = 0; tmpCnt < MAX_BUFF_ELEMENTS; tmpCnt++)
    {
        buffArray[tmpCnt].bufId = tmpCnt+1;
        buffArray[tmpCnt].bufStatus = BUFFMGR_BUFFER_FREE;
        buffArray[tmpCnt].bufSize[1] = 0;
        buffArray[tmpCnt].bufSize[0] = 0;
        buffArray[tmpCnt].buf[1] = NULL;
        buffArray[tmpCnt].buf[0] = NULL;
    }

    /* Initialise the entire buffer space to first frame and
     * re-modify buffer sizes as per the picture frame sizes
     * after first frame decode */
     buffArray[0].buf[1] = chromaGlobalBufferHandle;
     buffArray[0].bufSize[1] = chromaGlobalBufferSize;
     buffArray[0].buf[0] = lumaGlobalBufferHandle;
     buffArray[0].bufSize[0] = lumaGlobalBufferSize;
     return 0;
}
Esempio n. 8
0
/*****************************************************************************
 Prototype    : display_buf_free
 Description  : free mem allocated
 Input        : DisplayHanlde hDisplay  
 Output       : None
 Return Value : static
 Calls        : 
 Called By    : 
 
  History        :
  1.Date         : 2012/8/28
    Author       : Sun
    Modification : Created function

*****************************************************************************/
static Int32 display_buf_free(DisplayHanlde hDisplay)
{
	Int32 i;
	
	for(i = 0; i < DISPLAY_BUF_NUM; i++) {
		if(hDisplay->displayBuf[i].userAddr) {
			CMEM_free(hDisplay->displayBuf[i].userAddr, &hDisplay->memAllocParams);
			hDisplay->displayBuf[i].userAddr = NULL;
		}
	}

	return E_NO;
}
Esempio n. 9
0
/*
 *  ======== _ALG_freeMemory ========
 */
Void _ALG1_freeMemory(IALG_MemRec memTab[], Int n)
{
    Int i;

    for (i = 0; i < n; i++) {
        if (memTab[i].base != NULL) {
#ifdef ON_LINUX
            CMEM_free(memTab[i].base, &memParams);
#else
            myFree(memTab[i].base);
#endif
        }
    }
}
Esempio n. 10
0
static Bool contigFree(Ptr addr, UInt size, Int type)
{
    Bool retVal = FALSE;
    CMEM_AllocParams cmemParams;

    Log_print2(Diags_ENTRY, "[+E] Memory_contigFree> Enter(addr=0x%x, size=0x%x)",
            (IArg)addr, (IArg)size);

    if (!cmemInitialized) {
        return (FALSE);
    }

    Lock_acquire( moduleLock );

    if (removeContigBuf((UInt32)addr, size) >= 0) {
        /* CMEM_free uses just the 'type' param */
        cmemParams.type = type;
        if (CMEM_free(addr, &cmemParams) == 0) {
            retVal = TRUE;
        }
        else {
        Log_print1(Diags_USER6, "[+6] Memory_contigFree> "
                "Warning: CMEM_free(0x%x) failed", (IArg)addr);
        }
    }
    else {
        Log_print2(Diags_USER7, "[+7] Memory_contigFree> "
                  "ERROR: buffer (addr=0x%x, size=0x%x) not found in "
                  "translation cache\n",
                  (IArg)addr, (IArg)size);
    }

    Lock_release(moduleLock);

    Log_print1(Diags_EXIT, "[+X] Memory_contigFree> return (0x%x)",
            (IArg)retVal);

    return (retVal);

}
Esempio n. 11
0
void testCache(int size, int block)
{
    unsigned int *ptr1_nocache = NULL;
    unsigned int *ptr1_cache = NULL;
    unsigned int *ptr1_dma = NULL;
    unsigned int *ptr2 = NULL;
    unsigned long physp;
    unsigned long physp_dma;
    unsigned long physp_nocache;
    unsigned long physp_cache;
    int poolid;
    int i, j;
    struct timeval start_tv, end_tv;
    unsigned long diff;
    int foo, bar;
    CMEM_AllocParams params;

    printf("Allocating first noncached buffer.\n");

    /* First allocate a buffer from the pool that best fits */
    ptr1_nocache = CMEM_alloc(size, NULL);

    if (ptr1_nocache == NULL) {
        fprintf(stderr, "Failed to allocate buffer of size %d\n", size);
        goto cleanup;
    }

    printf("Allocated buffer of size %d at address %#x.\n", size,
           (unsigned int) ptr1_nocache);

    /* Find out and print the physical address of this buffer */
    physp_nocache = CMEM_getPhys(ptr1_nocache);

    if (physp_nocache == 0) {
        fprintf(stderr, "Failed to get physical address of buffer %#x\n",
                (unsigned int) ptr1_nocache);
        goto cleanup;
    }

    printf("Physical address of allocated buffer is %#x.\n",
           (unsigned int) physp_nocache);

    /* Write some data into this buffer */
    for (i=0; i < size / sizeof(int) ; i++) {
        ptr1_nocache[i] = 0xbeefbeef;
    }

    printf("Allocating first cached buffer.\n");

    /* First allocate a buffer from the pool that best fits */
    params = CMEM_DEFAULTPARAMS;
    params.flags = CMEM_CACHED;
    ptr1_cache = CMEM_alloc2(block, size, &params);

    if (ptr1_cache == NULL) {
        fprintf(stderr, "Failed to allocate buffer of size %d\n", size);
        goto cleanup;
    }

    printf("Allocated buffer of size %d at address %#x.\n", size,
           (unsigned int) ptr1_cache);

    /* Find out and print the physical address of this buffer */
    physp_cache = CMEM_getPhys(ptr1_cache);

    if (physp_cache == 0) {
        fprintf(stderr, "Failed to get physical address of buffer %#x\n",
                (unsigned int) ptr1_cache);
        goto cleanup;
    }

    printf("Physical address of allocated buffer is %#x.\n",
           (unsigned int) physp_cache);

    /* Write some data into this buffer */
    for (i = 0; i < size / sizeof(int); i++) {
        ptr1_cache[i] = 0x0dead1ce;
    }

    printf("Allocating noncached DMA source buffer.\n");

    /* Allocate a noncached buffer for the DMA source */
    ptr1_dma = CMEM_alloc(size, NULL);

    if (ptr1_dma == NULL) {
        fprintf(stderr, "Failed to allocate buffer of size %d\n", size);
        goto cleanup;
    }

    printf("Allocated buffer of size %d at address %#x.\n", size,
           (unsigned int) ptr1_dma);

    /* Find out and print the physical address of this buffer */
    physp_dma = CMEM_getPhys(ptr1_dma);

    if (physp_dma == 0) {
        fprintf(stderr, "Failed to get physical address of buffer %#x\n",
                (unsigned int) ptr1_dma);
        goto cleanup;
    }

    printf("Physical address of allocated buffer is %#x.\n",
           (unsigned int) physp_dma);

    /* Initialize DMA source buffer */
    for (i = 0; i < size / sizeof(int); i++) {
        ptr1_cache[i] = 0x0dead1ce;
    }

    /*
     * Measure the write performance of each buffer to check that one
     * is cached and the other isn't.
     */
    printf("Measuring R-M-W performance (cached should be quicker).\n");
    for (j = 0; j < 3; j++) {
        printf("R-M-W noncached buffer %lx\n", physp_nocache);
        gettimeofday(&start_tv, NULL);
        for (i = 0; i < (size / sizeof(int)); i += 1) {
            ptr1_nocache[i] += 1;
        }
        gettimeofday(&end_tv, NULL);
        diff = end_tv.tv_usec - start_tv.tv_usec;
        if (end_tv.tv_sec > start_tv.tv_sec) {
            diff += (end_tv.tv_sec - start_tv.tv_sec) * 1000000;
        }
        printf("  diff=%ld\n", diff);

        printf("R-M-W cached buffer %lx\n", physp_cache);
        gettimeofday(&start_tv, NULL);
        for (i = 0; i < (size / sizeof(int)); i += 1) {
            ptr1_cache[i] += 1;
        }
        gettimeofday(&end_tv, NULL);
        diff = end_tv.tv_usec - start_tv.tv_usec;
        if (end_tv.tv_sec > start_tv.tv_sec) {
            diff += (end_tv.tv_sec - start_tv.tv_sec) * 1000000;
        }
        printf("  diff=%ld\n", diff);
    }

    printf("Invalidate cached buffer %p\n", ptr1_cache);

    foo = *ptr1_cache;
    bar = foo;
    bar++;
    *ptr1_cache = bar;
    CMEM_cacheInv(ptr1_cache, size);
    printf("post-flush *ptr1_cache=0x%x\n", foo);
    printf("wrote 0x%x to *ptr1_cache\n", bar);
    printf("post-inv *ptr1_cache=0x%x\n", *ptr1_cache);

    printf("R-M-W cached buffer %lx\n", physp_cache);
    gettimeofday(&start_tv, NULL);
    for (i = 0; i < (size / sizeof(int)); i += 1) {
        ptr1_cache[i] += 1;
    }
    gettimeofday(&end_tv, NULL);
    diff = end_tv.tv_usec - start_tv.tv_usec;
    if (end_tv.tv_sec > start_tv.tv_sec) {
        diff += (end_tv.tv_sec - start_tv.tv_sec) * 1000000;
    }
    printf("  diff=%ld\n", diff);

    /* 
     * Now allocate another buffer by first finding out which pool that fits
     * best, and then explicitly allocating from that pool. This gives more
     * control at the cost of an extra function call, but essentially does
     * the same thing as the above CMEM_alloc() call.
     */
    printf("Allocating second buffer.\n");

    poolid = CMEM_getPool(size);

    if (poolid == -1) {
        fprintf(stderr, "Failed to get a pool which fits size %d\n", size);
        goto cleanup;
    }

    printf("Got a pool (%d) that fits the size %d\n", poolid, size);

    ptr2 = CMEM_allocPool(poolid, NULL);

    if (ptr2 == NULL) {
        fprintf(stderr, "Failed to allocate buffer of size %d\n", size);
        goto cleanup;
    }

    printf("Allocated buffer of size %d at address %#x.\n", size,
           (unsigned int) ptr2);

    /* Find out and print the physical address of this buffer */
    physp = CMEM_getPhys(ptr2);

    if (physp == 0) {
        fprintf(stderr, "Failed to get physical address of buffer %#x\n",
                (unsigned int) ptr2);
        goto cleanup;
    }

    printf("Physical address of allocated buffer is %#x.\n",
           (unsigned int) physp);

    /* Write some data into this buffer */
    for (i=0; i < size / sizeof(int); i++) {
        ptr2[i] = 0xfeebfeeb;
    }

    printf("Inspect your memory map in /proc/%d/maps.\n", getpid());
    printf("Also look at your pool info under /proc/cmem\n");
    printf("Press ENTER to exit (after 'cat /proc/cmem' if desired).\n");
    getchar();

cleanup:
    if (ptr1_nocache != NULL) {
        if (CMEM_free(ptr1_nocache, NULL) < 0) {
            fprintf(stderr, "Failed to free buffer at %#x\n",
                    (unsigned int) ptr1_nocache);
        }
        printf("Successfully freed buffer at %#x.\n",
               (unsigned int) ptr1_nocache);
    }

    if (ptr1_cache != NULL) {
        if (CMEM_free(ptr1_cache, &params) < 0) {
            fprintf(stderr, "Failed to free buffer at %#x\n",
                    (unsigned int) ptr1_cache);
        }
        printf("Successfully freed buffer at %#x.\n",
               (unsigned int) ptr1_cache);
    }

    if (ptr1_dma != NULL) {
        if (CMEM_free(ptr1_dma, NULL) < 0) {
            fprintf(stderr, "Failed to free buffer at %#x\n",
                    (unsigned int) ptr1_dma);
        }
        printf("Successfully freed buffer at %#x.\n",
               (unsigned int) ptr1_dma);
    }

    if (ptr2 != NULL) {
        if (CMEM_free(ptr2, NULL) < 0) {
            fprintf(stderr, "Failed to free buffer at %#x\n",
                    (unsigned int) ptr2);
        }
        printf("Successfully freed buffer at %#x.\n",
               (unsigned int) ptr2);
    }
}
Esempio n. 12
0
int CMEM_unregister(void *ptr, CMEM_AllocParams *params)
{
    __D("unregister: delegating to CMEM_free()...\n");

    return CMEM_free(ptr, params);
}
Esempio n. 13
0
static int save_image(const AVPicture *picture, enum PixelFormat pix_fmt,
        int width, int height, const char *filename)
{
    AVCodec *codec;
    AVCodecContext *avctx;
    AVFrame *tmp_picture;
    uint8_t *outbuf;
    int outbuf_size;
    int size;
    FILE *f;

    avctx = avcodec_alloc_context();

    avctx->codec_id = CODEC_ID_BMP;
    avctx->codec_type = AVMEDIA_TYPE_VIDEO;
    avctx->width = width;
    avctx->height = height;
    avctx->pix_fmt = PIX_FMT_BGR24;
    avctx->time_base = (AVRational) {1, 1};

    codec = avcodec_find_encoder(avctx->codec_id);
    if (!codec) {
        fprintf(stderr, "codec not found\n");
        return -1;
    }

    /* open the codec */
    if (avcodec_open(avctx, codec) < 0) {
        fprintf(stderr, "could not open codec\n");
        return -1;
    }

    if (pix_fmt != PIX_FMT_BGR24) {
        struct SwsContext *sctx;

        tmp_picture = alloc_picture(PIX_FMT_BGR24, avctx->width, avctx->height);
        if (!tmp_picture)
            return -1;

        sctx = sws_getContext(avctx->width, avctx->height, pix_fmt,
                avctx->width, avctx->height, PIX_FMT_BGR24,
                SWS_POINT, NULL, NULL, NULL);

        sws_scale(sctx, (const uint8_t * const *) picture->data, picture->linesize,
                0, avctx->height, tmp_picture->data, tmp_picture->linesize);
    } else {
        tmp_picture = (AVFrame *)picture;
    }

    outbuf_size = 6*1024*1024;
    outbuf = av_malloc(outbuf_size);
    if (!outbuf)
        return AVERROR(ENOMEM);

    f = fopen(filename, "wb");
    size = avcodec_encode_video(avctx, outbuf, outbuf_size, tmp_picture);
    fwrite(outbuf, sizeof(uint8_t), size, f);
    fclose(f);

    if (pix_fmt != PIX_FMT_BGR24) {
        CMEM_free(tmp_picture->data[0], &alloc_params);
    }
    av_free(tmp_picture);
    av_free(outbuf);
    av_free(avctx);

    return 0;
}
Esempio n. 14
0
/*
 *  ======== contigAlloc ========
 */
static Ptr contigAlloc(UInt size, UInt align, Bool cacheable, Bool heap)
{
    Ptr    addr = NULL;
    UInt32 physAddr;
    CMEM_AllocParams cmemParams;

    /* lock acquire should be after the trace, but it's unlikely to fail
     * and we get a more consistent/less confusing output this way.
     */
    Lock_acquire(moduleLock);

    Log_print4(Diags_ENTRY, "[+E] Memory_contigAlloc> "
            "Enter(size=0x%x, align=0x%x, cached=%s, heap=%s)", (IArg)size,
            (IArg)align, (IArg)(cacheable ? "TRUE" : "FALSE"),
            (IArg)(heap ? "TRUE" : "FALSE"));

    if (!cmemInitialized) {
        Log_print1(Diags_USER7, "[+7] Memory_contigAlloc> "
                "ERROR: request for size=0x%x failed -- CMEM has not been "
                "initialized.", (IArg)size);
        goto contigAlloc_return;
    }

    if (!heap && (Int)align > CMEMPOOLALIGN) {
        Log_print2(Diags_USER6, "[+6] Memory_contigAlloc> "
                "Warning: alignment %#x not supported for pool-based allocations,"
                " using fixed alignment %#x.",
                (IArg)align, (IArg)CMEMPOOLALIGN);
        /* align is not used for pool-based allocs, but set it anyway */
        align = CMEMPOOLALIGN;
    }

    cmemParams.type = heap ? CMEM_HEAP : CMEM_POOL;
    cmemParams.flags = cacheable ? CMEM_CACHED : CMEM_NONCACHED;
    cmemParams.alignment = align;
    addr = CMEM_alloc(size, &cmemParams);

    Log_print2(Diags_USER4, "[+4] Memory_contigAlloc> CMEM_alloc(0x%x) = 0x%x.",
            (IArg)size, (IArg)addr);

    if (addr != NULL) {

        /* since the allocation succeeded, get physical address now and add the
         * description for this buffer in our list of contiguous buffers.
         */
        physAddr = CMEM_getPhys(addr);
        if (physAddr != 0) {
            Log_print2(Diags_USER4, "[+4] Memory_contigAlloc> "
                    "CMEM_getPhys(0x%x) = 0x%x.", (IArg)addr, (IArg)physAddr);
            addContigBuf((Uint32)addr, size, physAddr);
        } else {
            Log_print1(Diags_USER7, "[+7] Memory_contigAlloc> "
                    "ERROR: CMEM_getPhys(0x%x) (virt-to-phys) failed; "
                    "releasing the block.", (IArg)addr);
            CMEM_free(addr, &cmemParams);
            addr = NULL;
        }
    } else {
        Log_print0(Diags_USER7, "[+7] Memory_contigAlloc> "
                "ERROR: CMEM alloc failed");
    }

contigAlloc_return:

    Log_print1(Diags_EXIT, "[+X] Memory_contigAlloc> return (0x%x)",
            (IArg)addr);

    Lock_release(moduleLock);

    return addr;
}
Esempio n. 15
0
int testMap(size_t size)
{
    unsigned int *ptr;
    unsigned int *map_ptr;
#if defined(LINUXUTILS_BUILDOS_ANDROID)
    off64_t physp;
#else
    off_t physp;
#endif
    int ret = 0;

    ptr = CMEM_alloc(size, NULL);
    printf("testMap: ptr = %p\n", ptr);

    if (ptr == NULL) {
	printf("testMap: CMEM_alloc() failed\n");
	return 1;
    }

    printf("    writing 0xdadaface to *ptr\n");
    *ptr = 0xdadaface;

#if defined(LINUXUTILS_BUILDOS_ANDROID)
    physp = CMEM_getPhys64(ptr);
    map_ptr = CMEM_map64(physp, size);
#else
    physp = CMEM_getPhys(ptr);
    map_ptr = CMEM_map(physp, size);
#endif
    if (map_ptr == NULL) {
	printf("testMap: CMEM_map() failed\n");
	ret = 1;
	goto cleanup;
    }
    else {
	printf("testMap: remapped physp %#llx to %p\n",
		physp, map_ptr);
	printf("    *map_ptr = 0x%x\n", *map_ptr);
    }

    if (*map_ptr != 0xdadaface) {
	printf("testMap: failed, read didn't match write\n");
	ret = 1;
    }

    CMEM_unmap(map_ptr, size);

    if (*ptr != 0xdadaface) {
	printf("testMap: after unmap *ptr != 0xdadaface\n");
	ret = 1;
	goto cleanup;
    }
    else {
	printf("testMap: original pointer still good\n");
    }

    printf("testMap: trying to map too much (0x%x)...\n", size * 0x10);
#if defined(LINUXUTILS_BUILDOS_ANDROID)
    map_ptr = CMEM_map64(physp, size * 0x10);
#else
    map_ptr = CMEM_map(physp, size * 0x10);
#endif
    if (map_ptr != NULL) {
	printf("testMap: CMEM_map() should've failed but didn't\n");
	CMEM_unmap(map_ptr, size * 0x10);
	ret = 1;
    }

cleanup:
    CMEM_free(ptr, NULL);

    return ret;
}
Esempio n. 16
0
int main(int argc, char *argv[])
{
    unsigned int *ptr = NULL;
    pid_t newPid = 0;
    int pid = 0;
    int numProcesses;
    int r;
    int i;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <Number of processes to fork>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    numProcesses = atoi(argv[1]);

    for (i=0; i<numProcesses; i++) {
        newPid = fork(); 

        if (newPid == -1) {
            fprintf(stderr, "Failed to fork off new process\n");
            exit(EXIT_FAILURE);
        }
        else if (newPid == 0) {
            pid = i;
            break;
        }

        printf("Forked off process %d\n", newPid);
    }

    if (newPid != 0) {
        printf("Main process exiting\n");
        exit(EXIT_SUCCESS);
    }

    /* First initialize the CMEM module */
    if (CMEM_init() == -1) {
        fprintf(stderr, "Process %d: Failed to initialize CMEM\n", pid);
        exit(EXIT_FAILURE);
    }

    printf("Process %d: CMEM initialized.\n", pid);

    /* First allocate a buffer from the pool that best fits */
    ptr = CMEM_alloc(BUFFER_SIZE, NULL);

    if (ptr == NULL) {
        fprintf(stderr, "Process %d: Failed to allocate buffer of size %d\n",
                pid, BUFFER_SIZE);
        exit(EXIT_FAILURE);
    }

    printf("Process %d: Allocated buffer at %#x\n", pid, (unsigned int) ptr);

    /* Write some data into this buffer */
    for (i=0; i < BUFFER_SIZE / sizeof(int) ; i++) {
        ptr[i] = 0xbeefbeef;
    }

#if 0
    srand(pid * 1024);

    r = 1 + (int) (DELAYSPAN * (rand() / (RAND_MAX + 1.0)));
#else
    r = (pid * 3) + 3;
#endif

    printf("Process %d: Sleeping for %d seconds\n", pid, r);

    sleep(r);

    if (pid % 2) {
        printf("Process %d: Freeing buffer at %#x\n", pid, (unsigned int) ptr);

        if (CMEM_free(ptr, NULL) < 0) {
            fprintf(stderr, "Process %d: Failed to free buffer at %#x\n",
                    pid, (unsigned int) ptr);
        }
    }
    else {
        printf("Process %d: intentionally neglecting to call CMEM_free()\n",
               pid);
    }


    if (pid != 0) {
        printf("Process %d: Exiting CMEM\n", pid);
        if (CMEM_exit() < 0) {
            fprintf(stderr, "Process %d: Failed to finalize the CMEM module\n",
                    pid);
        }
    }
    else {
        printf("Process %d: sleeping 5 ...\n", pid);
        sleep(5);
        printf("Process %d: exiting, intentionally forgetting to call "
               "CMEM_exit()\n", pid);
    }

    exit(EXIT_SUCCESS);
}
int rebuild_jpg_config_para(jpeg_data_t  *jpeg_data,jpegdec_config_t *config)
{
	int ret = 0;
	if((scale_w*jpeg_data->info.height)!= (scale_h*jpeg_data->info.width)){
	    sMode =  IGNOREASPECTRATIO;   	        
    }else{
        sMode =  KEEPASPECTRATIO;   	 
    }
#ifdef JPEG_DBG    
    printf("current sMode is %d\n",sMode);	
#endif    
	switch(sMode){
	    case KEEPASPECTRATIO:
	    ret = compute_keep_ratio(jpeg_data,config);
	    break;
	    case IGNOREASPECTRATIO:
	    ret = compute_keep_ratio_by_expanding(jpeg_data,config);
	    if(ret < 0){
	        ret = compute_keep_ratio(jpeg_data,config);    
	    }
	    break;
	    case KEEPASPECTRATIOBYEXPANDING:
	    ret = compute_keep_ratio_by_expanding(jpeg_data,config);
	    if(ret < 0){
	        ret = compute_keep_ratio(jpeg_data,config);    
	    }
	    break;
	    default:
	    break;    
	}  
	if(config->dec_h<2) {
		printf("too small to decode with hwjpeg decoder.\n");
		return -1;
	}	
	config->canvas_width = CANVAS_ALIGNED(config->dec_w);	
	planes[0] = (unsigned char *)CMEM_alloc(0, 
				 config->canvas_width * config->dec_h, &cmemParm);
	planes[1] = (unsigned char *)CMEM_alloc(0,
				CANVAS_ALIGNED((config->canvas_width/2)) *config->dec_h/2, &cmemParm);
	planes[2] = (unsigned char *)CMEM_alloc(0,
				CANVAS_ALIGNED((config->canvas_width/2)) * config->dec_h/2, &cmemParm);
	if ((!planes[0]) || (!planes[1]) || (!planes[2])) {
		printf("Not enough memory\n");
		if (planes[0])
			CMEM_free(planes[0], &cmemParm);
		if (planes[1])
			CMEM_free(planes[1], &cmemParm);
		if (planes[2])
			CMEM_free(planes[2], &cmemParm);
		return -1;
	}
	config->addr_y = CMEM_getPhys(planes[0]);
	config->addr_u = CMEM_getPhys(planes[1]);
	config->addr_v = CMEM_getPhys(planes[2]);
	
	if(config->dec_w==0 ||config->dec_h==0)
	{
		config->dec_w= jpeg_data->info.width;
		config->dec_h= jpeg_data->info.height;
	}
//	scaleSize(config->dec_w, config->dec_h, jpeg_data->info.width, jpeg_data->info.height, (Qt::AspectRatioMode)config->opt);
	config->opt = 0;
	config->dec_x = 0;
	config->dec_y = 0;
	config->angle = CLKWISE_0;
	clear_plane(0,config);
	clear_plane(1,config);
	clear_plane(2,config);
	return 0;	
}