2 SMM Access2 Protocol on SMM Access Protocol Thunk driver.
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "SmmAccess2OnSmmAccessThunk.h"
17 EFI_SMM_ACCESS2_PROTOCOL gSmmAccess2
= {
21 SmmAccess2GetCapabilities
,
26 EFI_SMM_ACCESS_PROTOCOL
*mSmmAccess
;
27 UINTN mSmramRegionNumber
;
30 Opens the SMRAM area to be accessible by a boot-service driver.
32 This function "opens" SMRAM so that it is visible while not inside of SMM. The function should
33 return EFI_UNSUPPORTED if the hardware does not support hiding of SMRAM. The function
34 should return EFI_DEVICE_ERROR if the SMRAM configuration is locked.
36 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
38 @retval EFI_SUCCESS The operation was successful.
39 @retval EFI_UNSUPPORTED The system does not support opening and closing of SMRAM.
40 @retval EFI_DEVICE_ERROR SMRAM cannot be opened, perhaps because it is locked.
45 IN EFI_SMM_ACCESS2_PROTOCOL
*This
49 UINTN DescriptorIndex
;
52 /// Open all SMRAM regions via SMM Access Protocol
56 for (DescriptorIndex
= 0; DescriptorIndex
< mSmramRegionNumber
&& !EFI_ERROR (Status
); DescriptorIndex
++) {
57 Status
= mSmmAccess
->Open (mSmmAccess
, DescriptorIndex
);
59 if (!EFI_ERROR (Status
)) {
60 gSmmAccess2
.OpenState
= TRUE
;
66 Inhibits access to the SMRAM.
68 This function "closes" SMRAM so that it is not visible while outside of SMM. The function should
69 return EFI_UNSUPPORTED if the hardware does not support hiding of SMRAM.
71 @param [in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
73 @retval EFI_SUCCESS The operation was successful.
74 @retval EFI_UNSUPPORTED The system does not support opening and closing of SMRAM.
75 @retval EFI_DEVICE_ERROR SMRAM cannot be closed.
80 IN EFI_SMM_ACCESS2_PROTOCOL
*This
84 UINTN DescriptorIndex
;
87 /// Close all SMRAM regions via SMM Access Protocol
91 for (DescriptorIndex
= 0; DescriptorIndex
< mSmramRegionNumber
&& !EFI_ERROR (Status
); DescriptorIndex
++) {
92 Status
= mSmmAccess
->Close (mSmmAccess
, DescriptorIndex
);
94 if (!EFI_ERROR (Status
)) {
95 gSmmAccess2
.OpenState
= FALSE
;
101 Inhibits access to the SMRAM.
103 This function prohibits access to the SMRAM region. This function is usually implemented such
104 that it is a write-once operation.
106 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
108 @retval EFI_SUCCESS The device was successfully locked.
109 @retval EFI_UNSUPPORTED The system does not support locking of SMRAM.
114 IN EFI_SMM_ACCESS2_PROTOCOL
*This
118 UINTN DescriptorIndex
;
121 /// Lock all SMRAM regions via SMM Access Protocol
124 Status
= EFI_SUCCESS
;
125 for (DescriptorIndex
= 0; DescriptorIndex
< mSmramRegionNumber
&& !EFI_ERROR (Status
); DescriptorIndex
++) {
126 Status
= mSmmAccess
->Lock (mSmmAccess
, DescriptorIndex
);
128 if (!EFI_ERROR (Status
)) {
129 gSmmAccess2
.LockState
= TRUE
;
135 Queries the memory controller for the possible regions that will support SMRAM.
137 @param[in] This The EFI_SMM_ACCESS2_PROTOCOL instance.
138 @param[in, out] SmramMapSize A pointer to the size, in bytes, of the SmramMemoryMap buffer.
139 @param[in, out] SmramMap A pointer to the buffer in which firmware places the current memory map.
141 @retval EFI_SUCCESS The chipset supported the given resource.
142 @retval EFI_BUFFER_TOO_SMALL The SmramMap parameter was too small. The current buffer size
143 needed to hold the memory map is returned in SmramMapSize.
147 SmmAccess2GetCapabilities (
148 IN CONST EFI_SMM_ACCESS2_PROTOCOL
*This
,
149 IN OUT UINTN
*SmramMapSize
,
150 IN OUT EFI_SMRAM_DESCRIPTOR
*SmramMap
153 return mSmmAccess
->GetCapabilities (mSmmAccess
, SmramMapSize
, SmramMap
);
157 Entry Point for SMM Access2 On SMM Access Thunk driver.
159 @param[in] ImageHandle Image handle of this driver.
160 @param[in] SystemTable A Pointer to the EFI System Table.
162 @retval EFI_SUCCESS The entry point is executed successfully.
163 @retval other Some error occurred when executing this entry point.
167 SmmAccess2ThunkMain (
168 IN EFI_HANDLE ImageHandle
,
169 IN EFI_SYSTEM_TABLE
*SystemTable
176 /// Locate SMM Access Protocol
178 Status
= gBS
->LocateProtocol (&gEfiSmmAccessProtocolGuid
, NULL
, (VOID
**)&mSmmAccess
);
179 ASSERT_EFI_ERROR (Status
);
182 /// Calculate number of SMRAM regions
185 Status
= mSmmAccess
->GetCapabilities (mSmmAccess
, &SmramMapSize
, NULL
);
186 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
188 mSmramRegionNumber
= SmramMapSize
/sizeof (EFI_SMRAM_DESCRIPTOR
);
189 ASSERT (mSmramRegionNumber
> 0);
192 /// Assume all SMRAM regions have consistent OPEN and LOCK states
194 gSmmAccess2
.OpenState
= mSmmAccess
->OpenState
;
195 gSmmAccess2
.LockState
= mSmmAccess
->LockState
;
198 /// Publish PI SMM Access2 Protocol
200 Status
= gBS
->InstallProtocolInterface (
202 &gEfiSmmAccess2ProtocolGuid
,
203 EFI_NATIVE_INTERFACE
,