From patchwork Thu Jul 18 10:32:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 13736362 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id B1841C3DA49 for ; Thu, 18 Jul 2024 10:33:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 395D610E721; Thu, 18 Jul 2024 10:33:06 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="WTADr1Mo"; dkim-atps=neutral Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2069.outbound.protection.outlook.com [40.107.92.69]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5C05710E71A; Thu, 18 Jul 2024 10:33:04 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hRI14IsAOhBXKnYcjqeG+K04SuKmkuui+5tF9NhuM1LWcDcO7WLBKy5oUUoZmU28CktxV9uZsGtLStAYr1YR7+P+IGS1BZmHaOhOaBCjj9W1MC6UTpNQ/jV87vd0z3DisSKR1budCnARF6rHyA/BW+8t6e4ij4kXTut70a0xO7eT2y3tgmOSCVqiJBRvN4F/U7R0Wlrodkp0sPJEZPnTpcDB2xNubGphFLApflUREAfPKLZzC24uLDu0enm/YfwIKzz+ljYLJ4SPHwUwUvJrTFrfuX7eVN1jnzG9ZOO1xpp0tOAFGlqIEaUQ0tgIATDZQQ9hv045/bz8kDhjIgWmWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=bmGQnREBrqpjhoMUWsxJ9lF5y8O3G8+D6U9zDc5FJRY=; b=xA1LVZ8E02s/IiyEE5o2HrFvxT6oSY52ktbUbQ0MbeU9Gm4Le0pQLvuzLfK9eWnLEn0o+R3Hm+FFNhnw8+wYsj8FRhHn3uknEIcC59eH3TJA9kM3EyAmQqaDroIDCOwUrfHxnxCFlfUdYbgSw+0LzlnYZSug4iR0cyjHCivDmlIighILiHXzH5FFJjUYpWrUXKN/k8qziIMwV9Tegf+PBs/qgwoxQnwpgoZXIRIQeM4TDgONA/rsxtt15vDnFAVgoLvTMTroxdX4DfFxD8Ey2xVwFIAeELqVETgpTG3zQTkyefl/G/sSNqPJ3spvmQohzHfsEB0thmzXWzHvkB6sSw== 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 (0) 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=bmGQnREBrqpjhoMUWsxJ9lF5y8O3G8+D6U9zDc5FJRY=; b=WTADr1MoVUlzurQwbyuy27g6DSDZyzQ8OOwN4Z3vmcR+JyW/+dz133lQHxY1StAyUB+1/v1YGgLP2TdU8pMuRs1qIbrGaSaN8R60sjQqH12nCj4sUkW9HiDl5aQl9tcbNQGMCGqY3QdxFxHJb7ZPg/di9uJTGW5IlnhA9EmQlzo= Received: from SA0PR11CA0190.namprd11.prod.outlook.com (2603:10b6:806:1bc::15) by IA1PR12MB8335.namprd12.prod.outlook.com (2603:10b6:208:3fa::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16; Thu, 18 Jul 2024 10:33:00 +0000 Received: from SA2PEPF00003F64.namprd04.prod.outlook.com (2603:10b6:806:1bc:cafe::17) by SA0PR11CA0190.outlook.office365.com (2603:10b6:806:1bc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.29 via Frontend Transport; Thu, 18 Jul 2024 10:33:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF00003F64.mail.protection.outlook.com (10.167.248.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Thu, 18 Jul 2024 10:33:00 +0000 Received: from amd-X570-AORUS-ELITE.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.2507.39; Thu, 18 Jul 2024 05:32:57 -0500 From: Arunpravin Paneer Selvam To: , , , CC: , , , , Arunpravin Paneer Selvam Subject: [PATCH v6 1/2] drm/buddy: Add start address support to trim function Date: Thu, 18 Jul 2024 16:02:42 +0530 Message-ID: <20240718103243.1241392-1-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 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-TrafficTypeDiagnostic: SA2PEPF00003F64:EE_|IA1PR12MB8335:EE_ X-MS-Office365-Filtering-Correlation-Id: fb82938c-be76-45c4-e47a-08dca714ff4c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?IbMDXM9614kut6h65YqH3m0Y3uks+w1?= =?utf-8?q?eU8c3JGvTUZ9Qxqg4peHhsb9wLW0c0dXk9HyMQnG4gnmdH5B7OdJXpoe3ay42bTjV?= =?utf-8?q?Dp3DKy6Rk8+8plfahgIHZcrALWrOmw0We0TAg0uZSUCXyrzKw8m5mjfG9G8mPV4nK?= =?utf-8?q?+BHcEtdyEHbieafDWJOPu84RygXnpKh3pydO2+zk+XqcU6xpyogIoeRRIzENRUm5E?= =?utf-8?q?Cd/IBG+tO/AB/zF1HWTNgKpaO0ycFiQZ/NIT9+d5P/9WNINbKR6ecNy16Vjh5unMf?= =?utf-8?q?UbZVTF4+jDI/puTkM9bsf5RSz+SBFVMU0u8qckbLUzU8Md+pFUU95+/BqbOfqsA+G?= =?utf-8?q?/1uWP+sfvsF2gKR1JbtSdW7o/bCLUr+B21Kz7HpZNGolCnlLgPgfB8WfVQiLip0GJ?= =?utf-8?q?h93erJZF7JN804TZ6dEZM3/iv6UX11+MdecwDsXB4By9Nk+ogiO0EnZ8GXLmD0PeS?= =?utf-8?q?PwZvQQRoyN5DuXnxcgwhpKD3/iYIekixKuLom9oL8ZnfJ/jDlTyRco3BacK/OH0up?= =?utf-8?q?6Q6Prw6uWKRhWEOG1xQXyYvhV1qoRMADbY1ipVgEoa0rA62c/BH407HHyFb8RqXLs?= =?utf-8?q?GwWz7HAIUKx86WGmIvBVpaz6zP3ikpixwmYHTiJO/nLT+/NZdJ+rqJ77iayeChHJ1?= =?utf-8?q?ar5D4WFDP2Sq9wox0U1Y+XyLSwQeFZHuQ6TWX/aWK4U1wL+FRRrcxh3SkIs3u445r?= =?utf-8?q?omXeFaZ5CTApuQ28jCFrhe8nn5V0gSl4IwA1DqISzfGFDGlKBdEXPFujZqJeQxAkR?= =?utf-8?q?WoTYV6oatVYTrnAbORjL/C/1EmC4BvQgGip7x4kug3IwV1+1fNiemNZt3pW68WRSs?= =?utf-8?q?dX4vMbtj+4/8YeaBf+jAfAY1jE4VsGlpIy68YEyLjKqQqGE5DSAlDZb1ktR/EmRiN?= =?utf-8?q?uGE6TblwMITZYZaOHMTFGX7sk3aHHKapIpVF16uYECKPgKtK+8drwrewiSf9WCAjQ?= =?utf-8?q?JFdvIgrYyy9IPTVf5AJ3oaC+3bMZUmhjRjYdQH5uJMeW/sspz7so+vechwBK0IHDQ?= =?utf-8?q?OdaF5X/VlNJ6SJNI79IBF00upNFhyVHUyPyBxvCbhF6XL5AgezdjtZ94YqH63L6+H?= =?utf-8?q?i7pZ4ESrzBfbjyh4WJoQGO4pADX+o3z1RB43CeRiObG9wjrdatYaiaf+r3hFzumZc?= =?utf-8?q?8lxTyO7jZN1nUyF59i1TDpXe3Eeq+O59dT/vCBaphtXb+eSZ7gXWgwfK2x2JCau0o?= =?utf-8?q?gbAt08yhlFCq8OJNMqb5xrJgkhFRDO4TTuCy81U3iRoUjIfpcJiZhJFcG80YbpLTE?= =?utf-8?q?LYfEWR6OjsL5Z22AmpAnod6xh8VEPxQ2QVZ+BXVkVqi9FOKSYbxYAo6BdntZrj3pg?= =?utf-8?q?lTjGATd3BzoYv+x63Gcd+8mSXEuRYm8nsF/g2nG3ohogJWHZSYdKkGkMTds/8c6Xh?= =?utf-8?q?IDk0DnWQkKT?= 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:(13230040)(1800799024)(36860700013)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2024 10:33:00.3712 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fb82938c-be76-45c4-e47a-08dca714ff4c 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: SA2PEPF00003F64.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8335 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 a new start parameter in trim function to specify exact address from where to start the trimming. This would help us in situations like if drivers would like to do address alignment for specific requirements. - Add a new flag DRM_BUDDY_TRIM_DISABLE. Drivers can use this flag to disable the allocator trimming part. This patch enables the drivers control trimming and they can do it themselves based on the application requirements. v1:(Matthew) - check new_start alignment with min chunk_size - use range_overflows() Signed-off-by: Arunpravin Paneer Selvam Acked-by: Alex Deucher Acked-by: Christian König --- drivers/gpu/drm/drm_buddy.c | 25 +++++++++++++++++++++++-- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 2 +- include/drm/drm_buddy.h | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-) base-commit: 66d3fbb024886f8fbbc15fe79222f046cccd18c7 diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c index 6a8e45e9d0ec..103c185bb1c8 100644 --- a/drivers/gpu/drm/drm_buddy.c +++ b/drivers/gpu/drm/drm_buddy.c @@ -851,6 +851,7 @@ static int __alloc_contig_try_harder(struct drm_buddy *mm, * drm_buddy_block_trim - free unused pages * * @mm: DRM buddy manager + * @start: start address to begin the trimming. * @new_size: original size requested * @blocks: Input and output list of allocated blocks. * MUST contain single block as input to be trimmed. @@ -866,11 +867,13 @@ static int __alloc_contig_try_harder(struct drm_buddy *mm, * 0 on success, error code on failure. */ int drm_buddy_block_trim(struct drm_buddy *mm, + u64 *start, u64 new_size, struct list_head *blocks) { struct drm_buddy_block *parent; struct drm_buddy_block *block; + u64 block_start, block_end; LIST_HEAD(dfs); u64 new_start; int err; @@ -882,6 +885,9 @@ int drm_buddy_block_trim(struct drm_buddy *mm, struct drm_buddy_block, link); + block_start = drm_buddy_block_offset(block); + block_end = block_start + drm_buddy_block_size(mm, block); + if (WARN_ON(!drm_buddy_block_is_allocated(block))) return -EINVAL; @@ -894,6 +900,20 @@ int drm_buddy_block_trim(struct drm_buddy *mm, if (new_size == drm_buddy_block_size(mm, block)) return 0; + new_start = block_start; + if (start) { + new_start = *start; + + if (new_start < block_start) + return -EINVAL; + + if (!IS_ALIGNED(new_start, mm->chunk_size)) + return -EINVAL; + + if (range_overflows(new_start, new_size, block_end)) + return -EINVAL; + } + list_del(&block->link); mark_free(mm, block); mm->avail += drm_buddy_block_size(mm, block); @@ -904,7 +924,6 @@ int drm_buddy_block_trim(struct drm_buddy *mm, parent = block->parent; block->parent = NULL; - new_start = drm_buddy_block_offset(block); list_add(&block->tmp_link, &dfs); err = __alloc_range(mm, &dfs, new_start, new_size, blocks, NULL); if (err) { @@ -1066,7 +1085,8 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm, } while (1); /* Trim the allocated block to the required size */ - if (original_size != size) { + if (!(flags & DRM_BUDDY_TRIM_DISABLE) && + original_size != size) { struct list_head *trim_list; LIST_HEAD(temp); u64 trim_size; @@ -1083,6 +1103,7 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm, } drm_buddy_block_trim(mm, + NULL, trim_size, trim_list); diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c index fe3779fdba2c..423b261ea743 100644 --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c @@ -150,7 +150,7 @@ static int xe_ttm_vram_mgr_new(struct ttm_resource_manager *man, } while (remaining_size); if (place->flags & TTM_PL_FLAG_CONTIGUOUS) { - if (!drm_buddy_block_trim(mm, vres->base.size, &vres->blocks)) + if (!drm_buddy_block_trim(mm, NULL, vres->base.size, &vres->blocks)) size = vres->base.size; } diff --git a/include/drm/drm_buddy.h b/include/drm/drm_buddy.h index 2a74fa9d0ce5..9689a7c5dd36 100644 --- a/include/drm/drm_buddy.h +++ b/include/drm/drm_buddy.h @@ -27,6 +27,7 @@ #define DRM_BUDDY_CONTIGUOUS_ALLOCATION BIT(2) #define DRM_BUDDY_CLEAR_ALLOCATION BIT(3) #define DRM_BUDDY_CLEARED BIT(4) +#define DRM_BUDDY_TRIM_DISABLE BIT(5) struct drm_buddy_block { #define DRM_BUDDY_HEADER_OFFSET GENMASK_ULL(63, 12) @@ -155,6 +156,7 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm, unsigned long flags); int drm_buddy_block_trim(struct drm_buddy *mm, + u64 *start, u64 new_size, struct list_head *blocks); From patchwork Thu Jul 18 10:32:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 13736363 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 6FB7AC3DA49 for ; Thu, 18 Jul 2024 10:33:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5BEE910E72A; Thu, 18 Jul 2024 10:33:10 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="iVRkA4cQ"; dkim-atps=neutral Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2067.outbound.protection.outlook.com [40.107.223.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id A43FE10E722; Thu, 18 Jul 2024 10:33:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YdUMiu9PjdBnI0fBt+KeHOar3i5+rkkf1RYK1kr+JbJCqiHjtDs9IA6So0sBdWA0D5l20hfRSwtGPhdNk6QwPpUk9rTXCE+rAdPQVc4XfTabwprMl0q2lMlYWTpte+UODVXBHGH3i/t1oMqngvkytPCqd9Wv9KdTRhjG09os88A3zwDZyeNBMBwSYolQYt86UHmEwVARPF6mqZ4bX6HKCMW6w7LLUgIeN+Z8fL/XoRHvWKNj4JwSdjo6iQcj1I7NcUMx1d0rvq5Y/OvgMEOPyR2NKyfBBF/p9e20ByOuTpmHlHiy02WzQTliB0LeBSSNJ3zK10NveqvKTH5yRk0Lgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=dxrkv1Z2ayVOvAiUIfUH/SV2E19wNBQRuLKDOU3TAGQ=; b=wrwBWk/9+niRFC2URMLOwJcVOaPtqiCFs93A163TnnFlAgbkfoQrUYIjsaKUdneuvPVKn5nIP8fhDL4f/qjrx2LHWUROzuerf05Z1MsUNqH0aSZldKBdAizdCqu/OWuPi3nb33J11sKRSNVqqSmseDCVwZunmM4w7KA5gIEfBEI4lv64S6MxYi5axoazENWk6fUfjWZvav4dVVhvA1KPzIUgSxPMWMzGb7O2pjnoLCXLe2jOe1oAP0l2mNKxWhl+QYH77UKfqUfIg9q9ps71LzB/SJKIirJmM7YG5ErJPY61s99e3aLfpYGM/EK9LiDlSCmBOvaUbSiqzmZsvT+7LQ== 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 (0) 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=dxrkv1Z2ayVOvAiUIfUH/SV2E19wNBQRuLKDOU3TAGQ=; b=iVRkA4cQzQSFMeO/zYz/g0Um+0z7hyRHk3EUTqxsKgvLlrwbeOeOhWcQLWj7rKsW4gSyqGQvBhpig4FCdEqbxTlCdXTa49GQRSUkbNtNYlOFGZjSOttQ9jwuoezh9DUgZJCoAl8m4D1jdRROWBcCvFpYQ/snL0hw8m6pCfLIUr4= Received: from SA1P222CA0045.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:2d0::22) by PH7PR12MB7794.namprd12.prod.outlook.com (2603:10b6:510:276::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.35; Thu, 18 Jul 2024 10:33:03 +0000 Received: from SA2PEPF00003F62.namprd04.prod.outlook.com (2603:10b6:806:2d0:cafe::46) by SA1P222CA0045.outlook.office365.com (2603:10b6:806:2d0::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.17 via Frontend Transport; Thu, 18 Jul 2024 10:33:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SA2PEPF00003F62.mail.protection.outlook.com (10.167.248.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7784.11 via Frontend Transport; Thu, 18 Jul 2024 10:33:03 +0000 Received: from amd-X570-AORUS-ELITE.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.2507.39; Thu, 18 Jul 2024 05:33:00 -0500 From: Arunpravin Paneer Selvam To: , , , CC: , , , , Arunpravin Paneer Selvam , Frank Min Subject: [PATCH v6 2/2] drm/amdgpu: Add address alignment support to DCC buffers Date: Thu, 18 Jul 2024 16:02:43 +0530 Message-ID: <20240718103243.1241392-2-Arunpravin.PaneerSelvam@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240718103243.1241392-1-Arunpravin.PaneerSelvam@amd.com> References: <20240718103243.1241392-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-TrafficTypeDiagnostic: SA2PEPF00003F62:EE_|PH7PR12MB7794:EE_ X-MS-Office365-Filtering-Correlation-Id: 638cb41a-4dd1-4d26-c00d-08dca7150127 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?q?PJfBmQ+ByYc61GhDvvkWGqWxgjVyNj6?= =?utf-8?q?Z+5x71QUMiazRK1ZH/6a1xnfN8LsffRF6SulyUcaO4rESUreZWMUrmjhHiIFpTiFV?= =?utf-8?q?235vVtWgVtbQtBHXBem+Wic9w2pi2w9mq+LxBXWmlDYPhtshLS/CrAz48CZ+aEbd/?= =?utf-8?q?WgDmafmXE2bDm23F4CSyZsCQOKQxRgI/yAcFP1ITSXoZRlvsuVnhx+ZMDT0KGlsWE?= =?utf-8?q?hNeOafdgiMTOL+pdTAyOqDy+uoR/vsBXQ/fNenMHgHsNeh8V0bY+IV8k7wB9esC8V?= =?utf-8?q?FX0EpyclujrZXiMjaAHuX57iF/W6ajfskx7beFVGLNqMjFy6o5/eywlMEZnvp5UGK?= =?utf-8?q?Lyl5YSYaSaGqk43g/VpIElBn0/98cRdpqtozTtxZyGJL5tUbwWL47i8x0CPj9xlPZ?= =?utf-8?q?4qjuxILBIAQVTMfRTpHfqzTaRS8LvmNjYj4xeBAswHiaPyWTK5mtFuzCxgTyp946o?= =?utf-8?q?PiadPPcKkkk22WzmhyUfZjaJuKGoxo9yBnMn4y0IaJJfImwRrHsqDGtaQZLUK4avD?= =?utf-8?q?Z8Qby3geVcqgjqtbNREevrYvKmdIUJwJdtT4jNoQAk5jTNXb1RpOB1EhTUhN3R83z?= =?utf-8?q?Tbw/efDz6oJiJpcGejSp7+gg+cwJhIDmpkKizM2mF+ViLGUkCEVnKEdcluqXtaErb?= =?utf-8?q?cJW5P4Wj0OVIb0BDdSFs0wL7z43d/s+VyJZvC8mEHRjo1Qh9+xYLdgKWfvq1CIxQV?= =?utf-8?q?n3BdR8RTgg84DLHpwsztjJ8CaqcYW02yF167jb276YDJff7Lgrx3Z8fI8RTtP1IZt?= =?utf-8?q?9Vro0mnJv0wj/wpFsBS8QmDrOWCSsMwtii1tRZ/Pf/zmImb1BQUverbAo76tlN0u5?= =?utf-8?q?vGa78f3APu5yeMGvqIvY+J9h6hnlEvZfL/m53+AUkG5wWo7gr5zu0H0OhpN+8qjk4?= =?utf-8?q?d4E6a6z+IQMLy4gmmXeZ58qNPBSQLQQ7NisEGrHZOka/Xgu1A/Yz/NzlOP+7TNiMI?= =?utf-8?q?i4sAmPD2Tj5VmkzESBYKxcIvso2RNoqOTAQbUoiH2ZjplwZP29MdFdTKRRPfUzW28?= =?utf-8?q?NEZ8Vm9nLh8sn2qzEviZyeMIdd+m8JHZHm7t4qDyx5HsfmLPWB49me9VysViy8b6M?= =?utf-8?q?00g5j5ICS0b1KQ7ZzQgrbD1pF5PNEfHPGwTj8oojKVPh7PCVv0g/42hJovTm7dSeZ?= =?utf-8?q?X5X2lbMnpkTMzOtZiYi4wuX0xxBmjEn4FsaqabOfSPuhX4wHQFImQxZSORkhogC6f?= =?utf-8?q?5418Y1LDyWKKBftcxNx3eiiY3ijsQ0bHcwAymeQBvFVkRyXD+uGZ4j4y/jIWpCCjN?= =?utf-8?q?AwCPZW1Js13jNklrMaJqWYGtxe9chZxtqlZBNz4BVtJ6pB6XDD6N/Fd1W6xqFVrMV?= =?utf-8?q?vBWR/4HV3VM7pLuVqrrhSW7cSx38I6AlDBjTYeoZ041uI7PpX2Lbos8DN7gT+TEEE?= =?utf-8?q?hfZEM33FubC?= 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:(13230040)(36860700013)(82310400026)(376014)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jul 2024 10:33:03.4520 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 638cb41a-4dd1-4d26-c00d-08dca7150127 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: SA2PEPF00003F62.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7794 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 address alignment support to the DCC VRAM buffers. v2: - adjust size based on the max_texture_channel_caches values only for GFX12 DCC buffers. - used AMDGPU_GEM_CREATE_GFX12_DCC flag to apply change only for DCC buffers. - roundup non power of two DCC buffer adjusted size to nearest power of two number as the buddy allocator does not support non power of two alignments. This applies only to the contiguous DCC buffers. v3:(Alex) - rewrite the max texture channel caches comparison code in an algorithmic way to determine the alignment size. v4:(Alex) - Move the logic from amdgpu_vram_mgr_dcc_alignment() to gmc_v12_0.c and add a new gmc func callback for dcc alignment. If the callback is non-NULL, call it to get the alignment, otherwise, use the default. v5:(Alex) - Set the Alignment to a default value if the callback doesn't exist. - Add the callback to amdgpu_gmc_funcs. v6: - Fix checkpatch warning reported by Intel CI. v7:(Christian) - remove the AMDGPU_GEM_CREATE_GFX12_DCC flag and keep a flag that checks the BO pinning and for a specific hw generation. Signed-off-by: Arunpravin Paneer Selvam Acked-by: Alex Deucher Acked-by: Christian König Reviewed-by: Frank Min --- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 6 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 39 +++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 15 ++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h index febca3130497..654d0548a3f8 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h @@ -156,6 +156,8 @@ struct amdgpu_gmc_funcs { uint64_t addr, uint64_t *flags); /* get the amount of memory used by the vbios for pre-OS console */ unsigned int (*get_vbios_fb_size)(struct amdgpu_device *adev); + /* get the DCC buffer alignment */ + u64 (*get_dcc_alignment)(struct amdgpu_device *adev); enum amdgpu_memory_partition (*query_mem_partition_mode)( struct amdgpu_device *adev); @@ -363,6 +365,10 @@ struct amdgpu_gmc { (adev)->gmc.gmc_funcs->override_vm_pte_flags \ ((adev), (vm), (addr), (pte_flags)) #define amdgpu_gmc_get_vbios_fb_size(adev) (adev)->gmc.gmc_funcs->get_vbios_fb_size((adev)) +#define amdgpu_gmc_get_dcc_alignment(_adev) ({ \ + typeof(_adev) (adev) = (_adev); \ + ((adev)->gmc.gmc_funcs->get_dcc_alignment((adev))); \ +}) /** * amdgpu_gmc_vram_full_visible - Check if full VRAM is visible through the BAR diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c index f91cc149d06c..ace9d61fc512 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c @@ -512,6 +512,17 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, vres->flags |= DRM_BUDDY_RANGE_ALLOCATION; remaining_size = (u64)vres->base.size; + if (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS && + (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(12, 0, 0) || + amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(12, 0, 1))) { + u64 adjust_size; + + if (adev->gmc.gmc_funcs->get_dcc_alignment) { + adjust_size = amdgpu_gmc_get_dcc_alignment(adev); + remaining_size = roundup_pow_of_two(remaining_size + adjust_size); + vres->flags |= DRM_BUDDY_TRIM_DISABLE; + } + } mutex_lock(&mgr->lock); while (remaining_size) { @@ -521,8 +532,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, min_block_size = mgr->default_page_size; size = remaining_size; - if ((size >= (u64)pages_per_block << PAGE_SHIFT) && - !(size & (((u64)pages_per_block << PAGE_SHIFT) - 1))) + + if (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS && + (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(12, 0, 0) || + amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(12, 0, 1))) + min_block_size = size; + else if ((size >= (u64)pages_per_block << PAGE_SHIFT) && + !(size & (((u64)pages_per_block << PAGE_SHIFT) - 1))) min_block_size = (u64)pages_per_block << PAGE_SHIFT; BUG_ON(min_block_size < mm->chunk_size); @@ -553,6 +569,25 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, } mutex_unlock(&mgr->lock); + if (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS && + (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(12, 0, 0) || + amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(12, 0, 1))) { + struct drm_buddy_block *dcc_block; + u64 dcc_start, alignment; + + dcc_block = amdgpu_vram_mgr_first_block(&vres->blocks); + dcc_start = amdgpu_vram_mgr_block_start(dcc_block); + + if (adev->gmc.gmc_funcs->get_dcc_alignment) { + alignment = amdgpu_gmc_get_dcc_alignment(adev); + /* Adjust the start address for DCC buffers only */ + dcc_start = roundup(dcc_start, alignment); + drm_buddy_block_trim(mm, &dcc_start, + (u64)vres->base.size, + &vres->blocks); + } + } + vres->base.start = 0; size = max_t(u64, amdgpu_vram_mgr_blocks_size(&vres->blocks), vres->base.size); diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c index fd3ac483760e..4259edcdec8a 100644 --- a/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c @@ -542,6 +542,20 @@ static unsigned gmc_v12_0_get_vbios_fb_size(struct amdgpu_device *adev) return 0; } +static u64 gmc_v12_0_get_dcc_alignment(struct amdgpu_device *adev) +{ + u64 max_tex_channel_caches, alignment; + + max_tex_channel_caches = adev->gfx.config.max_texture_channel_caches; + if (is_power_of_2(max_tex_channel_caches)) + alignment = (max_tex_channel_caches / SZ_4) * max_tex_channel_caches; + else + alignment = roundup_pow_of_two(max_tex_channel_caches) * + max_tex_channel_caches; + + return (u64)alignment * SZ_1K; +} + static const struct amdgpu_gmc_funcs gmc_v12_0_gmc_funcs = { .flush_gpu_tlb = gmc_v12_0_flush_gpu_tlb, .flush_gpu_tlb_pasid = gmc_v12_0_flush_gpu_tlb_pasid, @@ -551,6 +565,7 @@ static const struct amdgpu_gmc_funcs gmc_v12_0_gmc_funcs = { .get_vm_pde = gmc_v12_0_get_vm_pde, .get_vm_pte = gmc_v12_0_get_vm_pte, .get_vbios_fb_size = gmc_v12_0_get_vbios_fb_size, + .get_dcc_alignment = gmc_v12_0_get_dcc_alignment, }; static void gmc_v12_0_set_gmc_funcs(struct amdgpu_device *adev)