Skip to contentSkip to conversation

drm/edid: Implement DisplayID Type IX & X timing blocks parsing

PATCH RESEND Superseded Egor Vorontsov 2 participants 3 messages Feb 7, 2025 – Feb 12, 2025

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 drm/edid: Implement DisplayID Type IX & X timing blocks parsing

Some newer high refresh rate consumer monitors (including those by Samsung) make use of DisplayID 2.1 timing blocks in their EDID data, notably for their highest refresh rate modes. Such modes won't be available as of now.

Implement partial support for such blocks in order to enable native support of HRR modes of most such monitors for users without having to rely on EDID patching/override (or need thereof).

---

The formatting was taken from the neighboring code for consistency, thus some warnings.

[Resent due to some Spamhaus issues that are now resolved.]

 drivers/gpu/drm/drm_displayid_internal.h | 13 +++++
 drivers/gpu/drm/drm_edid.c               | 61 ++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
drivers/gpu/drm/drm_displayid_internal.h +13 -0
index aee1b86a73c1..a75d0f637b72 100644
@@ -66,6 +66,7 @@ struct drm_edid;
 #define DATA_BLOCK_2_STEREO_DISPLAY_INTERFACE	0x27
 #define DATA_BLOCK_2_TILED_DISPLAY_TOPOLOGY	0x28
 #define DATA_BLOCK_2_CONTAINER_ID		0x29
+#define DATA_BLOCK_2_TYPE_10_FORMULA_TIMING	0x2a
 #define DATA_BLOCK_2_VENDOR_SPECIFIC		0x7e
 #define DATA_BLOCK_2_CTA_DISPLAY_ID		0x81
 
@@ -129,6 +130,18 @@ struct displayid_detailed_timing_block {
 	struct displayid_detailed_timings_1 timings[];
 };
 
+struct displayid_formula_timings_9 {
+	u8 flags;
+	u8 hactive[2];
+	u8 vactive[2];
+	u8 refresh;
+} __packed;
+
+struct displayid_formula_timing_block {
+	struct displayid_block base;
+	struct displayid_formula_timings_9 timings[];
+};
+
 #define DISPLAYID_VESA_MSO_OVERLAP	GENMASK(3, 0)
 #define DISPLAYID_VESA_MSO_MODE		GENMASK(6, 5)
 
drivers/gpu/drm/drm_edid.c +61 -0

73 lines not on this page · raw message

Signature · 1 line
2.48.0
#1 lore raw
Quoted 7 lines · Egor Vorontsov

Some newer high refresh rate consumer monitors (including those by Samsung) make use of DisplayID 2.1 timing blocks in their EDID data, notably for their highest refresh rate modes. Such modes won't be available as of now.

Implement partial support for such blocks in order to enable native support of HRR modes of most such monitors for users without having to rely on EDID patching/override (or need thereof).

Thanks for the patch. It appears to do what's desired, but please find quite a bit of comments inline.

Quoted 1 line

I think "Closes:" is what we want.

Quoted 7 lines

---

The formatting was taken from the neighboring code for consistency, thus some warnings.

Sometimes it's good to follow the surrounding code, but let's not duplicate existing mistakes. ;)

Quoted 20 lines

[Resent due to some Spamhaus issues that are now resolved.]

 drivers/gpu/drm/drm_displayid_internal.h | 13 +++++
 drivers/gpu/drm/drm_edid.c               | 61 ++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
drivers/gpu/drm/drm_displayid_internal.h +1 -0
index aee1b86a73c1..a75d0f637b72 100644
@@ -66,6 +66,7 @@ struct drm_edid;
 #define DATA_BLOCK_2_STEREO_DISPLAY_INTERFACE	0x27
 #define DATA_BLOCK_2_TILED_DISPLAY_TOPOLOGY	0x28
 #define DATA_BLOCK_2_CONTAINER_ID		0x29
+#define DATA_BLOCK_2_TYPE_10_FORMULA_TIMING	0x2a
 #define DATA_BLOCK_2_VENDOR_SPECIFIC		0x7e
 #define DATA_BLOCK_2_CTA_DISPLAY_ID		0x81
 

