]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/xen/interface/kexec.h
MFV r368746:
[FreeBSD/FreeBSD.git] / sys / xen / interface / kexec.h
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
27 #ifndef _XEN_PUBLIC_KEXEC_H
28 #define _XEN_PUBLIC_KEXEC_H
29
30 /* This file describes the Kexec / Kdump hypercall interface for Xen.
31  *
32  * Kexec under vanilla Linux allows a user to reboot the physical machine 
33  * into a new user-specified kernel. The Xen port extends this idea
34  * to allow rebooting of the machine from dom0. When kexec for dom0
35  * is used to reboot,  both the hypervisor and the domains get replaced
36  * with some other kernel. It is possible to kexec between vanilla
37  * Linux and Xen and back again. Xen to Xen works well too.
38  *
39  * The hypercall interface for kexec can be divided into three main
40  * types of hypercall operations:
41  *
42  * 1) Range information:
43  *    This is used by the dom0 kernel to ask the hypervisor about various 
44  *    address information. This information is needed to allow kexec-tools 
45  *    to fill in the ELF headers for /proc/vmcore properly.
46  *
47  * 2) Load and unload of images:
48  *    There are no big surprises here, the kexec binary from kexec-tools
49  *    runs in userspace in dom0. The tool loads/unloads data into the
50  *    dom0 kernel such as new kernel, initramfs and hypervisor. When
51  *    loaded the dom0 kernel performs a load hypercall operation, and
52  *    before releasing all page references the dom0 kernel calls unload.
53  *
54  * 3) Kexec operation:
55  *    This is used to start a previously loaded kernel.
56  */
57
58 #include "xen.h"
59
60 #if defined(__i386__) || defined(__x86_64__)
61 #define KEXEC_XEN_NO_PAGES 17
62 #endif
63
64 /*
65  * Prototype for this hypercall is:
66  *  int kexec_op(int cmd, void *args)
67  * @cmd  == KEXEC_CMD_... 
68  *          KEXEC operation to perform
69  * @args == Operation-specific extra arguments (NULL if none).
70  */
71
72 /*
73  * Kexec supports two types of operation:
74  * - kexec into a regular kernel, very similar to a standard reboot
75  *   - KEXEC_TYPE_DEFAULT is used to specify this type
76  * - kexec into a special "crash kernel", aka kexec-on-panic
77  *   - KEXEC_TYPE_CRASH is used to specify this type
78  *   - parts of our system may be broken at kexec-on-panic time
79  *     - the code should be kept as simple and self-contained as possible
80  */
81
82 #define KEXEC_TYPE_DEFAULT 0
83 #define KEXEC_TYPE_CRASH   1
84
85 /* The kexec implementation for Xen allows the user to load two
86  * types of kernels, KEXEC_TYPE_DEFAULT and KEXEC_TYPE_CRASH.
87  * All data needed for a kexec reboot is kept in one xen_kexec_image_t
88  * per "instance". The data mainly consists of machine address lists to pages
89  * together with destination addresses. The data in xen_kexec_image_t
90  * is passed to the "code page" which is one page of code that performs
91  * the final relocations before jumping to the new kernel.
92  */
93
94 typedef struct xen_kexec_image {
95 #if defined(__i386__) || defined(__x86_64__)
96     unsigned long page_list[KEXEC_XEN_NO_PAGES];
97 #endif
98     unsigned long indirection_page;
99     unsigned long start_address;
100 } xen_kexec_image_t;
101
102 /*
103  * Perform kexec having previously loaded a kexec or kdump kernel
104  * as appropriate.
105  * type == KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH [in]
106  *
107  * Control is transferred to the image entry point with the host in
108  * the following state.
109  *
110  * - The image may be executed on any PCPU and all other PCPUs are
111  *   stopped.
112  *
113  * - Local interrupts are disabled.
114  *
115  * - Register values are undefined.
116  *
117  * - The image segments have writeable 1:1 virtual to machine
118  *   mappings.  The location of any page tables is undefined and these
119  *   page table frames are not be mapped.
120  */
121 #define KEXEC_CMD_kexec                 0
122 typedef struct xen_kexec_exec {
123     int type;
124 } xen_kexec_exec_t;
125
126 /*
127  * Load/Unload kernel image for kexec or kdump.
128  * type  == KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH [in]
129  * image == relocation information for kexec (ignored for unload) [in]
130  */
131 #define KEXEC_CMD_kexec_load_v1         1 /* obsolete since 0x00040400 */
132 #define KEXEC_CMD_kexec_unload_v1       2 /* obsolete since 0x00040400 */
133 typedef struct xen_kexec_load_v1 {
134     int type;
135     xen_kexec_image_t image;
136 } xen_kexec_load_v1_t;
137
138 #define KEXEC_RANGE_MA_CRASH      0 /* machine address and size of crash area */
139 #define KEXEC_RANGE_MA_XEN        1 /* machine address and size of Xen itself */
140 #define KEXEC_RANGE_MA_CPU        2 /* machine address and size of a CPU note */
141 #define KEXEC_RANGE_MA_XENHEAP    3 /* machine address and size of xenheap
142                                      * Note that although this is adjacent
143                                      * to Xen it exists in a separate EFI
144                                      * region on ia64, and thus needs to be
145                                      * inserted into iomem_machine separately */
146 #define KEXEC_RANGE_MA_BOOT_PARAM 4 /* Obsolete: machine address and size of
147                                      * the ia64_boot_param */
148 #define KEXEC_RANGE_MA_EFI_MEMMAP 5 /* machine address and size of
149                                      * of the EFI Memory Map */
150 #define KEXEC_RANGE_MA_VMCOREINFO 6 /* machine address and size of vmcoreinfo */
151
152 /*
153  * Find the address and size of certain memory areas
154  * range == KEXEC_RANGE_... [in]
155  * nr    == physical CPU number (starting from 0) if KEXEC_RANGE_MA_CPU [in]
156  * size  == number of bytes reserved in window [out]
157  * start == address of the first byte in the window [out]
158  */
159 #define KEXEC_CMD_kexec_get_range       3
160 typedef struct xen_kexec_range {
161     int range;
162     int nr;
163     unsigned long size;
164     unsigned long start;
165 } xen_kexec_range_t;
166
167 #if __XEN_INTERFACE_VERSION__ >= 0x00040400
168 /*
169  * A contiguous chunk of a kexec image and it's destination machine
170  * address.
171  */
172 typedef struct xen_kexec_segment {
173     union {
174         XEN_GUEST_HANDLE(const_void) h;
175         uint64_t _pad;
176     } buf;
177     uint64_t buf_size;
178     uint64_t dest_maddr;
179     uint64_t dest_size;
180 } xen_kexec_segment_t;
181 DEFINE_XEN_GUEST_HANDLE(xen_kexec_segment_t);
182
183 /*
184  * Load a kexec image into memory.
185  *
186  * For KEXEC_TYPE_DEFAULT images, the segments may be anywhere in RAM.
187  * The image is relocated prior to being executed.
188  *
189  * For KEXEC_TYPE_CRASH images, each segment of the image must reside
190  * in the memory region reserved for kexec (KEXEC_RANGE_MA_CRASH) and
191  * the entry point must be within the image. The caller is responsible
192  * for ensuring that multiple images do not overlap.
193  *
194  * All image segments will be loaded to their destination machine
195  * addresses prior to being executed.  The trailing portion of any
196  * segments with a source buffer (from dest_maddr + buf_size to
197  * dest_maddr + dest_size) will be zeroed.
198  *
199  * Segments with no source buffer will be accessible to the image when
200  * it is executed.
201  */
202
203 #define KEXEC_CMD_kexec_load 4
204 typedef struct xen_kexec_load {
205     uint8_t  type;        /* One of KEXEC_TYPE_* */
206     uint8_t  _pad;
207     uint16_t arch;        /* ELF machine type (EM_*). */
208     uint32_t nr_segments;
209     union {
210         XEN_GUEST_HANDLE(xen_kexec_segment_t) h;
211         uint64_t _pad;
212     } segments;
213     uint64_t entry_maddr; /* image entry point machine address. */
214 } xen_kexec_load_t;
215 DEFINE_XEN_GUEST_HANDLE(xen_kexec_load_t);
216
217 /*
218  * Unload a kexec image.
219  *
220  * Type must be one of KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH.
221  */
222 #define KEXEC_CMD_kexec_unload 5
223 typedef struct xen_kexec_unload {
224     uint8_t type;
225 } xen_kexec_unload_t;
226 DEFINE_XEN_GUEST_HANDLE(xen_kexec_unload_t);
227
228 #else /* __XEN_INTERFACE_VERSION__ < 0x00040400 */
229
230 #define KEXEC_CMD_kexec_load KEXEC_CMD_kexec_load_v1
231 #define KEXEC_CMD_kexec_unload KEXEC_CMD_kexec_unload_v1
232 #define xen_kexec_load xen_kexec_load_v1
233 #define xen_kexec_load_t xen_kexec_load_v1_t
234
235 #endif
236
237 #endif /* _XEN_PUBLIC_KEXEC_H */
238
239 /*
240  * Local variables:
241  * mode: C
242  * c-file-style: "BSD"
243  * c-basic-offset: 4
244  * tab-width: 4
245  * indent-tabs-mode: nil
246  * End:
247  */