From patchwork Fri Apr 30 09:25:04 2021 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: 12232861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9863C433ED for ; Fri, 30 Apr 2021 09:25:44 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6F8A561352 for ; Fri, 30 Apr 2021 09:25:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F8A561352 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C7A486F517; Fri, 30 Apr 2021 09:25:43 +0000 (UTC) Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1AF496F50C for ; Fri, 30 Apr 2021 09:25:17 +0000 (UTC) Received: by mail-ej1-x633.google.com with SMTP id r9so104225096ejj.3 for ; Fri, 30 Apr 2021 02:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=09FzZUp/FDpa+6m0of7/xNo4usnS7yLTYPpVTfDsqOI=; b=gJJMhpEyjzRUplgHrMN6TRPqhFKkPW37uEfkqPHyathzKdQg2gg1hS062EzjiUNmFv iHDcCQaUEyjyp7Mw364FCI9/VRiAMoeDBuvB8RHvMTjRb4AdaSpnACooX/Ro2MYoQPax xzX7NVuXFngkNP6vThnvgg5aY5oEaWA74+DKj4AOhLLpkBL9yRPHBgK9qPzIHmO6/gNq eJX1bo/UdNjjYfwOSWw8s5ALC/Wa9p/VCgvzR8+ZRQUaKGmMMiVbsfGmZje2G7Aku7Zc HkT7UPFs2OAU9MxCY+drxi6vyG/JgLf537+muo6UX5j/DHxFX6qGEbKCV9SgEIsCCaly 3Tyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=09FzZUp/FDpa+6m0of7/xNo4usnS7yLTYPpVTfDsqOI=; b=jo5G1NU6egPPREvXG6lV7UUt0NkWetRlQKNJwrcOWl7t4QiTYIDAEvnPGR8YtEbv+4 wjyynE6GA5djT4V0OLyDrRyEPCdwmRQzT1WWjDRqlMCVqw3SS7h4kt7yHIsgxhCuppCT uqeQkzn8l4C+T3jWs3JKzSeqwzy2lXin+qL8rDR7WfMo1XoXJZtpkv9LGRKJkb7PcK4G 0DuuyGRioQ16kUp+L5aKvls9iOz4NWCRUTAmw19ZsPeXCetZw3HfjLPqEZLxPdKOtebs 5rz4XyNNrTKgSjS98oQX53nSQv8q0YOC/yOgyLlbUpGebml0QT7zvAkb+pSIRz/5AVsD 8kwA== X-Gm-Message-State: AOAM531ubPl5GYRAX+9fZaBHPRIliMXeEd+MWtV4wAAind5P9klxyOKt M/ASmEpggXPQgfmVYICRzHionNW6ieY= X-Google-Smtp-Source: ABdhPJyXpqej8xCzZsVSeJw8aQwxDcZsNPAHFF1okBPljJfXLsSEguHIKIO34AK1SX9IlUJ7WNNnRQ== X-Received: by 2002:a17:906:3458:: with SMTP id d24mr3393331ejb.54.1619774715754; Fri, 30 Apr 2021 02:25:15 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:d08c:9633:b7a2:37e2]) by smtp.gmail.com with ESMTPSA id h23sm1550959ejx.90.2021.04.30.02.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 02:25:15 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 09/13] drm/amdgpu: switch the GTT backend to self alloc Date: Fri, 30 Apr 2021 11:25:04 +0200 Message-Id: <20210430092508.60710-9-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210430092508.60710-1-christian.koenig@amd.com> References: <20210430092508.60710-1-christian.koenig@amd.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: daniel.vetter@ffwll.ch, matthew.william.auld@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Similar to the TTM range manager. Signed-off-by: Christian König Reviewed-by: Matthew Auld --- drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 36 +++++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c index 55ca80133411..2e7dffd3614d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c @@ -22,11 +22,13 @@ * Authors: Christian König */ +#include + #include "amdgpu.h" struct amdgpu_gtt_node { - struct drm_mm_node node; struct ttm_buffer_object *tbo; + struct ttm_range_mgr_node base; }; static inline struct amdgpu_gtt_mgr * @@ -38,7 +40,8 @@ to_gtt_mgr(struct ttm_resource_manager *man) static inline struct amdgpu_gtt_node * to_amdgpu_gtt_node(struct ttm_resource *res) { - return container_of(res->mm_node, struct amdgpu_gtt_node, node); + return container_of(res->mm_node, struct amdgpu_gtt_node, + base.mm_nodes[0]); } /** @@ -97,7 +100,7 @@ bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_resource *mem) { struct amdgpu_gtt_node *node = to_amdgpu_gtt_node(mem); - return drm_mm_node_allocated(&node->node); + return drm_mm_node_allocated(&node->base.mm_nodes[0]); } /** @@ -128,16 +131,19 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, atomic64_sub(mem->num_pages, &mgr->available); spin_unlock(&mgr->lock); - node = kzalloc(sizeof(*node), GFP_KERNEL); + node = kzalloc(struct_size(node, base.mm_nodes, 1), GFP_KERNEL); if (!node) { r = -ENOMEM; goto err_out; } node->tbo = tbo; + ttm_resource_init(tbo, place, &node->base.base); + if (place->lpfn) { spin_lock(&mgr->lock); - r = drm_mm_insert_node_in_range(&mgr->mm, &node->node, + r = drm_mm_insert_node_in_range(&mgr->mm, + &node->base.mm_nodes[0], mem->num_pages, tbo->page_alignment, 0, place->fpfn, place->lpfn, @@ -146,14 +152,14 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, if (unlikely(r)) goto err_free; - mem->start = node->node.start; + mem->start = node->base.mm_nodes[0].start; } else { - node->node.start = 0; - node->node.size = mem->num_pages; + node->base.mm_nodes[0].start = 0; + node->base.mm_nodes[0].size = mem->num_pages; mem->start = AMDGPU_BO_INVALID_OFFSET; } - mem->mm_node = &node->node; + mem->mm_node = &node->base.mm_nodes[0]; return 0; err_free: @@ -176,15 +182,17 @@ static int amdgpu_gtt_mgr_new(struct ttm_resource_manager *man, static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man, struct ttm_resource *mem) { - struct amdgpu_gtt_node *node = to_amdgpu_gtt_node(mem); struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man); + struct amdgpu_gtt_node *node; - if (!node) + if (!mem->mm_node) return; + node = to_amdgpu_gtt_node(mem); + spin_lock(&mgr->lock); - if (drm_mm_node_allocated(&node->node)) - drm_mm_remove_node(&node->node); + if (drm_mm_node_allocated(&node->base.mm_nodes[0])) + drm_mm_remove_node(&node->base.mm_nodes[0]); spin_unlock(&mgr->lock); atomic64_add(mem->num_pages, &mgr->available); @@ -222,7 +230,7 @@ int amdgpu_gtt_mgr_recover(struct ttm_resource_manager *man) spin_lock(&mgr->lock); drm_mm_for_each_node(mm_node, &mgr->mm) { - node = container_of(mm_node, struct amdgpu_gtt_node, node); + node = container_of(mm_node, typeof(*node), base.mm_nodes[0]); r = amdgpu_ttm_recover_gart(node->tbo); if (r) break;