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