Skip to contentSkip to conversation

Need a drmModeGetFB2() or similar query

PATCH In review Joe Kniss 4 participants 6 messages Jul 27, 2017 – Aug 2, 2017 1 message not in the archive

Subsystems (18)
lore
Share & tools
lore

Joe Kniss

author
#0 lore raw

Hi,
I am a recent addition to Google's ChromeOS gfx team. I am currently
working on display testing and reporting. An important part of this is
our screen capture tool, which works by querying drm for crtcs, planes, and fbs. Unfortunately, there is only limited information available via drmModeGetFB(), which often wrong information when drmModeAddFB2() was used
to create the fbs. For example, if the pixel format is NV12 or YUV420,
the fb returned knows nothing about the additional buffer planes required
by these formats. Ideally, we would like a function (e.g. drmModeGetFB2)
to return information symmetric with drmModeAddFB2 including the pixel format id, buffer plane information etc.

I am curious what would be the best way to make this work. I'm happy to create the patch, but need some guidance first.

cheers,
-j

Signature · 2 lines
Dr. Joe Michael Kniss |  Google ChromeOS |  [email protected]   |
1-801-898-7977

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw

PATCH 1/1 Add drm ioctl DRM_IOCTL_MODE_GETFB2 & associated helpers.

New getfb2 functionality uses drm_mode_fb_cmd2 struct to be symmetric
with addfb2. Also modifies *_fb_create_handle() calls to accept a
format_plane_index so that handles for each plane can be generated. Previously, many *_fb_create_handle() calls simply defaulted to plane 0 only.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c |  5 +-
 drivers/gpu/drm/armada/armada_fb.c          |  1 +
 drivers/gpu/drm/drm_crtc_internal.h         |  2 +
 drivers/gpu/drm/drm_fb_cma_helper.c         | 11 ++--
 drivers/gpu/drm/drm_framebuffer.c           | 79 ++++++++++++++++++++++++++++-
 drivers/gpu/drm/drm_ioctl.c                 |  1 +
 drivers/gpu/drm/exynos/exynos_drm_fb.c      |  7 ++-
 drivers/gpu/drm/gma500/framebuffer.c        |  2 +
 drivers/gpu/drm/i915/intel_display.c        |  1 +
 drivers/gpu/drm/mediatek/mtk_drm_fb.c       |  1 +
 drivers/gpu/drm/msm/msm_fb.c                |  5 +-
 drivers/gpu/drm/nouveau/nouveau_display.c   |  1 +
 drivers/gpu/drm/omapdrm/omap_fb.c           |  5 +-
 drivers/gpu/drm/radeon/radeon_display.c     |  5 +-
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  |  6 ++-
 drivers/gpu/drm/tegra/fb.c                  |  9 +++-
 include/drm/drm_framebuffer.h               |  1 +
 include/uapi/drm/drm.h                      |  2 +
 18 files changed, 127 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c +3 -2
index 39fc388f222a..c77c1cd265a0 100644
@@ -566,8 +566,9 @@ static void amdgpu_user_framebuffer_destroy(struct drm_framebuffer *fb)
 }
 
 static int amdgpu_user_framebuffer_create_handle(struct drm_framebuffer *fb,
-						  struct drm_file *file_priv,
-						  unsigned int *handle)
+						 unsigned int plane_index,
+						 struct drm_file *file_priv,
+						 unsigned int *handle)
 {
 	struct amdgpu_framebuffer *amdgpu_fb = to_amdgpu_framebuffer(fb);
 
drivers/gpu/drm/armada/armada_fb.c +1 -0
index 2a7eb6817c36..9f237544f6c5 100644
@@ -23,6 +23,7 @@ static void armada_fb_destroy(struct drm_framebuffer *fb)
 }
 
 static int armada_fb_create_handle(struct drm_framebuffer *fb,
+	unsigned int format_plane_index,
 	struct drm_file *dfile, unsigned int *handle)
 {
 	struct armada_framebuffer *dfb = drm_fb_to_armada_fb(fb);
drivers/gpu/drm/drm_crtc_internal.h +2 -0
index 955c5690bf64..ec8d913240fe 100644
@@ -170,6 +170,8 @@ int drm_mode_rmfb(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(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);
 
drivers/gpu/drm/drm_fb_cma_helper.c +7 -4
index 596fabf18c3e..5fd7bcc2c6d1 100644
@@ -110,13 +110,16 @@ void drm_fb_cma_destroy(struct drm_framebuffer *fb)
 }
 EXPORT_SYMBOL(drm_fb_cma_destroy);
 
-int drm_fb_cma_create_handle(struct drm_framebuffer *fb,
-	struct drm_file *file_priv, unsigned int *handle)
+static int drm_fb_cma_create_handle(struct drm_framebuffer *fb,
+				    unsigned int format_plane_index,
+				    struct drm_file *file_priv,
+				    unsigned int *handle)
 {
 	struct drm_fb_cma *fb_cma = to_fb_cma(fb);
-
+	if (format_plane_index >= 4 || !fb_dma->obj[format_plane_index])
+		return -ENOENT;
 	return drm_gem_handle_create(file_priv,
-			&fb_cma->obj[0]->base, handle);
+			&fb_cma->obj[format_plane_index]->base, handle);
 }
 EXPORT_SYMBOL(drm_fb_cma_create_handle);
 
drivers/gpu/drm/drm_framebuffer.c +78 -1

97 lines not on this page · raw message

drivers/gpu/drm/drm_ioctl.c +1 -0
index a7c61c23685a..a9b578dc5d17 100644
@@ -627,6 +627,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY, drm_mode_connector_property_set_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB, drm_mode_getblob_ioctl, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
+	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB2, drm_mode_getfb2, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
drivers/gpu/drm/exynos/exynos_drm_fb.c +5 -2
index c77a5aced81a..5e8b774dc1af 100644
@@ -88,13 +88,16 @@ static void exynos_drm_fb_destroy(struct drm_framebuffer *fb)
 }
 
 static int exynos_drm_fb_create_handle(struct drm_framebuffer *fb,
+				       unsigned int format_plane_index,
 					struct drm_file *file_priv,
 					unsigned int *handle)
 {
 	struct exynos_drm_fb *exynos_fb = to_exynos_fb(fb);
-
+	if (format_plane_index >= MAX_FB_BUFFER ||
+	    !exynos_fb->exynos_gem[format_plane_index])
+		return -ENOENT;
 	return drm_gem_handle_create(file_priv,
-				     &exynos_fb->exynos_gem[0]->base, handle);
+		     &exynos_fb->exynos_gem[format_plane_index]->base, handle);
 }
 
 static const struct drm_framebuffer_funcs exynos_drm_fb_funcs = {
drivers/gpu/drm/gma500/framebuffer.c +2 -0
index ffe6b4ffa1a8..c221544b4c6a 100644
@@ -42,6 +42,7 @@
 
 static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb);
 static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb,
+					      unsigned int format_plane_index,
 					      struct drm_file *file_priv,
 					      unsigned int *handle);
 
@@ -619,6 +620,7 @@ static void psbfb_output_poll_changed(struct drm_device *dev)
  *	the work for us
  */
 static int psb_user_framebuffer_create_handle(struct drm_framebuffer *fb,
+					      unsigned int plane_index,
 					      struct drm_file *file_priv,
 					      unsigned int *handle)
 {
drivers/gpu/drm/i915/intel_display.c +1 -0
index 3282b0f4b134..54fdd30b0598 100644
@@ -15853,6 +15853,7 @@ static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
 }
 
 static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
+						unsigned int format_plane_index,
 						struct drm_file *file,
 						unsigned int *handle)
 {
drivers/gpu/drm/mediatek/mtk_drm_fb.c +1 -0
index d4246c9dceae..8343144ba1cd 100644
@@ -44,6 +44,7 @@ struct drm_gem_object *mtk_fb_get_gem_obj(struct drm_framebuffer *fb)
 }
 
 static int mtk_drm_fb_create_handle(struct drm_framebuffer *fb,
+				    unsigned int format_plane_index,
 				    struct drm_file *file_priv,
 				    unsigned int *handle)
 {
drivers/gpu/drm/msm/msm_fb.c +4 -1
index 5cf165c9c3a9..de92fc8a7a1c 100644
@@ -30,12 +30,15 @@ struct msm_framebuffer {
 
 
 static int msm_framebuffer_create_handle(struct drm_framebuffer *fb,
+		unsigned int format_plane_index,
 		struct drm_file *file_priv,
 		unsigned int *handle)
 {
 	struct msm_framebuffer *msm_fb = to_msm_framebuffer(fb);
+	if (format_plane_index >= MAX_PLANE)
+		return -ENOENT;
 	return drm_gem_handle_create(file_priv,
-			msm_fb->planes[0], handle);
+			msm_fb->planes[format_plane_index], handle);
 }
 
 static void msm_framebuffer_destroy(struct drm_framebuffer *fb)
drivers/gpu/drm/nouveau/nouveau_display.c +1 -0
index 72fdba1a1c5d..bc30c0d3d9cd 100644
@@ -237,6 +237,7 @@ nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb)
 
 static int
 nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb,
+				       unsigned int format_plane_index,
 				       struct drm_file *file_priv,
 				       unsigned int *handle)
 {
drivers/gpu/drm/omapdrm/omap_fb.c +4 -1
index 29dc677dd4d3..a982c72a773e 100644
@@ -90,12 +90,15 @@ struct omap_framebuffer {
 };
 
 static int omap_framebuffer_create_handle(struct drm_framebuffer *fb,
+		unsigned int format_plane_index,
 		struct drm_file *file_priv,
 		unsigned int *handle)
 {
 	struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb);
+	if (format_plane_index >= 4 || !omap_fb->planes[format_plane_index])
+		return -ENOENT;
 	return drm_gem_handle_create(file_priv,
-			omap_fb->planes[0].bo, handle);
+			omap_fb->planes[format_plane_index].bo, handle);
 }
 
 static void omap_framebuffer_destroy(struct drm_framebuffer *fb)
