x86: add pte_pgprot to 32-bit
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / video / fb_defio.c
bloba0c5d9d90d741499e5cdb6087d138337c494b3e9
1 /*
2 * linux/drivers/video/fb_defio.c
4 * Copyright (C) 2006 Jaya Kumar
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 */
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/string.h>
15 #include <linux/mm.h>
16 #include <linux/slab.h>
17 #include <linux/vmalloc.h>
18 #include <linux/delay.h>
19 #include <linux/interrupt.h>
20 #include <linux/fb.h>
21 #include <linux/list.h>
23 /* to support deferred IO */
24 #include <linux/rmap.h>
25 #include <linux/pagemap.h>
27 /* this is to find and return the vmalloc-ed fb pages */
28 static struct page* fb_deferred_io_nopage(struct vm_area_struct *vma,
29 unsigned long vaddr, int *type)
31 unsigned long offset;
32 struct page *page;
33 struct fb_info *info = vma->vm_private_data;
34 /* info->screen_base is in System RAM */
35 void *screen_base = (void __force *) info->screen_base;
37 offset = (vaddr - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
38 if (offset >= info->fix.smem_len)
39 return NOPAGE_SIGBUS;
41 page = vmalloc_to_page(screen_base + offset);
42 if (!page)
43 return NOPAGE_OOM;
45 get_page(page);
46 if (type)
47 *type = VM_FAULT_MINOR;
48 return page;
51 int fb_deferred_io_fsync(struct file *file, struct dentry *dentry, int datasync)
53 struct fb_info *info = file->private_data;
55 /* Kill off the delayed work */
56 cancel_rearming_delayed_work(&info->deferred_work);
58 /* Run it immediately */
59 return schedule_delayed_work(&info->deferred_work, 0);
61 EXPORT_SYMBOL_GPL(fb_deferred_io_fsync);
63 /* vm_ops->page_mkwrite handler */
64 static int fb_deferred_io_mkwrite(struct vm_area_struct *vma,
65 struct page *page)
67 struct fb_info *info = vma->vm_private_data;
68 struct fb_deferred_io *fbdefio = info->fbdefio;
70 /* this is a callback we get when userspace first tries to
71 write to the page. we schedule a workqueue. that workqueue
72 will eventually mkclean the touched pages and execute the
73 deferred framebuffer IO. then if userspace touches a page
74 again, we repeat the same scheme */
76 /* protect against the workqueue changing the page list */
77 mutex_lock(&fbdefio->lock);
78 list_add(&page->lru, &fbdefio->pagelist);
79 mutex_unlock(&fbdefio->lock);
81 /* come back after delay to process the deferred IO */
82 schedule_delayed_work(&info->deferred_work, fbdefio->delay);
83 return 0;
86 static struct vm_operations_struct fb_deferred_io_vm_ops = {
87 .nopage = fb_deferred_io_nopage,
88 .page_mkwrite = fb_deferred_io_mkwrite,
91 static int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
93 vma->vm_ops = &fb_deferred_io_vm_ops;
94 vma->vm_flags |= ( VM_IO | VM_RESERVED | VM_DONTEXPAND );
95 vma->vm_private_data = info;
96 return 0;
99 /* workqueue callback */
100 static void fb_deferred_io_work(struct work_struct *work)
102 struct fb_info *info = container_of(work, struct fb_info,
103 deferred_work.work);
104 struct list_head *node, *next;
105 struct page *cur;
106 struct fb_deferred_io *fbdefio = info->fbdefio;
108 /* here we mkclean the pages, then do all deferred IO */
109 mutex_lock(&fbdefio->lock);
110 list_for_each_entry(cur, &fbdefio->pagelist, lru) {
111 lock_page(cur);
112 page_mkclean(cur);
113 unlock_page(cur);
116 /* driver's callback with pagelist */
117 fbdefio->deferred_io(info, &fbdefio->pagelist);
119 /* clear the list */
120 list_for_each_safe(node, next, &fbdefio->pagelist) {
121 list_del(node);
123 mutex_unlock(&fbdefio->lock);
126 void fb_deferred_io_init(struct fb_info *info)
128 struct fb_deferred_io *fbdefio = info->fbdefio;
130 BUG_ON(!fbdefio);
131 mutex_init(&fbdefio->lock);
132 info->fbops->fb_mmap = fb_deferred_io_mmap;
133 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
134 INIT_LIST_HEAD(&fbdefio->pagelist);
135 if (fbdefio->delay == 0) /* set a default of 1 s */
136 fbdefio->delay = HZ;
138 EXPORT_SYMBOL_GPL(fb_deferred_io_init);
140 void fb_deferred_io_cleanup(struct fb_info *info)
142 struct fb_deferred_io *fbdefio = info->fbdefio;
144 BUG_ON(!fbdefio);
145 cancel_delayed_work(&info->deferred_work);
146 flush_scheduled_work();
148 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
150 MODULE_LICENSE("GPL");