TianoCore EDK2 master
Loading...
Searching...
No Matches
PiSmmCpuCommon.c File Reference
#include "PiSmmCpuCommon.h"

Go to the source code of this file.

Functions

VOID InitializeSmmIdt (VOID)
 
VOID DumpModuleInfoByIp (IN UINTN CallerIpAddress)
 
EFI_STATUS EFIAPI SmmReadSaveState (IN CONST EFI_SMM_CPU_PROTOCOL *This, IN UINTN Width, IN EFI_SMM_SAVE_STATE_REGISTER Register, IN UINTN CpuIndex, OUT VOID *Buffer)
 
EFI_STATUS EFIAPI SmmWriteSaveState (IN CONST EFI_SMM_CPU_PROTOCOL *This, IN UINTN Width, IN EFI_SMM_SAVE_STATE_REGISTER Register, IN UINTN CpuIndex, IN CONST VOID *Buffer)
 
VOID InitializeSmm (VOID)
 
VOID ExecuteFirstSmiInit (VOID)
 
INTN EFIAPI SmBaseHobCompare (IN CONST VOID *Buffer1, IN CONST VOID *Buffer2)
 
STATIC EFI_STATUS GetSmBase (IN UINTN MaxNumberOfCpus, OUT UINTN **AllocatedSmBaseBuffer)
 
INTN EFIAPI MpInformation2HobCompare (IN CONST VOID *Buffer1, IN CONST VOID *Buffer2)
 
EFI_PROCESSOR_INFORMATIONGetMpInformation (OUT UINTN *NumberOfCpus, OUT UINTN *MaxNumberOfCpus)
 
EFI_STATUS PiSmmCpuEntryCommon (VOID)
 
INTN EFIAPI CpuSmramRangeCompare (IN CONST VOID *Buffer1, IN CONST VOID *Buffer2)
 
VOID FindSmramInfo (OUT UINT32 *SmrrBase, OUT UINT32 *SmrrSize)
 
VOID EFIAPI ConfigSmmCodeAccessCheckOnCurrentProcessor (IN OUT VOID *Buffer)
 
VOID ConfigSmmCodeAccessCheck (VOID)
 
VOID * AllocateCodePages (IN UINTN Pages)
 
VOID PerformPreTasks (VOID)
 

Variables

SMM_CPU_PRIVATE_DATA mSmmCpuPrivateData
 
CPU_HOT_PLUG_DATA mCpuHotPlugData
 
SMM_CPU_PRIVATE_DATAgSmmCpuPrivate = &mSmmCpuPrivateData
 
EFI_HANDLE mSmmCpuHandle = NULL
 
EFI_SMM_CPU_PROTOCOL mSmmCpu
 
EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL mSmmMemoryAttribute
 
EFI_CPU_INTERRUPT_HANDLER mExternalVectorTable [EXCEPTION_VECTOR_NUMBER]
 
volatile BOOLEAN * mSmmInitialized = NULL
 
UINT32 mBspApicId = 0
 
UINTN mSmmStackArrayBase
 
UINTN mSmmStackArrayEnd
 
UINTN mSmmStackSize
 
UINTN mSmmShadowStackSize
 
BOOLEAN mCetSupported = TRUE
 
UINTN mMaxNumberOfCpus = 0
 
UINTN mNumberOfCpus = 0
 
BOOLEAN mSmmCodeAccessCheckEnable = FALSE
 
BOOLEAN mSmmDebugAgentSupport = FALSE
 
UINT64 mAddressEncMask = 0
 
SPIN_LOCKmConfigSmmCodeAccessCheckLock = NULL
 
EFI_SMRAM_DESCRIPTORmSmmCpuSmramRanges
 
UINTN mSmmCpuSmramRangeCount
 
UINT8 mPhysicalAddressBits
 

Detailed Description

Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU.

Copyright (c) 2009 - 2024, Intel Corporation. All rights reserved.
Copyright (c) 2017, AMD Incorporated. All rights reserved.
Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file PiSmmCpuCommon.c.

Function Documentation

◆ AllocateCodePages()

VOID * AllocateCodePages ( IN UINTN  Pages)

Allocate pages for code.

Parameters
[in]PagesNumber of pages to be allocated.
Returns
Allocated memory.

Definition at line 1509 of file PiSmmCpuCommon.c.

◆ ConfigSmmCodeAccessCheck()

VOID ConfigSmmCodeAccessCheck ( VOID  )

Configure SMM Code Access Check feature for all processors. SMM Feature Control MSR will be locked after configuration.

Definition at line 1435 of file PiSmmCpuCommon.c.

◆ ConfigSmmCodeAccessCheckOnCurrentProcessor()

VOID EFIAPI ConfigSmmCodeAccessCheckOnCurrentProcessor ( IN OUT VOID *  Buffer)

Configure SMM Code Access Check feature on an AP. SMM Feature Control MSR will be locked after configuration.

Parameters
[in,out]BufferPointer to private data buffer.

Definition at line 1388 of file PiSmmCpuCommon.c.

◆ CpuSmramRangeCompare()

INTN EFIAPI CpuSmramRangeCompare ( IN CONST VOID *  Buffer1,
IN CONST VOID *  Buffer2 
)

Function to compare 2 EFI_SMRAM_DESCRIPTOR based on CpuStart.

Parameters
[in]Buffer1pointer to Device Path poiner to compare
[in]Buffer2pointer to second DevicePath pointer to compare
Return values
0Buffer1 equal to Buffer2
<0Buffer1 is less than Buffer2
>0Buffer1 is greater than Buffer2

Definition at line 1283 of file PiSmmCpuCommon.c.

◆ DumpModuleInfoByIp()

VOID DumpModuleInfoByIp ( IN UINTN  CallerIpAddress)

Search module name by input IP address and output it.

Parameters
CallerIpAddressCaller instruction pointer.

Definition at line 181 of file PiSmmCpuCommon.c.

◆ ExecuteFirstSmiInit()

VOID ExecuteFirstSmiInit ( VOID  )

Issue SMI IPI (All Excluding Self SMM IPI + BSP SMM IPI) to execute first SMI init.

Definition at line 398 of file PiSmmCpuCommon.c.

◆ FindSmramInfo()

VOID FindSmramInfo ( OUT UINT32 *  SmrrBase,
OUT UINT32 *  SmrrSize 
)

Find out SMRAM information including SMRR base and SMRR size.

Parameters
SmrrBaseSMRR base
SmrrSizeSMRR size

Definition at line 1305 of file PiSmmCpuCommon.c.

◆ GetMpInformation()

EFI_PROCESSOR_INFORMATION * GetMpInformation ( OUT UINTN NumberOfCpus,
OUT UINTN MaxNumberOfCpus 
)

Extract NumberOfCpus, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION for all CPU from MpInformation2 HOB.

Parameters
[out]NumberOfCpusPointer to NumberOfCpus.
[out]MaxNumberOfCpusPointer to MaxNumberOfCpus.
Return values
ProcessorInfoPointer to EFI_PROCESSOR_INFORMATION buffer.

Definition at line 616 of file PiSmmCpuCommon.c.

◆ GetSmBase()

STATIC EFI_STATUS GetSmBase ( IN UINTN  MaxNumberOfCpus,
OUT UINTN **  AllocatedSmBaseBuffer 
)

Extract SmBase for all CPU from SmmBase HOB.

Parameters
[in]MaxNumberOfCpusMax NumberOfCpus.
[out]AllocatedSmBaseBufferPointer to SmBase Buffer allocated by this function. Only set if the function returns EFI_SUCCESS.
Return values
EFI_SUCCESSSmBase Buffer output successfully.
EFI_OUT_OF_RESOURCESMemory allocation failed.
EFI_NOT_FOUNDgSmmBaseHobGuid was never created.

Definition at line 489 of file PiSmmCpuCommon.c.

◆ InitializeSmm()

VOID InitializeSmm ( VOID  )

Initialize SMM environment.

Definition at line 327 of file PiSmmCpuCommon.c.

◆ InitializeSmmIdt()

VOID InitializeSmmIdt ( VOID  )

Initialize IDT to setup exception handlers for SMM.

Definition at line 132 of file PiSmmCpuCommon.c.

◆ MpInformation2HobCompare()

INTN EFIAPI MpInformation2HobCompare ( IN CONST VOID *  Buffer1,
IN CONST VOID *  Buffer2 
)

Function to compare 2 MP_INFORMATION2_HOB_DATA pointer based on ProcessorIndex.

Parameters
[in]Buffer1pointer to MP_INFORMATION2_HOB_DATA poiner to compare
[in]Buffer2pointer to second MP_INFORMATION2_HOB_DATA pointer to compare
Return values
0Buffer1 equal to Buffer2
<0Buffer1 is less than Buffer2
>0Buffer1 is greater than Buffer2

