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