Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 3/3] drm/i915/i915: assume vbt is 4-byte aligned into oprom
Date: Fri, 22 Nov 2019 15:55:32 +0200	[thread overview]
Message-ID: <20191122135532.GL1208@intel.com> (raw)
In-Reply-To: <20191121185429.aqc2ga7ciiqkoovg@ldmartin-desk1>

On Thu, Nov 21, 2019 at 10:54:29AM -0800, Lucas De Marchi wrote:
> On Thu, Nov 21, 2019 at 03:09:03PM +0200, Jani Nikula wrote:
> >On Wed, 20 Nov 2019, Lucas De Marchi <lucas.demarchi@intel.com> wrote:
> >> The unaligned ioread32() will make us read byte by byte looking for the
> >> vbt. We could just as well have done a ioread8() + a shift and avoid the
> >> extra confusion on how we are looking for "$VBT".
> >>
> >> However when using ACPI it's guaranteed the VBT is 4-byte aligned
> >> per spec, so we can probably assume it here as well.
> >>
> >> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
> >> ---
> >>  drivers/gpu/drm/i915/display/intel_bios.c | 19 ++++++-------------
> >>  1 file changed, 6 insertions(+), 13 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> >> index aa9b182efee5..6bf57b1ad056 100644
> >> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> >> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> >> @@ -1902,27 +1902,20 @@ static struct vbt_header *oprom_get_vbt(struct drm_i915_private *dev_priv)
> >>  	void __iomem *p = NULL, *oprom;
> >>  	struct vbt_header *vbt;
> >>  	u16 vbt_size;
> >> -	size_t i, size;
> >> +	size_t size;
> >>
> >>  	oprom = pci_map_rom(pdev, &size);
> >>  	if (!oprom)
> >>  		return NULL;
> >>
> >>  	/* Scour memory looking for the VBT signature. */
> >> -	for (i = 0; i + 4 < size; i++) {
> >> -		if (ioread32(oprom + i) != *((const u32 *)"$VBT"))
> >> -			continue;
> >> -
> >> -		p = oprom + i;
> >> -		size -= i;
> >> -		break;
> >> -	}
> >> -
> >> -	if (!p)
> >> -		goto err_unmap_oprom;
> >> +	for (p = oprom; size >= 4; p += 4, size -= 4)
> >> +		if (ioread32(p) == *((const u32 *)"$VBT"))
> >> +			break;
> >
> >I think the original is easier to read. You only really need to change
> >"i++" to "i += 4" and be done with it.
> 
> I really liked this version much more... shorter and with only one control
> variable rather than keeping the control in 3 different places (i, size
> and p).

I think I'm with Jani here. Generally not a huge fan of pointer
arithmetic, and having just one variable modified by the loop is
more customary so usually doesn't require me to read more than
once. This thing I had to read a few times to make sure I
understood what it's doing.

-- 
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH 3/3] drm/i915/i915: assume vbt is 4-byte aligned into oprom
Date: Fri, 22 Nov 2019 15:55:32 +0200	[thread overview]
Message-ID: <20191122135532.GL1208@intel.com> (raw)
Message-ID: <20191122135532.rZVNMncp157PtRw9UR76uWb835ipGumWED5hVezrK4E@z> (raw)
In-Reply-To: <20191121185429.aqc2ga7ciiqkoovg@ldmartin-desk1>

