x86-32: Separate 1:1 pagetables from swapper_pg_dir
[firefly-linux-kernel-4.4.55.git] / arch / x86 / kernel / trampoline.c
1 #include <linux/io.h>
2
3 #include <asm/trampoline.h>
4 #include <asm/pgtable.h>
5 #include <asm/e820.h>
6
7 #if defined(CONFIG_X86_64) && defined(CONFIG_ACPI_SLEEP)
8 #define __trampinit
9 #define __trampinitdata
10 #else
11 #define __trampinit __cpuinit
12 #define __trampinitdata __cpuinitdata
13 #endif
14
15 /* ready for x86_64 and x86 */
16 unsigned char *__trampinitdata trampoline_base = __va(TRAMPOLINE_BASE);
17
18 void __init reserve_trampoline_memory(void)
19 {
20 #ifdef CONFIG_X86_32
21         /*
22          * But first pinch a few for the stack/trampoline stuff
23          * FIXME: Don't need the extra page at 4K, but need to fix
24          * trampoline before removing it. (see the GDT stuff)
25          */
26         reserve_early(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE, "EX TRAMPOLINE");
27 #endif
28         /* Has to be in very low memory so we can execute real-mode AP code. */
29         reserve_early(TRAMPOLINE_BASE, TRAMPOLINE_BASE + TRAMPOLINE_SIZE,
30                         "TRAMPOLINE");
31 }
32
33 /*
34  * Currently trivial. Write the real->protected mode
35  * bootstrap into the page concerned. The caller
36  * has made sure it's suitably aligned.
37  */
38 unsigned long __trampinit setup_trampoline(void)
39 {
40         memcpy(trampoline_base, trampoline_data, TRAMPOLINE_SIZE);
41         return virt_to_phys(trampoline_base);
42 }
43
44 void __init setup_trampoline_page_table(void)
45 {
46 #ifdef CONFIG_X86_32
47         /* Copy kernel address range */
48         clone_pgd_range(trampoline_pg_dir + KERNEL_PGD_BOUNDARY,
49                         swapper_pg_dir + KERNEL_PGD_BOUNDARY,
50                         min_t(unsigned long, KERNEL_PGD_PTRS,
51                               KERNEL_PGD_BOUNDARY));
52
53         /* Initialize low mappings */
54         clone_pgd_range(trampoline_pg_dir,
55                         swapper_pg_dir + KERNEL_PGD_BOUNDARY,
56                         min_t(unsigned long, KERNEL_PGD_PTRS,
57                               KERNEL_PGD_BOUNDARY));
58 #endif
59 }