]>
Commit | Line | Data |
---|---|---|
504214c4 | 1 | /** @file\r |
8d3a5c82 | 2 | \r |
d1102dba | 3 | Implment all four UEFI runtime variable services and\r |
504214c4 | 4 | install variable architeture protocol.\r |
d1102dba LG |
5 | \r |
6 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
e5eed7d3 | 7 | This program and the accompanying materials\r |
8d3a5c82 | 8 | are licensed and made available under the terms and conditions of the BSD License\r |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
504214c4 | 15 | **/\r |
8d3a5c82 | 16 | \r |
17 | #include "Variable.h"\r | |
18 | \r | |
a1634424 | 19 | EFI_EVENT mVirtualAddressChangeEvent = NULL;\r |
20 | \r | |
1794e506 | 21 | /**\r |
22 | \r | |
23 | This code finds variable in storage blocks (Volatile or Non-Volatile).\r | |
24 | \r | |
25 | @param VariableName Name of Variable to be found.\r | |
26 | @param VendorGuid Variable vendor GUID.\r | |
27 | @param Attributes Attribute value of the variable found.\r | |
28 | @param DataSize Size of Data found. If size is less than the\r | |
29 | data, this value contains the required size.\r | |
dd59d95e SZ |
30 | @param Data The buffer to return the contents of the variable. May be NULL\r |
31 | with a zero DataSize in order to determine the size buffer needed.\r | |
d1102dba | 32 | \r |
1794e506 | 33 | @return EFI_INVALID_PARAMETER Invalid parameter\r |
34 | @return EFI_SUCCESS Find the specified variable\r | |
35 | @return EFI_NOT_FOUND Not found\r | |
36 | @return EFI_BUFFER_TO_SMALL DataSize is too small for the result\r | |
37 | \r | |
38 | **/\r | |
8d3a5c82 | 39 | EFI_STATUS\r |
40 | EFIAPI\r | |
41 | RuntimeServiceGetVariable (\r | |
42 | IN CHAR16 *VariableName,\r | |
1794e506 | 43 | IN EFI_GUID *VendorGuid,\r |
8d3a5c82 | 44 | OUT UINT32 *Attributes OPTIONAL,\r |
45 | IN OUT UINTN *DataSize,\r | |
dd59d95e | 46 | OUT VOID *Data OPTIONAL\r |
8d3a5c82 | 47 | )\r |
8d3a5c82 | 48 | {\r |
bd682470 | 49 | return EmuGetVariable (\r |
8d3a5c82 | 50 | VariableName,\r |
51 | VendorGuid,\r | |
52 | Attributes OPTIONAL,\r | |
53 | DataSize,\r | |
54 | Data,\r | |
72399dae | 55 | &mVariableModuleGlobal->VariableGlobal[Physical]\r |
8d3a5c82 | 56 | );\r |
57 | }\r | |
58 | \r | |
1794e506 | 59 | /**\r |
60 | \r | |
61 | This code Finds the Next available variable.\r | |
62 | \r | |
6f817f9b SZ |
63 | @param VariableNameSize The size of the VariableName buffer. The size must be large enough to fit input\r |
64 | string supplied in VariableName buffer.\r | |
65 | @param VariableName On input, supplies the last VariableName that was returned by GetNextVariableName().\r | |
66 | On output, returns the Null-terminated Unicode string of the current variable.\r | |
67 | @param VendorGuid On input, supplies the last VendorGuid that was returned by GetNextVariableName().\r | |
68 | On output, returns the VendorGuid of the current variable.\r | |
1794e506 | 69 | \r |
6f817f9b SZ |
70 | @retval EFI_SUCCESS The function completed successfully.\r |
71 | @retval EFI_NOT_FOUND The next variable was not found.\r | |
72 | @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the result.\r | |
73 | VariableNameSize has been updated with the size needed to complete the request.\r | |
74 | @retval EFI_INVALID_PARAMETER VariableNameSize or VariableName or VendorGuid is NULL.\r | |
75 | @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and\r | |
76 | GUID of an existing variable.\r | |
77 | @retval EFI_INVALID_PARAMETER Null-terminator is not found in the first VariableNameSize bytes of\r | |
78 | the input VariableName buffer.\r | |
1794e506 | 79 | \r |
80 | **/\r | |
8d3a5c82 | 81 | EFI_STATUS\r |
82 | EFIAPI\r | |
83 | RuntimeServiceGetNextVariableName (\r | |
84 | IN OUT UINTN *VariableNameSize,\r | |
85 | IN OUT CHAR16 *VariableName,\r | |
86 | IN OUT EFI_GUID *VendorGuid\r | |
87 | )\r | |
8d3a5c82 | 88 | {\r |
bd682470 | 89 | return EmuGetNextVariableName (\r |
8d3a5c82 | 90 | VariableNameSize,\r |
91 | VariableName,\r | |
92 | VendorGuid,\r | |
72399dae | 93 | &mVariableModuleGlobal->VariableGlobal[Physical]\r |
8d3a5c82 | 94 | );\r |
95 | }\r | |
96 | \r | |
1794e506 | 97 | /**\r |
98 | \r | |
99 | This code sets variable in storage blocks (Volatile or Non-Volatile).\r | |
100 | \r | |
101 | @param VariableName Name of Variable to be found\r | |
102 | @param VendorGuid Variable vendor GUID\r | |
103 | @param Attributes Attribute value of the variable found\r | |
104 | @param DataSize Size of Data found. If size is less than the\r | |
105 | data, this value contains the required size.\r | |
106 | @param Data Data pointer\r | |
107 | \r | |
108 | @return EFI_INVALID_PARAMETER Invalid parameter\r | |
109 | @return EFI_SUCCESS Set successfully\r | |
110 | @return EFI_OUT_OF_RESOURCES Resource not enough to set variable\r | |
111 | @return EFI_NOT_FOUND Not found\r | |
112 | @return EFI_WRITE_PROTECTED Variable is read-only\r | |
113 | \r | |
114 | **/\r | |
8d3a5c82 | 115 | EFI_STATUS\r |
116 | EFIAPI\r | |
117 | RuntimeServiceSetVariable (\r | |
118 | IN CHAR16 *VariableName,\r | |
119 | IN EFI_GUID *VendorGuid,\r | |
120 | IN UINT32 Attributes,\r | |
121 | IN UINTN DataSize,\r | |
122 | IN VOID *Data\r | |
123 | )\r | |
8d3a5c82 | 124 | {\r |
bd682470 | 125 | return EmuSetVariable (\r |
8d3a5c82 | 126 | VariableName,\r |
127 | VendorGuid,\r | |
128 | Attributes,\r | |
129 | DataSize,\r | |
130 | Data,\r | |
131 | &mVariableModuleGlobal->VariableGlobal[Physical],\r | |
132 | &mVariableModuleGlobal->VolatileLastVariableOffset,\r | |
72399dae | 133 | &mVariableModuleGlobal->NonVolatileLastVariableOffset\r |
8d3a5c82 | 134 | );\r |
135 | }\r | |
136 | \r | |
1794e506 | 137 | /**\r |
138 | \r | |
139 | This code returns information about the EFI variables.\r | |
140 | \r | |
141 | @param Attributes Attributes bitmask to specify the type of variables\r | |
142 | on which to return information.\r | |
143 | @param MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r | |
144 | for the EFI variables associated with the attributes specified.\r | |
145 | @param RemainingVariableStorageSize Pointer to the remaining size of the storage space available\r | |
146 | for EFI variables associated with the attributes specified.\r | |
147 | @param MaximumVariableSize Pointer to the maximum size of an individual EFI variables\r | |
148 | associated with the attributes specified.\r | |
149 | \r | |
150 | @return EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.\r | |
151 | @return EFI_SUCCESS Query successfully.\r | |
152 | @return EFI_UNSUPPORTED The attribute is not supported on this platform.\r | |
153 | \r | |
154 | **/\r | |
8d3a5c82 | 155 | EFI_STATUS\r |
156 | EFIAPI\r | |
157 | RuntimeServiceQueryVariableInfo (\r | |
158 | IN UINT32 Attributes,\r | |
159 | OUT UINT64 *MaximumVariableStorageSize,\r | |
160 | OUT UINT64 *RemainingVariableStorageSize,\r | |
161 | OUT UINT64 *MaximumVariableSize\r | |
162 | )\r | |
8d3a5c82 | 163 | {\r |
bd682470 | 164 | return EmuQueryVariableInfo (\r |
8d3a5c82 | 165 | Attributes,\r |
166 | MaximumVariableStorageSize,\r | |
167 | RemainingVariableStorageSize,\r | |
168 | MaximumVariableSize,\r | |
72399dae | 169 | &mVariableModuleGlobal->VariableGlobal[Physical]\r |
8d3a5c82 | 170 | );\r |
171 | }\r | |
172 | \r | |
1794e506 | 173 | /**\r |
174 | Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r | |
175 | \r | |
176 | This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r | |
177 | It convers pointer to new virtual address.\r | |
178 | \r | |
179 | @param Event Event whose notification function is being invoked.\r | |
180 | @param Context Pointer to the notification function's context.\r | |
181 | \r | |
182 | **/\r | |
8d3a5c82 | 183 | VOID\r |
184 | EFIAPI\r | |
185 | VariableClassAddressChangeEvent (\r | |
186 | IN EFI_EVENT Event,\r | |
187 | IN VOID *Context\r | |
188 | )\r | |
8d3a5c82 | 189 | {\r |
1623ce4a RN |
190 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLangCodes);\r |
191 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->LangCodes);\r | |
192 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal->PlatformLang);\r | |
8d3a5c82 | 193 | EfiConvertPointer (\r |
194 | 0x0,\r | |
195 | (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].NonVolatileVariableBase\r | |
196 | );\r | |
197 | EfiConvertPointer (\r | |
198 | 0x0,\r | |
199 | (VOID **) &mVariableModuleGlobal->VariableGlobal[Physical].VolatileVariableBase\r | |
200 | );\r | |
201 | EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);\r | |
202 | }\r | |
203 | \r | |
1794e506 | 204 | /**\r |
7c80e839 | 205 | EmuVariable Driver main entry point. The Variable driver places the 4 EFI\r |
d1102dba | 206 | runtime services in the EFI System Table and installs arch protocols\r |
d9303576 | 207 | for variable read and write services being available. It also registers\r |
1794e506 | 208 | notification function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r |
209 | \r | |
d1102dba | 210 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r |
7c80e839 | 211 | @param[in] SystemTable A pointer to the EFI System Table.\r |
d1102dba | 212 | \r |
7c80e839 | 213 | @retval EFI_SUCCESS Variable service successfully initialized.\r |
1794e506 | 214 | \r |
215 | **/\r | |
8d3a5c82 | 216 | EFI_STATUS\r |
217 | EFIAPI\r | |
218 | VariableServiceInitialize (\r | |
219 | IN EFI_HANDLE ImageHandle,\r | |
220 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
221 | )\r | |
8d3a5c82 | 222 | {\r |
223 | EFI_HANDLE NewHandle;\r | |
224 | EFI_STATUS Status;\r | |
225 | \r | |
226 | Status = VariableCommonInitialize (ImageHandle, SystemTable);\r | |
227 | ASSERT_EFI_ERROR (Status);\r | |
228 | \r | |
229 | SystemTable->RuntimeServices->GetVariable = RuntimeServiceGetVariable;\r | |
230 | SystemTable->RuntimeServices->GetNextVariableName = RuntimeServiceGetNextVariableName;\r | |
231 | SystemTable->RuntimeServices->SetVariable = RuntimeServiceSetVariable;\r | |
232 | SystemTable->RuntimeServices->QueryVariableInfo = RuntimeServiceQueryVariableInfo;\r | |
233 | \r | |
234 | //\r | |
235 | // Now install the Variable Runtime Architectural Protocol on a new handle\r | |
236 | //\r | |
237 | NewHandle = NULL;\r | |
238 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
239 | &NewHandle,\r | |
240 | &gEfiVariableArchProtocolGuid,\r | |
241 | NULL,\r | |
242 | &gEfiVariableWriteArchProtocolGuid,\r | |
243 | NULL,\r | |
244 | NULL\r | |
245 | );\r | |
246 | ASSERT_EFI_ERROR (Status);\r | |
247 | \r | |
01a5c994 | 248 | Status = gBS->CreateEventEx (\r |
249 | EVT_NOTIFY_SIGNAL,\r | |
a1634424 | 250 | TPL_NOTIFY,\r |
251 | VariableClassAddressChangeEvent,\r | |
252 | NULL,\r | |
01a5c994 | 253 | &gEfiEventVirtualAddressChangeGuid,\r |
a1634424 | 254 | &mVirtualAddressChangeEvent\r |
255 | );\r | |
256 | ASSERT_EFI_ERROR (Status);\r | |
257 | \r | |
8d3a5c82 | 258 | return EFI_SUCCESS;\r |
259 | }\r |