summaryrefslogtreecommitdiff
path: root/drivers/video/fbdev/core/fb_defio.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/video/fbdev/core/fb_defio.c')
-rw-r--r--drivers/video/fbdev/core/fb_defio.c82
1 files changed, 55 insertions, 27 deletions
diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
index 806ecd32219b..5ee7e78c2cea 100644
--- a/drivers/video/fbdev/core/fb_defio.c
+++ b/drivers/video/fbdev/core/fb_defio.c
@@ -23,33 +23,71 @@
#include <linux/rmap.h>
#include <linux/pagemap.h>
-static struct page *fb_deferred_io_page(struct fb_info *info, unsigned long offs)
+static struct page *fb_deferred_io_get_page(struct fb_info *info, unsigned long offs)
{
- void *screen_base = (void __force *) info->screen_base;
- struct page *page;
+ struct fb_deferred_io *fbdefio = info->fbdefio;
+ const void *screen_buffer = info->screen_buffer;
+ struct page *page = NULL;
- if (is_vmalloc_addr(screen_base + offs))
- page = vmalloc_to_page(screen_base + offs);
- else
+ if (fbdefio->get_page)
+ return fbdefio->get_page(info, offs);
+
+ if (is_vmalloc_addr(screen_buffer + offs))
+ page = vmalloc_to_page(screen_buffer + offs);
+ else if (info->fix.smem_start)
page = pfn_to_page((info->fix.smem_start + offs) >> PAGE_SHIFT);
+ if (page)
+ get_page(page);
+
return page;
}
+static struct fb_deferred_io_pageref *fb_deferred_io_pageref_lookup(struct fb_info *info,
+ unsigned long offset,
+ struct page *page)
+{
+ unsigned long pgoff = offset >> PAGE_SHIFT;
+ struct fb_deferred_io_pageref *pageref;
+
+ if (fb_WARN_ON_ONCE(info, pgoff >= info->npagerefs))
+ return NULL; /* incorrect allocation size */
+
+ /* 1:1 mapping between pageref and page offset */
+ pageref = &info->pagerefs[pgoff];
+
+ if (pageref->page)
+ goto out;
+
+ pageref->page = page;
+ pageref->offset = pgoff << PAGE_SHIFT;
+ INIT_LIST_HEAD(&pageref->list);
+
+out:
+ if (fb_WARN_ON_ONCE(info, pageref->page != page))
+ return NULL; /* inconsistent state */
+ return pageref;
+}
+
+static void fb_deferred_io_pageref_clear(struct fb_deferred_io_pageref *pageref)
+{
+ struct page *page = pageref->page;
+
+ if (page)
+ page->mapping = NULL;
+}
+
static struct fb_deferred_io_pageref *fb_deferred_io_pageref_get(struct fb_info *info,
unsigned long offset,
struct page *page)
{
struct fb_deferred_io *fbdefio = info->fbdefio;
struct list_head *pos = &fbdefio->pagereflist;
- unsigned long pgoff = offset >> PAGE_SHIFT;
struct fb_deferred_io_pageref *pageref, *cur;
- if (WARN_ON_ONCE(pgoff >= info->npagerefs))
- return NULL; /* incorrect allocation size */
-
- /* 1:1 mapping between pageref and page offset */
- pageref = &info->pagerefs[pgoff];
+ pageref = fb_deferred_io_pageref_lookup(info, offset, page);
+ if (!pageref)
+ return NULL;
/*
* This check is to catch the case where a new process could start
@@ -60,9 +98,6 @@ static struct fb_deferred_io_pageref *fb_deferred_io_pageref_get(struct fb_info
if (!list_empty(&pageref->list))
goto pageref_already_added;
- pageref->page = page;
- pageref->offset = pgoff << PAGE_SHIFT;
-
if (unlikely(fbdefio->sort_pagereflist)) {
/*
* We loop through the list of pagerefs before adding in
@@ -101,12 +136,10 @@ static vm_fault_t fb_deferred_io_fault(struct vm_fault *vmf)
if (offset >= info->fix.smem_len)
return VM_FAULT_SIGBUS;
- page = fb_deferred_io_page(info, offset);
+ page = fb_deferred_io_get_page(info, offset);
if (!page)
return VM_FAULT_SIGBUS;
- get_page(page);
-
if (vmf->vma->vm_file)
page->mapping = vmf->vma->vm_file->f_mapping;
else
@@ -264,7 +297,7 @@ int fb_deferred_io_init(struct fb_info *info)
{
struct fb_deferred_io *fbdefio = info->fbdefio;
struct fb_deferred_io_pageref *pagerefs;
- unsigned long npagerefs, i;
+ unsigned long npagerefs;
int ret;
BUG_ON(!fbdefio);
@@ -286,8 +319,6 @@ int fb_deferred_io_init(struct fb_info *info)
ret = -ENOMEM;
goto err;
}
- for (i = 0; i < npagerefs; ++i)
- INIT_LIST_HEAD(&pagerefs[i].list);
info->npagerefs = npagerefs;
info->pagerefs = pagerefs;
@@ -312,16 +343,13 @@ EXPORT_SYMBOL_GPL(fb_deferred_io_open);
static void fb_deferred_io_lastclose(struct fb_info *info)
{
- struct page *page;
- int i;
+ unsigned long i;
flush_delayed_work(&info->deferred_work);
/* clear out the mapping that we setup */
- for (i = 0 ; i < info->fix.smem_len; i += PAGE_SIZE) {
- page = fb_deferred_io_page(info, i);
- page->mapping = NULL;
- }
+ for (i = 0; i < info->npagerefs; ++i)
+ fb_deferred_io_pageref_clear(&info->pagerefs[i]);
}
void fb_deferred_io_release(struct fb_info *info)