blob: e5f44d2605a83345b552ad89a8577a6e1faba939 [file] [log] [blame]
Jayachandran C65040e22011-11-16 00:21:28 +00001/*
2 * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
3 * reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the NetLogic
9 * license below:
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
Jayachandran C65040e22011-11-16 00:21:28 +000035#include <linux/kernel.h>
36#include <linux/threads.h>
37
38#include <asm/asm.h>
39#include <asm/asm-offsets.h>
40#include <asm/mipsregs.h>
41#include <asm/addrspace.h>
42#include <asm/string.h>
43
44#include <asm/netlogic/haldefs.h>
45#include <asm/netlogic/common.h>
46#include <asm/netlogic/mips-extns.h>
47
48#include <asm/netlogic/xlp-hal/iomap.h>
Jayachandran C65040e22011-11-16 00:21:28 +000049#include <asm/netlogic/xlp-hal/xlp.h>
Jayachandran Cd150cef2013-12-21 16:52:22 +053050#include <asm/netlogic/xlp-hal/pic.h>
Jayachandran C65040e22011-11-16 00:21:28 +000051#include <asm/netlogic/xlp-hal/sys.h>
52
Jayachandran Ccba3b642013-01-14 15:12:01 +000053static int xlp_wakeup_core(uint64_t sysbase, int node, int core)
Jayachandran C65040e22011-11-16 00:21:28 +000054{
Jayachandran C2a37b1a2012-10-31 12:01:37 +000055 uint32_t coremask, value;
Jayachandran C861c0562013-12-21 16:52:23 +053056 int count, resetreg;
Jayachandran C66d29982011-11-16 00:21:29 +000057
Jayachandran C2a37b1a2012-10-31 12:01:37 +000058 coremask = (1 << core);
Jayachandran C66d29982011-11-16 00:21:29 +000059
Jayachandran Cc49e42a2013-08-11 14:43:57 +053060 /* Enable CPU clock in case of 8xx/3xx */
61 if (!cpu_is_xlpii()) {
62 value = nlm_read_sys_reg(sysbase, SYS_CORE_DFS_DIS_CTRL);
63 value &= ~coremask;
64 nlm_write_sys_reg(sysbase, SYS_CORE_DFS_DIS_CTRL, value);
65 }
Jayachandran C65040e22011-11-16 00:21:28 +000066
Jayachandran C861c0562013-12-21 16:52:23 +053067 /* On 9XX, mark coherent first */
68 if (cpu_is_xlp9xx()) {
69 value = nlm_read_sys_reg(sysbase, SYS_9XX_CPU_NONCOHERENT_MODE);
70 value &= ~coremask;
71 nlm_write_sys_reg(sysbase, SYS_9XX_CPU_NONCOHERENT_MODE, value);
72 }
Jayachandran C65040e22011-11-16 00:21:28 +000073
Jayachandran C861c0562013-12-21 16:52:23 +053074 /* Remove CPU Reset */
75 resetreg = cpu_is_xlp9xx() ? SYS_9XX_CPU_RESET : SYS_CPU_RESET;
76 value = nlm_read_sys_reg(sysbase, resetreg);
77 value &= ~coremask;
78 nlm_write_sys_reg(sysbase, resetreg, value);
79
80 /* We are done on 9XX */
81 if (cpu_is_xlp9xx())
82 return 1;
83
84 /* Poll for CPU to mark itself coherent on other type of XLP */
Jayachandran C2a37b1a2012-10-31 12:01:37 +000085 count = 100000;
86 do {
87 value = nlm_read_sys_reg(sysbase, SYS_CPU_NONCOHERENT_MODE);
88 } while ((value & coremask) != 0 && --count > 0);
Jayachandran C65040e22011-11-16 00:21:28 +000089
Jayachandran C2a37b1a2012-10-31 12:01:37 +000090 return count != 0;
91}
Jayachandran C65040e22011-11-16 00:21:28 +000092
Jayachandran C4033d382013-06-10 06:41:07 +000093static int wait_for_cpus(int cpu, int bootcpu)
94{
95 volatile uint32_t *cpu_ready = nlm_get_boot_data(BOOT_CPU_READY);
96 int i, count, notready;
97
Jayachandran Ce92e1d02014-01-14 12:39:15 +010098 count = 0x800000;
Jayachandran C4033d382013-06-10 06:41:07 +000099 do {
100 notready = nlm_threads_per_core;
101 for (i = 0; i < nlm_threads_per_core; i++)
102 if (cpu_ready[cpu + i] || cpu == bootcpu)
103 --notready;
104 } while (notready != 0 && --count > 0);
105
106 return count != 0;
107}
108
Jayachandran C2a37b1a2012-10-31 12:01:37 +0000109static void xlp_enable_secondary_cores(const cpumask_t *wakeup_mask)
110{
Jayachandran C77ae7982012-10-31 12:01:39 +0000111 struct nlm_soc_info *nodep;
Jayachandran C861c0562013-12-21 16:52:23 +0530112 uint64_t syspcibase, fusebase;
Jayachandran Cdb038fe2013-12-21 16:52:18 +0530113 uint32_t syscoremask, mask, fusemask;
Jayachandran C4033d382013-06-10 06:41:07 +0000114 int core, n, cpu;
Jayachandran C66d29982011-11-16 00:21:29 +0000115
Jayachandran C77ae7982012-10-31 12:01:39 +0000116 for (n = 0; n < NLM_NR_NODES; n++) {
Jayachandran C861c0562013-12-21 16:52:23 +0530117 if (n != 0) {
118 /* check if node exists and is online */
119 if (cpu_is_xlp9xx()) {
120 int b = xlp9xx_get_socbus(n);
121 pr_info("Node %d SoC PCI bus %d.\n", n, b);
122 if (b == 0)
123 break;
124 } else {
125 syspcibase = nlm_get_sys_pcibase(n);
126 if (nlm_read_reg(syspcibase, 0) == 0xffffffff)
127 break;
128 }
129 nlm_node_init(n);
130 }
Jayachandran C2a37b1a2012-10-31 12:01:37 +0000131
Jayachandran Ccba3b642013-01-14 15:12:01 +0000132 /* read cores in reset from SYS */
Jayachandran C77ae7982012-10-31 12:01:39 +0000133 nodep = nlm_get_node(n);
Jayachandran Cdb038fe2013-12-21 16:52:18 +0530134
Jayachandran C861c0562013-12-21 16:52:23 +0530135 if (cpu_is_xlp9xx()) {
136 fusebase = nlm_get_fuse_regbase(n);
137 fusemask = nlm_read_reg(fusebase, FUSE_9XX_DEVCFG6);
Yonghong Song1c983982014-04-29 20:07:53 +0530138 switch (read_c0_prid() & PRID_IMP_MASK) {
139 case PRID_IMP_NETLOGIC_XLP5XX:
140 mask = 0xff;
141 break;
142 case PRID_IMP_NETLOGIC_XLP9XX:
143 default:
144 mask = 0xfffff;
145 break;
146 }
Jayachandran C861c0562013-12-21 16:52:23 +0530147 } else {
148 fusemask = nlm_read_sys_reg(nodep->sysbase,
149 SYS_EFUSE_DEVICE_CFG_STATUS0);
Jayachandran C5874743e2014-04-29 20:07:49 +0530150 switch (read_c0_prid() & PRID_IMP_MASK) {
Jayachandran C861c0562013-12-21 16:52:23 +0530151 case PRID_IMP_NETLOGIC_XLP3XX:
152 mask = 0xf;
153 break;
154 case PRID_IMP_NETLOGIC_XLP2XX:
155 mask = 0x3;
156 break;
157 case PRID_IMP_NETLOGIC_XLP8XX:
158 default:
159 mask = 0xff;
160 break;
161 }
Jayachandran Ccba3b642013-01-14 15:12:01 +0000162 }
Jayachandran C2a37b1a2012-10-31 12:01:37 +0000163
Jayachandran Cdb038fe2013-12-21 16:52:18 +0530164 /*
165 * Fused out cores are set in the fusemask, and the remaining
166 * cores are renumbered to range 0 .. nactive-1
167 */
168 syscoremask = (1 << hweight32(~fusemask & mask)) - 1;
169
Jayachandran C861c0562013-12-21 16:52:23 +0530170 pr_info("Node %d - SYS/FUSE coremask %x\n", n, syscoremask);
Jayachandran C98d48842013-12-21 16:52:26 +0530171 for (core = 0; core < nlm_cores_per_node(); core++) {
Jayachandran Ccba3b642013-01-14 15:12:01 +0000172 /* we will be on node 0 core 0 */
173 if (n == 0 && core == 0)
174 continue;
175
Jayachandran C2a37b1a2012-10-31 12:01:37 +0000176 /* see if the core exists */
177 if ((syscoremask & (1 << core)) == 0)
178 continue;
179
Jayachandran Ccba3b642013-01-14 15:12:01 +0000180 /* see if at least the first hw thread is enabled */
Jayachandran C98d48842013-12-21 16:52:26 +0530181 cpu = (n * nlm_cores_per_node() + core)
Jayachandran C77ae7982012-10-31 12:01:39 +0000182 * NLM_THREADS_PER_CORE;
183 if (!cpumask_test_cpu(cpu, wakeup_mask))
Jayachandran C2a37b1a2012-10-31 12:01:37 +0000184 continue;
185
186 /* wake up the core */
Jayachandran Ccba3b642013-01-14 15:12:01 +0000187 if (!xlp_wakeup_core(nodep->sysbase, n, core))
188 continue;
189
190 /* core is up */
191 nodep->coremask |= 1u << core;
192
Jayachandran C4033d382013-06-10 06:41:07 +0000193 /* spin until the hw threads sets their ready */
Jayachandran Ce92e1d02014-01-14 12:39:15 +0100194 if (!wait_for_cpus(cpu, 0))
195 pr_err("Node %d : timeout core %d\n", n, core);
Jayachandran C2a37b1a2012-10-31 12:01:37 +0000196 }
Jayachandran C65040e22011-11-16 00:21:28 +0000197 }
198}
199
Jayachandran C2a37b1a2012-10-31 12:01:37 +0000200void xlp_wakeup_secondary_cpus()
Jayachandran C65040e22011-11-16 00:21:28 +0000201{
Jayachandran C66d29982011-11-16 00:21:29 +0000202 /*
203 * In case of u-boot, the secondaries are in reset
204 * first wakeup core 0 threads
205 */
206 xlp_boot_core0_siblings();
Jayachandran Ce92e1d02014-01-14 12:39:15 +0100207 if (!wait_for_cpus(0, 0))
208 pr_err("Node 0 : timeout core 0\n");
Jayachandran C65040e22011-11-16 00:21:28 +0000209
Jayachandran C66d29982011-11-16 00:21:29 +0000210 /* now get other cores out of reset */
Jayachandran C2a37b1a2012-10-31 12:01:37 +0000211 xlp_enable_secondary_cores(&nlm_cpumask);
Jayachandran C65040e22011-11-16 00:21:28 +0000212}