kexec.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_CODE_SIZE
  23. #error KEXEC_CONTROL_CODE_SIZE not defined
  24. #endif
  25. #ifndef KEXEC_ARCH
  26. #error KEXEC_ARCH not defined
  27. #endif
  28. #define KEXEC_NOTE_HEAD_BYTES ALIGN(sizeof(struct elf_note), 4)
  29. #define KEXEC_CORE_NOTE_NAME "CORE"
  30. #define KEXEC_CORE_NOTE_NAME_BYTES ALIGN(sizeof(KEXEC_CORE_NOTE_NAME), 4)
  31. #define KEXEC_CORE_NOTE_DESC_BYTES ALIGN(sizeof(struct elf_prstatus), 4)
  32. /*
  33. * The per-cpu notes area is a list of notes terminated by a "NULL"
  34. * note header. For kdump, the code in vmcore.c runs in the context
  35. * of the second kernel to combine them into one note.
  36. */
  37. #define KEXEC_NOTE_BYTES ( (KEXEC_NOTE_HEAD_BYTES * 2) + \
  38. KEXEC_CORE_NOTE_NAME_BYTES + \
  39. KEXEC_CORE_NOTE_DESC_BYTES )
  40. /*
  41. * This structure is used to hold the arguments that are used when loading
  42. * kernel binaries.
  43. */
  44. typedef unsigned long kimage_entry_t;
  45. #define IND_DESTINATION 0x1
  46. #define IND_INDIRECTION 0x2
  47. #define IND_DONE 0x4
  48. #define IND_SOURCE 0x8
  49. #define KEXEC_SEGMENT_MAX 16
  50. struct kexec_segment {
  51. void __user *buf;
  52. size_t bufsz;
  53. unsigned long mem; /* User space sees this as a (void *) ... */
  54. size_t memsz;
  55. };
  56. #ifdef CONFIG_COMPAT
  57. struct compat_kexec_segment {
  58. compat_uptr_t buf;
  59. compat_size_t bufsz;
  60. compat_ulong_t mem; /* User space sees this as a (void *) ... */
  61. compat_size_t memsz;
  62. };
  63. #endif
  64. struct kimage {
  65. kimage_entry_t head;
  66. kimage_entry_t *entry;
  67. kimage_entry_t *last_entry;
  68. unsigned long destination;
  69. unsigned long start;
  70. struct page *control_code_page;
  71. unsigned long nr_segments;
  72. struct kexec_segment segment[KEXEC_SEGMENT_MAX];
  73. struct list_head control_pages;
  74. struct list_head dest_pages;
  75. struct list_head unuseable_pages;
  76. /* Address of next control page to allocate for crash kernels. */
  77. unsigned long control_page;
  78. /* Flags to indicate special processing */
  79. unsigned int type : 1;
  80. #define KEXEC_TYPE_DEFAULT 0
  81. #define KEXEC_TYPE_CRASH 1
  82. };
  83. /* kexec interface functions */
  84. extern NORET_TYPE void machine_kexec(struct kimage *image) ATTRIB_NORET;
  85. extern int machine_kexec_prepare(struct kimage *image);
  86. extern void machine_kexec_cleanup(struct kimage *image);
  87. extern asmlinkage long sys_kexec_load(unsigned long entry,
  88. unsigned long nr_segments,
  89. struct kexec_segment __user *segments,
  90. unsigned long flags);
  91. #ifdef CONFIG_COMPAT
  92. extern asmlinkage long compat_sys_kexec_load(unsigned long entry,
  93. unsigned long nr_segments,
  94. struct compat_kexec_segment __user *segments,
  95. unsigned long flags);
  96. #endif
  97. extern struct page *kimage_alloc_control_pages(struct kimage *image,
  98. unsigned int order);
  99. extern void crash_kexec(struct pt_regs *);
  100. int kexec_should_crash(struct task_struct *);
  101. void crash_save_cpu(struct pt_regs *regs, int cpu);
  102. void crash_save_vmcoreinfo(void);
  103. void arch_crash_save_vmcoreinfo(void);
  104. void vmcoreinfo_append_str(const char *fmt, ...);
  105. unsigned long paddr_vmcoreinfo_note(void);
  106. #define SYMBOL(name) \
  107. vmcoreinfo_append_str("SYMBOL(%s)=%lx\n", #name, (unsigned long)&name)
  108. #define SIZE(name) \
  109. vmcoreinfo_append_str("SIZE(%s)=%d\n", #name, sizeof(struct name))
  110. #define OFFSET(name, field) \
  111. vmcoreinfo_append_str("OFFSET(%s.%s)=%d\n", #name, #field, \
  112. &(((struct name *)0)->field))
  113. #define LENGTH(name, value) \
  114. vmcoreinfo_append_str("LENGTH(%s)=%d\n", #name, value)
  115. #define CONFIG(name) \
  116. vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
  117. extern struct kimage *kexec_image;
  118. extern struct kimage *kexec_crash_image;
  119. #ifndef kexec_flush_icache_page
  120. #define kexec_flush_icache_page(page)
  121. #endif
  122. #define KEXEC_ON_CRASH 0x00000001
  123. #define KEXEC_ARCH_MASK 0xffff0000
  124. /* These values match the ELF architecture values.
  125. * Unless there is a good reason that should continue to be the case.
  126. */
  127. #define KEXEC_ARCH_DEFAULT ( 0 << 16)
  128. #define KEXEC_ARCH_386 ( 3 << 16)
  129. #define KEXEC_ARCH_X86_64 (62 << 16)
  130. #define KEXEC_ARCH_PPC (20 << 16)
  131. #define KEXEC_ARCH_PPC64 (21 << 16)
  132. #define KEXEC_ARCH_IA_64 (50 << 16)
  133. #define KEXEC_ARCH_ARM (40 << 16)
  134. #define KEXEC_ARCH_S390 (22 << 16)
  135. #define KEXEC_ARCH_SH (42 << 16)
  136. #define KEXEC_ARCH_MIPS_LE (10 << 16)
  137. #define KEXEC_ARCH_MIPS ( 8 << 16)
  138. #define KEXEC_FLAGS (KEXEC_ON_CRASH) /* List of defined/legal kexec flags */
  139. #define VMCOREINFO_BYTES (4096)
  140. #define VMCOREINFO_NOTE_NAME "VMCOREINFO"
  141. #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
  142. #define VMCOREINFO_NOTE_SIZE (KEXEC_NOTE_HEAD_BYTES*2 + VMCOREINFO_BYTES \
  143. + VMCOREINFO_NOTE_NAME_BYTES)
  144. /* Location of a reserved region to hold the crash kernel.
  145. */
  146. extern struct resource crashk_res;
  147. typedef u32 note_buf_t[KEXEC_NOTE_BYTES/4];
  148. extern note_buf_t *crash_notes;
  149. extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
  150. extern unsigned int vmcoreinfo_size;
  151. extern unsigned int vmcoreinfo_max_size;
  152. #else /* !CONFIG_KEXEC */
  153. struct pt_regs;
  154. struct task_struct;
  155. static inline void crash_kexec(struct pt_regs *regs) { }
  156. static inline int kexec_should_crash(struct task_struct *p) { return 0; }
  157. #endif /* CONFIG_KEXEC */
  158. #endif /* LINUX_KEXEC_H */