Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 15 | #include <linux/device.h> |
| 16 | #include <linux/mm.h> |
| 17 | #include <linux/kexec.h> |
| 18 | #include <linux/delay.h> |
Heiko Carstens | a386fba | 2006-02-11 17:56:01 -0800 | [diff] [blame] | 19 | #include <asm/cio.h> |
| 20 | #include <asm/setup.h> |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 21 | #include <asm/pgtable.h> |
| 22 | #include <asm/pgalloc.h> |
| 23 | #include <asm/system.h> |
Heiko Carstens | a386fba | 2006-02-11 17:56:01 -0800 | [diff] [blame] | 24 | #include <asm/smp.h> |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame^] | 25 | #include <asm/reset.h> |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 26 | |
| 27 | static void kexec_halt_all_cpus(void *); |
| 28 | |
| 29 | typedef void (*relocate_kernel_t) (kimage_entry_t *, unsigned long); |
| 30 | |
Tobias Klauser | 2efe55a | 2006-06-26 18:57:34 +0200 | [diff] [blame] | 31 | extern const unsigned char relocate_kernel[]; |
| 32 | extern const unsigned long long relocate_kernel_len; |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 33 | |
| 34 | int |
| 35 | machine_kexec_prepare(struct kimage *image) |
| 36 | { |
| 37 | unsigned long reboot_code_buffer; |
| 38 | |
| 39 | /* We don't support anything but the default image type for now. */ |
| 40 | if (image->type != KEXEC_TYPE_DEFAULT) |
| 41 | return -EINVAL; |
| 42 | |
| 43 | /* Get the destination where the assembler code should be copied to.*/ |
| 44 | reboot_code_buffer = page_to_pfn(image->control_code_page)<<PAGE_SHIFT; |
| 45 | |
| 46 | /* Then copy it */ |
| 47 | memcpy((void *) reboot_code_buffer, relocate_kernel, |
| 48 | relocate_kernel_len); |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | machine_kexec_cleanup(struct kimage *image) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | machine_shutdown(void) |
| 59 | { |
| 60 | printk(KERN_INFO "kexec: machine_shutdown called\n"); |
| 61 | } |
| 62 | |
| 63 | NORET_TYPE void |
| 64 | machine_kexec(struct kimage *image) |
| 65 | { |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 66 | on_each_cpu(kexec_halt_all_cpus, image, 0, 0); |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 67 | for (;;); |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Heiko Carstens | 5d3f229 | 2005-08-01 21:11:33 -0700 | [diff] [blame] | 70 | extern void pfault_fini(void); |
| 71 | |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 72 | static void |
| 73 | kexec_halt_all_cpus(void *kernel_image) |
| 74 | { |
| 75 | static atomic_t cpuid = ATOMIC_INIT(-1); |
| 76 | int cpu; |
| 77 | struct kimage *image; |
| 78 | relocate_kernel_t data_mover; |
| 79 | |
Heiko Carstens | 5d3f229 | 2005-08-01 21:11:33 -0700 | [diff] [blame] | 80 | #ifdef CONFIG_PFAULT |
| 81 | if (MACHINE_IS_VM) |
| 82 | pfault_fini(); |
| 83 | #endif |
| 84 | |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 85 | if (atomic_cmpxchg(&cpuid, -1, smp_processor_id()) != -1) |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 86 | signal_processor(smp_processor_id(), sigp_stop); |
| 87 | |
| 88 | /* Wait for all other cpus to enter stopped state */ |
| 89 | for_each_online_cpu(cpu) { |
| 90 | if (cpu == smp_processor_id()) |
| 91 | continue; |
Maneesh Soni | 72414d3 | 2005-06-25 14:58:28 -0700 | [diff] [blame] | 92 | while (!smp_cpu_not_running(cpu)) |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 93 | cpu_relax(); |
| 94 | } |
| 95 | |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame^] | 96 | s390_reset_system(); |
| 97 | |
Heiko Carstens | cf13f0e | 2005-06-25 14:58:11 -0700 | [diff] [blame] | 98 | image = (struct kimage *) kernel_image; |
| 99 | data_mover = (relocate_kernel_t) |
| 100 | (page_to_pfn(image->control_code_page) << PAGE_SHIFT); |
| 101 | |
| 102 | /* Call the moving routine */ |
| 103 | (*data_mover) (&image->head, image->start); |
| 104 | } |