0001-OvmfPkg-QemuVideoDxe-add-feature-PCD-to-remap-frameb.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. From 921c78f57a16b00debd58899a48e7045015c374b Mon Sep 17 00:00:00 2001
  2. From: Ard Biesheuvel <ardb@kernel.org>
  3. Date: Mon, 17 Jun 2024 17:07:41 +0200
  4. Subject: [PATCH] OvmfPkg/QemuVideoDxe: add feature PCD to remap framebuffer
  5. W/C
  6. Some platforms (such as SBSA-QEMU on recent builds of the emulator) only
  7. tolerate misaligned accesses to normal memory, and raise alignment
  8. faults on such accesses to device memory, which is the default for PCIe
  9. MMIO BARs.
  10. When emulating a PCIe graphics controller, the framebuffer is typically
  11. exposed via a MMIO BAR, while the disposition of the region is closer to
  12. memory (no side effects on reads or writes, except for the changing
  13. picture on the screen; direct random access to any pixel in the image).
  14. In order to permit the use of such controllers on platforms that only
  15. tolerate these types of accesses for normal memory, it is necessary to
  16. remap the memory. Use the DXE services to set the desired capabilities
  17. and attributes.
  18. Hide this behavior under a feature PCD so only platforms that really
  19. need it can enable it. (OVMF on x86 has no need for this)
  20. Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
  21. Upstream: https://github.com/tianocore/edk2/commit/c1d1910be6e04a8b1a73090cf2881fb698947a6e
  22. Signed-off-by: Romain Naour <romain.naour@smile.fr>
  23. ---
  24. OvmfPkg/OvmfPkg.dec | 5 +++++
  25. OvmfPkg/QemuVideoDxe/Gop.c | 19 +++++++++++++++++++
  26. OvmfPkg/QemuVideoDxe/Qemu.h | 2 +-
  27. OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf | 4 ++++
  28. 4 files changed, 29 insertions(+), 1 deletion(-)
  29. diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
  30. index 51be9a5959..2c40de8a13 100644
  31. --- a/OvmfPkg/OvmfPkg.dec
  32. +++ b/OvmfPkg/OvmfPkg.dec
  33. @@ -444,3 +444,8 @@
  34. ## This feature flag indicates the firmware build supports secure boot.
  35. gUefiOvmfPkgTokenSpaceGuid.PcdSecureBootSupported|FALSE|BOOLEAN|0x6d
  36. +
  37. + ## Whether QemuVideoDxe should perform a EFI_MEMORY_WC remap of the PCI
  38. + # framebuffer. This might be required on platforms that do not tolerate
  39. + # misaligned accesses otherwise.
  40. + gUefiOvmfPkgTokenSpaceGuid.PcdRemapFrameBufferWriteCombine|FALSE|BOOLEAN|0x75
  41. diff --git a/OvmfPkg/QemuVideoDxe/Gop.c b/OvmfPkg/QemuVideoDxe/Gop.c
  42. index b11eed7558..a29c025afd 100644
  43. --- a/OvmfPkg/QemuVideoDxe/Gop.c
  44. +++ b/OvmfPkg/QemuVideoDxe/Gop.c
  45. @@ -9,6 +9,8 @@
  46. #include "Qemu.h"
  47. +#include <Library/DxeServicesTableLib.h>
  48. +
  49. STATIC
  50. VOID
  51. QemuVideoCompleteModeInfo (
  52. @@ -54,6 +56,7 @@ QemuVideoCompleteModeData (
  53. EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
  54. EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *FrameBufDesc;
  55. QEMU_VIDEO_MODE_DATA *ModeData;
  56. + EFI_STATUS Status;
  57. ModeData = &Private->ModeData[Mode->Mode];
  58. Info = Mode->Info;
  59. @@ -79,6 +82,22 @@ QemuVideoCompleteModeData (
  60. (UINT64)Mode->FrameBufferSize
  61. ));
  62. + if (FeaturePcdGet (PcdRemapFrameBufferWriteCombine)) {
  63. + Status = gDS->SetMemorySpaceCapabilities (
  64. + FrameBufDesc->AddrRangeMin,
  65. + FrameBufDesc->AddrLen,
  66. + EFI_MEMORY_UC | EFI_MEMORY_WC | EFI_MEMORY_XP
  67. + );
  68. + ASSERT_EFI_ERROR (Status);
  69. +
  70. + Status = gDS->SetMemorySpaceAttributes (
  71. + FrameBufDesc->AddrRangeMin,
  72. + FrameBufDesc->AddrLen,
  73. + EFI_MEMORY_WC | EFI_MEMORY_XP
  74. + );
  75. + ASSERT_EFI_ERROR (Status);
  76. + }
  77. +
  78. FreePool (FrameBufDesc);
  79. return EFI_SUCCESS;
  80. }
  81. diff --git a/OvmfPkg/QemuVideoDxe/Qemu.h b/OvmfPkg/QemuVideoDxe/Qemu.h
  82. index 57341a0bbf..a3da725fbf 100644
  83. --- a/OvmfPkg/QemuVideoDxe/Qemu.h
  84. +++ b/OvmfPkg/QemuVideoDxe/Qemu.h
  85. @@ -13,7 +13,7 @@
  86. #ifndef _QEMU_H_
  87. #define _QEMU_H_
  88. -#include <Uefi.h>
  89. +#include <PiDxe.h>
  90. #include <Protocol/GraphicsOutput.h>
  91. #include <Protocol/PciIo.h>
  92. #include <Protocol/DriverSupportedEfiVersion.h>
  93. diff --git a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
  94. index 43a6e07faa..4c0870171b 100644
  95. --- a/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
  96. +++ b/OvmfPkg/QemuVideoDxe/QemuVideoDxe.inf
  97. @@ -44,6 +44,7 @@
  98. [LibraryClasses]
  99. BaseMemoryLib
  100. + DxeServicesTableLib
  101. FrameBufferBltLib
  102. DebugLib
  103. DevicePathLib
  104. @@ -61,6 +62,9 @@
  105. gEfiDevicePathProtocolGuid # PROTOCOL BY_START
  106. gEfiPciIoProtocolGuid # PROTOCOL TO_START
  107. +[FeaturePcd]
  108. + gUefiOvmfPkgTokenSpaceGuid.PcdRemapFrameBufferWriteCombine
  109. +
  110. [Pcd]
  111. gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
  112. gUefiOvmfPkgTokenSpaceGuid.PcdVideoResolutionSource
  113. --
  114. 2.45.0