ia64/linux-2.6.18-xen.hg

view arch/x86_64/kernel/machine_kexec.c @ 450:b7f980c60a61

kexec: add xen_machine_kexec_register_resources() and machine_kexec_register_resources()

Add xen_machine_kexec_register_resources() and
machine_kexec_register_resources() to allow architecture specific
handling of iomem resources.

At this time xen_machine_kexec_register_resources() does the
same parenting of per-cpu resources on all architectures.
And machine_kexec_register_resources does nothing on all
architectures.

Signed-off-by: Simon Horman <horms@verge.net.au>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Feb 28 10:54:20 2008 +0000 (2008-02-28)
parents a533be77c572
children
line source
1 /*
2 * machine_kexec.c - handle transition of Linux booting another kernel
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 */
9 #include <linux/mm.h>
10 #include <linux/kexec.h>
11 #include <linux/string.h>
12 #include <linux/reboot.h>
13 #include <asm/pgtable.h>
14 #include <asm/tlbflush.h>
15 #include <asm/mmu_context.h>
16 #include <asm/io.h>
18 #define PAGE_ALIGNED __attribute__ ((__aligned__(PAGE_SIZE)))
19 static u64 kexec_pgd[512] PAGE_ALIGNED;
20 static u64 kexec_pud0[512] PAGE_ALIGNED;
21 static u64 kexec_pmd0[512] PAGE_ALIGNED;
22 static u64 kexec_pte0[512] PAGE_ALIGNED;
23 static u64 kexec_pud1[512] PAGE_ALIGNED;
24 static u64 kexec_pmd1[512] PAGE_ALIGNED;
25 static u64 kexec_pte1[512] PAGE_ALIGNED;
27 #ifdef CONFIG_XEN
29 /* In the case of Xen, override hypervisor functions to be able to create
30 * a regular identity mapping page table...
31 */
33 #include <xen/interface/kexec.h>
34 #include <xen/interface/memory.h>
36 #define x__pmd(x) ((pmd_t) { (x) } )
37 #define x__pud(x) ((pud_t) { (x) } )
38 #define x__pgd(x) ((pgd_t) { (x) } )
40 #define x_pmd_val(x) ((x).pmd)
41 #define x_pud_val(x) ((x).pud)
42 #define x_pgd_val(x) ((x).pgd)
44 static inline void x_set_pmd(pmd_t *dst, pmd_t val)
45 {
46 x_pmd_val(*dst) = x_pmd_val(val);
47 }
49 static inline void x_set_pud(pud_t *dst, pud_t val)
50 {
51 x_pud_val(*dst) = phys_to_machine(x_pud_val(val));
52 }
54 static inline void x_pud_clear (pud_t *pud)
55 {
56 x_pud_val(*pud) = 0;
57 }
59 static inline void x_set_pgd(pgd_t *dst, pgd_t val)
60 {
61 x_pgd_val(*dst) = phys_to_machine(x_pgd_val(val));
62 }
64 static inline void x_pgd_clear (pgd_t * pgd)
65 {
66 x_pgd_val(*pgd) = 0;
67 }
69 #define X__PAGE_KERNEL_LARGE_EXEC \
70 _PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_PSE
71 #define X_KERNPG_TABLE _PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY
73 #define __ma(x) (pfn_to_mfn(__pa((x)) >> PAGE_SHIFT) << PAGE_SHIFT)
75 #if PAGES_NR > KEXEC_XEN_NO_PAGES
76 #error PAGES_NR is greater than KEXEC_XEN_NO_PAGES - Xen support will break
77 #endif
79 #if PA_CONTROL_PAGE != 0
80 #error PA_CONTROL_PAGE is non zero - Xen support will break
81 #endif
83 void machine_kexec_setup_load_arg(xen_kexec_image_t *xki, struct kimage *image)
84 {
85 void *control_page;
86 void *table_page;
88 memset(xki->page_list, 0, sizeof(xki->page_list));
90 control_page = page_address(image->control_code_page) + PAGE_SIZE;
91 memcpy(control_page, relocate_kernel, PAGE_SIZE);
93 table_page = page_address(image->control_code_page);
95 xki->page_list[PA_CONTROL_PAGE] = __ma(control_page);
96 xki->page_list[PA_TABLE_PAGE] = __ma(table_page);
98 xki->page_list[PA_PGD] = __ma(kexec_pgd);
99 xki->page_list[PA_PUD_0] = __ma(kexec_pud0);
100 xki->page_list[PA_PUD_1] = __ma(kexec_pud1);
101 xki->page_list[PA_PMD_0] = __ma(kexec_pmd0);
102 xki->page_list[PA_PMD_1] = __ma(kexec_pmd1);
103 xki->page_list[PA_PTE_0] = __ma(kexec_pte0);
104 xki->page_list[PA_PTE_1] = __ma(kexec_pte1);
105 }
107 int __init machine_kexec_setup_resources(struct resource *hypervisor,
108 struct resource *phys_cpus,
109 int nr_phys_cpus)
110 {
111 int k;
113 /* The per-cpu crash note resources belong to the hypervisor resource */
114 for (k = 0; k < nr_phys_cpus; k++)
115 request_resource(hypervisor, phys_cpus + k);
117 return 0;
118 }
120 void machine_kexec_register_resources(struct resource *res) { ; }
122 #else /* CONFIG_XEN */
124 #define x__pmd(x) __pmd(x)
125 #define x__pud(x) __pud(x)
126 #define x__pgd(x) __pgd(x)
128 #define x_set_pmd(x, y) set_pmd(x, y)
129 #define x_set_pud(x, y) set_pud(x, y)
130 #define x_set_pgd(x, y) set_pgd(x, y)
132 #define x_pud_clear(x) pud_clear(x)
133 #define x_pgd_clear(x) pgd_clear(x)
135 #define X__PAGE_KERNEL_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
136 #define X_KERNPG_TABLE _KERNPG_TABLE
138 #endif /* CONFIG_XEN */
140 static void init_level2_page(pmd_t *level2p, unsigned long addr)
141 {
142 unsigned long end_addr;
144 addr &= PAGE_MASK;
145 end_addr = addr + PUD_SIZE;
146 while (addr < end_addr) {
147 x_set_pmd(level2p++, x__pmd(addr | X__PAGE_KERNEL_LARGE_EXEC));
148 addr += PMD_SIZE;
149 }
150 }
152 static int init_level3_page(struct kimage *image, pud_t *level3p,
153 unsigned long addr, unsigned long last_addr)
154 {
155 unsigned long end_addr;
156 int result;
158 result = 0;
159 addr &= PAGE_MASK;
160 end_addr = addr + PGDIR_SIZE;
161 while ((addr < last_addr) && (addr < end_addr)) {
162 struct page *page;
163 pmd_t *level2p;
165 page = kimage_alloc_control_pages(image, 0);
166 if (!page) {
167 result = -ENOMEM;
168 goto out;
169 }
170 level2p = (pmd_t *)page_address(page);
171 init_level2_page(level2p, addr);
172 x_set_pud(level3p++, x__pud(__pa(level2p) | X_KERNPG_TABLE));
173 addr += PUD_SIZE;
174 }
175 /* clear the unused entries */
176 while (addr < end_addr) {
177 x_pud_clear(level3p++);
178 addr += PUD_SIZE;
179 }
180 out:
181 return result;
182 }
185 static int init_level4_page(struct kimage *image, pgd_t *level4p,
186 unsigned long addr, unsigned long last_addr)
187 {
188 unsigned long end_addr;
189 int result;
191 result = 0;
192 addr &= PAGE_MASK;
193 end_addr = addr + (PTRS_PER_PGD * PGDIR_SIZE);
194 while ((addr < last_addr) && (addr < end_addr)) {
195 struct page *page;
196 pud_t *level3p;
198 page = kimage_alloc_control_pages(image, 0);
199 if (!page) {
200 result = -ENOMEM;
201 goto out;
202 }
203 level3p = (pud_t *)page_address(page);
204 result = init_level3_page(image, level3p, addr, last_addr);
205 if (result) {
206 goto out;
207 }
208 x_set_pgd(level4p++, x__pgd(__pa(level3p) | X_KERNPG_TABLE));
209 addr += PGDIR_SIZE;
210 }
211 /* clear the unused entries */
212 while (addr < end_addr) {
213 x_pgd_clear(level4p++);
214 addr += PGDIR_SIZE;
215 }
216 out:
217 return result;
218 }
221 static int init_pgtable(struct kimage *image, unsigned long start_pgtable)
222 {
223 pgd_t *level4p;
224 unsigned long x_end_pfn = end_pfn;
226 #ifdef CONFIG_XEN
227 x_end_pfn = HYPERVISOR_memory_op(XENMEM_maximum_ram_page, NULL);
228 #endif
230 level4p = (pgd_t *)__va(start_pgtable);
231 return init_level4_page(image, level4p, 0, x_end_pfn << PAGE_SHIFT);
232 }
234 int machine_kexec_prepare(struct kimage *image)
235 {
236 unsigned long start_pgtable;
237 int result;
239 /* Calculate the offsets */
240 start_pgtable = page_to_pfn(image->control_code_page) << PAGE_SHIFT;
242 /* Setup the identity mapped 64bit page table */
243 result = init_pgtable(image, start_pgtable);
244 if (result)
245 return result;
247 return 0;
248 }
250 void machine_kexec_cleanup(struct kimage *image)
251 {
252 return;
253 }
255 #ifndef CONFIG_XEN
256 /*
257 * Do not allocate memory (or fail in any way) in machine_kexec().
258 * We are past the point of no return, committed to rebooting now.
259 */
260 NORET_TYPE void machine_kexec(struct kimage *image)
261 {
262 unsigned long page_list[PAGES_NR];
263 void *control_page;
265 /* Interrupts aren't acceptable while we reboot */
266 local_irq_disable();
268 control_page = page_address(image->control_code_page) + PAGE_SIZE;
269 memcpy(control_page, relocate_kernel, PAGE_SIZE);
271 page_list[PA_CONTROL_PAGE] = __pa(control_page);
272 page_list[VA_CONTROL_PAGE] = (unsigned long)relocate_kernel;
273 page_list[PA_PGD] = __pa(kexec_pgd);
274 page_list[VA_PGD] = (unsigned long)kexec_pgd;
275 page_list[PA_PUD_0] = __pa(kexec_pud0);
276 page_list[VA_PUD_0] = (unsigned long)kexec_pud0;
277 page_list[PA_PMD_0] = __pa(kexec_pmd0);
278 page_list[VA_PMD_0] = (unsigned long)kexec_pmd0;
279 page_list[PA_PTE_0] = __pa(kexec_pte0);
280 page_list[VA_PTE_0] = (unsigned long)kexec_pte0;
281 page_list[PA_PUD_1] = __pa(kexec_pud1);
282 page_list[VA_PUD_1] = (unsigned long)kexec_pud1;
283 page_list[PA_PMD_1] = __pa(kexec_pmd1);
284 page_list[VA_PMD_1] = (unsigned long)kexec_pmd1;
285 page_list[PA_PTE_1] = __pa(kexec_pte1);
286 page_list[VA_PTE_1] = (unsigned long)kexec_pte1;
288 page_list[PA_TABLE_PAGE] =
289 (unsigned long)__pa(page_address(image->control_code_page));
291 relocate_kernel((unsigned long)image->head, (unsigned long)page_list,
292 image->start);
293 }
294 #endif