提交 27bd66dd 编写于 作者: T Thomas Zimmermann

drm/format-helper: Rework format-helper memcpy functions

Move destination-buffer clipping from all format-helper memcpy
function into callers. Support destination-buffer pitch. Only
distinguish between system and I/O memory, but use same logic
everywhere.
Signed-off-by: NThomas Zimmermann <tzimmermann@suse.de>
Tested-by: NNoralf Trønnes <noralf@tronnes.org>
Reviewed-by: NNoralf Trønnes <noralf@tronnes.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20211110103702.374-3-tzimmermann@suse.de
上级 452290f3
...@@ -41,58 +41,62 @@ EXPORT_SYMBOL(drm_fb_clip_offset); ...@@ -41,58 +41,62 @@ EXPORT_SYMBOL(drm_fb_clip_offset);
/** /**
* drm_fb_memcpy - Copy clip buffer * drm_fb_memcpy - Copy clip buffer
* @dst: Destination buffer * @dst: Destination buffer
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
* @vaddr: Source buffer * @vaddr: Source buffer
* @fb: DRM framebuffer * @fb: DRM framebuffer
* @clip: Clip rectangle area to copy * @clip: Clip rectangle area to copy
* *
* This function does not apply clipping on dst, i.e. the destination * This function does not apply clipping on dst, i.e. the destination
* is a small buffer containing the clip rect only. * is at the top-left corner.
*/ */
void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb, void drm_fb_memcpy(void *dst, unsigned int dst_pitch, const void *vaddr,
struct drm_rect *clip) const struct drm_framebuffer *fb, const struct drm_rect *clip)
{ {
unsigned int cpp = fb->format->cpp[0]; unsigned int cpp = fb->format->cpp[0];
size_t len = (clip->x2 - clip->x1) * cpp; size_t len = (clip->x2 - clip->x1) * cpp;
unsigned int y, lines = clip->y2 - clip->y1; unsigned int y, lines = clip->y2 - clip->y1;
if (!dst_pitch)
dst_pitch = len;
vaddr += clip_offset(clip, fb->pitches[0], cpp); vaddr += clip_offset(clip, fb->pitches[0], cpp);
for (y = 0; y < lines; y++) { for (y = 0; y < lines; y++) {
memcpy(dst, vaddr, len); memcpy(dst, vaddr, len);
vaddr += fb->pitches[0]; vaddr += fb->pitches[0];
dst += len; dst += dst_pitch;
} }
} }
EXPORT_SYMBOL(drm_fb_memcpy); EXPORT_SYMBOL(drm_fb_memcpy);
/** /**
* drm_fb_memcpy_dstclip - Copy clip buffer * drm_fb_memcpy_toio - Copy clip buffer
* @dst: Destination buffer (iomem) * @dst: Destination buffer (iomem)
* @dst_pitch: Number of bytes between two consecutive scanlines within dst * @dst_pitch: Number of bytes between two consecutive scanlines within dst
* @vaddr: Source buffer * @vaddr: Source buffer
* @fb: DRM framebuffer * @fb: DRM framebuffer
* @clip: Clip rectangle area to copy * @clip: Clip rectangle area to copy
* *
* This function applies clipping on dst, i.e. the destination is a * This function does not apply clipping on dst, i.e. the destination
* full (iomem) framebuffer but only the clip rect content is copied over. * is at the top-left corner.
*/ */
void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void drm_fb_memcpy_toio(void __iomem *dst, unsigned int dst_pitch, const void *vaddr,
void *vaddr, struct drm_framebuffer *fb, const struct drm_framebuffer *fb, const struct drm_rect *clip)
struct drm_rect *clip)
{ {
unsigned int cpp = fb->format->cpp[0]; unsigned int cpp = fb->format->cpp[0];
unsigned int offset = clip_offset(clip, dst_pitch, cpp);
size_t len = (clip->x2 - clip->x1) * cpp; size_t len = (clip->x2 - clip->x1) * cpp;
unsigned int y, lines = clip->y2 - clip->y1; unsigned int y, lines = clip->y2 - clip->y1;
vaddr += offset; if (!dst_pitch)
dst += offset; dst_pitch = len;
vaddr += clip_offset(clip, fb->pitches[0], cpp);
for (y = 0; y < lines; y++) { for (y = 0; y < lines; y++) {
memcpy_toio(dst, vaddr, len); memcpy_toio(dst, vaddr, len);
vaddr += fb->pitches[0]; vaddr += fb->pitches[0];
dst += dst_pitch; dst += dst_pitch;
} }
} }
EXPORT_SYMBOL(drm_fb_memcpy_dstclip); EXPORT_SYMBOL(drm_fb_memcpy_toio);
/** /**
* drm_fb_swab - Swap bytes into clip buffer * drm_fb_swab - Swap bytes into clip buffer
...@@ -481,7 +485,8 @@ int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned int dst_pitch, ...@@ -481,7 +485,8 @@ int drm_fb_blit_rect_dstclip(void __iomem *dst, unsigned int dst_pitch,
dst_format = DRM_FORMAT_XRGB8888; dst_format = DRM_FORMAT_XRGB8888;
if (dst_format == fb_format) { if (dst_format == fb_format) {
drm_fb_memcpy_dstclip(dst, dst_pitch, vmap, fb, clip); dst += clip_offset(clip, dst_pitch, fb->format->cpp[0]);
drm_fb_memcpy_toio(dst, dst_pitch, vmap, fb, clip);
return 0; return 0;
} else if (dst_format == DRM_FORMAT_RGB565) { } else if (dst_format == DRM_FORMAT_RGB565) {
......
...@@ -213,7 +213,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb, ...@@ -213,7 +213,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
if (swap) if (swap)
drm_fb_swab(dst, src, fb, clip, !gem->import_attach); drm_fb_swab(dst, src, fb, clip, !gem->import_attach);
else else
drm_fb_memcpy(dst, src, fb, clip); drm_fb_memcpy(dst, 0, src, fb, clip);
break; break;
case DRM_FORMAT_XRGB8888: case DRM_FORMAT_XRGB8888:
drm_fb_xrgb8888_to_rgb565(dst, src, fb, clip, swap); drm_fb_xrgb8888_to_rgb565(dst, src, fb, clip, swap);
......
...@@ -206,7 +206,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, ...@@ -206,7 +206,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb,
/* can compress directly from the framebuffer */ /* can compress directly from the framebuffer */
buf = vaddr + rect->y1 * pitch; buf = vaddr + rect->y1 * pitch;
} else { } else {
drm_fb_memcpy(buf, vaddr, fb, rect); drm_fb_memcpy(buf, 0, vaddr, fb, rect);
} }
memset(req, 0, sizeof(*req)); memset(req, 0, sizeof(*req));
......
...@@ -23,13 +23,16 @@ static int hyperv_blit_to_vram_rect(struct drm_framebuffer *fb, ...@@ -23,13 +23,16 @@ static int hyperv_blit_to_vram_rect(struct drm_framebuffer *fb,
struct drm_rect *rect) struct drm_rect *rect)
{ {
struct hyperv_drm_device *hv = to_hv(fb->dev); struct hyperv_drm_device *hv = to_hv(fb->dev);
void __iomem *dst = hv->vram;
void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */ void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */
int idx; int idx;
if (!drm_dev_enter(&hv->dev, &idx)) if (!drm_dev_enter(&hv->dev, &idx))
return -ENODEV; return -ENODEV;
drm_fb_memcpy_dstclip(hv->vram, fb->pitches[0], vmap, fb, rect); dst += drm_fb_clip_offset(fb->pitches[0], fb->format, rect);
drm_fb_memcpy_toio(dst, fb->pitches[0], vmap, fb, rect);
drm_dev_exit(idx); drm_dev_exit(idx);
return 0; return 0;
......
...@@ -847,9 +847,11 @@ static void ...@@ -847,9 +847,11 @@ static void
mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb, mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb,
struct drm_rect *clip, const struct dma_buf_map *map) struct drm_rect *clip, const struct dma_buf_map *map)
{ {
void __iomem *dst = mdev->vram;
void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */ void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */
drm_fb_memcpy_dstclip(mdev->vram, fb->pitches[0], vmap, fb, clip); dst += drm_fb_clip_offset(fb->pitches[0], fb->format, clip);
drm_fb_memcpy_toio(dst, fb->pitches[0], vmap, fb, clip);
/* Always scanout image at VRAM offset 0 */ /* Always scanout image at VRAM offset 0 */
mgag200_set_startadd(mdev, (u32)0); mgag200_set_startadd(mdev, (u32)0);
......
...@@ -317,28 +317,30 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb, const struct dma_buf_ ...@@ -317,28 +317,30 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb, const struct dma_buf_
struct drm_rect *rect) struct drm_rect *rect)
{ {
struct cirrus_device *cirrus = to_cirrus(fb->dev); struct cirrus_device *cirrus = to_cirrus(fb->dev);
void __iomem *dst = cirrus->vram;
void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */ void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */
int idx; int idx;
if (!drm_dev_enter(&cirrus->dev, &idx)) if (!drm_dev_enter(&cirrus->dev, &idx))
return -ENODEV; return -ENODEV;
if (cirrus->cpp == fb->format->cpp[0]) if (cirrus->cpp == fb->format->cpp[0]) {
drm_fb_memcpy_dstclip(cirrus->vram, fb->pitches[0], dst += drm_fb_clip_offset(fb->pitches[0], fb->format, rect);
vmap, fb, rect); drm_fb_memcpy_toio(dst, fb->pitches[0], vmap, fb, rect);
else if (fb->format->cpp[0] == 4 && cirrus->cpp == 2) } else if (fb->format->cpp[0] == 4 && cirrus->cpp == 2) {
drm_fb_xrgb8888_to_rgb565_dstclip(cirrus->vram, drm_fb_xrgb8888_to_rgb565_dstclip(cirrus->vram,
cirrus->pitch, cirrus->pitch,
vmap, fb, rect, false); vmap, fb, rect, false);
else if (fb->format->cpp[0] == 4 && cirrus->cpp == 3) } else if (fb->format->cpp[0] == 4 && cirrus->cpp == 3) {
drm_fb_xrgb8888_to_rgb888_dstclip(cirrus->vram, drm_fb_xrgb8888_to_rgb888_dstclip(cirrus->vram,
cirrus->pitch, cirrus->pitch,
vmap, fb, rect); vmap, fb, rect);
else } else {
WARN_ON_ONCE("cpp mismatch"); WARN_ON_ONCE("cpp mismatch");
}
drm_dev_exit(idx); drm_dev_exit(idx);
......
...@@ -13,11 +13,10 @@ struct drm_rect; ...@@ -13,11 +13,10 @@ struct drm_rect;
unsigned int drm_fb_clip_offset(unsigned int pitch, const struct drm_format_info *format, unsigned int drm_fb_clip_offset(unsigned int pitch, const struct drm_format_info *format,
const struct drm_rect *clip); const struct drm_rect *clip);
void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb, void drm_fb_memcpy(void *dst, unsigned int dst_pitch, const void *vaddr,
struct drm_rect *clip); const struct drm_framebuffer *fb, const struct drm_rect *clip);
void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void *vaddr, void drm_fb_memcpy_toio(void __iomem *dst, unsigned int dst_pitch, const void *vaddr,
struct drm_framebuffer *fb, const struct drm_framebuffer *fb, const struct drm_rect *clip);
struct drm_rect *clip);
void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
struct drm_rect *clip, bool cached); struct drm_rect *clip, bool cached);
void drm_fb_xrgb8888_to_rgb332(void *dst, void *vaddr, struct drm_framebuffer *fb, void drm_fb_xrgb8888_to_rgb332(void *dst, void *vaddr, struct drm_framebuffer *fb,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册