1. Rename PeiCoreLib to PeiServicesLib and rename all the interfaces from PeiCoreXXX...
[mirror_edk2.git] / EdkNt32Pkg / Pei / FirmwareVolume / 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 #include <FlashLayout.h>
24
25
26 EFI_STATUS
27 EFIAPI
28 PeimInitializeWinNtFwh (
29 IN EFI_FFS_FILE_HEADER *FfsHeader,
30 IN EFI_PEI_SERVICES **PeiServices
31 )
32 /*++
33
34 Routine Description:
35 Perform a call-back into the SEC simulator to get address of the Firmware Hub
36
37 Arguments:
38 FfsHeader - Ffs Header availible to every PEIM
39 PeiServices - General purpose services available to every PEIM.
40
41 Returns:
42 None
43
44 --*/
45 {
46 EFI_STATUS Status;
47 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
48 NT_FWH_PPI *FwhPpi;
49 EFI_PHYSICAL_ADDRESS FdBase;
50 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
51 UINT64 FdSize;
52 UINTN Index;
53
54 DEBUG ((EFI_D_ERROR, "NT 32 Firmware Volume PEIM Loaded\n"));
55
56 //
57 // Get the Fwh Information PPI
58 //
59 Status = (**PeiServices).LocatePpi (
60 PeiServices,
61 &gNtFwhPpiGuid, // GUID
62 0, // INSTANCE
63 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
64 &FwhPpi // PPI
65 );
66 ASSERT_EFI_ERROR (Status);
67
68 Index = 0;
69 do {
70 //
71 // Get information about all the FD's in the system
72 //
73 Status = FwhPpi->NtFwh (Index, &FdBase, &FdSize);
74 if (!EFI_ERROR (Status)) {
75 //
76 // Assume the FD starts with an FV header
77 //
78 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FdBase;
79
80 //
81 // Make an FV Hob for the first FV in the FD
82 //
83 BuildFvHob (FdBase, FvHeader->FvLength);
84
85 if (Index == 0) {
86 //
87 // Assume the first FD was produced by the NT32.DSC
88 // All these strange offests are needed to keep in
89 // sync with the FlashMap and NT32.dsc file
90 //
91 BuildResourceDescriptorHob (
92 EFI_RESOURCE_FIRMWARE_DEVICE,
93 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
94 FdBase,
95 (FvHeader->FvLength + EFI_WINNT_RUNTIME_UPDATABLE_LENGTH + EFI_WINNT_FTW_SPARE_BLOCK_LENGTH)
96 );
97
98 //
99 // Hard code the address of the spare block and variable services.
100 // Assume it's a hard coded offset from FV0 in FD0.
101 //
102 FdBase = FdBase + EFI_WINNT_RUNTIME_UPDATABLE_OFFSET;
103 FdSize = EFI_WINNT_RUNTIME_UPDATABLE_LENGTH + EFI_WINNT_FTW_SPARE_BLOCK_LENGTH;
104
105 BuildFvHob (FdBase, FdSize);
106 } else {
107 //
108 // For other FD's just map them in.
109 //
110 BuildResourceDescriptorHob (
111 EFI_RESOURCE_FIRMWARE_DEVICE,
112 (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
113 FdBase,
114 FdSize
115 );
116 }
117 }
118
119 Index++;
120 } while (!EFI_ERROR (Status));
121
122 return Status;
123 }