From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web08.22480.1629110937958525158 for ; Mon, 16 Aug 2021 03:48:58 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IQaOXuRk; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629110937; 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=i+fotHDUEANsO9stacruWpxI241iqwN6U3YGbDUymmw=; b=IQaOXuRkBC4wQ6yYf32vD//IXUrlYEBD8D587KibQmctm94Lc/rtzUbis/t/wNmp3eQaFR mhncSmBt8TRP3t3NBmpO17Ie7TW61GmRcIIv8Y++IO4MWXNCWDNQ+cUze4KfV4ibGxahHc qyZrGwfcJ6Gc7WJnjDnml6qCpsCB6g8= 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-602-0rPidKQXORikOzfg8fL1iQ-1; Mon, 16 Aug 2021 06:48:56 -0400 X-MC-Unique: 0rPidKQXORikOzfg8fL1iQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4E1571082924 for ; Mon, 16 Aug 2021 10:48:55 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.193.216]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 529D119C44; Mon, 16 Aug 2021 10:48:51 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id A87031800926; Mon, 16 Aug 2021 09:11:09 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Gerd Hoffmann Subject: [PATCH v2 4/4] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 feature bit handling Date: Mon, 16 Aug 2021 09:11:09 +0200 Message-Id: <20210816071109.101122-5-kraxel@redhat.com> In-Reply-To: <20210816071109.101122-1-kraxel@redhat.com> References: <20210816071109.101122-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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 has 64 feature bits instead of 32. Signed-off-by: Gerd Hoffmann --- .../VirtioMmioDeviceFunctions.c | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c index c7a22c1e1cc4..44fa24972ff4 100644 --- a/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c +++ b/OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDeviceFunctions.c @@ -20,6 +20,7 @@ VirtioMmioGetDeviceFeatures ( ) { VIRTIO_MMIO_DEVICE *Device; + UINT32 LowBits, HighBits; if (DeviceFeatures == NULL) { return EFI_INVALID_PARAMETER; @@ -27,7 +28,15 @@ VirtioMmioGetDeviceFeatures ( Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - *DeviceFeatures = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES); + if (Device->Version == 1) { + *DeviceFeatures = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES); + } else { + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES_SEL, 0); + LowBits = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES); + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES_SEL, 1); + HighBits = VIRTIO_CFG_READ (Device, VIRTIO_MMIO_OFFSET_HOST_FEATURES); + *DeviceFeatures = LShiftU64(HighBits, 32) | LowBits; + } return EFI_SUCCESS; } @@ -238,11 +247,20 @@ VirtioMmioSetGuestFeatures ( Device = VIRTIO_MMIO_DEVICE_FROM_VIRTIO_DEVICE (This); - if (Features > MAX_UINT32) { - return EFI_UNSUPPORTED; + if (Device->Version == 1) { + if (Features > MAX_UINT32) { + return EFI_UNSUPPORTED; + } + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES, + (UINT32)Features); + } else { + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES_SEL, 0); + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES, + (UINT32)Features); + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES_SEL, 1); + VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES, + (UINT32)RShiftU64(Features, 32)); } - VIRTIO_CFG_WRITE (Device, VIRTIO_MMIO_OFFSET_GUEST_FEATURES, - (UINT32)Features); return EFI_SUCCESS; } -- 2.31.1