From 2fff9f7cd4985ec2831c03666f59d195b45d5baa Mon Sep 17 00:00:00 2001 From: Venkata Rao Kakani Date: Mon, 16 Oct 2023 12:37:39 +0530 Subject: [PATCH] ANDROID: vendor hooks: Enable Vendor hook to register smmu driver to dedicated iommu bus defined by vendor. Current implementation of iommu busses driver has temporarily enforce global restriction to a single driver. This was already the de-facto behaviour, since any possible combination of existing drivers would compete for at least the PCI or platform bus. Due to this restriction we are not able to probe SMMU v3 driver for PCI bus. There is an ongoing work in upstream(https://lore.kernel.org/linux-iommu/cover.1696253096.git.robin.murphy@arm.com/#t) to fix this but we can't backport now as still review in progress. However, Some of our targets have both SMMU v2 (used by all peripherals except PCIe) and SMMU v3 (PCie) and they are expected to co-exit in current kernel version. To cater this requirement, we have implemented a vendor hook, which will skip the pci bus probe for smmuv2 and in smmuv3 skips all iommu buses execept pcie bus. Bug: 305648820 Signed-off-by: Venkata Rao Kakani Change-Id: I9304962a7fc7afad93295cc08b3c68f8e340ffe8 --- drivers/android/vendor_hooks.c | 1 + drivers/iommu/iommu.c | 9 ++++++++- include/trace/hooks/iommu.h | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 0e9014adf5f6..c7b6b1553b30 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -343,3 +343,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_alloc_pages_may_oom_exit); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_vmscan_kswapd_done); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_compaction_begin); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mm_compaction_end); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_bus_iommu_probe); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index fc7286d801db..eebba280512f 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "dma-iommu.h" @@ -223,7 +224,8 @@ int iommu_device_register(struct iommu_device *iommu, * already the de-facto behaviour, since any possible combination of * existing drivers would compete for at least the PCI or platform bus. */ - if (iommu_buses[0]->iommu_ops && iommu_buses[0]->iommu_ops != ops) + if (iommu_buses[0]->iommu_ops && iommu_buses[0]->iommu_ops != ops + && !trace_android_vh_bus_iommu_probe_enabled()) return -EBUSY; iommu->ops = ops; @@ -235,6 +237,11 @@ int iommu_device_register(struct iommu_device *iommu, spin_unlock(&iommu_device_lock); for (int i = 0; i < ARRAY_SIZE(iommu_buses) && !err; i++) { + bool skip = false; + + trace_android_vh_bus_iommu_probe(iommu, iommu_buses[i], &skip); + if (skip) + continue; iommu_buses[i]->iommu_ops = ops; err = bus_iommu_probe(iommu_buses[i]); } diff --git a/include/trace/hooks/iommu.h b/include/trace/hooks/iommu.h index d36446f0dd40..604dbf00cf6a 100644 --- a/include/trace/hooks/iommu.h +++ b/include/trace/hooks/iommu.h @@ -15,6 +15,7 @@ DECLARE_RESTRICTED_HOOK(android_rvh_iommu_setup_dma_ops, struct iova_domain; struct iova; +struct iommu_device; DECLARE_RESTRICTED_HOOK(android_rvh_iommu_alloc_insert_iova, TP_PROTO(struct iova_domain *iovad, unsigned long size, @@ -40,6 +41,10 @@ DECLARE_RESTRICTED_HOOK(android_rvh_iommu_limit_align_shift, unsigned long *shift), TP_ARGS(iovad, size, shift), 1); +DECLARE_HOOK(android_vh_bus_iommu_probe, + TP_PROTO(struct iommu_device *iommu, struct bus_type *bus, bool *skip), + TP_ARGS(iommu, bus, skip)); + #endif /* _TRACE_HOOK_IOMMU_H */ /* This part must be outside protection */