~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/sh/kernel/machine_kexec.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * machine_kexec.c - handle transition of Linux booting another kernel
  4  * Copyright (C) 2002-2003 Eric Biederman  <ebiederm@xmission.com>
  5  *
  6  * GameCube/ppc32 port Copyright (C) 2004 Albert Herranz
  7  * LANDISK/sh4 supported by kogiidena
  8  */
  9 #include <linux/mm.h>
 10 #include <linux/kexec.h>
 11 #include <linux/delay.h>
 12 #include <linux/reboot.h>
 13 #include <linux/numa.h>
 14 #include <linux/ftrace.h>
 15 #include <linux/suspend.h>
 16 #include <linux/memblock.h>
 17 #include <asm/mmu_context.h>
 18 #include <asm/io.h>
 19 #include <asm/cacheflush.h>
 20 #include <asm/sh_bios.h>
 21 #include <asm/reboot.h>
 22 
 23 typedef void (*relocate_new_kernel_t)(unsigned long indirection_page,
 24                                       unsigned long reboot_code_buffer,
 25                                       unsigned long start_address);
 26 
 27 extern const unsigned char relocate_new_kernel[];
 28 extern const unsigned int relocate_new_kernel_size;
 29 extern void *vbr_base;
 30 
 31 void native_machine_crash_shutdown(struct pt_regs *regs)
 32 {
 33         /* Nothing to do for UP, but definitely broken for SMP.. */
 34 }
 35 
 36 /*
 37  * Do what every setup is needed on image and the
 38  * reboot code buffer to allow us to avoid allocations
 39  * later.
 40  */
 41 int machine_kexec_prepare(struct kimage *image)
 42 {
 43         return 0;
 44 }
 45 
 46 void machine_kexec_cleanup(struct kimage *image)
 47 {
 48 }
 49 
 50 static void kexec_info(struct kimage *image)
 51 {
 52         int i;
 53         printk("kexec information\n");
 54         for (i = 0; i < image->nr_segments; i++) {
 55                 printk("  segment[%d]: 0x%08x - 0x%08x (0x%08x)\n",
 56                        i,
 57                        (unsigned int)image->segment[i].mem,
 58                        (unsigned int)image->segment[i].mem +
 59                                      image->segment[i].memsz,
 60                        (unsigned int)image->segment[i].memsz);
 61         }
 62         printk("  start     : 0x%08x\n\n", (unsigned int)image->start);
 63 }
 64 
 65 /*
 66  * Do not allocate memory (or fail in any way) in machine_kexec().
 67  * We are past the point of no return, committed to rebooting now.
 68  */
 69 void machine_kexec(struct kimage *image)
 70 {
 71         unsigned long page_list;
 72         unsigned long reboot_code_buffer;
 73         relocate_new_kernel_t rnk;
 74         unsigned long entry;
 75         unsigned long *ptr;
 76         int save_ftrace_enabled;
 77 
 78         /*
 79          * Nicked from the mips version of machine_kexec():
 80          * The generic kexec code builds a page list with physical
 81          * addresses. Use phys_to_virt() to convert them to virtual.
 82          */
 83         for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
 84              ptr = (entry & IND_INDIRECTION) ?
 85                phys_to_virt(entry & PAGE_MASK) : ptr + 1) {
 86                 if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
 87                     *ptr & IND_DESTINATION)
 88                         *ptr = (unsigned long) phys_to_virt(*ptr);
 89         }
 90 
 91 #ifdef CONFIG_KEXEC_JUMP
 92         if (image->preserve_context)
 93                 save_processor_state();
 94 #endif
 95 
 96         save_ftrace_enabled = __ftrace_enabled_save();
 97 
 98         /* Interrupts aren't acceptable while we reboot */
 99         local_irq_disable();
100 
101         page_list = image->head;
102 
103         /* we need both effective and real address here */
104         reboot_code_buffer =
105                         (unsigned long)page_address(image->control_code_page);
106 
107         /* copy our kernel relocation code to the control code page */
108         memcpy((void *)reboot_code_buffer, relocate_new_kernel,
109                                                 relocate_new_kernel_size);
110 
111         kexec_info(image);
112         flush_cache_all();
113 
114         sh_bios_vbr_reload();
115 
116         /* now call it */
117         rnk = (relocate_new_kernel_t) reboot_code_buffer;
118         (*rnk)(page_list, reboot_code_buffer,
119                (unsigned long)phys_to_virt(image->start));
120 
121 #ifdef CONFIG_KEXEC_JUMP
122         asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory");
123 
124         if (image->preserve_context)
125                 restore_processor_state();
126 
127         /* Convert page list back to physical addresses, what a mess. */
128         for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
129              ptr = (*ptr & IND_INDIRECTION) ?
130                phys_to_virt(*ptr & PAGE_MASK) : ptr + 1) {
131                 if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
132                     *ptr & IND_DESTINATION)
133                         *ptr = virt_to_phys(*ptr);
134         }
135 #endif
136 
137         __ftrace_enabled_restore(save_ftrace_enabled);
138 }
139 
140 void __init reserve_crashkernel(void)
141 {
142         unsigned long long crash_size, crash_base;
143         int ret;
144 
145         if (!IS_ENABLED(CONFIG_CRASH_RESERVE))
146                 return;
147 
148         ret = parse_crashkernel(boot_command_line, memblock_phys_mem_size(),
149                         &crash_size, &crash_base, NULL, NULL);
150         if (ret == 0 && crash_size > 0) {
151                 crashk_res.start = crash_base;
152                 crashk_res.end = crash_base + crash_size - 1;
153         }
154 
155         if (crashk_res.end == crashk_res.start)
156                 goto disable;
157 
158         crash_size = PAGE_ALIGN(resource_size(&crashk_res));
159         if (!crashk_res.start) {
160                 unsigned long max = memblock_end_of_DRAM() - memory_limit;
161                 crashk_res.start = memblock_phys_alloc_range(crash_size,
162                                                              PAGE_SIZE, 0, max);
163                 if (!crashk_res.start) {
164                         pr_err("crashkernel allocation failed\n");
165                         goto disable;
166                 }
167         } else {
168                 ret = memblock_reserve(crashk_res.start, crash_size);
169                 if (unlikely(ret < 0)) {
170                         pr_err("crashkernel reservation failed - "
171                                "memory is in use\n");
172                         goto disable;
173                 }
174         }
175 
176         crashk_res.end = crashk_res.start + crash_size - 1;
177 
178         /*
179          * Crash kernel trumps memory limit
180          */
181         if ((memblock_end_of_DRAM() - memory_limit) <= crashk_res.end) {
182                 memory_limit = 0;
183                 pr_info("Disabled memory limit for crashkernel\n");
184         }
185 
186         pr_info("Reserving %ldMB of memory at 0x%08lx "
187                 "for crashkernel (System RAM: %ldMB)\n",
188                 (unsigned long)(crash_size >> 20),
189                 (unsigned long)(crashk_res.start),
190                 (unsigned long)(memblock_phys_mem_size() >> 20));
191 
192         return;
193 
194 disable:
195         crashk_res.start = crashk_res.end = 0;
196 }
197 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php