TianoCore EDK2 master
Loading...
Searching...
No Matches
CpuDxe.c File Reference
#include "CpuDxe.h"
#include "CpuMp.h"
#include "CpuPageTable.h"

Go to the source code of this file.

Macros

#define CPU_INTERRUPT_NUM   256
 

Functions

EFI_STATUS EFIAPI CpuFlushCpuDataCache (IN EFI_CPU_ARCH_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS Start, IN UINT64 Length, IN EFI_CPU_FLUSH_TYPE FlushType)
 
EFI_STATUS EFIAPI CpuEnableInterrupt (IN EFI_CPU_ARCH_PROTOCOL *This)
 
EFI_STATUS EFIAPI CpuDisableInterrupt (IN EFI_CPU_ARCH_PROTOCOL *This)
 
EFI_STATUS EFIAPI CpuGetInterruptState (IN EFI_CPU_ARCH_PROTOCOL *This, OUT BOOLEAN *State)
 
EFI_STATUS EFIAPI CpuInit (IN EFI_CPU_ARCH_PROTOCOL *This, IN EFI_CPU_INIT_TYPE InitType)
 
EFI_STATUS EFIAPI CpuRegisterInterruptHandler (IN EFI_CPU_ARCH_PROTOCOL *This, IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler)
 
EFI_STATUS EFIAPI CpuGetTimerValue (IN EFI_CPU_ARCH_PROTOCOL *This, IN UINT32 TimerIndex, OUT UINT64 *TimerValue, OUT UINT64 *TimerPeriod OPTIONAL)
 
VOID EFIAPI SetMtrrsFromBuffer (IN VOID *Buffer)
 
