Skip to contentSkip to conversation

Add HDMI 2.0 support to DW HDMI QP TX

PATCH Superseded Cristian Ciocaltea 5 participants 104 messages Jul 2 – Jul 22

Subsystems (6)

v8 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v8 cover Add HDMI 2.0 support to DW HDMI QP TX

Enable HDMI 2.0 display modes (e.g. 4K@60Hz) on the Synopsys DW HDMI QP TX controller, as found in Rockchip RK3576 & RK3588 SoCs, by adding SCDC management for high TMDS clock ratio and scrambling.

Since SCDC state is lost on sink disconnects, the bridge driver needs to trigger a CRTC reset during connector detection. To support this, the series introduces the connector and bridge scrambling infrastructure (patches 1-8), wires it up through the bridge connector layer with an atomic-aware detect_ctx hook (patches 9-11), then implements the SCDC scrambling feature in the DW HDMI QP bridge driver (patches 12-15).

Patches 16-18 are minor cleanups in the Rockchip platform driver. Patches 19-23 improve HPD handling by deferring IRQ registration until the connector is fully initialized, adding .enable_hpd()/.disable_hpd() PHY ops, and restricting HPD events to the affected connector.

Patches 24-25 convert vc4 HDMI to the common SCDC scrambling helpers as a proof of reuse, replacing the driver-local scrambling implementation.

Patches 26-30 add KUnit tests: connector scrambler validation, a new 4K@60Hz 600MHz EDID, hdmi_state_helper scrambling tests, and EDID conformity fixes for some of the existing test blobs.

This has been tested on the following boards:

* Radxa ROCK 5B (RK3588)
* Radxa ROCK 4D (RK3576)
* Raspberry Pi 5 Model B Rev 1.1 (BCM2712 D0)

Note that commit d87773de9efe1 ("clocksource/drivers/arm_arch_timer:
Default to EL2 virtual timer when running VHE"), introduced in v7.2-rc1, causes Raspberry Pi 5 to hang during boot. Reverting the commit restores normal boot. This issue has already been reported in [1]; alternatively, the workaround proposed in [2] can be applied.

Regards,
Cristian

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

---
Changes in v8:
- Added an enum hdmi_version under video/hdmi to describe the HDMI
specification version a source/sink supports (new patch 1)
- Introduced HDMI connector capabilities API and reworked the
infrastructure patches on top of it: drmm_connector_hdmi_init() now
takes a drm_connector_hdmi_caps struct that carries supported_formats,
max_bpc, supported_hdmi_ver and max_tmds_char_rate (new patches 2-3)
- Moved all the new SCDC helpers covering both source and sink to display/drm_hdmi_helper.c
- Renamed drm_scdc_{start,stop}_scrambling() to drm_connector_hdmi_{enable,disable}_scrambling() and added a
connector-state argument so the scrambler_needed flag is checked
centrally instead of in every driver
- Renamed drm_scdc_sync_status() to drm_connector_hdmi_sync_scdc(),
aligned its lifecycle with vc4_hdmi_reset_link(), and removed the
internal drm_scdc_reset_crtc() helper; it now also gates on CRTC state
and an in-flight commit (Maxime)
- Changed the prototype of drm_atomic_helper_connector_hdmi_hotplug() to
take an acquire context and an int return, instead of adding a new
_ctx variant (Maxime)
- Added drm_hdmi_mode_needs_scrambling() to centralise the above-340 MHz
decision (new patch 7)
- Made SCDC source version negotiation optional and moved it to a
dedicated patch "drm/display: hdmi: Advertise SCDC source version when scrambling" (new patch 8), backed by a new
drm_scdc_set_source_version() helper in "drm/display: scdc-helper: Add
helper to set SCDC version information" (new patch 6)
- Added a fallback TMDS rate validation patch using the connector-level max_tmds_char_rate when the driver provides no .tmds_char_rate_valid()
hook (new patch 9)
- Split scrambler_needed flag handling into its own hdmi-state-helper
dedicate change (new patch 11)
- VC4:
* Replaced vc4_hdmi_mode_needs_scrambling() with drm_hdmi_mode_needs_scrambling() (new patch 30)
* Restored drm_dev_{enter,exit}() pairing around the converted
scrambling paths
* Removed now unused output_{bpc,color_format} fields from vc4_hdmi as
part of the SCDC conversion
- KUnit:
* Covered the caps-based connector init path: NULL caps, inferred max_tmds_char_rate per supported_hdmi_ver, and override validation
(new patch 32)
* Switched drm_hdmi_state_helper_test to the caps-based init helper
and exposed it through drm_kunit_helper_connector_hdmi_init_with_caps_edid_funcs() (new
patch 34)
* Added max_tmds_char_rate fallback coverage in
drm_hdmi_state_helper_test (new patch 35)
- Rebased onto latest drm-misc-next and dropped the already applied "drm/fb-helper: Remove unused local variable in hotplug_event()" patch
- Link to v7: https://patch.msgid.link/[email protected]

Changes in v7:
- Split the scrambler_needed flag computation from the SCDC scrambling
helpers into a standalone hdmi_state_helper patch for clarity (new
patch 6)
- Added vc4 HDMI conversion to common TMDS char rate constants and SCDC scrambling helpers as a proof of reuse (new patches 24-25)
- Added KUnit tests for connector scrambler_supported/callback
consistency validation (new patch 26)
- Added 4K@60Hz 600MHz TMDS test EDID for high-rate scrambling coverage
(new patch 27)
- Added KUnit tests for hdmi_state_helper scrambler_needed flag:
low-rate, high-rate, and source-no-support cases (new patch 28)
- Fixed EDID conformity issues (edid-decode v1.33.0 failures) in the
existing 1080p+4K YUV420 200MHz and 4K RGB/YUV 340MHz test EDIDs
without changing the capabilities used by existing tests (new patches
29-30)
- Rebased onto latest drm-misc-next
- Link to v6: https://patch.msgid.link/[email protected]

Changes in v6:
- Collected R-b & A-b tags from Dmitry and Heiko
- Restructured the series from 10 into 22 patches, splitting the SCDC
scrambling helpers, connector infrastructure, bridge operations, bridge_connector plumbing, dw-hdmi-qp implementation, and Rockchip
platform changes into distinct commits
- Added drm_scdc_dbg() macro to simplify debug messages (new patch)
- Added drm_scdc_start/stop/sync_status() helpers for full scrambling
lifecycle management (reworked from v5 patch 5)
- Added drm_atomic_helper_connector_hdmi_hotplug_ctx() to propagate
modeset acquire context for SCDC sync on hotplug (new patch)
- Added connector scrambler callbacks and SCDC work/flag infrastructure
as a separate patch (split from v5 patch 5)
- Added DRM_BRIDGE_OP_HDMI_SCRAMBLER bridge operation with hdmi_scrambler_enable/disable callbacks (new patch)
- Implemented bridge_connector scrambler interface wiring (new patch)
- Added .enable_hpd()/.disable_hpd() PHY ops for dw-hdmi-qp bridge and
Rockchip platform drivers, replacing the obsolete .setup_hpd() op
- Added dw_hdmi_qp_hpd_notify() helper for targeted connector-only HPD notification (split from v5 patch 10)
- Dropped drm_fb_helper_hotplug_event() unused variable (new cleanup)
- Dropped unused drm_simple_kms_helper.h include (new cleanup)
- Masked RK3576 HPD IRQ in io_init() for consistency with RK3588
- Rebased onto latest drm-misc-next
- Link to v5: https://patch.msgid.link/[email protected]

Changes in v5:
- Added new patches: 1/10, 3/10, 6/10, 7/10, 8/10
- Removed redundant no-op error check in drm_bridge_helper_reset_crtc()
(patch 1)
- Removed the EDEADLK retry loop from the bridge .detect_ctx() callback,
as that's already handled in the drm_bridge_detect_ctx() helper or by
the caller when ctx is provided (patch 2)
- Refactored drm_bridge_detect() to delegate to drm_bridge_detect_ctx()
and added a WARN_ON for unexpected negative return values (patch 2)
- Split the bridge-connector .detect_ctx() switch into a preparatory
patch to use cached connector status in .get_modes() (patch 3)
- Improved error handling in SCDC scrambling setup: roll back high TMDS
clock ratio on scrambling failure, reset scramb_enabled flag on
set_scramb failure, and add SCDC version read/write error checks
(patch 5)
- Annotated scramb_enabled with READ_ONCE/WRITE_ONCE for cross-context
access between modeset paths and the scrambling work item (patch 5)
- Renamed SCDC_MIN_SOURCE_VERSION to SCDC_MAX_SOURCE_VERSION (patch 5)
- Rate limited i2c error messages (patch 6)
- Added missing newlines in dev_err_probe() messages (patch 7)
- Replaced indirect device pointer accesses with local dev variable in
bind() (patch 8)
- Split the HPD connector restriction (formerly patch 4/4): register HPD
IRQ after connector setup first (patch 9), then restrict HPD event to
the affected connector (patch 10); also collected R-b from Heiko
- Rebased onto latest drm-misc-next
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Fixed conflicts while rebasing onto latest drm-misc-next
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Used drm_bridge_helper_reset_crtc() helper to reset the display
pipeline and got rid of some boilerplate code (Maxime)
- Rebased onto latest drm-misc-next
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Collected Tested-by tags from Diederik and Maud
- Rebased onto latest drm-misc-next
- Ensured the recently introduced 'no-hpd' support for dealing with unconnected/repurposed/broken HPD pin is limited to HDMI 1.4 rates
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Cristian Ciocaltea (39):
video/hdmi: Introduce HDMI version enum
drm/connector: Add caps-based HDMI connector init helper drm/display: bridge_connector: Pass HDMI capabilities through caps struct drm/connector: Add HDMI 2.0 scrambler infrastructure drm/display: scdc-helper: Add macro for connector-prefixed debug messages drm/display: scdc-helper: Add helper to set SCDC version information drm/display: hdmi: Add HDMI 2.0 scrambling management helpers drm/display: hdmi: Advertise SCDC source version when scrambling drm/display: hdmi-state-helper: Add fallback TMDS rate validation drm/display: hdmi-state-helper: Sync SCDC state on hotplug drm/display: hdmi-state-helper: Set HDMI scrambling requirement drm/bridge: Remove redundant error check in drm_bridge_helper_reset_crtc() drm/bridge: Add bridge ops for source-side HDMI 2.0 scrambling drm/display: bridge_connector: Use cached connector status in .get_modes() drm/display: bridge_connector: Switch to .detect_ctx() connector helper drm/display: bridge_connector: Wire up HDMI 2.0 scrambler callbacks drm/bridge: dw-hdmi-qp: Rate limit i2c read error messages drm/bridge: dw-hdmi-qp: Provide .{enable|disable}_hpd() PHY ops drm/bridge: dw-hdmi-qp: Add HDMI 2.0 SCDC scrambling support drm/bridge: dw-hdmi-qp: Provide dw_hdmi_qp_hpd_notify() helper drm/rockchip: dw_hdmi_qp: Add missing newlines in dev_err_probe() messages drm/rockchip: dw_hdmi_qp: Use local dev variable consistently in bind() drm/rockchip: dw_hdmi_qp: Drop unnecessary #include drm/rockchip: dw_hdmi_qp: Defer HPD IRQ enable until after connector setup drm/rockchip: dw_hdmi_qp: Mask RK3576 HPD IRQ in io_init drm/rockchip: dw_hdmi_qp: Implement .{enable|disable}_hpd() PHY ops drm/rockchip: dw_hdmi_qp: Use dw_hdmi_qp_hpd_notify() for HPD reports drm/bridge: dw-hdmi-qp: Drop unused .setup_hpd() phy op drm/vc4: hdmi: Use common TMDS char rate constants
drm/vc4: hdmi: Switch to drm_hdmi_mode_needs_scrambling() drm/vc4: hdmi: Convert to common SCDC scrambling infrastructure drm/tests: connector: Add HDMI caps-based init coverage drm/tests: connector: Add HDMI source-side scrambler coverage drm/tests: hdmi_state_helper: Use drmm_connector_hdmi_init_with_caps() drm/tests: hdmi_state_helper: Add max_tmds_char_rate fallback tests drm/tests: edid: Add 4K@60Hz EDID with 600MHz TMDS
drm/tests: hdmi_state_helper: Cover source-side scrambling decision drm/tests: edid: Fix conformity for 1080p+4K YUV420 200MHz EDID drm/tests: edid: Fix conformity for 4K RGB/YUV 340MHz EDID

 drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c       | 129 ++++++--
 drivers/gpu/drm/display/drm_bridge_connector.c     | 146 +++++----
 drivers/gpu/drm/display/drm_hdmi_helper.c          | 267 +++++++++++++++++
 drivers/gpu/drm/display/drm_hdmi_state_helper.c    |  32 +-
 drivers/gpu/drm/display/drm_scdc_helper.c          |  70 ++++-
 drivers/gpu/drm/drm_bridge_helper.c                |   2 -
 drivers/gpu/drm/drm_connector.c                    | 222 ++++++++++----
 drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c     | 130 ++++----
 drivers/gpu/drm/tests/drm_connector_test.c         | 330 +++++++++++++++++++++
 drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 315 +++++++++++++++++++-
 drivers/gpu/drm/tests/drm_kunit_edid.c             | 251 +++++++++++++---
 drivers/gpu/drm/tests/drm_kunit_edid.h             |   1 +
 drivers/gpu/drm/vc4/vc4_hdmi.c                     | 301 ++++---------------
 drivers/gpu/drm/vc4/vc4_hdmi.h                     |  21 --
 include/drm/bridge/dw_hdmi_qp.h                    |   4 +-
 include/drm/display/drm_hdmi_helper.h              |  15 +
 include/drm/display/drm_hdmi_state_helper.h        |   6 +-
 include/drm/display/drm_scdc_helper.h              |   2 +
 include/drm/drm_bridge.h                           |  41 +++
 include/drm/drm_connector.h                        | 132 +++++++++
 include/linux/hdmi.h                               |  12 +
 21 files changed, 1869 insertions(+), 560 deletions(-)

---
base-commit: 44d19b8a7548aa25cbc6ebd5f27e958f7142c36b
change-id: 20251203-dw-hdmi-qp-scramb-cdbd8b57ccf9

#1 lore raw

PATCH v8 1/39 video/hdmi: Introduce HDMI version enum

Add an enum to represent HDMI specification versions. This will be used by upcoming changes to associate HDMI connectors and bridges with a maximum supported version and to simplify handling of version-dependent features.

---
 include/linux/hdmi.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/linux/hdmi.h +12 -0
index 8dab78e1f61b..b80a5ee63bb2 100644
@@ -27,6 +27,18 @@
 #include <linux/types.h>
 #include <linux/device.h>
 
+enum hdmi_version {
+	HDMI_VERSION_UNKNOWN,
+	HDMI_VERSION_1_0,
+	HDMI_VERSION_1_1,
+	HDMI_VERSION_1_2,
+	HDMI_VERSION_1_3,
+	HDMI_VERSION_1_4,
+	HDMI_VERSION_2_0,
+	HDMI_VERSION_2_1,
+	HDMI_VERSION_2_2,
+};
+
 enum hdmi_packet_type {
 	HDMI_PACKET_TYPE_NULL = 0x00,
 	HDMI_PACKET_TYPE_AUDIO_CLOCK_REGEN = 0x01,
Signature · 1 line
2.54.0
Reviewed-by on v8 1/39
#2 lore raw

Re: [PATCH v8 01/39] video/hdmi: Introduce HDMI version enum

Quoted 10 lines · Cristian Ciocaltea

Add an enum to represent HDMI specification versions. This will be used by upcoming changes to associate HDMI connectors and bridges with a maximum supported version and to simplify handling of version-dependent features.

---
 include/linux/hdmi.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Signature · 2 lines
With best wishes
Dmitry
maintainer Reviewed-by on v8 1/39
#3 lore raw

Re: [PATCH v8 01/39] video/hdmi: Introduce HDMI version enum

In reply to Cristian Ciocaltea
Quoted 7 lines · Cristian Ciocaltea

Add an enum to represent HDMI specification versions. This will be used by upcoming changes to associate HDMI connectors and bridges with a maximum supported version and to simplify handling of version-dependent features.

[ ... ]

Thanks!
Maxime

#4 lore raw

PATCH v8 2/39 drm/connector: Add caps-based HDMI connector init helper

In reply to Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

---
 drivers/gpu/drm/drm_connector.c | 202 +++++++++++++++++++++++++++-------------
 include/drm/drm_connector.h     |  55 +++++++++++
 2 files changed, 193 insertions(+), 64 deletions(-)
drivers/gpu/drm/drm_connector.c +138 -64
index 8b4baed060f3..c7ce6b7bd8b0 100644
@@ -542,6 +542,137 @@ int drmm_connector_init(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drmm_connector_init);
 
+/**
+ * drmm_connector_hdmi_init_with_caps - Init a preallocated HDMI connector
+ * @dev: DRM device
+ * @connector: A pointer to the HDMI connector to init
+ * @vendor: HDMI Controller Vendor name
+ * @product: HDMI Controller Product name
+ * @funcs: callbacks for this connector
+ * @hdmi_funcs: HDMI-related callbacks for this connector
+ * @connector_type: user visible type of the connector
+ * @ddc: optional pointer to the associated ddc adapter
+ * @caps: optional HDMI connector capabilities
+ *
+ * Initialises a preallocated HDMI connector. Connectors can be
+ * subclassed as part of driver connector objects.
+ *
+ * Cleanup is automatically handled with a call to
+ * drm_connector_cleanup() in a DRM-managed action.
+ *
+ * The connector structure should be allocated with drmm_kzalloc().
+ *
+ * The @drm_connector_funcs.destroy hook must be NULL.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ */
+int drmm_connector_hdmi_init_with_caps(struct drm_device *dev,
+				       struct drm_connector *connector,
+				       const char *vendor, const char *product,
+				       const struct drm_connector_funcs *funcs,
+				       const struct drm_connector_hdmi_funcs *hdmi_funcs,
+				       int connector_type,
+				       struct i2c_adapter *ddc,
+				       const struct drm_connector_hdmi_caps *caps)
+{
+	int ret;
+
+	if (!vendor || !product)
+		return -EINVAL;
+
+	if ((strlen(vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) ||
+	    (strlen(product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN))
+		return -EINVAL;
+
+	if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA ||
+	      connector_type == DRM_MODE_CONNECTOR_HDMIB))
+		return -EINVAL;
+
+	if (!caps)
+		return -EINVAL;
+
+	if (!caps->supported_formats ||
+	    !(caps->supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444)))
+		return -EINVAL;
+
+	if (connector->ycbcr_420_allowed !=
+	    !!(caps->supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420)))
+		return -EINVAL;
+
+	if (!(caps->max_bpc == 8 || caps->max_bpc == 10 || caps->max_bpc == 12))
+		return -EINVAL;
+
+	if (!hdmi_funcs->avi.clear_infoframe ||
+	    !hdmi_funcs->avi.write_infoframe ||
+	    !hdmi_funcs->hdmi.clear_infoframe ||
+	    !hdmi_funcs->hdmi.write_infoframe)
+		return -EINVAL;
+
+	ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc);
+	if (ret)
+		return ret;
+
+	connector->hdmi.supported_formats = caps->supported_formats;
+
+	/*
+	 * The supported HDMI version can be used to infer the maximum TMDS
+	 * character rate allowed by the specification. Some controllers,
+	 * however, may support a lower rate than that version would imply.
+	 *
+	 * A non-zero caps->max_tmds_char_rate lets drivers override the
+	 * inferred limit with the actual controller capability. A value of
+	 * zero keeps the default limit inferred from supported_hdmi_ver.
+	 */
+	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0)
+		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
+	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3)
+		connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
+	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0)
+		connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
+
+	if (caps->max_tmds_char_rate) {
+		if (caps->max_tmds_char_rate > connector->hdmi.max_tmds_char_rate)
+			return -EINVAL;
+		connector->hdmi.max_tmds_char_rate = caps->max_tmds_char_rate;
+	}
+
+	strtomem_pad(connector->hdmi.vendor, vendor, 0);
+	strtomem_pad(connector->hdmi.product, product, 0);
+
+	/*
+	 * drm_connector_attach_max_bpc_property() requires the
+	 * connector to have a state.
+	 */
+	if (connector->funcs->atomic_create_state) {
+		struct drm_connector_state *state;
+
+		state = connector->funcs->atomic_create_state(connector);
+		if (IS_ERR(state))
+			return PTR_ERR(state);
+
+		connector->state = state;
+	} else if (connector->funcs->reset) {
+		connector->funcs->reset(connector);
+	}
+
+	drm_connector_attach_max_bpc_property(connector, 8, caps->max_bpc);
+	connector->max_bpc = caps->max_bpc;
+
+	if (caps->max_bpc > 8)
+		drm_connector_attach_hdr_output_metadata_property(connector);
+
+	ret = drm_connector_attach_color_format_property(connector,
+							 caps->supported_formats);
+	if (ret)
+		return ret;
+
+	connector->hdmi.funcs = hdmi_funcs;
+
+	return 0;
+}
+EXPORT_SYMBOL(drmm_connector_hdmi_init_with_caps);
+
 /**
  * drmm_connector_hdmi_init - Init a preallocated HDMI connector
  * @dev: DRM device
@@ -578,71 +709,14 @@ int drmm_connector_hdmi_init(struct drm_device *dev,
 			     unsigned long supported_formats,
 			     unsigned int max_bpc)
 {
-	int ret;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_formats = supported_formats,
+		.max_bpc = max_bpc,
+	};
 
-	if (!vendor || !product)
-		return -EINVAL;
-
-	if ((strlen(vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) ||
-	    (strlen(product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN))
-		return -EINVAL;
-
-	if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA ||
-	      connector_type == DRM_MODE_CONNECTOR_HDMIB))
-		return -EINVAL;
-
-	if (!supported_formats || !(supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444)))
-		return -EINVAL;
-
-	if (connector->ycbcr_420_allowed != !!(supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420)))
-		return -EINVAL;
-
-	if (!(max_bpc == 8 || max_bpc == 10 || max_bpc == 12))
-		return -EINVAL;
-
-	if (!hdmi_funcs->avi.clear_infoframe ||
-	    !hdmi_funcs->avi.write_infoframe ||
-	    !hdmi_funcs->hdmi.clear_infoframe ||
-	    !hdmi_funcs->hdmi.write_infoframe)
-		return -EINVAL;
-
-	ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc);
-	if (ret)
-		return ret;
-
-	connector->hdmi.supported_formats = supported_formats;
-	strtomem_pad(connector->hdmi.vendor, vendor, 0);
-	strtomem_pad(connector->hdmi.product, product, 0);
-
-	/*
-	 * drm_connector_attach_max_bpc_property() requires the
-	 * connector to have a state.
-	 */
-	if (connector->funcs->atomic_create_state) {
-		struct drm_connector_state *state;
-
-		state = connector->funcs->atomic_create_state(connector);
-		if (IS_ERR(state))
-			return PTR_ERR(state);
-
-		connector->state = state;
-	} else if (connector->funcs->reset) {
-		connector->funcs->reset(connector);
-	}
-
-	drm_connector_attach_max_bpc_property(connector, 8, max_bpc);
-	connector->max_bpc = max_bpc;
-
-	if (max_bpc > 8)
-		drm_connector_attach_hdr_output_metadata_property(connector);
-
-	ret = drm_connector_attach_color_format_property(connector, supported_formats);
-	if (ret)
-		return ret;
-
-	connector->hdmi.funcs = hdmi_funcs;
-
-	return 0;
+	return drmm_connector_hdmi_init_with_caps(dev, connector, vendor,
+						  product, funcs, hdmi_funcs,
+						  connector_type, ddc, &caps);
 }
 EXPORT_SYMBOL(drmm_connector_hdmi_init);
 
include/drm/drm_connector.h +55 -0

73 lines not on this page · raw message

Signature · 1 line
2.54.0
#5 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The kernel-doc for drmm_connector_hdmi_init_with_caps incorrectly claims the caps parameter is…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The kernel-doc for drmm_connector_hdmi_init_with_caps incorrectly claims the caps parameter is optional, but the implementation strictly requires it. --

commit 0bf3f9f06453c1934cf1bf6f51eb321720ded5eb
Author: Cristian Ciocaltea <[email protected]>

drm/connector: Add caps-based HDMI connector init helper

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

Quoted 4 lines
drivers/gpu/drm/drm_connector.c +0 -0
index 8b4baed060f3a..c7ce6b7bd8b0e 100644

[ ... ]

Quoted 9 lines
drivers/gpu/drm/drm_connector.c +1 -2
@@ -552,8 +552,7 @@ EXPORT_SYMBOL(drmm_connector_init);
  * @hdmi_funcs: HDMI-related callbacks for this connector
  * @connector_type: user visible type of the connector
  * @ddc: optional pointer to the associated ddc adapter
- * @supported_formats: Bitmask of @drm_output_color_format listing supported output formats
- * @max_bpc: Maximum bits per char the HDMI connector supports
+ * @caps: optional HDMI connector capabilities
  *
  * Initialises a preallocated HDMI connector. Connectors can be

[ ... ]

drivers/gpu/drm/drm_connector.c int drmm_connector_hdmi_init(struct drm_device *dev, · line 593

Quoted 7 lines
drivers/gpu/drm/drm_connector.c +1 -1
@@ -591,13 +589,18 @@ int drmm_connector_hdmi_init(struct drm_device *dev,
 	      connector_type == DRM_MODE_CONNECTOR_HDMIB))
 		return -EINVAL;
 
-	if (!supported_formats || !(supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444)))
+	if (!caps)
 		return -EINVAL;

[Severity: Low]
The kernel-doc for drmm_connector_hdmi_init_with_caps() marks @caps as an optional parameter, but the implementation explicitly rejects a NULL caps pointer with -EINVAL.

Should the documentation be updated to reflect that @caps is actually required?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#6 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

In reply to Cristian Ciocaltea
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 99 lines
---
 drivers/gpu/drm/drm_connector.c | 202 +++++++++++++++++++++++++++-------------
 include/drm/drm_connector.h     |  55 +++++++++++
 2 files changed, 193 insertions(+), 64 deletions(-)
drivers/gpu/drm/drm_connector.c +84 -0
index 8b4baed060f3..c7ce6b7bd8b0 100644
@@ -542,6 +542,137 @@ int drmm_connector_init(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drmm_connector_init);
 
+/**
+ * drmm_connector_hdmi_init_with_caps - Init a preallocated HDMI connector
+ * @dev: DRM device
+ * @connector: A pointer to the HDMI connector to init
+ * @vendor: HDMI Controller Vendor name
+ * @product: HDMI Controller Product name
+ * @funcs: callbacks for this connector
+ * @hdmi_funcs: HDMI-related callbacks for this connector
+ * @connector_type: user visible type of the connector
+ * @ddc: optional pointer to the associated ddc adapter
+ * @caps: optional HDMI connector capabilities
+ *
+ * Initialises a preallocated HDMI connector. Connectors can be
+ * subclassed as part of driver connector objects.
+ *
+ * Cleanup is automatically handled with a call to
+ * drm_connector_cleanup() in a DRM-managed action.
+ *
+ * The connector structure should be allocated with drmm_kzalloc().
+ *
+ * The @drm_connector_funcs.destroy hook must be NULL.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ */
+int drmm_connector_hdmi_init_with_caps(struct drm_device *dev,
+				       struct drm_connector *connector,
+				       const char *vendor, const char *product,
+				       const struct drm_connector_funcs *funcs,
+				       const struct drm_connector_hdmi_funcs *hdmi_funcs,
+				       int connector_type,
+				       struct i2c_adapter *ddc,
+				       const struct drm_connector_hdmi_caps *caps)
+{
+	int ret;
+
+	if (!vendor || !product)
+		return -EINVAL;
+
+	if ((strlen(vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) ||
+	    (strlen(product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN))
+		return -EINVAL;
+
+	if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA ||
+	      connector_type == DRM_MODE_CONNECTOR_HDMIB))
+		return -EINVAL;
+
+	if (!caps)
+		return -EINVAL;
+
+	if (!caps->supported_formats ||
+	    !(caps->supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444)))
+		return -EINVAL;
+
+	if (connector->ycbcr_420_allowed !=
+	    !!(caps->supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420)))
+		return -EINVAL;
+
+	if (!(caps->max_bpc == 8 || caps->max_bpc == 10 || caps->max_bpc == 12))
+		return -EINVAL;
+
+	if (!hdmi_funcs->avi.clear_infoframe ||
+	    !hdmi_funcs->avi.write_infoframe ||
+	    !hdmi_funcs->hdmi.clear_infoframe ||
+	    !hdmi_funcs->hdmi.write_infoframe)
+		return -EINVAL;
+
+	ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc);
+	if (ret)
+		return ret;
+
+	connector->hdmi.supported_formats = caps->supported_formats;
+
+	/*
+	 * The supported HDMI version can be used to infer the maximum TMDS
+	 * character rate allowed by the specification. Some controllers,
+	 * however, may support a lower rate than that version would imply.
+	 *
+	 * A non-zero caps->max_tmds_char_rate lets drivers override the
+	 * inferred limit with the actual controller capability. A value of
+	 * zero keeps the default limit inferred from supported_hdmi_ver.
+	 */
+	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0)
+		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;

drivers/gpu/drm/drm_connector.c int drmm_connector_init(struct drm_device *dev, · line 638

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3)
+		connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
+	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0)
+		connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
+
+	if (caps->max_tmds_char_rate) {
+		if (caps->max_tmds_char_rate > connector->hdmi.max_tmds_char_rate)
+			return -EINVAL;
+		connector->hdmi.max_tmds_char_rate = caps->max_tmds_char_rate;
+	}

Here I'd totally suggest something simpler:

if (!caps->max_tmds_char_rate) {
	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0)
		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3)
		connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0)
		connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
}
Quoted 12 lines
drivers/gpu/drm/drm_connector.c +12 -0
+
+	strtomem_pad(connector->hdmi.vendor, vendor, 0);
+	strtomem_pad(connector->hdmi.product, product, 0);
+
+	/*
+	 * drm_connector_attach_max_bpc_property() requires the
+	 * connector to have a state.
+	 */
+	if (connector->funcs->atomic_create_state) {
+		struct drm_connector_state *state;
+
+		state = connector->funcs->atomic_create_state(connector);

drivers/gpu/drm/drm_connector.c int drmm_connector_init(struct drm_device *dev, · line 660

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+		if (IS_ERR(state))
+			return PTR_ERR(state);
+
+		connector->state = state;
+	} else if (connector->funcs->reset) {
+		connector->funcs->reset(connector);
+	}
+
+	drm_connector_attach_max_bpc_property(connector, 8, caps->max_bpc);
+	connector->max_bpc = caps->max_bpc;

If you don't like the max_bpc argument, let's do it other way:

if (connector->max_bpc < 8)

	return -EINVAL;

if (connector->max_bpc > 8)

	drm_connector_attach_hdr_output_metadata_property(connector);
Quoted 111 lines
drivers/gpu/drm/drm_connector.c +22 -64
+
+	if (caps->max_bpc > 8)
+		drm_connector_attach_hdr_output_metadata_property(connector);
+
+	ret = drm_connector_attach_color_format_property(connector,
+							 caps->supported_formats);
+	if (ret)
+		return ret;
+
+	connector->hdmi.funcs = hdmi_funcs;
+
+	return 0;
+}
+EXPORT_SYMBOL(drmm_connector_hdmi_init_with_caps);
+
 /**
  * drmm_connector_hdmi_init - Init a preallocated HDMI connector
  * @dev: DRM device
@@ -578,71 +709,14 @@ int drmm_connector_hdmi_init(struct drm_device *dev,
 			     unsigned long supported_formats,
 			     unsigned int max_bpc)
 {
-	int ret;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_formats = supported_formats,
+		.max_bpc = max_bpc,
+	};
 
-	if (!vendor || !product)
-		return -EINVAL;
-
-	if ((strlen(vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) ||
-	    (strlen(product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN))
-		return -EINVAL;
-
-	if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA ||
-	      connector_type == DRM_MODE_CONNECTOR_HDMIB))
-		return -EINVAL;
-
-	if (!supported_formats || !(supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444)))
-		return -EINVAL;
-
-	if (connector->ycbcr_420_allowed != !!(supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420)))
-		return -EINVAL;
-
-	if (!(max_bpc == 8 || max_bpc == 10 || max_bpc == 12))
-		return -EINVAL;
-
-	if (!hdmi_funcs->avi.clear_infoframe ||
-	    !hdmi_funcs->avi.write_infoframe ||
-	    !hdmi_funcs->hdmi.clear_infoframe ||
-	    !hdmi_funcs->hdmi.write_infoframe)
-		return -EINVAL;
-
-	ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc);
-	if (ret)
-		return ret;
-
-	connector->hdmi.supported_formats = supported_formats;
-	strtomem_pad(connector->hdmi.vendor, vendor, 0);
-	strtomem_pad(connector->hdmi.product, product, 0);
-
-	/*
-	 * drm_connector_attach_max_bpc_property() requires the
-	 * connector to have a state.
-	 */
-	if (connector->funcs->atomic_create_state) {
-		struct drm_connector_state *state;
-
-		state = connector->funcs->atomic_create_state(connector);
-		if (IS_ERR(state))
-			return PTR_ERR(state);
-
-		connector->state = state;
-	} else if (connector->funcs->reset) {
-		connector->funcs->reset(connector);
-	}
-
-	drm_connector_attach_max_bpc_property(connector, 8, max_bpc);
-	connector->max_bpc = max_bpc;
-
-	if (max_bpc > 8)
-		drm_connector_attach_hdr_output_metadata_property(connector);
-
-	ret = drm_connector_attach_color_format_property(connector, supported_formats);
-	if (ret)
-		return ret;
-
-	connector->hdmi.funcs = hdmi_funcs;
-
-	return 0;
+	return drmm_connector_hdmi_init_with_caps(dev, connector, vendor,
+						  product, funcs, hdmi_funcs,
+						  connector_type, ddc, &caps);
 }
 EXPORT_SYMBOL(drmm_connector_hdmi_init);
 
include/drm/drm_connector.h +6 -0
index af075c38f4db..961a729d0869 100644
@@ -2029,6 +2029,47 @@ struct drm_connector_hdmi_audio {
 	int dai_port;
 };
 
+/**
+ * struct drm_connector_hdmi_caps - HDMI capabilities structure
+ *
+ * This structure is required to initialize the connector using
+ * drmm_connector_hdmi_init_with_caps().
+ */

include/drm/drm_connector.h struct drm_connector_hdmi_audio { · line 2047

Quoted 10 lines
include/drm/drm_connector.h +10 -0
+struct drm_connector_hdmi_caps {
+	/**
+	 * @supported_hdmi_ver:
+	 *
+	 * Maximum HDMI specification version supported by the controller side
+	 * of this connector. This describes the controller capability only;
+	 * the effective link capabilities may be further restricted by the
+	 * sink, bridge, or mode validation.
+	 *
+	 * HDMI_VERSION_UNKNOWN means legacy/default behaviour.

What would it actually mean here? Every chip has some version of HDMI standard it conforms to.

Quoted 28 lines
include/drm/drm_connector.h +25 -0
+	 */
+	enum hdmi_version supported_hdmi_ver;
+
+	/**
+	 * @supported_formats:
+	 *
+	 * Bitmask of @drm_output_color_format listing supported output formats.
+	 */
+	unsigned long supported_formats;
+
+	/**
+	 * @max_tmds_char_rate:
+	 *
+	 * Maximum TMDS character rate supported by the source, in Hz.
+	 * A value of 0 means the core should use the default limit implied by
+	 * @supported_hdmi_ver.
+	 */
+	unsigned long long max_tmds_char_rate;
+
+	/**
+	 * @max_bpc: Maximum bits per char the HDMI connector supports.
+	 */
+	unsigned int max_bpc;
+};
+
 /*
  * struct drm_connector_hdmi - DRM Connector HDMI-related structure
  */
Signature · 2 lines
With best wishes
Dmitry
#7 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

Quoted 112 lines
Quoted 99 lines
---
 drivers/gpu/drm/drm_connector.c | 202 +++++++++++++++++++++++++++-------------
 include/drm/drm_connector.h     |  55 +++++++++++
 2 files changed, 193 insertions(+), 64 deletions(-)
drivers/gpu/drm/drm_connector.c +84 -0
index 8b4baed060f3..c7ce6b7bd8b0 100644
@@ -542,6 +542,137 @@ int drmm_connector_init(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drmm_connector_init);
 
+/**
+ * drmm_connector_hdmi_init_with_caps - Init a preallocated HDMI connector
+ * @dev: DRM device
+ * @connector: A pointer to the HDMI connector to init
+ * @vendor: HDMI Controller Vendor name
+ * @product: HDMI Controller Product name
+ * @funcs: callbacks for this connector
+ * @hdmi_funcs: HDMI-related callbacks for this connector
+ * @connector_type: user visible type of the connector
+ * @ddc: optional pointer to the associated ddc adapter
+ * @caps: optional HDMI connector capabilities
+ *
+ * Initialises a preallocated HDMI connector. Connectors can be
+ * subclassed as part of driver connector objects.
+ *
+ * Cleanup is automatically handled with a call to
+ * drm_connector_cleanup() in a DRM-managed action.
+ *
+ * The connector structure should be allocated with drmm_kzalloc().
+ *
+ * The @drm_connector_funcs.destroy hook must be NULL.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ */
+int drmm_connector_hdmi_init_with_caps(struct drm_device *dev,
+				       struct drm_connector *connector,
+				       const char *vendor, const char *product,
+				       const struct drm_connector_funcs *funcs,
+				       const struct drm_connector_hdmi_funcs *hdmi_funcs,
+				       int connector_type,
+				       struct i2c_adapter *ddc,
+				       const struct drm_connector_hdmi_caps *caps)
+{
+	int ret;
+
+	if (!vendor || !product)
+		return -EINVAL;
+
+	if ((strlen(vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) ||
+	    (strlen(product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN))
+		return -EINVAL;
+
+	if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA ||
+	      connector_type == DRM_MODE_CONNECTOR_HDMIB))
+		return -EINVAL;
+
+	if (!caps)
+		return -EINVAL;
+
+	if (!caps->supported_formats ||
+	    !(caps->supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444)))
+		return -EINVAL;
+
+	if (connector->ycbcr_420_allowed !=
+	    !!(caps->supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420)))
+		return -EINVAL;
+
+	if (!(caps->max_bpc == 8 || caps->max_bpc == 10 || caps->max_bpc == 12))
+		return -EINVAL;
+
+	if (!hdmi_funcs->avi.clear_infoframe ||
+	    !hdmi_funcs->avi.write_infoframe ||
+	    !hdmi_funcs->hdmi.clear_infoframe ||
+	    !hdmi_funcs->hdmi.write_infoframe)
+		return -EINVAL;
+
+	ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc);
+	if (ret)
+		return ret;
+
+	connector->hdmi.supported_formats = caps->supported_formats;
+
+	/*
+	 * The supported HDMI version can be used to infer the maximum TMDS
+	 * character rate allowed by the specification. Some controllers,
+	 * however, may support a lower rate than that version would imply.
+	 *
+	 * A non-zero caps->max_tmds_char_rate lets drivers override the
+	 * inferred limit with the actual controller capability. A value of
+	 * zero keeps the default limit inferred from supported_hdmi_ver.
+	 */
+	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0)
+		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;

drivers/gpu/drm/drm_connector.c int drmm_connector_init(struct drm_device *dev, · line 638

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3)
+		connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
+	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0)
+		connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
+
+	if (caps->max_tmds_char_rate) {
+		if (caps->max_tmds_char_rate > connector->hdmi.max_tmds_char_rate)
+			return -EINVAL;
+		connector->hdmi.max_tmds_char_rate = caps->max_tmds_char_rate;
+	}

Here I'd totally suggest something simpler:

Quoted 8 lines
if (!caps->max_tmds_char_rate) {
	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0)
		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3)
		connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0)
		connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
}

My intention was to check that a driver-supplied caps->max_tmds_char_rate doesn't exceed the spec-permitted maximum for the declared supported_hdmi_ver. With the simplified form, a driver could declare e.g. HDMI 1.4 but pass a 2.0-level char rate, and we'd silently accept it.

Also, we'd still need to handle the supplied value in the non-zero case:

} else {
    connector->hdmi.max_tmds_char_rate = caps->max_tmds_char_rate;
}

So the net reduction is smaller than it looks.

Quoted 25 lines
Quoted 12 lines
drivers/gpu/drm/drm_connector.c +12 -0
+
+	strtomem_pad(connector->hdmi.vendor, vendor, 0);
+	strtomem_pad(connector->hdmi.product, product, 0);
+
+	/*
+	 * drm_connector_attach_max_bpc_property() requires the
+	 * connector to have a state.
+	 */
+	if (connector->funcs->atomic_create_state) {
+		struct drm_connector_state *state;
+
+		state = connector->funcs->atomic_create_state(connector);

drivers/gpu/drm/drm_connector.c int drmm_connector_init(struct drm_device *dev, · line 660

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +10 -0
+		if (IS_ERR(state))
+			return PTR_ERR(state);
+
+		connector->state = state;
+	} else if (connector->funcs->reset) {
+		connector->funcs->reset(connector);
+	}
+
+	drm_connector_attach_max_bpc_property(connector, 8, caps->max_bpc);
+	connector->max_bpc = caps->max_bpc;

If you don't like the max_bpc argument, let's do it other way:

Quoted 2 lines

if (connector->max_bpc < 8)

	return -EINVAL;

If I follow correctly, you suggest dropping max_bpc from the caps struct and letting drivers set connector->max_bpc before calling the init helper, leaving the core to only do the reject.

Also note we actually have a more restricted check above:

if (!(caps->max_bpc == 8 || caps->max_bpc == 10 || caps->max_bpc == 12))

    return -EINVAL;

I'd still keep max_bpc in the struct, assuming we can move further with the caps approach.

Quoted 120 lines

if (connector->max_bpc > 8)

	drm_connector_attach_hdr_output_metadata_property(connector);
Quoted 116 lines
drivers/gpu/drm/drm_connector.c +22 -64
+
+	if (caps->max_bpc > 8)
+		drm_connector_attach_hdr_output_metadata_property(connector);
+
+	ret = drm_connector_attach_color_format_property(connector,
+							 caps->supported_formats);
+	if (ret)
+		return ret;
+
+	connector->hdmi.funcs = hdmi_funcs;
+
+	return 0;
+}
+EXPORT_SYMBOL(drmm_connector_hdmi_init_with_caps);
+
 /**
  * drmm_connector_hdmi_init - Init a preallocated HDMI connector
  * @dev: DRM device
@@ -578,71 +709,14 @@ int drmm_connector_hdmi_init(struct drm_device *dev,
 			     unsigned long supported_formats,
 			     unsigned int max_bpc)
 {
-	int ret;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_formats = supported_formats,
+		.max_bpc = max_bpc,
+	};
 
-	if (!vendor || !product)
-		return -EINVAL;
-
-	if ((strlen(vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) ||
-	    (strlen(product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN))
-		return -EINVAL;
-
-	if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA ||
-	      connector_type == DRM_MODE_CONNECTOR_HDMIB))
-		return -EINVAL;
-
-	if (!supported_formats || !(supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444)))
-		return -EINVAL;
-
-	if (connector->ycbcr_420_allowed != !!(supported_formats & BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420)))
-		return -EINVAL;
-
-	if (!(max_bpc == 8 || max_bpc == 10 || max_bpc == 12))
-		return -EINVAL;
-
-	if (!hdmi_funcs->avi.clear_infoframe ||
-	    !hdmi_funcs->avi.write_infoframe ||
-	    !hdmi_funcs->hdmi.clear_infoframe ||
-	    !hdmi_funcs->hdmi.write_infoframe)
-		return -EINVAL;
-
-	ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc);
-	if (ret)
-		return ret;
-
-	connector->hdmi.supported_formats = supported_formats;
-	strtomem_pad(connector->hdmi.vendor, vendor, 0);
-	strtomem_pad(connector->hdmi.product, product, 0);
-
-	/*
-	 * drm_connector_attach_max_bpc_property() requires the
-	 * connector to have a state.
-	 */
-	if (connector->funcs->atomic_create_state) {
-		struct drm_connector_state *state;
-
-		state = connector->funcs->atomic_create_state(connector);
-		if (IS_ERR(state))
-			return PTR_ERR(state);
-
-		connector->state = state;
-	} else if (connector->funcs->reset) {
-		connector->funcs->reset(connector);
-	}
-
-	drm_connector_attach_max_bpc_property(connector, 8, max_bpc);
-	connector->max_bpc = max_bpc;
-
-	if (max_bpc > 8)
-		drm_connector_attach_hdr_output_metadata_property(connector);
-
-	ret = drm_connector_attach_color_format_property(connector, supported_formats);
-	if (ret)
-		return ret;
-
-	connector->hdmi.funcs = hdmi_funcs;
-
-	return 0;
+	return drmm_connector_hdmi_init_with_caps(dev, connector, vendor,
+						  product, funcs, hdmi_funcs,
+						  connector_type, ddc, &caps);
 }
 EXPORT_SYMBOL(drmm_connector_hdmi_init);
 
include/drm/drm_connector.h +11 -0
index af075c38f4db..961a729d0869 100644
@@ -2029,6 +2029,47 @@ struct drm_connector_hdmi_audio {
 	int dai_port;
 };
 
+/**
+ * struct drm_connector_hdmi_caps - HDMI capabilities structure
+ *
+ * This structure is required to initialize the connector using
+ * drmm_connector_hdmi_init_with_caps().
+ */
+struct drm_connector_hdmi_caps {
+	/**
+	 * @supported_hdmi_ver:
+	 *
+	 * Maximum HDMI specification version supported by the controller side
Quoted 8 lines

include/drm/drm_connector.h struct drm_connector_hdmi_audio { · line 2047

Quoted 5 lines
include/drm/drm_connector.h +5 -0
+	 * of this connector. This describes the controller capability only;
+	 * the effective link capabilities may be further restricted by the
+	 * sink, bridge, or mode validation.
+	 *
+	 * HDMI_VERSION_UNKNOWN means legacy/default behaviour.

What would it actually mean here? Every chip has some version of HDMI standard it conforms to.

HDMI_VERSION_UNKNOWN only exists for the legacy drmm_connector_hdmi_init() wrapper, which doesn't pass a version - in that case the code keeps the pre-existing behaviour (no version-inferred TMDS limit). Once all callers migrate to the caps-based API, supported_hdmi_ver becomes mandatory.

Given that, I'd simply drop the "legacy/default behaviour" statement, unless you have a better suggestion.

Quoted 29 lines
Quoted 28 lines
include/drm/drm_connector.h +25 -0
+	 */
+	enum hdmi_version supported_hdmi_ver;
+
+	/**
+	 * @supported_formats:
+	 *
+	 * Bitmask of @drm_output_color_format listing supported output formats.
+	 */
+	unsigned long supported_formats;
+
+	/**
+	 * @max_tmds_char_rate:
+	 *
+	 * Maximum TMDS character rate supported by the source, in Hz.
+	 * A value of 0 means the core should use the default limit implied by
+	 * @supported_hdmi_ver.
+	 */
+	unsigned long long max_tmds_char_rate;
+
+	/**
+	 * @max_bpc: Maximum bits per char the HDMI connector supports.
+	 */
+	unsigned int max_bpc;
+};
+
 /*
  * struct drm_connector_hdmi - DRM Connector HDMI-related structure
  */
maintainer
#8 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

Quoted 21 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 8 lines

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

Yeah, I don't think we can win with C here. Rust might, but we're probably a long way from that.

Quoted 10 lines

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

I just realized something reviewing your patch: we don't necessarily need an extra argument or a callback, we can just put these fields into drm_hdmi_connector_funcs directly, and then validate them in init.

Maxime

#9 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

Hi Maxime,

Quoted 45 lines · Maxime Ripard
Quoted 21 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 8 lines

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

Yeah, I don't think we can win with C here. Rust might, but we're probably a long way from that.

Quoted 10 lines

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

Quoted 3 lines

I just realized something reviewing your patch: we don't necessarily need an extra argument or a callback, we can just put these fields into drm_hdmi_connector_funcs directly, and then validate them in init.

If I understand correctly, we should drop the drm_connector_hdmi_caps struct introduced by this patch and move all its fields into drm_hdmi_connector_funcs.

In that case, how should we proceed with drmm_connector_hdmi_init()? I see the following options:

1. Continue with drmm_connector_hdmi_init_with_caps() after removing the caps parameter, and then drop drmm_connector_hdmi_init() after the migration.

2. Keep the existing (unaltered) drmm_connector_hdmi_init(), which would be slightly inconsistent: supported_formats and max_bpc would still be passed as arguments, while the rest would go through drm_hdmi_connector_funcs.

3. A variation of option 1: additionally rename drmm_connector_hdmi_init_with_caps() to drmm_connector_hdmi_init() after the migration.

Thanks,
Cristian

#10 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

Quoted 48 lines · Cristian Ciocaltea

Hi Maxime,

Quoted 45 lines · Maxime Ripard
Quoted 21 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 8 lines

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

Yeah, I don't think we can win with C here. Rust might, but we're probably a long way from that.

Quoted 10 lines

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

Quoted 8 lines
Quoted 3 lines

I just realized something reviewing your patch: we don't necessarily need an extra argument or a callback, we can just put these fields into drm_hdmi_connector_funcs directly, and then validate them in init.

If I understand correctly, we should drop the drm_connector_hdmi_caps struct introduced by this patch and move all its fields into drm_hdmi_connector_funcs.

In that case, how should we proceed with drmm_connector_hdmi_init()?

Actually, this brings us to the callback issue: we cannot compute caps dynamically, as it only works with static data, since funcs is supposed to be immutable.

Moreover, we would end up with some redundancy, as most of these input fields, after validation, would be stored (altered or not) directly in drm_connector/drm_connector_hdmi structs.

Hence, I think we are still better off sticking with drmm_connector_hdmi_init_with_caps() for now.

Quoted 16 lines

I see the
following options:

1. Continue with drmm_connector_hdmi_init_with_caps() after removing the caps parameter, and then drop drmm_connector_hdmi_init() after the migration.

2. Keep the existing (unaltered) drmm_connector_hdmi_init(), which would be slightly inconsistent: supported_formats and max_bpc would still be passed as arguments, while the rest would go through drm_hdmi_connector_funcs.

3. A variation of option 1: additionally rename drmm_connector_hdmi_init_with_caps() to drmm_connector_hdmi_init() after the migration.

Thanks,
Cristian

maintainer
#11 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

Quoted 53 lines · Cristian Ciocaltea
Quoted 52 lines · Cristian Ciocaltea

Hi Maxime,

Quoted 48 lines · Maxime Ripard
Quoted 21 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 8 lines

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

Yeah, I don't think we can win with C here. Rust might, but we're probably a long way from that.

Quoted 10 lines

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

I just realized something reviewing your patch: we don't necessarily need an extra argument or a callback, we can just put these fields into drm_hdmi_connector_funcs directly, and then validate them in init.

Quoted 8 lines
Quoted 4 lines

If I understand correctly, we should drop the drm_connector_hdmi_caps struct introduced by this patch and move all its fields into drm_hdmi_connector_funcs.

In that case, how should we proceed with drmm_connector_hdmi_init()?

Actually, this brings us to the callback issue: we cannot compute caps dynamically, as it only works with static data, since funcs is supposed to be immutable.

Does it? The core and helpers must consider it immutable but it doesn't have to. drm_bridge_connector for example could totally allocate it and dynamically create it based on the bridge capabilities.

Quoted 3 lines

Moreover, we would end up with some redundancy, as most of these input fields, after validation, would be stored (altered or not) directly in drm_connector/drm_connector_hdmi structs.

I mean, part of the conversion would obviously be to remove the redundant fields.

#12 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

Quoted 59 lines · Maxime Ripard
Quoted 58 lines · Cristian Ciocaltea
Quoted 56 lines · Cristian Ciocaltea

Hi Maxime,

Quoted 45 lines · Maxime Ripard
Quoted 21 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 8 lines

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

Yeah, I don't think we can win with C here. Rust might, but we're probably a long way from that.

Quoted 10 lines

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

Quoted 3 lines

I just realized something reviewing your patch: we don't necessarily need an extra argument or a callback, we can just put these fields into drm_hdmi_connector_funcs directly, and then validate them in init.

If I understand correctly, we should drop the drm_connector_hdmi_caps struct introduced by this patch and move all its fields into drm_hdmi_connector_funcs.

In that case, how should we proceed with drmm_connector_hdmi_init()?

Quoted 7 lines
Quoted 3 lines

Actually, this brings us to the callback issue: we cannot compute caps dynamically, as it only works with static data, since funcs is supposed to be immutable.

Does it? The core and helpers must consider it immutable but it doesn't have to. drm_bridge_connector for example could totally allocate it and dynamically create it based on the bridge capabilities.

If we take the VC4 case, is it fine to drop the const from the static drm_connector_hdmi_funcs to allow dynamically setting up supported_hdmi_ver and max_bpc in vc4_hdmi_connector_init()?

static struct drm_connector_hdmi_funcs vc4_hdmi_hdmi_connector_funcs = {
	.tmds_char_rate_valid	 = vc4_hdmi_connector_clock_valid,
	...
}

static int vc4_hdmi_connector_init()

{
	...
    
	if (vc4_hdmi->variant->supports_hdr)
		vc4_hdmi_hdmi_connector_funcs.max_bpc = 12;

	if (vc4_hdmi->variant->max_pixel_clock >= HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_2_0;
	else if (vc4_hdmi->variant->max_pixel_clock >= HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_1_3;
	...
}
Quoted 6 lines
Quoted 3 lines

Moreover, we would end up with some redundancy, as most of these input fields, after validation, would be stored (altered or not) directly in drm_connector/drm_connector_hdmi structs.

I mean, part of the conversion would obviously be to remove the redundant fields.

Ack.

maintainer
#13 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

Quoted 78 lines · Cristian Ciocaltea
Quoted 59 lines · Maxime Ripard
Quoted 58 lines · Cristian Ciocaltea
Quoted 56 lines · Cristian Ciocaltea

Hi Maxime,

Quoted 45 lines · Maxime Ripard
Quoted 21 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 8 lines

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

Yeah, I don't think we can win with C here. Rust might, but we're probably a long way from that.

Quoted 10 lines

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

Quoted 3 lines

I just realized something reviewing your patch: we don't necessarily need an extra argument or a callback, we can just put these fields into drm_hdmi_connector_funcs directly, and then validate them in init.

If I understand correctly, we should drop the drm_connector_hdmi_caps struct introduced by this patch and move all its fields into drm_hdmi_connector_funcs.

In that case, how should we proceed with drmm_connector_hdmi_init()?

Quoted 7 lines
Quoted 3 lines

Actually, this brings us to the callback issue: we cannot compute caps dynamically, as it only works with static data, since funcs is supposed to be immutable.

Does it? The core and helpers must consider it immutable but it doesn't have to. drm_bridge_connector for example could totally allocate it and dynamically create it based on the bridge capabilities.

If we take the VC4 case, is it fine to drop the const from the static drm_connector_hdmi_funcs to allow dynamically setting up supported_hdmi_ver and max_bpc in vc4_hdmi_connector_init()?

static struct drm_connector_hdmi_funcs vc4_hdmi_hdmi_connector_funcs = {
	.tmds_char_rate_valid	 = vc4_hdmi_connector_clock_valid,
	...
}

static int vc4_hdmi_connector_init()

Quoted 12 lines
{
	...
    
	if (vc4_hdmi->variant->supports_hdr)
		vc4_hdmi_hdmi_connector_funcs.max_bpc = 12;

	if (vc4_hdmi->variant->max_pixel_clock >= HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_2_0;
	else if (vc4_hdmi->variant->max_pixel_clock >= HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_1_3;
	...
}

No, but you don't have to do that either.

You have three cases:
- Rpi < 4 has max_bpc = 8, HDMI 1.4
- RPI 4 HDMI 0 and RPI 5 has max_bpc = 12, HDMI 2.0
- RPI 4 HDMI 1 has max_bpc = 12, HDMI 1.4

Just create three different structures, and put a pointer to the right one in the vc4_hdmi_variant structure. There's no need to be dynamic there.

Maxime

#14 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

Quoted 94 lines · Maxime Ripard
Quoted 78 lines · Cristian Ciocaltea
Quoted 59 lines · Maxime Ripard
Quoted 58 lines · Cristian Ciocaltea
Quoted 56 lines · Cristian Ciocaltea

Hi Maxime,

Quoted 45 lines · Maxime Ripard
Quoted 21 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 8 lines

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

Yeah, I don't think we can win with C here. Rust might, but we're probably a long way from that.

Quoted 10 lines

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

Quoted 3 lines

I just realized something reviewing your patch: we don't necessarily need an extra argument or a callback, we can just put these fields into drm_hdmi_connector_funcs directly, and then validate them in init.

If I understand correctly, we should drop the drm_connector_hdmi_caps struct introduced by this patch and move all its fields into drm_hdmi_connector_funcs.

In that case, how should we proceed with drmm_connector_hdmi_init()?

Quoted 7 lines
Quoted 3 lines

Actually, this brings us to the callback issue: we cannot compute caps dynamically, as it only works with static data, since funcs is supposed to be immutable.

Does it? The core and helpers must consider it immutable but it doesn't have to. drm_bridge_connector for example could totally allocate it and dynamically create it based on the bridge capabilities.

If we take the VC4 case, is it fine to drop the const from the static drm_connector_hdmi_funcs to allow dynamically setting up supported_hdmi_ver and max_bpc in vc4_hdmi_connector_init()?

static struct drm_connector_hdmi_funcs vc4_hdmi_hdmi_connector_funcs = {
	.tmds_char_rate_valid	 = vc4_hdmi_connector_clock_valid,
	...
}

static int vc4_hdmi_connector_init()

Quoted 12 lines
{
	...
    
	if (vc4_hdmi->variant->supports_hdr)
		vc4_hdmi_hdmi_connector_funcs.max_bpc = 12;

	if (vc4_hdmi->variant->max_pixel_clock >= HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_2_0;
	else if (vc4_hdmi->variant->max_pixel_clock >= HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_1_3;
	...
}

No, but you don't have to do that either.

Quoted 8 lines

You have three cases:
- Rpi < 4 has max_bpc = 8, HDMI 1.4
- RPI 4 HDMI 0 and RPI 5 has max_bpc = 12, HDMI 2.0
- RPI 4 HDMI 1 has max_bpc = 12, HDMI 1.4

Just create three different structures, and put a pointer to the right one in the vc4_hdmi_variant structure. There's no need to be dynamic there.

Ack, will do!

Thanks,
Cristian

#15 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

In reply to Cristian Ciocaltea
Quoted 78 lines · Cristian Ciocaltea
Quoted 59 lines · Maxime Ripard
Quoted 58 lines · Cristian Ciocaltea
Quoted 56 lines · Cristian Ciocaltea

Hi Maxime,

Quoted 45 lines · Maxime Ripard
Quoted 21 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 8 lines

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

Yeah, I don't think we can win with C here. Rust might, but we're probably a long way from that.

Quoted 10 lines

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

Quoted 3 lines

I just realized something reviewing your patch: we don't necessarily need an extra argument or a callback, we can just put these fields into drm_hdmi_connector_funcs directly, and then validate them in init.

If I understand correctly, we should drop the drm_connector_hdmi_caps struct introduced by this patch and move all its fields into drm_hdmi_connector_funcs.

In that case, how should we proceed with drmm_connector_hdmi_init()?

Quoted 7 lines
Quoted 3 lines

Actually, this brings us to the callback issue: we cannot compute caps dynamically, as it only works with static data, since funcs is supposed to be immutable.

Does it? The core and helpers must consider it immutable but it doesn't have to. drm_bridge_connector for example could totally allocate it and dynamically create it based on the bridge capabilities.

If we take the VC4 case, is it fine to drop the const from the static drm_connector_hdmi_funcs to allow dynamically setting up supported_hdmi_ver and max_bpc in vc4_hdmi_connector_init()?

static struct drm_connector_hdmi_funcs vc4_hdmi_hdmi_connector_funcs = {
	.tmds_char_rate_valid	 = vc4_hdmi_connector_clock_valid,
	...
}

static int vc4_hdmi_connector_init()

Quoted 12 lines
{
	...
    
	if (vc4_hdmi->variant->supports_hdr)
		vc4_hdmi_hdmi_connector_funcs.max_bpc = 12;

	if (vc4_hdmi->variant->max_pixel_clock >= HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_2_0;
	else if (vc4_hdmi->variant->max_pixel_clock >= HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_1_3;
	...
}

I'm sorry for the late response, I was OoO. Why do we want to put data into the funcs part? My suggestion would be to put the data into the drm_connector_hdmi itself.

Setting connector->hdmi.supported_hdmi_ver = HDMI_VERSION_1_4; is more idiomatic than passing it through the funcs.

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

Moreover, we would end up with some redundancy, as most of these input fields, after validation, would be stored (altered or not) directly in drm_connector/drm_connector_hdmi structs.

I mean, part of the conversion would obviously be to remove the redundant fields.

Ack.

Signature · 2 lines
With best wishes
Dmitry
#16 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

Quoted 99 lines · Dmitry Baryshkov
Quoted 78 lines · Cristian Ciocaltea
Quoted 59 lines · Maxime Ripard
Quoted 58 lines · Cristian Ciocaltea
Quoted 56 lines · Cristian Ciocaltea

Hi Maxime,

Quoted 45 lines · Maxime Ripard
Quoted 21 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 8 lines

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

Yeah, I don't think we can win with C here. Rust might, but we're probably a long way from that.

Quoted 10 lines

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

Quoted 3 lines

I just realized something reviewing your patch: we don't necessarily need an extra argument or a callback, we can just put these fields into drm_hdmi_connector_funcs directly, and then validate them in init.

If I understand correctly, we should drop the drm_connector_hdmi_caps struct introduced by this patch and move all its fields into drm_hdmi_connector_funcs.

In that case, how should we proceed with drmm_connector_hdmi_init()?

Quoted 7 lines
Quoted 3 lines

Actually, this brings us to the callback issue: we cannot compute caps dynamically, as it only works with static data, since funcs is supposed to be immutable.

Does it? The core and helpers must consider it immutable but it doesn't have to. drm_bridge_connector for example could totally allocate it and dynamically create it based on the bridge capabilities.

If we take the VC4 case, is it fine to drop the const from the static drm_connector_hdmi_funcs to allow dynamically setting up supported_hdmi_ver and max_bpc in vc4_hdmi_connector_init()?

static struct drm_connector_hdmi_funcs vc4_hdmi_hdmi_connector_funcs = {
	.tmds_char_rate_valid	 = vc4_hdmi_connector_clock_valid,
	...
}

static int vc4_hdmi_connector_init()

Quoted 12 lines
{
	...
    
	if (vc4_hdmi->variant->supports_hdr)
		vc4_hdmi_hdmi_connector_funcs.max_bpc = 12;

	if (vc4_hdmi->variant->max_pixel_clock >= HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_2_0;
	else if (vc4_hdmi->variant->max_pixel_clock >= HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_1_3;
	...
}

I'm sorry for the late response, I was OoO. Why do we want to put data into the funcs part? My suggestion would be to put the data into the drm_connector_hdmi itself.

Setting connector->hdmi.supported_hdmi_ver = HDMI_VERSION_1_4; is more idiomatic than passing it through the funcs.

Quoted 92 lines · Dmitry Baryshkov
Quoted 78 lines · Cristian Ciocaltea
Quoted 59 lines · Maxime Ripard
Quoted 58 lines · Cristian Ciocaltea
Quoted 56 lines · Cristian Ciocaltea

Hi Maxime,

Quoted 45 lines · Maxime Ripard
Quoted 21 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 8 lines

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

Yeah, I don't think we can win with C here. Rust might, but we're probably a long way from that.

Quoted 10 lines

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

Quoted 3 lines

I just realized something reviewing your patch: we don't necessarily need an extra argument or a callback, we can just put these fields into drm_hdmi_connector_funcs directly, and then validate them in init.

If I understand correctly, we should drop the drm_connector_hdmi_caps struct introduced by this patch and move all its fields into drm_hdmi_connector_funcs.

In that case, how should we proceed with drmm_connector_hdmi_init()?

Quoted 7 lines
Quoted 3 lines

Actually, this brings us to the callback issue: we cannot compute caps dynamically, as it only works with static data, since funcs is supposed to be immutable.

Does it? The core and helpers must consider it immutable but it doesn't have to. drm_bridge_connector for example could totally allocate it and dynamically create it based on the bridge capabilities.

If we take the VC4 case, is it fine to drop the const from the static drm_connector_hdmi_funcs to allow dynamically setting up supported_hdmi_ver and max_bpc in vc4_hdmi_connector_init()?

static struct drm_connector_hdmi_funcs vc4_hdmi_hdmi_connector_funcs = {
	.tmds_char_rate_valid	 = vc4_hdmi_connector_clock_valid,
	...
}

static int vc4_hdmi_connector_init()

Quoted 12 lines
{
	...
    
	if (vc4_hdmi->variant->supports_hdr)
		vc4_hdmi_hdmi_connector_funcs.max_bpc = 12;

	if (vc4_hdmi->variant->max_pixel_clock >= HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_2_0;
	else if (vc4_hdmi->variant->max_pixel_clock >= HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ)
		vc4_hdmi_hdmi_connector_funcs.supported_hdmi_ver = HDMI_VERSION_1_3;
	...
}
Quoted 7 lines

I'm sorry for the late response, I was OoO. Why do we want to put data into the funcs part? My suggestion would be to put the data into the drm_connector_hdmi itself.

Setting connector->hdmi.supported_hdmi_ver = HDMI_VERSION_1_4; is more idiomatic than passing it through the funcs.

I've already done the conversion so that vendor, product, supported_formats and max_bpc values previously passed as arguments are now provided through drm_connector_hdmi_funcs, along with the additional supported_hdmi_ver and supported_tmds_char_rate fields.

In most cases it wasn't necessary to pass this data dynamically (with the exception of the bridge connector and some kunit tests), so it was just a matter of extending the immutable hdmi_funcs structs.

I'll send v9 a bit later today so we can discuss directly on the code changes.

FWIW, in the VC4 case, I followed Maxime's suggestion and introduced three hdmi_funcs instances (+ a macro to avoid duplication) and assigned them to the corresponding vc4_hdmi_variant entries:

#define VC4_HDMI_CONNECTOR_FUNCS_COMMON						\
	.vendor			 = "Broadcom",					\
	.product		 = "Videocore",					\
	.supported_formats	 = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444) |	\
				   BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR422) |	\
				   BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR444),	\
	.tmds_char_rate_valid	 = vc4_hdmi_connector_clock_valid,		\
	.avi = {								\
		.clear_infoframe = vc4_hdmi_clear_avi_infoframe,		\
		.write_infoframe = vc4_hdmi_write_avi_infoframe,		\
	},									\
	.hdmi = {								\
		.clear_infoframe = vc4_hdmi_clear_hdmi_infoframe,		\
		.write_infoframe = vc4_hdmi_write_hdmi_infoframe,		\
	},									\
	...
static const struct drm_connector_hdmi_funcs vc4_hdmi_connector_funcs_hdmi14 = {
	VC4_HDMI_CONNECTOR_FUNCS_COMMON,
	.max_bpc		= 12,
	.supported_hdmi_ver	= HDMI_VERSION_1_4,
};
static const struct drm_connector_hdmi_funcs vc4_hdmi_connector_funcs_hdmi20 = {
	VC4_HDMI_CONNECTOR_FUNCS_COMMON,
	.max_bpc		= 12,
	.supported_hdmi_ver	= HDMI_VERSION_2_0,
	.scrambler_enable	= vc4_hdmi_scrambler_enable,
	.scrambler_disable	= vc4_hdmi_scrambler_disable,
};
static const struct vc4_hdmi_variant bcm2712_hdmi0_variant = {
	...
	.hp_detect		= vc5_hdmi_hp_detect,
	.hdmi_funcs		= &vc4_hdmi_connector_funcs_hdmi20,
};

vc4_hdmi_connector_init()

{
	...
	ret = drmm_connector_hdmi_init(dev, connector,
				       &vc4_hdmi_connector_funcs,
				       vc4_hdmi->variant->hdmi_funcs,
				       DRM_MODE_CONNECTOR_HDMIA,
				       vc4_hdmi->ddc);
	...
}
maintainer
#17 lore raw

Re: [PATCH v8 02/39] drm/connector: Add caps-based HDMI connector init helper

In reply to Cristian Ciocaltea

Hi,

Quoted 50 lines · Cristian Ciocaltea
Quoted 45 lines · Maxime Ripard
Quoted 21 lines · Cristian Ciocaltea

Hi Dmitry,

Thanks for your quick review!

Quoted 12 lines · Dmitry Baryshkov
Quoted 10 lines · Cristian Ciocaltea

In preparation for adding HDMI 2.x source capabilities, introduce struct drm_connector_hdmi_caps and a new drmm_connector_hdmi_init_with_caps() helper.

The existing drmm_connector_hdmi_init() helper currently takes individual capability arguments such as supported_formats and max_bpc. Adding more HDMI-specific arguments to that function would not scale well, so move those values into a dedicated capabilities structure and implement the existing helper as a wrapper around the new caps-based interface.

Quoted 3 lines

I think, it was an intention of Maxime: make sure that every driver is forced to provide some values here. With the struct-based init it is easy to overlook or to ommit a value.

Quoted 8 lines

Agreed that the struct-based init loses the compile-time guarantee that every argument is explicitly provided - that's a real downside.

I'd argue it's recoverable, though: the init helper validates the mandatory fields, so a driver that omits a required value gets rejected at init time rather than silently misconfigured. The "you must provide sane values" property is expected to be preserved, just enforced at runtime instead of by the compiler.

Yeah, I don't think we can win with C here. Rust might, but we're probably a long way from that.

Quoted 10 lines

The main motivation for the struct is scalability/maintainability as we add HDMI 2.x capabilities: new fields go into the struct rather than growing the helper's argument list, so existing callers don't need churny signature updates on every extension.

FWIW, in the previous revision we discussed addressing the concern with a callback instead. Sadly, I had to discard that approach, as it proved not flexible enough, e.g. drm_bridge_connector_init() computes caps dynamically, and would have required either stateful callbacks, or storing redundant/temporary cap data in driver-private structures just to satisfy the callback.

Quoted 3 lines

I just realized something reviewing your patch: we don't necessarily need an extra argument or a callback, we can just put these fields into drm_hdmi_connector_funcs directly, and then validate them in init.

Quoted 8 lines

If I understand correctly, we should drop the drm_connector_hdmi_caps struct introduced by this patch and move all its fields into drm_hdmi_connector_funcs.

In that case, how should we proceed with drmm_connector_hdmi_init()? I see the following options:

1. Continue with drmm_connector_hdmi_init_with_caps() after removing the caps parameter, and then drop drmm_connector_hdmi_init() after the migration.

If we're going that road, we can also move the format, bpc and vendor and product there for example.

Quoted 3 lines

2. Keep the existing (unaltered) drmm_connector_hdmi_init(), which would be slightly inconsistent: supported_formats and max_bpc would still be passed as arguments, while the rest would go through drm_hdmi_connector_funcs.

I'm not sure why we would want to do that?

Quoted 3 lines

3. A variation of option 1: additionally rename drmm_connector_hdmi_init_with_caps() to drmm_connector_hdmi_init() after the migration.

It should be renamed indeed.

Maxime

#18 lore raw

PATCH v8 3/39 drm/display: bridge_connector: Pass HDMI capabilities through caps struct

In reply to Cristian Ciocaltea

Switch drm_bridge_connector_init() to drmm_connector_hdmi_init_with_caps(), collecting the bridge's HDMI properties into a stack drm_connector_hdmi_caps so future HDMI 2.x capabilities can be plumbed without growing the argument list.

Introduce struct drm_bridge::supported_hdmi_ver to let bridges declare the HDMI specification version they are conformant with, and forward it to the connector layer through the new caps struct so HDMI 2.x features can be gated on real source capability rather than guesswork.

---
 drivers/gpu/drm/display/drm_bridge_connector.c | 29 ++++++++++++++------------
 include/drm/drm_bridge.h                       |  6 ++++++
 2 files changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +16 -13
index 92f8a2d7aab4..796069dbf1a1 100644
@@ -823,8 +823,10 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 	struct drm_connector *connector;
 	struct i2c_adapter *ddc = NULL;
 	struct drm_bridge *panel_bridge __free(drm_bridge_put) = NULL;
-	unsigned int supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444);
-	unsigned int max_bpc = 8;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+	};
 	bool support_hdcp = false;
 	int connector_type;
 	int ret;
@@ -885,6 +887,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 		if (bridge->ops & DRM_BRIDGE_OP_HDMI) {
 			if (bridge_connector->bridge_hdmi)
 				return ERR_PTR(-EBUSY);
+
 			if (!bridge->funcs->hdmi_write_avi_infoframe ||
 			    !bridge->funcs->hdmi_clear_avi_infoframe ||
 			    !bridge->funcs->hdmi_write_hdmi_infoframe ||
@@ -908,10 +911,12 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 
 			bridge_connector->bridge_hdmi = drm_bridge_get(bridge);
 
+			if (bridge->supported_hdmi_ver)
+				caps.supported_hdmi_ver = bridge->supported_hdmi_ver;
 			if (bridge->supported_formats)
-				supported_formats = bridge->supported_formats;
+				caps.supported_formats = bridge->supported_formats;
 			if (bridge->max_bpc)
-				max_bpc = bridge->max_bpc;
+				caps.max_bpc = bridge->max_bpc;
 		}
 
 		if (bridge->ops & DRM_BRIDGE_OP_HDMI_AUDIO) {
@@ -994,7 +999,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 
 	if (bridge_connector->bridge_hdmi) {
 		if (!connector->ycbcr_420_allowed)
-			supported_formats &= ~BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420);
+			caps.supported_formats &= ~BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420);
 
 		bridge_connector->hdmi_funcs = drm_bridge_connector_hdmi_funcs;
 
@@ -1010,14 +1015,12 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 			bridge_connector->hdmi_funcs.spd =
 				drm_bridge_connector_hdmi_spd_infoframe;
 
-		ret = drmm_connector_hdmi_init(drm, connector,
-					       bridge_connector->bridge_hdmi->vendor,
-					       bridge_connector->bridge_hdmi->product,
-					       &drm_bridge_connector_funcs,
-					       &bridge_connector->hdmi_funcs,
-					       connector_type, ddc,
-					       supported_formats,
-					       max_bpc);
+		ret = drmm_connector_hdmi_init_with_caps(drm, connector,
+							 bridge_connector->bridge_hdmi->vendor,
+							 bridge_connector->bridge_hdmi->product,
+							 &drm_bridge_connector_funcs,
+							 &bridge_connector->hdmi_funcs,
+							 connector_type, ddc, &caps);
 		if (ret)
 			return ERR_PTR(ret);
 	} else {
include/drm/drm_bridge.h +6 -0
index 18f3db367dc1..2d8b5e4c64ba 100644
@@ -1176,6 +1176,12 @@ struct drm_bridge {
 	 */
 	const char *product;
 
+	/**
+	 * @supported_hdmi_ver: HDMI version the bridge is conformant with.
+	 * This is only relevant if @DRM_BRIDGE_OP_HDMI is set.
+	 */
+	enum hdmi_version supported_hdmi_ver;
+
 	/**
 	 * @supported_formats: Bitmask of @drm_output_color_format listing
 	 * supported output formats. This is only relevant if
Signature · 1 line
2.54.0
#19 lore raw

Re: [PATCH v8 03/39] drm/display: bridge_connector: Pass HDMI capabilities through caps struct

Quoted 9 lines · Cristian Ciocaltea

Switch drm_bridge_connector_init() to drmm_connector_hdmi_init_with_caps(), collecting the bridge's HDMI properties into a stack drm_connector_hdmi_caps so future HDMI 2.x capabilities can be plumbed without growing the argument list.

Introduce struct drm_bridge::supported_hdmi_ver to let bridges declare the HDMI specification version they are conformant with, and forward it to the connector layer through the new caps struct so HDMI 2.x features can be gated on real source capability rather than guesswork.

And it's left uninitialized by the bridges, which doesn't mean anything. If you don't want to touch all bridge drivers in one commit, please provide some migration path and hopefully get rid of it by the end of the series. At least, there should be a drm_warn() if the version in unsspecified.

Quoted 12 lines
---
 drivers/gpu/drm/display/drm_bridge_connector.c | 29 ++++++++++++++------------
 include/drm/drm_bridge.h                       |  6 ++++++
 2 files changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +0 -0
index 92f8a2d7aab4..796069dbf1a1 100644

drivers/gpu/drm/display/drm_bridge_connector.c struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, · line 829

Quoted 9 lines
drivers/gpu/drm/display/drm_bridge_connector.c +4 -2
@@ -823,8 +823,10 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 	struct drm_connector *connector;
 	struct i2c_adapter *ddc = NULL;
 	struct drm_bridge *panel_bridge __free(drm_bridge_put) = NULL;
-	unsigned int supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444);
-	unsigned int max_bpc = 8;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+	};

I'm really not sure that we need separate caps. But if we do, it would make sense to embed it as is in the drm_bridge instead of having the scattered fields.

Quoted 24 lines
drivers/gpu/drm/display/drm_bridge_connector.c +0 -0
 	bool support_hdcp = false;
 	int connector_type;
 	int ret;
include/drm/drm_bridge.h +6 -0
index 18f3db367dc1..2d8b5e4c64ba 100644
@@ -1176,6 +1176,12 @@ struct drm_bridge {
 	 */
 	const char *product;
 
+	/**
+	 * @supported_hdmi_ver: HDMI version the bridge is conformant with.
+	 * This is only relevant if @DRM_BRIDGE_OP_HDMI is set.
+	 */
+	enum hdmi_version supported_hdmi_ver;
+
 	/**
 	 * @supported_formats: Bitmask of @drm_output_color_format listing
 	 * supported output formats. This is only relevant if
Signature · 2 lines
-- 
2.54.0
Signature · 2 lines
With best wishes
Dmitry
#20 lore raw

Re: [PATCH v8 03/39] drm/display: bridge_connector: Pass HDMI capabilities through caps struct

Quoted 11 lines · Dmitry Baryshkov
Quoted 9 lines · Cristian Ciocaltea

Switch drm_bridge_connector_init() to drmm_connector_hdmi_init_with_caps(), collecting the bridge's HDMI properties into a stack drm_connector_hdmi_caps so future HDMI 2.x capabilities can be plumbed without growing the argument list.

Introduce struct drm_bridge::supported_hdmi_ver to let bridges declare the HDMI specification version they are conformant with, and forward it to the connector layer through the new caps struct so HDMI 2.x features can be gated on real source capability rather than guesswork.

Quoted 4 lines

And it's left uninitialized by the bridges, which doesn't mean anything. If you don't want to touch all bridge drivers in one commit, please provide some migration path and hopefully get rid of it by the end of the series.

Sure, one question though: at the end of the migration, would it be fine to stick with drmm_connector_hdmi_init_with_caps() and just drop drmm_connector_hdmi_init()? Otherwise I'll rename it back.

Quoted 2 lines

At least, there should be a drm_warn() if the version in unsspecified.

I’ll double-check if any use cases remain that can't be covered by this series.

Quoted 17 lines
Quoted 17 lines
---
 drivers/gpu/drm/display/drm_bridge_connector.c | 29 ++++++++++++++------------
 include/drm/drm_bridge.h                       |  6 ++++++
 2 files changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +0 -2
index 92f8a2d7aab4..796069dbf1a1 100644
@@ -823,8 +823,10 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 	struct drm_connector *connector;
 	struct i2c_adapter *ddc = NULL;
 	struct drm_bridge *panel_bridge __free(drm_bridge_put) = NULL;
-	unsigned int supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444);
-	unsigned int max_bpc = 8;
Quoted 8 lines

drivers/gpu/drm/display/drm_bridge_connector.c struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, · line 829

Quoted 4 lines
drivers/gpu/drm/display/drm_bridge_connector.c +4 -0
+	struct drm_connector_hdmi_caps caps = {
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+	};

I'm really not sure that we need separate caps. But if we do, it would make sense to embed it as is in the drm_bridge instead of having the scattered fields.

Ack.

Quoted 26 lines
Quoted 25 lines
drivers/gpu/drm/display/drm_bridge_connector.c +0 -0
 	bool support_hdcp = false;
 	int connector_type;
 	int ret;
include/drm/drm_bridge.h +6 -0
index 18f3db367dc1..2d8b5e4c64ba 100644
@@ -1176,6 +1176,12 @@ struct drm_bridge {
 	 */
 	const char *product;
 
+	/**
+	 * @supported_hdmi_ver: HDMI version the bridge is conformant with.
+	 * This is only relevant if @DRM_BRIDGE_OP_HDMI is set.
+	 */
+	enum hdmi_version supported_hdmi_ver;
+
 	/**
 	 * @supported_formats: Bitmask of @drm_output_color_format listing
 	 * supported output formats. This is only relevant if
Signature · 2 lines
-- 
2.54.0
maintainer
#21 lore raw

Re: [PATCH v8 03/39] drm/display: bridge_connector: Pass HDMI capabilities through caps struct

Quoted 12 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 9 lines · Cristian Ciocaltea

Switch drm_bridge_connector_init() to drmm_connector_hdmi_init_with_caps(), collecting the bridge's HDMI properties into a stack drm_connector_hdmi_caps so future HDMI 2.x capabilities can be plumbed without growing the argument list.

Introduce struct drm_bridge::supported_hdmi_ver to let bridges declare the HDMI specification version they are conformant with, and forward it to the connector layer through the new caps struct so HDMI 2.x features can be gated on real source capability rather than guesswork.

Quoted 8 lines
Quoted 4 lines

And it's left uninitialized by the bridges, which doesn't mean anything. If you don't want to touch all bridge drivers in one commit, please provide some migration path and hopefully get rid of it by the end of the series.

Sure, one question though: at the end of the migration, would it be fine to stick with drmm_connector_hdmi_init_with_caps() and just drop drmm_connector_hdmi_init()? Otherwise I'll rename it back.

Absolutely, it doesn't make any sense to keep both variants.

Maxime

#22 lore raw

Re: [PATCH v8 03/39] drm/display: bridge_connector: Pass HDMI capabilities through caps struct

Quoted 18 lines · Maxime Ripard
Quoted 17 lines · Cristian Ciocaltea
Quoted 15 lines · Dmitry Baryshkov
Quoted 9 lines · Cristian Ciocaltea

Switch drm_bridge_connector_init() to drmm_connector_hdmi_init_with_caps(), collecting the bridge's HDMI properties into a stack drm_connector_hdmi_caps so future HDMI 2.x capabilities can be plumbed without growing the argument list.

Introduce struct drm_bridge::supported_hdmi_ver to let bridges declare the HDMI specification version they are conformant with, and forward it to the connector layer through the new caps struct so HDMI 2.x features can be gated on real source capability rather than guesswork.

And it's left uninitialized by the bridges, which doesn't mean anything. If you don't want to touch all bridge drivers in one commit, please provide some migration path and hopefully get rid of it by the end of the series.

Quoted 5 lines
Quoted 3 lines

Sure, one question though: at the end of the migration, would it be fine to stick with drmm_connector_hdmi_init_with_caps() and just drop drmm_connector_hdmi_init()? Otherwise I'll rename it back.

Absolutely, it doesn't make any sense to keep both variants.

I was referring to whether option 3 might be the preferred choice in the context of the earlier patch discussion.

Cristian

#23 lore raw

Re: [PATCH v8 03/39] drm/display: bridge_connector: Pass HDMI capabilities through caps struct

Quoted 19 lines · Cristian Ciocaltea
Quoted 18 lines · Maxime Ripard
Quoted 17 lines · Cristian Ciocaltea
Quoted 15 lines · Dmitry Baryshkov
Quoted 9 lines · Cristian Ciocaltea

Switch drm_bridge_connector_init() to drmm_connector_hdmi_init_with_caps(), collecting the bridge's HDMI properties into a stack drm_connector_hdmi_caps so future HDMI 2.x capabilities can be plumbed without growing the argument list.

Introduce struct drm_bridge::supported_hdmi_ver to let bridges declare the HDMI specification version they are conformant with, and forward it to the connector layer through the new caps struct so HDMI 2.x features can be gated on real source capability rather than guesswork.

And it's left uninitialized by the bridges, which doesn't mean anything. If you don't want to touch all bridge drivers in one commit, please provide some migration path and hopefully get rid of it by the end of the series.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Sure, one question though: at the end of the migration, would it be fine to stick with drmm_connector_hdmi_init_with_caps() and just drop drmm_connector_hdmi_init()? Otherwise I'll rename it back.

Absolutely, it doesn't make any sense to keep both variants.

I was referring to whether option 3 might be the preferred choice in the context of the earlier patch discussion.

Plesae exuse my ignorance, what is option 3?

Signature · 2 lines
With best wishes
Dmitry
#24 lore raw

Re: [PATCH v8 03/39] drm/display: bridge_connector: Pass HDMI capabilities through caps struct

Quoted 24 lines · Dmitry Baryshkov
Quoted 23 lines · Cristian Ciocaltea
Quoted 22 lines · Maxime Ripard
Quoted 20 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 9 lines · Cristian Ciocaltea

Switch drm_bridge_connector_init() to drmm_connector_hdmi_init_with_caps(), collecting the bridge's HDMI properties into a stack drm_connector_hdmi_caps so future HDMI 2.x capabilities can be plumbed without growing the argument list.

Introduce struct drm_bridge::supported_hdmi_ver to let bridges declare the HDMI specification version they are conformant with, and forward it to the connector layer through the new caps struct so HDMI 2.x features can be gated on real source capability rather than guesswork.

Quoted 4 lines

And it's left uninitialized by the bridges, which doesn't mean anything. If you don't want to touch all bridge drivers in one commit, please provide some migration path and hopefully get rid of it by the end of the series.

Sure, one question though: at the end of the migration, would it be fine to stick with drmm_connector_hdmi_init_with_caps() and just drop drmm_connector_hdmi_init()? Otherwise I'll rename it back.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Absolutely, it doesn't make any sense to keep both variants.

I was referring to whether option 3 might be the preferred choice in the context of the earlier patch discussion.

Plesae exuse my ignorance, what is option 3?

The options discussed were:

1. Continue with drmm_connector_hdmi_init_with_caps() after removing the caps parameter, and then drop drmm_connector_hdmi_init() after the migration.
...
3. A variation of option 1: additionally rename drmm_connector_hdmi_init_with_caps() to drmm_connector_hdmi_init() after the migration.

In the end I went with a slightly different approach: temporarily renamed the original helper to drmm_connector_hdmi_ini2(), to let the new signature be introduced under the original name while callers were converted incrementally. Finally added a patch to remove *_ini2().

Note the transitional name had the same length, to avoid re-alignment churn and keep the diffs to a minimum.

Cristian

#25 lore raw

PATCH v8 4/39 drm/connector: Add HDMI 2.0 scrambler infrastructure

In reply to Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory
- A scrambler_needed flag to be managed by the hdmi state helpers based on the negotiated TMDS character rate and the source/sink scrambling capabilities
- A scrambler_enabled flag to track whether scrambling is currently active
- A delayed work item (scdc_work) with an associated callback (scdc_cb) to monitor sink-side scrambling status and retry the setup if the sink resets it

These are intended to be used by SCDC scrambling helpers to coordinate scrambling setup and teardown between the source driver and the DRM core.

---
 drivers/gpu/drm/drm_connector.c | 26 ++++++++++++--
 include/drm/drm_connector.h     | 77 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_connector.c +23 -3
index c7ce6b7bd8b0..deecfc582f09 100644
@@ -220,6 +220,19 @@ void drm_connector_free_work_fn(struct work_struct *work)
 	}
 }
 
+static void drm_connector_hdmi_scdc_work(struct work_struct *work)
+{
+	struct drm_connector *connector;
+	struct drm_connector_hdmi *hdmi;
+
+	hdmi = container_of(to_delayed_work(work), struct drm_connector_hdmi,
+			    scdc_work);
+	connector = container_of(hdmi, struct drm_connector, hdmi);
+
+	if (hdmi->scdc_cb)
+		hdmi->scdc_cb(connector);
+}
+
 static int drm_connector_init_only(struct drm_device *dev,
 				   struct drm_connector *connector,
 				   const struct drm_connector_funcs *funcs,
@@ -285,6 +298,7 @@ static int drm_connector_init_only(struct drm_device *dev,
 	mutex_init(&connector->edid_override_mutex);
 	mutex_init(&connector->hdmi.infoframes.lock);
 	mutex_init(&connector->hdmi_audio.lock);
+	INIT_DELAYED_WORK(&connector->hdmi.scdc_work, drm_connector_hdmi_scdc_work);
 	connector->edid_blob_ptr = NULL;
 	connector->epoch_counter = 0;
 	connector->tile_blob_ptr = NULL;
@@ -624,12 +638,18 @@ int drmm_connector_hdmi_init_with_caps(struct drm_device *dev,
 	 * inferred limit with the actual controller capability. A value of
 	 * zero keeps the default limit inferred from supported_hdmi_ver.
 	 */
-	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0)
+	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0) {
+		if (!hdmi_funcs->scrambler_enable ||
+		    !hdmi_funcs->scrambler_disable)
+			return -EINVAL;
+
+		connector->hdmi.scrambler_supported = true;
 		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
-	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3)
+	} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3) {
 		connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
-	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0)
+	} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0) {
 		connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
+	}
 
 	if (caps->max_tmds_char_rate) {
 		if (caps->max_tmds_char_rate > connector->hdmi.max_tmds_char_rate)
include/drm/drm_connector.h +77 -0

101 lines not on this page · raw message

Signature · 1 line
2.54.0
#26 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Missing delayed work cancellation causes use-after-free and memory corruption on hot-unplug --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing delayed work cancellation causes use-after-free and memory corruption on hot-unplug --

commit 4ff004f5a0501b0ac5dedcf3dbce4ba7bc01c710
Author: Cristian Ciocaltea <[email protected]>

drm/connector: Add HDMI 2.0 scrambler infrastructure

This commit introduces connector-level infrastructure to support HDMI 2.0 scrambling. It includes various capability flags and a new delayed work item (scdc_work) to monitor sink-side scrambling status.

Quoted 4 lines
drivers/gpu/drm/drm_connector.c +0 -0
index c7ce6b7bd8b0e..deecfc582f093 100644

[ ... ]

drivers/gpu/drm/drm_connector.c static int drm_connector_init_only(struct drm_device *dev, · line 304

Quoted 8 lines
drivers/gpu/drm/drm_connector.c +1 -0
@@ -285,6 +298,7 @@ static int drm_connector_init_only(struct drm_device *dev,
 	mutex_init(&connector->edid_override_mutex);
 	mutex_init(&connector->hdmi.infoframes.lock);
 	mutex_init(&connector->hdmi_audio.lock);
+	INIT_DELAYED_WORK(&connector->hdmi.scdc_work, drm_connector_hdmi_scdc_work);
 	connector->edid_blob_ptr = NULL;
 	connector->epoch_counter = 0;
 	connector->tile_blob_ptr = NULL;

[Severity: High]
Does this delayed work need to be explicitly cancelled during connector teardown?

If a device is hot-unplugged or the driver is unbound while the display is active and scrambling is enabled, the driver's atomic disable hooks might skip calling drm_connector_hdmi_disable_scrambling() (e.g., if drm_dev_enter() returns false on a disconnected device).

If the connector is then torn down while scdc_work is still queued, drm_connector_cleanup() will eventually be called, which zeros out the connector structure:

drm_connector_cleanup()

    ...
    memset(connector, 0, sizeof(*connector));

Overwriting an actively queued delayed_work (and its internal timer_list) with zeroes can corrupt the kernel's timer wheel and workqueue lists, leading to a use-after-free or kernel panic when the timer fires.

Should there be a cancel_delayed_work_sync(&connector->hdmi.scdc_work) added to drm_connector_cleanup() to prevent this?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#27 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

In reply to Cristian Ciocaltea
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

Quoted 52 lines

- A scrambler_needed flag to be managed by the hdmi state helpers based on the negotiated TMDS character rate and the source/sink scrambling capabilities
- A scrambler_enabled flag to track whether scrambling is currently active
- A delayed work item (scdc_work) with an associated callback (scdc_cb) to monitor sink-side scrambling status and retry the setup if the sink resets it

These are intended to be used by SCDC scrambling helpers to coordinate scrambling setup and teardown between the source driver and the DRM core.

---
 drivers/gpu/drm/drm_connector.c | 26 ++++++++++++--
 include/drm/drm_connector.h     | 77 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_connector.c +14 -0
index c7ce6b7bd8b0..deecfc582f09 100644
@@ -220,6 +220,19 @@ void drm_connector_free_work_fn(struct work_struct *work)
 	}
 }
 
+static void drm_connector_hdmi_scdc_work(struct work_struct *work)
+{
+	struct drm_connector *connector;
+	struct drm_connector_hdmi *hdmi;
+
+	hdmi = container_of(to_delayed_work(work), struct drm_connector_hdmi,
+			    scdc_work);
+	connector = container_of(hdmi, struct drm_connector, hdmi);
+
+	if (hdmi->scdc_cb)
+		hdmi->scdc_cb(connector);
+}
+
 static int drm_connector_init_only(struct drm_device *dev,
 				   struct drm_connector *connector,
 				   const struct drm_connector_funcs *funcs,
@@ -285,6 +298,7 @@ static int drm_connector_init_only(struct drm_device *dev,
 	mutex_init(&connector->edid_override_mutex);
 	mutex_init(&connector->hdmi.infoframes.lock);
 	mutex_init(&connector->hdmi_audio.lock);
+	INIT_DELAYED_WORK(&connector->hdmi.scdc_work, drm_connector_hdmi_scdc_work);
 	connector->edid_blob_ptr = NULL;
 	connector->epoch_counter = 0;
 	connector->tile_blob_ptr = NULL;

drivers/gpu/drm/drm_connector.c int drmm_connector_hdmi_init_with_caps(struct drm_device *dev, · line 640

Quoted 3 lines
drivers/gpu/drm/drm_connector.c +0 -0
@@ -624,12 +638,18 @@ int drmm_connector_hdmi_init_with_caps(struct drm_device *dev,
 	 * inferred limit with the actual controller capability. A value of
 	 * zero keeps the default limit inferred from supported_hdmi_ver.
 	 */

Here we need to check that the driver doesn't set only one callback of the pair.

Quoted 16 lines
drivers/gpu/drm/drm_connector.c +9 -3
-	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0)
+	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0) {
+		if (!hdmi_funcs->scrambler_enable ||
+		    !hdmi_funcs->scrambler_disable)
+			return -EINVAL;
+
+		connector->hdmi.scrambler_supported = true;
 		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
-	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3)
+	} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3) {
 		connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
-	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0)
+	} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0) {
 		connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
+	}
 

drivers/gpu/drm/drm_connector.c int drmm_connector_hdmi_init_with_caps(struct drm_device *dev,

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +8 -0
 	if (caps->max_tmds_char_rate) {
 		if (caps->max_tmds_char_rate > connector->hdmi.max_tmds_char_rate)
+
+	/** @scdc_cb: Callback to be invoked as part of @scdc_work.
+	 *
+	 * Currently used to monitor sink-side scrambling status and retry
+	 * setup if the sink resets it.
+	 *
+	 * This is assigned by the framework when making use of
+	 * drm_connector_hdmi_enable_scrambling() helper.

No such helper. Also, please explain in the commit message, why do we need to keep it configurable. Why the default is not enough?

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +3 -0
+	 */
+	void (*scdc_cb)(struct drm_connector *connector);
+
 	/**
 	 * @funcs: HDMI connector Control Functions
 	 */
Signature · 2 lines
-- 
2.54.0
Signature · 2 lines
With best wishes
Dmitry
#28 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Quoted 11 lines · Dmitry Baryshkov
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

The flag is intended to be set only within drmm_connector_hdmi_init_with_caps() when drivers advertise HDMI 2.x capability, in which case it also ensures the callbacks are provided.

We could drop the flag and instead have the init helper clear the callbacks if they were provided for HDMI 1.x. This might slightly reduce code readability, as it relies on checking the presence of individual callbacks - especially since we plan to extend this further with HDMI 2.1 support, providing four or five additional FRL-specific callbacks.

That said, I don’t have a strong opinion on this.

Quoted 50 lines
Quoted 50 lines

- A scrambler_needed flag to be managed by the hdmi state helpers based on the negotiated TMDS character rate and the source/sink scrambling capabilities
- A scrambler_enabled flag to track whether scrambling is currently active
- A delayed work item (scdc_work) with an associated callback (scdc_cb) to monitor sink-side scrambling status and retry the setup if the sink resets it

These are intended to be used by SCDC scrambling helpers to coordinate scrambling setup and teardown between the source driver and the DRM core.

---
 drivers/gpu/drm/drm_connector.c | 26 ++++++++++++--
 include/drm/drm_connector.h     | 77 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_connector.c +14 -0
index c7ce6b7bd8b0..deecfc582f09 100644
@@ -220,6 +220,19 @@ void drm_connector_free_work_fn(struct work_struct *work)
 	}
 }
 
+static void drm_connector_hdmi_scdc_work(struct work_struct *work)
+{
+	struct drm_connector *connector;
+	struct drm_connector_hdmi *hdmi;
+
+	hdmi = container_of(to_delayed_work(work), struct drm_connector_hdmi,
+			    scdc_work);
+	connector = container_of(hdmi, struct drm_connector, hdmi);
+
+	if (hdmi->scdc_cb)
+		hdmi->scdc_cb(connector);
+}
+
 static int drm_connector_init_only(struct drm_device *dev,
 				   struct drm_connector *connector,
 				   const struct drm_connector_funcs *funcs,
@@ -285,6 +298,7 @@ static int drm_connector_init_only(struct drm_device *dev,
 	mutex_init(&connector->edid_override_mutex);
 	mutex_init(&connector->hdmi.infoframes.lock);
 	mutex_init(&connector->hdmi_audio.lock);
+	INIT_DELAYED_WORK(&connector->hdmi.scdc_work, drm_connector_hdmi_scdc_work);
 	connector->edid_blob_ptr = NULL;
 	connector->epoch_counter = 0;
Quoted 8 lines

drivers/gpu/drm/drm_connector.c int drmm_connector_hdmi_init_with_caps(struct drm_device *dev, · line 640

Quoted 5 lines
drivers/gpu/drm/drm_connector.c +0 -0
 	connector->tile_blob_ptr = NULL;
@@ -624,12 +638,18 @@ int drmm_connector_hdmi_init_with_caps(struct drm_device *dev,
 	 * inferred limit with the actual controller capability. A value of
 	 * zero keeps the default limit inferred from supported_hdmi_ver.
 	 */

Here we need to check that the driver doesn't set only one callback of the pair.

Is anything missing from the check below? I chose to ignore the presence of the callbacks in HDMI 1.x cases.

Quoted 17 lines
Quoted 17 lines
drivers/gpu/drm/drm_connector.c +9 -3
-	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0)
+	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0) {
+		if (!hdmi_funcs->scrambler_enable ||
+		    !hdmi_funcs->scrambler_disable)
+			return -EINVAL;
+
+		connector->hdmi.scrambler_supported = true;
 		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
-	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3)
+	} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3) {
 		connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
-	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0)
+	} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0) {
 		connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
+	}
 
Quoted 12 lines

drivers/gpu/drm/drm_connector.c int drmm_connector_hdmi_init_with_caps(struct drm_device *dev,

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +8 -0
 	if (caps->max_tmds_char_rate) {
 		if (caps->max_tmds_char_rate > connector->hdmi.max_tmds_char_rate)
+
+	/** @scdc_cb: Callback to be invoked as part of @scdc_work.
+	 *
+	 * Currently used to monitor sink-side scrambling status and retry
+	 * setup if the sink resets it.
+	 *
+	 * This is assigned by the framework when making use of
+	 * drm_connector_hdmi_enable_scrambling() helper.

No such helper.

Right, I'll drop the reference to the helper name, as that's added later in the series.

Quoted 2 lines

Also, please explain in the commit message, why do we need to keep it configurable. Why the default is not enough?

We will need a separate callback to support HDMI 2.1, i.e. for link training management. I’ll update the commit message accordingly.

Thanks,
Cristian

maintainer
#29 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Quoted 29 lines · Cristian Ciocaltea
Quoted 16 lines
Quoted 16 lines
Quoted 1 line
drivers/gpu/drm/drm_connector.c +0 -1
-	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0)
drivers/gpu/drm/drm_connector.c +9 -2
+	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0) {
+		if (!hdmi_funcs->scrambler_enable ||
+		    !hdmi_funcs->scrambler_disable)
+			return -EINVAL;
+
+		connector->hdmi.scrambler_supported = true;
 		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
-	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3)
+	} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3) {
 		connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
-	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0)
+	} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0) {
 		connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
+	}
Quoted 12 lines

include/drm/drm_connector.h struct drm_connector_hdmi { · line 2174

Quoted 10 lines
include/drm/drm_connector.h +8 -0
 	if (caps->max_tmds_char_rate) {
 		if (caps->max_tmds_char_rate > connector->hdmi.max_tmds_char_rate)
+
+	/** @scdc_cb: Callback to be invoked as part of @scdc_work.
+	 *
+	 * Currently used to monitor sink-side scrambling status and retry
+	 * setup if the sink resets it.
+	 *
+	 * This is assigned by the framework when making use of
+	 * drm_connector_hdmi_enable_scrambling() helper.

No such helper.

Quoted 8 lines

Right, I'll drop the reference to the helper name, as that's added later in the series.

Quoted 2 lines

Also, please explain in the commit message, why do we need to keep it configurable. Why the default is not enough?

We will need a separate callback to support HDMI 2.1, i.e. for link training management. I’ll update the commit message accordingly.

I think I'm equally confused as Dmitry here. If scdc_cb is only called if we're sending scrambled pixels but the monitor doesn't acknowledge it initially, then the only thing we need to do is "if the scrambler's enabled, call drm_scdc_set_scrambling()", then we don't need to set a callback. And even if we ever need to deal with HDMI link training, then we can still have the same function but with a couple of branches more.

Maxime

#30 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Quoted 39 lines · Maxime Ripard
Quoted 29 lines · Cristian Ciocaltea
Quoted 16 lines
Quoted 16 lines
Quoted 1 line
drivers/gpu/drm/drm_connector.c +0 -1
-	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0)
drivers/gpu/drm/drm_connector.c +9 -2
+	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0) {
+		if (!hdmi_funcs->scrambler_enable ||
+		    !hdmi_funcs->scrambler_disable)
+			return -EINVAL;
+
+		connector->hdmi.scrambler_supported = true;
 		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
-	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3)
+	} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3) {
 		connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
-	else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0)
+	} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0) {
 		connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
+	}
Quoted 12 lines

include/drm/drm_connector.h struct drm_connector_hdmi { · line 2174

Quoted 10 lines
include/drm/drm_connector.h +8 -0
 	if (caps->max_tmds_char_rate) {
 		if (caps->max_tmds_char_rate > connector->hdmi.max_tmds_char_rate)
+
+	/** @scdc_cb: Callback to be invoked as part of @scdc_work.
+	 *
+	 * Currently used to monitor sink-side scrambling status and retry
+	 * setup if the sink resets it.
+	 *
+	 * This is assigned by the framework when making use of
+	 * drm_connector_hdmi_enable_scrambling() helper.

No such helper.

Quoted 8 lines

Right, I'll drop the reference to the helper name, as that's added later in the series.

Quoted 2 lines

Also, please explain in the commit message, why do we need to keep it configurable. Why the default is not enough?

We will need a separate callback to support HDMI 2.1, i.e. for link training management. I’ll update the commit message accordingly.

Quoted 6 lines

I think I'm equally confused as Dmitry here. If scdc_cb is only called if we're sending scrambled pixels but the monitor doesn't acknowledge it initially, then the only thing we need to do is "if the scrambler's enabled, call drm_scdc_set_scrambling()", then we don't need to set a callback. And even if we ever need to deal with HDMI link training, then we can still have the same function but with a couple of branches more.

I think I overengineered this by trying to keep the SCDC-related bits as much as possible in drm_hdmi_helper.c. I’ll drop this callback and move the logic into drm_connector_hdmi_scdc_work().

Cristian

#31 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

In reply to Cristian Ciocaltea
Quoted 17 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

The flag is intended to be set only within drmm_connector_hdmi_init_with_caps() when drivers advertise HDMI 2.x capability, in which case it also ensures the callbacks are provided.

Quoted 5 lines

We could drop the flag and instead have the init helper clear the callbacks if they were provided for HDMI 1.x. This might slightly reduce code readability, as it relies on checking the presence of individual callbacks - especially since we plan to extend this further with HDMI 2.1 support, providing four or five additional FRL-specific callbacks.

I tried to replace the flag with a helper that checks the presence of (one of) the callbacks, but it's not straightforward to unset those for non-HDMI 2.x cases since the hdmi_funcs argument is immutable.

Also, rejecting that use case is less than ideal, since we would restrict reusing the struct instance, e.g. to support HW revisions with varying scrambling capabilities.

Therefore, I'd keep the flag for now.

Cristian

maintainer
#32 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Quoted 24 lines · Cristian Ciocaltea
Quoted 17 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

The flag is intended to be set only within drmm_connector_hdmi_init_with_caps() when drivers advertise HDMI 2.x capability, in which case it also ensures the callbacks are provided.

Quoted 5 lines

We could drop the flag and instead have the init helper clear the callbacks if they were provided for HDMI 1.x. This might slightly reduce code readability, as it relies on checking the presence of individual callbacks - especially since we plan to extend this further with HDMI 2.1 support, providing four or five additional FRL-specific callbacks.

Quoted 3 lines

I tried to replace the flag with a helper that checks the presence of (one of) the callbacks, but it's not straightforward to unset those for non-HDMI 2.x cases since the hdmi_funcs argument is immutable.

I'm not sure why we would need to unset them. If the driver states that it support HDMI 2.0, then it needs to be there, if it doesn't, then who cares? it's not going to be used. We can log a warning that it's inconsistent I guess, but there's no need to actively remove it.

Quoted 3 lines

Also, rejecting that use case is less than ideal, since we would restrict reusing the struct instance, e.g. to support HW revisions with varying scrambling capabilities.

We can have several structures instances in that case.

Maxime

#33 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Quoted 25 lines · Maxime Ripard
Quoted 24 lines · Cristian Ciocaltea
Quoted 22 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

The flag is intended to be set only within drmm_connector_hdmi_init_with_caps() when drivers advertise HDMI 2.x capability, in which case it also ensures the callbacks are provided.

We could drop the flag and instead have the init helper clear the callbacks if they were provided for HDMI 1.x. This might slightly reduce code readability, as it relies on checking the presence of individual callbacks - especially since we plan to extend this further with HDMI 2.1 support, providing four or five additional FRL-specific callbacks.

Quoted 8 lines
Quoted 3 lines

I tried to replace the flag with a helper that checks the presence of (one of) the callbacks, but it's not straightforward to unset those for non-HDMI 2.x cases since the hdmi_funcs argument is immutable.

I'm not sure why we would need to unset them. If the driver states that it support HDMI 2.0, then it needs to be there, if it doesn't, then who cares? it's not going to be used. We can log a warning that it's inconsistent I guess, but there's no need to actively remove it.

I was trying to address the use case where drivers provide the scrambler callbacks despite not supporting HDMI 2.0. If we replace the scrambler_supported flag with a helper checking the presence of the scrambler callbacks, then we would need to ensure the callbacks do not exist in this case. Since we cannot/don't want to unset them, the remaining solution would be to bail out in init().

Quoted 5 lines
Quoted 3 lines

Also, rejecting that use case is less than ideal, since we would restrict reusing the struct instance, e.g. to support HW revisions with varying scrambling capabilities.

We can have several structures instances in that case.

Fair enough, I wasn't sure if that'd be an acceptable drawback.

Thanks,
Cristian

maintainer
#34 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Quoted 30 lines · Cristian Ciocaltea
Quoted 29 lines · Maxime Ripard
Quoted 27 lines · Cristian Ciocaltea
Quoted 17 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

The flag is intended to be set only within drmm_connector_hdmi_init_with_caps() when drivers advertise HDMI 2.x capability, in which case it also ensures the callbacks are provided.

Quoted 5 lines

We could drop the flag and instead have the init helper clear the callbacks if they were provided for HDMI 1.x. This might slightly reduce code readability, as it relies on checking the presence of individual callbacks - especially since we plan to extend this further with HDMI 2.1 support, providing four or five additional FRL-specific callbacks.

I tried to replace the flag with a helper that checks the presence of (one of) the callbacks, but it's not straightforward to unset those for non-HDMI 2.x cases since the hdmi_funcs argument is immutable.

Quoted 7 lines
Quoted 4 lines

I'm not sure why we would need to unset them. If the driver states that it support HDMI 2.0, then it needs to be there, if it doesn't, then who cares? it's not going to be used. We can log a warning that it's inconsistent I guess, but there's no need to actively remove it.

I was trying to address the use case where drivers provide the scrambler callbacks despite not supporting HDMI 2.0.

Scrambling got introduced with HDMI 2.0. That doesn't make sense, but it's not a total deal breaker, it's just going to be here unused. Hence why I was suggesting to put a warning there if you wanted to.

Quoted 3 lines

If we replace the scrambler_supported flag with a helper checking the presence of the scrambler callbacks, then we would need to ensure the callbacks do not exist in this case.

Keep it simple:

if (hdmi_version >= HDMI_VERSION_2_0)
if (funcs->scrambler_enable)

      hdmi->scramblers_supported = true
   else
      return -EINVAL
else
    drm_warn(warn, "Inconsistent HDMI version");

We don't need anything more than that.

Maxime

#35 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Quoted 51 lines · Maxime Ripard
Quoted 30 lines · Cristian Ciocaltea
Quoted 29 lines · Maxime Ripard
Quoted 27 lines · Cristian Ciocaltea
Quoted 17 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

The flag is intended to be set only within drmm_connector_hdmi_init_with_caps() when drivers advertise HDMI 2.x capability, in which case it also ensures the callbacks are provided.

Quoted 5 lines

We could drop the flag and instead have the init helper clear the callbacks if they were provided for HDMI 1.x. This might slightly reduce code readability, as it relies on checking the presence of individual callbacks - especially since we plan to extend this further with HDMI 2.1 support, providing four or five additional FRL-specific callbacks.

I tried to replace the flag with a helper that checks the presence of (one of) the callbacks, but it's not straightforward to unset those for non-HDMI 2.x cases since the hdmi_funcs argument is immutable.

Quoted 7 lines
Quoted 4 lines

I'm not sure why we would need to unset them. If the driver states that it support HDMI 2.0, then it needs to be there, if it doesn't, then who cares? it's not going to be used. We can log a warning that it's inconsistent I guess, but there's no need to actively remove it.

I was trying to address the use case where drivers provide the scrambler callbacks despite not supporting HDMI 2.0.

Scrambling got introduced with HDMI 2.0. That doesn't make sense, but it's not a total deal breaker, it's just going to be here unused. Hence why I was suggesting to put a warning there if you wanted to.

Quoted 3 lines

If we replace the scrambler_supported flag with a helper checking the presence of the scrambler callbacks, then we would need to ensure the callbacks do not exist in this case.

Keep it simple:

if (hdmi_version >= HDMI_VERSION_2_0)
if (funcs->scrambler_enable)

Quoted 7 lines
      hdmi->scramblers_supported = true
   else
      return -EINVAL
else
    drm_warn(warn, "Inconsistent HDMI version");

We don't need anything more than that.

I dropped the scrambler_supported flag and introduced a helper:

static inline bool drm_connector_hdmi_scrambler_supported(struct drm_connector *connector)

{
	return connector->hdmi.funcs && connector->hdmi.funcs->scrambler_enable;
}

Therefore we need to ensure the callbacks are not set in the HDMI 1.x cases:

int drmm_connector_hdmi_init_with_caps()

{
	...
	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0) {
		if (!hdmi_funcs->scrambler_enable ||
		    !hdmi_funcs->scrambler_disable)
			return -EINVAL;

		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
	} else {
		/*
		 * Scrambler callbacks are only valid for connectors advertising
		 * HDMI 2.0 capability. drm_connector_hdmi_scrambler_supported()
		 * relies on their presence to report scrambling support.
		 */
		if (hdmi_funcs->scrambler_enable ||
		    hdmi_funcs->scrambler_disable)
			return -EINVAL;

		if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3) {
			connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
		} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0) {
			connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
		}
	}
	...
}
maintainer
#36 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Quoted 58 lines · Cristian Ciocaltea
Quoted 57 lines · Maxime Ripard
Quoted 30 lines · Cristian Ciocaltea
Quoted 29 lines · Maxime Ripard
Quoted 27 lines · Cristian Ciocaltea
Quoted 17 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

The flag is intended to be set only within drmm_connector_hdmi_init_with_caps() when drivers advertise HDMI 2.x capability, in which case it also ensures the callbacks are provided.

Quoted 5 lines

We could drop the flag and instead have the init helper clear the callbacks if they were provided for HDMI 1.x. This might slightly reduce code readability, as it relies on checking the presence of individual callbacks - especially since we plan to extend this further with HDMI 2.1 support, providing four or five additional FRL-specific callbacks.

I tried to replace the flag with a helper that checks the presence of (one of) the callbacks, but it's not straightforward to unset those for non-HDMI 2.x cases since the hdmi_funcs argument is immutable.

Quoted 7 lines
Quoted 4 lines

I'm not sure why we would need to unset them. If the driver states that it support HDMI 2.0, then it needs to be there, if it doesn't, then who cares? it's not going to be used. We can log a warning that it's inconsistent I guess, but there's no need to actively remove it.

I was trying to address the use case where drivers provide the scrambler callbacks despite not supporting HDMI 2.0.

Scrambling got introduced with HDMI 2.0. That doesn't make sense, but it's not a total deal breaker, it's just going to be here unused. Hence why I was suggesting to put a warning there if you wanted to.

Quoted 3 lines

If we replace the scrambler_supported flag with a helper checking the presence of the scrambler callbacks, then we would need to ensure the callbacks do not exist in this case.

Keep it simple:

if (hdmi_version >= HDMI_VERSION_2_0)
if (funcs->scrambler_enable)

      hdmi->scramblers_supported = true
   else
      return -EINVAL
else
    drm_warn(warn, "Inconsistent HDMI version");
Quoted 8 lines
Quoted 1 line

We don't need anything more than that.

I dropped the scrambler_supported flag and introduced a helper:

static inline bool drm_connector_hdmi_scrambler_supported(struct drm_connector *connector)

{
	return connector->hdmi.funcs && connector->hdmi.funcs->scrambler_enable;

I'd add disable to that test

Quoted 21 lines

}

Therefore we need to ensure the callbacks are not set in the HDMI 1.x cases:

int drmm_connector_hdmi_init_with_caps()

{
	...
	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0) {
		if (!hdmi_funcs->scrambler_enable ||
		    !hdmi_funcs->scrambler_disable)
			return -EINVAL;

		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
	} else {
		/*
		 * Scrambler callbacks are only valid for connectors advertising
		 * HDMI 2.0 capability. drm_connector_hdmi_scrambler_supported()
		 * relies on their presence to report scrambling support.
		 */
		if (hdmi_funcs->scrambler_enable ||
		    hdmi_funcs->scrambler_disable)
Quoted 8 lines
			return -EINVAL;

		if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3) {
			connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
		} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0) {
			connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
		}
	}

Drivers might have a lower limit than the max allowed by the spec. It should be provided by the driver, possibly optionally with a fallback to what the spec states?

Maxime

#37 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Quoted 61 lines · Maxime Ripard
Quoted 60 lines · Cristian Ciocaltea
Quoted 58 lines · Maxime Ripard
Quoted 30 lines · Cristian Ciocaltea
Quoted 29 lines · Maxime Ripard
Quoted 27 lines · Cristian Ciocaltea
Quoted 17 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

The flag is intended to be set only within drmm_connector_hdmi_init_with_caps() when drivers advertise HDMI 2.x capability, in which case it also ensures the callbacks are provided.

Quoted 5 lines

We could drop the flag and instead have the init helper clear the callbacks if they were provided for HDMI 1.x. This might slightly reduce code readability, as it relies on checking the presence of individual callbacks - especially since we plan to extend this further with HDMI 2.1 support, providing four or five additional FRL-specific callbacks.

I tried to replace the flag with a helper that checks the presence of (one of) the callbacks, but it's not straightforward to unset those for non-HDMI 2.x cases since the hdmi_funcs argument is immutable.

Quoted 7 lines
Quoted 4 lines

I'm not sure why we would need to unset them. If the driver states that it support HDMI 2.0, then it needs to be there, if it doesn't, then who cares? it's not going to be used. We can log a warning that it's inconsistent I guess, but there's no need to actively remove it.

I was trying to address the use case where drivers provide the scrambler callbacks despite not supporting HDMI 2.0.

Scrambling got introduced with HDMI 2.0. That doesn't make sense, but it's not a total deal breaker, it's just going to be here unused. Hence why I was suggesting to put a warning there if you wanted to.

Quoted 3 lines

If we replace the scrambler_supported flag with a helper checking the presence of the scrambler callbacks, then we would need to ensure the callbacks do not exist in this case.

Keep it simple:

if (hdmi_version >= HDMI_VERSION_2_0)
if (funcs->scrambler_enable)

      hdmi->scramblers_supported = true
   else
      return -EINVAL
else
    drm_warn(warn, "Inconsistent HDMI version");

We don't need anything more than that.

Quoted 8 lines
Quoted 6 lines

I dropped the scrambler_supported flag and introduced a helper:

static inline bool drm_connector_hdmi_scrambler_supported(struct drm_connector *connector)

{
	return connector->hdmi.funcs && connector->hdmi.funcs->scrambler_enable;

I'd add disable to that test

If scrambler_enable is present, scrambler_disable is also present, as guaranteed by the init validation below. I assume you'd like to have it added regardless, to improve code readability, which is a fair point.

Quoted 30 lines
Quoted 21 lines

}

Therefore we need to ensure the callbacks are not set in the HDMI 1.x cases:

int drmm_connector_hdmi_init_with_caps()

{
	...
	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0) {
		if (!hdmi_funcs->scrambler_enable ||
		    !hdmi_funcs->scrambler_disable)
			return -EINVAL;

		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
	} else {
		/*
		 * Scrambler callbacks are only valid for connectors advertising
		 * HDMI 2.0 capability. drm_connector_hdmi_scrambler_supported()
		 * relies on their presence to report scrambling support.
		 */
		if (hdmi_funcs->scrambler_enable ||
		    hdmi_funcs->scrambler_disable)
Quoted 8 lines
			return -EINVAL;

		if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3) {
			connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
		} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0) {
			connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
		}
	}
Quoted 3 lines

Drivers might have a lower limit than the max allowed by the spec. It should be provided by the driver, possibly optionally with a fallback to what the spec states?

Yes, this has been already part of patch 2 (also added an error message to help with debugging):

	if (caps->max_tmds_char_rate) {
		if (caps->max_tmds_char_rate > connector->hdmi.max_tmds_char_rate) {
			drm_err(dev, "Enforced max_tmds_char_rate exceeds %llu spec limit\n",
				connector->hdmi.max_tmds_char_rate);
			return -EINVAL;
		}
		connector->hdmi.max_tmds_char_rate = caps->max_tmds_char_rate;
	}

Regards,
Cristian

maintainer
#38 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Quoted 112 lines · Cristian Ciocaltea
Quoted 61 lines · Maxime Ripard
Quoted 60 lines · Cristian Ciocaltea
Quoted 58 lines · Maxime Ripard
Quoted 30 lines · Cristian Ciocaltea
Quoted 29 lines · Maxime Ripard
Quoted 27 lines · Cristian Ciocaltea
Quoted 17 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

The flag is intended to be set only within drmm_connector_hdmi_init_with_caps() when drivers advertise HDMI 2.x capability, in which case it also ensures the callbacks are provided.

Quoted 5 lines

We could drop the flag and instead have the init helper clear the callbacks if they were provided for HDMI 1.x. This might slightly reduce code readability, as it relies on checking the presence of individual callbacks - especially since we plan to extend this further with HDMI 2.1 support, providing four or five additional FRL-specific callbacks.

I tried to replace the flag with a helper that checks the presence of (one of) the callbacks, but it's not straightforward to unset those for non-HDMI 2.x cases since the hdmi_funcs argument is immutable.

Quoted 7 lines
Quoted 4 lines

I'm not sure why we would need to unset them. If the driver states that it support HDMI 2.0, then it needs to be there, if it doesn't, then who cares? it's not going to be used. We can log a warning that it's inconsistent I guess, but there's no need to actively remove it.

I was trying to address the use case where drivers provide the scrambler callbacks despite not supporting HDMI 2.0.

Scrambling got introduced with HDMI 2.0. That doesn't make sense, but it's not a total deal breaker, it's just going to be here unused. Hence why I was suggesting to put a warning there if you wanted to.

Quoted 3 lines

If we replace the scrambler_supported flag with a helper checking the presence of the scrambler callbacks, then we would need to ensure the callbacks do not exist in this case.

Keep it simple:

if (hdmi_version >= HDMI_VERSION_2_0)
if (funcs->scrambler_enable)

      hdmi->scramblers_supported = true
   else
      return -EINVAL
else
    drm_warn(warn, "Inconsistent HDMI version");

We don't need anything more than that.

Quoted 8 lines
Quoted 6 lines

I dropped the scrambler_supported flag and introduced a helper:

static inline bool drm_connector_hdmi_scrambler_supported(struct drm_connector *connector)

{
	return connector->hdmi.funcs && connector->hdmi.funcs->scrambler_enable;

I'd add disable to that test

If scrambler_enable is present, scrambler_disable is also present, as guaranteed by the init validation below. I assume you'd like to have it added regardless, to improve code readability, which is a fair point.

Quoted 30 lines
Quoted 21 lines

}

Therefore we need to ensure the callbacks are not set in the HDMI 1.x cases:

int drmm_connector_hdmi_init_with_caps()

{
	...
	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0) {
		if (!hdmi_funcs->scrambler_enable ||
		    !hdmi_funcs->scrambler_disable)
			return -EINVAL;

		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
	} else {
		/*
		 * Scrambler callbacks are only valid for connectors advertising
		 * HDMI 2.0 capability. drm_connector_hdmi_scrambler_supported()
		 * relies on their presence to report scrambling support.
		 */
		if (hdmi_funcs->scrambler_enable ||
		    hdmi_funcs->scrambler_disable)
Quoted 8 lines
			return -EINVAL;

		if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3) {
			connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
		} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0) {
			connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
		}
	}
Quoted 3 lines

Drivers might have a lower limit than the max allowed by the spec. It should be provided by the driver, possibly optionally with a fallback to what the spec states?

Yes, this has been already part of patch 2 (also added an error message to help with debugging):

Quoted 8 lines
	if (caps->max_tmds_char_rate) {
		if (caps->max_tmds_char_rate > connector->hdmi.max_tmds_char_rate) {
			drm_err(dev, "Enforced max_tmds_char_rate exceeds %llu spec limit\n",
				connector->hdmi.max_tmds_char_rate);
			return -EINVAL;
		}
		connector->hdmi.max_tmds_char_rate = caps->max_tmds_char_rate;
	}

Ah right, my bad. Thanks!
Maxime

#39 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

In reply to Maxime Ripard
Quoted 61 lines · Maxime Ripard
Quoted 60 lines · Cristian Ciocaltea
Quoted 58 lines · Maxime Ripard
Quoted 30 lines · Cristian Ciocaltea
Quoted 29 lines · Maxime Ripard
Quoted 27 lines · Cristian Ciocaltea
Quoted 17 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

The flag is intended to be set only within drmm_connector_hdmi_init_with_caps() when drivers advertise HDMI 2.x capability, in which case it also ensures the callbacks are provided.

Quoted 5 lines

We could drop the flag and instead have the init helper clear the callbacks if they were provided for HDMI 1.x. This might slightly reduce code readability, as it relies on checking the presence of individual callbacks - especially since we plan to extend this further with HDMI 2.1 support, providing four or five additional FRL-specific callbacks.

I tried to replace the flag with a helper that checks the presence of (one of) the callbacks, but it's not straightforward to unset those for non-HDMI 2.x cases since the hdmi_funcs argument is immutable.

Quoted 7 lines
Quoted 4 lines

I'm not sure why we would need to unset them. If the driver states that it support HDMI 2.0, then it needs to be there, if it doesn't, then who cares? it's not going to be used. We can log a warning that it's inconsistent I guess, but there's no need to actively remove it.

I was trying to address the use case where drivers provide the scrambler callbacks despite not supporting HDMI 2.0.

Scrambling got introduced with HDMI 2.0. That doesn't make sense, but it's not a total deal breaker, it's just going to be here unused. Hence why I was suggesting to put a warning there if you wanted to.

Quoted 3 lines

If we replace the scrambler_supported flag with a helper checking the presence of the scrambler callbacks, then we would need to ensure the callbacks do not exist in this case.

Keep it simple:

if (hdmi_version >= HDMI_VERSION_2_0)
if (funcs->scrambler_enable)

      hdmi->scramblers_supported = true
   else
      return -EINVAL
else
    drm_warn(warn, "Inconsistent HDMI version");

We don't need anything more than that.

Quoted 8 lines
Quoted 6 lines

I dropped the scrambler_supported flag and introduced a helper:

static inline bool drm_connector_hdmi_scrambler_supported(struct drm_connector *connector)

{
	return connector->hdmi.funcs && connector->hdmi.funcs->scrambler_enable;

I'd add disable to that test

I'd make it an error, if there is only scrambler_enable without scrambler_disable (or vice versa).

Quoted 31 lines
Quoted 22 lines

}

Therefore we need to ensure the callbacks are not set in the HDMI 1.x cases:

int drmm_connector_hdmi_init_with_caps()

{
	...
	if (caps->supported_hdmi_ver >= HDMI_VERSION_2_0) {
		if (!hdmi_funcs->scrambler_enable ||
		    !hdmi_funcs->scrambler_disable)
			return -EINVAL;

		connector->hdmi.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ;
	} else {
		/*
		 * Scrambler callbacks are only valid for connectors advertising
		 * HDMI 2.0 capability. drm_connector_hdmi_scrambler_supported()
		 * relies on their presence to report scrambling support.
		 */
		if (hdmi_funcs->scrambler_enable ||
		    hdmi_funcs->scrambler_disable)
Quoted 8 lines
			return -EINVAL;

		if (caps->supported_hdmi_ver >= HDMI_VERSION_1_3) {
			connector->hdmi.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
		} else if (caps->supported_hdmi_ver >= HDMI_VERSION_1_0) {
			connector->hdmi.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ;
		}
	}
Quoted 3 lines

Drivers might have a lower limit than the max allowed by the spec. It should be provided by the driver, possibly optionally with a fallback to what the spec states?

Yes, likely it can be handled with the if !connector->hdmi.max_tmds_char_rate.

Signature · 2 lines
With best wishes
Dmitry
#40 lore raw

Re: [PATCH v8 04/39] drm/connector: Add HDMI 2.0 scrambler infrastructure

Quoted 69 lines · Dmitry Baryshkov
Quoted 68 lines · Maxime Ripard
Quoted 66 lines · Cristian Ciocaltea
Quoted 51 lines · Maxime Ripard
Quoted 30 lines · Cristian Ciocaltea
Quoted 29 lines · Maxime Ripard
Quoted 27 lines · Cristian Ciocaltea
Quoted 17 lines · Cristian Ciocaltea
Quoted 11 lines · Dmitry Baryshkov
Quoted 6 lines · Cristian Ciocaltea

Add the connector-level infrastructure to support HDMI 2.0 scrambling:

- A scrambler_supported flag to indicate whether the source supports the scrambling capability, in which case the newly introduced .scrambler_{enable|disable}() callbacks in drm_connector_hdmi_funcs are mandatory

Do we need a flag? What would it mean if the flag is set, but the callbacks are not? Can we drop the flag and use the presence of the callbacks as a way to identify that scrambler is enabled?

The flag is intended to be set only within drmm_connector_hdmi_init_with_caps() when drivers advertise HDMI 2.x capability, in which case it also ensures the callbacks are provided.

Quoted 5 lines

We could drop the flag and instead have the init helper clear the callbacks if they were provided for HDMI 1.x. This might slightly reduce code readability, as it relies on checking the presence of individual callbacks - especially since we plan to extend this further with HDMI 2.1 support, providing four or five additional FRL-specific callbacks.

I tried to replace the flag with a helper that checks the presence of (one of) the callbacks, but it's not straightforward to unset those for non-HDMI 2.x cases since the hdmi_funcs argument is immutable.

Quoted 7 lines
Quoted 4 lines

I'm not sure why we would need to unset them. If the driver states that it support HDMI 2.0, then it needs to be there, if it doesn't, then who cares? it's not going to be used. We can log a warning that it's inconsistent I guess, but there's no need to actively remove it.

I was trying to address the use case where drivers provide the scrambler callbacks despite not supporting HDMI 2.0.

Scrambling got introduced with HDMI 2.0. That doesn't make sense, but it's not a total deal breaker, it's just going to be here unused. Hence why I was suggesting to put a warning there if you wanted to.

Quoted 3 lines

If we replace the scrambler_supported flag with a helper checking the presence of the scrambler callbacks, then we would need to ensure the callbacks do not exist in this case.

Keep it simple:

if (hdmi_version >= HDMI_VERSION_2_0)
if (funcs->scrambler_enable)

Quoted 7 lines
      hdmi->scramblers_supported = true
   else
      return -EINVAL
else
    drm_warn(warn, "Inconsistent HDMI version");

We don't need anything more than that.

I dropped the scrambler_supported flag and introduced a helper:

static inline bool drm_connector_hdmi_scrambler_supported(struct drm_connector *connector)

{
	return connector->hdmi.funcs && connector->hdmi.funcs->scrambler_enable;
Quoted 4 lines
Quoted 1 line

I'd add disable to that test

I'd make it an error, if there is only scrambler_enable without scrambler_disable (or vice versa).

hdmi_init() already guaranties that both scrambler callbacks must be present when supported_hdmi_ver indicates HDMI_VERSION_2_0, and neither of them otherwise.

Regardless, I've already added scrambler_disable to the check above to improve code readability.

Thanks,
Cristian

#41 lore raw

PATCH v8 5/39 drm/display: scdc-helper: Add macro for connector-prefixed debug messages

In reply to Cristian Ciocaltea

Introduce the drm_scdc_dbg() wrapper over drm_dbg_kms() to help getting rid of the boilerplate around prefixing the debug messages with the connector information.

---
 drivers/gpu/drm/display/drm_scdc_helper.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
drivers/gpu/drm/display/drm_scdc_helper.c +9 -15
index df878aad4a36..cb6632346aad 100644
@@ -55,6 +55,10 @@
 
 #define SCDC_I2C_SLAVE_ADDRESS 0x54
 
+#define drm_scdc_dbg(connector, fmt, ...)					\
+	drm_dbg_kms((connector)->dev, "[CONNECTOR:%d:%s] " fmt,			\
+		    (connector)->base.id, (connector)->name, ##__VA_ARGS__)
+
 /**
  * drm_scdc_read - read a block of data from SCDC
  * @adapter: I2C controller
@@ -158,9 +162,7 @@ bool drm_scdc_get_scrambling_status(struct drm_connector *connector)
 
 	ret = drm_scdc_readb(connector->ddc, SCDC_SCRAMBLER_STATUS, &status);
 	if (ret < 0) {
-		drm_dbg_kms(connector->dev,
-			    "[CONNECTOR:%d:%s] Failed to read scrambling status: %d\n",
-			    connector->base.id, connector->name, ret);
+		drm_scdc_dbg(connector, "Failed to read scrambling status: %d\n", ret);
 		return false;
 	}
 
@@ -188,9 +190,7 @@ bool drm_scdc_set_scrambling(struct drm_connector *connector,
 
 	ret = drm_scdc_readb(connector->ddc, SCDC_TMDS_CONFIG, &config);
 	if (ret < 0) {
-		drm_dbg_kms(connector->dev,
-			    "[CONNECTOR:%d:%s] Failed to read TMDS config: %d\n",
-			    connector->base.id, connector->name, ret);
+		drm_scdc_dbg(connector, "Failed to read TMDS config: %d\n", ret);
 		return false;
 	}
 
@@ -201,9 +201,7 @@ bool drm_scdc_set_scrambling(struct drm_connector *connector,
 
 	ret = drm_scdc_writeb(connector->ddc, SCDC_TMDS_CONFIG, config);
 	if (ret < 0) {
-		drm_dbg_kms(connector->dev,
-			    "[CONNECTOR:%d:%s] Failed to enable scrambling: %d\n",
-			    connector->base.id, connector->name, ret);
+		drm_scdc_dbg(connector, "Failed to enable scrambling: %d\n", ret);
 		return false;
 	}
 
@@ -248,9 +246,7 @@ bool drm_scdc_set_high_tmds_clock_ratio(struct drm_connector *connector,
 
 	ret = drm_scdc_readb(connector->ddc, SCDC_TMDS_CONFIG, &config);
 	if (ret < 0) {
-		drm_dbg_kms(connector->dev,
-			    "[CONNECTOR:%d:%s] Failed to read TMDS config: %d\n",
-			    connector->base.id, connector->name, ret);
+		drm_scdc_dbg(connector, "Failed to read TMDS config: %d\n", ret);
 		return false;
 	}
 
@@ -261,9 +257,7 @@ bool drm_scdc_set_high_tmds_clock_ratio(struct drm_connector *connector,
 
 	ret = drm_scdc_writeb(connector->ddc, SCDC_TMDS_CONFIG, config);
 	if (ret < 0) {
-		drm_dbg_kms(connector->dev,
-			    "[CONNECTOR:%d:%s] Failed to set TMDS clock ratio: %d\n",
-			    connector->base.id, connector->name, ret);
+		drm_scdc_dbg(connector, "Failed to set TMDS clock ratio: %d\n", ret);
 		return false;
 	}
 
Signature · 1 line
2.54.0
#42 lore raw

PATCH v8 6/39 drm/display: scdc-helper: Add helper to set SCDC version information

In reply to Cristian Ciocaltea

The HDMI 2.x specs mandate that compliant Sink devices report their SCDC version in the Sink Version register, which reads as 1 on any SCDC-capable sink.

There is also a dedicated Source Version register. Writing it is not compulsory, but the spec advises that compliant Source devices do so, in which case the value must be 1.

Add drm_scdc_set_source_version() to follow this recommendation. The Sink Version register is read first, both to log the advertised SCDC version and to guard against non-conformant devices: a sink reporting version 0 is either not SCDC-version-aware or broken, so writing the source version gains nothing and risks upsetting such hardware. In that case the write is skipped.

The source version is passed as a parameter rather than hardcoded, as future spec revisions may define additional rules for the allowable version values. The written value is additionally clamped to the sink's reported version so the source never advertises a version the sink does not understand.

---
 drivers/gpu/drm/display/drm_scdc_helper.c | 46 ++++++++++++++++++++++++++++++-
 include/drm/display/drm_scdc_helper.h     |  2 ++
 2 files changed, 47 insertions(+), 1 deletion(-)
drivers/gpu/drm/display/drm_scdc_helper.c +45 -1
index cb6632346aad..6d804ee19420 100644
@@ -21,10 +21,11 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#include <linux/delay.h>
 #include <linux/export.h>
 #include <linux/i2c.h>
+#include <linux/minmax.h>
 #include <linux/slab.h>
-#include <linux/delay.h>
 
 #include <drm/display/drm_scdc_helper.h>
 #include <drm/drm_connector.h>
@@ -270,3 +271,46 @@ bool drm_scdc_set_high_tmds_clock_ratio(struct drm_connector *connector,
 	return true;
 }
 EXPORT_SYMBOL(drm_scdc_set_high_tmds_clock_ratio);
+
+/**
+ * drm_scdc_set_source_version - set SCDC source version on the sink
+ * @connector: connector
+ * @ver: source version to advertise (per spec, 1)
+ *
+ * Reads the sink version for diagnostics and as a guard, then writes
+ * the source version unless the sink reports version 0.
+ *
+ * Returns:
+ * 0 on success or when skipped; a negative error code when either
+ * the read or the write failed.
+ */
+int drm_scdc_set_source_version(struct drm_connector *connector, u8 ver)
+{
+	u8 sink_ver;
+	int ret;
+
+	ret = drm_scdc_readb(connector->ddc, SCDC_SINK_VERSION, &sink_ver);
+	if (ret) {
+		drm_scdc_dbg(connector, "Failed to read SCDC_SINK_VERSION: %d\n", ret);
+		return ret;
+	}
+
+	drm_scdc_dbg(connector, "Sink reported SCDC ver. %u\n", sink_ver);
+
+	/*
+	 * Only advertise our source version to sinks that report a
+	 * non-zero sink version.  A sink reporting version 0 is either
+	 * not SCDC-version-aware or non-conformant; writing the source
+	 * version gains nothing and may upset broken hardware.
+	 */
+	if (sink_ver) {
+		ret = drm_scdc_writeb(connector->ddc, SCDC_SOURCE_VERSION,
+				      min_t(u8, sink_ver, ver));
+		if (ret)
+			drm_scdc_dbg(connector,
+				     "Failed to write SCDC_SOURCE_VERSION: %d\n", ret);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL(drm_scdc_set_source_version);
include/drm/display/drm_scdc_helper.h +2 -0
index 34600476a1b9..90b0828364c2 100644
@@ -77,4 +77,6 @@ bool drm_scdc_get_scrambling_status(struct drm_connector *connector);
 bool drm_scdc_set_scrambling(struct drm_connector *connector, bool enable);
 bool drm_scdc_set_high_tmds_clock_ratio(struct drm_connector *connector, bool set);
 
+int drm_scdc_set_source_version(struct drm_connector *connector, u8 ver);
+
 #endif
Signature · 1 line
2.54.0
maintainer Acked-by on v8 6/39
#43 lore raw

Re: [PATCH v8 06/39] drm/display: scdc-helper: Add helper to set SCDC version information

Quoted 7 lines · Cristian Ciocaltea

The HDMI 2.x specs mandate that compliant Sink devices report their SCDC version in the Sink Version register, which reads as 1 on any SCDC-capable sink.

There is also a dedicated Source Version register. Writing it is not

[ ... ]

Thanks!
Maxime

Reviewed-by on v8 6/39
#44 lore raw

Re: [PATCH v8 06/39] drm/display: scdc-helper: Add helper to set SCDC version information

In reply to Cristian Ciocaltea
Quoted 21 lines · Cristian Ciocaltea

The HDMI 2.x specs mandate that compliant Sink devices report their SCDC version in the Sink Version register, which reads as 1 on any SCDC-capable sink.

There is also a dedicated Source Version register. Writing it is not compulsory, but the spec advises that compliant Source devices do so, in which case the value must be 1.

Add drm_scdc_set_source_version() to follow this recommendation. The Sink Version register is read first, both to log the advertised SCDC version and to guard against non-conformant devices: a sink reporting version 0 is either not SCDC-version-aware or broken, so writing the source version gains nothing and risks upsetting such hardware. In that case the write is skipped.

The source version is passed as a parameter rather than hardcoded, as future spec revisions may define additional rules for the allowable version values. The written value is additionally clamped to the sink's reported version so the source never advertises a version the sink does not understand.

Quoted 6 lines
---
 drivers/gpu/drm/display/drm_scdc_helper.c | 46 ++++++++++++++++++++++++++++++-
 include/drm/display/drm_scdc_helper.h     |  2 ++
 2 files changed, 47 insertions(+), 1 deletion(-)
Signature · 2 lines
With best wishes
Dmitry
#45 lore raw

PATCH v8 7/39 drm/display: hdmi: Add HDMI 2.0 scrambling management helpers

In reply to Cristian Ciocaltea

Add helpers to manage the full lifecycle of HDMI 2.0 SCDC scrambling on both source and sink sides:

- drm_hdmi_mode_needs_scrambling(): checks whether a mode, bits per component and output format combination requires scrambling, which is needed when the resulting TMDS character rate exceeds the HDMI 1.3 maximum of 340 MHz

- drm_connector_hdmi_enable_scrambling(): configures SCDC scrambling and high TMDS clock ratio and starts a periodic work item that monitors the sink's SCDC scrambling status, retrying setup when the sink loses state

- drm_connector_hdmi_disable_scrambling(): tears down scrambling on both sides and cancels the monitoring work

- drm_connector_hdmi_sync_scdc(): triggers a CRTC reset on reconnection to restore SCDC state lost during sink disconnects within an active display pipeline

---
 drivers/gpu/drm/display/drm_hdmi_helper.c | 260 ++++++++++++++++++++++++++++++
 include/drm/display/drm_hdmi_helper.h     |  15 ++
 2 files changed, 275 insertions(+)
drivers/gpu/drm/display/drm_hdmi_helper.c +260 -0
index 5cb0b033b171..7c96cccf683d 100644
@@ -4,12 +4,20 @@
 #include <linux/module.h>
 
 #include <drm/display/drm_hdmi_helper.h>
+#include <drm/display/drm_scdc_helper.h>
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
 #include <drm/drm_connector.h>
+#include <drm/drm_crtc.h>
 #include <drm/drm_edid.h>
 #include <drm/drm_modes.h>
+#include <drm/drm_modeset_lock.h>
 #include <drm/drm_print.h>
 #include <drm/drm_property.h>
 
+#define DRM_HDMI_SCDC_POLL_DELAY_MS	1000
+
 static inline bool is_eotf_supported(u8 output_eotf, u8 sink_eotf)
 {
 	return sink_eotf & BIT(output_eotf);
@@ -426,3 +434,255 @@ drm_hdmi_acr_get_n_cts(unsigned long long tmds_char_rate,
 	*out_cts = cts;
 }
 EXPORT_SYMBOL(drm_hdmi_acr_get_n_cts);
+
+/**
+ * drm_hdmi_mode_needs_scrambling() - Check if an HDMI mode requires scrambling
+ * @mode: Display mode to check
+ * @bpc: Bits per color component
+ * @fmt: Output pixel format
+ *
+ * Computes the TMDS character rate for the given mode, bits per component and
+ * output format, and checks whether it exceeds the HDMI 1.3 maximum TMDS
+ * character rate of 340 MHz.
+ *
+ * Returns:
+ * true if the mode requires scrambling, false otherwise.
+ */
+bool drm_hdmi_mode_needs_scrambling(const struct drm_display_mode *mode,
+				    unsigned int bpc,
+				    enum drm_output_color_format fmt)
+{
+	unsigned long long tmds_char_rate;
+
+	tmds_char_rate = drm_hdmi_compute_mode_clock(mode, bpc, fmt);
+
+	return tmds_char_rate > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
+}
+EXPORT_SYMBOL(drm_hdmi_mode_needs_scrambling);
+
+static int drm_scdc_try_scrambling_setup(struct drm_connector *connector)
+{
+	bool done;
+
+	done = drm_scdc_set_high_tmds_clock_ratio(connector, true);
+	if (!done)
+		return -EIO;
+
+	done = drm_scdc_set_scrambling(connector, true);
+	if (!done)
+		return -EIO;
+
+	if (READ_ONCE(connector->hdmi.scrambler_enabled))
+		schedule_delayed_work(&connector->hdmi.scdc_work,
+				      msecs_to_jiffies(DRM_HDMI_SCDC_POLL_DELAY_MS));
+
+	return 0;
+}
+
+static void drm_scdc_monitor_scrambler(struct drm_connector *connector)
+{
+	if (READ_ONCE(connector->hdmi.scrambler_enabled) &&
+	    !drm_scdc_get_scrambling_status(connector))
+		drm_scdc_try_scrambling_setup(connector);
+}
+
+static bool drm_scdc_sink_supports_scrambling(struct drm_connector *connector)
+{
+	const struct drm_display_info *info = &connector->display_info;
+
+	return info->is_hdmi &&
+	       info->hdmi.scdc.supported &&
+	       info->hdmi.scdc.scrambling.supported;
+}
+
+/**
+ * drm_connector_hdmi_enable_scrambling - enable scrambling and monitor SCDC status
+ * @connector: connector
+ * @conn_state: connector state
+ *
+ * Enables scrambling and high TMDS clock ratio on both source and sink sides.
+ * Additionally, use a delayed work item to monitor the scrambling status on
+ * the sink side and retry the operation, as some displays refuse to set the
+ * scrambling bit right away.
+ *
+ * Returns:
+ * Zero if scrambling is set successfully, an error code otherwise.
+ */
+int drm_connector_hdmi_enable_scrambling(struct drm_connector *connector,
+					 const struct drm_connector_state *conn_state)
+{
+	struct drm_connector_hdmi *hdmi = &connector->hdmi;
+	struct drm_device *dev = connector->dev;
+	int ret;
+
+	if (!conn_state)
+		return -EINVAL;
+
+	if (!conn_state->hdmi.scrambler_needed)
+		return 0;
+
+	if (!hdmi->scrambler_supported) {
+		drm_dbg_kms(dev, "Source doesn't support scrambling.\n");
+		return -EINVAL;
+	}
+
+	if (!drm_scdc_sink_supports_scrambling(connector)) {
+		drm_dbg_kms(dev, "Sink doesn't support scrambling.\n");
+		return -EINVAL;
+	}
+
+	drm_dbg_kms(dev, "Enabling scrambling\n");
+
+	hdmi->scdc_cb = drm_scdc_monitor_scrambler;
+	WRITE_ONCE(hdmi->scrambler_enabled, true);
+
+	ret = drm_scdc_try_scrambling_setup(connector);
+	if (!ret)
+		ret = hdmi->funcs->scrambler_enable(connector);
+
+	if (ret) {
+		WRITE_ONCE(hdmi->scrambler_enabled, false);
+		cancel_delayed_work_sync(&hdmi->scdc_work);
+		hdmi->scdc_cb = NULL;
+
+		drm_scdc_set_scrambling(connector, false);
+		drm_scdc_set_high_tmds_clock_ratio(connector, false);
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL(drm_connector_hdmi_enable_scrambling);
+
+/**
+ * drm_connector_hdmi_disable_scrambling - disable scrambling and SCDC monitoring
+ * @connector: connector
+ *
+ * Disables scrambling and high TMDS clock ratio on both source and sink sides.
+ * Also cancels the SCDC status monitoring work item, if it is still pending.
+ *
+ * Returns:
+ * Zero if scrambling is reset successfully, an error code otherwise.
+ */
+int drm_connector_hdmi_disable_scrambling(struct drm_connector *connector)
+{
+	struct drm_connector_hdmi *hdmi = &connector->hdmi;
+	struct drm_device *dev = connector->dev;
+
+	if (!READ_ONCE(hdmi->scrambler_enabled))
+		return 0;
+
+	drm_dbg_kms(dev, "Disabling scrambling\n");
+
+	WRITE_ONCE(hdmi->scrambler_enabled, false);
+	cancel_delayed_work_sync(&hdmi->scdc_work);
+	hdmi->scdc_cb = NULL;
+
+	if (connector->status == connector_status_connected &&
+	    drm_scdc_sink_supports_scrambling(connector)) {
+		drm_scdc_set_scrambling(connector, false);
+		drm_scdc_set_high_tmds_clock_ratio(connector, false);
+	}
+
+	return hdmi->funcs->scrambler_disable(connector);
+}
+EXPORT_SYMBOL(drm_connector_hdmi_disable_scrambling);
+
+/**
+ * drm_connector_hdmi_sync_scdc - resync the sink-side SCDC upon reconnect
+ * @connector: connector
+ * @plugged: connector plugged status event
+ * @ctx: initialized lock acquisition context
+ *
+ * When receiving hotplug disconnect/reconnect event, while the display is
+ * still active (CRTC enabled), the SCDC status on the sink side is reset
+ * and must be explicitly restored.
+ *
+ * The typical solution for this is to trigger an empty modeset in
+ * drm_connector_helper_funcs.detect_ctx(), which is what this helper does
+ * by triggering a CRTC reset on reconnection.
+ *
+ * When making use of the HDMI connector framework, this is automatically
+ * triggered via drm_atomic_helper_connector_hdmi_hotplug().
+ *
+ * Returns:
+ * Zero on success, an error code otherwise, including -EDEADLK.
+ */
+int drm_connector_hdmi_sync_scdc(struct drm_connector *connector, bool plugged,
+				 struct drm_modeset_acquire_ctx *ctx)
+{
+	struct drm_connector_hdmi *hdmi = &connector->hdmi;
+	struct drm_device *dev = connector->dev;
+	struct drm_connector_state *conn_state;
+	struct drm_crtc *crtc;
+	u8 config;
+	int ret;
+
+	if (!connector || !plugged || !ctx)
+		return 0;
+
+	/*
+	 * This is normally part of .detect_ctx() call path, which already holds
+	 * connection_mutex through @ctx.  However, re-acquiring it with the
+	 * same context is a no-op and makes the helper safe under any caller.
+	 */
+	ret = drm_modeset_lock(&connector->dev->mode_config.connection_mutex, ctx);
+	if (ret)
+		return ret;
+
+	/* TODO: Also handle HDMI 2.1 FRL link training */
+
+	if (!hdmi->scrambler_supported || !READ_ONCE(hdmi->scrambler_enabled))
+		return 0;
+
+	conn_state = connector->state;
+	if (!conn_state)
+		return 0;
+
+	crtc = connector->state->crtc;
+	if (!crtc)
+		return 0;
+
+	ret = drm_modeset_lock(&crtc->mutex, ctx);
+	if (ret)
+		return ret;
+
+	if (!crtc->state || !crtc->state->active)
+		return 0;
+
+	if (!drm_scdc_sink_supports_scrambling(connector))
+		return 0;
+
+	if (conn_state->commit &&
+	    !try_wait_for_completion(&conn_state->commit->hw_done))
+		return 0;
+
+	ret = drm_scdc_readb(connector->ddc, SCDC_TMDS_CONFIG, &config);
+	if (ret) {
+		drm_dbg_kms(dev, "Failed to read TMDS config: %d\n", ret);
+		return ret;
+	}
+
+	if (config & SCDC_SCRAMBLING_ENABLE)
+		return 0;
+
+	/*
+	 * HDMI 2.0 requires that one should not send scrambled data prior
+	 * to configuring the sink scrambling, and that TMDS clock/data
+	 * transmission should be suspended when changing the TMDS clock rate
+	 * in the sink.  So let's just do a full modeset here, even though some
+	 * sinks would be perfectly happy if were to just reconfigure the SCDC
+	 * settings on the fly.
+	 *
+	 * The disable/re-enable cycle triggered by the reset should call
+	 * drm_connector_hdmi_enable_scrambling() during re-enable, thus
+	 * properly configuring the sink before data transmission resumes.
+	 */
+	drm_dbg_kms(dev, "Resetting CRTC to restore SCDC status\n");
+
+	ret = drm_atomic_helper_reset_crtc(crtc, ctx);
+	if (ret && ret != -EDEADLK)
+		drm_dbg_kms(dev, "Failed to reset CRTC: %d\n", ret);
+
+	return ret;
+}
+EXPORT_SYMBOL(drm_connector_hdmi_sync_scdc);
include/drm/display/drm_hdmi_helper.h +15 -0
index 9c31ed90516b..2cdd6e3bc090 100644
@@ -8,6 +8,7 @@
 struct drm_connector;
 struct drm_connector_state;
 struct drm_display_mode;
+struct drm_modeset_acquire_ctx;
 enum drm_output_color_format;
 
 void
@@ -35,4 +36,18 @@ drm_hdmi_acr_get_n_cts(unsigned long long tmds_char_rate,
 		       unsigned int *out_n,
 		       unsigned int *out_cts);
 
+bool
+drm_hdmi_mode_needs_scrambling(const struct drm_display_mode *mode,
+			       unsigned int bpc, enum drm_output_color_format fmt);
+
+int
+drm_connector_hdmi_enable_scrambling(struct drm_connector *connector,
+				     const struct drm_connector_state *conn_state);
+int
+drm_connector_hdmi_disable_scrambling(struct drm_connector *connector);
+
+int
+drm_connector_hdmi_sync_scdc(struct drm_connector *connector, bool plugged,
+			     struct drm_modeset_acquire_ctx *ctx);
+
 #endif
Signature · 1 line
2.54.0
#46 lore raw

Re: [PATCH v8 07/39] drm/display: hdmi: Add HDMI 2.0 scrambling management helpers

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] The `scdc_work` delayed work item is initialized but never explicitly canceled during connector…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The scdc_work delayed work item is initialized but never explicitly canceled during connector cleanup, risking a Use-After-Free.
- [High] The SCDC configuration helpers attempt to execute I2C transfers without verifying that connector->ddc is not NULL, leading to a NULL pointer dereference.
- [High] The newly added HDMI scrambling helpers invoke sleeping functions in atomic context.
- [Medium] The SCDC scrambling monitor delayed work fails to reschedule itself under normal conditions or upon recovery failure, breaking the intended periodic polling. --

commit 8b2652a7b68d13a84c5a135061f33fe6fdd00be1
Author: Cristian Ciocaltea <[email protected]>

drm/display: hdmi: Add HDMI 2.0 scrambling management helpers

Add helpers to manage the full lifecycle of HDMI 2.0 SCDC scrambling on both source and sink sides:

- drm_hdmi_mode_needs_scrambling(): checks whether a mode, bits per component and output format combination requires scrambling, which is needed when the resulting TMDS character rate exceeds the HDMI 1.3 maximum of 340 MHz

- drm_connector_hdmi_enable_scrambling(): configures SCDC scrambling and high TMDS clock ratio and starts a periodic work item that monitors the sink's SCDC scrambling status, retrying setup when the sink loses state

- drm_connector_hdmi_disable_scrambling(): tears down scrambling on both sides and cancels the monitoring work

- drm_connector_hdmi_sync_scdc(): triggers a CRTC reset on reconnection to restore SCDC state lost during sink disconnects within an active display pipeline

Quoted 4 lines
drivers/gpu/drm/display/drm_hdmi_helper.c +0 -0
index 5cb0b033b1713..7c96cccf683d4 100644

[ ... ]

Quoted 15 lines
drivers/gpu/drm/display/drm_hdmi_helper.c +15 -0
+static int drm_scdc_try_scrambling_setup(struct drm_connector *connector)
+{
+	bool done;
+
+	done = drm_scdc_set_high_tmds_clock_ratio(connector, true);
+	if (!done)
+		return -EIO;
+
+	done = drm_scdc_set_scrambling(connector, true);
+	if (!done)
+		return -EIO;
+
+	if (READ_ONCE(connector->hdmi.scrambler_enabled))
+		schedule_delayed_work(&connector->hdmi.scdc_work,
+				      msecs_to_jiffies(DRM_HDMI_SCDC_POLL_DELAY_MS));

drivers/gpu/drm/display/drm_hdmi_helper.c drm_hdmi_acr_get_n_cts(unsigned long long tmds_char_rate, · line 487

Quoted 10 lines
drivers/gpu/drm/display/drm_hdmi_helper.c +10 -0
+
+	return 0;
+}
+
+static void drm_scdc_monitor_scrambler(struct drm_connector *connector)
+{
+	if (READ_ONCE(connector->hdmi.scrambler_enabled) &&
+	    !drm_scdc_get_scrambling_status(connector))
+		drm_scdc_try_scrambling_setup(connector);
+}

[Severity: Medium]
Does this periodic monitoring loop stop unintentionally?

If drm_scdc_get_scrambling_status() returns true to indicate normal status, or if drm_scdc_try_scrambling_setup() fails and returns early without rescheduling, the delayed work is never scheduled again.

This appears to break the intended periodic polling loop in both the success and persistent-failure paths.

[Severity: High]
Is the scdc_work delayed work item explicitly cancelled when the connector is destroyed?

If a connector is destroyed abruptly while the work is pending, it seems drm_connector_cleanup() will clear the connector structure using memset without first calling cancel_delayed_work_sync(&connector->hdmi.scdc_work).

Could this leave a corrupted entry in the timer list, leading to a panic when the timer fires?

[ ... ]

Quoted 12 lines
drivers/gpu/drm/display/drm_hdmi_helper.c +12 -0
+int drm_connector_hdmi_enable_scrambling(struct drm_connector *connector,
+					 const struct drm_connector_state *conn_state)
+{
+	struct drm_connector_hdmi *hdmi = &connector->hdmi;
+	struct drm_device *dev = connector->dev;
+	int ret;
+
+	if (!conn_state)
+		return -EINVAL;
+
+	if (!conn_state->hdmi.scrambler_needed)
+		return 0;

drivers/gpu/drm/display/drm_hdmi_helper.c drm_hdmi_acr_get_n_cts(unsigned long long tmds_char_rate, · line 532

Quoted 10 lines
drivers/gpu/drm/display/drm_hdmi_helper.c +10 -0
+
+	if (!hdmi->scrambler_supported) {
+		drm_dbg_kms(dev, "Source doesn't support scrambling.\n");
+		return -EINVAL;
+	}
+
+	if (!drm_scdc_sink_supports_scrambling(connector)) {
+		drm_dbg_kms(dev, "Sink doesn't support scrambling.\n");
+		return -EINVAL;
+	}

[Severity: High]
Is it possible for connector->ddc to be NULL here?

If an EDID advertising SCDC is forced on a connector that physically lacks an I2C DDC bus, drm_scdc_sink_supports_scrambling() might pass because it only checks the EDID capabilities.

This would lead to a NULL pointer dereference when I2C transfers are attempted later in the function.

drivers/gpu/drm/display/drm_hdmi_helper.c drm_hdmi_acr_get_n_cts(unsigned long long tmds_char_rate, · line 545

Quoted 13 lines
drivers/gpu/drm/display/drm_hdmi_helper.c +13 -0
+
+	drm_dbg_kms(dev, "Enabling scrambling\n");
+
+	hdmi->scdc_cb = drm_scdc_monitor_scrambler;
+	WRITE_ONCE(hdmi->scrambler_enabled, true);
+
+	ret = drm_scdc_try_scrambling_setup(connector);
+	if (!ret)
+		ret = hdmi->funcs->scrambler_enable(connector);
+
+	if (ret) {
+		WRITE_ONCE(hdmi->scrambler_enabled, false);
+		cancel_delayed_work_sync(&hdmi->scdc_work);

[Severity: High]
Are sleeping functions being called from an atomic context here?

These scrambling helpers appear to be invoked from encoder and bridge atomic enable/disable paths where sleeping is strictly forbidden.

However, drm_scdc_try_scrambling_setup() indirectly uses usleep_range(), and cancel_delayed_work_sync() can also sleep.

Could this cause deadlocks or system instability during modesets?

[ ... ]

drivers/gpu/drm/display/drm_hdmi_helper.c drm_hdmi_acr_get_n_cts(unsigned long long tmds_char_rate, · line 577

Quoted 12 lines
drivers/gpu/drm/display/drm_hdmi_helper.c +12 -0
+int drm_connector_hdmi_disable_scrambling(struct drm_connector *connector)
+{
+	struct drm_connector_hdmi *hdmi = &connector->hdmi;
+	struct drm_device *dev = connector->dev;
+
+	if (!READ_ONCE(hdmi->scrambler_enabled))
+		return 0;
+
+	drm_dbg_kms(dev, "Disabling scrambling\n");
+
+	WRITE_ONCE(hdmi->scrambler_enabled, false);
+	cancel_delayed_work_sync(&hdmi->scdc_work);

[Severity: High]
Could this cancel_delayed_work_sync() call sleep in an atomic disable path?

Like the enable path, this disable helper uses a synchronization function that can sleep. This violates the requirement that atomic disable callbacks must not sleep.

[ ... ]

Quoted 9 lines
drivers/gpu/drm/display/drm_hdmi_helper.c +9 -0
+int drm_connector_hdmi_sync_scdc(struct drm_connector *connector, bool plugged,
+				 struct drm_modeset_acquire_ctx *ctx)
+{
+	struct drm_connector_hdmi *hdmi = &connector->hdmi;
+	struct drm_device *dev = connector->dev;
+	struct drm_connector_state *conn_state;
+	struct drm_crtc *crtc;
+	u8 config;
+	int ret;

[ ... ]

drivers/gpu/drm/display/drm_hdmi_helper.c drm_hdmi_acr_get_n_cts(unsigned long long tmds_char_rate, · line 659

Quoted 8 lines
drivers/gpu/drm/display/drm_hdmi_helper.c +8 -0
+	if (!drm_scdc_sink_supports_scrambling(connector))
+		return 0;
+
+	if (conn_state->commit &&
+	    !try_wait_for_completion(&conn_state->commit->hw_done))
+		return 0;
+
+	ret = drm_scdc_readb(connector->ddc, SCDC_TMDS_CONFIG, &config);

[Severity: High]
Does this code need to verify connector->ddc before using it?

Similar to the enable path, if the connector lacks a physical I2C bus but SCDC is supported by the EDID, reading from connector->ddc here without a NULL check will result in a kernel panic.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#47 lore raw

PATCH v8 8/39 drm/display: hdmi: Advertise SCDC source version when scrambling

In reply to Cristian Ciocaltea

The HDMI 2.0 spec advises that compliant Source devices report their SCDC version in the Source Version register. Do so when enabling scrambling by calling drm_scdc_set_source_version().

Failures are non-fatal: SCDC version negotiation is purely informational and does not gate scrambling or any high-bitrate functionality, so a flaky DDC bus should not block scrambling setup.

---
 drivers/gpu/drm/display/drm_hdmi_helper.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/display/drm_hdmi_helper.c +7 -0
index 7c96cccf683d..b8ed2a1e47f5 100644
@@ -16,6 +16,7 @@
 #include <drm/drm_print.h>
 #include <drm/drm_property.h>
 
+#define DRM_HDMI_SCDC_SOURCE_VERSION	1
 #define DRM_HDMI_SCDC_POLL_DELAY_MS	1000
 
 static inline bool is_eotf_supported(u8 output_eotf, u8 sink_eotf)
@@ -531,6 +532,12 @@ int drm_connector_hdmi_enable_scrambling(struct drm_connector *connector,
 		return -EINVAL;
 	}
 
+	/*
+	 * Advertise our SCDC source version. This is purely informational and
+	 * does not gate scrambling, so failures are non-fatal.
+	 */
+	drm_scdc_set_source_version(connector, DRM_HDMI_SCDC_SOURCE_VERSION);
+
 	drm_dbg_kms(dev, "Enabling scrambling\n");
 
 	hdmi->scdc_cb = drm_scdc_monitor_scrambler;
Signature · 1 line
2.54.0
maintainer Acked-by on v8 8/39
#48 lore raw

Re: [PATCH v8 08/39] drm/display: hdmi: Advertise SCDC source version when scrambling

Quoted 7 lines · Cristian Ciocaltea

The HDMI 2.0 spec advises that compliant Source devices report their SCDC version in the Source Version register. Do so when enabling scrambling by calling drm_scdc_set_source_version().

Failures are non-fatal: SCDC version negotiation is purely informational

[ ... ]

Thanks!
Maxime

#49 lore raw

PATCH v8 9/39 drm/display: hdmi-state-helper: Add fallback TMDS rate validation

In reply to Cristian Ciocaltea

Validate the computed TMDS character rate against connector->hdmi.max_tmds_char_rate when no driver-specific tmds_char_rate_valid() hook is provided.

This gives HDMI connectors a common fallback for rejecting modes whose TMDS character rate exceeds the connector limit, while still allowing drivers with custom validation requirements to implement their own tmds_char_rate_valid() callback.

---
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/display/drm_hdmi_state_helper.c +3 -0
index ce17eeefc2da..db76699093e8 100644
@@ -566,6 +566,9 @@ hdmi_clock_valid(const struct drm_connector *connector,
 		status = funcs->tmds_char_rate_valid(connector, mode, clock);
 		if (status != MODE_OK)
 			return status;
+	} else if (connector->hdmi.max_tmds_char_rate) {
+		if (clock > connector->hdmi.max_tmds_char_rate)
+			return MODE_CLOCK_HIGH;
 	}
 
 	return MODE_OK;
Signature · 1 line
2.54.0
#50 lore raw

Re: [PATCH v8 09/39] drm/display: hdmi-state-helper: Add fallback TMDS rate validation

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The fallback TMDS character rate validation is silently bypassed for HDMI bridge connectors…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The fallback TMDS character rate validation is silently bypassed for HDMI bridge connectors because the bridge framework unconditionally provides a wrapper callback. --

commit 98644f49de11eb659578421bd532a4a887719f94
Author: Cristian Ciocaltea <[email protected]>

drm/display: hdmi-state-helper: Add fallback TMDS rate validation

Validate the computed TMDS character rate against connector limits when no driver-specific hook is provided.

drivers/gpu/drm/display/drm_hdmi_state_helper.c hdmi_clock_valid(const struct drm_connector *connector, · line 569

Quoted 9 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +1 -0
index ce17eeefc2da4..db76699093e87 100644
@@ -566,6 +566,9 @@ hdmi_clock_valid(const struct drm_connector *connector,
 		status = funcs->tmds_char_rate_valid(connector, mode, clock);
 		if (status != MODE_OK)
 			return status;
+	} else if (connector->hdmi.max_tmds_char_rate) {

[Severity: Medium]
Does this else if structure bypass the fallback logic for HDMI bridge connectors?

The bridge framework always provides a wrapper for its connectors:

drm_bridge_connector_tmds_char_rate_valid() {
        if (bridge->funcs->hdmi_tmds_char_rate_valid)
                return bridge->funcs->hdmi_tmds_char_rate_valid(...);
        else
                return MODE_OK;
}

Because this wrapper unconditionally exists, funcs->tmds_char_rate_valid evaluates to true in hdmi_clock_valid().

If the underlying bridge lacks its own validation, the wrapper simply returns MODE_OK. Since this was checked in the first if statement, the execution skips the else if branch entirely.

Will this prevent the max_tmds_char_rate limit from being enforced on bridge drivers, potentially allowing unsupported display modes to be selected?

Quoted 5 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +2 -0
+		if (clock > connector->hdmi.max_tmds_char_rate)
+			return MODE_CLOCK_HIGH;
 	}
 
 	return MODE_OK;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
maintainer
#51 lore raw

Re: [PATCH v8 09/39] drm/display: hdmi-state-helper: Add fallback TMDS rate validation

In reply to Cristian Ciocaltea

Hi,

Quoted 19 lines · Cristian Ciocaltea

Validate the computed TMDS character rate against connector->hdmi.max_tmds_char_rate when no driver-specific tmds_char_rate_valid() hook is provided.

This gives HDMI connectors a common fallback for rejecting modes whose TMDS character rate exceeds the connector limit, while still allowing drivers with custom validation requirements to implement their own tmds_char_rate_valid() callback.

---
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/display/drm_hdmi_state_helper.c +0 -0
index ce17eeefc2da..db76699093e8 100644

drivers/gpu/drm/display/drm_hdmi_state_helper.c hdmi_clock_valid(const struct drm_connector *connector, · line 571

Quoted 6 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +3 -0
@@ -566,6 +566,9 @@ hdmi_clock_valid(const struct drm_connector *connector,
 		status = funcs->tmds_char_rate_valid(connector, mode, clock);
 		if (status != MODE_OK)
 			return status;
+	} else if (connector->hdmi.max_tmds_char_rate) {
+		if (clock > connector->hdmi.max_tmds_char_rate)
+			return MODE_CLOCK_HIGH;

I think we should handle this the same way we do for info->max_tmds_clock: if it's set, we always check that before calling the driver.

It reduces the boilerplate in drivers, and it's always a relevant check anyway.

Maxime

#52 lore raw

Re: [PATCH v8 09/39] drm/display: hdmi-state-helper: Add fallback TMDS rate validation

Quoted 33 lines · Maxime Ripard

Hi,

Quoted 19 lines · Cristian Ciocaltea

Validate the computed TMDS character rate against connector->hdmi.max_tmds_char_rate when no driver-specific tmds_char_rate_valid() hook is provided.

This gives HDMI connectors a common fallback for rejecting modes whose TMDS character rate exceeds the connector limit, while still allowing drivers with custom validation requirements to implement their own tmds_char_rate_valid() callback.

---
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/display/drm_hdmi_state_helper.c +0 -0
index ce17eeefc2da..db76699093e8 100644

drivers/gpu/drm/display/drm_hdmi_state_helper.c hdmi_clock_valid(const struct drm_connector *connector, · line 571

Quoted 6 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +3 -0
@@ -566,6 +566,9 @@ hdmi_clock_valid(const struct drm_connector *connector,
 		status = funcs->tmds_char_rate_valid(connector, mode, clock);
 		if (status != MODE_OK)
 			return status;
+	} else if (connector->hdmi.max_tmds_char_rate) {
+		if (clock > connector->hdmi.max_tmds_char_rate)
+			return MODE_CLOCK_HIGH;

I think we should handle this the same way we do for info->max_tmds_clock: if it's set, we always check that before calling the driver.

Quoted 2 lines

It reduces the boilerplate in drivers, and it's always a relevant check anyway.

Ack.

Thanks,
Cristian

#53 lore raw

PATCH v8 10/39 drm/display: hdmi-state-helper: Sync SCDC state on hotplug

In reply to Cristian Ciocaltea

drm_atomic_helper_connector_hdmi_hotplug() does not currently synchronize SCDC status on hotplug events, leaving the scrambler state potentially inconsistent after (re)connect.

Hook drm_connector_hdmi_sync_scdc() into both the connect and disconnect paths, replacing the existing TODOs around missing scrambler handling.

SCDC synchronization may require a CRTC reset, which in turn needs a modeset acquire context for correct locking. Therefore, extend drm_atomic_helper_connector_hdmi_hotplug() and drm_atomic_helper_connector_hdmi_update() to take a drm_modeset_acquire_ctx argument. Additionally, change their return type from void to int, allowing propagation of errors, such as -EDEADLK from lock contention.

Update existing callers to pass NULL for the acquire context, preserving current behavior.

---
 drivers/gpu/drm/display/drm_bridge_connector.c  |  3 ++-
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 28 +++++++++++++++++--------
 drivers/gpu/drm/vc4/vc4_hdmi.c                  |  2 +-
 include/drm/display/drm_hdmi_state_helper.h     |  6 ++++--
 4 files changed, 26 insertions(+), 13 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +2 -1
index 796069dbf1a1..46104506fe32 100644
@@ -221,7 +221,8 @@ drm_bridge_connector_detect(struct drm_connector *connector, bool force)
 		status = detect->funcs->detect(detect, connector);
 
 		if (hdmi)
-			drm_atomic_helper_connector_hdmi_hotplug(connector, status);
+			drm_atomic_helper_connector_hdmi_hotplug(connector, status,
+								 NULL);
 
 		drm_bridge_connector_hpd_notify(connector, status);
 	} else {
drivers/gpu/drm/display/drm_hdmi_state_helper.c +19 -9
index db76699093e8..69ccfbf123fe 100644
@@ -1198,18 +1198,20 @@ drm_atomic_helper_connector_hdmi_clear_audio_infoframe(struct drm_connector *con
 }
 EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_clear_audio_infoframe);
 
-static void
+static int
 drm_atomic_helper_connector_hdmi_update(struct drm_connector *connector,
-					enum drm_connector_status status)
+					enum drm_connector_status status,
+					struct drm_modeset_acquire_ctx *ctx)
 {
 	const struct drm_edid *drm_edid;
+	int ret = 0;
 
 	if (status == connector_status_disconnected) {
-		// TODO: also handle scramber, HDMI sink disconnected.
+		ret = drm_connector_hdmi_sync_scdc(connector, false, ctx);
 		drm_connector_hdmi_audio_plugged_notify(connector, false);
 		drm_edid_connector_update(connector, NULL);
 		drm_connector_cec_phys_addr_invalidate(connector);
-		return;
+		return ret;
 	}
 
 	if (connector->hdmi.funcs->read_edid)
@@ -1222,24 +1224,32 @@ drm_atomic_helper_connector_hdmi_update(struct drm_connector *connector,
 	drm_edid_free(drm_edid);
 
 	if (status == connector_status_connected) {
-		// TODO: also handle scramber, HDMI sink is now connected.
+		ret = drm_connector_hdmi_sync_scdc(connector, true, ctx);
 		drm_connector_hdmi_audio_plugged_notify(connector, true);
 		drm_connector_cec_phys_addr_set(connector);
 	}
+
+	return ret;
 }
 
 /**
  * drm_atomic_helper_connector_hdmi_hotplug - Handle the hotplug event for the HDMI connector
  * @connector: A pointer to the HDMI connector
  * @status: Connection status
+ * @ctx: Lock acquisition context to be used for resetting CRTC
  *
  * This function should be called as a part of the .detect() / .detect_ctx()
  * callbacks for all status changes.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ * If @ctx is set, it might also return -EDEADLK.
  */
-void drm_atomic_helper_connector_hdmi_hotplug(struct drm_connector *connector,
-					      enum drm_connector_status status)
+int drm_atomic_helper_connector_hdmi_hotplug(struct drm_connector *connector,
+					     enum drm_connector_status status,
+					     struct drm_modeset_acquire_ctx *ctx)
 {
-	drm_atomic_helper_connector_hdmi_update(connector, status);
+	return drm_atomic_helper_connector_hdmi_update(connector, status, ctx);
 }
 EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_hotplug);
 
@@ -1254,6 +1264,6 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_hotplug);
  */
 void drm_atomic_helper_connector_hdmi_force(struct drm_connector *connector)
 {
-	drm_atomic_helper_connector_hdmi_update(connector, connector->status);
+	drm_atomic_helper_connector_hdmi_update(connector, connector->status, NULL);
 }
 EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_force);
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
index 74dce4be0c00..e165f604939b 100644
@@ -375,7 +375,7 @@ static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi,
 	 * the lock for now.
 	 */
 
-	drm_atomic_helper_connector_hdmi_hotplug(connector, status);
+	drm_atomic_helper_connector_hdmi_hotplug(connector, status, NULL);
 
 	if (status != connector_status_connected)
 		return;
include/drm/display/drm_hdmi_state_helper.h +4 -2
index 13375bd0f4ae..0619cd7c435e 100644
@@ -7,6 +7,7 @@ struct drm_atomic_commit;
 struct drm_connector;
 struct drm_connector_state;
 struct drm_display_mode;
+struct drm_modeset_acquire_ctx;
 struct hdmi_audio_infoframe;
 
 enum drm_connector_status;
@@ -22,8 +23,9 @@ int drm_atomic_helper_connector_hdmi_update_audio_infoframe(struct drm_connector
 int drm_atomic_helper_connector_hdmi_clear_audio_infoframe(struct drm_connector *connector);
 int drm_atomic_helper_connector_hdmi_update_infoframes(struct drm_connector *connector,
 						       struct drm_atomic_commit *state);
-void drm_atomic_helper_connector_hdmi_hotplug(struct drm_connector *connector,
-					      enum drm_connector_status status);
+int drm_atomic_helper_connector_hdmi_hotplug(struct drm_connector *connector,
+					     enum drm_connector_status status,
+					     struct drm_modeset_acquire_ctx *ctx);
 void drm_atomic_helper_connector_hdmi_force(struct drm_connector *connector);
 
 enum drm_mode_status
Signature · 1 line
2.54.0
#54 lore raw

Re: [PATCH v8 10/39] drm/display: hdmi-state-helper: Sync SCDC state on hotplug

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Medium] State mutations (audio and CEC notifications) are applied even when SCDC sync fails with a WW mutex backoff (-EDEADLK).

Pre-existing issues:
- [High] The disconnect path replaces a TODO with a no-op function call, leaving the scrambler state potentially inconsistent on hotplug. --

commit 079e249ec8df03c559fb868b6a5035e1328d0d31
Author: Cristian Ciocaltea <[email protected]>

drm/display: hdmi-state-helper: Sync SCDC state on hotplug

This commit hooks drm_connector_hdmi_sync_scdc() into both the connect and disconnect paths of drm_atomic_helper_connector_hdmi_update() to synchronize SCDC status on hotplug events. It also adds a context argument to propagate lock contention errors like -EDEADLK.

Quoted 4 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +0 -0
@@ -1198,18 +1198,20 @@ drm_atomic_helper_connector_hdmi_clear_audio_infoframe(struct drm_connector *con

[ ... ]

drivers/gpu/drm/display/drm_hdmi_state_helper.c drm_atomic_helper_connector_hdmi_clear_audio_infoframe(struct drm_connector *con · line 1210

Quoted 13 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +5 -3
-static void
+static int
 drm_atomic_helper_connector_hdmi_update(struct drm_connector *connector,
-					enum drm_connector_status status)
+					enum drm_connector_status status,
+					struct drm_modeset_acquire_ctx *ctx)
 {
 	const struct drm_edid *drm_edid;
+	int ret = 0;
 
 	if (status == connector_status_disconnected) {
-		// TODO: also handle scramber, HDMI sink disconnected.
+		ret = drm_connector_hdmi_sync_scdc(connector, false, ctx);

[Severity: High]
This is a pre-existing issue, but the patch actively replaces the TODO with a function call that appears to be a no-op on disconnect.

Looking at drm_connector_hdmi_sync_scdc() in drm_hdmi_helper.c, it immediately returns 0 when the plugged parameter is false:

int drm_connector_hdmi_sync_scdc(...)

{
        if (!connector || !plugged || !ctx)
                return 0;
        ...
}

Will this leave the scrambler state potentially inconsistent if a user unplugs an SCDC-enabled sink and plugs in a non-SCDC sink without an active modeset? Should the scrambler be explicitly disabled here instead of silently returning?

Quoted 7 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +1 -1
 		drm_connector_hdmi_audio_plugged_notify(connector, false);
 		drm_edid_connector_update(connector, NULL);
 		drm_connector_cec_phys_addr_invalidate(connector);
-		return;
+		return ret;
 	}

[ ... ]

drivers/gpu/drm/display/drm_hdmi_state_helper.c drm_atomic_helper_connector_hdmi_update(struct drm_connector *connector, · line 1232

Quoted 11 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +3 -1
@@ -1222,24 +1224,32 @@ drm_atomic_helper_connector_hdmi_update(struct drm_connector *connector,
 	drm_edid_free(drm_edid);
 
 	if (status == connector_status_connected) {
-		// TODO: also handle scramber, HDMI sink is now connected.
+		ret = drm_connector_hdmi_sync_scdc(connector, true, ctx);
 		drm_connector_hdmi_audio_plugged_notify(connector, true);
 		drm_connector_cec_phys_addr_set(connector);
 	}
+
+	return ret;

[Severity: Medium]
If drm_connector_hdmi_sync_scdc() encounters lock contention and returns -EDEADLK, should we proceed with applying state mutations?

Because ret is captured but not checked before calling drm_connector_hdmi_audio_plugged_notify() and drm_connector_cec_phys_addr_set(), this leaks the plugged state to the audio and CEC subsystems before the WW mutex backoff is completed.

Could we add an error check here to return early on -EDEADLK before mutating the audio and CEC states?

Quoted 1 line
drivers/gpu/drm/display/drm_hdmi_state_helper.c +0 -0
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
maintainer
#55 lore raw

Re: [PATCH v8 10/39] drm/display: hdmi-state-helper: Sync SCDC state on hotplug

In reply to Cristian Ciocaltea

Hi,

Quoted 15 lines · Cristian Ciocaltea

drm_atomic_helper_connector_hdmi_hotplug() does not currently synchronize SCDC status on hotplug events, leaving the scrambler state potentially inconsistent after (re)connect.

Hook drm_connector_hdmi_sync_scdc() into both the connect and disconnect paths, replacing the existing TODOs around missing scrambler handling.

SCDC synchronization may require a CRTC reset, which in turn needs a modeset acquire context for correct locking. Therefore, extend drm_atomic_helper_connector_hdmi_hotplug() and drm_atomic_helper_connector_hdmi_update() to take a drm_modeset_acquire_ctx argument. Additionally, change their return type from void to int, allowing propagation of errors, such as -EDEADLK from lock contention.

Quoted 2 lines

Update existing callers to pass NULL for the acquire context, preserving current behavior.

You should have two patches here: one to change the prototype of the helpers, and one to add the call to drm_connector_hdmi_sync_scdc

Quoted 13 lines
---
 drivers/gpu/drm/display/drm_bridge_connector.c  |  3 ++-
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 28 +++++++++++++++++--------
 drivers/gpu/drm/vc4/vc4_hdmi.c                  |  2 +-
 include/drm/display/drm_hdmi_state_helper.h     |  6 ++++--
 4 files changed, 26 insertions(+), 13 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +0 -0
index 796069dbf1a1..46104506fe32 100644

drivers/gpu/drm/display/drm_bridge_connector.c drm_bridge_connector_detect(struct drm_connector *connector, bool force) · line 228

Quoted 9 lines
drivers/gpu/drm/display/drm_bridge_connector.c +2 -1
@@ -221,7 +221,8 @@ drm_bridge_connector_detect(struct drm_connector *connector, bool force)
 		status = detect->funcs->detect(detect, connector);
 
 		if (hdmi)
-			drm_atomic_helper_connector_hdmi_hotplug(connector, status);
+			drm_atomic_helper_connector_hdmi_hotplug(connector, status,
+								 NULL);
 
 		drm_bridge_connector_hpd_notify(connector, status);
 	} else {

We should move this one to detect_ctx to get the ctx passed and avoid passing NULL here.

Quoted 5 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +0 -0
index db76699093e8..69ccfbf123fe 100644

drivers/gpu/drm/display/drm_hdmi_state_helper.c drm_atomic_helper_connector_hdmi_clear_audio_infoframe(struct drm_connector *con · line 1204

Quoted 9 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +3 -2
@@ -1198,18 +1198,20 @@ drm_atomic_helper_connector_hdmi_clear_audio_infoframe(struct drm_connector *con
 }
 EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_clear_audio_infoframe);
 
-static void
+static int
 drm_atomic_helper_connector_hdmi_update(struct drm_connector *connector,
-					enum drm_connector_status status)
+					enum drm_connector_status status,
+					struct drm_modeset_acquire_ctx *ctx)

detect_ctx has the context first, I think we should use that convention here too.

Quoted 53 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +15 -6
 {
 	const struct drm_edid *drm_edid;
+	int ret = 0;
 
 	if (status == connector_status_disconnected) {
-		// TODO: also handle scramber, HDMI sink disconnected.
+		ret = drm_connector_hdmi_sync_scdc(connector, false, ctx);
 		drm_connector_hdmi_audio_plugged_notify(connector, false);
 		drm_edid_connector_update(connector, NULL);
 		drm_connector_cec_phys_addr_invalidate(connector);
-		return;
+		return ret;
 	}
 
 	if (connector->hdmi.funcs->read_edid)
@@ -1222,24 +1224,32 @@ drm_atomic_helper_connector_hdmi_update(struct drm_connector *connector,
 	drm_edid_free(drm_edid);
 
 	if (status == connector_status_connected) {
-		// TODO: also handle scramber, HDMI sink is now connected.
+		ret = drm_connector_hdmi_sync_scdc(connector, true, ctx);
 		drm_connector_hdmi_audio_plugged_notify(connector, true);
 		drm_connector_cec_phys_addr_set(connector);
 	}
+
+	return ret;
 }
 
 /**
  * drm_atomic_helper_connector_hdmi_hotplug - Handle the hotplug event for the HDMI connector
  * @connector: A pointer to the HDMI connector
  * @status: Connection status
+ * @ctx: Lock acquisition context to be used for resetting CRTC
  *
  * This function should be called as a part of the .detect() / .detect_ctx()
  * callbacks for all status changes.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ * If @ctx is set, it might also return -EDEADLK.
  */
-void drm_atomic_helper_connector_hdmi_hotplug(struct drm_connector *connector,
-					      enum drm_connector_status status)
+int drm_atomic_helper_connector_hdmi_hotplug(struct drm_connector *connector,
+					     enum drm_connector_status status,
+					     struct drm_modeset_acquire_ctx *ctx)
 {
-	drm_atomic_helper_connector_hdmi_update(connector, status);
+	return drm_atomic_helper_connector_hdmi_update(connector, status, ctx);
 }
 EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_hotplug);
 

drivers/gpu/drm/display/drm_hdmi_state_helper.c EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_hotplug); · line 1268

Quoted 6 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +1 -1
@@ -1254,6 +1264,6 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_hotplug);
  */
 void drm_atomic_helper_connector_hdmi_force(struct drm_connector *connector)
 {
-	drm_atomic_helper_connector_hdmi_update(connector, connector->status);
+	drm_atomic_helper_connector_hdmi_update(connector, connector->status, NULL);
 }

We should create a new context here.

drivers/gpu/drm/vc4/vc4_hdmi.c static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi, · line 378

Quoted 11 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +0 -0
 EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_force);
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
index 74dce4be0c00..e165f604939b 100644
@@ -375,7 +375,7 @@ static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi,
 	 * the lock for now.
 	 */
 
-	drm_atomic_helper_connector_hdmi_hotplug(connector, status);
+	drm_atomic_helper_connector_hdmi_hotplug(connector, status, NULL);

vc4_hdmi_handle_hotplug has the context passed as an argument, we should reuse it.

Maxime

#56 lore raw

Re: [PATCH v8 10/39] drm/display: hdmi-state-helper: Sync SCDC state on hotplug

Hi Maxime,

Quoted 18 lines · Maxime Ripard

Hi,

Quoted 15 lines · Cristian Ciocaltea

drm_atomic_helper_connector_hdmi_hotplug() does not currently synchronize SCDC status on hotplug events, leaving the scrambler state potentially inconsistent after (re)connect.

Hook drm_connector_hdmi_sync_scdc() into both the connect and disconnect paths, replacing the existing TODOs around missing scrambler handling.

SCDC synchronization may require a CRTC reset, which in turn needs a modeset acquire context for correct locking. Therefore, extend drm_atomic_helper_connector_hdmi_hotplug() and drm_atomic_helper_connector_hdmi_update() to take a drm_modeset_acquire_ctx argument. Additionally, change their return type from void to int, allowing propagation of errors, such as -EDEADLK from lock contention.

Quoted 5 lines
Quoted 2 lines

Update existing callers to pass NULL for the acquire context, preserving current behavior.

You should have two patches here: one to change the prototype of the helpers, and one to add the call to drm_connector_hdmi_sync_scdc

Ack.

Quoted 20 lines
Quoted 20 lines
---
 drivers/gpu/drm/display/drm_bridge_connector.c  |  3 ++-
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 28 +++++++++++++++++--------
 drivers/gpu/drm/vc4/vc4_hdmi.c                  |  2 +-
 include/drm/display/drm_hdmi_state_helper.h     |  6 ++++--
 4 files changed, 26 insertions(+), 13 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +2 -1
index 796069dbf1a1..46104506fe32 100644
@@ -221,7 +221,8 @@ drm_bridge_connector_detect(struct drm_connector *connector, bool force)
 		status = detect->funcs->detect(detect, connector);
 
 		if (hdmi)
-			drm_atomic_helper_connector_hdmi_hotplug(connector, status);
+			drm_atomic_helper_connector_hdmi_hotplug(connector, status,
+								 NULL);
 
Quoted 5 lines

drivers/gpu/drm/display/drm_bridge_connector.c drm_bridge_connector_detect(struct drm_connector *connector, bool force) · line 228

Quoted 2 lines
drivers/gpu/drm/display/drm_bridge_connector.c +0 -0
 		drm_bridge_connector_hpd_notify(connector, status);
 	} else {

We should move this one to detect_ctx to get the ctx passed and avoid passing NULL here.

We do this in patch 15. Should I try to reorder?

Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +0 -0
index db76699093e8..69ccfbf123fe 100644
@@ -1198,18 +1198,20 @@ drm_atomic_helper_connector_hdmi_clear_audio_infoframe(struct drm_connector *con
 }
 EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_clear_audio_infoframe);
 
Quoted 9 lines

drivers/gpu/drm/display/drm_hdmi_state_helper.c drm_atomic_helper_connector_hdmi_clear_audio_infoframe(struct drm_connector *con · line 1204

Quoted 6 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +3 -2
-static void
+static int
 drm_atomic_helper_connector_hdmi_update(struct drm_connector *connector,
-					enum drm_connector_status status)
+					enum drm_connector_status status,
+					struct drm_modeset_acquire_ctx *ctx)

detect_ctx has the context first, I think we should use that convention here too.

Ack.

Quoted 52 lines
Quoted 52 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +15 -6
 {
 	const struct drm_edid *drm_edid;
+	int ret = 0;
 
 	if (status == connector_status_disconnected) {
-		// TODO: also handle scramber, HDMI sink disconnected.
+		ret = drm_connector_hdmi_sync_scdc(connector, false, ctx);
 		drm_connector_hdmi_audio_plugged_notify(connector, false);
 		drm_edid_connector_update(connector, NULL);
 		drm_connector_cec_phys_addr_invalidate(connector);
-		return;
+		return ret;
 	}
 
 	if (connector->hdmi.funcs->read_edid)
@@ -1222,24 +1224,32 @@ drm_atomic_helper_connector_hdmi_update(struct drm_connector *connector,
 	drm_edid_free(drm_edid);
 
 	if (status == connector_status_connected) {
-		// TODO: also handle scramber, HDMI sink is now connected.
+		ret = drm_connector_hdmi_sync_scdc(connector, true, ctx);
 		drm_connector_hdmi_audio_plugged_notify(connector, true);
 		drm_connector_cec_phys_addr_set(connector);
 	}
+
+	return ret;
 }
 
 /**
  * drm_atomic_helper_connector_hdmi_hotplug - Handle the hotplug event for the HDMI connector
  * @connector: A pointer to the HDMI connector
  * @status: Connection status
+ * @ctx: Lock acquisition context to be used for resetting CRTC
  *
  * This function should be called as a part of the .detect() / .detect_ctx()
  * callbacks for all status changes.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ * If @ctx is set, it might also return -EDEADLK.
  */
-void drm_atomic_helper_connector_hdmi_hotplug(struct drm_connector *connector,
-					      enum drm_connector_status status)
+int drm_atomic_helper_connector_hdmi_hotplug(struct drm_connector *connector,
+					     enum drm_connector_status status,
+					     struct drm_modeset_acquire_ctx *ctx)
 {
-	drm_atomic_helper_connector_hdmi_update(connector, status);
+	return drm_atomic_helper_connector_hdmi_update(connector, status, ctx);
 }
 EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_hotplug);
 
Quoted 9 lines

drivers/gpu/drm/display/drm_hdmi_state_helper.c EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_hotplug); · line 1268

Quoted 7 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +1 -1
@@ -1254,6 +1264,6 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_hotplug);
  */
 void drm_atomic_helper_connector_hdmi_force(struct drm_connector *connector)
 {
-	drm_atomic_helper_connector_hdmi_update(connector, connector->status);
+	drm_atomic_helper_connector_hdmi_update(connector, connector->status, NULL);
 }

We should create a new context here.

Ack.

Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +0 -0
 EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_force);
drivers/gpu/drm/vc4/vc4_hdmi.c +0 -0
index 74dce4be0c00..e165f604939b 100644
@@ -375,7 +375,7 @@ static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi,
 	 * the lock for now.
 	 */
 
Quoted 4 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi, · line 378

Quoted 2 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
-	drm_atomic_helper_connector_hdmi_hotplug(connector, status);
+	drm_atomic_helper_connector_hdmi_hotplug(connector, status, NULL);

vc4_hdmi_handle_hotplug has the context passed as an argument, we should reuse it.

The vc4 conversion (patch 31) removes vc4_hdmi_handle_hotplug() and calls drm_atomic_helper_connector_hdmi_hotplug() directly in vc4_hdmi_connector_detect_ctx().

I used NULL here to ensure there wouldn't be any race between the two separate SCDC state management implementations, but that can't happen at this point anyway (hdmi->scrambler_enabled isn't set by the driver). So we can pass the context if you prefer.

Thanks,
Cristian

maintainer
#57 lore raw

Re: [PATCH v8 10/39] drm/display: hdmi-state-helper: Sync SCDC state on hotplug

Quoted 20 lines · Cristian Ciocaltea
Quoted 20 lines
Quoted 20 lines
---
 drivers/gpu/drm/display/drm_bridge_connector.c  |  3 ++-
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 28 +++++++++++++++++--------
 drivers/gpu/drm/vc4/vc4_hdmi.c                  |  2 +-
 include/drm/display/drm_hdmi_state_helper.h     |  6 ++++--
 4 files changed, 26 insertions(+), 13 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +2 -1
index 796069dbf1a1..46104506fe32 100644
@@ -221,7 +221,8 @@ drm_bridge_connector_detect(struct drm_connector *connector, bool force)
 		status = detect->funcs->detect(detect, connector);
 
 		if (hdmi)
-			drm_atomic_helper_connector_hdmi_hotplug(connector, status);
+			drm_atomic_helper_connector_hdmi_hotplug(connector, status,
+								 NULL);
 
Quoted 7 lines
Quoted 5 lines

drivers/gpu/drm/display/drm_bridge_connector.c drm_bridge_connector_detect(struct drm_connector *connector, bool force) · line 228

Quoted 2 lines
drivers/gpu/drm/display/drm_bridge_connector.c +0 -0
 		drm_bridge_connector_hpd_notify(connector, status);
 	} else {

We should move this one to detect_ctx to get the ctx passed and avoid passing NULL here.

We do this in patch 15. Should I try to reorder?

Yes, it would make this part more obvious

[...]

Quoted 14 lines
Quoted 9 lines
Quoted 9 lines

EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_force);

drivers/gpu/drm/vc4/vc4_hdmi.c +0 -0
index 74dce4be0c00..e165f604939b 100644
@@ -375,7 +375,7 @@ static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi,
 	 * the lock for now.
 	 */
 
Quoted 4 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi, · line 378

Quoted 2 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
-	drm_atomic_helper_connector_hdmi_hotplug(connector, status);
+	drm_atomic_helper_connector_hdmi_hotplug(connector, status, NULL);

vc4_hdmi_handle_hotplug has the context passed as an argument, we should reuse it.

Quoted 8 lines

The vc4 conversion (patch 31) removes vc4_hdmi_handle_hotplug() and calls drm_atomic_helper_connector_hdmi_hotplug() directly in vc4_hdmi_connector_detect_ctx().

I used NULL here to ensure there wouldn't be any race between the two separate SCDC state management implementations, but that can't happen at this point anyway (hdmi->scrambler_enabled isn't set by the driver). So we can pass the context if you prefer.

We still need this to be bisectable, so yeah, please do.

Thanks!
Maxime

#58 lore raw

PATCH v8 11/39 drm/display: hdmi-state-helper: Set HDMI scrambling requirement

In reply to Cristian Ciocaltea

Set drm_connector_hdmi_state.scrambler_needed when the computed TMDS character rate exceeds the HDMI 1.3 maximum TMDS character rate.

HDMI 2.0 requires scrambling above 340 MHz. Centralize that clock-based requirement in the HDMI state helper so drivers do not need to open-code the threshold check.

---
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/display/drm_hdmi_state_helper.c +1 -0
index 69ccfbf123fe..34e48e04d971 100644
@@ -592,6 +592,7 @@ hdmi_compute_clock(const struct drm_connector *connector,
 		return -EINVAL;
 
 	conn_state->hdmi.tmds_char_rate = clock;
+	conn_state->hdmi.scrambler_needed = (clock > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ);
 
 	return 0;
 }
Signature · 1 line
2.54.0
#59 lore raw

Re: [PATCH v8 11/39] drm/display: hdmi-state-helper: Set HDMI scrambling requirement

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Missing validation of SCDC scrambling capabilities in HDMI atomic check, leading to atomic commit…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing validation of SCDC scrambling capabilities in HDMI atomic check, leading to atomic commit failure.
- [Low] Kernel doc for scrambler_needed incorrectly claims it considers capabilities.
--

commit 8506d2c44481f513bea9b489debfc6aacfc2b9a2
Author: Cristian Ciocaltea <[email protected]>

drm/display: hdmi-state-helper: Set HDMI scrambling requirement

This commit sets the drm_connector_hdmi_state.scrambler_needed flag when the computed TMDS character rate exceeds the HDMI 1.3 maximum limit. By centralizing this clock-based requirement in the HDMI state helper, it removes the need for drivers to open-code the threshold check.

drivers/gpu/drm/display/drm_hdmi_state_helper.c hdmi_compute_clock(const struct drm_connector *connector, · line 595

Quoted 9 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +1 -0
index 69ccfbf123fe3..34e48e04d9712 100644
@@ -592,6 +592,7 @@ hdmi_compute_clock(const struct drm_connector *connector,
 		return -EINVAL;
 
 	conn_state->hdmi.tmds_char_rate = clock;
+	conn_state->hdmi.scrambler_needed = (clock > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ);

[Severity: High]
Does this code fail to validate SCDC scrambling capabilities during atomic check?

Setting scrambler_needed purely based on the clock rate, without validating if scrambling is actually supported by the sink and source, allows invalid atomic states to proceed.

If an HDMI sink provides a buggy EDID reporting >= 340 MHz but without SCDC scrambling support (or the source lacks scrambling support), a mode requiring

Quoted 1 line

340 MHz TMDS rate could be requested. hdmi_clock_valid() passes because

info->max_tmds_clock doesn't reject it.

Because hdmi_compute_clock() unconditionally sets scrambler_needed = true without checking if scrambling is actually supported by both source and sink, the atomic_check succeeds.

Then, atomic_commit calls drm_connector_hdmi_enable_scrambling(), which checks capabilities, finds them lacking, and returns -EINVAL.

Returning an error during the atomic commit phase violates the DRM atomic KMS contract. This leads to a state where the hardware might be partially programmed and the driver aborts the commit, which can cause black screens, driver state desync, or kernel warnings.

[Severity: Low]
Does this change make the kernel documentation for drm_connector_hdmi_state inaccurate?

In include/drm/drm_connector.h, the kernel doc for scrambler_needed states it is computed from the capabilities:

include/drm/drm_connector.h:drm_connector_hdmi_state
/**
* @scrambler_needed: Whether HDMI 2.0 SCDC scrambling is required
* for the negotiated mode/bpc/format.
*
* Computed by drm_atomic_helper_connector_hdmi_check() from
* @tmds_char_rate and the source/sink scrambling capabilities.

But the implementation now only checks the clock against HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ, creating a documentation mismatch.

Quoted 3 lines

return 0;
}

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
maintainer Acked-by on v8 11/39
#60 lore raw

Re: [PATCH v8 11/39] drm/display: hdmi-state-helper: Set HDMI scrambling requirement

In reply to Cristian Ciocaltea
Quoted 17 lines · Cristian Ciocaltea

Set drm_connector_hdmi_state.scrambler_needed when the computed TMDS character rate exceeds the HDMI 1.3 maximum TMDS character rate.

HDMI 2.0 requires scrambling above 340 MHz. Centralize that clock-based requirement in the HDMI state helper so drivers do not need to open-code the threshold check.

---
 drivers/gpu/drm/display/drm_hdmi_state_helper.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/display/drm_hdmi_state_helper.c +0 -0
index 69ccfbf123fe..34e48e04d971 100644

drivers/gpu/drm/display/drm_hdmi_state_helper.c hdmi_compute_clock(const struct drm_connector *connector, · line 595

Quoted 4 lines
drivers/gpu/drm/display/drm_hdmi_state_helper.c +1 -0
@@ -592,6 +592,7 @@ hdmi_compute_clock(const struct drm_connector *connector,
 		return -EINVAL;
 
 	conn_state->hdmi.tmds_char_rate = clock;
+	conn_state->hdmi.scrambler_needed = (clock > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ);

I'd add a FIXME/TODO comment that we might want to check drm_display_info.hdmi.scdc.scrambling.low_rates

With that fixed,

Maxime

#61 lore raw

PATCH v8 12/39 drm/bridge: Remove redundant error check in drm_bridge_helper_reset_crtc()

In reply to Cristian Ciocaltea

Remove the no-op error check after drm_atomic_helper_reset_crtc() since the goto target is the immediately following label and the return value is already propagated correctly without it.

---
 drivers/gpu/drm/drm_bridge_helper.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/drm_bridge_helper.c +0 -2
index 420f29cf3e54..0a3c8fee66b3 100644
@@ -50,8 +50,6 @@ int drm_bridge_helper_reset_crtc(struct drm_bridge *bridge,
 
 	crtc = connector->state->crtc;
 	ret = drm_atomic_helper_reset_crtc(crtc, ctx);
-	if (ret)
-		goto out;
 
 out:
 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
Signature · 1 line
2.54.0
#62 lore raw

Re: [PATCH v8 12/39] drm/bridge: Remove redundant error check in drm_bridge_helper_reset_crtc()

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Preexisting double unlock of connection_mutex and lockless access to connector state in drm_bridge_helper_reset_crtc(). --

commit 8efd841f2ea4070344d378811452cf54e3a77546
Author: Cristian Ciocaltea <[email protected]>

drm/bridge: Remove redundant error check in drm_bridge_helper_reset_crtc()

This commit removes a no-op error check after drm_atomic_helper_reset_crtc, as the goto target is the immediately following label and the return value is already propagated correctly.

drivers/gpu/drm/drm_bridge_helper.c int drm_bridge_helper_reset_crtc(struct drm_bridge *bridge, · line 55

Quoted 13 lines
drivers/gpu/drm/drm_bridge_helper.c +0 -2
index 420f29cf3e543..0a3c8fee66b32 100644
@@ -50,8 +50,6 @@ int drm_bridge_helper_reset_crtc(struct drm_bridge *bridge,
 
 	crtc = connector->state->crtc;
 	ret = drm_atomic_helper_reset_crtc(crtc, ctx);
-	if (ret)
-		goto out;
 
 out:
 	drm_modeset_unlock(&dev->mode_config.connection_mutex);

[Severity: High]
This isn't a bug introduced by this patch, but does this function have a pre-existing double unlock bug due to how drm_atomic_get_connector_for_encoder behaves?

Looking at drm_bridge_helper_reset_crtc, it first acquires connection_mutex via drm_modeset_lock.

It then calls drm_atomic_get_connector_for_encoder. Because the lock is already held by ctx, the drm_modeset_lock call inside the helper returns 0 rather than an error. However, drm_atomic_get_connector_for_encoder unconditionally calls drm_modeset_unlock on the connection_mutex before returning.

Since ww_mutex does not track nesting depths, the lock is completely dropped.

Does this lead to connector->state being accessed without the lock just before this hunk, and then a subsequent double unlock when drm_modeset_unlock is called again here at the out label?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
#63 lore raw

PATCH v8 13/39 drm/bridge: Add bridge ops for source-side HDMI 2.0 scrambling

In reply to Cristian Ciocaltea

Bridges advertising HDMI 2.0 must be able to enable and disable source-side scrambling and the high TMDS clock ratio when the configured mode exceeds 340 MHz.

Add .hdmi_scrambler_{enable|disable}() callbacks covering the source-side programming only; sink-side SCDC negotiation remains the job of the HDMI connector helpers.

---
 include/drm/drm_bridge.h | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
include/drm/drm_bridge.h +35 -0
index 2d8b5e4c64ba..236d1cabe669 100644
@@ -656,6 +656,41 @@ struct drm_bridge_funcs {
 				     const struct drm_display_mode *mode,
 				     unsigned long long tmds_rate);
 
+	/**
+	 * @hdmi_scrambler_enable:
+	 *
+	 * Enable source-side scrambling and the high TMDS clock ratio for the
+	 * mode currently being applied.
+	 *
+	 * This only programs the source side. Sink-side SCDC configuration is
+	 * handled by the HDMI connector helpers.
+	 *
+	 * Mandatory for bridges that set the DRM_BRIDGE_OP_HDMI flag in their
+	 * &drm_bridge->ops and advertise HDMI_VERSION_2_0 or later via
+	 * &drm_bridge->supported_hdmi_ver; unused otherwise.
+	 *
+	 * Returns:
+	 * 0 on success, a negative error code otherwise.
+	 */
+	int (*hdmi_scrambler_enable)(struct drm_bridge *bridge);
+
+	/**
+	 * @hdmi_scrambler_disable:
+	 *
+	 * Disable source-side scrambling and the high TMDS clock ratio.
+	 *
+	 * This only programs the source side. Sink-side SCDC configuration is
+	 * handled by the HDMI connector helpers.
+	 *
+	 * Mandatory for bridges that set the DRM_BRIDGE_OP_HDMI flag in their
+	 * &drm_bridge->ops and advertise HDMI_VERSION_2_0 or later via
+	 * &drm_bridge->supported_hdmi_ver; unused otherwise.
+	 *
+	 * Returns:
+	 * 0 on success, a negative error code otherwise.
+	 */
+	int (*hdmi_scrambler_disable)(struct drm_bridge *bridge);
+
 	/**
 	 * @hdmi_clear_avi_infoframe:
 	 *
Signature · 1 line
2.54.0
#64 lore raw

PATCH v8 14/39 drm/display: bridge_connector: Use cached connector status in .get_modes()

In reply to Cristian Ciocaltea

Replace the active drm_bridge_connector_detect() call in get_modes() with a read of the already-cached connector->status.

The .get_modes() callback is only invoked from drm_helper_probe_single_connector_modes(), which has already retrieved the connector status. Calling detect again is redundant and triggers a duplicate hotplug event. This is also a prerequisite for switching to the .detect_ctx() hook, which requires a drm_modeset_acquire_ctx not available in the .get_modes() path.

---
 drivers/gpu/drm/display/drm_bridge_connector.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +1 -3
index 46104506fe32..57238ba49d70 100644
@@ -326,12 +326,10 @@ static const struct drm_connector_funcs drm_bridge_connector_funcs = {
 static int drm_bridge_connector_get_modes_edid(struct drm_connector *connector,
 					       struct drm_bridge *bridge)
 {
-	enum drm_connector_status status;
 	const struct drm_edid *drm_edid;
 	int n;
 
-	status = drm_bridge_connector_detect(connector, false);
-	if (status != connector_status_connected)
+	if (connector->status != connector_status_connected)
 		goto no_edid;
 
 	drm_edid = drm_bridge_edid_read(bridge, connector);
Signature · 1 line
2.54.0
#65 lore raw

PATCH v8 15/39 drm/display: bridge_connector: Switch to .detect_ctx() connector helper

In reply to Cristian Ciocaltea

Replace the .detect() connector_funcs callback with the atomic-aware .detect_ctx() connector_helper_funcs hook.

This propagates the modeset acquire context through drm_atomic_helper_connector_hdmi_hotplug() to the HDMI connector framework, enabling SCDC state recovery via CRTC reset when the sink reconnects during an active display pipeline.

---
 drivers/gpu/drm/display/drm_bridge_connector.c | 74 ++++++++++++++------------
 1 file changed, 39 insertions(+), 35 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +39 -35
index 57238ba49d70..17eb2548efad 100644
@@ -208,40 +208,6 @@ static void drm_bridge_connector_disable_hpd(struct drm_connector *connector)
  * Bridge Connector Functions
  */
 
-static enum drm_connector_status
-drm_bridge_connector_detect(struct drm_connector *connector, bool force)
-{
-	struct drm_bridge_connector *bridge_connector =
-		to_drm_bridge_connector(connector);
-	struct drm_bridge *detect = bridge_connector->bridge_detect;
-	struct drm_bridge *hdmi = bridge_connector->bridge_hdmi;
-	enum drm_connector_status status;
-
-	if (detect) {
-		status = detect->funcs->detect(detect, connector);
-
-		if (hdmi)
-			drm_atomic_helper_connector_hdmi_hotplug(connector, status,
-								 NULL);
-
-		drm_bridge_connector_hpd_notify(connector, status);
-	} else {
-		switch (connector->connector_type) {
-		case DRM_MODE_CONNECTOR_DPI:
-		case DRM_MODE_CONNECTOR_LVDS:
-		case DRM_MODE_CONNECTOR_DSI:
-		case DRM_MODE_CONNECTOR_eDP:
-			status = connector_status_connected;
-			break;
-		default:
-			status = connector_status_unknown;
-			break;
-		}
-	}
-
-	return status;
-}
-
 static void drm_bridge_connector_force(struct drm_connector *connector)
 {
 	struct drm_bridge_connector *bridge_connector =
@@ -308,7 +274,6 @@ drm_bridge_connector_color_format(const struct drm_connector_state *conn_state)
 }
 
 static const struct drm_connector_funcs drm_bridge_connector_funcs = {
-	.detect = drm_bridge_connector_detect,
 	.force = drm_bridge_connector_force,
 	.fill_modes = drm_helper_probe_single_connector_modes,
 	.atomic_create_state = drm_bridge_connector_create_state,
@@ -323,6 +288,44 @@ static const struct drm_connector_funcs drm_bridge_connector_funcs = {
  * Bridge Connector Helper Functions
  */
 
+static int drm_bridge_connector_detect_ctx(struct drm_connector *connector,
+					   struct drm_modeset_acquire_ctx *ctx,
+					   bool force)
+{
+	struct drm_bridge_connector *bridge_connector =
+		to_drm_bridge_connector(connector);
+	struct drm_bridge *detect = bridge_connector->bridge_detect;
+	struct drm_bridge *hdmi = bridge_connector->bridge_hdmi;
+	enum drm_connector_status status;
+	int ret;
+
+	if (detect) {
+		status = detect->funcs->detect(detect, connector);
+
+		if (hdmi) {
+			ret = drm_atomic_helper_connector_hdmi_hotplug(connector, status, ctx);
+			if (ret == -EDEADLK)
+				return ret;
+		}
+
+		drm_bridge_connector_hpd_notify(connector, status);
+	} else {
+		switch (connector->connector_type) {
+		case DRM_MODE_CONNECTOR_DPI:
+		case DRM_MODE_CONNECTOR_LVDS:
+		case DRM_MODE_CONNECTOR_DSI:
+		case DRM_MODE_CONNECTOR_eDP:
+			status = connector_status_connected;
+			break;
+		default:
+			status = connector_status_unknown;
+			break;
+		}
+	}
+
+	return status;
+}
+
 static int drm_bridge_connector_get_modes_edid(struct drm_connector *connector,
 					       struct drm_bridge *bridge)
 {
@@ -414,6 +417,7 @@ static int drm_bridge_connector_atomic_check(struct drm_connector *connector,
 
 static const struct drm_connector_helper_funcs drm_bridge_connector_helper_funcs = {
 	.get_modes = drm_bridge_connector_get_modes,
+	.detect_ctx = drm_bridge_connector_detect_ctx,
 	.mode_valid = drm_bridge_connector_mode_valid,
 	.enable_hpd = drm_bridge_connector_enable_hpd,
 	.disable_hpd = drm_bridge_connector_disable_hpd,
Signature · 1 line
2.54.0
#66 lore raw

PATCH v8 16/39 drm/display: bridge_connector: Wire up HDMI 2.0 scrambler callbacks

In reply to Cristian Ciocaltea

Connect the bridge connector's .scrambler_{enable|disable} callbacks to the underlying bridge's .hdmi_scrambler_{enable|disable} funcs when HDMI 2.0 conformance is advertised.

This completes the bridge connector plumbing so that the SCDC scrambling helpers can control source-side scrambling through the bridge chain.

---
 drivers/gpu/drm/display/drm_bridge_connector.c | 40 +++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
drivers/gpu/drm/display/drm_bridge_connector.c +39 -1
index 17eb2548efad..ceb961a9adb5 100644
@@ -578,6 +578,32 @@ static int drm_bridge_connector_write_spd_infoframe(struct drm_connector *connec
 	return bridge->funcs->hdmi_write_spd_infoframe(bridge, buffer, len);
 }
 
+static int drm_bridge_connector_scrambler_enable(struct drm_connector *connector)
+{
+	struct drm_bridge_connector *bridge_connector =
+		to_drm_bridge_connector(connector);
+	struct drm_bridge *bridge;
+
+	bridge = bridge_connector->bridge_hdmi;
+	if (!bridge)
+		return -EINVAL;
+
+	return bridge->funcs->hdmi_scrambler_enable(bridge);
+}
+
+static int drm_bridge_connector_scrambler_disable(struct drm_connector *connector)
+{
+	struct drm_bridge_connector *bridge_connector =
+		to_drm_bridge_connector(connector);
+	struct drm_bridge *bridge;
+
+	bridge = bridge_connector->bridge_hdmi;
+	if (!bridge)
+		return -EINVAL;
+
+	return bridge->funcs->hdmi_scrambler_disable(bridge);
+}
+
 static const struct drm_edid *
 drm_bridge_connector_read_edid(struct drm_connector *connector)
 {
@@ -603,7 +629,7 @@ static const struct drm_connector_hdmi_funcs drm_bridge_connector_hdmi_funcs = {
 		.clear_infoframe = drm_bridge_connector_clear_hdmi_infoframe,
 		.write_infoframe = drm_bridge_connector_write_hdmi_infoframe,
 	},
-	/* audio, hdr_drm and spd are set dynamically during init */
+	/* scrambler, audio, hdr_drm and spd are set dynamically during init */
 };
 
 static const struct drm_connector_infoframe_funcs drm_bridge_connector_hdmi_audio_infoframe = {
@@ -912,6 +938,11 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 			     !bridge->funcs->hdmi_clear_spd_infoframe))
 				return ERR_PTR(-EINVAL);
 
+			if (bridge->supported_hdmi_ver >= HDMI_VERSION_2_0 &&
+			    (!bridge->funcs->hdmi_scrambler_enable ||
+			     !bridge->funcs->hdmi_scrambler_disable))
+				return ERR_PTR(-EINVAL);
+
 			bridge_connector->bridge_hdmi = drm_bridge_get(bridge);
 
 			if (bridge->supported_hdmi_ver)
@@ -1018,6 +1049,13 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 			bridge_connector->hdmi_funcs.spd =
 				drm_bridge_connector_hdmi_spd_infoframe;
 
+		if (bridge_connector->bridge_hdmi->supported_hdmi_ver >= HDMI_VERSION_2_0) {
+			bridge_connector->hdmi_funcs.scrambler_enable =
+				drm_bridge_connector_scrambler_enable;
+			bridge_connector->hdmi_funcs.scrambler_disable =
+				drm_bridge_connector_scrambler_disable;
+		}
+
 		ret = drmm_connector_hdmi_init_with_caps(drm, connector,
 							 bridge_connector->bridge_hdmi->vendor,
 							 bridge_connector->bridge_hdmi->product,
Signature · 1 line
2.54.0
#67 lore raw

PATCH v8 17/39 drm/bridge: dw-hdmi-qp: Rate limit i2c read error messages

In reply to Cristian Ciocaltea

During EDID reads, repeated i2c errors can flood the kernel log:

[   25.361716] dwhdmiqp-rockchip fde80000.hdmi: i2c read error
[   25.363376] dwhdmiqp-rockchip fde80000.hdmi: i2c read error
...
[   25.368671] dwhdmiqp-rockchip fde80000.hdmi: i2c read error
[   25.369440] dwhdmiqp-rockchip fde80000.hdmi: failed to get edid

Switch to dev_err_ratelimited() in dw_hdmi_qp_i2c_read() to reduce log spam while still reporting the condition.

---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +2 -2
index cfd1b18c06e6..7475b6b71836 100644
@@ -561,7 +561,7 @@ static int dw_hdmi_qp_i2c_read(struct dw_hdmi_qp *hdmi,
 				dev_dbg_ratelimited(hdmi->dev,
 						    "i2c read timed out\n");
 			else
-				dev_err(hdmi->dev, "i2c read timed out\n");
+				dev_err_ratelimited(hdmi->dev, "i2c read timed out\n");
 			dw_hdmi_qp_write(hdmi, 0x01, I2CM_CONTROL0);
 			return -EAGAIN;
 		}
@@ -572,7 +572,7 @@ static int dw_hdmi_qp_i2c_read(struct dw_hdmi_qp *hdmi,
 				dev_dbg_ratelimited(hdmi->dev,
 						    "i2c read error\n");
 			else
-				dev_err(hdmi->dev, "i2c read error\n");
+				dev_err_ratelimited(hdmi->dev, "i2c read error\n");
 			dw_hdmi_qp_write(hdmi, 0x01, I2CM_CONTROL0);
 			return -EIO;
 		}
Signature · 1 line
2.54.0
#68 lore raw

PATCH v8 18/39 drm/bridge: dw-hdmi-qp: Provide .{enable|disable}_hpd() PHY ops

In reply to Cristian Ciocaltea

Implement the .hpd_enable() and .hpd_disable() bridge callbacks and extend dw_hdmi_qp_phy_ops with corresponding hooks.

This enables the DRM core to control when HPD interrupts are armed, which is needed to prevent premature interrupt delivery before the connector is fully initialized, and to properly quiesce HPD during suspend.

---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c | 18 ++++++++++++++++++
 include/drm/bridge/dw_hdmi_qp.h              |  2 ++
 2 files changed, 20 insertions(+)
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +18 -0
index 7475b6b71836..a0613f0d2ebc 100644
@@ -1189,6 +1189,22 @@ static int dw_hdmi_qp_cec_transmit(struct drm_bridge *bridge, u8 attempts,
 #define dw_hdmi_qp_cec_transmit NULL
 #endif /* CONFIG_DRM_DW_HDMI_QP_CEC */
 
+static void dw_hdmi_qp_bridge_hpd_enable(struct drm_bridge *bridge)
+{
+	struct dw_hdmi_qp *hdmi = bridge->driver_private;
+
+	if (hdmi->phy.ops->enable_hpd)
+		hdmi->phy.ops->enable_hpd(hdmi, hdmi->phy.data);
+}
+
+static void dw_hdmi_qp_bridge_hpd_disable(struct drm_bridge *bridge)
+{
+	struct dw_hdmi_qp *hdmi = bridge->driver_private;
+
+	if (hdmi->phy.ops->disable_hpd)
+		hdmi->phy.ops->disable_hpd(hdmi, hdmi->phy.data);
+}
+
 static const struct drm_bridge_funcs dw_hdmi_qp_bridge_funcs = {
 	.atomic_get_output_bus_fmts = drm_atomic_helper_bridge_get_hdmi_output_bus_fmts,
 	.atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
@@ -1197,6 +1213,8 @@ static const struct drm_bridge_funcs dw_hdmi_qp_bridge_funcs = {
 	.atomic_enable = dw_hdmi_qp_bridge_atomic_enable,
 	.atomic_disable = dw_hdmi_qp_bridge_atomic_disable,
 	.detect = dw_hdmi_qp_bridge_detect,
+	.hpd_enable = dw_hdmi_qp_bridge_hpd_enable,
+	.hpd_disable = dw_hdmi_qp_bridge_hpd_disable,
 	.edid_read = dw_hdmi_qp_bridge_edid_read,
 	.hdmi_tmds_char_rate_valid = dw_hdmi_qp_bridge_tmds_char_rate_valid,
 	.hdmi_clear_avi_infoframe = dw_hdmi_qp_bridge_clear_avi_infoframe,
include/drm/bridge/dw_hdmi_qp.h +2 -0
index 6ea9c561cfef..b80fceffc315 100644
@@ -17,6 +17,8 @@ struct dw_hdmi_qp_phy_ops {
 	void (*disable)(struct dw_hdmi_qp *hdmi, void *data);
 	enum drm_connector_status (*read_hpd)(struct dw_hdmi_qp *hdmi, void *data);
 	void (*setup_hpd)(struct dw_hdmi_qp *hdmi, void *data);
+	void (*enable_hpd)(struct dw_hdmi_qp *hdmi, void *data);
+	void (*disable_hpd)(struct dw_hdmi_qp *hdmi, void *data);
 };
 
 struct dw_hdmi_qp_plat_data {
Signature · 1 line
2.54.0
#69 lore raw

PATCH v8 19/39 drm/bridge: dw-hdmi-qp: Add HDMI 2.0 SCDC scrambling support

In reply to Cristian Ciocaltea

Enable HDMI 2.0 display modes (e.g. 4K@60Hz) by implementing SCDC scrambling and high TMDS clock ratio management for TMDS character rates exceeding the 340 MHz HDMI 1.4b limit.

Reject modes requiring TMDS rates above 600 MHz since those require HDMI 2.1 FRL which is not yet supported. In no_hpd configurations, further restrict to 340 MHz because SCDC requires a connected sink.

---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c | 73 ++++++++++++++++++++--------
 1 file changed, 54 insertions(+), 19 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +54 -19
index a0613f0d2ebc..07b274f76e53 100644
@@ -2,6 +2,7 @@
 /*
  * Copyright (c) 2021-2022 Rockchip Electronics Co., Ltd.
  * Copyright (c) 2024 Collabora Ltd.
+ * Copyright (c) 2025 Amazon.com, Inc. or its affiliates.
  *
  * Author: Algea Cao <[email protected]>
  * Author: Cristian Ciocaltea <[email protected]>
@@ -15,7 +16,6 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/of.h>
-#include <linux/workqueue.h>
 
 #include <drm/bridge/dw_hdmi_qp.h>
 #include <drm/display/drm_hdmi_helper.h>
@@ -38,8 +38,6 @@
 #define DDC_CI_ADDR		0x37
 #define DDC_SEGMENT_ADDR	0x30
 
-#define SCRAMB_POLL_DELAY_MS	3000
-
 /*
  * Unless otherwise noted, entries in this table are 100% optimization.
  * Values can be obtained from dw_hdmi_qp_compute_n() but that function is
@@ -162,6 +160,7 @@ struct dw_hdmi_qp {
 	} phy;
 
 	unsigned long ref_clk_rate;
+	struct drm_connector *curr_conn;
 	struct regmap *regm;
 	int main_irq;
 
@@ -752,26 +751,33 @@ static void dw_hdmi_qp_bridge_atomic_enable(struct drm_bridge *bridge,
 {
 	struct dw_hdmi_qp *hdmi = bridge->driver_private;
 	struct drm_connector_state *conn_state;
-	struct drm_connector *connector;
 	unsigned int op_mode;
+	int ret;
 
-	connector = drm_atomic_get_new_connector_for_encoder(state, bridge->encoder);
-	if (WARN_ON(!connector))
+	hdmi->curr_conn = drm_atomic_get_new_connector_for_encoder(state,
+								   bridge->encoder);
+	if (WARN_ON(!hdmi->curr_conn))
 		return;
 
-	conn_state = drm_atomic_get_new_connector_state(state, connector);
+	conn_state = drm_atomic_get_new_connector_state(state, hdmi->curr_conn);
 	if (WARN_ON(!conn_state))
 		return;
 
-	if (connector->display_info.is_hdmi) {
-		dev_dbg(hdmi->dev, "%s mode=HDMI %s rate=%llu bpc=%u\n", __func__,
-			drm_hdmi_connector_get_output_format_name(conn_state->hdmi.output_format),
-			conn_state->hdmi.tmds_char_rate, conn_state->hdmi.output_bpc);
+	if (hdmi->curr_conn->display_info.is_hdmi) {
 		op_mode = 0;
 		hdmi->tmds_char_rate = conn_state->hdmi.tmds_char_rate;
+
+		ret = drm_connector_hdmi_enable_scrambling(hdmi->curr_conn, conn_state);
+		if (ret)
+			dev_warn(hdmi->dev, "Failed to setup SCDC: %d\n", ret);
+
+		dev_dbg(hdmi->dev, "%s mode=HDMI %s rate=%llu bpc=%u scramb=%d\n", __func__,
+			drm_hdmi_connector_get_output_format_name(conn_state->hdmi.output_format),
+			conn_state->hdmi.tmds_char_rate, conn_state->hdmi.output_bpc,
+			hdmi->curr_conn->hdmi.scrambler_enabled);
 	} else {
-		dev_dbg(hdmi->dev, "%s mode=DVI\n", __func__);
 		op_mode = OPMODE_DVI;
+		dev_dbg(hdmi->dev, "%s mode=DVI\n", __func__);
 	}
 
 	hdmi->phy.ops->init(hdmi, hdmi->phy.data);
@@ -779,7 +785,7 @@ static void dw_hdmi_qp_bridge_atomic_enable(struct drm_bridge *bridge,
 	dw_hdmi_qp_mod(hdmi, HDCP2_BYPASS, HDCP2_BYPASS, HDCP2LOGIC_CONFIG0);
 	dw_hdmi_qp_mod(hdmi, op_mode, OPMODE_DVI, LINK_CONFIG0);
 
-	drm_atomic_helper_connector_hdmi_update_infoframes(connector, state);
+	drm_atomic_helper_connector_hdmi_update_infoframes(hdmi->curr_conn, state);
 }
 
 static void dw_hdmi_qp_bridge_atomic_disable(struct drm_bridge *bridge,
@@ -787,8 +793,14 @@ static void dw_hdmi_qp_bridge_atomic_disable(struct drm_bridge *bridge,
 {
 	struct dw_hdmi_qp *hdmi = bridge->driver_private;
 
+	if (!hdmi->curr_conn)
+		return;
+
 	hdmi->tmds_char_rate = 0;
 
+	drm_connector_hdmi_disable_scrambling(hdmi->curr_conn);
+
+	hdmi->curr_conn = NULL;
 	hdmi->phy.ops->disable(hdmi, hdmi->phy.data);
 }
 
@@ -830,12 +842,12 @@ dw_hdmi_qp_bridge_tmds_char_rate_valid(const struct drm_bridge *bridge,
 {
 	struct dw_hdmi_qp *hdmi = bridge->driver_private;
 
-	/*
-	 * TODO: when hdmi->no_hpd is 1 we must not support modes that
-	 * require scrambling, including every mode with a clock above
-	 * HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ.
-	 */
-	if (rate > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ) {
+	if (hdmi->no_hpd && rate > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ) {
+		dev_dbg(hdmi->dev, "Unsupported TMDS char rate in no_hpd mode: %lld\n", rate);
+		return MODE_CLOCK_HIGH;
+	}
+
+	if (rate > HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ) {
 		dev_dbg(hdmi->dev, "Unsupported TMDS char rate: %lld\n", rate);
 		return MODE_CLOCK_HIGH;
 	}
@@ -843,6 +855,26 @@ dw_hdmi_qp_bridge_tmds_char_rate_valid(const struct drm_bridge *bridge,
 	return MODE_OK;
 }
 
+static int dw_hdmi_qp_bridge_scrambler_enable(struct drm_bridge *bridge)
+{
+	struct dw_hdmi_qp *hdmi = bridge->driver_private;
+
+	dw_hdmi_qp_write(hdmi, 1, SCRAMB_CONFIG0);
+	dev_dbg(hdmi->dev, "scrambler enabled\n");
+
+	return 0;
+}
+
+static int dw_hdmi_qp_bridge_scrambler_disable(struct drm_bridge *bridge)
+{
+	struct dw_hdmi_qp *hdmi = bridge->driver_private;
+
+	dw_hdmi_qp_write(hdmi, 0, SCRAMB_CONFIG0);
+	dev_dbg(hdmi->dev, "scrambler disabled\n");
+
+	return 0;
+}
+
 static int dw_hdmi_qp_bridge_clear_avi_infoframe(struct drm_bridge *bridge)
 {
 	struct dw_hdmi_qp *hdmi = bridge->driver_private;
@@ -1217,6 +1249,8 @@ static const struct drm_bridge_funcs dw_hdmi_qp_bridge_funcs = {
 	.hpd_disable = dw_hdmi_qp_bridge_hpd_disable,
 	.edid_read = dw_hdmi_qp_bridge_edid_read,
 	.hdmi_tmds_char_rate_valid = dw_hdmi_qp_bridge_tmds_char_rate_valid,
+	.hdmi_scrambler_enable = dw_hdmi_qp_bridge_scrambler_enable,
+	.hdmi_scrambler_disable = dw_hdmi_qp_bridge_scrambler_disable,
 	.hdmi_clear_avi_infoframe = dw_hdmi_qp_bridge_clear_avi_infoframe,
 	.hdmi_write_avi_infoframe = dw_hdmi_qp_bridge_write_avi_infoframe,
 	.hdmi_clear_hdmi_infoframe = dw_hdmi_qp_bridge_clear_hdmi_infoframe,
@@ -1350,6 +1384,7 @@ struct dw_hdmi_qp *dw_hdmi_qp_bind(struct platform_device *pdev,
 	hdmi->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
 	hdmi->bridge.vendor = "Synopsys";
 	hdmi->bridge.product = "DW HDMI QP TX";
+	hdmi->bridge.supported_hdmi_ver = HDMI_VERSION_2_0;
 
 	if (plat_data->supported_formats)
 		hdmi->bridge.supported_formats = plat_data->supported_formats;
Signature · 1 line
2.54.0
#70 lore raw

Re: [PATCH v8 19/39] drm/bridge: dw-hdmi-qp: Add HDMI 2.0 SCDC scrambling support

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] State tracking bug in atomic disable skips PHY shutdown on initial modesets. --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] State tracking bug in atomic disable skips PHY shutdown on initial modesets. --

commit 572f752e8a57b7a37e457765a056b711271ae975
Author: Cristian Ciocaltea <[email protected]>
Subject: drm/bridge: dw-hdmi-qp: Add HDMI 2.0 SCDC scrambling support

Enable HDMI 2.0 display modes (e.g. 4K@60Hz) by implementing SCDC scrambling and high TMDS clock ratio management for TMDS character rates exceeding the 340 MHz HDMI 1.4b limit. Reject modes requiring TMDS rates above 600 MHz since those require HDMI 2.1 FRL.

Quoted 4 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +0 -0
index a0613f0d2ebcf..07b274f76e53e 100644

[ ... ]

Quoted 12 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +3 -3
@@ -752,26 +751,33 @@ static void dw_hdmi_qp_bridge_atomic_enable(struct drm_bridge *bridge,
 {
 	struct dw_hdmi_qp *hdmi = bridge->driver_private;
 	struct drm_connector_state *conn_state;
-	struct drm_connector *connector;
 	unsigned int op_mode;
+	int ret;
 
-	connector = drm_atomic_get_new_connector_for_encoder(state, bridge->encoder);
-	if (WARN_ON(!connector))
+	hdmi->curr_conn = drm_atomic_get_new_connector_for_encoder(state,
+								   bridge->encoder);

[ ... ]

drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c static void dw_hdmi_qp_bridge_atomic_disable(struct drm_bridge *bridge, · line 798

Quoted 7 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +3 -0
@@ -787,8 +793,14 @@ static void dw_hdmi_qp_bridge_atomic_disable(struct drm_bridge *bridge,
 {
 	struct dw_hdmi_qp *hdmi = bridge->driver_private;
 
+	if (!hdmi->curr_conn)
+		return;
+

[Severity: Medium]
Will this early return skip the PHY disable sequence during initial modesets?

If the DRM core determines the encoder is active on boot and needs to be disabled for a new modeset, it calls dw_hdmi_qp_bridge_atomic_disable(). Because dw_hdmi_qp_bridge_atomic_enable() hasn't run yet in this boot cycle, hdmi->curr_conn will be NULL.

This causes the early return to trigger, skipping the hdmi->phy.ops->disable() call below. Could this leave the hardware in an inconsistent state, causing PLL lock failures or display glitches when atomic_enable() tries to re-initialize an already running PHY with new parameters?

To avoid caching unreferenced pointers like curr_conn across state changes, should the old connector be extracted directly from the atomic state using drm_atomic_get_old_connector_for_encoder() instead?

Quoted 7 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +3 -0
 	hdmi->tmds_char_rate = 0;
 
+	drm_connector_hdmi_disable_scrambling(hdmi->curr_conn);
+
+	hdmi->curr_conn = NULL;
 	hdmi->phy.ops->disable(hdmi, hdmi->phy.data);
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
#71 lore raw

PATCH v8 20/39 drm/bridge: dw-hdmi-qp: Provide dw_hdmi_qp_hpd_notify() helper

In reply to Cristian Ciocaltea

Export dw_hdmi_qp_hpd_notify() for platform drivers to report hot-plug detection events. Unlike drm_helper_hpd_irq_event() which polls all connectors, this helper targets only the affected connector and ensures .detect_ctx() is invoked on reconnection events to trigger SCDC state recovery.

Note that this helper may sleep, so it must only be called from a threaded HPD interrupt handler or a work function.

---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c | 31 ++++++++++++++++++++++++++++
 include/drm/bridge/dw_hdmi_qp.h              |  1 +
 2 files changed, 32 insertions(+)
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +31 -0
index 07b274f76e53..4d41ad7319a5 100644
@@ -28,6 +28,7 @@
 #include <drm/drm_edid.h>
 #include <drm/drm_modes.h>
 #include <drm/drm_print.h>
+#include <drm/drm_probe_helper.h>
 
 #include <media/cec.h>
 
@@ -1429,6 +1430,36 @@ struct dw_hdmi_qp *dw_hdmi_qp_bind(struct platform_device *pdev,
 }
 EXPORT_SYMBOL_GPL(dw_hdmi_qp_bind);
 
+/**
+ * dw_hdmi_qp_hpd_notify() - Notify a hot-plug detection event
+ * @hdmi: pointer to the DW HDMI QP controller
+ *
+ * Platform drivers should call this from their threaded IRQ handler or work
+ * function to notify the bridge of a connection status change.
+ * The bridge's .read_hpd() phy_ops callback is used to read the current
+ * connection status.
+ */
+void dw_hdmi_qp_hpd_notify(struct dw_hdmi_qp *hdmi)
+{
+	enum drm_connector_status status;
+
+	status = hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data);
+	dev_dbg(hdmi->dev, "%s status=%d\n", __func__, status);
+
+	/*
+	 * When the display pipeline has been already active, switch to
+	 * drm_connector_helper_hpd_irq_event() to ensure .detect_ctx()
+	 * gets invoked, i.e. via drm_helper_probe_detect(), because
+	 * drm_bridge_hpd_notify() defers to a delayed hotplug path in
+	 * this case.
+	 */
+	if (hdmi->curr_conn && status == connector_status_connected)
+		drm_connector_helper_hpd_irq_event(hdmi->curr_conn);
+	else
+		drm_bridge_hpd_notify(&hdmi->bridge, status);
+}
+EXPORT_SYMBOL_GPL(dw_hdmi_qp_hpd_notify);
+
 void dw_hdmi_qp_suspend(struct device *dev, struct dw_hdmi_qp *hdmi)
 {
 	disable_irq(hdmi->main_irq);
include/drm/bridge/dw_hdmi_qp.h +1 -0
index b80fceffc315..b4fb1c578a5b 100644
@@ -36,6 +36,7 @@ struct dw_hdmi_qp_plat_data {
 struct dw_hdmi_qp *dw_hdmi_qp_bind(struct platform_device *pdev,
 				   struct drm_encoder *encoder,
 				   const struct dw_hdmi_qp_plat_data *plat_data);
+void dw_hdmi_qp_hpd_notify(struct dw_hdmi_qp *hdmi);
 void dw_hdmi_qp_suspend(struct device *dev, struct dw_hdmi_qp *hdmi);
 void dw_hdmi_qp_resume(struct device *dev, struct dw_hdmi_qp *hdmi);
 #endif /* __DW_HDMI_QP__ */
Signature · 1 line
2.54.0
#72 lore raw

Re: [PATCH v8 20/39] drm/bridge: dw-hdmi-qp: Provide dw_hdmi_qp_hpd_notify() helper

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Unprotected double-read of `hdmi->curr_conn` causes a Time-Of-Check to Time-Of-Use (TOCTOU) data…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unprotected double-read of hdmi->curr_conn causes a Time-Of-Check to Time-Of-Use (TOCTOU) data race, leading to a potential NULL pointer dereference. --

commit 8041d212a61ef15cbf004795e5f7dc2a8f5f69ad
Author: Cristian Ciocaltea <[email protected]>

drm/bridge: dw-hdmi-qp: Provide dw_hdmi_qp_hpd_notify() helper

This commit introduces the dw_hdmi_qp_hpd_notify() helper to allow platform drivers to report hot-plug detection events directly to the affected connector. It ensures the detect context is invoked on reconnection events by using drm_connector_helper_hpd_irq_event() when the display pipeline is active.

Quoted 4 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +0 -0
index 07b274f76e53e..4d41ad7319a58 100644

[ ... ]

Quoted 6 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +2 -0
@@ -1429,6 +1430,36 @@ struct dw_hdmi_qp *dw_hdmi_qp_bind(struct platform_device *pdev,
 }
 EXPORT_SYMBOL_GPL(dw_hdmi_qp_bind);
 
+/**
+ * dw_hdmi_qp_hpd_notify() - Notify a hot-plug detection event

[ ... ]

Quoted 6 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +6 -0
+void dw_hdmi_qp_hpd_notify(struct dw_hdmi_qp *hdmi)
+{
+	enum drm_connector_status status;
+
+	status = hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data);
+	dev_dbg(hdmi->dev, "%s status=%d\n", __func__, status);

drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c struct dw_hdmi_qp *dw_hdmi_qp_bind(struct platform_device *pdev, · line 1457

Quoted 10 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +10 -0
+
+	/*
+	 * When the display pipeline has been already active, switch to
+	 * drm_connector_helper_hpd_irq_event() to ensure .detect_ctx()
+	 * gets invoked, i.e. via drm_helper_probe_detect(), because
+	 * drm_bridge_hpd_notify() defers to a delayed hotplug path in
+	 * this case.
+	 */
+	if (hdmi->curr_conn && status == connector_status_connected)
+		drm_connector_helper_hpd_irq_event(hdmi->curr_conn);

[Severity: High]
Could this double-read of hdmi->curr_conn lead to a NULL pointer dereference due to a Time-Of-Check to Time-Of-Use race?

If an HPD interrupt or workqueue executes dw_hdmi_qp_hpd_notify() concurrently with dw_hdmi_qp_bridge_atomic_disable() during a modeset, could the modeset thread clear hdmi->curr_conn locklessly?

Thread 1 (HPD notify):

    if (hdmi->curr_conn && ...) // Evaluates to true

Thread 2 (Modeset disable):

    dw_hdmi_qp_bridge_atomic_disable() {
        ...
        hdmi->curr_conn = NULL;
    }

Thread 1 (HPD notify resumes):

    drm_connector_helper_hpd_irq_event(hdmi->curr_conn); // Passes NULL

If the compiler emits a second read of the pointer for the argument, it would pass NULL to drm_connector_helper_hpd_irq_event(), which unconditionally dereferences the connector pointer. Would it be safer to use READ_ONCE() or a local variable to cache the connector pointer before checking and passing it?

Quoted 4 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +4 -0
+	else
+		drm_bridge_hpd_notify(&hdmi->bridge, status);
+}
+EXPORT_SYMBOL_GPL(dw_hdmi_qp_hpd_notify);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
#73 lore raw

PATCH v8 21/39 drm/rockchip: dw_hdmi_qp: Add missing newlines in dev_err_probe() messages

In reply to Cristian Ciocaltea

Add the missing trailing newlines to a couple of dev_err_probe() calls in dw_hdmi_qp_rockchip_bind().

Fixes b6736a4ea3fa ("drm/rockchip: dw_hdmi_qp: Improve error handling with dev_err_probe()")
Fixes e1f7b7cbd74c ("drm/rockchip: dw_hdmi_qp: Switch to drmm_encoder_init()")
---
 drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +2 -2
index 815f9ea7bcbe..7bd0f6dcbe5d 100644
@@ -682,14 +682,14 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
 	drm_encoder_helper_add(encoder, &dw_hdmi_qp_rockchip_encoder_helper_funcs);
 	ret = drmm_encoder_init(drm, encoder, NULL, DRM_MODE_ENCODER_TMDS, NULL);
 	if (ret)
-		return dev_err_probe(hdmi->dev, ret, "Failed to init encoder");
+		return dev_err_probe(hdmi->dev, ret, "Failed to init encoder\n");
 
 	platform_set_drvdata(pdev, hdmi);
 
 	hdmi->hdmi = dw_hdmi_qp_bind(pdev, encoder, &plat_data);
 	if (IS_ERR(hdmi->hdmi))
 		return dev_err_probe(hdmi->dev, PTR_ERR(hdmi->hdmi),
-				     "Failed to bind dw-hdmi-qp");
+				     "Failed to bind dw-hdmi-qp\n");
 
 	connector = drm_bridge_connector_init(drm, encoder);
 	if (IS_ERR(connector))
Signature · 1 line
2.54.0
#74 lore raw

PATCH v8 22/39 drm/rockchip: dw_hdmi_qp: Use local dev variable consistently in bind()

In reply to Cristian Ciocaltea

Replace indirect struct device accesses via hdmi->dev and pdev->dev with the local dev parameter already available in dw_hdmi_qp_rockchip_bind(), for consistency and readability.

---
 drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 33 +++++++++++++-------------
 1 file changed, 16 insertions(+), 17 deletions(-)
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +16 -17
index 7bd0f6dcbe5d..d2fcfa70ed16 100644
@@ -564,7 +564,7 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
 	struct clk *ref_clk;
 	int ret, irq, i;
 
-	if (!pdev->dev.of_node)
+	if (!dev->of_node)
 		return -ENODEV;
 
 	hdmi = drmm_kzalloc(drm, sizeof(*hdmi), GFP_KERNEL);
@@ -584,7 +584,7 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
 		return dev_err_probe(dev, -ENODEV, "Missing platform ctrl ops\n");
 
 	hdmi->ctrl_ops = cfg->ctrl_ops;
-	hdmi->dev = &pdev->dev;
+	hdmi->dev = dev;
 	hdmi->port_id = -ENODEV;
 
 	/* Identify port ID by matching base IO address */
@@ -595,7 +595,7 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
 		}
 	}
 	if (hdmi->port_id < 0)
-		return dev_err_probe(hdmi->dev, hdmi->port_id,
+		return dev_err_probe(dev, hdmi->port_id,
 				     "Failed to match HDMI port ID\n");
 
 	plat_data.phy_ops = cfg->phy_ops;
@@ -623,37 +623,36 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
 	hdmi->regmap = syscon_regmap_lookup_by_phandle(dev->of_node,
 						       "rockchip,grf");
 	if (IS_ERR(hdmi->regmap))
-		return dev_err_probe(hdmi->dev, PTR_ERR(hdmi->regmap),
+		return dev_err_probe(dev, PTR_ERR(hdmi->regmap),
 				     "Unable to get rockchip,grf\n");
 
 	hdmi->vo_regmap = syscon_regmap_lookup_by_phandle(dev->of_node,
 							  "rockchip,vo-grf");
 	if (IS_ERR(hdmi->vo_regmap))
-		return dev_err_probe(hdmi->dev, PTR_ERR(hdmi->vo_regmap),
+		return dev_err_probe(dev, PTR_ERR(hdmi->vo_regmap),
 				     "Unable to get rockchip,vo-grf\n");
 
-	ret = devm_clk_bulk_get_all_enabled(hdmi->dev, &clks);
+	ret = devm_clk_bulk_get_all_enabled(dev, &clks);
 	if (ret < 0)
-		return dev_err_probe(hdmi->dev, ret, "Failed to get clocks\n");
+		return dev_err_probe(dev, ret, "Failed to get clocks\n");
 
-	ref_clk = clk_get(hdmi->dev, "ref");
+	ref_clk = clk_get(dev, "ref");
 	if (IS_ERR(ref_clk))
-		return dev_err_probe(hdmi->dev, PTR_ERR(ref_clk),
+		return dev_err_probe(dev, PTR_ERR(ref_clk),
 				     "Failed to get ref clock\n");
 
 	plat_data.ref_clk_rate = clk_get_rate(ref_clk);
 	clk_put(ref_clk);
 
-	hdmi->frl_enable_gpio = devm_gpiod_get_optional(hdmi->dev, "frl-enable",
+	hdmi->frl_enable_gpio = devm_gpiod_get_optional(dev, "frl-enable",
 							GPIOD_OUT_LOW);
 	if (IS_ERR(hdmi->frl_enable_gpio))
-		return dev_err_probe(hdmi->dev, PTR_ERR(hdmi->frl_enable_gpio),
+		return dev_err_probe(dev, PTR_ERR(hdmi->frl_enable_gpio),
 				     "Failed to request FRL enable GPIO\n");
 
 	hdmi->phy = devm_of_phy_get_by_index(dev, dev->of_node, 0);
 	if (IS_ERR(hdmi->phy))
-		return dev_err_probe(hdmi->dev, PTR_ERR(hdmi->phy),
-				     "Failed to get phy\n");
+		return dev_err_probe(dev, PTR_ERR(hdmi->phy), "Failed to get phy\n");
 
 	cfg->ctrl_ops->io_init(hdmi);
 
@@ -671,7 +670,7 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
 	if (irq < 0)
 		return irq;
 
-	ret = devm_request_threaded_irq(hdmi->dev, irq,
+	ret = devm_request_threaded_irq(dev, irq,
 					cfg->ctrl_ops->hardirq_callback,
 					cfg->ctrl_ops->irq_callback,
 					IRQF_SHARED, "dw-hdmi-qp-hpd",
@@ -682,18 +681,18 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
 	drm_encoder_helper_add(encoder, &dw_hdmi_qp_rockchip_encoder_helper_funcs);
 	ret = drmm_encoder_init(drm, encoder, NULL, DRM_MODE_ENCODER_TMDS, NULL);
 	if (ret)
-		return dev_err_probe(hdmi->dev, ret, "Failed to init encoder\n");
+		return dev_err_probe(dev, ret, "Failed to init encoder\n");
 
 	platform_set_drvdata(pdev, hdmi);
 
 	hdmi->hdmi = dw_hdmi_qp_bind(pdev, encoder, &plat_data);
 	if (IS_ERR(hdmi->hdmi))
-		return dev_err_probe(hdmi->dev, PTR_ERR(hdmi->hdmi),
+		return dev_err_probe(dev, PTR_ERR(hdmi->hdmi),
 				     "Failed to bind dw-hdmi-qp\n");
 
 	connector = drm_bridge_connector_init(drm, encoder);
 	if (IS_ERR(connector))
-		return dev_err_probe(hdmi->dev, PTR_ERR(connector),
+		return dev_err_probe(dev, PTR_ERR(connector),
 				     "Failed to init bridge connector\n");
 
 	return 0;
Signature · 1 line
2.54.0
#75 lore raw

Re: [PATCH v8 22/39] drm/rockchip: dw_hdmi_qp: Use local dev variable consistently in bind()

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Component bind/unbind lifetime mismatch leading to Use-After-Free and resource leaks. --

commit 53ed72bcdde7f86deb352e52bb664f24f880b84c
Author: Cristian Ciocaltea <[email protected]>

drm/rockchip: dw_hdmi_qp: Use local dev variable consistently in bind()

This patch updates dw_hdmi_qp_rockchip_bind() to use the local dev parameter instead of indirect struct device accesses. This improves consistency and readability throughout the function.

Quoted 4 lines
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +0 -0
index 7bd0f6dcbe5dc..d2fcfa70ed168 100644

[ ... ]

Quoted 10 lines
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +1 -1
@@ -671,7 +670,7 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
 	if (irq < 0)
 		return irq;
 
-	ret = devm_request_threaded_irq(hdmi->dev, irq,
+	ret = devm_request_threaded_irq(dev, irq,
 					cfg->ctrl_ops->hardirq_callback,
 					cfg->ctrl_ops->irq_callback,
 					IRQF_SHARED, "dw-hdmi-qp-hpd",

hdmi);

[Severity: High]
This is a pre-existing issue, but could this lifetime mismatch between the component device and the DRM master lead to a use-after-free?

The hdmi context is allocated earlier in dw_hdmi_qp_rockchip_bind() using drmm_kzalloc(), which ties its lifetime to the DRM master device:

    hdmi = drmm_kzalloc(drm, sizeof(*hdmi), GFP_KERNEL);

However, the HPD interrupt is requested using devm_request_threaded_irq() with the component device (dev).

If the master DRM device is unbound, the hdmi context will be freed automatically. Looking at dw_hdmi_qp_rockchip_unbind(), it only cancels the delayed work but lacks manual cleanup of the IRQ:

static void dw_hdmi_qp_rockchip_unbind(struct device *dev,
struct device *master, void *data)

{
	struct rockchip_hdmi_qp *hdmi = dev_get_drvdata(dev);

	cancel_delayed_work_sync(&hdmi->hpd_work);
}

If the HPD interrupt fires after the master DRM device is unbound but before the component device is unbound, the dangling interrupt handler will execute with a freed hdmi pointer. Is it possible to tie the IRQ lifetime to the DRM master or explicitly free it in the unbind path?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=22
#76 lore raw

PATCH v8 23/39 drm/rockchip: dw_hdmi_qp: Drop unnecessary #include

In reply to Cristian Ciocaltea

Remove superfluous drm_simple_kms_helper.h include, which has no users in this file since commit e1f7b7cbd74c ("drm/rockchip: dw_hdmi_qp:
Switch to drmm_encoder_init()").

---
 drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +0 -1
index d2fcfa70ed16..33036f194e34 100644
@@ -25,7 +25,6 @@
 #include <drm/drm_managed.h>
 #include <drm/drm_of.h>
 #include <drm/drm_probe_helper.h>
-#include <drm/drm_simple_kms_helper.h>
 
 #include "rockchip_drm_drv.h"
 
Signature · 1 line
2.54.0
#77 lore raw

PATCH v8 24/39 drm/rockchip: dw_hdmi_qp: Defer HPD IRQ enable until after connector setup

In reply to Cristian Ciocaltea

Request the HPD IRQ early in bind() with IRQF_NO_AUTOEN, keeping it disabled until all DRM resources are fully initialized, at which point enable_irq() arms it. This prevents premature interrupt delivery without forcing devm_request_threaded_irq() to the very end of the initialization sequence, which would complicate error unwinding.

Note that IRQF_NO_AUTOEN is incompatible with IRQF_SHARED; the latter is dropped as this IRQ has no other users.

---
 drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +3 -1
index 33036f194e34..3de4b3e6ea85 100644
@@ -672,7 +672,7 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
 	ret = devm_request_threaded_irq(dev, irq,
 					cfg->ctrl_ops->hardirq_callback,
 					cfg->ctrl_ops->irq_callback,
-					IRQF_SHARED, "dw-hdmi-qp-hpd",
+					IRQF_NO_AUTOEN, "dw-hdmi-qp-hpd",
 					hdmi);
 	if (ret)
 		return ret;
@@ -694,6 +694,8 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
 		return dev_err_probe(dev, PTR_ERR(connector),
 				     "Failed to init bridge connector\n");
 
+	enable_irq(irq);
+
 	return 0;
 }
 
Signature · 1 line
2.54.0
#78 lore raw

Re: [PATCH v8 24/39] drm/rockchip: dw_hdmi_qp: Defer HPD IRQ enable until after connector setup

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing disable_irq() or devm_free_irq() in component unbind() leaves the HPD IRQ enabled, causing a Use-After-Free of the hdmi struct if an interrupt fires after the DRM device is torn down. --

commit ed0ca175c20c7a0b231242e1a45aec15890b9c5d
Author: Cristian Ciocaltea <[email protected]>

drm/rockchip: dw_hdmi_qp: Defer HPD IRQ enable until after connector setup

This commit defers enabling the HPD IRQ until the end of the initialization sequence by using IRQF_NO_AUTOEN and calling enable_irq() later. It also removes the incompatible IRQF_SHARED flag.

Quoted 4 lines
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +0 -0
index 33036f194e348..3de4b3e6ea85e 100644

[ ... ]

drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master, · line 700

Quoted 8 lines
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +2 -0
@@ -694,6 +694,8 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,
 		return dev_err_probe(dev, PTR_ERR(connector),
 				     "Failed to init bridge connector\n");
 
+	enable_irq(irq);
+
 	return 0;
 }

[Severity: High]
This is a pre-existing issue, but does the hardware IRQ remain enabled after component unbind?

Since the IRQ is requested with devm_request_threaded_irq(), it won't be freed until driver detach. However, when the component is unbound (e.g., via sysfs), dw_hdmi_qp_rockchip_unbind() is called:

static void dw_hdmi_qp_rockchip_unbind(struct device *dev, ...)

{
        struct rockchip_hdmi_qp *hdmi = dev_get_drvdata(dev);

        cancel_delayed_work_sync(&hdmi->hpd_work);
}

This cancels the delayed work but does not disable the IRQ. After unbind, the DRM master completes teardown and frees the hdmi struct (which was allocated via drmm_kzalloc).

If a physical HDMI hotplug event occurs after unbind, could the hardirq handler dw_hdmi_qp_rk3588_hardirq() execute and dereference the freed hdmi->regmap, causing a use-after-free?

Should dw_hdmi_qp_rockchip_unbind() include a matching disable_irq() or devm_free_irq() to prevent the interrupt from firing after teardown?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
#79 lore raw

PATCH v8 25/39 drm/rockchip: dw_hdmi_qp: Mask RK3576 HPD IRQ in io_init

In reply to Cristian Ciocaltea

Start with HPD masked, matching RK3588, so the bridge framework controls when interrupts are armed via hpd_enable().

---
 drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +1 -1
index 3de4b3e6ea85..11ca73ca4caf 100644
@@ -427,7 +427,7 @@ static void dw_hdmi_qp_rk3576_io_init(struct rockchip_hdmi_qp *hdmi)
 
 	regmap_write(hdmi->vo_regmap, RK3576_VO0_GRF_SOC_CON14, val);
 
-	val = FIELD_PREP_WM16(RK3576_HDMI_HPD_INT_MSK, 0);
+	val = FIELD_PREP_WM16(RK3576_HDMI_HPD_INT_MSK, 1);
 	regmap_write(hdmi->regmap, RK3576_IOC_MISC_CON0, val);
 }
 
Signature · 1 line
2.54.0
#80 lore raw

PATCH v8 26/39 drm/rockchip: dw_hdmi_qp: Implement .{enable|disable}_hpd() PHY ops

In reply to Cristian Ciocaltea

Implement .enable_hpd() and .disable_hpd() phy ops for RK3576 and RK3588 SoCs, used by the corresponding bridge callbacks for HPD activation control.

Consolidate the interrupt clear-and-unmask sequence into enable_hpd() and the mask-only operation into disable_hpd(), replacing the open-coded register writes in the interrupt handlers and io_init().

The .setup_hpd() phy op, which was previously called from dw_hdmi_qp_init_hw(), is no longer needed and its users are removed.

---
 drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 78 +++++++++++++-------------
 1 file changed, 38 insertions(+), 40 deletions(-)
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +38 -40
index 11ca73ca4caf..c8675f43c687 100644
@@ -274,7 +274,7 @@ dw_hdmi_qp_rk3588_read_hpd(struct dw_hdmi_qp *dw_hdmi, void *data)
 	return val ? connector_status_connected : connector_status_disconnected;
 }
 
-static void dw_hdmi_qp_rk3588_setup_hpd(struct dw_hdmi_qp *dw_hdmi, void *data)
+static void dw_hdmi_qp_rk3588_enable_hpd(struct dw_hdmi_qp *dw_hdmi, void *data)
 {
 	struct rockchip_hdmi_qp *hdmi = (struct rockchip_hdmi_qp *)data;
 	u32 val;
@@ -289,11 +289,25 @@ static void dw_hdmi_qp_rk3588_setup_hpd(struct dw_hdmi_qp *dw_hdmi, void *data)
 	regmap_write(hdmi->regmap, RK3588_GRF_SOC_CON2, val);
 }
 
+static void dw_hdmi_qp_rk3588_disable_hpd(struct dw_hdmi_qp *dw_hdmi, void *data)
+{
+	struct rockchip_hdmi_qp *hdmi = (struct rockchip_hdmi_qp *)data;
+	u32 val;
+
+	if (hdmi->port_id)
+		val = FIELD_PREP_WM16(RK3588_HDMI1_HPD_INT_MSK, 1);
+	else
+		val = FIELD_PREP_WM16(RK3588_HDMI0_HPD_INT_MSK, 1);
+
+	regmap_write(hdmi->regmap, RK3588_GRF_SOC_CON2, val);
+}
+
 static const struct dw_hdmi_qp_phy_ops rk3588_hdmi_phy_ops = {
 	.init		= dw_hdmi_qp_rk3588_phy_init,
 	.disable	= dw_hdmi_qp_rk3588_phy_disable,
 	.read_hpd	= dw_hdmi_qp_rk3588_read_hpd,
-	.setup_hpd	= dw_hdmi_qp_rk3588_setup_hpd,
+	.enable_hpd	= dw_hdmi_qp_rk3588_enable_hpd,
+	.disable_hpd	= dw_hdmi_qp_rk3588_disable_hpd,
 };
 
 static enum drm_connector_status
@@ -308,7 +322,7 @@ dw_hdmi_qp_rk3576_read_hpd(struct dw_hdmi_qp *dw_hdmi, void *data)
 		connector_status_connected : connector_status_disconnected;
 }
 
-static void dw_hdmi_qp_rk3576_setup_hpd(struct dw_hdmi_qp *dw_hdmi, void *data)
+static void dw_hdmi_qp_rk3576_enable_hpd(struct dw_hdmi_qp *dw_hdmi, void *data)
 {
 	struct rockchip_hdmi_qp *hdmi = (struct rockchip_hdmi_qp *)data;
 	u32 val;
@@ -317,14 +331,22 @@ static void dw_hdmi_qp_rk3576_setup_hpd(struct dw_hdmi_qp *dw_hdmi, void *data)
 	       FIELD_PREP_WM16(RK3576_HDMI_HPD_INT_MSK, 0));
 
 	regmap_write(hdmi->regmap, RK3576_IOC_MISC_CON0, val);
-	regmap_write(hdmi->regmap, 0xa404, 0xffff0102);
+}
+
+static void dw_hdmi_qp_rk3576_disable_hpd(struct dw_hdmi_qp *dw_hdmi, void *data)
+{
+	struct rockchip_hdmi_qp *hdmi = (struct rockchip_hdmi_qp *)data;
+
+	regmap_write(hdmi->regmap, RK3576_IOC_MISC_CON0,
+		     FIELD_PREP_WM16(RK3576_HDMI_HPD_INT_MSK, 1));
 }
 
 static const struct dw_hdmi_qp_phy_ops rk3576_hdmi_phy_ops = {
 	.init		= dw_hdmi_qp_rk3588_phy_init,
 	.disable	= dw_hdmi_qp_rk3588_phy_disable,
 	.read_hpd	= dw_hdmi_qp_rk3576_read_hpd,
-	.setup_hpd	= dw_hdmi_qp_rk3576_setup_hpd,
+	.enable_hpd	= dw_hdmi_qp_rk3576_enable_hpd,
+	.disable_hpd	= dw_hdmi_qp_rk3576_disable_hpd,
 };
 
 static void dw_hdmi_qp_rk3588_hpd_work(struct work_struct *work)
@@ -345,13 +367,12 @@ static void dw_hdmi_qp_rk3588_hpd_work(struct work_struct *work)
 static irqreturn_t dw_hdmi_qp_rk3576_hardirq(int irq, void *dev_id)
 {
 	struct rockchip_hdmi_qp *hdmi = dev_id;
-	u32 intr_stat, val;
+	u32 intr_stat;
 
 	regmap_read(hdmi->regmap, RK3576_IOC_HDMI_HPD_STATUS, &intr_stat);
-	if (intr_stat) {
-		val = FIELD_PREP_WM16(RK3576_HDMI_HPD_INT_MSK, 1);
 
-		regmap_write(hdmi->regmap, RK3576_IOC_MISC_CON0, val);
+	if (intr_stat) {
+		dw_hdmi_qp_rk3576_disable_hpd(NULL, hdmi);
 		return IRQ_WAKE_THREAD;
 	}
 
@@ -361,15 +382,11 @@ static irqreturn_t dw_hdmi_qp_rk3576_hardirq(int irq, void *dev_id)
 static irqreturn_t dw_hdmi_qp_rk3576_irq(int irq, void *dev_id)
 {
 	struct rockchip_hdmi_qp *hdmi = dev_id;
-	u32 val;
 
-	val = FIELD_PREP_WM16(RK3576_HDMI_HPD_INT_CLR, 1);
-	regmap_write(hdmi->regmap, RK3576_IOC_MISC_CON0, val);
 	mod_delayed_work(system_percpu_wq, &hdmi->hpd_work,
 			 msecs_to_jiffies(HOTPLUG_DEBOUNCE_MS));
 
-	val = FIELD_PREP_WM16(RK3576_HDMI_HPD_INT_MSK, 0);
-	regmap_write(hdmi->regmap, RK3576_IOC_MISC_CON0, val);
+	dw_hdmi_qp_rk3576_enable_hpd(NULL, hdmi);
 
 	return IRQ_HANDLED;
 }
@@ -377,16 +394,12 @@ static irqreturn_t dw_hdmi_qp_rk3576_irq(int irq, void *dev_id)
 static irqreturn_t dw_hdmi_qp_rk3588_hardirq(int irq, void *dev_id)
 {
 	struct rockchip_hdmi_qp *hdmi = dev_id;
-	u32 intr_stat, val;
+	u32 intr_stat;
 
 	regmap_read(hdmi->regmap, RK3588_GRF_SOC_STATUS1, &intr_stat);
 
 	if (intr_stat) {
-		if (hdmi->port_id)
-			val = FIELD_PREP_WM16(RK3588_HDMI1_HPD_INT_MSK, 1);
-		else
-			val = FIELD_PREP_WM16(RK3588_HDMI0_HPD_INT_MSK, 1);
-		regmap_write(hdmi->regmap, RK3588_GRF_SOC_CON2, val);
+		dw_hdmi_qp_rk3588_disable_hpd(NULL, hdmi);
 		return IRQ_WAKE_THREAD;
 	}
 
@@ -396,22 +409,11 @@ static irqreturn_t dw_hdmi_qp_rk3588_hardirq(int irq, void *dev_id)
 static irqreturn_t dw_hdmi_qp_rk3588_irq(int irq, void *dev_id)
 {
 	struct rockchip_hdmi_qp *hdmi = dev_id;
-	u32 val;
-
-	if (hdmi->port_id)
-		val = FIELD_PREP_WM16(RK3588_HDMI1_HPD_INT_CLR, 1);
-	else
-		val = FIELD_PREP_WM16(RK3588_HDMI0_HPD_INT_CLR, 1);
-	regmap_write(hdmi->regmap, RK3588_GRF_SOC_CON2, val);
 
 	mod_delayed_work(system_percpu_wq, &hdmi->hpd_work,
 			 msecs_to_jiffies(HOTPLUG_DEBOUNCE_MS));
 
-	if (hdmi->port_id)
-		val |= FIELD_PREP_WM16(RK3588_HDMI1_HPD_INT_MSK, 0);
-	else
-		val |= FIELD_PREP_WM16(RK3588_HDMI0_HPD_INT_MSK, 0);
-	regmap_write(hdmi->regmap, RK3588_GRF_SOC_CON2, val);
+	dw_hdmi_qp_rk3588_enable_hpd(NULL, hdmi);
 
 	return IRQ_HANDLED;
 }
@@ -424,11 +426,11 @@ static void dw_hdmi_qp_rk3576_io_init(struct rockchip_hdmi_qp *hdmi)
 	      FIELD_PREP_WM16(RK3576_SDAIN_MASK, 1) |
 	      FIELD_PREP_WM16(RK3576_HDMI_GRANT_SEL, 1) |
 	      FIELD_PREP_WM16(RK3576_I2S_SEL_MASK, 1);
-
 	regmap_write(hdmi->vo_regmap, RK3576_VO0_GRF_SOC_CON14, val);
 
-	val = FIELD_PREP_WM16(RK3576_HDMI_HPD_INT_MSK, 1);
-	regmap_write(hdmi->regmap, RK3576_IOC_MISC_CON0, val);
+	regmap_write(hdmi->regmap, 0xa404, 0xffff0102);
+
+	dw_hdmi_qp_rk3576_disable_hpd(NULL, hdmi);
 }
 
 static void dw_hdmi_qp_rk3588_io_init(struct rockchip_hdmi_qp *hdmi)
@@ -453,11 +455,7 @@ static void dw_hdmi_qp_rk3588_io_init(struct rockchip_hdmi_qp *hdmi)
 		val = FIELD_PREP_WM16(RK3588_HDMI0_GRANT_SEL, 1);
 	regmap_write(hdmi->vo_regmap, RK3588_GRF_VO1_CON9, val);
 
-	if (hdmi->port_id)
-		val = FIELD_PREP_WM16(RK3588_HDMI1_HPD_INT_MSK, 1);
-	else
-		val = FIELD_PREP_WM16(RK3588_HDMI0_HPD_INT_MSK, 1);
-	regmap_write(hdmi->regmap, RK3588_GRF_SOC_CON2, val);
+	dw_hdmi_qp_rk3588_disable_hpd(NULL, hdmi);
 }
 
 static void dw_hdmi_qp_rk3576_enc_init(struct rockchip_hdmi_qp *hdmi,
Signature · 1 line
2.54.0
#81 lore raw

Re: [PATCH v8 26/39] drm/rockchip: dw_hdmi_qp: Implement .{enable|disable}_hpd() PHY ops

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Medium] Threaded IRQ handler unconditionally re-enables the HPD interrupt, racing with DRM core state.

Pre-existing issues:
- [High] Hardirq handlers check an unmasked global status register, causing spurious wakeups and potentially missing unplug events.
- [High] Missing IRQ disable before cancel_delayed_work_sync() in unbind causes a use-after-free.
--

Note: Due to system recitation constraints, I cannot include the quoted diff hunks in this review. The feedback below uses a free-form summary of the locations instead of inline diff comments.

commit d6251e05f12f1c50b3e31b91e1dfea22e19df9e0
Author: Cristian Ciocaltea <[email protected]>
Subject: drm/rockchip: dw_hdmi_qp: Implement .{enable|disable}_hpd() PHY ops

This commit implements the enable_hpd() and disable_hpd() phy operations for the RK3576 and RK3588 SoCs. It also consolidates the interrupt clear-and-unmask sequences to replace open-coded register writes.

[Severity: Medium]
In drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c, specifically within the threaded IRQ handlers dw_hdmi_qp_rk3588_irq() (around line 409) and dw_hdmi_qp_rk3576_irq() (around line 382), does the unconditional call to enable_hpd() race with the DRM core?

With the introduction of the .enable_hpd and .disable_hpd PHY operations, the DRM core expects to dynamically control HPD activation (for instance, masking it during suspend). If an HPD event triggers just before the core disables HPD, the hardirq handler schedules the threaded handler. Since the threaded handler finishes by unconditionally unmasking the interrupt via enable_hpd(), won't this override the DRM core's explicit request to keep the interrupt disabled? This seems like it could leave the interrupt armed unexpectedly and potentially cause spurious wakeups.

[Severity: High]
This isn't a bug introduced by this patch, but there appears to be an issue in the hardirq handlers dw_hdmi_qp_rk3588_hardirq() (around line 394) and dw_hdmi_qp_rk3576_hardirq() (around line 367).

These functions read the shared status registers (RK3588_GRF_SOC_STATUS1 or RK3576_IOC_HDMI_HPD_STATUS) and check if the value is non-zero without applying a port-specific mask. Because no mask is applied, could any set bit in these shared registers trigger a spurious thread wakeup?

Additionally, if these registers reflect the physical level (as used in read_hpd), an unplug event would result in a level of 0. If no other bits are set, the handler evaluates "if (intr_stat)" as false and returns IRQ_NONE. Does this mean the driver will fail to wake the thread and completely miss the disconnect event?

[Severity: High]
This is a pre-existing issue, but I noticed a potential use-after-free in the unbind path involving dw_hdmi_qp_rockchip_unbind() and the IRQ handlers.

In the unbind path, cancel_delayed_work_sync() is called to stop the HPD debounce work, but the hardware interrupt isn't explicitly disabled first. If an HPD interrupt fires during or just after the cancellation, the hardirq will wake the threaded handler (e.g., dw_hdmi_qp_rk3588_irq() at line 409), which then calls mod_delayed_work() to re-arm the timer.

When the module unloads or the workqueue is destroyed, won't this pending timer fire and execute unmapped memory, resulting in a kernel panic? Should the IRQ be explicitly disabled before cancelling the delayed work?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
#82 lore raw

PATCH v8 27/39 drm/rockchip: dw_hdmi_qp: Use dw_hdmi_qp_hpd_notify() for HPD reports

In reply to Cristian Ciocaltea

Notify only the affected connector instead of polling all of them, and ensure .detect_ctx() runs on reconnect to recover SCDC state.

---
 drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +2 -10
index c8675f43c687..9bced588c86c 100644
@@ -24,7 +24,6 @@
 #include <drm/drm_bridge_connector.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_of.h>
-#include <drm/drm_probe_helper.h>
 
 #include "rockchip_drm_drv.h"
 
@@ -354,14 +353,8 @@ static void dw_hdmi_qp_rk3588_hpd_work(struct work_struct *work)
 	struct rockchip_hdmi_qp *hdmi = container_of(work,
 						     struct rockchip_hdmi_qp,
 						     hpd_work.work);
-	struct drm_device *drm = hdmi->encoder.encoder.dev;
-	bool changed;
 
-	if (drm) {
-		changed = drm_helper_hpd_irq_event(drm);
-		if (changed)
-			dev_dbg(hdmi->dev, "connector status changed\n");
-	}
+	dw_hdmi_qp_hpd_notify(hdmi->hdmi);
 }
 
 static irqreturn_t dw_hdmi_qp_rk3576_hardirq(int irq, void *dev_id)
@@ -738,8 +731,7 @@ static int __maybe_unused dw_hdmi_qp_rockchip_resume(struct device *dev)
 
 	dw_hdmi_qp_resume(dev, hdmi->hdmi);
 
-	if (hdmi->encoder.encoder.dev)
-		drm_helper_hpd_irq_event(hdmi->encoder.encoder.dev);
+	dw_hdmi_qp_hpd_notify(hdmi->hdmi);
 
 	return 0;
 }
Signature · 1 line
2.54.0
#83 lore raw

Re: [PATCH v8 27/39] drm/rockchip: dw_hdmi_qp: Use dw_hdmi_qp_hpd_notify() for HPD reports

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

New issues:
- [High] Unprotected access to hdmi->curr_conn in dw_hdmi_qp_hpd_notify() can lead to a TOCTOU NULL pointer dereference.

Pre-existing issues:
- [High] System PM suspend/resume callbacks unconditionally dereference dev_get_drvdata(), which can be NULL if component bind hasn't completed.
- [High] Missing disable_irq() in unbind allows the hotplug interrupt to fire after the DRM master is unbound, leading to a Use-After-Free.
- [High] Using devm_* functions in component bind() ties resources to the platform device's lifetime rather than the component's lifetime, causing resource leaks and permanent bind failures on retries. --

commit 71c4a3386d116454bc66b990f1d692e5daa00ba8
Author: Cristian Ciocaltea <[email protected]>
Subject: drm/rockchip: dw_hdmi_qp: Use dw_hdmi_qp_hpd_notify() for HPD reports

This commit updates the HPD reporting to notify only the affected connector instead of polling all of them. It also ensures the detection context runs on reconnect to properly recover the SCDC state.

Quoted 3 lines
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +0 -0

[ ... ]

Quoted 4 lines
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +0 -0
@@ -354,14 +353,8 @@ static void dw_hdmi_qp_rk3588_hpd_work(struct work_struct *work)
 	struct rockchip_hdmi_qp *hdmi = container_of(work,
 						     struct rockchip_hdmi_qp,
 						     hpd_work.work);

drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c static void dw_hdmi_qp_rk3588_hpd_work(struct work_struct *work) · line 358

Quoted 10 lines
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +1 -7
-	struct drm_device *drm = hdmi->encoder.encoder.dev;
-	bool changed;
 
-	if (drm) {
-		changed = drm_helper_hpd_irq_event(drm);
-		if (changed)
-			dev_dbg(hdmi->dev, "connector status changed\n");
-	}
+	dw_hdmi_qp_hpd_notify(hdmi->hdmi);
 }

[Severity: High]
Could this call introduce a time-of-check to time-of-use race condition?

In dw_hdmi_qp_hpd_notify(), we evaluate hdmi->curr_conn without locks:

	if (hdmi->curr_conn && status == connector_status_connected)
		drm_connector_helper_hpd_irq_event(hdmi->curr_conn);

If a concurrent atomic modeset (triggered by userspace or hotplug) invokes atomic_post_disable() between the condition evaluation and the dereference in drm_connector_helper_hpd_irq_event(), hdmi->curr_conn could be set to NULL.

A compiler might emit two separate memory reads here, which could lead to passing a NULL pointer to the helper and causing a kernel crash.

Would it be better to use a local variable with READ_ONCE() to ensure the pointer remains valid across the check and the call?

[ ... ]

drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c static int __maybe_unused dw_hdmi_qp_rockchip_resume(struct device *dev) · line 737

Quoted 10 lines
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +1 -2
@@ -738,8 +731,7 @@ static int __maybe_unused dw_hdmi_qp_rockchip_resume(struct device *dev)
 
 	dw_hdmi_qp_resume(dev, hdmi->hdmi);
 
-	if (hdmi->encoder.encoder.dev)
-		drm_helper_hpd_irq_event(hdmi->encoder.encoder.dev);
+	dw_hdmi_qp_hpd_notify(hdmi->hdmi);
 
 	return 0;
 }

[Severity: High]
This is a pre-existing issue, but does this function safely handle a NULL hdmi pointer?

The resume callback fetches the hdmi struct via dev_get_drvdata(dev).

However, if the system suspends before the component framework calls the bind callback (for instance, during a deferred probe waiting for the VOP), dev_get_drvdata() will return NULL.

Since dw_hdmi_qp_rockchip_resume() unconditionally accesses hdmi->ctrl_ops and hdmi->hdmi, wouldn't this cause a kernel panic on system resume?

[Severity: High]
This isn't a bug introduced by this patch, but is it possible for the HPD interrupt to fire after the DRM master is unbound?

In dw_hdmi_qp_rockchip_unbind(), cancel_delayed_work_sync() is called, but the IRQ itself is never disabled.

Because the IRQ was requested using devm_request_threaded_irq() on the platform device, it remains active until the platform device itself is removed.

If an HPD event occurs after the component unbinds (which frees the drmm_kzalloc'd hdmi struct), the IRQ handler will schedule the HPD work which accesses freed memory, leading to a use-after-free crash.

Should disable_irq() be called during unbind to prevent this?

[Severity: High]
This is a pre-existing issue, but are we at risk of leaking resources and permanently failing initialization on bind retries?

In dw_hdmi_qp_rockchip_bind(), several devm_ functions like devm_request_threaded_irq() and devm_clk_get() are used on the platform device.

Because the component framework allows bind() to fail and be retried, any failure mid-way through bind() means these resources are not freed, as the platform device remains active.

On subsequent retries, devm_request_threaded_irq() will return -EBUSY, permanently breaking the HDMI port initialization until the platform module is unloaded.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=27
#84 lore raw

PATCH v8 28/39 drm/bridge: dw-hdmi-qp: Drop unused .setup_hpd() phy op

In reply to Cristian Ciocaltea

With the transition to .{enable|disable}_hpd() phy ops complete in both the bridge and platform drivers, .setup_hpd() has no remaining callers. Drop it.

---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c | 3 ---
 include/drm/bridge/dw_hdmi_qp.h              | 1 -
 2 files changed, 4 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-hdmi-qp.c +0 -3
index 4d41ad7319a5..8ce005673517 100644
@@ -1314,9 +1314,6 @@ static void dw_hdmi_qp_init_hw(struct dw_hdmi_qp *hdmi)
 	/* Clear DONE and ERROR interrupts */
 	dw_hdmi_qp_write(hdmi, I2CM_OP_DONE_CLEAR | I2CM_NACK_RCVD_CLEAR,
 			 MAINUNIT_1_INT_CLEAR);
-
-	if (hdmi->phy.ops->setup_hpd)
-		hdmi->phy.ops->setup_hpd(hdmi, hdmi->phy.data);
 }
 
 struct dw_hdmi_qp *dw_hdmi_qp_bind(struct platform_device *pdev,
include/drm/bridge/dw_hdmi_qp.h +0 -1
index b4fb1c578a5b..ad33f9cafdeb 100644
@@ -16,7 +16,6 @@ struct dw_hdmi_qp_phy_ops {
 	int (*init)(struct dw_hdmi_qp *hdmi, void *data);
 	void (*disable)(struct dw_hdmi_qp *hdmi, void *data);
 	enum drm_connector_status (*read_hpd)(struct dw_hdmi_qp *hdmi, void *data);
-	void (*setup_hpd)(struct dw_hdmi_qp *hdmi, void *data);
 	void (*enable_hpd)(struct dw_hdmi_qp *hdmi, void *data);
 	void (*disable_hpd)(struct dw_hdmi_qp *hdmi, void *data);
 };
Signature · 1 line
2.54.0
#85 lore raw

PATCH v8 29/39 drm/vc4: hdmi: Use common TMDS char rate constants

In reply to Cristian Ciocaltea

Replace HDMI_14_MAX_TMDS_CLK defined locally with HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ provided by linux/hdmi.h. Note this incorrectly referenced HDMI 1.4, as the 340 MHz maximum TMDS character rate was actually introduced in HDMI 1.3.

Similarly, use HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ instead of the 600000000 magic number.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +8 -9
index e165f604939b..fbdb0448aa2b 100644
@@ -45,6 +45,7 @@
 #include <linux/clk.h>
 #include <linux/component.h>
 #include <linux/gpio/consumer.h>
+#include <linux/hdmi.h>
 #include <linux/i2c.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
@@ -113,8 +114,6 @@
 #define HSM_MIN_CLOCK_FREQ	120000000
 #define CEC_CLOCK_FREQ 40000
 
-#define HDMI_14_MAX_TMDS_CLK   (340 * 1000 * 1000)
-
 static bool vc4_hdmi_supports_scrambling(struct vc4_hdmi *vc4_hdmi)
 {
 	struct drm_display_info *display = &vc4_hdmi->connector.display_info;
@@ -137,7 +136,7 @@ static bool vc4_hdmi_mode_needs_scrambling(const struct drm_display_mode *mode,
 {
 	unsigned long long clock = drm_hdmi_compute_mode_clock(mode, bpc, fmt);
 
-	return clock > HDMI_14_MAX_TMDS_CLK;
+	return clock > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
 }
 
 static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
@@ -1727,7 +1726,7 @@ vc4_hdmi_connector_clock_valid(const struct drm_connector *connector,
 	if (clock > vc4_hdmi->variant->max_pixel_clock)
 		return MODE_CLOCK_HIGH;
 
-	if (!vc4->hvs->vc5_hdmi_enable_hdmi_20 && clock > HDMI_14_MAX_TMDS_CLK)
+	if (!vc4->hvs->vc5_hdmi_enable_hdmi_20 && clock > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ)
 		return MODE_CLOCK_HIGH;
 
 	/* 4096x2160@60 is not reliable without overclocking core */
@@ -3253,7 +3252,7 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 	 * vc4_hdmi_disable_scrambling() will thus run at boot, make
 	 * sure it's disabled, and avoid any inconsistency.
 	 */
-	if (variant->max_pixel_clock > HDMI_14_MAX_TMDS_CLK)
+	if (variant->max_pixel_clock > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ)
 		vc4_hdmi->scdc_enabled = true;
 
 	ret = variant->init_resources(drm, vc4_hdmi);
@@ -3383,7 +3382,7 @@ static const struct vc4_hdmi_variant bcm2711_hdmi0_variant = {
 	.encoder_type		= VC4_ENCODER_TYPE_HDMI0,
 	.debugfs_name		= "hdmi0_regs",
 	.card_name		= "vc4-hdmi-0",
-	.max_pixel_clock	= 600000000,
+	.max_pixel_clock	= HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ,
 	.registers		= vc5_hdmi_hdmi0_fields,
 	.num_registers		= ARRAY_SIZE(vc5_hdmi_hdmi0_fields),
 	.phy_lane_mapping	= {
@@ -3412,7 +3411,7 @@ static const struct vc4_hdmi_variant bcm2711_hdmi1_variant = {
 	.encoder_type		= VC4_ENCODER_TYPE_HDMI1,
 	.debugfs_name		= "hdmi1_regs",
 	.card_name		= "vc4-hdmi-1",
-	.max_pixel_clock	= HDMI_14_MAX_TMDS_CLK,
+	.max_pixel_clock	= HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ,
 	.registers		= vc5_hdmi_hdmi1_fields,
 	.num_registers		= ARRAY_SIZE(vc5_hdmi_hdmi1_fields),
 	.phy_lane_mapping	= {
@@ -3441,7 +3440,7 @@ static const struct vc4_hdmi_variant bcm2712_hdmi0_variant = {
 	.encoder_type		= VC4_ENCODER_TYPE_HDMI0,
 	.debugfs_name		= "hdmi0_regs",
 	.card_name		= "vc4-hdmi-0",
-	.max_pixel_clock	= 600000000,
+	.max_pixel_clock	= HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ,
 	.registers		= vc6_hdmi_hdmi0_fields,
 	.num_registers		= ARRAY_SIZE(vc6_hdmi_hdmi0_fields),
 	.phy_lane_mapping	= {
@@ -3468,7 +3467,7 @@ static const struct vc4_hdmi_variant bcm2712_hdmi1_variant = {
 	.encoder_type		= VC4_ENCODER_TYPE_HDMI1,
 	.debugfs_name		= "hdmi1_regs",
 	.card_name		= "vc4-hdmi-1",
-	.max_pixel_clock	= 600000000,
+	.max_pixel_clock	= HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ,
 	.registers		= vc6_hdmi_hdmi1_fields,
 	.num_registers		= ARRAY_SIZE(vc6_hdmi_hdmi1_fields),
 	.phy_lane_mapping	= {
Signature · 1 line
2.54.0
#86 lore raw

PATCH v8 30/39 drm/vc4: hdmi: Switch to drm_hdmi_mode_needs_scrambling()

In reply to Cristian Ciocaltea

The VC4 HDMI driver has a local helper to check whether a mode requires scrambling. It is equivalent to drm_hdmi_mode_needs_scrambling(), so use the common helper instead.

No functional change intended.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +4 -12
index fbdb0448aa2b..e7b0f0f2e350 100644
@@ -130,15 +130,6 @@ static bool vc4_hdmi_supports_scrambling(struct vc4_hdmi *vc4_hdmi)
 	return true;
 }
 
-static bool vc4_hdmi_mode_needs_scrambling(const struct drm_display_mode *mode,
-					   unsigned int bpc,
-					   enum drm_output_color_format fmt)
-{
-	unsigned long long clock = drm_hdmi_compute_mode_clock(mode, bpc, fmt);
-
-	return clock > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ;
-}
-
 static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
 {
 	struct drm_debugfs_entry *entry = m->private;
@@ -313,7 +304,7 @@ static int vc4_hdmi_reset_link(struct drm_connector *connector,
 		return 0;
 	}
 
-	scrambling_needed = vc4_hdmi_mode_needs_scrambling(&vc4_hdmi->saved_adjusted_mode,
+	scrambling_needed = drm_hdmi_mode_needs_scrambling(&vc4_hdmi->saved_adjusted_mode,
 							   vc4_hdmi->output_bpc,
 							   vc4_hdmi->output_format);
 	if (!scrambling_needed) {
@@ -443,7 +434,8 @@ static int vc4_hdmi_connector_get_modes(struct drm_connector *connector)
 		const struct drm_display_mode *mode;
 
 		list_for_each_entry(mode, &connector->probed_modes, head) {
-			if (vc4_hdmi_mode_needs_scrambling(mode, 8, DRM_OUTPUT_COLOR_FORMAT_RGB444)) {
+			if (drm_hdmi_mode_needs_scrambling(mode, 8,
+							   DRM_OUTPUT_COLOR_FORMAT_RGB444)) {
 				drm_warn_once(drm, "The core clock cannot reach frequencies high enough to support 4k @ 60Hz.");
 				drm_warn_once(drm, "Please change your config.txt file to add hdmi_enable_4kp60.");
 			}
@@ -802,7 +794,7 @@ static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder)
 	if (!vc4_hdmi_supports_scrambling(vc4_hdmi))
 		return;
 
-	if (!vc4_hdmi_mode_needs_scrambling(mode,
+	if (!drm_hdmi_mode_needs_scrambling(mode,
 					    vc4_hdmi->output_bpc,
 					    vc4_hdmi->output_format))
 		return;
Signature · 1 line
2.54.0
maintainer Acked-by on v8 30/39
#87 lore raw

Re: [PATCH v8 30/39] drm/vc4: hdmi: Switch to drm_hdmi_mode_needs_scrambling()

Quoted 7 lines · Cristian Ciocaltea

The VC4 HDMI driver has a local helper to check whether a mode requires scrambling. It is equivalent to drm_hdmi_mode_needs_scrambling(), so use the common helper instead.

No functional change intended.

[ ... ]

Thanks!
Maxime

#88 lore raw

PATCH v8 31/39 drm/vc4: hdmi: Convert to common SCDC scrambling infrastructure

In reply to Cristian Ciocaltea

Replace driver local scrambling logic with the newly introduced common HDMI 2.0 scrambling support:

- Advertise source-side scrambling capability by setting supported HDMI version based on the variant's max_pixel_clock.

- Provide minimal .scrambler_{enable|disable} connector callbacks that only toggle the VC5 HDMI_SCRAMBLER_CTL register, while delegating sink-side SCDC programming and periodic status monitoring to drm_connector_hdmi_{enable|disable}_scrambling().

- Drop vc4_hdmi_reset_link() and vc4_hdmi_handle_hotplug(), switching the .detect_ctx() path to drm_atomic_helper_connector_hdmi_hotplug() which internally calls drm_connector_hdmi_sync_scdc() to trigger a CRTC reset on reconnection.

- Drop the local scrambling_work delayed workqueue and scdc_enabled flag, now tracked by the common drm_connector_hdmi layer, as well as the now unused output_{bpc|color_format} driver data members.

No functional change intended.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 276 ++++++++---------------------------------
 drivers/gpu/drm/vc4/vc4_hdmi.h |  21 ----
 2 files changed, 49 insertions(+), 248 deletions(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +49 -227
index e7b0f0f2e350..81e0214f7e95 100644
@@ -35,7 +35,6 @@
 #include <drm/display/drm_hdmi_cec_helper.h>
 #include <drm/display/drm_hdmi_helper.h>
 #include <drm/display/drm_hdmi_state_helper.h>
-#include <drm/display/drm_scdc_helper.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_edid.h>
@@ -114,22 +113,6 @@
 #define HSM_MIN_CLOCK_FREQ	120000000
 #define CEC_CLOCK_FREQ 40000
 
-static bool vc4_hdmi_supports_scrambling(struct vc4_hdmi *vc4_hdmi)
-{
-	struct drm_display_info *display = &vc4_hdmi->connector.display_info;
-
-	lockdep_assert_held(&vc4_hdmi->mutex);
-
-	if (!display->is_hdmi)
-		return false;
-
-	if (!display->hdmi.scdc.supported ||
-	    !display->hdmi.scdc.scrambling.supported)
-		return false;
-
-	return true;
-}
-
 static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
 {
 	struct drm_debugfs_entry *entry = m->private;
@@ -263,124 +246,6 @@ static void vc4_hdmi_cec_update_clk_div(struct vc4_hdmi *vc4_hdmi)
 static void vc4_hdmi_cec_update_clk_div(struct vc4_hdmi *vc4_hdmi) {}
 #endif
 
-static int vc4_hdmi_reset_link(struct drm_connector *connector,
-			       struct drm_modeset_acquire_ctx *ctx)
-{
-	struct drm_device *drm;
-	struct vc4_hdmi *vc4_hdmi;
-	struct drm_connector_state *conn_state;
-	struct drm_crtc_state *crtc_state;
-	struct drm_crtc *crtc;
-	bool scrambling_needed;
-	u8 config;
-	int ret;
-
-	if (!connector)
-		return 0;
-
-	drm = connector->dev;
-	ret = drm_modeset_lock(&drm->mode_config.connection_mutex, ctx);
-	if (ret)
-		return ret;
-
-	conn_state = connector->state;
-	crtc = conn_state->crtc;
-	if (!crtc)
-		return 0;
-
-	ret = drm_modeset_lock(&crtc->mutex, ctx);
-	if (ret)
-		return ret;
-
-	crtc_state = crtc->state;
-	if (!crtc_state->active)
-		return 0;
-
-	vc4_hdmi = connector_to_vc4_hdmi(connector);
-	mutex_lock(&vc4_hdmi->mutex);
-
-	if (!vc4_hdmi_supports_scrambling(vc4_hdmi)) {
-		mutex_unlock(&vc4_hdmi->mutex);
-		return 0;
-	}
-
-	scrambling_needed = drm_hdmi_mode_needs_scrambling(&vc4_hdmi->saved_adjusted_mode,
-							   vc4_hdmi->output_bpc,
-							   vc4_hdmi->output_format);
-	if (!scrambling_needed) {
-		mutex_unlock(&vc4_hdmi->mutex);
-		return 0;
-	}
-
-	if (conn_state->commit &&
-	    !try_wait_for_completion(&conn_state->commit->hw_done)) {
-		mutex_unlock(&vc4_hdmi->mutex);
-		return 0;
-	}
-
-	ret = drm_scdc_readb(connector->ddc, SCDC_TMDS_CONFIG, &config);
-	if (ret < 0) {
-		drm_err(drm, "Failed to read TMDS config: %d\n", ret);
-		mutex_unlock(&vc4_hdmi->mutex);
-		return 0;
-	}
-
-	if (!!(config & SCDC_SCRAMBLING_ENABLE) == scrambling_needed) {
-		mutex_unlock(&vc4_hdmi->mutex);
-		return 0;
-	}
-
-	mutex_unlock(&vc4_hdmi->mutex);
-
-	/*
-	 * HDMI 2.0 says that one should not send scrambled data
-	 * prior to configuring the sink scrambling, and that
-	 * TMDS clock/data transmission should be suspended when
-	 * changing the TMDS clock rate in the sink. So let's
-	 * just do a full modeset here, even though some sinks
-	 * would be perfectly happy if were to just reconfigure
-	 * the SCDC settings on the fly.
-	 */
-	return drm_atomic_helper_reset_crtc(crtc, ctx);
-}
-
-static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi,
-				    struct drm_modeset_acquire_ctx *ctx,
-				    enum drm_connector_status status)
-{
-	struct drm_connector *connector = &vc4_hdmi->connector;
-	int ret;
-
-	/*
-	 * NOTE: This function should really be called with vc4_hdmi->mutex
-	 * held, but doing so results in reentrancy issues since
-	 * cec_s_phys_addr() might call .adap_enable, which leads to that
-	 * funtion being called with our mutex held.
-	 *
-	 * A similar situation occurs with vc4_hdmi_reset_link() that
-	 * will call into our KMS hooks if the scrambling was enabled.
-	 *
-	 * Concurrency isn't an issue at the moment since we don't share
-	 * any state with any of the other frameworks so we can ignore
-	 * the lock for now.
-	 */
-
-	drm_atomic_helper_connector_hdmi_hotplug(connector, status, NULL);
-
-	if (status != connector_status_connected)
-		return;
-
-	for (;;) {
-		ret = vc4_hdmi_reset_link(connector, ctx);
-		if (ret == -EDEADLK) {
-			drm_modeset_backoff(ctx);
-			continue;
-		}
-
-		break;
-	}
-}
-
 static int vc4_hdmi_connector_detect_ctx(struct drm_connector *connector,
 					 struct drm_modeset_acquire_ctx *ctx,
 					 bool force)
@@ -392,8 +257,8 @@ static int vc4_hdmi_connector_detect_ctx(struct drm_connector *connector,
 	/*
 	 * NOTE: This function should really take vc4_hdmi->mutex, but
 	 * doing so results in reentrancy issues since
-	 * vc4_hdmi_handle_hotplug() can call into other functions that
-	 * would take the mutex while it's held here.
+	 * drm_atomic_helper_connector_hdmi_hotplug() can call into other
+	 * functions that would take the mutex while it's held here.
 	 *
 	 * Concurrency isn't an issue at the moment since we don't share
 	 * any state with any of the other frameworks so we can ignore
@@ -416,10 +281,11 @@ static int vc4_hdmi_connector_detect_ctx(struct drm_connector *connector,
 			status = connector_status_connected;
 	}
 
-	vc4_hdmi_handle_hotplug(vc4_hdmi, ctx, status);
+	ret = drm_atomic_helper_connector_hdmi_hotplug(connector, status, ctx);
+
 	pm_runtime_put(&vc4_hdmi->pdev->dev);
 
-	return status;
+	return ret == -EDEADLK ? ret : status;
 }
 
 static int vc4_hdmi_connector_get_modes(struct drm_connector *connector)
@@ -526,22 +392,28 @@ static int vc4_hdmi_connector_init(struct drm_device *dev,
 {
 	struct drm_connector *connector = &vc4_hdmi->connector;
 	struct drm_encoder *encoder = &vc4_hdmi->encoder.base;
-	unsigned int max_bpc = 8;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444) |
+				     BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR422) |
+				     BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR444),
+		.max_bpc = 8,
+	};
 	int ret;
 
 	if (vc4_hdmi->variant->supports_hdr)
-		max_bpc = 12;
+		caps.max_bpc = 12;
 
-	ret = drmm_connector_hdmi_init(dev, connector,
-				       "Broadcom", "Videocore",
-				       &vc4_hdmi_connector_funcs,
-				       &vc4_hdmi_hdmi_connector_funcs,
-				       DRM_MODE_CONNECTOR_HDMIA,
-				       vc4_hdmi->ddc,
-				       BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444) |
-				       BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR422) |
-				       BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR444),
-				       max_bpc);
+	if (vc4_hdmi->variant->max_pixel_clock > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ)
+		caps.supported_hdmi_ver = HDMI_VERSION_2_0;
+	else if (vc4_hdmi->variant->max_pixel_clock > HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ)
+		caps.supported_hdmi_ver = HDMI_VERSION_1_3;
+
+	ret = drmm_connector_hdmi_init_with_caps(dev, connector,
+						 "Broadcom", "Videocore",
+						 &vc4_hdmi_connector_funcs,
+						 &vc4_hdmi_hdmi_connector_funcs,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 vc4_hdmi->ddc, &caps);
 	if (ret)
 		return ret;
 
@@ -553,6 +425,14 @@ static int vc4_hdmi_connector_init(struct drm_device *dev,
 
 	drm_connector_helper_add(connector, &vc4_hdmi_connector_helper_funcs);
 
+	/*
+	 * Since we don't know the state of the controller and its
+	 * display (if any), let's assume it's always enabled.
+	 * drm_connector_hdmi_disable_scrambling() will thus run at boot,
+	 * make sure it's disabled, and avoid any inconsistency.
+	 */
+	connector->hdmi.scrambler_enabled = connector->hdmi.scrambler_supported;
+
 	/*
 	 * Some of the properties below require access to state, like bpc.
 	 * Allocate some default initial connector state with our reset helper.
@@ -778,32 +658,14 @@ static int vc4_hdmi_write_spd_infoframe(struct drm_connector *connector,
 					buffer, len);
 }
 
-#define SCRAMBLING_POLLING_DELAY_MS	1000
-
-static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder)
+static int vc4_hdmi_scrambler_enable(struct drm_connector *connector)
 {
-	struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
-	struct drm_connector *connector = &vc4_hdmi->connector;
-	struct drm_device *drm = connector->dev;
-	const struct drm_display_mode *mode = &vc4_hdmi->saved_adjusted_mode;
+	struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
 	unsigned long flags;
 	int idx;
 
-	lockdep_assert_held(&vc4_hdmi->mutex);
-
-	if (!vc4_hdmi_supports_scrambling(vc4_hdmi))
-		return;
-
-	if (!drm_hdmi_mode_needs_scrambling(mode,
-					    vc4_hdmi->output_bpc,
-					    vc4_hdmi->output_format))
-		return;
-
-	if (!drm_dev_enter(drm, &idx))
-		return;
-
-	drm_scdc_set_high_tmds_clock_ratio(connector, true);
-	drm_scdc_set_scrambling(connector, true);
+	if (!drm_dev_enter(connector->dev, &idx))
+		return -ENODEV;
 
 	spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
 	HDMI_WRITE(HDMI_SCRAMBLER_CTL, HDMI_READ(HDMI_SCRAMBLER_CTL) |
@@ -812,59 +674,26 @@ static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder)
 
 	drm_dev_exit(idx);
 
-	vc4_hdmi->scdc_enabled = true;
-
-	queue_delayed_work(system_percpu_wq, &vc4_hdmi->scrambling_work,
-			   msecs_to_jiffies(SCRAMBLING_POLLING_DELAY_MS));
+	return 0;
 }
 
-static void vc4_hdmi_disable_scrambling(struct drm_encoder *encoder)
+static int vc4_hdmi_scrambler_disable(struct drm_connector *connector)
 {
-	struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
-	struct drm_connector *connector = &vc4_hdmi->connector;
-	struct drm_device *drm = connector->dev;
+	struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
 	unsigned long flags;
 	int idx;
 
-	lockdep_assert_held(&vc4_hdmi->mutex);
-
-	if (!vc4_hdmi->scdc_enabled)
-		return;
-
-	vc4_hdmi->scdc_enabled = false;
-
-	if (delayed_work_pending(&vc4_hdmi->scrambling_work))
-		cancel_delayed_work_sync(&vc4_hdmi->scrambling_work);
-
-	if (!drm_dev_enter(drm, &idx))
-		return;
+	if (!drm_dev_enter(connector->dev, &idx))
+		return -ENODEV;
 
 	spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
 	HDMI_WRITE(HDMI_SCRAMBLER_CTL, HDMI_READ(HDMI_SCRAMBLER_CTL) &
 		   ~VC5_HDMI_SCRAMBLER_CTL_ENABLE);
 	spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
 
-	drm_scdc_set_scrambling(connector, false);
-	drm_scdc_set_high_tmds_clock_ratio(connector, false);
-
 	drm_dev_exit(idx);
-}
 
-static void vc4_hdmi_scrambling_wq(struct work_struct *work)
-{
-	struct vc4_hdmi *vc4_hdmi = container_of(to_delayed_work(work),
-						 struct vc4_hdmi,
-						 scrambling_work);
-	struct drm_connector *connector = &vc4_hdmi->connector;
-
-	if (drm_scdc_get_scrambling_status(connector))
-		return;
-
-	drm_scdc_set_high_tmds_clock_ratio(connector, true);
-	drm_scdc_set_scrambling(connector, true);
-
-	queue_delayed_work(system_percpu_wq, &vc4_hdmi->scrambling_work,
-			   msecs_to_jiffies(SCRAMBLING_POLLING_DELAY_MS));
+	return 0;
 }
 
 static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder,
@@ -909,7 +738,7 @@ static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder,
 		spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
 	}
 
-	vc4_hdmi_disable_scrambling(encoder);
+	drm_connector_hdmi_disable_scrambling(&vc4_hdmi->connector);
 
 	drm_dev_exit(idx);
 
@@ -1617,6 +1446,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
 	struct drm_display_info *display = &vc4_hdmi->connector.display_info;
 	bool hsync_pos = mode->flags & DRM_MODE_FLAG_PHSYNC;
 	bool vsync_pos = mode->flags & DRM_MODE_FLAG_PVSYNC;
+	struct drm_connector_state *conn_state;
 	unsigned long flags;
 	int ret;
 	int idx;
@@ -1685,7 +1515,9 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
 	}
 
 	vc4_hdmi_recenter_fifo(vc4_hdmi);
-	vc4_hdmi_enable_scrambling(encoder);
+
+	conn_state = drm_atomic_get_new_connector_state(state, connector);
+	drm_connector_hdmi_enable_scrambling(connector, conn_state);
 
 	drm_dev_exit(idx);
 
@@ -1702,8 +1534,6 @@ static void vc4_hdmi_encoder_atomic_mode_set(struct drm_encoder *encoder,
 	mutex_lock(&vc4_hdmi->mutex);
 	drm_mode_copy(&vc4_hdmi->saved_adjusted_mode,
 		      &crtc_state->adjusted_mode);
-	vc4_hdmi->output_bpc = conn_state->hdmi.output_bpc;
-	vc4_hdmi->output_format = conn_state->hdmi.output_format;
 	mutex_unlock(&vc4_hdmi->mutex);
 }
 
@@ -1731,7 +1561,9 @@ vc4_hdmi_connector_clock_valid(const struct drm_connector *connector,
 }
 
 static const struct drm_connector_hdmi_funcs vc4_hdmi_hdmi_connector_funcs = {
-	.tmds_char_rate_valid	= vc4_hdmi_connector_clock_valid,
+	.tmds_char_rate_valid	 = vc4_hdmi_connector_clock_valid,
+	.scrambler_enable	 = vc4_hdmi_scrambler_enable,
+	.scrambler_disable	 = vc4_hdmi_scrambler_disable,
 	.avi = {
 		.clear_infoframe = vc4_hdmi_clear_avi_infoframe,
 		.write_infoframe = vc4_hdmi_write_avi_infoframe,
@@ -3225,7 +3057,6 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 		return ret;
 
 	spin_lock_init(&vc4_hdmi->hw_lock);
-	INIT_DELAYED_WORK(&vc4_hdmi->scrambling_work, vc4_hdmi_scrambling_wq);
 
 	dev_set_drvdata(dev, vc4_hdmi);
 	encoder = &vc4_hdmi->encoder.base;
@@ -3238,15 +3069,6 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 	vc4_hdmi->pdev = pdev;
 	vc4_hdmi->variant = variant;
 
-	/*
-	 * Since we don't know the state of the controller and its
-	 * display (if any), let's assume it's always enabled.
-	 * vc4_hdmi_disable_scrambling() will thus run at boot, make
-	 * sure it's disabled, and avoid any inconsistency.
-	 */
-	if (variant->max_pixel_clock > HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ)
-		vc4_hdmi->scdc_enabled = true;
-
 	ret = variant->init_resources(drm, vc4_hdmi);
 	if (ret)
 		return ret;
drivers/gpu/drm/vc4/vc4_hdmi.h +0 -21
index 29d461d4ee49..0e9797ffad30 100644
@@ -118,8 +118,6 @@ struct vc4_hdmi {
 	struct vc4_encoder encoder;
 	struct drm_connector connector;
 
-	struct delayed_work scrambling_work;
-
 	struct i2c_adapter *ddc;
 	void __iomem *hdmicore_regs;
 	void __iomem *hd_regs;
@@ -193,25 +191,6 @@ struct vc4_hdmi {
 	 */
 	bool packet_ram_enabled;
 
-	/**
-	 * @scdc_enabled: Is the HDMI controller currently running with
-	 * the scrambler on? Protected by @mutex.
-	 */
-	bool scdc_enabled;
-
-	/**
-	 * @output_bpc: Copy of @drm_connector_state.hdmi.output_bpc for
-	 * use outside of KMS hooks. Protected by @mutex.
-	 */
-	unsigned int output_bpc;
-
-	/**
-	 * @output_format: Copy of
-	 * @drm_connector_state.hdmi.output_format for use outside of
-	 * KMS hooks. Protected by @mutex.
-	 */
-	enum drm_output_color_format output_format;
-
 	/**
 	 * @hdmi_jack: Represents the connection state of the HDMI plug, for
 	 * ALSA jack detection.
Signature · 1 line
2.54.0
#89 lore raw

Re: [PATCH v8 31/39] drm/vc4: hdmi: Convert to common SCDC scrambling infrastructure

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] If drm_dev_enter fails in vc4_hdmi_encoder_post_crtc_disable (e.g., when the device is unbound or unplugged), the function jumps to the out label and skips calling drm_connector_hdmi_disable_scrambling(). This leaves the connector->hdmi.scdc_work delayed work pending. Since drm_connector_cleanup() does not natively cancel this work, it will execute after the connector memory has been zeroed and freed, causing a use-after-free and kernel crash. --

commit b7c6215b3f661e126a4a4477a77ead5d481367d2
Author: Cristian Ciocaltea <[email protected]>

drm/vc4: hdmi: Convert to common SCDC scrambling infrastructure

This commit converts the vc4 HDMI driver to use the common HDMI 2.0 scrambling infrastructure. It removes the local scrambling workqueue and state tracking, relying instead on the shared drm_connector_hdmi layer functions.

drivers/gpu/drm/vc4/vc4_hdmi.c static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder, · line 743

Quoted 11 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
@@ -909,7 +738,7 @@ static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder,
 		spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
 	}
 
-	vc4_hdmi_disable_scrambling(encoder);
+	drm_connector_hdmi_disable_scrambling(&vc4_hdmi->connector);
 
 	drm_dev_exit(idx);

[Severity: High]
This is a pre-existing issue, but does skipping this function leave a pending delayed work if device access is lost?

Looking at vc4_hdmi_encoder_post_crtc_disable(), if drm_dev_enter() fails, the function jumps to the out label:

	if (!drm_dev_enter(drm, &idx))
		goto out;
	...
	drm_connector_hdmi_disable_scrambling(&vc4_hdmi->connector);
	drm_dev_exit(idx);
out:
	mutex_unlock(&vc4_hdmi->mutex);

If drm_connector_hdmi_disable_scrambling() is skipped because drm_dev_enter() failed, the connector->hdmi.scdc_work delayed work is never cancelled. Since drm_connector_cleanup() does not cancel this work, will it execute after the connector is freed and cause a use-after-free when the timer fires?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=31
maintainer
#90 lore raw

Re: [PATCH v8 31/39] drm/vc4: hdmi: Convert to common SCDC scrambling infrastructure

In reply to Cristian Ciocaltea

Hi,

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_connector_detect_ctx(struct drm_connector *connector, · line 289

Quoted 12 lines · Cristian Ciocaltea
drivers/gpu/drm/vc4/vc4_hdmi.c +3 -2
@@ -416,10 +281,11 @@ static int vc4_hdmi_connector_detect_ctx(struct drm_connector *connector,
 			status = connector_status_connected;
 	}
 
-	vc4_hdmi_handle_hotplug(vc4_hdmi, ctx, status);
+	ret = drm_atomic_helper_connector_hdmi_hotplug(connector, status, ctx);
+
 	pm_runtime_put(&vc4_hdmi->pdev->dev);
 
-	return status;
+	return ret == -EDEADLK ? ret : status;
 }

This looks like a change that should have its own patch and explanation.

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_write_spd_infoframe(struct drm_connector *connector, · line 787

Quoted 12 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -6
@@ -778,32 +658,14 @@ static int vc4_hdmi_write_spd_infoframe(struct drm_connector *connector,
 					buffer, len);
 }
 
-#define SCRAMBLING_POLLING_DELAY_MS	1000
-
-static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder)
+static int vc4_hdmi_scrambler_enable(struct drm_connector *connector)
 {
-	struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
-	struct drm_connector *connector = &vc4_hdmi->connector;
-	struct drm_device *drm = connector->dev;

If you don't remove this line....

Quoted 6 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -2
-	const struct drm_display_mode *mode = &vc4_hdmi->saved_adjusted_mode;
+	struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
 	unsigned long flags;
 	int idx;
 
-	lockdep_assert_held(&vc4_hdmi->mutex);

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_write_spd_infoframe(struct drm_connector *connector, · line 802

Quoted 10 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +0 -10
-
-	if (!vc4_hdmi_supports_scrambling(vc4_hdmi))
-		return;
-
-	if (!drm_hdmi_mode_needs_scrambling(mode,
-					    vc4_hdmi->output_bpc,
-					    vc4_hdmi->output_format))
-		return;
-
-	if (!drm_dev_enter(drm, &idx))

Then you don't need to change this one either

[...]

Quoted 34 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +5 -15
-		return;
-
-	drm_scdc_set_high_tmds_clock_ratio(connector, true);
-	drm_scdc_set_scrambling(connector, true);
+	if (!drm_dev_enter(connector->dev, &idx))
+		return -ENODEV;
 
 	spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
 	HDMI_WRITE(HDMI_SCRAMBLER_CTL, HDMI_READ(HDMI_SCRAMBLER_CTL) |
@@ -812,59 +674,26 @@ static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder)
 
 	drm_dev_exit(idx);
 
-	vc4_hdmi->scdc_enabled = true;
-
-	queue_delayed_work(system_percpu_wq, &vc4_hdmi->scrambling_work,
-			   msecs_to_jiffies(SCRAMBLING_POLLING_DELAY_MS));
+	return 0;
 }
 
-static void vc4_hdmi_disable_scrambling(struct drm_encoder *encoder)
+static int vc4_hdmi_scrambler_disable(struct drm_connector *connector)
 {
-	struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
-	struct drm_connector *connector = &vc4_hdmi->connector;
-	struct drm_device *drm = connector->dev;
+	struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
 	unsigned long flags;
 	int idx;
 
-	lockdep_assert_held(&vc4_hdmi->mutex);
-
-	if (!vc4_hdmi->scdc_enabled)

drivers/gpu/drm/vc4/vc4_hdmi.c static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder) · line 686

Quoted 10 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -9
-		return;
-
-	vc4_hdmi->scdc_enabled = false;
-
-	if (delayed_work_pending(&vc4_hdmi->scrambling_work))
-		cancel_delayed_work_sync(&vc4_hdmi->scrambling_work);
-
-	if (!drm_dev_enter(drm, &idx))
-		return;
+	if (!drm_dev_enter(connector->dev, &idx))

Ditto

Maxime

#91 lore raw

Re: [PATCH v8 31/39] drm/vc4: hdmi: Convert to common SCDC scrambling infrastructure

Quoted 12 lines · Maxime Ripard

Hi,

Quoted 9 lines · Cristian Ciocaltea
drivers/gpu/drm/vc4/vc4_hdmi.c +2 -1
@@ -416,10 +281,11 @@ static int vc4_hdmi_connector_detect_ctx(struct drm_connector *connector,
 			status = connector_status_connected;
 	}
 
-	vc4_hdmi_handle_hotplug(vc4_hdmi, ctx, status);
+	ret = drm_atomic_helper_connector_hdmi_hotplug(connector, status, ctx);
+
 	pm_runtime_put(&vc4_hdmi->pdev->dev);
 
Quoted 5 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_connector_detect_ctx(struct drm_connector *connector, · line 289

Quoted 3 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
-	return status;
+	return ret == -EDEADLK ? ret : status;
 }

This looks like a change that should have its own patch and explanation.

Yeah, I think .detect_ctx is supposed to return -EDEADLK to allow context owners, e.g. drm_helper_probe_detect_ctx(), to do the backoff and retry.

vc4_hdmi_handle_hotplug() instead runs its own retry loop, calling drm_modeset_backoff() on the acquire context not owned by the driver, which drops every lock in the context, including connection_mutex owned by the core.

This is now implicitly fixed by this patch, but you're right that we should handle this separately, before doing the conversion, i.e. drop the local retry logic and propagate -EDEADLK to the top level.

Quoted 20 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_write_spd_infoframe(struct drm_connector *connector, · line 787

Quoted 12 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -6
@@ -778,32 +658,14 @@ static int vc4_hdmi_write_spd_infoframe(struct drm_connector *connector,
 					buffer, len);
 }
 
-#define SCRAMBLING_POLLING_DELAY_MS	1000
-
-static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder)
+static int vc4_hdmi_scrambler_enable(struct drm_connector *connector)
 {
-	struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
-	struct drm_connector *connector = &vc4_hdmi->connector;
-	struct drm_device *drm = connector->dev;

If you don't remove this line....

Quoted 5 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
-	const struct drm_display_mode *mode = &vc4_hdmi->saved_adjusted_mode;
+	struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
 	unsigned long flags;
 	int idx;
 
Quoted 13 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_write_spd_infoframe(struct drm_connector *connector, · line 802

Quoted 11 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +0 -11
-	lockdep_assert_held(&vc4_hdmi->mutex);
-
-	if (!vc4_hdmi_supports_scrambling(vc4_hdmi))
-		return;
-
-	if (!drm_hdmi_mode_needs_scrambling(mode,
-					    vc4_hdmi->output_bpc,
-					    vc4_hdmi->output_format))
-		return;
-
-	if (!drm_dev_enter(drm, &idx))

Then you don't need to change this one either

Ack.

Cristian

#92 lore raw

PATCH v8 32/39 drm/tests: connector: Add HDMI caps-based init coverage

In reply to Cristian Ciocaltea

Add KUnit tests for drmm_connector_hdmi_init_with_caps() covering NULL caps rejection, the max_tmds_char_rate inferred from each advertised HDMI specification version, and the validation of a driver-provided max_tmds_char_rate against the version-inferred limit: override below, accept at, reject above, reject when no version is advertised.

---
 drivers/gpu/drm/tests/drm_connector_test.c | 189 +++++++++++++++++++++++++++++
 1 file changed, 189 insertions(+)
drivers/gpu/drm/tests/drm_connector_test.c +189 -0
index beb1d50a6646..1fb1d83aec1a 100644
@@ -1254,6 +1254,188 @@ KUNIT_ARRAY_PARAM(drm_connector_hdmi_init_type_invalid,
 		  drm_connector_hdmi_init_type_invalid_tests,
 		  drm_connector_hdmi_init_type_desc);
 
+/*
+ * Test that the registration of an HDMI connector with a NULL caps fails.
+ */
+static void drm_test_connector_hdmi_init_null_caps(struct kunit *test)
+{
+	struct drm_connector_init_priv *priv = test->priv;
+	int ret;
+
+	ret = drmm_connector_hdmi_init_with_caps(&priv->drm, &priv->connector,
+						 "Vendor", "Product",
+						 &dummy_funcs,
+						 &dummy_hdmi_funcs,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 &priv->ddc,
+						 NULL);
+	KUNIT_EXPECT_LT(test, ret, 0);
+}
+
+/*
+ * Test that the registration of an HDMI connector without an explicit max TMDS
+ * character rate being provided succeeds, and the connector limit is inferred
+ * from the advertised HDMI specification version.
+ */
+struct drm_connector_hdmi_init_max_tmds_rate_inferred_case {
+	const char *desc;
+	enum hdmi_version ver;
+	unsigned long long expected;
+};
+
+static void drm_test_connector_hdmi_init_max_tmds_rate_inferred(struct kunit *test)
+{
+	struct drm_connector_init_priv *priv = test->priv;
+	const struct drm_connector_hdmi_init_max_tmds_rate_inferred_case *param =
+		test->param_value;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = param->ver,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+	};
+	int ret;
+
+	ret = drmm_connector_hdmi_init_with_caps(&priv->drm, &priv->connector,
+						 "Vendor", "Product",
+						 &dummy_funcs,
+						 &dummy_hdmi_funcs_scrambler,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 &priv->ddc,
+						 &caps);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, priv->connector.hdmi.max_tmds_char_rate,
+			param->expected);
+}
+
+static const struct drm_connector_hdmi_init_max_tmds_rate_inferred_case
+drm_connector_hdmi_init_max_tmds_rate_inferred_tests[] = {
+	{ "unknown",	HDMI_VERSION_UNKNOWN,	0 },
+	{ "1.0",	HDMI_VERSION_1_0,	HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ },
+	{ "1.2",	HDMI_VERSION_1_2,	HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ },
+	{ "1.3",	HDMI_VERSION_1_3,	HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ },
+	{ "1.4",	HDMI_VERSION_1_4,	HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ },
+	{ "2.0",	HDMI_VERSION_2_0,	HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ },
+};
+
+static void drm_connector_hdmi_init_max_tmds_rate_inferred_desc(
+	const struct drm_connector_hdmi_init_max_tmds_rate_inferred_case *t,
+	char *desc)
+{
+	strscpy(desc, t->desc, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(drm_connector_hdmi_init_max_tmds_rate_inferred,
+		  drm_connector_hdmi_init_max_tmds_rate_inferred_tests,
+		  drm_connector_hdmi_init_max_tmds_rate_inferred_desc);
+
+/*
+ * Test that the registration of an HDMI connector providing a max TMDS
+ * character rate strictly below the version-inferred limit succeeds, and
+ * the connector limit is overridden.
+ */
+static void drm_test_connector_hdmi_init_max_tmds_rate_override(struct kunit *test)
+{
+	struct drm_connector_init_priv *priv = test->priv;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_2_0,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+		.max_tmds_char_rate = HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ,
+	};
+	int ret;
+
+	ret = drmm_connector_hdmi_init_with_caps(&priv->drm, &priv->connector,
+						 "Vendor", "Product",
+						 &dummy_funcs,
+						 &dummy_hdmi_funcs_scrambler,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 &priv->ddc,
+						 &caps);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, priv->connector.hdmi.max_tmds_char_rate,
+			HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ);
+}
+
+/*
+ * Test that the registration of an HDMI connector providing a max TMDS
+ * character rate equal to the version-inferred limit succeeds.
+ */
+static void drm_test_connector_hdmi_init_max_tmds_rate_at_limit(struct kunit *test)
+{
+	struct drm_connector_init_priv *priv = test->priv;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_2_0,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+		.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ,
+	};
+	int ret;
+
+	ret = drmm_connector_hdmi_init_with_caps(&priv->drm, &priv->connector,
+						 "Vendor", "Product",
+						 &dummy_funcs,
+						 &dummy_hdmi_funcs_scrambler,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 &priv->ddc,
+						 &caps);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, priv->connector.hdmi.max_tmds_char_rate,
+			HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ);
+}
+
+/*
+ * Test that the registration of an HDMI connector providing a max TMDS
+ * character rate that exceeds the limit inferred from the advertised HDMI
+ * specification version fails.
+ */
+static void drm_test_connector_hdmi_init_max_tmds_rate_exceeds(struct kunit *test)
+{
+	struct drm_connector_init_priv *priv = test->priv;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_1_4,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+		.max_tmds_char_rate = HDMI_2_0_TMDS_CHAR_RATE_MAX_HZ,
+	};
+	int ret;
+
+	ret = drmm_connector_hdmi_init_with_caps(&priv->drm, &priv->connector,
+						 "Vendor", "Product",
+						 &dummy_funcs,
+						 &dummy_hdmi_funcs,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 &priv->ddc,
+						 &caps);
+	KUNIT_EXPECT_LT(test, ret, 0);
+}
+
+/*
+ * Test that the registration of an HDMI connector providing a non-zero max
+ * TMDS character rate without an HDMI specification version fails, as the
+ * version-inferred limit defaults to zero and any positive override would
+ * exceed it.
+ */
+static void drm_test_connector_hdmi_init_max_tmds_rate_no_version(struct kunit *test)
+{
+	struct drm_connector_init_priv *priv = test->priv;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_UNKNOWN,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+		.max_tmds_char_rate = HDMI_1_0_TMDS_CHAR_RATE_MAX_HZ,
+	};
+	int ret;
+
+	ret = drmm_connector_hdmi_init_with_caps(&priv->drm, &priv->connector,
+						 "Vendor", "Product",
+						 &dummy_funcs,
+						 &dummy_hdmi_funcs,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 &priv->ddc,
+						 &caps);
+	KUNIT_EXPECT_LT(test, ret, 0);
+}
+
 static struct kunit_case drmm_connector_hdmi_init_tests[] = {
 	KUNIT_CASE(drm_test_connector_hdmi_init_valid),
 	KUNIT_CASE(drm_test_connector_hdmi_init_bpc_8),
@@ -1278,6 +1460,13 @@ static struct kunit_case drmm_connector_hdmi_init_tests[] = {
 			 drm_connector_hdmi_init_type_valid_gen_params),
 	KUNIT_CASE_PARAM(drm_test_connector_hdmi_init_type_invalid,
 			 drm_connector_hdmi_init_type_invalid_gen_params),
+	KUNIT_CASE(drm_test_connector_hdmi_init_null_caps),
+	KUNIT_CASE_PARAM(drm_test_connector_hdmi_init_max_tmds_rate_inferred,
+			 drm_connector_hdmi_init_max_tmds_rate_inferred_gen_params),
+	KUNIT_CASE(drm_test_connector_hdmi_init_max_tmds_rate_override),
+	KUNIT_CASE(drm_test_connector_hdmi_init_max_tmds_rate_at_limit),
+	KUNIT_CASE(drm_test_connector_hdmi_init_max_tmds_rate_exceeds),
+	KUNIT_CASE(drm_test_connector_hdmi_init_max_tmds_rate_no_version),
 	{ }
 };
 
Signature · 1 line
2.54.0
#93 lore raw

Re: [PATCH v8 32/39] drm/tests: connector: Add HDMI caps-based init coverage

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The test cases introduced in this patch reference `dummy_hdmi_funcs_scrambler`, which is undeclared…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The test cases introduced in this patch reference dummy_hdmi_funcs_scrambler, which is undeclared in this commit, causing a compilation error. Each patch in a series must compile independently to preserve git bisectability. --

commit 00f793137805b36c4e39a000783f65bb290b345b
Author: Cristian Ciocaltea <[email protected]>

drm/tests: connector: Add HDMI caps-based init coverage

Add KUnit tests for drmm_connector_hdmi_init_with_caps() covering NULL caps rejection, max_tmds_char_rate inference, and limits validation.

Quoted 4 lines
drivers/gpu/drm/tests/drm_connector_test.c +0 -0
index beb1d50a66464..1fb1d83aec1af 100644

[ ... ]

Quoted 2 lines
drivers/gpu/drm/tests/drm_connector_test.c +2 -0
+static void drm_test_connector_hdmi_init_max_tmds_rate_inferred(struct kunit *test)
+{

[ ... ]

drivers/gpu/drm/tests/drm_connector_test.c KUNIT_ARRAY_PARAM(drm_connector_hdmi_init_type_invalid, · line 1301

Quoted 4 lines
drivers/gpu/drm/tests/drm_connector_test.c +4 -0
+	ret = drmm_connector_hdmi_init_with_caps(&priv->drm, &priv->connector,
+						 "Vendor", "Product",
+						 &dummy_funcs,
+						 &dummy_hdmi_funcs_scrambler,

[Severity: Low]
Does this cause a compilation error? It appears dummy_hdmi_funcs_scrambler is undeclared in this commit.

While this gets fixed later in the series in commit c237a4e2c8cf9600c005 (drm/tests: connector: Add HDMI source-side scrambler coverage), referencing it early breaks git bisectability as this patch will fail to compile on its own.

This same undeclared variable is also referenced in drm_test_connector_hdmi_init_max_tmds_rate_override() and drm_test_connector_hdmi_init_max_tmds_rate_at_limit() later in this patch.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=32
#94 lore raw

PATCH v8 33/39 drm/tests: connector: Add HDMI source-side scrambler coverage

In reply to Cristian Ciocaltea

Add KUnit tests for the HDMI source-side scrambling validation done by drmm_connector_hdmi_init_with_caps().

Connector initialization derives the scrambler_supported flag from the driver-provided supported_hdmi_ver capability. If it indicates source-side scrambling support, both .scrambler_enable and .scrambler_disable must be provided. Missing either callback is rejected. If source-side scrambling is not supported, the callbacks are ignored.

Test the valid and invalid callback combinations for both supported and unsupported scrambling configurations.

---
 drivers/gpu/drm/tests/drm_connector_test.c | 141 +++++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)
drivers/gpu/drm/tests/drm_connector_test.c +141 -0
index 1fb1d83aec1a..98ccfaa0ee36 100644
@@ -47,6 +47,41 @@ static const struct drm_connector_hdmi_funcs dummy_hdmi_funcs = {
 	},
 };
 
+static int accept_scrambler_enable(struct drm_connector *connector)
+{
+	return 0;
+}
+
+static int accept_scrambler_disable(struct drm_connector *connector)
+{
+	return 0;
+}
+
+static const struct drm_connector_hdmi_funcs dummy_hdmi_funcs_scrambler = {
+	.scrambler_enable = accept_scrambler_enable,
+	.scrambler_disable = accept_scrambler_disable,
+	.avi = {
+		.clear_infoframe = accept_infoframe_clear_infoframe,
+		.write_infoframe = accept_infoframe_write_infoframe,
+	},
+	.hdmi = {
+		.clear_infoframe = accept_infoframe_clear_infoframe,
+		.write_infoframe = accept_infoframe_write_infoframe,
+	},
+};
+
+static const struct drm_connector_hdmi_funcs dummy_hdmi_funcs_scrambler_partial = {
+	.scrambler_enable = accept_scrambler_enable,
+	.avi = {
+		.clear_infoframe = accept_infoframe_clear_infoframe,
+		.write_infoframe = accept_infoframe_write_infoframe,
+	},
+	.hdmi = {
+		.clear_infoframe = accept_infoframe_clear_infoframe,
+		.write_infoframe = accept_infoframe_write_infoframe,
+	},
+};
+
 static const struct drm_connector_funcs dummy_funcs = {
 	.atomic_destroy_state	= drm_atomic_helper_connector_destroy_state,
 	.atomic_duplicate_state	= drm_atomic_helper_connector_duplicate_state,
@@ -1436,6 +1471,108 @@ static void drm_test_connector_hdmi_init_max_tmds_rate_no_version(struct kunit *
 	KUNIT_EXPECT_LT(test, ret, 0);
 }
 
+/*
+ * Test that the registration of an HDMI connector advertising source-side
+ * scrambling support succeeds when the .scrambler_{enable|disable} callbacks
+ * are provided.
+ */
+static void drm_test_connector_hdmi_init_scrambler_valid(struct kunit *test)
+{
+	struct drm_connector_init_priv *priv = test->priv;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_2_0,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+	};
+	int ret;
+
+	ret = drmm_connector_hdmi_init_with_caps(&priv->drm, &priv->connector,
+						 "Vendor", "Product",
+						 &dummy_funcs,
+						 &dummy_hdmi_funcs_scrambler,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 &priv->ddc,
+						 &caps);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, priv->connector.hdmi.scrambler_supported, true);
+}
+
+/*
+ * Test that the registration of an HDMI connector advertising source-side
+ * scrambling support fails when the .scrambler_{enable|disable} callbacks
+ * are not provided.
+ */
+static void drm_test_connector_hdmi_init_scrambler_no_callbacks(struct kunit *test)
+{
+	struct drm_connector_init_priv *priv = test->priv;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_2_0,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+	};
+	int ret;
+
+	ret = drmm_connector_hdmi_init_with_caps(&priv->drm, &priv->connector,
+						 "Vendor", "Product",
+						 &dummy_funcs,
+						 &dummy_hdmi_funcs,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 &priv->ddc,
+						 &caps);
+	KUNIT_EXPECT_LT(test, ret, 0);
+}
+
+/*
+ * Test that the registration of an HDMI connector advertising source-side
+ * scrambling support fails when only one of the .scrambler_{enable|disable}
+ * callbacks are provided.
+ */
+static void drm_test_connector_hdmi_init_scrambler_partial_callbacks(struct kunit *test)
+{
+	struct drm_connector_init_priv *priv = test->priv;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_2_0,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+	};
+	int ret;
+
+	ret = drmm_connector_hdmi_init_with_caps(&priv->drm, &priv->connector,
+						 "Vendor", "Product",
+						 &dummy_funcs,
+						 &dummy_hdmi_funcs_scrambler_partial,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 &priv->ddc,
+						 &caps);
+	KUNIT_EXPECT_LT(test, ret, 0);
+}
+
+/*
+ * Test that the registration of an HDMI connector not advertising source-side
+ * scrambling support succeeds, even when the .scrambler_{enable|disable}
+ * callbacks are provided, i.e. they are ignored.
+ */
+static void drm_test_connector_hdmi_init_scrambler_ignored_callbacks(struct kunit *test)
+{
+	struct drm_connector_init_priv *priv = test->priv;
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_1_4,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+	};
+	int ret;
+
+	ret = drmm_connector_hdmi_init_with_caps(&priv->drm, &priv->connector,
+						 "Vendor", "Product",
+						 &dummy_funcs,
+						 &dummy_hdmi_funcs_scrambler,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 &priv->ddc,
+						 &caps);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, priv->connector.hdmi.scrambler_supported, false);
+}
+
 static struct kunit_case drmm_connector_hdmi_init_tests[] = {
 	KUNIT_CASE(drm_test_connector_hdmi_init_valid),
 	KUNIT_CASE(drm_test_connector_hdmi_init_bpc_8),
@@ -1467,6 +1604,10 @@ static struct kunit_case drmm_connector_hdmi_init_tests[] = {
 	KUNIT_CASE(drm_test_connector_hdmi_init_max_tmds_rate_at_limit),
 	KUNIT_CASE(drm_test_connector_hdmi_init_max_tmds_rate_exceeds),
 	KUNIT_CASE(drm_test_connector_hdmi_init_max_tmds_rate_no_version),
+	KUNIT_CASE(drm_test_connector_hdmi_init_scrambler_valid),
+	KUNIT_CASE(drm_test_connector_hdmi_init_scrambler_no_callbacks),
+	KUNIT_CASE(drm_test_connector_hdmi_init_scrambler_partial_callbacks),
+	KUNIT_CASE(drm_test_connector_hdmi_init_scrambler_ignored_callbacks),
 	{ }
 };
 
Signature · 1 line
2.54.0
#95 lore raw

PATCH v8 34/39 drm/tests: hdmi_state_helper: Use drmm_connector_hdmi_init_with_caps()

In reply to Cristian Ciocaltea

Convert the internal __connector_hdmi_init() helper to take a drm_connector_hdmi_caps struct rather than separate formats and max_bpc parameters, and add a drm_kunit_helper_connector_hdmi_init_with_caps_edid_funcs() macro that exposes the full caps struct to tests.

This lets new tests exercise capability fields beyond formats and max_bpc, notably supported_hdmi_ver and max_tmds_char_rate, without further changes to the helper signature.

The legacy drm_kunit_helper_connector_hdmi_init_with_edid_funcs() macro is kept as a thin wrapper so the bulk of the test suite is unaffected.

---
 drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 35 ++++++++++++++--------
 1 file changed, 22 insertions(+), 13 deletions(-)
drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c +22 -13
index 353a261d42da..6a7dd2de002a 100644
@@ -231,8 +231,7 @@ static const struct drm_encoder_helper_funcs test_encoder_helper_funcs = {
 static
 struct drm_atomic_helper_connector_hdmi_priv *
 __connector_hdmi_init(struct kunit *test,
-		      unsigned int formats,
-		      unsigned int max_bpc,
+		      const struct drm_connector_hdmi_caps *caps,
 		      const struct drm_connector_hdmi_funcs *hdmi_funcs,
 		      const void *edid_data, size_t edid_len)
 {
@@ -273,16 +272,16 @@ __connector_hdmi_init(struct kunit *test,
 	enc->possible_crtcs = drm_crtc_mask(priv->crtc);
 
 	conn = &priv->connector;
-	conn->ycbcr_420_allowed = !!(formats & BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420));
+	conn->ycbcr_420_allowed = !!(caps->supported_formats &
+				     BIT(DRM_OUTPUT_COLOR_FORMAT_YCBCR420));
 
-	ret = drmm_connector_hdmi_init(drm, conn,
-				       "Vendor", "Product",
-				       &dummy_connector_funcs,
-				       hdmi_funcs,
-				       DRM_MODE_CONNECTOR_HDMIA,
-				       NULL,
-				       formats,
-				       max_bpc);
+	ret = drmm_connector_hdmi_init_with_caps(drm, conn,
+						 "Vendor", "Product",
+						 &dummy_connector_funcs,
+						 hdmi_funcs,
+						 DRM_MODE_CONNECTOR_HDMIA,
+						 NULL,
+						 caps);
 	KUNIT_ASSERT_EQ(test, ret, 0);
 
 	drm_connector_helper_add(conn, &dummy_connector_helper_funcs);
@@ -298,8 +297,18 @@ __connector_hdmi_init(struct kunit *test,
 	return priv;
 }
 
-#define drm_kunit_helper_connector_hdmi_init_with_edid_funcs(test, formats, max_bpc, funcs, edid) \
-	__connector_hdmi_init(test, formats, max_bpc, funcs, edid, ARRAY_SIZE(edid))
+#define drm_kunit_helper_connector_hdmi_init_with_edid_funcs(test, formats,	\
+						bpc_max, funcs, edid)		\
+({										\
+	struct drm_connector_hdmi_caps __caps = {				\
+		.supported_formats = (formats),					\
+		.max_bpc = (bpc_max),						\
+	};									\
+	__connector_hdmi_init(test, &__caps, funcs, edid, ARRAY_SIZE(edid));	\
+})
+
+#define drm_kunit_helper_connector_hdmi_init_with_caps_edid_funcs(test, caps, funcs, edid) \
+	__connector_hdmi_init(test, caps, funcs, edid, ARRAY_SIZE(edid))
 
 static
 struct drm_atomic_helper_connector_hdmi_priv *
Signature · 1 line
2.54.0
#96 lore raw

PATCH v8 35/39 drm/tests: hdmi_state_helper: Add max_tmds_char_rate fallback tests

In reply to Cristian Ciocaltea

Cover the fallback in hdmi_clock_valid() that rejects modes whose TMDS character rate exceeds connector->hdmi.max_tmds_char_rate when the driver provides no .tmds_char_rate_valid() callback. Exercise both an explicit limit set through drm_connector_hdmi_caps and the limit inferred from caps.supported_hdmi_ver, and confirm that a driver hook takes precedence over the connector limit.

The connector limit is installed via the new drm_kunit_helper_connector_hdmi_init_with_caps_edid_funcs() helper so it is in place before mode probing runs.

---
 drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 120 +++++++++++++++++++++
 1 file changed, 120 insertions(+)
drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c +120 -0
index 6a7dd2de002a..b8ae5fad2794 100644
@@ -174,6 +174,26 @@ static const struct drm_connector_hdmi_funcs reject_100mhz_connector_hdmi_funcs
 	},
 };
 
+static enum drm_mode_status
+accept_connector_tmds_char_rate_valid(const struct drm_connector *connector,
+				      const struct drm_display_mode *mode,
+				      unsigned long long tmds_rate)
+{
+	return MODE_OK;
+}
+
+static const struct drm_connector_hdmi_funcs accept_connector_hdmi_funcs = {
+	.tmds_char_rate_valid	= accept_connector_tmds_char_rate_valid,
+	.avi = {
+		.clear_infoframe = accept_infoframe_clear_infoframe,
+		.write_infoframe = accept_infoframe_write_infoframe,
+	},
+	.hdmi = {
+		.clear_infoframe = accept_infoframe_clear_infoframe,
+		.write_infoframe = accept_infoframe_write_infoframe,
+	},
+};
+
 static int dummy_connector_get_modes(struct drm_connector *connector)
 {
 	struct drm_atomic_helper_connector_hdmi_priv *priv =
@@ -2771,6 +2791,103 @@ static void drm_test_check_mode_valid_reject_max_clock(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, preferred->clock, 25200);
 }
 
+/*
+ * Test that a driver-provided .tmds_char_rate_valid() hook takes precedence
+ * over the connector->hdmi.max_tmds_char_rate fallback: the fallback must
+ * not be consulted when the hook is present.
+ */
+static void
+drm_test_check_mode_valid_driver_hook_overrides_max_tmds_char_rate(struct kunit *test)
+{
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_1_3,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+		.max_tmds_char_rate = 100ULL * 1000 * 1000,
+	};
+	struct drm_atomic_helper_connector_hdmi_priv *priv;
+	struct drm_display_mode *preferred;
+
+	priv = drm_kunit_helper_connector_hdmi_init_with_caps_edid_funcs(test,
+					&caps,
+					&accept_connector_hdmi_funcs,
+					test_edid_hdmi_1080p_rgb_max_200mhz);
+	KUNIT_ASSERT_NOT_NULL(test, priv);
+
+	preferred = find_preferred_mode(&priv->connector);
+	KUNIT_ASSERT_NOT_NULL(test, preferred);
+	KUNIT_EXPECT_EQ(test, preferred->hdisplay, 1920);
+	KUNIT_EXPECT_EQ(test, preferred->vdisplay, 1080);
+	KUNIT_EXPECT_EQ(test, preferred->clock, 148500);
+}
+
+/*
+ * Test that drm_hdmi_connector_mode_valid() falls back to
+ * connector->hdmi.max_tmds_char_rate when the driver provides no
+ * .tmds_char_rate_valid() hook, rejecting modes whose computed TMDS character
+ * rate exceeds the connector limit.
+ */
+static void
+drm_test_check_mode_valid_reject_connector_max_tmds_char_rate(struct kunit *test)
+{
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_1_3,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+		.max_tmds_char_rate = 100ULL * 1000 * 1000,
+	};
+	struct drm_atomic_helper_connector_hdmi_priv *priv;
+	struct drm_display_mode *preferred;
+
+	priv = drm_kunit_helper_connector_hdmi_init_with_caps_edid_funcs(test,
+					&caps,
+					&dummy_connector_hdmi_funcs,
+					test_edid_hdmi_1080p_rgb_max_200mhz);
+	KUNIT_ASSERT_NOT_NULL(test, priv);
+
+	preferred = find_preferred_mode(&priv->connector);
+	KUNIT_ASSERT_NOT_NULL(test, preferred);
+	KUNIT_EXPECT_EQ(test, preferred->hdisplay, 640);
+	KUNIT_EXPECT_EQ(test, preferred->vdisplay, 480);
+	KUNIT_EXPECT_EQ(test, preferred->clock, 25200);
+}
+
+/*
+ * Test that the max_tmds_char_rate inferred from caps.supported_hdmi_ver
+ * is applied as a mode-filtering limit: with an HDMI 1.3 connector
+ * (340 MHz inferred cap) and no driver hook, modes whose RGB444/8bpc TMDS
+ * rate exceeds 340 MHz must be filtered out even though the sink itself
+ * advertises a higher limit.
+ */
+static void
+drm_test_check_mode_valid_reject_inferred_max_tmds_char_rate(struct kunit *test)
+{
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_1_3,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+	};
+	struct drm_atomic_helper_connector_hdmi_priv *priv;
+	struct drm_display_mode *preferred;
+	unsigned long long rate;
+
+	priv = drm_kunit_helper_connector_hdmi_init_with_caps_edid_funcs(test,
+					&caps,
+					&dummy_connector_hdmi_funcs,
+					test_edid_hdmi_4k_rgb_yuv420_dc_max_600mhz);
+	KUNIT_ASSERT_NOT_NULL(test, priv);
+
+	KUNIT_ASSERT_EQ(test, priv->connector.hdmi.max_tmds_char_rate,
+			HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ);
+
+	preferred = find_preferred_mode(&priv->connector);
+	KUNIT_ASSERT_NOT_NULL(test, preferred);
+
+	rate = drm_hdmi_compute_mode_clock(preferred, 8,
+					   DRM_OUTPUT_COLOR_FORMAT_RGB444);
+	KUNIT_EXPECT_LE(test, rate, HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ);
+}
+
 /*
  * Test that drm_hdmi_connector_mode_valid() will accept modes that require a
  * 4:2:0 chroma subsampling, even if said mode would violate maximum clock
@@ -2865,6 +2982,9 @@ static struct kunit_case drm_atomic_helper_connector_hdmi_mode_valid_tests[] = {
 	KUNIT_CASE(drm_test_check_mode_valid_reject),
 	KUNIT_CASE(drm_test_check_mode_valid_reject_rate),
 	KUNIT_CASE(drm_test_check_mode_valid_reject_max_clock),
+	KUNIT_CASE(drm_test_check_mode_valid_driver_hook_overrides_max_tmds_char_rate),
+	KUNIT_CASE(drm_test_check_mode_valid_reject_connector_max_tmds_char_rate),
+	KUNIT_CASE(drm_test_check_mode_valid_reject_inferred_max_tmds_char_rate),
 	KUNIT_CASE(drm_test_check_mode_valid_yuv420_only_max_clock),
 	KUNIT_CASE(drm_test_check_mode_valid_reject_yuv420_only_connector),
 	KUNIT_CASE(drm_test_check_mode_valid_accept_yuv420_also_connector_rgb),
Signature · 1 line
2.54.0
#97 lore raw

PATCH v8 36/39 drm/tests: edid: Add 4K@60Hz EDID with 600MHz TMDS

In reply to Cristian Ciocaltea

Add a new test EDID advertising the following capabilities:

Max resolution: 3840x2160@60Hz with RGB, YUV444, YUV422, YUV420
Max BPC:        16
Max TMDS clock: 600 MHz

This is needed to exercise the new HDMI infrastructure that decides whether scrambling needs to be enabled for a given display mode and to validate that high-rate modes are properly rejected/accepted depending on the source/sink scrambling capability.

The EDID is derived from test_edid_hdmi_4k_rgb_yuv420_dc_max_340mhz with the following changes:

- Upgraded the first DTD from 3840x2160@30 (297 MHz) to 3840x2160@60 (594 MHz). The H/V totals (4400x2250) and porches already match the HDMI 2.0 4K@60Hz standard timing, so only the pixel clock had to be bumped.
- Widened Display Range Limits descriptor to cover the new timing, i.e. 24-140 kHz H, max dotclock 600 MHz.
- Updated CTA-861 Video Data Block to advertise VIC 97 (4K@60Hz) instead of VIC 95 (4k30).
- Bumped HF-VSDB Max TMDS Character Rate to 600 MHz, keeping SCDC_Present set so that the sink advertises scrambling support.
- Cleared HDMI VSDB Max TMDS clock byte, as required by HDMI 2.0 when the HF-VSDB declares a Max TMDS Character Rate above 340 MHz.
- Provided a Video Capability Data Block advertising selectable RGB and YCC quantization range plus underscan for IT/CE formats; also set the 'IT Video Formats Underscanned' bit in the CTA-861 extension header to match.
- Aligned base block image size with the DTD (160x90 cm) and replaced the bogus 'Week of Manufacture = 0xff' with the Model Year code, both fixing inherited EDID conformity warnings.
- Dropped the empty YCbCr 4:2:0 Video Data Block inherited from the parent EDID, which is flagged as a failure by edid-decode v1.33.0

---
 drivers/gpu/drm/tests/drm_kunit_edid.c | 129 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/tests/drm_kunit_edid.h |   1 +
 2 files changed, 130 insertions(+)
drivers/gpu/drm/tests/drm_kunit_edid.c +129 -0
index c807ae0d9faa..673a0ea8c2ae 100644
@@ -990,6 +990,135 @@ const unsigned char test_edid_hdmi_4k_rgb_yuv420_dc_max_340mhz[] = {
 };
 EXPORT_SYMBOL(test_edid_hdmi_4k_rgb_yuv420_dc_max_340mhz);
 
+/*
+ * Max resolution: 3840x2160@60Hz with RGB, YUV444, YUV422, YUV420
+ * Max BPC:        16 for all modes
+ * Max TMDS clock: 600 MHz
+ *
+ * edid-decode (hex):
+ *
+ * 00 ff ff ff ff ff ff 00 31 d8 34 00 00 00 00 00
+ * 00 23 01 03 80 a0 5a 78 0f ee 91 a3 54 4c 99 26
+ * 0f 50 54 20 00 00 01 01 01 01 01 01 01 01 01 01
+ * 01 01 01 01 01 01 08 e8 00 30 f2 70 5a 80 b0 58
+ * 8a 00 40 84 63 00 00 1e 00 00 00 fc 00 54 65 73
+ * 74 20 45 44 49 44 0a 20 20 20 00 00 00 fd 00 18
+ * 55 18 8c 3c 00 0a 20 20 20 20 20 20 00 00 00 10
+ * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 a9
+ *
+ * 02 03 28 b1 41 61 6c 03 0c 00 10 00 78 00 20 00
+ * 00 01 03 6d d8 5d c4 01 78 80 07 00 00 00 00 00
+ * 00 e2 00 ca e3 0f 01 00 00 00 00 00 00 00 00 00
+ * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 54
+ *
+ * ----------------
+ *
+ * Block 0, Base EDID:
+ *   EDID Structure Version & Revision: 1.3
+ *   Vendor & Product Identification:
+ *     Manufacturer: LNX
+ *     Model: 52
+ *     Made in: 2025
+ *   Basic Display Parameters & Features:
+ *     Digital display
+ *     Maximum image size: 160 cm x 90 cm
+ *     Gamma: 2.20
+ *     RGB color display
+ *     Default (sRGB) color space is primary color space
+ *     First detailed timing is the preferred timing
+ *     Supports GTF timings within operating range
+ *   Color Characteristics:
+ *     Red  : 0.6396, 0.3300
+ *     Green: 0.2998, 0.5996
+ *     Blue : 0.1503, 0.0595
+ *     White: 0.3125, 0.3291
+ *   Established Timings I & II:
+ *     DMT 0x04:   640x480    59.940476 Hz   4:3     31.469 kHz     25.175000 MHz
+ *   Standard Timings: none
+ *   Detailed Timing Descriptors:
+ *     DTD 1:  3840x2160   60.000000 Hz  16:9    135.000 kHz    594.000000 MHz (1600 mm x 900 mm)
+ *                  Hfront  176 Hsync  88 Hback  296 Hpol P
+ *                  Vfront    8 Vsync  10 Vback   72 Vpol P
+ *     Display Product Name: 'Test EDID'
+ *     Display Range Limits:
+ *       Monitor ranges (GTF): 24-85 Hz V, 24-140 kHz H, max dotclock 600 MHz
+ *     Dummy Descriptor:
+ *   Extension blocks: 1
+ * Checksum: 0xa9
+ *
+ * ----------------
+ *
+ * Block 1, CTA-861 Extension Block:
+ *   Revision: 3
+ *   Underscans IT Video Formats by default
+ *   Supports YCbCr 4:4:4
+ *   Supports YCbCr 4:2:2
+ *   Native detailed modes: 1
+ *   Video Data Block:
+ *     VIC  97:  3840x2160   60.000000 Hz  16:9    135.000 kHz    594.000000 MHz
+ *   Vendor-Specific Data Block (HDMI), OUI 00-0C-03:
+ *     Source physical address: 1.0.0.0
+ *     DC_48bit
+ *     DC_36bit
+ *     DC_30bit
+ *     DC_Y444
+ *     Maximum TMDS clock: 0 MHz
+ *     Extended HDMI video details:
+ *   Vendor-Specific Data Block (HDMI Forum), OUI C4-5D-D8:
+ *     Version: 1
+ *     Maximum TMDS Character Rate: 600 MHz
+ *     SCDC Present
+ *     Supports 16-bits/component Deep Color 4:2:0 Pixel Encoding
+ *     Supports 12-bits/component Deep Color 4:2:0 Pixel Encoding
+ *     Supports 10-bits/component Deep Color 4:2:0 Pixel Encoding
+ *     VRRmin: 0 Hz
+ *     VRRmax: 0 Hz
+ *   Video Capability Data Block:
+ *     YCbCr quantization: Selectable (via AVI YQ)
+ *     RGB quantization: Selectable (via AVI Q)
+ *     PT scan behavior: No Data
+ *     IT scan behavior: Always Underscanned
+ *     CE scan behavior: Always Underscanned
+ *   YCbCr 4:2:0 Capability Map Data Block:
+ *     VIC  97:  3840x2160   60.000000 Hz  16:9    135.000 kHz    594.000000 MHz
+ * Checksum: 0x54  Unused space in Extension Block: 87 bytes
+ *
+ * ----------------
+ *
+ * edid-decode 1.33.0
+ *
+ * EDID conformity: PASS
+ */
+const unsigned char test_edid_hdmi_4k_rgb_yuv420_dc_max_600mhz[] = {
+	0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x31, 0xd8, 0x34, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x01, 0x03, 0x80, 0xa0, 0x5a, 0x78,
+	0x0f, 0xee, 0x91, 0xa3, 0x54, 0x4c, 0x99, 0x26, 0x0f, 0x50, 0x54, 0x20,
+	0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+	0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x08, 0xe8, 0x00, 0x30, 0xf2, 0x70,
+	0x5a, 0x80, 0xb0, 0x58, 0x8a, 0x00, 0x40, 0x84, 0x63, 0x00, 0x00, 0x1e,
+	0x00, 0x00, 0x00, 0xfc, 0x00, 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x44,
+	0x49, 0x44, 0x0a, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18,
+	0x55, 0x18, 0x8c, 0x3c, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+	0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xa9, 0x02, 0x03, 0x28, 0xb1,
+	0x41, 0x61, 0x6c, 0x03, 0x0c, 0x00, 0x10, 0x00, 0x78, 0x00, 0x20, 0x00,
+	0x00, 0x01, 0x03, 0x6d, 0xd8, 0x5d, 0xc4, 0x01, 0x78, 0x80, 0x07, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x00, 0xca, 0xe3, 0x0f, 0x01, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x54,
+};
+EXPORT_SYMBOL(test_edid_hdmi_4k_rgb_yuv420_dc_max_600mhz);
+
 MODULE_AUTHOR("Maxime Ripard <[email protected]>");
 MODULE_DESCRIPTION("EDID Definitions for KUnit tests");
 MODULE_LICENSE("GPL");
drivers/gpu/drm/tests/drm_kunit_edid.h +1 -0
index 28b4df93a555..fb5b0295e35e 100644
@@ -12,5 +12,6 @@ extern const unsigned char test_edid_hdmi_1080p_rgb_yuv_dc_max_200mhz[256];
 extern const unsigned char test_edid_hdmi_1080p_rgb_yuv_dc_max_340mhz[256];
 extern const unsigned char test_edid_hdmi_1080p_rgb_yuv_4k_yuv420_dc_max_200mhz[256];
 extern const unsigned char test_edid_hdmi_4k_rgb_yuv420_dc_max_340mhz[256];
+extern const unsigned char test_edid_hdmi_4k_rgb_yuv420_dc_max_600mhz[256];
 
 #endif // DRM_KUNIT_EDID_H_
Signature · 1 line
2.54.0
#98 lore raw

PATCH v8 37/39 drm/tests: hdmi_state_helper: Cover source-side scrambling decision

In reply to Cristian Ciocaltea

Add two atomic-check cases that initialise an HDMI 2.0 connector via drm_connector_hdmi_caps (so the core infers scrambler_supported and the 600 MHz TMDS limit) and assert that conn_state->hdmi.scrambler_needed stays clear for a 1080p@60 CEA mode (~148.5 MHz TMDS) and is set for the 4K@60 RGB preferred mode (~594 MHz TMDS), straddling the 340 MHz threshold.

---
 drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c | 160 +++++++++++++++++++++
 1 file changed, 160 insertions(+)
drivers/gpu/drm/tests/drm_hdmi_state_helper_test.c +160 -0
index b8ae5fad2794..7cd6bd422b0b 100644
@@ -20,6 +20,8 @@
 #include <drm/display/drm_hdmi_helper.h>
 #include <drm/display/drm_hdmi_state_helper.h>
 
+#include <linux/hdmi.h>
+
 #include "../drm_crtc_internal.h"
 
 #include <kunit/test.h>
@@ -194,6 +196,29 @@ static const struct drm_connector_hdmi_funcs accept_connector_hdmi_funcs = {
 	},
 };
 
+static int accept_scrambler_enable(struct drm_connector *connector)
+{
+	return 0;
+}
+
+static int accept_scrambler_disable(struct drm_connector *connector)
+{
+	return 0;
+}
+
+static const struct drm_connector_hdmi_funcs scrambler_connector_hdmi_funcs = {
+	.scrambler_enable	 = accept_scrambler_enable,
+	.scrambler_disable	 = accept_scrambler_disable,
+	.avi = {
+		.clear_infoframe = accept_infoframe_clear_infoframe,
+		.write_infoframe = accept_infoframe_write_infoframe,
+	},
+	.hdmi = {
+		.clear_infoframe = accept_infoframe_clear_infoframe,
+		.write_infoframe = accept_infoframe_write_infoframe,
+	},
+};
+
 static int dummy_connector_get_modes(struct drm_connector *connector)
 {
 	struct drm_atomic_helper_connector_hdmi_priv *priv =
@@ -2265,6 +2290,139 @@ static void drm_test_check_disable_connector(struct kunit *test)
 	drm_modeset_acquire_fini(&ctx);
 }
 
+/*
+ * Test that on an HDMI connector with source+sink scrambling support, driving
+ * a sub-340 MHz CEA mode, we end up with scrambler_needed cleared.
+ */
+static void drm_test_check_scrambler_needed_low_rate(struct kunit *test)
+{
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_2_0,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+	};
+	struct drm_atomic_helper_connector_hdmi_priv *priv;
+	struct drm_modeset_acquire_ctx ctx;
+	struct drm_connector_state *conn_state;
+	struct drm_display_info *info;
+	struct drm_display_mode *low_rate_mode;
+	struct drm_connector *conn;
+	struct drm_device *drm;
+	struct drm_crtc *crtc;
+	unsigned long long rate;
+	int ret;
+
+	priv = drm_kunit_helper_connector_hdmi_init_with_caps_edid_funcs(test,
+				&caps,
+				&scrambler_connector_hdmi_funcs,
+				test_edid_hdmi_4k_rgb_yuv420_dc_max_600mhz);
+	KUNIT_ASSERT_NOT_NULL(test, priv);
+
+	drm = &priv->drm;
+	crtc = priv->crtc;
+	conn = &priv->connector;
+	info = &conn->display_info;
+	KUNIT_ASSERT_TRUE(test, conn->hdmi.scrambler_supported);
+	KUNIT_ASSERT_TRUE(test, info->is_hdmi);
+	KUNIT_ASSERT_TRUE(test, info->hdmi.scdc.supported);
+	KUNIT_ASSERT_TRUE(test, info->hdmi.scdc.scrambling.supported);
+
+	low_rate_mode = drm_kunit_display_mode_from_cea_vic(test, drm, 16);
+	KUNIT_ASSERT_NOT_NULL(test, low_rate_mode);
+
+	rate = drm_hdmi_compute_mode_clock(low_rate_mode, 8, DRM_OUTPUT_COLOR_FORMAT_RGB444);
+	KUNIT_ASSERT_LT(test, rate, HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ);
+
+	drm_modeset_acquire_init(&ctx, 0);
+
+retry_conn_enable:
+	ret = drm_kunit_helper_enable_crtc_connector(test, drm, crtc, conn,
+						     low_rate_mode, &ctx);
+	if (ret == -EDEADLK) {
+		ret = drm_modeset_backoff(&ctx);
+		if (!ret)
+			goto retry_conn_enable;
+	}
+	KUNIT_ASSERT_EQ(test, ret, 0);
+
+	conn_state = conn->state;
+	KUNIT_ASSERT_NOT_NULL(test, conn_state);
+
+	KUNIT_EXPECT_LE(test, conn_state->hdmi.tmds_char_rate,
+			HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ);
+	KUNIT_EXPECT_FALSE(test, conn_state->hdmi.scrambler_needed);
+
+	drm_modeset_drop_locks(&ctx);
+	drm_modeset_acquire_fini(&ctx);
+}
+
+/*
+ * Test that on an HDMI connector with source+sink scrambling support, driving
+ * the 4K@60 RGB preferred mode (~594 MHz TMDS, above the 340 MHz threshold),
+ * we end up with scrambler_needed set.
+ */
+static void drm_test_check_scrambler_needed_high_rate(struct kunit *test)
+{
+	struct drm_connector_hdmi_caps caps = {
+		.supported_hdmi_ver = HDMI_VERSION_2_0,
+		.supported_formats = BIT(DRM_OUTPUT_COLOR_FORMAT_RGB444),
+		.max_bpc = 8,
+	};
+	struct drm_atomic_helper_connector_hdmi_priv *priv;
+	struct drm_modeset_acquire_ctx ctx;
+	struct drm_connector_state *conn_state;
+	struct drm_display_info *info;
+	struct drm_display_mode *preferred;
+	struct drm_connector *conn;
+	struct drm_device *drm;
+	struct drm_crtc *crtc;
+	unsigned long long rate;
+	int ret;
+
+	priv = drm_kunit_helper_connector_hdmi_init_with_caps_edid_funcs(test,
+				&caps,
+				&scrambler_connector_hdmi_funcs,
+				test_edid_hdmi_4k_rgb_yuv420_dc_max_600mhz);
+	KUNIT_ASSERT_NOT_NULL(test, priv);
+
+	drm = &priv->drm;
+	crtc = priv->crtc;
+	conn = &priv->connector;
+	info = &conn->display_info;
+	KUNIT_ASSERT_TRUE(test, conn->hdmi.scrambler_supported);
+	KUNIT_ASSERT_TRUE(test, info->is_hdmi);
+	KUNIT_ASSERT_TRUE(test, info->hdmi.scdc.supported);
+	KUNIT_ASSERT_TRUE(test, info->hdmi.scdc.scrambling.supported);
+
+	preferred = find_preferred_mode(conn);
+	KUNIT_ASSERT_NOT_NULL(test, preferred);
+
+	rate = drm_hdmi_compute_mode_clock(preferred, 8, DRM_OUTPUT_COLOR_FORMAT_RGB444);
+	KUNIT_ASSERT_GT(test, rate, HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ);
+
+	drm_modeset_acquire_init(&ctx, 0);
+
+retry_conn_enable:
+	ret = drm_kunit_helper_enable_crtc_connector(test, drm, crtc, conn,
+						     preferred, &ctx);
+	if (ret == -EDEADLK) {
+		ret = drm_modeset_backoff(&ctx);
+		if (!ret)
+			goto retry_conn_enable;
+	}
+	KUNIT_ASSERT_EQ(test, ret, 0);
+
+	conn_state = conn->state;
+	KUNIT_ASSERT_NOT_NULL(test, conn_state);
+
+	KUNIT_EXPECT_GT(test, conn_state->hdmi.tmds_char_rate,
+			HDMI_1_3_TMDS_CHAR_RATE_MAX_HZ);
+	KUNIT_EXPECT_TRUE(test, conn_state->hdmi.scrambler_needed);
+
+	drm_modeset_drop_locks(&ctx);
+	drm_modeset_acquire_fini(&ctx);
+}
+
 struct color_format_test_param {
 	enum drm_connector_color_format fmt;
 	enum drm_output_color_format expected;
@@ -2505,6 +2663,8 @@ static struct kunit_case drm_atomic_helper_connector_hdmi_check_tests[] = {
 	KUNIT_CASE(drm_test_check_tmds_char_rate_rgb_8bpc),
 	KUNIT_CASE(drm_test_check_tmds_char_rate_rgb_10bpc),
 	KUNIT_CASE(drm_test_check_tmds_char_rate_rgb_12bpc),
+	KUNIT_CASE(drm_test_check_scrambler_needed_low_rate),
+	KUNIT_CASE(drm_test_check_scrambler_needed_high_rate),
 	KUNIT_CASE_PARAM(drm_test_check_hdmi_color_format,
 			 check_hdmi_color_format_gen_params),
 	KUNIT_CASE_PARAM(drm_test_check_hdmi_color_format_420_only,
Signature · 1 line
2.54.0
#99 lore raw

PATCH v8 38/39 drm/tests: edid: Fix conformity for 1080p+4K YUV420 200MHz EDID

In reply to Cristian Ciocaltea

The test EDID added by commit 58fe1d78605e ("drm/tests: hdmi: Provide EDID supporting 4K@30Hz with YUV420 only") fails 'edid-decode --check' (v1.33.0) with the following issues:

Warnings:

Block 1, CTA-861 Extension Block:
IT Video Formats are overscanned by default, but normally this should be underscanned. YCbCr 4:2:0 Video Data Block: Some YCbCr 4:2:0 timings are invalid for HDMI 2.1
(which requires an RGB timings pixel rate >= 590 MHz).
EDID:
Base EDID: Some timings are out of range of the Monitor Ranges:
Maximum Clock: 297.000 MHz (Monitor: 170.000 MHz)
CTA-861: Multiple native progressive timings are defined.

Failures:

Block 0, Base EDID:

    Vendor & Product Identification: EDID 1.3 does not support week 0xff.

Block 1, CTA-861 Extension Block:
Vendor-Specific Data Block (HDMI Forum), OUI C4-5D-D8: Max TMDS rate is > 0 and <= 340 or > 600. YCbCr 4:2:0 Capability Map Data Block: Empty Capability Map.
YCbCr 4:2:0 Video Data Block: YCbCr 4:2:0-only VIC 95 is also a regular VIC.
Missing VCDB, needed for Set Selectable RGB Quantization to avoid interop issues.
EDID:
CTA-861: The maximum HDMI TMDS clock is 200000 kHz, but one or more video timings go up to 297000 kHz.

Address them while preserving the advertised maximum resolutions, BPC and TMDS clock used by the existing KUnit tests:

- Week 0xff is not valid for EDID 1.3; set it to 0x00 so that the Model year field becomes a regular Year of Manufacture.
- The HDMI Forum VSDB Max TMDS Character Rate must be 0 when no rate above 340 MHz is supported. The HDMI VSDB still advertises 200 MHz as Max TMDS Clock.
- VIC 95 (3840x2160@30Hz) was reported as YUV420-only but was listed in both the regular Video Data Block and the YCbCr 4:2:0 Video Data Block. Drop it from the regular VDB (so it stays advertised in the 4:2:0 VDB only) and remove the now unnecessary empty YCbCr 4:2:0 Capability Map Data Block.
- Add a Video Capability Data Block advertising selectable RGB and YCC quantization range plus underscan for IT/CE formats; also set the 'IT Video Formats Underscanned' bit in the CTA-861 extension header to match.
- Bump the Display Range Limits max pixel clock from 170 MHz to 300 MHz so it covers the 297 MHz pixel rate of VIC 95.
- Drop the 'native' flag from VIC 16 in the Video Data Block so it is no longer flagged as a second native progressive timing alongside the preferred DTD.

The only remaining warning is HDMI 2.1 related and can be ignored, as it requires that any mode listed in the YCbCr 4:2:0 Video Data Block must have a corresponding RGB pixel clock >= 590 MHz.

---
 drivers/gpu/drm/tests/drm_kunit_edid.c | 65 +++++++++++++++++++++-------------
 1 file changed, 41 insertions(+), 24 deletions(-)
drivers/gpu/drm/tests/drm_kunit_edid.c +41 -24
index 673a0ea8c2ae..4dff28fff796 100644
@@ -766,22 +766,22 @@ EXPORT_SYMBOL(test_edid_hdmi_1080p_rgb_yuv_dc_max_340mhz);
  * edid-decode (hex):
  *
  * 00 ff ff ff ff ff ff 00 31 d8 34 00 00 00 00 00
- * ff 23 01 03 80 60 36 78 0f ee 91 a3 54 4c 99 26
+ * 00 23 01 03 80 60 36 78 0f ee 91 a3 54 4c 99 26
  * 0f 50 54 20 00 00 01 01 01 01 01 01 01 01 01 01
  * 01 01 01 01 01 01 02 3a 80 18 71 38 2d 40 58 2c
  * 45 00 c0 1c 32 00 00 1e 00 00 00 fc 00 54 65 73
  * 74 20 45 44 49 44 0a 20 20 20 00 00 00 fd 00 18
- * 55 18 5e 11 00 0a 20 20 20 20 20 20 00 00 00 10
- * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 bb
+ * 55 18 5e 1e 00 0a 20 20 20 20 20 20 00 00 00 10
+ * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ad
  *
- * 02 03 29 31 42 90 5f 6c 03 0c 00 10 00 78 28 20
- * 00 00 01 03 6d d8 5d c4 01 28 80 07 00 00 00 00
- * 00 00 e3 0f 00 00 e2 0e 5f 00 00 00 00 00 00 00
+ * 02 03 27 b1 41 10 6c 03 0c 00 10 00 78 28 20 00
+ * 00 01 03 6d d8 5d c4 01 00 80 07 00 00 00 00 00
+ * 00 e2 00 ca e2 0e 5f 00 00 00 00 00 00 00 00 00
  * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
- * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ca
+ * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 9a
  *
  * ----------------
  *
@@ -790,7 +790,7 @@ EXPORT_SYMBOL(test_edid_hdmi_1080p_rgb_yuv_dc_max_340mhz);
  *   Vendor & Product Identification:
  *     Manufacturer: LNX
  *     Model: 52
- *     Model year: 2025
+ *     Made in: 2025
  *   Basic Display Parameters & Features:
  *     Digital display
  *     Maximum image size: 96 cm x 54 cm
@@ -813,21 +813,21 @@ EXPORT_SYMBOL(test_edid_hdmi_1080p_rgb_yuv_dc_max_340mhz);
  *                  Vfront    4 Vsync   5 Vback   36 Vpol P
  *     Display Product Name: 'Test EDID'
  *     Display Range Limits:
- *       Monitor ranges (GTF): 24-85 Hz V, 24-94 kHz H, max dotclock 170 MHz
+ *       Monitor ranges (GTF): 24-85 Hz V, 24-94 kHz H, max dotclock 300 MHz
  *     Dummy Descriptor:
  *   Extension blocks: 1
- * Checksum: 0xbb
+ * Checksum: 0xad
  *
  * ----------------
  *
  * Block 1, CTA-861 Extension Block:
  *   Revision: 3
+ *   Underscans IT Video Formats by default
  *   Supports YCbCr 4:4:4
  *   Supports YCbCr 4:2:2
  *   Native detailed modes: 1
  *   Video Data Block:
- *     VIC  16:  1920x1080   60.000000 Hz  16:9     67.500 kHz    148.500000 MHz (native)
- *     VIC  95:  3840x2160   30.000000 Hz  16:9     67.500 kHz    297.000000 MHz
+ *     VIC  16:  1920x1080   60.000000 Hz  16:9     67.500 kHz    148.500000 MHz
  *   Vendor-Specific Data Block (HDMI), OUI 00-0C-03:
  *     Source physical address: 1.0.0.0
  *     DC_48bit
@@ -838,40 +838,57 @@ EXPORT_SYMBOL(test_edid_hdmi_1080p_rgb_yuv_dc_max_340mhz);
  *     Extended HDMI video details:
  *   Vendor-Specific Data Block (HDMI Forum), OUI C4-5D-D8:
  *     Version: 1
- *     Maximum TMDS Character Rate: 200 MHz
  *     SCDC Present
  *     Supports 16-bits/component Deep Color 4:2:0 Pixel Encoding
  *     Supports 12-bits/component Deep Color 4:2:0 Pixel Encoding
  *     Supports 10-bits/component Deep Color 4:2:0 Pixel Encoding
- *   YCbCr 4:2:0 Capability Map Data Block:
- *     Empty Capability Map
+ *     VRRmin: 0 Hz
+ *     VRRmax: 0 Hz
+ *   Video Capability Data Block:
+ *     YCbCr quantization: Selectable (via AVI YQ)
+ *     RGB quantization: Selectable (via AVI Q)
+ *     PT scan behavior: No Data
+ *     IT scan behavior: Always Underscanned
+ *     CE scan behavior: Always Underscanned
  *   YCbCr 4:2:0 Video Data Block:
  *     VIC  95:  3840x2160   30.000000 Hz  16:9     67.500 kHz    297.000000 MHz
- * Checksum: 0xca
+ * Checksum: 0x9a  Unused space in Extension Block: 88 bytes
+ *
+ * ----------------
+ *
+ * edid-decode 1.33.0
+ *
+ * Warnings:
+ *
+ * Block 1, CTA-861 Extension Block:
+ *   YCbCr 4:2:0 Video Data Block: Some YCbCr 4:2:0 timings are invalid for HDMI 2.1
+ *     (which requires an RGB timings pixel rate >= 590 MHz).
+ *
+ * EDID conformity: PASS
  */
 const unsigned char test_edid_hdmi_1080p_rgb_yuv_4k_yuv420_dc_max_200mhz[] = {
 	0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x31, 0xd8, 0x34, 0x00,
-	0x00, 0x00, 0x00, 0x00, 0xff, 0x23, 0x01, 0x03, 0x80, 0x60, 0x36, 0x78,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x01, 0x03, 0x80, 0x60, 0x36, 0x78,
 	0x0f, 0xee, 0x91, 0xa3, 0x54, 0x4c, 0x99, 0x26, 0x0f, 0x50, 0x54, 0x20,
 	0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
 	0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38,
 	0x2d, 0x40, 0x58, 0x2c, 0x45, 0x00, 0xc0, 0x1c, 0x32, 0x00, 0x00, 0x1e,
 	0x00, 0x00, 0x00, 0xfc, 0x00, 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x44,
 	0x49, 0x44, 0x0a, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18,
-	0x55, 0x18, 0x5e, 0x11, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+	0x55, 0x18, 0x5e, 0x1e, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
 	0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xbb, 0x02, 0x03, 0x29, 0x31,
-	0x42, 0x90, 0x5f, 0x6c, 0x03, 0x0c, 0x00, 0x10, 0x00, 0x78, 0x28, 0x20,
-	0x00, 0x00, 0x01, 0x03, 0x6d, 0xd8, 0x5d, 0xc4, 0x01, 0x28, 0x80, 0x07,
-	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x0f, 0x00, 0x00, 0xe2, 0x0e,
-	0x5f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xad, 0x02, 0x03, 0x27, 0xb1,
+	0x41, 0x10, 0x6c, 0x03, 0x0c, 0x00, 0x10, 0x00, 0x78, 0x28, 0x20, 0x00,
+	0x00, 0x01, 0x03, 0x6d, 0xd8, 0x5d, 0xc4, 0x01, 0x00, 0x80, 0x07, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x00, 0xca, 0xe2, 0x0e, 0x5f, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-	0x00, 0x00, 0x00, 0xca
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x9a,
 };
 EXPORT_SYMBOL(test_edid_hdmi_1080p_rgb_yuv_4k_yuv420_dc_max_200mhz);
 
Signature · 1 line
2.54.0
#100 lore raw

PATCH v8 39/39 drm/tests: edid: Fix conformity for 4K RGB/YUV 340MHz EDID

In reply to Cristian Ciocaltea

The test EDID added by commit 54a5f1c4d5f8 ("drm/tests: hdmi: Provide EDID supporting 4K@30Hz with RGB/YUV") fails 'edid-decode --check' (v1.33.0) with the following issues:

Warnings:

Block 1, CTA-861 Extension Block:
IT Video Formats are overscanned by default, but normally this should be underscanned. YCbCr 4:2:0 Capability Map Data Block: Some YCbCr 4:2:0 timings are invalid for HDMI 2.1
(which requires an RGB timings pixel rate >= 590 MHz).

Failures:

Block 0, Base EDID:

    Vendor & Product Identification: EDID 1.3 does not support week 0xff.
    Detailed Timing Descriptor #1: Mismatch of image size 1600x900 mm vs display size 960x540 mm.
  Block 1, CTA-861 Extension Block:
    Vendor-Specific Data Block (HDMI Forum), OUI C4-5D-D8: Max TMDS rate is > 0 and <= 340 or > 600.
    YCbCr 4:2:0 Video Data Block: This Data Block is empty.
    Missing VCDB, needed for Set Selectable RGB Quantization to avoid interop issues.
  EDID:
    Base EDID: The DTD max image size is 1600x900mm, which is larger than the display size 960.0x540.0mm.

Address them while preserving the advertised maximum resolution, BPC and TMDS clock used by the existing KUnit tests:

- Week 0xff is not valid for EDID 1.3; set it to 0x00 so that the Model year field becomes a regular Year of Manufacture.
- Align the DTD image size with the Basic Display Parameters maximum image size (96 cm x 54 cm).
- The HDMI Forum VSDB Max TMDS Character Rate must be 0 when no rate above 340 MHz is supported. The HDMI VSDB still advertises 340 MHz as Max TMDS Clock.
- Drop the empty YCbCr 4:2:0 Video Data Block. VIC 95 (3840x2160@30Hz) remains advertised as YUV420-capable via the YCbCr 4:2:0 Capability Map Data Block, which references the corresponding entry in the regular Video Data Block.
- Add a Video Capability Data Block advertising selectable RGB and YCC quantization range plus underscan for IT/CE formats; also set the 'IT Video Formats Underscanned' bit in the CTA-861 extension header to match.

The only remaining warning is HDMI 2.1 related and can be ignored, as it requires that any mode listed in the YCbCr 4:2:0 Video Data Block must have a corresponding RGB pixel clock >= 590 MHz.

---
 drivers/gpu/drm/tests/drm_kunit_edid.c | 57 ++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 19 deletions(-)
drivers/gpu/drm/tests/drm_kunit_edid.c +38 -19
index 4dff28fff796..a6c5e8d6077a 100644
@@ -900,22 +900,22 @@ EXPORT_SYMBOL(test_edid_hdmi_1080p_rgb_yuv_4k_yuv420_dc_max_200mhz);
  * edid-decode (hex):
  *
  * 00 ff ff ff ff ff ff 00 31 d8 34 00 00 00 00 00
- * ff 23 01 03 80 60 36 78 0f ee 91 a3 54 4c 99 26
+ * 00 23 01 03 80 60 36 78 0f ee 91 a3 54 4c 99 26
  * 0f 50 54 20 00 00 01 01 01 01 01 01 01 01 01 01
  * 01 01 01 01 01 01 04 74 00 30 f2 70 5a 80 b0 58
- * 8a 00 40 84 63 00 00 1e 00 00 00 fc 00 54 65 73
+ * 8a 00 c0 1c 32 00 00 1e 00 00 00 fc 00 54 65 73
  * 74 20 45 44 49 44 0a 20 20 20 00 00 00 fd 00 18
  * 55 18 5e 22 00 0a 20 20 20 20 20 20 00 00 00 10
- * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ce
+ * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 e6
  *
- * 02 03 27 31 41 5f 6c 03 0c 00 10 00 78 44 20 00
- * 00 01 03 6d d8 5d c4 01 44 80 07 00 00 00 00 00
- * 00 e3 0f 01 00 e1 0e 00 00 00 00 00 00 00 00 00
+ * 02 03 28 b1 41 5f 6c 03 0c 00 10 00 78 44 20 00
+ * 00 01 03 6d d8 5d c4 01 00 80 07 00 00 00 00 00
+ * 00 e2 00 ca e3 0f 01 00 00 00 00 00 00 00 00 00
  * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
- * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 84
+ * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 8a
  *
  * ----------------
  *
@@ -924,7 +924,7 @@ EXPORT_SYMBOL(test_edid_hdmi_1080p_rgb_yuv_4k_yuv420_dc_max_200mhz);
  *   Vendor & Product Identification:
  *     Manufacturer: LNX
  *     Model: 52
- *     Model year: 2025
+ *     Made in: 2025
  *   Basic Display Parameters & Features:
  *     Digital display
  *     Maximum image size: 96 cm x 54 cm
@@ -942,7 +942,7 @@ EXPORT_SYMBOL(test_edid_hdmi_1080p_rgb_yuv_4k_yuv420_dc_max_200mhz);
  *     DMT 0x04:   640x480    59.940476 Hz   4:3     31.469 kHz     25.175000 MHz
  *   Standard Timings: none
  *   Detailed Timing Descriptors:
- *     DTD 1:  3840x2160   30.000000 Hz  16:9     67.500 kHz    297.000000 MHz (1600 mm x 900 mm)
+ *     DTD 1:  3840x2160   30.000000 Hz  16:9     67.500 kHz    297.000000 MHz (960 mm x 540 mm)
  *                  Hfront  176 Hsync  88 Hback  296 Hpol P
  *                  Vfront    8 Vsync  10 Vback   72 Vpol P
  *     Display Product Name: 'Test EDID'
@@ -950,12 +950,13 @@ EXPORT_SYMBOL(test_edid_hdmi_1080p_rgb_yuv_4k_yuv420_dc_max_200mhz);
  *       Monitor ranges (GTF): 24-85 Hz V, 24-94 kHz H, max dotclock 340 MHz
  *     Dummy Descriptor:
  *   Extension blocks: 1
- * Checksum: 0xce
+ * Checksum: 0xe6
  *
  * ----------------
  *
  * Block 1, CTA-861 Extension Block:
  *   Revision: 3
+ *   Underscans IT Video Formats by default
  *   Supports YCbCr 4:4:4
  *   Supports YCbCr 4:2:2
  *   Native detailed modes: 1
@@ -971,31 +972,49 @@ EXPORT_SYMBOL(test_edid_hdmi_1080p_rgb_yuv_4k_yuv420_dc_max_200mhz);
  *     Extended HDMI video details:
  *   Vendor-Specific Data Block (HDMI Forum), OUI C4-5D-D8:
  *     Version: 1
- *     Maximum TMDS Character Rate: 340 MHz
  *     SCDC Present
  *     Supports 16-bits/component Deep Color 4:2:0 Pixel Encoding
  *     Supports 12-bits/component Deep Color 4:2:0 Pixel Encoding
  *     Supports 10-bits/component Deep Color 4:2:0 Pixel Encoding
+ *     VRRmin: 0 Hz
+ *     VRRmax: 0 Hz
+ *   Video Capability Data Block:
+ *     YCbCr quantization: Selectable (via AVI YQ)
+ *     RGB quantization: Selectable (via AVI Q)
+ *     PT scan behavior: No Data
+ *     IT scan behavior: Always Underscanned
+ *     CE scan behavior: Always Underscanned
  *   YCbCr 4:2:0 Capability Map Data Block:
  *     VIC  95:  3840x2160   30.000000 Hz  16:9     67.500 kHz    297.000000 MHz
- *   YCbCr 4:2:0 Video Data Block:
- * Checksum: 0x84
+ * Checksum: 0x8a  Unused space in Extension Block: 87 bytes
+ *
+ * ----------------
+ *
+ * edid-decode 1.33.0
+ *
+ * Warnings:
+ *
+ * Block 1, CTA-861 Extension Block:
+ *   YCbCr 4:2:0 Capability Map Data Block: Some YCbCr 4:2:0 timings are invalid for HDMI 2.1
+ *     (which requires an RGB timings pixel rate >= 590 MHz).
+ *
+ * EDID conformity: PASS
  */
 const unsigned char test_edid_hdmi_4k_rgb_yuv420_dc_max_340mhz[] = {
 	0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x31, 0xd8, 0x34, 0x00,
-	0x00, 0x00, 0x00, 0x00, 0xff, 0x23, 0x01, 0x03, 0x80, 0x60, 0x36, 0x78,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x01, 0x03, 0x80, 0x60, 0x36, 0x78,
 	0x0f, 0xee, 0x91, 0xa3, 0x54, 0x4c, 0x99, 0x26, 0x0f, 0x50, 0x54, 0x20,
 	0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
 	0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x04, 0x74, 0x00, 0x30, 0xf2, 0x70,
-	0x5a, 0x80, 0xb0, 0x58, 0x8a, 0x00, 0x40, 0x84, 0x63, 0x00, 0x00, 0x1e,
+	0x5a, 0x80, 0xb0, 0x58, 0x8a, 0x00, 0xc0, 0x1c, 0x32, 0x00, 0x00, 0x1e,
 	0x00, 0x00, 0x00, 0xfc, 0x00, 0x54, 0x65, 0x73, 0x74, 0x20, 0x45, 0x44,
 	0x49, 0x44, 0x0a, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18,
 	0x55, 0x18, 0x5e, 0x22, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
 	0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xce, 0x02, 0x03, 0x27, 0x31,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe6, 0x02, 0x03, 0x28, 0xb1,
 	0x41, 0x5f, 0x6c, 0x03, 0x0c, 0x00, 0x10, 0x00, 0x78, 0x44, 0x20, 0x00,
-	0x00, 0x01, 0x03, 0x6d, 0xd8, 0x5d, 0xc4, 0x01, 0x44, 0x80, 0x07, 0x00,
-	0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0x0f, 0x01, 0x00, 0xe1, 0x0e, 0x00,
+	0x00, 0x01, 0x03, 0x6d, 0xd8, 0x5d, 0xc4, 0x01, 0x00, 0x80, 0x07, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0xe2, 0x00, 0xca, 0xe3, 0x0f, 0x01, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -1003,7 +1022,7 @@ const unsigned char test_edid_hdmi_4k_rgb_yuv420_dc_max_340mhz[] = {
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-	0x00, 0x00, 0x00, 0x84
+	0x00, 0x00, 0x00, 0x8a,
 };
 EXPORT_SYMBOL(test_edid_hdmi_4k_rgb_yuv420_dc_max_340mhz);
 
Signature · 1 line
2.54.0
#101 lore raw
In reply to Cristian Ciocaltea

Hi,

I've just realized I missed updating the part of the cover letter that describes the patch structure. Please find the corrected content below.

Regards,
Cristian

Quoted 3 lines · Cristian Ciocaltea

Enable HDMI 2.0 display modes (e.g. 4K@60Hz) on the Synopsys DW HDMI QP TX controller, as found in Rockchip RK3576 & RK3588 SoCs, by adding SCDC management for high TMDS clock ratio and scrambling.

Since SCDC state is lost on sink disconnects, the bridge driver needs to trigger a CRTC reset during connector detection. To support this, the series first introduces the HDMI version enum and the caps-based HDMI connector init helper (patches 1-3), then builds the connector and bridge scrambling infrastructure on top of it - the connector scrambler support, the scdc-helper additions (connector-prefixed debug macro and SCDC version helper), and the HDMI scrambling management helpers including SCDC source-version advertisement (patches 4-8).

It then wires this up through the hdmi-state-helper and bridge connector
layers: fallback TMDS rate validation, hotplug SCDC state sync and the scrambling requirement (patches 9-11), a bridge cleanup and the new source-side scrambling bridge ops (patches 12-13), the switch to a cached-status, atomic-aware .detect_ctx() connector helper (patches 14-15), and finally hooking up the HDMI 2.0 scrambler callbacks (patch 16).

The SCDC scrambling feature itself is implemented in the DW HDMI QP bridge driver, alongside i2c error-message rate limiting, .enable_hpd()/.disable_hpd() PHY ops and a dw_hdmi_qp_hpd_notify() helper (patches 17-20).

Patches 21-28 cover the Rockchip platform driver and HPD handling: minor cleanups (newlines in dev_err_probe(), consistent local dev variable, dropping an unnecessary include), deferring HPD IRQ enable until after connector setup, masking the RK3576 HPD IRQ in io_init, implementing the .{enable|disable}_hpd() PHY ops, switching HPD reports to dw_hdmi_qp_hpd_notify() to restrict events to the affected connector, and dropping the now-unused .setup_hpd() PHY op.

Patches 29-31 convert vc4 HDMI to the common infrastructure as a proof of reuse: adopting the shared TMDS char rate constants, switching to drm_hdmi_mode_needs_scrambling(), and replacing the driver-local scrambling implementation with the common SCDC scrambling helpers.

Patches 32-39 add KUnit tests: HDMI caps-based init coverage and source-side scrambler validation for the connector, conversion of hdmi_state_helper to drmm_connector_hdmi_init_with_caps() with max_tmds_char_rate fallback tests, a new 4K@60Hz 600MHz TMDS EDID, source-side scrambling decision coverage, and conformity fixes for the existing 1080p+4K YUV420 200MHz and 4K RGB/YUV 340MHz test EDID blobs.

Quoted 73 lines

This has been tested on the following boards:

* Radxa ROCK 5B (RK3588)
* Radxa ROCK 4D (RK3576)
* Raspberry Pi 5 Model B Rev 1.1 (BCM2712 D0)

Note that commit d87773de9efe1 ("clocksource/drivers/arm_arch_timer:
Default to EL2 virtual timer when running VHE"), introduced in v7.2-rc1, causes Raspberry Pi 5 to hang during boot. Reverting the commit restores normal boot. This issue has already been reported in [1]; alternatively, the workaround proposed in [2] can be applied.

Regards,
Cristian

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

---
Changes in v8:
- Added an enum hdmi_version under video/hdmi to describe the HDMI
specification version a source/sink supports (new patch 1)
- Introduced HDMI connector capabilities API and reworked the
infrastructure patches on top of it: drmm_connector_hdmi_init() now
takes a drm_connector_hdmi_caps struct that carries supported_formats,
max_bpc, supported_hdmi_ver and max_tmds_char_rate (new patches 2-3)
- Moved all the new SCDC helpers covering both source and sink to display/drm_hdmi_helper.c
- Renamed drm_scdc_{start,stop}_scrambling() to drm_connector_hdmi_{enable,disable}_scrambling() and added a
connector-state argument so the scrambler_needed flag is checked
centrally instead of in every driver
- Renamed drm_scdc_sync_status() to drm_connector_hdmi_sync_scdc(),
aligned its lifecycle with vc4_hdmi_reset_link(), and removed the
internal drm_scdc_reset_crtc() helper; it now also gates on CRTC state
and an in-flight commit (Maxime)
- Changed the prototype of drm_atomic_helper_connector_hdmi_hotplug() to
take an acquire context and an int return, instead of adding a new
_ctx variant (Maxime)
- Added drm_hdmi_mode_needs_scrambling() to centralise the above-340 MHz
decision (new patch 7)
- Made SCDC source version negotiation optional and moved it to a
dedicated patch "drm/display: hdmi: Advertise SCDC source version when scrambling" (new patch 8), backed by a new
drm_scdc_set_source_version() helper in "drm/display: scdc-helper: Add
helper to set SCDC version information" (new patch 6)
- Added a fallback TMDS rate validation patch using the connector-level max_tmds_char_rate when the driver provides no .tmds_char_rate_valid()
hook (new patch 9)
- Split scrambler_needed flag handling into its own hdmi-state-helper
dedicate change (new patch 11)
- VC4:
* Replaced vc4_hdmi_mode_needs_scrambling() with drm_hdmi_mode_needs_scrambling() (new patch 30)
* Restored drm_dev_{enter,exit}() pairing around the converted
scrambling paths
* Removed now unused output_{bpc,color_format} fields from vc4_hdmi as
part of the SCDC conversion
- KUnit:
* Covered the caps-based connector init path: NULL caps, inferred max_tmds_char_rate per supported_hdmi_ver, and override validation
(new patch 32)
* Switched drm_hdmi_state_helper_test to the caps-based init helper
and exposed it through drm_kunit_helper_connector_hdmi_init_with_caps_edid_funcs() (new
patch 34)
* Added max_tmds_char_rate fallback coverage in
drm_hdmi_state_helper_test (new patch 35)
- Rebased onto latest drm-misc-next and dropped the already applied "drm/fb-helper: Remove unused local variable in hotplug_event()" patch
- Link to v7: https://patch.msgid.link/[email protected]

[...]

Tested-by on the v8 series
#102 lore raw
In reply to Cristian Ciocaltea
Quoted 35 lines

Enable HDMI 2.0 display modes (e.g. 4K@60Hz) on the Synopsys DW HDMI QP TX controller, as found in Rockchip RK3576 & RK3588 SoCs, by adding SCDC management for high TMDS clock ratio and scrambling.

Since SCDC state is lost on sink disconnects, the bridge driver needs to trigger a CRTC reset during connector detection. To support this, the series introduces the connector and bridge scrambling infrastructure (patches 1-8), wires it up through the bridge connector layer with an atomic-aware detect_ctx hook (patches 9-11), then implements the SCDC scrambling feature in the DW HDMI QP bridge driver (patches 12-15).

Patches 16-18 are minor cleanups in the Rockchip platform driver. Patches 19-23 improve HPD handling by deferring IRQ registration until the connector is fully initialized, adding .enable_hpd()/.disable_hpd() PHY ops, and restricting HPD events to the affected connector.

Patches 24-25 convert vc4 HDMI to the common SCDC scrambling helpers as a proof of reuse, replacing the driver-local scrambling implementation.

Patches 26-30 add KUnit tests: connector scrambler validation, a new 4K@60Hz 600MHz EDID, hdmi_state_helper scrambling tests, and EDID conformity fixes for some of the existing test blobs.

This has been tested on the following boards:

* Radxa ROCK 5B (RK3588)
* Radxa ROCK 4D (RK3576)
* Raspberry Pi 5 Model B Rev 1.1 (BCM2712 D0)

Note that commit d87773de9efe1 ("clocksource/drivers/arm_arch_timer:
Default to EL2 virtual timer when running VHE"), introduced in v7.2-rc1, causes Raspberry Pi 5 to hang during boot. Reverting the commit restores normal boot. This issue has already been reported in [1]; alternatively, the workaround proposed in [2] can be applied.

Quoted 7 lines

Regards,
Cristian

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Tested on an Orangepi 5+ board (rk3588), with a 4k60 tv and a 1440p100 monitor.

To all applicable patches:

Kind regards,
Maud

#103 lore raw
Quoted 41 lines · Maud Spierings
Quoted 41 lines

Enable HDMI 2.0 display modes (e.g. 4K@60Hz) on the Synopsys DW HDMI QP TX controller, as found in Rockchip RK3576 & RK3588 SoCs, by adding SCDC management for high TMDS clock ratio and scrambling.

Since SCDC state is lost on sink disconnects, the bridge driver needs to trigger a CRTC reset during connector detection. To support this, the series introduces the connector and bridge scrambling infrastructure (patches 1-8), wires it up through the bridge connector layer with an atomic-aware detect_ctx hook (patches 9-11), then implements the SCDC scrambling feature in the DW HDMI QP bridge driver (patches 12-15).

Patches 16-18 are minor cleanups in the Rockchip platform driver. Patches 19-23 improve HPD handling by deferring IRQ registration until the connector is fully initialized, adding .enable_hpd()/.disable_hpd() PHY ops, and restricting HPD events to the affected connector.

Patches 24-25 convert vc4 HDMI to the common SCDC scrambling helpers as a proof of reuse, replacing the driver-local scrambling implementation.

Patches 26-30 add KUnit tests: connector scrambler validation, a new 4K@60Hz 600MHz EDID, hdmi_state_helper scrambling tests, and EDID conformity fixes for some of the existing test blobs.

This has been tested on the following boards:

* Radxa ROCK 5B (RK3588)
* Radxa ROCK 4D (RK3576)
* Raspberry Pi 5 Model B Rev 1.1 (BCM2712 D0)

Note that commit d87773de9efe1 ("clocksource/drivers/arm_arch_timer:
Default to EL2 virtual timer when running VHE"), introduced in v7.2-rc1, causes Raspberry Pi 5 to hang during boot. Reverting the commit restores normal boot. This issue has already been reported in [1]; alternatively, the workaround proposed in [2] can be applied.

Regards,
Cristian

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Quoted 7 lines
Quoted 1 line

Tested on an Orangepi 5+ board (rk3588), with a 4k60 tv and a 1440p100 monitor.

To all applicable patches:

Thanks for checking this out!

b4 will apply the tag to all patches, but I'll manually drop it from the VC4 and KUnit related patches, and probably some others that aren't really testable as-is.

Cristian