Skip to contentSkip to conversation

drm/edid: Infoframe cleanups and fixes

PATCH In review Ville Syrjala 5 participants 40 messages Nov 13, 2017 – Nov 24, 2017

Subsystems (18)
lore
Share & tools
lore
#0 lore raw

cover drm/edid: Infoframe cleanups and fixes

From: Ville Syrjälä <[email protected]>

This series tries to fix some issues with HDMI infoframes. In particular we can currently send a bogus picture aspect ratio in the infoframe. I included stuff to to make the infoframe unpakc more robust, evne though we don't (yet) use it in drm. Additionally I included my earlier "empty" HDMI infoframe support.

I have further work piled up on top which allows us to precompuet the infoframes during the atomic check phase. But the series would have become rather big, so I wanted to post these fixes and cleanups first.

Entire series (with the infoframe precompute) is available here:
git://github.com/vsyrjala/linux.git infoframe_precompute

Cc Akashdeep Sharma <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Hans Verkuil <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Sean Paul <[email protected]>
Cc Shashank Sharma <[email protected]>
Cc Thierry Reding <[email protected]>

Ville Syrjälä (10):
video/hdmi: Allow "empty" HDMI infoframes
drm/edid: Allow HDMI infoframe without VIC or S3D drm/modes: Introduce drm_mode_match()
drm/edid: Use drm_mode_match_no_clocks_no_stereo() for consistentcy drm/edid: Fix up edid_cea_modes[] formatting
drm/edid: Fix cea mode aspect ratio handling
drm/edid: Don't send bogus aspect ratios in AVI infoframes video/hdmi: Reject illegal picture aspect ratios video/hdmi: Constify 'buffer' to the unpack functions video/hdmi: Pass buffer size to infoframe unpack functions

 drivers/gpu/drm/bridge/sil-sii8620.c      |   3 +-
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c |   4 +-
 drivers/gpu/drm/drm_edid.c                | 159 +++++++++++++++++++-----------
 drivers/gpu/drm/drm_modes.c               | 134 +++++++++++++++++++------
 drivers/gpu/drm/exynos/exynos_hdmi.c      |   2 +-
 drivers/gpu/drm/i915/intel_hdmi.c         |  14 +--
 drivers/gpu/drm/mediatek/mtk_hdmi.c       |   3 +-
 drivers/gpu/drm/nouveau/nv50_display.c    |   3 +-
 drivers/gpu/drm/rockchip/inno_hdmi.c      |   1 +
 drivers/gpu/drm/sti/sti_hdmi.c            |   4 +-
 drivers/gpu/drm/zte/zx_hdmi.c             |   1 +
 drivers/media/i2c/adv7511.c               |   2 +-
 drivers/media/i2c/adv7604.c               |   2 +-
 drivers/media/i2c/adv7842.c               |   2 +-
 drivers/media/i2c/tc358743.c              |   2 +-
 drivers/video/hdmi.c                      | 118 ++++++++++++++--------
 include/drm/drm_connector.h               |   5 +
 include/drm/drm_edid.h                    |   1 +
 include/drm/drm_modes.h                   |   9 ++
 include/linux/hdmi.h                      |   3 +-
 20 files changed, 326 insertions(+), 146 deletions(-)
Signature · 1 line
2.13.6
#1 lore raw

PATCH 1/10 video/hdmi: Allow "empty" HDMI infoframes

From: Ville Syrjälä <[email protected]>

HDMI 2.0 Appendix F suggest that we should keep sending the infoframe when switching from 3D to 2D mode, even if the infoframe isn't strictly necessary (ie. not needed to transmit the VIC or stereo information). This is a workaround against some sinks that fail to realize that they should switch from 3D to 2D mode when the source stop transmitting the infoframe.

v2: Handle unpack() as well
Pull the length calculation into a helper

---
 drivers/video/hdmi.c | 51 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 20 deletions(-)
drivers/video/hdmi.c +31 -20
index 1cf907ecded4..111a0ab6280a 100644
@@ -321,6 +321,17 @@ int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame)
 }
 EXPORT_SYMBOL(hdmi_vendor_infoframe_init);
 
+static int hdmi_vendor_infoframe_length(const struct hdmi_vendor_infoframe *frame)
+{
+	/* for side by side (half) we also need to provide 3D_Ext_Data */
+	if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
+		return 6;
+	else if (frame->vic != 0 || frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
+		return 5;
+	else
+		return 4;
+}
+
 /**
  * hdmi_vendor_infoframe_pack() - write a HDMI vendor infoframe to binary buffer
  * @frame: HDMI infoframe
@@ -341,19 +352,11 @@ ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
 	u8 *ptr = buffer;
 	size_t length;
 
-	/* empty info frame */
-	if (frame->vic == 0 && frame->s3d_struct == HDMI_3D_STRUCTURE_INVALID)
-		return -EINVAL;
-
 	/* only one of those can be supplied */
 	if (frame->vic != 0 && frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
 		return -EINVAL;
 
-	/* for side by side (half) we also need to provide 3D_Ext_Data */
-	if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
-		frame->length = 6;
-	else
-		frame->length = 5;
+	frame->length = hdmi_vendor_infoframe_length(frame);
 
 	length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
 
@@ -372,14 +375,16 @@ ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
 	ptr[5] = 0x0c;
 	ptr[6] = 0x00;
 
-	if (frame->vic) {
-		ptr[7] = 0x1 << 5;	/* video format */
-		ptr[8] = frame->vic;
-	} else {
+	if (frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID) {
 		ptr[7] = 0x2 << 5;	/* video format */
 		ptr[8] = (frame->s3d_struct & 0xf) << 4;
 		if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
 			ptr[9] = (frame->s3d_ext_data & 0xf) << 4;
+	} else if (frame->vic) {
+		ptr[7] = 0x1 << 5;	/* video format */
+		ptr[8] = frame->vic;
+	} else {
+		ptr[7] = 0x0 << 5;	/* video format */
 	}
 
 	hdmi_infoframe_set_checksum(buffer, length);
@@ -1165,7 +1170,7 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 
 	if (ptr[0] != HDMI_INFOFRAME_TYPE_VENDOR ||
 	    ptr[1] != 1 ||
-	    (ptr[2] != 5 && ptr[2] != 6))
+	    (ptr[2] != 4 && ptr[2] != 5 && ptr[2] != 6))
 		return -EINVAL;
 
 	length = ptr[2];
@@ -1193,16 +1198,22 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 
 	hvf->length = length;
 
-	if (hdmi_video_format == 0x1) {
-		hvf->vic = ptr[4];
-	} else if (hdmi_video_format == 0x2) {
+	if (hdmi_video_format == 0x2) {
+		if (length != 5 && length != 6)
+			return -EINVAL;
 		hvf->s3d_struct = ptr[4] >> 4;
 		if (hvf->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF) {
-			if (length == 6)
-				hvf->s3d_ext_data = ptr[5] >> 4;
-			else
+			if (length != 6)
 				return -EINVAL;
+			hvf->s3d_ext_data = ptr[5] >> 4;
 		}
+	} else if (hdmi_video_format == 0x1) {
+		if (length != 5)
+			return -EINVAL;
+		hvf->vic = ptr[4];
+	} else {
+		if (length != 4)
+			return -EINVAL;
 	}
 
 	return 0;
Signature · 6 lines
2.13.6

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

PATCH 2/10 drm/edid: Allow HDMI infoframe without VIC or S3D

In reply to Ville Syrjala

From: Ville Syrjälä <[email protected]>

Appedix F of HDMI 2.0 says that some HDMI sink may fail to switch from 3D to 2D mode in a timely fashion if the source simply stops sending the HDMI infoframe. The suggested workaround is to keep sending the infoframe even when strictly not necessary (ie. no VIC and no S3D). HDMI 1.4 does allow for this behaviour, stating that sending the infoframe is optional in this case.

The infoframe was first specified in HDMI 1.4, so in theory sinks predating that may not appreciate us sending an uknown infoframe their way. To avoid regressions let's try to determine if the sink supports the infoframe or not. Unfortunately there's no direct way to do that, so instead we'll just check if we managed to parse any HDMI 1.4 4k or stereo modes from the EDID, and if so we assume the sink will accept the infoframe. Also if the EDID contains the HDMI 2.0 HDMI Forum VSDB we can assume the sink is prepared to receive the infoframe.

v2: Fix the getting has_hdmi_infoframe from display_info
Always fail constructing the infoframe if the display possibly can't handle it

Cc Shashank Sharma <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
 drivers/gpu/drm/bridge/sil-sii8620.c      |  3 ++-
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c |  4 +++-
 drivers/gpu/drm/drm_edid.c                | 34 +++++++++++++++++++++++++------
 drivers/gpu/drm/exynos/exynos_hdmi.c      |  2 +-
 drivers/gpu/drm/i915/intel_hdmi.c         | 14 +++++++------
 drivers/gpu/drm/mediatek/mtk_hdmi.c       |  3 ++-
 drivers/gpu/drm/nouveau/nv50_display.c    |  3 ++-
 drivers/gpu/drm/rockchip/inno_hdmi.c      |  1 +
 drivers/gpu/drm/sti/sti_hdmi.c            |  4 +++-
 drivers/gpu/drm/zte/zx_hdmi.c             |  1 +
 include/drm/drm_connector.h               |  5 +++++
 include/drm/drm_edid.h                    |  1 +
 12 files changed, 57 insertions(+), 18 deletions(-)
drivers/gpu/drm/bridge/sil-sii8620.c +2 -1
index b7eb704d0a8a..4417276ba02e 100644
@@ -2220,8 +2220,9 @@ static bool sii8620_mode_fixup(struct drm_bridge *bridge,
 			union hdmi_infoframe frm;
 			u8 mhl_vic[] = { 0, 95, 94, 93, 98 };
 
+			/* FIXME: We need the connector here */
 			drm_hdmi_vendor_infoframe_from_display_mode(
-				&frm.vendor.hdmi, adjusted_mode);
+				&frm.vendor.hdmi, NULL, adjusted_mode);
 			vic = frm.vendor.hdmi.vic;
 			if (vic >= ARRAY_SIZE(mhl_vic))
 				vic = 0;
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +3 -1
index a64ce7112288..b172139502d6 100644
@@ -1437,7 +1437,9 @@ static void hdmi_config_vendor_specific_infoframe(struct dw_hdmi *hdmi,
 	u8 buffer[10];
 	ssize_t err;
 
-	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
+	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame,
+							  &hdmi->connector,
+							  mode);
 	if (err < 0)
 		/*
 		 * Going into that statement does not means vendor infoframe
drivers/gpu/drm/drm_edid.c +28 -6
index 749d07a01772..9ada0ccf50df 100644
@@ -3393,6 +3393,7 @@ static int
 do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
 		   const u8 *video_db, u8 video_len)
 {
+	struct drm_display_info *info = &connector->display_info;
 	int modes = 0, offset = 0, i, multi_present = 0, multi_len;
 	u8 vic_len, hdmi_3d_len = 0;
 	u16 mask;
@@ -3520,6 +3521,8 @@ do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
 	}
 
 out:
+	if (modes > 0)
+		info->has_hdmi_infoframe = true;
 	return modes;
 }
 
@@ -4243,6 +4246,8 @@ static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
 	struct drm_display_info *display = &connector->display_info;
 	struct drm_hdmi_info *hdmi = &display->hdmi;
 
+	display->has_hdmi_infoframe = true;
+
 	if (hf_vsdb[6] & 0x80) {
 		hdmi->scdc.supported = true;
 		if (hf_vsdb[6] & 0x40)
@@ -4416,6 +4421,7 @@ static void drm_add_display_info(struct drm_connector *connector,
 	info->cea_rev = 0;
 	info->max_tmds_clock = 0;
 	info->dvi_dual = false;
+	info->has_hdmi_infoframe = false;
 
 	if (edid->revision < 3)
 		return;
@@ -4903,6 +4909,7 @@ s3d_structure_from_display_mode(const struct drm_display_mode *mode)
  * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
  * data from a DRM display mode
  * @frame: HDMI vendor infoframe
+ * @connector: the connector
  * @mode: DRM display mode
  *
  * Note that there's is a need to send HDMI vendor infoframes only when using a
@@ -4913,8 +4920,15 @@ s3d_structure_from_display_mode(const struct drm_display_mode *mode)
  */
 int
 drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+					    struct drm_connector *connector,
 					    const struct drm_display_mode *mode)
 {
+	/*
+	 * FIXME: sil-sii8620 doesn't have a connector around when
+	 * we need one, so we have to be prepared for a NULL connector.
+	 */
+	bool has_hdmi_infoframe = connector ?
+		connector->display_info.has_hdmi_infoframe : false;
 	int err;
 	u32 s3d_flags;
 	u8 vic;
@@ -4922,11 +4936,21 @@ drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
 	if (!frame || !mode)
 		return -EINVAL;
 
+	if (!has_hdmi_infoframe)
+		return -EINVAL;
+
 	vic = drm_match_hdmi_mode(mode);
 	s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
 
-	if (!vic && !s3d_flags)
-		return -EINVAL;
+	/*
+	 * Even if it's not absolutely necessary to send the infoframe
+	 * (ie.vic==0 and s3d_struct==0) we will still send it if we
+	 * know that the sink can handle it. This is based on a
+	 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
+	 * have trouble realizing that they shuld switch from 3D to 2D
+	 * mode if the source simply stops sending the infoframe when
+	 * it wants to switch from 3D to 2D.
+	 */
 
 	if (vic && s3d_flags)
 		return -EINVAL;
@@ -4935,10 +4959,8 @@ drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
 	if (err < 0)
 		return err;
 
-	if (vic)
-		frame->vic = vic;
-	else
-		frame->s3d_struct = s3d_structure_from_display_mode(mode);
+	frame->vic = vic;
+	frame->s3d_struct = s3d_structure_from_display_mode(mode);
 
 	return 0;
 }
drivers/gpu/drm/exynos/exynos_hdmi.c +1 -1
index 0109ff40b1db..812b2773ed69 100644
@@ -795,7 +795,7 @@ static void hdmi_reg_infoframes(struct hdmi_context *hdata)
 	}
 
 	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frm.vendor.hdmi,
-			&hdata->current_mode);
+			&hdata->connector, &hdata->current_mode);
 	if (!ret)
 		ret = hdmi_vendor_infoframe_pack(&frm.vendor.hdmi, buf,
 				sizeof(buf));
drivers/gpu/drm/i915/intel_hdmi.c +8 -6
index 2d95db64cdf2..2ccba4ccf7ad 100644
@@ -512,12 +512,14 @@ static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder,
 
 static void
 intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
-			      const struct intel_crtc_state *crtc_state)
+			      const struct intel_crtc_state *crtc_state,
+			      const struct drm_connector_state *conn_state)
 {
 	union hdmi_infoframe frame;
 	int ret;
 
 	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							  conn_state->connector,
 							  &crtc_state->base.adjusted_mode);
 	if (ret < 0)
 		return;
@@ -584,7 +586,7 @@ static void g4x_set_infoframes(struct drm_encoder *encoder,
 
 	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
 	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
 }
 
 static bool hdmi_sink_is_deep_color(const struct drm_connector_state *conn_state)
@@ -725,7 +727,7 @@ static void ibx_set_infoframes(struct drm_encoder *encoder,
 
 	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
 	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
 }
 
 static void cpt_set_infoframes(struct drm_encoder *encoder,
@@ -768,7 +770,7 @@ static void cpt_set_infoframes(struct drm_encoder *encoder,
 
 	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
 	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
 }
 
 static void vlv_set_infoframes(struct drm_encoder *encoder,
@@ -821,7 +823,7 @@ static void vlv_set_infoframes(struct drm_encoder *encoder,
 
 	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
 	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
 }
 
 static void hsw_set_infoframes(struct drm_encoder *encoder,
@@ -854,7 +856,7 @@ static void hsw_set_infoframes(struct drm_encoder *encoder,
 
 	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
 	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
 }
 
 void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
drivers/gpu/drm/mediatek/mtk_hdmi.c +2 -1
index b78791061983..59a11026dceb 100644
@@ -1054,7 +1054,8 @@ static int mtk_hdmi_setup_vendor_specific_infoframe(struct mtk_hdmi *hdmi,
 	u8 buffer[10];
 	ssize_t err;
 
-	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
+	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame,
+							  &hdmi->conn, mode);
 	if (err) {
 		dev_err(hdmi->dev,
 			"Failed to get vendor infoframe from mode: %zd\n", err);
drivers/gpu/drm/nouveau/nv50_display.c +2 -1
index b26a506d20ca..9d7b2afd7cfc 100644
@@ -2754,7 +2754,8 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
 			= hdmi_infoframe_pack(&avi_frame, args.infoframes, 17);
 	}
 
-	ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi, mode);
+	ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi,
+							  &nv_connector->base, mode);
 	if (!ret) {
 		/* We have a Vendor InfoFrame, populate it to the display */
 		args.pwr.vendor_infoframe_length
drivers/gpu/drm/rockchip/inno_hdmi.c +1 -0
index ee584d87111f..fab30927a889 100644
@@ -282,6 +282,7 @@ static int inno_hdmi_config_video_vsi(struct inno_hdmi *hdmi,
 	int rc;
 
 	rc = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							 &hdmi->connector,
 							 mode);
 
 	return inno_hdmi_upload_frame(hdmi, rc, &frame, INFOFRAME_VSI,
drivers/gpu/drm/sti/sti_hdmi.c +3 -1
index d1902750a85d..c3b292ab17a5 100644
@@ -515,7 +515,9 @@ static int hdmi_vendor_infoframe_config(struct sti_hdmi *hdmi)
 
 	DRM_DEBUG_DRIVER("\n");
 
-	ret = drm_hdmi_vendor_infoframe_from_display_mode(&infoframe, mode);
+	ret = drm_hdmi_vendor_infoframe_from_display_mode(&infoframe,
+							  hdmi->drm_connector,
+							  mode);
 	if (ret < 0) {
 		/*
 		 * Going into that statement does not means vendor infoframe
drivers/gpu/drm/zte/zx_hdmi.c +1 -0
index b8abb1b496ff..13ea90f7a185 100644
@@ -108,6 +108,7 @@ static int zx_hdmi_config_video_vsi(struct zx_hdmi *hdmi,
 	int ret;
 
 	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							  &hdmi->connector,
 							  mode);
 	if (ret) {
 		DRM_DEV_ERROR(hdmi->dev, "failed to get vendor infoframe: %d\n",
include/drm/drm_connector.h +5 -0
index 2b97d1e28f60..1543212b0449 100644
@@ -270,6 +270,11 @@ struct drm_display_info {
 	bool dvi_dual;
 
 	/**
+	 * @has_hdmi_infoframe: Does the sink support the HDMI infoframe?
+	 */
+	bool has_hdmi_infoframe;
+
+	/**
 	 * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
 	 * more stuff redundant with @bus_formats.
 	 */
include/drm/drm_edid.h +1 -0
index 9e4e23524840..3c8740ad1db6 100644
@@ -356,6 +356,7 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
 					 bool is_hdmi2_sink);
 int
 drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+					    struct drm_connector *connector,
 					    const struct drm_display_mode *mode);
 void
 drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
Signature · 6 lines
2.13.6

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw

PATCH 3/10 drm/modes: Introduce drm_mode_match()

In reply to Ville Syrjala

From: Ville Syrjälä <[email protected]>

Make mode matching less confusing by allowing the caller to specify which parts of the modes should match via some flags.

---
 drivers/gpu/drm/drm_modes.c | 134 ++++++++++++++++++++++++++++++++++----------
 include/drm/drm_modes.h     |   9 +++
 2 files changed, 112 insertions(+), 31 deletions(-)
drivers/gpu/drm/drm_modes.c +103 -31
index 4a3f68a33844..8128dbb098be 100644
@@ -940,17 +940,68 @@ struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_mode_duplicate);
 
+static bool drm_mode_match_timings(const struct drm_display_mode *mode1,
+				   const struct drm_display_mode *mode2)
+{
+	return mode1->hdisplay == mode2->hdisplay &&
+		mode1->hsync_start == mode2->hsync_start &&
+		mode1->hsync_end == mode2->hsync_end &&
+		mode1->htotal == mode2->htotal &&
+		mode1->hskew == mode2->hskew &&
+		mode1->vdisplay == mode2->vdisplay &&
+		mode1->vsync_start == mode2->vsync_start &&
+		mode1->vsync_end == mode2->vsync_end &&
+		mode1->vtotal == mode2->vtotal &&
+		mode1->vscan == mode2->vscan;
+}
+
+static bool drm_mode_match_clock(const struct drm_display_mode *mode1,
+				  const struct drm_display_mode *mode2)
+{
+	/*
+	 * do clock check convert to PICOS
+	 * so fb modes get matched the same
+	 */
+	if (mode1->clock && mode2->clock)
+		return KHZ2PICOS(mode1->clock) == KHZ2PICOS(mode2->clock);
+	else
+		return mode1->clock == mode2->clock;
+}
+
+static bool drm_mode_match_flags(const struct drm_display_mode *mode1,
+				 const struct drm_display_mode *mode2)
+{
+	return (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
+		(mode2->flags & ~DRM_MODE_FLAG_3D_MASK);
+}
+
+static bool drm_mode_match_3d_flags(const struct drm_display_mode *mode1,
+				    const struct drm_display_mode *mode2)
+{
+	return (mode1->flags & DRM_MODE_FLAG_3D_MASK) ==
+		(mode2->flags & DRM_MODE_FLAG_3D_MASK);
+}
+
+static bool drm_mode_match_aspect_ratio(const struct drm_display_mode *mode1,
+					const struct drm_display_mode *mode2)
+{
+	return mode1->picture_aspect_ratio == mode2->picture_aspect_ratio;
+}
+
 /**
- * drm_mode_equal - test modes for equality
+ * drm_mode_match - test modes for (partial) equality
  * @mode1: first mode
  * @mode2: second mode
+ * @match_flags: which parts need to match (DRM_MODE_MATCH_*)
  *
  * Check to see if @mode1 and @mode2 are equivalent.
  *
  * Returns:
- * True if the modes are equal, false otherwise.
+ * True if the modes are (partially) equal, false otherwise.
  */
-bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
+bool drm_mode_match(const struct drm_display_mode *mode1,
+		    const struct drm_display_mode *mode2,
+		    unsigned int match_flags)
 {
 	if (!mode1 && !mode2)
 		return true;
@@ -958,15 +1009,48 @@ bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_displ
 	if (!mode1 || !mode2)
 		return false;
 
-	/* do clock check convert to PICOS so fb modes get matched
-	 * the same */
-	if (mode1->clock && mode2->clock) {
-		if (KHZ2PICOS(mode1->clock) != KHZ2PICOS(mode2->clock))
-			return false;
-	} else if (mode1->clock != mode2->clock)
+	if (match_flags & DRM_MODE_MATCH_TIMINGS &&
+	    !drm_mode_match_timings(mode1, mode2))
+		return false;
+
+	if (match_flags & DRM_MODE_MATCH_CLOCK &&
+	    !drm_mode_match_clock(mode1, mode2))
+		return false;
+
+	if (match_flags & DRM_MODE_MATCH_FLAGS &&
+	    !drm_mode_match_flags(mode1, mode2))
+		return false;
+
+	if (match_flags & DRM_MODE_MATCH_3D_FLAGS &&
+	    !drm_mode_match_3d_flags(mode1, mode2))
 		return false;
 
-	return drm_mode_equal_no_clocks(mode1, mode2);
+	if (match_flags & DRM_MODE_MATCH_ASPECT_RATIO &&
+	    !drm_mode_match_aspect_ratio(mode1, mode2))
+		return false;
+
+	return true;
+}
+EXPORT_SYMBOL(drm_mode_match);
+
+/**
+ * drm_mode_equal - test modes for equality
+ * @mode1: first mode
+ * @mode2: second mode
+ *
+ * Check to see if @mode1 and @mode2 are equivalent.
+ *
+ * Returns:
+ * True if the modes are equal, false otherwise.
+ */
+bool drm_mode_equal(const struct drm_display_mode *mode1,
+		    const struct drm_display_mode *mode2)
+{
+	return drm_mode_match(mode1, mode2,
+			      DRM_MODE_MATCH_TIMINGS |
+			      DRM_MODE_MATCH_CLOCK |
+			      DRM_MODE_MATCH_FLAGS |
+			      DRM_MODE_MATCH_3D_FLAGS);
 }
 EXPORT_SYMBOL(drm_mode_equal);
 
@@ -981,13 +1065,13 @@ EXPORT_SYMBOL(drm_mode_equal);
  * Returns:
  * True if the modes are equal, false otherwise.
  */
-bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2)
+bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
+			      const struct drm_display_mode *mode2)
 {
-	if ((mode1->flags & DRM_MODE_FLAG_3D_MASK) !=
-	    (mode2->flags & DRM_MODE_FLAG_3D_MASK))
-		return false;
-
-	return drm_mode_equal_no_clocks_no_stereo(mode1, mode2);
+	return drm_mode_match(mode1, mode2,
+			      DRM_MODE_MATCH_TIMINGS |
+			      DRM_MODE_MATCH_FLAGS |
+			      DRM_MODE_MATCH_3D_FLAGS);
 }
 EXPORT_SYMBOL(drm_mode_equal_no_clocks);
 
