1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2014 NVIDIA Corporation
6 #ifndef __SOC_TEGRA_MC_H__
7 #define __SOC_TEGRA_MC_H__
9 #include <linux/bits.h>
10 #include <linux/debugfs.h>
11 #include <linux/err.h>
12 #include <linux/interconnect-provider.h>
13 #include <linux/irq.h>
14 #include <linux/reset-controller.h>
15 #include <linux/types.h>
16 #include <linux/tegra-icc.h>
22 struct tegra_mc_timing {
28 struct tegra_mc_client {
31 enum tegra_icc_client_type type;
34 * For Tegra210 and earlier, this is the SWGROUP ID used for IOVA translations in the
35 * Tegra SMMU, whereas on Tegra186 and later this is the ID used to override the ARM SMMU
36 * stream ID used for IOVA translations for the given memory client.
43 unsigned int fifo_size;
46 /* Tegra SMMU enable (Tegra210 and earlier) */
52 /* latency allowance */
60 /* stream ID overrides (Tegra186 and later) */
62 unsigned int override;
63 unsigned int security;
68 struct tegra_smmu_swgroup {
74 struct tegra_smmu_group_soc {
76 const unsigned int *swgroups;
77 unsigned int num_swgroups;
80 struct tegra_smmu_soc {
81 const struct tegra_mc_client *clients;
82 unsigned int num_clients;
84 const struct tegra_smmu_swgroup *swgroups;
85 unsigned int num_swgroups;
87 const struct tegra_smmu_group_soc *groups;
88 unsigned int num_groups;
90 bool supports_round_robin_arbitration;
91 bool supports_request_limit;
93 unsigned int num_tlb_lines;
94 unsigned int num_asids;
101 #ifdef CONFIG_TEGRA_IOMMU_SMMU
102 struct tegra_smmu *tegra_smmu_probe(struct device *dev,
103 const struct tegra_smmu_soc *soc,
104 struct tegra_mc *mc);
105 void tegra_smmu_remove(struct tegra_smmu *smmu);
107 static inline struct tegra_smmu *
108 tegra_smmu_probe(struct device *dev, const struct tegra_smmu_soc *soc,
114 static inline void tegra_smmu_remove(struct tegra_smmu *smmu)
119 #ifdef CONFIG_TEGRA_IOMMU_GART
120 struct gart_device *tegra_gart_probe(struct device *dev, struct tegra_mc *mc);
121 int tegra_gart_suspend(struct gart_device *gart);
122 int tegra_gart_resume(struct gart_device *gart);
124 static inline struct gart_device *
125 tegra_gart_probe(struct device *dev, struct tegra_mc *mc)
127 return ERR_PTR(-ENODEV);
130 static inline int tegra_gart_suspend(struct gart_device *gart)
135 static inline int tegra_gart_resume(struct gart_device *gart)
141 struct tegra_mc_reset {
144 unsigned int control;
150 struct tegra_mc_reset_ops {
151 int (*hotreset_assert)(struct tegra_mc *mc,
152 const struct tegra_mc_reset *rst);
153 int (*hotreset_deassert)(struct tegra_mc *mc,
154 const struct tegra_mc_reset *rst);
155 int (*block_dma)(struct tegra_mc *mc,
156 const struct tegra_mc_reset *rst);
157 bool (*dma_idling)(struct tegra_mc *mc,
158 const struct tegra_mc_reset *rst);
159 int (*unblock_dma)(struct tegra_mc *mc,
160 const struct tegra_mc_reset *rst);
161 int (*reset_status)(struct tegra_mc *mc,
162 const struct tegra_mc_reset *rst);
165 #define TEGRA_MC_ICC_TAG_DEFAULT 0
166 #define TEGRA_MC_ICC_TAG_ISO BIT(0)
168 struct tegra_mc_icc_ops {
169 int (*set)(struct icc_node *src, struct icc_node *dst);
170 int (*aggregate)(struct icc_node *node, u32 tag, u32 avg_bw,
171 u32 peak_bw, u32 *agg_avg, u32 *agg_peak);
172 struct icc_node* (*xlate)(struct of_phandle_args *spec, void *data);
173 struct icc_node_data *(*xlate_extended)(struct of_phandle_args *spec,
175 int (*get_bw)(struct icc_node *node, u32 *avg, u32 *peak);
178 struct icc_node *tegra_mc_icc_xlate(struct of_phandle_args *spec, void *data);
179 extern const struct tegra_mc_icc_ops tegra_mc_icc_ops;
181 struct tegra_mc_ops {
183 * @probe: Callback to set up SoC-specific bits of the memory controller. This is called
184 * after basic, common set up that is done by the SoC-agnostic bits.
186 int (*probe)(struct tegra_mc *mc);
187 void (*remove)(struct tegra_mc *mc);
188 int (*suspend)(struct tegra_mc *mc);
189 int (*resume)(struct tegra_mc *mc);
190 irqreturn_t (*handle_irq)(int irq, void *data);
191 int (*probe_device)(struct tegra_mc *mc, struct device *dev);
194 struct tegra_mc_soc {
195 const struct tegra_mc_client *clients;
196 unsigned int num_clients;
198 const unsigned long *emem_regs;
199 unsigned int num_emem_regs;
201 unsigned int num_address_bits;
202 unsigned int atom_size;
204 unsigned int num_carveouts;
209 const struct tegra_smmu_soc *smmu;
213 u32 global_intstatus_channel_shift;
214 bool has_addr_hi_reg;
216 const struct tegra_mc_reset_ops *reset_ops;
217 const struct tegra_mc_reset *resets;
218 unsigned int num_resets;
220 const struct tegra_mc_icc_ops *icc_ops;
221 const struct tegra_mc_ops *ops;
225 struct tegra_bpmp *bpmp;
227 struct tegra_smmu *smmu;
228 struct gart_device *gart;
230 void __iomem *bcast_ch_regs;
231 void __iomem **ch_regs;
235 const struct tegra_mc_soc *soc;
238 struct tegra_mc_timing *timings;
239 unsigned int num_timings;
240 unsigned int num_channels;
242 bool bwmgr_mrq_supported;
243 struct reset_controller_dev reset;
245 struct icc_provider provider;
254 int tegra_mc_write_emem_configuration(struct tegra_mc *mc, unsigned long rate);
255 unsigned int tegra_mc_get_emem_device_count(struct tegra_mc *mc);
257 #ifdef CONFIG_TEGRA_MC
258 struct tegra_mc *devm_tegra_memory_controller_get(struct device *dev);
259 int tegra_mc_probe_device(struct tegra_mc *mc, struct device *dev);
260 int tegra_mc_get_carveout_info(struct tegra_mc *mc, unsigned int id,
261 phys_addr_t *base, u64 *size);
263 static inline struct tegra_mc *
264 devm_tegra_memory_controller_get(struct device *dev)
266 return ERR_PTR(-ENODEV);
270 tegra_mc_probe_device(struct tegra_mc *mc, struct device *dev)
276 tegra_mc_get_carveout_info(struct tegra_mc *mc, unsigned int id,
277 phys_addr_t *base, u64 *size)
283 #endif /* __SOC_TEGRA_MC_H__ */