drm/simpledrm: Synchronize access to GEM BOs
authorThomas Zimmermann <tzimmermann@suse.de>
Thu, 22 Sep 2022 13:09:44 +0000 (15:09 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Tue, 27 Sep 2022 08:27:00 +0000 (10:27 +0200)
Synchronize CPU access to GEM BOs with other drivers when updating the
screen buffer. Imported buffers might otherwise contain stale data.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220922130944.27138-6-tzimmermann@suse.de
drivers/gpu/drm/tiny/simpledrm.c

index 5f242558891ebb8f9ce6ad3978558054fcdbc4a0..18489779fb8aa335948f1222f9c04226cb7f8663 100644 (file)
@@ -480,11 +480,15 @@ static void simpledrm_primary_plane_helper_atomic_update(struct drm_plane *plane
        struct simpledrm_device *sdev = simpledrm_device_of_dev(dev);
        struct drm_atomic_helper_damage_iter iter;
        struct drm_rect damage;
-       int idx;
+       int ret, idx;
 
-       if (!drm_dev_enter(dev, &idx))
+       ret = drm_gem_fb_begin_cpu_access(fb, DMA_FROM_DEVICE);
+       if (ret)
                return;
 
+       if (!drm_dev_enter(dev, &idx))
+               goto out_drm_gem_fb_end_cpu_access;
+
        drm_atomic_helper_damage_iter_init(&iter, old_plane_state, plane_state);
        drm_atomic_for_each_plane_damage(&iter, &damage) {
                struct iosys_map dst = IOSYS_MAP_INIT_VADDR(sdev->screen_base);
@@ -499,6 +503,8 @@ static void simpledrm_primary_plane_helper_atomic_update(struct drm_plane *plane
        }
 
        drm_dev_exit(idx);
+out_drm_gem_fb_end_cpu_access:
+       drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
 }
 
 static void simpledrm_primary_plane_helper_atomic_disable(struct drm_plane *plane,