common.h 3.1 KB

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