mc.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2014 NVIDIA Corporation
  4. */
  5. #ifndef __SOC_TEGRA_MC_H__
  6. #define __SOC_TEGRA_MC_H__
  7. #include <linux/bits.h>
  8. #include <linux/debugfs.h>
  9. #include <linux/err.h>
  10. #include <linux/interconnect-provider.h>
  11. #include <linux/irq.h>
  12. #include <linux/reset-controller.h>
  13. #include <linux/types.h>
  14. #include <linux/tegra-icc.h>
  15. struct clk;
  16. struct device;
  17. struct page;
  18. struct tegra_mc_timing {
  19. unsigned long rate;
  20. u32 *emem_data;
  21. };
  22. struct tegra_mc_client {
  23. unsigned int id;
  24. unsigned int bpmp_id;
  25. enum tegra_icc_client_type type;
  26. const char *name;
  27. /*
  28. * For Tegra210 and earlier, this is the SWGROUP ID used for IOVA translations in the
  29. * Tegra SMMU, whereas on Tegra186 and later this is the ID used to override the ARM SMMU
  30. * stream ID used for IOVA translations for the given memory client.
  31. */
  32. union {
  33. unsigned int swgroup;
  34. unsigned int sid;
  35. };
  36. unsigned int fifo_size;
  37. struct {
  38. /* Tegra SMMU enable (Tegra210 and earlier) */
  39. struct {
  40. unsigned int reg;
  41. unsigned int bit;
  42. } smmu;
  43. /* latency allowance */
  44. struct {
  45. unsigned int reg;
  46. unsigned int shift;
  47. unsigned int mask;
  48. unsigned int def;
  49. } la;
  50. /* stream ID overrides (Tegra186 and later) */
  51. struct {
  52. unsigned int override;
  53. unsigned int security;
  54. } sid;
  55. } regs;
  56. };
  57. struct tegra_smmu_swgroup {
  58. const char *name;
  59. unsigned int swgroup;
  60. unsigned int reg;
  61. };
  62. struct tegra_smmu_group_soc {
  63. const char *name;
  64. const unsigned int *swgroups;
  65. unsigned int num_swgroups;
  66. };
  67. struct tegra_smmu_soc {
  68. const struct tegra_mc_client *clients;
  69. unsigned int num_clients;
  70. const struct tegra_smmu_swgroup *swgroups;
  71. unsigned int num_swgroups;
  72. const struct tegra_smmu_group_soc *groups;
  73. unsigned int num_groups;
  74. bool supports_round_robin_arbitration;
  75. bool supports_request_limit;
  76. unsigned int num_tlb_lines;
  77. unsigned int num_asids;
  78. };
  79. struct tegra_mc;
  80. struct tegra_smmu;
  81. #ifdef CONFIG_TEGRA_IOMMU_SMMU
  82. struct tegra_smmu *tegra_smmu_probe(struct device *dev,
  83. const struct tegra_smmu_soc *soc,
  84. struct tegra_mc *mc);
  85. void tegra_smmu_remove(struct tegra_smmu *smmu);
  86. #else
  87. static inline struct tegra_smmu *
  88. tegra_smmu_probe(struct device *dev, const struct tegra_smmu_soc *soc,
  89. struct tegra_mc *mc)
  90. {
  91. return NULL;
  92. }
  93. static inline void tegra_smmu_remove(struct tegra_smmu *smmu)
  94. {
  95. }
  96. #endif
  97. struct tegra_mc_reset {
  98. const char *name;
  99. unsigned long id;
  100. unsigned int control;
  101. unsigned int status;
  102. unsigned int reset;
  103. unsigned int bit;
  104. };
  105. struct tegra_mc_reset_ops {
  106. int (*hotreset_assert)(struct tegra_mc *mc,
  107. const struct tegra_mc_reset *rst);
  108. int (*hotreset_deassert)(struct tegra_mc *mc,
  109. const struct tegra_mc_reset *rst);
  110. int (*block_dma)(struct tegra_mc *mc,
  111. const struct tegra_mc_reset *rst);
  112. bool (*dma_idling)(struct tegra_mc *mc,
  113. const struct tegra_mc_reset *rst);
  114. int (*unblock_dma)(struct tegra_mc *mc,
  115. const struct tegra_mc_reset *rst);
  116. int (*reset_status)(struct tegra_mc *mc,
  117. const struct tegra_mc_reset *rst);
  118. };
  119. #define TEGRA_MC_ICC_TAG_DEFAULT 0
  120. #define TEGRA_MC_ICC_TAG_ISO BIT(0)
  121. struct tegra_mc_icc_ops {
  122. int (*set)(struct icc_node *src, struct icc_node *dst);
  123. int (*aggregate)(struct icc_node *node, u32 tag, u32 avg_bw,
  124. u32 peak_bw, u32 *agg_avg, u32 *agg_peak);
  125. struct icc_node* (*xlate)(const struct of_phandle_args *spec, void *data);
  126. struct icc_node_data *(*xlate_extended)(const struct of_phandle_args *spec,
  127. void *data);
  128. int (*get_bw)(struct icc_node *node, u32 *avg, u32 *peak);
  129. };
  130. struct icc_node *tegra_mc_icc_xlate(const struct of_phandle_args *spec,
  131. void *data);
  132. extern const struct tegra_mc_icc_ops tegra_mc_icc_ops;
  133. struct tegra_mc_ops {
  134. /*
  135. * @probe: Callback to set up SoC-specific bits of the memory controller. This is called
  136. * after basic, common set up that is done by the SoC-agnostic bits.
  137. */
  138. int (*probe)(struct tegra_mc *mc);
  139. void (*remove)(struct tegra_mc *mc);
  140. int (*resume)(struct tegra_mc *mc);
  141. irqreturn_t (*handle_irq)(int irq, void *data);
  142. int (*probe_device)(struct tegra_mc *mc, struct device *dev);
  143. };
  144. struct tegra_mc_soc {
  145. const struct tegra_mc_client *clients;
  146. unsigned int num_clients;
  147. const unsigned long *emem_regs;
  148. unsigned int num_emem_regs;
  149. unsigned int num_address_bits;
  150. unsigned int atom_size;
  151. unsigned int num_carveouts;
  152. u16 client_id_mask;
  153. u8 num_channels;
  154. const struct tegra_smmu_soc *smmu;
  155. u32 intmask;
  156. u32 ch_intmask;
  157. u32 global_intstatus_channel_shift;
  158. bool has_addr_hi_reg;
  159. const struct tegra_mc_reset_ops *reset_ops;
  160. const struct tegra_mc_reset *resets;
  161. unsigned int num_resets;
  162. const struct tegra_mc_icc_ops *icc_ops;
  163. const struct tegra_mc_ops *ops;
  164. };
  165. struct tegra_mc {
  166. struct tegra_bpmp *bpmp;
  167. struct device *dev;
  168. struct tegra_smmu *smmu;
  169. void __iomem *regs;
  170. void __iomem *bcast_ch_regs;
  171. void __iomem **ch_regs;
  172. struct clk *clk;
  173. int irq;
  174. const struct tegra_mc_soc *soc;
  175. unsigned long tick;
  176. struct tegra_mc_timing *timings;
  177. unsigned int num_timings;
  178. unsigned int num_channels;
  179. bool bwmgr_mrq_supported;
  180. struct reset_controller_dev reset;
  181. struct icc_provider provider;
  182. spinlock_t lock;
  183. struct {
  184. struct dentry *root;
  185. } debugfs;
  186. };
  187. int tegra_mc_write_emem_configuration(struct tegra_mc *mc, unsigned long rate);
  188. unsigned int tegra_mc_get_emem_device_count(struct tegra_mc *mc);
  189. #ifdef CONFIG_TEGRA_MC
  190. struct tegra_mc *devm_tegra_memory_controller_get(struct device *dev);
  191. int tegra_mc_probe_device(struct tegra_mc *mc, struct device *dev);
  192. int tegra_mc_get_carveout_info(struct tegra_mc *mc, unsigned int id,
  193. phys_addr_t *base, u64 *size);
  194. #else
  195. static inline struct tegra_mc *
  196. devm_tegra_memory_controller_get(struct device *dev)
  197. {
  198. return ERR_PTR(-ENODEV);
  199. }
  200. static inline int
  201. tegra_mc_probe_device(struct tegra_mc *mc, struct device *dev)
  202. {
  203. return -ENODEV;
  204. }
  205. static inline int
  206. tegra_mc_get_carveout_info(struct tegra_mc *mc, unsigned int id,
  207. phys_addr_t *base, u64 *size)
  208. {
  209. return -ENODEV;
  210. }
  211. #endif
  212. #endif /* __SOC_TEGRA_MC_H__ */