1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014-2015 Freescale Semiconductor, Inc.
10 #include <asm/system.h>
11 #include <asm/arch/mp.h>
12 #include <asm/arch/soc.h>
14 #include <asm/arch-fsl-layerscape/soc.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 void *get_spin_tbl_addr(void)
23 phys_addr_t determine_mp_bootpg(void)
25 return (phys_addr_t)&secondary_boot_code;
28 void update_os_arch_secondary_cores(uint8_t os_arch)
30 u64 *table = get_spin_tbl_addr();
33 for (i = 1; i < CONFIG_MAX_CPUS; i++) {
34 if (os_arch == IH_ARCH_DEFAULT)
35 table[i * WORDS_PER_SPIN_TABLE_ENTRY +
36 SPIN_TABLE_ELEM_ARCH_COMP_IDX] = OS_ARCH_SAME;
38 table[i * WORDS_PER_SPIN_TABLE_ENTRY +
39 SPIN_TABLE_ELEM_ARCH_COMP_IDX] = OS_ARCH_DIFF;
43 #ifdef CONFIG_FSL_LSCH3
44 void wake_secondary_core_n(int cluster, int core, int cluster_cores)
46 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
47 struct ccsr_reset __iomem *rst = (void *)(CONFIG_SYS_FSL_RST_ADDR);
50 mpidr = ((cluster << 8) | core);
52 * mpidr_el1 register value of core which needs to be released
53 * is written to scratchrw[6] register
55 gur_out32(&gur->scratchrw[6], mpidr);
56 asm volatile("dsb st" : : : "memory");
57 rst->brrl |= 1 << ((cluster * cluster_cores) + core);
58 asm volatile("dsb st" : : : "memory");
60 * scratchrw[6] register value is polled
61 * when the value becomes zero, this means that this core is up
62 * and running, next core can be released now
64 while (gur_in32(&gur->scratchrw[6]) != 0)
69 int fsl_layerscape_wake_seconday_cores(void)
71 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
72 #ifdef CONFIG_FSL_LSCH3
73 struct ccsr_reset __iomem *rst = (void *)(CONFIG_SYS_FSL_RST_ADDR);
74 u32 svr, ver, cluster, type;
75 int j = 0, cluster_cores = 0;
76 #elif defined(CONFIG_FSL_LSCH2)
77 struct ccsr_scfg __iomem *scfg = (void *)(CONFIG_SYS_FSL_SCFG_ADDR);
79 u32 cores, cpu_up_mask = 1;
81 u64 *table = get_spin_tbl_addr();
83 #ifdef COUNTER_FREQUENCY_REAL
84 /* update for secondary cores */
85 __real_cntfrq = COUNTER_FREQUENCY_REAL;
86 flush_dcache_range((unsigned long)&__real_cntfrq,
87 (unsigned long)&__real_cntfrq + 8);
91 /* Clear spin table so that secondary processors
92 * observe the correct value after waking up from wfe.
94 memset(table, 0, CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE);
95 flush_dcache_range((unsigned long)table,
96 (unsigned long)table +
97 (CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE));
99 printf("Waking secondary cores to start from %lx\n", gd->relocaddr);
101 #ifdef CONFIG_FSL_LSCH3
102 gur_out32(&gur->bootlocptrh, (u32)(gd->relocaddr >> 32));
103 gur_out32(&gur->bootlocptrl, (u32)gd->relocaddr);
105 svr = gur_in32(&gur->svr);
106 ver = SVR_SOC_VER(svr);
107 if (ver == SVR_LS2080A || ver == SVR_LS2085A) {
108 gur_out32(&gur->scratchrw[6], 1);
109 asm volatile("dsb st" : : : "memory");
111 asm volatile("dsb st" : : : "memory");
114 * Release the cores out of reset one-at-a-time to avoid
118 cluster = in_le32(&gur->tp_cluster[i].lower);
119 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
120 type = initiator_type(cluster, j);
122 TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)
127 cluster = in_le32(&gur->tp_cluster[i].lower);
128 for (j = 0; j < TP_INIT_PER_CLUSTER; j++) {
129 type = initiator_type(cluster, j);
131 TP_ITYP_TYPE(type) == TP_ITYP_TYPE_ARM)
132 wake_secondary_core_n(i, j,
136 } while ((cluster & TP_CLUSTER_EOC) != TP_CLUSTER_EOC);
138 #elif defined(CONFIG_FSL_LSCH2)
139 scfg_out32(&scfg->scratchrw[0], (u32)(gd->relocaddr >> 32));
140 scfg_out32(&scfg->scratchrw[1], (u32)gd->relocaddr);
141 asm volatile("dsb st" : : : "memory");
142 gur_out32(&gur->brrl, cores);
143 asm volatile("dsb st" : : : "memory");
145 /* Bootup online cores */
146 scfg_out32(&scfg->corebcr, cores);
148 /* This is needed as a precautionary measure.
149 * If some code before this has accidentally released the secondary
150 * cores then the pre-bootloader code will trap them in a "wfe" unless
151 * the scratchrw[6] is set. In this case we need a sev here to get these
152 * cores moving again.
157 flush_dcache_range((unsigned long)table, (unsigned long)table +
158 CONFIG_MAX_CPUS * 64);
159 for (i = 1; i < CONFIG_MAX_CPUS; i++) {
160 if (table[i * WORDS_PER_SPIN_TABLE_ENTRY +
161 SPIN_TABLE_ELEM_STATUS_IDX])
162 cpu_up_mask |= 1 << i;
164 if (hweight32(cpu_up_mask) == hweight32(cores))
169 printf("Not all cores (0x%x) are up (0x%x)\n",
173 printf("All (%d) cores are up.\n", hweight32(cores));
178 int is_core_valid(unsigned int core)
180 return !!((1 << core) & cpu_mask());
183 static int is_pos_valid(unsigned int pos)
185 return !!((1 << pos) & cpu_pos_mask());
188 int is_core_online(u64 cpu_id)
191 int pos = id_to_core(cpu_id);
192 table = (u64 *)get_spin_tbl_addr() + pos * WORDS_PER_SPIN_TABLE_ENTRY;
193 return table[SPIN_TABLE_ELEM_STATUS_IDX] == 1;
196 int cpu_reset(u32 nr)
198 puts("Feature is not implemented.\n");
203 int cpu_disable(u32 nr)
205 puts("Feature is not implemented.\n");
210 static int core_to_pos(int nr)
212 u32 cores = cpu_pos_mask();
217 } else if (nr >= hweight32(cores)) {
218 puts("Not a valid core number.\n");
222 for (i = 1; i < 32; i++) {
223 if (is_pos_valid(i)) {
236 int cpu_status(u32 nr)
242 table = (u64 *)get_spin_tbl_addr();
243 printf("table base @ 0x%p\n", table);
245 pos = core_to_pos(nr);
248 table = (u64 *)get_spin_tbl_addr() + pos *
249 WORDS_PER_SPIN_TABLE_ENTRY;
250 printf("table @ 0x%p\n", table);
251 printf(" addr - 0x%016llx\n",
252 table[SPIN_TABLE_ELEM_ENTRY_ADDR_IDX]);
253 printf(" status - 0x%016llx\n",
254 table[SPIN_TABLE_ELEM_STATUS_IDX]);
255 printf(" lpid - 0x%016llx\n",
256 table[SPIN_TABLE_ELEM_LPID_IDX]);
262 int cpu_release(u32 nr, int argc, char * const argv[])
265 u64 *table = (u64 *)get_spin_tbl_addr();
268 pos = core_to_pos(nr);
272 table += pos * WORDS_PER_SPIN_TABLE_ENTRY;
273 boot_addr = simple_strtoull(argv[0], NULL, 16);
274 table[SPIN_TABLE_ELEM_ENTRY_ADDR_IDX] = boot_addr;
275 flush_dcache_range((unsigned long)table,
276 (unsigned long)table + SPIN_TABLE_ELEM_SIZE);
277 asm volatile("dsb st");
278 smp_kick_all_cpus(); /* only those with entry addr set will run */
280 * When the first release command runs, all cores are set to go. Those
281 * without a valid entry address will be trapped by "wfe". "sev" kicks
282 * them off to check the address again. When set, they continue to run.