blob: 9af3027ea3ae9aaf22aa508da50b837fd5308fff [file] [log] [blame]
Varun Wadekar412dd5c2015-09-20 15:08:22 +05301/*
Manish V Badarkhec959ea72020-10-07 16:04:06 +01002 * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
Varun Wadekar08e60f82019-08-26 10:20:53 -07003 * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
Varun Wadekar412dd5c2015-09-20 15:08:22 +05304 *
dp-arm82cb2c12017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar412dd5c2015-09-20 15:08:22 +05306 */
7
Antonio Nino Diazc3cf06f2018-11-08 10:20:19 +00008#ifndef MEMCTRL_V2_H
9#define MEMCTRL_V2_H
Varun Wadekar412dd5c2015-09-20 15:08:22 +053010
Varun Wadekar08e60f82019-08-26 10:20:53 -070011#include <arch.h>
12
Varun Wadekar412dd5c2015-09-20 15:08:22 +053013#include <tegra_def.h>
14
Puneet Saxenaab2eb452017-08-04 17:19:55 +053015/*******************************************************************************
16 * Memory Controller SMMU Bypass config register
17 ******************************************************************************/
18#define MC_SMMU_BYPASS_CONFIG 0x1820U
19#define MC_SMMU_BYPASS_CTRL_MASK 0x3U
20#define MC_SMMU_BYPASS_CTRL_SHIFT 0U
21#define MC_SMMU_CTRL_TBU_BYPASS_ALL (0U << MC_SMMU_BYPASS_CTRL_SHIFT)
22#define MC_SMMU_CTRL_TBU_RSVD (1U << MC_SMMU_BYPASS_CTRL_SHIFT)
23#define MC_SMMU_CTRL_TBU_BYPASS_SPL_STREAMID (2U << MC_SMMU_BYPASS_CTRL_SHIFT)
24#define MC_SMMU_CTRL_TBU_BYPASS_NONE (3U << MC_SMMU_BYPASS_CTRL_SHIFT)
25#define MC_SMMU_BYPASS_CONFIG_WRITE_ACCESS_BIT (1U << 31)
26#define MC_SMMU_BYPASS_CONFIG_SETTINGS (MC_SMMU_BYPASS_CONFIG_WRITE_ACCESS_BIT | \
27 MC_SMMU_CTRL_TBU_BYPASS_SPL_STREAMID)
Varun Wadekar412dd5c2015-09-20 15:08:22 +053028
Manish V Badarkhec959ea72020-10-07 16:04:06 +010029#ifndef __ASSEMBLER__
Pritesh Raithatha06803cf2017-01-02 19:42:31 +053030
Anthony Zhou2561cb52019-11-13 18:36:07 +080031#include <assert.h>
32
Pritesh Raithathaa391d492018-08-03 15:48:15 +053033typedef struct mc_regs {
34 uint32_t reg;
35 uint32_t val;
36} mc_regs_t;
37
Pritesh Raithathaa391d492018-08-03 15:48:15 +053038#define mc_smmu_bypass_cfg \
39 { \
40 .reg = TEGRA_MC_BASE + MC_SMMU_BYPASS_CONFIG, \
41 .val = 0x00000000U, \
42 }
43
44#define _START_OF_TABLE_ \
45 { \
46 .reg = 0xCAFE05C7U, \
47 .val = 0x00000000U, \
48 }
49
50#define _END_OF_TABLE_ \
51 { \
52 .reg = 0xFFFFFFFFU, \
53 .val = 0xFFFFFFFFU, \
54 }
55
Manish V Badarkhec959ea72020-10-07 16:04:06 +010056#endif /* __ASSEMBLER__ */
Varun Wadekar08e60f82019-08-26 10:20:53 -070057
Manish V Badarkhec959ea72020-10-07 16:04:06 +010058#ifndef __ASSEMBLER__
Varun Wadekar08e60f82019-08-26 10:20:53 -070059
60#include <lib/mmio.h>
Varun Wadekar412dd5c2015-09-20 15:08:22 +053061
Varun Wadekar412dd5c2015-09-20 15:08:22 +053062static inline uint32_t tegra_mc_read_32(uint32_t off)
63{
64 return mmio_read_32(TEGRA_MC_BASE + off);
65}
66
67static inline void tegra_mc_write_32(uint32_t off, uint32_t val)
68{
69 mmio_write_32(TEGRA_MC_BASE + off, val);
70}
71
Varun Wadekar21ec61a2019-09-26 08:26:41 -070072#if defined(TEGRA_MC_STREAMID_BASE)
Varun Wadekar412dd5c2015-09-20 15:08:22 +053073static inline uint32_t tegra_mc_streamid_read_32(uint32_t off)
74{
75 return mmio_read_32(TEGRA_MC_STREAMID_BASE + off);
76}
77
78static inline void tegra_mc_streamid_write_32(uint32_t off, uint32_t val)
79{
80 mmio_write_32(TEGRA_MC_STREAMID_BASE + off, val);
Anthony Zhou2561cb52019-11-13 18:36:07 +080081 assert(mmio_read_32(TEGRA_MC_STREAMID_BASE + off) == val);
Varun Wadekar412dd5c2015-09-20 15:08:22 +053082}
Varun Wadekar21ec61a2019-09-26 08:26:41 -070083#endif
Varun Wadekar412dd5c2015-09-20 15:08:22 +053084
Varun Wadekar08e60f82019-08-26 10:20:53 -070085void plat_memctrl_setup(void);
Varun Wadekare64ce3a2016-03-11 17:18:51 -080086
Varun Wadekar08e60f82019-08-26 10:20:53 -070087void plat_memctrl_restore(void);
88mc_regs_t *plat_memctrl_get_sys_suspend_ctx(void);
Pritesh Raithatha06803cf2017-01-02 19:42:31 +053089
Varun Wadekard5bd0de2017-10-30 14:35:17 -070090/*******************************************************************************
Pritesh Raithathaa391d492018-08-03 15:48:15 +053091 * Handler to save MC settings before "System Suspend" to TZDRAM
92 *
93 * Implemented by Tegra common memctrl_v2 driver under common/drivers/memctrl
94 ******************************************************************************/
95void tegra_mc_save_context(uint64_t mc_ctx_addr);
96
97/*******************************************************************************
Varun Wadekard5bd0de2017-10-30 14:35:17 -070098 * Handler to program the scratch registers with TZDRAM settings for the
99 * resume firmware.
100 *
101 * Implemented by SoCs under tegra/soc/txxx
102 ******************************************************************************/
103void plat_memctrl_tzdram_setup(uint64_t phys_base, uint64_t size_in_bytes);
104
Julius Wernerd5dfdeb2019-07-09 13:49:11 -0700105#endif /* __ASSEMBLER__ */
Varun Wadekare64ce3a2016-03-11 17:18:51 -0800106
Antonio Nino Diazc3cf06f2018-11-08 10:20:19 +0000107#endif /* MEMCTRL_V2_H */