stm32mp2_private.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * Copyright (c) 2023-2024, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <lib/xlat_tables/xlat_tables_v2.h>
  8. #include <platform_def.h>
  9. #define BKPR_BOOT_MODE 96U
  10. #if defined(IMAGE_BL31)
  11. /* BL31 only uses the first half of the SYSRAM */
  12. #define MAP_SYSRAM MAP_REGION_FLAT(STM32MP_SYSRAM_BASE, \
  13. STM32MP_SYSRAM_SIZE / 2U, \
  14. MT_MEMORY | \
  15. MT_RW | \
  16. MT_SECURE | \
  17. MT_EXECUTE_NEVER)
  18. #else
  19. #define MAP_SYSRAM MAP_REGION_FLAT(STM32MP_SYSRAM_BASE, \
  20. STM32MP_SYSRAM_SIZE, \
  21. MT_MEMORY | \
  22. MT_RW | \
  23. MT_SECURE | \
  24. MT_EXECUTE_NEVER)
  25. #endif
  26. #if STM32MP_DDR_FIP_IO_STORAGE
  27. #define MAP_SRAM1 MAP_REGION_FLAT(SRAM1_BASE, \
  28. SRAM1_SIZE_FOR_TFA, \
  29. MT_MEMORY | \
  30. MT_RW | \
  31. MT_SECURE | \
  32. MT_EXECUTE_NEVER)
  33. #endif
  34. #define MAP_DEVICE MAP_REGION_FLAT(STM32MP_DEVICE_BASE, \
  35. STM32MP_DEVICE_SIZE, \
  36. MT_DEVICE | \
  37. MT_RW | \
  38. MT_SECURE | \
  39. MT_EXECUTE_NEVER)
  40. #if defined(IMAGE_BL2)
  41. static const mmap_region_t stm32mp2_mmap[] = {
  42. MAP_SYSRAM,
  43. #if STM32MP_DDR_FIP_IO_STORAGE
  44. MAP_SRAM1,
  45. #endif
  46. MAP_DEVICE,
  47. {0}
  48. };
  49. #endif
  50. #if defined(IMAGE_BL31)
  51. static const mmap_region_t stm32mp2_mmap[] = {
  52. MAP_SYSRAM,
  53. MAP_DEVICE,
  54. {0}
  55. };
  56. #endif
  57. void configure_mmu(void)
  58. {
  59. mmap_add(stm32mp2_mmap);
  60. init_xlat_tables();
  61. enable_mmu_el3(0);
  62. }
  63. int stm32mp_map_retram(void)
  64. {
  65. return mmap_add_dynamic_region(RETRAM_BASE, RETRAM_BASE,
  66. RETRAM_SIZE,
  67. MT_RW | MT_SECURE);
  68. }
  69. int stm32mp_unmap_retram(void)
  70. {
  71. return mmap_remove_dynamic_region(RETRAM_BASE,
  72. RETRAM_SIZE);
  73. }
  74. uintptr_t stm32_get_gpio_bank_base(unsigned int bank)
  75. {
  76. if (bank == GPIO_BANK_Z) {
  77. return GPIOZ_BASE;
  78. }
  79. assert(bank <= GPIO_BANK_K);
  80. return GPIOA_BASE + (bank * GPIO_BANK_OFFSET);
  81. }
  82. uint32_t stm32_get_gpio_bank_offset(unsigned int bank)
  83. {
  84. if (bank == GPIO_BANK_Z) {
  85. return 0;
  86. }
  87. assert(bank <= GPIO_BANK_K);
  88. return bank * GPIO_BANK_OFFSET;
  89. }
  90. unsigned long stm32_get_gpio_bank_clock(unsigned int bank)
  91. {
  92. if (bank == GPIO_BANK_Z) {
  93. return CK_BUS_GPIOZ;
  94. }
  95. assert(bank <= GPIO_BANK_K);
  96. return CK_BUS_GPIOA + (bank - GPIO_BANK_A);
  97. }
  98. #if STM32MP_UART_PROGRAMMER || !defined(IMAGE_BL2)
  99. /*
  100. * UART Management
  101. */
  102. static const uintptr_t stm32mp2_uart_addresses[STM32MP_NB_OF_UART] = {
  103. USART1_BASE,
  104. USART2_BASE,
  105. USART3_BASE,
  106. UART4_BASE,
  107. UART5_BASE,
  108. USART6_BASE,
  109. UART7_BASE,
  110. UART8_BASE,
  111. UART9_BASE,
  112. };
  113. uintptr_t get_uart_address(uint32_t instance_nb)
  114. {
  115. if ((instance_nb == 0U) ||
  116. (instance_nb > STM32MP_NB_OF_UART)) {
  117. return 0U;
  118. }
  119. return stm32mp2_uart_addresses[instance_nb - 1U];
  120. }
  121. #endif
  122. uint32_t stm32mp_get_chip_version(void)
  123. {
  124. static uint32_t rev;
  125. if (rev != 0U) {
  126. return rev;
  127. }
  128. if (stm32_get_otp_value(REVISION_OTP, &rev) != 0) {
  129. panic();
  130. }
  131. return rev;
  132. }
  133. uint32_t stm32mp_get_chip_dev_id(void)
  134. {
  135. return stm32mp_syscfg_get_chip_dev_id();
  136. }
  137. static uint32_t get_part_number(void)
  138. {
  139. static uint32_t part_number;
  140. if (part_number != 0U) {
  141. return part_number;
  142. }
  143. if (stm32_get_otp_value(PART_NUMBER_OTP, &part_number) != 0) {
  144. panic();
  145. }
  146. return part_number;
  147. }
  148. static uint32_t get_cpu_package(void)
  149. {
  150. static uint32_t package = UINT32_MAX;
  151. if (package == UINT32_MAX) {
  152. if (stm32_get_otp_value(PACKAGE_OTP, &package) != 0) {
  153. panic();
  154. }
  155. }
  156. return (package & PACKAGE_OTP_PKG_MASK) >> PACKAGE_OTP_PKG_SHIFT;
  157. }
  158. void stm32mp_get_soc_name(char name[STM32_SOC_NAME_SIZE])
  159. {
  160. char *cpu_s, *cpu_r, *pkg;
  161. /* MPUs Part Numbers */
  162. switch (get_part_number()) {
  163. case STM32MP251A_PART_NB:
  164. cpu_s = "251A";
  165. break;
  166. case STM32MP251C_PART_NB:
  167. cpu_s = "251C";
  168. break;
  169. case STM32MP251D_PART_NB:
  170. cpu_s = "251D";
  171. break;
  172. case STM32MP251F_PART_NB:
  173. cpu_s = "251F";
  174. break;
  175. case STM32MP253A_PART_NB:
  176. cpu_s = "253A";
  177. break;
  178. case STM32MP253C_PART_NB:
  179. cpu_s = "253C";
  180. break;
  181. case STM32MP253D_PART_NB:
  182. cpu_s = "253D";
  183. break;
  184. case STM32MP253F_PART_NB:
  185. cpu_s = "253F";
  186. break;
  187. case STM32MP255A_PART_NB:
  188. cpu_s = "255A";
  189. break;
  190. case STM32MP255C_PART_NB:
  191. cpu_s = "255C";
  192. break;
  193. case STM32MP255D_PART_NB:
  194. cpu_s = "255D";
  195. break;
  196. case STM32MP255F_PART_NB:
  197. cpu_s = "255F";
  198. break;
  199. case STM32MP257A_PART_NB:
  200. cpu_s = "257A";
  201. break;
  202. case STM32MP257C_PART_NB:
  203. cpu_s = "257C";
  204. break;
  205. case STM32MP257D_PART_NB:
  206. cpu_s = "257D";
  207. break;
  208. case STM32MP257F_PART_NB:
  209. cpu_s = "257F";
  210. break;
  211. default:
  212. cpu_s = "????";
  213. break;
  214. }
  215. /* Package */
  216. switch (get_cpu_package()) {
  217. case STM32MP25_PKG_CUSTOM:
  218. pkg = "XX";
  219. break;
  220. case STM32MP25_PKG_AL_VFBGA361:
  221. pkg = "AL";
  222. break;
  223. case STM32MP25_PKG_AK_VFBGA424:
  224. pkg = "AK";
  225. break;
  226. case STM32MP25_PKG_AI_TFBGA436:
  227. pkg = "AI";
  228. break;
  229. default:
  230. pkg = "??";
  231. break;
  232. }
  233. /* REVISION */
  234. switch (stm32mp_get_chip_version()) {
  235. case STM32MP2_REV_A:
  236. cpu_r = "A";
  237. break;
  238. case STM32MP2_REV_B:
  239. cpu_r = "B";
  240. break;
  241. case STM32MP2_REV_X:
  242. cpu_r = "X";
  243. break;
  244. case STM32MP2_REV_Y:
  245. cpu_r = "Y";
  246. break;
  247. case STM32MP2_REV_Z:
  248. cpu_r = "Z";
  249. break;
  250. default:
  251. cpu_r = "?";
  252. break;
  253. }
  254. snprintf(name, STM32_SOC_NAME_SIZE,
  255. "STM32MP%s%s Rev.%s", cpu_s, pkg, cpu_r);
  256. }
  257. void stm32mp_print_cpuinfo(void)
  258. {
  259. char name[STM32_SOC_NAME_SIZE];
  260. stm32mp_get_soc_name(name);
  261. NOTICE("CPU: %s\n", name);
  262. }
  263. void stm32mp_print_boardinfo(void)
  264. {
  265. uint32_t board_id = 0U;
  266. if (stm32_get_otp_value(BOARD_ID_OTP, &board_id) != 0) {
  267. return;
  268. }
  269. if (board_id != 0U) {
  270. stm32_display_board_info(board_id);
  271. }
  272. }
  273. bool stm32mp_is_wakeup_from_standby(void)
  274. {
  275. /* TODO add source code to determine if platform is waking up from standby mode */
  276. return false;
  277. }
  278. uintptr_t stm32_get_bkpr_boot_mode_addr(void)
  279. {
  280. return tamp_bkpr(BKPR_BOOT_MODE);
  281. }
  282. uintptr_t stm32_ddrdbg_get_base(void)
  283. {
  284. return DDRDBG_BASE;
  285. }