Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Gaurav Jain | db4dd6a | 2022-03-24 11:50:33 +0530 | [diff] [blame] | 3 | * Copyright 2018, 2021 NXP |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 6 | #include <clk.h> |
Anatolij Gustschin | 9b39be9 | 2018-10-18 14:28:24 +0200 | [diff] [blame] | 7 | #include <cpu.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | fc55736 | 2022-03-04 08:43:05 -0700 | [diff] [blame] | 10 | #include <event.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 13 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 15 | #include <dm/device-internal.h> |
| 16 | #include <dm/lists.h> |
| 17 | #include <dm/uclass.h> |
| 18 | #include <errno.h> |
Peng Fan | 617fc29 | 2020-05-05 20:28:41 +0800 | [diff] [blame] | 19 | #include <spl.h> |
Peng Fan | 48f9c4e | 2019-04-26 01:44:27 +0000 | [diff] [blame] | 20 | #include <thermal.h> |
Peng Fan | 2e0644a | 2023-04-28 12:08:09 +0800 | [diff] [blame] | 21 | #include <firmware/imx/sci/sci.h> |
Peng Fan | 29c9dd3 | 2018-10-18 14:28:19 +0200 | [diff] [blame] | 22 | #include <asm/arch/sys_proto.h> |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 23 | #include <asm/arch-imx/cpu.h> |
| 24 | #include <asm/armv8/cpu.h> |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 25 | #include <asm/armv8/mmu.h> |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 26 | #include <asm/setup.h> |
Peng Fan | 29c9dd3 | 2018-10-18 14:28:19 +0200 | [diff] [blame] | 27 | #include <asm/mach-imx/boot_mode.h> |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 28 | #include <power-domain.h> |
| 29 | #include <elf.h> |
Ye Li | c3169bd | 2020-05-05 20:28:42 +0800 | [diff] [blame] | 30 | #include <spl.h> |
Peng Fan | 2e6be07 | 2018-10-18 14:28:18 +0200 | [diff] [blame] | 31 | |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 34 | #define BT_PASSOVER_TAG 0x504F |
| 35 | struct pass_over_info_t *get_pass_over_info(void) |
| 36 | { |
| 37 | struct pass_over_info_t *p = |
| 38 | (struct pass_over_info_t *)PASS_OVER_INFO_ADDR; |
| 39 | |
| 40 | if (p->barker != BT_PASSOVER_TAG || |
| 41 | p->len != sizeof(struct pass_over_info_t)) |
| 42 | return NULL; |
| 43 | |
| 44 | return p; |
| 45 | } |
| 46 | |
Igor Opaniuk | ab5ffef | 2024-01-31 13:49:26 +0100 | [diff] [blame] | 47 | static char *get_reset_cause(void) |
| 48 | { |
| 49 | sc_pm_reset_reason_t reason; |
| 50 | |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 51 | if (sc_pm_reset_reason(-1, &reason)) |
Igor Opaniuk | ab5ffef | 2024-01-31 13:49:26 +0100 | [diff] [blame] | 52 | return "Unknown reset"; |
| 53 | |
| 54 | switch (reason) { |
| 55 | case SC_PM_RESET_REASON_POR: |
| 56 | return "POR"; |
| 57 | case SC_PM_RESET_REASON_JTAG: |
| 58 | return "JTAG reset "; |
| 59 | case SC_PM_RESET_REASON_SW: |
| 60 | return "Software reset"; |
| 61 | case SC_PM_RESET_REASON_WDOG: |
| 62 | return "Watchdog reset"; |
| 63 | case SC_PM_RESET_REASON_LOCKUP: |
| 64 | return "SCU lockup reset"; |
| 65 | case SC_PM_RESET_REASON_SNVS: |
| 66 | return "SNVS reset"; |
| 67 | case SC_PM_RESET_REASON_TEMP: |
| 68 | return "Temp panic reset"; |
| 69 | case SC_PM_RESET_REASON_MSI: |
| 70 | return "MSI reset"; |
| 71 | case SC_PM_RESET_REASON_UECC: |
| 72 | return "ECC reset"; |
| 73 | case SC_PM_RESET_REASON_SCFW_WDOG: |
| 74 | return "SCFW watchdog reset"; |
| 75 | case SC_PM_RESET_REASON_ROM_WDOG: |
| 76 | return "SCU ROM watchdog reset"; |
| 77 | case SC_PM_RESET_REASON_SECO: |
| 78 | return "SECO reset"; |
| 79 | case SC_PM_RESET_REASON_SCFW_FAULT: |
| 80 | return "SCFW fault reset"; |
| 81 | default: |
| 82 | return "Unknown reset"; |
| 83 | } |
| 84 | } |
| 85 | |
Fabio Estevam | 70b39d0 | 2024-03-26 09:19:49 -0300 | [diff] [blame] | 86 | __weak void reset_cpu(void) |
| 87 | { |
| 88 | } |
| 89 | |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 90 | int arch_cpu_init(void) |
| 91 | { |
Simon Glass | 85ed77d | 2024-09-29 19:49:46 -0600 | [diff] [blame] | 92 | #if defined(CONFIG_XPL_BUILD) && defined(CONFIG_SPL_RECOVER_DATA_SECTION) |
Peng Fan | 617fc29 | 2020-05-05 20:28:41 +0800 | [diff] [blame] | 93 | spl_save_restore_data(); |
| 94 | #endif |
| 95 | |
Simon Glass | 85ed77d | 2024-09-29 19:49:46 -0600 | [diff] [blame] | 96 | #ifdef CONFIG_XPL_BUILD |
Peng Fan | 0bcec7f | 2019-01-18 08:58:38 +0000 | [diff] [blame] | 97 | struct pass_over_info_t *pass_over; |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 98 | |
Peng Fan | 0bcec7f | 2019-01-18 08:58:38 +0000 | [diff] [blame] | 99 | if (is_soc_rev(CHIP_REV_A)) { |
| 100 | pass_over = get_pass_over_info(); |
| 101 | if (pass_over && pass_over->g_ap_mu == 0) { |
| 102 | /* |
| 103 | * When ap_mu is 0, means the U-Boot booted |
| 104 | * from first container |
| 105 | */ |
| 106 | sc_misc_boot_status(-1, SC_MISC_BOOT_STATUS_SUCCESS); |
| 107 | } |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 108 | } |
Peng Fan | 0bcec7f | 2019-01-18 08:58:38 +0000 | [diff] [blame] | 109 | #endif |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
Simon Glass | b8357c1 | 2023-08-21 21:16:56 -0600 | [diff] [blame] | 114 | static int imx8_init_mu(void) |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 115 | { |
| 116 | struct udevice *devp; |
| 117 | int node, ret; |
| 118 | |
| 119 | node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "fsl,imx8-mu"); |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 120 | |
Ye Li | f2ea6f0 | 2019-08-26 08:11:42 +0000 | [diff] [blame] | 121 | ret = uclass_get_device_by_of_offset(UCLASS_MISC, node, &devp); |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 122 | if (ret) { |
Ye Li | f2ea6f0 | 2019-08-26 08:11:42 +0000 | [diff] [blame] | 123 | printf("could not get scu %d\n", ret); |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 124 | return ret; |
| 125 | } |
| 126 | |
Peng Fan | ee380c5 | 2019-08-26 08:11:49 +0000 | [diff] [blame] | 127 | if (is_imx8qm()) { |
| 128 | ret = sc_pm_set_resource_power_mode(-1, SC_R_SMMU, |
| 129 | SC_PM_PW_MODE_ON); |
| 130 | if (ret) |
| 131 | return ret; |
| 132 | } |
| 133 | |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 134 | return 0; |
| 135 | } |
Simon Glass | b8357c1 | 2023-08-21 21:16:56 -0600 | [diff] [blame] | 136 | EVENT_SPY_SIMPLE(EVT_DM_POST_INIT_F, imx8_init_mu); |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 137 | |
Gaurav Jain | db4dd6a | 2022-03-24 11:50:33 +0530 | [diff] [blame] | 138 | #if defined(CONFIG_ARCH_MISC_INIT) |
| 139 | int arch_misc_init(void) |
| 140 | { |
| 141 | if (IS_ENABLED(CONFIG_FSL_CAAM)) { |
| 142 | struct udevice *dev; |
| 143 | int ret; |
| 144 | |
| 145 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev); |
| 146 | if (ret) |
Ye Li | ec34689 | 2022-05-11 13:56:20 +0530 | [diff] [blame] | 147 | printf("Failed to initialize caam_jr: %d\n", ret); |
Gaurav Jain | db4dd6a | 2022-03-24 11:50:33 +0530 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | #endif |
| 153 | |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 154 | #ifdef CONFIG_IMX_BOOTAUX |
| 155 | |
| 156 | #ifdef CONFIG_IMX8QM |
| 157 | int arch_auxiliary_core_up(u32 core_id, ulong boot_private_data) |
| 158 | { |
| 159 | sc_rsrc_t core_rsrc, mu_rsrc; |
| 160 | sc_faddr_t tcml_addr; |
| 161 | u32 tcml_size = SZ_128K; |
| 162 | ulong addr; |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 163 | int ret; |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 164 | |
| 165 | switch (core_id) { |
| 166 | case 0: |
| 167 | core_rsrc = SC_R_M4_0_PID0; |
| 168 | tcml_addr = 0x34FE0000; |
| 169 | mu_rsrc = SC_R_M4_0_MU_1A; |
| 170 | break; |
| 171 | case 1: |
| 172 | core_rsrc = SC_R_M4_1_PID0; |
| 173 | tcml_addr = 0x38FE0000; |
| 174 | mu_rsrc = SC_R_M4_1_MU_1A; |
| 175 | break; |
| 176 | default: |
| 177 | printf("Not support this core boot up, ID:%u\n", core_id); |
| 178 | return -EINVAL; |
| 179 | } |
| 180 | |
| 181 | addr = (sc_faddr_t)boot_private_data; |
| 182 | |
| 183 | if (addr >= tcml_addr && addr <= tcml_addr + tcml_size) { |
| 184 | printf("Wrong image address 0x%lx, should not in TCML\n", |
| 185 | addr); |
| 186 | return -EINVAL; |
| 187 | } |
| 188 | |
| 189 | printf("Power on M4 and MU\n"); |
| 190 | |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 191 | ret = sc_pm_set_resource_power_mode(-1, core_rsrc, SC_PM_PW_MODE_ON); |
| 192 | if (ret) |
| 193 | return ret; |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 194 | |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 195 | ret = sc_pm_set_resource_power_mode(-1, mu_rsrc, SC_PM_PW_MODE_ON); |
| 196 | if (ret) |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 197 | return -EIO; |
| 198 | |
| 199 | printf("Copy M4 image from 0x%lx to TCML 0x%lx\n", addr, (ulong)tcml_addr); |
| 200 | |
| 201 | if (addr != tcml_addr) |
| 202 | memcpy((void *)tcml_addr, (void *)addr, tcml_size); |
| 203 | |
| 204 | printf("Start M4 %u\n", core_id); |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 205 | ret = sc_pm_cpu_start(-1, core_rsrc, true, tcml_addr); |
| 206 | if (ret) |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 207 | return -EIO; |
| 208 | |
| 209 | printf("bootaux complete\n"); |
| 210 | return 0; |
| 211 | } |
| 212 | #endif |
| 213 | |
| 214 | #ifdef CONFIG_IMX8QXP |
| 215 | int arch_auxiliary_core_up(u32 core_id, ulong boot_private_data) |
| 216 | { |
| 217 | sc_rsrc_t core_rsrc, mu_rsrc = SC_R_NONE; |
| 218 | sc_faddr_t aux_core_ram; |
| 219 | u32 size; |
| 220 | ulong addr; |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 221 | int ret; |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 222 | |
| 223 | switch (core_id) { |
| 224 | case 0: |
| 225 | core_rsrc = SC_R_M4_0_PID0; |
| 226 | aux_core_ram = 0x34FE0000; |
| 227 | mu_rsrc = SC_R_M4_0_MU_1A; |
| 228 | size = SZ_128K; |
| 229 | break; |
| 230 | case 1: |
| 231 | core_rsrc = SC_R_DSP; |
| 232 | aux_core_ram = 0x596f8000; |
| 233 | size = SZ_2K; |
| 234 | break; |
| 235 | default: |
| 236 | printf("Not support this core boot up, ID:%u\n", core_id); |
| 237 | return -EINVAL; |
| 238 | } |
| 239 | |
| 240 | addr = (sc_faddr_t)boot_private_data; |
| 241 | |
| 242 | if (addr >= aux_core_ram && addr <= aux_core_ram + size) { |
| 243 | printf("Wrong image address 0x%lx, should not in aux core ram\n", |
| 244 | addr); |
| 245 | return -EINVAL; |
| 246 | } |
| 247 | |
| 248 | printf("Power on aux core %d\n", core_id); |
| 249 | |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 250 | ret = sc_pm_set_resource_power_mode(-1, core_rsrc, SC_PM_PW_MODE_ON); |
| 251 | if (ret) |
| 252 | return ret; |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 253 | |
| 254 | if (mu_rsrc != SC_R_NONE) { |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 255 | ret = sc_pm_set_resource_power_mode(-1, mu_rsrc, SC_PM_PW_MODE_ON); |
| 256 | if (ret) |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 257 | return -EIO; |
| 258 | } |
| 259 | |
| 260 | if (core_id == 1) { |
| 261 | struct power_domain pd; |
| 262 | |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 263 | ret = sc_pm_clock_enable(-1, core_rsrc, SC_PM_CLK_PER, true, false); |
| 264 | if (ret) { |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 265 | printf("Error enable clock\n"); |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 266 | return ret; |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 267 | } |
| 268 | |
Max Krummenacher | c209c8f | 2024-08-07 15:39:11 +0200 | [diff] [blame] | 269 | if (!imx8_power_domain_lookup_name("audio_sai0", &pd)) { |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 270 | if (power_domain_on(&pd)) { |
| 271 | printf("Error power on SAI0\n"); |
| 272 | return -EIO; |
| 273 | } |
| 274 | } |
| 275 | |
Max Krummenacher | c209c8f | 2024-08-07 15:39:11 +0200 | [diff] [blame] | 276 | if (!imx8_power_domain_lookup_name("audio_ocram", &pd)) { |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 277 | if (power_domain_on(&pd)) { |
| 278 | printf("Error power on HIFI RAM\n"); |
| 279 | return -EIO; |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | printf("Copy image from 0x%lx to 0x%lx\n", addr, (ulong)aux_core_ram); |
| 285 | if (core_id == 0) { |
| 286 | /* M4 use bin file */ |
| 287 | memcpy((void *)aux_core_ram, (void *)addr, size); |
| 288 | } else { |
| 289 | /* HIFI use elf file */ |
| 290 | if (!valid_elf_image(addr)) |
| 291 | return -1; |
| 292 | addr = load_elf_image_shdr(addr); |
| 293 | } |
| 294 | |
| 295 | printf("Start %s\n", core_id == 0 ? "M4" : "HIFI"); |
| 296 | |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 297 | ret = sc_pm_cpu_start(-1, core_rsrc, true, aux_core_ram); |
| 298 | if (ret) |
| 299 | return ret; |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 300 | |
| 301 | printf("bootaux complete\n"); |
| 302 | return 0; |
| 303 | } |
| 304 | #endif |
| 305 | |
| 306 | int arch_auxiliary_core_check_up(u32 core_id) |
| 307 | { |
| 308 | sc_rsrc_t core_rsrc; |
| 309 | sc_pm_power_mode_t power_mode; |
| 310 | |
| 311 | switch (core_id) { |
| 312 | case 0: |
| 313 | core_rsrc = SC_R_M4_0_PID0; |
| 314 | break; |
| 315 | #ifdef CONFIG_IMX8QM |
| 316 | case 1: |
| 317 | core_rsrc = SC_R_M4_1_PID0; |
| 318 | break; |
| 319 | #endif |
| 320 | default: |
| 321 | printf("Not support this core, ID:%u\n", core_id); |
| 322 | return 0; |
| 323 | } |
| 324 | |
Peng Fan | ddeb21a | 2024-10-09 16:29:36 +0800 | [diff] [blame] | 325 | if (sc_pm_get_resource_power_mode(-1, core_rsrc, &power_mode)) |
Ye Li | c07ac74 | 2023-06-15 18:09:20 +0800 | [diff] [blame] | 326 | return 0; |
| 327 | |
| 328 | if (power_mode != SC_PM_PW_MODE_OFF) |
| 329 | return 1; |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | #endif |
| 334 | |
Peng Fan | 29c9dd3 | 2018-10-18 14:28:19 +0200 | [diff] [blame] | 335 | int print_bootinfo(void) |
| 336 | { |
| 337 | enum boot_device bt_dev = get_boot_device(); |
| 338 | |
| 339 | puts("Boot: "); |
| 340 | switch (bt_dev) { |
| 341 | case SD1_BOOT: |
| 342 | puts("SD0\n"); |
| 343 | break; |
| 344 | case SD2_BOOT: |
| 345 | puts("SD1\n"); |
| 346 | break; |
| 347 | case SD3_BOOT: |
| 348 | puts("SD2\n"); |
| 349 | break; |
| 350 | case MMC1_BOOT: |
| 351 | puts("MMC0\n"); |
| 352 | break; |
| 353 | case MMC2_BOOT: |
| 354 | puts("MMC1\n"); |
| 355 | break; |
| 356 | case MMC3_BOOT: |
| 357 | puts("MMC2\n"); |
| 358 | break; |
| 359 | case FLEXSPI_BOOT: |
| 360 | puts("FLEXSPI\n"); |
| 361 | break; |
| 362 | case SATA_BOOT: |
| 363 | puts("SATA\n"); |
| 364 | break; |
| 365 | case NAND_BOOT: |
| 366 | puts("NAND\n"); |
| 367 | break; |
| 368 | case USB_BOOT: |
| 369 | puts("USB\n"); |
| 370 | break; |
| 371 | default: |
| 372 | printf("Unknown device %u\n", bt_dev); |
| 373 | break; |
| 374 | } |
| 375 | |
Igor Opaniuk | ab5ffef | 2024-01-31 13:49:26 +0100 | [diff] [blame] | 376 | printf("Reset cause: %s\n", get_reset_cause()); |
| 377 | |
Peng Fan | 29c9dd3 | 2018-10-18 14:28:19 +0200 | [diff] [blame] | 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | enum boot_device get_boot_device(void) |
| 382 | { |
| 383 | enum boot_device boot_dev = SD1_BOOT; |
| 384 | |
| 385 | sc_rsrc_t dev_rsrc; |
| 386 | |
| 387 | sc_misc_get_boot_dev(-1, &dev_rsrc); |
| 388 | |
| 389 | switch (dev_rsrc) { |
| 390 | case SC_R_SDHC_0: |
| 391 | boot_dev = MMC1_BOOT; |
| 392 | break; |
| 393 | case SC_R_SDHC_1: |
| 394 | boot_dev = SD2_BOOT; |
| 395 | break; |
| 396 | case SC_R_SDHC_2: |
| 397 | boot_dev = SD3_BOOT; |
| 398 | break; |
| 399 | case SC_R_NAND: |
| 400 | boot_dev = NAND_BOOT; |
| 401 | break; |
| 402 | case SC_R_FSPI_0: |
| 403 | boot_dev = FLEXSPI_BOOT; |
| 404 | break; |
| 405 | case SC_R_SATA_0: |
| 406 | boot_dev = SATA_BOOT; |
| 407 | break; |
| 408 | case SC_R_USB_0: |
| 409 | case SC_R_USB_1: |
| 410 | case SC_R_USB_2: |
| 411 | boot_dev = USB_BOOT; |
| 412 | break; |
| 413 | default: |
| 414 | break; |
| 415 | } |
| 416 | |
| 417 | return boot_dev; |
| 418 | } |
Peng Fan | 93b6cfd | 2018-10-18 14:28:20 +0200 | [diff] [blame] | 419 | |
Tom Rini | ae21e7f | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 420 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 421 | #define FUSE_UNIQUE_ID_WORD0 16 |
| 422 | #define FUSE_UNIQUE_ID_WORD1 17 |
| 423 | void get_board_serial(struct tag_serialnr *serialnr) |
| 424 | { |
Peng Fan | 25b7eb4 | 2023-06-15 18:08:58 +0800 | [diff] [blame] | 425 | int err; |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 426 | u32 val1 = 0, val2 = 0; |
| 427 | u32 word1, word2; |
| 428 | |
| 429 | if (!serialnr) |
| 430 | return; |
| 431 | |
| 432 | word1 = FUSE_UNIQUE_ID_WORD0; |
| 433 | word2 = FUSE_UNIQUE_ID_WORD1; |
| 434 | |
| 435 | err = sc_misc_otp_fuse_read(-1, word1, &val1); |
Peng Fan | 25b7eb4 | 2023-06-15 18:08:58 +0800 | [diff] [blame] | 436 | if (err) { |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 437 | printf("%s fuse %d read error: %d\n", __func__, word1, err); |
| 438 | return; |
| 439 | } |
| 440 | |
| 441 | err = sc_misc_otp_fuse_read(-1, word2, &val2); |
Peng Fan | 25b7eb4 | 2023-06-15 18:08:58 +0800 | [diff] [blame] | 442 | if (err) { |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 443 | printf("%s fuse %d read error: %d\n", __func__, word2, err); |
| 444 | return; |
| 445 | } |
| 446 | serialnr->low = val1; |
| 447 | serialnr->high = val2; |
| 448 | } |
Tom Rini | ae21e7f | 2021-08-30 09:16:29 -0400 | [diff] [blame] | 449 | #endif /*CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG*/ |
Peng Fan | d2aaf0c | 2020-05-05 20:28:39 +0800 | [diff] [blame] | 450 | |
Peng Fan | 93b6cfd | 2018-10-18 14:28:20 +0200 | [diff] [blame] | 451 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 452 | __weak int board_mmc_get_env_dev(int devno) |
| 453 | { |
| 454 | return CONFIG_SYS_MMC_ENV_DEV; |
| 455 | } |
| 456 | |
| 457 | int mmc_get_env_dev(void) |
| 458 | { |
| 459 | sc_rsrc_t dev_rsrc; |
| 460 | int devno; |
| 461 | |
| 462 | sc_misc_get_boot_dev(-1, &dev_rsrc); |
| 463 | |
| 464 | switch (dev_rsrc) { |
| 465 | case SC_R_SDHC_0: |
| 466 | devno = 0; |
| 467 | break; |
| 468 | case SC_R_SDHC_1: |
| 469 | devno = 1; |
| 470 | break; |
| 471 | case SC_R_SDHC_2: |
| 472 | devno = 2; |
| 473 | break; |
| 474 | default: |
| 475 | /* If not boot from sd/mmc, use default value */ |
| 476 | return CONFIG_SYS_MMC_ENV_DEV; |
| 477 | } |
| 478 | |
| 479 | return board_mmc_get_env_dev(devno); |
| 480 | } |
| 481 | #endif |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 482 | |
| 483 | #define MEMSTART_ALIGNMENT SZ_2M /* Align the memory start with 2MB */ |
| 484 | |
| 485 | static int get_owned_memreg(sc_rm_mr_t mr, sc_faddr_t *addr_start, |
| 486 | sc_faddr_t *addr_end) |
| 487 | { |
| 488 | sc_faddr_t start, end; |
| 489 | int ret; |
| 490 | bool owned; |
| 491 | |
| 492 | owned = sc_rm_is_memreg_owned(-1, mr); |
| 493 | if (owned) { |
| 494 | ret = sc_rm_get_memreg_info(-1, mr, &start, &end); |
| 495 | if (ret) { |
| 496 | printf("Memreg get info failed, %d\n", ret); |
| 497 | return -EINVAL; |
| 498 | } |
| 499 | debug("0x%llx -- 0x%llx\n", start, end); |
| 500 | *addr_start = start; |
| 501 | *addr_end = end; |
| 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | return -EINVAL; |
| 507 | } |
| 508 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 509 | __weak void board_mem_get_layout(u64 *phys_sdram_1_start, |
| 510 | u64 *phys_sdram_1_size, |
| 511 | u64 *phys_sdram_2_start, |
| 512 | u64 *phys_sdram_2_size) |
| 513 | { |
| 514 | *phys_sdram_1_start = PHYS_SDRAM_1; |
| 515 | *phys_sdram_1_size = PHYS_SDRAM_1_SIZE; |
| 516 | *phys_sdram_2_start = PHYS_SDRAM_2; |
| 517 | *phys_sdram_2_size = PHYS_SDRAM_2_SIZE; |
| 518 | } |
| 519 | |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 520 | phys_size_t get_effective_memsize(void) |
| 521 | { |
| 522 | sc_rm_mr_t mr; |
Ye Li | 7545bd1 | 2020-05-05 20:28:38 +0800 | [diff] [blame] | 523 | sc_faddr_t start, end, end1, start_aligned; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 524 | u64 phys_sdram_1_start, phys_sdram_1_size; |
| 525 | u64 phys_sdram_2_start, phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 526 | int err; |
| 527 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 528 | board_mem_get_layout(&phys_sdram_1_start, &phys_sdram_1_size, |
| 529 | &phys_sdram_2_start, &phys_sdram_2_size); |
| 530 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 531 | end1 = (sc_faddr_t)phys_sdram_1_start + phys_sdram_1_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 532 | for (mr = 0; mr < 64; mr++) { |
| 533 | err = get_owned_memreg(mr, &start, &end); |
| 534 | if (!err) { |
Ye Li | 7545bd1 | 2020-05-05 20:28:38 +0800 | [diff] [blame] | 535 | start_aligned = roundup(start, MEMSTART_ALIGNMENT); |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 536 | /* Too small memory region, not use it */ |
Ye Li | 7545bd1 | 2020-05-05 20:28:38 +0800 | [diff] [blame] | 537 | if (start_aligned > end) |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 538 | continue; |
| 539 | |
Peng Fan | 14b4cd2 | 2018-10-18 14:28:22 +0200 | [diff] [blame] | 540 | /* Find the memory region runs the U-Boot */ |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 541 | if (start >= phys_sdram_1_start && start <= end1 && |
Simon Glass | 72cc538 | 2022-10-20 18:22:39 -0600 | [diff] [blame] | 542 | (start <= CONFIG_TEXT_BASE && |
| 543 | end >= CONFIG_TEXT_BASE)) { |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 544 | if ((end + 1) <= |
| 545 | ((sc_faddr_t)phys_sdram_1_start + |
| 546 | phys_sdram_1_size)) |
| 547 | return (end - phys_sdram_1_start + 1); |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 548 | else |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 549 | return phys_sdram_1_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 554 | return phys_sdram_1_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | int dram_init(void) |
| 558 | { |
| 559 | sc_rm_mr_t mr; |
| 560 | sc_faddr_t start, end, end1, end2; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 561 | u64 phys_sdram_1_start, phys_sdram_1_size; |
| 562 | u64 phys_sdram_2_start, phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 563 | int err; |
| 564 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 565 | board_mem_get_layout(&phys_sdram_1_start, &phys_sdram_1_size, |
| 566 | &phys_sdram_2_start, &phys_sdram_2_size); |
| 567 | |
| 568 | end1 = (sc_faddr_t)phys_sdram_1_start + phys_sdram_1_size; |
| 569 | end2 = (sc_faddr_t)phys_sdram_2_start + phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 570 | for (mr = 0; mr < 64; mr++) { |
| 571 | err = get_owned_memreg(mr, &start, &end); |
| 572 | if (!err) { |
| 573 | start = roundup(start, MEMSTART_ALIGNMENT); |
| 574 | /* Too small memory region, not use it */ |
| 575 | if (start > end) |
| 576 | continue; |
| 577 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 578 | if (start >= phys_sdram_1_start && start <= end1) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 579 | if ((end + 1) <= end1) |
| 580 | gd->ram_size += end - start + 1; |
| 581 | else |
| 582 | gd->ram_size += end1 - start; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 583 | } else if (start >= phys_sdram_2_start && |
| 584 | start <= end2) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 585 | if ((end + 1) <= end2) |
| 586 | gd->ram_size += end - start + 1; |
| 587 | else |
| 588 | gd->ram_size += end2 - start; |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | /* If error, set to the default value */ |
| 594 | if (!gd->ram_size) { |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 595 | gd->ram_size = phys_sdram_1_size; |
| 596 | gd->ram_size += phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 597 | } |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | static void dram_bank_sort(int current_bank) |
| 602 | { |
| 603 | phys_addr_t start; |
| 604 | phys_size_t size; |
| 605 | |
| 606 | while (current_bank > 0) { |
| 607 | if (gd->bd->bi_dram[current_bank - 1].start > |
| 608 | gd->bd->bi_dram[current_bank].start) { |
| 609 | start = gd->bd->bi_dram[current_bank - 1].start; |
| 610 | size = gd->bd->bi_dram[current_bank - 1].size; |
| 611 | |
| 612 | gd->bd->bi_dram[current_bank - 1].start = |
| 613 | gd->bd->bi_dram[current_bank].start; |
| 614 | gd->bd->bi_dram[current_bank - 1].size = |
| 615 | gd->bd->bi_dram[current_bank].size; |
| 616 | |
| 617 | gd->bd->bi_dram[current_bank].start = start; |
| 618 | gd->bd->bi_dram[current_bank].size = size; |
| 619 | } |
| 620 | current_bank--; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | int dram_init_banksize(void) |
| 625 | { |
| 626 | sc_rm_mr_t mr; |
| 627 | sc_faddr_t start, end, end1, end2; |
| 628 | int i = 0; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 629 | u64 phys_sdram_1_start, phys_sdram_1_size; |
| 630 | u64 phys_sdram_2_start, phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 631 | int err; |
| 632 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 633 | board_mem_get_layout(&phys_sdram_1_start, &phys_sdram_1_size, |
| 634 | &phys_sdram_2_start, &phys_sdram_2_size); |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 635 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 636 | end1 = (sc_faddr_t)phys_sdram_1_start + phys_sdram_1_size; |
| 637 | end2 = (sc_faddr_t)phys_sdram_2_start + phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 638 | for (mr = 0; mr < 64 && i < CONFIG_NR_DRAM_BANKS; mr++) { |
| 639 | err = get_owned_memreg(mr, &start, &end); |
| 640 | if (!err) { |
| 641 | start = roundup(start, MEMSTART_ALIGNMENT); |
| 642 | if (start > end) /* Small memory region, no use it */ |
| 643 | continue; |
| 644 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 645 | if (start >= phys_sdram_1_start && start <= end1) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 646 | gd->bd->bi_dram[i].start = start; |
| 647 | |
| 648 | if ((end + 1) <= end1) |
| 649 | gd->bd->bi_dram[i].size = |
| 650 | end - start + 1; |
| 651 | else |
| 652 | gd->bd->bi_dram[i].size = end1 - start; |
| 653 | |
| 654 | dram_bank_sort(i); |
| 655 | i++; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 656 | } else if (start >= phys_sdram_2_start && start <= end2) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 657 | gd->bd->bi_dram[i].start = start; |
| 658 | |
| 659 | if ((end + 1) <= end2) |
| 660 | gd->bd->bi_dram[i].size = |
| 661 | end - start + 1; |
| 662 | else |
| 663 | gd->bd->bi_dram[i].size = end2 - start; |
| 664 | |
| 665 | dram_bank_sort(i); |
| 666 | i++; |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | /* If error, set to the default value */ |
| 672 | if (!i) { |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 673 | gd->bd->bi_dram[0].start = phys_sdram_1_start; |
| 674 | gd->bd->bi_dram[0].size = phys_sdram_1_size; |
| 675 | gd->bd->bi_dram[1].start = phys_sdram_2_start; |
| 676 | gd->bd->bi_dram[1].size = phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | static u64 get_block_attrs(sc_faddr_t addr_start) |
| 683 | { |
| 684 | u64 attr = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | PTE_BLOCK_NON_SHARE | |
| 685 | PTE_BLOCK_PXN | PTE_BLOCK_UXN; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 686 | u64 phys_sdram_1_start, phys_sdram_1_size; |
| 687 | u64 phys_sdram_2_start, phys_sdram_2_size; |
| 688 | |
| 689 | board_mem_get_layout(&phys_sdram_1_start, &phys_sdram_1_size, |
| 690 | &phys_sdram_2_start, &phys_sdram_2_size); |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 691 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 692 | if ((addr_start >= phys_sdram_1_start && |
| 693 | addr_start <= ((sc_faddr_t)phys_sdram_1_start + phys_sdram_1_size)) || |
| 694 | (addr_start >= phys_sdram_2_start && |
| 695 | addr_start <= ((sc_faddr_t)phys_sdram_2_start + phys_sdram_2_size))) |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 696 | return (PTE_BLOCK_MEMTYPE(MT_NORMAL) | PTE_BLOCK_OUTER_SHARE); |
| 697 | |
| 698 | return attr; |
| 699 | } |
| 700 | |
| 701 | static u64 get_block_size(sc_faddr_t addr_start, sc_faddr_t addr_end) |
| 702 | { |
| 703 | sc_faddr_t end1, end2; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 704 | u64 phys_sdram_1_start, phys_sdram_1_size; |
| 705 | u64 phys_sdram_2_start, phys_sdram_2_size; |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 706 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 707 | board_mem_get_layout(&phys_sdram_1_start, &phys_sdram_1_size, |
| 708 | &phys_sdram_2_start, &phys_sdram_2_size); |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 709 | |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 710 | end1 = (sc_faddr_t)phys_sdram_1_start + phys_sdram_1_size; |
| 711 | end2 = (sc_faddr_t)phys_sdram_2_start + phys_sdram_2_size; |
| 712 | |
| 713 | if (addr_start >= phys_sdram_1_start && addr_start <= end1) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 714 | if ((addr_end + 1) > end1) |
| 715 | return end1 - addr_start; |
Marcel Ziswiler | a45585b | 2020-10-22 11:21:40 +0300 | [diff] [blame] | 716 | } else if (addr_start >= phys_sdram_2_start && addr_start <= end2) { |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 717 | if ((addr_end + 1) > end2) |
| 718 | return end2 - addr_start; |
| 719 | } |
| 720 | |
| 721 | return (addr_end - addr_start + 1); |
| 722 | } |
| 723 | |
| 724 | #define MAX_PTE_ENTRIES 512 |
| 725 | #define MAX_MEM_MAP_REGIONS 16 |
| 726 | |
| 727 | static struct mm_region imx8_mem_map[MAX_MEM_MAP_REGIONS]; |
| 728 | struct mm_region *mem_map = imx8_mem_map; |
| 729 | |
| 730 | void enable_caches(void) |
| 731 | { |
| 732 | sc_rm_mr_t mr; |
| 733 | sc_faddr_t start, end; |
| 734 | int err, i; |
| 735 | |
| 736 | /* Create map for registers access from 0x1c000000 to 0x80000000*/ |
| 737 | imx8_mem_map[0].virt = 0x1c000000UL; |
| 738 | imx8_mem_map[0].phys = 0x1c000000UL; |
| 739 | imx8_mem_map[0].size = 0x64000000UL; |
| 740 | imx8_mem_map[0].attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 741 | PTE_BLOCK_NON_SHARE | PTE_BLOCK_PXN | PTE_BLOCK_UXN; |
| 742 | |
| 743 | i = 1; |
| 744 | for (mr = 0; mr < 64 && i < MAX_MEM_MAP_REGIONS; mr++) { |
| 745 | err = get_owned_memreg(mr, &start, &end); |
| 746 | if (!err) { |
| 747 | imx8_mem_map[i].virt = start; |
| 748 | imx8_mem_map[i].phys = start; |
| 749 | imx8_mem_map[i].size = get_block_size(start, end); |
| 750 | imx8_mem_map[i].attrs = get_block_attrs(start); |
| 751 | i++; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | if (i < MAX_MEM_MAP_REGIONS) { |
| 756 | imx8_mem_map[i].size = 0; |
| 757 | imx8_mem_map[i].attrs = 0; |
| 758 | } else { |
| 759 | puts("Error, need more MEM MAP REGIONS reserved\n"); |
| 760 | icache_enable(); |
| 761 | return; |
| 762 | } |
| 763 | |
| 764 | for (i = 0; i < MAX_MEM_MAP_REGIONS; i++) { |
| 765 | debug("[%d] vir = 0x%llx phys = 0x%llx size = 0x%llx attrs = 0x%llx\n", |
| 766 | i, imx8_mem_map[i].virt, imx8_mem_map[i].phys, |
| 767 | imx8_mem_map[i].size, imx8_mem_map[i].attrs); |
| 768 | } |
| 769 | |
| 770 | icache_enable(); |
| 771 | dcache_enable(); |
| 772 | } |
| 773 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 774 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Peng Fan | 4f211a5 | 2018-10-18 14:28:21 +0200 | [diff] [blame] | 775 | u64 get_page_table_size(void) |
| 776 | { |
| 777 | u64 one_pt = MAX_PTE_ENTRIES * sizeof(u64); |
| 778 | u64 size = 0; |
| 779 | |
| 780 | /* |
| 781 | * For each memory region, the max table size: |
| 782 | * 2 level 3 tables + 2 level 2 tables + 1 level 1 table |
| 783 | */ |
| 784 | size = (2 + 2 + 1) * one_pt * MAX_MEM_MAP_REGIONS + one_pt; |
| 785 | |
| 786 | /* |
| 787 | * We need to duplicate our page table once to have an emergency pt to |
| 788 | * resort to when splitting page tables later on |
| 789 | */ |
| 790 | size *= 2; |
| 791 | |
| 792 | /* |
| 793 | * We may need to split page tables later on if dcache settings change, |
| 794 | * so reserve up to 4 (random pick) page tables for that. |
| 795 | */ |
| 796 | size += one_pt * 4; |
| 797 | |
| 798 | return size; |
| 799 | } |
| 800 | #endif |
Anatolij Gustschin | 05b354b | 2018-10-18 14:28:23 +0200 | [diff] [blame] | 801 | |
Peng Fan | 303324d | 2019-08-26 08:12:23 +0000 | [diff] [blame] | 802 | #if defined(CONFIG_IMX8QM) |
| 803 | #define FUSE_MAC0_WORD0 452 |
| 804 | #define FUSE_MAC0_WORD1 453 |
| 805 | #define FUSE_MAC1_WORD0 454 |
| 806 | #define FUSE_MAC1_WORD1 455 |
| 807 | #elif defined(CONFIG_IMX8QXP) |
Anatolij Gustschin | 05b354b | 2018-10-18 14:28:23 +0200 | [diff] [blame] | 808 | #define FUSE_MAC0_WORD0 708 |
| 809 | #define FUSE_MAC0_WORD1 709 |
| 810 | #define FUSE_MAC1_WORD0 710 |
| 811 | #define FUSE_MAC1_WORD1 711 |
Peng Fan | 303324d | 2019-08-26 08:12:23 +0000 | [diff] [blame] | 812 | #endif |
Anatolij Gustschin | 05b354b | 2018-10-18 14:28:23 +0200 | [diff] [blame] | 813 | |
| 814 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
| 815 | { |
| 816 | u32 word[2], val[2] = {}; |
| 817 | int i, ret; |
| 818 | |
| 819 | if (dev_id == 0) { |
| 820 | word[0] = FUSE_MAC0_WORD0; |
| 821 | word[1] = FUSE_MAC0_WORD1; |
| 822 | } else { |
| 823 | word[0] = FUSE_MAC1_WORD0; |
| 824 | word[1] = FUSE_MAC1_WORD1; |
| 825 | } |
| 826 | |
| 827 | for (i = 0; i < 2; i++) { |
| 828 | ret = sc_misc_otp_fuse_read(-1, word[i], &val[i]); |
| 829 | if (ret < 0) |
| 830 | goto err; |
| 831 | } |
| 832 | |
| 833 | mac[0] = val[0]; |
| 834 | mac[1] = val[0] >> 8; |
| 835 | mac[2] = val[0] >> 16; |
| 836 | mac[3] = val[0] >> 24; |
| 837 | mac[4] = val[1]; |
| 838 | mac[5] = val[1] >> 8; |
| 839 | |
| 840 | debug("%s: MAC%d: %02x.%02x.%02x.%02x.%02x.%02x\n", |
| 841 | __func__, dev_id, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
| 842 | return; |
| 843 | err: |
| 844 | printf("%s: fuse %d, err: %d\n", __func__, word[i], ret); |
| 845 | } |
Anatolij Gustschin | 9b39be9 | 2018-10-18 14:28:24 +0200 | [diff] [blame] | 846 | |
Anatolij Gustschin | 9b39be9 | 2018-10-18 14:28:24 +0200 | [diff] [blame] | 847 | u32 get_cpu_rev(void) |
| 848 | { |
| 849 | u32 id = 0, rev = 0; |
| 850 | int ret; |
| 851 | |
| 852 | ret = sc_misc_get_control(-1, SC_R_SYSTEM, SC_C_ID, &id); |
| 853 | if (ret) |
| 854 | return 0; |
| 855 | |
| 856 | rev = (id >> 5) & 0xf; |
| 857 | id = (id & 0x1f) + MXC_SOC_IMX8; /* Dummy ID for chip */ |
| 858 | |
| 859 | return (id << 12) | rev; |
| 860 | } |
Ye Li | c3169bd | 2020-05-05 20:28:42 +0800 | [diff] [blame] | 861 | |
| 862 | void board_boot_order(u32 *spl_boot_list) |
| 863 | { |
| 864 | spl_boot_list[0] = spl_boot_device(); |
| 865 | |
| 866 | if (spl_boot_list[0] == BOOT_DEVICE_SPI) { |
| 867 | /* Check whether we own the flexspi0, if not, use NOR boot */ |
| 868 | if (!sc_rm_is_resource_owned(-1, SC_R_FSPI_0)) |
| 869 | spl_boot_list[0] = BOOT_DEVICE_NOR; |
| 870 | } |
| 871 | } |
Peng Fan | 2d65a16 | 2020-05-05 20:28:43 +0800 | [diff] [blame] | 872 | |
| 873 | bool m4_parts_booted(void) |
| 874 | { |
| 875 | sc_rm_pt_t m4_parts[2]; |
| 876 | int err; |
| 877 | |
| 878 | err = sc_rm_get_resource_owner(-1, SC_R_M4_0_PID0, &m4_parts[0]); |
| 879 | if (err) { |
| 880 | printf("%s get resource [%d] owner error: %d\n", __func__, |
| 881 | SC_R_M4_0_PID0, err); |
| 882 | return false; |
| 883 | } |
| 884 | |
| 885 | if (sc_pm_is_partition_started(-1, m4_parts[0])) |
| 886 | return true; |
| 887 | |
| 888 | if (is_imx8qm()) { |
| 889 | err = sc_rm_get_resource_owner(-1, SC_R_M4_1_PID0, &m4_parts[1]); |
| 890 | if (err) { |
| 891 | printf("%s get resource [%d] owner error: %d\n", |
| 892 | __func__, SC_R_M4_1_PID0, err); |
| 893 | return false; |
| 894 | } |
| 895 | |
| 896 | if (sc_pm_is_partition_started(-1, m4_parts[1])) |
| 897 | return true; |
| 898 | } |
| 899 | |
| 900 | return false; |
| 901 | } |