2 This is the driver that locates the MemoryConfigurationData HOB, if it
3 exists, and saves the data to nvRAM.
5 Copyright (c) 2013-2015 Intel Corporation.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/DebugLib.h>
12 #include <Library/HobLib.h>
13 #include <Library/MemoryAllocationLib.h>
14 #include <Library/UefiBootServicesTableLib.h>
15 #include <Library/UefiRuntimeServicesTableLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/UefiDriverEntryPoint.h>
19 #include <Guid/MemoryConfigData.h>
20 #include <Guid/DebugMask.h>
24 SaveMemoryConfigEntryPoint (
25 IN EFI_HANDLE ImageHandle
,
26 IN EFI_SYSTEM_TABLE
*SystemTable
31 This is the standard EFI driver point that detects whether there is a
32 MemoryConfigurationData HOB and, if so, saves its data to nvRAM.
35 ImageHandle - Handle for the image of this driver
36 SystemTable - Pointer to the EFI System Table
39 EFI_SUCCESS - if the data is successfully saved or there was no data
40 EFI_NOT_FOUND - if the HOB list could not be located.
41 EFI_UNLOAD_IMAGE - It is not success
47 EFI_HOB_GUID_TYPE
*GuidHob
;
58 Status
= EFI_UNSUPPORTED
;
61 // Get the HOB list. If it is not present, then ASSERT.
63 HobList
= GetHobList ();
64 ASSERT (HobList
!= NULL
);
67 // Search for the Memory Configuration GUID HOB. If it is not present, then
68 // there's nothing we can do. It may not exist on the update path.
70 GuidHob
= GetNextGuidHob (&gEfiMemoryConfigDataGuid
, HobList
);
71 if (GuidHob
!= NULL
) {
72 HobData
= GET_GUID_HOB_DATA (GuidHob
);
73 DataSize
= GET_GUID_HOB_DATA_SIZE (GuidHob
);
75 // Use the HOB to save Memory Configuration Data
77 BufferSize
= DataSize
;
78 VariableData
= AllocatePool (BufferSize
);
79 ASSERT (VariableData
!= NULL
);
80 Status
= gRT
->GetVariable (
81 EFI_MEMORY_CONFIG_DATA_NAME
,
82 &gEfiMemoryConfigDataGuid
,
87 if (Status
== EFI_BUFFER_TOO_SMALL
) {
88 gBS
->FreePool (VariableData
);
89 VariableData
= AllocatePool (BufferSize
);
90 ASSERT (VariableData
!= NULL
);
91 Status
= gRT
->GetVariable (
92 EFI_MEMORY_CONFIG_DATA_NAME
,
93 &gEfiMemoryConfigDataGuid
,
100 if (EFI_ERROR(Status
) || BufferSize
!= DataSize
|| CompareMem (HobData
, VariableData
, DataSize
) != 0) {
101 Status
= gRT
->SetVariable (
102 EFI_MEMORY_CONFIG_DATA_NAME
,
103 &gEfiMemoryConfigDataGuid
,
104 (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
),
108 ASSERT((Status
== EFI_SUCCESS
) || (Status
== EFI_OUT_OF_RESOURCES
));
111 gBS
->FreePool (VariableData
);
115 // This driver does not produce any protocol services, so always unload it.