@@ -1005,21 +1089,9 @@ EXPORT_SYMBOL(drm_mode_equal_no_clocks);
 bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
 					const struct drm_display_mode *mode2)
 {
-	if (mode1->hdisplay == mode2->hdisplay &&
-	    mode1->hsync_start == mode2->hsync_start &&
-	    mode1->hsync_end == mode2->hsync_end &&
-	    mode1->htotal == mode2->htotal &&
-	    mode1->hskew == mode2->hskew &&
-	    mode1->vdisplay == mode2->vdisplay &&
-	    mode1->vsync_start == mode2->vsync_start &&
-	    mode1->vsync_end == mode2->vsync_end &&
-	    mode1->vtotal == mode2->vtotal &&
-	    mode1->vscan == mode2->vscan &&
-	    (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
-	     (mode2->flags & ~DRM_MODE_FLAG_3D_MASK))
-		return true;
-
-	return false;
+	return drm_mode_match(mode1, mode2,
+			      DRM_MODE_MATCH_TIMINGS |
+			      DRM_MODE_MATCH_FLAGS);
 }
 EXPORT_SYMBOL(drm_mode_equal_no_clocks_no_stereo);
 
include/drm/drm_modes.h +9 -0
index 9f3421c8efcd..839eb9c3a029 100644
@@ -150,6 +150,12 @@ enum drm_mode_status {
 
 #define DRM_MODE_FLAG_3D_MAX	DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
 
+#define DRM_MODE_MATCH_TIMINGS (1 << 0)
+#define DRM_MODE_MATCH_CLOCK (1 << 1)
+#define DRM_MODE_MATCH_FLAGS (1 << 2)
+#define DRM_MODE_MATCH_3D_FLAGS (1 << 3)
+#define DRM_MODE_MATCH_ASPECT_RATIO (1 << 4)
+
 /**
  * struct drm_display_mode - DRM kernel-internal display mode structure
  * @hdisplay: horizontal display size
@@ -493,6 +499,9 @@ void drm_mode_copy(struct drm_display_mode *dst,
 		   const struct drm_display_mode *src);
 struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
 					    const struct drm_display_mode *mode);
+bool drm_mode_match(const struct drm_display_mode *mode1,
+		    const struct drm_display_mode *mode2,
+		    unsigned int match_flags);
 bool drm_mode_equal(const struct drm_display_mode *mode1,
 		    const struct drm_display_mode *mode2);
 bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
Signature · 6 lines
2.13.6

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw

PATCH 4/10 drm/edid: Use drm_mode_match_no_clocks_no_stereo() for consistentcy

In reply to Ville Syrjala

From: Ville Syrjälä <[email protected]>

Use drm_mode_equal_no_clocks_no_stereo() in drm_match_hdmi_mode_clock_tolerance() for consistency as we also use it in drm_match_hdmi_mode() and the cea mode matching functions.

This doesn't actually change anything since the input mode comes from detailed timings and we match it against edid_4k_modes[] which. So none of those modes can have stereo flags set.

---
 drivers/gpu/drm/drm_edid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_edid.c +1 -1
index 9ada0ccf50df..b575c4b5a313 100644
@@ -3020,7 +3020,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
 		    abs(to_match->clock - clock2) > clock_tolerance)
 			continue;
 
-		if (drm_mode_equal_no_clocks(to_match, hdmi_mode))
+		if (drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
 			return vic;
 	}
 
Signature · 6 lines
2.13.6

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#12 lore raw

PATCH 5/10 drm/edid: Fix up edid_cea_modes[] formatting

In reply to Ville Syrjala

From: Ville Syrjälä <[email protected]>

Fix up a bunch of bad indentation and insconsistent comments in edid_cea_modes[].

---
 drivers/gpu/drm/drm_edid.c | 84 +++++++++++++++++++++++-----------------------
 1 file changed, 42 insertions(+), 42 deletions(-)
drivers/gpu/drm/drm_edid.c +42 -42
index b575c4b5a313..7220b8f9a7e8 100644
@@ -685,43 +685,43 @@ static const struct drm_display_mode edid_cea_modes[] = {
 	{ DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
 		   2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
-			DRM_MODE_FLAG_INTERLACE),
+		   DRM_MODE_FLAG_INTERLACE),
 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 6 - 720(1440)x480i@60Hz */
 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
 		   801, 858, 0, 480, 488, 494, 525, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
 	/* 7 - 720(1440)x480i@60Hz */
 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
 		   801, 858, 0, 480, 488, 494, 525, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 8 - 720(1440)x240@60Hz */
 	{ DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
 		   801, 858, 0, 240, 244, 247, 262, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
 	/* 9 - 720(1440)x240@60Hz */
 	{ DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
 		   801, 858, 0, 240, 244, 247, 262, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 10 - 2880x480i@60Hz */
 	{ DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
 		   3204, 3432, 0, 480, 488, 494, 525, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE),
+		   DRM_MODE_FLAG_INTERLACE),
 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
 	/* 11 - 2880x480i@60Hz */
 	{ DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
 		   3204, 3432, 0, 480, 488, 494, 525, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE),
+		   DRM_MODE_FLAG_INTERLACE),
 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 12 - 2880x240@60Hz */
 	{ DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
@@ -767,43 +767,43 @@ static const struct drm_display_mode edid_cea_modes[] = {
 	{ DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
 		   2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
-			DRM_MODE_FLAG_INTERLACE),
+		   DRM_MODE_FLAG_INTERLACE),
 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 21 - 720(1440)x576i@50Hz */
 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
 		   795, 864, 0, 576, 580, 586, 625, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
 	/* 22 - 720(1440)x576i@50Hz */
 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
 		   795, 864, 0, 576, 580, 586, 625, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 23 - 720(1440)x288@50Hz */
 	{ DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
 		   795, 864, 0, 288, 290, 293, 312, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
 	/* 24 - 720(1440)x288@50Hz */
 	{ DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
 		   795, 864, 0, 288, 290, 293, 312, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 25 - 2880x576i@50Hz */
 	{ DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
 		   3180, 3456, 0, 576, 580, 586, 625, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE),
+		   DRM_MODE_FLAG_INTERLACE),
 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
 	/* 26 - 2880x576i@50Hz */
 	{ DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
 		   3180, 3456, 0, 576, 580, 586, 625, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE),
+		   DRM_MODE_FLAG_INTERLACE),
 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 27 - 2880x288@50Hz */
 	{ DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
@@ -869,13 +869,13 @@ static const struct drm_display_mode edid_cea_modes[] = {
 	{ DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
 		   2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE),
+		   DRM_MODE_FLAG_INTERLACE),
 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 40 - 1920x1080i@100Hz */
 	{ DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
 		   2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
-			DRM_MODE_FLAG_INTERLACE),
+		   DRM_MODE_FLAG_INTERLACE),
 	  .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 41 - 1280x720@100Hz */
 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
@@ -896,19 +896,19 @@ static const struct drm_display_mode edid_cea_modes[] = {
 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
 		   795, 864, 0, 576, 580, 586, 625, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
 	/* 45 - 720(1440)x576i@100Hz */
 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
 		   795, 864, 0, 576, 580, 586, 625, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 46 - 1920x1080i@120Hz */
 	{ DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
 		   2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
-			DRM_MODE_FLAG_INTERLACE),
+		   DRM_MODE_FLAG_INTERLACE),
 	  .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 47 - 1280x720@120Hz */
 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
@@ -929,13 +929,13 @@ static const struct drm_display_mode edid_cea_modes[] = {
 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
 		   801, 858, 0, 480, 488, 494, 525, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
 	/* 51 - 720(1440)x480i@120Hz */
 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
 		   801, 858, 0, 480, 488, 494, 525, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 52 - 720x576@200Hz */
 	{ DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
@@ -951,13 +951,13 @@ static const struct drm_display_mode edid_cea_modes[] = {
 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
 		   795, 864, 0, 576, 580, 586, 625, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
 	/* 55 - 720(1440)x576i@200Hz */
 	{ DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
 		   795, 864, 0, 576, 580, 586, 625, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 56 - 720x480@240Hz */
 	{ DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
@@ -973,13 +973,13 @@ static const struct drm_display_mode edid_cea_modes[] = {
 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
 		   801, 858, 0, 480, 488, 494, 525, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
 	/* 59 - 720(1440)x480i@240Hz */
 	{ DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
 		   801, 858, 0, 480, 488, 494, 525, 0,
 		   DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
-			DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
+		   DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
 	  .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 60 - 1280x720@24Hz */
 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
@@ -1000,12 +1000,12 @@ static const struct drm_display_mode edid_cea_modes[] = {
 	{ DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
 		   2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
-	 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
+	  .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 64 - 1920x1080@100Hz */
 	{ DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
 		   2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
-	 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
+	  .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
 	/* 65 - 1280x720@24Hz */
 	{ DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
 		   3080, 3300, 0, 720, 725, 730, 750, 0,
@@ -1146,77 +1146,77 @@ static const struct drm_display_mode edid_cea_modes[] = {
 		   3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
-	/* 93 - 3840x2160p@24Hz 16:9 */
+	/* 93 - 3840x2160@24Hz */
 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
 		   5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
-	/* 94 - 3840x2160p@25Hz 16:9 */
+	/* 94 - 3840x2160@25Hz */
 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
 		   4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
-	/* 95 - 3840x2160p@30Hz 16:9 */
+	/* 95 - 3840x2160@30Hz */
 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
 		   4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
-	/* 96 - 3840x2160p@50Hz 16:9 */
+	/* 96 - 3840x2160@50Hz */
 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
 		   4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
-	/* 97 - 3840x2160p@60Hz 16:9 */
+	/* 97 - 3840x2160@60Hz */
 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
 		   4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
-	/* 98 - 4096x2160p@24Hz 256:135 */
+	/* 98 - 4096x2160@24Hz */
 	{ DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
 		   5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
-	/* 99 - 4096x2160p@25Hz 256:135 */
+	/* 99 - 4096x2160@25Hz */
 	{ DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
 		   5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
-	/* 100 - 4096x2160p@30Hz 256:135 */
+	/* 100 - 4096x2160@30Hz */
 	{ DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
 		   4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
-	/* 101 - 4096x2160p@50Hz 256:135 */
+	/* 101 - 4096x2160@50Hz */
 	{ DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
 		   5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
-	/* 102 - 4096x2160p@60Hz 256:135 */
+	/* 102 - 4096x2160@60Hz */
 	{ DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
 		   4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
-	/* 103 - 3840x2160p@24Hz 64:27 */
+	/* 103 - 3840x2160@24Hz */
 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
 		   5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
-	/* 104 - 3840x2160p@25Hz 64:27 */
+	/* 104 - 3840x2160@25Hz */
 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
 		   4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
-	/* 105 - 3840x2160p@30Hz 64:27 */
+	/* 105 - 3840x2160@30Hz */
 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
 		   4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
-	/* 106 - 3840x2160p@50Hz 64:27 */
+	/* 106 - 3840x2160@50Hz */
 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
 		   4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
 	  .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
-	/* 107 - 3840x2160p@60Hz 64:27 */
+	/* 107 - 3840x2160@60Hz */
 	{ DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
 		   4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
 		   DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Signature · 6 lines
2.13.6

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#13 lore raw

PATCH 6/10 drm/edid: Fix cea mode aspect ratio handling

In reply to Ville Syrjala

From: Ville Syrjälä <[email protected]>

commit 6dffd431e229 ("drm: Add aspect ratio parsing in DRM layer") cause us to not send out any VICs in the AVI infoframes. That commit was since reverted, but if and when we add aspect ratio handing back we need to be more careful.

Let's handle this by considering the aspect ratio as a requirement for cea mode matching only if the passed in mode actually has a non-zero aspect ratio field. This will keep userspace that doesn't provide an aspect ratio working as before by matching it to the first otherwise equal cea mode. And once userspace starts to provide the aspect ratio it will be considerd a hard requirement for the match.

Also change the hdmi mode matching to use drm_mode_match() for consistency, but we don't match on aspect ratio there since the spec doesn't list a specific aspect ratio for those modes.

Cc Shashank Sharma <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Akashdeep Sharma <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
 drivers/gpu/drm/drm_edid.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_edid.c +14 -4
index 7220b8f9a7e8..00aa98f3e55d 100644
@@ -2903,11 +2903,15 @@ cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
 static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
 					     unsigned int clock_tolerance)
 {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
 	u8 vic;
 
 	if (!to_match->clock)
 		return 0;
 
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
+
 	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
 		struct drm_display_mode cea_mode = edid_cea_modes[vic];
 		unsigned int clock1, clock2;
@@ -2921,7 +2925,7 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
 			continue;
 
 		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
 				return vic;
 		} while (cea_mode_alternate_timings(vic, &cea_mode));
 	}
@@ -2938,11 +2942,15 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
  */
 u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
 {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
 	u8 vic;
 
 	if (!to_match->clock)
 		return 0;
 
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
+
 	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
 		struct drm_display_mode cea_mode = edid_cea_modes[vic];
 		unsigned int clock1, clock2;
@@ -2956,7 +2964,7 @@ u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
 			continue;
 
 		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
 				return vic;
 		} while (cea_mode_alternate_timings(vic, &cea_mode));
 	}
@@ -3003,6 +3011,7 @@ hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
 static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
 					      unsigned int clock_tolerance)
 {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
 	u8 vic;
 
 	if (!to_match->clock)
@@ -3020,7 +3029,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
 		    abs(to_match->clock - clock2) > clock_tolerance)
 			continue;
 
-		if (drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		if (drm_mode_match(to_match, hdmi_mode, match_flags))
 			return vic;
 	}
 
@@ -3037,6 +3046,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
  */
 static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
 {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
 	u8 vic;
 
 	if (!to_match->clock)
@@ -3052,7 +3062,7 @@ static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
 
 		if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
 		     KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
-		    drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		    drm_mode_match(to_match, hdmi_mode, match_flags))
 			return vic;
 	}
 	return 0;
Signature · 6 lines
2.13.6

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#24 lore raw

PATCH 7/10 drm/edid: Don't send bogus aspect ratios in AVI infoframes

In reply to Ville Syrjala

From: Ville Syrjälä <[email protected]>

If the user mode would specify an aspect ratio other than 4:3 or 16:9 we now silently ignore it. Maybe a better apporoach is to return an error? Let's try that.

Also we must be careful that we don't try to send illegal picture aspect in the infoframe as it's only capable of signalling none, 4:3, and 16:9. Currently we're sending these bogus infoframes whenever the cea mode specifies some other aspect ratio.

Cc Shashank Sharma <[email protected]>
Cc Sean Paul <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
 drivers/gpu/drm/drm_edid.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_edid.c +17 -6
index 00aa98f3e55d..bafb3ee4ea97 100644
@@ -4786,6 +4786,7 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
 					 const struct drm_display_mode *mode,
 					 bool is_hdmi2_sink)
 {
+	enum hdmi_picture_aspect picture_aspect;
 	int err;
 
 	if (!frame || !mode)
@@ -4828,13 +4829,23 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
 	 * Populate picture aspect ratio from either
 	 * user input (if specified) or from the CEA mode list.
 	 */
-	if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
-		mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
-		frame->picture_aspect = mode->picture_aspect_ratio;
-	else if (frame->video_code > 0)
-		frame->picture_aspect = drm_get_cea_aspect_ratio(
-						frame->video_code);
+	picture_aspect = mode->picture_aspect_ratio;
+	if (picture_aspect == HDMI_PICTURE_ASPECT_NONE)
+		picture_aspect = drm_get_cea_aspect_ratio(frame->video_code);
 
+	/*
+	 * The infoframe can't convey anything but none, 4:3
+	 * and 16:9, so if the user has asked for anything else
+	 * we can only satisfy it by specifying the right VIC.
+	 */
+	if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {
+		if (picture_aspect !=
+		    drm_get_cea_aspect_ratio(frame->video_code))
+			return -EINVAL;
+		picture_aspect = HDMI_PICTURE_ASPECT_NONE;
+	}
+
+	frame->picture_aspect = picture_aspect;
 	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
 	frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
 
Signature · 6 lines
2.13.6

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#32 lore raw

PATCH 8/10 video/hdmi: Reject illegal picture aspect ratios

In reply to Ville Syrjala

From: Ville Syrjälä <[email protected]>

AVI infoframe can only carry none, 4:3, or 16:9 picture aspect ratios. Return an error if the user asked for something different.

Cc Shashank Sharma <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Akashdeep Sharma <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Hans Verkuil <[email protected]>
---
 drivers/video/hdmi.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/video/hdmi.c +3 -0
index 111a0ab6280a..38716eb50408 100644
@@ -93,6 +93,9 @@ ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer,
 	if (size < length)
 		return -ENOSPC;
 
+	if (frame->picture_aspect > HDMI_PICTURE_ASPECT_16_9)
+		return -EINVAL;
+
 	memset(buffer, 0, size);
 
 	ptr[0] = frame->type;
Signature · 1 line
2.13.6
#34 lore raw

PATCH 9/10 video/hdmi: Constify 'buffer' to the unpack functions

In reply to Ville Syrjala

From: Ville Syrjälä <[email protected]>

The unpack functions just read from the passed in buffer, so make it const.

---
 drivers/video/hdmi.c | 23 ++++++++++++-----------
 include/linux/hdmi.h |  3 ++-
 2 files changed, 14 insertions(+), 12 deletions(-)
drivers/video/hdmi.c +12 -11
index 38716eb50408..65b915ea4936 100644
@@ -31,7 +31,7 @@
 
 #define hdmi_log(fmt, ...) dev_printk(level, dev, fmt, ##__VA_ARGS__)
 
-static u8 hdmi_infoframe_checksum(u8 *ptr, size_t size)
+static u8 hdmi_infoframe_checksum(const u8 *ptr, size_t size)
 {
 	u8 csum = 0;
 	size_t i;
@@ -1016,9 +1016,9 @@ EXPORT_SYMBOL(hdmi_infoframe_log);
  * Returns 0 on success or a negative error code on failure.
  */
 static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe *frame,
-				     void *buffer)
+				     const void *buffer)
 {
-	u8 *ptr = buffer;
+	const u8 *ptr = buffer;
 	int ret;
 
 	if (ptr[0] != HDMI_INFOFRAME_TYPE_AVI ||
@@ -1079,9 +1079,9 @@ static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe *frame,
  * Returns 0 on success or a negative error code on failure.
  */
 static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe *frame,
-				     void *buffer)
+				     const void *buffer)
 {
-	u8 *ptr = buffer;
+	const u8 *ptr = buffer;
 	int ret;
 
 	if (ptr[0] != HDMI_INFOFRAME_TYPE_SPD ||
@@ -1117,9 +1117,9 @@ static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe *frame,
  * Returns 0 on success or a negative error code on failure.
  */
 static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe *frame,
-				       void *buffer)
+				       const void *buffer)
 {
-	u8 *ptr = buffer;
+	const u8 *ptr = buffer;
 	int ret;
 
 	if (ptr[0] != HDMI_INFOFRAME_TYPE_AUDIO ||
@@ -1163,9 +1163,9 @@ static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe *frame,
  */
 static int
 hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
-				 void *buffer)
+				 const void *buffer)
 {
-	u8 *ptr = buffer;
+	const u8 *ptr = buffer;
 	size_t length;
 	int ret;
 	u8 hdmi_video_format;
@@ -1234,10 +1234,11 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
  *
  * Returns 0 on success or a negative error code on failure.
  */
-int hdmi_infoframe_unpack(union hdmi_infoframe *frame, void *buffer)
+int hdmi_infoframe_unpack(union hdmi_infoframe *frame,
+			  const void *buffer)
 {
 	int ret;
-	u8 *ptr = buffer;
+	const u8 *ptr = buffer;
 
 	switch (ptr[0]) {
 	case HDMI_INFOFRAME_TYPE_AVI:
include/linux/hdmi.h +2 -1
index d271ff23984f..d3816170c062 100644
@@ -332,7 +332,8 @@ union hdmi_infoframe {
 
 ssize_t
 hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer, size_t size);
-int hdmi_infoframe_unpack(union hdmi_infoframe *frame, void *buffer);
+int hdmi_infoframe_unpack(union hdmi_infoframe *frame,
+			  const void *buffer);
 void hdmi_infoframe_log(const char *level, struct device *dev,
 			union hdmi_infoframe *frame);
 
Signature · 1 line
2.13.6
#35 lore raw

PATCH 10/10 video/hdmi: Pass buffer size to infoframe unpack functions

In reply to Ville Syrjala

From: Ville Syrjälä <[email protected]>

To make sure the infoframe unpack functions don't end up examining stack garbage or oopsing, let's pass in the size of the buffer.

---
 drivers/media/i2c/adv7511.c  |  2 +-
 drivers/media/i2c/adv7604.c  |  2 +-
 drivers/media/i2c/adv7842.c  |  2 +-
 drivers/media/i2c/tc358743.c |  2 +-
 drivers/video/hdmi.c         | 51 ++++++++++++++++++++++++++++++++------------
 include/linux/hdmi.h         |  2 +-
 6 files changed, 42 insertions(+), 19 deletions(-)
drivers/media/i2c/adv7511.c +1 -1
index 2817bafc67bf..dec09c18ea34 100644
@@ -562,7 +562,7 @@ static void log_infoframe(struct v4l2_subdev *sd, const struct adv7511_cfg_read_
 	buffer[3] = 0;
 	buffer[3] = hdmi_infoframe_checksum(buffer, len + 4);
 
-	if (hdmi_infoframe_unpack(&frame, buffer) < 0) {
+	if (hdmi_infoframe_unpack(&frame, buffer, sizeof(buffer)) < 0) {
 		v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc);
 		return;
 	}
drivers/media/i2c/adv7604.c +1 -1
index f289b8aca1da..8500438af0d3 100644
@@ -2429,7 +2429,7 @@ static int adv76xx_read_infoframe(struct v4l2_subdev *sd, int index,
 		buffer[i + 3] = infoframe_read(sd,
 				       adv76xx_cri[index].payload_addr + i);
 
-	if (hdmi_infoframe_unpack(frame, buffer) < 0) {
+	if (hdmi_infoframe_unpack(frame, buffer, sizeof(buffer)) < 0) {
 		v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__,
 			 adv76xx_cri[index].desc);
 		return -ENOENT;
drivers/media/i2c/adv7842.c +1 -1
index 65f34e7e146f..fd5d5e84dcbf 100644
@@ -2576,7 +2576,7 @@ static void log_infoframe(struct v4l2_subdev *sd, struct adv7842_cfg_read_infofr
 	for (i = 0; i < len; i++)
 		buffer[i + 3] = infoframe_read(sd, cri->payload_addr + i);
 
-	if (hdmi_infoframe_unpack(&frame, buffer) < 0) {
+	if (hdmi_infoframe_unpack(&frame, buffer, sizeof(buffer)) < 0) {
 		v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc);
 		return;
 	}
drivers/media/i2c/tc358743.c +1 -1
index e6f5c363ccab..f6a5ebffd9c6 100644
@@ -453,7 +453,7 @@ static void print_avi_infoframe(struct v4l2_subdev *sd)
 
 	i2c_rd(sd, PK_AVI_0HEAD, buffer, HDMI_INFOFRAME_SIZE(AVI));
 
-	if (hdmi_infoframe_unpack(&frame, buffer) < 0) {
+	if (hdmi_infoframe_unpack(&frame, buffer, sizeof(buffer)) < 0) {
 		v4l2_err(sd, "%s: unpack of AVI infoframe failed\n", __func__);
 		return;
 	}
drivers/video/hdmi.c +37 -14

152 lines not on this page · raw message

include/linux/hdmi.h +1 -1
index d3816170c062..a577d4ae2570 100644
@@ -333,7 +333,7 @@ union hdmi_infoframe {
 ssize_t
 hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer, size_t size);
 int hdmi_infoframe_unpack(union hdmi_infoframe *frame,
-			  const void *buffer);
+			  const void *buffer, size_t size);
 void hdmi_infoframe_log(const char *level, struct device *dev,
 			union hdmi_infoframe *frame);
 
Signature · 1 line
2.13.6
#38 lore raw

✓ Fi.CI.BAT: success for drm/edid: Infoframe cleanups and fixes

In reply to Ville Syrjala
== Series Details ==

== Series Details ==

Series: drm/edid: Infoframe cleanups and fixes
URL : https://patchwork.freedesktop.org/series/33730/
State : success

== Summary ==

Series 33730v1 drm/edid: Infoframe cleanups and fixes
https://patchwork.freedesktop.org/api/1.0/series/33730/revisions/1/mbox/

Test chamelium:

        Subgroup dp-crc-fast:
                dmesg-fail -> PASS       (fi-kbl-7500u) fdo#102514
Test vgem_basic:
        Subgroup dmabuf-export:
                incomplete -> PASS       (fi-byt-n2820) fdo#103714
                pass       -> INCOMPLETE (fi-bxt-dsi) fdo#103706 +1
        Subgroup unload:
                notrun     -> INCOMPLETE (fi-byt-n2820) fdo#103702 +1

fdo#102514 https://bugs.freedesktop.org/show_bug.cgi?id=102514
fdo#103714 https://bugs.freedesktop.org/show_bug.cgi?id=103714
fdo#103706 https://bugs.freedesktop.org/show_bug.cgi?id=103706
fdo#103702 https://bugs.freedesktop.org/show_bug.cgi?id=103702

fi-bdw-5557u     total:285  pass:263  dwarn:0   dfail:1   fail:0   skip:20 
fi-bdw-gvtdvm    total:285  pass:260  dwarn:0   dfail:1   fail:0   skip:23 
fi-blb-e6850     total:285  pass:218  dwarn:1   dfail:1   fail:0   skip:64 
fi-bsw-n3050     total:285  pass:238  dwarn:0   dfail:1   fail:0   skip:45 
fi-bwr-2160      total:285  pass:178  dwarn:0   dfail:1   fail:0   skip:105
fi-bxt-dsi       total:278  pass:247  dwarn:0   dfail:1   fail:0   skip:29 
fi-bxt-j4205     total:285  pass:255  dwarn:0   dfail:1   fail:0   skip:28 
fi-byt-j1900     total:285  pass:249  dwarn:0   dfail:1   fail:0   skip:34 
fi-byt-n2820     total:285  pass:245  dwarn:0   dfail:1   fail:0   skip:38 
fi-elk-e7500     total:285  pass:224  dwarn:0   dfail:1   fail:0   skip:59 
fi-gdg-551       total:285  pass:174  dwarn:0   dfail:1   fail:1   skip:108
fi-glk-1         total:285  pass:256  dwarn:0   dfail:1   fail:0   skip:27 
fi-hsw-4770      total:285  pass:257  dwarn:0   dfail:1   fail:0   skip:26 
fi-hsw-4770r     total:285  pass:257  dwarn:0   dfail:1   fail:0   skip:26 
fi-ilk-650       total:285  pass:223  dwarn:0   dfail:1   fail:0   skip:60 
fi-ivb-3520m     total:285  pass:255  dwarn:0   dfail:1   fail:0   skip:28 
fi-ivb-3770      total:285  pass:255  dwarn:0   dfail:1   fail:0   skip:28 
fi-kbl-7500u     total:285  pass:259  dwarn:1   dfail:1   fail:0   skip:23 
fi-kbl-7560u     total:285  pass:265  dwarn:0   dfail:1   fail:0   skip:18 
fi-kbl-7567u     total:285  pass:264  dwarn:0   dfail:1   fail:0   skip:19 
fi-kbl-r         total:285  pass:257  dwarn:0   dfail:1   fail:0   skip:26 
fi-pnv-d510      total:285  pass:217  dwarn:1   dfail:1   fail:0   skip:65 
fi-skl-6260u     total:285  pass:264  dwarn:0   dfail:1   fail:0   skip:19 
fi-skl-6600u     total:285  pass:257  dwarn:0   dfail:1   fail:0   skip:26 
fi-skl-6700hq    total:285  pass:258  dwarn:0   dfail:1   fail:0   skip:25 
fi-skl-6700k     total:285  pass:260  dwarn:0   dfail:1   fail:0   skip:23 
fi-skl-6770hq    total:285  pass:264  dwarn:0   dfail:1   fail:0   skip:19 
fi-skl-gvtdvm    total:285  pass:261  dwarn:0   dfail:1   fail:0   skip:22 
fi-snb-2520m     total:285  pass:245  dwarn:0   dfail:1   fail:0   skip:38 
fi-snb-2600      total:285  pass:244  dwarn:0   dfail:1   fail:0   skip:39 

Blacklisted hosts:
fi-cfl-s total:285 pass:252 dwarn:0 dfail:1 fail:0 skip:31

9891b4090c6e6a5299a4134f7bd6c463fb2cd485 drm-tip: 2017y-11m-13d-16h-04m-46s UTC integration manifest 2d305bb901cc video/hdmi: Pass buffer size to infoframe unpack functions
9161733e0c67 video/hdmi: Constify 'buffer' to the unpack functions
5298f77013f6 video/hdmi: Reject illegal picture aspect ratios
e8cc0955a59d drm/edid: Don't send bogus aspect ratios in AVI infoframes
76160a03d4d4 drm/edid: Fix cea mode aspect ratio handling
2df0375a1d11 drm/edid: Fix up edid_cea_modes[] formatting
7178bb61b138 drm/edid: Use drm_mode_match_no_clocks_no_stereo() for consistentcy 72e507c9f3b3 drm/modes: Introduce drm_mode_match()
e9cc41ee0390 drm/edid: Allow HDMI infoframe without VIC or S3D
1a18a539358a video/hdmi: Allow "empty" HDMI infoframes

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_7098/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#14 lore raw

Re: [PATCH 06/10] drm/edid: Fix cea mode aspect ratio handling

In reply to Ville Syrjala

Hi Ville,

drivers/gpu/drm/drm_edid.c cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode) · line 2914

Quoted 5 lines · Ville Syrjala
drivers/gpu/drm/drm_edid.c +3 -0
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
+

Maybe "if (to_match->picture_aspect_ratio != HDMI_PICTURE_ASPECT_NONE && to_match->picture_aspect_ratio != HDMI_PICTURE_ASPECT_RESERVED)"?

Or some kind of helper to validate the aspect ratio from userspace?

Best Regards,
Jose Miguel Abreu
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#25 lore raw

Re: [PATCH 07/10] drm/edid: Don't send bogus aspect ratios in AVI infoframes

In reply to Ville Syrjala
Quoted 12 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

If the user mode would specify an aspect ratio other than 4:3 or 16:9 we now silently ignore it. Maybe a better apporoach is to return an error? Let's try that.

Also we must be careful that we don't try to send illegal picture aspect in the infoframe as it's only capable of signalling none, 4:3, and 16:9. Currently we're sending these bogus infoframes whenever the cea mode specifies some other aspect ratio.

Yes, this is a bug. Following my input from the previous patch I think you should also check for HDMI_PICTURE_ASPECT_RESERVED or user a helper to check that. I'm also wondering if this should go to stable since the vics with aspect ratio > 16:9 were introduced. We are indeed corrupting the AVI infoframe.

Best Regards,
Jose Miguel Abreu
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reviewed-by on v1 8/10
#33 lore raw

Re: [PATCH 08/10] video/hdmi: Reject illegal picture aspect ratios

In reply to Ville Syrjala
Quoted 5 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

AVI infoframe can only carry none, 4:3, or 16:9 picture aspect ratios. Return an error if the user asked for something different.

Quoted 11 lines
Cc Shashank Sharma <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Akashdeep Sharma <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Hans Verkuil <[email protected]>

Best Regards,
Jose Miguel Abreu

#15 lore raw

Re: [PATCH 06/10] drm/edid: Fix cea mode aspect ratio handling

In reply to Jose Abreu
Quoted 13 lines · Jose Abreu

Hi Ville,

drivers/gpu/drm/drm_edid.c cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode) · line 2914

Quoted 5 lines · Ville Syrjala
drivers/gpu/drm/drm_edid.c +3 -0
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
+

Maybe "if (to_match->picture_aspect_ratio != HDMI_PICTURE_ASPECT_NONE && to_match->picture_aspect_ratio != HDMI_PICTURE_ASPECT_RESERVED)"?

Quoted 1 line

Or some kind of helper to validate the aspect ratio from userspace?

We can't currently get an aspect ratio from userspace. Well we had it but I reverted it due to regressions. When we add it back it will obviously need to be validated, just like any other information we get from userspace.

Hmm. Except we don't even validate the current mode flags/type at all. Fail.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#26 lore raw

Re: [PATCH 07/10] drm/edid: Don't send bogus aspect ratios in AVI infoframes

In reply to Jose Abreu
Quoted 16 lines · Jose Abreu
Quoted 12 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

If the user mode would specify an aspect ratio other than 4:3 or 16:9 we now silently ignore it. Maybe a better apporoach is to return an error? Let's try that.

Also we must be careful that we don't try to send illegal picture aspect in the infoframe as it's only capable of signalling none, 4:3, and 16:9. Currently we're sending these bogus infoframes whenever the cea mode specifies some other aspect ratio.

Quoted 2 lines

Yes, this is a bug. Following my input from the previous patch I think you should also check for HDMI_PICTURE_ASPECT_RESERVED or

RESERVED > 16_9

Quoted 3 lines

user a helper to check that. I'm also wondering if this should go to stable since the vics with aspect ratio > 16:9 were introduced. We are indeed corrupting the AVI infoframe.

Possibly. Just need to be careful we don't end up making a bigger mess in stable. I has some concerns about the ordering of these patches, but I guess that was between this patch and the next patch that starts to reject the illegal aspect ratios in the infoframe code. So just backporting this one alone (or both patches) should be fine.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#39 lore raw

✓ Fi.CI.IGT: success for drm/edid: Infoframe cleanups and fixes

In reply to Ville Syrjala
== Series Details ==

== Series Details ==

Series: drm/edid: Infoframe cleanups and fixes
URL : https://patchwork.freedesktop.org/series/33730/
State : success

== Summary ==

Test kms_atomic_transition:

        Subgroup plane-all-modeset-transition-fencing:
                pass       -> DMESG-WARN (shard-hsw) fdo#102614

fdo#102614 https://bugs.freedesktop.org/show_bug.cgi?id=102614

shard-hsw total:2584 pass:1471 dwarn:3 dfail:2 fail:9 skip:1099 time:9464s
Blacklisted hosts:

shard-apl        total:2543 pass:1582 dwarn:2   dfail:1   fail:21  skip:936 time:12922s
shard-kbl        total:2438 pass:1600 dwarn:22  dfail:6   fail:23  skip:784 time:9793s
shard-snb        total:2584 pass:1204 dwarn:2   dfail:2   fail:11  skip:1365 time:7730s

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_7098/shards.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw

Re: [PATCH 01/10] video/hdmi: Allow "empty" HDMI infoframes

In reply to Ville Syrjala

Regards

Shashank

Quoted 70 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

HDMI 2.0 Appendix F suggest that we should keep sending the infoframe when switching from 3D to 2D mode, even if the infoframe isn't strictly necessary (ie. not needed to transmit the VIC or stereo information). This is a workaround against some sinks that fail to realize that they should switch from 3D to 2D mode when the source stop transmitting the infoframe.

v2: Handle unpack() as well
Pull the length calculation into a helper

---
  drivers/video/hdmi.c | 51 +++++++++++++++++++++++++++++++--------------------
  1 file changed, 31 insertions(+), 20 deletions(-)
drivers/video/hdmi.c +12 -9
index 1cf907ecded4..111a0ab6280a 100644
@@ -321,6 +321,17 @@ int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame)
  }
  EXPORT_SYMBOL(hdmi_vendor_infoframe_init);
 
+static int hdmi_vendor_infoframe_length(const struct hdmi_vendor_infoframe *frame)
+{
+	/* for side by side (half) we also need to provide 3D_Ext_Data */
+	if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
+		return 6;
+	else if (frame->vic != 0 || frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
+		return 5;
+	else
+		return 4;
+}
+
  /**
   * hdmi_vendor_infoframe_pack() - write a HDMI vendor infoframe to binary buffer
   * @frame: HDMI infoframe
@@ -341,19 +352,11 @@ ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
  	u8 *ptr = buffer;
  	size_t length;
 
-	/* empty info frame */
-	if (frame->vic == 0 && frame->s3d_struct == HDMI_3D_STRUCTURE_INVALID)
-		return -EINVAL;
-
  	/* only one of those can be supplied */
  	if (frame->vic != 0 && frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
  		return -EINVAL;
 
-	/* for side by side (half) we also need to provide 3D_Ext_Data */
-	if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
-		frame->length = 6;
-	else
-		frame->length = 5;
+	frame->length = hdmi_vendor_infoframe_length(frame);
 
  	length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
 
@@ -372,14 +375,16 @@ ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
  	ptr[5] = 0x0c;
  	ptr[6] = 0x00;
 

drivers/video/hdmi.c ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame, · line 383

Quoted 10 lines
drivers/video/hdmi.c +2 -4
-	if (frame->vic) {
-		ptr[7] = 0x1 << 5;	/* video format */
-		ptr[8] = frame->vic;
-	} else {
+	if (frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID) {
  		ptr[7] = 0x2 << 5;	/* video format */
  		ptr[8] = (frame->s3d_struct & 0xf) << 4;
  		if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
  			ptr[9] = (frame->s3d_ext_data & 0xf) << 4;
+	} else if (frame->vic) {

Please correct me if I dint understand this properly, but for a HDMI 2.0 sink + 3D transmission, wouldn't I be sending HDMI 2.0 VIC = 94 as well as some valid s3d flag (like side by side) ?

- Shashank

Quoted 45 lines
drivers/video/hdmi.c +17 -7
+		ptr[7] = 0x1 << 5;	/* video format */
+		ptr[8] = frame->vic;
+	} else {
+		ptr[7] = 0x0 << 5;	/* video format */
  	}
 
  	hdmi_infoframe_set_checksum(buffer, length);
@@ -1165,7 +1170,7 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 
  	if (ptr[0] != HDMI_INFOFRAME_TYPE_VENDOR ||
  	    ptr[1] != 1 ||
-	    (ptr[2] != 5 && ptr[2] != 6))
+	    (ptr[2] != 4 && ptr[2] != 5 && ptr[2] != 6))
  		return -EINVAL;
 
  	length = ptr[2];
@@ -1193,16 +1198,22 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 
  	hvf->length = length;
 
-	if (hdmi_video_format == 0x1) {
-		hvf->vic = ptr[4];
-	} else if (hdmi_video_format == 0x2) {
+	if (hdmi_video_format == 0x2) {
+		if (length != 5 && length != 6)
+			return -EINVAL;
  		hvf->s3d_struct = ptr[4] >> 4;
  		if (hvf->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF) {
-			if (length == 6)
-				hvf->s3d_ext_data = ptr[5] >> 4;
-			else
+			if (length != 6)
  				return -EINVAL;
+			hvf->s3d_ext_data = ptr[5] >> 4;
  		}
+	} else if (hdmi_video_format == 0x1) {
+		if (length != 5)
+			return -EINVAL;
+		hvf->vic = ptr[4];
+	} else {
+		if (length != 4)
+			return -EINVAL;
  	}
 
  	return 0;
#6 lore raw

Re: [PATCH 02/10] drm/edid: Allow HDMI infoframe without VIC or S3D

In reply to Ville Syrjala

Regards

Shashank

Quoted 9 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

Appedix F of HDMI 2.0 says that some HDMI sink may fail to switch from 3D to 2D mode in a timely fashion if the source simply stops sending the HDMI infoframe. The suggested workaround is to keep sending the infoframe even when strictly not necessary (ie. no VIC and no S3D). HDMI 1.4 does allow for this behaviour, stating that sending the infoframe is optional in this case.

Quoted 9 lines

The infoframe was first specified in HDMI 1.4, so in theory sinks predating that may not appreciate us sending an uknown infoframe their way. To avoid regressions let's try to determine if the sink supports the infoframe or not. Unfortunately there's no direct way to do that, so instead we'll just check if we managed to parse any HDMI 1.4 4k or stereo modes from the EDID, and if so we assume the sink will accept the infoframe. Also if the EDID contains the HDMI 2.0 HDMI Forum VSDB we can assume the sink is prepared to receive the infoframe.

I am trying to get some sense from HDMI 2.0 spec section 10.2.1, which talks about switch from 3D to 2D. To me it looks like:
If (sending_to_hdmi2_sinks) {
- for 3d modes send HF-VSIF
- for 2d modes && defined in H14b HFVSIF, send H14B-VSIF
When you switch from 3d->2d {
- send_HF-VSIF with 3D_valid bit = 0/1
}
} else { /* HDMI 1.4b sinks from Appendix F */
- send H14b-VSIF with HDMI_video_format[2:0 = 0 OR 1]
}

Should we add a is_hdmi2 check and separate these cases ?

Quoted 93 lines

v2: Fix the getting has_hdmi_infoframe from display_info
Always fail constructing the infoframe if the display possibly can't handle it

Cc Shashank Sharma <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
  drivers/gpu/drm/bridge/sil-sii8620.c      |  3 ++-
  drivers/gpu/drm/bridge/synopsys/dw-hdmi.c |  4 +++-
  drivers/gpu/drm/drm_edid.c                | 34 +++++++++++++++++++++++++------
  drivers/gpu/drm/exynos/exynos_hdmi.c      |  2 +-
  drivers/gpu/drm/i915/intel_hdmi.c         | 14 +++++++------
  drivers/gpu/drm/mediatek/mtk_hdmi.c       |  3 ++-
  drivers/gpu/drm/nouveau/nv50_display.c    |  3 ++-
  drivers/gpu/drm/rockchip/inno_hdmi.c      |  1 +
  drivers/gpu/drm/sti/sti_hdmi.c            |  4 +++-
  drivers/gpu/drm/zte/zx_hdmi.c             |  1 +
  include/drm/drm_connector.h               |  5 +++++
  include/drm/drm_edid.h                    |  1 +
  12 files changed, 57 insertions(+), 18 deletions(-)
drivers/gpu/drm/bridge/sil-sii8620.c +2 -1
index b7eb704d0a8a..4417276ba02e 100644
@@ -2220,8 +2220,9 @@ static bool sii8620_mode_fixup(struct drm_bridge *bridge,
  			union hdmi_infoframe frm;
  			u8 mhl_vic[] = { 0, 95, 94, 93, 98 };
 
+			/* FIXME: We need the connector here */
  			drm_hdmi_vendor_infoframe_from_display_mode(
-				&frm.vendor.hdmi, adjusted_mode);
+				&frm.vendor.hdmi, NULL, adjusted_mode);
  			vic = frm.vendor.hdmi.vic;
  			if (vic >= ARRAY_SIZE(mhl_vic))
  				vic = 0;
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +3 -1
index a64ce7112288..b172139502d6 100644
@@ -1437,7 +1437,9 @@ static void hdmi_config_vendor_specific_infoframe(struct dw_hdmi *hdmi,
  	u8 buffer[10];
  	ssize_t err;
 
-	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
+	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame,
+							  &hdmi->connector,
+							  mode);
  	if (err < 0)
  		/*
  		 * Going into that statement does not means vendor infoframe
drivers/gpu/drm/drm_edid.c +6 -0
index 749d07a01772..9ada0ccf50df 100644
@@ -3393,6 +3393,7 @@ static int
  do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
  		   const u8 *video_db, u8 video_len)
  {
+	struct drm_display_info *info = &connector->display_info;
  	int modes = 0, offset = 0, i, multi_present = 0, multi_len;
  	u8 vic_len, hdmi_3d_len = 0;
  	u16 mask;
@@ -3520,6 +3521,8 @@ do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
  	}
 
  out:
+	if (modes > 0)
+		info->has_hdmi_infoframe = true;
  	return modes;
  }
 
@@ -4243,6 +4246,8 @@ static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
  	struct drm_display_info *display = &connector->display_info;
  	struct drm_hdmi_info *hdmi = &display->hdmi;
 
+	display->has_hdmi_infoframe = true;
+
  	if (hf_vsdb[6] & 0x80) {
  		hdmi->scdc.supported = true;
  		if (hf_vsdb[6] & 0x40)
@@ -4416,6 +4421,7 @@ static void drm_add_display_info(struct drm_connector *connector,
  	info->cea_rev = 0;
  	info->max_tmds_clock = 0;
  	info->dvi_dual = false;
+	info->has_hdmi_infoframe = false;
 
  	if (edid->revision < 3)
  		return;

drivers/gpu/drm/drm_edid.c s3d_structure_from_display_mode(const struct drm_display_mode *mode) · line 4912

Quoted 4 lines
drivers/gpu/drm/drm_edid.c +1 -0
@@ -4903,6 +4909,7 @@ s3d_structure_from_display_mode(const struct drm_display_mode *mode)
   * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
   * data from a DRM display mode
   * @frame: HDMI vendor infoframe
+ * @connector: the connector

I remember our old discussion where we realized that we will need this connector for all types of infoframes, eventually, do you think we should start thinking about creating a wrapper like drm_any_infoframe_from_display_mode(), and pass connector and desired type to it ?Or I am getting too ambitious targeting this series :) ?

Quoted 222 lines
drivers/gpu/drm/drm_edid.c +21 -6
   * @mode: DRM display mode
   *
   * Note that there's is a need to send HDMI vendor infoframes only when using a
@@ -4913,8 +4920,15 @@ s3d_structure_from_display_mode(const struct drm_display_mode *mode)
   */
  int
  drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+					    struct drm_connector *connector,
  					    const struct drm_display_mode *mode)
  {
+	/*
+	 * FIXME: sil-sii8620 doesn't have a connector around when
+	 * we need one, so we have to be prepared for a NULL connector.
+	 */
+	bool has_hdmi_infoframe = connector ?
+		connector->display_info.has_hdmi_infoframe : false;
  	int err;
  	u32 s3d_flags;
  	u8 vic;
@@ -4922,11 +4936,21 @@ drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
  	if (!frame || !mode)
  		return -EINVAL;
 
+	if (!has_hdmi_infoframe)
+		return -EINVAL;
+
  	vic = drm_match_hdmi_mode(mode);
  	s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
 
-	if (!vic && !s3d_flags)
-		return -EINVAL;
+	/*
+	 * Even if it's not absolutely necessary to send the infoframe
+	 * (ie.vic==0 and s3d_struct==0) we will still send it if we
+	 * know that the sink can handle it. This is based on a
+	 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
+	 * have trouble realizing that they shuld switch from 3D to 2D
+	 * mode if the source simply stops sending the infoframe when
+	 * it wants to switch from 3D to 2D.
+	 */
 
  	if (vic && s3d_flags)
  		return -EINVAL;
@@ -4935,10 +4959,8 @@ drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
  	if (err < 0)
  		return err;
 
-	if (vic)
-		frame->vic = vic;
-	else
-		frame->s3d_struct = s3d_structure_from_display_mode(mode);
+	frame->vic = vic;
+	frame->s3d_struct = s3d_structure_from_display_mode(mode);
 
  	return 0;
  }
drivers/gpu/drm/exynos/exynos_hdmi.c +1 -1
index 0109ff40b1db..812b2773ed69 100644
@@ -795,7 +795,7 @@ static void hdmi_reg_infoframes(struct hdmi_context *hdata)
  	}
 
  	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frm.vendor.hdmi,
-			&hdata->current_mode);
+			&hdata->connector, &hdata->current_mode);
  	if (!ret)
  		ret = hdmi_vendor_infoframe_pack(&frm.vendor.hdmi, buf,
  				sizeof(buf));
drivers/gpu/drm/i915/intel_hdmi.c +8 -6
index 2d95db64cdf2..2ccba4ccf7ad 100644
@@ -512,12 +512,14 @@ static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder,
 
  static void
  intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
-			      const struct intel_crtc_state *crtc_state)
+			      const struct intel_crtc_state *crtc_state,
+			      const struct drm_connector_state *conn_state)
  {
  	union hdmi_infoframe frame;
  	int ret;
 
  	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							  conn_state->connector,
  							  &crtc_state->base.adjusted_mode);
  	if (ret < 0)
  		return;
@@ -584,7 +586,7 @@ static void g4x_set_infoframes(struct drm_encoder *encoder,
 
  	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
 
  static bool hdmi_sink_is_deep_color(const struct drm_connector_state *conn_state)
@@ -725,7 +727,7 @@ static void ibx_set_infoframes(struct drm_encoder *encoder,
 
  	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
 
  static void cpt_set_infoframes(struct drm_encoder *encoder,
@@ -768,7 +770,7 @@ static void cpt_set_infoframes(struct drm_encoder *encoder,
 
  	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
 
  static void vlv_set_infoframes(struct drm_encoder *encoder,
@@ -821,7 +823,7 @@ static void vlv_set_infoframes(struct drm_encoder *encoder,
 
  	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
 
  static void hsw_set_infoframes(struct drm_encoder *encoder,
@@ -854,7 +856,7 @@ static void hsw_set_infoframes(struct drm_encoder *encoder,
 
  	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
 
  void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
drivers/gpu/drm/mediatek/mtk_hdmi.c +2 -1
index b78791061983..59a11026dceb 100644
@@ -1054,7 +1054,8 @@ static int mtk_hdmi_setup_vendor_specific_infoframe(struct mtk_hdmi *hdmi,
  	u8 buffer[10];
  	ssize_t err;
 
-	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
+	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame,
+							  &hdmi->conn, mode);
  	if (err) {
  		dev_err(hdmi->dev,
  			"Failed to get vendor infoframe from mode: %zd\n", err);
drivers/gpu/drm/nouveau/nv50_display.c +2 -1
index b26a506d20ca..9d7b2afd7cfc 100644
@@ -2754,7 +2754,8 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
  			= hdmi_infoframe_pack(&avi_frame, args.infoframes, 17);
  	}
 
-	ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi, mode);
+	ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi,
+							  &nv_connector->base, mode);
  	if (!ret) {
  		/* We have a Vendor InfoFrame, populate it to the display */
  		args.pwr.vendor_infoframe_length
drivers/gpu/drm/rockchip/inno_hdmi.c +1 -0
index ee584d87111f..fab30927a889 100644
@@ -282,6 +282,7 @@ static int inno_hdmi_config_video_vsi(struct inno_hdmi *hdmi,
  	int rc;
 
  	rc = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							 &hdmi->connector,
  							 mode);
 
  	return inno_hdmi_upload_frame(hdmi, rc, &frame, INFOFRAME_VSI,
drivers/gpu/drm/sti/sti_hdmi.c +3 -1
index d1902750a85d..c3b292ab17a5 100644
@@ -515,7 +515,9 @@ static int hdmi_vendor_infoframe_config(struct sti_hdmi *hdmi)
 
  	DRM_DEBUG_DRIVER("\n");
 
-	ret = drm_hdmi_vendor_infoframe_from_display_mode(&infoframe, mode);
+	ret = drm_hdmi_vendor_infoframe_from_display_mode(&infoframe,
+							  hdmi->drm_connector,
+							  mode);
  	if (ret < 0) {
  		/*
  		 * Going into that statement does not means vendor infoframe
drivers/gpu/drm/zte/zx_hdmi.c +1 -0
index b8abb1b496ff..13ea90f7a185 100644
@@ -108,6 +108,7 @@ static int zx_hdmi_config_video_vsi(struct zx_hdmi *hdmi,
  	int ret;
 
  	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							  &hdmi->connector,
  							  mode);
  	if (ret) {
  		DRM_DEV_ERROR(hdmi->dev, "failed to get vendor infoframe: %d\n",
include/drm/drm_connector.h +5 -0
index 2b97d1e28f60..1543212b0449 100644
@@ -270,6 +270,11 @@ struct drm_display_info {
  	bool dvi_dual;
 
  	/**
+	 * @has_hdmi_infoframe: Does the sink support the HDMI infoframe?
+	 */
+	bool has_hdmi_infoframe;
+
+	/**
  	 * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
  	 * more stuff redundant with @bus_formats.
  	 */
include/drm/drm_edid.h +0 -0
index 9e4e23524840..3c8740ad1db6 100644

include/drm/drm_edid.h drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 362

Quoted 7 lines
include/drm/drm_edid.h +1 -0
@@ -356,6 +356,7 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
  					 bool is_hdmi2_sink);
  int
  drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+					    struct drm_connector *connector,
  					    const struct drm_display_mode *mode);
  void
  drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,

Otherwise looks good
- Shashank
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#16 lore raw

Re: [PATCH 06/10] drm/edid: Fix cea mode aspect ratio handling

In reply to Ville Syrjala

Regards

Shashank

Quoted 37 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

commit 6dffd431e229 ("drm: Add aspect ratio parsing in DRM layer") cause us to not send out any VICs in the AVI infoframes. That commit was since reverted, but if and when we add aspect ratio handing back we need to be more careful.

Let's handle this by considering the aspect ratio as a requirement for cea mode matching only if the passed in mode actually has a non-zero aspect ratio field. This will keep userspace that doesn't provide an aspect ratio working as before by matching it to the first otherwise equal cea mode. And once userspace starts to provide the aspect ratio it will be considerd a hard requirement for the match.

Also change the hdmi mode matching to use drm_mode_match() for consistency, but we don't match on aspect ratio there since the spec doesn't list a specific aspect ratio for those modes.

Cc Shashank Sharma <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Akashdeep Sharma <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
  drivers/gpu/drm/drm_edid.c | 18 ++++++++++++++----
  1 file changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_edid.c +0 -0
index 7220b8f9a7e8..00aa98f3e55d 100644
@@ -2903,11 +2903,15 @@ cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
  static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,

drivers/gpu/drm/drm_edid.c cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode) · line 2913

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +3 -0
  					     unsigned int clock_tolerance)
  {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  	u8 vic;
 
  	if (!to_match->clock)
  		return 0;
 
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

This doesn't look right. This means we are expecting a CEA mode without a pic aspect ratio field,
which is invalid. Ankit is going to publish the aspect ratio patch series again, with proper DRM cap and flags check. Would it be ok if we have a look that handling first ?

Quoted 15 lines
drivers/gpu/drm/drm_edid.c +2 -1
+
  	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
  		struct drm_display_mode cea_mode = edid_cea_modes[vic];
  		unsigned int clock1, clock2;
@@ -2921,7 +2925,7 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
  			continue;
 
  		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
  				return vic;
  		} while (cea_mode_alternate_timings(vic, &cea_mode));
  	}
@@ -2938,11 +2942,15 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
   */

drivers/gpu/drm/drm_edid.c static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m · line 2952

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +3 -0
  u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
  {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  	u8 vic;
 
  	if (!to_match->clock)
  		return 0;
 
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

same here, and probably in other CEA match functions.

Quoted 39 lines
drivers/gpu/drm/drm_edid.c +5 -2
+
  	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
  		struct drm_display_mode cea_mode = edid_cea_modes[vic];
  		unsigned int clock1, clock2;
@@ -2956,7 +2964,7 @@ u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
  			continue;
 
  		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
  				return vic;
  		} while (cea_mode_alternate_timings(vic, &cea_mode));
  	}
@@ -3003,6 +3011,7 @@ hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
  static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
  					      unsigned int clock_tolerance)
  {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  	u8 vic;
 
  	if (!to_match->clock)
@@ -3020,7 +3029,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
  		    abs(to_match->clock - clock2) > clock_tolerance)
  			continue;
 
-		if (drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		if (drm_mode_match(to_match, hdmi_mode, match_flags))
  			return vic;
  	}
 
@@ -3037,6 +3046,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
   */
  static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
  {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  	u8 vic;
 
  	if (!to_match->clock)

drivers/gpu/drm/drm_edid.c static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match) · line 3068

Quoted 8 lines
drivers/gpu/drm/drm_edid.c +1 -1
@@ -3052,7 +3062,7 @@ static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
 
  		if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
  		     KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
-		    drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		    drm_mode_match(to_match, hdmi_mode, match_flags))
  			return vic;
  	}
  	return 0;

- Shashank
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#27 lore raw

Re: [PATCH 07/10] drm/edid: Don't send bogus aspect ratios in AVI infoframes

In reply to Ville Syrjala

Regards

Shashank

Quoted 36 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

If the user mode would specify an aspect ratio other than 4:3 or 16:9 we now silently ignore it. Maybe a better apporoach is to return an error? Let's try that.

Also we must be careful that we don't try to send illegal picture aspect in the infoframe as it's only capable of signalling none, 4:3, and 16:9. Currently we're sending these bogus infoframes whenever the cea mode specifies some other aspect ratio.

Cc Shashank Sharma <[email protected]>
Cc Sean Paul <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
  drivers/gpu/drm/drm_edid.c | 23 +++++++++++++++++------
  1 file changed, 17 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 00aa98f3e55d..bafb3ee4ea97 100644
@@ -4786,6 +4786,7 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
  					 const struct drm_display_mode *mode,
  					 bool is_hdmi2_sink)
  {
+	enum hdmi_picture_aspect picture_aspect;
  	int err;
 
  	if (!frame || !mode)
@@ -4828,13 +4829,23 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
  	 * Populate picture aspect ratio from either
  	 * user input (if specified) or from the CEA mode list.

drivers/gpu/drm/drm_edid.c drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 4834

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +3 -6
  	 */
-	if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
-		mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
-		frame->picture_aspect = mode->picture_aspect_ratio;
-	else if (frame->video_code > 0)
-		frame->picture_aspect = drm_get_cea_aspect_ratio(
-						frame->video_code);
+	picture_aspect = mode->picture_aspect_ratio;
+	if (picture_aspect == HDMI_PICTURE_ASPECT_NONE)
+		picture_aspect = drm_get_cea_aspect_ratio(frame->video_code);

This is slightly going in the loop.
- During the modeset the driver cant specify the aspect ratio information, as DRM layer lacks this support.
- So we fill the VIC field, by comparing the mode with the DRM_CEA_MODES[] list. This will pick the first mode available in the list (regardless of its aspect ratio), and fill the
VIC, as we don't consider aspect ratio while comparing timings.
- Again, now while sending the aspect ratio, we are picking up the VIC, which may not be correct.

So if we have 720x480(4:3) and 720x480(16:9) in the list, as 4:3 is first in list, we will always pick 4:3 aspect ratio.

- Shashank

Quoted 7 lines
drivers/gpu/drm/drm_edid.c +6 -0
+	/*
+	 * The infoframe can't convey anything but none, 4:3
+	 * and 16:9, so if the user has asked for anything else
+	 * we can only satisfy it by specifying the right VIC.
+	 */
+	if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {

drivers/gpu/drm/drm_edid.c drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 4851

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +7 -0
+		if (picture_aspect !=
+		    drm_get_cea_aspect_ratio(frame->video_code))
+			return -EINVAL;
+		picture_aspect = HDMI_PICTURE_ASPECT_NONE;
+	}
+
+	frame->picture_aspect = picture_aspect;
  	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
  	frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Re: [PATCH 01/10] video/hdmi: Allow "empty" HDMI infoframes

In reply to Sharma, Shashank
Quoted 76 lines · Shashank

Regards

Shashank

Quoted 70 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

HDMI 2.0 Appendix F suggest that we should keep sending the infoframe when switching from 3D to 2D mode, even if the infoframe isn't strictly necessary (ie. not needed to transmit the VIC or stereo information). This is a workaround against some sinks that fail to realize that they should switch from 3D to 2D mode when the source stop transmitting the infoframe.

v2: Handle unpack() as well
Pull the length calculation into a helper

---
  drivers/video/hdmi.c | 51 +++++++++++++++++++++++++++++++--------------------
  1 file changed, 31 insertions(+), 20 deletions(-)
drivers/video/hdmi.c +12 -9
index 1cf907ecded4..111a0ab6280a 100644
@@ -321,6 +321,17 @@ int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame)
  }
  EXPORT_SYMBOL(hdmi_vendor_infoframe_init);
 
+static int hdmi_vendor_infoframe_length(const struct hdmi_vendor_infoframe *frame)
+{
+	/* for side by side (half) we also need to provide 3D_Ext_Data */
+	if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
+		return 6;
+	else if (frame->vic != 0 || frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
+		return 5;
+	else
+		return 4;
+}
+
  /**
   * hdmi_vendor_infoframe_pack() - write a HDMI vendor infoframe to binary buffer
   * @frame: HDMI infoframe
@@ -341,19 +352,11 @@ ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
  	u8 *ptr = buffer;
  	size_t length;
 
-	/* empty info frame */
-	if (frame->vic == 0 && frame->s3d_struct == HDMI_3D_STRUCTURE_INVALID)
-		return -EINVAL;
-
  	/* only one of those can be supplied */
  	if (frame->vic != 0 && frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
  		return -EINVAL;
 
-	/* for side by side (half) we also need to provide 3D_Ext_Data */
-	if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
-		frame->length = 6;
-	else
-		frame->length = 5;
+	frame->length = hdmi_vendor_infoframe_length(frame);
 
  	length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
 
@@ -372,14 +375,16 @@ ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
  	ptr[5] = 0x0c;
  	ptr[6] = 0x00;
 
Quoted 13 lines

drivers/video/hdmi.c ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame, · line 383

Quoted 10 lines
drivers/video/hdmi.c +2 -4
-	if (frame->vic) {
-		ptr[7] = 0x1 << 5;	/* video format */
-		ptr[8] = frame->vic;
-	} else {
+	if (frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID) {
  		ptr[7] = 0x2 << 5;	/* video format */
  		ptr[8] = (frame->s3d_struct & 0xf) << 4;
  		if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
  			ptr[9] = (frame->s3d_ext_data & 0xf) << 4;
+	} else if (frame->vic) {

Please correct me if I dint understand this properly, but for a HDMI 2.0 sink + 3D transmission, wouldn't I be sending
HDMI 2.0 VIC = 94 as well as some valid s3d flag (like side by side) ?

That vic will be in the AVI infoframe. Here we're concerned about the VIC in the HDMI vendor infoframe.

Quoted 47 lines

- Shashank

Quoted 45 lines
drivers/video/hdmi.c +17 -7
+		ptr[7] = 0x1 << 5;	/* video format */
+		ptr[8] = frame->vic;
+	} else {
+		ptr[7] = 0x0 << 5;	/* video format */
  	}
 
  	hdmi_infoframe_set_checksum(buffer, length);
@@ -1165,7 +1170,7 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 
  	if (ptr[0] != HDMI_INFOFRAME_TYPE_VENDOR ||
  	    ptr[1] != 1 ||
-	    (ptr[2] != 5 && ptr[2] != 6))
+	    (ptr[2] != 4 && ptr[2] != 5 && ptr[2] != 6))
  		return -EINVAL;
 
  	length = ptr[2];
@@ -1193,16 +1198,22 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 
  	hvf->length = length;
 
-	if (hdmi_video_format == 0x1) {
-		hvf->vic = ptr[4];
-	} else if (hdmi_video_format == 0x2) {
+	if (hdmi_video_format == 0x2) {
+		if (length != 5 && length != 6)
+			return -EINVAL;
  		hvf->s3d_struct = ptr[4] >> 4;
  		if (hvf->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF) {
-			if (length == 6)
-				hvf->s3d_ext_data = ptr[5] >> 4;
-			else
+			if (length != 6)
  				return -EINVAL;
+			hvf->s3d_ext_data = ptr[5] >> 4;
  		}
+	} else if (hdmi_video_format == 0x1) {
+		if (length != 5)
+			return -EINVAL;
+		hvf->vic = ptr[4];
+	} else {
+		if (length != 4)
+			return -EINVAL;
  	}
 
  	return 0;
Signature · 2 lines
Ville Syrjälä
Intel OTC
#7 lore raw

Re: [PATCH 02/10] drm/edid: Allow HDMI infoframe without VIC or S3D

In reply to Sharma, Shashank
Quoted 37 lines · Shashank

Regards

Shashank

Quoted 9 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

Appedix F of HDMI 2.0 says that some HDMI sink may fail to switch from 3D to 2D mode in a timely fashion if the source simply stops sending the HDMI infoframe. The suggested workaround is to keep sending the infoframe even when strictly not necessary (ie. no VIC and no S3D). HDMI 1.4 does allow for this behaviour, stating that sending the infoframe is optional in this case.

Quoted 9 lines

The infoframe was first specified in HDMI 1.4, so in theory sinks predating that may not appreciate us sending an uknown infoframe their way. To avoid regressions let's try to determine if the sink supports the infoframe or not. Unfortunately there's no direct way to do that, so instead we'll just check if we managed to parse any HDMI 1.4 4k or stereo modes from the EDID, and if so we assume the sink will accept the infoframe. Also if the EDID contains the HDMI 2.0 HDMI Forum VSDB we can assume the sink is prepared to receive the infoframe.

I am trying to get some sense from HDMI 2.0 spec section 10.2.1, which talks about
switch from 3D to 2D. To me it looks like:
If (sending_to_hdmi2_sinks) {
- for 3d modes send HF-VSIF
- for 2d modes && defined in H14b HFVSIF, send H14B-VSIF When you switch from 3d->2d {
- send_HF-VSIF with 3D_valid bit = 0/1
}
} else { /* HDMI 1.4b sinks from Appendix F */
- send H14b-VSIF with HDMI_video_format[2:0 = 0 OR 1]
}

Quoted 1 line

Should we add a is_hdmi2 check and separate these cases ?

We don't support the HDMI forum infoframe. Maybe someone forgot to implement that when adding the rest of HDMI 2.0 support? ;)

Quoted 335 lines
Quoted 94 lines

v2: Fix the getting has_hdmi_infoframe from display_info
Always fail constructing the infoframe if the display possibly can't handle it

Cc Shashank Sharma <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
  drivers/gpu/drm/bridge/sil-sii8620.c      |  3 ++-
  drivers/gpu/drm/bridge/synopsys/dw-hdmi.c |  4 +++-
  drivers/gpu/drm/drm_edid.c                | 34 +++++++++++++++++++++++++------
  drivers/gpu/drm/exynos/exynos_hdmi.c      |  2 +-
  drivers/gpu/drm/i915/intel_hdmi.c         | 14 +++++++------
  drivers/gpu/drm/mediatek/mtk_hdmi.c       |  3 ++-
  drivers/gpu/drm/nouveau/nv50_display.c    |  3 ++-
  drivers/gpu/drm/rockchip/inno_hdmi.c      |  1 +
  drivers/gpu/drm/sti/sti_hdmi.c            |  4 +++-
  drivers/gpu/drm/zte/zx_hdmi.c             |  1 +
  include/drm/drm_connector.h               |  5 +++++
  include/drm/drm_edid.h                    |  1 +
  12 files changed, 57 insertions(+), 18 deletions(-)
drivers/gpu/drm/bridge/sil-sii8620.c +2 -1
index b7eb704d0a8a..4417276ba02e 100644
@@ -2220,8 +2220,9 @@ static bool sii8620_mode_fixup(struct drm_bridge *bridge,
  			union hdmi_infoframe frm;
  			u8 mhl_vic[] = { 0, 95, 94, 93, 98 };
 
+			/* FIXME: We need the connector here */
  			drm_hdmi_vendor_infoframe_from_display_mode(
-				&frm.vendor.hdmi, adjusted_mode);
+				&frm.vendor.hdmi, NULL, adjusted_mode);
  			vic = frm.vendor.hdmi.vic;
  			if (vic >= ARRAY_SIZE(mhl_vic))
  				vic = 0;
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +3 -1
index a64ce7112288..b172139502d6 100644
@@ -1437,7 +1437,9 @@ static void hdmi_config_vendor_specific_infoframe(struct dw_hdmi *hdmi,
  	u8 buffer[10];
  	ssize_t err;
 
-	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
+	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame,
+							  &hdmi->connector,
+							  mode);
  	if (err < 0)
  		/*
  		 * Going into that statement does not means vendor infoframe
drivers/gpu/drm/drm_edid.c +6 -0
index 749d07a01772..9ada0ccf50df 100644
@@ -3393,6 +3393,7 @@ static int
  do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
  		   const u8 *video_db, u8 video_len)
  {
+	struct drm_display_info *info = &connector->display_info;
  	int modes = 0, offset = 0, i, multi_present = 0, multi_len;
  	u8 vic_len, hdmi_3d_len = 0;
  	u16 mask;
@@ -3520,6 +3521,8 @@ do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
  	}
 
  out:
+	if (modes > 0)
+		info->has_hdmi_infoframe = true;
  	return modes;
  }
 
@@ -4243,6 +4246,8 @@ static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
  	struct drm_display_info *display = &connector->display_info;
  	struct drm_hdmi_info *hdmi = &display->hdmi;
 
+	display->has_hdmi_infoframe = true;
+
  	if (hf_vsdb[6] & 0x80) {
  		hdmi->scdc.supported = true;
  		if (hf_vsdb[6] & 0x40)
@@ -4416,6 +4421,7 @@ static void drm_add_display_info(struct drm_connector *connector,
  	info->cea_rev = 0;
  	info->max_tmds_clock = 0;
  	info->dvi_dual = false;
+	info->has_hdmi_infoframe = false;
 
  	if (edid->revision < 3)
  		return;

drivers/gpu/drm/drm_edid.c s3d_structure_from_display_mode(const struct drm_display_mode *mode) · line 4912

Quoted 4 lines
drivers/gpu/drm/drm_edid.c +1 -0
@@ -4903,6 +4909,7 @@ s3d_structure_from_display_mode(const struct drm_display_mode *mode)
   * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
   * data from a DRM display mode
   * @frame: HDMI vendor infoframe
+ * @connector: the connector

I remember our old discussion where we realized that we will need this connector for all types of infoframes,
eventually, do you think we should start thinking about creating a wrapper like drm_any_infoframe_from_display_mode(),
and pass connector and desired type to it ?Or I am getting too ambitious targeting this series :) ?

Quoted 222 lines
drivers/gpu/drm/drm_edid.c +21 -6
   * @mode: DRM display mode
   *
   * Note that there's is a need to send HDMI vendor infoframes only when using a
@@ -4913,8 +4920,15 @@ s3d_structure_from_display_mode(const struct drm_display_mode *mode)
   */
  int
  drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+					    struct drm_connector *connector,
  					    const struct drm_display_mode *mode)
  {
+	/*
+	 * FIXME: sil-sii8620 doesn't have a connector around when
+	 * we need one, so we have to be prepared for a NULL connector.
+	 */
+	bool has_hdmi_infoframe = connector ?
+		connector->display_info.has_hdmi_infoframe : false;
  	int err;
  	u32 s3d_flags;
  	u8 vic;
@@ -4922,11 +4936,21 @@ drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
  	if (!frame || !mode)
  		return -EINVAL;
 
+	if (!has_hdmi_infoframe)
+		return -EINVAL;
+
  	vic = drm_match_hdmi_mode(mode);
  	s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
 
-	if (!vic && !s3d_flags)
-		return -EINVAL;
+	/*
+	 * Even if it's not absolutely necessary to send the infoframe
+	 * (ie.vic==0 and s3d_struct==0) we will still send it if we
+	 * know that the sink can handle it. This is based on a
+	 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
+	 * have trouble realizing that they shuld switch from 3D to 2D
+	 * mode if the source simply stops sending the infoframe when
+	 * it wants to switch from 3D to 2D.
+	 */
 
  	if (vic && s3d_flags)
  		return -EINVAL;
@@ -4935,10 +4959,8 @@ drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
  	if (err < 0)
  		return err;
 
-	if (vic)
-		frame->vic = vic;
-	else
-		frame->s3d_struct = s3d_structure_from_display_mode(mode);
+	frame->vic = vic;
+	frame->s3d_struct = s3d_structure_from_display_mode(mode);
 
  	return 0;
  }
drivers/gpu/drm/exynos/exynos_hdmi.c +1 -1
index 0109ff40b1db..812b2773ed69 100644
@@ -795,7 +795,7 @@ static void hdmi_reg_infoframes(struct hdmi_context *hdata)
  	}
 
  	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frm.vendor.hdmi,
-			&hdata->current_mode);
+			&hdata->connector, &hdata->current_mode);
  	if (!ret)
  		ret = hdmi_vendor_infoframe_pack(&frm.vendor.hdmi, buf,
  				sizeof(buf));
drivers/gpu/drm/i915/intel_hdmi.c +8 -6
index 2d95db64cdf2..2ccba4ccf7ad 100644
@@ -512,12 +512,14 @@ static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder,
 
  static void
  intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
-			      const struct intel_crtc_state *crtc_state)
+			      const struct intel_crtc_state *crtc_state,
+			      const struct drm_connector_state *conn_state)
  {
  	union hdmi_infoframe frame;
  	int ret;
 
  	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							  conn_state->connector,
  							  &crtc_state->base.adjusted_mode);
  	if (ret < 0)
  		return;
@@ -584,7 +586,7 @@ static void g4x_set_infoframes(struct drm_encoder *encoder,
 
  	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
 
  static bool hdmi_sink_is_deep_color(const struct drm_connector_state *conn_state)
@@ -725,7 +727,7 @@ static void ibx_set_infoframes(struct drm_encoder *encoder,
 
  	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
 
  static void cpt_set_infoframes(struct drm_encoder *encoder,
@@ -768,7 +770,7 @@ static void cpt_set_infoframes(struct drm_encoder *encoder,
 
  	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
 
  static void vlv_set_infoframes(struct drm_encoder *encoder,
@@ -821,7 +823,7 @@ static void vlv_set_infoframes(struct drm_encoder *encoder,
 
  	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
 
  static void hsw_set_infoframes(struct drm_encoder *encoder,
@@ -854,7 +856,7 @@ static void hsw_set_infoframes(struct drm_encoder *encoder,
 
  	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  }
 
  void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
drivers/gpu/drm/mediatek/mtk_hdmi.c +2 -1
index b78791061983..59a11026dceb 100644
@@ -1054,7 +1054,8 @@ static int mtk_hdmi_setup_vendor_specific_infoframe(struct mtk_hdmi *hdmi,
  	u8 buffer[10];
  	ssize_t err;
 
-	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
+	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame,
+							  &hdmi->conn, mode);
  	if (err) {
  		dev_err(hdmi->dev,
  			"Failed to get vendor infoframe from mode: %zd\n", err);
drivers/gpu/drm/nouveau/nv50_display.c +2 -1
index b26a506d20ca..9d7b2afd7cfc 100644
@@ -2754,7 +2754,8 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
  			= hdmi_infoframe_pack(&avi_frame, args.infoframes, 17);
  	}
 
-	ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi, mode);
+	ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi,
+							  &nv_connector->base, mode);
  	if (!ret) {
  		/* We have a Vendor InfoFrame, populate it to the display */
  		args.pwr.vendor_infoframe_length
drivers/gpu/drm/rockchip/inno_hdmi.c +1 -0
index ee584d87111f..fab30927a889 100644
@@ -282,6 +282,7 @@ static int inno_hdmi_config_video_vsi(struct inno_hdmi *hdmi,
  	int rc;
 
  	rc = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							 &hdmi->connector,
  							 mode);
 
  	return inno_hdmi_upload_frame(hdmi, rc, &frame, INFOFRAME_VSI,
drivers/gpu/drm/sti/sti_hdmi.c +3 -1
index d1902750a85d..c3b292ab17a5 100644
@@ -515,7 +515,9 @@ static int hdmi_vendor_infoframe_config(struct sti_hdmi *hdmi)
 
  	DRM_DEBUG_DRIVER("\n");
 
-	ret = drm_hdmi_vendor_infoframe_from_display_mode(&infoframe, mode);
+	ret = drm_hdmi_vendor_infoframe_from_display_mode(&infoframe,
+							  hdmi->drm_connector,
+							  mode);
  	if (ret < 0) {
  		/*
  		 * Going into that statement does not means vendor infoframe
drivers/gpu/drm/zte/zx_hdmi.c +1 -0
index b8abb1b496ff..13ea90f7a185 100644
@@ -108,6 +108,7 @@ static int zx_hdmi_config_video_vsi(struct zx_hdmi *hdmi,
  	int ret;
 
  	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							  &hdmi->connector,
  							  mode);
  	if (ret) {
  		DRM_DEV_ERROR(hdmi->dev, "failed to get vendor infoframe: %d\n",
include/drm/drm_connector.h +5 -0
index 2b97d1e28f60..1543212b0449 100644
@@ -270,6 +270,11 @@ struct drm_display_info {
  	bool dvi_dual;
 
  	/**
+	 * @has_hdmi_infoframe: Does the sink support the HDMI infoframe?
+	 */
+	bool has_hdmi_infoframe;
+
+	/**
  	 * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
  	 * more stuff redundant with @bus_formats.
  	 */
include/drm/drm_edid.h +0 -0
index 9e4e23524840..3c8740ad1db6 100644

include/drm/drm_edid.h drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 362

Quoted 7 lines
include/drm/drm_edid.h +1 -0
@@ -356,6 +356,7 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
  					 bool is_hdmi2_sink);
  int
  drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+					    struct drm_connector *connector,
  					    const struct drm_display_mode *mode);
  void
  drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,

Otherwise looks good
- Shashank

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#17 lore raw

Re: [PATCH 06/10] drm/edid: Fix cea mode aspect ratio handling

In reply to Sharma, Shashank
Quoted 48 lines · Shashank

Regards

Shashank

Quoted 42 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

commit 6dffd431e229 ("drm: Add aspect ratio parsing in DRM layer") cause us to not send out any VICs in the AVI infoframes. That commit was since reverted, but if and when we add aspect ratio handing back we need to be more careful.

Let's handle this by considering the aspect ratio as a requirement for cea mode matching only if the passed in mode actually has a non-zero aspect ratio field. This will keep userspace that doesn't provide an aspect ratio working as before by matching it to the first otherwise equal cea mode. And once userspace starts to provide the aspect ratio it will be considerd a hard requirement for the match.

Also change the hdmi mode matching to use drm_mode_match() for consistency, but we don't match on aspect ratio there since the spec doesn't list a specific aspect ratio for those modes.

Cc Shashank Sharma <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Akashdeep Sharma <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
  drivers/gpu/drm/drm_edid.c | 18 ++++++++++++++----
  1 file changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 7220b8f9a7e8..00aa98f3e55d 100644
@@ -2903,11 +2903,15 @@ cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
  static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
  					     unsigned int clock_tolerance)
  {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  	u8 vic;
 
Quoted 8 lines

drivers/gpu/drm/drm_edid.c cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode) · line 2913

Quoted 5 lines
drivers/gpu/drm/drm_edid.c +2 -0
  	if (!to_match->clock)
  		return 0;
 
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

This doesn't look right. This means we are expecting a CEA mode without a pic aspect ratio field,
which is invalid.

No, it's perfectly valid. It's what we currently get from userspace.

Quoted 3 lines

Ankit is going to publish the aspect ratio patch series again, with proper DRM cap and flags check. Would it be ok if we have a look that handling first ?

This patch will be needed by that work. Otherwise we're going to stop sending a VIC for CEA modes with current userspace.

Quoted 74 lines
Quoted 15 lines
drivers/gpu/drm/drm_edid.c +2 -1
+
  	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
  		struct drm_display_mode cea_mode = edid_cea_modes[vic];
  		unsigned int clock1, clock2;
@@ -2921,7 +2925,7 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
  			continue;
 
  		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
  				return vic;
  		} while (cea_mode_alternate_timings(vic, &cea_mode));
  	}
@@ -2938,11 +2942,15 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
   */

drivers/gpu/drm/drm_edid.c static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m · line 2952

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +3 -0
  u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
  {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  	u8 vic;
 
  	if (!to_match->clock)
  		return 0;
 
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

same here, and probably in other CEA match functions.

Quoted 39 lines
drivers/gpu/drm/drm_edid.c +5 -2
+
  	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
  		struct drm_display_mode cea_mode = edid_cea_modes[vic];
  		unsigned int clock1, clock2;
@@ -2956,7 +2964,7 @@ u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
  			continue;
 
  		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
  				return vic;
  		} while (cea_mode_alternate_timings(vic, &cea_mode));
  	}
@@ -3003,6 +3011,7 @@ hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
  static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
  					      unsigned int clock_tolerance)
  {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  	u8 vic;
 
  	if (!to_match->clock)
@@ -3020,7 +3029,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
  		    abs(to_match->clock - clock2) > clock_tolerance)
  			continue;
 
-		if (drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		if (drm_mode_match(to_match, hdmi_mode, match_flags))
  			return vic;
  	}
 
@@ -3037,6 +3046,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
   */
  static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
  {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
  	u8 vic;
 
  	if (!to_match->clock)

drivers/gpu/drm/drm_edid.c static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match) · line 3068

Quoted 8 lines
drivers/gpu/drm/drm_edid.c +1 -1
@@ -3052,7 +3062,7 @@ static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
 
  		if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
  		     KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
-		    drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		    drm_mode_match(to_match, hdmi_mode, match_flags))
  			return vic;
  	}
  	return 0;

- Shashank

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#28 lore raw

Re: [PATCH 07/10] drm/edid: Don't send bogus aspect ratios in AVI infoframes

In reply to Sharma, Shashank
Quoted 62 lines · Shashank

Regards

Shashank

Quoted 36 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

If the user mode would specify an aspect ratio other than 4:3 or 16:9 we now silently ignore it. Maybe a better apporoach is to return an error? Let's try that.

Also we must be careful that we don't try to send illegal picture aspect in the infoframe as it's only capable of signalling none, 4:3, and 16:9. Currently we're sending these bogus infoframes whenever the cea mode specifies some other aspect ratio.

Cc Shashank Sharma <[email protected]>
Cc Sean Paul <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
  drivers/gpu/drm/drm_edid.c | 23 +++++++++++++++++------
  1 file changed, 17 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 00aa98f3e55d..bafb3ee4ea97 100644
@@ -4786,6 +4786,7 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
  					 const struct drm_display_mode *mode,
  					 bool is_hdmi2_sink)
  {
+	enum hdmi_picture_aspect picture_aspect;
  	int err;
 
  	if (!frame || !mode)
@@ -4828,13 +4829,23 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
  	 * Populate picture aspect ratio from either
  	 * user input (if specified) or from the CEA mode list.

drivers/gpu/drm/drm_edid.c drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 4834

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +3 -6
  	 */
-	if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
-		mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
-		frame->picture_aspect = mode->picture_aspect_ratio;
-	else if (frame->video_code > 0)
-		frame->picture_aspect = drm_get_cea_aspect_ratio(
-						frame->video_code);
+	picture_aspect = mode->picture_aspect_ratio;
+	if (picture_aspect == HDMI_PICTURE_ASPECT_NONE)
+		picture_aspect = drm_get_cea_aspect_ratio(frame->video_code);

This is slightly going in the loop.
- During the modeset the driver cant specify the aspect ratio information, as DRM layer lacks this support.
- So we fill the VIC field, by comparing the mode with the DRM_CEA_MODES[] list. This will pick the first mode available in the list (regardless of its aspect ratio), and fill the
VIC, as we don't consider aspect ratio while comparing timings.
- Again, now while sending the aspect ratio, we are picking up the VIC, which may not be correct.

Quoted 2 lines

So if we have 720x480(4:3) and 720x480(16:9) in the list, as 4:3 is first in list, we will always pick 4:3 aspect ratio.

Yes. The user didn't care about the aspect ratio (or rather couldn't specify one) so we just pick one. Which is exactly what we've been doing ever since we started sending the VIC in the infoframe.

Quoted 19 lines

- Shashank

Quoted 17 lines
drivers/gpu/drm/drm_edid.c +13 -0
+	/*
+	 * The infoframe can't convey anything but none, 4:3
+	 * and 16:9, so if the user has asked for anything else
+	 * we can only satisfy it by specifying the right VIC.
+	 */
+	if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {
+		if (picture_aspect !=
+		    drm_get_cea_aspect_ratio(frame->video_code))
+			return -EINVAL;
+		picture_aspect = HDMI_PICTURE_ASPECT_NONE;
+	}
+
+	frame->picture_aspect = picture_aspect;
  	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
  	frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
 
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by
#4 lore raw

Re: [PATCH 01/10] video/hdmi: Allow "empty" HDMI infoframes

In reply to Ville Syrjälä

Regards

Shashank

Quoted 90 lines · Ville Syrjälä
Quoted 76 lines · Shashank

Regards

Shashank

Quoted 70 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

HDMI 2.0 Appendix F suggest that we should keep sending the infoframe when switching from 3D to 2D mode, even if the infoframe isn't strictly necessary (ie. not needed to transmit the VIC or stereo information). This is a workaround against some sinks that fail to realize that they should switch from 3D to 2D mode when the source stop transmitting the infoframe.

v2: Handle unpack() as well
Pull the length calculation into a helper

---
   drivers/video/hdmi.c | 51 +++++++++++++++++++++++++++++++--------------------
   1 file changed, 31 insertions(+), 20 deletions(-)
drivers/video/hdmi.c +12 -9
index 1cf907ecded4..111a0ab6280a 100644
@@ -321,6 +321,17 @@ int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame)
   }
   EXPORT_SYMBOL(hdmi_vendor_infoframe_init);
 
+static int hdmi_vendor_infoframe_length(const struct hdmi_vendor_infoframe *frame)
+{
+	/* for side by side (half) we also need to provide 3D_Ext_Data */
+	if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
+		return 6;
+	else if (frame->vic != 0 || frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
+		return 5;
+	else
+		return 4;
+}
+
   /**
    * hdmi_vendor_infoframe_pack() - write a HDMI vendor infoframe to binary buffer
    * @frame: HDMI infoframe
@@ -341,19 +352,11 @@ ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
   	u8 *ptr = buffer;
   	size_t length;
 
-	/* empty info frame */
-	if (frame->vic == 0 && frame->s3d_struct == HDMI_3D_STRUCTURE_INVALID)
-		return -EINVAL;
-
   	/* only one of those can be supplied */
   	if (frame->vic != 0 && frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
   		return -EINVAL;
 
-	/* for side by side (half) we also need to provide 3D_Ext_Data */
-	if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
-		frame->length = 6;
-	else
-		frame->length = 5;
+	frame->length = hdmi_vendor_infoframe_length(frame);
 
   	length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
 
@@ -372,14 +375,16 @@ ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
   	ptr[5] = 0x0c;
   	ptr[6] = 0x00;
 
Quoted 13 lines

drivers/video/hdmi.c ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame, · line 383

Quoted 10 lines
drivers/video/hdmi.c +2 -4
-	if (frame->vic) {
-		ptr[7] = 0x1 << 5;	/* video format */
-		ptr[8] = frame->vic;
-	} else {
+	if (frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID) {
   		ptr[7] = 0x2 << 5;	/* video format */
   		ptr[8] = (frame->s3d_struct & 0xf) << 4;
   		if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
   			ptr[9] = (frame->s3d_ext_data & 0xf) << 4;
+	} else if (frame->vic) {

Please correct me if I dint understand this properly, but for a HDMI 2.0 sink + 3D transmission, wouldn't I be sending
HDMI 2.0 VIC = 94 as well as some valid s3d flag (like side by side) ?

Quoted 2 lines

That vic will be in the AVI infoframe. Here we're concerned about the VIC in the HDMI vendor infoframe.

Yep, I was thinking if there is any way we can cross check that there is a valid HDMI 2 vic before we do anything here, but seems like a long shot.

Quoted 45 lines
Quoted 45 lines

- Shashank

Quoted 44 lines
drivers/video/hdmi.c +17 -7
+		ptr[7] = 0x1 << 5;	/* video format */
+		ptr[8] = frame->vic;
+	} else {
+		ptr[7] = 0x0 << 5;	/* video format */
   	}
 
   	hdmi_infoframe_set_checksum(buffer, length);
@@ -1165,7 +1170,7 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 
   	if (ptr[0] != HDMI_INFOFRAME_TYPE_VENDOR ||
   	    ptr[1] != 1 ||
-	    (ptr[2] != 5 && ptr[2] != 6))
+	    (ptr[2] != 4 && ptr[2] != 5 && ptr[2] != 6))
   		return -EINVAL;
 
   	length = ptr[2];
@@ -1193,16 +1198,22 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 
   	hvf->length = length;
 
-	if (hdmi_video_format == 0x1) {
-		hvf->vic = ptr[4];
-	} else if (hdmi_video_format == 0x2) {
+	if (hdmi_video_format == 0x2) {
+		if (length != 5 && length != 6)
+			return -EINVAL;
   		hvf->s3d_struct = ptr[4] >> 4;
   		if (hvf->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF) {
-			if (length == 6)
-				hvf->s3d_ext_data = ptr[5] >> 4;
-			else
+			if (length != 6)
   				return -EINVAL;
+			hvf->s3d_ext_data = ptr[5] >> 4;
   		}
+	} else if (hdmi_video_format == 0x1) {
+		if (length != 5)
+			return -EINVAL;
+		hvf->vic = ptr[4];
+	} else {
+		if (length != 4)
+			return -EINVAL;
   	}
 
Quoted 1 line
Quoted 1 line

drivers/video/hdmi.c hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame, · line 1219

Quoted 1 line
drivers/video/hdmi.c +0 -0
   	return 0;

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reviewed-by
#8 lore raw

Re: [PATCH 02/10] drm/edid: Allow HDMI infoframe without VIC or S3D

In reply to Ville Syrjälä

Regards

Shashank

Quoted 38 lines · Ville Syrjälä
Quoted 37 lines · Shashank

Regards

Shashank

Quoted 9 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

Appedix F of HDMI 2.0 says that some HDMI sink may fail to switch from 3D to 2D mode in a timely fashion if the source simply stops sending the HDMI infoframe. The suggested workaround is to keep sending the infoframe even when strictly not necessary (ie. no VIC and no S3D). HDMI 1.4 does allow for this behaviour, stating that sending the infoframe is optional in this case.

Quoted 9 lines

The infoframe was first specified in HDMI 1.4, so in theory sinks predating that may not appreciate us sending an uknown infoframe their way. To avoid regressions let's try to determine if the sink supports the infoframe or not. Unfortunately there's no direct way to do that, so instead we'll just check if we managed to parse any HDMI 1.4 4k or stereo modes from the EDID, and if so we assume the sink will accept the infoframe. Also if the EDID contains the HDMI 2.0 HDMI Forum VSDB we can assume the sink is prepared to receive the infoframe.

I am trying to get some sense from HDMI 2.0 spec section 10.2.1, which talks about
switch from 3D to 2D. To me it looks like:
If (sending_to_hdmi2_sinks) {
- for 3d modes send HF-VSIF
- for 2d modes && defined in H14b HFVSIF, send H14B-VSIF When you switch from 3d->2d {
- send_HF-VSIF with 3D_valid bit = 0/1
}
} else { /* HDMI 1.4b sinks from Appendix F */
- send H14b-VSIF with HDMI_video_format[2:0 = 0 OR 1]
}

Quoted 3 lines
Quoted 1 line

Should we add a is_hdmi2 check and separate these cases ?

We don't support the HDMI forum infoframe. Maybe someone forgot to implement that when adding the rest of HDMI 2.0 support? ;)

How to make an 'embarrassed smile ' smiley :) ?
Will start looking into it. Meanwhile

Quoted 325 lines
Quoted 325 lines
Quoted 92 lines

v2: Fix the getting has_hdmi_infoframe from display_info
Always fail constructing the infoframe if the display possibly can't handle it

Cc Shashank Sharma <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
   drivers/gpu/drm/bridge/sil-sii8620.c      |  3 ++-
   drivers/gpu/drm/bridge/synopsys/dw-hdmi.c |  4 +++-
   drivers/gpu/drm/drm_edid.c                | 34 +++++++++++++++++++++++++------
   drivers/gpu/drm/exynos/exynos_hdmi.c      |  2 +-
   drivers/gpu/drm/i915/intel_hdmi.c         | 14 +++++++------
   drivers/gpu/drm/mediatek/mtk_hdmi.c       |  3 ++-
   drivers/gpu/drm/nouveau/nv50_display.c    |  3 ++-
   drivers/gpu/drm/rockchip/inno_hdmi.c      |  1 +
   drivers/gpu/drm/sti/sti_hdmi.c            |  4 +++-
   drivers/gpu/drm/zte/zx_hdmi.c             |  1 +
   include/drm/drm_connector.h               |  5 +++++
   include/drm/drm_edid.h                    |  1 +
   12 files changed, 57 insertions(+), 18 deletions(-)
drivers/gpu/drm/bridge/sil-sii8620.c +2 -1
index b7eb704d0a8a..4417276ba02e 100644
@@ -2220,8 +2220,9 @@ static bool sii8620_mode_fixup(struct drm_bridge *bridge,
   			union hdmi_infoframe frm;
   			u8 mhl_vic[] = { 0, 95, 94, 93, 98 };
 
+			/* FIXME: We need the connector here */
   			drm_hdmi_vendor_infoframe_from_display_mode(
-				&frm.vendor.hdmi, adjusted_mode);
+				&frm.vendor.hdmi, NULL, adjusted_mode);
   			vic = frm.vendor.hdmi.vic;
   			if (vic >= ARRAY_SIZE(mhl_vic))
   				vic = 0;
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +3 -1
index a64ce7112288..b172139502d6 100644
@@ -1437,7 +1437,9 @@ static void hdmi_config_vendor_specific_infoframe(struct dw_hdmi *hdmi,
   	u8 buffer[10];
   	ssize_t err;
 
-	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
+	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame,
+							  &hdmi->connector,
+							  mode);
   	if (err < 0)
   		/*
   		 * Going into that statement does not means vendor infoframe
drivers/gpu/drm/drm_edid.c +6 -0
index 749d07a01772..9ada0ccf50df 100644
@@ -3393,6 +3393,7 @@ static int
   do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
   		   const u8 *video_db, u8 video_len)
   {
+	struct drm_display_info *info = &connector->display_info;
   	int modes = 0, offset = 0, i, multi_present = 0, multi_len;
   	u8 vic_len, hdmi_3d_len = 0;
   	u16 mask;
@@ -3520,6 +3521,8 @@ do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
   	}
 
   out:
+	if (modes > 0)
+		info->has_hdmi_infoframe = true;
   	return modes;
   }
 
@@ -4243,6 +4246,8 @@ static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
   	struct drm_display_info *display = &connector->display_info;
   	struct drm_hdmi_info *hdmi = &display->hdmi;
 
+	display->has_hdmi_infoframe = true;
+
   	if (hf_vsdb[6] & 0x80) {
   		hdmi->scdc.supported = true;
   		if (hf_vsdb[6] & 0x40)
@@ -4416,6 +4421,7 @@ static void drm_add_display_info(struct drm_connector *connector,
   	info->cea_rev = 0;
   	info->max_tmds_clock = 0;
   	info->dvi_dual = false;
+	info->has_hdmi_infoframe = false;
 
   	if (edid->revision < 3)
   		return;

drivers/gpu/drm/drm_edid.c s3d_structure_from_display_mode(const struct drm_display_mode *mode) · line 4912

Quoted 4 lines
drivers/gpu/drm/drm_edid.c +1 -0
@@ -4903,6 +4909,7 @@ s3d_structure_from_display_mode(const struct drm_display_mode *mode)
    * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
    * data from a DRM display mode
    * @frame: HDMI vendor infoframe
+ * @connector: the connector

I remember our old discussion where we realized that we will need this connector for all types of infoframes,
eventually, do you think we should start thinking about creating a wrapper like drm_any_infoframe_from_display_mode(),
and pass connector and desired type to it ?Or I am getting too ambitious targeting this series :) ?

Quoted 223 lines
drivers/gpu/drm/drm_edid.c +21 -6
    * @mode: DRM display mode
    *
    * Note that there's is a need to send HDMI vendor infoframes only when using a
@@ -4913,8 +4920,15 @@ s3d_structure_from_display_mode(const struct drm_display_mode *mode)
    */
   int
   drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+					    struct drm_connector *connector,
   					    const struct drm_display_mode *mode)
   {
+	/*
+	 * FIXME: sil-sii8620 doesn't have a connector around when
+	 * we need one, so we have to be prepared for a NULL connector.
+	 */
+	bool has_hdmi_infoframe = connector ?
+		connector->display_info.has_hdmi_infoframe : false;
   	int err;
   	u32 s3d_flags;
   	u8 vic;
@@ -4922,11 +4936,21 @@ drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
   	if (!frame || !mode)
   		return -EINVAL;
 
+	if (!has_hdmi_infoframe)
+		return -EINVAL;
+
   	vic = drm_match_hdmi_mode(mode);
   	s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
 
-	if (!vic && !s3d_flags)
-		return -EINVAL;
+	/*
+	 * Even if it's not absolutely necessary to send the infoframe
+	 * (ie.vic==0 and s3d_struct==0) we will still send it if we
+	 * know that the sink can handle it. This is based on a
+	 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
+	 * have trouble realizing that they shuld switch from 3D to 2D
+	 * mode if the source simply stops sending the infoframe when
+	 * it wants to switch from 3D to 2D.
+	 */
 
   	if (vic && s3d_flags)
   		return -EINVAL;
@@ -4935,10 +4959,8 @@ drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
   	if (err < 0)
   		return err;
 
-	if (vic)
-		frame->vic = vic;
-	else
-		frame->s3d_struct = s3d_structure_from_display_mode(mode);
+	frame->vic = vic;
+	frame->s3d_struct = s3d_structure_from_display_mode(mode);
 
   	return 0;
   }
drivers/gpu/drm/exynos/exynos_hdmi.c +1 -1
index 0109ff40b1db..812b2773ed69 100644
@@ -795,7 +795,7 @@ static void hdmi_reg_infoframes(struct hdmi_context *hdata)
   	}
 
   	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frm.vendor.hdmi,
-			&hdata->current_mode);
+			&hdata->connector, &hdata->current_mode);
   	if (!ret)
   		ret = hdmi_vendor_infoframe_pack(&frm.vendor.hdmi, buf,
   				sizeof(buf));
drivers/gpu/drm/i915/intel_hdmi.c +8 -6
index 2d95db64cdf2..2ccba4ccf7ad 100644
@@ -512,12 +512,14 @@ static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder,
 
   static void
   intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
-			      const struct intel_crtc_state *crtc_state)
+			      const struct intel_crtc_state *crtc_state,
+			      const struct drm_connector_state *conn_state)
   {
   	union hdmi_infoframe frame;
   	int ret;
 
   	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							  conn_state->connector,
   							  &crtc_state->base.adjusted_mode);
   	if (ret < 0)
   		return;
@@ -584,7 +586,7 @@ static void g4x_set_infoframes(struct drm_encoder *encoder,
 
   	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
   	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
   }
 
   static bool hdmi_sink_is_deep_color(const struct drm_connector_state *conn_state)
@@ -725,7 +727,7 @@ static void ibx_set_infoframes(struct drm_encoder *encoder,
 
   	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
   	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
   }
 
   static void cpt_set_infoframes(struct drm_encoder *encoder,
@@ -768,7 +770,7 @@ static void cpt_set_infoframes(struct drm_encoder *encoder,
 
   	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
   	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
   }
 
   static void vlv_set_infoframes(struct drm_encoder *encoder,
@@ -821,7 +823,7 @@ static void vlv_set_infoframes(struct drm_encoder *encoder,
 
   	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
   	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
   }
 
   static void hsw_set_infoframes(struct drm_encoder *encoder,
@@ -854,7 +856,7 @@ static void hsw_set_infoframes(struct drm_encoder *encoder,
 
   	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
   	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
   }
 
   void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
drivers/gpu/drm/mediatek/mtk_hdmi.c +2 -1
index b78791061983..59a11026dceb 100644
@@ -1054,7 +1054,8 @@ static int mtk_hdmi_setup_vendor_specific_infoframe(struct mtk_hdmi *hdmi,
   	u8 buffer[10];
   	ssize_t err;
 
-	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
+	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame,
+							  &hdmi->conn, mode);
   	if (err) {
   		dev_err(hdmi->dev,
   			"Failed to get vendor infoframe from mode: %zd\n", err);
drivers/gpu/drm/nouveau/nv50_display.c +2 -1
index b26a506d20ca..9d7b2afd7cfc 100644
@@ -2754,7 +2754,8 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
   			= hdmi_infoframe_pack(&avi_frame, args.infoframes, 17);
   	}
 
-	ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi, mode);
+	ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi,
+							  &nv_connector->base, mode);
   	if (!ret) {
   		/* We have a Vendor InfoFrame, populate it to the display */
   		args.pwr.vendor_infoframe_length
drivers/gpu/drm/rockchip/inno_hdmi.c +1 -0
index ee584d87111f..fab30927a889 100644
@@ -282,6 +282,7 @@ static int inno_hdmi_config_video_vsi(struct inno_hdmi *hdmi,
   	int rc;
 
   	rc = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							 &hdmi->connector,
   							 mode);
 
   	return inno_hdmi_upload_frame(hdmi, rc, &frame, INFOFRAME_VSI,
drivers/gpu/drm/sti/sti_hdmi.c +3 -1
index d1902750a85d..c3b292ab17a5 100644
@@ -515,7 +515,9 @@ static int hdmi_vendor_infoframe_config(struct sti_hdmi *hdmi)
 
   	DRM_DEBUG_DRIVER("\n");
 
-	ret = drm_hdmi_vendor_infoframe_from_display_mode(&infoframe, mode);
+	ret = drm_hdmi_vendor_infoframe_from_display_mode(&infoframe,
+							  hdmi->drm_connector,
+							  mode);
   	if (ret < 0) {
   		/*
   		 * Going into that statement does not means vendor infoframe
drivers/gpu/drm/zte/zx_hdmi.c +1 -0
index b8abb1b496ff..13ea90f7a185 100644
@@ -108,6 +108,7 @@ static int zx_hdmi_config_video_vsi(struct zx_hdmi *hdmi,
   	int ret;
 
   	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							  &hdmi->connector,
   							  mode);
   	if (ret) {
   		DRM_DEV_ERROR(hdmi->dev, "failed to get vendor infoframe: %d\n",
include/drm/drm_connector.h +5 -0
index 2b97d1e28f60..1543212b0449 100644
@@ -270,6 +270,11 @@ struct drm_display_info {
   	bool dvi_dual;
 
   	/**
+	 * @has_hdmi_infoframe: Does the sink support the HDMI infoframe?
+	 */
+	bool has_hdmi_infoframe;
+
+	/**
   	 * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
   	 * more stuff redundant with @bus_formats.
   	 */
include/drm/drm_edid.h +0 -0
index 9e4e23524840..3c8740ad1db6 100644
@@ -356,6 +356,7 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
   					 bool is_hdmi2_sink);
Quoted 8 lines
Quoted 8 lines

include/drm/drm_edid.h drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 362

Quoted 6 lines
include/drm/drm_edid.h +1 -0
   int
   drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+					    struct drm_connector *connector,
   					    const struct drm_display_mode *mode);
   void
   drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,

Otherwise looks good
- Shashank

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#18 lore raw

Re: [PATCH 06/10] drm/edid: Fix cea mode aspect ratio handling

In reply to Ville Syrjälä

Regards

Shashank

Quoted 52 lines · Ville Syrjälä
Quoted 51 lines · Shashank

Regards

Shashank

Quoted 45 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

commit 6dffd431e229 ("drm: Add aspect ratio parsing in DRM layer") cause us to not send out any VICs in the AVI infoframes. That commit was since reverted, but if and when we add aspect ratio handing back we need to be more careful.

Let's handle this by considering the aspect ratio as a requirement for cea mode matching only if the passed in mode actually has a non-zero aspect ratio field. This will keep userspace that doesn't provide an aspect ratio working as before by matching it to the first otherwise equal cea mode. And once userspace starts to provide the aspect ratio it will be considerd a hard requirement for the match.

Also change the hdmi mode matching to use drm_mode_match() for consistency, but we don't match on aspect ratio there since the spec doesn't list a specific aspect ratio for those modes.

Cc Shashank Sharma <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Akashdeep Sharma <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
   drivers/gpu/drm/drm_edid.c | 18 ++++++++++++++----
   1 file changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 7220b8f9a7e8..00aa98f3e55d 100644
@@ -2903,11 +2903,15 @@ cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
   static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
   					     unsigned int clock_tolerance)
   {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
   	u8 vic;
 
   	if (!to_match->clock)
   		return 0;
 
Quoted 6 lines
Quoted 5 lines

drivers/gpu/drm/drm_edid.c cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode) · line 2913

Quoted 2 lines
drivers/gpu/drm/drm_edid.c +2 -0
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

This doesn't look right. This means we are expecting a CEA mode without a pic aspect ratio field,
which is invalid.

No, it's perfectly valid. It's what we currently get from userspace.

Yep, but that's due to missing Aspect ratio handling in the DRM layer. If that's fixed, as per the list of CEA modes, each CEA VIC contains an aspect ratio, which is a part of its unique identity.

I guess once we have the aspect ratio handling in DRM layer, it would/should look like this:
- EDID gives you all supported modes, including CEA modes with Aspect ratio
- Userspcae gets the mode information, with aspect ratio (for CEA modes)
If ( Userspace picks one of the CEA modes)
- sends a modeset
- we find a matching CEA VIC, found one from modedb
- we load this VIC = nonzero information in AVI IF VIC field,
else
- sends a modeset
- we could not find a matching CEA VIC, as aspect ratio is 0
- we make VIC field in AVI IF as 0

This is important, as HDMI compliance test 7-27 inspects if the VIC field in the AVI IF is accurate.

- Shashank

Quoted 5 lines
Quoted 3 lines

Ankit is going to publish the aspect ratio patch series again, with proper DRM cap and flags check. Would it be ok if we have a look that handling first ?

This patch will be needed by that work. Otherwise we're going to stop sending a VIC for CEA modes with current userspace.

I guess we should force userspaces to start bothering about aspect ratio field, right now we are doing this for Wayland based compositors, may be we should extend it to X based too.

- Shashank

Quoted 67 lines
Quoted 67 lines
Quoted 16 lines
drivers/gpu/drm/drm_edid.c +2 -1
+
   	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
   		struct drm_display_mode cea_mode = edid_cea_modes[vic];
   		unsigned int clock1, clock2;
@@ -2921,7 +2925,7 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
   			continue;
 
   		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
   				return vic;
   		} while (cea_mode_alternate_timings(vic, &cea_mode));
   	}
@@ -2938,11 +2942,15 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
    */

drivers/gpu/drm/drm_edid.c static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m · line 2952

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +3 -0
   u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
   {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
   	u8 vic;
 
   	if (!to_match->clock)
   		return 0;
 
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

same here, and probably in other CEA match functions.

Quoted 40 lines
drivers/gpu/drm/drm_edid.c +5 -2
+
   	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
   		struct drm_display_mode cea_mode = edid_cea_modes[vic];
   		unsigned int clock1, clock2;
@@ -2956,7 +2964,7 @@ u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
   			continue;
 
   		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
   				return vic;
   		} while (cea_mode_alternate_timings(vic, &cea_mode));
   	}
