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