Call drm_gem_fb_begin_cpu_access() and drm_gem_fb_end_cpu_access() in the simple pipe's {begin,end}_fb_access helpers. This allows to abort commits correctly after observing an error. Remove the corresponding CPU-access calls from the driver's damage handler. It runs during the atomic-apply phase when it's already too late to handle errors. Signed-off-by: Thomas Zimmermann <tzimmermann@xxxxxxx> --- drivers/gpu/drm/tiny/st7586.c | 44 ++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/tiny/st7586.c b/drivers/gpu/drm/tiny/st7586.c index b6f620b902e6d..bd61e0d22ca2d 100644 --- a/drivers/gpu/drm/tiny/st7586.c +++ b/drivers/gpu/drm/tiny/st7586.c @@ -92,29 +92,20 @@ static void st7586_xrgb8888_to_gray332(u8 *dst, void *vaddr, kfree(buf); } -static int st7586_buf_copy(void *dst, struct drm_framebuffer *fb, - struct drm_rect *clip) +static void st7586_buf_copy(void *dst, struct drm_framebuffer *fb, + struct drm_rect *clip) { struct drm_gem_dma_object *dma_obj = drm_fb_dma_get_gem_obj(fb, 0); void *src = dma_obj->vaddr; - int ret = 0; - - ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); - if (ret) - return ret; st7586_xrgb8888_to_gray332(dst, src, fb, clip); - - drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); - - return 0; } static void st7586_fb_dirty(struct drm_framebuffer *fb, struct drm_rect *rect) { struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev); struct mipi_dbi *dbi = &dbidev->dbi; - int start, end, idx, ret = 0; + int start, end, idx, ret; if (!drm_dev_enter(fb->dev, &idx)) return; @@ -125,9 +116,7 @@ static void st7586_fb_dirty(struct drm_framebuffer *fb, struct drm_rect *rect) DRM_DEBUG_KMS("Flushing [FB:%d] " DRM_RECT_FMT "\n", fb->base.id, DRM_RECT_ARG(rect)); - ret = st7586_buf_copy(dbidev->tx_buf, fb, rect); - if (ret) - goto err_msg; + st7586_buf_copy(dbidev->tx_buf, fb, rect); /* Pixels are packed 3 per byte */ start = rect->x1 / 3; @@ -143,7 +132,6 @@ static void st7586_fb_dirty(struct drm_framebuffer *fb, struct drm_rect *rect) ret = mipi_dbi_command_buf(dbi, MIPI_DCS_WRITE_MEMORY_START, (u8 *)dbidev->tx_buf, (end - start) * (rect->y2 - rect->y1)); -err_msg: if (ret) dev_err_once(fb->dev->dev, "Failed to update display %d\n", ret); @@ -258,6 +246,28 @@ static void st7586_pipe_disable(struct drm_simple_display_pipe *pipe) mipi_dbi_command(&dbidev->dbi, MIPI_DCS_SET_DISPLAY_OFF); } +static int st7586_pipe_begin_fb_access(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state) +{ + struct drm_framebuffer *fb = plane_state->fb; + + if (!fb) + return 0; + + return drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE); +} + +static void st7586_pipe_end_fb_access(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state) +{ + struct drm_framebuffer *fb = plane_state->fb; + + if (!fb) + return; + + drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE); +} + static const u32 st7586_formats[] = { DRM_FORMAT_XRGB8888, }; @@ -266,6 +276,8 @@ static const struct drm_simple_display_pipe_funcs st7586_pipe_funcs = { .enable = st7586_pipe_enable, .disable = st7586_pipe_disable, .update = st7586_pipe_update, + .begin_fb_access = st7586_pipe_begin_fb_access, + .end_fb_access = st7586_pipe_end_fb_access, }; static const struct drm_display_mode st7586_mode = { -- 2.38.0