Skip to content

Commit bf3aed4

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu: Introduce explicit type for non-strict DMA domains
Promote the difference between strict and non-strict DMA domains from an internal detail to a distinct domain feature and type, to pave the road for exposing it through the sysfs default domain interface. Reviewed-by: Lu Baolu <[email protected]> Reviewed-by: Jean-Philippe Brucker <[email protected]> Signed-off-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/08cd2afaf6b63c58ad49acec3517c9b32c2bb946.1628682049.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <[email protected]>
1 parent a8e5f04 commit bf3aed4

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

drivers/iommu/dma-iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 dma_limit)
13191319
* The IOMMU core code allocates the default DMA domain, which the
13201320
* underlying IOMMU driver needs to support via the dma-iommu layer.
13211321
*/
1322-
if (domain->type == IOMMU_DOMAIN_DMA) {
1322+
if (iommu_is_dma_domain(domain)) {
13231323
if (iommu_dma_init_domain(domain, dma_base, dma_limit, dev))
13241324
goto out_err;
13251325
dev->dma_ops = &iommu_dma_ops;

drivers/iommu/iommu.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ static const char *iommu_domain_type_str(unsigned int t)
115115
case IOMMU_DOMAIN_UNMANAGED:
116116
return "Unmanaged";
117117
case IOMMU_DOMAIN_DMA:
118+
case IOMMU_DOMAIN_DMA_FQ:
118119
return "Translated";
119120
default:
120121
return "Unknown";
@@ -552,6 +553,9 @@ static ssize_t iommu_group_show_type(struct iommu_group *group,
552553
case IOMMU_DOMAIN_DMA:
553554
type = "DMA\n";
554555
break;
556+
case IOMMU_DOMAIN_DMA_FQ:
557+
type = "DMA-FQ\n";
558+
break;
555559
}
556560
}
557561
mutex_unlock(&group->mutex);
@@ -765,7 +769,7 @@ static int iommu_create_device_direct_mappings(struct iommu_group *group,
765769
unsigned long pg_size;
766770
int ret = 0;
767771

768-
if (!domain || domain->type != IOMMU_DOMAIN_DMA)
772+
if (!domain || !iommu_is_dma_domain(domain))
769773
return 0;
770774

771775
BUG_ON(!domain->pgsize_bitmap);
@@ -1948,7 +1952,7 @@ static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
19481952
domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap;
19491953

19501954
/* Temporarily avoid -EEXIST while drivers still get their own cookies */
1951-
if (type == IOMMU_DOMAIN_DMA && !domain->iova_cookie && iommu_get_dma_cookie(domain)) {
1955+
if (iommu_is_dma_domain(domain) && !domain->iova_cookie && iommu_get_dma_cookie(domain)) {
19521956
iommu_domain_free(domain);
19531957
domain = NULL;
19541958
}

include/linux/iommu.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct iommu_domain_geometry {
6161
#define __IOMMU_DOMAIN_DMA_API (1U << 1) /* Domain for use in DMA-API
6262
implementation */
6363
#define __IOMMU_DOMAIN_PT (1U << 2) /* Domain is identity mapped */
64+
#define __IOMMU_DOMAIN_DMA_FQ (1U << 3) /* DMA-API uses flush queue */
6465

6566
/*
6667
* This are the possible domain-types
@@ -73,12 +74,17 @@ struct iommu_domain_geometry {
7374
* IOMMU_DOMAIN_DMA - Internally used for DMA-API implementations.
7475
* This flag allows IOMMU drivers to implement
7576
* certain optimizations for these domains
77+
* IOMMU_DOMAIN_DMA_FQ - As above, but definitely using batched TLB
78+
* invalidation.
7679
*/
7780
#define IOMMU_DOMAIN_BLOCKED (0U)
7881
#define IOMMU_DOMAIN_IDENTITY (__IOMMU_DOMAIN_PT)
7982
#define IOMMU_DOMAIN_UNMANAGED (__IOMMU_DOMAIN_PAGING)
8083
#define IOMMU_DOMAIN_DMA (__IOMMU_DOMAIN_PAGING | \
8184
__IOMMU_DOMAIN_DMA_API)
85+
#define IOMMU_DOMAIN_DMA_FQ (__IOMMU_DOMAIN_PAGING | \
86+
__IOMMU_DOMAIN_DMA_API | \
87+
__IOMMU_DOMAIN_DMA_FQ)
8288

8389
struct iommu_domain {
8490
unsigned type;
@@ -90,6 +96,11 @@ struct iommu_domain {
9096
struct iommu_dma_cookie *iova_cookie;
9197
};
9298

99+
static inline bool iommu_is_dma_domain(struct iommu_domain *domain)
100+
{
101+
return domain->type & __IOMMU_DOMAIN_DMA_API;
102+
}
103+
93104
enum iommu_cap {
94105
IOMMU_CAP_CACHE_COHERENCY, /* IOMMU can enforce cache coherent DMA
95106
transactions */

0 commit comments

Comments
 (0)