From patchwork Tue Oct 19 22:54:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12572347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 243DDC433EF for ; Wed, 20 Oct 2021 12:59:33 +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 E718160241 for ; Wed, 20 Oct 2021 12:59:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E718160241 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 305D76E9BA; Wed, 20 Oct 2021 12:59:20 +0000 (UTC) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2049.outbound.protection.outlook.com [40.107.96.49]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9FB5C6E1AA; Tue, 19 Oct 2021 22:55:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mwHARi86OUUk2rCtZkR8tQ0rn7QihCVVuTnIaldvRIN2hum0t2KAiXXCuy5+XMIZgQmEdFsEqtGzdgqCsYSMgS4yxpIgTLx+Arlg2haO+8dRGTCaqSDspvVQ9L586lMb/PF9G5/XqlVuYXRKTfi+QWgB+5qxlDmL3wwp4IPCx4mCYKoqxfLELGAU+q9POfhnIp10Urt76Ab5W0Ifh3AUiuBut+C3QlK/3s3WAZfbalxjYrbuAl74kS/jnrFDV6S9j5OQk4/FgJl0yyqSmbNN/lf+AWEZsaibs4Jj9uQGBOd3Bb+Z7Lso/xskrDkE3l5DgXSXkWsvKzPAnr1FUd/qgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jY3WLjrxYHhBF3tyzaKCW3g4jt99oifWPTpa3Cg4KT0=; b=IHBN0TzR9DdAFBwOgdko+il7CLJQtcagNuMqXR5QlMAkahUXA/4QzYYe9uATvxR/pO2GBm+Tj4pgDJHfCdCjgmi11h0DgUdAA+jAR2YipblCpIn7t07B1b3Y6gEOHCKstRBQeGHDb+vMvEF69yQ5Ow5aWDld0gMe8d8exQzBU+HvAtXdy4yJSRmlUyS5s9sj+sk2yMGKhbUuPKthK4Fm8HBkTQTPTO6tTn7UgczvnX6I55/r9TSaqCutdI+JEGBJOx8vKBMXJYurY7rQYdG3BNl8hx5KapcM/6+BBw4HWJP/RtOLB7F5MBa8heJg0PGUb/Ob65wGlbxuakXkHSvXiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jY3WLjrxYHhBF3tyzaKCW3g4jt99oifWPTpa3Cg4KT0=; b=T36+x+E3clkq5gh/qVf8mPa9X47//j1MkP6JgP/dbMQ4ed+xbyfp5LUxGOI9uMIA4KEYBOC6m35bU7ESBAdIZR+Zx1jTP1tJqadLTGvdEKUzpHv62YxaCL/VPFDWFwRpu+hEY3rvgNxyjHejdqvJraXjV2qPdcMlKyjer1mVa9A= Received: from MW4PR04CA0244.namprd04.prod.outlook.com (2603:10b6:303:88::9) by DM6PR12MB3627.namprd12.prod.outlook.com (2603:10b6:5:3e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.18; Tue, 19 Oct 2021 22:55:36 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:303:88:cafe::15) by MW4PR04CA0244.outlook.office365.com (2603:10b6:303:88::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.17 via Frontend Transport; Tue, 19 Oct 2021 22:55:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Tue, 19 Oct 2021 22:55:36 +0000 Received: from rtg-amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Tue, 19 Oct 2021 17:55:32 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Date: Wed, 20 Oct 2021 04:24:08 +0530 Message-ID: <20211019225409.569355-13-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211019225409.569355-1-Arunpravin.PaneerSelvam@amd.com> References: <20211019225409.569355-1-Arunpravin.PaneerSelvam@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0a6c5e1b-ea63-4206-116d-08d993539051 X-MS-TrafficTypeDiagnostic: DM6PR12MB3627: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:655; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LE7+if186yhTTgh0fM0K97qCkXsHuPUL7VFwNYRprmaz3egSRa2aPhvHE+nvP/ie3gxK1bLLRkRln0f1SfTHWKTC2XQhoAb0jjb0le1/bHotga8j8HQuROxBixE05yEpeKTgWRO58kThay0OyTI26vc/F6siKC8rZATj6LguoElkLDVbGlac0z8W7gfmRtP4ALTbeOfXoo0cX0IxG5y8QzVYAghLM0n1oBQ3HI2R+l0C2Tw31gV7ZhtHvCKCaLVjtkPNOVe7/VT+LMfenVZiM+BitiW5eUiyPGLy0tMxyCwkb3uMZKkpUzCryeUb6ZuwNHbVuLTD1bgU+8TvwAHcYrrcHYVGra7iYtm8nmo4OPRRiIAQKpvrxzLT28P/DDk0JsnTKvKNkyWOJwRBqVIB9VH5R/W/kUUqdkq/dvtmrV4it7kmnHlhV4qDfXETabMjMVZz1FY7mNvB1AJoeSCqLZ5XGo5bRSuzG6wY7RWPDF/YzFX84fnO6dUG7jqiD0UW7ct2iGFXQNl8PF50IljfumxoDrQnhDLNZDA4smld/tBTgzEHf/C4aGqG0r/EA0FWSiKUfSHHp/P8CjSUrxc5uDAXcT/ca/X+4p7buWyIXLhywvUgvF5e0jO6TRnaevmpcZSUCev/oWDLOvzhxIP/DtpTUTJifiYkMpml+MOEqUisiO5Ifc3Ofqj1LZcwf8jFF+v0ztEvNaeIXL9Kl57UGEZCiJmlNKjp3MBl3ILaWhk= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(336012)(316002)(36756003)(186003)(1076003)(2906002)(4326008)(8936002)(83380400001)(8676002)(16526019)(356005)(26005)(47076005)(6666004)(5660300002)(82310400003)(426003)(70206006)(86362001)(81166007)(36860700001)(508600001)(70586007)(2616005)(7696005)(110136005)(54906003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:36.0829 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a6c5e1b-ea63-4206-116d-08d993539051 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3627 X-Mailman-Approved-At: Wed, 20 Oct 2021 12:59:17 +0000 Subject: [Intel-gfx] [PATCH 12/13] drm/amdgpu: add cursor support for drm buddy X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" - Add res cursor support for drm buddy - Replace if..else statement with switch case statement Signed-off-by: Arunpravin --- .../gpu/drm/amd/amdgpu/amdgpu_res_cursor.h | 97 +++++++++++++++---- 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h index acfa207cf970..2c17e948355e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_res_cursor.h @@ -30,12 +30,15 @@ #include #include +#include "amdgpu_vram_mgr.h" + /* state back for walking over vram_mgr and gtt_mgr allocations */ struct amdgpu_res_cursor { uint64_t start; uint64_t size; uint64_t remaining; - struct drm_mm_node *node; + void *node; + uint32_t mem_type; }; /** @@ -52,27 +55,63 @@ static inline void amdgpu_res_first(struct ttm_resource *res, uint64_t start, uint64_t size, struct amdgpu_res_cursor *cur) { + struct drm_buddy_block *block; + struct list_head *head, *next; struct drm_mm_node *node; - if (!res || res->mem_type == TTM_PL_SYSTEM) { - cur->start = start; - cur->size = size; - cur->remaining = size; - cur->node = NULL; - WARN_ON(res && start + size > res->num_pages << PAGE_SHIFT); - return; - } + if (!res) + goto err_out; BUG_ON(start + size > res->num_pages << PAGE_SHIFT); - node = to_ttm_range_mgr_node(res)->mm_nodes; - while (start >= node->size << PAGE_SHIFT) - start -= node++->size << PAGE_SHIFT; + cur->mem_type = res->mem_type; + + switch (cur->mem_type) { + case TTM_PL_VRAM: + head = &to_amdgpu_vram_mgr_node(res)->blocks; + + block = list_first_entry_or_null(head, + struct drm_buddy_block, + link); + if (!block) + goto err_out; + + while (start >= node_size(block)) { + start -= node_size(block); + + next = block->link.next; + if (next != head) + block = list_entry(next, struct drm_buddy_block, link); + } + + cur->start = node_start(block) + start; + cur->size = min(node_size(block) - start, size); + cur->remaining = size; + cur->node = block; + break; + case TTM_PL_TT: + node = to_ttm_range_mgr_node(res)->mm_nodes; + while (start >= node->size << PAGE_SHIFT) + start -= node++->size << PAGE_SHIFT; + + cur->start = (node->start << PAGE_SHIFT) + start; + cur->size = min((node->size << PAGE_SHIFT) - start, size); + cur->remaining = size; + cur->node = node; + break; + default: + goto err_out; + } - cur->start = (node->start << PAGE_SHIFT) + start; - cur->size = min((node->size << PAGE_SHIFT) - start, size); + return; + +err_out: + cur->start = start; + cur->size = size; cur->remaining = size; - cur->node = node; + cur->node = NULL; + WARN_ON(res && start + size > res->num_pages << PAGE_SHIFT); + return; } /** @@ -85,7 +124,9 @@ static inline void amdgpu_res_first(struct ttm_resource *res, */ static inline void amdgpu_res_next(struct amdgpu_res_cursor *cur, uint64_t size) { - struct drm_mm_node *node = cur->node; + struct drm_buddy_block *block; + struct drm_mm_node *node; + struct list_head *next; BUG_ON(size > cur->remaining); @@ -99,9 +140,27 @@ static inline void amdgpu_res_next(struct amdgpu_res_cursor *cur, uint64_t size) return; } - cur->node = ++node; - cur->start = node->start << PAGE_SHIFT; - cur->size = min(node->size << PAGE_SHIFT, cur->remaining); + switch (cur->mem_type) { + case TTM_PL_VRAM: + block = cur->node; + + next = block->link.next; + block = list_entry(next, struct drm_buddy_block, link); + + cur->node = block; + cur->start = node_start(block); + cur->size = min(node_size(block), cur->remaining); + break; + case TTM_PL_TT: + node = cur->node; + + cur->node = ++node; + cur->start = node->start << PAGE_SHIFT; + cur->size = min(node->size << PAGE_SHIFT, cur->remaining); + break; + default: + return; + } } #endif