8d62659ff0f9188acd9d63bee36a6e8c29520315
[openwrt/staging/ansuel.git] /
1 From 05d10aebe62239b014098c8e517dd96848f9a495 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Wed, 18 Nov 2020 10:47:58 +0100
4 Subject: [PATCH] drm: Pass the full state to connectors atomic
5 functions
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 The current atomic helpers have either their object state being passed as
11 an argument or the full atomic state.
12
13 The former is the pattern that was done at first, before switching to the
14 latter for new hooks or when it was needed.
15
16 Now that the CRTCs have been converted, let's move forward with the
17 connectors to provide a consistent interface.
18
19 The conversion was done using the coccinelle script below, and built tested
20 on all the drivers.
21
22 @@
23 identifier connector, connector_state;
24 @@
25
26 struct drm_connector_helper_funcs {
27 ...
28 struct drm_encoder* (*atomic_best_encoder)(struct drm_connector *connector,
29 - struct drm_connector_state *connector_state);
30 + struct drm_atomic_state *state);
31 ...
32 }
33
34 @@
35 identifier connector, connector_state;
36 @@
37
38 struct drm_connector_helper_funcs {
39 ...
40 void (*atomic_commit)(struct drm_connector *connector,
41 - struct drm_connector_state *connector_state);
42 + struct drm_atomic_state *state);
43 ...
44 }
45
46 @@
47 struct drm_connector_helper_funcs *FUNCS;
48 identifier state;
49 identifier connector, connector_state;
50 identifier f;
51 @@
52
53 f(..., struct drm_atomic_state *state, ...)
54 {
55 <+...
56 - FUNCS->atomic_commit(connector, connector_state);
57 + FUNCS->atomic_commit(connector, state);
58 ...+>
59 }
60
61 @@
62 struct drm_connector_helper_funcs *FUNCS;
63 identifier state;
64 identifier connector, connector_state;
65 identifier var, f;
66 @@
67
68 f(struct drm_atomic_state *state, ...)
69 {
70 <+...
71 - var = FUNCS->atomic_best_encoder(connector, connector_state);
72 + var = FUNCS->atomic_best_encoder(connector, state);
73 ...+>
74 }
75
76 @ connector_atomic_func @
77 identifier helpers;
78 identifier func;
79 @@
80
81 (
82 static struct drm_connector_helper_funcs helpers = {
83 ...,
84 .atomic_best_encoder = func,
85 ...,
86 };
87 |
88 static struct drm_connector_helper_funcs helpers = {
89 ...,
90 .atomic_commit = func,
91 ...,
92 };
93 )
94
95 @@
96 identifier connector_atomic_func.func;
97 identifier connector;
98 symbol state;
99 @@
100
101 func(struct drm_connector *connector,
102 - struct drm_connector_state *state
103 + struct drm_connector_state *connector_state
104 )
105 {
106 ...
107 - state
108 + connector_state
109 ...
110 }
111
112 @ ignores_state @
113 identifier connector_atomic_func.func;
114 identifier connector, connector_state;
115 @@
116
117 func(struct drm_connector *connector,
118 struct drm_connector_state *connector_state)
119 {
120 ... when != connector_state
121 }
122
123 @ adds_state depends on connector_atomic_func && !ignores_state @
124 identifier connector_atomic_func.func;
125 identifier connector, connector_state;
126 @@
127
128 func(struct drm_connector *connector, struct drm_connector_state *connector_state)
129 {
130 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state, connector);
131 ...
132 }
133
134 @ depends on connector_atomic_func @
135 identifier connector_atomic_func.func;
136 identifier connector_state;
137 identifier connector;
138 @@
139
140 func(struct drm_connector *connector,
141 - struct drm_connector_state *connector_state
142 + struct drm_atomic_state *state
143 )
144 { ... }
145
146 @ include depends on adds_state @
147 @@
148
149 #include <drm/drm_atomic.h>
150
151 @ no_include depends on !include && adds_state @
152 @@
153
154 + #include <drm/drm_atomic.h>
155 #include <drm/...>
156
157 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
158 Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
159 Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
160 Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
161 Acked-by: Harry Wentland <harry.wentland@amd.com>
162 Cc: Leo Li <sunpeng.li@amd.com>
163 Cc: Alex Deucher <alexander.deucher@amd.com>
164 Cc: "Christian König" <christian.koenig@amd.com>
165 Cc: Jani Nikula <jani.nikula@linux.intel.com>
166 Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
167 Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
168 Cc: Ben Skeggs <bskeggs@redhat.com>
169 Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
170 Cc: Melissa Wen <melissa.srw@gmail.com>
171 Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
172 Link: https://patchwork.freedesktop.org/patch/msgid/20201118094758.506730-1-maxime@cerno.tech
173 ---
174 .../drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c | 5 ++++-
175 drivers/gpu/drm/drm_atomic_helper.c | 8 ++++----
176 drivers/gpu/drm/i915/display/intel_dp_mst.c | 7 +++++--
177 drivers/gpu/drm/nouveau/dispnv50/disp.c | 5 ++++-
178 drivers/gpu/drm/vc4/vc4_txp.c | 4 +++-
179 drivers/gpu/drm/vkms/vkms_writeback.c | 8 ++++++--
180 include/drm/drm_modeset_helper_vtables.h | 13 ++++++-------
181 7 files changed, 32 insertions(+), 18 deletions(-)
182
183 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
184 +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
185 @@ -24,6 +24,7 @@
186 */
187
188 #include <linux/version.h>
189 +#include <drm/drm_atomic.h>
190 #include <drm/drm_atomic_helper.h>
191 #include <drm/drm_dp_mst_helper.h>
192 #include <drm/drm_dp_helper.h>
193 @@ -252,8 +253,10 @@ static int dm_dp_mst_get_modes(struct dr
194
195 static struct drm_encoder *
196 dm_mst_atomic_best_encoder(struct drm_connector *connector,
197 - struct drm_connector_state *connector_state)
198 + struct drm_atomic_state *state)
199 {
200 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
201 + connector);
202 struct drm_device *dev = connector->dev;
203 struct amdgpu_device *adev = drm_to_adev(dev);
204 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(connector_state->crtc);
205 --- a/drivers/gpu/drm/drm_atomic_helper.c
206 +++ b/drivers/gpu/drm/drm_atomic_helper.c
207 @@ -122,7 +122,8 @@ static int handle_conflicting_encoders(s
208 continue;
209
210 if (funcs->atomic_best_encoder)
211 - new_encoder = funcs->atomic_best_encoder(connector, new_conn_state);
212 + new_encoder = funcs->atomic_best_encoder(connector,
213 + state);
214 else if (funcs->best_encoder)
215 new_encoder = funcs->best_encoder(connector);
216 else
217 @@ -345,8 +346,7 @@ update_connector_routing(struct drm_atom
218 funcs = connector->helper_private;
219
220 if (funcs->atomic_best_encoder)
221 - new_encoder = funcs->atomic_best_encoder(connector,
222 - new_connector_state);
223 + new_encoder = funcs->atomic_best_encoder(connector, state);
224 else if (funcs->best_encoder)
225 new_encoder = funcs->best_encoder(connector);
226 else
227 @@ -1318,7 +1318,7 @@ static void drm_atomic_helper_commit_wri
228
229 if (new_conn_state->writeback_job && new_conn_state->writeback_job->fb) {
230 WARN_ON(connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK);
231 - funcs->atomic_commit(connector, new_conn_state);
232 + funcs->atomic_commit(connector, old_state);
233 }
234 }
235 }
236 --- a/drivers/gpu/drm/i915/display/intel_dp_mst.c
237 +++ b/drivers/gpu/drm/i915/display/intel_dp_mst.c
238 @@ -23,6 +23,7 @@
239 *
240 */
241
242 +#include <drm/drm_atomic.h>
243 #include <drm/drm_atomic_helper.h>
244 #include <drm/drm_edid.h>
245 #include <drm/drm_probe_helper.h>
246 @@ -708,11 +709,13 @@ intel_dp_mst_mode_valid_ctx(struct drm_c
247 }
248
249 static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector,
250 - struct drm_connector_state *state)
251 + struct drm_atomic_state *state)
252 {
253 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
254 + connector);
255 struct intel_connector *intel_connector = to_intel_connector(connector);
256 struct intel_dp *intel_dp = intel_connector->mst_port;
257 - struct intel_crtc *crtc = to_intel_crtc(state->crtc);
258 + struct intel_crtc *crtc = to_intel_crtc(connector_state->crtc);
259
260 return &intel_dp->mst_encoders[crtc->pipe]->base.base;
261 }
262 --- a/drivers/gpu/drm/nouveau/dispnv50/disp.c
263 +++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c
264 @@ -32,6 +32,7 @@
265 #include <linux/hdmi.h>
266 #include <linux/component.h>
267
268 +#include <drm/drm_atomic.h>
269 #include <drm/drm_atomic_helper.h>
270 #include <drm/drm_dp_helper.h>
271 #include <drm/drm_edid.h>
272 @@ -1161,8 +1162,10 @@ nv50_msto_new(struct drm_device *dev, st
273
274 static struct drm_encoder *
275 nv50_mstc_atomic_best_encoder(struct drm_connector *connector,
276 - struct drm_connector_state *connector_state)
277 + struct drm_atomic_state *state)
278 {
279 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
280 + connector);
281 struct nv50_mstc *mstc = nv50_mstc(connector);
282 struct drm_crtc *crtc = connector_state->crtc;
283
284 --- a/drivers/gpu/drm/vc4/vc4_txp.c
285 +++ b/drivers/gpu/drm/vc4/vc4_txp.c
286 @@ -273,8 +273,10 @@ static int vc4_txp_connector_atomic_chec
287 }
288
289 static void vc4_txp_connector_atomic_commit(struct drm_connector *conn,
290 - struct drm_connector_state *conn_state)
291 + struct drm_atomic_state *state)
292 {
293 + struct drm_connector_state *conn_state = drm_atomic_get_new_connector_state(state,
294 + conn);
295 struct vc4_txp *txp = connector_to_vc4_txp(conn);
296 struct drm_gem_cma_object *gem;
297 struct drm_display_mode *mode;
298 --- a/drivers/gpu/drm/vkms/vkms_writeback.c
299 +++ b/drivers/gpu/drm/vkms/vkms_writeback.c
300 @@ -1,6 +1,8 @@
301 // SPDX-License-Identifier: GPL-2.0+
302
303 #include "vkms_drv.h"
304 +
305 +#include <drm/drm_atomic.h>
306 #include <drm/drm_fourcc.h>
307 #include <drm/drm_writeback.h>
308 #include <drm/drm_probe_helper.h>
309 @@ -100,8 +102,10 @@ static void vkms_wb_cleanup_job(struct d
310 }
311
312 static void vkms_wb_atomic_commit(struct drm_connector *conn,
313 - struct drm_connector_state *state)
314 + struct drm_atomic_state *state)
315 {
316 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
317 + conn);
318 struct vkms_device *vkmsdev = drm_device_to_vkms_device(conn->dev);
319 struct vkms_output *output = &vkmsdev->output;
320 struct drm_writeback_connector *wb_conn = &output->wb_connector;
321 @@ -117,7 +121,7 @@ static void vkms_wb_atomic_commit(struct
322 crtc_state->active_writeback = conn_state->writeback_job->priv;
323 crtc_state->wb_pending = true;
324 spin_unlock_irq(&output->composer_lock);
325 - drm_writeback_queue_job(wb_conn, state);
326 + drm_writeback_queue_job(wb_conn, connector_state);
327 }
328
329 static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = {
330 --- a/include/drm/drm_modeset_helper_vtables.h
331 +++ b/include/drm/drm_modeset_helper_vtables.h
332 @@ -1044,9 +1044,8 @@ struct drm_connector_helper_funcs {
333 * NOTE:
334 *
335 * This function is called in the check phase of an atomic update. The
336 - * driver is not allowed to change anything outside of the free-standing
337 - * state objects passed-in or assembled in the overall &drm_atomic_state
338 - * update tracking structure.
339 + * driver is not allowed to change anything outside of the
340 + * &drm_atomic_state update tracking structure passed in.
341 *
342 * RETURNS:
343 *
344 @@ -1056,7 +1055,7 @@ struct drm_connector_helper_funcs {
345 * for this.
346 */
347 struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
348 - struct drm_connector_state *connector_state);
349 + struct drm_atomic_state *state);
350
351 /**
352 * @atomic_check:
353 @@ -1097,15 +1096,15 @@ struct drm_connector_helper_funcs {
354 *
355 * This hook is to be used by drivers implementing writeback connectors
356 * that need a point when to commit the writeback job to the hardware.
357 - * The writeback_job to commit is available in
358 - * &drm_connector_state.writeback_job.
359 + * The writeback_job to commit is available in the new connector state,
360 + * in &drm_connector_state.writeback_job.
361 *
362 * This hook is optional.
363 *
364 * This callback is used by the atomic modeset helpers.
365 */
366 void (*atomic_commit)(struct drm_connector *connector,
367 - struct drm_connector_state *state);
368 + struct drm_atomic_state *state);
369
370 /**
371 * @prepare_writeback_job: