x86/pci: Convert pci_mmcfg_{read,write}() to use pci_sbdf_t

All callers now have an sbdf.  Pass it down directly, rather than splitting
into three parameters.

In turn this shows that bus and devfn could never be out of bounds, so drop
those checks too.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Teddy Astie <teddy.astie@vates.tech>
This commit is contained in:
Andrew Cooper committed 2026-09-09 18:07:32 +01:00
1 parent e1ddc74203
commit 04670075bc
4 files changed
+19 -23

No files matched your search

+1 -3
View File
@@ -331,9 +331,7 @@ static int cf_check mmcfg_intercept_write(
offset &= 0xfff;
if ( pci_conf_write_intercept(mmio_ctxt->sbdf.seg, mmio_ctxt->sbdf.bdf,
offset, bytes, p_data) >= 0 )
pci_mmcfg_write(mmio_ctxt->sbdf.seg, mmio_ctxt->sbdf.bus,
mmio_ctxt->sbdf.devfn, offset, bytes,
*(uint32_t *)p_data);
pci_mmcfg_write(mmio_ctxt->sbdf, offset, bytes, *(uint32_t *)p_data);
return X86EMUL_OKAY;
}
+8 -10
View File
@@ -55,19 +55,18 @@ static char __iomem *pci_dev_base(unsigned int seg, unsigned int bus, unsigned i
return addr + ((bus << 20) | (devfn << 12));
}
int pci_mmcfg_read(unsigned int seg, unsigned int bus,
unsigned int devfn, int reg, int len, u32 *value)
int pci_mmcfg_read(
pci_sbdf_t sbdf, unsigned int reg, unsigned int len, uint32_t *value)
{
char __iomem *addr;
/* Why do we have this when nobody checks it. How about a BUG()!? -AK */
if (unlikely((bus > 255) || (devfn > 255) ||
(reg + len > PCI_CFG_SPACE_EXP_SIZE))) {
if (unlikely(reg + len > PCI_CFG_SPACE_EXP_SIZE)) {
err: *value = -1;
return -EINVAL;
}
addr = pci_dev_base(seg, bus, devfn);
addr = pci_dev_base(sbdf.seg, sbdf.bus, sbdf.devfn);
if (!addr)
goto err;
@@ -86,17 +85,16 @@ err: *value = -1;
return 0;
}
int pci_mmcfg_write(unsigned int seg, unsigned int bus,
unsigned int devfn, int reg, int len, u32 value)
int pci_mmcfg_write(
pci_sbdf_t sbdf, unsigned int reg, unsigned int len, uint32_t value)
{
char __iomem *addr;
/* Why do we have this when nobody checks it. How about a BUG()!? -AK */
if (unlikely((bus > 255) || (devfn > 255) ||
(reg + len > PCI_CFG_SPACE_EXP_SIZE)))
if (unlikely(reg + len > PCI_CFG_SPACE_EXP_SIZE))
return -EINVAL;
addr = pci_dev_base(seg, bus, devfn);
addr = pci_dev_base(sbdf.seg, sbdf.bus, sbdf.devfn);
if (!addr)
return -EINVAL;
+6 -6
View File
@@ -17,7 +17,7 @@ uint8_t pci_conf_read8(pci_sbdf_t sbdf, unsigned int reg)
if ( sbdf.seg || reg > 255 )
{
pci_mmcfg_read(sbdf.seg, sbdf.bus, sbdf.devfn, reg, 1, &value);
pci_mmcfg_read(sbdf, reg, 1, &value);
return value;
}
@@ -30,7 +30,7 @@ uint16_t pci_conf_read16(pci_sbdf_t sbdf, unsigned int reg)
{
uint32_t value;
pci_mmcfg_read(sbdf.seg, sbdf.bus, sbdf.devfn, reg, 2, &value);
pci_mmcfg_read(sbdf, reg, 2, &value);
return value;
}
@@ -43,7 +43,7 @@ uint32_t pci_conf_read32(pci_sbdf_t sbdf, unsigned int reg)
{
uint32_t value;
pci_mmcfg_read(sbdf.seg, sbdf.bus, sbdf.devfn, reg, 4, &value);
pci_mmcfg_read(sbdf, reg, 4, &value);
return value;
}
@@ -53,7 +53,7 @@ uint32_t pci_conf_read32(pci_sbdf_t sbdf, unsigned int reg)
void pci_conf_write8(pci_sbdf_t sbdf, unsigned int reg, uint8_t data)
{
if ( sbdf.seg || reg > 255 )
pci_mmcfg_write(sbdf.seg, sbdf.bus, sbdf.devfn, reg, 1, data);
pci_mmcfg_write(sbdf, reg, 1, data);
else
pci_conf_write(PCI_CONF_ADDRESS(sbdf, reg), reg & 3, 1, data);
}
@@ -61,7 +61,7 @@ void pci_conf_write8(pci_sbdf_t sbdf, unsigned int reg, uint8_t data)
void pci_conf_write16(pci_sbdf_t sbdf, unsigned int reg, uint16_t data)
{
if ( sbdf.seg || reg > 255 || !IS_ALIGNED(reg, 2) )
pci_mmcfg_write(sbdf.seg, sbdf.bus, sbdf.devfn, reg, 2, data);
pci_mmcfg_write(sbdf, reg, 2, data);
else
pci_conf_write(PCI_CONF_ADDRESS(sbdf, reg), reg & 2, 2, data);
}
@@ -69,7 +69,7 @@ void pci_conf_write16(pci_sbdf_t sbdf, unsigned int reg, uint16_t data)
void pci_conf_write32(pci_sbdf_t sbdf, unsigned int reg, uint32_t data)
{
if ( sbdf.seg || reg > 255 || !IS_ALIGNED(reg, 4) )
pci_mmcfg_write(sbdf.seg, sbdf.bus, sbdf.devfn, reg, 4, data);
pci_mmcfg_write(sbdf, reg, 4, data);
else
pci_conf_write(PCI_CONF_ADDRESS(sbdf, reg), 0, 4, data);
}
+4 -4
View File
@@ -258,10 +258,10 @@ void pci_conf_write16(pci_sbdf_t sbdf, unsigned int reg, uint16_t data);
void pci_conf_write32(pci_sbdf_t sbdf, unsigned int reg, uint32_t data);
uint32_t pci_conf_read(uint32_t cf8, uint8_t offset, uint8_t bytes);
void pci_conf_write(uint32_t cf8, uint8_t offset, uint8_t bytes, uint32_t data);
int pci_mmcfg_read(unsigned int seg, unsigned int bus,
unsigned int devfn, int reg, int len, u32 *value);
int pci_mmcfg_write(unsigned int seg, unsigned int bus,
unsigned int devfn, int reg, int len, u32 value);
int pci_mmcfg_read(
pci_sbdf_t sbdf, unsigned int reg, unsigned int len, uint32_t *value);
int pci_mmcfg_write(
pci_sbdf_t sbdf, unsigned int reg, unsigned int len, uint32_t value);
unsigned int pci_find_cap_offset(pci_sbdf_t sbdf, unsigned int cap);
unsigned int pci_find_next_cap_ttl(pci_sbdf_t sbdf, unsigned int pos,
const unsigned int caps[], unsigned int n,
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.