]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/FirmwareVolumePei/FirmwareVolumePei.c
EmulatorPkg: Replace BSD License with BSD+Patent License
[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 Routine Description:
27 Perform a call-back into the SEC simulator to get address of the Firmware Hub
28
29 Arguments:
30 FfsHeader - Ffs Header available to every PEIM
31 PeiServices - General purpose services available to every PEIM.
32
33 Returns:
34 None
35
36 **/
37 {
38 EFI_STATUS Status;
39 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
40 EMU_THUNK_PPI *Thunk;
41 EFI_PHYSICAL_ADDRESS FdBase;
42 EFI_PHYSICAL_ADDRESS FdFixUp;
43 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
44 UINT64 FdSize;
45 UINTN Index;
46
47 DEBUG ((EFI_D_ERROR, "Unix Firmware Volume PEIM Loaded\n"));
48
49 //
50 // Get the Fwh Information PPI
51 //
52 Status = PeiServicesLocatePpi (
53 &gEmuThunkPpiGuid, // GUID
54 0, // INSTANCE
55 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
56 (VOID **)&Thunk // PPI
57 );
58 ASSERT_EFI_ERROR (Status);
59
60 Index = 0;
61 do {
62 //
63 // Get information about all the FD's in the system
64 //
65 Status = Thunk->FirmwareDevices (Index, &FdBase, &FdSize, &FdFixUp);
66 if (!EFI_ERROR (Status)) {
67 //
68 // Assume the FD starts with an FV header
69 //
70 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FdBase;
71
72 //
73 // Make an FV Hob for the first FV in the FD
74 //
75 BuildFvHob (FdBase, FvHeader->FvLength);
76
77 if (Index == 0) {
78 //
79 // Assume the first FD was produced by the NT32.DSC
80 // All these strange offests are needed to keep in
81 // sync with the FlashMap and NT32.dsc file
82 //
83 BuildResourceDescriptorHob (
84 EFI_RESOURCE_FIRMWARE_DEVICE,
85 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
86 FdBase,
87 (
88 FvHeader->FvLength +
89 PcdGet32 (PcdFlashNvStorageVariableSize) +
90 PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
91 PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
92 PcdGet32 (PcdEmuFlashNvStorageEventLogSize)
93 )
94 );
95
96 //
97 // Hard code the address of the spare block and variable services.
98 // Assume it's a hard coded offset from FV0 in FD0.
99 //
100 FdSize =
101 PcdGet32 (PcdFlashNvStorageVariableSize) +
102 PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
103 PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
104 PcdGet32 (PcdEmuFlashNvStorageEventLogSize);
105
106 BuildFvHob (FdFixUp + PcdGet64 (PcdEmuFlashNvStorageVariableBase), FdSize);
107 } else {
108 //
109 // For other FD's just map them in.
110 //
111 BuildResourceDescriptorHob (
112 EFI_RESOURCE_FIRMWARE_DEVICE,
113 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
114 FdBase,
115 FdSize
116 );
117 }
118 }
119
120 Index++;
121 } while (!EFI_ERROR (Status));
122
123 return Status;
124 }