Skip to content

Commit 75a655e

Browse files
committed
drm/modes: Provide global mode_valid hook
Allow drivers to provide a device wide .mode_valid() hook in addition to the already existing crtc/encoder/bridge/connector hooks. This can be used to validate device/driver wide constraings without having to add those to the other hooks. And since we call this hook also for user modes later on in the modeset we don't have to worry about anything the hook has already rejected. I also have some further ideas for this hook. Eg. we could replace the drm_mode_set_crtcinfo(HALVE_V) call in drm_mode_convert_umode()/etc. with a driver specific variant via this hook. At least on i915 we would like to pass CRTC_STEREO_DOUBLE to that function instead, and then we could safely use the crtc_ timings in all our .mode_valid() hooks, which would allow us to reuse those hooks for validating the adjusted_mode during a modeset. v2: Fix the language fails in the kernel docs (Daniel) Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20171114183258.16976-10-ville.syrjala@linux.intel.com Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent b7245cc commit 75a655e

6 files changed

Lines changed: 53 additions & 19 deletions

File tree

‎drivers/gpu/drm/drm_atomic.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
390390

391391
if (blob) {
392392
if (blob->length != sizeof(struct drm_mode_modeinfo) ||
393-
drm_mode_convert_umode(&state->mode,
393+
drm_mode_convert_umode(state->crtc->dev, &state->mode,
394394
(const struct drm_mode_modeinfo *)
395395
blob->data))
396396
return -EINVAL;

‎drivers/gpu/drm/drm_crtc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
614614
goto out;
615615
}
616616

617-
ret = drm_mode_convert_umode(mode, &crtc_req->mode);
617+
ret = drm_mode_convert_umode(dev, mode, &crtc_req->mode);
618618
if (ret) {
619619
DRM_DEBUG_KMS("Invalid mode\n");
620620
goto out;

‎drivers/gpu/drm/drm_modes.c‎

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,17 +1023,7 @@ bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
10231023
}
10241024
EXPORT_SYMBOL(drm_mode_equal_no_clocks_no_stereo);
10251025

1026-
/**
1027-
* drm_mode_validate_basic - make sure the mode is somewhat sane
1028-
* @mode: mode to check
1029-
*
1030-
* Check that the mode timings are at least somewhat reasonable.
1031-
* Any hardware specific limits are left up for each driver to check.
1032-
*
1033-
* Returns:
1034-
* The mode status
1035-
*/
1036-
enum drm_mode_status
1026+
static enum drm_mode_status
10371027
drm_mode_validate_basic(const struct drm_display_mode *mode)
10381028
{
10391029
if (mode->type & ~DRM_MODE_TYPE_ALL)
@@ -1062,7 +1052,35 @@ drm_mode_validate_basic(const struct drm_display_mode *mode)
10621052

10631053
return MODE_OK;
10641054
}
1065-
EXPORT_SYMBOL(drm_mode_validate_basic);
1055+
1056+
/**
1057+
* drm_mode_validate_driver - make sure the mode is somewhat sane
1058+
* @dev: drm device
1059+
* @mode: mode to check
1060+
*
1061+
* First do basic validation on the mode, and then allow the driver
1062+
* to check for device/driver specific limitations via the optional
1063+
* &drm_mode_config_helper_funcs.mode_valid hook.
1064+
*
1065+
* Returns:
1066+
* The mode status
1067+
*/
1068+
enum drm_mode_status
1069+
drm_mode_validate_driver(struct drm_device *dev,
1070+
const struct drm_display_mode *mode)
1071+
{
1072+
enum drm_mode_status status;
1073+
1074+
status = drm_mode_validate_basic(mode);
1075+
if (status != MODE_OK)
1076+
return status;
1077+
1078+
if (dev->mode_config.funcs->mode_valid)
1079+
return dev->mode_config.funcs->mode_valid(dev, mode);
1080+
else
1081+
return MODE_OK;
1082+
}
1083+
EXPORT_SYMBOL(drm_mode_validate_driver);
10661084

10671085
/**
10681086
* drm_mode_validate_size - make sure modes adhere to size constraints
@@ -1564,6 +1582,7 @@ void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
15641582

15651583
/**
15661584
* drm_crtc_convert_umode - convert a modeinfo into a drm_display_mode
1585+
* @dev: drm device
15671586
* @out: drm_display_mode to return to the user
15681587
* @in: drm_mode_modeinfo to use
15691588
*
@@ -1573,7 +1592,8 @@ void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
15731592
* Returns:
15741593
* Zero on success, negative errno on failure.
15751594
*/
1576-
int drm_mode_convert_umode(struct drm_display_mode *out,
1595+
int drm_mode_convert_umode(struct drm_device *dev,
1596+
struct drm_display_mode *out,
15771597
const struct drm_mode_modeinfo *in)
15781598
{
15791599
int ret = -EINVAL;
@@ -1600,7 +1620,7 @@ int drm_mode_convert_umode(struct drm_display_mode *out,
16001620
strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
16011621
out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
16021622

1603-
out->status = drm_mode_validate_basic(out);
1623+
out->status = drm_mode_validate_driver(dev, out);
16041624
if (out->status != MODE_OK)
16051625
goto out;
16061626

‎drivers/gpu/drm/drm_probe_helper.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ int drm_helper_probe_single_connector_modes(struct drm_connector *connector,
499499

500500
list_for_each_entry(mode, &connector->modes, head) {
501501
if (mode->status == MODE_OK)
502-
mode->status = drm_mode_validate_basic(mode);
502+
mode->status = drm_mode_validate_driver(dev, mode);
503503

504504
if (mode->status == MODE_OK)
505505
mode->status = drm_mode_validate_size(mode, maxX, maxY);

‎include/drm/drm_mode_config.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct drm_device;
3636
struct drm_atomic_state;
3737
struct drm_mode_fb_cmd2;
3838
struct drm_format_info;
39+
struct drm_display_mode;
3940

4041
/**
4142
* struct drm_mode_config_funcs - basic driver provided mode setting functions
@@ -101,6 +102,17 @@ struct drm_mode_config_funcs {
101102
*/
102103
void (*output_poll_changed)(struct drm_device *dev);
103104

105+
/**
106+
* @mode_valid:
107+
*
108+
* Device specific validation of display modes. Can be used to reject
109+
* modes that can never be supported. Only device wide constraints can
110+
* be checked here. crtc/encoder/bridge/connector specific constraints
111+
* should be checked in the .mode_valid() hook for each specific object.
112+
*/
113+
enum drm_mode_status (*mode_valid)(struct drm_device *dev,
114+
const struct drm_display_mode *mode);
115+
104116
/**
105117
* @atomic_check:
106118
*

‎include/drm/drm_modes.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ struct drm_display_mode *drm_mode_create(struct drm_device *dev);
444444
void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
445445
void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
446446
const struct drm_display_mode *in);
447-
int drm_mode_convert_umode(struct drm_display_mode *out,
447+
int drm_mode_convert_umode(struct drm_device *dev,
448+
struct drm_display_mode *out,
448449
const struct drm_mode_modeinfo *in);
449450
void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
450451
void drm_mode_debug_printmodeline(const struct drm_display_mode *mode);
@@ -497,7 +498,8 @@ bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
497498
const struct drm_display_mode *mode2);
498499

499500
/* for use by the crtc helper probe functions */
500-
enum drm_mode_status drm_mode_validate_basic(const struct drm_display_mode *mode);
501+
enum drm_mode_status drm_mode_validate_driver(struct drm_device *dev,
502+
const struct drm_display_mode *mode);
501503
enum drm_mode_status drm_mode_validate_size(const struct drm_display_mode *mode,
502504
int maxX, int maxY);
503505
enum drm_mode_status

0 commit comments

Comments
 (0)