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