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 | { |
| 202 | switch (bank) { |
| 203 | case GPIO_BANK_A: |
| 204 | case GPIO_BANK_B: |
| 205 | case GPIO_BANK_C: |
| 206 | case GPIO_BANK_D: |
| 207 | case GPIO_BANK_E: |
| 208 | case GPIO_BANK_F: |
| 209 | case GPIO_BANK_G: |
| 210 | case GPIO_BANK_H: |
| 211 | case GPIO_BANK_I: |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 212 | #if STM32MP15 |
Etienne Carriere | d81dadf | 2020-04-25 11:14:45 +0200 | [diff] [blame] | 213 | case GPIO_BANK_J: |
| 214 | case GPIO_BANK_K: |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 215 | #endif |
Etienne Carriere | d81dadf | 2020-04-25 11:14:45 +0200 | [diff] [blame] | 216 | return fdt_path_offset(fdt, "/soc/pin-controller"); |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 217 | #if STM32MP15 |
Etienne Carriere | d81dadf | 2020-04-25 11:14:45 +0200 | [diff] [blame] | 218 | case GPIO_BANK_Z: |
| 219 | return fdt_path_offset(fdt, "/soc/pin-controller-z"); |
Yann Gautier | cc5f89a | 2020-02-12 09:36:23 +0100 | [diff] [blame] | 220 | #endif |
Etienne Carriere | d81dadf | 2020-04-25 11:14:45 +0200 | [diff] [blame] | 221 | default: |
| 222 | panic(); |
| 223 | } |
| 224 | } |
| 225 | |
Yann Gautier | 3d8497c | 2021-10-18 16:06:22 +0200 | [diff] [blame] | 226 | #if STM32MP_UART_PROGRAMMER || !defined(IMAGE_BL2) |
Patrick Delaunay | e50571b | 2021-10-28 13:48:52 +0200 | [diff] [blame] | 227 | /* |
| 228 | * UART Management |
| 229 | */ |
| 230 | static const uintptr_t stm32mp1_uart_addresses[8] = { |
| 231 | USART1_BASE, |
| 232 | USART2_BASE, |
| 233 | USART3_BASE, |
| 234 | UART4_BASE, |
| 235 | UART5_BASE, |
| 236 | USART6_BASE, |
| 237 | UART7_BASE, |
| 238 | UART8_BASE, |
| 239 | }; |
| 240 | |
| 241 | uintptr_t get_uart_address(uint32_t instance_nb) |
| 242 | { |
| 243 | if ((instance_nb == 0U) || |
| 244 | (instance_nb > ARRAY_SIZE(stm32mp1_uart_addresses))) { |
| 245 | return 0U; |
| 246 | } |
| 247 | |
| 248 | return stm32mp1_uart_addresses[instance_nb - 1U]; |
| 249 | } |
| 250 | #endif |
| 251 | |
Yann Gautier | cd16df3 | 2021-06-04 14:04:05 +0200 | [diff] [blame] | 252 | #if STM32MP_USB_PROGRAMMER |
| 253 | struct gpio_bank_pin_list { |
| 254 | uint32_t bank; |
| 255 | uint32_t pin; |
| 256 | }; |
| 257 | |
| 258 | static const struct gpio_bank_pin_list gpio_list[] = { |
| 259 | { /* USART2_RX: GPIOA3 */ |
| 260 | .bank = 0U, |
| 261 | .pin = 3U, |
| 262 | }, |
| 263 | { /* USART3_RX: GPIOB12 */ |
| 264 | .bank = 1U, |
| 265 | .pin = 12U, |
| 266 | }, |
| 267 | { /* UART4_RX: GPIOB2 */ |
| 268 | .bank = 1U, |
| 269 | .pin = 2U, |
| 270 | }, |
| 271 | { /* UART5_RX: GPIOB4 */ |
| 272 | .bank = 1U, |
| 273 | .pin = 5U, |
| 274 | }, |
| 275 | { /* USART6_RX: GPIOC7 */ |
| 276 | .bank = 2U, |
| 277 | .pin = 7U, |
| 278 | }, |
| 279 | { /* UART7_RX: GPIOF6 */ |
| 280 | .bank = 5U, |
| 281 | .pin = 6U, |
| 282 | }, |
| 283 | { /* UART8_RX: GPIOE0 */ |
| 284 | .bank = 4U, |
| 285 | .pin = 0U, |
| 286 | }, |
| 287 | }; |
| 288 | |
| 289 | void stm32mp1_deconfigure_uart_pins(void) |
| 290 | { |
| 291 | size_t i; |
| 292 | |
| 293 | for (i = 0U; i < ARRAY_SIZE(gpio_list); i++) { |
| 294 | set_gpio_reset_cfg(gpio_list[i].bank, gpio_list[i].pin); |
| 295 | } |
| 296 | } |
| 297 | #endif |
| 298 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 299 | uint32_t stm32mp_get_chip_version(void) |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 300 | { |
Yann Gautier | f36a1d3 | 2020-04-21 15:03:59 +0200 | [diff] [blame] | 301 | #if STM32MP13 |
| 302 | return stm32mp1_syscfg_get_chip_version(); |
| 303 | #endif |
| 304 | #if STM32MP15 |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 305 | uint32_t version = 0U; |
| 306 | |
| 307 | if (stm32mp1_dbgmcu_get_chip_version(&version) < 0) { |
| 308 | INFO("Cannot get CPU version, debug disabled\n"); |
| 309 | return 0U; |
| 310 | } |
| 311 | |
| 312 | return version; |
Yann Gautier | f36a1d3 | 2020-04-21 15:03:59 +0200 | [diff] [blame] | 313 | #endif |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 314 | } |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 315 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 316 | uint32_t stm32mp_get_chip_dev_id(void) |
| 317 | { |
Yann Gautier | f36a1d3 | 2020-04-21 15:03:59 +0200 | [diff] [blame] | 318 | #if STM32MP13 |
| 319 | return stm32mp1_syscfg_get_chip_dev_id(); |
| 320 | #endif |
| 321 | #if STM32MP15 |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 322 | uint32_t dev_id; |
Nicolas Le Bayon | 98f4ea0 | 2019-09-23 11:18:32 +0200 | [diff] [blame] | 323 | |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 324 | if (stm32mp1_dbgmcu_get_chip_dev_id(&dev_id) < 0) { |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 325 | INFO("Use default chip ID, debug disabled\n"); |
| 326 | dev_id = STM32MP1_CHIP_ID; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 327 | } |
| 328 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 329 | return dev_id; |
Yann Gautier | f36a1d3 | 2020-04-21 15:03:59 +0200 | [diff] [blame] | 330 | #endif |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | static uint32_t get_part_number(void) |
| 334 | { |
| 335 | static uint32_t part_number; |
| 336 | |
| 337 | if (part_number != 0U) { |
| 338 | return part_number; |
| 339 | } |
| 340 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 341 | if (stm32_get_otp_value(PART_NUMBER_OTP, &part_number) != 0) { |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 342 | panic(); |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | part_number = (part_number & PART_NUMBER_OTP_PART_MASK) >> |
| 346 | PART_NUMBER_OTP_PART_SHIFT; |
| 347 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 348 | part_number |= stm32mp_get_chip_dev_id() << 16; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 349 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 350 | return part_number; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 351 | } |
| 352 | |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 353 | #if STM32MP15 |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 354 | static uint32_t get_cpu_package(void) |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 355 | { |
| 356 | uint32_t package; |
| 357 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 358 | if (stm32_get_otp_value(PACKAGE_OTP, &package) != 0) { |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 359 | panic(); |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 360 | } |
| 361 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 362 | package = (package & PACKAGE_OTP_PKG_MASK) >> |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 363 | PACKAGE_OTP_PKG_SHIFT; |
| 364 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 365 | return package; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 366 | } |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 367 | #endif |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 368 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 369 | void stm32mp_get_soc_name(char name[STM32_SOC_NAME_SIZE]) |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 370 | { |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 371 | char *cpu_s, *cpu_r, *pkg; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 372 | |
| 373 | /* MPUs Part Numbers */ |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 374 | switch (get_part_number()) { |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 375 | #if STM32MP13 |
| 376 | case STM32MP135F_PART_NB: |
| 377 | cpu_s = "135F"; |
| 378 | break; |
| 379 | case STM32MP135D_PART_NB: |
| 380 | cpu_s = "135D"; |
| 381 | break; |
| 382 | case STM32MP135C_PART_NB: |
| 383 | cpu_s = "135C"; |
| 384 | break; |
| 385 | case STM32MP135A_PART_NB: |
| 386 | cpu_s = "135A"; |
| 387 | break; |
| 388 | case STM32MP133F_PART_NB: |
| 389 | cpu_s = "133F"; |
| 390 | break; |
| 391 | case STM32MP133D_PART_NB: |
| 392 | cpu_s = "133D"; |
| 393 | break; |
| 394 | case STM32MP133C_PART_NB: |
| 395 | cpu_s = "133C"; |
| 396 | break; |
| 397 | case STM32MP133A_PART_NB: |
| 398 | cpu_s = "133A"; |
| 399 | break; |
| 400 | case STM32MP131F_PART_NB: |
| 401 | cpu_s = "131F"; |
| 402 | break; |
| 403 | case STM32MP131D_PART_NB: |
| 404 | cpu_s = "131D"; |
| 405 | break; |
| 406 | case STM32MP131C_PART_NB: |
| 407 | cpu_s = "131C"; |
| 408 | break; |
| 409 | case STM32MP131A_PART_NB: |
| 410 | cpu_s = "131A"; |
| 411 | break; |
| 412 | #endif |
| 413 | #if STM32MP15 |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 414 | case STM32MP157C_PART_NB: |
| 415 | cpu_s = "157C"; |
| 416 | break; |
| 417 | case STM32MP157A_PART_NB: |
| 418 | cpu_s = "157A"; |
| 419 | break; |
| 420 | case STM32MP153C_PART_NB: |
| 421 | cpu_s = "153C"; |
| 422 | break; |
| 423 | case STM32MP153A_PART_NB: |
| 424 | cpu_s = "153A"; |
| 425 | break; |
| 426 | case STM32MP151C_PART_NB: |
| 427 | cpu_s = "151C"; |
| 428 | break; |
| 429 | case STM32MP151A_PART_NB: |
| 430 | cpu_s = "151A"; |
| 431 | break; |
Lionel Debieve | 7b64e3e | 2019-05-17 16:01:18 +0200 | [diff] [blame] | 432 | case STM32MP157F_PART_NB: |
| 433 | cpu_s = "157F"; |
| 434 | break; |
| 435 | case STM32MP157D_PART_NB: |
| 436 | cpu_s = "157D"; |
| 437 | break; |
| 438 | case STM32MP153F_PART_NB: |
| 439 | cpu_s = "153F"; |
| 440 | break; |
| 441 | case STM32MP153D_PART_NB: |
| 442 | cpu_s = "153D"; |
| 443 | break; |
| 444 | case STM32MP151F_PART_NB: |
| 445 | cpu_s = "151F"; |
| 446 | break; |
| 447 | case STM32MP151D_PART_NB: |
| 448 | cpu_s = "151D"; |
| 449 | break; |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 450 | #endif |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 451 | default: |
| 452 | cpu_s = "????"; |
| 453 | break; |
| 454 | } |
| 455 | |
| 456 | /* Package */ |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 457 | #if STM32MP13 |
| 458 | /* On STM32MP13, package is not present in OTP */ |
| 459 | pkg = ""; |
| 460 | #endif |
| 461 | #if STM32MP15 |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 462 | switch (get_cpu_package()) { |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 463 | case PKG_AA_LFBGA448: |
| 464 | pkg = "AA"; |
| 465 | break; |
| 466 | case PKG_AB_LFBGA354: |
| 467 | pkg = "AB"; |
| 468 | break; |
| 469 | case PKG_AC_TFBGA361: |
| 470 | pkg = "AC"; |
| 471 | break; |
| 472 | case PKG_AD_TFBGA257: |
| 473 | pkg = "AD"; |
| 474 | break; |
| 475 | default: |
| 476 | pkg = "??"; |
| 477 | break; |
| 478 | } |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 479 | #endif |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 480 | |
| 481 | /* REVISION */ |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 482 | switch (stm32mp_get_chip_version()) { |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 483 | case STM32MP1_REV_B: |
| 484 | cpu_r = "B"; |
| 485 | break; |
Lionel Debieve | 2d64b53 | 2019-06-25 10:40:37 +0200 | [diff] [blame] | 486 | case STM32MP1_REV_Z: |
| 487 | cpu_r = "Z"; |
| 488 | break; |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 489 | default: |
| 490 | cpu_r = "?"; |
| 491 | break; |
| 492 | } |
| 493 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 494 | snprintf(name, STM32_SOC_NAME_SIZE, |
| 495 | "STM32MP%s%s Rev.%s", cpu_s, pkg, cpu_r); |
| 496 | } |
| 497 | |
| 498 | void stm32mp_print_cpuinfo(void) |
| 499 | { |
| 500 | char name[STM32_SOC_NAME_SIZE]; |
| 501 | |
| 502 | stm32mp_get_soc_name(name); |
| 503 | NOTICE("CPU: %s\n", name); |
Yann Gautier | c737405 | 2019-06-04 18:02:37 +0200 | [diff] [blame] | 504 | } |
| 505 | |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 506 | void stm32mp_print_boardinfo(void) |
| 507 | { |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 508 | uint32_t board_id = 0; |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 509 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 510 | if (stm32_get_otp_value(BOARD_ID_OTP, &board_id) != 0) { |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 511 | return; |
| 512 | } |
| 513 | |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 514 | if (board_id != 0U) { |
| 515 | char rev[2]; |
| 516 | |
| 517 | rev[0] = BOARD_ID2REV(board_id) - 1 + 'A'; |
| 518 | rev[1] = '\0'; |
Yann Gautier | 36e9d38 | 2020-10-13 18:03:31 +0200 | [diff] [blame] | 519 | NOTICE("Board: MB%04x Var%u.%u Rev.%s-%02u\n", |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 520 | BOARD_ID2NB(board_id), |
Patrick Delaunay | 7704f16 | 2020-01-08 10:05:14 +0100 | [diff] [blame] | 521 | BOARD_ID2VARCPN(board_id), |
| 522 | BOARD_ID2VARFG(board_id), |
Yann Gautier | 35dc077 | 2019-05-13 18:34:48 +0200 | [diff] [blame] | 523 | rev, |
| 524 | BOARD_ID2BOM(board_id)); |
| 525 | } |
| 526 | } |
| 527 | |
Yann Gautier | af19ff9 | 2019-06-04 18:23:10 +0200 | [diff] [blame] | 528 | /* Return true when SoC provides a single Cortex-A7 core, and false otherwise */ |
| 529 | bool stm32mp_is_single_core(void) |
| 530 | { |
Yann Gautier | 6bd30e2 | 2020-02-06 15:34:16 +0100 | [diff] [blame] | 531 | #if STM32MP13 |
| 532 | return true; |
| 533 | #endif |
| 534 | #if STM32MP15 |
Yann Gautier | 2f3b560 | 2021-10-19 13:31:06 +0200 | [diff] [blame] | 535 | bool single_core = false; |
| 536 | |
Yann Gautier | a0a6ff6 | 2021-05-10 16:05:18 +0200 | [diff] [blame] | 537 | switch (get_part_number()) { |
Yann Gautier | af19ff9 | 2019-06-04 18:23:10 +0200 | [diff] [blame] | 538 | case STM32MP151A_PART_NB: |
| 539 | case STM32MP151C_PART_NB: |
Lionel Debieve | 7b64e3e | 2019-05-17 16:01:18 +0200 | [diff] [blame] | 540 | case STM32MP151D_PART_NB: |
| 541 | case STM32MP151F_PART_NB: |
Yann Gautier | 2f3b560 | 2021-10-19 13:31:06 +0200 | [diff] [blame] | 542 | single_core = true; |
| 543 | break; |
Yann Gautier | af19ff9 | 2019-06-04 18:23:10 +0200 | [diff] [blame] | 544 | default: |
Yann Gautier | 2f3b560 | 2021-10-19 13:31:06 +0200 | [diff] [blame] | 545 | break; |
Yann Gautier | af19ff9 | 2019-06-04 18:23:10 +0200 | [diff] [blame] | 546 | } |
Yann Gautier | 2f3b560 | 2021-10-19 13:31:06 +0200 | [diff] [blame] | 547 | |
| 548 | return single_core; |
Yann Gautier | 6bd30e2 | 2020-02-06 15:34:16 +0100 | [diff] [blame] | 549 | #endif |
Yann Gautier | af19ff9 | 2019-06-04 18:23:10 +0200 | [diff] [blame] | 550 | } |
| 551 | |
Lionel Debieve | 0e73d73 | 2019-09-16 12:17:09 +0200 | [diff] [blame] | 552 | /* Return true when device is in closed state */ |
| 553 | bool stm32mp_is_closed_device(void) |
| 554 | { |
| 555 | uint32_t value; |
| 556 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 557 | if (stm32_get_otp_value(CFG0_OTP, &value) != 0) { |
Lionel Debieve | 0e73d73 | 2019-09-16 12:17:09 +0200 | [diff] [blame] | 558 | return true; |
| 559 | } |
| 560 | |
Nicolas Le Bayon | 34cbf23 | 2020-11-26 09:57:09 +0100 | [diff] [blame] | 561 | #if STM32MP13 |
| 562 | value = (value & CFG0_OTP_MODE_MASK) >> CFG0_OTP_MODE_SHIFT; |
| 563 | |
| 564 | switch (value) { |
| 565 | case CFG0_OPEN_DEVICE: |
| 566 | return false; |
| 567 | case CFG0_CLOSED_DEVICE: |
| 568 | case CFG0_CLOSED_DEVICE_NO_BOUNDARY_SCAN: |
| 569 | case CFG0_CLOSED_DEVICE_NO_JTAG: |
| 570 | return true; |
| 571 | default: |
| 572 | panic(); |
| 573 | } |
| 574 | #endif |
| 575 | #if STM32MP15 |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 576 | return (value & CFG0_CLOSED_DEVICE) == CFG0_CLOSED_DEVICE; |
Nicolas Le Bayon | 34cbf23 | 2020-11-26 09:57:09 +0100 | [diff] [blame] | 577 | #endif |
Lionel Debieve | 0e73d73 | 2019-09-16 12:17:09 +0200 | [diff] [blame] | 578 | } |
| 579 | |
Lionel Debieve | 06bc62d | 2019-12-06 12:42:20 +0100 | [diff] [blame] | 580 | /* Return true when device supports secure boot */ |
| 581 | bool stm32mp_is_auth_supported(void) |
| 582 | { |
| 583 | bool supported = false; |
| 584 | |
| 585 | switch (get_part_number()) { |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 586 | #if STM32MP13 |
| 587 | case STM32MP131C_PART_NB: |
| 588 | case STM32MP131F_PART_NB: |
| 589 | case STM32MP133C_PART_NB: |
| 590 | case STM32MP133F_PART_NB: |
| 591 | case STM32MP135C_PART_NB: |
| 592 | case STM32MP135F_PART_NB: |
| 593 | #endif |
| 594 | #if STM32MP15 |
Lionel Debieve | 06bc62d | 2019-12-06 12:42:20 +0100 | [diff] [blame] | 595 | case STM32MP151C_PART_NB: |
| 596 | case STM32MP151F_PART_NB: |
| 597 | case STM32MP153C_PART_NB: |
| 598 | case STM32MP153F_PART_NB: |
| 599 | case STM32MP157C_PART_NB: |
| 600 | case STM32MP157F_PART_NB: |
Yann Gautier | 16188f3 | 2020-02-12 15:38:34 +0100 | [diff] [blame] | 601 | #endif |
Lionel Debieve | 06bc62d | 2019-12-06 12:42:20 +0100 | [diff] [blame] | 602 | supported = true; |
| 603 | break; |
| 604 | default: |
| 605 | break; |
| 606 | } |
| 607 | |
| 608 | return supported; |
| 609 | } |
| 610 | |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 611 | uint32_t stm32_iwdg_get_instance(uintptr_t base) |
| 612 | { |
| 613 | switch (base) { |
| 614 | case IWDG1_BASE: |
| 615 | return IWDG1_INST; |
| 616 | case IWDG2_BASE: |
| 617 | return IWDG2_INST; |
| 618 | default: |
| 619 | panic(); |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | uint32_t stm32_iwdg_get_otp_config(uint32_t iwdg_inst) |
| 624 | { |
| 625 | uint32_t iwdg_cfg = 0U; |
| 626 | uint32_t otp_value; |
| 627 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 628 | if (stm32_get_otp_value(HW2_OTP, &otp_value) != 0) { |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 629 | panic(); |
| 630 | } |
| 631 | |
| 632 | if ((otp_value & BIT(iwdg_inst + HW2_OTP_IWDG_HW_POS)) != 0U) { |
| 633 | iwdg_cfg |= IWDG_HW_ENABLED; |
| 634 | } |
| 635 | |
| 636 | if ((otp_value & BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STOP_POS)) != 0U) { |
| 637 | iwdg_cfg |= IWDG_DISABLE_ON_STOP; |
| 638 | } |
| 639 | |
| 640 | if ((otp_value & BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STANDBY_POS)) != 0U) { |
| 641 | iwdg_cfg |= IWDG_DISABLE_ON_STANDBY; |
| 642 | } |
| 643 | |
| 644 | return iwdg_cfg; |
| 645 | } |
| 646 | |
| 647 | #if defined(IMAGE_BL2) |
| 648 | uint32_t stm32_iwdg_shadow_update(uint32_t iwdg_inst, uint32_t flags) |
| 649 | { |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 650 | uint32_t otp_value; |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 651 | uint32_t otp; |
| 652 | uint32_t result; |
| 653 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 654 | if (stm32_get_otp_index(HW2_OTP, &otp, NULL) != 0) { |
| 655 | panic(); |
| 656 | } |
| 657 | |
| 658 | if (stm32_get_otp_value(HW2_OTP, &otp_value) != 0) { |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 659 | panic(); |
| 660 | } |
| 661 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 662 | if ((flags & IWDG_DISABLE_ON_STOP) != 0) { |
| 663 | otp_value |= BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STOP_POS); |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 664 | } |
| 665 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 666 | if ((flags & IWDG_DISABLE_ON_STANDBY) != 0) { |
| 667 | otp_value |= BIT(iwdg_inst + HW2_OTP_IWDG_FZ_STANDBY_POS); |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 668 | } |
| 669 | |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 670 | result = bsec_write_otp(otp_value, otp); |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 671 | if (result != BSEC_OK) { |
| 672 | return result; |
| 673 | } |
| 674 | |
| 675 | /* Sticky lock OTP_IWDG (read and write) */ |
Lionel Debieve | bc2d88d | 2019-11-04 14:31:38 +0100 | [diff] [blame] | 676 | if ((bsec_set_sr_lock(otp) != BSEC_OK) || |
| 677 | (bsec_set_sw_lock(otp) != BSEC_OK)) { |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 678 | return BSEC_LOCK_FAIL; |
| 679 | } |
| 680 | |
| 681 | return BSEC_OK; |
| 682 | } |
| 683 | #endif |
Yann Gautier | 8f268c8 | 2020-02-26 13:39:44 +0100 | [diff] [blame] | 684 | |
Lionel Debieve | 1dc5e2e | 2020-09-27 21:13:53 +0200 | [diff] [blame] | 685 | #if STM32MP_USE_STM32IMAGE |
Yann Gautier | 8f268c8 | 2020-02-26 13:39:44 +0100 | [diff] [blame] | 686 | /* Get the non-secure DDR size */ |
| 687 | uint32_t stm32mp_get_ddr_ns_size(void) |
| 688 | { |
| 689 | static uint32_t ddr_ns_size; |
| 690 | uint32_t ddr_size; |
| 691 | |
| 692 | if (ddr_ns_size != 0U) { |
| 693 | return ddr_ns_size; |
| 694 | } |
| 695 | |
| 696 | ddr_size = dt_get_ddr_size(); |
| 697 | if ((ddr_size <= (STM32MP_DDR_S_SIZE + STM32MP_DDR_SHMEM_SIZE)) || |
| 698 | (ddr_size > STM32MP_DDR_MAX_SIZE)) { |
| 699 | panic(); |
| 700 | } |
| 701 | |
| 702 | ddr_ns_size = ddr_size - (STM32MP_DDR_S_SIZE + STM32MP_DDR_SHMEM_SIZE); |
| 703 | |
| 704 | return ddr_ns_size; |
| 705 | } |
Lionel Debieve | 1dc5e2e | 2020-09-27 21:13:53 +0200 | [diff] [blame] | 706 | #endif /* STM32MP_USE_STM32IMAGE */ |
Yann Gautier | 6eef525 | 2021-12-10 17:04:40 +0100 | [diff] [blame] | 707 | |
| 708 | void stm32_save_boot_interface(uint32_t interface, uint32_t instance) |
| 709 | { |
Nicolas Toromanoff | bb82b1b | 2022-02-09 12:26:31 +0100 | [diff] [blame] | 710 | 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] | 711 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 712 | clk_enable(RTCAPB); |
Yann Gautier | 6eef525 | 2021-12-10 17:04:40 +0100 | [diff] [blame] | 713 | |
| 714 | mmio_clrsetbits_32(bkpr_itf_idx, |
| 715 | TAMP_BOOT_MODE_ITF_MASK, |
| 716 | ((interface << 4) | (instance & 0xFU)) << |
| 717 | TAMP_BOOT_MODE_ITF_SHIFT); |
| 718 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 719 | clk_disable(RTCAPB); |
Yann Gautier | 6eef525 | 2021-12-10 17:04:40 +0100 | [diff] [blame] | 720 | } |
Yann Gautier | aaee061 | 2020-12-16 12:04:06 +0100 | [diff] [blame] | 721 | |
| 722 | void stm32_get_boot_interface(uint32_t *interface, uint32_t *instance) |
| 723 | { |
| 724 | static uint32_t itf; |
| 725 | |
| 726 | if (itf == 0U) { |
Nicolas Toromanoff | bb82b1b | 2022-02-09 12:26:31 +0100 | [diff] [blame] | 727 | uintptr_t bkpr = tamp_bkpr(TAMP_BOOT_MODE_BACKUP_REG_ID); |
Yann Gautier | aaee061 | 2020-12-16 12:04:06 +0100 | [diff] [blame] | 728 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 729 | clk_enable(RTCAPB); |
Yann Gautier | aaee061 | 2020-12-16 12:04:06 +0100 | [diff] [blame] | 730 | |
| 731 | itf = (mmio_read_32(bkpr) & TAMP_BOOT_MODE_ITF_MASK) >> |
| 732 | TAMP_BOOT_MODE_ITF_SHIFT; |
| 733 | |
Yann Gautier | a205a5c | 2021-08-30 15:06:54 +0200 | [diff] [blame] | 734 | clk_disable(RTCAPB); |
Yann Gautier | aaee061 | 2020-12-16 12:04:06 +0100 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | *interface = itf >> 4; |
| 738 | *instance = itf & 0xFU; |
| 739 | } |
Sughosh Ganu | 03e2f80 | 2021-12-01 15:56:27 +0530 | [diff] [blame] | 740 | |
| 741 | #if !STM32MP_USE_STM32IMAGE && PSA_FWU_SUPPORT |
| 742 | void stm32mp1_fwu_set_boot_idx(void) |
| 743 | { |
| 744 | clk_enable(RTCAPB); |
Yann Gautier | 9bbd26a | 2022-03-28 17:49:38 +0200 | [diff] [blame] | 745 | mmio_clrsetbits_32(tamp_bkpr(TAMP_BOOT_FWU_INFO_REG_ID), |
| 746 | TAMP_BOOT_FWU_INFO_IDX_MSK, |
| 747 | (plat_fwu_get_boot_idx() << TAMP_BOOT_FWU_INFO_IDX_OFF) & |
| 748 | TAMP_BOOT_FWU_INFO_IDX_MSK); |
Sughosh Ganu | 03e2f80 | 2021-12-01 15:56:27 +0530 | [diff] [blame] | 749 | clk_disable(RTCAPB); |
| 750 | } |
Nicolas Toromanoff | 5a937cd | 2022-02-07 10:12:04 +0100 | [diff] [blame] | 751 | |
| 752 | uint32_t stm32_get_and_dec_fwu_trial_boot_cnt(void) |
| 753 | { |
| 754 | uintptr_t bkpr_fwu_cnt = tamp_bkpr(TAMP_BOOT_FWU_INFO_REG_ID); |
| 755 | uint32_t try_cnt; |
| 756 | |
| 757 | clk_enable(RTCAPB); |
| 758 | try_cnt = (mmio_read_32(bkpr_fwu_cnt) & TAMP_BOOT_FWU_INFO_CNT_MSK) >> |
| 759 | TAMP_BOOT_FWU_INFO_CNT_OFF; |
| 760 | |
| 761 | assert(try_cnt <= FWU_MAX_TRIAL_REBOOT); |
| 762 | |
| 763 | if (try_cnt != 0U) { |
| 764 | mmio_clrsetbits_32(bkpr_fwu_cnt, TAMP_BOOT_FWU_INFO_CNT_MSK, |
| 765 | (try_cnt - 1U) << TAMP_BOOT_FWU_INFO_CNT_OFF); |
| 766 | } |
| 767 | clk_disable(RTCAPB); |
| 768 | |
| 769 | return try_cnt; |
| 770 | } |
| 771 | |
| 772 | void stm32_set_max_fwu_trial_boot_cnt(void) |
| 773 | { |
| 774 | uintptr_t bkpr_fwu_cnt = tamp_bkpr(TAMP_BOOT_FWU_INFO_REG_ID); |
| 775 | |
| 776 | clk_enable(RTCAPB); |
| 777 | mmio_clrsetbits_32(bkpr_fwu_cnt, TAMP_BOOT_FWU_INFO_CNT_MSK, |
| 778 | (FWU_MAX_TRIAL_REBOOT << TAMP_BOOT_FWU_INFO_CNT_OFF) & |
| 779 | TAMP_BOOT_FWU_INFO_CNT_MSK); |
| 780 | clk_disable(RTCAPB); |
| 781 | } |
Sughosh Ganu | 03e2f80 | 2021-12-01 15:56:27 +0530 | [diff] [blame] | 782 | #endif /* !STM32MP_USE_STM32IMAGE && PSA_FWU_SUPPORT */ |