Revert "video: tegra: dc: manage alloc/release framebuffer memory by driver"
Prafull Suryawanshi [Mon, 19 Oct 2015 11:26:26 +0000 (16:26 +0530)]
Bug 200147064
Bug 1602113

This reverts commit 69867681b50f345c9180d63570a8436a33557809.

Change-Id: I3a65157580b542bee5f15bc9980c558b4047bec7
Signed-off-by: Prafull Suryawanshi <prafulls@nvidia.com>
Reviewed-on: http://git-master/r/819593
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>

arch/arm/mach-tegra/include/mach/dc.h
drivers/platform/tegra/common.c
drivers/video/tegra/dc/dc_priv.h
drivers/video/tegra/dc/ext/dev.c
drivers/video/tegra/dc/of_dc.c
drivers/video/tegra/fb.c

index fc7098f..04d0cd9 100644 (file)
@@ -978,7 +978,6 @@ struct tegra_fb_data {
        int             xres;
        int             yres;
        int             bits_per_pixel; /* -1 means autodetect */
-       size_t          fbmem_size;
 
        unsigned long   flags;
 };
index 233d4b4..b002e93 100644 (file)
@@ -2205,16 +2205,16 @@ void tegra_reserve4(ulong carveout_size, ulong fb_size,
 
 void tegra_get_fb_resource(struct resource *fb_res)
 {
-       fb_res->start = (resource_size_t) tegra_bootloader_fb_start;
+       fb_res->start = (resource_size_t) tegra_fb_start;
        fb_res->end = fb_res->start +
-                       (resource_size_t) tegra_bootloader_fb_size - 1;
+                       (resource_size_t) tegra_fb_size - 1;
 }
 
 void tegra_get_fb2_resource(struct resource *fb2_res)
 {
-       fb2_res->start = (resource_size_t) tegra_bootloader_fb2_start;
+       fb2_res->start = (resource_size_t) tegra_fb2_start;
        fb2_res->end = fb2_res->start +
-                       (resource_size_t) tegra_bootloader_fb2_size - 1;
+                       (resource_size_t) tegra_fb2_size - 1;
 }
 
 
index a3df5f7..279e29f 100644 (file)
@@ -634,5 +634,4 @@ int tegra_nvdisp_update_cmu(struct tegra_dc *dc, struct tegra_dc_lut *lut);
 void tegra_dc_cache_cmu(struct tegra_dc *dc, struct tegra_dc_cmu *src_cmu);
 #endif
 
-int tegra_fb_release_fbmem(struct tegra_fb_info *);
 #endif
index 09f5798..c25a428 100644 (file)
@@ -851,10 +851,7 @@ static void tegra_dc_ext_flip_worker(struct kthread_work *work)
 
        /* unpin and deref previous front buffers */
        tegra_dc_ext_unpin_handles(unpin_handles, nr_unpin);
-#ifdef CONFIG_ANDROID
-       /* now DC has submitted buffer for display, try to release fbmem */
-       tegra_fb_release_fbmem(ext->dc->fb);
-#endif
+
        kfree(data);
        kfree(blank_win);
 }
index fc1da7c..5a59b0a 100644 (file)
@@ -2192,11 +2192,6 @@ struct tegra_dc_platform_data
                goto fail_parse;
        }
 
