iommu/amd: Consolidate irq domain getter
authorThomas Gleixner <tglx@linutronix.de>
Wed, 26 Aug 2020 11:16:38 +0000 (13:16 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Wed, 16 Sep 2020 14:52:29 +0000 (16:52 +0200)
The irq domain request mode is now indicated in irq_alloc_info::type.

Consolidate the two getter functions into one.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Joerg Roedel <jroedel@suse.de>
Link: https://lore.kernel.org/r/20200826112331.634777249@linutronix.de
drivers/iommu/amd/iommu.c

index b98b0ab..4d4045a 100644 (file)
@@ -3519,77 +3519,54 @@ static void irte_ga_clear_allocated(struct irq_remap_table *table, int index)
 
 static int get_devid(struct irq_alloc_info *info)
 {
-       int devid = -1;
-
        switch (info->type) {
        case X86_IRQ_ALLOC_TYPE_IOAPIC:
-               devid     = get_ioapic_devid(info->ioapic_id);
-               break;
+       case X86_IRQ_ALLOC_TYPE_IOAPIC_GET_PARENT:
+               return get_ioapic_devid(info->ioapic_id);
        case X86_IRQ_ALLOC_TYPE_HPET:
-               devid     = get_hpet_devid(info->hpet_id);
-               break;
+       case X86_IRQ_ALLOC_TYPE_HPET_GET_PARENT:
+               return get_hpet_devid(info->hpet_id);
        case X86_IRQ_ALLOC_TYPE_PCI_MSI:
        case X86_IRQ_ALLOC_TYPE_PCI_MSIX:
-               devid = get_device_id(&info->msi_dev->dev);
-               break;
+               return get_device_id(&info->msi_dev->dev);
        default:
-               BUG_ON(1);
-               break;
+               WARN_ON_ONCE(1);
+               return -1;
        }
-
-       return devid;
 }
 
-static struct irq_domain *get_ir_irq_domain(struct irq_alloc_info *info)
+static struct irq_domain *get_irq_domain_for_devid(struct irq_alloc_info *info,
+                                                  int devid)
 {
-       struct amd_iommu *iommu;
-       int devid;
+       struct amd_iommu *iommu = amd_iommu_rlookup_table[devid];
 
-       if (!info)
+       if (!iommu)
                return NULL;
 
        switch (info->type) {
        case X86_IRQ_ALLOC_TYPE_IOAPIC_GET_PARENT:
        case X86_IRQ_ALLOC_TYPE_HPET_GET_PARENT:
-               break;
+               return iommu->ir_domain;
+       case X86_IRQ_ALLOC_TYPE_PCI_MSI:
+       case X86_IRQ_ALLOC_TYPE_PCI_MSIX:
+               return iommu->msi_domain;
        default:
+               WARN_ON_ONCE(1);
                return NULL;
        }
-
-       devid = get_devid(info);
-       if (devid >= 0) {
-               iommu = amd_iommu_rlookup_table[devid];
-               if (iommu)
-                       return iommu->ir_domain;
-       }
-
-       return NULL;
 }
 
 static struct irq_domain *get_irq_domain(struct irq_alloc_info *info)
 {
-       struct amd_iommu *iommu;
        int devid;
 
        if (!info)
                return NULL;
 
-       switch (info->type) {
-       case X86_IRQ_ALLOC_TYPE_PCI_MSI:
-       case X86_IRQ_ALLOC_TYPE_PCI_MSIX:
-               devid = get_device_id(&info->msi_dev->dev);
-               if (devid < 0)
-                       return NULL;
-
-               iommu = amd_iommu_rlookup_table[devid];
-               if (iommu)
-                       return iommu->msi_domain;
-               break;
-       default:
-               break;
-       }
-
-       return NULL;
+       devid = get_devid(info);
+       if (devid < 0)
+               return NULL;
+       return get_irq_domain_for_devid(info, devid);
 }
 
 struct irq_remap_ops amd_iommu_irq_ops = {
@@ -3598,7 +3575,7 @@ struct irq_remap_ops amd_iommu_irq_ops = {
        .disable                = amd_iommu_disable,
        .reenable               = amd_iommu_reenable,
        .enable_faulting        = amd_iommu_enable_faulting,
-       .get_ir_irq_domain      = get_ir_irq_domain,
+       .get_ir_irq_domain      = get_irq_domain,
        .get_irq_domain         = get_irq_domain,
 };