blob: db72a92943bf63e4cb9f1c1e583f027a6be06698 [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>
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +110042#include <asm/serial.h>
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +110043#include <asm/udbg.h>
Paul Mackerras9b6b5632005-10-06 12:06:20 +100044
Stephen Rothwell66ba1352005-11-09 11:01:06 +110045#include "setup.h"
46
Paul Mackerras03501da2005-10-26 17:11:18 +100047#define DBG(fmt...)
48
Paul Mackerras9b6b5632005-10-06 12:06:20 +100049#if defined CONFIG_KGDB
50#include <asm/kgdb.h>
51#endif
52
53extern void platform_init(void);
54extern void bootx_init(unsigned long r4, unsigned long phys);
55
56extern void ppc6xx_idle(void);
57extern void power4_idle(void);
58
59boot_infos_t *boot_infos;
60struct ide_machdep_calls ppc_ide_md;
61
Paul Mackerras80579e12005-10-27 22:42:04 +100062int boot_cpuid;
63EXPORT_SYMBOL_GPL(boot_cpuid);
64int boot_cpuid_phys;
65
Paul Mackerras9b6b5632005-10-06 12:06:20 +100066unsigned long ISA_DMA_THRESHOLD;
67unsigned int DMA_MODE_READ;
68unsigned int DMA_MODE_WRITE;
69
Paul Mackerrase574d232005-10-10 22:58:10 +100070int have_of = 1;
71
Paul Mackerras9b6b5632005-10-06 12:06:20 +100072#ifdef CONFIG_PPC_MULTIPLATFORM
Paul Mackerras9b6b5632005-10-06 12:06:20 +100073extern void prep_init(void);
74extern void pmac_init(void);
75extern void chrp_init(void);
76
77dev_t boot_dev;
78#endif /* CONFIG_PPC_MULTIPLATFORM */
79
80#ifdef CONFIG_MAGIC_SYSRQ
81unsigned long SYSRQ_KEY = 0x54;
82#endif /* CONFIG_MAGIC_SYSRQ */
83
84#ifdef CONFIG_VGA_CONSOLE
85unsigned long vgacon_remap_base;
86#endif
87
88struct machdep_calls ppc_md;
Paul Mackerrase574d232005-10-10 22:58:10 +100089EXPORT_SYMBOL(ppc_md);
Paul Mackerras9b6b5632005-10-06 12:06:20 +100090
91/*
92 * These are used in binfmt_elf.c to put aux entries on the stack
93 * for each elf executable being started.
94 */
95int dcache_bsize;
96int icache_bsize;
97int ucache_bsize;
98
Paul Mackerras9b6b5632005-10-06 12:06:20 +100099/*
100 * We're called here very early in the boot. We determine the machine
101 * type and call the appropriate low-level setup functions.
102 * -- Cort <cort@fsmlabs.com>
103 *
104 * Note that the kernel may be running at an address which is different
105 * from the address that it was linked at, so we must use RELOC/PTRRELOC
106 * to access static data (including strings). -- paulus
107 */
108unsigned long __init early_init(unsigned long dt_ptr)
109{
110 unsigned long offset = reloc_offset();
111
Paul Mackerrasdd1843432005-10-17 20:13:47 +1000112 /* First zero the BSS -- use memset_io, some platforms don't have
113 * caches on yet */
114 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
115
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000116 /*
117 * Identify the CPU type and fix up code sections
118 * that depend on which cpu we have.
119 */
120 identify_cpu(offset, 0);
121 do_cpu_ftr_fixups(offset);
122
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000123 return KERNELBASE + offset;
124}
125
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000126#ifdef CONFIG_PPC_MULTIPLATFORM
127/*
128 * The PPC_MULTIPLATFORM version of platform_init...
129 */
130void __init platform_init(void)
131{
132 /* if we didn't get any bootinfo telling us what we are... */
133 if (_machine == 0) {
134 /* prep boot loader tells us if we're prep or not */
135 if ( *(unsigned long *)(KERNELBASE) == (0xdeadc0de) )
136 _machine = _MACH_prep;
137 }
138
139#ifdef CONFIG_PPC_PREP
140 /* not much more to do here, if prep */
141 if (_machine == _MACH_prep) {
142 prep_init();
143 return;
144 }
145#endif
146
147#ifdef CONFIG_ADB
148 if (strstr(cmd_line, "adb_sync")) {
149 extern int __adb_probe_sync;
150 __adb_probe_sync = 1;
151 }
152#endif /* CONFIG_ADB */
153
154 switch (_machine) {
155#ifdef CONFIG_PPC_PMAC
156 case _MACH_Pmac:
157 pmac_init();
158 break;
159#endif
160#ifdef CONFIG_PPC_CHRP
161 case _MACH_chrp:
162 chrp_init();
163 break;
164#endif
165 }
166}
Paul Mackerras03501da2005-10-26 17:11:18 +1000167#endif
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000168
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000169/*
170 * Find out what kind of machine we're on and save any data we need
171 * from the early boot process (devtree is copied on pmac by prom_init()).
172 * This is called very early on the boot process, after a minimal
173 * MMU environment has been set up but before MMU_init is called.
174 */
175void __init machine_init(unsigned long dt_ptr, unsigned long phys)
176{
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100177 /* If btext is enabled, we might have a BAT setup for early display,
178 * thus we do enable some very basic udbg output
179 */
180#ifdef CONFIG_BOOTX_TEXT
181 udbg_putc = btext_drawchar;
182#endif
183
184 /* Do some early initialization based on the flat device tree */
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000185 early_init_devtree(__va(dt_ptr));
186
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100187 /* Check default command line */
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000188#ifdef CONFIG_CMDLINE
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100189 if (cmd_line[0] == 0)
190 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000191#endif /* CONFIG_CMDLINE */
192
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100193 /* Base init based on machine type */
Paul Mackerras35499c02005-10-22 16:02:39 +1000194 platform_init();
195
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000196#ifdef CONFIG_6xx
197 ppc_md.power_save = ppc6xx_idle;
198#endif
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000199
200 if (ppc_md.progress)
201 ppc_md.progress("id mach(): done", 0x200);
202}
203
204#ifdef CONFIG_BOOKE_WDT
205/* Checks wdt=x and wdt_period=xx command-line option */
206int __init early_parse_wdt(char *p)
207{
208 if (p && strncmp(p, "0", 1) != 0)
209 booke_wdt_enabled = 1;
210
211 return 0;
212}
213early_param("wdt", early_parse_wdt);
214
215int __init early_parse_wdt_period (char *p)
216{
217 if (p)
218 booke_wdt_period = simple_strtoul(p, NULL, 0);
219
220 return 0;
221}
222early_param("wdt_period", early_parse_wdt_period);
223#endif /* CONFIG_BOOKE_WDT */
224
225/* Checks "l2cr=xxxx" command-line option */
226int __init ppc_setup_l2cr(char *str)
227{
228 if (cpu_has_feature(CPU_FTR_L2CR)) {
229 unsigned long val = simple_strtoul(str, NULL, 0);
230 printk(KERN_INFO "l2cr set to %lx\n", val);
231 _set_L2CR(0); /* force invalidate by disable cache */
232 _set_L2CR(val); /* and enable it */
233 }
234 return 1;
235}
236__setup("l2cr=", ppc_setup_l2cr);
237
238#ifdef CONFIG_GENERIC_NVRAM
239
240/* Generic nvram hooks used by drivers/char/gen_nvram.c */
241unsigned char nvram_read_byte(int addr)
242{
243 if (ppc_md.nvram_read_val)
244 return ppc_md.nvram_read_val(addr);
245 return 0xff;
246}
247EXPORT_SYMBOL(nvram_read_byte);
248
249void nvram_write_byte(unsigned char val, int addr)
250{
251 if (ppc_md.nvram_write_val)
252 ppc_md.nvram_write_val(addr, val);
253}
254EXPORT_SYMBOL(nvram_write_byte);
255
256void nvram_sync(void)
257{
258 if (ppc_md.nvram_sync)
259 ppc_md.nvram_sync();
260}
261EXPORT_SYMBOL(nvram_sync);
262
263#endif /* CONFIG_NVRAM */
264
265static struct cpu cpu_devices[NR_CPUS];
266
267int __init ppc_init(void)
268{
269 int i;
270
271 /* clear the progress line */
272 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
273
274 /* register CPU devices */
275 for (i = 0; i < NR_CPUS; i++)
276 if (cpu_possible(i))
277 register_cpu(&cpu_devices[i], i, NULL);
278
279 /* call platform init */
280 if (ppc_md.init != NULL) {
281 ppc_md.init();
282 }
283 return 0;
284}
285
286arch_initcall(ppc_init);
287
288/* Warning, IO base is not yet inited */
289void __init setup_arch(char **cmdline_p)
290{
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000291 extern void do_init_bootmem(void);
292
293 /* so udelay does something sensible, assume <= 1000 bogomips */
294 loops_per_jiffy = 500000000 / HZ;
295
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000296 unflatten_device_tree();
David Woodhousea82765b2005-11-02 22:34:20 +0000297 check_for_initrd();
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100298
299 if (ppc_md.init_early)
300 ppc_md.init_early();
301
Benjamin Herrenschmidt463ce0e2005-11-23 17:56:06 +1100302 find_legacy_serial_ports();
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000303 finish_device_tree();
304
Paul Mackerras5ad57072005-11-05 10:33:55 +1100305 smp_setup_cpu_maps();
306
Paul Mackerrasfca5dcd2005-11-08 22:55:08 +1100307#ifdef CONFIG_XMON_DEFAULT
308 xmon_init(1);
309#endif
Benjamin Herrenschmidt51d30822005-11-23 17:57:25 +1100310 /* Register early console */
311 register_early_udbg_console();
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000312
313#if defined(CONFIG_KGDB)
314 if (ppc_md.kgdb_map_scc)
315 ppc_md.kgdb_map_scc();
316 set_debug_traps();
317 if (strstr(cmd_line, "gdb")) {
318 if (ppc_md.progress)
319 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
320 printk("kgdb breakpoint activated\n");
321 breakpoint();
322 }
323#endif
324
325 /*
326 * Set cache line size based on type of cpu as a default.
327 * Systems with OF can look in the properties on the cpu node(s)
328 * for a possibly more accurate value.
329 */
330 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
331 dcache_bsize = cur_cpu_spec->dcache_bsize;
332 icache_bsize = cur_cpu_spec->icache_bsize;
333 ucache_bsize = 0;
334 } else
335 ucache_bsize = dcache_bsize = icache_bsize
336 = cur_cpu_spec->dcache_bsize;
337
338 /* reboot on panic */
339 panic_timeout = 180;
340
341 init_mm.start_code = PAGE_OFFSET;
342 init_mm.end_code = (unsigned long) _etext;
343 init_mm.end_data = (unsigned long) _edata;
Paul Mackerras49b09852005-11-10 15:53:40 +1100344 init_mm.brk = klimit;
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000345
346 /* Save unparsed command line copy for /proc/cmdline */
347 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
348 *cmdline_p = cmd_line;
349
350 parse_early_param();
351
352 /* set up the bootmem stuff with available memory */
353 do_init_bootmem();
354 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
355
356#ifdef CONFIG_PPC_OCP
357 /* Initialize OCP device list */
358 ocp_early_init();
359 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
360#endif
361
362#ifdef CONFIG_DUMMY_CONSOLE
363 conswitchp = &dummy_con;
364#endif
365
366 ppc_md.setup_arch();
367 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
368
369 paging_init();
370
371 /* this is for modules since _machine can be a define -- Cort */
372 ppc_md.ppc_machine = _machine;
373}