Skip to contentSkip to conversation

RPMI and SBI MPXY support for OpenSBI

PATCH New Anup Patel 3 participants 23 messages Nov 29, 2024 – Dec 16, 2024 Arm/Allwinner sunXi SoC support

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

v2 cover RPMI and SBI MPXY support for OpenSBI

This series adds RPMI and SBI MPXY support for OpenSBI. The RPMI service groups supported include system reset, system suspend, HSM, CPPC, and clock. The RPMI clock serivice group is exposed to supervisor software as an MPXY channel.

These patches can also be found in the rpmi_mpxy_v2 branch at:
https://github.com/avpatel/opensbi.git

To test these patches, use the dev-upstream branch of the following repos:
* https://github.com/ventanamicro/qemu.git
* https://github.com/ventanamicro/linux.git

To enable QEMU RPMI emulation (using librpmi) for virt machine, use "virt,rpmi=on" as the QEMU machine name.

Changes since v1:
- Rebased on latest OpenSBI
- Use the recently introduced helpers for generic driver initialization
- Updated RPMI drivers to match the latest RPMI specification
- Don't support fixed number of channels in RPMI shared memory mailbox driver
- Added new patch9 for support RPMI HSM based FDT fixup
- Improved arrangment of barrier in __smq_rx() and __smq_tx()

Anup Patel (8):
lib: utils/mailbox: Add generic mailbox library
lib: utils/mailbox: Add simple FDT based mailbox framework
lib: utils: Add simple FDT based system suspend driver framework
lib: utils/fdt: Allow dynamic registration of FDT fixup callbacks
lib: utils: Add simple FDT based HSM driver framework
lib: utils: Add simple FDT based CPPC driver framework
lib: sbi: Implement SBI MPXY extension
lib: utils: Add simple FDT based MPXY driver framework

Rahul Pathak (5):
lib: Increase ROOT_REGION_MAX to accomodate more memregions lib/utils: Add RPMI messaging protocol and shared memory transport
support
lib/utils: reset: Add RPMI System Reset driver
lib: sbi: Add SBI Message Proxy (MPXY) framework
lib: utils/mpxy: Add RPMI client driver for MPXY

Subrahmanya Lingappa (4):
lib: utils/suspend: Add RPMI system suspend driver
lib: sbi: Add optional resume address to hart suspend
lib: utils/hsm: Add RPMI HSM driver
lib: utils/cppc: Add RPMI CPPC driver

 include/sbi/sbi_ecall_interface.h            |  12 +
 include/sbi/sbi_error.h                      |  15 +-
 include/sbi/sbi_hsm.h                        |   6 +-
 include/sbi/sbi_mpxy.h                       | 183 +++++
 include/sbi/sbi_platform.h                   |  17 +
 include/sbi_utils/cppc/fdt_cppc.h            |  26 +
 include/sbi_utils/fdt/fdt_fixup.h            |  15 +
 include/sbi_utils/hsm/fdt_hsm.h              |  26 +
 include/sbi_utils/mailbox/fdt_mailbox.h      |  35 +
 include/sbi_utils/mailbox/mailbox.h          | 180 +++++
 include/sbi_utils/mailbox/rpmi_mailbox.h     |  32 +
 include/sbi_utils/mailbox/rpmi_msgprot.h     | 607 +++++++++++++++
 include/sbi_utils/mpxy/fdt_mpxy.h            |  26 +
 include/sbi_utils/suspend/fdt_suspend.h      |  26 +
 lib/sbi/Kconfig                              |   3 +
 lib/sbi/objects.mk                           |   4 +
 lib/sbi/sbi_domain.c                         |   2 +-
 lib/sbi/sbi_ecall_mpxy.c                     |  68 ++
 lib/sbi/sbi_hsm.c                            |   6 +-
 lib/sbi/sbi_init.c                           |   6 +
 lib/sbi/sbi_mpxy.c                           | 698 +++++++++++++++++
 lib/utils/Kconfig                            |  10 +
 lib/utils/cppc/Kconfig                       |  19 +
 lib/utils/cppc/fdt_cppc.c                    |  22 +
 lib/utils/cppc/fdt_cppc_drivers.carray       |   3 +
 lib/utils/cppc/fdt_cppc_rpmi.c               | 377 +++++++++
 lib/utils/cppc/objects.mk                    |  14 +
 lib/utils/fdt/fdt_fixup.c                    |  33 +
 lib/utils/hsm/Kconfig                        |  19 +
 lib/utils/hsm/fdt_hsm.c                      |  22 +
 lib/utils/hsm/fdt_hsm_drivers.carray         |   3 +
 lib/utils/hsm/fdt_hsm_rpmi.c                 | 362 +++++++++
 lib/utils/hsm/objects.mk                     |  14 +
 lib/utils/mailbox/Kconfig                    |  29 +
 lib/utils/mailbox/fdt_mailbox.c              |  96 +++
 lib/utils/mailbox/fdt_mailbox_drivers.carray |   5 +
 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c   | 773 +++++++++++++++++++
 lib/utils/mailbox/mailbox.c                  | 138 ++++
 lib/utils/mailbox/objects.mk                 |  18 +
 lib/utils/mailbox/rpmi_mailbox.c             |  91 +++
 lib/utils/mpxy/Kconfig                       |  19 +
 lib/utils/mpxy/fdt_mpxy.c                    |  22 +
 lib/utils/mpxy/fdt_mpxy_drivers.carray       |   3 +
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c          | 442 +++++++++++
 lib/utils/mpxy/objects.mk                    |  14 +
 lib/utils/reset/Kconfig                      |   5 +
 lib/utils/reset/fdt_reset_rpmi.c             | 141 ++++
 lib/utils/reset/objects.mk                   |   3 +
 lib/utils/suspend/Kconfig                    |  19 +
 lib/utils/suspend/fdt_suspend.c              |  22 +
 lib/utils/suspend/fdt_suspend_drivers.carray |   3 +
 lib/utils/suspend/fdt_suspend_rpmi.c         | 138 ++++
 lib/utils/suspend/objects.mk                 |  14 +
 platform/generic/allwinner/sun20i-d1.c       |   2 +-
 platform/generic/configs/defconfig           |  12 +
 platform/generic/platform.c                  |  16 +
 56 files changed, 4903 insertions(+), 13 deletions(-)
 create mode 100644 include/sbi/sbi_mpxy.h
 create mode 100644 include/sbi_utils/cppc/fdt_cppc.h
 create mode 100644 include/sbi_utils/hsm/fdt_hsm.h
 create mode 100644 include/sbi_utils/mailbox/fdt_mailbox.h
 create mode 100644 include/sbi_utils/mailbox/mailbox.h
 create mode 100644 include/sbi_utils/mailbox/rpmi_mailbox.h
 create mode 100644 include/sbi_utils/mailbox/rpmi_msgprot.h
 create mode 100644 include/sbi_utils/mpxy/fdt_mpxy.h
 create mode 100644 include/sbi_utils/suspend/fdt_suspend.h
 create mode 100644 lib/sbi/sbi_ecall_mpxy.c
 create mode 100644 lib/sbi/sbi_mpxy.c
 create mode 100644 lib/utils/cppc/Kconfig
 create mode 100644 lib/utils/cppc/fdt_cppc.c
 create mode 100644 lib/utils/cppc/fdt_cppc_drivers.carray
 create mode 100644 lib/utils/cppc/fdt_cppc_rpmi.c
 create mode 100644 lib/utils/cppc/objects.mk
 create mode 100644 lib/utils/hsm/Kconfig
 create mode 100644 lib/utils/hsm/fdt_hsm.c
 create mode 100644 lib/utils/hsm/fdt_hsm_drivers.carray
 create mode 100644 lib/utils/hsm/fdt_hsm_rpmi.c
 create mode 100644 lib/utils/hsm/objects.mk
 create mode 100644 lib/utils/mailbox/Kconfig
 create mode 100644 lib/utils/mailbox/fdt_mailbox.c
 create mode 100644 lib/utils/mailbox/fdt_mailbox_drivers.carray
 create mode 100644 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
 create mode 100644 lib/utils/mailbox/mailbox.c
 create mode 100644 lib/utils/mailbox/objects.mk
 create mode 100644 lib/utils/mailbox/rpmi_mailbox.c
 create mode 100644 lib/utils/mpxy/Kconfig
 create mode 100644 lib/utils/mpxy/fdt_mpxy.c
 create mode 100644 lib/utils/mpxy/fdt_mpxy_drivers.carray
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
 create mode 100644 lib/utils/mpxy/objects.mk
 create mode 100644 lib/utils/reset/fdt_reset_rpmi.c
 create mode 100644 lib/utils/suspend/Kconfig
 create mode 100644 lib/utils/suspend/fdt_suspend.c
 create mode 100644 lib/utils/suspend/fdt_suspend_drivers.carray
 create mode 100644 lib/utils/suspend/fdt_suspend_rpmi.c
 create mode 100644 lib/utils/suspend/objects.mk
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v2 1/17 lib: Increase ROOT_REGION_MAX to accomodate more memregions

From: Rahul Pathak <[email protected]>

As more drivers adding memregions into root domain, the current static limit of ROOT_REGION_MAX is not sufficient. Increase the limit to accomodate more memregions.

---
 lib/sbi/sbi_domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sbi/sbi_domain.c +1 -1
index 7fdcf9d3..1cf7e2d8 100644
@@ -24,7 +24,7 @@ SBI_LIST_HEAD(domain_list);
 static u32 domain_count = 0;
 static bool domain_finalized = false;
 
-#define ROOT_REGION_MAX	16
+#define ROOT_REGION_MAX	32
 static u32 root_memregs_count = 0;
 
 struct sbi_domain root = {
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v2 2/17 lib: utils/mailbox: Add generic mailbox library

In reply to Anup Patel

Add generic mailbox library which is independent of hardware description format. The OpenSBI platform support or mailbox drivers can register mailbox controller instances which can be discovered and used by different mailbox client drivers. Each mailbox controller instance has a unique ID which can be used by mailbox client drivers for find the mailbox controller instance. The mailbox client drivers will typically request a mailbox channel from the mailbox controller and use it to do data transfer with the remote end of mailbox channel.

---
 include/sbi_utils/mailbox/mailbox.h | 180 ++++++++++++++++++++++++++++
 lib/utils/Kconfig                   |   2 +
 lib/utils/mailbox/Kconfig           |   9 ++
 lib/utils/mailbox/mailbox.c         | 138 +++++++++++++++++++++
 lib/utils/mailbox/objects.mk        |  10 ++
 5 files changed, 339 insertions(+)
 create mode 100644 include/sbi_utils/mailbox/mailbox.h
 create mode 100644 lib/utils/mailbox/Kconfig
 create mode 100644 lib/utils/mailbox/mailbox.c
 create mode 100644 lib/utils/mailbox/objects.mk
include/sbi_utils/mailbox/mailbox.h new file +180 -0
new file mode 100644
index 00000000..46fd8770
@@ -0,0 +1,180 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#ifndef __MAILBOX_H__
+#define __MAILBOX_H__
+
+#include <sbi/sbi_types.h>
+#include <sbi/sbi_list.h>
+#include <sbi/riscv_atomic.h>
+
+/** Representation of a mailbox channel */
+struct mbox_chan {
+	/** List head */
+	struct sbi_dlist node;
+	/** Pointer to the mailbox controller */
+	struct mbox_controller *mbox;
+	/**
+	 * Arguments (or parameters) to identify a mailbox channel
+	 * within a mailbox controller.
+	 */
+#define MBOX_CHAN_MAX_ARGS	2
+	u32 chan_args[MBOX_CHAN_MAX_ARGS];
+};
+
+#define to_mbox_chan(__node)	\
+	container_of((__node), struct mbox_chan, node)
+
+/**
+ * Representation of a mailbox data transfer
+ *
+ * NOTE: If both "tx" and "rx" are non-NULL then Tx is done before Rx.
+ */
+struct mbox_xfer {
+#define MBOX_XFER_SEQ			(1UL << 0)
+	/** Transfer flags */
+	unsigned long flags;
+	/** Transfer arguments (or parameters) */
+	void *args;
+	/**
+	 * Sequence number
+	 *
+	 * If MBOX_XFER_SEQ is not set in flags then mbox_chan_xfer()
+	 * will generate a unique sequence number and update this field
+	 * else mbox_chan_xfer() will blindly use the sequence number
+	 * specified by this field.
+	 */
+	long seq;
+	/** Send data pointer */
+	void *tx;
+	/** Send data length (valid only if tx != NULL) */
+	unsigned long tx_len;
+	/**
+	 * Send timeout milliseconds (valid only if tx != NULL)
+	 *
+	 * If this field is non-zero along with tx != NULL then the
+	 * mailbox controller driver will wait specified milliseconds
+	 * for send data transfer to complete else the mailbox controller
+	 * driver will not wait.
+	 */
+	unsigned long tx_timeout;
+	/** Receive data pointer */
+	void *rx;
+	/** Receive data length (valid only if rx != NULL) */
+	unsigned long rx_len;
+	/**
+	 * Receive timeout milliseconds (valid only if rx != NULL)
+	 *
+	 * If this field is non-zero along with rx != NULL then the
+	 * mailbox controller driver will wait specified milliseconds
+	 * for receive data transfer to complete else the mailbox
+	 * controller driver will not wait.
+	 */
+	unsigned long rx_timeout;
+};
+
+#define mbox_xfer_init_tx(__p, __a, __t, __t_len, __t_tim)		\
+do {									\
+	(__p)->flags = 0;						\
+	(__p)->args = (__a);						\
+	(__p)->tx = (__t);						\
+	(__p)->tx_len = (__t_len);					\
+	(__p)->tx_timeout = (__t_tim);					\
+	(__p)->rx = NULL;						\
+	(__p)->rx_len = 0;						\
+	(__p)->rx_timeout = 0;						\
+} while (0)
+
+#define mbox_xfer_init_rx(__p, __a, __r, __r_len, __r_tim)		\
+do {									\
+	(__p)->flags = 0;						\
+	(__p)->args = (__a);						\
+	(__p)->tx = NULL;						\
+	(__p)->tx_len = 0;						\
+	(__p)->tx_timeout = 0;						\
+	(__p)->rx = (__r);						\
+	(__p)->rx_len = (__r_len);					\
+	(__p)->rx_timeout = (__r_tim);					\
+} while (0)
+
+#define mbox_xfer_init_txrx(__p, __a, __t, __t_len, __t_tim, __r, __r_len, __r_tim)\
+do {									\
+	(__p)->flags = 0;						\
+	(__p)->args = (__a);						\
+	(__p)->tx = (__t);						\
+	(__p)->tx_len = (__t_len);					\
+	(__p)->tx_timeout = (__t_tim);					\
+	(__p)->rx = (__r);						\
+	(__p)->rx_len = (__r_len);					\
+	(__p)->rx_timeout = (__r_tim);					\
+} while (0)
+
+#define mbox_xfer_set_sequence(__p, __seq)				\
+do {									\
+	(__p)->flags |= MBOX_XFER_SEQ;					\
+	(__p)->seq = (__seq);						\
+} while (0)
+
+/** Representation of a mailbox controller */
+struct mbox_controller {
+	/** List head */
+	struct sbi_dlist node;
+	/** Next sequence atomic counter */
+	atomic_t xfer_next_seq;
+	/* List of mailbox channels */
+	struct sbi_dlist chan_list;
+	/** Unique ID of the mailbox controller assigned by the driver */
+	unsigned int id;
+	/** Maximum length of transfer supported by the mailbox controller */
+	unsigned int max_xfer_len;
+	/** Pointer to mailbox driver owning this mailbox controller */
+	void *driver;
+	/** Request a mailbox channel from the mailbox controller */
+	struct mbox_chan *(*request_chan)(struct mbox_controller *mbox,
+					  u32 *chan_args);
+	/** Free a mailbox channel from the mailbox controller */
+	void (*free_chan)(struct mbox_controller *mbox,
+			  struct mbox_chan *chan);
+	/** Transfer data over mailbox channel */
+	int (*xfer)(struct mbox_chan *chan, struct mbox_xfer *xfer);
+	/** Get an attribute of mailbox channel */
+	int (*get_attribute)(struct mbox_chan *chan, int attr_id, void *out_value);
+	/** Set an attribute of mailbox channel */
+	int (*set_attribute)(struct mbox_chan *chan, int attr_id, void *new_value);
+};
+
+#define to_mbox_controller(__node)	\
+	container_of((__node), struct mbox_controller, node)
+
+/** Find a registered mailbox controller */
+struct mbox_controller *mbox_controller_find(unsigned int id);
+
+/** Register mailbox controller */
+int mbox_controller_add(struct mbox_controller *mbox);
+
+/** Un-register mailbox controller */
+void mbox_controller_remove(struct mbox_controller *mbox);
+
+/** Request a mailbox channel */
+struct mbox_chan *mbox_controller_request_chan(struct mbox_controller *mbox,
+					       u32 *chan_args);
+
+/** Free a mailbox channel */
+void mbox_controller_free_chan(struct mbox_chan *chan);
+
+/** Data transfer over mailbox channel */
+int mbox_chan_xfer(struct mbox_chan *chan, struct mbox_xfer *xfer);
+
+/** Get an attribute of mailbox channel */
+int mbox_chan_get_attribute(struct mbox_chan *chan, int attr_id, void *out_value);
+
+/** Set an attribute of mailbox channel */
+int mbox_chan_set_attribute(struct mbox_chan *chan, int attr_id, void *new_value);
+
+#endif
lib/utils/Kconfig +2 -0
index de8b4eb9..6aa7843c 100644
@@ -14,6 +14,8 @@ source "$(OPENSBI_SRC_DIR)/lib/utils/irqchip/Kconfig"
 
 source "$(OPENSBI_SRC_DIR)/lib/utils/libfdt/Kconfig"
 
+source "$(OPENSBI_SRC_DIR)/lib/utils/mailbox/Kconfig"
+
 source "$(OPENSBI_SRC_DIR)/lib/utils/regmap/Kconfig"
 
 source "$(OPENSBI_SRC_DIR)/lib/utils/reset/Kconfig"
lib/utils/mailbox/Kconfig new file +9 -0
new file mode 100644
index 00000000..f91a9bb9
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: BSD-2-Clause
+
+menu "Mailbox Support"
+
+config MAILBOX
+	bool "Mailbox support"
+	default n
+
+endmenu
lib/utils/mailbox/mailbox.c new file +138 -0

138 lines not on this page · raw message

lib/utils/mailbox/objects.mk new file +10 -0
new file mode 100644
index 00000000..79b27e4c
@@ -0,0 +1,10 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2024 Ventana Micro Systems Inc.
+#
+# Authors:
+#   Anup Patel <[email protected]>
+#
+
+libsbiutils-objs-$(CONFIG_MAILBOX) += mailbox/mailbox.o
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH v2 3/17 lib: utils/mailbox: Add simple FDT based mailbox framework

In reply to Anup Patel

Add a simple FDT based mailbox framework which is built on top of the generic mailbox library. The phandle of FDT mailbox DT node is treated as the unique mailbox controller ID which is required by the generic mailbox library. The FDT based mailbox drivers will be probed on-demand from fdt_mailbox_request_chan() called by the mailbox client drivers.

---
 include/sbi_utils/mailbox/fdt_mailbox.h      | 35 +++++++
 lib/utils/mailbox/Kconfig                    |  6 ++
 lib/utils/mailbox/fdt_mailbox.c              | 96 ++++++++++++++++++++
 lib/utils/mailbox/fdt_mailbox_drivers.carray |  5 +
 lib/utils/mailbox/objects.mk                 |  3 +
 5 files changed, 145 insertions(+)
 create mode 100644 include/sbi_utils/mailbox/fdt_mailbox.h
 create mode 100644 lib/utils/mailbox/fdt_mailbox.c
 create mode 100644 lib/utils/mailbox/fdt_mailbox_drivers.carray
include/sbi_utils/mailbox/fdt_mailbox.h new file +35 -0
new file mode 100644
index 00000000..0d5df340
@@ -0,0 +1,35 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#ifndef __FDT_MAILBOX_H__
+#define __FDT_MAILBOX_H__
+
+#include <sbi_utils/fdt/fdt_driver.h>
+#include <sbi_utils/mailbox/mailbox.h>
+
+struct fdt_phandle_args;
+
+/** FDT based mailbox driver */
+struct fdt_mailbox {
+	struct fdt_driver driver;
+	int (*xlate)(struct mbox_controller *mbox,
+		     const struct fdt_phandle_args *pargs,
+		     u32 *out_chan_args);
+};
+
+/** Request a mailbox channel using "mboxes" DT property of client DT node */
+int fdt_mailbox_request_chan(const void *fdt, int nodeoff, int index,
+			     struct mbox_chan **out_chan);
+
+/** Simple xlate function to convert one mailbox FDT cell into channel args */
+int fdt_mailbox_simple_xlate(struct mbox_controller *mbox,
+			     const struct fdt_phandle_args *pargs,
+			     u32 *out_chan_args);
+
+#endif
lib/utils/mailbox/Kconfig +6 -0
index f91a9bb9..3957bfba 100644
@@ -2,6 +2,12 @@
 
 menu "Mailbox Support"
 
+config FDT_MAILBOX
+	bool "FDT based mailbox drivers"
+	depends on FDT
+	select MAILBOX
+	default n
+
 config MAILBOX
 	bool "Mailbox support"
 	default n
lib/utils/mailbox/fdt_mailbox.c new file +96 -0

96 lines not on this page · raw message

lib/utils/mailbox/fdt_mailbox_drivers.carray new file +5 -0
new file mode 100644
index 00000000..cf87d40c
@@ -0,0 +1,5 @@
+HEADER: sbi_utils/mailbox/fdt_mailbox.h
+TYPE: const struct fdt_mailbox
+NAME: fdt_mailbox_drivers
+MEMBER-NAME: driver
+MEMBER-TYPE: const struct fdt_driver
lib/utils/mailbox/objects.mk +3 -0
index 79b27e4c..2135898c 100644
@@ -7,4 +7,7 @@
 #   Anup Patel <[email protected]>
 #
 
+libsbiutils-objs-$(CONFIG_FDT_MAILBOX) += mailbox/fdt_mailbox.o
+libsbiutils-objs-$(CONFIG_FDT_MAILBOX) += mailbox/fdt_mailbox_drivers.carray.o
+
 libsbiutils-objs-$(CONFIG_MAILBOX) += mailbox/mailbox.o
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH v2 4/17 lib/utils: Add RPMI messaging protocol and shared memory transport support

In reply to Anup Patel

From: Rahul Pathak <[email protected]>

The RISC-V Platform Management Interface (RPMI) defines a messaging protocol and shared memory based transport for bi-directional communication with an on-chip or external microcontroller.

To support RPMI in OpenSBI, add:
1) The RPMI messaging protocol defines and helper macros
2) A FDT mailbox driver for the RPMI shared memory transport

