[POWERPC] Remove APUS support from arch/ppc
[linux-2.6/x86.git] / arch / ppc / kernel / setup.c
blobaac88c2f3db9d7d07b9b6e63e431f4fdb6a328b1
1 /*
2 * Common prep boot and setup code.
3 */
5 #include <linux/module.h>
6 #include <linux/string.h>
7 #include <linux/sched.h>
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/reboot.h>
11 #include <linux/delay.h>
12 #include <linux/initrd.h>
13 #include <linux/ide.h>
14 #include <linux/screen_info.h>
15 #include <linux/bootmem.h>
16 #include <linux/seq_file.h>
17 #include <linux/root_dev.h>
18 #include <linux/cpu.h>
19 #include <linux/console.h>
21 #include <asm/residual.h>
22 #include <asm/io.h>
23 #include <asm/prom.h>
24 #include <asm/processor.h>
25 #include <asm/pgtable.h>
26 #include <asm/bootinfo.h>
27 #include <asm/setup.h>
28 #include <asm/smp.h>
29 #include <asm/elf.h>
30 #include <asm/cputable.h>
31 #include <asm/bootx.h>
32 #include <asm/btext.h>
33 #include <asm/machdep.h>
34 #include <asm/uaccess.h>
35 #include <asm/system.h>
36 #include <asm/sections.h>
37 #include <asm/nvram.h>
38 #include <asm/xmon.h>
39 #include <asm/ocp.h>
40 #include <asm/prom.h>
42 #define USES_PPC_SYS (defined(CONFIG_85xx) || defined(CONFIG_83xx) || \
43 defined(CONFIG_MPC10X_BRIDGE) || defined(CONFIG_8260) || \
44 defined(CONFIG_PPC_MPC52xx))
46 #if USES_PPC_SYS
47 #include <asm/ppc_sys.h>
48 #endif
50 #if defined CONFIG_KGDB
51 #include <asm/kgdb.h>
52 #endif
54 extern void platform_init(unsigned long r3, unsigned long r4,
55 unsigned long r5, unsigned long r6, unsigned long r7);
56 extern void reloc_got2(unsigned long offset);
58 extern void ppc6xx_idle(void);
59 extern void power4_idle(void);
61 extern boot_infos_t *boot_infos;
62 struct ide_machdep_calls ppc_ide_md;
64 /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
65 size value reported by the boot loader. */
66 unsigned long boot_mem_size;
68 unsigned long ISA_DMA_THRESHOLD;
69 unsigned int DMA_MODE_READ;
70 unsigned int DMA_MODE_WRITE;
72 #ifdef CONFIG_PPC_PREP
73 extern void prep_init(unsigned long r3, unsigned long r4,
74 unsigned long r5, unsigned long r6, unsigned long r7);
76 dev_t boot_dev;
77 #endif /* CONFIG_PPC_PREP */
79 int have_of;
80 EXPORT_SYMBOL(have_of);
82 #ifdef __DO_IRQ_CANON
83 int ppc_do_canonicalize_irqs;
84 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
85 #endif
87 #ifdef CONFIG_VGA_CONSOLE
88 unsigned long vgacon_remap_base;
89 #endif
91 struct machdep_calls ppc_md;
94 * These are used in binfmt_elf.c to put aux entries on the stack
95 * for each elf executable being started.
97 int dcache_bsize;
98 int icache_bsize;
99 int ucache_bsize;
101 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
102 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
103 struct screen_info screen_info = {
104 0, 25, /* orig-x, orig-y */
105 0, /* unused */
106 0, /* orig-video-page */
107 0, /* orig-video-mode */
108 80, /* orig-video-cols */
109 0,0,0, /* ega_ax, ega_bx, ega_cx */
110 25, /* orig-video-lines */
111 1, /* orig-video-isVGA */
112 16 /* orig-video-points */
114 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
116 void machine_restart(char *cmd)
118 #ifdef CONFIG_NVRAM
119 nvram_sync();
120 #endif
121 ppc_md.restart(cmd);
124 static void ppc_generic_power_off(void)
126 ppc_md.power_off();
129 void machine_halt(void)
131 #ifdef CONFIG_NVRAM
132 nvram_sync();
133 #endif
134 ppc_md.halt();
137 void (*pm_power_off)(void) = ppc_generic_power_off;
139 void machine_power_off(void)
141 #ifdef CONFIG_NVRAM
142 nvram_sync();
143 #endif
144 if (pm_power_off)
145 pm_power_off();
146 ppc_generic_power_off();
149 #ifdef CONFIG_TAU
150 extern u32 cpu_temp(unsigned long cpu);
151 extern u32 cpu_temp_both(unsigned long cpu);
152 #endif /* CONFIG_TAU */
154 int show_cpuinfo(struct seq_file *m, void *v)
156 int i = (int) v - 1;
157 int err = 0;
158 unsigned int pvr;
159 unsigned short maj, min;
160 unsigned long lpj;
162 if (i >= NR_CPUS) {
163 /* Show summary information */
164 #ifdef CONFIG_SMP
165 unsigned long bogosum = 0;
166 for_each_online_cpu(i)
167 bogosum += cpu_data[i].loops_per_jiffy;
168 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
169 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
170 #endif /* CONFIG_SMP */
172 if (ppc_md.show_cpuinfo != NULL)
173 err = ppc_md.show_cpuinfo(m);
174 return err;
177 #ifdef CONFIG_SMP
178 if (!cpu_online(i))
179 return 0;
180 pvr = cpu_data[i].pvr;
181 lpj = cpu_data[i].loops_per_jiffy;
182 #else
183 pvr = mfspr(SPRN_PVR);
184 lpj = loops_per_jiffy;
185 #endif
187 seq_printf(m, "processor\t: %d\n", i);
188 seq_printf(m, "cpu\t\t: ");
190 if (cur_cpu_spec->pvr_mask)
191 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
192 else
193 seq_printf(m, "unknown (%08x)", pvr);
194 #ifdef CONFIG_ALTIVEC
195 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
196 seq_printf(m, ", altivec supported");
197 #endif
198 seq_printf(m, "\n");
200 #ifdef CONFIG_TAU
201 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
202 #ifdef CONFIG_TAU_AVERAGE
203 /* more straightforward, but potentially misleading */
204 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
205 cpu_temp(i));
206 #else
207 /* show the actual temp sensor range */
208 u32 temp;
209 temp = cpu_temp_both(i);
210 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
211 temp & 0xff, temp >> 16);
212 #endif
214 #endif /* CONFIG_TAU */
216 if (ppc_md.show_percpuinfo != NULL) {
217 err = ppc_md.show_percpuinfo(m, i);
218 if (err)
219 return err;
222 /* If we are a Freescale core do a simple check so
223 * we dont have to keep adding cases in the future */
224 if ((PVR_VER(pvr) & 0x8000) == 0x8000) {
225 maj = PVR_MAJ(pvr);
226 min = PVR_MIN(pvr);
227 } else {
228 switch (PVR_VER(pvr)) {
229 case 0x0020: /* 403 family */
230 maj = PVR_MAJ(pvr) + 1;
231 min = PVR_MIN(pvr);
232 break;
233 case 0x1008: /* 740P/750P ?? */
234 maj = ((pvr >> 8) & 0xFF) - 1;
235 min = pvr & 0xFF;
236 break;
237 default:
238 maj = (pvr >> 8) & 0xFF;
239 min = pvr & 0xFF;
240 break;
244 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
245 maj, min, PVR_VER(pvr), PVR_REV(pvr));
247 seq_printf(m, "bogomips\t: %lu.%02lu\n",
248 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
250 #if USES_PPC_SYS
251 if (cur_ppc_sys_spec->ppc_sys_name)
252 seq_printf(m, "chipset\t\t: %s\n",
253 cur_ppc_sys_spec->ppc_sys_name);
254 #endif
256 #ifdef CONFIG_SMP
257 seq_printf(m, "\n");
258 #endif
260 return 0;
263 static void *c_start(struct seq_file *m, loff_t *pos)
265 int i = *pos;
267 return i <= NR_CPUS? (void *) (i + 1): NULL;
270 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
272 ++*pos;
273 return c_start(m, pos);
276 static void c_stop(struct seq_file *m, void *v)
280 struct seq_operations cpuinfo_op = {
281 .start =c_start,
282 .next = c_next,
283 .stop = c_stop,
284 .show = show_cpuinfo,
288 * We're called here very early in the boot. We determine the machine
289 * type and call the appropriate low-level setup functions.
290 * -- Cort <cort@fsmlabs.com>
292 * Note that the kernel may be running at an address which is different
293 * from the address that it was linked at, so we must use RELOC/PTRRELOC
294 * to access static data (including strings). -- paulus
296 __init
297 unsigned long
298 early_init(int r3, int r4, int r5)
300 unsigned long phys;
301 unsigned long offset = reloc_offset();
302 struct cpu_spec *spec;
304 /* Default */
305 phys = offset + KERNELBASE;
307 /* First zero the BSS -- use memset, some arches don't have
308 * caches on yet */
309 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
312 * Identify the CPU type and fix up code sections
313 * that depend on which cpu we have.
315 spec = identify_cpu(offset, mfspr(SPRN_PVR));
316 do_feature_fixups(spec->cpu_features,
317 PTRRELOC(&__start___ftr_fixup),
318 PTRRELOC(&__stop___ftr_fixup));
320 return phys;
323 #ifdef CONFIG_PPC_PREP
325 * The PPC_PREP version of platform_init...
327 void __init
328 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
329 unsigned long r6, unsigned long r7)
331 #ifdef CONFIG_BOOTX_TEXT
332 if (boot_text_mapped) {
333 btext_clearscreen();
334 btext_welcome();
336 #endif
338 parse_bootinfo(find_bootinfo());
340 prep_init(r3, r4, r5, r6, r7);
342 #endif /* CONFIG_PPC_PREP */
344 struct bi_record *find_bootinfo(void)
346 struct bi_record *rec;
348 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
349 if ( rec->tag != BI_FIRST ) {
351 * This 0x10000 offset is a terrible hack but it will go away when
352 * we have the bootloader handle all the relocation and
353 * prom calls -- Cort
355 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
356 if ( rec->tag != BI_FIRST )
357 return NULL;
359 return rec;
362 void parse_bootinfo(struct bi_record *rec)
364 if (rec == NULL || rec->tag != BI_FIRST)
365 return;
366 while (rec->tag != BI_LAST) {
367 ulong *data = rec->data;
368 switch (rec->tag) {
369 case BI_CMD_LINE:
370 strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
371 break;
372 #ifdef CONFIG_BLK_DEV_INITRD
373 case BI_INITRD:
374 initrd_start = data[0] + KERNELBASE;
375 initrd_end = data[0] + data[1] + KERNELBASE;
376 break;
377 #endif /* CONFIG_BLK_DEV_INITRD */
378 case BI_MEMSIZE:
379 boot_mem_size = data[0];
380 break;
382 rec = (struct bi_record *)((ulong)rec + rec->size);
387 * Find out what kind of machine we're on and save any data we need
388 * from the early boot process (devtree is copied on pmac by prom_init()).
389 * This is called very early on the boot process, after a minimal
390 * MMU environment has been set up but before MMU_init is called.
392 void __init
393 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
394 unsigned long r6, unsigned long r7)
396 #ifdef CONFIG_CMDLINE
397 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
398 #endif /* CONFIG_CMDLINE */
400 #ifdef CONFIG_6xx
401 ppc_md.power_save = ppc6xx_idle;
402 #endif
404 platform_init(r3, r4, r5, r6, r7);
406 if (ppc_md.progress)
407 ppc_md.progress("id mach(): done", 0x200);
409 #ifdef CONFIG_BOOKE_WDT
410 /* Checks wdt=x and wdt_period=xx command-line option */
411 int __init early_parse_wdt(char *p)
413 if (p && strncmp(p, "0", 1) != 0)
414 booke_wdt_enabled = 1;
416 return 0;
418 early_param("wdt", early_parse_wdt);
420 int __init early_parse_wdt_period (char *p)
422 if (p)
423 booke_wdt_period = simple_strtoul(p, NULL, 0);
425 return 0;
427 early_param("wdt_period", early_parse_wdt_period);
428 #endif /* CONFIG_BOOKE_WDT */
430 /* Checks "l2cr=xxxx" command-line option */
431 int __init ppc_setup_l2cr(char *str)
433 if (cpu_has_feature(CPU_FTR_L2CR)) {
434 unsigned long val = simple_strtoul(str, NULL, 0);
435 printk(KERN_INFO "l2cr set to %lx\n", val);
436 _set_L2CR(0); /* force invalidate by disable cache */
437 _set_L2CR(val); /* and enable it */
439 return 1;
441 __setup("l2cr=", ppc_setup_l2cr);
443 #ifdef CONFIG_GENERIC_NVRAM
445 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
446 unsigned char nvram_read_byte(int addr)
448 if (ppc_md.nvram_read_val)
449 return ppc_md.nvram_read_val(addr);
450 return 0xff;
452 EXPORT_SYMBOL(nvram_read_byte);
454 void nvram_write_byte(unsigned char val, int addr)
456 if (ppc_md.nvram_write_val)
457 ppc_md.nvram_write_val(addr, val);
459 EXPORT_SYMBOL(nvram_write_byte);
461 void nvram_sync(void)
463 if (ppc_md.nvram_sync)
464 ppc_md.nvram_sync();
466 EXPORT_SYMBOL(nvram_sync);
468 #endif /* CONFIG_NVRAM */
470 static struct cpu cpu_devices[NR_CPUS];
472 int __init ppc_init(void)
474 int i;
476 /* clear the progress line */
477 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
479 /* register CPU devices */
480 for_each_possible_cpu(i)
481 register_cpu(&cpu_devices[i], i);
483 /* call platform init */
484 if (ppc_md.init != NULL) {
485 ppc_md.init();
487 return 0;
490 arch_initcall(ppc_init);
492 /* Warning, IO base is not yet inited */
493 void __init setup_arch(char **cmdline_p)
495 extern char *klimit;
496 extern void do_init_bootmem(void);
498 /* so udelay does something sensible, assume <= 1000 bogomips */
499 loops_per_jiffy = 500000000 / HZ;
501 if (ppc_md.init_early)
502 ppc_md.init_early();
504 #ifdef CONFIG_XMON
505 xmon_init(1);
506 if (strstr(cmd_line, "xmon"))
507 xmon(NULL);
508 #endif /* CONFIG_XMON */
509 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
511 #if defined(CONFIG_KGDB)
512 if (ppc_md.kgdb_map_scc)
513 ppc_md.kgdb_map_scc();
514 set_debug_traps();
515 if (strstr(cmd_line, "gdb")) {
516 if (ppc_md.progress)
517 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
518 printk("kgdb breakpoint activated\n");
519 breakpoint();
521 #endif
524 * Set cache line size based on type of cpu as a default.
525 * Systems with OF can look in the properties on the cpu node(s)
526 * for a possibly more accurate value.
528 if (! cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE)) {
529 dcache_bsize = cur_cpu_spec->dcache_bsize;
530 icache_bsize = cur_cpu_spec->icache_bsize;
531 ucache_bsize = 0;
532 } else
533 ucache_bsize = dcache_bsize = icache_bsize
534 = cur_cpu_spec->dcache_bsize;
536 /* reboot on panic */
537 panic_timeout = 180;
539 init_mm.start_code = PAGE_OFFSET;
540 init_mm.end_code = (unsigned long) _etext;
541 init_mm.end_data = (unsigned long) _edata;
542 init_mm.brk = (unsigned long) klimit;
544 /* Save unparsed command line copy for /proc/cmdline */
545 strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE);
546 *cmdline_p = cmd_line;
548 parse_early_param();
550 /* set up the bootmem stuff with available memory */
551 do_init_bootmem();
552 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
554 #ifdef CONFIG_PPC_OCP
555 /* Initialize OCP device list */
556 ocp_early_init();
557 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
558 #endif
560 #ifdef CONFIG_DUMMY_CONSOLE
561 conswitchp = &dummy_con;
562 #endif
564 ppc_md.setup_arch();
565 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
567 paging_init();