xref: /freebsd/sys/contrib/xen/kexec.h (revision 3a9fd824)
13a9fd824SRoger Pau Monné /******************************************************************************
23a9fd824SRoger Pau Monné  * kexec.h - Public portion
33a9fd824SRoger Pau Monné  *
43a9fd824SRoger Pau Monné  * Permission is hereby granted, free of charge, to any person obtaining a copy
53a9fd824SRoger Pau Monné  * of this software and associated documentation files (the "Software"), to
63a9fd824SRoger Pau Monné  * deal in the Software without restriction, including without limitation the
73a9fd824SRoger Pau Monné  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
83a9fd824SRoger Pau Monné  * sell copies of the Software, and to permit persons to whom the Software is
93a9fd824SRoger Pau Monné  * furnished to do so, subject to the following conditions:
103a9fd824SRoger Pau Monné  *
113a9fd824SRoger Pau Monné  * The above copyright notice and this permission notice shall be included in
123a9fd824SRoger Pau Monné  * all copies or substantial portions of the Software.
133a9fd824SRoger Pau Monné  *
143a9fd824SRoger Pau Monné  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
153a9fd824SRoger Pau Monné  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
163a9fd824SRoger Pau Monné  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
173a9fd824SRoger Pau Monné  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
183a9fd824SRoger Pau Monné  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
193a9fd824SRoger Pau Monné  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
203a9fd824SRoger Pau Monné  * DEALINGS IN THE SOFTWARE.
213a9fd824SRoger Pau Monné  *
223a9fd824SRoger Pau Monné  * Xen port written by:
233a9fd824SRoger Pau Monné  * - Simon 'Horms' Horman <horms@verge.net.au>
243a9fd824SRoger Pau Monné  * - Magnus Damm <magnus@valinux.co.jp>
253a9fd824SRoger Pau Monné  */
263a9fd824SRoger Pau Monné 
273a9fd824SRoger Pau Monné #ifndef _XEN_PUBLIC_KEXEC_H
283a9fd824SRoger Pau Monné #define _XEN_PUBLIC_KEXEC_H
293a9fd824SRoger Pau Monné 
303a9fd824SRoger Pau Monné 
313a9fd824SRoger Pau Monné /* This file describes the Kexec / Kdump hypercall interface for Xen.
323a9fd824SRoger Pau Monné  *
333a9fd824SRoger Pau Monné  * Kexec under vanilla Linux allows a user to reboot the physical machine
343a9fd824SRoger Pau Monné  * into a new user-specified kernel. The Xen port extends this idea
353a9fd824SRoger Pau Monné  * to allow rebooting of the machine from dom0. When kexec for dom0
363a9fd824SRoger Pau Monné  * is used to reboot,  both the hypervisor and the domains get replaced
373a9fd824SRoger Pau Monné  * with some other kernel. It is possible to kexec between vanilla
383a9fd824SRoger Pau Monné  * Linux and Xen and back again. Xen to Xen works well too.
393a9fd824SRoger Pau Monné  *
403a9fd824SRoger Pau Monné  * The hypercall interface for kexec can be divided into three main
413a9fd824SRoger Pau Monné  * types of hypercall operations:
423a9fd824SRoger Pau Monné  *
433a9fd824SRoger Pau Monné  * 1) Range information:
443a9fd824SRoger Pau Monné  *    This is used by the dom0 kernel to ask the hypervisor about various
453a9fd824SRoger Pau Monné  *    address information. This information is needed to allow kexec-tools
463a9fd824SRoger Pau Monné  *    to fill in the ELF headers for /proc/vmcore properly.
473a9fd824SRoger Pau Monné  *
483a9fd824SRoger Pau Monné  * 2) Load and unload of images:
493a9fd824SRoger Pau Monné  *    There are no big surprises here, the kexec binary from kexec-tools
503a9fd824SRoger Pau Monné  *    runs in userspace in dom0. The tool loads/unloads data into the
513a9fd824SRoger Pau Monné  *    dom0 kernel such as new kernel, initramfs and hypervisor. When
523a9fd824SRoger Pau Monné  *    loaded the dom0 kernel performs a load hypercall operation, and
533a9fd824SRoger Pau Monné  *    before releasing all page references the dom0 kernel calls unload.
543a9fd824SRoger Pau Monné  *
553a9fd824SRoger Pau Monné  * 3) Kexec operation:
563a9fd824SRoger Pau Monné  *    This is used to start a previously loaded kernel.
573a9fd824SRoger Pau Monné  */
583a9fd824SRoger Pau Monné 
593a9fd824SRoger Pau Monné #include "xen.h"
603a9fd824SRoger Pau Monné 
613a9fd824SRoger Pau Monné #if defined(__i386__) || defined(__x86_64__)
623a9fd824SRoger Pau Monné #define KEXEC_XEN_NO_PAGES 17
633a9fd824SRoger Pau Monné #endif
643a9fd824SRoger Pau Monné 
653a9fd824SRoger Pau Monné /*
663a9fd824SRoger Pau Monné  * Prototype for this hypercall is:
673a9fd824SRoger Pau Monné  *  int kexec_op(int cmd, void *args)
683a9fd824SRoger Pau Monné  * @cmd  == KEXEC_CMD_...
693a9fd824SRoger Pau Monné  *          KEXEC operation to perform
703a9fd824SRoger Pau Monné  * @args == Operation-specific extra arguments (NULL if none).
713a9fd824SRoger Pau Monné  */
723a9fd824SRoger Pau Monné 
733a9fd824SRoger Pau Monné /*
743a9fd824SRoger Pau Monné  * Kexec supports two types of operation:
753a9fd824SRoger Pau Monné  * - kexec into a regular kernel, very similar to a standard reboot
763a9fd824SRoger Pau Monné  *   - KEXEC_TYPE_DEFAULT is used to specify this type
773a9fd824SRoger Pau Monné  * - kexec into a special "crash kernel", aka kexec-on-panic
783a9fd824SRoger Pau Monné  *   - KEXEC_TYPE_CRASH is used to specify this type
793a9fd824SRoger Pau Monné  *   - parts of our system may be broken at kexec-on-panic time
803a9fd824SRoger Pau Monné  *     - the code should be kept as simple and self-contained as possible
813a9fd824SRoger Pau Monné  */
823a9fd824SRoger Pau Monné 
833a9fd824SRoger Pau Monné #define KEXEC_TYPE_DEFAULT 0
843a9fd824SRoger Pau Monné #define KEXEC_TYPE_CRASH   1
853a9fd824SRoger Pau Monné 
863a9fd824SRoger Pau Monné 
873a9fd824SRoger Pau Monné /* The kexec implementation for Xen allows the user to load two
883a9fd824SRoger Pau Monné  * types of kernels, KEXEC_TYPE_DEFAULT and KEXEC_TYPE_CRASH.
893a9fd824SRoger Pau Monné  * All data needed for a kexec reboot is kept in one xen_kexec_image_t
903a9fd824SRoger Pau Monné  * per "instance". The data mainly consists of machine address lists to pages
913a9fd824SRoger Pau Monné  * together with destination addresses. The data in xen_kexec_image_t
923a9fd824SRoger Pau Monné  * is passed to the "code page" which is one page of code that performs
933a9fd824SRoger Pau Monné  * the final relocations before jumping to the new kernel.
943a9fd824SRoger Pau Monné  */
953a9fd824SRoger Pau Monné 
963a9fd824SRoger Pau Monné typedef struct xen_kexec_image {
973a9fd824SRoger Pau Monné #if defined(__i386__) || defined(__x86_64__)
983a9fd824SRoger Pau Monné     unsigned long page_list[KEXEC_XEN_NO_PAGES];
993a9fd824SRoger Pau Monné #endif
1003a9fd824SRoger Pau Monné     unsigned long indirection_page;
1013a9fd824SRoger Pau Monné     unsigned long start_address;
1023a9fd824SRoger Pau Monné } xen_kexec_image_t;
1033a9fd824SRoger Pau Monné 
1043a9fd824SRoger Pau Monné /*
1053a9fd824SRoger Pau Monné  * Perform kexec having previously loaded a kexec or kdump kernel
1063a9fd824SRoger Pau Monné  * as appropriate.
1073a9fd824SRoger Pau Monné  * type == KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH [in]
1083a9fd824SRoger Pau Monné  *
1093a9fd824SRoger Pau Monné  * Control is transferred to the image entry point with the host in
1103a9fd824SRoger Pau Monné  * the following state.
1113a9fd824SRoger Pau Monné  *
1123a9fd824SRoger Pau Monné  * - The image may be executed on any PCPU and all other PCPUs are
1133a9fd824SRoger Pau Monné  *   stopped.
1143a9fd824SRoger Pau Monné  *
1153a9fd824SRoger Pau Monné  * - Local interrupts are disabled.
1163a9fd824SRoger Pau Monné  *
1173a9fd824SRoger Pau Monné  * - Register values are undefined.
1183a9fd824SRoger Pau Monné  *
1193a9fd824SRoger Pau Monné  * - The image segments have writeable 1:1 virtual to machine
1203a9fd824SRoger Pau Monné  *   mappings.  The location of any page tables is undefined and these
1213a9fd824SRoger Pau Monné  *   page table frames are not be mapped.
1223a9fd824SRoger Pau Monné  */
1233a9fd824SRoger Pau Monné #define KEXEC_CMD_kexec                 0
1243a9fd824SRoger Pau Monné typedef struct xen_kexec_exec {
1253a9fd824SRoger Pau Monné     int type;
1263a9fd824SRoger Pau Monné } xen_kexec_exec_t;
1273a9fd824SRoger Pau Monné 
1283a9fd824SRoger Pau Monné /*
1293a9fd824SRoger Pau Monné  * Load/Unload kernel image for kexec or kdump.
1303a9fd824SRoger Pau Monné  * type  == KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH [in]
1313a9fd824SRoger Pau Monné  * image == relocation information for kexec (ignored for unload) [in]
1323a9fd824SRoger Pau Monné  */
1333a9fd824SRoger Pau Monné #define KEXEC_CMD_kexec_load_v1         1 /* obsolete since 0x00040400 */
1343a9fd824SRoger Pau Monné #define KEXEC_CMD_kexec_unload_v1       2 /* obsolete since 0x00040400 */
1353a9fd824SRoger Pau Monné typedef struct xen_kexec_load_v1 {
1363a9fd824SRoger Pau Monné     int type;
1373a9fd824SRoger Pau Monné     xen_kexec_image_t image;
1383a9fd824SRoger Pau Monné } xen_kexec_load_v1_t;
1393a9fd824SRoger Pau Monné 
1403a9fd824SRoger Pau Monné #define KEXEC_RANGE_MA_CRASH      0 /* machine address and size of crash area */
1413a9fd824SRoger Pau Monné #define KEXEC_RANGE_MA_XEN        1 /* machine address and size of Xen itself */
1423a9fd824SRoger Pau Monné #define KEXEC_RANGE_MA_CPU        2 /* machine address and size of a CPU note */
1433a9fd824SRoger Pau Monné #define KEXEC_RANGE_MA_XENHEAP    3 /* machine address and size of xenheap
1443a9fd824SRoger Pau Monné                                      * Note that although this is adjacent
1453a9fd824SRoger Pau Monné                                      * to Xen it exists in a separate EFI
1463a9fd824SRoger Pau Monné                                      * region on ia64, and thus needs to be
1473a9fd824SRoger Pau Monné                                      * inserted into iomem_machine separately */
1483a9fd824SRoger Pau Monné #define KEXEC_RANGE_MA_BOOT_PARAM 4 /* Obsolete: machine address and size of
1493a9fd824SRoger Pau Monné                                      * the ia64_boot_param */
1503a9fd824SRoger Pau Monné #define KEXEC_RANGE_MA_EFI_MEMMAP 5 /* machine address and size of
1513a9fd824SRoger Pau Monné                                      * of the EFI Memory Map */
1523a9fd824SRoger Pau Monné #define KEXEC_RANGE_MA_VMCOREINFO 6 /* machine address and size of vmcoreinfo */
1533a9fd824SRoger Pau Monné 
1543a9fd824SRoger Pau Monné /*
1553a9fd824SRoger Pau Monné  * Find the address and size of certain memory areas
1563a9fd824SRoger Pau Monné  * range == KEXEC_RANGE_... [in]
1573a9fd824SRoger Pau Monné  * nr    == physical CPU number (starting from 0) if KEXEC_RANGE_MA_CPU [in]
1583a9fd824SRoger Pau Monné  * size  == number of bytes reserved in window [out]
1593a9fd824SRoger Pau Monné  * start == address of the first byte in the window [out]
1603a9fd824SRoger Pau Monné  */
1613a9fd824SRoger Pau Monné #define KEXEC_CMD_kexec_get_range       3
1623a9fd824SRoger Pau Monné typedef struct xen_kexec_range {
1633a9fd824SRoger Pau Monné     int range;
1643a9fd824SRoger Pau Monné     int nr;
1653a9fd824SRoger Pau Monné     unsigned long size;
1663a9fd824SRoger Pau Monné     unsigned long start;
1673a9fd824SRoger Pau Monné } xen_kexec_range_t;
1683a9fd824SRoger Pau Monné 
1693a9fd824SRoger Pau Monné #if __XEN_INTERFACE_VERSION__ >= 0x00040400
1703a9fd824SRoger Pau Monné /*
1713a9fd824SRoger Pau Monné  * A contiguous chunk of a kexec image and it's destination machine
1723a9fd824SRoger Pau Monné  * address.
1733a9fd824SRoger Pau Monné  */
1743a9fd824SRoger Pau Monné typedef struct xen_kexec_segment {
1753a9fd824SRoger Pau Monné     union {
1763a9fd824SRoger Pau Monné         XEN_GUEST_HANDLE(const_void) h;
1773a9fd824SRoger Pau Monné         uint64_t _pad;
1783a9fd824SRoger Pau Monné     } buf;
1793a9fd824SRoger Pau Monné     uint64_t buf_size;
1803a9fd824SRoger Pau Monné     uint64_t dest_maddr;
1813a9fd824SRoger Pau Monné     uint64_t dest_size;
1823a9fd824SRoger Pau Monné } xen_kexec_segment_t;
1833a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(xen_kexec_segment_t);
1843a9fd824SRoger Pau Monné 
1853a9fd824SRoger Pau Monné /*
1863a9fd824SRoger Pau Monné  * Load a kexec image into memory.
1873a9fd824SRoger Pau Monné  *
1883a9fd824SRoger Pau Monné  * For KEXEC_TYPE_DEFAULT images, the segments may be anywhere in RAM.
1893a9fd824SRoger Pau Monné  * The image is relocated prior to being executed.
1903a9fd824SRoger Pau Monné  *
1913a9fd824SRoger Pau Monné  * For KEXEC_TYPE_CRASH images, each segment of the image must reside
1923a9fd824SRoger Pau Monné  * in the memory region reserved for kexec (KEXEC_RANGE_MA_CRASH) and
1933a9fd824SRoger Pau Monné  * the entry point must be within the image. The caller is responsible
1943a9fd824SRoger Pau Monné  * for ensuring that multiple images do not overlap.
1953a9fd824SRoger Pau Monné  *
1963a9fd824SRoger Pau Monné  * All image segments will be loaded to their destination machine
1973a9fd824SRoger Pau Monné  * addresses prior to being executed.  The trailing portion of any
1983a9fd824SRoger Pau Monné  * segments with a source buffer (from dest_maddr + buf_size to
1993a9fd824SRoger Pau Monné  * dest_maddr + dest_size) will be zeroed.
2003a9fd824SRoger Pau Monné  *
2013a9fd824SRoger Pau Monné  * Segments with no source buffer will be accessible to the image when
2023a9fd824SRoger Pau Monné  * it is executed.
2033a9fd824SRoger Pau Monné  */
2043a9fd824SRoger Pau Monné 
2053a9fd824SRoger Pau Monné #define KEXEC_CMD_kexec_load 4
2063a9fd824SRoger Pau Monné typedef struct xen_kexec_load {
2073a9fd824SRoger Pau Monné     uint8_t  type;        /* One of KEXEC_TYPE_* */
2083a9fd824SRoger Pau Monné     uint8_t  _pad;
2093a9fd824SRoger Pau Monné     uint16_t arch;        /* ELF machine type (EM_*). */
2103a9fd824SRoger Pau Monné     uint32_t nr_segments;
2113a9fd824SRoger Pau Monné     union {
2123a9fd824SRoger Pau Monné         XEN_GUEST_HANDLE(xen_kexec_segment_t) h;
2133a9fd824SRoger Pau Monné         uint64_t _pad;
2143a9fd824SRoger Pau Monné     } segments;
2153a9fd824SRoger Pau Monné     uint64_t entry_maddr; /* image entry point machine address. */
2163a9fd824SRoger Pau Monné } xen_kexec_load_t;
2173a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(xen_kexec_load_t);
2183a9fd824SRoger Pau Monné 
2193a9fd824SRoger Pau Monné /*
2203a9fd824SRoger Pau Monné  * Unload a kexec image.
2213a9fd824SRoger Pau Monné  *
2223a9fd824SRoger Pau Monné  * Type must be one of KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH.
2233a9fd824SRoger Pau Monné  */
2243a9fd824SRoger Pau Monné #define KEXEC_CMD_kexec_unload 5
2253a9fd824SRoger Pau Monné typedef struct xen_kexec_unload {
2263a9fd824SRoger Pau Monné     uint8_t type;
2273a9fd824SRoger Pau Monné } xen_kexec_unload_t;
2283a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(xen_kexec_unload_t);
2293a9fd824SRoger Pau Monné 
2303a9fd824SRoger Pau Monné /*
2313a9fd824SRoger Pau Monné  * Figure out whether we have an image loaded. A return value of
2323a9fd824SRoger Pau Monné  * zero indicates no image loaded. A return value of one
2333a9fd824SRoger Pau Monné  * indicates an image is loaded. A negative return value
2343a9fd824SRoger Pau Monné  * indicates an error.
2353a9fd824SRoger Pau Monné  *
2363a9fd824SRoger Pau Monné  * Type must be one of KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH.
2373a9fd824SRoger Pau Monné  */
2383a9fd824SRoger Pau Monné #define KEXEC_CMD_kexec_status 6
2393a9fd824SRoger Pau Monné typedef struct xen_kexec_status {
2403a9fd824SRoger Pau Monné     uint8_t type;
2413a9fd824SRoger Pau Monné } xen_kexec_status_t;
2423a9fd824SRoger Pau Monné DEFINE_XEN_GUEST_HANDLE(xen_kexec_status_t);
2433a9fd824SRoger Pau Monné 
2443a9fd824SRoger Pau Monné #else /* __XEN_INTERFACE_VERSION__ < 0x00040400 */
2453a9fd824SRoger Pau Monné 
2463a9fd824SRoger Pau Monné #define KEXEC_CMD_kexec_load KEXEC_CMD_kexec_load_v1
2473a9fd824SRoger Pau Monné #define KEXEC_CMD_kexec_unload KEXEC_CMD_kexec_unload_v1
2483a9fd824SRoger Pau Monné #define xen_kexec_load xen_kexec_load_v1
2493a9fd824SRoger Pau Monné #define xen_kexec_load_t xen_kexec_load_v1_t
2503a9fd824SRoger Pau Monné 
2513a9fd824SRoger Pau Monné #endif
2523a9fd824SRoger Pau Monné 
2533a9fd824SRoger Pau Monné #endif /* _XEN_PUBLIC_KEXEC_H */
2543a9fd824SRoger Pau Monné 
2553a9fd824SRoger Pau Monné /*
2563a9fd824SRoger Pau Monné  * Local variables:
2573a9fd824SRoger Pau Monné  * mode: C
2583a9fd824SRoger Pau Monné  * c-file-style: "BSD"
2593a9fd824SRoger Pau Monné  * c-basic-offset: 4
2603a9fd824SRoger Pau Monné  * tab-width: 4
2613a9fd824SRoger Pau Monné  * indent-tabs-mode: nil
2623a9fd824SRoger Pau Monné  * End:
2633a9fd824SRoger Pau Monné  */
264