2
0

950-0015-drm-vc4-crtc-Rework-the-encoder-retrieval-code-again.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From 0496e855a6e1acd60d4ae2e52ee906a4cffae014 Mon Sep 17 00:00:00 2001
  2. From: Maxime Ripard <[email protected]>
  3. Date: Mon, 21 Jun 2021 16:07:22 +0200
  4. Subject: [PATCH] drm/vc4: crtc: Rework the encoder retrieval code
  5. (again)
  6. It turns out the encoder retrieval code, in addition to being
  7. unnecessarily complicated, has a bug when only the planes and crtcs are
  8. affected by a given atomic commit.
  9. Indeed, in such a case, either drm_atomic_get_old_connector_state or
  10. drm_atomic_get_new_connector_state will return NULL and thus our encoder
  11. retrieval code will not match on anything.
  12. We can however simplify the code by using drm_for_each_encoder_mask, the
  13. drm_crtc_state storing the encoders a given CRTC is connected to
  14. directly and without relying on any other state.
  15. Signed-off-by: Maxime Ripard <[email protected]>
  16. ---
  17. drivers/gpu/drm/vc4/vc4_crtc.c | 30 +++++++++---------------------
  18. drivers/gpu/drm/vc4/vc4_drv.h | 4 +---
  19. 2 files changed, 10 insertions(+), 24 deletions(-)
  20. --- a/drivers/gpu/drm/vc4/vc4_crtc.c
  21. +++ b/drivers/gpu/drm/vc4/vc4_crtc.c
  22. @@ -282,26 +282,14 @@ static u32 vc4_crtc_get_fifo_full_level_
  23. * same CRTC.
  24. */
  25. struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc,
  26. - struct drm_atomic_state *state,
  27. - struct drm_connector_state *(*get_state)(struct drm_atomic_state *state,
  28. - struct drm_connector *connector))
  29. + struct drm_crtc_state *state)
  30. {
  31. - struct drm_connector *connector;
  32. - struct drm_connector_list_iter conn_iter;
  33. + struct drm_encoder *encoder;
  34. - drm_connector_list_iter_begin(crtc->dev, &conn_iter);
  35. - drm_for_each_connector_iter(connector, &conn_iter) {
  36. - struct drm_connector_state *conn_state = get_state(state, connector);
  37. -
  38. - if (!conn_state)
  39. - continue;
  40. -
  41. - if (conn_state->crtc == crtc) {
  42. - drm_connector_list_iter_end(&conn_iter);
  43. - return connector->encoder;
  44. - }
  45. - }
  46. - drm_connector_list_iter_end(&conn_iter);
  47. + WARN_ON(hweight32(state->encoder_mask) > 1);
  48. +
  49. + drm_for_each_encoder_mask(encoder, crtc->dev, state->encoder_mask)
  50. + return encoder;
  51. return NULL;
  52. }
  53. @@ -554,8 +542,7 @@ static void vc4_crtc_atomic_disable(stru
  54. struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state,
  55. crtc);
  56. struct vc4_crtc_state *old_vc4_state = to_vc4_crtc_state(old_state);
  57. - struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc, state,
  58. - drm_atomic_get_old_connector_state);
  59. + struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc, old_state);
  60. struct drm_device *dev = crtc->dev;
  61. require_hvs_enabled(dev);
  62. @@ -582,10 +569,11 @@ static void vc4_crtc_atomic_disable(stru
  63. static void vc4_crtc_atomic_enable(struct drm_crtc *crtc,
  64. struct drm_atomic_state *state)
  65. {
  66. + struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state,
  67. + crtc);
  68. struct drm_device *dev = crtc->dev;
  69. struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
  70. - struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc, state,
  71. - drm_atomic_get_new_connector_state);
  72. + struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc, new_state);
  73. struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder);
  74. require_hvs_enabled(dev);
  75. --- a/drivers/gpu/drm/vc4/vc4_drv.h
  76. +++ b/drivers/gpu/drm/vc4/vc4_drv.h
  77. @@ -545,9 +545,7 @@ vc4_crtc_to_vc4_pv_data(const struct vc4
  78. }
  79. struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc,
  80. - struct drm_atomic_state *state,
  81. - struct drm_connector_state *(*get_state)(struct drm_atomic_state *state,
  82. - struct drm_connector *connector));
  83. + struct drm_crtc_state *state);
  84. struct vc4_crtc_state {
  85. struct drm_crtc_state base;