@@ -3003,6 +3011,7 @@ hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
   static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
   					      unsigned int clock_tolerance)
   {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
   	u8 vic;
 
   	if (!to_match->clock)
@@ -3020,7 +3029,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
   		    abs(to_match->clock - clock2) > clock_tolerance)
   			continue;
 
-		if (drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		if (drm_mode_match(to_match, hdmi_mode, match_flags))
   			return vic;
   	}
 
@@ -3037,6 +3046,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
    */
   static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
   {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
   	u8 vic;
 
   	if (!to_match->clock)
@@ -3052,7 +3062,7 @@ static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
 
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/drm_edid.c static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match) · line 3068

Quoted 7 lines
drivers/gpu/drm/drm_edid.c +1 -1
   		if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
   		     KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
-		    drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		    drm_mode_match(to_match, hdmi_mode, match_flags))
   			return vic;
   	}
   	return 0;

- Shashank

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#29 lore raw

Re: [PATCH 07/10] drm/edid: Don't send bogus aspect ratios in AVI infoframes

In reply to Ville Syrjälä

Regards

Shashank

Quoted 63 lines · Ville Syrjälä
Quoted 62 lines · Shashank

Regards

Shashank

Quoted 36 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

If the user mode would specify an aspect ratio other than 4:3 or 16:9 we now silently ignore it. Maybe a better apporoach is to return an error? Let's try that.

