kexec.h 7.7 KB

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