From patchwork Tue Oct 9 13:10:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?THVrw6HFoSBIcsOhemvDvQ==?= X-Patchwork-Id: 981287 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42TzHD6gFbz9s7T for ; Wed, 10 Oct 2018 00:54:16 +1100 (AEDT) Received: from localhost ([::1]:51690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9sSk-0002J5-13 for incoming@patchwork.ozlabs.org; Tue, 09 Oct 2018 09:54:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9rnB-0004Hg-Ro for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:11:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9rn0-0000VH-1o for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:11:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36472) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9rmz-0000Un-PV for qemu-devel@nongnu.org; Tue, 09 Oct 2018 09:11:05 -0400 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 B2A7A4024F; Tue, 9 Oct 2018 13:11:04 +0000 (UTC) Received: from diego.redhat.com (unknown [10.40.205.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id B88FB672E2; Tue, 9 Oct 2018 13:10:59 +0000 (UTC) From: =?utf-8?b?THVrw6HFoSBIcsOhemvDvQ==?= To: spice-devel@lists.freedesktop.org, qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 15:10:51 +0200 Message-Id: <20181009131052.18500-2-lhrazky@redhat.com> In-Reply-To: <20181009131052.18500-1-lhrazky@redhat.com> References: <20181009131052.18500-1-lhrazky@redhat.com> 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.30]); Tue, 09 Oct 2018 13:11:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-Mailman-Approved-At: Tue, 09 Oct 2018 09:45:57 -0400 Subject: [Qemu-devel] [RFC PATCH spice 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Adds two functions to let QEMU provide information to identify graphics devices and their monitors in the guest: * device path - The path identifying the device on the system (e.g. PCI path): spice_qxl_device_set_path(...) * device display ID - The index of the monitor on the graphics device: spice_qxl_device_monitor_add_display_id(...) Signed-off-by: Lukáš Hrázký --- server/red-qxl.c | 67 ++++++++++++++++++++++++++++++++++++++++ server/spice-qxl.h | 3 ++ server/spice-server.syms | 6 ++++ 3 files changed, 76 insertions(+) diff --git a/server/red-qxl.c b/server/red-qxl.c index 97940611..143228ca 100644 --- a/server/red-qxl.c +++ b/server/red-qxl.c @@ -41,6 +41,9 @@ #include "red-qxl.h" +#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_path[MAX_PATH_LEN]; + uint32_t device_display_ids[MAX_MONITORS_COUNT]; + size_t monitors_count; // length of ^^^ pthread_mutex_t scanout_mutex; SpiceMsgDisplayGlScanoutUnix scanout; @@ -846,6 +852,67 @@ void red_qxl_gl_draw_async_complete(QXLInstance *qxl) red_qxl_async_complete(qxl, cookie); } +/** + * spice_qxl_device_set_path: + * @instance the QXL instance to set the path to + * @device_path the path of the device this QXL instance belongs to + * + * Sets the hardware (e.g. PCI) path of the graphics device represented by this QXL interface instance. + * + */ +SPICE_GNUC_VISIBLE +void spice_qxl_device_set_path(QXLInstance *instance, const char *device_path) +{ + g_return_if_fail(device_path != NULL); + + size_t dp_len = strnlen(device_path, MAX_PATH_LEN); + if (dp_len >= MAX_PATH_LEN) { + spice_error("PCI device path too long: %lu > %u", dp_len, MAX_PATH_LEN); + return; + } + + strncpy(instance->st->device_path, device_path, MAX_PATH_LEN); + + g_debug("QXL Instance %d setting device PCI path \"%s\"", instance->id, device_path); +} + +/** + * spice_qxl_device_monitor_add_display_id: + * @instance the QXL instance to add the display ID to + * @device_display_id the display ID to add to the QXL instance + * + * Adds a #device_display_id to this QXL interface instance. The + * #device_display_id is an index (a sequence starting from 0) into the list of + * all the displays on the graphics device. This function should be called in + * sequence for all possible displays of the device. The ID of the first call + * will belong to #monitor_id 0, and so forth in the sequence. + * + * Since for some graphics devices (e.g. virtio-gpu) a QXL interface instance + * is created per each display of a single device, you can get e.g. the single + * following call on the third QXL interface instance for this device: + * + * spice_qxl_device_monitor_add_display_id(instance, 2); + * + * This tells you that the single monitor of this QXL interface actually + * belongs to the 3rd display of the underlying device. + * + * Returns: The actual SPICE server monitor_id associated with the display + */ +SPICE_GNUC_VISIBLE +int spice_qxl_device_monitor_add_display_id(QXLInstance *instance, uint32_t device_display_id) +{ + if (instance->st->monitors_count >= MAX_MONITORS_COUNT) { + spice_error("Cannot register more than %u monitors per QXL interface", MAX_MONITORS_COUNT); + return -1; + } + + instance->st->device_display_ids[instance->st->monitors_count] = device_display_id; + + g_debug("QXL Instance %d adding device display ID %u", instance->id, device_display_id); + + return 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..ae2d5975 100644 --- a/server/spice-qxl.h +++ b/server/spice-qxl.h @@ -114,6 +114,9 @@ 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_device_set_path(QXLInstance *instance, const char *device_path); +int spice_qxl_device_monitor_add_display_id(QXLInstance *instance, uint32_t device_display_id); typedef struct QXLDevInitInfo { uint32_t num_memslots_groups; diff --git a/server/spice-server.syms b/server/spice-server.syms index edf04a42..fdeafd23 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_device_set_path; + spice_qxl_device_monitor_add_display_id; +} SPICE_SERVER_0.13.2;