Merge branch 'for-linus' of git://neil.brown.name/md
[deliverable/linux.git] / include / asm-x86 / kexec.h
1 #ifndef _KEXEC_H
2 #define _KEXEC_H
3
4 #ifdef CONFIG_X86_32
5 # define PA_CONTROL_PAGE 0
6 # define VA_CONTROL_PAGE 1
7 # define PA_PGD 2
8 # define VA_PGD 3
9 # define PA_PTE_0 4
10 # define VA_PTE_0 5
11 # define PA_PTE_1 6
12 # define VA_PTE_1 7
13 # define PA_SWAP_PAGE 8
14 # ifdef CONFIG_X86_PAE
15 # define PA_PMD_0 9
16 # define VA_PMD_0 10
17 # define PA_PMD_1 11
18 # define VA_PMD_1 12
19 # define PAGES_NR 13
20 # else
21 # define PAGES_NR 9
22 # endif
23 #else
24 # define PA_CONTROL_PAGE 0
25 # define VA_CONTROL_PAGE 1
26 # define PA_PGD 2
27 # define VA_PGD 3
28 # define PA_PUD_0 4
29 # define VA_PUD_0 5
30 # define PA_PMD_0 6
31 # define VA_PMD_0 7
32 # define PA_PTE_0 8
33 # define VA_PTE_0 9
34 # define PA_PUD_1 10
35 # define VA_PUD_1 11
36 # define PA_PMD_1 12
37 # define VA_PMD_1 13
38 # define PA_PTE_1 14
39 # define VA_PTE_1 15
40 # define PA_TABLE_PAGE 16
41 # define PAGES_NR 17
42 #endif
43
44 #ifndef __ASSEMBLY__
45
46 #include <linux/string.h>
47
48 #include <asm/page.h>
49 #include <asm/ptrace.h>
50
51 /*
52 * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
53 * I.e. Maximum page that is mapped directly into kernel memory,
54 * and kmap is not required.
55 *
56 * So far x86_64 is limited to 40 physical address bits.
57 */
58 #ifdef CONFIG_X86_32
59 /* Maximum physical address we can use pages from */
60 # define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
61 /* Maximum address we can reach in physical address mode */
62 # define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
63 /* Maximum address we can use for the control code buffer */
64 # define KEXEC_CONTROL_MEMORY_LIMIT TASK_SIZE
65
66 # define KEXEC_CONTROL_CODE_SIZE 4096
67
68 /* The native architecture */
69 # define KEXEC_ARCH KEXEC_ARCH_386
70
71 /* We can also handle crash dumps from 64 bit kernel. */
72 # define vmcore_elf_check_arch_cross(x) ((x)->e_machine == EM_X86_64)
73 #else
74 /* Maximum physical address we can use pages from */
75 # define KEXEC_SOURCE_MEMORY_LIMIT (0xFFFFFFFFFFUL)
76 /* Maximum address we can reach in physical address mode */
77 # define KEXEC_DESTINATION_MEMORY_LIMIT (0xFFFFFFFFFFUL)
78 /* Maximum address we can use for the control pages */
79 # define KEXEC_CONTROL_MEMORY_LIMIT (0xFFFFFFFFFFUL)
80
81 /* Allocate one page for the pdp and the second for the code */
82 # define KEXEC_CONTROL_CODE_SIZE (4096UL + 4096UL)
83
84 /* The native architecture */
85 # define KEXEC_ARCH KEXEC_ARCH_X86_64
86 #endif
87
88 /*
89 * CPU does not save ss and sp on stack if execution is already
90 * running in kernel mode at the time of NMI occurrence. This code
91 * fixes it.
92 */
93 static inline void crash_fixup_ss_esp(struct pt_regs *newregs,
94 struct pt_regs *oldregs)
95 {
96 #ifdef CONFIG_X86_32
97 newregs->sp = (unsigned long)&(oldregs->sp);
98 asm volatile("xorl %%eax, %%eax\n\t"
99 "movw %%ss, %%ax\n\t"
100 :"=a"(newregs->ss));
101 #endif
102 }
103
104 /*
105 * This function is responsible for capturing register states if coming
106 * via panic otherwise just fix up the ss and sp if coming via kernel
107 * mode exception.
108 */
109 static inline void crash_setup_regs(struct pt_regs *newregs,
110 struct pt_regs *oldregs)
111 {
112 if (oldregs) {
113 memcpy(newregs, oldregs, sizeof(*newregs));
114 crash_fixup_ss_esp(newregs, oldregs);
115 } else {
116 #ifdef CONFIG_X86_32
117 asm volatile("movl %%ebx,%0" : "=m"(newregs->bx));
118 asm volatile("movl %%ecx,%0" : "=m"(newregs->cx));
119 asm volatile("movl %%edx,%0" : "=m"(newregs->dx));
120 asm volatile("movl %%esi,%0" : "=m"(newregs->si));
121 asm volatile("movl %%edi,%0" : "=m"(newregs->di));
122 asm volatile("movl %%ebp,%0" : "=m"(newregs->bp));
123 asm volatile("movl %%eax,%0" : "=m"(newregs->ax));
124 asm volatile("movl %%esp,%0" : "=m"(newregs->sp));
125 asm volatile("movl %%ss, %%eax;" :"=a"(newregs->ss));
126 asm volatile("movl %%cs, %%eax;" :"=a"(newregs->cs));
127 asm volatile("movl %%ds, %%eax;" :"=a"(newregs->ds));
128 asm volatile("movl %%es, %%eax;" :"=a"(newregs->es));
129 asm volatile("pushfl; popl %0" :"=m"(newregs->flags));
130 #else
131 asm volatile("movq %%rbx,%0" : "=m"(newregs->bx));
132 asm volatile("movq %%rcx,%0" : "=m"(newregs->cx));
133 asm volatile("movq %%rdx,%0" : "=m"(newregs->dx));
134 asm volatile("movq %%rsi,%0" : "=m"(newregs->si));
135 asm volatile("movq %%rdi,%0" : "=m"(newregs->di));
136 asm volatile("movq %%rbp,%0" : "=m"(newregs->bp));
137 asm volatile("movq %%rax,%0" : "=m"(newregs->ax));
138 asm volatile("movq %%rsp,%0" : "=m"(newregs->sp));
139 asm volatile("movq %%r8,%0" : "=m"(newregs->r8));
140 asm volatile("movq %%r9,%0" : "=m"(newregs->r9));
141 asm volatile("movq %%r10,%0" : "=m"(newregs->r10));
142 asm volatile("movq %%r11,%0" : "=m"(newregs->r11));
143 asm volatile("movq %%r12,%0" : "=m"(newregs->r12));
144 asm volatile("movq %%r13,%0" : "=m"(newregs->r13));
145 asm volatile("movq %%r14,%0" : "=m"(newregs->r14));
146 asm volatile("movq %%r15,%0" : "=m"(newregs->r15));
147 asm volatile("movl %%ss, %%eax;" :"=a"(newregs->ss));
148 asm volatile("movl %%cs, %%eax;" :"=a"(newregs->cs));
149 asm volatile("pushfq; popq %0" :"=m"(newregs->flags));
150 #endif
151 newregs->ip = (unsigned long)current_text_addr();
152 }
153 }
154
155 #ifdef CONFIG_X86_32
156 asmlinkage unsigned long
157 relocate_kernel(unsigned long indirection_page,
158 unsigned long control_page,
159 unsigned long start_address,
160 unsigned int has_pae,
161 unsigned int preserve_context);
162 #else
163 NORET_TYPE void
164 relocate_kernel(unsigned long indirection_page,
165 unsigned long page_list,
166 unsigned long start_address) ATTRIB_NORET;
167 #endif
168
169 #endif /* __ASSEMBLY__ */
170
171 #endif /* _KEXEC_H */
This page took 0.034606 seconds and 6 git commands to generate.