Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: Pass the full state to connectors atomic functions

The current atomic helpers have either their object state being passed as
an argument or the full atomic state.

The former is the pattern that was done at first, before switching to the
latter for new hooks or when it was needed.

Now that the CRTCs have been converted, let's move forward with the
connectors to provide a consistent interface.

The conversion was done using the coccinelle script below, and built tested
on all the drivers.

@@
identifier connector, connector_state;
@@

struct drm_connector_helper_funcs {
...
struct drm_encoder* (*atomic_best_encoder)(struct drm_connector *connector,
- struct drm_connector_state *connector_state);
+ struct drm_atomic_state *state);
...
}

@@
identifier connector, connector_state;
@@

struct drm_connector_helper_funcs {
...
void (*atomic_commit)(struct drm_connector *connector,
- struct drm_connector_state *connector_state);
+ struct drm_atomic_state *state);
...
}

@@
struct drm_connector_helper_funcs *FUNCS;
identifier state;
identifier connector, connector_state;
identifier f;
@@

f(..., struct drm_atomic_state *state, ...)
{
<+...
- FUNCS->atomic_commit(connector, connector_state);
+ FUNCS->atomic_commit(connector, state);
...+>
}

@@
struct drm_connector_helper_funcs *FUNCS;
identifier state;
identifier connector, connector_state;
identifier var, f;
@@

f(struct drm_atomic_state *state, ...)
{
<+...
- var = FUNCS->atomic_best_encoder(connector, connector_state);
+ var = FUNCS->atomic_best_encoder(connector, state);
...+>
}

@ connector_atomic_func @
identifier helpers;
identifier func;
@@

(
static struct drm_connector_helper_funcs helpers = {
...,
.atomic_best_encoder = func,
...,
};
|
static struct drm_connector_helper_funcs helpers = {
...,
.atomic_commit = func,
...,
};
)

@@
identifier connector_atomic_func.func;
identifier connector;
symbol state;
@@

func(struct drm_connector *connector,
- struct drm_connector_state *state
+ struct drm_connector_state *connector_state
)
{
...
- state
+ connector_state
...
}

@ ignores_state @
identifier connector_atomic_func.func;
identifier connector, connector_state;
@@

func(struct drm_connector *connector,
struct drm_connector_state *connector_state)
{
... when != connector_state
}

@ adds_state depends on connector_atomic_func && !ignores_state @
identifier connector_atomic_func.func;
identifier connector, connector_state;
@@

func(struct drm_connector *connector, struct drm_connector_state *connector_state)
{
+ struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state, connector);
...
}

@ depends on connector_atomic_func @
identifier connector_atomic_func.func;
identifier connector_state;
identifier connector;
@@

func(struct drm_connector *connector,
- struct drm_connector_state *connector_state
+ struct drm_atomic_state *state
)
{ ... }

@ include depends on adds_state @
@@

#include <drm/drm_atomic.h>

@ no_include depends on !include && adds_state @
@@

+ #include <drm/drm_atomic.h>
#include <drm/...>

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Reviewed-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Harry Wentland <harry.wentland@amd.com>
Cc: Leo Li <sunpeng.li@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: "Christian König" <christian.koenig@amd.com>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Cc: Melissa Wen <melissa.srw@gmail.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20201118094758.506730-1-maxime@cerno.tech

