]> git.ipfire.org Git - people/ms/linux.git/blame - arch/mips/sibyte/common/cfe.c
mm: remove include/linux/bootmem.h
[people/ms/linux.git] / arch / mips / sibyte / common / cfe.c
CommitLineData
1da177e4
LT
1/*
2 * Copyright (C) 2000, 2001, 2002, 2003 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
1da177e4
LT
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/linkage.h>
22#include <linux/mm.h>
23#include <linux/blkdev.h>
57c8a661 24#include <linux/memblock.h>
fcdb27ad 25#include <linux/pm.h>
1da177e4
LT
26#include <linux/smp.h>
27
28#include <asm/bootinfo.h>
29#include <asm/reboot.h>
5c93316c 30#include <asm/setup.h>
1da177e4 31#include <asm/sibyte/board.h>
87353d8a 32#include <asm/smp-ops.h>
1da177e4 33
df78b5c8
AJ
34#include <asm/fw/cfe/cfe_api.h>
35#include <asm/fw/cfe/cfe_error.h>
1da177e4
LT
36
37/* Max ram addressable in 32-bit segments */
875d43e7 38#ifdef CONFIG_64BIT
1da177e4
LT
39#define MAX_RAM_SIZE (~0ULL)
40#else
41#ifdef CONFIG_HIGHMEM
34adb28d 42#ifdef CONFIG_PHYS_ADDR_T_64BIT
1da177e4
LT
43#define MAX_RAM_SIZE (~0ULL)
44#else
45#define MAX_RAM_SIZE (0xffffffffULL)
46#endif
47#else
48#define MAX_RAM_SIZE (0x1fffffffULL)
49#endif
50#endif
51
52#define SIBYTE_MAX_MEM_REGIONS 8
15d45cce
RB
53phys_addr_t board_mem_region_addrs[SIBYTE_MAX_MEM_REGIONS];
54phys_addr_t board_mem_region_sizes[SIBYTE_MAX_MEM_REGIONS];
1da177e4
LT
55unsigned int board_mem_region_count;
56
57int cfe_cons_handle;
58
59#ifdef CONFIG_BLK_DEV_INITRD
60extern unsigned long initrd_start, initrd_end;
61#endif
62
b3f6df9f 63static void __noreturn cfe_linux_exit(void *arg)
1da177e4
LT
64{
65 int warm = *(int *)arg;
66
67 if (smp_processor_id()) {
68 static int reboot_smp;
69
70 /* Don't repeat the process from another CPU */
71 if (!reboot_smp) {
72 /* Get CPU 0 to do the cfe_exit */
73 reboot_smp = 1;
8691e5a8 74 smp_call_function(cfe_linux_exit, arg, 0);
1da177e4
LT
75 }
76 } else {
77 printk("Passing control back to CFE...\n");
78 cfe_exit(warm, 0);
79 printk("cfe_exit returned??\n");
80 }
81 while (1);
82}
83
b3f6df9f 84static void __noreturn cfe_linux_restart(char *command)
1da177e4
LT
85{
86 static const int zero;
87
88 cfe_linux_exit((void *)&zero);
89}
90
b3f6df9f 91static void __noreturn cfe_linux_halt(void)
1da177e4
LT
92{
93 static const int one = 1;
94
95 cfe_linux_exit((void *)&one);
96}
97
98static __init void prom_meminit(void)
99{
34adb28d 100 u64 addr, size, type; /* regardless of PHYS_ADDR_T_64BIT */
1da177e4
LT
101 int mem_flags = 0;
102 unsigned int idx;
103 int rd_flag;
104#ifdef CONFIG_BLK_DEV_INITRD
105 unsigned long initrd_pstart;
106 unsigned long initrd_pend;
107
108 initrd_pstart = CPHYSADDR(initrd_start);
109 initrd_pend = CPHYSADDR(initrd_end);
110 if (initrd_start &&
111 ((initrd_pstart > MAX_RAM_SIZE)
112 || (initrd_pend > MAX_RAM_SIZE))) {
113 panic("initrd out of addressable memory");
114 }
115
116#endif /* INITRD */
117
118 for (idx = 0; cfe_enummem(idx, mem_flags, &addr, &size, &type) != CFE_ERR_NOMORE;
119 idx++) {
120 rd_flag = 0;
121 if (type == CFE_MI_AVAILABLE) {
122 /*
123 * See if this block contains (any portion of) the
124 * ramdisk
125 */
126#ifdef CONFIG_BLK_DEV_INITRD
127 if (initrd_start) {
128 if ((initrd_pstart > addr) &&
129 (initrd_pstart < (addr + size))) {
130 add_memory_region(addr,
70342287
RB
131 initrd_pstart - addr,
132 BOOT_MEM_RAM);
1da177e4
LT
133 rd_flag = 1;
134 }
135 if ((initrd_pend > addr) &&
136 (initrd_pend < (addr + size))) {
137 add_memory_region(initrd_pend,
138 (addr + size) - initrd_pend,
139 BOOT_MEM_RAM);
140 rd_flag = 1;
141 }
142 }
143#endif
144 if (!rd_flag) {
145 if (addr > MAX_RAM_SIZE)
146 continue;
147 if (addr+size > MAX_RAM_SIZE)
148 size = MAX_RAM_SIZE - (addr+size) + 1;
149 /*
150 * memcpy/__copy_user prefetch, which
151 * will cause a bus error for
152 * KSEG/KUSEG addrs not backed by RAM.
153 * Hence, reserve some padding for the
154 * prefetch distance.
155 */
156 if (size > 512)
157 size -= 512;
158 add_memory_region(addr, size, BOOT_MEM_RAM);
159 }
160 board_mem_region_addrs[board_mem_region_count] = addr;
161 board_mem_region_sizes[board_mem_region_count] = size;
162 board_mem_region_count++;
163 if (board_mem_region_count ==
164 SIBYTE_MAX_MEM_REGIONS) {
165 /*
166 * Too many regions. Need to configure more
167 */
168 while(1);
169 }
170 }
171 }
172#ifdef CONFIG_BLK_DEV_INITRD
173 if (initrd_start) {
174 add_memory_region(initrd_pstart, initrd_pend - initrd_pstart,
175 BOOT_MEM_RESERVED);
176 }
177#endif
178}
179
180#ifdef CONFIG_BLK_DEV_INITRD
181static int __init initrd_setup(char *str)
182{
183 char rdarg[64];
184 int idx;
185 char *tmp, *endptr;
186 unsigned long initrd_size;
187
188 /* Make a copy of the initrd argument so we can smash it up here */
189 for (idx = 0; idx < sizeof(rdarg)-1; idx++) {
190 if (!str[idx] || (str[idx] == ' ')) break;
191 rdarg[idx] = str[idx];
192 }
193
194 rdarg[idx] = 0;
195 str = rdarg;
196
197 /*
198 *Initrd location comes in the form "<hex size of ramdisk in bytes>@<location in memory>"
70342287 199 * e.g. initrd=3abfd@80010000. This is set up by the loader.
1da177e4
LT
200 */
201 for (tmp = str; *tmp != '@'; tmp++) {
202 if (!*tmp) {
203 goto fail;
204 }
205 }
206 *tmp = 0;
207 tmp++;
208 if (!*tmp) {
209 goto fail;
210 }
211 initrd_size = simple_strtoul(str, &endptr, 16);
212 if (*endptr) {
213 *(tmp-1) = '@';
214 goto fail;
215 }
216 *(tmp-1) = '@';
217 initrd_start = simple_strtoul(tmp, &endptr, 16);
218 if (*endptr) {
219 goto fail;
220 }
221 initrd_end = initrd_start + initrd_size;
36a88530 222 printk("Found initrd of %lx@%lx\n", initrd_size, initrd_start);
1da177e4
LT
223 return 1;
224 fail:
36a88530 225 printk("Bad initrd argument. Disabling initrd\n");
1da177e4
LT
226 initrd_start = 0;
227 initrd_end = 0;
228 return 1;
229}
230
231#endif
232
ff2c8252
MR
233extern const struct plat_smp_ops sb_smp_ops;
234extern const struct plat_smp_ops bcm1480_smp_ops;
87353d8a 235
1da177e4
LT
236/*
237 * prom_init is called just after the cpu type is determined, from setup_arch()
238 */
239void __init prom_init(void)
240{
241 uint64_t cfe_ept, cfe_handle;
242 unsigned int cfe_eptseal;
243 int argc = fw_arg0;
244 char **envp = (char **) fw_arg2;
245 int *prom_vec = (int *) fw_arg3;
1da177e4
LT
246
247 _machine_restart = cfe_linux_restart;
70342287 248 _machine_halt = cfe_linux_halt;
fcdb27ad 249 pm_power_off = cfe_linux_halt;
1da177e4
LT
250
251 /*
252 * Check if a loader was used; if NOT, the 4 arguments are
253 * what CFE gives us (handle, 0, EPT and EPTSEAL)
254 */
255 if (argc < 0) {
256 cfe_handle = (uint64_t)(long)argc;
257 cfe_ept = (long)envp;
258 cfe_eptseal = (uint32_t)(unsigned long)prom_vec;
259 } else {
260 if ((int32_t)(long)prom_vec < 0) {
261 /*
262 * Old loader; all it gives us is the handle,
263 * so use the "known" entrypoint and assume
264 * the seal.
265 */
266 cfe_handle = (uint64_t)(long)prom_vec;
267 cfe_ept = (uint64_t)((int32_t)0x9fc00500);
268 cfe_eptseal = CFE_EPTSEAL;
269 } else {
270 /*
271 * Newer loaders bundle the handle/ept/eptseal
272 * Note: prom_vec is in the loader's useg
273 * which is still alive in the TLB.
274 */
275 cfe_handle = (uint64_t)((int32_t *)prom_vec)[0];
276 cfe_ept = (uint64_t)((int32_t *)prom_vec)[2];
277 cfe_eptseal = (unsigned int)((uint32_t *)prom_vec)[3];
278 }
279 }
280 if (cfe_eptseal != CFE_EPTSEAL) {
281 /* too early for panic to do any good */
36a88530 282 printk("CFE's entrypoint seal doesn't match. Spinning.");
1da177e4
LT
283 while (1) ;
284 }
285 cfe_init(cfe_handle, cfe_ept);
42a3b4f2 286 /*
1da177e4
LT
287 * Get the handle for (at least) prom_putchar, possibly for
288 * boot console
289 */
290 cfe_cons_handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
7580c9c3 291 if (cfe_getenv("LINUX_CMDLINE", arcs_cmdline, COMMAND_LINE_SIZE) < 0) {
e082f188 292 if (argc >= 0) {
1da177e4
LT
293 /* The loader should have set the command line */
294 /* too early for panic to do any good */
36a88530 295 printk("LINUX_CMDLINE not defined in cfe.");
1da177e4
LT
296 while (1) ;
297 }
298 }
299
1da177e4
LT
300#ifdef CONFIG_BLK_DEV_INITRD
301 {
302 char *ptr;
70342287 303 /* Need to find out early whether we've got an initrd. So scan
1da177e4
LT
304 the list looking now */
305 for (ptr = arcs_cmdline; *ptr; ptr++) {
306 while (*ptr == ' ') {
307 ptr++;
308 }
309 if (!strncmp(ptr, "initrd=", 7)) {
310 initrd_setup(ptr+7);
311 break;
312 } else {
313 while (*ptr && (*ptr != ' ')) {
314 ptr++;
315 }
316 }
317 }
318 }
319#endif /* CONFIG_BLK_DEV_INITRD */
320
321 /* Not sure this is needed, but it's the safe way. */
7580c9c3 322 arcs_cmdline[COMMAND_LINE_SIZE-1] = 0;
1da177e4 323
1da177e4 324 prom_meminit();
87353d8a
RB
325
326#if defined(CONFIG_SIBYTE_BCM112X) || defined(CONFIG_SIBYTE_SB1250)
327 register_smp_ops(&sb_smp_ops);
328#endif
329#if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
330 register_smp_ops(&bcm1480_smp_ops);
331#endif
1da177e4
LT
332}
333
c44e8d5e 334void __init prom_free_prom_memory(void)
1da177e4
LT
335{
336 /* Not sure what I'm supposed to do here. Nothing, I think */
1da177e4
LT
337}
338
339void prom_putchar(char c)
340{
341 int ret;
342
343 while ((ret = cfe_write(cfe_cons_handle, &c, 1)) == 0)
344 ;
345}