|
|
5c789a |
From 4c7e315ccb97dd7c3dc7f38e22b84ffbc4df90e3 Mon Sep 17 00:00:00 2001
|
|
|
5c789a |
From: Laszlo Ersek <lersek@redhat.com>
|
|
|
5c789a |
Date: Fri, 18 May 2018 21:40:24 +0200
|
|
|
5c789a |
Subject: [PATCH 5/5] OvmfPkg/PlatformBootManagerLib: connect Virtio RNG
|
|
|
5c789a |
devices again
|
|
|
5c789a |
|
|
|
5c789a |
Message-id: <20180518194024.30614-3-lersek@redhat.com>
|
|
|
5c789a |
Patchwork-id: 80427
|
|
|
5c789a |
O-Subject: [RHEL-7.6 ovmf PATCH 2/2] OvmfPkg/PlatformBootManagerLib: connect
|
|
|
5c789a |
Virtio RNG devices again
|
|
|
5c789a |
Bugzilla: 1579518
|
|
|
5c789a |
Acked-by: Thomas Huth <thuth@redhat.com>
|
|
|
5c789a |
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
5c789a |
|
|
|
5c789a |
Virtio RNG devices are never boot devices, so in commit 245c643cc8b7 we
|
|
|
5c789a |
stopped connecting them. This is a problem because an OS boot loader may
|
|
|
5c789a |
depend on EFI_RNG_PROTOCOL to seed the OS's RNG.
|
|
|
5c789a |
|
|
|
5c789a |
Connect Virtio RNG devices again. And, while commit 245c643cc8b7 removed
|
|
|
5c789a |
that from PlatformBootManagerAfterConsole(), reintroduce it now to
|
|
|
5c789a |
PlatformBootManagerBeforeConsole() -- this way Driver#### options launched
|
|
|
5c789a |
between both functions may access EFI_RNG_PROTOCOL too.
|
|
|
5c789a |
|
|
|
5c789a |
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
|
|
|
5c789a |
Cc: Jordan Justen <jordan.l.justen@intel.com>
|
|
|
5c789a |
Fixes: 245c643cc8b73240c3b88cb55b2911b285a8c10d
|
|
|
5c789a |
Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1579518
|
|
|
5c789a |
Contributed-under: TianoCore Contribution Agreement 1.1
|
|
|
5c789a |
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
5c789a |
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
|
|
|
5c789a |
(cherry picked from commit 7ebad830d6ab61f0395f6f4bae4156664bbd8086)
|
|
|
5c789a |
---
|
|
|
5c789a |
.../Library/PlatformBootManagerLib/BdsPlatform.c | 105 +++++++++++++++++++++
|
|
|
5c789a |
.../Library/PlatformBootManagerLib/BdsPlatform.h | 1 +
|
|
|
5c789a |
2 files changed, 106 insertions(+)
|
|
|
5c789a |
|
|
|
5c789a |
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
|
|
|
5c789a |
index 004b753..5d4d323 100644
|
|
|
5c789a |
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
|
|
|
5c789a |
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
|
|
|
5c789a |
@@ -319,6 +319,15 @@ ConnectRootBridge (
|
|
|
5c789a |
);
|
|
|
5c789a |
|
|
|
5c789a |
STATIC
|
|
|
5c789a |
+EFI_STATUS
|
|
|
5c789a |
+EFIAPI
|
|
|
5c789a |
+ConnectVirtioPciRng (
|
|
|
5c789a |
+ IN EFI_HANDLE Handle,
|
|
|
5c789a |
+ IN VOID *Instance,
|
|
|
5c789a |
+ IN VOID *Context
|
|
|
5c789a |
+ );
|
|
|
5c789a |
+
|
|
|
5c789a |
+STATIC
|
|
|
5c789a |
VOID
|
|
|
5c789a |
SaveS3BootScript (
|
|
|
5c789a |
VOID
|
|
|
5c789a |
@@ -399,6 +408,13 @@ PlatformBootManagerBeforeConsole (
|
|
|
5c789a |
ASSERT_RETURN_ERROR (PcdStatus);
|
|
|
5c789a |
|
|
|
5c789a |
PlatformRegisterOptionsAndKeys ();
|
|
|
5c789a |
+
|
|
|
5c789a |
+ //
|
|
|
5c789a |
+ // Install both VIRTIO_DEVICE_PROTOCOL and (dependent) EFI_RNG_PROTOCOL
|
|
|
5c789a |
+ // instances on Virtio PCI RNG devices.
|
|
|
5c789a |
+ //
|
|
|
5c789a |
+ VisitAllInstancesOfProtocol (&gEfiPciIoProtocolGuid, ConnectVirtioPciRng,
|
|
|
5c789a |
+ NULL);
|
|
|
5c789a |
}
|
|
|
5c789a |
|
|
|
5c789a |
|
|
|
5c789a |
@@ -427,6 +443,95 @@ ConnectRootBridge (
|
|
|
5c789a |
}
|
|
|
5c789a |
|
|
|
5c789a |
|
|
|
5c789a |
+STATIC
|
|
|
5c789a |
+EFI_STATUS
|
|
|
5c789a |
+EFIAPI
|
|
|
5c789a |
+ConnectVirtioPciRng (
|
|
|
5c789a |
+ IN EFI_HANDLE Handle,
|
|
|
5c789a |
+ IN VOID *Instance,
|
|
|
5c789a |
+ IN VOID *Context
|
|
|
5c789a |
+ )
|
|
|
5c789a |
+{
|
|
|
5c789a |
+ EFI_PCI_IO_PROTOCOL *PciIo;
|
|
|
5c789a |
+ EFI_STATUS Status;
|
|
|
5c789a |
+ UINT16 VendorId;
|
|
|
5c789a |
+ UINT16 DeviceId;
|
|
|
5c789a |
+ UINT8 RevisionId;
|
|
|
5c789a |
+ BOOLEAN Virtio10;
|
|
|
5c789a |
+ UINT16 SubsystemId;
|
|
|
5c789a |
+
|
|
|
5c789a |
+ PciIo = Instance;
|
|
|
5c789a |
+
|
|
|
5c789a |
+ //
|
|
|
5c789a |
+ // Read and check VendorId.
|
|
|
5c789a |
+ //
|
|
|
5c789a |
+ Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, PCI_VENDOR_ID_OFFSET,
|
|
|
5c789a |
+ 1, &VendorId);
|
|
|
5c789a |
+ if (EFI_ERROR (Status)) {
|
|
|
5c789a |
+ goto Error;
|
|
|
5c789a |
+ }
|
|
|
5c789a |
+ if (VendorId != VIRTIO_VENDOR_ID) {
|
|
|
5c789a |
+ return EFI_SUCCESS;
|
|
|
5c789a |
+ }
|
|
|
5c789a |
+
|
|
|
5c789a |
+ //
|
|
|
5c789a |
+ // Read DeviceId and RevisionId.
|
|
|
5c789a |
+ //
|
|
|
5c789a |
+ Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, PCI_DEVICE_ID_OFFSET,
|
|
|
5c789a |
+ 1, &DeviceId);
|
|
|
5c789a |
+ if (EFI_ERROR (Status)) {
|
|
|
5c789a |
+ goto Error;
|
|
|
5c789a |
+ }
|
|
|
5c789a |
+ Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, PCI_REVISION_ID_OFFSET,
|
|
|
5c789a |
+ 1, &RevisionId);
|
|
|
5c789a |
+ if (EFI_ERROR (Status)) {
|
|
|
5c789a |
+ goto Error;
|
|
|
5c789a |
+ }
|
|
|
5c789a |
+
|
|
|
5c789a |
+ //
|
|
|
5c789a |
+ // From DeviceId and RevisionId, determine whether the device is a
|
|
|
5c789a |
+ // modern-only Virtio 1.0 device. In case of Virtio 1.0, DeviceId can
|
|
|
5c789a |
+ // immediately be restricted to VIRTIO_SUBSYSTEM_ENTROPY_SOURCE, and
|
|
|
5c789a |
+ // SubsystemId will only play a sanity-check role. Otherwise, DeviceId can
|
|
|
5c789a |
+ // only be sanity-checked, and SubsystemId will decide.
|
|
|
5c789a |
+ //
|
|
|
5c789a |
+ if (DeviceId == 0x1040 + VIRTIO_SUBSYSTEM_ENTROPY_SOURCE &&
|
|
|
5c789a |
+ RevisionId >= 0x01) {
|
|
|
5c789a |
+ Virtio10 = TRUE;
|
|
|
5c789a |
+ } else if (DeviceId >= 0x1000 && DeviceId <= 0x103F && RevisionId == 0x00) {
|
|
|
5c789a |
+ Virtio10 = FALSE;
|
|
|
5c789a |
+ } else {
|
|
|
5c789a |
+ return EFI_SUCCESS;
|
|
|
5c789a |
+ }
|
|
|
5c789a |
+
|
|
|
5c789a |
+ //
|
|
|
5c789a |
+ // Read and check SubsystemId as dictated by Virtio10.
|
|
|
5c789a |
+ //
|
|
|
5c789a |
+ Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16,
|
|
|
5c789a |
+ PCI_SUBSYSTEM_ID_OFFSET, 1, &SubsystemId);
|
|
|
5c789a |
+ if (EFI_ERROR (Status)) {
|
|
|
5c789a |
+ goto Error;
|
|
|
5c789a |
+ }
|
|
|
5c789a |
+ if ((Virtio10 && SubsystemId >= 0x40) ||
|
|
|
5c789a |
+ (!Virtio10 && SubsystemId == VIRTIO_SUBSYSTEM_ENTROPY_SOURCE)) {
|
|
|
5c789a |
+ Status = gBS->ConnectController (
|
|
|
5c789a |
+ Handle, // ControllerHandle
|
|
|
5c789a |
+ NULL, // DriverImageHandle -- connect all drivers
|
|
|
5c789a |
+ NULL, // RemainingDevicePath -- produce all child handles
|
|
|
5c789a |
+ FALSE // Recursive -- don't follow child handles
|
|
|
5c789a |
+ );
|
|
|
5c789a |
+ if (EFI_ERROR (Status)) {
|
|
|
5c789a |
+ goto Error;
|
|
|
5c789a |
+ }
|
|
|
5c789a |
+ }
|
|
|
5c789a |
+ return EFI_SUCCESS;
|
|
|
5c789a |
+
|
|
|
5c789a |
+Error:
|
|
|
5c789a |
+ DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, Status));
|
|
|
5c789a |
+ return Status;
|
|
|
5c789a |
+}
|
|
|
5c789a |
+
|
|
|
5c789a |
+
|
|
|
5c789a |
/**
|
|
|
5c789a |
Add IsaKeyboard to ConIn; add IsaSerial to ConOut, ConIn, ErrOut.
|
|
|
5c789a |
|
|
|
5c789a |
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h
|
|
|
5c789a |
index 97ffbb5..4948ca6 100644
|
|
|
5c789a |
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h
|
|
|
5c789a |
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h
|
|
|
5c789a |
@@ -30,6 +30,7 @@ Abstract:
|
|
|
5c789a |
#include <IndustryStandard/Acpi.h>
|
|
|
5c789a |
#include <IndustryStandard/SmBios.h>
|
|
|
5c789a |
#include <IndustryStandard/PeImage.h>
|
|
|
5c789a |
+#include <IndustryStandard/Virtio095.h>
|
|
|
5c789a |
|
|
|
5c789a |
#include <Library/DebugLib.h>
|
|
|
5c789a |
#include <Library/BaseMemoryLib.h>
|
|
|
5c789a |
--
|
|
|
5c789a |
1.8.3.1
|
|
|
5c789a |
|