950-0907-drm-vc4-crtc-Move-the-BO-Handling-out-of-Common-Page.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. From 99c7b8eabae7a6a6e6c5f53f3a9d0996b24e10b3 Mon Sep 17 00:00:00 2001
  2. From: Maxime Ripard <[email protected]>
  3. Date: Mon, 2 May 2022 15:27:36 +0200
  4. Subject: [PATCH] drm/vc4: crtc: Move the BO Handling out of Common
  5. Page-Flip Handler
  6. The function vc4_async_page_flip() handles asynchronous page-flips in
  7. the vc4 driver.
  8. However, it mixes some generic code with code that should only be run on
  9. older generations that have the GPU handled by the vc4 driver.
  10. Let's split the generic part out of vc4_async_page_flip() and into a
  11. common function that we be reusable by an handler made for the BCM2711.
  12. Signed-off-by: Maxime Ripard <[email protected]>
  13. ---
  14. drivers/gpu/drm/vc4/vc4_crtc.c | 75 ++++++++++++++++++++++------------
  15. 1 file changed, 48 insertions(+), 27 deletions(-)
  16. --- a/drivers/gpu/drm/vc4/vc4_crtc.c
  17. +++ b/drivers/gpu/drm/vc4/vc4_crtc.c
  18. @@ -896,40 +896,19 @@ static int vc4_async_set_fence_cb(struct
  19. return 0;
  20. }
  21. -/* Implements async (non-vblank-synced) page flips.
  22. - *
  23. - * The page flip ioctl needs to return immediately, so we grab the
  24. - * modeset semaphore on the pipe, and queue the address update for
  25. - * when V3D is done with the BO being flipped to.
  26. - */
  27. -static int vc4_async_page_flip(struct drm_crtc *crtc,
  28. - struct drm_framebuffer *fb,
  29. - struct drm_pending_vblank_event *event,
  30. - uint32_t flags)
  31. +static int
  32. +vc4_async_page_flip_common(struct drm_crtc *crtc,
  33. + struct drm_framebuffer *fb,
  34. + struct drm_pending_vblank_event *event,
  35. + uint32_t flags)
  36. {
  37. struct drm_device *dev = crtc->dev;
  38. struct drm_plane *plane = crtc->primary;
  39. - int ret = 0;
  40. struct vc4_async_flip_state *flip_state;
  41. - struct drm_gem_cma_object *cma_bo = drm_fb_cma_get_gem_obj(fb, 0);
  42. - struct vc4_bo *bo = to_vc4_bo(&cma_bo->base);
  43. -
  44. - /* Increment the BO usecnt here, so that we never end up with an
  45. - * unbalanced number of vc4_bo_{dec,inc}_usecnt() calls when the
  46. - * plane is later updated through the non-async path.
  47. - * FIXME: we should move to generic async-page-flip when it's
  48. - * available, so that we can get rid of this hand-made prepare_fb()
  49. - * logic.
  50. - */
  51. - ret = vc4_bo_inc_usecnt(bo);
  52. - if (ret)
  53. - return ret;
  54. flip_state = kzalloc(sizeof(*flip_state), GFP_KERNEL);
  55. - if (!flip_state) {
  56. - vc4_bo_dec_usecnt(bo);
  57. + if (!flip_state)
  58. return -ENOMEM;
  59. - }
  60. drm_framebuffer_get(fb);
  61. flip_state->fb = fb;
  62. @@ -962,6 +941,48 @@ static int vc4_async_page_flip(struct dr
  63. return 0;
  64. }
  65. +/* Implements async (non-vblank-synced) page flips.
  66. + *
  67. + * The page flip ioctl needs to return immediately, so we grab the
  68. + * modeset semaphore on the pipe, and queue the address update for
  69. + * when V3D is done with the BO being flipped to.
  70. + */
  71. +static int vc4_async_page_flip(struct drm_crtc *crtc,
  72. + struct drm_framebuffer *fb,
  73. + struct drm_pending_vblank_event *event,
  74. + uint32_t flags)
  75. +{
  76. + struct drm_device *dev = crtc->dev;
  77. + struct vc4_dev *vc4 = to_vc4_dev(dev);
  78. + struct drm_gem_cma_object *cma_bo = drm_fb_cma_get_gem_obj(fb, 0);
  79. + struct vc4_bo *bo = to_vc4_bo(&cma_bo->base);
  80. + int ret;
  81. +
  82. + if (WARN_ON_ONCE(vc4->is_vc5))
  83. + return -ENODEV;
  84. +
  85. + /*
  86. + * Increment the BO usecnt here, so that we never end up with an
  87. + * unbalanced number of vc4_bo_{dec,inc}_usecnt() calls when the
  88. + * plane is later updated through the non-async path.
  89. + *
  90. + * FIXME: we should move to generic async-page-flip when
  91. + * it's available, so that we can get rid of this
  92. + * hand-made prepare_fb() logic.
  93. + */
  94. + ret = vc4_bo_inc_usecnt(bo);
  95. + if (ret)
  96. + return ret;
  97. +
  98. + ret = vc4_async_page_flip_common(crtc, fb, event, flags);
  99. + if (ret) {
  100. + vc4_bo_dec_usecnt(bo);
  101. + return ret;
  102. + }
  103. +
  104. + return 0;
  105. +}
  106. +
  107. int vc4_page_flip(struct drm_crtc *crtc,
  108. struct drm_framebuffer *fb,
  109. struct drm_pending_vblank_event *event,