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

drm/connector: Allow drivers to pass list of supported colorspaces

Drivers might not support all colorspaces defined in
dp_colorspaces and hdmi_colorspaces. This results in
undefined behavior when userspace is setting an
unsupported colorspace.

Allow drivers to pass the list of supported colorspaces
when creating the colorspace property.

v2:
- Use 0 to indicate support for all colorspaces (Jani)
- Print drm_dbg_kms message when drivers pass 0
to signal that drivers should specify supported
colorspaecs explicity (Jani)

v3:
- Move changes to create a common colorspace_names array
to separate patch

v6:
- Avoid magic when passing 0 for supported_colorspaces;
be explicit in treating it as "all DP/HDMI"

Signed-off-by: Harry Wentland <harry.wentland@amd.com>
Reviewed-by: Sebastian Wick <sebastian.wick@redhat.com>
Reviewed-by: Joshua Ashton <joshua@froggi.es>
Reviewed-by: Simon Ser <contact@emersion.fr>

Cc: Pekka Paalanen <ppaalanen@gmail.com>
Cc: Sebastian Wick <sebastian.wick@redhat.com>
Cc: Vitaly.Prosyak@amd.com
Cc: Uma Shankar <uma.shankar@intel.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Joshua Ashton <joshua@froggi.es>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Simon Ser <contact@emersion.fr>
Cc: Melissa Wen <mwen@igalia.com>
Cc: dri-devel@lists.freedesktop.org
Cc: amd-gfx@lists.freedesktop.org
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Harry Wentland and committed by
Alex Deucher
c265f340 035d53e0

+28 -9
+20 -4
drivers/gpu/drm/drm_connector.c
··· 2210 2210 * Returns: 2211 2211 * Zero on success, negative errno on failure. 2212 2212 */ 2213 - int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector) 2213 + int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector, 2214 + u32 supported_colorspaces) 2214 2215 { 2215 - return drm_mode_create_colorspace_property(connector, hdmi_colorspaces); 2216 + u32 colorspaces; 2217 + 2218 + if (supported_colorspaces) 2219 + colorspaces = supported_colorspaces & hdmi_colorspaces; 2220 + else 2221 + colorspaces = hdmi_colorspaces; 2222 + 2223 + return drm_mode_create_colorspace_property(connector, colorspaces); 2216 2224 } 2217 2225 EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property); 2218 2226 ··· 2234 2226 * Returns: 2235 2227 * Zero on success, negative errno on failure. 2236 2228 */ 2237 - int drm_mode_create_dp_colorspace_property(struct drm_connector *connector) 2229 + int drm_mode_create_dp_colorspace_property(struct drm_connector *connector, 2230 + u32 supported_colorspaces) 2238 2231 { 2239 - return drm_mode_create_colorspace_property(connector, dp_colorspaces); 2232 + u32 colorspaces; 2233 + 2234 + if (supported_colorspaces) 2235 + colorspaces = supported_colorspaces & dp_colorspaces; 2236 + else 2237 + colorspaces = dp_colorspaces; 2238 + 2239 + return drm_mode_create_colorspace_property(connector, colorspaces); 2240 2240 } 2241 2241 EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property); 2242 2242
+2 -2
drivers/gpu/drm/i915/display/intel_connector.c
··· 280 280 void 281 281 intel_attach_hdmi_colorspace_property(struct drm_connector *connector) 282 282 { 283 - if (!drm_mode_create_hdmi_colorspace_property(connector)) 283 + if (!drm_mode_create_hdmi_colorspace_property(connector, 0)) 284 284 drm_connector_attach_colorspace_property(connector); 285 285 } 286 286 287 287 void 288 288 intel_attach_dp_colorspace_property(struct drm_connector *connector) 289 289 { 290 - if (!drm_mode_create_dp_colorspace_property(connector)) 290 + if (!drm_mode_create_dp_colorspace_property(connector, 0)) 291 291 drm_connector_attach_colorspace_property(connector); 292 292 } 293 293
+1 -1
drivers/gpu/drm/vc4/vc4_hdmi.c
··· 631 631 if (ret) 632 632 return ret; 633 633 634 - ret = drm_mode_create_hdmi_colorspace_property(connector); 634 + ret = drm_mode_create_hdmi_colorspace_property(connector, 0); 635 635 if (ret) 636 636 return ret; 637 637
+5 -2
include/drm/drm_connector.h
··· 30 30 #include <linux/notifier.h> 31 31 #include <drm/drm_mode_object.h> 32 32 #include <drm/drm_util.h> 33 + #include <drm/drm_property.h> 33 34 34 35 #include <uapi/drm/drm_mode.h> 35 36 ··· 1995 1994 bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state, 1996 1995 struct drm_connector_state *new_state); 1997 1996 int drm_mode_create_aspect_ratio_property(struct drm_device *dev); 1998 - int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector); 1999 - int drm_mode_create_dp_colorspace_property(struct drm_connector *connector); 1997 + int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector, 1998 + u32 supported_colorspaces); 1999 + int drm_mode_create_dp_colorspace_property(struct drm_connector *connector, 2000 + u32 supported_colorspaces); 2000 2001 int drm_mode_create_content_type_property(struct drm_device *dev); 2001 2002 int drm_mode_create_suggested_offset_properties(struct drm_device *dev); 2002 2003