]> git.proxmox.com Git - mirror_edk2.git/blob - Vlv2TbltDevicePkg/SaveMemoryConfig/SaveMemoryConfig.c
ArmPkg/CompilerIntrinsicsLib: Add uread, uwrite GCC assembly sources
[mirror_edk2.git] / Vlv2TbltDevicePkg / SaveMemoryConfig / SaveMemoryConfig.c
1 /**
2 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
3 SPDX-License-Identifier: BSD-2-Clause-Patent
4
5
6 Module Name:
7
8 SaveMemoryConfig.c
9
10 Abstract:
11 This is the driver that locates the MemoryConfigurationData HOB, if it
12 exists, and saves the data to nvRAM.
13
14
15
16 --*/
17
18 #include "SaveMemoryConfig.h"
19
20 CHAR16 EfiMemoryConfigVariable[] = L"MemoryConfig";
21
22
23 EFI_STATUS
24 EFIAPI
25 SaveMemoryConfigEntryPoint (
26 IN EFI_HANDLE ImageHandle,
27 IN EFI_SYSTEM_TABLE *SystemTable
28 )
29 /*++
30
31 Routine Description:
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.
34
35 Arguments:
36 ImageHandle - Handle for the image of this driver
37 SystemTable - Pointer to the EFI System Table
38
39 Returns:
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
43
44 --*/
45 {
46 EFI_STATUS Status=EFI_SUCCESS;
47 VOID *MemHobData;
48 VOID *VariableData;
49 UINTN BufferSize;
50 BOOLEAN MfgMode;
51 EFI_PLATFORM_SETUP_ID *BootModeBuffer;
52 EFI_PLATFORM_INFO_HOB *PlatformInfoHobPtr;
53 MEM_INFO_PROTOCOL *MemInfoProtocol;
54 EFI_HANDLE Handle;
55 UINT8 Channel, Slot;
56 VOID *GuidHob;
57
58 VariableData = NULL;
59 MfgMode = FALSE;
60 Handle = NULL;
61 BootModeBuffer = NULL;
62 MemHobData = NULL;
63 PlatformInfoHobPtr = NULL;
64 BufferSize = 0;
65
66 //
67 // Get Platform Info HOB
68 //
69 GuidHob = GetFirstGuidHob (&gEfiPlatformInfoGuid);
70 if (GuidHob == NULL) {
71 Status = EFI_NOT_FOUND;
72 }
73 ASSERT_EFI_ERROR (Status);
74
75 PlatformInfoHobPtr = GET_GUID_HOB_DATA (GuidHob);
76
77 //
78 // Get the BootMode guid hob
79 //
80 GuidHob = GetFirstGuidHob (&gEfiPlatformBootModeGuid);
81 if (GuidHob == NULL) {
82 Status = EFI_NOT_FOUND;
83 }
84 ASSERT_EFI_ERROR (Status);
85
86 BootModeBuffer = GET_GUID_HOB_DATA (GuidHob);
87
88
89 //
90 // Check whether in Manufacturing Mode
91 //
92 if (BootModeBuffer) {
93 if ( !CompareMem ( //EfiCompareMem
94 &BootModeBuffer->SetupName,
95 MANUFACTURE_SETUP_NAME,
96 StrSize (MANUFACTURE_SETUP_NAME) //EfiStrSize
97 ) ) {
98 MfgMode = TRUE;
99 }
100 }
101
102 if (MfgMode) {
103 //
104 // Don't save Memory Configuration in Manufacturing Mode. Clear memory configuration.
105 //
106 Status = gRT->SetVariable (
107 EfiMemoryConfigVariable,
108 &gEfiVlv2VariableGuid,
109 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
110 0,
111 NULL
112 );
113 } else {
114
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)];
121 }
122 }
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){
128 //
129 // We hardcode if MRC didn't fill these info in
130 //
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
136 }
137
138 Status = gBS->InstallMultipleProtocolInterfaces (
139 &Handle,
140 &gMemInfoProtocolGuid,
141 MemInfoProtocol,
142 NULL
143 );
144 }
145
146 Status = EFI_SUCCESS;
147 if (BOOT_WITH_MINIMAL_CONFIGURATION != GetBootModeHob()){
148 //
149 // Get the Memory Config guid hob
150 //
151 GuidHob = GetFirstGuidHob (&gEfiMemoryConfigDataGuid);
152 if (GuidHob == NULL) {
153 Status = EFI_NOT_FOUND;
154 }
155 ASSERT_EFI_ERROR (Status);
156
157 MemHobData = GET_GUID_HOB_DATA (GuidHob);
158 BufferSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
159
160 Status = gRT->GetVariable (
161 EfiMemoryConfigVariable,
162 &gEfiVlv2VariableGuid,
163 NULL,
164 &BufferSize,
165 VariableData
166 );
167 if (EFI_ERROR(Status) && (MemHobData != NULL)) {
168 Status = gRT->SetVariable (
169 EfiMemoryConfigVariable,
170 &gEfiVlv2VariableGuid,
171 (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS),
172 BufferSize,
173 MemHobData
174 );
175 }
176 }
177
178 } // if-else MfgMode
179
180 return EFI_SUCCESS;
181 }