Skip to contentSkip to conversation

Add CPPC extension support in OpenSBI

RFC PATCH Superseded Sunil V L 1 participant 5 messages Mar 27, 2023

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Sunil V L

author
#0 lore raw

v3 cover Add CPPC extension support in OpenSBI

The latest proposal of SBI CPPC extension can be found at:
https://lists.riscv.org/g/tech-prs/message/301

This series implements SBI CPPC extension support in OpenSBI as-per above draft proposal.

To test these patches,
Qemu patches can be found in,
aia_plic_cppc_v1 branch at: https://github.com/vlsunil/qemu.git
Linux patches can be found in
aia_plic_cppc_v1 branch at: https://github.com/vlsunil/linux.git

These OpenSBI patches can also be found in aia_plic_cppc_v3 branch at: https://github.com/vlsunil/opensbi.git

Changes since v2:
1) Updated probe, read/write functions as per Drew's feedback to split between common and platform specific functions.

Changes since v1:
1) Addresses Drew's feedback
a) Updated common functions to handle most of the errors.
b) Added is_reserved, readable, writable helpers as per Drew's feedback.
c) Updated macro name to SBI_CPPC_ENERGY_PERF_PREFERENCE
2) Updated RB tags

Sunil V L (4):
include: Add defines for SBI CPPC extension
lib: sbi: Implement SBI CPPC extension
lib: sbi: Print the CPPC device name
NOT_FOR_MERGE: Add test code to emulate CPPC extension

 include/sbi/sbi_cppc.h            |  37 ++++++
 include/sbi/sbi_ecall_interface.h |  34 ++++++
 lib/sbi/Kconfig                   |   4 +
 lib/sbi/objects.mk                |   4 +
 lib/sbi/sbi_cppc.c                | 156 ++++++++++++++++++++++++
 lib/sbi/sbi_ecall_cppc.c          |  63 ++++++++++
 lib/sbi/sbi_init.c                |   5 +
 platform/generic/objects.mk       |   1 +
 platform/generic/platform.c       |   6 +
 platform/generic/test_cppc.c      | 196 ++++++++++++++++++++++++++++++
 10 files changed, 506 insertions(+)
 create mode 100644 include/sbi/sbi_cppc.h
 create mode 100644 lib/sbi/sbi_cppc.c
 create mode 100644 lib/sbi/sbi_ecall_cppc.c
 create mode 100644 platform/generic/test_cppc.c
Signature · 1 line
2.34.1
author
#1 lore raw

RFC PATCH v3 1/4 include: Add defines for SBI CPPC extension

Add SBI CPPC extension related defines to the
SBI ecall interface header.

---
 include/sbi/sbi_ecall_interface.h | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
include/sbi/sbi_ecall_interface.h +34 -0
index 4597358..dee2dd9 100644
@@ -31,6 +31,7 @@
 #define SBI_EXT_PMU				0x504D55
 #define SBI_EXT_DBCN				0x4442434E
 #define SBI_EXT_SUSP				0x53555350
+#define SBI_EXT_CPPC				0x43505043
 
 /* SBI function IDs for BASE extension*/
 #define SBI_EXT_BASE_GET_SPEC_VERSION		0x0
