Skip to content

Commit ed36d04

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu: Introduce device_iommu_capable()
iommu_capable() only really works for systems where all IOMMU instances are completely homogeneous, and all devices are IOMMU-mapped. Implement the new variant which will be able to give a more accurate answer for whichever device the caller is actually interested in, and even more so once all the external users have been converted and we can reliably pass the device pointer through the internal driver interface too. Signed-off-by: Robin Murphy <robin.murphy@arm.com> Link: https://lore.kernel.org/r/8407eb9586677995b7a9fd70d0fd82d85929a9bb.1650878781.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent f316ba0 commit ed36d04

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

drivers/iommu/iommu.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,29 @@ bool iommu_present(struct bus_type *bus)
19061906
}
19071907
EXPORT_SYMBOL_GPL(iommu_present);
19081908

1909+
/**
1910+
* device_iommu_capable() - check for a general IOMMU capability
1911+
* @dev: device to which the capability would be relevant, if available
1912+
* @cap: IOMMU capability
1913+
*
1914+
* Return: true if an IOMMU is present and supports the given capability
1915+
* for the given device, otherwise false.
1916+
*/
1917+
bool device_iommu_capable(struct device *dev, enum iommu_cap cap)
1918+
{
1919+
const struct iommu_ops *ops;
1920+
1921+
if (!dev->iommu || !dev->iommu->iommu_dev)
1922+
return false;
1923+
1924+
ops = dev_iommu_ops(dev);
1925+
if (!ops->capable)
1926+
return false;
1927+
1928+
return ops->capable(cap);
1929+
}
1930+
EXPORT_SYMBOL_GPL(device_iommu_capable);
1931+
19091932
bool iommu_capable(struct bus_type *bus, enum iommu_cap cap)
19101933
{
19111934
if (!bus->iommu_ops || !bus->iommu_ops->capable)

include/linux/iommu.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ static inline const struct iommu_ops *dev_iommu_ops(struct device *dev)
417417
extern int bus_set_iommu(struct bus_type *bus, const struct iommu_ops *ops);
418418
extern int bus_iommu_probe(struct bus_type *bus);
419419
extern bool iommu_present(struct bus_type *bus);
420+
extern bool device_iommu_capable(struct device *dev, enum iommu_cap cap);
420421
extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap);
421422
extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
422423
extern struct iommu_group *iommu_group_get_by_id(int id);
@@ -689,6 +690,11 @@ static inline bool iommu_present(struct bus_type *bus)
689690
return false;
690691
}
691692

693+
static inline bool device_iommu_capable(struct device *dev, enum iommu_cap cap)
694+
{
695+
return false;
696+
}
697+
692698
static inline bool iommu_capable(struct bus_type *bus, enum iommu_cap cap)
693699
{
694700
return false;

0 commit comments

Comments
 (0)