1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
289184651SThierry Reding /*
389184651SThierry Reding * Copyright (C) 2014 NVIDIA CORPORATION. All rights reserved.
489184651SThierry Reding */
589184651SThierry Reding
689184651SThierry Reding #ifndef MEMORY_TEGRA_MC_H
789184651SThierry Reding #define MEMORY_TEGRA_MC_H
889184651SThierry Reding
9e34212c7SDmitry Osipenko #include <linux/bits.h>
1089184651SThierry Reding #include <linux/io.h>
1189184651SThierry Reding #include <linux/types.h>
1289184651SThierry Reding
1389184651SThierry Reding #include <soc/tegra/mc.h>
1489184651SThierry Reding
15141bef44SDmitry Osipenko #define MC_INTSTATUS 0x00
16141bef44SDmitry Osipenko #define MC_INTMASK 0x04
17141bef44SDmitry Osipenko #define MC_ERR_STATUS 0x08
18141bef44SDmitry Osipenko #define MC_ERR_ADR 0x0c
19141bef44SDmitry Osipenko #define MC_GART_ERROR_REQ 0x30
20141bef44SDmitry Osipenko #define MC_EMEM_ADR_CFG 0x54
21141bef44SDmitry Osipenko #define MC_DECERR_EMEM_OTHERS_STATUS 0x58
22141bef44SDmitry Osipenko #define MC_SECURITY_VIOLATION_STATUS 0x74
23141bef44SDmitry Osipenko #define MC_EMEM_ARB_CFG 0x90
24141bef44SDmitry Osipenko #define MC_EMEM_ARB_OUTSTANDING_REQ 0x94
25141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_RCD 0x98
26141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_RP 0x9c
27141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_RC 0xa0
28141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_RAS 0xa4
29141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_FAW 0xa8
30141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_RRD 0xac
31141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_RAP2PRE 0xb0
32141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_WAP2PRE 0xb4
33141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_R2R 0xb8
34141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_W2W 0xbc
35141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_R2W 0xc0
36141bef44SDmitry Osipenko #define MC_EMEM_ARB_TIMING_W2R 0xc4
3710de2114SJoseph Lo #define MC_EMEM_ARB_MISC2 0xc8
38141bef44SDmitry Osipenko #define MC_EMEM_ARB_DA_TURNS 0xd0
39141bef44SDmitry Osipenko #define MC_EMEM_ARB_DA_COVERS 0xd4
40141bef44SDmitry Osipenko #define MC_EMEM_ARB_MISC0 0xd8
41141bef44SDmitry Osipenko #define MC_EMEM_ARB_MISC1 0xdc
42141bef44SDmitry Osipenko #define MC_EMEM_ARB_RING1_THROTTLE 0xe0
43141bef44SDmitry Osipenko #define MC_EMEM_ARB_OVERRIDE 0xe8
44141bef44SDmitry Osipenko #define MC_TIMING_CONTROL_DBG 0xf8
45141bef44SDmitry Osipenko #define MC_TIMING_CONTROL 0xfc
4654a85e09SAshish Mhetre #define MC_ERR_VPR_STATUS 0x654
4754a85e09SAshish Mhetre #define MC_ERR_VPR_ADR 0x658
4854a85e09SAshish Mhetre #define MC_ERR_SEC_STATUS 0x67c
4954a85e09SAshish Mhetre #define MC_ERR_SEC_ADR 0x680
5054a85e09SAshish Mhetre #define MC_ERR_MTS_STATUS 0x9b0
5154a85e09SAshish Mhetre #define MC_ERR_MTS_ADR 0x9b4
5254a85e09SAshish Mhetre #define MC_ERR_ROUTE_SANITY_STATUS 0x9c0
5354a85e09SAshish Mhetre #define MC_ERR_ROUTE_SANITY_ADR 0x9c4
5454a85e09SAshish Mhetre #define MC_ERR_GENERALIZED_CARVEOUT_STATUS 0xc00
5554a85e09SAshish Mhetre #define MC_ERR_GENERALIZED_CARVEOUT_ADR 0xc04
56*e852af72SSumit Gupta #define MC_EMEM_ADR_CFG_CHANNEL_ENABLE 0xdf8
5754a85e09SAshish Mhetre #define MC_GLOBAL_INTSTATUS 0xf24
5854a85e09SAshish Mhetre #define MC_ERR_ADR_HI 0x11fc
59141bef44SDmitry Osipenko
6054a85e09SAshish Mhetre #define MC_INT_DECERR_ROUTE_SANITY BIT(20)
6154a85e09SAshish Mhetre #define MC_INT_DECERR_GENERALIZED_CARVEOUT BIT(17)
62e34212c7SDmitry Osipenko #define MC_INT_DECERR_MTS BIT(16)
63e34212c7SDmitry Osipenko #define MC_INT_SECERR_SEC BIT(13)
64e34212c7SDmitry Osipenko #define MC_INT_DECERR_VPR BIT(12)
65e34212c7SDmitry Osipenko #define MC_INT_INVALID_APB_ASID_UPDATE BIT(11)
66e34212c7SDmitry Osipenko #define MC_INT_INVALID_SMMU_PAGE BIT(10)
67e34212c7SDmitry Osipenko #define MC_INT_ARBITRATION_EMEM BIT(9)
68e34212c7SDmitry Osipenko #define MC_INT_SECURITY_VIOLATION BIT(8)
69e34212c7SDmitry Osipenko #define MC_INT_INVALID_GART_PAGE BIT(7)
70e34212c7SDmitry Osipenko #define MC_INT_DECERR_EMEM BIT(6)
71e34212c7SDmitry Osipenko
72141bef44SDmitry Osipenko #define MC_ERR_STATUS_TYPE_SHIFT 28
73141bef44SDmitry Osipenko #define MC_ERR_STATUS_TYPE_INVALID_SMMU_PAGE (0x6 << 28)
74141bef44SDmitry Osipenko #define MC_ERR_STATUS_TYPE_MASK (0x7 << 28)
75141bef44SDmitry Osipenko #define MC_ERR_STATUS_READABLE BIT(27)
76141bef44SDmitry Osipenko #define MC_ERR_STATUS_WRITABLE BIT(26)
77141bef44SDmitry Osipenko #define MC_ERR_STATUS_NONSECURE BIT(25)
78141bef44SDmitry Osipenko #define MC_ERR_STATUS_ADR_HI_SHIFT 20
79141bef44SDmitry Osipenko #define MC_ERR_STATUS_ADR_HI_MASK 0x3
80141bef44SDmitry Osipenko #define MC_ERR_STATUS_SECURITY BIT(17)
81141bef44SDmitry Osipenko #define MC_ERR_STATUS_RW BIT(16)
82141bef44SDmitry Osipenko
83141bef44SDmitry Osipenko #define MC_EMEM_ADR_CFG_EMEM_NUMDEV BIT(0)
84141bef44SDmitry Osipenko
85141bef44SDmitry Osipenko #define MC_EMEM_ARB_CFG_CYCLES_PER_UPDATE(x) ((x) & 0x1ff)
86141bef44SDmitry Osipenko #define MC_EMEM_ARB_CFG_CYCLES_PER_UPDATE_MASK 0x1ff
87141bef44SDmitry Osipenko
88e34212c7SDmitry Osipenko #define MC_EMEM_ARB_OUTSTANDING_REQ_MAX_MASK 0x1ff
89e34212c7SDmitry Osipenko #define MC_EMEM_ARB_OUTSTANDING_REQ_HOLDOFF_OVERRIDE BIT(30)
90e34212c7SDmitry Osipenko #define MC_EMEM_ARB_OUTSTANDING_REQ_LIMIT_ENABLE BIT(31)
91e34212c7SDmitry Osipenko
92e34212c7SDmitry Osipenko #define MC_EMEM_ARB_OVERRIDE_EACK_MASK 0x3
93e34212c7SDmitry Osipenko
94e34212c7SDmitry Osipenko #define MC_TIMING_UPDATE BIT(0)
951c74d5c0SDmitry Osipenko
9654a85e09SAshish Mhetre #define MC_BROADCAST_CHANNEL ~0
9754a85e09SAshish Mhetre
tegra_mc_scale_percents(u64 val,unsigned int percents)9806f07981SDmitry Osipenko static inline u32 tegra_mc_scale_percents(u64 val, unsigned int percents)
9906f07981SDmitry Osipenko {
10006f07981SDmitry Osipenko val = val * percents;
10106f07981SDmitry Osipenko do_div(val, 100);
10206f07981SDmitry Osipenko
10306f07981SDmitry Osipenko return min_t(u64, val, U32_MAX);
10406f07981SDmitry Osipenko }
10506f07981SDmitry Osipenko
10606f07981SDmitry Osipenko static inline struct tegra_mc *
icc_provider_to_tegra_mc(struct icc_provider * provider)10706f07981SDmitry Osipenko icc_provider_to_tegra_mc(struct icc_provider *provider)
10806f07981SDmitry Osipenko {
10906f07981SDmitry Osipenko return container_of(provider, struct tegra_mc, provider);
11006f07981SDmitry Osipenko }
11106f07981SDmitry Osipenko
mc_ch_readl(const struct tegra_mc * mc,int ch,unsigned long offset)11254a85e09SAshish Mhetre static inline u32 mc_ch_readl(const struct tegra_mc *mc, int ch,
11354a85e09SAshish Mhetre unsigned long offset)
11454a85e09SAshish Mhetre {
11554a85e09SAshish Mhetre if (!mc->bcast_ch_regs)
11654a85e09SAshish Mhetre return 0;
11754a85e09SAshish Mhetre
11854a85e09SAshish Mhetre if (ch == MC_BROADCAST_CHANNEL)
11954a85e09SAshish Mhetre return readl_relaxed(mc->bcast_ch_regs + offset);
12054a85e09SAshish Mhetre
12154a85e09SAshish Mhetre return readl_relaxed(mc->ch_regs[ch] + offset);
12254a85e09SAshish Mhetre }
12354a85e09SAshish Mhetre
mc_ch_writel(const struct tegra_mc * mc,int ch,u32 value,unsigned long offset)12454a85e09SAshish Mhetre static inline void mc_ch_writel(const struct tegra_mc *mc, int ch,
12554a85e09SAshish Mhetre u32 value, unsigned long offset)
12654a85e09SAshish Mhetre {
12754a85e09SAshish Mhetre if (!mc->bcast_ch_regs)
12854a85e09SAshish Mhetre return;
12954a85e09SAshish Mhetre
13054a85e09SAshish Mhetre if (ch == MC_BROADCAST_CHANNEL)
13154a85e09SAshish Mhetre writel_relaxed(value, mc->bcast_ch_regs + offset);
13254a85e09SAshish Mhetre else
13354a85e09SAshish Mhetre writel_relaxed(value, mc->ch_regs[ch] + offset);
13454a85e09SAshish Mhetre }
13554a85e09SAshish Mhetre
mc_readl(const struct tegra_mc * mc,unsigned long offset)136fbd31f5aSDmitry Osipenko static inline u32 mc_readl(const struct tegra_mc *mc, unsigned long offset)
13789184651SThierry Reding {
13845594c68SDmitry Osipenko return readl_relaxed(mc->regs + offset);
13989184651SThierry Reding }
14089184651SThierry Reding
mc_writel(const struct tegra_mc * mc,u32 value,unsigned long offset)141fbd31f5aSDmitry Osipenko static inline void mc_writel(const struct tegra_mc *mc, u32 value,
14289184651SThierry Reding unsigned long offset)
14389184651SThierry Reding {
14445594c68SDmitry Osipenko writel_relaxed(value, mc->regs + offset);
14589184651SThierry Reding }
14689184651SThierry Reding
147cb2b5839SThierry Reding extern const struct tegra_mc_reset_ops tegra_mc_reset_ops_common;
14820e92462SDmitry Osipenko
149a8d502fdSDmitry Osipenko #ifdef CONFIG_ARCH_TEGRA_2x_SOC
150a8d502fdSDmitry Osipenko extern const struct tegra_mc_soc tegra20_mc_soc;
151a8d502fdSDmitry Osipenko #endif
152a8d502fdSDmitry Osipenko
15389184651SThierry Reding #ifdef CONFIG_ARCH_TEGRA_3x_SOC
15489184651SThierry Reding extern const struct tegra_mc_soc tegra30_mc_soc;
15589184651SThierry Reding #endif
15689184651SThierry Reding
15789184651SThierry Reding #ifdef CONFIG_ARCH_TEGRA_114_SOC
15889184651SThierry Reding extern const struct tegra_mc_soc tegra114_mc_soc;
15989184651SThierry Reding #endif
16089184651SThierry Reding
16189184651SThierry Reding #ifdef CONFIG_ARCH_TEGRA_124_SOC
16289184651SThierry Reding extern const struct tegra_mc_soc tegra124_mc_soc;
16389184651SThierry Reding #endif
16489184651SThierry Reding
165242b1d71SThierry Reding #ifdef CONFIG_ARCH_TEGRA_132_SOC
166242b1d71SThierry Reding extern const struct tegra_mc_soc tegra132_mc_soc;
167242b1d71SThierry Reding #endif
168242b1d71SThierry Reding
169588c43a7SThierry Reding #ifdef CONFIG_ARCH_TEGRA_210_SOC
170588c43a7SThierry Reding extern const struct tegra_mc_soc tegra210_mc_soc;
171588c43a7SThierry Reding #endif
172588c43a7SThierry Reding
1737355c7b9SThierry Reding #ifdef CONFIG_ARCH_TEGRA_186_SOC
1747355c7b9SThierry Reding extern const struct tegra_mc_soc tegra186_mc_soc;
1757355c7b9SThierry Reding #endif
1767355c7b9SThierry Reding
1777355c7b9SThierry Reding #ifdef CONFIG_ARCH_TEGRA_194_SOC
1787355c7b9SThierry Reding extern const struct tegra_mc_soc tegra194_mc_soc;
1797355c7b9SThierry Reding #endif
1807355c7b9SThierry Reding
18172c81bb6SThierry Reding #ifdef CONFIG_ARCH_TEGRA_234_SOC
18272c81bb6SThierry Reding extern const struct tegra_mc_soc tegra234_mc_soc;
18372c81bb6SThierry Reding #endif
18472c81bb6SThierry Reding
185ddeceab0SThierry Reding #if defined(CONFIG_ARCH_TEGRA_3x_SOC) || \
186ddeceab0SThierry Reding defined(CONFIG_ARCH_TEGRA_114_SOC) || \
187ddeceab0SThierry Reding defined(CONFIG_ARCH_TEGRA_124_SOC) || \
188ddeceab0SThierry Reding defined(CONFIG_ARCH_TEGRA_132_SOC) || \
189ddeceab0SThierry Reding defined(CONFIG_ARCH_TEGRA_210_SOC)
190ddeceab0SThierry Reding int tegra30_mc_probe(struct tegra_mc *mc);
191ddeceab0SThierry Reding extern const struct tegra_mc_ops tegra30_mc_ops;
192ddeceab0SThierry Reding #endif
193ddeceab0SThierry Reding
1948fd9f632SThierry Reding #if defined(CONFIG_ARCH_TEGRA_186_SOC) || \
19572c81bb6SThierry Reding defined(CONFIG_ARCH_TEGRA_194_SOC) || \
19672c81bb6SThierry Reding defined(CONFIG_ARCH_TEGRA_234_SOC)
1978fd9f632SThierry Reding extern const struct tegra_mc_ops tegra186_mc_ops;
1988fd9f632SThierry Reding #endif
1998fd9f632SThierry Reding
20054a85e09SAshish Mhetre irqreturn_t tegra30_mc_handle_irq(int irq, void *data);
2011079a66bSThierry Reding extern const char * const tegra_mc_status_names[32];
2021079a66bSThierry Reding extern const char * const tegra_mc_error_names[8];
2031079a66bSThierry Reding
20406f07981SDmitry Osipenko /*
20506f07981SDmitry Osipenko * These IDs are for internal use of Tegra ICC drivers. The ID numbers are
20606f07981SDmitry Osipenko * chosen such that they don't conflict with the device-tree ICC node IDs.
20706f07981SDmitry Osipenko */
20806f07981SDmitry Osipenko #define TEGRA_ICC_MC 1000
20906f07981SDmitry Osipenko #define TEGRA_ICC_EMC 1001
21006f07981SDmitry Osipenko #define TEGRA_ICC_EMEM 1002
21106f07981SDmitry Osipenko
21289184651SThierry Reding #endif /* MEMORY_TEGRA_MC_H */
213