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.web12.36954.1629192226539825408 for ; Tue, 17 Aug 2021 02:23:46 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XM00DDbv; 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=1629192225; 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=0Y+FRbSFtQEwa99b1D/5IFDxP2mQ6E7Xp0wIVFL2B1o=; b=XM00DDbvi0XrO5EPukdtuQ08GKx+QjymrAq30BOMLoF8XOojLGgjmw36hgz+cPfTyI9xKU hT1jEMEaJTvqZXxB5PLEPrwxTXSQbxO7+zRudr+phTaGvpugoiJfbntUq/X/BdOAI/9TpE ENLtCCR8YW6DaUWnJGmI0A0X1VW6f6M= 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-13-1gQfwM06Mr2u_shzIkplhQ-1; Tue, 17 Aug 2021 05:23:42 -0400 X-MC-Unique: 1gQfwM06Mr2u_shzIkplhQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BDC0C107ACF5 for ; Tue, 17 Aug 2021 09:23:41 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.193.216]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 086565DA2D; Tue, 17 Aug 2021 09:23:38 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 703DF1800909; Tue, 17 Aug 2021 11:23:29 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Gerd Hoffmann Subject: [PATCH v3 4/4] OvmfPkg/VirtioMmioDeviceLib: Add virtio 1.0 feature bit handling Date: Tue, 17 Aug 2021 11:23:29 +0200 Message-Id: <20210817092329.808150-5-kraxel@redhat.com> In-Reply-To: <20210817092329.808150-1-kraxel@redhat.com> References: <20210817092329.808150-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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 b9ee407eddc4..7215e0414c24 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 == VIRTIO_MMIO_DEVICE_VERSION_0_95) { + *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 == VIRTIO_MMIO_DEVICE_VERSION_0_95) { + 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