From nobody Sun Apr 28 17:12:38 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549895052138641.0376557476463; Mon, 11 Feb 2019 06:24:12 -0800 (PST) Received: from localhost ([127.0.0.1]:50854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtCVE-0003jJ-LK for importer@patchew.org; Mon, 11 Feb 2019 09:24:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtCUB-0003EM-Oh for qemu-devel@nongnu.org; Mon, 11 Feb 2019 09:23:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtCUA-0006MJ-Ji for qemu-devel@nongnu.org; Mon, 11 Feb 2019 09:23:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55858) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtCUA-0006La-9a for qemu-devel@nongnu.org; Mon, 11 Feb 2019 09:23:02 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1CBC087633; Mon, 11 Feb 2019 14:15:17 +0000 (UTC) Received: from diego.redhat.com (ovpn-204-236.brq.redhat.com [10.40.204.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 178E962F8B; Mon, 11 Feb 2019 14:15:10 +0000 (UTC) From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= To: qemu-devel@nongnu.org, kraxel@redhat.com Date: Mon, 11 Feb 2019 15:15:09 +0100 Message-Id: <20190211141509.26964-1-lhrazky@redhat.com> In-Reply-To: <20190205094628.632m4avyszuevktp@sirius.home.kraxel.org> References: <20190205094628.632m4avyszuevktp@sirius.home.kraxel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 11 Feb 2019 14:15:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] spice: set device address and device display ID in QXL interface 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: spice-devel@lists.freedesktop.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Calls the new SPICE QXL interface function spice_qxl_set_device_info to set the hardware address of the graphics device represented by the QXL interface (e.g. a PCI path) and the device display IDs (the IDs of the device's monitors that belong to this QXL interface). Also stops using the deprecated spice_qxl_set_max_monitors, the new interface function replaces it. Signed-off-by: Luk=C3=A1=C5=A1 Hr=C3=A1zk=C3=BD --- Hi, I've fixed the undefined reference by checking the parent_dev pointer directly instead of through pci_bus_is_root(), that was the only function needed that's not built with PCI_CONFIG=3Dn. Added a comment to explain it too. Changes since v2: * Check the parent_dev pointer directly instead of calling pci_bus_is_root(). Cheers, Lukas hw/display/qxl.c | 14 ++++++++++- include/ui/spice-display.h | 4 ++++ ui/spice-core.c | 49 ++++++++++++++++++++++++++++++++++++++ ui/spice-display.c | 11 +++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index da8fd5a40a..c8ce5781e0 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -276,7 +276,8 @@ static void qxl_spice_monitors_config_async(PCIQXLDevic= e *qxl, int replay) QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG, 0)); } else { -#if SPICE_SERVER_VERSION >=3D 0x000c06 /* release 0.12.6 */ +/* >=3D release 0.12.6, < release 0.14.2 */ +#if SPICE_SERVER_VERSION >=3D 0x000c06 && SPICE_SERVER_VERSION < 0x000e02 if (qxl->max_outputs) { spice_qxl_set_max_monitors(&qxl->ssd.qxl, qxl->max_outputs); } @@ -2188,6 +2189,17 @@ static void qxl_realize_common(PCIQXLDevice *qxl, Er= ror **errp) SPICE_INTERFACE_QXL_MAJOR, SPICE_INTERFACE_QXL_MINOR); return; } + +#if SPICE_SERVER_VERSION >=3D 0x000e02 /* release 0.14.2 */ + char device_address[256] =3D ""; + if (qemu_spice_fill_device_address(qxl->vga.con, device_address, 256))= { + spice_qxl_set_device_info(&qxl->ssd.qxl, + device_address, + 0, + qxl->max_outputs); + } +#endif + qemu_add_vm_change_state_handler(qxl_vm_change_state_handler, qxl); =20 qxl->update_irq =3D qemu_bh_new(qxl_update_irq_bh, qxl); diff --git a/include/ui/spice-display.h b/include/ui/spice-display.h index 87a84a59d4..53c3612c32 100644 --- a/include/ui/spice-display.h +++ b/include/ui/spice-display.h @@ -179,3 +179,7 @@ void qemu_spice_wakeup(SimpleSpiceDisplay *ssd); void qemu_spice_display_start(void); void qemu_spice_display_stop(void); int qemu_spice_display_is_running(SimpleSpiceDisplay *ssd); + +bool qemu_spice_fill_device_address(QemuConsole *con, + char *device_address, + size_t size); diff --git a/ui/spice-core.c b/ui/spice-core.c index a40fb2c00d..a2f8e15030 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -34,6 +34,7 @@ #include "qemu/option.h" #include "migration/misc.h" #include "hw/hw.h" +#include "hw/pci/pci_bus.h" #include "ui/spice-display.h" =20 /* core bits */ @@ -863,6 +864,54 @@ bool qemu_spice_have_display_interface(QemuConsole *co= n) return false; } =20 +/* + * Recursively (in reverse order) appends addresses of PCI devices as it m= oves + * up in the PCI hierarchy. + * + * @returns true on success, false when the buffer wasn't large enough + */ +static bool append_pci_address(char *buf, size_t buf_size, const PCIDevice= *pci) +{ + PCIBus *bus =3D pci_get_bus(pci); + // equivalent to if (!pci_bus_is_root(bus)), but the function is not b= uilt + // with PCI_CONFIG=3Dn, avoid using an #ifdef by checking directly + if (bus->parent_dev !=3D NULL) { + append_pci_address(buf, buf_size, bus->parent_dev); + } + + size_t len =3D strlen(buf); + ssize_t written =3D snprintf(buf + len, buf_size - len, "/%02x.%x", + PCI_SLOT(pci->devfn), PCI_FUNC(pci->devfn)); + + return written > 0 && written < buf_size - len; +} + +bool qemu_spice_fill_device_address(QemuConsole *con, + char *device_address, + size_t size) +{ + DeviceState *dev =3D DEVICE(object_property_get_link(OBJECT(con), + "device", + &error_abort)); + PCIDevice *pci =3D (PCIDevice *) object_dynamic_cast(OBJECT(dev), + TYPE_PCI_DEVICE); + + if (pci =3D=3D NULL) { + warn_report("Setting device address of a display device to SPICE: " + "Not a PCI device."); + return false; + } + + strncpy(device_address, "pci/0000", size); + if (!append_pci_address(device_address, size, pci)) { + warn_report("Setting device address of a display device to SPICE: " + "Too many PCI devices in the chain."); + return false; + } + + return true; +} + int qemu_spice_add_display_interface(QXLInstance *qxlin, QemuConsole *con) { if (g_slist_find(spice_consoles, con)) { diff --git a/ui/spice-display.c b/ui/spice-display.c index aea6f6ebce..a5e26479a8 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -1147,6 +1147,17 @@ static void qemu_spice_display_init_one(QemuConsole = *con) =20 ssd->qxl.base.sif =3D &dpy_interface.base; qemu_spice_add_display_interface(&ssd->qxl, con); + +#if SPICE_SERVER_VERSION >=3D 0x000e02 /* release 0.14.2 */ + char device_address[256] =3D ""; + if (qemu_spice_fill_device_address(con, device_address, 256)) { + spice_qxl_set_device_info(&ssd->qxl, + device_address, + qemu_console_get_head(con), + 1); + } +#endif + qemu_spice_create_host_memslot(ssd); =20 register_displaychangelistener(&ssd->dcl); --=20 2.20.1