buildroot/boot/edk2/0001-OvmfPkg-QemuVideoDxe-add-feature-PCD-to-remap-frameb.patch
Romain Naour cc0823c2d1 boot/edk2: bump to version edk2-stable202405
Release notes:

  https://github.com/tianocore/edk2/releases/tag/edk2-stable202405

We can't bump to edk2-stable202408 yet due to a runtime issue while
testing qemu_aarch64_sbsa_defconfig following the switch generic
ArmPsciResetSystemLib [1]

  ERROR:   sbsa_sip_smc_handler: unhandled SMC (0xc20000ca) (function id: 202)

Qemu 9.0/9.1 is using a slightly older edk2 firmware based on
edk2-stable202405 release [2] that contains a commit [3] fixing a
bootloader crash produced with qemu_aarch64_sbsa_defconfig [4] since
Qemu 9.0.

From [5]:
"The version of the sbsa-ref EDK2 firmware we used to use in this test
had a bug where it might make an unaligned access to the framebuffer,
which causes a guest crash on newer versions of QEMU where we enforce
the architectural requirement that unaligned accesses to Device memory
should take an exception."

This commit [5] is backported to edk2-stable202405.

For the same reason, we have to update edk2-platforms to a specific
version [6]:

"QemuSbsa: enable WriteCombine for the FrameBuffer
QEMU no longer permits misaligned access to device memory, which breaks
QemuVideoDxe on SbsaQemu.

c1d1910be6e04a8b1a73090cf2881fb698947a6e commit in EDK2 fixed it by
enabling WriteCombine for Framebuffer memory. This change enables that
fix."

As a side note, the edk2-non-osi package does not need to be updated, so
it is left untouched.

Finally, this EDK2 version requires a recent Qemu version. The version
included in the reference Docker image (5.2.0) is too old and will not
allow to start this EDK2 version. Therefore, this bump is known to be
incompatible with runtime tests which are using EDK2 on Aarch64
architecture. At the authoring time of this commit, broken tests are:
- tests.boot.test_edk2
- tests.boot.test_grub.TestGrubAArch64EFI
- tests.package.test_fwts

Note that the EDK2/Qemu incompatibility is only affecting Aarch64
tests. Other tests using EDK2 on i386 or x86_64 are not affected.

To prevent this commit introducing broken runtime tests, those have
been disabled in a previous commit.

[1] 2d0668d399
[2] 24a7cd6a7c
[3] c1d1910be6
[4] https://gitlab.com/buildroot.org/buildroot/-/jobs/7764483764
[5] 6c84daac58
[6] 3f08401365

Fixes:
https://gitlab.com/buildroot.org/buildroot/-/jobs/7764483764

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Waldemar Brodkorb <wbx@openadk.org>
[Julien: add comments in commit log]
Signed-off-by: Julien Olivain <ju.o@free.fr>
2024-11-04 23:03:44 +01:00

130 lines
4.5 KiB
Diff

