runtime-wrappers.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * runtime-wrappers.c - Runtime Services function call wrappers
  3. *
  4. * Copyright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
  5. *
  6. * Split off from arch/x86/platform/efi/efi.c
  7. *
  8. * Copyright (C) 1999 VA Linux Systems
  9. * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
  10. * Copyright (C) 1999-2002 Hewlett-Packard Co.
  11. * Copyright (C) 2005-2008 Intel Co.
  12. * Copyright (C) 2013 SuSE Labs
  13. *
  14. * This file is released under the GPLv2.
  15. */
  16. #include <linux/efi.h>
  17. #include <linux/spinlock.h> /* spinlock_t */
  18. #include <asm/efi.h>
  19. /*
  20. * As per commit ef68c8f87ed1 ("x86: Serialize EFI time accesses on rtc_lock"),
  21. * the EFI specification requires that callers of the time related runtime
  22. * functions serialize with other CMOS accesses in the kernel, as the EFI time
  23. * functions may choose to also use the legacy CMOS RTC.
  24. */
  25. __weak DEFINE_SPINLOCK(rtc_lock);
  26. static efi_status_t virt_efi_get_time(efi_time_t *tm, efi_time_cap_t *tc)
  27. {
  28. unsigned long flags;
  29. efi_status_t status;
  30. spin_lock_irqsave(&rtc_lock, flags);
  31. status = efi_call_virt(get_time, tm, tc);
  32. spin_unlock_irqrestore(&rtc_lock, flags);
  33. return status;
  34. }
  35. static efi_status_t virt_efi_set_time(efi_time_t *tm)
  36. {
  37. unsigned long flags;
  38. efi_status_t status;
  39. spin_lock_irqsave(&rtc_lock, flags);
  40. status = efi_call_virt(set_time, tm);
  41. spin_unlock_irqrestore(&rtc_lock, flags);
  42. return status;
  43. }
  44. static efi_status_t virt_efi_get_wakeup_time(efi_bool_t *enabled,
  45. efi_bool_t *pending,
  46. efi_time_t *tm)
  47. {
  48. unsigned long flags;
  49. efi_status_t status;
  50. spin_lock_irqsave(&rtc_lock, flags);
  51. status = efi_call_virt(get_wakeup_time, enabled, pending, tm);
  52. spin_unlock_irqrestore(&rtc_lock, flags);
  53. return status;
  54. }
  55. static efi_status_t virt_efi_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm)
  56. {
  57. unsigned long flags;
  58. efi_status_t status;
  59. spin_lock_irqsave(&rtc_lock, flags);
  60. status = efi_call_virt(set_wakeup_time, enabled, tm);
  61. spin_unlock_irqrestore(&rtc_lock, flags);
  62. return status;
  63. }
  64. static efi_status_t virt_efi_get_variable(efi_char16_t *name,
  65. efi_guid_t *vendor,
  66. u32 *attr,
  67. unsigned long *data_size,
  68. void *data)
  69. {
  70. return efi_call_virt(get_variable, name, vendor, attr, data_size, data);
  71. }
  72. static efi_status_t virt_efi_get_next_variable(unsigned long *name_size,
  73. efi_char16_t *name,
  74. efi_guid_t *vendor)
  75. {
  76. return efi_call_virt(get_next_variable, name_size, name, vendor);
  77. }
  78. static efi_status_t virt_efi_set_variable(efi_char16_t *name,
  79. efi_guid_t *vendor,
  80. u32 attr,
  81. unsigned long data_size,
  82. void *data)
  83. {
  84. return efi_call_virt(set_variable, name, vendor, attr, data_size, data);
  85. }
  86. static efi_status_t virt_efi_query_variable_info(u32 attr,
  87. u64 *storage_space,
  88. u64 *remaining_space,
  89. u64 *max_variable_size)
  90. {
  91. if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
  92. return EFI_UNSUPPORTED;
  93. return efi_call_virt(query_variable_info, attr, storage_space,
  94. remaining_space, max_variable_size);
  95. }
  96. static efi_status_t virt_efi_get_next_high_mono_count(u32 *count)
  97. {
  98. return efi_call_virt(get_next_high_mono_count, count);
  99. }
  100. static void virt_efi_reset_system(int reset_type,
  101. efi_status_t status,
  102. unsigned long data_size,
  103. efi_char16_t *data)
  104. {
  105. __efi_call_virt(reset_system, reset_type, status, data_size, data);
  106. }
  107. static efi_status_t virt_efi_update_capsule(efi_capsule_header_t **capsules,
  108. unsigned long count,
  109. unsigned long sg_list)
  110. {
  111. if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
  112. return EFI_UNSUPPORTED;
  113. return efi_call_virt(update_capsule, capsules, count, sg_list);
  114. }
  115. static efi_status_t virt_efi_query_capsule_caps(efi_capsule_header_t **capsules,
  116. unsigned long count,
  117. u64 *max_size,
  118. int *reset_type)
  119. {
  120. if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION)
  121. return EFI_UNSUPPORTED;
  122. return efi_call_virt(query_capsule_caps, capsules, count, max_size,
  123. reset_type);
  124. }
  125. void efi_native_runtime_setup(void)
  126. {
  127. efi.get_time = virt_efi_get_time;
  128. efi.set_time = virt_efi_set_time;
  129. efi.get_wakeup_time = virt_efi_get_wakeup_time;
  130. efi.set_wakeup_time = virt_efi_set_wakeup_time;
  131. efi.get_variable = virt_efi_get_variable;
  132. efi.get_next_variable = virt_efi_get_next_variable;
  133. efi.set_variable = virt_efi_set_variable;
  134. efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count;
  135. efi.reset_system = virt_efi_reset_system;
  136. efi.query_variable_info = virt_efi_query_variable_info;
  137. efi.update_capsule = virt_efi_update_capsule;
  138. efi.query_capsule_caps = virt_efi_query_capsule_caps;
  139. }