[SeaBIOS] [PATCH v2 1/2] pci: factor out ioconfig_cmd()

Gerd Hoffmann posted 2 patches 9 weeks ago

[SeaBIOS] [PATCH v2 1/2] pci: factor out ioconfig_cmd()

Posted by Gerd Hoffmann 9 weeks ago
Add helper function to calculate PORT_PCI_CMD value from bdf + addr.

Signed-off-by: Gerd Hoffmann <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 9855badbc7da..7aca1e6bfa97 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));
 }
 
-- 
2.18.2
_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org