blob: e2ccc9f660c5730e1bbe77adc4f0cccafadbfdb7 [file] [log] [blame]
Zou Nan haia79561132006-12-07 09:51:35 -08001/*
2 * arch/ia64/kernel/machine_kexec.c
3 *
4 * Handle transition of Linux booting another kernel
5 * Copyright (C) 2005 Hewlett-Packard Development Comapny, L.P.
6 * Copyright (C) 2005 Khalid Aziz <khalid.aziz@hp.com>
7 * Copyright (C) 2006 Intel Corp, Zou Nan hai <nanhai.zou@intel.com>
8 *
9 * This source code is licensed under the GNU General Public License,
10 * Version 2. See the file COPYING for more details.
11 */
12
13#include <linux/mm.h>
14#include <linux/kexec.h>
15#include <linux/cpu.h>
16#include <linux/irq.h>
17#include <asm/mmu_context.h>
18#include <asm/setup.h>
19#include <asm/delay.h>
20#include <asm/meminit.h>
21
Horms53da5762006-12-12 18:06:13 +090022typedef NORET_TYPE void (*relocate_new_kernel_t)(
23 unsigned long indirection_page,
24 unsigned long start_address,
25 struct ia64_boot_param *boot_param,
26 unsigned long pal_addr) ATTRIB_NORET;
Zou Nan haia79561132006-12-07 09:51:35 -080027
28struct kimage *ia64_kimage;
29
30struct resource efi_memmap_res = {
31 .name = "EFI Memory Map",
32 .start = 0,
33 .end = 0,
34 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
35};
36
37struct resource boot_param_res = {
38 .name = "Boot parameter",
39 .start = 0,
40 .end = 0,
41 .flags = IORESOURCE_BUSY | IORESOURCE_MEM
42};
43
44
45/*
46 * Do what every setup is needed on image and the
47 * reboot code buffer to allow us to avoid allocations
48 * later.
49 */
50int machine_kexec_prepare(struct kimage *image)
51{
52 void *control_code_buffer;
53 const unsigned long *func;
54
55 func = (unsigned long *)&relocate_new_kernel;
56 /* Pre-load control code buffer to minimize work in kexec path */
57 control_code_buffer = page_address(image->control_code_page);
58 memcpy((void *)control_code_buffer, (const void *)func[0],
59 relocate_new_kernel_size);
60 flush_icache_range((unsigned long)control_code_buffer,
61 (unsigned long)control_code_buffer + relocate_new_kernel_size);
62 ia64_kimage = image;
63
64 return 0;
65}
66
67void machine_kexec_cleanup(struct kimage *image)
68{
69}
70
71void machine_shutdown(void)
72{
73 int cpu;
74
75 for_each_online_cpu(cpu) {
76 if (cpu != smp_processor_id())
77 cpu_down(cpu);
78 }
79 kexec_disable_iosapic();
80}
81
82/*
83 * Do not allocate memory (or fail in any way) in machine_kexec().
84 * We are past the point of no return, committed to rebooting now.
85 */
86extern void *efi_get_pal_addr(void);
87static void ia64_machine_kexec(struct unw_frame_info *info, void *arg)
88{
89 struct kimage *image = arg;
90 relocate_new_kernel_t rnk;
91 void *pal_addr = efi_get_pal_addr();
92 unsigned long code_addr = (unsigned long)page_address(image->control_code_page);
93 unsigned long vector;
94 int ii;
95
96 if (image->type == KEXEC_TYPE_CRASH) {
97 crash_save_this_cpu();
98 current->thread.ksp = (__u64)info->sw - 16;
99 }
100
101 /* Interrupts aren't acceptable while we reboot */
102 local_irq_disable();
103
104 /* Mask CMC and Performance Monitor interrupts */
105 ia64_setreg(_IA64_REG_CR_PMV, 1 << 16);
106 ia64_setreg(_IA64_REG_CR_CMCV, 1 << 16);
107
108 /* Mask ITV and Local Redirect Registers */
109 ia64_set_itv(1 << 16);
110 ia64_set_lrr0(1 << 16);
111 ia64_set_lrr1(1 << 16);
112
113 /* terminate possible nested in-service interrupts */
114 for (ii = 0; ii < 16; ii++)
115 ia64_eoi();
116
117 /* unmask TPR and clear any pending interrupts */
118 ia64_setreg(_IA64_REG_CR_TPR, 0);
119 ia64_srlz_d();
120 vector = ia64_get_ivr();
121 while (vector != IA64_SPURIOUS_INT_VECTOR) {
122 ia64_eoi();
123 vector = ia64_get_ivr();
124 }
125 platform_kernel_launch_event();
126 rnk = (relocate_new_kernel_t)&code_addr;
127 (*rnk)(image->head, image->start, ia64_boot_param,
128 GRANULEROUNDDOWN((unsigned long) pal_addr));
129 BUG();
130}
131
132void machine_kexec(struct kimage *image)
133{
134 unw_init_running(ia64_machine_kexec, image);
135 for(;;);
136}