blob: 295d5c77f02061c72bf2b5b4fb47dcadfe356146 [file] [log] [blame]
Paul Mackerras9b6b5632005-10-06 12:06:20 +10001/*
2 * Common prep/pmac/chrp boot and setup code.
3 */
4
5#include <linux/config.h>
6#include <linux/module.h>
7#include <linux/string.h>
8#include <linux/sched.h>
9#include <linux/init.h>
10#include <linux/kernel.h>
11#include <linux/reboot.h>
12#include <linux/delay.h>
13#include <linux/initrd.h>
14#include <linux/ide.h>
15#include <linux/tty.h>
16#include <linux/bootmem.h>
17#include <linux/seq_file.h>
18#include <linux/root_dev.h>
19#include <linux/cpu.h>
20#include <linux/console.h>
21
22#include <asm/residual.h>
23#include <asm/io.h>
24#include <asm/prom.h>
25#include <asm/processor.h>
26#include <asm/pgtable.h>
27#include <asm/bootinfo.h>
28#include <asm/setup.h>
29#include <asm/amigappc.h>
30#include <asm/smp.h>
31#include <asm/elf.h>
32#include <asm/cputable.h>
33#include <asm/bootx.h>
34#include <asm/btext.h>
35#include <asm/machdep.h>
36#include <asm/uaccess.h>
37#include <asm/system.h>
38#include <asm/pmac_feature.h>
39#include <asm/sections.h>
40#include <asm/nvram.h>
41#include <asm/xmon.h>
Kumar Gala6d7f58b2005-10-25 23:57:33 -050042#include <asm/time.h>
Paul Mackerras9b6b5632005-10-06 12:06:20 +100043
Paul Mackerras03501da2005-10-26 17:11:18 +100044#define DBG(fmt...)
45
Paul Mackerras9b6b5632005-10-06 12:06:20 +100046#if defined CONFIG_KGDB
47#include <asm/kgdb.h>
48#endif
49
50extern void platform_init(void);
51extern void bootx_init(unsigned long r4, unsigned long phys);
52
53extern void ppc6xx_idle(void);
54extern void power4_idle(void);
55
56boot_infos_t *boot_infos;
57struct ide_machdep_calls ppc_ide_md;
58
59/* Used with the BI_MEMSIZE bootinfo parameter to store the memory
60 size value reported by the boot loader. */
61unsigned long boot_mem_size;
62
63unsigned long ISA_DMA_THRESHOLD;
64unsigned int DMA_MODE_READ;
65unsigned int DMA_MODE_WRITE;
66
Paul Mackerrase574d232005-10-10 22:58:10 +100067int have_of = 1;
68
Paul Mackerras9b6b5632005-10-06 12:06:20 +100069#ifdef CONFIG_PPC_MULTIPLATFORM
70int _machine = 0;
71
72extern void prep_init(void);
73extern void pmac_init(void);
74extern void chrp_init(void);
75
76dev_t boot_dev;
77#endif /* CONFIG_PPC_MULTIPLATFORM */
78
79#ifdef CONFIG_MAGIC_SYSRQ
80unsigned long SYSRQ_KEY = 0x54;
81#endif /* CONFIG_MAGIC_SYSRQ */
82
83#ifdef CONFIG_VGA_CONSOLE
84unsigned long vgacon_remap_base;
85#endif
86
87struct machdep_calls ppc_md;
Paul Mackerrase574d232005-10-10 22:58:10 +100088EXPORT_SYMBOL(ppc_md);
Paul Mackerras9b6b5632005-10-06 12:06:20 +100089
90/*
91 * These are used in binfmt_elf.c to put aux entries on the stack
92 * for each elf executable being started.
93 */
94int dcache_bsize;
95int icache_bsize;
96int ucache_bsize;
97
98#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
99 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
100struct screen_info screen_info = {
101 0, 25, /* orig-x, orig-y */
102 0, /* unused */
103 0, /* orig-video-page */
104 0, /* orig-video-mode */
105 80, /* orig-video-cols */
106 0,0,0, /* ega_ax, ega_bx, ega_cx */
107 25, /* orig-video-lines */
108 1, /* orig-video-isVGA */
109 16 /* orig-video-points */
110};
111#endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
112
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000113/*
114 * We're called here very early in the boot. We determine the machine
115 * type and call the appropriate low-level setup functions.
116 * -- Cort <cort@fsmlabs.com>
117 *
118 * Note that the kernel may be running at an address which is different
119 * from the address that it was linked at, so we must use RELOC/PTRRELOC
120 * to access static data (including strings). -- paulus
121 */
122unsigned long __init early_init(unsigned long dt_ptr)
123{
124 unsigned long offset = reloc_offset();
125
Paul Mackerrasdd1843432005-10-17 20:13:47 +1000126 /* First zero the BSS -- use memset_io, some platforms don't have
127 * caches on yet */
128 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
129
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000130 /*
131 * Identify the CPU type and fix up code sections
132 * that depend on which cpu we have.
133 */
134 identify_cpu(offset, 0);
135 do_cpu_ftr_fixups(offset);
136
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000137 return KERNELBASE + offset;
138}
139
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000140#ifdef CONFIG_PPC_MULTIPLATFORM
141/*
142 * The PPC_MULTIPLATFORM version of platform_init...
143 */
144void __init platform_init(void)
145{
146 /* if we didn't get any bootinfo telling us what we are... */
147 if (_machine == 0) {
148 /* prep boot loader tells us if we're prep or not */
149 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
150 _machine = _MACH_prep;
151 }
152
153#ifdef CONFIG_PPC_PREP
154 /* not much more to do here, if prep */
155 if (_machine == _MACH_prep) {
156 prep_init();
157 return;
158 }
159#endif
160
161#ifdef CONFIG_ADB
162 if (strstr(cmd_line, "adb_sync")) {
163 extern int __adb_probe_sync;
164 __adb_probe_sync = 1;
165 }
166#endif /* CONFIG_ADB */
167
168 switch (_machine) {
169#ifdef CONFIG_PPC_PMAC
170 case _MACH_Pmac:
171 pmac_init();
172 break;
173#endif
174#ifdef CONFIG_PPC_CHRP
175 case _MACH_chrp:
176 chrp_init();
177 break;
178#endif
179 }
180}
Paul Mackerras03501da2005-10-26 17:11:18 +1000181#endif
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000182
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000183/*
184 * Find out what kind of machine we're on and save any data we need
185 * from the early boot process (devtree is copied on pmac by prom_init()).
186 * This is called very early on the boot process, after a minimal
187 * MMU environment has been set up but before MMU_init is called.
188 */
189void __init machine_init(unsigned long dt_ptr, unsigned long phys)
190{
191 early_init_devtree(__va(dt_ptr));
192
193#ifdef CONFIG_CMDLINE
194 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
195#endif /* CONFIG_CMDLINE */
196
Paul Mackerras35499c02005-10-22 16:02:39 +1000197 platform_init();
198
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000199#ifdef CONFIG_6xx
200 ppc_md.power_save = ppc6xx_idle;
201#endif
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000202
203 if (ppc_md.progress)
204 ppc_md.progress("id mach(): done", 0x200);
205}
206
207#ifdef CONFIG_BOOKE_WDT
208/* Checks wdt=x and wdt_period=xx command-line option */
209int __init early_parse_wdt(char *p)
210{
211 if (p && strncmp(p, "0", 1) != 0)
212 booke_wdt_enabled = 1;
213
214 return 0;
215}
216early_param("wdt", early_parse_wdt);
217
218int __init early_parse_wdt_period (char *p)
219{
220 if (p)
221 booke_wdt_period = simple_strtoul(p, NULL, 0);
222
223 return 0;
224}
225early_param("wdt_period", early_parse_wdt_period);
226#endif /* CONFIG_BOOKE_WDT */
227
228/* Checks "l2cr=xxxx" command-line option */
229int __init ppc_setup_l2cr(char *str)
230{
231 if (cpu_has_feature(CPU_FTR_L2CR)) {
232 unsigned long val = simple_strtoul(str, NULL, 0);
233 printk(KERN_INFO "l2cr set to %lx\n", val);
234 _set_L2CR(0); /* force invalidate by disable cache */
235 _set_L2CR(val); /* and enable it */
236 }
237 return 1;
238}
239__setup("l2cr=", ppc_setup_l2cr);
240
241#ifdef CONFIG_GENERIC_NVRAM
242
243/* Generic nvram hooks used by drivers/char/gen_nvram.c */
244unsigned char nvram_read_byte(int addr)
245{
246 if (ppc_md.nvram_read_val)
247 return ppc_md.nvram_read_val(addr);
248 return 0xff;
249}
250EXPORT_SYMBOL(nvram_read_byte);
251
252void nvram_write_byte(unsigned char val, int addr)
253{
254 if (ppc_md.nvram_write_val)
255 ppc_md.nvram_write_val(addr, val);
256}
257EXPORT_SYMBOL(nvram_write_byte);
258
259void nvram_sync(void)
260{
261 if (ppc_md.nvram_sync)
262 ppc_md.nvram_sync();
263}
264EXPORT_SYMBOL(nvram_sync);
265
266#endif /* CONFIG_NVRAM */
267
268static struct cpu cpu_devices[NR_CPUS];
269
270int __init ppc_init(void)
271{
272 int i;
273
274 /* clear the progress line */
275 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
276
277 /* register CPU devices */
278 for (i = 0; i < NR_CPUS; i++)
279 if (cpu_possible(i))
280 register_cpu(&cpu_devices[i], i, NULL);
281
282 /* call platform init */
283 if (ppc_md.init != NULL) {
284 ppc_md.init();
285 }
286 return 0;
287}
288
289arch_initcall(ppc_init);
290
291/* Warning, IO base is not yet inited */
292void __init setup_arch(char **cmdline_p)
293{
294 extern char *klimit;
295 extern void do_init_bootmem(void);
296
297 /* so udelay does something sensible, assume <= 1000 bogomips */
298 loops_per_jiffy = 500000000 / HZ;
299
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000300 unflatten_device_tree();
301 finish_device_tree();
302
Paul Mackerras30cd4a42005-10-17 19:20:46 +1000303#ifdef CONFIG_BOOTX_TEXT
304 init_boot_display();
305#endif
306
Paul Mackerras03501da2005-10-26 17:11:18 +1000307#ifdef CONFIG_PPC_PMAC
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000308 /* This could be called "early setup arch", it must be done
309 * now because xmon need it
310 */
311 if (_machine == _MACH_Pmac)
312 pmac_feature_init(); /* New cool way */
313#endif
314
315#ifdef CONFIG_XMON
316 xmon_map_scc();
317 if (strstr(cmd_line, "xmon"))
318 xmon(NULL);
319#endif /* CONFIG_XMON */
320 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
321
322#if defined(CONFIG_KGDB)
323 if (ppc_md.kgdb_map_scc)
324 ppc_md.kgdb_map_scc();
325 set_debug_traps();
326 if (strstr(cmd_line, "gdb")) {
327 if (ppc_md.progress)
328 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
329 printk("kgdb breakpoint activated\n");
330 breakpoint();
331 }
332#endif
333
334 /*
335 * Set cache line size based on type of cpu as a default.
336 * Systems with OF can look in the properties on the cpu node(s)
337 * for a possibly more accurate value.
338 */
339 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
340 dcache_bsize = cur_cpu_spec->dcache_bsize;
341 icache_bsize = cur_cpu_spec->icache_bsize;
342 ucache_bsize = 0;
343 } else
344 ucache_bsize = dcache_bsize = icache_bsize
345 = cur_cpu_spec->dcache_bsize;
346
347 /* reboot on panic */
348 panic_timeout = 180;
349
350 init_mm.start_code = PAGE_OFFSET;
351 init_mm.end_code = (unsigned long) _etext;
352 init_mm.end_data = (unsigned long) _edata;
353 init_mm.brk = (unsigned long) klimit;
354
355 /* Save unparsed command line copy for /proc/cmdline */
356 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
357 *cmdline_p = cmd_line;
358
359 parse_early_param();
360
361 /* set up the bootmem stuff with available memory */
362 do_init_bootmem();
363 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
364
365#ifdef CONFIG_PPC_OCP
366 /* Initialize OCP device list */
367 ocp_early_init();
368 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
369#endif
370
371#ifdef CONFIG_DUMMY_CONSOLE
372 conswitchp = &dummy_con;
373#endif
374
375 ppc_md.setup_arch();
376 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
377
378 paging_init();
379
380 /* this is for modules since _machine can be a define -- Cort */
381 ppc_md.ppc_machine = _machine;
382}