3 A DXE_DRIVER providing SMRAM access by producing EFI_SMM_ACCESS2_PROTOCOL.
5 Q35 TSEG is expected to have been verified and set up by the SmmAccessPei
8 Copyright (C) 2013, 2015, Red Hat, Inc.<BR>
9 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
11 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #include <Library/DebugLib.h>
16 #include <Library/PcdLib.h>
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Protocol/SmmAccess2.h>
20 #include "SmramInternal.h"
23 Opens the SMRAM area to be accessible by a boot-service driver.
25 This function "opens" SMRAM so that it is visible while not inside of SMM.
26 The function should return EFI_UNSUPPORTED if the hardware does not support
27 hiding of SMRAM. The function should return EFI_DEVICE_ERROR if the SMRAM
28 configuration is locked.
30 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
32 @retval EFI_SUCCESS The operation was successful.
33 @retval EFI_UNSUPPORTED The system does not support opening and closing of
35 @retval EFI_DEVICE_ERROR SMRAM cannot be opened, perhaps because it is
42 IN EFI_SMM_ACCESS2_PROTOCOL
*This
45 return SmramAccessOpen (&This
->LockState
, &This
->OpenState
);
49 Inhibits access to the SMRAM.
51 This function "closes" SMRAM so that it is not visible while outside of SMM.
52 The function should return EFI_UNSUPPORTED if the hardware does not support
55 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
57 @retval EFI_SUCCESS The operation was successful.
58 @retval EFI_UNSUPPORTED The system does not support opening and closing of
60 @retval EFI_DEVICE_ERROR SMRAM cannot be closed.
66 IN EFI_SMM_ACCESS2_PROTOCOL
*This
69 return SmramAccessClose (&This
->LockState
, &This
->OpenState
);
73 Inhibits access to the SMRAM.
75 This function prohibits access to the SMRAM region. This function is usually
76 implemented such that it is a write-once operation.
78 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
80 @retval EFI_SUCCESS The device was successfully locked.
81 @retval EFI_UNSUPPORTED The system does not support locking of SMRAM.
87 IN EFI_SMM_ACCESS2_PROTOCOL
*This
90 return SmramAccessLock (&This
->LockState
, &This
->OpenState
);
94 Queries the memory controller for the possible regions that will support
97 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
98 @param[in,out] SmramMapSize A pointer to the size, in bytes, of the
99 SmramMemoryMap buffer.
100 @param[in,out] SmramMap A pointer to the buffer in which firmware
101 places the current memory map.
103 @retval EFI_SUCCESS The chipset supported the given resource.
104 @retval EFI_BUFFER_TOO_SMALL The SmramMap parameter was too small. The
105 current buffer size needed to hold the memory
106 map is returned in SmramMapSize.
111 SmmAccess2DxeGetCapabilities (
112 IN CONST EFI_SMM_ACCESS2_PROTOCOL
*This
,
113 IN OUT UINTN
*SmramMapSize
,
114 IN OUT EFI_SMRAM_DESCRIPTOR
*SmramMap
117 return SmramAccessGetCapabilities (This
->LockState
, This
->OpenState
,
118 SmramMapSize
, SmramMap
);
122 // LockState and OpenState will be filled in by the entry point.
124 STATIC EFI_SMM_ACCESS2_PROTOCOL mAccess2
= {
128 &SmmAccess2DxeGetCapabilities
132 // Entry point of this driver.
136 SmmAccess2DxeEntryPoint (
137 IN EFI_HANDLE ImageHandle
,
138 IN EFI_SYSTEM_TABLE
*SystemTable
142 // This module should only be included if SMRAM support is required.
144 ASSERT (FeaturePcdGet (PcdSmmSmramRequire
));
146 InitQ35TsegMbytes ();
147 GetStates (&mAccess2
.LockState
, &mAccess2
.OpenState
);
150 // SmramAccessLock() depends on "mQ35SmramAtDefaultSmbase"; init the latter
151 // just before exposing the former via EFI_SMM_ACCESS2_PROTOCOL.Lock().
153 InitQ35SmramAtDefaultSmbase ();
155 return gBS
->InstallMultipleProtocolInterfaces (&ImageHandle
,
156 &gEfiSmmAccess2ProtocolGuid
, &mAccess2
,