diff mbox series

[RESEND,v2] drm: Add getfb2 ioctl

Message ID 20191003183125.4520-1-juston.li@intel.com (mailing list archive)
State New, archived
Headers show
Series [RESEND,v2] drm: Add getfb2 ioctl | expand

Commit Message

Juston Li Oct. 3, 2019, 6:31 p.m. UTC
From: Daniel Stone <daniels@collabora.com>

getfb2 allows us to pass multiple planes and modifiers, just like addfb2
over addfb.

Changes since v1:
 - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
 - update ioctl number

Signed-off-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Juston Li <juston.li@intel.com>
---
 drivers/gpu/drm/drm_crtc_internal.h |   2 +
 drivers/gpu/drm/drm_framebuffer.c   | 110 ++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_ioctl.c         |   1 +
 include/uapi/drm/drm.h              |   2 +
 4 files changed, 115 insertions(+)

Comments

Daniel Vetter Oct. 9, 2019, 3:50 p.m. UTC | #1
On Thu, Oct 03, 2019 at 11:31:25AM -0700, Juston Li wrote:
> From: Daniel Stone <daniels@collabora.com>
> 
> getfb2 allows us to pass multiple planes and modifiers, just like addfb2
> over addfb.
> 
> Changes since v1:
>  - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
>  - update ioctl number
> 
> Signed-off-by: Daniel Stone <daniels@collabora.com>
> Signed-off-by: Juston Li <juston.li@intel.com>

Looks all good from a very quick glance (kernel, libdrm, igt), but where's
the userspace? Link to weston/drm_hwc/whatever MR good enough.
-Daniel

