]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Compatibility/ReadOnlyVariable2ToReadOnlyVariableThunk/ReadOnlyVariable2ToReadOnlyVariableThunk.c
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6130 6f19259b...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / ReadOnlyVariable2ToReadOnlyVariableThunk / ReadOnlyVariable2ToReadOnlyVariableThunk.c
CommitLineData
6c45955b 1/** @file\r
2Module produce EFI_PEI_READ_ONLY_VARIABLE2_PPI on top of EFI_PEI_READ_ONLY_VARIABLE_PPI.\r
3UEFI PI Spec supersedes Intel's Framework Specs. \r
4EFI_PEI_READ_ONLY_VARIABLE_PPI defined in Intel Framework Pkg is replaced by EFI_PEI_READ_ONLY_VARIABLE2_PPI\r
5in MdePkg.\r
6This module produces EFI_PEI_READ_ONLY_VARIABLE2_PPI on top of EFI_PEI_READ_ONLY_VARIABLE_PPI. \r
7This module is used on platform when both of these two conditions are true:\r
81) Framework module produces EFI_PEI_READ_ONLY_VARIABLE_PPI is present.\r
92) The platform has PI modules that only consumes EFI_PEI_READ_ONLY_VARIABLE2_PPI.\r
10\r
11This module can't be used together with ReadOnlyVariableToReadOnlyVariable2Thunk module.\r
12\r
4259256b 13\r
14Copyright (c) 2006 - 2008 Intel Corporation. <BR>\r
15All rights reserved. This program and the accompanying materials\r
16are licensed and made available under the terms and conditions of the BSD License\r
17which accompanies this distribution. The full text of the license may be found at\r
18http://opensource.org/licenses/bsd-license.php\r
19\r
20THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
21WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
22Module Name:\r
23\r
6c45955b 24**/\r
4259256b 25\r
26#include <PiPei.h>\r
27#include <Ppi/ReadOnlyVariable2.h>\r
28#include <Ppi/ReadOnlyVariable.h>\r
6c45955b 29#include <Ppi/ReadOnlyVariableThunkPresent.h>\r
4259256b 30#include <Library/DebugLib.h>\r
31#include <Library/PeiServicesTablePointerLib.h>\r
32#include <Library/PeiServicesLib.h>\r
33\r
34//\r
35// Function Prototypes\r
36//\r
37EFI_STATUS\r
38EFIAPI\r
39PeiGetVariable (\r
40 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
41 IN CONST CHAR16 *VariableName,\r
42 IN CONST EFI_GUID *VariableGuid,\r
43 OUT UINT32 *Attributes,\r
44 IN OUT UINTN *DataSize,\r
45 OUT VOID *Data\r
46 );\r
47\r
48EFI_STATUS\r
49EFIAPI\r
50PeiGetNextVariableName (\r
51 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
52 IN OUT UINTN *VariableNameSize,\r
53 IN OUT CHAR16 *VariableName,\r
54 IN OUT EFI_GUID *VariableGuid\r
55 );\r
56\r
57//\r
58// Module globals\r
59//\r
60EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi = {\r
61 PeiGetVariable,\r
62 PeiGetNextVariableName\r
63};\r
64\r
65EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = {\r
66 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
67 &gEfiPeiReadOnlyVariable2PpiGuid,\r
68 &mVariablePpi\r
69};\r
70\r
6c45955b 71\r
72EFI_PEI_PPI_DESCRIPTOR mReadOnlyVariableThunkPresent = {\r
73 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
74 &gPeiReadonlyVariableThunkPresentPpiGuid,\r
75 NULL\r
f21c3770 76};\r
6c45955b 77\r
4259256b 78EFI_STATUS\r
79EFIAPI\r
80PeimInitializeReadOnlyVariable2 (\r
81 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
82 IN EFI_PEI_SERVICES **PeiServices\r
83 )\r
84/*++\r
85\r
86Routine Description:\r
87\r
88 Provide the functionality of the variable services.\r
89\r
90Arguments:\r
91\r
92 FfsHeadher - The FFS file header\r
93 PeiServices - General purpose services available to every PEIM.\r
94\r
95Returns:\r
96\r
97 Status - EFI_SUCCESS if the interface could be successfully\r
98 installed\r
99\r
100--*/\r
101{\r
6c45955b 102 VOID *Interface;\r
103 EFI_STATUS Status;\r
9d5eaca4 104 //\r
105 // This thunk module can only be used together with a PI PEI core, as we \r
106 // assume PeiServices Pointer Table can be located in a standard way defined\r
107 // in PI spec.\r
108 //\r
109 ASSERT ((*PeiServices)->Hdr.Revision >= 0x00010000);\r
6c45955b 110\r
111 //\r
112 // Make sure ReadOnlyVariable2ToReadOnlyVariable module is not present. If so, the call chain will form a\r
113 // infinite loop: ReadOnlyVariable2 -> ReadOnlyVariable -> ReadOnlyVariable2 -> ....\r
114 //\r
115 Status = PeiServicesLocatePpi (&gPeiReadonlyVariableThunkPresentPpiGuid, 0, NULL, &Interface);\r
116 ASSERT (Status == EFI_NOT_FOUND);\r
117 \r
f21c3770 118 Status = PeiServicesInstallPpi (&mReadOnlyVariableThunkPresent);\r
119 ASSERT_EFI_ERROR (Status);\r
120 \r
4259256b 121 //\r
122 // Publish the variable capability to other modules\r
123 //\r
124 return PeiServicesInstallPpi (&mPpiListVariable);\r
125}\r
126\r
2be3c946 127/**\r
128 Provide the read variable functionality of the variable services.\r
129\r
130 @param PeiServices General purpose services available to every PEIM.\r
131 @param VariableName The variable name\r
132 @param VendorGuid The vendor's GUID\r
133 @param Attributes Pointer to the attribute\r
134 @param DataSize Size of data\r
135 @param Data Pointer to data\r
136\r
137 @retval EFI_SUCCESS The interface could be successfully installed\r
138 @retval EFI_NOT_FOUND The variable could not be discovered\r
139 @retval EFI_BUFFER_TOO_SMALL The caller buffer is not large enough\r
140\r
141**/\r
4259256b 142EFI_STATUS\r
143EFIAPI\r
144PeiGetVariable (\r
145 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
146 IN CONST CHAR16 *VariableName,\r
147 IN CONST EFI_GUID *VariableGuid,\r
148 OUT UINT32 *Attributes,\r
149 IN OUT UINTN *DataSize,\r
150 OUT VOID *Data\r
151 )\r
4259256b 152{\r
153 EFI_STATUS Status;\r
154 EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;\r
155\r
156 Status = PeiServicesLocatePpi (\r
157 &gEfiPeiReadOnlyVariablePpiGuid,\r
158 0,\r
159 NULL,\r
160 (VOID **)&ReadOnlyVariable\r
161 );\r
162 ASSERT_EFI_ERROR (Status);\r
163\r
164 return ReadOnlyVariable->PeiGetVariable (\r
165 GetPeiServicesTablePointer (),\r
166 (CHAR16 *)VariableName,\r
167 (EFI_GUID *)VariableGuid,\r
168 Attributes,\r
169 DataSize,\r
170 Data\r
171 );\r
172}\r
173\r
2be3c946 174/**\r
175 Provide the get next variable functionality of the variable services.\r
176\r
177 @param PeiServices General purpose services available to every PEIM.\r
178 @param VariabvleNameSize The variable name's size.\r
179 @param VariableName A pointer to the variable's name.\r
180 @param VariableGuid A pointer to the EFI_GUID structure.\r
181 @param VariableNameSize Size of the variable name\r
182 @param VariableName The variable name\r
183 @param VendorGuid The vendor's GUID\r
184\r
185 @retval EFI_SUCCESS The interface could be successfully installed\r
186 @retval EFI_NOT_FOUND The variable could not be discovered\r
187\r
188**/\r
4259256b 189EFI_STATUS\r
190EFIAPI\r
191PeiGetNextVariableName (\r
192 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,\r
193 IN OUT UINTN *VariableNameSize,\r
194 IN OUT CHAR16 *VariableName,\r
195 IN OUT EFI_GUID *VariableGuid\r
196 )\r
4259256b 197{\r
198 EFI_STATUS Status;\r
199 EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;\r
200\r
201 Status = PeiServicesLocatePpi (\r
202 &gEfiPeiReadOnlyVariablePpiGuid,\r
203 0,\r
204 NULL,\r
205 (VOID **)&ReadOnlyVariable\r
206 );\r
207 ASSERT_EFI_ERROR (Status);\r
208\r
209 return ReadOnlyVariable->PeiGetNextVariableName (\r
210 GetPeiServicesTablePointer (),\r
211 VariableNameSize,\r
212 VariableName,\r
213 VariableGuid\r
214 );\r
215}\r