drm/ast: Support imported cursor buffers
Subsystems (3)
Thomas Zimmermann
maintainercover drm/ast: Support imported cursor buffers
Support cursor framebuffers with imported GEM objects. Also handle corner cases where imported buffers are not readily available. The common case of native cursor buffers in XRGB8888 format is not affected by these changes.
This series is a follow-up to commit 3dd0be7a301b ("drm/ast: Handle framebuffer from dma-buf"), which implemented such support for primary planes. While unlikely, imported cursor buffers is possible and can be supported by the ast driver easily.
Tested on AST2600 hardware.
Thomas Zimmermann (3):
drm/ast: Move cursor format conversion into helper function drm/ast: Support cursor buffers objects in I/O memory drm/ast: Wrap cursor framebuffer access in
drm_gem_fb_begin/end_cpu_access()
drivers/gpu/drm/ast/ast_cursor.c | 83 ++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 21 deletions(-)
base-commit: 0a21e96e0b6840d2a4e0b45a957679eeddeb4362
Signature · 1 line
2.51.1
Thomas Zimmermann
maintainerPATCH 1/3 drm/ast: Move cursor format conversion into helper function
Move the format conversion of the cursor framebuffer into the new helper ast_cursor_plane_get_argb4444(). It returns a buffer in system memory, which the atomic_update handler copies to video memory.
The returned buffer is either the GEM buffer itself, or a temporary copy within the plane in ARGB4444 format.
As a small change, list supported formats explicitly in the switch statement. Do not assume ARGB8888 input by default. The cursor framebuffer knows its format, so should we.
--- drivers/gpu/drm/ast/ast_cursor.c | 62 ++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 23 deletions(-)
drivers/gpu/drm/ast/ast_cursor.c +39 -23
@@ -181,6 +181,38 @@ static int ast_cursor_plane_helper_atomic_check(struct drm_plane *plane,return 0 ; } +static const u8 *ast_cursor_plane_get_argb4444 (struct ast_cursor_plane *ast_cursor_plane, +struct drm_shadow_plane_state *shadow_plane_state, +const struct drm_rect *clip) +{ +struct drm_plane_state *plane_state = &shadow_plane_state->base; +struct drm_framebuffer *fb = plane_state->fb; +u8 *argb4444 =NULL ; + +switch (fb->format->format) { +case DRM_FORMAT_ARGB4444 : + argb4444 = shadow_plane_state->data[0 ].vaddr; +break ; +case DRM_FORMAT_ARGB8888 : + { +struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { +IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), + }; +unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { +AST_HWC_PITCH , + }; + +drm_fb_argb8888_to_argb4444 (argb4444_dst, argb4444_dst_pitch, + shadow_plane_state->data, fb, clip, + &shadow_plane_state->fmtcnv_state); + argb4444 = argb4444_dst[0 ].vaddr; + } +break ; + } + +return argb4444; +} +static void ast_cursor_plane_helper_atomic_update (struct drm_plane *plane,struct drm_atomic_state *state) {
@@ -205,29 +237,13 @@ static void ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,*/ if (drm_atomic_helper_damage_merged (old_plane_state, plane_state, &damage)) { -u8 *argb4444; - -switch (fb->format->format) { -case DRM_FORMAT_ARGB4444 : - argb4444 = shadow_plane_state->data[0 ].vaddr; -break ; -default : - argb4444 = ast_cursor_plane->argb4444; - { -struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { -IOSYS_MAP_INIT_VADDR (argb4444), - }; -unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { -AST_HWC_PITCH , - }; - -drm_fb_argb8888_to_argb4444 (argb4444_dst, argb4444_dst_pitch, - shadow_plane_state->data, fb, &damage, - &shadow_plane_state->fmtcnv_state); - } -break ; - } -ast_set_cursor_image (ast, argb4444, fb->width, fb->height); +const u8 *argb4444 =ast_cursor_plane_get_argb4444 (ast_cursor_plane, + shadow_plane_state, + &damage); + +if (argb4444) +ast_set_cursor_image (ast, argb4444, fb->width, fb->height); +ast_set_cursor_base (ast, dst_off); }
Signature · 1 line
2.51.1
Thomas Zimmermann
maintainerPATCH 3/3 drm/ast: Wrap cursor framebuffer access in drm_gem_fb_begin/end_cpu_access()
In reply to Thomas ZimmermannCall drm_gem_fb_begin_cpu_access() and drm_gem_fb_end_cpu_access() around cursor image updates. Imported buffers might have to be synchronized for CPU access before they can be used.
Ignore errors from drm_gem_fb_begin_cpu_access(). These errors can often be transitory. The cursor image will be updated on the next frame. Meanwhile display a white square where the cursor would be.
--- drivers/gpu/drm/ast/ast_cursor.c | 74 +++++++++++++++++++------------- 1 file changed, 43 insertions(+), 31 deletions(-)
drivers/gpu/drm/ast/ast_cursor.c +43 -31
@@ -28,6 +28,7 @@#include <drm/drm_damage_helper.h> #include <drm/drm_format_helper.h> #include <drm/drm_gem_atomic_helper.h> +#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_print.h> #include "ast_drv.h"
@@ -189,38 +190,49 @@ static const u8 *ast_cursor_plane_get_argb4444(struct ast_cursor_plane *ast_cursstruct drm_framebuffer *fb = plane_state->fb;u8 *argb4444 =NULL ; -switch (fb->format->format) { -case DRM_FORMAT_ARGB4444 : -if (shadow_plane_state->data[0 ].is_iomem) { -struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { -IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), - }; -unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { -AST_HWC_PITCH , - }; - -drm_fb_memcpy (argb4444_dst, argb4444_dst_pitch, - shadow_plane_state->data, fb, clip); - argb4444 = argb4444_dst[0 ].vaddr; - }else { - argb4444 = shadow_plane_state->data[0 ].vaddr; +if (drm_gem_fb_begin_cpu_access (fb,DMA_FROM_DEVICE ) ==0 ) { +switch (fb->format->format) { +case DRM_FORMAT_ARGB4444 : +if (shadow_plane_state->data[0 ].is_iomem) { +struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { +IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), + }; +unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { +AST_HWC_PITCH , + }; + +drm_fb_memcpy (argb4444_dst, argb4444_dst_pitch, + shadow_plane_state->data, fb, clip); + argb4444 = argb4444_dst[0 ].vaddr; + }else { + argb4444 = shadow_plane_state->data[0 ].vaddr; + } +break ; +case DRM_FORMAT_ARGB8888 : + { +struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { +IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), + }; +unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { +AST_HWC_PITCH , + }; + +drm_fb_argb8888_to_argb4444 (argb4444_dst, argb4444_dst_pitch, + shadow_plane_state->data, fb, clip, + &shadow_plane_state->fmtcnv_state); + argb4444 = argb4444_dst[0 ].vaddr; + } +break ; } -break ; -case DRM_FORMAT_ARGB8888 : - { -struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { -IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), - }; -unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { -AST_HWC_PITCH , - }; - -drm_fb_argb8888_to_argb4444 (argb4444_dst, argb4444_dst_pitch, - shadow_plane_state->data, fb, clip, - &shadow_plane_state->fmtcnv_state); - argb4444 = argb4444_dst[0 ].vaddr; - } -break ; + +drm_gem_fb_end_cpu_access (fb,DMA_FROM_DEVICE ); + }else { +/* +* Fall back to white square if GEM object is not ready. Gives +* the user an indication where the cursor is located. +*/ +memset (ast_cursor_plane->argb4444,0xff ,sizeof (ast_cursor_plane->argb4444)); + argb4444 = ast_cursor_plane->argb4444; }return argb4444;
Signature · 1 line
2.51.1
Thomas Zimmermann
maintainerPATCH 2/3 drm/ast: Support cursor buffers objects in I/O memory
In reply to Thomas ZimmermannCopy the ARGB4444 cursor buffer to system memory if it is located in I/O memory. While this cannot happen with ast's native GEM objects, an imported buffer object might be on the external device's I/O memory.
If the cursor buffer is located in system memory continue to use it directly.
--- drivers/gpu/drm/ast/ast_cursor.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/gpu/drm/ast/ast_cursor.c +14 -1
@@ -191,7 +191,20 @@ static const u8 *ast_cursor_plane_get_argb4444(struct ast_cursor_plane *ast_cursswitch (fb->format->format) {case DRM_FORMAT_ARGB4444 : - argb4444 = shadow_plane_state->data[0 ].vaddr; +if (shadow_plane_state->data[0 ].is_iomem) { +struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { +IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), + }; +unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { +AST_HWC_PITCH , + }; + +drm_fb_memcpy (argb4444_dst, argb4444_dst_pitch, + shadow_plane_state->data, fb, clip); + argb4444 = argb4444_dst[0 ].vaddr; + }else { + argb4444 = shadow_plane_state->data[0 ].vaddr; + }break ;case DRM_FORMAT_ARGB8888 : {
Signature · 1 line
2.51.1
Re: [PATCH 1/3] drm/ast: Move cursor format conversion into helper function
In reply to Thomas ZimmermannQuoted 11 lines · Thomas Zimmermann
Move the format conversion of the cursor framebuffer into the new helper
ast_cursor_plane_get_argb4444(). It returns a buffer in system memory, which theatomic_updatehandler copies to video memory.The returned buffer is either the GEM buffer itself, or a temporary copy within the plane in ARGB4444 format.
As a small change, list supported formats explicitly in the switch statement. Do not assume ARGB8888 input by default. The cursor framebuffer knows its format, so should we.
Thanks, it looks good to me.
Quoted 85 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_cursor.c | 62 ++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 23 deletions(-)drivers/gpu/drm/ast/ast_cursor.c +39
-23@@ -181,6 +181,38 @@ static int ast_cursor_plane_helper_atomic_check(struct drm_plane *plane,return 0 ; } +static const u8 *ast_cursor_plane_get_argb4444 (struct ast_cursor_plane *ast_cursor_plane, +struct drm_shadow_plane_state *shadow_plane_state, +const struct drm_rect *clip) +{ +struct drm_plane_state *plane_state = &shadow_plane_state->base; +struct drm_framebuffer *fb = plane_state->fb; +u8 *argb4444 =NULL ; + +switch (fb->format->format) { +case DRM_FORMAT_ARGB4444 : + argb4444 = shadow_plane_state->data[0 ].vaddr; +break ; +case DRM_FORMAT_ARGB8888 : + { +struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { +IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), + }; +unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { +AST_HWC_PITCH , + }; + +drm_fb_argb8888_to_argb4444 (argb4444_dst, argb4444_dst_pitch, + shadow_plane_state->data, fb, clip, + &shadow_plane_state->fmtcnv_state); + argb4444 = argb4444_dst[0 ].vaddr; + } +break ; + } + +return argb4444; +} +static void ast_cursor_plane_helper_atomic_update (struct drm_plane *plane,struct drm_atomic_state *state) {@@ -205,29 +237,13 @@ static void ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,*/ if (drm_atomic_helper_damage_merged (old_plane_state, plane_state, &damage)) { -u8 *argb4444; - -switch (fb->format->format) { -case DRM_FORMAT_ARGB4444 : - argb4444 = shadow_plane_state->data[0 ].vaddr; -break ; -default : - argb4444 = ast_cursor_plane->argb4444; - { -struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { -IOSYS_MAP_INIT_VADDR (argb4444), - }; -unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { -AST_HWC_PITCH , - }; - -drm_fb_argb8888_to_argb4444 (argb4444_dst, argb4444_dst_pitch, - shadow_plane_state->data, fb, &damage, - &shadow_plane_state->fmtcnv_state); - } -break ; - } -ast_set_cursor_image (ast, argb4444, fb->width, fb->height); +const u8 *argb4444 =ast_cursor_plane_get_argb4444 (ast_cursor_plane, + shadow_plane_state, + &damage); + +if (argb4444) +ast_set_cursor_image (ast, argb4444, fb->width, fb->height); +ast_set_cursor_base (ast, dst_off); }
Re: [PATCH 2/3] drm/ast: Support cursor buffers objects in I/O memory
In reply to Thomas ZimmermannQuoted 6 lines · Thomas Zimmermann
Copy the ARGB4444 cursor buffer to system memory if it is located in I/O memory. While this cannot happen with ast's native GEM objects, an imported buffer object might be on the external device's I/O memory.
If the cursor buffer is located in system memory continue to use it directly.
Thanks, it looks good to me.
Quoted 31 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_cursor.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)drivers/gpu/drm/ast/ast_cursor.c +14
-1@@ -191,7 +191,20 @@ static const u8 *ast_cursor_plane_get_argb4444(struct ast_cursor_plane *ast_cursswitch (fb->format->format) {case DRM_FORMAT_ARGB4444 : - argb4444 = shadow_plane_state->data[0 ].vaddr; +if (shadow_plane_state->data[0 ].is_iomem) { +struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { +IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), + }; +unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { +AST_HWC_PITCH , + }; + +drm_fb_memcpy (argb4444_dst, argb4444_dst_pitch, + shadow_plane_state->data, fb, clip); + argb4444 = argb4444_dst[0 ].vaddr; + }else { + argb4444 = shadow_plane_state->data[0 ].vaddr; + }break ;case DRM_FORMAT_ARGB8888 : {
Re: [PATCH 3/3] drm/ast: Wrap cursor framebuffer access in drm_gem_fb_begin/end_cpu_access()
In reply to Thomas ZimmermannQuoted 7 lines · Thomas Zimmermann
Call
drm_gem_fb_begin_cpu_access()anddrm_gem_fb_end_cpu_access()around cursor image updates. Imported buffers might have to be synchronized for CPU access before they can be used.Ignore errors from
drm_gem_fb_begin_cpu_access(). These errors can often be transitory. The cursor image will be updated on the next frame. Meanwhile display a white square where the cursor would be.
Thanks, it looks good to me.
Quoted 98 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_cursor.c | 74 +++++++++++++++++++------------- 1 file changed, 43 insertions(+), 31 deletions(-)drivers/gpu/drm/ast/ast_cursor.c +43
-31@@ -28,6 +28,7 @@#include <drm/drm_damage_helper.h> #include <drm/drm_format_helper.h> #include <drm/drm_gem_atomic_helper.h> +#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_print.h> #include "ast_drv.h" @@ -189,38 +190,49 @@ static const u8 *ast_cursor_plane_get_argb4444(struct ast_cursor_plane *ast_cursstruct drm_framebuffer *fb = plane_state->fb;u8 *argb4444 =NULL ; -switch (fb->format->format) { -case DRM_FORMAT_ARGB4444 : -if (shadow_plane_state->data[0 ].is_iomem) { -struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { -IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), - }; -unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { -AST_HWC_PITCH , - }; - -drm_fb_memcpy (argb4444_dst, argb4444_dst_pitch, - shadow_plane_state->data, fb, clip); - argb4444 = argb4444_dst[0 ].vaddr; - }else { - argb4444 = shadow_plane_state->data[0 ].vaddr; +if (drm_gem_fb_begin_cpu_access (fb,DMA_FROM_DEVICE ) ==0 ) { +switch (fb->format->format) { +case DRM_FORMAT_ARGB4444 : +if (shadow_plane_state->data[0 ].is_iomem) { +struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { +IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), + }; +unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { +AST_HWC_PITCH , + }; + +drm_fb_memcpy (argb4444_dst, argb4444_dst_pitch, + shadow_plane_state->data, fb, clip); + argb4444 = argb4444_dst[0 ].vaddr; + }else { + argb4444 = shadow_plane_state->data[0 ].vaddr; + } +break ; +case DRM_FORMAT_ARGB8888 : + { +struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { +IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), + }; +unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { +AST_HWC_PITCH , + }; + +drm_fb_argb8888_to_argb4444 (argb4444_dst, argb4444_dst_pitch, + shadow_plane_state->data, fb, clip, + &shadow_plane_state->fmtcnv_state); + argb4444 = argb4444_dst[0 ].vaddr; + } +break ; } -break ; -case DRM_FORMAT_ARGB8888 : - { -struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES ] = { -IOSYS_MAP_INIT_VADDR (ast_cursor_plane->argb4444), - }; -unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES ] = { -AST_HWC_PITCH , - }; - -drm_fb_argb8888_to_argb4444 (argb4444_dst, argb4444_dst_pitch, - shadow_plane_state->data, fb, clip, - &shadow_plane_state->fmtcnv_state); - argb4444 = argb4444_dst[0 ].vaddr; - } -break ; + +drm_gem_fb_end_cpu_access (fb,DMA_FROM_DEVICE ); + }else { +/* +* Fall back to white square if GEM object is not ready. Gives +* the user an indication where the cursor is located. +*/ +memset (ast_cursor_plane->argb4444,0xff ,sizeof (ast_cursor_plane->argb4444)); + argb4444 = ast_cursor_plane->argb4444; }return argb4444;