From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.81]) by mx.groups.io with SMTP id smtpd.web10.271.1587140600692773082 for ; Fri, 17 Apr 2020 09:23:20 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NJXFkMZf; spf=pass (domain: redhat.com, ip: 207.211.31.81, mailfrom: philmd@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587140599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9BuXtR76O/eYCiZaJl7X0Tty3NGVsDdcUv/rUJa5WHQ=; b=NJXFkMZf8VOGY24RyHs65pwxwqdWq8oIrshZT5sk8/q7VhPrUcjeOYRoxd3PEjZd9iSJnt YvY+IIwQrxHOf0mym1EG/XLxxJcfNESnceoaXri2EHi2UWPtOKjyS3bBSYWpLqrMXnvbeU YdalC4bxQyaqBk7ck+w+BSg9fdNUW1s= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-277-yGQNZh8EMDevmzSb0CVDCg-1; Fri, 17 Apr 2020 12:23:17 -0400 X-MC-Unique: yGQNZh8EMDevmzSb0CVDCg-1 Received: by mail-ed1-f72.google.com with SMTP id b7so949347edz.9 for ; Fri, 17 Apr 2020 09:23:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=fdTDuBECRMQK9rlUZF3ICtSwIPBDT0wQqnIGxdIcMeY=; b=nlaLGCS0gnEL2pKd0BBfUVmEIob/+oD1ckhkQudfdXUqMq9NL7RLRHKhSACJ1K/9/c 5vwvj8XkbxjBQykeGSSXpPeAtIH/CroOXIZeQvxlGg8AYh0e5smLHJAuP6HSHZx+y8Y8 oKSXLyrmqpXD21VJd3e957VKF58J7PdXY/c7yYiXDKsrGguK+Orfo3o2rXeRTDosTYYt ASMe8Kz1c7eJn8Aw1UyvQ1XGSlRv+8Hq6N5BX4YeXtDnLtpf65ulFtGyZvN4Vft9osef +BWXfdXzyoKqkuHzqqxyWO852emhF5hJknJbtz4Vi1mHVchLxHiDReOm/eD4JqAR2B12 YSnA== X-Gm-Message-State: AGi0PuZkQiWSoB2vzLHsM6Hq4EuHBFidrTqzHbaEjEOKzhB+UCrB2tqf hN5J03Q5dk+Fp4Wpphr7k2D6aNwgLc0W0fsDV33dn5TVZpKF5EZ34PNyh45BsmC317Yo/RdlnPr BSK8T7y1kR40a1Q== X-Received: by 2002:aa7:c64a:: with SMTP id z10mr3834986edr.126.1587140596385; Fri, 17 Apr 2020 09:23:16 -0700 (PDT) X-Google-Smtp-Source: APiQypK6DdTin8VPr7Kzc9DpFEdosrcAQP+tzietDp40WgfSjSl21ukexUmsAWr8h0zE60fEIPupVQ== X-Received: by 2002:aa7:c64a:: with SMTP id z10mr3834968edr.126.1587140596083; Fri, 17 Apr 2020 09:23:16 -0700 (PDT) Return-Path: Received: from [192.168.1.39] (116.red-83-42-57.dynamicip.rima-tde.net. [83.42.57.116]) by smtp.gmail.com with ESMTPSA id l91sm2933911ede.64.2020.04.17.09.23.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Apr 2020 09:23:15 -0700 (PDT) Subject: Re: [PATCH 6/6] OvmfPkg/ResetSystemLib: introduce the DxeResetSystemLib instance To: Laszlo Ersek , edk2-devel-groups-io Cc: Anthony Perard , Ard Biesheuvel , Jordan Justen , Julien Grall , Rebecca Cran References: <20200417153751.7110-1-lersek@redhat.com> <20200417153751.7110-7-lersek@redhat.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Message-ID: <4cc7f027-5595-c7ea-5bd5-1c79c23734a8@redhat.com> Date: Fri, 17 Apr 2020 18:23:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200417153751.7110-7-lersek@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 4/17/20 5:37 PM, Laszlo Ersek wrote: > The BaseResetSystemLib instance is not suitable for OS runtime, because > its ResetShutdown() implementation calls PciRead16 (OVMF_HOSTBRIDGE_DID). > On q35, this boils down to a memory-mapped config space access -- but we > never ask the OS to map MMCONFIG for runtime. >=20 > There are at least three alternatives to approach this: >=20 > (1) Investigate "MdePkg/Library/DxeRuntimePciExpressLib", which offers > some kind of runtime mapping for MMCONFIG. >=20 > (2) Consume PciCf8Lib directly, rather than PciLib, in ResetSystemLib. > Then we'll read OVMF_HOSTBRIDGE_DID from the config space with IO po= rt > accesses on q35 too, not just on i440fx. IO ports don't depend on pa= ge > tables. >=20 > (3) In the lib constructor, cache "mAcpiPmBaseAddress" based on > "PcdOvmfHostBridgePciDevId" (which is set by PlatformPei). Then the > host bridge type will be known at runtime without PCI config space > accesses. >=20 > This patch follows approach (3), in order to mirror AcpiTimerLib. Reviewed-by: Philippe Mathieu-Daude >=20 > Notes: >=20 > * This patch is best viewed with "git show --find-copies-harder -C43". >=20 > * PCDs are not usable in the DXE_CORE, as the PCD PPI is gone, and the PC= D > protocol is not available yet. (The DXE_CORE does consume ResetSystemL= ib > in practice, when OVMF is built with -D SOURCE_DEBUG_ENABLE.) >=20 > * The bug is not easy to trigger in common setups, because e.g. the Linux > guest cannot easily be convinced to use the EFI runtime service for > poweroff. One way to trigger the bug is to (a) patch OVMF as follows: >=20 >> diff --git a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c b/OvmfPkg/L= ibrary/ResetSystemLib/ResetSystemLib.c >> index fe51f53d1df2..1edc4349ad20 100644 >> --- a/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c >> +++ b/OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c >> @@ -28,6 +28,7 @@ ResetCold ( >> VOID >> ) >> { >> + ResetShutdown (); >> IoWrite8 (0xCF9, BIT2 | BIT1); // 1st choice: PIIX3 RCR, RCPU|SRST >> MicroSecondDelay (50); >=20 > (b) boot a Linux guest with "reboot=3Defi" on q35, and (c) reboot the > guest with the "reboot" command. Then the guest kernel will log: >=20 >> reboot: Restarting system >> reboot: machine restart >> ------------[ cut here ]------------ >> [Firmware Bug]: Page fault caused by firmware at PA: 0xb0000002 >> WARNING: CPU: 0 PID: 1362 at arch/x86/platform/efi/quirks.c:738 >> efi_recover_from_page_fault+0x2a/0xc8 >> Modules linked in: ip_set nfnetlink sunrpc vfat fat intel_rapl_msr >> intel_rapl_common kvm_intel kvm irqbypass crct10dif_pclmul crc32_pclmul >> bochs_drm drm_vram_helper ttm ghash_clmulni_intel drm_kms_helper >> iTCO_wdt iTCO_vendor >> CPU: 0 PID: 1362 Comm: reboot Not tainted 5.3.6-200.fc30.x86_64 #1 >> Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 >> 02/06/2015 >> RIP: 0010:efi_recover_from_page_fault+0x2a/0xc8 >> Code: 0f 1f 44 00 00 8b 15 35 c2 c1 01 85 d2 74 09 48 81 ff ff 0f 00 00 >> 77 01 c3 53 48 89 fe 48 c7 c7 58 ba 12 aa 50 e8 74 f0 00 00 <0f> 0b 83 >> 3d 0d c2 c1 01 0a 0f 84 8f 00 00 00 48 8b 05 70 c8 4a 01 >> RSP: 0018:ffffaf3a402539d8 EFLAGS: 00010286 >> RAX: 0000000000000000 RBX: ffff8a3c33711f40 RCX: 00000000000003b2 >> RDX: 0000000000000001 RSI: 0000000000000096 RDI: 0000000000000246 >> RBP: ffffaf3a40253a88 R08: 0000000000000000 R09: 00000000000003b2 >> R10: 0000000000000001 R11: ffffffffa9ee3800 R12: 00000000b0000002 >> R13: 0000000000000000 R14: 000000000000000b R15: 0000000000000001 >> FS: 00007fbca9cf8940(0000) GS:ffff8a3c3ae00000(0000) >> knlGS:0000000000000000 >> CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 >> CR2: fffffffeff8a67a1 CR3: 0000000072868006 CR4: 00000000001606f0 >> Call Trace: >> no_context+0x15b/0x380 >> ? do_user_addr_fault+0x12e/0x440 >> do_page_fault+0x31/0x110 >> async_page_fault+0x3e/0x50 >> RIP: 0010:0xfffffffeff8a67a1 >> Code: Bad RIP value. >> RSP: 0018:ffffaf3a40253b30 EFLAGS: 00010046 >> RAX: 00000000b0000002 RBX: 0000000000000000 RCX: 00000000b0000002 >> RDX: 00000000b0000000 RSI: 0000000000000000 RDI: fffffffeff8a80f0 >> RBP: ffffaf3a40253b60 R08: fffffffeff8aadb8 R09: 0000000000000000 >> R10: ffffffffaa5762c0 R11: ffffffffa9ee3800 R12: 0000000000000000 >> R13: 0000000000000000 R14: 0000000000000046 R15: 0000000000000000 >> ? efi_call+0x58/0x90 >> ? virt_efi_reset_system+0x8d/0x100 >> ? efi_reboot+0x85/0xb8 >> ? native_machine_emergency_restart+0x9f/0x250 >> ? native_apic_msr_read+0x16/0x20 >> ? disconnect_bsp_APIC+0x8c/0xd0 >> ? __do_sys_reboot+0x1d2/0x210 >> ? __fput+0x168/0x250 >> ? do_writev+0x6b/0x110 >> ? do_syscall_64+0x5f/0x1a0 >> ? entry_SYSCALL_64_after_hwframe+0x44/0xa9 >> ---[ end trace d5bee708166d198b ]--- >> efi: efi_reset_system() buggy! Reboot through BIOS >=20 > Cc: Anthony Perard > Cc: Ard Biesheuvel > Cc: Jordan Justen > Cc: Julien Grall > Cc: Philippe Mathieu-Daud=C3=A9 > Cc: Rebecca Cran > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2675 > Signed-off-by: Laszlo Ersek > --- > OvmfPkg/OvmfPkgIa32.dsc = | 6 +++ > OvmfPkg/OvmfPkgIa32X64.dsc = | 6 +++ > OvmfPkg/OvmfPkgX64.dsc = | 6 +++ > OvmfPkg/OvmfXen.dsc = | 4 ++ > OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf = | 2 +- > OvmfPkg/Library/ResetSystemLib/{BaseResetSystemLib.inf =3D> DxeResetSys= temLib.inf} | 21 +++++---- > OvmfPkg/Library/ResetSystemLib/{BaseResetShutdown.c =3D> DxeResetShutdo= wn.c} | 49 ++++++++++++-------- > 7 files changed, 66 insertions(+), 28 deletions(-) >=20 > diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc > index cd0ed34e0e5a..d5e90c001370 100644 > --- a/OvmfPkg/OvmfPkgIa32.dsc > +++ b/OvmfPkg/OvmfPkgIa32.dsc > @@ -314,6 +314,7 @@ [LibraryClasses.common.DXE_CORE] > [LibraryClasses.common.DXE_RUNTIME_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.= inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > @@ -331,6 +332,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] > [LibraryClasses.common.UEFI_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.= inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > @@ -346,6 +348,7 @@ [LibraryClasses.common.UEFI_DRIVER] > [LibraryClasses.common.DXE_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > @@ -383,6 +386,7 @@ [LibraryClasses.common.DXE_DRIVER] > [LibraryClasses.common.UEFI_APPLICATION] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > @@ -396,6 +400,7 @@ [LibraryClasses.common.UEFI_APPLICATION] > [LibraryClasses.common.DXE_SMM_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAl= locationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > @@ -417,6 +422,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] > [LibraryClasses.common.SMM_CORE] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > SmmCorePlatformHookLib|MdeModulePkg/Library/SmmCorePlatformHookLibNul= l/SmmCorePlatformHookLibNull.inf > MemoryAllocationLib|MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib= /PiSmmCoreMemoryAllocationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc > index 3c377c6e858e..066f49aeaee0 100644 > --- a/OvmfPkg/OvmfPkgIa32X64.dsc > +++ b/OvmfPkg/OvmfPkgIa32X64.dsc > @@ -318,6 +318,7 @@ [LibraryClasses.common.DXE_CORE] > [LibraryClasses.common.DXE_RUNTIME_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.= inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > @@ -335,6 +336,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] > [LibraryClasses.common.UEFI_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.= inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > @@ -350,6 +352,7 @@ [LibraryClasses.common.UEFI_DRIVER] > [LibraryClasses.common.DXE_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > @@ -387,6 +390,7 @@ [LibraryClasses.common.DXE_DRIVER] > [LibraryClasses.common.UEFI_APPLICATION] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > @@ -400,6 +404,7 @@ [LibraryClasses.common.UEFI_APPLICATION] > [LibraryClasses.common.DXE_SMM_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAl= locationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > @@ -421,6 +426,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] > [LibraryClasses.common.SMM_CORE] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > SmmCorePlatformHookLib|MdeModulePkg/Library/SmmCorePlatformHookLibNul= l/SmmCorePlatformHookLibNull.inf > MemoryAllocationLib|MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib= /PiSmmCoreMemoryAllocationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc > index 701a7ccea987..ac510522a9ff 100644 > --- a/OvmfPkg/OvmfPkgX64.dsc > +++ b/OvmfPkg/OvmfPkgX64.dsc > @@ -318,6 +318,7 @@ [LibraryClasses.common.DXE_CORE] > [LibraryClasses.common.DXE_RUNTIME_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.= inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > @@ -335,6 +336,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] > [LibraryClasses.common.UEFI_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.= inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > @@ -350,6 +352,7 @@ [LibraryClasses.common.UEFI_DRIVER] > [LibraryClasses.common.DXE_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > @@ -387,6 +390,7 @@ [LibraryClasses.common.DXE_DRIVER] > [LibraryClasses.common.UEFI_APPLICATION] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > @@ -400,6 +404,7 @@ [LibraryClasses.common.UEFI_APPLICATION] > [LibraryClasses.common.DXE_SMM_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAl= locationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > @@ -421,6 +426,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] > [LibraryClasses.common.SMM_CORE] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > SmmCorePlatformHookLib|MdeModulePkg/Library/SmmCorePlatformHookLibNul= l/SmmCorePlatformHookLibNull.inf > MemoryAllocationLib|MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib= /PiSmmCoreMemoryAllocationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc > index 86b24d1716b9..f6214bd3465a 100644 > --- a/OvmfPkg/OvmfXen.dsc > +++ b/OvmfPkg/OvmfXen.dsc > @@ -288,6 +288,7 @@ [LibraryClasses.common.DXE_CORE] > =20 > [LibraryClasses.common.DXE_RUNTIME_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.= inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > @@ -304,6 +305,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] > =20 > [LibraryClasses.common.UEFI_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.= inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > @@ -318,6 +320,7 @@ [LibraryClasses.common.UEFI_DRIVER] > =20 > [LibraryClasses.common.DXE_DRIVER] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > @@ -341,6 +344,7 @@ [LibraryClasses.common.DXE_DRIVER] > =20 > [LibraryClasses.common.UEFI_APPLICATION] > PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf > + ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf > MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemory= AllocationLib.inf > ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRe= portStatusCodeLib.inf > diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf b/Ovmf= Pkg/Library/ResetSystemLib/BaseResetSystemLib.inf > index 0772780b2dc2..35d317f1e0b3 100644 > --- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf > +++ b/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf > @@ -12,7 +12,7 @@ [Defines] > FILE_GUID =3D 66564872-21d4-4d2a-a68b-1e844f9808= 20 > MODULE_TYPE =3D BASE > VERSION_STRING =3D 1.0 > - LIBRARY_CLASS =3D ResetSystemLib > + LIBRARY_CLASS =3D ResetSystemLib|SEC PEI_CORE PEIM DX= E_CORE > =20 > # > # The following information is for reference only and not required by t= he build > diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf b/Ovmf= Pkg/Library/ResetSystemLib/DxeResetSystemLib.inf > similarity index 43% > copy from OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf > copy to OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > index 0772780b2dc2..a9b4ce90000a 100644 > --- a/OvmfPkg/Library/ResetSystemLib/BaseResetSystemLib.inf > +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf > @@ -1,18 +1,20 @@ > ## @file > -# Base library instance for ResetSystem library class for OVMF > +# DXE library instance for ResetSystem library class for OVMF > # > +# Copyright (C) 2020, Red Hat, Inc. > # Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. > # SPDX-License-Identifier: BSD-2-Clause-Patent > # > ## > =20 > [Defines] > - INF_VERSION =3D 0x00010005 > - BASE_NAME =3D BaseResetSystemLib > - FILE_GUID =3D 66564872-21d4-4d2a-a68b-1e844f98082= 0 > - MODULE_TYPE =3D BASE > + INF_VERSION =3D 1.29 > + BASE_NAME =3D DxeResetSystemLib > + FILE_GUID =3D bc7835ea-4094-41fe-b770-bad9e6c479b= 2 > + MODULE_TYPE =3D DXE_DRIVER > VERSION_STRING =3D 1.0 > - LIBRARY_CLASS =3D ResetSystemLib > + LIBRARY_CLASS =3D ResetSystemLib|DXE_DRIVER DXE_RUNTI= ME_DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION > + CONSTRUCTOR =3D DxeResetInit > =20 > # > # The following information is for reference only and not required by t= he build > @@ -22,7 +24,7 @@ [Defines] > # > =20 > [Sources] > - BaseResetShutdown.c > + DxeResetShutdown.c > ResetSystemLib.c > =20 > [Packages] > @@ -34,5 +36,8 @@ [LibraryClasses] > BaseLib > DebugLib > IoLib > - PciLib > + PcdLib > TimerLib > + > +[Pcd] > + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId ## CONSUMES > diff --git a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c b/OvmfPkg= /Library/ResetSystemLib/DxeResetShutdown.c > similarity index 57% > copy from OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c > copy to OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c > index 21c80e43230c..5a75c32df361 100644 > --- a/OvmfPkg/Library/ResetSystemLib/BaseResetShutdown.c > +++ b/OvmfPkg/Library/ResetSystemLib/DxeResetShutdown.c > @@ -1,5 +1,5 @@ > /** @file > - Base Reset System Library Shutdown API implementation for OVMF. > + DXE Reset System Library Shutdown API implementation for OVMF. > =20 > Copyright (C) 2020, Red Hat, Inc. > Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved. > @@ -11,41 +11,52 @@ > #include // CpuDeadLoop() > #include // ASSERT() > #include // IoOr16() > -#include // PciRead16() > +#include // PcdGet16() > #include // ResetShutdown() > -#include // OVMF_HOSTBRIDGE_DID > +#include // PIIX4_PMBA_VALUE > =20 > -/** > - Calling this function causes the system to enter a power state equival= ent > - to the ACPI G2/S5 or G3 states. > +STATIC UINT16 mAcpiPmBaseAddress; > =20 > - System shutdown should not return, if it returns, it means the system = does > - not support shut down reset. > -**/ > -VOID > +EFI_STATUS > EFIAPI > -ResetShutdown ( > - VOID > +DxeResetInit ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > ) > { > - UINT16 AcpiPmBaseAddress; > UINT16 HostBridgeDevId; > =20 > - AcpiPmBaseAddress =3D 0; > - HostBridgeDevId =3D PciRead16 (OVMF_HOSTBRIDGE_DID); > + HostBridgeDevId =3D PcdGet16 (PcdOvmfHostBridgePciDevId); > switch (HostBridgeDevId) { > case INTEL_82441_DEVICE_ID: > - AcpiPmBaseAddress =3D PIIX4_PMBA_VALUE; > + mAcpiPmBaseAddress =3D PIIX4_PMBA_VALUE; > break; > case INTEL_Q35_MCH_DEVICE_ID: > - AcpiPmBaseAddress =3D ICH9_PMBASE_VALUE; > + mAcpiPmBaseAddress =3D ICH9_PMBASE_VALUE; > break; > default: > ASSERT (FALSE); > CpuDeadLoop (); > + return EFI_UNSUPPORTED; > } > =20 > - IoBitFieldWrite16 (AcpiPmBaseAddress + 4, 10, 13, 0); > - IoOr16 (AcpiPmBaseAddress + 4, BIT13); > + return EFI_SUCCESS; > +} > + > +/** > + Calling this function causes the system to enter a power state equival= ent > + to the ACPI G2/S5 or G3 states. > + > + System shutdown should not return, if it returns, it means the system = does > + not support shut down reset. > +**/ > +VOID > +EFIAPI > +ResetShutdown ( > + VOID > + ) > +{ > + IoBitFieldWrite16 (mAcpiPmBaseAddress + 4, 10, 13, 0); > + IoOr16 (mAcpiPmBaseAddress + 4, BIT13); > CpuDeadLoop (); > } >=20