drivers/gpu/drm/radeon/radeon_display.c +3 -2
index aea8b62835a4..2188e6341cd9 100644
@@ -1306,8 +1306,9 @@ static void radeon_user_framebuffer_destroy(struct drm_framebuffer *fb)
 }
 
 static int radeon_user_framebuffer_create_handle(struct drm_framebuffer *fb,
-						  struct drm_file *file_priv,
-						  unsigned int *handle)
+						 unsigned int plane_index,
+						 struct drm_file *file_priv,
+						 unsigned int *handle)
 {
 	struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb);
 
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +4 -2
index c9ccdf8f44bb..206d93249519 100644
@@ -55,13 +55,15 @@ static void rockchip_drm_fb_destroy(struct drm_framebuffer *fb)
 }
 
 static int rockchip_drm_fb_create_handle(struct drm_framebuffer *fb,
+					 unsigned int format_plane_index,
 					 struct drm_file *file_priv,
 					 unsigned int *handle)
 {
 	struct rockchip_drm_fb *rockchip_fb = to_rockchip_fb(fb);
-
+	if (format_plane_index >= ROCKCHIP_MAX_FB_BUFFER)
+		return -ENOENT;
 	return drm_gem_handle_create(file_priv,
-				     rockchip_fb->obj[0], handle);
+				  rockchip_fb->obj[format_plane_index], handle);
 }
 
 static int rockchip_drm_fb_dirty(struct drm_framebuffer *fb,
drivers/gpu/drm/tegra/fb.c +7 -2
index f142f6a4db25..ff206b143503 100644
@@ -81,11 +81,16 @@ static void tegra_fb_destroy(struct drm_framebuffer *framebuffer)
 }
 
 static int tegra_fb_create_handle(struct drm_framebuffer *framebuffer,
+				  unsigned int format_plane_index,
 				  struct drm_file *file, unsigned int *handle)
 {
 	struct tegra_fb *fb = to_tegra_fb(framebuffer);
-
-	return drm_gem_handle_create(file, &fb->planes[0]->gem, handle);
+	if (format_plane_index >= fb->num_planes ||
+	    !fb->planes[format_plane_index])
+		return -ENOENT;
+	return drm_gem_handle_create(file,
+				     &fb->planes[format_plane_index]->gem,
+				     handle);
 }
 
 static const struct drm_framebuffer_funcs tegra_fb_funcs = {
include/drm/drm_framebuffer.h +1 -0
index dd1e3e99dcff..2fb398cb4646 100644
@@ -66,6 +66,7 @@ struct drm_framebuffer_funcs {
 	 * 0 on success or a negative error code on failure.
 	 */
 	int (*create_handle)(struct drm_framebuffer *fb,
+			     unsigned int plane_index,
 			     struct drm_file *file_priv,
 			     unsigned int *handle);
 	/**
include/uapi/drm/drm.h +2 -0
index b2c52843bc70..c81c75335cca 100644
@@ -814,6 +814,8 @@ extern "C" {
 #define DRM_IOCTL_MODE_CREATEPROPBLOB	DRM_IOWR(0xBD, struct drm_mode_create_blob)
 #define DRM_IOCTL_MODE_DESTROYPROPBLOB	DRM_IOWR(0xBE, struct drm_mode_destroy_blob)
 
+#define DRM_IOCTL_MODE_GETFB2  DRM_IOWR(0xC4, 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.
Signature · 1 line
2.14.0.rc0.400.g1c36432dff-goog
#2 lore raw

Re: [PATCH] Add drm ioctl DRM_IOCTL_MODE_GETFB2 & associated helpers.

Hi Joe,

Thank you for the patch.

Quoted 2 lines · On Monday 31 Jul 2017 11:29:13 Joe Kniss wrote:

New getfb2 functionality uses drm_mode_fb_cmd2 struct to be symmetric with addfb2.

What's the use case for this ? We haven't needed such an ioctl for so long that it seemed to me that userspace doesn't really need it, but I could be wrong.

Quoted 4 lines

Also modifies *_fb_create_handle() calls to accept a format_plane_index so that handles for each plane can be generated. Previously, many *_fb_create_handle() calls simply defaulted to plane 0 only.

And with this patch the amd/amdgpu, armada, gma500, i915, mediatek, msm, nouveau and radeon drivers still do. Do none of them support multi-planar formats ?

Quoted 21 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c |  5 +-
 drivers/gpu/drm/armada/armada_fb.c          |  1 +
 drivers/gpu/drm/drm_crtc_internal.h         |  2 +
 drivers/gpu/drm/drm_fb_cma_helper.c         | 11 ++--
 drivers/gpu/drm/drm_framebuffer.c           | 79 +++++++++++++++++++++++++-
 drivers/gpu/drm/drm_ioctl.c                 |  1 +
 drivers/gpu/drm/exynos/exynos_drm_fb.c      |  7 ++-
 drivers/gpu/drm/gma500/framebuffer.c        |  2 +
 drivers/gpu/drm/i915/intel_display.c        |  1 +
 drivers/gpu/drm/mediatek/mtk_drm_fb.c       |  1 +
 drivers/gpu/drm/msm/msm_fb.c                |  5 +-
 drivers/gpu/drm/nouveau/nouveau_display.c   |  1 +
 drivers/gpu/drm/omapdrm/omap_fb.c           |  5 +-
 drivers/gpu/drm/radeon/radeon_display.c     |  5 +-
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  |  6 ++-
 drivers/gpu/drm/tegra/fb.c                  |  9 +++-
 include/drm/drm_framebuffer.h               |  1 +
 include/uapi/drm/drm.h                      |  2 +
 18 files changed, 127 insertions(+), 17 deletions(-)

[snip]

Quoted 11 lines
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_framebuffer.c index 28a0108a1ab8..67b3be1bedbc 100644

drivers/gpu/drm/drm_framebuffer.c +1 -0
@@ -24,6 +24,7 @@
 #include <drm/drmP.h>
 #include <drm/drm_auth.h>
 #include <drm/drm_framebuffer.h>
+#include <drm/drm_gem.h>
 
 #include "drm_crtc_internal.h"

[snip]

Quoted 55 lines
drivers/gpu/drm/drm_framebuffer.c +43 -0
+/**
+ * drm_mode_getfb2 - get 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(struct drm_device *dev,
+		   void *data, struct drm_file *file_priv)
+{
+	struct drm_mode_fb_cmd2 *r = data;
+	struct drm_framebuffer *fb;
+	int ret, i;
+
+	if (!drm_core_check_feature(dev, DRIVER_MODESET))
+		return -EINVAL;
+
+	fb = drm_framebuffer_lookup(dev, r->fb_id);
+	if (!fb)
+		return -ENOENT;
+
+	r->height = fb->height;
+	r->width = fb->width;
+	r->pixel_format = fb->format->format;
+	for (i = 0; i < 4; ++i) {
+		r->pitches[i] = fb->pitches[i];
+		r->offsets[i] = fb->offsets[i];
+		r->modifier[i] = fb->modifier;
+		r->handles[i] = 0;
+	}
+
+	for (i = 0; i < fb->format->num_planes; ++i) {
+		if (fb->funcs->create_handle) {
+			if (drm_is_current_master(file_priv) ||
+			    capable(CAP_SYS_ADMIN) ||
+			    drm_is_control_client(file_priv)) {
+				ret = fb->funcs->create_handle(fb, i,

file_priv,

drivers/gpu/drm/drm_framebuffer.c +1 -0
+							       

&r->handles[i]);

drivers/gpu/drm/drm_framebuffer.c +4 -0
+				if (ret)
+					break;
+			} else {
+				/* GET_FB() is an unprivileged ioctl so we

must

drivers/gpu/drm/drm_framebuffer.c +3 -0
+				 * not return a buffer-handle to non-master
+				 * processes! For backwards-compatibility
+				 * reasons, we cannot make GET_FB()

privileged,

drivers/gpu/drm/drm_framebuffer.c int drm_mode_getfb(struct drm_device *dev, · line 514

Quoted 2 lines
drivers/gpu/drm/drm_framebuffer.c +2 -0
+				 * so just return an invalid handle for
+				 * non-masters. */

There's no backward compatibility to handle here, just make it privileged if it has to be.

drivers/gpu/drm/drm_framebuffer.c int drm_mode_getfb(struct drm_device *dev,

Quoted 10 lines
drivers/gpu/drm/drm_framebuffer.c +10 -0
+				r->handles[i] = 0;
+				ret = 0;
+			}
+		} else {
+			ret = -ENODEV;
+			break;
+		}
+	}
+
+	/* If handle creation failed, delete/dereference any that were made. 

*/

Quoted 5 lines
drivers/gpu/drm/drm_framebuffer.c +4 -0
+	if (ret) {
+		for (i = 0; i < 4; ++i) {
+			if (r->handles[i])
+				drm_gem_handle_delete(file_priv, r-

handles[i]);

My initial reaction to this was to reply that not all drivers use GEM, but after some investigation it seems they actually do. If that's really the case, we could get rid of the .create_handle() operation completely, which should simplify the implementation of both DRM_IOCTL_MODE_GETFB and DRM_IOCTL_MODE_GETFB2.

Quoted 8 lines
drivers/gpu/drm/drm_framebuffer.c +8 -0
+			r->handles[i] = 0;
+		}
+	}
+
+	drm_framebuffer_unreference(fb);
+
+	return ret;
+}

[snip]

Quoted 5 lines
(quoted diff) +0 -0

b/drivers/gpu/drm/omapdrm/omap_fb.c index 29dc677dd4d3..a982c72a773e 100644

