From patchwork Thu Feb 22 15:02:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10235705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 20A5160224 for ; Thu, 22 Feb 2018 15:02:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B38928BF2 for ; Thu, 22 Feb 2018 15:02:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F91528C15; Thu, 22 Feb 2018 15:02:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A179228BF2 for ; Thu, 22 Feb 2018 15:02:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9B5DB6EE2B; Thu, 22 Feb 2018 15:02:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6A2666EE26 for ; Thu, 22 Feb 2018 15:02:27 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id x21so4235751wmh.0 for ; Thu, 22 Feb 2018 07:02:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=JBKyipEdsTihzeVpuKVztP6cIYOTQlpxyK0psUpaWi8=; b=dsxQFUx/P565Q+Czs++qbzUrjZVJVc1RJvx/sf8iTqhODodbdIXUMdHuBcx268SeBZ DBmrV63/wmhlU+3RY0WreM0s1iZJ311/6tSkMPwt+LU9bZEQiMs1Sq5k4T9ruSlvjagB diV9fYoQ57dIqgY6WA8flQ6EzJqHiBQmruQEGmXHQgsqSJhXL0yBUSbGZavLnmAZkQ4y D5d0k5lwAUXzXWEpsLx73KozQaaESKo7WGa5PMx722oS1S8Dj8Ys65sKYjJEKb04z52Z DlVnWDjAlM3c5AvZZH1caHYdFIqysaSQbjcdACRXK1BQbhn8UttIQ18jrGxeMhVfnT9M u4+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JBKyipEdsTihzeVpuKVztP6cIYOTQlpxyK0psUpaWi8=; b=ZgGs5fQIxBB7qMWsmzEfHMPzl0fMIKCCYIZNV5oL4wJZLsEGpkvbmsjaS81dTr0N4R qPfNyg9PhLuRmHauDtSwBkrrkebNqgGAxxcmUftuRE64BTVZKJZLYEvOqiz7Ok1Lohs/ 4nT2smESlO0CF3wOGpmzp8DNnSYHpo0CzqzVVoRLOXWT7Uvs3C0dBqCNPZxZO315U/tG NdDpyre5M/WvR9clGEvveSInaw0rGq6izDfMnvekGGuDDysCXrQ2LGVKVgzskjfgr6V5 fSqth/CQjBO2EbEOLKHYYsQ0++3obKI0jE9WhTeaCsK/L7rd2JiSXxANj6b2971i+/oK UM3g== X-Gm-Message-State: APf1xPCxQPoJheYs8nb25LtcC6sJ31q9nTIhE5xTbyR6jod/+2DQc7To VHFCmH9Pgep3d2CMDY4P7DuXPQ== X-Google-Smtp-Source: AH8x225zNdSLAAVRsC+eJZZpw2fwdIDGpZJIgH55SWp+6xBXpMJNhP2AQwrDGZ+IQdhip/8LDXtUsA== X-Received: by 10.28.122.12 with SMTP id v12mr2643949wmc.66.1519311745781; Thu, 22 Feb 2018 07:02:25 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:88c:4715:87af:fa74]) by smtp.gmail.com with ESMTPSA id v63sm424613wrc.69.2018.02.22.07.02.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Feb 2018 07:02:25 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/6] drm/ttm: move ttm_tt_create into ttm_tt.c Date: Thu, 22 Feb 2018 16:02:18 +0100 Message-Id: <20180222150220.8702-4-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180222150220.8702-1-christian.koenig@amd.com> References: <20180222150220.8702-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 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-Virus-Scanned: ClamAV using ClamSMTP Rename ttm_bo_add_ttm to ttm_tt_create, clean it up and move it into ttm_tt.c. Signed-off-by: Christian König Reviewed-by: Michel Dänzer --- drivers/gpu/drm/ttm/ttm_bo.c | 50 ++--------------------------------------- drivers/gpu/drm/ttm/ttm_tt.c | 43 +++++++++++++++++++++++++++++++++++ include/drm/ttm/ttm_bo_driver.h | 11 +++++++++ 3 files changed, 56 insertions(+), 48 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 55028745214b..3fb58ba1df51 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -222,52 +222,6 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo) } EXPORT_SYMBOL(ttm_bo_move_to_lru_tail); -/* - * Call bo->mutex locked. - */ -static int ttm_bo_add_ttm(struct ttm_buffer_object *bo, bool zero_alloc) -{ - struct ttm_bo_device *bdev = bo->bdev; - int ret = 0; - uint32_t page_flags = 0; - - reservation_object_assert_held(bo->resv); - bo->ttm = NULL; - - if (bdev->need_dma32) - page_flags |= TTM_PAGE_FLAG_DMA32; - - if (bdev->no_retry) - page_flags |= TTM_PAGE_FLAG_NO_RETRY; - - switch (bo->type) { - case ttm_bo_type_device: - if (zero_alloc) - page_flags |= TTM_PAGE_FLAG_ZERO_ALLOC; - case ttm_bo_type_kernel: - bo->ttm = bdev->driver->ttm_tt_create(bdev, bo->num_pages << PAGE_SHIFT, - page_flags); - if (unlikely(bo->ttm == NULL)) - ret = -ENOMEM; - break; - case ttm_bo_type_sg: - bo->ttm = bdev->driver->ttm_tt_create(bdev, bo->num_pages << PAGE_SHIFT, - page_flags | TTM_PAGE_FLAG_SG); - if (unlikely(bo->ttm == NULL)) { - ret = -ENOMEM; - break; - } - bo->ttm->sg = bo->sg; - break; - default: - pr_err("Illegal buffer object type\n"); - ret = -EINVAL; - break; - } - - return ret; -} - static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem, bool evict, struct ttm_operation_ctx *ctx) @@ -295,7 +249,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, if (!(new_man->flags & TTM_MEMTYPE_FLAG_FIXED)) { if (bo->ttm == NULL) { bool zero = !(old_man->flags & TTM_MEMTYPE_FLAG_FIXED); - ret = ttm_bo_add_ttm(bo, zero); + ret = ttm_tt_create(bo, zero); if (ret) goto out_err; } @@ -1134,7 +1088,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, * We might need to add a TTM. */ if (bo->mem.mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) { - ret = ttm_bo_add_ttm(bo, true); + ret = ttm_tt_create(bo, true); if (ret) return ret; } diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c index f93cd108b19d..0ee3b8f11605 100644 --- a/drivers/gpu/drm/ttm/ttm_tt.c +++ b/drivers/gpu/drm/ttm/ttm_tt.c @@ -47,6 +47,49 @@ #include #endif +/** + * Allocates a ttm structure for the given BO. + */ +int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc) +{ + struct ttm_bo_device *bdev = bo->bdev; + uint32_t page_flags = 0; + + reservation_object_assert_held(bo->resv); + + if (bdev->need_dma32) + page_flags |= TTM_PAGE_FLAG_DMA32; + + if (bdev->no_retry) + page_flags |= TTM_PAGE_FLAG_NO_RETRY; + + switch (bo->type) { + case ttm_bo_type_device: + if (zero_alloc) + page_flags |= TTM_PAGE_FLAG_ZERO_ALLOC; + break; + case ttm_bo_type_kernel: + break; + case ttm_bo_type_sg: + page_flags |= TTM_PAGE_FLAG_SG; + break; + default: + bo->ttm = NULL; + pr_err("Illegal buffer object type\n"); + return -EINVAL; + } + + bo->ttm = bdev->driver->ttm_tt_create(bdev, bo->num_pages << PAGE_SHIFT, + page_flags); + if (unlikely(bo->ttm == NULL)) + return -ENOMEM; + + if (bo->type == ttm_bo_type_sg) + bo->ttm->sg = bo->sg; + + return 0; +} + /** * Allocates storage for pointers to the pages that back the ttm. */ diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index b338dd0ea038..4312b5326f0b 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h @@ -610,6 +610,17 @@ ttm_flag_masked(uint32_t *old, uint32_t new, uint32_t mask) return *old; } +/** + * ttm_tt_create + * + * @bo: pointer to a struct ttm_buffer_object + * @zero_alloc: true if allocated pages needs to be zeroed + * + * Make sure we have a TTM structure allocated for the given BO. + * No pages are actually allocated. + */ +int ttm_tt_create(struct ttm_buffer_object *bo, bool zero_alloc); + /** * ttm_tt_init *