TianoCore EDK2 master
Loading...
Searching...
No Matches
FirmwareVolumePei.c
1/*++ @file
2
3Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
4Portions copyright (c) 2011, Apple Inc. All rights reserved.
5SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include "PiPei.h"
10#include <Ppi/EmuThunk.h>
11#include <Library/DebugLib.h>
13#include <Library/HobLib.h>
16#include <Library/PcdLib.h>
17
19EFIAPI
20PeimInitializeFirmwareVolumePei (
21 IN EFI_PEI_FILE_HANDLE FileHandle,
22 IN CONST EFI_PEI_SERVICES **PeiServices
23 )
24
25/*++
26
27Routine Description:
28 Perform a call-back into the SEC simulator to get address of the Firmware Hub
29
30Arguments:
31 FfsHeader - Ffs Header available to every PEIM
32 PeiServices - General purpose services available to every PEIM.
33
34Returns:
35 None
36
37**/
38{
39 EFI_STATUS Status;
40 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
41 EMU_THUNK_PPI *Thunk;
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 //
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 //
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}
UINT64 UINTN
VOID EFIAPI BuildResourceDescriptorHob(IN EFI_RESOURCE_TYPE ResourceType, IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute, IN EFI_PHYSICAL_ADDRESS PhysicalStart, IN UINT64 NumberOfBytes)
Definition: HobLib.c:299
VOID EFIAPI BuildFvHob(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
Definition: HobLib.c:404
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29