2019-05-19 20:08:55 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-10-06 10:06:20 +08:00
|
|
|
/*
|
|
|
|
* Common prep/pmac/chrp boot and setup code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/reboot.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/initrd.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/root_dev.h>
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/console.h>
|
2010-07-12 12:36:09 +08:00
|
|
|
#include <linux/memblock.h>
|
2016-01-14 12:33:46 +08:00
|
|
|
#include <linux/export.h>
|
2019-01-15 12:18:56 +08:00
|
|
|
#include <linux/nvram.h>
|
2005-10-06 10:06:20 +08:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/smp.h>
|
|
|
|
#include <asm/elf.h>
|
|
|
|
#include <asm/cputable.h>
|
|
|
|
#include <asm/bootx.h>
|
|
|
|
#include <asm/btext.h>
|
|
|
|
#include <asm/machdep.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-10-06 10:06:20 +08:00
|
|
|
#include <asm/pmac_feature.h>
|
|
|
|
#include <asm/sections.h>
|
|
|
|
#include <asm/nvram.h>
|
|
|
|
#include <asm/xmon.h>
|
2005-10-26 12:57:33 +08:00
|
|
|
#include <asm/time.h>
|
2005-11-23 14:56:06 +08:00
|
|
|
#include <asm/serial.h>
|
2005-11-23 14:57:25 +08:00
|
|
|
#include <asm/udbg.h>
|
2015-09-16 18:04:51 +08:00
|
|
|
#include <asm/code-patching.h>
|
2016-07-23 17:12:40 +08:00
|
|
|
#include <asm/cpu_has_feature.h>
|
2018-03-08 19:31:59 +08:00
|
|
|
#include <asm/asm-prototypes.h>
|
2018-07-06 00:24:51 +08:00
|
|
|
#include <asm/kdump.h>
|
2018-07-06 00:25:01 +08:00
|
|
|
#include <asm/feature-fixups.h>
|
2019-09-12 21:49:43 +08:00
|
|
|
#include <asm/early_ioremap.h>
|
2005-10-06 10:06:20 +08:00
|
|
|
|
2018-06-23 03:26:53 +08:00
|
|
|
#include "setup.h"
|
|
|
|
|
2005-10-26 15:11:18 +08:00
|
|
|
#define DBG(fmt...)
|
|
|
|
|
2005-10-06 10:06:20 +08:00
|
|
|
extern void bootx_init(unsigned long r4, unsigned long phys);
|
|
|
|
|
2005-10-27 20:42:04 +08:00
|
|
|
int boot_cpuid_phys;
|
2011-07-16 11:22:13 +08:00
|
|
|
EXPORT_SYMBOL_GPL(boot_cpuid_phys);
|
2005-10-27 20:42:04 +08:00
|
|
|
|
2008-12-10 22:28:41 +08:00
|
|
|
int smp_hw_index[NR_CPUS];
|
2016-01-14 12:33:46 +08:00
|
|
|
EXPORT_SYMBOL(smp_hw_index);
|
2008-12-10 22:28:41 +08:00
|
|
|
|
2005-10-06 10:06:20 +08:00
|
|
|
unsigned long ISA_DMA_THRESHOLD;
|
|
|
|
unsigned int DMA_MODE_READ;
|
|
|
|
unsigned int DMA_MODE_WRITE;
|
|
|
|
|
2016-01-14 12:33:46 +08:00
|
|
|
EXPORT_SYMBOL(DMA_MODE_READ);
|
|
|
|
EXPORT_SYMBOL(DMA_MODE_WRITE);
|
|
|
|
|
2005-10-06 10:06:20 +08:00
|
|
|
/*
|
2016-07-05 13:03:45 +08:00
|
|
|
* This is run before start_kernel(), the kernel has been relocated
|
|
|
|
* and we are running with enough of the MMU enabled to have our
|
|
|
|
* proper kernel virtual addresses
|
|
|
|
*
|
2016-08-10 15:32:38 +08:00
|
|
|
* We do the initial parsing of the flat device-tree and prepares
|
|
|
|
* for the MMU to be fully initialized.
|
2005-10-06 10:06:20 +08:00
|
|
|
*/
|
2011-07-25 19:29:33 +08:00
|
|
|
notrace void __init machine_init(u64 dt_ptr)
|
2005-10-06 10:06:20 +08:00
|
|
|
{
|
2018-11-10 01:33:20 +08:00
|
|
|
unsigned int *addr = (unsigned int *)patch_site_addr(&patch__memset_nocache);
|
2017-08-23 22:54:38 +08:00
|
|
|
unsigned long insn;
|
|
|
|
|
2016-08-10 15:27:34 +08:00
|
|
|
/* Configure static keys first, now that we're relocated. */
|
|
|
|
setup_feature_keys();
|
|
|
|
|
2019-09-12 21:49:43 +08:00
|
|
|
early_ioremap_setup();
|
|
|
|
|
2007-02-13 12:54:22 +08:00
|
|
|
/* Enable early debugging if any specified (see udbg.h) */
|
|
|
|
udbg_early_init();
|
2005-11-23 14:57:25 +08:00
|
|
|
|
2018-08-09 16:14:41 +08:00
|
|
|
patch_instruction_site(&patch__memcpy_nocache, PPC_INST_NOP);
|
2017-08-23 22:54:38 +08:00
|
|
|
|
|
|
|
insn = create_cond_branch(addr, branch_target(addr), 0x820000);
|
|
|
|
patch_instruction(addr, insn); /* replace b by bne cr0 */
|
2015-09-16 18:04:51 +08:00
|
|
|
|
2005-11-23 14:57:25 +08:00
|
|
|
/* Do some early initialization based on the flat device tree */
|
2005-10-06 10:06:20 +08:00
|
|
|
early_init_devtree(__va(dt_ptr));
|
|
|
|
|
2011-07-05 02:38:03 +08:00
|
|
|
early_init_mmu();
|
|
|
|
|
2008-12-17 18:09:26 +08:00
|
|
|
setup_kdump_trampoline();
|
2005-10-06 10:06:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks "l2cr=xxxx" command-line option */
|
2018-03-08 04:32:55 +08:00
|
|
|
static int __init ppc_setup_l2cr(char *str)
|
2005-10-06 10:06:20 +08:00
|
|
|
{
|
|
|
|
if (cpu_has_feature(CPU_FTR_L2CR)) {
|
|
|
|
unsigned long val = simple_strtoul(str, NULL, 0);
|
|
|
|
printk(KERN_INFO "l2cr set to %lx\n", val);
|
|
|
|
_set_L2CR(0); /* force invalidate by disable cache */
|
|
|
|
_set_L2CR(val); /* and enable it */
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("l2cr=", ppc_setup_l2cr);
|
|
|
|
|
2008-03-29 04:20:23 +08:00
|
|
|
/* Checks "l3cr=xxxx" command-line option */
|
2018-03-08 04:32:55 +08:00
|
|
|
static int __init ppc_setup_l3cr(char *str)
|
2008-03-29 04:20:23 +08:00
|
|
|
{
|
|
|
|
if (cpu_has_feature(CPU_FTR_L3CR)) {
|
|
|
|
unsigned long val = simple_strtoul(str, NULL, 0);
|
|
|
|
printk(KERN_INFO "l3cr set to %lx\n", val);
|
|
|
|
_set_L3CR(val); /* and enable it */
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("l3cr=", ppc_setup_l3cr);
|
|
|
|
|
2018-03-08 04:32:55 +08:00
|
|
|
static int __init ppc_init(void)
|
2005-10-06 10:06:20 +08:00
|
|
|
{
|
|
|
|
/* clear the progress line */
|
2007-03-27 13:40:28 +08:00
|
|
|
if (ppc_md.progress)
|
|
|
|
ppc_md.progress(" ", 0xffff);
|
2005-10-06 10:06:20 +08:00
|
|
|
|
|
|
|
/* call platform init */
|
|
|
|
if (ppc_md.init != NULL) {
|
|
|
|
ppc_md.init();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
arch_initcall(ppc_init);
|
|
|
|
|
2019-01-31 18:08:44 +08:00
|
|
|
static void *__init alloc_stack(void)
|
|
|
|
{
|
2019-12-21 16:32:28 +08:00
|
|
|
void *ptr = memblock_alloc(THREAD_SIZE, THREAD_ALIGN);
|
2019-01-31 18:08:44 +08:00
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
panic("cannot allocate %d bytes for stack at %pS\n",
|
|
|
|
THREAD_SIZE, (void *)_RET_IP_);
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2016-07-05 13:07:51 +08:00
|
|
|
void __init irqstack_early_init(void)
|
2008-04-28 14:21:22 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2019-12-21 16:32:30 +08:00
|
|
|
if (IS_ENABLED(CONFIG_VMAP_STACK))
|
|
|
|
return;
|
|
|
|
|
2008-04-28 14:21:22 +08:00
|
|
|
/* interrupt stacks must be in lowmem, we get that for free on ppc32
|
2010-07-07 06:39:01 +08:00
|
|
|
* as the memblock is limited to lowmem by default */
|
2008-04-28 14:21:22 +08:00
|
|
|
for_each_possible_cpu(i) {
|
2019-01-31 18:08:44 +08:00
|
|
|
softirq_ctx[i] = alloc_stack();
|
|
|
|
hardirq_ctx[i] = alloc_stack();
|
2008-04-28 14:21:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
powerpc/32: Add early stack overflow detection with VMAP stack.
To avoid recursive faults, stack overflow detection has to be
performed before writing in the stack in exception prologs.
Do it by checking the alignment. If the stack pointer alignment is
wrong, it means it is pointing to the following or preceding page.
Without VMAP stack, a stack overflow is catastrophic. With VMAP
stack, a stack overflow isn't destructive, so don't panic. Kill
the task with SIGSEGV instead.
A dedicated overflow stack is set up for each CPU.
lkdtm: Performing direct entry EXHAUST_STACK
lkdtm: Calling function with 512 frame size to depth 32 ...
lkdtm: loop 32/32 ...
lkdtm: loop 31/32 ...
lkdtm: loop 30/32 ...
lkdtm: loop 29/32 ...
lkdtm: loop 28/32 ...
lkdtm: loop 27/32 ...
lkdtm: loop 26/32 ...
lkdtm: loop 25/32 ...
lkdtm: loop 24/32 ...
lkdtm: loop 23/32 ...
lkdtm: loop 22/32 ...
lkdtm: loop 21/32 ...
lkdtm: loop 20/32 ...
Kernel stack overflow in process test[359], r1=c900c008
Oops: Kernel stack overflow, sig: 6 [#1]
BE PAGE_SIZE=4K MMU=Hash PowerMac
Modules linked in:
CPU: 0 PID: 359 Comm: test Not tainted 5.3.0-rc7+ #2225
NIP: c0622060 LR: c0626710 CTR: 00000000
REGS: c0895f48 TRAP: 0000 Not tainted (5.3.0-rc7+)
MSR: 00001032 <ME,IR,DR,RI> CR: 28004224 XER: 00000000
GPR00: c0626ca4 c900c008 c783c000 c07335cc c900c010 c07335cc c900c0f0 c07335cc
GPR08: c900c0f0 00000001 00000000 00000000 28008222 00000000 00000000 00000000
GPR16: 00000000 00000000 10010128 10010000 b799c245 10010158 c07335cc 00000025
GPR24: c0690000 c08b91d4 c068f688 00000020 c900c0f0 c068f668 c08b95b4 c08b91d4
NIP [c0622060] format_decode+0x0/0x4d4
LR [c0626710] vsnprintf+0x80/0x5fc
Call Trace:
[c900c068] [c0626ca4] vscnprintf+0x18/0x48
[c900c078] [c007b944] vprintk_store+0x40/0x214
[c900c0b8] [c007bf50] vprintk_emit+0x90/0x1dc
[c900c0e8] [c007c5cc] printk+0x50/0x60
[c900c128] [c03da5b0] recursive_loop+0x44/0x6c
[c900c338] [c03da5c4] recursive_loop+0x58/0x6c
[c900c548] [c03da5c4] recursive_loop+0x58/0x6c
[c900c758] [c03da5c4] recursive_loop+0x58/0x6c
[c900c968] [c03da5c4] recursive_loop+0x58/0x6c
[c900cb78] [c03da5c4] recursive_loop+0x58/0x6c
[c900cd88] [c03da5c4] recursive_loop+0x58/0x6c
[c900cf98] [c03da5c4] recursive_loop+0x58/0x6c
[c900d1a8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d3b8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d5c8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d7d8] [c03da5c4] recursive_loop+0x58/0x6c
[c900d9e8] [c03da5c4] recursive_loop+0x58/0x6c
[c900dbf8] [c03da5c4] recursive_loop+0x58/0x6c
[c900de08] [c03da67c] lkdtm_EXHAUST_STACK+0x30/0x4c
[c900de18] [c03da3e8] direct_entry+0xc8/0x140
[c900de48] [c029fb40] full_proxy_write+0x64/0xcc
[c900de68] [c01500f8] __vfs_write+0x30/0x1d0
[c900dee8] [c0152cb8] vfs_write+0xb8/0x1d4
[c900df08] [c0152f7c] ksys_write+0x58/0xe8
[c900df38] [c0014208] ret_from_syscall+0x0/0x34
--- interrupt: c01 at 0xf806664
LR = 0x1000c868
Instruction dump:
4bffff91 80010014 7c832378 7c0803a6 38210010 4e800020 3d20c08a 3ca0c089
8089a0cc 38a58f0c 38600001 4ba2d494 <9421ffe0> 7c0802a6 bfc10018 7c9f2378
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/1b89c121b4070c7ee99e4f22cc178f15a736b07b.1576916812.git.christophe.leroy@c-s.fr
2019-12-21 16:32:29 +08:00
|
|
|
#ifdef CONFIG_VMAP_STACK
|
|
|
|
void *emergency_ctx[NR_CPUS] __ro_after_init;
|
|
|
|
|
|
|
|
void __init emergency_stack_init(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for_each_possible_cpu(i)
|
|
|
|
emergency_ctx[i] = alloc_stack();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-04-30 16:49:55 +08:00
|
|
|
#if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
|
2016-07-05 13:07:51 +08:00
|
|
|
void __init exc_lvl_early_init(void)
|
2008-04-30 16:49:55 +08:00
|
|
|
{
|
2010-08-18 14:44:25 +08:00
|
|
|
unsigned int i, hw_cpu;
|
2008-04-30 16:49:55 +08:00
|
|
|
|
|
|
|
/* interrupt stacks must be in lowmem, we get that for free on ppc32
|
2010-07-12 12:36:09 +08:00
|
|
|
* as the memblock is limited to lowmem by MEMBLOCK_REAL_LIMIT */
|
2008-04-30 16:49:55 +08:00
|
|
|
for_each_possible_cpu(i) {
|
2014-01-29 18:24:54 +08:00
|
|
|
#ifdef CONFIG_SMP
|
2010-08-18 14:44:25 +08:00
|
|
|
hw_cpu = get_hard_smp_processor_id(i);
|
2014-01-29 18:24:54 +08:00
|
|
|
#else
|
|
|
|
hw_cpu = 0;
|
|
|
|
#endif
|
|
|
|
|
2019-01-31 18:08:44 +08:00
|
|
|
critirq_ctx[hw_cpu] = alloc_stack();
|
2008-04-30 16:49:55 +08:00
|
|
|
#ifdef CONFIG_BOOKE
|
2019-01-31 18:08:44 +08:00
|
|
|
dbgirq_ctx[hw_cpu] = alloc_stack();
|
|
|
|
mcheckirq_ctx[hw_cpu] = alloc_stack();
|
2008-04-30 16:49:55 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-07-05 13:07:51 +08:00
|
|
|
void __init setup_power_save(void)
|
2016-07-05 13:04:05 +08:00
|
|
|
{
|
2018-11-17 18:24:56 +08:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_32
|
2016-07-05 13:04:05 +08:00
|
|
|
if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
|
|
|
|
cpu_has_feature(CPU_FTR_CAN_NAP))
|
|
|
|
ppc_md.power_save = ppc6xx_idle;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_E500
|
|
|
|
if (cpu_has_feature(CPU_FTR_CAN_DOZE) ||
|
|
|
|
cpu_has_feature(CPU_FTR_CAN_NAP))
|
|
|
|
ppc_md.power_save = e500_idle;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-07-05 13:07:51 +08:00
|
|
|
__init void initialize_cache_info(void)
|
2016-07-05 13:04:10 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Set cache line size based on type of cpu as a default.
|
|
|
|
* Systems with OF can look in the properties on the cpu node(s)
|
|
|
|
* for a possibly more accurate value.
|
|
|
|
*/
|
|
|
|
dcache_bsize = cur_cpu_spec->dcache_bsize;
|
|
|
|
icache_bsize = cur_cpu_spec->icache_bsize;
|
|
|
|
ucache_bsize = 0;
|
2019-08-26 23:52:18 +08:00
|
|
|
if (IS_ENABLED(CONFIG_PPC_BOOK3S_601) || IS_ENABLED(CONFIG_E200))
|
2016-07-05 13:04:10 +08:00
|
|
|
ucache_bsize = icache_bsize = dcache_bsize;
|
|
|
|
}
|