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