Skip to content

Conversation

yongxu-wang15
Copy link
Contributor

@yongxu-wang15 yongxu-wang15 commented Jul 18, 2025

  1. SCMI P2A support: Adds RX channel handling to support notifications from platform to agent, including callback categorization for different message types.
  2. Shared memory separation: Extends SCMI shared memory to an phandles to allow TX and RX to use different memory regions, which is required on platforms like i.MX95.
  3. BBNSM protocol support: Adds initial support for the BBNSM domain protocol
    test pass in imx95 m7 hello_word sample, The M7 core can continuously receive button messages from the SCMI platform.

@yongxu-wang15
Copy link
Contributor Author

v2: updated to fix twister build issue in imx95/imx943 m/a core

ret = k_mutex_lock(&proto->rx->lock, K_USEC(SCMI_CHAN_LOCK_TIMEOUT_USEC));
if (ret < 0) {
LOG_ERR("failed to acquire chan lock");
return ret;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are returning with mutex locked. I think you might want to goto out_release_mutex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if k_mutex_lock error, it not need to release mutex from my understand


#if defined(CONFIG_NXP_SCMI_BBM_HELPERS)
uint32_t flags;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part should come in a different patch. Also, please abstract it under a function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have removed this call back flow into another commit, thanks

This driver is NXP-specific. As such, it may only be used on NXP
system that uses SCMI for cpu domain management operations.

NXP - BBNSM management
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least in the commit message you should explain what BBNSM acronym stands for so that you can allow reviewers to understand what is this all about.

Copy link
Contributor Author

@yongxu-wang15 yongxu-wang15 Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, updated it in doc and commit description

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see this scaling very well. So, how about moving all of the NXP vendor-specific stuff to a different page? Also, do we have a link to some sort of documentation fully describing the protocol? Kinda like what we have for Linux: https://elixir.bootlin.com/linux/v6.16.1/source/drivers/firmware/arm_scmi/vendors/imx/imx95.rst

CC: @kartben would we bloat the documentation page if we were to add a full explanation of each vendor-specific protocol?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, do you mean that we need add an directory scmi/vendor/nxp into zephyr/doc/hardware/arch? I can organize it if need, thanks
ping: @kartben , can you give some suggestion about this? thanks a lot

@yongxu-wang15 yongxu-wang15 force-pushed the NXP-scmi-add-p2a-and-bbnsm-protocol branch from e073dd8 to ea7ed13 Compare July 22, 2025 08:33
@yongxu-wang15
Copy link
Contributor Author

yongxu-wang15 commented Jul 22, 2025

V3: update pr according into @dbaluta comments

  1. add more description about bbnsm
  2. separate into another patch about p2a callback flow

@yongxu-wang15
Copy link
Contributor Author

yongxu-wang15 commented Aug 11, 2025

hi @dbaluta, have updated it according into your suggestion, other comments about it? thanks a lot

Copy link
Contributor

@LaurentiuM1234 LaurentiuM1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions/comments below.

None of your commits should break the build if applied incrementally. If I try to build the hello_world application with 6fbb947 and then 9a3dda1 applied, the build will break.

I believe @dbaluta has told you multiple times to break your changes into different patches, based on what the changes are trying to achieve. This, of course, applies to the whole PR, not just the areas on which @dbaluta commented.

As things stand now I don't believe this is ready for merge, which is why I'm blocking this.


DT_SCMI_PROTOCOL_DEFINE_NODEV(DT_INST(0, nxp_scmi_bbm), NULL);

extern uint32_t scmi_p2a_header_token;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this driver added in the first commit? would it even compile? would it do anything useful without the notifications infrastructure?

reply.len = sizeof(uint32_t);
reply.content = &status;

use_polling = k_is_pre_kernel();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this variable - can just pass k_is_pre_kernel() to scmi_send_message()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, updated


msg.hdr = SCMI_MESSAGE_HDR_MAKE(SCMI_PROTO_BBM_BBM_BUTTON_NOTIFY, SCMI_COMMAND,
proto->id, 0);
msg.len = sizeof(uint32_t);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sizeof(flags)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, done

msg.content = &flags;

reply.hdr = msg.hdr;
reply.len = sizeof(uint32_t);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sizeof(status)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, done


msg.hdr = SCMI_MESSAGE_HDR_MAKE(SCMI_PROTO_BBM_PROTOCOL_BUTTON_EVENT, SCMI_NOTIFICATION,
proto->id, scmi_p2a_header_token++);
msg.len = sizeof(uint32_t);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sizeof(flags)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

#include <zephyr/drivers/firmware/scmi/shmem.h>
#include <string.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the point of incrementally introducing these changes to the BBM driver? this is a new protocol so might as well have everything introduced in a single commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put bbm driver as only single commit now, keep its readability of the code logic

}

