dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Stefan Christ <s.christ@phytec.de>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 2/3] drm: fb_helper: implement ioctl FBIO_WAITFORVSYNC
Date: Wed, 13 Jul 2016 12:16:05 +0200	[thread overview]
Message-ID: <20160713101605.GC23520@phenom.ffwll.local> (raw)
In-Reply-To: <1468397508-5112-3-git-send-email-s.christ@phytec.de>

On Wed, Jul 13, 2016 at 10:11:47AM +0200, Stefan Christ wrote:
> Implement legacy framebuffer ioctl FBIO_WAITFORVSYNC in the generic
> framebuffer emulation driver. Legacy framebuffer users like non kms/drm
> based OpenGL(ES)/EGL implementations may require the ioctl to
> synchronize drawing or buffer flip for double buffering. It is tested on
> the i.MX6.
> 
> Code is based on
>     https://github.com/Xilinx/linux-xlnx/blob/master/drivers/gpu/drm/xilinx/xilinx_drm_fb.c#L196
> 
> Signed-off-by: Stefan Christ <s.christ@phytec.de>
> ---
>  drivers/gpu/drm/drm_fb_cma_helper.c |  1 +
>  drivers/gpu/drm/drm_fb_helper.c     | 43 +++++++++++++++++++++++++++++++++++++
>  include/drm/drm_fb_helper.h         |  2 ++
>  3 files changed, 46 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c b/drivers/gpu/drm/drm_fb_cma_helper.c
> index be66042..95657da 100644
> --- a/drivers/gpu/drm/drm_fb_cma_helper.c
> +++ b/drivers/gpu/drm/drm_fb_cma_helper.c
> @@ -313,6 +313,7 @@ static struct fb_ops drm_fbdev_cma_ops = {
>  	.fb_blank	= drm_fb_helper_blank,
>  	.fb_pan_display	= drm_fb_helper_pan_display,
>  	.fb_setcmap	= drm_fb_helper_setcmap,
> +	.fb_ioctl       = drm_fb_helper_ioctl,
>  };
>  
>  static int drm_fbdev_cma_deferred_io_mmap(struct fb_info *info,
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index 7c2eb75..4d1f9b9 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -1167,6 +1167,49 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
>  EXPORT_SYMBOL(drm_fb_helper_setcmap);
>  
>  /**
> + * drm_fb_helper_ioctl - legacy ioctl implementation
> + * @info:
> + * @cmd: ioctl like FBIO_WAITFORVSYNC
> + * @arg: ioctl argument

A bit more verbose kerneldoc would be great. Also, if you add this I think
we should roll it out for all drivers, for consistency of the supported
fbdev features when using emulation.
-Daniel

> + */
> +int drm_fb_helper_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
> +{
> +	struct drm_fb_helper *fb_helper = info->par;
> +	unsigned int i;
> +	int ret = 0;

You must first check whether fbdev owns the kms driver by calling
drm_fb_helper_is_bound(). Not sure whether the ioctl should fail, or
whether you instead should msleep(16) to throttle userspace a bit. Up to
you really.

> +
> +	switch (cmd) {
> +	case FBIO_WAITFORVSYNC:
> +		for (i = 0; i < fb_helper->crtc_count; i++) {
> +			struct drm_mode_set *mode_set;
> +			struct drm_crtc *crtc;
> +
> +			mode_set = &fb_helper->crtc_info[i].mode_set;
> +			crtc = mode_set->crtc;
> +
> +			/*
> +			 * Only call drm_crtc_wait_one_vblank for crtcs that
> +			 * are currently active.
> +			 */
> +			if (!crtc->enabled)
> +				continue;

crtc->enabled != crtc->active, and drm_crtc_vblank_get only works when the
crtc is active. This means this ioctl will fail if the display is
suspended using dpms off/FB_BLANK. Is that what you want?

> +
> +			ret = drm_crtc_vblank_get(crtc);
> +			if (!ret) {
> +				drm_crtc_wait_one_vblank(crtc);
> +				drm_crtc_vblank_put(crtc);
> +			}

			else
				break;

Probably you also need some locking here, drm_modeset_lock(&crtc->mutex);
should be enough. Without that you might race with a dpms off. Might need
more locks, not entirely sure, perhaps also dev->mode_config.mutex for
fbdev emulation state.
-Daniel

> +		}
> +		return ret;
> +	default:
> +		return -ENOTTY;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_fb_helper_ioctl);
> +
> +/**
>   * drm_fb_helper_check_var - implementation for ->fb_check_var
>   * @var: screeninfo to check
>   * @info: fbdev registered by the helper
> diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper.h
> index 5b4aa35..121af93 100644
> --- a/include/drm/drm_fb_helper.h
> +++ b/include/drm/drm_fb_helper.h
> @@ -278,6 +278,8 @@ void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, int state);
>  
>  int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info);
>  
> +int drm_fb_helper_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg);
> +
>  int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper);
>  int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel);
>  int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper);
> -- 
> 1.9.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2016-07-13 10:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-13  8:11 [PATCH 0/3] Support fast framebuffer panning for i.MX6 Stefan Christ
2016-07-13  8:11 ` [PATCH 1/3] drm/cma-helper: Add multi buffer support for cma fbdev Stefan Christ
2016-07-13 10:05   ` Daniel Vetter
2016-07-13  8:11 ` [PATCH 2/3] drm: fb_helper: implement ioctl FBIO_WAITFORVSYNC Stefan Christ
2016-07-13 10:16   ` Daniel Vetter [this message]
2016-07-15  7:19     ` Daniel Vetter
2016-07-27  9:59       ` Stefan Christ
2016-07-27 13:09         ` Daniel Vetter
2016-07-13  8:11 ` [PATCH 3/3] drm/imx: ipuv3-crtc: implement fast path mode_set_base Stefan Christ
2016-07-13 10:00 ` [PATCH 0/3] Support fast framebuffer panning for i.MX6 Daniel Vetter
2016-07-14 15:11   ` Stefan Christ
2016-07-15  7:14     ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160713101605.GC23520@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=s.christ@phytec.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox