diff options
-rw-r--r-- | Documentation/fb/deferred_io.txt | 75 | ||||
-rw-r--r-- | drivers/video/Kconfig | 5 | ||||
-rw-r--r-- | drivers/video/Makefile | 1 | ||||
-rw-r--r-- | drivers/video/fb_defio.c | 137 | ||||
-rw-r--r-- | include/linux/fb.h | 20 | ||||
-rw-r--r-- | mm/rmap.c | 1 |
6 files changed, 239 insertions, 0 deletions
diff --git a/Documentation/fb/deferred_io.txt b/Documentation/fb/deferred_io.txt new file mode 100644 index 000000000000..73cf9fb7cf60 --- /dev/null +++ b/Documentation/fb/deferred_io.txt | |||
@@ -0,0 +1,75 @@ | |||
1 | Deferred IO | ||
2 | ----------- | ||
3 | |||
4 | Deferred IO is a way to delay and repurpose IO. It uses host memory as a | ||
5 | buffer and the MMU pagefault as a pretrigger for when to perform the device | ||
6 | IO. The following example may be a useful explaination of how one such setup | ||
7 | works: | ||
8 | |||
9 | - userspace app like Xfbdev mmaps framebuffer | ||
10 | - deferred IO and driver sets up nopage and page_mkwrite handlers | ||
11 | - userspace app tries to write to mmaped vaddress | ||
12 | - we get pagefault and reach nopage handler | ||
13 | - nopage handler finds and returns physical page | ||
14 | - we get page_mkwrite where we add this page to a list | ||
15 | - schedule a workqueue task to be run after a delay | ||
16 | - app continues writing to that page with no additional cost. this is | ||
17 | the key benefit. | ||
18 | - the workqueue task comes in and mkcleans the pages on the list, then | ||
19 | completes the work associated with updating the framebuffer. this is | ||
20 | the real work talking to the device. | ||
21 | - app tries to write to the address (that has now been mkcleaned) | ||
22 | - get pagefault and the above sequence occurs again | ||
23 | |||
24 | As can be seen from above, one benefit is roughly to allow bursty framebuffer | ||
25 | writes to occur at minimum cost. Then after some time when hopefully things | ||
26 | have gone quiet, we go and really update the framebuffer which would be | ||
27 | a relatively more expensive operation. | ||
28 | |||
29 | For some types of nonvolatile high latency displays, the desired image is | ||
30 | the final image rather than the intermediate stages which is why it's okay | ||
31 | to not update for each write that is occuring. | ||
32 | |||
33 | It may be the case that this is useful in other scenarios as well. Paul Mundt | ||
34 | has mentioned a case where it is beneficial to use the page count to decide | ||
35 | whether to coalesce and issue SG DMA or to do memory bursts. | ||
36 | |||
37 | Another one may be if one has a device framebuffer that is in an usual format, | ||
38 | say diagonally shifting RGB, this may then be a mechanism for you to allow | ||
39 | apps to pretend to have a normal framebuffer but reswizzle for the device | ||
40 | framebuffer at vsync time based on the touched pagelist. | ||
41 | |||
42 | How to use it: (for applications) | ||
43 | --------------------------------- | ||
44 | No changes needed. mmap the framebuffer like normal and just use it. | ||
45 | |||
46 | How to use it: (for fbdev drivers) | ||
47 | ---------------------------------- | ||
48 | The following example may be helpful. | ||
49 | |||
50 | 1. Setup your structure. Eg: | ||
51 | |||
52 | static struct fb_deferred_io hecubafb_defio = { | ||
53 | .delay = HZ, | ||
54 | .deferred_io = hecubafb_dpy_deferred_io, | ||
55 | }; | ||
56 | |||
57 | The delay is the minimum delay between when the page_mkwrite trigger occurs | ||
58 | and when the deferred_io callback is called. The deferred_io callback is | ||
59 | explained below. | ||
60 | |||
61 | 2. Setup your deferred IO callback. Eg: | ||
62 | static void hecubafb_dpy_deferred_io(struct fb_info *info, | ||
63 | struct list_head *pagelist) | ||
64 | |||
65 | The deferred_io callback is where you would perform all your IO to the display | ||
66 | device. You receive the pagelist which is the list of pages that were written | ||
67 | to during the delay. You must not modify this list. This callback is called | ||
68 | from a workqueue. | ||
69 | |||
70 | 3. Call init | ||
71 | info->fbdefio = &hecubafb_defio; | ||
72 | fb_deferred_io_init(info); | ||
73 | |||
74 | 4. Call cleanup | ||
75 | fb_deferred_io_cleanup(info); | ||
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 8dfa88a68ae9..61c0a03d33f2 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig | |||
@@ -91,6 +91,11 @@ config FB_CFB_IMAGEBLIT | |||
91 | blitting. This is used by drivers that don't provide their own | 91 | blitting. This is used by drivers that don't provide their own |
92 | (accelerated) version. | 92 | (accelerated) version. |
93 | 93 | ||
94 | config FB_DEFERRED_IO | ||
95 | bool | ||
96 | depends on FB | ||
97 | default y | ||
98 | |||
94 | config FB_SVGALIB | 99 | config FB_SVGALIB |
95 | tristate | 100 | tristate |
96 | depends on FB | 101 | depends on FB |
diff --git a/drivers/video/Makefile b/drivers/video/Makefile index 281462414930..deb5fa55f783 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile | |||
@@ -20,6 +20,7 @@ obj-$(CONFIG_FB_CFB_IMAGEBLIT) += cfbimgblt.o | |||
20 | obj-$(CONFIG_FB_SVGALIB) += svgalib.o | 20 | obj-$(CONFIG_FB_SVGALIB) += svgalib.o |
21 | obj-$(CONFIG_FB_MACMODES) += macmodes.o | 21 | obj-$(CONFIG_FB_MACMODES) += macmodes.o |
22 | obj-$(CONFIG_FB_DDC) += fb_ddc.o | 22 | obj-$(CONFIG_FB_DDC) += fb_ddc.o |
23 | obj-$(CONFIG_FB_DEFERRED_IO) += fb_defio.o | ||
23 | 24 | ||
24 | # Hardware specific drivers go first | 25 | # Hardware specific drivers go first |
25 | obj-$(CONFIG_FB_AMIGA) += amifb.o c2p.o | 26 | obj-$(CONFIG_FB_AMIGA) += amifb.o c2p.o |
diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c new file mode 100644 index 000000000000..cc780f4e183d --- /dev/null +++ b/drivers/video/fb_defio.c | |||
@@ -0,0 +1,137 @@ | |||
1 | /* | ||
2 | * linux/drivers/video/fb_defio.c | ||
3 | * | ||
4 | * Copyright (C) 2006 Jaya Kumar | ||
5 | * | ||
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 | */ | ||
10 | |||
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> | ||
22 | #include <asm/uaccess.h> | ||
23 | |||
24 | /* to support deferred IO */ | ||
25 | #include <linux/rmap.h> | ||
26 | #include <linux/pagemap.h> | ||
27 | |||
28 | /* this is to find and return the vmalloc-ed fb pages */ | ||
29 | static struct page* fb_deferred_io_nopage(struct vm_area_struct *vma, | ||
30 | unsigned long vaddr, int *type) | ||
31 | { | ||
32 | unsigned long offset; | ||
33 | struct page *page; | ||
34 | struct fb_info *info = vma->vm_private_data; | ||
35 | |||
36 | offset = (vaddr - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT); | ||
37 | if (offset >= info->fix.smem_len) | ||
38 | return NOPAGE_SIGBUS; | ||
39 | |||
40 | page = vmalloc_to_page(info->screen_base + offset); | ||
41 | if (!page) | ||
42 | return NOPAGE_OOM; | ||
43 | |||
44 | get_page(page); | ||
45 | if (type) | ||
46 | *type = VM_FAULT_MINOR; | ||
47 | return page; | ||
48 | } | ||
49 | |||
50 | /* vm_ops->page_mkwrite handler */ | ||
51 | int fb_deferred_io_mkwrite(struct vm_area_struct *vma, | ||
52 | struct page *page) | ||
53 | { | ||
54 | struct fb_info *info = vma->vm_private_data; | ||
55 | struct fb_deferred_io *fbdefio = info->fbdefio; | ||
56 | |||
57 | /* this is a callback we get when userspace first tries to | ||
58 | write to the page. we schedule a workqueue. that workqueue | ||
59 | will eventually mkclean the touched pages and execute the | ||
60 | deferred framebuffer IO. then if userspace touches a page | ||
61 | again, we repeat the same scheme */ | ||
62 | |||
63 | /* protect against the workqueue changing the page list */ | ||
64 | mutex_lock(&fbdefio->lock); | ||
65 | list_add(&page->lru, &fbdefio->pagelist); | ||
66 | mutex_unlock(&fbdefio->lock); | ||
67 | |||
68 | /* come back after delay to process the deferred IO */ | ||
69 | schedule_delayed_work(&info->deferred_work, fbdefio->delay); | ||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static struct vm_operations_struct fb_deferred_io_vm_ops = { | ||
74 | .nopage = fb_deferred_io_nopage, | ||
75 | .page_mkwrite = fb_deferred_io_mkwrite, | ||
76 | }; | ||
77 | |||
78 | static int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma) | ||
79 | { | ||
80 | vma->vm_ops = &fb_deferred_io_vm_ops; | ||
81 | vma->vm_flags |= ( VM_IO | VM_RESERVED | VM_DONTEXPAND ); | ||
82 | vma->vm_private_data = info; | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | /* workqueue callback */ | ||
87 | static void fb_deferred_io_work(struct work_struct *work) | ||
88 | { | ||
89 | struct fb_info *info = container_of(work, struct fb_info, | ||
90 | deferred_work.work); | ||
91 | struct list_head *node, *next; | ||
92 | struct page *cur; | ||
93 | struct fb_deferred_io *fbdefio = info->fbdefio; | ||
94 | |||
95 | /* here we mkclean the pages, then do all deferred IO */ | ||
96 | mutex_lock(&fbdefio->lock); | ||
97 | list_for_each_entry(cur, &fbdefio->pagelist, lru) { | ||
98 | lock_page(cur); | ||
99 | page_mkclean(cur); | ||
100 | unlock_page(cur); | ||
101 | } | ||
102 | |||
103 | /* driver's callback with pagelist */ | ||
104 | fbdefio->deferred_io(info, &fbdefio->pagelist); | ||
105 | |||
106 | /* clear the list */ | ||
107 | list_for_each_safe(node, next, &fbdefio->pagelist) { | ||
108 | list_del(node); | ||
109 | } | ||
110 | mutex_unlock(&fbdefio->lock); | ||
111 | } | ||
112 | |||
113 | void fb_deferred_io_init(struct fb_info *info) | ||
114 | { | ||
115 | struct fb_deferred_io *fbdefio = info->fbdefio; | ||
116 | |||
117 | BUG_ON(!fbdefio); | ||
118 | mutex_init(&fbdefio->lock); | ||
119 | info->fbops->fb_mmap = fb_deferred_io_mmap; | ||
120 | INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work); | ||
121 | INIT_LIST_HEAD(&fbdefio->pagelist); | ||
122 | if (fbdefio->delay == 0) /* set a default of 1 s */ | ||
123 | fbdefio->delay = HZ; | ||
124 | } | ||
125 | EXPORT_SYMBOL_GPL(fb_deferred_io_init); | ||
126 | |||
127 | void fb_deferred_io_cleanup(struct fb_info *info) | ||
128 | { | ||
129 | struct fb_deferred_io *fbdefio = info->fbdefio; | ||
130 | |||
131 | BUG_ON(!fbdefio); | ||
132 | cancel_delayed_work(&info->deferred_work); | ||
133 | flush_scheduled_work(); | ||
134 | } | ||
135 | EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup); | ||
136 | |||
137 | MODULE_LICENSE("GPL"); | ||
diff --git a/include/linux/fb.h b/include/linux/fb.h index be913ec87169..8a8255b94b62 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h | |||
@@ -561,6 +561,16 @@ struct fb_pixmap { | |||
561 | void (*readio) (struct fb_info *info, void *dst, void __iomem *src, unsigned int size); | 561 | void (*readio) (struct fb_info *info, void *dst, void __iomem *src, unsigned int size); |
562 | }; | 562 | }; |
563 | 563 | ||
564 | #ifdef CONFIG_FB_DEFERRED_IO | ||
565 | struct fb_deferred_io { | ||
566 | /* delay between mkwrite and deferred handler */ | ||
567 | unsigned long delay; | ||
568 | struct mutex lock; /* mutex that protects the page list */ | ||
569 | struct list_head pagelist; /* list of touched pages */ | ||
570 | /* callback */ | ||
571 | void (*deferred_io)(struct fb_info *info, struct list_head *pagelist); | ||
572 | }; | ||
573 | #endif | ||
564 | 574 | ||
565 | /* | 575 | /* |
566 | * Frame buffer operations | 576 | * Frame buffer operations |
@@ -778,6 +788,10 @@ struct fb_info { | |||
778 | struct mutex bl_curve_mutex; | 788 | struct mutex bl_curve_mutex; |
779 | u8 bl_curve[FB_BACKLIGHT_LEVELS]; | 789 | u8 bl_curve[FB_BACKLIGHT_LEVELS]; |
780 | #endif | 790 | #endif |
791 | #ifdef CONFIG_FB_DEFERRED_IO | ||
792 | struct delayed_work deferred_work; | ||
793 | struct fb_deferred_io *fbdefio; | ||
794 | #endif | ||
781 | 795 | ||
782 | struct fb_ops *fbops; | 796 | struct fb_ops *fbops; |
783 | struct device *device; /* This is the parent */ | 797 | struct device *device; /* This is the parent */ |
@@ -913,6 +927,12 @@ static inline void __fb_pad_aligned_buffer(u8 *dst, u32 d_pitch, | |||
913 | } | 927 | } |
914 | } | 928 | } |
915 | 929 | ||
930 | #ifdef CONFIG_FB_DEFERRED_IO | ||
931 | /* drivers/video/fb_defio.c */ | ||
932 | extern void fb_deferred_io_init(struct fb_info *info); | ||
933 | extern void fb_deferred_io_cleanup(struct fb_info *info); | ||
934 | #endif | ||
935 | |||
916 | /* drivers/video/fbsysfs.c */ | 936 | /* drivers/video/fbsysfs.c */ |
917 | extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev); | 937 | extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev); |
918 | extern void framebuffer_release(struct fb_info *info); | 938 | extern void framebuffer_release(struct fb_info *info); |
@@ -505,6 +505,7 @@ int page_mkclean(struct page *page) | |||
505 | 505 | ||
506 | return ret; | 506 | return ret; |
507 | } | 507 | } |
508 | EXPORT_SYMBOL_GPL(page_mkclean); | ||
508 | 509 | ||
509 | /** | 510 | /** |
510 | * page_set_anon_rmap - setup new anonymous rmap | 511 | * page_set_anon_rmap - setup new anonymous rmap |