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. |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Tom Rini | 8c70baa | 2021-12-14 13:36:40 -0500 | [diff] [blame] | 7 | #include <clock_legacy.h> |
Simon Glass | 970b61e | 2019-11-14 12:57:09 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 9 | #include <image.h> |
Michael Walle | 24d116d | 2020-06-01 21:53:25 +0200 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 13 | #include <asm/io.h> |
Jiafei Pan | ded62e5 | 2021-04-21 12:12:49 +0800 | [diff] [blame] | 14 | #include <asm/ptrace.h> |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 15 | #include <asm/system.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 16 | #include <asm/arch/mp.h> |
| 17 | #include <asm/arch/soc.h> |
Michael Walle | 7e3d6fd | 2021-10-31 23:21:56 +0100 | [diff] [blame] | 18 | #include <linux/compat.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 19 | #include <linux/delay.h> |
Jiafei Pan | ded62e5 | 2021-04-21 12:12:49 +0800 | [diff] [blame] | 20 | #include <linux/psci.h> |
Michael Walle | 7e3d6fd | 2021-10-31 23:21:56 +0100 | [diff] [blame] | 21 | #include <malloc.h> |
Priyanka Jain | 9a27670 | 2016-11-17 12:29:56 +0530 | [diff] [blame] | 22 | #include "cpu.h" |
| 23 | #include <asm/arch-fsl-layerscape/soc.h> |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | void *get_spin_tbl_addr(void) |
| 28 | { |
Michael Walle | c251f5b | 2020-06-01 21:53:34 +0200 | [diff] [blame] | 29 | /* the spin table is at the beginning */ |
| 30 | return secondary_boot_code_start; |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Alison Wang | 876c7e1 | 2016-11-10 10:49:04 +0800 | [diff] [blame] | 33 | void update_os_arch_secondary_cores(uint8_t os_arch) |
| 34 | { |
| 35 | u64 *table = get_spin_tbl_addr(); |
| 36 | int i; |
| 37 | |
Alison Wang | a6231fe | 2017-06-08 16:15:14 +0800 | [diff] [blame] | 38 | for (i = 1; i < CONFIG_MAX_CPUS; i++) { |
| 39 | if (os_arch == IH_ARCH_DEFAULT) |
| 40 | table[i * WORDS_PER_SPIN_TABLE_ENTRY + |
| 41 | SPIN_TABLE_ELEM_ARCH_COMP_IDX] = OS_ARCH_SAME; |
| 42 | else |
| 43 | table[i * WORDS_PER_SPIN_TABLE_ENTRY + |
| 44 | SPIN_TABLE_ELEM_ARCH_COMP_IDX] = OS_ARCH_DIFF; |
| 45 | } |
Alison Wang | 876c7e1 | 2016-11-10 10:49:04 +0800 | [diff] [blame] | 46 | } |
| 47 | |
Priyanka Jain | 9a27670 | 2016-11-17 12:29:56 +0530 | [diff] [blame] | 48 | #ifdef CONFIG_FSL_LSCH3 |
Michael Walle | 319f1a3 | 2020-06-01 21:53:32 +0200 | [diff] [blame] | 49 | static void wake_secondary_core_n(int cluster, int core, int cluster_cores) |
Priyanka Jain | 9a27670 | 2016-11-17 12:29:56 +0530 | [diff] [blame] | 50 | { |
| 51 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 52 | struct ccsr_reset __iomem *rst = (void *)(CONFIG_SYS_FSL_RST_ADDR); |
| 53 | u32 mpidr = 0; |
| 54 | |
| 55 | mpidr = ((cluster << 8) | core); |
| 56 | /* |
| 57 | * mpidr_el1 register value of core which needs to be released |
| 58 | * is written to scratchrw[6] register |
| 59 | */ |
| 60 | gur_out32(&gur->scratchrw[6], mpidr); |
| 61 | asm volatile("dsb st" : : : "memory"); |
| 62 | rst->brrl |= 1 << ((cluster * cluster_cores) + core); |
| 63 | asm volatile("dsb st" : : : "memory"); |
| 64 | /* |
| 65 | * scratchrw[6] register value is polled |
| 66 | * when the value becomes zero, this means that this core is up |
| 67 | * and running, next core can be released now |
| 68 | */ |
| 69 | while (gur_in32(&gur->scratchrw[6]) != 0) |
| 70 | ; |
| 71 | } |
| 72 | #endif |
| 73 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 74 | int fsl_layerscape_wake_seconday_cores(void) |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 75 | { |
| 76 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
Hou Zhiqiang | c7098fa | 2015-10-26 19:47:57 +0800 | [diff] [blame] | 77 | #ifdef CONFIG_FSL_LSCH3 |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 78 | struct ccsr_reset __iomem *rst = (void *)(CONFIG_SYS_FSL_RST_ADDR); |
Priyanka Jain | 9a27670 | 2016-11-17 12:29:56 +0530 | [diff] [blame] | 79 | u32 svr, ver, cluster, type; |
| 80 | int j = 0, cluster_cores = 0; |
Hou Zhiqiang | c7098fa | 2015-10-26 19:47:57 +0800 | [diff] [blame] | 81 | #elif defined(CONFIG_FSL_LSCH2) |
| 82 | struct ccsr_scfg __iomem *scfg = (void *)(CONFIG_SYS_FSL_SCFG_ADDR); |
| 83 | #endif |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 84 | u32 cores, cpu_up_mask = 1; |
| 85 | int i, timeout = 10; |
Michael Walle | bd7e4ee | 2020-06-01 21:53:31 +0200 | [diff] [blame] | 86 | u64 *table; |
Michael Walle | 661c602 | 2020-06-01 21:53:35 +0200 | [diff] [blame] | 87 | #ifdef CONFIG_EFI_LOADER |
Michael Walle | 7e3d6fd | 2021-10-31 23:21:56 +0100 | [diff] [blame] | 88 | void *reloc_addr; |
Michael Walle | 661c602 | 2020-06-01 21:53:35 +0200 | [diff] [blame] | 89 | #endif |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 90 | |
York Sun | 77a1097 | 2015-03-20 19:28:08 -0700 | [diff] [blame] | 91 | #ifdef COUNTER_FREQUENCY_REAL |
| 92 | /* update for secondary cores */ |
| 93 | __real_cntfrq = COUNTER_FREQUENCY_REAL; |
| 94 | flush_dcache_range((unsigned long)&__real_cntfrq, |
| 95 | (unsigned long)&__real_cntfrq + 8); |
| 96 | #endif |
| 97 | |
Michael Walle | 661c602 | 2020-06-01 21:53:35 +0200 | [diff] [blame] | 98 | #ifdef CONFIG_EFI_LOADER |
| 99 | /* |
| 100 | * EFI will reserve 64kb for its runtime services. This will probably |
| 101 | * overlap with our spin table code, which is why we have to relocate |
| 102 | * it. |
| 103 | * Keep this after the __real_cntfrq update, so we have it when we |
| 104 | * copy the complete section here. |
| 105 | */ |
Michael Walle | 7e3d6fd | 2021-10-31 23:21:56 +0100 | [diff] [blame] | 106 | reloc_addr = memalign(PAGE_SIZE, |
| 107 | round_up(secondary_boot_code_size, PAGE_SIZE)); |
| 108 | if (reloc_addr) { |
| 109 | debug("Relocating spin table from %p to %p (size %lx)\n", |
| 110 | secondary_boot_code_start, reloc_addr, |
Michael Walle | 661c602 | 2020-06-01 21:53:35 +0200 | [diff] [blame] | 111 | secondary_boot_code_size); |
Michael Walle | 7e3d6fd | 2021-10-31 23:21:56 +0100 | [diff] [blame] | 112 | memcpy(reloc_addr, secondary_boot_code_start, |
Michael Walle | 661c602 | 2020-06-01 21:53:35 +0200 | [diff] [blame] | 113 | secondary_boot_code_size); |
Michael Walle | 7e3d6fd | 2021-10-31 23:21:56 +0100 | [diff] [blame] | 114 | flush_dcache_range((unsigned long)reloc_addr, |
| 115 | (unsigned long)reloc_addr + |
| 116 | secondary_boot_code_size); |
Michael Walle | 661c602 | 2020-06-01 21:53:35 +0200 | [diff] [blame] | 117 | |
| 118 | /* set new entry point for secondary cores */ |
Michael Walle | 7e3d6fd | 2021-10-31 23:21:56 +0100 | [diff] [blame] | 119 | secondary_boot_addr += reloc_addr - |
Michael Walle | 661c602 | 2020-06-01 21:53:35 +0200 | [diff] [blame] | 120 | secondary_boot_code_start; |
| 121 | flush_dcache_range((unsigned long)&secondary_boot_addr, |
| 122 | (unsigned long)&secondary_boot_addr + 8); |
| 123 | |
| 124 | /* this will be used to reserve the memory */ |
Michael Walle | 7e3d6fd | 2021-10-31 23:21:56 +0100 | [diff] [blame] | 125 | secondary_boot_code_start = reloc_addr; |
Michael Walle | 661c602 | 2020-06-01 21:53:35 +0200 | [diff] [blame] | 126 | } |
| 127 | #endif |
| 128 | |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 129 | cores = cpu_mask(); |
| 130 | /* Clear spin table so that secondary processors |
| 131 | * observe the correct value after waking up from wfe. |
| 132 | */ |
Michael Walle | bd7e4ee | 2020-06-01 21:53:31 +0200 | [diff] [blame] | 133 | table = get_spin_tbl_addr(); |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 134 | memset(table, 0, CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE); |
| 135 | flush_dcache_range((unsigned long)table, |
| 136 | (unsigned long)table + |
| 137 | (CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE)); |
| 138 | |
Michael Walle | 24d116d | 2020-06-01 21:53:25 +0200 | [diff] [blame] | 139 | debug("Waking secondary cores to start from %lx\n", gd->relocaddr); |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 140 | |
Hou Zhiqiang | c7098fa | 2015-10-26 19:47:57 +0800 | [diff] [blame] | 141 | #ifdef CONFIG_FSL_LSCH3 |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 142 | gur_out32(&gur->bootlocptrh, (u32)(gd->relocaddr >> 32)); |
| 143 | gur_out32(&gur->bootlocptrl, (u32)gd->relocaddr); |
Priyanka Jain | 9a27670 | 2016-11-17 12:29:56 +0530 | [diff] [blame] | 144 | |
| 145 | svr = gur_in32(&gur->svr); |
| 146 | ver = SVR_SOC_VER(svr); |
| 147 | if (ver == SVR_LS2080A || ver == SVR_LS2085A) { |
| 148 | gur_out32(&gur->scratchrw[6], 1); |
| 149 | asm volatile("dsb st" : : : "memory"); |
| 150 | rst->brrl = cores; |
| 151 | asm volatile("dsb st" : : : "memory"); |
| 152 | } else { |
| 153 | /* |
| 154 | * Release the cores out of reset one-at-a-time to avoid |
| 155 | * power spikes |
| 156 | */ |
| 157 | i = 0; |
| 158 | cluster = in_le32(&gur->tp_cluster[i].lower); |
| 159 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 160 | type = initiator_type(cluster, j); |
| 161 | if (type && |
| 162 | TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM) |
| 163 | cluster_cores++; |
| 164 | } |
| 165 | |
| 166 | do { |
| 167 | cluster = in_le32(&gur->tp_cluster[i].lower); |
| 168 | for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { |
| 169 | type = initiator_type(cluster, j); |
| 170 | if (type && |
| 171 | TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM) |
| 172 | wake_secondary_core_n(i, j, |
| 173 | cluster_cores); |
| 174 | } |
| 175 | i++; |
| 176 | } while ((cluster & TP_CLUSTER_EOC) != TP_CLUSTER_EOC); |
| 177 | } |
Hou Zhiqiang | c7098fa | 2015-10-26 19:47:57 +0800 | [diff] [blame] | 178 | #elif defined(CONFIG_FSL_LSCH2) |
| 179 | scfg_out32(&scfg->scratchrw[0], (u32)(gd->relocaddr >> 32)); |
| 180 | scfg_out32(&scfg->scratchrw[1], (u32)gd->relocaddr); |
| 181 | asm volatile("dsb st" : : : "memory"); |
| 182 | gur_out32(&gur->brrl, cores); |
| 183 | asm volatile("dsb st" : : : "memory"); |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 184 | |
Hou Zhiqiang | c7098fa | 2015-10-26 19:47:57 +0800 | [diff] [blame] | 185 | /* Bootup online cores */ |
| 186 | scfg_out32(&scfg->corebcr, cores); |
| 187 | #endif |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 188 | /* This is needed as a precautionary measure. |
| 189 | * If some code before this has accidentally released the secondary |
| 190 | * cores then the pre-bootloader code will trap them in a "wfe" unless |
| 191 | * the scratchrw[6] is set. In this case we need a sev here to get these |
| 192 | * cores moving again. |
| 193 | */ |
| 194 | asm volatile("sev"); |
| 195 | |
| 196 | while (timeout--) { |
| 197 | flush_dcache_range((unsigned long)table, (unsigned long)table + |
| 198 | CONFIG_MAX_CPUS * 64); |
| 199 | for (i = 1; i < CONFIG_MAX_CPUS; i++) { |
| 200 | if (table[i * WORDS_PER_SPIN_TABLE_ENTRY + |
| 201 | SPIN_TABLE_ELEM_STATUS_IDX]) |
| 202 | cpu_up_mask |= 1 << i; |
| 203 | } |
| 204 | if (hweight32(cpu_up_mask) == hweight32(cores)) |
| 205 | break; |
| 206 | udelay(10); |
| 207 | } |
| 208 | if (timeout <= 0) { |
Michael Walle | 24d116d | 2020-06-01 21:53:25 +0200 | [diff] [blame] | 209 | printf("CPU: Failed to bring up some cores (mask 0x%x)\n", |
| 210 | cores ^ cpu_up_mask); |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 211 | return 1; |
| 212 | } |
Michael Walle | 24d116d | 2020-06-01 21:53:25 +0200 | [diff] [blame] | 213 | printf("CPU: %d cores online\n", hweight32(cores)); |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | int is_core_valid(unsigned int core) |
| 219 | { |
| 220 | return !!((1 << core) & cpu_mask()); |
| 221 | } |
| 222 | |
York Sun | ed7fbe3 | 2016-09-13 12:40:30 -0700 | [diff] [blame] | 223 | static int is_pos_valid(unsigned int pos) |
| 224 | { |
| 225 | return !!((1 << pos) & cpu_pos_mask()); |
| 226 | } |
| 227 | |
Arnab Basu | 0cb1942 | 2015-01-06 13:18:41 -0800 | [diff] [blame] | 228 | int is_core_online(u64 cpu_id) |
| 229 | { |
Michael Walle | bd7e4ee | 2020-06-01 21:53:31 +0200 | [diff] [blame] | 230 | u64 *table = get_spin_tbl_addr(); |
Arnab Basu | 0cb1942 | 2015-01-06 13:18:41 -0800 | [diff] [blame] | 231 | int pos = id_to_core(cpu_id); |
Michael Walle | bd7e4ee | 2020-06-01 21:53:31 +0200 | [diff] [blame] | 232 | table += pos * WORDS_PER_SPIN_TABLE_ENTRY; |
Arnab Basu | 0cb1942 | 2015-01-06 13:18:41 -0800 | [diff] [blame] | 233 | return table[SPIN_TABLE_ELEM_STATUS_IDX] == 1; |
| 234 | } |
| 235 | |
Michal Simek | 1669e18 | 2018-06-13 08:56:31 +0200 | [diff] [blame] | 236 | int cpu_reset(u32 nr) |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 237 | { |
| 238 | puts("Feature is not implemented.\n"); |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
Michal Simek | 1669e18 | 2018-06-13 08:56:31 +0200 | [diff] [blame] | 243 | int cpu_disable(u32 nr) |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 244 | { |
| 245 | puts("Feature is not implemented.\n"); |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
York Sun | ed7fbe3 | 2016-09-13 12:40:30 -0700 | [diff] [blame] | 250 | static int core_to_pos(int nr) |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 251 | { |
York Sun | ed7fbe3 | 2016-09-13 12:40:30 -0700 | [diff] [blame] | 252 | u32 cores = cpu_pos_mask(); |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 253 | int i, count = 0; |
| 254 | |
| 255 | if (nr == 0) { |
| 256 | return 0; |
| 257 | } else if (nr >= hweight32(cores)) { |
| 258 | puts("Not a valid core number.\n"); |
| 259 | return -1; |
| 260 | } |
| 261 | |
| 262 | for (i = 1; i < 32; i++) { |
York Sun | ed7fbe3 | 2016-09-13 12:40:30 -0700 | [diff] [blame] | 263 | if (is_pos_valid(i)) { |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 264 | count++; |
| 265 | if (count == nr) |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | |
York Sun | ed7fbe3 | 2016-09-13 12:40:30 -0700 | [diff] [blame] | 270 | if (count != nr) |
| 271 | return -1; |
| 272 | |
| 273 | return i; |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Michal Simek | 1669e18 | 2018-06-13 08:56:31 +0200 | [diff] [blame] | 276 | int cpu_status(u32 nr) |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 277 | { |
Michael Walle | bd7e4ee | 2020-06-01 21:53:31 +0200 | [diff] [blame] | 278 | u64 *table = get_spin_tbl_addr(); |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 279 | int pos; |
| 280 | |
| 281 | if (nr == 0) { |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 282 | printf("table base @ 0x%p\n", table); |
| 283 | } else { |
| 284 | pos = core_to_pos(nr); |
| 285 | if (pos < 0) |
| 286 | return -1; |
Michael Walle | bd7e4ee | 2020-06-01 21:53:31 +0200 | [diff] [blame] | 287 | table += pos * WORDS_PER_SPIN_TABLE_ENTRY; |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 288 | printf("table @ 0x%p\n", table); |
| 289 | printf(" addr - 0x%016llx\n", |
| 290 | table[SPIN_TABLE_ELEM_ENTRY_ADDR_IDX]); |
| 291 | printf(" status - 0x%016llx\n", |
| 292 | table[SPIN_TABLE_ELEM_STATUS_IDX]); |
| 293 | printf(" lpid - 0x%016llx\n", |
| 294 | table[SPIN_TABLE_ELEM_LPID_IDX]); |
| 295 | } |
| 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 300 | int cpu_release(u32 nr, int argc, char *const argv[]) |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 301 | { |
| 302 | u64 boot_addr; |
Michael Walle | bd7e4ee | 2020-06-01 21:53:31 +0200 | [diff] [blame] | 303 | u64 *table = get_spin_tbl_addr(); |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 304 | int pos; |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 305 | int ret; |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 306 | |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 307 | boot_addr = simple_strtoull(argv[0], NULL, 16); |
Jiafei Pan | ded62e5 | 2021-04-21 12:12:49 +0800 | [diff] [blame] | 308 | |
| 309 | if (check_psci()) { |
| 310 | /* SPIN Table is used */ |
| 311 | pos = core_to_pos(nr); |
| 312 | if (pos <= 0) |
| 313 | return -1; |
| 314 | |
| 315 | table += pos * WORDS_PER_SPIN_TABLE_ENTRY; |
| 316 | table[SPIN_TABLE_ELEM_ENTRY_ADDR_IDX] = boot_addr; |
| 317 | flush_dcache_range((unsigned long)table, |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 318 | (unsigned long)table + SPIN_TABLE_ELEM_SIZE); |
Jiafei Pan | ded62e5 | 2021-04-21 12:12:49 +0800 | [diff] [blame] | 319 | asm volatile("dsb st"); |
Michael Walle | 576f6850 | 2020-06-01 21:53:24 +0200 | [diff] [blame] | 320 | |
Jiafei Pan | ded62e5 | 2021-04-21 12:12:49 +0800 | [diff] [blame] | 321 | /* |
| 322 | * The secondary CPUs polling the spin-table above for a non-zero |
| 323 | * value. To save power "wfe" is called. Thus call "sev" here to |
| 324 | * wake the CPUs and let them check the spin-table again (see |
| 325 | * slave_cpu loop in lowlevel.S) |
| 326 | */ |
| 327 | asm volatile("sev"); |
| 328 | } else { |
| 329 | /* Use PSCI to kick the core */ |
Jiafei Pan | ded62e5 | 2021-04-21 12:12:49 +0800 | [diff] [blame] | 330 | printf("begin to kick cpu core #%d to address %llx\n", |
| 331 | nr, boot_addr); |
Michael Walle | 166ea48 | 2022-04-22 14:53:27 +0530 | [diff] [blame] | 332 | ret = invoke_psci_fn(PSCI_0_2_FN64_CPU_ON, nr, boot_addr, 0); |
| 333 | if (ret) |
Jiafei Pan | ded62e5 | 2021-04-21 12:12:49 +0800 | [diff] [blame] | 334 | return -1; |
| 335 | } |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 336 | |
| 337 | return 0; |
| 338 | } |