Volatile variable is read-only in runtime.
[mirror_edk2.git] / EdkModulePkg / Universal / EmuVariable / RuntimeDxe / InitVariable.c
CommitLineData
878ddf1f 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 InitVariable.c\r
15\r
16Abstract:\r
17\r
18Revision History\r
19\r
20--*/\r
21\r
22#include "Variable.h"\r
23\r
24//\r
25// Don't use module globals after the SetVirtualAddress map is signaled\r
26//\r
27extern ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal;\r
28\r
29EFI_STATUS\r
30EFIAPI\r
31RuntimeServiceGetVariable (\r
32 IN CHAR16 *VariableName,\r
33 IN EFI_GUID * VendorGuid,\r
34 OUT UINT32 *Attributes OPTIONAL,\r
35 IN OUT UINTN *DataSize,\r
36 OUT VOID *Data\r
37 )\r
38/*++\r
39\r
40Routine Description:\r
41\r
42Arguments:\r
43\r
44Returns:\r
45\r
46--*/\r
47{\r
48 return GetVariable (\r
49 VariableName,\r
50 VendorGuid,\r
51 Attributes OPTIONAL,\r
52 DataSize,\r
53 Data,\r
54 &mVariableModuleGlobal->VariableBase[Physical],\r
55 mVariableModuleGlobal->FvbInstance\r
56 );\r
57}\r
58\r
59EFI_STATUS\r
60EFIAPI\r
61RuntimeServiceGetNextVariableName (\r
62 IN OUT UINTN *VariableNameSize,\r
63 IN OUT CHAR16 *VariableName,\r
64 IN OUT EFI_GUID *VendorGuid\r
65 )\r
66/*++\r
67\r
68Routine Description:\r
69\r
70Arguments:\r
71\r
72Returns:\r
73\r
74--*/\r
75{\r
76 return GetNextVariableName (\r
77 VariableNameSize,\r
78 VariableName,\r
79 VendorGuid,\r
80 &mVariableModuleGlobal->VariableBase[Physical],\r
81 mVariableModuleGlobal->FvbInstance\r
82 );\r
83}\r
84\r
85EFI_STATUS\r
86EFIAPI\r
87RuntimeServiceSetVariable (\r
88 IN CHAR16 *VariableName,\r
89 IN EFI_GUID *VendorGuid,\r
90 IN UINT32 Attributes,\r
91 IN UINTN DataSize,\r
92 IN VOID *Data\r
93 )\r
94/*++\r
95\r
96Routine Description:\r
97\r
98Arguments:\r
99\r
100Returns:\r
101\r
102--*/\r
103{\r
104 return SetVariable (\r
105 VariableName,\r
106 VendorGuid,\r
107 Attributes,\r
108 DataSize,\r
109 Data,\r
110 &mVariableModuleGlobal->VariableBase[Physical],\r
111 &mVariableModuleGlobal->VolatileLastVariableOffset,\r
112 &mVariableModuleGlobal->NonVolatileLastVariableOffset,\r
113 mVariableModuleGlobal->FvbInstance\r
114 );\r
115}\r
116\r
045f4521 117#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
118EFI_STATUS\r
119EFIAPI\r
120RuntimeServiceQueryVariableInfo (\r
121 IN UINT32 Attributes,\r
122 OUT UINT64 *MaximumVariableStorageSize,\r
123 OUT UINT64 *RemainingVariableStorageSize,\r
124 OUT UINT64 *MaximumVariableSize\r
125 )\r
126/*++\r
127\r
128Routine Description:\r
129\r
130Arguments:\r
131\r
132Returns:\r
133\r
134--*/\r
135{\r
136 return QueryVariableInfo (\r
137 Attributes,\r
138 MaximumVariableStorageSize,\r
139 RemainingVariableStorageSize,\r
140 MaximumVariableSize,\r
141 &mVariableModuleGlobal->VariableBase[Physical],\r
142 mVariableModuleGlobal->FvbInstance\r
143 );\r
144}\r
145#endif\r
146\r
878ddf1f 147VOID\r
148EFIAPI\r
149VariableClassAddressChangeEvent (\r
150 IN EFI_EVENT Event,\r
151 IN VOID *Context\r
152 )\r
153/*++\r
154\r
155Routine Description:\r
156\r
157Arguments:\r
158\r
159Returns:\r
160\r
161--*/\r
162{\r
163 EfiConvertPointer (\r
164 0x0,\r
165 (VOID **) &mVariableModuleGlobal->VariableBase[Physical].NonVolatileVariableBase\r
166 );\r
167 EfiConvertPointer (\r
168 0x0,\r
169 (VOID **) &mVariableModuleGlobal->VariableBase[Physical].VolatileVariableBase\r
170 );\r
171 EfiConvertPointer (0x0, (VOID **) &mVariableModuleGlobal);\r
172}\r
173\r
174EFI_STATUS\r
175EFIAPI\r
176VariableServiceInitialize (\r
177 IN EFI_HANDLE ImageHandle,\r
178 IN EFI_SYSTEM_TABLE *SystemTable\r
179 )\r
180/*++\r
181\r
182Routine Description:\r
183\r
184Arguments:\r
185\r
186Returns:\r
187\r
188--*/\r
189{\r
190 EFI_HANDLE NewHandle;\r
191 EFI_STATUS Status;\r
192\r
193 Status = VariableCommonInitialize (ImageHandle, SystemTable);\r
194 ASSERT_EFI_ERROR (Status);\r
195\r
196 SystemTable->RuntimeServices->GetVariable = RuntimeServiceGetVariable;\r
197 SystemTable->RuntimeServices->GetNextVariableName = RuntimeServiceGetNextVariableName;\r
198 SystemTable->RuntimeServices->SetVariable = RuntimeServiceSetVariable;\r
045f4521 199#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
200 SystemTable->RuntimeServices->QueryVariableInfo = RuntimeServiceQueryVariableInfo;\r
201#endif\r
878ddf1f 202\r
203 //\r
204 // Now install the Variable Runtime Architectural Protocol on a new handle\r
205 //\r
206 NewHandle = NULL;\r
207 Status = gBS->InstallMultipleProtocolInterfaces (\r
208 &NewHandle,\r
209 &gEfiVariableArchProtocolGuid,\r
210 NULL,\r
211 &gEfiVariableWriteArchProtocolGuid,\r
212 NULL,\r
213 NULL\r
214 );\r
215 ASSERT_EFI_ERROR (Status);\r
216\r
217 return EFI_SUCCESS;\r
218}\r