Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * machine_kexec.c for kexec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Created by <nschichan@corp.free.fr> on Thu Oct 12 15:15:06 2006
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/kexec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/libfdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) extern const unsigned char relocate_new_kernel[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) extern const size_t relocate_new_kernel_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) extern unsigned long kexec_start_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) extern unsigned long kexec_indirection_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static unsigned long reboot_code_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static void (*relocated_kexec_smp_wait)(void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) atomic_t kexec_ready_to_reboot = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) void (*_crash_smp_send_stop)(void) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) void (*_machine_kexec_shutdown)(void) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) void (*_machine_crash_shutdown)(struct pt_regs *regs) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static void kexec_image_info(const struct kimage *kimage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	pr_debug("kexec kimage info:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	pr_debug("  type:        %d\n", kimage->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	pr_debug("  start:       %lx\n", kimage->start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	pr_debug("  head:        %lx\n", kimage->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	pr_debug("  nr_segments: %lu\n", kimage->nr_segments);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	for (i = 0; i < kimage->nr_segments; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		pr_debug("    segment[%lu]: %016lx - %016lx, 0x%lx bytes, %lu pages\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			kimage->segment[i].mem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			kimage->segment[i].mem + kimage->segment[i].memsz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			(unsigned long)kimage->segment[i].memsz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			(unsigned long)kimage->segment[i].memsz /  PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #ifdef CONFIG_UHI_BOOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static int uhi_machine_kexec_prepare(struct kimage *kimage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	 * In case DTB file is not passed to the new kernel, a flat device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	 * tree will be created by kexec tool. It holds modified command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 * line for the new kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	for (i = 0; i < kimage->nr_segments; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		struct fdt_header fdt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		if (kimage->segment[i].memsz <= sizeof(fdt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		if (copy_from_user(&fdt, kimage->segment[i].buf, sizeof(fdt)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		if (fdt_check_header(&fdt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		kexec_args[0] = -2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		kexec_args[1] = (unsigned long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			phys_to_virt((unsigned long)kimage->segment[i].mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) int (*_machine_kexec_prepare)(struct kimage *) = uhi_machine_kexec_prepare;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) int (*_machine_kexec_prepare)(struct kimage *) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #endif /* CONFIG_UHI_BOOT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) machine_kexec_prepare(struct kimage *kimage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (!kexec_nonboot_cpu_func())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	kexec_image_info(kimage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (_machine_kexec_prepare)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		return _machine_kexec_prepare(kimage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) machine_kexec_cleanup(struct kimage *kimage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static void kexec_shutdown_secondary(void *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (!cpu_online(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	/* We won't be sent IPIs any more. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	set_cpu_online(cpu, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	while (!atomic_read(&kexec_ready_to_reboot))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	kexec_reboot();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	/* NOTREACHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) machine_shutdown(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (_machine_kexec_shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		_machine_kexec_shutdown();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	smp_call_function(kexec_shutdown_secondary, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	while (num_online_cpus() > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		mdelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) machine_crash_shutdown(struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (_machine_crash_shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		_machine_crash_shutdown(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		default_machine_crash_shutdown(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) void kexec_nonboot_cpu_jump(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	local_flush_icache_range((unsigned long)relocated_kexec_smp_wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 				 reboot_code_buffer + relocate_new_kernel_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	relocated_kexec_smp_wait(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) void kexec_reboot(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	void (*do_kexec)(void) __noreturn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 * We know we were online, and there will be no incoming IPIs at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	 * this point. Mark online again before rebooting so that the crash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	 * analysis tool will see us correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	set_cpu_online(smp_processor_id(), true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	/* Ensure remote CPUs observe that we're online before rebooting. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (smp_processor_id() > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		 * Instead of cpu_relax() or wait, this is needed for kexec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		 * smp reboot. Kdump usually doesn't require an smp new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		 * kernel, but kexec may do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		kexec_nonboot_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		/* NOTREACHED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	 * Make sure we get correct instructions written by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	 * machine_kexec() CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	local_flush_icache_range(reboot_code_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 				 reboot_code_buffer + relocate_new_kernel_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	do_kexec = (void *)reboot_code_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	do_kexec();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) machine_kexec(struct kimage *image)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	unsigned long entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	unsigned long *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	reboot_code_buffer =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	  (unsigned long)page_address(image->control_code_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	kexec_start_address =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		(unsigned long) phys_to_virt(image->start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (image->type == KEXEC_TYPE_DEFAULT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		kexec_indirection_page =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			(unsigned long) phys_to_virt(image->head & PAGE_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		kexec_indirection_page = (unsigned long)&image->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	memcpy((void*)reboot_code_buffer, relocate_new_kernel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	       relocate_new_kernel_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	 * The generic kexec code builds a page list with physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	 * addresses. they are directly accessible through KSEG0 (or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	 * CKSEG0 or XPHYS if on 64bit system), hence the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	 * phys_to_virt() call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	for (ptr = &image->head; (entry = *ptr) && !(entry &IND_DONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	     ptr = (entry & IND_INDIRECTION) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	       phys_to_virt(entry & PAGE_MASK) : ptr + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		    *ptr & IND_DESTINATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			*ptr = (unsigned long) phys_to_virt(*ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/* Mark offline BEFORE disabling local irq. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	set_cpu_online(smp_processor_id(), false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 * we do not want to be bothered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	printk("Will call new kernel at %08lx\n", image->start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	printk("Bye ...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	/* Make reboot code buffer available to the boot CPU. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	__flush_cache_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	/* All secondary cpus now may jump to kexec_wait cycle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	relocated_kexec_smp_wait = reboot_code_buffer +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		(void *)(kexec_smp_wait - relocate_new_kernel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	atomic_set(&kexec_ready_to_reboot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	kexec_reboot();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }