Jayachandran C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 1 | /* |
| 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 C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 35 | #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 C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 49 | #include <asm/netlogic/xlp-hal/xlp.h> |
Jayachandran C | d150cef | 2013-12-21 16:52:22 +0530 | [diff] [blame] | 50 | #include <asm/netlogic/xlp-hal/pic.h> |
Jayachandran C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 51 | #include <asm/netlogic/xlp-hal/sys.h> |
| 52 | |
Jayachandran C | cba3b64 | 2013-01-14 15:12:01 +0000 | [diff] [blame] | 53 | static int xlp_wakeup_core(uint64_t sysbase, int node, int core) |
Jayachandran C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 54 | { |
Jayachandran C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 55 | uint32_t coremask, value; |
Jayachandran C | 861c056 | 2013-12-21 16:52:23 +0530 | [diff] [blame] | 56 | int count, resetreg; |
Jayachandran C | 66d2998 | 2011-11-16 00:21:29 +0000 | [diff] [blame] | 57 | |
Jayachandran C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 58 | coremask = (1 << core); |
Jayachandran C | 66d2998 | 2011-11-16 00:21:29 +0000 | [diff] [blame] | 59 | |
Jayachandran C | c49e42a | 2013-08-11 14:43:57 +0530 | [diff] [blame] | 60 | /* 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 C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 66 | |
Jayachandran C | 861c056 | 2013-12-21 16:52:23 +0530 | [diff] [blame] | 67 | /* 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 C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 73 | |
Jayachandran C | 861c056 | 2013-12-21 16:52:23 +0530 | [diff] [blame] | 74 | /* 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 C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 85 | count = 100000; |
| 86 | do { |
| 87 | value = nlm_read_sys_reg(sysbase, SYS_CPU_NONCOHERENT_MODE); |
| 88 | } while ((value & coremask) != 0 && --count > 0); |
Jayachandran C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 89 | |
Jayachandran C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 90 | return count != 0; |
| 91 | } |
Jayachandran C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 92 | |
Jayachandran C | 4033d38 | 2013-06-10 06:41:07 +0000 | [diff] [blame] | 93 | static 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 C | e92e1d0 | 2014-01-14 12:39:15 +0100 | [diff] [blame] | 98 | count = 0x800000; |
Jayachandran C | 4033d38 | 2013-06-10 06:41:07 +0000 | [diff] [blame] | 99 | 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 C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 109 | static void xlp_enable_secondary_cores(const cpumask_t *wakeup_mask) |
| 110 | { |
Jayachandran C | 77ae798 | 2012-10-31 12:01:39 +0000 | [diff] [blame] | 111 | struct nlm_soc_info *nodep; |
Jayachandran C | 861c056 | 2013-12-21 16:52:23 +0530 | [diff] [blame] | 112 | uint64_t syspcibase, fusebase; |
Jayachandran C | db038fe | 2013-12-21 16:52:18 +0530 | [diff] [blame] | 113 | uint32_t syscoremask, mask, fusemask; |
Jayachandran C | 4033d38 | 2013-06-10 06:41:07 +0000 | [diff] [blame] | 114 | int core, n, cpu; |
Jayachandran C | 66d2998 | 2011-11-16 00:21:29 +0000 | [diff] [blame] | 115 | |
Jayachandran C | 77ae798 | 2012-10-31 12:01:39 +0000 | [diff] [blame] | 116 | for (n = 0; n < NLM_NR_NODES; n++) { |
Jayachandran C | 861c056 | 2013-12-21 16:52:23 +0530 | [diff] [blame] | 117 | 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 C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 131 | |
Jayachandran C | cba3b64 | 2013-01-14 15:12:01 +0000 | [diff] [blame] | 132 | /* read cores in reset from SYS */ |
Jayachandran C | 77ae798 | 2012-10-31 12:01:39 +0000 | [diff] [blame] | 133 | nodep = nlm_get_node(n); |
Jayachandran C | db038fe | 2013-12-21 16:52:18 +0530 | [diff] [blame] | 134 | |
Jayachandran C | 861c056 | 2013-12-21 16:52:23 +0530 | [diff] [blame] | 135 | if (cpu_is_xlp9xx()) { |
| 136 | fusebase = nlm_get_fuse_regbase(n); |
| 137 | fusemask = nlm_read_reg(fusebase, FUSE_9XX_DEVCFG6); |
Yonghong Song | 1c98398 | 2014-04-29 20:07:53 +0530 | [diff] [blame] | 138 | 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 C | 861c056 | 2013-12-21 16:52:23 +0530 | [diff] [blame] | 147 | } else { |
| 148 | fusemask = nlm_read_sys_reg(nodep->sysbase, |
| 149 | SYS_EFUSE_DEVICE_CFG_STATUS0); |
Jayachandran C | 5874743e | 2014-04-29 20:07:49 +0530 | [diff] [blame] | 150 | switch (read_c0_prid() & PRID_IMP_MASK) { |
Jayachandran C | 861c056 | 2013-12-21 16:52:23 +0530 | [diff] [blame] | 151 | 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 C | cba3b64 | 2013-01-14 15:12:01 +0000 | [diff] [blame] | 162 | } |
Jayachandran C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 163 | |
Jayachandran C | db038fe | 2013-12-21 16:52:18 +0530 | [diff] [blame] | 164 | /* |
| 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 C | 861c056 | 2013-12-21 16:52:23 +0530 | [diff] [blame] | 170 | pr_info("Node %d - SYS/FUSE coremask %x\n", n, syscoremask); |
Jayachandran C | 98d4884 | 2013-12-21 16:52:26 +0530 | [diff] [blame] | 171 | for (core = 0; core < nlm_cores_per_node(); core++) { |
Jayachandran C | cba3b64 | 2013-01-14 15:12:01 +0000 | [diff] [blame] | 172 | /* we will be on node 0 core 0 */ |
| 173 | if (n == 0 && core == 0) |
| 174 | continue; |
| 175 | |
Jayachandran C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 176 | /* see if the core exists */ |
| 177 | if ((syscoremask & (1 << core)) == 0) |
| 178 | continue; |
| 179 | |
Jayachandran C | cba3b64 | 2013-01-14 15:12:01 +0000 | [diff] [blame] | 180 | /* see if at least the first hw thread is enabled */ |
Jayachandran C | 98d4884 | 2013-12-21 16:52:26 +0530 | [diff] [blame] | 181 | cpu = (n * nlm_cores_per_node() + core) |
Jayachandran C | 77ae798 | 2012-10-31 12:01:39 +0000 | [diff] [blame] | 182 | * NLM_THREADS_PER_CORE; |
| 183 | if (!cpumask_test_cpu(cpu, wakeup_mask)) |
Jayachandran C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 184 | continue; |
| 185 | |
| 186 | /* wake up the core */ |
Jayachandran C | cba3b64 | 2013-01-14 15:12:01 +0000 | [diff] [blame] | 187 | if (!xlp_wakeup_core(nodep->sysbase, n, core)) |
| 188 | continue; |
| 189 | |
| 190 | /* core is up */ |
| 191 | nodep->coremask |= 1u << core; |
| 192 | |
Jayachandran C | 4033d38 | 2013-06-10 06:41:07 +0000 | [diff] [blame] | 193 | /* spin until the hw threads sets their ready */ |
Jayachandran C | e92e1d0 | 2014-01-14 12:39:15 +0100 | [diff] [blame] | 194 | if (!wait_for_cpus(cpu, 0)) |
| 195 | pr_err("Node %d : timeout core %d\n", n, core); |
Jayachandran C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 196 | } |
Jayachandran C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
Jayachandran C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 200 | void xlp_wakeup_secondary_cpus() |
Jayachandran C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 201 | { |
Jayachandran C | 66d2998 | 2011-11-16 00:21:29 +0000 | [diff] [blame] | 202 | /* |
| 203 | * In case of u-boot, the secondaries are in reset |
| 204 | * first wakeup core 0 threads |
| 205 | */ |
| 206 | xlp_boot_core0_siblings(); |
Jayachandran C | e92e1d0 | 2014-01-14 12:39:15 +0100 | [diff] [blame] | 207 | if (!wait_for_cpus(0, 0)) |
| 208 | pr_err("Node 0 : timeout core 0\n"); |
Jayachandran C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 209 | |
Jayachandran C | 66d2998 | 2011-11-16 00:21:29 +0000 | [diff] [blame] | 210 | /* now get other cores out of reset */ |
Jayachandran C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 211 | xlp_enable_secondary_cores(&nlm_cpumask); |
Jayachandran C | 65040e2 | 2011-11-16 00:21:28 +0000 | [diff] [blame] | 212 | } |