EFI_STATUS EFIAPI CpuSetMemoryAttributes (IN EFI_CPU_ARCH_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
 
UINT64 GetMemorySpaceAttributeFromMtrrType (IN MTRR_MEMORY_CACHE_TYPE Type)
 
EFI_STATUS SearchGcdMemorySpaces (IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap, IN UINTN NumberOfDescriptors, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, OUT UINTN *StartIndex, OUT UINTN *EndIndex)
 
EFI_STATUS SetGcdMemorySpaceAttributes (IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap, IN UINTN NumberOfDescriptors, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
 
VOID RefreshMemoryAttributesFromMtrr (VOID)
 
BOOLEAN IsPagingAndPageAddressExtensionsEnabled (VOID)
 
VOID RefreshGcdMemoryAttributes (VOID)
 
VOID InitInterruptDescriptorTable (VOID)
 
VOID EFIAPI IdleLoopEventCallback (IN EFI_EVENT Event, IN VOID *Context)
 
EFI_STATUS IntersectMemoryDescriptor (IN UINT64 Base, IN UINT64 Length, IN UINT64 Capabilities, IN CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor)
 
EFI_STATUS AddMemoryMappedIoSpace (IN UINT64 Base, IN UINT64 Length, IN UINT64 Capabilities)
 
VOID AddLocalApicMemorySpace (IN EFI_HANDLE ImageHandle)
 
EFI_STATUS EFIAPI InitializeCpu (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 

Variables

BOOLEAN InterruptState = FALSE
 
EFI_HANDLE mCpuHandle = NULL
 
BOOLEAN mIsFlushingGCD
 
BOOLEAN mIsAllocatingPageTable = FALSE
 
UINT64 mTimerPeriod = 0
 
EFI_CPU_ARCH_PROTOCOL gCpu
 

Detailed Description

CPU DXE Module to produce CPU ARCH Protocol.

Copyright (c) 2008 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CpuDxe.c.

Macro Definition Documentation

◆ CPU_INTERRUPT_NUM

#define CPU_INTERRUPT_NUM   256

Definition at line 13 of file CpuDxe.c.

Function Documentation

◆ AddLocalApicMemorySpace()

VOID AddLocalApicMemorySpace ( IN EFI_HANDLE  ImageHandle)

Add and allocate CPU local APIC memory mapped space.

Parameters
[in]

Image handle this driver.

Definition at line 949 of file CpuDxe.c.

◆ AddMemoryMappedIoSpace()

EFI_STATUS AddMemoryMappedIoSpace ( IN UINT64  Base,
IN UINT64  Length,
IN UINT64  Capabilities 
)

Add MMIO space to GCD. The routine checks the GCD database and only adds those which are not added in the specified range to GCD.

Parameters
BaseBase address of the MMIO space.
LengthLength of the MMIO space.
CapabilitiesCapabilities of the MMIO space.
Return values
EFI_SUCCESSThe MMIO space was added successfully.

Definition at line 879 of file CpuDxe.c.

◆ CpuDisableInterrupt()

EFI_STATUS EFIAPI CpuDisableInterrupt ( IN EFI_CPU_ARCH_PROTOCOL This)

Disables CPU interrupts.

Parameters
ThisProtocol instance structure
Return values
EFI_SUCCESSIf interrupts were disabled in the CPU.
EFI_DEVICE_ERRORIf interrupts could not be disabled on the CPU.

Definition at line 108 of file CpuDxe.c.

◆ CpuEnableInterrupt()

EFI_STATUS EFIAPI CpuEnableInterrupt ( IN EFI_CPU_ARCH_PROTOCOL This)

Enables CPU interrupts.

Parameters
ThisProtocol instance structure
Return values
EFI_SUCCESSIf interrupts were enabled in the CPU
EFI_DEVICE_ERRORIf interrupts could not be enabled on the CPU.

Definition at line 87 of file CpuDxe.c.

◆ CpuFlushCpuDataCache()

EFI_STATUS EFIAPI CpuFlushCpuDataCache ( IN EFI_CPU_ARCH_PROTOCOL This,
IN EFI_PHYSICAL_ADDRESS  Start,
IN UINT64  Length,
IN EFI_CPU_FLUSH_TYPE  FlushType 
)

Flush CPU data cache. If the instruction cache is fully coherent with all DMA operations then function can just return EFI_SUCCESS.

Parameters
ThisProtocol instance structure
StartPhysical address to start flushing from.
LengthNumber of bytes to flush. Round up to chipset granularity.
FlushTypeSpecifies the type of flush operation to perform.
Return values
EFI_SUCCESSIf cache was flushed
EFI_UNSUPPORTEDIf flush type is not supported.
EFI_DEVICE_ERRORIf requested range could not be flushed.

Definition at line 58 of file CpuDxe.c.

◆ CpuGetInterruptState()

EFI_STATUS EFIAPI CpuGetInterruptState ( IN EFI_CPU_ARCH_PROTOCOL This,
OUT BOOLEAN *  State 
)

Return the state of interrupts.

Parameters
ThisProtocol instance structure
StatePointer to the CPU's current interrupt state
Return values
EFI_SUCCESSIf interrupts were disabled in the CPU.
EFI_INVALID_PARAMETERState is NULL.

Definition at line 130 of file CpuDxe.c.

◆ CpuGetTimerValue()

EFI_STATUS EFIAPI CpuGetTimerValue ( IN EFI_CPU_ARCH_PROTOCOL This,
IN UINT32  TimerIndex,
OUT UINT64 *  TimerValue,
OUT UINT64 *TimerPeriod  OPTIONAL 
)

Returns a timer value from one of the CPU's internal timers. There is no inherent time interval between ticks but is a function of the CPU frequency.

Parameters
This- Protocol instance structure.
TimerIndex- Specifies which CPU timer is requested.
TimerValue- Pointer to the returned timer value.
TimerPeriod- A pointer to the amount of time that passes in femtoseconds (10-15) for each increment of TimerValue. If TimerValue does not increment at a predictable rate, then 0 is returned. The amount of time that has passed between two calls to GetTimerValue() can be calculated with the formula (TimerValue2 - TimerValue1) * TimerPeriod. This parameter is optional and may be NULL.
Return values
EFI_SUCCESS- If the CPU timer count was returned.
EFI_UNSUPPORTED- If the CPU does not have any readable timers.
EFI_DEVICE_ERROR- If an error occurred while reading the timer.
EFI_INVALID_PARAMETER- TimerIndex is not valid or TimerValue is NULL.

Definition at line 221 of file CpuDxe.c.

◆ CpuInit()

EFI_STATUS EFIAPI CpuInit ( IN EFI_CPU_ARCH_PROTOCOL This,
IN EFI_CPU_INIT_TYPE  InitType 
)

Generates an INIT to the CPU.

Parameters
ThisProtocol instance structure
InitTypeType of CPU INIT to perform
Return values
EFI_SUCCESSIf CPU INIT occurred. This value should never be seen.
EFI_DEVICE_ERRORIf CPU INIT failed.
EFI_UNSUPPORTEDRequested type of CPU INIT not supported.

Definition at line 157 of file CpuDxe.c.

◆ CpuRegisterInterruptHandler()

EFI_STATUS EFIAPI CpuRegisterInterruptHandler ( IN EFI_CPU_ARCH_PROTOCOL This,
IN EFI_EXCEPTION_TYPE  InterruptType,
IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler 
)

Registers a function to be called from the CPU interrupt handler.

Parameters
ThisProtocol instance structure
InterruptTypeDefines which interrupt to hook. IA-32 valid range is 0x00 through 0xFF
InterruptHandlerA pointer to a function of type EFI_CPU_INTERRUPT_HANDLER that is called when a processor interrupt occurs. A null pointer is an error condition.
Return values
EFI_SUCCESSIf handler installed or uninstalled.
EFI_ALREADY_STARTEDInterruptHandler is not NULL, and a handler for InterruptType was previously installed.
EFI_INVALID_PARAMETERInterruptHandler is NULL, and a handler for InterruptType was not previously installed.
EFI_UNSUPPORTEDThe interrupt specified by InterruptType is not supported.

Definition at line 187 of file CpuDxe.c.

◆ CpuSetMemoryAttributes()

EFI_STATUS EFIAPI CpuSetMemoryAttributes ( IN EFI_CPU_ARCH_PROTOCOL This,
IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN UINT64  Attributes 
)

Implementation of SetMemoryAttributes() service of CPU Architecture Protocol.

This function modifies the attributes for the memory region specified by BaseAddress and Length from their current attributes to the attributes specified by Attributes.

Parameters
ThisThe EFI_CPU_ARCH_PROTOCOL instance.
BaseAddressThe physical address that is the start address of a memory region.
LengthThe size in bytes of the memory region.
AttributesThe bit mask of attributes to set for the memory region.
Return values
EFI_SUCCESSThe attributes were set for the memory region.
EFI_ACCESS_DENIEDThe attributes for the memory resource range specified by BaseAddress and Length cannot be modified.
EFI_INVALID_PARAMETERLength is zero. Attributes specified an illegal combination of attributes that cannot be set together.
EFI_OUT_OF_RESOURCESThere are not enough system resources to modify the attributes of the memory resource range.
EFI_UNSUPPORTEDThe processor does not support one or more bytes of the memory resource range specified by BaseAddress and Length. The bit mask of attributes is not support for the memory resource range specified by BaseAddress and Length.

Definition at line 311 of file CpuDxe.c.

◆ GetMemorySpaceAttributeFromMtrrType()

UINT64 GetMemorySpaceAttributeFromMtrrType ( IN MTRR_MEMORY_CACHE_TYPE  Type)

Gets GCD Mem Space type from MTRR Type.

This function gets GCD Mem Space type from MTRR Type.

Parameters
TypeMTRR memory type
Returns
GCD Mem Space type

Definition at line 448 of file CpuDxe.c.

◆ IdleLoopEventCallback()

VOID EFIAPI IdleLoopEventCallback ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Callback function for idle events.

Parameters
EventEvent whose notification function is being invoked.
ContextThe pointer to the notification function's context, which is implementation-dependent.

Definition at line 753 of file CpuDxe.c.

◆ InitializeCpu()

EFI_STATUS EFIAPI InitializeCpu ( IN EFI_HANDLE  ImageHandle,
IN EFI_SYSTEM_TABLE SystemTable 
)

Initialize the state information for the CPU Architectural Protocol.

Parameters
ImageHandleImage handle this driver.
SystemTablePointer to the System Table.
Return values
EFI_SUCCESSThread can be successfully created
EFI_OUT_OF_RESOURCESCannot allocate protocol data structure
EFI_DEVICE_ERRORCannot create the thread

Definition at line 998 of file CpuDxe.c.

◆ InitInterruptDescriptorTable()

VOID InitInterruptDescriptorTable ( VOID  )

Initialize Interrupt Descriptor Table for interrupt handling.

Definition at line 704 of file CpuDxe.c.

◆ IntersectMemoryDescriptor()

EFI_STATUS IntersectMemoryDescriptor ( IN UINT64  Base,
IN UINT64  Length,
IN UINT64  Capabilities,
IN CONST EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor 
)

Ensure the compatibility of a memory space descriptor with the MMIO aperture.

The memory space descriptor can come from the GCD memory space map, or it can represent a gap between two neighboring memory space descriptors. In the latter case, the GcdMemoryType field is expected to be EfiGcdMemoryTypeNonExistent.

If the memory space descriptor already has type EfiGcdMemoryTypeMemoryMappedIo, and its capabilities are a superset of the required capabilities, then no action is taken – it is by definition compatible with the aperture.

Otherwise, the intersection of the memory space descriptor is calculated with the aperture. If the intersection is the empty set (no overlap), no action is taken; the memory space descriptor is compatible with the aperture.

Otherwise, the type of the descriptor is investigated again. If the type is EfiGcdMemoryTypeNonExistent (representing a gap, or a genuine descriptor with such a type), then an attempt is made to add the intersection as MMIO space to the GCD memory space map, with the specified capabilities. This ensures continuity for the aperture, and the descriptor is deemed compatible with the aperture.

Otherwise, the memory space descriptor is incompatible with the MMIO aperture.

Parameters
[in]BaseBase address of the aperture.
[in]LengthLength of the aperture.
[in]CapabilitiesCapabilities required by the aperture.
[in]DescriptorThe descriptor to ensure compatibility with the aperture for.
Return values
EFI_SUCCESSThe descriptor is compatible. The GCD memory space map may have been updated, for continuity within the aperture.
EFI_INVALID_PARAMETERThe descriptor is incompatible.
Returns
Error codes from gDS->AddMemorySpace().

Definition at line 801 of file CpuDxe.c.

◆ IsPagingAndPageAddressExtensionsEnabled()

BOOLEAN IsPagingAndPageAddressExtensionsEnabled ( VOID  )

Check if paging is enabled or not.

Definition at line 661 of file CpuDxe.c.

◆ RefreshGcdMemoryAttributes()

VOID RefreshGcdMemoryAttributes ( VOID  )

Refreshes the GCD Memory Space attributes according to MTRRs and Paging.

This function refreshes the GCD Memory Space attributes according to MTRRs and page tables.

Definition at line 682 of file CpuDxe.c.

◆ RefreshMemoryAttributesFromMtrr()

VOID RefreshMemoryAttributesFromMtrr ( VOID  )

Refreshes the GCD Memory Space attributes according to MTRRs.

This function refreshes the GCD Memory Space attributes according to MTRRs.

Definition at line 608 of file CpuDxe.c.

◆ SearchGcdMemorySpaces()

EFI_STATUS SearchGcdMemorySpaces ( IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemorySpaceMap,
IN UINTN  NumberOfDescriptors,
IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
OUT UINTN StartIndex,
OUT UINTN EndIndex 
)

Searches memory descriptors covered by given memory range.

This function searches into the Gcd Memory Space for descriptors (from StartIndex to EndIndex) that contains the memory range specified by BaseAddress and Length.

Parameters
MemorySpaceMapGcd Memory Space Map as array.
NumberOfDescriptorsNumber of descriptors in map.
BaseAddressBaseAddress for the requested range.
LengthLength for the requested range.
StartIndexStart index into the Gcd Memory Space Map.
EndIndexEnd index into the Gcd Memory Space Map.
Return values
EFI_SUCCESSSearch successfully.
EFI_NOT_FOUNDThe requested descriptors does not exist.

Definition at line 487 of file CpuDxe.c.

◆ SetGcdMemorySpaceAttributes()

EFI_STATUS SetGcdMemorySpaceAttributes ( IN EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemorySpaceMap,
IN UINTN  NumberOfDescriptors,
IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN UINT64  Attributes 
)

Sets the attributes for a specified range in Gcd Memory Space Map.

This function sets the attributes for a specified range in Gcd Memory Space Map.

Parameters
MemorySpaceMapGcd Memory Space Map as array
NumberOfDescriptorsNumber of descriptors in map
BaseAddressBaseAddress for the range
LengthLength for the range
AttributesAttributes to set
Return values
EFI_SUCCESSMemory attributes set successfully
EFI_NOT_FOUNDThe specified range does not exist in Gcd Memory Space

Definition at line 535 of file CpuDxe.c.

◆ SetMtrrsFromBuffer()

VOID EFIAPI SetMtrrsFromBuffer ( IN VOID *  Buffer)

A minimal wrapper function that allows MtrrSetAllMtrrs() to be passed to EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() as Procedure.

Parameters
[in]BufferPointer to an MTRR_SETTINGS object, to be passed to MtrrSetAllMtrrs().

Definition at line 277 of file CpuDxe.c.

Variable Documentation

◆ gCpu

Initial value:
= {
1,
4
}
EFI_STATUS EFIAPI CpuGetInterruptState(IN EFI_CPU_ARCH_PROTOCOL *This, OUT BOOLEAN *State)
Definition: CpuDxe.c:126
EFI_STATUS EFIAPI CpuRegisterInterruptHandler(IN EFI_CPU_ARCH_PROTOCOL *This, IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler)
Definition: CpuDxe.c:167
EFI_STATUS EFIAPI CpuGetTimerValue(IN EFI_CPU_ARCH_PROTOCOL *This, IN UINT32 TimerIndex, OUT UINT64 *TimerValue, OUT UINT64 *TimerPeriod OPTIONAL)
Definition: CpuDxe.c:178
EFI_STATUS EFIAPI CpuDisableInterrupt(IN EFI_CPU_ARCH_PROTOCOL *This)
Definition: CpuDxe.c:102
EFI_STATUS EFIAPI CpuInit(IN EFI_CPU_ARCH_PROTOCOL *This, IN EFI_CPU_INIT_TYPE InitType)
Definition: CpuDxe.c:157
EFI_STATUS EFIAPI CpuFlushCpuDataCache(IN EFI_CPU_ARCH_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS Start, IN UINT64 Length, IN EFI_CPU_FLUSH_TYPE FlushType)
Definition: CpuDxe.c:47
EFI_STATUS EFIAPI CpuEnableInterrupt(IN EFI_CPU_ARCH_PROTOCOL *This)
Definition: CpuDxe.c:82
EFI_STATUS EFIAPI CpuSetMemoryAttributes(IN EFI_CPU_ARCH_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
Definition: CpuMmuCommon.c:228

Definition at line 24 of file CpuDxe.c.

◆ InterruptState

BOOLEAN InterruptState = FALSE

Definition at line 18 of file CpuDxe.c.

◆ mCpuHandle

EFI_HANDLE mCpuHandle = NULL

Definition at line 19 of file CpuDxe.c.

◆ mIsAllocatingPageTable

BOOLEAN mIsAllocatingPageTable = FALSE

Definition at line 21 of file CpuDxe.c.

◆ mIsFlushingGCD

BOOLEAN mIsFlushingGCD

Definition at line 20 of file CpuDxe.c.

◆ mTimerPeriod

UINT64 mTimerPeriod = 0

Definition at line 22 of file CpuDxe.c.