@@ -256,6 +257,39 @@ enum sbi_pmu_ctr_type {
 #define SBI_SUSP_SLEEP_TYPE_LAST		SBI_SUSP_SLEEP_TYPE_SUSPEND
 #define SBI_SUSP_PLATFORM_SLEEP_START		0x80000000
 
+/* SBI function IDs for CPPC extension */
+#define SBI_EXT_CPPC_PROBE			0x0
+#define SBI_EXT_CPPC_READ			0x1
+#define SBI_EXT_CPPC_READ_HI			0x2
+#define SBI_EXT_CPPC_WRITE			0x3
+
+enum sbi_cppc_reg_id {
+	SBI_CPPC_HIGHEST_PERF		= 0x00000000,
+	SBI_CPPC_NOMINAL_PERF		= 0x00000001,
+	SBI_CPPC_LOW_NON_LINEAR_PERF	= 0x00000002,
+	SBI_CPPC_LOWEST_PERF		= 0x00000003,
+	SBI_CPPC_GUARANTEED_PERF	= 0x00000004,
+	SBI_CPPC_DESIRED_PERF		= 0x00000005,
+	SBI_CPPC_MIN_PERF		= 0x00000006,
+	SBI_CPPC_MAX_PERF		= 0x00000007,
+	SBI_CPPC_PERF_REDUC_TOLERANCE	= 0x00000008,
+	SBI_CPPC_TIME_WINDOW		= 0x00000009,
+	SBI_CPPC_CTR_WRAP_TIME		= 0x0000000A,
+	SBI_CPPC_REFERENCE_CTR		= 0x0000000B,
+	SBI_CPPC_DELIVERED_CTR		= 0x0000000C,
+	SBI_CPPC_PERF_LIMITED		= 0x0000000D,
+	SBI_CPPC_ENABLE			= 0x0000000E,
+	SBI_CPPC_AUTO_SEL_ENABLE	= 0x0000000F,
+	SBI_CPPC_AUTO_ACT_WINDOW	= 0x00000010,
+	SBI_CPPC_ENERGY_PERF_PREFERENCE	= 0x00000011,
+	SBI_CPPC_REFERENCE_PERF		= 0x00000012,
+	SBI_CPPC_LOWEST_FREQ		= 0x00000013,
+	SBI_CPPC_NOMINAL_FREQ		= 0x00000014,
+	SBI_CPPC_ACPI_LAST		= SBI_CPPC_NOMINAL_FREQ,
+	SBI_CPPC_TRANSITION_LATENCY	= 0x80000000,
+	SBI_CPPC_NON_ACPI_LAST		= SBI_CPPC_TRANSITION_LATENCY,
+};
+
 /* SBI base specification related macros */
 #define SBI_SPEC_VERSION_MAJOR_OFFSET		24
 #define SBI_SPEC_VERSION_MAJOR_MASK		0x7f
Signature · 1 line
2.34.1
author
#2 lore raw

RFC PATCH v3 2/4 lib: sbi: Implement SBI CPPC extension

In reply to Sunil V L

Implement SBI CPPC extension. This extension is only available when OpenSBI platform provides a CPPC device to generic library.

---
 include/sbi/sbi_cppc.h   |  35 +++++++++
 lib/sbi/Kconfig          |   4 +
 lib/sbi/objects.mk       |   4 +
 lib/sbi/sbi_cppc.c       | 156 +++++++++++++++++++++++++++++++++++++++
 lib/sbi/sbi_ecall_cppc.c |  63 ++++++++++++++++
 5 files changed, 262 insertions(+)
 create mode 100644 include/sbi/sbi_cppc.h
 create mode 100644 lib/sbi/sbi_cppc.c
 create mode 100644 lib/sbi/sbi_ecall_cppc.c
include/sbi/sbi_cppc.h new file +35 -0
new file mode 100644
index 0000000..edf73f5
@@ -0,0 +1,35 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Ventana Micro Systems Inc.
+ *
+ */
+
+#ifndef __SBI_CPPC_H__
+#define __SBI_CPPC_H__
+
+#include <sbi/sbi_types.h>
+
+/** CPPC device */
+struct sbi_cppc_device {
+	/** Name of the CPPC device */
+	char name[32];
+
+	/** probe - returns register width if implemented, 0 otherwise */
+	int (*cppc_probe)(unsigned long reg);
+
+	/** read the cppc register*/
+	int (*cppc_read)(unsigned long reg, uint64_t *val);
+
+	/** write to the cppc register*/
+	int (*cppc_write)(unsigned long reg, uint64_t val);
+};
+
+int sbi_cppc_probe(unsigned long reg);
+int sbi_cppc_read(unsigned long reg, uint64_t *val);
+int sbi_cppc_write(unsigned long reg, uint64_t val);
+
+const struct sbi_cppc_device *sbi_cppc_get_device(void);
+void sbi_cppc_set_device(const struct sbi_cppc_device *dev);
+
+#endif
lib/sbi/Kconfig +4 -0
index 7eb3273..477775e 100644
@@ -34,6 +34,10 @@ config SBI_ECALL_DBCN
 	bool "Debug Console extension"
 	default y
 
+config SBI_ECALL_CPPC
+	bool "CPPC extension"
+	default y
+
 config SBI_ECALL_LEGACY
 	bool "SBI v0.1 legacy extensions"
 	default y
lib/sbi/objects.mk +4 -0
index 770238b..7d691c6 100644
@@ -43,6 +43,9 @@ libsbi-objs-$(CONFIG_SBI_ECALL_PMU) += sbi_ecall_pmu.o
 carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_DBCN) += ecall_dbcn
 libsbi-objs-$(CONFIG_SBI_ECALL_DBCN) += sbi_ecall_dbcn.o
 
+carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_CPPC) += ecall_cppc
+libsbi-objs-$(CONFIG_SBI_ECALL_CPPC) += sbi_ecall_cppc.o
+
 carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_LEGACY) += ecall_legacy
 libsbi-objs-$(CONFIG_SBI_ECALL_LEGACY) += sbi_ecall_legacy.o
 