Definition at line 593 of file PiSmmCpuCommon.c.

◆ PerformPreTasks()

VOID PerformPreTasks ( VOID  )

Perform the pre tasks.

Definition at line 1533 of file PiSmmCpuCommon.c.

◆ PiSmmCpuEntryCommon()

EFI_STATUS PiSmmCpuEntryCommon ( VOID  )

The module Entry Point of the CPU SMM driver.

Return values
EFI_SUCCESSThe common entry point is executed successfully.
OtherSome error occurs when executing this entry point.

Definition at line 740 of file PiSmmCpuCommon.c.

◆ SmBaseHobCompare()

INTN EFIAPI SmBaseHobCompare ( IN CONST VOID *  Buffer1,
IN CONST VOID *  Buffer2 
)

Function to compare 2 SMM_BASE_HOB_DATA pointer based on ProcessorIndex.

Parameters
[in]Buffer1pointer to SMM_BASE_HOB_DATA poiner to compare
[in]Buffer2pointer to second SMM_BASE_HOB_DATA pointer to compare
Return values
0Buffer1 equal to Buffer2
<0Buffer1 is less than Buffer2
>0Buffer1 is greater than Buffer2

Definition at line 460 of file PiSmmCpuCommon.c.

◆ SmmReadSaveState()

EFI_STATUS EFIAPI SmmReadSaveState ( IN CONST EFI_SMM_CPU_PROTOCOL This,
IN UINTN  Width,
IN EFI_SMM_SAVE_STATE_REGISTER  Register,
IN UINTN  CpuIndex,
OUT VOID *  Buffer 
)

Read information from the CPU save state.

Parameters
ThisEFI_SMM_CPU_PROTOCOL instance
WidthThe number of bytes to read from the CPU save state.
RegisterSpecifies the CPU register to read form the save state.
CpuIndexSpecifies the zero-based index of the CPU save state.
BufferUpon return, this holds the CPU register value read from the save state.
Return values
EFI_SUCCESSThe register was read from Save State
EFI_NOT_FOUNDThe register is not defined for the Save State of Processor
EFI_INVALID_PARAMETERThis or Buffer is NULL.

Definition at line 217 of file PiSmmCpuCommon.c.

◆ SmmWriteSaveState()

EFI_STATUS EFIAPI SmmWriteSaveState ( IN CONST EFI_SMM_CPU_PROTOCOL This,
IN UINTN  Width,
IN EFI_SMM_SAVE_STATE_REGISTER  Register,
IN UINTN  CpuIndex,
IN CONST VOID *  Buffer 
)

Write data to the CPU save state.

Parameters
ThisEFI_SMM_CPU_PROTOCOL instance
WidthThe number of bytes to read from the CPU save state.
RegisterSpecifies the CPU register to write to the save state.
CpuIndexSpecifies the zero-based index of the CPU save state
BufferUpon entry, this holds the new CPU register value.
Return values
EFI_SUCCESSThe register was written from Save State
EFI_NOT_FOUNDThe register is not defined for the Save State of Processor
EFI_INVALID_PARAMETERProcessorIndex or Width is not correct

Definition at line 289 of file PiSmmCpuCommon.c.

Variable Documentation

◆ gSmmCpuPrivate

SMM_CPU_PRIVATE_DATA* gSmmCpuPrivate = &mSmmCpuPrivateData

Definition at line 57 of file PiSmmCpuCommon.c.

◆ mAddressEncMask

UINT64 mAddressEncMask = 0

Definition at line 112 of file PiSmmCpuCommon.c.

◆ mBspApicId

UINT32 mBspApicId = 0

Definition at line 84 of file PiSmmCpuCommon.c.

◆ mCetSupported

BOOLEAN mCetSupported = TRUE

Definition at line 94 of file PiSmmCpuCommon.c.

◆ mConfigSmmCodeAccessCheckLock

SPIN_LOCK* mConfigSmmCodeAccessCheckLock = NULL

Definition at line 117 of file PiSmmCpuCommon.c.

◆ mCpuHotPlugData

CPU_HOT_PLUG_DATA mCpuHotPlugData
Initial value:
= {
CPU_HOT_PLUG_DATA_REVISION_1,
0,
NULL,
NULL,
0,
0,
0
}
#define NULL
Definition: Base.h:319

Definition at line 44 of file PiSmmCpuCommon.c.

◆ mExternalVectorTable