-       if (!of_property_read_u32(np, "nvidia,fbmem-size", &temp)) {
-               pdata->fb->fbmem_size = (int)temp;
-               OF_DC_LOG("fbmem size %d\n", pdata->fb->fbmem_size);
-       }
-
        if (!of_property_read_u32(np, "nvidia,fb-flags", &temp)) {
                if (temp == TEGRA_FB_FLIP_ON_PROBE)
                        OF_DC_LOG("fb flip on probe\n");
index f62c4fe..05ece53 100644 (file)
@@ -25,7 +25,6 @@
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/mm.h>
-#include <linux/highmem.h>
 #include <linux/uaccess.h>
 #include <linux/slab.h>
 #include <linux/file.h>
@@ -55,9 +54,6 @@
 #define user_ptr(p) (p)
 #endif
 
-/* support up to 4K (3840x2150) with double buffering */
-#define DEFAULT_FBMEM_SIZE     (SZ_64M + SZ_8M)
-
 struct tegra_fb_info {
        struct tegra_dc_win     win;
        struct tegra_dc_win     blank_win;
@@ -66,7 +62,6 @@ struct tegra_fb_info {
        bool                    valid;
 
        struct resource         *fb_mem;
-       size_t                  fb_size;
 
        int                     xres;
        int                     yres;
@@ -75,8 +70,6 @@ struct tegra_fb_info {
 
        struct fb_videomode     mode;
        phys_addr_t             phys_start;
-       int                     kuse_count;
-       int                     mmap_count;
 
        char __iomem            *blank_base;    /* Virtual address */
        phys_addr_t             blank_start;
@@ -85,43 +78,6 @@ struct tegra_fb_info {
 /* palette array used by the fbcon */
 static u32 pseudo_palette[16];
 
-int tegra_fb_release_fbmem(struct tegra_fb_info *info)
-{
-       if (info && info->phys_start) {
-               /* do not release the framebuffer if:
-                * 1) kernel is using (e.g. fbcon)
-                * 2) user space has mmap
-                */
-               if (info->kuse_count || info->mmap_count)
-                       return -EBUSY;
-
-               dma_free_writecombine(&info->ndev->dev,
-                               info->fb_size,
-                               info->win.virt_addr,
-                               info->phys_start);
-
-               info->phys_start = 0;
-               info->win.virt_addr = NULL;
-       }
-       return 0;
-}
-
-static int tegra_fb_open(struct fb_info *fb_info, int user)
-{
-       struct tegra_fb_info *info = fb_info->par;
-       if (user == 0)
-               info->kuse_count++;
-       return 0;
-}
-
-static int tegra_fb_release(struct fb_info *fb_info, int user)
-{
-       struct tegra_fb_info *info = fb_info->par;
-       if (user == 0)
-               info->kuse_count--;
-       return 0;
-}
-
 static int tegra_fb_check_var(struct fb_var_screeninfo *var,
                              struct fb_info *info)
 {
@@ -647,24 +603,8 @@ static int tegra_fb_set_mode(struct tegra_dc *dc, int fps)
        return -EIO;
 }
 
-static int tegra_fb_mmap(struct fb_info *fb_info, struct vm_area_struct *vma)
-{
-       struct tegra_fb_info *info = fb_info->par;
-
-       if (info->phys_start) {
-               info->mmap_count++;
-               return dma_mmap_writecombine(&info->ndev->dev, vma,
-                               info->win.virt_addr,
-                               info->phys_start,
-                               info->fb_size);
-       }
-       return -ENOMEM;
-}
-
 static struct fb_ops tegra_fb_ops = {
        .owner = THIS_MODULE,
-       .fb_open = tegra_fb_open,
-       .fb_release = tegra_fb_release,
        .fb_check_var = tegra_fb_check_var,
        .fb_set_par = tegra_fb_set_par,
        .fb_setcmap = tegra_fb_setcmap,
@@ -677,7 +617,6 @@ static struct fb_ops tegra_fb_ops = {
 #ifdef CONFIG_COMPAT
        .fb_compat_ioctl = tegra_fb_ioctl,
 #endif
-       .fb_mmap = tegra_fb_mmap,
 };
 
 /* Enabling the pan_display by resetting the cache of offset */
@@ -914,28 +853,6 @@ struct tegra_dc_win *tegra_fb_get_blank_win(struct tegra_fb_info *tegra_fb)
        return &tegra_fb->blank_win;
 }
 
-static void tegra_fb_copy_fbmem(void *to, size_t size, struct resource *fb)
-{
-       size_t i;
-       phys_addr_t from = fb->start;
-       size = min_t(size_t, size, resource_size(fb));
-
-       if (!from || size <= 0)
-               return;
-
-       BUG_ON(PAGE_ALIGN((unsigned long)to) != (unsigned long)to);
-       BUG_ON(PAGE_ALIGN(from) != from);
-       BUG_ON(PAGE_ALIGN(size) != size);
-       BUG_ON(!pfn_valid(page_to_pfn(phys_to_page(from))));
-
-       for (i = 0; i < size; i += PAGE_SIZE) {
-               struct page *page = phys_to_page(from + i);
-               void *from_virt = kmap(page);
-               memcpy(to + i, from_virt, PAGE_SIZE);
-               kunmap(page);
-       }
-}
-
 struct tegra_fb_info *tegra_fb_register(struct platform_device *ndev,
                                        struct tegra_dc *dc,
                                        struct tegra_fb_data *fb_data,
@@ -944,7 +861,7 @@ struct tegra_fb_info *tegra_fb_register(struct platform_device *ndev,
 {
        struct fb_info *info;
        struct tegra_fb_info *tegra_fb;
-       void *fb_base = NULL;
+       void __iomem *fb_base = NULL;
        phys_addr_t fb_size = 0;
        int ret = 0;
        int mode_idx;
@@ -972,20 +889,22 @@ struct tegra_fb_info *tegra_fb_register(struct platform_device *ndev,
 
        tegra_fb->win.idx = fb_data->win;
 
-       fb_size = fb_data->fbmem_size ? : DEFAULT_FBMEM_SIZE;
-       fb_base = dma_alloc_writecombine(&ndev->dev, fb_size,
-                       &tegra_fb->phys_start, GFP_KERNEL);
-       if (!fb_base) {
-               dev_err(&ndev->dev, "failed to allocate framebuffer\n");
-               ret = -EBUSY;
-               goto err_free;
+       if (fb_mem) {
+               fb_size = resource_size(fb_mem);
+               tegra_fb->phys_start = fb_mem->start;
+
+               /* If the caller provided virtual address, meaning the buffer
+                * is already mapped, just use that address */
+               fb_base = virt_addr ? virt_addr :
+                       ioremap_wc(tegra_fb->phys_start, fb_size);
+               if (!fb_base) {
+                       dev_err(&ndev->dev, "fb can't be mapped\n");
+                       ret = -EBUSY;
+                       goto err_free;
+               }
+               tegra_fb->valid = true;
        }
 
-       /* copy content from the bootloader framebuffer */
-       tegra_fb_copy_fbmem(fb_base, fb_size, fb_mem);
-       tegra_fb->fb_size = fb_size;
-       tegra_fb->valid = true;
-
        dma_set_attr(DMA_ATTR_WRITE_COMBINE, &attrs);
        tegra_fb->blank_base = dma_alloc_attrs(&ndev->dev,
                                               BLANK_LINE_SIZE,
@@ -995,7 +914,7 @@ struct tegra_fb_info *tegra_fb_register(struct platform_device *ndev,
        if (!tegra_fb->blank_base) {
                dev_err(&ndev->dev, "failed to allocate blank buffer\n");
                ret = -EBUSY;
-               goto err_free_fbmem;
+               goto err_free;
        }
 
        info->fix.line_length = fb_data->xres * fb_data->bits_per_pixel / 8;
@@ -1104,8 +1023,6 @@ err_iounmap_fb:
                       tegra_fb->blank_start, &attrs);
        if (fb_base)
                iounmap(fb_base);
-err_free_fbmem:
-       tegra_fb_release_fbmem(tegra_fb);
 err_free:
        framebuffer_release(info);
 err:
@@ -1123,8 +1040,8 @@ void tegra_fb_unregister(struct tegra_fb_info *fb_info)
        dma_free_attrs(dev, BLANK_LINE_SIZE, fb_info->blank_base,
                       fb_info->blank_start, &attrs);
 
-       tegra_fb_release_fbmem(fb_info);
        unregister_framebuffer(info);
+
        iounmap(info->screen_base);
        framebuffer_release(info);
 }