From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 21D9EC54FDF for ; Thu, 30 Jul 2026 10:12:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B502510EE74; Thu, 30 Jul 2026 10:12:00 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="CdqHMblv"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id A113510EE6D; Thu, 30 Jul 2026 10:11:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1785406318; x=1816942318; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w1b7MPyQwYUv0BfP8b+DcSsNdYvPfcNImRvtNECFHbE=; b=CdqHMblvAUnkrs/egwTXWWdA1gBcTBTKyh2aJbW8zH8uDTZesowjWGWy 93cro9LZ5AO0OfWL1uyDBbWKD9mFnuA2AW2EL0HbkqmH4ykzadoSCAl6S Ifmnh64H0fWZqcyjyWSA6wedRPP+slUJG8HkH0cJ5runjGRf9LsybjqiV QBPJM5WPo9Lda1wcIigNDE7ottWnbqTYvsufx4rvil9SCnJCEzDm8P4I8 DKLYqiUgNV9J7m5DcS6VAwMzvEwGnKTgXuL+C9UeDxFbjq4B4xsoyP0tX bGvOJkjgjGcf34iAyqXpjBVawqjv6UB6KjdCiVId8PnFlM79fsp7M16zr g==; X-CSE-ConnectionGUID: WJSrImD0Swat5L/LLGGZ2Q== X-CSE-MsgGUID: adGxcfulSD6R4CImrLoFvw== X-IronPort-AV: E=McAfee;i="6800,10657,11859"; a="73557228" X-IronPort-AV: E=Sophos;i="6.25,194,1779174000"; d="scan'208";a="73557228" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2026 03:11:58 -0700 X-CSE-ConnectionGUID: kBW+CNrkQHegHgFwpyMTsw== X-CSE-MsgGUID: eEB779vZRwuNAeJjsSibKw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,194,1779174000"; d="scan'208";a="256925247" Received: from tejasupa-desk.iind.intel.com (HELO tejasupa-desk) ([10.190.239.37]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2026 03:11:55 -0700 From: Tejas Upadhyay To: intel-xe@lists.freedesktop.org Cc: himal.prasad.ghimiray@intel.com, Tejas Upadhyay , Arunpravin Paneer Selvam , dri-devel@lists.freedesktop.org, Arunpravin Paneer Selvam Subject: [PATCH V14 2/9] [DO NOT MERGE]drm/gpu: Add gpu_buddy_allocated_addr_to_block helper Date: Thu, 30 Jul 2026 15:41:24 +0530 Message-ID: <20260730101132.2770752-13-tejas.upadhyay@intel.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260730101132.2770752-11-tejas.upadhyay@intel.com> References: <20260730101132.2770752-11-tejas.upadhyay@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" Add helper with primary purpose is to efficiently trace a specific physical memory address back to its corresponding TTM buffer object. v3: - use mm->chunk_size minimum allocation granularity (Arun) v2: - %s/gpu_buddy_addr_to_block/gpu_buddy_allocated_addr_to_block(MattA) - remove clear->avail and split nodes check(MattA) - Adapt lockdep(MattB) Signed-off-by: Tejas Upadhyay Cc: Arunpravin Paneer Selvam Cc: dri-devel@lists.freedesktop.org Reviewed-by: Arunpravin Paneer Selvam --- drivers/gpu/buddy.c | 53 +++++++++++++++++++++++++++++++++++++++ include/linux/gpu_buddy.h | 2 ++ 2 files changed, 55 insertions(+) diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c index dc81fe0301ce..4d5ac375a538 100644 --- a/drivers/gpu/buddy.c +++ b/drivers/gpu/buddy.c @@ -630,6 +630,59 @@ void gpu_buddy_free_block(struct gpu_buddy *mm, } EXPORT_SYMBOL(gpu_buddy_free_block); +/** + * gpu_buddy_allocated_addr_to_block - given relative address find the allocated block + * + * @mm: GPU buddy manager + * @addr: Relative address + * + * Returns: + * gpu_buddy_block on success, NULL or error code on failure + */ +struct gpu_buddy_block *gpu_buddy_allocated_addr_to_block(struct gpu_buddy *mm, u64 addr) +{ + struct gpu_buddy_block *block; + LIST_HEAD(dfs); + u64 end; + int i; + + gpu_buddy_driver_lock_held(mm); + + end = addr + mm->chunk_size - 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 gpu_buddy_block, + tmp_link); + if (!block) + break; + + list_del(&block->tmp_link); + + block_start = gpu_buddy_block_offset(block); + block_end = block_start + gpu_buddy_block_size(mm, block) - 1; + + if (!overlaps(addr, end, block_start, block_end)) + continue; + + if (gpu_buddy_block_is_allocated(block)) + return block; + else if (gpu_buddy_block_is_free(block)) + return NULL; + + list_add(&block->right->tmp_link, &dfs); + list_add(&block->left->tmp_link, &dfs); + } while (1); + + return ERR_PTR(-ENXIO); +} +EXPORT_SYMBOL(gpu_buddy_allocated_addr_to_block); + static void __gpu_buddy_free_list(struct gpu_buddy *mm, struct list_head *objects, bool mark_clear, diff --git a/include/linux/gpu_buddy.h b/include/linux/gpu_buddy.h index e037714563d8..2c36124bb696 100644 --- a/include/linux/gpu_buddy.h +++ b/include/linux/gpu_buddy.h @@ -287,6 +287,8 @@ void gpu_buddy_reset_clear(struct gpu_buddy *mm, bool is_clear); void gpu_buddy_free_block(struct gpu_buddy *mm, struct gpu_buddy_block *block); +struct gpu_buddy_block *gpu_buddy_allocated_addr_to_block(struct gpu_buddy *mm, u64 addr); + void gpu_buddy_free_list(struct gpu_buddy *mm, struct list_head *objects, unsigned int flags); -- 2.52.0