Skip to content

Commit a27bf27

Browse files
LuBaoluwilldeacon
authored andcommitted
iommu: Add iommu_paging_domain_alloc() interface
Commit <17de3f5fdd35> ("iommu: Retire bus ops") removes iommu ops from bus. The iommu subsystem no longer relies on bus for operations. So the bus parameter in iommu_domain_alloc() is no longer relevant. Add a new interface named iommu_paging_domain_alloc(), which explicitly indicates the allocation of a paging domain for DMA managed by a kernel driver. The new interface takes a device pointer as its parameter, that better aligns with the current iommu subsystem. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 83a7eef commit a27bf27

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

drivers/iommu/iommu.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,6 +2016,10 @@ static int __iommu_domain_alloc_dev(struct device *dev, void *data)
20162016
return 0;
20172017
}
20182018

2019+
/*
2020+
* The iommu ops in bus has been retired. Do not use this interface in
2021+
* new drivers.
2022+
*/
20192023
struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus)
20202024
{
20212025
const struct iommu_ops *ops = NULL;
@@ -2032,6 +2036,22 @@ struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus)
20322036
}
20332037
EXPORT_SYMBOL_GPL(iommu_domain_alloc);
20342038

2039+
/**
2040+
* iommu_paging_domain_alloc() - Allocate a paging domain
2041+
* @dev: device for which the domain is allocated
2042+
*
2043+
* Allocate a paging domain which will be managed by a kernel driver. Return
2044+
* allocated domain if successful, or a ERR pointer for failure.
2045+
*/
2046+
struct iommu_domain *iommu_paging_domain_alloc(struct device *dev)
2047+
{
2048+
if (!dev_has_iommu(dev))
2049+
return ERR_PTR(-ENODEV);
2050+
2051+
return __iommu_domain_alloc(dev_iommu_ops(dev), dev, IOMMU_DOMAIN_UNMANAGED);
2052+
}
2053+
EXPORT_SYMBOL_GPL(iommu_paging_domain_alloc);
2054+
20352055
void iommu_domain_free(struct iommu_domain *domain)
20362056
{
20372057
if (domain->type == IOMMU_DOMAIN_SVA)

include/linux/iommu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ extern bool iommu_present(const struct bus_type *bus);
780780
extern bool device_iommu_capable(struct device *dev, enum iommu_cap cap);
781781
extern bool iommu_group_has_isolated_msi(struct iommu_group *group);
782782
extern struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus);
783+
struct iommu_domain *iommu_paging_domain_alloc(struct device *dev);
783784
extern void iommu_domain_free(struct iommu_domain *domain);
784785
extern int iommu_attach_device(struct iommu_domain *domain,
785786
struct device *dev);
@@ -1086,6 +1087,11 @@ static inline struct iommu_domain *iommu_domain_alloc(const struct bus_type *bus
10861087
return NULL;
10871088
}
10881089

1090+
static inline struct iommu_domain *iommu_paging_domain_alloc(struct device *dev)
1091+
{
1092+
return ERR_PTR(-ENODEV);
1093+
}
1094+
10891095
static inline void iommu_domain_free(struct iommu_domain *domain)
10901096
{
10911097
}

0 commit comments

Comments
 (0)