1
2
3
4
5
6
7
8
9
10
11#include <linux/types.h>
12
13#include "common.h"
14
15
16
17
18
19
20
21struct scmi_msg_payld {
22 __le32 msg_header;
23 __le32 msg_payload[];
24};
25
26
27
28
29
30
31
32
33size_t msg_command_size(struct scmi_xfer *xfer)
34{
35 return sizeof(struct scmi_msg_payld) + xfer->tx.len;
36}
37
38
39
40
41
42
43
44
45size_t msg_response_size(struct scmi_xfer *xfer)
46{
47 return sizeof(struct scmi_msg_payld) + sizeof(__le32) + xfer->rx.len;
48}
49
50
51
52
53
54
55
56void msg_tx_prepare(struct scmi_msg_payld *msg, struct scmi_xfer *xfer)
57{
58 msg->msg_header = cpu_to_le32(pack_scmi_header(&xfer->hdr));
59 if (xfer->tx.buf)
60 memcpy(msg->msg_payload, xfer->tx.buf, xfer->tx.len);
61}
62
63
64
65
66
67
68
69
70u32 msg_read_header(struct scmi_msg_payld *msg)
71{
72 return le32_to_cpu(msg->msg_header);
73}
74
75
76
77
78
79
80
81
82void msg_fetch_response(struct scmi_msg_payld *msg, size_t len,
83 struct scmi_xfer *xfer)
84{
85 size_t prefix_len = sizeof(*msg) + sizeof(msg->msg_payload[0]);
86
87 xfer->hdr.status = le32_to_cpu(msg->msg_payload[0]);
88 xfer->rx.len = min_t(size_t, xfer->rx.len,
89 len >= prefix_len ? len - prefix_len : 0);
90
91
92 memcpy(xfer->rx.buf, &msg->msg_payload[1], xfer->rx.len);
93}
94
95
96
97
98
99
100
101
102
103void msg_fetch_notification(struct scmi_msg_payld *msg, size_t len,
104 size_t max_len, struct scmi_xfer *xfer)
105{
106 xfer->rx.len = min_t(size_t, max_len,
107 len >= sizeof(*msg) ? len - sizeof(*msg) : 0);
108
109
110 memcpy(xfer->rx.buf, msg->msg_payload, xfer->rx.len);
111}
112