]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/FirmwareVolumePei/FirmwareVolumePei.c
a7f548b00e79ceb36bad6b9f68da57287323c3d5
[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 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "PiPei.h"
16 #include <Ppi/EmuThunk.h>
17 #include <Library/DebugLib.h>
18 #include <Library/PeimEntryPoint.h>
19 #include <Library/HobLib.h>
20 #include <Library/PeiServicesLib.h>
21 #include <Library/PeiServicesTablePointerLib.h>
22 #include <Library/PcdLib.h>
23
24 EFI_STATUS
25 EFIAPI
26 PeimInitializeFirmwareVolumePei (
27 IN EFI_PEI_FILE_HANDLE FileHandle,
28 IN CONST EFI_PEI_SERVICES **PeiServices
29 )
30 /*++
31
32 Routine Description:
33 Perform a call-back into the SEC simulator to get address of the Firmware Hub
34
35 Arguments:
36 FfsHeader - Ffs Header available to every PEIM
37 PeiServices - General purpose services available to every PEIM.
38
39 Returns:
40 None
41
42 **/
43 {
44 EFI_STATUS Status;
45 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
46 EMU_THUNK_PPI *Thunk;
47 EFI_PHYSICAL_ADDRESS FdBase;
48 EFI_PHYSICAL_ADDRESS FdFixUp;
49 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
50 UINT64 FdSize;
51 UINTN Index;
52
53 DEBUG ((EFI_D_ERROR, "Unix Firmware Volume PEIM Loaded\n"));
54
55 //
56 // Get the Fwh Information PPI
57 //
58 Status = PeiServicesLocatePpi (
59 &gEmuThunkPpiGuid, // GUID
60 0, // INSTANCE
61 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
62 (VOID **)&Thunk // PPI
63 );
64 ASSERT_EFI_ERROR (Status);
65
66 Index = 0;
67 do {
68 //
69 // Get information about all the FD's in the system
70 //
71 Status = Thunk->FirmwareDevices (Index, &FdBase, &FdSize, &FdFixUp);
72 if (!EFI_ERROR (Status)) {
73 //
74 // Assume the FD starts with an FV header
75 //
76 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FdBase;
77
78 //
79 // Make an FV Hob for the first FV in the FD
80 //
81 BuildFvHob (FdBase, FvHeader->FvLength);
82
83 if (Index == 0) {
84 //
85 // Assume the first FD was produced by the NT32.DSC
86 // All these strange offests are needed to keep in
87 // sync with the FlashMap and NT32.dsc file
88 //
89 BuildResourceDescriptorHob (
90 EFI_RESOURCE_FIRMWARE_DEVICE,
91 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
92 FdBase,
93 (
94 FvHeader->FvLength +
95 PcdGet32 (PcdFlashNvStorageVariableSize) +
96 PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
97 PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
98 PcdGet32 (PcdEmuFlashNvStorageEventLogSize)
99 )
100 );
101
102 //
103 // Hard code the address of the spare block and variable services.
104 // Assume it's a hard coded offset from FV0 in FD0.
105 //
106 FdSize =
107 PcdGet32 (PcdFlashNvStorageVariableSize) +
108 PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
109 PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
110 PcdGet32 (PcdEmuFlashNvStorageEventLogSize);
111
112 BuildFvHob (FdFixUp + PcdGet64 (PcdEmuFlashNvStorageVariableBase), FdSize);
113 } else {
114 //
115 // For other FD's just map them in.
116 //
117 BuildResourceDescriptorHob (
118 EFI_RESOURCE_FIRMWARE_DEVICE,
119 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
120 FdBase,
121 FdSize
122 );
123 }
124 }
125
126 Index++;
127 } while (!EFI_ERROR (Status));
128
129 return Status;
130 }