OvmfPkg: add PEIM for providing TSEG-as-SMRAM during PEI
"MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf" is the
LockBoxLib instance with SMRAM access for the PEI phase.
Said library instance must, and can, access the LockBox data in SMRAM
directly if it is invoked before SMBASE relocation / SMI handler
installation. In that case, it only needs PEI_SMM_ACCESS_PPI from the
platform, and it doesn't depend on EFI_PEI_SMM_COMMUNICATION_PPI.
OVMF satisfies the description in SVN r18823 ("MdeModulePkg:
SmmLockBoxPeiLib: work without EFI_PEI_SMM_COMMUNICATION_PPI"): in OVMF,
only S3Resume2Pei links against SmmLockBoxPeiLib.
Therefore, introduce a PEIM that produces the PEI_SMM_ACCESS_PPI
interface, enabling SmmLockBoxPeiLib to work; we can omit including
"UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf".
The load / installation order of S3Resume2Pei and SmmAccessPei is
indifferent. SmmAccessPei produces the gEfiAcpiVariableGuid HOB during its
installation (which happens during PEI), but S3Resume2Pei accesses the HOB
only when the DXE IPL calls its S3RestoreConfig2 PPI member, as last act
of PEI.
MCH_SMRAM_D_LCK and MCH_ESMRAMC_T_EN are masked out the way they are, in
SmmAccessPeiEntryPoint() and SmramAccessOpen() respectively, in order to
prevent VS20xx from warning about the (otherwise fully intentional)
truncation in the UINT8 casts. (Warnings reported by Michael Kinney.)
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19040 6f19259b-4bc3-4df7-8a09-765794883524
2015-11-30 19:41:38 +01:00
|
|
|
/** @file
|
|
|
|
|
|
|
|
Functions and types shared by the SMM accessor PEI and DXE modules.
|
|
|
|
|
|
|
|
Copyright (C) 2015, Red Hat, Inc.
|
|
|
|
|
2019-04-04 01:06:33 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
OvmfPkg: add PEIM for providing TSEG-as-SMRAM during PEI
"MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf" is the
LockBoxLib instance with SMRAM access for the PEI phase.
Said library instance must, and can, access the LockBox data in SMRAM
directly if it is invoked before SMBASE relocation / SMI handler
installation. In that case, it only needs PEI_SMM_ACCESS_PPI from the
platform, and it doesn't depend on EFI_PEI_SMM_COMMUNICATION_PPI.
OVMF satisfies the description in SVN r18823 ("MdeModulePkg:
SmmLockBoxPeiLib: work without EFI_PEI_SMM_COMMUNICATION_PPI"): in OVMF,
only S3Resume2Pei links against SmmLockBoxPeiLib.
Therefore, introduce a PEIM that produces the PEI_SMM_ACCESS_PPI
interface, enabling SmmLockBoxPeiLib to work; we can omit including
"UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf".
The load / installation order of S3Resume2Pei and SmmAccessPei is
indifferent. SmmAccessPei produces the gEfiAcpiVariableGuid HOB during its
installation (which happens during PEI), but S3Resume2Pei accesses the HOB
only when the DXE IPL calls its S3RestoreConfig2 PPI member, as last act
of PEI.
MCH_SMRAM_D_LCK and MCH_ESMRAMC_T_EN are masked out the way they are, in
SmmAccessPeiEntryPoint() and SmramAccessOpen() respectively, in order to
prevent VS20xx from warning about the (otherwise fully intentional)
truncation in the UINT8 casts. (Warnings reported by Michael Kinney.)
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19040 6f19259b-4bc3-4df7-8a09-765794883524
2015-11-30 19:41:38 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <Pi/PiMultiPhase.h>
|
|
|
|
|
|
|
|
//
|
|
|
|
// We'll have two SMRAM ranges.
|
|
|
|
//
|
|
|
|
// The first is a tiny one that hosts an SMM_S3_RESUME_STATE object, to be
|
|
|
|
// filled in by the CPU SMM driver during normal boot, for the PEI instance of
|
|
|
|
// the LockBox library (which will rely on the object during S3 resume).
|
|
|
|
//
|
|
|
|
// The other SMRAM range is the main one, for the SMM core and the SMM drivers.
|
|
|
|
//
|
|
|
|
typedef enum {
|
|
|
|
DescIdxSmmS3ResumeState = 0,
|
|
|
|
DescIdxMain = 1,
|
|
|
|
DescIdxCount = 2
|
|
|
|
} DESCRIPTOR_INDEX;
|
|
|
|
|
2017-07-04 13:16:39 +02:00
|
|
|
//
|
|
|
|
// The value of PcdQ35TsegMbytes is saved into this variable at module startup.
|
|
|
|
//
|
|
|
|
extern UINT16 mQ35TsegMbytes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Save PcdQ35TsegMbytes into mQ35TsegMbytes.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
InitQ35TsegMbytes (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
2019-09-23 11:41:41 +02:00
|
|
|
/**
|
|
|
|
Save PcdQ35SmramAtDefaultSmbase into mQ35SmramAtDefaultSmbase.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
InitQ35SmramAtDefaultSmbase (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
OvmfPkg: add PEIM for providing TSEG-as-SMRAM during PEI
"MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf" is the
LockBoxLib instance with SMRAM access for the PEI phase.
Said library instance must, and can, access the LockBox data in SMRAM
directly if it is invoked before SMBASE relocation / SMI handler
installation. In that case, it only needs PEI_SMM_ACCESS_PPI from the
platform, and it doesn't depend on EFI_PEI_SMM_COMMUNICATION_PPI.
OVMF satisfies the description in SVN r18823 ("MdeModulePkg:
SmmLockBoxPeiLib: work without EFI_PEI_SMM_COMMUNICATION_PPI"): in OVMF,
only S3Resume2Pei links against SmmLockBoxPeiLib.
Therefore, introduce a PEIM that produces the PEI_SMM_ACCESS_PPI
interface, enabling SmmLockBoxPeiLib to work; we can omit including
"UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf".
The load / installation order of S3Resume2Pei and SmmAccessPei is
indifferent. SmmAccessPei produces the gEfiAcpiVariableGuid HOB during its
installation (which happens during PEI), but S3Resume2Pei accesses the HOB
only when the DXE IPL calls its S3RestoreConfig2 PPI member, as last act
of PEI.
MCH_SMRAM_D_LCK and MCH_ESMRAMC_T_EN are masked out the way they are, in
SmmAccessPeiEntryPoint() and SmramAccessOpen() respectively, in order to
prevent VS20xx from warning about the (otherwise fully intentional)
truncation in the UINT8 casts. (Warnings reported by Michael Kinney.)
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19040 6f19259b-4bc3-4df7-8a09-765794883524
2015-11-30 19:41:38 +01:00
|
|
|
/**
|
|
|
|
Read the MCH_SMRAM and ESMRAMC registers, and update the LockState and
|
|
|
|
OpenState fields in the PEI_SMM_ACCESS_PPI / EFI_SMM_ACCESS2_PROTOCOL object,
|
|
|
|
from the D_LCK and T_EN bits.
|
|
|
|
|
|
|
|
PEI_SMM_ACCESS_PPI and EFI_SMM_ACCESS2_PROTOCOL member functions can rely on
|
|
|
|
the LockState and OpenState fields being up-to-date on entry, and they need
|
|
|
|
to restore the same invariant on exit, if they touch the bits in question.
|
|
|
|
|
|
|
|
@param[out] LockState Reflects the D_LCK bit on output; TRUE iff SMRAM is
|
|
|
|
locked.
|
|
|
|
@param[out] OpenState Reflects the inverse of the T_EN bit on output; TRUE
|
|
|
|
iff SMRAM is open.
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
GetStates (
|
|
|
|
OUT BOOLEAN *LockState,
|
|
|
|
OUT BOOLEAN *OpenState
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// The functions below follow the PEI_SMM_ACCESS_PPI and
|
|
|
|
// EFI_SMM_ACCESS2_PROTOCOL member declarations. The PeiServices and This
|
|
|
|
// pointers are removed (TSEG doesn't depend on them), and so is the
|
|
|
|
// DescriptorIndex parameter (TSEG doesn't support range-wise locking).
|
|
|
|
//
|
|
|
|
// The LockState and OpenState members that are common to both
|
|
|
|
// PEI_SMM_ACCESS_PPI and EFI_SMM_ACCESS2_PROTOCOL are taken and updated in
|
|
|
|
// isolation from the rest of the (non-shared) members.
|
|
|
|
//
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
SmramAccessOpen (
|
|
|
|
OUT BOOLEAN *LockState,
|
|
|
|
OUT BOOLEAN *OpenState
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
SmramAccessClose (
|
|
|
|
OUT BOOLEAN *LockState,
|
|
|
|
OUT BOOLEAN *OpenState
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
SmramAccessLock (
|
|
|
|
OUT BOOLEAN *LockState,
|
|
|
|
IN OUT BOOLEAN *OpenState
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
SmramAccessGetCapabilities (
|
|
|
|
IN BOOLEAN LockState,
|
|
|
|
IN BOOLEAN OpenState,
|
|
|
|
IN OUT UINTN *SmramMapSize,
|
|
|
|
IN OUT EFI_SMRAM_DESCRIPTOR *SmramMap
|
|
|
|
);
|