machine_kexec.c 4.5 KB
Newer Older
Z
Zou Nan hai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * arch/ia64/kernel/machine_kexec.c
 *
 * Handle transition of Linux booting another kernel
 * Copyright (C) 2005 Hewlett-Packard Development Comapny, L.P.
 * Copyright (C) 2005 Khalid Aziz <khalid.aziz@hp.com>
 * Copyright (C) 2006 Intel Corp, Zou Nan hai <nanhai.zou@intel.com>
 *
 * This source code is licensed under the GNU General Public License,
 * Version 2.  See the file COPYING for more details.
 */

#include <linux/mm.h>
#include <linux/kexec.h>
#include <linux/cpu.h>
#include <linux/irq.h>
17
#include <linux/efi.h>
K
Ken'ichi Ohmichi 已提交
18 19
#include <linux/numa.h>
#include <linux/mmzone.h>
A
Andrew Morton 已提交
20 21

#include <asm/numa.h>
Z
Zou Nan hai 已提交
22 23 24 25
#include <asm/mmu_context.h>
#include <asm/setup.h>
#include <asm/delay.h>
#include <asm/meminit.h>
26
#include <asm/processor.h>
27 28
#include <asm/sal.h>
#include <asm/mca.h>
Z
Zou Nan hai 已提交
29

30
typedef void (*relocate_new_kernel_t)(
31 32 33 34
					unsigned long indirection_page,
					unsigned long start_address,
					struct ia64_boot_param *boot_param,
					unsigned long pal_addr) ATTRIB_NORET;
Z
Zou Nan hai 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89

struct kimage *ia64_kimage;

struct resource efi_memmap_res = {
        .name  = "EFI Memory Map",
        .start = 0,
        .end   = 0,
        .flags = IORESOURCE_BUSY | IORESOURCE_MEM
};

struct resource boot_param_res = {
        .name  = "Boot parameter",
        .start = 0,
        .end   = 0,
        .flags = IORESOURCE_BUSY | IORESOURCE_MEM
};


/*
 * Do what every setup is needed on image and the
 * reboot code buffer to allow us to avoid allocations
 * later.
 */
int machine_kexec_prepare(struct kimage *image)
{
	void *control_code_buffer;
	const unsigned long *func;

	func = (unsigned long *)&relocate_new_kernel;
	/* Pre-load control code buffer to minimize work in kexec path */
	control_code_buffer = page_address(image->control_code_page);
	memcpy((void *)control_code_buffer, (const void *)func[0],
			relocate_new_kernel_size);
	flush_icache_range((unsigned long)control_code_buffer,
			(unsigned long)control_code_buffer + relocate_new_kernel_size);
	ia64_kimage = image;

	return 0;
}

void machine_kexec_cleanup(struct kimage *image)
{
}

/*
 * Do not allocate memory (or fail in any way) in machine_kexec().
 * We are past the point of no return, committed to rebooting now.
 */
static void ia64_machine_kexec(struct unw_frame_info *info, void *arg)
{
	struct kimage *image = arg;
	relocate_new_kernel_t rnk;
	void *pal_addr = efi_get_pal_addr();
	unsigned long code_addr = (unsigned long)page_address(image->control_code_page);
	int ii;
90 91
	u64 fp, gp;
	ia64_fptr_t *init_handler = (ia64_fptr_t *)ia64_os_init_on_kdump;
Z
Zou Nan hai 已提交
92

93
	BUG_ON(!image);
Z
Zou Nan hai 已提交
94 95 96
	if (image->type == KEXEC_TYPE_CRASH) {
		crash_save_this_cpu();
		current->thread.ksp = (__u64)info->sw - 16;
97 98 99 100 101 102 103 104

		/* Register noop init handler */
		fp = ia64_tpa(init_handler->fp);
		gp = ia64_tpa(ia64_getreg(_IA64_REG_GP));
		ia64_sal_set_vectors(SAL_VECTOR_OS_INIT, fp, gp, 0, fp, gp, 0);
	} else {
		/* Unregister init handlers of current kernel */
		ia64_sal_set_vectors(SAL_VECTOR_OS_INIT, 0, 0, 0, 0, 0, 0);
Z
Zou Nan hai 已提交
105 106
	}

107 108 109
	/* Unregister mca handler - No more recovery on current kernel */
	ia64_sal_set_vectors(SAL_VECTOR_OS_MCA, 0, 0, 0, 0, 0, 0);

Z
Zou Nan hai 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
	/* Interrupts aren't acceptable while we reboot */
	local_irq_disable();

	/* Mask CMC and Performance Monitor interrupts */
	ia64_setreg(_IA64_REG_CR_PMV, 1 << 16);
	ia64_setreg(_IA64_REG_CR_CMCV, 1 << 16);

	/* Mask ITV and Local Redirect Registers */
	ia64_set_itv(1 << 16);
	ia64_set_lrr0(1 << 16);
	ia64_set_lrr1(1 << 16);

	/* terminate possible nested in-service interrupts */
	for (ii = 0; ii < 16; ii++)
		ia64_eoi();

	/* unmask TPR and clear any pending interrupts */
	ia64_setreg(_IA64_REG_CR_TPR, 0);
	ia64_srlz_d();
129
	while (ia64_get_ivr() != IA64_SPURIOUS_INT_VECTOR)
Z
Zou Nan hai 已提交
130 131 132 133 134 135 136 137 138 139
		ia64_eoi();
	platform_kernel_launch_event();
	rnk = (relocate_new_kernel_t)&code_addr;
	(*rnk)(image->head, image->start, ia64_boot_param,
		     GRANULEROUNDDOWN((unsigned long) pal_addr));
	BUG();
}

void machine_kexec(struct kimage *image)
{
140
	BUG_ON(!image);
Z
Zou Nan hai 已提交
141 142 143
	unw_init_running(ia64_machine_kexec, image);
	for(;;);
}
K
Ken'ichi Ohmichi 已提交
144 145 146

void arch_crash_save_vmcoreinfo(void)
{
147
#if defined(CONFIG_DISCONTIGMEM) || defined(CONFIG_SPARSEMEM)
148 149
	VMCOREINFO_SYMBOL(pgdat_list);
	VMCOREINFO_LENGTH(pgdat_list, MAX_NUMNODES);
150 151
#endif
#ifdef CONFIG_NUMA
152 153
	VMCOREINFO_SYMBOL(node_memblk);
	VMCOREINFO_LENGTH(node_memblk, NR_NODE_MEMBLKS);
154
	VMCOREINFO_STRUCT_SIZE(node_memblk_s);
155 156
	VMCOREINFO_OFFSET(node_memblk_s, start_paddr);
	VMCOREINFO_OFFSET(node_memblk_s, size);
K
Ken'ichi Ohmichi 已提交
157 158
#endif
#ifdef CONFIG_PGTABLE_3
159
	VMCOREINFO_CONFIG(PGTABLE_3);
K
Ken'ichi Ohmichi 已提交
160
#elif  CONFIG_PGTABLE_4
161
	VMCOREINFO_CONFIG(PGTABLE_4);
K
Ken'ichi Ohmichi 已提交
162 163 164 165 166
#endif
}

unsigned long paddr_vmcoreinfo_note(void)
{
167
	return ia64_tpa((unsigned long)(char *)&vmcoreinfo_note);
K
Ken'ichi Ohmichi 已提交
168 169
}