2 * Copyright (C) 2000, 2001, 2002, 2003 Broadcom Corporation
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.
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.
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.
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/linkage.h>
23 #include <linux/blkdev.h>
24 #include <linux/bootmem.h>
26 #include <linux/smp.h>
28 #include <asm/bootinfo.h>
29 #include <asm/reboot.h>
30 #include <asm/sibyte/board.h>
33 #include "cfe_error.h"
35 /* Max ram addressable in 32-bit segments */
37 #define MAX_RAM_SIZE (~0ULL)
40 #ifdef CONFIG_64BIT_PHYS_ADDR
41 #define MAX_RAM_SIZE (~0ULL)
43 #define MAX_RAM_SIZE (0xffffffffULL)
46 #define MAX_RAM_SIZE (0x1fffffffULL)
50 #define SIBYTE_MAX_MEM_REGIONS 8
51 phys_t board_mem_region_addrs
[SIBYTE_MAX_MEM_REGIONS
];
52 phys_t board_mem_region_sizes
[SIBYTE_MAX_MEM_REGIONS
];
53 unsigned int board_mem_region_count
;
57 #ifdef CONFIG_BLK_DEV_INITRD
58 extern unsigned long initrd_start
, initrd_end
;
65 static void __noreturn
cfe_linux_exit(void *arg
)
67 int warm
= *(int *)arg
;
69 if (smp_processor_id()) {
70 static int reboot_smp
;
72 /* Don't repeat the process from another CPU */
74 /* Get CPU 0 to do the cfe_exit */
76 smp_call_function(cfe_linux_exit
, arg
, 1, 0);
79 printk("Passing control back to CFE...\n");
81 printk("cfe_exit returned??\n");
86 static void __noreturn
cfe_linux_restart(char *command
)
88 static const int zero
;
90 cfe_linux_exit((void *)&zero
);
93 static void __noreturn
cfe_linux_halt(void)
95 static const int one
= 1;
97 cfe_linux_exit((void *)&one
);
100 static __init
void prom_meminit(void)
102 u64 addr
, size
, type
; /* regardless of 64BIT_PHYS_ADDR */
106 #ifdef CONFIG_BLK_DEV_INITRD
107 unsigned long initrd_pstart
;
108 unsigned long initrd_pend
;
110 initrd_pstart
= CPHYSADDR(initrd_start
);
111 initrd_pend
= CPHYSADDR(initrd_end
);
113 ((initrd_pstart
> MAX_RAM_SIZE
)
114 || (initrd_pend
> MAX_RAM_SIZE
))) {
115 panic("initrd out of addressable memory");
120 for (idx
= 0; cfe_enummem(idx
, mem_flags
, &addr
, &size
, &type
) != CFE_ERR_NOMORE
;
123 if (type
== CFE_MI_AVAILABLE
) {
125 * See if this block contains (any portion of) the
128 #ifdef CONFIG_BLK_DEV_INITRD
130 if ((initrd_pstart
> addr
) &&
131 (initrd_pstart
< (addr
+ size
))) {
132 add_memory_region(addr
,
133 initrd_pstart
- addr
,
137 if ((initrd_pend
> addr
) &&
138 (initrd_pend
< (addr
+ size
))) {
139 add_memory_region(initrd_pend
,
140 (addr
+ size
) - initrd_pend
,
147 if (addr
> MAX_RAM_SIZE
)
149 if (addr
+size
> MAX_RAM_SIZE
)
150 size
= MAX_RAM_SIZE
- (addr
+size
) + 1;
152 * memcpy/__copy_user prefetch, which
153 * will cause a bus error for
154 * KSEG/KUSEG addrs not backed by RAM.
155 * Hence, reserve some padding for the
160 add_memory_region(addr
, size
, BOOT_MEM_RAM
);
162 board_mem_region_addrs
[board_mem_region_count
] = addr
;
163 board_mem_region_sizes
[board_mem_region_count
] = size
;
164 board_mem_region_count
++;
165 if (board_mem_region_count
==
166 SIBYTE_MAX_MEM_REGIONS
) {
168 * Too many regions. Need to configure more
174 #ifdef CONFIG_BLK_DEV_INITRD
176 add_memory_region(initrd_pstart
, initrd_pend
- initrd_pstart
,
182 #ifdef CONFIG_BLK_DEV_INITRD
183 static int __init
initrd_setup(char *str
)
188 unsigned long initrd_size
;
190 /* Make a copy of the initrd argument so we can smash it up here */
191 for (idx
= 0; idx
< sizeof(rdarg
)-1; idx
++) {
192 if (!str
[idx
] || (str
[idx
] == ' ')) break;
193 rdarg
[idx
] = str
[idx
];
200 *Initrd location comes in the form "<hex size of ramdisk in bytes>@<location in memory>"
201 * e.g. initrd=3abfd@80010000. This is set up by the loader.
203 for (tmp
= str
; *tmp
!= '@'; tmp
++) {
213 initrd_size
= simple_strtoul(str
, &endptr
, 16);
219 initrd_start
= simple_strtoul(tmp
, &endptr
, 16);
223 initrd_end
= initrd_start
+ initrd_size
;
224 printk("Found initrd of %lx@%lx\n", initrd_size
, initrd_start
);
227 printk("Bad initrd argument. Disabling initrd\n");
236 * prom_init is called just after the cpu type is determined, from setup_arch()
238 void __init
prom_init(void)
240 uint64_t cfe_ept
, cfe_handle
;
241 unsigned int cfe_eptseal
;
243 char **envp
= (char **) fw_arg2
;
244 int *prom_vec
= (int *) fw_arg3
;
249 _machine_restart
= cfe_linux_restart
;
250 _machine_halt
= cfe_linux_halt
;
251 pm_power_off
= cfe_linux_halt
;
254 * Check if a loader was used; if NOT, the 4 arguments are
255 * what CFE gives us (handle, 0, EPT and EPTSEAL)
258 cfe_handle
= (uint64_t)(long)argc
;
259 cfe_ept
= (long)envp
;
260 cfe_eptseal
= (uint32_t)(unsigned long)prom_vec
;
262 if ((int32_t)(long)prom_vec
< 0) {
264 * Old loader; all it gives us is the handle,
265 * so use the "known" entrypoint and assume
268 cfe_handle
= (uint64_t)(long)prom_vec
;
269 cfe_ept
= (uint64_t)((int32_t)0x9fc00500);
270 cfe_eptseal
= CFE_EPTSEAL
;
273 * Newer loaders bundle the handle/ept/eptseal
274 * Note: prom_vec is in the loader's useg
275 * which is still alive in the TLB.
277 cfe_handle
= (uint64_t)((int32_t *)prom_vec
)[0];
278 cfe_ept
= (uint64_t)((int32_t *)prom_vec
)[2];
279 cfe_eptseal
= (unsigned int)((uint32_t *)prom_vec
)[3];
282 if (cfe_eptseal
!= CFE_EPTSEAL
) {
283 /* too early for panic to do any good */
284 printk("CFE's entrypoint seal doesn't match. Spinning.");
287 cfe_init(cfe_handle
, cfe_ept
);
289 * Get the handle for (at least) prom_putchar, possibly for
292 cfe_cons_handle
= cfe_getstdhandle(CFE_STDHANDLE_CONSOLE
);
293 if (cfe_getenv("LINUX_CMDLINE", arcs_cmdline
, CL_SIZE
) < 0) {
296 * It's OK for direct boot to not provide a
299 strcpy(arcs_cmdline
, "root=/dev/ram0 ");
300 #ifdef CONFIG_SIBYTE_PTSWARM
301 strcat(arcs_cmdline
, "console=ttyS0,115200 ");
304 /* The loader should have set the command line */
305 /* too early for panic to do any good */
306 printk("LINUX_CMDLINE not defined in cfe.");
312 if ((arg
= strstr(arcs_cmdline
,"kgdb=duart")) != NULL
)
313 kgdb_port
= (arg
[10] == '0') ? 0 : 1;
318 #ifdef CONFIG_BLK_DEV_INITRD
321 /* Need to find out early whether we've got an initrd. So scan
322 the list looking now */
323 for (ptr
= arcs_cmdline
; *ptr
; ptr
++) {
324 while (*ptr
== ' ') {
327 if (!strncmp(ptr
, "initrd=", 7)) {
331 while (*ptr
&& (*ptr
!= ' ')) {
337 #endif /* CONFIG_BLK_DEV_INITRD */
339 /* Not sure this is needed, but it's the safe way. */
340 arcs_cmdline
[CL_SIZE
-1] = 0;
342 mips_machgroup
= MACH_GROUP_SIBYTE
;
346 void __init
prom_free_prom_memory(void)
348 /* Not sure what I'm supposed to do here. Nothing, I think */
351 void prom_putchar(char c
)
355 while ((ret
= cfe_write(cfe_cons_handle
, &c
, 1)) == 0)