blob: affe5dcce7f465bcfcae706e3c3a1ebb24b44dbe [file] [log] [blame]
Michael Ellerman3d1229d2005-11-14 23:35:00 +11001/*
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
Joe Perches9402c952012-01-12 17:17:17 -080019typedef void (*relocate_new_kernel_t)(
Michael Ellerman3d1229d2005-11-14 23:35:00 +110020 unsigned long indirection_page,
21 unsigned long reboot_code_buffer,
Joe Perchesff2d8b12012-01-12 17:17:21 -080022 unsigned long start_address) __noreturn;
Michael Ellerman3d1229d2005-11-14 23:35:00 +110023
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{
Tobias Klauser2efe55a2006-06-26 18:57:34 +020033 extern const unsigned char relocate_new_kernel[];
34 extern const unsigned int relocate_new_kernel_size;
Michael Ellerman3d1229d2005-11-14 23:35:00 +110035 unsigned long page_list;
36 unsigned long reboot_code_buffer, reboot_code_buffer_phys;
37 relocate_new_kernel_t rnk;
38
39 /* Interrupts aren't acceptable while we reboot */
40 local_irq_disable();
41
Matthew McClintockc71635d2010-09-16 17:58:23 -050042 /* mask each interrupt so we are in a more sane state for the
43 * kexec kernel */
44 machine_kexec_mask_interrupts();
45
Michael Ellerman3d1229d2005-11-14 23:35:00 +110046 page_list = image->head;
47
48 /* we need both effective and real address here */
49 reboot_code_buffer =
50 (unsigned long)page_address(image->control_code_page);
51 reboot_code_buffer_phys = virt_to_phys((void *)reboot_code_buffer);
52
53 /* copy our kernel relocation code to the control code page */
54 memcpy((void *)reboot_code_buffer, relocate_new_kernel,
55 relocate_new_kernel_size);
56
57 flush_icache_range(reboot_code_buffer,
Huang Ying163f6872008-08-15 00:40:22 -070058 reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE);
Michael Ellerman3d1229d2005-11-14 23:35:00 +110059 printk(KERN_INFO "Bye!\n");
60
61 /* now call it */
62 rnk = (relocate_new_kernel_t) reboot_code_buffer;
63 (*rnk)(page_list, reboot_code_buffer_phys, image->start);
64}
65
66int default_machine_kexec_prepare(struct kimage *image)
67{
68 return 0;
69}