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