GopPolicyInitDxe.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /** @file
  2. This file initialises and Installs GopPolicy Protocol.
  3. Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "GopPolicyInitDxe.h"
  7. #include <Protocol/GopPolicy.h>
  8. GLOBAL_REMOVE_IF_UNREFERENCED GOP_POLICY_PROTOCOL mGOPPolicy;
  9. GLOBAL_REMOVE_IF_UNREFERENCED UINT32 mVbtSize = 0;
  10. GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS mVbtAddress = 0;
  11. //
  12. // Function implementations
  13. //
  14. /**
  15. @param[out] CurrentLidStatus
  16. @retval EFI_SUCCESS
  17. @retval EFI_UNSUPPORTED
  18. **/
  19. EFI_STATUS
  20. EFIAPI
  21. GetPlatformLidStatus (
  22. OUT LID_STATUS *CurrentLidStatus
  23. )
  24. {
  25. return EFI_UNSUPPORTED;
  26. }
  27. /**
  28. @param[out] CurrentDockStatus
  29. @retval EFI_SUCCESS
  30. @retval EFI_UNSUPPORTED
  31. **/
  32. EFI_STATUS
  33. EFIAPI
  34. GetPlatformDockStatus (
  35. OUT DOCK_STATUS CurrentDockStatus
  36. )
  37. {
  38. return EFI_UNSUPPORTED;
  39. }
  40. /**
  41. @param[out] VbtAddress
  42. @param[out] VbtSize
  43. @retval EFI_SUCCESS
  44. @retval EFI_NOT_FOUND
  45. **/
  46. EFI_STATUS
  47. EFIAPI
  48. GetVbtData (
  49. OUT EFI_PHYSICAL_ADDRESS *VbtAddress,
  50. OUT UINT32 *VbtSize
  51. )
  52. {
  53. EFI_STATUS Status;
  54. UINTN FvProtocolCount;
  55. EFI_HANDLE *FvHandles;
  56. EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
  57. UINTN Index;
  58. UINT32 AuthenticationStatus;
  59. UINT8 *Buffer;
  60. UINTN VbtBufferSize;
  61. Status = EFI_NOT_FOUND;
  62. if ( mVbtAddress == 0) {
  63. Fv = NULL;
  64. Buffer = 0;
  65. FvHandles = NULL;
  66. Status = gBS->LocateHandleBuffer (
  67. ByProtocol,
  68. &gEfiFirmwareVolume2ProtocolGuid,
  69. NULL,
  70. &FvProtocolCount,
  71. &FvHandles
  72. );
  73. if (!EFI_ERROR (Status)) {
  74. for (Index = 0; Index < FvProtocolCount; Index++) {
  75. Status = gBS->HandleProtocol (
  76. FvHandles[Index],
  77. &gEfiFirmwareVolume2ProtocolGuid,
  78. (VOID **) &Fv
  79. );
  80. VbtBufferSize = 0;
  81. Status = Fv->ReadSection (
  82. Fv,
  83. PcdGetPtr(PcdIntelGraphicsVbtFileGuid),
  84. EFI_SECTION_RAW,
  85. 0,
  86. (VOID **) &Buffer,
  87. &VbtBufferSize,
  88. &AuthenticationStatus
  89. );
  90. if (!EFI_ERROR (Status)) {
  91. *VbtAddress = (EFI_PHYSICAL_ADDRESS)Buffer;
  92. *VbtSize = (UINT32)VbtBufferSize;
  93. mVbtAddress = *VbtAddress;
  94. mVbtSize = *VbtSize;
  95. Status = EFI_SUCCESS;
  96. break;
  97. }
  98. }
  99. } else {
  100. Status = EFI_NOT_FOUND;
  101. }
  102. if (FvHandles != NULL) {
  103. FreePool (FvHandles);
  104. FvHandles = NULL;
  105. }
  106. } else {
  107. *VbtAddress = mVbtAddress;
  108. *VbtSize = mVbtSize;
  109. Status = EFI_SUCCESS;
  110. }
  111. return Status;
  112. }
  113. /**
  114. Initialize GOP DXE Policy
  115. @param[in] ImageHandle Image handle of this driver.
  116. @retval EFI_SUCCESS Initialization complete.
  117. @retval EFI_UNSUPPORTED The chipset is unsupported by this driver.
  118. @retval EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver.
  119. @retval EFI_DEVICE_ERROR Device error, driver exits abnormally.
  120. **/
  121. EFI_STATUS
  122. EFIAPI
  123. GopPolicyInitDxe (
  124. IN EFI_HANDLE ImageHandle
  125. )
  126. {
  127. EFI_STATUS Status;
  128. //
  129. // Initialize the EFI Driver Library
  130. //
  131. SetMem (&mGOPPolicy, sizeof (GOP_POLICY_PROTOCOL), 0);
  132. mGOPPolicy.Revision = GOP_POLICY_PROTOCOL_REVISION_03;
  133. mGOPPolicy.GetPlatformLidStatus = GetPlatformLidStatus;
  134. mGOPPolicy.GetVbtData = GetVbtData;
  135. mGOPPolicy.GetPlatformDockStatus = GetPlatformDockStatus;
  136. //
  137. // Install protocol to allow access to this Policy.
  138. //
  139. Status = gBS->InstallMultipleProtocolInterfaces (
  140. &ImageHandle,
  141. &gGopPolicyProtocolGuid,
  142. &mGOPPolicy,
  143. NULL
  144. );
  145. return Status;
  146. }