Skip to content

Commit

Permalink
Merge pull request #23 from haiwei-li/guest_s3
Browse files Browse the repository at this point in the history
ovmf booted Guest s3 support
  • Loading branch information
lifeix authored Jun 25, 2024
2 parents 786a369 + 146789c commit a2c3bb3
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 2 deletions.
40 changes: 40 additions & 0 deletions OvmfPkg/Include/Library/AcrnS3Lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** @file
S3 support for ACRN
This library class enables driver modules to query whether S3 support was
enabled on ACRN.
Copyright (C) 2024, Intel, Inc.
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License which accompanies this
distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/

#ifndef __ACRN_S3_LIB__
#define __ACRN_S3_LIB__

#include <Base.h>

/**
Determine if S3 support is explicitly enabled.
@retval TRUE If S3 support is explicitly enabled. Other functions in this
library may be called (subject to their individual
restrictions).
FALSE Otherwise. This includes unavailability of the firmware
configuration interface. No other function in this library
must be called.
**/
BOOLEAN
EFIAPI
AcrnS3Enabled (
VOID
);

#endif
39 changes: 39 additions & 0 deletions OvmfPkg/Library/AcrnS3Lib/AcrnS3Lib.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/** @file
S3 Library functions for OVMF on ACRN
Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/

#include <Library/AcrnS3Lib.h>

/**
Determine if S3 support is explicitly enabled.
@retval TRUE If S3 support is explicitly enabled. Other functions in this
library may be called (subject to their individual
restrictions).
FALSE Otherwise. This includes unavailability of the firmware
configuration interface. No other function in this library
must be called.
**/
BOOLEAN
EFIAPI
AcrnS3Enabled (
VOID
)
{
//
// Assumes that ACRN always supports S3.
//
// TODO: AcrnDetected() logic
return TRUE;
}
37 changes: 37 additions & 0 deletions OvmfPkg/Library/AcrnS3Lib/AcrnS3Lib.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## @file
# Library instance for AcrnS3Lib class for OVMF
#
# Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = AcrnS3Lib
FILE_GUID = 4fbe8dc8-eb23-4856-8496-6616f84ee9dd
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = AcrnS3Lib

#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
#

[Sources]
AcrnS3Lib.c

[Packages]
MdePkg/MdePkg.dec
OvmfPkg/OvmfPkg.dec

[LibraryClasses]
DebugLib
3 changes: 2 additions & 1 deletion OvmfPkg/Library/LockBoxLib/LockBoxDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <Library/DebugLib.h>
#include <Library/QemuFwCfgLib.h>
#include <Library/QemuFwCfgS3Lib.h>
#include <Library/AcrnS3Lib.h>
#include <Protocol/LockBox.h>
#include <LockBoxLib.h>

Expand Down Expand Up @@ -123,7 +124,7 @@ LockBoxDxeLibInitialize (

Status = LockBoxLibInitialize ();
if (!EFI_ERROR (Status)) {
if (QemuFwCfgS3Enabled ()) {
if (QemuFwCfgS3Enabled () || AcrnS3Enabled ()) {
//
// When S3 enabled, the first driver run with this library linked will
// have this library constructor to install LockBox protocol on the
Expand Down
1 change: 1 addition & 0 deletions OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
UefiBootServicesTableLib
QemuFwCfgLib
QemuFwCfgS3Lib
AcrnS3Lib

[Protocols]
gEfiLockBoxProtocolGuid ## SOMETIMES_PRODUCES
Expand Down
3 changes: 2 additions & 1 deletion OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <Guid/RootBridgesConnectedEventGroup.h>
#include <Protocol/FirmwareVolume2.h>
#include <Library/Tcg2PhysicalPresenceLib.h>
#include <Library/AcrnS3Lib.h>


//
Expand Down Expand Up @@ -383,7 +384,7 @@ PlatformBootManagerBeforeConsole (
//
EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);

if (QemuFwCfgS3Enabled ()) {
if (QemuFwCfgS3Enabled () || AcrnS3Enabled ()) {
//
// Save the boot script too. Note that this will require us to emit the
// DxeSmmReadyToLock event just below, which in turn locks down SMM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
NvVarsFileLib
QemuFwCfgLib
QemuFwCfgS3Lib
AcrnS3Lib
LoadLinuxLib
QemuBootOrderLib
ReportStatusCodeLib
Expand Down
4 changes: 4 additions & 0 deletions OvmfPkg/OvmfPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
#
QemuFwCfgS3Lib|Include/Library/QemuFwCfgS3Lib.h

## @libraryclass S3 support for ACRN
#
AcrnS3Lib|Include/Library/AcrnS3Lib.h

## @libraryclass Rewrite the BootOrder NvVar based on QEMU's "bootorder"
# fw_cfg file.
#
Expand Down
3 changes: 3 additions & 0 deletions OvmfPkg/OvmfPkgX64.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.inf
MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf
QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
AcrnS3Lib|OvmfPkg/Library/AcrnS3Lib/AcrnS3Lib.inf
PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibNull.inf

Expand Down Expand Up @@ -334,6 +335,7 @@
BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
#PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
AcrnS3Lib|OvmfPkg/Library/AcrnS3Lib/AcrnS3Lib.inf

[LibraryClasses.common.UEFI_DRIVER]
NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf
Expand Down Expand Up @@ -384,6 +386,7 @@
#PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
AcrnS3Lib|OvmfPkg/Library/AcrnS3Lib/AcrnS3Lib.inf
!if $(TPM2_ENABLE) == TRUE
Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf
!endif
Expand Down
7 changes: 7 additions & 0 deletions OvmfPkg/PlatformPei/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <Library/PeiServicesLib.h>
#include <Library/QemuFwCfgLib.h>
#include <Library/QemuFwCfgS3Lib.h>
#include <Library/AcrnS3Lib.h>
#include <Library/ResourcePublicationLib.h>
#include <Guid/MemoryTypeInformation.h>
#include <Ppi/MasterBootMode.h>
Expand Down Expand Up @@ -697,6 +698,12 @@ InitializePlatform (
if (QemuFwCfgS3Enabled ()) {
DEBUG ((EFI_D_INFO, "S3 support was detected on QEMU\n"));
mS3Supported = TRUE;
} else if (AcrnS3Enabled ()) {
DEBUG ((EFI_D_INFO, "S3 support was detected on ACRN\n"));
mS3Supported = TRUE;
}

if (mS3Supported) {
Status = PcdSetBoolS (PcdAcpiS3Enable, TRUE);
ASSERT_EFI_ERROR (Status);
}
Expand Down
1 change: 1 addition & 0 deletions OvmfPkg/PlatformPei/PlatformPei.inf
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
PeimEntryPoint
QemuFwCfgLib
QemuFwCfgS3Lib
AcrnS3Lib
MtrrLib
MemEncryptSevLib
PcdLib
Expand Down

0 comments on commit a2c3bb3

Please sign in to comment.