Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [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/kernel.h> |
| 36 | #include <linux/serial_8250.h> |
| 37 | #include <linux/pm.h> |
| 38 | |
Ralf Baechle | bdc92d74 | 2013-05-21 16:59:19 +0200 | [diff] [blame] | 39 | #include <asm/idle.h> |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 40 | #include <asm/reboot.h> |
| 41 | #include <asm/time.h> |
| 42 | #include <asm/bootinfo.h> |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 43 | |
| 44 | #include <asm/netlogic/interrupt.h> |
| 45 | #include <asm/netlogic/psb-bootinfo.h> |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame] | 46 | #include <asm/netlogic/haldefs.h> |
| 47 | #include <asm/netlogic/common.h> |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 48 | |
| 49 | #include <asm/netlogic/xlr/xlr.h> |
| 50 | #include <asm/netlogic/xlr/iomap.h> |
| 51 | #include <asm/netlogic/xlr/pic.h> |
| 52 | #include <asm/netlogic/xlr/gpio.h> |
Ganesan Ramalingam | ed21cfe | 2012-10-31 12:01:42 +0000 | [diff] [blame] | 53 | #include <asm/netlogic/xlr/fmn.h> |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 54 | |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame] | 55 | uint64_t nlm_io_base = DEFAULT_NETLOGIC_IO_BASE; |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 56 | struct psb_info nlm_prom_info; |
| 57 | |
Jayachandran C | 66d2998 | 2011-11-16 00:21:29 +0000 | [diff] [blame] | 58 | /* default to uniprocessor */ |
Jayachandran C | 77ae798 | 2012-10-31 12:01:39 +0000 | [diff] [blame] | 59 | unsigned int nlm_threads_per_core = 1; |
| 60 | struct nlm_soc_info nlm_nodes[NLM_NR_NODES]; |
Jayachandran C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 61 | cpumask_t nlm_cpumask = CPU_MASK_CPU0; |
Jayachandran C | 66d2998 | 2011-11-16 00:21:29 +0000 | [diff] [blame] | 62 | |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 63 | static void nlm_linux_exit(void) |
| 64 | { |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame] | 65 | uint64_t gpiobase; |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 66 | |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame] | 67 | gpiobase = nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET); |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 68 | /* trigger a chip reset by writing 1 to GPIO_SWRESET_REG */ |
Jayachandran C | c5a48ff | 2012-07-24 17:28:53 +0200 | [diff] [blame] | 69 | nlm_write_reg(gpiobase, GPIO_SWRESET_REG, 1); |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 70 | for ( ; ; ) |
| 71 | cpu_wait(); |
| 72 | } |
| 73 | |
| 74 | void __init plat_mem_setup(void) |
| 75 | { |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 76 | _machine_restart = (void (*)(char *))nlm_linux_exit; |
| 77 | _machine_halt = nlm_linux_exit; |
| 78 | pm_power_off = nlm_linux_exit; |
| 79 | } |
| 80 | |
| 81 | const char *get_system_type(void) |
| 82 | { |
| 83 | return "Netlogic XLR/XLS Series"; |
| 84 | } |
| 85 | |
Jayachandran C | 0c96540 | 2011-11-11 17:08:29 +0530 | [diff] [blame] | 86 | unsigned int nlm_get_cpu_frequency(void) |
| 87 | { |
| 88 | return (unsigned int)nlm_prom_info.cpu_frequency; |
| 89 | } |
| 90 | |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 91 | void __init prom_free_prom_memory(void) |
| 92 | { |
| 93 | /* Nothing yet */ |
| 94 | } |
| 95 | |
Ganesan Ramalingam | ed21cfe | 2012-10-31 12:01:42 +0000 | [diff] [blame] | 96 | void nlm_percpu_init(int hwcpuid) |
| 97 | { |
| 98 | if (hwcpuid % 4 == 0) |
| 99 | xlr_percpu_fmn_init(); |
| 100 | } |
| 101 | |
Jayachandran C | a74e335 | 2011-06-22 01:37:05 +0530 | [diff] [blame] | 102 | static void __init build_arcs_cmdline(int *argv) |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 103 | { |
| 104 | int i, remain, len; |
| 105 | char *arg; |
| 106 | |
| 107 | remain = sizeof(arcs_cmdline) - 1; |
| 108 | arcs_cmdline[0] = '\0'; |
| 109 | for (i = 0; argv[i] != 0; i++) { |
| 110 | arg = (char *)(long)argv[i]; |
| 111 | len = strlen(arg); |
| 112 | if (len + 1 > remain) |
| 113 | break; |
| 114 | strcat(arcs_cmdline, arg); |
| 115 | strcat(arcs_cmdline, " "); |
| 116 | remain -= len + 1; |
| 117 | } |
| 118 | |
| 119 | /* Add the default options here */ |
| 120 | if ((strstr(arcs_cmdline, "console=")) == NULL) { |
| 121 | arg = "console=ttyS0,38400 "; |
| 122 | len = strlen(arg); |
| 123 | if (len > remain) |
| 124 | goto fail; |
| 125 | strcat(arcs_cmdline, arg); |
| 126 | remain -= len; |
| 127 | } |
| 128 | #ifdef CONFIG_BLK_DEV_INITRD |
| 129 | if ((strstr(arcs_cmdline, "rdinit=")) == NULL) { |
| 130 | arg = "rdinit=/sbin/init "; |
| 131 | len = strlen(arg); |
| 132 | if (len > remain) |
| 133 | goto fail; |
| 134 | strcat(arcs_cmdline, arg); |
| 135 | remain -= len; |
| 136 | } |
| 137 | #endif |
| 138 | return; |
| 139 | fail: |
| 140 | panic("Cannot add %s, command line too big!", arg); |
| 141 | } |
| 142 | |
| 143 | static void prom_add_memory(void) |
| 144 | { |
| 145 | struct nlm_boot_mem_map *bootm; |
| 146 | u64 start, size; |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 147 | u64 pref_backup = 512; /* avoid pref walking beyond end */ |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 148 | int i; |
| 149 | |
| 150 | bootm = (void *)(long)nlm_prom_info.psb_mem_map; |
| 151 | for (i = 0; i < bootm->nr_map; i++) { |
| 152 | if (bootm->map[i].type != BOOT_MEM_RAM) |
| 153 | continue; |
| 154 | start = bootm->map[i].addr; |
| 155 | size = bootm->map[i].size; |
| 156 | |
| 157 | /* Work around for using bootloader mem */ |
| 158 | if (i == 0 && start == 0 && size == 0x0c000000) |
| 159 | size = 0x0ff00000; |
| 160 | |
| 161 | add_memory_region(start, size - pref_backup, BOOT_MEM_RAM); |
| 162 | } |
| 163 | } |
| 164 | |
Jayachandran C | 77ae798 | 2012-10-31 12:01:39 +0000 | [diff] [blame] | 165 | static void nlm_init_node(void) |
| 166 | { |
| 167 | struct nlm_soc_info *nodep; |
| 168 | |
| 169 | nodep = nlm_current_node(); |
| 170 | nodep->picbase = nlm_mmio_base(NETLOGIC_IO_PIC_OFFSET); |
| 171 | nodep->ebase = read_c0_ebase() & (~((1 << 12) - 1)); |
| 172 | spin_lock_init(&nodep->piclock); |
| 173 | } |
| 174 | |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 175 | void __init prom_init(void) |
| 176 | { |
Jayachandran C | 26f5ae8 | 2013-01-07 13:21:08 +0000 | [diff] [blame] | 177 | int *argv, *envp; /* passed as 32 bit ptrs */ |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 178 | struct psb_info *prom_infop; |
Jayachandran C | 571886b | 2013-06-10 06:41:02 +0000 | [diff] [blame] | 179 | void *reset_vec; |
Jayachandran C | 26f5ae8 | 2013-01-07 13:21:08 +0000 | [diff] [blame] | 180 | #ifdef CONFIG_SMP |
| 181 | int i; |
| 182 | #endif |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 183 | |
| 184 | /* truncate to 32 bit and sign extend all args */ |
| 185 | argv = (int *)(long)(int)fw_arg1; |
| 186 | envp = (int *)(long)(int)fw_arg2; |
| 187 | prom_infop = (struct psb_info *)(long)(int)fw_arg3; |
| 188 | |
| 189 | nlm_prom_info = *prom_infop; |
Jayachandran C | 77ae798 | 2012-10-31 12:01:39 +0000 | [diff] [blame] | 190 | nlm_init_node(); |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 191 | |
Jayachandran C | 571886b | 2013-06-10 06:41:02 +0000 | [diff] [blame] | 192 | /* Update reset entry point with CPU init code */ |
| 193 | reset_vec = (void *)CKSEG1ADDR(RESET_VEC_PHYS); |
Jayachandran C | 919f9ab | 2013-06-10 06:41:04 +0000 | [diff] [blame] | 194 | memset(reset_vec, 0, RESET_VEC_SIZE); |
Jayachandran C | 571886b | 2013-06-10 06:41:02 +0000 | [diff] [blame] | 195 | memcpy(reset_vec, (void *)nlm_reset_entry, |
| 196 | (nlm_reset_entry_end - nlm_reset_entry)); |
| 197 | |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 198 | build_arcs_cmdline(argv); |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 199 | prom_add_memory(); |
| 200 | |
| 201 | #ifdef CONFIG_SMP |
Jayachandran C | 2a37b1a | 2012-10-31 12:01:37 +0000 | [diff] [blame] | 202 | for (i = 0; i < 32; i++) |
| 203 | if (nlm_prom_info.online_cpu_map & (1 << i)) |
| 204 | cpumask_set_cpu(i, &nlm_cpumask); |
| 205 | nlm_wakeup_secondary_cpus(); |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 206 | register_smp_ops(&nlm_smp_ops); |
| 207 | #endif |
Ganesan Ramalingam | ed21cfe | 2012-10-31 12:01:42 +0000 | [diff] [blame] | 208 | xlr_board_info_setup(); |
| 209 | xlr_percpu_fmn_init(); |
Jayachandran C | 5c6425067 | 2011-05-07 01:36:40 +0530 | [diff] [blame] | 210 | } |