2 * drivers/xen/core/machine_kexec.c
3 * handle transition of Linux booting another kernel
6 #include <linux/kexec.h>
7 #include <xen/interface/kexec.h>
9 #include <linux/bootmem.h>
11 extern void machine_kexec_setup_load_arg(xen_kexec_image_t *xki,
12 struct kimage *image);
14 static int __initdata xen_max_nr_phys_cpus;
15 static struct resource xen_hypervisor_res;
16 static struct resource *xen_phys_cpus;
18 void __init xen_machine_kexec_setup_resources(void)
20 xen_kexec_range_t range;
24 if (strstr(boot_command_line, "crashkernel="))
25 printk(KERN_WARNING "Ignoring crashkernel command line, "
26 "parameter will be supplied by xen\n");
28 if (!is_initial_xendomain())
31 /* determine maximum number of physical cpus */
34 memset(&range, 0, sizeof(range));
35 range.range = KEXEC_RANGE_MA_CPU;
38 if(HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, &range))
47 xen_max_nr_phys_cpus = k;
49 /* allocate xen_phys_cpus */
51 xen_phys_cpus = alloc_bootmem_low(k * sizeof(struct resource));
52 BUG_ON(xen_phys_cpus == NULL);
54 /* fill in xen_phys_cpus with per-cpu crash note information */
56 for (k = 0; k < xen_max_nr_phys_cpus; k++) {
57 memset(&range, 0, sizeof(range));
58 range.range = KEXEC_RANGE_MA_CPU;
61 if (HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, &range))
64 res = xen_phys_cpus + k;
66 memset(res, 0, sizeof(*res));
67 res->name = "Crash note";
68 res->start = range.start;
69 res->end = range.start + range.size - 1;
70 res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
73 /* fill in xen_hypervisor_res with hypervisor machine address range */
75 memset(&range, 0, sizeof(range));
76 range.range = KEXEC_RANGE_MA_XEN;
78 if (HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, &range))
81 xen_hypervisor_res.name = "Hypervisor code and data";
82 xen_hypervisor_res.start = range.start;
83 xen_hypervisor_res.end = range.start + range.size - 1;
84 xen_hypervisor_res.flags = IORESOURCE_BUSY | IORESOURCE_MEM;
86 /* fill in crashk_res if range is reserved by hypervisor */
88 memset(&range, 0, sizeof(range));
89 range.range = KEXEC_RANGE_MA_CRASH;
91 if (HYPERVISOR_kexec_op(KEXEC_CMD_kexec_get_range, &range))
95 crashk_res.start = range.start;
96 crashk_res.end = range.start + range.size - 1;
103 * It isn't possible to free xen_phys_cpus this early in the
104 * boot. Failure at this stage is unexpected and the amount of
105 * memory is small therefore we tolerate the potential leak.
107 xen_max_nr_phys_cpus = 0;
111 void __init xen_machine_kexec_register_resources(struct resource *res)
115 request_resource(res, &xen_hypervisor_res);
117 for (k = 0; k < xen_max_nr_phys_cpus; k++)
118 request_resource(&xen_hypervisor_res, xen_phys_cpus + k);
122 static void setup_load_arg(xen_kexec_image_t *xki, struct kimage *image)
124 machine_kexec_setup_load_arg(xki, image);
126 xki->indirection_page = image->head;
127 xki->start_address = image->start;
131 * Load the image into xen so xen can kdump itself
132 * This might have been done in prepare, but prepare
133 * is currently called too early. It might make sense
134 * to move prepare, but for now, just add an extra hook.
136 int xen_machine_kexec_load(struct kimage *image)
138 xen_kexec_load_t xkl;
140 memset(&xkl, 0, sizeof(xkl));
141 xkl.type = image->type;
142 setup_load_arg(&xkl.image, image);
143 return HYPERVISOR_kexec_op(KEXEC_CMD_kexec_load, &xkl);
147 * Unload the image that was stored by machine_kexec_load()
148 * This might have been done in machine_kexec_cleanup() but it
149 * is called too late, and its possible xen could try and kdump
150 * using resources that have been freed.
152 void xen_machine_kexec_unload(struct kimage *image)
154 xen_kexec_load_t xkl;
156 memset(&xkl, 0, sizeof(xkl));
157 xkl.type = image->type;
158 WARN_ON(HYPERVISOR_kexec_op(KEXEC_CMD_kexec_unload, &xkl));
162 * Do not allocate memory (or fail in any way) in machine_kexec().
163 * We are past the point of no return, committed to rebooting now.
165 * This has the hypervisor move to the prefered reboot CPU,
166 * stop all CPUs and kexec. That is it combines machine_shutdown()
167 * and machine_kexec() in Linux kexec terms.
169 NORET_TYPE void machine_kexec(struct kimage *image)
171 xen_kexec_exec_t xke;
173 memset(&xke, 0, sizeof(xke));
174 xke.type = image->type;
175 VOID(HYPERVISOR_kexec_op(KEXEC_CMD_kexec, &xke));
176 panic("KEXEC_CMD_kexec hypercall should not return\n");
179 void machine_shutdown(void)
187 * c-file-style: "linux"
188 * indent-tabs-mode: t