bpmp.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
  4. */
  5. #ifndef __SOC_TEGRA_BPMP_H
  6. #define __SOC_TEGRA_BPMP_H
  7. #include <linux/iosys-map.h>
  8. #include <linux/mailbox_client.h>
  9. #include <linux/pm_domain.h>
  10. #include <linux/reset-controller.h>
  11. #include <linux/semaphore.h>
  12. #include <linux/types.h>
  13. #include <soc/tegra/bpmp-abi.h>
  14. struct tegra_bpmp_clk;
  15. struct tegra_bpmp_ops;
  16. struct tegra_bpmp_soc {
  17. struct {
  18. struct {
  19. unsigned int offset;
  20. unsigned int count;
  21. unsigned int timeout;
  22. } cpu_tx, thread, cpu_rx;
  23. } channels;
  24. const struct tegra_bpmp_ops *ops;
  25. unsigned int num_resets;
  26. };
  27. struct tegra_bpmp_mb_data {
  28. u32 code;
  29. u32 flags;
  30. u8 data[MSG_DATA_MIN_SZ];
  31. } __packed;
  32. #define tegra_bpmp_mb_read(dst, mb, size) \
  33. iosys_map_memcpy_from(dst, mb, offsetof(struct tegra_bpmp_mb_data, data), size)
  34. #define tegra_bpmp_mb_write(mb, src, size) \
  35. iosys_map_memcpy_to(mb, offsetof(struct tegra_bpmp_mb_data, data), src, size)
  36. #define tegra_bpmp_mb_read_field(mb, field) \
  37. iosys_map_rd_field(mb, 0, struct tegra_bpmp_mb_data, field)
  38. #define tegra_bpmp_mb_write_field(mb, field, value) \
  39. iosys_map_wr_field(mb, 0, struct tegra_bpmp_mb_data, field, value)
  40. struct tegra_bpmp_channel {
  41. struct tegra_bpmp *bpmp;
  42. struct iosys_map ib;
  43. struct iosys_map ob;
  44. struct completion completion;
  45. struct tegra_ivc *ivc;
  46. unsigned int index;
  47. };
  48. typedef void (*tegra_bpmp_mrq_handler_t)(unsigned int mrq,
  49. struct tegra_bpmp_channel *channel,
  50. void *data);
  51. struct tegra_bpmp_mrq {
  52. struct list_head list;
  53. unsigned int mrq;
  54. tegra_bpmp_mrq_handler_t handler;
  55. void *data;
  56. };
  57. struct tegra_bpmp {
  58. const struct tegra_bpmp_soc *soc;
  59. struct device *dev;
  60. void *priv;
  61. struct {
  62. struct mbox_client client;
  63. struct mbox_chan *channel;
  64. } mbox;
  65. spinlock_t atomic_tx_lock;
  66. struct tegra_bpmp_channel *tx_channel, *rx_channel, *threaded_channels;
  67. struct {
  68. unsigned long *allocated;
  69. unsigned long *busy;
  70. unsigned int count;
  71. struct semaphore lock;
  72. } threaded;
  73. struct list_head mrqs;
  74. spinlock_t lock;
  75. struct tegra_bpmp_clk **clocks;
  76. unsigned int num_clocks;
  77. struct reset_controller_dev rstc;
  78. struct genpd_onecell_data genpd;
  79. #ifdef CONFIG_DEBUG_FS
  80. struct dentry *debugfs_mirror;
  81. #endif
  82. bool suspended;
  83. };
  84. #define TEGRA_BPMP_MESSAGE_RESET BIT(0)
  85. struct tegra_bpmp_message {
  86. unsigned int mrq;
  87. struct {
  88. const void *data;
  89. size_t size;
  90. } tx;
  91. struct {
  92. void *data;
  93. size_t size;
  94. int ret;
  95. } rx;
  96. unsigned long flags;
  97. };
  98. #if IS_ENABLED(CONFIG_TEGRA_BPMP)
  99. struct tegra_bpmp *tegra_bpmp_get(struct device *dev);
  100. void tegra_bpmp_put(struct tegra_bpmp *bpmp);
  101. int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
  102. struct tegra_bpmp_message *msg);
  103. int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
  104. struct tegra_bpmp_message *msg);
  105. void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel, int code,
  106. const void *data, size_t size);
  107. int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
  108. tegra_bpmp_mrq_handler_t handler, void *data);
  109. void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
  110. void *data);
  111. bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp, unsigned int mrq);
  112. #else
  113. static inline struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
  114. {
  115. return ERR_PTR(-ENOTSUPP);
  116. }
  117. static inline void tegra_bpmp_put(struct tegra_bpmp *bpmp)
  118. {
  119. }
  120. static inline int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
  121. struct tegra_bpmp_message *msg)
  122. {
  123. return -ENOTSUPP;
  124. }
  125. static inline int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
  126. struct tegra_bpmp_message *msg)
  127. {
  128. return -ENOTSUPP;
  129. }
  130. static inline void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel,
  131. int code, const void *data,
  132. size_t size)
  133. {
  134. }
  135. static inline int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp,
  136. unsigned int mrq,
  137. tegra_bpmp_mrq_handler_t handler,
  138. void *data)
  139. {
  140. return -ENOTSUPP;
  141. }
  142. static inline void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp,
  143. unsigned int mrq, void *data)
  144. {
  145. }
  146. static inline bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp,
  147. unsigned int mrq)
  148. {
  149. return false;
  150. }
  151. #endif
  152. void tegra_bpmp_handle_rx(struct tegra_bpmp *bpmp);
  153. #if IS_ENABLED(CONFIG_CLK_TEGRA_BPMP)
  154. int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp);
  155. #else
  156. static inline int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp)
  157. {
  158. return 0;
  159. }
  160. #endif
  161. #if IS_ENABLED(CONFIG_RESET_TEGRA_BPMP)
  162. int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp);
  163. #else
  164. static inline int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
  165. {
  166. return 0;
  167. }
  168. #endif
  169. #if IS_ENABLED(CONFIG_SOC_TEGRA_POWERGATE_BPMP)
  170. int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp);
  171. #else
  172. static inline int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp)
  173. {
  174. return 0;
  175. }
  176. #endif
  177. #if IS_ENABLED(CONFIG_DEBUG_FS)
  178. int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp);
  179. #else
  180. static inline int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp)
  181. {
  182. return 0;
  183. }
  184. #endif
  185. #endif /* __SOC_TEGRA_BPMP_H */