Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/clock_control/clock_control_arm_scmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ static struct scmi_clock_data data;

DT_INST_SCMI_PROTOCOL_DEFINE(0, &scmi_clock_init, NULL, &data, NULL,
PRE_KERNEL_1, CONFIG_CLOCK_CONTROL_INIT_PRIORITY,
&scmi_clock_api);
&scmi_clock_api, NULL);
32 changes: 32 additions & 0 deletions drivers/firmware/scmi/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,37 @@ int scmi_status_to_errno(int scmi_status)
}
}

static int scmi_core_handle_notification(int hdr)
{
uint32_t protocol_id, msg_id;
struct scmi_protocol_event *events;

protocol_id = SCMI_MESSAGE_HDR_EX_PROTOCOL(hdr);
msg_id = SCMI_MESSAGE_HDR_EX_MSGID(hdr);

STRUCT_SECTION_FOREACH(scmi_protocol, it) {
events = it->events;
if (!events || !events->cb) {
continue;
}

if (protocol_id == it->id) {
for (uint32_t num = 0; num < events->num_events; num++) {
if (msg_id == events->evts[num]) {
events->cb(msg_id);
return 0;
}
}
}
}

return -ENOENT;
}

static void scmi_core_reply_cb(struct scmi_channel *chan, int hdr)
{
int msg_type;
int status;

msg_type = SCMI_MESSAGE_HDR_EX_TYPE(hdr);

Expand All @@ -55,6 +83,10 @@ static void scmi_core_reply_cb(struct scmi_channel *chan, int hdr)
case SCMI_DELAYED_REPLY:
break;
case SCMI_NOTIFICATION:
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?

break;
default:
LOG_WRN("Unexpected message type %u", msg_type);
Expand Down
2 changes: 1 addition & 1 deletion drivers/firmware/scmi/nxp/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <zephyr/drivers/firmware/scmi/nxp/cpu.h>
#include <zephyr/kernel.h>

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

int scmi_cpu_sleep_mode_set(struct scmi_cpu_sleep_mode_config *cfg)
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/firmware/scmi/pinctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <zephyr/drivers/firmware/scmi/pinctrl.h>
#include <zephyr/kernel.h>

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

int scmi_pinctrl_settings_configure(struct scmi_pinctrl_settings *settings)
{
Expand Down
2 changes: 1 addition & 1 deletion drivers/firmware/scmi/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <string.h>
#include <zephyr/kernel.h>

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

struct scmi_power_state_get_reply {
int32_t status;
Expand Down
30 changes: 30 additions & 0 deletions include/zephyr/drivers/firmware/scmi/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,36 @@ struct scmi_protocol {
const struct device *transport;
/** protocol private data */
void *data;
/** protocol event */
struct scmi_protocol_event *events;
};

/**
* @typedef scmi_protocol_event_callback
* @brief Per‑protocol notification callback invoked by the SCMI core.
*
* Define event-specific information during the static registration phase
* of each SCMI protocol. When a P2A notification/interrupt is received,
* the SCMI core decodes the message and dispatches it to the corresponding
* protocol's callback.
*
* @param msg_id is the protocol specific message index.
* @return int 0 on success, negative error code on failure
*/
typedef int (*scmi_protocol_event_callback)(int32_t msg_id);

/**
* @struct scmi_protocol_event
*
* @brief SCMI protocol event structure
*/
struct scmi_protocol_event {
/** events ids */
uint32_t *evts;
/** Number of supported protocol's events **/
uint32_t num_events;
/** protocol private event call back **/
scmi_protocol_event_callback cb;
};

/**
Expand Down
25 changes: 13 additions & 12 deletions include/zephyr/drivers/firmware/scmi/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@
* @param proto protocol ID in decimal format
* @param pdata protocol private data
*/
#define DT_SCMI_PROTOCOL_DATA_DEFINE(node_id, proto, pdata) \
#define DT_SCMI_PROTOCOL_DATA_DEFINE(node_id, proto, pdata, pevents) \
STRUCT_SECTION_ITERABLE(scmi_protocol, SCMI_PROTOCOL_NAME(proto)) = \
{ \
.id = proto, \
.tx = DT_SCMI_TRANSPORT_TX_CHAN(node_id), \
.rx = DT_SCMI_TRANSPORT_RX_CHAN(node_id), \
.data = pdata, \
.events = pevents, \
}

#else /* CONFIG_ARM_SCMI_TRANSPORT_HAS_STATIC_CHANNELS */
Expand Down Expand Up @@ -225,12 +226,12 @@
* @param level protocol initialization level
* @param prio protocol's priority within its initialization level
*/
#define DT_SCMI_PROTOCOL_DEFINE(node_id, init_fn, pm, data, config, \
level, prio, api) \
DT_SCMI_TRANSPORT_CHANNELS_DECLARE(node_id) \
DT_SCMI_PROTOCOL_DATA_DEFINE(node_id, DT_REG_ADDR_RAW(node_id), data); \
DEVICE_DT_DEFINE(node_id, init_fn, pm, \
&SCMI_PROTOCOL_NAME(DT_REG_ADDR_RAW(node_id)), \
#define DT_SCMI_PROTOCOL_DEFINE(node_id, init_fn, pm, data, config, \
level, prio, api, events) \
DT_SCMI_TRANSPORT_CHANNELS_DECLARE(node_id) \
DT_SCMI_PROTOCOL_DATA_DEFINE(node_id, DT_REG_ADDR_RAW(node_id), data, events); \
DEVICE_DT_DEFINE(node_id, init_fn, pm, \
&SCMI_PROTOCOL_NAME(DT_REG_ADDR_RAW(node_id)), \
config, level, prio, api)

/**
Expand All @@ -247,9 +248,9 @@
* @param prio protocol's priority within its initialization level
*/
#define DT_INST_SCMI_PROTOCOL_DEFINE(inst, init_fn, pm, data, config, \
level, prio, api) \
level, prio, api, events) \
DT_SCMI_PROTOCOL_DEFINE(DT_INST(inst, DT_DRV_COMPAT), init_fn, pm, \
data, config, level, prio, api)
data, config, level, prio, api, events)

/**
* @brief Define an SCMI protocol with no device
Expand All @@ -262,9 +263,9 @@
* @param node_id protocol node identifier
* @param data protocol private data
*/
#define DT_SCMI_PROTOCOL_DEFINE_NODEV(node_id, data) \
DT_SCMI_TRANSPORT_CHANNELS_DECLARE(node_id) \
DT_SCMI_PROTOCOL_DATA_DEFINE(node_id, DT_REG_ADDR_RAW(node_id), data)
#define DT_SCMI_PROTOCOL_DEFINE_NODEV(node_id, data, events_ptr) \
DT_SCMI_TRANSPORT_CHANNELS_DECLARE(node_id) \
DT_SCMI_PROTOCOL_DATA_DEFINE(node_id, DT_REG_ADDR_RAW(node_id), data, events_ptr)

/**
* @brief Create an SCMI message field
Expand Down