smt.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
  4. * Copyright (C) 2019-2022 Linaro Limited.
  5. */
  6. #ifndef SCMI_SMT_H
  7. #define SCMI_SMT_H
  8. #include <asm/types.h>
  9. /**
  10. * struct scmi_smt_header - Description of the shared memory message buffer
  11. *
  12. * SMT stands for Shared Memory based Transport.
  13. * SMT uses 28 byte header prior message payload to handle the state of
  14. * the communication channel realized by the shared memory area and
  15. * to define SCMI protocol information the payload relates to.
  16. */
  17. struct scmi_smt_header {
  18. __le32 reserved;
  19. __le32 channel_status;
  20. #define SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR BIT(1)
  21. #define SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE BIT(0)
  22. __le32 reserved1[2];
  23. __le32 flags;
  24. #define SCMI_SHMEM_FLAG_INTR_ENABLED BIT(0)
  25. __le32 length;
  26. __le32 msg_header;
  27. u8 msg_payload[0];
  28. };
  29. /**
  30. * struct scmi_msg_header - Description of a MSG shared memory message buffer
  31. *
  32. * MSG communication protocol uses a 32bit header memory cell to store SCMI
  33. * protocol data followed by the exchange SCMI message payload.
  34. */
  35. struct scmi_smt_msg_header {
  36. __le32 msg_header;
  37. u8 msg_payload[0];
  38. };
  39. #define SMT_HEADER_TOKEN(token) (((token) << 18) & GENMASK(31, 18))
  40. #define SMT_HEADER_PROTOCOL_ID(proto) (((proto) << 10) & GENMASK(17, 10))
  41. #define SMT_HEADER_MESSAGE_TYPE(type) (((type) << 18) & GENMASK(9, 8))
  42. #define SMT_HEADER_MESSAGE_ID(id) ((id) & GENMASK(7, 0))
  43. /**
  44. * struct scmi_smt - Description of a SMT memory buffer
  45. * @buf: Shared memory base address
  46. * @size: Shared memory byte size
  47. */
  48. struct scmi_smt {
  49. u8 *buf;
  50. size_t size;
  51. };
  52. static inline bool scmi_smt_channel_is_free(struct scmi_smt *smt)
  53. {
  54. struct scmi_smt_header *hdr = (void *)smt->buf;
  55. return hdr->channel_status & SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE;
  56. }
  57. static inline bool scmi_smt_channel_reports_error(struct scmi_smt *smt)
  58. {
  59. struct scmi_smt_header *hdr = (void *)smt->buf;
  60. return hdr->channel_status & SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR;
  61. }
  62. static inline void scmi_smt_get_channel(struct scmi_smt *smt)
  63. {
  64. struct scmi_smt_header *hdr = (void *)smt->buf;
  65. hdr->channel_status &= ~SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE;
  66. }
  67. static inline void scmi_smt_put_channel(struct scmi_smt *smt)
  68. {
  69. struct scmi_smt_header *hdr = (void *)smt->buf;
  70. hdr->channel_status |= SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE;
  71. hdr->channel_status &= ~SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR;
  72. }
  73. int scmi_dt_get_smt_buffer(struct udevice *dev, struct scmi_smt *smt);
  74. /*
  75. * Write SCMI message to a SMT shared memory
  76. * @dev: SCMI device
  77. * @smt: Reference to shared memory using SMT header
  78. * @msg: Input SCMI message transmitted
  79. */
  80. int scmi_write_msg_to_smt(struct udevice *dev, struct scmi_smt *smt,
  81. struct scmi_msg *msg);
  82. /*
  83. * Read SCMI message from a SMT shared memory
  84. * @dev: SCMI device
  85. * @smt: Reference to shared memory using SMT header
  86. * @msg: Output SCMI message received
  87. */
  88. int scmi_read_resp_from_smt(struct udevice *dev, struct scmi_smt *smt,
  89. struct scmi_msg *msg);
  90. void scmi_clear_smt_channel(struct scmi_smt *smt);
  91. /*
  92. * Write SCMI message to SMT_MSG shared memory
  93. * @dev: SCMI device
  94. * @smt: Reference to shared memory using SMT_MSG header
  95. * @msg: Input SCMI message transmitted
  96. * @buf_size: Size of the full SMT_MSG buffer transmitted
  97. */
  98. int scmi_msg_to_smt_msg(struct udevice *dev, struct scmi_smt *smt,
  99. struct scmi_msg *msg, size_t *buf_size);
  100. /*
  101. * Read SCMI message from SMT_MSG shared memory
  102. * @dev: SCMI device
  103. * @smt: Reference to shared memory using SMT_MSG header
  104. * @msg: Output SCMI message received
  105. * @buf_size: Size of the full SMT_MSG buffer received
  106. */
  107. int scmi_msg_from_smt_msg(struct udevice *dev, struct scmi_smt *smt,
  108. struct scmi_msg *msg, size_t buf_size);
  109. #endif /* SCMI_SMT_H */