juno_security.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (c) 2014-2023, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <common/debug.h>
  8. #include <drivers/arm/nic_400.h>
  9. #include <lib/mmio.h>
  10. #include <platform_def.h>
  11. #include <plat/arm/common/plat_arm.h>
  12. #include <plat/arm/soc/common/soc_css.h>
  13. #include <plat/common/platform.h>
  14. #include "juno_ethosn_tzmp1_def.h"
  15. #include "juno_tzmp1_def.h"
  16. #ifdef JUNO_TZMP1
  17. /*
  18. * Protect buffer for VPU/GPU/DPU memory usage with hardware protection
  19. * enabled. Propose 224MB video output, 96 MB video input and 32MB video
  20. * private.
  21. *
  22. * Ind Memory Range Caption S_ATTR NS_ATTR
  23. * 1 0x080000000 - 0x0E7FFFFFF ARM_NS_DRAM1 NONE RDWR | MEDIA_RW
  24. * 2 0x0E8000000 - 0x0F5FFFFFF JUNO_MEDIA_TZC_PROT_DRAM1 NONE MEDIA_RW | AP_WR
  25. * 3 0x0F6000000 - 0x0FBFFFFFF JUNO_VPU_TZC_PROT_DRAM1 RDWR VPU_PROT_RW
  26. * 4 0x0FC000000 - 0x0FDFFFFFF JUNO_VPU_TZC_PRIV_DRAM1 RDWR VPU_PRIV_RW
  27. * 5 0x0FE000000 - 0x0FEFFFFFF JUNO_AP_TZC_SHARE_DRAM1 NONE RDWR | MEDIA_RW
  28. * 6 0x0FF000000 - 0x0FFFFFFFF ARM_AP_TZC_DRAM1 RDWR NONE
  29. * 7 0x880000000 - 0x9FFFFFFFF ARM_DRAM2 NONE RDWR | MEDIA_RW
  30. *
  31. * Memory regions are neighbored to save limited TZC regions. Calculation
  32. * started from ARM_TZC_SHARE_DRAM1 since it is known and fixed for both
  33. * protected-enabled and protected-disabled settings.
  34. *
  35. * Video private buffer aheads of ARM_TZC_SHARE_DRAM1
  36. */
  37. static const arm_tzc_regions_info_t juno_tzmp1_tzc_regions[] = {
  38. {ARM_AP_TZC_DRAM1_BASE, ARM_AP_TZC_DRAM1_END, TZC_REGION_S_RDWR, 0},
  39. {JUNO_NS_DRAM1_PT1_BASE, JUNO_NS_DRAM1_PT1_END,
  40. TZC_REGION_S_NONE, JUNO_MEDIA_TZC_NS_DEV_ACCESS},
  41. {JUNO_MEDIA_TZC_PROT_DRAM1_BASE, JUNO_MEDIA_TZC_PROT_DRAM1_END,
  42. TZC_REGION_S_NONE, JUNO_MEDIA_TZC_PROT_ACCESS},
  43. {JUNO_VPU_TZC_PROT_DRAM1_BASE, JUNO_VPU_TZC_PROT_DRAM1_END,
  44. TZC_REGION_S_RDWR, JUNO_VPU_TZC_PROT_ACCESS},
  45. {JUNO_VPU_TZC_PRIV_DRAM1_BASE, JUNO_VPU_TZC_PRIV_DRAM1_END,
  46. TZC_REGION_S_RDWR, JUNO_VPU_TZC_PRIV_ACCESS},
  47. {JUNO_AP_TZC_SHARE_DRAM1_BASE, JUNO_AP_TZC_SHARE_DRAM1_END,
  48. TZC_REGION_S_NONE, JUNO_MEDIA_TZC_NS_DEV_ACCESS},
  49. {ARM_DRAM2_BASE, ARM_DRAM2_END,
  50. TZC_REGION_S_NONE, JUNO_MEDIA_TZC_NS_DEV_ACCESS},
  51. {},
  52. };
  53. /*******************************************************************************
  54. * Program dp650 to configure NSAID value for protected mode.
  55. ******************************************************************************/
  56. static void init_dp650(void)
  57. {
  58. mmio_write_32(DP650_BASE + DP650_PROT_NSAID_OFFSET,
  59. DP650_PROT_NSAID_CONFIG);
  60. }
  61. /*******************************************************************************
  62. * Program v550 to configure NSAID value for protected mode.
  63. ******************************************************************************/
  64. static void init_v550(void)
  65. {
  66. /*
  67. * bits[31:28] is for PRIVATE,
  68. * bits[27:24] is for OUTBUF,
  69. * bits[23:20] is for PROTECTED.
  70. */
  71. mmio_write_32(V550_BASE + V550_PROTCTRL_OFFSET, V550_PROTCTRL_CONFIG);
  72. }
  73. #endif /* JUNO_TZMP1 */
  74. #ifdef JUNO_ETHOSN_TZMP1
  75. static const arm_tzc_regions_info_t juno_ethosn_tzmp1_tzc_regions[] = {
  76. JUNO_ETHOSN_TZMP_REGIONS_DEF,
  77. {},
  78. };
  79. #endif /* JUNO_ETHOSN_TZMP1 */
  80. /*******************************************************************************
  81. * Set up the MMU-401 SSD tables. The power-on configuration has all stream IDs
  82. * assigned to Non-Secure except some for the DMA-330. Assign those back to the
  83. * Non-Secure world as well, otherwise EL1 may end up erroneously generating
  84. * (untranslated) Secure transactions if it turns the SMMU on.
  85. ******************************************************************************/
  86. static void init_mmu401(void)
  87. {
  88. uint32_t reg = mmio_read_32(MMU401_DMA330_BASE + MMU401_SSD_OFFSET);
  89. reg |= 0x1FF;
  90. mmio_write_32(MMU401_DMA330_BASE + MMU401_SSD_OFFSET, reg);
  91. }
  92. /*******************************************************************************
  93. * Program CSS-NIC400 to allow non-secure access to some CSS regions.
  94. ******************************************************************************/
  95. static void css_init_nic400(void)
  96. {
  97. /* Note: This is the NIC-400 device on the CSS */
  98. mmio_write_32(PLAT_SOC_CSS_NIC400_BASE +
  99. NIC400_ADDR_CTRL_SECURITY_REG(CSS_NIC400_SLAVE_BOOTSECURE),
  100. ~0);
  101. }
  102. /*******************************************************************************
  103. * Initialize debug configuration.
  104. ******************************************************************************/
  105. static void init_debug_cfg(void)
  106. {
  107. #if !DEBUG
  108. /* Set internal drive selection for SPIDEN. */
  109. mmio_write_32(SSC_REG_BASE + SSC_DBGCFG_SET,
  110. 1U << SPIDEN_SEL_SET_SHIFT);
  111. /* Drive SPIDEN LOW to disable invasive debug of secure state. */
  112. mmio_write_32(SSC_REG_BASE + SSC_DBGCFG_CLR,
  113. 1U << SPIDEN_INT_CLR_SHIFT);
  114. /* Set internal drive selection for SPNIDEN. */
  115. mmio_write_32(SSC_REG_BASE + SSC_DBGCFG_SET,
  116. 1U << SPNIDEN_SEL_SET_SHIFT);
  117. /* Drive SPNIDEN LOW to disable non-invasive debug of secure state. */
  118. mmio_write_32(SSC_REG_BASE + SSC_DBGCFG_CLR,
  119. 1U << SPNIDEN_INT_CLR_SHIFT);
  120. #endif
  121. }
  122. /*******************************************************************************
  123. * Initialize the secure environment.
  124. ******************************************************************************/
  125. void plat_arm_security_setup(void)
  126. {
  127. /* Initialize debug configuration */
  128. init_debug_cfg();
  129. /* Initialize the TrustZone Controller */
  130. #ifdef JUNO_TZMP1
  131. arm_tzc400_setup(PLAT_ARM_TZC_BASE, juno_tzmp1_tzc_regions);
  132. INFO("TZC protected shared memory base address for TZMP usecase: %p\n",
  133. (void *)JUNO_AP_TZC_SHARE_DRAM1_BASE);
  134. INFO("TZC protected shared memory end address for TZMP usecase: %p\n",
  135. (void *)JUNO_AP_TZC_SHARE_DRAM1_END);
  136. #elif defined(JUNO_ETHOSN_TZMP1)
  137. arm_tzc400_setup(PLAT_ARM_TZC_BASE, juno_ethosn_tzmp1_tzc_regions);
  138. INFO("TZC protected shared memory range for NPU TZMP usecase: %p - %p\n",
  139. (void *)JUNO_ETHOSN_NS_DRAM2_BASE,
  140. (void *)JUNO_ETHOSN_NS_DRAM2_END);
  141. INFO("TZC protected Data memory range for NPU TZMP usecase: %p - %p\n",
  142. (void *)JUNO_ETHOSN_DATA_TZC_PROT_DRAM2_BASE,
  143. (void *)JUNO_ETHOSN_DATA_TZC_PROT_DRAM2_END);
  144. INFO("TZC protected FW memory range for NPU TZMP usecase: %p - %p\n",
  145. (void *)JUNO_ETHOSN_FW_TZC_PROT_DRAM2_BASE,
  146. (void *)JUNO_ETHOSN_FW_TZC_PROT_DRAM2_END);
  147. #else
  148. arm_tzc400_setup(PLAT_ARM_TZC_BASE, NULL);
  149. #endif
  150. /* Do ARM CSS internal NIC setup */
  151. css_init_nic400();
  152. /* Do ARM CSS SoC security setup */
  153. soc_css_security_setup();
  154. /* Initialize the SMMU SSD tables */
  155. init_mmu401();
  156. #ifdef JUNO_TZMP1
  157. init_dp650();
  158. init_v550();
  159. #endif
  160. }
  161. #if TRUSTED_BOARD_BOOT
  162. int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size)
  163. {
  164. assert(heap_addr != NULL);
  165. assert(heap_size != NULL);
  166. return arm_get_mbedtls_heap(heap_addr, heap_size);
  167. }
  168. #endif