From patchwork Mon Mar 14 12:53:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 63816 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp18100lbc; Mon, 14 Mar 2016 05:53:59 -0700 (PDT) X-Received: by 10.98.86.146 with SMTP id h18mr29985099pfj.9.1457960038269; Mon, 14 Mar 2016 05:53:58 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id h4si7733708pat.211.2016.03.14.05.53.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Mar 2016 05:53:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A1A7B1A1FAE; Mon, 14 Mar 2016 05:54:09 -0700 (PDT) X-Original-To: edk2-devel@ml01.01.org Delivered-To: edk2-devel@ml01.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8AB311A1E63 for ; Mon, 14 Mar 2016 05:54:08 -0700 (PDT) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 5D1CB3B72B; Mon, 14 Mar 2016 12:53:50 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-113-101.phx2.redhat.com [10.3.113.101]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2ECraIM012537; Mon, 14 Mar 2016 08:53:49 -0400 From: Laszlo Ersek To: edk2-devel@ml01.01.org Date: Mon, 14 Mar 2016 13:53:24 +0100 Message-Id: <1457960012-29481-8-git-send-email-lersek@redhat.com> In-Reply-To: <1457960012-29481-1-git-send-email-lersek@redhat.com> References: <56E6B2D9.5010507@redhat.com> <1457960012-29481-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Cc: Jordan Justen , Ard Biesheuvel Subject: [edk2] [wave 3 PATCH 07/15] OvmfPkg: VirtioLib: add Virtio10WriteFeatures() function X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" In VirtIo 1.0, a device can reject a self-inconsistent feature bitmap through the new VSTAT_FEATURES_OK status bit. (For example if the driver requests a higher level feature but clears a prerequisite feature.) This function is a small wrapper around VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures() that also verifies if the VirtIo 1.0 device accepts the feature bitmap. Cc: Ard Biesheuvel Cc: Jordan Justen Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/Include/Library/VirtioLib.h | 47 ++++++++++++ OvmfPkg/Library/VirtioLib/VirtioLib.c | 75 ++++++++++++++++++++ 2 files changed, 122 insertions(+) -- 1.8.3.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/OvmfPkg/Include/Library/VirtioLib.h b/OvmfPkg/Include/Library/VirtioLib.h index decd4418af3d..989283c67d70 100644 --- a/OvmfPkg/Include/Library/VirtioLib.h +++ b/OvmfPkg/Include/Library/VirtioLib.h @@ -16,14 +16,15 @@ #ifndef _VIRTIO_LIB_H_ #define _VIRTIO_LIB_H_ #include #include +#include /** Configure a virtio ring. This function sets up internal storage (the guest-host communication area) @@ -185,8 +186,54 @@ VirtioFlush ( IN VIRTIO_DEVICE_PROTOCOL *VirtIo, IN UINT16 VirtQueueId, IN OUT VRING *Ring, IN DESC_INDICES *Indices, OUT UINT32 *UsedLen OPTIONAL ); + +/** + + Report the feature bits to the VirtIo 1.0 device that the VirtIo 1.0 driver + understands. + + In VirtIo 1.0, a device can reject a self-inconsistent feature bitmap through + the new VSTAT_FEATURES_OK status bit. (For example if the driver requests a + higher level feature but clears a prerequisite feature.) This function is a + small wrapper around VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures() that also + verifies if the VirtIo 1.0 device accepts the feature bitmap. + + @param[in] VirtIo Report feature bits to this device. + + @param[in] Features The set of feature bits that the driver wishes + to report. The caller is responsible to perform + any masking before calling this function; the + value is directly written with + VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures(). + + @param[in,out] DeviceStatus On input, the status byte most recently written + to the device's status register. On output (even + on error), DeviceStatus will be updated so that + it is suitable for further status bit + manipulation and writing to the device's status + register. + + @retval EFI_SUCCESS The device accepted the configuration in Features. + + @return EFI_UNSUPPORTED The device rejected the configuration in Features. + + @retval EFI_UNSUPPORTED VirtIo->Revision is smaller than 1.0.0. + + @return Error codes from the SetGuestFeatures(), + SetDeviceStatus(), GetDeviceStatus() member + functions. + +**/ +EFI_STATUS +EFIAPI +Virtio10WriteFeatures ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN UINT64 Features, + IN OUT UINT8 *DeviceStatus + ); + #endif // _VIRTIO_LIB_H_ diff --git a/OvmfPkg/Library/VirtioLib/VirtioLib.c b/OvmfPkg/Library/VirtioLib/VirtioLib.c index 4b1d78b5a03e..845f206369a3 100644 --- a/OvmfPkg/Library/VirtioLib/VirtioLib.c +++ b/OvmfPkg/Library/VirtioLib/VirtioLib.c @@ -335,7 +335,82 @@ VirtioFlush ( UsedElem = &Ring->Used.UsedElem[LastUsedIdx % Ring->QueueSize]; ASSERT (UsedElem->Id == Indices->HeadDescIdx); *UsedLen = UsedElem->Len; } return EFI_SUCCESS; } + + +/** + + Report the feature bits to the VirtIo 1.0 device that the VirtIo 1.0 driver + understands. + + In VirtIo 1.0, a device can reject a self-inconsistent feature bitmap through + the new VSTAT_FEATURES_OK status bit. (For example if the driver requests a + higher level feature but clears a prerequisite feature.) This function is a + small wrapper around VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures() that also + verifies if the VirtIo 1.0 device accepts the feature bitmap. + + @param[in] VirtIo Report feature bits to this device. + + @param[in] Features The set of feature bits that the driver wishes + to report. The caller is responsible to perform + any masking before calling this function; the + value is directly written with + VIRTIO_DEVICE_PROTOCOL.SetGuestFeatures(). + + @param[in,out] DeviceStatus On input, the status byte most recently written + to the device's status register. On output (even + on error), DeviceStatus will be updated so that + it is suitable for further status bit + manipulation and writing to the device's status + register. + + @retval EFI_SUCCESS The device accepted the configuration in Features. + + @return EFI_UNSUPPORTED The device rejected the configuration in Features. + + @retval EFI_UNSUPPORTED VirtIo->Revision is smaller than 1.0.0. + + @return Error codes from the SetGuestFeatures(), + SetDeviceStatus(), GetDeviceStatus() member + functions. + +**/ +EFI_STATUS +EFIAPI +Virtio10WriteFeatures ( + IN VIRTIO_DEVICE_PROTOCOL *VirtIo, + IN UINT64 Features, + IN OUT UINT8 *DeviceStatus + ) +{ + EFI_STATUS Status; + + if (VirtIo->Revision < VIRTIO_SPEC_REVISION (1, 0, 0)) { + return EFI_UNSUPPORTED; + } + + Status = VirtIo->SetGuestFeatures (VirtIo, Features); + if (EFI_ERROR (Status)) { + return Status; + } + + *DeviceStatus |= VSTAT_FEATURES_OK; + Status = VirtIo->SetDeviceStatus (VirtIo, *DeviceStatus); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = VirtIo->GetDeviceStatus (VirtIo, DeviceStatus); + if (EFI_ERROR (Status)) { + return Status; + } + + if ((*DeviceStatus & VSTAT_FEATURES_OK) == 0) { + Status = EFI_UNSUPPORTED; + } + + return Status; +}