All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Souza, Jose" <jose.souza@intel.com>
To: "Lee, Shawn C" <shawn.c.lee@intel.com>,
	"lma@semihalf.com" <lma@semihalf.com>
Cc: "dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"joonas.lahtinen@linux.intel.com"
	<joonas.lahtinen@linux.intel.com>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"jani.nikula@linux.intel.com" <jani.nikula@linux.intel.com>,
	"upstream@semihalf.com" <upstream@semihalf.com>
Subject: Re: [PATCH v2] drm/i915/bdb: Fix version check
Date: Wed, 29 Sep 2021 18:01:37 +0000	[thread overview]
Message-ID: <63d01fefc3068267b9115513020a1cbd9e64a5e2.camel@intel.com> (raw)
In-Reply-To: <20210923164927.55896-1-lma@semihalf.com>

On Thu, 2021-09-23 at 18:49 +0200, Lukasz Majczak wrote:
> With patch "drm/i915/vbt: Fix backlight parsing for VBT 234+"
> the size of bdb_lfp_backlight_data structure has been increased,
> causing if-statement in the parse_lfp_backlight function
> that comapres this structure size to the one retrieved from BDB,
> always to fail for older revisions.
> This patch calculates expected size of the structure for a given
> BDB version and compares it with the value gathered from BDB.
> Tested on Chromebook Pixelbook (Nocturne) (reports bdb->version = 221)

Fixes: d381baad29b4 ("drm/i915/vbt: Fix backlight parsing for VBT 234+")

