public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: intel/ipu6: Fix dma mask for non-secure mode
@ 2025-04-09  9:58 Stanislaw Gruszka
  2025-04-09 10:20 ` Stanislaw Gruszka
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Stanislaw Gruszka @ 2025-04-09  9:58 UTC (permalink / raw)
  To: linux-media; +Cc: Sakari Ailus, Bingbu Cao

We use dma_get_mask() of auxdev device for calculate iova pfn limit.
This is always 32 bit mask as we do not initialize the mask (and we can
not do so, since dev->dev_mask is NULL anyways for auxdev).

Since we need 31 bit mask for non-secure mode create wrapper of
alloc_iova() which use mmu_info->aperture_end. This give us always
the correct mask.

Fixes: daabc5c64703 ("media: ipu6: not override the dma_ops of device in driver")
Cc: stable@vger.kernel.org
Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
---
 drivers/media/pci/intel/ipu6/ipu6-dma.c |  6 ++----
 drivers/media/pci/intel/ipu6/ipu6-dma.h |  7 -------
 drivers/media/pci/intel/ipu6/ipu6-mmu.c |  3 +--
 drivers/media/pci/intel/ipu6/ipu6-mmu.h | 13 +++++++++++++
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/media/pci/intel/ipu6/ipu6-dma.c b/drivers/media/pci/intel/ipu6/ipu6-dma.c
index b34022bad83b..a1d4ec35f802 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-dma.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-dma.c
@@ -171,8 +171,7 @@ void *ipu6_dma_alloc(struct ipu6_bus_device *sys, size_t size,
 	size = PAGE_ALIGN(size);
 	count = PHYS_PFN(size);
 
-	iova = alloc_iova(&mmu->dmap->iovad, count,
-			  PHYS_PFN(dma_get_mask(dev)), 0);
+	iova = ipu6_alloc_iova(mmu, count);
 	if (!iova)
 		goto out_kfree;
 
@@ -397,8 +396,7 @@ int ipu6_dma_map_sg(struct ipu6_bus_device *sys, struct scatterlist *sglist,
 	dev_dbg(dev, "dmamap trying to map %d ents %zu pages\n",
 		nents, npages);
 
-	iova = alloc_iova(&mmu->dmap->iovad, npages,
-			  PHYS_PFN(dma_get_mask(dev)), 0);
+	iova = ipu6_alloc_iova(mmu, npages);
 	if (!iova)
 		return 0;
 
diff --git a/drivers/media/pci/intel/ipu6/ipu6-dma.h b/drivers/media/pci/intel/ipu6/ipu6-dma.h
index b51244add9e6..0dd7c0556bd2 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-dma.h
+++ b/drivers/media/pci/intel/ipu6/ipu6-dma.h
@@ -6,8 +6,6 @@
 
 #include <linux/dma-map-ops.h>
 #include <linux/dma-mapping.h>
-#include <linux/iova.h>
-#include <linux/iova.h>
 #include <linux/scatterlist.h>
 #include <linux/types.h>
 
@@ -15,11 +13,6 @@
 
 struct ipu6_mmu_info;
 
-struct ipu6_dma_mapping {
-	struct ipu6_mmu_info *mmu_info;
-	struct iova_domain iovad;
-};
-
 void ipu6_dma_sync_single(struct ipu6_bus_device *sys, dma_addr_t dma_handle,
 			  size_t size);
 void ipu6_dma_sync_sg(struct ipu6_bus_device *sys, struct scatterlist *sglist,
diff --git a/drivers/media/pci/intel/ipu6/ipu6-mmu.c b/drivers/media/pci/intel/ipu6/ipu6-mmu.c
index 6d1c0b90169d..95eb17855847 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-mmu.c
+++ b/drivers/media/pci/intel/ipu6/ipu6-mmu.c
@@ -421,8 +421,7 @@ static int allocate_trash_buffer(struct ipu6_mmu *mmu)
 	int ret;
 
 	/* Allocate 8MB in iova range */
-	iova = alloc_iova(&mmu->dmap->iovad, n_pages,
-			  PHYS_PFN(mmu->dmap->mmu_info->aperture_end), 0);
+	iova = ipu6_alloc_iova(mmu, n_pages);
 	if (!iova) {
 		dev_err(mmu->dev, "cannot allocate iova range for trash\n");
 		return -ENOMEM;
diff --git a/drivers/media/pci/intel/ipu6/ipu6-mmu.h b/drivers/media/pci/intel/ipu6/ipu6-mmu.h
index 8e40b4a66d7d..7f3860796762 100644
--- a/drivers/media/pci/intel/ipu6/ipu6-mmu.h
+++ b/drivers/media/pci/intel/ipu6/ipu6-mmu.h
@@ -7,6 +7,7 @@
 #define ISYS_MMID 1
 #define PSYS_MMID 0
 
+#include <linux/iova.h>
 #include <linux/list.h>
 #include <linux/spinlock_types.h>
 #include <linux/types.h>
@@ -58,6 +59,11 @@ struct ipu6_mmu {
 	void (*tlb_invalidate)(struct ipu6_mmu *mmu);
 };
 
+struct ipu6_dma_mapping {
+	struct ipu6_mmu_info *mmu_info;
+	struct iova_domain iovad;
+};
+
 struct ipu6_mmu *ipu6_mmu_init(struct device *dev,
 			       void __iomem *base, int mmid,
 			       const struct ipu6_hw_variants *hw);
@@ -70,4 +76,11 @@ void ipu6_mmu_unmap(struct ipu6_mmu_info *mmu_info, unsigned long iova,
 		    size_t size);
 phys_addr_t ipu6_mmu_iova_to_phys(struct ipu6_mmu_info *mmu_info,
 				  dma_addr_t iova);
+
+static inline struct iova *ipu_alloc_iova(struct ipu6_mmu *mmu,
+					  unsigned long n_pages)
+{
+	return alloc_iova(&mmu->dmap->iovad, n_pages,
+			  PHYS_PFN(mmu->dmap->mmu_info->aperture_end), 0);
+}
 #endif
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-04-10  8:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-09  9:58 [PATCH] media: intel/ipu6: Fix dma mask for non-secure mode Stanislaw Gruszka
2025-04-09 10:20 ` Stanislaw Gruszka
2025-04-09 12:20 ` kernel test robot
2025-04-09 13:14 ` kernel test robot
2025-04-10  6:53 ` Bingbu Cao
2025-04-10  8:52   ` Stanislaw Gruszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox