2 * Copyright 2014-2015 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/system.h>
10 #include <asm/arch/mp.h>
11 #include <asm/arch/soc.h>
13 #include <asm/arch-fsl-layerscape/soc.h>
15 DECLARE_GLOBAL_DATA_PTR
;
17 void *get_spin_tbl_addr(void)
22 phys_addr_t
determine_mp_bootpg(void)
24 return (phys_addr_t
)&secondary_boot_code
;
27 void update_os_arch_secondary_cores(uint8_t os_arch
)
29 u64
*table
= get_spin_tbl_addr();
32 for (i
= 1; i
< CONFIG_MAX_CPUS
; i
++)
33 table
[i
* WORDS_PER_SPIN_TABLE_ENTRY
+
34 SPIN_TABLE_ELEM_OS_ARCH_IDX
] = os_arch
;
37 #ifdef CONFIG_FSL_LSCH3
38 void wake_secondary_core_n(int cluster
, int core
, int cluster_cores
)
40 struct ccsr_gur __iomem
*gur
= (void *)(CONFIG_SYS_FSL_GUTS_ADDR
);
41 struct ccsr_reset __iomem
*rst
= (void *)(CONFIG_SYS_FSL_RST_ADDR
);
44 mpidr
= ((cluster
<< 8) | core
);
46 * mpidr_el1 register value of core which needs to be released
47 * is written to scratchrw[6] register
49 gur_out32(&gur
->scratchrw
[6], mpidr
);
50 asm volatile("dsb st" : : : "memory");
51 rst
->brrl
|= 1 << ((cluster
* cluster_cores
) + core
);
52 asm volatile("dsb st" : : : "memory");
54 * scratchrw[6] register value is polled
55 * when the value becomes zero, this means that this core is up
56 * and running, next core can be released now
58 while (gur_in32(&gur
->scratchrw
[6]) != 0)
63 int fsl_layerscape_wake_seconday_cores(void)
65 struct ccsr_gur __iomem
*gur
= (void *)(CONFIG_SYS_FSL_GUTS_ADDR
);
66 #ifdef CONFIG_FSL_LSCH3
67 struct ccsr_reset __iomem
*rst
= (void *)(CONFIG_SYS_FSL_RST_ADDR
);
68 u32 svr
, ver
, cluster
, type
;
69 int j
= 0, cluster_cores
= 0;
70 #elif defined(CONFIG_FSL_LSCH2)
71 struct ccsr_scfg __iomem
*scfg
= (void *)(CONFIG_SYS_FSL_SCFG_ADDR
);
73 u32 cores
, cpu_up_mask
= 1;
75 u64
*table
= get_spin_tbl_addr();
77 #ifdef COUNTER_FREQUENCY_REAL
78 /* update for secondary cores */
79 __real_cntfrq
= COUNTER_FREQUENCY_REAL
;
80 flush_dcache_range((unsigned long)&__real_cntfrq
,
81 (unsigned long)&__real_cntfrq
+ 8);
85 /* Clear spin table so that secondary processors
86 * observe the correct value after waking up from wfe.
88 memset(table
, 0, CONFIG_MAX_CPUS
*SPIN_TABLE_ELEM_SIZE
);
89 flush_dcache_range((unsigned long)table
,
90 (unsigned long)table
+
91 (CONFIG_MAX_CPUS
*SPIN_TABLE_ELEM_SIZE
));
93 printf("Waking secondary cores to start from %lx\n", gd
->relocaddr
);
95 #ifdef CONFIG_FSL_LSCH3
96 gur_out32(&gur
->bootlocptrh
, (u32
)(gd
->relocaddr
>> 32));
97 gur_out32(&gur
->bootlocptrl
, (u32
)gd
->relocaddr
);
99 svr
= gur_in32(&gur
->svr
);
100 ver
= SVR_SOC_VER(svr
);
101 if (ver
== SVR_LS2080A
|| ver
== SVR_LS2085A
) {
102 gur_out32(&gur
->scratchrw
[6], 1);
103 asm volatile("dsb st" : : : "memory");
105 asm volatile("dsb st" : : : "memory");
108 * Release the cores out of reset one-at-a-time to avoid
112 cluster
= in_le32(&gur
->tp_cluster
[i
].lower
);
113 for (j
= 0; j
< TP_INIT_PER_CLUSTER
; j
++) {
114 type
= initiator_type(cluster
, j
);
116 TP_ITYP_TYPE(type
) == TP_ITYP_TYPE_ARM
)
121 cluster
= in_le32(&gur
->tp_cluster
[i
].lower
);
122 for (j
= 0; j
< TP_INIT_PER_CLUSTER
; j
++) {
123 type
= initiator_type(cluster
, j
);
125 TP_ITYP_TYPE(type
) == TP_ITYP_TYPE_ARM
)
126 wake_secondary_core_n(i
, j
,
130 } while ((cluster
& TP_CLUSTER_EOC
) != TP_CLUSTER_EOC
);
132 #elif defined(CONFIG_FSL_LSCH2)
133 scfg_out32(&scfg
->scratchrw
[0], (u32
)(gd
->relocaddr
>> 32));
134 scfg_out32(&scfg
->scratchrw
[1], (u32
)gd
->relocaddr
);
135 asm volatile("dsb st" : : : "memory");
136 gur_out32(&gur
->brrl
, cores
);
137 asm volatile("dsb st" : : : "memory");
139 /* Bootup online cores */
140 scfg_out32(&scfg
->corebcr
, cores
);
142 /* This is needed as a precautionary measure.
143 * If some code before this has accidentally released the secondary
144 * cores then the pre-bootloader code will trap them in a "wfe" unless
145 * the scratchrw[6] is set. In this case we need a sev here to get these
146 * cores moving again.
151 flush_dcache_range((unsigned long)table
, (unsigned long)table
+
152 CONFIG_MAX_CPUS
* 64);
153 for (i
= 1; i
< CONFIG_MAX_CPUS
; i
++) {
154 if (table
[i
* WORDS_PER_SPIN_TABLE_ENTRY
+
155 SPIN_TABLE_ELEM_STATUS_IDX
])
156 cpu_up_mask
|= 1 << i
;
158 if (hweight32(cpu_up_mask
) == hweight32(cores
))
163 printf("Not all cores (0x%x) are up (0x%x)\n",
167 printf("All (%d) cores are up.\n", hweight32(cores
));
172 int is_core_valid(unsigned int core
)
174 return !!((1 << core
) & cpu_mask());
177 static int is_pos_valid(unsigned int pos
)
179 return !!((1 << pos
) & cpu_pos_mask());
182 int is_core_online(u64 cpu_id
)
185 int pos
= id_to_core(cpu_id
);
186 table
= (u64
*)get_spin_tbl_addr() + pos
* WORDS_PER_SPIN_TABLE_ENTRY
;
187 return table
[SPIN_TABLE_ELEM_STATUS_IDX
] == 1;
190 int cpu_reset(int nr
)
192 puts("Feature is not implemented.\n");
197 int cpu_disable(int nr
)
199 puts("Feature is not implemented.\n");
204 static int core_to_pos(int nr
)
206 u32 cores
= cpu_pos_mask();
211 } else if (nr
>= hweight32(cores
)) {
212 puts("Not a valid core number.\n");
216 for (i
= 1; i
< 32; i
++) {
217 if (is_pos_valid(i
)) {
230 int cpu_status(int nr
)
236 table
= (u64
*)get_spin_tbl_addr();
237 printf("table base @ 0x%p\n", table
);
239 pos
= core_to_pos(nr
);
242 table
= (u64
*)get_spin_tbl_addr() + pos
*
243 WORDS_PER_SPIN_TABLE_ENTRY
;
244 printf("table @ 0x%p\n", table
);
245 printf(" addr - 0x%016llx\n",
246 table
[SPIN_TABLE_ELEM_ENTRY_ADDR_IDX
]);
247 printf(" status - 0x%016llx\n",
248 table
[SPIN_TABLE_ELEM_STATUS_IDX
]);
249 printf(" lpid - 0x%016llx\n",
250 table
[SPIN_TABLE_ELEM_LPID_IDX
]);
256 int cpu_release(int nr
, int argc
, char * const argv
[])
259 u64
*table
= (u64
*)get_spin_tbl_addr();
262 pos
= core_to_pos(nr
);
266 table
+= pos
* WORDS_PER_SPIN_TABLE_ENTRY
;
267 boot_addr
= simple_strtoull(argv
[0], NULL
, 16);
268 table
[SPIN_TABLE_ELEM_ENTRY_ADDR_IDX
] = boot_addr
;
269 flush_dcache_range((unsigned long)table
,
270 (unsigned long)table
+ SPIN_TABLE_ELEM_SIZE
);
271 asm volatile("dsb st");
272 smp_kick_all_cpus(); /* only those with entry addr set will run */
274 * When the first release command runs, all cores are set to go. Those
275 * without a valid entry address will be trapped by "wfe". "sev" kicks
276 * them off to check the address again. When set, they continue to run.