root/drivers/firmware/arm_scmi/common.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


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

/* [<][>][^][v][top][bottom][index][help] */