Porting WinNtFwhPei and WinNtFlashMapPei to produce FvHob.
[mirror_edk2.git] / Nt32Pkg / WinNtFirmwareVolumePei / WinntFwh.c
1 /*++
2
3 Copyright (c) 2006, 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 WinNtFwh.c
14
15 Abstract:
16 PEIM to abstract construction of firmware volume in a Windows NT environment.
17
18 Revision History
19
20 --*/
21
22 //
23 // The package level header files this module uses
24 //
25 #include <PiPei.h>
26 #include <WinNtPeim.h>
27 //
28 // The protocols, PPI and GUID defintions for this module
29 //
30 #include <Ppi/NtFwh.h>
31 //
32 // The Library classes this module consumes
33 //
34 #include <Library/DebugLib.h>
35 #include <Library/PeimEntryPoint.h>
36 #include <Library/HobLib.h>
37
38 #include <FlashLayout.h>
39
40
41 EFI_STATUS
42 EFIAPI
43 PeimInitializeWinNtFwh (
44 IN EFI_FFS_FILE_HEADER *FfsHeader,
45 IN EFI_PEI_SERVICES **PeiServices
46 )
47 /*++
48
49 Routine Description:
50 Perform a call-back into the SEC simulator to get address of the Firmware Hub
51
52 Arguments:
53 FfsHeader - Ffs Header availible to every PEIM
54 PeiServices - General purpose services available to every PEIM.
55
56 Returns:
57 None
58
59 --*/
60 {
61 EFI_STATUS Status;
62 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
63 NT_FWH_PPI *FwhPpi;
64 EFI_PHYSICAL_ADDRESS FdBase;
65 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
66 UINT64 FdSize;
67 UINTN Index;
68
69 DEBUG ((EFI_D_ERROR, "NT 32 Firmware Volume PEIM Loaded\n"));
70
71 //
72 // Get the Fwh Information PPI
73 //
74 Status = (**PeiServices).LocatePpi (
75 PeiServices,
76 &gNtFwhPpiGuid, // GUID
77 0, // INSTANCE
78 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
79 &FwhPpi // PPI
80 );
81 ASSERT_EFI_ERROR (Status);
82
83 Index = 0;
84 do {
85 //
86 // Get information about all the FD's in the system
87 //
88 Status = FwhPpi->NtFwh (Index, &FdBase, &FdSize);
89 if (!EFI_ERROR (Status)) {
90 //
91 // Assume the FD starts with an FV header
92 //
93 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FdBase;
94
95 //
96 // Make an FV Hob for the first FV in the FD
97 //
98 BuildFvHob (FdBase, FvHeader->FvLength);
99
100 if (Index == 0) {
101 //
102 // Assume the first FD was produced by the NT32.DSC
103 // All these strange offests are needed to keep in
104 // sync with the FlashMap and NT32.dsc file
105 //
106 BuildResourceDescriptorHob (
107 EFI_RESOURCE_FIRMWARE_DEVICE,
108 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
109 FdBase,
110 (FvHeader->FvLength + EFI_WINNT_RUNTIME_UPDATABLE_LENGTH + EFI_WINNT_FTW_SPARE_BLOCK_LENGTH)
111 );
112
113 //
114 // Hard code the address of the spare block and variable services.
115 // Assume it's a hard coded offset from FV0 in FD0.
116 //
117 FdBase = FdBase + EFI_WINNT_RUNTIME_UPDATABLE_OFFSET;
118 FdSize = EFI_WINNT_RUNTIME_UPDATABLE_LENGTH + EFI_WINNT_FTW_SPARE_BLOCK_LENGTH;
119
120 BuildFvHob (FdBase, FdSize);
121 } else {
122 //
123 // For other FD's just map them in.
124 //
125 BuildResourceDescriptorHob (
126 EFI_RESOURCE_FIRMWARE_DEVICE,
127 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
128 FdBase,
129 FdSize
130 );
131 }
132 }
133
134 Index++;
135 } while (!EFI_ERROR (Status));
136
137 return Status;
138 }