blob: c44efb73ab1ae31edf4388617d698551e71d4d15 [file] [log] [blame]
kogiidena9d441902006-01-16 22:14:10 -08001/*
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 * LANDISK/sh4 supported by kogiidena
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/mm.h>
13#include <linux/kexec.h>
14#include <linux/delay.h>
15#include <linux/reboot.h>
Paul Mundtc3b4adf2008-08-04 13:42:49 +090016#include <linux/numa.h>
Magnus Dammb7cf6dd2009-03-18 08:51:29 +000017#include <linux/suspend.h>
kogiidena9d441902006-01-16 22:14:10 -080018#include <asm/pgtable.h>
19#include <asm/pgalloc.h>
20#include <asm/mmu_context.h>
21#include <asm/io.h>
22#include <asm/cacheflush.h>
23
Magnus Dammb7cf6dd2009-03-18 08:51:29 +000024typedef void (*relocate_new_kernel_t)(unsigned long indirection_page,
25 unsigned long reboot_code_buffer,
26 unsigned long start_address);
kogiidena9d441902006-01-16 22:14:10 -080027
Tobias Klauser2efe55a2006-06-26 18:57:34 +020028extern const unsigned char relocate_new_kernel[];
29extern const unsigned int relocate_new_kernel_size;
kogiidena9d441902006-01-16 22:14:10 -080030extern void *gdb_vbr_vector;
Magnus Dammb7cf6dd2009-03-18 08:51:29 +000031extern void *vbr_base;
kogiidena9d441902006-01-16 22:14:10 -080032
kogiidena9d441902006-01-16 22:14:10 -080033void machine_shutdown(void)
34{
35}
36
37void machine_crash_shutdown(struct pt_regs *regs)
38{
39}
40
41/*
42 * Do what every setup is needed on image and the
43 * reboot code buffer to allow us to avoid allocations
44 * later.
45 */
46int machine_kexec_prepare(struct kimage *image)
47{
48 return 0;
49}
50
51void machine_kexec_cleanup(struct kimage *image)
52{
53}
54
55static void kexec_info(struct kimage *image)
56{
57 int i;
58 printk("kexec information\n");
59 for (i = 0; i < image->nr_segments; i++) {
60 printk(" segment[%d]: 0x%08x - 0x%08x (0x%08x)\n",
61 i,
62 (unsigned int)image->segment[i].mem,
Paul Mundt4d5ade52007-04-27 11:25:57 +090063 (unsigned int)image->segment[i].mem +
64 image->segment[i].memsz,
kogiidena9d441902006-01-16 22:14:10 -080065 (unsigned int)image->segment[i].memsz);
Paul Mundt4d5ade52007-04-27 11:25:57 +090066 }
kogiidena9d441902006-01-16 22:14:10 -080067 printk(" start : 0x%08x\n\n", (unsigned int)image->start);
68}
69
kogiidena9d441902006-01-16 22:14:10 -080070/*
71 * Do not allocate memory (or fail in any way) in machine_kexec().
72 * We are past the point of no return, committed to rebooting now.
73 */
Huang Ying3ab83522008-07-25 19:45:07 -070074void machine_kexec(struct kimage *image)
kogiidena9d441902006-01-16 22:14:10 -080075{
kogiidena9d441902006-01-16 22:14:10 -080076 unsigned long page_list;
77 unsigned long reboot_code_buffer;
kogiidena9d441902006-01-16 22:14:10 -080078 relocate_new_kernel_t rnk;
Magnus Damme4e063d2009-03-18 08:49:45 +000079 unsigned long entry;
80 unsigned long *ptr;
81
82 /*
83 * Nicked from the mips version of machine_kexec():
84 * The generic kexec code builds a page list with physical
85 * addresses. Use phys_to_virt() to convert them to virtual.
86 */
87 for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
88 ptr = (entry & IND_INDIRECTION) ?
89 phys_to_virt(entry & PAGE_MASK) : ptr + 1) {
90 if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
91 *ptr & IND_DESTINATION)
92 *ptr = (unsigned long) phys_to_virt(*ptr);
93 }
kogiidena9d441902006-01-16 22:14:10 -080094
Magnus Dammb7cf6dd2009-03-18 08:51:29 +000095#ifdef CONFIG_KEXEC_JUMP
96 if (image->preserve_context)
97 save_processor_state();
98#endif
99
kogiidena9d441902006-01-16 22:14:10 -0800100 /* Interrupts aren't acceptable while we reboot */
101 local_irq_disable();
102
103 page_list = image->head;
104
105 /* we need both effective and real address here */
106 reboot_code_buffer =
107 (unsigned long)page_address(image->control_code_page);
108
109 /* copy our kernel relocation code to the control code page */
110 memcpy((void *)reboot_code_buffer, relocate_new_kernel,
111 relocate_new_kernel_size);
112
113 kexec_info(image);
114 flush_cache_all();
115
Magnus Damm7be5c552009-03-18 08:47:31 +0000116 set_bl_bit();
117#if defined(CONFIG_SH_STANDARD_BIOS)
118 asm volatile("ldc %0, vbr" :
119 : "r" (((unsigned long) gdb_vbr_vector) - 0x100)
120 : "memory");
121#endif
kogiidena9d441902006-01-16 22:14:10 -0800122 /* now call it */
123 rnk = (relocate_new_kernel_t) reboot_code_buffer;
Magnus Damme4e063d2009-03-18 08:49:45 +0000124 (*rnk)(page_list, reboot_code_buffer, image->start);
Magnus Dammb7cf6dd2009-03-18 08:51:29 +0000125
126#ifdef CONFIG_KEXEC_JUMP
127 asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory");
128 local_irq_disable();
129 clear_bl_bit();
130 if (image->preserve_context)
131 restore_processor_state();
132
133 /* Convert page list back to physical addresses, what a mess. */
134 for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
135 ptr = (*ptr & IND_INDIRECTION) ?
136 phys_to_virt(*ptr & PAGE_MASK) : ptr + 1) {
137 if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
138 *ptr & IND_DESTINATION)
139 *ptr = virt_to_phys(*ptr);
140 }
141#endif
kogiidena9d441902006-01-16 22:14:10 -0800142}
143
Paul Mundtc3b4adf2008-08-04 13:42:49 +0900144void arch_crash_save_vmcoreinfo(void)
145{
146#ifdef CONFIG_NUMA
147 VMCOREINFO_SYMBOL(node_data);
148 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
149#endif
150}