trampoline.c 1.0 KB

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