scmi_private.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef SCMI_PRIVATE_H
  7. #define SCMI_PRIVATE_H
  8. #include <lib/mmio.h>
  9. /*
  10. * SCMI power domain management protocol message and response lengths. It is
  11. * calculated as sum of length in bytes of the message header (4) and payload
  12. * area (the number of bytes of parameters or return values in the payload).
  13. */
  14. #define SCMI_PROTO_VERSION_MSG_LEN 4
  15. #define SCMI_PROTO_VERSION_RESP_LEN 12
  16. #define SCMI_PROTO_MSG_ATTR_MSG_LEN 8
  17. #define SCMI_PROTO_MSG_ATTR_RESP_LEN 12
  18. #define SCMI_AP_CORE_RESET_ADDR_SET_MSG_LEN 16
  19. #define SCMI_AP_CORE_RESET_ADDR_SET_RESP_LEN 8
  20. #define SCMI_AP_CORE_RESET_ADDR_GET_MSG_LEN 4
  21. #define SCMI_AP_CORE_RESET_ADDR_GET_RESP_LEN 20
  22. #define SCMI_PWR_STATE_SET_MSG_LEN 16
  23. #define SCMI_PWR_STATE_SET_RESP_LEN 8
  24. #define SCMI_PWR_STATE_GET_MSG_LEN 8
  25. #define SCMI_PWR_STATE_GET_RESP_LEN 12
  26. #define SCMI_SYS_PWR_STATE_SET_MSG_LEN 12
  27. #define SCMI_SYS_PWR_STATE_SET_RESP_LEN 8
  28. #define SCMI_SYS_PWR_STATE_GET_MSG_LEN 4
  29. #define SCMI_SYS_PWR_STATE_GET_RESP_LEN 12
  30. /* SCMI message header format bit field */
  31. #define SCMI_MSG_ID_SHIFT 0
  32. #define SCMI_MSG_ID_WIDTH 8
  33. #define SCMI_MSG_ID_MASK ((1 << SCMI_MSG_ID_WIDTH) - 1)
  34. #define SCMI_MSG_TYPE_SHIFT 8
  35. #define SCMI_MSG_TYPE_WIDTH 2
  36. #define SCMI_MSG_TYPE_MASK ((1 << SCMI_MSG_TYPE_WIDTH) - 1)
  37. #define SCMI_MSG_PROTO_ID_SHIFT 10
  38. #define SCMI_MSG_PROTO_ID_WIDTH 8
  39. #define SCMI_MSG_PROTO_ID_MASK ((1 << SCMI_MSG_PROTO_ID_WIDTH) - 1)
  40. #define SCMI_MSG_TOKEN_SHIFT 18
  41. #define SCMI_MSG_TOKEN_WIDTH 10
  42. #define SCMI_MSG_TOKEN_MASK ((1 << SCMI_MSG_TOKEN_WIDTH) - 1)
  43. /* SCMI mailbox flags */
  44. #define SCMI_FLAG_RESP_POLL 0
  45. #define SCMI_FLAG_RESP_INT 1
  46. /* SCMI power domain protocol `POWER_STATE_SET` message flags */
  47. #define SCMI_PWR_STATE_SET_FLAG_SYNC 0
  48. #define SCMI_PWR_STATE_SET_FLAG_ASYNC 1
  49. /*
  50. * Helper macro to create an SCMI message header given protocol, message id
  51. * and token.
  52. */
  53. #define SCMI_MSG_CREATE(_protocol, _msg_id, _token) \
  54. ((((_protocol) & SCMI_MSG_PROTO_ID_MASK) << SCMI_MSG_PROTO_ID_SHIFT) | \
  55. (((_msg_id) & SCMI_MSG_ID_MASK) << SCMI_MSG_ID_SHIFT) | \
  56. (((_token) & SCMI_MSG_TOKEN_MASK) << SCMI_MSG_TOKEN_SHIFT))
  57. /* Helper macro to get the token from a SCMI message header */
  58. #define SCMI_MSG_GET_TOKEN(_msg) \
  59. (((_msg) >> SCMI_MSG_TOKEN_SHIFT) & SCMI_MSG_TOKEN_MASK)
  60. /* SCMI Channel Status bit fields */
  61. #define SCMI_CH_STATUS_RES0_MASK 0xFFFFFFFE
  62. #define SCMI_CH_STATUS_FREE_SHIFT 0
  63. #define SCMI_CH_STATUS_FREE_WIDTH 1
  64. #define SCMI_CH_STATUS_FREE_MASK ((1 << SCMI_CH_STATUS_FREE_WIDTH) - 1)
  65. /* Helper macros to check and write the channel status */
  66. #define SCMI_IS_CHANNEL_FREE(status) \
  67. (!!(((status) >> SCMI_CH_STATUS_FREE_SHIFT) & SCMI_CH_STATUS_FREE_MASK))
  68. #define SCMI_MARK_CHANNEL_BUSY(status) do { \
  69. assert(SCMI_IS_CHANNEL_FREE(status)); \
  70. (status) &= ~(SCMI_CH_STATUS_FREE_MASK << \
  71. SCMI_CH_STATUS_FREE_SHIFT); \
  72. } while (0)
  73. /* Helper macros to copy arguments to the mailbox payload */
  74. #define SCMI_PAYLOAD_ARG1(payld_arr, arg1) \
  75. mmio_write_32((uintptr_t)&payld_arr[0], arg1)
  76. #define SCMI_PAYLOAD_ARG2(payld_arr, arg1, arg2) do { \
  77. SCMI_PAYLOAD_ARG1(payld_arr, arg1); \
  78. mmio_write_32((uintptr_t)&payld_arr[1], arg2); \
  79. } while (0)
  80. #define SCMI_PAYLOAD_ARG3(payld_arr, arg1, arg2, arg3) do { \
  81. SCMI_PAYLOAD_ARG2(payld_arr, arg1, arg2); \
  82. mmio_write_32((uintptr_t)&payld_arr[2], arg3); \
  83. } while (0)
  84. /* Helper macros to read return values from the mailbox payload */
  85. #define SCMI_PAYLOAD_RET_VAL1(payld_arr, val1) \
  86. (val1) = mmio_read_32((uintptr_t)&payld_arr[0])
  87. #define SCMI_PAYLOAD_RET_VAL2(payld_arr, val1, val2) do { \
  88. SCMI_PAYLOAD_RET_VAL1(payld_arr, val1); \
  89. (val2) = mmio_read_32((uintptr_t)&payld_arr[1]); \
  90. } while (0)
  91. #define SCMI_PAYLOAD_RET_VAL3(payld_arr, val1, val2, val3) do { \
  92. SCMI_PAYLOAD_RET_VAL2(payld_arr, val1, val2); \
  93. (val3) = mmio_read_32((uintptr_t)&payld_arr[2]); \
  94. } while (0)
  95. #define SCMI_PAYLOAD_RET_VAL4(payld_arr, val1, val2, val3, val4) do { \
  96. SCMI_PAYLOAD_RET_VAL3(payld_arr, val1, val2, val3); \
  97. (val4) = mmio_read_32((uintptr_t)&payld_arr[3]); \
  98. } while (0)
  99. /*
  100. * Private data structure for representing the mailbox memory layout. Refer
  101. * the SCMI specification for more details.
  102. */
  103. typedef struct mailbox_mem {
  104. uint32_t res_a; /* Reserved */
  105. volatile uint32_t status;
  106. uint64_t res_b; /* Reserved */
  107. uint32_t flags;
  108. volatile uint32_t len;
  109. volatile uint32_t msg_header;
  110. uint32_t payload[];
  111. } mailbox_mem_t;
  112. /* Private APIs for use within SCMI driver */
  113. void scmi_get_channel(scmi_channel_t *ch);
  114. void scmi_send_sync_command(scmi_channel_t *ch);
  115. void scmi_put_channel(scmi_channel_t *ch);
  116. static inline void validate_scmi_channel(scmi_channel_t *ch)
  117. {
  118. assert(ch && ch->is_initialized);
  119. assert(ch->info && ch->info->scmi_mbx_mem);
  120. }
  121. /*
  122. * SCMI vendor specific protocol
  123. */
  124. #define SCMI_SYS_VENDOR_EXT_PROTO_ID 0x80
  125. #endif /* SCMI_PRIVATE_H */