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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/** @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 *)(UINTN)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 ();
}
|