bpmp.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/reset-controller.h>
  17. #include <linux/semaphore.h>
  18. #include <linux/types.h>
  19. #include <soc/tegra/bpmp-abi.h>
  20. struct tegra_bpmp_clk;
  21. struct tegra_bpmp_soc {
  22. struct {
  23. struct {
  24. unsigned int offset;
  25. unsigned int count;
  26. unsigned int timeout;
  27. } cpu_tx, thread, cpu_rx;
  28. } channels;
  29. unsigned int num_resets;
  30. };
  31. struct tegra_bpmp_mb_data {
  32. u32 code;
  33. u32 flags;
  34. u8 data[MSG_DATA_MIN_SZ];
  35. } __packed;
  36. struct tegra_bpmp_channel {
  37. struct tegra_bpmp *bpmp;
  38. struct tegra_bpmp_mb_data *ib;
  39. struct tegra_bpmp_mb_data *ob;
  40. struct completion completion;
  41. struct tegra_ivc *ivc;
  42. };
  43. typedef void (*tegra_bpmp_mrq_handler_t)(unsigned int mrq,
  44. struct tegra_bpmp_channel *channel,
  45. void *data);
  46. struct tegra_bpmp_mrq {
  47. struct list_head list;
  48. unsigned int mrq;
  49. tegra_bpmp_mrq_handler_t handler;
  50. void *data;
  51. };
  52. struct tegra_bpmp {
  53. const struct tegra_bpmp_soc *soc;
  54. struct device *dev;
  55. struct {
  56. struct gen_pool *pool;
  57. dma_addr_t phys;
  58. void *virt;
  59. } tx, rx;
  60. struct {
  61. struct mbox_client client;
  62. struct mbox_chan *channel;
  63. } mbox;
  64. struct tegra_bpmp_channel *channels;
  65. unsigned int num_channels;
  66. struct {
  67. unsigned long *allocated;
  68. unsigned long *busy;
  69. unsigned int count;
  70. struct semaphore lock;
  71. } threaded;
  72. struct list_head mrqs;
  73. spinlock_t lock;
  74. struct tegra_bpmp_clk **clocks;
  75. unsigned int num_clocks;
  76. struct reset_controller_dev rstc;
  77. };
  78. struct tegra_bpmp *tegra_bpmp_get(struct device *dev);
  79. void tegra_bpmp_put(struct tegra_bpmp *bpmp);
  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. } rx;
  90. };
  91. int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
  92. struct tegra_bpmp_message *msg);
  93. int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
  94. struct tegra_bpmp_message *msg);
  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. #if IS_ENABLED(CONFIG_CLK_TEGRA_BPMP)
  100. int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp);
  101. #else
  102. static inline int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp)
  103. {
  104. return 0;
  105. }
  106. #endif
  107. #if IS_ENABLED(CONFIG_RESET_TEGRA_BPMP)
  108. int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp);
  109. #else
  110. static inline int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
  111. {
  112. return 0;
  113. }
  114. #endif
  115. #endif /* __SOC_TEGRA_BPMP_H */