]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/RuntimeDxe/EfiRuntimeLib/Ia32/RuntimeLib.c
Sync all bug fixes between EDK1.04 and EDK1.06 into EdkCompatibilityPkg.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / RuntimeDxe / EfiRuntimeLib / Ia32 / RuntimeLib.c
CommitLineData
3eb9473e 1/*++\r
2\r
3e99020d 3Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
4ea9375a 4This program and the accompanying materials \r
3eb9473e 5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 RuntimeLib.c\r
15\r
16Abstract:\r
17\r
18 Light weight lib to support Tiano drivers.\r
19\r
20--*/\r
21\r
22#include "Tiano.h"\r
23#include "EfiRuntimeLib.h"\r
3e99020d 24#include "PeiHob.h"\r
3eb9473e 25#include EFI_PROTOCOL_DEFINITION (CpuIo)\r
26#include EFI_PROTOCOL_DEFINITION (FirmwareVolumeBlock)\r
27#include EFI_GUID_DEFINITION (StatusCodeCallerId)\r
3e99020d 28#include EFI_GUID_DEFINITION (Hob)\r
3eb9473e 29#include EFI_ARCH_PROTOCOL_DEFINITION (StatusCode)\r
30\r
31//\r
32// Driver Lib Module Globals\r
33//\r
34static EFI_RUNTIME_SERVICES *mRT;\r
35static EFI_EVENT mRuntimeNotifyEvent = NULL;\r
36static EFI_EVENT mEfiVirtualNotifyEvent = NULL;\r
37static BOOLEAN mRuntimeLibInitialized = FALSE;\r
38static BOOLEAN mEfiGoneVirtual = FALSE;\r
39\r
40//\r
41// Runtime Global, but you should use the Lib functions\r
42//\r
43EFI_CPU_IO_PROTOCOL *gCpuIo;\r
44BOOLEAN mEfiAtRuntime = FALSE;\r
45FVB_ENTRY *mFvbEntry;\r
46\r
ce7a12fb 47#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
3e99020d
LG
48\r
49EFI_REPORT_STATUS_CODE gReportStatusCode = NULL;\r
50EFI_EVENT gEfiStatusCodeNotifyEvent = NULL;\r
51\r
52VOID\r
53EFIAPI\r
54OnStatusCodeInstall (\r
55 IN EFI_EVENT Event,\r
56 IN VOID *Context\r
57 )\r
58{\r
59 EFI_STATUS Status;\r
60 EFI_STATUS_CODE_PROTOCOL *StatusCode;\r
61\r
62 Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **) &StatusCode);\r
63 if (!EFI_ERROR (Status)) {\r
64 gReportStatusCode = StatusCode->ReportStatusCode;\r
65 }\r
66}\r
67\r
68EFI_STATUS\r
69GetPeiProtocol (\r
70 IN EFI_GUID *ProtocolGuid,\r
71 IN VOID **Interface\r
72 )\r
73/*++\r
74\r
75Routine Description:\r
76\r
77 Searches for a Protocol Interface passed from PEI through a HOB\r
78\r
79Arguments:\r
80\r
81 ProtocolGuid - The Protocol GUID to search for in the HOB List\r
82\r
83 Interface - A pointer to the interface for the Protocol GUID\r
84\r
85Returns:\r
86\r
87 EFI_SUCCESS - The Protocol GUID was found and its interface is returned in Interface\r
88\r
89 EFI_NOT_FOUND - The Protocol GUID was not found in the HOB List\r
90\r
91--*/\r
92{\r
93 EFI_STATUS Status;\r
94 EFI_PEI_HOB_POINTERS GuidHob;\r
95\r
96 //\r
97 // Get Hob list\r
98 //\r
99 Status = EfiLibGetSystemConfigurationTable (&gEfiHobListGuid, (VOID **) &GuidHob.Raw);\r
100 if (EFI_ERROR (Status)) {\r
101 return Status;\r
102 }\r
103\r
104 for (Status = EFI_NOT_FOUND; EFI_ERROR (Status);) {\r
105 if (END_OF_HOB_LIST (GuidHob)) {\r
106 Status = EFI_NOT_FOUND;\r
107 break;\r
108 }\r
109\r
110 if (GET_HOB_TYPE (GuidHob) == EFI_HOB_TYPE_GUID_EXTENSION) {\r
111 if (EfiCompareGuid (ProtocolGuid, &GuidHob.Guid->Name)) {\r
112 Status = EFI_SUCCESS;\r
113 *Interface = (VOID *) *(UINTN *) ((UINT8 *) (&GuidHob.Guid->Name) + sizeof (EFI_GUID));\r
114 }\r
115 }\r
116\r
117 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
118 }\r
119\r
120 return Status;\r
121}\r
122\r
ce7a12fb 123#endif\r
3eb9473e 124\r
125EFI_STATUS\r
126EfiConvertPointer (\r
127 IN UINTN DebugDisposition,\r
128 IN OUT VOID *Address\r
129 )\r
130/*++\r
131\r
132Routine Description:\r
133\r
134 Determines the new virtual address that is to be used on subsequent memory accesses.\r
135\r
136Arguments:\r
137\r
138 DebugDisposition - Supplies type information for the pointer being converted.\r
139 Address - A pointer to a pointer that is to be fixed to be the value needed\r
140 for the new virtual address mappings being applied.\r
141\r
142Returns:\r
143\r
144 Status code\r
145\r
146--*/\r
147{\r
148 return mRT->ConvertPointer (DebugDisposition, Address);\r
149}\r
150\r
151EFI_STATUS\r
152EfiConvertInternalPointer (\r
153 IN OUT VOID *Address\r
154 )\r
155/*++\r
156\r
157Routine Description:\r
158\r
159 Call EfiConvertPointer() to convert internal pointer.\r
160\r
161Arguments:\r
162\r
163 Address - A pointer to a pointer that is to be fixed to be the value needed\r
164 for the new virtual address mappings being applied.\r
165\r
166Returns:\r
167\r
168 Status code\r
169\r
170--*/\r
171{\r
172 return EfiConvertPointer (EFI_INTERNAL_POINTER, Address);\r
173}\r
174\r
175VOID\r
176EFIAPI\r
177EfiRuntimeLibFvbVirtualNotifyEvent (\r
178 IN EFI_EVENT Event,\r
179 IN VOID *Context\r
180 )\r
181/*++\r
182\r
183Routine Description:\r
184\r
185 Convert all pointers in mFvbEntry after ExitBootServices.\r
186\r
187Arguments:\r
188\r
189 Event - The Event that is being processed\r
190 \r
191 Context - Event Context\r
192\r
193Returns:\r
194\r
195 None\r
196\r
197--*/\r
198{\r
199 UINTN Index;\r
200 if (mFvbEntry != NULL) {\r
201 for (Index = 0; Index < MAX_FVB_COUNT; Index++) {\r
202 if (NULL != mFvbEntry[Index].Fvb) {\r
203 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);\r
204 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);\r
205 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetVolumeAttributes);\r
206 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->SetVolumeAttributes);\r
207 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->Read);\r
208 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->Write);\r
209 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->EraseBlocks);\r
210 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb);\r
211 }\r
212\r
213 if (NULL != mFvbEntry[Index].FvbExtension) {\r
214 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);\r
215 EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].FvbExtension);\r
216 }\r
217 }\r
218\r
219 EfiConvertInternalPointer ((VOID **) &mFvbEntry);\r
220 }\r
221}\r
222\r
223VOID\r
224EFIAPI\r
225RuntimeDriverExitBootServices (\r
226 IN EFI_EVENT Event,\r
227 IN VOID *Context\r
228 )\r
229/*++\r
230\r
231Routine Description:\r
232\r
233 Set AtRuntime flag as TRUE after ExitBootServices\r
234\r
235Arguments:\r
236\r
237 Event - The Event that is being processed\r
238 \r
239 Context - Event Context\r
240\r
241Returns: \r
242\r
243 None\r
244\r
245--*/\r
246{\r
247 mEfiAtRuntime = TRUE;\r
248}\r
249\r
250extern BOOLEAN gEfiFvbInitialized;\r
251\r
252VOID\r
253EFIAPI\r
254EfiRuntimeLibVirtualNotifyEvent (\r
255 IN EFI_EVENT Event,\r
256 IN VOID *Context\r
257 )\r
258/*++\r
259\r
260Routine Description:\r
261\r
262 Fixup internal data so that EFI can be call in virtual mode.\r
263 Call the passed in Child Notify event and convert any pointers in \r
264 lib to virtual mode.\r
265\r
266Arguments:\r
267\r
268 Event - The Event that is being processed\r
269 \r
270 Context - Event Context\r
271\r
272Returns: \r
273\r
274 None\r
275\r
276--*/\r
277{\r
278 EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
279\r
280 if (Context != NULL) {\r
281 ChildNotifyEventHandler = (EFI_EVENT_NOTIFY) (UINTN) Context;\r
282 ChildNotifyEventHandler (Event, NULL);\r
283 }\r
284\r
285 if (gEfiFvbInitialized) {\r
286 EfiRuntimeLibFvbVirtualNotifyEvent (Event, Context);\r
287 }\r
288 //\r
289 // Update global for Runtime Services Table and IO\r
290 //\r
291 EfiConvertInternalPointer ((VOID **) &gCpuIo);\r
ce7a12fb 292#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
3e99020d
LG
293 if (gReportStatusCode != NULL) {\r
294 EfiConvertInternalPointer ((VOID **) &gReportStatusCode);\r
3eb9473e 295 }\r
ce7a12fb 296#endif\r
3eb9473e 297 EfiConvertInternalPointer ((VOID **) &mRT);\r
298\r
299 //\r
300 // Clear out BootService globals\r
301 //\r
302 gBS = NULL;\r
303 gST = NULL;\r
304 mEfiGoneVirtual = TRUE;\r
305}\r
306\r
307EFI_STATUS\r
308EfiInitializeRuntimeDriverLib (\r
309 IN EFI_HANDLE ImageHandle,\r
310 IN EFI_SYSTEM_TABLE *SystemTable,\r
311 IN EFI_EVENT_NOTIFY GoVirtualChildEvent\r
312 )\r
313/*++\r
314\r
315Routine Description:\r
316\r
317 Intialize runtime Driver Lib if it has not yet been initialized. \r
318\r
319Arguments:\r
320\r
321 ImageHandle - The firmware allocated handle for the EFI image.\r
322 \r
323 SystemTable - A pointer to the EFI System Table.\r
324\r
325 GoVirtualChildEvent - Caller can register a virtual notification event.\r
326\r
327Returns: \r
328\r
329 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
330\r
331--*/\r
332{\r
333 EFI_STATUS Status;\r
3e99020d
LG
334#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
335 VOID *Registration;\r
336#endif\r
3eb9473e 337\r
338 if (mRuntimeLibInitialized) {\r
339 return EFI_ALREADY_STARTED;\r
340 }\r
341\r
342 mRuntimeLibInitialized = TRUE;\r
343\r
344 gST = SystemTable;\r
345 ASSERT (gST != NULL);\r
346\r
347 gBS = SystemTable->BootServices;\r
348 ASSERT (gBS != NULL);\r
349 mRT = SystemTable->RuntimeServices;\r
350 ASSERT (mRT != NULL);\r
351\r
352 Status = EfiLibGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);\r
353 ASSERT_EFI_ERROR (Status);\r
354\r
ce7a12fb 355#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
3e99020d
LG
356 //\r
357 // Register EFI_STATUS_CODE_PROTOCOL notify function\r
358 //\r
359 Status = gBS->CreateEvent (\r
360 EFI_EVENT_NOTIFY_SIGNAL,\r
361 EFI_TPL_CALLBACK,\r
362 OnStatusCodeInstall,\r
363 NULL,\r
364 &gEfiStatusCodeNotifyEvent\r
365 );\r
366 ASSERT_EFI_ERROR (Status);\r
367\r
368 Status = gBS->RegisterProtocolNotify (\r
369 &gEfiStatusCodeRuntimeProtocolGuid,\r
370 gEfiStatusCodeNotifyEvent,\r
371 &Registration\r
372 );\r
373 ASSERT_EFI_ERROR (Status);\r
374\r
375 gBS->SignalEvent (gEfiStatusCodeNotifyEvent);\r
ce7a12fb 376#endif\r
3eb9473e 377\r
4b79797e 378 Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, (VOID **) &gCpuIo);\r
3eb9473e 379 if (EFI_ERROR (Status)) {\r
380 gCpuIo = NULL;\r
381 }\r
382\r
383 //\r
384 // Register our ExitBootServices () notify function\r
385 //\r
386 Status = gBS->CreateEvent (\r
387 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r
388 EFI_TPL_NOTIFY,\r
389 RuntimeDriverExitBootServices,\r
390 NULL,\r
391 &mRuntimeNotifyEvent\r
392 );\r
393 ASSERT_EFI_ERROR (Status);\r
394\r
395 //\r
396 // Register SetVirtualAddressMap () notify function\r
397 //\r
398 Status = gBS->CreateEvent (\r
399 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
400 EFI_TPL_NOTIFY,\r
401 EfiRuntimeLibVirtualNotifyEvent,\r
402 (VOID *) (UINTN) GoVirtualChildEvent,\r
403 &mEfiVirtualNotifyEvent\r
404 );\r
405 ASSERT_EFI_ERROR (Status);\r
406\r
407 return EFI_SUCCESS;\r
408}\r
409\r
410EFI_STATUS\r
411EfiShutdownRuntimeDriverLib (\r
412 VOID\r
413 )\r
414/*++\r
415\r
416Routine Description:\r
417\r
418 This routine will free some resources which have been allocated in\r
419 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, \r
420 it must call this routine to free the allocated resource before the exiting.\r
421\r
422Arguments:\r
423\r
424 None\r
425\r
426Returns: \r
427\r
428 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully\r
429 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all\r
430\r
431--*/\r
432{\r
433 EFI_STATUS Status;\r
434\r
435 if (!mRuntimeLibInitialized) {\r
436 //\r
437 // You must call EfiInitializeRuntimeDriverLib() first\r
438 //\r
439 return EFI_UNSUPPORTED;\r
440 }\r
441\r
442 mRuntimeLibInitialized = FALSE;\r
443\r
444 //\r
445 // Close our ExitBootServices () notify function\r
446 //\r
447 if (mRuntimeNotifyEvent != NULL) {\r
448 Status = gBS->CloseEvent (mRuntimeNotifyEvent);\r
449 ASSERT_EFI_ERROR (Status);\r
450 }\r
451\r
452 //\r
453 // Close SetVirtualAddressMap () notify function\r
454 //\r
455 if (mEfiVirtualNotifyEvent != NULL) {\r
456 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
457 ASSERT_EFI_ERROR (Status);\r
458 }\r
459\r
3e99020d
LG
460#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
461 //\r
462 // Close EfiStatusCodeRuntimeProtocol notify function\r
463 //\r
464 if (gEfiStatusCodeNotifyEvent != NULL) {\r
465 Status = gBS->CloseEvent (gEfiStatusCodeNotifyEvent);\r
466 ASSERT_EFI_ERROR (Status);\r
467 }\r
468#endif\r
469\r
3eb9473e 470 return EFI_SUCCESS;\r
471}\r
472\r
473EFI_STATUS\r
474EfiInitializeSmmDriverLib (\r
475 IN EFI_HANDLE ImageHandle,\r
476 IN EFI_SYSTEM_TABLE *SystemTable\r
477 )\r
478/*++\r
479\r
480Routine Description:\r
481\r
482 Intialize runtime Driver Lib if it has not yet been initialized. \r
483\r
484Arguments:\r
485\r
486 ImageHandle - The firmware allocated handle for the EFI image.\r
487 \r
488 SystemTable - A pointer to the EFI System Table.\r
489\r
490Returns: \r
491\r
492 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
493\r
494--*/\r
495{\r
496 EFI_STATUS Status;\r
3e99020d
LG
497#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
498 VOID *Registration;\r
499#endif\r
3eb9473e 500\r
501 if (mRuntimeLibInitialized) {\r
502 return EFI_ALREADY_STARTED;\r
503 }\r
504\r
505 mRuntimeLibInitialized = TRUE;\r
506\r
507 gST = SystemTable;\r
508 ASSERT (gST != NULL);\r
509\r
510 gBS = SystemTable->BootServices;\r
511 ASSERT (gBS != NULL);\r
512 mRT = SystemTable->RuntimeServices;\r
513 ASSERT (mRT != NULL);\r
514\r
ce7a12fb 515#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
3e99020d
LG
516 //\r
517 // Register EFI_STATUS_CODE_PROTOCOL notify function\r
518 //\r
519 Status = gBS->CreateEvent (\r
520 EFI_EVENT_NOTIFY_SIGNAL,\r
521 EFI_TPL_CALLBACK,\r
522 OnStatusCodeInstall,\r
523 NULL,\r
524 &gEfiStatusCodeNotifyEvent\r
525 );\r
526 ASSERT_EFI_ERROR (Status);\r
527\r
528 Status = gBS->RegisterProtocolNotify (\r
529 &gEfiStatusCodeRuntimeProtocolGuid,\r
530 gEfiStatusCodeNotifyEvent,\r
531 &Registration\r
532 );\r
533 ASSERT_EFI_ERROR (Status);\r
534\r
535 gBS->SignalEvent (gEfiStatusCodeNotifyEvent);\r
ce7a12fb 536#endif\r
3eb9473e 537\r
4b79797e 538 Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, (VOID **) &gCpuIo);\r
3eb9473e 539 if (EFI_ERROR (Status)) {\r
540 gCpuIo = NULL;\r
541 }\r
542\r
543 return EFI_SUCCESS;\r
544}\r
545\r
546BOOLEAN\r
547EfiAtRuntime (\r
548 VOID\r
549 )\r
550/*++\r
551\r
552Routine Description:\r
553 Return TRUE if ExitBootServices () has been called\r
554\r
555Arguments:\r
556 NONE\r
557\r
558Returns: \r
559 TRUE - If ExitBootServices () has been called\r
560\r
561--*/\r
562{\r
563 return mEfiAtRuntime;\r
564}\r
565\r
566BOOLEAN\r
567EfiGoneVirtual (\r
568 VOID\r
569 )\r
570/*++\r
571\r
572Routine Description:\r
573 Return TRUE if SetVirtualAddressMap () has been called\r
574\r
575Arguments:\r
576 NONE\r
577\r
578Returns: \r
579 TRUE - If SetVirtualAddressMap () has been called\r
580\r
581--*/\r
582{\r
583 return mEfiGoneVirtual;\r
584}\r
585//\r
586// The following functions hide the mRT local global from the call to\r
587// runtime service in the EFI system table.\r
588//\r
589EFI_STATUS\r
590EfiGetTime (\r
591 OUT EFI_TIME *Time,\r
592 OUT EFI_TIME_CAPABILITIES *Capabilities\r
593 )\r
594/*++\r
595\r
596Routine Description:\r
597\r
598 Returns the current time and date information, and the time-keeping \r
599 capabilities of the hardware platform.\r
600\r
601Arguments:\r
602\r
603 Time - A pointer to storage to receive a snapshot of the current time.\r
fd0d281b 604 Capabilities - An optional pointer to a buffer to receive the real time clock device's\r
3eb9473e 605 capabilities.\r
606\r
607Returns:\r
608\r
609 Status code\r
610\r
611--*/\r
612{\r
613 return mRT->GetTime (Time, Capabilities);\r
614}\r
615\r
616EFI_STATUS\r
617EfiSetTime (\r
618 IN EFI_TIME *Time\r
619 )\r
620/*++\r
621\r
622Routine Description:\r
623\r
624 Sets the current local time and date information.\r
625\r
626Arguments:\r
627\r
628 Time - A pointer to the current time.\r
629\r
630Returns:\r
631\r
632 Status code\r
633\r
634--*/\r
635{\r
636 return mRT->SetTime (Time);\r
637}\r
638\r
639EFI_STATUS\r
640EfiGetWakeupTime (\r
641 OUT BOOLEAN *Enabled,\r
642 OUT BOOLEAN *Pending,\r
643 OUT EFI_TIME *Time\r
644 )\r
645/*++\r
646\r
647Routine Description:\r
648\r
649 Returns the current wakeup alarm clock setting.\r
650\r
651Arguments:\r
652\r
653 Enabled - Indicates if the alarm is currently enabled or disabled.\r
654 Pending - Indicates if the alarm signal is pending and requires acknowledgement.\r
655 Time - The current alarm setting.\r
656\r
657Returns:\r
658\r
659 Status code\r
660\r
661--*/\r
662{\r
663 return mRT->GetWakeupTime (Enabled, Pending, Time);\r
664}\r
665\r
666EFI_STATUS\r
667EfiSetWakeupTime (\r
668 IN BOOLEAN Enable,\r
669 IN EFI_TIME *Time\r
670 )\r
671/*++\r
672\r
673Routine Description:\r
674\r
675 Sets the system wakeup alarm clock time.\r
676\r
677Arguments:\r
678\r
679 Enable - Enable or disable the wakeup alarm.\r
680 Time - If Enable is TRUE, the time to set the wakeup alarm for.\r
681 If Enable is FALSE, then this parameter is optional, and may be NULL.\r
682\r
683Returns:\r
684\r
685 Status code\r
686\r
687--*/\r
688{\r
689 return mRT->SetWakeupTime (Enable, Time);\r
690}\r
691\r
692EFI_STATUS\r
693EfiGetVariable (\r
694 IN CHAR16 *VariableName,\r
695 IN EFI_GUID * VendorGuid,\r
696 OUT UINT32 *Attributes OPTIONAL,\r
697 IN OUT UINTN *DataSize,\r
698 OUT VOID *Data\r
699 )\r
700/*++\r
701\r
702Routine Description:\r
703\r
704 Returns the value of a variable.\r
705\r
706Arguments:\r
707\r
708 VariableName - A Null-terminated Unicode string that is the name of the\r
fd0d281b 709 vendor's variable.\r
3eb9473e 710 VendorGuid - A unique identifier for the vendor.\r
711 Attributes - If not NULL, a pointer to the memory location to return the\r
712 attributes bitmask for the variable.\r
713 DataSize - On input, the size in bytes of the return Data buffer.\r
714 On output the size of data returned in Data.\r
715 Data - The buffer to return the contents of the variable.\r
716\r
717Returns:\r
718\r
719 Status code\r
720\r
721--*/\r
722{\r
723 return mRT->GetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);\r
724}\r
725\r
726EFI_STATUS\r
727EfiGetNextVariableName (\r
728 IN OUT UINTN *VariableNameSize,\r
729 IN OUT CHAR16 *VariableName,\r
730 IN OUT EFI_GUID *VendorGuid\r
731 )\r
732/*++\r
733\r
734Routine Description:\r
735\r
736 Enumerates the current variable names.\r
737\r
738Arguments:\r
739\r
740 VariableNameSize - The size of the VariableName buffer.\r
741 VariableName - On input, supplies the last VariableName that was returned\r
742 by GetNextVariableName(). \r
743 On output, returns the Nullterminated Unicode string of the\r
744 current variable.\r
745 VendorGuid - On input, supplies the last VendorGuid that was returned by\r
746 GetNextVariableName(). \r
747 On output, returns the VendorGuid of the current variable.\r
748\r
749Returns:\r
750\r
751 Status code\r
752\r
753--*/\r
754{\r
755 return mRT->GetNextVariableName (VariableNameSize, VariableName, VendorGuid);\r
756}\r
757\r
758EFI_STATUS\r
759EfiSetVariable (\r
760 IN CHAR16 *VariableName,\r
761 IN EFI_GUID *VendorGuid,\r
762 IN UINT32 Attributes,\r
763 IN UINTN DataSize,\r
764 IN VOID *Data\r
765 )\r
766/*++\r
767\r
768Routine Description:\r
769\r
770 Sets the value of a variable.\r
771\r
772Arguments:\r
773\r
774 VariableName - A Null-terminated Unicode string that is the name of the\r
fd0d281b 775 vendor's variable.\r
3eb9473e 776 VendorGuid - A unique identifier for the vendor.\r
777 Attributes - Attributes bitmask to set for the variable.\r
778 DataSize - The size in bytes of the Data buffer.\r
779 Data - The contents for the variable.\r
780\r
781Returns:\r
782\r
783 Status code\r
784\r
785--*/\r
786{\r
787 return mRT->SetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);\r
788}\r
789\r
ce7a12fb 790\r
3eb9473e 791#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
792\r
793EFI_STATUS\r
794EfiQueryVariableInfo (\r
795 IN UINT32 Attributes,\r
796 OUT UINT64 *MaximumVariableStorageSize,\r
797 OUT UINT64 *RemainingVariableStorageSize,\r
798 OUT UINT64 *MaximumVariableSize\r
799 )\r
800\r
801/*++\r
802\r
803Routine Description:\r
804\r
805 This code returns information about the EFI variables.\r
806\r
807Arguments:\r
808\r
809 Attributes Attributes bitmask to specify the type of variables \r
810 on which to return information.\r
811 MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
812 for the EFI variables associated with the attributes specified.\r
813 RemainingVariableStorageSize Pointer to the remaining size of the storage space available \r
814 for the EFI variables associated with the attributes specified.\r
815 MaximumVariableSize Pointer to the maximum size of the individual EFI variables\r
816 associated with the attributes specified.\r
817\r
818Returns:\r
819\r
820 Status code\r
821\r
822--*/\r
823{\r
824 return mRT->QueryVariableInfo (Attributes, MaximumVariableStorageSize, RemainingVariableStorageSize, MaximumVariableSize);\r
825}\r
826\r
827#endif\r
828\r
829EFI_STATUS\r
830EfiGetNextHighMonotonicCount (\r
831 OUT UINT32 *HighCount\r
832 )\r
833/*++\r
834\r
835Routine Description:\r
836\r
fd0d281b 837 Returns the next high 32 bits of the platform's monotonic counter.\r
3eb9473e 838\r
839Arguments:\r
840\r
841 HighCount - Pointer to returned value.\r
842\r
843Returns:\r
844\r
845 Status code\r
846\r
847--*/\r
848{\r
849 return mRT->GetNextHighMonotonicCount (HighCount);\r
850}\r
851\r
852VOID\r
853EfiResetSystem (\r
854 IN EFI_RESET_TYPE ResetType,\r
855 IN EFI_STATUS ResetStatus,\r
856 IN UINTN DataSize,\r
857 IN CHAR16 *ResetData\r
858 )\r
859/*++\r
860\r
861Routine Description:\r
862\r
863 Resets the entire platform.\r
864\r
865Arguments:\r
866\r
867 ResetType - The type of reset to perform.\r
868 ResetStatus - The status code for the reset.\r
869 DataSize - The size, in bytes, of ResetData.\r
870 ResetData - A data buffer that includes a Null-terminated Unicode string, optionally\r
871 followed by additional binary data.\r
872\r
873Returns:\r
874\r
875 None\r
876\r
877--*/\r
878{\r
879 mRT->ResetSystem (ResetType, ResetStatus, DataSize, ResetData);\r
880}\r
881\r
882EFI_STATUS\r
883EfiReportStatusCode (\r
884 IN EFI_STATUS_CODE_TYPE CodeType,\r
885 IN EFI_STATUS_CODE_VALUE Value,\r
886 IN UINT32 Instance,\r
3e99020d
LG
887 IN EFI_GUID *CallerId OPTIONAL,\r
888 IN EFI_STATUS_CODE_DATA *Data OPTIONAL \r
3eb9473e 889 )\r
890/*++\r
891\r
892Routine Description:\r
893\r
894 Status Code reporter\r
895\r
896Arguments:\r
897\r
898 CodeType - Type of Status Code.\r
899 \r
900 Value - Value to output for Status Code.\r
901 \r
902 Instance - Instance Number of this status code.\r
903 \r
904 CallerId - ID of the caller of this status code.\r
905 \r
906 Data - Optional data associated with this status code.\r
907\r
908Returns:\r
909\r
910 Status code\r
911\r
912--*/\r
913{\r
3e99020d 914 EFI_STATUS Status;\r
bdabfae7 915\r
3e99020d
LG
916#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
917 if (gReportStatusCode == NULL) {\r
918 //\r
919 // Because we've installed the protocol notification on EfiStatusCodeRuntimeProtocol,\r
920 // running here indicates that the StatusCode driver has not started yet.\r
921 //\r
ce7a12fb 922 if (EfiAtRuntime ()) {\r
3e99020d
LG
923 //\r
924 // Running here only when StatusCode driver never starts.\r
925 //\r
ce7a12fb 926 return EFI_UNSUPPORTED;\r
927 }\r
3e99020d
LG
928\r
929 //\r
930 // Try to get the PEI version of ReportStatusCode.\r
931 //\r
932 Status = GetPeiProtocol (&gEfiStatusCodeRuntimeProtocolGuid, (VOID **) &gReportStatusCode);\r
933 if (EFI_ERROR (Status)) {\r
ce7a12fb 934 return EFI_UNSUPPORTED;\r
935 }\r
936 }\r
3e99020d 937 Status = gReportStatusCode (CodeType, Value, Instance, CallerId, Data);\r
ce7a12fb 938#else\r
939 if (mRT == NULL) {\r
940 return EFI_UNSUPPORTED;\r
941 }\r
942 //\r
943 // Check whether EFI_RUNTIME_SERVICES has Tiano Extension\r
944 //\r
945 Status = EFI_UNSUPPORTED;\r
946 if (mRT->Hdr.Revision == EFI_SPECIFICATION_VERSION &&\r
947 mRT->Hdr.HeaderSize == sizeof (EFI_RUNTIME_SERVICES) &&\r
948 mRT->ReportStatusCode != NULL) {\r
3eb9473e 949 Status = mRT->ReportStatusCode (CodeType, Value, Instance, CallerId, Data);\r
ce7a12fb 950 }\r
3eb9473e 951#endif\r
952 return Status;\r
953}\r