From mboxrd@z Thu Jan 1 00:00:00 1970 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.web09.8200.1630071923143696136 for ; Fri, 27 Aug 2021 06:45:23 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jRP6acku; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630071922; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SW1uzyRnDjlCWN61goAW7odmaml8MCXv2SC+RcmDX2s=; b=jRP6acku5Lz5s9LUl5z9LHdjNDT+NYiM1/9aFy8MnZDJWudymYcHJI9CL6LvjdO9ciNZyA CaWsPmkxKqk4umX8ovIQco5LP8YlFW1adGM7B6UK73GLqmITnmUrNNcRAU5Kum8LtHVoNn mhfhqAyYEOOTUorGTrWNeSBtjL+bu0U= 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-29-HSXizYpVNTyUA53S6oJYeQ-1; Fri, 27 Aug 2021 09:45:21 -0400 X-MC-Unique: HSXizYpVNTyUA53S6oJYeQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8AD9BC7400; Fri, 27 Aug 2021 13:45:19 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 736665FC22; Fri, 27 Aug 2021 13:45:17 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id D1AD51800843; Fri, 27 Aug 2021 15:44:59 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Jiewen Yao , Gerd Hoffmann , Ard Biesheuvel , Jordan Justen , Philippe Mathieu-Daude Subject: [PATCH v5 4/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Fix SetQueueAddress Date: Fri, 27 Aug 2021 15:44:56 +0200 Message-Id: <20210827134459.635098-5-kraxel@redhat.com> In-Reply-To: <20210827134459.635098-1-kraxel@redhat.com> References: <20210827134459.635098-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Virtio 1.0 allows a more flexible virtio ring layout, so we have to set addresses for descriptors avail flags and use flags separately. We continue to use a ring layout compatible with virtio 0.9.5 though, so no other changes are needed to setup the virtio queues. Signed-off-by: Gerd Hoffmann Reviewed-by: Philippe Mathieu-Daude --- .../VirtioMmioDeviceFunctions.c | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c index 50a4fd2100ee..cb1f9358eabd 100644 --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c +++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c @@ -183,13 +183,36 @@ VirtioMmioSetQueueAddress ( ) { VIRTIO_MMIO_DEVICE *Device; + UINT64 Address; ASSERT (RingBaseShift == 0); Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN, - (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT)); + if (Device->Version == VIRTIO_MMIO_DEVICE_VERSION_0_95) { + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_PFN, + (UINT32)((UINTN)Ring->Base >> EFI_PAGE_SHIFT)); + } else { + Address = (UINTN)Ring->Base; + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_DESC_LO, + (UINT32)Address); + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_DESC_HI, + (UINT32)RShiftU64(Address, 32)); + + Address = (UINTN)Ring->Avail.Flags; + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_LO, + (UINT32)Address); + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_AVAIL_HI, + (UINT32)RShiftU64(Address, 32)); + + Address = (UINTN)Ring->Used.Flags; + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_USED_LO, + (UINT32)Address); + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_USED_HI, + (UINT32)RShiftU64(Address, 32)); + + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_QUEUE_READY, 1); + } return EFI_SUCCESS; } -- 2.31.1