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

drm/probe_helper: Add drm_connector_helper_funcs.mode_valid_ctx

This is just an atomic version of mode_valid, which is intended to be
used for situations where a driver might need to check the atomic state
of objects other than the connector itself. One such example is with
MST, where the maximum possible bandwidth on a connector can change
dynamically irregardless of the display configuration.

Changes since v1:
* Use new drm logging functions
* Make some corrections in the mode_valid_ctx kdoc
* Return error codes or 0 from ->mode_valid_ctx() on fail, and store the
drm_mode_status in an additional function parameter
Changes since v2:
* Don't accidentally assign ret to mode->status on success, or we'll
squash legitimate mode validation results
* Don't forget to assign MODE_OK to status in drm_connector_mode_valid()
if we have no callbacks
* Drop leftover hunk in drm_modes.h around enum drm_mode_status
Changes since v3:
* s/return ret/return 0/ in drm_mode_validate_pipeline()
* Minor cleanup in drm_connector_mode_valid()

Tested-by: Imre Deak <imre.deak@intel.com>
Reviewed-by: Imre Deak <imre.deak@intel.com>
Cc: Lee Shawn C <shawn.c.lee@intel.com>
Signed-off-by: Lyude Paul <lyude@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200713170746.254388-2-lyude@redhat.com

