]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/UefiRuntimeLib/RuntimeService.c
The driver and library in MdePkg, MdeModulePkg and Nt32Pkg that don't depend on PI...
[mirror_edk2.git] / MdePkg / Library / UefiRuntimeLib / RuntimeService.c
1 /** @file
2 UEFI Runtime Library implementation for non IPF processor types.
3
4 This library hides the global variable for the EFI Runtime Services so the
5 caller does not need to deal with the possiblitly of being called from an
6 OS virtual address space. All pointer values are different for a virtual
7 mapping than from the normal physical mapping at boot services time.
8
9 Copyright (c) 2006 - 2008, Intel Corporation.<BR>
10 All rights reserved. This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
14
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17
18 **/
19
20 #include "RuntimeLibInternal.h"
21
22
23 /**
24 Resets the entire platform.
25
26 @param ResetType The type of reset to perform.
27 @param ResetStatus The status code for reset.
28 @param DataSize The size in bytes of reset data.
29 @param ResetData Pointer to data buffer that includes
30 Null-Terminated Unicode string.
31
32 **/
33 VOID
34 EFIAPI
35 EfiResetSystem (
36 IN EFI_RESET_TYPE ResetType,
37 IN EFI_STATUS ResetStatus,
38 IN UINTN DataSize,
39 IN CHAR16 *ResetData
40 )
41 {
42 mRT->ResetSystem (ResetType, ResetStatus, DataSize, ResetData);
43 }
44
45
46 /**
47 Return current time and date information, and time-keeping
48 capabilities of hardware platform.
49
50 @param Time A pointer to storage to receive a snapshot of the current time.
51 @param Capabilities An optional pointer to a buffer to receive the real time clock device's
52 capabilities.
53
54 @retval EFI_SUCCESS Success to execute the function.
55 @retval !EFI_SUCCESS Failed to execute the function.
56
57 **/
58 EFI_STATUS
59 EFIAPI
60 EfiGetTime (
61 OUT EFI_TIME *Time,
62 OUT EFI_TIME_CAPABILITIES *Capabilities
63 )
64 {
65 return mRT->GetTime (Time, Capabilities);
66 }
67
68
69 /**
70 Set current time and date information.
71
72 @param Time A pointer to cache of time setting.
73
74 @retval EFI_SUCCESS Success to execute the function.
75 @retval !EFI_SUCCESS Failed to execute the function.
76
77 **/
78 EFI_STATUS
79 EFIAPI
80 EfiSetTime (
81 IN EFI_TIME *Time
82 )
83 {
84 return mRT->SetTime (Time);
85 }
86
87
88 /**
89 Return current wakeup alarm clock setting.
90
91 @param Enabled Indicate if the alarm clock is enabled or disabled.
92 @param Pending Indicate if the alarm signal is pending and requires acknowledgement.
93 @param Time Current alarm clock setting.
94
95 @retval EFI_SUCCESS Success to execute the function.
96 @retval !EFI_SUCCESS Failed to execute the function.
97
98 **/
99 EFI_STATUS
100 EFIAPI
101 EfiGetWakeupTime (
102 OUT BOOLEAN *Enabled,
103 OUT BOOLEAN *Pending,
104 OUT EFI_TIME *Time
105 )
106 {
107 return mRT->GetWakeupTime (Enabled, Pending, Time);
108 }
109
110
111
112 /**
113 Set current wakeup alarm clock.
114
115 @param Enable Enable or disable current alarm clock..
116 @param Time Point to alarm clock setting.
117
118 @retval EFI_SUCCESS Success to execute the function.
119 @retval !EFI_SUCCESS Failed to execute the function.
120
121 **/
122 EFI_STATUS
123 EFIAPI
124 EfiSetWakeupTime (
125 IN BOOLEAN Enable,
126 IN EFI_TIME *Time
127 )
128 {
129 return mRT->SetWakeupTime (Enable, Time);
130 }
131
132
133 /**
134 Return value of variable.
135
136 @param VariableName the name of the vendor's variable, it's a
137 Null-Terminated Unicode String
138 @param VendorGuid Unify identifier for vendor.
139 @param Attributes Point to memory location to return the attributes of variable. If the point
140 is NULL, the parameter would be ignored.
141 @param DataSize As input, point to the maxinum size of return Data-Buffer.
142 As output, point to the actual size of the returned Data-Buffer.
143 @param Data Point to return Data-Buffer.
144
145 @retval EFI_SUCCESS Success to execute the function.
146 @retval !EFI_SUCCESS Failed to execute the function.
147
148 **/
149 EFI_STATUS
150 EFIAPI
151 EfiGetVariable (
152 IN CHAR16 *VariableName,
153 IN EFI_GUID * VendorGuid,
154 OUT UINT32 *Attributes OPTIONAL,
155 IN OUT UINTN *DataSize,
156 OUT VOID *Data
157 )
158 {
159 return mRT->GetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);
160 }
161
162
163 /**
164 Enumerates variable's name.
165
166 @param VariableNameSize As input, point to maxinum size of variable name.
167 As output, point to actual size of varaible name.
168 @param VariableName As input, supplies the last VariableName that was returned by
169 GetNextVariableName().
170 As output, returns the name of variable. The name
171 string is Null-Terminated Unicode string.
172 @param VendorGuid As input, supplies the last VendorGuid that was returned by
173 GetNextVriableName().
174 As output, returns the VendorGuid of the current variable.
175
176 @retval EFI_SUCCESS Success to execute the function.
177 @retval !EFI_SUCCESS Failed to execute the function.
178
179 **/
180 EFI_STATUS
181 EFIAPI
182 EfiGetNextVariableName (
183 IN OUT UINTN *VariableNameSize,
184 IN OUT CHAR16 *VariableName,
185 IN OUT EFI_GUID *VendorGuid
186 )
187 {
188 return mRT->GetNextVariableName (VariableNameSize, VariableName, VendorGuid);
189 }
190
191
192 /**
193 Sets value of variable.
194
195 @param VariableName the name of the vendor's variable, it's a
196 Null-Terminated Unicode String
197 @param VendorGuid Unify identifier for vendor.
198 @param Attributes Point to memory location to return the attributes of variable. If the point
199 is NULL, the parameter would be ignored.
200 @param DataSize The size in bytes of Data-Buffer.
201 @param Data Point to the content of the variable.
202
203 @retval EFI_SUCCESS Success to execute the function.
204 @retval !EFI_SUCCESS Failed to execute the function.
205
206 **/
207 EFI_STATUS
208 EFIAPI
209 EfiSetVariable (
210 IN CHAR16 *VariableName,
211 IN EFI_GUID *VendorGuid,
212 IN UINT32 Attributes,
213 IN UINTN DataSize,
214 IN VOID *Data
215 )
216 {
217 return mRT->SetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);
218 }
219
220
221 /**
222 Returns the next high 32 bits of platform's monotonic counter.
223
224 @param HighCount Pointer to returned value.
225
226 @retval EFI_SUCCESS Success to execute the function.
227 @retval !EFI_SUCCESS Failed to execute the function.
228
229 **/
230 EFI_STATUS
231 EFIAPI
232 EfiGetNextHighMonotonicCount (
233 OUT UINT32 *HighCount
234 )
235 {
236 return mRT->GetNextHighMonotonicCount (HighCount);
237 }
238
239
240 /**
241 Determines the new virtual address that is to be used on subsequent memory accesses.
242
243 @param DebugDisposition Supplies type information for the pointer being converted.
244 @param Address The pointer to a pointer that is to be fixed to be the
245 value needed for the new virtual address mapping being
246 applied.
247
248 @retval EFI_SUCCESS Success to execute the function.
249 @retval !EFI_SUCCESS Failed to execute the function.
250
251 **/
252 EFI_STATUS
253 EFIAPI
254 EfiConvertPointer (
255 IN UINTN DebugDisposition,
256 IN OUT VOID **Address
257 )
258 {
259 return gRT->ConvertPointer (DebugDisposition, Address);
260 }
261
262
263 /**
264 Conver the standard Lib double linked list to a virtual mapping.
265
266 @param DebugDisposition Supplies type information for the pointer being converted.
267 @param ListHead Head of linked list to convert.
268
269 @retval EFI_SUCCESS Success to execute the function.
270 @retval !EFI_SUCCESS Failed to execute the function.
271
272 **/
273 EFI_STATUS
274 EFIAPI
275 EfiConvertList (
276 IN UINTN DebugDisposition,
277 IN OUT LIST_ENTRY *ListHead
278 )
279 {
280 LIST_ENTRY *Link;
281 LIST_ENTRY *NextLink;
282
283 //
284 // For NULL List, return EFI_SUCCESS
285 //
286 if (ListHead == NULL) {
287 return EFI_SUCCESS;
288 }
289
290 //
291 // Convert all the ForwardLink & BackLink pointers in the list
292 //
293 Link = ListHead;
294 do {
295 NextLink = Link->ForwardLink;
296
297 EfiConvertPointer (
298 Link->ForwardLink == ListHead ? DebugDisposition : 0,
299 (VOID **) &Link->ForwardLink
300 );
301
302 EfiConvertPointer (
303 Link->BackLink == ListHead ? DebugDisposition : 0,
304 (VOID **) &Link->BackLink
305 );
306
307 Link = NextLink;
308 } while (Link != ListHead);
309 return EFI_SUCCESS;
310 }
311
312
313 /**
314 Change the runtime addressing mode of EFI firmware from physical to virtual.
315
316 @param MemoryMapSize The size in bytes of VirtualMap.
317 @param DescriptorSize The size in bytes of an entry in the VirtualMap.
318 @param DescriptorVersion The version of the structure entries in VirtualMap.
319 @param VirtualMap An array of memory descriptors which contain new virtual
320 address mapping information for all runtime ranges. Type
321 EFI_MEMORY_DESCRIPTOR is defined in the
322 GetMemoryMap() function description.
323
324 @retval EFI_SUCCESS The virtual address map has been applied.
325 @retval EFI_UNSUPPORTED EFI firmware is not at runtime, or the EFI firmware is already in
326 virtual address mapped mode.
327 @retval EFI_INVALID_PARAMETER DescriptorSize or DescriptorVersion is
328 invalid.
329 @retval EFI_NO_MAPPING A virtual address was not supplied for a range in the memory
330 map that requires a mapping.
331 @retval EFI_NOT_FOUND A virtual address was supplied for an address that is not found
332 in the memory map.
333 **/
334 EFI_STATUS
335 EFIAPI
336 EfiSetVirtualAddressMap (
337 IN UINTN MemoryMapSize,
338 IN UINTN DescriptorSize,
339 IN UINT32 DescriptorVersion,
340 IN CONST EFI_MEMORY_DESCRIPTOR *VirtualMap
341 )
342 {
343 return mRT->SetVirtualAddressMap (
344 MemoryMapSize,
345 DescriptorSize,
346 DescriptorVersion,
347 (EFI_MEMORY_DESCRIPTOR *) VirtualMap
348 );
349 }
350
351
352 /**
353 Passes capsules to the firmware with both virtual and physical mapping.
354 Depending on the intended consumption, the firmware may
355 process the capsule immediately. If the payload should persist across a
356 system reset, the reset value returned from EFI_QueryCapsuleCapabilities must
357 be passed into ResetSystem() and will cause the capsule to be processed by
358 the firmware as part of the reset process.
359
360 @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules
361 being passed into update capsule. Each capsules is assumed to
362 stored in contiguous virtual memory. The capsules in the
363 CapsuleHeaderArray must be the same capsules as the
364 ScatterGatherList. The CapsuleHeaderArray must
365 have the capsules in the same order as the ScatterGatherList.
366 @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in
367 CaspuleHeaderArray.
368 @param ScatterGatherList Physical pointer to a set of
369 EFI_CAPSULE_BLOCK_DESCRIPTOR that describes the
370 location in physical memory of a set of capsules. See Related
371 Definitions for an explanation of how more than one capsule is
372 passed via this interface. The capsules in the
373 ScatterGatherList must be in the same order as the
374 CapsuleHeaderArray. This parameter is only referenced if
375 the capsules are defined to persist across system reset.
376
377 @retval EFI_SUCCESS Valid capsule was passed. I Valid capsule was passed. If
378 CAPSULE_FLAGS_PERSIT_ACROSS_RESET is not set, the
379 capsule has been successfully processed by the firmware.
380 @retval EFI_INVALID_PARAMETER CapsuleSize is NULL or ResetTye is NULL.
381 @retval EFI_DEVICE_ERROR The capsule update was started, but failed due to a device error.
382
383 **/
384 EFI_STATUS
385 EFIAPI
386 EfiUpdateCapsule (
387 IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
388 IN UINTN CapsuleCount,
389 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL
390 )
391 {
392 return mRT->UpdateCapsule (
393 CapsuleHeaderArray,
394 CapsuleCount,
395 ScatterGatherList
396 );
397 }
398
399
400 /**
401 The QueryCapsuleCapabilities() function allows a caller to test to see if a capsule or
402 capsules can be updated via UpdateCapsule(). The Flags values in the capsule header and
403 size of the entire capsule is checked.
404 If the caller needs to query for generic capsule capability a fake EFI_CAPSULE_HEADER can be
405 constructed where CapsuleImageSize is equal to HeaderSize that is equal to sizeof
406 (EFI_CAPSULE_HEADER). To determine reset requirements,
407 CAPSULE_FLAGS_PERSIST_ACROSS_RESET should be set in the Flags field of the
408 EFI_CAPSULE_HEADER.
409 The firmware must support any capsule that has the
410 CAPSULE_FLAGS_PERSIST_ACROSS_RESET flag set in EFI_CAPSULE_HEADER. The
411 firmware sets the policy for what capsules are supported that do not have the
412 CAPSULE_FLAGS_PERSIST_ACROSS_RESET flag set.
413
414 @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules
415 being passed into update capsule. The capsules are assumed to
416 stored in contiguous virtual memory.
417 @param CapsuleCount Number of pointers to EFI_CAPSULE_HEADER in
418 CaspuleHeaderArray.
419 @param MaximumCapsuleSize On output the maximum size that UpdateCapsule() can
420 support as an argument to UpdateCapsule() via
421 CapsuleHeaderArray and ScatterGatherList.
422 Undefined on input.
423 @param ResetType Returns the type of reset required for the capsule update.
424
425 @retval EFI_SUCCESS Valid answer returned..
426 @retval EFI_INVALID_PARAMETER MaximumCapsuleSize is NULL.
427 @retval EFI_UNSUPPORTED The capsule type is not supported on this platform, and
428 MaximumCapsuleSize and ResetType are undefined.
429
430 **/
431 EFI_STATUS
432 EFIAPI
433 EfiQueryCapsuleCapabilities (
434 IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
435 IN UINTN CapsuleCount,
436 OUT UINT64 *MaximumCapsuleSize,
437 OUT EFI_RESET_TYPE *ResetType
438 )
439 {
440 return mRT->QueryCapsuleCapabilities (
441 CapsuleHeaderArray,
442 CapsuleCount,
443 MaximumCapsuleSize,
444 ResetType
445 );
446 }
447
448
449 /**
450 The QueryVariableInfo() function allows a caller to obtain the information about the
451 maximum size of the storage space available for the EFI variables, the remaining size of the storage
452 space available for the EFI variables and the maximum size of each individual EFI variable,
453 associated with the attributes specified.
454 The returned MaximumVariableStorageSize, RemainingVariableStorageSize,
455 MaximumVariableSize information may change immediately after the call based on other
456 runtime activities including asynchronous error events. Also, these values associated with different
457 attributes are not additive in nature.
458
459 @param Attributes Attributes bitmask to specify the type of variables on
460 which to return information. Refer to the
461 GetVariable() function description.
462 @param MaximumVariableStorageSize
463 On output the maximum size of the storage space
464 available for the EFI variables associated with the
465 attributes specified.
466 @param RemainingVariableStorageSize
467 Returns the remaining size of the storage space
468 available for the EFI variables associated with the
469 attributes specified..
470 @param MaximumVariableSize Returns the maximum size of the individual EFI
471 variables associated with the attributes specified.
472
473 @retval EFI_SUCCESS Valid answer returned.
474 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
475 @retval EFI_UNSUPPORTED EFI_UNSUPPORTED The attribute is not supported on this platform, and the
476 MaximumVariableStorageSize,
477 RemainingVariableStorageSize, MaximumVariableSize
478 are undefined.
479 **/
480 EFI_STATUS
481 EFIAPI
482 EfiQueryVariableInfo (
483 IN UINT32 Attributes,
484 OUT UINT64 *MaximumVariableStorageSize,
485 OUT UINT64 *RemainingVariableStorageSize,
486 OUT UINT64 *MaximumVariableSize
487 )
488 {
489 return mRT->QueryVariableInfo (
490 Attributes,
491 MaximumVariableStorageSize,
492 RemainingVariableStorageSize,
493 MaximumVariableSize
494 );
495 }