0279-drm-vc4-Move-the-plane-clipping-scaling-setup-to-a-s.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. From 647c62f1d368e2418d8abc6ea11c0c1bac7fae11 Mon Sep 17 00:00:00 2001
  2. From: Eric Anholt <eric@anholt.net>
  3. Date: Mon, 28 Dec 2015 14:34:44 -0800
  4. Subject: [PATCH 279/381] drm/vc4: Move the plane clipping/scaling setup to a
  5. separate function.
  6. As we add actual scaling, this is going to get way more complicated.
  7. Signed-off-by: Eric Anholt <eric@anholt.net>
  8. (cherry picked from commit 5c6799942003df91801b1d2277bba34d71f99603)
  9. ---
  10. drivers/gpu/drm/vc4/vc4_plane.c | 78 +++++++++++++++++++++++++++--------------
  11. 1 file changed, 52 insertions(+), 26 deletions(-)
  12. --- a/drivers/gpu/drm/vc4/vc4_plane.c
  13. +++ b/drivers/gpu/drm/vc4/vc4_plane.c
  14. @@ -40,6 +40,14 @@ struct vc4_plane_state {
  15. * hardware at vc4_crtc_atomic_flush() time.
  16. */
  17. u32 __iomem *hw_dlist;
  18. +
  19. + /* Clipped coordinates of the plane on the display. */
  20. + int crtc_x, crtc_y, crtc_w, crtc_h;
  21. +
  22. + /* Offset to start scanning out from the start of the plane's
  23. + * BO.
  24. + */
  25. + u32 offset;
  26. };
  27. static inline struct vc4_plane_state *
  28. @@ -167,22 +175,17 @@ static void vc4_dlist_write(struct vc4_p
  29. vc4_state->dlist[vc4_state->dlist_count++] = val;
  30. }
  31. -/* Writes out a full display list for an active plane to the plane's
  32. - * private dlist state.
  33. - */
  34. -static int vc4_plane_mode_set(struct drm_plane *plane,
  35. - struct drm_plane_state *state)
  36. +static int vc4_plane_setup_clipping_and_scaling(struct drm_plane_state *state)
  37. {
  38. struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
  39. struct drm_framebuffer *fb = state->fb;
  40. - struct drm_gem_cma_object *bo = drm_fb_cma_get_gem_obj(fb, 0);
  41. - u32 ctl0_offset = vc4_state->dlist_count;
  42. - const struct hvs_format *format = vc4_get_hvs_format(fb->pixel_format);
  43. - uint32_t offset = fb->offsets[0];
  44. - int crtc_x = state->crtc_x;
  45. - int crtc_y = state->crtc_y;
  46. - int crtc_w = state->crtc_w;
  47. - int crtc_h = state->crtc_h;
  48. +
  49. + vc4_state->offset = fb->offsets[0];
  50. +
  51. + vc4_state->crtc_x = state->crtc_x;
  52. + vc4_state->crtc_y = state->crtc_y;
  53. + vc4_state->crtc_w = state->crtc_w;
  54. + vc4_state->crtc_h = state->crtc_h;
  55. if (state->crtc_w << 16 != state->src_w ||
  56. state->crtc_h << 16 != state->src_h) {
  57. @@ -194,18 +197,41 @@ static int vc4_plane_mode_set(struct drm
  58. return -EINVAL;
  59. }
  60. - if (crtc_x < 0) {
  61. - offset += drm_format_plane_cpp(fb->pixel_format, 0) * -crtc_x;
  62. - crtc_w += crtc_x;
  63. - crtc_x = 0;
  64. + if (vc4_state->crtc_x < 0) {
  65. + vc4_state->offset += (drm_format_plane_cpp(fb->pixel_format,
  66. + 0) *
  67. + -vc4_state->crtc_x);
  68. + vc4_state->crtc_w += vc4_state->crtc_x;
  69. + vc4_state->crtc_x = 0;
  70. }
  71. - if (crtc_y < 0) {
  72. - offset += fb->pitches[0] * -crtc_y;
  73. - crtc_h += crtc_y;
  74. - crtc_y = 0;
  75. + if (vc4_state->crtc_y < 0) {
  76. + vc4_state->offset += fb->pitches[0] * -vc4_state->crtc_y;
  77. + vc4_state->crtc_h += vc4_state->crtc_y;
  78. + vc4_state->crtc_y = 0;
  79. }
  80. + return 0;
  81. +}
  82. +
  83. +
  84. +/* Writes out a full display list for an active plane to the plane's
  85. + * private dlist state.
  86. + */
  87. +static int vc4_plane_mode_set(struct drm_plane *plane,
  88. + struct drm_plane_state *state)
  89. +{
  90. + struct vc4_plane_state *vc4_state = to_vc4_plane_state(state);
  91. + struct drm_framebuffer *fb = state->fb;
  92. + struct drm_gem_cma_object *bo = drm_fb_cma_get_gem_obj(fb, 0);
  93. + u32 ctl0_offset = vc4_state->dlist_count;
  94. + const struct hvs_format *format = vc4_get_hvs_format(fb->pixel_format);
  95. + int ret;
  96. +
  97. + ret = vc4_plane_setup_clipping_and_scaling(state);
  98. + if (ret)
  99. + return ret;
  100. +
  101. vc4_dlist_write(vc4_state,
  102. SCALER_CTL0_VALID |
  103. (format->pixel_order << SCALER_CTL0_ORDER_SHIFT) |
  104. @@ -215,8 +241,8 @@ static int vc4_plane_mode_set(struct drm
  105. /* Position Word 0: Image Positions and Alpha Value */
  106. vc4_dlist_write(vc4_state,
  107. VC4_SET_FIELD(0xff, SCALER_POS0_FIXED_ALPHA) |
  108. - VC4_SET_FIELD(crtc_x, SCALER_POS0_START_X) |
  109. - VC4_SET_FIELD(crtc_y, SCALER_POS0_START_Y));
  110. + VC4_SET_FIELD(vc4_state->crtc_x, SCALER_POS0_START_X) |
  111. + VC4_SET_FIELD(vc4_state->crtc_y, SCALER_POS0_START_Y));
  112. /* Position Word 1: Scaled Image Dimensions.
  113. * Skipped due to SCALER_CTL0_UNITY scaling.
  114. @@ -228,8 +254,8 @@ static int vc4_plane_mode_set(struct drm
  115. SCALER_POS2_ALPHA_MODE_PIPELINE :
  116. SCALER_POS2_ALPHA_MODE_FIXED,
  117. SCALER_POS2_ALPHA_MODE) |
  118. - VC4_SET_FIELD(crtc_w, SCALER_POS2_WIDTH) |
  119. - VC4_SET_FIELD(crtc_h, SCALER_POS2_HEIGHT));
  120. + VC4_SET_FIELD(vc4_state->crtc_w, SCALER_POS2_WIDTH) |
  121. + VC4_SET_FIELD(vc4_state->crtc_h, SCALER_POS2_HEIGHT));
  122. /* Position Word 3: Context. Written by the HVS. */
  123. vc4_dlist_write(vc4_state, 0xc0c0c0c0);
  124. @@ -237,7 +263,7 @@ static int vc4_plane_mode_set(struct drm
  125. vc4_state->pw0_offset = vc4_state->dlist_count;
  126. /* Pointer Word 0: RGB / Y Pointer */
  127. - vc4_dlist_write(vc4_state, bo->paddr + offset);
  128. + vc4_dlist_write(vc4_state, bo->paddr + vc4_state->offset);
  129. /* Pointer Context Word 0: Written by the HVS */
  130. vc4_dlist_write(vc4_state, 0xc0c0c0c0);