Also we must be careful that we don't try to send illegal picture aspect in the infoframe as it's only capable of signalling none, 4:3, and 16:9. Currently we're sending these bogus infoframes whenever the cea mode specifies some other aspect ratio.

Cc Shashank Sharma <[email protected]>
Cc Sean Paul <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
   drivers/gpu/drm/drm_edid.c | 23 +++++++++++++++++------
   1 file changed, 17 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 00aa98f3e55d..bafb3ee4ea97 100644
@@ -4786,6 +4786,7 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
   					 const struct drm_display_mode *mode,
   					 bool is_hdmi2_sink)
   {
+	enum hdmi_picture_aspect picture_aspect;
   	int err;
 
   	if (!frame || !mode)
@@ -4828,13 +4829,23 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
   	 * Populate picture aspect ratio from either
   	 * user input (if specified) or from the CEA mode list.

drivers/gpu/drm/drm_edid.c drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 4834

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +3 -6
   	 */
-	if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
-		mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
-		frame->picture_aspect = mode->picture_aspect_ratio;
-	else if (frame->video_code > 0)
-		frame->picture_aspect = drm_get_cea_aspect_ratio(
-						frame->video_code);
+	picture_aspect = mode->picture_aspect_ratio;
+	if (picture_aspect == HDMI_PICTURE_ASPECT_NONE)
+		picture_aspect = drm_get_cea_aspect_ratio(frame->video_code);

This is slightly going in the loop.
- During the modeset the driver cant specify the aspect ratio information, as DRM layer lacks this support.
- So we fill the VIC field, by comparing the mode with the DRM_CEA_MODES[] list. This will pick the first mode available in the list (regardless of its aspect ratio), and fill the
VIC, as we don't consider aspect ratio while comparing timings.
- Again, now while sending the aspect ratio, we are picking up the VIC, which may not be correct.

Quoted 5 lines
Quoted 2 lines

So if we have 720x480(4:3) and 720x480(16:9) in the list, as 4:3 is first in list, we will always pick 4:3 aspect ratio.

Yes. The user didn't care about the aspect ratio (or rather couldn't specify one) so we just pick one. Which is exactly what we've been doing ever since we started sending the VIC in the infoframe.

