efi_32.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Extensible Firmware Interface
  4. *
  5. * Based on Extensible Firmware Interface Specification version 1.0
  6. *
  7. * Copyright (C) 1999 VA Linux Systems
  8. * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
  9. * Copyright (C) 1999-2002 Hewlett-Packard Co.
  10. * David Mosberger-Tang <davidm@hpl.hp.com>
  11. * Stephane Eranian <eranian@hpl.hp.com>
  12. *
  13. * All EFI Runtime Services are not implemented yet as EFI only
  14. * supports physical mode addressing on SoftSDV. This is to be fixed
  15. * in a future version. --drummond 1999-07-20
  16. *
  17. * Implemented EFI runtime services and virtual mode calls. --davidm
  18. *
  19. * Goutham Rao: <goutham.rao@intel.com>
  20. * Skip non-WB memory and ignore empty memory ranges.
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/types.h>
  24. #include <linux/ioport.h>
  25. #include <linux/efi.h>
  26. #include <linux/pgtable.h>
  27. #include <asm/io.h>
  28. #include <asm/desc.h>
  29. #include <asm/page.h>
  30. #include <asm/set_memory.h>
  31. #include <asm/tlbflush.h>
  32. #include <asm/efi.h>
  33. void __init efi_map_region(efi_memory_desc_t *md)
  34. {
  35. u64 start_pfn, end_pfn, end;
  36. unsigned long size;
  37. void *va;
  38. start_pfn = PFN_DOWN(md->phys_addr);
  39. size = md->num_pages << PAGE_SHIFT;
  40. end = md->phys_addr + size;
  41. end_pfn = PFN_UP(end);
  42. if (pfn_range_is_mapped(start_pfn, end_pfn)) {
  43. va = __va(md->phys_addr);
  44. if (!(md->attribute & EFI_MEMORY_WB))
  45. set_memory_uc((unsigned long)va, md->num_pages);
  46. } else {
  47. va = ioremap_cache(md->phys_addr, size);
  48. }
  49. md->virt_addr = (unsigned long)va;
  50. if (!va)
  51. pr_err("ioremap of 0x%llX failed!\n", md->phys_addr);
  52. }
  53. /*
  54. * To make EFI call EFI runtime service in physical addressing mode we need
  55. * prolog/epilog before/after the invocation to claim the EFI runtime service
  56. * handler exclusively and to duplicate a memory mapping in low memory space,
  57. * say 0 - 3G.
  58. */
  59. int __init efi_alloc_page_tables(void)
  60. {
  61. return 0;
  62. }
  63. void efi_sync_low_kernel_mappings(void) {}
  64. void __init efi_dump_pagetable(void)
  65. {
  66. #ifdef CONFIG_EFI_PGT_DUMP
  67. ptdump_walk_pgd_level(NULL, &init_mm);
  68. #endif
  69. }
  70. int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
  71. {
  72. return 0;
  73. }
  74. void __init efi_map_region_fixed(efi_memory_desc_t *md) {}
  75. void __init parse_efi_setup(u64 phys_addr, u32 data_len) {}
  76. efi_status_t efi_call_svam(efi_runtime_services_t * const *,
  77. u32, u32, u32, void *, u32);
  78. efi_status_t __init efi_set_virtual_address_map(unsigned long memory_map_size,
  79. unsigned long descriptor_size,
  80. u32 descriptor_version,
  81. efi_memory_desc_t *virtual_map,
  82. unsigned long systab_phys)
  83. {
  84. const efi_system_table_t *systab = (efi_system_table_t *)systab_phys;
  85. struct desc_ptr gdt_descr;
  86. efi_status_t status;
  87. unsigned long flags;
  88. pgd_t *save_pgd;
  89. /* Current pgd is swapper_pg_dir, we'll restore it later: */
  90. save_pgd = swapper_pg_dir;
  91. load_cr3(initial_page_table);
  92. __flush_tlb_all();
  93. gdt_descr.address = get_cpu_gdt_paddr(0);
  94. gdt_descr.size = GDT_SIZE - 1;
  95. load_gdt(&gdt_descr);
  96. /* Disable interrupts around EFI calls: */
  97. local_irq_save(flags);
  98. status = efi_call_svam(&systab->runtime,
  99. memory_map_size, descriptor_size,
  100. descriptor_version, virtual_map,
  101. __pa(&efi.runtime));
  102. local_irq_restore(flags);
  103. load_fixmap_gdt(0);
  104. load_cr3(save_pgd);
  105. __flush_tlb_all();
  106. return status;
  107. }
  108. void __init efi_runtime_update_mappings(void)
  109. {
  110. if (__supported_pte_mask & _PAGE_NX) {
  111. efi_memory_desc_t *md;
  112. /* Make EFI runtime service code area executable */
  113. for_each_efi_memory_desc(md) {
  114. if (md->type != EFI_RUNTIME_SERVICES_CODE)
  115. continue;
  116. set_memory_x(md->virt_addr, md->num_pages);
  117. }
  118. }
  119. }
  120. void arch_efi_call_virt_setup(void)
  121. {
  122. efi_fpu_begin();
  123. firmware_restrict_branch_speculation_start();
  124. }
  125. void arch_efi_call_virt_teardown(void)
  126. {
  127. firmware_restrict_branch_speculation_end();
  128. efi_fpu_end();
  129. }