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