All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Jani Nikula <jani.nikula@intel.com>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH 2/9] drm/edid: pass a timing pointer to is_display_descriptor()
Date: Fri, 25 Mar 2022 14:49:59 +0200	[thread overview]
Message-ID: <Yj26d1dJz5yfjbKJ@intel.com> (raw)
In-Reply-To: <7752b5a00e96b9b6719402487185211937c62c7d.1648210803.git.jani.nikula@intel.com>

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

-- 
Ville Syrjälä
Intel

WARNING: multiple messages have this Message-ID (diff)
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Jani Nikula <jani.nikula@intel.com>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 2/9] drm/edid: pass a timing pointer to is_display_descriptor()
Date: Fri, 25 Mar 2022 14:49:59 +0200	[thread overview]
Message-ID: <Yj26d1dJz5yfjbKJ@intel.com> (raw)
In-Reply-To: <7752b5a00e96b9b6719402487185211937c62c7d.1648210803.git.jani.nikula@intel.com>

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

-- 
Ville Syrjälä
Intel

  reply	other threads:[~2022-03-25 12:50 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25 12:25 [Intel-gfx] [PATCH 0/9] drm/edid: constify EDID parsing Jani Nikula
2022-03-25 12:25 ` Jani Nikula
2022-03-25 12:25 ` [Intel-gfx] [PATCH 1/9] drm/edid: don't modify EDID while parsing Jani Nikula
2022-03-25 12:25   ` Jani Nikula
2022-03-25 12:40   ` [Intel-gfx] " Ville Syrjälä
2022-03-25 12:40     ` Ville Syrjälä
2022-03-25 12:25 ` [Intel-gfx] [PATCH 2/9] drm/edid: pass a timing pointer to is_display_descriptor() Jani Nikula
2022-03-25 12:25   ` Jani Nikula
2022-03-25 12:49   ` Ville Syrjälä [this message]
2022-03-25 12:49     ` Ville Syrjälä
2022-03-25 12:25 ` [Intel-gfx] [PATCH 3/9] drm/edid: use struct detailed_timing member access in is_rb() Jani Nikula
2022-03-25 12:25   ` Jani Nikula
2022-03-25 13:06   ` [Intel-gfx] " Ville Syrjälä
2022-03-25 13:06     ` Ville Syrjälä
2022-03-25 12:25 ` [Intel-gfx] [PATCH 4/9] drm/edid: use struct detailed_timing member access in gtf2 functions Jani Nikula
2022-03-25 12:25   ` Jani Nikula
2022-03-25 12:25 ` [Intel-gfx] [PATCH 5/9] drm/edid: constify struct detailed_timing in lower level parsing Jani Nikula
2022-03-25 12:25   ` Jani Nikula
2022-03-25 12:25 ` [Intel-gfx] [PATCH 6/9] drm/edid: constify struct detailed_timing in parsing callbacks Jani Nikula
2022-03-25 12:25   ` Jani Nikula
2022-03-25 12:25 ` [Intel-gfx] [PATCH 7/9] drm/edid: constify struct edid passed to detailed blocks Jani Nikula
2022-03-25 12:25   ` Jani Nikula
2022-03-25 12:25 ` [Intel-gfx] [PATCH 8/9] drm/edid: constify struct edid passed around in callbacks and closure Jani Nikula
2022-03-25 12:25   ` Jani Nikula
2022-03-25 12:25 ` [Intel-gfx] [PATCH 9/9] drm/edid: add more general struct edid constness in the interfaces Jani Nikula
2022-03-25 12:25   ` Jani Nikula
2022-03-25 13:19 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/edid: constify EDID parsing Patchwork
2022-03-25 13:26 ` [Intel-gfx] ✗ Fi.CI.DOCS: " Patchwork
2022-03-25 13:46 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2022-03-25 15:54 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yj26d1dJz5yfjbKJ@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.