Skip to content

Commit c5b5da9

Browse files
committed
iommu/amd: Set up data structures for flush queue
The flush queue is the equivalent to defered-flushing in the Intel VT-d driver. This patch sets up the data structures needed for this. Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent bda350d commit c5b5da9

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

drivers/iommu/amd_iommu.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ LIST_HEAD(ioapic_map);
8989
LIST_HEAD(hpet_map);
9090
LIST_HEAD(acpihid_map);
9191

92+
#define FLUSH_QUEUE_SIZE 256
93+
94+
struct flush_queue_entry {
95+
unsigned long iova_pfn;
96+
unsigned long pages;
97+
struct dma_ops_domain *dma_dom;
98+
};
99+
100+
struct flush_queue {
101+
spinlock_t lock;
102+
unsigned next;
103+
struct flush_queue_entry *entries;
104+
};
105+
106+
DEFINE_PER_CPU(struct flush_queue, flush_queue);
107+
92108
/*
93109
* Domain for untranslated devices - only allocated
94110
* if iommu=pt passed on kernel cmd line.
@@ -2508,7 +2524,7 @@ static int init_reserved_iova_ranges(void)
25082524

25092525
int __init amd_iommu_init_api(void)
25102526
{
2511-
int ret, err = 0;
2527+
int ret, cpu, err = 0;
25122528

25132529
ret = iova_cache_get();
25142530
if (ret)
@@ -2518,6 +2534,18 @@ int __init amd_iommu_init_api(void)
25182534
if (ret)
25192535
return ret;
25202536

2537+
for_each_possible_cpu(cpu) {
2538+
struct flush_queue *queue = per_cpu_ptr(&flush_queue, cpu);
2539+
2540+
queue->entries = kzalloc(FLUSH_QUEUE_SIZE *
2541+
sizeof(*queue->entries),
2542+
GFP_KERNEL);
2543+
if (!queue->entries)
2544+
goto out_put_iova;
2545+
2546+
spin_lock_init(&queue->lock);
2547+
}
2548+
25212549
err = bus_set_iommu(&pci_bus_type, &amd_iommu_ops);
25222550
if (err)
25232551
return err;
@@ -2530,6 +2558,15 @@ int __init amd_iommu_init_api(void)
25302558
if (err)
25312559
return err;
25322560
return 0;
2561+
2562+
out_put_iova:
2563+
for_each_possible_cpu(cpu) {
2564+
struct flush_queue *queue = per_cpu_ptr(&flush_queue, cpu);
2565+
2566+
kfree(queue->entries);
2567+
}
2568+
2569+
return -ENOMEM;
25332570
}
25342571

25352572
int __init amd_iommu_init_dma_ops(void)
@@ -2552,6 +2589,7 @@ int __init amd_iommu_init_dma_ops(void)
25522589
pr_info("AMD-Vi: Lazy IO/TLB flushing enabled\n");
25532590

25542591
return 0;
2592+
25552593
}
25562594

25572595
/*****************************************************************************

0 commit comments

Comments
 (0)