Skip to content

Commit 48e2b69

Browse files
author
Thomas Zimmermann
committed
drm/vboxvideo: Implement cursor plane with struct drm_shadow_plane_state
Functions in the atomic commit tail are not allowed to acquire the dmabuf's reservation lock. So we cannot legally call the GEM object's vmap functionality in atomic_update. Instead use struct drm_shadow_plane_state and friends. It vmaps the framebuffer BOs in prepare_fb and vunmaps them in cleanup_fb. The cursor plane state stores the mapping's address. The pinning of the BO is implicitly done by vmap. As an extra benefit, there's no source of runtime errors left in atomic_update. v2: * rebase patch onto struct drm_shadow_plane_state Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Tested-by: Hans de Goede <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 9dc9067 commit 48e2b69

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

drivers/gpu/drm/vboxvideo/vbox_mode.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <drm/drm_atomic_helper.h>
1818
#include <drm/drm_fb_helper.h>
1919
#include <drm/drm_fourcc.h>
20+
#include <drm/drm_gem_atomic_helper.h>
2021
#include <drm/drm_gem_framebuffer_helper.h>
2122
#include <drm/drm_plane_helper.h>
2223
#include <drm/drm_probe_helper.h>
@@ -381,14 +382,14 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane,
381382
container_of(plane->dev, struct vbox_private, ddev);
382383
struct vbox_crtc *vbox_crtc = to_vbox_crtc(plane->state->crtc);
383384
struct drm_framebuffer *fb = plane->state->fb;
384-
struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(fb->obj[0]);
385385
u32 width = plane->state->crtc_w;
386386
u32 height = plane->state->crtc_h;
387+
struct drm_shadow_plane_state *shadow_plane_state =
388+
to_drm_shadow_plane_state(plane->state);
389+
struct dma_buf_map map = shadow_plane_state->map[0];
390+
u8 *src = map.vaddr; /* TODO: Use mapping abstraction properly */
387391
size_t data_size, mask_size;
388392
u32 flags;
389-
struct dma_buf_map map;
390-
int ret;
391-
u8 *src;
392393

393394
/*
394395
* VirtualBox uses the host windowing system to draw the cursor so
@@ -401,17 +402,6 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane,
401402

402403
vbox_crtc->cursor_enabled = true;
403404

404-
ret = drm_gem_vram_vmap(gbo, &map);
405-
if (ret) {
406-
/*
407-
* BUG: we should have pinned the BO in prepare_fb().
408-
*/
409-
mutex_unlock(&vbox->hw_mutex);
410-
DRM_WARN("Could not map cursor bo, skipping update\n");
411-
return;
412-
}
413-
src = map.vaddr; /* TODO: Use mapping abstraction properly */
414-
415405
/*
416406
* The mask must be calculated based on the alpha
417407
* channel, one bit per ARGB word, and must be 32-bit
@@ -421,7 +411,6 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane,
421411
data_size = width * height * 4 + mask_size;
422412

423413
copy_cursor_image(src, vbox->cursor_data, width, height, mask_size);
424-
drm_gem_vram_vunmap(gbo, &map);
425414

426415
flags = VBOX_MOUSE_POINTER_VISIBLE | VBOX_MOUSE_POINTER_SHAPE |
427416
VBOX_MOUSE_POINTER_ALPHA;
@@ -466,17 +455,14 @@ static const struct drm_plane_helper_funcs vbox_cursor_helper_funcs = {
466455
.atomic_check = vbox_cursor_atomic_check,
467456
.atomic_update = vbox_cursor_atomic_update,
468457
.atomic_disable = vbox_cursor_atomic_disable,
469-
.prepare_fb = drm_gem_vram_plane_helper_prepare_fb,
470-
.cleanup_fb = drm_gem_vram_plane_helper_cleanup_fb,
458+
DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
471459
};
472460

473461
static const struct drm_plane_funcs vbox_cursor_plane_funcs = {
474462
.update_plane = drm_atomic_helper_update_plane,
475463
.disable_plane = drm_atomic_helper_disable_plane,
476464
.destroy = drm_primary_helper_destroy,
477-
.reset = drm_atomic_helper_plane_reset,
478-
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
479-
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
465+
DRM_GEM_SHADOW_PLANE_FUNCS,
480466
};
481467

482468
static const u32 vbox_primary_plane_formats[] = {

0 commit comments

Comments
 (0)