]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/ReadOnlyVariableOnReadOnlyVariable2Thunk/ReadOnlyVariableOnReadOnlyVariable2Thunk.c
Maintainers.txt: Remove EdkCompatibilityPkg information
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / ReadOnlyVariableOnReadOnlyVariable2Thunk / ReadOnlyVariableOnReadOnlyVariable2Thunk.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 - 2010, Intel Corporation. All rights reserved.<BR>
14 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 <Library/DebugLib.h>
29 #include <Library/PeiServicesLib.h>
30
31 /**
32 Provide the read variable functionality of the variable services.
33
34 @param[in] PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
35 @param[in] VariableName A NULL-terminated Unicode string that is the name of the vendor's variable.
36 @param[in] VendorGuid A unique identifier for the vendor.
37 @param[out] Attributes This OPTIONAL parameter may be either NULL or
38 a pointer to the location in which to return
39 the attributes bitmask for the variable.
40 @param[in, out] DataSize On input, the size in bytes of the return Data buffer.
41 On output, the size of data returned in Data.
42 @param[out] Data The buffer to return the contents of the variable.
43
44 @retval EFI_SUCCESS The interface could be successfully installed
45 @retval EFI_NOT_FOUND The variable could not be discovered
46 @retval EFI_BUFFER_TOO_SMALL The caller buffer is not large enough
47
48 **/
49 EFI_STATUS
50 EFIAPI
51 PeiGetVariable (
52 IN EFI_PEI_SERVICES **PeiServices,
53 IN CHAR16 *VariableName,
54 IN EFI_GUID *VendorGuid,
55 OUT UINT32 *Attributes OPTIONAL,
56 IN OUT UINTN *DataSize,
57 OUT VOID *Data
58 )
59 {
60 EFI_STATUS Status;
61 EFI_PEI_READ_ONLY_VARIABLE2_PPI *ReadOnlyVariable2;
62
63 Status = (*PeiServices)->LocatePpi (
64 (CONST EFI_PEI_SERVICES **)PeiServices,
65 &gEfiPeiReadOnlyVariable2PpiGuid,
66 0,
67 NULL,
68 (VOID **)&ReadOnlyVariable2
69 );
70 ASSERT_EFI_ERROR (Status);
71
72 return ReadOnlyVariable2->GetVariable (
73 ReadOnlyVariable2,
74 VariableName,
75 VendorGuid,
76 Attributes,
77 DataSize,
78 Data
79 );
80 }
81
82 /**
83 Provide the get next variable functionality of the variable services.
84
85 @param[in] PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.
86 @param[in, out] VariableNameSize The size of the VariableName buffer.
87 @param[in, out] VariableName On input, supplies the last VariableName that was
88 returned by GetNextVariableName(). On output, returns the Null-terminated
89 Unicode string of the current variable.
90 @param[in, out] VendorGuid On input, supplies the last VendorGuid that was
91 returned by GetNextVariableName(). On output, returns the VendorGuid
92 of the current variable.
93
94 @retval EFI_SUCCESS The interface could be successfully installed
95 @retval EFI_NOT_FOUND The variable could not be discovered
96
97 **/
98 EFI_STATUS
99 EFIAPI
100 PeiGetNextVariableName (
101 IN EFI_PEI_SERVICES **PeiServices,
102 IN OUT UINTN *VariableNameSize,
103 IN OUT CHAR16 *VariableName,
104 IN OUT EFI_GUID *VendorGuid
105 )
106 {
107 EFI_STATUS Status;
108 EFI_PEI_READ_ONLY_VARIABLE2_PPI *ReadOnlyVariable2;
109
110 Status = (*PeiServices)->LocatePpi (
111 (CONST EFI_PEI_SERVICES **)PeiServices,
112 &gEfiPeiReadOnlyVariable2PpiGuid,
113 0,
114 NULL,
115 (VOID **)&ReadOnlyVariable2
116 );
117 ASSERT_EFI_ERROR (Status);
118
119 return ReadOnlyVariable2->NextVariableName (
120 ReadOnlyVariable2,
121 VariableNameSize,
122 VariableName,
123 VendorGuid
124 );
125 }
126
127 //
128 // Module globals
129 //
130 EFI_PEI_READ_ONLY_VARIABLE_PPI mVariablePpi = {
131 PeiGetVariable,
132 PeiGetNextVariableName
133 };
134
135 EFI_PEI_PPI_DESCRIPTOR mPpiListVariable = {
136 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
137 &gEfiPeiReadOnlyVariablePpiGuid,
138 &mVariablePpi
139 };
140
141 /**
142 Standard entry point of a PEIM.
143
144 @param FileHandle Handle of the file being invoked.
145 @param PeiServices General purpose services available to every PEIM.
146
147 @retval EFI_SUCCESS If the gEfiPeiReadOnlyVariablePpiGuid interface could be successfully installed.
148
149 **/
150 EFI_STATUS
151 EFIAPI
152 PeimInitializeReadOnlyVariable (
153 IN EFI_PEI_FILE_HANDLE FileHandle,
154 IN CONST EFI_PEI_SERVICES **PeiServices
155 )
156 {
157 //
158 //Developer should make sure ReadOnlyVariableToReadOnlyVariable2 module is not present. If so, the call chain will form a
159 // infinite loop: ReadOnlyVariable -> ReadOnlyVariable2 -> ReadOnlyVariable -> ....
160 //
161 //
162 // Publish the variable capability to other modules
163 //
164 return (*PeiServices)->InstallPpi (PeiServices, &mPpiListVariable);
165 }