diff options
author | Thierry Reding <treding@nvidia.com> | 2022-12-06 19:59:41 +0300 |
---|---|---|
committer | Ulf Hansson <ulf.hansson@linaro.org> | 2022-12-07 15:30:24 +0300 |
commit | 493c9b68d1d8765b2f8740a06c169e90a947159f (patch) | |
tree | 7ff31733deb00660e675cd1e46e69466b61d445b /include/linux/iommu.h | |
parent | 495b637f640b7f87ab42f3cc829e35ea76a1f3eb (diff) | |
download | linux-493c9b68d1d8765b2f8740a06c169e90a947159f.tar.xz |
iommu/tegra: Add tegra_dev_iommu_get_stream_id() helper
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>
Diffstat (limited to 'include/linux/iommu.h')
-rw-r--r-- | include/linux/iommu.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 20b592dec335..6f53ad74fa0d 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -1103,4 +1103,25 @@ static inline void iommu_dma_compose_msi_msg(struct msi_desc *desc, struct msi_m #endif /* CONFIG_IOMMU_DMA */ +/* + * Newer generations of Tegra SoCs require devices' stream IDs to be directly programmed into + * some registers. These are always paired with a Tegra SMMU or ARM SMMU, for which the contents + * of the struct iommu_fwspec are known. Use this helper to formalize access to these internals. + */ +#define TEGRA_STREAM_ID_BYPASS 0x7f + +static inline bool tegra_dev_iommu_get_stream_id(struct device *dev, u32 *stream_id) +{ +#ifdef CONFIG_IOMMU_API + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + + if (fwspec && fwspec->num_ids == 1) { + *stream_id = fwspec->ids[0] & 0xffff; + return true; + } +#endif + + return false; +} + #endif /* __LINUX_IOMMU_H */ |