machine_kexec_32.c 4.1 KB

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