drivers/gpu/drm/omapdrm/omap_fb.c struct omap_framebuffer { · line 98

Quoted 9 lines
drivers/gpu/drm/omapdrm/omap_fb.c +2 -0
@@ -90,12 +90,15 @@ struct omap_framebuffer {
 };
 
 static int omap_framebuffer_create_handle(struct drm_framebuffer *fb,
+		unsigned int format_plane_index,
 		struct drm_file *file_priv,
 		unsigned int *handle)
 {
 	struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb);
+	if (format_plane_index >= 4 || !omap_fb->planes[format_plane_index])

The first check shouldn't be needed, the core should never call this operation with an index >= 4.

Quoted 5 lines
drivers/gpu/drm/omapdrm/omap_fb.c +2 -1
+		return -ENOENT;
 	return drm_gem_handle_create(file_priv,
-			omap_fb->planes[0].bo, handle);
+			omap_fb->planes[format_plane_index].bo, handle);
 }

[snip]

include/uapi/drm/drm.h extern "C" { · line 820

Quoted 12 lines
include/uapi/drm/drm.h +2 -0
index b2c52843bc70..c81c75335cca 100644
@@ -814,6 +814,8 @@ extern "C" {
 #define DRM_IOCTL_MODE_CREATEPROPBLOB	DRM_IOWR(0xBD, struct
 drm_mode_create_blob)
 #define DRM_IOCTL_MODE_DESTROYPROPBLOB	DRM_IOWR(0xBE, struct
 drm_mode_destroy_blob)
 
+#define DRM_IOCTL_MODE_GETFB2  DRM_IOWR(0xC4, struct drm_mode_fb_cmd2)
+

Which tree is this based on ? The last defined ioctl (DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE) is 0xC2 in drm-next and drm-misc-next.

Quoted 3 lines
include/uapi/drm/drm.h +0 -0
 /**

* Device specific ioctls should only be in their respective headers
* The device specific ioctl range is from 0x40 to 0x9f.

Signature · 8 lines
Regards,

Laurent Pinchart

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#3 lore raw

Re: [PATCH] Add drm ioctl DRM_IOCTL_MODE_GETFB2 & associated helpers.

Thanks for the quick review!

Quoted 5 lines · Laurent Pinchart

Hi Joe,

Thank you for the patch.

On Monday 31 Jul 2017 11:29:13 Joe Kniss wrote:

Quoted 8 lines
Quoted 2 lines

New getfb2 functionality uses drm_mode_fb_cmd2 struct to be symmetric with addfb2.

What's the use case for this ? We haven't needed such an ioctl for so long that it seemed to me that userspace doesn't really need it, but I could be wrong.

Sorry, I failed to reference the original email. Here it is:

<snip>
I am a recent addition to Google's ChromeOS gfx team. I am currently
working on display testing and reporting. An important part of this is
our screen capture tool, which works by querying drm for crtcs, planes, and fbs. Unfortunately, there is only limited information available via drmModeGetFB(), which often wrong information when drmModeAddFB2() was used
to create the fbs. For example, if the pixel format is NV12 or YUV420,
the fb returned knows nothing about the additional buffer planes required
by these formats. Ideally, we would like a function (e.g. drmModeGetFB2)
to return information symmetric with drmModeAddFB2 including the pixel format id, buffer plane information etc.
</snip>
ChromeOS has needed this functionality from the start, for both testing and error reporting. We got away with guessing the buffer's format (32bit xrgb) until now. We are now enabling overlays and more formats including multi-planar (e.g. NV12). Current getfb() reports neither the pixel format nor planar information. Without this information, going forward, our gfx testing is going to break. It would be great if we had access to higher level buffer structs (like gbm), but we generally don't since they would be created by other apps (chrome browser, android apps, etc...).

Quoted 10 lines
Quoted 4 lines

Also modifies *_fb_create_handle() calls to accept a format_plane_index so that handles for each plane can be generated. Previously, many *_fb_create_handle() calls simply defaulted to plane 0 only.

And with this patch the amd/amdgpu, armada, gma500, i915, mediatek, msm, nouveau and radeon drivers still do. Do none of them support multi-planar formats ?

I would imagine that some of these do support multi-planar formats, but

they don't appear to have them implemented yet (except perhaps as offsets into a single buffer). I will certainly be looking into this soon, but any changes will come in future patches.

Quoted 124 lines
Quoted 7 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c |  5 +-
 drivers/gpu/drm/armada/armada_fb.c          |  1 +
 drivers/gpu/drm/drm_crtc_internal.h         |  2 +
 drivers/gpu/drm/drm_fb_cma_helper.c         | 11 ++--
 drivers/gpu/drm/drm_framebuffer.c           | 79

+++++++++++++++++++++++++-

Quoted 14 lines
 drivers/gpu/drm/drm_ioctl.c                 |  1 +
 drivers/gpu/drm/exynos/exynos_drm_fb.c      |  7 ++-
 drivers/gpu/drm/gma500/framebuffer.c        |  2 +
 drivers/gpu/drm/i915/intel_display.c        |  1 +
 drivers/gpu/drm/mediatek/mtk_drm_fb.c       |  1 +
 drivers/gpu/drm/msm/msm_fb.c                |  5 +-
 drivers/gpu/drm/nouveau/nouveau_display.c   |  1 +
 drivers/gpu/drm/omapdrm/omap_fb.c           |  5 +-
 drivers/gpu/drm/radeon/radeon_display.c     |  5 +-
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  |  6 ++-
 drivers/gpu/drm/tegra/fb.c                  |  9 +++-
 include/drm/drm_framebuffer.h               |  1 +
 include/uapi/drm/drm.h                      |  2 +
 18 files changed, 127 insertions(+), 17 deletions(-)

[snip]

Quoted 2 lines
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_framebuffer.c index 28a0108a1ab8..67b3be1bedbc

100644

Quoted 9 lines
drivers/gpu/drm/drm_framebuffer.c +1 -0
@@ -24,6 +24,7 @@
 #include <drm/drmP.h>
 #include <drm/drm_auth.h>
 #include <drm/drm_framebuffer.h>
+#include <drm/drm_gem.h>
 
 #include "drm_crtc_internal.h"

[snip]

Quoted 55 lines
drivers/gpu/drm/drm_framebuffer.c +43 -0
+/**
+ * drm_mode_getfb2 - get 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(struct drm_device *dev,
+                void *data, struct drm_file *file_priv)
+{
+     struct drm_mode_fb_cmd2 *r = data;
+     struct drm_framebuffer *fb;
+     int ret, i;
+
+     if (!drm_core_check_feature(dev, DRIVER_MODESET))
+             return -EINVAL;
+
+     fb = drm_framebuffer_lookup(dev, r->fb_id);
+     if (!fb)
+             return -ENOENT;
+
+     r->height = fb->height;
+     r->width = fb->width;
+     r->pixel_format = fb->format->format;
+     for (i = 0; i < 4; ++i) {
+             r->pitches[i] = fb->pitches[i];
+             r->offsets[i] = fb->offsets[i];
+             r->modifier[i] = fb->modifier;
+             r->handles[i] = 0;
+     }
+
+     for (i = 0; i < fb->format->num_planes; ++i) {
+             if (fb->funcs->create_handle) {
+                     if (drm_is_current_master(file_priv) ||
+                         capable(CAP_SYS_ADMIN) ||
+                         drm_is_control_client(file_priv)) {
+                             ret = fb->funcs->create_handle(fb, i,

file_priv,
+
&r->handles[i]);

drivers/gpu/drm/drm_framebuffer.c +4 -0
+                             if (ret)
+                                     break;
+                     } else {
+                             /* GET_FB() is an unprivileged ioctl so we

must

drivers/gpu/drm/drm_framebuffer.c +3 -0
+                              * not return a buffer-handle to non-master
+                              * processes! For backwards-compatibility
+                              * reasons, we cannot make GET_FB()

privileged,

drivers/gpu/drm/drm_framebuffer.c int drm_mode_getfb(struct drm_device *dev, · line 514

Quoted 2 lines
drivers/gpu/drm/drm_framebuffer.c +2 -0
+                              * so just return an invalid handle for
+                              * non-masters. */

