kernel/kexec.c: make 'kimage_terminate' void
[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>
5033cba0
EB
25
26#define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE)))
3566561b
MD
27static u32 kexec_pgd[1024] PAGE_ALIGNED;
28#ifdef CONFIG_X86_PAE
29static u32 kexec_pmd0[1024] PAGE_ALIGNED;
30static u32 kexec_pmd1[1024] PAGE_ALIGNED;
5033cba0 31#endif
3566561b
MD
32static u32 kexec_pte0[1024] PAGE_ALIGNED;
33static u32 kexec_pte1[1024] PAGE_ALIGNED;
5033cba0 34
5033cba0
EB
35static void set_idt(void *newidt, __u16 limit)
36{
6b68f01b 37 struct desc_ptr curidt;
5033cba0
EB
38
39 /* ia32 supports unaliged loads & stores */
e7b47cca
EB
40 curidt.size = limit;
41 curidt.address = (unsigned long)newidt;
5033cba0 42
f2ab4461 43 load_idt(&curidt);
378fc6ee 44}
5033cba0
EB
45
46
47static void set_gdt(void *newgdt, __u16 limit)
48{
6b68f01b 49 struct desc_ptr curgdt;
5033cba0
EB
50
51 /* ia32 supports unaligned loads & stores */
e7b47cca
EB
52 curgdt.size = limit;
53 curgdt.address = (unsigned long)newgdt;
5033cba0 54
f2ab4461 55 load_gdt(&curgdt);
378fc6ee 56}
5033cba0
EB
57
58static void load_segments(void)
59{
60#define __STR(X) #X
61#define STR(X) __STR(X)
62
63 __asm__ __volatile__ (
64 "\tljmp $"STR(__KERNEL_CS)",$1f\n"
65 "\t1:\n"
2ec5e3a8
MM
66 "\tmovl $"STR(__KERNEL_DS)",%%eax\n"
67 "\tmovl %%eax,%%ds\n"
68 "\tmovl %%eax,%%es\n"
69 "\tmovl %%eax,%%fs\n"
70 "\tmovl %%eax,%%gs\n"
71 "\tmovl %%eax,%%ss\n"
72 ::: "eax", "memory");
5033cba0
EB
73#undef STR
74#undef __STR
75}
76
5033cba0
EB
77/*
78 * A architecture hook called to validate the
79 * proposed image and prepare the control pages
80 * as needed. The pages for KEXEC_CONTROL_CODE_SIZE
81 * have been allocated, but the segments have yet
82 * been copied into the kernel.
83 *
84 * Do what every setup is needed on image and the
85 * reboot code buffer to allow us to avoid allocations
86 * later.
87 *
88 * Currently nothing.
89 */
90int machine_kexec_prepare(struct kimage *image)
91{
92 return 0;
93}
94
95/*
96 * Undo anything leftover by machine_kexec_prepare
97 * when an image is freed.
98 */
99void machine_kexec_cleanup(struct kimage *image)
100{
101}
102
103/*
104 * Do not allocate memory (or fail in any way) in machine_kexec().
105 * We are past the point of no return, committed to rebooting now.
106 */
107NORET_TYPE void machine_kexec(struct kimage *image)
108{
3566561b
MD
109 unsigned long page_list[PAGES_NR];
110 void *control_page;
5033cba0 111
f43fdad8
IM
112 tracer_disable();
113
5033cba0
EB
114 /* Interrupts aren't acceptable while we reboot */
115 local_irq_disable();
116
3566561b
MD
117 control_page = page_address(image->control_code_page);
118 memcpy(control_page, relocate_kernel, PAGE_SIZE);
119
120 page_list[PA_CONTROL_PAGE] = __pa(control_page);
121 page_list[VA_CONTROL_PAGE] = (unsigned long)relocate_kernel;
122 page_list[PA_PGD] = __pa(kexec_pgd);
123 page_list[VA_PGD] = (unsigned long)kexec_pgd;
124#ifdef CONFIG_X86_PAE
125 page_list[PA_PMD_0] = __pa(kexec_pmd0);
126 page_list[VA_PMD_0] = (unsigned long)kexec_pmd0;
127 page_list[PA_PMD_1] = __pa(kexec_pmd1);
128 page_list[VA_PMD_1] = (unsigned long)kexec_pmd1;
129#endif
130 page_list[PA_PTE_0] = __pa(kexec_pte0);
131 page_list[VA_PTE_0] = (unsigned long)kexec_pte0;
132 page_list[PA_PTE_1] = __pa(kexec_pte1);
133 page_list[VA_PTE_1] = (unsigned long)kexec_pte1;
5033cba0 134
2a8a3d5b
EB
135 /* The segment registers are funny things, they have both a
136 * visible and an invisible part. Whenever the visible part is
137 * set to a specific selector, the invisible part is loaded
138 * with from a table in memory. At no other time is the
139 * descriptor table in memory accessed.
5033cba0
EB
140 *
141 * I take advantage of this here by force loading the
142 * segments, before I zap the gdt with an invalid value.
143 */
144 load_segments();
145 /* The gdt & idt are now invalid.
146 * If you want to load them you must set up your own idt & gdt.
147 */
148 set_gdt(phys_to_virt(0),0);
149 set_idt(phys_to_virt(0),0);
150
151 /* now call it */
3566561b
MD
152 relocate_kernel((unsigned long)image->head, (unsigned long)page_list,
153 image->start, cpu_has_pae);
5033cba0 154}
1a3f239d 155
fd59d231
KO
156void arch_crash_save_vmcoreinfo(void)
157{
92df5c3e 158#ifdef CONFIG_NUMA
bcbba6c1
KO
159 VMCOREINFO_SYMBOL(node_data);
160 VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
fd59d231
KO
161#endif
162#ifdef CONFIG_X86_PAE
bcbba6c1 163 VMCOREINFO_CONFIG(X86_PAE);
fd59d231
KO
164#endif
165}
166