+31 -18
+4 -1
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
··· 24 24 */ 25 25 26 26 #include <linux/version.h> 27 + #include <drm/drm_atomic.h> 27 28 #include <drm/drm_atomic_helper.h> 28 29 #include <drm/drm_dp_mst_helper.h> 29 30 #include <drm/drm_dp_helper.h> ··· 253 252 254 253 static struct drm_encoder * 255 254 dm_mst_atomic_best_encoder(struct drm_connector *connector, 256 - struct drm_connector_state *connector_state) 255 + struct drm_atomic_state *state) 257 256 { 257 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state, 258 + connector); 258 259 struct drm_device *dev = connector->dev; 259 260 struct amdgpu_device *adev = drm_to_adev(dev); 260 261 struct amdgpu_crtc *acrtc = to_amdgpu_crtc(connector_state->crtc);
+4 -4
drivers/gpu/drm/drm_atomic_helper.c
··· 122 122 continue; 123 123 124 124 if (funcs->atomic_best_encoder) 125 - new_encoder = funcs->atomic_best_encoder(connector, new_conn_state); 125 + new_encoder = funcs->atomic_best_encoder(connector, 126 + state); 126 127 else if (funcs->best_encoder) 127 128 new_encoder = funcs->best_encoder(connector); 128 129 else ··· 346 345 funcs = connector->helper_private; 347 346 348 347 if (funcs->atomic_best_encoder) 349 - new_encoder = funcs->atomic_best_encoder(connector, 350 - new_connector_state); 348 + new_encoder = funcs->atomic_best_encoder(connector, state); 351 349 else if (funcs->best_encoder) 352 350 new_encoder = funcs->best_encoder(connector); 353 351 else ··· 1313 1313 1314 1314 if (new_conn_state->writeback_job && new_conn_state->writeback_job->fb) { 1315 1315 WARN_ON(connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK); 1316 - funcs->atomic_commit(connector, new_conn_state); 1316 + funcs->atomic_commit(connector, old_state); 1317 1317 } 1318 1318 } 1319 1319 }
+5 -2
drivers/gpu/drm/i915/display/intel_dp_mst.c
··· 23 23 * 24 24 */ 25 25 26 + #include <drm/drm_atomic.h> 26 27 #include <drm/drm_atomic_helper.h> 27 28 #include <drm/drm_edid.h> 28 29 #include <drm/drm_probe_helper.h> ··· 720 719 } 721 720 722 721 static struct drm_encoder *intel_mst_atomic_best_encoder(struct drm_connector *connector, 723 - struct drm_connector_state *state) 722 + struct drm_atomic_state *state) 724 723 { 724 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state, 725 + connector); 725 726 struct intel_connector *intel_connector = to_intel_connector(connector); 726 727 struct intel_dp *intel_dp = intel_connector->mst_port; 727 - struct intel_crtc *crtc = to_intel_crtc(state->crtc); 728 + struct intel_crtc *crtc = to_intel_crtc(connector_state->crtc); 728 729 729 730 return &intel_dp->mst_encoders[crtc->pipe]->base.base; 730 731 }
+4 -1
drivers/gpu/drm/nouveau/dispnv50/disp.c
··· 32 32 #include <linux/hdmi.h> 33 33 #include <linux/component.h> 34 34 35 + #include <drm/drm_atomic.h> 35 36 #include <drm/drm_atomic_helper.h> 36 37 #include <drm/drm_dp_helper.h> 37 38 #include <drm/drm_edid.h> ··· 1162 1161 1163 1162 static struct drm_encoder * 1164 1163 nv50_mstc_atomic_best_encoder(struct drm_connector *connector, 1165 - struct drm_connector_state *connector_state) 1164 + struct drm_atomic_state *state) 1166 1165 { 1166 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state, 1167 + connector); 1167 1168 struct nv50_mstc *mstc = nv50_mstc(connector); 1168 1169 struct drm_crtc *crtc = connector_state->crtc; 1169 1170
+3 -1
drivers/gpu/drm/vc4/vc4_txp.c
··· 273 273 } 274 274 275 275 static void vc4_txp_connector_atomic_commit(struct drm_connector *conn, 276 - struct drm_connector_state *conn_state) 276 + struct drm_atomic_state *state) 277 277 { 278 + struct drm_connector_state *conn_state = drm_atomic_get_new_connector_state(state, 279 + conn); 278 280 struct vc4_txp *txp = connector_to_vc4_txp(conn); 279 281 struct drm_gem_cma_object *gem; 280 282 struct drm_display_mode *mode;
+5 -2
drivers/gpu/drm/vkms/vkms_writeback.c
··· 2 2 3 3 #include <linux/dma-buf-map.h> 4 4 5 + #include <drm/drm_atomic.h> 5 6 #include <drm/drm_fourcc.h> 6 7 #include <drm/drm_writeback.h> 7 8 #include <drm/drm_probe_helper.h> ··· 106 105 } 107 106 108 107 static void vkms_wb_atomic_commit(struct drm_connector *conn, 109 - struct drm_connector_state *state) 108 + struct drm_atomic_state *state) 110 109 { 110 + struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state, 111 + conn); 111 112 struct vkms_device *vkmsdev = drm_device_to_vkms_device(conn->dev); 112 113 struct vkms_output *output = &vkmsdev->output; 113 114 struct drm_writeback_connector *wb_conn = &output->wb_connector; ··· 125 122 crtc_state->active_writeback = conn_state->writeback_job->priv; 126 123 crtc_state->wb_pending = true; 127 124 spin_unlock_irq(&output->composer_lock); 128 - drm_writeback_queue_job(wb_conn, state); 125 + drm_writeback_queue_job(wb_conn, connector_state); 129 126 } 130 127 131 128 static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = {
+6 -7
include/drm/drm_modeset_helper_vtables.h
··· 1044 1044 * NOTE: 1045 1045 * 1046 1046 * This function is called in the check phase of an atomic update. The 1047 - * driver is not allowed to change anything outside of the free-standing 1048 - * state objects passed-in or assembled in the overall &drm_atomic_state 1049 - * update tracking structure. 1047 + * driver is not allowed to change anything outside of the 1048 + * &drm_atomic_state update tracking structure passed in. 1050 1049 * 1051 1050 * RETURNS: 1052 1051 * ··· 1055 1056 * for this. 1056 1057 */ 1057 1058 struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector, 1058 - struct drm_connector_state *connector_state); 1059 + struct drm_atomic_state *state); 1059 1060 1060 1061 /** 1061 1062 * @atomic_check: ··· 1096 1097 * 1097 1098 * This hook is to be used by drivers implementing writeback connectors 1098 1099 * that need a point when to commit the writeback job to the hardware. 1099 - * The writeback_job to commit is available in 1100 - * &drm_connector_state.writeback_job. 1100 + * The writeback_job to commit is available in the new connector state, 1101 + * in &drm_connector_state.writeback_job. 1101 1102 * 1102 1103 * This hook is optional. 1103 1104 * 1104 1105 * This callback is used by the atomic modeset helpers. 1105 1106 */ 1106 1107 void (*atomic_commit)(struct drm_connector *connector, 1107 - struct drm_connector_state *state); 1108 + struct drm_atomic_state *state); 1108 1109 1109 1110 /** 1110 1111 * @prepare_writeback_job: