lib: utils: Populate MPXY channel attributes from RPMI channel attributes

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

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
This commit is contained in:
Anup Patel
2025-01-12 16:59:46 +05:30
committed by Anup Patel
parent 91012b475d
commit e4bc55930b
2 changed files with 63 additions and 37 deletions

View File

@@ -16,9 +16,6 @@
#include <sbi_utils/mailbox/rpmi_msgprot.h> #include <sbi_utils/mailbox/rpmi_msgprot.h>
#include <sbi_utils/mpxy/fdt_mpxy.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 */ /** Convert the mpxy attribute ID to attribute array index */
#define attr_id2index(attr_id) (attr_id - SBI_MPXY_ATTR_MSGPROTO_ATTR_START) #define attr_id2index(attr_id) (attr_id - SBI_MPXY_ATTR_MSGPROTO_ATTR_START)

View File

@@ -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) 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; const struct mpxy_rpmi_mbox_data *data = match->data;
struct mpxy_rpmi_mbox *rmb; struct mpxy_rpmi_mbox *rmb;
struct mbox_chan *chan; struct mbox_chan *chan;
const fdt32_t *val; const fdt32_t *val;
u32 channel_id;
int rc, len; int rc, len;
/* Allocate context for RPXY mbox client */ /* Allocate context for MPXY mbox client */
rmb = sbi_zalloc(sizeof(*rmb)); rmb = sbi_zalloc(sizeof(*rmb));
if (!rmb) if (!rmb)
return SBI_ENOMEM; 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); rc = fdt_mailbox_request_chan(fdt, nodeoff, 0, &chan);
if (rc) { if (rc) {
sbi_free(rmb); rc = SBI_ENODEV;
return SBI_ENODEV; goto fail_free_client;
} }
/* Match channel service group id */ /* Match channel service group id */
if (data->servicegrp_id != chan->chan_args[0]) { if (data->servicegrp_id != chan->chan_args[0]) {
mbox_controller_free_chan(chan); rc = SBI_EINVAL;
sbi_free(rmb); goto fail_free_chan;
return SBI_EINVAL;
} }
/* 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 * The "riscv,sbi-mpxy-channel-id" DT property is mandatory
* for MPXY RPMI mailbox client driver so if this is not * for MPXY RPMI mailbox client driver so if this is not
* present then try other drivers. * present then try other drivers.
*/ */
val = fdt_getprop(fdt, nodeoff, "riscv,sbi-mpxy-channel-id", &len); 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); channel_id = fdt32_to_cpu(*val);
else { } else {
mbox_controller_free_chan(chan); rc = SBI_ENODEV;
sbi_free(rmb); goto fail_free_chan;
return SBI_ENODEV;
} }
/* Setup MPXY mbox client */ /* 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 */ /* RPMI Message Protocol ID */
rmb->channel.attrs.msg_proto_id = SBI_MPXY_MSGPROTO_RPMI_ID; rmb->channel.attrs.msg_proto_id = SBI_MPXY_MSGPROTO_RPMI_ID;
/* RPMI Message Protocol Version */ /* RPMI Message Protocol Version */
rmb->channel.attrs.msg_proto_version = rmb->channel.attrs.msg_proto_version = pro_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 */ * RPMI supported max message data length(bytes), same for
rmb->channel.attrs.msg_data_maxlen = * all service groups
RPMI_MSG_DATA_SIZE(RPMI_SLOT_SIZE_MIN); */
/* RPMI message send timeout(milliseconds) rmb->channel.attrs.msg_data_maxlen = max_data_len;
* same for all service groups */ /*
rmb->channel.attrs.msg_send_timeout = RPMI_DEF_TX_TIMEOUT; * RPMI message send timeout(milliseconds)
rmb->channel.attrs.msg_completion_timeout = * same for all service groups
RPMI_DEF_TX_TIMEOUT + RPMI_DEF_RX_TIMEOUT; */
rmb->channel.attrs.msg_send_timeout = tx_tout;
rmb->channel.attrs.msg_completion_timeout = tx_tout + rx_tout;
/* RPMI message protocol attributes */ /* RPMI service group attributes */
rmb->msgprot_attrs.servicegrp_id = data->servicegrp_id; rmb->msgprot_attrs.servicegrp_id = data->servicegrp_id;
rmb->msgprot_attrs.servicegrp_ver = rmb->msgprot_attrs.servicegrp_ver = servicegrp_ver;
SBI_MPXY_MSGPROTO_VERSION(MPXY_RPMI_MAJOR_VER, MPXY_RPMI_MINOR_VER);
rmb->mbox_data = data; rmb->mbox_data = data;
rmb->chan = chan; 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 */ /* Setup RPMI service group context */
if (data->setup_group) { if (data->setup_group) {
rc = data->setup_group(&rmb->group_context, chan, data); rc = data->setup_group(&rmb->group_context, chan, data);
if (rc) { if (rc)
mbox_controller_free_chan(chan); goto fail_free_chan;
sbi_free(rmb);
return rc;
}
} }
/* Register RPMI service group */ /* 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 (rc) {
if (data->cleanup_group) if (data->cleanup_group)
data->cleanup_group(rmb->group_context); data->cleanup_group(rmb->group_context);
mbox_controller_free_chan(chan); goto fail_free_chan;
sbi_free(rmb);
return rc;
} }
return SBI_OK; return SBI_OK;
fail_free_chan:
mbox_controller_free_chan(chan);
fail_free_client:
sbi_free(rmb);
return rc;
} }