From 3af6aa10f7a439e97a5f7d159336b4a207a97c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ky=C3=B6sti=20M=C3=A4lkki?= Date: Mon, 11 Mar 2019 18:26:01 +0200 Subject: arch/x86: Optimise PCI IO config accessor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/31754 Reviewed-by: Nico Huber Tested-by: build bot (Jenkins) --- src/arch/x86/include/arch/pci_io_cfg.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/arch/x86/include') diff --git a/src/arch/x86/include/arch/pci_io_cfg.h b/src/arch/x86/include/arch/pci_io_cfg.h index 317c50a3fc..6c88b3cf5e 100644 --- a/src/arch/x86/include/arch/pci_io_cfg.h +++ b/src/arch/x86/include/arch/pci_io_cfg.h @@ -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); outl(0x80000000 | (addr & ~3), 0xCF8); - return inb(0xCFC + (addr & 3)); + return inb(0xCFC + (reg & 3)); } 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); outl(0x80000000 | (addr & ~3), 0xCF8); - return inw(0xCFC + (addr & 2)); + return inw(0xCFC + (reg & 2)); } 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); outl(0x80000000 | (addr & ~3), 0xCF8); - outb(value, 0xCFC + (addr & 3)); + outb(value, 0xCFC + (reg & 3)); } 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); outl(0x80000000 | (addr & ~3), 0xCF8); - outw(value, 0xCFC + (addr & 2)); + outw(value, 0xCFC + (reg & 2)); } static __always_inline -- cgit v1.2.3