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