1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
3*4882a593Smuzhiyun * reserved.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * This software is available to you under a choice of one of two
6*4882a593Smuzhiyun * licenses. You may choose to be licensed under the terms of the GNU
7*4882a593Smuzhiyun * General Public License (GPL) Version 2, available from the file
8*4882a593Smuzhiyun * COPYING in the main directory of this source tree, or the NetLogic
9*4882a593Smuzhiyun * license below:
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
12*4882a593Smuzhiyun * modification, are permitted provided that the following conditions
13*4882a593Smuzhiyun * are met:
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * 1. Redistributions of source code must retain the above copyright
16*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
17*4882a593Smuzhiyun * 2. Redistributions in binary form must reproduce the above copyright
18*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in
19*4882a593Smuzhiyun * the documentation and/or other materials provided with the
20*4882a593Smuzhiyun * distribution.
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
23*4882a593Smuzhiyun * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24*4882a593Smuzhiyun * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*4882a593Smuzhiyun * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
26*4882a593Smuzhiyun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27*4882a593Smuzhiyun * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28*4882a593Smuzhiyun * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29*4882a593Smuzhiyun * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30*4882a593Smuzhiyun * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31*4882a593Smuzhiyun * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32*4882a593Smuzhiyun * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*4882a593Smuzhiyun */
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun #include <linux/kernel.h>
36*4882a593Smuzhiyun #include <linux/serial_8250.h>
37*4882a593Smuzhiyun #include <linux/memblock.h>
38*4882a593Smuzhiyun #include <linux/pm.h>
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #include <asm/idle.h>
41*4882a593Smuzhiyun #include <asm/reboot.h>
42*4882a593Smuzhiyun #include <asm/time.h>
43*4882a593Smuzhiyun #include <asm/bootinfo.h>
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun #include <asm/netlogic/interrupt.h>
46*4882a593Smuzhiyun #include <asm/netlogic/psb-bootinfo.h>
47*4882a593Smuzhiyun #include <asm/netlogic/haldefs.h>
48*4882a593Smuzhiyun #include <asm/netlogic/common.h>
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun #include <asm/netlogic/xlr/xlr.h>
51*4882a593Smuzhiyun #include <asm/netlogic/xlr/iomap.h>
52*4882a593Smuzhiyun #include <asm/netlogic/xlr/pic.h>
53*4882a593Smuzhiyun #include <asm/netlogic/xlr/gpio.h>
54*4882a593Smuzhiyun #include <asm/netlogic/xlr/fmn.h>
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun uint64_t nlm_io_base = DEFAULT_NETLOGIC_IO_BASE;
57*4882a593Smuzhiyun struct psb_info nlm_prom_info;
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /* default to uniprocessor */
60*4882a593Smuzhiyun unsigned int nlm_threads_per_core = 1;
61*4882a593Smuzhiyun struct nlm_soc_info nlm_nodes[NLM_NR_NODES];
62*4882a593Smuzhiyun cpumask_t nlm_cpumask = CPU_MASK_CPU0;
63*4882a593Smuzhiyun
nlm_linux_exit(void)64*4882a593Smuzhiyun static void nlm_linux_exit(void)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun uint64_t gpiobase;
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun gpiobase = nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET);
69*4882a593Smuzhiyun /* trigger a chip reset by writing 1 to GPIO_SWRESET_REG */
70*4882a593Smuzhiyun nlm_write_reg(gpiobase, GPIO_SWRESET_REG, 1);
71*4882a593Smuzhiyun for ( ; ; )
72*4882a593Smuzhiyun cpu_wait();
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun
plat_mem_setup(void)75*4882a593Smuzhiyun void __init plat_mem_setup(void)
76*4882a593Smuzhiyun {
77*4882a593Smuzhiyun _machine_restart = (void (*)(char *))nlm_linux_exit;
78*4882a593Smuzhiyun _machine_halt = nlm_linux_exit;
79*4882a593Smuzhiyun pm_power_off = nlm_linux_exit;
80*4882a593Smuzhiyun }
81*4882a593Smuzhiyun
get_system_type(void)82*4882a593Smuzhiyun const char *get_system_type(void)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun return "Netlogic XLR/XLS Series";
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun
nlm_get_cpu_frequency(void)87*4882a593Smuzhiyun unsigned int nlm_get_cpu_frequency(void)
88*4882a593Smuzhiyun {
89*4882a593Smuzhiyun return (unsigned int)nlm_prom_info.cpu_frequency;
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun
prom_free_prom_memory(void)92*4882a593Smuzhiyun void __init prom_free_prom_memory(void)
93*4882a593Smuzhiyun {
94*4882a593Smuzhiyun /* Nothing yet */
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun
nlm_percpu_init(int hwcpuid)97*4882a593Smuzhiyun void nlm_percpu_init(int hwcpuid)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun if (hwcpuid % 4 == 0)
100*4882a593Smuzhiyun xlr_percpu_fmn_init();
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun
build_arcs_cmdline(int * argv)103*4882a593Smuzhiyun static void __init build_arcs_cmdline(int *argv)
104*4882a593Smuzhiyun {
105*4882a593Smuzhiyun int i, remain, len;
106*4882a593Smuzhiyun char *arg;
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun remain = sizeof(arcs_cmdline) - 1;
109*4882a593Smuzhiyun arcs_cmdline[0] = '\0';
110*4882a593Smuzhiyun for (i = 0; argv[i] != 0; i++) {
111*4882a593Smuzhiyun arg = (char *)(long)argv[i];
112*4882a593Smuzhiyun len = strlen(arg);
113*4882a593Smuzhiyun if (len + 1 > remain)
114*4882a593Smuzhiyun break;
115*4882a593Smuzhiyun strcat(arcs_cmdline, arg);
116*4882a593Smuzhiyun strcat(arcs_cmdline, " ");
117*4882a593Smuzhiyun remain -= len + 1;
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun /* Add the default options here */
121*4882a593Smuzhiyun if ((strstr(arcs_cmdline, "console=")) == NULL) {
122*4882a593Smuzhiyun arg = "console=ttyS0,38400 ";
123*4882a593Smuzhiyun len = strlen(arg);
124*4882a593Smuzhiyun if (len > remain)
125*4882a593Smuzhiyun goto fail;
126*4882a593Smuzhiyun strcat(arcs_cmdline, arg);
127*4882a593Smuzhiyun remain -= len;
128*4882a593Smuzhiyun }
129*4882a593Smuzhiyun #ifdef CONFIG_BLK_DEV_INITRD
130*4882a593Smuzhiyun if ((strstr(arcs_cmdline, "rdinit=")) == NULL) {
131*4882a593Smuzhiyun arg = "rdinit=/sbin/init ";
132*4882a593Smuzhiyun len = strlen(arg);
133*4882a593Smuzhiyun if (len > remain)
134*4882a593Smuzhiyun goto fail;
135*4882a593Smuzhiyun strcat(arcs_cmdline, arg);
136*4882a593Smuzhiyun remain -= len;
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun #endif
139*4882a593Smuzhiyun return;
140*4882a593Smuzhiyun fail:
141*4882a593Smuzhiyun panic("Cannot add %s, command line too big!", arg);
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun
prom_add_memory(void)144*4882a593Smuzhiyun static void prom_add_memory(void)
145*4882a593Smuzhiyun {
146*4882a593Smuzhiyun struct nlm_boot_mem_map *bootm;
147*4882a593Smuzhiyun u64 start, size;
148*4882a593Smuzhiyun u64 pref_backup = 512; /* avoid pref walking beyond end */
149*4882a593Smuzhiyun int i;
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun bootm = (void *)(long)nlm_prom_info.psb_mem_map;
152*4882a593Smuzhiyun for (i = 0; i < bootm->nr_map; i++) {
153*4882a593Smuzhiyun if (bootm->map[i].type != NLM_BOOT_MEM_RAM)
154*4882a593Smuzhiyun continue;
155*4882a593Smuzhiyun start = bootm->map[i].addr;
156*4882a593Smuzhiyun size = bootm->map[i].size;
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun /* Work around for using bootloader mem */
159*4882a593Smuzhiyun if (i == 0 && start == 0 && size == 0x0c000000)
160*4882a593Smuzhiyun size = 0x0ff00000;
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun memblock_add(start, size - pref_backup);
163*4882a593Smuzhiyun }
164*4882a593Smuzhiyun }
165*4882a593Smuzhiyun
nlm_init_node(void)166*4882a593Smuzhiyun static void nlm_init_node(void)
167*4882a593Smuzhiyun {
168*4882a593Smuzhiyun struct nlm_soc_info *nodep;
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun nodep = nlm_current_node();
171*4882a593Smuzhiyun nodep->picbase = nlm_mmio_base(NETLOGIC_IO_PIC_OFFSET);
172*4882a593Smuzhiyun nodep->ebase = read_c0_ebase() & MIPS_EBASE_BASE;
173*4882a593Smuzhiyun spin_lock_init(&nodep->piclock);
174*4882a593Smuzhiyun }
175*4882a593Smuzhiyun
prom_init(void)176*4882a593Smuzhiyun void __init prom_init(void)
177*4882a593Smuzhiyun {
178*4882a593Smuzhiyun int *argv, *envp; /* passed as 32 bit ptrs */
179*4882a593Smuzhiyun struct psb_info *prom_infop;
180*4882a593Smuzhiyun void *reset_vec;
181*4882a593Smuzhiyun #ifdef CONFIG_SMP
182*4882a593Smuzhiyun int i;
183*4882a593Smuzhiyun #endif
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun /* truncate to 32 bit and sign extend all args */
186*4882a593Smuzhiyun argv = (int *)(long)(int)fw_arg1;
187*4882a593Smuzhiyun envp = (int *)(long)(int)fw_arg2;
188*4882a593Smuzhiyun prom_infop = (struct psb_info *)(long)(int)fw_arg3;
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun nlm_prom_info = *prom_infop;
191*4882a593Smuzhiyun nlm_init_node();
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun /* Update reset entry point with CPU init code */
194*4882a593Smuzhiyun reset_vec = (void *)CKSEG1ADDR(RESET_VEC_PHYS);
195*4882a593Smuzhiyun memset(reset_vec, 0, RESET_VEC_SIZE);
196*4882a593Smuzhiyun memcpy(reset_vec, (void *)nlm_reset_entry,
197*4882a593Smuzhiyun (nlm_reset_entry_end - nlm_reset_entry));
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun build_arcs_cmdline(argv);
200*4882a593Smuzhiyun prom_add_memory();
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun #ifdef CONFIG_SMP
203*4882a593Smuzhiyun for (i = 0; i < 32; i++)
204*4882a593Smuzhiyun if (nlm_prom_info.online_cpu_map & (1 << i))
205*4882a593Smuzhiyun cpumask_set_cpu(i, &nlm_cpumask);
206*4882a593Smuzhiyun nlm_wakeup_secondary_cpus();
207*4882a593Smuzhiyun register_smp_ops(&nlm_smp_ops);
208*4882a593Smuzhiyun #endif
209*4882a593Smuzhiyun xlr_board_info_setup();
210*4882a593Smuzhiyun xlr_percpu_fmn_init();
211*4882a593Smuzhiyun }
212