There's no backward compatibility to handle here, just make it privileged if
it has to be.

Sure thing, sounds good.

drivers/gpu/drm/drm_framebuffer.c int drm_mode_getfb(struct drm_device *dev,

Quoted 10 lines
drivers/gpu/drm/drm_framebuffer.c +10 -0
+                             r->handles[i] = 0;
+                             ret = 0;
+                     }
+             } else {
+                     ret = -ENODEV;
+                     break;
+             }
+     }
+
+     /* If handle creation failed, delete/dereference any that were

made.
*/

Quoted 5 lines
drivers/gpu/drm/drm_framebuffer.c +4 -0
+     if (ret) {
+             for (i = 0; i < 4; ++i) {
+                     if (r->handles[i])
+                             drm_gem_handle_delete(file_priv, r-

handles[i]);

Quoted 8 lines

My initial reaction to this was to reply that not all drivers use GEM, but after some investigation it seems they actually do. If that's really the case,
we could get rid of the .create_handle() operation completely, which should simplify the implementation of both DRM_IOCTL_MODE_GETFB and DRM_IOCTL_MODE_GETFB2.

Deleting the handle is the same in all cases, but creating the handle

isn't consistent across the drivers. I didn't see a clean way to simplify this.

Quoted 53 lines
Quoted 8 lines
drivers/gpu/drm/drm_framebuffer.c +8 -0
+                     r->handles[i] = 0;
+             }
+     }
+
+     drm_framebuffer_unreference(fb);
+
+     return ret;
+}

[snip]

Quoted 2 lines
(quoted diff) +0 -0

b/drivers/gpu/drm/omapdrm/omap_fb.c index 29dc677dd4d3..a982c72a773e

100644

drivers/gpu/drm/omapdrm/omap_fb.c struct omap_framebuffer { · line 98

Quoted 12 lines
drivers/gpu/drm/omapdrm/omap_fb.c +2 -0
@@ -90,12 +90,15 @@ struct omap_framebuffer {
 };
 
 static int omap_framebuffer_create_handle(struct drm_framebuffer *fb,
+             unsigned int format_plane_index,
              struct drm_file *file_priv,
              unsigned int *handle)
 {
      struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb);
+     if (format_plane_index >= 4 || !omap_fb->planes[format_plane_

index])

The first check shouldn't be needed, the core should never call this operation
with an index >= 4.

I'll remove the check then.

Quoted 5 lines
drivers/gpu/drm/omapdrm/omap_fb.c +2 -1
+             return -ENOENT;
      return drm_gem_handle_create(file_priv,
-                     omap_fb->planes[0].bo, handle);
+                     omap_fb->planes[format_plane_index].bo, handle);
 }

[snip]

Quoted 10 lines
include/uapi/drm/drm.h +0 -0
index b2c52843bc70..c81c75335cca 100644
@@ -814,6 +814,8 @@ extern "C" {
 #define DRM_IOCTL_MODE_CREATEPROPBLOB        DRM_IOWR(0xBD, struct
 drm_mode_create_blob)
 #define DRM_IOCTL_MODE_DESTROYPROPBLOB        DRM_IOWR(0xBE, struct
 drm_mode_destroy_blob)
 
Quoted 7 lines

