Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 2 | /* |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 3 | * Copyright 2014-2015 Freescale Semiconductor, Inc. |
Chaitanya Sakinam | 811cbcf | 2021-05-07 12:22:05 +0800 | [diff] [blame] | 4 | * Copyright 2020-2021 NXP |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 85d6531 | 2019-12-28 10:44:58 -0700 | [diff] [blame] | 8 | #include <clock_legacy.h> |
Alexander Graf | 17b6593 | 2016-11-17 01:03:00 +0100 | [diff] [blame] | 9 | #include <efi_loader.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <asm/cache.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 12 | #include <linux/libfdt.h> |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 13 | #include <fdt_support.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 14 | #include <phy.h> |
| 15 | #ifdef CONFIG_FSL_LSCH3 |
| 16 | #include <asm/arch/fdt.h> |
| 17 | #endif |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 18 | #ifdef CONFIG_FSL_ESDHC |
| 19 | #include <fsl_esdhc.h> |
| 20 | #endif |
Qianyu Gong | 4026f66 | 2016-02-18 13:02:02 +0800 | [diff] [blame] | 21 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 22 | #include <fsl_fman.h> |
| 23 | #endif |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 24 | #ifdef CONFIG_MP |
| 25 | #include <asm/arch/mp.h> |
| 26 | #endif |
Alex Porosanu | 16286bb | 2016-04-11 10:42:50 +0300 | [diff] [blame] | 27 | #include <fsl_sec.h> |
| 28 | #include <asm/arch-fsl-layerscape/soc.h> |
Michael Walle | 16fd24c | 2020-11-18 17:45:54 +0100 | [diff] [blame] | 29 | #if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT) |
Hou Zhiqiang | 21c4d55 | 2016-06-28 20:18:15 +0800 | [diff] [blame] | 30 | #include <asm/armv8/sec_firmware.h> |
| 31 | #endif |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 32 | #include <asm/arch/speed.h> |
| 33 | #include <fsl_qbman.h> |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 34 | |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 35 | int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc) |
| 36 | { |
Florinel Iordache | a618a5a | 2020-03-16 15:35:59 +0200 | [diff] [blame] | 37 | const char *conn; |
| 38 | |
| 39 | /* Do NOT apply fixup for backplane modes specified in DT */ |
| 40 | if (phyc == PHY_INTERFACE_MODE_XGMII) { |
| 41 | conn = fdt_getprop(blob, offset, "phy-connection-type", NULL); |
| 42 | if (is_backplane_mode(conn)) |
| 43 | return 0; |
| 44 | } |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 45 | return fdt_setprop_string(blob, offset, "phy-connection-type", |
| 46 | phy_string_for_interface(phyc)); |
| 47 | } |
| 48 | |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 49 | #ifdef CONFIG_MP |
| 50 | void ft_fixup_cpu(void *blob) |
| 51 | { |
| 52 | int off; |
| 53 | __maybe_unused u64 spin_tbl_addr = (u64)get_spin_tbl_addr(); |
| 54 | fdt32_t *reg; |
| 55 | int addr_cells; |
Arnab Basu | 0cb1942 | 2015-01-06 13:18:41 -0800 | [diff] [blame] | 56 | u64 val, core_id; |
Wenbin song | ea19677 | 2017-12-04 12:18:29 +0800 | [diff] [blame] | 57 | u32 mask = cpu_pos_mask(); |
| 58 | int off_prev = -1; |
| 59 | |
| 60 | off = fdt_path_offset(blob, "/cpus"); |
| 61 | if (off < 0) { |
| 62 | puts("couldn't find /cpus node\n"); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | fdt_support_default_count_cells(blob, off, &addr_cells, NULL); |
| 67 | |
| 68 | off = fdt_node_offset_by_prop_value(blob, off_prev, "device_type", |
| 69 | "cpu", 4); |
| 70 | while (off != -FDT_ERR_NOTFOUND) { |
| 71 | reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0); |
| 72 | if (reg) { |
| 73 | core_id = fdt_read_number(reg, addr_cells); |
| 74 | if (!test_bit(id_to_core(core_id), &mask)) { |
| 75 | fdt_del_node(blob, off); |
| 76 | off = off_prev; |
| 77 | } |
| 78 | } |
| 79 | off_prev = off; |
| 80 | off = fdt_node_offset_by_prop_value(blob, off_prev, |
| 81 | "device_type", "cpu", 4); |
| 82 | } |
| 83 | |
Michael Walle | 16fd24c | 2020-11-18 17:45:54 +0100 | [diff] [blame] | 84 | #if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT) && \ |
Hou Zhiqiang | 6be115d | 2017-01-16 17:31:48 +0800 | [diff] [blame] | 85 | defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI) |
Hou Zhiqiang | 21c4d55 | 2016-06-28 20:18:15 +0800 | [diff] [blame] | 86 | int node; |
| 87 | u32 psci_ver; |
| 88 | |
| 89 | /* Check the psci version to determine if the psci is supported */ |
| 90 | psci_ver = sec_firmware_support_psci_version(); |
| 91 | if (psci_ver == 0xffffffff) { |
| 92 | /* remove psci DT node */ |
| 93 | node = fdt_path_offset(blob, "/psci"); |
| 94 | if (node >= 0) |
| 95 | goto remove_psci_node; |
| 96 | |
| 97 | node = fdt_node_offset_by_compatible(blob, -1, "arm,psci"); |
| 98 | if (node >= 0) |
| 99 | goto remove_psci_node; |
| 100 | |
| 101 | node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-0.2"); |
| 102 | if (node >= 0) |
| 103 | goto remove_psci_node; |
| 104 | |
| 105 | node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-1.0"); |
| 106 | if (node >= 0) |
| 107 | goto remove_psci_node; |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 108 | |
Hou Zhiqiang | 21c4d55 | 2016-06-28 20:18:15 +0800 | [diff] [blame] | 109 | remove_psci_node: |
| 110 | if (node >= 0) |
| 111 | fdt_del_node(blob, node); |
| 112 | } else { |
| 113 | return; |
| 114 | } |
| 115 | #endif |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 116 | off = fdt_path_offset(blob, "/cpus"); |
| 117 | if (off < 0) { |
| 118 | puts("couldn't find /cpus node\n"); |
| 119 | return; |
| 120 | } |
Simon Glass | bb7c01e | 2017-05-18 20:09:26 -0600 | [diff] [blame] | 121 | fdt_support_default_count_cells(blob, off, &addr_cells, NULL); |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 122 | |
| 123 | off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4); |
| 124 | while (off != -FDT_ERR_NOTFOUND) { |
| 125 | reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0); |
| 126 | if (reg) { |
Simon Glass | bb7c01e | 2017-05-18 20:09:26 -0600 | [diff] [blame] | 127 | core_id = fdt_read_number(reg, addr_cells); |
Arnab Basu | 0cb1942 | 2015-01-06 13:18:41 -0800 | [diff] [blame] | 128 | if (core_id == 0 || (is_core_online(core_id))) { |
| 129 | val = spin_tbl_addr; |
| 130 | val += id_to_core(core_id) * |
| 131 | SPIN_TABLE_ELEM_SIZE; |
| 132 | val = cpu_to_fdt64(val); |
| 133 | fdt_setprop_string(blob, off, "enable-method", |
| 134 | "spin-table"); |
| 135 | fdt_setprop(blob, off, "cpu-release-addr", |
| 136 | &val, sizeof(val)); |
| 137 | } else { |
| 138 | debug("skipping offline core\n"); |
| 139 | } |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 140 | } else { |
| 141 | puts("Warning: found cpu node without reg property\n"); |
| 142 | } |
| 143 | off = fdt_node_offset_by_prop_value(blob, off, "device_type", |
| 144 | "cpu", 4); |
| 145 | } |
| 146 | |
Michael Walle | c251f5b | 2020-06-01 21:53:34 +0200 | [diff] [blame] | 147 | fdt_add_mem_rsv(blob, (uintptr_t)secondary_boot_code_start, |
| 148 | secondary_boot_code_size); |
Stephen Warren | d0de806 | 2018-08-30 15:43:43 -0600 | [diff] [blame] | 149 | #if CONFIG_IS_ENABLED(EFI_LOADER) |
Michael Walle | c251f5b | 2020-06-01 21:53:34 +0200 | [diff] [blame] | 150 | efi_add_memory_map((uintptr_t)secondary_boot_code_start, |
| 151 | secondary_boot_code_size, EFI_RESERVED_MEMORY_TYPE); |
Alexander Graf | 17b6593 | 2016-11-17 01:03:00 +0100 | [diff] [blame] | 152 | #endif |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 153 | } |
| 154 | #endif |
| 155 | |
Sriram Dash | f92c2cb | 2016-10-03 16:24:46 +0530 | [diff] [blame] | 156 | void fsl_fdt_disable_usb(void *blob) |
| 157 | { |
| 158 | int off; |
| 159 | /* |
| 160 | * SYSCLK is used as a reference clock for USB. When the USB |
| 161 | * controller is used, SYSCLK must meet the additional requirement |
| 162 | * of 100 MHz. |
| 163 | */ |
Marek Behún | 5d6b448 | 2022-01-20 01:04:42 +0100 | [diff] [blame] | 164 | if (get_board_sys_clk() != 100000000) |
| 165 | fdt_for_each_node_by_compatible(off, blob, -1, "snps,dwc3") |
Sriram Dash | f92c2cb | 2016-10-03 16:24:46 +0530 | [diff] [blame] | 166 | fdt_status_disabled(blob, off); |
Sriram Dash | f92c2cb | 2016-10-03 16:24:46 +0530 | [diff] [blame] | 167 | } |
| 168 | |
Wenbin Song | a8f57a9 | 2017-01-17 18:31:15 +0800 | [diff] [blame] | 169 | #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN |
| 170 | static void fdt_fixup_gic(void *blob) |
| 171 | { |
| 172 | int offset, err; |
| 173 | u64 reg[8]; |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 174 | struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
Wenbin Song | a8f57a9 | 2017-01-17 18:31:15 +0800 | [diff] [blame] | 175 | unsigned int val; |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 176 | struct ccsr_scfg __iomem *scfg = (void *)CFG_SYS_FSL_SCFG_ADDR; |
Wenbin Song | a8f57a9 | 2017-01-17 18:31:15 +0800 | [diff] [blame] | 177 | int align_64k = 0; |
| 178 | |
| 179 | val = gur_in32(&gur->svr); |
| 180 | |
Wenbin song | 5d8a61c | 2017-12-04 12:18:28 +0800 | [diff] [blame] | 181 | if (!IS_SVR_DEV(val, SVR_DEV(SVR_LS1043A))) { |
Wenbin Song | a8f57a9 | 2017-01-17 18:31:15 +0800 | [diff] [blame] | 182 | align_64k = 1; |
| 183 | } else if (SVR_REV(val) != REV1_0) { |
| 184 | val = scfg_in32(&scfg->gic_align) & (0x01 << GIC_ADDR_BIT); |
| 185 | if (!val) |
| 186 | align_64k = 1; |
| 187 | } |
| 188 | |
| 189 | offset = fdt_subnode_offset(blob, 0, "interrupt-controller@1400000"); |
| 190 | if (offset < 0) { |
| 191 | printf("WARNING: fdt_subnode_offset can't find node %s: %s\n", |
| 192 | "interrupt-controller@1400000", fdt_strerror(offset)); |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | /* Fixup gic node align with 64K */ |
| 197 | if (align_64k) { |
| 198 | reg[0] = cpu_to_fdt64(GICD_BASE_64K); |
| 199 | reg[1] = cpu_to_fdt64(GICD_SIZE_64K); |
| 200 | reg[2] = cpu_to_fdt64(GICC_BASE_64K); |
| 201 | reg[3] = cpu_to_fdt64(GICC_SIZE_64K); |
| 202 | reg[4] = cpu_to_fdt64(GICH_BASE_64K); |
| 203 | reg[5] = cpu_to_fdt64(GICH_SIZE_64K); |
| 204 | reg[6] = cpu_to_fdt64(GICV_BASE_64K); |
| 205 | reg[7] = cpu_to_fdt64(GICV_SIZE_64K); |
| 206 | } else { |
| 207 | /* Fixup gic node align with default */ |
| 208 | reg[0] = cpu_to_fdt64(GICD_BASE); |
| 209 | reg[1] = cpu_to_fdt64(GICD_SIZE); |
| 210 | reg[2] = cpu_to_fdt64(GICC_BASE); |
| 211 | reg[3] = cpu_to_fdt64(GICC_SIZE); |
| 212 | reg[4] = cpu_to_fdt64(GICH_BASE); |
| 213 | reg[5] = cpu_to_fdt64(GICH_SIZE); |
| 214 | reg[6] = cpu_to_fdt64(GICV_BASE); |
| 215 | reg[7] = cpu_to_fdt64(GICV_SIZE); |
| 216 | } |
| 217 | |
| 218 | err = fdt_setprop(blob, offset, "reg", reg, sizeof(reg)); |
| 219 | if (err < 0) { |
| 220 | printf("WARNING: fdt_setprop can't set %s from node %s: %s\n", |
| 221 | "reg", "interrupt-controller@1400000", |
| 222 | fdt_strerror(err)); |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | return; |
| 227 | } |
| 228 | #endif |
| 229 | |
Wenbin Song | c6bc7c0 | 2017-01-17 18:31:16 +0800 | [diff] [blame] | 230 | #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI |
| 231 | static int _fdt_fixup_msi_node(void *blob, const char *name, |
| 232 | int irq_0, int irq_1, int rev) |
| 233 | { |
| 234 | int err, offset, len; |
| 235 | u32 tmp[4][3]; |
| 236 | void *p; |
| 237 | |
| 238 | offset = fdt_path_offset(blob, name); |
| 239 | if (offset < 0) { |
| 240 | printf("WARNING: fdt_path_offset can't find path %s: %s\n", |
| 241 | name, fdt_strerror(offset)); |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | /*fixup the property of interrupts*/ |
| 246 | |
| 247 | tmp[0][0] = cpu_to_fdt32(0x0); |
| 248 | tmp[0][1] = cpu_to_fdt32(irq_0); |
| 249 | tmp[0][2] = cpu_to_fdt32(0x4); |
| 250 | |
| 251 | if (rev > REV1_0) { |
| 252 | tmp[1][0] = cpu_to_fdt32(0x0); |
| 253 | tmp[1][1] = cpu_to_fdt32(irq_1); |
| 254 | tmp[1][2] = cpu_to_fdt32(0x4); |
| 255 | tmp[2][0] = cpu_to_fdt32(0x0); |
| 256 | tmp[2][1] = cpu_to_fdt32(irq_1 + 1); |
| 257 | tmp[2][2] = cpu_to_fdt32(0x4); |
| 258 | tmp[3][0] = cpu_to_fdt32(0x0); |
| 259 | tmp[3][1] = cpu_to_fdt32(irq_1 + 2); |
| 260 | tmp[3][2] = cpu_to_fdt32(0x4); |
| 261 | len = sizeof(tmp); |
| 262 | } else { |
| 263 | len = sizeof(tmp[0]); |
| 264 | } |
| 265 | |
| 266 | err = fdt_setprop(blob, offset, "interrupts", tmp, len); |
| 267 | if (err < 0) { |
| 268 | printf("WARNING: fdt_setprop can't set %s from node %s: %s\n", |
| 269 | "interrupts", name, fdt_strerror(err)); |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | /*fixup the property of reg*/ |
| 274 | p = (char *)fdt_getprop(blob, offset, "reg", &len); |
| 275 | if (!p) { |
| 276 | printf("WARNING: fdt_getprop can't get %s from node %s\n", |
| 277 | "reg", name); |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | memcpy((char *)tmp, p, len); |
| 282 | |
| 283 | if (rev > REV1_0) |
| 284 | *((u32 *)tmp + 3) = cpu_to_fdt32(0x1000); |
| 285 | else |
| 286 | *((u32 *)tmp + 3) = cpu_to_fdt32(0x8); |
| 287 | |
| 288 | err = fdt_setprop(blob, offset, "reg", tmp, len); |
| 289 | if (err < 0) { |
| 290 | printf("WARNING: fdt_setprop can't set %s from node %s: %s\n", |
| 291 | "reg", name, fdt_strerror(err)); |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | /*fixup the property of compatible*/ |
| 296 | if (rev > REV1_0) |
| 297 | err = fdt_setprop_string(blob, offset, "compatible", |
| 298 | "fsl,ls1043a-v1.1-msi"); |
| 299 | else |
| 300 | err = fdt_setprop_string(blob, offset, "compatible", |
| 301 | "fsl,ls1043a-msi"); |
| 302 | if (err < 0) { |
| 303 | printf("WARNING: fdt_setprop can't set %s from node %s: %s\n", |
| 304 | "compatible", name, fdt_strerror(err)); |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | return 1; |
| 309 | } |
| 310 | |
| 311 | static int _fdt_fixup_pci_msi(void *blob, const char *name, int rev) |
| 312 | { |
| 313 | int offset, len, err; |
| 314 | void *p; |
| 315 | int val; |
| 316 | u32 tmp[4][8]; |
| 317 | |
| 318 | offset = fdt_path_offset(blob, name); |
| 319 | if (offset < 0) { |
| 320 | printf("WARNING: fdt_path_offset can't find path %s: %s\n", |
| 321 | name, fdt_strerror(offset)); |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | p = (char *)fdt_getprop(blob, offset, "interrupt-map", &len); |
| 326 | if (!p || len != sizeof(tmp)) { |
| 327 | printf("WARNING: fdt_getprop can't get %s from node %s\n", |
| 328 | "interrupt-map", name); |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | memcpy((char *)tmp, p, len); |
| 333 | |
| 334 | val = fdt32_to_cpu(tmp[0][6]); |
Hou Zhiqiang | 35e0e74 | 2018-12-20 06:31:21 +0000 | [diff] [blame] | 335 | if (rev == REV1_0) { |
Wenbin Song | c6bc7c0 | 2017-01-17 18:31:16 +0800 | [diff] [blame] | 336 | tmp[1][6] = cpu_to_fdt32(val + 1); |
| 337 | tmp[2][6] = cpu_to_fdt32(val + 2); |
| 338 | tmp[3][6] = cpu_to_fdt32(val + 3); |
| 339 | } else { |
| 340 | tmp[1][6] = cpu_to_fdt32(val); |
| 341 | tmp[2][6] = cpu_to_fdt32(val); |
| 342 | tmp[3][6] = cpu_to_fdt32(val); |
| 343 | } |
| 344 | |
| 345 | err = fdt_setprop(blob, offset, "interrupt-map", tmp, sizeof(tmp)); |
| 346 | if (err < 0) { |
| 347 | printf("WARNING: fdt_setprop can't set %s from node %s: %s.\n", |
| 348 | "interrupt-map", name, fdt_strerror(err)); |
| 349 | return 0; |
| 350 | } |
| 351 | return 1; |
| 352 | } |
| 353 | |
| 354 | /* Fixup msi node for ls1043a rev1.1*/ |
| 355 | |
| 356 | static void fdt_fixup_msi(void *blob) |
| 357 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 358 | struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
Wenbin Song | c6bc7c0 | 2017-01-17 18:31:16 +0800 | [diff] [blame] | 359 | unsigned int rev; |
| 360 | |
| 361 | rev = gur_in32(&gur->svr); |
| 362 | |
Wenbin song | 5d8a61c | 2017-12-04 12:18:28 +0800 | [diff] [blame] | 363 | if (!IS_SVR_DEV(rev, SVR_DEV(SVR_LS1043A))) |
Wenbin Song | c6bc7c0 | 2017-01-17 18:31:16 +0800 | [diff] [blame] | 364 | return; |
| 365 | |
| 366 | rev = SVR_REV(rev); |
| 367 | |
| 368 | _fdt_fixup_msi_node(blob, "/soc/msi-controller1@1571000", |
| 369 | 116, 111, rev); |
| 370 | _fdt_fixup_msi_node(blob, "/soc/msi-controller2@1572000", |
| 371 | 126, 121, rev); |
| 372 | _fdt_fixup_msi_node(blob, "/soc/msi-controller3@1573000", |
| 373 | 160, 155, rev); |
| 374 | |
| 375 | _fdt_fixup_pci_msi(blob, "/soc/pcie@3400000", rev); |
| 376 | _fdt_fixup_pci_msi(blob, "/soc/pcie@3500000", rev); |
| 377 | _fdt_fixup_pci_msi(blob, "/soc/pcie@3600000", rev); |
| 378 | } |
| 379 | #endif |
| 380 | |
Michael Walle | 16fd24c | 2020-11-18 17:45:54 +0100 | [diff] [blame] | 381 | #if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT) |
Ruchika Gupta | db204d7 | 2017-08-16 15:58:10 +0530 | [diff] [blame] | 382 | /* Remove JR node used by SEC firmware */ |
| 383 | void fdt_fixup_remove_jr(void *blob) |
| 384 | { |
| 385 | int jr_node, addr_cells, len; |
| 386 | int crypto_node = fdt_path_offset(blob, "crypto"); |
| 387 | u64 jr_offset, used_jr; |
| 388 | fdt32_t *reg; |
| 389 | |
Mathew McBride | e909b82 | 2023-04-12 07:38:13 +0000 | [diff] [blame] | 390 | /* Return if crypto node not found */ |
| 391 | if (crypto_node < 0) |
| 392 | return; |
| 393 | |
Ruchika Gupta | db204d7 | 2017-08-16 15:58:10 +0530 | [diff] [blame] | 394 | used_jr = sec_firmware_used_jobring_offset(); |
| 395 | fdt_support_default_count_cells(blob, crypto_node, &addr_cells, NULL); |
| 396 | |
| 397 | jr_node = fdt_node_offset_by_compatible(blob, crypto_node, |
| 398 | "fsl,sec-v4.0-job-ring"); |
| 399 | |
| 400 | while (jr_node != -FDT_ERR_NOTFOUND) { |
| 401 | reg = (fdt32_t *)fdt_getprop(blob, jr_node, "reg", &len); |
Priyanka Singh | 15e25a4 | 2020-11-02 11:38:41 +0530 | [diff] [blame] | 402 | if (reg) { |
| 403 | jr_offset = fdt_read_number(reg, addr_cells); |
| 404 | if (jr_offset == used_jr) { |
| 405 | fdt_del_node(blob, jr_node); |
| 406 | break; |
| 407 | } |
Ruchika Gupta | db204d7 | 2017-08-16 15:58:10 +0530 | [diff] [blame] | 408 | } |
| 409 | jr_node = fdt_node_offset_by_compatible(blob, jr_node, |
| 410 | "fsl,sec-v4.0-job-ring"); |
| 411 | } |
| 412 | } |
| 413 | #endif |
| 414 | |
Yuantian Tang | 044719b | 2019-10-10 17:19:37 +0800 | [diff] [blame] | 415 | #ifdef CONFIG_ARCH_LS1028A |
| 416 | static void fdt_disable_multimedia(void *blob, unsigned int svr) |
| 417 | { |
| 418 | int off; |
| 419 | |
| 420 | if (IS_MULTIMEDIA_EN(svr)) |
| 421 | return; |
| 422 | |
| 423 | /* Disable eDP/LCD node */ |
| 424 | off = fdt_node_offset_by_compatible(blob, -1, "arm,mali-dp500"); |
| 425 | if (off != -FDT_ERR_NOTFOUND) |
| 426 | fdt_status_disabled(blob, off); |
| 427 | |
| 428 | /* Disable GPU node */ |
Michael Walle | 18522d8 | 2021-10-13 18:14:00 +0200 | [diff] [blame] | 429 | off = fdt_node_offset_by_compatible(blob, -1, "vivante,gc"); |
Yuantian Tang | 044719b | 2019-10-10 17:19:37 +0800 | [diff] [blame] | 430 | if (off != -FDT_ERR_NOTFOUND) |
| 431 | fdt_status_disabled(blob, off); |
| 432 | } |
| 433 | #endif |
| 434 | |
Alex Marginean | 762a268 | 2019-11-27 17:19:32 +0200 | [diff] [blame] | 435 | #ifdef CONFIG_PCIE_ECAM_GENERIC |
| 436 | __weak void fdt_fixup_ecam(void *blob) |
| 437 | { |
| 438 | } |
| 439 | #endif |
| 440 | |
Michael Walle | 8a1bf73 | 2020-10-16 19:38:18 +0200 | [diff] [blame] | 441 | /* |
| 442 | * If it is a non-E part the crypto is disabled on the following SoCs: |
| 443 | * - LS1043A |
| 444 | * - LS1088A |
| 445 | * - LS2080A |
| 446 | * - LS2088A |
| 447 | * and their personalities. |
| 448 | * |
| 449 | * On all other SoCs just the export-controlled ciphers are disabled, that |
| 450 | * means that the following is still working: |
| 451 | * - hashing (using MDHA - message digest hash accelerator) |
| 452 | * - random number generation (using RNG4) |
| 453 | * - cyclic redundancy checking (using CRCA) |
| 454 | * - runtime integrity checker (RTIC) |
| 455 | * |
| 456 | * The linux driver will figure out what is available and what is not. |
| 457 | * Therefore, we just remove the crypto node on the SoCs which have no crypto |
| 458 | * support at all. |
| 459 | */ |
| 460 | static bool crypto_is_disabled(unsigned int svr) |
| 461 | { |
| 462 | if (IS_E_PROCESSOR(svr)) |
| 463 | return false; |
| 464 | |
| 465 | if (IS_SVR_DEV(svr, SVR_DEV(SVR_LS1043A))) |
| 466 | return true; |
| 467 | |
| 468 | if (IS_SVR_DEV(svr, SVR_DEV(SVR_LS1088A))) |
| 469 | return true; |
| 470 | |
| 471 | if (IS_SVR_DEV(svr, SVR_DEV(SVR_LS2080A))) |
| 472 | return true; |
| 473 | |
| 474 | if (IS_SVR_DEV(svr, SVR_DEV(SVR_LS2088A))) |
| 475 | return true; |
| 476 | |
| 477 | return false; |
| 478 | } |
| 479 | |
Chaitanya Sakinam | 811cbcf | 2021-05-07 12:22:05 +0800 | [diff] [blame] | 480 | #ifdef CONFIG_FSL_PFE |
| 481 | void pfe_set_firmware_in_fdt(void *blob, int pfenode, void *pfw, char *pename, |
| 482 | unsigned int len) |
| 483 | { |
| 484 | int rc, fwnode; |
| 485 | unsigned int phandle; |
| 486 | char subnode_str[32], prop_str[32], phandle_str[32], s[64]; |
| 487 | |
| 488 | sprintf(subnode_str, "pfe-%s-firmware", pename); |
| 489 | sprintf(prop_str, "fsl,pfe-%s-firmware", pename); |
| 490 | sprintf(phandle_str, "fsl,%s-firmware", pename); |
| 491 | |
| 492 | /*Add PE FW to fdt.*/ |
| 493 | /* Increase the size of the fdt to make room for the node. */ |
| 494 | rc = fdt_increase_size(blob, len); |
| 495 | if (rc < 0) { |
| 496 | printf("Unable to make room for %s firmware: %s\n", pename, |
| 497 | fdt_strerror(rc)); |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | /* Create the firmware node. */ |
| 502 | fwnode = fdt_add_subnode(blob, pfenode, subnode_str); |
| 503 | if (fwnode < 0) { |
| 504 | fdt_get_path(blob, pfenode, s, sizeof(s)); |
| 505 | printf("Could not add firmware node to %s: %s\n", s, |
| 506 | fdt_strerror(fwnode)); |
| 507 | return; |
| 508 | } |
| 509 | |
| 510 | rc = fdt_setprop_string(blob, fwnode, "compatible", prop_str); |
| 511 | if (rc < 0) { |
| 512 | fdt_get_path(blob, fwnode, s, sizeof(s)); |
| 513 | printf("Could not add compatible property to node %s: %s\n", s, |
| 514 | fdt_strerror(rc)); |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | rc = fdt_setprop_u32(blob, fwnode, "length", len); |
| 519 | if (rc < 0) { |
| 520 | fdt_get_path(blob, fwnode, s, sizeof(s)); |
| 521 | printf("Could not add compatible property to node %s: %s\n", s, |
| 522 | fdt_strerror(rc)); |
| 523 | return; |
| 524 | } |
| 525 | |
| 526 | /*create phandle and set the property*/ |
| 527 | phandle = fdt_create_phandle(blob, fwnode); |
| 528 | if (!phandle) { |
| 529 | fdt_get_path(blob, fwnode, s, sizeof(s)); |
| 530 | printf("Could not add phandle property to node %s: %s\n", s, |
| 531 | fdt_strerror(rc)); |
| 532 | return; |
| 533 | } |
| 534 | |
| 535 | rc = fdt_setprop(blob, fwnode, phandle_str, pfw, len); |
| 536 | if (rc < 0) { |
| 537 | fdt_get_path(blob, fwnode, s, sizeof(s)); |
| 538 | printf("Could not add firmware property to node %s: %s\n", s, |
| 539 | fdt_strerror(rc)); |
| 540 | return; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | void fdt_fixup_pfe_firmware(void *blob) |
| 545 | { |
| 546 | int pfenode; |
| 547 | unsigned int len_class = 0, len_tmu = 0, len_util = 0; |
| 548 | const char *p; |
| 549 | void *pclassfw, *ptmufw, *putilfw; |
| 550 | |
| 551 | /* The first PFE we find, will contain the actual firmware. */ |
| 552 | pfenode = fdt_node_offset_by_compatible(blob, -1, "fsl,pfe"); |
| 553 | if (pfenode < 0) |
| 554 | /* Exit silently if there are no PFE devices */ |
| 555 | return; |
| 556 | |
| 557 | /* If we already have a firmware node, then also exit silently. */ |
| 558 | if (fdt_node_offset_by_compatible(blob, -1, |
| 559 | "fsl,pfe-class-firmware") > 0) |
| 560 | return; |
| 561 | |
| 562 | /* If the environment variable is not set, then exit silently */ |
| 563 | p = env_get("class_elf_firmware"); |
| 564 | if (!p) |
| 565 | return; |
| 566 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 567 | pclassfw = (void *)hextoul(p, NULL); |
Chaitanya Sakinam | 811cbcf | 2021-05-07 12:22:05 +0800 | [diff] [blame] | 568 | if (!pclassfw) |
| 569 | return; |
| 570 | |
| 571 | p = env_get("class_elf_size"); |
| 572 | if (!p) |
| 573 | return; |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 574 | len_class = hextoul(p, NULL); |
Chaitanya Sakinam | 811cbcf | 2021-05-07 12:22:05 +0800 | [diff] [blame] | 575 | |
| 576 | /* If the environment variable is not set, then exit silently */ |
| 577 | p = env_get("tmu_elf_firmware"); |
| 578 | if (!p) |
| 579 | return; |
| 580 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 581 | ptmufw = (void *)hextoul(p, NULL); |
Chaitanya Sakinam | 811cbcf | 2021-05-07 12:22:05 +0800 | [diff] [blame] | 582 | if (!ptmufw) |
| 583 | return; |
| 584 | |
| 585 | p = env_get("tmu_elf_size"); |
| 586 | if (!p) |
| 587 | return; |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 588 | len_tmu = hextoul(p, NULL); |
Chaitanya Sakinam | 811cbcf | 2021-05-07 12:22:05 +0800 | [diff] [blame] | 589 | |
| 590 | if (len_class == 0 || len_tmu == 0) { |
| 591 | printf("PFE FW corrupted. CLASS FW size %d, TMU FW size %d\n", |
| 592 | len_class, len_tmu); |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | /*Add CLASS FW to fdt.*/ |
| 597 | pfe_set_firmware_in_fdt(blob, pfenode, pclassfw, "class", len_class); |
| 598 | |
| 599 | /*Add TMU FW to fdt.*/ |
| 600 | pfe_set_firmware_in_fdt(blob, pfenode, ptmufw, "tmu", len_tmu); |
| 601 | |
| 602 | /* Util PE firmware is handled separately as it is not a usual case*/ |
| 603 | p = env_get("util_elf_firmware"); |
| 604 | if (!p) |
| 605 | return; |
| 606 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 607 | putilfw = (void *)hextoul(p, NULL); |
Chaitanya Sakinam | 811cbcf | 2021-05-07 12:22:05 +0800 | [diff] [blame] | 608 | if (!putilfw) |
| 609 | return; |
| 610 | |
| 611 | p = env_get("util_elf_size"); |
| 612 | if (!p) |
| 613 | return; |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 614 | len_util = hextoul(p, NULL); |
Chaitanya Sakinam | 811cbcf | 2021-05-07 12:22:05 +0800 | [diff] [blame] | 615 | |
| 616 | if (len_util) { |
| 617 | printf("PFE Util PE firmware is not added to FDT.\n"); |
| 618 | return; |
| 619 | } |
| 620 | |
| 621 | pfe_set_firmware_in_fdt(blob, pfenode, putilfw, "util", len_util); |
| 622 | } |
| 623 | #endif |
| 624 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 625 | void ft_cpu_setup(void *blob, struct bd_info *bd) |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 626 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 627 | struct ccsr_gur __iomem *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR); |
Ruchika Gupta | db204d7 | 2017-08-16 15:58:10 +0530 | [diff] [blame] | 628 | unsigned int svr = gur_in32(&gur->svr); |
Alex Porosanu | 16286bb | 2016-04-11 10:42:50 +0300 | [diff] [blame] | 629 | |
| 630 | /* delete crypto node if not on an E-processor */ |
Michael Walle | 8a1bf73 | 2020-10-16 19:38:18 +0200 | [diff] [blame] | 631 | if (crypto_is_disabled(svr)) |
Alex Porosanu | 16286bb | 2016-04-11 10:42:50 +0300 | [diff] [blame] | 632 | fdt_fixup_crypto_node(blob, 0); |
| 633 | #if CONFIG_SYS_FSL_SEC_COMPAT >= 4 |
| 634 | else { |
| 635 | ccsr_sec_t __iomem *sec; |
| 636 | |
Michael Walle | 16fd24c | 2020-11-18 17:45:54 +0100 | [diff] [blame] | 637 | #if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT) |
Ruchika Gupta | fc8e340 | 2018-04-12 16:24:35 +0530 | [diff] [blame] | 638 | fdt_fixup_remove_jr(blob); |
| 639 | fdt_fixup_kaslr(blob); |
Ruchika Gupta | db204d7 | 2017-08-16 15:58:10 +0530 | [diff] [blame] | 640 | #endif |
| 641 | |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 642 | sec = (void __iomem *)CFG_SYS_FSL_SEC_ADDR; |
Alex Porosanu | 16286bb | 2016-04-11 10:42:50 +0300 | [diff] [blame] | 643 | fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms)); |
| 644 | } |
| 645 | #endif |
Alex Porosanu | 16286bb | 2016-04-11 10:42:50 +0300 | [diff] [blame] | 646 | |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 647 | #ifdef CONFIG_MP |
| 648 | ft_fixup_cpu(blob); |
| 649 | #endif |
Bhupesh Sharma | c771040 | 2015-01-06 13:18:44 -0800 | [diff] [blame] | 650 | |
| 651 | #ifdef CONFIG_SYS_NS16550 |
Scott Wood | 3e7fd6f | 2015-03-20 19:28:14 -0700 | [diff] [blame] | 652 | do_fixup_by_compat_u32(blob, "fsl,ns16550", |
Tom Rini | df6a215 | 2022-11-16 13:10:28 -0500 | [diff] [blame] | 653 | "clock-frequency", CFG_SYS_NS16550_CLK, 1); |
Bhupesh Sharma | c771040 | 2015-01-06 13:18:44 -0800 | [diff] [blame] | 654 | #endif |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 655 | |
Yangbo Lu | 07d1a91 | 2017-04-10 15:04:11 +0800 | [diff] [blame] | 656 | do_fixup_by_path_u32(blob, "/sysclk", "clock-frequency", |
Tom Rini | 8c70baa | 2021-12-14 13:36:40 -0500 | [diff] [blame] | 657 | get_board_sys_clk(), 1); |
Prabhakar Kushwaha | 53d1cdc | 2015-12-24 17:25:06 +0530 | [diff] [blame] | 658 | |
Hou Zhiqiang | 031bb87 | 2020-04-28 10:19:32 +0800 | [diff] [blame] | 659 | #ifdef CONFIG_GIC_V3_ITS |
| 660 | ls_gic_rd_tables_init(blob); |
| 661 | #endif |
| 662 | |
Hou Zhiqiang | 79d34ca | 2019-08-27 03:30:03 +0000 | [diff] [blame] | 663 | #if defined(CONFIG_PCIE_LAYERSCAPE) || defined(CONFIG_PCIE_LAYERSCAPE_GEN4) |
Prabhakar Kushwaha | 940a316 | 2015-05-28 14:53:59 +0530 | [diff] [blame] | 664 | ft_pci_setup(blob, bd); |
| 665 | #endif |
| 666 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 667 | #ifdef CONFIG_FSL_ESDHC |
Yangbo Lu | d0e295d | 2015-03-20 19:28:31 -0700 | [diff] [blame] | 668 | fdt_fixup_esdhc(blob, bd); |
| 669 | #endif |
Stuart Yoder | eaea504 | 2015-07-02 11:29:04 +0530 | [diff] [blame] | 670 | |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 671 | #ifdef CONFIG_SYS_DPAA_QBMAN |
| 672 | fdt_fixup_bportals(blob); |
| 673 | fdt_fixup_qportals(blob); |
| 674 | do_fixup_by_compat_u32(blob, "fsl,qman", |
| 675 | "clock-frequency", get_qman_freq(), 1); |
| 676 | #endif |
| 677 | |
Tom Rini | 7806407 | 2022-08-09 10:16:22 -0400 | [diff] [blame] | 678 | #ifdef CONFIG_FMAN_ENET |
Qianyu Gong | 4026f66 | 2016-02-18 13:02:02 +0800 | [diff] [blame] | 679 | fdt_fixup_fman_firmware(blob); |
| 680 | #endif |
Chaitanya Sakinam | 811cbcf | 2021-05-07 12:22:05 +0800 | [diff] [blame] | 681 | #ifdef CONFIG_FSL_PFE |
| 682 | fdt_fixup_pfe_firmware(blob); |
| 683 | #endif |
Ran Wang | 9b1d15e | 2017-08-28 10:40:33 +0800 | [diff] [blame] | 684 | #ifndef CONFIG_ARCH_LS1012A |
Sriram Dash | f92c2cb | 2016-10-03 16:24:46 +0530 | [diff] [blame] | 685 | fsl_fdt_disable_usb(blob); |
Yingxi Yu | 8a507da | 2017-03-16 15:18:32 +0800 | [diff] [blame] | 686 | #endif |
Wenbin Song | a8f57a9 | 2017-01-17 18:31:15 +0800 | [diff] [blame] | 687 | #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN |
| 688 | fdt_fixup_gic(blob); |
| 689 | #endif |
Wenbin Song | c6bc7c0 | 2017-01-17 18:31:16 +0800 | [diff] [blame] | 690 | #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI |
| 691 | fdt_fixup_msi(blob); |
| 692 | #endif |
Yuantian Tang | 044719b | 2019-10-10 17:19:37 +0800 | [diff] [blame] | 693 | #ifdef CONFIG_ARCH_LS1028A |
| 694 | fdt_disable_multimedia(blob, svr); |
| 695 | #endif |
Alex Marginean | 762a268 | 2019-11-27 17:19:32 +0200 | [diff] [blame] | 696 | #ifdef CONFIG_PCIE_ECAM_GENERIC |
| 697 | fdt_fixup_ecam(blob); |
| 698 | #endif |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 699 | } |