3 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php.
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/BaseLib.h>
17 #include <Library/MemoryAllocationLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
19 #include <Library/SmmServicesTableLib.h>
20 #include <Library/DevicePathLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/DebugLib.h>
23 #include <Protocol/SmmCommunication.h>
25 #include <Guid/MemoryProfile.h>
27 EFI_SMM_COMMUNICATION_PROTOCOL
*mSmmCommunication
= NULL
;
30 Get the GUID file name from the file path.
32 @param FilePath File path.
34 @return The GUID file name from the file path.
38 GetFileNameFromFilePath (
39 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
42 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*ThisFilePath
;
44 ThisFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) FilePath
;
45 while (!IsDevicePathEnd (ThisFilePath
)) {
46 if ((DevicePathType (ThisFilePath
) == MEDIA_DEVICE_PATH
) && (DevicePathSubType (ThisFilePath
) == MEDIA_PIWG_FW_FILE_DP
)) {
47 return &ThisFilePath
->FvFileName
;
49 ThisFilePath
= (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH
*) NextDevicePathNode (ThisFilePath
);
56 Register SMM image to SMRAM profile.
58 @param[in] FilePath File path of the image.
59 @param[in] ImageBuffer Image base address.
60 @param[in] NumberOfPage Number of page.
62 @retval TRUE Register success.
63 @retval FALSE Register fail.
67 RegisterSmramProfileImage (
68 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
69 IN PHYSICAL_ADDRESS ImageBuffer
,
76 UINT8 CommBuffer
[sizeof (EFI_GUID
) + sizeof (UINTN
) + sizeof (SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE
)];
77 EFI_SMM_COMMUNICATE_HEADER
*CommHeader
;
78 SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE
*CommRegisterImage
;
80 if ((PcdGet8 (PcdMemoryProfilePropertyMask
) & BIT1
) == 0) {
84 FileName
= GetFileNameFromFilePath (FilePath
);
86 if (mSmmCommunication
== NULL
) {
87 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &mSmmCommunication
);
88 ASSERT_EFI_ERROR (Status
);
91 CommHeader
= (EFI_SMM_COMMUNICATE_HEADER
*) &CommBuffer
[0];
92 CopyMem (&CommHeader
->HeaderGuid
, &gEdkiiMemoryProfileGuid
, sizeof (gEdkiiMemoryProfileGuid
));
93 CommHeader
->MessageLength
= sizeof (SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE
);
95 CommRegisterImage
= (SMRAM_PROFILE_PARAMETER_REGISTER_IMAGE
*)&CommBuffer
[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
)];
96 CommRegisterImage
->Header
.Command
= SMRAM_PROFILE_COMMAND_REGISTER_IMAGE
;
97 CommRegisterImage
->Header
.DataLength
= sizeof (*CommRegisterImage
);
98 CommRegisterImage
->Header
.ReturnStatus
= (UINT64
)-1;
99 CopyMem (&CommRegisterImage
->FileName
, FileName
, sizeof(EFI_GUID
));
100 CommRegisterImage
->ImageBuffer
= ImageBuffer
;
101 CommRegisterImage
->NumberOfPage
= NumberOfPage
;
103 CommSize
= sizeof (EFI_GUID
) + sizeof (UINTN
) + CommHeader
->MessageLength
;
104 Status
= mSmmCommunication
->Communicate (mSmmCommunication
, CommBuffer
, &CommSize
);
105 ASSERT_EFI_ERROR (Status
);
107 if (CommRegisterImage
->Header
.ReturnStatus
!= 0) {
115 Unregister SMM image from SMRAM profile.
117 @param[in] FilePath File path of the image.
118 @param[in] ImageBuffer Image base address.
119 @param[in] NumberOfPage Number of page.
121 @retval TRUE Unregister success.
122 @retval FALSE Unregister fail.
126 UnregisterSmramProfileImage (
127 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
,
128 IN PHYSICAL_ADDRESS ImageBuffer
,
129 IN UINTN NumberOfPage
135 UINT8 CommBuffer
[sizeof (EFI_GUID
) + sizeof (UINTN
) + sizeof (SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE
)];
136 EFI_SMM_COMMUNICATE_HEADER
*CommHeader
;
137 SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE
*CommUnregisterImage
;
139 if ((PcdGet8 (PcdMemoryProfilePropertyMask
) & BIT1
) == 0) {
143 FileName
= GetFileNameFromFilePath (FilePath
);
145 if (mSmmCommunication
== NULL
) {
146 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &mSmmCommunication
);
147 ASSERT_EFI_ERROR (Status
);
150 CommHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)&CommBuffer
[0];
151 CopyMem (&CommHeader
->HeaderGuid
, &gEdkiiMemoryProfileGuid
, sizeof(gEdkiiMemoryProfileGuid
));
152 CommHeader
->MessageLength
= sizeof(SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE
);
154 CommUnregisterImage
= (SMRAM_PROFILE_PARAMETER_UNREGISTER_IMAGE
*)&CommBuffer
[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
)];
155 CommUnregisterImage
->Header
.Command
= SMRAM_PROFILE_COMMAND_UNREGISTER_IMAGE
;
156 CommUnregisterImage
->Header
.DataLength
= sizeof (*CommUnregisterImage
);
157 CommUnregisterImage
->Header
.ReturnStatus
= (UINT64
)-1;
158 CopyMem (&CommUnregisterImage
->FileName
, FileName
, sizeof(EFI_GUID
));
159 CommUnregisterImage
->ImageBuffer
= ImageBuffer
;
160 CommUnregisterImage
->NumberOfPage
= NumberOfPage
;
162 CommSize
= sizeof (EFI_GUID
) + sizeof (UINTN
) + CommHeader
->MessageLength
;
163 Status
= mSmmCommunication
->Communicate (mSmmCommunication
, CommBuffer
, &CommSize
);
164 ASSERT_EFI_ERROR (Status
);
166 if (CommUnregisterImage
->Header
.ReturnStatus
!= 0) {