blob: 7300cff255a39a22d4d69c64abea633ed7a6feab [file] [log] [blame]
Mauro Carvalho Chehabab42b812019-06-12 14:52:45 -03001===========
Jaya Kumar60b59be2007-05-08 00:37:37 -07002Deferred IO
Mauro Carvalho Chehabab42b812019-06-12 14:52:45 -03003===========
Jaya Kumar60b59be2007-05-08 00:37:37 -07004
5Deferred IO is a way to delay and repurpose IO. It uses host memory as a
6buffer and the MMU pagefault as a pretrigger for when to perform the device
Matt LaPlante01dd2fb2007-10-20 01:34:40 +02007IO. The following example may be a useful explanation of how one such setup
Jaya Kumar60b59be2007-05-08 00:37:37 -07008works:
9
10- userspace app like Xfbdev mmaps framebuffer
Nick Piggin529e55b2008-02-06 01:39:10 -080011- deferred IO and driver sets up fault and page_mkwrite handlers
Jaya Kumar60b59be2007-05-08 00:37:37 -070012- userspace app tries to write to mmaped vaddress
Nick Piggin529e55b2008-02-06 01:39:10 -080013- we get pagefault and reach fault handler
14- fault handler finds and returns physical page
Jaya Kumar60b59be2007-05-08 00:37:37 -070015- we get page_mkwrite where we add this page to a list
16- schedule a workqueue task to be run after a delay
17- app continues writing to that page with no additional cost. this is
18 the key benefit.
19- the workqueue task comes in and mkcleans the pages on the list, then
Mauro Carvalho Chehabab42b812019-06-12 14:52:45 -030020 completes the work associated with updating the framebuffer. this is
Jaya Kumar60b59be2007-05-08 00:37:37 -070021 the real work talking to the device.
22- app tries to write to the address (that has now been mkcleaned)
23- get pagefault and the above sequence occurs again
24
25As can be seen from above, one benefit is roughly to allow bursty framebuffer
26writes to occur at minimum cost. Then after some time when hopefully things
27have gone quiet, we go and really update the framebuffer which would be
28a relatively more expensive operation.
29
30For some types of nonvolatile high latency displays, the desired image is
31the final image rather than the intermediate stages which is why it's okay
Matt LaPlante01dd2fb2007-10-20 01:34:40 +020032to not update for each write that is occurring.
Jaya Kumar60b59be2007-05-08 00:37:37 -070033
34It may be the case that this is useful in other scenarios as well. Paul Mundt
35has mentioned a case where it is beneficial to use the page count to decide
36whether to coalesce and issue SG DMA or to do memory bursts.
37
38Another one may be if one has a device framebuffer that is in an usual format,
39say diagonally shifting RGB, this may then be a mechanism for you to allow
40apps to pretend to have a normal framebuffer but reswizzle for the device
41framebuffer at vsync time based on the touched pagelist.
42
43How to use it: (for applications)
44---------------------------------
45No changes needed. mmap the framebuffer like normal and just use it.
46
47How to use it: (for fbdev drivers)
48----------------------------------
49The following example may be helpful.
50
Mauro Carvalho Chehabab42b812019-06-12 14:52:45 -0300511. Setup your structure. Eg::
Jaya Kumar60b59be2007-05-08 00:37:37 -070052
Mauro Carvalho Chehabab42b812019-06-12 14:52:45 -030053 static struct fb_deferred_io hecubafb_defio = {
54 .delay = HZ,
55 .deferred_io = hecubafb_dpy_deferred_io,
56 };
Jaya Kumar60b59be2007-05-08 00:37:37 -070057
58The delay is the minimum delay between when the page_mkwrite trigger occurs
59and when the deferred_io callback is called. The deferred_io callback is
60explained below.
61
Mauro Carvalho Chehabab42b812019-06-12 14:52:45 -0300622. Setup your deferred IO callback. Eg::
63
64 static void hecubafb_dpy_deferred_io(struct fb_info *info,
65 struct list_head *pagelist)
Jaya Kumar60b59be2007-05-08 00:37:37 -070066
67The deferred_io callback is where you would perform all your IO to the display
68device. You receive the pagelist which is the list of pages that were written
69to during the delay. You must not modify this list. This callback is called
70from a workqueue.
71
Mauro Carvalho Chehabab42b812019-06-12 14:52:45 -0300723. Call init::
73
Jaya Kumar60b59be2007-05-08 00:37:37 -070074 info->fbdefio = &hecubafb_defio;
75 fb_deferred_io_init(info);
76
Mauro Carvalho Chehabab42b812019-06-12 14:52:45 -0300774. Call cleanup::
78
Jaya Kumar60b59be2007-05-08 00:37:37 -070079 fb_deferred_io_cleanup(info);