bpmp.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 *tegra_bpmp_get(struct device *dev);
  81. void tegra_bpmp_put(struct tegra_bpmp *bpmp);
  82. struct tegra_bpmp_message {
  83. unsigned int mrq;
  84. struct {
  85. const void *data;
  86. size_t size;
  87. } tx;
  88. struct {
  89. void *data;
  90. size_t size;
  91. } rx;
  92. };
  93. int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
  94. struct tegra_bpmp_message *msg);
  95. int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
  96. struct tegra_bpmp_message *msg);
  97. int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
  98. tegra_bpmp_mrq_handler_t handler, void *data);
  99. void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
  100. void *data);
  101. #if IS_ENABLED(CONFIG_CLK_TEGRA_BPMP)
  102. int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp);
  103. #else
  104. static inline int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp)
  105. {
  106. return 0;
  107. }
  108. #endif
  109. #if IS_ENABLED(CONFIG_RESET_TEGRA_BPMP)
  110. int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp);
  111. #else
  112. static inline int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
  113. {
  114. return 0;
  115. }
  116. #endif
  117. #if IS_ENABLED(CONFIG_SOC_TEGRA_POWERGATE_BPMP)
  118. int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp);
  119. #else
  120. static inline int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp)
  121. {
  122. return 0;
  123. }
  124. #endif
  125. #endif /* __SOC_TEGRA_BPMP_H */