EFI_CPU_INTERRUPT_HANDLER mExternalVectorTable[EXCEPTION_VECTOR_NUMBER]

Definition at line 81 of file PiSmmCpuCommon.c.

◆ mMaxNumberOfCpus

UINTN mMaxNumberOfCpus = 0

Definition at line 96 of file PiSmmCpuCommon.c.

◆ mNumberOfCpus

UINTN mNumberOfCpus = 0

Definition at line 97 of file PiSmmCpuCommon.c.

◆ mPhysicalAddressBits

UINT8 mPhysicalAddressBits

Definition at line 125 of file PiSmmCpuCommon.c.

◆ mSmmCodeAccessCheckEnable

BOOLEAN mSmmCodeAccessCheckEnable = FALSE

Definition at line 102 of file PiSmmCpuCommon.c.

◆ mSmmCpu

Initial value:
= {
}
EFI_STATUS EFIAPI SmmWriteSaveState(IN CONST EFI_SMM_CPU_PROTOCOL *This, IN UINTN Width, IN EFI_SMM_SAVE_STATE_REGISTER Register, IN UINTN CpuIndex, IN CONST VOID *Buffer)
EFI_STATUS EFIAPI SmmReadSaveState(IN CONST EFI_SMM_CPU_PROTOCOL *This, IN UINTN Width, IN EFI_SMM_SAVE_STATE_REGISTER Register, IN UINTN CpuIndex, OUT VOID *Buffer)

SMM CPU Protocol instance

Definition at line 67 of file PiSmmCpuCommon.c.

◆ mSmmCpuHandle

EFI_HANDLE mSmmCpuHandle = NULL

Handle for the SMM CPU Protocol

Definition at line 62 of file PiSmmCpuCommon.c.

◆ mSmmCpuPrivateData

SMM_CPU_PRIVATE_DATA mSmmCpuPrivateData
Initial value:
= {
SMM_CPU_PRIVATE_DATA_SIGNATURE,
NULL,
NULL,
NULL,
NULL,
NULL,
{
{ 0 }
},
{
0,
0,
NULL,
},
NULL,
{
mSmmCpuPrivateData.SmmReservedSmramRegion,
},
NULL,
{ NULL, NULL },
}
EFI_STATUS EFIAPI SmmStartupThisAp(IN EFI_AP_PROCEDURE Procedure, IN UINTN CpuIndex, IN OUT VOID *ProcArguments OPTIONAL)
Definition: MpService.c:1434
EFI_STATUS EFIAPI RegisterSmmEntry(IN CONST EFI_SMM_CONFIGURATION_PROTOCOL *This, IN EFI_SMM_ENTRY_POINT SmmEntryPoint)
Definition: MpService.c:2041

Definition at line 18 of file PiSmmCpuCommon.c.

◆ mSmmCpuSmramRangeCount

UINTN mSmmCpuSmramRangeCount

Definition at line 123 of file PiSmmCpuCommon.c.

◆ mSmmCpuSmramRanges

EFI_SMRAM_DESCRIPTOR* mSmmCpuSmramRanges

Definition at line 122 of file PiSmmCpuCommon.c.

◆ mSmmDebugAgentSupport

BOOLEAN mSmmDebugAgentSupport = FALSE

Definition at line 107 of file PiSmmCpuCommon.c.

◆ mSmmInitialized

volatile BOOLEAN* mSmmInitialized = NULL

Definition at line 83 of file PiSmmCpuCommon.c.

◆ mSmmMemoryAttribute

Initial value:
= {
}
EFI_STATUS EFIAPI EdkiiSmmGetMemoryAttributes(IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 *Attributes)
EFI_STATUS EFIAPI EdkiiSmmSetMemoryAttributes(IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
EFI_STATUS EFIAPI EdkiiSmmClearMemoryAttributes(IN EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)

SMM Memory Attribute Protocol instance

Definition at line 75 of file PiSmmCpuCommon.c.

◆ mSmmShadowStackSize

UINTN mSmmShadowStackSize

Definition at line 93 of file PiSmmCpuCommon.c.

◆ mSmmStackArrayBase

UINTN mSmmStackArrayBase

Definition at line 89 of file PiSmmCpuCommon.c.

◆ mSmmStackArrayEnd

UINTN mSmmStackArrayEnd

Definition at line 90 of file PiSmmCpuCommon.c.

◆ mSmmStackSize

UINTN mSmmStackSize

Definition at line 91 of file PiSmmCpuCommon.c.