• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Entrypoint of Extended SAL variable service module.
3 
4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution.  The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #include "Variable.h"
16 #include "AuthService.h"
17 
18 //
19 // Don't use module globals after the SetVirtualAddress map is signaled
20 //
21 EFI_EVENT mEfiVirtualNotifyEvent;
22 
23 /**
24   Common entry for Extended SAL Variable Services Class.
25 
26   This is the common entry of all functions of Extended SAL Variable Services Class.
27 
28   @param[in]  FunctionId        The Function ID of member function in Extended SAL Variable Services Class.
29   @param[in]  Arg2              The 2nd parameter for SAL procedure call.
30   @param[in]  Arg3              The 3rd parameter for SAL procedure call.
31   @param[in]  Arg4              The 4th parameter for SAL procedure call.
32   @param[in]  Arg5              The 5th parameter for SAL procedure call.
33   @param[in]  Arg6              The 6th parameter for SAL procedure call.
34   @param[in]  Arg7              The 7th parameter for SAL procedure call.
35   @param[in]  Arg8              The 8th parameter for SAL procedure call.
36   @param[in]  VirtualMode       The current calling mode for this function.
37   @param[in]  Global            The context of this Extended SAL Variable Services Class call.
38 
39   @return                       The register of SAL.
40 
41 **/
42 SAL_RETURN_REGS
43 EFIAPI
EsalVariableCommonEntry(IN UINT64 FunctionId,IN UINT64 Arg2,IN UINT64 Arg3,IN UINT64 Arg4,IN UINT64 Arg5,IN UINT64 Arg6,IN UINT64 Arg7,IN UINT64 Arg8,IN BOOLEAN VirtualMode,IN ESAL_VARIABLE_GLOBAL * Global)44 EsalVariableCommonEntry (
45   IN  UINT64                                      FunctionId,
46   IN  UINT64                                      Arg2,
47   IN  UINT64                                      Arg3,
48   IN  UINT64                                      Arg4,
49   IN  UINT64                                      Arg5,
50   IN  UINT64                                      Arg6,
51   IN  UINT64                                      Arg7,
52   IN  UINT64                                      Arg8,
53   IN  BOOLEAN                                     VirtualMode,
54   IN  ESAL_VARIABLE_GLOBAL                        *Global
55   )
56 {
57   SAL_RETURN_REGS ReturnVal;
58 
59   ReturnVal.r9  = 0;
60   ReturnVal.r10 = 0;
61   ReturnVal.r11 = 0;
62 
63   switch (FunctionId) {
64   case EsalGetVariableFunctionId:
65     ReturnVal.Status = EsalGetVariable (
66                          (CHAR16 *) Arg2,
67                          (EFI_GUID *) Arg3,
68                          (UINT32 *) Arg4,
69                          (UINTN *) Arg5,
70                          (VOID *) Arg6,
71                          VirtualMode,
72                          Global
73                          );
74     return ReturnVal;
75 
76   case EsalGetNextVariableNameFunctionId:
77     ReturnVal.Status = EsalGetNextVariableName (
78                          (UINTN *) Arg2,
79                          (CHAR16 *) Arg3,
80                          (EFI_GUID *) Arg4,
81                          VirtualMode,
82                          Global
83                          );
84     return ReturnVal;
85 
86   case EsalSetVariableFunctionId:
87     ReturnVal.Status = EsalSetVariable (
88                          (CHAR16 *) Arg2,
89                          (EFI_GUID *) Arg3,
90                          (UINT32) Arg4,
91                          (UINTN) Arg5,
92                          (VOID *) Arg6,
93                          VirtualMode,
94                          Global
95                          );
96     return ReturnVal;
97 
98   case EsalQueryVariableInfoFunctionId:
99     ReturnVal.Status = EsalQueryVariableInfo (
100                          (UINT32) Arg2,
101                          (UINT64 *) Arg3,
102                          (UINT64 *) Arg4,
103                          (UINT64 *) Arg5,
104                          VirtualMode,
105                          Global
106                          );
107     return ReturnVal;
108 
109   default:
110     ReturnVal.Status = EFI_SAL_INVALID_ARGUMENT;
111     return ReturnVal;
112   }
113 }
114 
115 /**
116   Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
117 
118   This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
119   It convers pointer to new virtual address.
120 
121   @param[in]  Event        The event whose notification function is being invoked.
122   @param[in]  Context      The pointer to the notification function's context.
123 
124 **/
125 VOID
126 EFIAPI
VariableClassAddressChangeEvent(IN EFI_EVENT Event,IN VOID * Context)127 VariableClassAddressChangeEvent (
128   IN EFI_EVENT        Event,
129   IN VOID             *Context
130   )
131 {
132   UINTN Index;
133 
134   CopyMem (
135     &mVariableModuleGlobal->VariableGlobal[Virtual],
136     &mVariableModuleGlobal->VariableGlobal[Physical],
137     sizeof (VARIABLE_GLOBAL)
138     );
139 
140   EfiConvertPointer (
141     0x0,
142     (VOID **) &mVariableModuleGlobal->VariableGlobal[Virtual].NonVolatileVariableBase
143     );
144   EfiConvertPointer (
145     0x0,
146     (VOID **) &mVariableModuleGlobal->VariableGlobal[Virtual].VolatileVariableBase
147     );
148 
149   mVariableModuleGlobal->PlatformLangCodes[Virtual] = mVariableModuleGlobal->PlatformLangCodes[Physical];
150   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes[Virtual]);
151 
152   mVariableModuleGlobal->LangCodes[Virtual] = mVariableModuleGlobal->LangCodes[Physical];
153   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes[Virtual]);
154 
155   mVariableModuleGlobal->PlatformLang[Virtual] = mVariableModuleGlobal->PlatformLang[Physical];
156   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang[Virtual]);
157 
158   CopyMem (
159     mVariableModuleGlobal->VariableName[Virtual],
160     mVariableModuleGlobal->VariableName[Physical],
161     sizeof (mVariableModuleGlobal->VariableName[Physical])
162     );
163   for (Index = 0; Index < NUM_VAR_NAME; Index++) {
164     EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->VariableName[Virtual][Index]);
165   }
166 
167   mVariableModuleGlobal->GlobalVariableGuid[Virtual] = &gEfiGlobalVariableGuid;
168   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->GlobalVariableGuid[Virtual]);
169 
170   mVariableModuleGlobal->AuthenticatedVariableGuid[Virtual] = &gEfiAuthenticatedVariableGuid;
171   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->AuthenticatedVariableGuid[Virtual]);
172 
173   mVariableModuleGlobal->CertRsa2048Sha256Guid[Virtual] = &gEfiCertRsa2048Sha256Guid;
174   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->CertRsa2048Sha256Guid[Virtual]);
175 
176   mVariableModuleGlobal->ImageSecurityDatabaseGuid[Virtual] = &gEfiImageSecurityDatabaseGuid;
177   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->ImageSecurityDatabaseGuid[Virtual]);
178 
179   mVariableModuleGlobal->HashContext[Virtual] = mVariableModuleGlobal->HashContext[Physical];
180   EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->HashContext[Virtual]);
181 }
182 
183 /**
184   Entry point of Extended SAL Variable service module.
185 
186   This function is the entry point of Extended SAL Variable service module.
187   It registers all functions of Extended SAL Variable class, initializes
188   variable store for non-volatile and volatile variables, and registers
189   notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.
190 
191   @param[in]  ImageHandle   The Image handle of this driver.
192   @param[in]  SystemTable   The pointer of EFI_SYSTEM_TABLE.
193 
194   @retval     EFI_SUCCESS   Extended SAL Variable Services Class successfully registered.
195 
196 **/
197 EFI_STATUS
198 EFIAPI
VariableServiceInitialize(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)199 VariableServiceInitialize (
200   IN EFI_HANDLE         ImageHandle,
201   IN EFI_SYSTEM_TABLE   *SystemTable
202   )
203 {
204   EFI_STATUS  Status;
205 
206   Status = gBS->CreateEventEx (
207                   EVT_NOTIFY_SIGNAL,
208                   TPL_NOTIFY,
209                   VariableClassAddressChangeEvent,
210                   NULL,
211                   &gEfiEventVirtualAddressChangeGuid,
212                   &mEfiVirtualNotifyEvent
213                   );
214 
215   ASSERT_EFI_ERROR (Status);
216 
217   Status = VariableCommonInitialize (ImageHandle, SystemTable);
218   ASSERT_EFI_ERROR (Status);
219 
220   //
221   // Authenticated variable initialize
222   //
223   Status = AutenticatedVariableServiceInitialize ();
224   ASSERT_EFI_ERROR (Status);
225 
226   FlushHob2Nv ();
227 
228   //
229   // Register All the Functions with Extended SAL Variable Services Class
230   //
231   RegisterEsalClass (
232     EFI_EXTENDED_SAL_VARIABLE_SERVICES_PROTOCOL_GUID_LO,
233     EFI_EXTENDED_SAL_VARIABLE_SERVICES_PROTOCOL_GUID_HI,
234     mVariableModuleGlobal,
235     EsalVariableCommonEntry,
236     EsalGetVariableFunctionId,
237     EsalVariableCommonEntry,
238     EsalGetNextVariableNameFunctionId,
239     EsalVariableCommonEntry,
240     EsalSetVariableFunctionId,
241     EsalVariableCommonEntry,
242     EsalQueryVariableInfoFunctionId,
243     NULL
244     );
245 
246   return EFI_SUCCESS;
247 }
248