drivers/gpu/drm/drm_displayid_internal.h struct displayid_detailed_timing_block { · line 136

Quoted 7 lines
drivers/gpu/drm/drm_displayid_internal.h +4 -0
@@ -129,6 +130,18 @@ struct displayid_detailed_timing_block {
 	struct displayid_detailed_timings_1 timings[];
 };
 
+struct displayid_formula_timings_9 {
+	u8 flags;
+	u8 hactive[2];
+	u8 vactive[2];

Regardless of what was done in struct displayid_detailed_timings_1, I'd go for defining these as:

	__be16 hactive;
	__be16 vactive;

and using be16_to_cpu() instead of hand-rolling it.

drivers/gpu/drm/drm_displayid_internal.h struct displayid_detailed_timing_block { · line 137

Quoted 1 line
drivers/gpu/drm/drm_displayid_internal.h +1 -0
+	u8 refresh;

Nitpick, I'd go for vrefresh.

drivers/gpu/drm/drm_displayid_internal.h struct displayid_detailed_timing_block { · line 143

Quoted 6 lines
drivers/gpu/drm/drm_displayid_internal.h +6 -0
+} __packed;
+
+struct displayid_formula_timing_block {
+	struct displayid_block base;
+	struct displayid_formula_timings_9 timings[];
+};

I know it's lacking in struct displayid_detailed_timing_block, but I'd add __packed here too.

Quoted 9 lines
drivers/gpu/drm/drm_displayid_internal.h +1 -0
+
 #define DISPLAYID_VESA_MSO_OVERLAP	GENMASK(3, 0)
 #define DISPLAYID_VESA_MSO_MODE		GENMASK(6, 5)
 
drivers/gpu/drm/drm_edid.c +0 -0
index 13bc4c290b17..8a4dec1d781c 100644

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6837

Quoted 5 lines
drivers/gpu/drm/drm_edid.c +2 -0
@@ -6833,6 +6833,64 @@ static int add_displayid_detailed_1_modes(struct drm_connector *connector,
 	return num_modes;
 }
 
+static struct drm_display_mode *drm_mode_displayid_formula(struct drm_device *dev,
+							   struct displayid_formula_timings_9 *timings,

const

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6842

Quoted 5 lines
drivers/gpu/drm/drm_edid.c +5 -0
+							   bool type_10)
+{
+	struct drm_display_mode *mode;
+	unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
+	unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
	u16 hactive = be16_to_cpu(timings->hactive) + 1;
        etc.

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6843

Quoted 1 line
drivers/gpu/drm/drm_edid.c +1 -0
+	u8 rb = timings->flags & 0b111;

I'd call this formula or algorithm instead of just rb.

Please avoid 0b, it's very rarely used. Just 0x7. Or we could start defining macros for these in drm_displayid_internal.h...

Please add a blank line between declarations and code here.

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6848

Quoted 5 lines
drivers/gpu/drm/drm_edid.c +5 -0
+	/* TODO: support RB-v2 & RB-v3 */
+	if (rb > 1)
+		return NULL;
+
+	mode = drm_cvt_mode(dev, hactive, vactive, timings->refresh, rb == 1, false, false);

Refresh rate is -1 in the data block, so this needs timings->refresh + 1.

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6852

Quoted 4 lines
drivers/gpu/drm/drm_edid.c +4 -0
+	if (!mode)
+		return NULL;
+
+	/* TODO: interpret S3D flags */

More important is TODO for fractional refresh rate indicated by bit 4 of flags.

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6857

Quoted 5 lines
drivers/gpu/drm/drm_edid.c +5 -0
+
+	mode->type = DRM_MODE_TYPE_DRIVER;
+
+	if (timings->flags & 0x80)
+		mode->type |= DRM_MODE_TYPE_PREFERRED;

There's no such thing?

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6866

Quoted 9 lines
drivers/gpu/drm/drm_edid.c +9 -0
+	drm_mode_set_name(mode);
+
+	return mode;
+}
+
+static int add_displayid_formula_modes(struct drm_connector *connector,
+				       const struct displayid_block *block)
+{
+	struct displayid_formula_timing_block *fb = (struct displayid_formula_timing_block *)block;

Please avoid fb as the name for this. Everyone's going to go all "framebuffer", wtf, backtrack, oh, "formula block". ;)

This should also be a const pointer. (I know, the detailed modes one isn't. Let's not duplicate mistakes from there.)

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6871

Quoted 5 lines
drivers/gpu/drm/drm_edid.c +5 -0
+	int num_timings;
+	struct drm_display_mode *newmode;
+	int num_modes = 0;
+	bool type_10 = block->tag == DATA_BLOCK_2_TYPE_10_FORMULA_TIMING;
+	u8 timing_size = 6 + ((fb->base.rev & 0x70) >> 4);

I'd go for int timing_size.

Blank line here.

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6881

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +10 -0
+	/* extended blocks are not supported yet */
+	if (timing_size != 6)
+		return 0;
+
+	if (block->num_bytes % timing_size)
+		return 0;
+
+	num_timings = block->num_bytes / timing_size;
+	for (int i = 0; i < num_timings; i++) {
+		struct displayid_formula_timings_9 *timings = \

const. Please don't use \ line continuations, it's not necessary.

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6882

Quoted 1 line
drivers/gpu/drm/drm_edid.c +1 -0
+			(struct displayid_formula_timings_9 *)&((u8 *)fb->timings)[i * timing_size];

Since we only support the one size for now, and that size is fixed in struct displayid_formula_timings_9, there's no need to do all this hackery. Just formula->timings[i].

Whoever fixes this for size 7 might have a better idea how to handle the size anyway.

Quoted 23 lines
drivers/gpu/drm/drm_edid.c +14 -0
+
+		newmode = drm_mode_displayid_formula(connector->dev, timings, type_10);
+		if (!newmode)
+			continue;
+
+		drm_mode_probed_add(connector, newmode);
+		num_modes++;
+	}
+	return num_modes;
+}
+
 static int add_displayid_detailed_modes(struct drm_connector *connector,
 					const struct drm_edid *drm_edid)
 {
@@ -6845,6 +6903,9 @@ static int add_displayid_detailed_modes(struct drm_connector *connector,
 		if (block->tag == DATA_BLOCK_TYPE_1_DETAILED_TIMING ||
 		    block->tag == DATA_BLOCK_2_TYPE_7_DETAILED_TIMING)
 			num_modes += add_displayid_detailed_1_modes(connector, block);
+		else if (block->tag == DATA_BLOCK_2_TYPE_9_FORMULA_TIMING ||
+			 block->tag == DATA_BLOCK_2_TYPE_10_FORMULA_TIMING)
+			num_modes += add_displayid_formula_modes(connector, block);
 	}
 	displayid_iter_end(&iter);
Signature · 1 line
Jani Nikula, Intel
#2 lore raw
Quoted 3 lines · Jani Nikula

I think "Closes:" is what we want.
Sometimes it's good to follow the surrounding code, but let's not duplicate existing mistakes. ;)

Ack!

Quoted 2 lines

Please avoid 0b, it's very rarely used. Just 0x7. Or we could start defining macros for these in drm_displayid_internal.h...

I guess I'll leave the macros to future implementation, as clearly the naming here is subject to seeing the actual DisplayID 2.1 specs PDF, which is non-public as of now.

Quoted 1 line

Refresh rate is -1 in the data block, so this needs timings->refresh + 1.

Ack, nice catch! Worked for me, might've not for someone else's case.

Quoted 3 lines

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6857

Quoted 2 lines
drivers/gpu/drm/drm_edid.c +2 -0
+	if (timings->flags & 0x80)
+ mode->type |= DRM_MODE_TYPE_PREFERRED;

There's no such thing?

Oh, accidentally picked up from `drm_mode_displayid_detailed()'. Ack.

Quoted 2 lines

drivers/gpu/drm/drm_edid.c static int add_displayid_detailed_1_modes(struct drm_connector *connector, · line 6871

Quoted 1 line
drivers/gpu/drm/drm_edid.c +1 -0
+	u8 timing_size = 6 + ((fb->base.rev & 0x70) >> 4);

I'd go for int timing_size.

I'd actually vote for an unsigned int, as it's a length and can't possibly be negative. But sticking to the M.O. of the file here.

Thank you for the review! Fixed per all other notes, as well.

Will resubmit soon,
Egor