static void scmi_core_reply_cb(struct scmi_channel *chan, struct scmi_message *msg)
static void scmi_core_reply_cb(struct scmi_channel *chan, struct scmi_message msg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this callback is meant for TX replies yet you're using it for notifications? I also don't understand the point of the second parameter and why it was randomly changed from a pointer to a struct scmi_message to just struct scmi_message in this commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, put tx/rx reply_cb into one scmi_core_reply_cb in core.c, but tx don't need another flow, just check its msg_type, its mainly deal with rx notification event, dispacher and send it into specific protocol

#define SCMI_CHAN_LOCK_TIMEOUT_USEC 500
#define SCMI_CHAN_SEM_TIMEOUT_USEC 500

static sys_slist_t scmi_event_list;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a linked list? Can we not have each protocol keep an array of struct scmi_protocol_event for all registered events?

The definition of struct scmi_protocol_event would be:

struct scmi_protocol_event {
    uint32_t id; /* event ID */
    scmi_evt_callback_t cb; /* event callback */
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed list, added events_ptr into DT_SCMI_PROTOCOL_DEFINE_NODEV now, thanks


static int scmi_nxp_bbm_event_init(void)
{
return scmi_register_protocol_event_handler(&bbm_event);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to also unregister protocol events? if not, then we can probably get around with binding the event array to the protocol structure at build time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, updated it

properties:
shmem:
type: phandle
type: phandle-array
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this not be phandles type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, its fine, corrected

@yongxu-wang15
Copy link
Contributor Author

Updated from LaurentiuM comments:
Hi @LaurentiuM1234 thanks your comments, I have redistributed the commit content and sequence of this PR to ensure the accuracy of the commit information and changes. I have also conducted a local hello_world test to guarantee that each commit does not affect the compilation of the platform, please help review it again when your time free, thanks

SCMI P2A (Platform to Agent) communication is critical in platform-agent
interactions. Previously, only A2P (Agent to Platform) was supported.
This patch introduces the P2A workflow by adding support for
`scmi_channel->rx` and `scmi_mbox_channel->rx`, treating the RX channel
as an independent channel.

For P2A RX channels, initialization is optional and depends on platform
design. If both the protocol node and the base transport node do not
specify an RX shmem region, the RX channel will not be initialized.

Signed-off-by: Yongxu Wang <[email protected]>
Introduce a dedicated RX callback at the mailbox transport layer so TX
and RX are dispatched via separate callbacks.

Signed-off-by: Yongxu Wang <[email protected]>
Add scmi_shmem_clear_channel_status to clear channel status which diff
a2p and p2a direction

Signed-off-by: Yongxu Wang <[email protected]>
In the SCMI core layer, add msg_type validation before dispatch
(e.g. RESP vs NOTIFY vs CMD). Messages with an unexpected or invalid
type for the current context are logged

Signed-off-by: Yongxu Wang <[email protected]>
Add support for protocol-level registration of notification events
during static registration. Each protocol declares the notifications
it needs at static init time.

In the SCMI core layer, upon receiving a P2A notification, the core
iterates over all registered protocols to locate the matching event
and dispatches it to the appropriate protocol handler.

Signed-off-by: Yongxu Wang <[email protected]>
Introduce scmi_read_message() to allow protocols to read the associated
event payload when a P2A notification is received. This enables protocol
drivers to process notification-specific data after the SCMI core
dispatches the event.

Signed-off-by: Yongxu Wang <[email protected]>
This protocol is intended provide access to the battery-backed module,
it contains persistent storage (GPR), an RTC, and the ON/OFF button.
The protocol can also provide access to similar functions
implemented via external board components.

Added button P2A notification event for the BBM protocol.

Signed-off-by: Yongxu Wang <[email protected]>
Extends the SCMI shared memory structure to phandles,
allowing TX and RX channels to use different shared memory regions.
This is necessary for platforms like i.MX95, where TX and RX
notifications are mapped to different addresses.

RX channel is not mandatory and depends on the platform's support

Signed-off-by: Yongxu Wang <[email protected]>
Add scmi rx shmem and bbm node into imx95 m7

Signed-off-by: Yongxu Wang <[email protected]>
enable scmi bbm button function, m7 can get notification from
scmi platform when press onoff button

Signed-off-by: Yongxu Wang <[email protected]>
@yongxu-wang15 yongxu-wang15 force-pushed the NXP-scmi-add-p2a-and-bbnsm-protocol branch from c76d77e to d876137 Compare October 14, 2025 02:29
Copy link

/**
* @brief Get a reference to a protocol's SCMI TX channel
* @brief Get a reference to a protocol's SCMI TX/RX channel
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont merge the comments like this. Add a similar comment for RX channel.

/**
* @brief Declare a TX SCMI channel
* @brief Declare TX/RX SCMI channel
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't merge commments like this. Add a similar comment at the top of RX Channel declaration.

#include <zephyr/logging/log.h>
#include "mailbox.h"

LOG_MODULE_REGISTER(scmi_mbox);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/callbak/callback/ in the commit subject.

void *user_data,
struct mbox_msg *data)
static void scmi_mbox_tx_reply_cb(const struct device *mbox,
mbox_channel_id_t channel_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this into 2 patches:

  1. Preparation for introducing the RX channel. Here you rename scmi_mbox_cb -> scmi_mbox_tx_reply_cb and implement scmi_mbox_cb with the logic for supporting tx/rx direction but only TX implemented so far.
  2. Add the RX channel.

Much easier to review the transition like this.

status = scmi_core_handle_notification(hdr);
if (status) {
LOG_WRN("Scmi notification event not find");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/not find/not found. Also, do you want to print the status here?

return -EINVAL;
}

ret = scmi_transport_read_message(proto->transport, proto->rx, msg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for ret here. Judt directly return scmi_transport_read_message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants