mc.h 5.8 KB

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