efi_64.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * x86_64 specific EFI support functions
  3. * Based on Extensible Firmware Interface Specification version 1.0
  4. *
  5. * Copyright (C) 2005-2008 Intel Co.
  6. * Fenghua Yu <fenghua.yu@intel.com>
  7. * Bibo Mao <bibo.mao@intel.com>
  8. * Chandramouli Narayanan <mouli@linux.intel.com>
  9. * Huang Ying <ying.huang@intel.com>
  10. *
  11. * Code to convert EFI to E820 map has been implemented in elilo bootloader
  12. * based on a EFI patch by Edgar Hucek. Based on the E820 map, the page table
  13. * is setup appropriately for EFI runtime code.
  14. * - mouli 06/14/2007.
  15. *
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/mm.h>
  20. #include <linux/types.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/bootmem.h>
  23. #include <linux/ioport.h>
  24. #include <linux/module.h>
  25. #include <linux/efi.h>
  26. #include <linux/uaccess.h>
  27. #include <linux/io.h>
  28. #include <linux/reboot.h>
  29. #include <asm/setup.h>
  30. #include <asm/page.h>
  31. #include <asm/e820.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/tlbflush.h>
  34. #include <asm/proto.h>
  35. #include <asm/efi.h>
  36. #include <asm/cacheflush.h>
  37. #include <asm/fixmap.h>
  38. static pgd_t save_pgd __initdata;
  39. static unsigned long efi_flags __initdata;
  40. static void __init early_mapping_set_exec(unsigned long start,
  41. unsigned long end,
  42. int executable)
  43. {
  44. unsigned long num_pages;
  45. start &= PMD_MASK;
  46. end = (end + PMD_SIZE - 1) & PMD_MASK;
  47. num_pages = (end - start) >> PAGE_SHIFT;
  48. if (executable)
  49. set_memory_x((unsigned long)__va(start), num_pages);
  50. else
  51. set_memory_nx((unsigned long)__va(start), num_pages);
  52. }
  53. static void __init early_runtime_code_mapping_set_exec(int executable)
  54. {
  55. efi_memory_desc_t *md;
  56. void *p;
  57. if (!(__supported_pte_mask & _PAGE_NX))
  58. return;
  59. /* Make EFI runtime service code area executable */
  60. for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) {
  61. md = p;
  62. if (md->type == EFI_RUNTIME_SERVICES_CODE) {
  63. unsigned long end;
  64. end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
  65. early_mapping_set_exec(md->phys_addr, end, executable);
  66. }
  67. }
  68. }
  69. void __init efi_call_phys_prelog(void)
  70. {
  71. unsigned long vaddress;
  72. early_runtime_code_mapping_set_exec(1);
  73. local_irq_save(efi_flags);
  74. vaddress = (unsigned long)__va(0x0UL);
  75. save_pgd = *pgd_offset_k(0x0UL);
  76. set_pgd(pgd_offset_k(0x0UL), *pgd_offset_k(vaddress));
  77. __flush_tlb_all();
  78. }
  79. void __init efi_call_phys_epilog(void)
  80. {
  81. /*
  82. * After the lock is released, the original page table is restored.
  83. */
  84. set_pgd(pgd_offset_k(0x0UL), save_pgd);
  85. __flush_tlb_all();
  86. local_irq_restore(efi_flags);
  87. early_runtime_code_mapping_set_exec(0);
  88. }
  89. void __iomem *__init efi_ioremap(unsigned long phys_addr, unsigned long size,
  90. u32 type)
  91. {
  92. unsigned long last_map_pfn;
  93. if (type == EFI_MEMORY_MAPPED_IO)
  94. return ioremap(phys_addr, size);
  95. last_map_pfn = init_memory_mapping(phys_addr, phys_addr + size);
  96. if ((last_map_pfn << PAGE_SHIFT) < phys_addr + size)
  97. return NULL;
  98. return (void __iomem *)__va(phys_addr);
  99. }