]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/ReadOnlyVariable2ToReadOnlyVariableThunk/ReadOnlyVariable2ToReadOnlyVariableThunk.c
56b801227aec92981bef49077b53f7cf1cc09caa
[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 EFI_STATUS
79 EFIAPI
80 PeimInitializeReadOnlyVariable2 (
81 IN EFI_FFS_FILE_HEADER *FfsHeader,
82 IN EFI_PEI_SERVICES **PeiServices
83 )
84 /*++
85
86 Routine Description:
87
88 Provide the functionality of the variable services.
89
90 Arguments:
91
92 FfsHeadher - The FFS file header
93 PeiServices - General purpose services available to every PEIM.
94
95 Returns:
96
97 Status - EFI_SUCCESS if the interface could be successfully
98 installed
99
100 --*/
101 {
102 VOID *Interface;
103 EFI_STATUS Status;
104 //
105 // This thunk module can only be used together with a PI PEI core, as we
106 // assume PeiServices Pointer Table can be located in a standard way defined
107 // in PI spec.
108 //
109 ASSERT ((*PeiServices)->Hdr.Revision >= 0x00010000);
110
111 //
112 // Make sure ReadOnlyVariable2ToReadOnlyVariable module is not present. If so, the call chain will form a
113 // infinite loop: ReadOnlyVariable2 -> ReadOnlyVariable -> ReadOnlyVariable2 -> ....
114 //
115 Status = PeiServicesLocatePpi (&gPeiReadonlyVariableThunkPresentPpiGuid, 0, NULL, &Interface);
116 ASSERT (Status == EFI_NOT_FOUND);
117
118 Status = PeiServicesInstallPpi (&mReadOnlyVariableThunkPresent);
119 ASSERT_EFI_ERROR (Status);
120
121 //
122 // Publish the variable capability to other modules
123 //
124 return PeiServicesInstallPpi (&mPpiListVariable);
125 }
126
127 /**
128 Provide the read variable functionality of the variable services.
129
130 @param PeiServices General purpose services available to every PEIM.
131 @param VariableName The variable name
132 @param VendorGuid The vendor's GUID
133 @param Attributes Pointer to the attribute
134 @param DataSize Size of data
135 @param Data Pointer to data
136
137 @retval EFI_SUCCESS The interface could be successfully installed
138 @retval EFI_NOT_FOUND The variable could not be discovered
139 @retval EFI_BUFFER_TOO_SMALL The caller buffer is not large enough
140
141 **/
142 EFI_STATUS
143 EFIAPI
144 PeiGetVariable (
145 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
146 IN CONST CHAR16 *VariableName,
147 IN CONST EFI_GUID *VariableGuid,
148 OUT UINT32 *Attributes,
149 IN OUT UINTN *DataSize,
150 OUT VOID *Data
151 )
152 {
153 EFI_STATUS Status;
154 EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;
155
156 Status = PeiServicesLocatePpi (
157 &gEfiPeiReadOnlyVariablePpiGuid,
158 0,
159 NULL,
160 (VOID **)&ReadOnlyVariable
161 );
162 ASSERT_EFI_ERROR (Status);
163
164 return ReadOnlyVariable->PeiGetVariable (
165 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
166 (CHAR16 *)VariableName,
167 (EFI_GUID *)VariableGuid,
168 Attributes,
169 DataSize,
170 Data
171 );
172 }
173
174 /**
175 Provide the get next variable functionality of the variable services.
176
177 @param PeiServices General purpose services available to every PEIM.
178 @param VariabvleNameSize The variable name's size.
179 @param VariableName A pointer to the variable's name.
180 @param VariableGuid A pointer to the EFI_GUID structure.
181 @param VariableNameSize Size of the variable name
182 @param VariableName The variable name
183 @param VendorGuid The vendor's GUID
184
185 @retval EFI_SUCCESS The interface could be successfully installed
186 @retval EFI_NOT_FOUND The variable could not be discovered
187
188 **/
189 EFI_STATUS
190 EFIAPI
191 PeiGetNextVariableName (
192 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
193 IN OUT UINTN *VariableNameSize,
194 IN OUT CHAR16 *VariableName,
195 IN OUT EFI_GUID *VariableGuid
196 )
197 {
198 EFI_STATUS Status;
199 EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;
200
201 Status = PeiServicesLocatePpi (
202 &gEfiPeiReadOnlyVariablePpiGuid,
203 0,
204 NULL,
205 (VOID **)&ReadOnlyVariable
206 );
207 ASSERT_EFI_ERROR (Status);
208
209 return ReadOnlyVariable->PeiGetNextVariableName (
210 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
211 VariableNameSize,
212 VariableName,
213 VariableGuid
214 );
215 }