> ---
>  drivers/gpu/drm/drm_crtc_internal.h |   2 +
>  drivers/gpu/drm/drm_framebuffer.c   | 110 ++++++++++++++++++++++++++++
>  drivers/gpu/drm/drm_ioctl.c         |   1 +
>  include/uapi/drm/drm.h              |   2 +
>  4 files changed, 115 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
> index c7d5e4c21423..16f2413403aa 100644
> --- a/drivers/gpu/drm/drm_crtc_internal.h
> +++ b/drivers/gpu/drm/drm_crtc_internal.h
> @@ -216,6 +216,8 @@ int drm_mode_rmfb_ioctl(struct drm_device *dev,
>  			void *data, struct drm_file *file_priv);
>  int drm_mode_getfb(struct drm_device *dev,
>  		   void *data, struct drm_file *file_priv);
> +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> +			  void *data, struct drm_file *file_priv);
>  int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
>  			   void *data, struct drm_file *file_priv);
>  
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 57564318ceea..6db54f177443 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -31,6 +31,7 @@
>  #include <drm/drm_file.h>
>  #include <drm/drm_fourcc.h>
>  #include <drm/drm_framebuffer.h>
> +#include <drm/drm_gem.h>
>  #include <drm/drm_print.h>
>  #include <drm/drm_util.h>
>  
> @@ -548,7 +549,116 @@ int drm_mode_getfb(struct drm_device *dev,
>  
>  out:
>  	drm_framebuffer_put(fb);
> +	return ret;
> +}
> +
> +/**
> + * drm_mode_getfb2 - get extended FB info
> + * @dev: drm device for the ioctl
> + * @data: data pointer for the ioctl
> + * @file_priv: drm file for the ioctl call
> + *
> + * Lookup the FB given its ID and return info about it.
> + *
> + * Called by the user via ioctl.
> + *
> + * Returns:
> + * Zero on success, negative errno on failure.
> + */
> +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> +			  void *data, struct drm_file *file_priv)
> +{
> +	struct drm_mode_fb_cmd2 *r = data;
> +	struct drm_framebuffer *fb;
> +	unsigned int i;
> +	int ret;
> +
> +	if (!drm_core_check_feature(dev, DRIVER_MODESET))
> +		return -EINVAL;
> +
> +	fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
> +	if (!fb)
> +		return -ENOENT;
> +
> +	/* For multi-plane framebuffers, we require the driver to place the
> +	 * GEM objects directly in the drm_framebuffer. For single-plane
> +	 * framebuffers, we can fall back to create_handle.
> +	 */
> +	if (!fb->obj[0] &&
> +	    (fb->format->num_planes > 1 || !fb->funcs->create_handle)) {
> +		ret = -ENODEV;
> +		goto out;
> +	}
> +
> +	r->height = fb->height;
> +	r->width = fb->width;
> +	r->pixel_format = fb->format->format;
> +
> +	r->flags = 0;
> +	if (dev->mode_config.allow_fb_modifiers)
> +		r->flags |= DRM_MODE_FB_MODIFIERS;
> +
> +	for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> +		r->handles[i] = 0;
> +		r->pitches[i] = 0;
> +		r->offsets[i] = 0;
> +		r->modifier[i] = 0;
> +	}
>  
> +	for (i = 0; i < fb->format->num_planes; i++) {
> +		int j;
> +
> +		r->pitches[i] = fb->pitches[i];
> +		r->offsets[i] = fb->offsets[i];
> +		if (dev->mode_config.allow_fb_modifiers)
> +			r->modifier[i] = fb->modifier;
> +
> +		/* If we reuse the same object for multiple planes, also
> +		 * return the same handle.
> +		 */
> +		for (j = 0; j < i; j++) {
> +			if (fb->obj[i] == fb->obj[j]) {
> +				r->handles[i] = r->handles[j];
> +				break;
> +			}
> +		}
> +
> +		if (r->handles[i])
> +			continue;
> +
> +		if (fb->obj[i]) {
> +			ret = drm_gem_handle_create(file_priv, fb->obj[i],
> +						    &r->handles[i]);
> +		} else {
> +			WARN_ON(i > 0);
> +			ret = fb->funcs->create_handle(fb, file_priv,
> +						       &r->handles[i]);
> +		}
> +
> +		if (ret != 0)
> +			goto out;
> +	}
> +
> +out:
> +	if (ret != 0) {
> +		/* Delete any previously-created handles on failure. */
> +		for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> +			int j;
> +
> +			if (r->handles[i])
> +				drm_gem_handle_delete(file_priv, r->handles[i]);
> +
> +			/* Zero out any handles identical to the one we just
> +			 * deleted.
> +			 */
> +			for (j = i + 1; j < ARRAY_SIZE(r->handles); j++) {
> +				if (r->handles[j] == r->handles[i])
> +					r->handles[j] = 0;
> +			}
> +		}
> +	}
> +
> +	drm_framebuffer_put(fb);
>  	return ret;
>  }
>  
> diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> index fcd728d7cf72..b1fafce3ad8c 100644
> --- a/drivers/gpu/drm/drm_ioctl.c
> +++ b/drivers/gpu/drm/drm_ioctl.c
> @@ -671,6 +671,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY, drm_connector_property_set_ioctl, DRM_MASTER),
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB, drm_mode_getblob_ioctl, 0),
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, 0),
> +	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB2, drm_mode_getfb2_ioctl, 0),
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb_ioctl, 0),
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2_ioctl, 0),
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb_ioctl, 0),
> diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
> index 8a5b2f8f8eb9..021f33675ba2 100644
> --- a/include/uapi/drm/drm.h
> +++ b/include/uapi/drm/drm.h
> @@ -947,6 +947,8 @@ extern "C" {
>  #define DRM_IOCTL_SYNCOBJ_TRANSFER	DRM_IOWR(0xCC, struct drm_syncobj_transfer)
>  #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL	DRM_IOWR(0xCD, struct drm_syncobj_timeline_array)
>  
> +#define DRM_IOCTL_MODE_GETFB2		DRM_IOWR(0xCE, struct drm_mode_fb_cmd2)
> +
>  /**
>   * Device specific ioctls should only be in their respective headers
>   * The device specific ioctl range is from 0x40 to 0x9f.
> -- 
> 2.21.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Juston Li Oct. 14, 2019, 4:21 p.m. UTC | #2
On Wed, 2019-10-09 at 17:50 +0200, Daniel Vetter wrote:
> On Thu, Oct 03, 2019 at 11:31:25AM -0700, Juston Li wrote:
> > From: Daniel Stone <daniels@collabora.com>
> > 
> > getfb2 allows us to pass multiple planes and modifiers, just like
> > addfb2
> > over addfb.
> > 
> > Changes since v1:
> >  - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
> >  - update ioctl number
> > 
> > Signed-off-by: Daniel Stone <daniels@collabora.com>
> > Signed-off-by: Juston Li <juston.li@intel.com>
> 
> Looks all good from a very quick glance (kernel, libdrm, igt), but
> where's
> the userspace? Link to weston/drm_hwc/whatever MR good enough.
> -Daniel

My use case is a screenshot utility in chromiuomos that breaks with y-
tiled ccs enabled.
Review linked is just WIP hack for now since it depends on this
merging:
https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1815146

Thanks
Juston

> > ---
> >  drivers/gpu/drm/drm_crtc_internal.h |   2 +
> >  drivers/gpu/drm/drm_framebuffer.c   | 110
> > ++++++++++++++++++++++++++++
> >  drivers/gpu/drm/drm_ioctl.c         |   1 +
> >  include/uapi/drm/drm.h              |   2 +
> >  4 files changed, 115 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/drm_crtc_internal.h
> > b/drivers/gpu/drm/drm_crtc_internal.h
> > index c7d5e4c21423..16f2413403aa 100644
> > --- a/drivers/gpu/drm/drm_crtc_internal.h
> > +++ b/drivers/gpu/drm/drm_crtc_internal.h
> > @@ -216,6 +216,8 @@ int drm_mode_rmfb_ioctl(struct drm_device *dev,
> >  			void *data, struct drm_file *file_priv);
> >  int drm_mode_getfb(struct drm_device *dev,
> >  		   void *data, struct drm_file *file_priv);
> > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > +			  void *data, struct drm_file *file_priv);
> >  int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
> >  			   void *data, struct drm_file *file_priv);
> >  
> > diff --git a/drivers/gpu/drm/drm_framebuffer.c
> > b/drivers/gpu/drm/drm_framebuffer.c
> > index 57564318ceea..6db54f177443 100644
> > --- a/drivers/gpu/drm/drm_framebuffer.c
> > +++ b/drivers/gpu/drm/drm_framebuffer.c
> > @@ -31,6 +31,7 @@
> >  #include <drm/drm_file.h>
> >  #include <drm/drm_fourcc.h>
> >  #include <drm/drm_framebuffer.h>
> > +#include <drm/drm_gem.h>
> >  #include <drm/drm_print.h>
> >  #include <drm/drm_util.h>
> >  
> > @@ -548,7 +549,116 @@ int drm_mode_getfb(struct drm_device *dev,
> >  
> >  out:
> >  	drm_framebuffer_put(fb);
> > +	return ret;
> > +}
> > +
> > +/**
> > + * drm_mode_getfb2 - get extended FB info
> > + * @dev: drm device for the ioctl
> > + * @data: data pointer for the ioctl
> > + * @file_priv: drm file for the ioctl call
> > + *
> > + * Lookup the FB given its ID and return info about it.
> > + *
> > + * Called by the user via ioctl.
> > + *
> > + * Returns:
> > + * Zero on success, negative errno on failure.
> > + */
> > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > +			  void *data, struct drm_file *file_priv)
> > +{
> > +	struct drm_mode_fb_cmd2 *r = data;
> > +	struct drm_framebuffer *fb;
> > +	unsigned int i;
> > +	int ret;
> > +
> > +	if (!drm_core_check_feature(dev, DRIVER_MODESET))
> > +		return -EINVAL;
> > +
> > +	fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
> > +	if (!fb)
> > +		return -ENOENT;
> > +
> > +	/* For multi-plane framebuffers, we require the driver to place
> > the
> > +	 * GEM objects directly in the drm_framebuffer. For single-
> > plane
> > +	 * framebuffers, we can fall back to create_handle.
> > +	 */
> > +	if (!fb->obj[0] &&
> > +	    (fb->format->num_planes > 1 || !fb->funcs->create_handle))
> > {
> > +		ret = -ENODEV;
> > +		goto out;
> > +	}
> > +
> > +	r->height = fb->height;
> > +	r->width = fb->width;
> > +	r->pixel_format = fb->format->format;
> > +
> > +	r->flags = 0;
> > +	if (dev->mode_config.allow_fb_modifiers)
> > +		r->flags |= DRM_MODE_FB_MODIFIERS;
> > +
> > +	for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> > +		r->handles[i] = 0;
> > +		r->pitches[i] = 0;
> > +		r->offsets[i] = 0;
> > +		r->modifier[i] = 0;
> > +	}
> >  
> > +	for (i = 0; i < fb->format->num_planes; i++) {
> > +		int j;
> > +
> > +		r->pitches[i] = fb->pitches[i];
> > +		r->offsets[i] = fb->offsets[i];
> > +		if (dev->mode_config.allow_fb_modifiers)
> > +			r->modifier[i] = fb->modifier;
> > +
> > +		/* If we reuse the same object for multiple planes,
> > also
> > +		 * return the same handle.
> > +		 */
> > +		for (j = 0; j < i; j++) {
> > +			if (fb->obj[i] == fb->obj[j]) {
> > +				r->handles[i] = r->handles[j];
> > +				break;
> > +			}
> > +		}
> > +
> > +		if (r->handles[i])
> > +			continue;
> > +
> > +		if (fb->obj[i]) {
> > +			ret = drm_gem_handle_create(file_priv, fb-
> > >obj[i],
> > +						    &r->handles[i]);
> > +		} else {
> > +			WARN_ON(i > 0);
> > +			ret = fb->funcs->create_handle(fb, file_priv,
> > +						       &r->handles[i]);
> > +		}
> > +
> > +		if (ret != 0)
> > +			goto out;
> > +	}
> > +
> > +out:
> > +	if (ret != 0) {
> > +		/* Delete any previously-created handles on failure. */
> > +		for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> > +			int j;
> > +
> > +			if (r->handles[i])
> > +				drm_gem_handle_delete(file_priv, r-
> > >handles[i]);
> > +
> > +			/* Zero out any handles identical to the one we
> > just
> > +			 * deleted.
> > +			 */
> > +			for (j = i + 1; j < ARRAY_SIZE(r->handles);
> > j++) {
> > +				if (r->handles[j] == r->handles[i])
> > +					r->handles[j] = 0;
> > +			}
> > +		}
> > +	}
> > +
> > +	drm_framebuffer_put(fb);
> >  	return ret;
> >  }
> >  
> > diff --git a/drivers/gpu/drm/drm_ioctl.c
> > b/drivers/gpu/drm/drm_ioctl.c
> > index fcd728d7cf72..b1fafce3ad8c 100644
> > --- a/drivers/gpu/drm/drm_ioctl.c
> > +++ b/drivers/gpu/drm/drm_ioctl.c
> > @@ -671,6 +671,7 @@ static const struct drm_ioctl_desc drm_ioctls[]
> > = {
> >  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY,
> > drm_connector_property_set_ioctl, DRM_MASTER),
> >  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB,
> > drm_mode_getblob_ioctl, 0),
> >  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, 0),
> > +	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB2, drm_mode_getfb2_ioctl, 0),
> >  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb_ioctl, 0),
> >  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2_ioctl, 0),
> >  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb_ioctl, 0),
> > diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
> > index 8a5b2f8f8eb9..021f33675ba2 100644
> > --- a/include/uapi/drm/drm.h
> > +++ b/include/uapi/drm/drm.h
> > @@ -947,6 +947,8 @@ extern "C" {
> >  #define DRM_IOCTL_SYNCOBJ_TRANSFER	DRM_IOWR(0xCC, struct
> > drm_syncobj_transfer)
> >  #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL	DRM_IOWR(0xCD, struct
> > drm_syncobj_timeline_array)
> >  
> > +#define DRM_IOCTL_MODE_GETFB2		DRM_IOWR(0xCE, struct
> > drm_mode_fb_cmd2)
> > +
> >  /**
> >   * Device specific ioctls should only be in their respective
> > headers
> >   * The device specific ioctl range is from 0x40 to 0x9f.
> > -- 
> > 2.21.0
> > 
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
Daniel Vetter Oct. 14, 2019, 5:51 p.m. UTC | #3
On Mon, Oct 14, 2019 at 6:21 PM Li, Juston <juston.li@intel.com> wrote:
>
> On Wed, 2019-10-09 at 17:50 +0200, Daniel Vetter wrote:
> > On Thu, Oct 03, 2019 at 11:31:25AM -0700, Juston Li wrote:
> > > From: Daniel Stone <daniels@collabora.com>
> > >
> > > getfb2 allows us to pass multiple planes and modifiers, just like
> > > addfb2
> > > over addfb.
> > >
> > > Changes since v1:
> > >  - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
> > >  - update ioctl number
> > >
> > > Signed-off-by: Daniel Stone <daniels@collabora.com>
> > > Signed-off-by: Juston Li <juston.li@intel.com>
> >
> > Looks all good from a very quick glance (kernel, libdrm, igt), but
> > where's
> > the userspace? Link to weston/drm_hwc/whatever MR good enough.
> > -Daniel
>
> My use case is a screenshot utility in chromiuomos that breaks with y-
> tiled ccs enabled.
> Review linked is just WIP hack for now since it depends on this
> merging:
> https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1815146

Adding Sean & Daniele to confirm this is real cros.
-Daniel

>
> Thanks
> Juston
>
> > > ---
> > >  drivers/gpu/drm/drm_crtc_internal.h |   2 +
> > >  drivers/gpu/drm/drm_framebuffer.c   | 110
> > > ++++++++++++++++++++++++++++
> > >  drivers/gpu/drm/drm_ioctl.c         |   1 +
> > >  include/uapi/drm/drm.h              |   2 +
> > >  4 files changed, 115 insertions(+)
> > >
> > > diff --git a/drivers/gpu/drm/drm_crtc_internal.h
> > > b/drivers/gpu/drm/drm_crtc_internal.h
> > > index c7d5e4c21423..16f2413403aa 100644
> > > --- a/drivers/gpu/drm/drm_crtc_internal.h
> > > +++ b/drivers/gpu/drm/drm_crtc_internal.h
> > > @@ -216,6 +216,8 @@ int drm_mode_rmfb_ioctl(struct drm_device *dev,
> > >                     void *data, struct drm_file *file_priv);
> > >  int drm_mode_getfb(struct drm_device *dev,
> > >                void *data, struct drm_file *file_priv);
> > > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > > +                     void *data, struct drm_file *file_priv);
> > >  int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
> > >                        void *data, struct drm_file *file_priv);
> > >
> > > diff --git a/drivers/gpu/drm/drm_framebuffer.c
> > > b/drivers/gpu/drm/drm_framebuffer.c
> > > index 57564318ceea..6db54f177443 100644
> > > --- a/drivers/gpu/drm/drm_framebuffer.c
> > > +++ b/drivers/gpu/drm/drm_framebuffer.c
> > > @@ -31,6 +31,7 @@
> > >  #include <drm/drm_file.h>
> > >  #include <drm/drm_fourcc.h>
> > >  #include <drm/drm_framebuffer.h>
> > > +#include <drm/drm_gem.h>
> > >  #include <drm/drm_print.h>
> > >  #include <drm/drm_util.h>
> > >
> > > @@ -548,7 +549,116 @@ int drm_mode_getfb(struct drm_device *dev,
> > >
> > >  out:
> > >     drm_framebuffer_put(fb);
> > > +   return ret;
> > > +}
> > > +
> > > +/**
> > > + * drm_mode_getfb2 - get extended FB info
> > > + * @dev: drm device for the ioctl
> > > + * @data: data pointer for the ioctl
> > > + * @file_priv: drm file for the ioctl call
> > > + *
> > > + * Lookup the FB given its ID and return info about it.
> > > + *
> > > + * Called by the user via ioctl.
> > > + *
> > > + * Returns:
> > > + * Zero on success, negative errno on failure.
> > > + */
> > > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > > +                     void *data, struct drm_file *file_priv)
> > > +{
> > > +   struct drm_mode_fb_cmd2 *r = data;
> > > +   struct drm_framebuffer *fb;
> > > +   unsigned int i;
> > > +   int ret;
> > > +
> > > +   if (!drm_core_check_feature(dev, DRIVER_MODESET))
> > > +           return -EINVAL;
> > > +
> > > +   fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
> > > +   if (!fb)
> > > +           return -ENOENT;
> > > +
> > > +   /* For multi-plane framebuffers, we require the driver to place
> > > the
> > > +    * GEM objects directly in the drm_framebuffer. For single-
> > > plane
> > > +    * framebuffers, we can fall back to create_handle.
> > > +    */
> > > +   if (!fb->obj[0] &&
> > > +       (fb->format->num_planes > 1 || !fb->funcs->create_handle))
> > > {
> > > +           ret = -ENODEV;
> > > +           goto out;
> > > +   }
> > > +
> > > +   r->height = fb->height;
> > > +   r->width = fb->width;
> > > +   r->pixel_format = fb->format->format;
> > > +
> > > +   r->flags = 0;
> > > +   if (dev->mode_config.allow_fb_modifiers)
> > > +           r->flags |= DRM_MODE_FB_MODIFIERS;
> > > +
> > > +   for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> > > +           r->handles[i] = 0;
> > > +           r->pitches[i] = 0;
> > > +           r->offsets[i] = 0;
> > > +           r->modifier[i] = 0;
> > > +   }
> > >
> > > +   for (i = 0; i < fb->format->num_planes; i++) {
> > > +           int j;
> > > +
> > > +           r->pitches[i] = fb->pitches[i];
> > > +           r->offsets[i] = fb->offsets[i];
> > > +           if (dev->mode_config.allow_fb_modifiers)
> > > +                   r->modifier[i] = fb->modifier;
> > > +
> > > +           /* If we reuse the same object for multiple planes,
> > > also
> > > +            * return the same handle.
> > > +            */
> > > +           for (j = 0; j < i; j++) {
> > > +                   if (fb->obj[i] == fb->obj[j]) {
> > > +                           r->handles[i] = r->handles[j];
> > > +                           break;
> > > +                   }
> > > +           }
> > > +
> > > +           if (r->handles[i])
> > > +                   continue;
> > > +
> > > +           if (fb->obj[i]) {
> > > +                   ret = drm_gem_handle_create(file_priv, fb-
> > > >obj[i],
> > > +                                               &r->handles[i]);
> > > +           } else {
> > > +                   WARN_ON(i > 0);
> > > +                   ret = fb->funcs->create_handle(fb, file_priv,
> > > +                                                  &r->handles[i]);
> > > +           }
> > > +
> > > +           if (ret != 0)
> > > +                   goto out;
> > > +   }
> > > +
> > > +out:
> > > +   if (ret != 0) {
> > > +           /* Delete any previously-created handles on failure. */
> > > +           for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> > > +                   int j;
> > > +
> > > +                   if (r->handles[i])
> > > +                           drm_gem_handle_delete(file_priv, r-
> > > >handles[i]);
> > > +
> > > +                   /* Zero out any handles identical to the one we
> > > just
> > > +                    * deleted.
> > > +                    */
> > > +                   for (j = i + 1; j < ARRAY_SIZE(r->handles);
> > > j++) {
> > > +                           if (r->handles[j] == r->handles[i])
> > > +                                   r->handles[j] = 0;
> > > +                   }
> > > +           }
> > > +   }
> > > +
> > > +   drm_framebuffer_put(fb);
> > >     return ret;
> > >  }
> > >
> > > diff --git a/drivers/gpu/drm/drm_ioctl.c
> > > b/drivers/gpu/drm/drm_ioctl.c
> > > index fcd728d7cf72..b1fafce3ad8c 100644
> > > --- a/drivers/gpu/drm/drm_ioctl.c
> > > +++ b/drivers/gpu/drm/drm_ioctl.c
> > > @@ -671,6 +671,7 @@ static const struct drm_ioctl_desc drm_ioctls[]
> > > = {
> > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY,
> > > drm_connector_property_set_ioctl, DRM_MASTER),
> > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB,
> > > drm_mode_getblob_ioctl, 0),
> > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, 0),
> > > +   DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB2, drm_mode_getfb2_ioctl, 0),
> > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb_ioctl, 0),
> > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2_ioctl, 0),
> > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb_ioctl, 0),
> > > diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
> > > index 8a5b2f8f8eb9..021f33675ba2 100644
> > > --- a/include/uapi/drm/drm.h
> > > +++ b/include/uapi/drm/drm.h
> > > @@ -947,6 +947,8 @@ extern "C" {
> > >  #define DRM_IOCTL_SYNCOBJ_TRANSFER DRM_IOWR(0xCC, struct
> > > drm_syncobj_transfer)
> > >  #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL  DRM_IOWR(0xCD, struct
> > > drm_syncobj_timeline_array)
> > >
> > > +#define DRM_IOCTL_MODE_GETFB2              DRM_IOWR(0xCE, struct
> > > drm_mode_fb_cmd2)
> > > +
> > >  /**
> > >   * Device specific ioctls should only be in their respective
> > > headers
> > >   * The device specific ioctl range is from 0x40 to 0x9f.
> > > --
> > > 2.21.0
> > >
> > > _______________________________________________
> > > dri-devel mailing list
> > > dri-devel@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
Juston Li Oct. 14, 2019, 6:30 p.m. UTC | #4
On Mon, 2019-10-14 at 19:51 +0200, Daniel Vetter wrote:
> On Mon, Oct 14, 2019 at 6:21 PM Li, Juston <juston.li@intel.com>
> wrote:
> > On Wed, 2019-10-09 at 17:50 +0200, Daniel Vetter wrote:
> > > On Thu, Oct 03, 2019 at 11:31:25AM -0700, Juston Li wrote:
> > > > From: Daniel Stone <daniels@collabora.com>
> > > > 
> > > > getfb2 allows us to pass multiple planes and modifiers, just
> > > > like
> > > > addfb2
> > > > over addfb.
> > > > 
> > > > Changes since v1:
> > > >  - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
> > > >  - update ioctl number
> > > > 
> > > > Signed-off-by: Daniel Stone <daniels@collabora.com>
> > > > Signed-off-by: Juston Li <juston.li@intel.com>
> > > 
> > > Looks all good from a very quick glance (kernel, libdrm, igt),
> > > but
> > > where's
> > > the userspace? Link to weston/drm_hwc/whatever MR good enough.
> > > -Daniel
> > 
> > My use case is a screenshot utility in chromiuomos that breaks with
> > y-
> > tiled ccs enabled.
> > Review linked is just WIP hack for now since it depends on this
> > merging:
> > https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1815146
> 
> Adding Sean & Daniele to confirm this is real cros.
> -Daniel

+Mark, who I've been talking about enabling render buffer compression.

This patch allows me to fix a regression w/ screenshot utility when
enabling RBC:
https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/1759155

Thanks
Juston

> > > > ---
> > > >  drivers/gpu/drm/drm_crtc_internal.h |   2 +
> > > >  drivers/gpu/drm/drm_framebuffer.c   | 110
> > > > ++++++++++++++++++++++++++++
> > > >  drivers/gpu/drm/drm_ioctl.c         |   1 +
> > > >  include/uapi/drm/drm.h              |   2 +
> > > >  4 files changed, 115 insertions(+)
> > > > 
> > > > diff --git a/drivers/gpu/drm/drm_crtc_internal.h
> > > > b/drivers/gpu/drm/drm_crtc_internal.h
> > > > index c7d5e4c21423..16f2413403aa 100644
> > > > --- a/drivers/gpu/drm/drm_crtc_internal.h
> > > > +++ b/drivers/gpu/drm/drm_crtc_internal.h
> > > > @@ -216,6 +216,8 @@ int drm_mode_rmfb_ioctl(struct drm_device
> > > > *dev,
> > > >                     void *data, struct drm_file *file_priv);
> > > >  int drm_mode_getfb(struct drm_device *dev,
> > > >                void *data, struct drm_file *file_priv);
> > > > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > > > +                     void *data, struct drm_file *file_priv);
> > > >  int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
> > > >                        void *data, struct drm_file *file_priv);
> > > > 
> > > > diff --git a/drivers/gpu/drm/drm_framebuffer.c
> > > > b/drivers/gpu/drm/drm_framebuffer.c
> > > > index 57564318ceea..6db54f177443 100644
> > > > --- a/drivers/gpu/drm/drm_framebuffer.c
> > > > +++ b/drivers/gpu/drm/drm_framebuffer.c
> > > > @@ -31,6 +31,7 @@
> > > >  #include <drm/drm_file.h>
> > > >  #include <drm/drm_fourcc.h>
> > > >  #include <drm/drm_framebuffer.h>
> > > > +#include <drm/drm_gem.h>
> > > >  #include <drm/drm_print.h>
> > > >  #include <drm/drm_util.h>
> > > > 
> > > > @@ -548,7 +549,116 @@ int drm_mode_getfb(struct drm_device
> > > > *dev,
> > > > 
> > > >  out:
> > > >     drm_framebuffer_put(fb);
> > > > +   return ret;
> > > > +}
> > > > +
> > > > +/**
> > > > + * drm_mode_getfb2 - get extended FB info
> > > > + * @dev: drm device for the ioctl
> > > > + * @data: data pointer for the ioctl
> > > > + * @file_priv: drm file for the ioctl call
> > > > + *
> > > > + * Lookup the FB given its ID and return info about it.
> > > > + *
> > > > + * Called by the user via ioctl.
> > > > + *
> > > > + * Returns:
> > > > + * Zero on success, negative errno on failure.
> > > > + */
> > > > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > > > +                     void *data, struct drm_file *file_priv)
> > > > +{
> > > > +   struct drm_mode_fb_cmd2 *r = data;
> > > > +   struct drm_framebuffer *fb;
> > > > +   unsigned int i;
> > > > +   int ret;
> > > > +
> > > > +   if (!drm_core_check_feature(dev, DRIVER_MODESET))
> > > > +           return -EINVAL;
> > > > +
> > > > +   fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
> > > > +   if (!fb)
> > > > +           return -ENOENT;
> > > > +
> > > > +   /* For multi-plane framebuffers, we require the driver to
> > > > place
> > > > the
> > > > +    * GEM objects directly in the drm_framebuffer. For single-
> > > > plane
> > > > +    * framebuffers, we can fall back to create_handle.
> > > > +    */
> > > > +   if (!fb->obj[0] &&
> > > > +       (fb->format->num_planes > 1 || !fb->funcs-
> > > > >create_handle))
> > > > {
> > > > +           ret = -ENODEV;
> > > > +           goto out;
> > > > +   }
> > > > +
> > > > +   r->height = fb->height;
> > > > +   r->width = fb->width;
> > > > +   r->pixel_format = fb->format->format;
> > > > +
> > > > +   r->flags = 0;
> > > > +   if (dev->mode_config.allow_fb_modifiers)
> > > > +           r->flags |= DRM_MODE_FB_MODIFIERS;
> > > > +
> > > > +   for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> > > > +           r->handles[i] = 0;
> > > > +           r->pitches[i] = 0;
> > > > +           r->offsets[i] = 0;
> > > > +           r->modifier[i] = 0;
> > > > +   }
> > > > 
> > > > +   for (i = 0; i < fb->format->num_planes; i++) {
> > > > +           int j;
> > > > +
> > > > +           r->pitches[i] = fb->pitches[i];
> > > > +           r->offsets[i] = fb->offsets[i];
> > > > +           if (dev->mode_config.allow_fb_modifiers)
> > > > +                   r->modifier[i] = fb->modifier;
> > > > +
> > > > +           /* If we reuse the same object for multiple planes,
> > > > also
> > > > +            * return the same handle.
> > > > +            */
> > > > +           for (j = 0; j < i; j++) {
> > > > +                   if (fb->obj[i] == fb->obj[j]) {
> > > > +                           r->handles[i] = r->handles[j];
> > > > +                           break;
> > > > +                   }
> > > > +           }
> > > > +
> > > > +           if (r->handles[i])
> > > > +                   continue;
> > > > +
> > > > +           if (fb->obj[i]) {
> > > > +                   ret = drm_gem_handle_create(file_priv, fb-
> > > > > obj[i],
> > > > +                                               &r-
> > > > >handles[i]);
> > > > +           } else {
> > > > +                   WARN_ON(i > 0);
> > > > +                   ret = fb->funcs->create_handle(fb,
> > > > file_priv,
> > > > +                                                  &r-
> > > > >handles[i]);
> > > > +           }
> > > > +
> > > > +           if (ret != 0)
> > > > +                   goto out;
> > > > +   }
> > > > +
> > > > +out:
> > > > +   if (ret != 0) {
> > > > +           /* Delete any previously-created handles on
> > > > failure. */
> > > > +           for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> > > > +                   int j;
> > > > +
> > > > +                   if (r->handles[i])
> > > > +                           drm_gem_handle_delete(file_priv, r-
> > > > > handles[i]);
> > > > +
> > > > +                   /* Zero out any handles identical to the
> > > > one we
> > > > just
> > > > +                    * deleted.
> > > > +                    */
> > > > +                   for (j = i + 1; j < ARRAY_SIZE(r->handles);
> > > > j++) {
> > > > +                           if (r->handles[j] == r->handles[i])
> > > > +                                   r->handles[j] = 0;
> > > > +                   }
> > > > +           }
> > > > +   }
> > > > +
> > > > +   drm_framebuffer_put(fb);
> > > >     return ret;
> > > >  }
> > > > 
> > > > diff --git a/drivers/gpu/drm/drm_ioctl.c
> > > > b/drivers/gpu/drm/drm_ioctl.c
> > > > index fcd728d7cf72..b1fafce3ad8c 100644
> > > > --- a/drivers/gpu/drm/drm_ioctl.c
> > > > +++ b/drivers/gpu/drm/drm_ioctl.c
> > > > @@ -671,6 +671,7 @@ static const struct drm_ioctl_desc
> > > > drm_ioctls[]
> > > > = {
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY,
> > > > drm_connector_property_set_ioctl, DRM_MASTER),
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB,
> > > > drm_mode_getblob_ioctl, 0),
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, 0),
> > > > +   DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB2, drm_mode_getfb2_ioctl,
> > > > 0),
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb_ioctl,
> > > > 0),
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2_ioctl,
> > > > 0),
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb_ioctl, 0),
> > > > diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
> > > > index 8a5b2f8f8eb9..021f33675ba2 100644
> > > > --- a/include/uapi/drm/drm.h
> > > > +++ b/include/uapi/drm/drm.h
> > > > @@ -947,6 +947,8 @@ extern "C" {
> > > >  #define DRM_IOCTL_SYNCOBJ_TRANSFER DRM_IOWR(0xCC, struct
> > > > drm_syncobj_transfer)
> > > >  #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL  DRM_IOWR(0xCD,
> > > > struct
> > > > drm_syncobj_timeline_array)
> > > > 
> > > > +#define DRM_IOCTL_MODE_GETFB2              DRM_IOWR(0xCE,
> > > > struct
> > > > drm_mode_fb_cmd2)
> > > > +
> > > >  /**
> > > >   * Device specific ioctls should only be in their respective
> > > > headers
> > > >   * The device specific ioctl range is from 0x40 to 0x9f.
> > > > --
> > > > 2.21.0
> > > > 
> > > > _______________________________________________
> > > > dri-devel mailing list
> > > > dri-devel@lists.freedesktop.org
> > > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 
>
Daniele Castagna Oct. 15, 2019, 3:12 p.m. UTC | #5
On Mon, Oct 14, 2019 at 1:51 PM Daniel Vetter <daniel@ffwll.ch> wrote:
>
> On Mon, Oct 14, 2019 at 6:21 PM Li, Juston <juston.li@intel.com> wrote:
> >
> > On Wed, 2019-10-09 at 17:50 +0200, Daniel Vetter wrote:
> > > On Thu, Oct 03, 2019 at 11:31:25AM -0700, Juston Li wrote:
> > > > From: Daniel Stone <daniels@collabora.com>
> > > >
> > > > getfb2 allows us to pass multiple planes and modifiers, just like
> > > > addfb2
> > > > over addfb.
> > > >
> > > > Changes since v1:
> > > >  - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
> > > >  - update ioctl number
> > > >
> > > > Signed-off-by: Daniel Stone <daniels@collabora.com>
> > > > Signed-off-by: Juston Li <juston.li@intel.com>
> > >
> > > Looks all good from a very quick glance (kernel, libdrm, igt), but
> > > where's
> > > the userspace? Link to weston/drm_hwc/whatever MR good enough.
> > > -Daniel
> >
> > My use case is a screenshot utility in chromiuomos that breaks with y-
> > tiled ccs enabled.
> > Review linked is just WIP hack for now since it depends on this
> > merging:
> > https://chromium-review.googlesource.com/c/chromiumos/platform2/+/1815146
>
> Adding Sean & Daniele to confirm this is real cros.
> -Daniel

Yes, this is useful for cros and not only for the screenshot utility.
It is also useful for the transition from the splash screen to Chrome
login without flashing the screen black.

Thank you!

>
> >
> > Thanks
> > Juston
> >
> > > > ---
> > > >  drivers/gpu/drm/drm_crtc_internal.h |   2 +
> > > >  drivers/gpu/drm/drm_framebuffer.c   | 110
> > > > ++++++++++++++++++++++++++++
> > > >  drivers/gpu/drm/drm_ioctl.c         |   1 +
> > > >  include/uapi/drm/drm.h              |   2 +
> > > >  4 files changed, 115 insertions(+)
> > > >
> > > > diff --git a/drivers/gpu/drm/drm_crtc_internal.h
> > > > b/drivers/gpu/drm/drm_crtc_internal.h
> > > > index c7d5e4c21423..16f2413403aa 100644
> > > > --- a/drivers/gpu/drm/drm_crtc_internal.h
> > > > +++ b/drivers/gpu/drm/drm_crtc_internal.h
> > > > @@ -216,6 +216,8 @@ int drm_mode_rmfb_ioctl(struct drm_device *dev,
> > > >                     void *data, struct drm_file *file_priv);
> > > >  int drm_mode_getfb(struct drm_device *dev,
> > > >                void *data, struct drm_file *file_priv);
> > > > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > > > +                     void *data, struct drm_file *file_priv);
> > > >  int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
> > > >                        void *data, struct drm_file *file_priv);
> > > >
> > > > diff --git a/drivers/gpu/drm/drm_framebuffer.c
> > > > b/drivers/gpu/drm/drm_framebuffer.c
> > > > index 57564318ceea..6db54f177443 100644
> > > > --- a/drivers/gpu/drm/drm_framebuffer.c
> > > > +++ b/drivers/gpu/drm/drm_framebuffer.c
> > > > @@ -31,6 +31,7 @@
> > > >  #include <drm/drm_file.h>
> > > >  #include <drm/drm_fourcc.h>
> > > >  #include <drm/drm_framebuffer.h>
> > > > +#include <drm/drm_gem.h>
> > > >  #include <drm/drm_print.h>
> > > >  #include <drm/drm_util.h>
> > > >
> > > > @@ -548,7 +549,116 @@ int drm_mode_getfb(struct drm_device *dev,
> > > >
> > > >  out:
> > > >     drm_framebuffer_put(fb);
> > > > +   return ret;
> > > > +}
> > > > +
> > > > +/**
> > > > + * drm_mode_getfb2 - get extended FB info
> > > > + * @dev: drm device for the ioctl
> > > > + * @data: data pointer for the ioctl
> > > > + * @file_priv: drm file for the ioctl call
> > > > + *
> > > > + * Lookup the FB given its ID and return info about it.
> > > > + *
> > > > + * Called by the user via ioctl.
> > > > + *
> > > > + * Returns:
> > > > + * Zero on success, negative errno on failure.
> > > > + */
> > > > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > > > +                     void *data, struct drm_file *file_priv)
> > > > +{
> > > > +   struct drm_mode_fb_cmd2 *r = data;
> > > > +   struct drm_framebuffer *fb;
> > > > +   unsigned int i;
> > > > +   int ret;
> > > > +
> > > > +   if (!drm_core_check_feature(dev, DRIVER_MODESET))
> > > > +           return -EINVAL;
> > > > +
> > > > +   fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
> > > > +   if (!fb)
> > > > +           return -ENOENT;
> > > > +
> > > > +   /* For multi-plane framebuffers, we require the driver to place
> > > > the
> > > > +    * GEM objects directly in the drm_framebuffer. For single-
> > > > plane
> > > > +    * framebuffers, we can fall back to create_handle.
> > > > +    */
> > > > +   if (!fb->obj[0] &&
> > > > +       (fb->format->num_planes > 1 || !fb->funcs->create_handle))
> > > > {
> > > > +           ret = -ENODEV;
> > > > +           goto out;
> > > > +   }
> > > > +
> > > > +   r->height = fb->height;
> > > > +   r->width = fb->width;
> > > > +   r->pixel_format = fb->format->format;
> > > > +
> > > > +   r->flags = 0;
> > > > +   if (dev->mode_config.allow_fb_modifiers)
> > > > +           r->flags |= DRM_MODE_FB_MODIFIERS;
> > > > +
> > > > +   for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> > > > +           r->handles[i] = 0;
> > > > +           r->pitches[i] = 0;
> > > > +           r->offsets[i] = 0;
> > > > +           r->modifier[i] = 0;
> > > > +   }
> > > >
> > > > +   for (i = 0; i < fb->format->num_planes; i++) {
> > > > +           int j;
> > > > +
> > > > +           r->pitches[i] = fb->pitches[i];
> > > > +           r->offsets[i] = fb->offsets[i];
> > > > +           if (dev->mode_config.allow_fb_modifiers)
> > > > +                   r->modifier[i] = fb->modifier;
> > > > +
> > > > +           /* If we reuse the same object for multiple planes,
> > > > also
> > > > +            * return the same handle.
> > > > +            */
> > > > +           for (j = 0; j < i; j++) {
> > > > +                   if (fb->obj[i] == fb->obj[j]) {
> > > > +                           r->handles[i] = r->handles[j];
> > > > +                           break;
> > > > +                   }
> > > > +           }
> > > > +
> > > > +           if (r->handles[i])
> > > > +                   continue;
> > > > +
> > > > +           if (fb->obj[i]) {
> > > > +                   ret = drm_gem_handle_create(file_priv, fb-
> > > > >obj[i],
> > > > +                                               &r->handles[i]);
> > > > +           } else {
> > > > +                   WARN_ON(i > 0);
> > > > +                   ret = fb->funcs->create_handle(fb, file_priv,
> > > > +                                                  &r->handles[i]);
> > > > +           }
> > > > +
> > > > +           if (ret != 0)
> > > > +                   goto out;
> > > > +   }
> > > > +
> > > > +out:
> > > > +   if (ret != 0) {
> > > > +           /* Delete any previously-created handles on failure. */
> > > > +           for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> > > > +                   int j;
> > > > +
> > > > +                   if (r->handles[i])
> > > > +                           drm_gem_handle_delete(file_priv, r-
> > > > >handles[i]);
> > > > +
> > > > +                   /* Zero out any handles identical to the one we
> > > > just
> > > > +                    * deleted.
> > > > +                    */
> > > > +                   for (j = i + 1; j < ARRAY_SIZE(r->handles);
> > > > j++) {
> > > > +                           if (r->handles[j] == r->handles[i])
> > > > +                                   r->handles[j] = 0;
> > > > +                   }
> > > > +           }
> > > > +   }
> > > > +
> > > > +   drm_framebuffer_put(fb);
> > > >     return ret;
> > > >  }
> > > >
> > > > diff --git a/drivers/gpu/drm/drm_ioctl.c
> > > > b/drivers/gpu/drm/drm_ioctl.c
> > > > index fcd728d7cf72..b1fafce3ad8c 100644
> > > > --- a/drivers/gpu/drm/drm_ioctl.c
> > > > +++ b/drivers/gpu/drm/drm_ioctl.c
> > > > @@ -671,6 +671,7 @@ static const struct drm_ioctl_desc drm_ioctls[]
> > > > = {
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY,
> > > > drm_connector_property_set_ioctl, DRM_MASTER),
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB,
> > > > drm_mode_getblob_ioctl, 0),
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, 0),
> > > > +   DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB2, drm_mode_getfb2_ioctl, 0),
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb_ioctl, 0),
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2_ioctl, 0),
> > > >     DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb_ioctl, 0),
> > > > diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
> > > > index 8a5b2f8f8eb9..021f33675ba2 100644
> > > > --- a/include/uapi/drm/drm.h
> > > > +++ b/include/uapi/drm/drm.h
> > > > @@ -947,6 +947,8 @@ extern "C" {
> > > >  #define DRM_IOCTL_SYNCOBJ_TRANSFER DRM_IOWR(0xCC, struct
> > > > drm_syncobj_transfer)
> > > >  #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL  DRM_IOWR(0xCD, struct
> > > > drm_syncobj_timeline_array)
> > > >
> > > > +#define DRM_IOCTL_MODE_GETFB2              DRM_IOWR(0xCE, struct
> > > > drm_mode_fb_cmd2)
> > > > +
> > > >  /**
> > > >   * Device specific ioctls should only be in their respective
> > > > headers
> > > >   * The device specific ioctl range is from 0x40 to 0x9f.
> > > > --
> > > > 2.21.0
> > > >
> > > > _______________________________________________
> > > > dri-devel mailing list
> > > > dri-devel@lists.freedesktop.org
> > > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
>
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Timo Aaltonen Nov. 21, 2019, 8:26 a.m. UTC | #6
On 9.10.2019 18.50, Daniel Vetter wrote:
> On Thu, Oct 03, 2019 at 11:31:25AM -0700, Juston Li wrote:
>> From: Daniel Stone <daniels@collabora.com>
>>
>> getfb2 allows us to pass multiple planes and modifiers, just like addfb2
>> over addfb.
>>
>> Changes since v1:
>>  - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
>>  - update ioctl number
>>
>> Signed-off-by: Daniel Stone <daniels@collabora.com>
>> Signed-off-by: Juston Li <juston.li@intel.com>
> 
> Looks all good from a very quick glance (kernel, libdrm, igt), but where's
> the userspace? Link to weston/drm_hwc/whatever MR good enough.
> -Daniel

xserver too

https://lists.x.org/archives/xorg-devel/2018-March/056363.html

to fix

https://gitlab.freedesktop.org/xorg/xserver/issues/33

which forces Ubuntu to disable CCS compression, and I'd like to get rid
of that patch.

Thanks Juston for pushing this!
Daniel Vetter Nov. 21, 2019, 9:28 a.m. UTC | #7
On Thu, Nov 21, 2019 at 9:26 AM Timo Aaltonen <tjaalton@ubuntu.com> wrote:
>
> On 9.10.2019 18.50, Daniel Vetter wrote:
> > On Thu, Oct 03, 2019 at 11:31:25AM -0700, Juston Li wrote:
> >> From: Daniel Stone <daniels@collabora.com>
> >>
> >> getfb2 allows us to pass multiple planes and modifiers, just like addfb2
> >> over addfb.
> >>
> >> Changes since v1:
> >>  - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
> >>  - update ioctl number
> >>
> >> Signed-off-by: Daniel Stone <daniels@collabora.com>
> >> Signed-off-by: Juston Li <juston.li@intel.com>
> >
> > Looks all good from a very quick glance (kernel, libdrm, igt), but where's
> > the userspace? Link to weston/drm_hwc/whatever MR good enough.
> > -Daniel
>
> xserver too
>
> https://lists.x.org/archives/xorg-devel/2018-March/056363.html
>
> to fix
>
> https://gitlab.freedesktop.org/xorg/xserver/issues/33
>
> which forces Ubuntu to disable CCS compression, and I'd like to get rid
> of that patch.
>
> Thanks Juston for pushing this!

Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>

... but someone needs to review all the patches and make sure kernel
patch + igt work and pass intel CI and then push it all, and given the
pile of committers we have that's not me I think. Just in case people
expect me to push this forward, I only jumped in here to make sure new
uapi is done by the book and checks all the boxes.
-Daniel
Juston Li Nov. 22, 2019, 1:07 a.m. UTC | #8
On Thu, 2019-11-21 at 10:28 +0100, Daniel Vetter wrote:
> On Thu, Nov 21, 2019 at 9:26 AM Timo Aaltonen <tjaalton@ubuntu.com>
> wrote:
> > On 9.10.2019 18.50, Daniel Vetter wrote:
> > > On Thu, Oct 03, 2019 at 11:31:25AM -0700, Juston Li wrote:
> > > > From: Daniel Stone <daniels@collabora.com>
> > > > 
> > > > getfb2 allows us to pass multiple planes and modifiers, just
> > > > like addfb2
> > > > over addfb.
> > > > 
> > > > Changes since v1:
> > > >  - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
> > > >  - update ioctl number
> > > > 
> > > > Signed-off-by: Daniel Stone <daniels@collabora.com>
> > > > Signed-off-by: Juston Li <juston.li@intel.com>
> > > 
> > > Looks all good from a very quick glance (kernel, libdrm, igt),
> > > but where's
> > > the userspace? Link to weston/drm_hwc/whatever MR good enough.
> > > -Daniel
> > 
> > xserver too
> > 
> > https://lists.x.org/archives/xorg-devel/2018-March/056363.html
> > 
> > to fix
> > 
> > https://gitlab.freedesktop.org/xorg/xserver/issues/33
> > 
> > which forces Ubuntu to disable CCS compression, and I'd like to get
> > rid
> > of that patch.
> > 
> > Thanks Juston for pushing this!
> 
> Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> 
> ... but someone needs to review all the patches and make sure kernel
> patch + igt work and pass intel CI and then push it all, and given
> the
> pile of committers we have that's not me I think. Just in case people
> expect me to push this forward, I only jumped in here to make sure
> new
> uapi is done by the book and checks all the boxes.
> -Daniel

Thanks for clarifying Daniel, I'll try to find someone to review.

Juston
Ville Syrjala Dec. 13, 2019, 9:36 p.m. UTC | #9
On Thu, Oct 03, 2019 at 11:31:25AM -0700, Juston Li wrote:
> From: Daniel Stone <daniels@collabora.com>
> 
> getfb2 allows us to pass multiple planes and modifiers, just like addfb2
> over addfb.
> 
> Changes since v1:
>  - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
>  - update ioctl number
> 
> Signed-off-by: Daniel Stone <daniels@collabora.com>
> Signed-off-by: Juston Li <juston.li@intel.com>
> ---
>  drivers/gpu/drm/drm_crtc_internal.h |   2 +
>  drivers/gpu/drm/drm_framebuffer.c   | 110 ++++++++++++++++++++++++++++
>  drivers/gpu/drm/drm_ioctl.c         |   1 +
>  include/uapi/drm/drm.h              |   2 +
>  4 files changed, 115 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
> index c7d5e4c21423..16f2413403aa 100644
> --- a/drivers/gpu/drm/drm_crtc_internal.h
> +++ b/drivers/gpu/drm/drm_crtc_internal.h
> @@ -216,6 +216,8 @@ int drm_mode_rmfb_ioctl(struct drm_device *dev,
>  			void *data, struct drm_file *file_priv);
>  int drm_mode_getfb(struct drm_device *dev,
>  		   void *data, struct drm_file *file_priv);
> +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> +			  void *data, struct drm_file *file_priv);
>  int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
>  			   void *data, struct drm_file *file_priv);
>  
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 57564318ceea..6db54f177443 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -31,6 +31,7 @@
>  #include <drm/drm_file.h>
>  #include <drm/drm_fourcc.h>
>  #include <drm/drm_framebuffer.h>
> +#include <drm/drm_gem.h>
>  #include <drm/drm_print.h>
>  #include <drm/drm_util.h>
>  
> @@ -548,7 +549,116 @@ int drm_mode_getfb(struct drm_device *dev,
>  
>  out:
>  	drm_framebuffer_put(fb);
> +	return ret;
> +}
> +
> +/**
> + * drm_mode_getfb2 - get extended FB info
> + * @dev: drm device for the ioctl
> + * @data: data pointer for the ioctl
> + * @file_priv: drm file for the ioctl call
> + *
> + * Lookup the FB given its ID and return info about it.
> + *
> + * Called by the user via ioctl.
> + *
> + * Returns:
> + * Zero on success, negative errno on failure.
> + */
> +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> +			  void *data, struct drm_file *file_priv)
> +{
> +	struct drm_mode_fb_cmd2 *r = data;
> +	struct drm_framebuffer *fb;
> +	unsigned int i;
> +	int ret;
> +
> +	if (!drm_core_check_feature(dev, DRIVER_MODESET))
> +		return -EINVAL;
> +
> +	fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
> +	if (!fb)
> +		return -ENOENT;
> +
> +	/* For multi-plane framebuffers, we require the driver to place the
> +	 * GEM objects directly in the drm_framebuffer. For single-plane
> +	 * framebuffers, we can fall back to create_handle.
> +	 */
> +	if (!fb->obj[0] &&
> +	    (fb->format->num_planes > 1 || !fb->funcs->create_handle)) {
> +		ret = -ENODEV;
> +		goto out;
> +	}
> +
> +	r->height = fb->height;
> +	r->width = fb->width;
> +	r->pixel_format = fb->format->format;
> +
> +	r->flags = 0;
> +	if (dev->mode_config.allow_fb_modifiers)
> +		r->flags |= DRM_MODE_FB_MODIFIERS;
> +
> +	for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> +		r->handles[i] = 0;
> +		r->pitches[i] = 0;
> +		r->offsets[i] = 0;
> +		r->modifier[i] = 0;
> +	}
>  
> +	for (i = 0; i < fb->format->num_planes; i++) {
> +		int j;
> +
> +		r->pitches[i] = fb->pitches[i];
> +		r->offsets[i] = fb->offsets[i];
> +		if (dev->mode_config.allow_fb_modifiers)
> +			r->modifier[i] = fb->modifier;
> +
> +		/* If we reuse the same object for multiple planes, also
> +		 * return the same handle.
> +		 */
> +		for (j = 0; j < i; j++) {
> +			if (fb->obj[i] == fb->obj[j]) {
> +				r->handles[i] = r->handles[j];
> +				break;
> +			}
> +		}
> +
> +		if (r->handles[i])
> +			continue;
> +
> +		if (fb->obj[i]) {
> +			ret = drm_gem_handle_create(file_priv, fb->obj[i],
> +						    &r->handles[i]);
> +		} else {
> +			WARN_ON(i > 0);
> +			ret = fb->funcs->create_handle(fb, file_priv,
> +						       &r->handles[i]);
> +		}

getfb1 doesn't allow non-master/root to see the handles. Here we don't
seem to have that same protection?

> +
> +		if (ret != 0)
> +			goto out;

Could be just 'break;' and then we wouldn't even need the label.

Rest lgtm.

> +	}
> +
> +out:
> +	if (ret != 0) {
> +		/* Delete any previously-created handles on failure. */
> +		for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> +			int j;
> +
> +			if (r->handles[i])
> +				drm_gem_handle_delete(file_priv, r->handles[i]);
> +
> +			/* Zero out any handles identical to the one we just
> +			 * deleted.
> +			 */
> +			for (j = i + 1; j < ARRAY_SIZE(r->handles); j++) {
> +				if (r->handles[j] == r->handles[i])
> +					r->handles[j] = 0;
> +			}
> +		}
> +	}
> +
> +	drm_framebuffer_put(fb);
>  	return ret;
>  }
>  
> diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
> index fcd728d7cf72..b1fafce3ad8c 100644
> --- a/drivers/gpu/drm/drm_ioctl.c
> +++ b/drivers/gpu/drm/drm_ioctl.c
> @@ -671,6 +671,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY, drm_connector_property_set_ioctl, DRM_MASTER),
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB, drm_mode_getblob_ioctl, 0),
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, 0),
> +	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB2, drm_mode_getfb2_ioctl, 0),
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb_ioctl, 0),
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2_ioctl, 0),
>  	DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb_ioctl, 0),
> diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
> index 8a5b2f8f8eb9..021f33675ba2 100644
> --- a/include/uapi/drm/drm.h
> +++ b/include/uapi/drm/drm.h
> @@ -947,6 +947,8 @@ extern "C" {
>  #define DRM_IOCTL_SYNCOBJ_TRANSFER	DRM_IOWR(0xCC, struct drm_syncobj_transfer)
>  #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL	DRM_IOWR(0xCD, struct drm_syncobj_timeline_array)
>  
> +#define DRM_IOCTL_MODE_GETFB2		DRM_IOWR(0xCE, struct drm_mode_fb_cmd2)
> +
>  /**
>   * Device specific ioctls should only be in their respective headers
>   * The device specific ioctl range is from 0x40 to 0x9f.
> -- 
> 2.21.0
Juston Li Dec. 13, 2019, 10:52 p.m. UTC | #10
On Fri, 2019-12-13 at 23:36 +0200, Ville Syrjälä wrote:
> On Thu, Oct 03, 2019 at 11:31:25AM -0700, Juston Li wrote:
> > From: Daniel Stone <daniels@collabora.com>
> > 
> > getfb2 allows us to pass multiple planes and modifiers, just like
> > addfb2
> > over addfb.
> > 
> > Changes since v1:
> >  - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
> >  - update ioctl number
> > 
> > Signed-off-by: Daniel Stone <daniels@collabora.com>
> > Signed-off-by: Juston Li <juston.li@intel.com>
> > ---
> >  drivers/gpu/drm/drm_crtc_internal.h |   2 +
> >  drivers/gpu/drm/drm_framebuffer.c   | 110
> > ++++++++++++++++++++++++++++
> >  drivers/gpu/drm/drm_ioctl.c         |   1 +
> >  include/uapi/drm/drm.h              |   2 +
> >  4 files changed, 115 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/drm_crtc_internal.h
> > b/drivers/gpu/drm/drm_crtc_internal.h
> > index c7d5e4c21423..16f2413403aa 100644
> > --- a/drivers/gpu/drm/drm_crtc_internal.h
> > +++ b/drivers/gpu/drm/drm_crtc_internal.h
> > @@ -216,6 +216,8 @@ int drm_mode_rmfb_ioctl(struct drm_device *dev,
> >  			void *data, struct drm_file *file_priv);
> >  int drm_mode_getfb(struct drm_device *dev,
> >  		   void *data, struct drm_file *file_priv);
> > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > +			  void *data, struct drm_file *file_priv);
> >  int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
> >  			   void *data, struct drm_file *file_priv);
> >  
> > diff --git a/drivers/gpu/drm/drm_framebuffer.c
> > b/drivers/gpu/drm/drm_framebuffer.c
> > index 57564318ceea..6db54f177443 100644
> > --- a/drivers/gpu/drm/drm_framebuffer.c
> > +++ b/drivers/gpu/drm/drm_framebuffer.c
> > @@ -31,6 +31,7 @@
> >  #include <drm/drm_file.h>
> >  #include <drm/drm_fourcc.h>
> >  #include <drm/drm_framebuffer.h>
> > +#include <drm/drm_gem.h>
> >  #include <drm/drm_print.h>
> >  #include <drm/drm_util.h>
> >  
> > @@ -548,7 +549,116 @@ int drm_mode_getfb(struct drm_device *dev,
> >  
> >  out:
> >  	drm_framebuffer_put(fb);
> > +	return ret;
> > +}
> > +
> > +/**
> > + * drm_mode_getfb2 - get extended FB info
> > + * @dev: drm device for the ioctl
> > + * @data: data pointer for the ioctl
> > + * @file_priv: drm file for the ioctl call
> > + *
> > + * Lookup the FB given its ID and return info about it.
> > + *
> > + * Called by the user via ioctl.
> > + *
> > + * Returns:
> > + * Zero on success, negative errno on failure.
> > + */
> > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > +			  void *data, struct drm_file *file_priv)
> > +{
> > +	struct drm_mode_fb_cmd2 *r = data;
> > +	struct drm_framebuffer *fb;
> > +	unsigned int i;
> > +	int ret;
> > +
> > +	if (!drm_core_check_feature(dev, DRIVER_MODESET))
> > +		return -EINVAL;
> > +
> > +	fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
> > +	if (!fb)
> > +		return -ENOENT;
> > +
> > +	/* For multi-plane framebuffers, we require the driver to place
> > the
> > +	 * GEM objects directly in the drm_framebuffer. For single-
> > plane
> > +	 * framebuffers, we can fall back to create_handle.
> > +	 */
> > +	if (!fb->obj[0] &&
> > +	    (fb->format->num_planes > 1 || !fb->funcs->create_handle))
> > {
> > +		ret = -ENODEV;
> > +		goto out;
> > +	}
> > +
> > +	r->height = fb->height;
> > +	r->width = fb->width;
> > +	r->pixel_format = fb->format->format;
> > +
> > +	r->flags = 0;
> > +	if (dev->mode_config.allow_fb_modifiers)
> > +		r->flags |= DRM_MODE_FB_MODIFIERS;
> > +
> > +	for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> > +		r->handles[i] = 0;
> > +		r->pitches[i] = 0;
> > +		r->offsets[i] = 0;
> > +		r->modifier[i] = 0;
> > +	}
> >  
> > +	for (i = 0; i < fb->format->num_planes; i++) {
> > +		int j;
> > +
> > +		r->pitches[i] = fb->pitches[i];
> > +		r->offsets[i] = fb->offsets[i];
> > +		if (dev->mode_config.allow_fb_modifiers)
> > +			r->modifier[i] = fb->modifier;
> > +
> > +		/* If we reuse the same object for multiple planes,
> > also
> > +		 * return the same handle.
> > +		 */
> > +		for (j = 0; j < i; j++) {
> > +			if (fb->obj[i] == fb->obj[j]) {
> > +				r->handles[i] = r->handles[j];
> > +				break;
> > +			}
> > +		}
> > +
> > +		if (r->handles[i])
> > +			continue;
> > +
> > +		if (fb->obj[i]) {
> > +			ret = drm_gem_handle_create(file_priv, fb-
> > >obj[i],
> > +						    &r->handles[i]);
> > +		} else {
> > +			WARN_ON(i > 0);
> > +			ret = fb->funcs->create_handle(fb, file_priv,
> > +						       &r->handles[i]);
> > +		}
> 
> getfb1 doesn't allow non-master/root to see the handles. Here we
> don't
> seem to have that same protection?

Hmm yeah sorry I missed the protections handling.
I think we can just set the getfb2 ioctl flags as
DRM_MASTER|DRM_ROOT_ONLY

> > +
> > +		if (ret != 0)
> > +			goto out;
> 
> Could be just 'break;' and then we wouldn't even need the label.

Will do.

> 
> Rest lgtm.
> 

Much appreciated
Daniel Vetter Dec. 14, 2019, 12:01 a.m. UTC | #11
On Fri, Dec 13, 2019 at 10:52:03PM +0000, Li, Juston wrote:
> On Fri, 2019-12-13 at 23:36 +0200, Ville Syrjälä wrote:
> > On Thu, Oct 03, 2019 at 11:31:25AM -0700, Juston Li wrote:
> > > From: Daniel Stone <daniels@collabora.com>
> > > 
> > > getfb2 allows us to pass multiple planes and modifiers, just like
> > > addfb2
> > > over addfb.
> > > 
> > > Changes since v1:
> > >  - unused modifiers set to 0 instead of DRM_FORMAT_MOD_INVALID
> > >  - update ioctl number
> > > 
> > > Signed-off-by: Daniel Stone <daniels@collabora.com>
> > > Signed-off-by: Juston Li <juston.li@intel.com>
> > > ---
> > >  drivers/gpu/drm/drm_crtc_internal.h |   2 +
> > >  drivers/gpu/drm/drm_framebuffer.c   | 110
> > > ++++++++++++++++++++++++++++
> > >  drivers/gpu/drm/drm_ioctl.c         |   1 +
> > >  include/uapi/drm/drm.h              |   2 +
> > >  4 files changed, 115 insertions(+)
> > > 
> > > diff --git a/drivers/gpu/drm/drm_crtc_internal.h
> > > b/drivers/gpu/drm/drm_crtc_internal.h
> > > index c7d5e4c21423..16f2413403aa 100644
> > > --- a/drivers/gpu/drm/drm_crtc_internal.h
> > > +++ b/drivers/gpu/drm/drm_crtc_internal.h
> > > @@ -216,6 +216,8 @@ int drm_mode_rmfb_ioctl(struct drm_device *dev,
> > >  			void *data, struct drm_file *file_priv);
> > >  int drm_mode_getfb(struct drm_device *dev,
> > >  		   void *data, struct drm_file *file_priv);
> > > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > > +			  void *data, struct drm_file *file_priv);
> > >  int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
> > >  			   void *data, struct drm_file *file_priv);
> > >  
> > > diff --git a/drivers/gpu/drm/drm_framebuffer.c
> > > b/drivers/gpu/drm/drm_framebuffer.c
> > > index 57564318ceea..6db54f177443 100644
> > > --- a/drivers/gpu/drm/drm_framebuffer.c
> > > +++ b/drivers/gpu/drm/drm_framebuffer.c
> > > @@ -31,6 +31,7 @@
> > >  #include <drm/drm_file.h>
> > >  #include <drm/drm_fourcc.h>
> > >  #include <drm/drm_framebuffer.h>
> > > +#include <drm/drm_gem.h>
> > >  #include <drm/drm_print.h>
> > >  #include <drm/drm_util.h>
> > >  
> > > @@ -548,7 +549,116 @@ int drm_mode_getfb(struct drm_device *dev,
> > >  
> > >  out:
> > >  	drm_framebuffer_put(fb);
> > > +	return ret;
> > > +}
> > > +
> > > +/**
> > > + * drm_mode_getfb2 - get extended FB info
> > > + * @dev: drm device for the ioctl
> > > + * @data: data pointer for the ioctl
> > > + * @file_priv: drm file for the ioctl call
> > > + *
> > > + * Lookup the FB given its ID and return info about it.
> > > + *
> > > + * Called by the user via ioctl.
> > > + *
> > > + * Returns:
> > > + * Zero on success, negative errno on failure.
> > > + */
> > > +int drm_mode_getfb2_ioctl(struct drm_device *dev,
> > > +			  void *data, struct drm_file *file_priv)
> > > +{
> > > +	struct drm_mode_fb_cmd2 *r = data;
> > > +	struct drm_framebuffer *fb;
> > > +	unsigned int i;
> > > +	int ret;
> > > +
> > > +	if (!drm_core_check_feature(dev, DRIVER_MODESET))
> > > +		return -EINVAL;
> > > +
> > > +	fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
> > > +	if (!fb)
> > > +		return -ENOENT;
> > > +
> > > +	/* For multi-plane framebuffers, we require the driver to place
> > > the
> > > +	 * GEM objects directly in the drm_framebuffer. For single-
> > > plane
> > > +	 * framebuffers, we can fall back to create_handle.
> > > +	 */
> > > +	if (!fb->obj[0] &&
> > > +	    (fb->format->num_planes > 1 || !fb->funcs->create_handle))
> > > {
> > > +		ret = -ENODEV;
> > > +		goto out;
> > > +	}
> > > +
> > > +	r->height = fb->height;
> > > +	r->width = fb->width;
> > > +	r->pixel_format = fb->format->format;
> > > +
> > > +	r->flags = 0;
> > > +	if (dev->mode_config.allow_fb_modifiers)
> > > +		r->flags |= DRM_MODE_FB_MODIFIERS;
> > > +
> > > +	for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
> > > +		r->handles[i] = 0;
> > > +		r->pitches[i] = 0;
> > > +		r->offsets[i] = 0;
> > > +		r->modifier[i] = 0;
> > > +	}
> > >  
> > > +	for (i = 0; i < fb->format->num_planes; i++) {
> > > +		int j;
> > > +
> > > +		r->pitches[i] = fb->pitches[i];
> > > +		r->offsets[i] = fb->offsets[i];
> > > +		if (dev->mode_config.allow_fb_modifiers)
> > > +			r->modifier[i] = fb->modifier;
> > > +
> > > +		/* If we reuse the same object for multiple planes,
> > > also
> > > +		 * return the same handle.
> > > +		 */
> > > +		for (j = 0; j < i; j++) {
> > > +			if (fb->obj[i] == fb->obj[j]) {
> > > +				r->handles[i] = r->handles[j];
> > > +				break;
> > > +			}
> > > +		}
> > > +
> > > +		if (r->handles[i])
> > > +			continue;
> > > +
> > > +		if (fb->obj[i]) {
> > > +			ret = drm_gem_handle_create(file_priv, fb-
> > > >obj[i],
> > > +						    &r->handles[i]);
> > > +		} else {
> > > +			WARN_ON(i > 0);
> > > +			ret = fb->funcs->create_handle(fb, file_priv,
> > > +						       &r->handles[i]);
> > > +		}
> > 
> > getfb1 doesn't allow non-master/root to see the handles. Here we
> > don't
> > seem to have that same protection?
> 
> Hmm yeah sorry I missed the protections handling.
> I think we can just set the getfb2 ioctl flags as
> DRM_MASTER|DRM_ROOT_ONLY

Since this was missed, can you pls extend the igt to test for this? Iirc
the getfb igt makes sure non-root doesn't get this ...

Also for consistency I think doing the same as getfb would be good. Fewer
surprises.
-Daniel

> 
> > > +
> > > +		if (ret != 0)
> > > +			goto out;
> > 
> > Could be just 'break;' and then we wouldn't even need the label.
> 
> Will do.
> 
> > 
> > Rest lgtm.
> > 
> 
> Much appreciated
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_crtc_internal.h b/drivers/gpu/drm/drm_crtc_internal.h
index c7d5e4c21423..16f2413403aa 100644
--- a/drivers/gpu/drm/drm_crtc_internal.h
+++ b/drivers/gpu/drm/drm_crtc_internal.h
@@ -216,6 +216,8 @@  int drm_mode_rmfb_ioctl(struct drm_device *dev,
 			void *data, struct drm_file *file_priv);
 int drm_mode_getfb(struct drm_device *dev,
 		   void *data, struct drm_file *file_priv);
+int drm_mode_getfb2_ioctl(struct drm_device *dev,
+			  void *data, struct drm_file *file_priv);
 int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
 			   void *data, struct drm_file *file_priv);
 
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index 57564318ceea..6db54f177443 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -31,6 +31,7 @@ 
 #include <drm/drm_file.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_framebuffer.h>
+#include <drm/drm_gem.h>
 #include <drm/drm_print.h>
 #include <drm/drm_util.h>
 
@@ -548,7 +549,116 @@  int drm_mode_getfb(struct drm_device *dev,
 
 out:
 	drm_framebuffer_put(fb);
+	return ret;
+}
+
+/**
+ * drm_mode_getfb2 - get extended FB info
+ * @dev: drm device for the ioctl
+ * @data: data pointer for the ioctl
+ * @file_priv: drm file for the ioctl call
+ *
+ * Lookup the FB given its ID and return info about it.
+ *
+ * Called by the user via ioctl.
+ *
+ * Returns:
+ * Zero on success, negative errno on failure.
+ */
+int drm_mode_getfb2_ioctl(struct drm_device *dev,
+			  void *data, struct drm_file *file_priv)
+{
+	struct drm_mode_fb_cmd2 *r = data;
+	struct drm_framebuffer *fb;
+	unsigned int i;
+	int ret;
+
+	if (!drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
+	fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
+	if (!fb)
+		return -ENOENT;
+
+	/* For multi-plane framebuffers, we require the driver to place the
+	 * GEM objects directly in the drm_framebuffer. For single-plane
+	 * framebuffers, we can fall back to create_handle.
+	 */
+	if (!fb->obj[0] &&
+	    (fb->format->num_planes > 1 || !fb->funcs->create_handle)) {
+		ret = -ENODEV;
+		goto out;
+	}
+
+	r->height = fb->height;
+	r->width = fb->width;
+	r->pixel_format = fb->format->format;
+
+	r->flags = 0;
+	if (dev->mode_config.allow_fb_modifiers)
+		r->flags |= DRM_MODE_FB_MODIFIERS;
+
+	for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
+		r->handles[i] = 0;
+		r->pitches[i] = 0;
+		r->offsets[i] = 0;
+		r->modifier[i] = 0;
+	}
 
+	for (i = 0; i < fb->format->num_planes; i++) {
+		int j;
+
+		r->pitches[i] = fb->pitches[i];
+		r->offsets[i] = fb->offsets[i];
+		if (dev->mode_config.allow_fb_modifiers)
+			r->modifier[i] = fb->modifier;
+
+		/* If we reuse the same object for multiple planes, also
+		 * return the same handle.
+		 */
+		for (j = 0; j < i; j++) {
+			if (fb->obj[i] == fb->obj[j]) {
+				r->handles[i] = r->handles[j];
+				break;
+			}
+		}
+
+		if (r->handles[i])
+			continue;
+
+		if (fb->obj[i]) {
+			ret = drm_gem_handle_create(file_priv, fb->obj[i],
+						    &r->handles[i]);
+		} else {
+			WARN_ON(i > 0);
+			ret = fb->funcs->create_handle(fb, file_priv,
+						       &r->handles[i]);
+		}
+
+		if (ret != 0)
+			goto out;
+	}
+
+out:
+	if (ret != 0) {
+		/* Delete any previously-created handles on failure. */
+		for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
+			int j;
+
+			if (r->handles[i])
+				drm_gem_handle_delete(file_priv, r->handles[i]);
+
+			/* Zero out any handles identical to the one we just
+			 * deleted.
+			 */
+			for (j = i + 1; j < ARRAY_SIZE(r->handles); j++) {
+				if (r->handles[j] == r->handles[i])
+					r->handles[j] = 0;
+			}
+		}
+	}
+
+	drm_framebuffer_put(fb);
 	return ret;
 }
 
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index fcd728d7cf72..b1fafce3ad8c 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -671,6 +671,7 @@  static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY, drm_connector_property_set_ioctl, DRM_MASTER),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB, drm_mode_getblob_ioctl, 0),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, 0),
+	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB2, drm_mode_getfb2_ioctl, 0),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb_ioctl, 0),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2_ioctl, 0),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb_ioctl, 0),
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index 8a5b2f8f8eb9..021f33675ba2 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -947,6 +947,8 @@  extern "C" {
 #define DRM_IOCTL_SYNCOBJ_TRANSFER	DRM_IOWR(0xCC, struct drm_syncobj_transfer)
 #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL	DRM_IOWR(0xCD, struct drm_syncobj_timeline_array)
 
+#define DRM_IOCTL_MODE_GETFB2		DRM_IOWR(0xCE, struct drm_mode_fb_cmd2)
+
 /**
  * Device specific ioctls should only be in their respective headers
  * The device specific ioctl range is from 0x40 to 0x9f.