diff options
Diffstat (limited to 'vmeta_lib.c')
-rwxr-xr-x | vmeta_lib.c | 128 |
1 files changed, 82 insertions, 46 deletions
diff --git a/vmeta_lib.c b/vmeta_lib.c index 57f3702..b7a8c5f 100755 --- a/vmeta_lib.c +++ b/vmeta_lib.c @@ -117,7 +117,7 @@ void vdec_os_api_wr32(UNSG32 addr, UNSG32 data) UNSG32 vdec_os_api_get_regbase_addr(void) { vdec_os_driver_cb_t *vdec_iface = vdec_driver_get_cb(); - return vdec_iface->io_mem_virt_addr; + return (UNSG32) vdec_iface->io_mem_virt_addr; } //End of hal mmap @@ -152,7 +152,7 @@ void *vdec_os_api_vmalloc(UNSG32 size, UNSG32 align) size += align; ptr = malloc(size); if (!ptr) { - printf("\tno enough memory\n"); + dbg_printf(VDEC_DEBUG_MEM, "vdec_os_api_vmalloc not enough memory \n"); return NULL; } @@ -190,7 +190,7 @@ void * vdec_os_api_dma_alloc(UNSG32 size, UNSG32 align, UNSG32 * pPhysical) size += align; ptr = bmm_malloc(size, BMM_ATTR_NONCACHED); if (!ptr) { - printf("\tno enough memory\n"); + dbg_printf(VDEC_DEBUG_MEM, "vdec_os_api_vmalloc not enough memory \n"); return NULL; } @@ -202,7 +202,6 @@ void * vdec_os_api_dma_alloc(UNSG32 size, UNSG32 align, UNSG32 * pPhysical) *pPhysical = (unsigned long)bmm_get_paddr(ptr); dbg_printf(VDEC_DEBUG_MEM, "vdec_os_api_dma_alloc ptr: 0x%x\n", ptr); - //memset(ptr, 0, size); return ptr; } @@ -221,7 +220,7 @@ void * vdec_os_api_dma_alloc_cached(UNSG32 size, UNSG32 align, UNSG32 * pPhysica size += align; ptr = bmm_malloc(size, BMM_ATTR_DEFAULT); if (!ptr) { - printf("\tno enough memory\n"); + dbg_printf(VDEC_DEBUG_MEM,"\tno enough memory\n"); return NULL; } @@ -233,7 +232,7 @@ void * vdec_os_api_dma_alloc_cached(UNSG32 size, UNSG32 align, UNSG32 * pPhysica *pPhysical = (unsigned long)bmm_get_paddr(ptr); dbg_printf(VDEC_DEBUG_MEM, "vdec_os_api_dma_alloc_cached ptr: 0x%x\n", ptr); - //memset(ptr, 0, size); + return ptr; } @@ -251,7 +250,7 @@ void * vdec_os_api_dma_alloc_writecombine(UNSG32 size, UNSG32 align, UNSG32 * pP size += align; ptr = bmm_malloc(size, BMM_ATTR_WRITECOMBINE); if (!ptr) { - printf("\tno enough memory\n"); + dbg_printf(VDEC_DEBUG_MEM, "\tno enough memory\n"); return NULL; } tmp = (unsigned int)((unsigned int)(ptr) & (align - 1)); @@ -262,7 +261,7 @@ void * vdec_os_api_dma_alloc_writecombine(UNSG32 size, UNSG32 align, UNSG32 * pP *pPhysical = (unsigned long)bmm_get_paddr(ptr); dbg_printf(VDEC_DEBUG_MEM, "vdec_os_api_dma_alloc_writecombine ptr: 0x%x\n", ptr); - //memset(ptr, 0, size); + return ptr; } @@ -470,7 +469,7 @@ SIGN32 vdec_os_driver_init(void) dbg_printf(VDEC_DEBUG_MEM, "vdec os driver io mem phy addr: 0x%x\n", vdec_iface->io_mem_phy_addr); // mmap the io mem area - vdec_iface->io_mem_virt_addr = (SIGN32)mmap(NULL, vdec_iface->io_mem_size, + vdec_iface->io_mem_virt_addr = (SIGN32) mmap(NULL, vdec_iface->io_mem_size, PROT_READ|PROT_WRITE, MAP_SHARED, vdec_iface->uiofd, 0); if(vdec_iface->io_mem_virt_addr == -1) { @@ -523,8 +522,21 @@ SIGN32 vdec_os_driver_clean(void) // unmap memory area if(vdec_iface->io_mem_virt_addr > 0) { - munmap((void*)vdec_iface->io_mem_virt_addr, vdec_iface->io_mem_size); dbg_printf(VDEC_DEBUG_MEM, "munmap with io_mem_virt_addr = 0x%x\n", vdec_iface->io_mem_virt_addr); + munmap((void*)vdec_iface->io_mem_virt_addr, vdec_iface->io_mem_size); + vdec_iface->io_mem_virt_addr = vdec_iface->io_mem_size = 0; + } + + if(vdec_iface->kernel_share_va > 0) { + dbg_printf(VDEC_DEBUG_MEM, "munmap with kernel_share_va = 0x%x size=%d\n", vdec_iface->kernel_share_va,vdec_iface->kernel_share_size); + munmap((void*)vdec_iface->kernel_share_va, vdec_iface->kernel_share_size); + vdec_iface->kernel_share_va = vdec_iface->kernel_share_size = 0; + } + + if(vdec_iface->vdec_obj_va > 0) { + dbg_printf(VDEC_DEBUG_MEM, "munmap with vdec_obj_va = 0x%x size=%d\n", vdec_iface->vdec_obj_va, vdec_iface->vdec_obj_size); + munmap((void*)vdec_iface->vdec_obj_va,vdec_iface->vdec_obj_size ); + vdec_iface->vdec_obj_va = vdec_iface->vdec_obj_size = 0; } // close fd @@ -597,12 +609,13 @@ SIGN32 vdec_os_api_get_hw_obj_addr(UNSG32* vaddr,UNSG32 size) { UNSG32 io_mem_size; UNSG32 io_mem_addr; - UNSG32 io_mem_virt_addr; + SIGN32 io_mem_virt_addr; UNSG32 ret = VDEC_OS_DRIVER_OK; - if(vdec_iface->vdec_obj_va != 0) + if(vdec_iface->vdec_obj_va > 0) { dbg_printf(VDEC_DEBUG_MEM, "Already get vdec obj\n"); + return VDEC_OS_DRIVER_OK; } io_mem_size = get_mem_size(UIO_IO_VMETA_OBJ_SIZE); @@ -623,10 +636,11 @@ SIGN32 vdec_os_api_get_hw_obj_addr(UNSG32* vaddr,UNSG32 size) goto get_vdec_obj_fail; } - dbg_printf(VDEC_DEBUG_MEM, "UIO_IO_VMETA_OBJ_ADDR virtual 0x%x\n", io_mem_virt_addr); + dbg_printf(VDEC_DEBUG_MEM, "UIO_IO_VMETA_OBJ_ADDR virtual 0x%x size=%d \n", io_mem_virt_addr,io_mem_size); *vaddr = io_mem_virt_addr; - vdec_iface->vdec_obj_va = (UNSG32)io_mem_virt_addr; + vdec_iface->vdec_obj_va = io_mem_virt_addr; + vdec_iface->vdec_obj_size = size; get_vdec_obj_fail: return ret; @@ -643,7 +657,9 @@ SIGN32 vdec_os_api_get_hw_context_addr(UNSG32* paddr, UNSG32* vaddr, UNSG32 size if(vdec_iface->hw_context_pa != 0) { dbg_printf(VDEC_DEBUG_MEM, "Already get hw context\n"); + return VDEC_OS_DRIVER_OK; } + io_mem_size = get_mem_size(UIO_IO_HW_CONTEXT_SIZE); if(io_mem_size <= 0 || io_mem_size < size) { ret = -VDEC_OS_DRIVER_MMAP_FAIL; @@ -675,7 +691,7 @@ SIGN32 vdec_os_api_get_ks(kernel_share** pp_ks) { UNSG32 io_mem_size; UNSG32 io_mem_addr; - UNSG32 io_mem_virt_addr; + SIGN32 io_mem_virt_addr; UNSG32 ret = VDEC_OS_DRIVER_OK; @@ -693,7 +709,7 @@ SIGN32 vdec_os_api_get_ks(kernel_share** pp_ks) } dbg_printf(VDEC_DEBUG_MEM, "vdec_os_api_get_ks: get_mem_size io_mem_size=%d\n",io_mem_size); - io_mem_virt_addr = (UNSG32)mmap(NULL, io_mem_size, \ + io_mem_virt_addr = (SIGN32)mmap(NULL, io_mem_size, \ PROT_READ|PROT_WRITE, MAP_SHARED, vdec_iface->uiofd, \ UIO_IO_KERNEL_SHARE_INDEX*getpagesize()); if(io_mem_virt_addr == -1) { @@ -702,10 +718,11 @@ SIGN32 vdec_os_api_get_ks(kernel_share** pp_ks) goto get_vos_fail; } - dbg_printf(VDEC_DEBUG_MEM, "kernel share virtual address: 0x%x\n", io_mem_virt_addr); + dbg_printf(VDEC_DEBUG_MEM, "kernel share virtual address: 0x%x size=%d \n", io_mem_virt_addr,io_mem_size); *pp_ks = (kernel_share *)io_mem_virt_addr; - vdec_iface->kernel_share_va = io_mem_virt_addr; + vdec_iface->kernel_share_va = (UNSG32)io_mem_virt_addr; + vdec_iface->kernel_share_size = io_mem_size; get_vos_fail: return ret; @@ -781,12 +798,12 @@ SIGN32 vdec_os_api_free_user_id(SIGN32 user_id) if(p_cb->kernel_share_va==0) { - printf("vdec_os_api_free_user_id error: not init yet\n"); + dbg_printf(VDEC_DEBUG_ALL,"vdec_os_api_free_user_id error: not init yet\n"); return VDEC_OS_DRIVER_USER_ID_FAIL; } if(user_id >= MAX_VMETA_INSTANCE || user_id < 0) { - printf("vdec_os_api_free_user_id error: exceeds max user_id\n"); + dbg_printf(VDEC_DEBUG_ALL,"vdec_os_api_free_user_id error: exceeds max user_id\n"); return VDEC_OS_DRIVER_USER_ID_FAIL; } p_ks = (kernel_share *)p_cb->kernel_share_va; @@ -810,15 +827,21 @@ int vmeta_thread_monitor(struct monitor_data * pmd) int detach_attr; struct monitor_data *p_md = NULL; + pthread_mutex_lock(&pmt); + if(p_cb->kernel_share_va==0 || pmd == NULL) { - printf("vdec_os_api_free_user_id error: not init yet\n"); + dbg_printf(VDEC_DEBUG_ALL,"vdec_os_api_free_user_id error: not init yet\n"); + pthread_mutex_unlock(&pmt); return -1; } p_md = malloc(sizeof(struct monitor_data)); if(p_md == NULL) + { + pthread_mutex_unlock(&pmt); return -1; + } memcpy(p_md,pmd,sizeof(struct monitor_data)); dbg_printf(VDEC_DEBUG_LOCK,"ori 0x%x 0x%x pt=0x%x user_id=0x%x \n",pmd->pt, pmd->user_id, p_md->pt,p_md->user_id); @@ -844,31 +867,44 @@ int vmeta_thread_monitor(struct monitor_data * pmd) } dbg_printf(VDEC_DEBUG_LOCK,"wait for pt=0x%x \n",p_md->pt); + pthread_mutex_unlock(&pmt); + pthread_join(p_md->pt,NULL); dbg_printf(VDEC_DEBUG_LOCK,"pt=0x%x is killed user_id(%d)\n",p_md->pt,p_md->user_id); - if(p_md->user_id==p_ks->active_user_id) { - dbg_printf(VDEC_DEBUG_LOCK,"vmeta thread exit abnormally, instance id=%d lock flag=%d\n",p_md->user_id,p_ks->lock_flag); - if( p_ks->lock_flag==VMETA_LOCK_ON ) { - vdec_os_api_unlock(p_md->user_id); - p_ks->lock_flag = VMETA_LOCK_FORCE_INIT; + pthread_mutex_lock(&pmt); + p_cb = vdec_driver_get_cb(); + + if(p_cb) { + if(p_cb->kernel_share_va) { + p_ks = (kernel_share *)p_cb->kernel_share_va; + if(p_md->user_id==p_ks->active_user_id) { + dbg_printf(VDEC_DEBUG_LOCK,"vmeta thread exit abnormally, instance id=%d lock flag=%d\n",p_md->user_id,p_ks->lock_flag); + if( p_ks->lock_flag==VMETA_LOCK_ON ) { + vdec_os_api_unlock(p_md->user_id); + p_ks->lock_flag = VMETA_LOCK_FORCE_INIT; + } + p_ks->active_user_id = MAX_VMETA_INSTANCE; + } + + if(p_ks->user_id_list[p_md->user_id].status != 0) { + dbg_printf(VDEC_DEBUG_LOCK,"vmeta thread exit abnormally, clear instance(%d)\n",p_md->user_id); + memset(&(p_ks->user_id_list[p_md->user_id]),0x0,sizeof(id_instance)); + p_ks->ref_count--; + } } - p_ks->active_user_id = MAX_VMETA_INSTANCE; - } - - if(p_ks->user_id_list[p_md->user_id].status != 0) { - dbg_printf(VDEC_DEBUG_LOCK,"vmeta thread exit abnormally, clear instance(%d)\n",p_md->user_id); - memset(&(p_ks->user_id_list[p_md->user_id]),0x0,sizeof(id_instance)); - p_ks->ref_count--; } free(p_md); free(pmd); pthread_attr_destroy(&pat); + dbg_printf(VDEC_DEBUG_MEM,"thread monitor exit\n"); + pthread_mutex_unlock(&pmt); return 0; tag_monitor_fail: + pthread_mutex_unlock(&pmt); free(p_md); free(pmd); @@ -885,7 +921,7 @@ tag_monitor_fail: struct monitor_data *p_md; if(user_id>=MAX_VMETA_INSTANCE || user_id<0) { - printf("vdec_os_api_register_user_id error: exceeds max user_id\n"); + dbg_printf(VDEC_DEBUG_ALL,"vdec_os_api_register_user_id error: exceeds max user_id\n"); return VDEC_OS_DRIVER_USER_ID_FAIL; } @@ -899,13 +935,13 @@ tag_monitor_fail: } if(set_bit(VMETA_STATUS_BIT_REGISTED, &(p_ks->user_id_list[user_id].status)) == 1) { - printf("vdec_os_api_register_user_id error: user id has already been registered\n"); + dbg_printf(VDEC_DEBUG_ALL, "vdec_os_api_register_user_id error: user id has already been registered\n"); return VDEC_OS_DRIVER_USER_ID_FAIL; } p_md = (struct monitor_data*) malloc(sizeof(struct monitor_data));//This is freed monitor function if(p_md == NULL) { - printf("vdec_os_api_register_user_id error: OOM\n"); + dbg_printf(VDEC_DEBUG_ALL,"vdec_os_api_register_user_id error: OOM\n"); return VDEC_OS_DRIVER_USER_ID_FAIL; } p_ks->ref_count++; @@ -927,13 +963,13 @@ tag_monitor_fail: vdec_os_driver_cb_t *p_cb = vdec_driver_get_cb(); if(user_id>=MAX_VMETA_INSTANCE || user_id<0) { - printf("vdec_os_api_unregister_user_id error: exceeds max user_id\n"); + dbg_printf(VDEC_DEBUG_ALL,"vdec_os_api_unregister_user_id error: exceeds max user_id\n"); return VDEC_OS_DRIVER_USER_ID_FAIL; } if(p_cb->kernel_share_va==0) { - printf("vdec_os_api_unregister_user_id error: not init yet\n"); + dbg_printf(VDEC_DEBUG_ALL,"vdec_os_api_unregister_user_id error: not init yet\n"); return VDEC_OS_DRIVER_USER_ID_FAIL; } else @@ -942,7 +978,7 @@ tag_monitor_fail: } if(clear_bit(VMETA_STATUS_BIT_REGISTED,&(p_ks->user_id_list[user_id].status)) == 0) { - printf("vdec_os_api_unregister_user_id error: user id[%d] has not been registered\n",user_id); + dbg_printf(VDEC_DEBUG_ALL,"vdec_os_api_unregister_user_id error: user id[%d] has not been registered\n",user_id); return VDEC_OS_DRIVER_USER_ID_FAIL; } @@ -970,7 +1006,7 @@ tag_monitor_fail: kernel_share *p_ks; if(p_cb == NULL) { - printf("vdec_os_api_get_user_count error: point is NULL\n"); + dbg_printf(VDEC_DEBUG_ALL,"vdec_os_api_get_user_count error: point is NULL\n"); return -1; } @@ -983,7 +1019,7 @@ tag_monitor_fail: p_ks = (kernel_share *)p_cb->kernel_share_va; } - dbg_printf(VDEC_DEBUG_ALL, "get_user_count=%d \n",p_ks->ref_count); + dbg_printf(VDEC_DEBUG_ALL, "get_user_count=%d \n",p_ks->ref_count); return p_ks->ref_count; } @@ -997,7 +1033,7 @@ tag_monitor_fail: SIGN32 sem_val; if(p_cb == NULL) { - printf("vdec_os_api_lock error: point is NULL\n"); + dbg_printf(VDEC_DEBUG_ALL,"vdec_os_api_lock error: point is NULL\n"); return LOCK_RET_ERROR_UNKNOWN; } p_ks = (kernel_share*)p_cb->kernel_share_va; @@ -1034,7 +1070,7 @@ tag_monitor_fail: int ret; if(p_cb == NULL) { - printf("vdec_os_api_unlock error: point is NULL\n"); + dbg_printf(VDEC_DEBUG_LOCK,"vdec_os_api_unlock error: point is NULL\n"); return LOCK_RET_ERROR_UNKNOWN; } @@ -1046,7 +1082,7 @@ tag_monitor_fail: } else { - printf("vdec_os_api_unlock error: unlock other user id %d; active_user_id is %d\n", user_id, p_ks->active_user_id); + dbg_printf(VDEC_DEBUG_LOCK,"vdec_os_api_unlock error: unlock other user id %d; active_user_id is %d\n", user_id, p_ks->active_user_id); vmeta_private_unlock(); return LOCK_RET_ERROR_UNKNOWN; } @@ -1055,7 +1091,7 @@ tag_monitor_fail: ret = ioctl(vdec_iface->uiofd,VMETA_CMD_UNLOCK); dbg_printf(VDEC_DEBUG_LOCK, "ID: %d after unlock\n", user_id); if(ret != 0) { - printf("vdec_os_api_unlock ioctl error\n"); + dbg_printf(VDEC_DEBUG_LOCK,"vdec_os_api_unlock ioctl error\n"); return LOCK_RET_ERROR_UNKNOWN; } @@ -1127,7 +1163,7 @@ SIGN32 vdec_os_driver_version(SIGN8 *ver_str) vdec_os_driver_cb_t *p_cb = vdec_driver_get_cb(); if(p_cb==NULL || ver_str==NULL) { - printf("vdec_os_driver_version error: point is NULL\n"); + dbg_printf(VDEC_DEBUG_VER,"vdec_os_driver_version error: point is NULL\n"); return -VDEC_OS_DRIVER_VER_FAIL; } |