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.8282.1630071926947995091 for ; Fri, 27 Aug 2021 06:45:27 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q+ucO2Wf; 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=1630071926; 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=orUz/yV0MgG+mi9GYjlZ7YAFSMSrgep9SdLUzJHHTlo=; b=Q+ucO2WfpxIpyT1ya+l/me2GYmV+fIDOTG+D6yEkhBg0jpkYFemtpApDIZylwqQgjzxOWf LO7c6wujfniBI+Z098luFxqiB3V4+NZT5XAp7j4UvH7u85CEwRmAk2JV9Fk4i68tJ9iO9S HApwTtCX2PC5ZzBJVRHG07xaJObR9fg= 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-496-tbmmQFbdNoOYZQXKwMoJZA-1; Fri, 27 Aug 2021 09:45:24 -0400 X-MC-Unique: tbmmQFbdNoOYZQXKwMoJZA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BC81C87D544; Fri, 27 Aug 2021 13:45:23 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.91]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2660D60622; Fri, 27 Aug 2021 13:45:21 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id DC641180091C; 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 6/7] OvmfPkg/VirtioMmioDeviceLib: virtio 1.0: Adapt feature bit handling Date: Fri, 27 Aug 2021 15:44:58 +0200 Message-Id: <20210827134459.635098-7-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.13 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 Reviewed-by: Philippe Mathieu-Daude --- .../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 436da2a2b497..b43850e69da9 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