From 921c78f57a16b00debd58899a48e7045015c374b Mon Sep 17 00:00:00 2001
From: Ard Biesheuvel <ardb@kernel.org>
Date: Mon, 17 Jun 2024 17:07:41 +0200
Subject: [PATCH] OvmfPkg/QemuVideoDxe: add feature PCD to remap framebuffer
W/C
Some platforms (such as SBSA-QEMU on recent builds of the emulator) only
tolerate misaligned accesses to normal memory, and raise alignment
faults on such accesses to device memory, which is the default for PCIe
MMIO BARs.
When emulating a PCIe graphics controller, the framebuffer is typically
exposed via a MMIO BAR, while the disposition of the region is closer to
memory (no side effects on reads or writes, except for the changing
picture on the screen; direct random access to any pixel in the image).
In order to permit the use of such controllers on platforms that only
tolerate these types of accesses for normal memory, it is necessary to
remap the memory. Use the DXE services to set the desired capabilities
and attributes.
Hide this behavior under a feature PCD so only platforms that really
need it can enable it. (OVMF on x86 has no need for this)
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Upstream: https://github.com/tianocore/edk2/commit/c1d1910be6e04a8b1a73090cf2881fb698947a6e
Signed-off-by: Romain Naour <romain.naour@smile.fr>
---
OvmfPkg/OvmfPkg.dec | 5 +++++
OvmfPkg/QemuVideoDxe/Gop.c | 19 +++++++++++++++++++
OvmfPkg/QemuVideoDxe/Qemu.h | 2 +-
OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf | 4 ++++
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 51be9a5959..2c40de8a13 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -444,3 +444,8 @@
## This feature flag indicates the firmware build supports secure boot.
gUefiOvmfPkgTokenSpaceGuid.PcdSecureBootSupported|FALSE|BOOLEAN|0x6d
+
+ ## Whether QemuVideoDxe should perform a EFI_MEMORY_WC remap of the PCI
+ # framebuffer. This might be required on platforms that do not tolerate
+ # misaligned accesses otherwise.
+ gUefiOvmfPkgTokenSpaceGuid.PcdRemapFrameBufferWriteCombine|FALSE|BOOLEAN|0x75
diff --git a/OvmfPkg/QemuVideoDxe/Gop.c b/OvmfPkg/QemuVideoDxe/Gop.c
index b11eed7558..a29c025afd 100644
--- a/OvmfPkg/QemuVideoDxe/Gop.c
+++ b/OvmfPkg/QemuVideoDxe/Gop.c
@@ -9,6 +9,8 @@
#include "Qemu.h"
+#include <Library/DxeServicesTableLib.h>
+
STATIC
VOID
QemuVideoCompleteModeInfo (
@@ -54,6 +56,7 @@ QemuVideoCompleteModeData (
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *FrameBufDesc;
QEMU_VIDEO_MODE_DATA *ModeData;
+ EFI_STATUS Status;
ModeData = &Private->ModeData[Mode->Mode];
Info = Mode->Info;
@@ -79,6 +82,22 @@ QemuVideoCompleteModeData (
(UINT64)Mode->FrameBufferSize
));
+ if (FeaturePcdGet (PcdRemapFrameBufferWriteCombine)) {
+ Status = gDS->SetMemorySpaceCapabilities (
+ FrameBufDesc->AddrRangeMin,
+ FrameBufDesc->AddrLen,
+ EFI_MEMORY_UC | EFI_MEMORY_WC | EFI_MEMORY_XP
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ Status = gDS->SetMemorySpaceAttributes (
+ FrameBufDesc->AddrRangeMin,
+ FrameBufDesc->AddrLen,
+ EFI_MEMORY_WC | EFI_MEMORY_XP
+ );
+ ASSERT_EFI_ERROR (Status);
+ }
+
FreePool (FrameBufDesc);
return EFI_SUCCESS;
}
diff --git a/OvmfPkg/QemuVideoDxe/Qemu.h b/OvmfPkg/QemuVideoDxe/Qemu.h
index 57341a0bbf..a3da725fbf 100644
--- a/OvmfPkg/QemuVideoDxe/Qemu.h
+++ b/OvmfPkg/QemuVideoDxe/Qemu.h
@@ -13,7 +13,7 @@
#ifndef _QEMU_H_
#define _QEMU_H_
-#include <Uefi.h>
+#include <PiDxe.h>
#include <Protocol/GraphicsOutput.h>
#include <Protocol/PciIo.h>
#include <Protocol/DriverSupportedEfiVersion.h>
diff --git a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
index 43a6e07faa..4c0870171b 100644
--- a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
+++ b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
@@ -44,6 +44,7 @@
[LibraryClasses]
BaseMemoryLib
+ DxeServicesTableLib
FrameBufferBltLib
DebugLib
DevicePathLib
@@ -61,6 +62,9 @@
gEfiDevicePathProtocolGuid # PROTOCOL BY_START
gEfiPciIoProtocolGuid # PROTOCOL TO_START
+[FeaturePcd]
+ gUefiOvmfPkgTokenSpaceGuid.PcdRemapFrameBufferWriteCombine
+
[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource
--
2.45.0