trampoline.c 989 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <linux/io.h>
  2. #include <asm/trampoline.h>
  3. #include <asm/e820.h>
  4. #if defined(CONFIG_X86_64) && defined(CONFIG_ACPI_SLEEP)
  5. #define __trampinit
  6. #define __trampinitdata
  7. #else
  8. #define __trampinit __cpuinit
  9. #define __trampinitdata __cpuinitdata
  10. #endif
  11. /* ready for x86_64 and x86 */
  12. unsigned char *__trampinitdata trampoline_base;
  13. void __init reserve_trampoline_memory(void)
  14. {
  15. unsigned long mem;
  16. /* Has to be in very low memory so we can execute real-mode AP code. */
  17. mem = find_e820_area(0, 1<<20, TRAMPOLINE_SIZE, PAGE_SIZE);
  18. if (mem == -1L)
  19. panic("Cannot allocate trampoline\n");
  20. trampoline_base = __va(mem);
  21. reserve_early(mem, mem + TRAMPOLINE_SIZE, "TRAMPOLINE");
  22. }
  23. /*
  24. * Currently trivial. Write the real->protected mode
  25. * bootstrap into the page concerned. The caller
  26. * has made sure it's suitably aligned.
  27. */
  28. unsigned long __trampinit setup_trampoline(void)
  29. {
  30. memcpy(trampoline_base, trampoline_data, TRAMPOLINE_SIZE);
  31. return virt_to_phys(trampoline_base);
  32. }