kexec.h 6.6 KB

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