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: 4434631 Return-Path: X-Original-To: patchwork-dri-devel@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 48D8CBEEAA for ; Fri, 27 Jun 2014 11:22:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 49A7020384 for ; Fri, 27 Jun 2014 11:22:47 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 3D15020381 for ; Fri, 27 Jun 2014 11:22:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2B8126E63A; Fri, 27 Jun 2014 04:22:45 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from hqemgate16.nvidia.com (hqemgate16.nvidia.com [216.228.121.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 654C26E63A; Fri, 27 Jun 2014 04:22:44 -0700 (PDT) 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 Cc: gnurou@gmail.com, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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;