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