Skip to content

Commit

Permalink
QemuQ35Pkg/SmmControl2Dxe: Drop S3 and Lock Box support
Browse files Browse the repository at this point in the history
Removes S3 and boot script related code to focus the module on simply
installing `Trigger()` and `Clear()` functionality for the SMM
Control protocol.

Signed-off-by: Michael Kubacki <Michael.kubacki@microsoft.com>
  • Loading branch information
makubacki committed Sep 24, 2024
1 parent 1f90578 commit b22b4e7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 309 deletions.
6 changes: 1 addition & 5 deletions Platforms/QemuQ35Pkg/SmmControl2Dxe/MmControlPei.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@
#include <Library/PciLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/QemuFwCfgLib.h>
#include <Library/QemuFwCfgS3Lib.h>
#include <Ppi/MmControl.h>

#include "SmiFeatures.h"

//
// The absolute IO port address of the SMI Control and Enable Register. It is
// only used to carry information from the entry point function to the
// S3SaveState protocol installation callback, strictly before the runtime
// phase.
// The absolute IO port address of the SMI Control and Enable Register.
//
STATIC UINTN mSmiEnable;

Expand Down
1 change: 0 additions & 1 deletion Platforms/QemuQ35Pkg/SmmControl2Dxe/MmControlPei.inf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
PcdLib
PciLib
QemuFwCfgLib
QemuFwCfgS3Lib
PeimEntryPoint

[Ppis]
Expand Down
121 changes: 7 additions & 114 deletions Platforms/QemuQ35Pkg/SmmControl2Dxe/SmiFeatures.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
accordingly.
Copyright (C) 2016-2017, Red Hat, Inc.
Copyright (c) Microsoft Corporation
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
Expand All @@ -13,7 +14,6 @@
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/QemuFwCfgLib.h>
#include <Library/QemuFwCfgS3Lib.h>

#include "SmiFeatures.h"

Expand All @@ -35,41 +35,27 @@
//
#define ICH9_LPC_SMI_F_CPU_HOT_UNPLUG BIT2

//
// Provides a scratch buffer (allocated in EfiReservedMemoryType type memory)
// for the S3 boot script fragment to write to and read from.
//
#pragma pack (1)
typedef union {
UINT64 Features;
UINT8 FeaturesOk;
} SCRATCH_BUFFER;
#pragma pack ()

//
// These carry the selector keys of the "etc/smi/requested-features" and
// "etc/smi/features-ok" fw_cfg files from NegotiateSmiFeatures() to
// AppendFwCfgBootScript().
// "etc/smi/features-ok" fw_cfg files from NegotiateSmiFeatures().
//
STATIC FIRMWARE_CONFIG_ITEM mRequestedFeaturesItem;
STATIC FIRMWARE_CONFIG_ITEM mFeaturesOkItem;

//
// Carries the negotiated SMI features from NegotiateSmiFeatures() to
// AppendFwCfgBootScript().
// Holds the negotiated SMI features from NegotiateSmiFeatures().
//
STATIC UINT64 mSmiFeatures;

/**
Negotiate SMI features with QEMU.
@retval FALSE If SMI feature negotiation is not supported by QEMU. This is
not an error, it just means that SaveSmiFeatures() should not
be called.
@retval FALSE It is not an error if SMI feature negotiation is not supported
by QEMU. It just means the data cannot be used.
@retval TRUE SMI feature negotiation is supported, and it has completed
successfully as well. (Failure to negotiate is a fatal error
and the function never returns in that case.)
successfully as well (failure to negotiate is a fatal error
and the function never returns in that case).
**/
BOOLEAN
NegotiateSmiFeatures (
Expand Down Expand Up @@ -237,96 +223,3 @@ NegotiateSmiFeatures (
//
return FALSE;
}

/**
FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION provided to QemuFwCfgS3Lib.
**/
STATIC
VOID
EFIAPI
AppendFwCfgBootScript (
IN OUT VOID *Context OPTIONAL,
IN OUT VOID *ExternalScratchBuffer
)
{
SCRATCH_BUFFER *ScratchBuffer;
RETURN_STATUS Status;

ScratchBuffer = ExternalScratchBuffer;

//
// Write the negotiated feature bitmap into "etc/smi/requested-features".
//
ScratchBuffer->Features = mSmiFeatures;
Status = QemuFwCfgS3ScriptWriteBytes (
mRequestedFeaturesItem,
sizeof ScratchBuffer->Features
);
if (RETURN_ERROR (Status)) {
goto FatalError;
}

//
// Read back "etc/smi/features-ok". This invokes the feature validation &
// lockdown. (The validation succeeded at first boot.)
//
Status = QemuFwCfgS3ScriptReadBytes (
mFeaturesOkItem,
sizeof ScratchBuffer->FeaturesOk
);
if (RETURN_ERROR (Status)) {
goto FatalError;
}

//
// If "etc/smi/features-ok" read as 1, we're good. Otherwise, hang the S3
// resume process.
//
Status = QemuFwCfgS3ScriptCheckValue (
&ScratchBuffer->FeaturesOk,
sizeof ScratchBuffer->FeaturesOk,
MAX_UINT8,
1
);
if (RETURN_ERROR (Status)) {
goto FatalError;
}

DEBUG ((
DEBUG_VERBOSE,
"%a: SMI feature negotiation boot script saved\n",
__FUNCTION__
));
return;

FatalError:
ASSERT (FALSE);
CpuDeadLoop ();
}

/**
Append a boot script fragment that will re-select the previously negotiated
SMI features during S3 resume.
**/
VOID
SaveSmiFeatures (
VOID
)
{
RETURN_STATUS Status;

//
// We are already running at TPL_CALLBACK, on the stack of
// OnS3SaveStateInstalled(). But that's okay, we can easily queue more
// notification functions while executing a notification function.
//
Status = QemuFwCfgS3CallWhenBootScriptReady (
AppendFwCfgBootScript,
NULL,
sizeof (SCRATCH_BUFFER)
);
if (RETURN_ERROR (Status)) {
ASSERT (FALSE);
CpuDeadLoop ();
}
}
21 changes: 5 additions & 16 deletions Platforms/QemuQ35Pkg/SmmControl2Dxe/SmiFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,27 @@
accordingly.
Copyright (C) 2016-2017, Red Hat, Inc.
Copyright (c) Microsoft Corporation
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef __SMI_FEATURES_H__
#define __SMI_FEATURES_H__

#include <Protocol/S3SaveState.h>

/**
Negotiate SMI features with QEMU.
@retval FALSE If SMI feature negotiation is not supported by QEMU. This is
not an error, it just means that SaveSmiFeatures() should not
be called.
@retval FALSE It is not an error if SMI feature negotiation is not supported
by QEMU. It just means the data cannot be used.
@retval TRUE SMI feature negotiation is supported, and it has completed
successfully as well. (Failure to negotiate is a fatal error
and the function never returns in that case.)
successfully as well (failure to negotiate is a fatal error
and the function never returns in that case).
**/
BOOLEAN
NegotiateSmiFeatures (
VOID
);

/**
Append a boot script fragment that will re-select the previously negotiated
SMI features during S3 resume.
**/
VOID
SaveSmiFeatures (
VOID
);

#endif
Loading

0 comments on commit b22b4e7

Please sign in to comment.