Commit | Line | Data |
---|---|---|
5c642506 J |
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 | ||
39 | #include <asm/reboot.h> | |
40 | #include <asm/time.h> | |
41 | #include <asm/bootinfo.h> | |
5c642506 J |
42 | |
43 | #include <asm/netlogic/interrupt.h> | |
44 | #include <asm/netlogic/psb-bootinfo.h> | |
0c965407 J |
45 | #include <asm/netlogic/haldefs.h> |
46 | #include <asm/netlogic/common.h> | |
5c642506 J |
47 | |
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> | |
52 | ||
0c965407 J |
53 | uint64_t nlm_io_base = DEFAULT_NETLOGIC_IO_BASE; |
54 | uint64_t nlm_pic_base; | |
5c642506 J |
55 | struct psb_info nlm_prom_info; |
56 | ||
66d29985 J |
57 | unsigned long nlm_common_ebase = 0x0; |
58 | ||
59 | /* default to uniprocessor */ | |
2a37b1ae | 60 | uint32_t nlm_coremask = 1; |
66d29985 | 61 | int nlm_threads_per_core = 1; |
2a37b1ae | 62 | cpumask_t nlm_cpumask = CPU_MASK_CPU0; |
66d29985 | 63 | |
a74e3353 | 64 | static void __init nlm_early_serial_setup(void) |
5c642506 J |
65 | { |
66 | struct uart_port s; | |
0c965407 | 67 | unsigned long uart_base; |
5c642506 | 68 | |
0c965407 | 69 | uart_base = (unsigned long)nlm_mmio_base(NETLOGIC_IO_UART_0_OFFSET); |
5c642506 J |
70 | memset(&s, 0, sizeof(s)); |
71 | s.flags = ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST; | |
72 | s.iotype = UPIO_MEM32; | |
73 | s.regshift = 2; | |
74 | s.irq = PIC_UART_0_IRQ; | |
75 | s.uartclk = PIC_CLKS_PER_SEC; | |
76 | s.serial_in = nlm_xlr_uart_in; | |
77 | s.serial_out = nlm_xlr_uart_out; | |
0c965407 | 78 | s.mapbase = uart_base; |
5c642506 J |
79 | s.membase = (unsigned char __iomem *)uart_base; |
80 | early_serial_setup(&s); | |
81 | } | |
82 | ||
83 | static void nlm_linux_exit(void) | |
84 | { | |
0c965407 | 85 | uint64_t gpiobase; |
5c642506 | 86 | |
0c965407 | 87 | gpiobase = nlm_mmio_base(NETLOGIC_IO_GPIO_OFFSET); |
5c642506 | 88 | /* trigger a chip reset by writing 1 to GPIO_SWRESET_REG */ |
c5a48ff8 | 89 | nlm_write_reg(gpiobase, GPIO_SWRESET_REG, 1); |
5c642506 J |
90 | for ( ; ; ) |
91 | cpu_wait(); | |
92 | } | |
93 | ||
94 | void __init plat_mem_setup(void) | |
95 | { | |
96 | panic_timeout = 5; | |
97 | _machine_restart = (void (*)(char *))nlm_linux_exit; | |
98 | _machine_halt = nlm_linux_exit; | |
99 | pm_power_off = nlm_linux_exit; | |
100 | } | |
101 | ||
102 | const char *get_system_type(void) | |
103 | { | |
104 | return "Netlogic XLR/XLS Series"; | |
105 | } | |
106 | ||
0c965407 J |
107 | unsigned int nlm_get_cpu_frequency(void) |
108 | { | |
109 | return (unsigned int)nlm_prom_info.cpu_frequency; | |
110 | } | |
111 | ||
5c642506 J |
112 | void __init prom_free_prom_memory(void) |
113 | { | |
114 | /* Nothing yet */ | |
115 | } | |
116 | ||
a74e3353 | 117 | static void __init build_arcs_cmdline(int *argv) |
5c642506 J |
118 | { |
119 | int i, remain, len; | |
120 | char *arg; | |
121 | ||
122 | remain = sizeof(arcs_cmdline) - 1; | |
123 | arcs_cmdline[0] = '\0'; | |
124 | for (i = 0; argv[i] != 0; i++) { | |
125 | arg = (char *)(long)argv[i]; | |
126 | len = strlen(arg); | |
127 | if (len + 1 > remain) | |
128 | break; | |
129 | strcat(arcs_cmdline, arg); | |
130 | strcat(arcs_cmdline, " "); | |
131 | remain -= len + 1; | |
132 | } | |
133 | ||
134 | /* Add the default options here */ | |
135 | if ((strstr(arcs_cmdline, "console=")) == NULL) { | |
136 | arg = "console=ttyS0,38400 "; | |
137 | len = strlen(arg); | |
138 | if (len > remain) | |
139 | goto fail; | |
140 | strcat(arcs_cmdline, arg); | |
141 | remain -= len; | |
142 | } | |
143 | #ifdef CONFIG_BLK_DEV_INITRD | |
144 | if ((strstr(arcs_cmdline, "rdinit=")) == NULL) { | |
145 | arg = "rdinit=/sbin/init "; | |
146 | len = strlen(arg); | |
147 | if (len > remain) | |
148 | goto fail; | |
149 | strcat(arcs_cmdline, arg); | |
150 | remain -= len; | |
151 | } | |
152 | #endif | |
153 | return; | |
154 | fail: | |
155 | panic("Cannot add %s, command line too big!", arg); | |
156 | } | |
157 | ||
158 | static void prom_add_memory(void) | |
159 | { | |
160 | struct nlm_boot_mem_map *bootm; | |
161 | u64 start, size; | |
162 | u64 pref_backup = 512; /* avoid pref walking beyond end */ | |
163 | int i; | |
164 | ||
165 | bootm = (void *)(long)nlm_prom_info.psb_mem_map; | |
166 | for (i = 0; i < bootm->nr_map; i++) { | |
167 | if (bootm->map[i].type != BOOT_MEM_RAM) | |
168 | continue; | |
169 | start = bootm->map[i].addr; | |
170 | size = bootm->map[i].size; | |
171 | ||
172 | /* Work around for using bootloader mem */ | |
173 | if (i == 0 && start == 0 && size == 0x0c000000) | |
174 | size = 0x0ff00000; | |
175 | ||
176 | add_memory_region(start, size - pref_backup, BOOT_MEM_RAM); | |
177 | } | |
178 | } | |
179 | ||
180 | void __init prom_init(void) | |
181 | { | |
2a37b1ae | 182 | int i, *argv, *envp; /* passed as 32 bit ptrs */ |
5c642506 J |
183 | struct psb_info *prom_infop; |
184 | ||
185 | /* truncate to 32 bit and sign extend all args */ | |
186 | argv = (int *)(long)(int)fw_arg1; | |
187 | envp = (int *)(long)(int)fw_arg2; | |
188 | prom_infop = (struct psb_info *)(long)(int)fw_arg3; | |
189 | ||
190 | nlm_prom_info = *prom_infop; | |
0c965407 | 191 | nlm_pic_base = nlm_mmio_base(NETLOGIC_IO_PIC_OFFSET); |
5c642506 J |
192 | |
193 | nlm_early_serial_setup(); | |
194 | build_arcs_cmdline(argv); | |
195 | nlm_common_ebase = read_c0_ebase() & (~((1 << 12) - 1)); | |
196 | prom_add_memory(); | |
197 | ||
198 | #ifdef CONFIG_SMP | |
2a37b1ae J |
199 | for (i = 0; i < 32; i++) |
200 | if (nlm_prom_info.online_cpu_map & (1 << i)) | |
201 | cpumask_set_cpu(i, &nlm_cpumask); | |
202 | nlm_wakeup_secondary_cpus(); | |
5c642506 J |
203 | register_smp_ops(&nlm_smp_ops); |
204 | #endif | |
205 | } |