]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/ReadOnlyVariableToReadOnlyVariable2Thunk/ReadOnlyVariableToReadOnlyVariable2Thunk.c
fcb6fb53f1e0df6443f3d0e20fbfafed6cc1ca57
[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 /**
70 Standard entry point of a PEIM.
71
72 @param FfsHeadher The FFS file header
73 @param PeiServices General purpose services available to every PEIM.
74
75 @retval EFI_SUCCESS If the gEfiPeiReadOnlyVariablePpiGuid interface could be successfully installed.
76
77 **/
78 EFI_STATUS
79 EFIAPI
80 PeimInitializeReadOnlyVariable (
81 IN EFI_PEI_FILE_HANDLE FfsHeader,
82 IN CONST EFI_PEI_SERVICES **PeiServices
83 )
84 {
85 VOID *Interface;
86 EFI_STATUS Status;
87
88 //
89 // Make sure ReadOnlyVariableToReadOnlyVariable2 module is not present. If so, the call chain will form a
90 // infinite loop: ReadOnlyVariable -> ReadOnlyVariable2 -> ReadOnlyVariable -> ....
91 //
92 Status = PeiServicesLocatePpi (&gPeiReadonlyVariableThunkPresentPpiGuid, 0, NULL, &Interface);
93 ASSERT (Status == EFI_NOT_FOUND);
94
95 //
96 // Publish the variable capability to other modules
97 //
98 return (*PeiServices)->InstallPpi (PeiServices, &mPpiListVariable);
99 }
100
101 /**
102 Provide the read variable functionality of the variable services.
103
104 @param PeiServices General purpose services available to every PEIM.
105 @param VariableName The variable name
106 @param VendorGuid The vendor's GUID
107 @param Attributes Pointer to the attribute
108 @param DataSize Size of data
109 @param Data Pointer to data
110
111 @retval EFI_SUCCESS The interface could be successfully installed
112 @retval EFI_NOT_FOUND The variable could not be discovered
113 @retval EFI_BUFFER_TOO_SMALL The caller buffer is not large enough
114
115 **/
116 EFI_STATUS
117 EFIAPI
118 PeiGetVariable (
119 IN EFI_PEI_SERVICES **PeiServices,
120 IN CHAR16 *VariableName,
121 IN EFI_GUID *VendorGuid,
122 OUT UINT32 *Attributes OPTIONAL,
123 IN OUT UINTN *DataSize,
124 OUT VOID *Data
125 )
126 {
127 EFI_STATUS Status;
128 EFI_PEI_READ_ONLY_VARIABLE2_PPI *ReadOnlyVariable2;
129
130 Status = (*PeiServices)->LocatePpi (
131 (CONST EFI_PEI_SERVICES **)PeiServices,
132 &gEfiPeiReadOnlyVariable2PpiGuid,
133 0,
134 NULL,
135 (VOID **)&ReadOnlyVariable2
136 );
137 ASSERT_EFI_ERROR (Status);
138
139 return ReadOnlyVariable2->GetVariable (
140 ReadOnlyVariable2,
141 VariableName,
142 VendorGuid,
143 Attributes,
144 DataSize,
145 Data
146 );
147 }
148
149 /**
150 Provide the get next variable functionality of the variable services.
151
152 @param PeiServices General purpose services available to every PEIM.
153 @param VariabvleNameSize The variable name's size.
154 @param VariableName A pointer to the variable's name.
155 @param VariableGuid A pointer to the EFI_GUID structure.
156 @param VariableNameSize Size of the variable name
157 @param VariableName The variable name
158 @param VendorGuid The vendor's GUID
159
160 @retval EFI_SUCCESS The interface could be successfully installed
161 @retval EFI_NOT_FOUND The variable could not be discovered
162
163 **/
164 EFI_STATUS
165 EFIAPI
166 PeiGetNextVariableName (
167 IN EFI_PEI_SERVICES **PeiServices,
168 IN OUT UINTN *VariableNameSize,
169 IN OUT CHAR16 *VariableName,
170 IN OUT EFI_GUID *VendorGuid
171 )
172 {
173 EFI_STATUS Status;
174 EFI_PEI_READ_ONLY_VARIABLE2_PPI *ReadOnlyVariable2;
175
176 Status = (*PeiServices)->LocatePpi (
177 (CONST EFI_PEI_SERVICES **)PeiServices,
178 &gEfiPeiReadOnlyVariable2PpiGuid,
179 0,
180 NULL,
181 (VOID **)&ReadOnlyVariable2
182 );
183 ASSERT_EFI_ERROR (Status);
184
185 return ReadOnlyVariable2->NextVariableName (
186 ReadOnlyVariable2,
187 VariableNameSize,
188 VariableName,
189 VendorGuid
190 );
191 }