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 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/DebugLib.h>
18 #include <Library/HobLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Library/UefiRuntimeServicesTableLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/UefiDriverEntryPoint.h>
25 #include <Guid/MemoryConfigData.h>
26 #include <Guid/DebugMask.h>
30 SaveMemoryConfigEntryPoint (
31 IN EFI_HANDLE ImageHandle
,
32 IN EFI_SYSTEM_TABLE
*SystemTable
37 This is the standard EFI driver point that detects whether there is a
38 MemoryConfigurationData HOB and, if so, saves its data to nvRAM.
41 ImageHandle - Handle for the image of this driver
42 SystemTable - Pointer to the EFI System Table
45 EFI_SUCCESS - if the data is successfully saved or there was no data
46 EFI_NOT_FOUND - if the HOB list could not be located.
47 EFI_UNLOAD_IMAGE - It is not success
53 EFI_HOB_GUID_TYPE
*GuidHob
;
64 Status
= EFI_UNSUPPORTED
;
67 // Get the HOB list. If it is not present, then ASSERT.
69 HobList
= GetHobList ();
70 ASSERT (HobList
!= NULL
);
73 // Search for the Memory Configuration GUID HOB. If it is not present, then
74 // there's nothing we can do. It may not exist on the update path.
76 GuidHob
= GetNextGuidHob (&gEfiMemoryConfigDataGuid
, HobList
);
77 if (GuidHob
!= NULL
) {
78 HobData
= GET_GUID_HOB_DATA (GuidHob
);
79 DataSize
= GET_GUID_HOB_DATA_SIZE (GuidHob
);
81 // Use the HOB to save Memory Configuration Data
83 BufferSize
= DataSize
;
84 VariableData
= AllocatePool (BufferSize
);
85 ASSERT (VariableData
!= NULL
);
86 Status
= gRT
->GetVariable (
87 EFI_MEMORY_CONFIG_DATA_NAME
,
88 &gEfiMemoryConfigDataGuid
,
93 if (Status
== EFI_BUFFER_TOO_SMALL
) {
94 gBS
->FreePool (VariableData
);
95 VariableData
= AllocatePool (BufferSize
);
96 ASSERT (VariableData
!= NULL
);
97 Status
= gRT
->GetVariable (
98 EFI_MEMORY_CONFIG_DATA_NAME
,
99 &gEfiMemoryConfigDataGuid
,
106 if (EFI_ERROR(Status
) || BufferSize
!= DataSize
|| CompareMem (HobData
, VariableData
, DataSize
) != 0) {
107 Status
= gRT
->SetVariable (
108 EFI_MEMORY_CONFIG_DATA_NAME
,
109 &gEfiMemoryConfigDataGuid
,
110 (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
),
114 ASSERT((Status
== EFI_SUCCESS
) || (Status
== EFI_OUT_OF_RESOURCES
));
117 gBS
->FreePool (VariableData
);
121 // This driver does not produce any protocol services, so always unload it.