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