static int __init ipera_init(void) { int ret; __D("** " __FILE__ " kernel module built: " __DATE__ " " __TIME__ "\n"); ret = register_chrdev(major, K_DEV, &ipera_fops); if (ret < 0) { __E("Failed to allocate major number.\n"); return -ENODEV; } __D("Allocated major number: %d\n", major); #ifdef USE_UDEV ipera_class = class_create(THIS_MODULE, K_DEV); if (IS_ERR(ipera_class)) { __E("Error creating ipera device class.\n"); return -EIO; } //class_device_create(ipera_class, NULL, MKDEV(major, 0), NULL, K_DEV); #endif // USE_UDEV __D("Successfully initialized module\n"); return 0; }
/** * @brief Video read frame * @param "void *pDest" : destination address * @param "int *pSize" : size * @param "int *pFrm_type" : frame type * @param "int bufflimit" : buffer limit * @param "VIDEO_FRAME *pFrame" * @param "VIDEO_BLK_INFO *pVidInfo" * @return 0 : success ; -1 : fail */ int MemMng_Video_ReadFrame( void *pDest, int *pSize, int *pFrm_type , int bufflimit, VIDEO_FRAME *pFrame, VIDEO_BLK_INFO *pVidInfo ) { if( pDest == NULL || pVidInfo == NULL || pFrame == NULL ) { __E("MemMng_Video_ReadFrame: invalidate pointer\n"); return -1; } if( pFrame->fram_type == DUMMY_FRAME || pFrame->fram_type == EMPTY_FRAME ) { __E("MemMng_Video_ReadFrame: invalidate frame_type\n"); return -1; } if( pFrame->realsize > bufflimit ) { __E("MemMng_Video_ReadFrame: Over bufflimit\n"); return -1; } void *pSrc = (void *)(pVidInfo->start + pFrame->blkindex*pVidInfo->blk_sz); *pSize = pFrame->realsize; *pFrm_type = pFrame->fram_type; MemMng_memcpy( pDest, pSrc, pFrame->realsize ); return 0; }
static int validate_init() { switch (cmem_fd) { case -3: __E("CMEM_exit() already called, check stderr output for earlier " "CMEM failure messages (possibly version mismatch).\n"); return 0; case -2: __E("CMEM_init() not called, you must initialize CMEM before " "making API calls.\n"); return 0; case -1: __E("CMEM file descriptor -1 (failed 'open()'), ensure CMEMK " "kernel module cmemk.ko has been installed with 'insmod'"); return 0; default: return 1; } }
EnemyInst::EnemyInst(int enemytype, int x, int y) : CombatGameInst(__E(enemytype).basestats, __E(enemytype).enemy_sprite, x, y, __E(enemytype).radius, true, DEPTH) { this->seen = false; this->xpgain = __E(enemytype).xpaward; this->enemytype = enemytype; this->enemy_regen_cooloff = 0; }
/* RGB Buffer Allocation */ static int camif_pp_preview(camif_cfg_t *cfg) { int i; u32 cbcr_size = 0; /* Cb,Cr size */ u32 area = cfg->target_x * cfg->target_y; __D("\n"); if(cfg->input_channel) { camif_pp_preview_msdma(cfg); return 0; } if (cfg->dst_fmt & CAMIF_YCBCR420) { cbcr_size = area /4; /* To Do */ } else if(cfg->dst_fmt & CAMIF_YCBCR422){ cbcr_size = area /2; /* To Do */ } else if(cfg->dst_fmt & CAMIF_RGB24) { area = area * 4 ; } else if (cfg->dst_fmt & CAMIF_RGB16) { area = area * 2; } else { __E("Invalid format No - %d \n", cfg->dst_fmt); } switch ( cfg->pp_num ) { case 1: for ( i = 0; i < 4 ; i++ ) { cfg->img_buf[i].virt_rgb = cfg->pp_virt_buf ; cfg->img_buf[i].phys_rgb = cfg->pp_phys_buf ; base->CIPRYSA[i] = cfg->img_buf[i].phys_rgb; } break; case 2: for ( i = 0; i < 4 ; i++) { cfg->img_buf[i].virt_rgb = cfg->pp_virt_buf + TRY * area; cfg->img_buf[i].phys_rgb = cfg->pp_phys_buf + TRY * area; base->CIPRYSA[i] = cfg->img_buf[i].phys_rgb; } break; case 4: for ( i = 0; i < 4 ; i++) { cfg->img_buf[i].virt_rgb = cfg->pp_virt_buf + i * area; cfg->img_buf[i].phys_rgb = cfg->pp_phys_buf + i * area; base->CIPRYSA[i] = cfg->img_buf[i].phys_rgb; } break; default: __E("Invalid PingPong Number %d \n", cfg->pp_num); } return 0; }
int __init gbshm_init(void) { int err = 0; /* cut-and-paste above as part of adding support for more than 2 blocks */ gbshm_major = register_chrdev(0, "vidctl", &gbshm_fxns); if (gbshm_major < 0) { __E("Failed to allocate major number.\n"); return -ENODEV; } __D("Allocated major number: %d\n", gbshm_major); #if (USE_UDEV==1) #ifdef USE_CLASS_SIMPLE gbshm_class = class_simple_create(THIS_MODULE, "gbshm"); #else gbshm_class = class_create(THIS_MODULE, "gbshm"); #endif if (IS_ERR(gbshm_class)) { __E("Error creating cmem device class.\n"); err = -EIO; return err; } #ifdef USE_CLASS_SIMPLE class_simple_device_add(gbshm_class, MKDEV(gbshm_major, 0), NULL, "gbshm"); #else #ifdef USE_CLASS_DEVICE class_device_create(gbshm_class, NULL, MKDEV(gbshm_major, 0), NULL, "gbshm"); #else #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) device_create(gbshm_class, NULL, MKDEV(gbshm_major, 0), NULL, "gbshm"); #else device_create(gbshm_class, NULL, MKDEV(gbshm_major, 0), "gbshm"); #endif // LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) #endif // USE_CLASS_DEVICE #endif // USE_CLASS_SIMPLE #endif // USE_UDEV /* Create the /proc entry */ printk(KERN_INFO "vidctl initialized\n"); //set_reg(); //printk_reg(); //tvp5150_set_input_mux(0); return 0; }
/* RGB Buffer Allocation For CODEC path */ static int camif_pp_codec_rgb(camif_cfg_t *cfg) { int i; u32 val; u32 area = cfg->target_x * cfg->target_y; __D("\n"); if(cfg->dst_fmt & CAMIF_RGB24) { area = area * 4 ; } else if (cfg->dst_fmt & CAMIF_RGB16){ area = area * 2; } else { __E("Failed! %d\n", cfg->dst_fmt); } if(cfg->input_channel == MSDMA_FROM_CODEC){ // Use MSDMA val = readl(S3C_VIDW00ADD0B0); for ( i = 0; i < 4 ; i++ ) { base->CICOYSA[i] = val; } } else{ // Do NOT use MSDMA switch ( cfg->pp_num ) { case 1: for ( i = 0; i < 4 ; i++ ) { cfg->img_buf[i].virt_rgb = cfg->pp_virt_buf ; cfg->img_buf[i].phys_rgb = cfg->pp_phys_buf ; base->CICOYSA[i] = cfg->img_buf[i].phys_rgb; } break; case 2: for ( i = 0; i < 4 ; i++) { cfg->img_buf[i].virt_rgb = cfg->pp_virt_buf + TRY * area; cfg->img_buf[i].phys_rgb = cfg->pp_phys_buf + TRY * area; base->CICOYSA[i] = cfg->img_buf[i].phys_rgb; } break; case 4: for ( i = 0; i < 4 ; i++) { cfg->img_buf[i].virt_rgb = cfg->pp_virt_buf + i * area; cfg->img_buf[i].phys_rgb = cfg->pp_phys_buf + i * area; base->CICOYSA[i] = cfg->img_buf[i].phys_rgb; } break; default: __E("Invalid PingPong Number %d \n",cfg->pp_num); panic("s3c_camif.c : Halt !\n"); } } return 0; }
int DM365MM_clearPending (void) { if (dm365mm_fd == -1) { __E ("clearPending: invalid fd\n"); return -1; } if (ioctl (dm365mm_fd, DM365MMAP_IOCCLEAR_PENDING, NULL) == -1) { __E ("clearPending: Clear Pending failed.\n"); return -1; } return 0; }
/** * @brief Video memory allocate * @param "MEM_MNG_INFO *pInfo" * @return 0 : success ; -1 : fail */ int Video_Mem_Malloc( MEM_MNG_INFO *pInfo ) { int cnt = 0; int loops = 0; int cnt2 = 0; loops = sizeof( Video_info_default )/ sizeof( Video_info_default[0] ); pInfo->video_info_nums = loops; pInfo->video_info = calloc( pInfo->video_info_nums, sizeof(VIDEO_BLK_INFO) ); memcpy( pInfo->video_info, Video_info_default, sizeof( Video_info_default ) ); for( cnt = 0; cnt < loops ; cnt++ ) { pInfo->video_info[cnt].start = pInfo->start_addr + pInfo->offset; pInfo->video_info[cnt].start_phy = pInfo->start_phyAddr + pInfo->offset;; pInfo->video_info[cnt].frame_num = pInfo->video_info[cnt].blk_num; pInfo->video_info[cnt].frame = calloc( pInfo->video_info[cnt].blk_num , sizeof(VIDEO_FRAME) ); for( cnt2 = 0; cnt2 < pInfo->video_info[cnt].blk_num ; cnt2++ ) { Video_Frame_reset( &(pInfo->video_info[cnt].frame[cnt2]) ); } pInfo->freesize -= pInfo->video_info[cnt].size; pInfo->offset += pInfo->video_info[cnt].size; if( pInfo->video_info[cnt].extrasize > 0 ) { pInfo->video_info[cnt].extradata = (void *)(pInfo->start_addr + pInfo->offset); pInfo->freesize -= pInfo->video_info[cnt].extrasize; pInfo->offset += pInfo->video_info[cnt].extrasize; } if( pInfo->freesize < 0 || pInfo->video_info[cnt].frame == NULL) { __E("pInfo->freesize = %d\n",pInfo->freesize); __E("Video_Mem_Malloc FAIL\n"); return -1; } } return 0; }
int DM365MM_waitForSequencer (void) { if (dm365mm_fd == -1) { __E ("waitForSequencer: invalid fd\n"); return -1; } if (ioctl (dm365mm_fd, DM365MMAP_IOCWAIT, NULL) == -1) { __E ("waitForSequencer: Wait failed, process interrupted in between.\n"); return -1; } return 0; }
/** * @brief Memory manager initialization * @param "MEM_MNG_INFO *pInfo" * @return 0 : success ; -1 : fail */ int MemMng_Init( MEM_MNG_INFO *pInfo ) { int mem_layout = pInfo->mem_layout; memset( pInfo, 0 , sizeof(MEM_MNG_INFO) ); pInfo->totalsize = MemMng_Mem_layout(mem_layout); pInfo->start_addr = (unsigned long)STREAM_CMEM_ALLOC(pInfo->totalsize, 32); if( pInfo->start_addr == 0 ) goto MEM_INIT_FAIL; pInfo->start_phyAddr = CMEM_getPhys((void *)pInfo->start_addr); if(pInfo->start_phyAddr == 0) fprintf(stderr, "Failed to get physical address of %#x\n", (unsigned int) pInfo->start_phyAddr); pInfo->freesize = pInfo->totalsize; pInfo->offset = 0; pInfo->video_info_nums = 0; if(Video_Mem_Malloc( pInfo )==0) __D(" MEM_INIT Success \n"); else return -1; MemMng_memcpy_open(); return 0; MEM_INIT_FAIL: __E(" MEM_INIT_FAIL \n"); return -1; }
EDMA_Status EDMA_freeResource(int lch, int nParams) { EDMA_Status status = EDMA_OK; struct EDMA_releaseDmaParams request; int ioctl_status; __D("freeResource: entered - lch=%d, nParams=%d\n", lch, nParams); if (EDMA_dmaops_fd < 0) { __D("freeResource: /dev/edma not opened\n"); return (EDMA_ENOINIT); } request.channel = lch; request.nParam = nParams; if ((ioctl_status = ioctl(EDMA_dmaops_fd, EDMA_IOCRELEASEDMA | EDMA_IOCMAGIC, (unsigned long)&request)) < 0) { __E("EDMA_IOCRELEASEDMA error\n"); status = EDMA_EFAIL; } __D("freeResource: exiting, ioctl EDMA_IOCRELEASEDMA returned %d\n", ioctl_status); return (status); }
EDMA_Status EDMA_registerResource(int lch) { EDMA_Status status = EDMA_OK; int ioctl_status; __D("registerResource: entered - lch=%d\n", lch); if (EDMA_dmaops_fd < 0) { __D("registerResource: /dev/edma not opened\n"); return (EDMA_ENOINIT); } if ((ioctl_status = ioctl(EDMA_dmaops_fd, EDMA_IOCREGUSER | EDMA_IOCMAGIC, (unsigned long)&lch)) < 0) { __E("EDMA_IOCREGUSER error\n"); status = EDMA_EFAIL; } __D("registerResource: exiting, ioctl EDMA_IOCREGUSER returned %d\n", ioctl_status); return (status); }
int EDMA_getVersion(void) { unsigned int version; int rv; __D("getVersion: entered\n"); if (EDMA_dmaops_fd < 0) { __D("getVersion: /dev/edma not opened\n"); return (EDMA_ENOINIT); } rv = ioctl(EDMA_dmaops_fd, EDMA_IOCGETVERSION | EDMA_IOCMAGIC, &version); if (rv != 0) { __E("getVersion: Failed to retrieve version from driver: %d.\n", rv); return -1; } __D("getVersion: exiting, ioctl EDMA_IOCGETVERSION returned %#x\n", version); return version; }
static int getBlock(int blockid, unsigned long *pphys_base, size_t *psize) { union CMEM_AllocUnion block; int rv; __D("getBlock: entered\n"); if (!validate_init()) { return -1; } block.blockid = blockid; rv = ioctl(cmem_fd, CMEM_IOCGETBLOCK | CMEM_IOCMAGIC, &block); if (rv != 0) { __E("getBlock: Failed to retrieve memory block bounds for block %d " "from driver: %d.\n", blockid, rv); return -1; } *pphys_base = block.get_block_outparams.physp; *psize = block.get_block_outparams.size; __D("getBlock: exiting, ioctl CMEM_IOCGETBLOCK succeeded, " "returning *pphys_base=0x%lx, *psize=0x%x\n", *pphys_base, *psize); return 0; }
/** * @brief Write cache * @param "CACHE_DATA *pCache" * @param "VIDEO_FRAME *pFrame" * @param "VIDEO_BLK_INFO *pVidInfo" * @return 0 ; CACHE_PARM_ERR */ int CacheMng_cache_write( CACHE_DATA *pCache, VIDEO_FRAME *pFrame, VIDEO_BLK_INFO *pVidInfo ) { CACHE_BLK *pblk = NULL; unsigned long Src_Addr = 0; unsigned long Des_Addr = 0; int size = 0; int cnt = 0; if( pCache==NULL || pFrame==NULL || pVidInfo==NULL ) { __E("CacheMng_cache_write: invalidate parameter!! \n"); return CACHE_PARM_ERR; } pCache->fram_type = pFrame->fram_type; pCache->serial = pFrame->serial; pCache->realsize = pFrame->realsize; pCache->flag = pFrame->flag; pCache->timestamp = pFrame->timestamp; pCache->temporalId = pFrame->temporalId; for( cnt = 0; cnt < VIDOE_INFO_END; cnt++ ) { pCache->ref_serial[cnt] = pFrame->ref_serial[cnt]; } for( cnt = 0; cnt < pCache->blks ; cnt ++ ) { pblk = &(pVidInfo->cachemng->blk[ pCache->blkindex + cnt ]); CacheMng_blk_set( pblk, pCache->serial ); } pblk = &(pVidInfo->cachemng->blk[ pCache->blkindex ]); Des_Addr = pVidInfo->cachemng->start_addr + pblk->offset; Src_Addr = pVidInfo->start + pVidInfo->blk_sz*pFrame->blkindex; size = pCache->realsize; if( CacheMng_MemCpy( (void *)Des_Addr, (void *)Src_Addr, size ) < 0 ) { __E("CacheMng_cache_write: error memcpy \n"); return CACHE_PARM_ERR; } return 0; }
static void *allocFromHeap(int blockid, size_t size, CMEM_AllocParams *params) { void *userp; union CMEM_AllocUnion allocDesc; unsigned long physp; unsigned int cmd; int rv; cmd = CMEM_IOCALLOCHEAP | params->flags; allocDesc.alloc_heap_inparams.size = size; allocDesc.alloc_heap_inparams.align = params->alignment == 0 ? 1 : params->alignment; allocDesc.alloc_heap_inparams.blockid = blockid; rv = ioctl(cmem_fd, cmd | CMEM_IOCMAGIC, &allocDesc); if (rv != 0) { __E("allocHeap: ioctl %s failed: %d\n", cmd == CMEM_IOCALLOCHEAP ? "CMEM_IOCALLOCHEAP" : "CMEM_IOCALLOCHEAPCACHED", rv); return NULL; } physp = allocDesc.physp; __D("allocHeap: allocated phys buffer %#lx\n", physp); /* Map the physical address to user space */ userp = mmap(0, // Preferred start address size, // Length to be mapped PROT_WRITE | PROT_READ, // Read and write access MAP_SHARED, // Shared memory cmem_fd, // File descriptor physp); // The byte offset from fd if (userp == MAP_FAILED) { __E("allocHeap: Failed to mmap buffer at physical address %#lx\n", physp); __E(" Freeing phys buffer %#lx\n", physp); ioctl(cmem_fd, CMEM_IOCFREEHEAPPHYS | CMEM_IOCMAGIC, &physp); return NULL; } __D("allocHeap: mmap succeeded, returning virt buffer %p\n", userp); return userp; }
/* RGB Buffer Allocation into frame buffer */ static int camif_pp_preview_msdma(camif_cfg_t *cfg) { int i; u32 cbcr_size = 0; /* Cb+Cr size */ u32 val; //one_p_size, val; u32 area = cfg->cis->source_x * cfg->cis->source_y; __D("\n"); val = readl(S3C_VIDW01ADD0B0); if(!((cfg->dst_fmt & CAMIF_RGB16) || (cfg->dst_fmt & CAMIF_RGB24))) __E("Invalid Format\n"); for ( i = 0; i < 4 ; i++ ) { base->CIPRYSA[i] = val; } if (cfg->src_fmt & CAMIF_YCBCR420) { cbcr_size = area/4; cfg->img_buf[0].virt_cb = cfg->pp_virt_buf + area; cfg->img_buf[0].phys_cb = cfg->pp_phys_buf + area; cfg->img_buf[0].virt_cr = cfg->pp_virt_buf + area + cbcr_size; cfg->img_buf[0].phys_cr = cfg->pp_phys_buf + area + cbcr_size; } else if(cfg->src_fmt & CAMIF_YCBCR422){ area = area * 2; cfg->img_buf[0].virt_cb = 0; cfg->img_buf[0].phys_cb = 0; cfg->img_buf[0].virt_cr = 0; cfg->img_buf[0].phys_cr = 0; } cfg->img_buf[0].virt_y = cfg->pp_virt_buf; cfg->img_buf[0].phys_y = cfg->pp_phys_buf; base->MSPRY0SA = cfg->img_buf[0].phys_y; base->MSPRY0END = cfg->img_buf[0].phys_y+area; base->MSPRCB0SA = cfg->img_buf[0].phys_cb; base->MSPRCB0END = cfg->img_buf[0].phys_cb+cbcr_size; base->MSPRCR0SA = cfg->img_buf[0].phys_cr; base->MSPRCR0END = cfg->img_buf[0].phys_cr+cbcr_size; #ifdef SW_IPC base->MSCOWIDTH.AutoLoadEnable = 0; // AutoLoadDisable #else base->MSCOWIDTH.AutoLoadEnable = 1; // AutoLoadEnable #endif base->MSPRWIDTH.MSPRHEIGHT = cfg->cis->source_y; base->MSPRWIDTH.MSPRHEIGHT = cfg->cis->source_x; return 0; }
/** * @brief Destroy the semephore * @param none * @retval 0: success; -1: fail */ int Sem_kill() { if( pthread_mutex_destroy(&mutex)!= 0 ) { __E("Sem_kill faill!!\n"); return -1; } return 0; }
static void *allocFromPool(int blockid, int poolid, CMEM_AllocParams *params) { union CMEM_AllocUnion allocDesc; unsigned long physp; void *userp; size_t size; unsigned int cmd; int rv; allocDesc.alloc_pool_inparams.poolid = poolid; allocDesc.alloc_pool_inparams.blockid = blockid; cmd = CMEM_IOCALLOC | params->flags; rv = ioctl(cmem_fd, cmd | CMEM_IOCMAGIC, &allocDesc); if (rv != 0) { __E("allocPool: ioctl %s failed from pool %d: %d\n", cmd == CMEM_IOCALLOC ? "CMEM_IOCALLOC" : "CMEM_IOCALLOCCACHED", poolid, rv); return NULL; } physp = allocDesc.alloc_pool_outparams.physp; size = allocDesc.alloc_pool_outparams.size; __D("allocPool: allocated phys buffer %#lx, size %#x\n", physp, size); /* Map the physical address to user space */ userp = mmap(0, // Preferred start address size, // Length to be mapped PROT_WRITE | PROT_READ, // Read and write access MAP_SHARED, // Shared memory cmem_fd, // File descriptor physp); // The byte offset from fd if (userp == MAP_FAILED) { __E("allocPool: Failed to mmap buffer at physical address %#lx\n", physp); __E(" Freeing phys buffer %#lx\n", physp); ioctl(cmem_fd, CMEM_IOCFREEPHYS | CMEM_IOCMAGIC , &physp); return NULL; } __D("allocPool: mmap succeeded, returning virt buffer %p\n", userp); return userp; }
/** * @brief Unset cache block * @param "CACHE_BLK *pblk" : cache block * @return none */ void CacheMng_blk_unset( CACHE_BLK *pblk) { if( pblk ) { pblk->IsFree = 1; pblk->serial = -1; } else { __E("CacheMng_blk_unset : NULL \n"); } }
/** * @brief read dm355 gio infomation * *@param gio_id GIO ID * @return GIO status *@retval -1 error */ int dm355_gio_read( int gio_id ) { int fd_gio = 0; char data[5]; int result = 0; char dev_name[25]; if( gio_id < 0 || gio_id > GIO_MAX_ID ) { __E("gio id = %d over range!!\n", gio_id); return -1; } if( dm355_gio_getname(dev_name,gio_id) < 0 ) { __E("gio get name error!!\n"); return -1; } fd_gio = open(dev_name, O_RDWR); if( !fd_gio ) { __E("open device error !! gio = %d\n", gio_id); return -1; } result = read(fd_gio, data, 1); if( result <= 0 ) { __E("read device error !! gio = %d\n", gio_id); close(fd_gio); return -1; } close(fd_gio); if( data[0] == '1') { return 1; }else{ return 0; } return -1; }
/* * Codec Input YCBCR422 will be Fixed * cfg->flip removed because cfg->flip will be set in camif_change_flip func. */ static int camif_target_fmt(camif_cfg_t *cfg) { //u32 cmd = 0; __D("\n"); if (cfg->dma_type & CAMIF_CODEC) { base->CICOTRGFMT.TargetHsize_Co = cfg->target_x; base->CICOTRGFMT.TargetVsize_Co = cfg->target_y; /* YCBCR setting */ if ( cfg->dst_fmt & CAMIF_YCBCR420 ) { base->CICOTRGFMT.OutFormat_Co = 0; //Interleadve Off } else if(cfg->dst_fmt & CAMIF_YCBCR422) { if(cfg->interlace_capture) base->CICOTRGFMT.OutFormat_Co = 2; else base->CICOTRGFMT.OutFormat_Co = 1; } else if((cfg->dst_fmt & CAMIF_RGB24) ||(cfg->dst_fmt & CAMIF_RGB16)) { base->CICOTRGFMT.OutFormat_Co = 3; } else { __E("camif_target_fmt() - Invalid Format\n"); } } else if (cfg->dma_type & CAMIF_PREVIEW) { base->CIPRTRGFMT.TargetHsize_Pr = cfg->target_x; base->CIPRTRGFMT.TargetVsize_Pr = cfg->target_y; /* YCBCR setting */ if ( cfg->dst_fmt & CAMIF_YCBCR420 ) { base->CIPRTRGFMT.OutFormat_Pr = 0; } else if(cfg->dst_fmt & CAMIF_YCBCR422) { base->CIPRTRGFMT.OutFormat_Pr = 1; } else if((cfg->dst_fmt & CAMIF_RGB24) ||(cfg->dst_fmt & CAMIF_RGB16)) { base->CIPRTRGFMT.OutFormat_Pr = 3; } else { __E("Invalid Format\n"); } } else { __E("Failed! %d\n", cfg->dma_type); } return 0; }
/** * @brief Set cache block * @param "CACHE_BLK *pblk" : cache block * @param "int serial" : serial number * @return none */ void CacheMng_blk_set( CACHE_BLK *pblk, int serial) { if( pblk ) { pblk->IsFree = 0; pblk->serial = serial; } else { __E("CacheMng_blk_set : NULL \n"); } }
/** * @brief Initialize the mutex which protects the global data * @param none * @retval 0: success; -1: fail */ int Sem_Creat() { /* Initialize the mutex which protects the global data */ if( pthread_mutex_init(&mutex, NULL) != 0 ) { __E("Sem_Creat init faill!!\n"); return -1; } return 0; }
/** * @brief Create a semaphore * @param "int index" : index * @return index : success ; -1 : fail */ int Sem_Creat( int index ) { if( index < 0 || index >= STREAM_SEM_NUM) { __E("Sem_Creat index faill!!\n"); return -1; } /* Initialize the mutex which protects the global data */ if( pthread_mutex_init(&stream_mutex[index], NULL) != 0 ) { __E("Sem_Creat init faill!!\n"); return -1; }else{ return index; } }
/** * @brief Destroy a semaphore * @param "int index" : index * @return 0 : success ; -1 : fail */ int Sem_kill( int index ) { if( index < 0 || index >= STREAM_SEM_NUM) { __E("Sem_kill index faill!!\n"); return -1; } if( pthread_mutex_destroy(&stream_mutex[index])!= 0 ) { __E("Sem_kill faill!!\n"); return -1; } return 0; }
/** * @brief Lock a semaphore * @param "int index" : index * @return 0 : success ; -1 : fail */ int Sem_lock( int index ) { if( index < 0 || index >= STREAM_SEM_NUM) { __E("Sem_lock faill!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); return -1; } pthread_mutex_lock(&stream_mutex[index]); return 0; }
/** * @brief Reset cache block * @param "CACHE_BLK *pblk" : cache block * @param "int offset" : offset * @return none */ void CacheMng_blk_reset( CACHE_BLK *pblk, int offset) { if( pblk ) { pblk->IsFree = 1; pblk->offset = offset; pblk->serial = -1; } else { __E("CacheMng_blk_reset : NULL \n"); } }
void *CMEM_registerAlloc(unsigned long physp) { union CMEM_AllocUnion allocDesc; void *userp; size_t size; int rv; allocDesc.physp = physp; rv = ioctl(cmem_fd, CMEM_IOCREGUSER | CMEM_IOCMAGIC, &allocDesc); if (rv != 0) { __E("registerAlloc: ioctl CMEM_IOCREGUSER failed for phys addr %#lx: %d\n", physp, rv); return NULL; } size = allocDesc.size; __D("registerAlloc: registered use of phys buffer %#lx, size %#x\n", physp, size); /* Map the physical address to user space */ userp = mmap(0, // Preferred start address size, // Length to be mapped PROT_WRITE | PROT_READ, // Read and write access MAP_SHARED, // Shared memory cmem_fd, // File descriptor physp); // The byte offset from fd if (userp == MAP_FAILED) { __E("registerAlloc: Failed to mmap buffer at physical address %#lx\n", physp); __E(" Unregistering use of phys buffer %#lx\n", physp); ioctl(cmem_fd, CMEM_IOCFREEPHYS | CMEM_IOCMAGIC, &physp); return NULL; } __D("registerAlloc: mmap succeeded, returning virt buffer %p\n", userp); return userp; }