]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/SaveMemoryConfig/SaveMemoryConfig.c
BaseTools/Capsule: Do not support -o with --dump-info
[mirror_edk2.git] / Vlv2TbltDevicePkg / SaveMemoryConfig / SaveMemoryConfig.c
CommitLineData
3cbfba02
DW
1/** \r
2 Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
3 This program and the accompanying materials\r
4 are licensed and made available under the terms and conditions of the BSD License\r
5 which accompanies this distribution. The full text of the license may be found at\r
6 http://opensource.org/licenses/bsd-license.php\r
7\r
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
10\r
11\r
12Module Name:\r
13\r
14 SaveMemoryConfig.c\r
15\r
16Abstract:\r
17 This is the driver that locates the MemoryConfigurationData HOB, if it\r
18 exists, and saves the data to nvRAM.\r
19\r
20 \r
21\r
22--*/\r
23\r
24#include "SaveMemoryConfig.h"\r
25\r
26CHAR16 EfiMemoryConfigVariable[] = L"MemoryConfig";\r
27\r
28\r
29EFI_STATUS\r
30EFIAPI\r
31SaveMemoryConfigEntryPoint (\r
32 IN EFI_HANDLE ImageHandle,\r
33 IN EFI_SYSTEM_TABLE *SystemTable\r
34 )\r
35/*++\r
36\r
37 Routine Description:\r
38 This is the standard EFI driver point that detects whether there is a\r
39 MemoryConfigurationData HOB and, if so, saves its data to nvRAM.\r
40\r
41 Arguments:\r
42 ImageHandle - Handle for the image of this driver\r
43 SystemTable - Pointer to the EFI System Table\r
44\r
45 Returns:\r
46 EFI_SUCCESS - if the data is successfully saved or there was no data\r
47 EFI_NOT_FOUND - if the HOB list could not be located.\r
48 EFI_UNLOAD_IMAGE - It is not success\r
49\r
50--*/\r
51{\r
52 EFI_STATUS Status=EFI_SUCCESS;\r
53 VOID *MemHobData;\r
54 VOID *VariableData;\r
55 UINTN BufferSize;\r
56 BOOLEAN MfgMode;\r
57 EFI_PLATFORM_SETUP_ID *BootModeBuffer;\r
58 EFI_PLATFORM_INFO_HOB *PlatformInfoHobPtr;\r
59 MEM_INFO_PROTOCOL *MemInfoProtocol;\r
60 EFI_HANDLE Handle;\r
61 UINT8 Channel, Slot;\r
62 VOID *GuidHob;\r
63\r
64 VariableData = NULL;\r
65 MfgMode = FALSE;\r
66 Handle = NULL;\r
67 BootModeBuffer = NULL;\r
68 MemHobData = NULL;\r
69 PlatformInfoHobPtr = NULL;\r
70 BufferSize = 0;\r
71\r
72 //\r
73 // Get Platform Info HOB\r
74 //\r
75 GuidHob = GetFirstGuidHob (&gEfiPlatformInfoGuid);\r
76 if (GuidHob == NULL) {\r
77 Status = EFI_NOT_FOUND;\r
78 }\r
79 ASSERT_EFI_ERROR (Status);\r
80\r
81 PlatformInfoHobPtr = GET_GUID_HOB_DATA (GuidHob);\r
82\r
83 //\r
84 // Get the BootMode guid hob\r
85 //\r
86 GuidHob = GetFirstGuidHob (&gEfiPlatformBootModeGuid);\r
87 if (GuidHob == NULL) {\r
88 Status = EFI_NOT_FOUND;\r
89 }\r
90 ASSERT_EFI_ERROR (Status);\r
91\r
92 BootModeBuffer = GET_GUID_HOB_DATA (GuidHob);\r
93\r
94\r
95 //\r
96 // Check whether in Manufacturing Mode\r
97 //\r
98 if (BootModeBuffer) {\r
99 if ( !CompareMem ( //EfiCompareMem\r
100 &BootModeBuffer->SetupName,\r
101 MANUFACTURE_SETUP_NAME,\r
102 StrSize (MANUFACTURE_SETUP_NAME) //EfiStrSize\r
103 ) ) {\r
104 MfgMode = TRUE;\r
105 }\r
106 }\r
107\r
108 if (MfgMode) {\r
109 //\r
110 // Don't save Memory Configuration in Manufacturing Mode. Clear memory configuration.\r
111 //\r
112 Status = gRT->SetVariable (\r
113 EfiMemoryConfigVariable,\r
114 &gEfiVlv2VariableGuid,\r
115 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
116 0,\r
117 NULL\r
118 ); \r
119 } else {\r
120\r
121 MemInfoProtocol = (MEM_INFO_PROTOCOL*)AllocateZeroPool(sizeof(MEM_INFO_PROTOCOL));\r
122 if (PlatformInfoHobPtr != NULL) {\r
123 MemInfoProtocol->MemInfoData.memSize = 0;\r
124 for (Channel = 0; Channel < CH_NUM; Channel ++){\r
125 for (Slot = 0; Slot < DIMM_NUM; Slot ++){ \r
6f2ef18e 126 MemInfoProtocol->MemInfoData.dimmSize[Slot + (Channel * DIMM_NUM)] = PlatformInfoHobPtr->MemData.DimmSize[Slot + (Channel * DIMM_NUM)];\r
3cbfba02
DW
127 }\r
128 }\r
129 MemInfoProtocol->MemInfoData.memSize = PlatformInfoHobPtr->MemData.MemSize; \r
130 MemInfoProtocol->MemInfoData.EccSupport = PlatformInfoHobPtr->MemData.EccSupport;\r
131 MemInfoProtocol->MemInfoData.ddrFreq = PlatformInfoHobPtr->MemData.DdrFreq;\r
132 MemInfoProtocol->MemInfoData.ddrType = PlatformInfoHobPtr->MemData.DdrType;\r
133 if (MemInfoProtocol->MemInfoData.memSize == 0){\r
134 //\r
135 // We hardcode if MRC didn't fill these info in\r
136 //\r
137 MemInfoProtocol->MemInfoData.memSize = 0x800; //per 1MB \r
138 MemInfoProtocol->MemInfoData.dimmSize[0] = 0x800;\r
139 MemInfoProtocol->MemInfoData.dimmSize[1] = 0; \r
140 MemInfoProtocol->MemInfoData.EccSupport = FALSE;\r
141 MemInfoProtocol->MemInfoData.ddrType = 5; //DDRType_LPDDR3\r
142 }\r
143\r
144 Status = gBS->InstallMultipleProtocolInterfaces (\r
145 &Handle,\r
146 &gMemInfoProtocolGuid,\r
147 MemInfoProtocol,\r
148 NULL\r
149 );\r
150 }\r
151\r
152 Status = EFI_SUCCESS;\r
153 if (BOOT_WITH_MINIMAL_CONFIGURATION != GetBootModeHob()){\r
154 //\r
155 // Get the Memory Config guid hob\r
156 //\r
157 GuidHob = GetFirstGuidHob (&gEfiMemoryConfigDataGuid);\r
158 if (GuidHob == NULL) {\r
159 Status = EFI_NOT_FOUND;\r
160 }\r
161 ASSERT_EFI_ERROR (Status);\r
162 \r
163 MemHobData = GET_GUID_HOB_DATA (GuidHob);\r
164 BufferSize = GET_GUID_HOB_DATA_SIZE (GuidHob);\r
165\r
166 Status = gRT->GetVariable (\r
167 EfiMemoryConfigVariable,\r
168 &gEfiVlv2VariableGuid,\r
169 NULL,\r
170 &BufferSize,\r
171 VariableData\r
172 );\r
173 if (EFI_ERROR(Status) && (MemHobData != NULL)) { \r
174 Status = gRT->SetVariable (\r
175 EfiMemoryConfigVariable,\r
176 &gEfiVlv2VariableGuid,\r
177 (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS),\r
178 BufferSize,\r
179 MemHobData\r
180 );\r
181 } \r
182 }\r
183\r
184 } // if-else MfgMode\r
185\r
186 return EFI_SUCCESS;\r
187}\r