[PATCH v4 23/27] sandbox: iommu: remove lmb allocation in the driver

Sughosh Ganu sughosh.ganu at linaro.org
Mon Aug 26 13:59:36 CEST 2024


The sandbox iommu driver uses the LMB module to allocate a particular
range of memory for the device virtual address(DVA). This used to work
earlier since the LMB memory map was caller specific and not
global. But with the change to make the LMB allocations global and
persistent, adding this memory range has other side effects. On the
other hand, the sandbox iommu test expects to see this particular
value of the DVA. Use the DVA address directly, instead of mapping it
in the LMB memory map, and then have it allocated.

Signed-off-by: Sughosh Ganu <sughosh.ganu at linaro.org>
Reviewed-by: Simon Glass <sjg at chromium.org>
---
Changes since V3: None

 arch/sandbox/include/asm/test.h |  4 ++++
 drivers/iommu/sandbox_iommu.c   | 25 ++++++-------------------
 2 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h
index 17159f8d67..0e8d19ce23 100644
--- a/arch/sandbox/include/asm/test.h
+++ b/arch/sandbox/include/asm/test.h
@@ -49,6 +49,10 @@ struct unit_test_state;
 #define PCI_EA_BAR2_MAGIC		0x72727272
 #define PCI_EA_BAR4_MAGIC		0x74747474
 
+/* Used by the sandbox iommu driver */
+#define SANDBOX_IOMMU_DVA_ADDR		0x89abc000
+#define SANDBOX_IOMMU_PAGE_SIZE		SZ_4K
+
 enum {
 	SANDBOX_IRQN_PEND = 1,	/* Interrupt number for 'pending' test */
 };
diff --git a/drivers/iommu/sandbox_iommu.c b/drivers/iommu/sandbox_iommu.c
index 5b4a6a8982..c5eefec218 100644
--- a/drivers/iommu/sandbox_iommu.c
+++ b/drivers/iommu/sandbox_iommu.c
@@ -5,23 +5,20 @@
 
 #include <dm.h>
 #include <iommu.h>
-#include <lmb.h>
 #include <asm/io.h>
+#include <asm/test.h>
 #include <linux/sizes.h>
 
-#define IOMMU_PAGE_SIZE		SZ_4K
-
 static dma_addr_t sandbox_iommu_map(struct udevice *dev, void *addr,
 				    size_t size)
 {
 	phys_addr_t paddr, dva;
 	phys_size_t psize, off;
 
-	paddr = ALIGN_DOWN(virt_to_phys(addr), IOMMU_PAGE_SIZE);
+	paddr = ALIGN_DOWN(virt_to_phys(addr), SANDBOX_IOMMU_PAGE_SIZE);
 	off = virt_to_phys(addr) - paddr;
-	psize = ALIGN(size + off, IOMMU_PAGE_SIZE);
-
-	dva = lmb_alloc(psize, IOMMU_PAGE_SIZE);
+	psize = ALIGN(size + off, SANDBOX_IOMMU_PAGE_SIZE);
+	dva = (phys_addr_t)SANDBOX_IOMMU_DVA_ADDR;
 
 	return dva + off;
 }
@@ -32,11 +29,9 @@ static void sandbox_iommu_unmap(struct udevice *dev, dma_addr_t addr,
 	phys_addr_t dva;
 	phys_size_t psize;
 
-	dva = ALIGN_DOWN(addr, IOMMU_PAGE_SIZE);
+	dva = ALIGN_DOWN(addr, SANDBOX_IOMMU_PAGE_SIZE);
 	psize = size + (addr - dva);
-	psize = ALIGN(psize, IOMMU_PAGE_SIZE);
-
-	lmb_free(dva, psize);
+	psize = ALIGN(psize, SANDBOX_IOMMU_PAGE_SIZE);
 }
 
 static struct iommu_ops sandbox_iommu_ops = {
@@ -44,13 +39,6 @@ static struct iommu_ops sandbox_iommu_ops = {
 	.unmap = sandbox_iommu_unmap,
 };
 
-static int sandbox_iommu_probe(struct udevice *dev)
-{
-	lmb_add(0x89abc000, SZ_16K);
-
-	return 0;
-}
-
 static const struct udevice_id sandbox_iommu_ids[] = {
 	{ .compatible = "sandbox,iommu" },
 	{ /* sentinel */ }
@@ -61,5 +49,4 @@ U_BOOT_DRIVER(sandbox_iommu) = {
 	.id = UCLASS_IOMMU,
 	.of_match = sandbox_iommu_ids,
 	.ops = &sandbox_iommu_ops,
-	.probe = sandbox_iommu_probe,
 };
-- 
2.34.1



More information about the U-Boot mailing list