kexec.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /******************************************************************************
  2. * kexec.h - Public portion
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to
  6. * deal in the Software without restriction, including without limitation the
  7. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. * sell copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. *
  22. * Xen port written by:
  23. * - Simon 'Horms' Horman <horms@verge.net.au>
  24. * - Magnus Damm <magnus@valinux.co.jp>
  25. */
  26. #ifndef _XEN_PUBLIC_KEXEC_H
  27. #define _XEN_PUBLIC_KEXEC_H
  28. /* This file describes the Kexec / Kdump hypercall interface for Xen.
  29. *
  30. * Kexec under vanilla Linux allows a user to reboot the physical machine
  31. * into a new user-specified kernel. The Xen port extends this idea
  32. * to allow rebooting of the machine from dom0. When kexec for dom0
  33. * is used to reboot, both the hypervisor and the domains get replaced
  34. * with some other kernel. It is possible to kexec between vanilla
  35. * Linux and Xen and back again. Xen to Xen works well too.
  36. *
  37. * The hypercall interface for kexec can be divided into three main
  38. * types of hypercall operations:
  39. *
  40. * 1) Range information:
  41. * This is used by the dom0 kernel to ask the hypervisor about various
  42. * address information. This information is needed to allow kexec-tools
  43. * to fill in the ELF headers for /proc/vmcore properly.
  44. *
  45. * 2) Load and unload of images:
  46. * There are no big surprises here, the kexec binary from kexec-tools
  47. * runs in userspace in dom0. The tool loads/unloads data into the
  48. * dom0 kernel such as new kernel, initramfs and hypervisor. When
  49. * loaded the dom0 kernel performs a load hypercall operation, and
  50. * before releasing all page references the dom0 kernel calls unload.
  51. *
  52. * 3) Kexec operation:
  53. * This is used to start a previously loaded kernel.
  54. */
  55. #include "xen.h"
  56. #if defined(__i386__) || defined(__x86_64__)
  57. #define KEXEC_XEN_NO_PAGES 17
  58. #endif
  59. /*
  60. * Prototype for this hypercall is:
  61. * int kexec_op(int cmd, void *args)
  62. * @cmd == KEXEC_CMD_...
  63. * KEXEC operation to perform
  64. * @args == Operation-specific extra arguments (NULL if none).
  65. */
  66. /*
  67. * Kexec supports two types of operation:
  68. * - kexec into a regular kernel, very similar to a standard reboot
  69. * - KEXEC_TYPE_DEFAULT is used to specify this type
  70. * - kexec into a special "crash kernel", aka kexec-on-panic
  71. * - KEXEC_TYPE_CRASH is used to specify this type
  72. * - parts of our system may be broken at kexec-on-panic time
  73. * - the code should be kept as simple and self-contained as possible
  74. */
  75. #define KEXEC_TYPE_DEFAULT 0
  76. #define KEXEC_TYPE_CRASH 1
  77. /* The kexec implementation for Xen allows the user to load two
  78. * types of kernels, KEXEC_TYPE_DEFAULT and KEXEC_TYPE_CRASH.
  79. * All data needed for a kexec reboot is kept in one xen_kexec_image_t
  80. * per "instance". The data mainly consists of machine address lists to pages
  81. * together with destination addresses. The data in xen_kexec_image_t
  82. * is passed to the "code page" which is one page of code that performs
  83. * the final relocations before jumping to the new kernel.
  84. */
  85. typedef struct xen_kexec_image {
  86. #if defined(__i386__) || defined(__x86_64__)
  87. unsigned long page_list[KEXEC_XEN_NO_PAGES];
  88. #endif
  89. unsigned long indirection_page;
  90. unsigned long start_address;
  91. } xen_kexec_image_t;
  92. /*
  93. * Perform kexec having previously loaded a kexec or kdump kernel
  94. * as appropriate.
  95. * type == KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH [in]
  96. *
  97. * Control is transferred to the image entry point with the host in
  98. * the following state.
  99. *
  100. * - The image may be executed on any PCPU and all other PCPUs are
  101. * stopped.
  102. *
  103. * - Local interrupts are disabled.
  104. *
  105. * - Register values are undefined.
  106. *
  107. * - The image segments have writeable 1:1 virtual to machine
  108. * mappings. The location of any page tables is undefined and these
  109. * page table frames are not be mapped.
  110. */
  111. #define KEXEC_CMD_kexec 0
  112. typedef struct xen_kexec_exec {
  113. int type;
  114. } xen_kexec_exec_t;
  115. /*
  116. * Load/Unload kernel image for kexec or kdump.
  117. * type == KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH [in]
  118. * image == relocation information for kexec (ignored for unload) [in]
  119. */
  120. #define KEXEC_CMD_kexec_load_v1 1 /* obsolete since 0x00040400 */
  121. #define KEXEC_CMD_kexec_unload_v1 2 /* obsolete since 0x00040400 */
  122. typedef struct xen_kexec_load_v1 {
  123. int type;
  124. xen_kexec_image_t image;
  125. } xen_kexec_load_v1_t;
  126. #define KEXEC_RANGE_MA_CRASH 0 /* machine address and size of crash area */
  127. #define KEXEC_RANGE_MA_XEN 1 /* machine address and size of Xen itself */
  128. #define KEXEC_RANGE_MA_CPU 2 /* machine address and size of a CPU note */
  129. #define KEXEC_RANGE_MA_XENHEAP 3 /* machine address and size of xenheap
  130. * Note that although this is adjacent
  131. * to Xen it exists in a separate EFI
  132. * region on ia64, and thus needs to be
  133. * inserted into iomem_machine separately */
  134. #define KEXEC_RANGE_MA_BOOT_PARAM 4 /* Obsolete: machine address and size of
  135. * the ia64_boot_param */
  136. #define KEXEC_RANGE_MA_EFI_MEMMAP 5 /* machine address and size of
  137. * of the EFI Memory Map */
  138. #define KEXEC_RANGE_MA_VMCOREINFO 6 /* machine address and size of vmcoreinfo */
  139. /*
  140. * Find the address and size of certain memory areas
  141. * range == KEXEC_RANGE_... [in]
  142. * nr == physical CPU number (starting from 0) if KEXEC_RANGE_MA_CPU [in]
  143. * size == number of bytes reserved in window [out]
  144. * start == address of the first byte in the window [out]
  145. */
  146. #define KEXEC_CMD_kexec_get_range 3
  147. typedef struct xen_kexec_range {
  148. int range;
  149. int nr;
  150. unsigned long size;
  151. unsigned long start;
  152. } xen_kexec_range_t;
  153. #if __XEN_INTERFACE_VERSION__ >= 0x00040400
  154. /*
  155. * A contiguous chunk of a kexec image and it's destination machine
  156. * address.
  157. */
  158. typedef struct xen_kexec_segment {
  159. union {
  160. XEN_GUEST_HANDLE(const_void) h;
  161. uint64_t _pad;
  162. } buf;
  163. uint64_t buf_size;
  164. uint64_t dest_maddr;
  165. uint64_t dest_size;
  166. } xen_kexec_segment_t;
  167. DEFINE_XEN_GUEST_HANDLE(xen_kexec_segment_t);
  168. /*
  169. * Load a kexec image into memory.
  170. *
  171. * For KEXEC_TYPE_DEFAULT images, the segments may be anywhere in RAM.
  172. * The image is relocated prior to being executed.
  173. *
  174. * For KEXEC_TYPE_CRASH images, each segment of the image must reside
  175. * in the memory region reserved for kexec (KEXEC_RANGE_MA_CRASH) and
  176. * the entry point must be within the image. The caller is responsible
  177. * for ensuring that multiple images do not overlap.
  178. *
  179. * All image segments will be loaded to their destination machine
  180. * addresses prior to being executed. The trailing portion of any
  181. * segments with a source buffer (from dest_maddr + buf_size to
  182. * dest_maddr + dest_size) will be zeroed.
  183. *
  184. * Segments with no source buffer will be accessible to the image when
  185. * it is executed.
  186. */
  187. #define KEXEC_CMD_kexec_load 4
  188. typedef struct xen_kexec_load {
  189. uint8_t type; /* One of KEXEC_TYPE_* */
  190. uint8_t _pad;
  191. uint16_t arch; /* ELF machine type (EM_*). */
  192. uint32_t nr_segments;
  193. union {
  194. XEN_GUEST_HANDLE(xen_kexec_segment_t) h;
  195. uint64_t _pad;
  196. } segments;
  197. uint64_t entry_maddr; /* image entry point machine address. */
  198. } xen_kexec_load_t;
  199. DEFINE_XEN_GUEST_HANDLE(xen_kexec_load_t);
  200. /*
  201. * Unload a kexec image.
  202. *
  203. * Type must be one of KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH.
  204. */
  205. #define KEXEC_CMD_kexec_unload 5
  206. typedef struct xen_kexec_unload {
  207. uint8_t type;
  208. } xen_kexec_unload_t;
  209. DEFINE_XEN_GUEST_HANDLE(xen_kexec_unload_t);
  210. /*
  211. * Figure out whether we have an image loaded. A return value of
  212. * zero indicates no image loaded. A return value of one
  213. * indicates an image is loaded. A negative return value
  214. * indicates an error.
  215. *
  216. * Type must be one of KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH.
  217. */
  218. #define KEXEC_CMD_kexec_status 6
  219. typedef struct xen_kexec_status {
  220. uint8_t type;
  221. } xen_kexec_status_t;
  222. DEFINE_XEN_GUEST_HANDLE(xen_kexec_status_t);
  223. #else /* __XEN_INTERFACE_VERSION__ < 0x00040400 */
  224. #define KEXEC_CMD_kexec_load KEXEC_CMD_kexec_load_v1
  225. #define KEXEC_CMD_kexec_unload KEXEC_CMD_kexec_unload_v1
  226. #define xen_kexec_load xen_kexec_load_v1
  227. #define xen_kexec_load_t xen_kexec_load_v1_t
  228. #endif
  229. #endif /* _XEN_PUBLIC_KEXEC_H */
  230. /*
  231. * Local variables:
  232. * mode: C
  233. * c-file-style: "BSD"
  234. * c-basic-offset: 4
  235. * tab-width: 4
  236. * indent-tabs-mode: nil
  237. * End:
  238. */