<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 1, 2017 at 1:46 PM, Laurent Pinchart <span dir="ltr"><<a href="mailto:laurent.pinchart@ideasonboard.com" target="_blank">laurent.pinchart@ideasonboard<wbr>.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Joe,<br>
<br>
On Tuesday 01 Aug 2017 10:24:25 Joe Kniss wrote:<br>
<div><div class="m_-5589228979114224614m_-260341373603592650h5">> On Tue, Aug 1, 2017 at 5:09 AM, Laurent Pinchart wrote:<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>
> > 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>
><br>
> Sorry, I failed to reference the original email. Here it is:<br>
><br>
> <snip><br>
> I am a recent addition to Google's ChromeOS gfx team. I am currently<br>
> working on display testing and reporting. An important part of this is<br>
> our screen capture tool, which works by querying drm for crtcs, planes, and<br>
> fbs. Unfortunately, there is only limited information available via<br>
> drmModeGetFB(), which often wrong information when drmModeAddFB2() was used<br>
> to create the fbs. For example, if the pixel format is NV12 or YUV420,<br>
> the fb returned knows nothing about the additional buffer planes required<br>
> by these formats. Ideally, we would like a function (e.g. drmModeGetFB2)<br>
> to return information symmetric with drmModeAddFB2 including the pixel<br>
> format id, buffer plane information etc.<br>
> </snip><br>
><br>
> ChromeOS has needed this functionality from the start, for both testing and<br>
> error reporting. We got away with guessing the buffer's format (32bit<br>
> xrgb) until now. We are now enabling overlays and more formats including<br>
> multi-planar (e.g. NV12). Current getfb() reports neither the pixel format<br>
> nor planar information. Without this information, going forward, our gfx<br>
> testing is going to break. It would be great if we had access to higher<br>
> level buffer structs (like gbm), but we generally don't since they would be<br>
> created by other apps (chrome browser, android apps, etc...).<br>
<br>
</div></div>How is screen capture implemented ? Do you enumerate the framebuffers being<br>
scanned out, dump their contents and compose them manually based on the active<br>
plane configuration ? If so, isn't this very race-prone ?<br>
<span><br></span></blockquote><div><br></div><div>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. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;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>
> > 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>
><br>
> I would imagine that some of these do support multi-planar formats, but<br>
> they don't appear to have them implemented yet (except perhaps as offsets<br>
> into a single buffer). I will certainly be looking into this soon, but any<br>
> changes will come in future patches.<br>
><br>
> >> Signed-off-by: Joe Kniss <<a href="mailto:djmk@google.com" target="_blank">djmk@google.com</a>><br>
> >> ---<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>
> > [snip]<br>
> ><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<br>
> >> 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>
<br>
</span><div><div class="m_-5589228979114224614m_-260341373603592650h5">[snip]<br>
<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<br>
> >> 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>
> > There's no backward compatibility to handle here, just make it privileged<br>
> > if it has to be.<br>
><br>
> Sure thing, sounds good.<br>
><br>
> > > + 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<br>
> ><br>
> > made.<br>
> > */<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>
> > 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<br>
> > case, we could get rid of the .create_handle() operation completely, which<br>
> > should simplify the implementation of both DRM_IOCTL_MODE_GETFB and<br>
> > DRM_IOCTL_MODE_GETFB2.<br>
><br>
> Deleting the handle is the same in all cases, but creating the handle<br>
> isn't consistent across the drivers. I didn't see a clean way to simplify<br>
> this.<br>
<br>
</div></div>Creating the handle seems to be fairly consistent, except for a very small<br>
number of special cases. If we stored the GEM object pointers in the<br>
drm_framebuffer structure, the common case would be simplified. Or maybe I've<br>
missed something :-)<br>
<span><br></span></blockquote><div><br></div><div>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.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;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>
[snip]<br>
<br>
</span><span>> >> 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>
> >><br>
> >> #define DRM_IOCTL_MODE_CREATEPROPBLOB DRM_IOWR(0xBD, struct<br>
> >> drm_mode_create_blob)<br>
> >> #define DRM_IOCTL_MODE_DESTROYPROPBLOB<wbr> 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>
> > 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>
><br>
> I just did a quick search for "DRM_IOWR 0xC*" and picked the first unused<br>
> one, there was a patch in-flight from last month that used 0xC3 (<br>
> <a href="https://lists.freedesktop.org/archives/amd-gfx/2017-June/010153.html" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>archives/amd-gfx/2017-June/010<wbr>153.html</a>).<br>
> Naturally, I'll set this to whatever is appropriate.<br>
<br>
</span>The best is to base your patch on top of the drm-misc-next branch of the drm-<br>
misc tree. Whoever is merged first will win the ioctl number :-) Of course it<br>
means rebasing if someone else wins the race, but that shouldn't be a big<br>
deal.<br>
<div class="m_-5589228979114224614m_-260341373603592650HOEnZb"><div class="m_-5589228979114224614m_-260341373603592650h5"><br></div></div></blockquote><div><br></div><div>Will do.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_-5589228979114224614m_-260341373603592650HOEnZb"><div class="m_-5589228979114224614m_-260341373603592650h5">
> > > /**<br>
> > ><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>
Regards,<br>
<br>
Laurent Pinchart<br>
<br>
</div></div></blockquote></div><br>I'll respond with an updated patch ASAP.<br clear="all"><div><br></div>-- <br><div class="m_-5589228979114224614m_-260341373603592650gmail_signature" data-smartmail="gmail_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-style:solid;border-top-color:rgb(213,15,37);border-top-width:2px"><font size="1"><font face="garamond, serif">Dr. Joe Michael Kniss </font>|</font></td><td nowrap style="border-top-style:solid;border-top-color:rgb(51,105,232);border-top-width:2px"><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-style:solid;border-top-color:rgb(0,153,57);border-top-width:2px"><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-style:solid;border-top-color:rgb(238,178,17);border-top-width:2px"><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>