From patchwork Tue Oct 19 22:53:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Paneer Selvam, Arunpravin" X-Patchwork-Id: 12571295 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 6F96DC433FE for ; Tue, 19 Oct 2021 22:55:16 +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 36F31610E5 for ; Tue, 19 Oct 2021 22:55:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 36F31610E5 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 4A2976E0D0; Tue, 19 Oct 2021 22:55:12 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2046.outbound.protection.outlook.com [40.107.237.46]) by gabe.freedesktop.org (Postfix) with ESMTPS id A3E376E0EF; Tue, 19 Oct 2021 22:55:08 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HGPN5VNAanlYwrTt9xd3WCDya+2FTqIrPGV2dhk/9SeN9JuAqYmiEH5tyisFpcoCHBgcIv7k3yk6n4kw/9DxgcPawnsjX+FtVql/dVHPkmFa2LJlyLl+wpRnYPh4Gi1ScNN/pXylUoZdA4ukaoG2dOdTYgxvzb2/AFTdlSThzMZ6GxkUimeuHnOJ9TZncaNghto/8bqMrVW0bYPTo9PqMoH4xoHbfO43hH0ZtWoFYKs0i0E2LeLnm2Incwb4XMuJYd2gzC2fWka23TtDNXHpo8Vw9U7I84YkfPOwy8YESxp5v05YzrVTlwF9XdfBYbKk7IAcaLjspNLb1F9o6BUC1g== 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=uPWUo3nL8XofUi7QE/IkICyRWq76/xXcvPXez7GLvmM=; b=BtD8S/dpmebctBYOV9lWxZ4BM4iFYc6+VtRmoqmrIvZhLArHAVhHJ16YvvCY4itM96yCvHgUqFk6860iXXMzUYT/7KQxvfilaAhEZZzqk5JL9G3/62hrw2AqZR99OyYNBRHq2m3PkTMw3+aQkdbtoaLdoGQ7jsml81v8nlQTfWiEfC/1Ok688yT1pcCeQ03csuxT+di5DC45eg6lV9w0/1/+/SKUycT/54ECxTzMjvSpEvaGIr6xlRGDXsEq+L/X4+I9pDYLYj3sE4G+vYm2Udmh4703tm2IuY4jwXadMg8zz4peD21+qg+iJW/36sfmO3lcMTAsDaARvXgdIL/Iqw== 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=uPWUo3nL8XofUi7QE/IkICyRWq76/xXcvPXez7GLvmM=; b=vK6a9SatudP/YuQV16cnDbZlLSETxmVJ443AAL53UeQtGrVWT6gaqSpalQDTfIfw6YgEtDH/xry2F3HxFg6wvcFZl1r8dPerk4osuk0sltXlgZ4Rfa/urRwGxO7CfY+b7EW+87VboVCSdrHHiOWF1DDqcs6OUAn4TCePjl0oHFE= Received: from MW3PR06CA0018.namprd06.prod.outlook.com (2603:10b6:303:2a::23) by MN2PR12MB4032.namprd12.prod.outlook.com (2603:10b6:208:16d::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Tue, 19 Oct 2021 22:55:05 +0000 Received: from CO1NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2a:cafe::dd) by MW3PR06CA0018.outlook.office365.com (2603:10b6:303:2a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 22:55:04 +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 CO1NAM11FT019.mail.protection.outlook.com (10.13.175.57) 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:04 +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:00 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 01/13] drm: Move and rename i915 buddy header Date: Wed, 20 Oct 2021 04:23:57 +0530 Message-ID: <20211019225409.569355-2-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: 4befc00b-07fb-4212-460a-08d993537d5e X-MS-TrafficTypeDiagnostic: MN2PR12MB4032: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1468; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: izYWwVHZnA756rk9bJQg0bUdA0mLqEJWTFxi+cctWaxATR2EJGwcl+ZvnzMV78Hr6Bv3JOt2M4otZL5ZTbw/QUq16/J3bFr1SrqjR3AMgSB1esviS0aE5Guq0yxac+o0pnGfv601SQCwQCW0n+186plyQOu7pF1JuHSQNY4+MAoKZ64Cl/S3/ymIrOtNnueozN5k6S5xrat+1oje9ciAx0gcDZSNHm7TA/2SmLpdNHSUtDRkLQxK4vuj+r8uA9e99HCMjlYCRDmHvX5dKudkalorzniqNdIgNm4IQSBNRoi7d2gz5x0HXQ2t5WCXUPF9TKXrZth9end/K1HKk1+UCPtF/gdJezeWeKCIbkzF4YYCejuEqDBi5ujDIwWDpd3ZDugXOpX5CXEtjDRkk7lVA9kU3T4LConLNDNo16WOC6DiDeNO89qFnyKwxb0lP0QxCJQlW91Zoc5qJstaM8SJXlnbJZbKDHqi+nfANirauPV4w9cdfue4zkWoxOzDEihrD2EOJ7IIRmh2/s8+8/T7t7T3m/Crm6Cvb66nr9XfLdwDmk8Q7jGqKW9Xpy1RB3Quj6XTEBcxM0zsLgFz30rqQw9ZJohd4JFL3bB8ljq222rDK2HruB2qDFYVD5xzX9/Yuvf/1NI87Ypq0J7p+WFQcvxq3K18FL+s1btthKF39Jk7iilXIyJPTLiIF190U3oDisVyyACIAMA5GOAVcKPcIJPem18N5CTE+0zM8eLlCTYxchKLNkBI9Jrpxd35qRAb 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)(36840700001)(46966006)(83380400001)(16526019)(7696005)(6666004)(110136005)(54906003)(508600001)(2616005)(8676002)(186003)(81166007)(86362001)(2906002)(356005)(70206006)(5660300002)(70586007)(336012)(26005)(36756003)(1076003)(8936002)(36860700001)(82310400003)(426003)(4326008)(316002)(47076005)(134034003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:04.2975 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4befc00b-07fb-4212-460a-08d993537d5e 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: CO1NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4032 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - Move i915_buddy.h to include/drm - rename "i915" string to "drm" - rename "I915" string to "DRM" Signed-off-by: Arunpravin --- drivers/gpu/drm/i915/i915_buddy.h | 143 ------------------------------ include/drm/drm_buddy.h | 143 ++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 143 deletions(-) delete mode 100644 drivers/gpu/drm/i915/i915_buddy.h create mode 100644 include/drm/drm_buddy.h diff --git a/drivers/gpu/drm/i915/i915_buddy.h b/drivers/gpu/drm/i915/i915_buddy.h deleted file mode 100644 index 7077742112ac..000000000000 --- a/drivers/gpu/drm/i915/i915_buddy.h +++ /dev/null @@ -1,143 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * Copyright © 2021 Intel Corporation - */ - -#ifndef __I915_BUDDY_H__ -#define __I915_BUDDY_H__ - -#include -#include -#include - -#include - -struct i915_buddy_block { -#define I915_BUDDY_HEADER_OFFSET GENMASK_ULL(63, 12) -#define I915_BUDDY_HEADER_STATE GENMASK_ULL(11, 10) -#define I915_BUDDY_ALLOCATED (1 << 10) -#define I915_BUDDY_FREE (2 << 10) -#define I915_BUDDY_SPLIT (3 << 10) -/* Free to be used, if needed in the future */ -#define I915_BUDDY_HEADER_UNUSED GENMASK_ULL(9, 6) -#define I915_BUDDY_HEADER_ORDER GENMASK_ULL(5, 0) - u64 header; - - struct i915_buddy_block *left; - struct i915_buddy_block *right; - struct i915_buddy_block *parent; - - void *private; /* owned by creator */ - - /* - * While the block is allocated by the user through i915_buddy_alloc*, - * the user has ownership of the link, for example to maintain within - * a list, if so desired. As soon as the block is freed with - * i915_buddy_free* ownership is given back to the mm. - */ - struct list_head link; - struct list_head tmp_link; -}; - -/* Order-zero must be at least PAGE_SIZE */ -#define I915_BUDDY_MAX_ORDER (63 - PAGE_SHIFT) - -/* - * Binary Buddy System. - * - * Locking should be handled by the user, a simple mutex around - * i915_buddy_alloc* and i915_buddy_free* should suffice. - */ -struct i915_buddy_mm { - /* Maintain a free list for each order. */ - struct list_head *free_list; - - /* - * Maintain explicit binary tree(s) to track the allocation of the - * address space. This gives us a simple way of finding a buddy block - * and performing the potentially recursive merge step when freeing a - * block. Nodes are either allocated or free, in which case they will - * also exist on the respective free list. - */ - struct i915_buddy_block **roots; - - /* - * Anything from here is public, and remains static for the lifetime of - * the mm. Everything above is considered do-not-touch. - */ - unsigned int n_roots; - unsigned int max_order; - - /* Must be at least PAGE_SIZE */ - u64 chunk_size; - u64 size; - u64 avail; -}; - -static inline u64 -i915_buddy_block_offset(struct i915_buddy_block *block) -{ - return block->header & I915_BUDDY_HEADER_OFFSET; -} - -static inline unsigned int -i915_buddy_block_order(struct i915_buddy_block *block) -{ - return block->header & I915_BUDDY_HEADER_ORDER; -} - -static inline unsigned int -i915_buddy_block_state(struct i915_buddy_block *block) -{ - return block->header & I915_BUDDY_HEADER_STATE; -} - -static inline bool -i915_buddy_block_is_allocated(struct i915_buddy_block *block) -{ - return i915_buddy_block_state(block) == I915_BUDDY_ALLOCATED; -} - -static inline bool -i915_buddy_block_is_free(struct i915_buddy_block *block) -{ - return i915_buddy_block_state(block) == I915_BUDDY_FREE; -} - -static inline bool -i915_buddy_block_is_split(struct i915_buddy_block *block) -{ - return i915_buddy_block_state(block) == I915_BUDDY_SPLIT; -} - -static inline u64 -i915_buddy_block_size(struct i915_buddy_mm *mm, - struct i915_buddy_block *block) -{ - return mm->chunk_size << i915_buddy_block_order(block); -} - -int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size); - -void i915_buddy_fini(struct i915_buddy_mm *mm); - -struct i915_buddy_block * -i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order); - -int i915_buddy_alloc_range(struct i915_buddy_mm *mm, - struct list_head *blocks, - u64 start, u64 size); - -void i915_buddy_free(struct i915_buddy_mm *mm, struct i915_buddy_block *block); - -void i915_buddy_free_list(struct i915_buddy_mm *mm, struct list_head *objects); - -void i915_buddy_print(struct i915_buddy_mm *mm, struct drm_printer *p); -void i915_buddy_block_print(struct i915_buddy_mm *mm, - struct i915_buddy_block *block, - struct drm_printer *p); - -void i915_buddy_module_exit(void); -int i915_buddy_module_init(void); - -#endif diff --git a/include/drm/drm_buddy.h b/include/drm/drm_buddy.h new file mode 100644 index 000000000000..521ed532d2b8 --- /dev/null +++ b/include/drm/drm_buddy.h @@ -0,0 +1,143 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2021 Intel Corporation + */ + +#ifndef __DRM_BUDDY_H__ +#define __DRM_BUDDY_H__ + +#include +#include +#include + +#include + +struct drm_buddy_block { +#define DRM_BUDDY_HEADER_OFFSET GENMASK_ULL(63, 12) +#define DRM_BUDDY_HEADER_STATE GENMASK_ULL(11, 10) +#define DRM_BUDDY_ALLOCATED (1 << 10) +#define DRM_BUDDY_FREE (2 << 10) +#define DRM_BUDDY_SPLIT (3 << 10) +/* Free to be used, if needed in the future */ +#define DRM_BUDDY_HEADER_UNUSED GENMASK_ULL(9, 6) +#define DRM_BUDDY_HEADER_ORDER GENMASK_ULL(5, 0) + u64 header; + + struct drm_buddy_block *left; + struct drm_buddy_block *right; + struct drm_buddy_block *parent; + + void *private; /* owned by creator */ + + /* + * While the block is allocated by the user through drm_buddy_alloc*, + * the user has ownership of the link, for example to maintain within + * a list, if so desired. As soon as the block is freed with + * drm_buddy_free* ownership is given back to the mm. + */ + struct list_head link; + struct list_head tmp_link; +}; + +/* Order-zero must be at least PAGE_SIZE */ +#define DRM_BUDDY_MAX_ORDER (63 - PAGE_SHIFT) + +/* + * Binary Buddy System. + * + * Locking should be handled by the user, a simple mutex around + * drm_buddy_alloc* and drm_buddy_free* should suffice. + */ +struct drm_buddy_mm { + /* Maintain a free list for each order. */ + struct list_head *free_list; + + /* + * Maintain explicit binary tree(s) to track the allocation of the + * address space. This gives us a simple way of finding a buddy block + * and performing the potentially recursive merge step when freeing a + * block. Nodes are either allocated or free, in which case they will + * also exist on the respective free list. + */ + struct drm_buddy_block **roots; + + /* + * Anything from here is public, and remains static for the lifetime of + * the mm. Everything above is considered do-not-touch. + */ + unsigned int n_roots; + unsigned int max_order; + + /* Must be at least PAGE_SIZE */ + u64 chunk_size; + u64 size; + u64 avail; +}; + +static inline u64 +drm_buddy_block_offset(struct drm_buddy_block *block) +{ + return block->header & DRM_BUDDY_HEADER_OFFSET; +} + +static inline unsigned int +drm_buddy_block_order(struct drm_buddy_block *block) +{ + return block->header & DRM_BUDDY_HEADER_ORDER; +} + +static inline unsigned int +drm_buddy_block_state(struct drm_buddy_block *block) +{ + return block->header & DRM_BUDDY_HEADER_STATE; +} + +static inline bool +drm_buddy_block_is_allocated(struct drm_buddy_block *block) +{ + return drm_buddy_block_state(block) == DRM_BUDDY_ALLOCATED; +} + +static inline bool +drm_buddy_block_is_free(struct drm_buddy_block *block) +{ + return drm_buddy_block_state(block) == DRM_BUDDY_FREE; +} + +static inline bool +drm_buddy_block_is_split(struct drm_buddy_block *block) +{ + return drm_buddy_block_state(block) == DRM_BUDDY_SPLIT; +} + +static inline u64 +drm_buddy_block_size(struct drm_buddy_mm *mm, + struct drm_buddy_block *block) +{ + return mm->chunk_size << drm_buddy_block_order(block); +} + +int drm_buddy_init(struct drm_buddy_mm *mm, u64 size, u64 chunk_size); + +void drm_buddy_fini(struct drm_buddy_mm *mm); + +struct drm_buddy_block * +drm_buddy_alloc(struct drm_buddy_mm *mm, unsigned int order); + +int drm_buddy_alloc_range(struct drm_buddy_mm *mm, + struct list_head *blocks, + u64 start, u64 size); + +void drm_buddy_free(struct drm_buddy_mm *mm, struct drm_buddy_block *block); + +void drm_buddy_free_list(struct drm_buddy_mm *mm, struct list_head *objects); + +void drm_buddy_print(struct drm_buddy_mm *mm, struct drm_printer *p); +void drm_buddy_block_print(struct drm_buddy_mm *mm, + struct drm_buddy_block *block, + struct drm_printer *p); + +void drm_buddy_module_exit(void); +int drm_buddy_module_init(void); + +#endif From patchwork Tue Oct 19 22:53:58 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: 12571297 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 7F442C433FE for ; Tue, 19 Oct 2021 22:55:21 +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 4C005610E5 for ; Tue, 19 Oct 2021 22:55:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4C005610E5 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 330ED6E0F6; Tue, 19 Oct 2021 22:55:16 +0000 (UTC) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2075.outbound.protection.outlook.com [40.107.243.75]) by gabe.freedesktop.org (Postfix) with ESMTPS id 110C36E10A; Tue, 19 Oct 2021 22:55:13 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kHuqUt8kVJAnP7r9f4kJyUBYXM3kcpKB6CheEHNfphb/gwqNjq84Ql5qOuXCflU5R8bLWucMqBrI3IYmPX7sQOcI3ktIY6KlCh6lxRGFvZL0rWYaWJvX18GPG+xZVBeMlN8TWsaLIXRAXQlAN/tsqGjP4HOJ/Xhh0Wz3EmTlvlxziFn6a2F+CBZ8cguGzvXUvAtPF2S/yeb4ZiRq3bTggTqosWqfzIsW7GHLhF5r1Almz0xTOcpdmsrVvcj8225kbPJhY7Zm3ijaBagLFkxA/wtos2V9hRmAWl0MfeL1e0RxdIgwHiEENLu0MHVi/mGCgc1ZF2S4CugKAuJXqB/R+A== 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=8UQLfaQosOU9A/dy6MEOwKmrmN92wiiTdpAlP1X7b/c=; b=jLdylhWc8wzoVJTsUKxs/4g5dty/esRDNNTPZ1eVA2n6nJTuwGByXzAFVeQzcYYJxzseBC/avDKL/PRmexkoARgyxy5rxrlOwwiejBbpdtZ2By8eNLZBwlIf94bE3SbRLCBOPTO0HrVXBuEKn4d7TBCOALuKRvw9/xbZfelGBzsqV4RCUIM+k+sYSdVzSRVZmWwMapt0nqH0elUtGxYzrj/DX+dGEJbkFcF11Xf/Fwee5BwuofjLnlZ6HBzp4R1yQ96xCZE6yra99IwKJBweoeHv7yLcjpc1+6MMAZoR1vPso0/5enYCGDjLZMvZnxeAyvM3ul9AwkLxYs52frXdDQ== 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=8UQLfaQosOU9A/dy6MEOwKmrmN92wiiTdpAlP1X7b/c=; b=PBrNB3KtYerqM1asPZrmks5+duEOAPiDMI5vs4Bag3OZN+0GYrv1W0qB8drwRYJEv9sXOPvhymEbkKGgzVXp7Brc+Q+iKm8VcsD1TfbX94/DVi4nl++p+xDob578Re1BfQr/Dp+UCvEFcoBfy43TOrxztqVpgrznDlfGNZNDt1E= Received: from MW3PR06CA0020.namprd06.prod.outlook.com (2603:10b6:303:2a::25) by MN2PR12MB3261.namprd12.prod.outlook.com (2603:10b6:208:108::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.17; Tue, 19 Oct 2021 22:55:07 +0000 Received: from CO1NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2a:cafe::29) by MW3PR06CA0020.outlook.office365.com (2603:10b6:303:2a::25) 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:07 +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 CO1NAM11FT035.mail.protection.outlook.com (10.13.175.36) 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:07 +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:03 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 02/13] drm: Move and rename i915 buddy source Date: Wed, 20 Oct 2021 04:23:58 +0530 Message-ID: <20211019225409.569355-3-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: 92a98d33-5ba7-4e70-6a32-08d993537f32 X-MS-TrafficTypeDiagnostic: MN2PR12MB3261: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vtUrZLwTFMTlYWhvIfqmsIQ1RGc0c81uoWj0lr9SfW8NK7+TWPyXvDt4g5KPjARA0NluAozYVFcIxhFAyaHBVK2fLbtwgSZX5iEnT+r8C2/AgdAMpqLtSkTTT+2ZnU5mNi9GK0wsm90rqPYIMBeozD4pPBtHHbHKEaxt3ccD5RsBVlWq11V4LeoMcNQV6d5rA2Fd8fYUVjQsVpxAFvYCyfRZty5PzMHkAOXzvyIDm+MguP1JBGT28e3bZPfu3lHkeKfGtj9IAFR+s6WAUme7WXdiLhl96zNPfx+8lNo48vaTNYeTOuT/ZQvYJj/L+ofeMuZlaTbGrt1X7CVwGC42NY8+lcwvEim/AUXYPnCMps4k9OfggwqWWtpKa0c903Xz+c+iE+QR5P/34uQq5hk2bi+CkT4Mvbpw2hdxCB69ZjQu4VA58taSdq0SAbhMzJI64tPEJGh24ZPbo4u8rz3KjMLH0tvKNAxWICH8wK6A/jgbMLyjcT0gtR224tBc4Qkc3b9787ZUwDfpYDvlL4pYDFlWwtQj5J14445YsHbS8/QyW3/G6XEPK4NXm3kQ1Os7hkcODA9yTn8JGA4k6YKzPZ8uH+TF44yieNYiwJ8VvYgfBk4AV+CGLdcspdqdx579/weAnb95Bc5aA+8EoeFsTVBzLmIlzj0aSshiNOVxWK3zvZuJdXNdjtyeIwC+ddKGvw7LLd9aM90h71i5LY2EG7COxfO6iif/JtvjN1KRpUU= 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)(36840700001)(46966006)(508600001)(36860700001)(2906002)(2616005)(4326008)(336012)(30864003)(5660300002)(426003)(8936002)(47076005)(26005)(1076003)(8676002)(16526019)(186003)(316002)(54906003)(83380400001)(110136005)(7696005)(70586007)(86362001)(36756003)(70206006)(82310400003)(6666004)(356005)(81166007)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:07.3306 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 92a98d33-5ba7-4e70-6a32-08d993537f32 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: CO1NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3261 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - Move i915_buddy.c to drm root folder - Rename "i915" string with "drm" string wherever applicable - Rename "I915" string with "DRM" string wherever applicable - Fix header file dependencies - Fix alignment issues Signed-off-by: Arunpravin --- .../drm/{i915/i915_buddy.c => drm_buddy.c} | 193 +++++++++--------- include/drm/drm_buddy.h | 10 + 2 files changed, 105 insertions(+), 98 deletions(-) rename drivers/gpu/drm/{i915/i915_buddy.c => drm_buddy.c} (58%) diff --git a/drivers/gpu/drm/i915/i915_buddy.c b/drivers/gpu/drm/drm_buddy.c similarity index 58% rename from drivers/gpu/drm/i915/i915_buddy.c rename to drivers/gpu/drm/drm_buddy.c index 6e2ad68f8f3f..0398706cb7ae 100644 --- a/drivers/gpu/drm/i915/i915_buddy.c +++ b/drivers/gpu/drm/drm_buddy.c @@ -6,21 +6,18 @@ #include #include -#include "i915_buddy.h" - -#include "i915_gem.h" -#include "i915_utils.h" +#include static struct kmem_cache *slab_blocks; -static struct i915_buddy_block *i915_block_alloc(struct i915_buddy_mm *mm, - struct i915_buddy_block *parent, - unsigned int order, - u64 offset) +static struct drm_buddy_block *drm_block_alloc(struct drm_buddy_mm *mm, + struct drm_buddy_block *parent, + unsigned int order, + u64 offset) { - struct i915_buddy_block *block; + struct drm_buddy_block *block; - GEM_BUG_ON(order > I915_BUDDY_MAX_ORDER); + BUG_ON(order > DRM_BUDDY_MAX_ORDER); block = kmem_cache_zalloc(slab_blocks, GFP_KERNEL); if (!block) @@ -30,43 +27,43 @@ static struct i915_buddy_block *i915_block_alloc(struct i915_buddy_mm *mm, block->header |= order; block->parent = parent; - GEM_BUG_ON(block->header & I915_BUDDY_HEADER_UNUSED); + BUG_ON(block->header & DRM_BUDDY_HEADER_UNUSED); return block; } -static void i915_block_free(struct i915_buddy_mm *mm, - struct i915_buddy_block *block) +static void drm_block_free(struct drm_buddy_mm *mm, + struct drm_buddy_block *block) { kmem_cache_free(slab_blocks, block); } -static void mark_allocated(struct i915_buddy_block *block) +static void mark_allocated(struct drm_buddy_block *block) { - block->header &= ~I915_BUDDY_HEADER_STATE; - block->header |= I915_BUDDY_ALLOCATED; + block->header &= ~DRM_BUDDY_HEADER_STATE; + block->header |= DRM_BUDDY_ALLOCATED; list_del(&block->link); } -static void mark_free(struct i915_buddy_mm *mm, - struct i915_buddy_block *block) +static void mark_free(struct drm_buddy_mm *mm, + struct drm_buddy_block *block) { - block->header &= ~I915_BUDDY_HEADER_STATE; - block->header |= I915_BUDDY_FREE; + block->header &= ~DRM_BUDDY_HEADER_STATE; + block->header |= DRM_BUDDY_FREE; list_add(&block->link, - &mm->free_list[i915_buddy_block_order(block)]); + &mm->free_list[drm_buddy_block_order(block)]); } -static void mark_split(struct i915_buddy_block *block) +static void mark_split(struct drm_buddy_block *block) { - block->header &= ~I915_BUDDY_HEADER_STATE; - block->header |= I915_BUDDY_SPLIT; + block->header &= ~DRM_BUDDY_HEADER_STATE; + block->header |= DRM_BUDDY_SPLIT; list_del(&block->link); } -int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size) +int drm_buddy_init(struct drm_buddy_mm *mm, u64 size, u64 chunk_size) { unsigned int i; u64 offset; @@ -87,7 +84,7 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size) mm->chunk_size = chunk_size; mm->max_order = ilog2(size) - ilog2(chunk_size); - GEM_BUG_ON(mm->max_order > I915_BUDDY_MAX_ORDER); + BUG_ON(mm->max_order > DRM_BUDDY_MAX_ORDER); mm->free_list = kmalloc_array(mm->max_order + 1, sizeof(struct list_head), @@ -101,7 +98,7 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size) mm->n_roots = hweight64(size); mm->roots = kmalloc_array(mm->n_roots, - sizeof(struct i915_buddy_block *), + sizeof(struct drm_buddy_block *), GFP_KERNEL); if (!mm->roots) goto out_free_list; @@ -114,21 +111,21 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size) * not itself a power-of-two. */ do { - struct i915_buddy_block *root; + struct drm_buddy_block *root; unsigned int order; u64 root_size; root_size = rounddown_pow_of_two(size); order = ilog2(root_size) - ilog2(chunk_size); - root = i915_block_alloc(mm, NULL, order, offset); + root = drm_block_alloc(mm, NULL, order, offset); if (!root) goto out_free_roots; mark_free(mm, root); - GEM_BUG_ON(i > mm->max_order); - GEM_BUG_ON(i915_buddy_block_size(mm, root) < chunk_size); + BUG_ON(i > mm->max_order); + BUG_ON(drm_buddy_block_size(mm, root) < chunk_size); mm->roots[i] = root; @@ -141,45 +138,45 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size) out_free_roots: while (i--) - i915_block_free(mm, mm->roots[i]); + drm_block_free(mm, mm->roots[i]); kfree(mm->roots); out_free_list: kfree(mm->free_list); return -ENOMEM; } -void i915_buddy_fini(struct i915_buddy_mm *mm) +void drm_buddy_fini(struct drm_buddy_mm *mm) { int i; for (i = 0; i < mm->n_roots; ++i) { - GEM_WARN_ON(!i915_buddy_block_is_free(mm->roots[i])); - i915_block_free(mm, mm->roots[i]); + WARN_ON(!drm_buddy_block_is_free(mm->roots[i])); + drm_block_free(mm, mm->roots[i]); } - GEM_WARN_ON(mm->avail != mm->size); + WARN_ON(mm->avail != mm->size); kfree(mm->roots); kfree(mm->free_list); } -static int split_block(struct i915_buddy_mm *mm, - struct i915_buddy_block *block) +static int split_block(struct drm_buddy_mm *mm, + struct drm_buddy_block *block) { - unsigned int block_order = i915_buddy_block_order(block) - 1; - u64 offset = i915_buddy_block_offset(block); + unsigned int block_order = drm_buddy_block_order(block) - 1; + u64 offset = drm_buddy_block_offset(block); - GEM_BUG_ON(!i915_buddy_block_is_free(block)); - GEM_BUG_ON(!i915_buddy_block_order(block)); + BUG_ON(!drm_buddy_block_is_free(block)); + BUG_ON(!drm_buddy_block_order(block)); - block->left = i915_block_alloc(mm, block, block_order, offset); + block->left = drm_block_alloc(mm, block, block_order, offset); if (!block->left) return -ENOMEM; - block->right = i915_block_alloc(mm, block, block_order, + block->right = drm_block_alloc(mm, block, block_order, offset + (mm->chunk_size << block_order)); if (!block->right) { - i915_block_free(mm, block->left); + drm_block_free(mm, block->left); return -ENOMEM; } @@ -191,10 +188,10 @@ static int split_block(struct i915_buddy_mm *mm, return 0; } -static struct i915_buddy_block * -get_buddy(struct i915_buddy_block *block) +static struct drm_buddy_block * +get_buddy(struct drm_buddy_block *block) { - struct i915_buddy_block *parent; + struct drm_buddy_block *parent; parent = block->parent; if (!parent) @@ -206,23 +203,23 @@ get_buddy(struct i915_buddy_block *block) return parent->left; } -static void __i915_buddy_free(struct i915_buddy_mm *mm, - struct i915_buddy_block *block) +static void __drm_buddy_free(struct drm_buddy_mm *mm, + struct drm_buddy_block *block) { - struct i915_buddy_block *parent; + struct drm_buddy_block *parent; while ((parent = block->parent)) { - struct i915_buddy_block *buddy; + struct drm_buddy_block *buddy; buddy = get_buddy(block); - if (!i915_buddy_block_is_free(buddy)) + if (!drm_buddy_block_is_free(buddy)) break; list_del(&buddy->link); - i915_block_free(mm, block); - i915_block_free(mm, buddy); + drm_block_free(mm, block); + drm_block_free(mm, buddy); block = parent; } @@ -230,20 +227,20 @@ static void __i915_buddy_free(struct i915_buddy_mm *mm, mark_free(mm, block); } -void i915_buddy_free(struct i915_buddy_mm *mm, - struct i915_buddy_block *block) +void drm_buddy_free(struct drm_buddy_mm *mm, + struct drm_buddy_block *block) { - GEM_BUG_ON(!i915_buddy_block_is_allocated(block)); - mm->avail += i915_buddy_block_size(mm, block); - __i915_buddy_free(mm, block); + BUG_ON(!drm_buddy_block_is_allocated(block)); + mm->avail += drm_buddy_block_size(mm, block); + __drm_buddy_free(mm, block); } -void i915_buddy_free_list(struct i915_buddy_mm *mm, struct list_head *objects) +void drm_buddy_free_list(struct drm_buddy_mm *mm, struct list_head *objects) { - struct i915_buddy_block *block, *on; + struct drm_buddy_block *block, *on; list_for_each_entry_safe(block, on, objects, link) { - i915_buddy_free(mm, block); + drm_buddy_free(mm, block); cond_resched(); } INIT_LIST_HEAD(objects); @@ -257,16 +254,16 @@ void i915_buddy_free_list(struct i915_buddy_mm *mm, struct list_head *objects) * 2 = 2^2 * mm->chunk_size * ... */ -struct i915_buddy_block * -i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order) +struct drm_buddy_block * +drm_buddy_alloc(struct drm_buddy_mm *mm, unsigned int order) { - struct i915_buddy_block *block = NULL; + struct drm_buddy_block *block = NULL; unsigned int i; int err; for (i = order; i <= mm->max_order; ++i) { block = list_first_entry_or_null(&mm->free_list[i], - struct i915_buddy_block, + struct drm_buddy_block, link); if (block) break; @@ -275,7 +272,7 @@ i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order) if (!block) return ERR_PTR(-ENOSPC); - GEM_BUG_ON(!i915_buddy_block_is_free(block)); + BUG_ON(!drm_buddy_block_is_free(block)); while (i != order) { err = split_block(mm, block); @@ -288,13 +285,13 @@ i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order) } mark_allocated(block); - mm->avail -= i915_buddy_block_size(mm, block); + mm->avail -= drm_buddy_block_size(mm, block); kmemleak_update_trace(block); return block; out_free: if (i != order) - __i915_buddy_free(mm, block); + __drm_buddy_free(mm, block); return ERR_PTR(err); } @@ -314,16 +311,16 @@ static inline bool contains(u64 s1, u64 e1, u64 s2, u64 e2) * * Intended for pre-allocating portions of the address space, for example to * reserve a block for the initial framebuffer or similar, hence the expectation - * here is that i915_buddy_alloc() is still the main vehicle for + * here is that drm_buddy_alloc() is still the main vehicle for * allocations, so if that's not the case then the drm_mm range allocator is * probably a much better fit, and so you should probably go use that instead. */ -int i915_buddy_alloc_range(struct i915_buddy_mm *mm, - struct list_head *blocks, - u64 start, u64 size) +int drm_buddy_alloc_range(struct drm_buddy_mm *mm, + struct list_head *blocks, + u64 start, u64 size) { - struct i915_buddy_block *block; - struct i915_buddy_block *buddy; + struct drm_buddy_block *block; + struct drm_buddy_block *buddy; LIST_HEAD(allocated); LIST_HEAD(dfs); u64 end; @@ -349,37 +346,37 @@ int i915_buddy_alloc_range(struct i915_buddy_mm *mm, u64 block_end; block = list_first_entry_or_null(&dfs, - struct i915_buddy_block, + struct drm_buddy_block, tmp_link); if (!block) break; list_del(&block->tmp_link); - block_start = i915_buddy_block_offset(block); - block_end = block_start + i915_buddy_block_size(mm, block) - 1; + block_start = drm_buddy_block_offset(block); + block_end = block_start + drm_buddy_block_size(mm, block) - 1; if (!overlaps(start, end, block_start, block_end)) continue; - if (i915_buddy_block_is_allocated(block)) { + if (drm_buddy_block_is_allocated(block)) { err = -ENOSPC; goto err_free; } if (contains(start, end, block_start, block_end)) { - if (!i915_buddy_block_is_free(block)) { + if (!drm_buddy_block_is_free(block)) { err = -ENOSPC; goto err_free; } mark_allocated(block); - mm->avail -= i915_buddy_block_size(mm, block); + mm->avail -= drm_buddy_block_size(mm, block); list_add_tail(&block->link, &allocated); continue; } - if (!i915_buddy_block_is_split(block)) { + if (!drm_buddy_block_is_split(block)) { err = split_block(mm, block); if (unlikely(err)) goto err_undo; @@ -400,26 +397,26 @@ int i915_buddy_alloc_range(struct i915_buddy_mm *mm, */ buddy = get_buddy(block); if (buddy && - (i915_buddy_block_is_free(block) && - i915_buddy_block_is_free(buddy))) - __i915_buddy_free(mm, block); + (drm_buddy_block_is_free(block) && + drm_buddy_block_is_free(buddy))) + __drm_buddy_free(mm, block); err_free: - i915_buddy_free_list(mm, &allocated); + drm_buddy_free_list(mm, &allocated); return err; } -void i915_buddy_block_print(struct i915_buddy_mm *mm, - struct i915_buddy_block *block, - struct drm_printer *p) +void drm_buddy_block_print(struct drm_buddy_mm *mm, + struct drm_buddy_block *block, + struct drm_printer *p) { - u64 start = i915_buddy_block_offset(block); - u64 size = i915_buddy_block_size(mm, block); + u64 start = drm_buddy_block_offset(block); + u64 size = drm_buddy_block_size(mm, block); drm_printf(p, "%#018llx-%#018llx: %llu\n", start, start + size, size); } -void i915_buddy_print(struct i915_buddy_mm *mm, struct drm_printer *p) +void drm_buddy_print(struct drm_buddy_mm *mm, struct drm_printer *p) { int order; @@ -427,11 +424,11 @@ void i915_buddy_print(struct i915_buddy_mm *mm, struct drm_printer *p) mm->chunk_size >> 10, mm->size >> 20, mm->avail >> 20); for (order = mm->max_order; order >= 0; order--) { - struct i915_buddy_block *block; + struct drm_buddy_block *block; u64 count = 0, free; list_for_each_entry(block, &mm->free_list[order], link) { - GEM_BUG_ON(!i915_buddy_block_is_free(block)); + BUG_ON(!drm_buddy_block_is_free(block)); count++; } @@ -451,14 +448,14 @@ void i915_buddy_print(struct i915_buddy_mm *mm, struct drm_printer *p) #include "selftests/i915_buddy.c" #endif -void i915_buddy_module_exit(void) +void drm_buddy_module_exit(void) { kmem_cache_destroy(slab_blocks); } -int __init i915_buddy_module_init(void) +int __init drm_buddy_module_init(void) { - slab_blocks = KMEM_CACHE(i915_buddy_block, 0); + slab_blocks = KMEM_CACHE(drm_buddy_block, 0); if (!slab_blocks) return -ENOMEM; diff --git a/include/drm/drm_buddy.h b/include/drm/drm_buddy.h index 521ed532d2b8..390b133fe342 100644 --- a/include/drm/drm_buddy.h +++ b/include/drm/drm_buddy.h @@ -9,9 +9,19 @@ #include #include #include +#include #include +#define range_overflows(start, size, max) ({ \ + typeof(start) start__ = (start); \ + typeof(size) size__ = (size); \ + typeof(max) max__ = (max); \ + (void)(&start__ == &size__); \ + (void)(&start__ == &max__); \ + start__ >= max__ || size__ > max__ - start__; \ +}) + struct drm_buddy_block { #define DRM_BUDDY_HEADER_OFFSET GENMASK_ULL(63, 12) #define DRM_BUDDY_HEADER_STATE GENMASK_ULL(11, 10) From patchwork Tue Oct 19 22:53:59 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: 12571299 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 E8733C433F5 for ; Tue, 19 Oct 2021 22:55:24 +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 B5AFE61074 for ; Tue, 19 Oct 2021 22:55:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B5AFE61074 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 7DA9F6E117; Tue, 19 Oct 2021 22:55:16 +0000 (UTC) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2078.outbound.protection.outlook.com [40.107.220.78]) by gabe.freedesktop.org (Postfix) with ESMTPS id 926B46E0F6; Tue, 19 Oct 2021 22:55:14 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UxfgI07yODex9MAC6jPk13+7bhHIaewD7Xu01Iuvc3gNuYt+X4FTkC0P2JWAu/427Kzn0hXbuTfZBslXlfSglmntoALNzFgud8SZnImM8RXnrd0rCp3ch6IjF8qD8KNsb2A8PTWsy2hR2idLevm3NsuSoVj+F4n3e8amM2SAylF7oJjq8qHUGSzi/+8FvnLL9DRC26rUJ314/yOp02lRsJoekQwqBaIrIvvW1Mi4yUniRPKpSN8Zb1GV6Y1oCoNYuTO1vfdXSPGr/u/i9xCdF+Uv9sB/eaAov4SgJd51/idUurpun9hbYsN6W/7Y+kPY/kYW4Fkc65StsWcQOajNeg== 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=PR1hi6cbAgcHWhJM/cwXFQ66oufHsToJdCJ1J7zr14k=; b=Zi1WoN/rlGyAj64AOHsZc7CM1LaVhJbHXmUa6DBM0RgVfby71U1tEGyummISoFCbwMJIoWxE/yC0Kf7pQWruqCHMf88QaLncsbJTH+3yb9lfWajH8ce9bouSCBFtVnXHFLFl6lNkkYfzASWxJCGvl02AiYj0Cg/5KtJul1dnKAuTwF72xqwQnDbQ7MyWKpnyxNsKJ1nHxpzSqkWgsLyIi9/O4IUsE2OnnOs2671yaIAsYTwfYdFWQfpL7NQuFOTkg6KxSrS4iQWXAU1bXF1/o48CZcTDKrIyXH69ipzH93OaBHeUk5BscVPkU9ExpgE32KBYSpWw8E9e8dox6y75DQ== 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=PR1hi6cbAgcHWhJM/cwXFQ66oufHsToJdCJ1J7zr14k=; b=LYbhAxng1fgsHvIQ9veHYvWP/xBB/nmsjyYf7etIzPlBbLZfiiK8myP9s+TIA9Vx3JYOR6IQzyhwG2xpziSI8n+hz9z34pOl+ooqtOQPWSzVFp7YQiueFPyu//cPMJ+qEi+Vl1LGuJc/AAhq0h9XPdJX8uZc5ksqc+qdtPGR24o= Received: from MW3PR06CA0020.namprd06.prod.outlook.com (2603:10b6:303:2a::25) by MN2PR12MB3421.namprd12.prod.outlook.com (2603:10b6:208:cd::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Tue, 19 Oct 2021 22:55:10 +0000 Received: from CO1NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2a:cafe::b0) by MW3PR06CA0020.outlook.office365.com (2603:10b6:303:2a::25) 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:09 +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 CO1NAM11FT035.mail.protection.outlook.com (10.13.175.36) 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:09 +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:06 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 03/13] drm: add Makefile support for drm buddy Date: Wed, 20 Oct 2021 04:23:59 +0530 Message-ID: <20211019225409.569355-4-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: 41271499-0fb1-41df-dc3a-08d993538087 X-MS-TrafficTypeDiagnostic: MN2PR12MB3421: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:103; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C5s7H3mXx/2x7O1YWyxZ13i4i8hqXguZBLR+yJR231ufv3M22M2vm7Jq4rSzX1+pVj+0rVy0Qvh/gjob12I8R/M+lCvaZjepyJpMHczOT2miSSgfHx80RMyKxCsK/xg41QATKo7cBe6UIqetnAponM6nn8/02X26L5RcgXVueLoIjnOaQXeXaVpsR5OjsFcxcq1nWBWb5c5L2EkDdgnJakNUb4qC8W89hTGSSeZTCWodYT8EXH+7w1DnpwZZA4CRKdfB2oAJY9AGDoiw8XYwcxtSUDtrWCt05+MpzOwMfazr+Ox0dZ/heNuxH3TXiIYvXTEVtl+uTD6TP2TALHy9djz8IwYcytqBlTSt8HW5Topx++o6cMOxsPBBRtrUEUQO+5kJUHS0SFoC9b6RDC3E5cGXk+ozxr0Sg+smVBc7nvPChSuVJ7BxinTeG2Vd+e19FlIBlk4cxfmvOHKBySuJs+RCK704PD/vXcdMxrWkJ5Pq+xBP3yhkpNJ6t1KXQsCpvHNXNS5Uot6fEAKOwgXR3SiL6Hxn+M2cT1gXXEDuV2f4u3P9HHZI4Rz/Jfs2l+J+BjaeoB09WtJDAnNMggLpdWnxb2fEd268nV3ccX0lFRdAi8xhp6uFGI4NX7unahSbN+algGALHPaTPUSInKO+XgmXbH7qbKstcO+ape6cLh3+rHftGBUG8U599sUo9XfVMHD/d5HYTQrjKcrrNoZhNVpXCXGAvVa+eEMfjRxmEtI= 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)(2906002)(1076003)(8936002)(6666004)(16526019)(54906003)(81166007)(8676002)(7696005)(82310400003)(26005)(5660300002)(186003)(508600001)(47076005)(70586007)(356005)(336012)(83380400001)(426003)(4326008)(316002)(70206006)(36860700001)(2616005)(110136005)(86362001)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:09.5982 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41271499-0fb1-41df-dc3a-08d993538087 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: CO1NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3421 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - Include drm buddy to DRM root Makefile - Add drm buddy init and exit function calls to drm core Signed-off-by: Arunpravin --- drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_drv.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 0dff40bb863c..dc61e91a3154 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -18,7 +18,7 @@ drm-y := drm_aperture.o drm_auth.o drm_cache.o \ drm_dumb_buffers.o drm_mode_config.o drm_vblank.o \ drm_syncobj.o drm_lease.o drm_writeback.o drm_client.o \ drm_client_modeset.o drm_atomic_uapi.o drm_hdcp.o \ - drm_managed.o drm_vblank_work.o + drm_managed.o drm_vblank_work.o drm_buddy.o drm-$(CONFIG_DRM_LEGACY) += drm_agpsupport.o drm_bufs.o drm_context.o drm_dma.o \ drm_legacy_misc.o drm_lock.o drm_memory.o drm_scatter.o \ diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 7a5097467ba5..6707eec21bef 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -43,6 +43,7 @@ #include #include #include +#include #include "drm_crtc_internal.h" #include "drm_internal.h" @@ -1034,6 +1035,7 @@ static void drm_core_exit(void) drm_sysfs_destroy(); idr_destroy(&drm_minors_idr); drm_connector_ida_destroy(); + drm_buddy_module_exit(); } static int __init drm_core_init(void) @@ -1043,6 +1045,7 @@ static int __init drm_core_init(void) drm_connector_ida_init(); idr_init(&drm_minors_idr); drm_memcpy_init_early(); + drm_buddy_module_init(); ret = drm_sysfs_init(); if (ret < 0) { From patchwork Tue Oct 19 22:54:00 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: 12571301 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 49EB6C433F5 for ; Tue, 19 Oct 2021 22:55:31 +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 082B861074 for ; Tue, 19 Oct 2021 22:55:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 082B861074 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 84EFB6E138; Tue, 19 Oct 2021 22:55:23 +0000 (UTC) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2088.outbound.protection.outlook.com [40.107.92.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 032CD6E10A; Tue, 19 Oct 2021 22:55:16 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BfkK0T0M3JT2lEyxSZXYb23LYUboEAu1D6a7xfEu1nl851jJqaHY24DslIIyXRbkJNsecRw60f/MClBiNv5/PpcbDcoTT0CIpIGvQUghsAAk+AIxXJaTNrcKNXTomZ5LKLJKg7Bc2hTHnUV8onWPsHkNDOmMctaGRpy6+ecsfT8HSz98lo2iDzkhH0OE7MgQFn6c+RQKDgb3dcIQOnbOW21LA5kQxq7zZrqUiJc7Dt8O95pSGOk/NS1h5T7jzLqqJGWUe9omW9GgXjeSjRhBcoClAMoYaZIAMj5RA+lrAIec6MwPpx88sUYDgMF9GiVjg+PipH3ew0zh/WvkO0OMEg== 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=BucEtWHJwRDivMuyuuPCQ0BV8dtBKBNIOnoWevGJC34=; b=Ha7NYGG8GNMe4phohaAqd6ZP42WFzfjL5SLfN+KE7JvyDyNgjWYFZFrI1DiDYfNq/MShipeyAhpURVkOeiIqHoAABZI3tkpbmNSb+A+4lZQabEH/mtFfMkX18+hoy5Y3oOlgeZc4tMpTP0o3iXD4bLHSOol9LtQgAV2Jv5i6MSgb1IBczwnpjupK8TybA58hgSpc8Z63NPPKOD1YX+f+Qf8yoKrtb+P3d/bP9EanpY+zlrk7RgYHBuiZOuWdPBEI/QozSE9lYijhFHKgefYh4luv8gOVVMMDBnxuuKe+66dFjiu1QDP0pHefGMp1RhcyTljHcSO/dtmX7cSINhuqRg== 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=BucEtWHJwRDivMuyuuPCQ0BV8dtBKBNIOnoWevGJC34=; b=oZ9k7q49fVbkEneoyBzb57FTmZgbcDGJgBvPFFRoGYCNHUNRcwvuMH86JyR8yeKOG/6bjr15dVNCJdLT5raiCS0G2e54P53CjBseFbE4R419/xfhKRjTYpMpt10kpktWfhGggImwnY/eTRI1Uqc4+aEr7WQTO5UK1jZi8CCBmXw= Received: from MW3PR06CA0024.namprd06.prod.outlook.com (2603:10b6:303:2a::29) by BN8PR12MB4787.namprd12.prod.outlook.com (2603:10b6:408:a1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15; Tue, 19 Oct 2021 22:55:12 +0000 Received: from CO1NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2a:cafe::c4) by MW3PR06CA0024.outlook.office365.com (2603:10b6:303:2a::29) 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:12 +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 CO1NAM11FT035.mail.protection.outlook.com (10.13.175.36) 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:12 +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:09 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 04/13] drm: make drm_buddy_alloc a commonplace Date: Wed, 20 Oct 2021 04:24:00 +0530 Message-ID: <20211019225409.569355-5-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: b8a91b13-a04f-4ff8-e00d-08d993538230 X-MS-TrafficTypeDiagnostic: BN8PR12MB4787: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:117; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: clOSVbMlG1EdfWTW0Y62WKIO5ZfMG5uYkRd0Z37c6bZB6dNOxfeM69bRY+eZ6CblIC0Jtfxy//+KBgWAYA781+pvBCcsHHkj+lzLS5qj9wM10+jbB4KiUZLUC9yXzh/IgZHyZ4rECnG/1y8TFbAL4ftwCEyGHFCPdbJsWWU3RIHWXK8eTG6pan5U1ribNJvPlitdA3g1S0NWab91z+5seAWdcMT0It7XWbAT8VZo4Lv6nSGKDmg2iHfI1faKa6Shpc59Czcg8ODPW2JRE9bzlliSwA4zTCjkHEm/5aipdbYoacIzinhyspUqQgvfSxdsTRbFpqiNiICX5VLdwajYOsE8uypgxItzpYmD+D+2wX+rV3y7btZmIeeg8jk9yUXV6HlY1K7ESuFw3UrSFKS1DlgJmYcgeWwdDuwyKl2FM1ymMhRJYKb5moMXjpa7YrocCVQOKyJ5nmhDRuQ6NALPNjRnFr7rduRJ0Bo7xJeIrlw2GVnxP/FlGaV+MHQl6/VuUqVXaI99GoVre3Ay3REfRBDQhVEV0IwMmvXo6g6M7npAGhMFZwuFI0Ym9eUNfRhdWWFgLp4AL6UGm/gwE2p+Godj8p5tyDgkMqkrQoK6bh2kkIOaxRRXRXsLbkBC7nZPNksk8lgAYPdSzuKEhtBwpLfkcdi33EZR5nteflNKjJItFW/iJGYfAM9AZ0CcG4XBPNcYJNtbUQXLqDBYHdaunHz8ozuMNi2XUDtkwM13tRo= 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)(36840700001)(46966006)(16526019)(186003)(4326008)(1076003)(70206006)(82310400003)(70586007)(81166007)(356005)(47076005)(8676002)(336012)(26005)(5660300002)(8936002)(83380400001)(36756003)(36860700001)(508600001)(2616005)(110136005)(86362001)(54906003)(7696005)(426003)(6666004)(316002)(2906002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:12.3846 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b8a91b13-a04f-4ff8-e00d-08d993538230 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: CO1NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB4787 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - Make drm_buddy_alloc a single function to handle range allocation and non-range allocation demands. - Implemented a new function alloc_range() which allocates the requested order (in bytes) comply with range limitations - Moved memory alignment logic from i915 driver Signed-off-by: Arunpravin --- drivers/gpu/drm/drm_buddy.c | 208 +++++++++++++++++++++++++++++++----- include/drm/drm_buddy.h | 18 +++- 2 files changed, 194 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c index 0398706cb7ae..f5f299dd9131 100644 --- a/drivers/gpu/drm/drm_buddy.c +++ b/drivers/gpu/drm/drm_buddy.c @@ -246,27 +246,112 @@ void drm_buddy_free_list(struct drm_buddy_mm *mm, struct list_head *objects) INIT_LIST_HEAD(objects); } -/* - * Allocate power-of-two block. The order value here translates to: - * - * 0 = 2^0 * mm->chunk_size - * 1 = 2^1 * mm->chunk_size - * 2 = 2^2 * mm->chunk_size - * ... - */ -struct drm_buddy_block * -drm_buddy_alloc(struct drm_buddy_mm *mm, unsigned int order) +static inline bool overlaps(u64 s1, u64 e1, u64 s2, u64 e2) +{ + return s1 <= e2 && e1 >= s2; +} + +static inline bool contains(u64 s1, u64 e1, u64 s2, u64 e2) +{ + return s1 <= s2 && e1 >= e2; +} + +static struct drm_buddy_block * +alloc_range(struct drm_buddy_mm *mm, + u64 start, u64 end, + unsigned int order) +{ + struct drm_buddy_block *block; + struct drm_buddy_block *buddy; + LIST_HEAD(dfs); + int err; + int i; + + end = end - 1; + + for (i = 0; i < mm->n_roots; ++i) + list_add_tail(&mm->roots[i]->tmp_link, &dfs); + + do { + u64 block_start; + u64 block_end; + + block = list_first_entry_or_null(&dfs, + struct drm_buddy_block, + tmp_link); + + if (!block) + break; + + list_del(&block->tmp_link); + + if (drm_buddy_block_order(block) < order) + continue; + + block_start = drm_buddy_block_offset(block); + block_end = block_start + drm_buddy_block_size(mm, block) - 1; + + if (!overlaps(start, end, block_start, block_end)) + continue; + + if (drm_buddy_block_is_allocated(block)) + continue; + + if (contains(start, end, block_start, block_end) + && order == drm_buddy_block_order(block)) { + /* + * Find the free block within the range. + */ + if (drm_buddy_block_is_free(block)) + return block; + + continue; + } + + if (!drm_buddy_block_is_split(block)) { + err = split_block(mm, block); + if (unlikely(err)) + goto err_undo; + } + + list_add(&block->left->tmp_link, &dfs); + list_add(&block->right->tmp_link, &dfs); + } while (1); + + return ERR_PTR(-ENOSPC); + +err_undo: + /* + * We really don't want to leave around a bunch of split blocks, since + * bigger is better, so make sure we merge everything back before we + * free the allocated blocks. + */ + buddy = get_buddy(block); + if (buddy && + (drm_buddy_block_is_free(block) && + drm_buddy_block_is_free(buddy))) + __drm_buddy_free(mm, block); + return ERR_PTR(err); +} + +static struct drm_buddy_block * +alloc_from_freelist(struct drm_buddy_mm *mm, + unsigned int order, + unsigned long flags) { struct drm_buddy_block *block = NULL; unsigned int i; int err; for (i = order; i <= mm->max_order; ++i) { - block = list_first_entry_or_null(&mm->free_list[i], - struct drm_buddy_block, - link); - if (block) - break; + if (!list_empty(&mm->free_list[i])) { + block = list_first_entry_or_null(&mm->free_list[i], + struct drm_buddy_block, + link); + + if (block) + break; + } } if (!block) @@ -276,33 +361,100 @@ drm_buddy_alloc(struct drm_buddy_mm *mm, unsigned int order) while (i != order) { err = split_block(mm, block); + if (unlikely(err)) - goto out_free; + goto err_undo; - /* Go low */ - block = block->left; + block = block->right; i--; } - mark_allocated(block); - mm->avail -= drm_buddy_block_size(mm, block); - kmemleak_update_trace(block); return block; -out_free: +err_undo: if (i != order) __drm_buddy_free(mm, block); return ERR_PTR(err); } -static inline bool overlaps(u64 s1, u64 e1, u64 s2, u64 e2) +/* + * Allocate power-of-two block. The order value here translates to: + * + * 0 = 2^0 * mm->chunk_size + * 1 = 2^1 * mm->chunk_size + * 2 = 2^2 * mm->chunk_size + * ... + */ +int drm_buddy_alloc(struct drm_buddy_mm *mm, + u64 start, u64 end, u64 size, + u64 min_page_size, + struct list_head *blocks, + unsigned long flags) { - return s1 <= e2 && e1 >= s2; -} + struct drm_buddy_block *block = NULL; + unsigned int min_order, order; + unsigned long pages; + LIST_HEAD(allocated); + int err; -static inline bool contains(u64 s1, u64 e1, u64 s2, u64 e2) -{ - return s1 <= s2 && e1 >= e2; + if (size < mm->chunk_size) + return -EINVAL; + + if (!IS_ALIGNED(start, mm->chunk_size)) + return -EINVAL; + + if (!IS_ALIGNED(end, mm->chunk_size)) + return -EINVAL; + + if (!IS_ALIGNED(size, mm->chunk_size)) + return -EINVAL; + + if (check_range_overflow(start, end, size, mm->size)) + return -EINVAL; + + pages = size >> ilog2(mm->chunk_size); + min_order = ilog2(min_page_size) - ilog2(mm->chunk_size); + + do { + order = fls(pages) - 1; + BUG_ON(order > mm->max_order); + BUG_ON(order < min_order); + + do { + if (flags & DRM_BUDDY_RANGE_ALLOCATION) + /* Allocate traversing within the range */ + block = alloc_range(mm, start, end, order); + else + /* Allocate from freelist */ + block = alloc_from_freelist(mm, order, flags); + + if (!IS_ERR(block)) + break; + + if (order-- == min_order) { + err = -ENOSPC; + goto err_free; + } + } while (1); + + mark_allocated(block); + mm->avail -= drm_buddy_block_size(mm, block); + kmemleak_update_trace(block); + + list_add_tail(&block->link, &allocated); + + pages -= BIT(order); + + if (!pages) + break; + } while (1); + + list_splice_tail(&allocated, blocks); + return 0; + +err_free: + drm_buddy_free_list(mm, &allocated); + return err; } /* diff --git a/include/drm/drm_buddy.h b/include/drm/drm_buddy.h index 390b133fe342..c64fd4062cb6 100644 --- a/include/drm/drm_buddy.h +++ b/include/drm/drm_buddy.h @@ -13,15 +13,22 @@ #include -#define range_overflows(start, size, max) ({ \ +#define check_range_overflow(start, end, size, max) ({ \ typeof(start) start__ = (start); \ + typeof(end) end__ = (end);\ typeof(size) size__ = (size); \ typeof(max) max__ = (max); \ (void)(&start__ == &size__); \ (void)(&start__ == &max__); \ - start__ >= max__ || size__ > max__ - start__; \ + (void)(&start__ == &end__); \ + (void)(&end__ == &size__); \ + (void)(&end__ == &max__); \ + start__ >= max__ || end__ > max__ \ + || size__ > end__ - start__; \ }) +#define DRM_BUDDY_RANGE_ALLOCATION (1 << 1) + struct drm_buddy_block { #define DRM_BUDDY_HEADER_OFFSET GENMASK_ULL(63, 12) #define DRM_BUDDY_HEADER_STATE GENMASK_ULL(11, 10) @@ -131,8 +138,11 @@ int drm_buddy_init(struct drm_buddy_mm *mm, u64 size, u64 chunk_size); void drm_buddy_fini(struct drm_buddy_mm *mm); -struct drm_buddy_block * -drm_buddy_alloc(struct drm_buddy_mm *mm, unsigned int order); +int drm_buddy_alloc(struct drm_buddy_mm *mm, + u64 start, u64 end, u64 size, + u64 min_page_size, + struct list_head *blocks, + unsigned long flags); int drm_buddy_alloc_range(struct drm_buddy_mm *mm, struct list_head *blocks, From patchwork Tue Oct 19 22:54:01 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: 12571303 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 6FCB2C433F5 for ; Tue, 19 Oct 2021 22:55:37 +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 3A801610E5 for ; Tue, 19 Oct 2021 22:55:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3A801610E5 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 AD25B6E14F; Tue, 19 Oct 2021 22:55:24 +0000 (UTC) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2052.outbound.protection.outlook.com [40.107.94.52]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8800C6E138; Tue, 19 Oct 2021 22:55:21 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c7LRbnqaTQzlooGSSOSeM0l+rEWMYFA/GEktinEy4zBxe3EpxW1x2iVEnxos82DrOfCEmq7tTH1wtUA6AX7zuWtXbFS6hBRV2njgHAAF65lmequJ25Sp43Fa6qVcXottiy/NPZwycfsFXZCpk9gv8bFt7G9XDToOb1HfdXR+VxpC3oPEUb95NetJW2iOQ+dMH62goIK87AtRpVC142gh+/ijxaotROaLxPvdvv/OmiEdD+oMxh6+waMGwImyz2VUseOyX/tgJ/26m4H29LAjRcRuIo8Ui8QhcBzRYpyVrmhMr7Uj7+oV06CrqID1HTpXvwe9/2rTVI9F4tg4mTQZGQ== 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=TicL0s/ZvhSsFe0I8vCX4p1ZYArbNiuXSvHt6bKOBik=; b=OZsby38878Z43eX2efG9r9Vl7tKBQvH88yp9ncwG1p280mM15Mfg9wGmxbDdb08oVvf//UCm2/PvCy+5Yj6Hcf5eQtayu8uVxnTYrS6p47iHkvUoiRvThwLxtpEdNAfiuGsdTaJtvy3S+x0kUfwW0cHN/EsongP45Z4jz2XPOfCZx56vb1vM8xh2/vRa6DqJfMTsq5IxqiD14j5NwuevqDhVzwazhN0InEQgBP1QyGtDyFpRfc8vgVFknpYwsz4hmKc7e/19aMVdIHkYpXRbtGGfnxqbakGrR68baZOVPOz7PpWmjtnB9/R5fw5NatPP8ceByoiFmoCb3rkxzpS2cQ== 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=TicL0s/ZvhSsFe0I8vCX4p1ZYArbNiuXSvHt6bKOBik=; b=iCizuKClHz85/0ljZZqM1jdh8l4v8sC/JYkbdLG8LXs4SqvGH82PZ0ucXxY0QUpjYBk5Dq9kssjTDn41UOxvuTQO+KMDCMtAV4tUaKvP2MrjrZ7z/ISy5XKpFMTJdvGCX6sBA+PKAUHYaDpuFPE7CQsyLX8PUfOXufqb0EOy53Q= Received: from MW3PR06CA0002.namprd06.prod.outlook.com (2603:10b6:303:2a::7) by CH2PR12MB4166.namprd12.prod.outlook.com (2603:10b6:610:78::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Tue, 19 Oct 2021 22:55:18 +0000 Received: from CO1NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2a:cafe::82) by MW3PR06CA0002.outlook.office365.com (2603:10b6:303:2a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.18 via Frontend Transport; Tue, 19 Oct 2021 22:55:18 +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 CO1NAM11FT035.mail.protection.outlook.com (10.13.175.36) 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:15 +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:12 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 05/13] drm: remove drm_buddy_alloc_range Date: Wed, 20 Oct 2021 04:24:01 +0530 Message-ID: <20211019225409.569355-6-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: d56d83e5-36a0-4a03-7d5d-08d99353843b X-MS-TrafficTypeDiagnostic: CH2PR12MB4166: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:409; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e/sWo47DWb37eQTUgdzI5aPJoRRRmU7vZAFClhHw2JsxPSCBDQalMvOrlivEs1ldYGfEanpb2GgSet/3iHE6nrIj2S6orWOSJMJr2IjAi2IjaZNoNmXAp4647zzE/T45Xa3VE9/ChT9Cwbz5qQGxldhLh3ZbXUO2OyrIpGN18WBPCG2JvqWG/JP+wHn8G/Bm+7W5eObdxE4frM+UJQgUPJVa6BY88QVfGNS4Wm29Bybedlnew4KbAjcODZZwMh1aWy0IzmsO1MUTBJd0nYtUdnaRyYOI2OY2cX7XtCtp1jnEjPWJyGk00I+4Z4iC9niurgQVMnVYroK9K3NPFKhB+/L6+7UQz86ohmTNyCXGf6jZVwtXseL6gAOUecjGIhQLYsIadtgGKkJADVv9FcKFgpjtZt9XOqiZZ60oA1ZJlUt4aw1CVC0llhIonp41H7/gEEvSExQsdnzNC2ZlYZmG5gq3ZYn35+0fAosNqs4OXsVxXKc6fgkxOS1u9EA7ehP7jfY0YG6hExcQFAXxs+xrU2KhPv5rpfALUq9pq8I8IJ6139ImbO8MtAg6MIGK8B8Lo9aj5UzQilqRc5kZlcAcAU4whXh3bBkh3zmOWiVZrKXgY49SEb7N2i5IPpVaLwv88bZGZRSiTPi55U/IlIPgPDdcDmkCOGjMQ94xZFrbtcNyDWVXzLL3iXtw2J42rlzZGoiWmAqdxGo0h3oYzy+yI3qKmjtSPL0NBGV3cIN7ybo= 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)(36840700001)(46966006)(1076003)(5660300002)(6666004)(8676002)(2906002)(36860700001)(8936002)(4326008)(47076005)(36756003)(508600001)(81166007)(83380400001)(356005)(82310400003)(86362001)(54906003)(110136005)(70586007)(426003)(70206006)(336012)(2616005)(316002)(186003)(7696005)(26005)(16526019)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:15.8086 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d56d83e5-36a0-4a03-7d5d-08d99353843b 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: CO1NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4166 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This function becomes obsolete and may be removed. Signed-off-by: Arunpravin --- drivers/gpu/drm/drm_buddy.c | 101 ------------------------------------ include/drm/drm_buddy.h | 4 -- 2 files changed, 105 deletions(-) diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c index f5f299dd9131..138e9f1a7340 100644 --- a/drivers/gpu/drm/drm_buddy.c +++ b/drivers/gpu/drm/drm_buddy.c @@ -457,107 +457,6 @@ int drm_buddy_alloc(struct drm_buddy_mm *mm, return err; } -/* - * Allocate range. Note that it's safe to chain together multiple alloc_ranges - * with the same blocks list. - * - * Intended for pre-allocating portions of the address space, for example to - * reserve a block for the initial framebuffer or similar, hence the expectation - * here is that drm_buddy_alloc() is still the main vehicle for - * allocations, so if that's not the case then the drm_mm range allocator is - * probably a much better fit, and so you should probably go use that instead. - */ -int drm_buddy_alloc_range(struct drm_buddy_mm *mm, - struct list_head *blocks, - u64 start, u64 size) -{ - struct drm_buddy_block *block; - struct drm_buddy_block *buddy; - LIST_HEAD(allocated); - LIST_HEAD(dfs); - u64 end; - int err; - int i; - - if (size < mm->chunk_size) - return -EINVAL; - - if (!IS_ALIGNED(size | start, mm->chunk_size)) - return -EINVAL; - - if (range_overflows(start, size, mm->size)) - return -EINVAL; - - for (i = 0; i < mm->n_roots; ++i) - list_add_tail(&mm->roots[i]->tmp_link, &dfs); - - end = start + size - 1; - - do { - u64 block_start; - u64 block_end; - - block = list_first_entry_or_null(&dfs, - struct drm_buddy_block, - tmp_link); - if (!block) - break; - - list_del(&block->tmp_link); - - block_start = drm_buddy_block_offset(block); - block_end = block_start + drm_buddy_block_size(mm, block) - 1; - - if (!overlaps(start, end, block_start, block_end)) - continue; - - if (drm_buddy_block_is_allocated(block)) { - err = -ENOSPC; - goto err_free; - } - - if (contains(start, end, block_start, block_end)) { - if (!drm_buddy_block_is_free(block)) { - err = -ENOSPC; - goto err_free; - } - - mark_allocated(block); - mm->avail -= drm_buddy_block_size(mm, block); - list_add_tail(&block->link, &allocated); - continue; - } - - if (!drm_buddy_block_is_split(block)) { - err = split_block(mm, block); - if (unlikely(err)) - goto err_undo; - } - - list_add(&block->right->tmp_link, &dfs); - list_add(&block->left->tmp_link, &dfs); - } while (1); - - list_splice_tail(&allocated, blocks); - return 0; - -err_undo: - /* - * We really don't want to leave around a bunch of split blocks, since - * bigger is better, so make sure we merge everything back before we - * free the allocated blocks. - */ - buddy = get_buddy(block); - if (buddy && - (drm_buddy_block_is_free(block) && - drm_buddy_block_is_free(buddy))) - __drm_buddy_free(mm, block); - -err_free: - drm_buddy_free_list(mm, &allocated); - return err; -} - void drm_buddy_block_print(struct drm_buddy_mm *mm, struct drm_buddy_block *block, struct drm_printer *p) diff --git a/include/drm/drm_buddy.h b/include/drm/drm_buddy.h index c64fd4062cb6..ebf03d151845 100644 --- a/include/drm/drm_buddy.h +++ b/include/drm/drm_buddy.h @@ -144,10 +144,6 @@ int drm_buddy_alloc(struct drm_buddy_mm *mm, struct list_head *blocks, unsigned long flags); -int drm_buddy_alloc_range(struct drm_buddy_mm *mm, - struct list_head *blocks, - u64 start, u64 size); - void drm_buddy_free(struct drm_buddy_mm *mm, struct drm_buddy_block *block); void drm_buddy_free_list(struct drm_buddy_mm *mm, struct list_head *objects); From patchwork Tue Oct 19 22:54:02 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: 12571307 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 7118AC433EF for ; Tue, 19 Oct 2021 22:55:45 +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 3F27261074 for ; Tue, 19 Oct 2021 22:55:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3F27261074 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 805E06E10F; Tue, 19 Oct 2021 22:55:29 +0000 (UTC) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2071.outbound.protection.outlook.com [40.107.92.71]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3593E6E10A; Tue, 19 Oct 2021 22:55:21 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c4m9EaUZy/nmGdmEpZ4lOTzGFvL5INB768VJJqJzDL2y3H1OBWAZLfgg0TZHCHIUxie92hGbJqHXtiMmiDzj11bc591EeOXNFIusYL/7YHxPS8N4hUapBUiUETK6x5ZLzAFZEo4RGs4pAaboegSyW5k8YuBn1u0mC3vkfeaOG7qCCDMTMYXxXHbfbEqLwK8s8LGkTK4+Su6Jp5OkjI9el4w6nqssdjEYSgylHD09epEYmo+F3ccsUC2FsI652SNDLdmsTT9AHM+PC5iCoBEQCIUg8rMQQGCHwdt5XbWGIoSE2Cx+IJEzG9ErcjoAcPAllMkJ2tIrnS8MdGkg7xrsBA== 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=fNNEWnBC6xiliPuVBS8tklV65cRJHhAiqGKXNpIHt1s=; b=d22vWBMSZziqWpTmt4e8X07DRl61qKkzXGiAF5MLBrWHG+xHykNFkvtp7R43n/UrCdVMFsa6+94X4bYKU/svBfyCk3dXae0x6p0QD50LN4C7AbE7OG1SrcGOMUguBxKHUF9BjqckCZbAu5eApBS2FlgATnsNCMQW9PlHdaoHR3dHcO5+gaIK6CDr5Q12mtp4L7zkQUBzex2D9m3EmF4szVLCRyt4nKeco8/5MCQOdbQ0S2hRi4Oa1TuWaMCBXl/XNnGJ8ALiZfq+DUL1pyoe5DK0OixlUE9PO5YmSU3KCg5Q7uaw0kUM6p2+qzQP8tOrcuFqsuJ80GX0RfbN5uIDyA== 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=fNNEWnBC6xiliPuVBS8tklV65cRJHhAiqGKXNpIHt1s=; b=ISZv4gSPBo3PiL3a/LsnGiyzyoI3qCi3YZa59leHn8rkLTAQl//nGSQ+m6Z+2+3kFgS36OlliwVURXlTJsBaqgbHsCf6MbdF9866tbSdSLNIqruPjwcTUX6YLHFotmWOrPoh8zYMPuN24GAu7KKK/2OoZGedED6YViY/LtOxBTQ= Received: from MW3PR06CA0014.namprd06.prod.outlook.com (2603:10b6:303:2a::19) by DM6PR12MB4073.namprd12.prod.outlook.com (2603:10b6:5:217::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.17; Tue, 19 Oct 2021 22:55:19 +0000 Received: from CO1NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2a:cafe::d0) by MW3PR06CA0014.outlook.office365.com (2603:10b6:303:2a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.18 via Frontend Transport; Tue, 19 Oct 2021 22:55:19 +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 CO1NAM11FT035.mail.protection.outlook.com (10.13.175.36) 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:19 +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:15 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 06/13] drm: implement top-down allocation method Date: Wed, 20 Oct 2021 04:24:02 +0530 Message-ID: <20211019225409.569355-7-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: 69d65cbb-360c-4f39-d792-08d993538626 X-MS-TrafficTypeDiagnostic: DM6PR12MB4073: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pUdQloySIKKYQ0/57fntMPEGHvlG62U+5nUZfYxYXsILMXBBLQAyKNomyHPFyNdgSSTrQgJE8NPucxUNq39KZRfMAIRkCLo4E+w3ARIgKanwNpH0oO8QdSnRdgTim9qeAuRoDydHM5wdp1Zt9TzunlGqbRsfbQSX6EUUzETGNDuq+rX4Lk0pyNfo/BsOUFC2AOvWMsRxcQF9/sFIMKRb9KBD9BZnXt6FeWQpp5wKgdWyNgMHUMJFgtj+pqorKI1ENEUGV1ecnMMOOF9sze+TitMWIisix/Db81dD7BhFF7z7ebyoiW84CVxrhfwClYiM515Jw5A99qb21XBRhGgtVM+iWTAv7yx5cOfgY+A4eqq/QMY0nSg7oDY6UJsuPvsAwkaqRyEW6m/v0W17Q+pzm4TWfP95mgaXpcBgSb4ey1tJ1BRVr1D99Ivz/gK3FBuRJ2Qaz26/xjmwzWdhU88eSkeo747bvHhbn46cjYQJQl5mN3207YQwKkOm+NS+/JteG+LDXcdRR4dsUmEssQfS8O6Hx2admQFASBInsUR7z7xanU6XTbIKGw7JyOoEYUQFY2yKs4dJ0Mzvhbx9b6GZzyD3a6cvxGFRZcp0h7eAItvfpFb9JY67hGjsMSX1LZsYYpVXFZTiJqxq7T1ln5E6shhmHieVakkEcL/ykRUAu2q7gi1oLSC3hFB3VuvrreodWVvI7q4XuIhVDeUi/4bZoytHXLv1nVXxy3gHIMIuu1g= 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)(36840700001)(46966006)(2616005)(356005)(2906002)(8936002)(81166007)(16526019)(82310400003)(6666004)(316002)(54906003)(70206006)(1076003)(83380400001)(508600001)(5660300002)(47076005)(36756003)(336012)(110136005)(4326008)(186003)(86362001)(7696005)(26005)(70586007)(426003)(36860700001)(8676002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:19.0287 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 69d65cbb-360c-4f39-d792-08d993538626 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: CO1NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4073 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Implemented a function which walk through the order list, compares the offset and returns the maximum offset block, this method is unpredictable in obtaining the high range address blocks which depends on allocation and deallocation. for instance, if driver requests address at a low specific range, allocator traverses from the root block and splits the larger blocks until it reaches the specific block and in the process of splitting, lower orders in the freelist are occupied with low range address blocks and for the subsequent TOPDOWN memory request we may return the low range blocks.To overcome this issue, we may go with the below approach. The other approach, sorting each order list entries in ascending order and compares the last entry of each order list in the freelist and return the max block. This creates sorting overhead on every drm_buddy_free() request and split up of larger blocks for a single page request. Signed-off-by: Arunpravin --- drivers/gpu/drm/drm_buddy.c | 42 +++++++++++++++++++++++++++++++------ include/drm/drm_buddy.h | 1 + 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c index 138e9f1a7340..42ce4f8f4e0e 100644 --- a/drivers/gpu/drm/drm_buddy.c +++ b/drivers/gpu/drm/drm_buddy.c @@ -334,6 +334,27 @@ alloc_range(struct drm_buddy_mm *mm, return ERR_PTR(err); } +static struct drm_buddy_block * +get_maxblock(struct list_head *head) +{ + struct drm_buddy_block *max_block = NULL, *node; + + max_block = list_first_entry_or_null(head, + struct drm_buddy_block, + link); + + if (!max_block) + return NULL; + + list_for_each_entry(node, head, link) { + if (drm_buddy_block_offset(node) > + drm_buddy_block_offset(max_block)) + max_block = node; + } + + return max_block; +} + static struct drm_buddy_block * alloc_from_freelist(struct drm_buddy_mm *mm, unsigned int order, @@ -344,13 +365,22 @@ alloc_from_freelist(struct drm_buddy_mm *mm, int err; for (i = order; i <= mm->max_order; ++i) { - if (!list_empty(&mm->free_list[i])) { - block = list_first_entry_or_null(&mm->free_list[i], - struct drm_buddy_block, - link); + if (flags & DRM_BUDDY_TOPDOWN_ALLOCATION) { + if (!list_empty(&mm->free_list[i])) { + block = get_maxblock(&mm->free_list[i]); - if (block) - break; + if (block) + break; + } + } else { + if (!list_empty(&mm->free_list[i])) { + block = list_first_entry_or_null(&mm->free_list[i], + struct drm_buddy_block, + link); + + if (block) + break; + } } } diff --git a/include/drm/drm_buddy.h b/include/drm/drm_buddy.h index ebf03d151845..19c7e298613e 100644 --- a/include/drm/drm_buddy.h +++ b/include/drm/drm_buddy.h @@ -27,6 +27,7 @@ || size__ > end__ - start__; \ }) +#define DRM_BUDDY_TOPDOWN_ALLOCATION (1 << 0) #define DRM_BUDDY_RANGE_ALLOCATION (1 << 1) struct drm_buddy_block { From patchwork Tue Oct 19 22:54:03 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: 12571305 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 37979C433FE for ; Tue, 19 Oct 2021 22:55:42 +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 07473610E5 for ; Tue, 19 Oct 2021 22:55:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 07473610E5 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 113C56E18F; Tue, 19 Oct 2021 22:55:29 +0000 (UTC) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2048.outbound.protection.outlook.com [40.107.237.48]) by gabe.freedesktop.org (Postfix) with ESMTPS id 800236E10F; Tue, 19 Oct 2021 22:55:24 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FpQPUUFAqZ9QX1W8d/W9FF3wxWQ0dNAyuOH1HmcJTZ67WQ3DxuIaTMy/qhYKLcocKj2LkVPifmKfKhAL7e+xat+C3shJGkcAZFGYvBSgMaJhWlLBNHi8hrt3QeMkCODndQZFLFom1uRjR6e2c+s6eO2OMjapQnsyerDWAiqOdgWiSKJDyKmzITy8/IsyXLZeMlZkOP/vhTFd2uWO44yMYOaR3FyRAVirOW7E7JoGj9aPty+5pTPfuk3VMeTZZ2wOcEgdmSIbDQQzZtFlH69xydqNTVlik+lD2cFdsGZk8/k2JnszcFf7T+/B1iG6jlbkXzuMIlOUfkfXAtyxnVr8GQ== 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=MQBxOKpU7l/Tsjl3JpfxDHXDll0N3U7MesOsKmCfOSE=; b=PthQtVZtQY5gV6AqMWZz5QHOHRlK7wTlou2dqdgc0f3dXJO+pDffWwGMhAD/47nOU+mOzEJgOQMz9UEiGHRSi5tnlNjkLYo+JMeYT6rwed7ikDsl6UieuELsI88Vhe6FjK6BVkNXqgVamPAgmeVW8M7nDFbCuWoT7FOd3zWQg8m2AQpy7RQ6ibUiKgUQD43guhqo8hi2nLU8fItRGrf78gyht6LeL7zqWJ2bgPo6Dw+9uoFlP0ZpvQKgBS1fTr4s2HWcm7lsvFI6mYdkrK+UMUfBxVZ1kaS1vc1NF2j46bDVts+0O0qNMVpvwaKs8zYqHaJn7Eyu7n/jBxZLndZZbg== 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=MQBxOKpU7l/Tsjl3JpfxDHXDll0N3U7MesOsKmCfOSE=; b=0zSN8DRbQaIrbM6hDY447bt3SxLiYe/qGS8mgqpWWeiisnd31fTREyOjOqdVJ6x8/Uhj43ZXXtGvpfY945nDZqUv9o+si1dYpinsIFR4Uc2XLW5ldadTIXyGe11JDAPpfSgPCwgk3UglhEQlydY0M19KDLhT36Xe0Rm2SCH90cg= Received: from MW3PR06CA0001.namprd06.prod.outlook.com (2603:10b6:303:2a::6) by BN6PR12MB1219.namprd12.prod.outlook.com (2603:10b6:404:1c::17) 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:21 +0000 Received: from CO1NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2a:cafe::dc) by MW3PR06CA0001.outlook.office365.com (2603:10b6:303:2a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 22:55:21 +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 CO1NAM11FT035.mail.protection.outlook.com (10.13.175.36) 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:20 +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:18 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 07/13] drm: Implement method to free unused pages Date: Wed, 20 Oct 2021 04:24:03 +0530 Message-ID: <20211019225409.569355-8-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: cf5a7105-5c4e-44d8-cc4f-08d993538739 X-MS-TrafficTypeDiagnostic: BN6PR12MB1219: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:765; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iwQS/NVJYsJlVXU12VGucMgmJcttxuPt09p+UPmloqlUIvECrX1wlp1mI5g1eE0ZlnvCV6lNLfvZ8qOp3VkRPSBYjItImVoDn2hFwXNBPx62tG/a6Q7nVaCJfXFR8QTBmrtDiCMP7Y9xYs+7p/OQ+yNX1fv8JZR8spfsl7GkYN9UpDZV5i3VwQkHdr3Y1nIcwY/fQZa/rWTM52JX6xOBYUQp4quO4AJGT4TNroxzdWwQMUCAsgfkeXfyrfycv/FczYMZO/hGFJJowCb8Em2gilIYYnnYswVLIo93/tfNc6JhN1teKI6rawFez/Dz7TeZFW3YvX2bshiaYg1V8s9TauQTvy7q0fY+zOF74SYwindLZ32NPg0oiIRTPqpCkIFonsI0HrfpigpbPYTJsTJfQqW2rfICV81CsyS0X4+qgU/XhlMe+pobwqAEK70zQj6HqgHbXsezxQBR+c0mDkEvLFgkit/Oy/kY2d9ND7atosnCzqeszhedpbnH//XXU3ZPcVTI1/nWh0eoC650Y6oqAtL7N2vMf5xvWwZyzY4lFNLs6/kA3c/tYi2rxSAUWY2AFPeNHAXJUZlz5X5g5o6IPAh1N3BNDbsfsVi2o+6olRglh15VEdMhdvbGobHNqQ3q20mCwnO0fkUzEbs5nWCrzgqn1n1x8FS8mzD/1Tb/yDV2Pe1grSNWJxewNwsXiD1Bj7xRMWSbHVFI/N7tkvPbqmg+Hs5QJ2XufbnEd8zs9Zw= 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)(36840700001)(46966006)(426003)(70586007)(86362001)(16526019)(81166007)(186003)(5660300002)(8676002)(4326008)(83380400001)(47076005)(356005)(36860700001)(336012)(316002)(2906002)(7696005)(110136005)(508600001)(8936002)(26005)(6666004)(82310400003)(36756003)(2616005)(70206006)(54906003)(1076003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:20.8307 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cf5a7105-5c4e-44d8-cc4f-08d993538739 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: CO1NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1219 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On contiguous allocation, we round up the size to the nearest power of 2, implement a function to free unused pages. Signed-off-by: Arunpravin --- drivers/gpu/drm/drm_buddy.c | 87 +++++++++++++++++++++++++++++++++++++ include/drm/drm_buddy.h | 4 ++ 2 files changed, 91 insertions(+) diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c index 42ce4f8f4e0e..3e3303dd6658 100644 --- a/drivers/gpu/drm/drm_buddy.c +++ b/drivers/gpu/drm/drm_buddy.c @@ -256,6 +256,93 @@ static inline bool contains(u64 s1, u64 e1, u64 s2, u64 e2) return s1 <= s2 && e1 >= e2; } +int drm_buddy_free_unused_pages(struct drm_buddy_mm *mm, + u64 actual_size, + struct list_head *blocks) +{ + struct drm_buddy_block *block; + struct drm_buddy_block *buddy; + u64 actual_start; + u64 actual_end; + LIST_HEAD(dfs); + u64 count = 0; + int err; + + if (!list_is_singular(blocks)) + return -EINVAL; + + block = list_first_entry_or_null(blocks, + struct drm_buddy_block, + link); + + if (!block) + return -EINVAL; + + if (actual_size > drm_buddy_block_size(mm, block)) + return -EINVAL; + + if (actual_size == drm_buddy_block_size(mm, block)) + return 0; + + list_del(&block->link); + + actual_start = drm_buddy_block_offset(block); + actual_end = actual_start + actual_size - 1; + + if (drm_buddy_block_is_allocated(block)) + mark_free(mm, block); + + list_add(&block->tmp_link, &dfs); + + while (1) { + block = list_first_entry_or_null(&dfs, + struct drm_buddy_block, + tmp_link); + + if (!block) + break; + + list_del(&block->tmp_link); + + if (count == actual_size) + return 0; + + if (contains(actual_start, actual_end, drm_buddy_block_offset(block), + (drm_buddy_block_offset(block) + drm_buddy_block_size(mm, block) - 1))) { + BUG_ON(!drm_buddy_block_is_free(block)); + /* Allocate only required blocks */ + mark_allocated(block); + mm->avail -= drm_buddy_block_size(mm, block); + list_add_tail(&block->link, blocks); + count += drm_buddy_block_size(mm, block); + continue; + } + + if (drm_buddy_block_order(block) == 0) + continue; + + if (!drm_buddy_block_is_split(block)) { + err = split_block(mm, block); + + if (unlikely(err)) + goto err_undo; + } + + list_add(&block->right->tmp_link, &dfs); + list_add(&block->left->tmp_link, &dfs); + } + + return -ENOSPC; + +err_undo: + buddy = get_buddy(block); + if (buddy && + (drm_buddy_block_is_free(block) && + drm_buddy_block_is_free(buddy))) + __drm_buddy_free(mm, block); + return err; +} + static struct drm_buddy_block * alloc_range(struct drm_buddy_mm *mm, u64 start, u64 end, diff --git a/include/drm/drm_buddy.h b/include/drm/drm_buddy.h index 19c7e298613e..993312841140 100644 --- a/include/drm/drm_buddy.h +++ b/include/drm/drm_buddy.h @@ -145,6 +145,10 @@ int drm_buddy_alloc(struct drm_buddy_mm *mm, struct list_head *blocks, unsigned long flags); +int drm_buddy_free_unused_pages(struct drm_buddy_mm *mm, + u64 actual_size, + struct list_head *blocks); + void drm_buddy_free(struct drm_buddy_mm *mm, struct drm_buddy_block *block); void drm_buddy_free_list(struct drm_buddy_mm *mm, struct list_head *objects); From patchwork Tue Oct 19 22:54:04 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: 12571309 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 6172DC43217 for ; Tue, 19 Oct 2021 22:55:50 +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 3154461074 for ; Tue, 19 Oct 2021 22:55:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3154461074 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 C0E4F6E171; Tue, 19 Oct 2021 22:55:34 +0000 (UTC) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2063.outbound.protection.outlook.com [40.107.223.63]) by gabe.freedesktop.org (Postfix) with ESMTPS id E95136E199; Tue, 19 Oct 2021 22:55:29 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MOcKKffzcDnzn6n3rtPPPlKpb1G/p3vsNT+pn6sy+Du+2X6LqNBojMRbrOJ25GsVkaW5L/wOSH6hDNI+BY7OLBWwFy3Dp3lQ/tm1MM8W5nIGEl+vdzxQbTUiHWQaNVCgTku/8pSLxfeiCo6eTNw/WwAeHbeHObE/87EzW/rS5GJKu18Mc2FTkKQOA7zNMFuD+AB3y2K6qmrsmk4MEdypaevAsHh6jS+r731NICoQlmd8nEcO/abJpP2SYJYWs3m1a2+mwiNq5kCQYTsjbc60gJiLf1GUrTsxvb5ZwEoY8mBnPOsPcICHIHpCVikzRaAY4clhaWQ8ZsL5bBcz9Waw6g== 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=Y/xfRfK1JvoiFD6MEeRGhaE9eC4U5qnrjPQoE6YMPsY=; b=PyzNSQyosO7xkqjw72A9jDc9qNaCGIkwSoaV4IP1SoD89FJVcX9SdhBwWybgAKSa822EYX1QFU0dCTLloz9iyWc6j95sdjQko3y/PDgRBAOaWXDTqJaqv5Upnohh0D2JW6mHp9i2VJ2YnkfzBrrxcheQy7acxCg/zx4vsN/Q8fe3v9sgdBW14OxYxJbHGR8mEuWGj78K/hj9+0/UrZgMpZQrD5szlzAbGI3lboLtHjCN8QSo5eQ2IngKLg/htHcu2ELD/Aj7xmy4cqbHl68oo0mdGFpdD+0fCDzTul76B78w2ZP5n1+FlNkEitssRyS4ycgk+hefrjCQJs54qpg8wQ== 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=Y/xfRfK1JvoiFD6MEeRGhaE9eC4U5qnrjPQoE6YMPsY=; b=Y+Rqnf3U6YmjR4klmwP1rhYmORM4YtCYGVZ4f/MoPHy27mQcvQfIbVIJlj4wOK0BBgQzrVPFBk4hM6MU0OCFIzMKRc+/l14OOagUwghTjYvGLxOpilXRuJw36FpcXZ5NZFhG4r4fkjNAHynWfCQnt/3+mrC7BPA1Zij+K/TNKak= Received: from MWHPR11CA0023.namprd11.prod.outlook.com (2603:10b6:301:1::33) by BN9PR12MB5132.namprd12.prod.outlook.com (2603:10b6:408:119::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Tue, 19 Oct 2021 22:55:27 +0000 Received: from CO1NAM11FT032.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::d4) by MWHPR11CA0023.outlook.office365.com (2603:10b6:301:1::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 22:55:27 +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 CO1NAM11FT032.mail.protection.outlook.com (10.13.174.218) 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:26 +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:20 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 08/13] drm: export functions and write description Date: Wed, 20 Oct 2021 04:24:04 +0530 Message-ID: <20211019225409.569355-9-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: ecedb80b-5131-476a-d088-08d993538ab7 X-MS-TrafficTypeDiagnostic: BN9PR12MB5132: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4UwSZbmof7lh7xLjlbHuIPd2XGqJwlZvVevwfeIOk9EJF1WnbMdoFSmE3sH5dZ3xe0oAlDs6lYQKinjuytSBHuoi1b73D2sIJyCrIrvJiUQLL7zAnlYPx2W/0gNbwEeTaJwTyOPQl0T4p36E/Gmq3e92HDYbiNyV5YIO6J59FN/HotdbH0zRrijfvhEQkMxys3Nt3glrloqPamcVemTNX7cuvSo7FQG/qR9IQfMMOzFngJfcXbeU20TdUgsjTJZekSOjENJmGq4aIXSvYol0eZg34XuyJE5dyjbiAOT8UGPbPecXv8juFnzLDcb87dQkBzBvYF83Wo/Wt1eStBRFTOXHmgfNkaNHh2SGfvN88IRtcGl6wJ6NtbmK3OFZIR1wxXGYCvFaVuZg9FWYxldfhfTflC/oPV6sypruVirJeCiKseSElyI0oZMqq08mFNhBjeqinx8TJuZplYXq2E+I336/AobUg4nn/7cEn0y4gDDWYV8tzxfoNZu9Ort1sIpkO2O8nstMTKn6VT1btS6ZbTnpdA4wBXcIxHat4OABLCVKoOPBLlUG9MFf1A/69mqrCU3opp3sScCkVJKemO//e8MCcpWWifYQb01Jmi7/a5UZhZ/8NDceBHirOYZgQPGpZ/AxE8FiC/eoZMGw+3WKJvHpURApcDcmg0VMFpGk0WOnWpimzk9ZD9P4OpNtPMHMkOj9Lsvh6CH7YnAtJRCbBXA7b1j29CYVgSWQvvCTL9U= 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)(36756003)(83380400001)(82310400003)(2906002)(356005)(81166007)(47076005)(86362001)(1076003)(36860700001)(6666004)(70586007)(5660300002)(426003)(2616005)(336012)(4326008)(186003)(8676002)(16526019)(8936002)(26005)(7696005)(54906003)(110136005)(70206006)(316002)(508600001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:26.7047 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ecedb80b-5131-476a-d088-08d993538ab7 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: CO1NAM11FT032.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5132 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Export functions and write kerneldoc description Signed-off-by: Arunpravin --- drivers/gpu/drm/drm_buddy.c | 89 ++++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c index 3e3303dd6658..5eb7c4187009 100644 --- a/drivers/gpu/drm/drm_buddy.c +++ b/drivers/gpu/drm/drm_buddy.c @@ -63,6 +63,18 @@ static void mark_split(struct drm_buddy_block *block) list_del(&block->link); } +/** + * drm_buddy_init - init memory manager + * + * @mm: DRM buddy manager to initialize + * @size: size in bytes to manage + * @chunk_size: minimum page size in bytes for our allocations + * + * Initializes the memory manager and its resources. + * + * Returns: + * 0 on success, error code on failure. + */ int drm_buddy_init(struct drm_buddy_mm *mm, u64 size, u64 chunk_size) { unsigned int i; @@ -144,7 +156,15 @@ int drm_buddy_init(struct drm_buddy_mm *mm, u64 size, u64 chunk_size) kfree(mm->free_list); return -ENOMEM; } +EXPORT_SYMBOL(drm_buddy_init); +/** + * drm_buddy_fini - tear down the memory manager + * + * @mm: DRM buddy manager to free + * + * Cleanup memory manager resources and the freelist + */ void drm_buddy_fini(struct drm_buddy_mm *mm) { int i; @@ -159,6 +179,7 @@ void drm_buddy_fini(struct drm_buddy_mm *mm) kfree(mm->roots); kfree(mm->free_list); } +EXPORT_SYMBOL(drm_buddy_fini); static int split_block(struct drm_buddy_mm *mm, struct drm_buddy_block *block) @@ -235,6 +256,12 @@ void drm_buddy_free(struct drm_buddy_mm *mm, __drm_buddy_free(mm, block); } +/** + * drm_buddy_free_list - free blocks + * + * @mm: DRM buddy manager + * @objects: input list head to free blocks + */ void drm_buddy_free_list(struct drm_buddy_mm *mm, struct list_head *objects) { struct drm_buddy_block *block, *on; @@ -245,6 +272,7 @@ void drm_buddy_free_list(struct drm_buddy_mm *mm, struct list_head *objects) } INIT_LIST_HEAD(objects); } +EXPORT_SYMBOL(drm_buddy_free_list); static inline bool overlaps(u64 s1, u64 e1, u64 s2, u64 e2) { @@ -256,6 +284,20 @@ static inline bool contains(u64 s1, u64 e1, u64 s2, u64 e2) return s1 <= s2 && e1 >= e2; } +/** + * drm_buddy_free_unused_pages - free unused pages + * + * @mm: DRM buddy manager + * @actual_size: original size requested + * @blocks: output list head to add allocated blocks + * + * For contiguous allocation, we round up the size to the nearest + * power of two value, drivers consume *actual* size, so remaining + * portions are unused and it can be freed. + * + * Returns: + * 0 on success, error code on failure. + */ int drm_buddy_free_unused_pages(struct drm_buddy_mm *mm, u64 actual_size, struct list_head *blocks) @@ -342,6 +384,7 @@ int drm_buddy_free_unused_pages(struct drm_buddy_mm *mm, __drm_buddy_free(mm, block); return err; } +EXPORT_SYMBOL(drm_buddy_free_unused_pages); static struct drm_buddy_block * alloc_range(struct drm_buddy_mm *mm, @@ -494,13 +537,31 @@ alloc_from_freelist(struct drm_buddy_mm *mm, return ERR_PTR(err); } -/* - * Allocate power-of-two block. The order value here translates to: +/** + * drm_buddy_alloc - allocate power-of-two blocks + * + * @mm: DRM buddy manager to allocate from + * @start: start of the allowed range for this block + * @end: end of the allowed range for this block + * @size: size of the allocation + * @min_page_size: alignment of the allocation + * @blocks: output list head to add allocated blocks + * @flags: DRM_BUDDY_*_ALLOCATION flags + * + * alloc_range() invoked on range limitations, which traverses + * the tree and returns the desired block. + * + * alloc_from_freelist() called when *no* range restrictions + * are enforced, which picks the block from the freelist. + * + * blocks are allocated in order, order value here translates to: * - * 0 = 2^0 * mm->chunk_size - * 1 = 2^1 * mm->chunk_size - * 2 = 2^2 * mm->chunk_size - * ... + * 0 = 2^0 * mm->chunk_size + * 1 = 2^1 * mm->chunk_size + * 2 = 2^2 * mm->chunk_size + * + * Returns: + * 0 on success, error code on failure. */ int drm_buddy_alloc(struct drm_buddy_mm *mm, u64 start, u64 end, u64 size, @@ -573,7 +634,15 @@ int drm_buddy_alloc(struct drm_buddy_mm *mm, drm_buddy_free_list(mm, &allocated); return err; } +EXPORT_SYMBOL(drm_buddy_alloc); +/** + * drm_buddy_block_print - print block information + * + * @mm: DRM buddy manager + * @block: DRM buddy block + * @p: DRM printer to use + */ void drm_buddy_block_print(struct drm_buddy_mm *mm, struct drm_buddy_block *block, struct drm_printer *p) @@ -583,7 +652,14 @@ void drm_buddy_block_print(struct drm_buddy_mm *mm, drm_printf(p, "%#018llx-%#018llx: %llu\n", start, start + size, size); } +EXPORT_SYMBOL(drm_buddy_block_print); +/** + * drm_buddy_print - print allocator state + * + * @mm: DRM buddy manager + * @p: DRM printer to use + */ void drm_buddy_print(struct drm_buddy_mm *mm, struct drm_printer *p) { int order; @@ -611,6 +687,7 @@ void drm_buddy_print(struct drm_buddy_mm *mm, struct drm_printer *p) drm_printf(p, ", pages: %llu\n", count); } } +EXPORT_SYMBOL(drm_buddy_print); #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) #include "selftests/i915_buddy.c" From patchwork Tue Oct 19 22:54:05 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: 12571311 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 18600C433EF for ; Tue, 19 Oct 2021 22:55:53 +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 DDF7661074 for ; Tue, 19 Oct 2021 22:55:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DDF7661074 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 C7E316E1A2; Tue, 19 Oct 2021 22:55:34 +0000 (UTC) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2048.outbound.protection.outlook.com [40.107.220.48]) by gabe.freedesktop.org (Postfix) with ESMTPS id D4E4B6E171; Tue, 19 Oct 2021 22:55:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FMIENoFHLC0eeeWqAfLboS2Q3kmw3rR5vvHiF3ApIISxfUuSkHiO41fEdyJCb0ByfcLeB98aqWBZPqfWeZyf74nVD7ebeO8ouqlvFIH2MQEkgigSZkvbkHrum8jDhLz0zyfbp/0ZqolYnAOrfs7l0LfnC9tsIiwnZhDqJentR6Fq5zQSQmhrweEeP60m7v0A2MMli6EoagfKHXtCurVhzyzFVoAz84pHg5/Zb0MDqKZM+LHRd5uIsMsTZEPMynOlytmAwIf6tVCvsSpS/DWWMdjKDbkRyLbZz8XM3B9fggOKX9bOsHqsF9KeyFxHaS9VgIE6u3UkHpe+jTgdo4HuHw== 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=HOaNYgs60em2wNEpIbpujxhWyBqf8w+LPBDwKf4CB4o=; b=PSLVK0Pm+X5brXbVYv2FU0Djx4eKc3Oxu0xIlANZH57W4sUu+r+FX2Ojugf7PyWzH/52hQWIVszpP0tv4EHX5oCnAXUWflZq6LYL6vsnmmjXxBiSJfhZOsj8GdeY+v+PTjrpcHGH/g/U5pByuK+Vb028uOLIlN3tzEhoVfo7OF3NSArW3OFbFtTEE1G611zOZxUAIJBjw4puyfHrymJgfxWvfFOIoqwXTH+OoiKEXcOc7+E0/GSxjcFWuFWy7mqndwLv91xbXtE6P/uGzQL22CGth90t7ByYutfx9mkkq9Po6fM/WNhfmkthCk1elxCc6tushUay+JQdf0nXdrs9IQ== 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=HOaNYgs60em2wNEpIbpujxhWyBqf8w+LPBDwKf4CB4o=; b=S+nl6fSjKzptQJ2wvrJehYvXrMph9nNzSnWj2t8b0lcOoVyE+IgaXefIFRT6/RAjweL6k6AVgHNU6GwscKNizDLJwp9qe3vgMcr1jpYiZcwKY8LXTM8XLJU+QWNPmjVUu80O6WglHL6K/3It/dD0IQKhQd7AarZwTevEL3vM/e4= Received: from MWHPR11CA0015.namprd11.prod.outlook.com (2603:10b6:301:1::25) by BL1PR12MB5285.namprd12.prod.outlook.com (2603:10b6:208:31f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Tue, 19 Oct 2021 22:55:28 +0000 Received: from CO1NAM11FT032.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::80) by MWHPR11CA0015.outlook.office365.com (2603:10b6:301:1::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Tue, 19 Oct 2021 22:55:28 +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 CO1NAM11FT032.mail.protection.outlook.com (10.13.174.218) 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:27 +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:23 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 09/13] drm: remove i915 selftest config check Date: Wed, 20 Oct 2021 04:24:05 +0530 Message-ID: <20211019225409.569355-10-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: d7da8c8a-4488-4068-12ab-08d993538b63 X-MS-TrafficTypeDiagnostic: BL1PR12MB5285: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:274; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bQef3ED7duMEjUX7h4Vc/g1jIYjVollr2Zk9iBjK6f8E/xKoOMSJE08f+EAOr39MkDIQNRPN09BQDZEH2Xu8FO3195fGQjh0CuM5M4WzlP5K504rlg8pdu+XRFv0KRFBxGgIGzPKEDM/a5m2qokb6/3YpK+tL/HZLB3TF7BmYZfrZWKaT0+3ZkNJyM/XeplpNXBazR/xDiwgnGrLn6grmgikXrd3B3O3o/uTSxUfSCL1CidpLmIoZMupxQTM4/GiWiguHH9WYOWIlhyrkJuNSHSe2JATJT19Vk0gFuGU2RQpXxlSGk0iShmieg6WP2JbJ1FRBlq/VkCO2kzJNjbcZkNGjyqHfzHWUVKJNlT+WL5m7y7pAONQCUrr73kKjyNCLx6LsBLnlaZWWf/gmmULrg52hDKLPvjO9m2HNqIESXwDlhOCR/bqq444yyW6WSwzFo/VbOELVkBz+nwkmMasze4cvphua6mtNFg7S8I7OMwxYCSsjAG53SRk67FgsXIUzV7evXST+kBTKfDT2N7g8koPOIWvdOzDkD2F7ixqVHWfJMXOkga+mLJ3jGobVlHYAf9P2mFyMHrXuJQIIpXfcyaj1nrkmRKcB9Pifpkcr4SkbVgIIeqLdc8/uEM3zIwAiMg6yWdWucCkF7JOeLX8XnyRYnw8cCIsoQBIRJ3z3xlXnnmvBNk0vnfiBXCqMQ7bB00UTOFf/F+dzz3kNuVzpRPiO+22swO5ud7CenH6YOc= 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)(36840700001)(46966006)(86362001)(16526019)(4326008)(70206006)(186003)(5660300002)(8676002)(54906003)(7696005)(6666004)(110136005)(316002)(83380400001)(82310400003)(47076005)(26005)(356005)(36756003)(81166007)(8936002)(4744005)(426003)(1076003)(508600001)(336012)(70586007)(36860700001)(2906002)(2616005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:27.8091 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d7da8c8a-4488-4068-12ab-08d993538b63 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: CO1NAM11FT032.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5285 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" i915 buddy selftests will be moved to drm selftest folder, hence the config condition check may be removed. Signed-off-by: Arunpravin --- drivers/gpu/drm/drm_buddy.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c index 5eb7c4187009..e7a5d6d47a37 100644 --- a/drivers/gpu/drm/drm_buddy.c +++ b/drivers/gpu/drm/drm_buddy.c @@ -689,10 +689,6 @@ void drm_buddy_print(struct drm_buddy_mm *mm, struct drm_printer *p) } EXPORT_SYMBOL(drm_buddy_print); -#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) -#include "selftests/i915_buddy.c" -#endif - void drm_buddy_module_exit(void) { kmem_cache_destroy(slab_blocks); From patchwork Tue Oct 19 22:54:06 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: 12571317 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 3A56CC433EF for ; Tue, 19 Oct 2021 22:55:59 +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 06C43610E5 for ; Tue, 19 Oct 2021 22:55:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 06C43610E5 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 931EE6E199; Tue, 19 Oct 2021 22:55:48 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2085.outbound.protection.outlook.com [40.107.236.85]) by gabe.freedesktop.org (Postfix) with ESMTPS id 53FA96E1AA; Tue, 19 Oct 2021 22:55:33 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l+ZrAEa43vTQrcvkD9xM2cSTq7O2XGDXw+e92DfUsr7O+/jGhd4vOh0zOEgHr2SmLo1CLYgjeqgaaU9+0W4/bJOOEy2PizIT+8uV0Ve0x8v2gLBAG1L/vMPLb1iLx4Bkx1ZYT5BVQHNIqJK4cEnJEkBb2nvLC1cg5W8UjnyMquv6I7D1vJuRswruR26PUSXeaRZLVhs99JQr0fZ04PtGvDBC11aGrBwm6KxtJ/rvZCosvsMc38y63l6fEpz8B5FemWk2xTh9TY5cuxbHZHl7JZpEv3jpnAWEYAqkK/m2NlCsXtX3c57axLs/Ja32vKC+bJdYoHyt8nqnkDGQyS1GUw== 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=VVeYy56eCb+iGsN7YRkXl8dOk6j0635e/MV7AHIFjmg=; b=oUnwo2qLD1pYhni2ywkYaw7pNCLmXFESOnKJFqxSjtwYvCExUj745zHX/vt1Ydoh49xRe7cELr9R2UWMzB9AzZY3LwjpoeEF6XJMwaSNDpVaTbEIOW4sUd94K78TOoZDCUZ9MKCLwnIsE2CgLFlYIxiTJk1k2FC3n65WwWKLplb5IK//7zNMB5NGnGkb3mLkPj5qWPDp4q5I1ZkzW19aIKSyVvStwwsM0gOVdx4/aPhwqiVq3WLhWfiuW4bw+F36Zg0WlX2gGFgXn1hx1UACe2OLnjVNWD4w4w/9/ILkTKD2lncyki9PtW7IqcUlT90cPf7byh54eLxu5iC7gDyTHw== 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=VVeYy56eCb+iGsN7YRkXl8dOk6j0635e/MV7AHIFjmg=; b=ctworVyZ9Zz3ALgBHGJLs1sLBszMhkHWyvpyCiSn9WTNMI59M3el3oga8OAaADF8kkVelyxlE/tkQ/+HF53UKrPnKppIskswkJmTEApyJviWK4MfZv3iHMujpaeirsqnI8cWgvn1LJGo8tHUL/Tw+ibT52FShZSNLgquigI7+Ac= Received: from MW3PR06CA0001.namprd06.prod.outlook.com (2603:10b6:303:2a::6) by BN6PR1201MB0226.namprd12.prod.outlook.com (2603:10b6:405:56::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Tue, 19 Oct 2021 22:55:30 +0000 Received: from CO1NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2a:cafe::cc) by MW3PR06CA0001.outlook.office365.com (2603:10b6:303:2a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Tue, 19 Oct 2021 22:55:30 +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 CO1NAM11FT035.mail.protection.outlook.com (10.13.175.36) 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:30 +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:26 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 10/13] drm/i915: cleanup i915 buddy and apply DRM buddy Date: Wed, 20 Oct 2021 04:24:06 +0530 Message-ID: <20211019225409.569355-11-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: a1878d3d-72cf-4bb9-54b8-08d993538cbd X-MS-TrafficTypeDiagnostic: BN6PR1201MB0226: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:529; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1vV6iKxblt4h2hqpy2ZaR8auB3HcMCDdjJnncyR8kC0gqzNyHD9d3xRXRUPVQkIwfh3MuEoggLMuutPAP9oeHAj/iSpoV3JAtLTJQ2emiAFMfBsGL9OiT9OjZiq4yeY3FZh36gm7m4QuadJc2/WIK8rD1EE5BHV/GhjXu4BpvUQVgurpMqT+7y+vK3MrNFVonVhvPmrR1/Yqvu56gdga4dggph36uyBNeClX6jAQh4DCOAdO+UbHT2kSLnwdQpX2uD4/CqNECjHqYDRB+QDknjMUDPNf83brSmVBzHtveZZ7oLIbq9sOp21jrvonMhS4ER5A7UAie5Ls4oSLHYnk/1p9OQ07NuADgYoMYFefuQgH2kd2EOc/zcOi5wLoCcg3CBHmaD4VKdhgh8MAEMijiZcikcLsSZmGFDzE2Y4A/CWqjcybrgwkP5l8zwjCjNRLRItV33oNoShEZArEe1c5A3ZpOigx5/I3ShUuCgU2zSayD9qFXBLUkTSiJcFDRNMf2RuLpgZGGoYPyQedhXOuZ4Ar0yMXOcbMyK2LwaY0CfQM2uZzyd6AE4v5P9B6QRwmuo0cY1/2d0MuX+USndpo1nK7g3AZZZNDmiD0HDvxpJlchRDogg7g98WgS4ZiHhxUXhp4gm7PAqGWxzvJdN5iRaVmzU/OyvEa55+2l07TsI5JGxAKf19zOaQaUUakdMQ0JhK/KA8P0u6gVaGcfpb3zHKF4CO/nxZuteGZlFFhJbA= 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)(36840700001)(46966006)(2906002)(86362001)(4326008)(36756003)(6666004)(1076003)(82310400003)(8936002)(8676002)(5660300002)(70586007)(70206006)(83380400001)(186003)(16526019)(356005)(110136005)(2616005)(47076005)(508600001)(336012)(36860700001)(81166007)(426003)(316002)(7696005)(54906003)(26005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:30.0803 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a1878d3d-72cf-4bb9-54b8-08d993538cbd 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: CO1NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0226 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Remove i915 buddy references and add DRM buddy functions Signed-off-by: Arunpravin --- drivers/gpu/drm/i915/Makefile | 1 - drivers/gpu/drm/i915/i915_module.c | 3 - drivers/gpu/drm/i915/i915_scatterlist.c | 11 +-- drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 91 +++++++++---------- drivers/gpu/drm/i915/i915_ttm_buddy_manager.h | 5 +- 5 files changed, 53 insertions(+), 58 deletions(-) diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile index 467872cca027..fc5ca8c4ccb2 100644 --- a/drivers/gpu/drm/i915/Makefile +++ b/drivers/gpu/drm/i915/Makefile @@ -161,7 +161,6 @@ gem-y += \ i915-y += \ $(gem-y) \ i915_active.o \ - i915_buddy.o \ i915_cmd_parser.o \ i915_gem_evict.o \ i915_gem_gtt.o \ diff --git a/drivers/gpu/drm/i915/i915_module.c b/drivers/gpu/drm/i915/i915_module.c index ab2295dd4500..121b4178c5ca 100644 --- a/drivers/gpu/drm/i915/i915_module.c +++ b/drivers/gpu/drm/i915/i915_module.c @@ -9,7 +9,6 @@ #include "gem/i915_gem_context.h" #include "gem/i915_gem_object.h" #include "i915_active.h" -#include "i915_buddy.h" #include "i915_params.h" #include "i915_pci.h" #include "i915_perf.h" @@ -50,8 +49,6 @@ static const struct { { .init = i915_check_nomodeset }, { .init = i915_active_module_init, .exit = i915_active_module_exit }, - { .init = i915_buddy_module_init, - .exit = i915_buddy_module_exit }, { .init = i915_context_module_init, .exit = i915_context_module_exit }, { .init = i915_gem_context_module_init, diff --git a/drivers/gpu/drm/i915/i915_scatterlist.c b/drivers/gpu/drm/i915/i915_scatterlist.c index 4a6712dca838..84d622aa32d2 100644 --- a/drivers/gpu/drm/i915/i915_scatterlist.c +++ b/drivers/gpu/drm/i915/i915_scatterlist.c @@ -5,10 +5,9 @@ */ #include "i915_scatterlist.h" - -#include "i915_buddy.h" #include "i915_ttm_buddy_manager.h" +#include #include #include @@ -126,9 +125,9 @@ struct sg_table *i915_sg_from_buddy_resource(struct ttm_resource *res, struct i915_ttm_buddy_resource *bman_res = to_ttm_buddy_resource(res); const u64 size = res->num_pages << PAGE_SHIFT; const u64 max_segment = rounddown(UINT_MAX, PAGE_SIZE); - struct i915_buddy_mm *mm = bman_res->mm; + struct drm_buddy_mm *mm = bman_res->mm; struct list_head *blocks = &bman_res->blocks; - struct i915_buddy_block *block; + struct drm_buddy_block *block; struct scatterlist *sg; struct sg_table *st; resource_size_t prev_end; @@ -151,8 +150,8 @@ struct sg_table *i915_sg_from_buddy_resource(struct ttm_resource *res, list_for_each_entry(block, blocks, link) { u64 block_size, offset; - block_size = min_t(u64, size, i915_buddy_block_size(mm, block)); - offset = i915_buddy_block_offset(block); + block_size = min_t(u64, size, drm_buddy_block_size(mm, block)); + offset = drm_buddy_block_offset(block); while (block_size) { u64 len; diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c index d59fbb019032..d09ea6c83a27 100644 --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c @@ -7,15 +7,15 @@ #include #include +#include #include "i915_ttm_buddy_manager.h" -#include "i915_buddy.h" #include "i915_gem.h" struct i915_ttm_buddy_manager { struct ttm_resource_manager manager; - struct i915_buddy_mm mm; + struct drm_buddy_mm mm; struct list_head reserved; struct mutex lock; u64 default_page_size; @@ -34,15 +34,12 @@ static int i915_ttm_buddy_man_alloc(struct ttm_resource_manager *man, { struct i915_ttm_buddy_manager *bman = to_buddy_manager(man); struct i915_ttm_buddy_resource *bman_res; - struct i915_buddy_mm *mm = &bman->mm; + struct drm_buddy_mm *mm = &bman->mm; unsigned long n_pages; - unsigned int min_order; u64 min_page_size; u64 size; int err; - GEM_BUG_ON(place->fpfn || place->lpfn); - bman_res = kzalloc(sizeof(*bman_res), GFP_KERNEL); if (!bman_res) return -ENOMEM; @@ -59,11 +56,12 @@ static int i915_ttm_buddy_man_alloc(struct ttm_resource_manager *man, min_page_size = bo->page_alignment << PAGE_SHIFT; GEM_BUG_ON(min_page_size < mm->chunk_size); - min_order = ilog2(min_page_size) - ilog2(mm->chunk_size); - if (place->flags & TTM_PL_FLAG_CONTIGUOUS) { + + if (place->flags & TTM_PL_FLAG_CONTIGUOUS) size = roundup_pow_of_two(size); - min_order = ilog2(size) - ilog2(mm->chunk_size); - } + + if (place->fpfn || place->lpfn) + bman_res->flags |= DRM_BUDDY_RANGE_ALLOCATION; if (size > mm->size) { err = -E2BIG; @@ -72,41 +70,34 @@ static int i915_ttm_buddy_man_alloc(struct ttm_resource_manager *man, n_pages = size >> ilog2(mm->chunk_size); - do { - struct i915_buddy_block *block; - unsigned int order; - - order = fls(n_pages) - 1; - GEM_BUG_ON(order > mm->max_order); - GEM_BUG_ON(order < min_order); - - do { - mutex_lock(&bman->lock); - block = i915_buddy_alloc(mm, order); - mutex_unlock(&bman->lock); - if (!IS_ERR(block)) - break; - - if (order-- == min_order) { - err = -ENOSPC; - goto err_free_blocks; - } - } while (1); + mutex_lock(&bman->lock); + err = drm_buddy_alloc(mm, (uint64_t)place->fpfn << PAGE_SHIFT, + (uint64_t)place->lpfn << PAGE_SHIFT, + (uint64_t)n_pages << PAGE_SHIFT, + min_page_size, + &bman_res->blocks, + bman_res->flags); + mutex_unlock(&bman->lock); - n_pages -= BIT(order); + if (unlikely(err)) + goto err_free_blocks; - list_add_tail(&block->link, &bman_res->blocks); +#if 0 + if (place->flags & TTM_PL_FLAG_CONTIGUOUS) { + err = drm_buddy_free_unused_pages(mm, (uint64_t)n_pages << PAGE_SHIFT, + &bman_res->blocks); - if (!n_pages) - break; - } while (1); + if (unlikely(err)) + goto err_free_blocks; + } +#endif *res = &bman_res->base; return 0; err_free_blocks: mutex_lock(&bman->lock); - i915_buddy_free_list(mm, &bman_res->blocks); + drm_buddy_free_list(mm, &bman_res->blocks); mutex_unlock(&bman->lock); err_free_res: kfree(bman_res); @@ -120,7 +111,7 @@ static void i915_ttm_buddy_man_free(struct ttm_resource_manager *man, struct i915_ttm_buddy_manager *bman = to_buddy_manager(man); mutex_lock(&bman->lock); - i915_buddy_free_list(&bman->mm, &bman_res->blocks); + drm_buddy_free_list(&bman->mm, &bman_res->blocks); mutex_unlock(&bman->lock); kfree(bman_res); @@ -130,17 +121,17 @@ static void i915_ttm_buddy_man_debug(struct ttm_resource_manager *man, struct drm_printer *printer) { struct i915_ttm_buddy_manager *bman = to_buddy_manager(man); - struct i915_buddy_block *block; + struct drm_buddy_block *block; mutex_lock(&bman->lock); drm_printf(printer, "default_page_size: %lluKiB\n", bman->default_page_size >> 10); - i915_buddy_print(&bman->mm, printer); + drm_buddy_print(&bman->mm, printer); drm_printf(printer, "reserved:\n"); list_for_each_entry(block, &bman->reserved, link) - i915_buddy_block_print(&bman->mm, block, printer); + drm_buddy_block_print(&bman->mm, block, printer); mutex_unlock(&bman->lock); } @@ -190,7 +181,7 @@ int i915_ttm_buddy_man_init(struct ttm_device *bdev, if (!bman) return -ENOMEM; - err = i915_buddy_init(&bman->mm, size, chunk_size); + err = drm_buddy_init(&bman->mm, size, chunk_size); if (err) goto err_free_bman; @@ -228,7 +219,7 @@ int i915_ttm_buddy_man_fini(struct ttm_device *bdev, unsigned int type) { struct ttm_resource_manager *man = ttm_manager_type(bdev, type); struct i915_ttm_buddy_manager *bman = to_buddy_manager(man); - struct i915_buddy_mm *mm = &bman->mm; + struct drm_buddy_mm *mm = &bman->mm; int ret; ttm_resource_manager_set_used(man, false); @@ -240,8 +231,8 @@ int i915_ttm_buddy_man_fini(struct ttm_device *bdev, unsigned int type) ttm_set_driver_manager(bdev, type, NULL); mutex_lock(&bman->lock); - i915_buddy_free_list(mm, &bman->reserved); - i915_buddy_fini(mm); + drm_buddy_free_list(mm, &bman->reserved); + drm_buddy_fini(mm); mutex_unlock(&bman->lock); ttm_resource_manager_cleanup(man); @@ -264,11 +255,19 @@ int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man, u64 start, u64 size) { struct i915_ttm_buddy_manager *bman = to_buddy_manager(man); - struct i915_buddy_mm *mm = &bman->mm; + struct drm_buddy_mm *mm = &bman->mm; + unsigned long flags = 0; + u64 min_size; int ret; + min_size = size; + flags |= DRM_BUDDY_RANGE_ALLOCATION; + mutex_lock(&bman->lock); - ret = i915_buddy_alloc_range(mm, &bman->reserved, start, size); + ret = drm_buddy_alloc(mm, start, start + size, + size, min_size, + &bman->reserved, + flags); mutex_unlock(&bman->lock); return ret; diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h index 0722d33f3e14..c8c0dea1cdca 100644 --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h @@ -13,7 +13,7 @@ struct ttm_device; struct ttm_resource_manager; -struct i915_buddy_mm; +struct drm_buddy_mm; /** * struct i915_ttm_buddy_resource @@ -28,7 +28,8 @@ struct i915_buddy_mm; struct i915_ttm_buddy_resource { struct ttm_resource base; struct list_head blocks; - struct i915_buddy_mm *mm; + unsigned long flags; + struct drm_buddy_mm *mm; }; /** From patchwork Tue Oct 19 22:54:07 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: 12571315 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 8F278C433EF for ; Tue, 19 Oct 2021 22:55:57 +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 5B50E61074 for ; Tue, 19 Oct 2021 22:55:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5B50E61074 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 A9B046E201; Tue, 19 Oct 2021 22:55:43 +0000 (UTC) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on2040.outbound.protection.outlook.com [40.107.102.40]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4D1766E1AA; Tue, 19 Oct 2021 22:55:38 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gCp7hemSFnETOlD+jtZUSIyo5g/J9wS3KjNkfxsgs1eV9GB7N3X05lnaU7irCRo+tApfHfkAwskhwP6xj68mSbyxinwV4O/1GGRlw1YrS5cN0pZR3KLtnZXNIHpO83/m59vmgUPHaZvp/w1yqG6+6Yy/+ePcylte1aIr6TQt0aMZBdRYBAwpFkrYzS5evjU1Ac/n9JuHYmFQZRzU6euIu4H6lctS2HDErL8Wvai3IbDTL1eJichDqZ00QwuD5LlLOXNjmCXxXKNCIA1PL8wzEz0Pwqa/FgUZCkQY7Kr6A9UgwjQm1EcI9P0neEwwou0TwrS+G0AZd1tDiW0/skdHYQ== 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=YZ+CyI3y3SClURoNfvSSfgDGivPmeGfCjCpQQqyIqpo=; b=a2k9LzNmatjWN2wQda0Fi0w3S+SlvkfuL2fbtMuwSRDvcC/2/XoPN5yO7m8wPRLM3XlAq2M5YizyFUM/oXMvwz4DAWOvQeYxV3ivYcywow+UOJmOIl0ahOc/EbRyDarsaDve3uFZm/MH7vBsQBsUfqnDzEy9rY9Tr40dVOQJDmyy1LsJf2y1ob5Ey4gOIbQ3Ra8dfczPmZWlZ/jgn/F19qqkjGqhj9UhFwWD2VYOhHXMTiBaILjx2XubvaWpTeYT6zE1HROU/gUTiFJcca7cC8AFEK2+D5rFkRavN7Sr4pAcOxYhJ/ELkeM0I2g6oJSVpIE2SZC11dIqNC8wx329HA== 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=YZ+CyI3y3SClURoNfvSSfgDGivPmeGfCjCpQQqyIqpo=; b=CoxSSqQRNXWCage22CrPUyE0oylXTtOU+ztNAYixPokxA5cerW6IqIH+wliZrWNLQvDgvrz7MaT7A8dxcNVNKqK4bPavPkoF/jHnVgDI0TrZFFsTXaWdbXy8I2Y9QZ0yfY6Gbr+qjwdTZt/obUDB6ruHdh+xD2XZwfe9vnpS9/c= Received: from MW4PR04CA0249.namprd04.prod.outlook.com (2603:10b6:303:88::14) by DM6PR12MB3738.namprd12.prod.outlook.com (2603:10b6:5:1c7::17) 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:35 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:303:88:cafe::61) by MW4PR04CA0249.outlook.office365.com (2603:10b6:303:88::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.18 via Frontend Transport; Tue, 19 Oct 2021 22:55:35 +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:34 +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:29 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 11/13] drm/amdgpu: move vram defines into a header Date: Wed, 20 Oct 2021 04:24:07 +0530 Message-ID: <20211019225409.569355-12-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: dd59ef77-8e20-4b6e-ee4d-08d993538f98 X-MS-TrafficTypeDiagnostic: DM6PR12MB3738: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ub3rBAlRofZKYGpU3bF2afcgsPJ04qfTAxsTGDY7f0xHf0TT2tzfZLNsx8T5VBCsh+lWlnnvbOf95aCTb6nKcNKu6FsaorZM6takkiDKmsWPkwVrZTczH1TEBAxi12x8zpMa5wjXwzgt4YG7lTDxIh8n4M03jQVA9ucupS+1NXgPyDJFDjb8uRofJRauAMsZSvx8qfka9S01/0f4YlcBp0Fk2NJc74mQBFi2HTgnajmh/r22QFciztjfGGgeu/VPm8qLHwjKYtQnWwtpVIfe7x+2TLJKWpIHfG4AdnSZ5gbaCGyiVFzfKGZhBE4S011I72tdP61/Kva926Li8JHR1BOAQu0yLqTkHhdPTbv2WmdvV69KSZcbf2PoLp58fjFOK+YrlfYL4HjUKnKhoIgkzvgDgikU3BZk2TOzixbWKoQYsSUBDCjInzH2UsgFwhokFXBpKMrWkUtbKcfWVtHtE6yzNHfT0tVe8lkWgoNDmr8pc+lwDfJJPfKtfFR2jFBH/wJxLEcgUyXEq+rxC0AV0JYwmji9OF4xCpFXBOvHNYk1wApJpMeNTKrirgfn1x7DX2H1K+EGKBr1WkRU2f/nf8iP6Cux8qST0f9gea9knY4zksgRdaCyaAWAivRL9alChXI/cdmeqT/mBuytKI9OJnuCSemRexQ0Bjgffg84dOFZFipMq5rTZsekaNAB426RyJaV6YQ4beQY1exrMJIw9D/tv0up7bi8ZhEWkgR0E3w= 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)(356005)(81166007)(6666004)(336012)(8936002)(70206006)(26005)(7696005)(5660300002)(316002)(83380400001)(2616005)(426003)(508600001)(36860700001)(4326008)(70586007)(2906002)(54906003)(16526019)(47076005)(1076003)(8676002)(82310400003)(36756003)(110136005)(186003)(86362001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:34.8577 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dd59ef77-8e20-4b6e-ee4d-08d993538f98 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: DM6PR12MB3738 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Move vram defines and inline functions into a header file Signed-off-by: Arunpravin --- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 18 +---- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h | 72 ++++++++++++++++++++ 2 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c index 7b2b0980ec41..a9182c59907a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c @@ -29,25 +29,9 @@ #include "amdgpu_vm.h" #include "amdgpu_res_cursor.h" #include "amdgpu_atomfirmware.h" +#include "amdgpu_vram_mgr.h" #include "atom.h" -struct amdgpu_vram_reservation { - struct list_head node; - struct drm_mm_node mm_node; -}; - -static inline struct amdgpu_vram_mgr * -to_vram_mgr(struct ttm_resource_manager *man) -{ - return container_of(man, struct amdgpu_vram_mgr, manager); -} - -static inline struct amdgpu_device * -to_amdgpu_device(struct amdgpu_vram_mgr *mgr) -{ - return container_of(mgr, struct amdgpu_device, mman.vram_mgr); -} - /** * DOC: mem_info_vram_total * diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h new file mode 100644 index 000000000000..fcab6475ccbb --- /dev/null +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: MIT + * Copyright 2021 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef __AMDGPU_VRAM_MGR_H__ +#define __AMDGPU_VRAM_MGR_H__ + +#include + +struct amdgpu_vram_mgr_node { + struct ttm_resource base; + struct list_head blocks; + unsigned long flags; +}; + +struct amdgpu_vram_reservation { + uint64_t start; + uint64_t size; + uint64_t min_size; + unsigned long flags; + struct list_head block; + struct list_head node; +}; + +static inline uint64_t node_start(struct drm_buddy_block *block) +{ + return drm_buddy_block_offset(block); +} + +static inline uint64_t node_size(struct drm_buddy_block *block) +{ + return PAGE_SIZE << drm_buddy_block_order(block); +} + +static inline struct amdgpu_vram_mgr_node * +to_amdgpu_vram_mgr_node(struct ttm_resource *res) +{ + return container_of(res, struct amdgpu_vram_mgr_node, base); +} + +static inline struct amdgpu_vram_mgr * +to_vram_mgr(struct ttm_resource_manager *man) +{ + return container_of(man, struct amdgpu_vram_mgr, manager); +} + +static inline struct amdgpu_device * +to_amdgpu_device(struct amdgpu_vram_mgr *mgr) +{ + return container_of(mgr, struct amdgpu_device, mman.vram_mgr); +} + +#endif 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: 12571313 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 C3DAAC433EF for ; Tue, 19 Oct 2021 22:55:55 +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 9452A61074 for ; Tue, 19 Oct 2021 22:55:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9452A61074 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 3BA776E1AA; Tue, 19 Oct 2021 22:55:43 +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 Subject: [PATCH 12/13] drm/amdgpu: add cursor support for drm buddy 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-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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" - 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 From patchwork Tue Oct 19 22:54:09 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: 12571319 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 5725EC433EF for ; Tue, 19 Oct 2021 22:56:01 +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 21144610E5 for ; Tue, 19 Oct 2021 22:56:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 21144610E5 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 345D06E202; Tue, 19 Oct 2021 22:55:49 +0000 (UTC) Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2040.outbound.protection.outlook.com [40.107.220.40]) by gabe.freedesktop.org (Postfix) with ESMTPS id 38BC16E1D7; Tue, 19 Oct 2021 22:55:42 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gcl6uwNfNR2U2feSqfpEZrSg0NIKwcJ8bczrgukPZ94A+OSgZbeUUE8MxyTZZ7TpOGlMP9VlK8TuvONNEV0ci41+DUf6xtEwo74YNZJcKVhxZT6T8ph0Y5+RSf084GzvKeHOYxKstk6tLqtAtOPKPkOz+kVdSHDfid7lzyAPrmmQhqKTwLxootVd2F3WocBb3an2qR6Zi7R6h4u0L/mBipcF72viJ1URH8Z6JKPvftzWcKhHG01myZntnz+aOrJWR2y7tHF5vWgFohdLlBzfwnPIXrLgQnW5UnN4u9fnDvFTiMDcfMGhlpb7Yg46hFnGvoQymRFZmTj2mnmwkeiDLw== 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=NGrbXmleBq24pAfVxMG7jpZ6d5sjT+Ryv1N9H8yGY9g=; b=REd7aMGnqvhpNaHdmZF62w/r82lkQiTwTHlEfIQ/dn5RHkbXOx94zobelE/Sfw/zADzcMizsIYmbipiUuuHug+pDd8eiRw2QGae9an/eS/KqZ1OsesszGB3nVr/+k2Y6fu6CYVh3713qwKbgkmOi7gcAU1m3I+Z11ocm7YF43iTIcRXyt/Q4BMzvQJU6c9Q08jUtszYxW8GmDVKSUv3QySHQkrW5ezIvldwmo2I/0yKXWqY5ZPEbsllZvi0/lOR50kqSHsdzj5TmFDbPBiNJERsO8UGvlV9peq2bCTEOXSnfeboCAVABpEupSft4dqz9MLEc2UoLLULKrzS+JvPsDg== 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=NGrbXmleBq24pAfVxMG7jpZ6d5sjT+Ryv1N9H8yGY9g=; b=OVZ+ONd1hEq88TPrVXuca2LApMloul/QbE06xH3FaOij4nsVTRE3ZtuL+yMpRDUID0989deKbV9sV6C79bUT0HmDlDRFBSsN28+KQppakZJGSwCT803x78tabYqfirH+7o9FBZFMt4XMdy19trhaHpPwKzTICyuvH9YntIovdV4= Received: from MWHPR07CA0021.namprd07.prod.outlook.com (2603:10b6:300:116::31) by BYAPR12MB3303.namprd12.prod.outlook.com (2603:10b6:a03:131::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.17; Tue, 19 Oct 2021 22:55:39 +0000 Received: from CO1NAM11FT017.eop-nam11.prod.protection.outlook.com (2603:10b6:300:116:cafe::e7) by MWHPR07CA0021.outlook.office365.com (2603:10b6:300:116::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16 via Frontend Transport; Tue, 19 Oct 2021 22:55:39 +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 CO1NAM11FT017.mail.protection.outlook.com (10.13.175.108) 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:38 +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:34 -0500 From: Arunpravin To: , , CC: , , , , Arunpravin Subject: [PATCH 13/13] drm/amdgpu: cleanup drm_mm and apply DRM buddy Date: Wed, 20 Oct 2021 04:24:09 +0530 Message-ID: <20211019225409.569355-14-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: ec15a2a5-da44-4ca4-7847-08d9935391d0 X-MS-TrafficTypeDiagnostic: BYAPR12MB3303: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:350; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wh/dznJrqyAgaBtsnm9n8y5LwVzvwVidRweBXk0/vfqY0wPaUCWlSZbSQDP+larQIS7IslSvq8foVkMuI6zs49swVL2FwdzccUGQ6EuENxHE+1xON3FYzI3AEGuwClqEadCRxCaIpqxJBDanO6O70Ztgn69j1P8GGwLVh03EH12Tznc5ueUHtgA57skSR2AkHXkFqzzvGF4IkBRtgf4gYMg/i3Fdv2w9MoxomsRp0XmjGSWmmxHsHmSeynGTdhg34wRoAGSxULPXS9fMq9mv5CBvgCml+tyBUixXaLlD4bSlwr8+MlsnRdMqxtyAwm3CQYOtH+pTpsFaH5vdohqr89zEFUlaoComyYor0VtwaMFBw1V1T42fuVBzhRBP/t+1XIG4+fFVclkpE28O3UMlmn18WGPpi5vqwPH44rGJai6QfpmvG4gp7xgHG2W6aBS9hLzL7RH1LSN4jMVa9zHGWyIc76INOYFi03L+EtHoOjEnM4350Z6BzWbql2Pq0keCCObr8alNldU0QCavSjS5TZ4gCZnelsLbuMyD8YrjjgbXFlblfOSeuGqJtWS++4V7fYCRaFgw+k6GVFGSOPMY1EcmlKUxxZQtC+6MwemdI2I0Q5p6NjFoIMlFQUi99DOlERvLsGALr9Ov6kCPrPwpZFqMZZPe1Tp6ysbXRntM7bvdZHKgTWDSAw9g23S3u6sojnGwn0mXyjTSv5BbH5pHOkI6QAmeA5Eo/LveGLvNz1k= 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)(36840700001)(46966006)(36756003)(316002)(8936002)(2906002)(426003)(30864003)(7696005)(5660300002)(1076003)(81166007)(47076005)(508600001)(70586007)(83380400001)(4326008)(2616005)(26005)(8676002)(86362001)(54906003)(110136005)(336012)(82310400003)(356005)(36860700001)(16526019)(70206006)(6666004)(186003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 22:55:38.5884 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ec15a2a5-da44-4ca4-7847-08d9935391d0 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: CO1NAM11FT017.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3303 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Remove drm_mm references and add DRM buddy functions Signed-off-by: Arunpravin --- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 233 +++++++++++-------- 2 files changed, 138 insertions(+), 99 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h index 639c7b41e30b..a8ac9902ab29 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h @@ -26,6 +26,7 @@ #include #include +#include #include "amdgpu.h" #define AMDGPU_PL_GDS (TTM_PL_PRIV + 0) @@ -40,12 +41,13 @@ struct amdgpu_vram_mgr { struct ttm_resource_manager manager; - struct drm_mm mm; + struct drm_buddy_mm mm; spinlock_t lock; struct list_head reservations_pending; struct list_head reserved_pages; atomic64_t usage; atomic64_t vis_usage; + uint64_t default_page_size; }; struct amdgpu_gtt_mgr { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c index a9182c59907a..0c55a5ea1ed1 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c @@ -180,10 +180,10 @@ const struct attribute_group amdgpu_vram_mgr_attr_group = { * Calculate how many bytes of the MM node are inside visible VRAM */ static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, - struct drm_mm_node *node) + struct drm_buddy_block *block) { - uint64_t start = node->start << PAGE_SHIFT; - uint64_t end = (node->size + node->start) << PAGE_SHIFT; + uint64_t start = node_start(block); + uint64_t end = start + node_size(block); if (start >= adev->gmc.visible_vram_size) return 0; @@ -204,9 +204,9 @@ u64 amdgpu_vram_mgr_bo_visible_size(struct amdgpu_bo *bo) { struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev); struct ttm_resource *res = bo->tbo.resource; - unsigned pages = res->num_pages; - struct drm_mm_node *mm; - u64 usage; + struct amdgpu_vram_mgr_node *node = to_amdgpu_vram_mgr_node(res); + struct drm_buddy_block *block; + u64 usage = 0; if (amdgpu_gmc_vram_full_visible(&adev->gmc)) return amdgpu_bo_size(bo); @@ -214,9 +214,8 @@ u64 amdgpu_vram_mgr_bo_visible_size(struct amdgpu_bo *bo) if (res->start >= adev->gmc.visible_vram_size >> PAGE_SHIFT) return 0; - mm = &container_of(res, struct ttm_range_mgr_node, base)->mm_nodes[0]; - for (usage = 0; pages; pages -= mm->size, mm++) - usage += amdgpu_vram_mgr_vis_size(adev, mm); + list_for_each_entry(block, &node->blocks, link) + usage += amdgpu_vram_mgr_vis_size(adev, block); return usage; } @@ -226,21 +225,30 @@ static void amdgpu_vram_mgr_do_reserve(struct ttm_resource_manager *man) { struct amdgpu_vram_mgr *mgr = to_vram_mgr(man); struct amdgpu_device *adev = to_amdgpu_device(mgr); - struct drm_mm *mm = &mgr->mm; + struct drm_buddy_mm *mm = &mgr->mm; struct amdgpu_vram_reservation *rsv, *temp; + struct drm_buddy_block *block; uint64_t vis_usage; list_for_each_entry_safe(rsv, temp, &mgr->reservations_pending, node) { - if (drm_mm_reserve_node(mm, &rsv->mm_node)) + if (drm_buddy_alloc(mm, rsv->start, rsv->start + rsv->size, + rsv->size, rsv->min_size, &rsv->block, + rsv->flags)) continue; - dev_dbg(adev->dev, "Reservation 0x%llx - %lld, Succeeded\n", - rsv->mm_node.start, rsv->mm_node.size); + block = list_first_entry_or_null(&rsv->block, + struct drm_buddy_block, + link); - vis_usage = amdgpu_vram_mgr_vis_size(adev, &rsv->mm_node); - atomic64_add(vis_usage, &mgr->vis_usage); - atomic64_add(rsv->mm_node.size << PAGE_SHIFT, &mgr->usage); - list_move(&rsv->node, &mgr->reserved_pages); + if (block) { + dev_dbg(adev->dev, "Reservation 0x%llx - %lld, Succeeded\n", + rsv->start, rsv->size); + + vis_usage = amdgpu_vram_mgr_vis_size(adev, block); + atomic64_add(vis_usage, &mgr->vis_usage); + atomic64_add(rsv->size, &mgr->usage); + list_move(&rsv->node, &mgr->reserved_pages); + } } } @@ -264,11 +272,15 @@ int amdgpu_vram_mgr_reserve_range(struct ttm_resource_manager *man, return -ENOMEM; INIT_LIST_HEAD(&rsv->node); - rsv->mm_node.start = start >> PAGE_SHIFT; - rsv->mm_node.size = size >> PAGE_SHIFT; + INIT_LIST_HEAD(&rsv->block); + + rsv->start = start; + rsv->size = size; + rsv->min_size = size; + rsv->flags |= DRM_BUDDY_RANGE_ALLOCATION; spin_lock(&mgr->lock); - list_add_tail(&mgr->reservations_pending, &rsv->node); + list_add_tail(&rsv->node, &mgr->reservations_pending); amdgpu_vram_mgr_do_reserve(man); spin_unlock(&mgr->lock); @@ -296,16 +308,16 @@ int amdgpu_vram_mgr_query_page_status(struct ttm_resource_manager *man, spin_lock(&mgr->lock); list_for_each_entry(rsv, &mgr->reservations_pending, node) { - if ((rsv->mm_node.start <= start) && - (start < (rsv->mm_node.start + rsv->mm_node.size))) { + if ((rsv->start <= start) && + (start < (rsv->start + rsv->size))) { ret = -EBUSY; goto out; } } list_for_each_entry(rsv, &mgr->reserved_pages, node) { - if ((rsv->mm_node.start <= start) && - (start < (rsv->mm_node.start + rsv->mm_node.size))) { + if ((rsv->start <= start) && + (start < (rsv->start + rsv->size))) { ret = 0; goto out; } @@ -317,28 +329,6 @@ int amdgpu_vram_mgr_query_page_status(struct ttm_resource_manager *man, return ret; } -/** - * amdgpu_vram_mgr_virt_start - update virtual start address - * - * @mem: ttm_resource to update - * @node: just allocated node - * - * Calculate a virtual BO start address to easily check if everything is CPU - * accessible. - */ -static void amdgpu_vram_mgr_virt_start(struct ttm_resource *mem, - struct drm_mm_node *node) -{ - unsigned long start; - - start = node->start + node->size; - if (start > mem->num_pages) - start -= mem->num_pages; - else - start = 0; - mem->start = max(mem->start, start); -} - /** * amdgpu_vram_mgr_new - allocate new ranges * @@ -354,13 +344,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, const struct ttm_place *place, struct ttm_resource **res) { - unsigned long lpfn, num_nodes, pages_per_node, pages_left, pages; + unsigned long lpfn, pages_per_node, pages_left, pages, n_pages; + uint64_t vis_usage = 0, mem_bytes, max_bytes, min_page_size; struct amdgpu_vram_mgr *mgr = to_vram_mgr(man); struct amdgpu_device *adev = to_amdgpu_device(mgr); - uint64_t vis_usage = 0, mem_bytes, max_bytes; - struct ttm_range_mgr_node *node; - struct drm_mm *mm = &mgr->mm; - enum drm_mm_insert_mode mode; + struct amdgpu_vram_mgr_node *node; + struct drm_buddy_mm *mm = &mgr->mm; + struct drm_buddy_block *block; unsigned i; int r; @@ -379,10 +369,9 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, goto error_sub; } - if (place->flags & TTM_PL_FLAG_CONTIGUOUS) { + if (place->flags & TTM_PL_FLAG_CONTIGUOUS) pages_per_node = ~0ul; - num_nodes = 1; - } else { + else { #ifdef CONFIG_TRANSPARENT_HUGEPAGE pages_per_node = HPAGE_PMD_NR; #else @@ -391,11 +380,10 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, #endif pages_per_node = max_t(uint32_t, pages_per_node, tbo->page_alignment); - num_nodes = DIV_ROUND_UP_ULL(PFN_UP(mem_bytes), pages_per_node); } - node = kvmalloc(struct_size(node, mm_nodes, num_nodes), - GFP_KERNEL | __GFP_ZERO); + node = kzalloc(sizeof(*node), GFP_KERNEL); + if (!node) { r = -ENOMEM; goto error_sub; @@ -403,9 +391,17 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, ttm_resource_init(tbo, place, &node->base); - mode = DRM_MM_INSERT_BEST; + INIT_LIST_HEAD(&node->blocks); + if (place->flags & TTM_PL_FLAG_TOPDOWN) - mode = DRM_MM_INSERT_HIGH; + node->flags |= DRM_BUDDY_TOPDOWN_ALLOCATION; + + if (place->fpfn || lpfn != man->size) + /* Allocate blocks in desired range */ + node->flags |= DRM_BUDDY_RANGE_ALLOCATION; + + min_page_size = mgr->default_page_size; + BUG_ON(min_page_size < mm->chunk_size); pages_left = node->base.num_pages; @@ -413,36 +409,63 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, pages = min(pages_left, 2UL << (30 - PAGE_SHIFT)); i = 0; - spin_lock(&mgr->lock); while (pages_left) { - uint32_t alignment = tbo->page_alignment; - if (pages >= pages_per_node) - alignment = pages_per_node; - - r = drm_mm_insert_node_in_range(mm, &node->mm_nodes[i], pages, - alignment, 0, place->fpfn, - lpfn, mode); - if (unlikely(r)) { - if (pages > pages_per_node) { - if (is_power_of_2(pages)) - pages = pages / 2; - else - pages = rounddown_pow_of_two(pages); - continue; - } - goto error_free; + pages = pages_per_node; + + n_pages = pages; + + if (place->flags & TTM_PL_FLAG_CONTIGUOUS) { + n_pages = roundup_pow_of_two(n_pages); + min_page_size = (uint64_t)n_pages << PAGE_SHIFT; + + if (n_pages > lpfn) + lpfn = n_pages; } - vis_usage += amdgpu_vram_mgr_vis_size(adev, &node->mm_nodes[i]); - amdgpu_vram_mgr_virt_start(&node->base, &node->mm_nodes[i]); + spin_lock(&mgr->lock); + r = drm_buddy_alloc(mm, (uint64_t)place->fpfn << PAGE_SHIFT, + (uint64_t)lpfn << PAGE_SHIFT, + (uint64_t)n_pages << PAGE_SHIFT, + min_page_size, &node->blocks, + node->flags); + spin_unlock(&mgr->lock); + + if (unlikely(r)) + goto error_free_blocks; + pages_left -= pages; ++i; if (pages > pages_left) pages = pages_left; } - spin_unlock(&mgr->lock); + + /* Free unused pages for contiguous allocation */ + if (place->flags & TTM_PL_FLAG_CONTIGUOUS) { + uint64_t actual_size = (uint64_t)node->base.num_pages << PAGE_SHIFT; + + r = drm_buddy_free_unused_pages(mm, + actual_size, + &node->blocks); + + if (unlikely(r)) + goto error_free_blocks; + } + + list_for_each_entry(block, &node->blocks, link) + vis_usage += amdgpu_vram_mgr_vis_size(adev, block); + + block = list_first_entry_or_null(&node->blocks, + struct drm_buddy_block, + link); + + if (!block) { + r = -ENOSPC; + goto error_free_res; + } + + node->base.start = node_start(block) >> PAGE_SHIFT; if (i == 1) node->base.placement |= TTM_PL_FLAG_CONTIGUOUS; @@ -456,12 +479,12 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, *res = &node->base; return 0; -error_free: - while (i--) - drm_mm_remove_node(&node->mm_nodes[i]); +error_free_blocks: + spin_lock(&mgr->lock); + drm_buddy_free_list(mm, &node->blocks); spin_unlock(&mgr->lock); - kvfree(node); - +error_free_res: + kfree(node); error_sub: atomic64_sub(mem_bytes, &mgr->usage); return r; @@ -478,28 +501,28 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, static void amdgpu_vram_mgr_del(struct ttm_resource_manager *man, struct ttm_resource *res) { - struct ttm_range_mgr_node *node = to_ttm_range_mgr_node(res); + struct amdgpu_vram_mgr_node *node = to_amdgpu_vram_mgr_node(res); struct amdgpu_vram_mgr *mgr = to_vram_mgr(man); struct amdgpu_device *adev = to_amdgpu_device(mgr); + struct drm_buddy_mm *mm = &mgr->mm; + struct drm_buddy_block *block; uint64_t usage = 0, vis_usage = 0; - unsigned i, pages; spin_lock(&mgr->lock); - for (i = 0, pages = res->num_pages; pages; - pages -= node->mm_nodes[i].size, ++i) { - struct drm_mm_node *mm = &node->mm_nodes[i]; - - drm_mm_remove_node(mm); - usage += mm->size << PAGE_SHIFT; - vis_usage += amdgpu_vram_mgr_vis_size(adev, mm); + list_for_each_entry(block, &node->blocks, link) { + usage += node_size(block); + vis_usage += amdgpu_vram_mgr_vis_size(adev, block); } + amdgpu_vram_mgr_do_reserve(man); + + drm_buddy_free_list(mm, &node->blocks); spin_unlock(&mgr->lock); atomic64_sub(usage, &mgr->usage); atomic64_sub(vis_usage, &mgr->vis_usage); - kvfree(node); + kfree(node); } /** @@ -653,9 +676,18 @@ static void amdgpu_vram_mgr_debug(struct ttm_resource_manager *man, struct drm_printer *printer) { struct amdgpu_vram_mgr *mgr = to_vram_mgr(man); + struct drm_buddy_mm *mm = &mgr->mm; + struct drm_buddy_block *block; spin_lock(&mgr->lock); - drm_mm_print(&mgr->mm, printer); + drm_printf(printer, "default_page_size: %lluKiB\n", + mgr->default_page_size >> 10); + + drm_buddy_print(mm, printer); + + drm_printf(printer, "reserved:\n"); + list_for_each_entry(block, &mgr->reserved_pages, link) + drm_buddy_block_print(mm, block, printer); spin_unlock(&mgr->lock); drm_printf(printer, "man size:%llu pages, ram usage:%lluMB, vis usage:%lluMB\n", @@ -680,15 +712,20 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev) { struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr; struct ttm_resource_manager *man = &mgr->manager; + int err; ttm_resource_manager_init(man, adev->gmc.real_vram_size >> PAGE_SHIFT); man->func = &amdgpu_vram_mgr_func; - drm_mm_init(&mgr->mm, 0, man->size); + err = drm_buddy_init(&mgr->mm, man->size << PAGE_SHIFT, PAGE_SIZE); + if (err) + return err; + spin_lock_init(&mgr->lock); INIT_LIST_HEAD(&mgr->reservations_pending); INIT_LIST_HEAD(&mgr->reserved_pages); + mgr->default_page_size = PAGE_SIZE; ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager); ttm_resource_manager_set_used(man, true); @@ -721,10 +758,10 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev) kfree(rsv); list_for_each_entry_safe(rsv, temp, &mgr->reserved_pages, node) { - drm_mm_remove_node(&rsv->mm_node); + drm_buddy_free_list(&mgr->mm, &rsv->block); kfree(rsv); } - drm_mm_takedown(&mgr->mm); + drm_buddy_fini(&mgr->mm); spin_unlock(&mgr->lock); ttm_resource_manager_cleanup(man);