* [PATCH 00/12] More RPMI and MPXY updates
@ 2025-01-16 15:56 Anup Patel
2025-01-16 15:56 ` [PATCH 01/12] lib: utils: Split the FDT MPXY RPMI mailbox client into two parts Anup Patel
` (11 more replies)
0 siblings, 12 replies; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 UTC (permalink / raw)
To: opensbi
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_v1 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.
Anup Patel (12):
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
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 | 84 ++++++
lib/sbi/sbi_mpxy.c | 77 ++---
lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c | 39 ++-
lib/utils/mpxy/Kconfig | 16 +-
lib/utils/mpxy/fdt_mpxy_rpmi_clock.c | 91 ++++++
lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 312 +++++++-------------
lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c | 208 +++++++++++++
lib/utils/mpxy/objects.mk | 7 +-
platform/generic/configs/defconfig | 2 +
11 files changed, 684 insertions(+), 270 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] 28+ messages in thread
* [PATCH 01/12] lib: utils: Split the FDT MPXY RPMI mailbox client into two parts
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-19 22:52 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 02/12] lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox Anup Patel
` (10 subsequent siblings)
11 siblings, 1 reply; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 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 | 70 ++++++++
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, 190 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..e4ca0151
--- /dev/null
+++ b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
@@ -0,0 +1,70 @@
+/*
+ * 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);
+
+/** 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..1f5c6e75
--- /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 },
+ { },
+};
+
+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] 28+ messages in thread
* [PATCH 02/12] lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
2025-01-16 15:56 ` [PATCH 01/12] lib: utils: Split the FDT MPXY RPMI mailbox client into two parts Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-19 22:54 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 03/12] lib: utils: Introduce optional MPXY RPMI service group operations Anup Patel
` (9 subsequent siblings)
11 siblings, 1 reply; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 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>
---
lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
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] 28+ messages in thread
* [PATCH 03/12] lib: utils: Introduce optional MPXY RPMI service group operations
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
2025-01-16 15:56 ` [PATCH 01/12] lib: utils: Split the FDT MPXY RPMI mailbox client into two parts Anup Patel
2025-01-16 15:56 ` [PATCH 02/12] lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-19 22:58 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 04/12] lib: sbi: Fix capability bit assignment in MPXY framework Anup Patel
` (8 subsequent siblings)
11 siblings, 1 reply; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 UTC (permalink / raw)
To: opensbi
Some of the RPMI service groups may additional contex and special
handling when transfering message to 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 | 18 ++++++++++++++++
lib/utils/mpxy/fdt_mpxy_rpmi_clock.c | 4 ++++
lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 24 +++++++++++++++++----
3 files changed, 42 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 e4ca0151..08b32a0a 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>
@@ -56,12 +57,29 @@ struct mpxy_rpmi_service_data {
u32 max_rx_len;
};
+struct mpxy_rpmi_mbox_data;
+
+/** MPXY RPMI service group operations */
+struct mpxy_rpmi_service_group_ops {
+ /** 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);
+};
+
/** 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;
+ struct mpxy_rpmi_service_group_ops *group_ops;
};
/** Common probe function for MPXY RPMI drivers */
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
index 1f5c6e75..3d275cd8 100644
--- a/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
@@ -10,6 +10,9 @@
#include <sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h>
+static struct mpxy_rpmi_service_group_ops clock_ops = {
+};
+
static struct mpxy_rpmi_service_data clock_services[] = {
{
.id = RPMI_CLOCK_SRV_ENABLE_NOTIFICATION,
@@ -74,6 +77,7 @@ static struct mpxy_rpmi_mbox_data clock_data = {
.num_services = RPMI_CLOCK_SRV_MAX_COUNT,
.notifications_support = 1,
.service_data = clock_services,
+ .group_ops = &clock_ops,
};
static const struct fdt_match clock_match[] = {
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
index 7034fb9e..8d892cef 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->group_ops->xfer_group)
+ ret = data->group_ops->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->group_ops->setup_group) {
+ rc = data->group_ops->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->group_ops->cleanup_group)
+ data->group_ops->cleanup_group(rmb->group_context);
mbox_controller_free_chan(chan);
sbi_free(rmb);
return rc;
--
2.43.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 04/12] lib: sbi: Fix capability bit assignment in MPXY framework
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
` (2 preceding siblings ...)
2025-01-16 15:56 ` [PATCH 03/12] lib: utils: Introduce optional MPXY RPMI service group operations Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-19 23:00 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 05/12] lib: sbi: Improve local variable declarations " Anup Patel
` (7 subsequent siblings)
11 siblings, 1 reply; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 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>
---
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] 28+ messages in thread
* [PATCH 05/12] lib: sbi: Improve local variable declarations in MPXY framework
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
` (3 preceding siblings ...)
2025-01-16 15:56 ` [PATCH 04/12] lib: sbi: Fix capability bit assignment in MPXY framework Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-19 23:02 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 06/12] lib: utils: Drop notifications from MPXY RPMI mailbox client Anup Patel
` (6 subsequent siblings)
11 siblings, 1 reply; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 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>
---
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] 28+ messages in thread
* [PATCH 06/12] lib: utils: Drop notifications from MPXY RPMI mailbox client
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
` (4 preceding siblings ...)
2025-01-16 15:56 ` [PATCH 05/12] lib: sbi: Improve local variable declarations " Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-19 23:02 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 07/12] lib: utils: Improve variable declarations in " Anup Patel
` (5 subsequent siblings)
11 siblings, 1 reply; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 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>
---
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 | 10 ----------
3 files changed, 12 deletions(-)
diff --git a/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
index 08b32a0a..53a8d8bd 100644
--- a/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
+++ b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
@@ -77,7 +77,6 @@ struct mpxy_rpmi_service_group_ops {
struct mpxy_rpmi_mbox_data {
u32 servicegrp_id;
u32 num_services;
- u32 notifications_support;
struct mpxy_rpmi_service_data *service_data;
struct mpxy_rpmi_service_group_ops *group_ops;
};
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
index 3d275cd8..125539ac 100644
--- a/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
@@ -75,7 +75,6 @@ static struct mpxy_rpmi_service_data clock_services[] = {
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,
.group_ops = &clock_ops,
};
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
index 8d892cef..26b9e6a6 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,9 +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;
--
2.43.0
^ permalink raw reply related [flat|nested] 28+ messages in thread
* [PATCH 07/12] lib: utils: Improve variable declarations in MPXY RPMI mailbox client
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
` (5 preceding siblings ...)
2025-01-16 15:56 ` [PATCH 06/12] lib: utils: Drop notifications from MPXY RPMI mailbox client Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-19 23:05 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 08/12] include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header Anup Patel
` (4 subsequent siblings)
11 siblings, 1 reply; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 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>
---
lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 31 ++++++++++++-----------------
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
index 26b9e6a6..27f4c571 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));
@@ -270,8 +267,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;
- /* 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] 28+ messages in thread
* [PATCH 08/12] include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
` (6 preceding siblings ...)
2025-01-16 15:56 ` [PATCH 07/12] lib: utils: Improve variable declarations in " Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-19 23:05 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 09/12] lib: utils: Implement get_attribute() for the RPMI shared memory mailbox Anup Patel
` (3 subsequent siblings)
11 siblings, 1 reply; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 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>
---
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] 28+ messages in thread
* [PATCH 09/12] lib: utils: Implement get_attribute() for the RPMI shared memory mailbox
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
` (7 preceding siblings ...)
2025-01-16 15:56 ` [PATCH 08/12] include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-16 15:56 ` [PATCH 10/12] lib: utils: Populate MPXY channel attributes from RPMI channel attributes Anup Patel
` (2 subsequent siblings)
11 siblings, 0 replies; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 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] 28+ messages in thread
* [PATCH 10/12] lib: utils: Populate MPXY channel attributes from RPMI channel attributes
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
` (8 preceding siblings ...)
2025-01-16 15:56 ` [PATCH 09/12] lib: utils: Implement get_attribute() for the RPMI shared memory mailbox Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-16 15:56 ` [PATCH 11/12] include: sbi_utils: Update RPMI service group IDs and BASE service group Anup Patel
2025-01-16 15:56 ` [PATCH 12/12] lib: utils: Add MPXY RPMI mailbox driver for System MSI " Anup Patel
11 siblings, 0 replies; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 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 53a8d8bd..ed41d0ac 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 27f4c571..8378070b 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->group_ops->setup_group) {
rc = data->group_ops->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->group_ops->cleanup_group)
data->group_ops->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] 28+ messages in thread
* [PATCH 11/12] include: sbi_utils: Update RPMI service group IDs and BASE service group
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
` (9 preceding siblings ...)
2025-01-16 15:56 ` [PATCH 10/12] lib: utils: Populate MPXY channel attributes from RPMI channel attributes Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-19 23:07 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 12/12] lib: utils: Add MPXY RPMI mailbox driver for System MSI " Anup Patel
11 siblings, 1 reply; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 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>
---
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] 28+ messages in thread
* [PATCH 12/12] lib: utils: Add MPXY RPMI mailbox driver for System MSI service group
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
` (10 preceding siblings ...)
2025-01-16 15:56 ` [PATCH 11/12] include: sbi_utils: Update RPMI service group IDs and BASE service group Anup Patel
@ 2025-01-16 15:56 ` Anup Patel
2025-01-19 23:11 ` Samuel Holland
11 siblings, 1 reply; 28+ messages in thread
From: Anup Patel @ 2025-01-16 15:56 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 | 208 +++++++++++++++++++++++
lib/utils/mpxy/objects.mk | 3 +
platform/generic/configs/defconfig | 1 +
5 files changed, 304 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..3dacf28f
--- /dev/null
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c
@@ -0,0 +1,208 @@
+/*
+ * 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_group_ops sysmsi_ops = {
+ .xfer_group = mpxy_rpmi_sysmis_xfer,
+ .setup_group = mpxy_rpmi_sysmsi_setup,
+ .cleanup_group = mpxy_rpmi_sysmsi_cleanup,
+};
+
+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 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,
+ .group_ops = &sysmsi_ops,
+};
+
+static const struct fdt_match sysmsi_match[] = {
+ { .compatible = "riscv,rpmi-mpxy-system-msi", .data = &sysmsi_data },
+ { },
+};
+
+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] 28+ messages in thread
* [PATCH 01/12] lib: utils: Split the FDT MPXY RPMI mailbox client into two parts
2025-01-16 15:56 ` [PATCH 01/12] lib: utils: Split the FDT MPXY RPMI mailbox client into two parts Anup Patel
@ 2025-01-19 22:52 ` Samuel Holland
2025-01-20 4:49 ` Anup Patel
0 siblings, 1 reply; 28+ messages in thread
From: Samuel Holland @ 2025-01-19 22:52 UTC (permalink / raw)
To: opensbi
Hi Anup,
A couple of comments on existing issues in the code. Maybe it makes sense to fix
them in this series to avoid conflicts?
On 2025-01-16 9:56 AM, Anup Patel wrote:
> 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 | 70 ++++++++
> 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, 190 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..e4ca0151
> --- /dev/null
> +++ b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
> @@ -0,0 +1,70 @@
> +/*
> + * 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);
Missing assertion for servicegrp_ver?
> +
> +/** 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..1f5c6e75
> --- /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 },
> + { },
> +};
> +
> +struct fdt_driver fdt_mpxy_rpmi_clock = {
This structure is required to be `const` both by the carray and the declaration
of fdt_mpxy_drivers.
Regards,
Samuel
> + .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
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 02/12] lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox
2025-01-16 15:56 ` [PATCH 02/12] lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox Anup Patel
@ 2025-01-19 22:54 ` Samuel Holland
2025-01-20 5:12 ` Anup Patel
0 siblings, 1 reply; 28+ messages in thread
From: Samuel Holland @ 2025-01-19 22:54 UTC (permalink / raw)
To: opensbi
On 2025-01-16 9:56 AM, Anup Patel wrote:
> 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>
> ---
> lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> 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 */
The underlying object (e.g. `clock_data`) can also be const now.
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 03/12] lib: utils: Introduce optional MPXY RPMI service group operations
2025-01-16 15:56 ` [PATCH 03/12] lib: utils: Introduce optional MPXY RPMI service group operations Anup Patel
@ 2025-01-19 22:58 ` Samuel Holland
2025-01-20 8:05 ` Anup Patel
0 siblings, 1 reply; 28+ messages in thread
From: Samuel Holland @ 2025-01-19 22:58 UTC (permalink / raw)
To: opensbi
Hi Anup,
On 2025-01-16 9:56 AM, Anup Patel wrote:
> Some of the RPMI service groups may additional contex and special
> handling when transfering message to underlying mailbox channel
typos: context, transferring
> 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 | 18 ++++++++++++++++
> lib/utils/mpxy/fdt_mpxy_rpmi_clock.c | 4 ++++
> lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 24 +++++++++++++++++----
> 3 files changed, 42 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 e4ca0151..08b32a0a 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>
>
> @@ -56,12 +57,29 @@ struct mpxy_rpmi_service_data {
> u32 max_rx_len;
> };
>
> +struct mpxy_rpmi_mbox_data;
> +
> +/** MPXY RPMI service group operations */
> +struct mpxy_rpmi_service_group_ops {
> + /** 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);
> +};
> +
> /** 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;
> + struct mpxy_rpmi_service_group_ops *group_ops;
Do you expect several service groups to share a mpxy_rpmi_service_group_ops? If
not, I would suggest to reduce pointer chasing by putting the function pointers
directly in mpxy_rpmi_mbox_data.
If you do keep it as a pointer, it should be a pointer to const.
Regards,
Samuel
> };
>
> /** Common probe function for MPXY RPMI drivers */
> diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
> index 1f5c6e75..3d275cd8 100644
> --- a/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
> +++ b/lib/utils/mpxy/fdt_mpxy_rpmi_clock.c
> @@ -10,6 +10,9 @@
>
> #include <sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h>
>
> +static struct mpxy_rpmi_service_group_ops clock_ops = {
> +};
> +
> static struct mpxy_rpmi_service_data clock_services[] = {
> {
> .id = RPMI_CLOCK_SRV_ENABLE_NOTIFICATION,
> @@ -74,6 +77,7 @@ static struct mpxy_rpmi_mbox_data clock_data = {
> .num_services = RPMI_CLOCK_SRV_MAX_COUNT,
> .notifications_support = 1,
> .service_data = clock_services,
> + .group_ops = &clock_ops,
> };
>
> static const struct fdt_match clock_match[] = {
> diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
> index 7034fb9e..8d892cef 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->group_ops->xfer_group)
> + ret = data->group_ops->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->group_ops->setup_group) {
> + rc = data->group_ops->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->group_ops->cleanup_group)
> + data->group_ops->cleanup_group(rmb->group_context);
> mbox_controller_free_chan(chan);
> sbi_free(rmb);
> return rc;
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 04/12] lib: sbi: Fix capability bit assignment in MPXY framework
2025-01-16 15:56 ` [PATCH 04/12] lib: sbi: Fix capability bit assignment in MPXY framework Anup Patel
@ 2025-01-19 23:00 ` Samuel Holland
0 siblings, 0 replies; 28+ messages in thread
From: Samuel Holland @ 2025-01-19 23:00 UTC (permalink / raw)
To: opensbi
On 2025-01-16 9:56 AM, Anup Patel wrote:
> 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>
> ---
> lib/sbi/sbi_mpxy.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 05/12] lib: sbi: Improve local variable declarations in MPXY framework
2025-01-16 15:56 ` [PATCH 05/12] lib: sbi: Improve local variable declarations " Anup Patel
@ 2025-01-19 23:02 ` Samuel Holland
0 siblings, 0 replies; 28+ messages in thread
From: Samuel Holland @ 2025-01-19 23:02 UTC (permalink / raw)
To: opensbi
On 2025-01-16 9:56 AM, Anup Patel wrote:
> 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>
> ---
> lib/sbi/sbi_mpxy.c | 65 ++++++++++++++++++----------------------------
> 1 file changed, 25 insertions(+), 40 deletions(-)
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 06/12] lib: utils: Drop notifications from MPXY RPMI mailbox client
2025-01-16 15:56 ` [PATCH 06/12] lib: utils: Drop notifications from MPXY RPMI mailbox client Anup Patel
@ 2025-01-19 23:02 ` Samuel Holland
0 siblings, 0 replies; 28+ messages in thread
From: Samuel Holland @ 2025-01-19 23:02 UTC (permalink / raw)
To: opensbi
On 2025-01-16 9:56 AM, Anup Patel wrote:
> 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>
> ---
> 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 | 10 ----------
> 3 files changed, 12 deletions(-)
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 07/12] lib: utils: Improve variable declarations in MPXY RPMI mailbox client
2025-01-16 15:56 ` [PATCH 07/12] lib: utils: Improve variable declarations in " Anup Patel
@ 2025-01-19 23:05 ` Samuel Holland
2025-01-20 8:37 ` Anup Patel
0 siblings, 1 reply; 28+ messages in thread
From: Samuel Holland @ 2025-01-19 23:05 UTC (permalink / raw)
To: opensbi
On 2025-01-16 9:56 AM, Anup Patel wrote:
> 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>
> ---
> lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 31 ++++++++++++-----------------
> 1 file changed, 13 insertions(+), 18 deletions(-)
>
> diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
> index 26b9e6a6..27f4c571 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));
> @@ -270,8 +267,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;
> - /* No callback to switch events state data */
> - rmb->channel.switch_eventsstate = NULL;
Does this belong as part of the previous patch? Either way:
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
>
> /* RPMI Message Protocol ID */
> rmb->channel.attrs.msg_proto_id = SBI_MPXY_MSGPROTO_RPMI_ID;
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 08/12] include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header
2025-01-16 15:56 ` [PATCH 08/12] include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header Anup Patel
@ 2025-01-19 23:05 ` Samuel Holland
0 siblings, 0 replies; 28+ messages in thread
From: Samuel Holland @ 2025-01-19 23:05 UTC (permalink / raw)
To: opensbi
On 2025-01-16 9:56 AM, Anup Patel wrote:
> 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>
> ---
> include/sbi_utils/mailbox/rpmi_mailbox.h | 1 +
> 1 file changed, 1 insertion(+)
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 11/12] include: sbi_utils: Update RPMI service group IDs and BASE service group
2025-01-16 15:56 ` [PATCH 11/12] include: sbi_utils: Update RPMI service group IDs and BASE service group Anup Patel
@ 2025-01-19 23:07 ` Samuel Holland
0 siblings, 0 replies; 28+ messages in thread
From: Samuel Holland @ 2025-01-19 23:07 UTC (permalink / raw)
To: opensbi
On 2025-01-16 9:56 AM, Anup Patel wrote:
> 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>
> ---
> include/sbi_utils/mailbox/rpmi_msgprot.h | 16 +++++++---------
> lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c | 4 ----
> 2 files changed, 7 insertions(+), 13 deletions(-)
Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 12/12] lib: utils: Add MPXY RPMI mailbox driver for System MSI service group
2025-01-16 15:56 ` [PATCH 12/12] lib: utils: Add MPXY RPMI mailbox driver for System MSI " Anup Patel
@ 2025-01-19 23:11 ` Samuel Holland
2025-01-20 9:16 ` Anup Patel
0 siblings, 1 reply; 28+ messages in thread
From: Samuel Holland @ 2025-01-19 23:11 UTC (permalink / raw)
To: opensbi
Hi Anup,
On 2025-01-16 9:56 AM, Anup Patel wrote:
> 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 | 208 +++++++++++++++++++++++
> lib/utils/mpxy/objects.mk | 3 +
> platform/generic/configs/defconfig | 1 +
> 5 files changed, 304 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..3dacf28f
> --- /dev/null
> +++ b/lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c
> @@ -0,0 +1,208 @@
> +/*
> + * 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);
> + }
> +
Is my understanding correct that this function will eventually contain code to
wire up the P2A doorbell to M-mode for notification support?
> + *context = smg;
> + return 0;
> +}
> +
> +static struct mpxy_rpmi_service_group_ops sysmsi_ops = {
> + .xfer_group = mpxy_rpmi_sysmis_xfer,
> + .setup_group = mpxy_rpmi_sysmsi_setup,
> + .cleanup_group = mpxy_rpmi_sysmsi_cleanup,
> +};
> +
> +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 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,
> + .group_ops = &sysmsi_ops,
> +};
> +
> +static const struct fdt_match sysmsi_match[] = {
> + { .compatible = "riscv,rpmi-mpxy-system-msi", .data = &sysmsi_data },
> + { },
> +};
> +
> +struct fdt_driver fdt_mpxy_rpmi_sysmsi = {
> + .match_table = sysmsi_match,
> + .init = mpxy_rpmi_mbox_init,
> + .experimental = true,
> +};
All of these object definitions should be `const`.
Regards,
Samuel
> 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
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 01/12] lib: utils: Split the FDT MPXY RPMI mailbox client into two parts
2025-01-19 22:52 ` Samuel Holland
@ 2025-01-20 4:49 ` Anup Patel
0 siblings, 0 replies; 28+ messages in thread
From: Anup Patel @ 2025-01-20 4:49 UTC (permalink / raw)
To: opensbi
On Mon, Jan 20, 2025 at 4:22?AM Samuel Holland
<samuel.holland@sifive.com> wrote:
>
> Hi Anup,
>
> A couple of comments on existing issues in the code. Maybe it makes sense to fix
> them in this series to avoid conflicts?
>
> On 2025-01-16 9:56 AM, Anup Patel wrote:
> > 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 | 70 ++++++++
> > 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, 190 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..e4ca0151
> > --- /dev/null
> > +++ b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
> > @@ -0,0 +1,70 @@
> > +/*
> > + * 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);
>
> Missing assertion for servicegrp_ver?
Okay, I will add the missing assertion.
>
> > +
> > +/** 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..1f5c6e75
> > --- /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 },
> > + { },
> > +};
> > +
> > +struct fdt_driver fdt_mpxy_rpmi_clock = {
>
> This structure is required to be `const` both by the carray and the declaration
> of fdt_mpxy_drivers.
Okay, I will update.
Regards,
Anup
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 02/12] lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox
2025-01-19 22:54 ` Samuel Holland
@ 2025-01-20 5:12 ` Anup Patel
0 siblings, 0 replies; 28+ messages in thread
From: Anup Patel @ 2025-01-20 5:12 UTC (permalink / raw)
To: opensbi
On Mon, Jan 20, 2025 at 4:24?AM Samuel Holland
<samuel.holland@sifive.com> wrote:
>
> On 2025-01-16 9:56 AM, Anup Patel wrote:
> > 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>
> > ---
> > lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 15 ++++++++-------
> > 1 file changed, 8 insertions(+), 7 deletions(-)
> >
> > 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 */
>
> The underlying object (e.g. `clock_data`) can also be const now.
Okay, I will update.
>
> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
>
Regards,
Anup
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 03/12] lib: utils: Introduce optional MPXY RPMI service group operations
2025-01-19 22:58 ` Samuel Holland
@ 2025-01-20 8:05 ` Anup Patel
0 siblings, 0 replies; 28+ messages in thread
From: Anup Patel @ 2025-01-20 8:05 UTC (permalink / raw)
To: opensbi
On Mon, Jan 20, 2025 at 4:28?AM Samuel Holland
<samuel.holland@sifive.com> wrote:
>
> Hi Anup,
>
> On 2025-01-16 9:56 AM, Anup Patel wrote:
> > Some of the RPMI service groups may additional contex and special
> > handling when transfering message to underlying mailbox channel
>
> typos: context, transferring
Okay, I will update.
>
> > 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 | 18 ++++++++++++++++
> > lib/utils/mpxy/fdt_mpxy_rpmi_clock.c | 4 ++++
> > lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 24 +++++++++++++++++----
> > 3 files changed, 42 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 e4ca0151..08b32a0a 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>
> >
> > @@ -56,12 +57,29 @@ struct mpxy_rpmi_service_data {
> > u32 max_rx_len;
> > };
> >
> > +struct mpxy_rpmi_mbox_data;
> > +
> > +/** MPXY RPMI service group operations */
> > +struct mpxy_rpmi_service_group_ops {
> > + /** 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);
> > +};
> > +
> > /** 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;
> > + struct mpxy_rpmi_service_group_ops *group_ops;
>
> Do you expect several service groups to share a mpxy_rpmi_service_group_ops? If
> not, I would suggest to reduce pointer chasing by putting the function pointers
> directly in mpxy_rpmi_mbox_data.
>
> If you do keep it as a pointer, it should be a pointer to const.
As of now, I don't envision MPXY RPMI service group drivers
sharing operations so I will put function pointers directly in
struct mpxy_rpmi_mbox_data.
Regards,
Anup
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 07/12] lib: utils: Improve variable declarations in MPXY RPMI mailbox client
2025-01-19 23:05 ` Samuel Holland
@ 2025-01-20 8:37 ` Anup Patel
0 siblings, 0 replies; 28+ messages in thread
From: Anup Patel @ 2025-01-20 8:37 UTC (permalink / raw)
To: opensbi
On Mon, Jan 20, 2025 at 4:35?AM Samuel Holland
<samuel.holland@sifive.com> wrote:
>
> On 2025-01-16 9:56 AM, Anup Patel wrote:
> > 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>
> > ---
> > lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c | 31 ++++++++++++-----------------
> > 1 file changed, 13 insertions(+), 18 deletions(-)
> >
> > diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
> > index 26b9e6a6..27f4c571 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));
> > @@ -270,8 +267,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;
> > - /* No callback to switch events state data */
> > - rmb->channel.switch_eventsstate = NULL;
>
> Does this belong as part of the previous patch? Either way:
Yes, this change should be part of the previous patch. I will update.
>
> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
>
> >
> > /* RPMI Message Protocol ID */
> > rmb->channel.attrs.msg_proto_id = SBI_MPXY_MSGPROTO_RPMI_ID;
>
Regards,
Anup
^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 12/12] lib: utils: Add MPXY RPMI mailbox driver for System MSI service group
2025-01-19 23:11 ` Samuel Holland
@ 2025-01-20 9:16 ` Anup Patel
0 siblings, 0 replies; 28+ messages in thread
From: Anup Patel @ 2025-01-20 9:16 UTC (permalink / raw)
To: opensbi
On Mon, Jan 20, 2025 at 4:41?AM Samuel Holland
<samuel.holland@sifive.com> wrote:
>
> Hi Anup,
>
> On 2025-01-16 9:56 AM, Anup Patel wrote:
> > 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 | 208 +++++++++++++++++++++++
> > lib/utils/mpxy/objects.mk | 3 +
> > platform/generic/configs/defconfig | 1 +
> > 5 files changed, 304 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..3dacf28f
> > --- /dev/null
> > +++ b/lib/utils/mpxy/fdt_mpxy_rpmi_sysmsi.c
> > @@ -0,0 +1,208 @@
> > +/*
> > + * 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);
> > + }
> > +
>
> Is my understanding correct that this function will eventually contain code to
> wire up the P2A doorbell to M-mode for notification support?
This driver will only block supervisor access to the P2A doorbell system
MSI whereas the RPMI shared memory mailbox driver will detect and
configure P2A doorbell system MSI.
This means two OpenSBI drivers (this driver and RPMI shared memory
mailbox driver) will share the RPMI System MSI mailbox channel.
>
> > + *context = smg;
> > + return 0;
> > +}
> > +
> > +static struct mpxy_rpmi_service_group_ops sysmsi_ops = {
> > + .xfer_group = mpxy_rpmi_sysmis_xfer,
> > + .setup_group = mpxy_rpmi_sysmsi_setup,
> > + .cleanup_group = mpxy_rpmi_sysmsi_cleanup,
> > +};
> > +
> > +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 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,
> > + .group_ops = &sysmsi_ops,
> > +};
> > +
> > +static const struct fdt_match sysmsi_match[] = {
> > + { .compatible = "riscv,rpmi-mpxy-system-msi", .data = &sysmsi_data },
> > + { },
> > +};
> > +
> > +struct fdt_driver fdt_mpxy_rpmi_sysmsi = {
> > + .match_table = sysmsi_match,
> > + .init = mpxy_rpmi_mbox_init,
> > + .experimental = true,
> > +};
>
> All of these object definitions should be `const`.
Okay, I will update.
Regards,
Anup
^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2025-01-20 9:16 UTC | newest]
Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-16 15:56 [PATCH 00/12] More RPMI and MPXY updates Anup Patel
2025-01-16 15:56 ` [PATCH 01/12] lib: utils: Split the FDT MPXY RPMI mailbox client into two parts Anup Patel
2025-01-19 22:52 ` Samuel Holland
2025-01-20 4:49 ` Anup Patel
2025-01-16 15:56 ` [PATCH 02/12] lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox Anup Patel
2025-01-19 22:54 ` Samuel Holland
2025-01-20 5:12 ` Anup Patel
2025-01-16 15:56 ` [PATCH 03/12] lib: utils: Introduce optional MPXY RPMI service group operations Anup Patel
2025-01-19 22:58 ` Samuel Holland
2025-01-20 8:05 ` Anup Patel
2025-01-16 15:56 ` [PATCH 04/12] lib: sbi: Fix capability bit assignment in MPXY framework Anup Patel
2025-01-19 23:00 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 05/12] lib: sbi: Improve local variable declarations " Anup Patel
2025-01-19 23:02 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 06/12] lib: utils: Drop notifications from MPXY RPMI mailbox client Anup Patel
2025-01-19 23:02 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 07/12] lib: utils: Improve variable declarations in " Anup Patel
2025-01-19 23:05 ` Samuel Holland
2025-01-20 8:37 ` Anup Patel
2025-01-16 15:56 ` [PATCH 08/12] include: sbi_utils: Include mailbox.h in rpmi_mailbox.h header Anup Patel
2025-01-19 23:05 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 09/12] lib: utils: Implement get_attribute() for the RPMI shared memory mailbox Anup Patel
2025-01-16 15:56 ` [PATCH 10/12] lib: utils: Populate MPXY channel attributes from RPMI channel attributes Anup Patel
2025-01-16 15:56 ` [PATCH 11/12] include: sbi_utils: Update RPMI service group IDs and BASE service group Anup Patel
2025-01-19 23:07 ` Samuel Holland
2025-01-16 15:56 ` [PATCH 12/12] lib: utils: Add MPXY RPMI mailbox driver for System MSI " Anup Patel
2025-01-19 23:11 ` Samuel Holland
2025-01-20 9:16 ` Anup Patel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox