blob: 509fe32bb1e838732c8694119ef1e32aa237f06f [file] [log] [blame]
Varun Wadekarcd5a2f52015-09-20 15:08:22 +05301/*
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +01002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Varun Wadekarcd5a2f52015-09-20 15:08:22 +05303 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekarcd5a2f52015-09-20 15:08:22 +05305 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef MEMCTRL_V2_H
8#define MEMCTRL_V2_H
Varun Wadekarcd5a2f52015-09-20 15:08:22 +05309
Varun Wadekarcd5a2f52015-09-20 15:08:22 +053010#include <tegra_def.h>
11
Julius Werner53456fc2019-07-09 13:49:11 -070012#ifndef __ASSEMBLER__
Pritesh Raithatha9eb5db52017-01-02 19:42:31 +053013
Ambroise Vincentffbf32a2019-03-28 09:01:18 +000014#include <lib/mmio.h>
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +010015#include <stdint.h>
Pritesh Raithatha9eb5db52017-01-02 19:42:31 +053016
Varun Wadekarcd5a2f52015-09-20 15:08:22 +053017/*******************************************************************************
Varun Wadekarc9ac3e42016-02-17 15:07:49 -080018 * Structure to hold the transaction override settings to use to override
19 * client inputs
20 ******************************************************************************/
21typedef struct mc_txn_override_cfg {
22 uint32_t offset;
23 uint8_t cgid_tag;
24} mc_txn_override_cfg_t;
25
26#define mc_make_txn_override_cfg(off, val) \
27 { \
28 .offset = MC_TXN_OVERRIDE_CONFIG_ ## off, \
29 .cgid_tag = MC_TXN_OVERRIDE_ ## val \
30 }
31
32/*******************************************************************************
Varun Wadekarcd5a2f52015-09-20 15:08:22 +053033 * Structure to hold the Stream ID to use to override client inputs
34 ******************************************************************************/
35typedef struct mc_streamid_override_cfg {
36 uint32_t offset;
37 uint8_t stream_id;
38} mc_streamid_override_cfg_t;
39
40/*******************************************************************************
41 * Structure to hold the Stream ID Security Configuration settings
42 ******************************************************************************/
43typedef struct mc_streamid_security_cfg {
44 char *name;
45 uint32_t offset;
46 int override_enable;
47 int override_client_inputs;
48 int override_client_ns_flag;
49} mc_streamid_security_cfg_t;
50
Anthony Zhou0e07e452017-07-26 17:16:54 +080051#define OVERRIDE_DISABLE 1U
52#define OVERRIDE_ENABLE 0U
53#define CLIENT_FLAG_SECURE 0U
54#define CLIENT_FLAG_NON_SECURE 1U
55#define CLIENT_INPUTS_OVERRIDE 1U
56#define CLIENT_INPUTS_NO_OVERRIDE 0U
Puneet Saxenacf8c0e22017-08-04 17:19:55 +053057/*******************************************************************************
58 * StreamID to indicate no SMMU translations (requests to be steered on the
59 * SMMU bypass path)
60 ******************************************************************************/
61#define MC_STREAM_ID_MAX 0x7FU
62
63/*******************************************************************************
64 * Memory Controller SMMU Bypass config register
65 ******************************************************************************/
66#define MC_SMMU_BYPASS_CONFIG 0x1820U
67#define MC_SMMU_BYPASS_CTRL_MASK 0x3U
68#define MC_SMMU_BYPASS_CTRL_SHIFT 0U
69#define MC_SMMU_CTRL_TBU_BYPASS_ALL (0U << MC_SMMU_BYPASS_CTRL_SHIFT)
70#define MC_SMMU_CTRL_TBU_RSVD (1U << MC_SMMU_BYPASS_CTRL_SHIFT)
71#define MC_SMMU_CTRL_TBU_BYPASS_SPL_STREAMID (2U << MC_SMMU_BYPASS_CTRL_SHIFT)
72#define MC_SMMU_CTRL_TBU_BYPASS_NONE (3U << MC_SMMU_BYPASS_CTRL_SHIFT)
73#define MC_SMMU_BYPASS_CONFIG_WRITE_ACCESS_BIT (1U << 31)
74#define MC_SMMU_BYPASS_CONFIG_SETTINGS (MC_SMMU_BYPASS_CONFIG_WRITE_ACCESS_BIT | \
75 MC_SMMU_CTRL_TBU_BYPASS_SPL_STREAMID)
Varun Wadekarcd5a2f52015-09-20 15:08:22 +053076
77#define mc_make_sec_cfg(off, ns, ovrrd, access) \
Pritesh Raithatha9eb5db52017-01-02 19:42:31 +053078 { \
79 .name = # off, \
80 .offset = MC_STREAMID_OVERRIDE_TO_SECURITY_CFG( \
81 MC_STREAMID_OVERRIDE_CFG_ ## off), \
82 .override_client_ns_flag = CLIENT_FLAG_ ## ns, \
83 .override_client_inputs = CLIENT_INPUTS_ ## ovrrd, \
84 .override_enable = OVERRIDE_ ## access \
85 }
86
Pritesh Raithatha75c94432018-08-03 15:48:15 +053087typedef struct mc_regs {
88 uint32_t reg;
89 uint32_t val;
90} mc_regs_t;
91
92#define mc_make_sid_override_cfg(name) \
93 { \
94 .reg = TEGRA_MC_STREAMID_BASE + MC_STREAMID_OVERRIDE_CFG_ ## name, \
95 .val = 0x00000000U, \
96 }
97
98#define mc_make_sid_security_cfg(name) \
99 { \
100 .reg = TEGRA_MC_STREAMID_BASE + MC_STREAMID_OVERRIDE_TO_SECURITY_CFG(MC_STREAMID_OVERRIDE_CFG_ ## name), \
101 .val = 0x00000000U, \
102 }
103
104#define mc_smmu_bypass_cfg \
105 { \
106 .reg = TEGRA_MC_BASE + MC_SMMU_BYPASS_CONFIG, \
107 .val = 0x00000000U, \
108 }
109
110#define _START_OF_TABLE_ \
111 { \
112 .reg = 0xCAFE05C7U, \
113 .val = 0x00000000U, \
114 }
115
116#define _END_OF_TABLE_ \
117 { \
118 .reg = 0xFFFFFFFFU, \
119 .val = 0xFFFFFFFFU, \
120 }
121
Pritesh Raithatha9eb5db52017-01-02 19:42:31 +0530122/*******************************************************************************
123 * Structure to hold Memory Controller's Configuration settings
124 ******************************************************************************/
125typedef struct tegra_mc_settings {
126 const uint32_t *streamid_override_cfg;
127 uint32_t num_streamid_override_cfgs;
128 const mc_streamid_security_cfg_t *streamid_security_cfg;
129 uint32_t num_streamid_security_cfgs;
130 const mc_txn_override_cfg_t *txn_override_cfg;
131 uint32_t num_txn_override_cfgs;
Puneet Saxenacf8c0e22017-08-04 17:19:55 +0530132 void (*reconfig_mss_clients)(void);
133 void (*set_txn_overrides)(void);
Pritesh Raithatha75c94432018-08-03 15:48:15 +0530134 mc_regs_t* (*get_mc_system_suspend_ctx)(void);
Pritesh Raithatha9eb5db52017-01-02 19:42:31 +0530135} tegra_mc_settings_t;
Varun Wadekarcd5a2f52015-09-20 15:08:22 +0530136
Varun Wadekarcd5a2f52015-09-20 15:08:22 +0530137static inline uint32_t tegra_mc_read_32(uint32_t off)
138{
139 return mmio_read_32(TEGRA_MC_BASE + off);
140}
141
142static inline void tegra_mc_write_32(uint32_t off, uint32_t val)
143{
144 mmio_write_32(TEGRA_MC_BASE + off, val);
145}
146
147static inline uint32_t tegra_mc_streamid_read_32(uint32_t off)
148{
149 return mmio_read_32(TEGRA_MC_STREAMID_BASE + off);
150}
151
152static inline void tegra_mc_streamid_write_32(uint32_t off, uint32_t val)
153{
154 mmio_write_32(TEGRA_MC_STREAMID_BASE + off, val);
155}
156
Varun Wadekara0f26972016-03-11 17:18:51 -0800157#define mc_set_pcfifo_unordered_boot_so_mss(id, client) \
Anthony Zhou0e07e452017-07-26 17:16:54 +0800158 ((uint32_t)~MC_PCFIFO_CLIENT_CONFIG##id##_PCFIFO_##client##_MASK | \
Varun Wadekara0f26972016-03-11 17:18:51 -0800159 MC_PCFIFO_CLIENT_CONFIG##id##_PCFIFO_##client##_UNORDERED)
160
Krishna Reddy329e2282017-05-25 11:04:33 -0700161#define mc_set_pcfifo_ordered_boot_so_mss(id, client) \
162 MC_PCFIFO_CLIENT_CONFIG##id##_PCFIFO_##client##_ORDERED
Varun Wadekara0f26972016-03-11 17:18:51 -0800163
164#define mc_set_tsa_passthrough(client) \
165 { \
166 mmio_write_32(TEGRA_TSA_BASE + TSA_CONFIG_STATIC0_CSW_##client, \
167 (TSA_CONFIG_STATIC0_CSW_##client##_RESET & \
Anthony Zhou0844b972017-06-28 16:35:54 +0800168 (uint32_t)~TSA_CONFIG_CSW_MEMTYPE_OVERRIDE_MASK) | \
169 (uint32_t)TSA_CONFIG_CSW_MEMTYPE_OVERRIDE_PASTHRU); \
Varun Wadekara0f26972016-03-11 17:18:51 -0800170 }
171
Puneet Saxenacf8c0e22017-08-04 17:19:55 +0530172#define mc_set_tsa_w_passthrough(client) \
173 { \
174 mmio_write_32(TEGRA_TSA_BASE + TSA_CONFIG_STATIC0_CSW_##client, \
175 (TSA_CONFIG_STATIC0_CSW_RESET_W & \
176 (uint32_t)~TSA_CONFIG_CSW_MEMTYPE_OVERRIDE_MASK) | \
177 (uint32_t)TSA_CONFIG_CSW_MEMTYPE_OVERRIDE_PASTHRU); \
178 }
179
180#define mc_set_tsa_r_passthrough(client) \
181 { \
182 mmio_write_32(TEGRA_TSA_BASE + TSA_CONFIG_STATIC0_CSR_##client, \
183 (TSA_CONFIG_STATIC0_CSR_RESET_R & \
184 (uint32_t)~TSA_CONFIG_CSW_MEMTYPE_OVERRIDE_MASK) | \
185 (uint32_t)TSA_CONFIG_CSW_MEMTYPE_OVERRIDE_PASTHRU); \
186 }
187
Krishna Reddy329e2282017-05-25 11:04:33 -0700188#define mc_set_txn_override(client, normal_axi_id, so_dev_axi_id, normal_override, so_dev_override) \
Varun Wadekara0f26972016-03-11 17:18:51 -0800189 { \
190 tegra_mc_write_32(MC_TXN_OVERRIDE_CONFIG_##client, \
Krishna Reddy329e2282017-05-25 11:04:33 -0700191 MC_TXN_OVERRIDE_##normal_axi_id | \
192 MC_TXN_OVERRIDE_CONFIG_COH_PATH_##so_dev_override##_SO_DEV | \
193 MC_TXN_OVERRIDE_CONFIG_COH_PATH_##normal_override##_NORMAL | \
194 MC_TXN_OVERRIDE_CONFIG_CGID_##so_dev_axi_id); \
Varun Wadekara0f26972016-03-11 17:18:51 -0800195 }
Pritesh Raithatha9eb5db52017-01-02 19:42:31 +0530196
197/*******************************************************************************
198 * Handler to read memory configuration settings
199 *
200 * Implemented by SoCs under tegra/soc/txxx
201 ******************************************************************************/
202tegra_mc_settings_t *tegra_get_mc_settings(void);
203
Varun Wadekarf3cd5092017-10-30 14:35:17 -0700204/*******************************************************************************
Pritesh Raithatha75c94432018-08-03 15:48:15 +0530205 * Handler to save MC settings before "System Suspend" to TZDRAM
206 *
207 * Implemented by Tegra common memctrl_v2 driver under common/drivers/memctrl
208 ******************************************************************************/
209void tegra_mc_save_context(uint64_t mc_ctx_addr);
210
211/*******************************************************************************
Varun Wadekarf3cd5092017-10-30 14:35:17 -0700212 * Handler to program the scratch registers with TZDRAM settings for the
213 * resume firmware.
214 *
215 * Implemented by SoCs under tegra/soc/txxx
216 ******************************************************************************/
217void plat_memctrl_tzdram_setup(uint64_t phys_base, uint64_t size_in_bytes);
218
Julius Werner53456fc2019-07-09 13:49:11 -0700219#endif /* __ASSEMBLER__ */
Varun Wadekara0f26972016-03-11 17:18:51 -0800220
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000221#endif /* MEMCTRL_V2_H */