bl2_secure_setting.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*
  2. * Copyright (c) 2015-2023, Renesas Electronics Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <lib/mmio.h>
  7. #include <lib/utils_def.h>
  8. #include "axi_registers.h"
  9. #include "lifec_registers.h"
  10. #include "micro_delay.h"
  11. static void lifec_security_setting(void);
  12. static void axi_security_setting(void);
  13. static const struct {
  14. uint32_t reg;
  15. uint32_t val;
  16. } lifec[] = {
  17. /*
  18. * LIFEC0 (SECURITY) settings
  19. * Security attribute setting for master ports
  20. * Bit 0: ARM realtime core (Cortex-R7) master port
  21. * 0: Non-Secure
  22. */
  23. { SEC_SRC, 0x0000001EU },
  24. /*
  25. * Security attribute setting for slave ports 0 to 15
  26. * {SEC_SEL0, 0xFFFFFFFFU},
  27. * {SEC_SEL1, 0xFFFFFFFFU},
  28. * {SEC_SEL2, 0xFFFFFFFFU},
  29. * Bit19: AXI-Bus (Main Memory domain AXI) slave ports
  30. * 0: registers accessed from secure resource only
  31. * Bit 9: DBSC4 register access slave ports.
  32. * 0: registers accessed from secure resource only.
  33. */
  34. #if (LIFEC_DBSC_PROTECT_ENABLE == 1)
  35. { SEC_SEL3, 0xFFF7FDFFU },
  36. #else /* LIFEC_DBSC_PROTECT_ENABLE == 1 */
  37. { SEC_SEL3, 0xFFFFFFFFU },
  38. #endif /* LIFEC_DBSC_PROTECT_ENABLE == 1 */
  39. /*
  40. * {SEC_SEL4, 0xFFFFFFFFU},
  41. * Bit 6: Boot ROM slave ports.
  42. * 0: registers accessed from secure resource only
  43. */
  44. { SEC_SEL5, 0xFFFFFFBFU },
  45. /*
  46. * Bit13: SCEG PKA (secure APB) slave ports
  47. * 0: registers accessed from secure resource only
  48. * 1: Reserved[R-Car E3/D3]
  49. * Bit12: SCEG PKA (public APB) slave ports
  50. * 0: registers accessed from secure resource only
  51. * 1: Reserved[R-Car E3/D3]
  52. * Bit10: SCEG Secure Core slave ports
  53. * 0: registers accessed from secure resource only
  54. */
  55. #if (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RCAR_D3)
  56. { SEC_SEL6, 0xFFFFFBFFU },
  57. #else /* (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RCAR_D3) */
  58. { SEC_SEL6, 0xFFFFCBFFU },
  59. #endif /* (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RCAR_D3) */
  60. /*
  61. * {SEC_SEL7, 0xFFFFFFFFU},
  62. * {SEC_SEL8, 0xFFFFFFFFU},
  63. * {SEC_SEL9, 0xFFFFFFFFU},
  64. * {SEC_SEL10, 0xFFFFFFFFU},
  65. * {SEC_SEL11, 0xFFFFFFFFU},
  66. * {SEC_SEL12, 0xFFFFFFFFU},
  67. * Bit22: RPC slave ports.
  68. * 0: registers accessed from secure resource only.
  69. */
  70. #if (RCAR_RPC_HYPERFLASH_LOCKED == 1)
  71. { SEC_SEL13, 0xFFBFFFFFU },
  72. #endif /* (RCAR_RPC_HYPERFLASH_LOCKED == 1) */
  73. /*
  74. * Bit27: System Timer (SCMT) slave ports
  75. * 0: registers accessed from secure resource only
  76. * Bit26: System Watchdog Timer (SWDT) slave ports
  77. * 0: registers accessed from secure resource only
  78. */
  79. { SEC_SEL14, 0xF3FFFFFFU },
  80. /*
  81. * Bit13: RST slave ports.
  82. * 0: registers accessed from secure resource only
  83. * Bit 7: Life Cycle 0 slave ports
  84. * 0: registers accessed from secure resource only
  85. */
  86. { SEC_SEL15, 0xFFFFFF3FU },
  87. /*
  88. * Security group 0 attribute setting for master ports 0
  89. * Security group 1 attribute setting for master ports 0
  90. * {SEC_GRP0CR0, 0x00000000U},
  91. * {SEC_GRP1CR0, 0x00000000U},
  92. * Security group 0 attribute setting for master ports 1
  93. * Security group 1 attribute setting for master ports 1
  94. * {SEC_GRP0CR1, 0x00000000U},
  95. * {SEC_GRP1CR1, 0x00000000U},
  96. * Security group 0 attribute setting for master ports 2
  97. * Security group 1 attribute setting for master ports 2
  98. * Bit17: SCEG Secure Core master ports.
  99. * SecurityGroup3
  100. */
  101. { SEC_GRP0CR2, 0x00020000U },
  102. { SEC_GRP1CR2, 0x00020000U },
  103. /*
  104. * Security group 0 attribute setting for master ports 3
  105. * Security group 1 attribute setting for master ports 3
  106. */
  107. { SEC_GRP0CR3, 0x00003780U },
  108. { SEC_GRP1CR3, 0x00003780U },
  109. /*
  110. * Security group 0 attribute setting for slave ports 0
  111. * Security group 1 attribute setting for slave ports 0
  112. * {SEC_GRP0COND0, 0x00000000U},
  113. * {SEC_GRP1COND0, 0x00000000U},
  114. * Security group 0 attribute setting for slave ports 1
  115. * Security group 1 attribute setting for slave ports 1
  116. * {SEC_GRP0COND1, 0x00000000U},
  117. * {SEC_GRP1COND1, 0x00000000U},
  118. * Security group 0 attribute setting for slave ports 2
  119. * Security group 1 attribute setting for slave ports 2
  120. * {SEC_GRP0COND2, 0x00000000U},
  121. * {SEC_GRP1COND2, 0x00000000U},
  122. * Security group 0 attribute setting for slave ports 3
  123. * Security group 1 attribute setting for slave ports 3
  124. * Bit19: AXI-Bus (Main Memory domain AXI) slave ports.
  125. * SecurityGroup3
  126. * Bit 9: DBSC4 register access slave ports.
  127. * SecurityGroup3
  128. */
  129. #if (LIFEC_DBSC_PROTECT_ENABLE == 1)
  130. { SEC_GRP0COND3, 0x00080200U },
  131. { SEC_GRP1COND3, 0x00080200U },
  132. #else /* (LIFEC_DBSC_PROTECT_ENABLE == 1) */
  133. { SEC_GRP0COND3, 0x00000000U },
  134. { SEC_GRP1COND3, 0x00000000U },
  135. #endif /* (LIFEC_DBSC_PROTECT_ENABLE == 1) */
  136. /*
  137. * Security group 0 attribute setting for slave ports 4
  138. * Security group 1 attribute setting for slave ports 4
  139. * {SEC_GRP0COND4, 0x00000000U},
  140. * {SEC_GRP1COND4, 0x00000000U},
  141. * Security group 0 attribute setting for slave ports 5
  142. * Security group 1 attribute setting for slave ports 5
  143. * Bit 6: Boot ROM slave ports
  144. * SecurityGroup3
  145. */
  146. { SEC_GRP0COND5, 0x00000040U },
  147. { SEC_GRP1COND5, 0x00000040U },
  148. /*
  149. * Security group 0 attribute setting for slave ports 6
  150. * Security group 1 attribute setting for slave ports 6
  151. * Bit13: SCEG PKA (secure APB) slave ports
  152. * SecurityGroup3
  153. * Reserved[R-Car E3/D3]
  154. * Bit12: SCEG PKA (public APB) slave ports
  155. * SecurityGroup3
  156. * Reserved[R-Car E3/D3]
  157. * Bit10: SCEG Secure Core slave ports
  158. * SecurityGroup3
  159. */
  160. #if RCAR_LSI == RCAR_E3 || RCAR_LSI == RCAR_D3
  161. { SEC_GRP0COND6, 0x00000400U },
  162. { SEC_GRP1COND6, 0x00000400U },
  163. #else /* RCAR_LSI == RCAR_E3 */
  164. { SEC_GRP0COND6, 0x00003400U },
  165. { SEC_GRP1COND6, 0x00003400U },
  166. #endif /* RCAR_LSI == RCAR_E3 */
  167. /*
  168. * Security group 0 attribute setting for slave ports 7
  169. * Security group 1 attribute setting for slave ports 7
  170. * {SEC_GRP0COND7, 0x00000000U},
  171. * {SEC_GRP1COND7, 0x00000000U},
  172. * Security group 0 attribute setting for slave ports 8
  173. * Security group 1 attribute setting for slave ports 8
  174. * {SEC_GRP0COND8, 0x00000000U},
  175. * {SEC_GRP1COND8, 0x00000000U},
  176. * Security group 0 attribute setting for slave ports 9
  177. * Security group 1 attribute setting for slave ports 9
  178. * {SEC_GRP0COND9, 0x00000000U},
  179. * {SEC_GRP1COND9, 0x00000000U},
  180. * Security group 0 attribute setting for slave ports 10
  181. * Security group 1 attribute setting for slave ports 10
  182. * {SEC_GRP0COND10, 0x00000000U},
  183. * {SEC_GRP1COND10, 0x00000000U},
  184. * Security group 0 attribute setting for slave ports 11
  185. * Security group 1 attribute setting for slave ports 11
  186. * {SEC_GRP0COND11, 0x00000000U},
  187. * {SEC_GRP1COND11, 0x00000000U},
  188. * Security group 0 attribute setting for slave ports 12
  189. * Security group 1 attribute setting for slave ports 12
  190. * {SEC_GRP0COND12, 0x00000000U},
  191. * {SEC_GRP1COND12, 0x00000000U},
  192. * Security group 0 attribute setting for slave ports 13
  193. * Security group 1 attribute setting for slave ports 13
  194. * Bit22: RPC slave ports.
  195. * SecurityGroup3
  196. */
  197. #if (RCAR_RPC_HYPERFLASH_LOCKED == 1)
  198. { SEC_GRP0COND13, 0x00400000U },
  199. { SEC_GRP1COND13, 0x00400000U },
  200. #endif /* (RCAR_RPC_HYPERFLASH_LOCKED == 1) */
  201. /*
  202. * Security group 0 attribute setting for slave ports 14
  203. * Security group 1 attribute setting for slave ports 14
  204. * Bit26: System Timer (SCMT) slave ports
  205. * SecurityGroup3
  206. * Bit27: System Watchdog Timer (SWDT) slave ports
  207. * SecurityGroup3
  208. */
  209. { SEC_GRP0COND14, 0x0C000000U },
  210. { SEC_GRP1COND14, 0x0C000000U },
  211. /*
  212. * Security group 0 attribute setting for slave ports 15
  213. * Security group 1 attribute setting for slave ports 15
  214. * Bit13: RST slave ports
  215. * SecurityGroup3
  216. * Bit 7: Life Cycle 0 slave ports
  217. * SecurityGroup3
  218. * Bit 6: TDBG slave ports
  219. * SecurityGroup3
  220. */
  221. { SEC_GRP0COND15, 0x000000C0U },
  222. { SEC_GRP1COND15, 0x000000C0U },
  223. /*
  224. * Security write protection attribute setting slave ports 0
  225. * {SEC_READONLY0, 0x00000000U},
  226. * Security write protection attribute setting slave ports 1
  227. * {SEC_READONLY1, 0x00000000U},
  228. * Security write protection attribute setting slave ports 2
  229. * {SEC_READONLY2, 0x00000000U},
  230. * Security write protection attribute setting slave ports 3
  231. * {SEC_READONLY3, 0x00000000U},
  232. * Security write protection attribute setting slave ports 4
  233. * {SEC_READONLY4, 0x00000000U},
  234. * Security write protection attribute setting slave ports 5
  235. * {SEC_READONLY5, 0x00000000U},
  236. * Security write protection attribute setting slave ports 6
  237. * {SEC_READONLY6, 0x00000000U},
  238. * Security write protection attribute setting slave ports 7
  239. * {SEC_READONLY7, 0x00000000U},
  240. * Security write protection attribute setting slave ports 8
  241. * {SEC_READONLY8, 0x00000000U},
  242. * Security write protection attribute setting slave ports 9
  243. * {SEC_READONLY9, 0x00000000U},
  244. * Security write protection attribute setting slave ports 10
  245. * {SEC_READONLY10, 0x00000000U},
  246. * Security write protection attribute setting slave ports 11
  247. * {SEC_READONLY11, 0x00000000U},
  248. * Security write protection attribute setting slave ports 12
  249. * {SEC_READONLY12, 0x00000000U},
  250. * Security write protection attribute setting slave ports 13
  251. * {SEC_READONLY13, 0x00000000U},
  252. * Security write protection attribute setting slave ports 14
  253. * {SEC_READONLY14, 0x00000000U},
  254. * Security write protection attribute setting slave ports 15
  255. * {SEC_READONLY15, 0x00000000U}
  256. */
  257. };
  258. /* AXI settings */
  259. struct axi_t {
  260. uint32_t reg;
  261. uint32_t val;
  262. };
  263. static const struct axi_t axi[] = {
  264. /*
  265. * SRAM ptotection
  266. * AXI sram protected area division
  267. */
  268. {AXI_SPTDIVCR0, 0x0E0E6304U},
  269. {AXI_SPTDIVCR1, 0x0E0E6360U},
  270. {AXI_SPTDIVCR2, 0x0E0E6360U},
  271. {AXI_SPTDIVCR3, 0x0E0E6360U},
  272. {AXI_SPTDIVCR4, 0x0E0E6360U},
  273. {AXI_SPTDIVCR5, 0x0E0E6360U},
  274. {AXI_SPTDIVCR6, 0x0E0E6360U},
  275. {AXI_SPTDIVCR7, 0x0E0E6360U},
  276. {AXI_SPTDIVCR8, 0x0E0E6360U},
  277. {AXI_SPTDIVCR9, 0x0E0E6360U},
  278. {AXI_SPTDIVCR10, 0x0E0E6360U},
  279. {AXI_SPTDIVCR11, 0x0E0E6360U},
  280. {AXI_SPTDIVCR12, 0x0E0E6360U},
  281. {AXI_SPTDIVCR13, 0x0E0E6360U},
  282. {AXI_SPTDIVCR14, 0x0E0E6360U},
  283. /* AXI sram protected area setting */
  284. {AXI_SPTCR0, 0x0E000E0EU},
  285. {AXI_SPTCR1, 0x0E000000U},
  286. {AXI_SPTCR2, 0x0E000000U},
  287. {AXI_SPTCR3, 0x0E000000U},
  288. {AXI_SPTCR4, 0x0E000000U},
  289. {AXI_SPTCR5, 0x0E000000U},
  290. {AXI_SPTCR6, 0x0E000000U},
  291. {AXI_SPTCR7, 0x0E000000U},
  292. {AXI_SPTCR8, 0x0E000000U},
  293. {AXI_SPTCR9, 0x0E000000U},
  294. {AXI_SPTCR10, 0x0E000000U},
  295. {AXI_SPTCR11, 0x0E000000U},
  296. {AXI_SPTCR12, 0x0E000000U},
  297. {AXI_SPTCR13, 0x0E000000U},
  298. {AXI_SPTCR14, 0x0E000000U},
  299. {AXI_SPTCR15, 0x0E000000U}
  300. };
  301. static const struct axi_t axi_dram[] = {
  302. /*
  303. * DRAM protection
  304. * AXI dram protected area division
  305. */
  306. {AXI_DPTDIVCR0, 0x0E0403F0U},
  307. {AXI_DPTDIVCR1, 0x0E0407E0U},
  308. {AXI_DPTDIVCR2, 0x0E080000U},
  309. {AXI_DPTDIVCR3, 0x0E080000U},
  310. {AXI_DPTDIVCR4, 0x0E080000U},
  311. {AXI_DPTDIVCR5, 0x0E080000U},
  312. {AXI_DPTDIVCR6, 0x0E080000U},
  313. {AXI_DPTDIVCR7, 0x0E080000U},
  314. {AXI_DPTDIVCR8, 0x0E080000U},
  315. {AXI_DPTDIVCR9, 0x0E080000U},
  316. {AXI_DPTDIVCR10, 0x0E080000U},
  317. {AXI_DPTDIVCR11, 0x0E080000U},
  318. {AXI_DPTDIVCR12, 0x0E080000U},
  319. {AXI_DPTDIVCR13, 0x0E080000U},
  320. {AXI_DPTDIVCR14, 0x0E080000U},
  321. /* AXI dram protected area setting */
  322. {AXI_DPTCR0, 0x0E000000U},
  323. {AXI_DPTCR1, 0x0E000E0EU},
  324. {AXI_DPTCR2, 0x0E000000U},
  325. {AXI_DPTCR3, 0x0E000000U},
  326. {AXI_DPTCR4, 0x0E000000U},
  327. {AXI_DPTCR5, 0x0E000000U},
  328. {AXI_DPTCR6, 0x0E000000U},
  329. {AXI_DPTCR7, 0x0E000000U},
  330. {AXI_DPTCR8, 0x0E000000U},
  331. {AXI_DPTCR9, 0x0E000000U},
  332. {AXI_DPTCR10, 0x0E000000U},
  333. {AXI_DPTCR11, 0x0E000000U},
  334. {AXI_DPTCR12, 0x0E000000U},
  335. {AXI_DPTCR13, 0x0E000000U},
  336. {AXI_DPTCR14, 0x0E000000U},
  337. {AXI_DPTCR15, 0x0E000000U},
  338. /* AXI sram protected area setting */
  339. {AXI_SPTCR15, 0x0E000000U}
  340. };
  341. static void lifec_security_setting(void)
  342. {
  343. uint32_t i;
  344. for (i = 0; i < ARRAY_SIZE(lifec); i++)
  345. mmio_write_32(lifec[i].reg, lifec[i].val);
  346. }
  347. /* SRAM protection setting */
  348. static void axi_security_setting(void)
  349. {
  350. uint32_t i;
  351. for (i = 0; i < ARRAY_SIZE(axi); i++)
  352. mmio_write_32(axi[i].reg, axi[i].val);
  353. }
  354. /* DRAM protection setting */
  355. void bl2_ram_security_setting_finish(void)
  356. {
  357. uint32_t i;
  358. for (i = 0; i < ARRAY_SIZE(axi_dram); i++)
  359. mmio_write_32(axi_dram[i].reg, axi_dram[i].val);
  360. }
  361. void bl2_secure_setting(void)
  362. {
  363. lifec_security_setting();
  364. axi_security_setting();
  365. rcar_micro_delay(10U);
  366. }