Skip to contentSkip to conversation

Add SiFive Private L2 cache and PMU driver

PATCH Superseded Eric Lin 7 participants 32 messages Jun 16, 2023 – Jul 20, 2023

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Eric Lin

author
#0 lore raw

cover Add SiFive Private L2 cache and PMU driver

This patch series adds the SiFive Private L2 cache controller driver and Performance Monitoring Unit (PMU) driver.

The Private L2 cache communicates with both the upstream L1 caches and downstream L3 cache or memory, enabling a high- performance cache subsystem. It is also responsible for managing requests from the L1 instruction and data caches of the core.

The Private L2 Performance Monitoring Unit (PMU) consists of a set of event-programmable counters and their event selector registers. The registers are available to control the behavior of the counters.

Eric Lin (2):
soc: sifive: Add SiFive private L2 cache support
dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

Greentime Hu (1):
soc: sifive: Add SiFive private L2 cache PMU driver

 .../bindings/riscv/sifive,pL2Cache0.yaml      |  81 +++
 drivers/soc/sifive/Kconfig                    |  17 +
 drivers/soc/sifive/Makefile                   |   2 +
 drivers/soc/sifive/sifive_pl2.h               |  45 ++
 drivers/soc/sifive/sifive_pl2_cache.c         | 218 ++++++
 drivers/soc/sifive/sifive_pl2_pmu.c           | 669 ++++++++++++++++++
 include/linux/cpuhotplug.h                    |   2 +
 7 files changed, 1034 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml
 create mode 100644 drivers/soc/sifive/sifive_pl2.h
 create mode 100644 drivers/soc/sifive/sifive_pl2_cache.c
 create mode 100644 drivers/soc/sifive/sifive_pl2_pmu.c
Signature · 1 line
2.40.1
author
#1 lore raw

PATCH 1/3 soc: sifive: Add SiFive private L2 cache support

This adds SiFive private L2 cache driver which will show cache config information when booting and add cpu hotplug callback functions.

---
 drivers/soc/sifive/Kconfig            |   8 +
 drivers/soc/sifive/Makefile           |   1 +
 drivers/soc/sifive/sifive_pl2.h       |  25 ++++
 drivers/soc/sifive/sifive_pl2_cache.c | 202 ++++++++++++++++++++++++++
 include/linux/cpuhotplug.h            |   1 +
 5 files changed, 237 insertions(+)
 create mode 100644 drivers/soc/sifive/sifive_pl2.h
 create mode 100644 drivers/soc/sifive/sifive_pl2_cache.c
drivers/soc/sifive/Kconfig +8 -0
index e86870be34c9..573564295058 100644
@@ -7,4 +7,12 @@ config SIFIVE_CCACHE
 	help
 	  Support for the composable cache controller on SiFive platforms.
 
+config SIFIVE_PL2
+	bool "Sifive private L2 Cache controller"
+	help
+	  Support for the private L2 cache controller on SiFive platforms.
+	  The SiFive Private L2 Cache Controller is per hart and communicates
+	  with both the upstream L1 caches and downstream L3 cache or memory,
+	  enabling a high-performance cache subsystem.
+
 endif
drivers/soc/sifive/Makefile +1 -0
index 1f5dc339bf82..707493e1c691 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_SIFIVE_CCACHE)	+= sifive_ccache.o
+obj-$(CONFIG_SIFIVE_PL2)	+= sifive_pl2_cache.o
drivers/soc/sifive/sifive_pl2.h new file +25 -0
new file mode 100644
index 000000000000..57aa1019d5ed
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 SiFive, Inc.
+ *
+ */
+
+#ifndef _SIFIVE_PL2_H
+#define _SIFIVE_PL2_H
+
+#define SIFIVE_PL2_CONFIG1_OFFSET	0x1000
+#define SIFIVE_PL2_CONFIG0_OFFSET	0x1008
+#define SIFIVE_PL2_PMCLIENT_OFFSET	0x2800
+
+struct sifive_pl2_state {
+	void __iomem *pl2_base;
+	u32 config1;
+	u32 config0;
+	u64 pmclientfilter;
+};
+
+int sifive_pl2_pmu_init(void);
+int sifive_pl2_pmu_probe(struct device_node *pl2_node,
+			 void __iomem *pl2_base, int cpu);
+
+#endif /*_SIFIVE_PL2_H */
drivers/soc/sifive/sifive_pl2_cache.c new file +202 -0

202 lines not on this page · raw message

