static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage, buffer_handle_t* pHandle, int w, int h, int format, int bpp, int stride_raw, int stride) { ump_handle ump_mem_handle; void *cpu_ptr; ump_secure_id ump_id; size = round_up_to_page_size(size); if (usage & GRALLOC_USAGE_HW_FIMC1) { int dev_fd=0; char node[20]; int ret; int paddr=0; int offset=0; struct v4l2_control vc; sprintf(node, "%s", PFX_NODE_FIMC1); if (gfd == 0) { gfd = open(node, O_RDWR); if (gfd < 0) { LOGE("%s:: %s Post processor open error\n", __func__, node); return false; } } vc.id = V4L2_CID_RESERVED_MEM_BASE_ADDR; vc.value = 0; ret = ioctl(gfd, VIDIOC_G_CTRL, &vc); if (ret < 0) { LOGE("Error in video VIDIOC_G_CTRL - V4L2_CID_RESERVED_MEM_BAES_ADDR (%d)\n", ret); return false; } paddr = (unsigned int)vc.value; if ((buffer_offset + size) >= FIMC1_RESERVED_SIZE * 1024) buffer_offset = 0; paddr += buffer_offset; private_handle_t* hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_IOCTL, size, 0, private_handle_t::LOCK_STATE_MAPPED, 0, 0); *pHandle = hnd; hnd->format = format; hnd->usage = usage; hnd->width = w; hnd->height = h; hnd->bpp = bpp; hnd->paddr = paddr; hnd->offset = buffer_offset; hnd->stride = stride; hnd->fd = gfd; hnd->uoffset = (EXYNOS4_ALIGN((EXYNOS4_ALIGN(hnd->width, 16) * EXYNOS4_ALIGN(hnd->height, 16)), 4096)); hnd->voffset = (EXYNOS4_ALIGN((EXYNOS4_ALIGN((hnd->width >> 1), 16) * EXYNOS4_ALIGN((hnd->height >> 1), 16)), 4096)); buffer_offset += size; return 0; } else {
static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage, buffer_handle_t* pHandle) { ump_handle ump_mem_handle; void *cpu_ptr; ump_secure_id ump_id; ump_alloc_constraints constraints; size = round_up_to_page_size(size); if( (usage&GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_OFTEN ) { constraints = UMP_REF_DRV_CONSTRAINT_USE_CACHE; } else { constraints = UMP_REF_DRV_CONSTRAINT_NONE; } ump_mem_handle = ump_ref_drv_allocate(size, constraints); if (UMP_INVALID_MEMORY_HANDLE != ump_mem_handle) { cpu_ptr = ump_mapped_pointer_get(ump_mem_handle); if (NULL != cpu_ptr) { ump_id = ump_secure_id_get(ump_mem_handle); if (UMP_INVALID_SECURE_ID != ump_id) { private_handle_t* hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_UMP, size, (int)cpu_ptr, private_handle_t::LOCK_STATE_MAPPED, ump_id, ump_mem_handle); if (NULL != hnd) { *pHandle = hnd; return 0; } else { LOGE("gralloc_alloc_buffer() failed to allocate handle"); } } else { LOGE("gralloc_alloc_buffer() failed to retrieve valid secure id"); } ump_mapped_pointer_release(ump_mem_handle); } else { LOGE("gralloc_alloc_buffer() failed to map UMP memory"); } ump_reference_release(ump_mem_handle); } else { LOGE("gralloc_alloc_buffer() failed to allcoate UMP memory"); } return -1; }
void fb_init(void) { const char *name = "/dev/fb0"; fb_dev.finfo = calloc(1, sizeof(struct fb_fix_screeninfo)); fb_dev.vinfo = calloc(1, sizeof(struct fb_var_screeninfo)); size_t fb_size; size_t fb_size_round_up; int res = NONE; fb_dev.fb_fd = open(name, O_RDWR); if (NONE == fb_dev.fb_fd) ERROR("Failed open FB device\n"); INFO("Open FB - OK"); res = ioctl(fb_dev.fb_fd, FBIOGET_VSCREENINFO, fb_dev.vinfo); if ( res < 0) ERROR("2: FBIOGET_VSCREENINFO failed\n errno=%d", errno); /* fb_dev.vinfo->yres = 16; fb_dev.vinfo->xres = 8; */ fb_dev.vinfo->reserved[0] = 0; fb_dev.vinfo->reserved[1] = 0; fb_dev.vinfo->reserved[2] = 0; fb_dev.vinfo->xoffset = 0; fb_dev.vinfo->yoffset = 0; fb_dev.vinfo->activate = FB_ACTIVATE_VBL;; fb_dev.vinfo->bits_per_pixel = 32; fb_dev.vinfo->red.offset = 16; fb_dev.vinfo->red.length = 8; fb_dev.vinfo->green.offset = 8; fb_dev.vinfo->green.length = 8; fb_dev.vinfo->blue.offset = 0; fb_dev.vinfo->blue.length = 8; fb_dev.vinfo->transp.offset = 0; fb_dev.vinfo->transp.length = 0; fb_dev.vinfo->yres_virtual = fb_dev.vinfo->yres * MAX_BUF; /* res = ioctl(fb_dev.fb_fd, FBIOPAN_DISPLAY, fb_dev.vinfo); if(res < 0) { INFO("2.5: FBIOPUT_VSCREENINFO failed\n errno=%d", errno); } */ res = ioctl(fb_dev.fb_fd, FBIOPAN_DISPLAY, fb_dev.vinfo); if(res < 0) { INFO("3: FBIOPUT_VSCREENINFO failed\n errno=%d", errno); fb_dev.vinfo->yres_virtual = fb_dev.vinfo->yres; INFO("Page flip not supported\n"); } if(fb_dev.vinfo->yres_virtual < (fb_dev.vinfo->yres *MAX_BUF)) { fb_dev.vinfo->yres_virtual = fb_dev.vinfo->yres; INFO("Page flip not supported\n"); } fb_dev.width = fb_dev.vinfo->xres; fb_dev.height = fb_dev.vinfo->yres; INFO("\n" " fb_dev.vinfo\n" " fb = %d\n" " id = %s\n" " xres = %d px \n" " yres = %d px \n" " xres_virtual = %d px \n" " yres_virtual = %d px \n" " bpp = %d \n" " r = %2u:%u\n" " g = %2u:%u\n" " b = %2u:%u\n" " t = %2u:%u\n" " active = %d \n" " width = %d mm \n" " height = %d mm \n", fb_dev.fb_fd, fb_dev.finfo->id, fb_dev.vinfo->xres, fb_dev.vinfo->yres, fb_dev.vinfo->xres_virtual, fb_dev.vinfo->yres_virtual, fb_dev.vinfo->bits_per_pixel, fb_dev.vinfo->red.offset, fb_dev.vinfo->red.length, fb_dev.vinfo->green.offset, fb_dev.vinfo->green.length, fb_dev.vinfo->blue.offset, fb_dev.vinfo->blue.length, fb_dev.vinfo->transp.offset, fb_dev.vinfo->transp.length, fb_dev.vinfo->activate, fb_dev.vinfo->width, fb_dev.vinfo->height); res = ioctl(fb_dev.fb_fd, FBIOGET_FSCREENINFO, fb_dev.finfo); if (res < 0) ERROR("5: FBIOGET_FSCREENINFO failed\n errno=%d", errno); INFO("\n" " fb_dev.finfo\n" " fb_dev.finfo->smem_len = %d\n" " fb_dev.finfo->line_length = %d\n", fb_dev.finfo->smem_len, fb_dev.finfo->line_length); if (fb_dev.finfo->smem_len <= 0) INFO("SMEM less then 0"); fb_size = fb_dev.vinfo->xres * fb_dev.vinfo->yres_virtual; fb_size_round_up = round_up_to_page_size(fb_dev.vinfo->xres * fb_dev.vinfo->yres * fb_dev.vinfo->bits_per_pixel / 8); size_t size = fb_dev.vinfo->xres * fb_dev.vinfo->yres * fb_dev.vinfo->bits_per_pixel / 8 * 3; INFO("\n" " FB\n" " fb_size = %zu\n" " fb_size_rup = %zu\n" " size = %zu\n" " pagesize = %ld\n" " page_size = %ld\n", fb_size, fb_size_round_up, size, sysconf(_SC_PAGESIZE), sysconf(_SC_PAGE_SIZE)); int refreshRate = 1000000000000000LLU / ( (uint64_t)( fb_dev.vinfo->upper_margin + fb_dev.vinfo->lower_margin + fb_dev.vinfo->yres + fb_dev.vinfo->vsync_len) * ( fb_dev.vinfo->left_margin + fb_dev.vinfo->right_margin + fb_dev.vinfo->xres + fb_dev.vinfo->hsync_len) * fb_dev.vinfo->pixclock ); INFO("\n" " My\n" " refresh =%d" " vsync_len =%d" " hvsync_len =%d", refreshRate, fb_dev.vinfo->vsync_len, fb_dev.vinfo->hsync_len ); fb_dev.vaddr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fb_dev.fb_fd, 0); if (fb_dev.vaddr == MAP_FAILED) ERROR("MMap failed, errno=%d", errno); INFO("MMap - OK\n vaddr=%p", fb_dev.vaddr); fb_dev.size = size; memset(fb_dev.vaddr, 0, size); /* * DPMS ON */ /* res = ioctl(fb_dev.fb_fd, FBIOBLANK, FB_BLANK_UNBLANK); if ( res < 0) ERROR("6: FBIOGET_FSCREENINFO failed\n errno=%d", errno); */ free(fb_dev.vinfo); free(fb_dev.finfo); }
static int gralloc_alloc_buffer(alloc_device_t *dev, size_t size, int usage, buffer_handle_t *pHandle) { #if GRALLOC_ARM_DMA_BUF_MODULE { private_module_t *m = reinterpret_cast<private_module_t *>(dev->common.module); ion_user_handle_t ion_hnd; unsigned char *cpu_ptr; int shared_fd; int ret; unsigned int ion_flags = 0; if( (usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_OFTEN ) ion_flags = ION_FLAG_CACHED | ION_FLAG_CACHED_NEEDS_SYNC; if (usage & GRALLOC_USAGE_PRIVATE_1) { ret = ion_alloc(m->ion_client, size, 0, ION_HEAP_CARVEOUT_MASK, ion_flags, &ion_hnd); } else { ret = ion_alloc(m->ion_client, size, 0, ION_HEAP_SYSTEM_MASK, ion_flags, &ion_hnd); } if (ret != 0) { AERR("Failed to ion_alloc from ion_client:%d", m->ion_client); return -1; } ret = ion_share(m->ion_client, ion_hnd, &shared_fd); if (ret != 0) { AERR("ion_share( %d ) failed", m->ion_client); if (0 != ion_free(m->ion_client, ion_hnd)) { AERR("ion_free( %d ) failed", m->ion_client); } return -1; } cpu_ptr = (unsigned char *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, shared_fd, 0); if (MAP_FAILED == cpu_ptr) { AERR("ion_map( %d ) failed", m->ion_client); if (0 != ion_free(m->ion_client, ion_hnd)) { AERR("ion_free( %d ) failed", m->ion_client); } close(shared_fd); return -1; } private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_ION, usage, size, (int)cpu_ptr, private_handle_t::LOCK_STATE_MAPPED); if (NULL != hnd) { hnd->share_fd = shared_fd; hnd->ion_hnd = ion_hnd; *pHandle = hnd; return 0; } else { AERR("Gralloc out of mem for ion_client:%d", m->ion_client); } close(shared_fd); ret = munmap(cpu_ptr, size); if (0 != ret) { AERR("munmap failed for base:%p size: %d", cpu_ptr, size); } ret = ion_free(m->ion_client, ion_hnd); if (0 != ret) { AERR("ion_free( %d ) failed", m->ion_client); } return -1; } #endif #if GRALLOC_ARM_UMP_MODULE { ump_handle ump_mem_handle; void *cpu_ptr; ump_secure_id ump_id; ump_alloc_constraints constraints; size = round_up_to_page_size(size); if ((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_OFTEN) { constraints = UMP_REF_DRV_CONSTRAINT_USE_CACHE; } else { constraints = UMP_REF_DRV_CONSTRAINT_NONE; } #ifdef GRALLOC_SIMULATE_FAILURES /* if the failure condition matches, fail this iteration */ if (__ump_alloc_should_fail()) { ump_mem_handle = UMP_INVALID_MEMORY_HANDLE; } else #endif { ump_mem_handle = ump_ref_drv_allocate(size, constraints); if (UMP_INVALID_MEMORY_HANDLE != ump_mem_handle) { cpu_ptr = ump_mapped_pointer_get(ump_mem_handle); if (NULL != cpu_ptr) { ump_id = ump_secure_id_get(ump_mem_handle); if (UMP_INVALID_SECURE_ID != ump_id) { private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_UMP, usage, size, (int)cpu_ptr, private_handle_t::LOCK_STATE_MAPPED, ump_id, ump_mem_handle); if (NULL != hnd) { *pHandle = hnd; return 0; } else { AERR("gralloc_alloc_buffer() failed to allocate handle. ump_handle = %p, ump_id = %d", ump_mem_handle, ump_id); } } else { AERR("gralloc_alloc_buffer() failed to retrieve valid secure id. ump_handle = %p", ump_mem_handle); } ump_mapped_pointer_release(ump_mem_handle); } else { AERR("gralloc_alloc_buffer() failed to map UMP memory. ump_handle = %p", ump_mem_handle); } ump_reference_release(ump_mem_handle); } else { AERR("gralloc_alloc_buffer() failed to allocate UMP memory. size:%d constraints: %d", size, constraints); } } return -1; } #endif }
//static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage, buffer_handle_t* pHandle, bool reserve) static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage, buffer_handle_t* pHandle, int reserve) { #if GRALLOC_ARM_DMA_BUF_MODULE { private_module_t *m = reinterpret_cast<private_module_t *>(dev->common.module); ion_user_handle_t ion_hnd; unsigned char *cpu_ptr; int shared_fd; int ret; unsigned int heap_mask; int Ion_type; bool Ishwc = false; int Ion_flag = 0; if(usage == (GRALLOC_USAGE_HW_COMPOSER|GRALLOC_USAGE_HW_RENDER)) Ishwc = true; //ret = ion_alloc(m->ion_client, size, 0, ION_HEAP_SYSTEM_MASK, 0, &ion_hnd); #ifdef USE_X86 if(usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) Ion_flag = (ION_FLAG_CACHED|ION_FLAG_CACHED_NEEDS_SYNC); if(is_out_log()) ALOGD("usage=%x,protect=%x,ion_flag=%x,mmu=%d",usage,GRALLOC_USAGE_PROTECTED,Ion_flag,g_MMU_stat); if (usage & GRALLOC_USAGE_PROTECTED) //secrue memery { unsigned long phys; ret = ion_secure_alloc(m->ion_client, size,&phys); //ALOGD("secure_alloc ret=%d,phys=%x",ret,(int)phys); if(ret != 0) { AERR("Failed to ion_alloc from ion_client:%d, size: %d", m->ion_client, size); return -1; } private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_ION, usage, size, 0, 0); if (NULL != hnd) { hnd->share_fd = 0; hnd->ion_hnd = 0; hnd->type = 0; hnd->phy_addr = (int)phys; *pHandle = hnd; if(is_out_log()) ALOGD("secure_alloc_ok phy=%x",usage,hnd->phy_addr); return 0; } else { AERR("Gralloc out of mem for ion_client:%d", m->ion_client); } close(shared_fd); return -1; } #endif //ret = ion_alloc(m->ion_client, size, 0, ION_HEAP_SYSTEM_MASK, 0, &ion_hnd); #ifdef USE_X86 if(g_MMU_stat && ((usage&GRALLOC_USAGE_HW_CAMERA_WRITE)==0) && !(usage & GRALLOC_USAGE_PRIVATE_2) && !Ishwc) #else if(g_MMU_stat) #endif { heap_mask = ION_HEAP(ION_VMALLOC_HEAP_ID); #ifdef USE_X86 if (usage & GRALLOC_USAGE_PRIVATE_2) { heap_mask |= ION_HEAP(ION_SECURE_HEAP_ID); } #endif ret = ion_alloc(m->ion_client, size, 0, heap_mask, Ion_flag, &ion_hnd); Ion_type = 1; } else { heap_mask = ION_HEAP(ION_CMA_HEAP_ID); #ifdef USE_X86 if (usage & GRALLOC_USAGE_PRIVATE_2) { heap_mask |= ION_HEAP(ION_SECURE_HEAP_ID); } #endif if (usage == (GRALLOC_USAGE_HW_CAMERA_WRITE|GRALLOC_USAGE_SW_READ_OFTEN)) { ret = ion_alloc(m->ion_client, size, 0,heap_mask, (ION_FLAG_CACHED|ION_FLAG_CACHED_NEEDS_SYNC), &ion_hnd); } else { ret = ion_alloc(m->ion_client, size, 0,heap_mask, Ion_flag, &ion_hnd); } #ifdef USE_X86 if(g_MMU_stat && Ishwc) { Ion_type = 1; } else #endif Ion_type = 0; } if (ret != 0) { if( (heap_mask & ION_HEAP(ION_CMA_HEAP_ID)) #ifdef USE_X86 && !Ishwc #endif ) { #ifdef BOARD_WITH_IOMMU heap_mask = ION_HEAP(ION_VMALLOC_HEAP_ID); #else heap_mask = ION_HEAP(ION_CARVEOUT_HEAP_ID); #endif ret = ion_alloc(m->ion_client, size, 0, heap_mask, 0, &ion_hnd ); { if( ret != 0) { AERR("Force to VMALLOC fail ion_client:%d", m->ion_client); return -1; } else { ALOGD("Force to VMALLOC sucess !"); Ion_type = 1; } } } else { AERR("Failed to ion_alloc from ion_client:%d, size: %d", m->ion_client, size); return -1; } } ret = ion_share(m->ion_client, ion_hnd, &shared_fd); if (ret != 0) { AERR("ion_share( %d ) failed", m->ion_client); if (0 != ion_free(m->ion_client, ion_hnd)) { AERR("ion_free( %d ) failed", m->ion_client); } return -1; } cpu_ptr = (unsigned char *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, shared_fd, 0); #ifdef USE_X86 //memset(cpu_ptr, 0, size); #endif if (MAP_FAILED == cpu_ptr) { AERR("ion_map( %d ) failed", m->ion_client); if (0 != ion_free(m->ion_client, ion_hnd)) { AERR("ion_free( %d ) failed", m->ion_client); } close(shared_fd); return -1; } private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_ION, usage, size, (int)cpu_ptr, private_handle_t::LOCK_STATE_MAPPED); if (NULL != hnd) { unsigned long cma_phys = 0; hnd->share_fd = shared_fd; hnd->ion_hnd = ion_hnd; hnd->type = Ion_type; if(!Ion_type) { int pret; pret = ion_get_phys(m->ion_client, ion_hnd, &cma_phys); //ALOGD("ion_get_phy ret=%d,cma_phys=%x",pret,cma_phys); } hnd->phy_addr = (int)cma_phys; *pHandle = hnd; if(is_out_log()) ALOGD("alloc_info fd[%d],type=%d,phy=%x",hnd->share_fd,hnd->type,hnd->phy_addr); return 0; } else { AERR("Gralloc out of mem for ion_client:%d", m->ion_client); } close(shared_fd); ret = munmap(cpu_ptr, size); if (0 != ret) { AERR("munmap failed for base:%p size: %d", cpu_ptr, size); } ret = ion_free(m->ion_client, ion_hnd); if (0 != ret) { AERR("ion_free( %d ) failed", m->ion_client); } return -1; } #endif #if GRALLOC_ARM_UMP_MODULE { ump_handle ump_mem_handle; void *cpu_ptr; ump_secure_id ump_id; int constraints; size = round_up_to_page_size(size); if ((usage & GRALLOC_USAGE_SW_READ_MASK) == GRALLOC_USAGE_SW_READ_OFTEN) { constraints = UMP_REF_DRV_CONSTRAINT_USE_CACHE; } else { constraints = UMP_REF_DRV_CONSTRAINT_NONE; } if ( reserve & 0x01) { constraints |= UMP_REF_DRV_CONSTRAINT_PRE_RESERVE; } if( reserve & 0x02) { constraints |= UMP_REF_DRV_UK_CONSTRAINT_MEM_SWITCH; } #ifdef GRALLOC_SIMULATE_FAILURES /* if the failure condition matches, fail this iteration */ if (__ump_alloc_should_fail()) { ump_mem_handle = UMP_INVALID_MEMORY_HANDLE; } else #endif { ump_mem_handle = ump_ref_drv_allocate(size, (ump_alloc_constraints)constraints); if (UMP_INVALID_MEMORY_HANDLE != ump_mem_handle) { cpu_ptr = ump_mapped_pointer_get(ump_mem_handle); if (NULL != cpu_ptr) { ump_id = ump_secure_id_get(ump_mem_handle); if (UMP_INVALID_SECURE_ID != ump_id) { private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_UMP, usage, size, (int)cpu_ptr, private_handle_t::LOCK_STATE_MAPPED, ump_id, ump_mem_handle); if (NULL != hnd) { #ifdef USE_LCDC_COMPOSER if( reserve & 0x02) { hnd->phy_addr = 0; } else { hnd->phy_addr = ump_phy_addr_get(ump_mem_handle); } #endif *pHandle = hnd; return 0; } else { AERR("gralloc_alloc_buffer() failed to allocate handle. ump_handle = %p, ump_id = %d", ump_mem_handle, ump_id); } } else { AERR("gralloc_alloc_buffer() failed to retrieve valid secure id. ump_handle = %p", ump_mem_handle); } ump_mapped_pointer_release(ump_mem_handle); } else { AERR("gralloc_alloc_buffer() failed to map UMP memory. ump_handle = %p", ump_mem_handle); } ump_reference_release(ump_mem_handle); } else { AERR("gralloc_alloc_buffer() failed to allocate UMP memory. size:%d constraints: %d", size, constraints); } } return -1; } #endif