blob: 9af3027ea3ae9aaf22aa508da50b837fd5308fff [file] [log] [blame]
Varun Wadekarcd5a2f52015-09-20 15:08:22 +05301/*
Manish V Badarkhe07538b52020-10-07 16:04:06 +01002 * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
Varun Wadekard4a698f2019-08-26 10:20:53 -07003 * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
Varun Wadekarcd5a2f52015-09-20 15:08:22 +05304 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekarcd5a2f52015-09-20 15:08:22 +05306 */
7
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00008#ifndef MEMCTRL_V2_H
9#define MEMCTRL_V2_H
Varun Wadekarcd5a2f52015-09-20 15:08:22 +053010
Varun Wadekard4a698f2019-08-26 10:20:53 -070011#include <arch.h>
Varun Wadekarcd5a2f52015-09-20 15:08:22 +053012
Varun Wadekard4a698f2019-08-26 10:20:53 -070013#include <tegra_def.h>
Puneet Saxenacf8c0e22017-08-04 17:19:55 +053014
15/*******************************************************************************
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 Wadekarcd5a2f52015-09-20 15:08:22 +053028
Manish V Badarkhe07538b52020-10-07 16:04:06 +010029#ifndef __ASSEMBLER__
Pritesh Raithatha9eb5db52017-01-02 19:42:31 +053030
Anthony Zhou9de77f62019-11-13 18:36:07 +080031#include <assert.h>
32
Pritesh Raithatha75c94432018-08-03 15:48:15 +053033typedef struct mc_regs {
34 uint32_t reg;
35 uint32_t val;
36} mc_regs_t;
37
Pritesh Raithatha75c94432018-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 Badarkhe07538b52020-10-07 16:04:06 +010056#endif /* __ASSEMBLER__ */
Varun Wadekard4a698f2019-08-26 10:20:53 -070057
Manish V Badarkhe07538b52020-10-07 16:04:06 +010058#ifndef __ASSEMBLER__
Varun Wadekard4a698f2019-08-26 10:20:53 -070059
60#include <lib/mmio.h>
Varun Wadekarcd5a2f52015-09-20 15:08:22 +053061
Varun Wadekarcd5a2f52015-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 Wadekar82b0b182019-09-26 08:26:41 -070072#if defined(TEGRA_MC_STREAMID_BASE)
Varun Wadekarcd5a2f52015-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 Zhou9de77f62019-11-13 18:36:07 +080081 assert(mmio_read_32(TEGRA_MC_STREAMID_BASE + off) == val);
Varun Wadekarcd5a2f52015-09-20 15:08:22 +053082}
Varun Wadekar82b0b182019-09-26 08:26:41 -070083#endif
Varun Wadekarcd5a2f52015-09-20 15:08:22 +053084
Varun Wadekard4a698f2019-08-26 10:20:53 -070085void plat_memctrl_setup(void);
Varun Wadekara0f26972016-03-11 17:18:51 -080086
Varun Wadekard4a698f2019-08-26 10:20:53 -070087void plat_memctrl_restore(void);
88mc_regs_t *plat_memctrl_get_sys_suspend_ctx(void);
Pritesh Raithatha9eb5db52017-01-02 19:42:31 +053089
Varun Wadekarf3cd5092017-10-30 14:35:17 -070090/*******************************************************************************
Pritesh Raithatha75c94432018-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 Wadekarf3cd5092017-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 Werner53456fc2019-07-09 13:49:11 -0700105#endif /* __ASSEMBLER__ */
Varun Wadekara0f26972016-03-11 17:18:51 -0800106
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000107#endif /* MEMCTRL_V2_H */