Skip to contentSkip to conversation

More RPMI and MPXY updates

PATCH New Anup Patel 2 participants 15 messages Jan 22, 2025 – Feb 13, 2025

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

v2 cover More RPMI and MPXY updates

This series does the following:
1) MPXY driver and framework cleanups
2) Update RPMI drivers as-per latest specification
3) Add MPXY RPMI driver for System MSI service group

These patches can also be found in the rpmi_updates_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,aia=aplic-imsic" as the QEMU machine name.

Changes since v1:
- Addressed comments in PATCH1, PATCH2, PATCH3, PATCH7, and PATCH12
- Added new PATCH13 to update MPXY framework and SBI extension based on latest specification.

Anup Patel (13):
lib: utils: Split the FDT MPXY RPMI mailbox client into two parts
lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox
lib: utils: Introduce optional MPXY RPMI service group operations
lib: sbi: Fix capability bit assignment in MPXY framework
lib: sbi: Improve local variable declarations in MPXY framework
lib: utils: Drop notifications from MPXY RPMI mailbox client
lib: utils: Improve variable declarations in MPXY RPMI mailbox client
include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header
lib: utils: Implement get_attribute() for the RPMI shared memory
mailbox
lib: utils: Populate MPXY channel attributes from RPMI channel
attributes
include: sbi_utils: Update RPMI service group IDs and BASE service
group
lib: utils: Add MPXY RPMI mailbox driver for System MSI service group
lib: sbi: Update MPXY framework and SBI extension as per latest spec

 include/sbi/sbi_ecall_interface.h           |  15 +-
 include/sbi/sbi_mpxy.h                      |  12 +-
 include/sbi_utils/mailbox/rpmi_mailbox.h    |   1 +
 include/sbi_utils/mailbox/rpmi_msgprot.h    | 117 +++++++-
 include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h |  79 +++++
 lib/sbi/sbi_ecall_mpxy.c                    |   7 +-
 lib/sbi/sbi_mpxy.c                          | 139 +++++----
 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c  |  39 ++-
 lib/utils/mpxy/Kconfig                      |  16 +-
 lib/utils/mpxy/fdt_mpxy_rpmi_clock.c        |  87 ++++++
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c         | 312 +++++++-------------
 lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c       | 204 +++++++++++++
 lib/utils/mpxy/objects.mk                   |   7 +-
 platform/generic/configs/defconfig          |   2 +
 14 files changed, 726 insertions(+), 311 deletions(-)
 create mode 100644 include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v2 1/13 lib: utils: Split the FDT MPXY RPMI mailbox client into two parts

Instead of having one common FDT MPXY RPMI mailbox client drivers for various RPMI service groups, split this driver into two parts:
1) Common MPXY RPMI mailbox client library
2) MPXY driver for RPMI clock service group

The above split enables having a separate MPXY driver for each RPMI clock service group and #1 (above) will allow code sharing between various MPXY RPMI drivers.

---
 include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h |  71 ++++++++
 lib/utils/mpxy/Kconfig                      |  12 +-
 lib/utils/mpxy/fdt_mpxy_rpmi_clock.c        |  88 ++++++++++
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c         | 169 +++-----------------
 lib/utils/mpxy/objects.mk                   |   4 +-
 platform/generic/configs/defconfig          |   1 +
 6 files changed, 191 insertions(+), 154 deletions(-)
 create mode 100644 include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h new file +71 -0
new file mode 100644
index 00000000..17b50557
@@ -0,0 +1,71 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <[email protected]>
+ */
+
+#ifndef __FDT_MPXY_RPMI_MBOX_H__
+#define __FDT_MPXY_RPMI_MBOX_H__
+
+#include <sbi/sbi_types.h>
+#include <sbi/sbi_mpxy.h>
+#include <sbi_utils/mailbox/rpmi_msgprot.h>
+#include <sbi_utils/mpxy/fdt_mpxy.h>
+
+#define MPXY_RPMI_MAJOR_VER		(1)
+#define MPXY_RPMI_MINOR_VER		(0)
+
+/** Convert the mpxy attribute ID to attribute array index */
+#define attr_id2index(attr_id)	(attr_id - SBI_MPXY_ATTR_MSGPROTO_ATTR_START)
+
+enum mpxy_msgprot_rpmi_attr_id {
+	MPXY_MSGPROT_RPMI_ATTR_SERVICEGROUP_ID = SBI_MPXY_ATTR_MSGPROTO_ATTR_START,
+	MPXY_MSGPROT_RPMI_ATTR_SERVICEGROUP_VERSION,
+	MPXY_MSGPROT_RPMI_ATTR_MAX_ID,
+};
+
+/**
+ * MPXY message protocol attributes for RPMI
+ * Order of attribute fields must follow the
+ * attribute IDs in `enum mpxy_msgprot_rpmi_attr_id`
+ */
+struct mpxy_rpmi_channel_attrs {
+	u32 servicegrp_id;
+	u32 servicegrp_ver;
+};
+
+/** Make sure all attributes are packed for direct memcpy */
+#define assert_field_offset(field, attr_offset)				\
+	_Static_assert(							\
+		((offsetof(struct mpxy_rpmi_channel_attrs, field)) /	\
+		 sizeof(u32)) == (attr_offset - SBI_MPXY_ATTR_MSGPROTO_ATTR_START),\
+		"field " #field						\
+		" from struct mpxy_rpmi_channel_attrs invalid offset, expected " #attr_offset)
+
+assert_field_offset(servicegrp_id, MPXY_MSGPROT_RPMI_ATTR_SERVICEGROUP_ID);
+assert_field_offset(servicegrp_ver, MPXY_MSGPROT_RPMI_ATTR_SERVICEGROUP_VERSION);
+
+/** MPXY RPMI service data for each service group */
+struct mpxy_rpmi_service_data {
+	u8 id;
+	u32 min_tx_len;
+	u32 max_tx_len;
+	u32 min_rx_len;
+	u32 max_rx_len;
+};
+
+/** MPXY RPMI mbox data for each service group */
+struct mpxy_rpmi_mbox_data {
+	u32 servicegrp_id;
+	u32 num_services;
+	u32 notifications_support;
+	struct mpxy_rpmi_service_data *service_data;
+};
+
+/** Common probe function for MPXY RPMI drivers */
+int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *match);
+
+#endif
lib/utils/mpxy/Kconfig +8 -4
index 131fb91a..ff88f24f 100644
@@ -7,11 +7,15 @@ 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
+	bool "MPXY drivers as RPMI mailbox client"
+	depends on FDT_MAILBOX && FDT_MPXY
+	default n
+
+if FDT_MPXY_RPMI_MBOX
+
+config FDT_MPXY_RPMI_CLOCK
+	bool "MPXY driver for RPMI clock service group"
 	default n
 
 endif
