blob: f0ed5c642c74cb6480426b106d1cc3e0aa05eed1 [file] [log] [blame]
Heiko Carstenscf13f0e2005-06-25 14:58:11 -07001/*
2 * arch/s390/kernel/machine_kexec.c
3 *
4 * (C) Copyright IBM Corp. 2005
5 *
6 * Author(s): Rolf Adelsberger <adelsberger@de.ibm.com>
7 *
8 */
9
10/*
11 * s390_machine_kexec.c - handle the transition of Linux booting another kernel
12 * on the S390 architecture.
13 */
14
15#include <asm/cio.h>
16#include <asm/setup.h>
17#include <linux/device.h>
18#include <linux/mm.h>
19#include <linux/kexec.h>
20#include <linux/delay.h>
21#include <asm/pgtable.h>
22#include <asm/pgalloc.h>
23#include <asm/system.h>
24
25static void kexec_halt_all_cpus(void *);
26
27typedef void (*relocate_kernel_t) (kimage_entry_t *, unsigned long);
28
29const extern unsigned char relocate_kernel[];
30const extern unsigned long long relocate_kernel_len;
31
32int
33machine_kexec_prepare(struct kimage *image)
34{
35 unsigned long reboot_code_buffer;
36
37 /* We don't support anything but the default image type for now. */
38 if (image->type != KEXEC_TYPE_DEFAULT)
39 return -EINVAL;
40
41 /* Get the destination where the assembler code should be copied to.*/
42 reboot_code_buffer = page_to_pfn(image->control_code_page)<<PAGE_SHIFT;
43
44 /* Then copy it */
45 memcpy((void *) reboot_code_buffer, relocate_kernel,
46 relocate_kernel_len);
47 return 0;
48}
49
50void
51machine_kexec_cleanup(struct kimage *image)
52{
53}
54
55void
56machine_shutdown(void)
57{
58 printk(KERN_INFO "kexec: machine_shutdown called\n");
59}
60
61NORET_TYPE void
62machine_kexec(struct kimage *image)
63{
64 clear_all_subchannels();
65
66 /* Disable lowcore protection */
67 ctl_clear_bit(0,28);
68
69 on_each_cpu(kexec_halt_all_cpus, image, 0, 0);
Maneesh Soni72414d32005-06-25 14:58:28 -070070 for (;;);
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070071}
72
Heiko Carstens5d3f2292005-08-01 21:11:33 -070073extern void pfault_fini(void);
74
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070075static void
76kexec_halt_all_cpus(void *kernel_image)
77{
78 static atomic_t cpuid = ATOMIC_INIT(-1);
79 int cpu;
80 struct kimage *image;
81 relocate_kernel_t data_mover;
82
Heiko Carstens5d3f2292005-08-01 21:11:33 -070083#ifdef CONFIG_PFAULT
84 if (MACHINE_IS_VM)
85 pfault_fini();
86#endif
87
Martin Schwidefsky973bd992006-01-06 00:19:07 -080088 if (atomic_cmpxchg(&cpuid, -1, smp_processor_id()) != -1)
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070089 signal_processor(smp_processor_id(), sigp_stop);
90
91 /* Wait for all other cpus to enter stopped state */
92 for_each_online_cpu(cpu) {
93 if (cpu == smp_processor_id())
94 continue;
Maneesh Soni72414d32005-06-25 14:58:28 -070095 while (!smp_cpu_not_running(cpu))
Heiko Carstenscf13f0e2005-06-25 14:58:11 -070096 cpu_relax();
97 }
98
99 image = (struct kimage *) kernel_image;
100 data_mover = (relocate_kernel_t)
101 (page_to_pfn(image->control_code_page) << PAGE_SHIFT);
102
103 /* Call the moving routine */
104 (*data_mover) (&image->head, image->start);
105}