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