| kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * machine_kexec.c - handle transition of Linux booting another kernel | 
|  | 3 | * Copyright (C) 2002-2003 Eric Biederman  <ebiederm@xmission.com> | 
|  | 4 | * | 
|  | 5 | * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz | 
|  | 6 | * LANDISK/sh4 supported by kogiidena | 
|  | 7 | * | 
|  | 8 | * This source code is licensed under the GNU General Public License, | 
|  | 9 | * Version 2.  See the file COPYING for more details. | 
|  | 10 | */ | 
|  | 11 |  | 
|  | 12 | #include <linux/mm.h> | 
|  | 13 | #include <linux/kexec.h> | 
|  | 14 | #include <linux/delay.h> | 
|  | 15 | #include <linux/reboot.h> | 
|  | 16 | #include <asm/pgtable.h> | 
|  | 17 | #include <asm/pgalloc.h> | 
|  | 18 | #include <asm/mmu_context.h> | 
|  | 19 | #include <asm/io.h> | 
|  | 20 | #include <asm/cacheflush.h> | 
|  | 21 |  | 
|  | 22 | typedef NORET_TYPE void (*relocate_new_kernel_t)( | 
|  | 23 | unsigned long indirection_page, | 
|  | 24 | unsigned long reboot_code_buffer, | 
|  | 25 | unsigned long start_address, | 
|  | 26 | unsigned long vbr_reg) ATTRIB_NORET; | 
|  | 27 |  | 
| Tobias Klauser | 2efe55a | 2006-06-26 18:57:34 +0200 | [diff] [blame] | 28 | extern const unsigned char relocate_new_kernel[]; | 
|  | 29 | extern const unsigned int relocate_new_kernel_size; | 
| kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 30 | extern void *gdb_vbr_vector; | 
|  | 31 |  | 
| kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 32 | void machine_shutdown(void) | 
|  | 33 | { | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | void machine_crash_shutdown(struct pt_regs *regs) | 
|  | 37 | { | 
|  | 38 | } | 
|  | 39 |  | 
|  | 40 | /* | 
|  | 41 | * Do what every setup is needed on image and the | 
|  | 42 | * reboot code buffer to allow us to avoid allocations | 
|  | 43 | * later. | 
|  | 44 | */ | 
|  | 45 | int machine_kexec_prepare(struct kimage *image) | 
|  | 46 | { | 
|  | 47 | return 0; | 
|  | 48 | } | 
|  | 49 |  | 
|  | 50 | void machine_kexec_cleanup(struct kimage *image) | 
|  | 51 | { | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | static void kexec_info(struct kimage *image) | 
|  | 55 | { | 
|  | 56 | int i; | 
|  | 57 | printk("kexec information\n"); | 
|  | 58 | for (i = 0; i < image->nr_segments; i++) { | 
|  | 59 | printk("  segment[%d]: 0x%08x - 0x%08x (0x%08x)\n", | 
|  | 60 | i, | 
|  | 61 | (unsigned int)image->segment[i].mem, | 
| Paul Mundt | 4d5ade5 | 2007-04-27 11:25:57 +0900 | [diff] [blame] | 62 | (unsigned int)image->segment[i].mem + | 
|  | 63 | image->segment[i].memsz, | 
| kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 64 | (unsigned int)image->segment[i].memsz); | 
| Paul Mundt | 4d5ade5 | 2007-04-27 11:25:57 +0900 | [diff] [blame] | 65 | } | 
| kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 66 | printk("  start     : 0x%08x\n\n", (unsigned int)image->start); | 
|  | 67 | } | 
|  | 68 |  | 
| kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 69 | /* | 
|  | 70 | * Do not allocate memory (or fail in any way) in machine_kexec(). | 
|  | 71 | * We are past the point of no return, committed to rebooting now. | 
|  | 72 | */ | 
|  | 73 | NORET_TYPE void machine_kexec(struct kimage *image) | 
|  | 74 | { | 
|  | 75 |  | 
|  | 76 | unsigned long page_list; | 
|  | 77 | unsigned long reboot_code_buffer; | 
|  | 78 | unsigned long vbr_reg; | 
|  | 79 | relocate_new_kernel_t rnk; | 
|  | 80 |  | 
|  | 81 | #if defined(CONFIG_SH_STANDARD_BIOS) | 
|  | 82 | vbr_reg = ((unsigned long )gdb_vbr_vector) - 0x100; | 
|  | 83 | #else | 
|  | 84 | vbr_reg = 0x80000000;  // dummy | 
|  | 85 | #endif | 
|  | 86 | /* Interrupts aren't acceptable while we reboot */ | 
|  | 87 | local_irq_disable(); | 
|  | 88 |  | 
|  | 89 | page_list = image->head; | 
|  | 90 |  | 
|  | 91 | /* we need both effective and real address here */ | 
|  | 92 | reboot_code_buffer = | 
|  | 93 | (unsigned long)page_address(image->control_code_page); | 
|  | 94 |  | 
|  | 95 | /* copy our kernel relocation code to the control code page */ | 
|  | 96 | memcpy((void *)reboot_code_buffer, relocate_new_kernel, | 
|  | 97 | relocate_new_kernel_size); | 
|  | 98 |  | 
|  | 99 | kexec_info(image); | 
|  | 100 | flush_cache_all(); | 
|  | 101 |  | 
|  | 102 | /* now call it */ | 
|  | 103 | rnk = (relocate_new_kernel_t) reboot_code_buffer; | 
| Paul Mundt | 4d5ade5 | 2007-04-27 11:25:57 +0900 | [diff] [blame] | 104 | (*rnk)(page_list, reboot_code_buffer, image->start, vbr_reg); | 
| kogiidena | 9d44190 | 2006-01-16 22:14:10 -0800 | [diff] [blame] | 105 | } | 
|  | 106 |  |