Correct, and we are hoping that this should be better (if not fixed) with the aspect ratio support patches + DRM cap. If the userspace doesn't set the cap, then anyways there is no aspect ratio field available, and VIC would be always 0, as this becomes a Non CEA mode.

Or do you think it would be a better idea to send some VIC instead of No VIC, when userspace doesn't set the DRM cap for aspect ratio ?

- Shashank

Quoted 18 lines
Quoted 18 lines

- Shashank

Quoted 7 lines
drivers/gpu/drm/drm_edid.c +6 -0
+	/*
+	 * The infoframe can't convey anything but none, 4:3
+	 * and 16:9, so if the user has asked for anything else
+	 * we can only satisfy it by specifying the right VIC.
+	 */
+	if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {

drivers/gpu/drm/drm_edid.c drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 4851

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +7 -0
+		if (picture_aspect !=
+		    drm_get_cea_aspect_ratio(frame->video_code))
+			return -EINVAL;
+		picture_aspect = HDMI_PICTURE_ASPECT_NONE;
+	}
+
+	frame->picture_aspect = picture_aspect;
   	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
   	frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
 

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#19 lore raw

Re: [PATCH 06/10] drm/edid: Fix cea mode aspect ratio handling

In reply to Sharma, Shashank
Quoted 69 lines · Shashank

