VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/ResetSystemLib/DxeResetShutdownXen.c

Last change on this file was 108794, checked in by vboxsync, 3 weeks ago

Devices/EFI/FirmwareNew: Merge edk2-stable202502 from the vendor branch and make it build for the important platforms, bugref:4643

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1/** @file
2 DXE Reset System Library Shutdown API implementation for OVMF.
3
4 Copyright (C) 2020, Red Hat, Inc.
5 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7**/
8
9#include <Base.h> // BIT13
10
11#include <IndustryStandard/Xen/sched.h>
12#include <Library/BaseLib.h> // CpuDeadLoop()
13#include <Library/DebugLib.h> // ASSERT()
14#include <Library/IoLib.h> // IoOr16()
15#include <Library/PcdLib.h> // PcdGet16()
16#include <Library/ResetSystemLib.h> // ResetShutdown()
17#include <Library/XenHypercallLib.h>
18#include <OvmfPlatforms.h> // PIIX4_PMBA_VALUE
19
20STATIC UINT16 mAcpiPmBaseAddress;
21
22EFI_STATUS
23EFIAPI
24DxeResetInit (
25 IN EFI_HANDLE ImageHandle,
26 IN EFI_SYSTEM_TABLE *SystemTable
27 )
28{
29 UINT16 HostBridgeDevId;
30
31 HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);
32 switch (HostBridgeDevId) {
33 case INTEL_82441_DEVICE_ID:
34 mAcpiPmBaseAddress = PIIX4_PMBA_VALUE;
35 break;
36 case INTEL_Q35_MCH_DEVICE_ID:
37 mAcpiPmBaseAddress = ICH9_PMBASE_VALUE;
38 break;
39 default:
40 //
41 // Fallback to using hypercall.
42 // Necessary for PVH guest, but should work for HVM guest.
43 //
44 mAcpiPmBaseAddress = 0xffff;
45 break;
46 }
47
48 return EFI_SUCCESS;
49}
50
51/**
52 Calling this function causes the system to enter a power state equivalent
53 to the ACPI G2/S5 or G3 states.
54
55 System shutdown should not return, if it returns, it means the system does
56 not support shut down reset.
57**/
58VOID
59EFIAPI
60ResetShutdown (
61 VOID
62 )
63{
64 if (mAcpiPmBaseAddress != 0xffff) {
65 IoBitFieldWrite16 (mAcpiPmBaseAddress + 4, 10, 13, 0);
66 IoOr16 (mAcpiPmBaseAddress + 4, BIT13);
67 } else {
68 INTN ReturnCode;
69 XEN_SCHED_SHUTDOWN ShutdownOp = {
70 .Reason = XEN_SHED_SHUTDOWN_POWEROFF,
71 };
72 ReturnCode = XenHypercallSchedOp (XEN_SCHEDOP_SHUTDOWN, &ShutdownOp);
73 ASSERT (ReturnCode == 0);
74 }
75
76 CpuDeadLoop ();
77}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette