[Intel-gfx] [PATCH v2 06/11] drm/edid: use struct detailed_data_monitor_range member access in gtf2 functions

Jani Nikula jani.nikula at intel.com
Mon Mar 28 09:17:20 UTC 2022


Use struct struct detailed_data_monitor_range member access instead of
direct offsets to avoid casting.

Use BUILD_BUG_ON() for sanity check.

v2:
- Rename timing to descriptor (Ville)
- Return and use struct detailed_data_monitor_range

Cc: Ville Syrjälä <ville.syrjala at linux.intel.com>
Signed-off-by: Jani Nikula <jani.nikula at intel.com>
---
 drivers/gpu/drm/drm_edid.c | 63 ++++++++++++++++++++++++++------------
 1 file changed, 43 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 242f074f60d9..4d63f3412672 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -2438,61 +2438,84 @@ drm_monitor_supports_rb(struct edid *edid)
 }
 
 static void
-find_gtf2(struct detailed_timing *t, void *data)
+find_gtf2(struct detailed_timing *descriptor, void *data)
 {
-	u8 *r = (u8 *)t;
+	struct detailed_data_monitor_range **res = data;
 
-	if (!is_display_descriptor(t, EDID_DETAIL_MONITOR_RANGE))
+	if (!is_display_descriptor(descriptor, EDID_DETAIL_MONITOR_RANGE))
 		return;
 
-	if (r[10] == 0x02)
-		*(u8 **)data = r;
+	BUILD_BUG_ON(offsetof(typeof(*descriptor), data.descriptor.data.range.flags) != 10);
+
+	if (descriptor->data.descriptor.data.range.flags ==
+	    DRM_EDID_SECONDARY_GTF_SUPPORT_FLAG)
+		*res = &descriptor->data.descriptor.data.range;
 }
 
 /* Secondary GTF curve kicks in above some break frequency */
 static int
 drm_gtf2_hbreak(struct edid *edid)
 {
-	u8 *r = NULL;
+	struct detailed_data_monitor_range *range = NULL;
+
+	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &range);
 
-	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
-	return r ? (r[12] * 2) : 0;
+	BUILD_BUG_ON(offsetof(struct detailed_timing, data.descriptor.data.range) +
+		     offsetof(typeof(*range), formula.gtf2.hfreq_start_khz) != 12);
+
+	return range ? range->formula.gtf2.hfreq_start_khz * 2 : 0;
 }
 
 static int
 drm_gtf2_2c(struct edid *edid)
 {
-	u8 *r = NULL;
+	struct detailed_data_monitor_range *range = NULL;
+
+	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &range);
+
+	BUILD_BUG_ON(offsetof(struct detailed_timing, data.descriptor.data.range) +
+		     offsetof(typeof(*range), formula.gtf2.c) != 13);
 
-	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
-	return r ? r[13] : 0;
+	return range ? range->formula.gtf2.c : 0;
 }
 
 static int
 drm_gtf2_m(struct edid *edid)
 {
-	u8 *r = NULL;
+	struct detailed_data_monitor_range *range = NULL;
 
-	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
-	return r ? (r[15] << 8) + r[14] : 0;
+	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &range);
+
+	BUILD_BUG_ON(offsetof(struct detailed_timing, data.descriptor.data.range) +
+		     offsetof(typeof(*range), formula.gtf2.m) != 14);
+
+	return range ? le16_to_cpu(range->formula.gtf2.m) : 0;
 }
 
 static int
 drm_gtf2_k(struct edid *edid)
 {
-	u8 *r = NULL;
+	struct detailed_data_monitor_range *range = NULL;
+
+	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &range);
 
-	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
-	return r ? r[16] : 0;
+	BUILD_BUG_ON(offsetof(struct detailed_timing, data.descriptor.data.range) +
+		     offsetof(typeof(*range), formula.gtf2.k) != 16);
+
+	return range ? range->formula.gtf2.k : 0;
 }
 
 static int
 drm_gtf2_2j(struct edid *edid)
 {
-	u8 *r = NULL;
+	struct detailed_data_monitor_range *range = NULL;
+
+	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &range);
+
+	BUILD_BUG_ON(offsetof(struct detailed_timing, data.descriptor.data.range) +
+		     offsetof(typeof(*range), formula.gtf2.j) != 17);
 
-	drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
-	return r ? r[17] : 0;
+	return range ? range->formula.gtf2.j : 0;
 }
 
 /**
-- 
2.30.2



More information about the Intel-gfx mailing list