Regards

Shashank

Quoted 52 lines · Ville Syrjälä
Quoted 51 lines · Shashank

Regards

Shashank

Quoted 45 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

commit 6dffd431e229 ("drm: Add aspect ratio parsing in DRM layer") cause us to not send out any VICs in the AVI infoframes. That commit was since reverted, but if and when we add aspect ratio handing back we need to be more careful.

Let's handle this by considering the aspect ratio as a requirement for cea mode matching only if the passed in mode actually has a non-zero aspect ratio field. This will keep userspace that doesn't provide an aspect ratio working as before by matching it to the first otherwise equal cea mode. And once userspace starts to provide the aspect ratio it will be considerd a hard requirement for the match.

Also change the hdmi mode matching to use drm_mode_match() for consistency, but we don't match on aspect ratio there since the spec doesn't list a specific aspect ratio for those modes.

Cc Shashank Sharma <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Akashdeep Sharma <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
   drivers/gpu/drm/drm_edid.c | 18 ++++++++++++++----
   1 file changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 7220b8f9a7e8..00aa98f3e55d 100644
@@ -2903,11 +2903,15 @@ cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
   static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
   					     unsigned int clock_tolerance)
   {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
   	u8 vic;
 
   	if (!to_match->clock)
   		return 0;
 
Quoted 6 lines
Quoted 5 lines

drivers/gpu/drm/drm_edid.c cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode) · line 2913

Quoted 2 lines
drivers/gpu/drm/drm_edid.c +2 -0
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

This doesn't look right. This means we are expecting a CEA mode without a pic aspect ratio field,
which is invalid.

No, it's perfectly valid. It's what we currently get from userspace.

Yep, but that's due to missing Aspect ratio handling in the DRM layer. If that's fixed, as per the list of CEA modes,
each CEA VIC contains an aspect ratio, which is a part of its unique identity.

Quoted 12 lines

I guess once we have the aspect ratio handling in DRM layer, it would/should look like this:
- EDID gives you all supported modes, including CEA modes with Aspect ratio
- Userspcae gets the mode information, with aspect ratio (for CEA modes) If ( Userspace picks one of the CEA modes)
- sends a modeset
- we find a matching CEA VIC, found one from modedb
- we load this VIC = nonzero information in AVI IF VIC field,
else
- sends a modeset
- we could not find a matching CEA VIC, as aspect ratio is 0
- we make VIC field in AVI IF as 0a

No. That would break current userspace.

Quoted 3 lines

This is important, as HDMI compliance test 7-27 inspects if the VIC field in the AVI IF is accurate.

Complicance is secondary to not breaking things that work. Also I find it hard to see what purpose there is in having a complicance test that sets a CEA modes w/o aspect ratio and then expects the infoframe to have VIC 0.

Quoted 11 lines

- Shashank

Quoted 5 lines
Quoted 3 lines

Ankit is going to publish the aspect ratio patch series again, with proper DRM cap and flags check. Would it be ok if we have a look that handling first ?

This patch will be needed by that work. Otherwise we're going to stop sending a VIC for CEA modes with current userspace.

I guess we should force userspaces to start bothering about aspect ratio field, right now we
are doing this for Wayland based compositors, may be we should extend it to X based too.

Yes, I've been saying that someone should look into extending the randr protocol with the necessary bits. But that still doesn't allow us to change the current behaviour as old userspace would anyway linger around for a long time.

Quoted 77 lines

- Shashank

Quoted 75 lines
Quoted 75 lines
Quoted 16 lines
drivers/gpu/drm/drm_edid.c +2 -1
+
   	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
   		struct drm_display_mode cea_mode = edid_cea_modes[vic];
   		unsigned int clock1, clock2;
@@ -2921,7 +2925,7 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
   			continue;
 
   		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
   				return vic;
   		} while (cea_mode_alternate_timings(vic, &cea_mode));
   	}
@@ -2938,11 +2942,15 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
    */

drivers/gpu/drm/drm_edid.c static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m · line 2952

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +3 -0
   u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
   {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
   	u8 vic;
 
   	if (!to_match->clock)
   		return 0;
 
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

same here, and probably in other CEA match functions.

Quoted 39 lines
drivers/gpu/drm/drm_edid.c +5 -2
+
   	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
   		struct drm_display_mode cea_mode = edid_cea_modes[vic];
   		unsigned int clock1, clock2;
@@ -2956,7 +2964,7 @@ u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
   			continue;
 
   		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
   				return vic;
   		} while (cea_mode_alternate_timings(vic, &cea_mode));
   	}
@@ -3003,6 +3011,7 @@ hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
   static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
   					      unsigned int clock_tolerance)
   {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
   	u8 vic;
 
   	if (!to_match->clock)
@@ -3020,7 +3029,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
   		    abs(to_match->clock - clock2) > clock_tolerance)
   			continue;
 
-		if (drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		if (drm_mode_match(to_match, hdmi_mode, match_flags))
   			return vic;
   	}
 
@@ -3037,6 +3046,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
    */
   static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
   {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
   	u8 vic;
 
   	if (!to_match->clock)

drivers/gpu/drm/drm_edid.c static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match) · line 3068

Quoted 8 lines
drivers/gpu/drm/drm_edid.c +1 -1
@@ -3052,7 +3062,7 @@ static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
 
   		if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
   		     KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
-		    drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		    drm_mode_match(to_match, hdmi_mode, match_flags))
   			return vic;
   	}
   	return 0;

- Shashank

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#30 lore raw

Re: [PATCH 07/10] drm/edid: Don't send bogus aspect ratios in AVI infoframes

In reply to Sharma, Shashank
Quoted 80 lines · Shashank

Regards

Shashank

Quoted 63 lines · Ville Syrjälä
Quoted 62 lines · Shashank

Regards

Shashank

Quoted 36 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

If the user mode would specify an aspect ratio other than 4:3 or 16:9 we now silently ignore it. Maybe a better apporoach is to return an error? Let's try that.

Also we must be careful that we don't try to send illegal picture aspect in the infoframe as it's only capable of signalling none, 4:3, and 16:9. Currently we're sending these bogus infoframes whenever the cea mode specifies some other aspect ratio.

Cc Shashank Sharma <[email protected]>
Cc Sean Paul <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
   drivers/gpu/drm/drm_edid.c | 23 +++++++++++++++++------
   1 file changed, 17 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 00aa98f3e55d..bafb3ee4ea97 100644
@@ -4786,6 +4786,7 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
   					 const struct drm_display_mode *mode,
   					 bool is_hdmi2_sink)
   {
+	enum hdmi_picture_aspect picture_aspect;
   	int err;
 
   	if (!frame || !mode)
@@ -4828,13 +4829,23 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
   	 * Populate picture aspect ratio from either
   	 * user input (if specified) or from the CEA mode list.

drivers/gpu/drm/drm_edid.c drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 4834

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +3 -6
   	 */
-	if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
-		mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
-		frame->picture_aspect = mode->picture_aspect_ratio;
-	else if (frame->video_code > 0)
-		frame->picture_aspect = drm_get_cea_aspect_ratio(
-						frame->video_code);
+	picture_aspect = mode->picture_aspect_ratio;
+	if (picture_aspect == HDMI_PICTURE_ASPECT_NONE)
+		picture_aspect = drm_get_cea_aspect_ratio(frame->video_code);

This is slightly going in the loop.
- During the modeset the driver cant specify the aspect ratio information, as DRM layer lacks this support.
- So we fill the VIC field, by comparing the mode with the DRM_CEA_MODES[] list. This will pick the first mode available in the list (regardless of its aspect ratio), and fill the
VIC, as we don't consider aspect ratio while comparing timings.
- Again, now while sending the aspect ratio, we are picking up the VIC, which may not be correct.

Quoted 5 lines
Quoted 2 lines

So if we have 720x480(4:3) and 720x480(16:9) in the list, as 4:3 is first in list, we will always pick 4:3 aspect ratio.

Yes. The user didn't care about the aspect ratio (or rather couldn't specify one) so we just pick one. Which is exactly what we've been doing ever since we started sending the VIC in the infoframe.

Correct, and we are hoping that this should be better (if not fixed) with the aspect ratio support
patches + DRM cap. If the userspace doesn't set the cap, then anyways there is no aspect ratio
field available, and VIC would be always 0, as this becomes a Non CEA mode.

Quoted 3 lines

Or do you think it would be a better idea to send some VIC instead of No VIC, when userspace doesn't
set the DRM cap for aspect ratio ?

Yes. That's the current behaviour.

IIRC some crappy amplifiers etc. with HDMI passthrough don't even work correctly unless VIC is specified. Hence we do want to send it whenever possible.

Quoted 20 lines

- Shashank

Quoted 18 lines
Quoted 18 lines

- Shashank

Quoted 17 lines
drivers/gpu/drm/drm_edid.c +13 -0
+	/*
+	 * The infoframe can't convey anything but none, 4:3
+	 * and 16:9, so if the user has asked for anything else
+	 * we can only satisfy it by specifying the right VIC.
+	 */
+	if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {
+		if (picture_aspect !=
+		    drm_get_cea_aspect_ratio(frame->video_code))
+			return -EINVAL;
+		picture_aspect = HDMI_PICTURE_ASPECT_NONE;
+	}
+
+	frame->picture_aspect = picture_aspect;
   	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
   	frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
 
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#20 lore raw

Re: [PATCH 06/10] drm/edid: Fix cea mode aspect ratio handling

In reply to Ville Syrjälä

Regards

Shashank

Quoted 82 lines · Ville Syrjälä
Quoted 69 lines · Shashank

Regards

Shashank

Quoted 52 lines · Ville Syrjälä
Quoted 51 lines · Shashank

Regards

Shashank

Quoted 45 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

commit 6dffd431e229 ("drm: Add aspect ratio parsing in DRM layer") cause us to not send out any VICs in the AVI infoframes. That commit was since reverted, but if and when we add aspect ratio handing back we need to be more careful.

Let's handle this by considering the aspect ratio as a requirement for cea mode matching only if the passed in mode actually has a non-zero aspect ratio field. This will keep userspace that doesn't provide an aspect ratio working as before by matching it to the first otherwise equal cea mode. And once userspace starts to provide the aspect ratio it will be considerd a hard requirement for the match.

