summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/VirtioRngDxe
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2024-05-29 17:28:11 +0200
committerArd Biesheuvel <workofard@gmail.com>2024-05-31 23:00:40 -0700
commit7339bfeffa3fa30b18dce86409c0112039bacec5 (patch)
tree5644b4f0a8ed9f86ecfbe4d87029cb835b73dae2 /OvmfPkg/VirtioRngDxe
parent3b36aa96de1d5f7a4660bec5c0cbad2616183dd6 (diff)
downloadedk2-7339bfeffa3fa30b18dce86409c0112039bacec5.tar.gz
edk2-7339bfeffa3fa30b18dce86409c0112039bacec5.tar.bz2
edk2-7339bfeffa3fa30b18dce86409c0112039bacec5.zip
OvmfPkg/VirtioRngDxe: check if device is ready
Add a 'Ready' boolean to the driver state struct, use it to track whenever the device is ready to be used. In case it is not ready throw an EFI_DEVICE_ERROR instead of sending a request which will never receive an answer. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'OvmfPkg/VirtioRngDxe')
-rw-r--r--OvmfPkg/VirtioRngDxe/VirtioRng.c13
-rw-r--r--OvmfPkg/VirtioRngDxe/VirtioRng.h1
2 files changed, 11 insertions, 3 deletions
diff --git a/OvmfPkg/VirtioRngDxe/VirtioRng.c b/OvmfPkg/VirtioRngDxe/VirtioRng.c
index 069aed148a..8959e51faf 100644
--- a/OvmfPkg/VirtioRngDxe/VirtioRng.c
+++ b/OvmfPkg/VirtioRngDxe/VirtioRng.c
@@ -156,6 +156,11 @@ VirtioRngGetRNG (
}
Dev = VIRTIO_ENTROPY_SOURCE_FROM_RNG (This);
+ if (!Dev->Ready) {
+ DEBUG ((DEBUG_INFO, "%a: not ready\n", __func__));
+ return EFI_DEVICE_ERROR;
+ }
+
//
// Map Buffer's system physical address to device address
//
@@ -382,6 +387,7 @@ VirtioRngInit (
//
Dev->Rng.GetInfo = VirtioRngGetInfo;
Dev->Rng.GetRNG = VirtioRngGetRNG;
+ Dev->Ready = TRUE;
return EFI_SUCCESS;
@@ -414,8 +420,8 @@ VirtioRngUninit (
// VIRTIO_CFG_WRITE() returns, the host will have learned to stay away from
// the old comms area.
//
+ Dev->Ready = FALSE;
Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
-
Dev->VirtIo->UnmapSharedBuffer (Dev->VirtIo, Dev->RingMap);
VirtioRingUninit (Dev->VirtIo, &Dev->Ring);
@@ -435,7 +441,7 @@ VirtioRngExitBoot (
{
VIRTIO_RNG_DEV *Dev;
- DEBUG ((DEBUG_VERBOSE, "%a: Context=0x%p\n", __func__, Context));
+ DEBUG ((DEBUG_INFO, "%a: Context=0x%p\n", __func__, Context));
//
// Reset the device. This causes the hypervisor to forget about the virtio
// ring.
@@ -443,7 +449,8 @@ VirtioRngExitBoot (
// We allocated said ring in EfiBootServicesData type memory, and code
// executing after ExitBootServices() is permitted to overwrite it.
//
- Dev = Context;
+ Dev = Context;
+ Dev->Ready = FALSE;
Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, 0);
}
diff --git a/OvmfPkg/VirtioRngDxe/VirtioRng.h b/OvmfPkg/VirtioRngDxe/VirtioRng.h
index 2da99540a2..3519521d6a 100644
--- a/OvmfPkg/VirtioRngDxe/VirtioRng.h
+++ b/OvmfPkg/VirtioRngDxe/VirtioRng.h
@@ -33,6 +33,7 @@ typedef struct {
VRING Ring; // VirtioRingInit 2
EFI_RNG_PROTOCOL Rng; // VirtioRngInit 1
VOID *RingMap; // VirtioRingMap 2
+ BOOLEAN Ready;
} VIRTIO_RNG_DEV;
#define VIRTIO_ENTROPY_SOURCE_FROM_RNG(RngPointer) \