kexec jump
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / x86 / kernel / machine_kexec_32.c
CommitLineData
5033cba0 1/*
835c34a1 2 * handle transition of Linux booting another kernel
5033cba0
EB
3 * Copyright (C) 2002-2005 Eric Biederman <ebiederm@xmission.com>
4 *
5 * This source code is licensed under the GNU General Public License,
6 * Version 2. See the file COPYING for more details.
7 */
8
9#include <linux/mm.h>
10#include <linux/kexec.h>
11#include <linux/delay.h>
1a3f239d 12#include <linux/init.h>
fd59d231 13#include <linux/numa.h>
f43fdad8
IM
14#include <linux/ftrace.h>
15
5033cba0
EB
16#include <asm/pgtable.h>
17#include <asm/pgalloc.h>
18#include <asm/tlbflush.h>
19#include <asm/mmu_context.h>
20#include <asm/io.h>
21#include <asm/apic.h>
22#include <asm/cpufeature.h>
e7b47cca 23#include <asm/desc.h>
4bb0d3ec 24#include <asm/system.h>
3ab83521 25#include <asm/cacheflush.h>
5033cba0
EB
26
27#define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE)))
3566561b
MD
28static u32 kexec_pgd[1024] PAGE_ALIGNED;
29#ifdef CONFIG_X86_PAE
30static u32 kexec_pmd0[1024] PAGE_ALIGNED;
31static u32 kexec_pmd1[1024] PAGE_ALIGNED;
5033cba0 32#endif
3566561b
MD
33static u32 kexec_pte0[1024] PAGE_ALIGNED;
34static u32 kexec_pte1[1024] PAGE_ALIGNED;
5033cba0 35
5033cba0
EB
36static void set_idt(void *newidt, __u16 limit)
37{
6b68f01b 38 struct desc_ptr curidt;
5033cba0
EB
39
40 /* ia32 supports unaliged loads & stores */
e7b47cca
EB
41 curidt.size = limit;
42 curidt.address = (unsigned long)newidt;
5033cba0 43
f2ab4461 44 load_idt(&curidt);
378fc6ee 45}
5033cba0
EB
46
47
48static void set_gdt(void *newgdt, __u16 limit)
49{
6b68f01b 50 struct desc_ptr curgdt;
5033cba0
EB
51
52 /* ia32 supports unaligned loads & stores */
e7b47cca
EB
53 curgdt.size = limit;
54 curgdt.address = (unsigned long)newgdt;
5033cba0 55
f2ab4461 56 load_gdt(&curgdt);
378fc6ee 57}
5033cba0
EB
58
59static void load_segments(void)
60{
61#define __STR(X) #X
62#define STR(X) __STR(X)
63
64 __asm__ __volatile__ (
65 "\tljmp $"STR(__KERNEL_CS)",$1f\n"
66 "\t1:\n"
2ec5e3a8
MM
67 "\tmovl $"STR(__KERNEL_DS)",%%eax\n"
68 "\tmovl %%eax,%%ds\n"
69 "\tmovl %%eax,%%es\n"
70 "\tmovl %%eax,%%fs\n"
71 "\tmovl %%eax,%%gs\n"
72 "\tmovl %%eax,%%ss\n"
73 ::: "eax", "memory");
5033cba0
EB
74#undef STR
75#undef __STR
76}
77
5033cba0
EB
78/*
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.
84 *
85 * Do what every setup is needed on image and the
86 * reboot code buffer to allow us to avoid allocations
87 * later.
88 *
3ab83521 89 * Make control page executable.
5033cba0
EB
90 */
91int machine_kexec_prepare(struct kimage *image)
92{
3ab83521
HY
93 if (nx_enabled)
94 set_pages_x(image->control_code_page, 1);
5033cba0
EB
95 return 0;
96}
97
98/*
99 * Undo anything leftover by machine_kexec_prepare
100 * when an image is freed.
101 */
102void machine_kexec_cleanup(struct kimage *image)
103{
3ab83521
HY
104 if (nx_enabled)
105 set_pages_nx(image->control_code_page, 1);
5033cba0
EB
106}
107
108/*
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.
111 */
3ab83521 112void machine_kexec(struct kimage *image)
5033cba0 113{
3566561b
MD
114 unsigned long page_list[PAGES_NR];
115 void *control_page;
3ab83521
HY
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);
5033cba0 122
f43fdad8
IM
123 tracer_disable();
124
5033cba0
EB
125 /* Interrupts aren't acceptable while we reboot */
126 local_irq_disable();
127
3566561b 128 control_page = page_address(image->control_code_page);
3ab83521 129 memcpy(control_page, relocate_kernel, PAGE_SIZE/2);
3566561b 130
3ab83521 131 relocate_kernel_ptr = control_page;
3566561b 132 page_list[PA_CONTROL_PAGE] = __pa(control_page);
3ab83521 133 page_list[VA_CONTROL_PAGE] = (unsigned long)control_page;
3566561b
MD
134 page_list[PA_PGD] = __pa(kexec_pgd);
135 page_list[VA_PGD] = (unsigned long)kexec_pgd;
136#ifdef CONFIG_X86_PAE
137 page_list[PA_PMD_0] = __pa(kexec_pmd0);
138 page_list[VA_PMD_0] = (unsigned long)kexec_pmd0;
139 page_list[PA_PMD_1] = __pa(kexec_pmd1);
140 page_list[VA_PMD_1] = (unsigned long)kexec_pmd1;
141#endif
142 page_list[PA_PTE_0] = __pa(kexec_pte0);
143 page_list[VA_PTE_0] = (unsigned long)kexec_pte0;
144 page_list[PA_PTE_1] = __pa(kexec_pte1);
145 page_list[VA_PTE_1] = (unsigned long)kexec_pte1;
3ab83521 146 page_list[PA_SWAP_PAGE] = (page_to_pfn(image->swap_page) << PAGE_SHIFT);
5033cba0 147
2a8a3d5b
EB
148 /* The segment registers are funny things, they have both a
149 * visible and an invisible part. Whenever the visible part is
150 * set to a specific selector, the invisible part is loaded
151 * with from a table in memory. At no other time is the
152 * descriptor table in memory accessed.
5033cba0
EB
153 *
154 * I take advantage of this here by force loading the
155 * segments, before I zap the gdt with an invalid value.
156 */
157 load_segments();
158 /* The gdt & idt are now invalid.
159 * If you want to load them you must set up your own idt & gdt.
160 */
161 set_gdt(phys_to_virt(0),0);
162 set_idt(phys_to_virt(0),0);
163
164 /* now call it */
3ab83521
HY
165 image->start = relocate_kernel_ptr((unsigned long)image->head,
166 (unsigned long)page_list,
167 image->start, cpu_has_pae,
168 image->preserve_context);
5033cba0 169}
1a3f239d 170
fd59d231
KO
171void arch_crash_save_vmcoreinfo(void)
172{
92df5c3e 173#ifdef CONFIG_NUMA
bcbba6c1
KO
174 VMCOREINFO_SYMBOL(node_data);
175 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
fd59d231
KO
176#endif
177#ifdef CONFIG_X86_PAE
bcbba6c1 178 VMCOREINFO_CONFIG(X86_PAE);
fd59d231
KO
179#endif
180}
181