SmmAccess2Dxe.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /** @file
  2. A DXE_DRIVER providing SMRAM access by producing EFI_SMM_ACCESS2_PROTOCOL.
  3. Q35 TSEG is expected to have been verified and set up by the SmmAccessPei
  4. driver.
  5. Copyright (C) 2013, 2015, Red Hat, Inc.<BR>
  6. Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
  7. SPDX-License-Identifier: BSD-2-Clause-Patent
  8. **/
  9. #include <Library/DebugLib.h>
  10. #include <Library/PcdLib.h>
  11. #include <Library/UefiBootServicesTableLib.h>
  12. #include <Protocol/SmmAccess2.h>
  13. #include "SmramInternal.h"
  14. /**
  15. Opens the SMRAM area to be accessible by a boot-service driver.
  16. This function "opens" SMRAM so that it is visible while not inside of SMM.
  17. The function should return EFI_UNSUPPORTED if the hardware does not support
  18. hiding of SMRAM. The function should return EFI_DEVICE_ERROR if the SMRAM
  19. configuration is locked.
  20. @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
  21. @retval EFI_SUCCESS The operation was successful.
  22. @retval EFI_UNSUPPORTED The system does not support opening and closing of
  23. SMRAM.
  24. @retval EFI_DEVICE_ERROR SMRAM cannot be opened, perhaps because it is
  25. locked.
  26. **/
  27. STATIC
  28. EFI_STATUS
  29. EFIAPI
  30. SmmAccess2DxeOpen (
  31. IN EFI_SMM_ACCESS2_PROTOCOL *This
  32. )
  33. {
  34. return SmramAccessOpen (&This->LockState, &This->OpenState);
  35. }
  36. /**
  37. Inhibits access to the SMRAM.
  38. This function "closes" SMRAM so that it is not visible while outside of SMM.
  39. The function should return EFI_UNSUPPORTED if the hardware does not support
  40. hiding of SMRAM.
  41. @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
  42. @retval EFI_SUCCESS The operation was successful.
  43. @retval EFI_UNSUPPORTED The system does not support opening and closing of
  44. SMRAM.
  45. @retval EFI_DEVICE_ERROR SMRAM cannot be closed.
  46. **/
  47. STATIC
  48. EFI_STATUS
  49. EFIAPI
  50. SmmAccess2DxeClose (
  51. IN EFI_SMM_ACCESS2_PROTOCOL *This
  52. )
  53. {
  54. return SmramAccessClose (&This->LockState, &This->OpenState);
  55. }
  56. /**
  57. Inhibits access to the SMRAM.
  58. This function prohibits access to the SMRAM region. This function is usually
  59. implemented such that it is a write-once operation.
  60. @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
  61. @retval EFI_SUCCESS The device was successfully locked.
  62. @retval EFI_UNSUPPORTED The system does not support locking of SMRAM.
  63. **/
  64. STATIC
  65. EFI_STATUS
  66. EFIAPI
  67. SmmAccess2DxeLock (
  68. IN EFI_SMM_ACCESS2_PROTOCOL *This
  69. )
  70. {
  71. return SmramAccessLock (&This->LockState, &This->OpenState);
  72. }
  73. /**
  74. Queries the memory controller for the possible regions that will support
  75. SMRAM.
  76. @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
  77. @param[in,out] SmramMapSize A pointer to the size, in bytes, of the
  78. SmramMemoryMap buffer.
  79. @param[in,out] SmramMap A pointer to the buffer in which firmware
  80. places the current memory map.
  81. @retval EFI_SUCCESS The chipset supported the given resource.
  82. @retval EFI_BUFFER_TOO_SMALL The SmramMap parameter was too small. The
  83. current buffer size needed to hold the memory
  84. map is returned in SmramMapSize.
  85. **/
  86. STATIC
  87. EFI_STATUS
  88. EFIAPI
  89. SmmAccess2DxeGetCapabilities (
  90. IN CONST EFI_SMM_ACCESS2_PROTOCOL *This,
  91. IN OUT UINTN *SmramMapSize,
  92. IN OUT EFI_SMRAM_DESCRIPTOR *SmramMap
  93. )
  94. {
  95. return SmramAccessGetCapabilities (
  96. This->LockState,
  97. This->OpenState,
  98. SmramMapSize,
  99. SmramMap
  100. );
  101. }
  102. //
  103. // LockState and OpenState will be filled in by the entry point.
  104. //
  105. STATIC EFI_SMM_ACCESS2_PROTOCOL mAccess2 = {
  106. &SmmAccess2DxeOpen,
  107. &SmmAccess2DxeClose,
  108. &SmmAccess2DxeLock,
  109. &SmmAccess2DxeGetCapabilities
  110. };
  111. //
  112. // Entry point of this driver.
  113. //
  114. EFI_STATUS
  115. EFIAPI
  116. SmmAccess2DxeEntryPoint (
  117. IN EFI_HANDLE ImageHandle,
  118. IN EFI_SYSTEM_TABLE *SystemTable
  119. )
  120. {
  121. //
  122. // This module should only be included if SMRAM support is required.
  123. //
  124. ASSERT (FeaturePcdGet (PcdSmmSmramRequire));
  125. InitQ35TsegMbytes ();
  126. GetStates (&mAccess2.LockState, &mAccess2.OpenState);
  127. //
  128. // SmramAccessLock() depends on "mQ35SmramAtDefaultSmbase"; init the latter
  129. // just before exposing the former via EFI_SMM_ACCESS2_PROTOCOL.Lock().
  130. //
  131. InitQ35SmramAtDefaultSmbase ();
  132. return gBS->InstallMultipleProtocolInterfaces (
  133. &ImageHandle,
  134. &gEfiSmmAccess2ProtocolGuid,
  135. &mAccess2,
  136. NULL
  137. );
  138. }