Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] x86/PCI: Name PCI BIOS error code & use FIELD_GET()
Date: Thu, 26 Oct 2023 10:37:12 -0700	[thread overview]
Message-ID: <476692ae-81e5-4b65-93e9-eb303bc4b80d@intel.com> (raw)
In-Reply-To: <20231026125453.25767-1-ilpo.jarvinen@linux.intel.com>

TOn 10/26/23 05:54, Ilpo Järvinen wrote:
> PCI BIOS returns error code in AH register when carry flag is set. The
> extraction of the error code is currently set of masking and shifting
> which makes the code harder to understand than it needs to be.

That's a really convoluted way of saying that "The error code is in the
high 8 bits of EAX".  The fact that 'AH' is an alias for the same
logical thing or that BIOS doesn't fill it in when !CF are rather
irrelevant to this patch.  In fact, that makes this changelog actively
confusing because there's no carry flag logic to be seen.  'eax' (the
variable) universally has a valid error code, it's just zero when
there's no error.

> Name the PCI BIOS error code with a define and use FIELD_GET() to
> access it to improve code readability.
> 
> In addition, rely on implicit cast to int and replace zero test
> with PCIBIOS_SUCCESSFUL.

It would be really nice if this was something like:

	Subject: x86/PCI: Clean up open-coded error code mangling

That makes it clear that this is a cleanup.  It's kinda obvious from the
code that it uses FIELD_GET().  You don't need to tell us in the subject.

>  arch/x86/pci/pcbios.c | 22 ++++++++++++++++------
>  1 file changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
> index 4f15280732ed..0515e0c05e10 100644
> --- a/arch/x86/pci/pcbios.c
> +++ b/arch/x86/pci/pcbios.c
> @@ -3,6 +3,8 @@
>   * BIOS32 and PCI BIOS handling.
>   */
>  
> +#include <linux/bits.h>
> +#include <linux/bitfield.h>
>  #include <linux/pci.h>
>  #include <linux/init.h>
>  #include <linux/slab.h>
> @@ -29,6 +31,12 @@
>  #define PCIBIOS_HW_TYPE1_SPEC		0x10
>  #define PCIBIOS_HW_TYPE2_SPEC		0x20
>  
> +/*
> + * Returned in EAX:
> + * - AH: return code
> + */
> +#define PCIBIOS_RETURN_CODE			GENMASK(15, 8)
> +
>  int pcibios_enabled;
>  
>  /* According to the BIOS specification at:
> @@ -154,7 +162,7 @@ static int __init check_pcibios(void)
>  			: "memory");
>  		local_irq_restore(flags);
>  
> -		status = (eax >> 8) & 0xff;
> +		status = FIELD_GET(PCIBIOS_RETURN_CODE, eax);

Nit: This:

	FIELD_GET(PCIBIOS_RETURN_CODE, foo)

pattern is repeated for *EVERY* use of PCIBIOS_RETURN_CODE.  This would
actually look nicer if you just did a helper like:

	static inline u32 get_return_code(u32 eax)
	{
		return FIELD_GET(PCIBIOS_RETURN_CODE, eax);
	}

although I'm not 100% sure what types you actually want there.

>  		hw_mech = eax & 0xff;
>  		major_ver = (ebx >> 8) & 0xff;
>  		minor_ver = ebx & 0xff;
> @@ -227,7 +235,7 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
>  
>  	raw_spin_unlock_irqrestore(&pci_config_lock, flags);
>  
> -	return (int)((result & 0xff00) >> 8);
> +	return FIELD_GET(PCIBIOS_RETURN_CODE, result);
>  }
>  
>  static int pci_bios_write(unsigned int seg, unsigned int bus,
> @@ -269,7 +277,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
>  
>  	raw_spin_unlock_irqrestore(&pci_config_lock, flags);
>  
> -	return (int)((result & 0xff00) >> 8);
> +	return FIELD_GET(PCIBIOS_RETURN_CODE, result);
>  }

For a cleanup like this, it's also nice to add the blurb:

	"No functional changes intended."

Or even (if it's true):

	"New code compiles the exact same code as the old code."


  reply	other threads:[~2023-10-26 17:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-26 12:54 [PATCH 1/1] x86/PCI: Name PCI BIOS error code & use FIELD_GET() Ilpo Järvinen
2023-10-26 17:37 ` Dave Hansen [this message]
2023-10-27  9:32   ` Ilpo Järvinen

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=476692ae-81e5-4b65-93e9-eb303bc4b80d@intel.com \
    --to=dave.hansen@intel.com \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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