]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/FirmwareVolumePei/FirmwareVolumePei.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmulatorPkg / FirmwareVolumePei / FirmwareVolumePei.c
1 /*++ @file
2
3 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2011, Apple Inc. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "PiPei.h"
10 #include <Ppi/EmuThunk.h>
11 #include <Library/DebugLib.h>
12 #include <Library/PeimEntryPoint.h>
13 #include <Library/HobLib.h>
14 #include <Library/PeiServicesLib.h>
15 #include <Library/PeiServicesTablePointerLib.h>
16 #include <Library/PcdLib.h>
17
18 EFI_STATUS
19 EFIAPI
20 PeimInitializeFirmwareVolumePei (
21 IN EFI_PEI_FILE_HANDLE FileHandle,
22 IN CONST EFI_PEI_SERVICES **PeiServices
23 )
24
25 /*++
26
27 Routine Description:
28 Perform a call-back into the SEC simulator to get address of the Firmware Hub
29
30 Arguments:
31 FfsHeader - Ffs Header available to every PEIM
32 PeiServices - General purpose services available to every PEIM.
33
34 Returns:
35 None
36
37 **/
38 {
39 EFI_STATUS Status;
40 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
41 EMU_THUNK_PPI *Thunk;
42 EFI_PHYSICAL_ADDRESS FdBase;
43 EFI_PHYSICAL_ADDRESS FdFixUp;
44 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
45 UINT64 FdSize;
46 UINTN Index;
47
48 DEBUG ((DEBUG_ERROR, "Unix Firmware Volume PEIM Loaded\n"));
49
50 //
51 // Get the Fwh Information PPI
52 //
53 Status = PeiServicesLocatePpi (
54 &gEmuThunkPpiGuid, // GUID
55 0, // INSTANCE
56 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
57 (VOID **)&Thunk // PPI
58 );
59 ASSERT_EFI_ERROR (Status);
60
61 Index = 0;
62 do {
63 //
64 // Get information about all the FD's in the system
65 //
66 Status = Thunk->FirmwareDevices (Index, &FdBase, &FdSize, &FdFixUp);
67 if (!EFI_ERROR (Status)) {
68 //
69 // Assume the FD starts with an FV header
70 //
71 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FdBase;
72
73 //
74 // Make an FV Hob for the first FV in the FD
75 //
76 BuildFvHob (FdBase, FvHeader->FvLength);
77
78 if (Index == 0) {
79 //
80 // Assume the first FD was produced by the NT32.DSC
81 // All these strange offests are needed to keep in
82 // sync with the FlashMap and NT32.dsc file
83 //
84 BuildResourceDescriptorHob (
85 EFI_RESOURCE_FIRMWARE_DEVICE,
86 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
87 FdBase,
88 (
89 FvHeader->FvLength +
90 PcdGet32 (PcdFlashNvStorageVariableSize) +
91 PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
92 PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
93 PcdGet32 (PcdEmuFlashNvStorageEventLogSize)
94 )
95 );
96
97 //
98 // Hard code the address of the spare block and variable services.
99 // Assume it's a hard coded offset from FV0 in FD0.
100 //
101 FdSize =
102 PcdGet32 (PcdFlashNvStorageVariableSize) +
103 PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
104 PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
105 PcdGet32 (PcdEmuFlashNvStorageEventLogSize);
106
107 BuildFvHob (FdFixUp + PcdGet64 (PcdEmuFlashNvStorageVariableBase), FdSize);
108 } else {
109 //
110 // For other FD's just map them in.
111 //
112 BuildResourceDescriptorHob (
113 EFI_RESOURCE_FIRMWARE_DEVICE,
114 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
115 FdBase,
116 FdSize
117 );
118 }
119 }
120
121 Index++;
122 } while (!EFI_ERROR (Status));
123
124 return Status;
125 }