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

drm: Include the encoder itself in possible_clones

The docs say possible_clones should always include the encoder itself.
Since most drivers don't want to deal with the complexities of cloning
let's allow them to set possible_clones=0 and instead we'll fix that
up in the core.

We can't put this special case into drm_encoder_init() because drivers
will have to fill up possible_clones after adding all the relevant
encoders. Otherwise they wouldn't know the proper encoder indexes to
use. So we'll just do it just before registering the device.

v2: Don't set the bit if possible_clones!=0 so that the
validation (coming soon) will WARN (Thomas)
Fix up the docs to allow possible_clones==0 (Daniel)
.late_register() is too late, introduce drm_mode_config_validate()
which gets called _before_ we register the char device (Daniel)

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200211162208.16224-2-ville.syrjala@linux.intel.com
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

+26 -1
+1
drivers/gpu/drm/drm_crtc_internal.h
··· 82 82 /* drm_mode_config.c */ 83 83 int drm_modeset_register_all(struct drm_device *dev); 84 84 void drm_modeset_unregister_all(struct drm_device *dev); 85 + void drm_mode_config_validate(struct drm_device *dev); 85 86 86 87 /* drm_modes.c */ 87 88 const char *drm_get_mode_status_name(enum drm_mode_status status);
+3
drivers/gpu/drm/drm_drv.c
··· 946 946 struct drm_driver *driver = dev->driver; 947 947 int ret; 948 948 949 + if (!driver->load) 950 + drm_mode_config_validate(dev); 951 + 949 952 if (drm_dev_needs_global_mutex(dev)) 950 953 mutex_lock(&drm_global_mutex); 951 954
+19
drivers/gpu/drm/drm_mode_config.c
··· 532 532 drm_modeset_lock_fini(&dev->mode_config.connection_mutex); 533 533 } 534 534 EXPORT_SYMBOL(drm_mode_config_cleanup); 535 + 536 + /* 537 + * For some reason we want the encoder itself included in 538 + * possible_clones. Make life easy for drivers by allowing them 539 + * to leave possible_clones unset if no cloning is possible. 540 + */ 541 + static void fixup_encoder_possible_clones(struct drm_encoder *encoder) 542 + { 543 + if (encoder->possible_clones == 0) 544 + encoder->possible_clones = drm_encoder_mask(encoder); 545 + } 546 + 547 + void drm_mode_config_validate(struct drm_device *dev) 548 + { 549 + struct drm_encoder *encoder; 550 + 551 + drm_for_each_encoder(encoder, dev) 552 + fixup_encoder_possible_clones(encoder); 553 + }
+3 -1
include/drm/drm_encoder.h
··· 159 159 * encoders can be used in a cloned configuration, they both should have 160 160 * each another bits set. 161 161 * 162 - * In reality almost every driver gets this wrong. 162 + * As an exception to the above rule if the driver doesn't implement 163 + * any cloning it can leave @possible_clones set to 0. The core will 164 + * automagically fix this up by setting the bit for the encoder itself. 163 165 * 164 166 * Note that since encoder objects can't be hotplugged the assigned indices 165 167 * are stable and hence known before registering all objects.