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 | |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/kernel.h> |
| 37 | #include <linux/threads.h> |
| 38 | |
| 39 | #include <asm/asm.h> |
| 40 | #include <asm/asm-offsets.h> |
| 41 | #include <asm/mipsregs.h> |
| 42 | #include <asm/addrspace.h> |
| 43 | #include <asm/string.h> |
| 44 | |
| 45 | #include <asm/netlogic/haldefs.h> |
| 46 | #include <asm/netlogic/common.h> |
| 47 | #include <asm/netlogic/mips-extns.h> |
| 48 | |
| 49 | #include <asm/netlogic/xlp-hal/iomap.h> |
| 50 | #include <asm/netlogic/xlp-hal/pic.h> |
| 51 | #include <asm/netlogic/xlp-hal/xlp.h> |
| 52 | #include <asm/netlogic/xlp-hal/sys.h> |
| 53 | |
| 54 | unsigned long secondary_entry; |
| 55 | uint32_t nlm_coremask; |
| 56 | unsigned int nlm_threads_per_core; |
| 57 | unsigned int nlm_threadmode; |
| 58 | |
| 59 | static void nlm_enable_secondary_cores(unsigned int cores_bitmap) |
| 60 | { |
| 61 | uint32_t core, value, coremask; |
| 62 | |
| 63 | for (core = 1; core < 8; core++) { |
| 64 | coremask = 1 << core; |
| 65 | if ((cores_bitmap & coremask) == 0) |
| 66 | continue; |
| 67 | |
| 68 | /* Enable CPU clock */ |
| 69 | value = nlm_read_sys_reg(nlm_sys_base, SYS_CORE_DFS_DIS_CTRL); |
| 70 | value &= ~coremask; |
| 71 | nlm_write_sys_reg(nlm_sys_base, SYS_CORE_DFS_DIS_CTRL, value); |
| 72 | |
| 73 | /* Remove CPU Reset */ |
| 74 | value = nlm_read_sys_reg(nlm_sys_base, SYS_CPU_RESET); |
| 75 | value &= ~coremask; |
| 76 | nlm_write_sys_reg(nlm_sys_base, SYS_CPU_RESET, value); |
| 77 | |
| 78 | /* Poll for CPU to mark itself coherent */ |
| 79 | do { |
| 80 | value = nlm_read_sys_reg(nlm_sys_base, |
| 81 | SYS_CPU_NONCOHERENT_MODE); |
| 82 | } while ((value & coremask) != 0); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | static void nlm_parse_cpumask(u32 cpu_mask) |
| 88 | { |
| 89 | uint32_t core0_thr_mask, core_thr_mask; |
| 90 | int i; |
| 91 | |
| 92 | core0_thr_mask = cpu_mask & 0xf; |
| 93 | switch (core0_thr_mask) { |
| 94 | case 1: |
| 95 | nlm_threads_per_core = 1; |
| 96 | nlm_threadmode = 0; |
| 97 | break; |
| 98 | case 3: |
| 99 | nlm_threads_per_core = 2; |
| 100 | nlm_threadmode = 2; |
| 101 | break; |
| 102 | case 0xf: |
| 103 | nlm_threads_per_core = 4; |
| 104 | nlm_threadmode = 3; |
| 105 | break; |
| 106 | default: |
| 107 | goto unsupp; |
| 108 | } |
| 109 | |
| 110 | /* Verify other cores CPU masks */ |
| 111 | nlm_coremask = 1; |
| 112 | for (i = 1; i < 8; i++) { |
| 113 | core_thr_mask = (cpu_mask >> (i * 4)) & 0xf; |
| 114 | if (core_thr_mask) { |
| 115 | if (core_thr_mask != core0_thr_mask) |
| 116 | goto unsupp; |
| 117 | nlm_coremask |= 1 << i; |
| 118 | } |
| 119 | } |
| 120 | return; |
| 121 | |
| 122 | unsupp: |
| 123 | panic("Unsupported CPU mask %x\n", cpu_mask); |
| 124 | } |
| 125 | |
| 126 | int __cpuinit nlm_wakeup_secondary_cpus(u32 wakeup_mask) |
| 127 | { |
| 128 | unsigned long reset_vec; |
| 129 | unsigned int *reset_data; |
| 130 | |
| 131 | /* Update reset entry point with CPU init code */ |
| 132 | reset_vec = CKSEG1ADDR(RESET_VEC_PHYS); |
| 133 | memcpy((void *)reset_vec, (void *)nlm_reset_entry, |
| 134 | (nlm_reset_entry_end - nlm_reset_entry)); |
| 135 | |
| 136 | /* verify the mask and setup core config variables */ |
| 137 | nlm_parse_cpumask(wakeup_mask); |
| 138 | |
| 139 | /* Setup CPU init parameters */ |
| 140 | reset_data = (unsigned int *)CKSEG1ADDR(RESET_DATA_PHYS); |
| 141 | reset_data[BOOT_THREAD_MODE] = nlm_threadmode; |
| 142 | |
| 143 | /* first wakeup core 0 siblings */ |
| 144 | nlm_boot_core0_siblings(); |
| 145 | |
| 146 | /* enable the reset of the cores */ |
| 147 | nlm_enable_secondary_cores(nlm_coremask); |
| 148 | return 0; |
| 149 | } |