Some library instance's PCD is missing in FPD file for a module, it break single...
[mirror_edk2.git] / EdkNt32Pkg / Pei / FlashMap / FlashMap.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 FlashMap.c\r
15 \r
16Abstract:\r
17\r
18 PEIM to build GUIDed HOBs for platform specific flash map\r
19\r
20--*/\r
21\r
22\r
23#include <FlashLayout.h>\r
24\r
25EFI_STATUS\r
26EFIAPI\r
27GetAreaInfo (\r
28 IN EFI_PEI_SERVICES **PeiServices,\r
29 IN PEI_FLASH_MAP_PPI *This,\r
30 IN EFI_FLASH_AREA_TYPE AreaType,\r
31 IN EFI_GUID *AreaTypeGuid,\r
32 OUT UINT32 *NumEntries,\r
33 OUT EFI_FLASH_SUBAREA_ENTRY **Entries\r
34 );\r
35\r
36EFI_STATUS\r
37EFIAPI\r
38MemoryDiscoveredPpiNotifyCallback (\r
39 IN EFI_PEI_SERVICES **PeiServices,\r
40 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r
41 IN VOID *Ppi\r
42 );\r
43\r
44//\r
45// Module globals\r
46//\r
47static PEI_FLASH_MAP_PPI mFlashMapPpi = { GetAreaInfo };\r
48\r
49static EFI_PEI_PPI_DESCRIPTOR mPpiListFlashMap = {\r
50 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
51 &gPeiFlashMapPpiGuid,\r
52 &mFlashMapPpi\r
53};\r
54\r
55static EFI_FLASH_AREA_DATA mFlashAreaData[] = {\r
56 //\r
57 // Variable area\r
58 //\r
59 {\r
60 EFI_VARIABLE_STORE_OFFSET,\r
61 EFI_VARIABLE_STORE_LENGTH,\r
62 EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV,\r
63 EFI_FLASH_AREA_EFI_VARIABLES\r
64 },\r
65 //\r
66 // FTW spare (backup) block\r
67 //\r
68 {\r
69 EFI_WINNT_FTW_SPARE_BLOCK_OFFSET,\r
70 EFI_WINNT_FTW_SPARE_BLOCK_LENGTH,\r
71 EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV,\r
72 EFI_FLASH_AREA_FTW_BACKUP\r
73 },\r
74 //\r
75 // FTW private working (state) area\r
76 //\r
77 {\r
78 EFI_FTW_WORKING_OFFSET,\r
79 EFI_FTW_WORKING_LENGTH,\r
80 EFI_FLASH_AREA_SUBFV | EFI_FLASH_AREA_MEMMAPPED_FV,\r
81 EFI_FLASH_AREA_FTW_STATE\r
82 },\r
83 //\r
84 // Recovery FV\r
85 //\r
86 {\r
87 EFI_WINNT_FIRMWARE_OFFSET,\r
88 EFI_WINNT_FIRMWARE_LENGTH,\r
89 EFI_FLASH_AREA_FV | EFI_FLASH_AREA_MEMMAPPED_FV,\r
90 EFI_FLASH_AREA_RECOVERY_BIOS\r
91 },\r
92 //\r
93 // System Non-Volatile Storage FV\r
94 //\r
95 {\r
96 EFI_WINNT_RUNTIME_UPDATABLE_OFFSET,\r
97 EFI_WINNT_RUNTIME_UPDATABLE_LENGTH + EFI_WINNT_FTW_SPARE_BLOCK_LENGTH,\r
98 EFI_FLASH_AREA_FV | EFI_FLASH_AREA_MEMMAPPED_FV,\r
99 EFI_FLASH_AREA_GUID_DEFINED\r
100 },\r
101};\r
102\r
103\r
104EFI_STATUS\r
105EFIAPI\r
106PeimInitializeFlashMap (\r
107 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
108 IN EFI_PEI_SERVICES **PeiServices\r
109 )\r
110/*++\r
111\r
112Routine Description:\r
113 Build GUIDed HOBs for platform specific flash map\r
114 \r
115Arguments:\r
116 FfsHeader - A pointer to the EFI_FFS_FILE_HEADER structure.\r
117 PeiServices - General purpose services available to every PEIM.\r
118 \r
119Returns:\r
120 EFI_STATUS\r
121\r
122--*/\r
123// TODO: EFI_SUCCESS - add return value to function comment\r
124{\r
125 EFI_STATUS Status;\r
126 NT_FWH_PPI *NtFwhPpi;\r
127 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;\r
128 EFI_PHYSICAL_ADDRESS FdBase;\r
129 UINT64 FdSize;\r
130 UINTN NumOfHobData;\r
131 UINTN Index;\r
132 EFI_FLASH_AREA_HOB_DATA FlashHobData;\r
133\r
134 DEBUG ((EFI_D_ERROR, "NT 32 Flash Map PEIM Loaded\n"));\r
135\r
136 //\r
137 // Install FlashMap PPI\r
138 //\r
84a99d48 139 Status = PeiServicesInstallPpi (&mPpiListFlashMap);\r
878ddf1f 140 ASSERT_EFI_ERROR (Status);\r
141\r
142\r
143 //\r
144 // Get the Fwh Information PPI\r
145 //\r
84a99d48 146 Status = PeiServicesLocatePpi (\r
878ddf1f 147 &gNtFwhPpiGuid, // GUID\r
148 0, // INSTANCE\r
149 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR\r
150 &NtFwhPpi // PPI\r
151 );\r
152 ASSERT_EFI_ERROR (Status);\r
153\r
154 //\r
155 // Assume that FD0 contains the Flash map.\r
156 //\r
157 Status = NtFwhPpi->NtFwh (0, &FdBase, &FdSize);\r
158 if (EFI_ERROR (Status)) {\r
159 return Status;\r
160 }\r
161\r
162 //\r
163 // Get number of types\r
164 //\r
165 NumOfHobData = sizeof (mFlashAreaData) / sizeof (EFI_FLASH_AREA_DATA);\r
166\r
167 //\r
168 // Build flash area entries as GUIDed HOBs.\r
169 //\r
170 for (Index = 0; Index < NumOfHobData; Index++) {\r
171 (*PeiServices)->SetMem (&FlashHobData, sizeof (EFI_FLASH_AREA_HOB_DATA), 0);\r
172\r
173 FlashHobData.AreaType = mFlashAreaData[Index].AreaType;\r
174 FlashHobData.NumberOfEntries = 1;\r
175 FlashHobData.SubAreaData.Attributes = mFlashAreaData[Index].Attributes;\r
176 FlashHobData.SubAreaData.Base = FdBase + (EFI_PHYSICAL_ADDRESS) (UINTN) mFlashAreaData[Index].Base;\r
177 FlashHobData.SubAreaData.Length = (EFI_PHYSICAL_ADDRESS) (UINTN) mFlashAreaData[Index].Length;\r
178\r
179 switch (FlashHobData.AreaType) {\r
180 case EFI_FLASH_AREA_RECOVERY_BIOS:\r
181 case EFI_FLASH_AREA_MAIN_BIOS:\r
182 (*PeiServices)->CopyMem (\r
183 &FlashHobData.AreaTypeGuid,\r
184 &gEfiFirmwareFileSystemGuid,\r
185 sizeof (EFI_GUID)\r
186 );\r
187 (*PeiServices)->CopyMem (\r
188 &FlashHobData.SubAreaData.FileSystem,\r
189 &gEfiFirmwareVolumeBlockProtocolGuid,\r
190 sizeof (EFI_GUID)\r
191 );\r
192 break;\r
193\r
194 case EFI_FLASH_AREA_GUID_DEFINED:\r
195 (*PeiServices)->CopyMem (\r
196 &FlashHobData.AreaTypeGuid,\r
197 &gEfiSystemNvDataHobGuid,\r
198 sizeof (EFI_GUID)\r
199 );\r
200 (*PeiServices)->CopyMem (\r
201 &FlashHobData.SubAreaData.FileSystem,\r
202 &gEfiFirmwareVolumeBlockProtocolGuid,\r
203 sizeof (EFI_GUID)\r
204 );\r
205 break;\r
206\r
207 default:\r
208 break;\r
209 }\r
210\r
211 BuildGuidDataHob (\r
212 &gEfiFlashMapHobGuid,\r
213 &FlashHobData,\r
214 sizeof (EFI_FLASH_AREA_HOB_DATA)\r
215 );\r
216 }\r
217\r
218 return EFI_SUCCESS;\r
219}\r
220\r
221EFI_STATUS\r
222EFIAPI\r
223GetAreaInfo (\r
224 IN EFI_PEI_SERVICES **PeiServices,\r
225 IN PEI_FLASH_MAP_PPI *This,\r
226 IN EFI_FLASH_AREA_TYPE AreaType,\r
227 IN EFI_GUID *AreaTypeGuid,\r
228 OUT UINT32 *NumEntries,\r
229 OUT EFI_FLASH_SUBAREA_ENTRY **Entries\r
230 )\r
231/*++\r
232\r
233 Routine Description: \r
234 Implementation of Flash Map PPI\r
235 \r
236--*/\r
237// TODO: function comment is missing 'Arguments:'\r
238// TODO: function comment is missing 'Returns:'\r
239// TODO: PeiServices - add argument and description to function comment\r
240// TODO: This - add argument and description to function comment\r
241// TODO: AreaType - add argument and description to function comment\r
242// TODO: AreaTypeGuid - add argument and description to function comment\r
243// TODO: NumEntries - add argument and description to function comment\r
244// TODO: Entries - add argument and description to function comment\r
245// TODO: EFI_SUCCESS - add return value to function comment\r
246// TODO: EFI_NOT_FOUND - add return value to function comment\r
247{\r
248 EFI_STATUS Status;\r
249 EFI_PEI_HOB_POINTERS Hob;\r
250 EFI_HOB_FLASH_MAP_ENTRY_TYPE *FlashMapEntry;\r
251\r
84a99d48 252 Status = PeiServicesGetHobList (&Hob.Raw);\r
878ddf1f 253 while (!END_OF_HOB_LIST (Hob)) {\r
254 if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION && CompareGuid (&Hob.Guid->Name, &gEfiFlashMapHobGuid)) {\r
255 FlashMapEntry = (EFI_HOB_FLASH_MAP_ENTRY_TYPE *) Hob.Raw;\r
256 if (AreaType == FlashMapEntry->AreaType) {\r
257 if (AreaType == EFI_FLASH_AREA_GUID_DEFINED) {\r
258 if (!CompareGuid (AreaTypeGuid, &FlashMapEntry->AreaTypeGuid)) {\r
259 continue;\r
260 }\r
261 }\r
262\r
263 *NumEntries = FlashMapEntry->NumEntries;\r
264 *Entries = FlashMapEntry->Entries;\r
265 return EFI_SUCCESS;\r
266 }\r
267 }\r
268\r
269 Hob.Raw = GET_NEXT_HOB (Hob);\r
270 }\r
271\r
272 return EFI_NOT_FOUND;\r
273}\r