]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/CapsulePei/UefiCapsule.c
MdeModulePkg CapsulePei: Fix some typos
[mirror_edk2.git] / MdeModulePkg / Universal / CapsulePei / UefiCapsule.c
CommitLineData
da58b0db 1/** @file\r
2 Capsule update PEIM for UEFI2.0\r
3\r
ed3ff1ac 4Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
da58b0db 5\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions\r
8of the BSD License which accompanies this distribution. The\r
9full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include "Capsule.h"\r
18\r
4e4f13d2 19#ifdef MDE_CPU_IA32\r
ab7017fe 20//\r
21// Global Descriptor Table (GDT)\r
22//\r
23GLOBAL_REMOVE_IF_UNREFERENCED IA32_SEGMENT_DESCRIPTOR mGdtEntries[] = {\r
24/* selector { Global Segment Descriptor } */\r
25/* 0x00 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //null descriptor\r
26/* 0x08 */ {{0xffff, 0, 0, 0x3, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear data segment descriptor\r
27/* 0x10 */ {{0xffff, 0, 0, 0xf, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //linear code segment descriptor\r
28/* 0x18 */ {{0xffff, 0, 0, 0x3, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor\r
29/* 0x20 */ {{0xffff, 0, 0, 0xb, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system code segment descriptor\r
30/* 0x28 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor\r
31/* 0x30 */ {{0xffff, 0, 0, 0x3, 1, 0, 1, 0xf, 0, 0, 1, 1, 0}}, //system data segment descriptor\r
32/* 0x38 */ {{0xffff, 0, 0, 0xb, 1, 0, 1, 0xf, 0, 1, 0, 1, 0}}, //system code segment descriptor\r
33/* 0x40 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, //spare segment descriptor\r
34};\r
35\r
36//\r
37// IA32 Gdt register\r
38//\r
39GLOBAL_REMOVE_IF_UNREFERENCED CONST IA32_DESCRIPTOR mGdt = {\r
40 sizeof (mGdtEntries) - 1,\r
41 (UINTN) mGdtEntries\r
42 };\r
da58b0db 43\r
44/**\r
716087e2
SZ
45 The function will check if 1G page is supported.\r
46\r
47 @retval TRUE 1G page is supported.\r
48 @retval FALSE 1G page is not supported.\r
49\r
da58b0db 50**/\r
716087e2
SZ
51BOOLEAN\r
52IsPage1GSupport (\r
ab7017fe 53 VOID\r
da58b0db 54 )\r
55{\r
c56b6566
JY
56 UINT32 RegEax;\r
57 UINT32 RegEdx;\r
c56b6566
JY
58 BOOLEAN Page1GSupport;\r
59\r
60 Page1GSupport = FALSE;\r
378175d2
JY
61 if (PcdGetBool(PcdUse1GPageTable)) {\r
62 AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);\r
63 if (RegEax >= 0x80000001) {\r
64 AsmCpuid (0x80000001, NULL, NULL, NULL, &RegEdx);\r
65 if ((RegEdx & BIT26) != 0) {\r
66 Page1GSupport = TRUE;\r
67 }\r
c56b6566
JY
68 }\r
69 }\r
ab7017fe 70\r
716087e2
SZ
71 return Page1GSupport;\r
72}\r
73\r
74/**\r
75 Calculate the total size of page table.\r
76\r
77 @param[in] Page1GSupport 1G page support or not.\r
78\r
79 @return The size of page table.\r
80\r
81**/\r
82UINTN\r
83CalculatePageTableSize (\r
84 IN BOOLEAN Page1GSupport\r
85 )\r
86{\r
87 UINTN ExtraPageTablePages;\r
88 UINTN TotalPagesNum;\r
89 UINT8 PhysicalAddressBits;\r
90 UINT32 NumberOfPml4EntriesNeeded;\r
91 UINT32 NumberOfPdpEntriesNeeded;\r
ab7017fe 92\r
da58b0db 93 //\r
716087e2
SZ
94 // Create 4G page table by default,\r
95 // and let PF handler to handle > 4G request.\r
da58b0db 96 //\r
716087e2
SZ
97 PhysicalAddressBits = 32;\r
98 ExtraPageTablePages = EXTRA_PAGE_TABLE_PAGES;\r
ab7017fe 99\r
100 //\r
101 // Calculate the table entries needed.\r
102 //\r
103 if (PhysicalAddressBits <= 39 ) {\r
104 NumberOfPml4EntriesNeeded = 1;\r
c56b6566 105 NumberOfPdpEntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 30));\r
ab7017fe 106 } else {\r
c56b6566 107 NumberOfPml4EntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 39));\r
ab7017fe 108 NumberOfPdpEntriesNeeded = 512;\r
da58b0db 109 }\r
110\r
c56b6566
JY
111 if (!Page1GSupport) {\r
112 TotalPagesNum = (NumberOfPdpEntriesNeeded + 1) * NumberOfPml4EntriesNeeded + 1;\r
113 } else {\r
114 TotalPagesNum = NumberOfPml4EntriesNeeded + 1;\r
115 }\r
716087e2 116 TotalPagesNum += ExtraPageTablePages;\r
ab7017fe 117\r
118 return EFI_PAGES_TO_SIZE (TotalPagesNum);\r
da58b0db 119}\r
120\r
121/**\r
ab7017fe 122 Allocates and fills in the Page Directory and Page Table Entries to\r
716087e2 123 establish a 4G page table.\r
da58b0db 124\r
716087e2
SZ
125 @param[in] PageTablesAddress The base address of page table.\r
126 @param[in] Page1GSupport 1G page support or not.\r
da58b0db 127\r
128**/\r
ab7017fe 129VOID\r
716087e2
SZ
130Create4GPageTables (\r
131 IN EFI_PHYSICAL_ADDRESS PageTablesAddress,\r
132 IN BOOLEAN Page1GSupport\r
da58b0db 133 )\r
ab7017fe 134{ \r
135 UINT8 PhysicalAddressBits;\r
136 EFI_PHYSICAL_ADDRESS PageAddress;\r
137 UINTN IndexOfPml4Entries;\r
138 UINTN IndexOfPdpEntries;\r
139 UINTN IndexOfPageDirectoryEntries;\r
140 UINT32 NumberOfPml4EntriesNeeded;\r
141 UINT32 NumberOfPdpEntriesNeeded;\r
142 PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry;\r
143 PAGE_MAP_AND_DIRECTORY_POINTER *PageMap;\r
144 PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry;\r
145 PAGE_TABLE_ENTRY *PageDirectoryEntry;\r
146 UINTN BigPageAddress;\r
c56b6566
JY
147 PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry;\r
148\r
ab7017fe 149 //\r
716087e2
SZ
150 // Create 4G page table by default,\r
151 // and let PF handler to handle > 4G request.\r
ab7017fe 152 //\r
716087e2 153 PhysicalAddressBits = 32;\r
da58b0db 154\r
155 //\r
ab7017fe 156 // Calculate the table entries needed.\r
157 //\r
158 if (PhysicalAddressBits <= 39 ) {\r
159 NumberOfPml4EntriesNeeded = 1;\r
c56b6566 160 NumberOfPdpEntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 30));\r
ab7017fe 161 } else {\r
c56b6566 162 NumberOfPml4EntriesNeeded = (UINT32)LShiftU64 (1, (PhysicalAddressBits - 39));\r
ab7017fe 163 NumberOfPdpEntriesNeeded = 512;\r
164 }\r
165\r
166 //\r
167 // Pre-allocate big pages to avoid later allocations. \r
168 //\r
169 BigPageAddress = (UINTN) PageTablesAddress;\r
170\r
171 //\r
172 // By architecture only one PageMapLevel4 exists - so lets allocate storage for it.\r
173 //\r
174 PageMap = (VOID *) BigPageAddress;\r
c56b6566 175 BigPageAddress += SIZE_4KB;\r
ab7017fe 176\r
177 PageMapLevel4Entry = PageMap;\r
178 PageAddress = 0;\r
179 for (IndexOfPml4Entries = 0; IndexOfPml4Entries < NumberOfPml4EntriesNeeded; IndexOfPml4Entries++, PageMapLevel4Entry++) {\r
da58b0db 180 //\r
ab7017fe 181 // Each PML4 entry points to a page of Page Directory Pointer entires.\r
182 // So lets allocate space for them and fill them in in the IndexOfPdpEntries loop.\r
da58b0db 183 //\r
ab7017fe 184 PageDirectoryPointerEntry = (VOID *) BigPageAddress;\r
c56b6566 185 BigPageAddress += SIZE_4KB;\r
da58b0db 186\r
ab7017fe 187 //\r
188 // Make a PML4 Entry\r
189 //\r
190 PageMapLevel4Entry->Uint64 = (UINT64)(UINTN)PageDirectoryPointerEntry;\r
191 PageMapLevel4Entry->Bits.ReadWrite = 1;\r
192 PageMapLevel4Entry->Bits.Present = 1;\r
193\r
c56b6566 194 if (Page1GSupport) {\r
54d3b84e 195 PageDirectory1GEntry = (VOID *) PageDirectoryPointerEntry;\r
c56b6566
JY
196 \r
197 for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectory1GEntry++, PageAddress += SIZE_1GB) {\r
da58b0db 198 //\r
ab7017fe 199 // Fill in the Page Directory entries\r
da58b0db 200 //\r
c56b6566
JY
201 PageDirectory1GEntry->Uint64 = (UINT64)PageAddress;\r
202 PageDirectory1GEntry->Bits.ReadWrite = 1;\r
203 PageDirectory1GEntry->Bits.Present = 1;\r
204 PageDirectory1GEntry->Bits.MustBe1 = 1;\r
205 }\r
206 } else {\r
207 for (IndexOfPdpEntries = 0; IndexOfPdpEntries < NumberOfPdpEntriesNeeded; IndexOfPdpEntries++, PageDirectoryPointerEntry++) {\r
208 //\r
209 // Each Directory Pointer entries points to a page of Page Directory entires.\r
210 // So allocate space for them and fill them in in the IndexOfPageDirectoryEntries loop.\r
211 // \r
212 PageDirectoryEntry = (VOID *) BigPageAddress;\r
213 BigPageAddress += SIZE_4KB;\r
214\r
215 //\r
216 // Fill in a Page Directory Pointer Entries\r
217 //\r
218 PageDirectoryPointerEntry->Uint64 = (UINT64)(UINTN)PageDirectoryEntry;\r
219 PageDirectoryPointerEntry->Bits.ReadWrite = 1;\r
220 PageDirectoryPointerEntry->Bits.Present = 1;\r
221\r
222 for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PageAddress += SIZE_2MB) {\r
223 //\r
224 // Fill in the Page Directory entries\r
225 //\r
226 PageDirectoryEntry->Uint64 = (UINT64)PageAddress;\r
227 PageDirectoryEntry->Bits.ReadWrite = 1;\r
228 PageDirectoryEntry->Bits.Present = 1;\r
229 PageDirectoryEntry->Bits.MustBe1 = 1;\r
230 }\r
231 }\r
ab7017fe 232\r
c56b6566
JY
233 for (; IndexOfPdpEntries < 512; IndexOfPdpEntries++, PageDirectoryPointerEntry++) {\r
234 ZeroMem (\r
235 PageDirectoryPointerEntry,\r
236 sizeof(PAGE_MAP_AND_DIRECTORY_POINTER)\r
237 );\r
da58b0db 238 }\r
da58b0db 239 }\r
240 }\r
241\r
ab7017fe 242 //\r
243 // For the PML4 entries we are not using fill in a null entry.\r
ab7017fe 244 //\r
245 for (; IndexOfPml4Entries < 512; IndexOfPml4Entries++, PageMapLevel4Entry++) {\r
c56b6566
JY
246 ZeroMem (\r
247 PageMapLevel4Entry,\r
248 sizeof (PAGE_MAP_AND_DIRECTORY_POINTER)\r
249 );\r
ab7017fe 250 }\r
251}\r
252\r
253/**\r
254 Return function from long mode to 32-bit mode.\r
255\r
256 @param EntrypointContext Context for mode switching\r
257 @param ReturnContext Context for mode switching\r
258\r
259**/\r
260VOID\r
261ReturnFunction (\r
262 SWITCH_32_TO_64_CONTEXT *EntrypointContext,\r
263 SWITCH_64_TO_32_CONTEXT *ReturnContext\r
264 )\r
716087e2 265{\r
ab7017fe 266 //\r
267 // Restore original GDT\r
268 //\r
269 AsmWriteGdtr (&ReturnContext->Gdtr);\r
716087e2 270\r
ab7017fe 271 //\r
272 // return to original caller\r
273 //\r
274 LongJump ((BASE_LIBRARY_JUMP_BUFFER *)(UINTN)EntrypointContext->JumpBuffer, 1);\r
716087e2 275\r
ab7017fe 276 //\r
277 // never be here\r
716087e2 278 //\r
ab7017fe 279 ASSERT (FALSE);\r
280}\r
281\r
282/**\r
283 Thunk function from 32-bit protection mode to long mode.\r
284\r
285 @param PageTableAddress Page table base address\r
286 @param Context Context for mode switching\r
287 @param ReturnContext Context for mode switching\r
288\r
289 @retval EFI_SUCCESS Function successfully executed.\r
290\r
291**/\r
292EFI_STATUS\r
293Thunk32To64 (\r
294 EFI_PHYSICAL_ADDRESS PageTableAddress,\r
295 SWITCH_32_TO_64_CONTEXT *Context,\r
296 SWITCH_64_TO_32_CONTEXT *ReturnContext\r
297 )\r
298{\r
299 UINTN SetJumpFlag;\r
300 EFI_STATUS Status;\r
301\r
302 //\r
303 // Save return address, LongJump will return here then\r
304 //\r
305 SetJumpFlag = SetJump ((BASE_LIBRARY_JUMP_BUFFER *) (UINTN) Context->JumpBuffer);\r
306\r
307 if (SetJumpFlag == 0) {\r
308\r
da58b0db 309 //\r
716087e2 310 // Build 4G Page Tables.\r
da58b0db 311 //\r
716087e2
SZ
312 Create4GPageTables (PageTableAddress, Context->Page1GSupport);\r
313\r
ab7017fe 314 //\r
315 // Create 64-bit GDT\r
316 //\r
317 AsmWriteGdtr (&mGdt);\r
da58b0db 318\r
ab7017fe 319 //\r
320 // Write CR3\r
321 //\r
322 AsmWriteCr3 ((UINTN) PageTableAddress);\r
323\r
933d80a1 324 //\r
325 // Disable interrupt of Debug timer, since the IDT table cannot work in long mode\r
326 //\r
327 SaveAndSetDebugTimerInterrupt (FALSE);\r
ab7017fe 328 //\r
329 // Transfer to long mode\r
330 //\r
331 AsmEnablePaging64 (\r
332 0x38,\r
333 (UINT64) Context->EntryPoint,\r
334 (UINT64)(UINTN) Context,\r
335 (UINT64)(UINTN) ReturnContext,\r
336 Context->StackBufferBase + Context->StackBufferLength\r
337 );\r
338 }\r
716087e2 339\r
ab7017fe 340 //\r
341 // Convert to 32-bit Status and return\r
342 //\r
343 Status = EFI_SUCCESS;\r
344 if ((UINTN) ReturnContext->ReturnStatus != 0) {\r
345 Status = ENCODE_ERROR ((UINTN) ReturnContext->ReturnStatus);\r
346 }\r
347 \r
348 return Status;\r
da58b0db 349}\r
350\r
ab7017fe 351/**\r
352 If in 32 bit protection mode, and coalesce image is of X64, switch to long mode.\r
353\r
354 @param LongModeBuffer The context of long mode.\r
355 @param CoalesceEntry Entry of coalesce image.\r
356 @param BlockListAddr Address of block list.\r
357 @param MemoryBase Base of memory range.\r
358 @param MemorySize Size of memory range.\r
359\r
360 @retval EFI_SUCCESS Successfully switched to long mode and execute coalesce.\r
361 @retval Others Failed to execute coalesce in long mode.\r
362\r
363**/\r
364EFI_STATUS\r
365ModeSwitch (\r
366 IN EFI_CAPSULE_LONG_MODE_BUFFER *LongModeBuffer,\r
367 IN COALESCE_ENTRY CoalesceEntry,\r
368 IN EFI_PHYSICAL_ADDRESS BlockListAddr,\r
369 IN OUT VOID **MemoryBase,\r
370 IN OUT UINTN *MemorySize\r
371 )\r
372{\r
373 EFI_STATUS Status;\r
374 EFI_PHYSICAL_ADDRESS MemoryBase64;\r
375 UINT64 MemorySize64;\r
376 EFI_PHYSICAL_ADDRESS MemoryEnd64;\r
377 SWITCH_32_TO_64_CONTEXT Context;\r
378 SWITCH_64_TO_32_CONTEXT ReturnContext;\r
379 BASE_LIBRARY_JUMP_BUFFER JumpBuffer;\r
380 EFI_PHYSICAL_ADDRESS ReservedRangeBase;\r
381 EFI_PHYSICAL_ADDRESS ReservedRangeEnd;\r
716087e2 382 BOOLEAN Page1GSupport;\r
ab7017fe 383\r
384 ZeroMem (&Context, sizeof (SWITCH_32_TO_64_CONTEXT));\r
385 ZeroMem (&ReturnContext, sizeof (SWITCH_64_TO_32_CONTEXT));\r
386 \r
387 MemoryBase64 = (UINT64) (UINTN) *MemoryBase;\r
388 MemorySize64 = (UINT64) (UINTN) *MemorySize;\r
389 MemoryEnd64 = MemoryBase64 + MemorySize64;\r
390\r
716087e2
SZ
391 Page1GSupport = IsPage1GSupport ();\r
392\r
ab7017fe 393 //\r
394 // Merge memory range reserved for stack and page table \r
395 //\r
396 if (LongModeBuffer->StackBaseAddress < LongModeBuffer->PageTableAddress) {\r
397 ReservedRangeBase = LongModeBuffer->StackBaseAddress;\r
716087e2 398 ReservedRangeEnd = LongModeBuffer->PageTableAddress + CalculatePageTableSize (Page1GSupport);\r
ab7017fe 399 } else {\r
400 ReservedRangeBase = LongModeBuffer->PageTableAddress;\r
401 ReservedRangeEnd = LongModeBuffer->StackBaseAddress + LongModeBuffer->StackSize;\r
402 }\r
716087e2 403\r
ab7017fe 404 //\r
405 // Check if memory range reserved is overlap with MemoryBase ~ MemoryBase + MemorySize.\r
406 // If they are overlapped, get a larger range to process capsule data.\r
407 //\r
408 if (ReservedRangeBase <= MemoryBase64) {\r
409 if (ReservedRangeEnd < MemoryEnd64) {\r
410 MemoryBase64 = ReservedRangeEnd;\r
411 } else {\r
412 DEBUG ((EFI_D_ERROR, "Memory is not enough to process capsule!\n"));\r
413 return EFI_OUT_OF_RESOURCES;\r
414 }\r
415 } else if (ReservedRangeBase < MemoryEnd64) {\r
416 if (ReservedRangeEnd < MemoryEnd64 &&\r
417 ReservedRangeBase - MemoryBase64 < MemoryEnd64 - ReservedRangeEnd) {\r
418 MemoryBase64 = ReservedRangeEnd;\r
419 } else {\r
420 MemorySize64 = (UINT64)(UINTN)(ReservedRangeBase - MemoryBase64);\r
421 }\r
716087e2
SZ
422 }\r
423\r
ab7017fe 424 //\r
425 // Initialize context jumping to 64-bit enviroment\r
426 //\r
427 Context.JumpBuffer = (EFI_PHYSICAL_ADDRESS)(UINTN)&JumpBuffer;\r
428 Context.StackBufferBase = LongModeBuffer->StackBaseAddress;\r
429 Context.StackBufferLength = LongModeBuffer->StackSize;\r
430 Context.EntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)CoalesceEntry;\r
431 Context.BlockListAddr = BlockListAddr;\r
432 Context.MemoryBase64Ptr = (EFI_PHYSICAL_ADDRESS)(UINTN)&MemoryBase64;\r
433 Context.MemorySize64Ptr = (EFI_PHYSICAL_ADDRESS)(UINTN)&MemorySize64;\r
716087e2 434 Context.Page1GSupport = Page1GSupport;\r
ab7017fe 435\r
436 //\r
437 // Prepare data for return back\r
438 //\r
439 ReturnContext.ReturnCs = 0x10;\r
440 ReturnContext.ReturnEntryPoint = (EFI_PHYSICAL_ADDRESS)(UINTN)ReturnFunction;\r
441 //\r
442 // Will save the return status of processing capsule\r
443 //\r
444 ReturnContext.ReturnStatus = 0;\r
445 \r
446 //\r
447 // Save original GDT\r
448 //\r
449 AsmReadGdtr ((IA32_DESCRIPTOR *)&ReturnContext.Gdtr);\r
450 \r
451 Status = Thunk32To64 (LongModeBuffer->PageTableAddress, &Context, &ReturnContext);\r
452 \r
453 if (!EFI_ERROR (Status)) {\r
454 *MemoryBase = (VOID *) (UINTN) MemoryBase64;\r
455 *MemorySize = (UINTN) MemorySize64;\r
456 }\r
457\r
458 return Status;\r
459\r
460}\r
da58b0db 461\r
4e4f13d2 462/**\r
463 Locates the coalesce image entry point, and detects its machine type.\r
464\r
465 @param CoalesceImageEntryPoint Pointer to coalesce image entry point for output.\r
466 @param CoalesceImageMachineType Pointer to machine type of coalesce image.\r
467\r
468 @retval EFI_SUCCESS Coalesce image successfully located.\r
469 @retval Others Failed to locate the coalesce image.\r
470\r
471**/\r
472EFI_STATUS\r
473FindCapsuleCoalesceImage (\r
474 OUT EFI_PHYSICAL_ADDRESS *CoalesceImageEntryPoint,\r
475 OUT UINT16 *CoalesceImageMachineType\r
476 )\r
477{\r
478 EFI_STATUS Status;\r
479 UINTN Instance;\r
480 EFI_PEI_LOAD_FILE_PPI *LoadFile;\r
481 EFI_PEI_FV_HANDLE VolumeHandle;\r
482 EFI_PEI_FILE_HANDLE FileHandle;\r
483 EFI_PHYSICAL_ADDRESS CoalesceImageAddress;\r
484 UINT64 CoalesceImageSize;\r
485 UINT32 AuthenticationState;\r
486\r
487 Instance = 0;\r
488\r
489 while (TRUE) {\r
490 Status = PeiServicesFfsFindNextVolume (Instance++, &VolumeHandle);\r
491 if (EFI_ERROR (Status)) {\r
492 return Status;\r
493 }\r
494 Status = PeiServicesFfsFindFileByName (PcdGetPtr(PcdCapsuleCoalesceFile), VolumeHandle, &FileHandle);\r
495 if (!EFI_ERROR (Status)) {\r
496 Status = PeiServicesLocatePpi (&gEfiPeiLoadFilePpiGuid, 0, NULL, (VOID **) &LoadFile);\r
497 ASSERT_EFI_ERROR (Status);\r
498\r
499 Status = LoadFile->LoadFile (\r
500 LoadFile,\r
501 FileHandle,\r
502 &CoalesceImageAddress,\r
503 &CoalesceImageSize,\r
504 CoalesceImageEntryPoint,\r
505 &AuthenticationState\r
506 );\r
507 if (EFI_ERROR (Status)) {\r
716087e2 508 DEBUG ((EFI_D_ERROR, "Unable to find PE32 section in CapsuleX64 image ffs %r!\n", Status));\r
4e4f13d2 509 return Status;\r
510 }\r
511 *CoalesceImageMachineType = PeCoffLoaderGetMachineType ((VOID *) (UINTN) CoalesceImageAddress);\r
512 break;\r
513 } else {\r
514 continue;\r
515 }\r
516 }\r
517\r
518 return Status;\r
519}\r
520\r
716087e2
SZ
521/**\r
522 Gets the reserved long mode buffer.\r
523\r
524 @param LongModeBuffer Pointer to the long mode buffer for output.\r
525\r
526 @retval EFI_SUCCESS Long mode buffer successfully retrieved.\r
527 @retval Others Variable storing long mode buffer not found.\r
528\r
529**/\r
530EFI_STATUS\r
531GetLongModeContext (\r
532 OUT EFI_CAPSULE_LONG_MODE_BUFFER *LongModeBuffer\r
533 )\r
534{\r
535 EFI_STATUS Status;\r
536 UINTN Size;\r
537 EFI_PEI_READ_ONLY_VARIABLE2_PPI *PPIVariableServices;\r
538\r
539 Status = PeiServicesLocatePpi (\r
540 &gEfiPeiReadOnlyVariable2PpiGuid,\r
541 0,\r
542 NULL,\r
543 (VOID **) &PPIVariableServices\r
544 );\r
545 ASSERT_EFI_ERROR (Status);\r
546\r
547 Size = sizeof (EFI_CAPSULE_LONG_MODE_BUFFER);\r
548 Status = PPIVariableServices->GetVariable (\r
549 PPIVariableServices,\r
550 EFI_CAPSULE_LONG_MODE_BUFFER_NAME,\r
551 &gEfiCapsuleVendorGuid,\r
552 NULL,\r
553 &Size,\r
554 LongModeBuffer\r
555 );\r
556 if (EFI_ERROR (Status)) {\r
557 DEBUG (( EFI_D_ERROR, "Error Get LongModeBuffer variable %r!\n", Status));\r
558 }\r
559 return Status;\r
560}\r
4e4f13d2 561#endif\r
562\r
da58b0db 563/**\r
564 Checks for the presence of capsule descriptors.\r
565 Get capsule descriptors from variable CapsuleUpdateData, CapsuleUpdateData1, CapsuleUpdateData2...\r
ab7017fe 566 and save to DescriptorBuffer.\r
da58b0db 567\r
ab7017fe 568 @param DescriptorBuffer Pointer to the capsule descriptors\r
da58b0db 569\r
570 @retval EFI_SUCCESS a valid capsule is present\r
571 @retval EFI_NOT_FOUND if a valid capsule is not present\r
572**/\r
573EFI_STATUS\r
574GetCapsuleDescriptors (\r
ab7017fe 575 IN EFI_PHYSICAL_ADDRESS *DescriptorBuffer\r
da58b0db 576 )\r
577{\r
578 EFI_STATUS Status;\r
579 UINTN Size;\r
580 UINTN Index;\r
581 UINTN TempIndex;\r
582 UINTN ValidIndex;\r
583 BOOLEAN Flag;\r
584 CHAR16 CapsuleVarName[30];\r
585 CHAR16 *TempVarName;\r
586 EFI_PHYSICAL_ADDRESS CapsuleDataPtr64;\r
da58b0db 587 EFI_PEI_READ_ONLY_VARIABLE2_PPI *PPIVariableServices;\r
588\r
da58b0db 589 Index = 0;\r
590 TempVarName = NULL;\r
591 CapsuleVarName[0] = 0;\r
592 ValidIndex = 0;\r
34717ef0 593 CapsuleDataPtr64 = 0;\r
da58b0db 594 \r
595 Status = PeiServicesLocatePpi (\r
596 &gEfiPeiReadOnlyVariable2PpiGuid,\r
597 0,\r
598 NULL,\r
599 (VOID **) &PPIVariableServices\r
600 );\r
601 if (Status == EFI_SUCCESS) {\r
59d1f4f0 602 StrCpyS (CapsuleVarName, sizeof(CapsuleVarName)/sizeof(CHAR16), EFI_CAPSULE_VARIABLE_NAME);\r
da58b0db 603 TempVarName = CapsuleVarName + StrLen (CapsuleVarName);\r
604 Size = sizeof (CapsuleDataPtr64);\r
605 while (1) {\r
606 if (Index == 0) {\r
607 //\r
608 // For the first Capsule Image\r
609 //\r
610 Status = PPIVariableServices->GetVariable (\r
611 PPIVariableServices,\r
612 CapsuleVarName,\r
613 &gEfiCapsuleVendorGuid,\r
614 NULL,\r
615 &Size,\r
616 (VOID *) &CapsuleDataPtr64\r
617 );\r
618 if (EFI_ERROR (Status)) {\r
619 DEBUG ((EFI_D_ERROR, "Capsule -- capsule variable not set\n"));\r
620 return EFI_NOT_FOUND;\r
621 }\r
622 //\r
623 // We have a chicken/egg situation where the memory init code needs to\r
624 // know the boot mode prior to initializing memory. For this case, our\r
625 // validate function will fail. We can detect if this is the case if blocklist\r
626 // pointer is null. In that case, return success since we know that the\r
627 // variable is set.\r
628 //\r
ab7017fe 629 if (DescriptorBuffer == NULL) {\r
da58b0db 630 return EFI_SUCCESS;\r
631 }\r
da58b0db 632 } else {\r
633 UnicodeValueToString (TempVarName, 0, Index, 0);\r
634 Status = PPIVariableServices->GetVariable (\r
635 PPIVariableServices,\r
636 CapsuleVarName,\r
637 &gEfiCapsuleVendorGuid,\r
638 NULL,\r
639 &Size,\r
640 (VOID *) &CapsuleDataPtr64\r
641 );\r
642 if (EFI_ERROR (Status)) {\r
643 break;\r
644 }\r
645 \r
646 //\r
647 // If this BlockList has been linked before, skip this variable\r
648 //\r
649 Flag = FALSE;\r
650 for (TempIndex = 0; TempIndex < ValidIndex; TempIndex++) {\r
ab7017fe 651 if (DescriptorBuffer[TempIndex] == CapsuleDataPtr64) {\r
da58b0db 652 Flag = TRUE;\r
653 break;\r
654 }\r
655 }\r
656 if (Flag) {\r
657 Index ++;\r
658 continue;\r
659 }\r
da58b0db 660 }\r
661 \r
662 //\r
663 // Cache BlockList which has been processed\r
664 //\r
ab7017fe 665 DescriptorBuffer[ValidIndex++] = CapsuleDataPtr64;\r
da58b0db 666 Index ++;\r
667 }\r
668 }\r
669 \r
da58b0db 670 return EFI_SUCCESS;\r
671}\r
672\r
da58b0db 673/**\r
674 Capsule PPI service to coalesce a fragmented capsule in memory.\r
675\r
da58b0db 676 @param PeiServices General purpose services available to every PEIM.\r
677 @param MemoryBase Pointer to the base of a block of memory that we can walk\r
678 all over while trying to coalesce our buffers.\r
679 On output, this variable will hold the base address of\r
680 a coalesced capsule.\r
681 @param MemorySize Size of the memory region pointed to by MemoryBase.\r
682 On output, this variable will contain the size of the\r
683 coalesced capsule.\r
684\r
685 @retval EFI_NOT_FOUND if we can't determine the boot mode\r
686 if the boot mode is not flash-update\r
687 if we could not find the capsule descriptors\r
688\r
689 @retval EFI_BUFFER_TOO_SMALL\r
690 if we could not coalesce the capsule in the memory\r
691 region provided to us\r
692\r
693 @retval EFI_SUCCESS if there's no capsule, or if we processed the\r
694 capsule successfully.\r
695**/\r
696EFI_STATUS\r
697EFIAPI\r
698CapsuleCoalesce (\r
699 IN EFI_PEI_SERVICES **PeiServices,\r
700 IN OUT VOID **MemoryBase,\r
701 IN OUT UINTN *MemorySize\r
702 )\r
703{\r
ab7017fe 704 UINTN Index;\r
705 UINTN Size;\r
706 UINTN VariableCount;\r
707 CHAR16 CapsuleVarName[30];\r
708 CHAR16 *TempVarName;\r
709 EFI_PHYSICAL_ADDRESS CapsuleDataPtr64; \r
710 EFI_STATUS Status;\r
711 EFI_BOOT_MODE BootMode;\r
712 EFI_PEI_READ_ONLY_VARIABLE2_PPI *PPIVariableServices;\r
713 EFI_PHYSICAL_ADDRESS *VariableArrayAddress;\r
714#ifdef MDE_CPU_IA32\r
715 UINT16 CoalesceImageMachineType;\r
716 EFI_PHYSICAL_ADDRESS CoalesceImageEntryPoint;\r
717 COALESCE_ENTRY CoalesceEntry;\r
718 EFI_CAPSULE_LONG_MODE_BUFFER LongModeBuffer;\r
719#endif\r
720\r
721 Index = 0;\r
722 VariableCount = 0;\r
723 CapsuleVarName[0] = 0;\r
34717ef0 724 CapsuleDataPtr64 = 0;\r
da58b0db 725\r
726 //\r
727 // Someone should have already ascertained the boot mode. If it's not\r
728 // capsule update, then return normally.\r
729 //\r
730 Status = PeiServicesGetBootMode (&BootMode);\r
731 if (EFI_ERROR (Status) || (BootMode != BOOT_ON_FLASH_UPDATE)) {\r
ab7017fe 732 DEBUG ((EFI_D_ERROR, "Boot mode is not correct for capsule update path.\n")); \r
733 Status = EFI_NOT_FOUND;\r
734 goto Done;\r
da58b0db 735 }\r
736 \r
737 //\r
738 // User may set the same ScatterGatherList with several different variables,\r
739 // so cache all ScatterGatherList for check later.\r
740 //\r
741 Status = PeiServicesLocatePpi (\r
742 &gEfiPeiReadOnlyVariable2PpiGuid,\r
743 0,\r
744 NULL,\r
745 (VOID **) &PPIVariableServices\r
746 );\r
747 if (EFI_ERROR (Status)) {\r
ab7017fe 748 goto Done;\r
da58b0db 749 }\r
750 Size = sizeof (CapsuleDataPtr64);\r
59d1f4f0 751 StrCpyS (CapsuleVarName, sizeof(CapsuleVarName)/sizeof(CHAR16), EFI_CAPSULE_VARIABLE_NAME);\r
da58b0db 752 TempVarName = CapsuleVarName + StrLen (CapsuleVarName);\r
753 while (TRUE) {\r
754 if (Index > 0) {\r
755 UnicodeValueToString (TempVarName, 0, Index, 0);\r
756 }\r
757 Status = PPIVariableServices->GetVariable (\r
758 PPIVariableServices,\r
759 CapsuleVarName,\r
760 &gEfiCapsuleVendorGuid,\r
761 NULL,\r
762 &Size,\r
763 (VOID *) &CapsuleDataPtr64\r
764 );\r
765 if (EFI_ERROR (Status)) {\r
766 //\r
767 // There is no capsule variables, quit\r
768 //\r
ab7017fe 769 DEBUG ((EFI_D_INFO,"Capsule variable Index = %d\n", Index));\r
da58b0db 770 break;\r
771 }\r
772 VariableCount++;\r
773 Index++;\r
774 }\r
775 \r
ab7017fe 776 DEBUG ((EFI_D_INFO,"Capsule variable count = %d\n", VariableCount));\r
da58b0db 777 \r
ab7017fe 778 //\r
779 // The last entry is the end flag.\r
780 //\r
da58b0db 781 Status = PeiServicesAllocatePool (\r
ab7017fe 782 (VariableCount + 1) * sizeof (EFI_PHYSICAL_ADDRESS),\r
783 (VOID **)&VariableArrayAddress\r
da58b0db 784 );\r
785\r
786 if (Status != EFI_SUCCESS) {\r
787 DEBUG ((EFI_D_ERROR, "AllocatePages Failed!, Status = %x\n", Status));\r
ab7017fe 788 goto Done;\r
da58b0db 789 }\r
790 \r
ab7017fe 791 ZeroMem (VariableArrayAddress, (VariableCount + 1) * sizeof (EFI_PHYSICAL_ADDRESS));\r
792 \r
da58b0db 793 //\r
794 // Find out if we actually have a capsule.\r
ab7017fe 795 // GetCapsuleDescriptors depends on variable PPI, so it should run in 32-bit environment.\r
da58b0db 796 //\r
ab7017fe 797 Status = GetCapsuleDescriptors (VariableArrayAddress);\r
da58b0db 798 if (EFI_ERROR (Status)) {\r
ab7017fe 799 DEBUG ((EFI_D_ERROR, "Fail to find capsule variables.\n"));\r
800 goto Done;\r
da58b0db 801 }\r
802\r
ab7017fe 803#ifdef MDE_CPU_IA32\r
804 if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {\r
da58b0db 805 //\r
ab7017fe 806 // Switch to 64-bit mode to process capsule data when:\r
807 // 1. When DXE phase is 64-bit\r
808 // 2. When the buffer for 64-bit transition exists\r
809 // 3. When Capsule X64 image is built in BIOS image\r
810 // In 64-bit mode, we can process capsule data above 4GB.\r
da58b0db 811 //\r
ab7017fe 812 CoalesceImageEntryPoint = 0;\r
813 Status = GetLongModeContext (&LongModeBuffer);\r
814 if (EFI_ERROR (Status)) {\r
716087e2 815 DEBUG ((EFI_D_ERROR, "Fail to find the variable for long mode context!\n"));\r
ab7017fe 816 Status = EFI_NOT_FOUND;\r
817 goto Done;\r
da58b0db 818 }\r
ab7017fe 819 \r
820 Status = FindCapsuleCoalesceImage (&CoalesceImageEntryPoint, &CoalesceImageMachineType);\r
821 if ((EFI_ERROR (Status)) || (CoalesceImageMachineType != EFI_IMAGE_MACHINE_X64)) {\r
822 DEBUG ((EFI_D_ERROR, "Fail to find CapsuleX64 module in FV!\n"));\r
823 Status = EFI_NOT_FOUND;\r
824 goto Done;\r
da58b0db 825 }\r
ab7017fe 826 ASSERT (CoalesceImageEntryPoint != 0);\r
827 CoalesceEntry = (COALESCE_ENTRY) (UINTN) CoalesceImageEntryPoint;\r
828 Status = ModeSwitch (&LongModeBuffer, CoalesceEntry, (EFI_PHYSICAL_ADDRESS)(UINTN)VariableArrayAddress, MemoryBase, MemorySize);\r
829 } else {\r
da58b0db 830 //\r
ab7017fe 831 // Capsule is processed in IA32 mode.\r
da58b0db 832 //\r
ab7017fe 833 Status = CapsuleDataCoalesce (PeiServices, (EFI_PHYSICAL_ADDRESS *)(UINTN)VariableArrayAddress, MemoryBase, MemorySize);\r
da58b0db 834 }\r
ab7017fe 835#else\r
da58b0db 836 //\r
ab7017fe 837 // Process capsule directly.\r
da58b0db 838 //\r
ab7017fe 839 Status = CapsuleDataCoalesce (PeiServices, (EFI_PHYSICAL_ADDRESS *)(UINTN)VariableArrayAddress, MemoryBase, MemorySize);\r
840#endif\r
841 \r
842 DEBUG ((EFI_D_INFO, "Capsule Coalesce Status = %r!\n", Status));\r
da58b0db 843\r
ab7017fe 844 if (Status == EFI_BUFFER_TOO_SMALL) {\r
845 DEBUG ((EFI_D_ERROR, "There is not enough memory to process capsule!\n"));\r
846 }\r
847 \r
848 if (Status == EFI_NOT_FOUND) {\r
849 DEBUG ((EFI_D_ERROR, "Fail to parse capsule descriptor in memory!\n"));\r
850 REPORT_STATUS_CODE (\r
851 EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
852 (EFI_SOFTWARE_PEI_MODULE | EFI_SW_PEI_EC_INVALID_CAPSULE_DESCRIPTOR)\r
853 );\r
854 }\r
da58b0db 855\r
ab7017fe 856Done:\r
da58b0db 857 return Status;\r
858}\r
859\r
860/**\r
861 Determine if we're in capsule update boot mode.\r
862\r
863 @param PeiServices PEI services table\r
864\r
865 @retval EFI_SUCCESS if we have a capsule available\r
866 @retval EFI_NOT_FOUND no capsule detected\r
867\r
868**/\r
869EFI_STATUS\r
870EFIAPI\r
871CheckCapsuleUpdate (\r
872 IN EFI_PEI_SERVICES **PeiServices\r
873 )\r
874{\r
875 EFI_STATUS Status;\r
876 Status = GetCapsuleDescriptors (NULL);\r
877 return Status;\r
878}\r
879/**\r
880 This function will look at a capsule and determine if it's a test pattern. \r
881 If it is, then it will verify it and emit an error message if corruption is detected.\r
882 \r
883 @param PeiServices Standard pei services pointer\r
884 @param CapsuleBase Base address of coalesced capsule, which is preceeded\r
885 by private data. Very implementation specific.\r
886\r
887 @retval TRUE Capsule image is the test image\r
888 @retval FALSE Capsule image is not the test image.\r
889\r
890**/\r
891BOOLEAN\r
892CapsuleTestPattern (\r
893 IN EFI_PEI_SERVICES **PeiServices,\r
894 IN VOID *CapsuleBase\r
895 )\r
896{\r
897 UINT32 *TestPtr;\r
898 UINT32 TestCounter;\r
899 UINT32 TestSize;\r
900 BOOLEAN RetValue;\r
901\r
902 RetValue = FALSE;\r
903\r
904 //\r
905 // Look at the capsule data and determine if it's a test pattern. If it\r
906 // is, then test it now.\r
907 //\r
908 TestPtr = (UINT32 *) CapsuleBase;\r
ab7017fe 909 //\r
910 // 0x54534554 "TEST"\r
911 //\r
912 if (*TestPtr == 0x54534554) {\r
da58b0db 913 RetValue = TRUE;\r
914 DEBUG ((EFI_D_INFO, "Capsule test pattern mode activated...\n"));\r
915 TestSize = TestPtr[1] / sizeof (UINT32);\r
916 //\r
917 // Skip over the signature and the size fields in the pattern data header\r
918 //\r
919 TestPtr += 2;\r
920 TestCounter = 0;\r
921 while (TestSize > 0) {\r
922 if (*TestPtr != TestCounter) {\r
923 DEBUG ((EFI_D_INFO, "Capsule test pattern mode FAILED: BaseAddr/FailAddr 0x%X 0x%X\n", (UINT32)(UINTN)(EFI_CAPSULE_PEIM_PRIVATE_DATA *)CapsuleBase, (UINT32)(UINTN)TestPtr));\r
924 return TRUE;\r
925 }\r
926\r
927 TestPtr++;\r
928 TestCounter++;\r
929 TestSize--;\r
930 }\r
931\r
932 DEBUG ((EFI_D_INFO, "Capsule test pattern mode SUCCESS\n"));\r
933 }\r
934\r
935 return RetValue;\r
936}\r
937\r
938/**\r
939 Capsule PPI service that gets called after memory is available. The\r
940 capsule coalesce function, which must be called first, returns a base\r
941 address and size, which can be anything actually. Once the memory init\r
942 PEIM has discovered memory, then it should call this function and pass in\r
943 the base address and size returned by the coalesce function. Then this\r
944 function can create a capsule HOB and return.\r
945\r
946 @param PeiServices standard pei services pointer\r
947 @param CapsuleBase address returned by the capsule coalesce function. Most\r
948 likely this will actually be a pointer to private data.\r
949 @param CapsuleSize value returned by the capsule coalesce function.\r
950\r
951 @retval EFI_VOLUME_CORRUPTED CapsuleBase does not appear to point to a\r
952 coalesced capsule\r
953 @retval EFI_SUCCESS if all goes well.\r
954**/\r
955EFI_STATUS\r
956EFIAPI\r
957CreateState (\r
958 IN EFI_PEI_SERVICES **PeiServices,\r
959 IN VOID *CapsuleBase,\r
960 IN UINTN CapsuleSize\r
961 )\r
962{\r
963 EFI_STATUS Status;\r
964 EFI_CAPSULE_PEIM_PRIVATE_DATA *PrivateData;\r
965 UINTN Size;\r
966 EFI_PHYSICAL_ADDRESS NewBuffer;\r
ff284c56 967 UINTN CapsuleNumber;\r
da58b0db 968 UINT32 Index;\r
969 EFI_PHYSICAL_ADDRESS BaseAddress;\r
970 UINT64 Length;\r
971 \r
da58b0db 972 PrivateData = (EFI_CAPSULE_PEIM_PRIVATE_DATA *) CapsuleBase;\r
973 if (PrivateData->Signature != EFI_CAPSULE_PEIM_PRIVATE_DATA_SIGNATURE) {\r
974 return EFI_VOLUME_CORRUPTED;\r
975 }\r
ff284c56
JY
976 if (PrivateData->CapsuleAllImageSize >= MAX_ADDRESS) {\r
977 DEBUG ((EFI_D_ERROR, "CapsuleAllImageSize too big - 0x%lx\n", PrivateData->CapsuleAllImageSize));\r
978 return EFI_OUT_OF_RESOURCES;\r
979 }\r
980 if (PrivateData->CapsuleNumber >= MAX_ADDRESS) {\r
981 DEBUG ((EFI_D_ERROR, "CapsuleNumber too big - 0x%lx\n", PrivateData->CapsuleNumber));\r
982 return EFI_OUT_OF_RESOURCES;\r
983 }\r
da58b0db 984 //\r
985 // Capsule Number and Capsule Offset is in the tail of Capsule data.\r
986 //\r
ff284c56
JY
987 Size = (UINTN)PrivateData->CapsuleAllImageSize;\r
988 CapsuleNumber = (UINTN)PrivateData->CapsuleNumber;\r
da58b0db 989 //\r
990 // Allocate the memory so that it gets preserved into DXE\r
991 //\r
992 Status = PeiServicesAllocatePages (\r
993 EfiRuntimeServicesData,\r
994 EFI_SIZE_TO_PAGES (Size),\r
995 &NewBuffer\r
996 );\r
997\r
998 if (Status != EFI_SUCCESS) {\r
999 DEBUG ((EFI_D_ERROR, "AllocatePages Failed!\n"));\r
1000 return Status;\r
1001 }\r
1002 //\r
1003 // Copy to our new buffer for DXE\r
1004 //\r
ff284c56
JY
1005 DEBUG ((EFI_D_INFO, "Capsule copy from 0x%8X to 0x%8X with size 0x%8X\n", (UINTN)((UINT8 *)PrivateData + sizeof(EFI_CAPSULE_PEIM_PRIVATE_DATA) + (CapsuleNumber - 1) * sizeof(UINT64)), (UINTN) NewBuffer, Size));\r
1006 CopyMem ((VOID *) (UINTN) NewBuffer, (VOID *) (UINTN) ((UINT8 *)PrivateData + sizeof(EFI_CAPSULE_PEIM_PRIVATE_DATA) + (CapsuleNumber - 1) * sizeof(UINT64)), Size);\r
da58b0db 1007 //\r
1008 // Check for test data pattern. If it is the test pattern, then we'll\r
ed3ff1ac 1009 // test it and still create the HOB so that it can be used to verify\r
da58b0db 1010 // that capsules don't get corrupted all the way into BDS. BDS will\r
1011 // still try to turn it into a firmware volume, but will think it's\r
1012 // corrupted so nothing will happen.\r
1013 //\r
1014 DEBUG_CODE (\r
1015 CapsuleTestPattern (PeiServices, (VOID *) (UINTN) NewBuffer);\r
1016 );\r
1017\r
1018 //\r
1019 // Build the UEFI Capsule Hob for each capsule image.\r
1020 //\r
1021 for (Index = 0; Index < CapsuleNumber; Index ++) {\r
ff284c56 1022 BaseAddress = NewBuffer + PrivateData->CapsuleOffset[Index];\r
da58b0db 1023 Length = ((EFI_CAPSULE_HEADER *)((UINTN) BaseAddress))->CapsuleImageSize;\r
1024\r
1025 BuildCvHob (BaseAddress, Length);\r
1026 }\r
1027 \r
1028 return EFI_SUCCESS;\r
1029}\r
1030\r
09d46995 1031CONST EFI_PEI_CAPSULE_PPI mCapsulePpi = {\r
da58b0db 1032 CapsuleCoalesce,\r
1033 CheckCapsuleUpdate,\r
1034 CreateState\r
1035};\r
1036\r
1037CONST EFI_PEI_PPI_DESCRIPTOR mUefiPpiListCapsule = {\r
1038 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
09d46995
LG
1039 &gEfiPeiCapsulePpiGuid,\r
1040 (EFI_PEI_CAPSULE_PPI *) &mCapsulePpi\r
da58b0db 1041};\r
1042\r
1043/**\r
1044 Entry point function for the PEIM\r
1045\r
1046 @param FileHandle Handle of the file being invoked.\r
1047 @param PeiServices Describes the list of possible PEI Services.\r
1048\r
1049 @return EFI_SUCCESS If we installed our PPI\r
1050\r
1051**/\r
1052EFI_STATUS\r
1053EFIAPI\r
1054CapsuleMain (\r
1055 IN EFI_PEI_FILE_HANDLE FileHandle,\r
1056 IN CONST EFI_PEI_SERVICES **PeiServices\r
1057 )\r
1058{\r
1059 //\r
1060 // Just produce our PPI\r
1061 //\r
1062 return PeiServicesInstallPpi (&mUefiPpiListCapsule);\r
1063}\r