efi_32.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Extensible Firmware Interface
  3. *
  4. * Based on Extensible Firmware Interface Specification version 1.0
  5. *
  6. * Copyright (C) 1999 VA Linux Systems
  7. * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
  8. * Copyright (C) 1999-2002 Hewlett-Packard Co.
  9. * David Mosberger-Tang <davidm@hpl.hp.com>
  10. * Stephane Eranian <eranian@hpl.hp.com>
  11. *
  12. * All EFI Runtime Services are not implemented yet as EFI only
  13. * supports physical mode addressing on SoftSDV. This is to be fixed
  14. * in a future version. --drummond 1999-07-20
  15. *
  16. * Implemented EFI runtime services and virtual mode calls. --davidm
  17. *
  18. * Goutham Rao: <goutham.rao@intel.com>
  19. * Skip non-WB memory and ignore empty memory ranges.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/types.h>
  23. #include <linux/ioport.h>
  24. #include <linux/efi.h>
  25. #include <asm/io.h>
  26. #include <asm/page.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/tlbflush.h>
  29. #include <asm/efi.h>
  30. /*
  31. * To make EFI call EFI runtime service in physical addressing mode we need
  32. * prelog/epilog before/after the invocation to disable interrupt, to
  33. * claim EFI runtime service handler exclusively and to duplicate a memory in
  34. * low memory space say 0 - 3G.
  35. */
  36. static unsigned long efi_rt_eflags;
  37. static pgd_t efi_bak_pg_dir_pointer[2];
  38. void efi_call_phys_prelog(void)
  39. {
  40. unsigned long cr4;
  41. unsigned long temp;
  42. struct desc_ptr gdt_descr;
  43. local_irq_save(efi_rt_eflags);
  44. /*
  45. * If I don't have PAE, I should just duplicate two entries in page
  46. * directory. If I have PAE, I just need to duplicate one entry in
  47. * page directory.
  48. */
  49. cr4 = read_cr4_safe();
  50. if (cr4 & X86_CR4_PAE) {
  51. efi_bak_pg_dir_pointer[0].pgd =
  52. swapper_pg_dir[pgd_index(0)].pgd;
  53. swapper_pg_dir[0].pgd =
  54. swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
  55. } else {
  56. efi_bak_pg_dir_pointer[0].pgd =
  57. swapper_pg_dir[pgd_index(0)].pgd;
  58. efi_bak_pg_dir_pointer[1].pgd =
  59. swapper_pg_dir[pgd_index(0x400000)].pgd;
  60. swapper_pg_dir[pgd_index(0)].pgd =
  61. swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
  62. temp = PAGE_OFFSET + 0x400000;
  63. swapper_pg_dir[pgd_index(0x400000)].pgd =
  64. swapper_pg_dir[pgd_index(temp)].pgd;
  65. }
  66. /*
  67. * After the lock is released, the original page table is restored.
  68. */
  69. __flush_tlb_all();
  70. gdt_descr.address = __pa(get_cpu_gdt_table(0));
  71. gdt_descr.size = GDT_SIZE - 1;
  72. load_gdt(&gdt_descr);
  73. }
  74. void efi_call_phys_epilog(void)
  75. {
  76. unsigned long cr4;
  77. struct desc_ptr gdt_descr;
  78. gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
  79. gdt_descr.size = GDT_SIZE - 1;
  80. load_gdt(&gdt_descr);
  81. cr4 = read_cr4_safe();
  82. if (cr4 & X86_CR4_PAE) {
  83. swapper_pg_dir[pgd_index(0)].pgd =
  84. efi_bak_pg_dir_pointer[0].pgd;
  85. } else {
  86. swapper_pg_dir[pgd_index(0)].pgd =
  87. efi_bak_pg_dir_pointer[0].pgd;
  88. swapper_pg_dir[pgd_index(0x400000)].pgd =
  89. efi_bak_pg_dir_pointer[1].pgd;
  90. }
  91. /*
  92. * After the lock is released, the original page table is restored.
  93. */
  94. __flush_tlb_all();
  95. local_irq_restore(efi_rt_eflags);
  96. }