From nobody Sun May 19 20:29:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1559642814; cv=none; d=zoho.com; s=zohoarc; b=DFU3h3k6kK1MFEad/2UgsKDbzHfGEFA9ULdjVmb7wYo4Nfb6qDI7FxnRX6EFoRhYy/6iOllr0G4Dac71GL6nZW4+yjfGgw9gtGzSzIKCa54gbQYxyOtRtUPCMuS2LdgmOsLNcmwQxTvkQFd5wzYb0EqHw9yGUOzWfjX+ET0Oln8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559642814; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=1iRZUCks/3iZl+95xmX6Y4ubmlWmf6EwfEXDQAMYAA4=; b=eaMYEFZ+QHzPs4nYCuSujg1fh5QsbBFYTvYrrr5g9vtTXCeGcwX8BE1/PDeCFcAVzYHo9y2R8/4H/QxSWZ5sLsUP1HEAvJw/IxXhch3F0J/opoo6bUns7hKEFXWuMAbrlPw0jWd5t11wI1MogfNl+0gi0hCjGHcnHVgQoUux5uU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1559642814652749.025617496128; Tue, 4 Jun 2019 03:06:54 -0700 (PDT) Received: from localhost ([127.0.0.1]:49683 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY6L6-0000xT-Ia for importer@patchew.org; Tue, 04 Jun 2019 06:06:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY6J6-00083R-9I for qemu-devel@nongnu.org; Tue, 04 Jun 2019 06:04:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hY6J4-0000mz-DL for qemu-devel@nongnu.org; Tue, 04 Jun 2019 06:04:40 -0400 Received: from mga18.intel.com ([134.134.136.126]:33969) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hY6J4-0000eZ-0b for qemu-devel@nongnu.org; Tue, 04 Jun 2019 06:04:38 -0400 Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2019 03:04:28 -0700 Received: from gvt.bj.intel.com ([10.238.158.187]) by orsmga007.jf.intel.com with ESMTP; 04 Jun 2019 03:04:26 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 From: Tina Zhang To: intel-gvt-dev@lists.freedesktop.org, qemu-devel@nongnu.org Date: Tue, 4 Jun 2019 17:58:45 +0800 Message-Id: <20190604095847.10532-2-tina.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604095847.10532-1-tina.zhang@intel.com> References: <20190604095847.10532-1-tina.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.126 Subject: [Qemu-devel] [RFC PATCH 1/3] vfio: Add a funtion to return a specific irq capabilities X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevin.tian@intel.com, zhenyuw@linux.intel.com, Tina Zhang , alex.williamson@redhat.com, zhiyuan.lv@intel.com, hang.yuan@intel.com, zhi.a.wang@intel.com, kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" vfio_get_dev_irq_info is introduced to return a specific irq capabilities. Signed-off-by: Tina Zhang --- hw/vfio/common.c | 78 +++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-common.h | 3 ++ 2 files changed, 81 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 4374cc6176..928ea54411 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -748,6 +748,25 @@ vfio_get_region_info_cap(struct vfio_region_info *info= , uint16_t id) return NULL; } =20 +static struct vfio_info_cap_header * +vfio_get_irq_info_cap(struct vfio_irq_info *info, uint16_t id) +{ + struct vfio_info_cap_header *hdr; + void *ptr =3D info; + + if (!(info->flags & VFIO_IRQ_INFO_FLAG_CAPS)) { + return NULL; + } + + for (hdr =3D ptr + info->cap_offset; hdr !=3D ptr; hdr =3D ptr + hdr->= next) { + if (hdr->id =3D=3D id) { + return hdr; + } + } + + return NULL; +} + static int vfio_setup_region_sparse_mmaps(VFIORegion *region, struct vfio_region_info *info) { @@ -1539,6 +1558,33 @@ retry: return 0; } =20 +static int vfio_get_irq_info(VFIODevice *vbasedev, int index, + struct vfio_irq_info **info) +{ + size_t argsz =3D sizeof(struct vfio_irq_info); + + *info =3D g_malloc0(argsz); + + (*info)->index =3D index; +retry: + (*info)->argsz =3D argsz; + + if (ioctl(vbasedev->fd, VFIO_DEVICE_GET_IRQ_INFO, *info)) { + g_free(*info); + *info =3D NULL; + return -errno; + } + + if ((*info)->argsz > argsz) { + argsz =3D (*info)->argsz; + *info =3D g_realloc(*info, argsz); + + goto retry; + } + + return 0; +} + int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, uint32_t subtype, struct vfio_region_info **i= nfo) { @@ -1574,6 +1620,38 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, u= int32_t type, return -ENODEV; } =20 +int vfio_get_dev_irq_info(VFIODevice *vbasedev, uint32_t type, + uint32_t subtype, struct vfio_irq_info **info) +{ + int i; + + for (i =3D 0; i < vbasedev->num_irqs; i++) { + struct vfio_info_cap_header *hdr; + struct vfio_irq_info_cap_type *cap_type; + + if (vfio_get_irq_info(vbasedev, i, info)) { + continue; + } + + hdr =3D vfio_get_irq_info_cap(*info, VFIO_IRQ_INFO_CAP_TYPE); + if (!hdr) { + g_free(*info); + continue; + } + + cap_type =3D container_of(hdr, struct vfio_irq_info_cap_type, head= er); + + if (cap_type->type =3D=3D type && cap_type->subtype =3D=3D subtype= ) { + return 0; + } + + g_free(*info); + } + + *info =3D NULL; + return -ENODEV; +} + bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_ty= pe) { struct vfio_region_info *info =3D NULL; diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 1155b79678..5cab6a1b81 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -195,6 +195,9 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev, uint= 32_t type, bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_ty= pe); struct vfio_info_cap_header * vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id); + +int vfio_get_dev_irq_info(VFIODevice *vbasedev, uint32_t type, + uint32_t subtype, struct vfio_irq_info **info); #endif extern const MemoryListener vfio_prereg_listener; =20 --=20 2.17.1 From nobody Sun May 19 20:29:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1559642806; cv=none; d=zoho.com; s=zohoarc; b=Swn96Wp5ek6EgMshLdyK1l5dW1YplOGXVUUCmbi5nWM3bAU0GDdNfpcRz3naIlwJGgtNLIbpCP78UXK156WqtOArUcRWYquyEIynMboxhNvC9TfIjydX4rupDgCVeFEVPnkHhxwTJxowWXMHZ61pTP809KhNrnqqudMl1mt1yXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559642806; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=PW4qEEwTNf5FRsrdTs4deU/SVIkMl1CguEe1wo2TQsY=; b=D4Pe/NMSTVjnRuvNlVF5nuKQJ6uvG124SrGmf7xRQH7VVCQEHG3kbxCzN1mpg7Vp6lDCqgrGrfczU3J/ycfVasgHzX6Jrq/sd6ggoSOfMdFQmu3OQHl0d1palJSCehbwEqsfX4OgKPded43JWspvjZ9A2oe+HcYX6776j8EbPbo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1559642806828428.7088132206129; Tue, 4 Jun 2019 03:06:46 -0700 (PDT) Received: from localhost ([127.0.0.1]:49681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY6L4-0000wv-Qc for importer@patchew.org; Tue, 04 Jun 2019 06:06:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55916) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY6J6-00083S-9V for qemu-devel@nongnu.org; Tue, 04 Jun 2019 06:04:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hY6J4-0000mv-Cf for qemu-devel@nongnu.org; Tue, 04 Jun 2019 06:04:40 -0400 Received: from mga18.intel.com ([134.134.136.126]:33971) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hY6J4-0000hK-0f for qemu-devel@nongnu.org; Tue, 04 Jun 2019 06:04:38 -0400 Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2019 03:04:30 -0700 Received: from gvt.bj.intel.com ([10.238.158.187]) by orsmga007.jf.intel.com with ESMTP; 04 Jun 2019 03:04:28 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 From: Tina Zhang To: intel-gvt-dev@lists.freedesktop.org, qemu-devel@nongnu.org Date: Tue, 4 Jun 2019 17:58:46 +0800 Message-Id: <20190604095847.10532-3-tina.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604095847.10532-1-tina.zhang@intel.com> References: <20190604095847.10532-1-tina.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.126 Subject: [Qemu-devel] [RFC PATCH 2/3] ui/console: Introduce two new APIs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevin.tian@intel.com, zhenyuw@linux.intel.com, Tina Zhang , alex.williamson@redhat.com, zhiyuan.lv@intel.com, hang.yuan@intel.com, zhi.a.wang@intel.com, kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" graphic_hw_refresh is used by display to invoke console refresh. dpy_update_interval is used by display to update gui timer interval. Signed-off-by: Tina Zhang --- include/ui/console.h | 2 ++ ui/console.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/ui/console.h b/include/ui/console.h index fef900db76..3b46264efb 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -275,6 +275,7 @@ void register_displaychangelistener(DisplayChangeListen= er *dcl); void update_displaychangelistener(DisplayChangeListener *dcl, uint64_t interval); void unregister_displaychangelistener(DisplayChangeListener *dcl); +void dpy_update_interval(QemuConsole *con, uint64_t interval); =20 bool dpy_ui_info_supported(QemuConsole *con); int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info); @@ -379,6 +380,7 @@ void graphic_console_set_hwops(QemuConsole *con, void graphic_console_close(QemuConsole *con); =20 void graphic_hw_update(QemuConsole *con); +void graphic_hw_refresh(QemuConsole *con); void graphic_hw_invalidate(QemuConsole *con); void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata); void graphic_hw_gl_block(QemuConsole *con, bool block); diff --git a/ui/console.c b/ui/console.c index 6d2282d3e9..3a02cea37d 100644 --- a/ui/console.c +++ b/ui/console.c @@ -268,6 +268,24 @@ void graphic_hw_update(QemuConsole *con) } } =20 +void graphic_hw_refresh(QemuConsole *con) +{ + DisplayState *ds; + DisplayChangeListener *dcl; + + if (!con) { + con =3D active_console; + } + + ds =3D con->ds; + + QLIST_FOREACH(dcl, &ds->listeners, next) { + if (dcl->ops->dpy_refresh) { + dcl->ops->dpy_refresh(dcl); + } + } +} + void graphic_hw_gl_block(QemuConsole *con, bool block) { assert(con !=3D NULL); @@ -1480,6 +1498,23 @@ void update_displaychangelistener(DisplayChangeListe= ner *dcl, } } =20 +void dpy_update_interval(QemuConsole *con, uint64_t interval) +{ + DisplayChangeListener *dcl; + DisplayState *ds; + + if (!con) { + return; + } + + ds =3D con->ds; + + QLIST_FOREACH(dcl, &ds->listeners, next) { + update_displaychangelistener(dcl, interval); + } +} + + void unregister_displaychangelistener(DisplayChangeListener *dcl) { DisplayState *ds =3D dcl->ds; --=20 2.17.1 From nobody Sun May 19 20:29:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=1559642938; cv=none; d=zoho.com; s=zohoarc; b=YnLpuqQoUfr0OLMdrmjT1H4DDQn0y3EO//gBXQ4saBXVeWbyxQln1nSvX0u0Q0Xn7rdl+aEPGo5K2HAEbAB5mGBcC8RxeC2ehjSJ+C+28P9OJKfvJRUePLrDoyO6uEfxMpF1w6+2fmbns/Hp6ic82ZQ7ypPpsxShfRBDw0gL3IY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559642938; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7wM31rh/b53H6RgBXTncrb6aX0S9LcVlxK+sg+tRFm4=; b=CoiZ88rwc5YmlnXni44UTrRF+C2ET05rH8fAUMY4aHtwXk/u6EtAWz9229vLGF9dwrNvC1KjHDZo/2cfnL4dCDvqhH3MbIc8F6pF+DeNUTz2CCjeiaD3+TRA9s6c1jzmAhgINdGsgcTiIX71xEiuDlSKeQ8R9rDLltU9Lvm/TfU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 1559642938413538.2728046434562; Tue, 4 Jun 2019 03:08:58 -0700 (PDT) Received: from localhost ([127.0.0.1]:49722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY6N9-0002u8-C1 for importer@patchew.org; Tue, 04 Jun 2019 06:08:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hY6J8-00085K-4F for qemu-devel@nongnu.org; Tue, 04 Jun 2019 06:04:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hY6J6-0000oP-8X for qemu-devel@nongnu.org; Tue, 04 Jun 2019 06:04:42 -0400 Received: from mga18.intel.com ([134.134.136.126]:33967) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hY6J4-0000aq-K8 for qemu-devel@nongnu.org; Tue, 04 Jun 2019 06:04:39 -0400 Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2019 03:04:33 -0700 Received: from gvt.bj.intel.com ([10.238.158.187]) by orsmga007.jf.intel.com with ESMTP; 04 Jun 2019 03:04:31 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 From: Tina Zhang To: intel-gvt-dev@lists.freedesktop.org, qemu-devel@nongnu.org Date: Tue, 4 Jun 2019 17:58:47 +0800 Message-Id: <20190604095847.10532-4-tina.zhang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190604095847.10532-1-tina.zhang@intel.com> References: <20190604095847.10532-1-tina.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.126 Subject: [Qemu-devel] [RFC PATCH 3/3] vfio/display: Refresh display depending on vGPU page flip events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevin.tian@intel.com, zhenyuw@linux.intel.com, Tina Zhang , alex.williamson@redhat.com, zhiyuan.lv@intel.com, hang.yuan@intel.com, zhi.a.wang@intel.com, kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Use vGPU plane page flip events to refresh display. Signed-off-by: Tina Zhang --- hw/vfio/display.c | 249 +++++++++++++++++++++++++++++----- include/hw/vfio/vfio-common.h | 8 ++ 2 files changed, 225 insertions(+), 32 deletions(-) diff --git a/hw/vfio/display.c b/hw/vfio/display.c index 2c2d3e5b71..6ef383b5e8 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -288,44 +288,54 @@ static void vfio_display_dmabuf_update(void *opaque) VFIODMABuf *primary, *cursor; bool free_bufs =3D false, new_cursor =3D false;; =20 - primary =3D vfio_display_get_dmabuf(vdev, DRM_PLANE_TYPE_PRIMARY); - if (primary =3D=3D NULL) { - if (dpy->ramfb) { - ramfb_display_update(dpy->con, dpy->ramfb); - } - return; + if (dpy->event_flags & VFIO_IRQ_EVENT_ENABLE) { + dpy_update_interval(dpy->con, GUI_REFRESH_INTERVAL_IDLE); } =20 - if (dpy->dmabuf.primary !=3D primary) { - dpy->dmabuf.primary =3D primary; - qemu_console_resize(dpy->con, - primary->buf.width, primary->buf.height); - dpy_gl_scanout_dmabuf(dpy->con, &primary->buf); - free_bufs =3D true; - } + if (!dpy->event_flags || + (dpy->event_flags & VFIO_IRQ_EVENT_PRIMRAY_PLANE_FLIP)) { + primary =3D vfio_display_get_dmabuf(vdev, DRM_PLANE_TYPE_PRIMARY); + if (primary =3D=3D NULL) { + if (dpy->ramfb) { + ramfb_display_update(dpy->con, dpy->ramfb); + } + return; + } =20 - cursor =3D vfio_display_get_dmabuf(vdev, DRM_PLANE_TYPE_CURSOR); - if (dpy->dmabuf.cursor !=3D cursor) { - dpy->dmabuf.cursor =3D cursor; - new_cursor =3D true; - free_bufs =3D true; + if (dpy->dmabuf.primary !=3D primary) { + dpy->dmabuf.primary =3D primary; + qemu_console_resize(dpy->con, + primary->buf.width, primary->buf.height); + dpy_gl_scanout_dmabuf(dpy->con, &primary->buf); + free_bufs =3D true; + } } =20 - if (cursor && (new_cursor || cursor->hot_updates)) { - bool have_hot =3D (cursor->hot_x !=3D 0xffffffff && - cursor->hot_y !=3D 0xffffffff); - dpy_gl_cursor_dmabuf(dpy->con, &cursor->buf, have_hot, - cursor->hot_x, cursor->hot_y); - cursor->hot_updates =3D 0; - } else if (!cursor && new_cursor) { - dpy_gl_cursor_dmabuf(dpy->con, NULL, false, 0, 0); - } + if (!dpy->event_flags || + (dpy->event_flags & VFIO_IRQ_EVENT_CURSOR_PLANE_FLIP)) { + cursor =3D vfio_display_get_dmabuf(vdev, DRM_PLANE_TYPE_CURSOR); + if (dpy->dmabuf.cursor !=3D cursor) { + dpy->dmabuf.cursor =3D cursor; + new_cursor =3D true; + free_bufs =3D true; + } + + if (cursor && (new_cursor || cursor->hot_updates)) { + bool have_hot =3D (cursor->hot_x !=3D 0xffffffff && + cursor->hot_y !=3D 0xffffffff); + dpy_gl_cursor_dmabuf(dpy->con, &cursor->buf, have_hot, + cursor->hot_x, cursor->hot_y); + cursor->hot_updates =3D 0; + } else if (!cursor && new_cursor) { + dpy_gl_cursor_dmabuf(dpy->con, NULL, false, 0, 0); + } =20 - if (cursor && cursor->pos_updates) { - dpy_gl_cursor_position(dpy->con, - cursor->pos_x, - cursor->pos_y); - cursor->pos_updates =3D 0; + if (cursor && cursor->pos_updates) { + dpy_gl_cursor_position(dpy->con, + cursor->pos_x, + cursor->pos_y); + cursor->pos_updates =3D 0; + } } =20 dpy_gl_update(dpy->con, 0, 0, primary->buf.width, primary->buf.height); @@ -340,6 +350,7 @@ static const GraphicHwOps vfio_display_dmabuf_ops =3D { .ui_info =3D vfio_display_edid_ui_info, }; =20 +static int vfio_register_display_notifier(VFIOPCIDevice *vdev); static int vfio_display_dmabuf_init(VFIOPCIDevice *vdev, Error **errp) { if (!display_opengl) { @@ -355,6 +366,8 @@ static int vfio_display_dmabuf_init(VFIOPCIDevice *vdev= , Error **errp) vdev->dpy->ramfb =3D ramfb_setup(DEVICE(vdev), errp); } vfio_display_edid_init(vdev); + vfio_register_display_notifier(vdev); + return 0; } =20 @@ -495,6 +508,177 @@ static void vfio_display_region_exit(VFIODisplay *dpy) =20 /* ---------------------------------------------------------------------- = */ =20 +static void primary_plane_update(void *opaque) +{ + VFIOPCIDevice *vdev =3D opaque; + VFIODisplay *dpy =3D vdev->dpy; + + if (!event_notifier_test_and_clear(&dpy->pri_event_notifier)) { + return; + } + + dpy->event_flags |=3D VFIO_IRQ_EVENT_PRIMRAY_PLANE_FLIP; + graphic_hw_refresh(dpy->con); + dpy->event_flags &=3D ~VFIO_IRQ_EVENT_PRIMRAY_PLANE_FLIP; +} + +static void cursor_plane_update(void *opaque) +{ + VFIOPCIDevice *vdev =3D opaque; + VFIODisplay *dpy =3D vdev->dpy; + static int times; + + if (!event_notifier_test_and_clear(&dpy->cur_event_notifier)) { + return; + } + + /* Have to skip some cursor events due to performance impact */ + if (times++ / 2) { + times =3D 0; + dpy->event_flags |=3D VFIO_IRQ_EVENT_CURSOR_PLANE_FLIP; + graphic_hw_refresh(dpy->con); + dpy->event_flags &=3D ~VFIO_IRQ_EVENT_CURSOR_PLANE_FLIP; + } +} + +static int register_display_notifier(VFIOPCIDevice *vdev, + uint32_t type, uint32_t subtype, + EventNotifier *notifier, + void (*handler)(void *opaque)) +{ + struct vfio_irq_info *irq; + struct vfio_irq_set *irq_set; + int argsz; + int32_t *pfd; + int ret; + + ret =3D vfio_get_dev_irq_info(&vdev->vbasedev, + type, + subtype, + &irq); + if (ret) { + goto out; + } + + ret =3D event_notifier_init(notifier, 0); + if (ret) { + error_report("vfio: Unable to init event notifier for device reque= st"); + goto out; + } + + argsz =3D sizeof(*irq_set) + sizeof(*pfd); + + irq_set =3D g_malloc0(argsz); + irq_set->argsz =3D argsz; + irq_set->flags =3D VFIO_IRQ_SET_DATA_EVENTFD | + VFIO_IRQ_SET_ACTION_TRIGGER; + irq_set->index =3D irq->index; + irq_set->start =3D 0; + irq_set->count =3D 1; + pfd =3D (int32_t *)&irq_set->data; + + *pfd =3D event_notifier_get_fd(notifier); + qemu_set_fd_handler(*pfd, handler, NULL, vdev); + + ret =3D ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set); + if (ret) { + error_report("vfio: Failed to set up device request notification"); + qemu_set_fd_handler(*pfd, NULL, NULL, vdev); + event_notifier_cleanup(notifier); + } + + g_free(irq_set); + +out: + return ret; +} + +static int vfio_register_display_notifier(VFIOPCIDevice *vdev) +{ + VFIODisplay *dpy =3D vdev->dpy; + int ret; + + ret =3D register_display_notifier(vdev, VFIO_IRQ_TYPE_GFX, + VFIO_IRQ_SUBTYPE_GFX_PRI_PLANE_FLIP, + &dpy->pri_event_notifier, + primary_plane_update); + + if (ret) { + goto out; + } + + ret =3D register_display_notifier(vdev, VFIO_IRQ_TYPE_GFX, + VFIO_IRQ_SUBTYPE_GFX_CUR_PLANE_FLIP, + &dpy->cur_event_notifier, + cursor_plane_update); +out: + if (ret) { + dpy->event_flags =3D 0; + } else { + dpy->event_flags =3D VFIO_IRQ_EVENT_ENABLE; + } + + return ret; +} + +static void unregister_display_notifier(VFIOPCIDevice *vdev, + uint32_t type, uint32_t subtype, + EventNotifier *notifier) +{ + VFIODisplay *dpy =3D vdev->dpy; + int argsz; + struct vfio_irq_info *irq; + struct vfio_irq_set *irq_set; + int32_t *pfd; + int ret; + + if (!dpy->event_flags) { + return; + } + + ret =3D vfio_get_dev_irq_info(&vdev->vbasedev, + type, + subtype, + &irq); + if (ret) { + return ; + } + + argsz =3D sizeof(*irq_set) + sizeof(*pfd); + + irq_set =3D g_malloc0(argsz); + irq_set->argsz =3D argsz; + irq_set->flags =3D VFIO_IRQ_SET_DATA_EVENTFD | + VFIO_IRQ_SET_ACTION_TRIGGER; + irq_set->index =3D irq->index; + irq_set->start =3D 0; + irq_set->count =3D 1; + pfd =3D (int32_t *)&irq_set->data; + *pfd =3D -1; + + if (ioctl(vdev->vbasedev.fd, VFIO_DEVICE_SET_IRQS, irq_set)) { + error_report("vfio: Failed to de-assign device request fd: %m"); + } + g_free(irq_set); + qemu_set_fd_handler(event_notifier_get_fd(notifier), + NULL, NULL, vdev); + event_notifier_cleanup(notifier); +} + +static void vfio_unregister_display_notifier(VFIOPCIDevice *vdev) +{ + VFIODisplay *dpy =3D vdev->dpy; + + unregister_display_notifier(vdev, VFIO_IRQ_TYPE_GFX, + VFIO_IRQ_SUBTYPE_GFX_PRI_PLANE_FLIP, + &dpy->pri_event_notifier); + + unregister_display_notifier(vdev, VFIO_IRQ_TYPE_GFX, + VFIO_IRQ_SUBTYPE_GFX_CUR_PLANE_FLIP, + &dpy->cur_event_notifier); + dpy->event_flags =3D false; +} + int vfio_display_probe(VFIOPCIDevice *vdev, Error **errp) { struct vfio_device_gfx_plane_info probe; @@ -531,6 +715,7 @@ void vfio_display_finalize(VFIOPCIDevice *vdev) return; } =20 + vfio_unregister_display_notifier(vdev); graphic_console_close(vdev->dpy->con); vfio_display_dmabuf_exit(vdev->dpy); vfio_display_region_exit(vdev->dpy); diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 5cab6a1b81..a3f03b20e8 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -27,6 +27,7 @@ #include "qemu/notify.h" #include "ui/console.h" #include "hw/display/ramfb.h" +#include "qemu/event_notifier.h" #ifdef CONFIG_LINUX #include #endif @@ -145,6 +146,10 @@ typedef struct VFIODMABuf { QTAILQ_ENTRY(VFIODMABuf) next; } VFIODMABuf; =20 +#define VFIO_IRQ_EVENT_ENABLE (1 << 0) +#define VFIO_IRQ_EVENT_PRIMRAY_PLANE_FLIP (1 << 1) +#define VFIO_IRQ_EVENT_CURSOR_PLANE_FLIP (1 << 2) + typedef struct VFIODisplay { QemuConsole *con; RAMFBState *ramfb; @@ -152,6 +157,9 @@ typedef struct VFIODisplay { struct vfio_region_gfx_edid *edid_regs; uint8_t *edid_blob; QEMUTimer *edid_link_timer; + EventNotifier pri_event_notifier; + EventNotifier cur_event_notifier; + uint32_t event_flags; struct { VFIORegion buffer; DisplaySurface *surface; --=20 2.17.1