# \[PATCH\] fb\_defio: add first\_io callback

- Subsystems: FRAMEBUFFER LAYER, THE REST
- Maintainers: Helge Deller, Linus Torvalds
- List: linux-fbdev
- 3 messages, 2 authors
- Page: https://ratatoskr.run/linux-fbdev/2011/12/13462352/t

## \[PATCH\] fb\_defio: add first\_io callback

- From: Heiko Stübner \<heiko@sntech.de\>
- Date: 2011-12-31 10:45:47 
- Message: https://ratatoskr.run/linux-fbdev/2011/12/13462352.md

```text
With this optional callback the driver is notified when the first page
is entered into the pagelist and a new deferred_io call is scheduled.

A possible use-case for this is runtime-pm. In the first_io call
	pm_runtime_get()
could be called, which starts an asynchronous runtime_resume of the
device. In the deferred_io callback a call to
	pm_runtime_barrier()
makes the sure, the device is resumed by then and a
	pm_runtime_put()
may put the device back to sleep.

Also, some SoCs may use the runtime-pm system to determine if they
are able to enter deeper idle states. Therefore it is necessary to
keep the use-count from the first written page until the conclusion
of the screen update, to prevent the system from going to sleep before
completing the pending update.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 drivers/video/fb_defio.c |    4 ++++
 include/linux/fb.h       |    1 +
 2 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
index c27e153..070f26f 100644
--- a/drivers/video/fb_defio.c
+++ b/drivers/video/fb_defio.c
@@ -107,6 +107,10 @@ static int fb_deferred_io_mkwrite(struct vm_area_struct *vma,
 	/* protect against the workqueue changing the page list */
 	mutex_lock(&fbdefio->lock);
 
+	/* first write in this cycle, notify the driver */
+	if (fbdefio->first_io && list_empty(&fbdefio->pagelist))
+		fbdefio->first_io(info);
+
 	/*
 	 * We want the page to remain locked from ->page_mkwrite until
 	 * the PTE is marked dirty to avoid page_mkclean() being called
diff --git a/include/linux/fb.h b/include/linux/fb.h
index 1d6836c..b86cd41 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -602,6 +602,7 @@ struct fb_deferred_io {
 	struct mutex lock; /* mutex that protects the page list */
 	struct list_head pagelist; /* list of touched pages */
 	/* callback */
+	void (*first_io)(struct fb_info *info);
 	void (*deferred_io)(struct fb_info *info, struct list_head *pagelist);
 };
 #endif
-- 
1.7.2.3

```

## Re: \[PATCH\] fb\_defio: add first\_io callback

- From: Florian Tobias Schandinat \<FlorianSchandinat@gmx.de\>
- Date: 2012-02-16 02:27:25 
- Message: https://ratatoskr.run/linux-fbdev/2012/02/13462650.md

```text
Hi Heiko,

sorry for the long delay.

On 12/31/2011 10:45 AM, Heiko Stübner wrote:
> With this optional callback the driver is notified when the first page
> is entered into the pagelist and a new deferred_io call is scheduled.
> 
> A possible use-case for this is runtime-pm. In the first_io call
> 	pm_runtime_get()
> could be called, which starts an asynchronous runtime_resume of the
> device. In the deferred_io callback a call to
> 	pm_runtime_barrier()
> makes the sure, the device is resumed by then and a
> 	pm_runtime_put()
> may put the device back to sleep.
> 
> Also, some SoCs may use the runtime-pm system to determine if they
> are able to enter deeper idle states. Therefore it is necessary to
> keep the use-count from the first written page until the conclusion
> of the screen update, to prevent the system from going to sleep before
> completing the pending update.
> 
> Signed-off-by: Heiko Stuebner <heiko@sntech.de>

while I consider this patch acceptable, I don't see any reason to apply it as
long as there is no driver actually using it.


Best regards,

Florian Tobias Schandinat

> ---
>  drivers/video/fb_defio.c |    4 ++++
>  include/linux/fb.h       |    1 +
>  2 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
> index c27e153..070f26f 100644
> --- a/drivers/video/fb_defio.c
> +++ b/drivers/video/fb_defio.c
> @@ -107,6 +107,10 @@ static int fb_deferred_io_mkwrite(struct vm_area_struct *vma,
>  	/* protect against the workqueue changing the page list */
>  	mutex_lock(&fbdefio->lock);
>  
> +	/* first write in this cycle, notify the driver */
> +	if (fbdefio->first_io && list_empty(&fbdefio->pagelist))
> +		fbdefio->first_io(info);
> +
>  	/*
>  	 * We want the page to remain locked from ->page_mkwrite until
>  	 * the PTE is marked dirty to avoid page_mkclean() being called
> diff --git a/include/linux/fb.h b/include/linux/fb.h
> index 1d6836c..b86cd41 100644
> --- a/include/linux/fb.h
> +++ b/include/linux/fb.h
> @@ -602,6 +602,7 @@ struct fb_deferred_io {
>  	struct mutex lock; /* mutex that protects the page list */
>  	struct list_head pagelist; /* list of touched pages */
>  	/* callback */
> +	void (*first_io)(struct fb_info *info);
>  	void (*deferred_io)(struct fb_info *info, struct list_head *pagelist);
>  };
>  #endif

```

## Re: \[PATCH\] fb\_defio: add first\_io callback

- From: Heiko Stübner \<heiko@sntech.de\>
- Date: 2012-02-16 07:34:09 
- Message: https://ratatoskr.run/linux-fbdev/2012/02/13462651.md

```text
Hi Florian,

Am Donnerstag, 16. Februar 2012, 03:27:25 schrieb Florian Tobias Schandinat:
> Hi Heiko,
> 
> sorry for the long delay.
no problem


> On 12/31/2011 10:45 AM, Heiko Stübner wrote:
> > With this optional callback the driver is notified when the first page
> > is entered into the pagelist and a new deferred_io call is scheduled.
> > 
> > A possible use-case for this is runtime-pm. In the first_io call
> > 
> > 	pm_runtime_get()
> > 
> > could be called, which starts an asynchronous runtime_resume of the
> > device. In the deferred_io callback a call to
> > 
> > 	pm_runtime_barrier()
> > 
> > makes the sure, the device is resumed by then and a
> > 
> > 	pm_runtime_put()
> > 
> > may put the device back to sleep.
> > 
> > Also, some SoCs may use the runtime-pm system to determine if they
> > are able to enter deeper idle states. Therefore it is necessary to
> > keep the use-count from the first written page until the conclusion
> > of the screen update, to prevent the system from going to sleep before
> > completing the pending update.
> > 
> > Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> 
> while I consider this patch acceptable, I don't see any reason to apply it
> as long as there is no driver actually using it.
ok, so I will keep sitting on it until my driver for the AUO-K190x epd 
controller is ready for primetime and resubmit this patch in conjunction with 
it.

Heiko
```
