blob: f607c3900ad53514b309a5d210eec3a6da477c56 [file] [log] [blame]
York Sun56cc3db2014-09-08 12:20:00 -07001/*
Mingkai Hu0e58b512015-10-26 19:47:50 +08002 * Copyright 2014-2015 Freescale Semiconductor, Inc.
York Sun56cc3db2014-09-08 12:20:00 -07003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <asm/system.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080010#include <asm/arch/mp.h>
11#include <asm/arch/soc.h>
York Sun56cc3db2014-09-08 12:20:00 -070012
13DECLARE_GLOBAL_DATA_PTR;
14
15void *get_spin_tbl_addr(void)
16{
17 return &__spin_table;
18}
19
20phys_addr_t determine_mp_bootpg(void)
21{
22 return (phys_addr_t)&secondary_boot_code;
23}
24
Mingkai Hu0e58b512015-10-26 19:47:50 +080025int fsl_layerscape_wake_seconday_cores(void)
York Sun56cc3db2014-09-08 12:20:00 -070026{
27 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
Hou Zhiqiangc7098fa2015-10-26 19:47:57 +080028#ifdef CONFIG_FSL_LSCH3
York Sun56cc3db2014-09-08 12:20:00 -070029 struct ccsr_reset __iomem *rst = (void *)(CONFIG_SYS_FSL_RST_ADDR);
Hou Zhiqiangc7098fa2015-10-26 19:47:57 +080030#elif defined(CONFIG_FSL_LSCH2)
31 struct ccsr_scfg __iomem *scfg = (void *)(CONFIG_SYS_FSL_SCFG_ADDR);
32#endif
York Sun56cc3db2014-09-08 12:20:00 -070033 u32 cores, cpu_up_mask = 1;
34 int i, timeout = 10;
35 u64 *table = get_spin_tbl_addr();
36
York Sun77a10972015-03-20 19:28:08 -070037#ifdef COUNTER_FREQUENCY_REAL
38 /* update for secondary cores */
39 __real_cntfrq = COUNTER_FREQUENCY_REAL;
40 flush_dcache_range((unsigned long)&__real_cntfrq,
41 (unsigned long)&__real_cntfrq + 8);
42#endif
43
York Sun56cc3db2014-09-08 12:20:00 -070044 cores = cpu_mask();
45 /* Clear spin table so that secondary processors
46 * observe the correct value after waking up from wfe.
47 */
48 memset(table, 0, CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE);
49 flush_dcache_range((unsigned long)table,
50 (unsigned long)table +
51 (CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE));
52
53 printf("Waking secondary cores to start from %lx\n", gd->relocaddr);
Mingkai Hu0e58b512015-10-26 19:47:50 +080054
Hou Zhiqiangc7098fa2015-10-26 19:47:57 +080055#ifdef CONFIG_FSL_LSCH3
Mingkai Hu0e58b512015-10-26 19:47:50 +080056 gur_out32(&gur->bootlocptrh, (u32)(gd->relocaddr >> 32));
57 gur_out32(&gur->bootlocptrl, (u32)gd->relocaddr);
58 gur_out32(&gur->scratchrw[6], 1);
York Sun56cc3db2014-09-08 12:20:00 -070059 asm volatile("dsb st" : : : "memory");
60 rst->brrl = cores;
61 asm volatile("dsb st" : : : "memory");
Hou Zhiqiangc7098fa2015-10-26 19:47:57 +080062#elif defined(CONFIG_FSL_LSCH2)
63 scfg_out32(&scfg->scratchrw[0], (u32)(gd->relocaddr >> 32));
64 scfg_out32(&scfg->scratchrw[1], (u32)gd->relocaddr);
65 asm volatile("dsb st" : : : "memory");
66 gur_out32(&gur->brrl, cores);
67 asm volatile("dsb st" : : : "memory");
York Sun56cc3db2014-09-08 12:20:00 -070068
Hou Zhiqiangc7098fa2015-10-26 19:47:57 +080069 /* Bootup online cores */
70 scfg_out32(&scfg->corebcr, cores);
71#endif
York Sun56cc3db2014-09-08 12:20:00 -070072 /* This is needed as a precautionary measure.
73 * If some code before this has accidentally released the secondary
74 * cores then the pre-bootloader code will trap them in a "wfe" unless
75 * the scratchrw[6] is set. In this case we need a sev here to get these
76 * cores moving again.
77 */
78 asm volatile("sev");
79
80 while (timeout--) {
81 flush_dcache_range((unsigned long)table, (unsigned long)table +
82 CONFIG_MAX_CPUS * 64);
83 for (i = 1; i < CONFIG_MAX_CPUS; i++) {
84 if (table[i * WORDS_PER_SPIN_TABLE_ENTRY +
85 SPIN_TABLE_ELEM_STATUS_IDX])
86 cpu_up_mask |= 1 << i;
87 }
88 if (hweight32(cpu_up_mask) == hweight32(cores))
89 break;
90 udelay(10);
91 }
92 if (timeout <= 0) {
93 printf("Not all cores (0x%x) are up (0x%x)\n",
94 cores, cpu_up_mask);
95 return 1;
96 }
97 printf("All (%d) cores are up.\n", hweight32(cores));
98
99 return 0;
100}
101
102int is_core_valid(unsigned int core)
103{
104 return !!((1 << core) & cpu_mask());
105}
106
York Suned7fbe32016-09-13 12:40:30 -0700107static int is_pos_valid(unsigned int pos)
108{
109 return !!((1 << pos) & cpu_pos_mask());
110}
111
Arnab Basu0cb19422015-01-06 13:18:41 -0800112int is_core_online(u64 cpu_id)
113{
114 u64 *table;
115 int pos = id_to_core(cpu_id);
116 table = (u64 *)get_spin_tbl_addr() + pos * WORDS_PER_SPIN_TABLE_ENTRY;
117 return table[SPIN_TABLE_ELEM_STATUS_IDX] == 1;
118}
119
York Sun56cc3db2014-09-08 12:20:00 -0700120int cpu_reset(int nr)
121{
122 puts("Feature is not implemented.\n");
123
124 return 0;
125}
126
127int cpu_disable(int nr)
128{
129 puts("Feature is not implemented.\n");
130
131 return 0;
132}
133
York Suned7fbe32016-09-13 12:40:30 -0700134static int core_to_pos(int nr)
York Sun56cc3db2014-09-08 12:20:00 -0700135{
York Suned7fbe32016-09-13 12:40:30 -0700136 u32 cores = cpu_pos_mask();
York Sun56cc3db2014-09-08 12:20:00 -0700137 int i, count = 0;
138
139 if (nr == 0) {
140 return 0;
141 } else if (nr >= hweight32(cores)) {
142 puts("Not a valid core number.\n");
143 return -1;
144 }
145
146 for (i = 1; i < 32; i++) {
York Suned7fbe32016-09-13 12:40:30 -0700147 if (is_pos_valid(i)) {
York Sun56cc3db2014-09-08 12:20:00 -0700148 count++;
149 if (count == nr)
150 break;
151 }
152 }
153
York Suned7fbe32016-09-13 12:40:30 -0700154 if (count != nr)
155 return -1;
156
157 return i;
York Sun56cc3db2014-09-08 12:20:00 -0700158}
159
160int cpu_status(int nr)
161{
162 u64 *table;
163 int pos;
164
165 if (nr == 0) {
166 table = (u64 *)get_spin_tbl_addr();
167 printf("table base @ 0x%p\n", table);
168 } else {
169 pos = core_to_pos(nr);
170 if (pos < 0)
171 return -1;
172 table = (u64 *)get_spin_tbl_addr() + pos *
173 WORDS_PER_SPIN_TABLE_ENTRY;
174 printf("table @ 0x%p\n", table);
175 printf(" addr - 0x%016llx\n",
176 table[SPIN_TABLE_ELEM_ENTRY_ADDR_IDX]);
177 printf(" status - 0x%016llx\n",
178 table[SPIN_TABLE_ELEM_STATUS_IDX]);
179 printf(" lpid - 0x%016llx\n",
180 table[SPIN_TABLE_ELEM_LPID_IDX]);
181 }
182
183 return 0;
184}
185
186int cpu_release(int nr, int argc, char * const argv[])
187{
188 u64 boot_addr;
189 u64 *table = (u64 *)get_spin_tbl_addr();
190 int pos;
191
192 pos = core_to_pos(nr);
193 if (pos <= 0)
194 return -1;
195
196 table += pos * WORDS_PER_SPIN_TABLE_ENTRY;
197 boot_addr = simple_strtoull(argv[0], NULL, 16);
198 table[SPIN_TABLE_ELEM_ENTRY_ADDR_IDX] = boot_addr;
199 flush_dcache_range((unsigned long)table,
200 (unsigned long)table + SPIN_TABLE_ELEM_SIZE);
201 asm volatile("dsb st");
202 smp_kick_all_cpus(); /* only those with entry addr set will run */
York Sun89c717c2015-11-12 12:38:21 -0800203 /*
204 * When the first release command runs, all cores are set to go. Those
205 * without a valid entry address will be trapped by "wfe". "sev" kicks
206 * them off to check the address again. When set, they continue to run.
207 */
208 asm volatile("sev");
York Sun56cc3db2014-09-08 12:20:00 -0700209
210 return 0;
211}