aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iommu/amd_iommu.c
diff options
context:
space:
mode:
authorJoerg Roedel <jroedel@suse.de>2016-07-05 11:54:04 +0200
committerJoerg Roedel <jroedel@suse.de>2016-07-13 12:46:05 +0200
commit307d5851ef74c6c06a68f50302bf19809966d345 (patch)
treeb7bcf2ffdd87fa71e3b493f2963708b870889c36 /drivers/iommu/amd_iommu.c
parentiommu/amd: Select IOMMU_IOVA for AMD IOMMU (diff)
downloadlinux-dev-307d5851ef74c6c06a68f50302bf19809966d345.tar.xz
linux-dev-307d5851ef74c6c06a68f50302bf19809966d345.zip
iommu/amd: Allocate iova_domain for dma_ops_domain
Use it later for allocating the IO virtual addresses. Signed-off-by: Joerg Roedel <jroedel@suse.de>
Diffstat (limited to 'drivers/iommu/amd_iommu.c')
-rw-r--r--drivers/iommu/amd_iommu.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index b938a4ac3a37..e7825b25c62f 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -39,6 +39,7 @@
#include <linux/dma-contiguous.h>
#include <linux/irqdomain.h>
#include <linux/percpu.h>
+#include <linux/iova.h>
#include <asm/irq_remapping.h>
#include <asm/io_apic.h>
#include <asm/apic.h>
@@ -57,6 +58,11 @@
#define LOOP_TIMEOUT 100000
+/* IO virtual address start page frame number */
+#define IOVA_START_PFN (1)
+#define IOVA_PFN(addr) ((addr) >> PAGE_SHIFT)
+#define DMA_32BIT_PFN IOVA_PFN(DMA_BIT_MASK(32))
+
/*
* This bitmap is used to advertise the page sizes our hardware support
* to the IOMMU core, which will then use this information to split
@@ -158,6 +164,9 @@ struct dma_ops_domain {
/* address space relevant data */
struct aperture_range *aperture[APERTURE_MAX_RANGES];
+
+ /* IOVA RB-Tree */
+ struct iova_domain iovad;
};
/****************************************************************************
@@ -1969,6 +1978,8 @@ static void dma_ops_domain_free(struct dma_ops_domain *dom)
if (!dom)
return;
+ put_iova_domain(&dom->iovad);
+
free_percpu(dom->next_index);
del_domain_from_list(&dom->domain);
@@ -2044,6 +2055,9 @@ static struct dma_ops_domain *dma_ops_domain_alloc(void)
for_each_possible_cpu(cpu)
*per_cpu_ptr(dma_dom->next_index, cpu) = 0;
+ init_iova_domain(&dma_dom->iovad, PAGE_SIZE,
+ IOVA_START_PFN, DMA_32BIT_PFN);
+
return dma_dom;
free_dma_dom:
@@ -2951,7 +2965,11 @@ static struct dma_map_ops amd_iommu_dma_ops = {
int __init amd_iommu_init_api(void)
{
- int err = 0;
+ int ret, err = 0;
+
+ ret = iova_cache_get();
+ if (ret)
+ return ret;
err = bus_set_iommu(&pci_bus_type, &amd_iommu_ops);
if (err)