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