]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/Pei/PeiLib/FindFv.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Pei / PeiLib / FindFv.c
1 /*++
2
3 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
4 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
13 Module Name:
14
15 FindFv.c
16
17 Abstract:
18
19 Library function to find fv by hob.
20
21 --*/
22
23 #include "Tiano.h"
24 #include "Pei.h"
25 #include "PeiLib.h"
26 #include "PeiHobLib.h"
27 #include "EfiCommonLib.h"
28 #include EFI_GUID_DEFINITION (FirmwareFileSystem)
29
30 static
31 VOID *
32 FindFvGetHob (
33 IN UINT16 Type,
34 IN VOID *HobStart
35 )
36 /*++
37
38 Routine Description:
39
40 This function returns the first instance of a HOB type in a HOB list.
41
42 Arguments:
43
44 Type The HOB type to return.
45 HobStart The first HOB in the HOB list.
46
47 Returns:
48
49 HobStart There were no HOBs found with the requested type.
50 else Returns the first HOB with the matching type.
51
52 --*/
53 {
54 EFI_PEI_HOB_POINTERS Hob;
55
56 Hob.Raw = HobStart;
57 //
58 // Return input if not found
59 //
60 if (HobStart == NULL) {
61 return HobStart;
62 }
63
64 //
65 // Parse the HOB list, stop if end of list or matching type found.
66 //
67 while (!END_OF_HOB_LIST (Hob)) {
68
69 if (Hob.Header->HobType == Type) {
70 break;
71 }
72
73 Hob.Raw = GET_NEXT_HOB (Hob);
74 }
75
76 //
77 // Return input if not found
78 //
79 if (END_OF_HOB_LIST (Hob)) {
80 return HobStart;
81 }
82
83 return (VOID *) (Hob.Raw);
84 }
85
86 EFI_STATUS
87 EFIAPI
88 FindFv (
89 IN EFI_FIND_FV_PPI *This,
90 IN EFI_PEI_SERVICES **PeiServices,
91 IN OUT UINT8 *FvNumber,
92 IN OUT EFI_FIRMWARE_VOLUME_HEADER **FvAddress
93 )
94 /*++
95
96 Routine Description:
97
98 Search Fv which supports FFS.
99
100 Arguments:
101
102 This - Interface pointer that implement the Find Fv PPI
103
104 PeiServices - Pointer to the PEI Service Table
105
106 FvNumber - On input, the number of the fireware volume which supports FFS to locate
107 On output, the next FV number which supports FFS.
108
109 FVAddress - The address of the volume which supports FFS to discover
110
111 Returns:
112
113 EFI_SUCCESS - An addtional FV which supports FFS found
114 EFI_OUT_OF_RESOURCES - There are no fireware volume which supports FFS for given fvnumber
115 EFI_INVALID_PARAMETER - FvAddress is NULL
116
117 --*/
118 {
119 EFI_STATUS Status;
120 EFI_PEI_HOB_POINTERS HobStart;
121 EFI_PEI_HOB_POINTERS Hob;
122 EFI_HOB_FIRMWARE_VOLUME *FvHob;
123 UINT8 FvIndex;
124
125 if (FvAddress == NULL){
126 return EFI_INVALID_PARAMETER;
127 }
128
129 Hob.Raw = NULL;
130 FvIndex = 0;
131
132 //
133 // Get the Hob table pointer
134 //
135 Status = (*PeiServices)->GetHobList (
136 PeiServices,
137 (VOID **) &HobStart.Raw
138 );
139
140 if (EFI_ERROR (Status)) {
141 return EFI_OUT_OF_RESOURCES;
142 }
143
144 //
145 // Loop to search the wanted FirmwareVolume which supports FFS
146 //
147 //
148 while (FvIndex <= *FvNumber) {
149
150 Hob.Raw = FindFvGetHob (EFI_HOB_TYPE_FV, HobStart.Raw);
151
152 //
153 // If the Hob is not EFI_HOB_TYPE_FV, it indicates that
154 // we have finished all FV volumes search, and there is no
155 // the FFS FV specified by FvNumber.
156 //
157 if (Hob.Header->HobType != EFI_HOB_TYPE_FV) {
158 *FvNumber = 0;
159 return EFI_OUT_OF_RESOURCES;
160 }
161
162 HobStart.Raw = Hob.Raw + Hob.Header->HobLength;
163 FvHob = Hob.FirmwareVolume;
164 *FvAddress = (EFI_FIRMWARE_VOLUME_HEADER *) ((UINTN) FvHob->BaseAddress);
165 //
166 // Check if the FV supports FFS
167 //
168 if (EfiCompareGuid (&((*FvAddress)->FileSystemGuid), &gEfiFirmwareFileSystemGuid)) {
169 FvIndex++;
170 }
171 }
172
173 //
174 // Return the next FV number which supports FFS.
175 //
176 (*FvNumber)++;
177
178 return EFI_SUCCESS;
179
180 }