include/uapi/drm/drm.h extern "C" { · line 818

Quoted 2 lines
include/uapi/drm/drm.h +2 -0
+#define DRM_IOCTL_MODE_GETFB2  DRM_IOWR(0xC4, struct drm_mode_fb_cmd2)
+

Which tree is this based on ? The last defined ioctl (DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE) is 0xC2 in drm-next and drm-misc-next.

I just did a quick search for "DRM_IOWR 0xC*" and picked the first unused

one, there was a patch in-flight from last month that used 0xC3 (
https://lists.freedesktop.org/archives/amd-gfx/2017-June/010153.html).
Naturally, I'll set this to whatever is appropriate.

Quoted 10 lines
Quoted 3 lines
include/uapi/drm/drm.h +0 -0
 /**

* Device specific ioctls should only be in their respective headers
* The device specific ioctl range is from 0x40 to 0x9f.

--
Regards,

Laurent Pinchart

Thanks!
-j

Signature · 2 lines
Dr. Joe Michael Kniss |  Google ChromeOS |  [email protected]   |
1-801-898-7977 <(801)%20898-7977>

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

A message that is not in the archive (sent off-list or not yet received): CAOvnNvZoHv8prg2R57cgGx5w7h69=X3hQGrpP5iXaLujhOfzYA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#5 lore raw

Re: [PATCH] Add drm ioctl DRM_IOCTL_MODE_GETFB2 & associated helpers.

Hi Joe,

Quoted 24 lines · On Tuesday 01 Aug 2017 10:24:25 Joe Kniss wrote:
Quoted 7 lines · Laurent Pinchart
Quoted 2 lines · On Monday 31 Jul 2017 11:29:13 Joe Kniss wrote:

New getfb2 functionality uses drm_mode_fb_cmd2 struct to be symmetric with addfb2.

What's the use case for this ? We haven't needed such an ioctl for so long that it seemed to me that userspace doesn't really need it, but I could be wrong.

Sorry, I failed to reference the original email. Here it is:

<snip>
I am a recent addition to Google's ChromeOS gfx team. I am currently
working on display testing and reporting. An important part of this is
our screen capture tool, which works by querying drm for crtcs, planes, and fbs. Unfortunately, there is only limited information available via drmModeGetFB(), which often wrong information when drmModeAddFB2() was used
to create the fbs. For example, if the pixel format is NV12 or YUV420,
the fb returned knows nothing about the additional buffer planes required
by these formats. Ideally, we would like a function (e.g. drmModeGetFB2)
to return information symmetric with drmModeAddFB2 including the pixel format id, buffer plane information etc.
</snip>

Quoted 8 lines

ChromeOS has needed this functionality from the start, for both testing and error reporting. We got away with guessing the buffer's format (32bit xrgb) until now. We are now enabling overlays and more formats including multi-planar (e.g. NV12). Current getfb() reports neither the pixel format nor planar information. Without this information, going forward, our gfx testing is going to break. It would be great if we had access to higher level buffer structs (like gbm), but we generally don't since they would be created by other apps (chrome browser, android apps, etc...).

How is screen capture implemented ? Do you enumerate the framebuffers being scanned out, dump their contents and compose them manually based on the active plane configuration ? If so, isn't this very race-prone ?

Quoted 45 lines
Quoted 8 lines
Quoted 4 lines

Also modifies *_fb_create_handle() calls to accept a format_plane_index so that handles for each plane can be generated. Previously, many *_fb_create_handle() calls simply defaulted to plane 0 only.

And with this patch the amd/amdgpu, armada, gma500, i915, mediatek, msm, nouveau and radeon drivers still do. Do none of them support multi-planar formats ?

I would imagine that some of these do support multi-planar formats, but they don't appear to have them implemented yet (except perhaps as offsets into a single buffer). I will certainly be looking into this soon, but any changes will come in future patches.

Quoted 31 lines
Quoted 22 lines

---

 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c |  5 +-
 drivers/gpu/drm/armada/armada_fb.c          |  1 +
 drivers/gpu/drm/drm_crtc_internal.h         |  2 +
 drivers/gpu/drm/drm_fb_cma_helper.c         | 11 ++--
 drivers/gpu/drm/drm_framebuffer.c           | 79 +++++++++++++++++++-
 drivers/gpu/drm/drm_ioctl.c                 |  1 +
 drivers/gpu/drm/exynos/exynos_drm_fb.c      |  7 ++-
 drivers/gpu/drm/gma500/framebuffer.c        |  2 +
 drivers/gpu/drm/i915/intel_display.c        |  1 +
 drivers/gpu/drm/mediatek/mtk_drm_fb.c       |  1 +
 drivers/gpu/drm/msm/msm_fb.c                |  5 +-
 drivers/gpu/drm/nouveau/nouveau_display.c   |  1 +
 drivers/gpu/drm/omapdrm/omap_fb.c           |  5 +-
 drivers/gpu/drm/radeon/radeon_display.c     |  5 +-
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  |  6 ++-
 drivers/gpu/drm/tegra/fb.c                  |  9 +++-
 include/drm/drm_framebuffer.h               |  1 +
 include/uapi/drm/drm.h                      |  2 +
 18 files changed, 127 insertions(+), 17 deletions(-)

[snip]

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_framebuffer.c index 28a0108a1ab8..67b3be1bedbc 100644

drivers/gpu/drm/drm_framebuffer.c +0 -0
@@ -24,6 +24,7 @@

[snip]

Quoted 90 lines
Quoted 53 lines
Quoted 53 lines
drivers/gpu/drm/drm_framebuffer.c +43 -0
+/**
+ * drm_mode_getfb2 - get 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(struct drm_device *dev,
+                void *data, struct drm_file *file_priv)
+{
+     struct drm_mode_fb_cmd2 *r = data;
+     struct drm_framebuffer *fb;
+     int ret, i;
+
+     if (!drm_core_check_feature(dev, DRIVER_MODESET))
+             return -EINVAL;
+
+     fb = drm_framebuffer_lookup(dev, r->fb_id);
+     if (!fb)
+             return -ENOENT;
+
+     r->height = fb->height;
+     r->width = fb->width;
+     r->pixel_format = fb->format->format;
+     for (i = 0; i < 4; ++i) {
+             r->pitches[i] = fb->pitches[i];
+             r->offsets[i] = fb->offsets[i];
+             r->modifier[i] = fb->modifier;
+             r->handles[i] = 0;
+     }
+
+     for (i = 0; i < fb->format->num_planes; ++i) {
+             if (fb->funcs->create_handle) {
+                     if (drm_is_current_master(file_priv) ||
+                         capable(CAP_SYS_ADMIN) ||
+                         drm_is_control_client(file_priv)) {
+                             ret = fb->funcs->create_handle(fb, i,

file_priv,
+
&r->handles[i]);

drivers/gpu/drm/drm_framebuffer.c +4 -0
+                             if (ret)
+                                     break;
+                     } else {
+                             /* GET_FB() is an unprivileged ioctl so we

must
+ * not return a buffer-handle to
non-master

Quoted 8 lines

drivers/gpu/drm/drm_framebuffer.c int drm_mode_getfb(struct drm_device *dev, · line 514

Quoted 5 lines
drivers/gpu/drm/drm_framebuffer.c +2 -0
+                              * processes! For backwards-compatibility
+                              * reasons, we cannot make GET_FB()

privileged,

drivers/gpu/drm/drm_framebuffer.c +2 -0
+                              * so just return an invalid handle for
+                              * non-masters. */

There's no backward compatibility to handle here, just make it privileged if it has to be.

Sure thing, sounds good.

Quoted 20 lines

drivers/gpu/drm/drm_framebuffer.c int drm_mode_getfb(struct drm_device *dev,

Quoted 10 lines
drivers/gpu/drm/drm_framebuffer.c +10 -0
+                             r->handles[i] = 0;
+                             ret = 0;
+                     }
+             } else {
+                     ret = -ENODEV;
+                     break;
+             }
+     }
+
+     /* If handle creation failed, delete/dereference any that were

made.
*/

Quoted 5 lines
drivers/gpu/drm/drm_framebuffer.c +4 -0
+     if (ret) {
+             for (i = 0; i < 4; ++i) {
+                     if (r->handles[i])
+                             drm_gem_handle_delete(file_priv, r-

handles[i]);

Quoted 5 lines

My initial reaction to this was to reply that not all drivers use GEM, but after some investigation it seems they actually do. If that's really the case, we could get rid of the .create_handle() operation completely, which should simplify the implementation of both DRM_IOCTL_MODE_GETFB and DRM_IOCTL_MODE_GETFB2.

Quoted 3 lines

Deleting the handle is the same in all cases, but creating the handle isn't consistent across the drivers. I didn't see a clean way to simplify this.

Creating the handle seems to be fairly consistent, except for a very small number of special cases. If we stored the GEM object pointers in the drm_framebuffer structure, the common case would be simplified. Or maybe I've missed something :-)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/drm_framebuffer.c +8 -0
+                     r->handles[i] = 0;
+             }
+     }
+
+     drm_framebuffer_unreference(fb);
+
+     return ret;
+}

