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