<div dir="ltr">Thanks for the quick review! <br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 1, 2017 at 5:09 AM, Laurent Pinchart <span dir="ltr"><<a href="mailto:laurent.pinchart@ideasonboard.com" target="_blank">laurent.pinchart@<wbr>ideasonboard.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Joe,<br>
<br>
Thank you for the patch.<br>
<span><br>
On Monday 31 Jul 2017 11:29:13 Joe Kniss wrote:<br>
> New getfb2 functionality uses drm_mode_fb_cmd2 struct to be symmetric<br>
> with addfb2.<br>
<br>
</span>What's the use case for this ? We haven't needed such an ioctl for so long<br>
that it seemed to me that userspace doesn't really need it, but I could be<br>
wrong.<br>
<span><br></span></blockquote><div>Sorry, I failed to reference the original email. Here it is: </div><div><snip></div><div><span style="font-size:12.8px"> 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. </span></div><div><span style="font-size:12.8px"></snip></span></div><div>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...).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>
> Also modifies *_fb_create_handle() calls to accept a<br>
> format_plane_index so that handles for each plane can be generated.<br>
> Previously, many *_fb_create_handle() calls simply defaulted to plane 0<br>
> only.<br>
<br>
</span>And with this patch the amd/amdgpu, armada, gma500, i915, mediatek, msm,<br>
nouveau and radeon drivers still do. Do none of them support multi-planar<br>
formats ?<br>
<span><br></span></blockquote><div>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. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>
> Signed-off-by: Joe Kniss <<a href="mailto:djmk@google.com" target="_blank">djmk@google.com</a>><br>
> ---<br>
> drivers/gpu/drm/amd/amdgpu/amd<wbr>gpu_display.c | 5 +-<br>
> drivers/gpu/drm/armada/armada_<wbr>fb.c | 1 +<br>
> drivers/gpu/drm/drm_crtc_inter<wbr>nal.h | 2 +<br>
> drivers/gpu/drm/drm_fb_cma_hel<wbr>per.c | 11 ++--<br>
</span>> drivers/gpu/drm/drm_framebuffe<wbr>r.c | 79 +++++++++++++++++++++++++-<br>
<span>> drivers/gpu/drm/drm_ioctl.c | 1 +<br>
> drivers/gpu/drm/exynos/exynos_<wbr>drm_fb.c | 7 ++-<br>
> drivers/gpu/drm/gma500/framebu<wbr>ffer.c | 2 +<br>
> drivers/gpu/drm/i915/intel_dis<wbr>play.c | 1 +<br>
> drivers/gpu/drm/mediatek/mtk_d<wbr>rm_fb.c | 1 +<br>
> drivers/gpu/drm/msm/msm_fb.c | 5 +-<br>
> drivers/gpu/drm/nouveau/nouvea<wbr>u_display.c | 1 +<br>
> drivers/gpu/drm/omapdrm/omap_f<wbr>b.c | 5 +-<br>
> drivers/gpu/drm/radeon/radeon_<wbr>display.c | 5 +-<br>
> drivers/gpu/drm/rockchip/rockc<wbr>hip_drm_fb.c | 6 ++-<br>
> drivers/gpu/drm/tegra/fb.c | 9 +++-<br>
> include/drm/drm_framebuffer.h | 1 +<br>
> include/uapi/drm/drm.h | 2 +<br>
> 18 files changed, 127 insertions(+), 17 deletions(-)<br>
<br>
</span>[snip]<br>
<span><br>
> diff --git a/drivers/gpu/drm/drm_framebuf<wbr>fer.c<br>
> b/drivers/gpu/drm/drm_framebuf<wbr>fer.c index 28a0108a1ab8..67b3be1bedbc 100644<br>
> --- a/drivers/gpu/drm/drm_framebuf<wbr>fer.c<br>
> +++ b/drivers/gpu/drm/drm_framebuf<wbr>fer.c<br>
> @@ -24,6 +24,7 @@<br>
> #include <drm/drmP.h><br>
> #include <drm/drm_auth.h><br>
> #include <drm/drm_framebuffer.h><br>
> +#include <drm/drm_gem.h><br>
><br>
> #include "drm_crtc_internal.h"<br>
<br>
</span>[snip]<br>
<div><div class="gmail-m_-3711990965528987190h5"><br>
> +/**<br>
> + * drm_mode_getfb2 - get FB info<br>
> + * @dev: drm device for the ioctl<br>
> + * @data: data pointer for the ioctl<br>
> + * @file_priv: drm file for the ioctl call<br>
> + *<br>
> + * Lookup the FB given its ID and return info about it.<br>
> + *<br>
> + * Called by the user via ioctl.<br>
> + *<br>
> + * Returns:<br>
> + * Zero on success, negative errno on failure.<br>
> + */<br>
> +int drm_mode_getfb2(struct drm_device *dev,<br>
> + void *data, struct drm_file *file_priv)<br>
> +{<br>
> + struct drm_mode_fb_cmd2 *r = data;<br>
> + struct drm_framebuffer *fb;<br>
> + int ret, i;<br>
> +<br>
> + if (!drm_core_check_feature(dev, DRIVER_MODESET))<br>
> + return -EINVAL;<br>
> +<br>
> + fb = drm_framebuffer_lookup(dev, r->fb_id);<br>
> + if (!fb)<br>
> + return -ENOENT;<br>
> +<br>
> + r->height = fb->height;<br>
> + r->width = fb->width;<br>
> + r->pixel_format = fb->format->format;<br>
> + for (i = 0; i < 4; ++i) {<br>
> + r->pitches[i] = fb->pitches[i];<br>
> + r->offsets[i] = fb->offsets[i];<br>
> + r->modifier[i] = fb->modifier;<br>
> + r->handles[i] = 0;<br>
> + }<br>
> +<br>
> + for (i = 0; i < fb->format->num_planes; ++i) {<br>
> + if (fb->funcs->create_handle) {<br>
> + if (drm_is_current_master(file_pr<wbr>iv) ||<br>
> + capable(CAP_SYS_ADMIN) ||<br>
> + drm_is_control_client(file_pr<wbr>iv)) {<br>
> + ret = fb->funcs->create_handle(fb, i,<br>
> file_priv,<br>
> +<br>
> &r->handles[i]);<br>
> + if (ret)<br>
> + break;<br>
> + } else {<br>
> + /* GET_FB() is an unprivileged ioctl so we<br>
> must<br>
> + * not return a buffer-handle to non-master<br>
> + * processes! For backwards-compatibility<br>
> + * reasons, we cannot make GET_FB()<br>
> privileged,<br>
> + * so just return an invalid handle for<br>
> + * non-masters. */<br>
<br>
</div></div>There's no backward compatibility to handle here, just make it privileged if<br>
it has to be.<br>
<span><br></span></blockquote><div>Sure thing, sounds good.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>
> + r->handles[i] = 0;<br>
> + ret = 0;<br>
> + }<br>
> + } else {<br>
> + ret = -ENODEV;<br>
> + break;<br>
> + }<br>
> + }<br>
> +<br>
> + /* If handle creation failed, delete/dereference any that were made.<br>
*/<br>
> + if (ret) {<br>
> + for (i = 0; i < 4; ++i) {<br>
> + if (r->handles[i])<br>
> + drm_gem_handle_delete(file_pr<wbr>iv, r-<br>
>handles[i]);<br>
<br>
</span>My initial reaction to this was to reply that not all drivers use GEM, but<br>
after some investigation it seems they actually do. If that's really the case,<br>
we could get rid of the .create_handle() operation completely, which should<br>
simplify the implementation of both DRM_IOCTL_MODE_GETFB and<br>
DRM_IOCTL_MODE_GETFB2.<br>
<span><br></span></blockquote><div>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.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>
> + r->handles[i] = 0;<br>
> + }<br>
> + }<br>
> +<br>
> + drm_framebuffer_unreference(f<wbr>b);<br>
> +<br>
> + return ret;<br>
> +}<br>
<br>
</span>[snip]<br>
<span><br>
> diff --git a/drivers/gpu/drm/omapdrm/omap<wbr>_fb.c<br>
> b/drivers/gpu/drm/omapdrm/omap<wbr>_fb.c index 29dc677dd4d3..a982c72a773e 100644<br>
> --- a/drivers/gpu/drm/omapdrm/omap<wbr>_fb.c<br>
> +++ b/drivers/gpu/drm/omapdrm/omap<wbr>_fb.c<br>
> @@ -90,12 +90,15 @@ struct omap_framebuffer {<br>
> };<br>
><br>
> static int omap_framebuffer_create_handle<wbr>(struct drm_framebuffer *fb,<br>
> + unsigned int format_plane_index,<br>
> struct drm_file *file_priv,<br>
> unsigned int *handle)<br>
> {<br>
> struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb);<br>
> + if (format_plane_index >= 4 || !omap_fb->planes[format_plane_<wbr>index])<br>
<br>
</span>The first check shouldn't be needed, the core should never call this operation<br>
with an index >= 4.<br>
<span><br></span></blockquote><div>I'll remove the check then.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>
> + return -ENOENT;<br>
> return drm_gem_handle_create(file_pri<wbr>v,<br>
> - omap_fb->planes[0].bo, handle);<br>
> + omap_fb->planes[format_plane_<wbr>index].bo, handle);<br>
> }<br>
<br>
</span>[snip]<br>
<span><br>
> diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h<br>
> index b2c52843bc70..c81c75335cca 100644<br>
> --- a/include/uapi/drm/drm.h<br>
> +++ b/include/uapi/drm/drm.h<br>
> @@ -814,6 +814,8 @@ extern "C" {<br>
> #define DRM_IOCTL_MODE_CREATEPROPBLOB DRM_IOWR(0xBD, struct<br>
> drm_mode_create_blob)<br>
> #define DRM_IOCTL_MODE_<wbr>DESTROYPROPBLOB DRM_IOWR(0xBE, struct<br>
> drm_mode_destroy_blob)<br>
><br>
> +#define DRM_IOCTL_MODE_GETFB2 DRM_IOWR(0xC4, struct drm_mode_fb_cmd2)<br>
> +<br>
<br>
</span>Which tree is this based on ? The last defined ioctl<br>
(DRM_IOCTL_SYNCOBJ_FD_TO_HANDL<wbr>E) is 0xC2 in drm-next and drm-misc-next.<br>
<span><br></span></blockquote><div>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 (<a href="https://lists.freedesktop.org/archives/amd-gfx/2017-June/010153.html">https://lists.freedesktop.org/archives/amd-gfx/2017-June/010153.html</a>). Naturally, I'll set this to whatever is appropriate.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>
> /**<br>
> * Device specific ioctls should only be in their respective headers<br>
> * The device specific ioctl range is from 0x40 to 0x9f.<br>
<br>
--<br>
</span>Regards,<br>
<br>
Laurent Pinchart<br>
<br>
</blockquote></div><div class="gmail_extra"><br></div>Thanks! </div><div class="gmail_extra">-j<br><br clear="all"><div><br></div>-- <br><div class="gmail-m_-3711990965528987190gmail_signature"><div dir="ltr"><div><div dir="ltr"><table cellspacing="0" cellpadding="0" style="text-align:center;color:rgb(80,0,80);font-family:"Times New Roman""><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top:2px solid rgb(213,15,37)"><font size="1"><font face="garamond, serif">Dr. Joe Michael Kniss </font>|</font></td><td nowrap style="border-top:2px solid rgb(51,105,232)"><font size="1"> <font face="garamond, serif"><font color="#0b5394">G</font><font color="#cc0000">o</font><font color="#bf9000">o</font><font color="#0b5394">g</font><font color="#38761d">l</font><font color="#cc0000">e</font><font color="#000000"> </font><font color="#444444">ChromeOS</font></font><font color="#000000"> </font>|</font></td><td nowrap style="border-top:2px solid rgb(0,153,57)"><font size="1"><font face="garamond, serif"> <a href="mailto:djmk@google.com" target="_blank">djmk<font color="#1155cc">@google.com</font></a> </font> </font></td><td nowrap style="border-top:2px solid rgb(238,178,17)"><font size="1"><a value="+16504298119" style="color:rgb(17,85,204)">| </a><font face="garamond, serif"><font color="#1155cc"><a href="tel:(801)%20898-7977" value="+18018987977" target="_blank">1-801-898-7977</a></font><br></font></font></td></tr></tbody></table></div></div></div></div>
</div></div>