include/linux/cpuhotplug.h +1 -0
index 0f1001dca0e0..35cd5ba0030b 100644
@@ -207,6 +207,7 @@ enum cpuhp_state {
 	CPUHP_AP_IRQ_AFFINITY_ONLINE,
 	CPUHP_AP_BLK_MQ_ONLINE,
 	CPUHP_AP_ARM_MVEBU_SYNC_CLOCKS,
+	CPUHP_AP_RISCV_SIFIVE_PL2_ONLINE,
 	CPUHP_AP_X86_INTEL_EPB_ONLINE,
 	CPUHP_AP_PERF_ONLINE,
 	CPUHP_AP_PERF_X86_ONLINE,
Signature · 1 line
2.40.1
#2 lore raw

Re: [PATCH 1/3] soc: sifive: Add SiFive private L2 cache support

Quoted 95 lines · Eric Lin

This adds SiFive private L2 cache driver which will show cache config information when booting and add cpu hotplug callback functions.

---
  drivers/soc/sifive/Kconfig            |   8 +
  drivers/soc/sifive/Makefile           |   1 +
  drivers/soc/sifive/sifive_pl2.h       |  25 ++++
  drivers/soc/sifive/sifive_pl2_cache.c | 202 ++++++++++++++++++++++++++
  include/linux/cpuhotplug.h            |   1 +
  5 files changed, 237 insertions(+)

create mode 100644 drivers/soc/sifive/sifive_pl2.h create mode 100644 drivers/soc/sifive/sifive_pl2_cache.c

drivers/soc/sifive/Kconfig +8 -0
index e86870be34c9..573564295058 100644
@@ -7,4 +7,12 @@ config SIFIVE_CCACHE
  	help
  	  Support for the composable cache controller on SiFive platforms.
 
+config SIFIVE_PL2
+	bool "Sifive private L2 Cache controller"
+	help
+	  Support for the private L2 cache controller on SiFive platforms.
+	  The SiFive Private L2 Cache Controller is per hart and communicates
+	  with both the upstream L1 caches and downstream L3 cache or memory,
+	  enabling a high-performance cache subsystem.
+
  endif
drivers/soc/sifive/Makefile +1 -0
index 1f5dc339bf82..707493e1c691 100644
@@ -1,3 +1,4 @@
  # SPDX-License-Identifier: GPL-2.0
 
  obj-$(CONFIG_SIFIVE_CCACHE)	+= sifive_ccache.o
+obj-$(CONFIG_SIFIVE_PL2)	+= sifive_pl2_cache.o
drivers/soc/sifive/sifive_pl2.h new file +25 -0
new file mode 100644
index 000000000000..57aa1019d5ed
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 SiFive, Inc.
+ *
+ */
+
+#ifndef _SIFIVE_PL2_H
+#define _SIFIVE_PL2_H
+
+#define SIFIVE_PL2_CONFIG1_OFFSET	0x1000
+#define SIFIVE_PL2_CONFIG0_OFFSET	0x1008
+#define SIFIVE_PL2_PMCLIENT_OFFSET	0x2800
+
+struct sifive_pl2_state {
+	void __iomem *pl2_base;
+	u32 config1;
+	u32 config0;
+	u64 pmclientfilter;
+};
+
+int sifive_pl2_pmu_init(void);
+int sifive_pl2_pmu_probe(struct device_node *pl2_node,
+			 void __iomem *pl2_base, int cpu);
+
+#endif /*_SIFIVE_PL2_H */
drivers/soc/sifive/sifive_pl2_cache.c new file +15 -0
new file mode 100644
index 000000000000..aeb51d576af9
@@ -0,0 +1,202 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SiFive private L2 cache controller Driver
+ *
+ * Copyright (C) 2018-2023 SiFive, Inc.
+ */
+
+#define pr_fmt(fmt) "pL2CACHE: " fmt
+
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+#include <linux/cpu_pm.h>
+#include <linux/cpuhotplug.h>

drivers/soc/sifive/sifive_pl2_cache.c line 25

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +10 -0
+#include "sifive_pl2.h"
+
+static DEFINE_PER_CPU(struct sifive_pl2_state, sifive_pl2_state);
+
+static void sifive_pl2_state_save(struct sifive_pl2_state *pl2_state)
+{
+	void __iomem *pl2_base = pl2_state->pl2_base;
+
+	if (!pl2_base)
+		return;

is this test realy needed?

Quoted 71 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +71 -0
+
+	pl2_state->config1 = readl(pl2_base + SIFIVE_PL2_CONFIG1_OFFSET);
+	pl2_state->config0 = readl(pl2_base + SIFIVE_PL2_CONFIG0_OFFSET);
+	pl2_state->pmclientfilter = readq(pl2_base + SIFIVE_PL2_PMCLIENT_OFFSET);
+}
+
+static void sifive_pl2_state_restore(struct sifive_pl2_state *pl2_state)
+{
+	void __iomem *pl2_base = pl2_state->pl2_base;
+
+	if (!pl2_base)
+		return;
+
+	writel(pl2_state->config1, pl2_base + SIFIVE_PL2_CONFIG1_OFFSET);
+	writel(pl2_state->config0, pl2_base + SIFIVE_PL2_CONFIG0_OFFSET);
+	writeq(pl2_state->pmclientfilter, pl2_base + SIFIVE_PL2_PMCLIENT_OFFSET);
+}
+
+/*
+ * CPU Hotplug call back function
+ */
+static int sifive_pl2_online_cpu(unsigned int cpu)
+{
+	struct sifive_pl2_state *pl2_state = this_cpu_ptr(&sifive_pl2_state);
+
+	sifive_pl2_state_restore(pl2_state);
+
+	return 0;
+}
+
+static int sifive_pl2_offline_cpu(unsigned int cpu)
+{
+	struct sifive_pl2_state *pl2_state = this_cpu_ptr(&sifive_pl2_state);
+
+	/* Save the pl2 state */
+	sifive_pl2_state_save(pl2_state);
+
+	return 0;
+}
+
+/*
+ *  PM notifer for suspend to ram
+ */
+#ifdef CONFIG_CPU_PM
+static int sifive_pl2_pm_notify(struct notifier_block *b, unsigned long cmd,
+				void *v)
+{
+	struct sifive_pl2_state *pl2_state = this_cpu_ptr(&sifive_pl2_state);
+
+	switch (cmd) {
+	case CPU_PM_ENTER:
+		/* Save the pl2 state */
+		sifive_pl2_state_save(pl2_state);
+		break;
+	case CPU_PM_ENTER_FAILED:
+	case CPU_PM_EXIT:
+		sifive_pl2_state_restore(pl2_state);
+		break;
+	default:
+		break;
+	}
+
+	return NOTIFY_OK;
+}
+
+static struct notifier_block sifive_pl2_pm_notifier_block = {
+	.notifier_call = sifive_pl2_pm_notify,
+};
+
+static inline void sifive_pl2_pm_init(void)
+{

drivers/soc/sifive/sifive_pl2_cache.c line 106

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +10 -0
+	cpu_pm_register_notifier(&sifive_pl2_pm_notifier_block);
+}
+
+#else
+static inline void sifive_pl2_pm_init(void) { }
+#endif /* CONFIG_CPU_PM */
+
+static const struct of_device_id sifive_pl2_cache_of_ids[] = {
+	{ .compatible = "sifive,pL2Cache0" },
+	{ .compatible = "sifive,pL2Cache1" },

why the single cap here? I think that looks ugly.

Quoted 8 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +8 -0
+	{ /* sentinel value */ }
+};
+
+static void pl2_config_read(void __iomem *pl2_base, int cpu)
+{
+	u32 regval, bank, way, set, cacheline;
+
+	regval = readl(pl2_base);

drivers/soc/sifive/sifive_pl2_cache.c line 124

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +10 -0
+	bank = regval & 0xff;
+	pr_info("in the CPU: %d\n", cpu);
+	pr_info("No. of Banks in the cache: %d\n", bank);
+	way = (regval & 0xff00) >> 8;
+	pr_info("No. of ways per bank: %d\n", way);
+	set = (regval & 0xff0000) >> 16;
+	pr_info("Total sets: %llu\n", (uint64_t)1 << set);
+	cacheline = (regval & 0xff000000) >> 24;
+	pr_info("Bytes per cache block: %llu\n", (uint64_t)1 << cacheline);
+	pr_info("Size: %d\n", way << (set + cacheline));

please either remove this or make it a single line, this is just going to spam the log with any system with more than one cpu core.

Quoted 90 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +78 -0
+}
+
+static int sifive_pl2_cache_dev_probe(struct platform_device *pdev)
+{
+	struct resource *res;
+	int cpu, ret = -EINVAL;
+	struct device_node *cpu_node, *pl2_node;
+	struct sifive_pl2_state *pl2_state = NULL;
+	void __iomem *pl2_base;
+
+	/* Traverse all cpu nodes to find the one mapping to its pl2 node. */
+	for_each_cpu(cpu, cpu_possible_mask) {
+		cpu_node = of_cpu_device_node_get(cpu);
+		pl2_node = of_parse_phandle(cpu_node, "next-level-cache", 0);
+
+		/* Found it! */
+		if (dev_of_node(&pdev->dev) == pl2_node) {
+			/* Use cpu to get its percpu data sifive_pl2_state. */
+			pl2_state = per_cpu_ptr(&sifive_pl2_state, cpu);
+			break;
+		}
+	}
+
+	if (!pl2_state) {
+		pr_err("Not found the corresponding cpu_node in dts.\n");
+		goto early_err;
+	}
+
+	/* Set base address of select and counter registers. */
+	pl2_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+	if (IS_ERR(pl2_base)) {
+		ret = PTR_ERR(pl2_base);
+		goto early_err;
+	}
+
+	/* Print pL2 configs. */
+	pl2_config_read(pl2_base, cpu);
+	pl2_state->pl2_base = pl2_base;
+
+	return 0;
+
+early_err:
+	return ret;
+}
+
+static struct platform_driver sifive_pl2_cache_driver = {
+	.driver = {
+		   .name = "SiFive-pL2-cache",
+		   .of_match_table = sifive_pl2_cache_of_ids,
+		   },
+	.probe = sifive_pl2_cache_dev_probe,
+};
+
+static int __init sifive_pl2_cache_init(void)
+{
+	int ret;
+
+	ret = cpuhp_setup_state(CPUHP_AP_RISCV_SIFIVE_PL2_ONLINE,
+				"soc/sifive/pl2:online",
+				      sifive_pl2_online_cpu,
+				      sifive_pl2_offline_cpu);
+	if (ret < 0) {
+		pr_err("Failed to register CPU hotplug notifier %d\n", ret);
+		return ret;
+	}
+
+	ret = platform_driver_register(&sifive_pl2_cache_driver);
+	if (ret) {
+		pr_err("Failed to register sifive_pl2_cache_driver: %d\n", ret);
+		return ret;
+	}
+
+	sifive_pl2_pm_init();
+
+	return ret;
+}
+
+device_initcall(sifive_pl2_cache_init);
include/linux/cpuhotplug.h +1 -0
index 0f1001dca0e0..35cd5ba0030b 100644
@@ -207,6 +207,7 @@ enum cpuhp_state {
  	CPUHP_AP_IRQ_AFFINITY_ONLINE,
  	CPUHP_AP_BLK_MQ_ONLINE,
  	CPUHP_AP_ARM_MVEBU_SYNC_CLOCKS,
+	CPUHP_AP_RISCV_SIFIVE_PL2_ONLINE,
  	CPUHP_AP_X86_INTEL_EPB_ONLINE,
  	CPUHP_AP_PERF_ONLINE,
  	CPUHP_AP_PERF_X86_ONLINE,
Signature · 10 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
author
#3 lore raw

Re: [PATCH 1/3] soc: sifive: Add SiFive private L2 cache support

Hi Ben,

Quoted 101 lines · Ben Dooks
Quoted 99 lines · Eric Lin

This adds SiFive private L2 cache driver which will show cache config information when booting and add cpu hotplug callback functions.

---
  drivers/soc/sifive/Kconfig            |   8 +
  drivers/soc/sifive/Makefile           |   1 +
  drivers/soc/sifive/sifive_pl2.h       |  25 ++++
  drivers/soc/sifive/sifive_pl2_cache.c | 202 ++++++++++++++++++++++++++
  include/linux/cpuhotplug.h            |   1 +
  5 files changed, 237 insertions(+)

create mode 100644 drivers/soc/sifive/sifive_pl2.h create mode 100644 drivers/soc/sifive/sifive_pl2_cache.c

drivers/soc/sifive/Kconfig +8 -0
index e86870be34c9..573564295058 100644
@@ -7,4 +7,12 @@ config SIFIVE_CCACHE
      help
        Support for the composable cache controller on SiFive platforms.
 
+config SIFIVE_PL2
+     bool "Sifive private L2 Cache controller"
+     help
+       Support for the private L2 cache controller on SiFive platforms.
+       The SiFive Private L2 Cache Controller is per hart and communicates
+       with both the upstream L1 caches and downstream L3 cache or memory,
+       enabling a high-performance cache subsystem.
+
  endif
drivers/soc/sifive/Makefile +1 -0
index 1f5dc339bf82..707493e1c691 100644
@@ -1,3 +1,4 @@
  # SPDX-License-Identifier: GPL-2.0
 
  obj-$(CONFIG_SIFIVE_CCACHE) += sifive_ccache.o
+obj-$(CONFIG_SIFIVE_PL2)     += sifive_pl2_cache.o
drivers/soc/sifive/sifive_pl2.h new file +25 -0
new file mode 100644
index 000000000000..57aa1019d5ed
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 SiFive, Inc.
+ *
+ */
+
+#ifndef _SIFIVE_PL2_H
+#define _SIFIVE_PL2_H
+
+#define SIFIVE_PL2_CONFIG1_OFFSET    0x1000
+#define SIFIVE_PL2_CONFIG0_OFFSET    0x1008
+#define SIFIVE_PL2_PMCLIENT_OFFSET   0x2800
+
+struct sifive_pl2_state {
+     void __iomem *pl2_base;
+     u32 config1;
+     u32 config0;
+     u64 pmclientfilter;
+};
+
+int sifive_pl2_pmu_init(void);
+int sifive_pl2_pmu_probe(struct device_node *pl2_node,
+                      void __iomem *pl2_base, int cpu);
+
+#endif /*_SIFIVE_PL2_H */
drivers/soc/sifive/sifive_pl2_cache.c new file +19 -0
new file mode 100644
index 000000000000..aeb51d576af9
@@ -0,0 +1,202 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * SiFive private L2 cache controller Driver
+ *
+ * Copyright (C) 2018-2023 SiFive, Inc.
+ */
+
+#define pr_fmt(fmt) "pL2CACHE: " fmt
+
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+#include <linux/cpu_pm.h>
+#include <linux/cpuhotplug.h>
+#include "sifive_pl2.h"
+
+static DEFINE_PER_CPU(struct sifive_pl2_state, sifive_pl2_state);
+
Quoted 9 lines

drivers/soc/sifive/sifive_pl2_cache.c line 25

Quoted 6 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +6 -0
+static void sifive_pl2_state_save(struct sifive_pl2_state *pl2_state)
+{
+     void __iomem *pl2_base = pl2_state->pl2_base;
+
+     if (!pl2_base)
+             return;

is this test realy needed?

Yes,
The function cpuhp_setup_state() is called before sifive_pl2_cache_dev_probe(). When registering the CPU hotplug state, the kernel will issue the pl2 CPU hotplug callback.
However, the pl2_base is not yet being ioremap in sifive_pl2_cache_dev_probe(). Therefore, it is necessary to check pl2_base first to avoid such a scenario.

Quoted 75 lines
Quoted 75 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +75 -0
+
+     pl2_state->config1 = readl(pl2_base + SIFIVE_PL2_CONFIG1_OFFSET);
+     pl2_state->config0 = readl(pl2_base + SIFIVE_PL2_CONFIG0_OFFSET);
+     pl2_state->pmclientfilter = readq(pl2_base + SIFIVE_PL2_PMCLIENT_OFFSET);
+}
+
+static void sifive_pl2_state_restore(struct sifive_pl2_state *pl2_state)
+{
+     void __iomem *pl2_base = pl2_state->pl2_base;
+
+     if (!pl2_base)
+             return;
+
+     writel(pl2_state->config1, pl2_base + SIFIVE_PL2_CONFIG1_OFFSET);
+     writel(pl2_state->config0, pl2_base + SIFIVE_PL2_CONFIG0_OFFSET);
+     writeq(pl2_state->pmclientfilter, pl2_base + SIFIVE_PL2_PMCLIENT_OFFSET);
+}
+
+/*
+ * CPU Hotplug call back function
+ */
+static int sifive_pl2_online_cpu(unsigned int cpu)
+{
+     struct sifive_pl2_state *pl2_state = this_cpu_ptr(&sifive_pl2_state);
+
+     sifive_pl2_state_restore(pl2_state);
+
+     return 0;
+}
+
+static int sifive_pl2_offline_cpu(unsigned int cpu)
+{
+     struct sifive_pl2_state *pl2_state = this_cpu_ptr(&sifive_pl2_state);
+
+     /* Save the pl2 state */
+     sifive_pl2_state_save(pl2_state);
+
+     return 0;
+}
+
+/*
+ *  PM notifer for suspend to ram
+ */
+#ifdef CONFIG_CPU_PM
+static int sifive_pl2_pm_notify(struct notifier_block *b, unsigned long cmd,
+                             void *v)
+{
+     struct sifive_pl2_state *pl2_state = this_cpu_ptr(&sifive_pl2_state);
+
+     switch (cmd) {
+     case CPU_PM_ENTER:
+             /* Save the pl2 state */
+             sifive_pl2_state_save(pl2_state);
+             break;
+     case CPU_PM_ENTER_FAILED:
+     case CPU_PM_EXIT:
+             sifive_pl2_state_restore(pl2_state);
+             break;
+     default:
+             break;
+     }
+
+     return NOTIFY_OK;
+}
+
+static struct notifier_block sifive_pl2_pm_notifier_block = {
+     .notifier_call = sifive_pl2_pm_notify,
+};
+
+static inline void sifive_pl2_pm_init(void)
+{
+     cpu_pm_register_notifier(&sifive_pl2_pm_notifier_block);
+}
+
+#else
Quoted 9 lines

drivers/soc/sifive/sifive_pl2_cache.c line 106

Quoted 6 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +6 -0
+static inline void sifive_pl2_pm_init(void) { }
+#endif /* CONFIG_CPU_PM */
+
+static const struct of_device_id sifive_pl2_cache_of_ids[] = {
+     { .compatible = "sifive,pL2Cache0" },
+     { .compatible = "sifive,pL2Cache1" },

why the single cap here? I think that looks ugly.

OK, I'll fix it in v2.

Quoted 14 lines
Quoted 14 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +14 -0
+     { /* sentinel value */ }
+};
+
+static void pl2_config_read(void __iomem *pl2_base, int cpu)
+{
+     u32 regval, bank, way, set, cacheline;
+
+     regval = readl(pl2_base);
+     bank = regval & 0xff;
+     pr_info("in the CPU: %d\n", cpu);
+     pr_info("No. of Banks in the cache: %d\n", bank);
+     way = (regval & 0xff00) >> 8;
+     pr_info("No. of ways per bank: %d\n", way);
+     set = (regval & 0xff0000) >> 16;
Quoted 9 lines

drivers/soc/sifive/sifive_pl2_cache.c line 124

Quoted 4 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +4 -0
+     pr_info("Total sets: %llu\n", (uint64_t)1 << set);
+     cacheline = (regval & 0xff000000) >> 24;
+     pr_info("Bytes per cache block: %llu\n", (uint64_t)1 << cacheline);
+     pr_info("Size: %d\n", way << (set + cacheline));

please either remove this or make it a single line, this is just going to spam the log with any system with more than one cpu core.

OK, I will make this log more simple in v2.
Thanks for the review.

Best Regards,
Eric Lin.

Quoted 97 lines
Quoted 83 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +78 -0
+}
+
+static int sifive_pl2_cache_dev_probe(struct platform_device *pdev)
+{
+     struct resource *res;
+     int cpu, ret = -EINVAL;
+     struct device_node *cpu_node, *pl2_node;
+     struct sifive_pl2_state *pl2_state = NULL;
+     void __iomem *pl2_base;
+
+     /* Traverse all cpu nodes to find the one mapping to its pl2 node. */
+     for_each_cpu(cpu, cpu_possible_mask) {
+             cpu_node = of_cpu_device_node_get(cpu);
+             pl2_node = of_parse_phandle(cpu_node, "next-level-cache", 0);
+
+             /* Found it! */
+             if (dev_of_node(&pdev->dev) == pl2_node) {
+                     /* Use cpu to get its percpu data sifive_pl2_state. */
+                     pl2_state = per_cpu_ptr(&sifive_pl2_state, cpu);
+                     break;
+             }
+     }
+
+     if (!pl2_state) {
+             pr_err("Not found the corresponding cpu_node in dts.\n");
+             goto early_err;
+     }
+
+     /* Set base address of select and counter registers. */
+     pl2_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+     if (IS_ERR(pl2_base)) {
+             ret = PTR_ERR(pl2_base);
+             goto early_err;
+     }
+
+     /* Print pL2 configs. */
+     pl2_config_read(pl2_base, cpu);
+     pl2_state->pl2_base = pl2_base;
+
+     return 0;
+
+early_err:
+     return ret;
+}
+
+static struct platform_driver sifive_pl2_cache_driver = {
+     .driver = {
+                .name = "SiFive-pL2-cache",
+                .of_match_table = sifive_pl2_cache_of_ids,
+                },
+     .probe = sifive_pl2_cache_dev_probe,
+};
+
+static int __init sifive_pl2_cache_init(void)
+{
+     int ret;
+
+     ret = cpuhp_setup_state(CPUHP_AP_RISCV_SIFIVE_PL2_ONLINE,
+                             "soc/sifive/pl2:online",
+                                   sifive_pl2_online_cpu,
+                                   sifive_pl2_offline_cpu);
+     if (ret < 0) {
+             pr_err("Failed to register CPU hotplug notifier %d\n", ret);
+             return ret;
+     }
+
+     ret = platform_driver_register(&sifive_pl2_cache_driver);
+     if (ret) {
+             pr_err("Failed to register sifive_pl2_cache_driver: %d\n", ret);
+             return ret;
+     }
+
+     sifive_pl2_pm_init();
+
+     return ret;
+}
+
+device_initcall(sifive_pl2_cache_init);
include/linux/cpuhotplug.h +0 -0
index 0f1001dca0e0..35cd5ba0030b 100644

include/linux/cpuhotplug.h enum cpuhp_state { · line 213

Quoted 7 lines
include/linux/cpuhotplug.h +1 -0
@@ -207,6 +207,7 @@ enum cpuhp_state {
      CPUHP_AP_IRQ_AFFINITY_ONLINE,
      CPUHP_AP_BLK_MQ_ONLINE,
      CPUHP_AP_ARM_MVEBU_SYNC_CLOCKS,
+     CPUHP_AP_RISCV_SIFIVE_PL2_ONLINE,
      CPUHP_AP_X86_INTEL_EPB_ONLINE,
      CPUHP_AP_PERF_ONLINE,
      CPUHP_AP_PERF_X86_ONLINE,

--
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html

#4 lore raw

Re: [PATCH 1/3] soc: sifive: Add SiFive private L2 cache support

In reply to Eric Lin

Le 16/06/2023 à 08:32, Eric Lin a écrit :

Quoted 7 lines

This adds SiFive private L2 cache driver which will show cache config information when booting and add cpu hotplug callback functions.

[...]

Quoted 6 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +6 -0
+static int __init sifive_pl2_cache_init(void)
+{
+	int ret;
+
+	ret = cpuhp_setup_state(CPUHP_AP_RISCV_SIFIVE_PL2_ONLINE,
+				"soc/sifive/pl2:online",

drivers/soc/sifive/sifive_pl2_cache.c line 193

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +10 -0
+				      sifive_pl2_online_cpu,
+				      sifive_pl2_offline_cpu);
+	if (ret < 0) {
+		pr_err("Failed to register CPU hotplug notifier %d\n", ret);
+		return ret;
+	}
+
+	ret = platform_driver_register(&sifive_pl2_cache_driver);
+	if (ret) {
+		pr_err("Failed to register sifive_pl2_cache_driver: %d\n", ret);

Blind guess: does cpuhp_remove_state() needs to be called?

drivers/soc/sifive/sifive_pl2_cache.c line 199

Quoted 6 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +6 -0
+		return ret;
+	}
+
+	sifive_pl2_pm_init();
+
+	return ret;

If you send a v2, return 0; would be slighly nicer here.

CJ

Quoted 1 line

+}

[...]

author
#5 lore raw

Re: [PATCH 1/3] soc: sifive: Add SiFive private L2 cache support

Hi Christophe,

Quoted 22 lines · Christophe JAILLET
Quoted 7 lines · Eric Lin

This adds SiFive private L2 cache driver which will show cache config information when booting and add cpu hotplug callback functions.

[...]

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +10 -0
+static int __init sifive_pl2_cache_init(void)
+{
+     int ret;
+
+     ret = cpuhp_setup_state(CPUHP_AP_RISCV_SIFIVE_PL2_ONLINE,
+                             "soc/sifive/pl2:online",
+                                   sifive_pl2_online_cpu,
+                                   sifive_pl2_offline_cpu);
+     if (ret < 0) {
+             pr_err("Failed to register CPU hotplug notifier %d\n", ret);
Quoted 9 lines

drivers/soc/sifive/sifive_pl2_cache.c line 193

Quoted 6 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +6 -0
+             return ret;
+     }
+
+     ret = platform_driver_register(&sifive_pl2_cache_driver);
+     if (ret) {
+             pr_err("Failed to register sifive_pl2_cache_driver: %d\n", ret);

Blind guess: does cpuhp_remove_state() needs to be called?

Yes, I'll fix this in v2. Thanks.

Quoted 9 lines

drivers/soc/sifive/sifive_pl2_cache.c line 199

Quoted 6 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +6 -0
+             return ret;
+     }
+
+     sifive_pl2_pm_init();
+
+     return ret;

If you send a v2, return 0; would be slighly nicer here.

OK, I'll fix it in v2.
Thanks for the review.

Best regards,
Eric Lin

Quoted 6 lines

CJ

Quoted 1 line

+}

[...]

#6 lore raw

Re: [PATCH 1/3] soc: sifive: Add SiFive private L2 cache support

In reply to Eric Lin

Hey Eric,

Quoted 6 lines · Eric Lin

This adds SiFive private L2 cache driver which will show cache config information when booting and add cpu hotplug callback functions.

Missing a Co-developed-by for Nick?

Quoted 6 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +6 -0
+static void pl2_config_read(void __iomem *pl2_base, int cpu)
+{
+	u32 regval, bank, way, set, cacheline;
+
+	regval = readl(pl2_base);
+	bank = regval & 0xff;

drivers/soc/sifive/sifive_pl2_cache.c line 125

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +10 -0
+	pr_info("in the CPU: %d\n", cpu);
+	pr_info("No. of Banks in the cache: %d\n", bank);
+	way = (regval & 0xff00) >> 8;
+	pr_info("No. of ways per bank: %d\n", way);
+	set = (regval & 0xff0000) >> 16;
+	pr_info("Total sets: %llu\n", (uint64_t)1 << set);
+	cacheline = (regval & 0xff000000) >> 24;
+	pr_info("Bytes per cache block: %llu\n", (uint64_t)1 << cacheline);
+	pr_info("Size: %d\n", way << (set + cacheline));
+}

Isn't this basically all information that we get anyway in sysfs based on what gets put into the DT, except printed out once per CPU at boottime?
If there's reason to keep it, please do as suggested by Ben and cut down the number of lines emitted. Look at the ccache one for comparison:

	static void ccache_config_read(void)
	{
		u32 cfg;
	
		cfg = readl(ccache_base + SIFIVE_CCACHE_CONFIG);
		pr_info("%llu banks, %llu ways, sets/bank=%llu, bytes/block=%llu\n",
			FIELD_GET(SIFIVE_CCACHE_CONFIG_BANK_MASK, cfg),
			FIELD_GET(SIFIVE_CCACHE_CONFIG_WAYS_MASK, cfg),
			BIT_ULL(FIELD_GET(SIFIVE_CCACHE_CONFIG_SETS_MASK, cfg)),
			BIT_ULL(FIELD_GET(SIFIVE_CCACHE_CONFIG_BLKS_MASK, cfg)));
	
		cfg = readl(ccache_base + SIFIVE_CCACHE_WAYENABLE);
		pr_info("Index of the largest way enabled: %u\n", cfg);
	}

It'd also be good to print the same things as the ccache, no?

drivers/soc/sifive/sifive_pl2_cache.c line 133

Quoted 7 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +7 -0
+static int sifive_pl2_cache_dev_probe(struct platform_device *pdev)
+{
+	struct resource *res;
+	int cpu, ret = -EINVAL;
+	struct device_node *cpu_node, *pl2_node;
+	struct sifive_pl2_state *pl2_state = NULL;
+	void __iomem *pl2_base;

Please pick a sensible ordering for variables. IDC if it is reverse xmas tree, or sorting by types, but this just seems quite random..

Quoted 5 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +5 -0
+	/* Traverse all cpu nodes to find the one mapping to its pl2 node. */
+	for_each_cpu(cpu, cpu_possible_mask) {
+		cpu_node = of_cpu_device_node_get(cpu);
+		pl2_node = of_parse_phandle(cpu_node, "next-level-cache", 0);
+

drivers/soc/sifive/sifive_pl2_cache.c line 149

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +10 -0
+		/* Found it! */
+		if (dev_of_node(&pdev->dev) == pl2_node) {
+			/* Use cpu to get its percpu data sifive_pl2_state. */
+			pl2_state = per_cpu_ptr(&sifive_pl2_state, cpu);
+			break;
+		}
+	}
+
+	if (!pl2_state) {
+		pr_err("Not found the corresponding cpu_node in dts.\n");

I don't think this error message is going to be helpful in figuring out where the problem is on a machine with many of the caches. More information about *which* cache caused it would be good. Also it is not grammatically correct, it should read something like "Failed to find CPU node for cache@abc" or something along those lines.

Review

Quoted 1 line
(quoted diff) +1 -0
+		goto early_err;

early_err just returns ret. Why not just return the error directly?

Quoted 25 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +24 -0
+	}
+
+	/* Set base address of select and counter registers. */
+	pl2_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+	if (IS_ERR(pl2_base)) {
+		ret = PTR_ERR(pl2_base);
+		goto early_err;
+	}
+
+	/* Print pL2 configs. */
+	pl2_config_read(pl2_base, cpu);
+	pl2_state->pl2_base = pl2_base;
+
+	return 0;
+
+early_err:
+	return ret;
+}
 
+static struct platform_driver sifive_pl2_cache_driver = {
+	.driver = {
+		   .name = "SiFive-pL2-cache",
+		   .of_match_table = sifive_pl2_cache_of_ids,
+		   },
+	.probe = sifive_pl2_cache_dev_probe,

drivers/soc/sifive/sifive_pl2_cache.c line 185

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +10 -0
+};
+
+static int __init sifive_pl2_cache_init(void)
+{
+	int ret;
+
+	ret = cpuhp_setup_state(CPUHP_AP_RISCV_SIFIVE_PL2_ONLINE,
+				"soc/sifive/pl2:online",
+				      sifive_pl2_online_cpu,
+				      sifive_pl2_offline_cpu);

Got some weird use of whitespace here & above, please remove the spaces.

Cheers,
Conor.

author
#7 lore raw

Re: [PATCH 1/3] soc: sifive: Add SiFive private L2 cache support

Hi Conor,

Quoted 4 lines · Conor Dooley

Hey Eric,

On Fri, Jun 16, 2023 at 02:32:08PM +0800, Eric Lin wrote:

Quoted 8 lines
Quoted 6 lines

This adds SiFive private L2 cache driver which will show cache config information when booting and add cpu hotplug callback functions.

Missing a Co-developed-by for Nick?

Yes, I'll add Co-developed-by for Nick in v2. Thanks.

Quoted 38 lines
Quoted 8 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +6 -0
+static void pl2_config_read(void __iomem *pl2_base, int cpu)
+{
+     u32 regval, bank, way, set, cacheline;
+
+     regval = readl(pl2_base);
+     bank = regval & 0xff;

drivers/soc/sifive/sifive_pl2_cache.c line 125

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +10 -0
+     pr_info("in the CPU: %d\n", cpu);
+     pr_info("No. of Banks in the cache: %d\n", bank);
+     way = (regval & 0xff00) >> 8;
+     pr_info("No. of ways per bank: %d\n", way);
+     set = (regval & 0xff0000) >> 16;
+     pr_info("Total sets: %llu\n", (uint64_t)1 << set);
+     cacheline = (regval & 0xff000000) >> 24;
+     pr_info("Bytes per cache block: %llu\n", (uint64_t)1 << cacheline);
+     pr_info("Size: %d\n", way << (set + cacheline));
+}

Isn't this basically all information that we get anyway in sysfs based on what gets put into the DT, except printed out once per CPU at boottime?
If there's reason to keep it, please do as suggested by Ben and cut down the number of lines emitted. Look at the ccache one for comparison:

        static void ccache_config_read(void)
        {
                u32 cfg;

                cfg = readl(ccache_base + SIFIVE_CCACHE_CONFIG);
                pr_info("%llu banks, %llu ways, sets/bank=%llu, bytes/block=%llu\n",
                        FIELD_GET(SIFIVE_CCACHE_CONFIG_BANK_MASK, cfg),
                        FIELD_GET(SIFIVE_CCACHE_CONFIG_WAYS_MASK, cfg),
                        BIT_ULL(FIELD_GET(SIFIVE_CCACHE_CONFIG_SETS_MASK, cfg)),
                        BIT_ULL(FIELD_GET(SIFIVE_CCACHE_CONFIG_BLKS_MASK, cfg)));

                cfg = readl(ccache_base + SIFIVE_CCACHE_WAYENABLE);
                pr_info("Index of the largest way enabled: %u\n", cfg);
        }
Quoted 2 lines

It'd also be good to print the same things as the ccache, no?

Yes, I'll cut down the number of lines as the ccache in v2. Thanks for the suggestion.

Quoted 11 lines

drivers/soc/sifive/sifive_pl2_cache.c line 133

Quoted 7 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +7 -0
+static int sifive_pl2_cache_dev_probe(struct platform_device *pdev)
+{
+     struct resource *res;
+     int cpu, ret = -EINVAL;
+     struct device_node *cpu_node, *pl2_node;
+     struct sifive_pl2_state *pl2_state = NULL;
+     void __iomem *pl2_base;

Please pick a sensible ordering for variables. IDC if it is reverse xmas tree, or sorting by types, but this just seems quite random..

Yes, I'll sort by type in v2.

Quoted 13 lines
Quoted 13 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +13 -0
+     /* Traverse all cpu nodes to find the one mapping to its pl2 node. */
+     for_each_cpu(cpu, cpu_possible_mask) {
+             cpu_node = of_cpu_device_node_get(cpu);
+             pl2_node = of_parse_phandle(cpu_node, "next-level-cache", 0);
+
+             /* Found it! */
+             if (dev_of_node(&pdev->dev) == pl2_node) {
+                     /* Use cpu to get its percpu data sifive_pl2_state. */
+                     pl2_state = per_cpu_ptr(&sifive_pl2_state, cpu);
+                     break;
+             }
+     }
+
Quoted 9 lines

drivers/soc/sifive/sifive_pl2_cache.c line 149

Quoted 2 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +2 -0
+     if (!pl2_state) {
+             pr_err("Not found the corresponding cpu_node in dts.\n");

I don't think this error message is going to be helpful in figuring out where the problem is on a machine with many of the caches. More information about *which* cache caused it would be good. Also it is not grammatically correct, it should read something like "Failed to find CPU node for cache@abc" or something along those lines.

OK, I'll rewrite the error message to make it more helpful for the user. I'll fix it in v2. Thanks for the suggestion.

Quoted 4 lines
Quoted 1 line

+ goto early_err;

early_err just returns ret. Why not just return the error directly?

Yeah, it can just return ret. I'll fix it in v2.

Quoted 29 lines
Quoted 29 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +28 -0
+     }
+
+     /* Set base address of select and counter registers. */
+     pl2_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+     if (IS_ERR(pl2_base)) {
+             ret = PTR_ERR(pl2_base);
+             goto early_err;
+     }
+
+     /* Print pL2 configs. */
+     pl2_config_read(pl2_base, cpu);
+     pl2_state->pl2_base = pl2_base;
+
+     return 0;
+
+early_err:
+     return ret;
+}
 
+static struct platform_driver sifive_pl2_cache_driver = {
+     .driver = {
+                .name = "SiFive-pL2-cache",
+                .of_match_table = sifive_pl2_cache_of_ids,
+                },
+     .probe = sifive_pl2_cache_dev_probe,
+};
+
+static int __init sifive_pl2_cache_init(void)
+{
Quoted 9 lines

drivers/soc/sifive/sifive_pl2_cache.c line 185

Quoted 6 lines
drivers/soc/sifive/sifive_pl2_cache.c new file +6 -0
+     int ret;
+
+     ret = cpuhp_setup_state(CPUHP_AP_RISCV_SIFIVE_PL2_ONLINE,
+                             "soc/sifive/pl2:online",
+                                   sifive_pl2_online_cpu,
+                                   sifive_pl2_offline_cpu);

Got some weird use of whitespace here & above, please remove the spaces.

Yes, I'll remove the whitespace in v2.
Thanks for the review.

Best Regards,
Eric Lin.

Quoted 2 lines

Cheers,
Conor.

author
#8 lore raw

PATCH 2/3 soc: sifive: Add SiFive private L2 cache PMU driver

In reply to Eric Lin

From: Greentime Hu <[email protected]>

This adds SiFive private L2 cache PMU driver. User can use perf tool to profile by event name and event id.

Example:

$ perf stat -C 0 -e /sifive_pl2_pmu/inner_acquire_block_btot/
                -e /sifive_pl2_pmu/inner_acquire_block_ntob/
                -e /sifive_pl2_pmu/inner_acquire_block_ntot/ ls

Performance counter stats for 'CPU(s) 0':

               300      sifive_pl2_pmu/inner_acquire_block_btot/
             17801      sifive_pl2_pmu/inner_acquire_block_ntob/
              5253      sifive_pl2_pmu/inner_acquire_block_ntot/
       0.088917326 seconds time elapsed
$ perf stat -C 0 -e /sifive_pl2_pmu/event=0x10001/
                -e /sifive_pl2_pmu/event=0x4001/
                -e /sifive_pl2_pmu/event=0x8001/ ls

Performance counter stats for 'CPU(s) 0':

               251      sifive_pl2_pmu/event=0x10001/
              2620      sifive_pl2_pmu/event=0x4001/
               644      sifive_pl2_pmu/event=0x8001/
       0.092827110 seconds time elapsed
---
 drivers/soc/sifive/Kconfig            |   9 +
 drivers/soc/sifive/Makefile           |   1 +
 drivers/soc/sifive/sifive_pl2.h       |  20 +
 drivers/soc/sifive/sifive_pl2_cache.c |  16 +
 drivers/soc/sifive/sifive_pl2_pmu.c   | 669 ++++++++++++++++++++++++++
 include/linux/cpuhotplug.h            |   1 +
 6 files changed, 716 insertions(+)
 create mode 100644 drivers/soc/sifive/sifive_pl2_pmu.c
drivers/soc/sifive/Kconfig +9 -0
index 573564295058..deeb752287c7 100644
@@ -15,4 +15,13 @@ config SIFIVE_PL2
 	  with both the upstream L1 caches and downstream L3 cache or memory,
 	  enabling a high-performance cache subsystem.
 
+config SIFIVE_PL2_PMU
+	bool "Sifive private L2 Cache PMU"
+	depends on SIFIVE_PL2 && PERF_EVENTS
+	default y
+	help
+	  Support for the private L2 cache controller performance monitor unit
+	  (PMU) on SiFive platforms. The SiFive private L2 PMU can monitor the
+	  each hart L2 cache performance and it consists of a set of event
+	  programmable counters and their event selector registers.
 endif
drivers/soc/sifive/Makefile +1 -0
index 707493e1c691..4bb3f97ef3f8 100644
@@ -2,3 +2,4 @@
 
 obj-$(CONFIG_SIFIVE_CCACHE)	+= sifive_ccache.o
 obj-$(CONFIG_SIFIVE_PL2)	+= sifive_pl2_cache.o
+obj-$(CONFIG_SIFIVE_PL2_PMU)	+= sifive_pl2_pmu.o
drivers/soc/sifive/sifive_pl2.h +20 -0
index 57aa1019d5ed..21207b0d6092 100644
@@ -7,10 +7,16 @@
 #ifndef _SIFIVE_PL2_H
 #define _SIFIVE_PL2_H
 
+#define SIFIVE_PL2_PMU_MAX_COUNTERS	64
+#define SIFIVE_PL2_SELECT_BASE_OFFSET	0x2000
+#define SIFIVE_PL2_COUNTER_BASE_OFFSET	0x3000
+
 #define SIFIVE_PL2_CONFIG1_OFFSET	0x1000
 #define SIFIVE_PL2_CONFIG0_OFFSET	0x1008
 #define SIFIVE_PL2_PMCLIENT_OFFSET	0x2800
 
+#define SIFIVE_PL2_COUNTER_MASK   GENMASK_ULL(63, 0)
+
 struct sifive_pl2_state {
 	void __iomem *pl2_base;
 	u32 config1;
@@ -18,6 +24,20 @@ struct sifive_pl2_state {
 	u64 pmclientfilter;
 };
 
+struct sifive_pl2_pmu_event {
+	struct perf_event **events;
+	void __iomem *event_counter_base;
+	void __iomem *event_select_base;
+	u32 counters;
+	DECLARE_BITMAP(used_mask, SIFIVE_PL2_PMU_MAX_COUNTERS);
+};
+
+struct sifive_pl2_pmu {
+	struct pmu *pmu;
+	struct hlist_node node;
+	cpumask_t cpumask;
+};
+
 int sifive_pl2_pmu_init(void);
 int sifive_pl2_pmu_probe(struct device_node *pl2_node,
 			 void __iomem *pl2_base, int cpu);
drivers/soc/sifive/sifive_pl2_cache.c +16 -0
index aeb51d576af9..56d67879de54 100644
@@ -161,6 +161,14 @@ static int sifive_pl2_cache_dev_probe(struct platform_device *pdev)
 	pl2_config_read(pl2_base, cpu);
 	pl2_state->pl2_base = pl2_base;
 
+	if (IS_ENABLED(CONFIG_SIFIVE_PL2_PMU)) {
+		ret = sifive_pl2_pmu_probe(pl2_node, pl2_base, cpu);
+		if (ret) {
+			pr_err("Fail to probe sifive_pl2_pmu driver.\n");
+			goto early_err;
+		}
+	}
+
 	return 0;
 
 early_err:
@@ -196,6 +204,14 @@ static int __init sifive_pl2_cache_init(void)
 
 	sifive_pl2_pm_init();
 
+	if (IS_ENABLED(CONFIG_SIFIVE_PL2_PMU)) {
+		ret = sifive_pl2_pmu_init();
+		if (ret) {
+			pr_err("Fail to init sifive_pl2_pmu driver.\n");
+			return ret;
+		}
+	}
+
 	return ret;
 }
 
drivers/soc/sifive/sifive_pl2_pmu.c new file +669 -0

669 lines not on this page · raw message

include/linux/cpuhotplug.h +1 -0
index 35cd5ba0030b..9c1a91c8cdaa 100644
@@ -243,6 +243,7 @@ enum cpuhp_state {
 	CPUHP_AP_PERF_POWERPC_HV_24x7_ONLINE,
 	CPUHP_AP_PERF_POWERPC_HV_GPCI_ONLINE,
 	CPUHP_AP_PERF_CSKY_ONLINE,
+	CPUHP_AP_PERF_RISCV_SIFIVE_PL2_PMU_ONLINE,
 	CPUHP_AP_WATCHDOG_ONLINE,
 	CPUHP_AP_WORKQUEUE_ONLINE,
 	CPUHP_AP_RANDOM_ONLINE,
Signature · 7 lines
2.40.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#9 lore raw

Re: [PATCH 2/3] soc: sifive: Add SiFive private L2 cache PMU driver

Quoted 34 lines · Eric Lin

From: Greentime Hu <[email protected]>

This adds SiFive private L2 cache PMU driver. User can use perf tool to profile by event name and event id.

Example:

$ perf stat -C 0 -e /sifive_pl2_pmu/inner_acquire_block_btot/
                -e /sifive_pl2_pmu/inner_acquire_block_ntob/
                -e /sifive_pl2_pmu/inner_acquire_block_ntot/ ls

Performance counter stats for 'CPU(s) 0':

               300      sifive_pl2_pmu/inner_acquire_block_btot/
             17801      sifive_pl2_pmu/inner_acquire_block_ntob/
              5253      sifive_pl2_pmu/inner_acquire_block_ntot/
       0.088917326 seconds time elapsed
$ perf stat -C 0 -e /sifive_pl2_pmu/event=0x10001/
                -e /sifive_pl2_pmu/event=0x4001/
                -e /sifive_pl2_pmu/event=0x8001/ ls

Performance counter stats for 'CPU(s) 0':

               251      sifive_pl2_pmu/event=0x10001/
              2620      sifive_pl2_pmu/event=0x4001/
               644      sifive_pl2_pmu/event=0x8001/
       0.092827110 seconds time elapsed
Quoted 6 lines
---
 drivers/soc/sifive/Kconfig            |   9 +
 drivers/soc/sifive/Makefile           |   1 +
 drivers/soc/sifive/sifive_pl2.h       |  20 +
 drivers/soc/sifive/sifive_pl2_cache.c |  16 +
 drivers/soc/sifive/sifive_pl2_pmu.c   | 669 ++++++++++++++++++++++++++

Perf drivers should be in drivers/perf, no?

Cheers,
Conor.

author
#10 lore raw

Re: [PATCH 2/3] soc: sifive: Add SiFive private L2 cache PMU driver

Quoted 43 lines · Conor Dooley
Quoted 34 lines · Eric Lin

From: Greentime Hu <[email protected]>

This adds SiFive private L2 cache PMU driver. User can use perf tool to profile by event name and event id.

Example:

$ perf stat -C 0 -e /sifive_pl2_pmu/inner_acquire_block_btot/
                -e /sifive_pl2_pmu/inner_acquire_block_ntob/
                -e /sifive_pl2_pmu/inner_acquire_block_ntot/ ls

Performance counter stats for 'CPU(s) 0':

               300      sifive_pl2_pmu/inner_acquire_block_btot/
             17801      sifive_pl2_pmu/inner_acquire_block_ntob/
              5253      sifive_pl2_pmu/inner_acquire_block_ntot/
       0.088917326 seconds time elapsed
$ perf stat -C 0 -e /sifive_pl2_pmu/event=0x10001/
                -e /sifive_pl2_pmu/event=0x4001/
                -e /sifive_pl2_pmu/event=0x8001/ ls

Performance counter stats for 'CPU(s) 0':

               251      sifive_pl2_pmu/event=0x10001/
              2620      sifive_pl2_pmu/event=0x4001/
               644      sifive_pl2_pmu/event=0x8001/
       0.092827110 seconds time elapsed
Quoted 6 lines
---
 drivers/soc/sifive/Kconfig            |   9 +
 drivers/soc/sifive/Makefile           |   1 +
 drivers/soc/sifive/sifive_pl2.h       |  20 +
 drivers/soc/sifive/sifive_pl2_cache.c |  16 +
 drivers/soc/sifive/sifive_pl2_pmu.c   | 669 ++++++++++++++++++++++++++
Quoted 2 lines

Perf drivers should be in drivers/perf, no?

Hi Conor,

Yes, I see most of the drivers are in the drivers/perf.

But I grep perf_pmu_register(), it seems not all the pmu drivers are in drivers/perf as below:

arch/arm/mach-imx/mmdc.c:517: ret =
perf_pmu_register(&(pmu_mmdc->pmu), name, -1);
arch/arm/mm/cache-l2x0-pmu.c:552: ret =
perf_pmu_register(l2x0_pmu, l2x0_name, -1);
...
drivers/dma/idxd/perfmon.c:627: rc = perf_pmu_register(&idxd_pmu->pmu, idxd_pmu->name, -1);
drivers/fpga/dfl-fme-perf.c:904:static int fme_perf_pmu_register(struct platform_device *pdev,
drivers/fpga/dfl-fme-perf.c:929: ret = perf_pmu_register(pmu, name, -1);
...
drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c:549: ret =
perf_pmu_register(&pmu_entry->pmu, pmu_name, -1);
drivers/gpu/drm/i915/i915_pmu.c:1190: ret =
perf_pmu_register(&pmu->base, pmu->name, -1);
drivers/hwtracing/coresight/coresight-etm-perf.c:907: ret =
perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1);
drivers/hwtracing/ptt/hisi_ptt.c:895: ret =
perf_pmu_register(&hisi_ptt->hisi_ptt_pmu, pmu_name, -1);
drivers/iommu/intel/perfmon.c:570: return
perf_pmu_register(&iommu_pmu->pmu, iommu_pmu->pmu.name, -1);
drivers/nvdimm/nd_perf.c:309: rc = perf_pmu_register(&nd_pmu->pmu,
nd_pmu->pmu.name, -1);
...

I just wondering what kind of pmu drivers should be in drivers/perf and what kind of pmu drivers should not be in drivers/perf. Thanks.

Best regards,
Eric Lin

Quoted 2 lines

Cheers,
Conor.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#11 lore raw

Re: [PATCH 2/3] soc: sifive: Add SiFive private L2 cache PMU driver

Arnd, Perf people,

Quoted 79 lines · Eric Lin
Quoted 43 lines · Conor Dooley
Quoted 34 lines · Eric Lin

From: Greentime Hu <[email protected]>

This adds SiFive private L2 cache PMU driver. User can use perf tool to profile by event name and event id.

Example:

$ perf stat -C 0 -e /sifive_pl2_pmu/inner_acquire_block_btot/
                -e /sifive_pl2_pmu/inner_acquire_block_ntob/
                -e /sifive_pl2_pmu/inner_acquire_block_ntot/ ls

Performance counter stats for 'CPU(s) 0':

               300      sifive_pl2_pmu/inner_acquire_block_btot/
             17801      sifive_pl2_pmu/inner_acquire_block_ntob/
              5253      sifive_pl2_pmu/inner_acquire_block_ntot/
       0.088917326 seconds time elapsed
$ perf stat -C 0 -e /sifive_pl2_pmu/event=0x10001/
                -e /sifive_pl2_pmu/event=0x4001/
                -e /sifive_pl2_pmu/event=0x8001/ ls

Performance counter stats for 'CPU(s) 0':

               251      sifive_pl2_pmu/event=0x10001/
              2620      sifive_pl2_pmu/event=0x4001/
               644      sifive_pl2_pmu/event=0x8001/
       0.092827110 seconds time elapsed
Quoted 6 lines
---
 drivers/soc/sifive/Kconfig            |   9 +
 drivers/soc/sifive/Makefile           |   1 +
 drivers/soc/sifive/sifive_pl2.h       |  20 +
 drivers/soc/sifive/sifive_pl2_cache.c |  16 +
 drivers/soc/sifive/sifive_pl2_pmu.c   | 669 ++++++++++++++++++++++++++
Quoted 2 lines

Perf drivers should be in drivers/perf, no?

Hi Conor,

Yes, I see most of the drivers are in the drivers/perf.

But I grep perf_pmu_register(), it seems not all the pmu drivers are in drivers/perf as below:

arch/arm/mach-imx/mmdc.c:517: ret =
perf_pmu_register(&(pmu_mmdc->pmu), name, -1);
arch/arm/mm/cache-l2x0-pmu.c:552: ret =
perf_pmu_register(l2x0_pmu, l2x0_name, -1);
...
drivers/dma/idxd/perfmon.c:627: rc = perf_pmu_register(&idxd_pmu->pmu, idxd_pmu->name, -1);
drivers/fpga/dfl-fme-perf.c:904:static int fme_perf_pmu_register(struct platform_device *pdev,
drivers/fpga/dfl-fme-perf.c:929: ret = perf_pmu_register(pmu, name, -1);
...
drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c:549: ret =
perf_pmu_register(&pmu_entry->pmu, pmu_name, -1);
drivers/gpu/drm/i915/i915_pmu.c:1190: ret =
perf_pmu_register(&pmu->base, pmu->name, -1);
drivers/hwtracing/coresight/coresight-etm-perf.c:907: ret =
perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1);
drivers/hwtracing/ptt/hisi_ptt.c:895: ret =
perf_pmu_register(&hisi_ptt->hisi_ptt_pmu, pmu_name, -1);
drivers/iommu/intel/perfmon.c:570: return
perf_pmu_register(&iommu_pmu->pmu, iommu_pmu->pmu.name, -1);
drivers/nvdimm/nd_perf.c:309: rc = perf_pmu_register(&nd_pmu->pmu,
nd_pmu->pmu.name, -1);
...

Quoted 3 lines

I just wondering what kind of pmu drivers should be in drivers/perf and what kind of pmu drivers should not be in drivers/perf. Thanks.

To be quite honest, I have no idea.
I'm just a wee bit wary of taking anything that appears to have another home via drivers/soc. I'd rather break drivers out, using the aux bus or similar if need be, so that people who are knowledgeable in an area are CCed on patches.
Hopefully Arnd or the Perf people can offer some guidance here. If it does go into drivers/soc, it'll need a review from someone knowledgeable of perf anyway.

Cheers,
Conor.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#12 lore raw

Re: [PATCH 2/3] soc: sifive: Add SiFive private L2 cache PMU driver

Hi folks,

Quoted 44 lines · Conor Dooley
Quoted 39 lines · Eric Lin
Quoted 9 lines · Conor Dooley
Quoted 5 lines · Eric Lin
 drivers/soc/sifive/Kconfig            |   9 +
 drivers/soc/sifive/Makefile           |   1 +
 drivers/soc/sifive/sifive_pl2.h       |  20 +
 drivers/soc/sifive/sifive_pl2_cache.c |  16 +
 drivers/soc/sifive/sifive_pl2_pmu.c   | 669 ++++++++++++++++++++++++++

Perf drivers should be in drivers/perf, no?

But I grep perf_pmu_register(), it seems not all the pmu drivers are in drivers/perf as below:

arch/arm/mach-imx/mmdc.c:517: ret =
perf_pmu_register(&(pmu_mmdc->pmu), name, -1);
arch/arm/mm/cache-l2x0-pmu.c:552: ret =
perf_pmu_register(l2x0_pmu, l2x0_name, -1);
...
drivers/dma/idxd/perfmon.c:627: rc = perf_pmu_register(&idxd_pmu->pmu, idxd_pmu->name, -1);
drivers/fpga/dfl-fme-perf.c:904:static int fme_perf_pmu_register(struct platform_device *pdev,
drivers/fpga/dfl-fme-perf.c:929: ret = perf_pmu_register(pmu, name, -1);
...
drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c:549: ret =
perf_pmu_register(&pmu_entry->pmu, pmu_name, -1);
drivers/gpu/drm/i915/i915_pmu.c:1190: ret =
perf_pmu_register(&pmu->base, pmu->name, -1);
drivers/hwtracing/coresight/coresight-etm-perf.c:907: ret =
perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1);
drivers/hwtracing/ptt/hisi_ptt.c:895: ret =
perf_pmu_register(&hisi_ptt->hisi_ptt_pmu, pmu_name, -1);
drivers/iommu/intel/perfmon.c:570: return
perf_pmu_register(&iommu_pmu->pmu, iommu_pmu->pmu.name, -1);
drivers/nvdimm/nd_perf.c:309: rc = perf_pmu_register(&nd_pmu->pmu,
nd_pmu->pmu.name, -1);
...

Quoted 3 lines

I just wondering what kind of pmu drivers should be in drivers/perf and what kind of pmu drivers should not be in drivers/perf. Thanks.

Quoted 8 lines

To be quite honest, I have no idea.
I'm just a wee bit wary of taking anything that appears to have another home via drivers/soc. I'd rather break drivers out, using the aux bus or similar if need be, so that people who are knowledgeable in an area are CCed on patches.
Hopefully Arnd or the Perf people can offer some guidance here. If it does go into drivers/soc, it'll need a review from someone knowledgeable of perf anyway.

I'm not territorial about the perf drivers at all, but L2CC PMUs like this one probably fit pretty well in drivers/perf. The usual reason for putting drivers elsewhere is if the PMU is tightly coupled with some other IP which is handled by another subsystem (e.g. GPU).

Will

author
#13 lore raw

Re: [PATCH 2/3] soc: sifive: Add SiFive private L2 cache PMU driver

Hi Will,

Quoted 57 lines · Will Deacon

Hi folks,

Quoted 44 lines · Conor Dooley
Quoted 39 lines · Eric Lin
Quoted 9 lines · Conor Dooley
Quoted 5 lines · Eric Lin
 drivers/soc/sifive/Kconfig            |   9 +
 drivers/soc/sifive/Makefile           |   1 +
 drivers/soc/sifive/sifive_pl2.h       |  20 +
 drivers/soc/sifive/sifive_pl2_cache.c |  16 +
 drivers/soc/sifive/sifive_pl2_pmu.c   | 669 ++++++++++++++++++++++++++

Perf drivers should be in drivers/perf, no?

But I grep perf_pmu_register(), it seems not all the pmu drivers are in drivers/perf as below:

arch/arm/mach-imx/mmdc.c:517: ret =
perf_pmu_register(&(pmu_mmdc->pmu), name, -1);
arch/arm/mm/cache-l2x0-pmu.c:552: ret =
perf_pmu_register(l2x0_pmu, l2x0_name, -1);
...
drivers/dma/idxd/perfmon.c:627: rc = perf_pmu_register(&idxd_pmu->pmu, idxd_pmu->name, -1);
drivers/fpga/dfl-fme-perf.c:904:static int fme_perf_pmu_register(struct platform_device *pdev,
drivers/fpga/dfl-fme-perf.c:929: ret = perf_pmu_register(pmu, name, -1);
...
drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c:549: ret =
perf_pmu_register(&pmu_entry->pmu, pmu_name, -1);
drivers/gpu/drm/i915/i915_pmu.c:1190: ret =
perf_pmu_register(&pmu->base, pmu->name, -1);
drivers/hwtracing/coresight/coresight-etm-perf.c:907: ret =
perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1);
drivers/hwtracing/ptt/hisi_ptt.c:895: ret =
perf_pmu_register(&hisi_ptt->hisi_ptt_pmu, pmu_name, -1);
drivers/iommu/intel/perfmon.c:570: return
perf_pmu_register(&iommu_pmu->pmu, iommu_pmu->pmu.name, -1);
drivers/nvdimm/nd_perf.c:309: rc = perf_pmu_register(&nd_pmu->pmu,
nd_pmu->pmu.name, -1);
...

Quoted 3 lines

I just wondering what kind of pmu drivers should be in drivers/perf and what kind of pmu drivers should not be in drivers/perf. Thanks.

Quoted 8 lines

To be quite honest, I have no idea.
I'm just a wee bit wary of taking anything that appears to have another home via drivers/soc. I'd rather break drivers out, using the aux bus or similar if need be, so that people who are knowledgeable in an area are CCed on patches.
Hopefully Arnd or the Perf people can offer some guidance here. If it does go into drivers/soc, it'll need a review from someone knowledgeable of perf anyway.

Quoted 5 lines

I'm not territorial about the perf drivers at all, but L2CC PMUs like this one probably fit pretty well in drivers/perf. The usual reason for putting drivers elsewhere is if the PMU is tightly coupled with some other IP which is handled by another subsystem (e.g. GPU).

Thanks for the explanation. OK, I'll put the pl2 cache PMU driver in drivers/perf.

Best Regards,
Eric Lin.

Quoted 1 line

Will

#14 lore raw

Re: [PATCH 2/3] soc: sifive: Add SiFive private L2 cache PMU driver

In reply to Eric Lin
Quoted 79 lines · Eric Lin
Quoted 43 lines · Conor Dooley
Quoted 34 lines · Eric Lin

From: Greentime Hu <[email protected]>

This adds SiFive private L2 cache PMU driver. User can use perf tool to profile by event name and event id.

Example:

$ perf stat -C 0 -e /sifive_pl2_pmu/inner_acquire_block_btot/
                 -e /sifive_pl2_pmu/inner_acquire_block_ntob/
                 -e /sifive_pl2_pmu/inner_acquire_block_ntot/ ls

Performance counter stats for 'CPU(s) 0':

                300      sifive_pl2_pmu/inner_acquire_block_btot/
              17801      sifive_pl2_pmu/inner_acquire_block_ntob/
               5253      sifive_pl2_pmu/inner_acquire_block_ntot/
        0.088917326 seconds time elapsed
$ perf stat -C 0 -e /sifive_pl2_pmu/event=0x10001/
                 -e /sifive_pl2_pmu/event=0x4001/
                 -e /sifive_pl2_pmu/event=0x8001/ ls

Performance counter stats for 'CPU(s) 0':

                251      sifive_pl2_pmu/event=0x10001/
               2620      sifive_pl2_pmu/event=0x4001/
                644      sifive_pl2_pmu/event=0x8001/
        0.092827110 seconds time elapsed
Quoted 6 lines
---
  drivers/soc/sifive/Kconfig            |   9 +
  drivers/soc/sifive/Makefile           |   1 +
  drivers/soc/sifive/sifive_pl2.h       |  20 +
  drivers/soc/sifive/sifive_pl2_cache.c |  16 +
  drivers/soc/sifive/sifive_pl2_pmu.c   | 669 ++++++++++++++++++++++++++
Quoted 2 lines

Perf drivers should be in drivers/perf, no?

Hi Conor,

Yes, I see most of the drivers are in the drivers/perf.

But I grep perf_pmu_register(), it seems not all the pmu drivers are in drivers/perf as below:

arch/arm/mach-imx/mmdc.c:517: ret =
perf_pmu_register(&(pmu_mmdc->pmu), name, -1);
arch/arm/mm/cache-l2x0-pmu.c:552: ret =
perf_pmu_register(l2x0_pmu, l2x0_name, -1);
...
drivers/dma/idxd/perfmon.c:627: rc = perf_pmu_register(&idxd_pmu->pmu, idxd_pmu->name, -1);
drivers/fpga/dfl-fme-perf.c:904:static int fme_perf_pmu_register(struct platform_device *pdev,
drivers/fpga/dfl-fme-perf.c:929: ret = perf_pmu_register(pmu, name, -1);
...
drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c:549: ret =
perf_pmu_register(&pmu_entry->pmu, pmu_name, -1);
drivers/gpu/drm/i915/i915_pmu.c:1190: ret =
perf_pmu_register(&pmu->base, pmu->name, -1);
drivers/hwtracing/coresight/coresight-etm-perf.c:907: ret =
perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1);
drivers/hwtracing/ptt/hisi_ptt.c:895: ret =
perf_pmu_register(&hisi_ptt->hisi_ptt_pmu, pmu_name, -1);
drivers/iommu/intel/perfmon.c:570: return
perf_pmu_register(&iommu_pmu->pmu, iommu_pmu->pmu.name, -1);
drivers/nvdimm/nd_perf.c:309: rc = perf_pmu_register(&nd_pmu->pmu,
nd_pmu->pmu.name, -1);
...

Quoted 4 lines

I just wondering what kind of pmu drivers should be in drivers/perf and what kind of pmu drivers should not be in drivers/perf. Thanks.

Given the registers for the l2 cache controls and l2 pmu don't overlap do we need the pmu and general cache drivers together?

Signature · 10 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
author
#15 lore raw

Re: [PATCH 2/3] soc: sifive: Add SiFive private L2 cache PMU driver

Hi Ben,

Quoted 81 lines · Ben Dooks
Quoted 79 lines · Eric Lin
Quoted 43 lines · Conor Dooley
Quoted 34 lines · Eric Lin

From: Greentime Hu <[email protected]>

This adds SiFive private L2 cache PMU driver. User can use perf tool to profile by event name and event id.

Example:

$ perf stat -C 0 -e /sifive_pl2_pmu/inner_acquire_block_btot/
                 -e /sifive_pl2_pmu/inner_acquire_block_ntob/
                 -e /sifive_pl2_pmu/inner_acquire_block_ntot/ ls

Performance counter stats for 'CPU(s) 0':

                300      sifive_pl2_pmu/inner_acquire_block_btot/
              17801      sifive_pl2_pmu/inner_acquire_block_ntob/
               5253      sifive_pl2_pmu/inner_acquire_block_ntot/
        0.088917326 seconds time elapsed
$ perf stat -C 0 -e /sifive_pl2_pmu/event=0x10001/
                 -e /sifive_pl2_pmu/event=0x4001/
                 -e /sifive_pl2_pmu/event=0x8001/ ls

Performance counter stats for 'CPU(s) 0':

                251      sifive_pl2_pmu/event=0x10001/
               2620      sifive_pl2_pmu/event=0x4001/
                644      sifive_pl2_pmu/event=0x8001/
        0.092827110 seconds time elapsed
Quoted 6 lines
---
  drivers/soc/sifive/Kconfig            |   9 +
  drivers/soc/sifive/Makefile           |   1 +
  drivers/soc/sifive/sifive_pl2.h       |  20 +
  drivers/soc/sifive/sifive_pl2_cache.c |  16 +
  drivers/soc/sifive/sifive_pl2_pmu.c   | 669 ++++++++++++++++++++++++++
Quoted 2 lines

Perf drivers should be in drivers/perf, no?

Hi Conor,

Yes, I see most of the drivers are in the drivers/perf.

But I grep perf_pmu_register(), it seems not all the pmu drivers are in drivers/perf as below:

arch/arm/mach-imx/mmdc.c:517: ret =
perf_pmu_register(&(pmu_mmdc->pmu), name, -1);
arch/arm/mm/cache-l2x0-pmu.c:552: ret =
perf_pmu_register(l2x0_pmu, l2x0_name, -1);
...
drivers/dma/idxd/perfmon.c:627: rc = perf_pmu_register(&idxd_pmu->pmu, idxd_pmu->name, -1);
drivers/fpga/dfl-fme-perf.c:904:static int fme_perf_pmu_register(struct platform_device *pdev,
drivers/fpga/dfl-fme-perf.c:929: ret = perf_pmu_register(pmu, name, -1);
...
drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c:549: ret =
perf_pmu_register(&pmu_entry->pmu, pmu_name, -1);
drivers/gpu/drm/i915/i915_pmu.c:1190: ret =
perf_pmu_register(&pmu->base, pmu->name, -1);
drivers/hwtracing/coresight/coresight-etm-perf.c:907: ret =
perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1);
drivers/hwtracing/ptt/hisi_ptt.c:895: ret =
perf_pmu_register(&hisi_ptt->hisi_ptt_pmu, pmu_name, -1);
drivers/iommu/intel/perfmon.c:570: return
perf_pmu_register(&iommu_pmu->pmu, iommu_pmu->pmu.name, -1);
drivers/nvdimm/nd_perf.c:309: rc = perf_pmu_register(&nd_pmu->pmu,
nd_pmu->pmu.name, -1);
...

Quoted 8 lines
Quoted 4 lines

I just wondering what kind of pmu drivers should be in drivers/perf and what kind of pmu drivers should not be in drivers/perf. Thanks.

Given the registers for the l2 cache controls and l2 pmu don't overlap do we need the pmu and general cache drivers together?

From Will's suggestion, I'll put the pl2 pmu driver to drivers/perf in v2. Thanks.

Best Regards,
Eric Lin.

Quoted 6 lines

--
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#16 lore raw

Re: [PATCH 2/3] soc: sifive: Add SiFive private L2 cache PMU driver

In reply to Eric Lin

Le 16/06/2023 à 08:32, Eric Lin a écrit :

Quoted 35 lines

From: Greentime Hu <[email protected]>

This adds SiFive private L2 cache PMU driver. User can use perf tool to profile by event name and event id.

Example:

$ perf stat -C 0 -e /sifive_pl2_pmu/inner_acquire_block_btot/
                 -e /sifive_pl2_pmu/inner_acquire_block_ntob/
                 -e /sifive_pl2_pmu/inner_acquire_block_ntot/ ls

Performance counter stats for 'CPU(s) 0':

                300      sifive_pl2_pmu/inner_acquire_block_btot/
              17801      sifive_pl2_pmu/inner_acquire_block_ntob/
               5253      sifive_pl2_pmu/inner_acquire_block_ntot/
        0.088917326 seconds time elapsed
$ perf stat -C 0 -e /sifive_pl2_pmu/event=0x10001/
                 -e /sifive_pl2_pmu/event=0x4001/
                 -e /sifive_pl2_pmu/event=0x8001/ ls

Performance counter stats for 'CPU(s) 0':

                251      sifive_pl2_pmu/event=0x10001/
               2620      sifive_pl2_pmu/event=0x4001/
                644      sifive_pl2_pmu/event=0x8001/
        0.092827110 seconds time elapsed

---

[...]

drivers/soc/sifive/sifive_pl2_pmu.c line 617

Quoted 5 lines
drivers/soc/sifive/sifive_pl2_pmu.c new file +5 -0
+int sifive_pl2_pmu_probe(struct device_node	*pl2_node,
+			 void __iomem *pl2_base, int cpu)
+{
+	struct sifive_pl2_pmu_event *ptr = per_cpu_ptr(&sifive_pl2_pmu_event, cpu);
+	int ret = -EINVAL;

Nit: no need to init

Quoted 27 lines
drivers/soc/sifive/sifive_pl2_pmu.c new file +27 -0
+
+	/* Get counter numbers. */
+	ret = of_property_read_u32(pl2_node, "sifive,perfmon-counters", &ptr->counters);
+	if (ret) {
+		pr_err("Not found sifive,perfmon-counters property\n");
+		goto early_err;
+	}
+	pr_info("perfmon-counters: %d for CPU %d\n", ptr->counters, cpu);
+
+	/* Allocate perf_event. */
+	ptr->events = kcalloc(ptr->counters, sizeof(struct perf_event), GFP_KERNEL);
+	if (!ptr->events)
+		return -ENOMEM;
+
+	ptr->event_select_base = pl2_base + SIFIVE_PL2_SELECT_BASE_OFFSET;
+	ptr->event_counter_base = pl2_base + SIFIVE_PL2_COUNTER_BASE_OFFSET;
+
+	if (!pl2pmu_init_done) {
+		ret = perf_pmu_register(sifive_pl2_pmu.pmu, sifive_pl2_pmu.pmu->name, -1);
+		if (ret) {
+			cpuhp_state_remove_instance(CPUHP_AP_PERF_RISCV_SIFIVE_PL2_PMU_ONLINE,
+						    &sifive_pl2_pmu.node);
+			pr_err("Failed to register sifive_pl2_pmu.pmu: %d\n", ret);
+		}
+		sifive_pl2_pmu_pm_init();
+		pl2pmu_init_done = true;
+	}

drivers/soc/sifive/sifive_pl2_pmu.c line 654

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_pmu.c new file +10 -0
+
+	return 0;
+
+early_err:
+	return ret;
+}
+
+int sifive_pl2_pmu_init(void)
+{
+	int ret = 0;

Nit: no need to init

Quoted 4 lines
drivers/soc/sifive/sifive_pl2_pmu.c new file +4 -0
+
+	ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_RISCV_SIFIVE_PL2_PMU_ONLINE,
+				      "perf/sifive/pl2pmu:online",
+				      sifive_pl2_pmu_online_cpu,

drivers/soc/sifive/sifive_pl2_pmu.c line 668

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_pmu.c new file +10 -0
+				      sifive_pl2_pmu_offline_cpu);
+	if (ret)
+		pr_err("Failed to register CPU hotplug notifier %d\n", ret);
+
+	ret = cpuhp_state_add_instance(CPUHP_AP_PERF_RISCV_SIFIVE_PL2_PMU_ONLINE,
+				       &sifive_pl2_pmu.node);
+	if (ret)
+		pr_err("Failed to add hotplug instance: %d\n", ret);
+
+	return ret;

Nit: return 0;

Quoted 1 line

+}

[...]

author
#17 lore raw

Re: [PATCH 2/3] soc: sifive: Add SiFive private L2 cache PMU driver

Hi Christophe,

Quoted 40 lines · Christophe JAILLET
Quoted 35 lines · Eric Lin

From: Greentime Hu <[email protected]>

This adds SiFive private L2 cache PMU driver. User can use perf tool to profile by event name and event id.

Example:

$ perf stat -C 0 -e /sifive_pl2_pmu/inner_acquire_block_btot/
                 -e /sifive_pl2_pmu/inner_acquire_block_ntob/
                 -e /sifive_pl2_pmu/inner_acquire_block_ntot/ ls

Performance counter stats for 'CPU(s) 0':

                300      sifive_pl2_pmu/inner_acquire_block_btot/
              17801      sifive_pl2_pmu/inner_acquire_block_ntob/
               5253      sifive_pl2_pmu/inner_acquire_block_ntot/
        0.088917326 seconds time elapsed
$ perf stat -C 0 -e /sifive_pl2_pmu/event=0x10001/
                 -e /sifive_pl2_pmu/event=0x4001/
                 -e /sifive_pl2_pmu/event=0x8001/ ls

Performance counter stats for 'CPU(s) 0':

                251      sifive_pl2_pmu/event=0x10001/
               2620      sifive_pl2_pmu/event=0x4001/
                644      sifive_pl2_pmu/event=0x8001/
        0.092827110 seconds time elapsed

---

[...]

Quoted 8 lines

drivers/soc/sifive/sifive_pl2_pmu.c line 617

Quoted 5 lines
drivers/soc/sifive/sifive_pl2_pmu.c new file +5 -0
+int sifive_pl2_pmu_probe(struct device_node  *pl2_node,
+                      void __iomem *pl2_base, int cpu)
+{
+     struct sifive_pl2_pmu_event *ptr = per_cpu_ptr(&sifive_pl2_pmu_event, cpu);
+     int ret = -EINVAL;

Nit: no need to init

OK, I will fix it in v2.

Quoted 31 lines
Quoted 31 lines
drivers/soc/sifive/sifive_pl2_pmu.c new file +31 -0
+
+     /* Get counter numbers. */
+     ret = of_property_read_u32(pl2_node, "sifive,perfmon-counters", &ptr->counters);
+     if (ret) {
+             pr_err("Not found sifive,perfmon-counters property\n");
+             goto early_err;
+     }
+     pr_info("perfmon-counters: %d for CPU %d\n", ptr->counters, cpu);
+
+     /* Allocate perf_event. */
+     ptr->events = kcalloc(ptr->counters, sizeof(struct perf_event), GFP_KERNEL);
+     if (!ptr->events)
+             return -ENOMEM;
+
+     ptr->event_select_base = pl2_base + SIFIVE_PL2_SELECT_BASE_OFFSET;
+     ptr->event_counter_base = pl2_base + SIFIVE_PL2_COUNTER_BASE_OFFSET;
+
+     if (!pl2pmu_init_done) {
+             ret = perf_pmu_register(sifive_pl2_pmu.pmu, sifive_pl2_pmu.pmu->name, -1);
+             if (ret) {
+                     cpuhp_state_remove_instance(CPUHP_AP_PERF_RISCV_SIFIVE_PL2_PMU_ONLINE,
+                                                 &sifive_pl2_pmu.node);
+                     pr_err("Failed to register sifive_pl2_pmu.pmu: %d\n", ret);
+             }
+             sifive_pl2_pmu_pm_init();
+             pl2pmu_init_done = true;
+     }
+
+     return 0;
+
+early_err:
Quoted 8 lines

drivers/soc/sifive/sifive_pl2_pmu.c line 654

Quoted 6 lines
drivers/soc/sifive/sifive_pl2_pmu.c new file +6 -0
+     return ret;
+}
+
+int sifive_pl2_pmu_init(void)
+{
+     int ret = 0;

Nit: no need to init

OK, I will fix it in v2.

Quoted 17 lines
Quoted 5 lines
drivers/soc/sifive/sifive_pl2_pmu.c new file +4 -0
+
+     ret = cpuhp_setup_state_multi(CPUHP_AP_PERF_RISCV_SIFIVE_PL2_PMU_ONLINE,
+                                   "perf/sifive/pl2pmu:online",
+                                   sifive_pl2_pmu_online_cpu,

drivers/soc/sifive/sifive_pl2_pmu.c line 668

Quoted 10 lines
drivers/soc/sifive/sifive_pl2_pmu.c new file +10 -0
+                                   sifive_pl2_pmu_offline_cpu);
+     if (ret)
+             pr_err("Failed to register CPU hotplug notifier %d\n", ret);
+
+     ret = cpuhp_state_add_instance(CPUHP_AP_PERF_RISCV_SIFIVE_PL2_PMU_ONLINE,
+                                    &sifive_pl2_pmu.node);
+     if (ret)
+             pr_err("Failed to add hotplug instance: %d\n", ret);
+
+     return ret;

Nit: return 0;

OK, I will fix it in v2.

Thanks for your review.

Best regards,
Eric Lin

Quoted 5 lines
Quoted 2 lines

+}

[...]

author
#18 lore raw

PATCH 3/3 dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

In reply to Eric Lin

This add YAML DT binding documentation for SiFive Private L2 cache controller

---
 .../bindings/riscv/sifive,pL2Cache0.yaml      | 81 +++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +81 -0
new file mode 100644
index 000000000000..b5d8d4a39dde
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (C) 2023 SiFive, Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/riscv/sifive,pL2Cache0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SiFive Private L2 Cache Controller
+
+maintainers:
+  - Greentime Hu  <[email protected]>
+  - Eric Lin      <[email protected]>
+
+description:
+  The SiFive Private L2 Cache Controller is per hart and communicates with both the upstream
+  L1 caches and downstream L3 cache or memory, enabling a high-performance cache subsystem.
+  All the properties in ePAPR/DeviceTree specification applies for this platform.
+
+allOf:
+  - $ref: /schemas/cache-controller.yaml#
+
+select:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1
+
+  required:
+    - compatible
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1
+
+  cache-block-size:
+    const: 64
+
+  cache-level:
+    const: 2
+
+  cache-sets:
+    const: 512
+
+  cache-size:
+    const: 262144
+
+  cache-unified: true
+
+  reg:
+    maxItems: 1
+
+  next-level-cache: true
+
+additionalProperties: false
+
+required:
+  - compatible
+  - cache-block-size
+  - cache-level
+  - cache-sets
+  - cache-size
+  - cache-unified
+  - reg
+
+examples:
+  - |
+    pl2@10104000 {
+        compatible = "sifive,pL2Cache0";
+        cache-block-size = <64>;
+        cache-level = <2>;
+        cache-sets = <512>;
+        cache-size = <262144>;
+        cache-unified;
+        reg = <0x10104000 0x4000>;
+        next-level-cache = <&L4>;
+    };
Signature · 7 lines
2.40.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#19 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

Hey Eric,

Quoted 6 lines · Eric Lin

This add YAML DT binding documentation for SiFive Private L2 cache controller

Firstly, bindings need to come before the driver using them.

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml

Quoted 10 lines
---
 .../bindings/riscv/sifive,pL2Cache0.yaml      | 81 +++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +0 -0
new file mode 100644
index 000000000000..b5d8d4a39dde

Cache bindings have moved to devicetree/bindings/cache.

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 12

Quoted 13 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +12 -0
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (C) 2023 SiFive, Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/riscv/sifive,pL2Cache0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SiFive Private L2 Cache Controller
+
+maintainers:
+  - Greentime Hu  <[email protected]>
+  - Eric Lin      <[email protected]>

Drop the alignment here please.

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 17

Quoted 5 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +5 -0
+
+description:
+  The SiFive Private L2 Cache Controller is per hart and communicates with both the upstream
+  L1 caches and downstream L3 cache or memory, enabling a high-performance cache subsystem.
+  All the properties in ePAPR/DeviceTree specification applies for this platform.

Please wrap before 80 characters.

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 28

Quoted 11 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +11 -0
+
+allOf:
+  - $ref: /schemas/cache-controller.yaml#
+
+select:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

Why is this select: required?

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 38

Quoted 9 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +9 -0
+  required:
+    - compatible
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

What is the difference between these? (and drop the caps please)

Should this also not fall back to "cache"?

Quoted 24 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +24 -0
+
+  cache-block-size:
+    const: 64
+
+  cache-level:
+    const: 2
+
+  cache-sets:
+    const: 512
+
+  cache-size:
+    const: 262144
+
+  cache-unified: true
+
+  reg:
+    maxItems: 1
+
+  next-level-cache: true
+
+additionalProperties: false
+
+required:
+  - compatible

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 72

Quoted 10 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +10 -0
+  - cache-block-size
+  - cache-level
+  - cache-sets
+  - cache-size
+  - cache-unified
+  - reg
+
+examples:
+  - |
+    pl2@10104000 {

cache-controller@

Cheers,
Conor.

Quoted 12 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +9 -0
+        compatible = "sifive,pL2Cache0";
+        cache-block-size = <64>;
+        cache-level = <2>;
+        cache-sets = <512>;
+        cache-size = <262144>;
+        cache-unified;
+        reg = <0x10104000 0x4000>;
+        next-level-cache = <&L4>;
+    };
Signature · 1 line
2.40.1
#20 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

Quoted 75 lines · Conor Dooley

Hey Eric,

Quoted 6 lines · Eric Lin

This add YAML DT binding documentation for SiFive Private L2 cache controller

Firstly, bindings need to come before the driver using them.

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml

Quoted 10 lines
---
  .../bindings/riscv/sifive,pL2Cache0.yaml      | 81 +++++++++++++++++++
  1 file changed, 81 insertions(+)

create mode 100644 Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +0 -0
new file mode 100644
index 000000000000..b5d8d4a39dde

Cache bindings have moved to devicetree/bindings/cache.

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 12

Quoted 13 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +12 -0
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (C) 2023 SiFive, Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/riscv/sifive,pL2Cache0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SiFive Private L2 Cache Controller
+
+maintainers:
+  - Greentime Hu  <[email protected]>
+  - Eric Lin      <[email protected]>

Drop the alignment here please.

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 17

Quoted 5 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +5 -0
+
+description:
+  The SiFive Private L2 Cache Controller is per hart and communicates with both the upstream
+  L1 caches and downstream L3 cache or memory, enabling a high-performance cache subsystem.
+  All the properties in ePAPR/DeviceTree specification applies for this platform.

Please wrap before 80 characters.

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 28

Quoted 11 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +11 -0
+
+allOf:
+  - $ref: /schemas/cache-controller.yaml#
+
+select:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

Why is this select: required?

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 38

Quoted 9 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +9 -0
+  required:
+    - compatible
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

What is the difference between these? (and drop the caps please)

Quoted 1 line

Should this also not fall back to "cache"?

I thought cache is required as the last resort.
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#21 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

In reply to Conor Dooley

Hi Conor,

Quoted 4 lines · Conor Dooley

Hey Eric,

On Fri, Jun 16, 2023 at 02:32:10PM +0800, Eric Lin wrote:

Quoted 9 lines
Quoted 6 lines

This add YAML DT binding documentation for SiFive Private L2 cache controller

Firstly, bindings need to come before the driver using them.

OK, I'll fix it in v2.

Quoted 13 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml

Quoted 10 lines
---
 .../bindings/riscv/sifive,pL2Cache0.yaml      | 81 +++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +0 -0
new file mode 100644
index 000000000000..b5d8d4a39dde

Cache bindings have moved to devicetree/bindings/cache.

Quoted 16 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 12

Quoted 13 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +12 -0
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (C) 2023 SiFive, Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/riscv/sifive,pL2Cache0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SiFive Private L2 Cache Controller
+
+maintainers:
+  - Greentime Hu  <[email protected]>
+  - Eric Lin      <[email protected]>

Drop the alignment here please.

OK, I'll fix it in v2.

Quoted 8 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 17

Quoted 5 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +5 -0
+
+description:
+  The SiFive Private L2 Cache Controller is per hart and communicates with both the upstream
+  L1 caches and downstream L3 cache or memory, enabling a high-performance cache subsystem.
+  All the properties in ePAPR/DeviceTree specification applies for this platform.

Please wrap before 80 characters.

OK, I'll fix it in v2.

Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +5 -0
+
+allOf:
+  - $ref: /schemas/cache-controller.yaml#
+
+select:
Quoted 9 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 28

Quoted 6 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +6 -0
+  properties:
+    compatible:
+      contains:
+        enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

Why is this select: required?

OK, I'll fix it in v2.

Quoted 11 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 38

Quoted 9 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +9 -0
+  required:
+    - compatible
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

What is the difference between these? (and drop the caps please)

The pL2Cache1 has minor changes in hardware, but it can use the same pl2 cache driver.
OK, I'll drop the caps in v2.

Quoted 3 lines

Should this also not fall back to "cache"?

Yes, I'll fix it in v2.

Quoted 28 lines
Quoted 28 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +28 -0
+
+  cache-block-size:
+    const: 64
+
+  cache-level:
+    const: 2
+
+  cache-sets:
+    const: 512
+
+  cache-size:
+    const: 262144
+
+  cache-unified: true
+
+  reg:
+    maxItems: 1
+
+  next-level-cache: true
+
+additionalProperties: false
+
+required:
+  - compatible
+  - cache-block-size
+  - cache-level
+  - cache-sets
+  - cache-size
Quoted 9 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 72

Quoted 6 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +6 -0
+  - cache-unified
+  - reg
+
+examples:
+  - |
+    pl2@10104000 {

cache-controller@

OK, I'll fix it in v2.
Thanks for the review.

Best Regards,
Eric Lin.

Quoted 15 lines

Cheers,
Conor.

Quoted 12 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +9 -1
+        compatible = "sifive,pL2Cache0";
+        cache-block-size = <64>;
+        cache-level = <2>;
+        cache-sets = <512>;
+        cache-size = <262144>;
+        cache-unified;
+        reg = <0x10104000 0x4000>;
+        next-level-cache = <&L4>;
+    };
--

2.40.1

#22 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

In reply to Eric Lin
Quoted 24 lines · Eric Lin

This add YAML DT binding documentation for SiFive Private L2 cache controller

---
 .../bindings/riscv/sifive,pL2Cache0.yaml      | 81 +++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +7 -0
new file mode 100644
index 000000000000..b5d8d4a39dde
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (C) 2023 SiFive, Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/riscv/sifive,pL2Cache0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 17

Quoted 10 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +10 -0
+title: SiFive Private L2 Cache Controller
+
+maintainers:
+  - Greentime Hu  <[email protected]>
+  - Eric Lin      <[email protected]>
+
+description:
+  The SiFive Private L2 Cache Controller is per hart and communicates with both the upstream
+  L1 caches and downstream L3 cache or memory, enabling a high-performance cache subsystem.
+  All the properties in ePAPR/DeviceTree specification applies for this platform.

Drop the last sentence. Why specification would not apply?

Quoted 8 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +8 -0
+
+allOf:
+  - $ref: /schemas/cache-controller.yaml#
+
+select:
+  properties:
+    compatible:
+      contains:

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 35

Quoted 10 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +10 -0
+        enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache
+
+  required:
+    - compatible
+
+properties:
+  compatible:
+    items:

You have only one item, so no need for items... unless you just missed proper fallback.

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 38

Quoted 3 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +3 -0
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

What is "0" and "1" here? What do these compatibles represent? Why they do not have any SoC related part?

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 50

Quoted 12 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +12 -0
+
+  cache-block-size:
+    const: 64
+
+  cache-level:
+    const: 2
+
+  cache-sets:
+    const: 512
+
+  cache-size:
+    const: 262144

Are you sure? So all private L2 cache controllers will have fixed size of cache?

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 61

Quoted 11 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +11 -0
+
+  cache-unified: true
+
+  reg:
+    maxItems: 1
+
+  next-level-cache: true
+
+additionalProperties: false
+
+required:

required: goes before additionalProperties:.

Best regards,
Krzysztof

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author
#23 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

Hi Krzysztof,

Quoted 30 lines · Krzysztof Kozlowski
Quoted 28 lines · Eric Lin

This add YAML DT binding documentation for SiFive Private L2 cache controller

---
 .../bindings/riscv/sifive,pL2Cache0.yaml      | 81 +++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +11 -0
new file mode 100644
index 000000000000..b5d8d4a39dde
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (C) 2023 SiFive, Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/riscv/sifive,pL2Cache0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SiFive Private L2 Cache Controller
+
+maintainers:
+  - Greentime Hu  <[email protected]>
Quoted 9 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 17

Quoted 6 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +6 -0
+  - Eric Lin      <[email protected]>
+
+description:
+  The SiFive Private L2 Cache Controller is per hart and communicates with both the upstream
+  L1 caches and downstream L3 cache or memory, enabling a high-performance cache subsystem.
+  All the properties in ePAPR/DeviceTree specification applies for this platform.

Drop the last sentence. Why specification would not apply?

OK, I'll drop it in v2.

Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +14 -0
+
+allOf:
+  - $ref: /schemas/cache-controller.yaml#
+
+select:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache
+
+  required:
+    - compatible
Quoted 8 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 35

Quoted 4 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +4 -0
+
+properties:
+  compatible:
+    items:

You have only one item, so no need for items... unless you just missed proper fallback.

OK, I'll fix it in v2.

Quoted 7 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 38

Quoted 4 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +3 -0
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

What is "0" and "1" here? What do these compatibles represent? Why they do not have any SoC related part?

The pL2Cache1 has minor changes in hardware, but it can use the same pl2 cache driver.
May I ask, what do you mean about the SoC-related part? Thanks.

Quoted 16 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 50

Quoted 13 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +12 -0
+
+  cache-block-size:
+    const: 64
+
+  cache-level:
+    const: 2
+
+  cache-sets:
+    const: 512
+
+  cache-size:
+    const: 262144

Are you sure? So all private L2 cache controllers will have fixed size of cache?

The private L2 cache controllers will have different sizes. OK, I'll fix in v2.

Quoted 15 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 61

Quoted 12 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +11 -0
+
+  cache-unified: true
+
+  reg:
+    maxItems: 1
+
+  next-level-cache: true
+
+additionalProperties: false
+
+required:

required: goes before additionalProperties:.

OK, I'll fix it in v2.
Thanks for the review.

Best Regards,
Eric Lin.

Quoted 4 lines

Best regards,
Krzysztof

#24 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

Quoted 75 lines · Eric Lin

Hi Krzysztof,

Quoted 30 lines · Krzysztof Kozlowski
Quoted 28 lines · Eric Lin

This add YAML DT binding documentation for SiFive Private L2 cache controller

---
 .../bindings/riscv/sifive,pL2Cache0.yaml      | 81 +++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +11 -0
new file mode 100644
index 000000000000..b5d8d4a39dde
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (C) 2023 SiFive, Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/riscv/sifive,pL2Cache0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SiFive Private L2 Cache Controller
+
+maintainers:
+  - Greentime Hu  <[email protected]>
Quoted 9 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 17

Quoted 6 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +6 -0
+  - Eric Lin      <[email protected]>
+
+description:
+  The SiFive Private L2 Cache Controller is per hart and communicates with both the upstream
+  L1 caches and downstream L3 cache or memory, enabling a high-performance cache subsystem.
+  All the properties in ePAPR/DeviceTree specification applies for this platform.

Drop the last sentence. Why specification would not apply?

OK, I'll drop it in v2.

Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +14 -0
+
+allOf:
+  - $ref: /schemas/cache-controller.yaml#
+
+select:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache
+
+  required:
+    - compatible
Quoted 8 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 35

Quoted 4 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +4 -0
+
+properties:
+  compatible:
+    items:

You have only one item, so no need for items... unless you just missed proper fallback.

OK, I'll fix it in v2.

Quoted 5 lines
Quoted 4 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +3 -0
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1
Quoted 5 lines
Quoted 2 lines

What is "0" and "1" here? What do these compatibles represent? Why they do not have any SoC related part?

The pL2Cache1 has minor changes in hardware, but it can use the same pl2 cache driver.

Then why aren't they compatible?

Quoted 1 line

May I ask, what do you mean about the SoC-related part? Thanks.

This is part of a SoC, right? We expect SoC blocks to have compatible based on the SoC.

Best regards,
Krzysztof

author
#25 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

Hi Krzysztof,

Quoted 77 lines · Krzysztof Kozlowski
Quoted 75 lines · Eric Lin

Hi Krzysztof,

Quoted 30 lines · Krzysztof Kozlowski
Quoted 28 lines · Eric Lin

This add YAML DT binding documentation for SiFive Private L2 cache controller

---
 .../bindings/riscv/sifive,pL2Cache0.yaml      | 81 +++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +11 -0
new file mode 100644
index 000000000000..b5d8d4a39dde
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (C) 2023 SiFive, Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/riscv/sifive,pL2Cache0.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SiFive Private L2 Cache Controller
+
+maintainers:
+  - Greentime Hu  <[email protected]>
Quoted 9 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 17

Quoted 6 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +6 -0
+  - Eric Lin      <[email protected]>
+
+description:
+  The SiFive Private L2 Cache Controller is per hart and communicates with both the upstream
+  L1 caches and downstream L3 cache or memory, enabling a high-performance cache subsystem.
+  All the properties in ePAPR/DeviceTree specification applies for this platform.

Drop the last sentence. Why specification would not apply?

OK, I'll drop it in v2.

Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +14 -0
+
+allOf:
+  - $ref: /schemas/cache-controller.yaml#
+
+select:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache
+
+  required:
+    - compatible
Quoted 8 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 35

Quoted 4 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +4 -0
+
+properties:
+  compatible:
+    items:

You have only one item, so no need for items... unless you just missed proper fallback.

OK, I'll fix it in v2.

Quoted 5 lines
Quoted 4 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +3 -0
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

What is "0" and "1" here? What do these compatibles represent? Why they do not have any SoC related part?

The pL2Cache1 has minor changes in hardware, but it can use the same pl2 cache driver.

Then why aren't they compatible?

The pL2Cache1 has removed some unused bits in the register compared to pl2Cache0.
From the hardware perspective, they are not compatible but they can share the same pl2 cache driver in software.
Thus, we would like to keep both. It would be great if you can provide some suggestions. Thanks.

Best Regards,
Eric Lin.

Quoted 10 lines
Quoted 1 line

May I ask, what do you mean about the SoC-related part? Thanks.

This is part of a SoC, right? We expect SoC blocks to have compatible based on the SoC.

Best regards,
Krzysztof

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#26 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

Quoted 11 lines · Eric Lin
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 38

Quoted 4 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +3 -0
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

What is "0" and "1" here? What do these compatibles represent? Why they do not have any SoC related part?

The pL2Cache1 has minor changes in hardware, but it can use the same pl2 cache driver.

Quoted 7 lines
Quoted 2 lines

Then why aren't they compatible?

The pL2Cache1 has removed some unused bits in the register compared to pl2Cache0.
From the hardware perspective, they are not compatible but they can share the same pl2 cache driver in software.

So they are compatible... If they were not compatible, you wouldn't be able to use the same match in the driver.

Quoted 2 lines

Thus, we would like to keep both. It would be great if you can provide some suggestions. Thanks.

I propose to make them compatible, like every other piece of SoC. I don't see any benefit of having them separate.

Best regards,
Krzysztof

author
#27 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

Quoted 21 lines · Krzysztof Kozlowski
Quoted 11 lines · Eric Lin
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml line 38

Quoted 4 lines
Documentation/devicetree/bindings/riscv/sifive,pL2Cache0.yaml new file +3 -0
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

What is "0" and "1" here? What do these compatibles represent? Why they do not have any SoC related part?

The pL2Cache1 has minor changes in hardware, but it can use the same pl2 cache driver.

Quoted 7 lines
Quoted 2 lines

Then why aren't they compatible?

The pL2Cache1 has removed some unused bits in the register compared to pl2Cache0.
From the hardware perspective, they are not compatible but they can share the same pl2 cache driver in software.

Quoted 9 lines

So they are compatible... If they were not compatible, you wouldn't be able to use the same match in the driver.

Quoted 2 lines

Thus, we would like to keep both. It would be great if you can provide some suggestions. Thanks.

I propose to make them compatible, like every other piece of SoC. I don't see any benefit of having them separate.

Hi Krzysztof,

Sorry for the late reply.
The pl2 cache is our internal platform IP and is not part of any SoC.

The reason why this driver is compatible with the hardware "pl2cache0" and hardware "pl2cache1" is that it doesn't program the different parts of the config register
However, our internal software (e.g., bare-metal software) will program these different parts, so it needs to rely on the different compatible string to identify the hardware.

Additionally, we would like the compatible strings to reflect which hardware is being used Thanks.

Best regards,
Eric Lin

Quoted 3 lines

Best regards,
Krzysztof

#28 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

Quoted 37 lines · Eric Lin
Quoted 21 lines · Krzysztof Kozlowski
Quoted 11 lines · Eric Lin
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

What is "0" and "1" here? What do these compatibles represent? Why they do not have any SoC related part?

The pL2Cache1 has minor changes in hardware, but it can use the same pl2 cache driver.

Quoted 7 lines
Quoted 2 lines

Then why aren't they compatible?

The pL2Cache1 has removed some unused bits in the register compared to pl2Cache0.
From the hardware perspective, they are not compatible but they can share the same pl2 cache driver in software.

Quoted 9 lines

So they are compatible... If they were not compatible, you wouldn't be able to use the same match in the driver.

Quoted 2 lines

Thus, we would like to keep both. It would be great if you can provide some suggestions. Thanks.

I propose to make them compatible, like every other piece of SoC. I don't see any benefit of having them separate.

Hi Krzysztof,

Sorry for the late reply.
The pl2 cache is our internal platform IP and is not part of any SoC.

Quoted 6 lines

The reason why this driver is compatible with the hardware "pl2cache0" and hardware "pl2cache1" is that it doesn't program the different parts of the config register
However, our internal software (e.g., bare-metal software) will program these different parts, so it needs to rely on the different compatible string to identify the hardware.

Additionally, we would like the compatible strings to reflect which hardware is being used Thanks.

I don't understand how does it contradicts anything I said. So you do agree with me? Or what?

Best regards,
Krzysztof

#29 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

Quoted 40 lines · Krzysztof Kozlowski
Quoted 39 lines · Eric Lin
Quoted 21 lines · Krzysztof Kozlowski
Quoted 11 lines · Eric Lin
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

What is "0" and "1" here? What do these compatibles represent? Why they do not have any SoC related part?

The pL2Cache1 has minor changes in hardware, but it can use the same pl2 cache driver.

Quoted 7 lines
Quoted 2 lines

Then why aren't they compatible?

The pL2Cache1 has removed some unused bits in the register compared to pl2Cache0.
From the hardware perspective, they are not compatible but they can share the same pl2 cache driver in software.

Quoted 9 lines

So they are compatible... If they were not compatible, you wouldn't be able to use the same match in the driver.

Quoted 2 lines

Thus, we would like to keep both. It would be great if you can provide some suggestions. Thanks.

I propose to make them compatible, like every other piece of SoC. I don't see any benefit of having them separate.

Sorry for the late reply.
The pl2 cache is our internal platform IP and is not part of any SoC.

The reason why this driver is compatible with the hardware "pl2cache0" and hardware "pl2cache1" is that it doesn't program the different parts of the config register
However, our internal software (e.g., bare-metal software) will program these different parts, so it needs to rely on the different compatible string to identify the hardware.

Quoted 4 lines
Quoted 1 line

Additionally, we would like the compatible strings to reflect which hardware is being used Thanks.

I don't understand how does it contradicts anything I said. So you do agree with me? Or what?

I probably should've been keeping a closer eye here, sorry.

I assume what Krzysztof means is why do you permit both "sifive,pL2Cache0" and "sifive,pL2Cache1" appearing in isolation. IOW, both of
compatible = "sifive,pl2cache0";
and
compatible = "sifive,pl2cache1";
are valid in your binding.

The hardware for both might be different, and their full featuresets may be incompatible, but they implement a compatible subset of features. I would expect that the following would be the permitted compatible setups:
compatible = "sifive,pl2cache0";
and
compatible = "sifive,pl2cache1", "sifive,pl2cache0";

A consumer of the DT that does care for the differences should be looking for the specific compatible, and OS code that does not care can always bind to the "0" version.

Do the "0" & "1" here refer to the IP version, as in sifive-blocks-ip-versioning.txt? I didn't think the compatibles containing those IP versions were supposed to appear in isolation, without a soc-specific one?

Thanks,
Conor.

author
#30 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

Hi Conor,

Quoted 64 lines · Conor Dooley
Quoted 40 lines · Krzysztof Kozlowski
Quoted 39 lines · Eric Lin
Quoted 21 lines · Krzysztof Kozlowski
Quoted 11 lines · Eric Lin
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

What is "0" and "1" here? What do these compatibles represent? Why they do not have any SoC related part?

The pL2Cache1 has minor changes in hardware, but it can use the same pl2 cache driver.

Quoted 7 lines
Quoted 2 lines

Then why aren't they compatible?

The pL2Cache1 has removed some unused bits in the register compared to pl2Cache0.
From the hardware perspective, they are not compatible but they can share the same pl2 cache driver in software.

Quoted 9 lines

So they are compatible... If they were not compatible, you wouldn't be able to use the same match in the driver.

Quoted 2 lines

Thus, we would like to keep both. It would be great if you can provide some suggestions. Thanks.

I propose to make them compatible, like every other piece of SoC. I don't see any benefit of having them separate.

Sorry for the late reply.
The pl2 cache is our internal platform IP and is not part of any SoC.

The reason why this driver is compatible with the hardware "pl2cache0" and hardware "pl2cache1" is that it doesn't program the different parts of the config register
However, our internal software (e.g., bare-metal software) will program these different parts, so it needs to rely on the different compatible string to identify the hardware.

Quoted 4 lines
Quoted 1 line

Additionally, we would like the compatible strings to reflect which hardware is being used Thanks.

I don't understand how does it contradicts anything I said. So you do agree with me? Or what?

I probably should've been keeping a closer eye here, sorry.

I assume what Krzysztof means is why do you permit both "sifive,pL2Cache0" and "sifive,pL2Cache1" appearing in isolation. IOW, both of
compatible = "sifive,pl2cache0";
and
compatible = "sifive,pl2cache1";
are valid in your binding.

The hardware for both might be different, and their full featuresets may be incompatible, but they implement a compatible subset of features. I would expect that the following would be the permitted compatible setups:
compatible = "sifive,pl2cache0";
and
compatible = "sifive,pl2cache1", "sifive,pl2cache0";

Quoted 4 lines

A consumer of the DT that does care for the differences should be looking for the specific compatible, and OS code that does not care can always bind to the "0" version.

Yes, but I think the proper compatible string for hw pl2cache0 and hw pl2cache1 should be as follows:
hw pl2cache0 -> compatible = "sifive,pl2cache0","sifive,pl2cache1"; hw pl2cache1 -> compatible = "sifive,pl2cache1";

Since the hw pl2cache0 implements more features than hw pl2cache1, it can be compatible with the pl2cache1 driver.
However, hw pl2cache1 only implements a sub-feature of hw pl2cache0, so it cannot be compatible with the pl2cache0 driver. Thus, I'll keep only the compatible = "sifive,pl2cache1". in the driver and dt-binding. Thanks for the suggestions.

Quoted 5 lines

Do the "0" & "1" here refer to the IP version, as in sifive-blocks-ip-versioning.txt? I didn't think the compatibles containing those IP versions were supposed to appear in isolation, without a soc-specific one?

Yes, I think they refer to IP versions. OK, I'll fix it in v2. Thanks for the review.

Best regards,
Eric Lin

Quoted 2 lines

Thanks,
Conor.

author
#31 lore raw

Re: [PATCH 3/3] dt-bindings: riscv: sifive: Add SiFive Private L2 cache controller

In reply to Krzysztof Kozlowski

Hi Krzysztof,

Quoted 44 lines · Krzysztof Kozlowski
Quoted 42 lines · Eric Lin
Quoted 21 lines · Krzysztof Kozlowski
Quoted 11 lines · Eric Lin
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+      - enum:
+          - sifive,pL2Cache0
+          - sifive,pL2Cache1

What is "0" and "1" here? What do these compatibles represent? Why they do not have any SoC related part?

The pL2Cache1 has minor changes in hardware, but it can use the same pl2 cache driver.

Quoted 7 lines
Quoted 2 lines

Then why aren't they compatible?

The pL2Cache1 has removed some unused bits in the register compared to pl2Cache0.
From the hardware perspective, they are not compatible but they can share the same pl2 cache driver in software.

Quoted 9 lines

So they are compatible... If they were not compatible, you wouldn't be able to use the same match in the driver.

Quoted 2 lines

Thus, we would like to keep both. It would be great if you can provide some suggestions. Thanks.

I propose to make them compatible, like every other piece of SoC. I don't see any benefit of having them separate.

Hi Krzysztof,

Sorry for the late reply.
The pl2 cache is our internal platform IP and is not part of any SoC.

The reason why this driver is compatible with the hardware "pl2cache0" and hardware "pl2cache1" is that it doesn't program the different parts of the config register
However, our internal software (e.g., bare-metal software) will program these different parts, so it needs to rely on the different compatible string to identify the hardware.

Quoted 5 lines
Quoted 1 line

Additionally, we would like the compatible strings to reflect which hardware is being used Thanks.

I don't understand how does it contradicts anything I said. So you do agree with me? Or what?

Thanks for your suggestions. OK, I'll fix it in v2.

Best regards,
Eric Lin

Quoted 3 lines

Best regards,
Krzysztof

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv