[PATCH RFC 046/111] staging: etnaviv: move GPU memory management into MMU

Lucas Stach l.stach at pengutronix.de
Thu Apr 2 08:29:48 PDT 2015


From: Russell King <rmk+kernel at arm.linux.org.uk>

The GPU memory management (managed by a drm_mm object) is used to
track which areas of the MMU address space are in-use.  Therefore,
this should be tied to the MMU object, rather than the GPU object.

This means we could (as comments suggest) have multiple MMU objects,
one for each context, and switch between them.  Each would need to
be managed by its own drm_mm object.

Signed-off-by: Russell King <rmk+kernel at arm.linux.org.uk>
---
 drivers/staging/etnaviv/etnaviv_gem.c | 2 +-
 drivers/staging/etnaviv/etnaviv_gpu.c | 4 ----
 drivers/staging/etnaviv/etnaviv_gpu.h | 3 ---
 drivers/staging/etnaviv/etnaviv_mmu.c | 4 ++++
 drivers/staging/etnaviv/etnaviv_mmu.h | 3 +++
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/etnaviv/etnaviv_gem.c b/drivers/staging/etnaviv/etnaviv_gem.c
index 034ff732bdf4..647815e4f1ba 100644
--- a/drivers/staging/etnaviv/etnaviv_gem.c
+++ b/drivers/staging/etnaviv/etnaviv_gem.c
@@ -292,7 +292,7 @@ int etnaviv_gem_get_iova_locked(struct etnaviv_gpu *gpu,
 		if (!node)
 			return -ENOMEM;
 
-		ret = drm_mm_insert_node(&gpu->mm, node, obj->size, 0,
+		ret = drm_mm_insert_node(&mmu->mm, node, obj->size, 0,
 				DRM_MM_SEARCH_DEFAULT);
 
 		if (!ret) {
diff --git a/drivers/staging/etnaviv/etnaviv_gpu.c b/drivers/staging/etnaviv/etnaviv_gpu.c
index 85a0862e0347..91dc44f35a49 100644
--- a/drivers/staging/etnaviv/etnaviv_gpu.c
+++ b/drivers/staging/etnaviv/etnaviv_gpu.c
@@ -947,8 +947,6 @@ static void etnaviv_gpu_unbind(struct device *dev, struct device *master,
 
 	if (gpu->mmu)
 		etnaviv_iommu_destroy(gpu->mmu);
-
-	drm_mm_takedown(&gpu->mm);
 }
 
 static const struct component_ops gpu_ops = {
@@ -1028,8 +1026,6 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev)
 	gpu->pipe = (int)match->data;
 
 	/* TODO: figure out max mapped size */
-	drm_mm_init(&gpu->mm, 0x80000000, SZ_1G);
-
 	dev_set_drvdata(dev, gpu);
 
 	err = component_add(&pdev->dev, &gpu_ops);
diff --git a/drivers/staging/etnaviv/etnaviv_gpu.h b/drivers/staging/etnaviv/etnaviv_gpu.h
index 5afa0f74106c..a26d0ded1019 100644
--- a/drivers/staging/etnaviv/etnaviv_gpu.h
+++ b/drivers/staging/etnaviv/etnaviv_gpu.h
@@ -113,9 +113,6 @@ struct etnaviv_gpu {
 
 	struct etnaviv_iommu *mmu;
 
-	/* memory manager for GPU address area */
-	struct drm_mm mm;
-
 	/* Power Control: */
 	struct clk *clk_bus;
 	struct clk *clk_core;
diff --git a/drivers/staging/etnaviv/etnaviv_mmu.c b/drivers/staging/etnaviv/etnaviv_mmu.c
index 94a6aa9f9c6f..48a0818a3788 100644
--- a/drivers/staging/etnaviv/etnaviv_mmu.c
+++ b/drivers/staging/etnaviv/etnaviv_mmu.c
@@ -92,6 +92,7 @@ int etnaviv_iommu_unmap(struct etnaviv_iommu *iommu, uint32_t iova,
 
 void etnaviv_iommu_destroy(struct etnaviv_iommu *mmu)
 {
+	drm_mm_takedown(&mmu->mm);
 	iommu_domain_free(mmu->domain);
 	kfree(mmu);
 }
@@ -107,6 +108,9 @@ struct etnaviv_iommu *etnaviv_iommu_new(struct drm_device *dev,
 
 	mmu->domain = domain;
 	mmu->dev = dev;
+
+	drm_mm_init(&mmu->mm, 0x80000000, SZ_1G);
+
 	iommu_set_fault_handler(domain, etnaviv_fault_handler, dev);
 
 	return mmu;
diff --git a/drivers/staging/etnaviv/etnaviv_mmu.h b/drivers/staging/etnaviv/etnaviv_mmu.h
index b3a0e3c98372..1adcc3ab4ebc 100644
--- a/drivers/staging/etnaviv/etnaviv_mmu.h
+++ b/drivers/staging/etnaviv/etnaviv_mmu.h
@@ -23,6 +23,9 @@
 struct etnaviv_iommu {
 	struct drm_device *dev;
 	struct iommu_domain *domain;
+
+	/* memory manager for GPU address area */
+	struct drm_mm mm;
 	bool need_flush;
 };
 
-- 
2.1.4



More information about the dri-devel mailing list