xref: /openbmc/linux/drivers/firmware/arm_scmi/common.h (revision 9c6d26df1fae6ad4718d51c48e6517913304ed27)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * System Control and Management Interface (SCMI) Message Protocol
4  * driver common header file containing some definitions, structures
5  * and function prototypes used in all the different SCMI protocols.
6  *
7  * Copyright (C) 2018 ARM Ltd.
8  */
9 
10 #include <linux/completion.h>
11 #include <linux/device.h>
12 #include <linux/errno.h>
13 #include <linux/kernel.h>
14 #include <linux/scmi_protocol.h>
15 #include <linux/types.h>
16 
17 #define PROTOCOL_REV_MINOR_BITS	16
18 #define PROTOCOL_REV_MINOR_MASK	((1U << PROTOCOL_REV_MINOR_BITS) - 1)
19 #define PROTOCOL_REV_MAJOR(x)	((x) >> PROTOCOL_REV_MINOR_BITS)
20 #define PROTOCOL_REV_MINOR(x)	((x) & PROTOCOL_REV_MINOR_MASK)
21 #define MAX_PROTOCOLS_IMP	16
22 #define MAX_OPPS		16
23 
24 enum scmi_common_cmd {
25 	PROTOCOL_VERSION = 0x0,
26 	PROTOCOL_ATTRIBUTES = 0x1,
27 	PROTOCOL_MESSAGE_ATTRIBUTES = 0x2,
28 };
29 
30 /**
31  * struct scmi_msg_resp_prot_version - Response for a message
32  *
33  * @major_version: Major version of the ABI that firmware supports
34  * @minor_version: Minor version of the ABI that firmware supports
35  *
36  * In general, ABI version changes follow the rule that minor version increments
37  * are backward compatible. Major revision changes in ABI may not be
38  * backward compatible.
39  *
40  * Response to a generic message with message type SCMI_MSG_VERSION
41  */
42 struct scmi_msg_resp_prot_version {
43 	__le16 minor_version;
44 	__le16 major_version;
45 };
46 
47 /**
48  * struct scmi_msg_hdr - Message(Tx/Rx) header
49  *
50  * @id: The identifier of the command being sent
51  * @protocol_id: The identifier of the protocol used to send @id command
52  * @seq: The token to identify the message. when a message/command returns,
53  *       the platform returns the whole message header unmodified including
54  *	 the token.
55  */
56 struct scmi_msg_hdr {
57 	u8 id;
58 	u8 protocol_id;
59 	u16 seq;
60 	u32 status;
61 	bool poll_completion;
62 };
63 
64 /**
65  * struct scmi_msg - Message(Tx/Rx) structure
66  *
67  * @buf: Buffer pointer
68  * @len: Length of data in the Buffer
69  */
70 struct scmi_msg {
71 	void *buf;
72 	size_t len;
73 };
74 
75 /**
76  * struct scmi_xfer - Structure representing a message flow
77  *
78  * @hdr: Transmit message header
79  * @tx: Transmit message
80  * @rx: Receive message, the buffer should be pre-allocated to store
81  *	message. If request-ACK protocol is used, we can reuse the same
82  *	buffer for the rx path as we use for the tx path.
83  * @done: completion event
84  */
85 
86 struct scmi_xfer {
87 	void *con_priv;
88 	struct scmi_msg_hdr hdr;
89 	struct scmi_msg tx;
90 	struct scmi_msg rx;
91 	struct completion done;
92 };
93 
94 void scmi_one_xfer_put(const struct scmi_handle *h, struct scmi_xfer *xfer);
95 int scmi_do_xfer(const struct scmi_handle *h, struct scmi_xfer *xfer);
96 int scmi_one_xfer_init(const struct scmi_handle *h, u8 msg_id, u8 prot_id,
97 		       size_t tx_size, size_t rx_size, struct scmi_xfer **p);
98 int scmi_handle_put(const struct scmi_handle *handle);
99 struct scmi_handle *scmi_handle_get(struct device *dev);
100 void scmi_set_handle(struct scmi_device *scmi_dev);
101 int scmi_version_get(const struct scmi_handle *h, u8 protocol, u32 *version);
102 void scmi_setup_protocol_implemented(const struct scmi_handle *handle,
103 				     u8 *prot_imp);
104 
105 int scmi_base_protocol_init(struct scmi_handle *h);
106