All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Sam Ravnborg <sam@ravnborg.org>, Dave Airlie <airlied@redhat.com>,
	chen@aspeedtech.com, Gerd Hoffmann <kraxel@redhat.com>,
	dri-devel <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 8/9] drm/ast: Add cursor plane
Date: Wed, 6 Nov 2019 10:05:10 +0100	[thread overview]
Message-ID: <CAKMK7uE6D+kdTg0UZ109QNo2Xhts+EyVz18dDtpjny8x1qUSgA@mail.gmail.com> (raw)
In-Reply-To: <0cf6145b-c966-a3a2-f956-5a5ab6cd375f@suse.de>

On Wed, Nov 6, 2019 at 9:31 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>
> Hi
>
> Am 05.11.19 um 10:55 schrieb Daniel Vetter:
> > On Mon, Oct 28, 2019 at 04:49:27PM +0100, Thomas Zimmermann wrote:
> >> The cursor plane uses an internal format of ARGB4444. To userspace, we
> >> announce ARGB8888 and do the transformation internally.
> >>
> >> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> >
> > Hm, might be fun to also expose the ARGB4444 directly. Not that anyone
> > will actually use it :-/
>
> Is that a serious proposal? I thought about ARGB4444 and quickly
> dismissed it because no one will ever support it anyway.

For cursor maybe not, but in other cases where we added the
RGB8888->native format hack because userspace, we did make sure that
the driver exposes the native formats too. Up to you really.
-Daniel

