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
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>
20 PeimInitializeFirmwareVolumePei (
21 IN EFI_PEI_FILE_HANDLE FileHandle
,
22 IN CONST EFI_PEI_SERVICES
**PeiServices
27 Perform a call-back into the SEC simulator to get address of the Firmware Hub
30 FfsHeader - Ffs Header available to every PEIM
31 PeiServices - General purpose services available to every PEIM.
39 EFI_PEI_PPI_DESCRIPTOR
*PpiDescriptor
;
41 EFI_PHYSICAL_ADDRESS FdBase
;
42 EFI_PHYSICAL_ADDRESS FdFixUp
;
43 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
47 DEBUG ((EFI_D_ERROR
, "Unix Firmware Volume PEIM Loaded\n"));
50 // Get the Fwh Information PPI
52 Status
= PeiServicesLocatePpi (
53 &gEmuThunkPpiGuid
, // GUID
55 &PpiDescriptor
, // EFI_PEI_PPI_DESCRIPTOR
56 (VOID
**)&Thunk
// PPI
58 ASSERT_EFI_ERROR (Status
);
63 // Get information about all the FD's in the system
65 Status
= Thunk
->FirmwareDevices (Index
, &FdBase
, &FdSize
, &FdFixUp
);
66 if (!EFI_ERROR (Status
)) {
68 // Assume the FD starts with an FV header
70 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) (UINTN
) FdBase
;
73 // Make an FV Hob for the first FV in the FD
75 BuildFvHob (FdBase
, FvHeader
->FvLength
);
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
83 BuildResourceDescriptorHob (
84 EFI_RESOURCE_FIRMWARE_DEVICE
,
85 (EFI_RESOURCE_ATTRIBUTE_PRESENT
| EFI_RESOURCE_ATTRIBUTE_INITIALIZED
| EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
),
89 PcdGet32 (PcdFlashNvStorageVariableSize
) +
90 PcdGet32 (PcdFlashNvStorageFtwWorkingSize
) +
91 PcdGet32 (PcdFlashNvStorageFtwSpareSize
) +
92 PcdGet32 (PcdEmuFlashNvStorageEventLogSize
)
97 // Hard code the address of the spare block and variable services.
98 // Assume it's a hard coded offset from FV0 in FD0.
101 PcdGet32 (PcdFlashNvStorageVariableSize
) +
102 PcdGet32 (PcdFlashNvStorageFtwWorkingSize
) +
103 PcdGet32 (PcdFlashNvStorageFtwSpareSize
) +
104 PcdGet32 (PcdEmuFlashNvStorageEventLogSize
);
106 BuildFvHob (FdFixUp
+ PcdGet64 (PcdEmuFlashNvStorageVariableBase
), FdSize
);
109 // For other FD's just map them in.
111 BuildResourceDescriptorHob (
112 EFI_RESOURCE_FIRMWARE_DEVICE
,
113 (EFI_RESOURCE_ATTRIBUTE_PRESENT
| EFI_RESOURCE_ATTRIBUTE_INITIALIZED
| EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
),
121 } while (!EFI_ERROR (Status
));