Skip to content

Commit 04d3a06

Browse files
committed
iommu/tegra: Add tegra_dev_iommu_get_stream_id() helper
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2144641 Conflicts: include/linux/iommu.h No backport of commit fa49364 "iommu/dma: Move public interfaces to linux/iommu.h" causes context conflict. commit 493c9b6 Author: Thierry Reding <treding@nvidia.com> Date: Tue, 6 Dec 2022 17:59:41 +0100 Access to the internals of struct iommu_fwspec by non-IOMMU drivers is discouraged. Many drivers for Tegra SoCs, however, need access to their IOMMU stream IDs so that they can be programmed into various hardware registers. Formalize this access into a common helper to make it easier to audit and maintain. Acked-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Thierry Reding <treding@nvidia.com> Link: https://lore.kernel.org/r/20221206165945.3551774-3-thierry.reding@gmail.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Mark Salter <msalter@redhat.com>
1 parent 70e4140 commit 04d3a06

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

include/linux/iommu.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,4 +1070,25 @@ void iommu_debugfs_setup(void);
10701070
static inline void iommu_debugfs_setup(void) {}
10711071
#endif
10721072

1073+
/*
1074+
* Newer generations of Tegra SoCs require devices' stream IDs to be directly programmed into
1075+
* some registers. These are always paired with a Tegra SMMU or ARM SMMU, for which the contents
1076+
* of the struct iommu_fwspec are known. Use this helper to formalize access to these internals.
1077+
*/
1078+
#define TEGRA_STREAM_ID_BYPASS 0x7f
1079+
1080+
static inline bool tegra_dev_iommu_get_stream_id(struct device *dev, u32 *stream_id)
1081+
{
1082+
#ifdef CONFIG_IOMMU_API
1083+
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
1084+
1085+
if (fwspec && fwspec->num_ids == 1) {
1086+
*stream_id = fwspec->ids[0] & 0xffff;
1087+
return true;
1088+
}
1089+
#endif
1090+
1091+
return false;
1092+
}
1093+
10731094
#endif /* __LINUX_IOMMU_H */

0 commit comments

Comments
 (0)