drm/ast: cursor: Improve format handling
Subsystems (3)
Thomas Zimmermann
maintainercover drm/ast: cursor: Improve format handling
A number of generally useful updates to the cursor code.
The cursor code performs format conversion to the hardware's ARGB444 format and calculation of a checksum in a single function. Patch 1 splits this into two steps. Patch 2 then implements the format conversion with DRM's format helpers. Other drivers can now reuse the code.
With the format handling separated, patch 3 adds support for ARGB4444, which is the hardware's native format.
Patch 4 moves cursor handling into a separate source file.
Tested on AST2600.
Thomas Zimmermann (4):
drm/ast: cursor: Calculate checksum in helper drm/ast: cursor: Move format conversion to shared helper drm/ast: cursor: Add support for ARGB4444
drm/ast: cursor: Move implementation to separate source file
drivers/gpu/drm/ast/Makefile | 1 + drivers/gpu/drm/ast/ast_cursor.c | 306 ++++++++++++++++++++++++++++ drivers/gpu/drm/ast/ast_drv.h | 41 ++-- drivers/gpu/drm/ast/ast_mode.c | 273 +------------------------ drivers/gpu/drm/drm_format_helper.c | 69 +++++++ include/drm/drm_format_helper.h | 3 + 6 files changed, 415 insertions(+), 278 deletions(-) create mode 100644 drivers/gpu/drm/ast/ast_cursor.c
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH 1/4 drm/ast: cursor: Calculate checksum in helper
Setting the cursor image requires a 32-bit checksum of the cursor image data. The current cursor code converts the image to ARGB4444 format and computes the checksum in a single step. Moving the checksum calculation into a separate helepr will allow to move the format conversion into a shared helper.
--- drivers/gpu/drm/ast/ast_drv.h | 13 +++++++- drivers/gpu/drm/ast/ast_mode.c | 57 +++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 15 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +12 -1
@@ -142,6 +142,17 @@ static inline struct ast_plane *to_ast_plane(struct drm_plane *plane) return container_of(plane, struct ast_plane, base); } +struct ast_cursor_plane { +struct ast_plane base; + +u8 argb4444[AST_HWC_SIZE ]; +}; + +static inline struct ast_cursor_plane *to_ast_cursor_plane (struct drm_plane *plane) +{ + return container_of(to_ast_plane(plane), struct ast_cursor_plane, base); +} +/* * Connector */
@@ -186,7 +197,7 @@ struct ast_device {enum ast_tx_chip tx_chip;struct ast_plane primary_plane; -struct ast_plane cursor_plane; +struct ast_cursor_plane cursor_plane;struct drm_crtc crtc; union { struct {
drivers/gpu/drm/ast/ast_mode.c +43 -14
126 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH 1/4] drm/ast: cursor: Calculate checksum in helper
Quoted 4 lines · Thomas Zimmermann
Setting the cursor image requires a 32-bit checksum of the cursor image data. The current cursor code converts the image to ARGB4444 format and computes the checksum in a single step. Moving the checksum calculation into a separate helepr will allow to move the
typo: helper
Quoted 1 line
format conversion into a shared helper.
Thanks, I've only one remark below, but you can keep it as-is if you prefer.
Quoted 52 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_drv.h | 13 +++++++- drivers/gpu/drm/ast/ast_mode.c | 57 +++++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 15 deletions(-)drivers/gpu/drm/ast/ast_drv.h +12
-1@@ -142,6 +142,17 @@ static inline struct ast_plane *to_ast_plane(struct drm_plane *plane) return container_of(plane, struct ast_plane, base); } +struct ast_cursor_plane { +struct ast_plane base; + +u8 argb4444[AST_HWC_SIZE ]; +}; + +static inline struct ast_cursor_plane *to_ast_cursor_plane (struct drm_plane *plane) +{ + return container_of(to_ast_plane(plane), struct ast_cursor_plane, base); +} +/* * Connector */ @@ -186,7 +197,7 @@ struct ast_device {enum ast_tx_chip tx_chip;struct ast_plane primary_plane; -struct ast_plane cursor_plane; +struct ast_cursor_plane cursor_plane;struct drm_crtc crtc; union { struct {drivers/gpu/drm/ast/ast_mode.c +5
-1@@ -632,7 +632,32 @@ static int ast_primary_plane_init(struct ast_device *ast)* Cursor plane */ -static void ast_update_cursor_image (u8 __iomem *dst,const u8 *src,int width,int height) +static u32 ast_cursor_calculate_checksum (const u8 *src,unsigned int width,unsigned int height) +{ +u32 csum =0 ; +unsigned int i, j; +unsigned int one_pixel_copy = width &BIT (0 );
drivers/gpu/drm/ast/ast_mode.c static int ast_primary_plane_init(struct ast_device *ast) · line 649
Quoted 10 lines
drivers/gpu/drm/ast/ast_mode.c +10
-0+unsigned int two_pixel_copy = width - one_pixel_copy; +unsigned int trailing_bytes = (AST_MAX_HWC_WIDTH - width) *sizeof (u16); + +for (j =0 ; j < height; j++) { +for (i =0 ; i < two_pixel_copy; i +=2 , src +=SZ_4 ) { +const u32 *src32 = (const u32 *)src; + + csum += *src32; + } +for (i =0 ; i < one_pixel_copy; i++, src +=SZ_2 ) {
This for loop can run only 0 or 1 time, so I would prefer an "if" instead.
Quoted 116 lines
drivers/gpu/drm/ast/ast_mode.c +28
-13+const u16 *src16 = (const u16 *)src; + + csum += *src16; + } + src += trailing_bytes; + } + +return csum; +} + +static void ast_update_cursor_image (u8 __iomem *dst,const u8 *src,u8 *tmp,int width,int height) {union {u32 ul;@@ -644,7 +669,7 @@ static void ast_update_cursor_image(u8 __iomem *dst, const u8 *src, int width, i } data16;u32 csum =0 ;s32 alpha_dst_delta, last_alpha_dst_delta; -u8 __iomem *dstxor; +u8 *dstxor;const u8 *srcxor;int i, j;u32 per_pixel_copy, two_pixel_copy;@@ -653,7 +678,7 @@ static void ast_update_cursor_image(u8 __iomem *dst, const u8 *src, int width, i last_alpha_dst_delta = alpha_dst_delta - (width <<1 ); srcxor = src; - dstxor = (u8 *)dst + last_alpha_dst_delta + (AST_MAX_HWC_HEIGHT - height) * alpha_dst_delta; + dstxor = tmp + last_alpha_dst_delta + (AST_MAX_HWC_HEIGHT - height) * alpha_dst_delta; per_pixel_copy = width &1 ; two_pixel_copy = width >>1 ;@@ -665,21 +690,17 @@ static void ast_update_cursor_image(u8 __iomem *dst, const u8 *src, int width, i data32.b[1 ] = srcdata32[0 ].b[3 ] | (srcdata32[0 ].b[2 ] >>4 ); data32.b[2 ] = srcdata32[1 ].b[1 ] | (srcdata32[1 ].b[0 ] >>4 ); data32.b[3 ] = srcdata32[1 ].b[3 ] | (srcdata32[1 ].b[2 ] >>4 ); - -writel (data32.ul, dstxor); - csum += data32.ul; +memcpy (dstxor, &data32,4 ); dstxor +=4 ; srcxor +=8 ; - }for (i =0 ; i < per_pixel_copy; i++) { srcdata32[0 ].ul = *((u32 *)srcxor) &0xf0f0f0f0 ; data16.b[0 ] = srcdata32[0 ].b[1 ] | (srcdata32[0 ].b[0 ] >>4 ); data16.b[1 ] = srcdata32[0 ].b[3 ] | (srcdata32[0 ].b[2 ] >>4 ); -writew (data16.us, dstxor); - csum += (u32 )data16.us; +memcpy (dstxor, &data16,2 ); dstxor +=2 ; srcxor +=4 ;@@ -687,6 +708,11 @@ static void ast_update_cursor_image(u8 __iomem *dst, const u8 *src, int width, i dstxor += last_alpha_dst_delta; } + csum =ast_cursor_calculate_checksum (tmp, width, height); + +/* write pixel data */ +memcpy_toio (dst, tmp,AST_HWC_SIZE ); +/* write checksum + signature */ dst +=AST_HWC_SIZE ;writel (csum, dst);@@ -767,6 +793,7 @@ static int ast_cursor_plane_helper_atomic_check(struct drm_plane *plane,static void ast_cursor_plane_helper_atomic_update (struct drm_plane *plane,struct drm_atomic_state *state) { +struct ast_cursor_plane *ast_cursor_plane =to_ast_cursor_plane (plane);struct ast_plane *ast_plane =to_ast_plane (plane);struct drm_plane_state *plane_state =drm_atomic_get_new_plane_state (state, plane);struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state);@@ -789,7 +816,8 @@ static void ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,*/ if (drm_atomic_helper_damage_merged (old_plane_state, plane_state, &damage)) { -ast_update_cursor_image (dst, src, fb->width, fb->height); +ast_update_cursor_image (dst, src, ast_cursor_plane->argb4444, + fb->width, fb->height);ast_set_cursor_base (ast, dst_off); }@@ -849,8 +877,9 @@ static const struct drm_plane_funcs ast_cursor_plane_funcs = {static int ast_cursor_plane_init (struct ast_device *ast) {struct drm_device *dev = &ast->base; -struct ast_plane *ast_cursor_plane = &ast->cursor_plane; -struct drm_plane *cursor_plane = &ast_cursor_plane->base; +struct ast_cursor_plane *ast_cursor_plane = &ast->cursor_plane; +struct ast_plane *ast_plane = &ast_cursor_plane->base; +struct drm_plane *cursor_plane = &ast_plane->base;size_t size;void __iomem *vaddr;u64 offset;@@ -869,7 +898,7 @@ static int ast_cursor_plane_init(struct ast_device *ast) vaddr = ast->vram + ast->vram_fb_available - size; offset = ast->vram_fb_available - size; - ret =ast_plane_init (dev, ast_cursor_plane, vaddr, offset, size, + ret =ast_plane_init (dev, ast_plane, vaddr, offset, size,0x01 , &ast_cursor_plane_funcs, ast_cursor_plane_formats,ARRAY_SIZE (ast_cursor_plane_formats),NULL ,DRM_PLANE_TYPE_CURSOR );@@ -1156,7 +1185,7 @@ static int ast_crtc_init(struct ast_device *ast)int ret; ret =drm_crtc_init_with_planes (dev, crtc, &ast->primary_plane.base, - &ast->cursor_plane.base, &ast_crtc_funcs, + &ast->cursor_plane.base.base, &ast_crtc_funcs,NULL );if (ret)return ret;
Thomas Zimmermann
maintainerPATCH 2/4 drm/ast: cursor: Move format conversion to shared helper
In reply to Thomas ZimmermannUser-space cursor-image data is encoded in ARBG8888, while hardware supports ARGB4444. Implement the format conversion as part of the format-helper framework, so that other drivers can benefit.
This allows to respect the damage area of the cursor update. In previous code, all cursor image data had to be converted on each update. Now, only the changed areas require an update. The hardware image is always updated completely, as it is required for the checksum update.
The format-conversion helper still contains the old implementation's optimization of writing 2 output pixels at the same time.
--- drivers/gpu/drm/ast/ast_drv.h | 4 +- drivers/gpu/drm/ast/ast_mode.c | 71 +++++++---------------------- drivers/gpu/drm/drm_format_helper.c | 69 ++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 3 ++ 4 files changed, 92 insertions(+), 55 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +3 -1
@@ -113,7 +113,9 @@ enum ast_config_mode {#define AST_MAX_HWC_WIDTH 64#define AST_MAX_HWC_HEIGHT 64 -#define AST_HWC_SIZE (AST_MAX_HWC_WIDTH * AST_MAX_HWC_HEIGHT * 2) +#define AST_HWC_PITCH (AST_MAX_HWC_WIDTH * SZ_2) +#define AST_HWC_SIZE (AST_MAX_HWC_HEIGHT * AST_HWC_PITCH) +#define AST_HWC_SIGNATURE_SIZE 32/* define for signature structure */
drivers/gpu/drm/ast/ast_mode.c +17 -54
95 lines not on this page · raw message
drivers/gpu/drm/drm_format_helper.c +69 -0
75 lines not on this page · raw message
include/drm/drm_format_helper.h +3 -0
@@ -110,6 +110,9 @@ void drm_fb_xrgb8888_to_argb2101010(struct iosys_map *dst, const unsigned int *dvoid drm_fb_xrgb8888_to_gray8 (struct iosys_map *dst,const unsigned int *dst_pitch,const struct iosys_map *src,const struct drm_framebuffer *fb,const struct drm_rect *clip,struct drm_format_conv_state *state); +void drm_fb_argb8888_to_argb4444 (struct iosys_map *dst,const unsigned int *dst_pitch, +const struct iosys_map *src,const struct drm_framebuffer *fb, +const struct drm_rect *clip,struct drm_format_conv_state *state); int drm_fb_blit(struct iosys_map *dst, const unsigned int *dst_pitch, uint32_t dst_format, const struct iosys_map *src, const struct drm_framebuffer *fb,
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerRe: [PATCH 2/4] drm/ast: cursor: Move format conversion to shared helper
Hi,
here's some additional information this patch.
Am 13.02.25 um 17:25 schrieb Thomas Zimmermann:
[...]
Quoted 4 lines
drivers/gpu/drm/ast/ast_mode.c +4
-0+ +drm_fb_argb8888_to_argb4444 (argb4444_dst, argb4444_dst_pitch, + shadow_plane_state->data, fb, &damage, + &shadow_plane_state->fmtcnv_state);
[...]
Quoted 15 lines
drivers/gpu/drm/drm_format_helper.c +14
-0+static void drm_fb_argb8888_to_argb4444_line (void *dbuf,const void *sbuf,unsigned int pixels) +{ +unsigned int pixels2 = pixels & ~GENMASK_ULL (0 ,0 ); +__le32 *dbuf32 = dbuf; +__le16 *dbuf16 = dbuf + pixels2 *sizeof (*dbuf16); +const __le32 *sbuf32 = sbuf; +unsigned int x; +u32 val32; +u16 val16; +u32 pix[2 ]; + +for (x =0 ; x < pixels2; x +=2 , ++dbuf32) { + pix[0 ] =le32_to_cpu (sbuf32[x]); + pix[1 ] =le32_to_cpu (sbuf32[x +1 ]);
drivers/gpu/drm/drm_format_helper.c void drm_fb_xrgb8888_to_gray8(struct iosys_map *dst, const unsigned int *dst_pit · line 1004
Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +10
-0+ val32 = ((pix[0 ] &0xf0000000 ) >>16 ) | + ((pix[0 ] &0x00f00000 ) >>12 ) | + ((pix[0 ] &0x0000f000 ) >>8 ) | + ((pix[0 ] &0x000000f0 ) >>4 ) | + ((pix[1 ] &0xf0000000 ) >>0 ) | + ((pix[1 ] &0x00f00000 ) <<4 ) | + ((pix[1 ] &0x0000f000 ) <<8 ) | + ((pix[1 ] &0x000000f0 ) <<12 ); + *dbuf32 =cpu_to_le32 (val32); + }
This loop is an optimization. It converts two source pixels at a time and writes them with a 32-bit store. When I measured the impact, I was quite delighted by the results. I measured the time it takes to convert a full cursor image of 64x64 pixels with drm_fb_argb8888_to_argb4444(), and then looked at the average.
Without this loop in place, the average runtime stabilizes around 97K nsecs. Here are the final results
[ 406.420664] ast 0000:02:00.0: [drm] count=8448 average=97239 nsec [ 414.869034] ast 0000:02:00.0: [drm] count=8704 average=97005 nsec [ 425.665928] ast 0000:02:00.0: [drm] count=8960 average=97096 nsec [ 435.185207] ast 0000:02:00.0: [drm] count=9216 average=96711 nsec [ 442.244948] ast 0000:02:00.0: [drm] count=9472 average=96432 nsec
Count is the number of probes. The time has been taken with ktime_get_ns().
With the additional loop, the values stabilize around 52K nsecs.
[ 348.797840] ast 0000:02:00.0: [drm] count=8448 average=51729 [ 356.503387] ast 0000:02:00.0: [drm] count=8704 average=51680 [ 364.151804] ast 0000:02:00.0: [drm] count=8960 average=51574 [ 372.412221] ast 0000:02:00.0: [drm] count=9216 average=51563 [ 425.158072] ast 0000:02:00.0: [drm] count=9472 average=51674
That's only ~53% of the unoptimized case.
Given these results, I'll try to add similar optimizations to other format-conversion helpers. Most of the format conversion happens for drivers with only a single output format, such as simpledrm. For full-screen pageflips on such drivers, it might even make a visible difference.
Best regards
Thomas
Quoted 62 lines
drivers/gpu/drm/drm_format_helper.c +45
-0+for (; x < pixels; x++) { + pix[0 ] =le32_to_cpu (sbuf32[x]); + val16 = ((pix[0 ] &0xf0000000 ) >>16 ) | + ((pix[0 ] &0x00f00000 ) >>12 ) | + ((pix[0 ] &0x0000f000 ) >>8 ) | + ((pix[0 ] &0x000000f0 ) >>4 ); + dbuf16[x] =cpu_to_le16 (val16); + } +} + +/** +* drm_fb_argb8888_to_argb4444 - Convert ARGB8888 to ARGB4444 clip buffer +* @dst: Array of ARGB4444 destination buffers +* @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines +* within @dst; can be NULL if scanlines are stored next to each other. +* @src: Array of ARGB8888 source buffer +* @fb: DRM framebuffer +* @clip: Clip rectangle area to copy +* @state: Transform and conversion state +* +* This function copies parts of a framebuffer to display memory and converts +* the color format during the process. The parameters @dst, @dst_pitch and +* @src refer to arrays. Each array must have at least as many entries as +* there are planes in @fb's format. Each entry stores the value for the +* format's respective color plane at the same index. +* +* This function does not apply clipping on @dst (i.e. the destination is at the +* top-left corner). +* +* Drivers can use this function for ARGB4444 devices that don't support +* ARGB8888 natively. +*/ +void drm_fb_argb8888_to_argb4444 (struct iosys_map *dst,const unsigned int *dst_pitch, +const struct iosys_map *src,const struct drm_framebuffer *fb, +const struct drm_rect *clip,struct drm_format_conv_state *state) +{ +static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES ] = { +2 , + }; + +drm_fb_xfrm (dst, dst_pitch, dst_pixsize, src, fb, clip, false, state, + drm_fb_argb8888_to_argb4444_line); +} +EXPORT_SYMBOL (drm_fb_argb8888_to_argb4444); +/** * drm_fb_blit - Copy parts of a framebuffer to display memory * @dst: Array of display-memory addresses to copy to include/drm/drm_format_helper.h +3
-0@@ -110,6 +110,9 @@ void drm_fb_xrgb8888_to_argb2101010(struct iosys_map *dst, const unsigned int *dvoid drm_fb_xrgb8888_to_gray8 (struct iosys_map *dst,const unsigned int *dst_pitch,const struct iosys_map *src,const struct drm_framebuffer *fb,const struct drm_rect *clip,struct drm_format_conv_state *state); +void drm_fb_argb8888_to_argb4444 (struct iosys_map *dst,const unsigned int *dst_pitch, +const struct iosys_map *src,const struct drm_framebuffer *fb, +const struct drm_rect *clip,struct drm_format_conv_state *state); int drm_fb_blit(struct iosys_map *dst, const unsigned int *dst_pitch, uint32_t dst_format, const struct iosys_map *src, const struct drm_framebuffer *fb,
Signature · 7 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
Re: [PATCH 2/4] drm/ast: cursor: Move format conversion to shared helper
In reply to Thomas ZimmermannQuoted 9 lines · Thomas Zimmermann
User-space cursor-image data is encoded in ARBG8888, while hardware supports ARGB4444. Implement the format conversion as part of the format-helper framework, so that other drivers can benefit.
This allows to respect the damage area of the cursor update. In previous code, all cursor image data had to be converted on each update. Now, only the changed areas require an update. The hardware image is always updated completely, as it is required for the checksum update.
Hum, for a 64x64 cursor size, I don't see much benefit to handle damage area (And I'm not sure userspace actually change only parts of the cursor).
Quoted 3 lines
The format-conversion helper still contains the old implementation's optimization of writing 2 output pixels at the same time.
Thanks, it looks good to me.
Quoted 220 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_drv.h | 4 +- drivers/gpu/drm/ast/ast_mode.c | 71 +++++++---------------------- drivers/gpu/drm/drm_format_helper.c | 69 ++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 3 ++ 4 files changed, 92 insertions(+), 55 deletions(-)drivers/gpu/drm/ast/ast_drv.h +3
-1@@ -113,7 +113,9 @@ enum ast_config_mode {#define AST_MAX_HWC_WIDTH 64#define AST_MAX_HWC_HEIGHT 64 -#define AST_HWC_SIZE (AST_MAX_HWC_WIDTH * AST_MAX_HWC_HEIGHT * 2) +#define AST_HWC_PITCH (AST_MAX_HWC_WIDTH * SZ_2) +#define AST_HWC_SIZE (AST_MAX_HWC_HEIGHT * AST_HWC_PITCH) +#define AST_HWC_SIGNATURE_SIZE 32/* define for signature structure */ drivers/gpu/drm/ast/ast_mode.c +17
-54@@ -657,61 +657,16 @@ static u32 ast_cursor_calculate_checksum(const u8 *src, unsigned int width, unsireturn csum; } -static void ast_update_cursor_image (u8 __iomem *dst,const u8 *src,u8 *tmp,int width,int height) +static void ast_set_cursor_image (struct ast_device *ast,const u8 *src, +unsigned int width,unsigned int height) { -union { -u32 ul; -u8 b[4 ]; - } srcdata32[2 ], data32; -union { -u16 us; -u8 b[2 ]; - } data16; +u8 __iomem *dst = ast->cursor_plane.base.vaddr;u32 csum =0 ; -s32 alpha_dst_delta, last_alpha_dst_delta; -u8 *dstxor; -const u8 *srcxor; -int i, j; -u32 per_pixel_copy, two_pixel_copy; - alpha_dst_delta =AST_MAX_HWC_WIDTH <<1 ; - last_alpha_dst_delta = alpha_dst_delta - (width <<1 ); - - srcxor = src; - dstxor = tmp + last_alpha_dst_delta + (AST_MAX_HWC_HEIGHT - height) * alpha_dst_delta; - per_pixel_copy = width &1 ; - two_pixel_copy = width >>1 ; - -for (j =0 ; j < height; j++) { -for (i =0 ; i < two_pixel_copy; i++) { - srcdata32[0 ].ul = *((u32 *)srcxor) &0xf0f0f0f0 ; - srcdata32[1 ].ul = *((u32 *)(srcxor +4 )) &0xf0f0f0f0 ; - data32.b[0 ] = srcdata32[0 ].b[1 ] | (srcdata32[0 ].b[0 ] >>4 ); - data32.b[1 ] = srcdata32[0 ].b[3 ] | (srcdata32[0 ].b[2 ] >>4 ); - data32.b[2 ] = srcdata32[1 ].b[1 ] | (srcdata32[1 ].b[0 ] >>4 ); - data32.b[3 ] = srcdata32[1 ].b[3 ] | (srcdata32[1 ].b[2 ] >>4 ); -memcpy (dstxor, &data32,4 ); - - dstxor +=4 ; - srcxor +=8 ; - } - -for (i =0 ; i < per_pixel_copy; i++) { - srcdata32[0 ].ul = *((u32 *)srcxor) &0xf0f0f0f0 ; - data16.b[0 ] = srcdata32[0 ].b[1 ] | (srcdata32[0 ].b[0 ] >>4 ); - data16.b[1 ] = srcdata32[0 ].b[3 ] | (srcdata32[0 ].b[2 ] >>4 ); -memcpy (dstxor, &data16,2 ); - - dstxor +=2 ; - srcxor +=4 ; - } - dstxor += last_alpha_dst_delta; - } - - csum =ast_cursor_calculate_checksum (tmp, width, height); + csum =ast_cursor_calculate_checksum (src, width, height);/* write pixel data */ -memcpy_toio (dst, tmp,AST_HWC_SIZE ); +memcpy_toio (dst, src,AST_HWC_SIZE );/* write checksum + signature */ dst +=AST_HWC_SIZE ;@@ -800,9 +755,7 @@ static void ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,struct drm_framebuffer *fb = plane_state->fb;struct drm_plane_state *old_plane_state =drm_atomic_get_old_plane_state (state, plane);struct ast_device *ast =to_ast_device (plane->dev); -struct iosys_map src_map = shadow_plane_state->data[0 ];struct drm_rect damage; -const u8 *src = src_map.vaddr;/* TODO: Use mapping abstraction properly */ u64 dst_off = ast_plane->offset;u8 __iomem *dst = ast_plane->vaddr;/* TODO: Use mapping abstraction properly */ u8 __iomem *sig = dst +AST_HWC_SIZE ;/* TODO: Use mapping abstraction properly */ @@ -816,8 +769,18 @@ static void ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,*/ if (drm_atomic_helper_damage_merged (old_plane_state, plane_state, &damage)) { -ast_update_cursor_image (dst, src, ast_cursor_plane->argb4444, - fb->width, fb->height); +u8 *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); +ast_set_cursor_image (ast, argb4444, fb->width, fb->height);ast_set_cursor_base (ast, dst_off); }drivers/gpu/drm/drm_format_helper.c +69
-0@@ -978,6 +978,75 @@ void drm_fb_xrgb8888_to_gray8(struct iosys_map *dst, const unsigned int *dst_pit }EXPORT_SYMBOL (drm_fb_xrgb8888_to_gray8); +static void drm_fb_argb8888_to_argb4444_line (void *dbuf,const void *sbuf,unsigned int pixels) +{ +unsigned int pixels2 = pixels & ~GENMASK_ULL (0 ,0 ); +__le32 *dbuf32 = dbuf; +__le16 *dbuf16 = dbuf + pixels2 *sizeof (*dbuf16); +const __le32 *sbuf32 = sbuf; +unsigned int x; +u32 val32; +u16 val16; +u32 pix[2 ]; + +for (x =0 ; x < pixels2; x +=2 , ++dbuf32) { + pix[0 ] =le32_to_cpu (sbuf32[x]); + pix[1 ] =le32_to_cpu (sbuf32[x +1 ]); + val32 = ((pix[0 ] &0xf0000000 ) >>16 ) | + ((pix[0 ] &0x00f00000 ) >>12 ) | + ((pix[0 ] &0x0000f000 ) >>8 ) | + ((pix[0 ] &0x000000f0 ) >>4 ) | + ((pix[1 ] &0xf0000000 ) >>0 ) | + ((pix[1 ] &0x00f00000 ) <<4 ) | + ((pix[1 ] &0x0000f000 ) <<8 ) | + ((pix[1 ] &0x000000f0 ) <<12 ); + *dbuf32 =cpu_to_le32 (val32); + } +for (; x < pixels; x++) { + pix[0 ] =le32_to_cpu (sbuf32[x]); + val16 = ((pix[0 ] &0xf0000000 ) >>16 ) | + ((pix[0 ] &0x00f00000 ) >>12 ) | + ((pix[0 ] &0x0000f000 ) >>8 ) | + ((pix[0 ] &0x000000f0 ) >>4 ); + dbuf16[x] =cpu_to_le16 (val16); + } +} + +/** +* drm_fb_argb8888_to_argb4444 - Convert ARGB8888 to ARGB4444 clip buffer +* @dst: Array of ARGB4444 destination buffers +* @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines +* within @dst; can be NULL if scanlines are stored next to each other. +* @src: Array of ARGB8888 source buffer +* @fb: DRM framebuffer +* @clip: Clip rectangle area to copy +* @state: Transform and conversion state +* +* This function copies parts of a framebuffer to display memory and converts +* the color format during the process. The parameters @dst, @dst_pitch and +* @src refer to arrays. Each array must have at least as many entries as +* there are planes in @fb's format. Each entry stores the value for the +* format's respective color plane at the same index. +* +* This function does not apply clipping on @dst (i.e. the destination is at the +* top-left corner). +* +* Drivers can use this function for ARGB4444 devices that don't support +* ARGB8888 natively. +*/ +void drm_fb_argb8888_to_argb4444 (struct iosys_map *dst,const unsigned int *dst_pitch, +const struct iosys_map *src,const struct drm_framebuffer *fb, +const struct drm_rect *clip,struct drm_format_conv_state *state) +{ +static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES ] = { +2 , + }; + +drm_fb_xfrm (dst, dst_pitch, dst_pixsize, src, fb, clip, false, state, + drm_fb_argb8888_to_argb4444_line); +} +EXPORT_SYMBOL (drm_fb_argb8888_to_argb4444); +/** * drm_fb_blit - Copy parts of a framebuffer to display memory * @dst: Array of display-memory addresses to copy to include/drm/drm_format_helper.h +3
-0@@ -110,6 +110,9 @@ void drm_fb_xrgb8888_to_argb2101010(struct iosys_map *dst, const unsigned int *dvoid drm_fb_xrgb8888_to_gray8 (struct iosys_map *dst,const unsigned int *dst_pitch,const struct iosys_map *src,const struct drm_framebuffer *fb,const struct drm_rect *clip,struct drm_format_conv_state *state); +void drm_fb_argb8888_to_argb4444 (struct iosys_map *dst,const unsigned int *dst_pitch, +const struct iosys_map *src,const struct drm_framebuffer *fb, +const struct drm_rect *clip,struct drm_format_conv_state *state); int drm_fb_blit(struct iosys_map *dst, const unsigned int *dst_pitch, uint32_t dst_format, const struct iosys_map *src, const struct drm_framebuffer *fb,
Thomas Zimmermann
maintainerRe: [PATCH 2/4] drm/ast: cursor: Move format conversion to shared helper
Hi
Am 14.02.25 um 11:35 schrieb Jocelyn Falempe:
Quoted 5 lines · Thomas Zimmermann
Quoted 4 lines
User-space cursor-image data is encoded in ARBG8888, while hardware supports ARGB4444. Implement the format conversion as part of the format-helper framework, so that other drivers can benefit.
Quoted 7 lines
Quoted 5 lines
This allows to respect the damage area of the cursor update. In previous code, all cursor image data had to be converted on each update. Now, only the changed areas require an update. The hardware image is always updated completely, as it is required for the checksum update.
Hum, for a 64x64 cursor size, I don't see much benefit to handle damage area (And I'm not sure userspace actually change only parts of the cursor).
Of course. I could imagine a user space that implements fully generic plane handling and treats all planes as equal; hence doing damage handling on cursors. But current user space usually treats cursor planes separately from primary planes and always replaces the cursor image with a different one. But we get it for free, so why not?
Quoted 8 lines
Quoted 4 lines
The format-conversion helper still contains the old implementation's optimization of writing 2 output pixels at the same time.
Thanks, it looks good to me.
Reviewed-by Jocelyn Falempe <[email protected]>
Thanks for reviewing.
Best regards
Thomas
Quoted 236 lines
Quoted 235 lines
Signed-off-by Thomas Zimmermann <[email protected]>---
drivers/gpu/drm/ast/ast_drv.h | 4 +- drivers/gpu/drm/ast/ast_mode.c | 71 +++++++----------------------drivers/gpu/drm/drm_format_helper.c| 69 ++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 3 ++4 files changed, 92 insertions(+), 55 deletions(-)drivers/gpu/drm/ast/ast_drv.h +3
-0@@ -113,7 +113,9 @@ enum ast_config_mode { #define AST_MAX_HWC_WIDTH 64 #define AST_MAX_HWC_HEIGHT 64 -#define AST_HWC_SIZE (AST_MAX_HWC_WIDTH * AST_MAX_HWC_HEIGHT * 2) +#define AST_HWC_PITCH (AST_MAX_HWC_WIDTH * SZ_2) +#define AST_HWC_SIZE (AST_MAX_HWC_HEIGHT * AST_HWC_PITCH) + #define AST_HWC_SIGNATURE_SIZE 32 /* define for signature structure */drivers/gpu/drm/ast/ast_mode.c +0
-0@@ -657,61 +657,16 @@ static u32 ast_cursor_calculate_checksum(constu8 *src, unsigned int width, unsi
return csum;
}
-static voidast_update_cursor_image(u8 __iomem *dst, const u8 *src, u8 *tmp, int width, int height)+static void ast_set_cursor_image(structast_device*ast, const u8 *src,
+ unsigned int width, unsigned int height)
{
- union {
- u32 ul;
- u8 b[4];
- } srcdata32[2], data32;
- union {
- u16 us;
- u8 b[2];
- } data16;
+ u8__iomem*dst =ast->cursor_plane.base.vaddr;
u32 csum = 0;
- s32alpha_dst_delta,last_alpha_dst_delta;
- u8 *dstxor;
- const u8 *srcxor;
- int i, j;
- u32per_pixel_copy,two_pixel_copy;
-alpha_dst_delta=AST_MAX_HWC_WIDTH<< 1;
-last_alpha_dst_delta=alpha_dst_delta- (width << 1);
-
- srcxor = src;
- dstxor = tmp +last_alpha_dst_delta+ (AST_MAX_HWC_HEIGHT-
height) *alpha_dst_delta;
-per_pixel_copy= width & 1;
-two_pixel_copy= width >> 1;drivers/gpu/drm/ast/ast_mode.c +1
-28- - for (j = 0; j < height; j++) { - for (i = 0; i < two_pixel_copy; i++) { - srcdata32[0].ul = *((u32 *)srcxor) & 0xf0f0f0f0; - srcdata32[1].ul = *((u32 *)(srcxor + 4)) & 0xf0f0f0f0; - data32.b[0] = srcdata32[0].b[1] | (srcdata32[0].b[0] >> 4); - data32.b[1] = srcdata32[0].b[3] | (srcdata32[0].b[2] >> 4); - data32.b[2] = srcdata32[1].b[1] | (srcdata32[1].b[0] >> 4); - data32.b[3] = srcdata32[1].b[3] | (srcdata32[1].b[2] >> 4); - memcpy(dstxor, &data32, 4); - - dstxor += 4; - srcxor += 8; - } - - for (i = 0; i < per_pixel_copy; i++) { - srcdata32[0].ul = *((u32 *)srcxor) & 0xf0f0f0f0; - data16.b[0] = srcdata32[0].b[1] | (srcdata32[0].b[0] >> 4); - data16.b[1] = srcdata32[0].b[3] | (srcdata32[0].b[2] >> 4); - memcpy(dstxor, &data16, 2); - - dstxor += 2; - srcxor += 4; - } - dstxor += last_alpha_dst_delta; - } - - csum = ast_cursor_calculate_checksum(tmp, width, height); + csum = ast_cursor_calculate_checksum(src, width, height);/* write pixel data */
-memcpy_toio(dst, tmp, AST_HWC_SIZE);
+memcpy_toio(dst, src, AST_HWC_SIZE);
/* write checksum + signature */
dst +=AST_HWC_SIZE;drivers/gpu/drm/ast/ast_mode.c +0
-2@@ -800,9 +755,7 @@ static void ast_cursor_plane_helper_atomic_update(struct drm_plane *plane, struct drm_framebuffer *fb = plane_state->fb; struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state, plane); struct ast_device *ast = to_ast_device(plane->dev); - struct iosys_map src_map = shadow_plane_state->data[0]; struct drm_rect damage; - const u8 *src = src_map.vaddr; /* TODO: Use mapping abstractionproperly */
u64dst_off=ast_plane->offset;
u8__iomem*dst =ast_plane->vaddr; /* TODO: Use mapping abstraction properly */ u8__iomem*sig = dst +AST_HWC_SIZE; /* TODO: Use mapping abstraction properly */drivers/gpu/drm/ast/ast_mode.c +12
-2@@ -816,8 +769,18 @@ static voidast_cursor_plane_helper_atomic_update(struct drm_plane *plane, */ if (drm_atomic_helper_damage_merged(old_plane_state, plane_state, &damage)) { - ast_update_cursor_image(dst, src, ast_cursor_plane->argb4444, - fb->width, fb->height); + u8 *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); + ast_set_cursor_image(ast, argb4444, fb->width, fb->height); ast_set_cursor_base(ast, dst_off); }diff --git
a/drivers/gpu/drm/drm_format_helper.cb/drivers/gpu/drm/drm_format_helper.cindexb1be458ed4dd..ecb278b63e8c100644drivers/gpu/drm/drm_format_helper.c +35
-0@@ -978,6 +978,75 @@ void drm_fb_xrgb8888_to_gray8(struct iosys_map *dst, const unsigned int *dst_pit } EXPORT_SYMBOL(drm_fb_xrgb8888_to_gray8); +static void drm_fb_argb8888_to_argb4444_line(void *dbuf, const void *sbuf, unsigned int pixels) +{ + unsigned int pixels2 = pixels & ~GENMASK_ULL(0, 0); + __le32 *dbuf32 = dbuf; + __le16 *dbuf16 = dbuf + pixels2 * sizeof(*dbuf16); + const __le32 *sbuf32 = sbuf; + unsigned int x; + u32 val32; + u16 val16; + u32 pix[2]; + + for (x = 0; x < pixels2; x += 2, ++dbuf32) { + pix[0] = le32_to_cpu(sbuf32[x]); + pix[1] = le32_to_cpu(sbuf32[x + 1]); + val32 = ((pix[0] & 0xf0000000) >> 16) | + ((pix[0] & 0x00f00000) >> 12) | + ((pix[0] & 0x0000f000) >> 8) | + ((pix[0] & 0x000000f0) >> 4) | + ((pix[1] & 0xf0000000) >> 0) | + ((pix[1] & 0x00f00000) << 4) | + ((pix[1] & 0x0000f000) << 8) | + ((pix[1] & 0x000000f0) << 12); + *dbuf32 = cpu_to_le32(val32); + } + for (; x < pixels; x++) { + pix[0] = le32_to_cpu(sbuf32[x]); + val16 = ((pix[0] & 0xf0000000) >> 16) | + ((pix[0] & 0x00f00000) >> 12) | + ((pix[0] & 0x0000f000) >> 8) | + ((pix[0] & 0x000000f0) >> 4); + dbuf16[x] = cpu_to_le16(val16); + } +} + +/** +* drm_fb_argb8888_to_argb4444 - Convert ARGB8888 to ARGB4444 clip buffer
+ * @dst: Array of ARGB4444 destination buffers
+ * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
+ * within @dst; can be NULL if scanlines are stored next to each other.
+ * @src: Array of ARGB8888 source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ * @state: Transform and conversion state
+ *
+ * This function copies parts of a framebuffer to display memory and converts
+ * the color format during the process. The parameters @dst, @dst_pitch and
+ * @src refer to arrays. Each array must have at least as many entries as
+ * there are planes in @fb's format. Each entry stores the value for the
+ * format's respective color plane at the same index.
+ *
+ * This function does not apply clipping on @dst (i.e. the destination is at the
+ * top-left corner).
+ *
+ * Drivers can use this function for ARGB4444 devices that don't support
+ * ARGB8888 natively.
+ */
+void drm_fb_argb8888_to_argb4444(structiosys_map*dst, const unsigned int*dst_pitch,
+ const structiosys_map*src, const structdrm_framebuffer*fb,
+ const structdrm_rect*clip, structdrm_format_conv_state*state)drivers/gpu/drm/drm_format_helper.c +6
-0+{ + static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = { + 2, + }; + + drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false,state,
+drm_fb_argb8888_to_argb4444_line);drivers/gpu/drm/drm_format_helper.c +3
-0+} +EXPORT_SYMBOL (drm_fb_argb8888_to_argb4444); +/**
*drm_fb_blit- Copy parts of a framebuffer to display memory
* @dst: Array of display-memory addresses to copy toinclude/drm/drm_format_helper.h +0
-0@@ -110,6 +110,9 @@ void drm_fb_xrgb8888_to_argb2101010(struct
iosys_map*dst, const unsigned int *d
void drm_fb_xrgb8888_to_gray8(structiosys_map*dst, const unsigned int*dst_pitch, const structiosys_map*src, const structdrm_framebuffer*fb, const structdrm_rect*clip, structdrm_format_conv_state*state); +void drm_fb_argb8888_to_argb4444(structiosys_map*dst, const
unsigned int*dst_pitch,
+ const structiosys_map*src, const structdrm_framebuffer*fb,
+ const structdrm_rect*clip, structdrm_format_conv_state*state);
int drm_fb_blit(structiosys_map*dst, const unsigned int*dst_pitch,uint32_tdst_format, const structiosys_map*src, const structdrm_framebuffer*fb,
Signature · 7 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
Thomas Zimmermann
maintainerPATCH 3/4 drm/ast: cursor: Add support for ARGB4444
In reply to Thomas ZimmermannAdd support for cursor image data in ARGB4444 format. This is the hardware's native format and requires no conversion.
--- drivers/gpu/drm/ast/ast_mode.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +23 -11
@@ -718,6 +718,7 @@ static void ast_set_cursor_enabled(struct ast_device *ast, bool enabled) }static const uint32_t ast_cursor_plane_formats[] = { +DRM_FORMAT_ARGB4444 ,DRM_FORMAT_ARGB8888 , };
@@ -769,17 +770,28 @@ 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 = 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); +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);ast_set_cursor_base (ast, dst_off); }
Signature · 1 line
2.48.1
Re: [PATCH 3/4] drm/ast: cursor: Add support for ARGB4444
Quoted 3 lines · Thomas Zimmermann
Add support for cursor image data in ARGB4444 format. This is the hardware's native format and requires no conversion.
Thanks, it looks good to me.
Quoted 57 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_mode.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-)drivers/gpu/drm/ast/ast_mode.c +23
-11@@ -718,6 +718,7 @@ static void ast_set_cursor_enabled(struct ast_device *ast, bool enabled) }static const uint32_t ast_cursor_plane_formats[] = { +DRM_FORMAT_ARGB4444 ,DRM_FORMAT_ARGB8888 , };@@ -769,17 +770,28 @@ 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 = 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); +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);ast_set_cursor_base (ast, dst_off); }
Thomas Zimmermann
maintainerPATCH 4/4 drm/ast: cursor: Move implementation to separate source file
In reply to Thomas ZimmermannMove the cursor code into a separate source file for readability. No functional changes.
--- drivers/gpu/drm/ast/Makefile | 1 + drivers/gpu/drm/ast/ast_cursor.c | 306 +++++++++++++++++++++++++++++++ drivers/gpu/drm/ast/ast_drv.h | 24 +-- drivers/gpu/drm/ast/ast_mode.c | 275 +-------------------------- 4 files changed, 327 insertions(+), 279 deletions(-) create mode 100644 drivers/gpu/drm/ast/ast_cursor.c
drivers/gpu/drm/ast/Makefile +1 -0
@@ -4,6 +4,7 @@ # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. ast-y := \ + ast_cursor.o \ ast_ddc.o \ ast_dp501.o \ ast_dp.o \
drivers/gpu/drm/ast/ast_cursor.c new file +306 -0
306 lines not on this page · raw message
drivers/gpu/drm/ast/ast_drv.h +13 -11
@@ -118,15 +118,6 @@ enum ast_config_mode {#define AST_HWC_SIGNATURE_SIZE 32 -/* define for signature structure */ -#define AST_HWC_SIGNATURE_CHECKSUM 0x00 -#define AST_HWC_SIGNATURE_SizeX 0x04 -#define AST_HWC_SIGNATURE_SizeY 0x08 -#define AST_HWC_SIGNATURE_X 0x0C -#define AST_HWC_SIGNATURE_Y 0x10 -#define AST_HWC_SIGNATURE_HOTSPOTX 0x14 -#define AST_HWC_SIGNATURE_HOTSPOTY 0x18 -/* * Planes */
@@ -383,8 +374,6 @@ struct ast_crtc_state {#define to_ast_crtc_state (state) container_of(state, struct ast_crtc_state, base) -int ast_mode_config_init (struct ast_device *ast); -#define AST_MM_ALIGN_SHIFT 4#define AST_MM_ALIGN_MASK ((1 << AST_MM_ALIGN_SHIFT) - 1)
@@ -450,6 +439,9 @@ void ast_patch_ahb_2500(void __iomem *regs);int ast_vga_output_init (struct ast_device *ast);int ast_sil164_output_init (struct ast_device *ast); +/* ast_cursor.c */ +int ast_cursor_plane_init (struct ast_device *ast); +/* ast dp501 */ bool ast_backup_fw (struct ast_device *ast,u8 *addr,u32 size);void ast_init_3rdtx (struct ast_device *ast);
@@ -459,4 +451,14 @@ int ast_dp501_output_init(struct ast_device *ast);int ast_dp_launch (struct ast_device *ast);int ast_astdp_output_init (struct ast_device *ast); +/* ast_mode.c */ +int ast_mode_config_init (struct ast_device *ast); +int ast_plane_init (struct drm_device *dev,struct ast_plane *ast_plane, +void __iomem *vaddr,u64 offset,unsigned long size, +uint32_t possible_crtcs, +const struct drm_plane_funcs *funcs, +const uint32_t *formats,unsigned int format_count, +const uint64_t *format_modifiers, +enum drm_plane_type type); +#endif
drivers/gpu/drm/ast/ast_mode.c +7 -268
287 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH 4/4] drm/ast: cursor: Move implementation to separate source file
Quoted 3 lines · Thomas Zimmermann
Move the cursor code into a separate source file for readability. No functional changes.
Thanks, it looks good to me.
Quoted 680 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/Makefile | 1 + drivers/gpu/drm/ast/ast_cursor.c | 306 +++++++++++++++++++++++++++++++ drivers/gpu/drm/ast/ast_drv.h | 24 +-- drivers/gpu/drm/ast/ast_mode.c | 275 +-------------------------- 4 files changed, 327 insertions(+), 279 deletions(-)create mode 100644
drivers/gpu/drm/ast/ast_cursor.cdrivers/gpu/drm/ast/Makefile +1
-0@@ -4,6 +4,7 @@ # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. ast-y := \ + ast_cursor.o \ ast_ddc.o \ ast_dp501.o \ ast_dp.o \drivers/gpu/drm/ast/ast_cursor.c new file +306
-0@@ -0,0 +1,306 @@ +// SPDX-License-Identifier: MIT +/* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sub license, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +* USE OR OTHER DEALINGS IN THE SOFTWARE. +* +* The above copyright notice and this permission notice (including the +* next paragraph) shall be included in all copies or substantial portions +* of the Software. +*/ + +#include <linux/sizes.h> + +#include <drm/drm_atomic.h> +#include <drm/drm_damage_helper.h> +#include <drm/drm_format_helper.h> +#include <drm/drm_gem_atomic_helper.h> +#include <drm/drm_print.h> + +#include "ast_drv.h" + +/* +* Hardware cursor +*/ + +/* define for signature structure */ +#define AST_HWC_SIGNATURE_CHECKSUM 0x00 +#define AST_HWC_SIGNATURE_SizeX 0x04 +#define AST_HWC_SIGNATURE_SizeY 0x08 +#define AST_HWC_SIGNATURE_X 0x0C +#define AST_HWC_SIGNATURE_Y 0x10 +#define AST_HWC_SIGNATURE_HOTSPOTX 0x14 +#define AST_HWC_SIGNATURE_HOTSPOTY 0x18 + +static u32 ast_cursor_calculate_checksum (const u8 *src,unsigned int width,unsigned int height) +{ +u32 csum =0 ; +unsigned int i, j; +unsigned int one_pixel_copy = width &BIT (0 ); +unsigned int two_pixel_copy = width - one_pixel_copy; +unsigned int trailing_bytes = (AST_MAX_HWC_WIDTH - width) *sizeof (u16); + +for (j =0 ; j < height; j++) { +for (i =0 ; i < two_pixel_copy; i +=2 , src +=SZ_4 ) { +const u32 *src32 = (const u32 *)src; + + csum += *src32; + } +for (i =0 ; i < one_pixel_copy; i++, src +=SZ_2 ) { +const u16 *src16 = (const u16 *)src; + + csum += *src16; + } + src += trailing_bytes; + } + +return csum; +} + +static void ast_set_cursor_image (struct ast_device *ast,const u8 *src, +unsigned int width,unsigned int height) +{ +u8 __iomem *dst = ast->cursor_plane.base.vaddr; +u32 csum =0 ; + + csum =ast_cursor_calculate_checksum (src, width, height); + +/* write pixel data */ +memcpy_toio (dst, src,AST_HWC_SIZE ); + +/* write checksum + signature */ + dst +=AST_HWC_SIZE ; +writel (csum, dst); +writel (width, dst + AST_HWC_SIGNATURE_SizeX); +writel (height, dst + AST_HWC_SIGNATURE_SizeY); +writel (0 , dst +AST_HWC_SIGNATURE_HOTSPOTX ); +writel (0 , dst +AST_HWC_SIGNATURE_HOTSPOTY ); +} + +static void ast_set_cursor_base (struct ast_device *ast,u64 address) +{ +u8 addr0 = (address >>3 ) &0xff ; +u8 addr1 = (address >>11 ) &0xff ; +u8 addr2 = (address >>19 ) &0xff ; + +ast_set_index_reg (ast,AST_IO_VGACRI ,0xc8 , addr0); +ast_set_index_reg (ast,AST_IO_VGACRI ,0xc9 , addr1); +ast_set_index_reg (ast,AST_IO_VGACRI ,0xca , addr2); +} + +static void ast_set_cursor_location (struct ast_device *ast,u16 x,u16 y, +u8 x_offset,u8 y_offset) +{ +u8 x0 = (x &0x00ff ); +u8 x1 = (x &0x0f00 ) >>8 ; +u8 y0 = (y &0x00ff ); +u8 y1 = (y &0x0700 ) >>8 ; + +ast_set_index_reg (ast,AST_IO_VGACRI ,0xc2 , x_offset); +ast_set_index_reg (ast,AST_IO_VGACRI ,0xc3 , y_offset); +ast_set_index_reg (ast,AST_IO_VGACRI ,0xc4 , x0); +ast_set_index_reg (ast,AST_IO_VGACRI ,0xc5 , x1); +ast_set_index_reg (ast,AST_IO_VGACRI ,0xc6 , y0); +ast_set_index_reg (ast,AST_IO_VGACRI ,0xc7 , y1); +} + +static void ast_set_cursor_enabled (struct ast_device *ast,bool enabled) +{ +static const u8 mask = (u8 )~(AST_IO_VGACRCB_HWC_16BPP | +AST_IO_VGACRCB_HWC_ENABLED ); + +u8 vgacrcb =AST_IO_VGACRCB_HWC_16BPP ; + +if (enabled) + vgacrcb |=AST_IO_VGACRCB_HWC_ENABLED ; + +ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xcb , mask, vgacrcb); +} + +/* +* Cursor plane +*/ + +static const uint32_t ast_cursor_plane_formats[] = { +DRM_FORMAT_ARGB4444 , +DRM_FORMAT_ARGB8888 , +}; + +static int ast_cursor_plane_helper_atomic_check (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +struct drm_plane_state *new_plane_state =drm_atomic_get_new_plane_state (state, plane); +struct drm_framebuffer *new_fb = new_plane_state->fb; +struct drm_crtc_state *new_crtc_state =NULL ; +int ret; + +if (new_plane_state->crtc) + new_crtc_state =drm_atomic_get_new_crtc_state (state, new_plane_state->crtc); + + ret =drm_atomic_helper_check_plane_state (new_plane_state, new_crtc_state, +DRM_PLANE_NO_SCALING , +DRM_PLANE_NO_SCALING , + true, true); +if (ret || !new_plane_state->visible) +return ret; + +if (new_fb->width >AST_MAX_HWC_WIDTH || new_fb->height >AST_MAX_HWC_HEIGHT ) +return -EINVAL ; + +return 0 ; +} + +static void ast_cursor_plane_helper_atomic_update (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +struct ast_cursor_plane *ast_cursor_plane =to_ast_cursor_plane (plane); +struct ast_plane *ast_plane =to_ast_plane (plane); +struct drm_plane_state *plane_state =drm_atomic_get_new_plane_state (state, plane); +struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); +struct drm_framebuffer *fb = plane_state->fb; +struct drm_plane_state *old_plane_state =drm_atomic_get_old_plane_state (state, plane); +struct ast_device *ast =to_ast_device (plane->dev); +struct drm_rect damage; +u64 dst_off = ast_plane->offset; +u8 __iomem *dst = ast_plane->vaddr;/* TODO: Use mapping abstraction properly */ +u8 __iomem *sig = dst +AST_HWC_SIZE ;/* TODO: Use mapping abstraction properly */ +unsigned int offset_x, offset_y; +u16 x, y; +u8 x_offset, y_offset; + +/* +* Do data transfer to hardware buffer and point the scanout +* engine to the offset. +*/ + +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); +ast_set_cursor_base (ast, dst_off); + } + +/* +* Update location in HWC signature and registers. +*/ + +writel (plane_state->crtc_x, sig +AST_HWC_SIGNATURE_X ); +writel (plane_state->crtc_y, sig +AST_HWC_SIGNATURE_Y ); + + offset_x =AST_MAX_HWC_WIDTH - fb->width; + offset_y =AST_MAX_HWC_HEIGHT - fb->height; + +if (plane_state->crtc_x <0 ) { + x_offset = (-plane_state->crtc_x) + offset_x; + x =0 ; + }else { + x_offset = offset_x; + x = plane_state->crtc_x; + } +if (plane_state->crtc_y <0 ) { + y_offset = (-plane_state->crtc_y) + offset_y; + y =0 ; + }else { + y_offset = offset_y; + y = plane_state->crtc_y; + } + +ast_set_cursor_location (ast, x, y, x_offset, y_offset); + +/* Dummy write to enable HWC and make the HW pick-up the changes. */ +ast_set_cursor_enabled (ast, true); +} + +static void ast_cursor_plane_helper_atomic_disable (struct drm_plane *plane, +struct drm_atomic_state *state) +{ +struct ast_device *ast =to_ast_device (plane->dev); + +ast_set_cursor_enabled (ast, false); +} + +static const struct drm_plane_helper_funcs ast_cursor_plane_helper_funcs = { +DRM_GEM_SHADOW_PLANE_HELPER_FUNCS , + .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, +DRM_GEM_SHADOW_PLANE_FUNCS , +}; + +int ast_cursor_plane_init (struct ast_device *ast) +{ +struct drm_device *dev = &ast->base; +struct ast_cursor_plane *ast_cursor_plane = &ast->cursor_plane; +struct ast_plane *ast_plane = &ast_cursor_plane->base; +struct drm_plane *cursor_plane = &ast_plane->base; +size_t size; +void __iomem *vaddr; +u64 offset; +int ret; + +/* +* Allocate backing storage for cursors. The BOs are permanently +* pinned to the top end of the VRAM. +*/ + + size =roundup (AST_HWC_SIZE +AST_HWC_SIGNATURE_SIZE ,PAGE_SIZE ); + +if (ast->vram_fb_available < size) +return -ENOMEM ; + + vaddr = ast->vram + ast->vram_fb_available - size; + offset = ast->vram_fb_available - size; + + ret =ast_plane_init (dev, ast_plane, vaddr, offset, size, +0x01 , &ast_cursor_plane_funcs, + ast_cursor_plane_formats,ARRAY_SIZE (ast_cursor_plane_formats), +NULL ,DRM_PLANE_TYPE_CURSOR ); +if (ret) { +drm_err (dev,"ast_plane_init() failed: %d\n" , ret); +return ret; + } +drm_plane_helper_add (cursor_plane, &ast_cursor_plane_helper_funcs); +drm_plane_enable_fb_damage_clips (cursor_plane); + + ast->vram_fb_available -= size; + +return 0 ; +}drivers/gpu/drm/ast/ast_drv.h +13
-11@@ -118,15 +118,6 @@ enum ast_config_mode {#define AST_HWC_SIGNATURE_SIZE 32 -/* define for signature structure */ -#define AST_HWC_SIGNATURE_CHECKSUM 0x00 -#define AST_HWC_SIGNATURE_SizeX 0x04 -#define AST_HWC_SIGNATURE_SizeY 0x08 -#define AST_HWC_SIGNATURE_X 0x0C -#define AST_HWC_SIGNATURE_Y 0x10 -#define AST_HWC_SIGNATURE_HOTSPOTX 0x14 -#define AST_HWC_SIGNATURE_HOTSPOTY 0x18 -/* * Planes */ @@ -383,8 +374,6 @@ struct ast_crtc_state {#define to_ast_crtc_state (state) container_of(state, struct ast_crtc_state, base) -int ast_mode_config_init (struct ast_device *ast); -#define AST_MM_ALIGN_SHIFT 4#define AST_MM_ALIGN_MASK ((1 << AST_MM_ALIGN_SHIFT) - 1)@@ -450,6 +439,9 @@ void ast_patch_ahb_2500(void __iomem *regs);int ast_vga_output_init (struct ast_device *ast);int ast_sil164_output_init (struct ast_device *ast); +/* ast_cursor.c */ +int ast_cursor_plane_init (struct ast_device *ast); +/* ast dp501 */ bool ast_backup_fw (struct ast_device *ast,u8 *addr,u32 size);void ast_init_3rdtx (struct ast_device *ast);@@ -459,4 +451,14 @@ int ast_dp501_output_init(struct ast_device *ast);int ast_dp_launch (struct ast_device *ast);int ast_astdp_output_init (struct ast_device *ast); +/* ast_mode.c */ +int ast_mode_config_init (struct ast_device *ast); +int ast_plane_init (struct drm_device *dev,struct ast_plane *ast_plane, +void __iomem *vaddr,u64 offset,unsigned long size, +uint32_t possible_crtcs, +const struct drm_plane_funcs *funcs, +const uint32_t *formats,unsigned int format_count, +const uint64_t *format_modifiers, +enum drm_plane_type type); +#endif drivers/gpu/drm/ast/ast_mode.c +7
-268@@ -438,13 +438,13 @@ static void ast_wait_for_vretrace(struct ast_device *ast)* Planes */ -static int ast_plane_init (struct drm_device *dev,struct ast_plane *ast_plane, -void __iomem *vaddr,u64 offset,unsigned long size, -uint32_t possible_crtcs, -const struct drm_plane_funcs *funcs, -const uint32_t *formats,unsigned int format_count, -const uint64_t *format_modifiers, -enum drm_plane_type type) +int ast_plane_init (struct drm_device *dev,struct ast_plane *ast_plane, +void __iomem *vaddr,u64 offset,unsigned long size, +uint32_t possible_crtcs, +const struct drm_plane_funcs *funcs, +const uint32_t *formats,unsigned int format_count, +const uint64_t *format_modifiers, +enum drm_plane_type type) {struct drm_plane *plane = &ast_plane->base;@@ -628,267 +628,6 @@ static int ast_primary_plane_init(struct ast_device *ast)return 0 ; } -/* -* Cursor plane -*/ - -static u32 ast_cursor_calculate_checksum (const u8 *src,unsigned int width,unsigned int height) -{ -u32 csum =0 ; -unsigned int i, j; -unsigned int one_pixel_copy = width &BIT (0 ); -unsigned int two_pixel_copy = width - one_pixel_copy; -unsigned int trailing_bytes = (AST_MAX_HWC_WIDTH - width) *sizeof (u16); - -for (j =0 ; j < height; j++) { -for (i =0 ; i < two_pixel_copy; i +=2 , src +=SZ_4 ) { -const u32 *src32 = (const u32 *)src; - - csum += *src32; - } -for (i =0 ; i < one_pixel_copy; i++, src +=SZ_2 ) { -const u16 *src16 = (const u16 *)src; - - csum += *src16; - } - src += trailing_bytes; - } - -return csum; -} - -static void ast_set_cursor_image (struct ast_device *ast,const u8 *src, -unsigned int width,unsigned int height) -{ -u8 __iomem *dst = ast->cursor_plane.base.vaddr; -u32 csum =0 ; - - csum =ast_cursor_calculate_checksum (src, width, height); - -/* write pixel data */ -memcpy_toio (dst, src,AST_HWC_SIZE ); - -/* write checksum + signature */ - dst +=AST_HWC_SIZE ; -writel (csum, dst); -writel (width, dst + AST_HWC_SIGNATURE_SizeX); -writel (height, dst + AST_HWC_SIGNATURE_SizeY); -writel (0 , dst +AST_HWC_SIGNATURE_HOTSPOTX ); -writel (0 , dst +AST_HWC_SIGNATURE_HOTSPOTY ); -} - -static void ast_set_cursor_base (struct ast_device *ast,u64 address) -{ -u8 addr0 = (address >>3 ) &0xff ; -u8 addr1 = (address >>11 ) &0xff ; -u8 addr2 = (address >>19 ) &0xff ; - -ast_set_index_reg (ast,AST_IO_VGACRI ,0xc8 , addr0); -ast_set_index_reg (ast,AST_IO_VGACRI ,0xc9 , addr1); -ast_set_index_reg (ast,AST_IO_VGACRI ,0xca , addr2); -} - -static void ast_set_cursor_location (struct ast_device *ast,u16 x,u16 y, -u8 x_offset,u8 y_offset) -{ -u8 x0 = (x &0x00ff ); -u8 x1 = (x &0x0f00 ) >>8 ; -u8 y0 = (y &0x00ff ); -u8 y1 = (y &0x0700 ) >>8 ; - -ast_set_index_reg (ast,AST_IO_VGACRI ,0xc2 , x_offset); -ast_set_index_reg (ast,AST_IO_VGACRI ,0xc3 , y_offset); -ast_set_index_reg (ast,AST_IO_VGACRI ,0xc4 , x0); -ast_set_index_reg (ast,AST_IO_VGACRI ,0xc5 , x1); -ast_set_index_reg (ast,AST_IO_VGACRI ,0xc6 , y0); -ast_set_index_reg (ast,AST_IO_VGACRI ,0xc7 , y1); -} - -static void ast_set_cursor_enabled (struct ast_device *ast,bool enabled) -{ -static const u8 mask = (u8 )~(AST_IO_VGACRCB_HWC_16BPP | -AST_IO_VGACRCB_HWC_ENABLED ); - -u8 vgacrcb =AST_IO_VGACRCB_HWC_16BPP ; - -if (enabled) - vgacrcb |=AST_IO_VGACRCB_HWC_ENABLED ; - -ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xcb , mask, vgacrcb); -} - -static const uint32_t ast_cursor_plane_formats[] = { -DRM_FORMAT_ARGB4444 , -DRM_FORMAT_ARGB8888 , -}; - -static int ast_cursor_plane_helper_atomic_check (struct drm_plane *plane, -struct drm_atomic_state *state) -{ -struct drm_plane_state *new_plane_state =drm_atomic_get_new_plane_state (state, plane); -struct drm_framebuffer *new_fb = new_plane_state->fb; -struct drm_crtc_state *new_crtc_state =NULL ; -int ret; - -if (new_plane_state->crtc) - new_crtc_state =drm_atomic_get_new_crtc_state (state, new_plane_state->crtc); - - ret =drm_atomic_helper_check_plane_state (new_plane_state, new_crtc_state, -DRM_PLANE_NO_SCALING , -DRM_PLANE_NO_SCALING , - true, true); -if (ret || !new_plane_state->visible) -return ret; - -if (new_fb->width >AST_MAX_HWC_WIDTH || new_fb->height >AST_MAX_HWC_HEIGHT ) -return -EINVAL ; - -return 0 ; -} - -static void ast_cursor_plane_helper_atomic_update (struct drm_plane *plane, -struct drm_atomic_state *state) -{ -struct ast_cursor_plane *ast_cursor_plane =to_ast_cursor_plane (plane); -struct ast_plane *ast_plane =to_ast_plane (plane); -struct drm_plane_state *plane_state =drm_atomic_get_new_plane_state (state, plane); -struct drm_shadow_plane_state *shadow_plane_state =to_drm_shadow_plane_state (plane_state); -struct drm_framebuffer *fb = plane_state->fb; -struct drm_plane_state *old_plane_state =drm_atomic_get_old_plane_state (state, plane); -struct ast_device *ast =to_ast_device (plane->dev); -struct drm_rect damage; -u64 dst_off = ast_plane->offset; -u8 __iomem *dst = ast_plane->vaddr;/* TODO: Use mapping abstraction properly */ -u8 __iomem *sig = dst +AST_HWC_SIZE ;/* TODO: Use mapping abstraction properly */ -unsigned int offset_x, offset_y; -u16 x, y; -u8 x_offset, y_offset; - -/* -* Do data transfer to hardware buffer and point the scanout -* engine to the offset. -*/ - -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); -ast_set_cursor_base (ast, dst_off); - } - -/* -* Update location in HWC signature and registers. -*/ - -writel (plane_state->crtc_x, sig +AST_HWC_SIGNATURE_X ); -writel (plane_state->crtc_y, sig +AST_HWC_SIGNATURE_Y ); - - offset_x =AST_MAX_HWC_WIDTH - fb->width; - offset_y =AST_MAX_HWC_HEIGHT - fb->height; - -if (plane_state->crtc_x <0 ) { - x_offset = (-plane_state->crtc_x) + offset_x; - x =0 ; - }else { - x_offset = offset_x; - x = plane_state->crtc_x; - } -if (plane_state->crtc_y <0 ) { - y_offset = (-plane_state->crtc_y) + offset_y; - y =0 ; - }else { - y_offset = offset_y; - y = plane_state->crtc_y; - } - -ast_set_cursor_location (ast, x, y, x_offset, y_offset); - -/* Dummy write to enable HWC and make the HW pick-up the changes. */ -ast_set_cursor_enabled (ast, true); -} - -static void ast_cursor_plane_helper_atomic_disable (struct drm_plane *plane, -struct drm_atomic_state *state) -{ -struct ast_device *ast =to_ast_device (plane->dev); - -ast_set_cursor_enabled (ast, false); -} - -static const struct drm_plane_helper_funcs ast_cursor_plane_helper_funcs = { -DRM_GEM_SHADOW_PLANE_HELPER_FUNCS , - .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, -DRM_GEM_SHADOW_PLANE_FUNCS , -}; - -static int ast_cursor_plane_init (struct ast_device *ast) -{ -struct drm_device *dev = &ast->base; -struct ast_cursor_plane *ast_cursor_plane = &ast->cursor_plane; -struct ast_plane *ast_plane = &ast_cursor_plane->base; -struct drm_plane *cursor_plane = &ast_plane->base; -size_t size; -void __iomem *vaddr; -u64 offset; -int ret; - -/* -* Allocate backing storage for cursors. The BOs are permanently -* pinned to the top end of the VRAM. -*/ - - size =roundup (AST_HWC_SIZE +AST_HWC_SIGNATURE_SIZE ,PAGE_SIZE ); - -if (ast->vram_fb_available < size) -return -ENOMEM ; - - vaddr = ast->vram + ast->vram_fb_available - size; - offset = ast->vram_fb_available - size; - - ret =ast_plane_init (dev, ast_plane, vaddr, offset, size, -0x01 , &ast_cursor_plane_funcs, - ast_cursor_plane_formats,ARRAY_SIZE (ast_cursor_plane_formats), -NULL ,DRM_PLANE_TYPE_CURSOR ); -if (ret) { -drm_err (dev,"ast_plane_init() failed: %d\n" , ret); -return ret; - } -drm_plane_helper_add (cursor_plane, &ast_cursor_plane_helper_funcs); -drm_plane_enable_fb_damage_clips (cursor_plane); - - ast->vram_fb_available -= size; - -return 0 ; -} -/* * CRTC */