blob: b09b9c62573e7bb77c145670dbd3e0e777ea8cdd [file] [log] [blame]
Heiko Carstenscf13f0e2005-06-25 14:58:11 -07001/*
2 * arch/s390/kernel/machine_kexec.c
3 *
Heiko Carstensc6b5b842006-12-04 15:40:33 +01004 * Copyright IBM Corp. 2005,2006
Heiko Carstenscf13f0e2005-06-25 14:58:11 -07005 *
Heiko Carstensc6b5b842006-12-04 15:40:33 +01006 * Author(s): Rolf Adelsberger,
7 * Heiko Carstens <heiko.carstens@de.ibm.com>
Heiko Carstenscf13f0e2005-06-25 14:58:11 -07008 */
9
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070010#include <linux/device.h>
11#include <linux/mm.h>
12#include <linux/kexec.h>
13#include <linux/delay.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010014#include <linux/reboot.h>
Heiko Carstens69667272011-03-15 17:08:33 +010015#include <linux/ftrace.h>
Heiko Carstensa386fba2006-02-11 17:56:01 -080016#include <asm/cio.h>
17#include <asm/setup.h>
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070018#include <asm/pgtable.h>
19#include <asm/pgalloc.h>
20#include <asm/system.h>
Heiko Carstensa386fba2006-02-11 17:56:01 -080021#include <asm/smp.h>
Heiko Carstens15e9b582006-12-04 15:40:26 +010022#include <asm/reset.h>
Heiko Carstens9c9c1762007-03-05 23:35:45 +010023#include <asm/ipl.h>
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070024
Heiko Carstensc6b5b842006-12-04 15:40:33 +010025typedef void (*relocate_kernel_t)(kimage_entry_t *, unsigned long);
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070026
Tobias Klauser2efe55a2006-06-26 18:57:34 +020027extern const unsigned char relocate_kernel[];
28extern const unsigned long long relocate_kernel_len;
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070029
Heiko Carstensc6b5b842006-12-04 15:40:33 +010030int machine_kexec_prepare(struct kimage *image)
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070031{
Heiko Carstensc6b5b842006-12-04 15:40:33 +010032 void *reboot_code_buffer;
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070033
Heiko Carstens9c9c1762007-03-05 23:35:45 +010034 /* Can't replace kernel image since it is read-only. */
35 if (ipl_flags & IPL_NSS_VALID)
36 return -ENOSYS;
37
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070038 /* We don't support anything but the default image type for now. */
39 if (image->type != KEXEC_TYPE_DEFAULT)
40 return -EINVAL;
41
42 /* Get the destination where the assembler code should be copied to.*/
Heiko Carstensc6b5b842006-12-04 15:40:33 +010043 reboot_code_buffer = (void *) page_to_phys(image->control_code_page);
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070044
45 /* Then copy it */
Heiko Carstensc6b5b842006-12-04 15:40:33 +010046 memcpy(reboot_code_buffer, relocate_kernel, relocate_kernel_len);
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070047 return 0;
48}
49
Heiko Carstensc6b5b842006-12-04 15:40:33 +010050void machine_kexec_cleanup(struct kimage *image)
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070051{
52}
53
Heiko Carstensc6b5b842006-12-04 15:40:33 +010054void machine_shutdown(void)
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070055{
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070056}
57
Heiko Carstens2c2df112010-02-26 22:37:34 +010058static void __machine_kexec(void *data)
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070059{
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070060 relocate_kernel_t data_mover;
Heiko Carstens2c2df112010-02-26 22:37:34 +010061 struct kimage *image = data;
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070062
Heiko Carstens29b08d22006-12-04 15:40:40 +010063 pfault_fini();
Heiko Carstens15e9b582006-12-04 15:40:26 +010064 s390_reset_system();
65
Heiko Carstensc6b5b842006-12-04 15:40:33 +010066 data_mover = (relocate_kernel_t) page_to_phys(image->control_code_page);
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070067
68 /* Call the moving routine */
Heiko Carstensc6b5b842006-12-04 15:40:33 +010069 (*data_mover)(&image->head, image->start);
70 for (;;);
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070071}
Heiko Carstens2c2df112010-02-26 22:37:34 +010072
73void machine_kexec(struct kimage *image)
74{
Heiko Carstens69667272011-03-15 17:08:33 +010075 tracer_disable();
Heiko Carstens2c2df112010-02-26 22:37:34 +010076 smp_send_stop();
77 smp_switch_to_ipl_cpu(__machine_kexec, image);
78}