Thomas Gleixner | 40b0b3f | 2019-06-03 07:44:46 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 2 | /* |
| 3 | * PPC32 code to handle Linux booting another kernel. |
| 4 | * |
| 5 | * Copyright (C) 2002-2003 Eric Biederman <ebiederm@xmission.com> |
| 6 | * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz |
| 7 | * Copyright (C) 2005 IBM Corporation. |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/kexec.h> |
| 11 | #include <linux/mm.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <asm/cacheflush.h> |
| 14 | #include <asm/hw_irq.h> |
| 15 | #include <asm/io.h> |
| 16 | |
Joe Perches | 9402c95 | 2012-01-12 17:17:17 -0800 | [diff] [blame] | 17 | typedef void (*relocate_new_kernel_t)( |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 18 | unsigned long indirection_page, |
| 19 | unsigned long reboot_code_buffer, |
Joe Perches | ff2d8b1 | 2012-01-12 17:17:21 -0800 | [diff] [blame] | 20 | unsigned long start_address) __noreturn; |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * This is a generic machine_kexec function suitable at least for |
| 24 | * non-OpenFirmware embedded platforms. |
| 25 | * It merely copies the image relocation code to the control page and |
| 26 | * jumps to it. |
| 27 | * A platform specific function may just call this one. |
| 28 | */ |
| 29 | void default_machine_kexec(struct kimage *image) |
| 30 | { |
Tobias Klauser | 2efe55a | 2006-06-26 18:57:34 +0200 | [diff] [blame] | 31 | extern const unsigned int relocate_new_kernel_size; |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 32 | unsigned long page_list; |
| 33 | unsigned long reboot_code_buffer, reboot_code_buffer_phys; |
| 34 | relocate_new_kernel_t rnk; |
| 35 | |
| 36 | /* Interrupts aren't acceptable while we reboot */ |
| 37 | local_irq_disable(); |
| 38 | |
Matthew McClintock | c71635d | 2010-09-16 17:58:23 -0500 | [diff] [blame] | 39 | /* mask each interrupt so we are in a more sane state for the |
| 40 | * kexec kernel */ |
| 41 | machine_kexec_mask_interrupts(); |
| 42 | |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 43 | page_list = image->head; |
| 44 | |
| 45 | /* we need both effective and real address here */ |
| 46 | reboot_code_buffer = |
| 47 | (unsigned long)page_address(image->control_code_page); |
| 48 | reboot_code_buffer_phys = virt_to_phys((void *)reboot_code_buffer); |
| 49 | |
| 50 | /* copy our kernel relocation code to the control code page */ |
| 51 | memcpy((void *)reboot_code_buffer, relocate_new_kernel, |
| 52 | relocate_new_kernel_size); |
| 53 | |
| 54 | flush_icache_range(reboot_code_buffer, |
Huang Ying | 163f687 | 2008-08-15 00:40:22 -0700 | [diff] [blame] | 55 | reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE); |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 56 | printk(KERN_INFO "Bye!\n"); |
| 57 | |
Christophe Leroy | 6c28422 | 2019-06-03 08:20:28 +0000 | [diff] [blame] | 58 | if (!IS_ENABLED(CONFIG_FSL_BOOKE) && !IS_ENABLED(CONFIG_44x)) |
| 59 | relocate_new_kernel(page_list, reboot_code_buffer_phys, image->start); |
| 60 | |
Michael Ellerman | 3d1229d | 2005-11-14 23:35:00 +1100 | [diff] [blame] | 61 | /* now call it */ |
| 62 | rnk = (relocate_new_kernel_t) reboot_code_buffer; |
| 63 | (*rnk)(page_list, reboot_code_buffer_phys, image->start); |
| 64 | } |
| 65 | |
| 66 | int default_machine_kexec_prepare(struct kimage *image) |
| 67 | { |
| 68 | return 0; |
| 69 | } |