> 
> Tested-by: Lukasz Majczak <lma@semihalf.com>
> Signed-off-by: Lukasz Majczak <lma@semihalf.com>
> ---
>  drivers/gpu/drm/i915/display/intel_bios.c     | 11 +++++++++--
>  drivers/gpu/drm/i915/display/intel_vbt_defs.h |  5 +++++
>  2 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> index 3c25926092de..90eae6da12e0 100644
> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> @@ -428,6 +428,7 @@ parse_lfp_backlight(struct drm_i915_private *i915,
>  	const struct lfp_backlight_data_entry *entry;
>  	int panel_type = i915->vbt.panel_type;
>  	u16 level;
> +	size_t exp_size;
>  
>  	backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
>  	if (!backlight_data)
> @@ -450,9 +451,15 @@ parse_lfp_backlight(struct drm_i915_private *i915,
>  		return;
>  	}
>  
> +	if (bdb->version <= 234)
> +		exp_size = EXP_BDB_LFP_BL_DATA_SIZE_REV_234;
> +	else if (bdb->version > 234 && bdb->version <= 236)
> +		exp_size = EXP_BDB_LFP_BL_DATA_SIZE_REV_236;
> +	else
> +		exp_size = sizeof(struct bdb_lfp_backlight_data);

Usually we go by the newest(IP version, platform...) to the oldest:


if (bdb->version >= 236)
	exp_size = sizeof(struct bdb_lfp_backlight_data);
else if (bdb->version >= 234)
	exp_size = offsetof(struct bdb_lfp_backlight_data, brightness_precision_bits);
else
	exp_size = offsetof(struct bdb_lfp_backlight_data, brightness_level);


backlight_control was added in version 191 so no need to set exp_size for older versions.

> +
>  	i915->vbt.backlight.type = INTEL_BACKLIGHT_DISPLAY_DDI;
> -	if (bdb->version >= 191 &&
> -	    get_blocksize(backlight_data) >= sizeof(*backlight_data)) {
> +	if (bdb->version >= 191  && get_blocksize(backlight_data) >= exp_size) {
>  		const struct lfp_backlight_control_method *method;
>  
>  		method = &backlight_data->backlight_control[panel_type];
> diff --git a/drivers/gpu/drm/i915/display/intel_vbt_defs.h b/drivers/gpu/drm/i915/display/intel_vbt_defs.h
> index 330077c2e588..ba9990e5983c 100644
> --- a/drivers/gpu/drm/i915/display/intel_vbt_defs.h
> +++ b/drivers/gpu/drm/i915/display/intel_vbt_defs.h
> @@ -814,6 +814,11 @@ struct lfp_brightness_level {
>  	u16 reserved;
>  } __packed;
>  
> +#define EXP_BDB_LFP_BL_DATA_SIZE_REV_234 \
> +	offsetof(struct bdb_lfp_backlight_data, brightness_level)

version 234 starts at brightness_level but the size of 234 data must be included to the size, so it should be:
offsetof(struct bdb_lfp_backlight_data, brightness_precision_bits).

> +#define EXP_BDB_LFP_BL_DATA_SIZE_REV_236 \
> +	offsetof(struct bdb_lfp_backlight_data, brightness_precision_bits)

> +
>  struct bdb_lfp_backlight_data {
>  	u8 entry_size;
>  	struct lfp_backlight_data_entry data[16];


WARNING: multiple messages have this Message-ID (diff)
From: "Souza, Jose" <jose.souza@intel.com>
To: "Lee, Shawn C" <shawn.c.lee@intel.com>,
	"lma@semihalf.com" <lma@semihalf.com>
Cc: "dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"joonas.lahtinen@linux.intel.com"
	<joonas.lahtinen@linux.intel.com>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"jani.nikula@linux.intel.com" <jani.nikula@linux.intel.com>,
	"upstream@semihalf.com" <upstream@semihalf.com>
Subject: Re: [Intel-gfx] [PATCH v2] drm/i915/bdb: Fix version check
Date: Wed, 29 Sep 2021 18:01:37 +0000	[thread overview]
Message-ID: <63d01fefc3068267b9115513020a1cbd9e64a5e2.camel@intel.com> (raw)
In-Reply-To: <20210923164927.55896-1-lma@semihalf.com>

On Thu, 2021-09-23 at 18:49 +0200, Lukasz Majczak wrote:
> With patch "drm/i915/vbt: Fix backlight parsing for VBT 234+"
> the size of bdb_lfp_backlight_data structure has been increased,
> causing if-statement in the parse_lfp_backlight function
> that comapres this structure size to the one retrieved from BDB,
> always to fail for older revisions.
> This patch calculates expected size of the structure for a given
> BDB version and compares it with the value gathered from BDB.
> Tested on Chromebook Pixelbook (Nocturne) (reports bdb->version = 221)

Fixes: d381baad29b4 ("drm/i915/vbt: Fix backlight parsing for VBT 234+")

> 
> Tested-by: Lukasz Majczak <lma@semihalf.com>
> Signed-off-by: Lukasz Majczak <lma@semihalf.com>
> ---
>  drivers/gpu/drm/i915/display/intel_bios.c     | 11 +++++++++--
>  drivers/gpu/drm/i915/display/intel_vbt_defs.h |  5 +++++
>  2 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> index 3c25926092de..90eae6da12e0 100644
> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> @@ -428,6 +428,7 @@ parse_lfp_backlight(struct drm_i915_private *i915,
>  	const struct lfp_backlight_data_entry *entry;
>  	int panel_type = i915->vbt.panel_type;
>  	u16 level;
> +	size_t exp_size;
>  
>  	backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
>  	if (!backlight_data)
> @@ -450,9 +451,15 @@ parse_lfp_backlight(struct drm_i915_private *i915,
>  		return;
>  	}
>  
> +	if (bdb->version <= 234)
> +		exp_size = EXP_BDB_LFP_BL_DATA_SIZE_REV_234;
> +	else if (bdb->version > 234 && bdb->version <= 236)
> +		exp_size = EXP_BDB_LFP_BL_DATA_SIZE_REV_236;
> +	else
> +		exp_size = sizeof(struct bdb_lfp_backlight_data);

Usually we go by the newest(IP version, platform...) to the oldest:


if (bdb->version >= 236)
	exp_size = sizeof(struct bdb_lfp_backlight_data);
else if (bdb->version >= 234)
	exp_size = offsetof(struct bdb_lfp_backlight_data, brightness_precision_bits);
else
	exp_size = offsetof(struct bdb_lfp_backlight_data, brightness_level);


backlight_control was added in version 191 so no need to set exp_size for older versions.

> +
>  	i915->vbt.backlight.type = INTEL_BACKLIGHT_DISPLAY_DDI;
> -	if (bdb->version >= 191 &&
> -	    get_blocksize(backlight_data) >= sizeof(*backlight_data)) {
> +	if (bdb->version >= 191  && get_blocksize(backlight_data) >= exp_size) {
>  		const struct lfp_backlight_control_method *method;
>  
>  		method = &backlight_data->backlight_control[panel_type];
> diff --git a/drivers/gpu/drm/i915/display/intel_vbt_defs.h b/drivers/gpu/drm/i915/display/intel_vbt_defs.h
> index 330077c2e588..ba9990e5983c 100644
> --- a/drivers/gpu/drm/i915/display/intel_vbt_defs.h
> +++ b/drivers/gpu/drm/i915/display/intel_vbt_defs.h
> @@ -814,6 +814,11 @@ struct lfp_brightness_level {
>  	u16 reserved;
>  } __packed;
>  
> +#define EXP_BDB_LFP_BL_DATA_SIZE_REV_234 \
> +	offsetof(struct bdb_lfp_backlight_data, brightness_level)

version 234 starts at brightness_level but the size of 234 data must be included to the size, so it should be:
offsetof(struct bdb_lfp_backlight_data, brightness_precision_bits).

> +#define EXP_BDB_LFP_BL_DATA_SIZE_REV_236 \
> +	offsetof(struct bdb_lfp_backlight_data, brightness_precision_bits)

> +
>  struct bdb_lfp_backlight_data {
>  	u8 entry_size;
>  	struct lfp_backlight_data_entry data[16];


  parent reply	other threads:[~2021-09-29 18:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-23 16:49 [PATCH v2] drm/i915/bdb: Fix version check Lukasz Majczak
2021-09-23 16:49 ` [Intel-gfx] " Lukasz Majczak
2021-09-23 20:34 ` [Intel-gfx] ✓ Fi.CI.BAT: success for drm/i915/bdb: Fix version check (rev2) Patchwork
2021-09-24  1:00 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork
2021-09-29 18:01 ` Souza, Jose [this message]
2021-09-29 18:01   ` [Intel-gfx] [PATCH v2] drm/i915/bdb: Fix version check Souza, Jose

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=63d01fefc3068267b9115513020a1cbd9e64a5e2.camel@intel.com \
    --to=jose.souza@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=lma@semihalf.com \
    --cc=shawn.c.lee@intel.com \
    --cc=upstream@semihalf.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.