Nishad Kamdar | d252768 | 2019-06-13 19:30:03 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Sudeep Holla | aa4f886 | 2017-03-28 11:36:07 +0100 | [diff] [blame] | 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 | |
Sudeep Holla | 354b2e3 | 2018-05-09 17:52:06 +0100 | [diff] [blame] | 10 | #include <linux/bitfield.h> |
Sudeep Holla | aa4f886 | 2017-03-28 11:36:07 +0100 | [diff] [blame] | 11 | #include <linux/completion.h> |
Sudeep Holla | b6f20ff | 2017-06-06 11:16:15 +0100 | [diff] [blame] | 12 | #include <linux/device.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/kernel.h> |
Sudeep Holla | aa4f886 | 2017-03-28 11:36:07 +0100 | [diff] [blame] | 15 | #include <linux/scmi_protocol.h> |
| 16 | #include <linux/types.h> |
| 17 | |
Sudeep Holla | 354b2e3 | 2018-05-09 17:52:06 +0100 | [diff] [blame] | 18 | #define PROTOCOL_REV_MINOR_MASK GENMASK(15, 0) |
| 19 | #define PROTOCOL_REV_MAJOR_MASK GENMASK(31, 16) |
| 20 | #define PROTOCOL_REV_MAJOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x))) |
| 21 | #define PROTOCOL_REV_MINOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MINOR_MASK, (x))) |
Sudeep Holla | b6f20ff | 2017-06-06 11:16:15 +0100 | [diff] [blame] | 22 | #define MAX_PROTOCOLS_IMP 16 |
Sudeep Holla | a9e3fbf | 2017-06-06 11:22:51 +0100 | [diff] [blame] | 23 | #define MAX_OPPS 16 |
Sudeep Holla | b6f20ff | 2017-06-06 11:16:15 +0100 | [diff] [blame] | 24 | |
| 25 | enum scmi_common_cmd { |
| 26 | PROTOCOL_VERSION = 0x0, |
| 27 | PROTOCOL_ATTRIBUTES = 0x1, |
| 28 | PROTOCOL_MESSAGE_ATTRIBUTES = 0x2, |
| 29 | }; |
| 30 | |
| 31 | /** |
| 32 | * struct scmi_msg_resp_prot_version - Response for a message |
| 33 | * |
| 34 | * @major_version: Major version of the ABI that firmware supports |
| 35 | * @minor_version: Minor version of the ABI that firmware supports |
| 36 | * |
| 37 | * In general, ABI version changes follow the rule that minor version increments |
| 38 | * are backward compatible. Major revision changes in ABI may not be |
| 39 | * backward compatible. |
| 40 | * |
| 41 | * Response to a generic message with message type SCMI_MSG_VERSION |
| 42 | */ |
| 43 | struct scmi_msg_resp_prot_version { |
| 44 | __le16 minor_version; |
| 45 | __le16 major_version; |
| 46 | }; |
| 47 | |
Sudeep Holla | aa4f886 | 2017-03-28 11:36:07 +0100 | [diff] [blame] | 48 | /** |
| 49 | * struct scmi_msg_hdr - Message(Tx/Rx) header |
| 50 | * |
Sudeep Holla | 5b65af8 | 2019-07-08 09:40:40 +0100 | [diff] [blame] | 51 | * @id: The identifier of the message being sent |
| 52 | * @protocol_id: The identifier of the protocol used to send @id message |
| 53 | * @seq: The token to identify the message. When a message returns, the |
| 54 | * platform returns the whole message header unmodified including the |
| 55 | * token |
Sudeep Holla | 1baf47c | 2018-05-09 17:52:06 +0100 | [diff] [blame] | 56 | * @status: Status of the transfer once it's complete |
| 57 | * @poll_completion: Indicate if the transfer needs to be polled for |
| 58 | * completion or interrupt mode is used |
Sudeep Holla | aa4f886 | 2017-03-28 11:36:07 +0100 | [diff] [blame] | 59 | */ |
| 60 | struct scmi_msg_hdr { |
| 61 | u8 id; |
| 62 | u8 protocol_id; |
| 63 | u16 seq; |
| 64 | u32 status; |
| 65 | bool poll_completion; |
| 66 | }; |
| 67 | |
| 68 | /** |
| 69 | * struct scmi_msg - Message(Tx/Rx) structure |
| 70 | * |
| 71 | * @buf: Buffer pointer |
| 72 | * @len: Length of data in the Buffer |
| 73 | */ |
| 74 | struct scmi_msg { |
| 75 | void *buf; |
| 76 | size_t len; |
| 77 | }; |
| 78 | |
| 79 | /** |
| 80 | * struct scmi_xfer - Structure representing a message flow |
| 81 | * |
| 82 | * @hdr: Transmit message header |
| 83 | * @tx: Transmit message |
| 84 | * @rx: Receive message, the buffer should be pre-allocated to store |
| 85 | * message. If request-ACK protocol is used, we can reuse the same |
| 86 | * buffer for the rx path as we use for the tx path. |
Sudeep Holla | 58ecdf0 | 2019-07-08 09:40:54 +0100 | [diff] [blame^] | 87 | * @done: command message transmit completion event |
| 88 | * @async: pointer to delayed response message received event completion |
Sudeep Holla | aa4f886 | 2017-03-28 11:36:07 +0100 | [diff] [blame] | 89 | */ |
Sudeep Holla | aa4f886 | 2017-03-28 11:36:07 +0100 | [diff] [blame] | 90 | struct scmi_xfer { |
Sudeep Holla | aa4f886 | 2017-03-28 11:36:07 +0100 | [diff] [blame] | 91 | struct scmi_msg_hdr hdr; |
| 92 | struct scmi_msg tx; |
| 93 | struct scmi_msg rx; |
| 94 | struct completion done; |
Sudeep Holla | 58ecdf0 | 2019-07-08 09:40:54 +0100 | [diff] [blame^] | 95 | struct completion *async_done; |
Sudeep Holla | aa4f886 | 2017-03-28 11:36:07 +0100 | [diff] [blame] | 96 | }; |
| 97 | |
Sudeep Holla | 14e297b | 2018-05-09 17:52:06 +0100 | [diff] [blame] | 98 | void scmi_xfer_put(const struct scmi_handle *h, struct scmi_xfer *xfer); |
Sudeep Holla | aa4f886 | 2017-03-28 11:36:07 +0100 | [diff] [blame] | 99 | int scmi_do_xfer(const struct scmi_handle *h, struct scmi_xfer *xfer); |
Sudeep Holla | 58ecdf0 | 2019-07-08 09:40:54 +0100 | [diff] [blame^] | 100 | int scmi_do_xfer_with_response(const struct scmi_handle *h, |
| 101 | struct scmi_xfer *xfer); |
Sudeep Holla | 14e297b | 2018-05-09 17:52:06 +0100 | [diff] [blame] | 102 | int scmi_xfer_get_init(const struct scmi_handle *h, u8 msg_id, u8 prot_id, |
Sudeep Holla | aa4f886 | 2017-03-28 11:36:07 +0100 | [diff] [blame] | 103 | size_t tx_size, size_t rx_size, struct scmi_xfer **p); |
| 104 | int scmi_handle_put(const struct scmi_handle *handle); |
| 105 | struct scmi_handle *scmi_handle_get(struct device *dev); |
Sudeep Holla | 933c504 | 2017-10-30 18:33:30 +0000 | [diff] [blame] | 106 | void scmi_set_handle(struct scmi_device *scmi_dev); |
Sudeep Holla | b6f20ff | 2017-06-06 11:16:15 +0100 | [diff] [blame] | 107 | int scmi_version_get(const struct scmi_handle *h, u8 protocol, u32 *version); |
| 108 | void scmi_setup_protocol_implemented(const struct scmi_handle *handle, |
| 109 | u8 *prot_imp); |
| 110 | |
| 111 | int scmi_base_protocol_init(struct scmi_handle *h); |