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