+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-\r
-Module Name:\r
-\r
- RuntimeLib.c\r
-\r
-Abstract:\r
-\r
- Light weight lib to support Tiano Sal drivers.\r
-\r
---*/\r
-\r
-#include "Tiano.h"\r
-#include "EfiRuntimeLib.h"\r
-#include EFI_PROTOCOL_DEFINITION (ExtendedSalBootService)\r
-#include EFI_PROTOCOL_DEFINITION (ExtendedSalGuid)\r
-#include "IpfDefines.h"\r
-#include "SalApi.h"\r
-\r
-//\r
-// Worker functions in EsalLib.s\r
-//\r
-SAL_RETURN_REGS\r
-GetEsalEntryPoint (\r
- VOID\r
- );\r
-\r
-SAL_RETURN_REGS\r
-SetEsalPhysicalEntryPoint (\r
- IN UINT64 EntryPoint,\r
- IN UINT64 Gp\r
- );\r
-\r
-SAL_RETURN_REGS\r
-SetEsalVirtualEntryPoint (\r
- IN UINT64 EntryPoint,\r
- IN UINT64 Gp\r
- );\r
-\r
-VOID\r
-SalFlushCache (\r
- IN EFI_PHYSICAL_ADDRESS Start,\r
- IN UINT64 Length\r
- );\r
-\r
-//\r
-// Module Globals. It's not valid to use these after the\r
-// EfiRuntimeLibVirtualNotifyEvent has fired.\r
-//\r
-static EFI_EVENT mEfiVirtualNotifyEvent;\r
-static EFI_RUNTIME_SERVICES *mRT;\r
-static EFI_PLABEL mPlabel;\r
-static EXTENDED_SAL_BOOT_SERVICE_PROTOCOL *mEsalBootService;\r
-static BOOLEAN mRuntimeLibInitialized = FALSE;\r
-\r
-VOID\r
-EFIAPI\r
-EfiRuntimeLibVirtualNotifyEvent (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Fixup internal data so that EFI and SAL can be call in virtual mode.\r
- Call the passed in Child Notify event and convert any pointers in \r
- lib to virtual mode.\r
-\r
-Arguments:\r
-\r
- Event - The Event that is being processed\r
- \r
- Context - Event Context\r
-\r
-Returns: \r
-\r
- None\r
-\r
---*/\r
-{\r
- EFI_EVENT_NOTIFY ChildNotify;\r
-\r
- if (Context != NULL) {\r
- //\r
- // Call child event\r
- //\r
- ChildNotify = (EFI_EVENT_NOTIFY) (UINTN) Context;\r
- ChildNotify (Event, NULL);\r
- }\r
-\r
- mRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID **) &mPlabel.EntryPoint);\r
- mRT->ConvertPointer (EFI_INTERNAL_POINTER | EFI_IPF_GP_POINTER, (VOID **) &mPlabel.GP);\r
-\r
- SetEsalVirtualEntryPoint (mPlabel.EntryPoint, mPlabel.GP);\r
-\r
- //\r
- // Clear out BootService globals\r
- //\r
- gBS = NULL;\r
- gST = NULL;\r
- mRT = NULL;\r
-\r
- //\r
- // Pointers don't work you must use a direct lib call\r
- //\r
-}\r
-\r
-EFI_STATUS\r
-EfiInitializeRuntimeDriverLib (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable,\r
- IN EFI_EVENT_NOTIFY GoVirtualChildEvent\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Intialize runtime Driver Lib if it has not yet been initialized. \r
-\r
-Arguments:\r
-\r
- ImageHandle - The firmware allocated handle for the EFI image.\r
- \r
- SystemTable - A pointer to the EFI System Table.\r
-\r
- GoVirtualChildEvent - Caller can register a virtual notification event.\r
-\r
-Returns: \r
-\r
- EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- EFI_PLABEL *Plabel;\r
-\r
- if (mRuntimeLibInitialized) {\r
- return EFI_ALREADY_STARTED;\r
- }\r
-\r
- mRuntimeLibInitialized = TRUE;\r
-\r
- gST = SystemTable;\r
- gBS = SystemTable->BootServices;\r
- mRT = SystemTable->RuntimeServices;\r
- Status = EfiLibGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- //\r
- // The protocol contains a function pointer, which is an indirect procedure call.\r
- // An indirect procedure call goes through a plabel, and pointer to a function is\r
- // a pointer to a plabel. To implement indirect procedure calls that can work in\r
- // both physical and virtual mode, two plabels are required (one physical and one\r
- // virtual). So lets grap the physical PLABEL for the EsalEntryPoint and store it\r
- // away. We cache it in a module global, so we can register the vitrual version.\r
- //\r
- Status = gBS->LocateProtocol (&gEfiExtendedSalBootServiceProtocolGuid, NULL, (VOID **) &mEsalBootService);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- Plabel = (EFI_PLABEL *) (UINTN) mEsalBootService->ExtendedSalProc;\r
-\r
- mPlabel.EntryPoint = Plabel->EntryPoint;\r
- mPlabel.GP = Plabel->GP;\r
-\r
- SetEsalPhysicalEntryPoint (mPlabel.EntryPoint, mPlabel.GP);\r
-\r
- //\r
- // Create a Virtual address change notification event. Pass in the callers\r
- // GoVirtualChildEvent so it's get passed to the event as contex.\r
- //\r
- Status = gBS->CreateEvent (\r
- EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
- EFI_TPL_NOTIFY,\r
- EfiRuntimeLibVirtualNotifyEvent,\r
- (VOID *) GoVirtualChildEvent,\r
- &mEfiVirtualNotifyEvent\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EfiShutdownRuntimeDriverLib (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This routine will free some resources which have been allocated in\r
- EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, \r
- it must call this routine to free the allocated resource before the exiting.\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns: \r
-\r
- EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully\r
- EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
-\r
- if (!mRuntimeLibInitialized) {\r
- //\r
- // You must call EfiInitializeRuntimeDriverLib() first\r
- //\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- mRuntimeLibInitialized = FALSE;\r
-\r
- //\r
- // Close SetVirtualAddressMap () notify function\r
- //\r
- Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- return EFI_SUCCESS;\r
-}\r
- \r
-EFI_STATUS\r
-RegisterEsalFunction (\r
- IN UINT64 FunctionId,\r
- IN EFI_GUID *ClassGuid,\r
- IN SAL_INTERNAL_EXTENDED_SAL_PROC Function,\r
- IN VOID *ModuleGlobal\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Register ESAL Class Function and it's asociated global.\r
- This function is boot service only!\r
-\r
-Arguments:\r
- FunctionId - ID of function to register\r
- ClassGuid - GUID of function class \r
- Function - Function to register under ClassGuid/FunctionId pair\r
- ModuleGlobal - Module global for Function.\r
-\r
-Returns: \r
- EFI_SUCCESS - If ClassGuid/FunctionId Function was registered.\r
-\r
---*/\r
-{\r
- return mEsalBootService->AddExtendedSalProc (\r
- mEsalBootService,\r
- ClassGuid,\r
- FunctionId,\r
- Function,\r
- ModuleGlobal\r
- );\r
-}\r
-\r
-EFI_STATUS\r
-RegisterEsalClass (\r
- IN EFI_GUID *ClassGuid,\r
- IN VOID *ModuleGlobal,\r
- ...\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Register ESAL Class and it's asociated global.\r
- This function is boot service only!\r
-\r
-Arguments:\r
- ClassGuid - GUID of function class \r
- ModuleGlobal - Module global for Function.\r
- ... - SAL_INTERNAL_EXTENDED_SAL_PROC and FunctionId pairs. NULL \r
- indicates the end of the list.\r
-\r
-Returns: \r
- EFI_SUCCESS - All members of ClassGuid registered\r
-\r
---*/\r
-{\r
- VA_LIST Args;\r
- EFI_STATUS Status;\r
- SAL_INTERNAL_EXTENDED_SAL_PROC Function;\r
- UINT64 FunctionId;\r
- EFI_HANDLE NewHandle;\r
-\r
- VA_START (Args, ModuleGlobal);\r
-\r
- Status = EFI_SUCCESS;\r
- while (!EFI_ERROR (Status)) {\r
- Function = (SAL_INTERNAL_EXTENDED_SAL_PROC) VA_ARG (Args, SAL_INTERNAL_EXTENDED_SAL_PROC);\r
- if (Function == NULL) {\r
- break;\r
- }\r
-\r
- FunctionId = VA_ARG (Args, UINT64);\r
-\r
- Status = RegisterEsalFunction (FunctionId, ClassGuid, Function, ModuleGlobal);\r
- }\r
-\r
- VA_END (Args);\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- NewHandle = NULL;\r
- return gBS->InstallProtocolInterface (\r
- &NewHandle,\r
- ClassGuid,\r
- EFI_NATIVE_INTERFACE,\r
- NULL\r
- );\r
-}\r
-\r
-SAL_RETURN_REGS\r
-EfiCallEsalService (\r
- IN EFI_GUID *ClassGuid,\r
- IN UINT64 FunctionId,\r
- IN UINT64 Arg2,\r
- IN UINT64 Arg3,\r
- IN UINT64 Arg4,\r
- IN UINT64 Arg5,\r
- IN UINT64 Arg6,\r
- IN UINT64 Arg7,\r
- IN UINT64 Arg8\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Call module that is not linked direclty to this module. This code is IP \r
- relative and hides the binding issues of virtual or physical calling. The\r
- function that gets dispatched has extra arguments that include the registered\r
- module global and a boolean flag to indicate if the system is in virutal mode.\r
-\r
-Arguments:\r
- ClassGuid - GUID of function\r
- FunctionId - Function in ClassGuid to call\r
- Arg2 - Argument 2 ClassGuid/FunctionId defined\r
- Arg3 - Argument 3 ClassGuid/FunctionId defined\r
- Arg4 - Argument 4 ClassGuid/FunctionId defined\r
- Arg5 - Argument 5 ClassGuid/FunctionId defined\r
- Arg6 - Argument 6 ClassGuid/FunctionId defined\r
- Arg7 - Argument 7 ClassGuid/FunctionId defined\r
- Arg8 - Argument 8 ClassGuid/FunctionId defined\r
-\r
-Returns: \r
- Status of ClassGuid/FuncitonId\r
-\r
---*/\r
-{\r
- SAL_RETURN_REGS ReturnReg;\r
- SAL_EXTENDED_SAL_PROC EsalProc;\r
-\r
- ReturnReg = GetEsalEntryPoint ();\r
- if (ReturnReg.Status != EFI_SAL_SUCCESS) {\r
- return ReturnReg;\r
- }\r
-\r
- if (ReturnReg.r11 & PSR_IT_MASK) {\r
- //\r
- // Virtual mode plabel to entry point\r
- //\r
- EsalProc = (SAL_EXTENDED_SAL_PROC) ReturnReg.r10;\r
- } else {\r
- //\r
- // Physical mode plabel to entry point\r
- //\r
- EsalProc = (SAL_EXTENDED_SAL_PROC) ReturnReg.r9;\r
- }\r
-\r
- return EsalProc (\r
- ClassGuid,\r
- FunctionId,\r
- Arg2,\r
- Arg3,\r
- Arg4,\r
- Arg5,\r
- Arg6,\r
- Arg7,\r
- Arg8\r
- );\r
-}\r
-\r
-EFI_STATUS\r
-EfiConvertPointer (\r
- IN UINTN DebugDisposition,\r
- IN OUT VOID *Address\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Determines the new virtual address that is to be used on subsequent memory accesses.\r
-\r
-Arguments:\r
-\r
- DebugDisposition - Supplies type information for the pointer being converted.\r
- Address - A pointer to a pointer that is to be fixed to be the value needed\r
- for the new virtual address mappings being applied.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return mRT->ConvertPointer (DebugDisposition, Address);\r
-}\r
-\r
-BOOLEAN\r
-EfiGoneVirtual (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Return TRUE if SetVirtualAddressMap () has been called\r
-\r
-Arguments:\r
- NONE\r
-\r
-Returns: \r
- TRUE - If SetVirtualAddressMap () has been called\r
-\r
---*/\r
-{\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;\r
- SAL_RETURN_REGS ReturnReg;\r
-\r
- ReturnReg = EfiCallEsalService (&Guid, IsVirtual, 0, 0, 0, 0, 0, 0, 0);\r
-\r
- return (BOOLEAN) (ReturnReg.r9 == 1);\r
-}\r
-\r
-BOOLEAN\r
-EfiAtRuntime (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Return TRUE if ExitBootService () has been called\r
-\r
-Arguments:\r
- NONE\r
-\r
-Returns: \r
- TRUE - If ExitBootService () has been called\r
-\r
---*/\r
-{\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_VIRTUAL_SERVICES_PROTOCOL_GUID;\r
- SAL_RETURN_REGS ReturnReg;\r
-\r
- ReturnReg = EfiCallEsalService (&Guid, IsEfiRuntime, 0, 0, 0, 0, 0, 0, 0);\r
-\r
- return (BOOLEAN) (ReturnReg.r9 == 1);\r
-}\r
-\r
-EFI_STATUS\r
-EfiReportStatusCode (\r
- IN EFI_STATUS_CODE_TYPE CodeType,\r
- IN EFI_STATUS_CODE_VALUE Value,\r
- IN UINT32 Instance,\r
- IN EFI_GUID * CallerId,\r
- IN EFI_STATUS_CODE_DATA * Data OPTIONAL\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Status Code reporter\r
-\r
-Arguments:\r
-\r
- CodeType - Type of Status Code.\r
- \r
- Value - Value to output for Status Code.\r
- \r
- Instance - Instance Number of this status code.\r
- \r
- CallerId - ID of the caller of this status code.\r
- \r
- Data - Optional data associated with this status code.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_STATUS_CODE_SERVICES_PROTOCOL_GUID;\r
- SAL_RETURN_REGS ReturnReg;\r
-\r
-\r
- ReturnReg = EfiCallEsalService (\r
- &Guid,\r
- StatusCode,\r
- (UINT64) CodeType,\r
- (UINT64) Value,\r
- (UINT64) Instance,\r
- (UINT64) CallerId,\r
- (UINT64) Data,\r
- 0,\r
- 0\r
- );\r
-\r
- return (EFI_STATUS) ReturnReg.Status;\r
-}\r
-//\r
-// Sal Reset Driver Class\r
-//\r
-VOID\r
-EfiResetSystem (\r
- IN EFI_RESET_TYPE ResetType,\r
- IN EFI_STATUS ResetStatus,\r
- IN UINTN DataSize,\r
- IN CHAR16 *ResetData\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Resets the entire platform.\r
-\r
-Arguments:\r
-\r
- ResetType - The type of reset to perform.\r
- ResetStatus - The status code for the reset.\r
- DataSize - The size, in bytes, of ResetData.\r
- ResetData - A data buffer that includes a Null-terminated Unicode string, optionally\r
- followed by additional binary data.\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-{\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_RESET_SERVICES_PROTOCOL_GUID;\r
-\r
- EfiCallEsalService (\r
- &Guid,\r
- ResetSystem,\r
- (UINT64) ResetType,\r
- (UINT64) ResetStatus,\r
- (UINT64) DataSize,\r
- (UINT64) ResetData,\r
- 0,\r
- 0,\r
- 0\r
- );\r
-}\r
-//\r
-// Sal MTC Driver Class\r
-//\r
-EFI_STATUS\r
-EfiGetNextHighMonotonicCount (\r
- OUT UINT32 *HighCount\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Returns the next high 32 bits of the platform's monotonic counter.\r
-\r
-Arguments:\r
-\r
- HighCount - Pointer to returned value.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- SAL_RETURN_REGS ReturnReg;\r
-\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_MTC_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (&Guid, GetNextHighMonotonicCount, (UINT64) HighCount, 0, 0, 0, 0, 0, 0);\r
- return (EFI_STATUS) ReturnReg.Status;\r
-}\r
-//\r
-// Sal Variable Driver Class\r
-//\r
-EFI_STATUS\r
-EfiGetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID * VendorGuid,\r
- OUT UINT32 *Attributes OPTIONAL,\r
- IN OUT UINTN *DataSize,\r
- OUT VOID *Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Returns the value of a variable.\r
-\r
-Arguments:\r
-\r
- VariableName - A Null-terminated Unicode string that is the name of the\r
- vendor's variable.\r
- VendorGuid - A unique identifier for the vendor.\r
- Attributes - If not NULL, a pointer to the memory location to return the\r
- attributes bitmask for the variable.\r
- DataSize - On input, the size in bytes of the return Data buffer.\r
- On output the size of data returned in Data.\r
- Data - The buffer to return the contents of the variable.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- SAL_RETURN_REGS ReturnReg;\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_VARIABLE_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (\r
- &Guid,\r
- EsalGetVariable,\r
- (UINT64) VariableName,\r
- (UINT64) VendorGuid,\r
- (UINT64) Attributes,\r
- (UINT64) DataSize,\r
- (UINT64) Data,\r
- 0,\r
- 0\r
- );\r
- return (EFI_STATUS) ReturnReg.Status;\r
-}\r
-\r
-EFI_STATUS\r
-EfiGetNextVariableName (\r
- IN OUT UINTN *VariableNameSize,\r
- IN OUT CHAR16 *VariableName,\r
- IN OUT EFI_GUID *VendorGuid\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Enumerates the current variable names.\r
-\r
-Arguments:\r
-\r
- VariableNameSize - The size of the VariableName buffer.\r
- VariableName - On input, supplies the last VariableName that was returned\r
- by GetNextVariableName(). \r
- On output, returns the Nullterminated Unicode string of the\r
- current variable.\r
- VendorGuid - On input, supplies the last VendorGuid that was returned by\r
- GetNextVariableName(). \r
- On output, returns the VendorGuid of the current variable.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- SAL_RETURN_REGS ReturnReg;\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_VARIABLE_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (\r
- &Guid,\r
- EsalGetNextVariableName,\r
- (UINT64) VariableNameSize,\r
- (UINT64) VariableName,\r
- (UINT64) VendorGuid,\r
- 0,\r
- 0,\r
- 0,\r
- 0\r
- );\r
- return (EFI_STATUS) ReturnReg.Status;\r
-}\r
-\r
-EFI_STATUS\r
-EfiSetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- IN UINT32 Attributes,\r
- IN UINTN DataSize,\r
- IN VOID *Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Sets the value of a variable.\r
-\r
-Arguments:\r
-\r
- VariableName - A Null-terminated Unicode string that is the name of the\r
- vendor's variable.\r
- VendorGuid - A unique identifier for the vendor.\r
- Attributes - Attributes bitmask to set for the variable.\r
- DataSize - The size in bytes of the Data buffer.\r
- Data - The contents for the variable.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- SAL_RETURN_REGS ReturnReg;\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_VARIABLE_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (\r
- &Guid,\r
- EsalSetVariable,\r
- (UINT64) VariableName,\r
- (UINT64) VendorGuid,\r
- (UINT64) Attributes,\r
- (UINT64) DataSize,\r
- (UINT64) Data,\r
- 0,\r
- 0\r
- );\r
- return (EFI_STATUS) ReturnReg.Status;\r
-}\r
-\r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
-\r
-EFI_STATUS\r
-EfiQueryVariableInfo (\r
- IN UINT32 Attributes,\r
- OUT UINT64 *MaximumVariableStorageSize,\r
- OUT UINT64 *RemainingVariableStorageSize,\r
- OUT UINT64 *MaximumVariableSize\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code returns information about the EFI variables.\r
-\r
-Arguments:\r
-\r
- Attributes Attributes bitmask to specify the type of variables \r
- on which to return information.\r
- MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
- for the EFI variables associated with the attributes specified.\r
- RemainingVariableStorageSize Pointer to the remaining size of the storage space available \r
- for the EFI variables associated with the attributes specified.\r
- MaximumVariableSize Pointer to the maximum size of the individual EFI variables\r
- associated with the attributes specified.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- SAL_RETURN_REGS ReturnReg;\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_VARIABLE_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (\r
- &Guid,\r
- EsalQueryVariableInfo,\r
- (UINT64) Attributes,\r
- (UINT64) MaximumVariableStorageSize,\r
- (UINT64) RemainingVariableStorageSize,\r
- (UINT64) MaximumVariableSize,\r
- 0, \r
- 0,\r
- 0\r
- );\r
- return (EFI_STATUS) ReturnReg.Status;\r
-}\r
-\r
-#endif\r
-\r
-//\r
-// Sal RTC Driver Class.\r
-//\r
-EFI_STATUS\r
-EfiGetTime (\r
- OUT EFI_TIME *Time,\r
- OUT EFI_TIME_CAPABILITIES *Capabilities\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Returns the current time and date information, and the time-keeping \r
- capabilities of the hardware platform.\r
-\r
-Arguments:\r
-\r
- Time - A pointer to storage to receive a snapshot of the current time.\r
- Capabilities - An optional pointer to a buffer to receive the real time clock device's\r
- capabilities.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- SAL_RETURN_REGS ReturnReg;\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_RTC_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (&Guid, GetTime, (UINT64) Time, (UINT64) Capabilities, 0, 0, 0, 0, 0);\r
- return ReturnReg.Status;\r
-}\r
-\r
-EFI_STATUS\r
-EfiSetTime (\r
- OUT EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Sets the current local time and date information.\r
-\r
-Arguments:\r
-\r
- Time - A pointer to the current time.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- SAL_RETURN_REGS ReturnReg;\r
-\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_RTC_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (&Guid, SetTime, (UINT64) Time, 0, 0, 0, 0, 0, 0);\r
- return ReturnReg.Status;\r
-}\r
-\r
-EFI_STATUS\r
-EfiGetWakeupTime (\r
- OUT BOOLEAN *Enabled,\r
- OUT BOOLEAN *Pending,\r
- OUT EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Returns the current wakeup alarm clock setting.\r
-\r
-Arguments:\r
-\r
- Enabled - Indicates if the alarm is currently enabled or disabled.\r
- Pending - Indicates if the alarm signal is pending and requires acknowledgement.\r
- Time - The current alarm setting.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- SAL_RETURN_REGS ReturnReg;\r
-\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_RTC_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (&Guid, GetWakeupTime, (UINT64) Enabled, (UINT64) Pending, (UINT64) Time, 0, 0, 0, 0);\r
- return ReturnReg.Status;\r
-}\r
-\r
-EFI_STATUS\r
-EfiSetWakeupTime (\r
- IN BOOLEAN Enable,\r
- IN EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Sets the system wakeup alarm clock time.\r
-\r
-Arguments:\r
-\r
- Enable - Enable or disable the wakeup alarm.\r
- Time - If Enable is TRUE, the time to set the wakeup alarm for.\r
- If Enable is FALSE, then this parameter is optional, and may be NULL.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- SAL_RETURN_REGS ReturnReg;\r
-\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_RTC_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (&Guid, SetWakeupTime, (UINT64) Enable, (UINT64) Time, 0, 0, 0, 0, 0);\r
- return ReturnReg.Status;\r
-}\r
-\r
-\r
-\r
-//\r
-// Base IO Services\r
-//\r
-EFI_STATUS\r
-EfiIoRead (\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an IO read into Buffer.\r
-\r
-Arguments:\r
- Width - Width of read transaction, and repeat operation to use\r
- Address - IO address to read\r
- Count - Number of times to read the IO address.\r
- Buffer - Buffer to read data into. size is Width * Count\r
-\r
-Returns:\r
- Status code\r
-\r
---*/\r
-{\r
-\r
- SAL_RETURN_REGS ReturnReg;\r
-\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (&Guid, IoRead, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);\r
- ASSERT (ReturnReg.Status == EFI_SAL_SUCCESS);\r
-\r
- return ReturnReg.Status;\r
-\r
-}\r
-\r
-EFI_STATUS\r
-EfiIoWrite (\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an IO write into Buffer.\r
-\r
-Arguments:\r
- Width - Width of write transaction, and repeat operation to use\r
- Address - IO address to write\r
- Count - Number of times to write the IO address.\r
- Buffer - Buffer to write data from. size is Width * Count\r
-\r
-Returns:\r
- Status code\r
-\r
---*/\r
-{\r
-\r
- SAL_RETURN_REGS ReturnReg;\r
-\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (&Guid, IoWrite, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);\r
-\r
- return ReturnReg.Status;\r
-\r
-}\r
-\r
-EFI_STATUS\r
-EfiMemRead (\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform a Memory mapped IO read into Buffer.\r
-\r
-Arguments:\r
- Width - Width of each read transaction.\r
- Address - Memory mapped IO address to read\r
- Count - Number of Width quanta to read\r
- Buffer - Buffer to read data into. size is Width * Count\r
-\r
-Returns:\r
- Status code\r
-\r
---*/\r
-{\r
-\r
- SAL_RETURN_REGS ReturnReg;\r
-\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (&Guid, MemRead, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);\r
- ASSERT (ReturnReg.Status == EFI_SAL_SUCCESS);\r
-\r
- return ReturnReg.Status;\r
-\r
-}\r
-\r
-EFI_STATUS\r
-EfiMemWrite (\r
- IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
- IN UINT64 Address,\r
- IN UINTN Count,\r
- IN OUT VOID *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform a memory mapped IO write into Buffer.\r
-\r
-Arguments:\r
- Width - Width of write transaction, and repeat operation to use\r
- Address - IO address to write\r
- Count - Number of times to write the IO address.\r
- Buffer - Buffer to write data from. size is Width * Count\r
-\r
-Returns:\r
- Status code\r
-\r
---*/\r
-{\r
-\r
- SAL_RETURN_REGS ReturnReg;\r
-\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;\r
-\r
- ReturnReg = EfiCallEsalService (&Guid, MemWrite, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);\r
-\r
- return ReturnReg.Status;\r
-\r
-}\r
-\r
-\r
-#define EFI_PCI_ADDRESS_IPF(_seg, _bus, _devfunc, _reg) \\r
- (((_seg) << 24) | ((_bus) << 16) | ((_devfunc) << 8) | (_reg)) & 0xFFFFFFFF\r
-\r
-//\r
-// PCI Class Functions\r
-//\r
-UINT8\r
-PciRead8 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an one byte PCI config cycle read\r
-\r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
-\r
-Returns:\r
- Data read from PCI config space\r
-\r
---*/\r
-{\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
- UINT64 Address;\r
- SAL_RETURN_REGS Return;\r
-\r
- Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
- Return = EfiCallEsalService (&Guid, SalPciConfigRead, Address, 1, 0, 0, 0, 0, 0);\r
-\r
- return (UINT8) Return.r9;\r
-}\r
-\r
-\r
-UINT16\r
-PciRead16 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an two byte PCI config cycle read\r
-\r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
-\r
-Returns:\r
- Data read from PCI config space\r
-\r
---*/\r
-{\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
- UINT64 Address;\r
- SAL_RETURN_REGS Return;\r
-\r
- Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
- Return = EfiCallEsalService (&Guid, SalPciConfigRead, Address, 2, 0, 0, 0, 0, 0);\r
-\r
- return (UINT16) Return.r9;\r
-}\r
-\r
-UINT32\r
-PciRead32 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an four byte PCI config cycle read\r
-\r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
-\r
-Returns:\r
- Data read from PCI config space\r
-\r
---*/\r
-{\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
- UINT64 Address;\r
- SAL_RETURN_REGS Return;\r
-\r
- Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
- Return = EfiCallEsalService (&Guid, SalPciConfigRead, Address, 4, 0, 0, 0, 0, 0);\r
-\r
- return (UINT32) Return.r9;\r
-}\r
-\r
-VOID\r
-PciWrite8 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register,\r
- UINT8 Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an one byte PCI config cycle write\r
-\r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
- Data - Data to write\r
-\r
-Returns:\r
- NONE\r
-\r
---*/\r
-{\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
- UINT64 Address;\r
-\r
- Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
- EfiCallEsalService (&Guid, SalPciConfigWrite, Address, 1, Data, 0, 0, 0, 0);\r
-}\r
-\r
-VOID\r
-PciWrite16 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register,\r
- UINT16 Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an two byte PCI config cycle write\r
-\r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
- Data - Data to write\r
-\r
-Returns:\r
- None.\r
-\r
---*/\r
-{\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
- UINT64 Address;\r
-\r
- Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
- EfiCallEsalService (&Guid, SalPciConfigWrite, Address, 2, Data, 0, 0, 0, 0);\r
-}\r
-\r
-VOID\r
-PciWrite32 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register,\r
- UINT32 Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an four byte PCI config cycle write\r
-\r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
- Data - Data to write\r
-\r
-Returns:\r
- NONE\r
-\r
---*/\r
-{\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;\r
- UINT64 Address;\r
-\r
- Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);\r
- EfiCallEsalService (&Guid, SalPciConfigWrite, Address, 4, Data, 0, 0, 0, 0);\r
-}\r
-\r
-//\r
-// Stall class functions\r
-//\r
-VOID\r
-EfiStall (\r
- IN UINTN Microseconds\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Delay for at least the request number of microseconds\r
-\r
-Arguments:\r
- Microseconds - Number of microseconds to delay.\r
-\r
-Returns:\r
- NONE\r
-\r
---*/\r
-{\r
- EFI_GUID Guid = EFI_EXTENDED_SAL_STALL_SERVICES_PROTOCOL_GUID;\r
-\r
- if (EfiAtRuntime ()) {\r
- EfiCallEsalService (&Guid, Stall, Microseconds, 4, 0, 0, 0, 0, 0);\r
- } else {\r
- gBS->Stall (Microseconds);\r
- }\r
-}\r
-//\r
-// Cache Flush Routine.\r
-//\r
-EFI_STATUS\r
-EfiCpuFlushCache (\r
- IN EFI_PHYSICAL_ADDRESS Start,\r
- IN UINT64 Length\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Flush cache with specified range.\r
-\r
-Arguments:\r
-\r
- Start - Start address\r
- Length - Length in bytes\r
-\r
-Returns:\r
-\r
- Status code\r
- \r
- EFI_SUCCESS - success\r
-\r
---*/\r
-{\r
- SalFlushCache (Start, Length);\r
- return EFI_SUCCESS;\r
-}\r