Skip to content

Commit 46983fc

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu: Pull IOVA cookie management into the core
Now that everyone has converged on iommu-dma for IOMMU_DOMAIN_DMA support, we can abandon the notion of drivers being responsible for the cookie type, and consolidate all the management into the core code. CC: Yong Wu <[email protected]> CC: Chunyan Zhang <[email protected]> CC: Maxime Ripard <[email protected]> Tested-by: Heiko Stuebner <[email protected]> Tested-by: Marek Szyprowski <[email protected]> Tested-by: Yoshihiro Shimoda <[email protected]> Reviewed-by: Jean-Philippe Brucker <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Signed-off-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/46a2c0e7419c7d1d931762dc7b6a69fa082d199a.1628682048.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <[email protected]>
1 parent 9eec3f9 commit 46983fc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

drivers/iommu/iommu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define pr_fmt(fmt) "iommu: " fmt
88

99
#include <linux/device.h>
10+
#include <linux/dma-iommu.h>
1011
#include <linux/kernel.h>
1112
#include <linux/bits.h>
1213
#include <linux/bug.h>
@@ -1946,6 +1947,11 @@ static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
19461947
/* Assume all sizes by default; the driver may override this later */
19471948
domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap;
19481949

1950+
/* Temporarily avoid -EEXIST while drivers still get their own cookies */
1951+
if (type == IOMMU_DOMAIN_DMA && !domain->iova_cookie && iommu_get_dma_cookie(domain)) {
1952+
iommu_domain_free(domain);
1953+
domain = NULL;
1954+
}
19491955
return domain;
19501956
}
19511957

@@ -1957,6 +1963,7 @@ EXPORT_SYMBOL_GPL(iommu_domain_alloc);
19571963

19581964
void iommu_domain_free(struct iommu_domain *domain)
19591965
{
1966+
iommu_put_dma_cookie(domain);
19601967
domain->ops->domain_free(domain);
19611968
}
19621969
EXPORT_SYMBOL_GPL(iommu_domain_free);

include/linux/iommu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct iommu_domain;
4040
struct notifier_block;
4141
struct iommu_sva;
4242
struct iommu_fault_event;
43+
struct iommu_dma_cookie;
4344

4445
/* iommu fault flags */
4546
#define IOMMU_FAULT_READ 0x0
@@ -86,7 +87,7 @@ struct iommu_domain {
8687
iommu_fault_handler_t handler;
8788
void *handler_token;
8889
struct iommu_domain_geometry geometry;
89-
void *iova_cookie;
90+
struct iommu_dma_cookie *iova_cookie;
9091
};
9192

9293
enum iommu_cap {

0 commit comments

Comments
 (0)