@@ -74,3 +77,4 @@ libsbi-objs-y += sbi_tlb.o
 libsbi-objs-y += sbi_trap.o
 libsbi-objs-y += sbi_unpriv.o
 libsbi-objs-y += sbi_expected_trap.o
+libsbi-objs-y += sbi_cppc.o
lib/sbi/sbi_cppc.c new file +156 -0

156 lines not on this page · raw message

lib/sbi/sbi_ecall_cppc.c new file +63 -0

63 lines not on this page · raw message

Signature · 1 line
2.34.1
author
#3 lore raw

RFC PATCH v3 3/4 lib: sbi: Print the CPPC device name

In reply to Sunil V L

If CPPC device is registered by the platform, print its name.

---
 lib/sbi/sbi_init.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/sbi/sbi_init.c +5 -0
index ffa214c..fa89320 100644
@@ -12,6 +12,7 @@
 #include <sbi/riscv_barrier.h>
 #include <sbi/riscv_locks.h>
 #include <sbi/sbi_console.h>
+#include <sbi/sbi_cppc.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_ecall.h>
 #include <sbi/sbi_hart.h>
@@ -70,6 +71,7 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
 	const struct sbi_console_device *cdev;
 	const struct sbi_system_reset_device *srdev;
 	const struct sbi_system_suspend_device *susp_dev;
+	const struct sbi_cppc_device *cppc_dev;
 	const struct sbi_platform *plat = sbi_platform_ptr(scratch);
 
 	if (scratch->options & SBI_SCRATCH_NO_BOOT_PRINTS)
@@ -107,6 +109,9 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
 	susp_dev = sbi_system_suspend_get_device();
 	sbi_printf("Platform Suspend Device   : %s\n",
 		   (susp_dev) ? susp_dev->name : "---");
+	cppc_dev = sbi_cppc_get_device();
+	sbi_printf("Platform CPPC Device      : %s\n",
+		   (cppc_dev) ? cppc_dev->name : "---");
 
 	/* Firmware details */
 	sbi_printf("Firmware Base             : 0x%lx\n", scratch->fw_start);
Signature · 1 line
2.34.1
author
#4 lore raw

RFC PATCH v3 4/4 NOT_FOR_MERGE: Add test code to emulate CPPC extension

In reply to Sunil V L

This is a test code to emulate the CPPC extension and it is not for merge.

---
 include/sbi/sbi_cppc.h       |   2 +
 platform/generic/objects.mk  |   1 +
 platform/generic/platform.c  |   6 ++
 platform/generic/test_cppc.c | 196 +++++++++++++++++++++++++++++++++++
 4 files changed, 205 insertions(+)
 create mode 100644 platform/generic/test_cppc.c
include/sbi/sbi_cppc.h +2 -0
index edf73f5..f62d702 100644
@@ -32,4 +32,6 @@ int sbi_cppc_write(unsigned long reg, uint64_t val);
 const struct sbi_cppc_device *sbi_cppc_get_device(void);
 void sbi_cppc_set_device(const struct sbi_cppc_device *dev);
 
+int test_cppc_init(void);
+
 #endif
platform/generic/objects.mk +1 -0
index 136853e..d9eb959 100644
@@ -20,6 +20,7 @@ platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \
 # Objects to build
 platform-objs-y += platform.o
 platform-objs-y += platform_override_modules.o
+platform-objs-$(CONFIG_SBI_ECALL_CPPC) += test_cppc.o
 
 # Blobs to build
 FW_TEXT_START=0x80000000
platform/generic/platform.c +6 -0
index eeefef4..ef85b70 100644
@@ -14,6 +14,7 @@
 #include <sbi/sbi_platform.h>
 #include <sbi/sbi_string.h>
 #include <sbi/sbi_system.h>
+#include <sbi/sbi_cppc.h>
 #include <sbi_utils/fdt/fdt_domain.h>
 #include <sbi_utils/fdt/fdt_fixup.h>
 #include <sbi_utils/fdt/fdt_helper.h>
@@ -166,6 +167,11 @@ static int generic_final_init(bool cold_boot)
 	if (!cold_boot)
 		return 0;
 
+#ifdef CONFIG_SBI_ECALL_CPPC
+	if (!generic_plat)
+		test_cppc_init();
+#endif
+
 	fdt = fdt_get_address();
 
 	fdt_cpu_fixup(fdt);
platform/generic/test_cppc.c new file +196 -0

196 lines not on this page · raw message

Signature · 1 line
2.34.1