Skip to content

Commit 0d481ff

Browse files
ij-intelbjorn-helgaas
authored andcommitted
x86/pci: Clean up open-coded PCIBIOS return code mangling
Per PCI Firmware spec r3.3, sec 2.5.2, 2.6.2, and 2.7, the return code for these PCI BIOS interfaces is in 8 bits of the EAX register. Previously it was extracted by open-coded masks and shifting. Name the return code bits with a #define and add pcibios_get_return_code() to extract the return code to improve code readability. In addition, replace zero test with PCIBIOS_SUCCESSFUL. No functional changes intended. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 420ac76 commit 0d481ff

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

arch/x86/pci/pcbios.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* BIOS32 and PCI BIOS handling.
44
*/
55

6+
#include <linux/bits.h>
7+
#include <linux/bitfield.h>
68
#include <linux/pci.h>
79
#include <linux/init.h>
810
#include <linux/slab.h>
@@ -29,8 +31,19 @@
2931
#define PCIBIOS_HW_TYPE1_SPEC 0x10
3032
#define PCIBIOS_HW_TYPE2_SPEC 0x20
3133

34+
/*
35+
* Returned in EAX:
36+
* - AH: return code
37+
*/
38+
#define PCIBIOS_RETURN_CODE GENMASK(15, 8)
39+
3240
int pcibios_enabled;
3341

42+
static u8 pcibios_get_return_code(u32 eax)
43+
{
44+
return FIELD_GET(PCIBIOS_RETURN_CODE, eax);
45+
}
46+
3447
/* According to the BIOS specification at:
3548
* http://members.datafast.net.au/dft0802/specs/bios21.pdf, we could
3649
* restrict the x zone to some pages and make it ro. But this may be
@@ -154,7 +167,7 @@ static int __init check_pcibios(void)
154167
: "memory");
155168
local_irq_restore(flags);
156169

157-
status = (eax >> 8) & 0xff;
170+
status = pcibios_get_return_code(eax);
158171
hw_mech = eax & 0xff;
159172
major_ver = (ebx >> 8) & 0xff;
160173
minor_ver = ebx & 0xff;
@@ -227,7 +240,7 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
227240

228241
raw_spin_unlock_irqrestore(&pci_config_lock, flags);
229242

230-
return (int)((result & 0xff00) >> 8);
243+
return pcibios_get_return_code(result);
231244
}
232245

233246
static int pci_bios_write(unsigned int seg, unsigned int bus,
@@ -269,7 +282,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
269282

270283
raw_spin_unlock_irqrestore(&pci_config_lock, flags);
271284

272-
return (int)((result & 0xff00) >> 8);
285+
return pcibios_get_return_code(result);
273286
}
274287

275288

@@ -385,9 +398,10 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
385398
"m" (opt)
386399
: "memory");
387400
DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
388-
if (ret & 0xff00)
389-
printk(KERN_ERR "PCI: Error %02x when fetching IRQ routing table.\n", (ret >> 8) & 0xff);
390-
else if (opt.size) {
401+
ret = pcibios_get_return_code(ret);
402+
if (ret) {
403+
printk(KERN_ERR "PCI: Error %02x when fetching IRQ routing table.\n", ret);
404+
} else if (opt.size) {
391405
rt = kmalloc(sizeof(struct irq_routing_table) + opt.size, GFP_KERNEL);
392406
if (rt) {
393407
memset(rt, 0, sizeof(struct irq_routing_table));
@@ -415,7 +429,7 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
415429
"b" ((dev->bus->number << 8) | dev->devfn),
416430
"c" ((irq << 8) | (pin + 10)),
417431
"S" (&pci_indirect));
418-
return !(ret & 0xff00);
432+
return pcibios_get_return_code(ret) == PCIBIOS_SUCCESSFUL;
419433
}
420434
EXPORT_SYMBOL(pcibios_set_irq_routing);
421435

0 commit comments

Comments
 (0)