From nobody Tue Oct 7 08:53:17 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68E50199FAB for ; Fri, 11 Jul 2025 18:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752259038; cv=none; b=mt4lksCATr65DLbQszuuhJ5mvFuGD9ySYDSFce5/FQOCD1Wr7pqEQgtnasyvFLEH2L++9xaaMQetYbK4tMMaTNdkd/IdmSroqY8tjpl2D3Gq04uhLoH+g4bV+0YyZQycloktajVxBEUVSr6erkhG0G3+yeMZdBEKhlrZ0ASK4iM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752259038; c=relaxed/simple; bh=q18nYXAm4vunGVzbFsAjhYiP6o38u7Kc4hIJmurnU2A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MD/+B8ccd0lPJeFAGpecSzcJss/oH/3Nep5jUg2DNmfzZigS9YrxuW/vXYHqNUFeZthl5x+yZP9Yr/Z8/Do6Hz/bayYUyFpklttrOvL26MXqU/HqIhzIA3sVQY3KgH71fAVaf7Yv/hc9I1l3LsZZbQ+sX0AOVsaTTKUq1YbqXpI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4ACDA16F8; Fri, 11 Jul 2025 11:37:06 -0700 (PDT) Received: from merodach.members.linode.com (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D57183F694; Fri, 11 Jul 2025 11:37:13 -0700 (PDT) From: James Morse To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Rob Herring , Ben Horgan , Rohit Mathew , Shanker Donthineni , Zeng Heng , Lecopzer Chen , Carl Worth , shameerali.kolothum.thodi@huawei.com, D Scott Phillips OS , lcherian@marvell.com, bobo.shaobowang@huawei.com, tan.shaopeng@fujitsu.com, baolin.wang@linux.alibaba.com, Jamie Iles , Xin Hao , peternewman@google.com, dfustini@baylibre.com, amitsinght@marvell.com, David Hildenbrand , Rex Nie , Dave Martin , Koba Ko , James Morse Subject: [RFC PATCH 04/36] cacheinfo: Expose the code to generate a cache-id from a device_node Date: Fri, 11 Jul 2025 18:36:16 +0000 Message-Id: <20250711183648.30766-5-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20250711183648.30766-1-james.morse@arm.com> References: <20250711183648.30766-1-james.morse@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The MPAM driver identifies caches by id for use with resctrl. It needs to know the cache-id when probe-ing, but the value isn't set in cacheinfo until device_initcall(). Expose the code that generates the cache-id. The parts of the MPAM driver that run early can use this to set up the resctrl structures before cacheinfo is ready in device_initcall(). Signed-off-by: James Morse --- Changes since v1: * Renamed cache_of_get_id() cache_of_calculate_id(). --- drivers/base/cacheinfo.c | 17 ++++++++++++----- include/linux/cacheinfo.h | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index 613410705a47..0fdd6358ee73 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -207,8 +207,7 @@ static bool match_cache_node(struct device_node *cpu, #define arch_compact_of_hwid(_x) (_x) #endif =20 -static void cache_of_set_id(struct cacheinfo *this_leaf, - struct device_node *cache_node) +unsigned long cache_of_calculate_id(struct device_node *cache_node) { struct device_node *cpu; u32 min_id =3D ~0; @@ -219,15 +218,23 @@ static void cache_of_set_id(struct cacheinfo *this_le= af, id =3D arch_compact_of_hwid(id); if (FIELD_GET(GENMASK_ULL(63, 32), id)) { of_node_put(cpu); - return; + return ~0UL; } =20 if (match_cache_node(cpu, cache_node)) min_id =3D min(min_id, id); } =20 - if (min_id !=3D ~0) { - this_leaf->id =3D min_id; + return min_id; +} + +static void cache_of_set_id(struct cacheinfo *this_leaf, + struct device_node *cache_node) +{ + unsigned long id =3D cache_of_calculate_id(cache_node); + + if (id !=3D ~0UL) { + this_leaf->id =3D id; this_leaf->attributes |=3D CACHE_ID; } } diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index c8f4f0a0b874..2dcbb69139e9 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -112,6 +112,7 @@ int acpi_get_cache_info(unsigned int cpu, #endif =20 const struct attribute_group *cache_get_priv_group(struct cacheinfo *this_= leaf); +unsigned long cache_of_calculate_id(struct device_node *np); =20 /* * Get the cacheinfo structure for the cache associated with @cpu at --=20 2.39.5