All those functions only scan a predefined EDID block and have no need to alter anything. Constify the passed in struct edid pointer to reflect this in the interface.
Signed-off-by: Lucas Stach dev@lynxeye.de --- drivers/gpu/drm/drm_edid.c | 73 ++++++++++++++++++++++++---------------------- include/drm/drm_crtc.h | 10 +++---- include/drm/drm_edid.h | 2 +- 3 files changed, 44 insertions(+), 41 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 5a3770f..9564e15 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -71,7 +71,7 @@
struct detailed_mode_closure { struct drm_connector *connector; - struct edid *edid; + const struct edid *edid; bool preferred; u32 quirks; int modes; @@ -227,7 +227,7 @@ EXPORT_SYMBOL(drm_edid_block_valid); * * Sanity-check an entire EDID record (including extensions) */ -bool drm_edid_is_valid(struct edid *edid) +bool drm_edid_is_valid(const struct edid *edid) { int i; u8 *raw = (u8 *)edid; @@ -432,7 +432,7 @@ EXPORT_SYMBOL(drm_get_edid); * * Returns true if @vendor is in @edid, false otherwise */ -static bool edid_vendor(struct edid *edid, char *vendor) +static bool edid_vendor(const struct edid *edid, char *vendor) { char edid_vendor[3];
@@ -450,7 +450,7 @@ static bool edid_vendor(struct edid *edid, char *vendor) * * This tells subsequent routines what fixes they need to apply. */ -static u32 edid_get_quirks(struct edid *edid) +static u32 edid_get_quirks(const struct edid *edid) { struct edid_quirk *quirk; int i; @@ -624,7 +624,7 @@ is_rb(struct detailed_timing *t, 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; @@ -645,7 +645,7 @@ find_gtf2(struct detailed_timing *t, 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) { u8 *r = NULL; drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); @@ -653,7 +653,7 @@ drm_gtf2_hbreak(struct edid *edid) }
static int -drm_gtf2_2c(struct edid *edid) +drm_gtf2_2c(const struct edid *edid) { u8 *r = NULL; drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); @@ -661,7 +661,7 @@ drm_gtf2_2c(struct edid *edid) }
static int -drm_gtf2_m(struct edid *edid) +drm_gtf2_m(const struct edid *edid) { u8 *r = NULL; drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); @@ -669,7 +669,7 @@ drm_gtf2_m(struct edid *edid) }
static int -drm_gtf2_k(struct edid *edid) +drm_gtf2_k(const struct edid *edid) { u8 *r = NULL; drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); @@ -677,7 +677,7 @@ drm_gtf2_k(struct edid *edid) }
static int -drm_gtf2_2j(struct edid *edid) +drm_gtf2_2j(const struct edid *edid) { u8 *r = NULL; drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); @@ -688,7 +688,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)) @@ -705,7 +705,7 @@ static int standard_timing_level(struct edid *edid) * monitors fill with ascii space (0x20) instead. */ static int -bad_std_timing(u8 a, u8 b) +bad_std_timing(const u8 a, const u8 b) { return (a == 0x00 && b == 0x00) || (a == 0x01 && b == 0x01) || @@ -721,8 +721,8 @@ bad_std_timing(u8 a, u8 b) * 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, - struct std_timing *t, int revision) +drm_mode_std(struct drm_connector *connector, const struct edid *edid, + const struct std_timing *t, int revision) { struct drm_device *dev = connector->dev; struct drm_display_mode *m, *mode = NULL; @@ -881,7 +881,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, struct detailed_timing *timing, u32 quirks) { @@ -981,7 +981,7 @@ set_size:
static bool mode_in_hsync_range(const struct drm_display_mode *mode, - struct edid *edid, u8 *t) + const struct edid *edid, u8 *t) { int hsync, hmin, hmax;
@@ -998,7 +998,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) + const struct edid *edid, u8 *t) { int vsync, vmin, vmax;
@@ -1014,7 +1014,7 @@ mode_in_vsync_range(const struct drm_display_mode *mode, }
static u32 -range_pixel_clock(struct edid *edid, u8 *t) +range_pixel_clock(const struct edid *edid, u8 *t) { /* unspecified */ if (t[9] == 0 || t[9] == 255) @@ -1029,7 +1029,7 @@ range_pixel_clock(struct edid *edid, 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, struct detailed_timing *timing) { u32 max_clock; @@ -1075,7 +1075,8 @@ 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, struct detailed_timing *timing) { int i, modes = 0; @@ -1110,7 +1111,8 @@ static void fixup_mode_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, struct detailed_timing *timing) { int i, modes = 0; @@ -1138,7 +1140,8 @@ 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, struct detailed_timing *timing) { int i, modes = 0; @@ -1205,7 +1208,7 @@ do_inferred_modes(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, edid, 0, 0, 0 @@ -1265,7 +1268,7 @@ do_established_modes(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 | @@ -1300,7 +1303,7 @@ do_standard_modes(struct detailed_timing *timing, void *c) struct detailed_mode_closure *closure = c; 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;
if (data->type == EDID_DETAIL_STD_MODES) { int i; @@ -1327,7 +1330,7 @@ do_standard_modes(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 = { @@ -1415,7 +1418,7 @@ do_cvt_mode(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, edid, 0, 0, 0 @@ -1458,7 +1461,7 @@ do_detailed_mode(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 = { @@ -1490,7 +1493,7 @@ add_detailed_modes(struct drm_connector *connector, struct edid *edid, /** * Search EDID for CEA extension block. */ -u8 *drm_find_cea_extension(struct edid *edid) +u8 *drm_find_cea_extension(const struct edid *edid) { u8 *edid_ext = NULL; int i; @@ -1591,7 +1594,7 @@ cea_db_offsets(const u8 *cea, int *start, int *end) for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
static int -add_cea_modes(struct drm_connector *connector, struct edid *edid) +add_cea_modes(struct drm_connector *connector, const struct edid *edid) { u8 * cea = drm_find_cea_extension(edid); u8 * db, dbl; @@ -1687,7 +1690,7 @@ static bool cea_db_is_hdmi_vsdb(const u8 *db) * - HDCP * - Port_ID */ -void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) +void drm_edid_to_eld(struct drm_connector *connector, const struct edid *edid) { uint8_t *eld = connector->eld; u8 *cea; @@ -1830,7 +1833,7 @@ EXPORT_SYMBOL(drm_select_eld); * Parse the CEA extension according to CEA-861-B. * Return true if HDMI, false if not or unknown. */ -bool drm_detect_hdmi_monitor(struct edid *edid) +bool drm_detect_hdmi_monitor(const struct edid *edid) { u8 *edid_ext; int i; @@ -1866,7 +1869,7 @@ EXPORT_SYMBOL(drm_detect_hdmi_monitor); * audio' is not defined in EDID. * */ -bool drm_detect_monitor_audio(struct edid *edid) +bool drm_detect_monitor_audio(const struct edid *edid) { u8 *edid_ext; int i, j; @@ -1910,7 +1913,7 @@ EXPORT_SYMBOL(drm_detect_monitor_audio); * structure that's part of the connector. Useful for tracking bpp and * color spaces. */ -static void drm_add_display_info(struct edid *edid, +static void drm_add_display_info(const struct edid *edid, struct drm_display_info *info) { u8 *edid_ext; @@ -1986,7 +1989,7 @@ static void drm_add_display_info(struct edid *edid, * * Return number of modes added or 0 if we couldn't find any. */ -int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid) +int drm_add_edid_modes(struct drm_connector *connector, const struct edid *edid) { int num_modes = 0; u32 quirks; diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 00d78b5..9b2198b 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -882,7 +882,7 @@ extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_m extern bool drm_probe_ddc(struct i2c_adapter *adapter); extern struct edid *drm_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter); -extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid); +extern int drm_add_edid_modes(struct drm_connector *connector, const struct edid *edid); extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode); extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode); extern void drm_mode_copy(struct drm_display_mode *dst, const struct drm_display_mode *src); @@ -1029,10 +1029,10 @@ extern int drm_mode_gamma_get_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); extern int drm_mode_gamma_set_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); -extern u8 *drm_find_cea_extension(struct edid *edid); +extern u8 *drm_find_cea_extension(const struct edid *edid); extern u8 drm_match_cea_mode(struct drm_display_mode *to_match); -extern bool drm_detect_hdmi_monitor(struct edid *edid); -extern bool drm_detect_monitor_audio(struct edid *edid); +extern bool drm_detect_hdmi_monitor(const struct edid *edid); +extern bool drm_detect_monitor_audio(const struct edid *edid); extern int drm_mode_page_flip_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, @@ -1051,7 +1051,7 @@ extern uint8_t drm_mode_cea_vic(const struct drm_display_mode *mode);
extern int drm_edid_header_is_valid(const u8 *raw_edid); extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid); -extern bool drm_edid_is_valid(struct edid *edid); +extern bool drm_edid_is_valid(const struct edid *edid); struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, int hsize, int vsize, int fresh, bool rb); diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 0cac551..464ae2b 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -247,7 +247,7 @@ struct edid { struct drm_encoder; struct drm_connector; struct drm_display_mode; -void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid); +void drm_edid_to_eld(struct drm_connector *connector, const struct edid *edid); int drm_av_sync_delay(struct drm_connector *connector, struct drm_display_mode *mode); struct drm_connector *drm_select_eld(struct drm_encoder *encoder,
Check if sink is HDMI capable when enabling an output. This disables HDMI audio/infoframes if we are talking to a plain DVI sink. All things except this check are already in place.
Signed-off-by: Lucas Stach dev@lynxeye.de --- drivers/gpu/drm/tegra/hdmi.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c index e060c7e..3405313 100644 --- a/drivers/gpu/drm/tegra/hdmi.c +++ b/drivers/gpu/drm/tegra/hdmi.c @@ -660,6 +660,9 @@ static int tegra_output_hdmi_enable(struct tegra_output *output) usleep_range(1000, 2000); tegra_periph_reset_deassert(hdmi->clk);
+ /* if the connected sink is not HDMI capable fall back to plain DVI */ + hdmi->dvi = !drm_detect_hdmi_monitor(output->edid); + tegra_dc_writel(dc, VSYNC_H_POSITION(1), DC_DISP_DISP_TIMING_OPTIONS); tegra_dc_writel(dc, DITHER_CONTROL_DISABLE | BASE_COLOR_SIZE888,
On Wed, Jan 16, 2013 at 03:36:42PM +0100, Lucas Stach wrote:
Check if sink is HDMI capable when enabling an output. This disables HDMI audio/infoframes if we are talking to a plain DVI sink. All things except this check are already in place.
Signed-off-by: Lucas Stach dev@lynxeye.de
drivers/gpu/drm/tegra/hdmi.c | 3 +++ 1 file changed, 3 insertions(+)
Reviewed-by: Thierry Reding thierry.reding@avionic-design.de
On Wed, Jan 16, 2013 at 7:24 AM, Thierry Reding thierry.reding@avionic-design.de wrote:
On Wed, Jan 16, 2013 at 03:36:42PM +0100, Lucas Stach wrote:
Check if sink is HDMI capable when enabling an output. This disables HDMI audio/infoframes if we are talking to a plain DVI sink. All things except this check are already in place.
Signed-off-by: Lucas Stach dev@lynxeye.de
drivers/gpu/drm/tegra/hdmi.c | 3 +++ 1 file changed, 3 insertions(+)
Reviewed-by: Thierry Reding thierry.reding@avionic-design.de
Reviewed-by: Jon Mayo jmayo@nvidia.com
On Wed, Jan 16, 2013 at 03:36:41PM +0100, Lucas Stach wrote: [...]
@@ -705,7 +705,7 @@ static int standard_timing_level(struct edid *edid)
- monitors fill with ascii space (0x20) instead.
*/ static int -bad_std_timing(u8 a, u8 b) +bad_std_timing(const u8 a, const u8 b) { return (a == 0x00 && b == 0x00) || (a == 0x01 && b == 0x01) ||
Was this intended to go in here?
@@ -721,8 +721,8 @@ bad_std_timing(u8 a, u8 b)
- 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,
struct std_timing *t, int revision)
+drm_mode_std(struct drm_connector *connector, const struct edid *edid,
const struct std_timing *t, int revision)
{ struct drm_device *dev = connector->dev; struct drm_display_mode *m, *mode = NULL;
I know I'm being picky, but you're constifying the t parameter here as well without saying so in the commit message.
Thierry
Am Mittwoch, den 16.01.2013, 16:23 +0100 schrieb Thierry Reding:
On Wed, Jan 16, 2013 at 03:36:41PM +0100, Lucas Stach wrote: [...]
@@ -705,7 +705,7 @@ static int standard_timing_level(struct edid *edid)
- monitors fill with ascii space (0x20) instead.
*/ static int -bad_std_timing(u8 a, u8 b) +bad_std_timing(const u8 a, const u8 b) { return (a == 0x00 && b == 0x00) || (a == 0x01 && b == 0x01) ||
Was this intended to go in here?
@@ -721,8 +721,8 @@ bad_std_timing(u8 a, u8 b)
- 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,
struct std_timing *t, int revision)
+drm_mode_std(struct drm_connector *connector, const struct edid *edid,
const struct std_timing *t, int revision)
{ struct drm_device *dev = connector->dev; struct drm_display_mode *m, *mode = NULL;
I know I'm being picky, but you're constifying the t parameter here as well without saying so in the commit message.
Yes, probably I should have been a bit more elaborate in the commit message. Both hunks are intentional, as I looked at how those functions in the environment of the edid handling funcs are used and added const where appropriate, not just strictly to the struct edid pointer.
Regards, Lucas
On Wed, 16 Jan 2013, Lucas Stach dev@lynxeye.de wrote:
Am Mittwoch, den 16.01.2013, 16:23 +0100 schrieb Thierry Reding:
On Wed, Jan 16, 2013 at 03:36:41PM +0100, Lucas Stach wrote: [...]
@@ -705,7 +705,7 @@ static int standard_timing_level(struct edid *edid)
- monitors fill with ascii space (0x20) instead.
*/ static int -bad_std_timing(u8 a, u8 b) +bad_std_timing(const u8 a, const u8 b) { return (a == 0x00 && b == 0x00) || (a == 0x01 && b == 0x01) ||
Was this intended to go in here?
[...]
Yes, probably I should have been a bit more elaborate in the commit message. Both hunks are intentional, as I looked at how those functions in the environment of the edid handling funcs are used and added const where appropriate, not just strictly to the struct edid pointer.
Please, let's not start constifying non-pointer parameters and local variables.
BR, Jani.
On Wed, Jan 16, 2013 at 07:04:22PM +0200, Jani Nikula wrote:
On Wed, 16 Jan 2013, Lucas Stach dev@lynxeye.de wrote:
Am Mittwoch, den 16.01.2013, 16:23 +0100 schrieb Thierry Reding:
On Wed, Jan 16, 2013 at 03:36:41PM +0100, Lucas Stach wrote: [...]
@@ -705,7 +705,7 @@ static int standard_timing_level(struct edid *edid)
- monitors fill with ascii space (0x20) instead.
*/ static int -bad_std_timing(u8 a, u8 b) +bad_std_timing(const u8 a, const u8 b) { return (a == 0x00 && b == 0x00) || (a == 0x01 && b == 0x01) ||
Was this intended to go in here?
[...]
Yes, probably I should have been a bit more elaborate in the commit message. Both hunks are intentional, as I looked at how those functions in the environment of the edid handling funcs are used and added const where appropriate, not just strictly to the struct edid pointer.
Please, let's not start constifying non-pointer parameters and local variables.
I agree. I don't think there's any advantage in making a and b const.
Thierry
On Wed, Jan 16, 2013 at 03:36:41PM +0100, Lucas Stach wrote:
All those functions only scan a predefined EDID block and have no need to alter anything. Constify the passed in struct edid pointer to reflect this in the interface.
Signed-off-by: Lucas Stach dev@lynxeye.de
drivers/gpu/drm/drm_edid.c | 73 ++++++++++++++++++++++++---------------------- include/drm/drm_crtc.h | 10 +++---- include/drm/drm_edid.h | 2 +- 3 files changed, 44 insertions(+), 41 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 5a3770f..9564e15 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -71,7 +71,7 @@
struct detailed_mode_closure { struct drm_connector *connector;
- struct edid *edid;
- const struct edid *edid; bool preferred; u32 quirks; int modes;
@@ -227,7 +227,7 @@ EXPORT_SYMBOL(drm_edid_block_valid);
- Sanity-check an entire EDID record (including extensions)
*/ -bool drm_edid_is_valid(struct edid *edid) +bool drm_edid_is_valid(const struct edid *edid)
This isn't quite right. This guy calls drm_edid_block_is_valid() which can modify the EDID. Unfortunately the casts hide the problem, and you don't get a warning :( I didn't check if that modification could be elimnated.
Also there's a lot more in drm_edid.c that could be const. I've included a very quick patch (on top of yours) which undoes a few of the consts you added, and adds a bunch more. If I compile it w/ -Wcast-qual, the only warnings I get are from the list.h macros, so it would seem to be mostly OK.
I had to change the way EDID_QUIRK_135_CLOCK_TOO_HIGH and EDID_QUIRK_DETAILED_SYNC_PP are applied. Previously they would modify the EDID itself, but I just made them modify the mode directly. Since user space can see the raw EDID, this will affect user space too. So perhaps some other solution would be needed. Possibly the quirks could be applied in a separate step before the EDID is otherwise parsed.
From 8ffe8d0fa8d2bed71adb372f14d5bf34e6687947 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= ville.syrjala@linux.intel.com Date: Wed, 16 Jan 2013 17:56:02 +0200 Subject: [PATCH] constify a lot more
--- drivers/gpu/drm/drm_edid.c | 182 ++++++++++++++++++++++---------------------- include/drm/drm_crtc.h | 8 +- include/drm/drm_edid.h | 4 +- 3 files changed, 98 insertions(+), 96 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 9564e15..902800c 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -227,7 +227,7 @@ EXPORT_SYMBOL(drm_edid_block_valid); * * Sanity-check an entire EDID record (including extensions) */ -bool drm_edid_is_valid(const struct edid *edid) +bool drm_edid_is_valid(struct edid *edid) { int i; u8 *raw = (u8 *)edid; @@ -559,38 +559,38 @@ struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, } EXPORT_SYMBOL(drm_mode_find_dmt);
-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) +cea_for_each_detailed_block(const u8 *ext, detailed_cb *cb, void *closure) { int i, n = 0; u8 d = ext[0x02]; - u8 *det_base = ext + d; + const u8 *det_base = ext + d;
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 u8 *raw_edid, detailed_cb *cb, void *closure) { int i; - struct edid *edid = (struct edid *)raw_edid; + const struct edid *edid = (const struct edid *)raw_edid;
if (edid == NULL) return; @@ -599,7 +599,7 @@ drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure) cb(&(edid->detailed_timings[i]), closure);
for (i = 1; i <= raw_edid[0x7e]; i++) { - u8 *ext = raw_edid + (i * EDID_LENGTH); + const u8 *ext = raw_edid + (i * EDID_LENGTH); switch (*ext) { case CEA_EXT: cea_for_each_detailed_block(ext, cb, closure); @@ -614,9 +614,9 @@ 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(const struct detailed_timing *t, void *data) { - u8 *r = (u8 *)t; + const u8 *r = (const u8 *)t; if (r[3] == EDID_DETAIL_MONITOR_RANGE) if (r[15] & 0x10) *(bool *)data = true; @@ -628,7 +628,7 @@ drm_monitor_supports_rb(const 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((const u8 *)edid, is_rb, &ret); return ret; }
@@ -636,51 +636,51 @@ drm_monitor_supports_rb(const struct edid *edid) }
static void -find_gtf2(struct detailed_timing *t, void *data) +find_gtf2(const struct detailed_timing *t, void *data) { - u8 *r = (u8 *)t; + const u8 *r = (const u8 *)t; if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02) - *(u8 **)data = r; + *(const u8 **)data = r; }
/* Secondary GTF curve kicks in above some break frequency */ static int drm_gtf2_hbreak(const struct edid *edid) { - u8 *r = NULL; - drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); + const u8 *r = NULL; + drm_for_each_detailed_block((const u8 *)edid, find_gtf2, &r); return r ? (r[12] * 2) : 0; }
static int drm_gtf2_2c(const struct edid *edid) { - u8 *r = NULL; - drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); + const u8 *r = NULL; + drm_for_each_detailed_block((const u8 *)edid, find_gtf2, &r); return r ? r[13] : 0; }
static int drm_gtf2_m(const struct edid *edid) { - u8 *r = NULL; - drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); + const u8 *r = NULL; + drm_for_each_detailed_block((const u8 *)edid, find_gtf2, &r); return r ? (r[15] << 8) + r[14] : 0; }
static int drm_gtf2_k(const struct edid *edid) { - u8 *r = NULL; - drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); + const u8 *r = NULL; + drm_for_each_detailed_block((const u8 *)edid, find_gtf2, &r); return r ? r[16] : 0; }
static int drm_gtf2_2j(const struct edid *edid) { - u8 *r = NULL; - drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); + const u8 *r = NULL; + drm_for_each_detailed_block((const u8 *)edid, find_gtf2, &r); return r ? r[17] : 0; }
@@ -838,7 +838,7 @@ drm_mode_std(struct drm_connector *connector, const 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 { @@ -882,11 +882,11 @@ drm_mode_do_interlace_quirk(struct drm_display_mode *mode, */ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, const 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; @@ -928,9 +928,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 = 10880; + else + mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
mode->hdisplay = hactive; mode->hsync_start = mode->hdisplay + hsync_offset; @@ -951,14 +951,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; @@ -981,7 +981,7 @@ set_size:
static bool mode_in_hsync_range(const struct drm_display_mode *mode, - const struct edid *edid, u8 *t) + const struct edid *edid, const u8 *t) { int hsync, hmin, hmax;
@@ -998,7 +998,7 @@ mode_in_hsync_range(const struct drm_display_mode *mode,
static bool mode_in_vsync_range(const struct drm_display_mode *mode, - const struct edid *edid, u8 *t) + const struct edid *edid, const u8 *t) { int vsync, vmin, vmax;
@@ -1014,7 +1014,7 @@ mode_in_vsync_range(const struct drm_display_mode *mode, }
static u32 -range_pixel_clock(const struct edid *edid, u8 *t) +range_pixel_clock(const struct edid *edid, const u8 *t) { /* unspecified */ if (t[9] == 0 || t[9] == 255) @@ -1030,10 +1030,10 @@ range_pixel_clock(const struct edid *edid, u8 *t)
static bool mode_in_range(const struct drm_display_mode *mode, const 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; @@ -1059,7 +1059,7 @@ mode_in_range(const struct drm_display_mode *mode, const struct edid *edid, static bool valid_inferred_mode(const struct drm_connector *connector, const struct drm_display_mode *mode) { - struct drm_display_mode *m; + const struct drm_display_mode *m; bool ok = false;
list_for_each_entry(m, &connector->probed_modes, head) { @@ -1077,7 +1077,7 @@ static bool valid_inferred_mode(const struct drm_connector *connector, static int drm_dmt_modes_for_range(struct drm_connector *connector, const struct edid *edid, - struct detailed_timing *timing) + const struct detailed_timing *timing) { int i, modes = 0; struct drm_display_mode *newmode; @@ -1113,7 +1113,7 @@ static void fixup_mode_1366x768(struct drm_display_mode *mode) static int drm_gtf_modes_for_range(struct drm_connector *connector, const struct edid *edid, - struct detailed_timing *timing) + const struct detailed_timing *timing) { int i, modes = 0; struct drm_display_mode *newmode; @@ -1142,7 +1142,7 @@ drm_gtf_modes_for_range(struct drm_connector *connector, static int drm_cvt_modes_for_range(struct drm_connector *connector, const struct edid *edid, - struct detailed_timing *timing) + const struct detailed_timing *timing) { int i, modes = 0; struct drm_display_mode *newmode; @@ -1170,11 +1170,11 @@ drm_cvt_modes_for_range(struct drm_connector *connector, }
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; - 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 (data->type != EDID_DETAIL_MONITOR_RANGE) return; @@ -1215,18 +1215,18 @@ add_inferred_modes(struct drm_connector *connector, const struct edid *edid) };
if (version_greater(edid, 1, 0)) - drm_for_each_detailed_block((u8 *)edid, do_inferred_modes, + drm_for_each_detailed_block((const u8 *)edid, do_inferred_modes, &closure);
return closure.modes; }
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) + 5; + const u8 *est = ((const u8 *)timing) + 5;
for (i = 0; i < 6; i++) { for (j = 7; j > 0; j--) { @@ -1251,10 +1251,10 @@ drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing) }
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; - struct detailed_non_pixel *data = &timing->data.other_data; + const struct detailed_non_pixel *data = &timing->data.other_data;
if (data->type == EDID_DETAIL_EST_TIMINGS) closure->modes += drm_est3_modes(closure->connector, timing); @@ -1291,24 +1291,24 @@ add_established_modes(struct drm_connector *connector, const struct edid *edid) }
if (version_greater(edid, 1, 0)) - drm_for_each_detailed_block((u8 *)edid, + drm_for_each_detailed_block((const u8 *)edid, do_established_modes, &closure);
return modes + closure.modes; }
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; - 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; const struct edid *edid = closure->edid;
if (data->type == EDID_DETAIL_STD_MODES) { int i; for (i = 0; i < 6; i++) { - struct std_timing *std; + const struct std_timing *std; struct drm_display_mode *newmode;
std = &data->data.timings[i]; @@ -1350,7 +1350,7 @@ add_standard_modes(struct drm_connector *connector, const struct edid *edid) }
if (version_greater(edid, 1, 0)) - drm_for_each_detailed_block((u8 *)edid, do_standard_modes, + drm_for_each_detailed_block((const u8 *)edid, do_standard_modes, &closure);
/* XXX should also look for standard codes in VTB blocks */ @@ -1359,12 +1359,12 @@ add_standard_modes(struct drm_connector *connector, const 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 };
@@ -1408,10 +1408,10 @@ 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; - struct detailed_non_pixel *data = &timing->data.other_data; + const struct detailed_non_pixel *data = &timing->data.other_data;
if (data->type == EDID_DETAIL_CVT_3BYTE) closure->modes += drm_cvt_modes(closure->connector, timing); @@ -1425,7 +1425,7 @@ add_cvt_modes(struct drm_connector *connector, const 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((const u8 *)edid, do_cvt_mode, &closure);
/* XXX should also look for CVT codes in VTB blocks */
@@ -1433,7 +1433,7 @@ add_cvt_modes(struct drm_connector *connector, const struct edid *edid) }
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; @@ -1476,7 +1476,7 @@ add_detailed_modes(struct drm_connector *connector, const 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((const u8 *)edid, do_detailed_mode, &closure);
return closure.modes; } @@ -1493,9 +1493,9 @@ add_detailed_modes(struct drm_connector *connector, const struct edid *edid, /** * Search EDID for CEA extension block. */ -u8 *drm_find_cea_extension(const struct edid *edid) +const u8 *drm_find_cea_extension(const struct edid *edid) { - u8 *edid_ext = NULL; + const u8 *edid_ext = NULL; int i;
/* No EDID or EDID extensions */ @@ -1504,7 +1504,7 @@ u8 *drm_find_cea_extension(const struct edid *edid)
/* Find CEA extension */ for (i = 0; i < edid->extensions; i++) { - edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1); + edid_ext = (const u8 *)edid + EDID_LENGTH * (i + 1); if (edid_ext[0] == CEA_EXT) break; } @@ -1520,13 +1520,13 @@ EXPORT_SYMBOL(drm_find_cea_extension); * Looks for a CEA mode matching given drm_display_mode. * Returns its CEA Video ID code, or 0 if not found. */ -u8 drm_match_cea_mode(struct drm_display_mode *to_match) +u8 drm_match_cea_mode(const struct drm_display_mode *to_match) { - struct drm_display_mode *cea_mode; + const struct drm_display_mode *cea_mode; u8 mode;
for (mode = 0; mode < drm_num_cea_modes; mode++) { - cea_mode = (struct drm_display_mode *)&edid_cea_modes[mode]; + cea_mode = (const struct drm_display_mode *)&edid_cea_modes[mode];
if (drm_mode_equal(to_match, cea_mode)) return mode + 1; @@ -1537,10 +1537,11 @@ EXPORT_SYMBOL(drm_match_cea_mode);
static int -do_cea_modes (struct drm_connector *connector, u8 *db, u8 len) +do_cea_modes (struct drm_connector *connector, const u8 *db, u8 len) { struct drm_device *dev = connector->dev; - u8 * mode, cea_mode; + const u8 * mode; + u8 cea_mode; int modes = 0;
for (mode = db; mode < db + len; mode++) { @@ -1596,8 +1597,9 @@ cea_db_offsets(const u8 *cea, int *start, int *end) static int add_cea_modes(struct drm_connector *connector, const struct edid *edid) { - u8 * cea = drm_find_cea_extension(edid); - u8 * db, dbl; + const u8 *cea = drm_find_cea_extension(edid); + const u8 *db; + u8 dbl; int modes = 0;
if (cea && cea_revision(cea) >= 3) { @@ -1658,10 +1660,10 @@ parse_hdmi_vsdb(struct drm_connector *connector, const u8 *db) }
static void -monitor_name(struct detailed_timing *t, void *data) +monitor_name(const struct detailed_timing *t, void *data) { if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME) - *(u8 **)data = t->data.other_data.data.str.str; + *(const u8 **)data = t->data.other_data.data.str.str; }
static bool cea_db_is_hdmi_vsdb(const u8 *db) @@ -1693,9 +1695,9 @@ static bool cea_db_is_hdmi_vsdb(const u8 *db) void drm_edid_to_eld(struct drm_connector *connector, const struct edid *edid) { uint8_t *eld = connector->eld; - u8 *cea; - u8 *name; - u8 *db; + const u8 *cea; + const u8 *name; + const u8 *db; int sad_count = 0; int mnl; int dbl; @@ -1709,7 +1711,7 @@ void drm_edid_to_eld(struct drm_connector *connector, const struct edid *edid) }
name = NULL; - drm_for_each_detailed_block((u8 *)edid, monitor_name, &name); + drm_for_each_detailed_block((const u8 *)edid, monitor_name, &name); for (mnl = 0; name && mnl < 13; mnl++) { if (name[mnl] == 0x0a) break; @@ -1771,8 +1773,8 @@ EXPORT_SYMBOL(drm_edid_to_eld); * @connector: connector associated with the HDMI/DP sink * @mode: the display mode */ -int drm_av_sync_delay(struct drm_connector *connector, - struct drm_display_mode *mode) +int drm_av_sync_delay(const struct drm_connector *connector, + const struct drm_display_mode *mode) { int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE); int a, v; @@ -1835,7 +1837,7 @@ EXPORT_SYMBOL(drm_select_eld); */ bool drm_detect_hdmi_monitor(const struct edid *edid) { - u8 *edid_ext; + const u8 *edid_ext; int i; int start_offset, end_offset;
@@ -1871,7 +1873,7 @@ EXPORT_SYMBOL(drm_detect_hdmi_monitor); */ bool drm_detect_monitor_audio(const struct edid *edid) { - u8 *edid_ext; + const u8 *edid_ext; int i, j; bool has_audio = false; int start_offset, end_offset; @@ -1916,7 +1918,7 @@ EXPORT_SYMBOL(drm_detect_monitor_audio); static void drm_add_display_info(const struct edid *edid, struct drm_display_info *info) { - u8 *edid_ext; + const u8 *edid_ext;
info->width_mm = edid->width_cm * 10; info->height_mm = edid->height_cm * 10; @@ -1989,7 +1991,7 @@ static void drm_add_display_info(const struct edid *edid, * * Return number of modes added or 0 if we couldn't find any. */ -int drm_add_edid_modes(struct drm_connector *connector, const struct edid *edid) +int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid) { int num_modes = 0; u32 quirks; diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 9b2198b..50c17b9 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -882,7 +882,7 @@ extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_m extern bool drm_probe_ddc(struct i2c_adapter *adapter); extern struct edid *drm_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter); -extern int drm_add_edid_modes(struct drm_connector *connector, const struct edid *edid); +extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid); extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode); extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode); extern void drm_mode_copy(struct drm_display_mode *dst, const struct drm_display_mode *src); @@ -1029,8 +1029,8 @@ extern int drm_mode_gamma_get_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); extern int drm_mode_gamma_set_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); -extern u8 *drm_find_cea_extension(const struct edid *edid); -extern u8 drm_match_cea_mode(struct drm_display_mode *to_match); +extern const u8 *drm_find_cea_extension(const struct edid *edid); +extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match); extern bool drm_detect_hdmi_monitor(const struct edid *edid); extern bool drm_detect_monitor_audio(const struct edid *edid); extern int drm_mode_page_flip_ioctl(struct drm_device *dev, @@ -1051,7 +1051,7 @@ extern uint8_t drm_mode_cea_vic(const struct drm_display_mode *mode);
extern int drm_edid_header_is_valid(const u8 *raw_edid); extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid); -extern bool drm_edid_is_valid(const struct edid *edid); +extern bool drm_edid_is_valid(struct edid *edid); struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, int hsize, int vsize, int fresh, bool rb); diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 464ae2b..1e0ab69 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -248,8 +248,8 @@ struct drm_encoder; struct drm_connector; struct drm_display_mode; void drm_edid_to_eld(struct drm_connector *connector, const struct edid *edid); -int drm_av_sync_delay(struct drm_connector *connector, - struct drm_display_mode *mode); +int drm_av_sync_delay(const struct drm_connector *connector, + const struct drm_display_mode *mode); struct drm_connector *drm_select_eld(struct drm_encoder *encoder, struct drm_display_mode *mode); int drm_load_edid_firmware(struct drm_connector *connector);
dri-devel@lists.freedesktop.org