blob: c98cfcc9cd9a9183f5dbe9f3b7fe4c527642ace1 [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>
Paul Mackerras9b6b5632005-10-06 12:06:20 +100027#include <asm/setup.h>
28#include <asm/amigappc.h>
29#include <asm/smp.h>
30#include <asm/elf.h>
31#include <asm/cputable.h>
32#include <asm/bootx.h>
33#include <asm/btext.h>
34#include <asm/machdep.h>
35#include <asm/uaccess.h>
36#include <asm/system.h>
37#include <asm/pmac_feature.h>
38#include <asm/sections.h>
39#include <asm/nvram.h>
40#include <asm/xmon.h>
Kumar Gala6d7f58b2005-10-25 23:57:33 -050041#include <asm/time.h>
Paul Mackerras9b6b5632005-10-06 12:06:20 +100042
Stephen Rothwell66ba1352005-11-09 11:01:06 +110043#include "setup.h"
44
Paul Mackerras03501da2005-10-26 17:11:18 +100045#define DBG(fmt...)
46
Paul Mackerras9b6b5632005-10-06 12:06:20 +100047#if defined CONFIG_KGDB
48#include <asm/kgdb.h>
49#endif
50
51extern void platform_init(void);
52extern void bootx_init(unsigned long r4, unsigned long phys);
53
54extern void ppc6xx_idle(void);
55extern void power4_idle(void);
56
57boot_infos_t *boot_infos;
58struct ide_machdep_calls ppc_ide_md;
59
Paul Mackerrasbbd0abd2005-10-26 21:45:56 +100060/* XXX should go elsewhere */
61int __irq_offset_value;
62EXPORT_SYMBOL(__irq_offset_value);
63
Paul Mackerras80579e12005-10-27 22:42:04 +100064int boot_cpuid;
65EXPORT_SYMBOL_GPL(boot_cpuid);
66int boot_cpuid_phys;
67
Paul Mackerras9b6b5632005-10-06 12:06:20 +100068unsigned long ISA_DMA_THRESHOLD;
69unsigned int DMA_MODE_READ;
70unsigned int DMA_MODE_WRITE;
71
Paul Mackerrase574d232005-10-10 22:58:10 +100072int have_of = 1;
73
Paul Mackerras9b6b5632005-10-06 12:06:20 +100074#ifdef CONFIG_PPC_MULTIPLATFORM
Paul Mackerras9b6b5632005-10-06 12:06:20 +100075extern void prep_init(void);
76extern void pmac_init(void);
77extern void chrp_init(void);
78
79dev_t boot_dev;
80#endif /* CONFIG_PPC_MULTIPLATFORM */
81
82#ifdef CONFIG_MAGIC_SYSRQ
83unsigned long SYSRQ_KEY = 0x54;
84#endif /* CONFIG_MAGIC_SYSRQ */
85
86#ifdef CONFIG_VGA_CONSOLE
87unsigned long vgacon_remap_base;
88#endif
89
90struct machdep_calls ppc_md;
Paul Mackerrase574d232005-10-10 22:58:10 +100091EXPORT_SYMBOL(ppc_md);
Paul Mackerras9b6b5632005-10-06 12:06:20 +100092
93/*
94 * These are used in binfmt_elf.c to put aux entries on the stack
95 * for each elf executable being started.
96 */
97int dcache_bsize;
98int icache_bsize;
99int ucache_bsize;
100
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000101/*
102 * We're called here very early in the boot. We determine the machine
103 * type and call the appropriate low-level setup functions.
104 * -- Cort <cort@fsmlabs.com>
105 *
106 * Note that the kernel may be running at an address which is different
107 * from the address that it was linked at, so we must use RELOC/PTRRELOC
108 * to access static data (including strings). -- paulus
109 */
110unsigned long __init early_init(unsigned long dt_ptr)
111{
112 unsigned long offset = reloc_offset();
113
Paul Mackerrasdd1843432005-10-17 20:13:47 +1000114 /* First zero the BSS -- use memset_io, some platforms don't have
115 * caches on yet */
116 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
117
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000118 /*
119 * Identify the CPU type and fix up code sections
120 * that depend on which cpu we have.
121 */
122 identify_cpu(offset, 0);
123 do_cpu_ftr_fixups(offset);
124
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000125 return KERNELBASE + offset;
126}
127
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000128#ifdef CONFIG_PPC_MULTIPLATFORM
129/*
130 * The PPC_MULTIPLATFORM version of platform_init...
131 */
132void __init platform_init(void)
133{
134 /* if we didn't get any bootinfo telling us what we are... */
135 if (_machine == 0) {
136 /* prep boot loader tells us if we're prep or not */
137 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
138 _machine = _MACH_prep;
139 }
140
141#ifdef CONFIG_PPC_PREP
142 /* not much more to do here, if prep */
143 if (_machine == _MACH_prep) {
144 prep_init();
145 return;
146 }
147#endif
148
149#ifdef CONFIG_ADB
150 if (strstr(cmd_line, "adb_sync")) {
151 extern int __adb_probe_sync;
152 __adb_probe_sync = 1;
153 }
154#endif /* CONFIG_ADB */
155
156 switch (_machine) {
157#ifdef CONFIG_PPC_PMAC
158 case _MACH_Pmac:
159 pmac_init();
160 break;
161#endif
162#ifdef CONFIG_PPC_CHRP
163 case _MACH_chrp:
164 chrp_init();
165 break;
166#endif
167 }
168}
Paul Mackerras03501da2005-10-26 17:11:18 +1000169#endif
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000170
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000171/*
172 * Find out what kind of machine we're on and save any data we need
173 * from the early boot process (devtree is copied on pmac by prom_init()).
174 * This is called very early on the boot process, after a minimal
175 * MMU environment has been set up but before MMU_init is called.
176 */
177void __init machine_init(unsigned long dt_ptr, unsigned long phys)
178{
179 early_init_devtree(__va(dt_ptr));
180
181#ifdef CONFIG_CMDLINE
182 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
183#endif /* CONFIG_CMDLINE */
184
Paul Mackerras35499c02005-10-22 16:02:39 +1000185 platform_init();
186
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000187#ifdef CONFIG_6xx
188 ppc_md.power_save = ppc6xx_idle;
189#endif
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000190
191 if (ppc_md.progress)
192 ppc_md.progress("id mach(): done", 0x200);
193}
194
195#ifdef CONFIG_BOOKE_WDT
196/* Checks wdt=x and wdt_period=xx command-line option */
197int __init early_parse_wdt(char *p)
198{
199 if (p && strncmp(p, "0", 1) != 0)
200 booke_wdt_enabled = 1;
201
202 return 0;
203}
204early_param("wdt", early_parse_wdt);
205
206int __init early_parse_wdt_period (char *p)
207{
208 if (p)
209 booke_wdt_period = simple_strtoul(p, NULL, 0);
210
211 return 0;
212}
213early_param("wdt_period", early_parse_wdt_period);
214#endif /* CONFIG_BOOKE_WDT */
215
216/* Checks "l2cr=xxxx" command-line option */
217int __init ppc_setup_l2cr(char *str)
218{
219 if (cpu_has_feature(CPU_FTR_L2CR)) {
220 unsigned long val = simple_strtoul(str, NULL, 0);
221 printk(KERN_INFO "l2cr set to %lx\n", val);
222 _set_L2CR(0); /* force invalidate by disable cache */
223 _set_L2CR(val); /* and enable it */
224 }
225 return 1;
226}
227__setup("l2cr=", ppc_setup_l2cr);
228
229#ifdef CONFIG_GENERIC_NVRAM
230
231/* Generic nvram hooks used by drivers/char/gen_nvram.c */
232unsigned char nvram_read_byte(int addr)
233{
234 if (ppc_md.nvram_read_val)
235 return ppc_md.nvram_read_val(addr);
236 return 0xff;
237}
238EXPORT_SYMBOL(nvram_read_byte);
239
240void nvram_write_byte(unsigned char val, int addr)
241{
242 if (ppc_md.nvram_write_val)
243 ppc_md.nvram_write_val(addr, val);
244}
245EXPORT_SYMBOL(nvram_write_byte);
246
247void nvram_sync(void)
248{
249 if (ppc_md.nvram_sync)
250 ppc_md.nvram_sync();
251}
252EXPORT_SYMBOL(nvram_sync);
253
254#endif /* CONFIG_NVRAM */
255
256static struct cpu cpu_devices[NR_CPUS];
257
258int __init ppc_init(void)
259{
260 int i;
261
262 /* clear the progress line */
263 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
264
265 /* register CPU devices */
266 for (i = 0; i < NR_CPUS; i++)
267 if (cpu_possible(i))
268 register_cpu(&cpu_devices[i], i, NULL);
269
270 /* call platform init */
271 if (ppc_md.init != NULL) {
272 ppc_md.init();
273 }
274 return 0;
275}
276
277arch_initcall(ppc_init);
278
279/* Warning, IO base is not yet inited */
280void __init setup_arch(char **cmdline_p)
281{
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000282 extern void do_init_bootmem(void);
283
284 /* so udelay does something sensible, assume <= 1000 bogomips */
285 loops_per_jiffy = 500000000 / HZ;
286
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000287 unflatten_device_tree();
David Woodhousea82765b2005-11-02 22:34:20 +0000288 check_for_initrd();
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000289 finish_device_tree();
290
Paul Mackerras5ad57072005-11-05 10:33:55 +1100291 smp_setup_cpu_maps();
292
Paul Mackerras30cd4a42005-10-17 19:20:46 +1000293#ifdef CONFIG_BOOTX_TEXT
294 init_boot_display();
295#endif
296
Paul Mackerras03501da2005-10-26 17:11:18 +1000297#ifdef CONFIG_PPC_PMAC
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000298 /* This could be called "early setup arch", it must be done
299 * now because xmon need it
300 */
301 if (_machine == _MACH_Pmac)
302 pmac_feature_init(); /* New cool way */
303#endif
304
Paul Mackerrasfca5dcd2005-11-08 22:55:08 +1100305#ifdef CONFIG_XMON_DEFAULT
306 xmon_init(1);
307#endif
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000308
309#if defined(CONFIG_KGDB)
310 if (ppc_md.kgdb_map_scc)
311 ppc_md.kgdb_map_scc();
312 set_debug_traps();
313 if (strstr(cmd_line, "gdb")) {
314 if (ppc_md.progress)
315 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
316 printk("kgdb breakpoint activated\n");
317 breakpoint();
318 }
319#endif
320
321 /*
322 * Set cache line size based on type of cpu as a default.
323 * Systems with OF can look in the properties on the cpu node(s)
324 * for a possibly more accurate value.
325 */
326 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
327 dcache_bsize = cur_cpu_spec->dcache_bsize;
328 icache_bsize = cur_cpu_spec->icache_bsize;
329 ucache_bsize = 0;
330 } else
331 ucache_bsize = dcache_bsize = icache_bsize
332 = cur_cpu_spec->dcache_bsize;
333
334 /* reboot on panic */
335 panic_timeout = 180;
336
337 init_mm.start_code = PAGE_OFFSET;
338 init_mm.end_code = (unsigned long) _etext;
339 init_mm.end_data = (unsigned long) _edata;
Paul Mackerras49b09852005-11-10 15:53:40 +1100340 init_mm.brk = klimit;
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000341
342 /* Save unparsed command line copy for /proc/cmdline */
343 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
344 *cmdline_p = cmd_line;
345
346 parse_early_param();
347
348 /* set up the bootmem stuff with available memory */
349 do_init_bootmem();
350 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
351
352#ifdef CONFIG_PPC_OCP
353 /* Initialize OCP device list */
354 ocp_early_init();
355 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
356#endif
357
358#ifdef CONFIG_DUMMY_CONSOLE
359 conswitchp = &dummy_con;
360#endif
361
362 ppc_md.setup_arch();
363 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
364
365 paging_init();
366
367 /* this is for modules since _machine can be a define -- Cort */
368 ppc_md.ppc_machine = _machine;
369}