From 63a44aff7a6a2303ff1c03b6bfcfa6477943e60d Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 23 Mar 2020 15:59:10 +0100 Subject: pci: factor out ioconfig_cmd() Add helper function to calculate PORT_PCI_CMD value from bdf + addr. Signed-off-by: Gerd Hoffmann Message-id: 20200323145911.22319-2-kraxel@redhat.com --- src/hw/pci.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/hw/pci.c b/src/hw/pci.c index 9855badb..7aca1e6b 100644 --- a/src/hw/pci.c +++ b/src/hw/pci.c @@ -14,39 +14,44 @@ #define PORT_PCI_CMD 0x0cf8 #define PORT_PCI_DATA 0x0cfc +static u32 ioconfig_cmd(u16 bdf, u32 addr) +{ + return 0x80000000 | (bdf << 8) | (addr & 0xfc); +} + void pci_config_writel(u16 bdf, u32 addr, u32 val) { - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); + outl(ioconfig_cmd(bdf, addr), PORT_PCI_CMD); outl(val, PORT_PCI_DATA); } void pci_config_writew(u16 bdf, u32 addr, u16 val) { - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); + outl(ioconfig_cmd(bdf, addr), PORT_PCI_CMD); outw(val, PORT_PCI_DATA + (addr & 2)); } void pci_config_writeb(u16 bdf, u32 addr, u8 val) { - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); + outl(ioconfig_cmd(bdf, addr), PORT_PCI_CMD); outb(val, PORT_PCI_DATA + (addr & 3)); } u32 pci_config_readl(u16 bdf, u32 addr) { - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); + outl(ioconfig_cmd(bdf, addr), PORT_PCI_CMD); return inl(PORT_PCI_DATA); } u16 pci_config_readw(u16 bdf, u32 addr) { - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); + outl(ioconfig_cmd(bdf, addr), PORT_PCI_CMD); return inw(PORT_PCI_DATA + (addr & 2)); } u8 pci_config_readb(u16 bdf, u32 addr) { - outl(0x80000000 | (bdf << 8) | (addr & 0xfc), PORT_PCI_CMD); + outl(ioconfig_cmd(bdf, addr), PORT_PCI_CMD); return inb(PORT_PCI_DATA + (addr & 3)); } -- cgit