Replace the FlashMapHob with PCD defined in FDF on Nt32 platform. Currently, the...
[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 #include <Library/PcdLib.h>
38
39 EFI_STATUS
40 EFIAPI
41 PeimInitializeWinNtFwh (
42 IN EFI_FFS_FILE_HEADER *FfsHeader,
43 IN EFI_PEI_SERVICES **PeiServices
44 )
45 /*++
46
47 Routine Description:
48 Perform a call-back into the SEC simulator to get address of the Firmware Hub
49
50 Arguments:
51 FfsHeader - Ffs Header availible to every PEIM
52 PeiServices - General purpose services available to every PEIM.
53
54 Returns:
55 None
56
57 --*/
58 {
59 EFI_STATUS Status;
60 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
61 NT_FWH_PPI *FwhPpi;
62 EFI_PHYSICAL_ADDRESS FdBase;
63 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
64 UINT64 FdSize;
65 UINTN Index;
66
67 DEBUG ((EFI_D_ERROR, "NT 32 Firmware Volume PEIM Loaded\n"));
68
69 //
70 // Get the Fwh Information PPI
71 //
72 Status = (**PeiServices).LocatePpi (
73 PeiServices,
74 &gNtFwhPpiGuid, // GUID
75 0, // INSTANCE
76 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
77 &FwhPpi // PPI
78 );
79 ASSERT_EFI_ERROR (Status);
80
81 Index = 0;
82 do {
83 //
84 // Get information about all the FD's in the system
85 //
86 Status = FwhPpi->NtFwh (Index, &FdBase, &FdSize);
87 if (!EFI_ERROR (Status)) {
88 //
89 // Assume the FD starts with an FV header
90 //
91 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FdBase;
92
93 //
94 // Make an FV Hob for the first FV in the FD
95 //
96 BuildFvHob (FdBase, FvHeader->FvLength);
97
98 if (Index == 0) {
99 //
100 // Assume the first FD was produced by the NT32.DSC
101 // All these strange offests are needed to keep in
102 // sync with the FlashMap and NT32.dsc file
103 //
104 BuildResourceDescriptorHob (
105 EFI_RESOURCE_FIRMWARE_DEVICE,
106 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
107 FdBase,
108 (
109 FvHeader->FvLength +
110 PcdGet32 (PcdFlashNvStorageVariableSize) +
111 PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
112 PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
113 PcdGet32 (PcdWinNtFlashNvStorageEventLogSize)
114 )
115 );
116 //
117 // Hard code the address of the spare block and variable services.
118 // Assume it's a hard coded offset from FV0 in FD0.
119 //
120 FdBase = FdBase + PcdGet32 (PcdWinNtFlashNvStorageVariableBase);
121 FdSize =
122 PcdGet32 (PcdFlashNvStorageVariableSize) +
123 PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
124 PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
125 PcdGet32 (PcdWinNtFlashNvStorageEventLogSize);
126
127 BuildFvHob (FdBase, FdSize);
128 } else {
129 //
130 // For other FD's just map them in.
131 //
132 BuildResourceDescriptorHob (
133 EFI_RESOURCE_FIRMWARE_DEVICE,
134 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
135 FdBase,
136 FdSize
137 );
138 }
139 }
140
141 Index++;
142 } while (!EFI_ERROR (Status));
143
144 return Status;
145 }