treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 226
[linux-block.git] / arch / powerpc / kernel / machine_kexec_32.c
CommitLineData
3d1229d6
ME
1/*
2 * PPC32 code to handle Linux booting another kernel.
3 *
4 * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
5 * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
6 * Copyright (C) 2005 IBM Corporation.
7 *
8 * This source code is licensed under the GNU General Public License,
9 * Version 2. See the file COPYING for more details.
10 */
11
12#include <linux/kexec.h>
13#include <linux/mm.h>
14#include <linux/string.h>
15#include <asm/cacheflush.h>
16#include <asm/hw_irq.h>
17#include <asm/io.h>
18
9402c95f 19typedef void (*relocate_new_kernel_t)(
3d1229d6
ME
20 unsigned long indirection_page,
21 unsigned long reboot_code_buffer,
ff2d8b19 22 unsigned long start_address) __noreturn;
3d1229d6
ME
23
24/*
25 * This is a generic machine_kexec function suitable at least for
26 * non-OpenFirmware embedded platforms.
27 * It merely copies the image relocation code to the control page and
28 * jumps to it.
29 * A platform specific function may just call this one.
30 */
31void default_machine_kexec(struct kimage *image)
32{
2efe55a9 33 extern const unsigned int relocate_new_kernel_size;
3d1229d6
ME
34 unsigned long page_list;
35 unsigned long reboot_code_buffer, reboot_code_buffer_phys;
36 relocate_new_kernel_t rnk;
37
38 /* Interrupts aren't acceptable while we reboot */
39 local_irq_disable();
40
c71635d2
MM
41 /* mask each interrupt so we are in a more sane state for the
42 * kexec kernel */
43 machine_kexec_mask_interrupts();
44
3d1229d6
ME
45 page_list = image->head;
46
47 /* we need both effective and real address here */
48 reboot_code_buffer =
49 (unsigned long)page_address(image->control_code_page);
50 reboot_code_buffer_phys = virt_to_phys((void *)reboot_code_buffer);
51
52 /* copy our kernel relocation code to the control code page */
53 memcpy((void *)reboot_code_buffer, relocate_new_kernel,
54 relocate_new_kernel_size);
55
56 flush_icache_range(reboot_code_buffer,
163f6876 57 reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE);
3d1229d6
ME
58 printk(KERN_INFO "Bye!\n");
59
6c284228
CL
60 if (!IS_ENABLED(CONFIG_FSL_BOOKE) && !IS_ENABLED(CONFIG_44x))
61 relocate_new_kernel(page_list, reboot_code_buffer_phys, image->start);
62
3d1229d6
ME
63 /* now call it */
64 rnk = (relocate_new_kernel_t) reboot_code_buffer;
65 (*rnk)(page_list, reboot_code_buffer_phys, image->start);
66}
67
68int default_machine_kexec_prepare(struct kimage *image)
69{
70 return 0;
71}