From patchwork Mon Mar 14 12:53:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 63812 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp18008lbc; Mon, 14 Mar 2016 05:53:48 -0700 (PDT) X-Received: by 10.98.68.71 with SMTP id r68mr29858260pfa.119.1457960026485; Mon, 14 Mar 2016 05:53:46 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id o63si1074765pfi.141.2016.03.14.05.53.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Mar 2016 05:53:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 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 A37481A1F97; Mon, 14 Mar 2016 05:54:03 -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 5ADAB1A1F9D for ; Mon, 14 Mar 2016 05:54:02 -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 2EE1CC00F1C4; Mon, 14 Mar 2016 12:53:44 +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 u2ECraII012537; Mon, 14 Mar 2016 08:53:42 -0400 From: Laszlo Ersek To: edk2-devel@ml01.01.org Date: Mon, 14 Mar 2016 13:53:20 +0100 Message-Id: <1457960012-29481-4-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 03/15] OvmfPkg: VIRTIO_DEVICE_PROTOCOL: pass VRING object to SetQueueAddress() 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, it is not enough to pass the base address of the virtio queue to the hypervisor (as a frame number); instead it will want the addresses of the descriptor table, the available ring, and the used ring separately. Pass the VRING object to the SetQueueAddress() member function; this will enable a virtio-1.0 implementation. Convert the current producers and consumers to this prototype. Cc: Ard Biesheuvel Cc: Jordan Justen Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/Include/Protocol/VirtioDevice.h | 12 ++++++------ OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h | 4 ++-- OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h | 4 ++-- OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c | 7 ++++--- OvmfPkg/VirtioBlkDxe/VirtioBlk.c | 3 +-- OvmfPkg/VirtioNetDxe/SnpInitialize.c | 3 +-- OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c | 6 +++--- OvmfPkg/VirtioRngDxe/VirtioRng.c | 3 +-- OvmfPkg/VirtioScsiDxe/VirtioScsi.c | 3 +-- 9 files changed, 21 insertions(+), 24 deletions(-) -- 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/Protocol/VirtioDevice.h b/OvmfPkg/Include/Protocol/VirtioDevice.h index f8afa7120a4c..910a4866e7ac 100644 --- a/OvmfPkg/Include/Protocol/VirtioDevice.h +++ b/OvmfPkg/Include/Protocol/VirtioDevice.h @@ -15,14 +15,16 @@ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #ifndef __VIRTIO_DEVICE_H__ #define __VIRTIO_DEVICE_H__ +#include + // VirtIo Specification Revision: Major[31:24].Minor[23:16].Revision[15:0 #define VIRTIO_SPEC_REVISION(major,minor,revision) \ ((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF)) #define VIRTIO_DEVICE_PROTOCOL_GUID { \ 0xfa920010, 0x6785, 0x4941, {0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a }\ } @@ -123,32 +125,30 @@ typedef EFI_STATUS (EFIAPI *VIRTIO_SET_GUEST_FEATURES) ( IN VIRTIO_DEVICE_PROTOCOL *This, IN UINT64 Features ); /** - Write the queue address field in the Virtio Header. - - The parameter Address must be the base address of the virtqueue divided - by 4096. + Write the queue address field(s) in the Virtio Header. @param[in] This This instance of VIRTIO_DEVICE_PROTOCOL - @param[in] Address The 32-bit Queue Address field + @param[in] Ring The initialized VRING object to take the + addresses from. @retval EFI_SUCCESS The data was written successfully. @retval EFI_UNSUPPORTED The underlying IO device doesn't support the provided address offset and write size. **/ typedef EFI_STATUS (EFIAPI *VIRTIO_SET_QUEUE_ADDRESS) ( IN VIRTIO_DEVICE_PROTOCOL *This, - IN UINT32 Address + IN VRING *Ring ); /** Write the queue select field in the Virtio Header. Writing to the queue select field sets the index of the queue to which diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h index 3b1e90ba9f3b..4130dbc043df 100644 --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h +++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice.h @@ -108,16 +108,16 @@ EFIAPI VirtioMmioSetQueueSel ( VIRTIO_DEVICE_PROTOCOL *This, UINT16 Sel ); EFI_STATUS VirtioMmioSetQueueAddress ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Address + IN VIRTIO_DEVICE_PROTOCOL *This, + IN VRING *Ring ); EFI_STATUS EFIAPI VirtioMmioSetQueueAlignment ( VIRTIO_DEVICE_PROTOCOL *This, UINT32 Alignment diff --git a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h index 95f82611e295..8f17a16c88f5 100644 --- a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h +++ b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciDevice.h @@ -120,16 +120,16 @@ VirtioPciSetGuestFeatures ( IN VIRTIO_DEVICE_PROTOCOL *This, IN UINT64 Features ); EFI_STATUS EFIAPI VirtioPciSetQueueAddress ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Address + IN VIRTIO_DEVICE_PROTOCOL *This, + IN VRING *Ring ); EFI_STATUS EFIAPI VirtioPciSetQueueSel ( VIRTIO_DEVICE_PROTOCOL *This, UINT16 Sel diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c index 2cd293ab88d9..53c734f6b1af 100644 --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c +++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c @@ -176,23 +176,24 @@ VirtioMmioSetQueueSel ( VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_SEL, Sel); return EFI_SUCCESS; } EFI_STATUS VirtioMmioSetQueueAddress ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Address + IN VIRTIO_DEVICE_PROTOCOL *This, + IN VRING *Ring ) { VIRTIO_MMIO_DEVICE *Device; Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN, Address); + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN, + (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT)); return EFI_SUCCESS; } EFI_STATUS EFIAPI VirtioMmioSetGuestFeatures ( diff --git a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c index b35f60c9d233..daccc7a5d06b 100644 --- a/OvmfPkg/VirtioBlkDxe/VirtioBlk.c +++ b/OvmfPkg/VirtioBlkDxe/VirtioBlk.c @@ -726,16 +726,15 @@ VirtioBlkInit ( if (EFI_ERROR (Status)) { goto ReleaseQueue; } // // step 4c -- Report GPFN (guest-physical frame number) of queue. // - Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, - (UINT32) ((UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT)); + Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring); if (EFI_ERROR (Status)) { goto ReleaseQueue; } // // step 5 -- Report understood features. There are no virtio-blk specific diff --git a/OvmfPkg/VirtioNetDxe/SnpInitialize.c b/OvmfPkg/VirtioNetDxe/SnpInitialize.c index 71b67fa52df9..f06b0a5a5742 100644 --- a/OvmfPkg/VirtioNetDxe/SnpInitialize.c +++ b/OvmfPkg/VirtioNetDxe/SnpInitialize.c @@ -91,16 +91,15 @@ VirtioNetInitRing ( if (EFI_ERROR (Status)) { goto ReleaseQueue; } // // step 4c -- report GPFN (guest-physical frame number) of queue // - Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, - (UINT32) ((UINTN) Ring->Base >> EFI_PAGE_SHIFT)); + Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, Ring); if (EFI_ERROR (Status)) { goto ReleaseQueue; } return EFI_SUCCESS; ReleaseQueue: diff --git a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c index 4ba37a2d1ceb..243aa14c2421 100644 --- a/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c +++ b/OvmfPkg/VirtioPciDeviceDxe/VirtioPciFunctions.c @@ -177,24 +177,24 @@ VirtioPciSetGuestFeatures ( return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_GUEST_FEATURES, sizeof (UINT32), Features); } EFI_STATUS EFIAPI VirtioPciSetQueueAddress ( - VIRTIO_DEVICE_PROTOCOL *This, - UINT32 Address + IN VIRTIO_DEVICE_PROTOCOL *This, + IN VRING *Ring ) { VIRTIO_PCI_DEVICE *Dev; Dev = VIRTIO_PCI_DEVICE_FROM_VIRTIO_DEVICE (This); return VirtioPciIoWrite (Dev, VIRTIO_PCI_OFFSET_QUEUE_ADDRESS, sizeof (UINT32), - Address); + (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT)); } EFI_STATUS EFIAPI VirtioPciSetQueueSel ( VIRTIO_DEVICE_PROTOCOL *This, UINT16 Sel diff --git a/OvmfPkg/VirtioRngDxe/VirtioRng.c b/OvmfPkg/VirtioRngDxe/VirtioRng.c index de4afefe7000..290bddeeecae 100644 --- a/OvmfPkg/VirtioRngDxe/VirtioRng.c +++ b/OvmfPkg/VirtioRngDxe/VirtioRng.c @@ -280,16 +280,15 @@ VirtioRngInit ( if (EFI_ERROR (Status)) { goto ReleaseQueue; } // // step 4c -- Report GPFN (guest-physical frame number) of queue. // - Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, - (UINT32) ((UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT)); + Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring); if (EFI_ERROR (Status)) { goto ReleaseQueue; } // // step 5 -- Report understood features and guest-tuneables. None are // currently defined for VirtioRng, and no generic features are needed by diff --git a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c index 52952886226b..162577bcb961 100644 --- a/OvmfPkg/VirtioScsiDxe/VirtioScsi.c +++ b/OvmfPkg/VirtioScsiDxe/VirtioScsi.c @@ -837,16 +837,15 @@ VirtioScsiInit ( if (EFI_ERROR (Status)) { goto ReleaseQueue; } // // step 4c -- Report GPFN (guest-physical frame number) of queue. // - Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, - (UINT32) ((UINTN) Dev->Ring.Base >> EFI_PAGE_SHIFT)); + Status = Dev->VirtIo->SetQueueAddress (Dev->VirtIo, &Dev->Ring); if (EFI_ERROR (Status)) { goto ReleaseQueue; } // // step 5 -- Report understood features and guest-tuneables. We want none of // the known (or unknown) VIRTIO_SCSI_F_* or VIRTIO_F_* capabilities (see