]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiRuntimeLib/RuntimeLib.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / UefiRuntimeLib / RuntimeLib.c
CommitLineData
42eedea9 1/** @file\r
60c93673 2 UEFI Runtime Library implementation for non IPF processor types.\r
ebcc8fb7 3\r
363bb1b5 4 This library hides the global variable for the EFI Runtime Services so the\r
5 caller does not need to deal with the possibility of being called from an\r
9095d37b 6 OS virtual address space. All pointer values are different for a virtual\r
363bb1b5 7 mapping than from the normal physical mapping at boot services time.\r
8\r
9095d37b 9Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 10SPDX-License-Identifier: BSD-2-Clause-Patent\r
ebcc8fb7 11\r
12**/\r
13\r
363bb1b5 14#include <Uefi.h>\r
15#include <Library/UefiRuntimeLib.h>\r
16#include <Library/DebugLib.h>\r
17#include <Library/UefiBootServicesTableLib.h>\r
18#include <Library/UefiRuntimeServicesTableLib.h>\r
19#include <Guid/EventGroup.h>\r
ebcc8fb7 20\r
21///\r
22/// Driver Lib Module Globals\r
23///\r
fe467413 24EFI_EVENT mEfiVirtualNotifyEvent;\r
25EFI_EVENT mEfiExitBootServicesEvent;\r
26BOOLEAN mEfiGoneVirtual = FALSE;\r
27BOOLEAN mEfiAtRuntime = FALSE;\r
363bb1b5 28EFI_RUNTIME_SERVICES *mInternalRT;\r
ebcc8fb7 29\r
30/**\r
42eedea9 31 Set AtRuntime flag as TRUE after ExitBootServices.\r
ebcc8fb7 32\r
58380e9c 33 @param[in] Event The Event that is being processed.\r
34 @param[in] Context The Event Context.\r
363bb1b5 35\r
ebcc8fb7 36**/\r
37VOID\r
38EFIAPI\r
21998b67 39RuntimeLibExitBootServicesEvent (\r
ebcc8fb7 40 IN EFI_EVENT Event,\r
41 IN VOID *Context\r
42 )\r
43{\r
ebcc8fb7 44 mEfiAtRuntime = TRUE;\r
45}\r
46\r
47/**\r
48 Fixup internal data so that EFI can be call in virtual mode.\r
49 Call the passed in Child Notify event and convert any pointers in\r
50 lib to virtual mode.\r
51\r
58380e9c 52 @param[in] Event The Event that is being processed.\r
53 @param[in] Context The Event Context.\r
ebcc8fb7 54**/\r
ebcc8fb7 55VOID\r
56EFIAPI\r
57RuntimeLibVirtualNotifyEvent (\r
58 IN EFI_EVENT Event,\r
59 IN VOID *Context\r
60 )\r
61{\r
ebcc8fb7 62 //\r
63 // Update global for Runtime Services Table and IO\r
64 //\r
363bb1b5 65 EfiConvertPointer (0, (VOID **) &mInternalRT);\r
ebcc8fb7 66\r
67 mEfiGoneVirtual = TRUE;\r
68}\r
69\r
70/**\r
a9b896f4 71 Initialize runtime Driver Lib if it has not yet been initialized.\r
60c93673
LG
72 It will ASSERT() if gRT is NULL or gBS is NULL.\r
73 It will ASSERT() if that operation fails.\r
ebcc8fb7 74\r
75 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
76 @param[in] SystemTable A pointer to the EFI System Table.\r
77\r
78 @return EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
79**/\r
80EFI_STATUS\r
81EFIAPI\r
82RuntimeDriverLibConstruct (\r
83 IN EFI_HANDLE ImageHandle,\r
84 IN EFI_SYSTEM_TABLE *SystemTable\r
85 )\r
86{\r
87 EFI_STATUS Status;\r
88\r
60c93673
LG
89 ASSERT (gRT != NULL);\r
90 ASSERT (gBS != NULL);\r
91\r
363bb1b5 92 mInternalRT = gRT;\r
ebcc8fb7 93 //\r
94 // Register SetVirtualAddressMap () notify function\r
95 //\r
57a31578 96 Status = gBS->CreateEventEx (\r
97 EVT_NOTIFY_SIGNAL,\r
ebcc8fb7 98 TPL_NOTIFY,\r
99 RuntimeLibVirtualNotifyEvent,\r
100 NULL,\r
57a31578 101 &gEfiEventVirtualAddressChangeGuid,\r
ebcc8fb7 102 &mEfiVirtualNotifyEvent\r
103 );\r
104\r
105 ASSERT_EFI_ERROR (Status);\r
106\r
57a31578 107 Status = gBS->CreateEventEx (\r
108 EVT_NOTIFY_SIGNAL,\r
21998b67 109 TPL_NOTIFY,\r
110 RuntimeLibExitBootServicesEvent,\r
111 NULL,\r
57a31578 112 &gEfiEventExitBootServicesGuid,\r
21998b67 113 &mEfiExitBootServicesEvent\r
114 );\r
115\r
116 ASSERT_EFI_ERROR (Status);\r
117\r
ebcc8fb7 118 return Status;\r
119}\r
120\r
121/**\r
9095d37b 122 If a runtime driver exits with an error, it must call this routine\r
60c93673
LG
123 to free the allocated resource before the exiting.\r
124 It will ASSERT() if gBS is NULL.\r
125 It will ASSERT() if that operation fails.\r
ebcc8fb7 126\r
42eedea9 127 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
128 @param[in] SystemTable A pointer to the EFI System Table.\r
129\r
58380e9c 130 @retval EFI_SUCCESS The Runtime Driver Lib shutdown successfully.\r
131 @retval EFI_UNSUPPORTED Runtime Driver lib was not initialized.\r
ebcc8fb7 132**/\r
133EFI_STATUS\r
134EFIAPI\r
135RuntimeDriverLibDeconstruct (\r
136 IN EFI_HANDLE ImageHandle,\r
137 IN EFI_SYSTEM_TABLE *SystemTable\r
138 )\r
139{\r
140 EFI_STATUS Status;\r
141\r
142 //\r
143 // Close SetVirtualAddressMap () notify function\r
144 //\r
145 ASSERT (gBS != NULL);\r
146 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
147 ASSERT_EFI_ERROR (Status);\r
148\r
21998b67 149 Status = gBS->CloseEvent (mEfiExitBootServicesEvent);\r
150 ASSERT_EFI_ERROR (Status);\r
151\r
ebcc8fb7 152 return Status;\r
153}\r
154\r
155/**\r
1d37ab9f 156 This function allows the caller to determine if UEFI ExitBootServices() has been called.\r
157\r
158 This function returns TRUE after all the EVT_SIGNAL_EXIT_BOOT_SERVICES functions have\r
159 executed as a result of the OS calling ExitBootServices(). Prior to this time FALSE\r
160 is returned. This function is used by runtime code to decide it is legal to access\r
161 services that go away after ExitBootServices().\r
162\r
163 @retval TRUE The system has finished executing the EVT_SIGNAL_EXIT_BOOT_SERVICES event.\r
164 @retval FALSE The system has not finished executing the EVT_SIGNAL_EXIT_BOOT_SERVICES event.\r
ebcc8fb7 165\r
ebcc8fb7 166**/\r
167BOOLEAN\r
168EFIAPI\r
169EfiAtRuntime (\r
170 VOID\r
171 )\r
172{\r
173 return mEfiAtRuntime;\r
174}\r
175\r
176/**\r
9095d37b 177 This function allows the caller to determine if UEFI SetVirtualAddressMap() has been called.\r
1d37ab9f 178\r
179 This function returns TRUE after all the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE functions have\r
180 executed as a result of the OS calling SetVirtualAddressMap(). Prior to this time FALSE\r
181 is returned. This function is used by runtime code to decide it is legal to access services\r
182 that go away after SetVirtualAddressMap().\r
183\r
184 @retval TRUE The system has finished executing the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
185 @retval FALSE The system has not finished executing the EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event.\r
ebcc8fb7 186\r
ebcc8fb7 187**/\r
188BOOLEAN\r
189EFIAPI\r
190EfiGoneVirtual (\r
191 VOID\r
192 )\r
193{\r
194 return mEfiGoneVirtual;\r
195}\r
196\r
363bb1b5 197\r
198/**\r
199 This service is a wrapper for the UEFI Runtime Service ResetSystem().\r
200\r
201 The ResetSystem()function resets the entire platform, including all processors and devices,and reboots the system.\r
202 Calling this interface with ResetType of EfiResetCold causes a system-wide reset. This sets all circuitry within\r
203 the system to its initial state. This type of reset is asynchronous to system operation and operates without regard\r
204 to cycle boundaries. EfiResetCold is tantamount to a system power cycle.\r
205 Calling this interface with ResetType of EfiResetWarm causes a system-wide initialization. The processors are set to\r
206 their initial state, and pending cycles are not corrupted. If the system does not support this reset type, then an\r
207 EfiResetCold must be performed.\r
208 Calling this interface with ResetType of EfiResetShutdown causes the system to enter a power state equivalent to the\r
209 ACPI G2/S5 or G3 states. If the system does not support this reset type, then when the system is rebooted, it should\r
210 exhibit the EfiResetCold attributes.\r
211 The platform may optionally log the parameters from any non-normal reset that occurs.\r
212 The ResetSystem() function does not return.\r
213\r
214 @param ResetType The type of reset to perform.\r
215 @param ResetStatus The status code for the reset. If the system reset is part of a normal operation, the status code\r
216 would be EFI_SUCCESS. If the system reset is due to some type of failure the most appropriate EFI\r
217 Status code would be used.\r
218 @param DataSizeThe size, in bytes, of ResetData.\r
219 @param ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown the data buffer starts with a\r
220 Null-terminated Unicode string, optionally followed by additional binary data. The string is a\r
221 description that the caller may use to further indicate the reason for the system reset. ResetData\r
222 is only valid if ResetStatus is something other then EFI_SUCCESS. This pointer must be a physical\r
223 address. For a ResetType of EfiRestUpdate the data buffer also starts with a Null-terminated string\r
224 that is followed by a physical VOID * to an EFI_CAPSULE_HEADER.\r
225\r
226**/\r
227VOID\r
228EFIAPI\r
229EfiResetSystem (\r
230 IN EFI_RESET_TYPE ResetType,\r
231 IN EFI_STATUS ResetStatus,\r
232 IN UINTN DataSize,\r
233 IN VOID *ResetData OPTIONAL\r
234 )\r
235{\r
236 mInternalRT->ResetSystem (ResetType, ResetStatus, DataSize, ResetData);\r
237}\r
238\r
239\r
240/**\r
241 This service is a wrapper for the UEFI Runtime Service GetTime().\r
242\r
243 The GetTime() function returns a time that was valid sometime during the call to the function.\r
244 While the returned EFI_TIME structure contains TimeZone and Daylight savings time information,\r
245 the actual clock does not maintain these values. The current time zone and daylight saving time\r
246 information returned by GetTime() are the values that were last set via SetTime().\r
247 The GetTime() function should take approximately the same amount of time to read the time each\r
248 time it is called. All reported device capabilities are to be rounded up.\r
249 During runtime, if a PC-AT CMOS device is present in the platform the caller must synchronize\r
250 access to the device before calling GetTime().\r
251\r
252 @param Time A pointer to storage to receive a snapshot of the current time.\r
253 @param Capabilities An optional pointer to a buffer to receive the real time clock device's\r
254 capabilities.\r
255\r
256 @retval EFI_SUCCESS The operation completed successfully.\r
257 @retval EFI_INVALID_PARAMETER Time is NULL.\r
258 @retval EFI_DEVICE_ERROR The time could not be retrieved due to a hardware error.\r
259\r
260**/\r
261EFI_STATUS\r
262EFIAPI\r
263EfiGetTime (\r
264 OUT EFI_TIME *Time,\r
265 OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL\r
266 )\r
267{\r
268 return mInternalRT->GetTime (Time, Capabilities);\r
269}\r
270\r
271\r
272/**\r
273 This service is a wrapper for the UEFI Runtime Service SetTime().\r
274\r
275 The SetTime() function sets the real time clock device to the supplied time, and records the\r
276 current time zone and daylight savings time information. The SetTime() function is not allowed\r
277 to loop based on the current time. For example, if the device does not support a hardware reset\r
278 for the sub-resolution time, the code is not to implement the feature by waiting for the time to\r
279 wrap.\r
280 During runtime, if a PC-AT CMOS device is present in the platform the caller must synchronize\r
281 access to the device before calling SetTime().\r
282\r
283 @param Time A pointer to the current time. Type EFI_TIME is defined in the GetTime()\r
284 function description. Full error checking is performed on the different\r
285 fields of the EFI_TIME structure (refer to the EFI_TIME definition in the\r
286 GetTime() function description for full details), and EFI_INVALID_PARAMETER\r
287 is returned if any field is out of range.\r
288\r
289 @retval EFI_SUCCESS The operation completed successfully.\r
290 @retval EFI_INVALID_PARAMETER A time field is out of range.\r
291 @retval EFI_DEVICE_ERROR The time could not be set due to a hardware error.\r
292\r
293**/\r
294EFI_STATUS\r
295EFIAPI\r
296EfiSetTime (\r
297 IN EFI_TIME *Time\r
298 )\r
299{\r
300 return mInternalRT->SetTime (Time);\r
301}\r
302\r
303\r
304/**\r
305 This service is a wrapper for the UEFI Runtime Service GetWakeupTime().\r
306\r
307 The alarm clock time may be rounded from the set alarm clock time to be within the resolution\r
308 of the alarm clock device. The resolution of the alarm clock device is defined to be one second.\r
309 During runtime, if a PC-AT CMOS device is present in the platform the caller must synchronize\r
310 access to the device before calling GetWakeupTime().\r
311\r
312 @param Enabled Indicates if the alarm is currently enabled or disabled.\r
313 @param Pending Indicates if the alarm signal is pending and requires acknowledgement.\r
314 @param Time The current alarm setting. Type EFI_TIME is defined in the GetTime()\r
315 function description.\r
316\r
58380e9c 317 @retval EFI_SUCCESS The alarm settings were returned.\r
363bb1b5 318 @retval EFI_INVALID_PARAMETER Enabled is NULL.\r
319 @retval EFI_INVALID_PARAMETER Pending is NULL.\r
320 @retval EFI_INVALID_PARAMETER Time is NULL.\r
321 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.\r
322 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r
323\r
324**/\r
325EFI_STATUS\r
326EFIAPI\r
327EfiGetWakeupTime (\r
328 OUT BOOLEAN *Enabled,\r
329 OUT BOOLEAN *Pending,\r
330 OUT EFI_TIME *Time\r
331 )\r
332{\r
333 return mInternalRT->GetWakeupTime (Enabled, Pending, Time);\r
334}\r
335\r
336\r
337\r
338/**\r
339 This service is a wrapper for the UEFI Runtime Service SetWakeupTime()\r
340\r
341 Setting a system wakeup alarm causes the system to wake up or power on at the set time.\r
342 When the alarm fires, the alarm signal is latched until it is acknowledged by calling SetWakeupTime()\r
343 to disable the alarm. If the alarm fires before the system is put into a sleeping or off state,\r
344 since the alarm signal is latched the system will immediately wake up. If the alarm fires while\r
345 the system is off and there is insufficient power to power on the system, the system is powered\r
346 on when power is restored.\r
347\r
348 @param Enable Enable or disable the wakeup alarm.\r
349 @param Time If Enable is TRUE, the time to set the wakeup alarm for. Type EFI_TIME\r
350 is defined in the GetTime() function description. If Enable is FALSE,\r
351 then this parameter is optional, and may be NULL.\r
352\r
353 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.\r
354 If Enable is FALSE, then the wakeup alarm was disabled.\r
355 @retval EFI_INVALID_PARAMETER A time field is out of range.\r
356 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.\r
357 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r
358\r
359**/\r
360EFI_STATUS\r
361EFIAPI\r
362EfiSetWakeupTime (\r
363 IN BOOLEAN Enable,\r
364 IN EFI_TIME *Time OPTIONAL\r
365 )\r
366{\r
367 return mInternalRT->SetWakeupTime (Enable, Time);\r
368}\r
369\r
370\r
371/**\r
372 This service is a wrapper for the UEFI Runtime Service GetVariable().\r
373\r
374 Each vendor may create and manage its own variables without the risk of name conflicts by\r
375 using a unique VendorGuid. When a variable is set its Attributes are supplied to indicate\r
376 how the data variable should be stored and maintained by the system. The attributes affect\r
377 when the variable may be accessed and volatility of the data. Any attempts to access a variable\r
378 that does not have the attribute set for runtime access will yield the EFI_NOT_FOUND error.\r
379 If the Data buffer is too small to hold the contents of the variable, the error EFI_BUFFER_TOO_SMALL\r
380 is returned and DataSize is set to the required buffer size to obtain the data.\r
381\r
382 @param VariableName the name of the vendor's variable, it's a Null-Terminated Unicode String\r
383 @param VendorGuid Unify identifier for vendor.\r
384 @param Attributes Point to memory location to return the attributes of variable. If the point\r
385 is NULL, the parameter would be ignored.\r
386 @param DataSize As input, point to the maximum size of return Data-Buffer.\r
387 As output, point to the actual size of the returned Data-Buffer.\r
388 @param Data Point to return Data-Buffer.\r
389\r
390 @retval EFI_SUCCESS The function completed successfully.\r
391 @retval EFI_NOT_FOUND The variable was not found.\r
392 @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. DataSize has\r
393 been updated with the size needed to complete the request.\r
394 @retval EFI_INVALID_PARAMETER VariableName is NULL.\r
395 @retval EFI_INVALID_PARAMETER VendorGuid is NULL.\r
396 @retval EFI_INVALID_PARAMETER DataSize is NULL.\r
397 @retval EFI_INVALID_PARAMETER The DataSize is not too small and Data is NULL.\r
398 @retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.\r
399 @retval EFI_SECURITY_VIOLATION The variable could not be retrieved due to an authentication failure.\r
400**/\r
401EFI_STATUS\r
402EFIAPI\r
403EfiGetVariable (\r
404 IN CHAR16 *VariableName,\r
405 IN EFI_GUID *VendorGuid,\r
406 OUT UINT32 *Attributes OPTIONAL,\r
407 IN OUT UINTN *DataSize,\r
408 OUT VOID *Data\r
409 )\r
410{\r
411 return mInternalRT->GetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);\r
412}\r
413\r
414\r
415/**\r
416 This service is a wrapper for the UEFI Runtime Service GetNextVariableName().\r
417\r
418 GetNextVariableName() is called multiple times to retrieve the VariableName and VendorGuid of\r
419 all variables currently available in the system. On each call to GetNextVariableName() the\r
420 previous results are passed into the interface, and on output the interface returns the next\r
421 variable name data. When the entire variable list has been returned, the error EFI_NOT_FOUND\r
422 is returned.\r
423\r
424 @param VariableNameSize As input, point to maximum size of variable name.\r
425 As output, point to actual size of variable name.\r
426 @param VariableName As input, supplies the last VariableName that was returned by\r
427 GetNextVariableName().\r
428 As output, returns the name of variable. The name\r
429 string is Null-Terminated Unicode string.\r
430 @param VendorGuid As input, supplies the last VendorGuid that was returned by\r
431 GetNextVriableName().\r
432 As output, returns the VendorGuid of the current variable.\r
433\r
434 @retval EFI_SUCCESS The function completed successfully.\r
435 @retval EFI_NOT_FOUND The next variable was not found.\r
436 @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the result.\r
437 VariableNameSize has been updated with the size needed\r
438 to complete the request.\r
439 @retval EFI_INVALID_PARAMETER VariableNameSize is NULL.\r
440 @retval EFI_INVALID_PARAMETER VariableName is NULL.\r
441 @retval EFI_INVALID_PARAMETER VendorGuid is NULL.\r
442 @retval EFI_DEVICE_ERROR The variable name could not be retrieved due to a hardware error.\r
443\r
444**/\r
445EFI_STATUS\r
446EFIAPI\r
447EfiGetNextVariableName (\r
448 IN OUT UINTN *VariableNameSize,\r
449 IN OUT CHAR16 *VariableName,\r
450 IN OUT EFI_GUID *VendorGuid\r
451 )\r
452{\r
453 return mInternalRT->GetNextVariableName (VariableNameSize, VariableName, VendorGuid);\r
454}\r
455\r
456\r
457/**\r
458 This service is a wrapper for the UEFI Runtime Service GetNextVariableName()\r
459\r
460 Variables are stored by the firmware and may maintain their values across power cycles. Each vendor\r
461 may create and manage its own variables without the risk of name conflicts by using a unique VendorGuid.\r
462\r
9095d37b 463 @param VariableName The name of the vendor's variable; it's a Null-Terminated\r
58380e9c 464 Unicode String\r
363bb1b5 465 @param VendorGuid Unify identifier for vendor.\r
58380e9c 466 @param Attributes Points to a memory location to return the attributes of variable. If the point\r
363bb1b5 467 is NULL, the parameter would be ignored.\r
468 @param DataSize The size in bytes of Data-Buffer.\r
58380e9c 469 @param Data Points to the content of the variable.\r
363bb1b5 470\r
471 @retval EFI_SUCCESS The firmware has successfully stored the variable and its data as\r
472 defined by the Attributes.\r
473 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied, or the\r
474 DataSize exceeds the maximum allowed.\r
475 @retval EFI_INVALID_PARAMETER VariableName is an empty Unicode string.\r
476 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
477 @retval EFI_DEVICE_ERROR The variable could not be saved due to a hardware failure.\r
478 @retval EFI_WRITE_PROTECTED The variable in question is read-only.\r
479 @retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.\r
403170bb 480 @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS\r
363bb1b5 481 set but the AuthInfo does NOT pass the validation check carried\r
482 out by the firmware.\r
483 @retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.\r
484\r
485**/\r
486EFI_STATUS\r
487EFIAPI\r
488EfiSetVariable (\r
489 IN CHAR16 *VariableName,\r
490 IN EFI_GUID *VendorGuid,\r
491 IN UINT32 Attributes,\r
492 IN UINTN DataSize,\r
493 IN VOID *Data\r
494 )\r
495{\r
496 return mInternalRT->SetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);\r
497}\r
498\r
499\r
500/**\r
501 This service is a wrapper for the UEFI Runtime Service GetNextHighMonotonicCount().\r
502\r
503 The platform's monotonic counter is comprised of two 32-bit quantities: the high 32 bits and\r
504 the low 32 bits. During boot service time the low 32-bit value is volatile: it is reset to zero\r
505 on every system reset and is increased by 1 on every call to GetNextMonotonicCount(). The high\r
506 32-bit value is nonvolatile and is increased by 1 whenever the system resets or whenever the low\r
507 32-bit count (returned by GetNextMonoticCount()) overflows.\r
508\r
2fc59a00 509 @param HighCount The pointer to returned value.\r
363bb1b5 510\r
511 @retval EFI_SUCCESS The next high monotonic count was returned.\r
512 @retval EFI_DEVICE_ERROR The device is not functioning properly.\r
513 @retval EFI_INVALID_PARAMETER HighCount is NULL.\r
514\r
515**/\r
516EFI_STATUS\r
517EFIAPI\r
518EfiGetNextHighMonotonicCount (\r
519 OUT UINT32 *HighCount\r
520 )\r
521{\r
522 return mInternalRT->GetNextHighMonotonicCount (HighCount);\r
523}\r
524\r
525\r
526/**\r
9095d37b 527 This service is a wrapper for the UEFI Runtime Service ConvertPointer().\r
363bb1b5 528\r
529 The ConvertPointer() function is used by an EFI component during the SetVirtualAddressMap() operation.\r
530 ConvertPointer()must be called using physical address pointers during the execution of SetVirtualAddressMap().\r
531\r
532 @param DebugDisposition Supplies type information for the pointer being converted.\r
533 @param Address The pointer to a pointer that is to be fixed to be the\r
534 value needed for the new virtual address mapping being\r
535 applied.\r
536\r
537 @retval EFI_SUCCESS The pointer pointed to by Address was modified.\r
538 @retval EFI_NOT_FOUND The pointer pointed to by Address was not found to be part of\r
539 the current memory map. This is normally fatal.\r
540 @retval EFI_INVALID_PARAMETER Address is NULL.\r
541 @retval EFI_INVALID_PARAMETER *Address is NULL and DebugDispositio\r
542\r
543**/\r
544EFI_STATUS\r
545EFIAPI\r
546EfiConvertPointer (\r
547 IN UINTN DebugDisposition,\r
548 IN OUT VOID **Address\r
549 )\r
550{\r
551 return gRT->ConvertPointer (DebugDisposition, Address);\r
552}\r
553\r
554\r
555/**\r
556 Determines the new virtual address that is to be used on subsequent memory accesses.\r
557\r
558 For IA32, x64, and EBC, this service is a wrapper for the UEFI Runtime Service\r
9095d37b 559 ConvertPointer(). See the UEFI Specification for details.\r
363bb1b5 560 For IPF, this function interprets Address as a pointer to an EFI_PLABEL structure\r
561 and both the EntryPoint and GP fields of an EFI_PLABEL are converted from physical\r
562 to virtiual addressing. Since IPF allows the GP to point to an address outside\r
563 a PE/COFF image, the physical to virtual offset for the EntryPoint field is used\r
564 to adjust the GP field. The UEFI Runtime Service ConvertPointer() is used to convert\r
565 EntryPoint and the status code for this conversion is always returned. If the convertion\r
566 of EntryPoint fails, then neither EntryPoint nor GP are modified. See the UEFI\r
567 Specification for details on the UEFI Runtime Service ConvertPointer().\r
568\r
569 @param DebugDisposition Supplies type information for the pointer being converted.\r
570 @param Address The pointer to a pointer that is to be fixed to be the\r
571 value needed for the new virtual address mapping being\r
572 applied.\r
573\r
574 @return EFI_STATUS value from EfiConvertPointer().\r
575\r
576**/\r
577EFI_STATUS\r
578EFIAPI\r
579EfiConvertFunctionPointer (\r
580 IN UINTN DebugDisposition,\r
581 IN OUT VOID **Address\r
582 )\r
583{\r
584 return EfiConvertPointer (DebugDisposition, Address);\r
585}\r
586\r
587\r
588/**\r
589 Convert the standard Lib double linked list to a virtual mapping.\r
590\r
591 This service uses EfiConvertPointer() to walk a double linked list and convert all the link\r
592 pointers to their virtual mappings. This function is only guaranteed to work during the\r
593 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event and calling it at other times has undefined results.\r
594\r
595 @param DebugDisposition Supplies type information for the pointer being converted.\r
596 @param ListHead Head of linked list to convert.\r
597\r
598 @retval EFI_SUCCESS Success to execute the function.\r
599 @retval !EFI_SUCCESS Failed to e3xecute the function.\r
600\r
601**/\r
602EFI_STATUS\r
603EFIAPI\r
604EfiConvertList (\r
605 IN UINTN DebugDisposition,\r
606 IN OUT LIST_ENTRY *ListHead\r
607 )\r
608{\r
609 LIST_ENTRY *Link;\r
610 LIST_ENTRY *NextLink;\r
9095d37b 611\r
363bb1b5 612 //\r
613 // For NULL List, return EFI_SUCCESS\r
614 //\r
615 if (ListHead == NULL) {\r
616 return EFI_SUCCESS;\r
617 }\r
618\r
619 //\r
620 // Convert all the ForwardLink & BackLink pointers in the list\r
621 //\r
622 Link = ListHead;\r
623 do {\r
624 NextLink = Link->ForwardLink;\r
625\r
626 EfiConvertPointer (\r
627 Link->ForwardLink == ListHead ? DebugDisposition : 0,\r
628 (VOID **) &Link->ForwardLink\r
629 );\r
630\r
631 EfiConvertPointer (\r
632 Link->BackLink == ListHead ? DebugDisposition : 0,\r
633 (VOID **) &Link->BackLink\r
634 );\r
635\r
636 Link = NextLink;\r
637 } while (Link != ListHead);\r
638 return EFI_SUCCESS;\r
639}\r
640\r
641\r
642/**\r
643 This service is a wrapper for the UEFI Runtime Service SetVirtualAddressMap().\r
644\r
645 The SetVirtualAddressMap() function is used by the OS loader. The function can only be called\r
646 at runtime, and is called by the owner of the system's memory map. I.e., the component which\r
647 called ExitBootServices(). All events of type EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE must be signaled\r
648 before SetVirtualAddressMap() returns.\r
649\r
650 @param MemoryMapSize The size in bytes of VirtualMap.\r
651 @param DescriptorSize The size in bytes of an entry in the VirtualMap.\r
652 @param DescriptorVersion The version of the structure entries in VirtualMap.\r
653 @param VirtualMap An array of memory descriptors which contain new virtual\r
654 address mapping information for all runtime ranges. Type\r
655 EFI_MEMORY_DESCRIPTOR is defined in the\r
656 GetMemoryMap() function description.\r
657\r
658 @retval EFI_SUCCESS The virtual address map has been applied.\r
659 @retval EFI_UNSUPPORTED EFI firmware is not at runtime, or the EFI firmware is already in\r
660 virtual address mapped mode.\r
661 @retval EFI_INVALID_PARAMETER DescriptorSize or DescriptorVersion is\r
662 invalid.\r
663 @retval EFI_NO_MAPPING A virtual address was not supplied for a range in the memory\r
664 map that requires a mapping.\r
665 @retval EFI_NOT_FOUND A virtual address was supplied for an address that is not found\r
666 in the memory map.\r
667**/\r
668EFI_STATUS\r
669EFIAPI\r
670EfiSetVirtualAddressMap (\r
671 IN UINTN MemoryMapSize,\r
672 IN UINTN DescriptorSize,\r
673 IN UINT32 DescriptorVersion,\r
674 IN CONST EFI_MEMORY_DESCRIPTOR *VirtualMap\r
675 )\r
676{\r
677 return mInternalRT->SetVirtualAddressMap (\r
678 MemoryMapSize,\r
679 DescriptorSize,\r
680 DescriptorVersion,\r
681 (EFI_MEMORY_DESCRIPTOR *) VirtualMap\r
682 );\r
683}\r
684\r
685\r
686/**\r
687 This service is a wrapper for the UEFI Runtime Service UpdateCapsule().\r
688\r
689 Passes capsules to the firmware with both virtual and physical mapping. Depending on the intended\r
690 consumption, the firmware may process the capsule immediately. If the payload should persist across a\r
691 system reset, the reset value returned from EFI_QueryCapsuleCapabilities must be passed into ResetSystem()\r
692 and will cause the capsule to be processed by the firmware as part of the reset process.\r
693\r
694 @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules\r
695 being passed into update capsule. Each capsules is assumed to\r
696 stored in contiguous virtual memory. The capsules in the\r
697 CapsuleHeaderArray must be the same capsules as the\r
698 ScatterGatherList. The CapsuleHeaderArray must\r
699 have the capsules in the same order as the ScatterGatherList.\r
2fc59a00 700 @param CapsuleCount The number of pointers to EFI_CAPSULE_HEADER in\r
363bb1b5 701 CaspuleHeaderArray.\r
702 @param ScatterGatherList Physical pointer to a set of\r
703 EFI_CAPSULE_BLOCK_DESCRIPTOR that describes the\r
704 location in physical memory of a set of capsules. See Related\r
705 Definitions for an explanation of how more than one capsule is\r
706 passed via this interface. The capsules in the\r
707 ScatterGatherList must be in the same order as the\r
708 CapsuleHeaderArray. This parameter is only referenced if\r
709 the capsules are defined to persist across system reset.\r
710\r
711 @retval EFI_SUCCESS Valid capsule was passed. If CAPSULE_FLAGS_PERSIT_ACROSS_RESET is not set,\r
712 the capsule has been successfully processed by the firmware.\r
713 @retval EFI_INVALID_PARAMETER CapsuleSize or HeaderSize is NULL.\r
714 @retval EFI_INVALID_PARAMETER CapsuleCount is 0\r
715 @retval EFI_DEVICE_ERROR The capsule update was started, but failed due to a device error.\r
716 @retval EFI_UNSUPPORTED The capsule type is not supported on this platform.\r
717 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to process the capsule.\r
718\r
719**/\r
720EFI_STATUS\r
721EFIAPI\r
722EfiUpdateCapsule (\r
723 IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
724 IN UINTN CapsuleCount,\r
725 IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL\r
726 )\r
727{\r
728 return mInternalRT->UpdateCapsule (\r
729 CapsuleHeaderArray,\r
730 CapsuleCount,\r
731 ScatterGatherList\r
732 );\r
733}\r
734\r
735\r
736/**\r
737 This service is a wrapper for the UEFI Runtime Service QueryCapsuleCapabilities().\r
738\r
739 The QueryCapsuleCapabilities() function allows a caller to test to see if a capsule or\r
740 capsules can be updated via UpdateCapsule(). The Flags values in the capsule header and\r
741 size of the entire capsule is checked.\r
742 If the caller needs to query for generic capsule capability a fake EFI_CAPSULE_HEADER can be\r
743 constructed where CapsuleImageSize is equal to HeaderSize that is equal to sizeof\r
744 (EFI_CAPSULE_HEADER). To determine reset requirements,\r
745 CAPSULE_FLAGS_PERSIST_ACROSS_RESET should be set in the Flags field of the\r
746 EFI_CAPSULE_HEADER.\r
747 The firmware must support any capsule that has the\r
748 CAPSULE_FLAGS_PERSIST_ACROSS_RESET flag set in EFI_CAPSULE_HEADER. The\r
749 firmware sets the policy for what capsules are supported that do not have the\r
750 CAPSULE_FLAGS_PERSIST_ACROSS_RESET flag set.\r
751\r
752 @param CapsuleHeaderArray Virtual pointer to an array of virtual pointers to the capsules\r
753 being passed into update capsule. The capsules are assumed to\r
754 stored in contiguous virtual memory.\r
2fc59a00 755 @param CapsuleCount The number of pointers to EFI_CAPSULE_HEADER in\r
363bb1b5 756 CaspuleHeaderArray.\r
757 @param MaximumCapsuleSize On output the maximum size that UpdateCapsule() can\r
758 support as an argument to UpdateCapsule() via\r
759 CapsuleHeaderArray and ScatterGatherList.\r
760 Undefined on input.\r
761 @param ResetType Returns the type of reset required for the capsule update.\r
762\r
58380e9c 763 @retval EFI_SUCCESS A valid answer was returned.\r
363bb1b5 764 @retval EFI_INVALID_PARAMETER MaximumCapsuleSize is NULL.\r
765 @retval EFI_UNSUPPORTED The capsule type is not supported on this platform, and\r
766 MaximumCapsuleSize and ResetType are undefined.\r
767 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to process the query request.\r
768\r
769**/\r
770EFI_STATUS\r
771EFIAPI\r
772EfiQueryCapsuleCapabilities (\r
773 IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,\r
774 IN UINTN CapsuleCount,\r
775 OUT UINT64 *MaximumCapsuleSize,\r
776 OUT EFI_RESET_TYPE *ResetType\r
777 )\r
778{\r
779 return mInternalRT->QueryCapsuleCapabilities (\r
780 CapsuleHeaderArray,\r
781 CapsuleCount,\r
782 MaximumCapsuleSize,\r
783 ResetType\r
784 );\r
785}\r
786\r
787\r
788/**\r
789 This service is a wrapper for the UEFI Runtime Service QueryVariableInfo().\r
790\r
791 The QueryVariableInfo() function allows a caller to obtain the information about the\r
792 maximum size of the storage space available for the EFI variables, the remaining size of the storage\r
793 space available for the EFI variables and the maximum size of each individual EFI variable,\r
794 associated with the attributes specified.\r
795 The returned MaximumVariableStorageSize, RemainingVariableStorageSize,\r
796 MaximumVariableSize information may change immediately after the call based on other\r
797 runtime activities including asynchronous error events. Also, these values associated with different\r
798 attributes are not additive in nature.\r
799\r
800 @param Attributes Attributes bitmask to specify the type of variables on\r
801 which to return information. Refer to the\r
802 GetVariable() function description.\r
803 @param MaximumVariableStorageSize\r
804 On output the maximum size of the storage space\r
805 available for the EFI variables associated with the\r
806 attributes specified.\r
807 @param RemainingVariableStorageSize\r
808 Returns the remaining size of the storage space\r
809 available for the EFI variables associated with the\r
810 attributes specified..\r
811 @param MaximumVariableSize Returns the maximum size of the individual EFI\r
812 variables associated with the attributes specified.\r
813\r
58380e9c 814 @retval EFI_SUCCESS A valid answer was returned.\r
363bb1b5 815 @retval EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.\r
816 @retval EFI_UNSUPPORTED EFI_UNSUPPORTED The attribute is not supported on this platform, and the\r
817 MaximumVariableStorageSize,\r
818 RemainingVariableStorageSize, MaximumVariableSize\r
819 are undefined.\r
820\r
821**/\r
822EFI_STATUS\r
823EFIAPI\r
824EfiQueryVariableInfo (\r
825 IN UINT32 Attributes,\r
826 OUT UINT64 *MaximumVariableStorageSize,\r
827 OUT UINT64 *RemainingVariableStorageSize,\r
828 OUT UINT64 *MaximumVariableSize\r
829 )\r
830{\r
831 return mInternalRT->QueryVariableInfo (\r
832 Attributes,\r
833 MaximumVariableStorageSize,\r
834 RemainingVariableStorageSize,\r
835 MaximumVariableSize\r
836 );\r
837}\r