* [PATCH v2 01/13] lib: utils: Split the FDT MPXY RPMI mailbox client into two parts
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 02/13] lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox Anup Patel
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
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.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
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
diff --git a/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
new file mode 100644
index 00000000..17b50557
--- /dev/null
+++ b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
@@ -0,0 +1,71 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ * Anup Patel <apatel@ventanamicro.com>
+ */
+
+#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
diff --git a/lib/utils/mpxy/Kconfig b/lib/utils/mpxy/Kconfig
index 131fb91a..ff88f24f 100644
--- a/lib/utils/mpxy/Kconfig
+++ b/lib/utils/mpxy/Kconfig
@@ -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
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
new file mode 100644
index 00000000..d2ce0718
--- /dev/null
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
@@ -0,0 +1,88 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ * Rahul Pathak <rpathak@ventanamicro.com>
+ * Anup Patel <apatel@ventanamicro.com>
+ */
+
+#include <sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h>
+
+static struct mpxy_rpmi_service_data clock_services[] = {
+{
+ .id = RPMI_CLOCK_SRV_ENABLE_NOTIFICATION,
+ .min_tx_len = sizeof(struct rpmi_enable_notification_req),
+ .max_tx_len = sizeof(struct rpmi_enable_notification_req),
+ .min_rx_len = sizeof(struct rpmi_enable_notification_resp),
+ .max_rx_len = sizeof(struct rpmi_enable_notification_resp),
+},
+{
+ .id = RPMI_CLOCK_SRV_GET_NUM_CLOCKS,
+ .min_tx_len = 0,
+ .max_tx_len = 0,
+ .min_rx_len = sizeof(struct rpmi_clock_get_num_clocks_resp),
+ .max_rx_len = sizeof(struct rpmi_clock_get_num_clocks_resp),
+},
+{
+ .id = RPMI_CLOCK_SRV_GET_ATTRIBUTES,
+ .min_tx_len = sizeof(struct rpmi_clock_get_attributes_req),
+ .max_tx_len = sizeof(struct rpmi_clock_get_attributes_req),
+ .min_rx_len = sizeof(struct rpmi_clock_get_attributes_resp),
+ .max_rx_len = sizeof(struct rpmi_clock_get_attributes_resp),
+},
+{
+ .id = RPMI_CLOCK_SRV_GET_SUPPORTED_RATES,
+ .min_tx_len = sizeof(struct rpmi_clock_get_supported_rates_req),
+ .max_tx_len = sizeof(struct rpmi_clock_get_supported_rates_req),
+ .min_rx_len = sizeof(struct rpmi_clock_get_supported_rates_resp),
+ .max_rx_len = -1U,
+},
+{
+ .id = RPMI_CLOCK_SRV_SET_CONFIG,
+ .min_tx_len = sizeof(struct rpmi_clock_set_config_req),
+ .max_tx_len = sizeof(struct rpmi_clock_set_config_req),
+ .min_rx_len = sizeof(struct rpmi_clock_set_config_resp),
+ .max_rx_len = sizeof(struct rpmi_clock_set_config_resp),
+},
+{
+ .id = RPMI_CLOCK_SRV_GET_CONFIG,
+ .min_tx_len = sizeof(struct rpmi_clock_get_config_req),
+ .max_tx_len = sizeof(struct rpmi_clock_get_config_req),
+ .min_rx_len = sizeof(struct rpmi_clock_get_config_resp),
+ .max_rx_len = sizeof(struct rpmi_clock_get_config_resp),
+},
+{
+ .id = RPMI_CLOCK_SRV_SET_RATE,
+ .min_tx_len = sizeof(struct rpmi_clock_set_rate_req),
+ .max_tx_len = sizeof(struct rpmi_clock_set_rate_req),
+ .min_rx_len = sizeof(struct rpmi_clock_set_rate_resp),
+ .max_rx_len = sizeof(struct rpmi_clock_set_rate_resp),
+},
+{
+ .id = RPMI_CLOCK_SRV_GET_RATE,
+ .min_tx_len = sizeof(struct rpmi_clock_get_rate_req),
+ .max_tx_len = sizeof(struct rpmi_clock_get_rate_req),
+ .min_rx_len = sizeof(struct rpmi_clock_get_rate_resp),
+ .max_rx_len = sizeof(struct rpmi_clock_get_rate_resp),
+},
+};
+
+static 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,
+};
+
+static const struct fdt_match clock_match[] = {
+ { .compatible = "riscv,rpmi-mpxy-clock", .data = &clock_data },
+ { },
+};
+
+const struct fdt_driver fdt_mpxy_rpmi_clock = {
+ .match_table = clock_match,
+ .init = mpxy_rpmi_mbox_init,
+ .experimental = true,
+};
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
index 78020eae..0d4fd1fe 100644
--- a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
@@ -11,82 +11,32 @@
#include <libfdt.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_heap.h>
-#include <sbi/sbi_mpxy.h>
#include <sbi_utils/fdt/fdt_helper.h>
-#include <sbi_utils/mpxy/fdt_mpxy.h>
+#include <sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h>
#include <sbi_utils/mailbox/fdt_mailbox.h>
-#include <sbi_utils/mailbox/rpmi_msgprot.h>
#include <sbi/sbi_console.h>
-#define RPMI_MAJOR_VER (1)
-#define 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;
-};
-
-/* RPMI mbox data per service group */
-struct mpxy_mbox_data {
- u32 servicegrp_id;
- u32 num_services;
- u32 notifications_support;
- void *priv_data;
-};
-
-/* RPMI service data per service group */
-struct rpmi_service_data {
- u8 id;
- u32 min_tx_len;
- u32 max_tx_len;
- u32 min_rx_len;
- u32 max_rx_len;
-};
-
/**
* MPXY mbox instance per MPXY channel. This ties
* an MPXY channel with an RPMI Service group.
*/
-struct mpxy_mbox {
+struct mpxy_rpmi_mbox {
struct mbox_chan *chan;
- struct mpxy_mbox_data *mbox_data;
+ struct mpxy_rpmi_mbox_data *mbox_data;
struct mpxy_rpmi_channel_attrs msgprot_attrs;
struct sbi_mpxy_channel channel;
};
-/** 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);
-
/**
* Discover the RPMI service data using message_id
* MPXY message_id == RPMI service_id
*/
-static struct rpmi_service_data *mpxy_find_rpmi_srvid(u32 message_id,
- struct mpxy_mbox_data *mbox_data)
+static struct mpxy_rpmi_service_data *mpxy_find_rpmi_srvid(u32 message_id,
+ struct mpxy_rpmi_mbox_data *mbox_data)
{
int mid = 0;
- struct rpmi_service_data *srv = mbox_data->priv_data;
+ 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)
return &srv[mid];
@@ -108,9 +58,8 @@ static int mpxy_mbox_read_attributes(struct sbi_mpxy_channel *channel,
u32 attr_count)
{
u32 end_id;
- struct mpxy_mbox *rmb =
- container_of(channel, struct mpxy_mbox, channel);
-
+ 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;
@@ -161,8 +110,8 @@ static int mpxy_mbox_write_attributes(struct sbi_mpxy_channel *channel,
{
int ret, mem_idx;
u32 end_id, attr_val, idx;
- struct mpxy_mbox *rmb =
- container_of(channel, struct mpxy_mbox, channel);
+ struct mpxy_rpmi_mbox *rmb =
+ container_of(channel, struct mpxy_rpmi_mbox, channel);
end_id = base_attr_id + attr_count - 1;
@@ -195,9 +144,9 @@ static int __mpxy_mbox_send_message(struct sbi_mpxy_channel *channel,
u32 rx_len = 0;
struct mbox_xfer xfer;
struct rpmi_message_args args = {0};
- struct mpxy_mbox *rmb =
- container_of(channel, struct mpxy_mbox, channel);
- struct rpmi_service_data *srv =
+ 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);
if (!srv)
return SBI_ENOTSUPP;
@@ -266,15 +215,14 @@ static int mpxy_mbox_get_notifications(struct sbi_mpxy_channel *channel,
return SBI_ENOTSUPP;
}
-static int mpxy_mbox_init(const void *fdt, int nodeoff,
- const struct fdt_match *match)
+int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *match)
{
int rc, len;
const fdt32_t *val;
u32 channel_id;
- struct mpxy_mbox *rmb;
struct mbox_chan *chan;
- const struct mpxy_mbox_data *data = match->data;
+ struct mpxy_rpmi_mbox *rmb;
+ const struct mpxy_rpmi_mbox_data *data = match->data;
/* Allocate context for RPXY mbox client */
rmb = sbi_zalloc(sizeof(*rmb));
@@ -334,7 +282,7 @@ static int mpxy_mbox_init(const void *fdt, int nodeoff,
rmb->channel.attrs.msg_proto_id = SBI_MPXY_MSGPROTO_RPMI_ID;
/* RPMI Message Protocol Version */
rmb->channel.attrs.msg_proto_version =
- SBI_MPXY_MSGPROTO_VERSION(RPMI_MAJOR_VER, RPMI_MINOR_VER);
+ SBI_MPXY_MSGPROTO_VERSION(MPXY_RPMI_MAJOR_VER, MPXY_RPMI_MINOR_VER);
/* RPMI supported max message data length(bytes), same for
* all service groups */
@@ -349,9 +297,9 @@ static int mpxy_mbox_init(const void *fdt, int nodeoff,
/* RPMI message protocol attributes */
rmb->msgprot_attrs.servicegrp_id = data->servicegrp_id;
rmb->msgprot_attrs.servicegrp_ver =
- SBI_MPXY_MSGPROTO_VERSION(RPMI_MAJOR_VER, RPMI_MINOR_VER);
+ SBI_MPXY_MSGPROTO_VERSION(MPXY_RPMI_MAJOR_VER, MPXY_RPMI_MINOR_VER);
- rmb->mbox_data = (struct mpxy_mbox_data *)data;
+ rmb->mbox_data = (struct mpxy_rpmi_mbox_data *)data;
rmb->chan = chan;
/* Register RPXY service group */
@@ -364,80 +312,3 @@ static int mpxy_mbox_init(const void *fdt, int nodeoff,
return SBI_OK;
}
-
-static struct rpmi_service_data clock_services[] = {
-{
- .id = RPMI_CLOCK_SRV_ENABLE_NOTIFICATION,
- .min_tx_len = sizeof(struct rpmi_enable_notification_req),
- .max_tx_len = sizeof(struct rpmi_enable_notification_req),
- .min_rx_len = sizeof(struct rpmi_enable_notification_resp),
- .max_rx_len = sizeof(struct rpmi_enable_notification_resp),
-},
-{
- .id = RPMI_CLOCK_SRV_GET_NUM_CLOCKS,
- .min_tx_len = 0,
- .max_tx_len = 0,
- .min_rx_len = sizeof(struct rpmi_clock_get_num_clocks_resp),
- .max_rx_len = sizeof(struct rpmi_clock_get_num_clocks_resp),
-},
-{
- .id = RPMI_CLOCK_SRV_GET_ATTRIBUTES,
- .min_tx_len = sizeof(struct rpmi_clock_get_attributes_req),
- .max_tx_len = sizeof(struct rpmi_clock_get_attributes_req),
- .min_rx_len = sizeof(struct rpmi_clock_get_attributes_resp),
- .max_rx_len = sizeof(struct rpmi_clock_get_attributes_resp),
-},
-{
- .id = RPMI_CLOCK_SRV_GET_SUPPORTED_RATES,
- .min_tx_len = sizeof(struct rpmi_clock_get_supported_rates_req),
- .max_tx_len = sizeof(struct rpmi_clock_get_supported_rates_req),
- .min_rx_len = sizeof(struct rpmi_clock_get_supported_rates_resp),
- .max_rx_len = -1U,
-},
-{
- .id = RPMI_CLOCK_SRV_SET_CONFIG,
- .min_tx_len = sizeof(struct rpmi_clock_set_config_req),
- .max_tx_len = sizeof(struct rpmi_clock_set_config_req),
- .min_rx_len = sizeof(struct rpmi_clock_set_config_resp),
- .max_rx_len = sizeof(struct rpmi_clock_set_config_resp),
-},
-{
- .id = RPMI_CLOCK_SRV_GET_CONFIG,
- .min_tx_len = sizeof(struct rpmi_clock_get_config_req),
- .max_tx_len = sizeof(struct rpmi_clock_get_config_req),
- .min_rx_len = sizeof(struct rpmi_clock_get_config_resp),
- .max_rx_len = sizeof(struct rpmi_clock_get_config_resp),
-},
-{
- .id = RPMI_CLOCK_SRV_SET_RATE,
- .min_tx_len = sizeof(struct rpmi_clock_set_rate_req),
- .max_tx_len = sizeof(struct rpmi_clock_set_rate_req),
- .min_rx_len = sizeof(struct rpmi_clock_set_rate_resp),
- .max_rx_len = sizeof(struct rpmi_clock_set_rate_resp),
-},
-{
- .id = RPMI_CLOCK_SRV_GET_RATE,
- .min_tx_len = sizeof(struct rpmi_clock_get_rate_req),
- .max_tx_len = sizeof(struct rpmi_clock_get_rate_req),
- .min_rx_len = sizeof(struct rpmi_clock_get_rate_resp),
- .max_rx_len = sizeof(struct rpmi_clock_get_rate_resp),
-},
-};
-
-static struct mpxy_mbox_data clock_data = {
- .servicegrp_id = RPMI_SRVGRP_CLOCK,
- .num_services = RPMI_CLOCK_SRV_MAX_COUNT,
- .notifications_support = 1,
- .priv_data = clock_services,
-};
-
-static const struct fdt_match mpxy_mbox_match[] = {
- { .compatible = "riscv,rpmi-mpxy-clock", .data = &clock_data },
- { },
-};
-
-struct fdt_driver fdt_mpxy_rpmi_mbox = {
- .match_table = mpxy_mbox_match,
- .init = mpxy_mbox_init,
- .experimental = true,
-};
diff --git a/lib/utils/mpxy/objects.mk b/lib/utils/mpxy/objects.mk
index ccb28b55..1c9afed9 100644
--- a/lib/utils/mpxy/objects.mk
+++ b/lib/utils/mpxy/objects.mk
@@ -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
diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig
index e23b38b2..55607a28 100644
--- a/platform/generic/configs/defconfig
+++ b/platform/generic/configs/defconfig
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 02/13] lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
2025-01-22 6:44 ` [PATCH v2 01/13] lib: utils: Split the FDT MPXY RPMI mailbox client into two parts Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 03/13] lib: utils: Introduce optional MPXY RPMI service group operations Anup Patel
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
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.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
---
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(-)
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
index d2ce0718..4e36d4f5 100644
--- a/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
@@ -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,
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
index 0d4fd1fe..7034fb9e 100644
--- a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
@@ -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 */
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 03/13] lib: utils: Introduce optional MPXY RPMI service group operations
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
2025-01-22 6:44 ` [PATCH v2 01/13] lib: utils: Split the FDT MPXY RPMI mailbox client into two parts Anup Patel
2025-01-22 6:44 ` [PATCH v2 02/13] lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 04/13] lib: sbi: Fix capability bit assignment in MPXY framework Anup Patel
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
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.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
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(-)
diff --git a/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
index 17b50557..df81a73d 100644
--- a/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
+++ b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
@@ -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 */
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
index 7034fb9e..6db750fb 100644
--- a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 04/13] lib: sbi: Fix capability bit assignment in MPXY framework
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
` (2 preceding siblings ...)
2025-01-22 6:44 ` [PATCH v2 03/13] lib: utils: Introduce optional MPXY RPMI service group operations Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 05/13] lib: sbi: Improve local variable declarations " Anup Patel
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
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")
Signed-off-by: Anup patel <apatel@ventanamicro.com>
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
---
lib/sbi/sbi_mpxy.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lib/sbi/sbi_mpxy.c b/lib/sbi/sbi_mpxy.c
index 639478bf..91b212a6 100644
--- a/lib/sbi/sbi_mpxy.c
+++ b/lib/sbi/sbi_mpxy.c
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 05/13] lib: sbi: Improve local variable declarations in MPXY framework
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
` (3 preceding siblings ...)
2025-01-22 6:44 ` [PATCH v2 04/13] lib: sbi: Fix capability bit assignment in MPXY framework Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 06/13] lib: utils: Drop notifications from MPXY RPMI mailbox client Anup Patel
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
The local variable declarations should be at the start of function
and preferrably organized like a inverted pyramid.
Signed-off-by: Anup patel <apatel@ventanamicro.com>
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
---
lib/sbi/sbi_mpxy.c | 65 ++++++++++++++++++----------------------------
1 file changed, 25 insertions(+), 40 deletions(-)
diff --git a/lib/sbi/sbi_mpxy.c b/lib/sbi/sbi_mpxy.c
index 91b212a6..6a5605ea 100644
--- a/lib/sbi/sbi_mpxy.c
+++ b/lib/sbi/sbi_mpxy.c
@@ -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);
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 06/13] lib: utils: Drop notifications from MPXY RPMI mailbox client
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
` (4 preceding siblings ...)
2025-01-22 6:44 ` [PATCH v2 05/13] lib: sbi: Improve local variable declarations " Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 07/13] lib: utils: Improve variable declarations in " Anup Patel
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
Currently, the common MPXY RPMI mailbox client does not support
notifications so no need for dummy notifications support.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
---
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(-)
diff --git a/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
index df81a73d..373b077a 100644
--- a/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
+++ b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
@@ -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 */
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
index 4e36d4f5..7d2b4a20 100644
--- a/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
@@ -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,
};
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
index 6db750fb..cbcea4f2 100644
--- a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 07/13] lib: utils: Improve variable declarations in MPXY RPMI mailbox client
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
` (5 preceding siblings ...)
2025-01-22 6:44 ` [PATCH v2 06/13] lib: utils: Drop notifications from MPXY RPMI mailbox client Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 08/13] include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header Anup Patel
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
The local variable declarations should be at the start of function
and preferrably organized like a inverted pyramid.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
---
lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
index cbcea4f2..f8de91a5 100644
--- a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
@@ -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));
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 08/13] include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
` (6 preceding siblings ...)
2025-01-22 6:44 ` [PATCH v2 07/13] lib: utils: Improve variable declarations in " Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 09/13] lib: utils: Implement get_attribute() for the RPMI shared memory mailbox Anup Patel
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
The rpmi_mailbox.h uses structures defined in mailbox.h so let's
include mailbox.h in rpmi_mailbox.h header.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
---
include/sbi_utils/mailbox/rpmi_mailbox.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/sbi_utils/mailbox/rpmi_mailbox.h b/include/sbi_utils/mailbox/rpmi_mailbox.h
index 61af51a8..a23ad8ca 100644
--- a/include/sbi_utils/mailbox/rpmi_mailbox.h
+++ b/include/sbi_utils/mailbox/rpmi_mailbox.h
@@ -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))
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 09/13] lib: utils: Implement get_attribute() for the RPMI shared memory mailbox
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
` (7 preceding siblings ...)
2025-01-22 6:44 ` [PATCH v2 08/13] include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 10/13] lib: utils: Populate MPXY channel attributes from RPMI channel attributes Anup Patel
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
To allow clients query service group version of a RPMI mailbox channel,
implement get_attribute() callback for the RPMI shared memory mailbox
controller.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
include/sbi_utils/mailbox/rpmi_msgprot.h | 13 +++++++-
lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c | 35 ++++++++++++++++++++++
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/include/sbi_utils/mailbox/rpmi_msgprot.h b/include/sbi_utils/mailbox/rpmi_msgprot.h
index 9575dc72..17d678a3 100644
--- a/include/sbi_utils/mailbox/rpmi_msgprot.h
+++ b/include/sbi_utils/mailbox/rpmi_msgprot.h
@@ -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
*/
diff --git a/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c b/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
index b8bd3cd6..e9f52c7a 100644
--- a/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
+++ b/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 10/13] lib: utils: Populate MPXY channel attributes from RPMI channel attributes
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
` (8 preceding siblings ...)
2025-01-22 6:44 ` [PATCH v2 09/13] lib: utils: Implement get_attribute() for the RPMI shared memory mailbox Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 11/13] include: sbi_utils: Update RPMI service group IDs and BASE service group Anup Patel
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
Use the RPMI mailbox channel attributes to populate MPXY channel
attributes instead of hard coding them.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
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(-)
diff --git a/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
index 373b077a..068a1a55 100644
--- a/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
+++ b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
@@ -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)
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
index f8de91a5..48dfe476 100644
--- a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
@@ -212,14 +212,14 @@ 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)
{
+ u32 channel_id, servicegrp_ver, pro_ver, max_data_len, tx_tout, rx_tout;
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;
int rc, len;
- /* Allocate context for RPXY mbox client */
+ /* Allocate context for MPXY mbox client */
rmb = sbi_zalloc(sizeof(*rmb));
if (!rmb)
return SBI_ENOMEM;
@@ -230,29 +230,57 @@ int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *ma
*/
rc = fdt_mailbox_request_chan(fdt, nodeoff, 0, &chan);
if (rc) {
- sbi_free(rmb);
- return SBI_ENODEV;
+ rc = SBI_ENODEV;
+ goto fail_free_client;
}
/* Match channel service group id */
if (data->servicegrp_id != chan->chan_args[0]) {
- mbox_controller_free_chan(chan);
- sbi_free(rmb);
- return SBI_EINVAL;
+ rc = SBI_EINVAL;
+ goto fail_free_chan;
}
+ /* Get channel protocol version */
+ rc = mbox_chan_get_attribute(chan, RPMI_CHANNEL_ATTR_PROTOCOL_VERSION,
+ &pro_ver);
+ if (rc)
+ goto fail_free_chan;
+
+ /* Get channel maximum data length */
+ rc = mbox_chan_get_attribute(chan, RPMI_CHANNEL_ATTR_MAX_DATA_LEN,
+ &max_data_len);
+ if (rc)
+ goto fail_free_chan;
+
+ /* Get channel Tx timeout */
+ rc = mbox_chan_get_attribute(chan, RPMI_CHANNEL_ATTR_TX_TIMEOUT,
+ &tx_tout);
+ if (rc)
+ goto fail_free_chan;
+
+ /* Get channel Rx timeout */
+ rc = mbox_chan_get_attribute(chan, RPMI_CHANNEL_ATTR_RX_TIMEOUT,
+ &rx_tout);
+ if (rc)
+ goto fail_free_chan;
+
+ /* Get channel service group version */
+ rc = mbox_chan_get_attribute(chan, RPMI_CHANNEL_ATTR_SERVICEGROUP_VERSION,
+ &servicegrp_ver);
+ if (rc)
+ goto fail_free_chan;
+
/*
* The "riscv,sbi-mpxy-channel-id" DT property is mandatory
* for MPXY RPMI mailbox client driver so if this is not
* present then try other drivers.
*/
val = fdt_getprop(fdt, nodeoff, "riscv,sbi-mpxy-channel-id", &len);
- if (len > 0 && val)
+ if (len > 0 && val) {
channel_id = fdt32_to_cpu(*val);
- else {
- mbox_controller_free_chan(chan);
- sbi_free(rmb);
- return SBI_ENODEV;
+ } else {
+ rc = SBI_ENODEV;
+ goto fail_free_chan;
}
/* Setup MPXY mbox client */
@@ -271,23 +299,23 @@ int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *ma
/* RPMI Message Protocol ID */
rmb->channel.attrs.msg_proto_id = SBI_MPXY_MSGPROTO_RPMI_ID;
/* RPMI Message Protocol Version */
- rmb->channel.attrs.msg_proto_version =
- SBI_MPXY_MSGPROTO_VERSION(MPXY_RPMI_MAJOR_VER, MPXY_RPMI_MINOR_VER);
-
- /* RPMI supported max message data length(bytes), same for
- * all service groups */
- rmb->channel.attrs.msg_data_maxlen =
- RPMI_MSG_DATA_SIZE(RPMI_SLOT_SIZE_MIN);
- /* RPMI message send timeout(milliseconds)
- * same for all service groups */
- rmb->channel.attrs.msg_send_timeout = RPMI_DEF_TX_TIMEOUT;
- rmb->channel.attrs.msg_completion_timeout =
- RPMI_DEF_TX_TIMEOUT + RPMI_DEF_RX_TIMEOUT;
-
- /* RPMI message protocol attributes */
+ rmb->channel.attrs.msg_proto_version = pro_ver;
+
+ /*
+ * RPMI supported max message data length(bytes), same for
+ * all service groups
+ */
+ rmb->channel.attrs.msg_data_maxlen = max_data_len;
+ /*
+ * RPMI message send timeout(milliseconds)
+ * same for all service groups
+ */
+ rmb->channel.attrs.msg_send_timeout = tx_tout;
+ rmb->channel.attrs.msg_completion_timeout = tx_tout + rx_tout;
+
+ /* RPMI service group attributes */
rmb->msgprot_attrs.servicegrp_id = data->servicegrp_id;
- rmb->msgprot_attrs.servicegrp_ver =
- SBI_MPXY_MSGPROTO_VERSION(MPXY_RPMI_MAJOR_VER, MPXY_RPMI_MINOR_VER);
+ rmb->msgprot_attrs.servicegrp_ver = servicegrp_ver;
rmb->mbox_data = data;
rmb->chan = chan;
@@ -295,11 +323,8 @@ int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *ma
/* 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;
- }
+ if (rc)
+ goto fail_free_chan;
}
/* Register RPMI service group */
@@ -307,10 +332,14 @@ int mpxy_rpmi_mbox_init(const void *fdt, int nodeoff, const struct fdt_match *ma
if (rc) {
if (data->cleanup_group)
data->cleanup_group(rmb->group_context);
- mbox_controller_free_chan(chan);
- sbi_free(rmb);
- return rc;
+ goto fail_free_chan;
}
return SBI_OK;
+
+fail_free_chan:
+ mbox_controller_free_chan(chan);
+fail_free_client:
+ sbi_free(rmb);
+ return rc;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 11/13] include: sbi_utils: Update RPMI service group IDs and BASE service group
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
` (9 preceding siblings ...)
2025-01-22 6:44 ` [PATCH v2 10/13] lib: utils: Populate MPXY channel attributes from RPMI channel attributes Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 12/13] lib: utils: Add MPXY RPMI mailbox driver for System MSI " Anup Patel
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
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.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
---
include/sbi_utils/mailbox/rpmi_msgprot.h | 16 +++++++---------
lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c | 4 ----
2 files changed, 7 insertions(+), 13 deletions(-)
diff --git a/include/sbi_utils/mailbox/rpmi_msgprot.h b/include/sbi_utils/mailbox/rpmi_msgprot.h
index 17d678a3..363cc653 100644
--- a/include/sbi_utils/mailbox/rpmi_msgprot.h
+++ b/include/sbi_utils/mailbox/rpmi_msgprot.h
@@ -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,
diff --git a/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c b/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
index e9f52c7a..5b858d36 100644
--- a/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
+++ b/lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c
@@ -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) {
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 12/13] lib: utils: Add MPXY RPMI mailbox driver for System MSI service group
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
` (10 preceding siblings ...)
2025-01-22 6:44 ` [PATCH v2 11/13] include: sbi_utils: Update RPMI service group IDs and BASE service group Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-01-22 6:44 ` [PATCH v2 13/13] lib: sbi: Update MPXY framework and SBI extension as per latest spec Anup Patel
2025-02-13 5:48 ` [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
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.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
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
diff --git a/include/sbi_utils/mailbox/rpmi_msgprot.h b/include/sbi_utils/mailbox/rpmi_msgprot.h
index 363cc653..8d8fa5e5 100644
--- a/include/sbi_utils/mailbox/rpmi_msgprot.h
+++ b/include/sbi_utils/mailbox/rpmi_msgprot.h
@@ -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,
diff --git a/lib/utils/mpxy/Kconfig b/lib/utils/mpxy/Kconfig
index ff88f24f..8d1f5183 100644
--- a/lib/utils/mpxy/Kconfig
+++ b/lib/utils/mpxy/Kconfig
@@ -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
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c b/lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c
new file mode 100644
index 00000000..87e6aa53
--- /dev/null
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c
@@ -0,0 +1,204 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 Ventana Micro Systems Inc.
+ */
+
+#include <sbi/sbi_bitmap.h>
+#include <sbi/sbi_domain.h>
+#include <sbi/sbi_byteorder.h>
+#include <sbi/sbi_heap.h>
+#include <sbi_utils/mailbox/rpmi_mailbox.h>
+#include <sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h>
+
+struct mpxy_rpmi_sysmsi {
+ u32 sys_num_msi;
+ unsigned long *sys_msi_denied_bmap;
+};
+
+static int mpxy_rpmi_sysmis_xfer(void *context, struct mbox_chan *chan,
+ struct mbox_xfer *xfer)
+{
+ struct rpmi_message_args *args = xfer->args;
+ struct mpxy_rpmi_sysmsi *smg = context;
+ u64 sys_msi_address;
+ u32 sys_msi_index;
+ int rc = 0;
+
+ if (!xfer->rx || args->type != RPMI_MSG_NORMAL_REQUEST)
+ return 0;
+
+ switch (args->service_id) {
+ case RPMI_SYSMSI_SRV_GET_ATTRIBUTES:
+ ((u32 *)xfer->rx)[0] = cpu_to_le32(RPMI_SUCCESS);
+ ((u32 *)xfer->rx)[1] = cpu_to_le32(smg->sys_num_msi);
+ ((u32 *)xfer->rx)[2] = -1U;
+ ((u32 *)xfer->rx)[3] = 0;
+ ((u32 *)xfer->rx)[4] = 0;
+ args->rx_data_len = 5 * sizeof(u32);
+ break;
+ case RPMI_SYSMSI_SRV_GET_MSI_ATTRIBUTES:
+ case RPMI_SYSMSI_SRV_SET_MSI_STATE:
+ case RPMI_SYSMSI_SRV_GET_MSI_STATE:
+ case RPMI_SYSMSI_SRV_SET_MSI_TARGET:
+ case RPMI_SYSMSI_SRV_GET_MSI_TARGET:
+ sys_msi_index = le32_to_cpu(((u32 *)xfer->tx)[0]);
+ if (smg->sys_num_msi <= sys_msi_index) {
+ ((u32 *)xfer->rx)[0] = cpu_to_le32(RPMI_ERR_INVALID_PARAM);
+ args->rx_data_len = sizeof(u32);
+ break;
+ }
+ if (bitmap_test(smg->sys_msi_denied_bmap, sys_msi_index)) {
+ ((u32 *)xfer->rx)[0] = cpu_to_le32(RPMI_ERR_DENIED);
+ args->rx_data_len = sizeof(u32);
+ break;
+ }
+ if (args->service_id == RPMI_SYSMSI_SRV_SET_MSI_TARGET) {
+ sys_msi_address = le32_to_cpu(((u32 *)xfer->tx)[1]);
+ sys_msi_address |= ((u64)le32_to_cpu(((u32 *)xfer->tx)[2])) << 32;
+ if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(),
+ sys_msi_address, 0x4, PRV_S,
+ SBI_DOMAIN_READ | SBI_DOMAIN_WRITE)) {
+ ((u32 *)xfer->rx)[0] = cpu_to_le32(RPMI_ERR_INVALID_ADDR);
+ args->rx_data_len = sizeof(u32);
+ break;
+ }
+ }
+ rc = mbox_chan_xfer(chan, xfer);
+ break;
+ default:
+ ((u32 *)xfer->rx)[0] = cpu_to_le32(RPMI_ERR_NOTSUPP);
+ args->rx_data_len = sizeof(u32);
+ break;
+ };
+
+ return rc;
+}
+
+static void mpxy_rpmi_sysmsi_cleanup(void *context)
+{
+ struct mpxy_rpmi_sysmsi *smg = context;
+
+ sbi_free(smg->sys_msi_denied_bmap);
+ sbi_free(smg);
+}
+
+static int mpxy_rpmi_sysmsi_setup(void **context, struct mbox_chan *chan,
+ const struct mpxy_rpmi_mbox_data *data)
+{
+ struct rpmi_sysmsi_get_msi_attributes_resp gmaresp;
+ struct rpmi_sysmsi_get_msi_attributes_req gmareq;
+ struct rpmi_sysmsi_get_attributes_resp garesp;
+ struct mpxy_rpmi_sysmsi *smg;
+ int rc, i;
+
+ rc = rpmi_normal_request_with_status(chan, RPMI_SYSMSI_SRV_GET_ATTRIBUTES,
+ NULL, 0, 0, &garesp, rpmi_u32_count(garesp),
+ rpmi_u32_count(garesp));
+ if (rc)
+ return rc;
+
+ smg = sbi_zalloc(sizeof(*smg));
+ if (!smg)
+ return SBI_ENOMEM;
+
+ smg->sys_num_msi = garesp.sys_num_msi;
+ smg->sys_msi_denied_bmap = sbi_zalloc(bitmap_estimate_size(smg->sys_num_msi));
+ if (!smg->sys_msi_denied_bmap) {
+ sbi_free(smg);
+ return SBI_ENOMEM;
+ }
+
+ for (i = 0; i < smg->sys_num_msi; i++) {
+ gmareq.sys_msi_index = i;
+ rc = rpmi_normal_request_with_status(chan,
+ RPMI_SYSMSI_SRV_GET_MSI_ATTRIBUTES,
+ &gmareq, rpmi_u32_count(gmareq),
+ rpmi_u32_count(gmareq),
+ &gmaresp, rpmi_u32_count(gmaresp),
+ rpmi_u32_count(gmaresp));
+ if (rc) {
+ mpxy_rpmi_sysmsi_cleanup(smg);
+ return rc;
+ }
+
+ if (garesp.p2a_db_index == i ||
+ (gmaresp.flag0 & RPMI_SYSMSI_MSI_ATTRIBUTES_FLAG0_PREF_PRIV))
+ bitmap_set(smg->sys_msi_denied_bmap, i, 1);
+ }
+
+ *context = smg;
+ return 0;
+}
+
+static struct mpxy_rpmi_service_data sysmsi_services[] = {
+{
+ .id = RPMI_SYSMSI_SRV_ENABLE_NOTIFICATION,
+ .min_tx_len = sizeof(struct rpmi_enable_notification_req),
+ .max_tx_len = sizeof(struct rpmi_enable_notification_req),
+ .min_rx_len = sizeof(struct rpmi_enable_notification_resp),
+ .max_rx_len = sizeof(struct rpmi_enable_notification_resp),
+},
+{
+ .id = RPMI_SYSMSI_SRV_GET_ATTRIBUTES,
+ .min_tx_len = 0,
+ .max_tx_len = 0,
+ .min_rx_len = sizeof(struct rpmi_sysmsi_get_attributes_resp),
+ .max_rx_len = sizeof(struct rpmi_sysmsi_get_attributes_resp),
+},
+{
+ .id = RPMI_SYSMSI_SRV_GET_MSI_ATTRIBUTES,
+ .min_tx_len = sizeof(struct rpmi_sysmsi_get_msi_attributes_req),
+ .max_tx_len = sizeof(struct rpmi_sysmsi_get_msi_attributes_req),
+ .min_rx_len = sizeof(struct rpmi_sysmsi_get_msi_attributes_resp),
+ .max_rx_len = sizeof(struct rpmi_sysmsi_get_msi_attributes_resp),
+},
+{
+ .id = RPMI_SYSMSI_SRV_SET_MSI_STATE,
+ .min_tx_len = sizeof(struct rpmi_sysmsi_set_msi_state_req),
+ .max_tx_len = sizeof(struct rpmi_sysmsi_set_msi_state_req),
+ .min_rx_len = sizeof(struct rpmi_sysmsi_set_msi_state_resp),
+ .max_rx_len = sizeof(struct rpmi_sysmsi_set_msi_state_resp),
+},
+{
+ .id = RPMI_SYSMSI_SRV_GET_MSI_STATE,
+ .min_tx_len = sizeof(struct rpmi_sysmsi_get_msi_state_req),
+ .max_tx_len = sizeof(struct rpmi_sysmsi_get_msi_state_req),
+ .min_rx_len = sizeof(struct rpmi_sysmsi_get_msi_state_resp),
+ .max_rx_len = sizeof(struct rpmi_sysmsi_get_msi_state_resp),
+},
+{
+ .id = RPMI_SYSMSI_SRV_SET_MSI_TARGET,
+ .min_tx_len = sizeof(struct rpmi_sysmsi_set_msi_target_req),
+ .max_tx_len = sizeof(struct rpmi_sysmsi_set_msi_target_req),
+ .min_rx_len = sizeof(struct rpmi_sysmsi_set_msi_target_resp),
+ .max_rx_len = sizeof(struct rpmi_sysmsi_set_msi_target_resp),
+},
+{
+ .id = RPMI_SYSMSI_SRV_GET_MSI_TARGET,
+ .min_tx_len = sizeof(struct rpmi_sysmsi_get_msi_target_req),
+ .max_tx_len = sizeof(struct rpmi_sysmsi_get_msi_target_req),
+ .min_rx_len = sizeof(struct rpmi_sysmsi_get_msi_target_resp),
+ .max_rx_len = sizeof(struct rpmi_sysmsi_get_msi_target_resp),
+},
+};
+
+static const struct mpxy_rpmi_mbox_data sysmsi_data = {
+ .servicegrp_id = RPMI_SRVGRP_SYSTEM_MSI,
+ .num_services = RPMI_SYSMSI_SRV_ID_MAX_COUNT,
+ .service_data = sysmsi_services,
+ .xfer_group = mpxy_rpmi_sysmis_xfer,
+ .setup_group = mpxy_rpmi_sysmsi_setup,
+ .cleanup_group = mpxy_rpmi_sysmsi_cleanup,
+};
+
+static const struct fdt_match sysmsi_match[] = {
+ { .compatible = "riscv,rpmi-mpxy-system-msi", .data = &sysmsi_data },
+ { },
+};
+
+const struct fdt_driver fdt_mpxy_rpmi_sysmsi = {
+ .match_table = sysmsi_match,
+ .init = mpxy_rpmi_mbox_init,
+ .experimental = true,
+};
diff --git a/lib/utils/mpxy/objects.mk b/lib/utils/mpxy/objects.mk
index 1c9afed9..5b6e9bdf 100644
--- a/lib/utils/mpxy/objects.mk
+++ b/lib/utils/mpxy/objects.mk
@@ -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
diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig
index 55607a28..bb260626 100644
--- a/platform/generic/configs/defconfig
+++ b/platform/generic/configs/defconfig
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 13/13] lib: sbi: Update MPXY framework and SBI extension as per latest spec
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
` (11 preceding siblings ...)
2025-01-22 6:44 ` [PATCH v2 12/13] lib: utils: Add MPXY RPMI mailbox driver for System MSI " Anup Patel
@ 2025-01-22 6:44 ` Anup Patel
2025-02-13 5:48 ` [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-01-22 6:44 UTC (permalink / raw)
To: opensbi
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.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
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(-)
diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h
index 0b6b5714..46a813e8 100644
--- a/include/sbi/sbi_ecall_interface.h
+++ b/include/sbi/sbi_ecall_interface.h
@@ -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
diff --git a/include/sbi/sbi_mpxy.h b/include/sbi/sbi_mpxy.h
index e30a17d1..9da2791e 100644
--- a/include/sbi/sbi_mpxy.h
+++ b/include/sbi/sbi_mpxy.h
@@ -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);
diff --git a/lib/sbi/sbi_ecall_mpxy.c b/lib/sbi/sbi_ecall_mpxy.c
index 09705cce..03ac71b2 100644
--- a/lib/sbi/sbi_ecall_mpxy.c
+++ b/lib/sbi/sbi_ecall_mpxy.c
@@ -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;
diff --git a/lib/sbi/sbi_mpxy.c b/lib/sbi/sbi_mpxy.c
index 6a5605ea..c5d9d1bb 100644
--- a/lib/sbi/sbi_mpxy.c
+++ b/lib/sbi/sbi_mpxy.c
@@ -19,6 +19,9 @@
#include <sbi/sbi_console.h>
#include <sbi/sbi_byteorder.h>
+/** Shared memory size across all harts */
+static unsigned long mpxy_shmem_size = PAGE_SIZE;
+
/** Offset of pointer to MPXY state in scratch space */
static unsigned long mpxy_state_offset;
@@ -73,7 +76,6 @@ static SBI_LIST_HEAD(mpxy_channel_list);
/** Per hart shared memory */
struct mpxy_shmem {
- unsigned long shmem_size;
unsigned long shmem_addr_lo;
unsigned long shmem_addr_hi;
};
@@ -90,7 +92,6 @@ struct mpxy_state {
/** Disable hart shared memory */
static inline void sbi_mpxy_shmem_disable(struct mpxy_state *ms)
{
- ms->shmem.shmem_size = 0;
ms->shmem.shmem_addr_lo = INVALID_ADDR;
ms->shmem.shmem_addr_hi = INVALID_ADDR;
}
@@ -227,6 +228,12 @@ int sbi_mpxy_register_channel(struct sbi_mpxy_channel *channel)
/* Initialize channel specific attributes */
mpxy_std_attrs_init(channel);
+ /* Update shared memory size if required */
+ if (mpxy_shmem_size < channel->attrs.msg_data_maxlen) {
+ mpxy_shmem_size = channel->attrs.msg_data_maxlen;
+ mpxy_shmem_size = (mpxy_shmem_size + (PAGE_SIZE - 1)) / PAGE_SIZE;
+ }
+
SBI_INIT_LIST_HEAD(&channel->head);
sbi_list_add_tail(&channel->head, &mpxy_channel_list);
@@ -254,8 +261,14 @@ int sbi_mpxy_init(struct sbi_scratch *scratch)
return sbi_platform_mpxy_init(sbi_platform_ptr(scratch));
}
-int sbi_mpxy_set_shmem(unsigned long shmem_size, unsigned long shmem_phys_lo,
- unsigned long shmem_phys_hi, unsigned long flags)
+unsigned long sbi_mpxy_get_shmem_size(void)
+{
+ return mpxy_shmem_size;
+}
+
+int sbi_mpxy_set_shmem(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);
unsigned long *ret_buf;
@@ -271,13 +284,12 @@ int sbi_mpxy_set_shmem(unsigned long shmem_size, unsigned long shmem_phys_lo,
return SBI_ERR_INVALID_PARAM;
/** Check shared memory size and address aligned to 4K Page */
- if (!shmem_size || (shmem_size & ~PAGE_MASK) ||
- (shmem_phys_lo & ~PAGE_MASK))
+ if (shmem_phys_lo & ~PAGE_MASK)
return SBI_ERR_INVALID_PARAM;
if (!sbi_domain_check_addr_range(sbi_domain_thishart_ptr(),
SHMEM_PHYS_ADDR(shmem_phys_hi, shmem_phys_lo),
- shmem_size, PRV_S,
+ mpxy_shmem_size, PRV_S,
SBI_DOMAIN_READ | SBI_DOMAIN_WRITE))
return SBI_ERR_INVALID_ADDRESS;
@@ -285,15 +297,13 @@ int sbi_mpxy_set_shmem(unsigned long shmem_size, unsigned long shmem_phys_lo,
if (flags == SBI_EXT_MPXY_SHMEM_FLAG_OVERWRITE_RETURN) {
ret_buf = (unsigned long *)(ulong)SHMEM_PHYS_ADDR(shmem_phys_hi,
shmem_phys_lo);
- sbi_hart_map_saddr((unsigned long)ret_buf, shmem_size);
- ret_buf[0] = cpu_to_lle(ms->shmem.shmem_size);
- ret_buf[1] = cpu_to_lle(ms->shmem.shmem_addr_lo);
- ret_buf[2] = cpu_to_lle(ms->shmem.shmem_addr_hi);
+ sbi_hart_map_saddr((unsigned long)ret_buf, mpxy_shmem_size);
+ ret_buf[0] = cpu_to_lle(ms->shmem.shmem_addr_lo);
+ ret_buf[1] = cpu_to_lle(ms->shmem.shmem_addr_hi);
sbi_hart_unmap_saddr();
}
/** Setup the new shared memory */
- ms->shmem.shmem_size = shmem_size;
ms->shmem.shmem_addr_lo = shmem_phys_lo;
ms->shmem.shmem_addr_hi = shmem_phys_hi;
@@ -319,12 +329,11 @@ int sbi_mpxy_get_channel_ids(u32 start_index)
return SBI_ERR_INVALID_PARAM;
shmem_base = hart_shmem_base(ms);
- sbi_hart_map_saddr((unsigned long)hart_shmem_base(ms),
- ms->shmem.shmem_size);
+ sbi_hart_map_saddr((unsigned long)hart_shmem_base(ms), mpxy_shmem_size);
/** number of channel ids which can be stored in shmem adjusting
* for remaining and returned fields */
- max_channelids = (ms->shmem.shmem_size / sizeof(u32)) - 2;
+ max_channelids = (mpxy_shmem_size / sizeof(u32)) - 2;
/* total remaining from the start index */
remaining = channels_count - start_index;
/* how many can be returned */
@@ -372,14 +381,13 @@ int sbi_mpxy_read_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count)
return SBI_ERR_INVALID_PARAM;
/* Sanity check for base_attr_id and attr_count */
- if (!attr_count || (attr_count > (ms->shmem.shmem_size / ATTR_SIZE)))
+ if (!attr_count || (attr_count > (mpxy_shmem_size / ATTR_SIZE)))
return SBI_ERR_INVALID_PARAM;
shmem_base = hart_shmem_base(ms);
end_id = base_attr_id + attr_count - 1;
- sbi_hart_map_saddr((unsigned long)hart_shmem_base(ms),
- ms->shmem.shmem_size);
+ sbi_hart_map_saddr((unsigned long)hart_shmem_base(ms), mpxy_shmem_size);
/* Standard attributes range check */
if (mpxy_is_std_attr(base_attr_id)) {
@@ -524,13 +532,13 @@ int sbi_mpxy_write_attrs(u32 channel_id, u32 base_attr_id, u32 attr_count)
return SBI_ERR_INVALID_PARAM;
/* Sanity check for base_attr_id and attr_count */
- if (!attr_count || (attr_count > (ms->shmem.shmem_size / ATTR_SIZE)))
+ if (!attr_count || (attr_count > (mpxy_shmem_size / ATTR_SIZE)))
return SBI_ERR_INVALID_PARAM;
shmem_base = hart_shmem_base(ms);
end_id = base_attr_id + attr_count - 1;
- sbi_hart_map_saddr((unsigned long)shmem_base, ms->shmem.shmem_size);
+ sbi_hart_map_saddr((unsigned long)shmem_base, mpxy_shmem_size);
mem_ptr = (u32 *)shmem_base;
@@ -614,16 +622,16 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,
if (!resp_data_len && !channel->send_message_without_response)
return SBI_ERR_NOT_SUPPORTED;
- if (msg_data_len > ms->shmem.shmem_size ||
+ if (msg_data_len > mpxy_shmem_size ||
msg_data_len > channel->attrs.msg_data_maxlen)
return SBI_ERR_INVALID_PARAM;
shmem_base = hart_shmem_base(ms);
- sbi_hart_map_saddr((unsigned long)shmem_base, ms->shmem.shmem_size);
+ sbi_hart_map_saddr((unsigned long)shmem_base, mpxy_shmem_size);
if (resp_data_len) {
resp_buf = shmem_base;
- resp_bufsize = ms->shmem.shmem_size;
+ resp_bufsize = mpxy_shmem_size;
ret = channel->send_message_with_response(channel, msg_id,
shmem_base,
msg_data_len,
@@ -644,7 +652,7 @@ int sbi_mpxy_send_message(u32 channel_id, u8 msg_id,
return SBI_ERR_FAILED;
if (resp_data_len &&
- (*resp_data_len > ms->shmem.shmem_size ||
+ (*resp_data_len > mpxy_shmem_size ||
*resp_data_len > channel->attrs.msg_data_maxlen))
return SBI_ERR_FAILED;
@@ -666,17 +674,17 @@ int sbi_mpxy_get_notification_events(u32 channel_id, unsigned long *events_len)
return SBI_ERR_NOT_SUPPORTED;
shmem_base = hart_shmem_base(ms);
- sbi_hart_map_saddr((unsigned long)shmem_base, ms->shmem.shmem_size);
+ sbi_hart_map_saddr((unsigned long)shmem_base, mpxy_shmem_size);
eventsbuf = shmem_base;
ret = channel->get_notification_events(channel, eventsbuf,
- ms->shmem.shmem_size,
+ mpxy_shmem_size,
events_len);
sbi_hart_unmap_saddr();
if (ret)
return ret;
- if (*events_len > ms->shmem.shmem_size)
+ if (*events_len > (mpxy_shmem_size - 16))
return SBI_ERR_FAILED;
return SBI_SUCCESS;
--
2.43.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v2 00/13] More RPMI and MPXY updates
2025-01-22 6:44 [PATCH v2 00/13] More RPMI and MPXY updates Anup Patel
` (12 preceding siblings ...)
2025-01-22 6:44 ` [PATCH v2 13/13] lib: sbi: Update MPXY framework and SBI extension as per latest spec Anup Patel
@ 2025-02-13 5:48 ` Anup Patel
13 siblings, 0 replies; 15+ messages in thread
From: Anup Patel @ 2025-02-13 5:48 UTC (permalink / raw)
To: opensbi
On Wed, Jan 22, 2025 at 12:14?PM Anup Patel <apatel@ventanamicro.com> 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
> 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
>
> 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
>
^ permalink raw reply [flat|nested] 15+ messages in thread