blob: a72787747df7efa0ec8e73395a3b799b71c266bd [file] [log] [blame]
Eric W. Biederman70765aa2005-06-25 14:58:07 -07001/*
2 * machine_kexec.c - handle transition of Linux booting another kernel
3 * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com>
4 *
5 * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
6 *
7 * This source code is licensed under the GNU General Public License,
8 * Version 2. See the file COPYING for more details.
9 */
10
11#include <linux/mm.h>
12#include <linux/kexec.h>
13#include <linux/delay.h>
14#include <linux/reboot.h>
15#include <asm/pgtable.h>
16#include <asm/pgalloc.h>
17#include <asm/mmu_context.h>
18#include <asm/io.h>
19#include <asm/hw_irq.h>
20#include <asm/cacheflush.h>
21#include <asm/machdep.h>
22
23typedef NORET_TYPE void (*relocate_new_kernel_t)(
Maneesh Soni72414d32005-06-25 14:58:28 -070024 unsigned long indirection_page,
25 unsigned long reboot_code_buffer,
26 unsigned long start_address) ATTRIB_NORET;
Eric W. Biederman70765aa2005-06-25 14:58:07 -070027
28const extern unsigned char relocate_new_kernel[];
29const extern unsigned int relocate_new_kernel_size;
30
Albert Herranzbc75a242005-07-12 13:58:34 -070031/*
32 * Provide a dummy crash_notes definition while crash dump arrives to ppc.
33 * This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
34 */
35void *crash_notes = NULL;
36
Eric W. Biederman70765aa2005-06-25 14:58:07 -070037void machine_shutdown(void)
38{
Maneesh Soni72414d32005-06-25 14:58:28 -070039 if (ppc_md.machine_shutdown)
Eric W. Biederman70765aa2005-06-25 14:58:07 -070040 ppc_md.machine_shutdown();
Eric W. Biederman70765aa2005-06-25 14:58:07 -070041}
42
Alexander Nyberg6e274d12005-06-25 14:58:26 -070043void machine_crash_shutdown(struct pt_regs *regs)
Eric W. Biederman70765aa2005-06-25 14:58:07 -070044{
Maneesh Soni72414d32005-06-25 14:58:28 -070045 if (ppc_md.machine_crash_shutdown)
Eric W. Biederman70765aa2005-06-25 14:58:07 -070046 ppc_md.machine_crash_shutdown();
Eric W. Biederman70765aa2005-06-25 14:58:07 -070047}
48
49/*
50 * Do what every setup is needed on image and the
51 * reboot code buffer to allow us to avoid allocations
52 * later.
53 */
54int machine_kexec_prepare(struct kimage *image)
55{
Maneesh Soni72414d32005-06-25 14:58:28 -070056 if (ppc_md.machine_kexec_prepare)
Eric W. Biederman70765aa2005-06-25 14:58:07 -070057 return ppc_md.machine_kexec_prepare(image);
Eric W. Biederman70765aa2005-06-25 14:58:07 -070058 /*
59 * Fail if platform doesn't provide its own machine_kexec_prepare
60 * implementation.
61 */
62 return -ENOSYS;
63}
64
65void machine_kexec_cleanup(struct kimage *image)
66{
Maneesh Soni72414d32005-06-25 14:58:28 -070067 if (ppc_md.machine_kexec_cleanup)
Eric W. Biederman70765aa2005-06-25 14:58:07 -070068 ppc_md.machine_kexec_cleanup(image);
Eric W. Biederman70765aa2005-06-25 14:58:07 -070069}
70
71/*
72 * Do not allocate memory (or fail in any way) in machine_kexec().
73 * We are past the point of no return, committed to rebooting now.
74 */
75NORET_TYPE void machine_kexec(struct kimage *image)
76{
Maneesh Soni72414d32005-06-25 14:58:28 -070077 if (ppc_md.machine_kexec)
Eric W. Biederman70765aa2005-06-25 14:58:07 -070078 ppc_md.machine_kexec(image);
Maneesh Soni72414d32005-06-25 14:58:28 -070079 else {
Eric W. Biederman70765aa2005-06-25 14:58:07 -070080 /*
81 * Fall back to normal restart if platform doesn't provide
82 * its own kexec function, and user insist to kexec...
83 */
84 machine_restart(NULL);
85 }
86 for(;;);
87}
88
Eric W. Biederman70765aa2005-06-25 14:58:07 -070089/*
90 * This is a generic machine_kexec function suitable at least for
91 * non-OpenFirmware embedded platforms.
92 * It merely copies the image relocation code to the control page and
93 * jumps to it.
94 * A platform specific function may just call this one.
95 */
96void machine_kexec_simple(struct kimage *image)
97{
98 unsigned long page_list;
99 unsigned long reboot_code_buffer, reboot_code_buffer_phys;
100 relocate_new_kernel_t rnk;
101
102 /* Interrupts aren't acceptable while we reboot */
103 local_irq_disable();
104
105 page_list = image->head;
106
107 /* we need both effective and real address here */
108 reboot_code_buffer =
Maneesh Soni72414d32005-06-25 14:58:28 -0700109 (unsigned long)page_address(image->control_code_page);
Eric W. Biederman70765aa2005-06-25 14:58:07 -0700110 reboot_code_buffer_phys = virt_to_phys((void *)reboot_code_buffer);
111
112 /* copy our kernel relocation code to the control code page */
Maneesh Soni72414d32005-06-25 14:58:28 -0700113 memcpy((void *)reboot_code_buffer, relocate_new_kernel,
114 relocate_new_kernel_size);
Eric W. Biederman70765aa2005-06-25 14:58:07 -0700115
116 flush_icache_range(reboot_code_buffer,
Maneesh Soni72414d32005-06-25 14:58:28 -0700117 reboot_code_buffer + KEXEC_CONTROL_CODE_SIZE);
Eric W. Biederman70765aa2005-06-25 14:58:07 -0700118 printk(KERN_INFO "Bye!\n");
119
120 /* now call it */
121 rnk = (relocate_new_kernel_t) reboot_code_buffer;
122 (*rnk)(page_list, reboot_code_buffer_phys, image->start);
123}
124