From 1d3e89f3490f05a20df0470a21767d063587a596 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 8 Sep 2021 11:01:14 +0200 Subject: 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 Acked-by: Jiewen Yao --- .../ResetSystemLib/DxeResetSystemLibMicrovm.c | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c (limited to 'OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c') diff --git a/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c new file mode 100644 index 0000000000..0de8b39f54 --- /dev/null +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c @@ -0,0 +1,49 @@ +/** @file + Reset System Library functions for OVMF + + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include // BIT1 +#include + +#include // CpuDeadLoop() +#include // ASSERT() +#include +#include // IoWrite8() +#include // ResetCold() +#include // MicroSecondDelay() +#include // EfiGoneVirtual() +#include // 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; +} -- cgit v1.2.3