[snip]

Quoted 17 lines
Quoted 11 lines
Quoted 11 lines
include/uapi/drm/drm.h +0 -0
index b2c52843bc70..c81c75335cca 100644
@@ -814,6 +814,8 @@ extern "C" {
 
 #define DRM_IOCTL_MODE_CREATEPROPBLOB        DRM_IOWR(0xBD, struct
 drm_mode_create_blob)
 #define DRM_IOCTL_MODE_DESTROYPROPBLOB        DRM_IOWR(0xBE, struct
 drm_mode_destroy_blob)
 
Quoted 5 lines

include/uapi/drm/drm.h extern "C" { · line 818

Quoted 2 lines
include/uapi/drm/drm.h +2 -0
+#define DRM_IOCTL_MODE_GETFB2  DRM_IOWR(0xC4, struct drm_mode_fb_cmd2)
+

Which tree is this based on ? The last defined ioctl (DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE) is 0xC2 in drm-next and drm-misc-next.

Quoted 4 lines

I just did a quick search for "DRM_IOWR 0xC*" and picked the first unused one, there was a patch in-flight from last month that used 0xC3 (
https://lists.freedesktop.org/archives/amd-gfx/2017-June/010153.html).
Naturally, I'll set this to whatever is appropriate.

The best is to base your patch on top of the drm-misc-next branch of the drm- misc tree. Whoever is merged first will win the ioctl number :-) Of course it means rebasing if someone else wins the race, but that shouldn't be a big deal.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

/**

* Device specific ioctls should only be in their respective headers
* The device specific ioctl range is from 0x40 to 0x9f.

Signature · 8 lines
Regards,

Laurent Pinchart

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
author
#6 lore raw

Re: [PATCH] Add drm ioctl DRM_IOCTL_MODE_GETFB2 & associated helpers.

Quoted 42 lines · Laurent Pinchart

Hi Joe,

Quoted 6 lines · On Tuesday 01 Aug 2017 10:24:25 Joe Kniss wrote:
Quoted 5 lines · Laurent Pinchart
Quoted 2 lines · On Monday 31 Jul 2017 11:29:13 Joe Kniss wrote:

New getfb2 functionality uses drm_mode_fb_cmd2 struct to be symmetric with addfb2.

What's the use case for this ? We haven't needed such an ioctl for so

long

Quoted 1 line
Quoted 1 line

that it seemed to me that userspace doesn't really need it, but I

could be

Quoted 8 lines
Quoted 1 line

wrong.

Sorry, I failed to reference the original email. Here it is:

<snip>
I am a recent addition to Google's ChromeOS gfx team. I am currently
working on display testing and reporting. An important part of this is
our screen capture tool, which works by querying drm for crtcs, planes,

and

Quoted 2 lines

fbs. Unfortunately, there is only limited information available via drmModeGetFB(), which often wrong information when drmModeAddFB2() was

used

Quoted 3 lines

to create the fbs. For example, if the pixel format is NV12 or YUV420,
the fb returned knows nothing about the additional buffer planes required
by these formats. Ideally, we would like a function (e.g.

drmModeGetFB2)

Quoted 5 lines

to return information symmetric with drmModeAddFB2 including the pixel format id, buffer plane information etc.
</snip>

ChromeOS has needed this functionality from the start, for both testing

and

Quoted 3 lines

error reporting. We got away with guessing the buffer's format (32bit xrgb) until now. We are now enabling overlays and more formats including multi-planar (e.g. NV12). Current getfb() reports neither the pixel

format

Quoted 1 line

nor planar information. Without this information, going forward, our

gfx

Quoted 2 lines

testing is going to break. It would be great if we had access to higher level buffer structs (like gbm), but we generally don't since they would

Quoted 9 lines

be

Quoted 1 line

created by other apps (chrome browser, android apps, etc...).

How is screen capture implemented ? Do you enumerate the framebuffers being scanned out, dump their contents and compose them manually based on the active
plane configuration ? If so, isn't this very race-prone ?

Yes, this is basically it. We identify the crtc to capture, query the planes associated with it and their properties. For each plane, we get the fb, then a FD that we use to import a GBM buffer, which we map and composite. It's not ideal, but it's the only thing that will work across
all of our platforms and configs. We either wait or sleep for consistent
testing captures. I'm not sure what we can do about the race condition without a much more substantial change... We are currently looking into some platform specific methods, but the current approach won't be going away anytime soon.

Quoted 151 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Also modifies *_fb_create_handle() calls to accept a format_plane_index so that handles for each plane can be generated. Previously, many *_fb_create_handle() calls simply defaulted to plane

0

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

only.

And with this patch the amd/amdgpu, armada, gma500, i915, mediatek,

msm,

Quoted 1 line
Quoted 1 line

nouveau and radeon drivers still do. Do none of them support

multi-planar

Quoted 5 lines
Quoted 1 line

formats ?

I would imagine that some of these do support multi-planar formats, but they don't appear to have them implemented yet (except perhaps as offsets into a single buffer). I will certainly be looking into this soon, but

any

Quoted 10 lines

changes will come in future patches.

Quoted 8 lines
Quoted 8 lines

---

 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c |  5 +-
 drivers/gpu/drm/armada/armada_fb.c          |  1 +
 drivers/gpu/drm/drm_crtc_internal.h         |  2 +
 drivers/gpu/drm/drm_fb_cma_helper.c         | 11 ++--
 drivers/gpu/drm/drm_framebuffer.c           | 79

+++++++++++++++++++-

Quoted 23 lines
Quoted 23 lines
Quoted 14 lines
 drivers/gpu/drm/drm_ioctl.c                 |  1 +
 drivers/gpu/drm/exynos/exynos_drm_fb.c      |  7 ++-
 drivers/gpu/drm/gma500/framebuffer.c        |  2 +
 drivers/gpu/drm/i915/intel_display.c        |  1 +
 drivers/gpu/drm/mediatek/mtk_drm_fb.c       |  1 +
 drivers/gpu/drm/msm/msm_fb.c                |  5 +-
 drivers/gpu/drm/nouveau/nouveau_display.c   |  1 +
 drivers/gpu/drm/omapdrm/omap_fb.c           |  5 +-
 drivers/gpu/drm/radeon/radeon_display.c     |  5 +-
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  |  6 ++-
 drivers/gpu/drm/tegra/fb.c                  |  9 +++-
 include/drm/drm_framebuffer.h               |  1 +
 include/uapi/drm/drm.h                      |  2 +
 18 files changed, 127 insertions(+), 17 deletions(-)

[snip]

Quoted 6 lines
(quoted diff) +0 -0

b/drivers/gpu/drm/drm_framebuffer.c index 28a0108a1ab8..67b3be1bedbc 100644

drivers/gpu/drm/drm_framebuffer.c +0 -0
@@ -24,6 +24,7 @@

[snip]

Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
drivers/gpu/drm/drm_framebuffer.c +42 -0
+/**
+ * drm_mode_getfb2 - get 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(struct drm_device *dev,
+                void *data, struct drm_file *file_priv)
+{
+     struct drm_mode_fb_cmd2 *r = data;
+     struct drm_framebuffer *fb;
+     int ret, i;
+
+     if (!drm_core_check_feature(dev, DRIVER_MODESET))
+             return -EINVAL;
+
+     fb = drm_framebuffer_lookup(dev, r->fb_id);
+     if (!fb)
+             return -ENOENT;
+
+     r->height = fb->height;
+     r->width = fb->width;
+     r->pixel_format = fb->format->format;
+     for (i = 0; i < 4; ++i) {
+             r->pitches[i] = fb->pitches[i];
+             r->offsets[i] = fb->offsets[i];
+             r->modifier[i] = fb->modifier;
+             r->handles[i] = 0;
+     }
+
+     for (i = 0; i < fb->format->num_planes; ++i) {
+             if (fb->funcs->create_handle) {
+                     if (drm_is_current_master(file_priv) ||
+                         capable(CAP_SYS_ADMIN) ||
+                         drm_is_control_client(file_priv)) {
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/drm_framebuffer.c int drm_mode_getfb(struct drm_device *dev,

Quoted 8 lines

+ ret = fb->funcs->create_handle(fb, i,
file_priv,
+
&r->handles[i]);

drivers/gpu/drm/drm_framebuffer.c +4 -0
+                             if (ret)
+                                     break;
+                     } else {
+                             /* GET_FB() is an unprivileged ioctl so

we

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

must
+ * not return a buffer-handle to
non-master
+ * processes! For

backwards-compatibility

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/drm_framebuffer.c int drm_mode_getfb(struct drm_device *dev, · line 514

Quoted 4 lines

+ * reasons, we cannot make GET_FB()
privileged,

drivers/gpu/drm/drm_framebuffer.c +2 -0
+                              * so just return an invalid handle for
+                              * non-masters. */

There's no backward compatibility to handle here, just make it

privileged

Quoted 25 lines
Quoted 1 line

if it has to be.

Sure thing, sounds good.

Quoted 21 lines

drivers/gpu/drm/drm_framebuffer.c int drm_mode_getfb(struct drm_device *dev,

Quoted 10 lines
drivers/gpu/drm/drm_framebuffer.c +10 -0
+                             r->handles[i] = 0;
+                             ret = 0;
+                     }
+             } else {
+                     ret = -ENODEV;
+                     break;
+             }
+     }
+
+     /* If handle creation failed, delete/dereference any that were

made.
*/

