From nobody Thu Nov 6 06:17:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.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 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539787353500244.90368645249362; Wed, 17 Oct 2018 07:42:33 -0700 (PDT) Received: from localhost ([::1]:37073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCn1s-00060K-BH for importer@patchew.org; Wed, 17 Oct 2018 10:42:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCmvn-0001Oy-MZ for qemu-devel@nongnu.org; Wed, 17 Oct 2018 10:36:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCmvl-0007uo-In for qemu-devel@nongnu.org; Wed, 17 Oct 2018 10:36:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46588) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCmvl-0007uJ-6g for qemu-devel@nongnu.org; Wed, 17 Oct 2018 10:36:13 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D96DB30EBB51; Wed, 17 Oct 2018 14:36:11 +0000 (UTC) Received: from diego.redhat.com (unknown [10.40.205.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BD451057054; Wed, 17 Oct 2018 14:36:10 +0000 (UTC) From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= To: spice-devel@lists.freedesktop.org, qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 16:36:03 +0200 Message-Id: <20181017143604.5194-2-lhrazky@redhat.com> In-Reply-To: <20181017143604.5194-1-lhrazky@redhat.com> References: <20181017143604.5194-1-lhrazky@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 17 Oct 2018 14:36:11 +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] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest 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: kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Adds two functions to let QEMU provide information to identify graphics devices and their monitors in the guest: * device address - The path identifying the device on the system (e.g. PCI path): spice_qxl_set_device_address(...) * device display ID - The index of the monitor on the graphics device: spice_qxl_monitor_set_device_display_id(...) Signed-off-by: Luk=C3=A1=C5=A1 Hr=C3=A1zk=C3=BD --- server/red-qxl.c | 89 ++++++++++++++++++++++++++++++++++++++++ server/spice-qxl.h | 5 +++ server/spice-server.syms | 6 +++ 3 files changed, 100 insertions(+) diff --git a/server/red-qxl.c b/server/red-qxl.c index 97940611..0b2043e1 100644 --- a/server/red-qxl.c +++ b/server/red-qxl.c @@ -41,6 +41,9 @@ #include "red-qxl.h" =20 =20 +#define MAX_PATH_LEN 256 +#define MAX_MONITORS_COUNT 16 + struct QXLState { QXLWorker qxl_worker; QXLInstance *qxl; @@ -53,6 +56,9 @@ struct QXLState { unsigned int max_monitors; RedsState *reds; RedWorker *worker; + char device_address[MAX_PATH_LEN]; + uint32_t device_display_ids[MAX_MONITORS_COUNT]; + size_t monitors_count; // length of ^^^ =20 pthread_mutex_t scanout_mutex; SpiceMsgDisplayGlScanoutUnix scanout; @@ -846,6 +852,89 @@ void red_qxl_gl_draw_async_complete(QXLInstance *qxl) red_qxl_async_complete(qxl, cookie); } =20 +/** + * spice_qxl_set_device_address: + * @instance the QXL instance to set the path to + * @device_address the path of the device this QXL instance belongs to + * + * Sets the hardware address (e.g. PCI) of the graphics device represented= by + * this QXL interface instance. + * + * The supported format is: + * "pci//./.../." + * + * The "pci" identifies the rest of the string as a PCI adress. It is the = only + * supported address at the moment, other identifiers can be introduced la= ter. + * is the PCI domain, followed by . of any PCI br= idges + * in the chain leading to the device. The last . is the + * graphics device. + */ +SPICE_GNUC_VISIBLE +void spice_qxl_set_device_address(QXLInstance *instance, const char *devic= e_address) +{ + g_return_if_fail(device_address !=3D NULL); + + size_t dp_len =3D strnlen(device_address, MAX_PATH_LEN); + if (dp_len >=3D MAX_PATH_LEN) { + spice_error("PCI device path too long: %lu > %u", dp_len, MAX_PATH= _LEN); + return; + } + + strncpy(instance->st->device_address, device_address, MAX_PATH_LEN); + + g_debug("QXL Instance %d setting device address \"%s\"", instance->id,= device_address); +} + +/** + * spice_qxl_monitor_set_device_display_id: + * @instance the QXL instance to set the device display ID to + * @monitor_id the SPICE monitor ID to set the device display ID to + * @device_display_id the actual ID of the display (output) on the graphic= s device + * + * Sets the device display ID for a given monitor ID in a QXL instance. The + * monitor IDs are expected and required to be a consecutive sequence star= ting + * at 0. The function requires the calls to be made in the sequence to pre= vent + * holes. + * + * The requirement for the monitor ID to be a sequence starting from 0 com= es + * from the mechanism of generating a single display_id from channel_id and + * monitor_id on the client: + * + * display_id =3D channel_id + monitor_id + * + * This is unambiguous either if there is only a single channel with multi= ple + * monitors ("legacy" QXL on linux case) or multiple channels with only a + * single monitor. Also both channel_id and monitor_id need to be a sequen= ce + * starting from 0, otherwise there is still a possibility of collisions. + */ +SPICE_GNUC_VISIBLE +void spice_qxl_monitor_set_device_display_id(QXLInstance *instance, + uint32_t monitor_id, + uint32_t device_display_id) +{ + if (instance->st->monitors_count >=3D MAX_MONITORS_COUNT) { + spice_error("Cannot register more than %u monitors per QXL interfa= ce", MAX_MONITORS_COUNT); + return; + } + + if (monitor_id > instance->st->monitors_count) { + spice_error("Monitor ID %u is not inside a consecutive sequence of= monitor IDs " + "starting from zero. Needs to be lower than or equal t= o %lu.", + monitor_id, instance->st->monitors_count); + return; + } + + instance->st->device_display_ids[monitor_id] =3D device_display_id; + + g_debug("QXL Instance %d setting device display ID %u for monitor ID %= u", + instance->id, device_display_id, monitor_id); + + // if we're adding a new ID (and not resetting an existing one), incre= ment the array length + if (monitor_id =3D=3D instance->st->monitors_count) { + instance->st->monitors_count++; + } +} + void red_qxl_init(RedsState *reds, QXLInstance *qxl) { QXLState *qxl_state; diff --git a/server/spice-qxl.h b/server/spice-qxl.h index 0c4e75fc..c9ea6564 100644 --- a/server/spice-qxl.h +++ b/server/spice-qxl.h @@ -114,6 +114,11 @@ void spice_qxl_gl_draw_async(QXLInstance *instance, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint64_t cookie); +/* since spice 0.14.2 */ +void spice_qxl_set_device_address(QXLInstance *instance, const char *devic= e_path); +void spice_qxl_monitor_set_device_display_id(QXLInstance *instance, + uint32_t monitor_id, + uint32_t device_display_id); =20 typedef struct QXLDevInitInfo { uint32_t num_memslots_groups; diff --git a/server/spice-server.syms b/server/spice-server.syms index edf04a42..6e9ffa93 100644 --- a/server/spice-server.syms +++ b/server/spice-server.syms @@ -173,3 +173,9 @@ SPICE_SERVER_0.13.2 { global: spice_server_set_video_codecs; } SPICE_SERVER_0.13.1; + +SPICE_SERVER_0.14.2 { +global: + spice_qxl_set_device_address; + spice_qxl_monitor_set_device_display_id; +} SPICE_SERVER_0.13.2; --=20 2.19.1 From nobody Thu Nov 6 06:17:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.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 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539787197252618.0468410483575; Wed, 17 Oct 2018 07:39:57 -0700 (PDT) Received: from localhost ([::1]:37049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCmzL-0004FO-8y for importer@patchew.org; Wed, 17 Oct 2018 10:39:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCmvy-0001XL-Cj for qemu-devel@nongnu.org; Wed, 17 Oct 2018 10:36:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCmvn-0007vk-DN for qemu-devel@nongnu.org; Wed, 17 Oct 2018 10:36:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45334) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCmvm-0007uu-Vo for qemu-devel@nongnu.org; Wed, 17 Oct 2018 10:36:15 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F95080F6D; Wed, 17 Oct 2018 14:36:13 +0000 (UTC) Received: from diego.redhat.com (unknown [10.40.205.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52B221057054; Wed, 17 Oct 2018 14:36:12 +0000 (UTC) From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= To: spice-devel@lists.freedesktop.org, qemu-devel@nongnu.org Date: Wed, 17 Oct 2018 16:36:04 +0200 Message-Id: <20181017143604.5194-3-lhrazky@redhat.com> In-Reply-To: <20181017143604.5194-1-lhrazky@redhat.com> References: <20181017143604.5194-1-lhrazky@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 17 Oct 2018 14:36:13 +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] [RFC PATCH qemu v2 2/2] 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: kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Calls new SPICE QXL interface functions to set: * The hardware address of the graphics device represented by the QXL interface (e.g. a PCI path): spice_qxl_set_device_address(...) * The device display IDs (the IDs of the device's monitors that belong to this QXL interface): spice_qxl_monitor_set_device_display_id(...) Signed-off-by: Luk=C3=A1=C5=A1 Hr=C3=A1zk=C3=BD --- hw/display/qxl.c | 8 ++++++++ ui/spice-core.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- ui/spice-display.c | 5 +++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index f608abc769..63144f42b4 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -2184,6 +2184,14 @@ 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 */ + // register all possible device display IDs to SPICE server + for (int i =3D 0; i < qxl->max_outputs; ++i) { + spice_qxl_monitor_set_device_display_id(&qxl->ssd.qxl, i, i); + } +#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/ui/spice-core.c b/ui/spice-core.c index a4fbbc3898..2e01beea03 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -35,6 +35,8 @@ #include "qemu/option.h" #include "migration/misc.h" #include "hw/hw.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "ui/spice-display.h" =20 /* core bits */ @@ -871,6 +873,26 @@ 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_recursive(char *buf, size_t buf_size, const= PCIDevice *pci) +{ + PCIBus *bus =3D pci_get_bus(pci); + if (!pci_bus_is_root(bus)) { + append_pci_address_recursive(buf, buf_size, bus->parent_dev); + } + + size_t len =3D strlen(buf); + size_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; +} + int qemu_spice_add_display_interface(QXLInstance *qxlin, QemuConsole *con) { if (g_slist_find(spice_consoles, con)) { @@ -878,7 +900,28 @@ int qemu_spice_add_display_interface(QXLInstance *qxli= n, QemuConsole *con) } qxlin->id =3D qemu_console_get_index(con); spice_consoles =3D g_slist_append(spice_consoles, con); - return qemu_spice_add_interface(&qxlin->base); + int res =3D qemu_spice_add_interface(&qxlin->base); + +#if SPICE_SERVER_VERSION >=3D 0x000e02 /* release 0.14.2 */ + DeviceState *dev =3D DEVICE(object_property_get_link(OBJECT(con), "dev= ice", &error_abort)); + PCIDevice *pci =3D (PCIDevice *) object_dynamic_cast(OBJECT(dev), TYPE= _PCI_DEVICE); + + if (pci =3D=3D NULL) { + warn_report("Setting PCI path of a display device to SPICE: Not a = PCI device."); + return res; + } + + char device_path[128] =3D "pci/0000"; // hardcoded PCI domain 0000 + if (!append_pci_address_recursive(device_path, sizeof(device_path), pc= i)) { + warn_report("Setting PCI path of a display device to SPICE: " + "Too many PCI devices in the chain."); + return res; + } + + spice_qxl_set_device_address(qxlin, device_path); +#endif + + return res; } =20 static int qemu_spice_set_ticket(bool fail_if_conn, bool disconnect_if_con= n) diff --git a/ui/spice-display.c b/ui/spice-display.c index 2f8adb6b9f..f620750803 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -1129,6 +1129,11 @@ 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 */ + spice_qxl_monitor_set_device_display_id(&ssd->qxl, 0, qemu_console_get= _head(con)); +#endif + qemu_spice_create_host_memslot(ssd); =20 register_displaychangelistener(&ssd->dcl); --=20 2.19.1