summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLibMicrovm.c
blob: 0de8b39f54086a2c59d1ae51f51550d7c197ed21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
}