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