2 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
3 SPDX-License-Identifier: BSD-2-Clause-Patent
11 This is the driver that locates the MemoryConfigurationData HOB, if it
12 exists, and saves the data to nvRAM.
18 #include "SaveMemoryConfig.h"
20 CHAR16 EfiMemoryConfigVariable
[] = L
"MemoryConfig";
25 SaveMemoryConfigEntryPoint (
26 IN EFI_HANDLE ImageHandle
,
27 IN EFI_SYSTEM_TABLE
*SystemTable
32 This is the standard EFI driver point that detects whether there is a
33 MemoryConfigurationData HOB and, if so, saves its data to nvRAM.
36 ImageHandle - Handle for the image of this driver
37 SystemTable - Pointer to the EFI System Table
40 EFI_SUCCESS - if the data is successfully saved or there was no data
41 EFI_NOT_FOUND - if the HOB list could not be located.
42 EFI_UNLOAD_IMAGE - It is not success
46 EFI_STATUS Status
=EFI_SUCCESS
;
51 EFI_PLATFORM_SETUP_ID
*BootModeBuffer
;
52 EFI_PLATFORM_INFO_HOB
*PlatformInfoHobPtr
;
53 MEM_INFO_PROTOCOL
*MemInfoProtocol
;
61 BootModeBuffer
= NULL
;
63 PlatformInfoHobPtr
= NULL
;
67 // Get Platform Info HOB
69 GuidHob
= GetFirstGuidHob (&gEfiPlatformInfoGuid
);
70 if (GuidHob
== NULL
) {
71 Status
= EFI_NOT_FOUND
;
73 ASSERT_EFI_ERROR (Status
);
75 PlatformInfoHobPtr
= GET_GUID_HOB_DATA (GuidHob
);
78 // Get the BootMode guid hob
80 GuidHob
= GetFirstGuidHob (&gEfiPlatformBootModeGuid
);
81 if (GuidHob
== NULL
) {
82 Status
= EFI_NOT_FOUND
;
84 ASSERT_EFI_ERROR (Status
);
86 BootModeBuffer
= GET_GUID_HOB_DATA (GuidHob
);
90 // Check whether in Manufacturing Mode
93 if ( !CompareMem ( //EfiCompareMem
94 &BootModeBuffer
->SetupName
,
95 MANUFACTURE_SETUP_NAME
,
96 StrSize (MANUFACTURE_SETUP_NAME
) //EfiStrSize
104 // Don't save Memory Configuration in Manufacturing Mode. Clear memory configuration.
106 Status
= gRT
->SetVariable (
107 EfiMemoryConfigVariable
,
108 &gEfiVlv2VariableGuid
,
109 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
115 MemInfoProtocol
= (MEM_INFO_PROTOCOL
*)AllocateZeroPool(sizeof(MEM_INFO_PROTOCOL
));
116 if (PlatformInfoHobPtr
!= NULL
) {
117 MemInfoProtocol
->MemInfoData
.memSize
= 0;
118 for (Channel
= 0; Channel
< CH_NUM
; Channel
++){
119 for (Slot
= 0; Slot
< DIMM_NUM
; Slot
++){
120 MemInfoProtocol
->MemInfoData
.dimmSize
[Slot
+ (Channel
* DIMM_NUM
)] = PlatformInfoHobPtr
->MemData
.DimmSize
[Slot
+ (Channel
* DIMM_NUM
)];
123 MemInfoProtocol
->MemInfoData
.memSize
= PlatformInfoHobPtr
->MemData
.MemSize
;
124 MemInfoProtocol
->MemInfoData
.EccSupport
= PlatformInfoHobPtr
->MemData
.EccSupport
;
125 MemInfoProtocol
->MemInfoData
.ddrFreq
= PlatformInfoHobPtr
->MemData
.DdrFreq
;
126 MemInfoProtocol
->MemInfoData
.ddrType
= PlatformInfoHobPtr
->MemData
.DdrType
;
127 if (MemInfoProtocol
->MemInfoData
.memSize
== 0){
129 // We hardcode if MRC didn't fill these info in
131 MemInfoProtocol
->MemInfoData
.memSize
= 0x800; //per 1MB
132 MemInfoProtocol
->MemInfoData
.dimmSize
[0] = 0x800;
133 MemInfoProtocol
->MemInfoData
.dimmSize
[1] = 0;
134 MemInfoProtocol
->MemInfoData
.EccSupport
= FALSE
;
135 MemInfoProtocol
->MemInfoData
.ddrType
= 5; //DDRType_LPDDR3
138 Status
= gBS
->InstallMultipleProtocolInterfaces (
140 &gMemInfoProtocolGuid
,
146 Status
= EFI_SUCCESS
;
147 if (BOOT_WITH_MINIMAL_CONFIGURATION
!= GetBootModeHob()){
149 // Get the Memory Config guid hob
151 GuidHob
= GetFirstGuidHob (&gEfiMemoryConfigDataGuid
);
152 if (GuidHob
== NULL
) {
153 Status
= EFI_NOT_FOUND
;
155 ASSERT_EFI_ERROR (Status
);
157 MemHobData
= GET_GUID_HOB_DATA (GuidHob
);
158 BufferSize
= GET_GUID_HOB_DATA_SIZE (GuidHob
);
160 Status
= gRT
->GetVariable (
161 EfiMemoryConfigVariable
,
162 &gEfiVlv2VariableGuid
,
167 if (EFI_ERROR(Status
) && (MemHobData
!= NULL
)) {
168 Status
= gRT
->SetVariable (
169 EfiMemoryConfigVariable
,
170 &gEfiVlv2VariableGuid
,
171 (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
),