>
> Best regards
> Thomas
>
> > -Daniel
> >
> >> ---
> >>  drivers/gpu/drm/ast/ast_drv.h  |   1 +
> >>  drivers/gpu/drm/ast/ast_mode.c | 161 ++++++++++++++++++++++++++++++++-
> >>  2 files changed, 161 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
> >> index 13560622f22a..49557a73390f 100644
> >> --- a/drivers/gpu/drm/ast/ast_drv.h
> >> +++ b/drivers/gpu/drm/ast/ast_drv.h
> >> @@ -122,6 +122,7 @@ struct ast_private {
> >>      } cursor;
> >>
> >>      struct drm_plane primary_plane;
> >> +    struct drm_plane cursor_plane;
> >>
> >>      bool support_wide_screen;
> >>      enum {
> >> diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
> >> index 7667f4502eb9..f5f73200e8e4 100644
> >> --- a/drivers/gpu/drm/ast/ast_mode.c
> >> +++ b/drivers/gpu/drm/ast/ast_mode.c
> >> @@ -54,6 +54,16 @@ static int ast_cursor_move(struct drm_crtc *crtc,
> >>                         int x, int y);
> >>
> >>
> >> +static u32 copy_cursor_image(u8 *src, u8 *dst, int width, int height);
> >> +static int ast_cursor_update(void *dst, void *src, unsigned int width,
> >> +                         unsigned int height);
> >> +static void ast_cursor_set_base(struct ast_private *ast, u64 address);
> >> +static int ast_show_cursor(struct drm_crtc *crtc, void *src,
> >> +                       unsigned int width, unsigned int height);
> >> +static void ast_hide_cursor(struct drm_crtc *crtc);
> >> +static int ast_cursor_move(struct drm_crtc *crtc,
> >> +                       int x, int y);
> >> +
> >>  static inline void ast_load_palette_index(struct ast_private *ast,
> >>                                   u8 index, u8 red, u8 green,
> >>                                   u8 blue)
> >> @@ -594,6 +604,139 @@ static const struct drm_plane_funcs ast_primary_plane_funcs = {
> >>      .format_mod_supported = NULL,
> >>  };
> >>
> >> +/*
> >> + * Cursor plane
> >> + */
> >> +
> >> +static int
> >> +ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane,
> >> +                               struct drm_plane_state *new_state)
> >> +{
> >> +    struct drm_framebuffer *fb = new_state->fb;
> >> +    struct drm_crtc *crtc = new_state->crtc;
> >> +    struct drm_gem_vram_object *gbo;
> >> +    struct ast_private *ast;
> >> +    int ret;
> >> +    void *src, *dst;
> >> +
> >> +    if (!crtc || !fb)
> >> +            return 0;
> >> +
> >> +    if (fb->width > AST_MAX_HWC_WIDTH || fb->height > AST_MAX_HWC_HEIGHT)
> >> +            return -EINVAL;
> >> +
> >> +    ast = crtc->dev->dev_private;
> >> +
> >> +    gbo = drm_gem_vram_of_gem(fb->obj[0]);
> >> +    src = drm_gem_vram_vmap(gbo);
> >> +    if (IS_ERR(src)) {
> >> +            ret = PTR_ERR(src);
> >> +            goto err_drm_gem_vram_unpin;
> >> +    }
> >> +
> >> +    dst = drm_gem_vram_vmap(ast->cursor.gbo[ast->cursor.next_index]);
> >> +    if (IS_ERR(dst)) {
> >> +            ret = PTR_ERR(dst);
> >> +            goto err_drm_gem_vram_vunmap_src;
> >> +    }
> >> +
> >> +    ret = ast_cursor_update(dst, src, fb->width, fb->height);
> >> +    if (ret)
> >> +            goto err_drm_gem_vram_vunmap_dst;
> >> +
> >> +    /* Always unmap buffers here. Destination buffers are
> >> +     * perma-pinned while the driver is active. We're only
> >> +     * changing ref-counters here.
> >> +     */
> >> +    drm_gem_vram_vunmap(ast->cursor.gbo[ast->cursor.next_index], dst);
> >> +    drm_gem_vram_vunmap(gbo, src);
> >> +
> >> +    return 0;
> >> +
> >> +err_drm_gem_vram_vunmap_dst:
> >> +    drm_gem_vram_vunmap(ast->cursor.gbo[ast->cursor.next_index], dst);
> >> +err_drm_gem_vram_vunmap_src:
> >> +    drm_gem_vram_vunmap(gbo, src);
> >> +err_drm_gem_vram_unpin:
> >> +    drm_gem_vram_unpin(gbo);
> >> +    return ret;
> >> +}
> >> +
> >> +static int ast_cursor_plane_helper_atomic_check(struct drm_plane *plane,
> >> +                                            struct drm_plane_state *state)
> >> +{
> >> +    return 0;
> >> +}
> >> +
> >> +static void
> >> +ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
> >> +                                  struct drm_plane_state *old_state)
> >> +{
> >> +    struct drm_plane_state *state = plane->state;
> >> +    struct drm_crtc *crtc = state->crtc;
> >> +    struct drm_framebuffer *fb = state->fb;
> >> +    struct ast_private *ast = plane->dev->dev_private;
> >> +    struct ast_crtc *ast_crtc = to_ast_crtc(crtc);
> >> +    struct drm_gem_vram_object *gbo;
> >> +    s64 off;
> >> +    u8 jreg;
> >> +
> >> +    ast_crtc->offset_x = AST_MAX_HWC_WIDTH - fb->width;
> >> +    ast_crtc->offset_y = AST_MAX_HWC_WIDTH - fb->height;
> >> +
> >> +    if (state->fb != old_state->fb) {
> >> +            /* A new cursor image was installed. */
> >> +            gbo = ast->cursor.gbo[ast->cursor.next_index];
> >> +            off = drm_gem_vram_offset(gbo);
> >> +            if (WARN_ON_ONCE(off < 0))
> >> +                    return; /* Bug: we didn't pin cursor HW BO to VRAM. */
> >> +            ast_cursor_set_base(ast, off);
> >> +
> >> +            ++ast->cursor.next_index;
> >> +            ast->cursor.next_index %= ARRAY_SIZE(ast->cursor.gbo);
> >> +    }
> >> +
> >> +    ast_cursor_move(crtc, state->crtc_x, state->crtc_y);
> >> +
> >> +    jreg = 0x2;
> >> +    /* enable ARGB cursor */
> >> +    jreg |= 1;
> >> +    ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, 0xfc, jreg);
> >> +}
> >> +
> >> +static void
> >> +ast_cursor_plane_helper_atomic_disable(struct drm_plane *plane,
> >> +                                   struct drm_plane_state *old_state)
> >> +{
> >> +    struct ast_private *ast = plane->dev->dev_private;
> >> +
> >> +    ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, 0xfc, 0x00);
> >> +}
> >> +
> >> +static const struct drm_plane_helper_funcs ast_cursor_plane_helper_funcs = {
> >> +    .prepare_fb = ast_cursor_plane_helper_prepare_fb,
> >> +    .cleanup_fb = NULL, /* not required for cursor plane */
> >> +    .atomic_check = ast_cursor_plane_helper_atomic_check,
> >> +    .atomic_update = ast_cursor_plane_helper_atomic_update,
> >> +    .atomic_disable = ast_cursor_plane_helper_atomic_disable,
> >> +};
> >> +
> >> +static const struct drm_plane_funcs ast_cursor_plane_funcs = {
> >> +    .update_plane = drm_atomic_helper_update_plane,
> >> +    .disable_plane = drm_atomic_helper_disable_plane,
> >> +    .destroy = drm_plane_cleanup,
> >> +    .reset = drm_atomic_helper_plane_reset,
> >> +    .set_property = NULL,
> >> +    .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
> >> +    .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
> >> +    .atomic_set_property = NULL,
> >> +    .atomic_get_property = NULL,
> >> +    .late_register = NULL,
> >> +    .early_unregister = NULL,
> >> +    .atomic_print_state = NULL,
> >> +    .format_mod_supported = NULL,
> >> +};
> >> +
> >>  /*
> >>   * CRTC
> >>   */
> >> @@ -883,7 +1026,8 @@ static int ast_crtc_init(struct drm_device *dev)
> >>              return -ENOMEM;
> >>
> >>      ret = drm_crtc_init_with_planes(dev, &crtc->base, &ast->primary_plane,
> >> -                                    NULL, &ast_crtc_funcs, NULL);
> >> +                                    &ast->cursor_plane, &ast_crtc_funcs,
> >> +                                    NULL);
> >>      if (ret)
> >>              goto err_kfree;
> >>
> >> @@ -1153,6 +1297,9 @@ int ast_mode_init(struct drm_device *dev)
> >>              DRM_FORMAT_RGB565,
> >>              DRM_FORMAT_C8,
> >>      };
> >> +    static const uint32_t cursor_plane_formats[] = {
> >> +            DRM_FORMAT_ARGB8888,
> >> +    };
> >>
> >>      struct ast_private *ast = dev->dev_private;
> >>      int ret;
> >> @@ -1170,6 +1317,18 @@ int ast_mode_init(struct drm_device *dev)
> >>      drm_plane_helper_add(&ast->primary_plane,
> >>                           &ast_primary_plane_helper_funcs);
> >>
> >> +    ret = drm_universal_plane_init(dev, &ast->cursor_plane, 0x01,
> >> +                                   &ast_cursor_plane_funcs,
> >> +                                   cursor_plane_formats,
> >> +                                   ARRAY_SIZE(cursor_plane_formats),
> >> +                                   NULL, DRM_PLANE_TYPE_CURSOR, NULL);
> >> +    if (ret) {
> >> +            DRM_ERROR("drm_universal_plane_failed(): %d\n", ret);
> >> +            return ret;
> >> +    }
> >> +    drm_plane_helper_add(&ast->cursor_plane,
> >> +                         &ast_cursor_plane_helper_funcs);
> >> +
> >>      ast_cursor_init(dev);
> >>      ast_crtc_init(dev);
> >>      ast_encoder_init(dev);
> >> --
> >> 2.23.0
> >>
> >
>
> --
> Thomas Zimmermann
> Graphics Driver Developer
> SUSE Software Solutions Germany GmbH
> Maxfeldstr. 5, 90409 Nürnberg, Germany
> (HRB 36809, AG Nürnberg)
> Geschäftsführer: Felix Imendörffer
>


