From: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>

To allow IOMMU rlookup using both PCI segment and device ID.

Co-developed-by: Vasant Hegde <vasant.he...@amd.com>
Signed-off-by: Vasant Hegde <vasant.he...@amd.com>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>
---
 drivers/iommu/amd/iommu.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index cc200bfaa8c4..c3941e342fb2 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -3241,8 +3241,9 @@ static int irq_remapping_alloc(struct irq_domain *domain, 
unsigned int virq,
        struct irq_alloc_info *info = arg;
        struct irq_data *irq_data;
        struct amd_ir_data *data = NULL;
+       struct amd_iommu *iommu;
        struct irq_cfg *cfg;
-       int i, ret, devid;
+       int i, ret, devid, seg, sbdf;
        int index;
 
        if (!info)
@@ -3258,8 +3259,14 @@ static int irq_remapping_alloc(struct irq_domain 
*domain, unsigned int virq,
        if (info->type == X86_IRQ_ALLOC_TYPE_PCI_MSI)
                info->flags &= ~X86_IRQ_ALLOC_CONTIGUOUS_VECTORS;
 
-       devid = get_devid(info);
-       if (devid < 0)
+       sbdf = get_devid(info);
+       if (sbdf < 0)
+               return -EINVAL;
+
+       seg = sbdf >> 16;
+       devid = sbdf & 0xffff;
+       iommu = __rlookup_amd_iommu(seg, devid);
+       if (!iommu)
                return -EINVAL;
 
        ret = irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, arg);
@@ -3268,7 +3275,6 @@ static int irq_remapping_alloc(struct irq_domain *domain, 
unsigned int virq,
 
        if (info->type == X86_IRQ_ALLOC_TYPE_IOAPIC) {
                struct irq_remap_table *table;
-               struct amd_iommu *iommu;
 
                table = alloc_irq_table(devid, NULL);
                if (table) {
@@ -3278,7 +3284,6 @@ static int irq_remapping_alloc(struct irq_domain *domain, 
unsigned int virq,
                                 * interrupts.
                                 */
                                table->min_index = 32;
-                               iommu = amd_iommu_rlookup_table[devid];
                                for (i = 0; i < 32; ++i)
                                        iommu->irte_ops->set_allocated(table, 
i);
                        }
-- 
2.27.0

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to