Skip to content

Commit 3df3ed3

Browse files
committed
drivers: firmware: scmi: add interface to read hdr message
Introduced an interface to shmem to directly read the current hdr content without knowing the context of the message Add api to get shmem message in mailbox driver Signed-off-by: Yongxu Wang <[email protected]>
1 parent 21744a1 commit 3df3ed3

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

drivers/firmware/scmi/mailbox.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,39 @@
66

77
#include <zephyr/logging/log.h>
88
#include "mailbox.h"
9+
#include <zephyr/drivers/firmware/scmi/protocol.h>
910

1011
LOG_MODULE_REGISTER(scmi_mbox);
1112

13+
static int scmi_mbox_get_pending_msg(struct scmi_channel *chan,
14+
struct scmi_message *msg)
15+
{
16+
uint32_t context;
17+
int ret;
18+
struct scmi_mbox_channel *mbox_chan = chan->data;
19+
20+
msg->hdr = 0x0;
21+
msg->len = sizeof(uint32_t);
22+
msg->content = &context;
23+
24+
ret = scmi_shmem_read_hdr(mbox_chan->shmem, msg);
25+
if (ret < 0) {
26+
LOG_ERR("failed to read message to shmem: %d", ret);
27+
return ret;
28+
}
29+
30+
return 0;
31+
}
32+
1233
static void scmi_mbox_tx_reply_cb(const struct device *mbox,
1334
mbox_channel_id_t channel_id,
1435
void *user_data,
1536
struct mbox_msg *data)
1637
{
1738
struct scmi_channel *scmi_chan = user_data;
39+
struct scmi_message msg;
40+
41+
scmi_mbox_get_pending_msg(scmi_chan, &msg);
1842

1943
if (scmi_chan->cb) {
2044
scmi_chan->cb(scmi_chan);
@@ -29,6 +53,9 @@ static void scmi_mbox_rx_notify_cb(const struct device *mbox,
2953
struct scmi_channel *scmi_chan = user_data;
3054
struct scmi_mbox_channel *mbox_chan = scmi_chan->data;
3155
const struct device *shmem = mbox_chan->shmem;
56+
struct scmi_message msg;
57+
58+
scmi_mbox_get_pending_msg(scmi_chan, &msg);
3259

3360
if (scmi_chan->cb) {
3461
scmi_chan->cb(scmi_chan);

drivers/firmware/scmi/shmem.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@ static void scmi_shmem_memcpy(mm_reg_t dst, mm_reg_t src, uint32_t bytes)
5959
}
6060
}
6161

62+
int scmi_shmem_read_hdr(const struct device *shmem, struct scmi_message *msg)
63+
{
64+
struct scmi_shmem_layout *layout;
65+
struct scmi_shmem_data *data;
66+
67+
data = shmem->data;
68+
layout = (struct scmi_shmem_layout *)data->regmap;
69+
70+
/* some sanity checks first */
71+
if (!msg) {
72+
return -EINVAL;
73+
}
74+
75+
if (scmi_shmem_vendor_read_message(layout) < 0) {
76+
LOG_ERR("vendor specific validation failed");
77+
return -EINVAL;
78+
}
79+
80+
scmi_shmem_memcpy(POINTER_TO_UINT(&msg->hdr),
81+
data->regmap + SCMI_SHMEM_CHAN_MSG_HDR_OFFSET, sizeof(uint32_t));
82+
83+
return 0;
84+
}
85+
6286
__weak int scmi_shmem_vendor_read_message(const struct scmi_shmem_layout *layout)
6387
{
6488
return 0;

include/zephyr/drivers/firmware/scmi/shmem.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#define SCMI_SHMEM_CHAN_STATUS_FREE_BIT BIT(0)
2020
#define SCMI_SHMEM_CHAN_FLAG_IRQ_BIT BIT(0)
2121

22+
#define SCMI_SHMEM_CHAN_MSG_HDR_OFFSET 0x18
23+
2224
struct scmi_shmem_layout {
2325
volatile uint32_t res0;
2426
volatile uint32_t chan_status;
@@ -100,4 +102,16 @@ int scmi_shmem_vendor_read_message(const struct scmi_shmem_layout *layout);
100102
*/
101103
void scmi_shmem_clear_channel_status(const struct device *dev);
102104

105+
/**
106+
* @brief Read a message header from a SHMEM area
107+
*
108+
* @param shmem pointer to shmem device
109+
* @param msg message to write the data into
110+
*
111+
* @retval 0 if successful
112+
* @retval negative errno if failure
113+
*/
114+
115+
int scmi_shmem_read_hdr(const struct device *shmem, struct scmi_message *msg);
116+
103117
#endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_SHMEM_H_ */

0 commit comments

Comments
 (0)