OvmfPkg/VirtioFsDxe: DriverBinding: open VirtioDevice, install SimpleFs

Complete the Supported, Start, and Stop member functions of
EFI_DRIVER_BINDING_PROTOCOL sufficiently for exercising the UEFI driver
model:

- bind virtio-fs devices,

- produce placeholder EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on them.

On the "TO_START" (= Virtio) side, the VirtioFsBindingSupported() function
verifies the Virtio subsystem ID for the virtio-fs device (decimal 26 --
see
<https://github.com/oasis-tcs/virtio-spec/blob/87fa6b5d8155/virtio-fs.tex>).
Beyond that, no actual Virtio setup is performed for now. Those bits are
going to be implemented later in this series.

On the "BY_START" (= UEFI filesystem) side, the VirtioFsOpenVolume()
function -- which is the sole EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member
function -- is a stub; it always returns EFI_NO_MEDIA, for now.

The "CONNECT", "DISCONNECT", and "MAP -R" UEFI Shell commands can be used
to test this patch.

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20201216211125.19496-4-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
This commit is contained in:
Laszlo Ersek
2020-12-16 22:10:40 +01:00
committed by mergify[bot]
parent fbc3e1267a
commit b55d6622d4
5 changed files with 181 additions and 3 deletions

View File

@@ -6,11 +6,15 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <IndustryStandard/Virtio.h> // VIRTIO_SUBSYSTEM_FILESYSTEM
#include <Library/BaseLib.h> // AsciiStrCmp()
#include <Library/MemoryAllocationLib.h> // AllocatePool()
#include <Library/UefiBootServicesTableLib.h> // gBS
#include <Protocol/ComponentName2.h> // EFI_COMPONENT_NAME2_PROTOCOL
#include <Protocol/DriverBinding.h> // EFI_DRIVER_BINDING_PROTOCOL
#include "VirtioFsDxe.h"
//
// UEFI Driver Model protocol instances.
//
@@ -28,7 +32,27 @@ VirtioFsBindingSupported (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
return EFI_UNSUPPORTED;
EFI_STATUS Status;
VIRTIO_DEVICE_PROTOCOL *Virtio;
EFI_STATUS CloseStatus;
Status = gBS->OpenProtocol (ControllerHandle, &gVirtioDeviceProtocolGuid,
(VOID **)&Virtio, This->DriverBindingHandle,
ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER);
if (EFI_ERROR (Status)) {
return Status;
}
if (Virtio->SubSystemDeviceId != VIRTIO_SUBSYSTEM_FILESYSTEM) {
Status = EFI_UNSUPPORTED;
}
CloseStatus = gBS->CloseProtocol (ControllerHandle,
&gVirtioDeviceProtocolGuid, This->DriverBindingHandle,
ControllerHandle);
ASSERT_EFI_ERROR (CloseStatus);
return Status;
}
EFI_STATUS
@@ -39,7 +63,45 @@ VirtioFsBindingStart (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
)
{
return EFI_DEVICE_ERROR;
VIRTIO_FS *VirtioFs;
EFI_STATUS Status;
EFI_STATUS CloseStatus;
VirtioFs = AllocatePool (sizeof *VirtioFs);
if (VirtioFs == NULL) {
return EFI_OUT_OF_RESOURCES;
}
VirtioFs->Signature = VIRTIO_FS_SIG;
Status = gBS->OpenProtocol (ControllerHandle, &gVirtioDeviceProtocolGuid,
(VOID **)&VirtioFs->Virtio, This->DriverBindingHandle,
ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER);
if (EFI_ERROR (Status)) {
goto FreeVirtioFs;
}
VirtioFs->SimpleFs.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
VirtioFs->SimpleFs.OpenVolume = VirtioFsOpenVolume;
Status = gBS->InstallProtocolInterface (&ControllerHandle,
&gEfiSimpleFileSystemProtocolGuid, EFI_NATIVE_INTERFACE,
&VirtioFs->SimpleFs);
if (EFI_ERROR (Status)) {
goto CloseVirtio;
}
return EFI_SUCCESS;
CloseVirtio:
CloseStatus = gBS->CloseProtocol (ControllerHandle,
&gVirtioDeviceProtocolGuid, This->DriverBindingHandle,
ControllerHandle);
ASSERT_EFI_ERROR (CloseStatus);
FreeVirtioFs:
FreePool (VirtioFs);
return Status;
}
EFI_STATUS
@@ -51,7 +113,33 @@ VirtioFsBindingStop (
IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
)
{
return EFI_DEVICE_ERROR;
EFI_STATUS Status;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFs;
VIRTIO_FS *VirtioFs;
Status = gBS->OpenProtocol (ControllerHandle,
&gEfiSimpleFileSystemProtocolGuid, (VOID **)&SimpleFs,
This->DriverBindingHandle, ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (EFI_ERROR (Status)) {
return Status;
}
VirtioFs = VIRTIO_FS_FROM_SIMPLE_FS (SimpleFs);
Status = gBS->UninstallProtocolInterface (ControllerHandle,
&gEfiSimpleFileSystemProtocolGuid, SimpleFs);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->CloseProtocol (ControllerHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, ControllerHandle);
ASSERT_EFI_ERROR (Status);
FreePool (VirtioFs);
return EFI_SUCCESS;
}
EFI_STATUS