+110 -34
+5 -2
drivers/gpu/drm/drm_crtc_helper_internal.h
··· 73 73 const struct drm_display_mode *mode); 74 74 enum drm_mode_status drm_encoder_mode_valid(struct drm_encoder *encoder, 75 75 const struct drm_display_mode *mode); 76 - enum drm_mode_status drm_connector_mode_valid(struct drm_connector *connector, 77 - struct drm_display_mode *mode); 76 + int 77 + drm_connector_mode_valid(struct drm_connector *connector, 78 + struct drm_display_mode *mode, 79 + struct drm_modeset_acquire_ctx *ctx, 80 + enum drm_mode_status *status); 78 81 79 82 struct drm_encoder * 80 83 drm_connector_get_single_encoder(struct drm_connector *connector);
+63 -32
drivers/gpu/drm/drm_probe_helper.c
··· 86 86 return MODE_OK; 87 87 } 88 88 89 - static enum drm_mode_status 89 + static int 90 90 drm_mode_validate_pipeline(struct drm_display_mode *mode, 91 - struct drm_connector *connector) 91 + struct drm_connector *connector, 92 + struct drm_modeset_acquire_ctx *ctx, 93 + enum drm_mode_status *status) 92 94 { 93 95 struct drm_device *dev = connector->dev; 94 - enum drm_mode_status ret = MODE_OK; 95 96 struct drm_encoder *encoder; 97 + int ret; 96 98 97 99 /* Step 1: Validate against connector */ 98 - ret = drm_connector_mode_valid(connector, mode); 99 - if (ret != MODE_OK) 100 + ret = drm_connector_mode_valid(connector, mode, ctx, status); 101 + if (ret || *status != MODE_OK) 100 102 return ret; 101 103 102 104 /* Step 2: Validate against encoders and crtcs */ ··· 106 104 struct drm_bridge *bridge; 107 105 struct drm_crtc *crtc; 108 106 109 - ret = drm_encoder_mode_valid(encoder, mode); 110 - if (ret != MODE_OK) { 107 + *status = drm_encoder_mode_valid(encoder, mode); 108 + if (*status != MODE_OK) { 111 109 /* No point in continuing for crtc check as this encoder 112 110 * will not accept the mode anyway. If all encoders 113 111 * reject the mode then, at exit, ret will not be ··· 116 114 } 117 115 118 116 bridge = drm_bridge_chain_get_first_bridge(encoder); 119 - ret = drm_bridge_chain_mode_valid(bridge, mode); 120 - if (ret != MODE_OK) { 117 + *status = drm_bridge_chain_mode_valid(bridge, mode); 118 + if (*status != MODE_OK) { 121 119 /* There is also no point in continuing for crtc check 122 120 * here. */ 123 121 continue; ··· 127 125 if (!drm_encoder_crtc_ok(encoder, crtc)) 128 126 continue; 129 127 130 - ret = drm_crtc_mode_valid(crtc, mode); 131 - if (ret == MODE_OK) { 128 + *status = drm_crtc_mode_valid(crtc, mode); 129 + if (*status == MODE_OK) { 132 130 /* If we get to this point there is at least 133 131 * one combination of encoder+crtc that works 134 132 * for this mode. Lets return now. */ 135 - return ret; 133 + return 0; 136 134 } 137 135 } 138 136 } 139 137 140 - return ret; 138 + return 0; 141 139 } 142 140 143 141 static int drm_helper_probe_add_cmdline_mode(struct drm_connector *connector) ··· 198 196 return encoder_funcs->mode_valid(encoder, mode); 199 197 } 200 198 201 - enum drm_mode_status drm_connector_mode_valid(struct drm_connector *connector, 202 - struct drm_display_mode *mode) 199 + int 200 + drm_connector_mode_valid(struct drm_connector *connector, 201 + struct drm_display_mode *mode, 202 + struct drm_modeset_acquire_ctx *ctx, 203 + enum drm_mode_status *status) 203 204 { 204 205 const struct drm_connector_helper_funcs *connector_funcs = 205 206 connector->helper_private; 207 + int ret = 0; 206 208 207 - if (!connector_funcs || !connector_funcs->mode_valid) 208 - return MODE_OK; 209 + if (!connector_funcs) 210 + *status = MODE_OK; 211 + else if (connector_funcs->mode_valid_ctx) 212 + ret = connector_funcs->mode_valid_ctx(connector, mode, ctx, 213 + status); 214 + else if (connector_funcs->mode_valid) 215 + *status = connector_funcs->mode_valid(connector, mode); 216 + else 217 + *status = MODE_OK; 209 218 210 - return connector_funcs->mode_valid(connector, mode); 219 + return ret; 211 220 } 212 221 213 222 #define DRM_OUTPUT_POLL_PERIOD (10*HZ) ··· 388 375 * (if specified) 389 376 * - drm_mode_validate_flag() checks the modes against basic connector 390 377 * capabilities (interlace_allowed,doublescan_allowed,stereo_allowed) 391 - * - the optional &drm_connector_helper_funcs.mode_valid helper can perform 392 - * driver and/or sink specific checks 378 + * - the optional &drm_connector_helper_funcs.mode_valid or 379 + * &drm_connector_helper_funcs.mode_valid_ctx helpers can perform driver 380 + * and/or sink specific checks 393 381 * - the optional &drm_crtc_helper_funcs.mode_valid, 394 382 * &drm_bridge_funcs.mode_valid and &drm_encoder_helper_funcs.mode_valid 395 383 * helpers can perform driver and/or source specific checks which are also ··· 521 507 mode_flags |= DRM_MODE_FLAG_3D_MASK; 522 508 523 509 list_for_each_entry(mode, &connector->modes, head) { 524 - if (mode->status == MODE_OK) 525 - mode->status = drm_mode_validate_driver(dev, mode); 510 + if (mode->status != MODE_OK) 511 + continue; 526 512 527 - if (mode->status == MODE_OK) 528 - mode->status = drm_mode_validate_size(mode, maxX, maxY); 513 + mode->status = drm_mode_validate_driver(dev, mode); 514 + if (mode->status != MODE_OK) 515 + continue; 529 516 530 - if (mode->status == MODE_OK) 531 - mode->status = drm_mode_validate_flag(mode, mode_flags); 517 + mode->status = drm_mode_validate_size(mode, maxX, maxY); 518 + if (mode->status != MODE_OK) 519 + continue; 532 520 533 - if (mode->status == MODE_OK) 534 - mode->status = drm_mode_validate_pipeline(mode, 535 - connector); 521 + mode->status = drm_mode_validate_flag(mode, mode_flags); 522 + if (mode->status != MODE_OK) 523 + continue; 536 524 537 - if (mode->status == MODE_OK) 538 - mode->status = drm_mode_validate_ycbcr420(mode, 539 - connector); 525 + ret = drm_mode_validate_pipeline(mode, connector, &ctx, 526 + &mode->status); 527 + if (ret) { 528 + drm_dbg_kms(dev, 529 + "drm_mode_validate_pipeline failed: %d\n", 530 + ret); 531 + 532 + if (drm_WARN_ON_ONCE(dev, ret != -EDEADLK)) { 533 + mode->status = MODE_ERROR; 534 + } else { 535 + drm_modeset_backoff(&ctx); 536 + goto retry; 537 + } 538 + } 539 + 540 + if (mode->status != MODE_OK) 541 + continue; 542 + mode->status = drm_mode_validate_ycbcr420(mode, connector); 540 543 } 541 544 542 545 prune:
+42
include/drm/drm_modeset_helper_vtables.h
··· 968 968 */ 969 969 enum drm_mode_status (*mode_valid)(struct drm_connector *connector, 970 970 struct drm_display_mode *mode); 971 + 972 + /** 973 + * @mode_valid_ctx: 974 + * 975 + * Callback to validate a mode for a connector, irrespective of the 976 + * specific display configuration. 977 + * 978 + * This callback is used by the probe helpers to filter the mode list 979 + * (which is usually derived from the EDID data block from the sink). 980 + * See e.g. drm_helper_probe_single_connector_modes(). 981 + * 982 + * This function is optional, and is the atomic version of 983 + * &drm_connector_helper_funcs.mode_valid. 984 + * 985 + * To allow for accessing the atomic state of modesetting objects, the 986 + * helper libraries always call this with ctx set to a valid context, 987 + * and &drm_mode_config.connection_mutex will always be locked with 988 + * the ctx parameter set to @ctx. This allows for taking additional 989 + * locks as required. 990 + * 991 + * Even though additional locks may be acquired, this callback is 992 + * still expected not to take any constraints into account which would 993 + * be influenced by the currently set display state - such constraints 994 + * should be handled in the driver's atomic check. For example, if a 995 + * connector shares display bandwidth with other connectors then it 996 + * would be ok to validate the minimum bandwidth requirement of a mode 997 + * against the maximum possible bandwidth of the connector. But it 998 + * wouldn't be ok to take the current bandwidth usage of other 999 + * connectors into account, as this would change depending on the 1000 + * display state. 1001 + * 1002 + * Returns: 1003 + * 0 if &drm_connector_helper_funcs.mode_valid_ctx succeeded and wrote 1004 + * the &enum drm_mode_status value to @status, or a negative error 1005 + * code otherwise. 1006 + * 1007 + */ 1008 + int (*mode_valid_ctx)(struct drm_connector *connector, 1009 + struct drm_display_mode *mode, 1010 + struct drm_modeset_acquire_ctx *ctx, 1011 + enum drm_mode_status *status); 1012 + 971 1013 /** 972 1014 * @best_encoder: 973 1015 *