Skip to content

Commit

Permalink
sunxi-disp: Fall back to kmalloc-ed mem when no fb mem is reserved
Browse files Browse the repository at this point in the history
Since it is now possible to disable fb-mem reservation from the cmdline,
enable the kmalloc fallback path even if CONFIG_FB_SUNXI_RESERVED_MEM is set.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  • Loading branch information
jwrdegoede authored and amery committed Feb 15, 2013
1 parent 6409b68 commit e046d49
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 53 deletions.
58 changes: 25 additions & 33 deletions drivers/video/sunxi/disp/dev_disp.c
Expand Up @@ -313,13 +313,30 @@ __s32 DRV_DISP_Exit(void)
static int
disp_mem_request(int sel, __u32 size)
{
#ifndef CONFIG_FB_SUNXI_RESERVED_MEM
unsigned map_size = 0;
struct page *page;

if (g_disp_mm[sel].info_base != NULL)
return -EINVAL;

#ifdef CONFIG_FB_SUNXI_RESERVED_MEM
if (fb_size) {
void *ret = disp_malloc(size);
if (ret) {
g_disp_mm[sel].info_base = ret;
g_disp_mm[sel].mem_start =
virt_to_phys(g_disp_mm[sel].info_base);
memset(g_disp_mm[sel].info_base, 0, size);
__inf("pa=0x%08lx va=0x%p size:0x%x\n",
g_disp_mm[sel].mem_start,
g_disp_mm[sel].info_base, size);
return 0;
} else {
__wrn("disp_malloc fail!\n");
return -ENOMEM;
}
}
#endif
g_disp_mm[sel].mem_len = size;
map_size = PAGE_ALIGN(g_disp_mm[sel].mem_len);

Expand All @@ -342,50 +359,25 @@ disp_mem_request(int sel, __u32 size)
__wrn("alloc_pages fail!\n");
return -ENOMEM;
}
#else
void *ret;

ret = disp_malloc(size);
if (ret) {
g_disp_mm[sel].info_base = ret;
g_disp_mm[sel].mem_start =
virt_to_phys(g_disp_mm[sel].info_base);
memset(g_disp_mm[sel].info_base, 0, size);
__inf("pa=0x%08lx va=0x%p size:0x%x\n",
g_disp_mm[sel].mem_start, g_disp_mm[sel].info_base, size);

return 0;
} else {
__wrn("disp_malloc fail!\n");
return -ENOMEM;
}
#endif

}

static int
disp_mem_release(int sel)
{
#ifndef CONFIG_FB_SUNXI_RESERVED_MEM
unsigned map_size = PAGE_ALIGN(g_disp_mm[sel].mem_len);
unsigned page_size = map_size;

if (g_disp_mm[sel].info_base == 0)
return -EINVAL;

free_pages((unsigned long)(g_disp_mm[sel].info_base),
get_order(page_size));
memset(&g_disp_mm[sel], 0, sizeof(struct info_mm));
#else
if (g_disp_mm[sel].info_base == NULL)
return -EINVAL;

disp_free((void *)g_disp_mm[sel].info_base);
memset(&g_disp_mm[sel], 0, sizeof(struct info_mm));
#ifdef CONFIG_FB_SUNXI_RESERVED_MEM
if (fb_size)
disp_free((void *)g_disp_mm[sel].info_base);
else
#endif

free_pages((unsigned long)(g_disp_mm[sel].info_base),
get_order(map_size));
memset(&g_disp_mm[sel], 0, sizeof(struct info_mm));
return 0;

}

int disp_mmap(struct file *filp, struct vm_area_struct *vma)
Expand Down
40 changes: 20 additions & 20 deletions drivers/video/sunxi/disp/dev_fb.c
Expand Up @@ -170,12 +170,6 @@ parser_disp_init_para(__disp_init_t *init_para)
return -1;
}
init_para->b_init = value;
#ifdef CONFIG_FB_SUNXI_RESERVED_MEM
if (init_para->b_init && fb_size == 0) {
pr_warn("0 bytes reserved for fb mem, disabling display\n");
init_para->b_init = 0;
}
#endif

if (script_parser_fetch("disp_init", "disp_mode", &value, 1) < 0) {
__wrn("fetch script data disp_init.disp_mode fail\n");
Expand Down Expand Up @@ -471,10 +465,13 @@ fb_draw_gray_pictures(__u32 base, __u32 width, __u32 height,

static int __init Fb_map_video_memory(__u32 fb_id, struct fb_info *info)
{
#ifndef CONFIG_FB_SUNXI_RESERVED_MEM
unsigned map_size = PAGE_ALIGN(info->fix.smem_len);
struct page *page;

#ifdef CONFIG_FB_SUNXI_RESERVED_MEM
if (fb_size)
goto use_reserved_mem;
#endif
page = alloc_pages(GFP_KERNEL, get_order(map_size));
if (page != NULL) {
info->screen_base = page_address(page);
Expand All @@ -487,7 +484,8 @@ static int __init Fb_map_video_memory(__u32 fb_id, struct fb_info *info)
__wrn("alloc_pages fail!\n");
return -ENOMEM;
}
#else
#ifdef CONFIG_FB_SUNXI_RESERVED_MEM
use_reserved_mem:
g_fbi.malloc_screen_base[fb_id] = disp_malloc(info->fix.smem_len);
if (g_fbi.malloc_screen_base[fb_id] == NULL)
return -ENOMEM;
Expand All @@ -513,20 +511,22 @@ static int __init Fb_map_video_memory(__u32 fb_id, struct fb_info *info)

static inline void Fb_unmap_video_memory(__u32 fb_id, struct fb_info *info)
{
#ifndef CONFIG_FB_SUNXI_RESERVED_MEM
unsigned map_size = PAGE_ALIGN(info->fix.smem_len);

free_pages((unsigned long)info->screen_base, get_order(map_size));
#else
if ((void *)info->screen_base != g_fbi.malloc_screen_base[fb_id]) {
__inf("Fb_unmap_video_memory: fb_id=%d, iounmap(%p)\n",
fb_id, info->screen_base);
iounmap(info->screen_base);
}
__inf("Fb_unmap_video_memory: fb_id=%d, disp_free(%p)\n",
fb_id, g_fbi.malloc_screen_base[fb_id]);
disp_free(g_fbi.malloc_screen_base[fb_id]);
#ifdef CONFIG_FB_SUNXI_RESERVED_MEM
if (fb_size) {
if ((void *)info->screen_base !=
g_fbi.malloc_screen_base[fb_id]) {
__inf("Fb_unmap_video_memory: fb_id=%d, iounmap(%p)\n",
fb_id, info->screen_base);
iounmap(info->screen_base);
}
__inf("Fb_unmap_video_memory: fb_id=%d, disp_free(%p)\n",
fb_id, g_fbi.malloc_screen_base[fb_id]);
disp_free(g_fbi.malloc_screen_base[fb_id]);
} else
#endif
free_pages((unsigned long)info->screen_base,
get_order(map_size));
}

/*
Expand Down

0 comments on commit e046d49

Please sign in to comment.