2 * handle transition of Linux booting another kernel
3 * Copyright (C) 2002-2005 Eric Biederman <ebiederm@xmission.com>
5 * This source code is licensed under the GNU General Public License,
6 * Version 2. See the file COPYING for more details.
10 #include <linux/kexec.h>
11 #include <linux/delay.h>
12 #include <linux/init.h>
13 #include <linux/numa.h>
14 #include <linux/ftrace.h>
16 #include <asm/pgtable.h>
17 #include <asm/pgalloc.h>
18 #include <asm/tlbflush.h>
19 #include <asm/mmu_context.h>
22 #include <asm/cpufeature.h>
24 #include <asm/system.h>
25 #include <asm/cacheflush.h>
27 #define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE)))
28 static u32 kexec_pgd[1024] PAGE_ALIGNED;
30 static u32 kexec_pmd0[1024] PAGE_ALIGNED;
31 static u32 kexec_pmd1[1024] PAGE_ALIGNED;
33 static u32 kexec_pte0[1024] PAGE_ALIGNED;
34 static u32 kexec_pte1[1024] PAGE_ALIGNED;
36 static void set_idt(void *newidt, __u16 limit)
38 struct desc_ptr curidt;
40 /* ia32 supports unaliged loads & stores */
42 curidt.address = (unsigned long)newidt;
48 static void set_gdt(void *newgdt, __u16 limit)
50 struct desc_ptr curgdt;
52 /* ia32 supports unaligned loads & stores */
54 curgdt.address = (unsigned long)newgdt;
59 static void load_segments(void)
62 #define STR(X) __STR(X)
64 __asm__ __volatile__ (
65 "\tljmp $"STR(__KERNEL_CS)",$1f\n"
67 "\tmovl $"STR(__KERNEL_DS)",%%eax\n"
79 * A architecture hook called to validate the
80 * proposed image and prepare the control pages
81 * as needed. The pages for KEXEC_CONTROL_CODE_SIZE
82 * have been allocated, but the segments have yet
83 * been copied into the kernel.
85 * Do what every setup is needed on image and the
86 * reboot code buffer to allow us to avoid allocations
89 * Make control page executable.
91 int machine_kexec_prepare(struct kimage *image)
94 set_pages_x(image->control_code_page, 1);
99 * Undo anything leftover by machine_kexec_prepare
100 * when an image is freed.
102 void machine_kexec_cleanup(struct kimage *image)
105 set_pages_nx(image->control_code_page, 1);
109 * Do not allocate memory (or fail in any way) in machine_kexec().
110 * We are past the point of no return, committed to rebooting now.
112 void machine_kexec(struct kimage *image)
114 unsigned long page_list[PAGES_NR];
116 asmlinkage unsigned long
117 (*relocate_kernel_ptr)(unsigned long indirection_page,
118 unsigned long control_page,
119 unsigned long start_address,
120 unsigned int has_pae,
121 unsigned int preserve_context);
125 /* Interrupts aren't acceptable while we reboot */
128 if (image->preserve_context) {
129 #ifdef CONFIG_X86_IO_APIC
130 /* We need to put APICs in legacy mode so that we can
131 * get timer interrupts in second kernel. kexec/kdump
132 * paths already have calls to disable_IO_APIC() in
133 * one form or other. kexec jump path also need
140 control_page = page_address(image->control_code_page);
141 memcpy(control_page, relocate_kernel, PAGE_SIZE/2);
143 relocate_kernel_ptr = control_page;
144 page_list[PA_CONTROL_PAGE] = __pa(control_page);
145 page_list[VA_CONTROL_PAGE] = (unsigned long)control_page;
146 page_list[PA_PGD] = __pa(kexec_pgd);
147 page_list[VA_PGD] = (unsigned long)kexec_pgd;
148 #ifdef CONFIG_X86_PAE
149 page_list[PA_PMD_0] = __pa(kexec_pmd0);
150 page_list[VA_PMD_0] = (unsigned long)kexec_pmd0;
151 page_list[PA_PMD_1] = __pa(kexec_pmd1);
152 page_list[VA_PMD_1] = (unsigned long)kexec_pmd1;
154 page_list[PA_PTE_0] = __pa(kexec_pte0);
155 page_list[VA_PTE_0] = (unsigned long)kexec_pte0;
156 page_list[PA_PTE_1] = __pa(kexec_pte1);
157 page_list[VA_PTE_1] = (unsigned long)kexec_pte1;
158 page_list[PA_SWAP_PAGE] = (page_to_pfn(image->swap_page) << PAGE_SHIFT);
160 /* The segment registers are funny things, they have both a
161 * visible and an invisible part. Whenever the visible part is
162 * set to a specific selector, the invisible part is loaded
163 * with from a table in memory. At no other time is the
164 * descriptor table in memory accessed.
166 * I take advantage of this here by force loading the
167 * segments, before I zap the gdt with an invalid value.
170 /* The gdt & idt are now invalid.
171 * If you want to load them you must set up your own idt & gdt.
173 set_gdt(phys_to_virt(0),0);
174 set_idt(phys_to_virt(0),0);
177 image->start = relocate_kernel_ptr((unsigned long)image->head,
178 (unsigned long)page_list,
179 image->start, cpu_has_pae,
180 image->preserve_context);
183 void arch_crash_save_vmcoreinfo(void)
186 VMCOREINFO_SYMBOL(node_data);
187 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
189 #ifdef CONFIG_X86_PAE
190 VMCOREINFO_CONFIG(X86_PAE);