]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/ReadOnlyVariable2OnReadOnlyVariableThunk/ReadOnlyVariable2OnReadOnlyVariableThunk.c
adeddbc00e1ebb90ea5229a556f045dc158d0e37
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / ReadOnlyVariable2OnReadOnlyVariableThunk / ReadOnlyVariable2OnReadOnlyVariableThunk.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 <Library/DebugLib.h>
30 #include <Library/PeiServicesTablePointerLib.h>
31 #include <Library/PeiServicesLib.h>
32
33 //
34 // Function Prototypes
35 //
36 EFI_STATUS
37 EFIAPI
38 PeiGetVariable (
39 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
40 IN CONST CHAR16 *VariableName,
41 IN CONST EFI_GUID *VariableGuid,
42 OUT UINT32 *Attributes,
43 IN OUT UINTN *DataSize,
44 OUT VOID *Data
45 );
46
47 EFI_STATUS
48 EFIAPI
49 PeiGetNextVariableName (
50 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
51 IN OUT UINTN *VariableNameSize,
52 IN OUT CHAR16 *VariableName,
53 IN OUT EFI_GUID *VariableGuid
54 );
55
56 //
57 // Module globals
58 //
59 EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi = {
60 PeiGetVariable,
61 PeiGetNextVariableName
62 };
63
64 EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = {
65 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
66 &gEfiPeiReadOnlyVariable2PpiGuid,
67 &mVariablePpi
68 };
69
70
71 /**
72 User entry for this PEIM driver.
73
74 @param FileHandle Handle of the file being invoked.
75 @param PeiServices Describes the list of possible PEI Services.
76
77 @retval EFI_SUCCESS ReadOnlyVariable2 PPI is successfully installed.
78 @return Others ReadOnlyVariable2 PPI is not successfully installed.
79
80 **/
81 EFI_STATUS
82 EFIAPI
83 PeimInitializeReadOnlyVariable2 (
84 IN EFI_PEI_FILE_HANDLE FfsHeader,
85 IN CONST EFI_PEI_SERVICES **PeiServices
86 )
87 {
88 //
89 // This thunk module can only be used together with a PI PEI core, as we
90 // assume PeiServices Pointer Table can be located in a standard way defined
91 // in PI spec.
92 //
93 ASSERT ((*PeiServices)->Hdr.Revision >= 0x00010000);
94
95 //
96 // Developer should make sure ReadOnlyVariable2ToReadOnlyVariable module is not present. or else, the call chain will form a
97 // infinite loop: ReadOnlyVariable2 -> ReadOnlyVariable -> ReadOnlyVariable2 -> .....
98 //
99 //
100 // Publish the variable capability to other modules
101 //
102 return PeiServicesInstallPpi (&mPpiListVariable);
103 }
104
105 /**
106 Provide the read variable functionality of the variable services.
107
108 @param PeiServices General purpose services available to every PEIM.
109 @param VariableName The variable name
110 @param VendorGuid The vendor's GUID
111 @param Attributes Pointer to the attribute
112 @param DataSize Size of data
113 @param Data Pointer to data
114
115 @retval EFI_SUCCESS The interface could be successfully installed
116 @retval EFI_NOT_FOUND The variable could not be discovered
117 @retval EFI_BUFFER_TOO_SMALL The caller buffer is not large enough
118
119 **/
120 EFI_STATUS
121 EFIAPI
122 PeiGetVariable (
123 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
124 IN CONST CHAR16 *VariableName,
125 IN CONST EFI_GUID *VariableGuid,
126 OUT UINT32 *Attributes,
127 IN OUT UINTN *DataSize,
128 OUT VOID *Data
129 )
130 {
131 EFI_STATUS Status;
132 EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;
133
134 Status = PeiServicesLocatePpi (
135 &gEfiPeiReadOnlyVariablePpiGuid,
136 0,
137 NULL,
138 (VOID **)&ReadOnlyVariable
139 );
140 ASSERT_EFI_ERROR (Status);
141
142 return ReadOnlyVariable->PeiGetVariable (
143 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
144 (CHAR16 *)VariableName,
145 (EFI_GUID *)VariableGuid,
146 Attributes,
147 DataSize,
148 Data
149 );
150 }
151
152 /**
153 Provide the get next variable functionality of the variable services.
154
155 @param PeiServices General purpose services available to every PEIM.
156 @param VariabvleNameSize The variable name's size.
157 @param VariableName A pointer to the variable's name.
158 @param VariableGuid A pointer to the EFI_GUID structure.
159 @param VariableNameSize Size of the variable name
160 @param VariableName The variable name
161 @param VendorGuid The vendor's GUID
162
163 @retval EFI_SUCCESS The interface could be successfully installed
164 @retval EFI_NOT_FOUND The variable could not be discovered
165
166 **/
167 EFI_STATUS
168 EFIAPI
169 PeiGetNextVariableName (
170 IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
171 IN OUT UINTN *VariableNameSize,
172 IN OUT CHAR16 *VariableName,
173 IN OUT EFI_GUID *VariableGuid
174 )
175 {
176 EFI_STATUS Status;
177 EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;
178
179 Status = PeiServicesLocatePpi (
180 &gEfiPeiReadOnlyVariablePpiGuid,
181 0,
182 NULL,
183 (VOID **)&ReadOnlyVariable
184 );
185 ASSERT_EFI_ERROR (Status);
186
187 return ReadOnlyVariable->PeiGetNextVariableName (
188 (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
189 VariableNameSize,
190 VariableName,
191 VariableGuid
192 );
193 }