Import UefiRuntimeLib in MdePkg
[mirror_edk2.git] / MdePkg / Library / UefiRuntimeLib / RuntimeService.c
1 /*++
2
3 Copyright (c) 2006 - 2007, 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 RuntimeService.c
15
16 --*/
17
18 #include <PiDxe.h>
19
20 #include <RuntimeLibInternal.h>
21
22 VOID
23 EFIAPI
24 EfiResetSystem (
25 IN EFI_RESET_TYPE ResetType,
26 IN EFI_STATUS ResetStatus,
27 IN UINTN DataSize,
28 IN CHAR16 *ResetData
29 )
30 /*++
31
32 Routine Description:
33
34 Resets the entire platform.
35
36 Arguments:
37
38 ResetType - The type of reset to perform.
39 ResetStatus - The status code for the reset.
40 DataSize - The size, in bytes, of ResetData.
41 ResetData - A data buffer that includes a Null-terminated Unicode string, optionally
42 followed by additional binary data.
43
44 Returns:
45
46 None
47
48 --*/
49 {
50 mRT->ResetSystem (ResetType, ResetStatus, DataSize, ResetData);
51 }
52
53 //
54 // The following functions hide the mRT local global from the call to
55 // runtime service in the EFI system table.
56 //
57 EFI_STATUS
58 EFIAPI
59 EfiGetTime (
60 OUT EFI_TIME *Time,
61 OUT EFI_TIME_CAPABILITIES *Capabilities
62 )
63 /*++
64
65 Routine Description:
66
67 Returns the current time and date information, and the time-keeping
68 capabilities of the hardware platform.
69
70 Arguments:
71
72 Time - A pointer to storage to receive a snapshot of the current time.
73 Capabilities - An optional pointer to a buffer to receive the real time clock device's
74 capabilities.
75
76 Returns:
77
78 Status code
79
80 --*/
81 {
82 return mRT->GetTime (Time, Capabilities);
83 }
84
85 EFI_STATUS
86 EFIAPI
87 EfiSetTime (
88 IN EFI_TIME *Time
89 )
90 /*++
91
92 Routine Description:
93
94 Sets the current local time and date information.
95
96 Arguments:
97
98 Time - A pointer to the current time.
99
100 Returns:
101
102 Status code
103
104 --*/
105 {
106 return mRT->SetTime (Time);
107 }
108
109 EFI_STATUS
110 EFIAPI
111 EfiGetWakeupTime (
112 OUT BOOLEAN *Enabled,
113 OUT BOOLEAN *Pending,
114 OUT EFI_TIME *Time
115 )
116 /*++
117
118 Routine Description:
119
120 Returns the current wakeup alarm clock setting.
121
122 Arguments:
123
124 Enabled - Indicates if the alarm is currently enabled or disabled.
125 Pending - Indicates if the alarm signal is pending and requires acknowledgement.
126 Time - The current alarm setting.
127
128 Returns:
129
130 Status code
131
132 --*/
133 {
134 return mRT->GetWakeupTime (Enabled, Pending, Time);
135 }
136
137 EFI_STATUS
138 EFIAPI
139 EfiSetWakeupTime (
140 IN BOOLEAN Enable,
141 IN EFI_TIME *Time
142 )
143 /*++
144
145 Routine Description:
146
147 Sets the system wakeup alarm clock time.
148
149 Arguments:
150
151 Enable - Enable or disable the wakeup alarm.
152 Time - If Enable is TRUE, the time to set the wakeup alarm for.
153 If Enable is FALSE, then this parameter is optional, and may be NULL.
154
155 Returns:
156
157 Status code
158
159 --*/
160 {
161 return mRT->SetWakeupTime (Enable, Time);
162 }
163
164
165
166
167 EFI_STATUS
168 EFIAPI
169 EfiGetVariable (
170 IN CHAR16 *VariableName,
171 IN EFI_GUID * VendorGuid,
172 OUT UINT32 *Attributes OPTIONAL,
173 IN OUT UINTN *DataSize,
174 OUT VOID *Data
175 )
176 /*++
177
178 Routine Description:
179
180 Returns the value of a variable.
181
182 Arguments:
183
184 VariableName - A Null-terminated Unicode string that is the name of the
185 vendor's variable.
186 VendorGuid - A unique identifier for the vendor.
187 Attributes - If not NULL, a pointer to the memory location to return the
188 attributes bitmask for the variable.
189 DataSize - On input, the size in bytes of the return Data buffer.
190 On output the size of data returned in Data.
191 Data - The buffer to return the contents of the variable.
192
193 Returns:
194
195 Status code
196
197 --*/
198 {
199 return mRT->GetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);
200 }
201
202 EFI_STATUS
203 EFIAPI
204 EfiGetNextVariableName (
205 IN OUT UINTN *VariableNameSize,
206 IN OUT CHAR16 *VariableName,
207 IN OUT EFI_GUID *VendorGuid
208 )
209 /*++
210
211 Routine Description:
212
213 Enumerates the current variable names.
214
215 Arguments:
216
217 VariableNameSize - The size of the VariableName buffer.
218 VariableName - On input, supplies the last VariableName that was returned
219 by GetNextVariableName().
220 On output, returns the Nullterminated Unicode string of the
221 current variable.
222 VendorGuid - On input, supplies the last VendorGuid that was returned by
223 GetNextVariableName().
224 On output, returns the VendorGuid of the current variable.
225
226 Returns:
227
228 Status code
229
230 --*/
231 {
232 return mRT->GetNextVariableName (VariableNameSize, VariableName, VendorGuid);
233 }
234
235 EFI_STATUS
236 EFIAPI
237 EfiSetVariable (
238 IN CHAR16 *VariableName,
239 IN EFI_GUID *VendorGuid,
240 IN UINT32 Attributes,
241 IN UINTN DataSize,
242 IN VOID *Data
243 )
244 /*++
245
246 Routine Description:
247
248 Sets the value of a variable.
249
250 Arguments:
251
252 VariableName - A Null-terminated Unicode string that is the name of the
253 vendor's variable.
254 VendorGuid - A unique identifier for the vendor.
255 Attributes - Attributes bitmask to set for the variable.
256 DataSize - The size in bytes of the Data buffer.
257 Data - The contents for the variable.
258
259 Returns:
260
261 Status code
262
263 --*/
264 {
265 return mRT->SetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);
266 }
267
268 EFI_STATUS
269 EFIAPI
270 EfiGetNextHighMonotonicCount (
271 OUT UINT32 *HighCount
272 )
273 /*++
274
275 Routine Description:
276
277 Returns the next high 32 bits of the platform's monotonic counter.
278
279 Arguments:
280
281 HighCount - Pointer to returned value.
282
283 Returns:
284
285 Status code
286
287 --*/
288 {
289 return mRT->GetNextHighMonotonicCount (HighCount);
290 }
291
292 EFI_STATUS
293 EFIAPI
294 EfiConvertPointer (
295 IN UINTN DebugDisposition,
296 IN OUT VOID **Address
297 )
298 /*++
299
300 Routine Description:
301
302 Determines the new virtual address that is to be used on subsequent memory accesses.
303
304 Arguments:
305
306 DebugDisposition - Supplies type information for the pointer being converted.
307 Address - A pointer to a pointer that is to be fixed to be the value needed
308 for the new virtual address mappings being applied.
309
310 Returns:
311
312 Status code
313
314 --*/
315 {
316 return mRT->ConvertPointer (DebugDisposition, Address);
317 }
318
319 EFI_STATUS
320 EFIAPI
321 EfiConvertList (
322 IN UINTN DebugDisposition,
323 IN OUT LIST_ENTRY *ListHead
324 )
325 /*++
326
327 Routine Description:
328
329 Conver the standard Lib double linked list to a virtual mapping.
330
331 Arguments:
332
333 DebugDisposition - Argument to EfiConvertPointer (EFI 1.0 API)
334
335 ListHead - Head of linked list to convert
336
337 Returns:
338
339 EFI_SUCCESS
340
341 --*/
342 {
343 LIST_ENTRY *Link;
344 LIST_ENTRY *NextLink;
345
346 //
347 // Convert all the ForwardLink & BackLink pointers in the list
348 //
349 Link = ListHead;
350 do {
351 NextLink = Link->ForwardLink;
352
353 EfiConvertPointer (
354 Link->ForwardLink == ListHead ? DebugDisposition : 0,
355 (VOID **) &Link->ForwardLink
356 );
357
358 EfiConvertPointer (
359 Link->BackLink == ListHead ? DebugDisposition : 0,
360 (VOID **) &Link->BackLink
361 );
362
363 Link = NextLink;
364 } while (Link != ListHead);
365 return EFI_SUCCESS;
366 }
367
368
369 /**
370 Change the runtime addressing mode of EFI firmware from physical to virtual.
371
372 @param MemoryMapSize The size in bytes of VirtualMap.
373 @param DescriptorSize The size in bytes of an entry in the VirtualMap.
374 @param DescriptorVersion The version of the structure entries in VirtualMap.
375 @param VirtualMap An array of memory descriptors which contain new virtual
376 address mapping information for all runtime ranges. Type
377 EFI_MEMORY_DESCRIPTOR is defined in the
378 GetMemoryMap() function description.
379
380 @retval EFI_SUCCESS The virtual address map has been applied.
381 @retval EFI_UNSUPPORTED EFI firmware is not at runtime, or the EFI firmware is already in
382 virtual address mapped mode.
383 @retval EFI_INVALID_PARAMETER DescriptorSize or DescriptorVersion is
384 invalid.
385 @retval EFI_NO_MAPPING A virtual address was not supplied for a range in the memory
386 map that requires a mapping.
387 @retval EFI_NOT_FOUND A virtual address was supplied for an address that is not found
388 in the memory map.
389 **/
390 EFI_STATUS
391 EFIAPI
392 EfiSetVirtualAddressMap (
393 IN UINTN MemoryMapSize,
394 IN UINTN DescriptorSize,
395 IN UINT32 DescriptorVersion,
396 IN CONST EFI_MEMORY_DESCRIPTOR *VirtualMap
397 )
398 {
399 return mRT->SetVirtualAddressMap (
400 MemoryMapSize,
401 DescriptorSize,
402 DescriptorVersion,
403 (EFI_MEMORY_DESCRIPTOR *) VirtualMap
404 );
405 }
406
407
408 EFI_STATUS
409 EFIAPI
410 EfiUpdateCapsule (
411 IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray,
412 IN UINTN CapsuleCount,
413 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL
414 )
415 {
416 return mRT->UpdateCapsule (
417 CapsuleHeaderArray,
418 CapsuleCount,
419 ScatterGatherList
420 );
421 }
422
423 EFI_STATUS
424 EFIAPI
425 EfiQueryCapsuleCapabilities (
426 IN UEFI_CAPSULE_HEADER **CapsuleHeaderArray,
427 IN UINTN CapsuleCount,
428 OUT UINT64 *MaximumCapsuleSize,
429 OUT EFI_RESET_TYPE *ResetType
430 )
431 {
432 return mRT->QueryCapsuleCapabilities (
433 CapsuleHeaderArray,
434 CapsuleCount,
435 MaximumCapsuleSize,
436 ResetType
437 );
438 }
439
440
441 EFI_STATUS
442 EFIAPI
443 EfiQueryVariableInfo (
444 IN UINT32 Attributes,
445 OUT UINT64 *MaximumVariableStorageSize,
446 OUT UINT64 *RemainingVariableStorageSize,
447 OUT UINT64 *MaximumVariableSize
448 )
449 {
450 return mRT->QueryVariableInfo (
451 Attributes,
452 MaximumVariableStorageSize,
453 RemainingVariableStorageSize,
454 MaximumVariableSize
455 );
456 }