arch/x86: Optimise PCI IO config accessor

By design only 'reg' parameter can have the two least-
significant bits set. As 'reg' is often a constant,
'0xCFC + (reg & 3)' resolves to an immediate value
already at buildtime, unlike (addr & 3) which depends
of a constant (but non-immediate) value of 'dev' in
ramstage.

Change-Id: I6e729fe800c92b1ce4994ad2b4203072fa75a958
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/31754
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Kyösti Mälkki 2019-03-11 18:26:01 +02:00 committed by Patrick Georgi
parent 125c9cf98c
commit 3af6aa10f7
1 changed files with 4 additions and 4 deletions

View File

@ -34,7 +34,7 @@ uint8_t pci_io_read_config8(pci_devfn_t dev, uint16_t reg)
{ {
uint32_t addr = pci_io_encode_addr(dev, reg); uint32_t addr = pci_io_encode_addr(dev, reg);
outl(0x80000000 | (addr & ~3), 0xCF8); outl(0x80000000 | (addr & ~3), 0xCF8);
return inb(0xCFC + (addr & 3)); return inb(0xCFC + (reg & 3));
} }
static __always_inline static __always_inline
@ -42,7 +42,7 @@ uint16_t pci_io_read_config16(pci_devfn_t dev, uint16_t reg)
{ {
uint32_t addr = pci_io_encode_addr(dev, reg); uint32_t addr = pci_io_encode_addr(dev, reg);
outl(0x80000000 | (addr & ~3), 0xCF8); outl(0x80000000 | (addr & ~3), 0xCF8);
return inw(0xCFC + (addr & 2)); return inw(0xCFC + (reg & 2));
} }
static __always_inline static __always_inline
@ -58,7 +58,7 @@ void pci_io_write_config8(pci_devfn_t dev, uint16_t reg, uint8_t value)
{ {
uint32_t addr = pci_io_encode_addr(dev, reg); uint32_t addr = pci_io_encode_addr(dev, reg);
outl(0x80000000 | (addr & ~3), 0xCF8); outl(0x80000000 | (addr & ~3), 0xCF8);
outb(value, 0xCFC + (addr & 3)); outb(value, 0xCFC + (reg & 3));
} }
static __always_inline static __always_inline
@ -66,7 +66,7 @@ void pci_io_write_config16(pci_devfn_t dev, uint16_t reg, uint16_t value)
{ {
uint32_t addr = pci_io_encode_addr(dev, reg); uint32_t addr = pci_io_encode_addr(dev, reg);
outl(0x80000000 | (addr & ~3), 0xCF8); outl(0x80000000 | (addr & ~3), 0xCF8);
outw(value, 0xCFC + (addr & 2)); outw(value, 0xCFC + (reg & 2));
} }
static __always_inline static __always_inline