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

drm/virtio: Don't reinvent a flipping wheel

Now that the core helpers support nonblocking atomic commits there's
no need to invent that wheel separately (instead of fixing the bug in
the atomic implementation of virtio, as it should have been done!).

v2: Rebased on top of

commit e7cf0963f816fa44190caaf51aeffaa614c340c6
Author: Gerd Hoffmann <kraxel@redhat.com>
Date: Tue May 31 08:50:47 2016 +0200

virtio-gpu: add atomic_commit function

Cc: Gerd Hoffmann <kraxel@redhat.com>
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1465510073-20951-1-git-send-email-daniel.vetter@ffwll.ch

+13 -58
+13 -58
drivers/gpu/drm/virtio/virtgpu_display.c
··· 38 38 #define XRES_MAX 8192 39 39 #define YRES_MAX 8192 40 40 41 - static int virtio_gpu_page_flip(struct drm_crtc *crtc, 42 - struct drm_framebuffer *fb, 43 - struct drm_pending_vblank_event *event, 44 - uint32_t flags) 45 - { 46 - struct virtio_gpu_device *vgdev = crtc->dev->dev_private; 47 - struct virtio_gpu_output *output = 48 - container_of(crtc, struct virtio_gpu_output, crtc); 49 - struct drm_plane *plane = crtc->primary; 50 - struct virtio_gpu_framebuffer *vgfb; 51 - struct virtio_gpu_object *bo; 52 - unsigned long irqflags; 53 - uint32_t handle; 54 - 55 - plane->fb = fb; 56 - vgfb = to_virtio_gpu_framebuffer(plane->fb); 57 - bo = gem_to_virtio_gpu_obj(vgfb->obj); 58 - handle = bo->hw_res_handle; 59 - 60 - DRM_DEBUG("handle 0x%x%s, crtc %dx%d\n", handle, 61 - bo->dumb ? ", dumb" : "", 62 - crtc->mode.hdisplay, crtc->mode.vdisplay); 63 - if (bo->dumb) { 64 - virtio_gpu_cmd_transfer_to_host_2d 65 - (vgdev, handle, 0, 66 - cpu_to_le32(crtc->mode.hdisplay), 67 - cpu_to_le32(crtc->mode.vdisplay), 68 - 0, 0, NULL); 69 - } 70 - virtio_gpu_cmd_set_scanout(vgdev, output->index, handle, 71 - crtc->mode.hdisplay, 72 - crtc->mode.vdisplay, 0, 0); 73 - virtio_gpu_cmd_resource_flush(vgdev, handle, 0, 0, 74 - crtc->mode.hdisplay, 75 - crtc->mode.vdisplay); 76 - 77 - if (event) { 78 - spin_lock_irqsave(&crtc->dev->event_lock, irqflags); 79 - drm_crtc_send_vblank_event(crtc, event); 80 - spin_unlock_irqrestore(&crtc->dev->event_lock, irqflags); 81 - } 82 - 83 - return 0; 84 - } 85 - 86 41 static const struct drm_crtc_funcs virtio_gpu_crtc_funcs = { 87 42 .set_config = drm_atomic_helper_set_config, 88 43 .destroy = drm_crtc_cleanup, 89 44 90 - .page_flip = virtio_gpu_page_flip, 45 + .page_flip = drm_atomic_helper_page_flip, 91 46 .reset = drm_atomic_helper_crtc_reset, 92 47 .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, 93 48 .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, ··· 140 185 spin_lock_irqsave(&crtc->dev->event_lock, flags); 141 186 if (crtc->state->event) 142 187 drm_crtc_send_vblank_event(crtc, crtc->state->event); 188 + crtc->state->event = NULL; 143 189 spin_unlock_irqrestore(&crtc->dev->event_lock, flags); 144 190 } 145 191 ··· 334 378 return &virtio_gpu_fb->base; 335 379 } 336 380 337 - static int vgdev_atomic_commit(struct drm_device *dev, 338 - struct drm_atomic_state *state, 339 - bool nonblock) 381 + static void vgdev_atomic_commit_tail(struct drm_atomic_state *state) 340 382 { 341 - if (nonblock) 342 - return -EBUSY; 343 - 344 - drm_atomic_helper_swap_state(state, true); 345 - drm_atomic_helper_wait_for_fences(dev, state); 383 + struct drm_device *dev = state->dev; 346 384 347 385 drm_atomic_helper_commit_modeset_disables(dev, state); 348 386 drm_atomic_helper_commit_modeset_enables(dev, state); 349 387 drm_atomic_helper_commit_planes(dev, state, true); 350 388 389 + drm_atomic_helper_commit_hw_done(state); 390 + 351 391 drm_atomic_helper_wait_for_vblanks(dev, state); 352 392 drm_atomic_helper_cleanup_planes(dev, state); 353 - drm_atomic_state_free(state); 354 - return 0; 355 393 } 394 + 395 + struct drm_mode_config_helper_funcs virtio_mode_config_helpers = { 396 + .atomic_commit_tail = vgdev_atomic_commit_tail, 397 + }; 356 398 357 399 static const struct drm_mode_config_funcs virtio_gpu_mode_funcs = { 358 400 .fb_create = virtio_gpu_user_framebuffer_create, 359 401 .atomic_check = drm_atomic_helper_check, 360 - .atomic_commit = vgdev_atomic_commit, 402 + .atomic_commit = drm_atomic_helper_commit, 361 403 }; 362 404 363 405 int virtio_gpu_modeset_init(struct virtio_gpu_device *vgdev) ··· 363 409 int i; 364 410 365 411 drm_mode_config_init(vgdev->ddev); 366 - vgdev->ddev->mode_config.funcs = (void *)&virtio_gpu_mode_funcs; 412 + vgdev->ddev->mode_config.funcs = &virtio_gpu_mode_funcs; 413 + vgdev->ddev->mode_config.helper_private = &virtio_mode_config_helpers; 367 414 368 415 /* modes will be validated against the framebuffer size */ 369 416 vgdev->ddev->mode_config.min_width = XRES_MIN;