1 #include <linux/io.h>
2 #include <linux/memblock.h>
3 
4 #include <asm/trampoline.h>
5 #include <asm/cacheflush.h>
6 #include <asm/pgtable.h>
7 
8 unsigned char *x86_trampoline_base;
9 
setup_trampolines(void)10 void __init setup_trampolines(void)
11 {
12 	phys_addr_t mem;
13 	size_t size = PAGE_ALIGN(x86_trampoline_end - x86_trampoline_start);
14 
15 	/* Has to be in very low memory so we can execute real-mode AP code. */
16 	mem = memblock_find_in_range(0, 1<<20, size, PAGE_SIZE);
17 	if (!mem)
18 		panic("Cannot allocate trampoline\n");
19 
20 	x86_trampoline_base = __va(mem);
21 	memblock_reserve(mem, size);
22 
23 	printk(KERN_DEBUG "Base memory trampoline at [%p] %llx size %zu\n",
24 	       x86_trampoline_base, (unsigned long long)mem, size);
25 
26 	memcpy(x86_trampoline_base, x86_trampoline_start, size);
27 }
28 
29 /*
30  * setup_trampolines() gets called very early, to guarantee the
31  * availability of low memory.  This is before the proper kernel page
32  * tables are set up, so we cannot set page permissions in that
33  * function.  Thus, we use an arch_initcall instead.
34  */
configure_trampolines(void)35 static int __init configure_trampolines(void)
36 {
37 	size_t size = PAGE_ALIGN(x86_trampoline_end - x86_trampoline_start);
38 
39 	set_memory_x((unsigned long)x86_trampoline_base, size >> PAGE_SHIFT);
40 	return 0;
41 }
42 arch_initcall(configure_trampolines);
43