PCI: add ICH7/8 ACPI/GPIO io resource quirks
[pv_ops_mirror.git] / arch / ppc / kernel / setup.c
blob75fe13815be27c23e817ac7527c00079476f1c0b
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/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/sections.h>
38 #include <asm/nvram.h>
39 #include <asm/xmon.h>
40 #include <asm/ocp.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 identify_cpu(unsigned long offset, unsigned long cpu);
57 extern void do_cpu_ftr_fixups(unsigned long offset);
58 extern void reloc_got2(unsigned long offset);
60 extern void ppc6xx_idle(void);
61 extern void power4_idle(void);
63 extern boot_infos_t *boot_infos;
64 struct ide_machdep_calls ppc_ide_md;
66 /* Used with the BI_MEMSIZE bootinfo parameter to store the memory
67 size value reported by the boot loader. */
68 unsigned long boot_mem_size;
70 unsigned long ISA_DMA_THRESHOLD;
71 unsigned int DMA_MODE_READ;
72 unsigned int DMA_MODE_WRITE;
74 #ifdef CONFIG_PPC_PREP
75 extern void prep_init(unsigned long r3, unsigned long r4,
76 unsigned long r5, unsigned long r6, unsigned long r7);
78 dev_t boot_dev;
79 #endif /* CONFIG_PPC_PREP */
81 int have_of;
82 EXPORT_SYMBOL(have_of);
84 #ifdef __DO_IRQ_CANON
85 int ppc_do_canonicalize_irqs;
86 EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
87 #endif
89 #ifdef CONFIG_VGA_CONSOLE
90 unsigned long vgacon_remap_base;
91 #endif
93 struct machdep_calls ppc_md;
96 * These are used in binfmt_elf.c to put aux entries on the stack
97 * for each elf executable being started.
99 int dcache_bsize;
100 int icache_bsize;
101 int ucache_bsize;
103 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_FB_VGA16) || \
104 defined(CONFIG_FB_VGA16_MODULE) || defined(CONFIG_FB_VESA)
105 struct screen_info screen_info = {
106 0, 25, /* orig-x, orig-y */
107 0, /* unused */
108 0, /* orig-video-page */
109 0, /* orig-video-mode */
110 80, /* orig-video-cols */
111 0,0,0, /* ega_ax, ega_bx, ega_cx */
112 25, /* orig-video-lines */
113 1, /* orig-video-isVGA */
114 16 /* orig-video-points */
116 #endif /* CONFIG_VGA_CONSOLE || CONFIG_FB_VGA16 || CONFIG_FB_VESA */
118 void machine_restart(char *cmd)
120 #ifdef CONFIG_NVRAM
121 nvram_sync();
122 #endif
123 ppc_md.restart(cmd);
126 static void ppc_generic_power_off(void)
128 ppc_md.power_off();
131 void machine_halt(void)
133 #ifdef CONFIG_NVRAM
134 nvram_sync();
135 #endif
136 ppc_md.halt();
139 void (*pm_power_off)(void) = ppc_generic_power_off;
141 void machine_power_off(void)
143 #ifdef CONFIG_NVRAM
144 nvram_sync();
145 #endif
146 if (pm_power_off)
147 pm_power_off();
148 ppc_generic_power_off();
151 #ifdef CONFIG_TAU
152 extern u32 cpu_temp(unsigned long cpu);
153 extern u32 cpu_temp_both(unsigned long cpu);
154 #endif /* CONFIG_TAU */
156 int show_cpuinfo(struct seq_file *m, void *v)
158 int i = (int) v - 1;
159 int err = 0;
160 unsigned int pvr;
161 unsigned short maj, min;
162 unsigned long lpj;
164 if (i >= NR_CPUS) {
165 /* Show summary information */
166 #ifdef CONFIG_SMP
167 unsigned long bogosum = 0;
168 for_each_online_cpu(i)
169 bogosum += cpu_data[i].loops_per_jiffy;
170 seq_printf(m, "total bogomips\t: %lu.%02lu\n",
171 bogosum/(500000/HZ), bogosum/(5000/HZ) % 100);
172 #endif /* CONFIG_SMP */
174 if (ppc_md.show_cpuinfo != NULL)
175 err = ppc_md.show_cpuinfo(m);
176 return err;
179 #ifdef CONFIG_SMP
180 if (!cpu_online(i))
181 return 0;
182 pvr = cpu_data[i].pvr;
183 lpj = cpu_data[i].loops_per_jiffy;
184 #else
185 pvr = mfspr(SPRN_PVR);
186 lpj = loops_per_jiffy;
187 #endif
189 seq_printf(m, "processor\t: %d\n", i);
190 seq_printf(m, "cpu\t\t: ");
192 if (cur_cpu_spec->pvr_mask)
193 seq_printf(m, "%s", cur_cpu_spec->cpu_name);
194 else
195 seq_printf(m, "unknown (%08x)", pvr);
196 #ifdef CONFIG_ALTIVEC
197 if (cur_cpu_spec->cpu_features & CPU_FTR_ALTIVEC)
198 seq_printf(m, ", altivec supported");
199 #endif
200 seq_printf(m, "\n");
202 #ifdef CONFIG_TAU
203 if (cur_cpu_spec->cpu_features & CPU_FTR_TAU) {
204 #ifdef CONFIG_TAU_AVERAGE
205 /* more straightforward, but potentially misleading */
206 seq_printf(m, "temperature \t: %u C (uncalibrated)\n",
207 cpu_temp(i));
208 #else
209 /* show the actual temp sensor range */
210 u32 temp;
211 temp = cpu_temp_both(i);
212 seq_printf(m, "temperature \t: %u-%u C (uncalibrated)\n",
213 temp & 0xff, temp >> 16);
214 #endif
216 #endif /* CONFIG_TAU */
218 if (ppc_md.show_percpuinfo != NULL) {
219 err = ppc_md.show_percpuinfo(m, i);
220 if (err)
221 return err;
224 /* If we are a Freescale core do a simple check so
225 * we dont have to keep adding cases in the future */
226 if ((PVR_VER(pvr) & 0x8000) == 0x8000) {
227 maj = PVR_MAJ(pvr);
228 min = PVR_MIN(pvr);
229 } else {
230 switch (PVR_VER(pvr)) {
231 case 0x0020: /* 403 family */
232 maj = PVR_MAJ(pvr) + 1;
233 min = PVR_MIN(pvr);
234 break;
235 case 0x1008: /* 740P/750P ?? */
236 maj = ((pvr >> 8) & 0xFF) - 1;
237 min = pvr & 0xFF;
238 break;
239 default:
240 maj = (pvr >> 8) & 0xFF;
241 min = pvr & 0xFF;
242 break;
246 seq_printf(m, "revision\t: %hd.%hd (pvr %04x %04x)\n",
247 maj, min, PVR_VER(pvr), PVR_REV(pvr));
249 seq_printf(m, "bogomips\t: %lu.%02lu\n",
250 lpj / (500000/HZ), (lpj / (5000/HZ)) % 100);
252 #if USES_PPC_SYS
253 if (cur_ppc_sys_spec->ppc_sys_name)
254 seq_printf(m, "chipset\t\t: %s\n",
255 cur_ppc_sys_spec->ppc_sys_name);
256 #endif
258 #ifdef CONFIG_SMP
259 seq_printf(m, "\n");
260 #endif
262 return 0;
265 static void *c_start(struct seq_file *m, loff_t *pos)
267 int i = *pos;
269 return i <= NR_CPUS? (void *) (i + 1): NULL;
272 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
274 ++*pos;
275 return c_start(m, pos);
278 static void c_stop(struct seq_file *m, void *v)
282 struct seq_operations cpuinfo_op = {
283 .start =c_start,
284 .next = c_next,
285 .stop = c_stop,
286 .show = show_cpuinfo,
290 * We're called here very early in the boot. We determine the machine
291 * type and call the appropriate low-level setup functions.
292 * -- Cort <cort@fsmlabs.com>
294 * Note that the kernel may be running at an address which is different
295 * from the address that it was linked at, so we must use RELOC/PTRRELOC
296 * to access static data (including strings). -- paulus
298 __init
299 unsigned long
300 early_init(int r3, int r4, int r5)
302 unsigned long phys;
303 unsigned long offset = reloc_offset();
305 /* Default */
306 phys = offset + KERNELBASE;
308 /* First zero the BSS -- use memset, some arches don't have
309 * caches on yet */
310 memset_io(PTRRELOC(&__bss_start), 0, _end - __bss_start);
313 * Identify the CPU type and fix up code sections
314 * that depend on which cpu we have.
316 identify_cpu(offset, 0);
317 do_cpu_ftr_fixups(offset);
319 return phys;
322 #ifdef CONFIG_PPC_PREP
324 * The PPC_PREP version of platform_init...
326 void __init
327 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
328 unsigned long r6, unsigned long r7)
330 #ifdef CONFIG_BOOTX_TEXT
331 if (boot_text_mapped) {
332 btext_clearscreen();
333 btext_welcome();
335 #endif
337 parse_bootinfo(find_bootinfo());
339 prep_init(r3, r4, r5, r6, r7);
341 #endif /* CONFIG_PPC_PREP */
343 struct bi_record *find_bootinfo(void)
345 struct bi_record *rec;
347 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+(1<<20)-1,(1<<20));
348 if ( rec->tag != BI_FIRST ) {
350 * This 0x10000 offset is a terrible hack but it will go away when
351 * we have the bootloader handle all the relocation and
352 * prom calls -- Cort
354 rec = (struct bi_record *)_ALIGN((ulong)__bss_start+0x10000+(1<<20)-1,(1<<20));
355 if ( rec->tag != BI_FIRST )
356 return NULL;
358 return rec;
361 void parse_bootinfo(struct bi_record *rec)
363 if (rec == NULL || rec->tag != BI_FIRST)
364 return;
365 while (rec->tag != BI_LAST) {
366 ulong *data = rec->data;
367 switch (rec->tag) {
368 case BI_CMD_LINE:
369 strlcpy(cmd_line, (void *)data, sizeof(cmd_line));
370 break;
371 #ifdef CONFIG_BLK_DEV_INITRD
372 case BI_INITRD:
373 initrd_start = data[0] + KERNELBASE;
374 initrd_end = data[0] + data[1] + KERNELBASE;
375 break;
376 #endif /* CONFIG_BLK_DEV_INITRD */
377 case BI_MEMSIZE:
378 boot_mem_size = data[0];
379 break;
381 rec = (struct bi_record *)((ulong)rec + rec->size);
386 * Find out what kind of machine we're on and save any data we need
387 * from the early boot process (devtree is copied on pmac by prom_init()).
388 * This is called very early on the boot process, after a minimal
389 * MMU environment has been set up but before MMU_init is called.
391 void __init
392 machine_init(unsigned long r3, unsigned long r4, unsigned long r5,
393 unsigned long r6, unsigned long r7)
395 #ifdef CONFIG_CMDLINE
396 strlcpy(cmd_line, CONFIG_CMDLINE, sizeof(cmd_line));
397 #endif /* CONFIG_CMDLINE */
399 #ifdef CONFIG_6xx
400 ppc_md.power_save = ppc6xx_idle;
401 #endif
403 platform_init(r3, r4, r5, r6, r7);
405 if (ppc_md.progress)
406 ppc_md.progress("id mach(): done", 0x200);
408 #ifdef CONFIG_BOOKE_WDT
409 /* Checks wdt=x and wdt_period=xx command-line option */
410 int __init early_parse_wdt(char *p)
412 if (p && strncmp(p, "0", 1) != 0)
413 booke_wdt_enabled = 1;
415 return 0;
417 early_param("wdt", early_parse_wdt);
419 int __init early_parse_wdt_period (char *p)
421 if (p)
422 booke_wdt_period = simple_strtoul(p, NULL, 0);
424 return 0;
426 early_param("wdt_period", early_parse_wdt_period);
427 #endif /* CONFIG_BOOKE_WDT */
429 /* Checks "l2cr=xxxx" command-line option */
430 int __init ppc_setup_l2cr(char *str)
432 if (cpu_has_feature(CPU_FTR_L2CR)) {
433 unsigned long val = simple_strtoul(str, NULL, 0);
434 printk(KERN_INFO "l2cr set to %lx\n", val);
435 _set_L2CR(0); /* force invalidate by disable cache */
436 _set_L2CR(val); /* and enable it */
438 return 1;
440 __setup("l2cr=", ppc_setup_l2cr);
442 #ifdef CONFIG_GENERIC_NVRAM
444 /* Generic nvram hooks used by drivers/char/gen_nvram.c */
445 unsigned char nvram_read_byte(int addr)
447 if (ppc_md.nvram_read_val)
448 return ppc_md.nvram_read_val(addr);
449 return 0xff;
451 EXPORT_SYMBOL(nvram_read_byte);
453 void nvram_write_byte(unsigned char val, int addr)
455 if (ppc_md.nvram_write_val)
456 ppc_md.nvram_write_val(addr, val);
458 EXPORT_SYMBOL(nvram_write_byte);
460 void nvram_sync(void)
462 if (ppc_md.nvram_sync)
463 ppc_md.nvram_sync();
465 EXPORT_SYMBOL(nvram_sync);
467 #endif /* CONFIG_NVRAM */
469 static struct cpu cpu_devices[NR_CPUS];
471 int __init ppc_init(void)
473 int i;
475 /* clear the progress line */
476 if ( ppc_md.progress ) ppc_md.progress(" ", 0xffff);
478 /* register CPU devices */
479 for_each_possible_cpu(i)
480 register_cpu(&cpu_devices[i], i);
482 /* call platform init */
483 if (ppc_md.init != NULL) {
484 ppc_md.init();
486 return 0;
489 arch_initcall(ppc_init);
491 /* Warning, IO base is not yet inited */
492 void __init setup_arch(char **cmdline_p)
494 extern char *klimit;
495 extern void do_init_bootmem(void);
497 /* so udelay does something sensible, assume <= 1000 bogomips */
498 loops_per_jiffy = 500000000 / HZ;
500 if (ppc_md.init_early)
501 ppc_md.init_early();
503 #ifdef CONFIG_XMON
504 xmon_init(1);
505 if (strstr(cmd_line, "xmon"))
506 xmon(NULL);
507 #endif /* CONFIG_XMON */
508 if ( ppc_md.progress ) ppc_md.progress("setup_arch: enter", 0x3eab);
510 #if defined(CONFIG_KGDB)
511 if (ppc_md.kgdb_map_scc)
512 ppc_md.kgdb_map_scc();
513 set_debug_traps();
514 if (strstr(cmd_line, "gdb")) {
515 if (ppc_md.progress)
516 ppc_md.progress("setup_arch: kgdb breakpoint", 0x4000);
517 printk("kgdb breakpoint activated\n");
518 breakpoint();
520 #endif
523 * Set cache line size based on type of cpu as a default.
524 * Systems with OF can look in the properties on the cpu node(s)
525 * for a possibly more accurate value.
527 if (cpu_has_feature(CPU_FTR_SPLIT_ID_CACHE)) {
528 dcache_bsize = cur_cpu_spec->dcache_bsize;
529 icache_bsize = cur_cpu_spec->icache_bsize;
530 ucache_bsize = 0;
531 } else
532 ucache_bsize = dcache_bsize = icache_bsize
533 = cur_cpu_spec->dcache_bsize;
535 /* reboot on panic */
536 panic_timeout = 180;
538 init_mm.start_code = PAGE_OFFSET;
539 init_mm.end_code = (unsigned long) _etext;
540 init_mm.end_data = (unsigned long) _edata;
541 init_mm.brk = (unsigned long) klimit;
543 /* Save unparsed command line copy for /proc/cmdline */
544 strlcpy(saved_command_line, cmd_line, COMMAND_LINE_SIZE);
545 *cmdline_p = cmd_line;
547 parse_early_param();
549 /* set up the bootmem stuff with available memory */
550 do_init_bootmem();
551 if ( ppc_md.progress ) ppc_md.progress("setup_arch: bootmem", 0x3eab);
553 #ifdef CONFIG_PPC_OCP
554 /* Initialize OCP device list */
555 ocp_early_init();
556 if ( ppc_md.progress ) ppc_md.progress("ocp: exit", 0x3eab);
557 #endif
559 #ifdef CONFIG_DUMMY_CONSOLE
560 conswitchp = &dummy_con;
561 #endif
563 ppc_md.setup_arch();
564 if ( ppc_md.progress ) ppc_md.progress("arch: exit", 0x3eab);
566 paging_init();