Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/format-helper: Implement drm_fb_swab() with per-line helpers

Replace the inner loop of drm_fb_swab() with helper functions that
swap the bytes in each pixel. This will allow to share the outer
loop with other conversion helpers.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220427141409.22842-2-tzimmermann@suse.de

+35 -25
+35 -25
drivers/gpu/drm/drm_format_helper.c
··· 100 100 } 101 101 EXPORT_SYMBOL(drm_fb_memcpy_toio); 102 102 103 + static void drm_fb_swab16_line(void *dbuf, const void *sbuf, unsigned int pixels) 104 + { 105 + u16 *dbuf16 = dbuf; 106 + const u16 *sbuf16 = sbuf; 107 + const u16 *send16 = sbuf16 + pixels; 108 + 109 + while (sbuf16 < send16) 110 + *dbuf16++ = swab16(*sbuf16++); 111 + } 112 + 113 + static void drm_fb_swab32_line(void *dbuf, const void *sbuf, unsigned int pixels) 114 + { 115 + u32 *dbuf32 = dbuf; 116 + const u32 *sbuf32 = sbuf; 117 + const u32 *send32 = sbuf32 + pixels; 118 + 119 + while (sbuf32 < send32) 120 + *dbuf32++ = swab32(*sbuf32++); 121 + } 122 + 103 123 /** 104 124 * drm_fb_swab - Swap bytes into clip buffer 105 125 * @dst: Destination buffer ··· 140 120 bool cached) 141 121 { 142 122 u8 cpp = fb->format->cpp[0]; 143 - size_t len = drm_rect_width(clip) * cpp; 144 - const u16 *src16; 145 - const u32 *src32; 146 - u16 *dst16; 147 - u32 *dst32; 148 - unsigned int x, y; 123 + unsigned long linepixels = drm_rect_width(clip); 124 + size_t len = linepixels * cpp; 125 + const void *sbuf; 126 + void *dbuf; 127 + unsigned int y; 149 128 void *buf = NULL; 150 129 151 130 if (WARN_ON_ONCE(cpp != 2 && cpp != 4)) ··· 152 133 153 134 if (!dst_pitch) 154 135 dst_pitch = len; 136 + src += clip_offset(clip, fb->pitches[0], cpp); 155 137 156 138 if (!cached) 157 139 buf = kmalloc(len, GFP_KERNEL); 158 140 159 - src += clip_offset(clip, fb->pitches[0], cpp); 160 - 161 141 for (y = clip->y1; y < clip->y2; y++) { 162 - if (buf) { 163 - memcpy(buf, src, len); 164 - src16 = buf; 165 - src32 = buf; 166 - } else { 167 - src16 = src; 168 - src32 = src; 169 - } 142 + if (buf) 143 + sbuf = memcpy(buf, src, len); 144 + else 145 + sbuf = src; 146 + dbuf = dst + clip->x1 * cpp; 170 147 171 - dst16 = dst; 172 - dst32 = dst; 173 - 174 - for (x = clip->x1; x < clip->x2; x++) { 175 - if (cpp == 4) 176 - *dst32++ = swab32(*src32++); 177 - else 178 - *dst16++ = swab16(*src16++); 179 - } 148 + if (cpp == 4) 149 + drm_fb_swab32_line(dbuf, sbuf, linepixels); 150 + else 151 + drm_fb_swab16_line(dbuf, sbuf, linepixels); 180 152 181 153 src += fb->pitches[0]; 182 154 dst += dst_pitch;