0b736988056ca0f5afe60ef07a038cc3a9347c62
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.10 / 950-0598-drm-vc4-crtc-Fix-vc4_get_crtc_encoder-logic.patch
1 From bc75a1ca95c195508c7d9238a9dc31218ead3ad1 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Thu, 6 May 2021 17:07:07 +0200
4 Subject: [PATCH] drm/vc4: crtc: Fix vc4_get_crtc_encoder logic
5
6 The vc4_get_crtc_encoder function currently only works when the
7 connector->state->crtc pointer is set, which is only true when the
8 connector is currently enabled.
9
10 However, we use it as part of the disable path as well, and our lookup
11 will fail in that case, resulting in it returning a null pointer we
12 can't act on.
13
14 We can access the connector that used to be connected to that crtc
15 though using the old connector state in the disable path.
16
17 Since we want to support both the enable and disable path, we can
18 support it by passing the state accessor variant as a function pointer,
19 together with the atomic state.
20
21 Fixes: 792c3132bc1b ("drm/vc4: encoder: Add finer-grained encoder callbacks")
22 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
23 ---
24 drivers/gpu/drm/vc4/vc4_crtc.c | 21 ++++++++++++++++-----
25 1 file changed, 16 insertions(+), 5 deletions(-)
26
27 --- a/drivers/gpu/drm/vc4/vc4_crtc.c
28 +++ b/drivers/gpu/drm/vc4/vc4_crtc.c
29 @@ -279,14 +279,22 @@ static u32 vc4_crtc_get_fifo_full_level_
30 * allows drivers to push pixels to more than one encoder from the
31 * same CRTC.
32 */
33 -static struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc)
34 +static struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc,
35 + struct drm_atomic_state *state,
36 + struct drm_connector_state *(*get_state)(struct drm_atomic_state *state,
37 + struct drm_connector *connector))
38 {
39 struct drm_connector *connector;
40 struct drm_connector_list_iter conn_iter;
41
42 drm_connector_list_iter_begin(crtc->dev, &conn_iter);
43 drm_for_each_connector_iter(connector, &conn_iter) {
44 - if (connector->state->crtc == crtc) {
45 + struct drm_connector_state *conn_state = get_state(state, connector);
46 +
47 + if (!conn_state)
48 + continue;
49 +
50 + if (conn_state->crtc == crtc) {
51 drm_connector_list_iter_end(&conn_iter);
52 return connector->encoder;
53 }
54 @@ -309,7 +317,8 @@ static void vc4_crtc_config_pv(struct dr
55 {
56 struct drm_device *dev = crtc->dev;
57 struct vc4_dev *vc4 = to_vc4_dev(dev);
58 - struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc);
59 + struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc, state,
60 + drm_atomic_get_new_connector_state);
61 struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder);
62 struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
63 const struct vc4_pv_data *pv_data = vc4_crtc_to_vc4_pv_data(vc4_crtc);
64 @@ -425,7 +434,8 @@ static int vc4_crtc_disable(struct drm_c
65 struct drm_atomic_state *state,
66 unsigned int channel)
67 {
68 - struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc);
69 + struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc, state,
70 + drm_atomic_get_old_connector_state);
71 struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder);
72 struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
73 struct drm_device *dev = crtc->dev;
74 @@ -525,7 +535,8 @@ static void vc4_crtc_atomic_enable(struc
75 {
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);
79 + struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc, state,
80 + drm_atomic_get_new_connector_state);
81 struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder);
82
83 require_hvs_enabled(dev);