lib/utils/mpxy/fdt_mpxy_rpmi_clock.c new file +88 -0

88 lines not on this page · raw message

lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c +20 -149

239 lines not on this page · raw message

lib/utils/mpxy/objects.mk +3 -1
index ccb28b55..1c9afed9 100644
@@ -10,5 +10,7 @@
 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
+
+carray-fdt_mpxy_drivers-$(CONFIG_FDT_MPXY_RPMI_CLOCK) += fdt_mpxy_rpmi_clock
+libsbiutils-objs-$(CONFIG_FDT_MPXY_RPMI_CLOCK) += mpxy/fdt_mpxy_rpmi_clock.o
platform/generic/configs/defconfig +1 -0
index e23b38b2..55607a28 100644
@@ -55,3 +55,4 @@ CONFIG_FDT_TIMER_MTIMER=y
 CONFIG_FDT_TIMER_PLMT=y
 CONFIG_FDT_MPXY=y
 CONFIG_FDT_MPXY_RPMI_MBOX=y
+CONFIG_FDT_MPXY_RPMI_CLOCK=y
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v2 2/13 lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox

In reply to Anup Patel

The mpxy_rpmi_mbox_data is provided by RPMI service group specific MPXY driver to the common MPXY RPMI mailbox client implementation so let's constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox so that it is not accidently modified.

---
 lib/utils/mpxy/fdt_mpxy_rpmi_clock.c |  2 +-
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c  | 15 ++++++++-------
 2 files changed, 9 insertions(+), 8 deletions(-)
lib/utils/mpxy/fdt_mpxy_rpmi_clock.c +1 -1
index d2ce0718..4e36d4f5 100644
@@ -69,7 +69,7 @@ static struct mpxy_rpmi_service_data clock_services[] = {
 },
 };
 