-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2019-11-06  9:05 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-28 15:49 [PATCH 0/9] drm/ast: Convert to atomic modesetting Thomas Zimmermann
2019-10-28 15:49 ` [PATCH 1/9] drm/ast: Remove last traces of struct ast_gem_object Thomas Zimmermann
2019-11-05  9:42   ` Gerd Hoffmann
2019-10-28 15:49 ` [PATCH 2/9] drm/ast: Check video-mode requirements against VRAM size Thomas Zimmermann
2019-11-05  9:42   ` Gerd Hoffmann
2019-10-28 15:49 ` [PATCH 3/9] drm/ast: Don't clear base address and offset with default values Thomas Zimmermann
2019-11-05  9:44   ` Gerd Hoffmann
2019-10-28 15:49 ` [PATCH 4/9] drm/ast: Split ast_set_ext_reg() into color and threshold function Thomas Zimmermann
2019-11-05  9:45   ` Gerd Hoffmann
2019-10-28 15:49 ` [PATCH 5/9] drm/ast: Split ast_set_vbios_mode_info() Thomas Zimmermann
2019-11-05  9:47   ` Gerd Hoffmann
2019-10-28 15:49 ` [PATCH 6/9] drm/ast: Add primary plane Thomas Zimmermann
2019-11-05  9:51   ` Gerd Hoffmann
2019-11-05  9:54     ` Daniel Vetter
2019-11-06  8:24     ` Thomas Zimmermann
2019-10-28 15:49 ` [PATCH 7/9] drm/ast: Add CRTC helpers for atomic modesetting Thomas Zimmermann
2019-11-05  9:51   ` Gerd Hoffmann
2019-10-28 15:49 ` [PATCH 8/9] drm/ast: Add cursor plane Thomas Zimmermann
2019-11-05  9:52   ` Gerd Hoffmann
2019-11-05  9:55   ` Daniel Vetter
2019-11-06  8:31     ` Thomas Zimmermann
2019-11-06  9:05       ` Daniel Vetter [this message]
2019-11-06  9:46         ` Thomas Zimmermann
2019-10-28 15:49 ` [PATCH 9/9] drm/ast: Enable atomic modesetting Thomas Zimmermann
2019-11-05  9:57   ` Gerd Hoffmann
2019-11-05 10:31     ` Daniel Vetter
2019-11-06  8:28       ` Thomas Zimmermann
2019-11-06 13:36     ` Thomas Zimmermann
2019-11-07  6:55       ` Gerd Hoffmann
2019-11-07  7:32         ` Thomas Zimmermann
2019-10-28 16:00 ` [PATCH 0/9] drm/ast: Convert to " Thomas Zimmermann
2019-10-28 16:00   ` Thomas Zimmermann

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=CAKMK7uE6D+kdTg0UZ109QNo2Xhts+EyVz18dDtpjny8x1qUSgA@mail.gmail.com \
    --to=daniel@ffwll.ch \
    --cc=airlied@redhat.com \
    --cc=chen@aspeedtech.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kraxel@redhat.com \
    --cc=sam@ravnborg.org \
    --cc=tzimmermann@suse.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.