summaryrefslogtreecommitdiff
path: root/src/arch/x86/include/arch/pci_io_cfg.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/x86/include/arch/pci_io_cfg.h')
-rw-r--r--src/arch/x86/include/arch/pci_io_cfg.h53
1 files changed, 17 insertions, 36 deletions
diff --git a/src/arch/x86/include/arch/pci_io_cfg.h b/src/arch/x86/include/arch/pci_io_cfg.h
index 8802cc0616..a09b488032 100644
--- a/src/arch/x86/include/arch/pci_io_cfg.h
+++ b/src/arch/x86/include/arch/pci_io_cfg.h
@@ -17,14 +17,20 @@
#include <arch/io.h>
static inline __attribute__((always_inline))
+unsigned int pci_io_encode_addr(pci_devfn_t dev, unsigned int where)
+{
+ if (IS_ENABLED(CONFIG_PCI_IO_CFG_EXT)) {
+ // seg == 0
+ return dev >> 4 | (where & 0xff) | ((where & 0xf00) << 16);
+ } else {
+ return dev >> 4 | where;
+ }
+}
+
+static inline __attribute__((always_inline))
uint8_t pci_io_read_config8(pci_devfn_t dev, unsigned int where)
{
- unsigned int addr;
-#if !CONFIG_PCI_IO_CFG_EXT
- addr = (dev>>4) | where;
-#else
- addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16); //seg == 0
-#endif
+ unsigned int addr = pci_io_encode_addr(dev, where);
outl(0x80000000 | (addr & ~3), 0xCF8);
return inb(0xCFC + (addr & 3));
}
@@ -32,12 +38,7 @@ uint8_t pci_io_read_config8(pci_devfn_t dev, unsigned int where)
static inline __attribute__((always_inline))
uint16_t pci_io_read_config16(pci_devfn_t dev, unsigned int where)
{
- unsigned int addr;
-#if !CONFIG_PCI_IO_CFG_EXT
- addr = (dev>>4) | where;
-#else
- addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16);
-#endif
+ unsigned int addr = pci_io_encode_addr(dev, where);
outl(0x80000000 | (addr & ~3), 0xCF8);
return inw(0xCFC + (addr & 2));
}
@@ -45,12 +46,7 @@ uint16_t pci_io_read_config16(pci_devfn_t dev, unsigned int where)
static inline __attribute__((always_inline))
uint32_t pci_io_read_config32(pci_devfn_t dev, unsigned int where)
{
- unsigned int addr;
-#if !CONFIG_PCI_IO_CFG_EXT
- addr = (dev>>4) | where;
-#else
- addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16);
-#endif
+ unsigned int addr = pci_io_encode_addr(dev, where);
outl(0x80000000 | (addr & ~3), 0xCF8);
return inl(0xCFC);
}
@@ -58,12 +54,7 @@ uint32_t pci_io_read_config32(pci_devfn_t dev, unsigned int where)
static inline __attribute__((always_inline))
void pci_io_write_config8(pci_devfn_t dev, unsigned int where, uint8_t value)
{
- unsigned int addr;
-#if !CONFIG_PCI_IO_CFG_EXT
- addr = (dev>>4) | where;
-#else
- addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16);
-#endif
+ unsigned int addr = pci_io_encode_addr(dev, where);
outl(0x80000000 | (addr & ~3), 0xCF8);
outb(value, 0xCFC + (addr & 3));
}
@@ -71,12 +62,7 @@ void pci_io_write_config8(pci_devfn_t dev, unsigned int where, uint8_t value)
static inline __attribute__((always_inline))
void pci_io_write_config16(pci_devfn_t dev, unsigned int where, uint16_t value)
{
- unsigned int addr;
-#if !CONFIG_PCI_IO_CFG_EXT
- addr = (dev>>4) | where;
-#else
- addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16);
-#endif
+ unsigned int addr = pci_io_encode_addr(dev, where);
outl(0x80000000 | (addr & ~3), 0xCF8);
outw(value, 0xCFC + (addr & 2));
}
@@ -84,12 +70,7 @@ void pci_io_write_config16(pci_devfn_t dev, unsigned int where, uint16_t value)
static inline __attribute__((always_inline))
void pci_io_write_config32(pci_devfn_t dev, unsigned int where, uint32_t value)
{
- unsigned int addr;
-#if !CONFIG_PCI_IO_CFG_EXT
- addr = (dev>>4) | where;
-#else
- addr = (dev>>4) | (where & 0xff) | ((where & 0xf00)<<16);
-#endif
+ unsigned int addr = pci_io_encode_addr(dev, where);
outl(0x80000000 | (addr & ~3), 0xCF8);
outl(value, 0xCFC);
}