diff mbox series

[2/2] cacheinfo: pass of_node to cpu_device_create()

Message ID 20231231-cpu-cacheinfo-of-v1-2-cd3584d2c7b4@linaro.org
State New
Headers show
Series ARM: implement cacheinfo support (for v7/v7m) | expand

Commit Message

Dmitry Baryshkov Dec. 31, 2023, 5:30 p.m. UTC
Pass the DT node correponsing to caches to the cpu_device_create() in
order to let platform-specific cache drivers to bind to the
corresponding cache devices. For example, on Qualcomm Krait platforms
the L2 cache frequency should be scaled following the CPU frequencies.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/base/cacheinfo.c  | 12 +++++++++++-
 include/linux/cacheinfo.h |  2 ++
 2 files changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
index a72c69e70fa3..63bc94cf2c59 100644
--- a/drivers/base/cacheinfo.c
+++ b/drivers/base/cacheinfo.c
@@ -230,6 +230,7 @@  static int cache_setup_of_node(unsigned int cpu)
 		}
 		cache_of_set_props(this_leaf, np);
 		this_leaf->fw_token = np;
+		this_leaf->of_node = of_node_get(np);
 		index++;
 	}
 
@@ -457,10 +458,19 @@  static void cache_shared_cpu_map_remove(unsigned int cpu)
 
 static void free_cache_attributes(unsigned int cpu)
 {
+	struct cacheinfo *this_leaf;
+	unsigned int index;
+
 	if (!per_cpu_cacheinfo(cpu))
 		return;
 
 	cache_shared_cpu_map_remove(cpu);
+
+	for (index = 0; index < cache_leaves(cpu); index++) {
+		this_leaf = per_cpu_cacheinfo_idx(cpu, index);
+		of_node_put(this_leaf->of_node);
+		this_leaf->of_node = NULL;
+	}
 }
 
 int __weak early_cache_level(unsigned int cpu)
@@ -883,7 +893,7 @@  static int cache_add_dev(unsigned int cpu)
 			break;
 		cache_groups = cache_get_attribute_groups(this_leaf);
 		ci_dev = cpu_device_create(parent, this_leaf,
-					   NULL,
+					   this_leaf->of_node,
 					   cache_groups,
 					   "index%1u", i);
 		if (IS_ERR(ci_dev)) {
diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h
index d504eb4b49ab..543d1410e56a 100644
--- a/include/linux/cacheinfo.h
+++ b/include/linux/cacheinfo.h
@@ -38,6 +38,7 @@  extern unsigned int coherency_max_size;
  * @attributes: bitfield representing various cache attributes
  * @fw_token: Unique value used to determine if different cacheinfo
  *	structures represent a single hardware cache instance.
+ * @of_node: Corresponding DT node
  * @disable_sysfs: indicates whether this node is visible to the user via
  *	sysfs or not
  * @priv: pointer to any private data structure specific to particular
@@ -67,6 +68,7 @@  struct cacheinfo {
 	(CACHE_READ_ALLOCATE | CACHE_WRITE_ALLOCATE)
 #define CACHE_ID		BIT(4)
 	void *fw_token;
+	struct device_node *of_node;
 	bool disable_sysfs;
 	void *priv;
 };