xref: /OK3568_Linux_fs/u-boot/drivers/firmware/scmi/smt.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
4*4882a593Smuzhiyun  * Copyright (C) 2019-2020 Linaro Limited.
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #ifndef SCMI_SMT_H
7*4882a593Smuzhiyun #define SCMI_SMT_H
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <asm/types.h>
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun /**
12*4882a593Smuzhiyun  * struct scmi_smt_header - Description of the shared memory message buffer
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * SMT stands for Shared Memory based Transport.
15*4882a593Smuzhiyun  * SMT uses 28 byte header prior message payload to handle the state of
16*4882a593Smuzhiyun  * the communication channel realized by the shared memory area and
17*4882a593Smuzhiyun  * to define SCMI protocol information the payload relates to.
18*4882a593Smuzhiyun  */
19*4882a593Smuzhiyun struct scmi_smt_header {
20*4882a593Smuzhiyun 	__le32 reserved;
21*4882a593Smuzhiyun 	__le32 channel_status;
22*4882a593Smuzhiyun #define SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR	BIT(1)
23*4882a593Smuzhiyun #define SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE	BIT(0)
24*4882a593Smuzhiyun 	__le32 reserved1[2];
25*4882a593Smuzhiyun 	__le32 flags;
26*4882a593Smuzhiyun #define SCMI_SHMEM_FLAG_INTR_ENABLED		BIT(0)
27*4882a593Smuzhiyun 	__le32 length;
28*4882a593Smuzhiyun 	__le32 msg_header;
29*4882a593Smuzhiyun 	u8 msg_payload[0];
30*4882a593Smuzhiyun };
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #define SMT_HEADER_TOKEN(token)		(((token) << 18) & GENMASK(31, 18))
33*4882a593Smuzhiyun #define SMT_HEADER_PROTOCOL_ID(proto)	(((proto) << 10) & GENMASK(17, 10))
34*4882a593Smuzhiyun #define SMT_HEADER_MESSAGE_TYPE(type)	(((type) << 18) & GENMASK(9, 8))
35*4882a593Smuzhiyun #define SMT_HEADER_MESSAGE_ID(id)	((id) & GENMASK(7, 0))
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /**
38*4882a593Smuzhiyun  * struct scmi_smt - Description of a SMT memory buffer
39*4882a593Smuzhiyun  * @buf:	Shared memory base address
40*4882a593Smuzhiyun  * @size:	Shared memory byte size
41*4882a593Smuzhiyun  */
42*4882a593Smuzhiyun struct scmi_smt {
43*4882a593Smuzhiyun 	u8 *buf;
44*4882a593Smuzhiyun 	size_t size;
45*4882a593Smuzhiyun };
46*4882a593Smuzhiyun 
scmi_smt_channel_is_free(struct scmi_smt * smt)47*4882a593Smuzhiyun static inline bool scmi_smt_channel_is_free(struct scmi_smt *smt)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun 	struct scmi_smt_header *hdr = (void *)smt->buf;
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun 	return hdr->channel_status & SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun 
scmi_smt_channel_reports_error(struct scmi_smt * smt)54*4882a593Smuzhiyun static inline bool scmi_smt_channel_reports_error(struct scmi_smt *smt)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun 	struct scmi_smt_header *hdr = (void *)smt->buf;
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun 	return hdr->channel_status & SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR;
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun 
scmi_smt_get_channel(struct scmi_smt * smt)61*4882a593Smuzhiyun static inline void scmi_smt_get_channel(struct scmi_smt *smt)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun 	struct scmi_smt_header *hdr = (void *)smt->buf;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	hdr->channel_status &= ~SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE;
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun 
scmi_smt_put_channel(struct scmi_smt * smt)68*4882a593Smuzhiyun static inline void scmi_smt_put_channel(struct scmi_smt *smt)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun 	struct scmi_smt_header *hdr = (void *)smt->buf;
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	hdr->channel_status |= SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE;
73*4882a593Smuzhiyun 	hdr->channel_status &= ~SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR;
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun int scmi_dt_get_smt_buffer(struct udevice *dev, struct scmi_smt *smt);
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun int scmi_write_msg_to_smt(struct udevice *dev, struct scmi_smt *smt,
79*4882a593Smuzhiyun 			  struct scmi_msg *msg);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun int scmi_read_resp_from_smt(struct udevice *dev, struct scmi_smt *smt,
82*4882a593Smuzhiyun 			    struct scmi_msg *msg);
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun void scmi_clear_smt_channel(struct scmi_smt *smt);
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun #endif /* SCMI_SMT_H */
87