From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723463; cv=none; d=zohomail.com; s=zohoarc; b=cL+FLjpz/ChJPaPvh8j6GXlNZCtxpfCcIZrLg/JwYqx4J+J1C0JSW1EthKq+UyQXgk0qAj6pD2ja4w+bI+kS0OmgOzJ9o84IS5UIyQvgTeUcY02hO8uFgQz6j39kNJQ4aNoqOOkeS6bE78Yb0LldDNsICVl89ORL2IxRcBY843U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723463; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=R3RA+4kJ2h4JTjeFpL0gSf8whgbWPuACywxSkQzwxB0=; b=kjXoZNrP3ValHtAXeFoVW3csMnAqAvxbp+jolDgbCp0PKBmybNr9fgglFNwzR+LREz1ULFTXwI44AahWGdFfSO6wkBiJBXO4bXZgtodGwdONEXaA6A9Xwb/MnEOb9y0EIkeEndy48/1sHZxBEdDkCNwBC80a+3hmtIRWiiKC5dE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723463441988.0913135699789; Tue, 11 May 2021 01:57:43 -0700 (PDT) Received: from localhost ([::1]:53564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgOD0-0004b1-Bx for importer@patchew.org; Tue, 11 May 2021 04:57:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdZ-0007pS-Q1 for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:05 -0400 Received: from mga17.intel.com ([192.55.52.151]:32215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdX-0004r8-SB for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:05 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:48 -0700 IronPort-SDR: SXuCgVU/n9vu4S3G2MI2FJgObKM8bbwxF9LoGt65HjaxmTFPmVJpLvujA/pLBmtLOOonio0vYW SJGBIHY36p1w== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649381" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649381" IronPort-SDR: AVcfRN1SDdWayzzE/926PyOEH+G8xVu92lz1LMUWrjLowFcmMICiHJ7v3TRxjJKf7vVoB7ygg0 z6OFrs9OH8qw== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892173" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 01/20] ui: Get the fd associated with udmabuf driver Date: Tue, 11 May 2021 01:07:59 -0700 Message-Id: <20210511080818.366985-2-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Try to open the udmabuf dev node for the first time or return the fd if the device was previously opened. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- include/ui/console.h | 3 +++ ui/meson.build | 1 + ui/udmabuf.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 ui/udmabuf.c diff --git a/include/ui/console.h b/include/ui/console.h index ca3c7af6a6..b30b63976a 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -471,4 +471,7 @@ bool vnc_display_reload_certs(const char *id, Error **= errp); /* input.c */ int index_from_key(const char *key, size_t key_length); =20 +/* udmabuf.c */ +int udmabuf_fd(void); + #endif diff --git a/ui/meson.build b/ui/meson.build index e8d3ff41b9..7a709ff548 100644 --- a/ui/meson.build +++ b/ui/meson.build @@ -11,6 +11,7 @@ softmmu_ss.add(files( 'kbd-state.c', 'keymaps.c', 'qemu-pixman.c', + 'udmabuf.c', )) softmmu_ss.add([spice_headers, files('spice-module.c')]) =20 diff --git a/ui/udmabuf.c b/ui/udmabuf.c new file mode 100644 index 0000000000..e6234fd86f --- /dev/null +++ b/ui/udmabuf.c @@ -0,0 +1,40 @@ +/* + * udmabuf helper functions. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "ui/console.h" + +#ifdef CONFIG_LINUX + +#include +#include + +int udmabuf_fd(void) +{ + static bool first =3D true; + static int udmabuf; + + if (!first) { + return udmabuf; + } + first =3D false; + + udmabuf =3D open("/dev/udmabuf", O_RDWR); + if (udmabuf < 0) { + warn_report("open /dev/udmabuf: %s", strerror(errno)); + } + return udmabuf; +} + +#else + +int udmabuf_fd(void) +{ + return -1; +} + +#endif --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620722733; cv=none; d=zohomail.com; s=zohoarc; b=cU4h+mbGmsL6LNI2AnNn/oyolsfnNesFGBhrqlN4sfmTxTpYN+CAqFOoEGqot0uKZ83zhrw6iQaY8Lkn3f/hP4l+KmEUQ8oDD4Aj+ijGbVLO3TjtTLiT7aBxublxrRtqpHbPhKvAwwSxIhMS0/UUUA69GCi5McQpryLYVR9p9CE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620722733; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Rei4D+DIQWLh4yZ65ye70OSMYONjDXZe2zrBgu6ej0E=; b=L3ii+JNHgkDtc6FZWlPdVz8K0oklxzW4s5bKGSekGzymR/qFX41OcSvI2I4JEu5TA0CFc+Gd8zz0DmfE3dujGNygiHrvidvFVfMP63kOOa8j1LbewKgu47jtplaGTMOy+ruYYQQU7Lp7hvBeMf3mE1kyUKAUB2i6C3Pn8Rf3M3Y= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620722733712196.4697501201905; Tue, 11 May 2021 01:45:33 -0700 (PDT) Received: from localhost ([::1]:46106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgO1E-0005O4-BO for importer@patchew.org; Tue, 11 May 2021 04:45:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdX-0007gB-Co for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:03 -0400 Received: from mga17.intel.com ([192.55.52.151]:32215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdV-0004r8-AQ for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:03 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:48 -0700 IronPort-SDR: mUdAt5u3PnClPN8bg+WfwEZLRmgwVVgSDyHqdWK6QOy+48aD/xD7CEZU1ser0zTzxdsV0f7nxp jiTpEdoT37KA== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649382" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649382" IronPort-SDR: 6Hqh/jBzlKpSnclloHc7+PFgbIw+ApfUPTCf4F4COonrYZel1beEW/N/pf+8yZKy6bO4CVVRoB Iqo9J6N3weCg== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892176" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 02/20] headers: Add udmabuf.h Date: Tue, 11 May 2021 01:08:00 -0700 Message-Id: <20210511080818.366985-3-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This adds udmabuf header to standard headers so that the relevant udmabuf objects can be accessed in subsequent patches. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- include/standard-headers/linux/udmabuf.h | 32 ++++++++++++++++++++++++ scripts/update-linux-headers.sh | 3 +++ 2 files changed, 35 insertions(+) create mode 100644 include/standard-headers/linux/udmabuf.h diff --git a/include/standard-headers/linux/udmabuf.h b/include/standard-he= aders/linux/udmabuf.h new file mode 100644 index 0000000000..e19eb5b5ce --- /dev/null +++ b/include/standard-headers/linux/udmabuf.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_UDMABUF_H +#define _LINUX_UDMABUF_H + +#include "standard-headers/linux/types.h" + +#define UDMABUF_FLAGS_CLOEXEC 0x01 + +struct udmabuf_create { + uint32_t memfd; + uint32_t flags; + uint64_t offset; + uint64_t size; +}; + +struct udmabuf_create_item { + uint32_t memfd; + uint32_t __pad; + uint64_t offset; + uint64_t size; +}; + +struct udmabuf_create_list { + uint32_t flags; + uint32_t count; + struct udmabuf_create_item list[]; +}; + +#define UDMABUF_CREATE _IOW('u', 0x42, struct udmabuf_create) +#define UDMABUF_CREATE_LIST _IOW('u', 0x43, struct udmabuf_create_list) + +#endif /* _LINUX_UDMABUF_H */ diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers= .sh index 1050e36169..fea4d6eb65 100755 --- a/scripts/update-linux-headers.sh +++ b/scripts/update-linux-headers.sh @@ -34,6 +34,7 @@ cp_portable() { if grep '#include' "$f" | grep -v -e 'linux/virtio' \ -e 'linux/types' \ + -e 'linux/ioctl' \ -e 'stdint' \ -e 'linux/if_ether' \ -e 'input-event-codes' \ @@ -66,6 +67,7 @@ cp_portable() { -e 's/__BITS_PER_LONG/HOST_LONG_BITS/' \ -e '/\"drm.h\"/d' \ -e '/sys\/ioctl.h/d' \ + -e '/linux\/ioctl.h/d' \ -e 's/SW_MAX/SW_MAX_/' \ -e 's/atomic_t/int/' \ -e 's/__kernel_long_t/long/' \ @@ -190,6 +192,7 @@ for i in "$tmpdir"/include/linux/*virtio*.h \ "$tmpdir/include/linux/fuse.h" \ "$tmpdir/include/linux/input.h" \ "$tmpdir/include/linux/input-event-codes.h" \ + "$tmpdir/include/linux/udmabuf.h" \ "$tmpdir/include/linux/pci_regs.h" \ "$tmpdir/include/linux/ethtool.h" \ "$tmpdir/include/linux/const.h" \ --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620722876; cv=none; d=zohomail.com; s=zohoarc; b=H1Np/ge8AYLn0N45yjbSrQTe2lbG1ThKqwJdxe7TuzsakGKmkgFRvt4Dil+Z4oSGamsFPU84Sagr2RveAnNfloY5lG5t1DS9XzHfm2OXuTY9w0TUzcV4e06/JlaOvTyYPi12ObhH6gmQmZ5BtF0+7Hlp24Z0NBm5Wgog79ujZHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620722876; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iEE6VWxMnb+NHTd5ggNVVm4rPH7B+Y6F84q/NZYrkO4=; b=g8iRHW7bwlXI3Y4BTOKb/rWFK/9njiLAQUF/WFwvi2cMWL7svrC1jleGusXE34fZ7of6TqdjMpIflIgcM315fpGPkfHn+YcgXi1xoBLl+4xhDVIJg8noGoJmSHCMW8+QzCZhreThxTWQzThfoDK9RGJamtdMcU79GBJIr8yEecg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620722876890296.3657963632346; Tue, 11 May 2021 01:47:56 -0700 (PDT) Received: from localhost ([::1]:49168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgO3W-0007ci-CJ for importer@patchew.org; Tue, 11 May 2021 04:47:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdY-0007lT-OY for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:04 -0400 Received: from mga17.intel.com ([192.55.52.151]:32226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdW-0004x4-Ef for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:04 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: XTAdd2t3osuYgxh+D+KnBX5gYUDPw4KAWVnuvi3kpIDl2guc6EAmhjfELG803l3K9I4jl2SxDA Liqa4Y9fSSsg== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649384" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649384" IronPort-SDR: up+eu/ouwzw27PB0vIhqvVbcF3RQANm2r4+a8OsCBLTpCYCWgDsF9mcjkZKqmTHpevc0CcJJXY xVh0z+I+omDA== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892181" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 03/20] virtio-gpu: Add udmabuf helpers Date: Tue, 11 May 2021 01:08:01 -0700 Message-Id: <20210511080818.366985-4-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add helper functions to create a dmabuf for a resource and mmap it. To be able to create a dmabuf using the udmabuf driver, Qemu needs to be lauched with the memfd memory backend like this: qemu-system-x86_64 -m 8192m -object memory-backend-memfd,id=3Dmem1,size=3D8= 192M -machine memory-backend=3Dmem1 Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/meson.build | 2 +- hw/display/virtio-gpu-udmabuf.c | 186 ++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-gpu.h | 9 ++ 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 hw/display/virtio-gpu-udmabuf.c diff --git a/hw/display/meson.build b/hw/display/meson.build index 612cd6582d..576dea7a9d 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -56,7 +56,7 @@ softmmu_ss.add(when: [pixman, 'CONFIG_ATI_VGA'], if_true:= files('ati.c', 'ati_2d if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss =3D ss.source_set() virtio_gpu_ss.add(when: 'CONFIG_VIRTIO_GPU', - if_true: [files('virtio-gpu-base.c', 'virtio-gpu.c'), = pixman]) + if_true: [files('virtio-gpu-base.c', 'virtio-gpu.c', '= virtio-gpu-udmabuf.c'), pixman]) virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-u= ser-gpu.c')) hw_display_modules +=3D {'virtio-gpu': virtio_gpu_ss} =20 diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c new file mode 100644 index 0000000000..3e22d1702d --- /dev/null +++ b/hw/display/virtio-gpu-udmabuf.c @@ -0,0 +1,186 @@ +/* + * Virtio GPU Device + * + * Copyright Red Hat, Inc. 2013-2014 + * + * Authors: + * Dave Airlie + * Gerd Hoffmann + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qemu-common.h" +#include "qemu/iov.h" +#include "ui/console.h" +#include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-pixman.h" +#include "trace.h" + +#ifdef CONFIG_LINUX + +#include "exec/ramblock.h" +#include "sysemu/hostmem.h" +#include +#include +#include +#include "standard-headers/linux/udmabuf.h" + +static void virtio_gpu_create_udmabuf(struct virtio_gpu_simple_resource *r= es) +{ + struct udmabuf_create_list *list; + RAMBlock *rb; + ram_addr_t offset; + int udmabuf, i; + + udmabuf =3D udmabuf_fd(); + if (udmabuf < 0) { + return; + } + + list =3D g_malloc0(sizeof(struct udmabuf_create_list) + + sizeof(struct udmabuf_create_item) * res->iov_cnt); + + for (i =3D 0; i < res->iov_cnt; i++) { + rcu_read_lock(); + rb =3D qemu_ram_block_from_host(res->iov[i].iov_base, false, &offs= et); + rcu_read_unlock(); + + if (!rb || rb->fd < 0) { + g_free(list); + return; + } + + list->list[i].memfd =3D rb->fd; + list->list[i].offset =3D offset; + list->list[i].size =3D res->iov[i].iov_len; + } + + list->count =3D res->iov_cnt; + list->flags =3D UDMABUF_FLAGS_CLOEXEC; + + res->dmabuf_fd =3D ioctl(udmabuf, UDMABUF_CREATE_LIST, list); + if (res->dmabuf_fd < 0) { + warn_report("%s: UDMABUF_CREATE_LIST: %s", __func__, + strerror(errno)); + } + g_free(list); +} + +static void virtio_gpu_remap_udmabuf(struct virtio_gpu_simple_resource *re= s, + uint32_t size) +{ + res->remapped =3D mmap(NULL, size, PROT_READ, + MAP_SHARED, res->dmabuf_fd, 0); + if (res->remapped =3D=3D MAP_FAILED) { + warn_report("%s: dmabuf mmap failed: %s", __func__, + strerror(errno)); + res->remapped =3D NULL; + } +} + +static void virtio_gpu_destroy_udmabuf(struct virtio_gpu_simple_resource *= res, + uint32_t size) +{ + if (res->remapped) { + munmap(res->remapped, size); + res->remapped =3D NULL; + } + if (res->dmabuf_fd >=3D 0) { + close(res->dmabuf_fd); + res->dmabuf_fd =3D -1; + } +} + +static int find_memory_backend_type(Object *obj, void *opaque) +{ + bool *memfd_backend =3D opaque; + int ret; + + if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) { + HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); + RAMBlock *rb =3D backend->mr.ram_block; + + if (rb && rb->fd > 0) { + ret =3D fcntl(rb->fd, F_GET_SEALS); + if (ret > 0) { + *memfd_backend =3D true; + } + } + } + + return 0; +} + +bool virtio_gpu_have_udmabuf(void) +{ + Object *memdev_root; + int udmabuf; + bool memfd_backend =3D false; + + udmabuf =3D udmabuf_fd(); + if (udmabuf < 0) { + return false; + } + + memdev_root =3D object_resolve_path("/objects", NULL); + object_child_foreach(memdev_root, find_memory_backend_type, &memfd_bac= kend); + + return memfd_backend; +} + +void *virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +{ + void *pdata =3D NULL; + uint32_t size =3D res->width * res->height * 4; + + res->dmabuf_fd =3D -1; + if (res->iov_cnt =3D=3D 1) { + pdata =3D res->iov[0].iov_base; + } else { + virtio_gpu_create_udmabuf(res); + if (res->dmabuf_fd < 0) { + return NULL; + } + virtio_gpu_remap_udmabuf(res, size); + if (!res->remapped) { + return NULL; + } + pdata =3D res->remapped; + } + + return pdata; +} + +void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) +{ + uint32_t size =3D res->width * res->height * 4; + + if (res->remapped) { + virtio_gpu_destroy_udmabuf(res, size); + } +} + +#else + +bool virtio_gpu_have_udmabuf(void) +{ + /* nothing (stub) */ + return false; +} + +void *virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res) +{ + /* nothing (stub) */ + return NULL +} + +void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) +{ + /* nothing (stub) */ +} + +#endif diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 8ca2c55d9a..1025c4c8e4 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -50,6 +50,10 @@ struct virtio_gpu_simple_resource { uint32_t scanout_bitmask; pixman_image_t *image; uint64_t hostmem; + + int dmabuf_fd; + uint8_t *remapped; + QTAILQ_ENTRY(virtio_gpu_simple_resource) next; }; =20 @@ -238,6 +242,11 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, struct virtio_gpu_scanout *s, uint32_t resource_id); =20 +/* virtio-gpu-udmabuf.c */ +bool virtio_gpu_have_udmabuf(void); +void *virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res); +void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res); + /* virtio-gpu-3d.c */ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd); --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723068; cv=none; d=zohomail.com; s=zohoarc; b=HceSstNDViEPfbErJfQvAAgaQ9zKlV/Ewia6ALuFJBZrog0bjy/DQy4U+z2WuzVlBMI+HHh+JeLAweg4AURvAG1wP+nAf+QAgknQ8d0VHRuaZdrmSEejIa0zFm63EU6AjWudNGWkRkr9pUFv8JzL8vKedJD5pbN1lCb4Q3hEqjQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723068; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sNp1DiczMyinTXjZpc9fnLTi5Naj6LjtwroIFLyvw4A=; b=OTIBs7qmQ3ccJQw+kTe2gUB8OtidaJbCIG6d0SipmudLsPytiiFsNsRuhIUkFejOqjVTWzhcaPJAUEEsXkYkcJxoL9Kjdu5RJcqCskKTDic5heFCXV9ndKykVof0cwVBUfWTd9eNzkNYdb5R4gE5DuBfMsk7L/MbCLheWKoH5ZM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723068547191.42882786541043; Tue, 11 May 2021 01:51:08 -0700 (PDT) Received: from localhost ([::1]:56566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgO6b-0004Tv-GP for importer@patchew.org; Tue, 11 May 2021 04:51:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdU-0007WH-TA for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:00 -0400 Received: from mga17.intel.com ([192.55.52.151]:32215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdS-0004r8-Jk for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:00 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: rIlDp/BJxjgajxuxap1Yaa0X41mpV2iiDKxoSWSPT6tYBl0aFrvLtYwjqkVStp+TIBAmotIBs1 Pb8hU9KfBN/w== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649385" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649385" IronPort-SDR: R2mVg1UNmAKbqu2XSSZXayBsIc3Oc5FmFW3pf2iTs3FKQyuoHrnFdmV3M6H7V3QkrJrrX92YlY D9aA62gcfugg== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892183" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 04/20] virtio-gpu: Add virtio_gpu_find_check_resource Date: Tue, 11 May 2021 01:08:02 -0700 Message-Id: <20210511080818.366985-5-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Move finding the resource and validating its backing storage into one function. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu.c | 66 +++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 3607d3cab4..fec0bcf5c5 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -35,6 +35,10 @@ =20 static struct virtio_gpu_simple_resource* virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id); +static struct virtio_gpu_simple_resource * +virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t resource_id, + bool require_backing, + const char *caller, uint32_t *error); =20 static void virtio_gpu_cleanup_mapping(VirtIOGPU *g, struct virtio_gpu_simple_resource *= res); @@ -46,7 +50,8 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, struct virtio_gpu_simple_resource *res; uint32_t pixels; =20 - res =3D virtio_gpu_find_resource(g, resource_id); + res =3D virtio_gpu_find_check_resource(g, resource_id, false, + __func__, NULL); if (!res) { return; } @@ -114,6 +119,37 @@ virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resour= ce_id) return NULL; } =20 +static struct virtio_gpu_simple_resource * +virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t resource_id, + bool require_backing, + const char *caller, uint32_t *error) +{ + struct virtio_gpu_simple_resource *res; + + res =3D virtio_gpu_find_resource(g, resource_id); + if (!res) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid resource specified %d\= n", + caller, resource_id); + if (error) { + *error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + } + return NULL; + } + + if (require_backing) { + if (!res->iov || !res->image) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: no backing storage %d\n", + caller, resource_id); + if (error) { + *error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + } + return NULL; + } + } + + return res; +} + void virtio_gpu_ctrl_response(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd, struct virtio_gpu_ctrl_hdr *resp, @@ -352,11 +388,9 @@ static void virtio_gpu_transfer_to_host_2d(VirtIOGPU *= g, virtio_gpu_t2d_bswap(&t2d); trace_virtio_gpu_cmd_res_xfer_toh_2d(t2d.resource_id); =20 - res =3D virtio_gpu_find_resource(g, t2d.resource_id); - if (!res || !res->iov) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\= n", - __func__, t2d.resource_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + res =3D virtio_gpu_find_check_resource(g, t2d.resource_id, true, + __func__, &cmd->error); + if (!res) { return; } =20 @@ -410,11 +444,9 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, trace_virtio_gpu_cmd_res_flush(rf.resource_id, rf.r.width, rf.r.height, rf.r.x, rf.r.y= ); =20 - res =3D virtio_gpu_find_resource(g, rf.resource_id); + res =3D virtio_gpu_find_check_resource(g, rf.resource_id, false, + __func__, &cmd->error); if (!res) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\= n", - __func__, rf.resource_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; return; } =20 @@ -497,11 +529,9 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, } =20 /* create a surface for this scanout */ - res =3D virtio_gpu_find_resource(g, ss.resource_id); + res =3D virtio_gpu_find_check_resource(g, ss.resource_id, true, + __func__, &cmd->error); if (!res) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\= n", - __func__, ss.resource_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; return; } =20 @@ -708,11 +738,9 @@ virtio_gpu_resource_detach_backing(VirtIOGPU *g, virtio_gpu_bswap_32(&detach, sizeof(detach)); trace_virtio_gpu_cmd_res_back_detach(detach.resource_id); =20 - res =3D virtio_gpu_find_resource(g, detach.resource_id); - if (!res || !res->iov) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\= n", - __func__, detach.resource_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + res =3D virtio_gpu_find_check_resource(g, detach.resource_id, true, + __func__, &cmd->error); + if (!res) { return; } virtio_gpu_cleanup_mapping(g, res); --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723673; cv=none; d=zohomail.com; s=zohoarc; b=AL0VfTZBka254EdFTVunMWDP8eWhHWDftwB4WnnRqU1JPQ6Nt581afCZk+1lY5kQW1sbrJ/TdEk6pxR6I6RvqIH6zzH/Lr7LJ4jA9ZsDgY63DyFeA/aLjjXwXxGVJhwopTAwxi2nQpKx33AVOCBcovABS3qJADjLuqMrZz44R4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723673; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uqkz7fSkAratNer6L7OFIG/xgLbXmWKI/TXTxXu0fIQ=; b=C04VwGR8+lwRDxOWRTD5lyywvmpbc65DN2fR+/oC34gIQJzgLkS4fPjO6xkSCvnpXFYSbNtNV1BVca9wyHUAAhPHRLhXewA7rImeJu/kAqPMxYKn/s4I7Cssl6CJKk4BZZGiHlyAy3RDxQMz/1zpHvY8vjFNe70Er2xUdNRA1s8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723673228105.3492739313848; Tue, 11 May 2021 02:01:13 -0700 (PDT) Received: from localhost ([::1]:33782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgOGM-0001oG-UD for importer@patchew.org; Tue, 11 May 2021 05:01:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdb-0007va-E2 for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:07 -0400 Received: from mga17.intel.com ([192.55.52.151]:32226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdZ-0004x4-2l for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:07 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: p3cSapo3jFh55uycdebpfxZOu2tNcsWi8WqaYzpaUyUz3EIAgov31f/CSzMtmdoE3f6BOmRZ0M IyvY0uxDhEEg== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649386" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649386" IronPort-SDR: Nyq1QWonxHtqH1XN0n/Buk2GxDTZAV5R4Oq/FvqYraYACy1HZpp4K8l/hUVpj9kpW2JQBG7XyC Q5INnfQza2wQ== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892188" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 05/20] virtio-gpu: Refactor virtio_gpu_set_scanout Date: Tue, 11 May 2021 01:08:03 -0700 Message-Id: <20210511080818.366985-6-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Store the meta-data associated with a FB in a new object (struct virtio_gpu_framebuffer) and pass the object to set_scanout. Also move code in set_scanout into a do_set_scanout function. This will be helpful when adding set_scanout_blob API. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu.c | 151 +++++++++++++++++++-------------- include/hw/virtio/virtio-gpu.h | 8 ++ 2 files changed, 95 insertions(+), 64 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index fec0bcf5c5..6c27d8f42e 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -500,95 +500,118 @@ static void virtio_unref_resource(pixman_image_t *im= age, void *data) pixman_image_unref(data); } =20 -static void virtio_gpu_set_scanout(VirtIOGPU *g, - struct virtio_gpu_ctrl_command *cmd) +static void virtio_gpu_do_set_scanout(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_framebuffer *fb, + struct virtio_gpu_simple_resource *r= es, + struct virtio_gpu_rect *r, + uint32_t *error) { - struct virtio_gpu_simple_resource *res, *ores; + struct virtio_gpu_simple_resource *ores; struct virtio_gpu_scanout *scanout; - pixman_format_code_t format; - uint32_t offset; - int bpp; - struct virtio_gpu_set_scanout ss; + uint8_t *data; =20 - VIRTIO_GPU_FILL_CMD(ss); - virtio_gpu_bswap_32(&ss, sizeof(ss)); - trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id, - ss.r.width, ss.r.height, ss.r.x, ss.r= .y); - - if (ss.scanout_id >=3D g->parent_obj.conf.max_outputs) { + if (scanout_id >=3D g->parent_obj.conf.max_outputs) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout id specified %= d", - __func__, ss.scanout_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID; + __func__, scanout_id); + *error =3D VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID; return; } - - g->parent_obj.enable =3D 1; - if (ss.resource_id =3D=3D 0) { - virtio_gpu_disable_scanout(g, ss.scanout_id); - return; - } - - /* create a surface for this scanout */ - res =3D virtio_gpu_find_check_resource(g, ss.resource_id, true, - __func__, &cmd->error); - if (!res) { - return; - } - - if (ss.r.x > res->width || - ss.r.y > res->height || - ss.r.width < 16 || - ss.r.height < 16 || - ss.r.width > res->width || - ss.r.height > res->height || - ss.r.x + ss.r.width > res->width || - ss.r.y + ss.r.height > res->height) { + scanout =3D &g->parent_obj.scanout[scanout_id]; + + if (r->x > fb->width || + r->y > fb->height || + r->width < 16 || + r->height < 16 || + r->width > fb->width || + r->height > fb->height || + r->x + r->width > fb->width || + r->y + r->height > fb->height) { qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal scanout %d bounds for" - " resource %d, (%d,%d)+%d,%d vs %d %d\n", - __func__, ss.scanout_id, ss.resource_id, ss.r.x, ss.= r.y, - ss.r.width, ss.r.height, res->width, res->height); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + " resource %d, rect (%d,%d)+%d,%d, fb %d %d\n", + __func__, scanout_id, res->resource_id, + r->x, r->y, r->width, r->height, + fb->width, fb->height); + *error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; return; } =20 - scanout =3D &g->parent_obj.scanout[ss.scanout_id]; + g->parent_obj.enable =3D 1; + data =3D (uint8_t *)pixman_image_get_data(res->image); =20 - format =3D pixman_image_get_format(res->image); - bpp =3D DIV_ROUND_UP(PIXMAN_FORMAT_BPP(format), 8); - offset =3D (ss.r.x * bpp) + ss.r.y * pixman_image_get_stride(res->imag= e); - if (!scanout->ds || surface_data(scanout->ds) - !=3D ((uint8_t *)pixman_image_get_data(res->image) + offset) || - scanout->width !=3D ss.r.width || - scanout->height !=3D ss.r.height) { + /* create a surface for this scanout */ + if (!scanout->ds || + surface_data(scanout->ds) !=3D data + fb->offset || + scanout->width !=3D r->width || + scanout->height !=3D r->height) { pixman_image_t *rect; - void *ptr =3D (uint8_t *)pixman_image_get_data(res->image) + offse= t; - rect =3D pixman_image_create_bits(format, ss.r.width, ss.r.height,= ptr, - pixman_image_get_stride(res->image= )); - pixman_image_ref(res->image); - pixman_image_set_destroy_function(rect, virtio_unref_resource, - res->image); + void *ptr =3D data + fb->offset; + rect =3D pixman_image_create_bits(fb->format, r->width, r->height, + ptr, fb->stride); + + if (res->image) { + pixman_image_ref(res->image); + pixman_image_set_destroy_function(rect, virtio_unref_resource, + res->image); + } + /* realloc the surface ptr */ scanout->ds =3D qemu_create_displaysurface_pixman(rect); if (!scanout->ds) { - cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + *error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; return; } + pixman_image_unref(rect); - dpy_gfx_replace_surface(g->parent_obj.scanout[ss.scanout_id].con, + dpy_gfx_replace_surface(g->parent_obj.scanout[scanout_id].con, scanout->ds); } =20 ores =3D virtio_gpu_find_resource(g, scanout->resource_id); if (ores) { - ores->scanout_bitmask &=3D ~(1 << ss.scanout_id); + ores->scanout_bitmask &=3D ~(1 << scanout_id); + } + + res->scanout_bitmask |=3D (1 << scanout_id); + scanout->resource_id =3D res->resource_id; + scanout->x =3D r->x; + scanout->y =3D r->y; + scanout->width =3D r->width; + scanout->height =3D r->height; +} + +static void virtio_gpu_set_scanout(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_framebuffer fb =3D { 0 }; + struct virtio_gpu_set_scanout ss; + + VIRTIO_GPU_FILL_CMD(ss); + virtio_gpu_bswap_32(&ss, sizeof(ss)); + trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id, + ss.r.width, ss.r.height, ss.r.x, ss.r= .y); + + if (ss.resource_id =3D=3D 0) { + virtio_gpu_disable_scanout(g, ss.scanout_id); + return; } =20 - res->scanout_bitmask |=3D (1 << ss.scanout_id); - scanout->resource_id =3D ss.resource_id; - scanout->x =3D ss.r.x; - scanout->y =3D ss.r.y; - scanout->width =3D ss.r.width; - scanout->height =3D ss.r.height; + res =3D virtio_gpu_find_check_resource(g, ss.resource_id, true, + __func__, &cmd->error); + if (!res) { + return; + } + + fb.format =3D pixman_image_get_format(res->image); + fb.bytes_pp =3D DIV_ROUND_UP(PIXMAN_FORMAT_BPP(fb.format), 8); + fb.width =3D pixman_image_get_width(res->image); + fb.height =3D pixman_image_get_height(res->image); + fb.stride =3D pixman_image_get_stride(res->image); + fb.offset =3D ss.r.x * fb.bytes_pp + ss.r.y * fb.stride; + + virtio_gpu_do_set_scanout(g, ss.scanout_id, + &fb, res, &ss.r, &cmd->error); } =20 int virtio_gpu_create_mapping_iov(VirtIOGPU *g, diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 1025c4c8e4..cb72a03d1c 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -57,6 +57,14 @@ struct virtio_gpu_simple_resource { QTAILQ_ENTRY(virtio_gpu_simple_resource) next; }; =20 +struct virtio_gpu_framebuffer { + pixman_format_code_t format; + uint32_t bytes_pp; + uint32_t width, height; + uint32_t stride; + uint32_t offset; +}; + struct virtio_gpu_scanout { QemuConsole *con; DisplaySurface *ds; --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620722802; cv=none; d=zohomail.com; s=zohoarc; b=CyPoxv1MUhOZvh0V+w5PW6UlI+OzO5zumKQQvkrW/peESK8Nq/IxTHvGNMgYMqMVNdmirFoJjJVX1Kd1tGo75eZpWb/ql/FLV3yufRLB6pNMy62DRKCtjihp9y9aw+Lwot4Xl/9KhVAEP2yrseV8nvLt+vp5FkeKGKtw27iTx2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620722802; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BFGpVBTu4HWR8GlBw/+5y2RYcyKIBCcSilKtF0oZzuk=; b=nWyd/U7Jtt3/wI2vs5GnuY74NCmVXGcYAPzSU+7dyUGHVLX1tkWqC8aBq2OJqWyunrYNsnP9mbtGWAkO3lctCTLj8gJeNd99q9sKZTNuNSjPlMkzmMviibT6VIC9254nPgenTRdBdjaVCEYfN/+VFwmox0AalSQMTmj6PnIbT7M= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620722802049185.1410872206833; Tue, 11 May 2021 01:46:42 -0700 (PDT) Received: from localhost ([::1]:48078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgO2L-0006na-2J for importer@patchew.org; Tue, 11 May 2021 04:46:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdS-0007N1-Rp for qemu-devel@nongnu.org; Tue, 11 May 2021 04:20:58 -0400 Received: from mga17.intel.com ([192.55.52.151]:32215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdP-0004r8-Ba for qemu-devel@nongnu.org; Tue, 11 May 2021 04:20:57 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: AjoJEeGwymIF0o3KF1c1CzElaz2ei2uT4nciFpHQweoePBa5mSHeKkQC3X2ePKyMTGxsVmdYKU Jo/lunc6qBlw== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649387" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649387" IronPort-SDR: HR4fkuUUSsx+pEmNbRkOAduxYDSViIDWEcPhyMH7oRJZzPE1N5hLsSCGfro/w2bBRDrJrNBSvS B8zqw3EUjtXw== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892190" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 06/20] virtio-gpu: Refactor virtio_gpu_create_mapping_iov Date: Tue, 11 May 2021 01:08:04 -0700 Message-Id: <20210511080818.366985-7-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Instead of passing the attach_backing object to extract nr_entries and offset, explicitly pass these as arguments to this function. This will be helpful when adding create_blob API. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-virgl.c | 3 ++- hw/display/virtio-gpu.c | 18 +++++++++--------- include/hw/virtio/virtio-gpu.h | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 72c14d9132..092c6dc380 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -289,7 +289,8 @@ static void virgl_resource_attach_backing(VirtIOGPU *g, VIRTIO_GPU_FILL_CMD(att_rb); trace_virtio_gpu_cmd_res_back_attach(att_rb.resource_id); =20 - ret =3D virtio_gpu_create_mapping_iov(g, &att_rb, cmd, NULL, &res_iovs= , &res_niov); + ret =3D virtio_gpu_create_mapping_iov(g, att_rb.nr_entries, sizeof(att= _rb), + cmd, NULL, &res_iovs, &res_niov); if (ret !=3D 0) { cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; return; diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 6c27d8f42e..7a0db3a860 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -615,7 +615,7 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, } =20 int virtio_gpu_create_mapping_iov(VirtIOGPU *g, - struct virtio_gpu_resource_attach_backin= g *ab, + uint32_t nr_entries, uint32_t offset, struct virtio_gpu_ctrl_command *cmd, uint64_t **addr, struct iovec **iov, uint32_t *niov) @@ -624,17 +624,17 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, size_t esize, s; int e, v; =20 - if (ab->nr_entries > 16384) { + if (nr_entries > 16384) { qemu_log_mask(LOG_GUEST_ERROR, "%s: nr_entries is too big (%d > 16384)\n", - __func__, ab->nr_entries); + __func__, nr_entries); return -1; } =20 - esize =3D sizeof(*ents) * ab->nr_entries; + esize =3D sizeof(*ents) * nr_entries; ents =3D g_malloc(esize); s =3D iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, - sizeof(*ab), ents, esize); + offset, ents, esize); if (s !=3D esize) { qemu_log_mask(LOG_GUEST_ERROR, "%s: command data size incorrect %zu vs %zu\n", @@ -647,7 +647,7 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, if (addr) { *addr =3D NULL; } - for (e =3D 0, v =3D 0; e < ab->nr_entries; e++) { + for (e =3D 0, v =3D 0; e < nr_entries; e++) { uint64_t a =3D le64_to_cpu(ents[e].addr); uint32_t l =3D le32_to_cpu(ents[e].length); hwaddr len; @@ -659,8 +659,7 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, a, &len, DMA_DIRECTION_TO_DEVICE); if (!map) { qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to map MMIO mem= ory for" - " resource %d element %d\n", - __func__, ab->resource_id, e); + " element %d\n", __func__, e); virtio_gpu_cleanup_mapping_iov(g, *iov, v); g_free(ents); *iov =3D NULL; @@ -743,7 +742,8 @@ virtio_gpu_resource_attach_backing(VirtIOGPU *g, return; } =20 - ret =3D virtio_gpu_create_mapping_iov(g, &ab, cmd, &res->addrs, &res->= iov, &res->iov_cnt); + ret =3D virtio_gpu_create_mapping_iov(g, ab.nr_entries, sizeof(ab), cm= d, + &res->addrs, &res->iov, &res->iov_= cnt); if (ret !=3D 0) { cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; return; diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index cb72a03d1c..bff2eb1fdc 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -236,7 +236,7 @@ void virtio_gpu_get_display_info(VirtIOGPU *g, void virtio_gpu_get_edid(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd); int virtio_gpu_create_mapping_iov(VirtIOGPU *g, - struct virtio_gpu_resource_attach_backin= g *ab, + uint32_t nr_entries, uint32_t offset, struct virtio_gpu_ctrl_command *cmd, uint64_t **addr, struct iovec **iov, uint32_t *niov); --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723323; cv=none; d=zohomail.com; s=zohoarc; b=lWqROfWyFsL5lDSScAcYF/7FpcKia9Q8lxH9DJg97hkAsoB7xBw+cTvI/CzgO6ZZUcnyYhC+SJ+0+XmerxaovQ6HtkbRYiA4zyELQKtaw6cv0maTbl1bby4cdfAISIfl0PQosZAPr4n8tNivd5Ub/YHk303w+TK57AIlk8TwHR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723323; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3KQ/5WmwDXmQv95R1QnIoWopq2mY4zXqkTw7GGl2PTE=; b=bCXcWL0HVhSr4w/sbvlFWKax3fC0VfCpZ7ihpbkLGUofl0WaU9HO34rE3SE59f35v89i5I2JVsopCLj+yzJ09rTEVp8c9X1fkGgJRBA+Iylr1HLkHWntn6330jbaToPzOw+oiNFJe8HeRSHNlX3PLydF82+hTV59BS98tCBcQA8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162072332357280.70291262951105; Tue, 11 May 2021 01:55:23 -0700 (PDT) Received: from localhost ([::1]:45138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgOAk-0007Ic-FL for importer@patchew.org; Tue, 11 May 2021 04:55:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdZ-0007mq-43 for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:05 -0400 Received: from mga17.intel.com ([192.55.52.151]:32223) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdX-0004ul-8G for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:04 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: Mt6Ak9+jbjnm70JromUcvWYKCYw1RHl6hhDs5UJavcHZjEdLLws6YGl87lZ3CEvm/CKt9Fg6U1 1V2wglFQ1a3Q== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649388" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649388" IronPort-SDR: /WQelaNB/fXj8w0U9FL5Yet7l3kLrQQzhQgRA4wcJmvmzTb5ZYxYtX2YtklugOtZDLtDCoywyC r7B8bSDKjDYA== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892194" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 07/20] virtio-gpu: Add initial definitions for blob resources Date: Tue, 11 May 2021 01:08:05 -0700 Message-Id: <20210511080818.366985-8-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add the property bit, configuration flag and other relevant macros and definitions associated with this feature. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-base.c | 3 +++ hw/display/virtio-gpu.c | 14 ++++++++++++++ include/hw/virtio/virtio-gpu.h | 3 +++ 3 files changed, 20 insertions(+) diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c index afb3ee7d9a..dd294276cb 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -208,6 +208,9 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64= _t features, if (virtio_gpu_edid_enabled(g->conf)) { features |=3D (1 << VIRTIO_GPU_F_EDID); } + if (virtio_gpu_blob_enabled(g->conf)) { + features |=3D (1 << VIRTIO_GPU_F_RESOURCE_BLOB); + } =20 return features; } diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 7a0db3a860..f77a7fc7dd 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1108,6 +1108,18 @@ void virtio_gpu_device_realize(DeviceState *qdev, Er= ror **errp) VirtIODevice *vdev =3D VIRTIO_DEVICE(qdev); VirtIOGPU *g =3D VIRTIO_GPU(qdev); =20 + if (virtio_gpu_blob_enabled(g->parent_obj.conf)) { + if (!virtio_gpu_have_udmabuf()) { + error_setg(errp, "cannot enable blob resources without udmabuf= "); + return; + } + + if (virtio_gpu_virgl_enabled(g->parent_obj.conf)) { + error_setg(errp, "blobs and virgl are not compatible (yet)"); + return; + } + } + if (!virtio_gpu_base_device_realize(qdev, virtio_gpu_handle_ctrl_cb, virtio_gpu_handle_cursor_cb, @@ -1201,6 +1213,8 @@ static Property virtio_gpu_properties[] =3D { VIRTIO_GPU_BASE_PROPERTIES(VirtIOGPU, parent_obj.conf), DEFINE_PROP_SIZE("max_hostmem", VirtIOGPU, conf_max_hostmem, 256 * MiB), + DEFINE_PROP_BIT("blob", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_BLOB_ENABLED, false), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index bff2eb1fdc..1c7b4171c8 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -87,6 +87,7 @@ enum virtio_gpu_base_conf_flags { VIRTIO_GPU_FLAG_STATS_ENABLED, VIRTIO_GPU_FLAG_EDID_ENABLED, VIRTIO_GPU_FLAG_DMABUF_ENABLED, + VIRTIO_GPU_FLAG_BLOB_ENABLED, }; =20 #define virtio_gpu_virgl_enabled(_cfg) \ @@ -97,6 +98,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_EDID_ENABLED)) #define virtio_gpu_dmabuf_enabled(_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED)) +#define virtio_gpu_blob_enabled(_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED)) =20 struct virtio_gpu_base_conf { uint32_t max_outputs; --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723909; cv=none; d=zohomail.com; s=zohoarc; b=jRCbVgm9S82YhL9jeYX12a6KJNXdqarsuDHuCDitFD/GMrxVsNchw1L72PD7gVI/ViHzCdQJHM9mYQPX7fyToIGL7ta+lVhYo1x6cRPLQLWc6f3a3FPkq2e6LpWYfUYuRp3pwVS42oDe+WrvSnn7Vte5e8Q6l2fs9stSgM6U+Mk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723909; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=s/rAceNgtX04Nb8bXUUGq//1K1G7eCQMQsqeQ6RayD4=; b=J25DYuOWxLuWanc4lyoPOw/BBRhyjU6iVk0sf3qiuw1Rk3OC9SfHcmNHl8CHr2E1Pa0CcTBazNPRXAnqO0eQkfAHQ153syo+5kJlV30yXumGKglopQxp088P6vIqQ+s0cfHxQQcMz/cXvDpmsW7p1S4gRihkZouzprzEE06hhr4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723909746202.03278858619808; Tue, 11 May 2021 02:05:09 -0700 (PDT) Received: from localhost ([::1]:42076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgOKC-0007WI-0T for importer@patchew.org; Tue, 11 May 2021 05:05:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdb-0007xS-TJ for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:07 -0400 Received: from mga17.intel.com ([192.55.52.151]:32223) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdZ-0004ul-IN for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:07 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: KnxQcg5iyN5kcQsbfK/ctSK5mAdAdNVtAuDjhErEpiTFH55czN+RfThAuxGMN0OrlDGp0/Sj1n ulRbEDMbazaQ== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649389" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649389" IronPort-SDR: vQldoIUxyc2+lLfQRnaLflFKKtZmkGLLAAzIPjLgiGeeb0rqNSX8sAQA/WO05+ZnQNkDvAHHPS QqS9/OrKeM1Q== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892197" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 08/20] virtio-gpu: Add virtio_gpu_resource_create_blob Date: Tue, 11 May 2021 01:08:06 -0700 Message-Id: <20210511080818.366985-9-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This API allows Qemu to register the blob allocated by the Guest as a new resource and map its backing storage. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/trace-events | 1 + hw/display/virtio-gpu-udmabuf.c | 4 ++ hw/display/virtio-gpu.c | 75 ++++++++++++++++++++++++++-- include/hw/virtio/virtio-gpu-bswap.h | 9 ++++ include/hw/virtio/virtio-gpu.h | 2 + 5 files changed, 88 insertions(+), 3 deletions(-) diff --git a/hw/display/trace-events b/hw/display/trace-events index 957b8ba994..99e5256aac 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -42,6 +42,7 @@ virtio_gpu_cmd_get_edid(uint32_t scanout) "scanout %d" virtio_gpu_cmd_set_scanout(uint32_t id, uint32_t res, uint32_t w, uint32_t= h, uint32_t x, uint32_t y) "id %d, res 0x%x, w %d, h %d, x %d, y %d" virtio_gpu_cmd_res_create_2d(uint32_t res, uint32_t fmt, uint32_t w, uint3= 2_t h) "res 0x%x, fmt 0x%x, w %d, h %d" virtio_gpu_cmd_res_create_3d(uint32_t res, uint32_t fmt, uint32_t w, uint3= 2_t h, uint32_t d) "res 0x%x, fmt 0x%x, w %d, h %d, d %d" +virtio_gpu_cmd_res_create_blob(uint32_t res, uint64_t size) "res 0x%x, siz= e %" PRId64 virtio_gpu_cmd_res_unref(uint32_t res) "res 0x%x" virtio_gpu_cmd_res_back_attach(uint32_t res) "res 0x%x" virtio_gpu_cmd_res_back_detach(uint32_t res) "res 0x%x" diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c index 3e22d1702d..df79535a3a 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -137,6 +137,10 @@ void *virtio_gpu_init_udmabuf(struct virtio_gpu_simple= _resource *res) void *pdata =3D NULL; uint32_t size =3D res->width * res->height * 4; =20 + if (res->blob_size) { + size =3D res->blob_size; + } + res->dmabuf_fd =3D -1; if (res->iov_cnt =3D=3D 1) { pdata =3D res->iov[0].iov_base; diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index f77a7fc7dd..1b6e586f94 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -137,7 +137,7 @@ virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t r= esource_id, } =20 if (require_backing) { - if (!res->iov || !res->image) { + if (!res->iov || (!res->image && !res->blob)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: no backing storage %d\n", caller, resource_id); if (error) { @@ -313,6 +313,64 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g, g->hostmem +=3D res->hostmem; } =20 +static void virtio_gpu_resource_create_blob(VirtIOGPU *g, + struct virtio_gpu_ctrl_command= *cmd) +{ + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_resource_create_blob cblob; + int ret; + + VIRTIO_GPU_FILL_CMD(cblob); + virtio_gpu_create_blob_bswap(&cblob); + trace_virtio_gpu_cmd_res_create_blob(cblob.resource_id, cblob.size); + + if (cblob.resource_id =3D=3D 0) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: resource id 0 is not allowed\n= ", + __func__); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + return; + } + + res =3D virtio_gpu_find_resource(g, cblob.resource_id); + if (res) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: resource already exists %d\n", + __func__, cblob.resource_id); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + return; + } + + res =3D g_new0(struct virtio_gpu_simple_resource, 1); + res->resource_id =3D cblob.resource_id; + res->blob_size =3D cblob.size; + + if (cblob.blob_mem !=3D VIRTIO_GPU_BLOB_MEM_GUEST && + cblob.blob_flags !=3D VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid memory type\n", + __func__); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + g_free(res); + return; + } + + if (res->iov) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } + + ret =3D virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(cblo= b), + cmd, &res->addrs, &res->iov, + &res->iov_cnt); + if (ret !=3D 0) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } + + res->iov_cnt =3D cblob.nr_entries; + res->blob =3D virtio_gpu_init_udmabuf(res); + + QTAILQ_INSERT_HEAD(&g->reslist, res, next); +} + static void virtio_gpu_disable_scanout(VirtIOGPU *g, int scanout_id) { struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[scanout_= id]; @@ -390,7 +448,7 @@ static void virtio_gpu_transfer_to_host_2d(VirtIOGPU *g, =20 res =3D virtio_gpu_find_check_resource(g, t2d.resource_id, true, __func__, &cmd->error); - if (!res) { + if (!res || res->blob) { return; } =20 @@ -446,7 +504,7 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, =20 res =3D virtio_gpu_find_check_resource(g, rf.resource_id, false, __func__, &cmd->error); - if (!res) { + if (!res || res->blob) { return; } =20 @@ -715,6 +773,10 @@ static void virtio_gpu_cleanup_mapping(VirtIOGPU *g, res->iov_cnt =3D 0; g_free(res->addrs); res->addrs =3D NULL; + + if (res->blob) { + virtio_gpu_fini_udmabuf(res); + } } =20 static void @@ -785,6 +847,13 @@ void virtio_gpu_simple_process_cmd(VirtIOGPU *g, case VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: virtio_gpu_resource_create_2d(g, cmd); break; + case VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB: + if (!virtio_gpu_blob_enabled(g->parent_obj.conf)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + break; + } + virtio_gpu_resource_create_blob(g, cmd); + break; case VIRTIO_GPU_CMD_RESOURCE_UNREF: virtio_gpu_resource_unref(g, cmd); break; diff --git a/include/hw/virtio/virtio-gpu-bswap.h b/include/hw/virtio/virti= o-gpu-bswap.h index 203f9e1718..d23ac5cc4a 100644 --- a/include/hw/virtio/virtio-gpu-bswap.h +++ b/include/hw/virtio/virtio-gpu-bswap.h @@ -59,4 +59,13 @@ virtio_gpu_t2d_bswap(struct virtio_gpu_transfer_to_host_= 2d *t2d) le32_to_cpus(&t2d->padding); } =20 +static inline void +virtio_gpu_create_blob_bswap(struct virtio_gpu_resource_create_blob *cblob) +{ + virtio_gpu_ctrl_hdr_bswap(&cblob->hdr); + le32_to_cpus(&cblob->resource_id); + le32_to_cpus(&cblob->blob_flags); + le64_to_cpus(&cblob->size); +} + #endif diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 1c7b4171c8..fa6ee5ac98 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -51,6 +51,8 @@ struct virtio_gpu_simple_resource { pixman_image_t *image; uint64_t hostmem; =20 + uint64_t blob_size; + void *blob; int dmabuf_fd; uint8_t *remapped; =20 --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620724113; cv=none; d=zohomail.com; s=zohoarc; b=VigPMf7L2QaZxePDglirX89zeh6T83zVa1AW/W5z9KIGjWMruKxrKtZtP0AC/ddWeyjAi+D5KUihRaLFU+l4Rjd8psZDB1nnrfcslW0OGiLUlemvKTH8FgM8CL/9zWBEMSikH36C/8pRlLwWn1H+KyydhEgnp1+A5y7eN+6ZA3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620724113; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1ExHwjYndR4DACNkoiyAZneT3lP4S86o1UFenZxYSMA=; b=CD/UCAESjTDQa3NuyOm4q9Zgi6gppay9wZS40/5FaIjMxKDF3lW/KzFta2xZBnX5T9m23oqNOCsP5yhBusF67ZQ8hR9p1rJEuT+NomFVg78+wkb/e1ayG4jg+sv0tTuH07Pn1m3E/MRD3eJY0agZrVFzdcAYY50ZHhmrB1LV0hA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620724113277696.4589832609064; Tue, 11 May 2021 02:08:33 -0700 (PDT) Received: from localhost ([::1]:50380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgONT-0004m1-Hy for importer@patchew.org; Tue, 11 May 2021 05:08:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdd-00081b-2q for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:09 -0400 Received: from mga17.intel.com ([192.55.52.151]:32215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNda-0004r8-5Z for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:08 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: C7a+x6J5m6N7pi+k5r5MKYs7asxVOiy5WOIu8yNdyAxkp9Pf8NuAcUmb5vKJn1ar72IgEVwVLS EoS40yT6fJIg== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649390" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649390" IronPort-SDR: HgSoYWl0FLeImfRXDoZhU+qewJS0u9wAKMeJ3ViTjCIrTO4/cVQBMPCSOHbeg3eKAjJEm/RzPo NEuCnOtN/7IA== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892200" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 09/20] ui/pixman: Add qemu_pixman_to_drm_format() Date: Tue, 11 May 2021 01:08:07 -0700 Message-Id: <20210511080818.366985-10-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This new function to get the drm_format associated with a pixman format will be useful while creating a dmabuf. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- include/ui/qemu-pixman.h | 1 + ui/qemu-pixman.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/include/ui/qemu-pixman.h b/include/ui/qemu-pixman.h index 87737a6f16..806ddcd7cd 100644 --- a/include/ui/qemu-pixman.h +++ b/include/ui/qemu-pixman.h @@ -62,6 +62,7 @@ typedef struct PixelFormat { PixelFormat qemu_pixelformat_from_pixman(pixman_format_code_t format); pixman_format_code_t qemu_default_pixman_format(int bpp, bool native_endia= n); pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format); +uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman); int qemu_pixman_get_type(int rshift, int gshift, int bshift); pixman_format_code_t qemu_pixman_get_format(PixelFormat *pf); bool qemu_pixman_check_format(DisplayChangeListener *dcl, diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c index 85f2945e88..3ab7e2e958 100644 --- a/ui/qemu-pixman.c +++ b/ui/qemu-pixman.c @@ -89,21 +89,34 @@ pixman_format_code_t qemu_default_pixman_format(int bpp= , bool native_endian) } =20 /* Note: drm is little endian, pixman is native endian */ +static const struct { + uint32_t drm_format; + pixman_format_code_t pixman_format; +} drm_format_pixman_map[] =3D { + { DRM_FORMAT_RGB888, PIXMAN_LE_r8g8b8 }, + { DRM_FORMAT_ARGB8888, PIXMAN_LE_a8r8g8b8 }, + { DRM_FORMAT_XRGB8888, PIXMAN_LE_x8r8g8b8 } +}; + pixman_format_code_t qemu_drm_format_to_pixman(uint32_t drm_format) { - static const struct { - uint32_t drm_format; - pixman_format_code_t pixman; - } map[] =3D { - { DRM_FORMAT_RGB888, PIXMAN_LE_r8g8b8 }, - { DRM_FORMAT_ARGB8888, PIXMAN_LE_a8r8g8b8 }, - { DRM_FORMAT_XRGB8888, PIXMAN_LE_x8r8g8b8 } - }; int i; =20 - for (i =3D 0; i < ARRAY_SIZE(map); i++) { - if (drm_format =3D=3D map[i].drm_format) { - return map[i].pixman; + for (i =3D 0; i < ARRAY_SIZE(drm_format_pixman_map); i++) { + if (drm_format =3D=3D drm_format_pixman_map[i].drm_format) { + return drm_format_pixman_map[i].pixman_format; + } + } + return 0; +} + +uint32_t qemu_pixman_to_drm_format(pixman_format_code_t pixman_format) +{ + int i; + + for (i =3D 0; i < ARRAY_SIZE(drm_format_pixman_map); i++) { + if (pixman_format =3D=3D drm_format_pixman_map[i].pixman_format) { + return drm_format_pixman_map[i].drm_format; } } return 0; --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723012; cv=none; d=zohomail.com; s=zohoarc; b=S6aLTgLQgdtrdBqs1qbK6k6i2vEGUgbdRxZSu4wVoYVS9WMp6mTQDFP6+D61G5Mn0UBt0IB48C9LgiZaI2aGB56n64EqJzbpo2Y4LAdOYLJ1BBfjpzGk+SbeMFMd8voY9ZpUQybXUT3RfkXnMfDa1sHMdiCrcANaw0SrggaO2no= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723012; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jCjZau58uvKr3zcEzdawMpUlIbyHal13ieltahmYqL0=; b=MsuDIf22BPlZq6K6xZ8fVUoHcpCWTgU/TAByUA3B4llbCMjeZbBLahj9xrO7GACq8/TLhS0hhHx8eSFvv3kpH5et61VscF6b/lWfm1FeAwwUMSoWw8MPjLOmYNaZnrzw+PNHi9VDkuyxhNHGwBA2dGF5b4KahYgjmKfqN+HxOKE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162072301256568.54317792372638; Tue, 11 May 2021 01:50:12 -0700 (PDT) Received: from localhost ([::1]:54498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgO5j-00032t-Hp for importer@patchew.org; Tue, 11 May 2021 04:50:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdf-00083A-U8 for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:17 -0400 Received: from mga17.intel.com ([192.55.52.151]:32226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdb-0004x4-Pc for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:11 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: yGZ8nsB88wbvnlgzdAT/7kfLWXVkTe9QdBrIpF9Py+gr2MP16IbKm9Mi1onudkZIxavJ1ZFQ3x pC4vMFlSyjkQ== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649391" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649391" IronPort-SDR: 0GDQX+dP7NE90kHtS43Go0Weu4C52YHKjWJsl6SH03ka1jIf6ha0DSvGQ2nNdFtVpTtUh1+U2o zUVAPUquxZ5g== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892203" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 10/20] virtio-gpu: Add helpers to create and destroy dmabuf objects Date: Tue, 11 May 2021 01:08:08 -0700 Message-Id: <20210511080818.366985-11-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" These helpers can be useful for creating dmabuf objects from blobs and submitting them to the UI. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-udmabuf.c | 74 +++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-gpu.h | 15 +++++++ 2 files changed, 89 insertions(+) diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c index df79535a3a..a9cb83d686 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -168,6 +168,71 @@ void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_= resource *res) } } =20 +static void virtio_gpu_free_dmabuf(VirtIOGPU *g, VGPUDMABuf *dmabuf) +{ + struct virtio_gpu_scanout *scanout; + + scanout =3D &g->parent_obj.scanout[dmabuf->scanout_id]; + dpy_gl_release_dmabuf(scanout->con, &dmabuf->buf); + QTAILQ_REMOVE(&g->dmabuf.bufs, dmabuf, next); + g_free(dmabuf); +} + +static VGPUDMABuf +*virtio_gpu_create_dmabuf(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_simple_resource *res, + struct virtio_gpu_framebuffer *fb) +{ + VGPUDMABuf *dmabuf; + + if (res->dmabuf_fd < 0) { + return NULL; + } + + dmabuf =3D g_new0(VGPUDMABuf, 1); + dmabuf->buf.width =3D fb->width; + dmabuf->buf.height =3D fb->height; + dmabuf->buf.stride =3D fb->stride; + dmabuf->buf.fourcc =3D qemu_pixman_to_drm_format(fb->format); + dmabuf->buf.fd =3D res->dmabuf_fd; + + dmabuf->scanout_id =3D scanout_id; + QTAILQ_INSERT_HEAD(&g->dmabuf.bufs, dmabuf, next); + + return dmabuf; +} + +int virtio_gpu_update_dmabuf(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_simple_resource *res, + struct virtio_gpu_framebuffer *fb) +{ + struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[scanout_= id]; + VGPUDMABuf *new_primary, *old_primary; + + new_primary =3D virtio_gpu_create_dmabuf(g, scanout_id, res, fb); + if (!new_primary) { + return -EINVAL; + } + + if (g->dmabuf.primary) { + old_primary =3D g->dmabuf.primary; + } + + g->dmabuf.primary =3D new_primary; + qemu_console_resize(scanout->con, + new_primary->buf.width, + new_primary->buf.height); + dpy_gl_scanout_dmabuf(scanout->con, &new_primary->buf); + + if (old_primary) { + virtio_gpu_free_dmabuf(g, old_primary); + } + + return 0; +} + #else =20 bool virtio_gpu_have_udmabuf(void) @@ -187,4 +252,13 @@ void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_= resource *res) /* nothing (stub) */ } =20 +int virtio_gpu_update_dmabuf(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_simple_resource *res, + struct virtio_gpu_framebuffer *fb) +{ + /* nothing (stub) */ + return 0; +} + #endif diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index fa6ee5ac98..31b2bcc57b 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -150,6 +150,12 @@ struct VirtIOGPUBaseClass { DEFINE_PROP_UINT32("xres", _state, _conf.xres, 1024), \ DEFINE_PROP_UINT32("yres", _state, _conf.yres, 768) =20 +typedef struct VGPUDMABuf { + QemuDmaBuf buf; + uint32_t scanout_id; + QTAILQ_ENTRY(VGPUDMABuf) next; +} VGPUDMABuf; + struct VirtIOGPU { VirtIOGPUBase parent_obj; =20 @@ -178,6 +184,11 @@ struct VirtIOGPU { uint32_t req_3d; uint32_t bytes_3d; } stats; + + struct { + QTAILQ_HEAD(, VGPUDMABuf) bufs; + VGPUDMABuf *primary; + } dmabuf; }; =20 struct VirtIOGPUClass { @@ -259,6 +270,10 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, bool virtio_gpu_have_udmabuf(void); void *virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res); void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res); +int virtio_gpu_update_dmabuf(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_simple_resource *res, + struct virtio_gpu_framebuffer *fb); =20 /* virtio-gpu-3d.c */ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723176; cv=none; d=zohomail.com; s=zohoarc; b=SoKLwlPjlTbohDFcDLRSJkt3KqMZGDV4zpWBQVHg7pi8dz9eZ2TB9JH1AAQK9zEdX4AthQslgOwq84rY2gn7825hTh7eytyPqzzTnm5Ea0dHk06bH6+EQqIvlkmv0hQShj5uOde84Zi3KkVVf3zr6lrJ9Ey5hXmh8o0Ts+sAMs8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723176; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=g6AWWThE88TV4KVTXfaFTy9Kn9uZpg10Imc2KJ4Wykw=; b=UuH1Gask0kMFDKxewwC2fRoDDfQlhMSKQnVRN6M/n2lYoopKfVXurjEktAvHtb/GOL7tMUIgdARmTZ4hjWgmuSBrcoeHHY35bpcrt7E79DirteDG4Or9d243lCQRuZcukDEqQBFiiopHU7p8Rygx8gh3bHiql9wc/vLNiPepQaU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723176360948.7639140007713; Tue, 11 May 2021 01:52:56 -0700 (PDT) Received: from localhost ([::1]:34688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgO8N-0000La-5w for importer@patchew.org; Tue, 11 May 2021 04:52:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdt-00086D-9u for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:25 -0400 Received: from mga17.intel.com ([192.55.52.151]:32223) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdm-0004ul-HH for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:24 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: mLnWeMOHUHk8metnA56VEm9GfuGmmgOmsu3ErqJ8/ajUyhR9in81eK9w8M8FeW/ERV3q/ps6ug HkYn82PrjzcA== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649392" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649392" IronPort-SDR: gDyZNHvPJFKnUGdxn3V6IZfCdAPjBxo8LIhqacmle/JJN7rjRqDZYOKKw+Dan5V4INw9O+esgy q0ucMeDOieJw== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892206" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 11/20] virtio-gpu: Factor out update scanout Date: Tue, 11 May 2021 01:08:09 -0700 Message-Id: <20210511080818.366985-12-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Creating a small helper function for updating the scanout will be useful in the next patch where this needs to be done early in do_set_scanout before returning. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 1b6e586f94..f96f7590b1 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -558,6 +558,28 @@ static void virtio_unref_resource(pixman_image_t *imag= e, void *data) pixman_image_unref(data); } =20 +static void virtio_gpu_update_scanout(VirtIOGPU *g, + uint32_t scanout_id, + struct virtio_gpu_simple_resource *r= es, + struct virtio_gpu_rect *r) +{ + struct virtio_gpu_simple_resource *ores; + struct virtio_gpu_scanout *scanout; + + scanout =3D &g->parent_obj.scanout[scanout_id]; + ores =3D virtio_gpu_find_resource(g, scanout->resource_id); + if (ores) { + ores->scanout_bitmask &=3D ~(1 << scanout_id); + } + + res->scanout_bitmask |=3D (1 << scanout_id); + scanout->resource_id =3D res->resource_id; + scanout->x =3D r->x; + scanout->y =3D r->y; + scanout->width =3D r->width; + scanout->height =3D r->height; +} + static void virtio_gpu_do_set_scanout(VirtIOGPU *g, uint32_t scanout_id, struct virtio_gpu_framebuffer *fb, @@ -565,7 +587,6 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g, struct virtio_gpu_rect *r, uint32_t *error) { - struct virtio_gpu_simple_resource *ores; struct virtio_gpu_scanout *scanout; uint8_t *data; =20 @@ -625,17 +646,7 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g, scanout->ds); } =20 - ores =3D virtio_gpu_find_resource(g, scanout->resource_id); - if (ores) { - ores->scanout_bitmask &=3D ~(1 << scanout_id); - } - - res->scanout_bitmask |=3D (1 << scanout_id); - scanout->resource_id =3D res->resource_id; - scanout->x =3D r->x; - scanout->y =3D r->y; - scanout->width =3D r->width; - scanout->height =3D r->height; + virtio_gpu_update_scanout(g, scanout_id, res, r); } =20 static void virtio_gpu_set_scanout(VirtIOGPU *g, --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723013; cv=none; d=zohomail.com; s=zohoarc; b=ExjM8o310SH6G8waqbfjqD078ZdgdzEKsHVWNKuTtXL0P787LWv78s/qjXlMaUFJb6mHIuWPZ/tYG/7QxW5GsQPOF9A5e9kVIlwyWdfqYp93oi+KhPX25l0Q9ZT8WKs3Ith4/RFsb6igLI3ZQyckWLkgd3PRJ2MX2PjhXmt6gPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723013; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kCQYJHenCyNmt0EbO8I4DEfeGu4VcLsT3q5rzWCNh+E=; b=ibguABDe29ztjsTJVsiS7BC+Nl5pn4jPSVq271BysEj81SAD5W6383lfiThw6v6bS1FElI4Lj+AJ9GJIfhN2gRe6QBM3yYenlsnoxsIbYMc8kkaWadDMf3kqFPPhjqVivphJn8RKsZ7Tl0jdrEHq1AGC6EIcgq/mJmjRLDlYGhc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723013936133.03415769207834; Tue, 11 May 2021 01:50:13 -0700 (PDT) Received: from localhost ([::1]:54672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgO5k-0003Ab-S7 for importer@patchew.org; Tue, 11 May 2021 04:50:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdp-000851-It for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:25 -0400 Received: from mga17.intel.com ([192.55.52.151]:32215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdn-0004r8-FM for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:21 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: Wqr2cVm14VgA2Q0gF/AaI2FTuhJIBzICFrWMwA205dk8sE3zWzXkIxFjKn31swSeFRXv5vsRr0 iw/p7ktiTW7w== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649393" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649393" IronPort-SDR: DIkJcmH4Nst7uBMLAr78rL1Fk/rTVkwQNv8015VMqpobvGqWn3cxUCO0OBT9Tvu7afI/z+5/Q1 ImLNmNXYHbvg== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892209" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 12/20] virtio-gpu: Add virtio_gpu_set_scanout_blob Date: Tue, 11 May 2021 01:08:10 -0700 Message-Id: <20210511080818.366985-13-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This API allows Qemu to set the blob allocated by the Guest as the scanout buffer. If Opengl support is available, then the scanout buffer would be submitted as a dmabuf to the UI; if not, a pixman image is created from the scanout buffer and is submitted to the UI via the display surface. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/trace-events | 1 + hw/display/virtio-gpu.c | 105 +++++++++++++++++++++++++-- include/hw/virtio/virtio-gpu-bswap.h | 7 ++ 3 files changed, 105 insertions(+), 8 deletions(-) diff --git a/hw/display/trace-events b/hw/display/trace-events index 99e5256aac..96fe1ea3de 100644 --- a/hw/display/trace-events +++ b/hw/display/trace-events @@ -40,6 +40,7 @@ virtio_gpu_features(bool virgl) "virgl %d" virtio_gpu_cmd_get_display_info(void) "" virtio_gpu_cmd_get_edid(uint32_t scanout) "scanout %d" virtio_gpu_cmd_set_scanout(uint32_t id, uint32_t res, uint32_t w, uint32_t= h, uint32_t x, uint32_t y) "id %d, res 0x%x, w %d, h %d, x %d, y %d" +virtio_gpu_cmd_set_scanout_blob(uint32_t id, uint32_t res, uint32_t w, uin= t32_t h, uint32_t x, uint32_t y) "id %d, res 0x%x, w %d, h %d, x %d, y %d" virtio_gpu_cmd_res_create_2d(uint32_t res, uint32_t fmt, uint32_t w, uint3= 2_t h) "res 0x%x, fmt 0x%x, w %d, h %d" virtio_gpu_cmd_res_create_3d(uint32_t res, uint32_t fmt, uint32_t w, uint3= 2_t h, uint32_t d) "res 0x%x, fmt 0x%x, w %d, h %d, d %d" virtio_gpu_cmd_res_create_blob(uint32_t res, uint64_t size) "res 0x%x, siz= e %" PRId64 diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index f96f7590b1..b8695ac7d5 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -405,7 +405,9 @@ static void virtio_gpu_resource_destroy(VirtIOGPU *g, } } =20 - pixman_image_unref(res->image); + if (res->image) { + pixman_image_unref(res->image); + } virtio_gpu_cleanup_mapping(g, res); QTAILQ_REMOVE(&g->reslist, res, next); g->hostmem -=3D res->hostmem; @@ -494,6 +496,7 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, { struct virtio_gpu_simple_resource *res; struct virtio_gpu_resource_flush rf; + struct virtio_gpu_scanout *scanout; pixman_region16_t flush_region; int i; =20 @@ -504,16 +507,28 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, =20 res =3D virtio_gpu_find_check_resource(g, rf.resource_id, false, __func__, &cmd->error); - if (!res || res->blob) { + if (!res) { return; } =20 - if (rf.r.x > res->width || + if (res->blob && display_opengl) { + for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { + scanout =3D &g->parent_obj.scanout[i]; + if (scanout->resource_id =3D=3D res->resource_id) { + dpy_gl_update(scanout->con, 0, 0, scanout->width, + scanout->height); + return; + } + } + } + + if (!res->blob && + (rf.r.x > res->width || rf.r.y > res->height || rf.r.width > res->width || rf.r.height > res->height || rf.r.x + rf.r.width > res->width || - rf.r.y + rf.r.height > res->height) { + rf.r.y + rf.r.height > res->height)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: flush bounds outside resource" " bounds for resource %d: %d %d %d %d vs %d %d\n", __func__, rf.resource_id, rf.r.x, rf.r.y, @@ -525,7 +540,6 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, pixman_region_init_rect(&flush_region, rf.r.x, rf.r.y, rf.r.width, rf.r.height); for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { - struct virtio_gpu_scanout *scanout; pixman_region16_t region, finalregion; pixman_box16_t *extents; =20 @@ -616,10 +630,23 @@ static void virtio_gpu_do_set_scanout(VirtIOGPU *g, } =20 g->parent_obj.enable =3D 1; - data =3D (uint8_t *)pixman_image_get_data(res->image); + + if (res->blob) { + if (display_opengl) { + if (!virtio_gpu_update_dmabuf(g, scanout_id, res, fb)) { + virtio_gpu_update_scanout(g, scanout_id, res, r); + return; + } + } + + data =3D res->blob; + } else { + data =3D (uint8_t *)pixman_image_get_data(res->image); + } =20 /* create a surface for this scanout */ - if (!scanout->ds || + if ((res->blob && !display_opengl) || + !scanout->ds || surface_data(scanout->ds) !=3D data + fb->offset || scanout->width !=3D r->width || scanout->height !=3D r->height) { @@ -683,6 +710,61 @@ static void virtio_gpu_set_scanout(VirtIOGPU *g, &fb, res, &ss.r, &cmd->error); } =20 +static void virtio_gpu_set_scanout_blob(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cm= d) +{ + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_framebuffer fb =3D { 0 }; + struct virtio_gpu_set_scanout_blob ss; + uint64_t fbend; + + VIRTIO_GPU_FILL_CMD(ss); + virtio_gpu_scanout_blob_bswap(&ss); + trace_virtio_gpu_cmd_set_scanout_blob(ss.scanout_id, ss.resource_id, + ss.r.width, ss.r.height, ss.r.x, + ss.r.y); + + if (ss.resource_id =3D=3D 0) { + virtio_gpu_disable_scanout(g, ss.scanout_id); + return; + } + + res =3D virtio_gpu_find_check_resource(g, ss.resource_id, true, + __func__, &cmd->error); + if (!res) { + return; + } + + fb.format =3D virtio_gpu_get_pixman_format(ss.format); + if (!fb.format) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: host couldn't handle guest format %d\n", + __func__, ss.format); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + return; + } + + fb.bytes_pp =3D DIV_ROUND_UP(PIXMAN_FORMAT_BPP(fb.format), 8); + fb.width =3D ss.width; + fb.height =3D ss.height; + fb.stride =3D ss.strides[0]; + fb.offset =3D ss.offsets[0] + ss.r.x * fb.bytes_pp + ss.r.y * fb.strid= e; + + fbend =3D fb.offset; + fbend +=3D fb.stride * (ss.r.height - 1); + fbend +=3D fb.bytes_pp * ss.r.width; + if (fbend > res->blob_size) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: fb end out of range\n", + __func__); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + return; + } + + virtio_gpu_do_set_scanout(g, ss.scanout_id, + &fb, res, &ss.r, &cmd->error); +} + int virtio_gpu_create_mapping_iov(VirtIOGPU *g, uint32_t nr_entries, uint32_t offset, struct virtio_gpu_ctrl_command *cmd, @@ -858,7 +940,7 @@ void virtio_gpu_simple_process_cmd(VirtIOGPU *g, case VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: virtio_gpu_resource_create_2d(g, cmd); break; - case VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB: + case VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB: if (!virtio_gpu_blob_enabled(g->parent_obj.conf)) { cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; break; @@ -877,6 +959,13 @@ void virtio_gpu_simple_process_cmd(VirtIOGPU *g, case VIRTIO_GPU_CMD_SET_SCANOUT: virtio_gpu_set_scanout(g, cmd); break; + case VIRTIO_GPU_CMD_SET_SCANOUT_BLOB: + if (!virtio_gpu_blob_enabled(g->parent_obj.conf)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + break; + } + virtio_gpu_set_scanout_blob(g, cmd); + break; case VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING: virtio_gpu_resource_attach_backing(g, cmd); break; diff --git a/include/hw/virtio/virtio-gpu-bswap.h b/include/hw/virtio/virti= o-gpu-bswap.h index d23ac5cc4a..e2bee8f595 100644 --- a/include/hw/virtio/virtio-gpu-bswap.h +++ b/include/hw/virtio/virtio-gpu-bswap.h @@ -68,4 +68,11 @@ virtio_gpu_create_blob_bswap(struct virtio_gpu_resource_= create_blob *cblob) le64_to_cpus(&cblob->size); } =20 +static inline void +virtio_gpu_scanout_blob_bswap(struct virtio_gpu_set_scanout_blob *ssb) +{ + virtio_gpu_bswap_32(ssb, sizeof(*ssb) - sizeof(ssb->offsets[3])); + le32_to_cpus(&ssb->offsets[3]); +} + #endif --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723178; cv=none; d=zohomail.com; s=zohoarc; b=XumKvBe22QpZHsrSPJ7pbrBwPj1KHd0o/mBVGCJBknSDf8/zStNqJKiZEAesnohMvtC2zBTTRy1KAJClhzmbxte4QMMDB9MjifIp9c/CM1Y2wNNHo3933wwKrfW8bwHUAd8miaLfhXaG7ZQ6Zxd5jjUdllvboCkCSYwZ2YBYP5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723178; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JDzRidyYGAuuvoH6DHp+SnjA5b93A4TMbwAtN14wHBE=; b=BqcZKcQoFjeY3Rt0SJ1Nn+ZwQCTpcLYmK1jM5N4lN7snV1kC9xoL6YGyuDkJ3YxkQgw8/3KSXeBdJJiCjG9fA0SzJsFoPLrXuMSl0HGZ03DIgvQSed4loVYQ+Nh1zO3RtXvvlOoHAlSkYN9oJiKMddZtvcv4LBzgaGuiKbpOWHY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723178427715.8683978816747; Tue, 11 May 2021 01:52:58 -0700 (PDT) Received: from localhost ([::1]:34942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgO8P-0000Wq-3x for importer@patchew.org; Tue, 11 May 2021 04:52:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdu-00087m-Mv for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:27 -0400 Received: from mga17.intel.com ([192.55.52.151]:32226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNdr-0004x4-VC for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:26 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: 9xdxTGw6/DG0c7ujw1artYLZSNrW5PBUV5+M3Ga9AICp7ogeOR3bmztQBikfeNpUqJCs+VPGZ+ 8z5YFn6mJGMg== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649394" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649394" IronPort-SDR: T5rGcJkLRXegGemyf0T7sSiZhPubARWJDQXyJ3aF6bT3vV5O7mJkew/KYXlETahZCKWbZBItiV ZSkR5QsjJlBA== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892212" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 13/20] virtio-gpu: Update cursor data using blob Date: Tue, 11 May 2021 01:08:11 -0700 Message-Id: <20210511080818.366985-14-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If a blob is available for the cursor, copy the data from the blob. Based-on-patch-by: Gerd Hoffmann Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index b8695ac7d5..cc2a0af21a 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -49,6 +49,7 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, { struct virtio_gpu_simple_resource *res; uint32_t pixels; + void *data; =20 res =3D virtio_gpu_find_check_resource(g, resource_id, false, __func__, NULL); @@ -56,14 +57,22 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, return; } =20 - if (pixman_image_get_width(res->image) !=3D s->current_cursor->width = || - pixman_image_get_height(res->image) !=3D s->current_cursor->height= ) { - return; + if (res->blob_size) { + if (res->blob_size < (s->current_cursor->width * + s->current_cursor->height * 4)) { + return; + } + data =3D res->blob; + } else { + if (pixman_image_get_width(res->image) !=3D s->current_cursor->wi= dth || + pixman_image_get_height(res->image) !=3D s->current_cursor->he= ight) { + return; + } + data =3D pixman_image_get_data(res->image); } =20 pixels =3D s->current_cursor->width * s->current_cursor->height; - memcpy(s->current_cursor->data, - pixman_image_get_data(res->image), + memcpy(s->current_cursor->data, data, pixels * sizeof(uint32_t)); } =20 --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620724348; cv=none; d=zohomail.com; s=zohoarc; b=fmk7I7qYiwWbUR0l8To5MTfADjSEjitR1Sv0YFU+x6rtIKIAbnf5XJprB4rOs/pM6S4kYiEzZFyqLoEQfGlGn1TuEfkJyYqQDKLmZDcG5n7t2vIrHnSKOGzb8uYXPlXb1LDaRCYlLYAA2UOyy9+uKx/5YWg/wJmS7iATCGZV65s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620724348; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qsh5gV8UpXFMqyf3lASm+LUJ/50v4OrlA7cYim+8uCo=; b=STw6WwsJRrnpbyzRndmlsZZDFnPl20yE1BS0MVsMHmFHzk5a53oFTZjHu7ecyChXpfAtiCawkUNiV/G8vpwdHhR0tHlhozamINrooSt9KGOXwsedN5ZULLqjRgeSg19quPdWRw0bSCa0/AV4vLUi7YFYgKIgnrFo1CukQQHJTXw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620724348779131.49206503807204; Tue, 11 May 2021 02:12:28 -0700 (PDT) Received: from localhost ([::1]:58440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgORG-0002At-G7 for importer@patchew.org; Tue, 11 May 2021 05:12:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36606) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNe5-00005Q-Sf for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:37 -0400 Received: from mga17.intel.com ([192.55.52.151]:32215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNe0-0004r8-ET for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:37 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: NQq/VNw7it1K0vMLvcXLSJucRFB9bNCgnoOYTpfKUyHGN1BYbNFPAZhgLxxaiCSgTqgl4sRhe+ 8hc/aW0RdVUg== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649395" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649395" IronPort-SDR: Q7uf276u4hsmh+Jd67d3Z33YtWVfTgHwDVR3/TK/eKNYIo3smR4SQ8TUQE5dn71hS7p0MyymYl 9r+qtT5+Dk5g== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892215" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 14/20] virtio-gpu: Add initial definitions for explict flush feature Date: Tue, 11 May 2021 01:08:12 -0700 Message-Id: <20210511080818.366985-15-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Add the property bit, conf flag and other relevant declarations associated with this feature. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-base.c | 3 +++ hw/display/virtio-gpu.c | 9 +++++++++ include/hw/virtio/virtio-gpu.h | 3 +++ include/standard-headers/linux/virtio_gpu.h | 2 ++ 4 files changed, 17 insertions(+) diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c index dd294276cb..c9af4c6117 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -211,6 +211,9 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64= _t features, if (virtio_gpu_blob_enabled(g->conf)) { features |=3D (1 << VIRTIO_GPU_F_RESOURCE_BLOB); } + if (virtio_gpu_expflush_enabled(g->conf)) { + features |=3D (1 << VIRTIO_GPU_F_EXPLICIT_FLUSH); + } =20 return features; } diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index cc2a0af21a..694d8f550c 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1298,6 +1298,13 @@ void virtio_gpu_device_realize(DeviceState *qdev, Er= ror **errp) } } =20 + if (virtio_gpu_expflush_enabled(g->parent_obj.conf)) { + if (!virtio_gpu_blob_enabled(g->parent_obj.conf)) { + error_setg(errp, "cannot enable expflush without blob resource= s"); + return; + } + } + if (!virtio_gpu_base_device_realize(qdev, virtio_gpu_handle_ctrl_cb, virtio_gpu_handle_cursor_cb, @@ -1393,6 +1400,8 @@ static Property virtio_gpu_properties[] =3D { 256 * MiB), DEFINE_PROP_BIT("blob", VirtIOGPU, parent_obj.conf.flags, VIRTIO_GPU_FLAG_BLOB_ENABLED, false), + DEFINE_PROP_BIT("expflush", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_EXPFLUSH_ENABLED, false), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 31b2bcc57b..4a827454f5 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -90,6 +90,7 @@ enum virtio_gpu_base_conf_flags { VIRTIO_GPU_FLAG_EDID_ENABLED, VIRTIO_GPU_FLAG_DMABUF_ENABLED, VIRTIO_GPU_FLAG_BLOB_ENABLED, + VIRTIO_GPU_FLAG_EXPFLUSH_ENABLED, }; =20 #define virtio_gpu_virgl_enabled(_cfg) \ @@ -102,6 +103,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED)) #define virtio_gpu_blob_enabled(_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED)) +#define virtio_gpu_expflush_enabled(_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_EXPFLUSH_ENABLED)) =20 struct virtio_gpu_base_conf { uint32_t max_outputs; diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard= -headers/linux/virtio_gpu.h index 1357e4774e..d015741f0b 100644 --- a/include/standard-headers/linux/virtio_gpu.h +++ b/include/standard-headers/linux/virtio_gpu.h @@ -60,6 +60,8 @@ */ #define VIRTIO_GPU_F_RESOURCE_BLOB 3 =20 +#define VIRTIO_GPU_F_EXPLICIT_FLUSH 4 + enum virtio_gpu_ctrl_type { VIRTIO_GPU_UNDEFINED =3D 0, =20 --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723286; cv=none; d=zohomail.com; s=zohoarc; b=khL8V/qSKmvHXUaUxpUfXQuuHn2fwx/TO4lkyTYxzBRoOVegp7R1NSjTQaqg8oPoOtIhkaifDJUNO5NNazyNkGFV1BaqmKX8q/01KUTlAjnqaw3Wswao4b1tmlTzz+kyn7pJwF0UW+QkCkaGaHznDGSbDiys/wEmibYRa8rmLyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723286; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JHrDpfaJg9QT8VmuAc3NFwAfb9CdzWh56iVlhcEZ9dY=; b=hUvJHd/Ith2Ys00xsVhGL1H/6QI3lYOdCJzLD+MM+SHFQhbdR3kiTxjklkNyprErpNn0ZXEgf87aenetOE41pUennrAP0Jsi3FF6mz8DKzq08xJJPS920IrP0pcL3C8u6o/ou77CSYYuKV7zS9IzOrG0Qo4hdnl6KIS7e2ss2+k= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723286297458.0650012443598; Tue, 11 May 2021 01:54:46 -0700 (PDT) Received: from localhost ([::1]:43102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgOA9-0005vh-9W for importer@patchew.org; Tue, 11 May 2021 04:54:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNe7-0000Bj-HV for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:39 -0400 Received: from mga17.intel.com ([192.55.52.151]:32223) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNe4-0004ul-Hj for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:39 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: fxsdHQT/XXiPF/ILdqEB3lX+1A11PTtBcJqhM5f58qCfR2Cu2KJOfOsJ6hQ8WI90FLEu5Aa77u 5gbLS1TVUErA== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649396" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649396" IronPort-SDR: lmof1W5dq6khbjRoA4m5+byQhzogu/x0cyHGalMkGnbcoSMzcncQlvcJpvHK+sMrhtnkod+Kf/ Xz3Cf97eTm/Q== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892218" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 15/20] virtio-gpu: Add dmabuf helpers for synchronization Date: Tue, 11 May 2021 01:08:13 -0700 Message-Id: <20210511080818.366985-16-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" These helpers will be used in the next subsequent patches to wait until a dmabuf object (via a texture) has been used by the UI to render and submit its buffer. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu-udmabuf.c | 42 +++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-gpu.h | 4 ++++ include/ui/console.h | 6 +++++ ui/console.c | 10 ++++++++ 4 files changed, 62 insertions(+) diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c index a9cb83d686..57bddd4d01 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -178,6 +178,47 @@ static void virtio_gpu_free_dmabuf(VirtIOGPU *g, VGPUD= MABuf *dmabuf) g_free(dmabuf); } =20 +static VGPUDMABuf +*virtio_gpu_find_dmabuf(VirtIOGPU *g, + struct virtio_gpu_simple_resource *res) +{ + VGPUDMABuf *dmabuf, *tmp; + + QTAILQ_FOREACH_SAFE(dmabuf, &g->dmabuf.bufs, next, tmp) { + if (dmabuf->buf.fd =3D=3D res->dmabuf_fd) { + return dmabuf; + } + } + + return NULL; +} + +void virtio_gpu_resource_wait_sync(VirtIOGPU *g, + struct virtio_gpu_simple_resource *res) +{ + struct virtio_gpu_scanout *scanout; + VGPUDMABuf *dmabuf; + + dmabuf =3D virtio_gpu_find_dmabuf(g, res); + if (dmabuf) { + scanout =3D &g->parent_obj.scanout[dmabuf->scanout_id]; + dpy_gl_wait_dmabuf(scanout->con, &dmabuf->buf); + } +} + +bool virtio_gpu_resource_has_sync(VirtIOGPU *g, + struct virtio_gpu_simple_resource *res) +{ + VGPUDMABuf *dmabuf; + + dmabuf =3D virtio_gpu_find_dmabuf(g, res); + if (dmabuf && dmabuf->buf.sync) { + return true; + } + + return false; +} + static VGPUDMABuf *virtio_gpu_create_dmabuf(VirtIOGPU *g, uint32_t scanout_id, @@ -196,6 +237,7 @@ static VGPUDMABuf dmabuf->buf.stride =3D fb->stride; dmabuf->buf.fourcc =3D qemu_pixman_to_drm_format(fb->format); dmabuf->buf.fd =3D res->dmabuf_fd; + dmabuf->buf.sync =3D NULL; =20 dmabuf->scanout_id =3D scanout_id; QTAILQ_INSERT_HEAD(&g->dmabuf.bufs, dmabuf, next); diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 4a827454f5..41f74e9286 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -277,6 +277,10 @@ int virtio_gpu_update_dmabuf(VirtIOGPU *g, uint32_t scanout_id, struct virtio_gpu_simple_resource *res, struct virtio_gpu_framebuffer *fb); +void virtio_gpu_resource_wait_sync(VirtIOGPU *g, + struct virtio_gpu_simple_resource *res); +bool virtio_gpu_resource_has_sync(VirtIOGPU *g, + struct virtio_gpu_simple_resource *res); =20 /* virtio-gpu-3d.c */ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, diff --git a/include/ui/console.h b/include/ui/console.h index b30b63976a..3b0e377923 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -168,6 +168,7 @@ typedef struct QemuDmaBuf { uint64_t modifier; uint32_t texture; bool y0_top; + void *sync; } QemuDmaBuf; =20 typedef struct DisplayState DisplayState; @@ -240,6 +241,9 @@ typedef struct DisplayChangeListenerOps { /* optional */ void (*dpy_gl_release_dmabuf)(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf); + /* optional */ + void (*dpy_gl_wait_dmabuf)(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf); /* required if GL */ void (*dpy_gl_update)(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h); @@ -312,6 +316,8 @@ void dpy_gl_cursor_position(QemuConsole *con, uint32_t pos_x, uint32_t pos_y); void dpy_gl_release_dmabuf(QemuConsole *con, QemuDmaBuf *dmabuf); +void dpy_gl_wait_dmabuf(QemuConsole *con, + QemuDmaBuf *dmabuf); void dpy_gl_update(QemuConsole *con, uint32_t x, uint32_t y, uint32_t w, uint32_t h); =20 diff --git a/ui/console.c b/ui/console.c index 2de5f4105b..b0abfd2246 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1917,6 +1917,16 @@ void dpy_gl_release_dmabuf(QemuConsole *con, } } =20 +void dpy_gl_wait_dmabuf(QemuConsole *con, + QemuDmaBuf *dmabuf) +{ + assert(con->gl); + + if (con->gl->ops->dpy_gl_wait_dmabuf) { + con->gl->ops->dpy_gl_wait_dmabuf(con->gl, dmabuf); + } +} + void dpy_gl_update(QemuConsole *con, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723288; cv=none; d=zohomail.com; s=zohoarc; b=b0XzcDy6Kv7kcrN9mTfdZuGxfkVTX67wl1JUgBv8WHtzA2CWowFYfMv5IdIvoYF8FHGXd2dF/n7ZBpA2TH/5mdyjAL0urk8l1+Ynwg7syRHwsBt3YWpZyg3jaytvy3fUFDgrqbecvIfKKtSwLso0mg8i0NTUQpxwCKV7lq+4hKs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723288; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jFnXN7uDisjUr6NMovJlQJGGK4ubxKipzJ15YQtLF20=; b=Hv/NwwgoeawD8U5kkiX5OiyVIOvcBxztfAbz/dZgDs0dTW+yjw4jLPLcNpTb5/Mr1kVeo1GDpuCYjmsawBzntVScrRfzu0DeEQSYVXquqi1CbSBiAqU1FQfltryQzPLn5gp5V0pA63Bp4X6AA8clds9+Mw3i/uvOkd3POEW7ZXo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723288627821.8296115791559; Tue, 11 May 2021 01:54:48 -0700 (PDT) Received: from localhost ([::1]:43356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgOAB-00065p-JM for importer@patchew.org; Tue, 11 May 2021 04:54:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNe8-0000HT-Se for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:40 -0400 Received: from mga17.intel.com ([192.55.52.151]:32226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNe5-0004x4-3O for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:40 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: W5/uZQ/U0zApG3u+S71Bzo427f0WP9KvMTF285YEYE7lKi+FsAYrw28nCyX/FZQttfaNgyvwCK 8Z9X8RLJaMAQ== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649397" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649397" IronPort-SDR: YF2i2PBW8U/INCtP9KjeT8gNVblw0pL8Syks74MXoyzOr8CEHOfYGseuC+zeIqmMTXZD0vEZGa MaAbM2J1+J9g== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892221" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 16/20] virtio-gpu: Add virtio_gpu_wait_flush API Date: Tue, 11 May 2021 01:08:14 -0700 Message-Id: <20210511080818.366985-17-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This new command can be used by the Guest Compositor as a way to synchronize its updates (repaint/redraw) with Host UI buffer submissions (redraw). In other words, the Guest can wait until the buffer it has submitted has been used by the Host before it starts it new repaint cycle. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu.c | 31 +++++++++++++++++++++ include/standard-headers/linux/virtio_gpu.h | 10 +++++++ 2 files changed, 41 insertions(+) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 694d8f550c..59cbc2b1df 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -933,6 +933,30 @@ virtio_gpu_resource_detach_backing(VirtIOGPU *g, virtio_gpu_cleanup_mapping(g, res); } =20 +static void virtio_gpu_wait_flush(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_wait_flush wf; + + VIRTIO_GPU_FILL_CMD(wf); + virtio_gpu_bswap_32(&wf, sizeof(wf)); + + res =3D virtio_gpu_find_check_resource(g, wf.resource_id, true, + __func__, &cmd->error); + if (!res) { + return; + } + + if (res->blob) { + if (cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_FENCE && + virtio_gpu_resource_has_sync(g, res)) { + virtio_gpu_resource_wait_sync(g, res); + cmd->finished =3D true; + } + } +} + void virtio_gpu_simple_process_cmd(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { @@ -981,6 +1005,13 @@ void virtio_gpu_simple_process_cmd(VirtIOGPU *g, case VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING: virtio_gpu_resource_detach_backing(g, cmd); break; + case VIRTIO_GPU_CMD_WAIT_FLUSH: + if (!virtio_gpu_expflush_enabled(g->parent_obj.conf)) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + break; + } + virtio_gpu_wait_flush(g, cmd); + break; default: cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; break; diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard= -headers/linux/virtio_gpu.h index d015741f0b..f9aba84174 100644 --- a/include/standard-headers/linux/virtio_gpu.h +++ b/include/standard-headers/linux/virtio_gpu.h @@ -60,6 +60,9 @@ */ #define VIRTIO_GPU_F_RESOURCE_BLOB 3 =20 +/* + * VIRTIO_GPU_CMD_WAIT_FLUSH + */ #define VIRTIO_GPU_F_EXPLICIT_FLUSH 4 =20 enum virtio_gpu_ctrl_type { @@ -80,6 +83,7 @@ enum virtio_gpu_ctrl_type { VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID, VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB, VIRTIO_GPU_CMD_SET_SCANOUT_BLOB, + VIRTIO_GPU_CMD_WAIT_FLUSH, =20 /* 3d commands */ VIRTIO_GPU_CMD_CTX_CREATE =3D 0x0200, @@ -443,4 +447,10 @@ struct virtio_gpu_resource_unmap_blob { uint32_t padding; }; =20 +/* VIRTIO_GPU_CMD_WAIT_FLUSH */ +struct virtio_gpu_wait_flush { + struct virtio_gpu_ctrl_hdr hdr; + uint32_t resource_id; +}; + #endif --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620724529; cv=none; d=zohomail.com; s=zohoarc; b=GJ5eDriCxjWL76Z64usT10EkpISPJwRyPCmMm6ZpTanRgZ3pBWkOAjQYJnK7FbyE/UNMnQxwyG/t8eaCqJMW3+wyb+LeJj9wnXhuPOuzj2Wm61k008+e6ogo3FXECKVXy1Rq9v9SskNiUCuHs564aYpqJ56m40I+G5KjNgXFwXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620724529; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rUp+fXMEBlN8bBGb6CczasW/Jv1ullb8Vx3ncQI6sA4=; b=iTFLNgX+KKd/QpcW8wJiLkgWSUbH90mPwKWUu3Et+qyvlurhNZ/KGVOn9q/SLQ9FLoDTIhNIjFYUtnWT89BNdbmJKNNKLxW1NjalQ00LkzYibMkLAc03cZDMZbEaY4ixneVUfoPwRdTtTJWKksmN+zziGxR7BuWvtvtW69LKWjQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620724529749480.66814844156227; Tue, 11 May 2021 02:15:29 -0700 (PDT) Received: from localhost ([::1]:38186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgOUB-0007op-Bs for importer@patchew.org; Tue, 11 May 2021 05:15:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNeK-0000yz-OP for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:52 -0400 Received: from mga17.intel.com ([192.55.52.151]:32215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNeG-0004r8-9q for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:52 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: IEmpkwsbSrSb18g8ljOlptJs//DcJTFljcC7XMNYA8zGFhSSGSRaue7O8L3Lj8uh/cCx5aDkbF JIT4I7YjR/Pw== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649398" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649398" IronPort-SDR: gM9ZwpS+GcUMT6z8g3TQ6YDo3MieX0GfCbiE5v+fpXv9RvASD036S9wxe4VSWb9qC2a/KEVl0z j1oWq/MxIw9w== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892224" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 17/20] ui: Add egl helpers for synchronization Date: Tue, 11 May 2021 01:08:15 -0700 Message-Id: <20210511080818.366985-18-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" These egl helpers will be useful for creating a sync object and waiting on it when called from the virtio-gpu wait_flush API. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- include/ui/console.h | 2 ++ include/ui/egl-helpers.h | 4 ++++ ui/egl-helpers.c | 44 ++++++++++++++++++++++++++++++++++++++++ ui/gtk-egl.c | 10 +++++++++ ui/gtk-gl-area.c | 8 ++++++++ ui/gtk.c | 15 ++++++++++++++ 6 files changed, 83 insertions(+) diff --git a/include/ui/console.h b/include/ui/console.h index 3b0e377923..15a92dd87a 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -169,6 +169,8 @@ typedef struct QemuDmaBuf { uint32_t texture; bool y0_top; void *sync; + bool blob; + int fence_fd; } QemuDmaBuf; =20 typedef struct DisplayState DisplayState; diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h index f1bf8f97fc..1bc0e31b03 100644 --- a/include/ui/egl-helpers.h +++ b/include/ui/egl-helpers.h @@ -19,6 +19,7 @@ typedef struct egl_fb { GLuint texture; GLuint framebuffer; bool delete_texture; + QemuDmaBuf *dmabuf; } egl_fb; =20 void egl_fb_destroy(egl_fb *fb); @@ -45,6 +46,9 @@ int egl_get_fd_for_texture(uint32_t tex_id, EGLint *strid= e, EGLint *fourcc, =20 void egl_dmabuf_import_texture(QemuDmaBuf *dmabuf); void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf); +void egl_dmabuf_create_sync(QemuDmaBuf *dmabuf); +void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf); +void egl_dmabuf_wait_sync(QemuDmaBuf *dmabuf); =20 #endif =20 diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c index 6d0cb2b5cb..47220b66e0 100644 --- a/ui/egl-helpers.c +++ b/ui/egl-helpers.c @@ -76,6 +76,50 @@ void egl_fb_setup_for_tex(egl_fb *fb, int width, int hei= ght, GL_TEXTURE_2D, fb->texture, 0); } =20 +void egl_dmabuf_create_sync(QemuDmaBuf *dmabuf) +{ + EGLSyncKHR sync; + + if (epoxy_has_egl_extension(qemu_egl_display, + "EGL_KHR_fence_sync") && + epoxy_has_egl_extension(qemu_egl_display, + "EGL_ANDROID_native_fence_sync")) { + sync =3D eglCreateSyncKHR(qemu_egl_display, + EGL_SYNC_NATIVE_FENCE_ANDROID, NULL); + if (sync !=3D EGL_NO_SYNC_KHR) { + dmabuf->sync =3D sync; + } + } +} + +void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf) +{ + if (dmabuf->sync) { + dmabuf->fence_fd =3D eglDupNativeFenceFDANDROID(qemu_egl_display, + dmabuf->sync); + eglDestroySyncKHR(qemu_egl_display, dmabuf->sync); + dmabuf->sync =3D NULL; + } +} + +void egl_dmabuf_wait_sync(QemuDmaBuf *dmabuf) +{ + EGLSyncKHR sync; + EGLint attrib_list[] =3D { + EGL_SYNC_NATIVE_FENCE_FD_ANDROID, dmabuf->fence_fd, + EGL_NONE, + }; + + sync =3D eglCreateSyncKHR(qemu_egl_display, + EGL_SYNC_NATIVE_FENCE_ANDROID, attrib_list); + if (sync !=3D EGL_NO_SYNC_KHR) { + eglClientWaitSyncKHR(qemu_egl_display, sync, + 0, EGL_FOREVER_KHR); + eglDestroySyncKHR(qemu_egl_display, sync); + dmabuf->fence_fd =3D -1; + } +} + void egl_fb_setup_new_tex(egl_fb *fb, int width, int height) { GLuint texture; diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index 2a2e6d3a17..e7117695f0 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -209,6 +209,8 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf) { #ifdef CONFIG_GBM + VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); + egl_dmabuf_import_texture(dmabuf); if (!dmabuf->texture) { return; @@ -217,6 +219,10 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl, gd_egl_scanout_texture(dcl, dmabuf->texture, false, dmabuf->width, dmabuf->height, 0, 0, dmabuf->width, dmabuf->height); + + if (dmabuf->blob) { + vc->gfx.guest_fb.dmabuf =3D dmabuf; + } #endif } =20 @@ -289,6 +295,10 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl, egl_fb_blit(&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top); } =20 + if (vc->gfx.guest_fb.dmabuf) { + egl_dmabuf_create_sync(vc->gfx.guest_fb.dmabuf); + } + eglSwapBuffers(qemu_egl_display, vc->gfx.esurface); } =20 diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c index dd5783fec7..94f3b87c42 100644 --- a/ui/gtk-gl-area.c +++ b/ui/gtk-gl-area.c @@ -71,6 +71,10 @@ void gd_gl_area_draw(VirtualConsole *vc) surface_gl_render_texture(vc->gfx.gls, vc->gfx.ds); } =20 + if (vc->gfx.guest_fb.dmabuf) { + egl_dmabuf_create_sync(vc->gfx.guest_fb.dmabuf); + } + glFlush(); graphic_hw_gl_flushed(vc->gfx.dcl.con); } @@ -231,6 +235,10 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *= dcl, gd_gl_area_scanout_texture(dcl, dmabuf->texture, false, dmabuf->width, dmabuf->height, 0, 0, dmabuf->width, dmabuf->height); + + if (dmabuf->blob) { + vc->gfx.guest_fb.dmabuf =3D dmabuf; + } #endif } =20 diff --git a/ui/gtk.c b/ui/gtk.c index 1ea1253528..7465aa7552 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -630,6 +630,19 @@ static bool gd_has_dmabuf(DisplayChangeListener *dcl) return vc->gfx.has_dmabuf; } =20 +static void gd_gl_wait_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf) +{ +#ifdef CONFIG_GBM + egl_dmabuf_create_fence(dmabuf); + if (dmabuf->fence_fd <=3D 0) { + return; + } + + egl_dmabuf_wait_sync(dmabuf); +#endif +} + /** DisplayState Callbacks (opengl version) **/ =20 static const DisplayChangeListenerOps dcl_gl_area_ops =3D { @@ -648,6 +661,7 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = =3D { .dpy_gl_scanout_disable =3D gd_gl_area_scanout_disable, .dpy_gl_update =3D gd_gl_area_scanout_flush, .dpy_gl_scanout_dmabuf =3D gd_gl_area_scanout_dmabuf, + .dpy_gl_wait_dmabuf =3D gd_gl_wait_dmabuf, .dpy_has_dmabuf =3D gd_has_dmabuf, }; =20 @@ -672,6 +686,7 @@ static const DisplayChangeListenerOps dcl_egl_ops =3D { .dpy_gl_cursor_position =3D gd_egl_cursor_position, .dpy_gl_release_dmabuf =3D gd_egl_release_dmabuf, .dpy_gl_update =3D gd_egl_scanout_flush, + .dpy_gl_wait_dmabuf =3D gd_gl_wait_dmabuf, .dpy_has_dmabuf =3D gd_has_dmabuf, }; =20 --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723436; cv=none; d=zohomail.com; s=zohoarc; b=iTXJCOtz0rmUTQ2iIxajR+BRJgNAPwjXY2cNwTx7HDylYs1rr4vPVTsyYdsADDuOb0vorSSWMon5YC8olB2msGf5xZLCL2BmE+cF/qIPn90jMuH+psdh7yrG9REyugTiPhA7iMDcZ+XNMEp+y3uYajjImsIA+kTP/Q6llQWfX8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723436; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yd0tqYvX8AkY2Fk6Rcx6b3QfAiVvazZ7g6YNeF2GjW0=; b=TPsCYxVyFswiASqpF9hNFJwk3LmVshG66/qweVUiQ7jFpplH7vHgQ2MN2ybRPmpfiTkeLWPp5BEwVeFlSJmFKto1Q8a64ihS64pkDSytTCIlxO5i3XsX5ssaA2PaGaBeoYXiB2Pijxm5apvQc9uJMXyyf60IHM/2/GpdOLycj24= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723436324344.9803519369859; Tue, 11 May 2021 01:57:16 -0700 (PDT) Received: from localhost ([::1]:51764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgOCZ-0003NP-8F for importer@patchew.org; Tue, 11 May 2021 04:57:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNeJ-0000vd-Sb for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:51 -0400 Received: from mga17.intel.com ([192.55.52.151]:32223) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNeH-0004ul-Tz for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:51 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: PYj9cviWEJWu0FW1AA1WALfle8tcUBMEMlfjB/w9juFkPYw1CbHbqhc/2344AtVVsfGVUQM29n 2sDHt/+BS+XA== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649399" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649399" IronPort-SDR: APgZUB18IXD1DV4zfHn0WGTXWTtT9GkhmXlpMFRMM7u7Ft2t0zwHO1BR2BCL1n6C7gX2/YRyUE VxkhGM9DDtZA== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892226" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 18/20] ui/gtk-egl: Wait for the draw signal for dmabuf blobs Date: Tue, 11 May 2021 01:08:16 -0700 Message-Id: <20210511080818.366985-19-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Instead of immediately drawing and submitting, queue and wait for the draw signal if the dmabuf submitted is a blob. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- include/ui/gtk.h | 2 ++ ui/gtk-egl.c | 14 ++++++++++++++ ui/gtk.c | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/ui/gtk.h b/include/ui/gtk.h index 5ae0ad60a6..0929e658f2 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -116,6 +116,8 @@ void gd_egl_cursor_position(DisplayChangeListener *dcl, uint32_t pos_x, uint32_t pos_y); void gd_egl_release_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf); +void gd_egl_flush(DisplayChangeListener *dcl, + uint32_t x, uint32_t y, uint32_t w, uint32_t h); void gd_egl_scanout_flush(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h); void gtk_egl_init(DisplayGLMode mode); diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index e7117695f0..799e3cbc78 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -302,6 +302,20 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl, eglSwapBuffers(qemu_egl_display, vc->gfx.esurface); } =20 +void gd_egl_flush(DisplayChangeListener *dcl, + uint32_t x, uint32_t y, uint32_t w, uint32_t h) +{ + VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); + GtkWidget *area =3D vc->gfx.drawing_area; + + if (vc->gfx.guest_fb.dmabuf) { + gtk_widget_queue_draw_area(area, x, y, w, h); + return; + } + + gd_egl_scanout_flush(&vc->gfx.dcl, x, y, w, h); +} + void gtk_egl_init(DisplayGLMode mode) { GdkDisplay *gdk_display =3D gdk_display_get_default(); diff --git a/ui/gtk.c b/ui/gtk.c index 7465aa7552..4c6066b015 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -685,7 +685,7 @@ static const DisplayChangeListenerOps dcl_egl_ops =3D { .dpy_gl_cursor_dmabuf =3D gd_egl_cursor_dmabuf, .dpy_gl_cursor_position =3D gd_egl_cursor_position, .dpy_gl_release_dmabuf =3D gd_egl_release_dmabuf, - .dpy_gl_update =3D gd_egl_scanout_flush, + .dpy_gl_update =3D gd_egl_flush, .dpy_gl_wait_dmabuf =3D gd_gl_wait_dmabuf, .dpy_has_dmabuf =3D gd_has_dmabuf, }; --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723610; cv=none; d=zohomail.com; s=zohoarc; b=MkDDIR7ONyDE+5oWdxiKqEmaI/font2q9qkP2Q2D+Y26c/RjmDNSkKUp88WmdI7tDHxYTx6YYA8jRr5uMiozr/LNH4y8O/Eah7XJEWkdDnRXx4WEvNwqNTecAFJQCbxz57gDQ1TOfzYtuif3rNwFIzX3Qit8Yjz7dpmHXbXAZmQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723610; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Y+3+kUHXZJoa8GvmZ4MA+m3nYOHvTFcPPF0gODt7w8s=; b=X9cL5vYAZ4czbrkRX9nSF58zdW3Y8J0h/HuRfcE68e7yckk+AalwmTRq2+HFw4SngDpV2o4Xg8m1Z+RcPYAIY4jKFsYoCn6GiqCrNHFxugJIlMv+BBYdoqe/ij5p/weM5J5RguLTq71PpqDqYvPnQvYGbUOP/VL8si1VKLLwQmI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723610685769.0875629330939; Tue, 11 May 2021 02:00:10 -0700 (PDT) Received: from localhost ([::1]:60484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgOFH-0000mO-CN for importer@patchew.org; Tue, 11 May 2021 05:00:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNeL-00011E-BL for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:53 -0400 Received: from mga17.intel.com ([192.55.52.151]:32226) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNeJ-0004x4-Bb for qemu-devel@nongnu.org; Tue, 11 May 2021 04:21:53 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: d4/VEjqE5eYW5lj4geIrHJJkMZRs/k9aDee8SUNh01LnkvxwcLwsO/IccTb6j8DloytfTbfcM5 SjFnmgOUR/RA== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649400" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649400" IronPort-SDR: isdhtGoK9KzN6uoghXUa2nRJusUwYM6yXqH7jKn5ZI8OHhfRKBo/wNyQL6PJulShJpreM5tgtH emHckS5zjTaw== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892230" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 19/20] ui/gtk: Create a common release_dmabuf helper Date: Tue, 11 May 2021 01:08:17 -0700 Message-Id: <20210511080818.366985-20-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Since the texture release mechanism is same for both gtk-egl and gtk-glarea, move the helper from gtk-egl into common gtk area so that it can be shared by both gtk backends. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- include/ui/gtk.h | 2 -- ui/gtk-egl.c | 8 -------- ui/gtk.c | 11 ++++++++++- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/ui/gtk.h b/include/ui/gtk.h index 0929e658f2..95506aa13b 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -114,8 +114,6 @@ void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl, uint32_t hot_x, uint32_t hot_y); void gd_egl_cursor_position(DisplayChangeListener *dcl, uint32_t pos_x, uint32_t pos_y); -void gd_egl_release_dmabuf(DisplayChangeListener *dcl, - QemuDmaBuf *dmabuf); void gd_egl_flush(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h); void gd_egl_scanout_flush(DisplayChangeListener *dcl, diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index 799e3cbc78..a5655b6bbc 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -255,14 +255,6 @@ void gd_egl_cursor_position(DisplayChangeListener *dcl, vc->gfx.cursor_y =3D pos_y * vc->gfx.scale_y; } =20 -void gd_egl_release_dmabuf(DisplayChangeListener *dcl, - QemuDmaBuf *dmabuf) -{ -#ifdef CONFIG_GBM - egl_dmabuf_release_texture(dmabuf); -#endif -} - void gd_egl_scanout_flush(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { diff --git a/ui/gtk.c b/ui/gtk.c index 4c6066b015..621dcf3f9e 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -630,6 +630,14 @@ static bool gd_has_dmabuf(DisplayChangeListener *dcl) return vc->gfx.has_dmabuf; } =20 +static void gd_gl_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf) +{ +#ifdef CONFIG_GBM + egl_dmabuf_release_texture(dmabuf); +#endif +} + static void gd_gl_wait_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf) { @@ -661,6 +669,7 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = =3D { .dpy_gl_scanout_disable =3D gd_gl_area_scanout_disable, .dpy_gl_update =3D gd_gl_area_scanout_flush, .dpy_gl_scanout_dmabuf =3D gd_gl_area_scanout_dmabuf, + .dpy_gl_release_dmabuf =3D gd_gl_release_dmabuf, .dpy_gl_wait_dmabuf =3D gd_gl_wait_dmabuf, .dpy_has_dmabuf =3D gd_has_dmabuf, }; @@ -684,7 +693,7 @@ static const DisplayChangeListenerOps dcl_egl_ops =3D { .dpy_gl_scanout_dmabuf =3D gd_egl_scanout_dmabuf, .dpy_gl_cursor_dmabuf =3D gd_egl_cursor_dmabuf, .dpy_gl_cursor_position =3D gd_egl_cursor_position, - .dpy_gl_release_dmabuf =3D gd_egl_release_dmabuf, + .dpy_gl_release_dmabuf =3D gd_gl_release_dmabuf, .dpy_gl_update =3D gd_egl_flush, .dpy_gl_wait_dmabuf =3D gd_gl_wait_dmabuf, .dpy_has_dmabuf =3D gd_has_dmabuf, --=20 2.30.2 From nobody Sat May 18 07:09:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1620723574; cv=none; d=zohomail.com; s=zohoarc; b=V32x9MX9A5HxXrc2zgIiYuCu+ArlUFkIxQpwn8nppJ0xYz90Je5TV7OcewLnnd1D7eI61/YiLsD6MVdwroaaQDa41RVObTRpdcxWiw8uKdqaiITBsL37IsKACNRVKqDofaYwSpT4iOqK3rHpUpEE/pnHCv07UVYMcKcDuYicchk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620723574; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=07K9O46sqMBVeFkhv14fYy4gvb6S1bFV7XyE2DbFcg4=; b=lXP+e37w2k6MlyvVpI6zcT/jNo3RxdycpVDCC6asUkrOJmRNOY+J/QQoX/a+5MYguaOtsww4k1RHv4HYoT6tFEJ4xzTYJ71bHQUuT1sq0CMvzmq0epM0BAVNs/ir//tyh6NBCyJJride3qZdGXR52WTr5yo53JjWRGcSTSt++y0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620723574880493.7911237271703; Tue, 11 May 2021 01:59:34 -0700 (PDT) Received: from localhost ([::1]:60180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgOEn-0000Z5-MM for importer@patchew.org; Tue, 11 May 2021 04:59:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNeW-0001Rk-51 for qemu-devel@nongnu.org; Tue, 11 May 2021 04:22:04 -0400 Received: from mga17.intel.com ([192.55.52.151]:32223) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgNeU-0004ul-9p for qemu-devel@nongnu.org; Tue, 11 May 2021 04:22:03 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 Received: from vkasired-desk2.fm.intel.com ([10.105.128.127]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 01:20:49 -0700 IronPort-SDR: bGBq1JvLE6mqEvHtBwY111K8ed2CoBGjjEbjAKXqjXujVimuTvZgsl03VzX5JXL5EUR2kSguhK NKrYrP7NIvLA== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="179649401" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="179649401" IronPort-SDR: Ud7JgZJfXX7wL12rlWNgFXb4SHQ2sI693pSYdwhI38jdKewAVUSv1hZaFNzW5+v2TFpiOww+lz pxVlSEWMQEZA== X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="536892232" From: Vivek Kasireddy To: qemu-devel@nongnu.org Subject: [PATCH v3 20/20] virtio-gpu: Add gl_flushed callback Date: Tue, 11 May 2021 01:08:18 -0700 Message-Id: <20210511080818.366985-21-vivek.kasireddy@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511080818.366985-1-vivek.kasireddy@intel.com> References: <20210511080818.366985-1-vivek.kasireddy@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.151; envelope-from=vivek.kasireddy@intel.com; helo=mga17.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vivek Kasireddy , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Adding this callback provides a way to determine when the UI has submitted the buffer to the Host windowing system. Making the guest wait for this event will ensure that the dmabuf/buffer updates are synchronized. Cc: Gerd Hoffmann Signed-off-by: Vivek Kasireddy --- hw/display/virtio-gpu.c | 47 +++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-gpu.h | 1 + 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 59cbc2b1df..47b3b2b244 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1016,7 +1016,8 @@ void virtio_gpu_simple_process_cmd(VirtIOGPU *g, cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; break; } - if (!cmd->finished) { + if ((!cmd->finished && !(cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_FENCE)) = || + (cmd->finished && (cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_FENCE))) { virtio_gpu_ctrl_response_nodata(g, cmd, cmd->error ? cmd->error : VIRTIO_GPU_RESP_OK_NODATA); } @@ -1074,6 +1075,49 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g) g->processing_cmdq =3D false; } =20 +static void virtio_gpu_signal_fence(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd, + enum virtio_gpu_ctrl_type type) +{ + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_wait_flush wf; + + VIRTIO_GPU_FILL_CMD(wf); + virtio_gpu_bswap_32(&wf, sizeof(wf)); + + res =3D virtio_gpu_find_check_resource(g, wf.resource_id, true, + __func__, &cmd->error); + if (res && virtio_gpu_resource_has_sync(g, res)) { + virtio_gpu_resource_wait_sync(g, res); + } + + virtio_gpu_ctrl_response_nodata(g, cmd, VIRTIO_GPU_RESP_OK_NODATA); +} + +static void virtio_gpu_process_fenceq(VirtIOGPU *g) +{ + struct virtio_gpu_ctrl_command *cmd, *tmp; + + QTAILQ_FOREACH_SAFE(cmd, &g->fenceq, next, tmp) { + trace_virtio_gpu_fence_resp(cmd->cmd_hdr.fence_id); + virtio_gpu_signal_fence(g, cmd, VIRTIO_GPU_RESP_OK_NODATA); + QTAILQ_REMOVE(&g->fenceq, cmd, next); + + g_free(cmd); + g->inflight--; + if (virtio_gpu_stats_enabled(g->parent_obj.conf)) { + fprintf(stderr, "inflight: %3d (-)\r", g->inflight); + } + } +} + +static void virtio_gpu_gl_flushed(VirtIOGPU *g) +{ + if (virtio_gpu_expflush_enabled(g->parent_obj.conf)) { + virtio_gpu_process_fenceq(g); + } +} + static void virtio_gpu_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { VirtIOGPU *g =3D VIRTIO_GPU(vdev); @@ -1445,6 +1489,7 @@ static void virtio_gpu_class_init(ObjectClass *klass,= void *data) vgc->handle_ctrl =3D virtio_gpu_handle_ctrl; vgc->process_cmd =3D virtio_gpu_simple_process_cmd; vgc->update_cursor_data =3D virtio_gpu_update_cursor_data; + vgc->gl_flushed =3D virtio_gpu_gl_flushed; =20 vdc->realize =3D virtio_gpu_device_realize; vdc->reset =3D virtio_gpu_reset; diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 41f74e9286..59edd6da7f 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -202,6 +202,7 @@ struct VirtIOGPUClass { void (*update_cursor_data)(VirtIOGPU *g, struct virtio_gpu_scanout *s, uint32_t resource_id); + void (*gl_flushed)(VirtIOGPU *g); }; =20 struct VirtIOGPUGL { --=20 2.30.2