[PATCH] ocfs2: zero_user_page conversion
[wrt350n-kernel.git] / arch / mips / sibyte / cfe / setup.c
blob51898dd1304a85ad95f76665b3ee69b88368c306
1 /*
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>
22 #include <linux/mm.h>
23 #include <linux/blkdev.h>
24 #include <linux/bootmem.h>
25 #include <linux/pm.h>
26 #include <linux/smp.h>
28 #include <asm/bootinfo.h>
29 #include <asm/reboot.h>
30 #include <asm/sibyte/board.h>
32 #include "cfe_api.h"
33 #include "cfe_error.h"
35 /* Max ram addressable in 32-bit segments */
36 #ifdef CONFIG_64BIT
37 #define MAX_RAM_SIZE (~0ULL)
38 #else
39 #ifdef CONFIG_HIGHMEM
40 #ifdef CONFIG_64BIT_PHYS_ADDR
41 #define MAX_RAM_SIZE (~0ULL)
42 #else
43 #define MAX_RAM_SIZE (0xffffffffULL)
44 #endif
45 #else
46 #define MAX_RAM_SIZE (0x1fffffffULL)
47 #endif
48 #endif
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;
55 int cfe_cons_handle;
57 #ifdef CONFIG_BLK_DEV_INITRD
58 extern unsigned long initrd_start, initrd_end;
59 #endif
61 #ifdef CONFIG_KGDB
62 extern int kgdb_port;
63 #endif
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 */
73 if (!reboot_smp) {
74 /* Get CPU 0 to do the cfe_exit */
75 reboot_smp = 1;
76 smp_call_function(cfe_linux_exit, arg, 1, 0);
78 } else {
79 printk("Passing control back to CFE...\n");
80 cfe_exit(warm, 0);
81 printk("cfe_exit returned??\n");
83 while (1);
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 */
103 int mem_flags = 0;
104 unsigned int idx;
105 int rd_flag;
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);
112 if (initrd_start &&
113 ((initrd_pstart > MAX_RAM_SIZE)
114 || (initrd_pend > MAX_RAM_SIZE))) {
115 panic("initrd out of addressable memory");
118 #endif /* INITRD */
120 for (idx = 0; cfe_enummem(idx, mem_flags, &addr, &size, &type) != CFE_ERR_NOMORE;
121 idx++) {
122 rd_flag = 0;
123 if (type == CFE_MI_AVAILABLE) {
125 * See if this block contains (any portion of) the
126 * ramdisk
128 #ifdef CONFIG_BLK_DEV_INITRD
129 if (initrd_start) {
130 if ((initrd_pstart > addr) &&
131 (initrd_pstart < (addr + size))) {
132 add_memory_region(addr,
133 initrd_pstart - addr,
134 BOOT_MEM_RAM);
135 rd_flag = 1;
137 if ((initrd_pend > addr) &&
138 (initrd_pend < (addr + size))) {
139 add_memory_region(initrd_pend,
140 (addr + size) - initrd_pend,
141 BOOT_MEM_RAM);
142 rd_flag = 1;
145 #endif
146 if (!rd_flag) {
147 if (addr > MAX_RAM_SIZE)
148 continue;
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
156 * prefetch distance.
158 if (size > 512)
159 size -= 512;
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
170 while(1);
174 #ifdef CONFIG_BLK_DEV_INITRD
175 if (initrd_start) {
176 add_memory_region(initrd_pstart, initrd_pend - initrd_pstart,
177 BOOT_MEM_RESERVED);
179 #endif
182 #ifdef CONFIG_BLK_DEV_INITRD
183 static int __init initrd_setup(char *str)
185 char rdarg[64];
186 int idx;
187 char *tmp, *endptr;
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];
196 rdarg[idx] = 0;
197 str = rdarg;
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++) {
204 if (!*tmp) {
205 goto fail;
208 *tmp = 0;
209 tmp++;
210 if (!*tmp) {
211 goto fail;
213 initrd_size = simple_strtoul(str, &endptr, 16);
214 if (*endptr) {
215 *(tmp-1) = '@';
216 goto fail;
218 *(tmp-1) = '@';
219 initrd_start = simple_strtoul(tmp, &endptr, 16);
220 if (*endptr) {
221 goto fail;
223 initrd_end = initrd_start + initrd_size;
224 printk("Found initrd of %lx@%lx\n", initrd_size, initrd_start);
225 return 1;
226 fail:
227 printk("Bad initrd argument. Disabling initrd\n");
228 initrd_start = 0;
229 initrd_end = 0;
230 return 1;
233 #endif
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;
242 int argc = fw_arg0;
243 char **envp = (char **) fw_arg2;
244 int *prom_vec = (int *) fw_arg3;
245 #ifdef CONFIG_KGDB
246 char *arg;
247 #endif
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)
257 if (argc < 0) {
258 cfe_handle = (uint64_t)(long)argc;
259 cfe_ept = (long)envp;
260 cfe_eptseal = (uint32_t)(unsigned long)prom_vec;
261 } else {
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
266 * the seal.
268 cfe_handle = (uint64_t)(long)prom_vec;
269 cfe_ept = (uint64_t)((int32_t)0x9fc00500);
270 cfe_eptseal = CFE_EPTSEAL;
271 } else {
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.");
285 while (1) ;
287 cfe_init(cfe_handle, cfe_ept);
289 * Get the handle for (at least) prom_putchar, possibly for
290 * boot console
292 cfe_cons_handle = cfe_getstdhandle(CFE_STDHANDLE_CONSOLE);
293 if (cfe_getenv("LINUX_CMDLINE", arcs_cmdline, CL_SIZE) < 0) {
294 if (argc < 0) {
296 * It's OK for direct boot to not provide a
297 * command line
299 strcpy(arcs_cmdline, "root=/dev/ram0 ");
300 #ifdef CONFIG_SIBYTE_PTSWARM
301 strcat(arcs_cmdline, "console=ttyS0,115200 ");
302 #endif
303 } else {
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.");
307 while (1) ;
311 #ifdef CONFIG_KGDB
312 if ((arg = strstr(arcs_cmdline,"kgdb=duart")) != NULL)
313 kgdb_port = (arg[10] == '0') ? 0 : 1;
314 else
315 kgdb_port = 1;
316 #endif
318 #ifdef CONFIG_BLK_DEV_INITRD
320 char *ptr;
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 == ' ') {
325 ptr++;
327 if (!strncmp(ptr, "initrd=", 7)) {
328 initrd_setup(ptr+7);
329 break;
330 } else {
331 while (*ptr && (*ptr != ' ')) {
332 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;
343 prom_meminit();
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)
353 int ret;
355 while ((ret = cfe_write(cfe_cons_handle, &c, 1)) == 0)