Merge branch 'cpus4096' into irq/threaded
[safe/jmp/linux-2.6] / arch / x86 / kernel / machine_kexec_32.c
index 1100312..e7368c1 100644 (file)
 #include <linux/ftrace.h>
 #include <linux/suspend.h>
 #include <linux/gfp.h>
+#include <linux/io.h>
 
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
 #include <asm/mmu_context.h>
-#include <asm/io.h>
 #include <asm/apic.h>
 #include <asm/cpufeature.h>
 #include <asm/desc.h>
@@ -63,7 +63,7 @@ static void load_segments(void)
                "\tmovl %%eax,%%fs\n"
                "\tmovl %%eax,%%gs\n"
                "\tmovl %%eax,%%ss\n"
-               ::: "eax", "memory");
+               : : : "eax", "memory");
 #undef STR
 #undef __STR
 }
@@ -99,6 +99,45 @@ static int machine_kexec_alloc_page_tables(struct kimage *image)
        return 0;
 }
 
+static void machine_kexec_page_table_set_one(
+       pgd_t *pgd, pmd_t *pmd, pte_t *pte,
+       unsigned long vaddr, unsigned long paddr)
+{
+       pud_t *pud;
+
+       pgd += pgd_index(vaddr);
+#ifdef CONFIG_X86_PAE
+       if (!(pgd_val(*pgd) & _PAGE_PRESENT))
+               set_pgd(pgd, __pgd(__pa(pmd) | _PAGE_PRESENT));
+#endif
+       pud = pud_offset(pgd, vaddr);
+       pmd = pmd_offset(pud, vaddr);
+       if (!(pmd_val(*pmd) & _PAGE_PRESENT))
+               set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
+       pte = pte_offset_kernel(pmd, vaddr);
+       set_pte(pte, pfn_pte(paddr >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
+}
+
+static void machine_kexec_prepare_page_tables(struct kimage *image)
+{
+       void *control_page;
+       pmd_t *pmd = NULL;
+
+       control_page = page_address(image->control_code_page);
+#ifdef CONFIG_X86_PAE
+       pmd = image->arch.pmd0;
+#endif
+       machine_kexec_page_table_set_one(
+               image->arch.pgd, pmd, image->arch.pte0,
+               (unsigned long)control_page, __pa(control_page));
+#ifdef CONFIG_X86_PAE
+       pmd = image->arch.pmd1;
+#endif
+       machine_kexec_page_table_set_one(
+               image->arch.pgd, pmd, image->arch.pte1,
+               __pa(control_page), __pa(control_page));
+}
+
 /*
  * A architecture hook called to validate the
  * proposed image and prepare the control pages
@@ -112,12 +151,19 @@ static int machine_kexec_alloc_page_tables(struct kimage *image)
  *
  * - Make control page executable.
  * - Allocate page tables
+ * - Setup page tables
  */
 int machine_kexec_prepare(struct kimage *image)
 {
+       int error;
+
        if (nx_enabled)
                set_pages_x(image->control_code_page, 1);
-       return machine_kexec_alloc_page_tables(image);
+       error = machine_kexec_alloc_page_tables(image);
+       if (error)
+               return error;
+       machine_kexec_prepare_page_tables(image);
+       return 0;
 }
 
 /*
@@ -159,7 +205,8 @@ void machine_kexec(struct kimage *image)
 
        if (image->preserve_context) {
 #ifdef CONFIG_X86_IO_APIC
-               /* We need to put APICs in legacy mode so that we can
+               /*
+                * We need to put APICs in legacy mode so that we can
                 * get timer interrupts in second kernel. kexec/kdump
                 * paths already have calls to disable_IO_APIC() in
                 * one form or other. kexec jump path also need
@@ -176,23 +223,13 @@ void machine_kexec(struct kimage *image)
        page_list[PA_CONTROL_PAGE] = __pa(control_page);
        page_list[VA_CONTROL_PAGE] = (unsigned long)control_page;
        page_list[PA_PGD] = __pa(image->arch.pgd);
-       page_list[VA_PGD] = (unsigned long)image->arch.pgd;
-#ifdef CONFIG_X86_PAE
-       page_list[PA_PMD_0] = __pa(image->arch.pmd0);
-       page_list[VA_PMD_0] = (unsigned long)image->arch.pmd0;
-       page_list[PA_PMD_1] = __pa(image->arch.pmd1);
-       page_list[VA_PMD_1] = (unsigned long)image->arch.pmd1;
-#endif
-       page_list[PA_PTE_0] = __pa(image->arch.pte0);
-       page_list[VA_PTE_0] = (unsigned long)image->arch.pte0;
-       page_list[PA_PTE_1] = __pa(image->arch.pte1);
-       page_list[VA_PTE_1] = (unsigned long)image->arch.pte1;
 
        if (image->type == KEXEC_TYPE_DEFAULT)
                page_list[PA_SWAP_PAGE] = (page_to_pfn(image->swap_page)
                                                << PAGE_SHIFT);
 
-       /* The segment registers are funny things, they have both a
+       /*
+        * The segment registers are funny things, they have both a
         * visible and an invisible part.  Whenever the visible part is
         * set to a specific selector, the invisible part is loaded
         * with from a table in memory.  At no other time is the
@@ -202,11 +239,12 @@ void machine_kexec(struct kimage *image)
         * segments, before I zap the gdt with an invalid value.
         */
        load_segments();
-       /* The gdt & idt are now invalid.
+       /*
+        * The gdt & idt are now invalid.
         * If you want to load them you must set up your own idt & gdt.
         */
-       set_gdt(phys_to_virt(0),0);
-       set_idt(phys_to_virt(0),0);
+       set_gdt(phys_to_virt(0), 0);
+       set_idt(phys_to_virt(0), 0);
 
        /* now call it */
        image->start = relocate_kernel_ptr((unsigned long)image->head,