plat_memctrl.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <common/bl_common.h>
  8. #include <mce.h>
  9. #include <memctrl_v2.h>
  10. #include <tegra_platform.h>
  11. #include <tegra_private.h>
  12. /*******************************************************************************
  13. * Array to hold MC context for Tegra194
  14. ******************************************************************************/
  15. static __attribute__((aligned(16))) mc_regs_t tegra194_mc_context[] = {
  16. _START_OF_TABLE_,
  17. mc_smmu_bypass_cfg, /* TBU settings */
  18. _END_OF_TABLE_,
  19. };
  20. /*******************************************************************************
  21. * Handler to return the pointer to the MC's context struct
  22. ******************************************************************************/
  23. mc_regs_t *plat_memctrl_get_sys_suspend_ctx(void)
  24. {
  25. /* index of _END_OF_TABLE_ */
  26. tegra194_mc_context[0].val = (uint32_t)ARRAY_SIZE(tegra194_mc_context) - 1U;
  27. return tegra194_mc_context;
  28. }
  29. /*******************************************************************************
  30. * Handler to restore platform specific settings to the memory controller
  31. ******************************************************************************/
  32. void plat_memctrl_restore(void)
  33. {
  34. UNUSED_FUNC_NOP(); /* do nothing */
  35. }
  36. /*******************************************************************************
  37. * Handler to program platform specific settings to the memory controller
  38. ******************************************************************************/
  39. void plat_memctrl_setup(void)
  40. {
  41. UNUSED_FUNC_NOP(); /* do nothing */
  42. }
  43. /*******************************************************************************
  44. * Handler to program the scratch registers with TZDRAM settings for the
  45. * resume firmware
  46. ******************************************************************************/
  47. void plat_memctrl_tzdram_setup(uint64_t phys_base, uint64_t size_in_bytes)
  48. {
  49. uint32_t sec_reg_ctrl = tegra_mc_read_32(MC_SECURITY_CFG_REG_CTRL_0);
  50. uint32_t phys_base_lo = (uint32_t)phys_base & 0xFFF00000;
  51. uint32_t phys_base_hi = (uint32_t)(phys_base >> 32);
  52. /*
  53. * Check TZDRAM carveout register access status. Setup TZDRAM fence
  54. * only if access is enabled.
  55. */
  56. if ((sec_reg_ctrl & SECURITY_CFG_WRITE_ACCESS_BIT) ==
  57. SECURITY_CFG_WRITE_ACCESS_ENABLE) {
  58. /*
  59. * Setup the Memory controller to allow only secure accesses to
  60. * the TZDRAM carveout
  61. */
  62. INFO("Configuring TrustZone DRAM Memory Carveout\n");
  63. tegra_mc_write_32(MC_SECURITY_CFG0_0, phys_base_lo);
  64. tegra_mc_write_32(MC_SECURITY_CFG3_0, phys_base_hi);
  65. tegra_mc_write_32(MC_SECURITY_CFG1_0, (uint32_t)(size_in_bytes >> 20));
  66. /*
  67. * MCE propagates the security configuration values across the
  68. * CCPLEX.
  69. */
  70. (void)mce_update_gsc_tzdram();
  71. }
  72. }