bpmp.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. */
  13. #ifndef __SOC_TEGRA_BPMP_H
  14. #define __SOC_TEGRA_BPMP_H
  15. #include <linux/mailbox_client.h>
  16. #include <linux/pm_domain.h>
  17. #include <linux/reset-controller.h>
  18. #include <linux/semaphore.h>
  19. #include <linux/types.h>
  20. #include <soc/tegra/bpmp-abi.h>
  21. struct tegra_bpmp_clk;
  22. struct tegra_bpmp_soc {
  23. struct {
  24. struct {
  25. unsigned int offset;
  26. unsigned int count;
  27. unsigned int timeout;
  28. } cpu_tx, thread, cpu_rx;
  29. } channels;
  30. unsigned int num_resets;
  31. };
  32. struct tegra_bpmp_mb_data {
  33. u32 code;
  34. u32 flags;
  35. u8 data[MSG_DATA_MIN_SZ];
  36. } __packed;
  37. struct tegra_bpmp_channel {
  38. struct tegra_bpmp *bpmp;
  39. struct tegra_bpmp_mb_data *ib;
  40. struct tegra_bpmp_mb_data *ob;
  41. struct completion completion;
  42. struct tegra_ivc *ivc;
  43. };
  44. typedef void (*tegra_bpmp_mrq_handler_t)(unsigned int mrq,
  45. struct tegra_bpmp_channel *channel,
  46. void *data);
  47. struct tegra_bpmp_mrq {
  48. struct list_head list;
  49. unsigned int mrq;
  50. tegra_bpmp_mrq_handler_t handler;
  51. void *data;
  52. };
  53. struct tegra_bpmp {
  54. const struct tegra_bpmp_soc *soc;
  55. struct device *dev;
  56. struct {
  57. struct gen_pool *pool;
  58. dma_addr_t phys;
  59. void *virt;
  60. } tx, rx;
  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. };
  83. struct tegra_bpmp_message {
  84. unsigned int mrq;
  85. struct {
  86. const void *data;
  87. size_t size;
  88. } tx;
  89. struct {
  90. void *data;
  91. size_t size;
  92. int ret;
  93. } rx;
  94. };
  95. #if IS_ENABLED(CONFIG_TEGRA_BPMP)
  96. struct tegra_bpmp *tegra_bpmp_get(struct device *dev);
  97. void tegra_bpmp_put(struct tegra_bpmp *bpmp);
  98. int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
  99. struct tegra_bpmp_message *msg);
  100. int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
  101. struct tegra_bpmp_message *msg);
  102. void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel, int code,
  103. const void *data, size_t size);
  104. int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
  105. tegra_bpmp_mrq_handler_t handler, void *data);
  106. void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
  107. void *data);
  108. #else
  109. static inline struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
  110. {
  111. return ERR_PTR(-ENOTSUPP);
  112. }
  113. static inline void tegra_bpmp_put(struct tegra_bpmp *bpmp)
  114. {
  115. }
  116. static inline int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
  117. struct tegra_bpmp_message *msg)
  118. {
  119. return -ENOTSUPP;
  120. }
  121. static inline int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
  122. struct tegra_bpmp_message *msg)
  123. {
  124. return -ENOTSUPP;
  125. }
  126. static inline void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel,
  127. int code, const void *data,
  128. size_t size)
  129. {
  130. }
  131. static inline int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp,
  132. unsigned int mrq,
  133. tegra_bpmp_mrq_handler_t handler,
  134. void *data)
  135. {
  136. return -ENOTSUPP;
  137. }
  138. static inline void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp,
  139. unsigned int mrq, void *data)
  140. {
  141. }
  142. #endif
  143. #if IS_ENABLED(CONFIG_CLK_TEGRA_BPMP)
  144. int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp);
  145. #else
  146. static inline int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp)
  147. {
  148. return 0;
  149. }
  150. #endif
  151. #if IS_ENABLED(CONFIG_RESET_TEGRA_BPMP)
  152. int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp);
  153. #else
  154. static inline int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
  155. {
  156. return 0;
  157. }
  158. #endif
  159. #if IS_ENABLED(CONFIG_SOC_TEGRA_POWERGATE_BPMP)
  160. int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp);
  161. #else
  162. static inline int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp)
  163. {
  164. return 0;
  165. }
  166. #endif
  167. #if IS_ENABLED(CONFIG_DEBUG_FS)
  168. int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp);
  169. #else
  170. static inline int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp)
  171. {
  172. return 0;
  173. }
  174. #endif
  175. #endif /* __SOC_TEGRA_BPMP_H */