[PATCH 2/5] lib: utils/mpxy: Split RPMI message protocol attributes out of the mailbox header

marouene.boubakri at oss.nxp.com marouene.boubakri at oss.nxp.com
Mon Sep 7 04:59:10 PDT 2026


From: Marouene Boubakri <marouene.boubakri at nxp.com>

The RPMI message protocol attributes of an MPXY channel and the helper
reading them have nothing to do with the RPMI mailbox client. Move them
to their own header and source file so that an MPXY channel driver which
is not backed by an RPMI mailbox does not have to include the mailbox
headers to describe its channel.

No functional change.

Signed-off-by: Marouene Boubakri <marouene.boubakri at nxp.com>
---
 include/sbi_utils/mpxy/fdt_mpxy_rpmi.h      | 64 +++++++++++++++++++++
 include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h | 37 +-----------
 lib/utils/mpxy/fdt_mpxy_rpmi.c              | 29 ++++++++++
 lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c         | 19 +-----
 lib/utils/mpxy/objects.mk                   |  1 +
 5 files changed, 97 insertions(+), 53 deletions(-)
 create mode 100644 include/sbi_utils/mpxy/fdt_mpxy_rpmi.h
 create mode 100644 lib/utils/mpxy/fdt_mpxy_rpmi.c

diff --git a/include/sbi_utils/mpxy/fdt_mpxy_rpmi.h b/include/sbi_utils/mpxy/fdt_mpxy_rpmi.h
new file mode 100644
index 0000000..747936f
--- /dev/null
+++ b/include/sbi_utils/mpxy/fdt_mpxy_rpmi.h
@@ -0,0 +1,64 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <apatel at ventanamicro.com>
+ */
+
+#ifndef __FDT_MPXY_RPMI_H__
+#define __FDT_MPXY_RPMI_H__
+
+#include <sbi/sbi_mpxy.h>
+#include <sbi/sbi_types.h>
+
+/** 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_IMPL_ID,
+	MPXY_MSGPROT_RPMI_ATTR_IMPL_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;
+	u32 impl_id;
+	u32 impl_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_id2index(attr_offset),	\
+		       "field " #field " of struct "			\
+		       "mpxy_rpmi_channel_attrs is not at " #attr_offset)
+
+assert_field_offset(servicegrp_id, MPXY_MSGPROT_RPMI_ATTR_SERVICEGROUP_ID);
+assert_field_offset(servicegrp_ver, MPXY_MSGPROT_RPMI_ATTR_SERVICEGROUP_VERSION);
+assert_field_offset(impl_id, MPXY_MSGPROT_RPMI_ATTR_IMPL_ID);
+assert_field_offset(impl_ver, MPXY_MSGPROT_RPMI_ATTR_IMPL_VERSION);
+
+/**
+ * Read RPMI message protocol attributes of an MPXY channel
+ *
+ * @param attrs RPMI message protocol attributes of the channel
+ * @param outmem little-endian output memory
+ * @param base_attr_id first attribute ID to read
+ * @param attr_count number of attributes to read
+ *
+ * @return 0 on success and negative error code on failure
+ */
+int mpxy_rpmi_read_attrs(const struct mpxy_rpmi_channel_attrs *attrs,
+			 u32 *outmem, u32 base_attr_id, u32 attr_count);
+
+#endif
diff --git a/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
index 3a1c117..12daaae 100644
--- a/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
+++ b/include/sbi_utils/mpxy/fdt_mpxy_rpmi_mbox.h
@@ -15,42 +15,7 @@
 #include <sbi_utils/mailbox/fdt_mailbox.h>
 #include <sbi_utils/mailbox/rpmi_msgprot.h>
 #include <sbi_utils/mpxy/fdt_mpxy.h>
