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
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 The current atomic helpers have either their object state being passed as
11 an argument or the full atomic state.
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.
16 Now that the CRTCs have been converted, let's move forward with the
17 connectors to provide a consistent interface.
19 The conversion was done using the coccinelle script below, and built tested
23 identifier connector, connector_state;
26 struct drm_connector_helper_funcs {
28 struct drm_encoder* (*atomic_best_encoder)(struct drm_connector *connector,
29 - struct drm_connector_state *connector_state);
30 + struct drm_atomic_state *state);
35 identifier connector, connector_state;
38 struct drm_connector_helper_funcs {
40 void (*atomic_commit)(struct drm_connector *connector,
41 - struct drm_connector_state *connector_state);
42 + struct drm_atomic_state *state);
47 struct drm_connector_helper_funcs *FUNCS;
49 identifier connector, connector_state;
53 f(..., struct drm_atomic_state *state, ...)
56 - FUNCS->atomic_commit(connector, connector_state);
57 + FUNCS->atomic_commit(connector, state);
62 struct drm_connector_helper_funcs *FUNCS;
64 identifier connector, connector_state;
68 f(struct drm_atomic_state *state, ...)
71 - var = FUNCS->atomic_best_encoder(connector, connector_state);
72 + var = FUNCS->atomic_best_encoder(connector, state);
76 @ connector_atomic_func @
82 static struct drm_connector_helper_funcs helpers = {
84 .atomic_best_encoder = func,
88 static struct drm_connector_helper_funcs helpers = {
90 .atomic_commit = func,
96 identifier connector_atomic_func.func;
101 func(struct drm_connector *connector,
102 - struct drm_connector_state *state
103 + struct drm_connector_state *connector_state
113 identifier connector_atomic_func.func;
114 identifier connector, connector_state;
117 func(struct drm_connector *connector,
118 struct drm_connector_state *connector_state)
120 ... when != connector_state
123 @ adds_state depends on connector_atomic_func && !ignores_state @
124 identifier connector_atomic_func.func;
125 identifier connector, connector_state;
128 func(struct drm_connector *connector, struct drm_connector_state *connector_state)
130 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state, connector);
134 @ depends on connector_atomic_func @
135 identifier connector_atomic_func.func;
136 identifier connector_state;
137 identifier connector;
140 func(struct drm_connector *connector,
141 - struct drm_connector_state *connector_state
142 + struct drm_atomic_state *state
146 @ include depends on adds_state @
149 #include <drm/drm_atomic.h>
151 @ no_include depends on !include && adds_state @
154 + #include <drm/drm_atomic.h>
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
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(-)
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
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 @@ -264,8 +265,10 @@ static int dm_dp_mst_get_modes(struct dr
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)
200 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
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
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,
214 else if (funcs->best_encoder)
215 new_encoder = funcs->best_encoder(connector);
217 @@ -345,8 +346,7 @@ update_connector_routing(struct drm_atom
218 funcs = connector->helper_private;
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);
227 @@ -1318,7 +1318,7 @@ static void drm_atomic_helper_commit_wri
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);
236 --- a/drivers/gpu/drm/i915/display/intel_dp_mst.c
237 +++ b/drivers/gpu/drm/i915/display/intel_dp_mst.c
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
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)
253 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
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);
260 return &intel_dp->mst_encoders[crtc->pipe]->base.base;
262 --- a/drivers/gpu/drm/nouveau/dispnv50/disp.c
263 +++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c
265 #include <linux/hdmi.h>
266 #include <linux/component.h>
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
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)
279 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
281 struct nv50_mstc *mstc = nv50_mstc(connector);
282 struct drm_crtc *crtc = connector_state->crtc;
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
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)
293 + struct drm_connector_state *conn_state = drm_atomic_get_new_connector_state(state,
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
301 // SPDX-License-Identifier: GPL-2.0+
303 #include "vkms_drv.h"
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
312 static void vkms_wb_atomic_commit(struct drm_connector *conn,
313 - struct drm_connector_state *state)
314 + struct drm_atomic_state *state)
316 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
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);
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 {
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.
344 @@ -1056,7 +1055,7 @@ struct drm_connector_helper_funcs {
347 struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
348 - struct drm_connector_state *connector_state);
349 + struct drm_atomic_state *state);
353 @@ -1097,15 +1096,15 @@ struct drm_connector_helper_funcs {
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.
362 * This hook is optional.
364 * This callback is used by the atomic modeset helpers.
366 void (*atomic_commit)(struct drm_connector *connector,
367 - struct drm_connector_state *state);
368 + struct drm_atomic_state *state);
371 * @prepare_writeback_job: