x86/PCI: Name PCI BIOS error code & use FIELD_GET()
PATCH 1/1 x86/PCI: Name PCI BIOS error code & use FIELD_GET()
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.
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.
--- arch/x86/pci/pcbios.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
arch/x86/pci/pcbios.c +16 -6
@@ -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); 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); }
@@ -354,6 +362,7 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void) {struct irq_routing_options opt;struct irq_routing_table *rt =NULL ; +unsigned int error_code;int ret, map;unsigned long page;
@@ -385,8 +394,9 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void) "m" (opt) : "memory");DBG ("OK ret=%d, size=%d, map=%x\n" , ret, opt.size, map); -if (ret &0xff00 ) -printk (KERN_ERR "PCI: Error %02x when fetching IRQ routing table.\n" , (ret >>8 ) &0xff ); + error_code =FIELD_GET (PCIBIOS_RETURN_CODE , ret); +if (error_code) +printk (KERN_ERR "PCI: Error %02x when fetching IRQ routing table.\n" , error_code);else if (opt.size) { rt =kmalloc (sizeof (struct irq_routing_table ) + opt.size,GFP_KERNEL );if (rt) {
@@ -415,7 +425,7 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)"b" ((dev->bus->number <<8 ) | dev->devfn),"c" ((irq <<8 ) | (pin +10 )), "S" (&pci_indirect)); -return !(ret &0xff00 ); +return FIELD_GET (PCIBIOS_RETURN_CODE , ret) ==PCIBIOS_SUCCESSFUL ; }EXPORT_SYMBOL (pcibios_set_irq_routing);
Signature · 1 line
2.30.2
Quoted 3 lines · Ilpo Järvinen
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.
Quoted 5 lines
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.
Quoted 30 lines
arch/x86/pci/pcbios.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)arch/x86/pci/pcbios.c +8
-0@@ -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:
arch/x86/pci/pcbios.c static int __init check_pcibios(void) · line 165
Quoted 5 lines
arch/x86/pci/pcbios.c +1
-1@@ -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.
Quoted 13 lines
arch/x86/pci/pcbios.c +1
-1hw_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,
arch/x86/pci/pcbios.c static int pci_bios_write(unsigned int seg, unsigned int bus, · line 281
Quoted 6 lines
arch/x86/pci/pcbios.c +1
-1@@ -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."
Quoted 7 lines · Dave Hansen
Quoted 3 lines · Ilpo Järvinen
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
"high 8 bits" should odd to me since AH is not exactly at the highest end of eax register. But I'll try to figure out something along the lines of your suggestion.
Quoted 12 lines
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.
Quoted 5 lines
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.
Quoted 6 lines
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.
Okay, I'll try to adapt the rest of the changelog to your suggestions and make other changes you suggested.
Signature · 1 line
i.
Quoted 78 lines
Quoted 30 lines
arch/x86/pci/pcbios.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)arch/x86/pci/pcbios.c +8
-0@@ -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: arch/x86/pci/pcbios.c static int __init check_pcibios(void) · line 165
Quoted 5 lines
arch/x86/pci/pcbios.c +1
-1@@ -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.
Quoted 13 lines
arch/x86/pci/pcbios.c +1
-1hw_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,arch/x86/pci/pcbios.c static int pci_bios_write(unsigned int seg, unsigned int bus, · line 281
Quoted 6 lines
arch/x86/pci/pcbios.c +1
-1@@ -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."