Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 1 | /* |
Yann Gautier | 352d863 | 2020-09-17 11:38:09 +0200 | [diff] [blame] | 2 | * Copyright (c) 2015-2022, ARM Limited and Contributors. All rights reserved. |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Yann Gautier | e3bf913 | 2019-05-07 18:52:17 +0200 | [diff] [blame] | 7 | #include <assert.h> |
| 8 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 9 | #include <drivers/clk.h> |
Yann Gautier | cd16df3 | 2021-06-04 14:04:05 +0200 | [diff] [blame] | 10 | #include <drivers/st/stm32_gpio.h> |
| 11 | #include <drivers/st/stm32_iwdg.h> |
Yann Gautier | 6eef525 | 2021-12-10 17:04:40 +0100 | [diff] [blame] | 12 | #include <lib/mmio.h> |
Yann Gautier | cd16df3 | 2021-06-04 14:04:05 +0200 | [diff] [blame] | 13 | #include <lib/xlat_tables/xlat_tables_v2.h> |
Yann Gautier | 0c81088 | 2021-12-17 09:53:04 +0100 | [diff] [blame] | 14 | #include <libfdt.h> |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 15 | |
Sughosh Ganu | 03e2f80 | 2021-12-01 15:56:27 +0530 | [diff] [blame] | 16 | #include <plat/common/platform.h> |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 17 | #include <platform_def.h> |
| 18 | |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 19 | /* Internal layout of the 32bit OTP word board_id */ |
| 20 | #define BOARD_ID_BOARD_NB_MASK GENMASK(31, 16) |
| 21 | #define BOARD_ID_BOARD_NB_SHIFT 16 |
Patrick Delaunay | 7704f16 | 2020-01-08 10:05:14 +0100 | [diff] [blame] | 22 | #define BOARD_ID_VARCPN_MASK GENMASK(15, 12) |
| 23 | #define BOARD_ID_VARCPN_SHIFT 12 |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 24 | #define BOARD_ID_REVISION_MASK GENMASK(11, 8) |
| 25 | #define BOARD_ID_REVISION_SHIFT 8 |
Patrick Delaunay | 7704f16 | 2020-01-08 10:05:14 +0100 | [diff] [blame] | 26 | #define BOARD_ID_VARFG_MASK GENMASK(7, 4) |
| 27 | #define BOARD_ID_VARFG_SHIFT 4 |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 28 | #define BOARD_ID_BOM_MASK GENMASK(3, 0) |
| 29 | |
| 30 | #define BOARD_ID2NB(_id) (((_id) & BOARD_ID_BOARD_NB_MASK) >> \ |
| 31 | BOARD_ID_BOARD_NB_SHIFT) |
Patrick Delaunay | 7704f16 | 2020-01-08 10:05:14 +0100 | [diff] [blame] | 32 | #define BOARD_ID2VARCPN(_id) (((_id) & BOARD_ID_VARCPN_MASK) >> \ |
| 33 | BOARD_ID_VARCPN_SHIFT) |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 34 | #define BOARD_ID2REV(_id) (((_id) & BOARD_ID_REVISION_MASK) >> \ |
| 35 | BOARD_ID_REVISION_SHIFT) |
Patrick Delaunay | 7704f16 | 2020-01-08 10:05:14 +0100 | [diff] [blame] | 36 | #define BOARD_ID2VARFG(_id) (((_id) & BOARD_ID_VARFG_MASK) >> \ |
| 37 | BOARD_ID_VARFG_SHIFT) |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 38 | #define BOARD_ID2BOM(_id) ((_id) & BOARD_ID_BOM_MASK) |
| 39 | |
Yann Gautier | 8200047 | 2020-02-05 16:24:21 +0100 | [diff] [blame] | 40 | #if STM32MP13 |
| 41 | #define TAMP_BOOT_MODE_BACKUP_REG_ID U(30) |
| 42 | #endif |
| 43 | #if STM32MP15 |
Yann Gautier | 6eef525 | 2021-12-10 17:04:40 +0100 | [diff] [blame] | 44 | #define TAMP_BOOT_MODE_BACKUP_REG_ID U(20) |
Yann Gautier | 8200047 | 2020-02-05 16:24:21 +0100 | [diff] [blame] | 45 | #endif |
Yann Gautier | 6eef525 | 2021-12-10 17:04:40 +0100 | [diff] [blame] | 46 | #define TAMP_BOOT_MODE_ITF_MASK U(0x0000FF00) |
| 47 | #define TAMP_BOOT_MODE_ITF_SHIFT 8 |
| 48 | |
Yann Gautier | 9bbd26a | 2022-03-28 17:49:38 +0200 | [diff] [blame] | 49 | /* |
| 50 | * Backup register to store fwu update information. |
| 51 | * It should be writeable only by secure world, but also readable by non secure |
| 52 | * (so it should be in Zone 2). |
| 53 | */ |
| 54 | #define TAMP_BOOT_FWU_INFO_REG_ID U(10) |
| 55 | #define TAMP_BOOT_FWU_INFO_IDX_MSK U(0xF) |
| 56 | #define TAMP_BOOT_FWU_INFO_IDX_OFF U(0) |
| 57 | #define TAMP_BOOT_FWU_INFO_CNT_MSK U(0xF0) |
| 58 | #define TAMP_BOOT_FWU_INFO_CNT_OFF U(4) |
Sughosh Ganu | 03e2f80 | 2021-12-01 15:56:27 +0530 | [diff] [blame] | 59 | |
Etienne Carriere | 72369b1 | 2019-12-08 08:17:56 +0100 | [diff] [blame] | 60 | #if defined(IMAGE_BL2) |
| 61 | #define MAP_SEC_SYSRAM MAP_REGION_FLAT(STM32MP_SYSRAM_BASE, \ |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 62 | STM32MP_SYSRAM_SIZE, \ |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 63 | MT_MEMORY | \ |
| 64 | MT_RW | \ |
| 65 | MT_SECURE | \ |
| 66 | MT_EXECUTE_NEVER) |
Etienne Carriere | 72369b1 | 2019-12-08 08:17:56 +0100 | [diff] [blame] | 67 | #elif defined(IMAGE_BL32) |
| 68 | #define MAP_SEC_SYSRAM MAP_REGION_FLAT(STM32MP_SEC_SYSRAM_BASE, \ |
| 69 | STM32MP_SEC_SYSRAM_SIZE, \ |
| 70 | MT_MEMORY | \ |
| 71 | MT_RW | \ |
| 72 | MT_SECURE | \ |
| 73 | MT_EXECUTE_NEVER) |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 74 | |
Etienne Carriere | 72369b1 | 2019-12-08 08:17:56 +0100 | [diff] [blame] | 75 | /* Non-secure SYSRAM is used a uncached memory for SCMI message transfer */ |
| 76 | #define MAP_NS_SYSRAM MAP_REGION_FLAT(STM32MP_NS_SYSRAM_BASE, \ |
| 77 | STM32MP_NS_SYSRAM_SIZE, \ |
| 78 | MT_DEVICE | \ |
| 79 | MT_RW | \ |
| 80 | MT_NS | \ |
| 81 | MT_EXECUTE_NEVER) |
| 82 | #endif |
| 83 | |
Yann Gautier | 84d994b | 2020-04-14 18:08:50 +0200 | [diff] [blame] | 84 | #if STM32MP13 |
| 85 | #define MAP_SRAM_ALL MAP_REGION_FLAT(SRAMS_BASE, \ |
| 86 | SRAMS_SIZE_2MB_ALIGNED, \ |
| 87 | MT_MEMORY | \ |
| 88 | MT_RW | \ |
| 89 | MT_SECURE | \ |
| 90 | MT_EXECUTE_NEVER) |
| 91 | #endif |
| 92 | |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 93 | #define MAP_DEVICE1 MAP_REGION_FLAT(STM32MP1_DEVICE1_BASE, \ |
| 94 | STM32MP1_DEVICE1_SIZE, \ |
| 95 | MT_DEVICE | \ |
| 96 | MT_RW | \ |
| 97 | MT_SECURE | \ |
| 98 | MT_EXECUTE_NEVER) |
| 99 | |
| 100 | #define MAP_DEVICE2 MAP_REGION_FLAT(STM32MP1_DEVICE2_BASE, \ |
| 101 | STM32MP1_DEVICE2_SIZE, \ |
| 102 | MT_DEVICE | \ |
| 103 | MT_RW | \ |
| 104 | MT_SECURE | \ |
| 105 | MT_EXECUTE_NEVER) |
| 106 | |
| 107 | #if defined(IMAGE_BL2) |
| 108 | static const mmap_region_t stm32mp1_mmap[] = { |
Etienne Carriere | 72369b1 | 2019-12-08 08:17:56 +0100 | [diff] [blame] | 109 | MAP_SEC_SYSRAM, |
Yann Gautier | 84d994b | 2020-04-14 18:08:50 +0200 | [diff] [blame] | 110 | #if STM32MP13 |
| 111 | MAP_SRAM_ALL, |
| 112 | #endif |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 113 | MAP_DEVICE1, |
Yann Gautier | 352d863 | 2020-09-17 11:38:09 +0200 | [diff] [blame] | 114 | #if STM32MP_RAW_NAND |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 115 | MAP_DEVICE2, |
Yann Gautier | 352d863 | 2020-09-17 11:38:09 +0200 | [diff] [blame] | 116 | #endif |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 117 | {0} |
| 118 | }; |
| 119 | #endif |
| 120 | #if defined(IMAGE_BL32) |
| 121 | static const mmap_region_t stm32mp1_mmap[] = { |
Etienne Carriere | 72369b1 | 2019-12-08 08:17:56 +0100 | [diff] [blame] | 122 | MAP_SEC_SYSRAM, |
| 123 | MAP_NS_SYSRAM, |
Yann Gautier | ee8f542 | 2019-02-14 11:13:25 +0100 | [diff] [blame] | 124 | MAP_DEVICE1, |
| 125 | MAP_DEVICE2, |
| 126 | {0} |
| 127 | }; |
| 128 | #endif |
| 129 | |
| 130 | void configure_mmu(void) |
| 131 | { |
| 132 | mmap_add(stm32mp1_mmap); |
| 133 | init_xlat_tables(); |
| 134 | |
| 135 | enable_mmu_svc_mon(0); |
| 136 | } |
Yann Gautier | e3bf913 | 2019-05-07 18:52:17 +0200 | [diff] [blame] | 137 | |
Etienne Carriere | 66b0452 | 2019-12-02 10:05:02 +0100 | [diff] [blame] | 138 | uintptr_t stm32_get_gpio_bank_base(unsigned int bank) |
| 139 | { |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 140 | #if STM32MP13 |
| 141 | assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_I); |
| 142 | #endif |
| 143 | #if STM32MP15 |
Etienne Carriere | 66b0452 | 2019-12-02 10:05:02 +0100 | [diff] [blame] | 144 | if (bank == GPIO_BANK_Z) { |
| 145 | return GPIOZ_BASE; |
| 146 | } |
| 147 | |
| 148 | assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_K); |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 149 | #endif |
Etienne Carriere | 66b0452 | 2019-12-02 10:05:02 +0100 | [diff] [blame] | 150 | |
| 151 | return GPIOA_BASE + (bank * GPIO_BANK_OFFSET); |
| 152 | } |
| 153 | |
| 154 | uint32_t stm32_get_gpio_bank_offset(unsigned int bank) |
| 155 | { |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 156 | #if STM32MP13 |
| 157 | assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_I); |
| 158 | #endif |
| 159 | #if STM32MP15 |
Etienne Carriere | 66b0452 | 2019-12-02 10:05:02 +0100 | [diff] [blame] | 160 | if (bank == GPIO_BANK_Z) { |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_K); |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 165 | #endif |
Etienne Carriere | 66b0452 | 2019-12-02 10:05:02 +0100 | [diff] [blame] | 166 | |
| 167 | return bank * GPIO_BANK_OFFSET; |
| 168 | } |
| 169 | |
Yann Gautier | 2b79c37 | 2021-06-11 10:54:56 +0200 | [diff] [blame] | 170 | bool stm32_gpio_is_secure_at_reset(unsigned int bank) |
| 171 | { |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 172 | #if STM32MP13 |
| 173 | return true; |
| 174 | #endif |
| 175 | #if STM32MP15 |
Yann Gautier | 2b79c37 | 2021-06-11 10:54:56 +0200 | [diff] [blame] | 176 | if (bank == GPIO_BANK_Z) { |
| 177 | return true; |
| 178 | } |
| 179 | |
| 180 | return false; |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 181 | #endif |
Yann Gautier | 2b79c37 | 2021-06-11 10:54:56 +0200 | [diff] [blame] | 182 | } |
| 183 | |
Yann Gautier | e3bf913 | 2019-05-07 18:52:17 +0200 | [diff] [blame] | 184 | unsigned long stm32_get_gpio_bank_clock(unsigned int bank) |
| 185 | { |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 186 | #if STM32MP13 |
| 187 | assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_I); |
| 188 | #endif |
| 189 | #if STM32MP15 |
Yann Gautier | e3bf913 | 2019-05-07 18:52:17 +0200 | [diff] [blame] | 190 | if (bank == GPIO_BANK_Z) { |
| 191 | return GPIOZ; |
| 192 | } |
| 193 | |
| 194 | assert(GPIO_BANK_A == 0 && bank <= GPIO_BANK_K); |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 195 | #endif |
Yann Gautier | e3bf913 | 2019-05-07 18:52:17 +0200 | [diff] [blame] | 196 | |
| 197 | return GPIOA + (bank - GPIO_BANK_A); |
| 198 | } |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 199 | |
Etienne Carriere | d81dadf | 2020-04-25 11:14:45 +0200 | [diff] [blame] | 200 | int stm32_get_gpio_bank_pinctrl_node(void *fdt, unsigned int bank) |
| 201 | { |
Yann Gautier | e78db3b | 2022-03-11 14:18:13 +0100 | [diff] [blame] | 202 | const char *node_compatible = NULL; |
| 203 | |
Etienne Carriere | d81dadf | 2020-04-25 11:14:45 +0200 | [diff] [blame] | 204 | switch (bank) { |
| 205 | case GPIO_BANK_A: |
| 206 | case GPIO_BANK_B: |
| 207 | case GPIO_BANK_C: |
| 208 | case GPIO_BANK_D: |
| 209 | case GPIO_BANK_E: |
| 210 | case GPIO_BANK_F: |
| 211 | case GPIO_BANK_G: |
| 212 | case GPIO_BANK_H: |
| 213 | case GPIO_BANK_I: |
Yann Gautier | e78db3b | 2022-03-11 14:18:13 +0100 | [diff] [blame] | 214 | #if STM32MP13 |
| 215 | node_compatible = "st,stm32mp135-pinctrl"; |
| 216 | break; |
| 217 | #endif |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 218 | #if STM32MP15 |
Etienne Carriere | d81dadf | 2020-04-25 11:14:45 +0200 | [diff] [blame] | 219 | case GPIO_BANK_J: |
| 220 | case GPIO_BANK_K: |
Yann Gautier | e78db3b | 2022-03-11 14:18:13 +0100 | [diff] [blame] | 221 | node_compatible = "st,stm32mp157-pinctrl"; |
| 222 | break; |
Etienne Carriere | d81dadf | 2020-04-25 11:14:45 +0200 | [diff] [blame] | 223 | case GPIO_BANK_Z: |
Yann Gautier | e78db3b | 2022-03-11 14:18:13 +0100 | [diff] [blame] | 224 | node_compatible = "st,stm32mp157-z-pinctrl"; |
| 225 | break; |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 226 | #endif |
Etienne Carriere | d81dadf | 2020-04-25 11:14:45 +0200 | [diff] [blame] | 227 | default: |
| 228 | panic(); |
| 229 | } |
Yann Gautier | e78db3b | 2022-03-11 14:18:13 +0100 | [diff] [blame] | 230 | |
| 231 | return fdt_node_offset_by_compatible(fdt, -1, node_compatible); |
Etienne Carriere | d81dadf | 2020-04-25 11:14:45 +0200 | [diff] [blame] | 232 | } |
| 233 | |
Yann Gautier | 3d8497c | 2021-10-18 16:06:22 +0200 | [diff] [blame] | 234 | #if STM32MP_UART_PROGRAMMER || !defined(IMAGE_BL2) |
Patrick Delaunay | e50571b | 2021-10-28 13:48:52 +0200 | [diff] [blame] | 235 | /* |
| 236 | * UART Management |
| 237 | */ |
| 238 | static const uintptr_t stm32mp1_uart_addresses[8] = { |
| 239 | USART1_BASE, |
| 240 | USART2_BASE, |
| 241 | USART3_BASE, |
| 242 | UART4_BASE, |
| 243 | UART5_BASE, |
| 244 | USART6_BASE, |
| 245 | UART7_BASE, |
| 246 | UART8_BASE, |
| 247 | }; |
| 248 | |
| 249 | uintptr_t get_uart_address(uint32_t instance_nb) |
| 250 | { |
| 251 | if ((instance_nb == 0U) || |
| 252 | (instance_nb > ARRAY_SIZE(stm32mp1_uart_addresses))) { |
| 253 | return 0U; |
| 254 | } |
| 255 | |
| 256 | return stm32mp1_uart_addresses[instance_nb - 1U]; |
| 257 | } |
| 258 | #endif |
| 259 | |
Yann Gautier | cd16df3 | 2021-06-04 14:04:05 +0200 | [diff] [blame] | 260 | #if STM32MP_USB_PROGRAMMER |
| 261 | struct gpio_bank_pin_list { |
| 262 | uint32_t bank; |
| 263 | uint32_t pin; |
| 264 | }; |
| 265 | |
| 266 | static const struct gpio_bank_pin_list gpio_list[] = { |
| 267 | { /* USART2_RX: GPIOA3 */ |
| 268 | .bank = 0U, |
| 269 | .pin = 3U, |
| 270 | }, |
| 271 | { /* USART3_RX: GPIOB12 */ |
| 272 | .bank = 1U, |
| 273 | .pin = 12U, |
| 274 | }, |
| 275 | { /* UART4_RX: GPIOB2 */ |
| 276 | .bank = 1U, |
| 277 | .pin = 2U, |
| 278 | }, |
| 279 | { /* UART5_RX: GPIOB4 */ |
| 280 | .bank = 1U, |
| 281 | .pin = 5U, |
| 282 | }, |
| 283 | { /* USART6_RX: GPIOC7 */ |
| 284 | .bank = 2U, |
| 285 | .pin = 7U, |
| 286 | }, |
| 287 | { /* UART7_RX: GPIOF6 */ |
| 288 | .bank = 5U, |
| 289 | .pin = 6U, |
| 290 | }, |
| 291 | { /* UART8_RX: GPIOE0 */ |
| 292 | .bank = 4U, |
| 293 | .pin = 0U, |
| 294 | }, |
| 295 | }; |
| 296 | |
| 297 | void stm32mp1_deconfigure_uart_pins(void) |
| 298 | { |
| 299 | size_t i; |
| 300 | |
| 301 | for (i = 0U; i < ARRAY_SIZE(gpio_list); i++) { |
| 302 | set_gpio_reset_cfg(gpio_list[i].bank, gpio_list[i].pin); |
| 303 | } |
| 304 | } |
| 305 | #endif |
| 306 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 307 | uint32_t stm32mp_get_chip_version(void) |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 308 | { |
Yann Gautier | f36a1d3 | 2020-04-21 15:03:59 +0200 | [diff] [blame] | 309 | #if STM32MP13 |
| 310 | return stm32mp1_syscfg_get_chip_version(); |
| 311 | #endif |
| 312 | #if STM32MP15 |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 313 | uint32_t version = 0U; |
| 314 | |
| 315 | if (stm32mp1_dbgmcu_get_chip_version(&version) < 0) { |
| 316 | INFO("Cannot get CPU version, debug disabled\n"); |
| 317 | return 0U; |
| 318 | } |
| 319 | |
| 320 | return version; |
Yann Gautier | f36a1d3 | 2020-04-21 15:03:59 +0200 | [diff] [blame] | 321 | #endif |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 322 | } |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 323 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 324 | uint32_t stm32mp_get_chip_dev_id(void) |
| 325 | { |
Yann Gautier | f36a1d3 | 2020-04-21 15:03:59 +0200 | [diff] [blame] | 326 | #if STM32MP13 |
| 327 | return stm32mp1_syscfg_get_chip_dev_id(); |
| 328 | #endif |
| 329 | #if STM32MP15 |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 330 | uint32_t dev_id; |
Nicolas Le Bayon | 98f4ea0 | 2019-09-23 11:18:32 +0200 | [diff] [blame] | 331 | |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 332 | if (stm32mp1_dbgmcu_get_chip_dev_id(&dev_id) < 0) { |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 333 | INFO("Use default chip ID, debug disabled\n"); |
| 334 | dev_id = STM32MP1_CHIP_ID; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 335 | } |
| 336 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 337 | return dev_id; |
Yann Gautier | f36a1d3 | 2020-04-21 15:03:59 +0200 | [diff] [blame] | 338 | #endif |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static uint32_t get_part_number(void) |
| 342 | { |
| 343 | static uint32_t part_number; |
| 344 | |
| 345 | if (part_number != 0U) { |
| 346 | return part_number; |
| 347 | } |
| 348 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 349 | if (stm32_get_otp_value(PART_NUMBER_OTP, &part_number) != 0) { |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 350 | panic(); |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | part_number = (part_number & PART_NUMBER_OTP_PART_MASK) >> |
| 354 | PART_NUMBER_OTP_PART_SHIFT; |
| 355 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 356 | part_number |= stm32mp_get_chip_dev_id() << 16; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 357 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 358 | return part_number; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 361 | #if STM32MP15 |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 362 | static uint32_t get_cpu_package(void) |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 363 | { |
| 364 | uint32_t package; |
| 365 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 366 | if (stm32_get_otp_value(PACKAGE_OTP, &package) != 0) { |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 367 | panic(); |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 368 | } |
| 369 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 370 | package = (package & PACKAGE_OTP_PKG_MASK) >> |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 371 | PACKAGE_OTP_PKG_SHIFT; |
| 372 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 373 | return package; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 374 | } |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 375 | #endif |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 376 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 377 | void stm32mp_get_soc_name(char name[STM32_SOC_NAME_SIZE]) |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 378 | { |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 379 | char *cpu_s, *cpu_r, *pkg; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 380 | |
| 381 | /* MPUs Part Numbers */ |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 382 | switch (get_part_number()) { |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 383 | #if STM32MP13 |
| 384 | case STM32MP135F_PART_NB: |
| 385 | cpu_s = "135F"; |
| 386 | break; |
| 387 | case STM32MP135D_PART_NB: |
| 388 | cpu_s = "135D"; |
| 389 | break; |
| 390 | case STM32MP135C_PART_NB: |
| 391 | cpu_s = "135C"; |
| 392 | break; |
| 393 | case STM32MP135A_PART_NB: |
| 394 | cpu_s = "135A"; |
| 395 | break; |
| 396 | case STM32MP133F_PART_NB: |
| 397 | cpu_s = "133F"; |
| 398 | break; |
| 399 | case STM32MP133D_PART_NB: |
| 400 | cpu_s = "133D"; |
| 401 | break; |
| 402 | case STM32MP133C_PART_NB: |
| 403 | cpu_s = "133C"; |
| 404 | break; |
| 405 | case STM32MP133A_PART_NB: |
| 406 | cpu_s = "133A"; |
| 407 | break; |
| 408 | case STM32MP131F_PART_NB: |
| 409 | cpu_s = "131F"; |
| 410 | break; |
| 411 | case STM32MP131D_PART_NB: |
| 412 | cpu_s = "131D"; |
| 413 | break; |
| 414 | case STM32MP131C_PART_NB: |
| 415 | cpu_s = "131C"; |
| 416 | break; |
| 417 | case STM32MP131A_PART_NB: |
| 418 | cpu_s = "131A"; |
| 419 | break; |
| 420 | #endif |
| 421 | #if STM32MP15 |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 422 | case STM32MP157C_PART_NB: |
| 423 | cpu_s = "157C"; |
| 424 | break; |
| 425 | case STM32MP157A_PART_NB: |
| 426 | cpu_s = "157A"; |
| 427 | break; |
| 428 | case STM32MP153C_PART_NB: |
| 429 | cpu_s = "153C"; |
| 430 | break; |
| 431 | case STM32MP153A_PART_NB: |
| 432 | cpu_s = "153A"; |
| 433 | break; |
| 434 | case STM32MP151C_PART_NB: |
| 435 | cpu_s = "151C"; |
| 436 | break; |
| 437 | case STM32MP151A_PART_NB: |
| 438 | cpu_s = "151A"; |
| 439 | break; |
Lionel Debieve | 7b64e3e | 2019-05-17 16:01:18 +0200 | [diff] [blame] | 440 | case STM32MP157F_PART_NB: |
| 441 | cpu_s = "157F"; |
| 442 | break; |
| 443 | case STM32MP157D_PART_NB: |
| 444 | cpu_s = "157D"; |
| 445 | break; |
| 446 | case STM32MP153F_PART_NB: |
| 447 | cpu_s = "153F"; |
| 448 | break; |
| 449 | case STM32MP153D_PART_NB: |
| 450 | cpu_s = "153D"; |
| 451 | break; |
| 452 | case STM32MP151F_PART_NB: |
| 453 | cpu_s = "151F"; |
| 454 | break; |
| 455 | case STM32MP151D_PART_NB: |
| 456 | cpu_s = "151D"; |
| 457 | break; |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 458 | #endif |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 459 | default: |
| 460 | cpu_s = "????"; |
| 461 | break; |
| 462 | } |
| 463 | |
| 464 | /* Package */ |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 465 | #if STM32MP13 |
| 466 | /* On STM32MP13, package is not present in OTP */ |
| 467 | pkg = ""; |
| 468 | #endif |
| 469 | #if STM32MP15 |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 470 | switch (get_cpu_package()) { |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 471 | case PKG_AA_LFBGA448: |
| 472 | pkg = "AA"; |
| 473 | break; |
| 474 | case PKG_AB_LFBGA354: |
| 475 | pkg = "AB"; |
| 476 | break; |
| 477 | case PKG_AC_TFBGA361: |
| 478 | pkg = "AC"; |
| 479 | break; |
| 480 | case PKG_AD_TFBGA257: |
| 481 | pkg = "AD"; |
| 482 | break; |
| 483 | default: |
| 484 | pkg = "??"; |
| 485 | break; |
| 486 | } |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 487 | #endif |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 488 | |
| 489 | /* REVISION */ |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 490 | switch (stm32mp_get_chip_version()) { |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 491 | case STM32MP1_REV_B: |
| 492 | cpu_r = "B"; |
| 493 | break; |
Lionel Debieve | 2d64b53 | 2019-06-25 10:40:37 +0200 | [diff] [blame] | 494 | case STM32MP1_REV_Z: |
| 495 | cpu_r = "Z"; |
| 496 | break; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 497 | default: |
| 498 | cpu_r = "?"; |
| 499 | break; |
| 500 | } |
| 501 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 502 | snprintf(name, STM32_SOC_NAME_SIZE, |
| 503 | "STM32MP%s%s Rev.%s", cpu_s, pkg, cpu_r); |
| 504 | } |
| 505 | |
| 506 | void stm32mp_print_cpuinfo(void) |
| 507 | { |
| 508 | char name[STM32_SOC_NAME_SIZE]; |
| 509 | |
| 510 | stm32mp_get_soc_name(name); |
| 511 | NOTICE("CPU: %s\n", name); |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 512 | } |
| 513 | |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 514 | void stm32mp_print_boardinfo(void) |
| 515 | { |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 516 | uint32_t board_id = 0; |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 517 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 518 | if (stm32_get_otp_value(BOARD_ID_OTP, &board_id) != 0) { |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 519 | return; |
| 520 | } |
| 521 | |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 522 | if (board_id != 0U) { |
| 523 | char rev[2]; |
| 524 | |
| 525 | rev[0] = BOARD_ID2REV(board_id) - 1 + 'A'; |
| 526 | rev[1] = '\0'; |
Yann Gautier | 36e9d38 | 2020-10-13 18:03:31 +0200 | [diff] [blame] | 527 | NOTICE("Board: MB%04x Var%u.%u Rev.%s-%02u\n", |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 528 | BOARD_ID2NB(board_id), |
Patrick Delaunay | 7704f16 | 2020-01-08 10:05:14 +0100 | [diff] [blame] | 529 | BOARD_ID2VARCPN(board_id), |
| 530 | BOARD_ID2VARFG(board_id), |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 531 | rev, |
| 532 | BOARD_ID2BOM(board_id)); |
| 533 | } |
| 534 | } |
| 535 | |
Yann Gautier | af19ff9 | 2019-06-04 18:23:10 +0200 | [diff] [blame] | 536 | /* Return true when SoC provides a single Cortex-A7 core, and false otherwise */ |
| 537 | bool stm32mp_is_single_core(void) |
| 538 | { |
Yann Gautier | 6bd30e2 | 2020-02-06 15:34:16 +0100 | [diff] [blame] | 539 | #if STM32MP13 |
| 540 | return true; |
| 541 | #endif |
| 542 | #if STM32MP15 |
Yann Gautier | 2f3b560 | 2021-10-19 13:31:06 +0200 | [diff] [blame] | 543 | bool single_core = false; |
| 544 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 545 | switch (get_part_number()) { |
Yann Gautier | af19ff9 | 2019-06-04 18:23:10 +0200 | [diff] [blame] | 546 | case STM32MP151A_PART_NB: |
| 547 | case STM32MP151C_PART_NB: |
Lionel Debieve | 7b64e3e | 2019-05-17 16:01:18 +0200 | [diff] [blame] | 548 | case STM32MP151D_PART_NB: |
| 549 | case STM32MP151F_PART_NB: |
Yann Gautier | 2f3b560 | 2021-10-19 13:31:06 +0200 | [diff] [blame] | 550 | single_core = true; |
| 551 | break; |
Yann Gautier | af19ff9 | 2019-06-04 18:23:10 +0200 | [diff] [blame] | 552 | default: |
Yann Gautier | 2f3b560 | 2021-10-19 13:31:06 +0200 | [diff] [blame] | 553 | break; |
Yann Gautier | af19ff9 | 2019-06-04 18:23:10 +0200 | [diff] [blame] | 554 | } |
Yann Gautier | 2f3b560 | 2021-10-19 13:31:06 +0200 | [diff] [blame] | 555 | |
| 556 | return single_core; |
Yann Gautier | 6bd30e2 | 2020-02-06 15:34:16 +0100 | [diff] [blame] | 557 | #endif |
Yann Gautier | af19ff9 | 2019-06-04 18:23:10 +0200 | [diff] [blame] | 558 | } |
| 559 | |
Lionel Debieve | 0e73d73 | 2019-09-16 12:17:09 +0200 | [diff] [blame] | 560 | /* Return true when device is in closed state */ |
| 561 | bool stm32mp_is_closed_device(void) |
| 562 | { |
| 563 | uint32_t value; |
| 564 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 565 | if (stm32_get_otp_value(CFG0_OTP, &value) != 0) { |
Lionel Debieve | 0e73d73 | 2019-09-16 12:17:09 +0200 | [diff] [blame] | 566 | return true; |
| 567 | } |
| 568 | |
Nicolas Le Bayon | 34cbf23 | 2020-11-26 09:57:09 +0100 | [diff] [blame] | 569 | #if STM32MP13 |
| 570 | value = (value & CFG0_OTP_MODE_MASK) >> CFG0_OTP_MODE_SHIFT; |
| 571 | |
| 572 | switch (value) { |
| 573 | case CFG0_OPEN_DEVICE: |
| 574 | return false; |
| 575 | case CFG0_CLOSED_DEVICE: |
| 576 | case CFG0_CLOSED_DEVICE_NO_BOUNDARY_SCAN: |
| 577 | case CFG0_CLOSED_DEVICE_NO_JTAG: |
| 578 | return true; |
| 579 | default: |
| 580 | panic(); |
| 581 | } |
| 582 | #endif |
| 583 | #if STM32MP15 |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 584 | return (value & CFG0_CLOSED_DEVICE) == CFG0_CLOSED_DEVICE; |
Nicolas Le Bayon | 34cbf23 | 2020-11-26 09:57:09 +0100 | [diff] [blame] | 585 | #endif |
Lionel Debieve | 0e73d73 | 2019-09-16 12:17:09 +0200 | [diff] [blame] | 586 | } |
| 587 | |
Lionel Debieve | 06bc62d | 2019-12-06 12:42:20 +0100 | [diff] [blame] | 588 | /* Return true when device supports secure boot */ |
| 589 | bool stm32mp_is_auth_supported(void) |
| 590 | { |
| 591 | bool supported = false; |
| 592 | |
| 593 | switch (get_part_number()) { |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 594 | #if STM32MP13 |
| 595 | case STM32MP131C_PART_NB: |
| 596 | case STM32MP131F_PART_NB: |
| 597 | case STM32MP133C_PART_NB: |
| 598 | case STM32MP133F_PART_NB: |
| 599 | case STM32MP135C_PART_NB: |
| 600 | case STM32MP135F_PART_NB: |
| 601 | #endif |
| 602 | #if STM32MP15 |
Lionel Debieve | 06bc62d | 2019-12-06 12:42:20 +0100 | [diff] [blame] | 603 | case STM32MP151C_PART_NB: |
| 604 | case STM32MP151F_PART_NB: |
| 605 | case STM32MP153C_PART_NB: |
| 606 | case STM32MP153F_PART_NB: |
| 607 | case STM32MP157C_PART_NB: |
| 608 | case STM32MP157F_PART_NB: |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 609 | #endif |
Lionel Debieve | 06bc62d | 2019-12-06 12:42:20 +0100 | [diff] [blame] | 610 | supported = true; |
| 611 | break; |
| 612 | default: |
| 613 | break; |
| 614 | } |
| 615 | |
| 616 | return supported; |
| 617 | } |
| 618 | |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 619 | uint32_t stm32_iwdg_get_instance(uintptr_t base) |
| 620 | { |
| 621 | switch (base) { |
| 622 | case IWDG1_BASE: |
| 623 | return IWDG1_INST; |
| 624 | case IWDG2_BASE: |
| 625 | return IWDG2_INST; |
| 626 | default: |
| 627 | panic(); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | uint32_t stm32_iwdg_get_otp_config(uint32_t iwdg_inst) |
| 632 | { |
| 633 | uint32_t iwdg_cfg = 0U; |
| 634 | uint32_t otp_value; |
| 635 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 636 | if (stm32_get_otp_value(HW2_OTP, &otp_value) != 0) { |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 637 | panic(); |
| 638 | } |
| 639 | |
| 640 | if ((otp_value & BIT(iwdg_inst + HW2_OTP_IWDG_HW_POS)) != 0U) { |
| 641 | iwdg_cfg |= IWDG_HW_ENABLED; |
| 642 | } |
| 643 | |
| 644 | if ((otp_value & BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STOP_POS)) != 0U) { |
| 645 | iwdg_cfg |= IWDG_DISABLE_ON_STOP; |
| 646 | } |
| 647 | |
| 648 | if ((otp_value & BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STANDBY_POS)) != 0U) { |
| 649 | iwdg_cfg |= IWDG_DISABLE_ON_STANDBY; |
| 650 | } |
| 651 | |
| 652 | return iwdg_cfg; |
| 653 | } |
| 654 | |
| 655 | #if defined(IMAGE_BL2) |
| 656 | uint32_t stm32_iwdg_shadow_update(uint32_t iwdg_inst, uint32_t flags) |
| 657 | { |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 658 | uint32_t otp_value; |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 659 | uint32_t otp; |
| 660 | uint32_t result; |
| 661 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 662 | if (stm32_get_otp_index(HW2_OTP, &otp, NULL) != 0) { |
| 663 | panic(); |
| 664 | } |
| 665 | |
| 666 | if (stm32_get_otp_value(HW2_OTP, &otp_value) != 0) { |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 667 | panic(); |
| 668 | } |
| 669 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 670 | if ((flags & IWDG_DISABLE_ON_STOP) != 0) { |
| 671 | otp_value |= BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STOP_POS); |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 672 | } |
| 673 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 674 | if ((flags & IWDG_DISABLE_ON_STANDBY) != 0) { |
| 675 | otp_value |= BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STANDBY_POS); |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 676 | } |
| 677 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 678 | result = bsec_write_otp(otp_value, otp); |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 679 | if (result != BSEC_OK) { |
| 680 | return result; |
| 681 | } |
| 682 | |
| 683 | /* Sticky lock OTP_IWDG (read and write) */ |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 684 | if ((bsec_set_sr_lock(otp) != BSEC_OK) || |
| 685 | (bsec_set_sw_lock(otp) != BSEC_OK)) { |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 686 | return BSEC_LOCK_FAIL; |
| 687 | } |
| 688 | |
| 689 | return BSEC_OK; |
| 690 | } |
| 691 | #endif |
Yann Gautier | 8f268c8 | 2020-02-26 13:39:44 +0100 | [diff] [blame] | 692 | |
Lionel Debieve | 1dc5e2e | 2020-09-27 21:13:53 +0200 | [diff] [blame] | 693 | #if STM32MP_USE_STM32IMAGE |
Yann Gautier | 8f268c8 | 2020-02-26 13:39:44 +0100 | [diff] [blame] | 694 | /* Get the non-secure DDR size */ |
| 695 | uint32_t stm32mp_get_ddr_ns_size(void) |
| 696 | { |
| 697 | static uint32_t ddr_ns_size; |
| 698 | uint32_t ddr_size; |
| 699 | |
| 700 | if (ddr_ns_size != 0U) { |
| 701 | return ddr_ns_size; |
| 702 | } |
| 703 | |
| 704 | ddr_size = dt_get_ddr_size(); |
| 705 | if ((ddr_size <= (STM32MP_DDR_S_SIZE + STM32MP_DDR_SHMEM_SIZE)) || |
| 706 | (ddr_size > STM32MP_DDR_MAX_SIZE)) { |
| 707 | panic(); |
| 708 | } |
| 709 | |
| 710 | ddr_ns_size = ddr_size - (STM32MP_DDR_S_SIZE + STM32MP_DDR_SHMEM_SIZE); |
| 711 | |
| 712 | return ddr_ns_size; |
| 713 | } |
Lionel Debieve | 1dc5e2e | 2020-09-27 21:13:53 +0200 | [diff] [blame] | 714 | #endif /* STM32MP_USE_STM32IMAGE */ |
Yann Gautier | 6eef525 | 2021-12-10 17:04:40 +0100 | [diff] [blame] | 715 | |
| 716 | void stm32_save_boot_interface(uint32_t interface, uint32_t instance) |
| 717 | { |
Nicolas Toromanoff | bb82b1b | 2022-02-09 12:26:31 +0100 | [diff] [blame] | 718 | uintptr_t bkpr_itf_idx = tamp_bkpr(TAMP_BOOT_MODE_BACKUP_REG_ID); |
Yann Gautier | 6eef525 | 2021-12-10 17:04:40 +0100 | [diff] [blame] | 719 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 720 | clk_enable(RTCAPB); |
Yann Gautier | 6eef525 | 2021-12-10 17:04:40 +0100 | [diff] [blame] | 721 | |
| 722 | mmio_clrsetbits_32(bkpr_itf_idx, |
| 723 | TAMP_BOOT_MODE_ITF_MASK, |
| 724 | ((interface << 4) | (instance & 0xFU)) << |
| 725 | TAMP_BOOT_MODE_ITF_SHIFT); |
| 726 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 727 | clk_disable(RTCAPB); |
Yann Gautier | 6eef525 | 2021-12-10 17:04:40 +0100 | [diff] [blame] | 728 | } |
Yann Gautier | aaee061 | 2020-12-16 12:04:06 +0100 | [diff] [blame] | 729 | |
| 730 | void stm32_get_boot_interface(uint32_t *interface, uint32_t *instance) |
| 731 | { |
| 732 | static uint32_t itf; |
| 733 | |
| 734 | if (itf == 0U) { |
Nicolas Toromanoff | bb82b1b | 2022-02-09 12:26:31 +0100 | [diff] [blame] | 735 | uintptr_t bkpr = tamp_bkpr(TAMP_BOOT_MODE_BACKUP_REG_ID); |
Yann Gautier | aaee061 | 2020-12-16 12:04:06 +0100 | [diff] [blame] | 736 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 737 | clk_enable(RTCAPB); |
Yann Gautier | aaee061 | 2020-12-16 12:04:06 +0100 | [diff] [blame] | 738 | |
| 739 | itf = (mmio_read_32(bkpr) & TAMP_BOOT_MODE_ITF_MASK) >> |
| 740 | TAMP_BOOT_MODE_ITF_SHIFT; |
| 741 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 742 | clk_disable(RTCAPB); |
Yann Gautier | aaee061 | 2020-12-16 12:04:06 +0100 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | *interface = itf >> 4; |
| 746 | *instance = itf & 0xFU; |
| 747 | } |
Sughosh Ganu | 03e2f80 | 2021-12-01 15:56:27 +0530 | [diff] [blame] | 748 | |
| 749 | #if !STM32MP_USE_STM32IMAGE && PSA_FWU_SUPPORT |
| 750 | void stm32mp1_fwu_set_boot_idx(void) |
| 751 | { |
| 752 | clk_enable(RTCAPB); |
Yann Gautier | 9bbd26a | 2022-03-28 17:49:38 +0200 | [diff] [blame] | 753 | mmio_clrsetbits_32(tamp_bkpr(TAMP_BOOT_FWU_INFO_REG_ID), |
| 754 | TAMP_BOOT_FWU_INFO_IDX_MSK, |
| 755 | (plat_fwu_get_boot_idx() << TAMP_BOOT_FWU_INFO_IDX_OFF) & |
| 756 | TAMP_BOOT_FWU_INFO_IDX_MSK); |
Sughosh Ganu | 03e2f80 | 2021-12-01 15:56:27 +0530 | [diff] [blame] | 757 | clk_disable(RTCAPB); |
| 758 | } |
Nicolas Toromanoff | 5a937cd | 2022-02-07 10:12:04 +0100 | [diff] [blame] | 759 | |
| 760 | uint32_t stm32_get_and_dec_fwu_trial_boot_cnt(void) |
| 761 | { |
| 762 | uintptr_t bkpr_fwu_cnt = tamp_bkpr(TAMP_BOOT_FWU_INFO_REG_ID); |
| 763 | uint32_t try_cnt; |
| 764 | |
| 765 | clk_enable(RTCAPB); |
| 766 | try_cnt = (mmio_read_32(bkpr_fwu_cnt) & TAMP_BOOT_FWU_INFO_CNT_MSK) >> |
| 767 | TAMP_BOOT_FWU_INFO_CNT_OFF; |
| 768 | |
| 769 | assert(try_cnt <= FWU_MAX_TRIAL_REBOOT); |
| 770 | |
| 771 | if (try_cnt != 0U) { |
| 772 | mmio_clrsetbits_32(bkpr_fwu_cnt, TAMP_BOOT_FWU_INFO_CNT_MSK, |
| 773 | (try_cnt - 1U) << TAMP_BOOT_FWU_INFO_CNT_OFF); |
| 774 | } |
| 775 | clk_disable(RTCAPB); |
| 776 | |
| 777 | return try_cnt; |
| 778 | } |
| 779 | |
| 780 | void stm32_set_max_fwu_trial_boot_cnt(void) |
| 781 | { |
| 782 | uintptr_t bkpr_fwu_cnt = tamp_bkpr(TAMP_BOOT_FWU_INFO_REG_ID); |
| 783 | |
| 784 | clk_enable(RTCAPB); |
| 785 | mmio_clrsetbits_32(bkpr_fwu_cnt, TAMP_BOOT_FWU_INFO_CNT_MSK, |
| 786 | (FWU_MAX_TRIAL_REBOOT << TAMP_BOOT_FWU_INFO_CNT_OFF) & |
| 787 | TAMP_BOOT_FWU_INFO_CNT_MSK); |
| 788 | clk_disable(RTCAPB); |
| 789 | } |
Sughosh Ganu | 03e2f80 | 2021-12-01 15:56:27 +0530 | [diff] [blame] | 790 | #endif /* !STM32MP_USE_STM32IMAGE && PSA_FWU_SUPPORT */ |