mhu_v3_x.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef MHU_V3_X_H
  7. #define MHU_V3_X_H
  8. #include <stdbool.h>
  9. #include <stdint.h>
  10. /* MHU Architecture Major Revision 3 */
  11. #define MHU_MAJOR_REV_V3 U(0x2)
  12. /* MHU Architecture Minor Revision 0 */
  13. #define MHU_MINOR_REV_3_0 U(0x0)
  14. /* MHU Architecture Major Revision offset */
  15. #define MHU_ARCH_MAJOR_REV_OFF U(0x4)
  16. /* MHU Architecture Major Revision mask */
  17. #define MHU_ARCH_MAJOR_REV_MASK (U(0xf) << MHU_ARCH_MAJOR_REV_OFF)
  18. /* MHU Architecture Minor Revision offset */
  19. #define MHU_ARCH_MINOR_REV_OFF U(0x0)
  20. /* MHU Architecture Minor Revision mask */
  21. #define MHU_ARCH_MINOR_REV_MASK (U(0xf) << MHU_ARCH_MINOR_REV_OFF)
  22. /* MHUv3 PBX/MBX Operational Request offset */
  23. #define MHU_V3_OP_REQ_OFF U(0)
  24. /* MHUv3 PBX/MBX Operational Request */
  25. #define MHU_V3_OP_REQ (U(1) << MHU_V3_OP_REQ_OFF)
  26. /**
  27. * MHUv3 error enumeration types
  28. */
  29. enum mhu_v3_x_error_t {
  30. /* No error */
  31. MHU_V_3_X_ERR_NONE,
  32. /* MHU driver not initialized */
  33. MHU_V_3_X_ERR_NOT_INIT,
  34. /* MHU driver alreary initialized */
  35. MHU_V_3_X_ERR_ALREADY_INIT,
  36. /* MHU Revision not supported error */
  37. MHU_V_3_X_ERR_UNSUPPORTED_VERSION,
  38. /* Operation not supported */
  39. MHU_V_3_X_ERR_UNSUPPORTED,
  40. /* Invalid parameter */
  41. MHU_V_3_X_ERR_INVALID_PARAM,
  42. /* General MHU driver error */
  43. MHU_V_3_X_ERR_GENERAL,
  44. };
  45. /**
  46. * MHUv3 channel types
  47. */
  48. enum mhu_v3_x_channel_type_t {
  49. /* Doorbell channel */
  50. MHU_V3_X_CHANNEL_TYPE_DBCH,
  51. /* Channel type count */
  52. MHU_V3_X_CHANNEL_TYPE_COUNT,
  53. };
  54. /**
  55. * MHUv3 frame types
  56. */
  57. enum mhu_v3_x_frame_t {
  58. /* MHUv3 postbox frame */
  59. MHU_V3_X_PBX_FRAME,
  60. /* MHUv3 mailbox frame */
  61. MHU_V3_X_MBX_FRAME,
  62. };
  63. /**
  64. * MHUv3 device structure
  65. */
  66. struct mhu_v3_x_dev_t {
  67. /* Base address of the MHUv3 frame */
  68. uintptr_t base;
  69. /* Type of the MHUv3 frame */
  70. enum mhu_v3_x_frame_t frame;
  71. /* Minor revision of the MHUv3 */
  72. uint32_t subversion;
  73. /* Flag to indicate if the MHUv3 is initialized */
  74. bool is_initialized;
  75. };
  76. /**
  77. * Initializes the MHUv3
  78. *
  79. * dev MHU device struct mhu_v3_x_dev_t
  80. *
  81. * Returns mhu_v3_x_error_t error code
  82. */
  83. enum mhu_v3_x_error_t mhu_v3_x_driver_init(struct mhu_v3_x_dev_t *dev);
  84. /**
  85. * Returns the number of channels implemented
  86. *
  87. * dev MHU device struct mhu_v3_x_dev_t
  88. * ch_type MHU channel type mhu_v3_x_channel_type_t
  89. * num_ch Pointer to the variable that will store the value
  90. *
  91. * Returns mhu_v3_x_error_t error code
  92. */
  93. enum mhu_v3_x_error_t mhu_v3_x_get_num_channel_implemented(
  94. const struct mhu_v3_x_dev_t *dev, enum mhu_v3_x_channel_type_t ch_type,
  95. uint8_t *num_ch);
  96. /**
  97. * Clear flags from a doorbell channel
  98. *
  99. * dev MHU device struct mhu_v3_x_dev_t
  100. * channel Doorbell channel number
  101. * flags Flags to be cleared from the channel
  102. *
  103. * Returns mhu_v3_x_error_t error code
  104. */
  105. enum mhu_v3_x_error_t mhu_v3_x_doorbell_clear(const struct mhu_v3_x_dev_t *dev,
  106. const uint32_t channel, uint32_t flags);
  107. /**
  108. * Write flags to a doorbell channel
  109. *
  110. * dev MHU device struct mhu_v3_x_dev_t
  111. * channel Doorbell channel number
  112. * flags Flags to be written to the channel
  113. *
  114. * Returns mhu_v3_x_error_t error code
  115. */
  116. enum mhu_v3_x_error_t mhu_v3_x_doorbell_write(const struct mhu_v3_x_dev_t *dev,
  117. const uint32_t channel, uint32_t flags);
  118. /**
  119. * Read value from a doorbell channel
  120. *
  121. * dev MHU device struct mhu_v3_x_dev_t
  122. * channel Doorbell channel number
  123. * flags Pointer to the variable that will store the flags read from the
  124. * channel
  125. *
  126. * Returns mhu_v3_x_error_t error code
  127. */
  128. enum mhu_v3_x_error_t mhu_v3_x_doorbell_read(const struct mhu_v3_x_dev_t *dev,
  129. const uint32_t channel, uint32_t *flags);
  130. /**
  131. * Set bits in a doorbell channel mask which is used to disable interrupts for
  132. * received flags corresponding to the mask
  133. *
  134. * dev MHU device struct mhu_v3_x_dev_t
  135. * channel Doorbell channel number
  136. * flags Flags to set mask bits in this doorbell channel
  137. *
  138. * Returns mhu_v3_x_error_t error code
  139. */
  140. enum mhu_v3_x_error_t mhu_v3_x_doorbell_mask_set(
  141. const struct mhu_v3_x_dev_t *dev, const uint32_t channel,
  142. uint32_t flags);
  143. /**
  144. * Clear bits in a doorbell channel mask which is used to disable interrupts
  145. * for received flags corresponding to the mask
  146. *
  147. * dev MHU device struct mhu_v3_x_dev_t
  148. * channel Doorbell channel number
  149. * flags Flags to clear mask bits in this doorbell channel
  150. *
  151. * Returns mhu_v3_x_error_t error code
  152. */
  153. enum mhu_v3_x_error_t mhu_v3_x_doorbell_mask_clear(
  154. const struct mhu_v3_x_dev_t *dev, const uint32_t channel, uint32_t flags);
  155. /**
  156. * Get the mask of a doorbell channel which is used to disable interrupts for
  157. * received flags corresponding to the mask
  158. *
  159. * dev MHU device struct mhu_v3_x_dev_t
  160. * channel Doorbell channel number
  161. * flags Pointer to the variable that will store the flags read from the
  162. * mask value
  163. *
  164. * Returns mhu_v3_x_error_t error code
  165. */
  166. enum mhu_v3_x_error_t mhu_v3_x_doorbell_mask_get(
  167. const struct mhu_v3_x_dev_t *dev, const uint32_t channel, uint32_t *flags);
  168. /**
  169. * Enable the channel interrupt
  170. *
  171. * dev MHU device struct mhu_v3_x_dev_t
  172. * channel Doorbell channel number
  173. * ch_type MHU channel type mhu_v3_x_channel_type_t
  174. *
  175. * Returns mhu_v3_x_error_t error code
  176. */
  177. enum mhu_v3_x_error_t mhu_v3_x_channel_interrupt_enable(
  178. const struct mhu_v3_x_dev_t *dev, const uint32_t channel,
  179. enum mhu_v3_x_channel_type_t ch_type);
  180. /**
  181. * Disable the channel interrupt
  182. *
  183. * dev MHU device struct mhu_v3_x_dev_t
  184. * channel Doorbell channel number
  185. * ch_type MHU channel type mhu_v3_x_channel_type_t
  186. *
  187. * Returns mhu_v3_x_error_t error code
  188. */
  189. enum mhu_v3_x_error_t mhu_v3_x_channel_interrupt_disable(
  190. const struct mhu_v3_x_dev_t *dev, const uint32_t channel,
  191. enum mhu_v3_x_channel_type_t ch_type);
  192. /**
  193. * Clear the channel interrupt
  194. *
  195. * dev MHU device struct mhu_v3_x_dev_t
  196. * channel Doorbell channel number
  197. * ch_type MHU channel type mhu_v3_x_channel_type_t
  198. *
  199. * Returns mhu_v3_x_error_t error code
  200. */
  201. enum mhu_v3_x_error_t mhu_v3_x_channel_interrupt_clear(
  202. const struct mhu_v3_x_dev_t *dev, const uint32_t channel,
  203. enum mhu_v3_x_channel_type_t ch_type);
  204. #endif /* MHU_V3_X_H */