From: Daniel Vetter <daniel@ffwll.ch>
To: Peter Rosin <peda@axentia.se>
Cc: linux-kernel@vger.kernel.org,
"Boris Brezillon" <boris.brezillon@free-electrons.com>,
amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
"Philippe Cornu" <philippe.cornu@st.com>,
nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
"Russell King" <linux@armlinux.org.uk>,
"Yannick Fertre" <yannick.fertre@st.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Daniel Vetter" <daniel.vetter@intel.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Dave Airlie" <airlied@redhat.com>,
virtualization@lists.linux-foundation.org,
"Vincent Abriou" <vincent.abriou@st.com>,
"Christian König" <christian.koenig@amd.com>,
"Ben Skeggs" <bskeggs@redhat.com>
Subject: Re: [PATCH v2 03/14] drm/fb-helper: do a generic fb_setcmap helper in terms of crtc .gamma_set
Date: Mon, 26 Jun 2017 11:30:22 +0200 [thread overview]
Message-ID: <20170626093022.wz63vjto2fl7jpff@phenom.ffwll.local> (raw)
In-Reply-To: <fd73b01e-3327-faf1-c3eb-80663b739ff6@axentia.se>
On Thu, Jun 22, 2017 at 12:22:10PM +0200, Peter Rosin wrote:
> This makes the redundant fb helpers .load_lut, .gamma_set and .gamma_get
> totally obsolete.
>
> Signed-off-by: Peter Rosin <peda@axentia.se>
> ---
> drivers/gpu/drm/drm_fb_helper.c | 151 +++++++++++++++++-----------------------
> 1 file changed, 63 insertions(+), 88 deletions(-)
>
> This is an alternative version rebased on top of Daniel's "fbdev helper
> locking rework and deferred setup" series.
>
> And as noted by Daniel, .gamma_set does an atomic commit. Thus, the locks
> needs to be dropped and reacquired for each crtc. So, that is fixed here
> too. Doing it like this with a couple of individual alternative patches
> instead of sending a whole new series since the dependency on Daniel's
> series makes life somewhat difficult...
>
> Cheers,
> peda
>
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index 4aceb59..aa025f1 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -1257,50 +1257,6 @@ void drm_fb_helper_set_suspend_unlocked(struct drm_fb_helper *fb_helper,
> }
> EXPORT_SYMBOL(drm_fb_helper_set_suspend_unlocked);
>
> -static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
> - u16 blue, u16 regno, struct fb_info *info)
> -{
> - struct drm_fb_helper *fb_helper = info->par;
> - struct drm_framebuffer *fb = fb_helper->fb;
> -
> - if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
> - u32 *palette;
> - u32 value;
> - /* place color in psuedopalette */
> - if (regno > 16)
> - return -EINVAL;
> - palette = (u32 *)info->pseudo_palette;
> - red >>= (16 - info->var.red.length);
> - green >>= (16 - info->var.green.length);
> - blue >>= (16 - info->var.blue.length);
> - value = (red << info->var.red.offset) |
> - (green << info->var.green.offset) |
> - (blue << info->var.blue.offset);
> - if (info->var.transp.length > 0) {
> - u32 mask = (1 << info->var.transp.length) - 1;
> -
> - mask <<= info->var.transp.offset;
> - value |= mask;
> - }
> - palette[regno] = value;
> - return 0;
> - }
> -
> - /*
> - * The driver really shouldn't advertise pseudo/directcolor
> - * visuals if it can't deal with the palette.
> - */
> - if (WARN_ON(!fb_helper->funcs->gamma_set ||
> - !fb_helper->funcs->gamma_get))
> - return -EINVAL;
> -
> - WARN_ON(fb->format->cpp[0] != 1);
> -
> - fb_helper->funcs->gamma_set(crtc, red, green, blue, regno);
> -
> - return 0;
> -}
> -
> /**
> * drm_fb_helper_setcmap - implementation for &fb_ops.fb_setcmap
> * @cmap: cmap to set
> @@ -1310,12 +1266,10 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
> {
> struct drm_fb_helper *fb_helper = info->par;
> struct drm_device *dev = fb_helper->dev;
> - const struct drm_crtc_helper_funcs *crtc_funcs;
> - u16 *red, *green, *blue, *transp;
> + struct drm_modeset_acquire_ctx ctx;
> struct drm_crtc *crtc;
> u16 *r, *g, *b;
> - int i, j, rc = 0;
> - int start;
> + int i, ret = 0;
>
> if (oops_in_progress)
> return -EBUSY;
> @@ -1329,61 +1283,82 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
> return -EBUSY;
> }
>
> - drm_modeset_lock_all(dev);
> - for (i = 0; i < fb_helper->crtc_count; i++) {
> - crtc = fb_helper->crtc_info[i].mode_set.crtc;
> - crtc_funcs = crtc->helper_private;
> + drm_modeset_acquire_init(&ctx, 0);
>
> - red = cmap->red;
> - green = cmap->green;
> - blue = cmap->blue;
> - transp = cmap->transp;
> - start = cmap->start;
> + for (i = 0; i < fb_helper->crtc_count; i++) {
> + if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
> + u32 *palette;
> + int j;
>
> - if (info->fix.visual != FB_VISUAL_TRUECOLOR) {
> - if (!crtc->gamma_size) {
> - rc = -EINVAL;
> - goto out;
> + if (cmap->start + cmap->len > 16) {
> + ret = -EINVAL;
> + break;
> }
>
> - if (cmap->start + cmap->len > crtc->gamma_size) {
> - rc = -EINVAL;
> - goto out;
> + palette = (u32 *)info->pseudo_palette;
> + for (j = 0; j < cmap->len; ++j) {
> + u16 red = cmap->red[j];
> + u16 green = cmap->green[j];
> + u16 blue = cmap->blue[j];
> + u32 value;
> +
> + red >>= 16 - info->var.red.length;
> + green >>= 16 - info->var.green.length;
> + blue >>= 16 - info->var.blue.length;
> + value = (red << info->var.red.offset) |
> + (green << info->var.green.offset) |
> + (blue << info->var.blue.offset);
> + if (info->var.transp.length > 0) {
> + u32 mask = (1 << info->var.transp.length) - 1;
> +
> + mask <<= info->var.transp.offset;
> + value |= mask;
> + }
> + palette[cmap->start + j] = value;
> }
> + continue;
> + }
>
> - r = crtc->gamma_store;
> - g = r + crtc->gamma_size;
> - b = g + crtc->gamma_size;
> +retry:
> + ret = drm_modeset_lock_all_ctx(dev, &ctx);
> + if (ret)
> + break;
>
> - memcpy(r + cmap->start, cmap->red,
> - cmap->len * sizeof(u16));
> - memcpy(g + cmap->start, cmap->green,
> - cmap->len * sizeof(u16));
> - memcpy(b + cmap->start, cmap->blue,
> - cmap->len * sizeof(u16));
> + crtc = fb_helper->crtc_info[i].mode_set.crtc;
> + if (!crtc->funcs->gamma_set || !crtc->gamma_size) {
> + ret = -EINVAL;
> + goto drop_locks;
> }
>
> - for (j = 0; j < cmap->len; j++) {
> - u16 hred, hgreen, hblue, htransp = 0xffff;
> + if (cmap->start + cmap->len > crtc->gamma_size) {
> + ret = -EINVAL;
> + goto drop_locks;
> + }
>
> - hred = *red++;
> - hgreen = *green++;
> - hblue = *blue++;
> + r = crtc->gamma_store;
> + g = r + crtc->gamma_size;
> + b = g + crtc->gamma_size;
>
> - if (transp)
> - htransp = *transp++;
> + memcpy(r + cmap->start, cmap->red, cmap->len * sizeof(u16));
> + memcpy(g + cmap->start, cmap->green, cmap->len * sizeof(u16));
> + memcpy(b + cmap->start, cmap->blue, cmap->len * sizeof(u16));
>
> - rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
> - if (rc)
> - goto out;
> + ret = crtc->funcs->gamma_set(crtc, r, g, b,
> + crtc->gamma_size, &ctx);
> + if (ret == -EDEADLK) {
> + drm_modeset_backoff(&ctx);
> + goto retry;
> }
> - if (crtc_funcs->load_lut)
> - crtc_funcs->load_lut(crtc);
> +drop_locks:
> + drm_modeset_drop_locks(&ctx);
This doesn't work, you can't reuse the acquire_ctx (that's the bit where
the locking machinery gets mad at you). Simplest way really is 2 paths,
one legacy (using drm_modeset_lock_all), the other atomic (with the
gamma_set helper logic inlined, but as one global atomic commit).
I guess updating the gamma_store could be done with common code again, on
success only (another reason for atomic, that way you get all or nothing,
makes error handling easier).
-Daniel
> + if (ret)
> + break;
> }
> - out:
> - drm_modeset_unlock_all(dev);
> +
> + drm_modeset_acquire_fini(&ctx);
> mutex_unlock(&fb_helper->lock);
> - return rc;
> +
> + return ret;
> }
> EXPORT_SYMBOL(drm_fb_helper_setcmap);
>
> --
> 2.1.4
>
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
next prev parent reply other threads:[~2017-06-26 9:30 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-22 6:06 [PATCH v2 00/14] improve the fb_setcmap helper Peter Rosin
2017-06-22 6:06 ` [PATCH v2 01/14] drm/fb-helper: keep the .gamma_store updated in drm_fb_helper_setcmap Peter Rosin
2017-06-22 10:17 ` Peter Rosin
2017-06-26 9:27 ` Daniel Vetter
2017-06-22 6:06 ` [PATCH v2 02/14] drm/fb-helper: remove drm_fb_helper_save_lut_atomic Peter Rosin
2017-06-26 9:18 ` Daniel Vetter
2017-06-22 6:06 ` [PATCH v2 03/14] drm/fb-helper: do a generic fb_setcmap helper in terms of crtc .gamma_set Peter Rosin
2017-06-22 10:22 ` Peter Rosin
2017-06-26 9:30 ` Daniel Vetter [this message]
2017-06-26 9:23 ` Daniel Vetter
2017-06-22 6:06 ` [PATCH v2 04/14] drm: amd: remove dead code and pointless local lut storage Peter Rosin
2017-06-22 6:06 ` [PATCH v2 05/14] drm: armada: remove dead empty functions Peter Rosin
2017-06-22 6:06 ` [PATCH v2 06/14] drm: ast: remove dead code and pointless local lut storage Peter Rosin
2017-06-22 6:06 ` [PATCH v2 07/14] drm: cirrus: " Peter Rosin
2017-06-22 6:06 ` [PATCH v2 08/14] drm: gma500: " Peter Rosin
2017-06-22 6:06 ` [PATCH v2 09/14] drm: i915: " Peter Rosin
2017-06-22 6:06 ` [PATCH v2 10/14] drm: mgag200: " Peter Rosin
2017-06-22 6:06 ` [PATCH v2 11/14] drm: nouveau: " Peter Rosin
2017-06-22 6:06 ` [PATCH v2 12/14] drm: radeon: " Peter Rosin
2017-06-22 6:06 ` [PATCH v2 13/14] drm: stm: " Peter Rosin
2017-06-22 11:49 ` Philippe CORNU
2017-06-23 5:29 ` Peter Rosin
2017-06-23 9:35 ` [Intel-gfx] " Daniel Vetter
2017-06-22 6:06 ` [PATCH v2 14/14] drm: remove unused and redundant callbacks Peter Rosin
2017-06-26 9:35 ` [PATCH v2 00/14] improve the fb_setcmap helper Daniel Vetter
2017-06-26 19:13 ` Peter Rosin
2017-06-26 19:50 ` Dave Airlie
2017-06-27 7:19 ` [Nouveau] " Daniel Vetter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170626093022.wz63vjto2fl7jpff@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=airlied@redhat.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=boris.brezillon@free-electrons.com \
--cc=bskeggs@redhat.com \
--cc=christian.koenig@amd.com \
--cc=daniel.vetter@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=kraxel@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=nouveau@lists.freedesktop.org \
--cc=peda@axentia.se \
--cc=philippe.cornu@st.com \
--cc=vincent.abriou@st.com \
--cc=virtualization@lists.linux-foundation.org \
--cc=yannick.fertre@st.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).