xref: /openbmc/linux/arch/powerpc/kernel/setup_32.c (revision db0a2b633da4216b767d7aed95ffe30d37409c7a)
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>
43*db0a2b63SChristophe Leroy #include <asm/kdump.h>
4470d64ceaSPaul Mackerras 
4503501dabSPaul Mackerras #define DBG(fmt...)
4603501dabSPaul Mackerras 
4770d64ceaSPaul Mackerras extern void bootx_init(unsigned long r4, unsigned long phys);
4870d64ceaSPaul Mackerras 
4980579e1fSPaul Mackerras int boot_cpuid_phys;
509974eec2SAndrew Gabbasov EXPORT_SYMBOL_GPL(boot_cpuid_phys);
5180579e1fSPaul Mackerras 
5213a9801eSNathan Lynch int smp_hw_index[NR_CPUS];
539445aa1aSAl Viro EXPORT_SYMBOL(smp_hw_index);
5413a9801eSNathan Lynch 
5570d64ceaSPaul Mackerras unsigned long ISA_DMA_THRESHOLD;
5670d64ceaSPaul Mackerras unsigned int DMA_MODE_READ;
5770d64ceaSPaul Mackerras unsigned int DMA_MODE_WRITE;
5870d64ceaSPaul Mackerras 
599445aa1aSAl Viro EXPORT_SYMBOL(ISA_DMA_THRESHOLD);
609445aa1aSAl Viro EXPORT_SYMBOL(DMA_MODE_READ);
619445aa1aSAl Viro EXPORT_SYMBOL(DMA_MODE_WRITE);
629445aa1aSAl Viro 
6370d64ceaSPaul Mackerras /*
64bd7c93ccSBenjamin Herrenschmidt  * We're called here very early in the boot.
6570d64ceaSPaul Mackerras  *
6670d64ceaSPaul Mackerras  * Note that the kernel may be running at an address which is different
6770d64ceaSPaul Mackerras  * from the address that it was linked at, so we must use RELOC/PTRRELOC
6870d64ceaSPaul Mackerras  * to access static data (including strings).  -- paulus
6970d64ceaSPaul Mackerras  */
704e491d14SSteven Rostedt notrace unsigned long __init early_init(unsigned long dt_ptr)
7170d64ceaSPaul Mackerras {
7270d64ceaSPaul Mackerras 	unsigned long offset = reloc_offset();
7370d64ceaSPaul Mackerras 
74dd184343SPaul Mackerras 	/* First zero the BSS -- use memset_io, some platforms don't have
75dd184343SPaul Mackerras 	 * caches on yet */
76556b09c8SMark A. Greer 	memset_io((void __iomem *)PTRRELOC(&__bss_start), 0,
77556b09c8SMark A. Greer 			__bss_stop - __bss_start);
78dd184343SPaul Mackerras 
7970d64ceaSPaul Mackerras 	/*
8070d64ceaSPaul Mackerras 	 * Identify the CPU type and fix up code sections
8170d64ceaSPaul Mackerras 	 * that depend on which cpu we have.
8270d64ceaSPaul Mackerras 	 */
839402c684SBenjamin Herrenschmidt 	identify_cpu(offset, mfspr(SPRN_PVR));
8442c4aaadSBenjamin Herrenschmidt 
859402c684SBenjamin Herrenschmidt 	apply_feature_fixups();
86d715e433SAnton Blanchard 
8770d64ceaSPaul Mackerras 	return KERNELBASE + offset;
8870d64ceaSPaul Mackerras }
8970d64ceaSPaul Mackerras 
9070d64ceaSPaul Mackerras 
9170d64ceaSPaul Mackerras /*
92bd7c93ccSBenjamin Herrenschmidt  * This is run before start_kernel(), the kernel has been relocated
93bd7c93ccSBenjamin Herrenschmidt  * and we are running with enough of the MMU enabled to have our
94bd7c93ccSBenjamin Herrenschmidt  * proper kernel virtual addresses
95bd7c93ccSBenjamin Herrenschmidt  *
96f9cc1d1fSBenjamin Herrenschmidt  * We do the initial parsing of the flat device-tree and prepares
97f9cc1d1fSBenjamin Herrenschmidt  * for the MMU to be fully initialized.
9870d64ceaSPaul Mackerras  */
99400c47d8SLEROY Christophe extern unsigned int memset_nocache_branch; /* Insn to be replaced by NOP */
100400c47d8SLEROY Christophe 
1016dece0ebSScott Wood notrace void __init machine_init(u64 dt_ptr)
10270d64ceaSPaul Mackerras {
103ad1b0122SChristophe Leroy 	unsigned int *addr = &memset_nocache_branch;
104ad1b0122SChristophe Leroy 	unsigned long insn;
105ad1b0122SChristophe Leroy 
10697f6e0ccSBenjamin Herrenschmidt 	/* Configure static keys first, now that we're relocated. */
10797f6e0ccSBenjamin Herrenschmidt 	setup_feature_keys();
10897f6e0ccSBenjamin Herrenschmidt 
109719c91ccSDavid Gibson 	/* Enable early debugging if any specified (see udbg.h) */
110719c91ccSDavid Gibson 	udbg_early_init();
11151d3082fSBenjamin Herrenschmidt 
1121cd03890SLEROY Christophe 	patch_instruction((unsigned int *)&memcpy, PPC_INST_NOP);
113ad1b0122SChristophe Leroy 
114ad1b0122SChristophe Leroy 	insn = create_cond_branch(addr, branch_target(addr), 0x820000);
115ad1b0122SChristophe Leroy 	patch_instruction(addr, insn);	/* replace b by bne cr0 */
1161cd03890SLEROY Christophe 
11751d3082fSBenjamin Herrenschmidt 	/* Do some early initialization based on the flat device tree */
11870d64ceaSPaul Mackerras 	early_init_devtree(__va(dt_ptr));
11970d64ceaSPaul Mackerras 
12091b191c7SDave Kleikamp 	early_init_mmu();
12191b191c7SDave Kleikamp 
122f8f50b1bSDale Farnsworth 	setup_kdump_trampoline();
12370d64ceaSPaul Mackerras }
12470d64ceaSPaul Mackerras 
12570d64ceaSPaul Mackerras /* Checks "l2cr=xxxx" command-line option */
126d15a261dSMathieu Malaterre static int __init ppc_setup_l2cr(char *str)
12770d64ceaSPaul Mackerras {
12870d64ceaSPaul Mackerras 	if (cpu_has_feature(CPU_FTR_L2CR)) {
12970d64ceaSPaul Mackerras 		unsigned long val = simple_strtoul(str, NULL, 0);
13070d64ceaSPaul Mackerras 		printk(KERN_INFO "l2cr set to %lx\n", val);
13170d64ceaSPaul Mackerras 		_set_L2CR(0);		/* force invalidate by disable cache */
13270d64ceaSPaul Mackerras 		_set_L2CR(val);		/* and enable it */
13370d64ceaSPaul Mackerras 	}
13470d64ceaSPaul Mackerras 	return 1;
13570d64ceaSPaul Mackerras }
13670d64ceaSPaul Mackerras __setup("l2cr=", ppc_setup_l2cr);
13770d64ceaSPaul Mackerras 
138a78bfbfcSRobert Brose /* Checks "l3cr=xxxx" command-line option */
139d15a261dSMathieu Malaterre static int __init ppc_setup_l3cr(char *str)
140a78bfbfcSRobert Brose {
141a78bfbfcSRobert Brose 	if (cpu_has_feature(CPU_FTR_L3CR)) {
142a78bfbfcSRobert Brose 		unsigned long val = simple_strtoul(str, NULL, 0);
143a78bfbfcSRobert Brose 		printk(KERN_INFO "l3cr set to %lx\n", val);
144a78bfbfcSRobert Brose 		_set_L3CR(val);		/* and enable it */
145a78bfbfcSRobert Brose 	}
146a78bfbfcSRobert Brose 	return 1;
147a78bfbfcSRobert Brose }
148a78bfbfcSRobert Brose __setup("l3cr=", ppc_setup_l3cr);
149a78bfbfcSRobert Brose 
15070d64ceaSPaul Mackerras #ifdef CONFIG_GENERIC_NVRAM
15170d64ceaSPaul Mackerras 
15270d64ceaSPaul Mackerras /* Generic nvram hooks used by drivers/char/gen_nvram.c */
15370d64ceaSPaul Mackerras unsigned char nvram_read_byte(int addr)
15470d64ceaSPaul Mackerras {
15570d64ceaSPaul Mackerras 	if (ppc_md.nvram_read_val)
15670d64ceaSPaul Mackerras 		return ppc_md.nvram_read_val(addr);
15770d64ceaSPaul Mackerras 	return 0xff;
15870d64ceaSPaul Mackerras }
15970d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_read_byte);
16070d64ceaSPaul Mackerras 
16170d64ceaSPaul Mackerras void nvram_write_byte(unsigned char val, int addr)
16270d64ceaSPaul Mackerras {
16370d64ceaSPaul Mackerras 	if (ppc_md.nvram_write_val)
16470d64ceaSPaul Mackerras 		ppc_md.nvram_write_val(addr, val);
16570d64ceaSPaul Mackerras }
16670d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_write_byte);
16770d64ceaSPaul Mackerras 
168d331d830SMartyn Welch ssize_t nvram_get_size(void)
169d331d830SMartyn Welch {
170d331d830SMartyn Welch 	if (ppc_md.nvram_size)
171d331d830SMartyn Welch 		return ppc_md.nvram_size();
172d331d830SMartyn Welch 	return -1;
173d331d830SMartyn Welch }
174d331d830SMartyn Welch EXPORT_SYMBOL(nvram_get_size);
175d331d830SMartyn Welch 
17670d64ceaSPaul Mackerras void nvram_sync(void)
17770d64ceaSPaul Mackerras {
17870d64ceaSPaul Mackerras 	if (ppc_md.nvram_sync)
17970d64ceaSPaul Mackerras 		ppc_md.nvram_sync();
18070d64ceaSPaul Mackerras }
18170d64ceaSPaul Mackerras EXPORT_SYMBOL(nvram_sync);
18270d64ceaSPaul Mackerras 
18370d64ceaSPaul Mackerras #endif /* CONFIG_NVRAM */
18470d64ceaSPaul Mackerras 
185d15a261dSMathieu Malaterre static int __init ppc_init(void)
18670d64ceaSPaul Mackerras {
18770d64ceaSPaul Mackerras 	/* clear the progress line */
1885e41763aSGiuliano Pochini 	if (ppc_md.progress)
1895e41763aSGiuliano Pochini 		ppc_md.progress("             ", 0xffff);
19070d64ceaSPaul Mackerras 
19170d64ceaSPaul Mackerras 	/* call platform init */
19270d64ceaSPaul Mackerras 	if (ppc_md.init != NULL) {
19370d64ceaSPaul Mackerras 		ppc_md.init();
19470d64ceaSPaul Mackerras 	}
19570d64ceaSPaul Mackerras 	return 0;
19670d64ceaSPaul Mackerras }
19770d64ceaSPaul Mackerras arch_initcall(ppc_init);
19870d64ceaSPaul Mackerras 
199b1923caaSBenjamin Herrenschmidt void __init irqstack_early_init(void)
20085218827SKumar Gala {
20185218827SKumar Gala 	unsigned int i;
20285218827SKumar Gala 
20385218827SKumar Gala 	/* interrupt stacks must be in lowmem, we get that for free on ppc32
204e63075a3SBenjamin Herrenschmidt 	 * as the memblock is limited to lowmem by default */
20585218827SKumar Gala 	for_each_possible_cpu(i) {
20685218827SKumar Gala 		softirq_ctx[i] = (struct thread_info *)
20795f72d1eSYinghai Lu 			__va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
20885218827SKumar Gala 		hardirq_ctx[i] = (struct thread_info *)
20995f72d1eSYinghai Lu 			__va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
21085218827SKumar Gala 	}
21185218827SKumar Gala }
21285218827SKumar Gala 
213bcf0b088SKumar Gala #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
214b1923caaSBenjamin Herrenschmidt void __init exc_lvl_early_init(void)
215bcf0b088SKumar Gala {
2163e7f45adSDave Kleikamp 	unsigned int i, hw_cpu;
217bcf0b088SKumar Gala 
218bcf0b088SKumar Gala 	/* interrupt stacks must be in lowmem, we get that for free on ppc32
21995f72d1eSYinghai Lu 	 * as the memblock is limited to lowmem by MEMBLOCK_REAL_LIMIT */
220bcf0b088SKumar Gala 	for_each_possible_cpu(i) {
22104a34113SKevin Hao #ifdef CONFIG_SMP
2223e7f45adSDave Kleikamp 		hw_cpu = get_hard_smp_processor_id(i);
22304a34113SKevin Hao #else
22404a34113SKevin Hao 		hw_cpu = 0;
22504a34113SKevin Hao #endif
22604a34113SKevin Hao 
2273e7f45adSDave Kleikamp 		critirq_ctx[hw_cpu] = (struct thread_info *)
22895f72d1eSYinghai Lu 			__va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
229bcf0b088SKumar Gala #ifdef CONFIG_BOOKE
2303e7f45adSDave Kleikamp 		dbgirq_ctx[hw_cpu] = (struct thread_info *)
23195f72d1eSYinghai Lu 			__va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
2323e7f45adSDave Kleikamp 		mcheckirq_ctx[hw_cpu] = (struct thread_info *)
23395f72d1eSYinghai Lu 			__va(memblock_alloc(THREAD_SIZE, THREAD_SIZE));
234bcf0b088SKumar Gala #endif
235bcf0b088SKumar Gala 	}
236bcf0b088SKumar Gala }
237bcf0b088SKumar Gala #endif
238bcf0b088SKumar Gala 
239b1923caaSBenjamin Herrenschmidt void __init setup_power_save(void)
24056571384SBenjamin Herrenschmidt {
24156571384SBenjamin Herrenschmidt #ifdef CONFIG_6xx
24256571384SBenjamin Herrenschmidt 	if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
24356571384SBenjamin Herrenschmidt 	    cpu_has_feature(CPU_FTR_CAN_NAP))
24456571384SBenjamin Herrenschmidt 		ppc_md.power_save = ppc6xx_idle;
24556571384SBenjamin Herrenschmidt #endif
24656571384SBenjamin Herrenschmidt 
24756571384SBenjamin Herrenschmidt #ifdef CONFIG_E500
24856571384SBenjamin Herrenschmidt 	if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
24956571384SBenjamin Herrenschmidt 	    cpu_has_feature(CPU_FTR_CAN_NAP))
25056571384SBenjamin Herrenschmidt 		ppc_md.power_save = e500_idle;
25156571384SBenjamin Herrenschmidt #endif
25256571384SBenjamin Herrenschmidt }
25356571384SBenjamin Herrenschmidt 
254b1923caaSBenjamin Herrenschmidt __init void initialize_cache_info(void)
2558f212cb2SBenjamin Herrenschmidt {
2568f212cb2SBenjamin Herrenschmidt 	/*
2578f212cb2SBenjamin Herrenschmidt 	 * Set cache line size based on type of cpu as a default.
2588f212cb2SBenjamin Herrenschmidt 	 * Systems with OF can look in the properties on the cpu node(s)
2598f212cb2SBenjamin Herrenschmidt 	 * for a possibly more accurate value.
2608f212cb2SBenjamin Herrenschmidt 	 */
2618f212cb2SBenjamin Herrenschmidt 	dcache_bsize = cur_cpu_spec->dcache_bsize;
2628f212cb2SBenjamin Herrenschmidt 	icache_bsize = cur_cpu_spec->icache_bsize;
2638f212cb2SBenjamin Herrenschmidt 	ucache_bsize = 0;
2648f212cb2SBenjamin Herrenschmidt 	if (cpu_has_feature(CPU_FTR_UNIFIED_ID_CACHE))
2658f212cb2SBenjamin Herrenschmidt 		ucache_bsize = icache_bsize = dcache_bsize;
2668f212cb2SBenjamin Herrenschmidt }
267