runtimelib.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 1,318 行 · 第 1/3 页
C
1,318 行
ReturnReg = EfiCallEsalService (&Guid, GetWakeupTime, (UINT64) Enabled, (UINT64) Pending, (UINT64) Time, 0, 0, 0, 0);
return ReturnReg.Status;
}
EFI_STATUS
EfiSetWakeupTime (
IN BOOLEAN Enable,
IN EFI_TIME *Time
)
/*++
Routine Description:
Sets the system wakeup alarm clock time.
Arguments:
Enable - Enable or disable the wakeup alarm.
Time - If Enable is TRUE, the time to set the wakeup alarm for.
If Enable is FALSE, then this parameter is optional, and may be NULL.
Returns:
Status code
--*/
{
SAL_RETURN_REGS ReturnReg;
EFI_GUID Guid = EFI_EXTENDED_SAL_RTC_SERVICES_PROTOCOL_GUID;
ReturnReg = EfiCallEsalService (&Guid, SetWakeupTime, (UINT64) Enable, (UINT64) Time, 0, 0, 0, 0, 0);
return ReturnReg.Status;
}
//
// Base IO Services
//
EFI_STATUS
EfiIoRead (
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Perform an IO read into Buffer.
Arguments:
Width - Width of read transaction, and repeat operation to use
Address - IO address to read
Count - Number of times to read the IO address.
Buffer - Buffer to read data into. size is Width * Count
Returns:
Status code
--*/
{
SAL_RETURN_REGS ReturnReg;
EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;
ReturnReg = EfiCallEsalService (&Guid, IoRead, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);
return ReturnReg.Status;
}
EFI_STATUS
EfiIoWrite (
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Perform an IO write into Buffer.
Arguments:
Width - Width of write transaction, and repeat operation to use
Address - IO address to write
Count - Number of times to write the IO address.
Buffer - Buffer to write data from. size is Width * Count
Returns:
Status code
--*/
{
SAL_RETURN_REGS ReturnReg;
EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;
ReturnReg = EfiCallEsalService (&Guid, IoWrite, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);
return ReturnReg.Status;
}
EFI_STATUS
EfiMemRead (
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Perform a Memory mapped IO read into Buffer.
Arguments:
Width - Width of each read transaction.
Address - Memory mapped IO address to read
Count - Number of Width quanta to read
Buffer - Buffer to read data into. size is Width * Count
Returns:
Status code
--*/
{
SAL_RETURN_REGS ReturnReg;
EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;
ReturnReg = EfiCallEsalService (&Guid, MemRead, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);
return ReturnReg.Status;
}
EFI_STATUS
EfiMemWrite (
IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer
)
/*++
Routine Description:
Perform a memory mapped IO write into Buffer.
Arguments:
Width - Width of write transaction, and repeat operation to use
Address - IO address to write
Count - Number of times to write the IO address.
Buffer - Buffer to write data from. size is Width * Count
Returns:
Status code
--*/
{
SAL_RETURN_REGS ReturnReg;
EFI_GUID Guid = EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID;
ReturnReg = EfiCallEsalService (&Guid, MemWrite, (UINT64) Width, Address, Count, (UINT64) Buffer, 0, 0, 0);
return ReturnReg.Status;
}
#define EFI_PCI_ADDRESS_IPF(_seg, _bus, _devfunc, _reg) \
(((_seg) << 24) | ((_bus) << 16) | ((_devfunc) << 8) | (_reg)) & 0xFFFFFFFF
//
// PCI Class Functions
//
UINT8
PciRead8 (
UINT8 Segment,
UINT8 Bus,
UINT8 DevFunc,
UINT8 Register
)
/*++
Routine Description:
Perform an one byte PCI config cycle read
Arguments:
Segment - PCI Segment ACPI _SEG
Bus - PCI Bus
DevFunc - PCI Device(7:3) and Func(2:0)
Register - PCI config space register
Returns:
Data read from PCI config space
--*/
{
EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;
UINT64 Address;
SAL_RETURN_REGS Return;
Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);
Return = EfiCallEsalService (&Guid, SalPciConfigRead, Address, 1, 0, 0, 0, 0, 0);
return (UINT8) Return.r9;
}
UINT16
PciRead16 (
UINT8 Segment,
UINT8 Bus,
UINT8 DevFunc,
UINT8 Register
)
/*++
Routine Description:
Perform an two byte PCI config cycle read
Arguments:
Segment - PCI Segment ACPI _SEG
Bus - PCI Bus
DevFunc - PCI Device(7:3) and Func(2:0)
Register - PCI config space register
Returns:
Data read from PCI config space
--*/
{
EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;
UINT64 Address;
SAL_RETURN_REGS Return;
Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);
Return = EfiCallEsalService (&Guid, SalPciConfigRead, Address, 2, 0, 0, 0, 0, 0);
return (UINT16) Return.r9;
}
UINT32
PciRead32 (
UINT8 Segment,
UINT8 Bus,
UINT8 DevFunc,
UINT8 Register
)
/*++
Routine Description:
Perform an four byte PCI config cycle read
Arguments:
Segment - PCI Segment ACPI _SEG
Bus - PCI Bus
DevFunc - PCI Device(7:3) and Func(2:0)
Register - PCI config space register
Returns:
Data read from PCI config space
--*/
{
EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;
UINT64 Address;
SAL_RETURN_REGS Return;
Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);
Return = EfiCallEsalService (&Guid, SalPciConfigRead, Address, 4, 0, 0, 0, 0, 0);
return (UINT32) Return.r9;
}
VOID
PciWrite8 (
UINT8 Segment,
UINT8 Bus,
UINT8 DevFunc,
UINT8 Register,
UINT8 Data
)
/*++
Routine Description:
Perform an one byte PCI config cycle write
Arguments:
Segment - PCI Segment ACPI _SEG
Bus - PCI Bus
DevFunc - PCI Device(7:3) and Func(2:0)
Register - PCI config space register
Data - Data to write
Returns:
NONE
--*/
{
EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;
UINT64 Address;
Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);
EfiCallEsalService (&Guid, SalPciConfigWrite, Address, 1, Data, 0, 0, 0, 0);
}
VOID
PciWrite16 (
UINT8 Segment,
UINT8 Bus,
UINT8 DevFunc,
UINT8 Register,
UINT16 Data
)
/*++
Routine Description:
Perform an two byte PCI config cycle write
Arguments:
Segment - PCI Segment ACPI _SEG
Bus - PCI Bus
DevFunc - PCI Device(7:3) and Func(2:0)
Register - PCI config space register
Data - Data to write
Returns:
None.
--*/
{
EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;
UINT64 Address;
Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);
EfiCallEsalService (&Guid, SalPciConfigWrite, Address, 2, Data, 0, 0, 0, 0);
}
VOID
PciWrite32 (
UINT8 Segment,
UINT8 Bus,
UINT8 DevFunc,
UINT8 Register,
UINT32 Data
)
/*++
Routine Description:
Perform an four byte PCI config cycle write
Arguments:
Segment - PCI Segment ACPI _SEG
Bus - PCI Bus
DevFunc - PCI Device(7:3) and Func(2:0)
Register - PCI config space register
Data - Data to write
Returns:
NONE
--*/
{
EFI_GUID Guid = EFI_EXTENDED_SAL_PCI_SERVICES_PROTOCOL_GUID;
UINT64 Address;
Address = EFI_PCI_ADDRESS_IPF (Segment, Bus, DevFunc, Register);
EfiCallEsalService (&Guid, SalPciConfigWrite, Address, 4, Data, 0, 0, 0, 0);
}
//
// Stall class functions
//
VOID
EfiStall (
IN UINTN Microseconds
)
/*++
Routine Description:
Delay for at least the request number of microseconds
Arguments:
Microseconds - Number of microseconds to delay.
Returns:
NONE
--*/
{
EFI_GUID Guid = EFI_EXTENDED_SAL_STALL_SERVICES_PROTOCOL_GUID;
if (EfiAtRuntime ()) {
EfiCallEsalService (&Guid, Stall, Microseconds, 4, 0, 0, 0, 0, 0);
} else {
gBS->Stall (Microseconds);
}
}
//
// Cache Flush Routine.
//
EFI_STATUS
EfiCpuFlushCache (
IN EFI_PHYSICAL_ADDRESS Start,
IN UINT64 Length
)
/*++
Routine Description:
Flush cache with specified range.
Arguments:
Start - Start address
Length - Length in bytes
Returns:
Status code
EFI_SUCCESS - success
--*/
{
SalFlushCache (Start, Length);
return EFI_SUCCESS;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?