162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2014 NVIDIA CORPORATION.  All rights reserved.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef MEMORY_TEGRA_MC_H
762306a36Sopenharmony_ci#define MEMORY_TEGRA_MC_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/bits.h>
1062306a36Sopenharmony_ci#include <linux/io.h>
1162306a36Sopenharmony_ci#include <linux/types.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <soc/tegra/mc.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#define MC_INTSTATUS					0x00
1662306a36Sopenharmony_ci#define MC_INTMASK					0x04
1762306a36Sopenharmony_ci#define MC_ERR_STATUS					0x08
1862306a36Sopenharmony_ci#define MC_ERR_ADR					0x0c
1962306a36Sopenharmony_ci#define MC_GART_ERROR_REQ				0x30
2062306a36Sopenharmony_ci#define MC_EMEM_ADR_CFG					0x54
2162306a36Sopenharmony_ci#define MC_DECERR_EMEM_OTHERS_STATUS			0x58
2262306a36Sopenharmony_ci#define MC_SECURITY_VIOLATION_STATUS			0x74
2362306a36Sopenharmony_ci#define MC_EMEM_ARB_CFG					0x90
2462306a36Sopenharmony_ci#define MC_EMEM_ARB_OUTSTANDING_REQ			0x94
2562306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_RCD				0x98
2662306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_RP				0x9c
2762306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_RC				0xa0
2862306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_RAS				0xa4
2962306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_FAW				0xa8
3062306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_RRD				0xac
3162306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_RAP2PRE			0xb0
3262306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_WAP2PRE			0xb4
3362306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_R2R				0xb8
3462306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_W2W				0xbc
3562306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_R2W				0xc0
3662306a36Sopenharmony_ci#define MC_EMEM_ARB_TIMING_W2R				0xc4
3762306a36Sopenharmony_ci#define MC_EMEM_ARB_MISC2				0xc8
3862306a36Sopenharmony_ci#define MC_EMEM_ARB_DA_TURNS				0xd0
3962306a36Sopenharmony_ci#define MC_EMEM_ARB_DA_COVERS				0xd4
4062306a36Sopenharmony_ci#define MC_EMEM_ARB_MISC0				0xd8
4162306a36Sopenharmony_ci#define MC_EMEM_ARB_MISC1				0xdc
4262306a36Sopenharmony_ci#define MC_EMEM_ARB_RING1_THROTTLE			0xe0
4362306a36Sopenharmony_ci#define MC_EMEM_ARB_OVERRIDE				0xe8
4462306a36Sopenharmony_ci#define MC_TIMING_CONTROL_DBG				0xf8
4562306a36Sopenharmony_ci#define MC_TIMING_CONTROL				0xfc
4662306a36Sopenharmony_ci#define MC_ERR_VPR_STATUS				0x654
4762306a36Sopenharmony_ci#define MC_ERR_VPR_ADR					0x658
4862306a36Sopenharmony_ci#define MC_ERR_SEC_STATUS				0x67c
4962306a36Sopenharmony_ci#define MC_ERR_SEC_ADR					0x680
5062306a36Sopenharmony_ci#define MC_ERR_MTS_STATUS				0x9b0
5162306a36Sopenharmony_ci#define MC_ERR_MTS_ADR					0x9b4
5262306a36Sopenharmony_ci#define MC_ERR_ROUTE_SANITY_STATUS			0x9c0
5362306a36Sopenharmony_ci#define MC_ERR_ROUTE_SANITY_ADR				0x9c4
5462306a36Sopenharmony_ci#define MC_ERR_GENERALIZED_CARVEOUT_STATUS		0xc00
5562306a36Sopenharmony_ci#define MC_ERR_GENERALIZED_CARVEOUT_ADR			0xc04
5662306a36Sopenharmony_ci#define MC_EMEM_ADR_CFG_CHANNEL_ENABLE			0xdf8
5762306a36Sopenharmony_ci#define MC_GLOBAL_INTSTATUS				0xf24
5862306a36Sopenharmony_ci#define MC_ERR_ADR_HI					0x11fc
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define MC_INT_DECERR_ROUTE_SANITY			BIT(20)
6162306a36Sopenharmony_ci#define MC_INT_DECERR_GENERALIZED_CARVEOUT		BIT(17)
6262306a36Sopenharmony_ci#define MC_INT_DECERR_MTS				BIT(16)
6362306a36Sopenharmony_ci#define MC_INT_SECERR_SEC				BIT(13)
6462306a36Sopenharmony_ci#define MC_INT_DECERR_VPR				BIT(12)
6562306a36Sopenharmony_ci#define MC_INT_INVALID_APB_ASID_UPDATE			BIT(11)
6662306a36Sopenharmony_ci#define MC_INT_INVALID_SMMU_PAGE			BIT(10)
6762306a36Sopenharmony_ci#define MC_INT_ARBITRATION_EMEM				BIT(9)
6862306a36Sopenharmony_ci#define MC_INT_SECURITY_VIOLATION			BIT(8)
6962306a36Sopenharmony_ci#define MC_INT_INVALID_GART_PAGE			BIT(7)
7062306a36Sopenharmony_ci#define MC_INT_DECERR_EMEM				BIT(6)
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci#define MC_ERR_STATUS_TYPE_SHIFT			28
7362306a36Sopenharmony_ci#define MC_ERR_STATUS_TYPE_INVALID_SMMU_PAGE		(0x6 << 28)
7462306a36Sopenharmony_ci#define MC_ERR_STATUS_TYPE_MASK				(0x7 << 28)
7562306a36Sopenharmony_ci#define MC_ERR_STATUS_READABLE				BIT(27)
7662306a36Sopenharmony_ci#define MC_ERR_STATUS_WRITABLE				BIT(26)
7762306a36Sopenharmony_ci#define MC_ERR_STATUS_NONSECURE				BIT(25)
7862306a36Sopenharmony_ci#define MC_ERR_STATUS_ADR_HI_SHIFT			20
7962306a36Sopenharmony_ci#define MC_ERR_STATUS_ADR_HI_MASK			0x3
8062306a36Sopenharmony_ci#define MC_ERR_STATUS_SECURITY				BIT(17)
8162306a36Sopenharmony_ci#define MC_ERR_STATUS_RW				BIT(16)
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define MC_EMEM_ADR_CFG_EMEM_NUMDEV			BIT(0)
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci#define MC_EMEM_ARB_CFG_CYCLES_PER_UPDATE(x)		((x) & 0x1ff)
8662306a36Sopenharmony_ci#define MC_EMEM_ARB_CFG_CYCLES_PER_UPDATE_MASK		0x1ff
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#define MC_EMEM_ARB_OUTSTANDING_REQ_MAX_MASK		0x1ff
8962306a36Sopenharmony_ci#define MC_EMEM_ARB_OUTSTANDING_REQ_HOLDOFF_OVERRIDE	BIT(30)
9062306a36Sopenharmony_ci#define MC_EMEM_ARB_OUTSTANDING_REQ_LIMIT_ENABLE	BIT(31)
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci#define MC_EMEM_ARB_OVERRIDE_EACK_MASK			0x3
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci#define MC_TIMING_UPDATE				BIT(0)
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci#define MC_BROADCAST_CHANNEL				~0
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_cistatic inline u32 tegra_mc_scale_percents(u64 val, unsigned int percents)
9962306a36Sopenharmony_ci{
10062306a36Sopenharmony_ci	val = val * percents;
10162306a36Sopenharmony_ci	do_div(val, 100);
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci	return min_t(u64, val, U32_MAX);
10462306a36Sopenharmony_ci}
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_cistatic inline struct tegra_mc *
10762306a36Sopenharmony_ciicc_provider_to_tegra_mc(struct icc_provider *provider)
10862306a36Sopenharmony_ci{
10962306a36Sopenharmony_ci	return container_of(provider, struct tegra_mc, provider);
11062306a36Sopenharmony_ci}
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_cistatic inline u32 mc_ch_readl(const struct tegra_mc *mc, int ch,
11362306a36Sopenharmony_ci			      unsigned long offset)
11462306a36Sopenharmony_ci{
11562306a36Sopenharmony_ci	if (!mc->bcast_ch_regs)
11662306a36Sopenharmony_ci		return 0;
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci	if (ch == MC_BROADCAST_CHANNEL)
11962306a36Sopenharmony_ci		return readl_relaxed(mc->bcast_ch_regs + offset);
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci	return readl_relaxed(mc->ch_regs[ch] + offset);
12262306a36Sopenharmony_ci}
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_cistatic inline void mc_ch_writel(const struct tegra_mc *mc, int ch,
12562306a36Sopenharmony_ci				u32 value, unsigned long offset)
12662306a36Sopenharmony_ci{
12762306a36Sopenharmony_ci	if (!mc->bcast_ch_regs)
12862306a36Sopenharmony_ci		return;
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci	if (ch == MC_BROADCAST_CHANNEL)
13162306a36Sopenharmony_ci		writel_relaxed(value, mc->bcast_ch_regs + offset);
13262306a36Sopenharmony_ci	else
13362306a36Sopenharmony_ci		writel_relaxed(value, mc->ch_regs[ch] + offset);
13462306a36Sopenharmony_ci}
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_cistatic inline u32 mc_readl(const struct tegra_mc *mc, unsigned long offset)
13762306a36Sopenharmony_ci{
13862306a36Sopenharmony_ci	return readl_relaxed(mc->regs + offset);
13962306a36Sopenharmony_ci}
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_cistatic inline void mc_writel(const struct tegra_mc *mc, u32 value,
14262306a36Sopenharmony_ci			     unsigned long offset)
14362306a36Sopenharmony_ci{
14462306a36Sopenharmony_ci	writel_relaxed(value, mc->regs + offset);
14562306a36Sopenharmony_ci}
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ciextern const struct tegra_mc_reset_ops tegra_mc_reset_ops_common;
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_2x_SOC
15062306a36Sopenharmony_ciextern const struct tegra_mc_soc tegra20_mc_soc;
15162306a36Sopenharmony_ci#endif
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_3x_SOC
15462306a36Sopenharmony_ciextern const struct tegra_mc_soc tegra30_mc_soc;
15562306a36Sopenharmony_ci#endif
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_114_SOC
15862306a36Sopenharmony_ciextern const struct tegra_mc_soc tegra114_mc_soc;
15962306a36Sopenharmony_ci#endif
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_124_SOC
16262306a36Sopenharmony_ciextern const struct tegra_mc_soc tegra124_mc_soc;
16362306a36Sopenharmony_ci#endif
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_132_SOC
16662306a36Sopenharmony_ciextern const struct tegra_mc_soc tegra132_mc_soc;
16762306a36Sopenharmony_ci#endif
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_210_SOC
17062306a36Sopenharmony_ciextern const struct tegra_mc_soc tegra210_mc_soc;
17162306a36Sopenharmony_ci#endif
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_186_SOC
17462306a36Sopenharmony_ciextern const struct tegra_mc_soc tegra186_mc_soc;
17562306a36Sopenharmony_ci#endif
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_194_SOC
17862306a36Sopenharmony_ciextern const struct tegra_mc_soc tegra194_mc_soc;
17962306a36Sopenharmony_ci#endif
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci#ifdef CONFIG_ARCH_TEGRA_234_SOC
18262306a36Sopenharmony_ciextern const struct tegra_mc_soc tegra234_mc_soc;
18362306a36Sopenharmony_ci#endif
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci#if defined(CONFIG_ARCH_TEGRA_3x_SOC) || \
18662306a36Sopenharmony_ci    defined(CONFIG_ARCH_TEGRA_114_SOC) || \
18762306a36Sopenharmony_ci    defined(CONFIG_ARCH_TEGRA_124_SOC) || \
18862306a36Sopenharmony_ci    defined(CONFIG_ARCH_TEGRA_132_SOC) || \
18962306a36Sopenharmony_ci    defined(CONFIG_ARCH_TEGRA_210_SOC)
19062306a36Sopenharmony_ciint tegra30_mc_probe(struct tegra_mc *mc);
19162306a36Sopenharmony_ciextern const struct tegra_mc_ops tegra30_mc_ops;
19262306a36Sopenharmony_ci#endif
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci#if defined(CONFIG_ARCH_TEGRA_186_SOC) || \
19562306a36Sopenharmony_ci    defined(CONFIG_ARCH_TEGRA_194_SOC) || \
19662306a36Sopenharmony_ci    defined(CONFIG_ARCH_TEGRA_234_SOC)
19762306a36Sopenharmony_ciextern const struct tegra_mc_ops tegra186_mc_ops;
19862306a36Sopenharmony_ci#endif
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ciirqreturn_t tegra30_mc_handle_irq(int irq, void *data);
20162306a36Sopenharmony_ciextern const char * const tegra_mc_status_names[32];
20262306a36Sopenharmony_ciextern const char * const tegra_mc_error_names[8];
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci/*
20562306a36Sopenharmony_ci * These IDs are for internal use of Tegra ICC drivers. The ID numbers are
20662306a36Sopenharmony_ci * chosen such that they don't conflict with the device-tree ICC node IDs.
20762306a36Sopenharmony_ci */
20862306a36Sopenharmony_ci#define TEGRA_ICC_MC		1000
20962306a36Sopenharmony_ci#define TEGRA_ICC_EMC		1001
21062306a36Sopenharmony_ci#define TEGRA_ICC_EMEM		1002
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci#endif /* MEMORY_TEGRA_MC_H */
213