|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v3 10/18] vtd: Use pci_sbdf_t in acpi_parse_dev_scope()
Use a dedicated pci_sbdf_t struct that we update instead of recreating
one each time we need it.
Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
xen/drivers/passthrough/vtd/dmar.c | 90 ++++++++++++------------------
1 file changed, 36 insertions(+), 54 deletions(-)
diff --git a/xen/drivers/passthrough/vtd/dmar.c
b/xen/drivers/passthrough/vtd/dmar.c
index 8db9591a36..21649fa892 100644
--- a/xen/drivers/passthrough/vtd/dmar.c
+++ b/xen/drivers/passthrough/vtd/dmar.c
@@ -306,11 +306,11 @@ static int __init scope_device_count(const void *start,
const void *end)
static int __init acpi_parse_dev_scope(
const void *start, const void *end, struct dmar_scope *scope,
- int type, u16 seg)
+ int type, uint16_t seg)
{
struct acpi_ioapic_unit *acpi_ioapic_unit;
const struct acpi_dmar_device_scope *acpi_scope;
- u16 bus, sub_bus, sec_bus;
+ uint16_t sub_bus, sec_bus;
const struct acpi_dmar_pci_path *path;
struct acpi_drhd_unit *drhd = type == DMAR_TYPE ?
container_of(scope, struct acpi_drhd_unit, scope) : NULL;
@@ -322,7 +322,7 @@ static int __init acpi_parse_dev_scope(
if ( cnt > 0 )
{
- scope->devices = xzalloc_array(u16, cnt);
+ scope->devices = xzalloc_array(uint16_t, cnt);
if ( !scope->devices )
return -ENOMEM;
@@ -332,29 +332,28 @@ static int __init acpi_parse_dev_scope(
while ( start < end )
{
+ pci_sbdf_t dev_sbdf;
+
acpi_scope = start;
path = (const void *)(acpi_scope + 1);
depth = (acpi_scope->length - sizeof(*acpi_scope)) / sizeof(*path);
- bus = acpi_scope->bus;
+ dev_sbdf = PCI_SBDF(seg, acpi_scope->bus, path->dev, path->fn);
while ( --depth > 0 )
{
- bus = pci_conf_read8(PCI_SBDF(seg, bus, path->dev, path->fn),
- PCI_SECONDARY_BUS);
+ dev_sbdf.bus = pci_conf_read8(dev_sbdf, PCI_SECONDARY_BUS);
path++;
+ dev_sbdf.devfn = PCI_DEVFN(path->dev, path->fn);
}
switch ( acpi_scope->entry_type )
{
case ACPI_DMAR_SCOPE_TYPE_BRIDGE:
- sec_bus = pci_conf_read8(PCI_SBDF(seg, bus, path->dev, path->fn),
- PCI_SECONDARY_BUS);
- sub_bus = pci_conf_read8(PCI_SBDF(seg, bus, path->dev, path->fn),
- PCI_SUBORDINATE_BUS);
+ sec_bus = pci_conf_read8(dev_sbdf, PCI_SECONDARY_BUS);
+ sub_bus = pci_conf_read8(dev_sbdf, PCI_SUBORDINATE_BUS);
if ( iommu_verbose )
printk(VTDPREFIX " bridge: %pp start=%x sec=%x sub=%x\n",
- &PCI_SBDF(seg, bus, path->dev, path->fn),
- acpi_scope->bus, sec_bus, sub_bus);
+ &dev_sbdf, acpi_scope->bus, sec_bus, sub_bus);
dmar_scope_add_buses(scope, sec_bus, sub_bus);
gfx_only = false;
@@ -362,8 +361,7 @@ static int __init acpi_parse_dev_scope(
case ACPI_DMAR_SCOPE_TYPE_HPET:
if ( iommu_verbose )
- printk(VTDPREFIX " MSI HPET: %pp\n",
- &PCI_SBDF(seg, bus, path->dev, path->fn));
+ printk(VTDPREFIX " MSI HPET: %pp\n", &dev_sbdf);
if ( drhd )
{
@@ -374,9 +372,7 @@ static int __init acpi_parse_dev_scope(
if ( !acpi_hpet_unit )
goto out;
acpi_hpet_unit->id = acpi_scope->enumeration_id;
- acpi_hpet_unit->bus = bus;
- acpi_hpet_unit->dev = path->dev;
- acpi_hpet_unit->func = path->fn;
+ acpi_hpet_unit->bdf = dev_sbdf.bdf;
list_add(&acpi_hpet_unit->list, &drhd->hpet_list);
gfx_only = false;
@@ -386,17 +382,14 @@ static int __init acpi_parse_dev_scope(
case ACPI_DMAR_SCOPE_TYPE_ENDPOINT:
if ( iommu_verbose )
- printk(VTDPREFIX " endpoint: %pp\n",
- &PCI_SBDF(seg, bus, path->dev, path->fn));
+ printk(VTDPREFIX " endpoint: %pp\n", &dev_sbdf);
- if ( drhd && pci_device_detect(PCI_SBDF(seg, bus, path->dev,
- path->fn)) )
+ if ( drhd && pci_device_detect(dev_sbdf) )
{
- if ( pci_conf_read8(PCI_SBDF(seg, bus, path->dev, path->fn),
- PCI_CLASS_DEVICE + 1) != 0x03
- /* PCI_BASE_CLASS_DISPLAY */ )
+ if ( pci_conf_read8(dev_sbdf, PCI_CLASS_DEVICE + 1) !=
+ 0x03 /* PCI_BASE_CLASS_DISPLAY */ )
gfx_only = false;
- else if ( !seg && !bus && path->dev == 2 && !path->fn )
+ else if ( dev_sbdf.sbdf == PCI_SBDF(0, 0, 2, 0).sbdf )
igd_drhd_address = drhd->address;
}
@@ -404,8 +397,7 @@ static int __init acpi_parse_dev_scope(
case ACPI_DMAR_SCOPE_TYPE_IOAPIC:
if ( iommu_verbose )
- printk(VTDPREFIX " IOAPIC: %pp\n",
- &PCI_SBDF(seg, bus, path->dev, path->fn));
+ printk(VTDPREFIX " IOAPIC: %pp\n", &dev_sbdf);
if ( drhd )
{
@@ -414,9 +406,7 @@ static int __init acpi_parse_dev_scope(
if ( !acpi_ioapic_unit )
goto out;
acpi_ioapic_unit->apic_id = acpi_scope->enumeration_id;
- acpi_ioapic_unit->ioapic.bdf.bus = bus;
- acpi_ioapic_unit->ioapic.bdf.dev = path->dev;
- acpi_ioapic_unit->ioapic.bdf.func = path->fn;
+ acpi_ioapic_unit->ioapic.info = dev_sbdf.bdf;
list_add(&acpi_ioapic_unit->list, &drhd->ioapic_list);
gfx_only = false;
@@ -432,7 +422,7 @@ static int __init acpi_parse_dev_scope(
gfx_only = false;
continue;
}
- scope->devices[didx++] = PCI_BDF(bus, path->dev, path->fn);
+ scope->devices[didx++] = dev_sbdf.bdf;
start += acpi_scope->length;
}
@@ -516,7 +506,6 @@ acpi_parse_one_drhd(struct acpi_dmar_header *header)
acpi_register_drhd_unit(dmaru);
else
{
- u8 b, d, f;
unsigned int i = 0;
union {
const void *raw;
@@ -530,18 +519,16 @@ acpi_parse_one_drhd(struct acpi_dmar_header *header)
for ( p.raw = dev_scope_start; i < dmaru->scope.devices_cnt;
i++, p.raw += p.scope->length )
{
+ pci_sbdf_t sbdf = PCI_SBDF(drhd->segment, dmaru->scope.devices[i]);
+
if ( p.scope->entry_type == ACPI_DMAR_SCOPE_TYPE_IOAPIC ||
p.scope->entry_type == ACPI_DMAR_SCOPE_TYPE_HPET )
continue;
- b = PCI_BUS(dmaru->scope.devices[i]);
- d = PCI_SLOT(dmaru->scope.devices[i]);
- f = PCI_FUNC(dmaru->scope.devices[i]);
-
- if ( !pci_device_detect(PCI_SBDF(drhd->segment, b, d, f)) )
+ if ( !pci_device_detect(sbdf) )
printk(XENLOG_WARNING VTDPREFIX
" Non-existent device (%pp) in this DRHD's scope!\n",
- &PCI_SBDF(drhd->segment, b, d, f));
+ &sbdf);
}
acpi_register_drhd_unit(dmaru);
@@ -570,17 +557,14 @@ static int __init register_one_rmrr(struct acpi_rmrr_unit
*rmrru)
for ( ; i < rmrru->scope.devices_cnt; i++ )
{
- u8 b = PCI_BUS(rmrru->scope.devices[i]);
- u8 d = PCI_SLOT(rmrru->scope.devices[i]);
- u8 f = PCI_FUNC(rmrru->scope.devices[i]);
+ pci_sbdf_t sbdf = PCI_SBDF(rmrru->segment, rmrru->scope.devices[i]);
- if ( pci_device_detect(PCI_SBDF(rmrru->segment, b, d, f)) == 0 )
+ if ( pci_device_detect(sbdf) == 0 )
{
dprintk(XENLOG_WARNING VTDPREFIX,
" Non-existent device (%pp) is reported"
" in RMRR [%"PRIx64", %"PRIx64"]'s scope!\n",
- &PCI_SBDF(rmrru->segment, b, d, f),
- rmrru->base_address, rmrru->end_address);
+ &sbdf, rmrru->base_address, rmrru->end_address);
ignore = true;
}
else
@@ -764,15 +748,13 @@ static int __init register_one_satc(struct acpi_satc_unit
*satcu)
for ( ; i < satcu->scope.devices_cnt; i++ )
{
- uint8_t b = PCI_BUS(satcu->scope.devices[i]);
- uint8_t d = PCI_SLOT(satcu->scope.devices[i]);
- uint8_t f = PCI_FUNC(satcu->scope.devices[i]);
+ pci_sbdf_t sbdf = PCI_SBDF(satcu->segment, satcu->scope.devices[i]);
- if ( !pci_device_detect(PCI_SBDF(satcu->segment, b, d, f)) )
+ if ( !pci_device_detect(sbdf) )
{
dprintk(XENLOG_WARNING VTDPREFIX,
" Non-existent device (%pp) is reported in SATC scope!\n",
- &PCI_SBDF(satcu->segment, b, d, f));
+ &sbdf);
ignore = true;
}
else
@@ -1195,8 +1177,9 @@ int cf_check intel_iommu_get_reserved_device_memory(
static int __init cf_check parse_rmrr_param(const char *str)
{
const char *s = str, *cur, *stmp;
- unsigned int seg, bus, dev, func, dev_count;
+ unsigned int dev_count;
unsigned long start, end;
+ pci_sbdf_t sbdf;
do {
if ( nr_rmrr >= MAX_USER_RMRR )
@@ -1233,7 +1216,7 @@ static int __init cf_check parse_rmrr_param(const char
*str)
do {
bool def_seg = false;
- stmp = parse_pci_seg(s + 1, &seg, &bus, &dev, &func, &def_seg);
+ stmp = parse_pci_seg(s + 1, &sbdf, &def_seg);
if ( !stmp )
return -EINVAL;
@@ -1242,12 +1225,11 @@ static int __init cf_check parse_rmrr_param(const char
*str)
* Segment will be replaced with one from first device.
*/
if ( user_rmrrs[nr_rmrr].dev_count && def_seg )
- seg = PCI_SEG(user_rmrrs[nr_rmrr].sbdf[0]);
+ sbdf.seg = PCI_SEG(user_rmrrs[nr_rmrr].sbdf[0]);
/* Keep sbdf's even if they differ and later report an error. */
dev_count = user_rmrrs[nr_rmrr].dev_count;
- user_rmrrs[nr_rmrr].sbdf[dev_count] =
- PCI_SBDF(seg, bus, dev, func).sbdf;
+ user_rmrrs[nr_rmrr].sbdf[dev_count] = sbdf.sbdf;
user_rmrrs[nr_rmrr].dev_count++;
s = stmp;
--
2.54.0
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |