blob: 4e7f49d3d5a8105c45dd09a6b86999ed0506a7d7 [file] [log] [blame]
Jayachandran C5c642502011-05-07 01:36:40 +05301/*
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
39#include <asm/reboot.h>
40#include <asm/time.h>
41#include <asm/bootinfo.h>
Jayachandran C5c642502011-05-07 01:36:40 +053042
43#include <asm/netlogic/interrupt.h>
44#include <asm/netlogic/psb-bootinfo.h>
Jayachandran C0c965402011-11-11 17:08:29 +053045#include <asm/netlogic/haldefs.h>
46#include <asm/netlogic/common.h>
Jayachandran C5c642502011-05-07 01:36:40 +053047
48#include <asm/netlogic/xlr/xlr.h>
49#include <asm/netlogic/xlr/iomap.h>
50#include <asm/netlogic/xlr/pic.h>
51#include <asm/netlogic/xlr/gpio.h>
Ganesan Ramalingamed21cfe2012-10-31 12:01:42 +000052#include <asm/netlogic/xlr/fmn.h>
Jayachandran C5c642502011-05-07 01:36:40 +053053
Jayachandran C0c965402011-11-11 17:08:29 +053054uint64_t nlm_io_base = DEFAULT_NETLOGIC_IO_BASE;
Jayachandran C5c642502011-05-07 01:36:40 +053055struct psb_info nlm_prom_info;
56
Jayachandran C66d29982011-11-16 00:21:29 +000057/* default to uniprocessor */
Jayachandran C77ae7982012-10-31 12:01:39 +000058unsigned int nlm_threads_per_core = 1;
59struct nlm_soc_info nlm_nodes[NLM_NR_NODES];
Jayachandran C2a37b1a2012-10-31 12:01:37 +000060cpumask_t nlm_cpumask = CPU_MASK_CPU0;
Jayachandran C66d29982011-11-16 00:21:29 +000061
Jayachandran Ca74e3352011-06-22 01:37:05 +053062static void __init nlm_early_serial_setup(void)
Jayachandran C5c642502011-05-07 01:36:40 +053063{
64 struct uart_port s;
Jayachandran C0c965402011-11-11 17:08:29 +053065 unsigned long uart_base;
Jayachandran C5c642502011-05-07 01:36:40 +053066
Jayachandran C0c965402011-11-11 17:08:29 +053067 uart_base = (unsigned long)nlm_mmio_base(NETLOGIC_IO_UART_0_OFFSET);
Jayachandran C5c642502011-05-07 01:36:40 +053068 memset(&s, 0, sizeof(s));
69 s.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST;
70 s.iotype = UPIO_MEM32;
71 s.regshift = 2;
72 s.irq = PIC_UART_0_IRQ;
73 s.uartclk = PIC_CLKS_PER_SEC;
74 s.serial_in = nlm_xlr_uart_in;
75 s.serial_out = nlm_xlr_uart_out;
Jayachandran C0c965402011-11-11 17:08:29 +053076 s.mapbase = uart_base;
Jayachandran C5c642502011-05-07 01:36:40 +053077 s.membase = (unsigned char __iomem *)uart_base;
78 early_serial_setup(&s);
79}
80
81static void nlm_linux_exit(void)
82{
Jayachandran C0c965402011-11-11 17:08:29 +053083 uint64_t gpiobase;
Jayachandran C5c642502011-05-07 01:36:40 +053084
Jayachandran C0c965402011-11-11 17:08:29 +053085 gpiobase = nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET);
Jayachandran C5c642502011-05-07 01:36:40 +053086 /* trigger a chip reset by writing 1 to GPIO_SWRESET_REG */
Jayachandran Cc5a48ff2012-07-24 17:28:53 +020087 nlm_write_reg(gpiobase, GPIO_SWRESET_REG, 1);
Jayachandran C5c642502011-05-07 01:36:40 +053088 for ( ; ; )
89 cpu_wait();
90}
91
92void __init plat_mem_setup(void)
93{
94 panic_timeout = 5;
95 _machine_restart = (void (*)(char *))nlm_linux_exit;
96 _machine_halt = nlm_linux_exit;
97 pm_power_off = nlm_linux_exit;
98}
99
100const char *get_system_type(void)
101{
102 return "Netlogic XLR/XLS Series";
103}
104
Jayachandran C0c965402011-11-11 17:08:29 +0530105unsigned int nlm_get_cpu_frequency(void)
106{
107 return (unsigned int)nlm_prom_info.cpu_frequency;
108}
109
Jayachandran C5c642502011-05-07 01:36:40 +0530110void __init prom_free_prom_memory(void)
111{
112 /* Nothing yet */
113}
114
Ganesan Ramalingamed21cfe2012-10-31 12:01:42 +0000115void nlm_percpu_init(int hwcpuid)
116{
117 if (hwcpuid % 4 == 0)
118 xlr_percpu_fmn_init();
119}
120
Jayachandran Ca74e3352011-06-22 01:37:05 +0530121static void __init build_arcs_cmdline(int *argv)
Jayachandran C5c642502011-05-07 01:36:40 +0530122{
123 int i, remain, len;
124 char *arg;
125
126 remain = sizeof(arcs_cmdline) - 1;
127 arcs_cmdline[0] = '\0';
128 for (i = 0; argv[i] != 0; i++) {
129 arg = (char *)(long)argv[i];
130 len = strlen(arg);
131 if (len + 1 > remain)
132 break;
133 strcat(arcs_cmdline, arg);
134 strcat(arcs_cmdline, " ");
135 remain -= len + 1;
136 }
137
138 /* Add the default options here */
139 if ((strstr(arcs_cmdline, "console=")) == NULL) {
140 arg = "console=ttyS0,38400 ";
141 len = strlen(arg);
142 if (len > remain)
143 goto fail;
144 strcat(arcs_cmdline, arg);
145 remain -= len;
146 }
147#ifdef CONFIG_BLK_DEV_INITRD
148 if ((strstr(arcs_cmdline, "rdinit=")) == NULL) {
149 arg = "rdinit=/sbin/init ";
150 len = strlen(arg);
151 if (len > remain)
152 goto fail;
153 strcat(arcs_cmdline, arg);
154 remain -= len;
155 }
156#endif
157 return;
158fail:
159 panic("Cannot add %s, command line too big!", arg);
160}
161
162static void prom_add_memory(void)
163{
164 struct nlm_boot_mem_map *bootm;
165 u64 start, size;
166 u64 pref_backup = 512; /* avoid pref walking beyond end */
167 int i;
168
169 bootm = (void *)(long)nlm_prom_info.psb_mem_map;
170 for (i = 0; i < bootm->nr_map; i++) {
171 if (bootm->map[i].type != BOOT_MEM_RAM)
172 continue;
173 start = bootm->map[i].addr;
174 size = bootm->map[i].size;
175
176 /* Work around for using bootloader mem */
177 if (i == 0 && start == 0 && size == 0x0c000000)
178 size = 0x0ff00000;
179
180 add_memory_region(start, size - pref_backup, BOOT_MEM_RAM);
181 }
182}
183
Jayachandran C77ae7982012-10-31 12:01:39 +0000184static void nlm_init_node(void)
185{
186 struct nlm_soc_info *nodep;
187
188 nodep = nlm_current_node();
189 nodep->picbase = nlm_mmio_base(NETLOGIC_IO_PIC_OFFSET);
190 nodep->ebase = read_c0_ebase() & (~((1 << 12) - 1));
191 spin_lock_init(&nodep->piclock);
192}
193
Jayachandran C5c642502011-05-07 01:36:40 +0530194void __init prom_init(void)
195{
Jayachandran C2a37b1a2012-10-31 12:01:37 +0000196 int i, *argv, *envp; /* passed as 32 bit ptrs */
Jayachandran C5c642502011-05-07 01:36:40 +0530197 struct psb_info *prom_infop;
198
199 /* truncate to 32 bit and sign extend all args */
200 argv = (int *)(long)(int)fw_arg1;
201 envp = (int *)(long)(int)fw_arg2;
202 prom_infop = (struct psb_info *)(long)(int)fw_arg3;
203
204 nlm_prom_info = *prom_infop;
Jayachandran C77ae7982012-10-31 12:01:39 +0000205 nlm_init_node();
Jayachandran C5c642502011-05-07 01:36:40 +0530206
207 nlm_early_serial_setup();
208 build_arcs_cmdline(argv);
Jayachandran C5c642502011-05-07 01:36:40 +0530209 prom_add_memory();
210
211#ifdef CONFIG_SMP
Jayachandran C2a37b1a2012-10-31 12:01:37 +0000212 for (i = 0; i < 32; i++)
213 if (nlm_prom_info.online_cpu_map & (1 << i))
214 cpumask_set_cpu(i, &nlm_cpumask);
215 nlm_wakeup_secondary_cpus();
Jayachandran C5c642502011-05-07 01:36:40 +0530216 register_smp_ops(&nlm_smp_ops);
217#endif
Ganesan Ramalingamed21cfe2012-10-31 12:01:42 +0000218 xlr_board_info_setup();
219 xlr_percpu_fmn_init();
Jayachandran C5c642502011-05-07 01:36:40 +0530220}