Also change the hdmi mode matching to use drm_mode_match() for consistency, but we don't match on aspect ratio there since the spec doesn't list a specific aspect ratio for those modes.

Cc Shashank Sharma <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Akashdeep Sharma <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
    drivers/gpu/drm/drm_edid.c | 18 ++++++++++++++----
    1 file changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 7220b8f9a7e8..00aa98f3e55d 100644
@@ -2903,11 +2903,15 @@ cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
    static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
    					     unsigned int clock_tolerance)
    {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
    	u8 vic;
 
    	if (!to_match->clock)
    		return 0;
 
Quoted 6 lines
Quoted 5 lines

drivers/gpu/drm/drm_edid.c cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode) · line 2913

Quoted 2 lines
drivers/gpu/drm/drm_edid.c +2 -0
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

This doesn't look right. This means we are expecting a CEA mode without a pic aspect ratio field,
which is invalid.

No, it's perfectly valid. It's what we currently get from userspace.

Yep, but that's due to missing Aspect ratio handling in the DRM layer. If that's fixed, as per the list of CEA modes,
each CEA VIC contains an aspect ratio, which is a part of its unique identity.

Quoted 12 lines

I guess once we have the aspect ratio handling in DRM layer, it would/should look like this:
- EDID gives you all supported modes, including CEA modes with Aspect ratio
- Userspcae gets the mode information, with aspect ratio (for CEA modes) If ( Userspace picks one of the CEA modes)
- sends a modeset
- we find a matching CEA VIC, found one from modedb
- we load this VIC = nonzero information in AVI IF VIC field,
else
- sends a modeset
- we could not find a matching CEA VIC, as aspect ratio is 0
- we make VIC field in AVI IF as 0a

Quoted 1 line

No. That would break current userspace.

I guess I forgot to make it clear, that userspace will set the cap, only then we will provide aspect ratio information. So this should not break userspace, isn't it ?

Quoted 6 lines
Quoted 2 lines

This is important, as HDMI compliance test 7-27 inspects if the VIC field in the AVI IF is accurate.

Complicance is secondary to not breaking things that work. Also I find it hard to see what purpose there is in having a complicance test that sets a CEA modes w/o aspect ratio and then expects the infoframe to have VIC 0.

Again, typically this is how these analyzers force modeset:
- They send EDID with only one mode, which is the test mode, with aspect ratio.
- They expect that VIC to be present in AVI IF

Quoted 6 lines
Quoted 6 lines

- Shashank

Quoted 5 lines
Quoted 3 lines

Ankit is going to publish the aspect ratio patch series again, with proper DRM cap and flags check. Would it be ok if we have a look that handling first ?

This patch will be needed by that work. Otherwise we're going to stop sending a VIC for CEA modes with current userspace.

Quoted 8 lines
Quoted 4 lines

I guess we should force userspaces to start bothering about aspect ratio field, right now we
are doing this for Wayland based compositors, may be we should extend it to X based too.

Yes, I've been saying that someone should look into extending the randr protocol with the necessary bits. But that still doesn't allow us to change the current behaviour as old userspace would anyway linger around for a long time.

I think cap will cove this part

- Shashank

Quoted 67 lines
Quoted 67 lines

- Shashank

Quoted 66 lines
Quoted 66 lines
Quoted 15 lines
drivers/gpu/drm/drm_edid.c +2 -1
+
    	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
    		struct drm_display_mode cea_mode = edid_cea_modes[vic];
    		unsigned int clock1, clock2;
@@ -2921,7 +2925,7 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
    			continue;
 
    		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
    				return vic;
    		} while (cea_mode_alternate_timings(vic, &cea_mode));
    	}
@@ -2938,11 +2942,15 @@ static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m
     */

drivers/gpu/drm/drm_edid.c static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_m · line 2952

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +3 -0
    u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
    {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
    	u8 vic;
 
    	if (!to_match->clock)
    		return 0;
 
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

same here, and probably in other CEA match functions.

Quoted 40 lines
drivers/gpu/drm/drm_edid.c +5 -2
+
    	for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
    		struct drm_display_mode cea_mode = edid_cea_modes[vic];
    		unsigned int clock1, clock2;
@@ -2956,7 +2964,7 @@ u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
    			continue;
 
    		do {
-			if (drm_mode_equal_no_clocks_no_stereo(to_match, &cea_mode))
+			if (drm_mode_match(to_match, &cea_mode, match_flags))
    				return vic;
    		} while (cea_mode_alternate_timings(vic, &cea_mode));
    	}
@@ -3003,6 +3011,7 @@ hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
    static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
    					      unsigned int clock_tolerance)
    {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
    	u8 vic;
 
    	if (!to_match->clock)
@@ -3020,7 +3029,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
    		    abs(to_match->clock - clock2) > clock_tolerance)
    			continue;
 
-		if (drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		if (drm_mode_match(to_match, hdmi_mode, match_flags))
    			return vic;
    	}
 
@@ -3037,6 +3046,7 @@ static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_
     */
    static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
    {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
    	u8 vic;
 
    	if (!to_match->clock)
@@ -3052,7 +3062,7 @@ static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/drm_edid.c static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match) · line 3068

Quoted 7 lines
drivers/gpu/drm/drm_edid.c +1 -1
    		if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
    		     KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
-		    drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
+		    drm_mode_match(to_match, hdmi_mode, match_flags))
    			return vic;
    	}
    	return 0;

- Shashank

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#21 lore raw

Re: [PATCH 06/10] drm/edid: Fix cea mode aspect ratio handling

Quoted 112 lines · Shashank

Regards

Shashank

Quoted 82 lines · Ville Syrjälä
Quoted 69 lines · Shashank

Regards

Shashank

Quoted 52 lines · Ville Syrjälä
Quoted 51 lines · Shashank

Regards

Shashank

Quoted 45 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

commit 6dffd431e229 ("drm: Add aspect ratio parsing in DRM layer") cause us to not send out any VICs in the AVI infoframes. That commit was since reverted, but if and when we add aspect ratio handing back we need to be more careful.

Let's handle this by considering the aspect ratio as a requirement for cea mode matching only if the passed in mode actually has a non-zero aspect ratio field. This will keep userspace that doesn't provide an aspect ratio working as before by matching it to the first otherwise equal cea mode. And once userspace starts to provide the aspect ratio it will be considerd a hard requirement for the match.

Also change the hdmi mode matching to use drm_mode_match() for consistency, but we don't match on aspect ratio there since the spec doesn't list a specific aspect ratio for those modes.

Cc Shashank Sharma <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Akashdeep Sharma <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
    drivers/gpu/drm/drm_edid.c | 18 ++++++++++++++----
    1 file changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 7220b8f9a7e8..00aa98f3e55d 100644
@@ -2903,11 +2903,15 @@ cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
    static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
    					     unsigned int clock_tolerance)
    {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
    	u8 vic;
 
    	if (!to_match->clock)
    		return 0;
 
Quoted 6 lines
Quoted 5 lines

drivers/gpu/drm/drm_edid.c cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode) · line 2913

Quoted 2 lines
drivers/gpu/drm/drm_edid.c +2 -0
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

This doesn't look right. This means we are expecting a CEA mode without a pic aspect ratio field,
which is invalid.

No, it's perfectly valid. It's what we currently get from userspace.

Yep, but that's due to missing Aspect ratio handling in the DRM layer. If that's fixed, as per the list of CEA modes,
each CEA VIC contains an aspect ratio, which is a part of its unique identity.

Quoted 12 lines

I guess once we have the aspect ratio handling in DRM layer, it would/should look like this:
- EDID gives you all supported modes, including CEA modes with Aspect ratio
- Userspcae gets the mode information, with aspect ratio (for CEA modes) If ( Userspace picks one of the CEA modes)
- sends a modeset
- we find a matching CEA VIC, found one from modedb
- we load this VIC = nonzero information in AVI IF VIC field,
else
- sends a modeset
- we could not find a matching CEA VIC, as aspect ratio is 0
- we make VIC field in AVI IF as 0a

Quoted 1 line

No. That would break current userspace.

I guess I forgot to make it clear, that userspace will set the cap, only then we will provide aspect ratio information.
So this should not break userspace, isn't it ?

Quoted 6 lines
Quoted 2 lines

This is important, as HDMI compliance test 7-27 inspects if the VIC field in the AVI IF is accurate.

Complicance is secondary to not breaking things that work. Also I find it hard to see what purpose there is in having a complicance test that sets a CEA modes w/o aspect ratio and then expects the infoframe to have VIC 0.

Again, typically this is how these analyzers force modeset:
- They send EDID with only one mode, which is the test mode, with aspect ratio.
- They expect that VIC to be present in AVI IF

Quoted 10 lines
Quoted 10 lines

- Shashank

Quoted 5 lines
Quoted 3 lines

Ankit is going to publish the aspect ratio patch series again, with proper DRM cap and flags check. Would it be ok if we have a look that handling first ?

This patch will be needed by that work. Otherwise we're going to stop sending a VIC for CEA modes with current userspace.

I guess we should force userspaces to start bothering about aspect ratio field, right now we
are doing this for Wayland based compositors, may be we should extend it to X based too.

Quoted 5 lines
Quoted 4 lines

Yes, I've been saying that someone should look into extending the randr protocol with the necessary bits. But that still doesn't allow us to change the current behaviour as old userspace would anyway linger around for a long time.

I think cap will cove this part

The cap is irrelevant to this discussion. It will not be set by old userspace, hence it won't change anything for old userspace. Modes coming from old userspace will still have aspect_ratio=0.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#36 lore raw

Re: [PATCH 10/10] video/hdmi: Pass buffer size to infoframe unpack functions

In reply to Ville Syrjala
Quoted 176 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

To make sure the infoframe unpack functions don't end up examining stack garbage or oopsing, let's pass in the size of the buffer.

---
 drivers/media/i2c/adv7511.c  |  2 +-
 drivers/media/i2c/adv7604.c  |  2 +-
 drivers/media/i2c/adv7842.c  |  2 +-
 drivers/media/i2c/tc358743.c |  2 +-
 drivers/video/hdmi.c         | 51 ++++++++++++++++++++++++++++++++------------
 include/linux/hdmi.h         |  2 +-
 6 files changed, 42 insertions(+), 19 deletions(-)
drivers/media/i2c/adv7511.c +1 -1
index 2817bafc67bf..dec09c18ea34 100644
@@ -562,7 +562,7 @@ static void log_infoframe(struct v4l2_subdev *sd, const struct adv7511_cfg_read_
 	buffer[3] = 0;
 	buffer[3] = hdmi_infoframe_checksum(buffer, len + 4);
 
-	if (hdmi_infoframe_unpack(&frame, buffer) < 0) {
+	if (hdmi_infoframe_unpack(&frame, buffer, sizeof(buffer)) < 0) {
 		v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc);
 		return;
 	}
drivers/media/i2c/adv7604.c +1 -1
index f289b8aca1da..8500438af0d3 100644
@@ -2429,7 +2429,7 @@ static int adv76xx_read_infoframe(struct v4l2_subdev *sd, int index,
 		buffer[i + 3] = infoframe_read(sd,
 				       adv76xx_cri[index].payload_addr + i);
 
-	if (hdmi_infoframe_unpack(frame, buffer) < 0) {
+	if (hdmi_infoframe_unpack(frame, buffer, sizeof(buffer)) < 0) {
 		v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__,
 			 adv76xx_cri[index].desc);
 		return -ENOENT;
drivers/media/i2c/adv7842.c +1 -1
index 65f34e7e146f..fd5d5e84dcbf 100644
@@ -2576,7 +2576,7 @@ static void log_infoframe(struct v4l2_subdev *sd, struct adv7842_cfg_read_infofr
 	for (i = 0; i < len; i++)
 		buffer[i + 3] = infoframe_read(sd, cri->payload_addr + i);
 
-	if (hdmi_infoframe_unpack(&frame, buffer) < 0) {
+	if (hdmi_infoframe_unpack(&frame, buffer, sizeof(buffer)) < 0) {
 		v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc);
 		return;
 	}
drivers/media/i2c/tc358743.c +1 -1
index e6f5c363ccab..f6a5ebffd9c6 100644
@@ -453,7 +453,7 @@ static void print_avi_infoframe(struct v4l2_subdev *sd)
 
 	i2c_rd(sd, PK_AVI_0HEAD, buffer, HDMI_INFOFRAME_SIZE(AVI));
 
-	if (hdmi_infoframe_unpack(&frame, buffer) < 0) {
+	if (hdmi_infoframe_unpack(&frame, buffer, sizeof(buffer)) < 0) {
 		v4l2_err(sd, "%s: unpack of AVI infoframe failed\n", __func__);
 		return;
 	}
drivers/video/hdmi.c +21 -8
index 65b915ea4936..b5d491014b0b 100644
@@ -1005,8 +1005,9 @@ EXPORT_SYMBOL(hdmi_infoframe_log);
 
 /**
  * hdmi_avi_infoframe_unpack() - unpack binary buffer to a HDMI AVI infoframe
- * @buffer: source buffer
  * @frame: HDMI AVI infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
  *
  * Unpacks the information contained in binary @buffer into a structured
  * @frame of the HDMI Auxiliary Video (AVI) information frame.
@@ -1016,11 +1017,14 @@ EXPORT_SYMBOL(hdmi_infoframe_log);
  * Returns 0 on success or a negative error code on failure.
  */
 static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe *frame,
-				     const void *buffer)
+				     const void *buffer, size_t size)
 {
 	const u8 *ptr = buffer;
 	int ret;
 
+	if (size < HDMI_INFOFRAME_SIZE(AVI))
+		return -EINVAL;
+
 	if (ptr[0] != HDMI_INFOFRAME_TYPE_AVI ||
 	    ptr[1] != 2 ||
 	    ptr[2] != HDMI_AVI_INFOFRAME_SIZE)
@@ -1068,8 +1072,9 @@ static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe *frame,
 
 /**
  * hdmi_spd_infoframe_unpack() - unpack binary buffer to a HDMI SPD infoframe
- * @buffer: source buffer
  * @frame: HDMI SPD infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
  *
  * Unpacks the information contained in binary @buffer into a structured
  * @frame of the HDMI Source Product Description (SPD) information frame.
@@ -1079,11 +1084,14 @@ static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe *frame,
  * Returns 0 on success or a negative error code on failure.
  */
 static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe *frame,
-				     const void *buffer)
+				     const void *buffer, size_t size)
 {
 	const u8 *ptr = buffer;
 	int ret;
 
+	if (size < HDMI_INFOFRAME_SIZE(SPD))
+		return -EINVAL;
+
 	if (ptr[0] != HDMI_INFOFRAME_TYPE_SPD ||
 	    ptr[1] != 1 ||
 	    ptr[2] != HDMI_SPD_INFOFRAME_SIZE) {
@@ -1106,8 +1114,9 @@ static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe *frame,
 
 /**
  * hdmi_audio_infoframe_unpack() - unpack binary buffer to a HDMI AUDIO infoframe
- * @buffer: source buffer
  * @frame: HDMI Audio infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
  *
  * Unpacks the information contained in binary @buffer into a structured
  * @frame of the HDMI Audio information frame.
@@ -1117,11 +1126,14 @@ static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe *frame,
  * Returns 0 on success or a negative error code on failure.
  */
 static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe *frame,
-				       const void *buffer)
+				       const void *buffer, size_t size)
 {
 	const u8 *ptr = buffer;
 	int ret;
 
+	if (size < HDMI_INFOFRAME_SIZE(AUDIO))
+		return -EINVAL;
+
 	if (ptr[0] != HDMI_INFOFRAME_TYPE_AUDIO ||
 	    ptr[1] != 1 ||
 	    ptr[2] != HDMI_AUDIO_INFOFRAME_SIZE) {
@@ -1151,8 +1163,9 @@ static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe *frame,
 
 /**
  * hdmi_vendor_infoframe_unpack() - unpack binary buffer to a HDMI vendor infoframe
- * @buffer: source buffer
  * @frame: HDMI Vendor infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
  *
  * Unpacks the information contained in binary @buffer into a structured
  * @frame of the HDMI Vendor information frame.
@@ -1163,7 +1176,7 @@ static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe *frame,
  */
 static int
 hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
-				 const void *buffer)
+				 const void *buffer, size_t size)
 {
 	const u8 *ptr = buffer;
 	size_t length;

drivers/video/hdmi.c hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame, · line 1189

Quoted 6 lines
drivers/video/hdmi.c +3 -0
@@ -1171,6 +1184,9 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 	u8 hdmi_video_format;
 	struct hdmi_vendor_infoframe *hvf = &frame->hdmi;
 
+	if (size < HDMI_INFOFRAME_HEADER_SIZE)
+		return -EINVAL;
+

This check is not needed since that is already done in hdmi_infoframe_unpack().

Quoted 62 lines
drivers/video/hdmi.c +13 -6
 	if (ptr[0] != HDMI_INFOFRAME_TYPE_VENDOR ||
 	    ptr[1] != 1 ||
 	    (ptr[2] != 4 && ptr[2] != 5 && ptr[2] != 6))
@@ -1178,6 +1194,9 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 
 	length = ptr[2];
 
+	if (size < HDMI_INFOFRAME_HEADER_SIZE + length)
+		return -EINVAL;
+
 	if (hdmi_infoframe_checksum(buffer,
 				    HDMI_INFOFRAME_HEADER_SIZE + length) != 0)
 		return -EINVAL;
@@ -1224,8 +1243,9 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 
 /**
  * hdmi_infoframe_unpack() - unpack binary buffer to a HDMI infoframe
- * @buffer: source buffer
  * @frame: HDMI infoframe
+ * @buffer: source buffer
+ * @size: size of buffer
  *
  * Unpacks the information contained in binary buffer @buffer into a structured
  * @frame of a HDMI infoframe.
@@ -1235,23 +1255,26 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
  * Returns 0 on success or a negative error code on failure.
  */
 int hdmi_infoframe_unpack(union hdmi_infoframe *frame,
-			  const void *buffer)
+			  const void *buffer, size_t size)
 {
 	int ret;
 	const u8 *ptr = buffer;
 
+	if (size < HDMI_INFOFRAME_HEADER_SIZE)
+		return -EINVAL;
+
 	switch (ptr[0]) {
 	case HDMI_INFOFRAME_TYPE_AVI:
-		ret = hdmi_avi_infoframe_unpack(&frame->avi, buffer);
+		ret = hdmi_avi_infoframe_unpack(&frame->avi, buffer, size);
 		break;
 	case HDMI_INFOFRAME_TYPE_SPD:
-		ret = hdmi_spd_infoframe_unpack(&frame->spd, buffer);
+		ret = hdmi_spd_infoframe_unpack(&frame->spd, buffer, size);
 		break;
 	case HDMI_INFOFRAME_TYPE_AUDIO:
-		ret = hdmi_audio_infoframe_unpack(&frame->audio, buffer);
+		ret = hdmi_audio_infoframe_unpack(&frame->audio, buffer, size);
 		break;
 	case HDMI_INFOFRAME_TYPE_VENDOR:
-		ret = hdmi_vendor_any_infoframe_unpack(&frame->vendor, buffer);
+		ret = hdmi_vendor_any_infoframe_unpack(&frame->vendor, buffer, size);
 		break;
 	default:
 		ret = -EINVAL;
include/linux/hdmi.h +0 -0
index d3816170c062..a577d4ae2570 100644

include/linux/hdmi.h union hdmi_infoframe { · line 339

Quoted 8 lines
include/linux/hdmi.h +1 -1
@@ -333,7 +333,7 @@ union hdmi_infoframe {
 ssize_t
 hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer, size_t size);
 int hdmi_infoframe_unpack(union hdmi_infoframe *frame,
-			  const void *buffer);
+			  const void *buffer, size_t size);
 void hdmi_infoframe_log(const char *level, struct device *dev,
 			union hdmi_infoframe *frame);
 

FYI: I'll be posting two other hdmi.c patches today that we (Cisco) have in our queue for some time.

Regards,

Hans

#37 lore raw

Re: [PATCH 10/10] video/hdmi: Pass buffer size to infoframe unpack functions

Quoted 2 lines · Hans Verkuil
Quoted 1 line · Ville Syrjala

From: Ville Syrjälä <[email protected]>

<snip>

Quoted 13 lines
Quoted 13 lines
drivers/video/hdmi.c +1 -1
@@ -1163,7 +1176,7 @@ static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe *frame,
  */
 static int
 hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
-				 const void *buffer)
+				 const void *buffer, size_t size)
 {
 	const u8 *ptr = buffer;
 	size_t length;
@@ -1171,6 +1184,9 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 	u8 hdmi_video_format;
 	struct hdmi_vendor_infoframe *hvf = &frame->hdmi;
 
Quoted 5 lines

drivers/video/hdmi.c hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame, · line 1189

Quoted 3 lines
drivers/video/hdmi.c +3 -0
+	if (size < HDMI_INFOFRAME_HEADER_SIZE)
+		return -EINVAL;
+

This check is not needed since that is already done in hdmi_infoframe_unpack().

Hmm. True. Somehow I was expecting that this function would have been exported on its own, but it's static so clearly I was mistaken.

The pack functions are individually exported, which is where I got this idea probably.

Quoted 14 lines
Quoted 14 lines
drivers/video/hdmi.c +3 -0
 	if (ptr[0] != HDMI_INFOFRAME_TYPE_VENDOR ||
 	    ptr[1] != 1 ||
 	    (ptr[2] != 4 && ptr[2] != 5 && ptr[2] != 6))
@@ -1178,6 +1194,9 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
 
 	length = ptr[2];
 
+	if (size < HDMI_INFOFRAME_HEADER_SIZE + length)
+		return -EINVAL;
+
 	if (hdmi_infoframe_checksum(buffer,
 				    HDMI_INFOFRAME_HEADER_SIZE + length) != 0)
 		return -EINVAL;
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw

Re: [PATCH 02/10] drm/edid: Allow HDMI infoframe without VIC or S3D

In reply to Sharma, Shashank
Quoted 44 lines · Shashank

Regards

Shashank

Quoted 38 lines · Ville Syrjälä
Quoted 37 lines · Shashank

Regards

Shashank

Quoted 9 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

Appedix F of HDMI 2.0 says that some HDMI sink may fail to switch from 3D to 2D mode in a timely fashion if the source simply stops sending the HDMI infoframe. The suggested workaround is to keep sending the infoframe even when strictly not necessary (ie. no VIC and no S3D). HDMI 1.4 does allow for this behaviour, stating that sending the infoframe is optional in this case.

Quoted 9 lines

The infoframe was first specified in HDMI 1.4, so in theory sinks predating that may not appreciate us sending an uknown infoframe their way. To avoid regressions let's try to determine if the sink supports the infoframe or not. Unfortunately there's no direct way to do that, so instead we'll just check if we managed to parse any HDMI 1.4 4k or stereo modes from the EDID, and if so we assume the sink will accept the infoframe. Also if the EDID contains the HDMI 2.0 HDMI Forum VSDB we can assume the sink is prepared to receive the infoframe.

I am trying to get some sense from HDMI 2.0 spec section 10.2.1, which talks about
switch from 3D to 2D. To me it looks like:
If (sending_to_hdmi2_sinks) {
- for 3d modes send HF-VSIF
- for 2d modes && defined in H14b HFVSIF, send H14B-VSIF When you switch from 3d->2d {
- send_HF-VSIF with 3D_valid bit = 0/1
}
} else { /* HDMI 1.4b sinks from Appendix F */
- send H14b-VSIF with HDMI_video_format[2:0 = 0 OR 1]
}

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Should we add a is_hdmi2 check and separate these cases ?

We don't support the HDMI forum infoframe. Maybe someone forgot to implement that when adding the rest of HDMI 2.0 support? ;)

How to make an 'embarrassed smile ' smiley :) ?
Will start looking into it. Meanwhile

Patches 1-2 pushed to drm-misc-next. Thanks for the review.

Quoted 333 lines
Quoted 333 lines
Quoted 333 lines
Quoted 92 lines

v2: Fix the getting has_hdmi_infoframe from display_info
Always fail constructing the infoframe if the display possibly can't handle it

Cc Shashank Sharma <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Laurent Pinchart <[email protected]>
---
   drivers/gpu/drm/bridge/sil-sii8620.c      |  3 ++-
   drivers/gpu/drm/bridge/synopsys/dw-hdmi.c |  4 +++-
   drivers/gpu/drm/drm_edid.c                | 34 +++++++++++++++++++++++++------
   drivers/gpu/drm/exynos/exynos_hdmi.c      |  2 +-
   drivers/gpu/drm/i915/intel_hdmi.c         | 14 +++++++------
   drivers/gpu/drm/mediatek/mtk_hdmi.c       |  3 ++-
   drivers/gpu/drm/nouveau/nv50_display.c    |  3 ++-
   drivers/gpu/drm/rockchip/inno_hdmi.c      |  1 +
   drivers/gpu/drm/sti/sti_hdmi.c            |  4 +++-
   drivers/gpu/drm/zte/zx_hdmi.c             |  1 +
   include/drm/drm_connector.h               |  5 +++++
   include/drm/drm_edid.h                    |  1 +
   12 files changed, 57 insertions(+), 18 deletions(-)
drivers/gpu/drm/bridge/sil-sii8620.c +2 -1
index b7eb704d0a8a..4417276ba02e 100644
@@ -2220,8 +2220,9 @@ static bool sii8620_mode_fixup(struct drm_bridge *bridge,
   			union hdmi_infoframe frm;
   			u8 mhl_vic[] = { 0, 95, 94, 93, 98 };
 
+			/* FIXME: We need the connector here */
   			drm_hdmi_vendor_infoframe_from_display_mode(
-				&frm.vendor.hdmi, adjusted_mode);
+				&frm.vendor.hdmi, NULL, adjusted_mode);
   			vic = frm.vendor.hdmi.vic;
   			if (vic >= ARRAY_SIZE(mhl_vic))
   				vic = 0;
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +3 -1
index a64ce7112288..b172139502d6 100644
@@ -1437,7 +1437,9 @@ static void hdmi_config_vendor_specific_infoframe(struct dw_hdmi *hdmi,
   	u8 buffer[10];
   	ssize_t err;
 
-	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
+	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame,
+							  &hdmi->connector,
+							  mode);
   	if (err < 0)
   		/*
   		 * Going into that statement does not means vendor infoframe
drivers/gpu/drm/drm_edid.c +6 -0
index 749d07a01772..9ada0ccf50df 100644
@@ -3393,6 +3393,7 @@ static int
   do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
   		   const u8 *video_db, u8 video_len)
   {
+	struct drm_display_info *info = &connector->display_info;
   	int modes = 0, offset = 0, i, multi_present = 0, multi_len;
   	u8 vic_len, hdmi_3d_len = 0;
   	u16 mask;
@@ -3520,6 +3521,8 @@ do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
   	}
 
   out:
+	if (modes > 0)
+		info->has_hdmi_infoframe = true;
   	return modes;
   }
 
@@ -4243,6 +4246,8 @@ static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
   	struct drm_display_info *display = &connector->display_info;
   	struct drm_hdmi_info *hdmi = &display->hdmi;
 
+	display->has_hdmi_infoframe = true;
+
   	if (hf_vsdb[6] & 0x80) {
   		hdmi->scdc.supported = true;
   		if (hf_vsdb[6] & 0x40)
@@ -4416,6 +4421,7 @@ static void drm_add_display_info(struct drm_connector *connector,
   	info->cea_rev = 0;
   	info->max_tmds_clock = 0;
   	info->dvi_dual = false;
+	info->has_hdmi_infoframe = false;
 
   	if (edid->revision < 3)
   		return;

drivers/gpu/drm/drm_edid.c s3d_structure_from_display_mode(const struct drm_display_mode *mode) · line 4912

Quoted 4 lines
drivers/gpu/drm/drm_edid.c +1 -0
@@ -4903,6 +4909,7 @@ s3d_structure_from_display_mode(const struct drm_display_mode *mode)
    * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
    * data from a DRM display mode
    * @frame: HDMI vendor infoframe
+ * @connector: the connector

I remember our old discussion where we realized that we will need this connector for all types of infoframes,
eventually, do you think we should start thinking about creating a wrapper like drm_any_infoframe_from_display_mode(),
and pass connector and desired type to it ?Or I am getting too ambitious targeting this series :) ?

Quoted 222 lines
drivers/gpu/drm/drm_edid.c +21 -6
    * @mode: DRM display mode
    *
    * Note that there's is a need to send HDMI vendor infoframes only when using a
@@ -4913,8 +4920,15 @@ s3d_structure_from_display_mode(const struct drm_display_mode *mode)
    */
   int
   drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+					    struct drm_connector *connector,
   					    const struct drm_display_mode *mode)
   {
+	/*
+	 * FIXME: sil-sii8620 doesn't have a connector around when
+	 * we need one, so we have to be prepared for a NULL connector.
+	 */
+	bool has_hdmi_infoframe = connector ?
+		connector->display_info.has_hdmi_infoframe : false;
   	int err;
   	u32 s3d_flags;
   	u8 vic;
@@ -4922,11 +4936,21 @@ drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
   	if (!frame || !mode)
   		return -EINVAL;
 
+	if (!has_hdmi_infoframe)
+		return -EINVAL;
+
   	vic = drm_match_hdmi_mode(mode);
   	s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
 
-	if (!vic && !s3d_flags)
-		return -EINVAL;
+	/*
+	 * Even if it's not absolutely necessary to send the infoframe
+	 * (ie.vic==0 and s3d_struct==0) we will still send it if we
+	 * know that the sink can handle it. This is based on a
+	 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
+	 * have trouble realizing that they shuld switch from 3D to 2D
+	 * mode if the source simply stops sending the infoframe when
+	 * it wants to switch from 3D to 2D.
+	 */
 
   	if (vic && s3d_flags)
   		return -EINVAL;
@@ -4935,10 +4959,8 @@ drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
   	if (err < 0)
   		return err;
 
-	if (vic)
-		frame->vic = vic;
-	else
-		frame->s3d_struct = s3d_structure_from_display_mode(mode);
+	frame->vic = vic;
+	frame->s3d_struct = s3d_structure_from_display_mode(mode);
 
   	return 0;
   }
drivers/gpu/drm/exynos/exynos_hdmi.c +1 -1
index 0109ff40b1db..812b2773ed69 100644
@@ -795,7 +795,7 @@ static void hdmi_reg_infoframes(struct hdmi_context *hdata)
   	}
 
   	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frm.vendor.hdmi,
