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

drm/atomic: Add encoder_mask to crtc_state, v3.

This allows iteration over encoders without requiring connection_mutex.

Changes since v1:
- Add a set_best_encoder helper function and update encoder_mask inside
it.
Changes since v2:
- Relax the WARN_ON(!crtc), with explanation.
- Call set_best_encoder when connector is moved between crtc's.
- Add some paranoia to steal_encoder to prevent accidentally setting
best_encoder to NULL.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/56AA200A.6070501@linux.intel.com

authored by

Maarten Lankhorst and committed by
Daniel Vetter
e87a52b3 97a8df90

+55 -3
+50 -3
drivers/gpu/drm/drm_atomic_helper.c
··· 125 125 return NULL; 126 126 } 127 127 128 + static void 129 + set_best_encoder(struct drm_atomic_state *state, 130 + struct drm_connector_state *conn_state, 131 + struct drm_encoder *encoder) 132 + { 133 + struct drm_crtc_state *crtc_state; 134 + struct drm_crtc *crtc; 135 + 136 + if (conn_state->best_encoder) { 137 + /* Unset the encoder_mask in the old crtc state. */ 138 + crtc = conn_state->connector->state->crtc; 139 + 140 + /* A NULL crtc is an error here because we should have 141 + * duplicated a NULL best_encoder when crtc was NULL. 142 + * As an exception restoring duplicated atomic state 143 + * during resume is allowed, so don't warn when 144 + * best_encoder is equal to encoder we intend to set. 145 + */ 146 + WARN_ON(!crtc && encoder != conn_state->best_encoder); 147 + if (crtc) { 148 + crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); 149 + 150 + crtc_state->encoder_mask &= 151 + ~(1 << drm_encoder_index(conn_state->best_encoder)); 152 + } 153 + } 154 + 155 + if (encoder) { 156 + crtc = conn_state->crtc; 157 + WARN_ON(!crtc); 158 + if (crtc) { 159 + crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); 160 + 161 + crtc_state->encoder_mask |= 162 + 1 << drm_encoder_index(encoder); 163 + } 164 + } 165 + 166 + conn_state->best_encoder = encoder; 167 + } 168 + 128 169 static int 129 170 steal_encoder(struct drm_atomic_state *state, 130 171 struct drm_encoder *encoder, ··· 205 164 if (IS_ERR(connector_state)) 206 165 return PTR_ERR(connector_state); 207 166 208 - connector_state->best_encoder = NULL; 167 + if (connector_state->best_encoder != encoder) 168 + continue; 169 + 170 + set_best_encoder(state, connector_state, NULL); 209 171 } 210 172 211 173 return 0; ··· 256 212 connector->base.id, 257 213 connector->name); 258 214 259 - connector_state->best_encoder = NULL; 215 + set_best_encoder(state, connector_state, NULL); 260 216 261 217 return 0; 262 218 } ··· 285 241 } 286 242 287 243 if (new_encoder == connector_state->best_encoder) { 244 + set_best_encoder(state, connector_state, new_encoder); 245 + 288 246 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] keeps [ENCODER:%d:%s], now on [CRTC:%d:%s]\n", 289 247 connector->base.id, 290 248 connector->name, ··· 321 275 if (WARN_ON(!connector_state->crtc)) 322 276 return -EINVAL; 323 277 324 - connector_state->best_encoder = new_encoder; 278 + set_best_encoder(state, connector_state, new_encoder); 279 + 325 280 idx = drm_crtc_index(connector_state->crtc); 326 281 327 282 crtc_state = state->crtc_states[idx];
+3
drivers/gpu/drm/i915/intel_display.c
··· 15591 15591 crtc->base.state->active = crtc->active; 15592 15592 crtc->base.enabled = crtc->active; 15593 15593 crtc->base.state->connector_mask = 0; 15594 + crtc->base.state->encoder_mask = 0; 15594 15595 15595 15596 /* Because we only establish the connector -> encoder -> 15596 15597 * crtc links if something is active, this means the ··· 15831 15830 */ 15832 15831 encoder->base.crtc->state->connector_mask |= 15833 15832 1 << drm_connector_index(&connector->base); 15833 + encoder->base.crtc->state->encoder_mask |= 15834 + 1 << drm_encoder_index(&encoder->base); 15834 15835 } 15835 15836 15836 15837 } else {
+2
include/drm/drm_crtc.h
··· 307 307 * @connectors_changed: connectors to this crtc have been updated 308 308 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes 309 309 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors 310 + * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders 310 311 * @last_vblank_count: for helpers and drivers to capture the vblank of the 311 312 * update to ensure framebuffer cleanup isn't done too early 312 313 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings ··· 342 341 u32 plane_mask; 343 342 344 343 u32 connector_mask; 344 + u32 encoder_mask; 345 345 346 346 /* last_vblank_count: for vblank waits before cleanup */ 347 347 u32 last_vblank_count;