-static struct mpxy_rpmi_mbox_data clock_data = {
+static const struct mpxy_rpmi_mbox_data clock_data = {
 	.servicegrp_id = RPMI_SRVGRP_CLOCK,
 	.num_services = RPMI_CLOCK_SRV_MAX_COUNT,
 	.notifications_support = 1,
lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c +8 -7
index 0d4fd1fe..7034fb9e 100644
@@ -22,7 +22,7 @@
  */
 struct mpxy_rpmi_mbox {
 	struct mbox_chan *chan;
-	struct mpxy_rpmi_mbox_data *mbox_data;
+	const struct mpxy_rpmi_mbox_data *mbox_data;
 	struct mpxy_rpmi_channel_attrs msgprot_attrs;
 	struct sbi_mpxy_channel channel;
 };
@@ -31,11 +31,11 @@ struct mpxy_rpmi_mbox {
  * Discover the RPMI service data using message_id
  * MPXY message_id == RPMI service_id
  */
-static struct mpxy_rpmi_service_data *mpxy_find_rpmi_srvid(u32 message_id,
-					struct mpxy_rpmi_mbox_data *mbox_data)
+static const struct mpxy_rpmi_service_data *mpxy_find_rpmi_srvid(u32 message_id,
+					const struct mpxy_rpmi_mbox_data *mbox_data)
 {
 	int mid = 0;
-	struct mpxy_rpmi_service_data *srv = mbox_data->service_data;
+	const struct mpxy_rpmi_service_data *srv = mbox_data->service_data;
 
 	for (mid = 0; srv[mid].id < mbox_data->num_services; mid++) {
 		if (srv[mid].id == (u8)message_id)
@@ -146,8 +146,9 @@ static int __mpxy_mbox_send_message(struct sbi_mpxy_channel *channel,
 	struct rpmi_message_args args = {0};
 	struct mpxy_rpmi_mbox *rmb =
 		container_of(channel, struct mpxy_rpmi_mbox, channel);
-	struct mpxy_rpmi_service_data *srv =
-			mpxy_find_rpmi_srvid(message_id, rmb->mbox_data);
+	const struct mpxy_rpmi_service_data *srv =
+		mpxy_find_rpmi_srvid(message_id, rmb->mbox_data);
+
 	if (!srv)
 		return SBI_ENOTSUPP;
 
@@ -299,7 +300,7 @@ int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *ma
 	rmb->msgprot_attrs.servicegrp_ver =
 			SBI_MPXY_MSGPROTO_VERSION(MPXY_RPMI_MAJOR_VER, MPXY_RPMI_MINOR_VER);
 
-	rmb->mbox_data = (struct mpxy_rpmi_mbox_data *)data;
+	rmb->mbox_data = data;
 	rmb->chan = chan;
 
 	/* Register RPXY service group */
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH v2 3/13 lib: utils: Introduce optional MPXY RPMI service group operations

In reply to Anup Patel

Some of the RPMI service groups may need additional context and special handling when transferring messages via underlying mailbox channel so introduce optional MPXY RPMI service group operations for this purpose.

---
 include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h | 12 +++++++++++
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c         | 24 +++++++++++++++++----
 2 files changed, 32 insertions(+), 4 deletions(-)
include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h +12 -0
index 17b50557..df81a73d 100644
@@ -12,6 +12,7 @@
 
 #include <sbi/sbi_types.h>
 #include <sbi/sbi_mpxy.h>
+#include <sbi_utils/mailbox/fdt_mailbox.h>
 #include <sbi_utils/mailbox/rpmi_msgprot.h>
 #include <sbi_utils/mpxy/fdt_mpxy.h>
 
@@ -63,6 +64,17 @@ struct mpxy_rpmi_mbox_data {
 	u32 num_services;
 	u32 notifications_support;
 	struct mpxy_rpmi_service_data *service_data;
+
+	/** Transfer RPMI service group message */
+	int (*xfer_group)(void *context, struct mbox_chan *chan,
+			  struct mbox_xfer *xfer);
+
+	/** Setup RPMI service group context for MPXY */
+	int (*setup_group)(void **context, struct mbox_chan *chan,
+			   const struct mpxy_rpmi_mbox_data *data);
+
+	/** Cleanup RPMI service group context for MPXY */
+	void (*cleanup_group)(void *context);
 };
 
 /** Common probe function for MPXY RPMI drivers */
lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c +20 -4
index 7034fb9e..6db750fb 100644
@@ -13,7 +13,6 @@
 #include <sbi/sbi_heap.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 #include <sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h>
-#include <sbi_utils/mailbox/fdt_mailbox.h>
 #include <sbi/sbi_console.h>
 
 /**
@@ -25,6 +24,7 @@ struct mpxy_rpmi_mbox {
 	const struct mpxy_rpmi_mbox_data *mbox_data;
 	struct mpxy_rpmi_channel_attrs msgprot_attrs;
 	struct sbi_mpxy_channel channel;
+	void *group_context;
 };
 
 /**
@@ -146,8 +146,9 @@ static int __mpxy_mbox_send_message(struct sbi_mpxy_channel *channel,
 	struct rpmi_message_args args = {0};
 	struct mpxy_rpmi_mbox *rmb =
 		container_of(channel, struct mpxy_rpmi_mbox, channel);
+	const struct mpxy_rpmi_mbox_data *data = rmb->mbox_data;
 	const struct mpxy_rpmi_service_data *srv =
-		mpxy_find_rpmi_srvid(message_id, rmb->mbox_data);
+		mpxy_find_rpmi_srvid(message_id, data);
 
 	if (!srv)
 		return SBI_ENOTSUPP;
@@ -183,7 +184,10 @@ static int __mpxy_mbox_send_message(struct sbi_mpxy_channel *channel,
 				  tx, tx_len, RPMI_DEF_TX_TIMEOUT);
 	}
 
-	ret = mbox_chan_xfer(rmb->chan, &xfer);
+	if (data->xfer_group)
+		ret = data->xfer_group(rmb->group_context, rmb->chan, &xfer);
+	else
+		ret = mbox_chan_xfer(rmb->chan, &xfer);
 	if (ret)
 		return ret;
 
@@ -303,9 +307,21 @@ int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *ma
 	rmb->mbox_data = data;
 	rmb->chan = chan;
 
-	/* Register RPXY service group */
+	/* Setup RPMI service group context */
+	if (data->setup_group) {
+		rc = data->setup_group(&rmb->group_context, chan, data);
+		if (rc) {
+			mbox_controller_free_chan(chan);
+			sbi_free(rmb);
+			return rc;
+		}
+	}
+
+	/* Register RPMI service group */
 	rc = sbi_mpxy_register_channel(&rmb->channel);
 	if (rc) {
+		if (data->cleanup_group)
+			data->cleanup_group(rmb->group_context);
 		mbox_controller_free_chan(chan);
 		sbi_free(rmb);
 		return rc;
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH v2 4/13 lib: sbi: Fix capability bit assignment in MPXY framework

In reply to Anup Patel

The capability bit assignment in MPXY framework does not match the SBI MPXY extension in latest SBI specification so update it.

Fixes 7939bf1329eb ("lib: sbi: Add SBI Message Proxy (MPXY) framework")
---
 lib/sbi/sbi_mpxy.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
lib/sbi/sbi_mpxy.c +6 -6
index 639478bf..91b212a6 100644
@@ -43,17 +43,17 @@ static SBI_LIST_HEAD(mpxy_channel_list);
 #define CAP_EVENTSSTATE_POS	2
 #define CAP_EVENTSSTATE_MASK	(1U << CAP_EVENTSSTATE_POS)
 
-/** Channel Capability - Get Notification function support */
-#define CAP_GET_NOTIFICATIONS_POS	3
-#define CAP_GET_NOTIFICATIONS_MASK	(1U << CAP_GET_NOTIFICATIONS_POS)
+/** Channel Capability - Send Message With Response function support */
+#define CAP_SEND_MSG_WITH_RESP_POS	3
+#define CAP_SEND_MSG_WITH_RESP_MASK	(1U << CAP_SEND_MSG_WITH_RESP_POS)
 
 /** Channel Capability - Send Message Without Response function support */
 #define CAP_SEND_MSG_WITHOUT_RESP_POS	4
 #define CAP_SEND_MSG_WITHOUT_RESP_MASK	(1U << CAP_SEND_MSG_WITHOUT_RESP_POS)
 
-/** Channel Capability - Send Message With Response function support */
-#define CAP_SEND_MSG_WITH_RESP_POS	5
-#define CAP_SEND_MSG_WITH_RESP_MASK	(1U << CAP_SEND_MSG_WITH_RESP_POS)
+/** Channel Capability - Get Notification function support */
+#define CAP_GET_NOTIFICATIONS_POS	5
+#define CAP_GET_NOTIFICATIONS_MASK	(1U << CAP_GET_NOTIFICATIONS_POS)
 
 /** Helpers to enable/disable channel capability bits
  * _c: capability variable
Signature · 1 line
2.43.0
author
#5 lore raw

PATCH v2 5/13 lib: sbi: Improve local variable declarations in MPXY framework

In reply to Anup Patel

The local variable declarations should be at the start of function and preferrably organized like a inverted pyramid.

---
 lib/sbi/sbi_mpxy.c | 65 ++++++++++++++++++----------------------------
 1 file changed, 25 insertions(+), 40 deletions(-)
lib/sbi/sbi_mpxy.c +25 -40
index 91b212a6..6a5605ea 100644
@@ -170,9 +170,8 @@ bool sbi_mpxy_channel_available(void)
 
 static void mpxy_std_attrs_init(struct sbi_mpxy_channel *channel)
 {
+	struct mpxy_state *ms = sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
 	u32 capability = 0;
-	struct mpxy_state *ms =
-		sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
 
 	/* Reset values */
 	channel->attrs.msi_control = 0;
@@ -236,6 +235,8 @@ int sbi_mpxy_register_channel(struct sbi_mpxy_channel *channel)
 
 int sbi_mpxy_init(struct sbi_scratch *scratch)
 {
+	struct mpxy_state *ms;
+
 	mpxy_state_offset = sbi_scratch_alloc_type_offset(struct mpxy_state);
 	if (!mpxy_state_offset)
 		return SBI_ENOMEM;
@@ -244,8 +245,7 @@ int sbi_mpxy_init(struct sbi_scratch *scratch)
 	 * TODO: Proper support for checking msi support from platform.
 	 * Currently disable msi and sse and use polling
 	 */
-	struct mpxy_state *ms =
-		sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
+	ms = sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
 	ms->msi_avail = false;
 	ms->sse_avail = false;
 
@@ -257,8 +257,7 @@ int sbi_mpxy_init(struct sbi_scratch *scratch)
 int sbi_mpxy_set_shmem(unsigned long shmem_size, unsigned long shmem_phys_lo,
 		       unsigned long shmem_phys_hi, unsigned long flags)
 {
-	struct mpxy_state *ms =
-		sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
+	struct mpxy_state *ms = sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
 	unsigned long *ret_buf;
 
 	/** Disable shared memory if both hi and lo have all bit 1s */
@@ -303,15 +302,12 @@ int sbi_mpxy_set_shmem(unsigned long shmem_size, unsigned long shmem_phys_lo,
 
 int sbi_mpxy_get_channel_ids(u32 start_index)
 {
-	u32 node_index = 0, node_ret = 0;
+	struct mpxy_state *ms = sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
 	u32 remaining, returned, max_channelids;
+	u32 node_index = 0, node_ret = 0;
+	struct sbi_mpxy_channel *channel;
 	u32 channels_count = 0;
 	u32 *shmem_base;
-	struct sbi_mpxy_channel *channel;
-
-	/* Check if the shared memory is being setup or not. */
-	struct mpxy_state *ms =
-		sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
 
 	if (!mpxy_shmem_enabled(ms))
 		return SBI_ERR_NO_SHMEM;
@@ -358,13 +354,11 @@ int sbi_mpxy_get_channel_ids(u32 start_index)
 
 int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count)
 {
+	struct mpxy_state *ms = sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
 	int ret = SBI_SUCCESS;
 	u32 *attr_ptr, end_id;
 	void *shmem_base;
 
-	struct mpxy_state *ms =
-		sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
-
 	if (!mpxy_shmem_enabled(ms))
 		return SBI_ERR_NO_SHMEM;
 
@@ -442,8 +436,8 @@ out:
 static int mpxy_check_write_std_attr(struct sbi_mpxy_channel *channel,
 				     u32 attr_id, u32 attr_val)
 {
-	int ret = SBI_SUCCESS;
 	struct sbi_mpxy_channel_attrs *attrs = &channel->attrs;
+	int ret = SBI_SUCCESS;
 
 	switch(attr_id) {
 	case SBI_MPXY_ATTR_MSI_CONTROL:
@@ -477,9 +471,7 @@ static int mpxy_check_write_std_attr(struct sbi_mpxy_channel *channel,
 static void mpxy_write_std_attr(struct sbi_mpxy_channel *channel, u32 attr_id,
 			        u32 attr_val)
 {
-	struct mpxy_state *ms =
-		sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
-
+	struct mpxy_state *ms = sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
 	struct sbi_mpxy_channel_attrs *attrs = &channel->attrs;
 
 	switch(attr_id) {
@@ -513,17 +505,16 @@ static void mpxy_write_std_attr(struct sbi_mpxy_channel *channel, u32 attr_id,
 
 int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count)
 {
+	struct mpxy_state *ms = sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
+	u32 *mem_ptr, attr_id, end_id, attr_val;
+	struct sbi_mpxy_channel *channel;
 	int ret, mem_idx;
 	void *shmem_base;
-	u32 *mem_ptr, attr_id, end_id, attr_val;
-
-	struct mpxy_state *ms =
-		sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
 
 	if (!mpxy_shmem_enabled(ms))
 		return SBI_ERR_NO_SHMEM;
 
-	struct sbi_mpxy_channel *channel = mpxy_find_channel(channel_id);
+	channel = mpxy_find_channel(channel_id);
 	if (!channel)
 		return SBI_ERR_NOT_SUPPORTED;
 
@@ -604,17 +595,16 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,
 			  unsigned long msg_data_len,
 			  unsigned long *resp_data_len)
 {
-	int ret;
+	struct mpxy_state *ms = sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
+	struct sbi_mpxy_channel *channel;
 	void *shmem_base, *resp_buf;
 	u32 resp_bufsize;
-
-	struct mpxy_state *ms =
-		sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
+	int ret;
 
 	if (!mpxy_shmem_enabled(ms))
 		return SBI_ERR_NO_SHMEM;
 
-	struct sbi_mpxy_channel *channel = mpxy_find_channel(channel_id);
+	channel = mpxy_find_channel(channel_id);
 	if (!channel)
 		return SBI_ERR_NOT_SUPPORTED;
 
@@ -640,8 +630,7 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,
 							  resp_buf,
 							  resp_bufsize,
 							  resp_data_len);
-	}
-	else {
+	} else {
 		ret = channel->send_message_without_response(channel, msg_id,
 							     shmem_base,
 							     msg_data_len);
@@ -664,20 +653,16 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,
 
 int sbi_mpxy_get_notification_events(u32 channel_id, unsigned long *events_len)
 {
-	int ret;
+	struct mpxy_state *ms = sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
+	struct sbi_mpxy_channel *channel;
 	void *eventsbuf, *shmem_base;
-
-	struct mpxy_state *ms =
-		sbi_scratch_thishart_offset_ptr(mpxy_state_offset);
+	int ret;
 
 	if (!mpxy_shmem_enabled(ms))
 		return SBI_ERR_NO_SHMEM;
 
-	struct sbi_mpxy_channel *channel = mpxy_find_channel(channel_id);
-	if (!channel)
-		return SBI_ERR_NOT_SUPPORTED;
-
-	if (!channel->get_notification_events)
+	channel = mpxy_find_channel(channel_id);
+	if (!channel || !channel->get_notification_events)
 		return SBI_ERR_NOT_SUPPORTED;
 
 	shmem_base = hart_shmem_base(ms);
Signature · 1 line
2.43.0
author
#6 lore raw

PATCH v2 6/13 lib: utils: Drop notifications from MPXY RPMI mailbox client

In reply to Anup Patel

Currently, the common MPXY RPMI mailbox client does not support notifications so no need for dummy notifications support.

---
 include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h |  1 -
 lib/utils/mpxy/fdt_mpxy_rpmi_clock.c        |  1 -
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c         | 12 ------------
 3 files changed, 14 deletions(-)
include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h +0 -1
index df81a73d..373b077a 100644
@@ -62,7 +62,6 @@ struct mpxy_rpmi_service_data {
 struct mpxy_rpmi_mbox_data {
 	u32 servicegrp_id;
 	u32 num_services;
-	u32 notifications_support;
 	struct mpxy_rpmi_service_data *service_data;
 
 	/** Transfer RPMI service group message */
lib/utils/mpxy/fdt_mpxy_rpmi_clock.c +0 -1
index 4e36d4f5..7d2b4a20 100644
@@ -72,7 +72,6 @@ static struct mpxy_rpmi_service_data clock_services[] = {
 static const struct mpxy_rpmi_mbox_data clock_data = {
 	.servicegrp_id = RPMI_SRVGRP_CLOCK,
 	.num_services = RPMI_CLOCK_SRV_MAX_COUNT,
-	.notifications_support = 1,
 	.service_data = clock_services,
 };
 
lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c +0 -12
index 6db750fb..cbcea4f2 100644
@@ -213,13 +213,6 @@ static int mpxy_mbox_send_message_withoutresp(struct sbi_mpxy_channel *channel,
 				 NULL, 0, NULL);
 }
 
-static int mpxy_mbox_get_notifications(struct sbi_mpxy_channel *channel,
-				       void *eventsbuf, u32 bufsize,
-				       unsigned long *events_len)
-{
-	return SBI_ENOTSUPP;
-}
-
 int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *match)
 {
 	int rc, len;
@@ -277,11 +270,6 @@ int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *ma
 					mpxy_mbox_send_message_withresp;
 	rmb->channel.send_message_without_response =
 					mpxy_mbox_send_message_withoutresp;
-	/* Callback to get RPMI notifications */
-	rmb->channel.get_notification_events = mpxy_mbox_get_notifications;
-
-	/* No callback to switch events state data */
-	rmb->channel.switch_eventsstate = NULL;
 
 	/* RPMI Message Protocol ID */
 	rmb->channel.attrs.msg_proto_id = SBI_MPXY_MSGPROTO_RPMI_ID;
Signature · 1 line
2.43.0
author
#7 lore raw

PATCH v2 7/13 lib: utils: Improve variable declarations in MPXY RPMI mailbox client

In reply to Anup Patel

The local variable declarations should be at the start of function and preferrably organized like a inverted pyramid.

---
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)
lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c +13 -16
index cbcea4f2..f8de91a5 100644
@@ -34,8 +34,8 @@ struct mpxy_rpmi_mbox {
 static const struct mpxy_rpmi_service_data *mpxy_find_rpmi_srvid(u32 message_id,
 					const struct mpxy_rpmi_mbox_data *mbox_data)
 {
-	int mid = 0;
 	const struct mpxy_rpmi_service_data *srv = mbox_data->service_data;
+	int mid = 0;
 
 	for (mid = 0; srv[mid].id < mbox_data->num_services; mid++) {
 		if (srv[mid].id == (u8)message_id)
@@ -57,12 +57,10 @@ static int mpxy_mbox_read_attributes(struct sbi_mpxy_channel *channel,
 				     u32 *outmem, u32 base_attr_id,
 				     u32 attr_count)
 {
-	u32 end_id;
 	struct mpxy_rpmi_mbox *rmb =
 		container_of(channel, struct mpxy_rpmi_mbox, channel);
 	u32 *attr_array = (u32 *)&rmb->msgprot_attrs;
-
-	end_id = base_attr_id + attr_count - 1;
+	u32 end_id = base_attr_id + attr_count - 1;
 
 	if (end_id >= MPXY_MSGPROT_RPMI_ATTR_MAX_ID)
 		return SBI_EBAD_RANGE;
@@ -108,12 +106,11 @@ static int mpxy_mbox_write_attributes(struct sbi_mpxy_channel *channel,
 				     u32 *outmem, u32 base_attr_id,
 				     u32 attr_count)
 {
-	int ret, mem_idx;
-	u32 end_id, attr_val, idx;
 	struct mpxy_rpmi_mbox *rmb =
 		container_of(channel, struct mpxy_rpmi_mbox, channel);
-
-	end_id = base_attr_id + attr_count - 1;
+	u32 end_id = base_attr_id + attr_count - 1;
+	u32 attr_val, idx;
+	int ret, mem_idx;
 
 	if (end_id >= MPXY_MSGPROT_RPMI_ATTR_MAX_ID)
 		return SBI_EBAD_RANGE;
@@ -140,15 +137,15 @@ static int __mpxy_mbox_send_message(struct sbi_mpxy_channel *channel,
 				  void *rx, u32 rx_max_len,
 				  unsigned long *ack_len)
 {
-	int ret;
-	u32 rx_len = 0;
-	struct mbox_xfer xfer;
-	struct rpmi_message_args args = {0};
 	struct mpxy_rpmi_mbox *rmb =
 		container_of(channel, struct mpxy_rpmi_mbox, channel);
 	const struct mpxy_rpmi_mbox_data *data = rmb->mbox_data;
 	const struct mpxy_rpmi_service_data *srv =
 		mpxy_find_rpmi_srvid(message_id, data);
+	struct rpmi_message_args args = {0};
+	struct mbox_xfer xfer;
+	u32 rx_len = 0;
+	int ret;
 
 	if (!srv)
 		return SBI_ENOTSUPP;
@@ -215,12 +212,12 @@ static int mpxy_mbox_send_message_withoutresp(struct sbi_mpxy_channel *channel,
 
 int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *match)
 {
-	int rc, len;
+	const struct mpxy_rpmi_mbox_data *data = match->data;
+	struct mpxy_rpmi_mbox *rmb;
+	struct mbox_chan *chan;
 	const fdt32_t *val;
 	u32 channel_id;
-	struct mbox_chan *chan;
-	struct mpxy_rpmi_mbox *rmb;
-	const struct mpxy_rpmi_mbox_data *data = match->data;
+	int rc, len;
 
 	/* Allocate context for RPXY mbox client */
 	rmb = sbi_zalloc(sizeof(*rmb));
Signature · 1 line
2.43.0
author
#8 lore raw

PATCH v2 8/13 include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header

In reply to Anup Patel

The rpmi_mailbox.h uses structures defined in mailbox.h so let's include mailbox.h in rpmi_mailbox.h header.

---
 include/sbi_utils/mailbox/rpmi_mailbox.h | 1 +
 1 file changed, 1 insertion(+)
include/sbi_utils/mailbox/rpmi_mailbox.h +1 -0
index 61af51a8..a23ad8ca 100644
@@ -11,6 +11,7 @@
 #define __RPMI_MAILBOX_H__
 
 #include <sbi/sbi_error.h>
+#include <sbi_utils/mailbox/mailbox.h>
 #include <sbi_utils/mailbox/rpmi_msgprot.h>
 
 #define rpmi_u32_count(__var)	(sizeof(__var) / sizeof(u32))
Signature · 1 line
2.43.0
author
#9 lore raw

PATCH v2 9/13 lib: utils: Implement get_attribute() for the RPMI shared memory mailbox

In reply to Anup Patel

To allow clients query service group version of a RPMI mailbox channel, implement get_attribute() callback for the RPMI shared memory mailbox controller.

---
 include/sbi_utils/mailbox/rpmi_msgprot.h   | 13 +++++++-
 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c | 35 ++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)
include/sbi_utils/mailbox/rpmi_msgprot.h +12 -1
index 9575dc72..17d678a3 100644
@@ -175,7 +175,7 @@ enum rpmi_error {
 	RPMI_ERR_VENDOR_START	= -128,
 };
 
-/** RPMI Message Arguments */
+/** RPMI Mailbox Message Arguments */
 struct rpmi_message_args {
 	u32 flags;
 #define RPMI_MSG_FLAGS_NO_TX		(1U << 0)
@@ -189,6 +189,17 @@ struct rpmi_message_args {
 	u32 rx_data_len;
 };
 
+/** RPMI Mailbox Channel Attribute IDs */
+enum rpmi_channel_attribute_id {
+	RPMI_CHANNEL_ATTR_PROTOCOL_VERSION = 0,
+	RPMI_CHANNEL_ATTR_MAX_DATA_LEN,
+	RPMI_CHANNEL_ATTR_TX_TIMEOUT,
+	RPMI_CHANNEL_ATTR_RX_TIMEOUT,
+	RPMI_CHANNEL_ATTR_SERVICEGROUP_ID,
+	RPMI_CHANNEL_ATTR_SERVICEGROUP_VERSION,
+	RPMI_CHANNEL_ATTR_MAX,
+};
+
 /*
  * RPMI SERVICEGROUPS AND SERVICES
  */
lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c +35 -0
index b8bd3cd6..e9f52c7a 100644
@@ -490,6 +490,40 @@ static int rpmi_shmem_mbox_xfer(struct mbox_chan *chan, struct mbox_xfer *xfer)
 	return 0;
 }
 
+static int rpmi_shmem_mbox_get_attribute(struct mbox_chan *chan,
+					 int attr_id, void *out_value)
+{
+	struct rpmi_shmem_mbox_controller *mctl =
+			container_of(chan->mbox,
+				     struct rpmi_shmem_mbox_controller,
+				     controller);
+	struct rpmi_srvgrp_chan *srvgrp_chan = to_srvgrp_chan(chan);
+
+	switch (attr_id) {
+	case RPMI_CHANNEL_ATTR_PROTOCOL_VERSION:
+		*((u32 *)out_value) = mctl->spec_version;
+		break;
+	case RPMI_CHANNEL_ATTR_MAX_DATA_LEN:
+		*((u32 *)out_value) = RPMI_MSG_DATA_SIZE(mctl->slot_size);
+		break;
+	case RPMI_CHANNEL_ATTR_TX_TIMEOUT:
+		*((u32 *)out_value) = RPMI_DEF_TX_TIMEOUT;
+		break;
+	case RPMI_CHANNEL_ATTR_RX_TIMEOUT:
+		*((u32 *)out_value) = RPMI_DEF_RX_TIMEOUT;
+		break;
+	case RPMI_CHANNEL_ATTR_SERVICEGROUP_ID:
+		*((u32 *)out_value) = srvgrp_chan->servicegroup_id;
+		break;
+	case RPMI_CHANNEL_ATTR_SERVICEGROUP_VERSION:
+		*((u32 *)out_value) = srvgrp_chan->servicegroup_version;
+		break;
+	default:
+		return SBI_ENOTSUPP;
+	}
+
+	return 0;
+}
 
 static struct mbox_chan *rpmi_shmem_mbox_request_chan(
 						struct mbox_controller *mbox,
@@ -665,6 +699,7 @@ static int rpmi_shmem_mbox_init(const void *fdt, int nodeoff,
 	mctl->controller.request_chan = rpmi_shmem_mbox_request_chan;
 	mctl->controller.free_chan = rpmi_shmem_mbox_free_chan;
 	mctl->controller.xfer = rpmi_shmem_mbox_xfer;
+	mctl->controller.get_attribute = rpmi_shmem_mbox_get_attribute;
 	ret = mbox_controller_add(&mctl->controller);
 	if (ret)
 		goto fail_free_controller;
Signature · 1 line
2.43.0
author
#10 lore raw

PATCH v2 10/13 lib: utils: Populate MPXY channel attributes from RPMI channel attributes

In reply to Anup Patel

Use the RPMI mailbox channel attributes to populate MPXY channel attributes instead of hard coding them.

---
 include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h |   3 -
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c         | 101 +++++++++++++-------
 2 files changed, 65 insertions(+), 39 deletions(-)
include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h +0 -3
index 373b077a..068a1a55 100644
@@ -16,9 +16,6 @@
 #include <sbi_utils/mailbox/rpmi_msgprot.h>
 #include <sbi_utils/mpxy/fdt_mpxy.h>
 
-#define MPXY_RPMI_MAJOR_VER		(1)
-#define MPXY_RPMI_MINOR_VER		(0)
-
 /** Convert the mpxy attribute ID to attribute array index */
 #define attr_id2index(attr_id)	(attr_id - SBI_MPXY_ATTR_MSGPROTO_ATTR_START)
 
lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c +65 -36

152 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#11 lore raw

PATCH v2 11/13 include: sbi_utils: Update RPMI service group IDs and BASE service group

In reply to Anup Patel

The service group ID assignment and some of the BASE services have changes in the latest RPMI specification so let's update the RPMI implementation accordingly.

---
 include/sbi_utils/mailbox/rpmi_msgprot.h   | 16 +++++++---------
 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c |  4 ----
 2 files changed, 7 insertions(+), 13 deletions(-)
include/sbi_utils/mailbox/rpmi_msgprot.h +7 -9
index 17d678a3..363cc653 100644
@@ -208,11 +208,11 @@ enum rpmi_channel_attribute_id {
 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_HSM = 0x0004,
-	RPMI_SRVGRP_CPPC = 0x0005,
-	RPMI_SRVGRP_CLOCK = 0x0007,
+	RPMI_SRVGRP_SYSTEM_RESET = 0x0003,
+	RPMI_SRVGRP_SYSTEM_SUSPEND = 0x0004,
+	RPMI_SRVGRP_HSM = 0x0005,
+	RPMI_SRVGRP_CPPC = 0x0006,
+	RPMI_SRVGRP_CLOCK = 0x0008,
 	RPMI_SRVGRP_ID_MAX_COUNT,
 
 	/* Reserved range for service groups */
@@ -243,12 +243,10 @@ enum rpmi_base_service_id {
 	RPMI_BASE_SRV_GET_PLATFORM_INFO = 0x05,
 	RPMI_BASE_SRV_PROBE_SERVICE_GROUP = 0x06,
 	RPMI_BASE_SRV_GET_ATTRIBUTES = 0x07,
-	RPMI_BASE_SRV_SET_MSI = 0x08,
 };
 
-#define RPMI_BASE_FLAGS_F0_PRIVILEGE		(1U << 2)
-#define RPMI_BASE_FLAGS_F0_EV_NOTIFY		(1U << 1)
-#define RPMI_BASE_FLAGS_F0_MSI_EN		(1U)
+#define RPMI_BASE_FLAGS_F0_PRIVILEGE		(1U << 1)
+#define RPMI_BASE_FLAGS_F0_EV_NOTIFY		(1U << 0)
 
 enum rpmi_base_context_priv_level {
 	RPMI_BASE_CONTEXT_PRIV_S_MODE,
lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c +0 -4
index e9f52c7a..5b858d36 100644
@@ -146,7 +146,6 @@ struct rpmi_shmem_mbox_controller {
 	struct {
 		u8 f0_priv_level;
 		bool f0_ev_notif_en;
-		bool f0_msi_en;
 	} base_flags;
 };
 
@@ -767,9 +766,6 @@ static int rpmi_shmem_mbox_init(const void *fdt, int nodeoff,
 	/* 1: Supported, 0: Not Supported */
 	mctl->base_flags.f0_ev_notif_en =
 			resp.f0 & RPMI_BASE_FLAGS_F0_EV_NOTIFY ? 1 : 0;
-	/* 1: Supported, 0: Not Supported */
-	mctl->base_flags.f0_msi_en =
-			resp.f0 & RPMI_BASE_FLAGS_F0_MSI_EN ? 1 : 0;
 
 	/* We only use M-mode RPMI context in OpenSBI */
 	if (!mctl->base_flags.f0_priv_level) {
Signature · 1 line
2.43.0
author
#12 lore raw

PATCH v2 12/13 lib: utils: Add MPXY RPMI mailbox driver for System MSI service group

In reply to Anup Patel

The supervisor software can directly receive most of the system MSIs except P2A doorbell and MSIs preferred to be handled in M-mode.

Add MPXY RPMI mailbox client driver for the System MSI service group.

---
 include/sbi_utils/mailbox/rpmi_msgprot.h |  88 ++++++++++
 lib/utils/mpxy/Kconfig                   |   4 +
 lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c    | 204 +++++++++++++++++++++++
 lib/utils/mpxy/objects.mk                |   3 +
 platform/generic/configs/defconfig       |   1 +
 5 files changed, 300 insertions(+)
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c
include/sbi_utils/mailbox/rpmi_msgprot.h +88 -0
index 363cc653..8d8fa5e5 100644
@@ -208,6 +208,7 @@ enum rpmi_channel_attribute_id {
 enum rpmi_servicegroup_id {
 	RPMI_SRVGRP_ID_MIN = 0,
 	RPMI_SRVGRP_BASE = 0x0001,
+	RPMI_SRVGRP_SYSTEM_MSI = 0x0002,
 	RPMI_SRVGRP_SYSTEM_RESET = 0x0003,
 	RPMI_SRVGRP_SYSTEM_SUSPEND = 0x0004,
 	RPMI_SRVGRP_HSM = 0x0005,
@@ -267,6 +268,93 @@ struct rpmi_base_get_platform_info_resp {
 	char plat_info[];
 };
 
+/** RPMI System MSI ServiceGroup Service IDs */
+enum rpmi_sysmsi_service_id {
+	RPMI_SYSMSI_SRV_ENABLE_NOTIFICATION = 0x01,
+	RPMI_SYSMSI_SRV_GET_ATTRIBUTES = 0x2,
+	RPMI_SYSMSI_SRV_GET_MSI_ATTRIBUTES = 0x3,
+	RPMI_SYSMSI_SRV_SET_MSI_STATE = 0x4,
+	RPMI_SYSMSI_SRV_GET_MSI_STATE = 0x5,
+	RPMI_SYSMSI_SRV_SET_MSI_TARGET = 0x6,
+	RPMI_SYSMSI_SRV_GET_MSI_TARGET = 0x7,
+	RPMI_SYSMSI_SRV_ID_MAX_COUNT,
+};
+
+/** Response for system MSI service group attributes */
+struct rpmi_sysmsi_get_attributes_resp {
+	s32 status;
+	u32 sys_num_msi;
+	u32 p2a_db_index;
+	u32 flag0;
+	u32 flag1;
+};
+
+/** Request for system MSI attributes */
+struct rpmi_sysmsi_get_msi_attributes_req {
+	u32 sys_msi_index;
+};
+
+/** Response for system MSI attributes */
+struct rpmi_sysmsi_get_msi_attributes_resp {
+	s32 status;
+	u32 flag0;
+	u32 flag1;
+	u8 name[16];
+};
+
+#define RPMI_SYSMSI_MSI_ATTRIBUTES_FLAG0_PREF_PRIV	(1U << 0)
+
+/** Request for system MSI set state */
+struct rpmi_sysmsi_set_msi_state_req {
+	u32 sys_msi_index;
+	u32 sys_msi_state;
+};
+
+#define RPMI_SYSMSI_MSI_STATE_ENABLE			(1U << 0)
+#define RPMI_SYSMSI_MSI_STATE_PENDING			(1U << 1)
+
+/** Response for system MSI set state */
+struct rpmi_sysmsi_set_msi_state_resp {
+	s32 status;
+};
+
+/** Request for system MSI get state */
+struct rpmi_sysmsi_get_msi_state_req {
+	u32 sys_msi_index;
+};
+
+/** Response for system MSI get state */
+struct rpmi_sysmsi_get_msi_state_resp {
+	s32 status;
+	u32 sys_msi_state;
+};
+
+/** Request for system MSI set target */
+struct rpmi_sysmsi_set_msi_target_req {
+	u32 sys_msi_index;
+	u32 sys_msi_address_low;
+	u32 sys_msi_address_high;
+	u32 sys_msi_data;
+};
+
+/** Response for system MSI set target */
+struct rpmi_sysmsi_set_msi_target_resp {
+	s32 status;
+};
+
+/** Request for system MSI get target */
+struct rpmi_sysmsi_get_msi_target_req {
+	u32 sys_msi_index;
+};
+
+/** Response for system MSI get target */
+struct rpmi_sysmsi_get_msi_target_resp {
+	s32 status;
+	u32 sys_msi_address_low;
+	u32 sys_msi_address_high;
+	u32 sys_msi_data;
+};
+
 /** RPMI System Reset ServiceGroup Service IDs */
 enum rpmi_system_reset_service_id {
 	RPMI_SYSRST_SRV_ENABLE_NOTIFICATION = 0x01,
lib/utils/mpxy/Kconfig +4 -0
index ff88f24f..8d1f5183 100644
@@ -18,6 +18,10 @@ config FDT_MPXY_RPMI_CLOCK
 	bool "MPXY driver for RPMI clock service group"
 	default n
 
+config FDT_MPXY_RPMI_SYSMSI
+	bool "MPXY driver for RPMI system MSI service group"
+	default n
+
 endif
 
 endmenu
lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c new file +204 -0

204 lines not on this page · raw message

lib/utils/mpxy/objects.mk +3 -0
index 1c9afed9..5b6e9bdf 100644
@@ -14,3 +14,6 @@ libsbiutils-objs-$(CONFIG_FDT_MPXY_RPMI_MBOX) += mpxy/fdt_mpxy_rpmi_mbox.o
 
 carray-fdt_mpxy_drivers-$(CONFIG_FDT_MPXY_RPMI_CLOCK) += fdt_mpxy_rpmi_clock
 libsbiutils-objs-$(CONFIG_FDT_MPXY_RPMI_CLOCK) += mpxy/fdt_mpxy_rpmi_clock.o
+
+carray-fdt_mpxy_drivers-$(CONFIG_FDT_MPXY_RPMI_SYSMSI) += fdt_mpxy_rpmi_sysmsi
+libsbiutils-objs-$(CONFIG_FDT_MPXY_RPMI_SYSMSI) += mpxy/fdt_mpxy_rpmi_sysmsi.o
platform/generic/configs/defconfig +1 -0
index 55607a28..bb260626 100644
@@ -56,3 +56,4 @@ CONFIG_FDT_TIMER_PLMT=y
 CONFIG_FDT_MPXY=y
 CONFIG_FDT_MPXY_RPMI_MBOX=y
 CONFIG_FDT_MPXY_RPMI_CLOCK=y
+CONFIG_FDT_MPXY_RPMI_SYSMSI=y
Signature · 1 line
2.43.0
author
#13 lore raw

PATCH v2 13/13 lib: sbi: Update MPXY framework and SBI extension as per latest spec

In reply to Anup Patel

The latest SBI 3.0 spec defines a new sbi_mpxy_get_shmem_size() function and simplifies sbi_mpxy_set_shmem() function so update the MPXY framework and SBI extension accordingly.

---
 include/sbi/sbi_ecall_interface.h | 15 ++++----
 include/sbi/sbi_mpxy.h            | 12 +++---
 lib/sbi/sbi_ecall_mpxy.c          |  7 +++-
 lib/sbi/sbi_mpxy.c                | 62 +++++++++++++++++--------------
 4 files changed, 55 insertions(+), 41 deletions(-)
include/sbi/sbi_ecall_interface.h +8 -7
index 0b6b5714..46a813e8 100644
@@ -423,13 +423,14 @@ enum sbi_sse_state {
 #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
+#define SBI_EXT_MPXY_GET_SHMEM_SIZE		0x0
+#define SBI_EXT_MPXY_SET_SHMEM			0x1
+#define SBI_EXT_MPXY_GET_CHANNEL_IDS		0x2
+#define SBI_EXT_MPXY_READ_ATTRS			0x3
+#define SBI_EXT_MPXY_WRITE_ATTRS		0x4
+#define SBI_EXT_MPXY_SEND_MSG_WITH_RESP		0x5
+#define SBI_EXT_MPXY_SEND_MSG_WITHOUT_RESP	0x6
+#define SBI_EXT_MPXY_GET_NOTIFICATION_EVENTS	0x7
 
 /* SBI base specification related macros */
 #define SBI_SPEC_VERSION_MAJOR_OFFSET		24
include/sbi/sbi_mpxy.h +7 -5
index e30a17d1..9da2791e 100644
@@ -153,11 +153,13 @@ int sbi_mpxy_init(struct sbi_scratch *scratch);
 /** Check if some Message proxy channel is available */
 bool sbi_mpxy_channel_available(void);
 
-/** Set Message proxy shared memory on the calling HART */
-int sbi_mpxy_set_shmem(unsigned long shmem_size,
-			unsigned long shmem_phys_lo,
-			unsigned long shmem_phys_hi,
-			unsigned long flags);
+/** Get message proxy shared memory size */
+unsigned long sbi_mpxy_get_shmem_size(void);
+
+/** Set message proxy shared memory on the calling HART */
+int sbi_mpxy_set_shmem(unsigned long shmem_phys_lo,
+		       unsigned long shmem_phys_hi,
+		       unsigned long flags);
 
 /** Get channel IDs list */
 int sbi_mpxy_get_channel_ids(u32 start_index);
lib/sbi/sbi_ecall_mpxy.c +5 -2
index 09705cce..03ac71b2 100644
@@ -20,8 +20,11 @@ static int sbi_ecall_mpxy_handler(unsigned long extid, unsigned long funcid,
 	int ret = 0;
 
 	switch (funcid) {
+	case SBI_EXT_MPXY_GET_SHMEM_SIZE:
+		out->value = sbi_mpxy_get_shmem_size();
+		break;
 	case SBI_EXT_MPXY_SET_SHMEM:
-		ret = sbi_mpxy_set_shmem(regs->a0, regs->a1, regs->a2, regs->a3);
+		ret = sbi_mpxy_set_shmem(regs->a0, regs->a1, regs->a2);
 		break;
 	case SBI_EXT_MPXY_GET_CHANNEL_IDS:
 		ret = sbi_mpxy_get_channel_ids(regs->a0);
@@ -36,7 +39,7 @@ static int sbi_ecall_mpxy_handler(unsigned long extid, unsigned long funcid,
 		ret = sbi_mpxy_send_message(regs->a0, regs->a1,
 					    regs->a2, &out->value);
 		break;
-	case SBI_EXT_MPXY_SEND_MSG_NO_RESP:
+	case SBI_EXT_MPXY_SEND_MSG_WITHOUT_RESP:
 		ret = sbi_mpxy_send_message(regs->a0, regs->a1, regs->a2,
 					    NULL);
 		break;
lib/sbi/sbi_mpxy.c +35 -27

176 lines not on this page · raw message

Signature · 1 line
2.43.0
Applied
#14 lore raw

v2 cover More RPMI and MPXY updates

In reply to Anup Patel
Quoted 30 lines · On Wed, Jan 22, 2025 at 12:14?PM Anup Patel <[email protected]> wrote:

This series does the following:
1) MPXY driver and framework cleanups
2) Update RPMI drivers as-per latest specification
3) Add MPXY RPMI driver for System MSI service group

These patches can also be found in the rpmi_updates_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,aia=aplic-imsic" as the QEMU machine name.

Changes since v1:
- Addressed comments in PATCH1, PATCH2, PATCH3, PATCH7, and PATCH12
- Added new PATCH13 to update MPXY framework and SBI extension based on latest specification.

Anup Patel (13):
lib: utils: Split the FDT MPXY RPMI mailbox client into two parts
lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox
lib: utils: Introduce optional MPXY RPMI service group operations
lib: sbi: Fix capability bit assignment in MPXY framework
lib: sbi: Improve local variable declarations in MPXY framework
lib: utils: Drop notifications from MPXY RPMI mailbox client
lib: utils: Improve variable declarations in MPXY RPMI mailbox client
include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header

Quoted 8 lines

lib: utils: Implement get_attribute() for the RPMI shared memory
mailbox
lib: utils: Populate MPXY channel attributes from RPMI channel
attributes
include: sbi_utils: Update RPMI service group IDs and BASE service
group
lib: utils: Add MPXY RPMI mailbox driver for System MSI service group
lib: sbi: Update MPXY framework and SBI extension as per latest spec

Applied this series to the riscv/opensbi repo.

Thanks,
Anup

Quoted 23 lines
 include/sbi/sbi_ecall_interface.h           |  15 +-
 include/sbi/sbi_mpxy.h                      |  12 +-
 include/sbi_utils/mailbox/rpmi_mailbox.h    |   1 +
 include/sbi_utils/mailbox/rpmi_msgprot.h    | 117 +++++++-
 include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h |  79 +++++
 lib/sbi/sbi_ecall_mpxy.c                    |   7 +-
 lib/sbi/sbi_mpxy.c                          | 139 +++++----
 lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c  |  39 ++-
 lib/utils/mpxy/Kconfig                      |  16 +-
 lib/utils/mpxy/fdt_mpxy_rpmi_clock.c        |  87 ++++++
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c         | 312 +++++++-------------
 lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c       | 204 +++++++++++++
 lib/utils/mpxy/objects.mk                   |   7 +-
 platform/generic/configs/defconfig          |   2 +
 14 files changed, 726 insertions(+), 311 deletions(-)
 create mode 100644 include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c

--
2.43.0