Remove accidental (?) EDID modification while parsing, and constify EDID in most places during EDID parsing.
In the future I'll want more clarity on who modifies the EDID and where, and I'll want the compiler to help.
The EDID is still mutable in places that do validity checking and try to fix it in the process. I'll probably want to split the two into separate check and fix steps too, but that's for another series.
This is based on current drm-tip, without the CEA iterators work.
BR, Jani.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com
Jani Nikula (9): drm/edid: don't modify EDID while parsing drm/edid: pass a timing pointer to is_display_descriptor() drm/edid: use struct detailed_timing member access in is_rb() drm/edid: use struct detailed_timing member access in gtf2 functions drm/edid: constify struct detailed_timing in lower level parsing drm/edid: constify struct detailed_timing in parsing callbacks drm/edid: constify struct edid passed to detailed blocks drm/edid: constify struct edid passed around in callbacks and closure drm/edid: add more general struct edid constness in the interfaces
drivers/gpu/drm/drm_edid.c | 272 ++++++++++++++++++++----------------- include/drm/drm_edid.h | 10 +- 2 files changed, 153 insertions(+), 129 deletions(-)
We'll want to keep the EDID immutable while parsing. Stop modifying the EDID because of the quirks.
In theory, this does have userspace implications, but the userspace is supposed to use the modes exposed via KMS API, not by parsing the EDID directly.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com --- drivers/gpu/drm/drm_edid.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index cc7bd58369df..1b552fe54f38 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2740,9 +2740,9 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, return NULL;
if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH) - timing->pixel_clock = cpu_to_le16(1088); - - mode->clock = le16_to_cpu(timing->pixel_clock) * 10; + mode->clock = 1088 * 10; + else + mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
mode->hdisplay = hactive; mode->hsync_start = mode->hdisplay + hsync_offset; @@ -2763,14 +2763,14 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, drm_mode_do_interlace_quirk(mode, pt);
if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) { - pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE; + mode->flags |= DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC; + } else { + mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ? + DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC; + mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ? + DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC; }
- mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ? - DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC; - mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ? - DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC; - set_size: mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4; mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
On Fri, Mar 25, 2022 at 02:25:23PM +0200, Jani Nikula wrote:
We'll want to keep the EDID immutable while parsing. Stop modifying the EDID because of the quirks.
In theory, this does have userspace implications, but the userspace is supposed to use the modes exposed via KMS API, not by parsing the EDID directly.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com
Reviewed-by: Ville Syrjälä ville.syrjala@linux.intel.com
drivers/gpu/drm/drm_edid.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index cc7bd58369df..1b552fe54f38 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2740,9 +2740,9 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, return NULL;
if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
timing->pixel_clock = cpu_to_le16(1088);
- mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
mode->clock = 1088 * 10;
else
mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
mode->hdisplay = hactive; mode->hsync_start = mode->hdisplay + hsync_offset;
@@ -2763,14 +2763,14 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, drm_mode_do_interlace_quirk(mode, pt);
if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
mode->flags |= DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC;
- } else {
mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
}DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
- mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
- mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
set_size: mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4; mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8; -- 2.30.2
Use struct member access instead of direct offsets to avoid lots of casts all over the place.
Use BUILD_BUG_ON() for sanity check.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com --- drivers/gpu/drm/drm_edid.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 1b552fe54f38..48707eef1dc2 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2331,10 +2331,14 @@ struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, } EXPORT_SYMBOL(drm_mode_find_dmt);
-static bool is_display_descriptor(const u8 d[18], u8 tag) +static bool is_display_descriptor(const struct detailed_timing *timing, u8 type) { - return d[0] == 0x00 && d[1] == 0x00 && - d[2] == 0x00 && d[3] == tag; + BUILD_BUG_ON(offsetof(typeof(*timing), pixel_clock) != 0); + BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.pad1) != 2); + BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.type) != 3); + + return timing->pixel_clock == 0 && timing->data.other_data.pad1 == 0 && + timing->data.other_data.type == type; }
static bool is_detailed_timing_descriptor(const u8 d[18]) @@ -2405,7 +2409,7 @@ is_rb(struct detailed_timing *t, void *data) { u8 *r = (u8 *)t;
- if (!is_display_descriptor(r, EDID_DETAIL_MONITOR_RANGE)) + if (!is_display_descriptor(t, EDID_DETAIL_MONITOR_RANGE)) return;
if (r[15] & 0x10) @@ -2431,7 +2435,7 @@ find_gtf2(struct detailed_timing *t, void *data) { u8 *r = (u8 *)t;
- if (!is_display_descriptor(r, EDID_DETAIL_MONITOR_RANGE)) + if (!is_display_descriptor(t, EDID_DETAIL_MONITOR_RANGE)) return;
if (r[10] == 0x02) @@ -2987,7 +2991,7 @@ do_inferred_modes(struct detailed_timing *timing, void *c) struct detailed_non_pixel *data = &timing->data.other_data; struct detailed_data_monitor_range *range = &data->data.range;
- if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_MONITOR_RANGE)) + if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE)) return;
closure->modes += drm_dmt_modes_for_range(closure->connector, @@ -3067,7 +3071,7 @@ do_established_modes(struct detailed_timing *timing, void *c) { struct detailed_mode_closure *closure = c;
- if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_EST_TIMINGS)) + if (!is_display_descriptor(timing, EDID_DETAIL_EST_TIMINGS)) return;
closure->modes += drm_est3_modes(closure->connector, timing); @@ -3122,7 +3126,7 @@ do_standard_modes(struct detailed_timing *timing, void *c) struct edid *edid = closure->edid; int i;
- if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_STD_MODES)) + if (!is_display_descriptor(timing, EDID_DETAIL_STD_MODES)) return;
for (i = 0; i < 6; i++) { @@ -3231,7 +3235,7 @@ do_cvt_mode(struct detailed_timing *timing, void *c) { struct detailed_mode_closure *closure = c;
- if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_CVT_3BYTE)) + if (!is_display_descriptor(timing, EDID_DETAIL_CVT_3BYTE)) return;
closure->modes += drm_cvt_modes(closure->connector, timing); @@ -4491,7 +4495,7 @@ drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db) static void monitor_name(struct detailed_timing *t, void *data) { - if (!is_display_descriptor((const u8 *)t, EDID_DETAIL_MONITOR_NAME)) + if (!is_display_descriptor(t, EDID_DETAIL_MONITOR_NAME)) return;
*(u8 **)data = t->data.other_data.data.str.str; @@ -5226,7 +5230,7 @@ void get_monitor_range(struct detailed_timing *timing, const struct detailed_non_pixel *data = &timing->data.other_data; const struct detailed_data_monitor_range *range = &data->data.range;
- if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_MONITOR_RANGE)) + if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE)) return;
/*
On Fri, Mar 25, 2022 at 02:25:24PM +0200, Jani Nikula wrote:
Use struct member access instead of direct offsets to avoid lots of casts all over the place.
Use BUILD_BUG_ON() for sanity check.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com
drivers/gpu/drm/drm_edid.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 1b552fe54f38..48707eef1dc2 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2331,10 +2331,14 @@ struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, } EXPORT_SYMBOL(drm_mode_find_dmt);
-static bool is_display_descriptor(const u8 d[18], u8 tag) +static bool is_display_descriptor(const struct detailed_timing *timing, u8 type) {
- return d[0] == 0x00 && d[1] == 0x00 &&
d[2] == 0x00 && d[3] == tag;
- BUILD_BUG_ON(offsetof(typeof(*timing), pixel_clock) != 0);
- BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.pad1) != 2);
- BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.type) != 3);
- return timing->pixel_clock == 0 && timing->data.other_data.pad1 == 0 &&
This would probably be less confusing if we moved pixel_clock into pixel_data and just had matching padding bytes/etc. in other_data.
The names of all structs are also rather weird. We should probably change them to match the spec terminology a bit more closely: 18 byte descriptor,detailed timing descriptor,display descriptor. But that's a separate topic.
timing->data.other_data.type == type;
}
static bool is_detailed_timing_descriptor(const u8 d[18]) @@ -2405,7 +2409,7 @@ is_rb(struct detailed_timing *t, void *data) { u8 *r = (u8 *)t;
- if (!is_display_descriptor(r, EDID_DETAIL_MONITOR_RANGE))
if (!is_display_descriptor(t, EDID_DETAIL_MONITOR_RANGE)) return;
if (r[15] & 0x10)
@@ -2431,7 +2435,7 @@ find_gtf2(struct detailed_timing *t, void *data) { u8 *r = (u8 *)t;
- if (!is_display_descriptor(r, EDID_DETAIL_MONITOR_RANGE))
if (!is_display_descriptor(t, EDID_DETAIL_MONITOR_RANGE)) return;
if (r[10] == 0x02)
@@ -2987,7 +2991,7 @@ do_inferred_modes(struct detailed_timing *timing, void *c) struct detailed_non_pixel *data = &timing->data.other_data; struct detailed_data_monitor_range *range = &data->data.range;
- if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_MONITOR_RANGE))
if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE)) return;
closure->modes += drm_dmt_modes_for_range(closure->connector,
@@ -3067,7 +3071,7 @@ do_established_modes(struct detailed_timing *timing, void *c) { struct detailed_mode_closure *closure = c;
- if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_EST_TIMINGS))
if (!is_display_descriptor(timing, EDID_DETAIL_EST_TIMINGS)) return;
closure->modes += drm_est3_modes(closure->connector, timing);
@@ -3122,7 +3126,7 @@ do_standard_modes(struct detailed_timing *timing, void *c) struct edid *edid = closure->edid; int i;
- if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_STD_MODES))
if (!is_display_descriptor(timing, EDID_DETAIL_STD_MODES)) return;
for (i = 0; i < 6; i++) {
@@ -3231,7 +3235,7 @@ do_cvt_mode(struct detailed_timing *timing, void *c) { struct detailed_mode_closure *closure = c;
- if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_CVT_3BYTE))
if (!is_display_descriptor(timing, EDID_DETAIL_CVT_3BYTE)) return;
closure->modes += drm_cvt_modes(closure->connector, timing);
@@ -4491,7 +4495,7 @@ drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db) static void monitor_name(struct detailed_timing *t, void *data) {
- if (!is_display_descriptor((const u8 *)t, EDID_DETAIL_MONITOR_NAME))
if (!is_display_descriptor(t, EDID_DETAIL_MONITOR_NAME)) return;
*(u8 **)data = t->data.other_data.data.str.str;
@@ -5226,7 +5230,7 @@ void get_monitor_range(struct detailed_timing *timing, const struct detailed_non_pixel *data = &timing->data.other_data; const struct detailed_data_monitor_range *range = &data->data.range;
- if (!is_display_descriptor((const u8 *)timing, EDID_DETAIL_MONITOR_RANGE))
if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE)) return;
/*
-- 2.30.2
Use struct detailed_timing member access instead of direct offsets to avoid casting.
Use BUILD_BUG_ON() for sanity check.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com
---
Note: Why can we use range.formula.cvt.flags directly in is_rb() while gtf2 functions check for range.flags == 0x02 first to ensure it's gtf2? --- drivers/gpu/drm/drm_edid.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 48707eef1dc2..5396fa78e864 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2405,15 +2405,17 @@ drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure) }
static void -is_rb(struct detailed_timing *t, void *data) +is_rb(struct detailed_timing *timing, void *data) { - u8 *r = (u8 *)t; + bool *res = data;
- if (!is_display_descriptor(t, EDID_DETAIL_MONITOR_RANGE)) + if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE)) return;
- if (r[15] & 0x10) - *(bool *)data = true; + BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.cvt.flags) != 15); + + if (timing->data.other_data.data.range.formula.cvt.flags & 0x10) + *res = true; }
/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
On Fri, Mar 25, 2022 at 02:25:25PM +0200, Jani Nikula wrote:
Use struct detailed_timing member access instead of direct offsets to avoid casting.
Use BUILD_BUG_ON() for sanity check.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com
Note: Why can we use range.formula.cvt.flags directly in is_rb() while gtf2 functions check for range.flags == 0x02 first to ensure it's gtf2?
Looks to me like is_rb() is just borked.
Other weird stuff I just noticed is get_monitor_range() not doing anything for flags!=0x1 cases. It also fails to handle the other flags that were added to byte 4 in EDID 1.4.
drivers/gpu/drm/drm_edid.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 48707eef1dc2..5396fa78e864 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2405,15 +2405,17 @@ drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure) }
static void -is_rb(struct detailed_timing *t, void *data) +is_rb(struct detailed_timing *timing, void *data) {
- u8 *r = (u8 *)t;
- bool *res = data;
- if (!is_display_descriptor(t, EDID_DETAIL_MONITOR_RANGE))
- if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE))
Calling this 'timing' when it's not is a bit confusing. I'd probably rename it to something else for all the display descriptor cases.
return;
- if (r[15] & 0x10)
*(bool *)data = true;
- BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.cvt.flags) != 15);
- if (timing->data.other_data.data.range.formula.cvt.flags & 0x10)
*res = true;
}
/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
2.30.2
Use struct detailed_timing member access instead of direct offsets to avoid casting.
Use BUILD_BUG_ON() for sanity check.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com --- drivers/gpu/drm/drm_edid.c | 57 +++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 20 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 5396fa78e864..a9df75cdcc5b 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2433,61 +2433,78 @@ drm_monitor_supports_rb(struct edid *edid) }
static void -find_gtf2(struct detailed_timing *t, void *data) +find_gtf2(struct detailed_timing *timing, void *data) { - u8 *r = (u8 *)t; + struct detailed_timing **res = data;
- if (!is_display_descriptor(t, EDID_DETAIL_MONITOR_RANGE)) + if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE)) return;
- if (r[10] == 0x02) - *(u8 **)data = r; + BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.flags) != 10); + + if (timing->data.other_data.data.range.flags == 0x02) + *res = timing; }
/* Secondary GTF curve kicks in above some break frequency */ static int drm_gtf2_hbreak(struct edid *edid) { - u8 *r = NULL; + struct detailed_timing *timing = NULL; + + drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing);
- drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); - return r ? (r[12] * 2) : 0; + BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.gtf2.hfreq_start_khz) != 12); + + return timing ? timing->data.other_data.data.range.formula.gtf2.hfreq_start_khz * 2 : 0; }
static int drm_gtf2_2c(struct edid *edid) { - u8 *r = NULL; + struct detailed_timing *timing = NULL; + + drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing); + + BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.gtf2.c) != 13);
- drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); - return r ? r[13] : 0; + return timing ? timing->data.other_data.data.range.formula.gtf2.c : 0; }
static int drm_gtf2_m(struct edid *edid) { - u8 *r = NULL; + struct detailed_timing *timing = 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, &timing); + + BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.gtf2.m) != 14); + + return timing ? le16_to_cpu(timing->data.other_data.data.range.formula.gtf2.m) : 0; }
static int drm_gtf2_k(struct edid *edid) { - u8 *r = NULL; + struct detailed_timing *timing = NULL; + + drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing);
- drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); - return r ? r[16] : 0; + BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.gtf2.k) != 16); + + return timing ? timing->data.other_data.data.range.formula.gtf2.k : 0; }
static int drm_gtf2_2j(struct edid *edid) { - u8 *r = NULL; + struct detailed_timing *timing = NULL; + + drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing); + + BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.gtf2.j) != 17);
- drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); - return r ? r[17] : 0; + return timing ? timing->data.other_data.data.range.formula.gtf2.j : 0; }
/**
Start constifying the struct detailed_timing pointers being passed around from bottom up.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com --- drivers/gpu/drm/drm_edid.c | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index a9df75cdcc5b..593f151c1155 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2555,7 +2555,7 @@ static int drm_mode_hsync(const struct drm_display_mode *mode) */ static struct drm_display_mode * drm_mode_std(struct drm_connector *connector, struct edid *edid, - struct std_timing *t) + const struct std_timing *t) { struct drm_device *dev = connector->dev; struct drm_display_mode *m, *mode = NULL; @@ -2673,7 +2673,7 @@ drm_mode_std(struct drm_connector *connector, struct edid *edid, */ static void drm_mode_do_interlace_quirk(struct drm_display_mode *mode, - struct detailed_pixel_timing *pt) + const struct detailed_pixel_timing *pt) { int i; static const struct { @@ -2717,11 +2717,11 @@ drm_mode_do_interlace_quirk(struct drm_display_mode *mode, */ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, struct edid *edid, - struct detailed_timing *timing, + const struct detailed_timing *timing, u32 quirks) { struct drm_display_mode *mode; - struct detailed_pixel_timing *pt = &timing->data.pixel_data; + const struct detailed_pixel_timing *pt = &timing->data.pixel_data; unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo; unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo; unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo; @@ -2816,7 +2816,7 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
static bool mode_in_hsync_range(const struct drm_display_mode *mode, - struct edid *edid, u8 *t) + struct edid *edid, const u8 *t) { int hsync, hmin, hmax;
@@ -2833,7 +2833,7 @@ mode_in_hsync_range(const struct drm_display_mode *mode,
static bool mode_in_vsync_range(const struct drm_display_mode *mode, - struct edid *edid, u8 *t) + struct edid *edid, const u8 *t) { int vsync, vmin, vmax;
@@ -2849,7 +2849,7 @@ mode_in_vsync_range(const struct drm_display_mode *mode, }
static u32 -range_pixel_clock(struct edid *edid, u8 *t) +range_pixel_clock(struct edid *edid, const u8 *t) { /* unspecified */ if (t[9] == 0 || t[9] == 255) @@ -2865,10 +2865,10 @@ range_pixel_clock(struct edid *edid, u8 *t)
static bool mode_in_range(const struct drm_display_mode *mode, struct edid *edid, - struct detailed_timing *timing) + const struct detailed_timing *timing) { u32 max_clock; - u8 *t = (u8 *)timing; + const u8 *t = (const u8 *)timing;
if (!mode_in_hsync_range(mode, edid, t)) return false; @@ -2911,7 +2911,7 @@ static bool valid_inferred_mode(const struct drm_connector *connector,
static int drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid, - struct detailed_timing *timing) + const struct detailed_timing *timing) { int i, modes = 0; struct drm_display_mode *newmode; @@ -2946,7 +2946,7 @@ void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
static int drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid, - struct detailed_timing *timing) + const struct detailed_timing *timing) { int i, modes = 0; struct drm_display_mode *newmode; @@ -2975,7 +2975,7 @@ drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
static int drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid, - struct detailed_timing *timing) + const struct detailed_timing *timing) { int i, modes = 0; struct drm_display_mode *newmode; @@ -3007,8 +3007,8 @@ static void do_inferred_modes(struct detailed_timing *timing, void *c) { struct detailed_mode_closure *closure = c; - struct detailed_non_pixel *data = &timing->data.other_data; - struct detailed_data_monitor_range *range = &data->data.range; + const struct detailed_non_pixel *data = &timing->data.other_data; + const struct detailed_data_monitor_range *range = &data->data.range;
if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE)) return; @@ -3057,11 +3057,11 @@ add_inferred_modes(struct drm_connector *connector, struct edid *edid) }
static int -drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing) +drm_est3_modes(struct drm_connector *connector, const struct detailed_timing *timing) { int i, j, m, modes = 0; struct drm_display_mode *mode; - u8 *est = ((u8 *)timing) + 6; + const u8 *est = ((const u8 *)timing) + 6;
for (i = 0; i < 6; i++) { for (j = 7; j >= 0; j--) { @@ -3140,7 +3140,7 @@ static void do_standard_modes(struct detailed_timing *timing, void *c) { struct detailed_mode_closure *closure = c; - struct detailed_non_pixel *data = &timing->data.other_data; + const struct detailed_non_pixel *data = &timing->data.other_data; struct drm_connector *connector = closure->connector; struct edid *edid = closure->edid; int i; @@ -3149,7 +3149,7 @@ do_standard_modes(struct detailed_timing *timing, void *c) return;
for (i = 0; i < 6; i++) { - struct std_timing *std = &data->data.timings[i]; + const struct std_timing *std = &data->data.timings[i]; struct drm_display_mode *newmode;
newmode = drm_mode_std(connector, edid, std); @@ -3198,12 +3198,12 @@ add_standard_modes(struct drm_connector *connector, struct edid *edid) }
static int drm_cvt_modes(struct drm_connector *connector, - struct detailed_timing *timing) + const struct detailed_timing *timing) { int i, j, modes = 0; struct drm_display_mode *newmode; struct drm_device *dev = connector->dev; - struct cvt_timing *cvt; + const struct cvt_timing *cvt; const int rates[] = { 60, 85, 75, 60, 50 }; const u8 empty[3] = { 0, 0, 0 };
Moving one level higher, constify struct detailed_timing pointers in callbacks.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com --- drivers/gpu/drm/drm_edid.c | 40 ++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 593f151c1155..c006b09066bb 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2346,7 +2346,7 @@ static bool is_detailed_timing_descriptor(const u8 d[18]) return d[0] != 0x00 || d[1] != 0x00; }
-typedef void detailed_cb(struct detailed_timing *timing, void *closure); +typedef void detailed_cb(const struct detailed_timing *timing, void *closure);
static void cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure) @@ -2405,7 +2405,7 @@ drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure) }
static void -is_rb(struct detailed_timing *timing, void *data) +is_rb(const struct detailed_timing *timing, void *data) { bool *res = data;
@@ -2433,9 +2433,9 @@ drm_monitor_supports_rb(struct edid *edid) }
static void -find_gtf2(struct detailed_timing *timing, void *data) +find_gtf2(const struct detailed_timing *timing, void *data) { - struct detailed_timing **res = data; + const struct detailed_timing **res = data;
if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_RANGE)) return; @@ -2450,7 +2450,7 @@ find_gtf2(struct detailed_timing *timing, void *data) static int drm_gtf2_hbreak(struct edid *edid) { - struct detailed_timing *timing = NULL; + const struct detailed_timing *timing = NULL;
drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing);
@@ -2462,7 +2462,7 @@ drm_gtf2_hbreak(struct edid *edid) static int drm_gtf2_2c(struct edid *edid) { - struct detailed_timing *timing = NULL; + const struct detailed_timing *timing = NULL;
drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing);
@@ -2474,7 +2474,7 @@ drm_gtf2_2c(struct edid *edid) static int drm_gtf2_m(struct edid *edid) { - struct detailed_timing *timing = NULL; + const struct detailed_timing *timing = NULL;
drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing);
@@ -2486,7 +2486,7 @@ drm_gtf2_m(struct edid *edid) static int drm_gtf2_k(struct edid *edid) { - struct detailed_timing *timing = NULL; + const struct detailed_timing *timing = NULL;
drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing);
@@ -2498,7 +2498,7 @@ drm_gtf2_k(struct edid *edid) static int drm_gtf2_2j(struct edid *edid) { - struct detailed_timing *timing = NULL; + const struct detailed_timing *timing = NULL;
drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing);
@@ -3004,7 +3004,7 @@ drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid, }
static void -do_inferred_modes(struct detailed_timing *timing, void *c) +do_inferred_modes(const struct detailed_timing *timing, void *c) { struct detailed_mode_closure *closure = c; const struct detailed_non_pixel *data = &timing->data.other_data; @@ -3086,7 +3086,7 @@ drm_est3_modes(struct drm_connector *connector, const struct detailed_timing *ti }
static void -do_established_modes(struct detailed_timing *timing, void *c) +do_established_modes(const struct detailed_timing *timing, void *c) { struct detailed_mode_closure *closure = c;
@@ -3137,7 +3137,7 @@ add_established_modes(struct drm_connector *connector, struct edid *edid) }
static void -do_standard_modes(struct detailed_timing *timing, void *c) +do_standard_modes(const struct detailed_timing *timing, void *c) { struct detailed_mode_closure *closure = c; const struct detailed_non_pixel *data = &timing->data.other_data; @@ -3250,7 +3250,7 @@ static int drm_cvt_modes(struct drm_connector *connector, }
static void -do_cvt_mode(struct detailed_timing *timing, void *c) +do_cvt_mode(const struct detailed_timing *timing, void *c) { struct detailed_mode_closure *closure = c;
@@ -3279,7 +3279,7 @@ add_cvt_modes(struct drm_connector *connector, struct edid *edid) static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
static void -do_detailed_mode(struct detailed_timing *timing, void *c) +do_detailed_mode(const struct detailed_timing *timing, void *c) { struct detailed_mode_closure *closure = c; struct drm_display_mode *newmode; @@ -4512,17 +4512,19 @@ drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db) }
static void -monitor_name(struct detailed_timing *t, void *data) +monitor_name(const struct detailed_timing *timing, void *data) { - if (!is_display_descriptor(t, EDID_DETAIL_MONITOR_NAME)) + const char **res = data; + + if (!is_display_descriptor(timing, EDID_DETAIL_MONITOR_NAME)) return;
- *(u8 **)data = t->data.other_data.data.str.str; + *res = timing->data.other_data.data.str.str; }
static int get_monitor_name(struct edid *edid, char name[13]) { - char *edid_name = NULL; + const char *edid_name = NULL; int mnl;
if (!edid || !name) @@ -5242,7 +5244,7 @@ static void drm_parse_cea_ext(struct drm_connector *connector, }
static -void get_monitor_range(struct detailed_timing *timing, +void get_monitor_range(const struct detailed_timing *timing, void *info_monitor_range) { struct drm_monitor_range_info *monitor_range = info_monitor_range;
Constify the first level of struct edid in detailed timing parsing. Also switch to struct edid instead of u8.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com --- drivers/gpu/drm/drm_edid.c | 48 ++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 25 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index c006b09066bb..fad792ef2c79 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2349,38 +2349,37 @@ static bool is_detailed_timing_descriptor(const u8 d[18]) typedef void detailed_cb(const struct detailed_timing *timing, void *closure);
static void -cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure) +cea_for_each_detailed_block(const u8 *ext, detailed_cb *cb, void *closure) { int i, n; u8 d = ext[0x02]; - u8 *det_base = ext + d; + const u8 *det_base = ext + d;
if (d < 4 || d > 127) return;
n = (127 - d) / 18; for (i = 0; i < n; i++) - cb((struct detailed_timing *)(det_base + 18 * i), closure); + cb((const struct detailed_timing *)(det_base + 18 * i), closure); }
static void -vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure) +vtb_for_each_detailed_block(const u8 *ext, detailed_cb *cb, void *closure) { unsigned int i, n = min((int)ext[0x02], 6); - u8 *det_base = ext + 5; + const u8 *det_base = ext + 5;
if (ext[0x01] != 1) return; /* unknown version */
for (i = 0; i < n; i++) - cb((struct detailed_timing *)(det_base + 18 * i), closure); + cb((const struct detailed_timing *)(det_base + 18 * i), closure); }
static void -drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure) +drm_for_each_detailed_block(const struct edid *edid, detailed_cb *cb, void *closure) { int i; - struct edid *edid = (struct edid *)raw_edid;
if (edid == NULL) return; @@ -2388,8 +2387,8 @@ drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure) for (i = 0; i < EDID_DETAILED_TIMINGS; i++) cb(&(edid->detailed_timings[i]), closure);
- for (i = 1; i <= raw_edid[0x7e]; i++) { - u8 *ext = raw_edid + (i * EDID_LENGTH); + for (i = 1; i <= edid->extensions; i++) { + const u8 *ext = (const u8 *)edid + (i * EDID_LENGTH);
switch (*ext) { case CEA_EXT: @@ -2425,7 +2424,7 @@ drm_monitor_supports_rb(struct edid *edid) if (edid->revision >= 4) { bool ret = false;
- drm_for_each_detailed_block((u8 *)edid, is_rb, &ret); + drm_for_each_detailed_block(edid, is_rb, &ret); return ret; }
@@ -2452,7 +2451,7 @@ drm_gtf2_hbreak(struct edid *edid) { const struct detailed_timing *timing = NULL;
- drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing); + drm_for_each_detailed_block(edid, find_gtf2, &timing);
BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.gtf2.hfreq_start_khz) != 12);
@@ -2464,7 +2463,7 @@ drm_gtf2_2c(struct edid *edid) { const struct detailed_timing *timing = NULL;
- drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing); + drm_for_each_detailed_block(edid, find_gtf2, &timing);
BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.gtf2.c) != 13);
@@ -2476,7 +2475,7 @@ drm_gtf2_m(struct edid *edid) { const struct detailed_timing *timing = NULL;
- drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing); + drm_for_each_detailed_block(edid, find_gtf2, &timing);
BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.gtf2.m) != 14);
@@ -2488,7 +2487,7 @@ drm_gtf2_k(struct edid *edid) { const struct detailed_timing *timing = NULL;
- drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing); + drm_for_each_detailed_block(edid, find_gtf2, &timing);
BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.gtf2.k) != 16);
@@ -2500,7 +2499,7 @@ drm_gtf2_2j(struct edid *edid) { const struct detailed_timing *timing = NULL;
- drm_for_each_detailed_block((u8 *)edid, find_gtf2, &timing); + drm_for_each_detailed_block(edid, find_gtf2, &timing);
BUILD_BUG_ON(offsetof(typeof(*timing), data.other_data.data.range.formula.gtf2.j) != 17);
@@ -3050,8 +3049,7 @@ add_inferred_modes(struct drm_connector *connector, struct edid *edid) };
if (version_greater(edid, 1, 0)) - drm_for_each_detailed_block((u8 *)edid, do_inferred_modes, - &closure); + drm_for_each_detailed_block(edid, do_inferred_modes, &closure);
return closure.modes; } @@ -3130,8 +3128,8 @@ add_established_modes(struct drm_connector *connector, struct edid *edid) }
if (version_greater(edid, 1, 0)) - drm_for_each_detailed_block((u8 *)edid, - do_established_modes, &closure); + drm_for_each_detailed_block(edid, do_established_modes, + &closure);
return modes + closure.modes; } @@ -3189,7 +3187,7 @@ add_standard_modes(struct drm_connector *connector, struct edid *edid) }
if (version_greater(edid, 1, 0)) - drm_for_each_detailed_block((u8 *)edid, do_standard_modes, + drm_for_each_detailed_block(edid, do_standard_modes, &closure);
/* XXX should also look for standard codes in VTB blocks */ @@ -3269,7 +3267,7 @@ add_cvt_modes(struct drm_connector *connector, struct edid *edid) };
if (version_greater(edid, 1, 2)) - drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure); + drm_for_each_detailed_block(edid, do_cvt_mode, &closure);
/* XXX should also look for CVT codes in VTB blocks */
@@ -3329,7 +3327,7 @@ add_detailed_modes(struct drm_connector *connector, struct edid *edid, closure.preferred = (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
- drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure); + drm_for_each_detailed_block(edid, do_detailed_mode, &closure);
return closure.modes; } @@ -4530,7 +4528,7 @@ static int get_monitor_name(struct edid *edid, char name[13]) if (!edid || !name) return 0;
- drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name); + drm_for_each_detailed_block(edid, monitor_name, &edid_name); for (mnl = 0; edid_name && mnl < 13; mnl++) { if (edid_name[mnl] == 0x0a) break; @@ -5276,7 +5274,7 @@ void drm_get_monitor_range(struct drm_connector *connector, if (!version_greater(edid, 1, 1)) return;
- drm_for_each_detailed_block((u8 *)edid, get_monitor_range, + drm_for_each_detailed_block(edid, get_monitor_range, &info->monitor_range);
DRM_DEBUG_KMS("Supported Monitor Refresh rate range is %d Hz - %d Hz\n",
Finalize detailed timing parsing constness by making struct edid also const in callbacks and closure.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com --- drivers/gpu/drm/drm_edid.c | 48 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index fad792ef2c79..fae6f39897c8 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -97,7 +97,7 @@ static int oui(u8 first, u8 second, u8 third)
struct detailed_mode_closure { struct drm_connector *connector; - struct edid *edid; + const struct edid *edid; bool preferred; u32 quirks; int modes; @@ -2419,7 +2419,7 @@ is_rb(const struct detailed_timing *timing, void *data)
/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */ static bool -drm_monitor_supports_rb(struct edid *edid) +drm_monitor_supports_rb(const struct edid *edid) { if (edid->revision >= 4) { bool ret = false; @@ -2447,7 +2447,7 @@ find_gtf2(const struct detailed_timing *timing, void *data)
/* Secondary GTF curve kicks in above some break frequency */ static int -drm_gtf2_hbreak(struct edid *edid) +drm_gtf2_hbreak(const struct edid *edid) { const struct detailed_timing *timing = NULL;
@@ -2459,7 +2459,7 @@ drm_gtf2_hbreak(struct edid *edid) }
static int -drm_gtf2_2c(struct edid *edid) +drm_gtf2_2c(const struct edid *edid) { const struct detailed_timing *timing = NULL;
@@ -2471,7 +2471,7 @@ drm_gtf2_2c(struct edid *edid) }
static int -drm_gtf2_m(struct edid *edid) +drm_gtf2_m(const struct edid *edid) { const struct detailed_timing *timing = NULL;
@@ -2483,7 +2483,7 @@ drm_gtf2_m(struct edid *edid) }
static int -drm_gtf2_k(struct edid *edid) +drm_gtf2_k(const struct edid *edid) { const struct detailed_timing *timing = NULL;
@@ -2495,7 +2495,7 @@ drm_gtf2_k(struct edid *edid) }
static int -drm_gtf2_2j(struct edid *edid) +drm_gtf2_2j(const struct edid *edid) { const struct detailed_timing *timing = NULL;
@@ -2510,7 +2510,7 @@ drm_gtf2_2j(struct edid *edid) * standard_timing_level - get std. timing level(CVT/GTF/DMT) * @edid: EDID block to scan */ -static int standard_timing_level(struct edid *edid) +static int standard_timing_level(const struct edid *edid) { if (edid->revision >= 2) { if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)) @@ -2553,7 +2553,7 @@ static int drm_mode_hsync(const struct drm_display_mode *mode) * and convert them into a real mode using CVT/GTF/DMT. */ static struct drm_display_mode * -drm_mode_std(struct drm_connector *connector, struct edid *edid, +drm_mode_std(struct drm_connector *connector, const struct edid *edid, const struct std_timing *t) { struct drm_device *dev = connector->dev; @@ -2715,7 +2715,7 @@ drm_mode_do_interlace_quirk(struct drm_display_mode *mode, * return a new struct drm_display_mode. */ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, - struct edid *edid, + const struct edid *edid, const struct detailed_timing *timing, u32 quirks) { @@ -2815,7 +2815,7 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
static bool mode_in_hsync_range(const struct drm_display_mode *mode, - struct edid *edid, const u8 *t) + const struct edid *edid, const u8 *t) { int hsync, hmin, hmax;
@@ -2832,7 +2832,7 @@ mode_in_hsync_range(const struct drm_display_mode *mode,
static bool mode_in_vsync_range(const struct drm_display_mode *mode, - struct edid *edid, const u8 *t) + const struct edid *edid, const u8 *t) { int vsync, vmin, vmax;
@@ -2848,7 +2848,7 @@ mode_in_vsync_range(const struct drm_display_mode *mode, }
static u32 -range_pixel_clock(struct edid *edid, const u8 *t) +range_pixel_clock(const struct edid *edid, const u8 *t) { /* unspecified */ if (t[9] == 0 || t[9] == 255) @@ -2863,7 +2863,7 @@ range_pixel_clock(struct edid *edid, const u8 *t) }
static bool -mode_in_range(const struct drm_display_mode *mode, struct edid *edid, +mode_in_range(const struct drm_display_mode *mode, const struct edid *edid, const struct detailed_timing *timing) { u32 max_clock; @@ -2909,7 +2909,7 @@ static bool valid_inferred_mode(const struct drm_connector *connector, }
static int -drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid, +drm_dmt_modes_for_range(struct drm_connector *connector, const struct edid *edid, const struct detailed_timing *timing) { int i, modes = 0; @@ -2944,7 +2944,7 @@ void drm_mode_fixup_1366x768(struct drm_display_mode *mode) }
static int -drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid, +drm_gtf_modes_for_range(struct drm_connector *connector, const struct edid *edid, const struct detailed_timing *timing) { int i, modes = 0; @@ -2973,7 +2973,7 @@ drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid, }
static int -drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid, +drm_cvt_modes_for_range(struct drm_connector *connector, const struct edid *edid, const struct detailed_timing *timing) { int i, modes = 0; @@ -3041,7 +3041,7 @@ do_inferred_modes(const struct detailed_timing *timing, void *c) }
static int -add_inferred_modes(struct drm_connector *connector, struct edid *edid) +add_inferred_modes(struct drm_connector *connector, const struct edid *edid) { struct detailed_mode_closure closure = { .connector = connector, @@ -3103,7 +3103,7 @@ do_established_modes(const struct detailed_timing *timing, void *c) * (defined above). Tease them out and add them to the global modes list. */ static int -add_established_modes(struct drm_connector *connector, struct edid *edid) +add_established_modes(struct drm_connector *connector, const struct edid *edid) { struct drm_device *dev = connector->dev; unsigned long est_bits = edid->established_timings.t1 | @@ -3140,7 +3140,7 @@ do_standard_modes(const struct detailed_timing *timing, void *c) struct detailed_mode_closure *closure = c; const struct detailed_non_pixel *data = &timing->data.other_data; struct drm_connector *connector = closure->connector; - struct edid *edid = closure->edid; + const struct edid *edid = closure->edid; int i;
if (!is_display_descriptor(timing, EDID_DETAIL_STD_MODES)) @@ -3167,7 +3167,7 @@ do_standard_modes(const struct detailed_timing *timing, void *c) * GTF or CVT. Grab them from @edid and add them to the list. */ static int -add_standard_modes(struct drm_connector *connector, struct edid *edid) +add_standard_modes(struct drm_connector *connector, const struct edid *edid) { int i, modes = 0; struct detailed_mode_closure closure = { @@ -3259,7 +3259,7 @@ do_cvt_mode(const struct detailed_timing *timing, void *c) }
static int -add_cvt_modes(struct drm_connector *connector, struct edid *edid) +add_cvt_modes(struct drm_connector *connector, const struct edid *edid) { struct detailed_mode_closure closure = { .connector = connector, @@ -3313,7 +3313,7 @@ do_detailed_mode(const struct detailed_timing *timing, void *c) * @quirks: quirks to apply */ static int -add_detailed_modes(struct drm_connector *connector, struct edid *edid, +add_detailed_modes(struct drm_connector *connector, const struct edid *edid, u32 quirks) { struct detailed_mode_closure closure = { @@ -4520,7 +4520,7 @@ monitor_name(const struct detailed_timing *timing, void *data) *res = timing->data.other_data.data.str.str; }
-static int get_monitor_name(struct edid *edid, char name[13]) +static int get_monitor_name(const struct edid *edid, char name[13]) { const char *edid_name = NULL; int mnl;
With this, the remaining non-const parts are the ones that actually modify the EDID, for example to fix corrupt EDID.
Cc: Ville Syrjälä ville.syrjala@linux.intel.com Signed-off-by: Jani Nikula jani.nikula@intel.com --- drivers/gpu/drm/drm_edid.c | 21 +++++++++++---------- include/drm/drm_edid.h | 10 +++++----- 2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index fae6f39897c8..a069c2ddb09d 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2150,7 +2150,7 @@ static u32 edid_extract_panel_id(const struct edid *edid)
u32 drm_edid_get_panel_id(struct i2c_adapter *adapter) { - struct edid *edid; + const struct edid *edid; u32 panel_id;
edid = drm_do_get_edid_base_block(NULL, drm_do_probe_ddc_edid, adapter); @@ -3659,7 +3659,7 @@ static bool drm_valid_hdmi_vic(u8 vic) }
static int -add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid) +add_alternate_cea_modes(struct drm_connector *connector, const struct edid *edid) { struct drm_device *dev = connector->dev; struct drm_display_mode *mode, *tmp; @@ -4340,7 +4340,7 @@ static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector, }
static int -add_cea_modes(struct drm_connector *connector, struct edid *edid) +add_cea_modes(struct drm_connector *connector, const struct edid *edid) { const u8 *cea = drm_find_cea_extension(edid); const u8 *db, *hdmi = NULL, *video = NULL; @@ -4546,7 +4546,7 @@ static int get_monitor_name(const struct edid *edid, char name[13]) * @bufsize: The size of the name buffer (should be at least 14 chars.) * */ -void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize) +void drm_edid_get_monitor_name(const struct edid *edid, char *name, int bufsize) { int name_length; char buf[13]; @@ -4580,7 +4580,8 @@ static void clear_eld(struct drm_connector *connector) * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The * HDCP and Port_ID ELD fields are left for the graphics driver to fill in. */ -static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) +static void drm_edid_to_eld(struct drm_connector *connector, + const struct edid *edid) { uint8_t *eld = connector->eld; const u8 *cea; @@ -4676,7 +4677,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) * * Return: The number of found SADs or negative number on error. */ -int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads) +int drm_edid_to_sad(const struct edid *edid, struct cea_sad **sads) { int count = 0; int i, start, end, dbl; @@ -4738,7 +4739,7 @@ EXPORT_SYMBOL(drm_edid_to_sad); * Return: The number of found Speaker Allocation Blocks or negative number on * error. */ -int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb) +int drm_edid_to_speaker_allocation(const struct edid *edid, u8 **sadb) { int count = 0; int i, start, end, dbl; @@ -4833,7 +4834,7 @@ EXPORT_SYMBOL(drm_av_sync_delay); * * Return: True if the monitor is HDMI, false if not or unknown. */ -bool drm_detect_hdmi_monitor(struct edid *edid) +bool drm_detect_hdmi_monitor(const struct edid *edid) { const u8 *edid_ext; int i; @@ -4871,7 +4872,7 @@ EXPORT_SYMBOL(drm_detect_hdmi_monitor); * * Return: True if the monitor supports audio, false otherwise. */ -bool drm_detect_monitor_audio(struct edid *edid) +bool drm_detect_monitor_audio(const struct edid *edid) { const u8 *edid_ext; int i, j; @@ -5538,7 +5539,7 @@ static int add_displayid_detailed_1_modes(struct drm_connector *connector, }
static int add_displayid_detailed_modes(struct drm_connector *connector, - struct edid *edid) + const struct edid *edid) { const struct displayid_block *block; struct displayid_iter iter; diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 144c495b99c4..48b1bf9c315a 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -372,8 +372,8 @@ struct drm_connector; struct drm_connector_state; struct drm_display_mode;
-int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads); -int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb); +int drm_edid_to_sad(const struct edid *edid, struct cea_sad **sads); +int drm_edid_to_speaker_allocation(const struct edid *edid, u8 **sadb); int drm_av_sync_delay(struct drm_connector *connector, const struct drm_display_mode *mode);
@@ -569,8 +569,8 @@ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid); int drm_add_override_edid_modes(struct drm_connector *connector);
u8 drm_match_cea_mode(const struct drm_display_mode *to_match); -bool drm_detect_hdmi_monitor(struct edid *edid); -bool drm_detect_monitor_audio(struct edid *edid); +bool drm_detect_hdmi_monitor(const struct edid *edid); +bool drm_detect_monitor_audio(const struct edid *edid); enum hdmi_quantization_range drm_default_rgb_quant_range(const struct drm_display_mode *mode); int drm_add_modes_noedid(struct drm_connector *connector, @@ -582,7 +582,7 @@ int drm_edid_header_is_valid(const u8 *raw_edid); bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, bool *edid_corrupt); bool drm_edid_is_valid(struct edid *edid); -void drm_edid_get_monitor_name(struct edid *edid, char *name, +void drm_edid_get_monitor_name(const struct edid *edid, char *name, int buflen); struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, int hsize, int vsize, int fresh,
dri-devel@lists.freedesktop.org