mirror of https://github.com/acidanthera/audk.git
OvmfPkg/ResetSystemLib: add driver for microvm
Uses the generic event device to reset and poweroff. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3599 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com>
This commit is contained in:
parent
bf02d73e74
commit
1d3e89f349
|
@ -9,4 +9,11 @@
|
|||
|
||||
#define MICROVM_PSEUDO_DEVICE_ID 0xfff1
|
||||
|
||||
/* generic event device */
|
||||
#define MICROVM_GED_MMIO_BASE 0xfea00000
|
||||
#define MICROVM_GED_MMIO_BASE_REGS (MICROVM_GED_MMIO_BASE + 0x200)
|
||||
#define MICROVM_ACPI_GED_REG_SLEEP_CTL 0x00
|
||||
#define MICROVM_ACPI_GED_REG_RESET 0x02
|
||||
#define MICROVM_ACPI_GED_RESET_VALUE 0x42
|
||||
|
||||
#endif // __MICROVM_H__
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <IndustryStandard/Q35MchIch9.h>
|
||||
#include <IndustryStandard/I440FxPiix4.h>
|
||||
#include <IndustryStandard/Bhyve.h>
|
||||
#include <IndustryStandard/Microvm.h>
|
||||
|
||||
//
|
||||
// OVMF Host Bridge DID Address
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
## @file
|
||||
# DXE library instance for ResetSystem library class for OVMF
|
||||
#
|
||||
# Copyright (C) 2020, Red Hat, Inc.
|
||||
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 1.29
|
||||
BASE_NAME = ResetSystemLibMicrovm
|
||||
FILE_GUID = 7cd630bb-f581-4d1a-97ca-9dbc900e26a4
|
||||
MODULE_TYPE = BASE
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = ResetSystemLib|SEC PEI_CORE PEIM DXE_CORE
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build
|
||||
# tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64
|
||||
#
|
||||
|
||||
[Sources]
|
||||
ResetSystemLibMicrovm.c
|
||||
|
||||
[Packages]
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
OvmfPkg/OvmfPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
IoLib
|
||||
TimerLib
|
|
@ -0,0 +1,49 @@
|
|||
/** @file
|
||||
Reset System Library functions for OVMF
|
||||
|
||||
Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include <Base.h> // BIT1
|
||||
#include <PiDxe.h>
|
||||
|
||||
#include <Library/BaseLib.h> // CpuDeadLoop()
|
||||
#include <Library/DebugLib.h> // ASSERT()
|
||||
#include <Library/DxeServicesTableLib.h>
|
||||
#include <Library/IoLib.h> // IoWrite8()
|
||||
#include <Library/ResetSystemLib.h> // ResetCold()
|
||||
#include <Library/TimerLib.h> // MicroSecondDelay()
|
||||
#include <Library/UefiRuntimeLib.h> // EfiGoneVirtual()
|
||||
#include <OvmfPlatforms.h> // PIIX4_PMBA_VALUE
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
DxeResetSystemLibMicrovmConstructor (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
UINTN Address = MICROVM_GED_MMIO_BASE;
|
||||
EFI_STATUS Status;
|
||||
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
|
||||
|
||||
DEBUG ((DEBUG_INFO, "%a: start\n", __FUNCTION__));
|
||||
|
||||
Status = gDS->GetMemorySpaceDescriptor (Address, &Descriptor);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_INFO, "%a: GetMemorySpaceDescriptor failed\n", __FUNCTION__));
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
Status = gDS->SetMemorySpaceAttributes (Address, SIZE_4KB,
|
||||
Descriptor.Attributes | EFI_MEMORY_RUNTIME);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_INFO, "%a: SetMemorySpaceAttributes failed\n", __FUNCTION__));
|
||||
return RETURN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
DEBUG ((DEBUG_INFO, "%a: done\n", __FUNCTION__));
|
||||
return EFI_SUCCESS;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
## @file
|
||||
# DXE library instance for ResetSystem library class for OVMF
|
||||
#
|
||||
# Copyright (C) 2020, Red Hat, Inc.
|
||||
# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 1.29
|
||||
BASE_NAME = ResetSystemLibMicrovm
|
||||
FILE_GUID = 3d6faf60-804a-4ca9-a36a-1a92416919d0
|
||||
MODULE_TYPE = DXE_RUNTIME_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = ResetSystemLib|DXE_DRIVER DXE_RUNTIME_DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION
|
||||
CONSTRUCTOR = DxeResetSystemLibMicrovmConstructor
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build
|
||||
# tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64
|
||||
#
|
||||
|
||||
[Sources]
|
||||
ResetSystemLibMicrovm.c
|
||||
DxeResetSystemLibMicrovm.c
|
||||
|
||||
[Packages]
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
MdePkg/MdePkg.dec
|
||||
OvmfPkg/OvmfPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
DxeServicesTableLib
|
||||
IoLib
|
||||
TimerLib
|
|
@ -0,0 +1,89 @@
|
|||
/** @file
|
||||
Reset System Library functions for OVMF
|
||||
|
||||
Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include <Base.h> // BIT1
|
||||
|
||||
#include <Library/BaseLib.h> // CpuDeadLoop()
|
||||
#include <Library/DebugLib.h> // ASSERT()
|
||||
#include <Library/IoLib.h> // IoWrite8()
|
||||
#include <Library/ResetSystemLib.h> // ResetCold()
|
||||
#include <Library/TimerLib.h> // MicroSecondDelay()
|
||||
#include <Library/UefiRuntimeLib.h> // EfiGoneVirtual()
|
||||
#include <OvmfPlatforms.h> // PIIX4_PMBA_VALUE
|
||||
|
||||
static UINTN MicrovmGedBase (VOID)
|
||||
{
|
||||
VOID *Address = (VOID*) MICROVM_GED_MMIO_BASE_REGS;
|
||||
|
||||
if (EfiGoneVirtual ()) {
|
||||
EfiConvertPointer (0, &Address);
|
||||
DEBUG ((DEBUG_INFO, "%a: virtual -> 0x%x\n", __FUNCTION__, Address));
|
||||
} else {
|
||||
DEBUG ((DEBUG_INFO, "%a: physical -> 0x%x\n", __FUNCTION__, Address));
|
||||
}
|
||||
|
||||
return (UINTN) Address;
|
||||
}
|
||||
|
||||
static VOID MicrovmReset (VOID)
|
||||
{
|
||||
UINTN Address = MicrovmGedBase();
|
||||
|
||||
DEBUG ((DEBUG_INFO, "%a: microvm reset via ged\n", __FUNCTION__));
|
||||
MmioWrite8 (Address + MICROVM_ACPI_GED_REG_RESET,
|
||||
MICROVM_ACPI_GED_RESET_VALUE);
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
static VOID MicrovmShutdown (VOID)
|
||||
{
|
||||
UINTN Address = MicrovmGedBase();
|
||||
|
||||
DEBUG ((DEBUG_INFO, "%a: microvm poweroff via ged\n", __FUNCTION__));
|
||||
MmioWrite8 (Address + MICROVM_ACPI_GED_REG_SLEEP_CTL,
|
||||
(1 << 5) /* enable bit */ |
|
||||
(5 << 2) /* typ == S5 */);
|
||||
CpuDeadLoop ();
|
||||
}
|
||||
|
||||
VOID EFIAPI ResetCold (VOID)
|
||||
{
|
||||
MicrovmReset();
|
||||
}
|
||||
|
||||
VOID EFIAPI ResetWarm (VOID)
|
||||
{
|
||||
MicrovmReset();
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ResetPlatformSpecific (
|
||||
IN UINTN DataSize,
|
||||
IN VOID *ResetData
|
||||
)
|
||||
{
|
||||
MicrovmReset();
|
||||
}
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
ResetSystem (
|
||||
IN EFI_RESET_TYPE ResetType,
|
||||
IN EFI_STATUS ResetStatus,
|
||||
IN UINTN DataSize,
|
||||
IN VOID *ResetData OPTIONAL
|
||||
)
|
||||
{
|
||||
MicrovmReset();
|
||||
}
|
||||
|
||||
VOID EFIAPI ResetShutdown (VOID)
|
||||
{
|
||||
MicrovmShutdown();
|
||||
}
|
|
@ -128,7 +128,7 @@
|
|||
[LibraryClasses]
|
||||
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
|
||||
TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/BaseResetSystemLibMicrovm.inf
|
||||
PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
|
||||
BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf
|
||||
BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
|
||||
|
@ -318,7 +318,7 @@
|
|||
|
||||
[LibraryClasses.common.DXE_RUNTIME_DRIVER]
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf
|
||||
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
|
||||
DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
|
||||
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
|
||||
|
@ -336,7 +336,7 @@
|
|||
|
||||
[LibraryClasses.common.UEFI_DRIVER]
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf
|
||||
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
|
||||
DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
|
||||
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
|
||||
|
@ -351,7 +351,7 @@
|
|||
|
||||
[LibraryClasses.common.DXE_DRIVER]
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf
|
||||
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
|
||||
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
|
||||
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
|
||||
|
@ -376,7 +376,7 @@
|
|||
|
||||
[LibraryClasses.common.UEFI_APPLICATION]
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf
|
||||
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
|
||||
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
|
||||
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
|
||||
|
@ -389,7 +389,7 @@
|
|||
|
||||
[LibraryClasses.common.DXE_SMM_DRIVER]
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf
|
||||
MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf
|
||||
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
|
||||
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
|
||||
|
@ -410,7 +410,7 @@
|
|||
|
||||
[LibraryClasses.common.SMM_CORE]
|
||||
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf
|
||||
ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.inf
|
||||
SmmCorePlatformHookLib|MdeModulePkg/Library/SmmCorePlatformHookLibNull/SmmCorePlatformHookLibNull.inf
|
||||
MemoryAllocationLib|MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.inf
|
||||
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
|
||||
|
|
|
@ -161,6 +161,7 @@ MemMapInitialization (
|
|||
AddIoMemoryRangeHob (0x0A0000, BASE_1MB);
|
||||
|
||||
if (mHostBridgeDevId == 0xffff /* microvm */) {
|
||||
AddIoMemoryBaseSizeHob (MICROVM_GED_MMIO_BASE, SIZE_4KB);
|
||||
AddIoMemoryBaseSizeHob (0xFEC00000, SIZE_4KB); /* ioapic #1 */
|
||||
AddIoMemoryBaseSizeHob (0xFEC10000, SIZE_4KB); /* ioapic #2 */
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue