Exemplo n.º 1
0
static void ReleaseAllocMem(ALLOC_MEM_T *node, CODEC_MEM_CTX *CodecMem)
{
    FREE_MEM_T *free_node;
    BOOL        r;

    __try
    {
        printD("decommit CodecAddr\n");
        r = VirtualFreeEx(CodecMem->callerProcess,    // HANDLE hProcess
                          node->u_addr,
                          0,
                          MEM_RELEASE);
        if (r == FALSE)
        {
            RETAILMSG(1, (L"[%d][CMM_Close] CMM VirtualFreeEx returns FALSE.(u_addr : 0x%08x cacheFlag : %d callerprocess:%ld)\n", 
            CodecMem->inst_no, node->u_addr, node->cacheFlag, CodecMem->callerProcess));
        }

        free_node = (FREE_MEM_T    *)malloc(sizeof(FREE_MEM_T));
        free_node->startAddr = node->cached_p_addr;
        free_node->size = node->size;
        InsertNodeToFreeList(free_node, CodecMem->inst_no);

        // Delete from AllocMem list
        DeleteNodeFromAllocList(node, CodecMem->inst_no);
    }
    __except ( EXCEPTION_EXECUTE_HANDLER )
    {
        RETAILMSG( 1, ( _T("CMM ReleaseAllocMem exception occurred\n")) );
    }
}
Exemplo n.º 2
0
/*----------------------------------------------------------------------------
*Function: CMM_Init

*Parameters:         dwContext        :
*Return Value:        True/False
*Implementation Notes: Initialize JPEG Hardware 
-----------------------------------------------------------------------------*/
DWORD
CMM_Init(
    DWORD dwContext
    )
{
    HANDLE            h_Mutex;
    FREE_MEM_T *    freenode;
    ALLOC_MEM_T *   allocnode;
    PHYSICAL_ADDRESS    ioPhysicalBase = {0,0};

    printD("\n[CMM_Init]\n");

    
    // Mutex initialization
    h_Mutex = CreateCMMmutex();
    if (h_Mutex == NULL) 
    {
        RETAILMSG(1, (TEXT("[CMM_Init] CMM Mutex Initialize error : %d \r\n"),GetLastError()));    
        return FALSE;
    }

    ioPhysicalBase.LowPart = CODEC_MEM_START;
    CachedVirAddr = (UINT8 *)MmMapIoSpace(ioPhysicalBase, CODEC_MEM_SIZE, TRUE);
    if (CachedVirAddr == NULL)
    {
        RETAILMSG(1, (TEXT("[CMM_Init] MmMapIoSpace failed: %d\r\n"),GetLastError()));    
        return FALSE;
    }

    // init alloc list, if(AllocMemHead == AllocMemTail) then, the list is NULL
    allocnode = (ALLOC_MEM_T *)malloc(sizeof(ALLOC_MEM_T));
    memset(allocnode, 0x00, sizeof(ALLOC_MEM_T));
    allocnode->next = allocnode;
    allocnode->prev = allocnode;
    AllocMemHead = allocnode;
    AllocMemTail = AllocMemHead;

    // init free list, if(FreeMemHead == FreeMemTail) then, the list is NULL
    freenode = (FREE_MEM_T *)malloc(sizeof(FREE_MEM_T));
    memset(freenode, 0x00, sizeof(FREE_MEM_T));
    freenode->next = freenode;
    freenode->prev = freenode;
    FreeMemHead = freenode;
    FreeMemTail = FreeMemHead;

    freenode = (FREE_MEM_T *)malloc(sizeof(FREE_MEM_T));
    memset(freenode, 0x00, sizeof(FREE_MEM_T));
    freenode->startAddr = CODEC_MEM_START;
    freenode->size = CODEC_MEM_SIZE;
    InsertNodeToFreeList(freenode, -1);

    return TRUE;
}
Exemplo n.º 3
0
// Releae cacheable memory
static void ReleaseAllocMem(ALLOC_MEM_T *node, CODEC_MEM_CTX *CodecMem)
{
	FREE_MEM_T *free_node;
	

	free_node = (FREE_MEM_T	*)kmalloc(sizeof(FREE_MEM_T), GFP_KERNEL);

	if(node->cacheFlag) {
		free_node->startAddr = node->cached_p_addr;
		free_node->cacheFlag = 1;
	}
	else {
		free_node->startAddr = node->uncached_p_addr;
		free_node->cacheFlag = 0;
	}
	
	free_node->size = node->size;
	InsertNodeToFreeList(free_node, CodecMem->inst_no);
	
	// Delete from AllocMem list
	DeleteNodeFromAllocList(node, CodecMem->inst_no);
}
Exemplo n.º 4
0
static int __init s3c_cmm_init(void)
{
	HANDLE 		h_Mutex;
	int			ret;
	FREE_MEM_T	*node;
	ALLOC_MEM_T	*alloc_node;
	
	
	printk(banner);

	// Mutex initialization
	h_Mutex = CreateCMMmutex();
	if (h_Mutex == NULL) 
	{
		LOG_MSG(LOG_ERROR, "s3c_cmm_init", "DD::CMM Mutex Initialize error\r\n");
		return FALSE;
	}

	ret = LockCMMMutex();

	ret = misc_register(&s3c_cmm_miscdev);


	// First 4MB will use cacheable memory
	CachedVirAddr = (unsigned char *)ioremap_cached( (unsigned long)CODEC_MEM_START, 		\
					(int)CODEC_CACHED_MEM_SIZE );

	// Second 4MB will use non-cacheable memory
	NonCachedVirAddr = (unsigned char *)ioremap_nocache( (unsigned long)(CODEC_MEM_START + 	\
					CODEC_CACHED_MEM_SIZE), (int)CODEC_NON_CACHED_MEM_SIZE );

	// init alloc list, if(AllocMemHead == AllocMemTail) then, the list is NULL
	alloc_node = (ALLOC_MEM_T *)kmalloc(sizeof(ALLOC_MEM_T), GFP_KERNEL);
	memset(alloc_node, 0x00, sizeof(ALLOC_MEM_T));
	alloc_node->next = alloc_node;
	alloc_node->prev = alloc_node;
	AllocMemHead = alloc_node;
	AllocMemTail = AllocMemHead;

	// init free list, if(FreeMemHead == FreeMemTail) then, the list is NULL
	node = (FREE_MEM_T *)kmalloc(sizeof(FREE_MEM_T), GFP_KERNEL);
	memset(node, 0x00, sizeof(FREE_MEM_T));
	node->next = node;
	node->prev = node;
	FreeMemHead = node;
	FreeMemTail = FreeMemHead;

	node = (FREE_MEM_T *)kmalloc(sizeof(FREE_MEM_T), GFP_KERNEL);
	memset(node, 0x00, sizeof(FREE_MEM_T));
	node->startAddr = CODEC_MEM_START;
	node->cacheFlag = 1;
	node->size = CODEC_CACHED_MEM_SIZE;
	InsertNodeToFreeList(node, -1);

	node = (FREE_MEM_T *)kmalloc(sizeof(FREE_MEM_T), GFP_KERNEL);
	memset(node, 0x00, sizeof(FREE_MEM_T));
	node->startAddr = CODEC_MEM_START + CODEC_CACHED_MEM_SIZE;
	node->cacheFlag = 0;
	node->size = CODEC_NON_CACHED_MEM_SIZE;
	InsertNodeToFreeList(node, -1);

	UnlockCMMMutex();

	return 0;
}