xref: /openbmc/linux/arch/powerpc/kernel/setup_32.c (revision d7cceda96badc1bd444cff27ab9c375a1277c1e3)
170d64ceaSPaul Mackerras /*
270d64ceaSPaul Mackerras  * Common prep/pmac/chrp boot and setup code.
370d64ceaSPaul Mackerras  */
470d64ceaSPaul Mackerras 
570d64ceaSPaul Mackerras #include <linux/module.h>
670d64ceaSPaul Mackerras #include <linux/string.h>
770d64ceaSPaul Mackerras #include <linux/sched.h>
870d64ceaSPaul Mackerras #include <linux/init.h>
970d64ceaSPaul Mackerras #include <linux/kernel.h>
1070d64ceaSPaul Mackerras #include <linux/reboot.h>
1170d64ceaSPaul Mackerras #include <linux/delay.h>
1270d64ceaSPaul Mackerras #include <linux/initrd.h>
1370d64ceaSPaul Mackerras #include <linux/tty.h>
1470d64ceaSPaul Mackerras #include <linux/seq_file.h>
1570d64ceaSPaul Mackerras #include <linux/root_dev.h>
1670d64ceaSPaul Mackerras #include <linux/cpu.h>
1770d64ceaSPaul Mackerras #include <linux/console.h>
1895f72d1eSYinghai Lu #include <linux/memblock.h>
199445aa1aSAl Viro #include <linux/export.h>
2070d64ceaSPaul Mackerras 
2170d64ceaSPaul Mackerras #include <asm/io.h>
2270d64ceaSPaul Mackerras #include <asm/prom.h>
2370d64ceaSPaul Mackerras #include <asm/processor.h>
2470d64ceaSPaul Mackerras #include <asm/pgtable.h>
2570d64ceaSPaul Mackerras #include <asm/setup.h>
2670d64ceaSPaul Mackerras #include <asm/smp.h>
2770d64ceaSPaul Mackerras #include <asm/elf.h>
2870d64ceaSPaul Mackerras #include <asm/cputable.h>
2970d64ceaSPaul Mackerras #include <asm/bootx.h>
3070d64ceaSPaul Mackerras #include <asm/btext.h>
3170d64ceaSPaul Mackerras #include <asm/machdep.h>
327c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
3370d64ceaSPaul Mackerras #include <asm/pmac_feature.h>
3470d64ceaSPaul Mackerras #include <asm/sections.h>
3570d64ceaSPaul Mackerras #include <asm/nvram.h>
3670d64ceaSPaul Mackerras #include <asm/xmon.h>
376d7f58b0SKumar Gala #include <asm/time.h>
38463ce0e1SBenjamin Herrenschmidt #include <asm/serial.h>
3951d3082fSBenjamin Herrenschmidt #include <asm/udbg.h>
401cd03890SLEROY Christophe #include <asm/code-patching.h>
41b92a226eSKevin Hao #include <asm/cpu_has_feature.h>
42e82d70cfSMathieu Malaterre #include <asm/asm-prototypes.h>
43db0a2b63SChristophe Leroy #include <asm/kdump.h>
442c86cd18SChristophe Leroy #include <asm/feature-fixups.h>
4570d64ceaSPaul Mackerras 
46f2c6d0d1SMathieu Malaterre #include "setup.h"
47f2c6d0d1SMathieu Malaterre 
4803501dabSPaul Mackerras #define DBG(fmt...)
4903501dabSPaul Mackerras 
5070d64ceaSPaul Mackerras extern void bootx_init(unsigned long r4, unsigned long phys);
5170d64ceaSPaul Mackerras 
5280579e1fSPaul Mackerras int boot_cpuid_phys;
539974eec2SAndrew Gabbasov EXPORT_SYMBOL_GPL(boot_cpuid_phys);
5480579e1fSPaul Mackerras 
5513a9801eSNathan Lynch int smp_hw_index[NR_CPUS];
569445aa1aSAl Viro EXPORT_SYMBOL(smp_hw_index);
5713a9801eSNathan Lynch 
5870d64ceaSPaul Mackerras unsigned long ISA_DMA_THRESHOLD;
5970d64ceaSPaul Mackerras unsigned int DMA_MODE_READ;
6070d64ceaSPaul Mackerras unsigned int DMA_MODE_WRITE;
6170d64ceaSPaul Mackerras 
629445aa1aSAl Viro EXPORT_SYMBOL(ISA_DMA_THRESHOLD);
639445aa1aSAl Viro EXPORT_SYMBOL(DMA_MODE_READ);
649445aa1aSAl Viro EXPORT_SYMBOL(DMA_MODE_WRITE);
659445aa1aSAl Viro 
6670d64ceaSPaul Mackerras /*
67bd7c93ccSBenjamin Herrenschmidt  * We're called here very early in the boot.
6870d64ceaSPaul Mackerras  *
6970d64ceaSPaul Mackerras  * Note that the kernel may be running at an address which is different
7070d64ceaSPaul Mackerras  * from the address that it was linked at, so we must use RELOC/PTRRELOC
7170d64ceaSPaul Mackerras  * to access static data (including strings).  -- paulus
7270d64ceaSPaul Mackerras  */
734e491d14SSteven Rostedt notrace unsigned long __init early_init(unsigned long dt_ptr)
7470d64ceaSPaul Mackerras {
7570d64ceaSPaul Mackerras 	unsigned long offset = reloc_offset();
7670d64ceaSPaul Mackerras 
77dd184343SPaul Mackerras 	/* First zero the BSS -- use memset_io, some platforms don't have
78dd184343SPaul Mackerras 	 * caches on yet */
79556b09c8SMark A. Greer 	memset_io((void __iomem *)PTRRELOC(&__bss_start), 0,
80556b09c8SMark A. Greer 			__bss_stop - __bss_start);
81dd184343SPaul Mackerras 
8270d64ceaSPaul Mackerras 	/*
8370d64ceaSPaul Mackerras 	 * Identify the CPU type and fix up code sections
8470d64ceaSPaul Mackerras 	 * that depend on which cpu we have.
8570d64ceaSPaul Mackerras 	 */
869402c684SBenjamin Herrenschmidt 	identify_cpu(offset, mfspr(SPRN_PVR));
8742c4aaadSBenjamin Herrenschmidt 
889402c684SBenjamin Herrenschmidt 	apply_feature_fixups();
89d715e433SAnton Blanchard 
9070d64ceaSPaul Mackerras 	return KERNELBASE + offset;
9170d64ceaSPaul Mackerras }
9270d64ceaSPaul Mackerras 
9370d64ceaSPaul Mackerras 
9470d64ceaSPaul Mackerras /*
95bd7c93ccSBenjamin Herrenschmidt  * This is run before start_kernel(), the kernel has been relocated
96bd7c93ccSBenjamin Herrenschmidt  * and we are running with enough of the MMU enabled to have our
97bd7c93ccSBenjamin Herrenschmidt  * proper kernel virtual addresses
98bd7c93ccSBenjamin Herrenschmidt  *
99f9cc1d1fSBenjamin Herrenschmidt  * We do the initial parsing of the flat device-tree and prepares
100f9cc1d1fSBenjamin Herrenschmidt  * for the MMU to be fully initialized.
10170d64ceaSPaul Mackerras  */
1026dece0ebSScott Wood notrace void __init machine_init(u64 dt_ptr)
10370d64ceaSPaul Mackerras {
104fa54a981SChristophe Leroy 	unsigned int *addr = (unsigned int *)((unsigned long)&patch__memset_nocache +
105fa54a981SChristophe Leroy 					       patch__memset_nocache);
106ad1b0122SChristophe Leroy 	unsigned long insn;
107ad1b0122SChristophe Leroy 
10897f6e0ccSBenjamin Herrenschmidt 	/* Configure static keys first, now that we're relocated. */
10997f6e0ccSBenjamin Herrenschmidt 	setup_feature_keys();
11097f6e0ccSBenjamin Herrenschmidt 
111719c91ccSDavid Gibson 	/* Enable early debugging if any specified (see udbg.h) */
112719c91ccSDavid Gibson 	udbg_early_init();
11351d3082fSBenjamin Herrenschmidt 
114fa54a981SChristophe Leroy 	patch_instruction_site(&patch__memcpy_nocache, PPC_INST_NOP);
115ad1b0122SChristophe Leroy 
116ad1b0122SChristophe Leroy 	insn = create_cond_branch(addr, branch_target(addr), 0x820000);
117ad1b0122SChristophe Leroy 	patch_instruction(addr, insn);	/* replace b by bne cr0 */
1181cd03890SLEROY Christophe 
11951d3082fSBenjamin Herrenschmidt 	/* Do some early initialization based on the flat device tree */
12070d64ceaSPaul Mackerras 	early_init_devtree(__va(dt_ptr));
12170d64ceaSPaul Mackerras 
12291b191c7SDave Kleikamp 	early_init_mmu();
12391b191c7SDave Kleikamp 
124f8f50b1bSDale Farnsworth 	setup_kdump_trampoline();
12570d64ceaSPaul Mackerras }
12670d64ceaSPaul Mackerras 
12770d64ceaSPaul Mackerras /* Checks "l2cr=xxxx" command-line option */
128d15a261dSMathieu Malaterre static int __init ppc_setup_l2cr(char *str)
12970d64ceaSPaul Mackerras {
13070d64ceaSPaul Mackerras 	if (cpu_has_feature(CPU_FTR_L2CR)) {
13170d64ceaSPaul Mackerras 		unsigned long val = simple_strtoul(str, NULL, 0);
13270d64ceaSPaul Mackerras 		printk(KERN_INFO "l2cr set to %lx\n", val);
13370d64ceaSPaul Mackerras 		_set_L2CR(0);		/* force invalidate by disable cache */
13470d64ceaSPaul Mackerras 		_set_L2CR(val);		/* and enable it */
13570d64ceaSPaul Mackerras 	}
13670d64ceaSPaul Mackerras 	return 1;
13770d64ceaSPaul Mackerras }
13870d64ceaSPaul Mackerras __setup("l2cr=", ppc_setup_l2cr);
13970d64ceaSPaul Mackerras 
140a78bfbfcSRobert Brose /* Checks "l3cr=xxxx" command-line option */
141d15a261dSMathieu Malaterre static int __init ppc_setup_l3cr(char *str)
142a78bfbfcSRobert Brose {
143a78bfbfcSRobert Brose 	if (cpu_has_feature(CPU_FTR_L3CR)) {
144a78bfbfcSRobert Brose 		unsigned long val = simple_strtoul(str, NULL, 0);
145a78bfbfcSRobert Brose 		printk(KERN_INFO "l3cr set to %lx\n", val);
146a78bfbfcSRobert Brose 		_set_L3CR(val);		/* and enable it */
147a78bfbfcSRobert Brose 	}
148a78bfbfcSRobert Brose 	return 1;
149a78bfbfcSRobert Brose }
150a78bfbfcSRobert Brose __setup("l3cr=", ppc_setup_l3cr);
151a78bfbfcSRobert Brose 
15270d64ceaSPaul Mackerras #ifdef CONFIG_GENERIC_NVRAM
15370d64ceaSPaul Mackerras 
15470d64ceaSPaul Mackerras /* Generic nvram hooks used by drivers/char/gen_nvram.c */
15570d64ceaSPaul Mackerras unsigned char nvram_read_byte(int addr)
15670d64ceaSPaul Mackerras {
15770d64ceaSPaul Mackerras 	if (ppc_md.nvram_read_val)
15870d64ceaSPaul Mackerras 		return ppc_md.nvram_read_val(addr);
15970d64ceaSPaul Mackerras 	return 0xff;
16070d64ceaSPaul Mackerras }
16170d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_read_byte);
16270d64ceaSPaul Mackerras 
16370d64ceaSPaul Mackerras void nvram_write_byte(unsigned char val, int addr)
16470d64ceaSPaul Mackerras {
16570d64ceaSPaul Mackerras 	if (ppc_md.nvram_write_val)
16670d64ceaSPaul Mackerras 		ppc_md.nvram_write_val(addr, val);
16770d64ceaSPaul Mackerras }
16870d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_write_byte);
16970d64ceaSPaul Mackerras 
170d331d830SMartyn Welch ssize_t nvram_get_size(void)
171d331d830SMartyn Welch {
172d331d830SMartyn Welch 	if (ppc_md.nvram_size)
173d331d830SMartyn Welch 		return ppc_md.nvram_size();
174d331d830SMartyn Welch 	return -1;
175d331d830SMartyn Welch }
176d331d830SMartyn Welch EXPORT_SYMBOL(nvram_get_size);
177d331d830SMartyn Welch 
17870d64ceaSPaul Mackerras void nvram_sync(void)
17970d64ceaSPaul Mackerras {
18070d64ceaSPaul Mackerras 	if (ppc_md.nvram_sync)
18170d64ceaSPaul Mackerras 		ppc_md.nvram_sync();
18270d64ceaSPaul Mackerras }
18370d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_sync);
18470d64ceaSPaul Mackerras 
18570d64ceaSPaul Mackerras #endif /* CONFIG_NVRAM */
18670d64ceaSPaul Mackerras 
187d15a261dSMathieu Malaterre static int __init ppc_init(void)
18870d64ceaSPaul Mackerras {
18970d64ceaSPaul Mackerras 	/* clear the progress line */
1905e41763aSGiuliano Pochini 	if (ppc_md.progress)
1915e41763aSGiuliano Pochini 		ppc_md.progress("             ", 0xffff);
19270d64ceaSPaul Mackerras 
19370d64ceaSPaul Mackerras 	/* call platform init */
19470d64ceaSPaul Mackerras 	if (ppc_md.init != NULL) {
19570d64ceaSPaul Mackerras 		ppc_md.init();
19670d64ceaSPaul Mackerras 	}
19770d64ceaSPaul Mackerras 	return 0;
19870d64ceaSPaul Mackerras }
19970d64ceaSPaul Mackerras arch_initcall(ppc_init);
20070d64ceaSPaul Mackerras 
201b1923caaSBenjamin Herrenschmidt void __init irqstack_early_init(void)
20285218827SKumar Gala {
20385218827SKumar Gala 	unsigned int i;
20485218827SKumar Gala 
20585218827SKumar Gala 	/* interrupt stacks must be in lowmem, we get that for free on ppc32
206e63075a3SBenjamin Herrenschmidt 	 * as the memblock is limited to lowmem by default */
20785218827SKumar Gala 	for_each_possible_cpu(i) {
20885218827SKumar Gala 		softirq_ctx[i] = (struct thread_info *)
2099a8dd708SMike Rapoport 			__va(memblock_phys_alloc(THREAD_SIZE, THREAD_SIZE));
21085218827SKumar Gala 		hardirq_ctx[i] = (struct thread_info *)
2119a8dd708SMike Rapoport 			__va(memblock_phys_alloc(THREAD_SIZE, THREAD_SIZE));
21285218827SKumar Gala 	}
21385218827SKumar Gala }
21485218827SKumar Gala 
215bcf0b088SKumar Gala #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
216b1923caaSBenjamin Herrenschmidt void __init exc_lvl_early_init(void)
217bcf0b088SKumar Gala {
2183e7f45adSDave Kleikamp 	unsigned int i, hw_cpu;
219bcf0b088SKumar Gala 
220bcf0b088SKumar Gala 	/* interrupt stacks must be in lowmem, we get that for free on ppc32
22195f72d1eSYinghai Lu 	 * as the memblock is limited to lowmem by MEMBLOCK_REAL_LIMIT */
222bcf0b088SKumar Gala 	for_each_possible_cpu(i) {
22304a34113SKevin Hao #ifdef CONFIG_SMP
2243e7f45adSDave Kleikamp 		hw_cpu = get_hard_smp_processor_id(i);
22504a34113SKevin Hao #else
22604a34113SKevin Hao 		hw_cpu = 0;
22704a34113SKevin Hao #endif
22804a34113SKevin Hao 
2293e7f45adSDave Kleikamp 		critirq_ctx[hw_cpu] = (struct thread_info *)
2309a8dd708SMike Rapoport 			__va(memblock_phys_alloc(THREAD_SIZE, THREAD_SIZE));
231bcf0b088SKumar Gala #ifdef CONFIG_BOOKE
2323e7f45adSDave Kleikamp 		dbgirq_ctx[hw_cpu] = (struct thread_info *)
2339a8dd708SMike Rapoport 			__va(memblock_phys_alloc(THREAD_SIZE, THREAD_SIZE));
2343e7f45adSDave Kleikamp 		mcheckirq_ctx[hw_cpu] = (struct thread_info *)
2359a8dd708SMike Rapoport 			__va(memblock_phys_alloc(THREAD_SIZE, THREAD_SIZE));
236bcf0b088SKumar Gala #endif
237bcf0b088SKumar Gala 	}
238bcf0b088SKumar Gala }
239bcf0b088SKumar Gala #endif
240bcf0b088SKumar Gala 
241b1923caaSBenjamin Herrenschmidt void __init setup_power_save(void)
24256571384SBenjamin Herrenschmidt {
243*d7cceda9SChristophe Leroy #ifdef CONFIG_PPC_BOOK3S_32
24456571384SBenjamin Herrenschmidt 	if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
24556571384SBenjamin Herrenschmidt 	    cpu_has_feature(CPU_FTR_CAN_NAP))
24656571384SBenjamin Herrenschmidt 		ppc_md.power_save = ppc6xx_idle;
24756571384SBenjamin Herrenschmidt #endif
24856571384SBenjamin Herrenschmidt 
24956571384SBenjamin Herrenschmidt #ifdef CONFIG_E500
25056571384SBenjamin Herrenschmidt 	if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
25156571384SBenjamin Herrenschmidt 	    cpu_has_feature(CPU_FTR_CAN_NAP))
25256571384SBenjamin Herrenschmidt 		ppc_md.power_save = e500_idle;
25356571384SBenjamin Herrenschmidt #endif
25456571384SBenjamin Herrenschmidt }
25556571384SBenjamin Herrenschmidt 
256b1923caaSBenjamin Herrenschmidt __init void initialize_cache_info(void)
2578f212cb2SBenjamin Herrenschmidt {
2588f212cb2SBenjamin Herrenschmidt 	/*
2598f212cb2SBenjamin Herrenschmidt 	 * Set cache line size based on type of cpu as a default.
2608f212cb2SBenjamin Herrenschmidt 	 * Systems with OF can look in the properties on the cpu node(s)
2618f212cb2SBenjamin Herrenschmidt 	 * for a possibly more accurate value.
2628f212cb2SBenjamin Herrenschmidt 	 */
2638f212cb2SBenjamin Herrenschmidt 	dcache_bsize = cur_cpu_spec->dcache_bsize;
2648f212cb2SBenjamin Herrenschmidt 	icache_bsize = cur_cpu_spec->icache_bsize;
2658f212cb2SBenjamin Herrenschmidt 	ucache_bsize = 0;
2668f212cb2SBenjamin Herrenschmidt 	if (cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE))
2678f212cb2SBenjamin Herrenschmidt 		ucache_bsize = icache_bsize = dcache_bsize;
2688f212cb2SBenjamin Herrenschmidt }
269