CapsuleUpdatePolicyLibOnProtocol.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /** @file
  2. Provides platform policy services used during a capsule update that uses the
  3. services of the EDKII_CAPSULE_UPDATE_POLICY_PROTOCOL. If the
  4. EDKII_CAPSULE_UPDATE_POLICY_PROTOCOL is not available, then assume the
  5. platform is in a state that supports a firmware update.
  6. Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
  7. Copyright (c) 2018-2019, Intel Corporation. All rights reserved.<BR>
  8. SPDX-License-Identifier: BSD-2-Clause-Patent
  9. **/
  10. #include <PiDxe.h>
  11. #include <Library/CapsuleUpdatePolicyLib.h>
  12. #include <Library/DebugLib.h>
  13. #include <Library/UefiBootServicesTableLib.h>
  14. #include <Protocol/CapsuleUpdatePolicy.h>
  15. ///
  16. /// Pointer to the EDK II Capsule Update Policy Protocol instances that is
  17. /// optionally installed by a platform.
  18. ///
  19. EDKII_CAPSULE_UPDATE_POLICY_PROTOCOL *mCapsuleUpdatePolicy = NULL;
  20. /**
  21. Lookup the EDK II Capsule Update Policy Protocol.
  22. **/
  23. BOOLEAN
  24. LookupCapsuleUpdatePolicyProtocol (
  25. VOID
  26. )
  27. {
  28. EFI_STATUS Status;
  29. if (mCapsuleUpdatePolicy != NULL) {
  30. return TRUE;
  31. }
  32. Status = gBS->LocateProtocol (
  33. &gEdkiiCapsuleUpdatePolicyProtocolGuid,
  34. NULL,
  35. (VOID **)&mCapsuleUpdatePolicy
  36. );
  37. if (EFI_ERROR (Status)) {
  38. mCapsuleUpdatePolicy = NULL;
  39. return FALSE;
  40. }
  41. return TRUE;
  42. }
  43. /**
  44. Determine if the system power state supports a capsule update.
  45. @param[out] Good Returns TRUE if system power state supports a capsule
  46. update. Returns FALSE if system power state does not
  47. support a capsule update. Return value is only valid if
  48. return status is EFI_SUCCESS.
  49. @retval EFI_SUCCESS Good parameter has been updated with result.
  50. @retval EFI_INVALID_PARAMETER Good is NULL.
  51. @retval EFI_DEVICE_ERROR System power state can not be determined.
  52. **/
  53. EFI_STATUS
  54. EFIAPI
  55. CheckSystemPower (
  56. OUT BOOLEAN *Good
  57. )
  58. {
  59. if (LookupCapsuleUpdatePolicyProtocol ()) {
  60. return mCapsuleUpdatePolicy->CheckSystemPower (mCapsuleUpdatePolicy, Good);
  61. }
  62. *Good = TRUE;
  63. return EFI_SUCCESS;
  64. }
  65. /**
  66. Determines if the system thermal state supports a capsule update.
  67. @param[out] Good Returns TRUE if system thermal state supports a capsule
  68. update. Returns FALSE if system thermal state does not
  69. support a capsule update. Return value is only valid if
  70. return status is EFI_SUCCESS.
  71. @retval EFI_SUCCESS Good parameter has been updated with result.
  72. @retval EFI_INVALID_PARAMETER Good is NULL.
  73. @retval EFI_DEVICE_ERROR System thermal state can not be determined.
  74. **/
  75. EFI_STATUS
  76. EFIAPI
  77. CheckSystemThermal (
  78. OUT BOOLEAN *Good
  79. )
  80. {
  81. if (LookupCapsuleUpdatePolicyProtocol ()) {
  82. return mCapsuleUpdatePolicy->CheckSystemThermal (mCapsuleUpdatePolicy, Good);
  83. }
  84. *Good = TRUE;
  85. return EFI_SUCCESS;
  86. }
  87. /**
  88. Determines if the system environment state supports a capsule update.
  89. @param[out] Good Returns TRUE if system environment state supports a capsule
  90. update. Returns FALSE if system environment state does not
  91. support a capsule update. Return value is only valid if
  92. return status is EFI_SUCCESS.
  93. @retval EFI_SUCCESS Good parameter has been updated with result.
  94. @retval EFI_INVALID_PARAMETER Good is NULL.
  95. @retval EFI_DEVICE_ERROR System environment state can not be determined.
  96. **/
  97. EFI_STATUS
  98. EFIAPI
  99. CheckSystemEnvironment (
  100. OUT BOOLEAN *Good
  101. )
  102. {
  103. if (LookupCapsuleUpdatePolicyProtocol ()) {
  104. return mCapsuleUpdatePolicy->CheckSystemEnvironment (mCapsuleUpdatePolicy, Good);
  105. }
  106. *Good = TRUE;
  107. return EFI_SUCCESS;
  108. }
  109. /**
  110. Determines if the Lowest Supported Version checks should be performed. The
  111. expected result from this function is TRUE. A platform can choose to return
  112. FALSE (e.g. during manufacturing or servicing) to allow a capsule update to a
  113. version below the current Lowest Supported Version.
  114. @retval TRUE The lowest supported version check is required.
  115. @retval FALSE Do not perform lowest support version check.
  116. **/
  117. BOOLEAN
  118. EFIAPI
  119. IsLowestSupportedVersionCheckRequired (
  120. VOID
  121. )
  122. {
  123. if (LookupCapsuleUpdatePolicyProtocol ()) {
  124. return mCapsuleUpdatePolicy->IsLowestSupportedVersionCheckRequired (mCapsuleUpdatePolicy);
  125. }
  126. return TRUE;
  127. }
  128. /**
  129. Determines if the FMP device should be locked when the event specified by
  130. PcdFmpDeviceLockEventGuid is signaled. The expected result from this function
  131. is TRUE so the FMP device is always locked. A platform can choose to return
  132. FALSE (e.g. during manufacturing) to allow FMP devices to remain unlocked.
  133. @retval TRUE The FMP device lock action is required at lock event guid.
  134. @retval FALSE Do not perform FMP device lock at lock event guid.
  135. **/
  136. BOOLEAN
  137. EFIAPI
  138. IsLockFmpDeviceAtLockEventGuidRequired (
  139. VOID
  140. )
  141. {
  142. if (LookupCapsuleUpdatePolicyProtocol ()) {
  143. return mCapsuleUpdatePolicy->IsLockFmpDeviceAtLockEventGuidRequired (mCapsuleUpdatePolicy);
  144. }
  145. return TRUE;
  146. }