PlatformGopPolicy.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*++
  2. Copyright (c) 1999 - 2014, Intel Corporation. All rights reserved
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. --*/
  5. /** @file
  6. **/
  7. #include <Library/BaseMemoryLib.h>
  8. #include <Library/DebugLib.h>
  9. #include <Protocol/FirmwareVolume2.h>
  10. #include <Protocol/PlatformGopPolicy.h>
  11. #include <Guid/SetupVariable.h>
  12. #include <SetupMode.h>
  13. #include <Library/UefiBootServicesTableLib.h>
  14. #include <Library/UefiRuntimeServicesTableLib.h>
  15. PLATFORM_GOP_POLICY_PROTOCOL mPlatformGOPPolicy;
  16. //
  17. // Function implementations
  18. //
  19. /**
  20. The function will execute with as the platform policy, and gives
  21. the Platform Lid Status. IBV/OEM can customize this code for their specific
  22. policy action.
  23. @param CurrentLidStatus Gives the current LID Status
  24. @retval EFI_SUCCESS.
  25. **/
  26. EFI_STATUS
  27. EFIAPI
  28. GetPlatformLidStatus (
  29. OUT LID_STATUS *CurrentLidStatus
  30. )
  31. {
  32. *CurrentLidStatus = LidOpen;
  33. return EFI_SUCCESS;
  34. }
  35. /**
  36. The function will execute and gives the Video Bios Table Size and Address.
  37. @param VbtAddress Gives the Physical Address of Video BIOS Table
  38. @param VbtSize Gives the Size of Video BIOS Table
  39. @retval EFI_STATUS.
  40. **/
  41. EFI_STATUS
  42. EFIAPI
  43. GetVbtData (
  44. OUT EFI_PHYSICAL_ADDRESS *VbtAddress,
  45. OUT UINT32 *VbtSize
  46. )
  47. {
  48. EFI_STATUS Status;
  49. UINTN FvProtocolCount;
  50. EFI_HANDLE *FvHandles;
  51. EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
  52. UINTN Index;
  53. UINT32 AuthenticationStatus;
  54. UINT8 *Buffer;
  55. UINTN VbtBufferSize;
  56. Buffer = 0;
  57. FvHandles = NULL;
  58. if (VbtAddress == NULL || VbtSize == NULL){
  59. return EFI_INVALID_PARAMETER;
  60. }
  61. Status = gBS->LocateHandleBuffer (
  62. ByProtocol,
  63. &gEfiFirmwareVolume2ProtocolGuid,
  64. NULL,
  65. &FvProtocolCount,
  66. &FvHandles
  67. );
  68. if (!EFI_ERROR (Status)) {
  69. for (Index = 0; Index < FvProtocolCount; Index++) {
  70. Status = gBS->HandleProtocol (
  71. FvHandles[Index],
  72. &gEfiFirmwareVolume2ProtocolGuid,
  73. (VOID **) &Fv
  74. );
  75. VbtBufferSize = 0;
  76. Status = Fv->ReadSection (
  77. Fv,
  78. &gBmpImageGuid,
  79. EFI_SECTION_RAW,
  80. 0,
  81. (void **)&Buffer,
  82. &VbtBufferSize,
  83. &AuthenticationStatus
  84. );
  85. if (!EFI_ERROR (Status)) {
  86. *VbtAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;
  87. *VbtSize = (UINT32)VbtBufferSize;
  88. Status = EFI_SUCCESS;
  89. break;
  90. }
  91. }
  92. } else {
  93. Status = EFI_NOT_FOUND;
  94. }
  95. if (FvHandles != NULL) {
  96. gBS->FreePool (FvHandles);
  97. FvHandles = NULL;
  98. }
  99. return Status;
  100. }
  101. /**
  102. Entry point for the Platform GOP Policy Driver.
  103. @param ImageHandle Image handle of this driver.
  104. @param SystemTable Global system service table.
  105. @retval EFI_SUCCESS Initialization complete.
  106. @retval EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver.
  107. **/
  108. EFI_STATUS
  109. EFIAPI
  110. PlatformGOPPolicyEntryPoint (
  111. IN EFI_HANDLE ImageHandle,
  112. IN EFI_SYSTEM_TABLE *SystemTable
  113. )
  114. {
  115. EFI_STATUS Status = EFI_SUCCESS;
  116. SYSTEM_CONFIGURATION SystemConfiguration;
  117. UINTN VarSize;
  118. gBS = SystemTable->BootServices;
  119. gBS->SetMem (
  120. &mPlatformGOPPolicy,
  121. sizeof (PLATFORM_GOP_POLICY_PROTOCOL),
  122. 0
  123. );
  124. mPlatformGOPPolicy.Revision = PLATFORM_GOP_POLICY_PROTOCOL_REVISION_01;
  125. mPlatformGOPPolicy.GetPlatformLidStatus = GetPlatformLidStatus;
  126. mPlatformGOPPolicy.GetVbtData = GetVbtData;
  127. //
  128. // Install protocol to allow access to this Policy.
  129. //
  130. VarSize = sizeof(SYSTEM_CONFIGURATION);
  131. Status = gRT->GetVariable(
  132. L"Setup",
  133. &gEfiNormalSetupGuid,
  134. NULL,
  135. &VarSize,
  136. &SystemConfiguration
  137. );
  138. if (EFI_ERROR (Status) || VarSize != sizeof(SYSTEM_CONFIGURATION)) {
  139. //The setup variable is corrupted
  140. VarSize = sizeof(SYSTEM_CONFIGURATION);
  141. Status = gRT->GetVariable(
  142. L"SetupRecovery",
  143. &gEfiNormalSetupGuid,
  144. NULL,
  145. &VarSize,
  146. &SystemConfiguration
  147. );
  148. ASSERT_EFI_ERROR (Status);
  149. }
  150. if (SystemConfiguration.GOPEnable == 1)
  151. {
  152. Status = gBS->InstallMultipleProtocolInterfaces (
  153. &ImageHandle,
  154. &gPlatformGOPPolicyGuid,
  155. &mPlatformGOPPolicy,
  156. NULL
  157. );
  158. }
  159. return Status;
  160. }