From nobody Mon Feb 9 09:32:29 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+69016+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+69016+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608153614; cv=none; d=zohomail.com; s=zohoarc; b=MqUA7YH8hrDC/+dG6mmfBj8xQJCr0Lln2n693dllP5xOsQYJ4y0Ozlfdy9i/5PWy1Er63OTPR/mKfMXi8fjtAl0Ele0WeY2e2svcJ92fO+W2NwWSXkyIYKWofqhdofXBr/lfM28Bf3kigFREfc2enidgOk0TF9MM9R9Wbfgnhy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608153614; 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=PeBn7HDNJHKXaR2YepR7E5/PSfekgYN8BfXMWsE+Ylo=; b=n+imPAskslh//M6Lwoygd23rGIy90ZYjpgS6gO9dHret9yrpvC+LWYoik0ibAoK0GMn6eZOZnbV558w+RO2AOJZ+H9i25o8faw66x+m5MpxZpLNAZP+b24vj8ZywdP6W5p0C2FX74R4kbbm6ZpYckRULJy85o/igPsrUf75QW/Q= 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+69016+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 1608153614198754.1113131579496; Wed, 16 Dec 2020 13:20:14 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id XIXCYY1788612xN8FZyPhwy7; Wed, 16 Dec 2020 13:20:07 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.3640.1608153601436957133 for ; Wed, 16 Dec 2020 13:20:01 -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-339-hSteD7UxM0m-d7JfW_IzFw-1; Wed, 16 Dec 2020 16:19:57 -0500 X-MC-Unique: hSteD7UxM0m-d7JfW_IzFw-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 56C8F800D53; Wed, 16 Dec 2020 21:19:56 +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 92458106D5AC; Wed, 16 Dec 2020 21:19:51 +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 04/48] OvmfPkg/VirtioFsDxe: implement virtio device (un)initialization Date: Wed, 16 Dec 2020 22:10:41 +0100 Message-Id: <20201216211125.19496-5-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.84 on 10.5.11.22 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: 3GEAFEGLjMYg1fTRX4VHBpuTx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608153607; bh=PeBn7HDNJHKXaR2YepR7E5/PSfekgYN8BfXMWsE+Ylo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=qhUUtlbqFRN2R2ocwTLg5xGOkBRz8/45E9A2uyNWhCOguljJMQS8N/ppVSbJZEfSqAY vsEcwEoqkSx0Vwe52Kb4R5tDTvwFaN1orVSAH3B2lyXRCzFKkUbu/0KIO+ZBQtlaiiMSH gyL0spatSG857XTKY/tFInKSi4m98wKgCKk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add the VirtioFsInit(), VirtioFsUninit(), and VirtioFsExitBoot() functions. In VirtioFsInit(): - Verify the host-side config of the virtio-fs device. - Save the filesystem label ("tag") for later, from the configuration area of the virtio-fs device. - Save the virtio queue size for later as well. - Set up the virtio ring for sending requests. In VirtioFsUninit(): - Reset the device. - Tear down the virtio ring. In VirtioFsExitBoot(): - Reset the device. With this patch, the UEFI connect / disconnect controller operations involve virtio setup / teardown; they are visible in the virtio-fs daemon's log file. The virtiofsd log also confirms the device reset in VirtioFsExitBoot(), when an OS is booted while the virtio-fs device is bound. 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/VirtioFs.h | 52 ++++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 2 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 35 +++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 26 +- OvmfPkg/VirtioFsDxe/Helpers.c | 299 ++++++++++++++++++++ 5 files changed, 412 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h new file mode 100644 index 000000000000..ea7d80d15d0b --- /dev/null +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -0,0 +1,52 @@ +/** @file + Type and macro definitions specific to the Virtio Filesystem device. + + At the time of this writing, the latest released Virtio specification (v= 1.1) + does not include the virtio-fs device. The development version of the + specification defines it however; see the latest version at + . + + This header file is minimal, and only defines the types and macros that = are + necessary for the OvmfPkg implementation. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef VIRTIO_FS_H_ +#define VIRTIO_FS_H_ + +#include + +// +// Lowest numbered queue for sending normal priority requests. +// +#define VIRTIO_FS_REQUEST_QUEUE 1 + +// +// Number of bytes in the "VIRTIO_FS_CONFIG.Tag" field. +// +#define VIRTIO_FS_TAG_BYTES 36 + +// +// Device configuration layout. +// +#pragma pack (1) +typedef struct { + // + // The Tag field can be considered the filesystem label, or a mount point + // hint. It is UTF-8 encoded, and padded to full size with NUL bytes. If= the + // encoded bytes take up the entire Tag field, then there is no NUL + // terminator. + // + UINT8 Tag[VIRTIO_FS_TAG_BYTES]; + // + // The total number of request virtqueues exposed by the device (i.e., + // excluding the "hiprio" queue). + // + UINT32 NumReqQueues; +} VIRTIO_FS_CONFIG; +#pragma pack () + +#endif // VIRTIO_FS_H_ diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index ff9b1c6178bc..f6eebdb6bc7c 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -77,23 +77,25 @@ [Defines] ENTRY_POINT =3D VirtioFsEntryPoint =20 [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c + Helpers.c SimpleFsOpenVolume.c VirtioFsDxe.h =20 [LibraryClasses] BaseLib DebugLib MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint + VirtioLib =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 index 287defd21f23..2aae96ecd79a 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -6,42 +6,77 @@ =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #ifndef VIRTIO_FS_DXE_H_ #define VIRTIO_FS_DXE_H_ =20 #include // SIGNATURE_64() +#include // VIRTIO_FS_TAG_BYTES #include // CR() #include // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL #include // VIRTIO_DEVICE_PROTOCOL +#include // EFI_EVENT =20 #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S') =20 +// +// Filesystem label encoded in UCS-2, transformed from the UTF-8 represent= ation +// in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII= code +// points (U+0020 through U+007E) are supported. +// +typedef CHAR16 VIRTIO_FS_LABEL[VIRTIO_FS_TAG_BYTES + 1]; + // // 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 + VIRTIO_FS_LABEL Label; // VirtioFsInit 1 + UINT16 QueueSize; // VirtioFsInit 1 + VRING Ring; // VirtioRingInit 2 + VOID *RingMap; // VirtioRingMap 2 + EFI_EVENT ExitBoot; // DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0 } VIRTIO_FS; =20 #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); =20 +// +// Initialization and helper routines for the Virtio Filesystem device. +// + +EFI_STATUS +VirtioFsInit ( + IN OUT VIRTIO_FS *VirtioFs + ); + +VOID +VirtioFsUninit ( + IN OUT VIRTIO_FS *VirtioFs + ); + +VOID +EFIAPI +VirtioFsExitBoot ( + IN EFI_EVENT ExitBootEvent, + IN VOID *VirtioFsAsVoid + ); + // // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL member functions for the Virtio Filesys= tem // driver. // =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( diff --git a/OvmfPkg/VirtioFsDxe/DriverBinding.c b/OvmfPkg/VirtioFsDxe/Driv= erBinding.c index 65e45b5c4bf7..b888158a805d 100644 --- a/OvmfPkg/VirtioFsDxe/DriverBinding.c +++ b/OvmfPkg/VirtioFsDxe/DriverBinding.c @@ -1,17 +1,16 @@ /** @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" =20 @@ -75,28 +74,46 @@ VirtioFsBindingStart ( =20 Status =3D gBS->OpenProtocol (ControllerHandle, &gVirtioDeviceProtocolGu= id, (VOID **)&VirtioFs->Virtio, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER); if (EFI_ERROR (Status)) { goto FreeVirtioFs; } =20 + Status =3D VirtioFsInit (VirtioFs); + if (EFI_ERROR (Status)) { + goto CloseVirtio; + } + + Status =3D gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK, + VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot); + if (EFI_ERROR (Status)) { + goto UninitVirtioFs; + } + VirtioFs->SimpleFs.Revision =3D EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISI= ON; VirtioFs->SimpleFs.OpenVolume =3D VirtioFsOpenVolume; =20 Status =3D gBS->InstallProtocolInterface (&ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, EFI_NATIVE_INTERFACE, &VirtioFs->SimpleFs); if (EFI_ERROR (Status)) { - goto CloseVirtio; + goto CloseExitBoot; } =20 return EFI_SUCCESS; =20 +CloseExitBoot: + CloseStatus =3D gBS->CloseEvent (VirtioFs->ExitBoot); + ASSERT_EFI_ERROR (CloseStatus); + +UninitVirtioFs: + VirtioFsUninit (VirtioFs); + CloseVirtio: CloseStatus =3D gBS->CloseProtocol (ControllerHandle, &gVirtioDeviceProtocolGuid, This->DriverBindingHand= le, ControllerHandle); ASSERT_EFI_ERROR (CloseStatus); =20 FreeVirtioFs: FreePool (VirtioFs); @@ -128,16 +145,21 @@ VirtioFsBindingStop ( VirtioFs =3D VIRTIO_FS_FROM_SIMPLE_FS (SimpleFs); =20 Status =3D gBS->UninstallProtocolInterface (ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, SimpleFs); if (EFI_ERROR (Status)) { return Status; } =20 + Status =3D gBS->CloseEvent (VirtioFs->ExitBoot); + ASSERT_EFI_ERROR (Status); + + VirtioFsUninit (VirtioFs); + Status =3D gBS->CloseProtocol (ControllerHandle, &gVirtioDeviceProtocolG= uid, This->DriverBindingHandle, ControllerHandle); ASSERT_EFI_ERROR (Status); =20 FreePool (VirtioFs); =20 return EFI_SUCCESS; } diff --git a/OvmfPkg/VirtioFsDxe/Helpers.c b/OvmfPkg/VirtioFsDxe/Helpers.c new file mode 100644 index 000000000000..7b4906c54184 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/Helpers.c @@ -0,0 +1,299 @@ +/** @file + Initialization and helper routines for the Virtio Filesystem device. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // Virtio10WriteFeatures() + +#include "VirtioFsDxe.h" + +/** + Read the Virtio Filesystem device configuration structure in full. + + @param[in] Virtio The Virtio protocol underlying the VIRTIO_FS object. + + @param[out] Config The fully populated VIRTIO_FS_CONFIG structure. + + @retval EFI_SUCCESS Config has been filled in. + + @return Error codes propagated from Virtio->ReadDevice(). T= he + contents of Config are indeterminate. +**/ +STATIC +EFI_STATUS +VirtioFsReadConfig ( + IN VIRTIO_DEVICE_PROTOCOL *Virtio, + OUT VIRTIO_FS_CONFIG *Config + ) +{ + UINTN Idx; + EFI_STATUS Status; + + for (Idx =3D 0; Idx < VIRTIO_FS_TAG_BYTES; Idx++) { + Status =3D Virtio->ReadDevice ( + Virtio, // This + OFFSET_OF (VIRTIO_FS_CONFIG, Tag[Idx]), // FieldOff= set + sizeof Config->Tag[Idx], // FieldSize + sizeof Config->Tag[Idx], // BufferSi= ze + &Config->Tag[Idx] // Buffer + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + + Status =3D Virtio->ReadDevice ( + Virtio, // This + OFFSET_OF (VIRTIO_FS_CONFIG, NumReqQueues), // FieldO= ffset + sizeof Config->NumReqQueues, // FieldS= ize + sizeof Config->NumReqQueues, // Buffer= Size + &Config->NumReqQueues // Buffer + ); + return Status; +} + +/** + Configure the Virtio Filesystem device underlying VirtioFs. + + @param[in,out] VirtioFs The VIRTIO_FS object for which Virtio communica= tion + should be set up. On input, the caller is + responsible for VirtioFs->Virtio having been + initialized. On output, synchronous Virtio + Filesystem commands (primitives) may be submitt= ed to + the device. + + @retval EFI_SUCCESS Virtio machinery has been set up. + + @retval EFI_UNSUPPORTED The host-side configuration of the Virtio Files= ystem + is not supported by this driver. + + @return Error codes from underlying functions. +**/ +EFI_STATUS +VirtioFsInit ( + IN OUT VIRTIO_FS *VirtioFs + ) +{ + UINT8 NextDevStat; + EFI_STATUS Status; + UINT64 Features; + VIRTIO_FS_CONFIG Config; + UINTN Idx; + UINT64 RingBaseShift; + + // + // Execute virtio-v1.1-cs01-87fa6b5d8155, 3.1.1 Driver Requirements: Dev= ice + // Initialization. + // + // 1. Reset the device. + // + NextDevStat =3D 0; + Status =3D VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, NextDevS= tat); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // + // 2. Set the ACKNOWLEDGE status bit [...] + // + NextDevStat |=3D VSTAT_ACK; + Status =3D VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, NextDevS= tat); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // + // 3. Set the DRIVER status bit [...] + // + NextDevStat |=3D VSTAT_DRIVER; + Status =3D VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, NextDevS= tat); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // + // 4. Read device feature bits... + // + Status =3D VirtioFs->Virtio->GetDeviceFeatures (VirtioFs->Virtio, &Featu= res); + if (EFI_ERROR (Status)) { + goto Failed; + } + if ((Features & VIRTIO_F_VERSION_1) =3D=3D 0) { + Status =3D EFI_UNSUPPORTED; + goto Failed; + } + // + // No device-specific feature bits have been defined in file "virtio-fs.= tex" + // of the virtio spec at ,= as + // of commit 87fa6b5d8155. + // + Features &=3D VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM; + + // + // ... and write the subset of feature bits understood by the [...] driv= er to + // the device. [...] + // 5. Set the FEATURES_OK status bit. + // 6. Re-read device status to ensure the FEATURES_OK bit is still set [= ...] + // + Status =3D Virtio10WriteFeatures (VirtioFs->Virtio, Features, &NextDevSt= at); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // + // 7. Perform device-specific setup, including discovery of virtqueues f= or + // the device, [...] reading [...] the device's virtio configuration spa= ce + // + Status =3D VirtioFsReadConfig (VirtioFs->Virtio, &Config); + if (EFI_ERROR (Status)) { + goto Failed; + } + + // + // 7.a. Convert the filesystem label from UTF-8 to UCS-2. Only labels wi= th + // printable ASCII code points (U+0020 through U+007E) are supported. + // NUL-terminate at either the terminator we find, or right after the + // original label. + // + for (Idx =3D 0; Idx < VIRTIO_FS_TAG_BYTES && Config.Tag[Idx] !=3D '\0'; = Idx++) { + if (Config.Tag[Idx] < 0x20 || Config.Tag[Idx] > 0x7E) { + Status =3D EFI_UNSUPPORTED; + goto Failed; + } + VirtioFs->Label[Idx] =3D Config.Tag[Idx]; + } + VirtioFs->Label[Idx] =3D L'\0'; + + // + // 7.b. We need one queue for sending normal priority requests. + // + if (Config.NumReqQueues < 1) { + Status =3D EFI_UNSUPPORTED; + goto Failed; + } + + // + // 7.c. Fetch and remember the number of descriptors we can place on the + // queue at once. We'll need two descriptors per request, as a minimum -- + // request header, response header. + // + Status =3D VirtioFs->Virtio->SetQueueSel (VirtioFs->Virtio, + VIRTIO_FS_REQUEST_QUEUE); + if (EFI_ERROR (Status)) { + goto Failed; + } + Status =3D VirtioFs->Virtio->GetQueueNumMax (VirtioFs->Virtio, + &VirtioFs->QueueSize); + if (EFI_ERROR (Status)) { + goto Failed; + } + if (VirtioFs->QueueSize < 2) { + Status =3D EFI_UNSUPPORTED; + goto Failed; + } + + // + // 7.d. [...] population of virtqueues [...] + // + Status =3D VirtioRingInit (VirtioFs->Virtio, VirtioFs->QueueSize, + &VirtioFs->Ring); + if (EFI_ERROR (Status)) { + goto Failed; + } + + Status =3D VirtioRingMap (VirtioFs->Virtio, &VirtioFs->Ring, &RingBaseSh= ift, + &VirtioFs->RingMap); + if (EFI_ERROR (Status)) { + goto ReleaseQueue; + } + + Status =3D VirtioFs->Virtio->SetQueueAddress (VirtioFs->Virtio, + &VirtioFs->Ring, RingBaseShift); + if (EFI_ERROR (Status)) { + goto UnmapQueue; + } + + // + // 8. Set the DRIVER_OK status bit. + // + NextDevStat |=3D VSTAT_DRIVER_OK; + Status =3D VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, NextDevS= tat); + if (EFI_ERROR (Status)) { + goto UnmapQueue; + } + + return EFI_SUCCESS; + +UnmapQueue: + VirtioFs->Virtio->UnmapSharedBuffer (VirtioFs->Virtio, VirtioFs->RingMap= ); + +ReleaseQueue: + VirtioRingUninit (VirtioFs->Virtio, &VirtioFs->Ring); + +Failed: + // + // If any of these steps go irrecoverably wrong, the driver SHOULD set t= he + // FAILED status bit to indicate that it has given up on the device (it = can + // reset the device later to restart if desired). [...] + // + // Virtio access failure here should not mask the original error. + // + NextDevStat |=3D VSTAT_FAILED; + VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, NextDevStat); + + return Status; +} + +/** + De-configure the Virtio Filesystem device underlying VirtioFs. + + @param[in] VirtioFs The VIRTIO_FS object for which Virtio communication + should be torn down. On input, the caller is respon= sible + for having called VirtioFsInit(). On output, Virtio + Filesystem commands (primitives) must no longer be + submitted to the device. +**/ +VOID +VirtioFsUninit ( + IN OUT VIRTIO_FS *VirtioFs + ) +{ + // + // Resetting the Virtio device makes it release its resources and forget= its + // configuration. + // + VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, 0); + VirtioFs->Virtio->UnmapSharedBuffer (VirtioFs->Virtio, VirtioFs->RingMap= ); + VirtioRingUninit (VirtioFs->Virtio, &VirtioFs->Ring); +} + +/** + ExitBootServices event notification function for a Virtio Filesystem obj= ect. + + This function resets the VIRTIO_FS.Virtio device, causing it to release = all + references to guest-side resources. The function may only be called after + VirtioFsInit() returns successfully and before VirtioFsUninit() is calle= d. + + @param[in] ExitBootEvent The VIRTIO_FS.ExitBoot event that has been + signaled. + + @param[in] VirtioFsAsVoid Pointer to the VIRTIO_FS object, passed in as + (VOID*). +**/ +VOID +EFIAPI +VirtioFsExitBoot ( + IN EFI_EVENT ExitBootEvent, + IN VOID *VirtioFsAsVoid + ) +{ + VIRTIO_FS *VirtioFs; + + VirtioFs =3D VirtioFsAsVoid; + DEBUG ((DEBUG_VERBOSE, "%a: VirtioFs=3D0x%p Label=3D\"%s\"\n", __FUNCTIO= N__, + VirtioFsAsVoid, VirtioFs->Label)); + VirtioFs->Virtio->SetDeviceStatus (VirtioFs->Virtio, 0); +} --=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 (#69016): https://edk2.groups.io/g/devel/message/69016 Mute This Topic: https://groups.io/mt/79022663/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-