---
 include/sbi_utils/mailbox/rpmi_mailbox.h   |  32 +
 include/sbi_utils/mailbox/rpmi_msgprot.h   | 255 +++++++
 lib/utils/mailbox/Kconfig                  |  14 +
 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c | 773 +++++++++++++++++++++
 lib/utils/mailbox/objects.mk               |   5 +
 lib/utils/mailbox/rpmi_mailbox.c           |  91 +++
 platform/generic/configs/defconfig         |   3 +
 7 files changed, 1173 insertions(+)
 create mode 100644 include/sbi_utils/mailbox/rpmi_mailbox.h
 create mode 100644 include/sbi_utils/mailbox/rpmi_msgprot.h
 create mode 100644 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
 create mode 100644 lib/utils/mailbox/rpmi_mailbox.c
include/sbi_utils/mailbox/rpmi_mailbox.h new file +32 -0
new file mode 100644
index 00000000..61af51a8
@@ -0,0 +1,32 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2023 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#ifndef __RPMI_MAILBOX_H__
+#define __RPMI_MAILBOX_H__
+
+#include <sbi/sbi_error.h>
+#include <sbi_utils/mailbox/rpmi_msgprot.h>
+
+#define rpmi_u32_count(__var)	(sizeof(__var) / sizeof(u32))
+
+/** Convert RPMI error to SBI error */
+int rpmi_xlate_error(enum rpmi_error error);
+
+/** Typical RPMI normal request with at least status code in response */
+int rpmi_normal_request_with_status(
+			struct mbox_chan *chan, u32 service_id,
+			void *req, u32 req_words, u32 req_endian_words,
+			void *resp, u32 resp_words, u32 resp_endian_words);
+
+/* RPMI posted request which is without any response*/
+int rpmi_posted_request(
+		struct mbox_chan *chan, u32 service_id,
+		void *req, u32 req_words, u32 req_endian_words);
+
+#endif /* !__RPMI_MAILBOX_H__ */
include/sbi_utils/mailbox/rpmi_msgprot.h new file +255 -0

255 lines not on this page · raw message

lib/utils/mailbox/Kconfig +14 -0
index 3957bfba..6e7f2cdd 100644
@@ -8,8 +8,22 @@ config FDT_MAILBOX
 	select MAILBOX
 	default n
 
+config RPMI_MAILBOX
+	bool "RPMI based mailbox drivers"
+	select MAILBOX
+	default n
+
 config MAILBOX
 	bool "Mailbox support"
 	default n
 
+if FDT_MAILBOX
+
+config FDT_MAILBOX_RPMI_SHMEM
+	bool "RPMI Shared Memory Mailbox Controller"
+	depends on RPMI_MAILBOX
+	default n
+
+endif
+
 endmenu
lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c new file +773 -0

773 lines not on this page · raw message

lib/utils/mailbox/objects.mk +5 -0
index 2135898c..746b0313 100644
@@ -11,3 +11,8 @@ libsbiutils-objs-$(CONFIG_FDT_MAILBOX) += mailbox/fdt_mailbox.o
 libsbiutils-objs-$(CONFIG_FDT_MAILBOX) += mailbox/fdt_mailbox_drivers.carray.o
 
 libsbiutils-objs-$(CONFIG_MAILBOX) += mailbox/mailbox.o
+
+libsbiutils-objs-$(CONFIG_RPMI_MAILBOX) += mailbox/rpmi_mailbox.o
+
+carray-fdt_mailbox_drivers-$(CONFIG_FDT_MAILBOX_RPMI_SHMEM) += fdt_mailbox_rpmi_shmem
+libsbiutils-objs-$(CONFIG_FDT_MAILBOX_RPMI_SHMEM) += mailbox/fdt_mailbox_rpmi_shmem.o
lib/utils/mailbox/rpmi_mailbox.c new file +91 -0

91 lines not on this page · raw message

platform/generic/configs/defconfig +3 -0
index 079bc4fe..233a9a89 100644
@@ -20,6 +20,9 @@ CONFIG_FDT_IRQCHIP=y
 CONFIG_FDT_IRQCHIP_APLIC=y
 CONFIG_FDT_IRQCHIP_IMSIC=y
 CONFIG_FDT_IRQCHIP_PLIC=y
+CONFIG_FDT_MAILBOX=y
+CONFIG_RPMI_MAILBOX=y
+CONFIG_FDT_MAILBOX_RPMI_SHMEM=y
 CONFIG_FDT_REGMAP=y
 CONFIG_FDT_REGMAP_SYSCON=y
 CONFIG_FDT_RESET=y
Signature · 1 line
2.43.0
author
#5 lore raw

PATCH v2 5/17 lib/utils: reset: Add RPMI System Reset driver

In reply to Anup Patel

From: Rahul Pathak <[email protected]>

Add RPMI based driver for system reset and enable it in the generic platform defconfig

---
 include/sbi_utils/mailbox/rpmi_msgprot.h |  27 +++++
 lib/utils/reset/Kconfig                  |   5 +
 lib/utils/reset/fdt_reset_rpmi.c         | 141 +++++++++++++++++++++++
 lib/utils/reset/objects.mk               |   3 +
 platform/generic/configs/defconfig       |   1 +
 5 files changed, 177 insertions(+)
 create mode 100644 lib/utils/reset/fdt_reset_rpmi.c
include/sbi_utils/mailbox/rpmi_msgprot.h +27 -0
index f9f65447..31c3034b 100644
@@ -196,6 +196,7 @@ struct rpmi_message_args {
 enum rpmi_servicegroup_id {
 	RPMI_SRVGRP_ID_MIN = 0,
 	RPMI_SRVGRP_BASE = 0x0001,
+	RPMI_SRVGRP_SYSTEM_RESET = 0x0002,
 	RPMI_SRVGRP_ID_MAX_COUNT,
 
 	/* Reserved range for service groups */
@@ -252,4 +253,30 @@ struct rpmi_base_get_platform_info_resp {
 	char plat_info[];
 };
 
+/** RPMI System Reset ServiceGroup Service IDs */
+enum rpmi_system_reset_service_id {
+	RPMI_SYSRST_SRV_ENABLE_NOTIFICATION = 0x01,
+	RPMI_SYSRST_SRV_GET_ATTRIBUTES = 0x02,
+	RPMI_SYSRST_SRV_SYSTEM_RESET = 0x03,
+	RPMI_SYSRST_SRV_ID_MAX_COUNT,
+};
+
+/** RPMI System Reset types */
+enum rpmi_sysrst_reset_type {
+	RPMI_SYSRST_TYPE_SHUTDOWN = 0x0,
+	RPMI_SYSRST_TYPE_COLD_REBOOT = 0x1,
+	RPMI_SYSRST_TYPE_WARM_REBOOT = 0x2,
+	RPMI_SYSRST_TYPE_MAX,
+};
+
+#define RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE_POS		(1)
+#define RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE_MASK		\
+			(1U << RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE_POS)
+
+/** Response for system reset attributes */
+struct rpmi_sysrst_get_reset_attributes_resp {
+	s32 status;
+	u32 flags;
+};
+
 #endif /* !__RPMI_MSGPROT_H__ */
lib/utils/reset/Kconfig +5 -0
index 6c077fe7..68e66716 100644
@@ -24,6 +24,11 @@ config FDT_RESET_HTIF
 	select SYS_HTIF
 	default n
 
+config FDT_RESET_RPMI
+	bool "RPMI FDT reset driver"
+	depends on FDT_MAILBOX && RPMI_MAILBOX
+	default n
+
 config FDT_RESET_SG2042_HWMON_MCU
 	bool "Sophgo SG2042 hwmon MCU FDT reset driver"
 	default n
lib/utils/reset/fdt_reset_rpmi.c new file +141 -0

141 lines not on this page · raw message

lib/utils/reset/objects.mk +3 -0
index a84336cf..8f3774c5 100644
@@ -29,3 +29,6 @@ libsbiutils-objs-$(CONFIG_FDT_RESET_SUNXI_WDT) += reset/fdt_reset_sunxi_wdt.o
 carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_SYSCON) += fdt_syscon_poweroff
 carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_SYSCON) += fdt_syscon_reboot
 libsbiutils-objs-$(CONFIG_FDT_RESET_SYSCON) += reset/fdt_reset_syscon.o
+
+carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_RPMI) += fdt_reset_rpmi
+libsbiutils-objs-$(CONFIG_FDT_RESET_RPMI) += reset/fdt_reset_rpmi.o
platform/generic/configs/defconfig +1 -0
index 233a9a89..48f8df4c 100644
@@ -29,6 +29,7 @@ CONFIG_FDT_RESET=y
 CONFIG_FDT_RESET_ATCWDT200=y
 CONFIG_FDT_RESET_GPIO=y
 CONFIG_FDT_RESET_HTIF=y
+CONFIG_FDT_RESET_RPMI=y
 CONFIG_FDT_RESET_SUNXI_WDT=y
 CONFIG_FDT_RESET_SG2042_HWMON_MCU=y
 CONFIG_FDT_RESET_SYSCON=y
Signature · 1 line
2.43.0
author
#6 lore raw

PATCH v2 6/17 lib: utils: Add simple FDT based system suspend driver framework

In reply to Anup Patel

The generic platform can have multiple system suspend drivers so add a simple FDT based system suspend driver framework.

---
 include/sbi_utils/suspend/fdt_suspend.h      | 26 ++++++++++++++++++++
 lib/utils/Kconfig                            |  2 ++
 lib/utils/suspend/Kconfig                    | 10 ++++++++
 lib/utils/suspend/fdt_suspend.c              | 22 +++++++++++++++++
 lib/utils/suspend/fdt_suspend_drivers.carray |  3 +++
 lib/utils/suspend/objects.mk                 | 11 +++++++++
 platform/generic/configs/defconfig           |  1 +
 platform/generic/platform.c                  |  2 ++
 8 files changed, 77 insertions(+)
 create mode 100644 include/sbi_utils/suspend/fdt_suspend.h
 create mode 100644 lib/utils/suspend/Kconfig
 create mode 100644 lib/utils/suspend/fdt_suspend.c
 create mode 100644 lib/utils/suspend/fdt_suspend_drivers.carray
 create mode 100644 lib/utils/suspend/objects.mk
include/sbi_utils/suspend/fdt_suspend.h new file +26 -0
new file mode 100644
index 00000000..bfc6c69a
@@ -0,0 +1,26 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#ifndef __FDT_SUSPEND_H__
+#define __FDT_SUSPEND_H__
+
+#include <sbi/sbi_types.h>
+#include <sbi_utils/fdt/fdt_driver.h>
+
+#ifdef CONFIG_FDT_SUSPEND
+
+void fdt_suspend_init(const void *fdt);
+
+#else
+
+static inline void fdt_suspend_init(const void *fdt) { }
+
+#endif
+
+#endif
lib/utils/Kconfig +2 -0
index 6aa7843c..3f32c1ca 100644
@@ -22,6 +22,8 @@ source "$(OPENSBI_SRC_DIR)/lib/utils/reset/Kconfig"
 
 source "$(OPENSBI_SRC_DIR)/lib/utils/serial/Kconfig"
 
+source "$(OPENSBI_SRC_DIR)/lib/utils/suspend/Kconfig"
+
 source "$(OPENSBI_SRC_DIR)/lib/utils/sys/Kconfig"
 
 source "$(OPENSBI_SRC_DIR)/lib/utils/timer/Kconfig"
lib/utils/suspend/Kconfig new file +10 -0
new file mode 100644
index 00000000..416ae795
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: BSD-2-Clause
+
+menu "System Suspend Support"
+
+config FDT_SUSPEND
+	bool "FDT based suspend drivers"
+	depends on FDT
+	default n
+
+endmenu
lib/utils/suspend/fdt_suspend.c new file +22 -0
new file mode 100644
index 00000000..bd4691a0
@@ -0,0 +1,22 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#include <sbi_utils/suspend/fdt_suspend.h>
+
+/* List of FDT suspend drivers generated at compile time */
+extern const struct fdt_driver *const fdt_suspend_drivers[];
+
+void fdt_suspend_init(const void *fdt)
+{
+	/*
+	 * Platforms might have multiple system suspend devices or
+	 * might not have any so probe all and don't fail.
+	 */
+	fdt_driver_init_all(fdt, fdt_suspend_drivers);
+}
lib/utils/suspend/fdt_suspend_drivers.carray new file +3 -0
new file mode 100644
index 00000000..a0c857fc
@@ -0,0 +1,3 @@
+HEADER: sbi_utils/suspend/fdt_suspend.h
+TYPE: const struct fdt_driver
+NAME: fdt_suspend_drivers
lib/utils/suspend/objects.mk new file +11 -0
new file mode 100644
index 00000000..30d897d1
@@ -0,0 +1,11 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2024 Ventana Micro Systems Inc.
+#
+# Authors:
+#   Anup Patel <[email protected]>
+#
+
+libsbiutils-objs-$(CONFIG_FDT_SUSPEND) += suspend/fdt_suspend.o
+libsbiutils-objs-$(CONFIG_FDT_SUSPEND) += suspend/fdt_suspend_drivers.carray.o
platform/generic/configs/defconfig +1 -0
index 48f8df4c..ec439d74 100644
@@ -44,6 +44,7 @@ CONFIG_FDT_SERIAL_LITEX=y
 CONFIG_FDT_SERIAL_UART8250=y
 CONFIG_FDT_SERIAL_XILINX_UARTLITE=y
 CONFIG_SERIAL_SEMIHOSTING=y
+CONFIG_FDT_SUSPEND=y
 CONFIG_FDT_TIMER=y
 CONFIG_FDT_TIMER_MTIMER=y
 CONFIG_FDT_TIMER_PLMT=y
platform/generic/platform.c +2 -0
index fb074d4b..30da839f 100644
@@ -24,6 +24,7 @@
 #include <sbi_utils/irqchip/fdt_irqchip.h>
 #include <sbi_utils/irqchip/imsic.h>
 #include <sbi_utils/serial/fdt_serial.h>
+#include <sbi_utils/suspend/fdt_suspend.h>
 #include <sbi_utils/timer/fdt_timer.h>
 #include <sbi_utils/ipi/fdt_ipi.h>
 #include <sbi_utils/reset/fdt_reset.h>
@@ -247,6 +248,7 @@ static int generic_early_init(bool cold_boot)
 
 	if (cold_boot) {
 		fdt_reset_init(fdt);
+		fdt_suspend_init(fdt);
 
 		if (semihosting_enabled())
 			rc = semihosting_init();
Signature · 1 line
2.43.0
author
#7 lore raw

PATCH v2 7/17 lib: utils/suspend: Add RPMI system suspend driver

In reply to Anup Patel

From: Subrahmanya Lingappa <[email protected]>

Add RPMI based system suspend driver.

To test this, execute the follwoing in Linux:

 $ echo mem > /sys/power/state

To wake up, execute the following command on qemu monitor terminal:
(qemu) system_wakeup

---
 include/sbi_utils/mailbox/rpmi_msgprot.h |  35 ++++++
 lib/utils/suspend/Kconfig                |   9 ++
 lib/utils/suspend/fdt_suspend_rpmi.c     | 138 +++++++++++++++++++++++
 lib/utils/suspend/objects.mk             |   3 +
 platform/generic/configs/defconfig       |   1 +
 5 files changed, 186 insertions(+)
 create mode 100644 lib/utils/suspend/fdt_suspend_rpmi.c
include/sbi_utils/mailbox/rpmi_msgprot.h +35 -0
index 31c3034b..4de86adf 100644
@@ -5,6 +5,7 @@
  *
  * Authors:
  *   Rahul Pathak <[email protected]>
+ *   Subrahmanya Lingappa <[email protected]>
  */
 
 #ifndef __RPMI_MSGPROT_H__
@@ -197,6 +198,7 @@ enum rpmi_servicegroup_id {
 	RPMI_SRVGRP_ID_MIN = 0,
 	RPMI_SRVGRP_BASE = 0x0001,
 	RPMI_SRVGRP_SYSTEM_RESET = 0x0002,
+	RPMI_SRVGRP_SYSTEM_SUSPEND = 0x0003,
 	RPMI_SRVGRP_ID_MAX_COUNT,
 
 	/* Reserved range for service groups */
@@ -279,4 +281,37 @@ struct rpmi_sysrst_get_reset_attributes_resp {
 	u32 flags;
 };
 
+/** RPMI System Suspend ServiceGroup Service IDs */
+enum rpmi_system_suspend_service_id {
+	RPMI_SYSSUSP_SRV_ENABLE_NOTIFICATION = 0x01,
+	RPMI_SYSSUSP_SRV_GET_ATTRIBUTES = 0x02,
+	RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND = 0x03,
+	RPMI_SYSSUSP_SRV_ID_MAX_COUNT,
+};
+
+/** Request for system suspend attributes */
+struct rpmi_syssusp_get_attr_req {
+	u32 susp_type;
+};
+
+#define RPMI_SYSSUSP_ATTRS_FLAGS_RESUMEADDR	(1U << 1)
+#define RPMI_SYSSUSP_ATTRS_FLAGS_SUSPENDTYPE	1U
+
+/** Response for system suspend attributes */
+struct rpmi_syssusp_get_attr_resp {
+	s32 status;
+	u32 flags;
+};
+
+struct rpmi_syssusp_suspend_req {
+	u32 hartid;
+	u32 suspend_type;
+	u32 resume_addr_lo;
+	u32 resume_addr_hi;
+};
+
+struct rpmi_syssusp_suspend_resp {
+	s32 status;
+};
+
 #endif /* !__RPMI_MSGPROT_H__ */
lib/utils/suspend/Kconfig +9 -0
index 416ae795..2cbea75c 100644
@@ -7,4 +7,13 @@ config FDT_SUSPEND
 	depends on FDT
 	default n
 
+if FDT_SUSPEND
+
+config FDT_SUSPEND_RPMI
+	bool "FDT RPMI suspend driver"
+	depends on FDT_MAILBOX && RPMI_MAILBOX
+	default n
+
+endif
+
 endmenu
lib/utils/suspend/fdt_suspend_rpmi.c new file +138 -0

138 lines not on this page · raw message

lib/utils/suspend/objects.mk +3 -0
index 30d897d1..657670a8 100644
@@ -9,3 +9,6 @@
 
 libsbiutils-objs-$(CONFIG_FDT_SUSPEND) += suspend/fdt_suspend.o
 libsbiutils-objs-$(CONFIG_FDT_SUSPEND) += suspend/fdt_suspend_drivers.carray.o
+
+carray-fdt_suspend_drivers-$(CONFIG_FDT_SUSPEND_RPMI) += fdt_suspend_rpmi
+libsbiutils-objs-$(CONFIG_FDT_SUSPEND_RPMI) += suspend/fdt_suspend_rpmi.o
platform/generic/configs/defconfig +1 -0
index ec439d74..54300fb5 100644
@@ -45,6 +45,7 @@ CONFIG_FDT_SERIAL_UART8250=y
 CONFIG_FDT_SERIAL_XILINX_UARTLITE=y
 CONFIG_SERIAL_SEMIHOSTING=y
 CONFIG_FDT_SUSPEND=y
+CONFIG_FDT_SUSPEND_RPMI=y
 CONFIG_FDT_TIMER=y
 CONFIG_FDT_TIMER_MTIMER=y
 CONFIG_FDT_TIMER_PLMT=y
Signature · 1 line
2.43.0
author
#8 lore raw

PATCH v2 8/17 lib: sbi: Add optional resume address to hart suspend

In reply to Anup Patel

From: Subrahmanya Lingappa <[email protected]>

Add an optional resume address to the platform specific hart suspend call.

---
 include/sbi/sbi_hsm.h                  | 6 +++++-
 lib/sbi/sbi_hsm.c                      | 6 +++---
 platform/generic/allwinner/sun20i-d1.c | 2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)
include/sbi/sbi_hsm.h +5 -1
index ae098f45..38f90516 100644
@@ -40,8 +40,12 @@ struct sbi_hsm_device {
 	 *
 	 * For successful non-retentive suspend, the hart will resume from
 	 * the warm boot entry point.
+	 *
+	 * NOTE: mmode_resume_addr(resume address) is optional hence it
+	 * may or may not be honored by the platform. If its not honored
+	 * then platform must ensure to resume from the warmboot address.
 	 */
-	int (*hart_suspend)(u32 suspend_type);
+	int (*hart_suspend)(u32 suspend_type, ulong mmode_resume_addr);
 
 	/**
 	 * Perform platform-specific actions to resume from a suspended state.
lib/sbi/sbi_hsm.c +3 -3
index a3d6947a..cf0eb84b 100644
@@ -223,10 +223,10 @@ static int hsm_device_hart_stop(void)
 	return SBI_ENOTSUPP;
 }
 
-static int hsm_device_hart_suspend(u32 suspend_type)
+static int hsm_device_hart_suspend(u32 suspend_type, ulong mmode_resume_addr)
 {
 	if (hsm_dev && hsm_dev->hart_suspend)
-		return hsm_dev->hart_suspend(suspend_type);
+		return hsm_dev->hart_suspend(suspend_type, mmode_resume_addr);
 	return SBI_ENOTSUPP;
 }
 
@@ -532,7 +532,7 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type,
 		__sbi_hsm_suspend_non_ret_save(scratch);
 
 	/* Try platform specific suspend */
-	ret = hsm_device_hart_suspend(suspend_type);
+	ret = hsm_device_hart_suspend(suspend_type, scratch->warmboot_addr);
 	if (ret == SBI_ENOTSUPP) {
 		/* Try generic implementation of default suspend types */
 		if (suspend_type == SBI_HSM_SUSPEND_RET_DEFAULT ||
platform/generic/allwinner/sun20i-d1.c +1 -1
index b65013c2..c31ebdb2 100644
@@ -130,7 +130,7 @@ static void sun20i_d1_riscv_cfg_init(void)
 	writel_relaxed(entry >> 32, SUN20I_D1_RISCV_CFG_BASE + RESET_ENTRY_HI_REG);
 }
 
-static int sun20i_d1_hart_suspend(u32 suspend_type)
+static int sun20i_d1_hart_suspend(u32 suspend_type, ulong mmode_resume_addr)
 {
 	/* Use the generic code for retentive suspend. */
 	if (!(suspend_type & SBI_HSM_SUSP_NON_RET_BIT))
Signature · 1 line
2.43.0
author
#9 lore raw

PATCH v2 9/17 lib: utils/fdt: Allow dynamic registration of FDT fixup callbacks

In reply to Anup Patel

It should possible to fixup FDT from any part of OpenSBI so add fdt_register_general_fixup() which allows dynamic registration of FDT fixup callbacks.

---
 include/sbi_utils/fdt/fdt_fixup.h | 15 ++++++++++++++
 lib/utils/fdt/fdt_fixup.c         | 33 +++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
include/sbi_utils/fdt/fdt_fixup.h +15 -0
index 21a53011..93249968 100644
@@ -9,6 +9,8 @@
 #ifndef __FDT_FIXUP_H__
 #define __FDT_FIXUP_H__
 
+#include <sbi/sbi_list.h>
+
 struct sbi_cpu_idle_state {
 	const char *name;
 	uint32_t suspend_param;
@@ -93,6 +95,19 @@ void fdt_plic_fixup(void *fdt);
  */
 int fdt_reserved_memory_fixup(void *fdt);
 
+/** Representation of a general fixup */
+struct fdt_general_fixup {
+	struct sbi_dlist head;
+	const char *name;
+	void (*do_fixup)(struct fdt_general_fixup *f, void *fdt);
+};
+
+/** Register a general fixup */
+int fdt_register_general_fixup(struct fdt_general_fixup *fixup);
+
+/** UnRegister a general fixup */
+void fdt_unregister_general_fixup(struct fdt_general_fixup *fixup);
+
 /**
  * General device tree fix-up
  *
lib/utils/fdt/fdt_fixup.c +33 -0
index 9e013dfa..192d6dd5 100644
@@ -401,8 +401,38 @@ void fdt_config_fixup(void *fdt)
 	fdt_nop_node(fdt, config_offset);
 }
 
+static SBI_LIST_HEAD(fixup_list);
+
+int fdt_register_general_fixup(struct fdt_general_fixup *fixup)
+{
+	struct fdt_general_fixup *f;
+
+	if (!fixup || !fixup->name || !fixup->do_fixup)
+		return SBI_EINVAL;
+
+	sbi_list_for_each_entry(f, &fixup_list, head) {
+		if (f == fixup)
+			return SBI_EALREADY;
+	}
+
+	SBI_INIT_LIST_HEAD(&fixup->head);
+	sbi_list_add_tail(&fixup->head, &fixup_list);
+
+	return 0;
+}
+
+void fdt_unregister_general_fixup(struct fdt_general_fixup *fixup)
+{
+	if (!fixup)
+		return;
+
+	sbi_list_del(&fixup->head);
+}
+
 void fdt_fixups(void *fdt)
 {
+	struct fdt_general_fixup *f;
+
 	fdt_aplic_fixup(fdt);
 
 	fdt_imsic_fixup(fdt);
@@ -416,4 +446,7 @@ void fdt_fixups(void *fdt)
 #endif
 
 	fdt_config_fixup(fdt);
+
+	sbi_list_for_each_entry(f, &fixup_list, head)
+		f->do_fixup(f, fdt);
 }
Signature · 1 line
2.43.0
author
#10 lore raw

PATCH v2 10/17 lib: utils: Add simple FDT based HSM driver framework

In reply to Anup Patel

The generic platform can have multiple HSM drivers so add a simple FDT based HSM driver framework.

---
 include/sbi_utils/hsm/fdt_hsm.h      | 26 ++++++++++++++++++++++++++
 lib/utils/Kconfig                    |  2 ++
 lib/utils/hsm/Kconfig                | 10 ++++++++++
 lib/utils/hsm/fdt_hsm.c              | 22 ++++++++++++++++++++++
 lib/utils/hsm/fdt_hsm_drivers.carray |  3 +++
 lib/utils/hsm/objects.mk             | 11 +++++++++++
 platform/generic/configs/defconfig   |  1 +
 platform/generic/platform.c          |  2 ++
 8 files changed, 77 insertions(+)
 create mode 100644 include/sbi_utils/hsm/fdt_hsm.h
 create mode 100644 lib/utils/hsm/Kconfig
 create mode 100644 lib/utils/hsm/fdt_hsm.c
 create mode 100644 lib/utils/hsm/fdt_hsm_drivers.carray
 create mode 100644 lib/utils/hsm/objects.mk
include/sbi_utils/hsm/fdt_hsm.h new file +26 -0
new file mode 100644
index 00000000..58061afc
@@ -0,0 +1,26 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#ifndef __FDT_HSM_H__
+#define __FDT_HSM_H__
+
+#include <sbi/sbi_types.h>
+#include <sbi_utils/fdt/fdt_driver.h>
+
+#ifdef CONFIG_FDT_HSM
+
+void fdt_hsm_init(const void *fdt);
+
+#else
+
+static inline void fdt_hsm_init(const void *fdt) { }
+
+#endif
+
+#endif
lib/utils/Kconfig +2 -0
index 3f32c1ca..c860a185 100644
@@ -6,6 +6,8 @@ source "$(OPENSBI_SRC_DIR)/lib/utils/fdt/Kconfig"
 
 source "$(OPENSBI_SRC_DIR)/lib/utils/gpio/Kconfig"
 
+source "$(OPENSBI_SRC_DIR)/lib/utils/hsm/Kconfig"
+
 source "$(OPENSBI_SRC_DIR)/lib/utils/i2c/Kconfig"
 
 source "$(OPENSBI_SRC_DIR)/lib/utils/ipi/Kconfig"
lib/utils/hsm/Kconfig new file +10 -0
new file mode 100644
index 00000000..31506116
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: BSD-2-Clause
+
+menu "HSM Device Support"
+
+config FDT_HSM
+	bool "FDT based HSM drivers"
+	depends on FDT
+	default n
+
+endmenu
lib/utils/hsm/fdt_hsm.c new file +22 -0
new file mode 100644
index 00000000..162b9867
@@ -0,0 +1,22 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#include <sbi_utils/hsm/fdt_hsm.h>
+
+/* List of FDT HSM drivers generated at compile time */
+extern const struct fdt_driver *const fdt_hsm_drivers[];
+
+void fdt_hsm_init(const void *fdt)
+{
+	/*
+	 * Platforms might have multiple HSM devices or might
+	 * not have any so probe all and don't fail.
+	 */
+	fdt_driver_init_all(fdt, fdt_hsm_drivers);
+}
lib/utils/hsm/fdt_hsm_drivers.carray new file +3 -0
new file mode 100644
index 00000000..73680a25
@@ -0,0 +1,3 @@
+HEADER: sbi_utils/hsm/fdt_hsm.h
+TYPE: const struct fdt_driver
+NAME: fdt_hsm_drivers
lib/utils/hsm/objects.mk new file +11 -0
new file mode 100644
index 00000000..49337bf5
@@ -0,0 +1,11 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2024 Ventana Micro Systems Inc.
+#
+# Authors:
+#   Anup Patel <[email protected]>
+#
+
+libsbiutils-objs-$(CONFIG_FDT_HSM) += hsm/fdt_hsm.o
+libsbiutils-objs-$(CONFIG_FDT_HSM) += hsm/fdt_hsm_drivers.carray.o
platform/generic/configs/defconfig +1 -0
index 54300fb5..2efc7136 100644
@@ -10,6 +10,7 @@ CONFIG_FDT_GPIO=y
 CONFIG_FDT_GPIO_DESIGNWARE=y
 CONFIG_FDT_GPIO_SIFIVE=y
 CONFIG_FDT_GPIO_STARFIVE=y
+CONFIG_FDT_HSM=y
 CONFIG_FDT_I2C=y
 CONFIG_FDT_I2C_SIFIVE=y
 CONFIG_FDT_I2C_DW=y
platform/generic/platform.c +2 -0
index 30da839f..48228e67 100644
@@ -21,6 +21,7 @@
 #include <sbi_utils/fdt/fdt_fixup.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 #include <sbi_utils/fdt/fdt_pmu.h>
+#include <sbi_utils/hsm/fdt_hsm.h>
 #include <sbi_utils/irqchip/fdt_irqchip.h>
 #include <sbi_utils/irqchip/imsic.h>
 #include <sbi_utils/serial/fdt_serial.h>
@@ -249,6 +250,7 @@ static int generic_early_init(bool cold_boot)
 	if (cold_boot) {
 		fdt_reset_init(fdt);
 		fdt_suspend_init(fdt);
+		fdt_hsm_init(fdt);
 
 		if (semihosting_enabled())
 			rc = semihosting_init();
Signature · 1 line
2.43.0
author
#11 lore raw

PATCH v2 11/17 lib: utils/hsm: Add RPMI HSM driver

In reply to Anup Patel

From: Subrahmanya Lingappa <[email protected]>

The RPMI HSM service group provides set of routine to query and control power states of a Hart. Add RPMI based Hart State Management (HSM) driver.

---
 include/sbi_utils/mailbox/rpmi_msgprot.h |  92 ++++++
 lib/utils/hsm/Kconfig                    |   9 +
 lib/utils/hsm/fdt_hsm_rpmi.c             | 362 +++++++++++++++++++++++
 lib/utils/hsm/objects.mk                 |   3 +
 platform/generic/configs/defconfig       |   1 +
 5 files changed, 467 insertions(+)
 create mode 100644 lib/utils/hsm/fdt_hsm_rpmi.c
include/sbi_utils/mailbox/rpmi_msgprot.h +92 -0
index 4de86adf..8e2b23e2 100644
@@ -199,6 +199,7 @@ enum rpmi_servicegroup_id {
 	RPMI_SRVGRP_BASE = 0x0001,
 	RPMI_SRVGRP_SYSTEM_RESET = 0x0002,
 	RPMI_SRVGRP_SYSTEM_SUSPEND = 0x0003,
+	RPMI_SRVGRP_HSM = 0x0004,
 	RPMI_SRVGRP_ID_MAX_COUNT,
 
 	/* Reserved range for service groups */
@@ -314,4 +315,95 @@ struct rpmi_syssusp_suspend_resp {
 	s32 status;
 };
 
+/** RPMI HSM State Management ServiceGroup Service IDs */
+enum rpmi_hsm_service_id {
+	RPMI_HSM_SRV_ENABLE_NOTIFICATION = 0x01,
+	RPMI_HSM_SRV_GET_HART_STATUS = 0x02,
+	RPMI_HSM_SRV_GET_HART_LIST = 0x03,
+	RPMI_HSM_SRV_GET_SUSPEND_TYPES = 0x04,
+	RPMI_HSM_SRV_GET_SUSPEND_INFO = 0x05,
+	RPMI_HSM_SRV_HART_START = 0x06,
+	RPMI_HSM_SRV_HART_STOP = 0x07,
+	RPMI_HSM_SRV_HART_SUSPEND = 0x08,
+	RPMI_HSM_SRV_ID_MAX = 0x09,
+};
+
+/* HSM service group request and response structs */
+struct rpmi_hsm_hart_start_req {
+	u32 hartid;
+	u32 start_addr_lo;
+	u32 start_addr_hi;
+};
+
+struct rpmi_hsm_hart_start_resp {
+	s32 status;
+};
+
+struct rpmi_hsm_hart_stop_req {
+	u32 hartid;
+};
+
+struct rpmi_hsm_hart_stop_resp {
+	s32 status;
+};
+
+struct rpmi_hsm_hart_susp_req {
+	u32 hartid;
+	u32 suspend_type;
+	u32 resume_addr_lo;
+	u32 resume_addr_hi;
+};
+
+struct rpmi_hsm_hart_susp_resp {
+	s32 status;
+};
+
+struct rpmi_hsm_get_hart_status_req {
+	u32 hartid;
+};
+
+struct rpmi_hsm_get_hart_status_resp {
+	s32 status;
+	u32 hart_status;
+};
+
+struct rpmi_hsm_get_hart_list_req {
+	u32 start_index;
+};
+
+struct rpmi_hsm_get_hart_list_resp {
+	s32 status;
+	u32 remaining;
+	u32 returned;
+	/* remaining space need to be adjusted for the above 3 u32's */
+	u32 hartid[(RPMI_MSG_DATA_SIZE(RPMI_SLOT_SIZE_MIN) - (sizeof(u32) * 3)) / sizeof(u32)];
+};
+
+struct rpmi_hsm_get_susp_types_req {
+	u32 start_index;
+};
+
+struct rpmi_hsm_get_susp_types_resp {
+	s32 status;
+	u32 remaining;
+	u32 returned;
+	/* remaining space need to be adjusted for the above 3 u32's */
+	u32 types[(RPMI_MSG_DATA_SIZE(RPMI_SLOT_SIZE_MIN) - (sizeof(u32) * 3)) / sizeof(u32)];
+};
+
+struct rpmi_hsm_get_susp_info_req {
+	u32 suspend_type;
+};
+
+#define RPMI_HSM_SUSPEND_INFO_FLAGS_TIMER_STOP		1U
+
+struct rpmi_hsm_get_susp_info_resp {
+	s32 status;
+	u32 flags;
+	u32 entry_latency_us;
+	u32 exit_latency_us;
+	u32 wakeup_latency_us;
+	u32 min_residency_us;
+};
+
 #endif /* !__RPMI_MSGPROT_H__ */
lib/utils/hsm/Kconfig +9 -0
index 31506116..1ad7958f 100644
@@ -7,4 +7,13 @@ config FDT_HSM
 	depends on FDT
 	default n
 
+if FDT_HSM
+
+config FDT_HSM_RPMI
+	bool "FDT RPMI HSM driver"
+	depends on FDT_MAILBOX && RPMI_MAILBOX
+	default n
+
+endif
+
 endmenu
lib/utils/hsm/fdt_hsm_rpmi.c new file +362 -0

362 lines not on this page · raw message

lib/utils/hsm/objects.mk +3 -0
index 49337bf5..b54b6f6c 100644
@@ -9,3 +9,6 @@
 
 libsbiutils-objs-$(CONFIG_FDT_HSM) += hsm/fdt_hsm.o
 libsbiutils-objs-$(CONFIG_FDT_HSM) += hsm/fdt_hsm_drivers.carray.o
+
+carray-fdt_hsm_drivers-$(CONFIG_FDT_HSM_RPMI) += fdt_hsm_rpmi
+libsbiutils-objs-$(CONFIG_FDT_HSM_RPMI) += hsm/fdt_hsm_rpmi.o
platform/generic/configs/defconfig +1 -0
index 2efc7136..78fc96b6 100644
@@ -11,6 +11,7 @@ CONFIG_FDT_GPIO_DESIGNWARE=y
 CONFIG_FDT_GPIO_SIFIVE=y
 CONFIG_FDT_GPIO_STARFIVE=y
 CONFIG_FDT_HSM=y
+CONFIG_FDT_HSM_RPMI=y
 CONFIG_FDT_I2C=y
 CONFIG_FDT_I2C_SIFIVE=y
 CONFIG_FDT_I2C_DW=y
Signature · 1 line
2.43.0
author
#12 lore raw

PATCH v2 12/17 lib: utils: Add simple FDT based CPPC driver framework

In reply to Anup Patel

The generic platform can have multiple CPPC drivers so add a simple FDT based CPPC driver framework.

---
 include/sbi_utils/cppc/fdt_cppc.h      | 26 ++++++++++++++++++++++++++
 lib/utils/Kconfig                      |  2 ++
 lib/utils/cppc/Kconfig                 | 10 ++++++++++
 lib/utils/cppc/fdt_cppc.c              | 22 ++++++++++++++++++++++
 lib/utils/cppc/fdt_cppc_drivers.carray |  3 +++
 lib/utils/cppc/objects.mk              | 11 +++++++++++
 platform/generic/configs/defconfig     |  1 +
 platform/generic/platform.c            |  2 ++
 8 files changed, 77 insertions(+)
 create mode 100644 include/sbi_utils/cppc/fdt_cppc.h
 create mode 100644 lib/utils/cppc/Kconfig
 create mode 100644 lib/utils/cppc/fdt_cppc.c
 create mode 100644 lib/utils/cppc/fdt_cppc_drivers.carray
 create mode 100644 lib/utils/cppc/objects.mk
include/sbi_utils/cppc/fdt_cppc.h new file +26 -0
new file mode 100644
index 00000000..433c6d32
@@ -0,0 +1,26 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#ifndef __FDT_CPPC_H__
+#define __FDT_CPPC_H__
+
+#include <sbi/sbi_types.h>
+#include <sbi_utils/fdt/fdt_driver.h>
+
+#ifdef CONFIG_FDT_CPPC
+
+void fdt_cppc_init(const void *fdt);
+
+#else
+
+static inline void fdt_cppc_init(const void *fdt) { }
+
+#endif
+
+#endif
lib/utils/Kconfig +2 -0
index c860a185..002d6f8f 100644
@@ -2,6 +2,8 @@
 
 menu "Utils and Drivers Support"
 
+source "$(OPENSBI_SRC_DIR)/lib/utils/cppc/Kconfig"
+
 source "$(OPENSBI_SRC_DIR)/lib/utils/fdt/Kconfig"
 
 source "$(OPENSBI_SRC_DIR)/lib/utils/gpio/Kconfig"
lib/utils/cppc/Kconfig new file +10 -0
new file mode 100644
index 00000000..08d1c97f
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: BSD-2-Clause
+
+menu "CPPC Device Support"
+
+config FDT_CPPC
+	bool "FDT based CPPC drivers"
+	depends on FDT
+	default n
+
+endmenu
lib/utils/cppc/fdt_cppc.c new file +22 -0
new file mode 100644
index 00000000..0e1ecb24
@@ -0,0 +1,22 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#include <sbi_utils/cppc/fdt_cppc.h>
+
+/* List of FDT CPPC drivers generated at compile time */
+extern const struct fdt_driver *const fdt_cppc_drivers[];
+
+void fdt_cppc_init(const void *fdt)
+{
+	/*
+	 * Platforms might have multiple CPPC devices or might
+	 * not have any so probe all and don't fail.
+	 */
+	fdt_driver_init_all(fdt, fdt_cppc_drivers);
+}
lib/utils/cppc/fdt_cppc_drivers.carray new file +3 -0
new file mode 100644
index 00000000..b25c7888
@@ -0,0 +1,3 @@
+HEADER: sbi_utils/cppc/fdt_cppc.h
+TYPE: const struct fdt_driver
+NAME: fdt_cppc_drivers
lib/utils/cppc/objects.mk new file +11 -0
new file mode 100644
index 00000000..fb37478a
@@ -0,0 +1,11 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2024 Ventana Micro Systems Inc.
+#
+# Authors:
+#   Anup Patel <[email protected]>
+#
+
+libsbiutils-objs-$(CONFIG_FDT_CPPC) += cppc/fdt_cppc.o
+libsbiutils-objs-$(CONFIG_FDT_CPPC) += cppc/fdt_cppc_drivers.carray.o
platform/generic/configs/defconfig +1 -0
index 78fc96b6..bd18c3c1 100644
@@ -6,6 +6,7 @@ CONFIG_PLATFORM_SIFIVE_FU740=y
 CONFIG_PLATFORM_SOPHGO_SG2042=y
 CONFIG_PLATFORM_STARFIVE_JH7110=y
 CONFIG_PLATFORM_THEAD=y
+CONFIG_FDT_CPPC=y
 CONFIG_FDT_GPIO=y
 CONFIG_FDT_GPIO_DESIGNWARE=y
 CONFIG_FDT_GPIO_SIFIVE=y
platform/generic/platform.c +2 -0
index 48228e67..6f830744 100644
@@ -17,6 +17,7 @@
 #include <sbi/sbi_string.h>
 #include <sbi/sbi_system.h>
 #include <sbi/sbi_tlb.h>
+#include <sbi_utils/cppc/fdt_cppc.h>
 #include <sbi_utils/fdt/fdt_domain.h>
 #include <sbi_utils/fdt/fdt_fixup.h>
 #include <sbi_utils/fdt/fdt_helper.h>
@@ -251,6 +252,7 @@ static int generic_early_init(bool cold_boot)
 		fdt_reset_init(fdt);
 		fdt_suspend_init(fdt);
 		fdt_hsm_init(fdt);
+		fdt_cppc_init(fdt);
 
 		if (semihosting_enabled())
 			rc = semihosting_init();
Signature · 1 line
2.43.0
author
#13 lore raw

PATCH v2 13/17 lib: utils/cppc: Add RPMI CPPC driver

In reply to Anup Patel

From: Subrahmanya Lingappa <[email protected]>

Add RPMI based driver for CPPC register read, write and probe.

---
 include/sbi_utils/mailbox/rpmi_msgprot.h | 105 +++++++
 lib/utils/cppc/Kconfig                   |   9 +
 lib/utils/cppc/fdt_cppc_rpmi.c           | 377 +++++++++++++++++++++++
 lib/utils/cppc/objects.mk                |   3 +
 platform/generic/configs/defconfig       |   1 +
 5 files changed, 495 insertions(+)
 create mode 100644 lib/utils/cppc/fdt_cppc_rpmi.c
include/sbi_utils/mailbox/rpmi_msgprot.h +105 -0
index 8e2b23e2..f7c80360 100644
@@ -200,6 +200,7 @@ enum rpmi_servicegroup_id {
 	RPMI_SRVGRP_SYSTEM_RESET = 0x0002,
 	RPMI_SRVGRP_SYSTEM_SUSPEND = 0x0003,
 	RPMI_SRVGRP_HSM = 0x0004,
+	RPMI_SRVGRP_CPPC = 0x0005,
 	RPMI_SRVGRP_ID_MAX_COUNT,
 
 	/* Reserved range for service groups */
@@ -406,4 +407,108 @@ struct rpmi_hsm_get_susp_info_resp {
 	u32 min_residency_us;
 };
 
+/** RPMI CPPC ServiceGroup Service IDs */
+enum rpmi_cppc_service_id {
+	RPMI_CPPC_SRV_ENABLE_NOTIFICATION = 0x01,
+	RPMI_CPPC_SRV_PROBE_REG = 0x02,
+	RPMI_CPPC_SRV_READ_REG = 0x03,
+	RPMI_CPPC_SRV_WRITE_REG = 0x04,
+	RPMI_CPPC_SRV_GET_FAST_CHANNEL_REGION = 0x05,
+	RPMI_CPPC_SRV_GET_FAST_CHANNEL_OFFSET = 0x06,
+	RPMI_CPPC_SRV_GET_HART_LIST = 0x07,
+	RPMI_CPPC_SRV_MAX_COUNT,
+};
+
+struct rpmi_cppc_probe_req {
+	u32 hart_id;
+	u32 reg_id;
+};
+
+struct rpmi_cppc_probe_resp {
+	s32 status;
+	u32 reg_len;
+};
+
+struct rpmi_cppc_read_reg_req {
+	u32 hart_id;
+	u32 reg_id;
+};
+
+struct rpmi_cppc_read_reg_resp {
+	s32 status;
+	u32 data_lo;
+	u32 data_hi;
+};
+
+struct rpmi_cppc_write_reg_req {
+	u32 hart_id;
+	u32 reg_id;
+	u32 data_lo;
+	u32 data_hi;
+};
+
+struct rpmi_cppc_write_reg_resp {
+	s32 status;
+};
+
+struct rpmi_cppc_get_fastchan_offset_req {
+	u32 hart_id;
+};
+
+struct rpmi_cppc_get_fastchan_offset_resp {
+	s32 status;
+	u32 fc_perf_request_offset_lo;
+	u32 fc_perf_request_offset_hi;
+	u32 fc_perf_feedback_offset_lo;
+	u32 fc_perf_feedback_offset_hi;
+};
+
+#define RPMI_CPPC_FAST_CHANNEL_CPPC_MODE_POS		3
+#define RPMI_CPPC_FAST_CHANNEL_CPPC_MODE_MASK		\
+			(3U << RPMI_CPPC_FAST_CHANNEL_CPPC_MODE_POS)
+#define RPMI_CPPC_FAST_CHANNEL_FLAGS_DB_WIDTH_POS	1
+#define RPMI_CPPC_FAST_CHANNEL_FLAGS_DB_WIDTH_MASK	\
+			(3U << RPMI_CPPC_FAST_CHANNEL_FLAGS_DB_WIDTH_POS)
+#define RPMI_CPPC_FAST_CHANNEL_FLAGS_DB_SUPPORTED	(1U << 0)
+
+struct rpmi_cppc_get_fastchan_region_resp {
+	s32 status;
+	u32 flags;
+	u32 region_addr_lo;
+	u32 region_addr_hi;
+	u32 region_size_lo;
+	u32 region_size_hi;
+	u32 db_addr_lo;
+	u32 db_addr_hi;
+	u32 db_setmask_lo;
+	u32 db_setmask_hi;
+	u32 db_preservemask_lo;
+	u32 db_preservemask_hi;
+};
+
+enum rpmi_cppc_fast_channel_db_width {
+	RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_8 = 0x0,
+	RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_16 = 0x1,
+	RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_32 = 0x2,
+	RPMI_CPPC_FAST_CHANNEL_DB_WIDTH_64 = 0x3,
+};
+
+enum rpmi_cppc_fast_channel_cppc_mode {
+	RPMI_CPPC_FAST_CHANNEL_CPPC_MODE_PASSIVE = 0x0,
+	RPMI_CPPC_FAST_CHANNEL_CPPC_MODE_ACTIVE = 0x1,
+	RPMI_CPPC_FAST_CHANNEL_CPPC_MODE_MAX_IDX,
+};
+
+struct rpmi_cppc_hart_list_req {
+	u32 start_index;
+};
+
+struct rpmi_cppc_hart_list_resp {
+	s32 status;
+	u32 remaining;
+	u32 returned;
+	/* remaining space need to be adjusted for the above 3 u32's */
+	u32 hartid[(RPMI_MSG_DATA_SIZE(RPMI_SLOT_SIZE_MIN) - (sizeof(u32) * 3)) / sizeof(u32)];
+};
+
 #endif /* !__RPMI_MSGPROT_H__ */
lib/utils/cppc/Kconfig +9 -0
index 08d1c97f..494f6894 100644
@@ -7,4 +7,13 @@ config FDT_CPPC
 	depends on FDT
 	default n
 
+if FDT_CPPC
+
+config FDT_CPPC_RPMI
+	bool "FDT RPMI CPPC driver"
+	depends on FDT_MAILBOX && RPMI_MAILBOX
+	default n
+
+endif
+
 endmenu
lib/utils/cppc/fdt_cppc_rpmi.c new file +377 -0

377 lines not on this page · raw message

lib/utils/cppc/objects.mk +3 -0
index fb37478a..07dc7d89 100644
@@ -9,3 +9,6 @@
 
 libsbiutils-objs-$(CONFIG_FDT_CPPC) += cppc/fdt_cppc.o
 libsbiutils-objs-$(CONFIG_FDT_CPPC) += cppc/fdt_cppc_drivers.carray.o
+
+carray-fdt_cppc_drivers-$(CONFIG_FDT_CPPC_RPMI) += fdt_cppc_rpmi
+libsbiutils-objs-$(CONFIG_FDT_CPPC_RPMI) += cppc/fdt_cppc_rpmi.o
platform/generic/configs/defconfig +1 -0
index bd18c3c1..384918f9 100644
@@ -7,6 +7,7 @@ CONFIG_PLATFORM_SOPHGO_SG2042=y
 CONFIG_PLATFORM_STARFIVE_JH7110=y
 CONFIG_PLATFORM_THEAD=y
 CONFIG_FDT_CPPC=y
+CONFIG_FDT_CPPC_RPMI=y
 CONFIG_FDT_GPIO=y
 CONFIG_FDT_GPIO_DESIGNWARE=y
 CONFIG_FDT_GPIO_SIFIVE=y
Signature · 1 line
2.43.0
author
#14 lore raw

PATCH v2 14/17 lib: sbi: Add SBI Message Proxy (MPXY) framework

In reply to Anup Patel

From: Rahul Pathak <[email protected]>

Introduce SBI Message Proxy (MPXY) framework which allows platform specific code or drivers to register message protocol specific channels.

This framework enables the supervisor software to send messages belonging to different message protocols via OpenSBI firmware.

---
 include/sbi/sbi_ecall_interface.h |   2 +
 include/sbi/sbi_error.h           |  15 +-
 include/sbi/sbi_mpxy.h            | 183 ++++++++
 include/sbi/sbi_platform.h        |  17 +
 lib/sbi/objects.mk                |   1 +
 lib/sbi/sbi_init.c                |   6 +
 lib/sbi/sbi_mpxy.c                | 698 ++++++++++++++++++++++++++++++
 7 files changed, 915 insertions(+), 7 deletions(-)
 create mode 100644 include/sbi/sbi_mpxy.h
 create mode 100644 lib/sbi/sbi_mpxy.c
include/sbi/sbi_ecall_interface.h +2 -0
index 3aa57466..90c4ce11 100644
@@ -432,6 +432,8 @@ enum sbi_sse_state {
 #define SBI_ERR_NO_SHMEM			-9
 #define SBI_ERR_INVALID_STATE			-10
 #define SBI_ERR_BAD_RANGE			-11
+#define SBI_ERR_TIMEOUT				-12
+#define SBI_ERR_IO				-13
 
 #define SBI_LAST_ERR				SBI_ERR_BAD_RANGE
 
include/sbi/sbi_error.h +8 -7
index fb78bf62..b40b3319 100644
@@ -26,16 +26,17 @@
 #define SBI_ENO_SHMEM		SBI_ERR_NO_SHMEM
 #define SBI_EINVALID_STATE	SBI_ERR_INVALID_STATE
 #define SBI_EBAD_RANGE		SBI_ERR_BAD_RANGE
+#define SBI_ETIMEOUT		SBI_ERR_TIMEOUT
+#define SBI_ETIMEDOUT		SBI_ERR_TIMEOUT
+#define SBI_EIO			SBI_ERR_IO
 
 #define SBI_ENODEV		-1000
 #define SBI_ENOSYS		-1001
-#define SBI_ETIMEDOUT		-1002
-#define SBI_EIO			-1003
-#define SBI_EILL		-1004
-#define SBI_ENOSPC		-1005
-#define SBI_ENOMEM		-1006
-#define SBI_EUNKNOWN		-1007
-#define SBI_ENOENT		-1008
+#define SBI_EILL		-1002
+#define SBI_ENOSPC		-1003
+#define SBI_ENOMEM		-1004
+#define SBI_EUNKNOWN		-1005
+#define SBI_ENOENT		-1006
 
 /* clang-format on */
 
include/sbi/sbi_mpxy.h new file +183 -0

183 lines not on this page · raw message

include/sbi/sbi_platform.h +17 -0
index dc852a5c..6d5fbc7d 100644
@@ -126,6 +126,9 @@ struct sbi_platform_operations {
 	/** Initialize platform timer during cold boot */
 	int (*timer_init)(void);
 
+	/** Initialize the platform Message Proxy(MPXY) driver */
+	int (*mpxy_init)(void);
+
 	/** Check if SBI vendor extension is implemented or not */
 	bool (*vendor_ext_check)(void);
 	/** platform specific SBI extension implementation provider */
@@ -582,6 +585,20 @@ static inline int sbi_platform_timer_init(const struct sbi_platform *plat)
 	return 0;
 }
 
+/**
+ * Initialize the platform Message Proxy drivers
+ *
+ * @param plat pointer to struct sbi_platform
+ *
+ * @return 0 on success and negative error code on failure
+ */
+static inline int sbi_platform_mpxy_init(const struct sbi_platform *plat)
+{
+	if (plat && sbi_platform_ops(plat)->mpxy_init)
+		return sbi_platform_ops(plat)->mpxy_init();
+	return 0;
+}
+
 /**
  * Check if SBI vendor extension is implemented or not.
  *
lib/sbi/objects.mk +1 -0
index a6f7c5fa..80b82f8e 100644
@@ -83,6 +83,7 @@ libsbi-objs-y += sbi_irqchip.o
 libsbi-objs-y += sbi_platform.o
 libsbi-objs-y += sbi_pmu.o
 libsbi-objs-y += sbi_dbtr.o
+libsbi-objs-y += sbi_mpxy.o
 libsbi-objs-y += sbi_scratch.o
 libsbi-objs-y += sbi_sse.o
 libsbi-objs-y += sbi_string.o
lib/sbi/sbi_init.c +6 -0
index 8a2cfaef..0736345d 100644
@@ -24,6 +24,7 @@
 #include <sbi/sbi_platform.h>
 #include <sbi/sbi_pmu.h>
 #include <sbi/sbi_dbtr.h>
+#include <sbi/sbi_mpxy.h>
 #include <sbi/sbi_sse.h>
 #include <sbi/sbi_system.h>
 #include <sbi/sbi_string.h>
@@ -311,6 +312,11 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
 		sbi_hart_hang();
 	}
 
+	rc = sbi_mpxy_init(scratch);
+	if (rc) {
+		sbi_printf("%s: mpxy init failed (error %d)\n", __func__, rc);
+		sbi_hart_hang();
+	}
 	/*
 	 * Note: Finalize domains after HSM initialization so that we
 	 * can startup non-root domains.
lib/sbi/sbi_mpxy.c new file +698 -0

698 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#15 lore raw

PATCH v2 15/17 lib: sbi: Implement SBI MPXY extension

In reply to Anup Patel

Implement the SBI MPXY extension which provides an SBI interface to the supervisor software for send messages via MPXY framework.

---
 include/sbi/sbi_ecall_interface.h | 10 +++++
 lib/sbi/Kconfig                   |  3 ++
 lib/sbi/objects.mk                |  3 ++
 lib/sbi/sbi_ecall_mpxy.c          | 68 +++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+)
 create mode 100644 lib/sbi/sbi_ecall_mpxy.c
include/sbi/sbi_ecall_interface.h +10 -0
index 90c4ce11..c015ed93 100644
@@ -35,6 +35,7 @@
 #define SBI_EXT_DBTR				0x44425452
 #define SBI_EXT_SSE				0x535345
 #define SBI_EXT_FWFT				0x46574654
+#define SBI_EXT_MPXY				0x4D505859
 
 /* SBI function IDs for BASE extension*/
 #define SBI_EXT_BASE_GET_SPEC_VERSION		0x0
@@ -410,6 +411,15 @@ enum sbi_sse_state {
 #define SBI_SSE_EVENT_GLOBAL_BIT		(1 << 15)
 #define SBI_SSE_EVENT_PLATFORM_BIT		(1 << 14)
 
+/* SBI function IDs for MPXY extension */
+#define SBI_EXT_MPXY_SET_SHMEM			0x0
+#define SBI_EXT_MPXY_GET_CHANNEL_IDS		0x1
+#define SBI_EXT_MPXY_READ_ATTRS			0x2
+#define SBI_EXT_MPXY_WRITE_ATTRS		0x3
+#define SBI_EXT_MPXY_SEND_MSG_WITH_RESP		0x4
+#define SBI_EXT_MPXY_SEND_MSG_NO_RESP		0x5
+#define SBI_EXT_MPXY_GET_NOTIFICATION_EVENTS	0x6
+
 /* SBI base specification related macros */
 #define SBI_SPEC_VERSION_MAJOR_OFFSET		24
 #define SBI_SPEC_VERSION_MAJOR_MASK		0x7f
lib/sbi/Kconfig +3 -0
index bd8ba2b6..c6cc04bc 100644
@@ -66,4 +66,7 @@ config SBI_ECALL_SSE
 	bool "SSE extension"
 	default y
 
+config SBI_ECALL_MPXY
+	bool "MPXY extension"
+	default y
 endmenu
lib/sbi/objects.mk +3 -0
index 80b82f8e..12e9e2bd 100644
@@ -61,6 +61,9 @@ libsbi-objs-$(CONFIG_SBI_ECALL_DBTR) += sbi_ecall_dbtr.o
 carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_SSE) += ecall_sse
 libsbi-objs-$(CONFIG_SBI_ECALL_SSE) += sbi_ecall_sse.o
 
+carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_MPXY) += ecall_mpxy
+libsbi-objs-$(CONFIG_SBI_ECALL_MPXY) += sbi_ecall_mpxy.o
+
 libsbi-objs-y += sbi_bitmap.o
 libsbi-objs-y += sbi_bitops.o
 libsbi-objs-y += sbi_console.o
lib/sbi/sbi_ecall_mpxy.c new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#16 lore raw

PATCH v2 16/17 lib: utils: Add simple FDT based MPXY driver framework

In reply to Anup Patel

The generic platform can have multiple MPXY drivers so add a simple FDT based MPXY driver framework.

---
 include/sbi_utils/mpxy/fdt_mpxy.h      | 26 ++++++++++++++++++++++++++
 lib/utils/Kconfig                      |  2 ++
 lib/utils/mpxy/Kconfig                 | 10 ++++++++++
 lib/utils/mpxy/fdt_mpxy.c              | 22 ++++++++++++++++++++++
 lib/utils/mpxy/fdt_mpxy_drivers.carray |  3 +++
 lib/utils/mpxy/objects.mk              | 11 +++++++++++
 platform/generic/configs/defconfig     |  1 +
 platform/generic/platform.c            | 10 ++++++++++
 8 files changed, 85 insertions(+)
 create mode 100644 include/sbi_utils/mpxy/fdt_mpxy.h
 create mode 100644 lib/utils/mpxy/Kconfig
 create mode 100644 lib/utils/mpxy/fdt_mpxy.c
 create mode 100644 lib/utils/mpxy/fdt_mpxy_drivers.carray
 create mode 100644 lib/utils/mpxy/objects.mk
include/sbi_utils/mpxy/fdt_mpxy.h new file +26 -0
new file mode 100644
index 00000000..2ba9d28f
@@ -0,0 +1,26 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#ifndef __FDT_MPXY_H__
+#define __FDT_MPXY_H__
+
+#include <sbi/sbi_types.h>
+#include <sbi_utils/fdt/fdt_driver.h>
+
+#ifdef CONFIG_FDT_MPXY
+
+void fdt_mpxy_init(const void *fdt);
+
+#else
+
+static inline void fdt_mpxy_init(const void *fdt) { }
+
+#endif
+
+#endif
lib/utils/Kconfig +2 -0
index 002d6f8f..901ba564 100644
@@ -32,4 +32,6 @@ source "$(OPENSBI_SRC_DIR)/lib/utils/sys/Kconfig"
 
 source "$(OPENSBI_SRC_DIR)/lib/utils/timer/Kconfig"
 
+source "$(OPENSBI_SRC_DIR)/lib/utils/mpxy/Kconfig"
+
 endmenu
lib/utils/mpxy/Kconfig new file +10 -0
new file mode 100644
index 00000000..d084b09a
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: BSD-2-Clause
+
+menu "MPXY Device Support"
+
+config FDT_MPXY
+	bool "FDT based MPXY drivers"
+	depends on FDT
+	default n
+
+endmenu
lib/utils/mpxy/fdt_mpxy.c new file +22 -0
new file mode 100644
index 00000000..6984ec74
@@ -0,0 +1,22 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#include <sbi_utils/mpxy/fdt_mpxy.h>
+
+/* List of FDT MPXY drivers generated at compile time */
+extern const struct fdt_driver *const fdt_mpxy_drivers[];
+
+void fdt_mpxy_init(const void *fdt)
+{
+	/*
+	 * Platforms might have multiple MPXY devices or might not
+	 * have any MPXY devices so don't fail.
+	 */
+	fdt_driver_init_all(fdt, fdt_mpxy_drivers);
+}
lib/utils/mpxy/fdt_mpxy_drivers.carray new file +3 -0
new file mode 100644
index 00000000..3cac0155
@@ -0,0 +1,3 @@
+HEADER: sbi_utils/mpxy/fdt_mpxy.h
+TYPE: const struct fdt_driver
+NAME: fdt_mpxy_drivers
lib/utils/mpxy/objects.mk new file +11 -0
new file mode 100644
index 00000000..43e73c94
@@ -0,0 +1,11 @@
+#
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2024 Ventana Micro Systems Inc.
+#
+# Authors:
+#   Anup Patel <[email protected]>
+#
+
+libsbiutils-objs-$(CONFIG_FDT_MPXY) += mpxy/fdt_mpxy.o
+libsbiutils-objs-$(CONFIG_FDT_MPXY) += mpxy/fdt_mpxy_drivers.carray.o
platform/generic/configs/defconfig +1 -0
index 384918f9..1f0880ee 100644
@@ -53,3 +53,4 @@ CONFIG_FDT_SUSPEND_RPMI=y
 CONFIG_FDT_TIMER=y
 CONFIG_FDT_TIMER_MTIMER=y
 CONFIG_FDT_TIMER_PLMT=y
+CONFIG_FDT_MPXY=y
platform/generic/platform.c +10 -0
index 6f830744..f7888b43 100644
@@ -17,6 +17,7 @@
 #include <sbi/sbi_string.h>
 #include <sbi/sbi_system.h>
 #include <sbi/sbi_tlb.h>
+#include <sbi_utils/mpxy/fdt_mpxy.h>
 #include <sbi_utils/cppc/fdt_cppc.h>
 #include <sbi_utils/fdt/fdt_domain.h>
 #include <sbi_utils/fdt/fdt_fixup.h>
@@ -414,6 +415,14 @@ static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx,
 	return evt_val;
 }
 
+static int generic_mpxy_init(void)
+{
+	const void *fdt = fdt_get_address();
+
+	fdt_mpxy_init(fdt);
+	return 0;
+}
+
 const struct sbi_platform_operations platform_ops = {
 	.cold_boot_allowed	= generic_cold_boot_allowed,
 	.nascent_init		= generic_nascent_init,
@@ -430,6 +439,7 @@ const struct sbi_platform_operations platform_ops = {
 	.get_tlbr_flush_limit	= generic_tlbr_flush_limit,
 	.get_tlb_num_entries	= generic_tlb_num_entries,
 	.timer_init		= fdt_timer_init,
+	.mpxy_init		= generic_mpxy_init,
 	.vendor_ext_check	= generic_vendor_ext_check,
 	.vendor_ext_provider	= generic_vendor_ext_provider,
 };
Signature · 1 line
2.43.0
author
#17 lore raw

PATCH v2 17/17 lib: utils/mpxy: Add RPMI client driver for MPXY

In reply to Anup Patel

From: Rahul Pathak <[email protected]>

Add a generic RPMI mailbox client driver which provides a MPXY channel. Initially, this driver only supports RPMI clock service group but can be extended to support multiple RPMI service groups.

---
 include/sbi_utils/mailbox/rpmi_msgprot.h |  93 +++++
 lib/utils/mpxy/Kconfig                   |   9 +
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c      | 442 +++++++++++++++++++++++
 lib/utils/mpxy/objects.mk                |   3 +
 platform/generic/configs/defconfig       |   1 +
 5 files changed, 548 insertions(+)
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
include/sbi_utils/mailbox/rpmi_msgprot.h +93 -0
index f7c80360..9575dc72 100644
@@ -201,6 +201,7 @@ enum rpmi_servicegroup_id {
 	RPMI_SRVGRP_SYSTEM_SUSPEND = 0x0003,
 	RPMI_SRVGRP_HSM = 0x0004,
 	RPMI_SRVGRP_CPPC = 0x0005,
+	RPMI_SRVGRP_CLOCK = 0x0007,
 	RPMI_SRVGRP_ID_MAX_COUNT,
 
 	/* Reserved range for service groups */
@@ -511,4 +512,96 @@ struct rpmi_cppc_hart_list_resp {
 	u32 hartid[(RPMI_MSG_DATA_SIZE(RPMI_SLOT_SIZE_MIN) - (sizeof(u32) * 3)) / sizeof(u32)];
 };
 
+/** RPMI Clock ServiceGroup Service IDs */
+enum rpmi_clock_service_id {
+	RPMI_CLOCK_SRV_ENABLE_NOTIFICATION = 0x01,
+	RPMI_CLOCK_SRV_GET_NUM_CLOCKS = 0x02,
+	RPMI_CLOCK_SRV_GET_ATTRIBUTES = 0x03,
+	RPMI_CLOCK_SRV_GET_SUPPORTED_RATES = 0x04,
+	RPMI_CLOCK_SRV_SET_CONFIG = 0x05,
+	RPMI_CLOCK_SRV_GET_CONFIG = 0x06,
+	RPMI_CLOCK_SRV_SET_RATE = 0x07,
+	RPMI_CLOCK_SRV_GET_RATE = 0x08,
+	RPMI_CLOCK_SRV_MAX_COUNT,
+};
+
+struct rpmi_clock_get_num_clocks_resp {
+	s32 status;
+	u32 num_clocks;
+};
+
+struct rpmi_clock_get_attributes_req {
+	u32 clock_id;
+};
+
+struct rpmi_clock_get_attributes_resp {
+	s32 status;
+#define RPMI_CLOCK_FLAGS_FORMAT_POS		30
+#define RPMI_CLOCK_FLAGS_FORMAT_MASK		\
+			(3U << RPMI_CLOCK_FLAGS_CLOCK_FORMAT_POS)
+#define RPMI_CLOCK_FLAGS_FORMAT_DISCRETE	0
+#define RPMI_CLOCK_FLAGS_FORMAT_LINEAR		1
+	u32 flags;
+	u32 num_rates;
+	u32 transition_latency;
+	u8 name[16];
+};
+
+struct rpmi_clock_get_supported_rates_req {
+	u32 clock_id;
+	u32 clock_rate_index;
+};
+
+struct rpmi_clock_get_supported_rates_resp {
+	s32 status;
+	u32 flags;
+	u32 remaining;
+	u32 returned;
+	u32 clock_rate[0];
+};
+
+struct rpmi_clock_set_config_req {
+	u32 clock_id;
+#define RPMI_CLOCK_CONFIG_ENABLE		(1U << 0)
+	u32 config;
+};
+
+struct rpmi_clock_set_config_resp {
+	s32 status;
+};
+
+struct rpmi_clock_get_config_req {
+	u32 clock_id;
+};
+
+struct rpmi_clock_get_config_resp {
+	s32 status;
+	u32 config;
+};
+
+struct rpmi_clock_set_rate_req {
+	u32 clock_id;
+#define RPMI_CLOCK_SET_RATE_FLAGS_MASK		(3U << 0)
+#define RPMI_CLOCK_SET_RATE_FLAGS_ROUND_DOWN	0
+#define RPMI_CLOCK_SET_RATE_FLAGS_ROUND_UP	1
+#define RPMI_CLOCK_SET_RATE_FLAGS_ROUND_PLAT	2
+	u32 flags;
+	u32 clock_rate_low;
+	u32 clock_rate_high;
+};
+
+struct rpmi_clock_set_rate_resp {
+	s32 status;
+};
+
+struct rpmi_clock_get_rate_req {
+	u32 clock_id;
+};
+
+struct rpmi_clock_get_rate_resp {
+	s32 status;
+	u32 clock_rate_low;
+	u32 clock_rate_high;
+};
+
 #endif /* !__RPMI_MSGPROT_H__ */
lib/utils/mpxy/Kconfig +9 -0
index d084b09a..131fb91a 100644
@@ -7,4 +7,13 @@ config FDT_MPXY
 	depends on FDT
 	default n
 
+if FDT_MPXY
+
+config FDT_MPXY_RPMI_MBOX
+	bool "FDT MPXY mailbox client driver"
+	depends on FDT_MAILBOX
+	default n
+
+endif
+
 endmenu
lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c new file +442 -0

442 lines not on this page · raw message

lib/utils/mpxy/objects.mk +3 -0
index 43e73c94..ccb28b55 100644
@@ -9,3 +9,6 @@
 
 libsbiutils-objs-$(CONFIG_FDT_MPXY) += mpxy/fdt_mpxy.o
 libsbiutils-objs-$(CONFIG_FDT_MPXY) += mpxy/fdt_mpxy_drivers.carray.o
+
+carray-fdt_mpxy_drivers-$(CONFIG_FDT_MPXY_RPMI_MBOX) += fdt_mpxy_rpmi_mbox
+libsbiutils-objs-$(CONFIG_FDT_MPXY_RPMI_MBOX) += mpxy/fdt_mpxy_rpmi_mbox.o
platform/generic/configs/defconfig +1 -0
index 1f0880ee..e23b38b2 100644
@@ -54,3 +54,4 @@ CONFIG_FDT_TIMER=y
 CONFIG_FDT_TIMER_MTIMER=y
 CONFIG_FDT_TIMER_PLMT=y
 CONFIG_FDT_MPXY=y
+CONFIG_FDT_MPXY_RPMI_MBOX=y
Signature · 1 line
2.43.0
Applied
#18 lore raw

v2 cover RPMI and SBI MPXY support for OpenSBI

In reply to Anup Patel
Quoted 42 lines · On Fri, Nov 29, 2024 at 9:21?PM Anup Patel <[email protected]> wrote:

This series adds RPMI and SBI MPXY support for OpenSBI. The RPMI service groups supported include system reset, system suspend, HSM, CPPC, and clock. The RPMI clock serivice group is exposed to supervisor software as an MPXY channel.

These patches can also be found in the rpmi_mpxy_v2 branch at:
https://github.com/avpatel/opensbi.git

To test these patches, use the dev-upstream branch of the following repos:
* https://github.com/ventanamicro/qemu.git
* https://github.com/ventanamicro/linux.git

To enable QEMU RPMI emulation (using librpmi) for virt machine, use "virt,rpmi=on" as the QEMU machine name.

Changes since v1:
- Rebased on latest OpenSBI
- Use the recently introduced helpers for generic driver initialization
- Updated RPMI drivers to match the latest RPMI specification
- Don't support fixed number of channels in RPMI shared memory mailbox driver
- Added new patch9 for support RPMI HSM based FDT fixup
- Improved arrangment of barrier in __smq_rx() and __smq_tx()

Anup Patel (8):
lib: utils/mailbox: Add generic mailbox library
lib: utils/mailbox: Add simple FDT based mailbox framework
lib: utils: Add simple FDT based system suspend driver framework
lib: utils/fdt: Allow dynamic registration of FDT fixup callbacks
lib: utils: Add simple FDT based HSM driver framework
lib: utils: Add simple FDT based CPPC driver framework
lib: sbi: Implement SBI MPXY extension
lib: utils: Add simple FDT based MPXY driver framework

Rahul Pathak (5):
lib: Increase ROOT_REGION_MAX to accomodate more memregions lib/utils: Add RPMI messaging protocol and shared memory transport
support
lib/utils: reset: Add RPMI System Reset driver
lib: sbi: Add SBI Message Proxy (MPXY) framework
lib: utils/mpxy: Add RPMI client driver for MPXY

Quoted 5 lines

Subrahmanya Lingappa (4):
lib: utils/suspend: Add RPMI system suspend driver
lib: sbi: Add optional resume address to hart suspend
lib: utils/hsm: Add RPMI HSM driver
lib: utils/cppc: Add RPMI CPPC driver

We plan to include the RPMI and MPXY drivers as experimental for the upcoming OpenSBI v1.6 release at the end of this month. There is still more work required in improving these drivers and related frameworks but that can happen incrementally over time.

Applied this series to the riscv/opensi repo.

Thanks,
Anup

Quoted 101 lines
 include/sbi/sbi_ecall_interface.h            |  12 +
 include/sbi/sbi_error.h                      |  15 +-
 include/sbi/sbi_hsm.h                        |   6 +-
 include/sbi/sbi_mpxy.h                       | 183 +++++
 include/sbi/sbi_platform.h                   |  17 +
 include/sbi_utils/cppc/fdt_cppc.h            |  26 +
 include/sbi_utils/fdt/fdt_fixup.h            |  15 +
 include/sbi_utils/hsm/fdt_hsm.h              |  26 +
 include/sbi_utils/mailbox/fdt_mailbox.h      |  35 +
 include/sbi_utils/mailbox/mailbox.h          | 180 +++++
 include/sbi_utils/mailbox/rpmi_mailbox.h     |  32 +
 include/sbi_utils/mailbox/rpmi_msgprot.h     | 607 +++++++++++++++
 include/sbi_utils/mpxy/fdt_mpxy.h            |  26 +
 include/sbi_utils/suspend/fdt_suspend.h      |  26 +
 lib/sbi/Kconfig                              |   3 +
 lib/sbi/objects.mk                           |   4 +
 lib/sbi/sbi_domain.c                         |   2 +-
 lib/sbi/sbi_ecall_mpxy.c                     |  68 ++
 lib/sbi/sbi_hsm.c                            |   6 +-
 lib/sbi/sbi_init.c                           |   6 +
 lib/sbi/sbi_mpxy.c                           | 698 +++++++++++++++++
 lib/utils/Kconfig                            |  10 +
 lib/utils/cppc/Kconfig                       |  19 +
 lib/utils/cppc/fdt_cppc.c                    |  22 +
 lib/utils/cppc/fdt_cppc_drivers.carray       |   3 +
 lib/utils/cppc/fdt_cppc_rpmi.c               | 377 +++++++++
 lib/utils/cppc/objects.mk                    |  14 +
 lib/utils/fdt/fdt_fixup.c                    |  33 +
 lib/utils/hsm/Kconfig                        |  19 +
 lib/utils/hsm/fdt_hsm.c                      |  22 +
 lib/utils/hsm/fdt_hsm_drivers.carray         |   3 +
 lib/utils/hsm/fdt_hsm_rpmi.c                 | 362 +++++++++
 lib/utils/hsm/objects.mk                     |  14 +
 lib/utils/mailbox/Kconfig                    |  29 +
 lib/utils/mailbox/fdt_mailbox.c              |  96 +++
 lib/utils/mailbox/fdt_mailbox_drivers.carray |   5 +
 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c   | 773 +++++++++++++++++++
 lib/utils/mailbox/mailbox.c                  | 138 ++++
 lib/utils/mailbox/objects.mk                 |  18 +
 lib/utils/mailbox/rpmi_mailbox.c             |  91 +++
 lib/utils/mpxy/Kconfig                       |  19 +
 lib/utils/mpxy/fdt_mpxy.c                    |  22 +
 lib/utils/mpxy/fdt_mpxy_drivers.carray       |   3 +
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c          | 442 +++++++++++
 lib/utils/mpxy/objects.mk                    |  14 +
 lib/utils/reset/Kconfig                      |   5 +
 lib/utils/reset/fdt_reset_rpmi.c             | 141 ++++
 lib/utils/reset/objects.mk                   |   3 +
 lib/utils/suspend/Kconfig                    |  19 +
 lib/utils/suspend/fdt_suspend.c              |  22 +
 lib/utils/suspend/fdt_suspend_drivers.carray |   3 +
 lib/utils/suspend/fdt_suspend_rpmi.c         | 138 ++++
 lib/utils/suspend/objects.mk                 |  14 +
 platform/generic/allwinner/sun20i-d1.c       |   2 +-
 platform/generic/configs/defconfig           |  12 +
 platform/generic/platform.c                  |  16 +
 56 files changed, 4903 insertions(+), 13 deletions(-)
 create mode 100644 include/sbi/sbi_mpxy.h
 create mode 100644 include/sbi_utils/cppc/fdt_cppc.h
 create mode 100644 include/sbi_utils/hsm/fdt_hsm.h
 create mode 100644 include/sbi_utils/mailbox/fdt_mailbox.h
 create mode 100644 include/sbi_utils/mailbox/mailbox.h
 create mode 100644 include/sbi_utils/mailbox/rpmi_mailbox.h
 create mode 100644 include/sbi_utils/mailbox/rpmi_msgprot.h
 create mode 100644 include/sbi_utils/mpxy/fdt_mpxy.h
 create mode 100644 include/sbi_utils/suspend/fdt_suspend.h
 create mode 100644 lib/sbi/sbi_ecall_mpxy.c
 create mode 100644 lib/sbi/sbi_mpxy.c
 create mode 100644 lib/utils/cppc/Kconfig
 create mode 100644 lib/utils/cppc/fdt_cppc.c
 create mode 100644 lib/utils/cppc/fdt_cppc_drivers.carray
 create mode 100644 lib/utils/cppc/fdt_cppc_rpmi.c
 create mode 100644 lib/utils/cppc/objects.mk
 create mode 100644 lib/utils/hsm/Kconfig
 create mode 100644 lib/utils/hsm/fdt_hsm.c
 create mode 100644 lib/utils/hsm/fdt_hsm_drivers.carray
 create mode 100644 lib/utils/hsm/fdt_hsm_rpmi.c
 create mode 100644 lib/utils/hsm/objects.mk
 create mode 100644 lib/utils/mailbox/Kconfig
 create mode 100644 lib/utils/mailbox/fdt_mailbox.c
 create mode 100644 lib/utils/mailbox/fdt_mailbox_drivers.carray
 create mode 100644 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
 create mode 100644 lib/utils/mailbox/mailbox.c
 create mode 100644 lib/utils/mailbox/objects.mk
 create mode 100644 lib/utils/mailbox/rpmi_mailbox.c
 create mode 100644 lib/utils/mpxy/Kconfig
 create mode 100644 lib/utils/mpxy/fdt_mpxy.c
 create mode 100644 lib/utils/mpxy/fdt_mpxy_drivers.carray
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
 create mode 100644 lib/utils/mpxy/objects.mk
 create mode 100644 lib/utils/reset/fdt_reset_rpmi.c
 create mode 100644 lib/utils/suspend/Kconfig
 create mode 100644 lib/utils/suspend/fdt_suspend.c
 create mode 100644 lib/utils/suspend/fdt_suspend_drivers.carray
 create mode 100644 lib/utils/suspend/fdt_suspend_rpmi.c
 create mode 100644 lib/utils/suspend/objects.mk

--
2.43.0

#19 lore raw

v2 cover RPMI and SBI MPXY support for OpenSBI

Hi Anup,

Quoted 49 lines · Anup Patel
Quoted 42 lines · On Fri, Nov 29, 2024 at 9:21?PM Anup Patel <[email protected]> wrote:

This series adds RPMI and SBI MPXY support for OpenSBI. The RPMI service groups supported include system reset, system suspend, HSM, CPPC, and clock. The RPMI clock serivice group is exposed to supervisor software as an MPXY channel.

These patches can also be found in the rpmi_mpxy_v2 branch at:
https://github.com/avpatel/opensbi.git

To test these patches, use the dev-upstream branch of the following repos:
* https://github.com/ventanamicro/qemu.git
* https://github.com/ventanamicro/linux.git

To enable QEMU RPMI emulation (using librpmi) for virt machine, use "virt,rpmi=on" as the QEMU machine name.

Changes since v1:
- Rebased on latest OpenSBI
- Use the recently introduced helpers for generic driver initialization
- Updated RPMI drivers to match the latest RPMI specification
- Don't support fixed number of channels in RPMI shared memory mailbox driver
- Added new patch9 for support RPMI HSM based FDT fixup
- Improved arrangment of barrier in __smq_rx() and __smq_tx()

Anup Patel (8):
lib: utils/mailbox: Add generic mailbox library
lib: utils/mailbox: Add simple FDT based mailbox framework
lib: utils: Add simple FDT based system suspend driver framework
lib: utils/fdt: Allow dynamic registration of FDT fixup callbacks
lib: utils: Add simple FDT based HSM driver framework
lib: utils: Add simple FDT based CPPC driver framework
lib: sbi: Implement SBI MPXY extension
lib: utils: Add simple FDT based MPXY driver framework

Rahul Pathak (5):
lib: Increase ROOT_REGION_MAX to accomodate more memregions lib/utils: Add RPMI messaging protocol and shared memory transport
support
lib/utils: reset: Add RPMI System Reset driver
lib: sbi: Add SBI Message Proxy (MPXY) framework
lib: utils/mpxy: Add RPMI client driver for MPXY

Quoted 5 lines

Subrahmanya Lingappa (4):
lib: utils/suspend: Add RPMI system suspend driver
lib: sbi: Add optional resume address to hart suspend
lib: utils/hsm: Add RPMI HSM driver
lib: utils/cppc: Add RPMI CPPC driver

Quoted 4 lines

We plan to include the RPMI and MPXY drivers as experimental for the upcoming OpenSBI v1.6 release at the end of this month. There is still more work required in improving these drivers and related frameworks but that can happen incrementally over time.

I haven't taken the time to fully review this series yet because it's 5000 lines of new code and the RPMI spec isn't even frozen, but I have at least two major concerns.

1) Where is the documentation for the devicetree compatible strings added by this series? I don't see any attempt to get the bindings reviewed and accepted.
https://lore.kernel.org/linux-devicetree/?q=rpmi shows nothing. This isn't something that can just be changed incrementally. It's not acceptable to break DT ABI. It's not okay to unilaterally make up a devicetree interface without documenting it and getting feedback through the appropriate process. This is especially true since OpenSBI isn't the owner of the RPMI spec.

2) OpenSBI absolutely must not claim to implement MPXY MSG_PROT_ID 0 (RPMI) version 1.0. That specification does not exist. RPMI is not frozen and is still actively undergoing changes. If this is an experimental MPXY protocol, it should use an experimental message protocol ID.

I have no problem with merging experimental code and iterating on it, but such code must not create ABI surface that has stability guarantees.

Regards,
Samuel

Quoted 107 lines

Applied this series to the riscv/opensi repo.

Thanks,
Anup

Quoted 101 lines
 include/sbi/sbi_ecall_interface.h            |  12 +
 include/sbi/sbi_error.h                      |  15 +-
 include/sbi/sbi_hsm.h                        |   6 +-
 include/sbi/sbi_mpxy.h                       | 183 +++++
 include/sbi/sbi_platform.h                   |  17 +
 include/sbi_utils/cppc/fdt_cppc.h            |  26 +
 include/sbi_utils/fdt/fdt_fixup.h            |  15 +
 include/sbi_utils/hsm/fdt_hsm.h              |  26 +
 include/sbi_utils/mailbox/fdt_mailbox.h      |  35 +
 include/sbi_utils/mailbox/mailbox.h          | 180 +++++
 include/sbi_utils/mailbox/rpmi_mailbox.h     |  32 +
 include/sbi_utils/mailbox/rpmi_msgprot.h     | 607 +++++++++++++++
 include/sbi_utils/mpxy/fdt_mpxy.h            |  26 +
 include/sbi_utils/suspend/fdt_suspend.h      |  26 +
 lib/sbi/Kconfig                              |   3 +
 lib/sbi/objects.mk                           |   4 +
 lib/sbi/sbi_domain.c                         |   2 +-
 lib/sbi/sbi_ecall_mpxy.c                     |  68 ++
 lib/sbi/sbi_hsm.c                            |   6 +-
 lib/sbi/sbi_init.c                           |   6 +
 lib/sbi/sbi_mpxy.c                           | 698 +++++++++++++++++
 lib/utils/Kconfig                            |  10 +
 lib/utils/cppc/Kconfig                       |  19 +
 lib/utils/cppc/fdt_cppc.c                    |  22 +
 lib/utils/cppc/fdt_cppc_drivers.carray       |   3 +
 lib/utils/cppc/fdt_cppc_rpmi.c               | 377 +++++++++
 lib/utils/cppc/objects.mk                    |  14 +
 lib/utils/fdt/fdt_fixup.c                    |  33 +
 lib/utils/hsm/Kconfig                        |  19 +
 lib/utils/hsm/fdt_hsm.c                      |  22 +
 lib/utils/hsm/fdt_hsm_drivers.carray         |   3 +
 lib/utils/hsm/fdt_hsm_rpmi.c                 | 362 +++++++++
 lib/utils/hsm/objects.mk                     |  14 +
 lib/utils/mailbox/Kconfig                    |  29 +
 lib/utils/mailbox/fdt_mailbox.c              |  96 +++
 lib/utils/mailbox/fdt_mailbox_drivers.carray |   5 +
 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c   | 773 +++++++++++++++++++
 lib/utils/mailbox/mailbox.c                  | 138 ++++
 lib/utils/mailbox/objects.mk                 |  18 +
 lib/utils/mailbox/rpmi_mailbox.c             |  91 +++
 lib/utils/mpxy/Kconfig                       |  19 +
 lib/utils/mpxy/fdt_mpxy.c                    |  22 +
 lib/utils/mpxy/fdt_mpxy_drivers.carray       |   3 +
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c          | 442 +++++++++++
 lib/utils/mpxy/objects.mk                    |  14 +
 lib/utils/reset/Kconfig                      |   5 +
 lib/utils/reset/fdt_reset_rpmi.c             | 141 ++++
 lib/utils/reset/objects.mk                   |   3 +
 lib/utils/suspend/Kconfig                    |  19 +
 lib/utils/suspend/fdt_suspend.c              |  22 +
 lib/utils/suspend/fdt_suspend_drivers.carray |   3 +
 lib/utils/suspend/fdt_suspend_rpmi.c         | 138 ++++
 lib/utils/suspend/objects.mk                 |  14 +
 platform/generic/allwinner/sun20i-d1.c       |   2 +-
 platform/generic/configs/defconfig           |  12 +
 platform/generic/platform.c                  |  16 +
 56 files changed, 4903 insertions(+), 13 deletions(-)
 create mode 100644 include/sbi/sbi_mpxy.h
 create mode 100644 include/sbi_utils/cppc/fdt_cppc.h
 create mode 100644 include/sbi_utils/hsm/fdt_hsm.h
 create mode 100644 include/sbi_utils/mailbox/fdt_mailbox.h
 create mode 100644 include/sbi_utils/mailbox/mailbox.h
 create mode 100644 include/sbi_utils/mailbox/rpmi_mailbox.h
 create mode 100644 include/sbi_utils/mailbox/rpmi_msgprot.h
 create mode 100644 include/sbi_utils/mpxy/fdt_mpxy.h
 create mode 100644 include/sbi_utils/suspend/fdt_suspend.h
 create mode 100644 lib/sbi/sbi_ecall_mpxy.c
 create mode 100644 lib/sbi/sbi_mpxy.c
 create mode 100644 lib/utils/cppc/Kconfig
 create mode 100644 lib/utils/cppc/fdt_cppc.c
 create mode 100644 lib/utils/cppc/fdt_cppc_drivers.carray
 create mode 100644 lib/utils/cppc/fdt_cppc_rpmi.c
 create mode 100644 lib/utils/cppc/objects.mk
 create mode 100644 lib/utils/hsm/Kconfig
 create mode 100644 lib/utils/hsm/fdt_hsm.c
 create mode 100644 lib/utils/hsm/fdt_hsm_drivers.carray
 create mode 100644 lib/utils/hsm/fdt_hsm_rpmi.c
 create mode 100644 lib/utils/hsm/objects.mk
 create mode 100644 lib/utils/mailbox/Kconfig
 create mode 100644 lib/utils/mailbox/fdt_mailbox.c
 create mode 100644 lib/utils/mailbox/fdt_mailbox_drivers.carray
 create mode 100644 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
 create mode 100644 lib/utils/mailbox/mailbox.c
 create mode 100644 lib/utils/mailbox/objects.mk
 create mode 100644 lib/utils/mailbox/rpmi_mailbox.c
 create mode 100644 lib/utils/mpxy/Kconfig
 create mode 100644 lib/utils/mpxy/fdt_mpxy.c
 create mode 100644 lib/utils/mpxy/fdt_mpxy_drivers.carray
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
 create mode 100644 lib/utils/mpxy/objects.mk
 create mode 100644 lib/utils/reset/fdt_reset_rpmi.c
 create mode 100644 lib/utils/suspend/Kconfig
 create mode 100644 lib/utils/suspend/fdt_suspend.c
 create mode 100644 lib/utils/suspend/fdt_suspend_drivers.carray
 create mode 100644 lib/utils/suspend/fdt_suspend_rpmi.c
 create mode 100644 lib/utils/suspend/objects.mk

--
2.43.0

#20 lore raw

v2 cover RPMI and SBI MPXY support for OpenSBI

Quoted 53 lines · On Fri, Dec 6, 2024 at 10:38?AM Samuel Holland <[email protected]>…

Hi Anup,

Quoted 49 lines · Anup Patel
Quoted 47 lines · On Fri, Nov 29, 2024 at 9:21?PM Anup Patel <[email protected]> wrote:

This series adds RPMI and SBI MPXY support for OpenSBI. The RPMI service groups supported include system reset, system suspend, HSM, CPPC, and clock. The RPMI clock serivice group is exposed to supervisor software as an MPXY channel.

These patches can also be found in the rpmi_mpxy_v2 branch at:
https://github.com/avpatel/opensbi.git

To test these patches, use the dev-upstream branch of the following repos:
* https://github.com/ventanamicro/qemu.git
* https://github.com/ventanamicro/linux.git

To enable QEMU RPMI emulation (using librpmi) for virt machine, use "virt,rpmi=on" as the QEMU machine name.

Changes since v1:
- Rebased on latest OpenSBI
- Use the recently introduced helpers for generic driver initialization
- Updated RPMI drivers to match the latest RPMI specification
- Don't support fixed number of channels in RPMI shared memory mailbox driver
- Added new patch9 for support RPMI HSM based FDT fixup
- Improved arrangment of barrier in __smq_rx() and __smq_tx()

Anup Patel (8):
lib: utils/mailbox: Add generic mailbox library
lib: utils/mailbox: Add simple FDT based mailbox framework
lib: utils: Add simple FDT based system suspend driver framework
lib: utils/fdt: Allow dynamic registration of FDT fixup callbacks
lib: utils: Add simple FDT based HSM driver framework
lib: utils: Add simple FDT based CPPC driver framework
lib: sbi: Implement SBI MPXY extension
lib: utils: Add simple FDT based MPXY driver framework

Rahul Pathak (5):
lib: Increase ROOT_REGION_MAX to accomodate more memregions lib/utils: Add RPMI messaging protocol and shared memory transport
support
lib/utils: reset: Add RPMI System Reset driver
lib: sbi: Add SBI Message Proxy (MPXY) framework
lib: utils/mpxy: Add RPMI client driver for MPXY

Subrahmanya Lingappa (4):
lib: utils/suspend: Add RPMI system suspend driver
lib: sbi: Add optional resume address to hart suspend
lib: utils/hsm: Add RPMI HSM driver
lib: utils/cppc: Add RPMI CPPC driver

Quoted 8 lines
Quoted 4 lines

We plan to include the RPMI and MPXY drivers as experimental for the upcoming OpenSBI v1.6 release at the end of this month. There is still more work required in improving these drivers and related frameworks but that can happen incrementally over time.

I haven't taken the time to fully review this series yet because it's 5000 lines of new code and the RPMI spec isn't even frozen, but I have at least two major concerns.

The v1 of this series is available on the OpenSBI mailing list since 6th August 2024. Also, unlike kernel, OpenSBI only requires the specs to be in a stable state for accepting patches as experimental. This has been the policy for many years now.

Quoted 8 lines

1) Where is the documentation for the devicetree compatible strings added by this series? I don't see any attempt to get the bindings reviewed and accepted.
https://lore.kernel.org/linux-devicetree/?q=rpmi shows nothing. This isn't something that can just be changed incrementally. It's not acceptable to break DT ABI. It's not okay to unilaterally make up a devicetree interface without documenting it and getting feedback through the appropriate process. This is especially true since OpenSBI isn't the owner of the RPMI spec.

OpenSBI has accepted experimental drivers in the past and the expectation is that people will update the bindings in OpenSBI once finalized on LKML. The drivers being "experimental" means users should assume that everything (including DT bindings) can change.

We do have kernel RFC series in-development for getting early feedback on device tree bindings and kernel drivers. I plan to send it out this week or early next week.

Quoted 5 lines

2) OpenSBI absolutely must not claim to implement MPXY MSG_PROT_ID 0 (RPMI) version 1.0. That specification does not exist. RPMI is not frozen and is still actively undergoing changes. If this is an experimental MPXY protocol, it should use an experimental message protocol ID.

The whole SBI MPXY extension is experimental until the SBI v3.0 spec is frozen so RPMI v1.0 being accessed via SBI MPXY channel is also experimental.

Quoted 3 lines

I have no problem with merging experimental code and iterating on it, but such code must not create ABI surface that has stability guarantees.

Historically, we have always accepted new SBI extensions as experimental ABI once the corresponding SBI spec is stable enough. We only change the advertised SBI spec version in OpenSBI only after the SBI spec is frozen.

Regards,
Anup

Quoted 112 lines

Regards,
Samuel

Quoted 107 lines

Applied this series to the riscv/opensi repo.

Thanks,
Anup

Quoted 101 lines
 include/sbi/sbi_ecall_interface.h            |  12 +
 include/sbi/sbi_error.h                      |  15 +-
 include/sbi/sbi_hsm.h                        |   6 +-
 include/sbi/sbi_mpxy.h                       | 183 +++++
 include/sbi/sbi_platform.h                   |  17 +
 include/sbi_utils/cppc/fdt_cppc.h            |  26 +
 include/sbi_utils/fdt/fdt_fixup.h            |  15 +
 include/sbi_utils/hsm/fdt_hsm.h              |  26 +
 include/sbi_utils/mailbox/fdt_mailbox.h      |  35 +
 include/sbi_utils/mailbox/mailbox.h          | 180 +++++
 include/sbi_utils/mailbox/rpmi_mailbox.h     |  32 +
 include/sbi_utils/mailbox/rpmi_msgprot.h     | 607 +++++++++++++++
 include/sbi_utils/mpxy/fdt_mpxy.h            |  26 +
 include/sbi_utils/suspend/fdt_suspend.h      |  26 +
 lib/sbi/Kconfig                              |   3 +
 lib/sbi/objects.mk                           |   4 +
 lib/sbi/sbi_domain.c                         |   2 +-
 lib/sbi/sbi_ecall_mpxy.c                     |  68 ++
 lib/sbi/sbi_hsm.c                            |   6 +-
 lib/sbi/sbi_init.c                           |   6 +
 lib/sbi/sbi_mpxy.c                           | 698 +++++++++++++++++
 lib/utils/Kconfig                            |  10 +
 lib/utils/cppc/Kconfig                       |  19 +
 lib/utils/cppc/fdt_cppc.c                    |  22 +
 lib/utils/cppc/fdt_cppc_drivers.carray       |   3 +
 lib/utils/cppc/fdt_cppc_rpmi.c               | 377 +++++++++
 lib/utils/cppc/objects.mk                    |  14 +
 lib/utils/fdt/fdt_fixup.c                    |  33 +
 lib/utils/hsm/Kconfig                        |  19 +
 lib/utils/hsm/fdt_hsm.c                      |  22 +
 lib/utils/hsm/fdt_hsm_drivers.carray         |   3 +
 lib/utils/hsm/fdt_hsm_rpmi.c                 | 362 +++++++++
 lib/utils/hsm/objects.mk                     |  14 +
 lib/utils/mailbox/Kconfig                    |  29 +
 lib/utils/mailbox/fdt_mailbox.c              |  96 +++
 lib/utils/mailbox/fdt_mailbox_drivers.carray |   5 +
 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c   | 773 +++++++++++++++++++
 lib/utils/mailbox/mailbox.c                  | 138 ++++
 lib/utils/mailbox/objects.mk                 |  18 +
 lib/utils/mailbox/rpmi_mailbox.c             |  91 +++
 lib/utils/mpxy/Kconfig                       |  19 +
 lib/utils/mpxy/fdt_mpxy.c                    |  22 +
 lib/utils/mpxy/fdt_mpxy_drivers.carray       |   3 +
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c          | 442 +++++++++++
 lib/utils/mpxy/objects.mk                    |  14 +
 lib/utils/reset/Kconfig                      |   5 +
 lib/utils/reset/fdt_reset_rpmi.c             | 141 ++++
 lib/utils/reset/objects.mk                   |   3 +
 lib/utils/suspend/Kconfig                    |  19 +
 lib/utils/suspend/fdt_suspend.c              |  22 +
 lib/utils/suspend/fdt_suspend_drivers.carray |   3 +
 lib/utils/suspend/fdt_suspend_rpmi.c         | 138 ++++
 lib/utils/suspend/objects.mk                 |  14 +
 platform/generic/allwinner/sun20i-d1.c       |   2 +-
 platform/generic/configs/defconfig           |  12 +
 platform/generic/platform.c                  |  16 +
 56 files changed, 4903 insertions(+), 13 deletions(-)
 create mode 100644 include/sbi/sbi_mpxy.h
 create mode 100644 include/sbi_utils/cppc/fdt_cppc.h
 create mode 100644 include/sbi_utils/hsm/fdt_hsm.h
 create mode 100644 include/sbi_utils/mailbox/fdt_mailbox.h
 create mode 100644 include/sbi_utils/mailbox/mailbox.h
 create mode 100644 include/sbi_utils/mailbox/rpmi_mailbox.h
 create mode 100644 include/sbi_utils/mailbox/rpmi_msgprot.h
 create mode 100644 include/sbi_utils/mpxy/fdt_mpxy.h
 create mode 100644 include/sbi_utils/suspend/fdt_suspend.h
 create mode 100644 lib/sbi/sbi_ecall_mpxy.c
 create mode 100644 lib/sbi/sbi_mpxy.c
 create mode 100644 lib/utils/cppc/Kconfig
 create mode 100644 lib/utils/cppc/fdt_cppc.c
 create mode 100644 lib/utils/cppc/fdt_cppc_drivers.carray
 create mode 100644 lib/utils/cppc/fdt_cppc_rpmi.c
 create mode 100644 lib/utils/cppc/objects.mk
 create mode 100644 lib/utils/hsm/Kconfig
 create mode 100644 lib/utils/hsm/fdt_hsm.c
 create mode 100644 lib/utils/hsm/fdt_hsm_drivers.carray
 create mode 100644 lib/utils/hsm/fdt_hsm_rpmi.c
 create mode 100644 lib/utils/hsm/objects.mk
 create mode 100644 lib/utils/mailbox/Kconfig
 create mode 100644 lib/utils/mailbox/fdt_mailbox.c
 create mode 100644 lib/utils/mailbox/fdt_mailbox_drivers.carray
 create mode 100644 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
 create mode 100644 lib/utils/mailbox/mailbox.c
 create mode 100644 lib/utils/mailbox/objects.mk
 create mode 100644 lib/utils/mailbox/rpmi_mailbox.c
 create mode 100644 lib/utils/mpxy/Kconfig
 create mode 100644 lib/utils/mpxy/fdt_mpxy.c
 create mode 100644 lib/utils/mpxy/fdt_mpxy_drivers.carray
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
 create mode 100644 lib/utils/mpxy/objects.mk
 create mode 100644 lib/utils/reset/fdt_reset_rpmi.c
 create mode 100644 lib/utils/suspend/Kconfig
 create mode 100644 lib/utils/suspend/fdt_suspend.c
 create mode 100644 lib/utils/suspend/fdt_suspend_drivers.carray
 create mode 100644 lib/utils/suspend/fdt_suspend_rpmi.c
 create mode 100644 lib/utils/suspend/objects.mk

--
2.43.0

#21 lore raw

v2 cover RPMI and SBI MPXY support for OpenSBI

Hi Anup,

Quoted 57 lines · Anup Patel
Quoted 55 lines · On Fri, Dec 6, 2024 at 10:38?AM Samuel Holland <[email protected]>…
Quoted 53 lines · Anup Patel
Quoted 42 lines · On Fri, Nov 29, 2024 at 9:21?PM Anup Patel <[email protected]> wrote:

This series adds RPMI and SBI MPXY support for OpenSBI. The RPMI service groups supported include system reset, system suspend, HSM, CPPC, and clock. The RPMI clock serivice group is exposed to supervisor software as an MPXY channel.

These patches can also be found in the rpmi_mpxy_v2 branch at:
https://github.com/avpatel/opensbi.git

To test these patches, use the dev-upstream branch of the following repos:
* https://github.com/ventanamicro/qemu.git
* https://github.com/ventanamicro/linux.git

To enable QEMU RPMI emulation (using librpmi) for virt machine, use "virt,rpmi=on" as the QEMU machine name.

Changes since v1:
- Rebased on latest OpenSBI
- Use the recently introduced helpers for generic driver initialization
- Updated RPMI drivers to match the latest RPMI specification
- Don't support fixed number of channels in RPMI shared memory mailbox driver
- Added new patch9 for support RPMI HSM based FDT fixup
- Improved arrangment of barrier in __smq_rx() and __smq_tx()

Anup Patel (8):
lib: utils/mailbox: Add generic mailbox library
lib: utils/mailbox: Add simple FDT based mailbox framework
lib: utils: Add simple FDT based system suspend driver framework
lib: utils/fdt: Allow dynamic registration of FDT fixup callbacks
lib: utils: Add simple FDT based HSM driver framework
lib: utils: Add simple FDT based CPPC driver framework
lib: sbi: Implement SBI MPXY extension
lib: utils: Add simple FDT based MPXY driver framework

Rahul Pathak (5):
lib: Increase ROOT_REGION_MAX to accomodate more memregions lib/utils: Add RPMI messaging protocol and shared memory transport
support
lib/utils: reset: Add RPMI System Reset driver
lib: sbi: Add SBI Message Proxy (MPXY) framework
lib: utils/mpxy: Add RPMI client driver for MPXY

Quoted 5 lines

Subrahmanya Lingappa (4):
lib: utils/suspend: Add RPMI system suspend driver
lib: sbi: Add optional resume address to hart suspend
lib: utils/hsm: Add RPMI HSM driver
lib: utils/cppc: Add RPMI CPPC driver

We plan to include the RPMI and MPXY drivers as experimental for the upcoming OpenSBI v1.6 release at the end of this month. There is still more work required in improving these drivers and related frameworks but that can happen incrementally over time.

Quoted 8 lines
Quoted 3 lines

I haven't taken the time to fully review this series yet because it's 5000 lines of new code and the RPMI spec isn't even frozen, but I have at least two major concerns.

The v1 of this series is available on the OpenSBI mailing list since 6th August 2024. Also, unlike kernel, OpenSBI only requires the specs to be in a stable state for accepting patches as experimental. This has been the policy for many years now.

Alright, then this is my mistake for waiting too long to review the driver code. I generally assume that DT bindings will go through several iterations before being accepted, and binding changes will require updates to the driver code, so there's not much point in reviewing drivers until the bindings have stabilized.

Quoted 8 lines
Quoted 7 lines

1) Where is the documentation for the devicetree compatible strings added by this series? I don't see any attempt to get the bindings reviewed and accepted.
https://lore.kernel.org/linux-devicetree/?q=rpmi shows nothing. This isn't something that can just be changed incrementally. It's not acceptable to break DT ABI. It's not okay to unilaterally make up a devicetree interface without documenting it and getting feedback through the appropriate process. This is especially true since OpenSBI isn't the owner of the RPMI spec.

Quoted 5 lines

OpenSBI has accepted experimental drivers in the past and the expectation is that people will update the bindings in OpenSBI once finalized on LKML. The drivers being "experimental" means users should assume that everything (including DT bindings) can change.

OK, if that is the policy, then we need to make it obvious which drivers are experimental, and which ones have stability guarantees. I sent a patch doing this, that I hope can be merged for v1.6:

https://lists.infradead.org/pipermail/opensbi/2024-December/007830.html

Quoted 3 lines

We do have kernel RFC series in-development for getting early feedback on device tree bindings and kernel drivers. I plan to send it out this week or early next week.

Thanks! That will be helpful. I don't think I've seen this series yet. Did I miss it?

Quoted 8 lines
Quoted 4 lines

2) OpenSBI absolutely must not claim to implement MPXY MSG_PROT_ID 0 (RPMI) version 1.0. That specification does not exist. RPMI is not frozen and is still actively undergoing changes. If this is an experimental MPXY protocol, it should use an experimental message protocol ID.

The whole SBI MPXY extension is experimental until the SBI v3.0 spec is frozen so RPMI v1.0 being accessed via SBI MPXY channel is also experimental.

OK, I can accept that the RPMI protocol version number is currently hidden behind other experimental functionality (SBI v3.0).

Quoted 7 lines
Quoted 2 lines

I have no problem with merging experimental code and iterating on it, but such code must not create ABI surface that has stability guarantees.

Historically, we have always accepted new SBI extensions as experimental ABI once the corresponding SBI spec is stable enough. We only change the advertised SBI spec version in OpenSBI only after the SBI spec is frozen.

Right, though now there is another dependency: because of the protocol version issue above, we must also wait until the RPMI spec is frozen and the implementation is no longer experimental before stabilizing SBI v3.0.

Regards,
Samuel

#22 lore raw

v2 cover RPMI and SBI MPXY support for OpenSBI

Quoted 89 lines · On Mon, Dec 16, 2024 at 3:19?AM Samuel Holland <[email protected]>…

Hi Anup,

Quoted 57 lines · Anup Patel
Quoted 55 lines · On Fri, Dec 6, 2024 at 10:38?AM Samuel Holland <[email protected]>…
Quoted 53 lines · Anup Patel
Quoted 42 lines · On Fri, Nov 29, 2024 at 9:21?PM Anup Patel <[email protected]> wrote:

This series adds RPMI and SBI MPXY support for OpenSBI. The RPMI service groups supported include system reset, system suspend, HSM, CPPC, and clock. The RPMI clock serivice group is exposed to supervisor software as an MPXY channel.

These patches can also be found in the rpmi_mpxy_v2 branch at:
https://github.com/avpatel/opensbi.git

To test these patches, use the dev-upstream branch of the following repos:
* https://github.com/ventanamicro/qemu.git
* https://github.com/ventanamicro/linux.git

To enable QEMU RPMI emulation (using librpmi) for virt machine, use "virt,rpmi=on" as the QEMU machine name.

Changes since v1:
- Rebased on latest OpenSBI
- Use the recently introduced helpers for generic driver initialization
- Updated RPMI drivers to match the latest RPMI specification
- Don't support fixed number of channels in RPMI shared memory mailbox driver
- Added new patch9 for support RPMI HSM based FDT fixup
- Improved arrangment of barrier in __smq_rx() and __smq_tx()

Anup Patel (8):
lib: utils/mailbox: Add generic mailbox library
lib: utils/mailbox: Add simple FDT based mailbox framework
lib: utils: Add simple FDT based system suspend driver framework
lib: utils/fdt: Allow dynamic registration of FDT fixup callbacks
lib: utils: Add simple FDT based HSM driver framework
lib: utils: Add simple FDT based CPPC driver framework
lib: sbi: Implement SBI MPXY extension
lib: utils: Add simple FDT based MPXY driver framework

Rahul Pathak (5):
lib: Increase ROOT_REGION_MAX to accomodate more memregions lib/utils: Add RPMI messaging protocol and shared memory transport
support
lib/utils: reset: Add RPMI System Reset driver
lib: sbi: Add SBI Message Proxy (MPXY) framework
lib: utils/mpxy: Add RPMI client driver for MPXY

Quoted 5 lines

Subrahmanya Lingappa (4):
lib: utils/suspend: Add RPMI system suspend driver
lib: sbi: Add optional resume address to hart suspend
lib: utils/hsm: Add RPMI HSM driver
lib: utils/cppc: Add RPMI CPPC driver

We plan to include the RPMI and MPXY drivers as experimental for the upcoming OpenSBI v1.6 release at the end of this month. There is still more work required in improving these drivers and related frameworks but that can happen incrementally over time.

Quoted 8 lines
Quoted 3 lines

I haven't taken the time to fully review this series yet because it's 5000 lines of new code and the RPMI spec isn't even frozen, but I have at least two major concerns.

The v1 of this series is available on the OpenSBI mailing list since 6th August 2024. Also, unlike kernel, OpenSBI only requires the specs to be in a stable state for accepting patches as experimental. This has been the policy for many years now.

Alright, then this is my mistake for waiting too long to review the driver code. I generally assume that DT bindings will go through several iterations before being accepted, and binding changes will require updates to the driver code, so there's not much point in reviewing drivers until the bindings have stabilized.

Quoted 8 lines
Quoted 7 lines

1) Where is the documentation for the devicetree compatible strings added by this series? I don't see any attempt to get the bindings reviewed and accepted.
https://lore.kernel.org/linux-devicetree/?q=rpmi shows nothing. This isn't something that can just be changed incrementally. It's not acceptable to break DT ABI. It's not okay to unilaterally make up a devicetree interface without documenting it and getting feedback through the appropriate process. This is especially true since OpenSBI isn't the owner of the RPMI spec.

Quoted 5 lines

OpenSBI has accepted experimental drivers in the past and the expectation is that people will update the bindings in OpenSBI once finalized on LKML. The drivers being "experimental" means users should assume that everything (including DT bindings) can change.

Quoted 5 lines

OK, if that is the policy, then we need to make it obvious which drivers are experimental, and which ones have stability guarantees. I sent a patch doing this, that I hope can be merged for v1.6:

https://lists.infradead.org/pipermail/opensbi/2024-December/007830.html

Sure, I will look at this patch today.

Quoted 7 lines
Quoted 4 lines

We do have kernel RFC series in-development for getting early feedback on device tree bindings and kernel drivers. I plan to send it out this week or early next week.

Thanks! That will be helpful. I don't think I've seen this series yet. Did I miss it?

My bad. I got derailed by the Linux IMSIC driver improvements. I have send-out RFC series to LKML

Quoted 16 lines
Quoted 9 lines
Quoted 5 lines

2) OpenSBI absolutely must not claim to implement MPXY MSG_PROT_ID 0 (RPMI) version 1.0. That specification does not exist. RPMI is not frozen and is still actively undergoing changes. If this is an experimental MPXY protocol, it should use an experimental message protocol ID.

The whole SBI MPXY extension is experimental until the SBI v3.0 spec is frozen so RPMI v1.0 being accessed via SBI MPXY channel is also experimental.

OK, I can accept that the RPMI protocol version number is currently hidden behind other experimental functionality (SBI v3.0).

Quoted 3 lines
Quoted 2 lines

I have no problem with merging experimental code and iterating on it, but such code must not create ABI surface that has stability guarantees.

Quoted 8 lines
Quoted 4 lines

Historically, we have always accepted new SBI extensions as experimental ABI once the corresponding SBI spec is stable enough. We only change the advertised SBI spec version in OpenSBI only after the SBI spec is frozen.

Right, though now there is another dependency: because of the protocol version issue above, we must also wait until the RPMI spec is frozen and the implementation is no longer experimental before stabilizing SBI v3.0.

You are correct. Due to this reason, we have aligned the ratification plan milestone dates for both SBI v3.0 and RPMI v1.0. Both these specifications are currently under ARC review and hopefully both will be frozen in the same time frame. We had done such alignment in the past for SBI v2.0 and RISC-V ACPI FFH.

Regards,
Anup