bpmp.h 4.4 KB

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