TianoCore EDK2 master
Loading...
Searching...
No Matches
Smbase.c File Reference

Go to the source code of this file.

Functions

EFI_STATUS SmbaseAllocatePostSmmPen (OUT UINT32 *PenAddress, IN CONST EFI_BOOT_SERVICES *BootServices)
 
VOID SmbaseReinstallPostSmmPen (IN UINT32 PenAddress)
 
VOID SmbaseReleasePostSmmPen (IN UINT32 PenAddress, IN CONST EFI_BOOT_SERVICES *BootServices)
 
VOID SmbaseInstallFirstSmiHandler (VOID)
 
EFI_STATUS SmbaseRelocate (IN APIC_ID ApicId, IN UINTN Smbase, IN UINT32 PenAddress)
 

Variables

CONST UINT8 mPostSmmPen []
 
CONST UINT16 mPostSmmPenSize
 
CONST UINT8 mFirstSmiHandler []
 
CONST UINT16 mFirstSmiHandlerSize
 

Detailed Description

SMBASE relocation for hot-plugged CPUs.

Copyright (c) 2020, Red Hat, Inc.

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

Definition in file Smbase.c.

Function Documentation

◆ SmbaseAllocatePostSmmPen()

EFI_STATUS SmbaseAllocatePostSmmPen ( OUT UINT32 *  PenAddress,
IN CONST EFI_BOOT_SERVICES BootServices 
)

Allocate a non-SMRAM reserved memory page for the Post-SMM Pen for hot-added CPUs.

This function may only be called from the entry point function of the driver.

Parameters
[out]PenAddressThe address of the allocated (normal RAM) reserved page.
[in]BootServicesPointer to the UEFI boot services table. Used for allocating the normal RAM (not SMRAM) reserved page.
Return values
EFI_SUCCESSAllocation successful.
EFI_BAD_BUFFER_SIZEThe Post-SMM Pen template is not smaller than EFI_PAGE_SIZE.
Returns
Error codes propagated from underlying services. DEBUG_ERROR messages have been logged. No resources have been allocated.

Definition at line 48 of file Smbase.c.

◆ SmbaseInstallFirstSmiHandler()

VOID SmbaseInstallFirstSmiHandler ( VOID  )

Place the handler routine for the first SMIs of hot-added CPUs at (SMM_DEFAULT_SMBASE + SMM_HANDLER_OFFSET).

Note that this effects an "SMRAM to SMRAM" copy.

Additionally, shut the APIC ID gate in FIRST_SMI_HANDLER_CONTEXT.

This function may only be called from the entry point function of the driver, and only after PcdQ35SmramAtDefaultSmbase has been determined to be TRUE.

Definition at line 141 of file Smbase.c.

◆ SmbaseReinstallPostSmmPen()

VOID SmbaseReinstallPostSmmPen ( IN UINT32  PenAddress)

Copy the Post-SMM Pen template code into the reserved page allocated with SmbaseAllocatePostSmmPen().

Note that this effects an "SMRAM to normal RAM" copy.

The SMM Monarch is supposed to call this function from the root MMI handler.

Parameters
[in]PenAddressThe allocation address returned by SmbaseAllocatePostSmmPen().

Definition at line 101 of file Smbase.c.

◆ SmbaseReleasePostSmmPen()

VOID SmbaseReleasePostSmmPen ( IN UINT32  PenAddress,
IN CONST EFI_BOOT_SERVICES BootServices 
)

Release the reserved page allocated with SmbaseAllocatePostSmmPen().

This function may only be called from the entry point function of the driver, on the error path.

Parameters
[in]PenAddressThe allocation address returned by SmbaseAllocatePostSmmPen().
[in]BootServicesPointer to the UEFI boot services table. Used for releasing the normal RAM (not SMRAM) reserved page.

Definition at line 121 of file Smbase.c.

◆ SmbaseRelocate()

EFI_STATUS SmbaseRelocate ( IN APIC_ID  ApicId,
IN UINTN  Smbase,
IN UINT32  PenAddress 
)

Relocate the SMBASE on a hot-added CPU. Then pen the hot-added CPU in the normal RAM reserved memory page, set up earlier with SmbaseAllocatePostSmmPen() and SmbaseReinstallPostSmmPen().

The SMM Monarch is supposed to call this function from the root MMI handler.

The SMM Monarch is responsible for calling SmbaseInstallFirstSmiHandler(), SmbaseAllocatePostSmmPen(), and SmbaseReinstallPostSmmPen() before calling this function.

If the OS maliciously boots the hot-added CPU ahead of letting the ACPI CPU hotplug event handler broadcast the CPU hotplug MMI, then the hot-added CPU returns to the OS rather than to the pen, upon RSM. In that case, this function will hang forever (unless the OS happens to signal back through the last byte of the pen page).

Parameters
[in]ApicIdThe APIC ID of the hot-added CPU whose SMBASE should be relocated.
[in]SmbaseThe new SMBASE address. The root MMI handler is responsible for passing in a free ("unoccupied") SMBASE address that was pre-configured by PiSmmCpuDxeSmm in CPU_HOT_PLUG_DATA.
[in]PenAddressThe address of the Post-SMM Pen for hot-added CPUs, as returned by SmbaseAllocatePostSmmPen(), and installed by SmbaseReinstallPostSmmPen().
Return values
EFI_SUCCESSThe SMBASE of the hot-added CPU with APIC ID ApicId has been relocated to Smbase. The hot-added CPU has reported back about leaving SMM.
EFI_PROTOCOL_ERRORSynchronization bug encountered around FIRST_SMI_HANDLER_CONTEXT.ApicIdGate.
EFI_INVALID_PARAMETERSmbase does not fit in 32 bits. No relocation has been attempted.

Definition at line 198 of file Smbase.c.