From nobody Mon Feb 9 06:00:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+69015+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69015+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608153477; cv=none; d=zohomail.com; s=zohoarc; b=EakiDW2k5zGOKetXSnD/X3xz/se8JnHnqeXXAfxZup7ysnQzBXqyzATfC+fUZ8/KotyS80JYOd4Y2kTQ81DCpPZYvLumpyI4PRIWiQZMgsmCfTP423cHxNC3KQ4ZptSxYK2sb3ldz4ouqn5Zq/8KecXQhTR6VSgygoNYg04W9Qk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608153477; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=wBmD5XgRCX00AOXtT4fKGKPMVPwuGN6J8u+l7mbWCQ0=; b=ncNAQ6ZuJgVS9vGxm4EwKkjVP4HAHBCm5sKCzK7otpWHrxspEme2hwcm8gHepbdZ7gvoTZYIhEakiXIKiIKEjXpev9oeWEwJCd/659PSZuAhcDOMUU2Qw0c0j4qs9k59B9FOTb/0XFJ0gvGSxfdSd4/02SXs27x85OIw2aKO7o8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+69015+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608153477132437.7244076213733; Wed, 16 Dec 2020 13:17:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id OkSHYY1788612xOD28d56wdK; Wed, 16 Dec 2020 13:17:56 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.groups.io with SMTP id smtpd.web09.3416.1608153475745491043 for ; Wed, 16 Dec 2020 13:17:56 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-550-K_c9JeCnNUm5sgiAIfoOCQ-1; Wed, 16 Dec 2020 16:17:51 -0500 X-MC-Unique: K_c9JeCnNUm5sgiAIfoOCQ-1 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 632F5190D343; Wed, 16 Dec 2020 21:17:50 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EA605D9C0; Wed, 16 Dec 2020 21:17:45 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 03/48] OvmfPkg/VirtioFsDxe: DriverBinding: open VirtioDevice, install SimpleFs Date: Wed, 16 Dec 2020 22:10:40 +0100 Message-Id: <20201216211125.19496-4-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com X-Gm-Message-State: 911yIgUloXN25N05D0S3zzQ6x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608153476; bh=wBmD5XgRCX00AOXtT4fKGKPMVPwuGN6J8u+l7mbWCQ0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=HAGjpsLHkJL2vYhjuLl18mZGnAfrOhnUhXlAHQAl/0dRSJkpjBHQ5HHh7JoWLJNl7ci Bq36UEAK8L0LX6MTRywygxqIpgFdNWZ6nLXnpjceN5FJ06i9AsUF9ZFYJ8PTbr4E4thZV sxKcMFZFlO9HXqhZMbUhQReqcIRTpjSNsmI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" 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" (=3D Virtio) side, the VirtioFsBindingSupported() function verifies the Virtio subsystem ID for the virtio-fs device (decimal 26 -- see ). 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" (=3D 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 Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek --- OvmfPkg/Include/IndustryStandard/Virtio10.h | 5 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 7 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 52 +++++++++++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 94 +++++++++++++++++++- OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 26 ++++++ 5 files changed, 181 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/Include/IndustryStandard/Virtio10.h b/OvmfPkg/Include/= IndustryStandard/Virtio10.h index 3c1592d1fdea..2c60be2b7c0c 100644 --- a/OvmfPkg/Include/IndustryStandard/Virtio10.h +++ b/OvmfPkg/Include/IndustryStandard/Virtio10.h @@ -12,16 +12,21 @@ =20 #include #include =20 // // Subsystem Device IDs (to be) introduced in VirtIo 1.0 // #define VIRTIO_SUBSYSTEM_GPU_DEVICE 16 +// +// Subsystem Device IDs from the VirtIo spec at git commit 87fa6b5d8155; +// . +// +#define VIRTIO_SUBSYSTEM_FILESYSTEM 26 =20 // // Structures for parsing the VirtIo 1.0 specific PCI capabilities from the // config space // #pragma pack (1) typedef struct { EFI_PCI_CAPABILITY_VENDOR_HDR VendorHdr; diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 69cb44bc7c96..ff9b1c6178bc 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -73,20 +73,27 @@ [Defines] INF_VERSION =3D 1.29 BASE_NAME =3D VirtioFsDxe FILE_GUID =3D 7BD9DDF7-8B83-488E-AEC9-24C786= 10289C MODULE_TYPE =3D UEFI_DRIVER ENTRY_POINT =3D VirtioFsEntryPoint =20 [Packages] MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c + SimpleFsOpenVolume.c + VirtioFsDxe.h =20 [LibraryClasses] BaseLib + DebugLib + MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint =20 [Protocols] gEfiComponentName2ProtocolGuid ## PRODUCES gEfiDriverBindingProtocolGuid ## PRODUCES + gEfiSimpleFileSystemProtocolGuid ## BY_START + gVirtioDeviceProtocolGuid ## TO_START diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h new file mode 100644 index 000000000000..287defd21f23 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -0,0 +1,52 @@ +/** @file + Internal macro definitions, type definitions, and function declarations = for + the Virtio Filesystem device driver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef VIRTIO_FS_DXE_H_ +#define VIRTIO_FS_DXE_H_ + +#include // SIGNATURE_64() +#include // CR() +#include // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL +#include // VIRTIO_DEVICE_PROTOCOL + +#define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S') + +// +// Main context structure, expressing an EFI_SIMPLE_FILE_SYSTEM_PROTOCOL +// interface on top of the Virtio Filesystem device. +// +typedef struct { + // + // Parts of this structure are initialized / torn down in various functi= ons + // at various call depths. The table to the right should make it easier = to + // track them. + // + // field init function init d= epth + // ----------- ------------------ ------= ---- + UINT64 Signature; // DriverBindingStart 0 + VIRTIO_DEVICE_PROTOCOL *Virtio; // DriverBindingStart 0 + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0 +} VIRTIO_FS; + +#define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \ + CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); + +// +// EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem +// driver. +// + +EFI_STATUS +EFIAPI +VirtioFsOpenVolume ( + IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **Root + ); + +#endif // VIRTIO_FS_DXE_H_ diff --git a/OvmfPkg/VirtioFsDxe/DriverBinding.c b/OvmfPkg/VirtioFsDxe/Driv= erBinding.c index ac0a6330f01b..65e45b5c4bf7 100644 --- a/OvmfPkg/VirtioFsDxe/DriverBinding.c +++ b/OvmfPkg/VirtioFsDxe/DriverBinding.c @@ -1,21 +1,25 @@ /** @file Provide EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instances on virtio-fs devices. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 +#include // VIRTIO_SUBSYSTEM_FILESYST= EM #include // AsciiStrCmp() +#include // AllocatePool() #include // gBS #include // EFI_COMPONENT_NAME2_PROTO= COL #include // EFI_DRIVER_BINDING_PROTOC= OL =20 +#include "VirtioFsDxe.h" + // // UEFI Driver Model protocol instances. // STATIC EFI_DRIVER_BINDING_PROTOCOL mDriverBinding; STATIC EFI_COMPONENT_NAME2_PROTOCOL mComponentName2; =20 // // UEFI Driver Model protocol member functions. @@ -23,40 +27,124 @@ STATIC EFI_COMPONENT_NAME2_PROTOCOL mComponentName2; EFI_STATUS EFIAPI VirtioFsBindingSupported ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) { - return EFI_UNSUPPORTED; + EFI_STATUS Status; + VIRTIO_DEVICE_PROTOCOL *Virtio; + EFI_STATUS CloseStatus; + + Status =3D gBS->OpenProtocol (ControllerHandle, &gVirtioDeviceProtocolGu= id, + (VOID **)&Virtio, This->DriverBindingHandle, + ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER); + if (EFI_ERROR (Status)) { + return Status; + } + + if (Virtio->SubSystemDeviceId !=3D VIRTIO_SUBSYSTEM_FILESYSTEM) { + Status =3D EFI_UNSUPPORTED; + } + + CloseStatus =3D gBS->CloseProtocol (ControllerHandle, + &gVirtioDeviceProtocolGuid, This->DriverBindingHand= le, + ControllerHandle); + ASSERT_EFI_ERROR (CloseStatus); + + return Status; } =20 EFI_STATUS EFIAPI VirtioFsBindingStart ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) { - return EFI_DEVICE_ERROR; + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + EFI_STATUS CloseStatus; + + VirtioFs =3D AllocatePool (sizeof *VirtioFs); + if (VirtioFs =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + VirtioFs->Signature =3D VIRTIO_FS_SIG; + + Status =3D gBS->OpenProtocol (ControllerHandle, &gVirtioDeviceProtocolGu= id, + (VOID **)&VirtioFs->Virtio, This->DriverBindingHandle, + ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER); + if (EFI_ERROR (Status)) { + goto FreeVirtioFs; + } + + VirtioFs->SimpleFs.Revision =3D EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISI= ON; + VirtioFs->SimpleFs.OpenVolume =3D VirtioFsOpenVolume; + + Status =3D gBS->InstallProtocolInterface (&ControllerHandle, + &gEfiSimpleFileSystemProtocolGuid, EFI_NATIVE_INTERFACE, + &VirtioFs->SimpleFs); + if (EFI_ERROR (Status)) { + goto CloseVirtio; + } + + return EFI_SUCCESS; + +CloseVirtio: + CloseStatus =3D gBS->CloseProtocol (ControllerHandle, + &gVirtioDeviceProtocolGuid, This->DriverBindingHand= le, + ControllerHandle); + ASSERT_EFI_ERROR (CloseStatus); + +FreeVirtioFs: + FreePool (VirtioFs); + + return Status; } =20 EFI_STATUS EFIAPI VirtioFsBindingStop ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer OPTIONAL ) { - return EFI_DEVICE_ERROR; + EFI_STATUS Status; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFs; + VIRTIO_FS *VirtioFs; + + Status =3D gBS->OpenProtocol (ControllerHandle, + &gEfiSimpleFileSystemProtocolGuid, (VOID **)&SimpleFs, + This->DriverBindingHandle, ControllerHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (EFI_ERROR (Status)) { + return Status; + } + + VirtioFs =3D VIRTIO_FS_FROM_SIMPLE_FS (SimpleFs); + + Status =3D gBS->UninstallProtocolInterface (ControllerHandle, + &gEfiSimpleFileSystemProtocolGuid, SimpleFs); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D gBS->CloseProtocol (ControllerHandle, &gVirtioDeviceProtocolG= uid, + This->DriverBindingHandle, ControllerHandle); + ASSERT_EFI_ERROR (Status); + + FreePool (VirtioFs); + + return EFI_SUCCESS; } =20 EFI_STATUS EFIAPI VirtioFsGetDriverName ( IN EFI_COMPONENT_NAME2_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c b/OvmfPkg/VirtioFsDxe= /SimpleFsOpenVolume.c new file mode 100644 index 000000000000..a5a66a27d84c --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c @@ -0,0 +1,26 @@ +/** @file + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume() member function for the Vir= tio + Filesystem driver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +/** + Open the root directory on the Virtio Filesystem. + + Refer to EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME for the interface + contract. +**/ +EFI_STATUS +EFIAPI +VirtioFsOpenVolume ( + IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **Root + ) +{ + return EFI_NO_MEDIA; +} --=20 2.19.1.3.g30247aa5d201 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#69015): https://edk2.groups.io/g/devel/message/69015 Mute This Topic: https://groups.io/mt/79022609/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-