]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/RuntimeDxe/EfiRuntimeLib/Ipf/RuntimeLib.c
Add Missing invocations to VA_END() for VA_START().
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / RuntimeDxe / EfiRuntimeLib / Ipf / RuntimeLib.c
CommitLineData
3eb9473e 1/*++\r
2\r
3bbe68a3 3Copyright (c) 2004 - 2012, 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 Sal drivers.\r
19\r
20--*/\r
21\r
22#include "Tiano.h"\r
23#include "EfiRuntimeLib.h"\r
24#include EFI_PROTOCOL_DEFINITION (ExtendedSalBootService)\r
25#include EFI_PROTOCOL_DEFINITION (ExtendedSalGuid)\r
26#include "IpfDefines.h"\r
27#include "SalApi.h"\r
28\r
29//\r
30// Worker functions in EsalLib.s\r
31//\r
32SAL_RETURN_REGS\r
33GetEsalEntryPoint (\r
34 VOID\r
35 );\r
36\r
37SAL_RETURN_REGS\r
38SetEsalPhysicalEntryPoint (\r
39 IN UINT64 EntryPoint,\r
40 IN UINT64 Gp\r
41 );\r
42\r
43SAL_RETURN_REGS\r
44SetEsalVirtualEntryPoint (\r
45 IN UINT64 EntryPoint,\r
46 IN UINT64 Gp\r
47 );\r
48\r
49VOID\r
50SalFlushCache (\r
51 IN EFI_PHYSICAL_ADDRESS Start,\r
52 IN UINT64 Length\r
53 );\r
54\r
55//\r
56// Module Globals. It's not valid to use these after the\r
57// EfiRuntimeLibVirtualNotifyEvent has fired.\r
58//\r
59static EFI_EVENT mEfiVirtualNotifyEvent;\r
60static EFI_RUNTIME_SERVICES *mRT;\r
61static EFI_PLABEL mPlabel;\r
62static EXTENDED_SAL_BOOT_SERVICE_PROTOCOL *mEsalBootService;\r
63static BOOLEAN mRuntimeLibInitialized = FALSE;\r
64\r
65VOID\r
66EFIAPI\r
67EfiRuntimeLibVirtualNotifyEvent (\r
68 IN EFI_EVENT Event,\r
69 IN VOID *Context\r
70 )\r
71/*++\r
72\r
73Routine Description:\r
74\r
75 Fixup internal data so that EFI and SAL can be call in virtual mode.\r
76 Call the passed in Child Notify event and convert any pointers in \r
77 lib to virtual mode.\r
78\r
79Arguments:\r
80\r
81 Event - The Event that is being processed\r
82 \r
83 Context - Event Context\r
84\r
85Returns: \r
86\r
87 None\r
88\r
89--*/\r
90{\r
91 EFI_EVENT_NOTIFY ChildNotify;\r
92\r
93 if (Context != NULL) {\r
94 //\r
95 // Call child event\r
96 //\r
97 ChildNotify = (EFI_EVENT_NOTIFY) (UINTN) Context;\r
98 ChildNotify (Event, NULL);\r
99 }\r
100\r
101 mRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID **) &mPlabel.EntryPoint);\r
102 mRT->ConvertPointer (EFI_INTERNAL_POINTER | EFI_IPF_GP_POINTER, (VOID **) &mPlabel.GP);\r
103\r
104 SetEsalVirtualEntryPoint (mPlabel.EntryPoint, mPlabel.GP);\r
105\r
106 //\r
107 // Clear out BootService globals\r
108 //\r
109 gBS = NULL;\r
110 gST = NULL;\r
111 mRT = NULL;\r
112\r
113 //\r
114 // Pointers don't work you must use a direct lib call\r
115 //\r
116}\r
117\r
118EFI_STATUS\r
119EfiInitializeRuntimeDriverLib (\r
120 IN EFI_HANDLE ImageHandle,\r
121 IN EFI_SYSTEM_TABLE *SystemTable,\r
122 IN EFI_EVENT_NOTIFY GoVirtualChildEvent\r
123 )\r
124/*++\r
125\r
126Routine Description:\r
127\r
128 Intialize runtime Driver Lib if it has not yet been initialized. \r
129\r
130Arguments:\r
131\r
132 ImageHandle - The firmware allocated handle for the EFI image.\r
133 \r
134 SystemTable - A pointer to the EFI System Table.\r
135\r
136 GoVirtualChildEvent - Caller can register a virtual notification event.\r
137\r
138Returns: \r
139\r
140 EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
141\r
142--*/\r
143{\r
144 EFI_STATUS Status;\r
145 EFI_PLABEL *Plabel;\r
146\r
147 if (mRuntimeLibInitialized) {\r
148 return EFI_ALREADY_STARTED;\r
149 }\r
150\r
151 mRuntimeLibInitialized = TRUE;\r
152\r
153 gST = SystemTable;\r
154 gBS = SystemTable->BootServices;\r
155 mRT = SystemTable->RuntimeServices;\r
156 Status = EfiLibGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);\r
157 ASSERT_EFI_ERROR (Status);\r
158\r
159 //\r
160 // The protocol contains a function pointer, which is an indirect procedure call.\r
161 // An indirect procedure call goes through a plabel, and pointer to a function is\r
162 // a pointer to a plabel. To implement indirect procedure calls that can work in\r
163 // both physical and virtual mode, two plabels are required (one physical and one\r
164 // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it\r
165 // away. We cache it in a module global, so we can register the vitrual version.\r
166 //\r
717656c7 167 Status = gBS->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid, NULL, (VOID **) &mEsalBootService);\r
3eb9473e 168 ASSERT_EFI_ERROR (Status);\r
169\r
170 Plabel = (EFI_PLABEL *) (UINTN) mEsalBootService->ExtendedSalProc;\r
171\r
172 mPlabel.EntryPoint = Plabel->EntryPoint;\r
173 mPlabel.GP = Plabel->GP;\r
174\r
175 SetEsalPhysicalEntryPoint (mPlabel.EntryPoint, mPlabel.GP);\r
176\r
177 //\r
178 // Create a Virtual address change notification event. Pass in the callers\r
179 // GoVirtualChildEvent so it's get passed to the event as contex.\r
180 //\r
181 Status = gBS->CreateEvent (\r
182 EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
183 EFI_TPL_NOTIFY,\r
184 EfiRuntimeLibVirtualNotifyEvent,\r
185 (VOID *) GoVirtualChildEvent,\r
186 &mEfiVirtualNotifyEvent\r
187 );\r
188 ASSERT_EFI_ERROR (Status);\r
189\r
190 return EFI_SUCCESS;\r
191}\r
192\r
193EFI_STATUS\r
194EfiShutdownRuntimeDriverLib (\r
195 VOID\r
196 )\r
197/*++\r
198\r
199Routine Description:\r
200\r
201 This routine will free some resources which have been allocated in\r
202 EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, \r
203 it must call this routine to free the allocated resource before the exiting.\r
204\r
205Arguments:\r
206\r
207 None\r
208\r
209Returns: \r
210\r
211 EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully\r
212 EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all\r
213\r
214--*/\r
215{\r
216 EFI_STATUS Status;\r
217\r
218 if (!mRuntimeLibInitialized) {\r
219 //\r
220 // You must call EfiInitializeRuntimeDriverLib() first\r
221 //\r
222 return EFI_UNSUPPORTED;\r
223 }\r
224\r
225 mRuntimeLibInitialized = FALSE;\r
226\r
227 //\r
228 // Close SetVirtualAddressMap () notify function\r
229 //\r
230 Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
231 ASSERT_EFI_ERROR (Status);\r
232\r
233 return EFI_SUCCESS;\r
234}\r
235 \r
236EFI_STATUS\r
237RegisterEsalFunction (\r
238 IN UINT64 FunctionId,\r
239 IN EFI_GUID *ClassGuid,\r
240 IN SAL_INTERNAL_EXTENDED_SAL_PROC Function,\r
241 IN VOID *ModuleGlobal\r
242 )\r
243/*++\r
244\r
245Routine Description:\r
246\r
247 Register ESAL Class Function and it's asociated global.\r
248 This function is boot service only!\r
249\r
250Arguments:\r
251 FunctionId - ID of function to register\r
252 ClassGuid - GUID of function class \r
253 Function - Function to register under ClassGuid/FunctionId pair\r
254 ModuleGlobal - Module global for Function.\r
255\r
256Returns: \r
257 EFI_SUCCESS - If ClassGuid/FunctionId Function was registered.\r
258\r
259--*/\r
260{\r
261 return mEsalBootService->AddExtendedSalProc (\r
262 mEsalBootService,\r
263 ClassGuid,\r
264 FunctionId,\r
265 Function,\r
266 ModuleGlobal\r
267 );\r
268}\r
269\r
270EFI_STATUS\r
271RegisterEsalClass (\r
272 IN EFI_GUID *ClassGuid,\r
273 IN VOID *ModuleGlobal,\r
274 ...\r
275 )\r
276/*++\r
277\r
278Routine Description:\r
279\r
280 Register ESAL Class and it's asociated global.\r
281 This function is boot service only!\r
282\r
283Arguments:\r
284 ClassGuid - GUID of function class \r
285 ModuleGlobal - Module global for Function.\r
286 ... - SAL_INTERNAL_EXTENDED_SAL_PROC and FunctionId pairs. NULL \r
287 indicates the end of the list.\r
288\r
289Returns: \r
290 EFI_SUCCESS - All members of ClassGuid registered\r
291\r
292--*/\r
293{\r
294 VA_LIST Args;\r
295 EFI_STATUS Status;\r
296 SAL_INTERNAL_EXTENDED_SAL_PROC Function;\r
297 UINT64 FunctionId;\r
298 EFI_HANDLE NewHandle;\r
299\r
300 VA_START (Args, ModuleGlobal);\r
301\r
302 Status = EFI_SUCCESS;\r
303 while (!EFI_ERROR (Status)) {\r
304 Function = (SAL_INTERNAL_EXTENDED_SAL_PROC) VA_ARG (Args, SAL_INTERNAL_EXTENDED_SAL_PROC);\r
305 if (Function == NULL) {\r
306 break;\r
307 }\r
308\r
309 FunctionId = VA_ARG (Args, UINT64);\r
310\r
311 Status = RegisterEsalFunction (FunctionId, ClassGuid, Function, ModuleGlobal);\r
312 }\r
313\r
3bbe68a3 314 VA_END (Args);\r
315\r
3eb9473e 316 if (EFI_ERROR (Status)) {\r
317 return Status;\r
318 }\r
319\r
320 NewHandle = NULL;\r
321 return gBS->InstallProtocolInterface (\r
322 &NewHandle,\r
323 ClassGuid,\r
324 EFI_NATIVE_INTERFACE,\r
325 NULL\r
326 );\r
327}\r
328\r
329SAL_RETURN_REGS\r
330EfiCallEsalService (\r
331 IN EFI_GUID *ClassGuid,\r
332 IN UINT64 FunctionId,\r
333 IN UINT64 Arg2,\r
334 IN UINT64 Arg3,\r
335 IN UINT64 Arg4,\r
336 IN UINT64 Arg5,\r
337 IN UINT64 Arg6,\r
338 IN UINT64 Arg7,\r
339 IN UINT64 Arg8\r
340 )\r
341/*++\r
342\r
343Routine Description:\r
344\r
345 Call module that is not linked direclty to this module. This code is IP \r
346 relative and hides the binding issues of virtual or physical calling. The\r
347 function that gets dispatched has extra arguments that include the registered\r
348 module global and a boolean flag to indicate if the system is in virutal mode.\r
349\r
350Arguments:\r
351 ClassGuid - GUID of function\r
352 FunctionId - Function in ClassGuid to call\r
353 Arg2 - Argument 2 ClassGuid/FunctionId defined\r
354 Arg3 - Argument 3 ClassGuid/FunctionId defined\r
355 Arg4 - Argument 4 ClassGuid/FunctionId defined\r
356 Arg5 - Argument 5 ClassGuid/FunctionId defined\r
357 Arg6 - Argument 6 ClassGuid/FunctionId defined\r
358 Arg7 - Argument 7 ClassGuid/FunctionId defined\r
359 Arg8 - Argument 8 ClassGuid/FunctionId defined\r
360\r
361Returns: \r
362 Status of ClassGuid/FuncitonId\r
363\r
364--*/\r
365{\r
366 SAL_RETURN_REGS ReturnReg;\r
367 SAL_EXTENDED_SAL_PROC EsalProc;\r
368\r
369 ReturnReg = GetEsalEntryPoint ();\r
370 if (ReturnReg.Status != EFI_SAL_SUCCESS) {\r
371 return ReturnReg;\r
372 }\r
373\r
374 if (ReturnReg.r11 & PSR_IT_MASK) {\r
375 //\r
376 // Virtual mode plabel to entry point\r
377 //\r
378 EsalProc = (SAL_EXTENDED_SAL_PROC) ReturnReg.r10;\r
379 } else {\r
380 //\r
381 // Physical mode plabel to entry point\r
382 //\r
383 EsalProc = (SAL_EXTENDED_SAL_PROC) ReturnReg.r9;\r
384 }\r
385\r
386 return EsalProc (\r
387 ClassGuid,\r
388 FunctionId,\r
389 Arg2,\r
390 Arg3,\r
391 Arg4,\r
392 Arg5,\r
393 Arg6,\r
394 Arg7,\r
395 Arg8\r
396 );\r
397}\r
398\r
399EFI_STATUS\r
400EfiConvertPointer (\r
401 IN UINTN DebugDisposition,\r
402 IN OUT VOID *Address\r
403 )\r
404/*++\r
405\r
406Routine Description:\r
407\r
408 Determines the new virtual address that is to be used on subsequent memory accesses.\r
409\r
410Arguments:\r
411\r
412 DebugDisposition - Supplies type information for the pointer being converted.\r
413 Address - A pointer to a pointer that is to be fixed to be the value needed\r
414 for the new virtual address mappings being applied.\r
415\r
416Returns:\r
417\r
418 Status code\r
419\r
420--*/\r
421{\r
422 return mRT->ConvertPointer (DebugDisposition, Address);\r
423}\r
424\r
425BOOLEAN\r
426EfiGoneVirtual (\r
427 VOID\r
428 )\r
429/*++\r
430\r
431Routine Description:\r
432 Return TRUE if SetVirtualAddressMap () has been called\r
433\r
434Arguments:\r
435 NONE\r
436\r
437Returns: \r
438 TRUE - If SetVirtualAddressMap () has been called\r
439\r
440--*/\r
441{\r
442 EFI_GUID Guid = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;\r
443 SAL_RETURN_REGS ReturnReg;\r
444\r
445 ReturnReg = EfiCallEsalService (&Guid, IsVirtual, 0, 0, 0, 0, 0, 0, 0);\r
446\r
447 return (BOOLEAN) (ReturnReg.r9 == 1);\r
448}\r
449\r
450BOOLEAN\r
451EfiAtRuntime (\r
452 VOID\r
453 )\r
454/*++\r
455\r
456Routine Description:\r
457 Return TRUE if ExitBootService () has been called\r
458\r
459Arguments:\r
460 NONE\r
461\r
462Returns: \r
463 TRUE - If ExitBootService () has been called\r
464\r
465--*/\r
466{\r
467 EFI_GUID Guid = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;\r
468 SAL_RETURN_REGS ReturnReg;\r
469\r
470 ReturnReg = EfiCallEsalService (&Guid, IsEfiRuntime, 0, 0, 0, 0, 0, 0, 0);\r
471\r
472 return (BOOLEAN) (ReturnReg.r9 == 1);\r
473}\r
474\r
475EFI_STATUS\r
476EfiReportStatusCode (\r
477 IN EFI_STATUS_CODE_TYPE CodeType,\r
478 IN EFI_STATUS_CODE_VALUE Value,\r
479 IN UINT32 Instance,\r
480 IN EFI_GUID * CallerId,\r
481 IN EFI_STATUS_CODE_DATA * Data OPTIONAL\r
482 )\r
483/*++\r
484\r
485Routine Description:\r
486\r
487 Status Code reporter\r
488\r
489Arguments:\r
490\r
491 CodeType - Type of Status Code.\r
492 \r
493 Value - Value to output for Status Code.\r
494 \r
495 Instance - Instance Number of this status code.\r
496 \r
497 CallerId - ID of the caller of this status code.\r
498 \r
499 Data - Optional data associated with this status code.\r
500\r
501Returns:\r
502\r
503 Status code\r
504\r
505--*/\r
506{\r
507 EFI_GUID Guid = EFI_EXTENDED_SAL_STATUS_CODE_SERVICES_PROTOCOL_GUID;\r
508 SAL_RETURN_REGS ReturnReg;\r
509\r
510\r
511 ReturnReg = EfiCallEsalService (\r
512 &Guid,\r
513 StatusCode,\r
514 (UINT64) CodeType,\r
515 (UINT64) Value,\r
516 (UINT64) Instance,\r
517 (UINT64) CallerId,\r
518 (UINT64) Data,\r
519 0,\r
520 0\r
521 );\r
522\r
523 return (EFI_STATUS) ReturnReg.Status;\r
524}\r
525//\r
526// Sal Reset Driver Class\r
527//\r
528VOID\r
529EfiResetSystem (\r
530 IN EFI_RESET_TYPE ResetType,\r
531 IN EFI_STATUS ResetStatus,\r
532 IN UINTN DataSize,\r
533 IN CHAR16 *ResetData\r
534 )\r
535/*++\r
536\r
537Routine Description:\r
538\r
539 Resets the entire platform.\r
540\r
541Arguments:\r
542\r
543 ResetType - The type of reset to perform.\r
544 ResetStatus - The status code for the reset.\r
545 DataSize - The size, in bytes, of ResetData.\r
546 ResetData - A data buffer that includes a Null-terminated Unicode string, optionally\r
547 followed by additional binary data.\r
548\r
549Returns:\r
550\r
551 None\r
552\r
553--*/\r
554{\r
555 EFI_GUID Guid = EFI_EXTENDED_SAL_RESET_SERVICES_PROTOCOL_GUID;\r
556\r
557 EfiCallEsalService (\r
558 &Guid,\r
559 ResetSystem,\r
560 (UINT64) ResetType,\r
561 (UINT64) ResetStatus,\r
562 (UINT64) DataSize,\r
563 (UINT64) ResetData,\r
564 0,\r
565 0,\r
566 0\r
567 );\r
568}\r
569//\r
570// Sal MTC Driver Class\r
571//\r
572EFI_STATUS\r
573EfiGetNextHighMonotonicCount (\r
574 OUT UINT32 *HighCount\r
575 )\r
576/*++\r
577\r
578Routine Description:\r
579\r
fd0d281b 580 Returns the next high 32 bits of the platform's monotonic counter.\r
3eb9473e 581\r
582Arguments:\r
583\r
584 HighCount - Pointer to returned value.\r
585\r
586Returns:\r
587\r
588 Status code\r
589\r
590--*/\r
591{\r
592 SAL_RETURN_REGS ReturnReg;\r
593\r
594 EFI_GUID Guid = EFI_EXTENDED_SAL_MTC_SERVICES_PROTOCOL_GUID;\r
595\r
596 ReturnReg = EfiCallEsalService (&Guid, GetNextHighMonotonicCount, (UINT64) HighCount, 0, 0, 0, 0, 0, 0);\r
597 return (EFI_STATUS) ReturnReg.Status;\r
598}\r
599//\r
600// Sal Variable Driver Class\r
601//\r
602EFI_STATUS\r
603EfiGetVariable (\r
604 IN CHAR16 *VariableName,\r
605 IN EFI_GUID * VendorGuid,\r
606 OUT UINT32 *Attributes OPTIONAL,\r
607 IN OUT UINTN *DataSize,\r
608 OUT VOID *Data\r
609 )\r
610/*++\r
611\r
612Routine Description:\r
613\r
614 Returns the value of a variable.\r
615\r
616Arguments:\r
617\r
618 VariableName - A Null-terminated Unicode string that is the name of the\r
fd0d281b 619 vendor's variable.\r
3eb9473e 620 VendorGuid - A unique identifier for the vendor.\r
621 Attributes - If not NULL, a pointer to the memory location to return the\r
622 attributes bitmask for the variable.\r
623 DataSize - On input, the size in bytes of the return Data buffer.\r
624 On output the size of data returned in Data.\r
625 Data - The buffer to return the contents of the variable.\r
626\r
627Returns:\r
628\r
629 Status code\r
630\r
631--*/\r
632{\r
633 SAL_RETURN_REGS ReturnReg;\r
634 EFI_GUID Guid = EFI_EXTENDED_SAL_VARIABLE_SERVICES_PROTOCOL_GUID;\r
635\r
636 ReturnReg = EfiCallEsalService (\r
637 &Guid,\r
638 EsalGetVariable,\r
639 (UINT64) VariableName,\r
640 (UINT64) VendorGuid,\r
641 (UINT64) Attributes,\r
642 (UINT64) DataSize,\r
643 (UINT64) Data,\r
644 0,\r
645 0\r
646 );\r
647 return (EFI_STATUS) ReturnReg.Status;\r
648}\r
649\r
650EFI_STATUS\r
651EfiGetNextVariableName (\r
652 IN OUT UINTN *VariableNameSize,\r
653 IN OUT CHAR16 *VariableName,\r
654 IN OUT EFI_GUID *VendorGuid\r
655 )\r
656/*++\r
657\r
658Routine Description:\r
659\r
660 Enumerates the current variable names.\r
661\r
662Arguments:\r
663\r
664 VariableNameSize - The size of the VariableName buffer.\r
665 VariableName - On input, supplies the last VariableName that was returned\r
666 by GetNextVariableName(). \r
667 On output, returns the Nullterminated Unicode string of the\r
668 current variable.\r
669 VendorGuid - On input, supplies the last VendorGuid that was returned by\r
670 GetNextVariableName(). \r
671 On output, returns the VendorGuid of the current variable.\r
672\r
673Returns:\r
674\r
675 Status code\r
676\r
677--*/\r
678{\r
679 SAL_RETURN_REGS ReturnReg;\r
680 EFI_GUID Guid = EFI_EXTENDED_SAL_VARIABLE_SERVICES_PROTOCOL_GUID;\r
681\r
682 ReturnReg = EfiCallEsalService (\r
683 &Guid,\r
684 EsalGetNextVariableName,\r
685 (UINT64) VariableNameSize,\r
686 (UINT64) VariableName,\r
687 (UINT64) VendorGuid,\r
688 0,\r
689 0,\r
690 0,\r
691 0\r
692 );\r
693 return (EFI_STATUS) ReturnReg.Status;\r
694}\r
695\r
696EFI_STATUS\r
697EfiSetVariable (\r
698 IN CHAR16 *VariableName,\r
699 IN EFI_GUID *VendorGuid,\r
700 IN UINT32 Attributes,\r
701 IN UINTN DataSize,\r
702 IN VOID *Data\r
703 )\r
704/*++\r
705\r
706Routine Description:\r
707\r
708 Sets the value of a variable.\r
709\r
710Arguments:\r
711\r
712 VariableName - A Null-terminated Unicode string that is the name of the\r
fd0d281b 713 vendor's variable.\r
3eb9473e 714 VendorGuid - A unique identifier for the vendor.\r
715 Attributes - Attributes bitmask to set for the variable.\r
716 DataSize - The size in bytes of the Data buffer.\r
717 Data - The contents for the variable.\r
718\r
719Returns:\r
720\r
721 Status code\r
722\r
723--*/\r
724{\r
725 SAL_RETURN_REGS ReturnReg;\r
726 EFI_GUID Guid = EFI_EXTENDED_SAL_VARIABLE_SERVICES_PROTOCOL_GUID;\r
727\r
728 ReturnReg = EfiCallEsalService (\r
729 &Guid,\r
730 EsalSetVariable,\r
731 (UINT64) VariableName,\r
732 (UINT64) VendorGuid,\r
733 (UINT64) Attributes,\r
734 (UINT64) DataSize,\r
735 (UINT64) Data,\r
736 0,\r
737 0\r
738 );\r
739 return (EFI_STATUS) ReturnReg.Status;\r
740}\r
741\r
742#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
743\r
744EFI_STATUS\r
745EfiQueryVariableInfo (\r
746 IN UINT32 Attributes,\r
747 OUT UINT64 *MaximumVariableStorageSize,\r
748 OUT UINT64 *RemainingVariableStorageSize,\r
749 OUT UINT64 *MaximumVariableSize\r
750 )\r
751/*++\r
752\r
753Routine Description:\r
754\r
755 This code returns information about the EFI variables.\r
756\r
757Arguments:\r
758\r
759 Attributes Attributes bitmask to specify the type of variables \r
760 on which to return information.\r
761 MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
762 for the EFI variables associated with the attributes specified.\r
763 RemainingVariableStorageSize Pointer to the remaining size of the storage space available \r
764 for the EFI variables associated with the attributes specified.\r
765 MaximumVariableSize Pointer to the maximum size of the individual EFI variables\r
766 associated with the attributes specified.\r
767\r
768Returns:\r
769\r
770 Status code\r
771\r
772--*/\r
773{\r
774 SAL_RETURN_REGS ReturnReg;\r
775 EFI_GUID Guid = EFI_EXTENDED_SAL_VARIABLE_SERVICES_PROTOCOL_GUID;\r
776\r
777 ReturnReg = EfiCallEsalService (\r
778 &Guid,\r
779 EsalQueryVariableInfo,\r
780 (UINT64) Attributes,\r
781 (UINT64) MaximumVariableStorageSize,\r
782 (UINT64) RemainingVariableStorageSize,\r
783 (UINT64) MaximumVariableSize,\r
784 0, \r
785 0,\r
786 0\r
787 );\r
788 return (EFI_STATUS) ReturnReg.Status;\r
789}\r
790\r
791#endif\r
792\r
793//\r
794// Sal RTC Driver Class.\r
795//\r
796EFI_STATUS\r
797EfiGetTime (\r
798 OUT EFI_TIME *Time,\r
799 OUT EFI_TIME_CAPABILITIES *Capabilities\r
800 )\r
801/*++\r
802\r
803Routine Description:\r
804\r
805 Returns the current time and date information, and the time-keeping \r
806 capabilities of the hardware platform.\r
807\r
808Arguments:\r
809\r
810 Time - A pointer to storage to receive a snapshot of the current time.\r
fd0d281b 811 Capabilities - An optional pointer to a buffer to receive the real time clock device's\r
3eb9473e 812 capabilities.\r
813\r
814Returns:\r
815\r
816 Status code\r
817\r
818--*/\r
819{\r
820 SAL_RETURN_REGS ReturnReg;\r
821 EFI_GUID Guid = EFI_EXTENDED_SAL_RTC_SERVICES_PROTOCOL_GUID;\r
822\r
823 ReturnReg = EfiCallEsalService (&Guid, GetTime, (UINT64) Time, (UINT64) Capabilities, 0, 0, 0, 0, 0);\r
824 return ReturnReg.Status;\r
825}\r
826\r
827EFI_STATUS\r
828EfiSetTime (\r
829 OUT EFI_TIME *Time\r
830 )\r
831/*++\r
832\r
833Routine Description:\r
834\r
835 Sets the current local time and date information.\r
836\r
837Arguments:\r
838\r
839 Time - A pointer to the current time.\r
840\r
841Returns:\r
842\r
843 Status code\r
844\r
845--*/\r
846{\r
847 SAL_RETURN_REGS ReturnReg;\r
848\r
849 EFI_GUID Guid = EFI_EXTENDED_SAL_RTC_SERVICES_PROTOCOL_GUID;\r
850\r
851 ReturnReg = EfiCallEsalService (&Guid, SetTime, (UINT64) Time, 0, 0, 0, 0, 0, 0);\r
852 return ReturnReg.Status;\r
853}\r
854\r
855EFI_STATUS\r
856EfiGetWakeupTime (\r
857 OUT BOOLEAN *Enabled,\r
858 OUT BOOLEAN *Pending,\r
859 OUT EFI_TIME *Time\r
860 )\r
861/*++\r
862\r
863Routine Description:\r
864\r
865 Returns the current wakeup alarm clock setting.\r
866\r
867Arguments:\r
868\r
869 Enabled - Indicates if the alarm is currently enabled or disabled.\r
870 Pending - Indicates if the alarm signal is pending and requires acknowledgement.\r
871 Time - The current alarm setting.\r
872\r
873Returns:\r
874\r
875 Status code\r
876\r
877--*/\r
878{\r
879 SAL_RETURN_REGS ReturnReg;\r
880\r
881 EFI_GUID Guid = EFI_EXTENDED_SAL_RTC_SERVICES_PROTOCOL_GUID;\r
882\r
883 ReturnReg = EfiCallEsalService (&Guid, GetWakeupTime, (UINT64) Enabled, (UINT64) Pending, (UINT64) Time, 0, 0, 0, 0);\r
884 return ReturnReg.Status;\r
885}\r
886\r
887EFI_STATUS\r
888EfiSetWakeupTime (\r
889 IN BOOLEAN Enable,\r
890 IN EFI_TIME *Time\r
891 )\r
892/*++\r
893\r
894Routine Description:\r
895\r
896 Sets the system wakeup alarm clock time.\r
897\r
898Arguments:\r
899\r
900 Enable - Enable or disable the wakeup alarm.\r
901 Time - If Enable is TRUE, the time to set the wakeup alarm for.\r
902 If Enable is FALSE, then this parameter is optional, and may be NULL.\r
903\r
904Returns:\r
905\r
906 Status code\r
907\r
908--*/\r
909{\r
910 SAL_RETURN_REGS ReturnReg;\r
911\r
912 EFI_GUID Guid = EFI_EXTENDED_SAL_RTC_SERVICES_PROTOCOL_GUID;\r
913\r
914 ReturnReg = EfiCallEsalService (&Guid, SetWakeupTime, (UINT64) Enable, (UINT64) Time, 0, 0, 0, 0, 0);\r
915 return ReturnReg.Status;\r
916}\r
917\r
918\r
919\r
920//\r
921// Base IO Services\r
922//\r
923EFI_STATUS\r
924EfiIoRead (\r
925 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
926 IN UINT64 Address,\r
927 IN UINTN Count,\r
928 IN OUT VOID *Buffer\r
929 )\r
930/*++\r
931\r
932Routine Description:\r
933 Perform an IO read into Buffer.\r
934\r
935Arguments:\r
936 Width - Width of read transaction, and repeat operation to use\r
937 Address - IO address to read\r
938 Count - Number of times to read the IO address.\r
939 Buffer - Buffer to read data into. size is Width * Count\r
940\r
941Returns:\r
942 Status code\r
943\r
944--*/\r
945{\r
946\r
947 SAL_RETURN_REGS ReturnReg;\r
948\r
949 EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;\r
950\r
951 ReturnReg = EfiCallEsalService (&Guid, IoRead, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);\r
4ac4deb7 952 ASSERT (ReturnReg.Status == EFI_SAL_SUCCESS);\r
3eb9473e 953\r
954 return ReturnReg.Status;\r
955\r
956}\r
957\r
958EFI_STATUS\r
959EfiIoWrite (\r
960 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
961 IN UINT64 Address,\r
962 IN UINTN Count,\r
963 IN OUT VOID *Buffer\r
964 )\r
965/*++\r
966\r
967Routine Description:\r
968 Perform an IO write into Buffer.\r
969\r
970Arguments:\r
971 Width - Width of write transaction, and repeat operation to use\r
972 Address - IO address to write\r
973 Count - Number of times to write the IO address.\r
974 Buffer - Buffer to write data from. size is Width * Count\r
975\r
976Returns:\r
977 Status code\r
978\r
979--*/\r
980{\r
981\r
982 SAL_RETURN_REGS ReturnReg;\r
983\r
984 EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;\r
985\r
986 ReturnReg = EfiCallEsalService (&Guid, IoWrite, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);\r
987\r
988 return ReturnReg.Status;\r
989\r
990}\r
991\r
992EFI_STATUS\r
993EfiMemRead (\r
994 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
995 IN UINT64 Address,\r
996 IN UINTN Count,\r
997 IN OUT VOID *Buffer\r
998 )\r
999/*++\r
1000\r
1001Routine Description:\r
1002 Perform a Memory mapped IO read into Buffer.\r
1003\r
1004Arguments:\r
1005 Width - Width of each read transaction.\r
1006 Address - Memory mapped IO address to read\r
1007 Count - Number of Width quanta to read\r
1008 Buffer - Buffer to read data into. size is Width * Count\r
1009\r
1010Returns:\r
1011 Status code\r
1012\r
1013--*/\r
1014{\r
1015\r
1016 SAL_RETURN_REGS ReturnReg;\r
1017\r
1018 EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;\r
1019\r
1020 ReturnReg = EfiCallEsalService (&Guid, MemRead, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);\r
4ac4deb7 1021 ASSERT (ReturnReg.Status == EFI_SAL_SUCCESS);\r
3eb9473e 1022\r
1023 return ReturnReg.Status;\r
1024\r
1025}\r
1026\r
1027EFI_STATUS\r
1028EfiMemWrite (\r
1029 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
1030 IN UINT64 Address,\r
1031 IN UINTN Count,\r
1032 IN OUT VOID *Buffer\r
1033 )\r
1034/*++\r
1035\r
1036Routine Description:\r
1037 Perform a memory mapped IO write into Buffer.\r
1038\r
1039Arguments:\r
1040 Width - Width of write transaction, and repeat operation to use\r
1041 Address - IO address to write\r
1042 Count - Number of times to write the IO address.\r
1043 Buffer - Buffer to write data from. size is Width * Count\r
1044\r
1045Returns:\r
1046 Status code\r
1047\r
1048--*/\r
1049{\r
1050\r
1051 SAL_RETURN_REGS ReturnReg;\r
1052\r
1053 EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;\r
1054\r
1055 ReturnReg = EfiCallEsalService (&Guid, MemWrite, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);\r
1056\r
1057 return ReturnReg.Status;\r
1058\r
1059}\r
1060\r
1061\r
1062#define EFI_PCI_ADDRESS_IPF(_seg, _bus, _devfunc, _reg) \\r
1063 (((_seg) << 24) | ((_bus) << 16) | ((_devfunc) << 8) | (_reg)) & 0xFFFFFFFF\r
1064\r
1065//\r
1066// PCI Class Functions\r
1067//\r
1068UINT8\r
1069PciRead8 (\r
1070 UINT8 Segment,\r
1071 UINT8 Bus,\r
1072 UINT8 DevFunc,\r
1073 UINT8 Register\r
1074 )\r
1075/*++\r
1076\r
1077Routine Description:\r
1078 Perform an one byte PCI config cycle read\r
1079\r
1080Arguments:\r
1081 Segment - PCI Segment ACPI _SEG\r
1082 Bus - PCI Bus\r
1083 DevFunc - PCI Device(7:3) and Func(2:0)\r
1084 Register - PCI config space register\r
1085\r
1086Returns:\r
1087 Data read from PCI config space\r
1088\r
1089--*/\r
1090{\r
1091 EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
1092 UINT64 Address;\r
1093 SAL_RETURN_REGS Return;\r
1094\r
1095 Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
1096 Return = EfiCallEsalService (&Guid, SalPciConfigRead, Address, 1, 0, 0, 0, 0, 0);\r
1097\r
1098 return (UINT8) Return.r9;\r
1099}\r
1100\r
1101\r
1102UINT16\r
1103PciRead16 (\r
1104 UINT8 Segment,\r
1105 UINT8 Bus,\r
1106 UINT8 DevFunc,\r
1107 UINT8 Register\r
1108 )\r
1109/*++\r
1110\r
1111Routine Description:\r
1112 Perform an two byte PCI config cycle read\r
1113\r
1114Arguments:\r
1115 Segment - PCI Segment ACPI _SEG\r
1116 Bus - PCI Bus\r
1117 DevFunc - PCI Device(7:3) and Func(2:0)\r
1118 Register - PCI config space register\r
1119\r
1120Returns:\r
1121 Data read from PCI config space\r
1122\r
1123--*/\r
1124{\r
1125 EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
1126 UINT64 Address;\r
1127 SAL_RETURN_REGS Return;\r
1128\r
1129 Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
1130 Return = EfiCallEsalService (&Guid, SalPciConfigRead, Address, 2, 0, 0, 0, 0, 0);\r
1131\r
1132 return (UINT16) Return.r9;\r
1133}\r
1134\r
1135UINT32\r
1136PciRead32 (\r
1137 UINT8 Segment,\r
1138 UINT8 Bus,\r
1139 UINT8 DevFunc,\r
1140 UINT8 Register\r
1141 )\r
1142/*++\r
1143\r
1144Routine Description:\r
1145 Perform an four byte PCI config cycle read\r
1146\r
1147Arguments:\r
1148 Segment - PCI Segment ACPI _SEG\r
1149 Bus - PCI Bus\r
1150 DevFunc - PCI Device(7:3) and Func(2:0)\r
1151 Register - PCI config space register\r
1152\r
1153Returns:\r
1154 Data read from PCI config space\r
1155\r
1156--*/\r
1157{\r
1158 EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
1159 UINT64 Address;\r
1160 SAL_RETURN_REGS Return;\r
1161\r
1162 Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
1163 Return = EfiCallEsalService (&Guid, SalPciConfigRead, Address, 4, 0, 0, 0, 0, 0);\r
1164\r
1165 return (UINT32) Return.r9;\r
1166}\r
1167\r
1168VOID\r
1169PciWrite8 (\r
1170 UINT8 Segment,\r
1171 UINT8 Bus,\r
1172 UINT8 DevFunc,\r
1173 UINT8 Register,\r
1174 UINT8 Data\r
1175 )\r
1176/*++\r
1177\r
1178Routine Description:\r
1179 Perform an one byte PCI config cycle write\r
1180\r
1181Arguments:\r
1182 Segment - PCI Segment ACPI _SEG\r
1183 Bus - PCI Bus\r
1184 DevFunc - PCI Device(7:3) and Func(2:0)\r
1185 Register - PCI config space register\r
1186 Data - Data to write\r
1187\r
1188Returns:\r
1189 NONE\r
1190\r
1191--*/\r
1192{\r
1193 EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
1194 UINT64 Address;\r
1195\r
1196 Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
1197 EfiCallEsalService (&Guid, SalPciConfigWrite, Address, 1, Data, 0, 0, 0, 0);\r
1198}\r
1199\r
1200VOID\r
1201PciWrite16 (\r
1202 UINT8 Segment,\r
1203 UINT8 Bus,\r
1204 UINT8 DevFunc,\r
1205 UINT8 Register,\r
1206 UINT16 Data\r
1207 )\r
1208/*++\r
1209\r
1210Routine Description:\r
1211 Perform an two byte PCI config cycle write\r
1212\r
1213Arguments:\r
1214 Segment - PCI Segment ACPI _SEG\r
1215 Bus - PCI Bus\r
1216 DevFunc - PCI Device(7:3) and Func(2:0)\r
1217 Register - PCI config space register\r
1218 Data - Data to write\r
1219\r
1220Returns:\r
1221 None.\r
1222\r
1223--*/\r
1224{\r
1225 EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
1226 UINT64 Address;\r
1227\r
1228 Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
1229 EfiCallEsalService (&Guid, SalPciConfigWrite, Address, 2, Data, 0, 0, 0, 0);\r
1230}\r
1231\r
1232VOID\r
1233PciWrite32 (\r
1234 UINT8 Segment,\r
1235 UINT8 Bus,\r
1236 UINT8 DevFunc,\r
1237 UINT8 Register,\r
1238 UINT32 Data\r
1239 )\r
1240/*++\r
1241\r
1242Routine Description:\r
1243 Perform an four byte PCI config cycle write\r
1244\r
1245Arguments:\r
1246 Segment - PCI Segment ACPI _SEG\r
1247 Bus - PCI Bus\r
1248 DevFunc - PCI Device(7:3) and Func(2:0)\r
1249 Register - PCI config space register\r
1250 Data - Data to write\r
1251\r
1252Returns:\r
1253 NONE\r
1254\r
1255--*/\r
1256{\r
1257 EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
1258 UINT64 Address;\r
1259\r
1260 Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
1261 EfiCallEsalService (&Guid, SalPciConfigWrite, Address, 4, Data, 0, 0, 0, 0);\r
1262}\r
1263\r
1264//\r
1265// Stall class functions\r
1266//\r
1267VOID\r
1268EfiStall (\r
1269 IN UINTN Microseconds\r
1270 )\r
1271/*++\r
1272\r
1273Routine Description:\r
1274 Delay for at least the request number of microseconds\r
1275\r
1276Arguments:\r
1277 Microseconds - Number of microseconds to delay.\r
1278\r
1279Returns:\r
1280 NONE\r
1281\r
1282--*/\r
1283{\r
1284 EFI_GUID Guid = EFI_EXTENDED_SAL_STALL_SERVICES_PROTOCOL_GUID;\r
1285\r
1286 if (EfiAtRuntime ()) {\r
1287 EfiCallEsalService (&Guid, Stall, Microseconds, 4, 0, 0, 0, 0, 0);\r
1288 } else {\r
1289 gBS->Stall (Microseconds);\r
1290 }\r
1291}\r
1292//\r
1293// Cache Flush Routine.\r
1294//\r
1295EFI_STATUS\r
1296EfiCpuFlushCache (\r
1297 IN EFI_PHYSICAL_ADDRESS Start,\r
1298 IN UINT64 Length\r
1299 )\r
1300/*++\r
1301\r
1302Routine Description:\r
1303\r
1304 Flush cache with specified range.\r
1305\r
1306Arguments:\r
1307\r
1308 Start - Start address\r
1309 Length - Length in bytes\r
1310\r
1311Returns:\r
1312\r
1313 Status code\r
1314 \r
1315 EFI_SUCCESS - success\r
1316\r
1317--*/\r
1318{\r
1319 SalFlushCache (Start, Length);\r
1320 return EFI_SUCCESS;\r
1321}\r