From patchwork Fri Jun 27 11:22:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Courbot X-Patchwork-Id: 4434701 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ED358BEEAA for ; Fri, 27 Jun 2014 11:25:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 05D3520384 for ; Fri, 27 Jun 2014 11:25:18 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 07D6320381 for ; Fri, 27 Jun 2014 11:25:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1X0UFg-0006n3-Ka; Fri, 27 Jun 2014 11:23:32 +0000 Received: from hqemgate16.nvidia.com ([216.228.121.65]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1X0UFF-0006Ej-Da for linux-arm-kernel@lists.infradead.org; Fri, 27 Jun 2014 11:23:06 +0000 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com id ; Fri, 27 Jun 2014 04:21:58 -0700 Received: from hqemhub01.nvidia.com ([172.20.12.94]) by hqnvupgp07.nvidia.com (PGP Universal service); Fri, 27 Jun 2014 04:12:45 -0700 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Fri, 27 Jun 2014 04:12:45 -0700 Received: from percival.nvidia.com (172.20.144.16) by hqemhub01.nvidia.com (172.20.150.30) with Microsoft SMTP Server (TLS) id 8.3.342.0; Fri, 27 Jun 2014 04:22:43 -0700 From: Alexandre Courbot To: Ben Skeggs , David Airlie , Lucas Stach , Thierry Reding Subject: [PATCH v3 1/2] drm/nouveau: cleanup TTM population logic Date: Fri, 27 Jun 2014 20:22:13 +0900 Message-ID: <1403868134-31741-2-git-send-email-acourbot@nvidia.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1403868134-31741-1-git-send-email-acourbot@nvidia.com> References: <1403868134-31741-1-git-send-email-acourbot@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140627_042305_484981_527CCAE3 X-CRM114-Status: GOOD ( 20.99 ) X-Spam-Score: -0.0 (/) Cc: gnurou@gmail.com, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Alexandre Courbot , linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 -#include #include #include @@ -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 +#include +#include + #include #include #include @@ -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;