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/config.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
23 #include <linux/blkdev.h>
24 #include <linux/bootmem.h>
25 #include <linux/smp.h>
27 #include <asm/bootinfo.h>
28 #include <asm/reboot.h>
29 #include <asm/sibyte/board.h>
32 #include "cfe_error.h"
34 /* Max ram addressable in 32-bit segments */
36 #define MAX_RAM_SIZE (~0ULL)
39 #ifdef CONFIG_64BIT_PHYS_ADDR
40 #define MAX_RAM_SIZE (~0ULL)
42 #define MAX_RAM_SIZE (0xffffffffULL)
45 #define MAX_RAM_SIZE (0x1fffffffULL)
49 #define SIBYTE_MAX_MEM_REGIONS 8
50 phys_t board_mem_region_addrs[SIBYTE_MAX_MEM_REGIONS];
51 phys_t board_mem_region_sizes[SIBYTE_MAX_MEM_REGIONS];
52 unsigned int board_mem_region_count;
56 #ifdef CONFIG_BLK_DEV_INITRD
57 extern unsigned long initrd_start, initrd_end;
58 extern void * __rd_start, * __rd_end;
62 static int reboot_smp = 0;
69 static void cfe_linux_exit(void)
72 if (smp_processor_id()) {
74 /* Don't repeat the process from another CPU */
77 /* Get CPU 0 to do the cfe_exit */
79 smp_call_function((void *)_machine_restart, NULL, 1, 0);
84 printk("passing control back to CFE\n");
86 printk("cfe_exit returned??\n");
90 static __init void prom_meminit(void)
92 u64 addr, size, type; /* regardless of 64BIT_PHYS_ADDR */
96 #ifdef CONFIG_BLK_DEV_INITRD
97 unsigned long initrd_pstart;
98 unsigned long initrd_pend;
100 #ifdef CONFIG_EMBEDDED_RAMDISK
101 /* If we're using an embedded ramdisk, then __rd_start and __rd_end
102 are defined by the linker to be on either side of the ramdisk
103 area. Otherwise, initrd_start should be defined by kernel command
105 if (initrd_start == 0) {
106 initrd_start = (unsigned long)&__rd_start;
107 initrd_end = (unsigned long)&__rd_end;
111 initrd_pstart = CPHYSADDR(initrd_start);
112 initrd_pend = CPHYSADDR(initrd_end);
114 ((initrd_pstart > MAX_RAM_SIZE)
115 || (initrd_pend > MAX_RAM_SIZE))) {
116 panic("initrd out of addressable memory");
121 for (idx = 0; cfe_enummem(idx, mem_flags, &addr, &size, &type) != CFE_ERR_NOMORE;
124 if (type == CFE_MI_AVAILABLE) {
126 * See if this block contains (any portion of) the
129 #ifdef CONFIG_BLK_DEV_INITRD
131 if ((initrd_pstart > addr) &&
132 (initrd_pstart < (addr + size))) {
133 add_memory_region(addr,
134 initrd_pstart - addr,
138 if ((initrd_pend > addr) &&
139 (initrd_pend < (addr + size))) {
140 add_memory_region(initrd_pend,
141 (addr + size) - initrd_pend,
148 if (addr > MAX_RAM_SIZE)
150 if (addr+size > MAX_RAM_SIZE)
151 size = MAX_RAM_SIZE - (addr+size) + 1;
153 * memcpy/__copy_user prefetch, which
154 * will cause a bus error for
155 * KSEG/KUSEG addrs not backed by RAM.
156 * Hence, reserve some padding for the
161 add_memory_region(addr, size, BOOT_MEM_RAM);
163 board_mem_region_addrs[board_mem_region_count] = addr;
164 board_mem_region_sizes[board_mem_region_count] = size;
165 board_mem_region_count++;
166 if (board_mem_region_count ==
167 SIBYTE_MAX_MEM_REGIONS) {
169 * Too many regions. Need to configure more
175 #ifdef CONFIG_BLK_DEV_INITRD
177 add_memory_region(initrd_pstart, initrd_pend - initrd_pstart,
183 #ifdef CONFIG_BLK_DEV_INITRD
184 static int __init initrd_setup(char *str)
189 unsigned long initrd_size;
191 /* Make a copy of the initrd argument so we can smash it up here */
192 for (idx = 0; idx < sizeof(rdarg)-1; idx++) {
193 if (!str[idx] || (str[idx] == ' ')) break;
194 rdarg[idx] = str[idx];
201 *Initrd location comes in the form "<hex size of ramdisk in bytes>@<location in memory>"
202 * e.g. initrd=3abfd@80010000. This is set up by the loader.
204 for (tmp = str; *tmp != '@'; tmp++) {
214 initrd_size = simple_strtoul(str, &endptr, 16);
220 initrd_start = simple_strtoul(tmp, &endptr, 16);
224 initrd_end = initrd_start + initrd_size;
225 prom_printf("Found initrd of %lx@%lx\n", initrd_size, initrd_start);
228 prom_printf("Bad initrd argument. Disabling initrd\n");
237 * prom_init is called just after the cpu type is determined, from setup_arch()
239 void __init prom_init(void)
241 uint64_t cfe_ept, cfe_handle;
242 unsigned int cfe_eptseal;
244 char **envp = (char **) fw_arg2;
245 int *prom_vec = (int *) fw_arg3;
250 _machine_restart = (void (*)(char *))cfe_linux_exit;
251 _machine_halt = cfe_linux_exit;
252 _machine_power_off = cfe_linux_exit;
255 * Check if a loader was used; if NOT, the 4 arguments are
256 * what CFE gives us (handle, 0, EPT and EPTSEAL)
259 cfe_handle = (uint64_t)(long)argc;
260 cfe_ept = (long)envp;
261 cfe_eptseal = (uint32_t)(unsigned long)prom_vec;
263 if ((int32_t)(long)prom_vec < 0) {
265 * Old loader; all it gives us is the handle,
266 * so use the "known" entrypoint and assume
269 cfe_handle = (uint64_t)(long)prom_vec;
270 cfe_ept = (uint64_t)((int32_t)0x9fc00500);
271 cfe_eptseal = CFE_EPTSEAL;
274 * Newer loaders bundle the handle/ept/eptseal
275 * Note: prom_vec is in the loader's useg
276 * which is still alive in the TLB.
278 cfe_handle = (uint64_t)((int32_t *)prom_vec)[0];
279 cfe_ept = (uint64_t)((int32_t *)prom_vec)[2];
280 cfe_eptseal = (unsigned int)((uint32_t *)prom_vec)[3];
283 if (cfe_eptseal != CFE_EPTSEAL) {
284 /* too early for panic to do any good */
285 prom_printf("CFE's entrypoint seal doesn't match. Spinning.");
288 cfe_init(cfe_handle, cfe_ept);
290 * Get the handle for (at least) prom_putchar, possibly for
293 cfe_cons_handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
294 if (cfe_getenv("LINUX_CMDLINE", arcs_cmdline, CL_SIZE) < 0) {
297 * It's OK for direct boot to not provide a
300 strcpy(arcs_cmdline, "root=/dev/ram0 ");
301 #ifdef CONFIG_SIBYTE_PTSWARM
302 strcat(arcs_cmdline, "console=ttyS0,115200 ");
305 /* The loader should have set the command line */
306 /* too early for panic to do any good */
307 prom_printf("LINUX_CMDLINE not defined in cfe.");
313 if ((arg = strstr(arcs_cmdline,"kgdb=duart")) != NULL)
314 kgdb_port = (arg[10] == '0') ? 0 : 1;
319 #ifdef CONFIG_BLK_DEV_INITRD
322 /* Need to find out early whether we've got an initrd. So scan
323 the list looking now */
324 for (ptr = arcs_cmdline; *ptr; ptr++) {
325 while (*ptr == ' ') {
328 if (!strncmp(ptr, "initrd=", 7)) {
332 while (*ptr && (*ptr != ' ')) {
338 #endif /* CONFIG_BLK_DEV_INITRD */
340 /* Not sure this is needed, but it's the safe way. */
341 arcs_cmdline[CL_SIZE-1] = 0;
343 mips_machgroup = MACH_GROUP_SIBYTE;
347 unsigned long __init prom_free_prom_memory(void)
349 /* Not sure what I'm supposed to do here. Nothing, I think */
353 void prom_putchar(char c)
357 while ((ret = cfe_write(cfe_cons_handle, &c, 1)) == 0)