-			&hdata->current_mode);
+			&hdata->connector, &hdata->current_mode);
   	if (!ret)
   		ret = hdmi_vendor_infoframe_pack(&frm.vendor.hdmi, buf,
   				sizeof(buf));
drivers/gpu/drm/i915/intel_hdmi.c +8 -6
index 2d95db64cdf2..2ccba4ccf7ad 100644
@@ -512,12 +512,14 @@ static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder,
 
   static void
   intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
-			      const struct intel_crtc_state *crtc_state)
+			      const struct intel_crtc_state *crtc_state,
+			      const struct drm_connector_state *conn_state)
   {
   	union hdmi_infoframe frame;
   	int ret;
 
   	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							  conn_state->connector,
   							  &crtc_state->base.adjusted_mode);
   	if (ret < 0)
   		return;
@@ -584,7 +586,7 @@ static void g4x_set_infoframes(struct drm_encoder *encoder,
 
   	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
   	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
   }
 
   static bool hdmi_sink_is_deep_color(const struct drm_connector_state *conn_state)
@@ -725,7 +727,7 @@ static void ibx_set_infoframes(struct drm_encoder *encoder,
 
   	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
   	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
   }
 
   static void cpt_set_infoframes(struct drm_encoder *encoder,
@@ -768,7 +770,7 @@ static void cpt_set_infoframes(struct drm_encoder *encoder,
 
   	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
   	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
   }
 
   static void vlv_set_infoframes(struct drm_encoder *encoder,
@@ -821,7 +823,7 @@ static void vlv_set_infoframes(struct drm_encoder *encoder,
 
   	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
   	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
   }
 
   static void hsw_set_infoframes(struct drm_encoder *encoder,
@@ -854,7 +856,7 @@ static void hsw_set_infoframes(struct drm_encoder *encoder,
 
   	intel_hdmi_set_avi_infoframe(encoder, crtc_state);
   	intel_hdmi_set_spd_infoframe(encoder, crtc_state);
-	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state);
+	intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
   }
 
   void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
drivers/gpu/drm/mediatek/mtk_hdmi.c +2 -1
index b78791061983..59a11026dceb 100644
@@ -1054,7 +1054,8 @@ static int mtk_hdmi_setup_vendor_specific_infoframe(struct mtk_hdmi *hdmi,
   	u8 buffer[10];
   	ssize_t err;
 
-	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame, mode);
+	err = drm_hdmi_vendor_infoframe_from_display_mode(&frame,
+							  &hdmi->conn, mode);
   	if (err) {
   		dev_err(hdmi->dev,
   			"Failed to get vendor infoframe from mode: %zd\n", err);
drivers/gpu/drm/nouveau/nv50_display.c +2 -1
index b26a506d20ca..9d7b2afd7cfc 100644
@@ -2754,7 +2754,8 @@ nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
   			= hdmi_infoframe_pack(&avi_frame, args.infoframes, 17);
   	}
 
-	ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi, mode);
+	ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi,
+							  &nv_connector->base, mode);
   	if (!ret) {
   		/* We have a Vendor InfoFrame, populate it to the display */
   		args.pwr.vendor_infoframe_length
drivers/gpu/drm/rockchip/inno_hdmi.c +1 -0
index ee584d87111f..fab30927a889 100644
@@ -282,6 +282,7 @@ static int inno_hdmi_config_video_vsi(struct inno_hdmi *hdmi,
   	int rc;
 
   	rc = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							 &hdmi->connector,
   							 mode);
 
   	return inno_hdmi_upload_frame(hdmi, rc, &frame, INFOFRAME_VSI,
drivers/gpu/drm/sti/sti_hdmi.c +3 -1
index d1902750a85d..c3b292ab17a5 100644
@@ -515,7 +515,9 @@ static int hdmi_vendor_infoframe_config(struct sti_hdmi *hdmi)
 
   	DRM_DEBUG_DRIVER("\n");
 
-	ret = drm_hdmi_vendor_infoframe_from_display_mode(&infoframe, mode);
+	ret = drm_hdmi_vendor_infoframe_from_display_mode(&infoframe,
+							  hdmi->drm_connector,
+							  mode);
   	if (ret < 0) {
   		/*
   		 * Going into that statement does not means vendor infoframe
drivers/gpu/drm/zte/zx_hdmi.c +1 -0
index b8abb1b496ff..13ea90f7a185 100644
@@ -108,6 +108,7 @@ static int zx_hdmi_config_video_vsi(struct zx_hdmi *hdmi,
   	int ret;
 
   	ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
+							  &hdmi->connector,
   							  mode);
   	if (ret) {
   		DRM_DEV_ERROR(hdmi->dev, "failed to get vendor infoframe: %d\n",
include/drm/drm_connector.h +5 -0
index 2b97d1e28f60..1543212b0449 100644
@@ -270,6 +270,11 @@ struct drm_display_info {
   	bool dvi_dual;
 
   	/**
+	 * @has_hdmi_infoframe: Does the sink support the HDMI infoframe?
+	 */
+	bool has_hdmi_infoframe;
+
+	/**
   	 * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
   	 * more stuff redundant with @bus_formats.
   	 */
include/drm/drm_edid.h +0 -0
index 9e4e23524840..3c8740ad1db6 100644

include/drm/drm_edid.h drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 362

Quoted 7 lines
include/drm/drm_edid.h +1 -0
@@ -356,6 +356,7 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
   					 bool is_hdmi2_sink);
   int
   drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
+					    struct drm_connector *connector,
   					    const struct drm_display_mode *mode);
   void
   drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,

Otherwise looks good
- Shashank

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by
#31 lore raw

Re: [PATCH 07/10] drm/edid: Don't send bogus aspect ratios in AVI infoframes

In reply to Ville Syrjälä

Regards

Shashank

Quoted 81 lines · Ville Syrjälä
Quoted 80 lines · Shashank

Regards

Shashank

Quoted 63 lines · Ville Syrjälä
Quoted 62 lines · Shashank

Regards

Shashank

Quoted 36 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

If the user mode would specify an aspect ratio other than 4:3 or 16:9 we now silently ignore it. Maybe a better apporoach is to return an error? Let's try that.

Also we must be careful that we don't try to send illegal picture aspect in the infoframe as it's only capable of signalling none, 4:3, and 16:9. Currently we're sending these bogus infoframes whenever the cea mode specifies some other aspect ratio.

Cc Shashank Sharma <[email protected]>
Cc Sean Paul <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
    drivers/gpu/drm/drm_edid.c | 23 +++++++++++++++++------
    1 file changed, 17 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 00aa98f3e55d..bafb3ee4ea97 100644
@@ -4786,6 +4786,7 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
    					 const struct drm_display_mode *mode,
    					 bool is_hdmi2_sink)
    {
+	enum hdmi_picture_aspect picture_aspect;
    	int err;
 
    	if (!frame || !mode)
@@ -4828,13 +4829,23 @@ drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
    	 * Populate picture aspect ratio from either
    	 * user input (if specified) or from the CEA mode list.

drivers/gpu/drm/drm_edid.c drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 4834

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +3 -6
    	 */
-	if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
-		mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
-		frame->picture_aspect = mode->picture_aspect_ratio;
-	else if (frame->video_code > 0)
-		frame->picture_aspect = drm_get_cea_aspect_ratio(
-						frame->video_code);
+	picture_aspect = mode->picture_aspect_ratio;
+	if (picture_aspect == HDMI_PICTURE_ASPECT_NONE)
+		picture_aspect = drm_get_cea_aspect_ratio(frame->video_code);

This is slightly going in the loop.
- During the modeset the driver cant specify the aspect ratio information, as DRM layer lacks this support.
- So we fill the VIC field, by comparing the mode with the DRM_CEA_MODES[] list. This will pick the first mode
available in the list (regardless of its aspect ratio), and fill the
VIC, as we don't consider aspect ratio while comparing timings.
- Again, now while sending the aspect ratio, we are picking up the VIC, which may not be correct.

Quoted 5 lines
Quoted 2 lines

So if we have 720x480(4:3) and 720x480(16:9) in the list, as 4:3 is first in list, we will always pick 4:3 aspect ratio.

Yes. The user didn't care about the aspect ratio (or rather couldn't specify one) so we just pick one. Which is exactly what we've been doing ever since we started sending the VIC in the infoframe.

Correct, and we are hoping that this should be better (if not fixed) with the aspect ratio support
patches + DRM cap. If the userspace doesn't set the cap, then anyways there is no aspect ratio
field available, and VIC would be always 0, as this becomes a Non CEA mode.

Quoted 8 lines
Quoted 3 lines

Or do you think it would be a better idea to send some VIC instead of No VIC, when userspace doesn't
set the DRM cap for aspect ratio ?

Yes. That's the current behaviour.

IIRC some crappy amplifiers etc. with HDMI passthrough don't even work correctly unless VIC is specified. Hence we do want to send it whenever possible.

Ok, in this case this make sense, and then I kindof agree with what this patch is trying to do.

Quoted 19 lines
Quoted 19 lines

- Shashank

Quoted 18 lines
Quoted 18 lines

- Shashank

Quoted 7 lines
drivers/gpu/drm/drm_edid.c +6 -0
+	/*
+	 * The infoframe can't convey anything but none, 4:3
+	 * and 16:9, so if the user has asked for anything else
+	 * we can only satisfy it by specifying the right VIC.
+	 */
+	if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {

drivers/gpu/drm/drm_edid.c drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame, · line 4851

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +7 -0
+		if (picture_aspect !=
+		    drm_get_cea_aspect_ratio(frame->video_code))
+			return -EINVAL;
+		picture_aspect = HDMI_PICTURE_ASPECT_NONE;
+	}
+
+	frame->picture_aspect = picture_aspect;
    	frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
    	frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#22 lore raw

Re: [PATCH 06/10] drm/edid: Fix cea mode aspect ratio handling

In reply to Ville Syrjälä

Regards

Shashank

Quoted 113 lines · Ville Syrjälä
Quoted 112 lines · Shashank

Regards

Shashank

Quoted 82 lines · Ville Syrjälä
Quoted 69 lines · Shashank

Regards

Shashank

Quoted 52 lines · Ville Syrjälä
Quoted 51 lines · Shashank

Regards

Shashank

Quoted 45 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

commit 6dffd431e229 ("drm: Add aspect ratio parsing in DRM layer") cause us to not send out any VICs in the AVI infoframes. That commit was since reverted, but if and when we add aspect ratio handing back we need to be more careful.

Let's handle this by considering the aspect ratio as a requirement for cea mode matching only if the passed in mode actually has a non-zero aspect ratio field. This will keep userspace that doesn't provide an aspect ratio working as before by matching it to the first otherwise equal cea mode. And once userspace starts to provide the aspect ratio it will be considerd a hard requirement for the match.

Also change the hdmi mode matching to use drm_mode_match() for consistency, but we don't match on aspect ratio there since the spec doesn't list a specific aspect ratio for those modes.

Cc Shashank Sharma <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Akashdeep Sharma <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
     drivers/gpu/drm/drm_edid.c | 18 ++++++++++++++----
     1 file changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 7220b8f9a7e8..00aa98f3e55d 100644
@@ -2903,11 +2903,15 @@ cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
     static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
     					     unsigned int clock_tolerance)
     {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
     	u8 vic;
 
     	if (!to_match->clock)
     		return 0;
 
Quoted 6 lines
Quoted 5 lines

drivers/gpu/drm/drm_edid.c cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode) · line 2913

Quoted 2 lines
drivers/gpu/drm/drm_edid.c +2 -0
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

This doesn't look right. This means we are expecting a CEA mode without a pic aspect ratio field,
which is invalid.

No, it's perfectly valid. It's what we currently get from userspace.

Yep, but that's due to missing Aspect ratio handling in the DRM layer. If that's fixed, as per the list of CEA modes,
each CEA VIC contains an aspect ratio, which is a part of its unique identity.

Quoted 12 lines

I guess once we have the aspect ratio handling in DRM layer, it would/should look like this:
- EDID gives you all supported modes, including CEA modes with Aspect ratio
- Userspcae gets the mode information, with aspect ratio (for CEA modes) If ( Userspace picks one of the CEA modes)
- sends a modeset
- we find a matching CEA VIC, found one from modedb
- we load this VIC = nonzero information in AVI IF VIC field,
else
- sends a modeset
- we could not find a matching CEA VIC, as aspect ratio is 0
- we make VIC field in AVI IF as 0a

Quoted 1 line

No. That would break current userspace.

I guess I forgot to make it clear, that userspace will set the cap, only then we will provide aspect ratio information.
So this should not break userspace, isn't it ?

Quoted 6 lines
Quoted 2 lines

This is important, as HDMI compliance test 7-27 inspects if the VIC field in the AVI IF is accurate.

Complicance is secondary to not breaking things that work. Also I find it hard to see what purpose there is in having a complicance test that sets a CEA modes w/o aspect ratio and then expects the infoframe to have VIC 0.

Again, typically this is how these analyzers force modeset:
- They send EDID with only one mode, which is the test mode, with aspect ratio.
- They expect that VIC to be present in AVI IF

Quoted 10 lines
Quoted 10 lines

- Shashank

Quoted 5 lines
Quoted 3 lines

Ankit is going to publish the aspect ratio patch series again, with proper DRM cap and flags check. Would it be ok if we have a look that handling first ?

This patch will be needed by that work. Otherwise we're going to stop sending a VIC for CEA modes with current userspace.

I guess we should force userspaces to start bothering about aspect ratio field, right now we
are doing this for Wayland based compositors, may be we should extend it to X based too.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

Yes, I've been saying that someone should look into extending the randr protocol with the necessary bits. But that still doesn't allow us to change the current behaviour as old userspace would anyway linger around for a long time.

I think cap will cove this part

The cap is irrelevant to this discussion. It will not be set by old userspace, hence it won't change anything for old userspace. Modes coming from old userspace will still have aspect_ratio=0.

Agree, and in that case, why bother about aspect ratio flags here in this series ? Probably let this be taken care in aspect ratio series.
- Shashank

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#23 lore raw

Re: [PATCH 06/10] drm/edid: Fix cea mode aspect ratio handling

Quoted 123 lines · Shashank

Regards

Shashank

Quoted 117 lines · Ville Syrjälä
Quoted 116 lines · Shashank

Regards

Shashank

Quoted 82 lines · Ville Syrjälä
Quoted 69 lines · Shashank

Regards

Shashank

Quoted 52 lines · Ville Syrjälä
Quoted 51 lines · Shashank

Regards

Shashank

Quoted 45 lines · Ville Syrjala

From: Ville Syrjälä <[email protected]>

commit 6dffd431e229 ("drm: Add aspect ratio parsing in DRM layer") cause us to not send out any VICs in the AVI infoframes. That commit was since reverted, but if and when we add aspect ratio handing back we need to be more careful.

Let's handle this by considering the aspect ratio as a requirement for cea mode matching only if the passed in mode actually has a non-zero aspect ratio field. This will keep userspace that doesn't provide an aspect ratio working as before by matching it to the first otherwise equal cea mode. And once userspace starts to provide the aspect ratio it will be considerd a hard requirement for the match.

Also change the hdmi mode matching to use drm_mode_match() for consistency, but we don't match on aspect ratio there since the spec doesn't list a specific aspect ratio for those modes.

Cc Shashank Sharma <[email protected]>
Cc "Lin, Jia" <[email protected]>
Cc Akashdeep Sharma <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Emil Velikov <[email protected]>
---
     drivers/gpu/drm/drm_edid.c | 18 ++++++++++++++----
     1 file changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_edid.c +1 -0
index 7220b8f9a7e8..00aa98f3e55d 100644
@@ -2903,11 +2903,15 @@ cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
     static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
     					     unsigned int clock_tolerance)
     {
+	unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
     	u8 vic;
 
     	if (!to_match->clock)
     		return 0;
 
Quoted 6 lines
Quoted 5 lines

drivers/gpu/drm/drm_edid.c cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode) · line 2913

Quoted 2 lines
drivers/gpu/drm/drm_edid.c +2 -0
+	if (to_match->picture_aspect_ratio)
+		match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;

This doesn't look right. This means we are expecting a CEA mode without a pic aspect ratio field,
which is invalid.

No, it's perfectly valid. It's what we currently get from userspace.

Yep, but that's due to missing Aspect ratio handling in the DRM layer. If that's fixed, as per the list of CEA modes,
each CEA VIC contains an aspect ratio, which is a part of its unique identity.

Quoted 12 lines

I guess once we have the aspect ratio handling in DRM layer, it would/should look like this:
- EDID gives you all supported modes, including CEA modes with Aspect ratio
- Userspcae gets the mode information, with aspect ratio (for CEA modes) If ( Userspace picks one of the CEA modes)
- sends a modeset
- we find a matching CEA VIC, found one from modedb
- we load this VIC = nonzero information in AVI IF VIC field,
else
- sends a modeset
- we could not find a matching CEA VIC, as aspect ratio is 0
- we make VIC field in AVI IF as 0

Quoted 1 line

No. That would break current userspace.

I guess I forgot to make it clear, that userspace will set the cap, only then we will provide aspect ratio information.
So this should not break userspace, isn't it ?

Quoted 6 lines
Quoted 2 lines

This is important, as HDMI compliance test 7-27 inspects if the VIC field in the AVI IF is accurate.

Complicance is secondary to not breaking things that work. Also I find it hard to see what purpose there is in having a complicance test that sets a CEA modes w/o aspect ratio and then expects the infoframe to have VIC 0.

Again, typically this is how these analyzers force modeset:
- They send EDID with only one mode, which is the test mode, with aspect ratio.
- They expect that VIC to be present in AVI IF

Quoted 14 lines
Quoted 10 lines

- Shashank

Quoted 5 lines
Quoted 3 lines

Ankit is going to publish the aspect ratio patch series again, with proper DRM cap and flags check. Would it be ok if we have a look that handling first ?

This patch will be needed by that work. Otherwise we're going to stop sending a VIC for CEA modes with current userspace.

I guess we should force userspaces to start bothering about aspect ratio field, right now we
are doing this for Wayland based compositors, may be we should extend it to X based too.

Yes, I've been saying that someone should look into extending the randr protocol with the necessary bits. But that still doesn't allow us to change the current behaviour as old userspace would anyway linger around for a long time.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I think cap will cove this part

The cap is irrelevant to this discussion. It will not be set by old userspace, hence it won't change anything for old userspace. Modes coming from old userspace will still have aspect_ratio=0.

Agree, and in that case, why bother about aspect ratio flags here in this series ? Probably let this be taken care in aspect ratio series.

If someone wants to suck these patches into the aspect ratio series that fine by me.

I had them here because they were on the same branch where I had the fix for the aspect ratio in the infoframe. And I was too lazy to remove them from the series, figuring they're semi-related anyway.

Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel