bpmp.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. struct tegra_bpmp_channel *channels;
  66. unsigned int num_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. };
  80. struct tegra_bpmp_message {
  81. unsigned int mrq;
  82. struct {
  83. const void *data;
  84. size_t size;
  85. } tx;
  86. struct {
  87. void *data;
  88. size_t size;
  89. int ret;
  90. } rx;
  91. };
  92. #if IS_ENABLED(CONFIG_TEGRA_BPMP)
  93. struct tegra_bpmp *tegra_bpmp_get(struct device *dev);
  94. void tegra_bpmp_put(struct tegra_bpmp *bpmp);
  95. int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
  96. struct tegra_bpmp_message *msg);
  97. int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
  98. struct tegra_bpmp_message *msg);
  99. void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel, int code,
  100. const void *data, size_t size);
  101. int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
  102. tegra_bpmp_mrq_handler_t handler, void *data);
  103. void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
  104. void *data);
  105. #else
  106. static inline struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
  107. {
  108. return ERR_PTR(-ENOTSUPP);
  109. }
  110. static inline void tegra_bpmp_put(struct tegra_bpmp *bpmp)
  111. {
  112. }
  113. static inline int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
  114. struct tegra_bpmp_message *msg)
  115. {
  116. return -ENOTSUPP;
  117. }
  118. static inline int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
  119. struct tegra_bpmp_message *msg)
  120. {
  121. return -ENOTSUPP;
  122. }
  123. static inline void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel,
  124. int code, const void *data,
  125. size_t size)
  126. {
  127. }
  128. static inline int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp,
  129. unsigned int mrq,
  130. tegra_bpmp_mrq_handler_t handler,
  131. void *data)
  132. {
  133. return -ENOTSUPP;
  134. }
  135. static inline void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp,
  136. unsigned int mrq, void *data)
  137. {
  138. }
  139. #endif
  140. #if IS_ENABLED(CONFIG_CLK_TEGRA_BPMP)
  141. int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp);
  142. #else
  143. static inline int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp)
  144. {
  145. return 0;
  146. }
  147. #endif
  148. #if IS_ENABLED(CONFIG_RESET_TEGRA_BPMP)
  149. int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp);
  150. #else
  151. static inline int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
  152. {
  153. return 0;
  154. }
  155. #endif
  156. #if IS_ENABLED(CONFIG_SOC_TEGRA_POWERGATE_BPMP)
  157. int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp);
  158. #else
  159. static inline int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp)
  160. {
  161. return 0;
  162. }
  163. #endif
  164. #endif /* __SOC_TEGRA_BPMP_H */