kexec.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #ifndef LINUX_KEXEC_H
  2. #define LINUX_KEXEC_H
  3. #ifdef CONFIG_KEXEC
  4. #include <linux/types.h>
  5. #include <linux/list.h>
  6. #include <linux/linkage.h>
  7. #include <linux/compat.h>
  8. #include <linux/ioport.h>
  9. #include <linux/elfcore.h>
  10. #include <linux/elf.h>
  11. #include <asm/kexec.h>
  12. /* Verify architecture specific macros are defined */
  13. #ifndef KEXEC_SOURCE_MEMORY_LIMIT
  14. #error KEXEC_SOURCE_MEMORY_LIMIT not defined
  15. #endif
  16. #ifndef KEXEC_DESTINATION_MEMORY_LIMIT
  17. #error KEXEC_DESTINATION_MEMORY_LIMIT not defined
  18. #endif
  19. #ifndef KEXEC_CONTROL_MEMORY_LIMIT
  20. #error KEXEC_CONTROL_MEMORY_LIMIT not defined
  21. #endif
  22. #ifndef KEXEC_CONTROL_PAGE_SIZE
  23. #error KEXEC_CONTROL_PAGE_SIZE not defined
  24. #endif
  25. #ifndef KEXEC_ARCH
  26. #error KEXEC_ARCH not defined
  27. #endif
  28. #ifndef KEXEC_CRASH_CONTROL_MEMORY_LIMIT
  29. #define KEXEC_CRASH_CONTROL_MEMORY_LIMIT KEXEC_CONTROL_MEMORY_LIMIT
  30. #endif
  31. #define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
  32. #define KEXEC_CORE_NOTE_NAME "CORE"
  33. #define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
  34. #define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
  35. /*
  36. * The per-cpu notes area is a list of notes terminated by a "NULL"
  37. * note header. For kdump, the code in vmcore.c runs in the context
  38. * of the second kernel to combine them into one note.
  39. */
  40. #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
  41. KEXEC_CORE_NOTE_NAME_BYTES + \
  42. KEXEC_CORE_NOTE_DESC_BYTES )
  43. /*
  44. * This structure is used to hold the arguments that are used when loading
  45. * kernel binaries.
  46. */
  47. typedef unsigned long kimage_entry_t;
  48. #define IND_DESTINATION 0x1
  49. #define IND_INDIRECTION 0x2
  50. #define IND_DONE 0x4
  51. #define IND_SOURCE 0x8
  52. #define KEXEC_SEGMENT_MAX 16
  53. struct kexec_segment {
  54. void __user *buf;
  55. size_t bufsz;
  56. unsigned long mem; /* User space sees this as a (void *) ... */
  57. size_t memsz;
  58. };
  59. #ifdef CONFIG_COMPAT
  60. struct compat_kexec_segment {
  61. compat_uptr_t buf;
  62. compat_size_t bufsz;
  63. compat_ulong_t mem; /* User space sees this as a (void *) ... */
  64. compat_size_t memsz;
  65. };
  66. #endif
  67. struct kimage {
  68. kimage_entry_t head;
  69. kimage_entry_t *entry;
  70. kimage_entry_t *last_entry;
  71. unsigned long destination;
  72. unsigned long start;
  73. struct page *control_code_page;
  74. struct page *swap_page;
  75. unsigned long nr_segments;
  76. struct kexec_segment segment[KEXEC_SEGMENT_MAX];
  77. struct list_head control_pages;
  78. struct list_head dest_pages;
  79. struct list_head unuseable_pages;
  80. /* Address of next control page to allocate for crash kernels. */
  81. unsigned long control_page;
  82. /* Flags to indicate special processing */
  83. unsigned int type : 1;
  84. #define KEXEC_TYPE_DEFAULT 0
  85. #define KEXEC_TYPE_CRASH 1
  86. unsigned int preserve_context : 1;
  87. #ifdef ARCH_HAS_KIMAGE_ARCH
  88. struct kimage_arch arch;
  89. #endif
  90. };
  91. /* kexec interface functions */
  92. extern void machine_kexec(struct kimage *image);
  93. extern int machine_kexec_prepare(struct kimage *image);
  94. extern void machine_kexec_cleanup(struct kimage *image);
  95. extern asmlinkage long sys_kexec_load(unsigned long entry,
  96. unsigned long nr_segments,
  97. struct kexec_segment __user *segments,
  98. unsigned long flags);
  99. extern int kernel_kexec(void);
  100. #ifdef CONFIG_COMPAT
  101. extern asmlinkage long compat_sys_kexec_load(unsigned long entry,
  102. unsigned long nr_segments,
  103. struct compat_kexec_segment __user *segments,
  104. unsigned long flags);
  105. #endif
  106. extern struct page *kimage_alloc_control_pages(struct kimage *image,
  107. unsigned int order);
  108. extern void crash_kexec(struct pt_regs *);
  109. int kexec_should_crash(struct task_struct *);
  110. void crash_save_cpu(struct pt_regs *regs, int cpu);
  111. void crash_save_vmcoreinfo(void);
  112. void arch_crash_save_vmcoreinfo(void);
  113. void vmcoreinfo_append_str(const char *fmt, ...)
  114. __attribute__ ((format (printf, 1, 2)));
  115. unsigned long paddr_vmcoreinfo_note(void);
  116. #define VMCOREINFO_OSRELEASE(value) \
  117. vmcoreinfo_append_str("OSRELEASE=%s\n", value)
  118. #define VMCOREINFO_PAGESIZE(value) \
  119. vmcoreinfo_append_str("PAGESIZE=%ld\n", value)
  120. #define VMCOREINFO_SYMBOL(name) \
  121. vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
  122. #define VMCOREINFO_SIZE(name) \
  123. vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
  124. (unsigned long)sizeof(name))
  125. #define VMCOREINFO_STRUCT_SIZE(name) \
  126. vmcoreinfo_append_str("SIZE(%s)=%lu\n", #name, \
  127. (unsigned long)sizeof(struct name))
  128. #define VMCOREINFO_OFFSET(name, field) \
  129. vmcoreinfo_append_str("OFFSET(%s.%s)=%lu\n", #name, #field, \
  130. (unsigned long)offsetof(struct name, field))
  131. #define VMCOREINFO_LENGTH(name, value) \
  132. vmcoreinfo_append_str("LENGTH(%s)=%lu\n", #name, (unsigned long)value)
  133. #define VMCOREINFO_NUMBER(name) \
  134. vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
  135. #define VMCOREINFO_CONFIG(name) \
  136. vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
  137. extern struct kimage *kexec_image;
  138. extern struct kimage *kexec_crash_image;
  139. #ifndef kexec_flush_icache_page
  140. #define kexec_flush_icache_page(page)
  141. #endif
  142. #define KEXEC_ON_CRASH 0x00000001
  143. #define KEXEC_PRESERVE_CONTEXT 0x00000002
  144. #define KEXEC_ARCH_MASK 0xffff0000
  145. /* These values match the ELF architecture values.
  146. * Unless there is a good reason that should continue to be the case.
  147. */
  148. #define KEXEC_ARCH_DEFAULT ( 0 << 16)
  149. #define KEXEC_ARCH_386 ( 3 << 16)
  150. #define KEXEC_ARCH_X86_64 (62 << 16)
  151. #define KEXEC_ARCH_PPC (20 << 16)
  152. #define KEXEC_ARCH_PPC64 (21 << 16)
  153. #define KEXEC_ARCH_IA_64 (50 << 16)
  154. #define KEXEC_ARCH_ARM (40 << 16)
  155. #define KEXEC_ARCH_S390 (22 << 16)
  156. #define KEXEC_ARCH_SH (42 << 16)
  157. #define KEXEC_ARCH_MIPS_LE (10 << 16)
  158. #define KEXEC_ARCH_MIPS ( 8 << 16)
  159. /* List of defined/legal kexec flags */
  160. #ifndef CONFIG_KEXEC_JUMP
  161. #define KEXEC_FLAGS KEXEC_ON_CRASH
  162. #else
  163. #define KEXEC_FLAGS (KEXEC_ON_CRASH | KEXEC_PRESERVE_CONTEXT)
  164. #endif
  165. #define VMCOREINFO_BYTES (4096)
  166. #define VMCOREINFO_NOTE_NAME "VMCOREINFO"
  167. #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
  168. #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
  169. + VMCOREINFO_NOTE_NAME_BYTES)
  170. /* Location of a reserved region to hold the crash kernel.
  171. */
  172. extern struct resource crashk_res;
  173. typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
  174. extern note_buf_t __percpu *crash_notes;
  175. extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
  176. extern size_t vmcoreinfo_size;
  177. extern size_t vmcoreinfo_max_size;
  178. int __init parse_crashkernel(char *cmdline, unsigned long long system_ram,
  179. unsigned long long *crash_size, unsigned long long *crash_base);
  180. int crash_shrink_memory(unsigned long new_size);
  181. size_t crash_get_memory_size(void);
  182. void crash_free_reserved_phys_range(unsigned long begin, unsigned long end);
  183. #else /* !CONFIG_KEXEC */
  184. struct pt_regs;
  185. struct task_struct;
  186. static inline void crash_kexec(struct pt_regs *regs) { }
  187. static inline int kexec_should_crash(struct task_struct *p) { return 0; }
  188. #endif /* CONFIG_KEXEC */
  189. #endif /* LINUX_KEXEC_H */