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