common.h 3.3 KB

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