2 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
3 This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 This is the driver that locates the MemoryConfigurationData HOB, if it
18 exists, and saves the data to nvRAM.
24 #include "SaveMemoryConfig.h"
26 CHAR16 EfiMemoryConfigVariable
[] = L
"MemoryConfig";
31 SaveMemoryConfigEntryPoint (
32 IN EFI_HANDLE ImageHandle
,
33 IN EFI_SYSTEM_TABLE
*SystemTable
38 This is the standard EFI driver point that detects whether there is a
39 MemoryConfigurationData HOB and, if so, saves its data to nvRAM.
42 ImageHandle - Handle for the image of this driver
43 SystemTable - Pointer to the EFI System Table
46 EFI_SUCCESS - if the data is successfully saved or there was no data
47 EFI_NOT_FOUND - if the HOB list could not be located.
48 EFI_UNLOAD_IMAGE - It is not success
52 EFI_STATUS Status
=EFI_SUCCESS
;
57 EFI_PLATFORM_SETUP_ID
*BootModeBuffer
;
58 EFI_PLATFORM_INFO_HOB
*PlatformInfoHobPtr
;
59 MEM_INFO_PROTOCOL
*MemInfoProtocol
;
67 BootModeBuffer
= NULL
;
69 PlatformInfoHobPtr
= NULL
;
73 // Get Platform Info HOB
75 GuidHob
= GetFirstGuidHob (&gEfiPlatformInfoGuid
);
76 if (GuidHob
== NULL
) {
77 Status
= EFI_NOT_FOUND
;
79 ASSERT_EFI_ERROR (Status
);
81 PlatformInfoHobPtr
= GET_GUID_HOB_DATA (GuidHob
);
84 // Get the BootMode guid hob
86 GuidHob
= GetFirstGuidHob (&gEfiPlatformBootModeGuid
);
87 if (GuidHob
== NULL
) {
88 Status
= EFI_NOT_FOUND
;
90 ASSERT_EFI_ERROR (Status
);
92 BootModeBuffer
= GET_GUID_HOB_DATA (GuidHob
);
96 // Check whether in Manufacturing Mode
99 if ( !CompareMem ( //EfiCompareMem
100 &BootModeBuffer
->SetupName
,
101 MANUFACTURE_SETUP_NAME
,
102 StrSize (MANUFACTURE_SETUP_NAME
) //EfiStrSize
110 // Don't save Memory Configuration in Manufacturing Mode. Clear memory configuration.
112 Status
= gRT
->SetVariable (
113 EfiMemoryConfigVariable
,
114 &gEfiVlv2VariableGuid
,
115 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
121 MemInfoProtocol
= (MEM_INFO_PROTOCOL
*)AllocateZeroPool(sizeof(MEM_INFO_PROTOCOL
));
122 if (PlatformInfoHobPtr
!= NULL
) {
123 MemInfoProtocol
->MemInfoData
.memSize
= 0;
124 for (Channel
= 0; Channel
< CH_NUM
; Channel
++){
125 for (Slot
= 0; Slot
< DIMM_NUM
; Slot
++){
126 MemInfoProtocol
->MemInfoData
.dimmSize
[Slot
+ (Channel
* DIMM_NUM
)] = PlatformInfoHobPtr
->MemData
.DimmSize
[Slot
+ (Channel
* DIMM_NUM
)];
129 MemInfoProtocol
->MemInfoData
.memSize
= PlatformInfoHobPtr
->MemData
.MemSize
;
130 MemInfoProtocol
->MemInfoData
.EccSupport
= PlatformInfoHobPtr
->MemData
.EccSupport
;
131 MemInfoProtocol
->MemInfoData
.ddrFreq
= PlatformInfoHobPtr
->MemData
.DdrFreq
;
132 MemInfoProtocol
->MemInfoData
.ddrType
= PlatformInfoHobPtr
->MemData
.DdrType
;
133 if (MemInfoProtocol
->MemInfoData
.memSize
== 0){
135 // We hardcode if MRC didn't fill these info in
137 MemInfoProtocol
->MemInfoData
.memSize
= 0x800; //per 1MB
138 MemInfoProtocol
->MemInfoData
.dimmSize
[0] = 0x800;
139 MemInfoProtocol
->MemInfoData
.dimmSize
[1] = 0;
140 MemInfoProtocol
->MemInfoData
.EccSupport
= FALSE
;
141 MemInfoProtocol
->MemInfoData
.ddrType
= 5; //DDRType_LPDDR3
144 Status
= gBS
->InstallMultipleProtocolInterfaces (
146 &gMemInfoProtocolGuid
,
152 Status
= EFI_SUCCESS
;
153 if (BOOT_WITH_MINIMAL_CONFIGURATION
!= GetBootModeHob()){
155 // Get the Memory Config guid hob
157 GuidHob
= GetFirstGuidHob (&gEfiMemoryConfigDataGuid
);
158 if (GuidHob
== NULL
) {
159 Status
= EFI_NOT_FOUND
;
161 ASSERT_EFI_ERROR (Status
);
163 MemHobData
= GET_GUID_HOB_DATA (GuidHob
);
164 BufferSize
= GET_GUID_HOB_DATA_SIZE (GuidHob
);
166 Status
= gRT
->GetVariable (
167 EfiMemoryConfigVariable
,
168 &gEfiVlv2VariableGuid
,
173 if (EFI_ERROR(Status
) && (MemHobData
!= NULL
)) {
174 Status
= gRT
->SetVariable (
175 EfiMemoryConfigVariable
,
176 &gEfiVlv2VariableGuid
,
177 (EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
),