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 - 2010, Intel Corporation. All rights reserved.<BR>
15 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   Provide the read variable functionality of the variable services.
35 
36   @param  This                  A pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.
37   @param  VariableName          A pointer to a null-terminated string that is the variable's name.
38   @param  VariableGuid          A pointer to an EFI_GUID that is the variable's GUID. The combination of
39                                 VariableGuid and VariableName must be unique.
40   @param  Attributes            If non-NULL, on return, points to the variable's attributes.
41   @param  DataSize              On entry, points to the size in bytes of the Data buffer.
42                                 On return, points to the size of the data returned in Data.
43   @param  Data                  Points to the buffer which will hold the returned variable value.
44 
45   @retval EFI_SUCCESS           The interface could be successfully installed
46   @retval EFI_NOT_FOUND         The variable could not be discovered
47   @retval EFI_BUFFER_TOO_SMALL  The caller buffer is not large enough
48 
49 **/
50 EFI_STATUS
51 EFIAPI
PeiGetVariable(IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI * This,IN CONST CHAR16 * VariableName,IN CONST EFI_GUID * VariableGuid,OUT UINT32 * Attributes,IN OUT UINTN * DataSize,OUT VOID * Data)52 PeiGetVariable (
53   IN CONST  EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
54   IN CONST  CHAR16                          *VariableName,
55   IN CONST  EFI_GUID                        *VariableGuid,
56   OUT       UINT32                          *Attributes,
57   IN OUT    UINTN                           *DataSize,
58   OUT       VOID                            *Data
59   )
60 {
61   EFI_STATUS                     Status;
62   EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;
63 
64   Status = PeiServicesLocatePpi (
65              &gEfiPeiReadOnlyVariablePpiGuid,
66              0,
67              NULL,
68              (VOID **)&ReadOnlyVariable
69              );
70   ASSERT_EFI_ERROR (Status);
71 
72   return ReadOnlyVariable->PeiGetVariable (
73                              (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
74                              (CHAR16 *)VariableName,
75                              (EFI_GUID *)VariableGuid,
76                              Attributes,
77                              DataSize,
78                              Data
79                              );
80 }
81 
82 /**
83   Provide the get next variable functionality of the variable services.
84 
85   @param  This              A pointer to this instance of the EFI_PEI_READ_ONLY_VARIABLE2_PPI.
86 
87   @param  VariableNameSize  On entry, points to the size of the buffer pointed to by VariableName.
88   @param  VariableName      On entry, a pointer to a null-terminated string that is the variable's name.
89                             On return, points to the next variable's null-terminated name string.
90 
91   @param  VariableGuid      On entry, a pointer to an EFI_GUID that is the variable's GUID.
92                             On return, a pointer to the next variable's GUID.
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
PeiGetNextVariableName(IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI * This,IN OUT UINTN * VariableNameSize,IN OUT CHAR16 * VariableName,IN OUT EFI_GUID * VariableGuid)100 PeiGetNextVariableName (
101   IN CONST  EFI_PEI_READ_ONLY_VARIABLE2_PPI *This,
102   IN OUT UINTN                              *VariableNameSize,
103   IN OUT CHAR16                             *VariableName,
104   IN OUT EFI_GUID                           *VariableGuid
105   )
106 {
107   EFI_STATUS                     Status;
108   EFI_PEI_READ_ONLY_VARIABLE_PPI *ReadOnlyVariable;
109 
110   Status = PeiServicesLocatePpi (
111              &gEfiPeiReadOnlyVariablePpiGuid,
112              0,
113              NULL,
114              (VOID **)&ReadOnlyVariable
115              );
116   ASSERT_EFI_ERROR (Status);
117 
118   return ReadOnlyVariable->PeiGetNextVariableName (
119                              (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
120                              VariableNameSize,
121                              VariableName,
122                              VariableGuid
123                              );
124 }
125 
126 //
127 // Module globals
128 //
129 EFI_PEI_READ_ONLY_VARIABLE2_PPI mVariablePpi = {
130   PeiGetVariable,
131   PeiGetNextVariableName
132 };
133 
134 EFI_PEI_PPI_DESCRIPTOR     mPpiListVariable = {
135   (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
136   &gEfiPeiReadOnlyVariable2PpiGuid,
137   &mVariablePpi
138 };
139 
140 /**
141   User entry for this PEIM driver.
142 
143   @param  FileHandle  Handle of the file being invoked.
144   @param  PeiServices Describes the list of possible PEI Services.
145 
146   @retval EFI_SUCCESS ReadOnlyVariable2 PPI is successfully installed.
147   @return Others      ReadOnlyVariable2 PPI is not successfully installed.
148 
149 **/
150 EFI_STATUS
151 EFIAPI
PeimInitializeReadOnlyVariable2(IN EFI_PEI_FILE_HANDLE FileHandle,IN CONST EFI_PEI_SERVICES ** PeiServices)152 PeimInitializeReadOnlyVariable2 (
153   IN EFI_PEI_FILE_HANDLE       FileHandle,
154   IN CONST EFI_PEI_SERVICES    **PeiServices
155   )
156 {
157   //
158   // This thunk module can only be used together with a PI PEI core, as we
159   // assume PeiServices Pointer Table can be located in a standard way defined
160   // in PI spec.
161   //
162   ASSERT ((*PeiServices)->Hdr.Revision >= 0x00010000);
163 
164   //
165   // Developer should make sure ReadOnlyVariable2ToReadOnlyVariable module is not present. or else, the call chain will form a
166   // infinite loop: ReadOnlyVariable2 -> ReadOnlyVariable -> ReadOnlyVariable2 -> .....
167   //
168   //
169   // Publish the variable capability to other modules
170   //
171   return PeiServicesInstallPpi (&mPpiListVariable);
172 }
173