On Thu, Nov 21, 2019 at 10:54:29AM -0800, Lucas De Marchi wrote:
> On Thu, Nov 21, 2019 at 03:09:03PM +0200, Jani Nikula wrote:
> >On Wed, 20 Nov 2019, Lucas De Marchi <lucas.demarchi@intel.com> wrote:
> >> The unaligned ioread32() will make us read byte by byte looking for the
> >> vbt. We could just as well have done a ioread8() + a shift and avoid the
> >> extra confusion on how we are looking for "$VBT".
> >>
> >> However when using ACPI it's guaranteed the VBT is 4-byte aligned
> >> per spec, so we can probably assume it here as well.
> >>
> >> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
> >> ---
> >>  drivers/gpu/drm/i915/display/intel_bios.c | 19 ++++++-------------
> >>  1 file changed, 6 insertions(+), 13 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
> >> index aa9b182efee5..6bf57b1ad056 100644
> >> --- a/drivers/gpu/drm/i915/display/intel_bios.c
> >> +++ b/drivers/gpu/drm/i915/display/intel_bios.c
> >> @@ -1902,27 +1902,20 @@ static struct vbt_header *oprom_get_vbt(struct drm_i915_private *dev_priv)
> >>  	void __iomem *p = NULL, *oprom;
> >>  	struct vbt_header *vbt;
> >>  	u16 vbt_size;
> >> -	size_t i, size;
> >> +	size_t size;
> >>
> >>  	oprom = pci_map_rom(pdev, &size);
> >>  	if (!oprom)
> >>  		return NULL;
> >>
> >>  	/* Scour memory looking for the VBT signature. */
> >> -	for (i = 0; i + 4 < size; i++) {
> >> -		if (ioread32(oprom + i) != *((const u32 *)"$VBT"))
> >> -			continue;
> >> -
> >> -		p = oprom + i;
> >> -		size -= i;
> >> -		break;
> >> -	}
> >> -
> >> -	if (!p)
> >> -		goto err_unmap_oprom;
> >> +	for (p = oprom; size >= 4; p += 4, size -= 4)
> >> +		if (ioread32(p) == *((const u32 *)"$VBT"))
> >> +			break;
> >
> >I think the original is easier to read. You only really need to change
> >"i++" to "i += 4" and be done with it.
> 
> I really liked this version much more... shorter and with only one control
> variable rather than keeping the control in 3 different places (i, size
> and p).

I think I'm with Jani here. Generally not a huge fan of pointer
arithmetic, and having just one variable modified by the loop is
more customary so usually doesn't require me to read more than
once. This thing I had to read a few times to make sure I
understood what it's doing.

-- 
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2019-11-22 13:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-20 23:46 [PATCH 1/3] drm/i915/bios: do not discard address space Lucas De Marchi
2019-11-20 23:46 ` [Intel-gfx] " Lucas De Marchi
2019-11-20 23:46 ` [PATCH 2/3] drm/i915/bios: fold pci rom map/unmap into copy function Lucas De Marchi
2019-11-20 23:46   ` [Intel-gfx] " Lucas De Marchi
2019-11-21 13:02   ` Jani Nikula
2019-11-21 13:02     ` [Intel-gfx] " Jani Nikula
2019-11-22 13:49   ` Ville Syrjälä
2019-11-22 13:49     ` [Intel-gfx] " Ville Syrjälä
2019-11-20 23:46 ` [PATCH 3/3] drm/i915/i915: assume vbt is 4-byte aligned into oprom Lucas De Marchi
2019-11-20 23:46   ` [Intel-gfx] " Lucas De Marchi
2019-11-21 13:09   ` Jani Nikula
2019-11-21 13:09     ` [Intel-gfx] " Jani Nikula
2019-11-21 18:54     ` Lucas De Marchi
2019-11-21 18:54       ` [Intel-gfx] " Lucas De Marchi
2019-11-22 13:55       ` Ville Syrjälä [this message]
2019-11-22 13:55         ` Ville Syrjälä
2019-11-25 17:43         ` Lucas De Marchi
2019-11-25 17:43           ` [Intel-gfx] " Lucas De Marchi
2019-11-21  3:44 ` ✓ Fi.CI.BAT: success for series starting with [1/3] drm/i915/bios: do not discard address space Patchwork
2019-11-21  3:44   ` [Intel-gfx] " Patchwork
2019-11-22  5:42 ` ✗ Fi.CI.IGT: failure " Patchwork
2019-11-22  5:42   ` [Intel-gfx] " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2019-11-15 23:35 [PATCH 1/3] " Lucas De Marchi
2019-11-15 23:35 ` [PATCH 3/3] drm/i915/i915: assume vbt is 4-byte aligned into oprom Lucas De Marchi

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=20191122135532.GL1208@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=lucas.demarchi@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox