lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 27 Jun 2014 20:22:13 +0900
From:	Alexandre Courbot <acourbot@...dia.com>
To:	Ben Skeggs <bskeggs@...hat.com>, David Airlie <airlied@...ux.ie>,
	Lucas Stach <dev@...xeye.de>,
	Thierry Reding <thierry.reding@...il.com>
CC:	<nouveau@...ts.freedesktop.org>, <dri-devel@...ts.freedesktop.org>,
	<linux-tegra@...r.kernel.org>,
	<linux-arm-kernel@...ts.infradead.org>,
	<linux-kernel@...r.kernel.org>, <gnurou@...il.com>,
	Alexandre Courbot <acourbot@...dia.com>
Subject: [PATCH v3 1/2] drm/nouveau: cleanup TTM population logic

TTM pages can currently be populated using 3 different methods, but the
code does not make it clear which one is used. The same complex
conditions are tested in various parts of the code, which makes it
difficult to follow and error prone.

This patch introduces an enum into the nouveau_drm struct that indicates
which population method will be used for TT-backed BOs. It is set once
and for all during TTM initialization so the same conditions need not be
tested again and again. This will also allow us to add new non-default
TTM population cases by changing a single piece of code in
nouveau_ttm_init() instead of all over nouveau_bo.c

Signed-off-by: Alexandre Courbot <acourbot@...dia.com>
---
 drivers/gpu/drm/nouveau/nouveau_bo.c  | 63 ++++++++++++++++++-----------------
 drivers/gpu/drm/nouveau/nouveau_drm.h | 11 ++++++
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 15 +++++++++
 3 files changed, 59 insertions(+), 30 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 4db886f9f793..82c6b479abcb 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -28,7 +28,6 @@
  */
 
 #include <core/engine.h>
-#include <linux/swiotlb.h>
 
 #include <subdev/fb.h>
 #include <subdev/vm.h>
@@ -467,11 +466,11 @@ static struct ttm_tt *
 nouveau_ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size,
 		      uint32_t page_flags, struct page *dummy_read)
 {
-#if __OS_HAS_AGP
+#if defined(TTM_HAS_AGP)
 	struct nouveau_drm *drm = nouveau_bdev(bdev);
 	struct drm_device *dev = drm->dev;
 
-	if (drm->agp.stat == ENABLED) {
+	if (drm->ttm.populate_method == AGP) {
 		return ttm_agp_tt_create(bdev, dev->agp->bridge, size,
 					 page_flags, dummy_read);
 	}
@@ -524,21 +523,23 @@ nouveau_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,
 		if (nv_device(drm->device)->card_type >= NV_50)
 			man->func = &nouveau_gart_manager;
 		else
-		if (drm->agp.stat != ENABLED)
+		if (drm->ttm.populate_method != AGP)
 			man->func = &nv04_gart_manager;
 		else
 			man->func = &ttm_bo_manager_func;
 
-		if (drm->agp.stat == ENABLED) {
-			man->flags = TTM_MEMTYPE_FLAG_MAPPABLE;
+		man->flags = TTM_MEMTYPE_FLAG_MAPPABLE;
+
+		if (drm->ttm.populate_method != AGP)
+			man->flags |= TTM_MEMTYPE_FLAG_CMA;
+
+		if (drm->ttm.populate_method == POOL) {
+			man->available_caching = TTM_PL_MASK_CACHING;
+			man->default_caching = TTM_PL_FLAG_CACHED;
+		} else {
 			man->available_caching = TTM_PL_FLAG_UNCACHED |
 				TTM_PL_FLAG_WC;
 			man->default_caching = TTM_PL_FLAG_WC;
-		} else {
-			man->flags = TTM_MEMTYPE_FLAG_MAPPABLE |
-				     TTM_MEMTYPE_FLAG_CMA;
-			man->available_caching = TTM_PL_MASK_CACHING;
-			man->default_caching = TTM_PL_FLAG_CACHED;
 		}
 
 		break;
@@ -1249,13 +1250,11 @@ nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
 		/* System memory */
 		return 0;
 	case TTM_PL_TT:
-#if __OS_HAS_AGP
-		if (drm->agp.stat == ENABLED) {
+		if (drm->ttm.populate_method == AGP) {
 			mem->bus.offset = mem->start << PAGE_SHIFT;
 			mem->bus.base = drm->agp.base;
 			mem->bus.is_iomem = !dev->agp->cant_use_aperture;
 		}
-#endif
 		if (nv_device(drm->device)->card_type < NV_50 || !node->memtype)
 			/* untiled */
 			break;
@@ -1359,17 +1358,20 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm)
 	device = nv_device(drm->device);
 	dev = drm->dev;
 
-#if __OS_HAS_AGP
-	if (drm->agp.stat == ENABLED) {
+	switch (drm->ttm.populate_method) {
+	case AGP:
+#if defined(TTM_HAS_AGP)
 		return ttm_agp_tt_populate(ttm);
-	}
+#else
+		return 0;
 #endif
+	case DMA:
+		return ttm_dma_populate(ttm_dma, dev->dev);
 
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_nr_tbl()) {
-		return ttm_dma_populate((void *)ttm, dev->dev);
+	case POOL:
+		/* POOL case is handled below */
+		break;
 	}
-#endif
 
 	r = ttm_pool_populate(ttm);
 	if (r) {
@@ -1409,19 +1411,20 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
 	device = nv_device(drm->device);
 	dev = drm->dev;
 
-#if __OS_HAS_AGP
-	if (drm->agp.stat == ENABLED) {
+	switch (drm->ttm.populate_method) {
+	case AGP:
+#if defined(TTM_HAS_AGP)
 		ttm_agp_tt_unpopulate(ttm);
-		return;
-	}
 #endif
-
-#ifdef CONFIG_SWIOTLB
-	if (swiotlb_nr_tbl()) {
-		ttm_dma_unpopulate((void *)ttm, dev->dev);
 		return;
+	case DMA:
+		ttm_dma_unpopulate(ttm_dma, dev->dev);
+		return;
+
+	case POOL:
+		/* POOL case is handled below */
+		break;
 	}
-#endif
 
 	for (i = 0; i < ttm->num_pages; i++) {
 		if (ttm_dma->dma_address[i]) {
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
index 7efbafaf7c1d..0d4b9eff8863 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
@@ -103,6 +103,17 @@ struct nouveau_drm {
 			    struct ttm_mem_reg *, struct ttm_mem_reg *);
 		struct nouveau_channel *chan;
 		int mtrr;
+		/*
+		 * How TTM objects are populated:
+		 * POOL: use ttm_pool_populate()
+		 * AGP: use ttm_agp_tt_populate()
+		 * DMA: use ttm_dma_populate()
+		 */
+		enum {
+			POOL,
+			AGP,
+			DMA,
+		} populate_method;
 	} ttm;
 
 	/* GEM interface support */
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index ab0228f640a5..70893416d4b6 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -24,6 +24,10 @@
  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include <linux/dma-mapping.h>
+#include <linux/swiotlb.h>
+#include <linux/kconfig.h>
+
 #include <subdev/fb.h>
 #include <subdev/vm.h>
 #include <subdev/instmem.h>
@@ -375,6 +379,17 @@ nouveau_ttm_init(struct nouveau_drm *drm)
 						    DMA_BIT_MASK(32));
 	}
 
+	drm->ttm.populate_method = POOL;
+
+#ifdef CONFIG_SWIOTLB
+	if (swiotlb_nr_tbl())
+		drm->ttm.populate_method = DMA;
+#endif
+#if defined(TTM_HAS_AGP)
+	if (drm->agp.stat == ENABLED)
+		drm->ttm.populate_method = AGP;
+#endif
+
 	ret = nouveau_ttm_global_init(drm);
 	if (ret)
 		return ret;
-- 
2.0.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