Commit 0217ed5a authored by Vasant Hegde's avatar Vasant Hegde Committed by Joerg Roedel
Browse files

iommu/amd: Convert to use per PCI segment irq_lookup_table

parent ec12dd13
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -445,8 +445,6 @@ struct irq_remap_table {
	u32 *table;
};

extern struct irq_remap_table **irq_lookup_table;

/* Interrupt remapping feature used? */
extern bool amd_iommu_irq_remap;

+0 −19
Original line number Diff line number Diff line
@@ -206,12 +206,6 @@ u16 *amd_iommu_alias_table;
 */
struct amd_iommu **amd_iommu_rlookup_table;

/*
 * This table is used to find the irq remapping table for a given device id
 * quickly.
 */
struct irq_remap_table **irq_lookup_table;

/*
 * AMD IOMMU allows up to 2^16 different protection domains. This is a bitmap
 * to know which ones are already in use.
@@ -2789,11 +2783,6 @@ static struct syscore_ops amd_iommu_syscore_ops = {

static void __init free_iommu_resources(void)
{
	kmemleak_free(irq_lookup_table);
	free_pages((unsigned long)irq_lookup_table,
		   get_order(rlookup_table_size));
	irq_lookup_table = NULL;

	kmem_cache_destroy(amd_iommu_irq_cache);
	amd_iommu_irq_cache = NULL;

@@ -3014,14 +3003,6 @@ static int __init early_amd_iommu_init(void)
			if (alloc_irq_lookup_table(pci_seg))
				goto out;
		}

		irq_lookup_table = (void *)__get_free_pages(
				GFP_KERNEL | __GFP_ZERO,
				get_order(rlookup_table_size));
		kmemleak_alloc(irq_lookup_table, rlookup_table_size,
			       1, GFP_KERNEL);
		if (!irq_lookup_table)
			goto out;
	}

	ret = init_memory_definitions(ivrs_base);
+23 −13
Original line number Diff line number Diff line
@@ -2732,16 +2732,18 @@ static void set_dte_irq_entry(u16 devid, struct irq_remap_table *table)
	amd_iommu_dev_table[devid].data[2] = dte;
}

static struct irq_remap_table *get_irq_table(u16 devid)
static struct irq_remap_table *get_irq_table(struct amd_iommu *iommu, u16 devid)
{
	struct irq_remap_table *table;
	struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg;

	if (WARN_ONCE(!amd_iommu_rlookup_table[devid],
		      "%s: no iommu for devid %x\n", __func__, devid))
		return NULL;

	table = irq_lookup_table[devid];
	if (WARN_ONCE(!table, "%s: no table for devid %x\n", __func__, devid))
	table = pci_seg->irq_lookup_table[devid];
	if (WARN_ONCE(!table, "%s: no table for devid %x:%x\n",
		      __func__, pci_seg->id, devid))
		return NULL;

	return table;
@@ -2774,7 +2776,9 @@ static struct irq_remap_table *__alloc_irq_table(void)
static void set_remap_table_entry(struct amd_iommu *iommu, u16 devid,
				  struct irq_remap_table *table)
{
	irq_lookup_table[devid] = table;
	struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg;

	pci_seg->irq_lookup_table[devid] = table;
	set_dte_irq_entry(devid, table);
	iommu_flush_dte(iommu, devid);
}
@@ -2783,8 +2787,14 @@ static int set_remap_table_entry_alias(struct pci_dev *pdev, u16 alias,
				       void *data)
{
	struct irq_remap_table *table = data;
	struct amd_iommu_pci_seg *pci_seg;
	struct amd_iommu *iommu = rlookup_amd_iommu(&pdev->dev);

	irq_lookup_table[alias] = table;
	if (!iommu)
		return -EINVAL;

	pci_seg = iommu->pci_seg;
	pci_seg->irq_lookup_table[alias] = table;
	set_dte_irq_entry(alias, table);

	iommu_flush_dte(amd_iommu_rlookup_table[alias], alias);
@@ -2808,12 +2818,12 @@ static struct irq_remap_table *alloc_irq_table(u16 devid, struct pci_dev *pdev)
		goto out_unlock;

	pci_seg = iommu->pci_seg;
	table = irq_lookup_table[devid];
	table = pci_seg->irq_lookup_table[devid];
	if (table)
		goto out_unlock;

	alias = pci_seg->alias_table[devid];
	table = irq_lookup_table[alias];
	table = pci_seg->irq_lookup_table[alias];
	if (table) {
		set_remap_table_entry(iommu, devid, table);
		goto out_wait;
@@ -2827,11 +2837,11 @@ static struct irq_remap_table *alloc_irq_table(u16 devid, struct pci_dev *pdev)

	spin_lock_irqsave(&iommu_table_lock, flags);

	table = irq_lookup_table[devid];
	table = pci_seg->irq_lookup_table[devid];
	if (table)
		goto out_unlock;

	table = irq_lookup_table[alias];
	table = pci_seg->irq_lookup_table[alias];
	if (table) {
		set_remap_table_entry(iommu, devid, table);
		goto out_wait;
@@ -2925,7 +2935,7 @@ static int modify_irte_ga(u16 devid, int index, struct irte_ga *irte,
	if (iommu == NULL)
		return -EINVAL;

	table = get_irq_table(devid);
	table = get_irq_table(iommu, devid);
	if (!table)
		return -ENOMEM;

@@ -2966,7 +2976,7 @@ static int modify_irte(u16 devid, int index, union irte *irte)
	if (iommu == NULL)
		return -EINVAL;

	table = get_irq_table(devid);
	table = get_irq_table(iommu, devid);
	if (!table)
		return -ENOMEM;

@@ -2990,7 +3000,7 @@ static void free_irte(u16 devid, int index)
	if (iommu == NULL)
		return;

	table = get_irq_table(devid);
	table = get_irq_table(iommu, devid);
	if (!table)
		return;

@@ -3625,7 +3635,7 @@ int amd_iommu_update_ga(int cpu, bool is_run, void *data)
	if (!iommu)
		return -ENODEV;

	table = get_irq_table(devid);
	table = get_irq_table(iommu, devid);
	if (!table)
		return -ENODEV;