-
-/** 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_IMPL_ID,
-	MPXY_MSGPROT_RPMI_ATTR_IMPL_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;
-	u32 impl_id;
-	u32 impl_ver;
-};
-
-/** Make sure all attributes are packed for direct memcpy */
-#define assert_field_offset(field, attr_offset)				\
-	_Static_assert(							\
-		((offsetof(struct mpxy_rpmi_channel_attrs, field)) /	\
-		 sizeof(u32)) == (attr_offset - SBI_MPXY_ATTR_MSGPROTO_ATTR_START),\
-		"field " #field						\
-		" from struct mpxy_rpmi_channel_attrs invalid offset, expected " #attr_offset)
-
-assert_field_offset(servicegrp_id, MPXY_MSGPROT_RPMI_ATTR_SERVICEGROUP_ID);
-assert_field_offset(servicegrp_ver, MPXY_MSGPROT_RPMI_ATTR_SERVICEGROUP_VERSION);
-assert_field_offset(impl_id, MPXY_MSGPROT_RPMI_ATTR_IMPL_ID);
-assert_field_offset(impl_ver, MPXY_MSGPROT_RPMI_ATTR_IMPL_VERSION);
+#include <sbi_utils/mpxy/fdt_mpxy_rpmi.h>
 
 /** MPXY RPMI service data for each service group */
 struct mpxy_rpmi_service_data {
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi.c b/lib/utils/mpxy/fdt_mpxy_rpmi.c
new file mode 100644
index 0000000..e5b15dc
--- /dev/null
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi.c
@@ -0,0 +1,29 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 Ventana Micro Systems Inc.
+ *
+ * Authors:
+ *   Anup Patel <apatel at ventanamicro.com>
+ */
+
+#include <sbi/sbi_byteorder.h>
+#include <sbi/sbi_error.h>
+#include <sbi_utils/mpxy/fdt_mpxy_rpmi.h>
+
+int mpxy_rpmi_read_attrs(const struct mpxy_rpmi_channel_attrs *attrs,
+			 u32 *outmem, u32 base_attr_id, u32 attr_count)
+{
+	const u32 *attr_array = (const u32 *)attrs;
+	u32 end_id = base_attr_id + attr_count - 1;
+	u32 idx;
+
+	if (end_id >= MPXY_MSGPROT_RPMI_ATTR_MAX_ID)
+		return SBI_EBAD_RANGE;
+
+	attr_array += attr_id2index(base_attr_id);
+	for (idx = 0; idx < attr_count; idx++)
+		outmem[idx] = cpu_to_le32(attr_array[idx]);
+
+	return SBI_OK;
+}
diff --git a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
index 825ac9b..02320a6 100644
--- a/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
+++ b/lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c
@@ -45,30 +45,15 @@ static const struct mpxy_rpmi_service_data *mpxy_find_rpmi_srvid(u32 message_id,
 	return NULL;
 }
 
-/** Copy attributes word size */
-static void mpxy_copy_attrs(u32 *outmem, u32 *inmem, u32 count)
-{
-	u32 idx;
-	for (idx = 0; idx < count; idx++)
-		outmem[idx] = cpu_to_le32(inmem[idx]);
-}
-
 static int mpxy_mbox_read_attributes(struct sbi_mpxy_channel *channel,
 				     u32 *outmem, u32 base_attr_id,
 				     u32 attr_count)
 {
 	struct mpxy_rpmi_mbox *rmb =
 		container_of(channel, struct mpxy_rpmi_mbox, channel);
-	u32 *attr_array = (u32 *)&rmb->msgprot_attrs;
-	u32 end_id = base_attr_id + attr_count - 1;
 
-	if (end_id >= MPXY_MSGPROT_RPMI_ATTR_MAX_ID)
-		return SBI_EBAD_RANGE;
-
-	mpxy_copy_attrs(outmem, &attr_array[attr_id2index(base_attr_id)],
-			attr_count);
-
-	return SBI_OK;
+	return mpxy_rpmi_read_attrs(&rmb->msgprot_attrs, outmem,
+				    base_attr_id, attr_count);
 }
 
 /**
diff --git a/lib/utils/mpxy/objects.mk b/lib/utils/mpxy/objects.mk
index 1f1bf0a..c406c12 100644
--- a/lib/utils/mpxy/objects.mk
+++ b/lib/utils/mpxy/objects.mk
@@ -8,6 +8,7 @@
 #
 
 libsbiutils-objs-$(CONFIG_FDT_MPXY) += mpxy/fdt_mpxy.o
+libsbiutils-objs-$(CONFIG_FDT_MPXY) += mpxy/fdt_mpxy_rpmi.o
 libsbiutils-objs-$(CONFIG_FDT_MPXY) += mpxy/fdt_mpxy_drivers.carray.o
 
 libsbiutils-objs-$(CONFIG_FDT_MPXY_RPMI_MBOX) += mpxy/fdt_mpxy_rpmi_mbox.o
-- 
2.43.0




More information about the opensbi mailing list