Quoted 5 lines
drivers/gpu/drm/drm_framebuffer.c +4 -0
+     if (ret) {
+             for (i = 0; i < 4; ++i) {
+                     if (r->handles[i])
+                             drm_gem_handle_delete(file_priv, r-

handles[i]);

My initial reaction to this was to reply that not all drivers use GEM,

but

Quoted 1 line
Quoted 1 line

after some investigation it seems they actually do. If that's really

the

Quoted 1 line
Quoted 1 line

case, we could get rid of the .create_handle() operation completely,

which

Quoted 5 lines
Quoted 2 lines

should simplify the implementation of both DRM_IOCTL_MODE_GETFB and DRM_IOCTL_MODE_GETFB2.

Deleting the handle is the same in all cases, but creating the handle isn't consistent across the drivers. I didn't see a clean way to

Quoted 10 lines

simplify

Quoted 1 line

this.

Creating the handle seems to be fairly consistent, except for a very small number of special cases. If we stored the GEM object pointers in the drm_framebuffer structure, the common case would be simplified. Or maybe I've
missed something :-)

I am sure this would be fine, I'd be happy to get rid of it. I'll put together a separate patch for this.

Quoted 35 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/drm_framebuffer.c +8 -0
+                     r->handles[i] = 0;
+             }
+     }
+
+     drm_framebuffer_unreference(fb);
+
+     return ret;
+}

[snip]

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/uapi/drm/drm.h +0 -0
index b2c52843bc70..c81c75335cca 100644
@@ -814,6 +814,8 @@ extern "C" {
 
Quoted 6 lines
Quoted 6 lines

include/uapi/drm/drm.h extern "C" { · line 820

Quoted 6 lines
include/uapi/drm/drm.h +1 -0
 #define DRM_IOCTL_MODE_CREATEPROPBLOB        DRM_IOWR(0xBD, struct
 drm_mode_create_blob)
 #define DRM_IOCTL_MODE_DESTROYPROPBLOB        DRM_IOWR(0xBE, struct
 drm_mode_destroy_blob)
 
+#define DRM_IOCTL_MODE_GETFB2  DRM_IOWR(0xC4, struct

drm_mode_fb_cmd2)

Quoted 4 lines
Quoted 4 lines

include/uapi/drm/drm.h extern "C" { · line 821

Quoted 1 line
include/uapi/drm/drm.h +1 -0
+

Which tree is this based on ? The last defined ioctl (DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE) is 0xC2 in drm-next and

drm-misc-next.

Quoted 5 lines

I just did a quick search for "DRM_IOWR 0xC*" and picked the first unused one, there was a patch in-flight from last month that used 0xC3 (
https://lists.freedesktop.org/archives/amd-gfx/2017-June/010153.html).
Naturally, I'll set this to whatever is appropriate.

Quoted 8 lines

The best is to base your patch on top of the drm-misc-next branch of the drm-
misc tree. Whoever is merged first will win the ioctl number :-) Of course it
means rebasing if someone else wins the race, but that shouldn't be a big deal.

Will do.

Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

/**

* Device specific ioctls should only be in their respective headers
* The device specific ioctl range is from 0x40 to 0x9f.

--
Regards,

Laurent Pinchart

I'll respond with an updated patch ASAP.

Signature · 2 lines
Dr. Joe Michael Kniss |  Google ChromeOS |  [email protected]   |
1-801-898-7977 <(801)%20898-7977>

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx