blob: f223f7ba2d5740965376e26e514073b278c43132 [file] [log] [blame]
Varun Wadekar00759902017-05-31 11:41:00 -07001/*
Pritesh Raithatha45ea6892017-12-18 23:00:05 -08002 * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
Varun Wadekar00759902017-05-31 11:41:00 -07003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Varun Wadekar128f46a2019-10-24 16:06:12 -07007#include <assert.h>
8#include <common/bl_common.h>
9#include <mce.h>
Varun Wadekar00759902017-05-31 11:41:00 -070010#include <memctrl_v2.h>
Varun Wadekar128f46a2019-10-24 16:06:12 -070011#include <tegra_mc_def.h>
12#include <tegra_platform.h>
Varun Wadekar00759902017-05-31 11:41:00 -070013
14/*******************************************************************************
Pritesh Raithatha75c94432018-08-03 15:48:15 +053015 * Array to hold MC context for Tegra194
16 ******************************************************************************/
17static __attribute__((aligned(16))) mc_regs_t tegra194_mc_context[] = {
18 _START_OF_TABLE_,
Pritesh Raithatha75c94432018-08-03 15:48:15 +053019 mc_smmu_bypass_cfg, /* TBU settings */
20 _END_OF_TABLE_,
21};
22
23/*******************************************************************************
24 * Handler to return the pointer to the MC's context struct
25 ******************************************************************************/
26static mc_regs_t *tegra194_get_mc_system_suspend_ctx(void)
27{
28 /* index of _END_OF_TABLE_ */
29 tegra194_mc_context[0].val = (uint32_t)ARRAY_SIZE(tegra194_mc_context) - 1U;
30
31 return tegra194_mc_context;
32}
33
34/*******************************************************************************
Varun Wadekar00759902017-05-31 11:41:00 -070035 * Struct to hold the memory controller settings
36 ******************************************************************************/
37static tegra_mc_settings_t tegra194_mc_settings = {
Pritesh Raithatha75c94432018-08-03 15:48:15 +053038 .get_mc_system_suspend_ctx = tegra194_get_mc_system_suspend_ctx
Varun Wadekar00759902017-05-31 11:41:00 -070039};
40
41/*******************************************************************************
42 * Handler to return the pointer to the memory controller's settings struct
43 ******************************************************************************/
44tegra_mc_settings_t *tegra_get_mc_settings(void)
45{
46 return &tegra194_mc_settings;
Steven Kaoee93ed12017-11-14 19:12:58 +080047}
48
49/*******************************************************************************
50 * Handler to program the scratch registers with TZDRAM settings for the
51 * resume firmware
52 ******************************************************************************/
53void plat_memctrl_tzdram_setup(uint64_t phys_base, uint64_t size_in_bytes)
54{
Steven Kaob2b43052017-11-30 11:53:29 +080055 uint32_t sec_reg_ctrl = tegra_mc_read_32(MC_SECURITY_CFG_REG_CTRL_0);
Varun Wadekar22ddd8a2019-04-22 16:12:30 -070056 uint32_t phys_base_lo = (uint32_t)phys_base & 0xFFF00000;
57 uint32_t phys_base_hi = (uint32_t)(phys_base >> 32);
Steven Kaob2b43052017-11-30 11:53:29 +080058
Steven Kaoee93ed12017-11-14 19:12:58 +080059 /*
Steven Kaob2b43052017-11-30 11:53:29 +080060 * Check TZDRAM carveout register access status. Setup TZDRAM fence
61 * only if access is enabled.
Steven Kaoee93ed12017-11-14 19:12:58 +080062 */
Steven Kaob2b43052017-11-30 11:53:29 +080063 if ((sec_reg_ctrl & SECURITY_CFG_WRITE_ACCESS_BIT) ==
64 SECURITY_CFG_WRITE_ACCESS_ENABLE) {
Steven Kaoee93ed12017-11-14 19:12:58 +080065
66 /*
67 * Setup the Memory controller to allow only secure accesses to
68 * the TZDRAM carveout
69 */
70 INFO("Configuring TrustZone DRAM Memory Carveout\n");
71
Varun Wadekar22ddd8a2019-04-22 16:12:30 -070072 tegra_mc_write_32(MC_SECURITY_CFG0_0, phys_base_lo);
73 tegra_mc_write_32(MC_SECURITY_CFG3_0, phys_base_hi);
Steven Kaoee93ed12017-11-14 19:12:58 +080074 tegra_mc_write_32(MC_SECURITY_CFG1_0, (uint32_t)(size_in_bytes >> 20));
75
76 /*
77 * MCE propagates the security configuration values across the
78 * CCPLEX.
79 */
80 (void)mce_update_gsc_tzdram();
81 }
82}