Skip to contentSkip to conversation

QXL interface to set monitor ID

RFC PATCH In review Lukáš Hrázký 4 participants 10 messages Nov 7, 2018 – Nov 9, 2018

lore
Share & tools
lore
#0 lore raw

v3 cover QXL interface to set monitor ID

Hello,

another version of the proposed API for monitor identification information. Still not for merge yet, the plan is to merge when it's complete.

Changes since v2:
* Merged the two API functions into one:
spice_qxl_set_device_info(QXLInstance *instance,
const char *device_address, uint32_t device_display_id_start, uint32_t device_display_id_count)

* Minor fixes and documentation adjustments

Signature · 1 line
2.19.1
#1 lore raw

RFC PATCH v3 1/3 QXL interface: add a function to identify monitors in the guest

Adds a function to let QEMU provide information to identify graphics devices and their monitors in the guest. The function (spice_qxl_set_device_info) sets the device address (e.g. a PCI path) and monitor ID -> device display ID mapping of displays exposed by given QXL interface.

---
 server/red-qxl.c         | 44 ++++++++++++++++++++++++++++++++++++++
 server/spice-qxl.h       | 46 ++++++++++++++++++++++++++++++++++++++++
 server/spice-server.syms |  5 +++++
 3 files changed, 95 insertions(+)
server/red-qxl.c +44 -0
index 97940611..0ea424cd 100644
@@ -41,6 +41,9 @@
 #include "red-qxl.h"
 
 
+#define MAX_DEVICE_ADDRESS_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_DEVICE_ADDRESS_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,44 @@ void red_qxl_gl_draw_async_complete(QXLInstance *qxl)
     red_qxl_async_complete(qxl, cookie);
 }
 
+SPICE_GNUC_VISIBLE
+void spice_qxl_set_device_info(QXLInstance *instance,
+                               const char *device_address,
+                               uint32_t device_display_id_start,
+                               uint32_t device_display_id_count)
+{
+    g_return_if_fail(device_address != NULL);
+
+    size_t da_len = strnlen(device_address, MAX_DEVICE_ADDRESS_LEN);
+    if (da_len >= MAX_DEVICE_ADDRESS_LEN) {
+        spice_error("Device address too long: %lu > %u", da_len, MAX_DEVICE_ADDRESS_LEN);
+        return;
+    }
+
+    if (device_display_id_count > MAX_MONITORS_COUNT) {
+        spice_error("Device display ID count (%u) is greater than limit %u",
+                    device_display_id_count,
+                    MAX_MONITORS_COUNT);
+        return;
+    }
+
+    strncpy(instance->st->device_address, device_address, MAX_DEVICE_ADDRESS_LEN);
+
+    g_debug("QXL Instance %d setting device address \"%s\" and monitor -> device display mapping:",
+            instance->id,
+            device_address);
+
+    // store the mapping monitor_id -> device_display_id
+    for (uint32_t monitor_id = 0; monitor_id < device_display_id_count; ++monitor_id) {
+        uint32_t device_display_id = device_display_id_start + monitor_id;
+        instance->st->device_display_ids[monitor_id] = device_display_id;
+        g_debug("   monitor ID %u -> device display ID %u",
+                monitor_id, device_display_id);
+    }
+
+    instance->st->monitors_count = device_display_id_count;
+}
+
 void red_qxl_init(RedsState *reds, QXLInstance *qxl)
 {
     QXLState *qxl_state;
server/spice-qxl.h +46 -0

52 lines not on this page · raw message

server/spice-server.syms +5 -0
index edf04a42..ac4d9b14 100644
@@ -173,3 +173,8 @@ 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_info;
+} SPICE_SERVER_0.13.2;
Signature · 1 line
2.19.1
#2 lore raw

Re: [Qemu-devel] [RFC PATCH spice v3 1/3] QXL interface: add a function to identify monitors in the guest

Hi,

Quoted 4 lines

+ * The device_display_id_{start,count} denotes the sequence of device display
+ * IDs that map to the zero-based sequence of monitor IDs provided by monitors
+ * config on this interface. For example with device_display_id_start = 2 and
+ * device_display_id_count = 3 you get the following mapping:

Quoted 8 lines
+ * monitor_id  ->  device_display_id
+ *          0  ->  2
+ *          1  ->  3
+ *          2  ->  4

+ *
+ * Note this example is unsupported in practice. The only supported cases are
+ * either a single device display ID (count = 1) or multiple device display IDs
+ * in a sequence starting from 0.

This is confusing. The usage of this api in the qemu counterpart looks sane though.

cheers,
Gerd

#3 lore raw

Re: [Qemu-devel] [RFC PATCH spice v3 1/3] QXL interface: add a function to identify monitors in the guest

Hello,

Quoted 15 lines · Gerd Hoffmann

Hi,

Quoted 4 lines

+ * The device_display_id_{start,count} denotes the sequence of device display
+ * IDs that map to the zero-based sequence of monitor IDs provided by monitors
+ * config on this interface. For example with device_display_id_start = 2 and
+ * device_display_id_count = 3 you get the following mapping:

Quoted 8 lines
+ * monitor_id  ->  device_display_id
+ *          0  ->  2
+ *          1  ->  3
+ *          2  ->  4

+ *
+ * Note this example is unsupported in practice. The only supported cases are
+ * either a single device display ID (count = 1) or multiple device display IDs
+ * in a sequence starting from 0.

Quoted 2 lines

This is confusing. The usage of this api in the qemu counterpart looks sane though.

Not sure what you find confusing in particular... The example? Using an example and then saying it's not supported? (I wated to use a nontrivial example that will show the concept...) Suggestions for improvement?

Thanks,
Lukas

Quoted 3 lines

cheers,
Gerd

#4 lore raw

Re: [Qemu-devel] [Spice-devel] [RFC PATCH spice v3 1/3] QXL interface: add a function to identify monitors in the guest

Quoted 27 lines · Lukáš Hrázký

Hello,

Quoted 20 lines · Gerd Hoffmann

Hi,

Quoted 11 lines

+ * The device_display_id_{start,count} denotes the sequence of device display
+ * IDs that map to the zero-based sequence of monitor IDs provided by monitors
+ * config on this interface. For example with device_display_id_start = 2 and
+ * device_display_id_count = 3 you get the following mapping:

+ * monitor_id  ->  device_display_id
+ *          0  ->  2
+ *          1  ->  3
+ *          2  ->  4
Quoted 6 lines

+ *
+ * Note this example is unsupported in practice. The only supported cases are
+ * either a single device display ID (count = 1) or multiple device display IDs
+ * in a sequence starting from 0.

Quoted 3 lines

This is confusing. The usage of this api in the qemu counterpart looks
sane though.

Quoted 5 lines

Not sure what you find confusing in particular... The example? Using an
example and then saying it's not supported? (I wated to use a nontrivial example that will show the concept...) Suggestions for improvement?

It is funny that you chose an unsupported example for demonstration, but I can't think of a better option. The supported scenarios don't demonstrate the full behavior very well...

Quoted 12 lines

Thanks,
Lukas

Quoted 3 lines

cheers,
Gerd

_______________________________________________
Spice-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/spice-devel

#5 lore raw

Re: [Qemu-devel] [RFC PATCH spice v3 1/3] QXL interface: add a function to identify monitors in the guest

In reply to Lukáš Hrázký
Quoted 18 lines · Lukáš Hrázký

Hello,

Quoted 15 lines · Gerd Hoffmann

Hi,

Quoted 12 lines

+ * The device_display_id_{start,count} denotes the sequence of device display
+ * IDs that map to the zero-based sequence of monitor IDs provided by monitors
+ * config on this interface. For example with device_display_id_start = 2 and
+ * device_display_id_count = 3 you get the following mapping:

+ * monitor_id  ->  device_display_id
+ *          0  ->  2
+ *          1  ->  3
+ *          2  ->  4

+ *
+ * Note this example is unsupported in practice. The only supported cases are
+ * either a single device display ID (count = 1) or multiple device display IDs
+ * in a sequence starting from 0.

Quoted 5 lines
Quoted 2 lines

This is confusing. The usage of this api in the qemu counterpart looks sane though.

Not sure what you find confusing in particular... The example? Using an example and then saying it's not supported?

Yes, that for example. Also wondering why device_display_id doesn't start at zero.

cheers,
Gerd

#6 lore raw

Re: [Qemu-devel] [RFC PATCH spice v3 1/3] QXL interface: add a function to identify monitors in the guest

Quoted 24 lines · Lukáš Hrázký
Quoted 23 lines

Hello,

Quoted 20 lines · Gerd Hoffmann

Hi,

Quoted 17 lines

+ * The device_display_id_{start,count} denotes the sequence of device display
+ * IDs that map to the zero-based sequence of monitor IDs provided by monitors
+ * config on this interface. For example with device_display_id_start = 2 and
+ * device_display_id_count = 3 you get the following mapping:

+ * monitor_id  ->  device_display_id
+ *          0  ->  2
+ *          1  ->  3
+ *          2  ->  4

+ *
+ * Note this example is unsupported in practice. The only supported cases are
+ * either a single device display ID (count = 1) or multiple device display IDs
+ * in a sequence starting from 0.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

This is confusing. The usage of this api in the qemu counterpart looks sane though.

Not sure what you find confusing in particular... The example? Using an example and then saying it's not supported?

Yes, that for example. Also wondering why device_display_id doesn't start at zero.

You introduced this ID so you should remember.
It starts from 0, just this is not the first registration, the other displays were registered to other QXL instances.
This was introduced for virtio-gpu to be able to register the different outputs to different QXL instances so to have

first output/display:
spice_qxl_set_device_info(instance1, path1, 0, 1);
second:
spice_qxl_set_device_info(instance2, path1, 1, 1);
third:
spice_qxl_set_device_info(instance3, path1, 2, 1);

So as you can see device_display_id start from 0 but does not mean is always 0 for every call.

Quoted 5 lines

cheers,
Gerd

Frediano

#7 lore raw

Re: [Qemu-devel] [RFC PATCH spice v3 1/3] QXL interface: add a function to identify monitors in the guest

Hi,

Quoted 6 lines

first output/display:
spice_qxl_set_device_info(instance1, path1, 0, 1);
second:
spice_qxl_set_device_info(instance2, path1, 1, 1);
third:
spice_qxl_set_device_info(instance3, path1, 2, 1);

That is a much better example IMHO.

cheers,
Gerd

#8 lore raw

RFC PATCH v3 2/3 QXL interface: deprecate spice_qxl_set_max_monitors

In reply to Lukáš Hrázký

Replace it by spice_qxl_set_device_info. Note we can't use monitors_count for what's stored in max_monitors, because monitors_count denotes the length of the device_display_ids array, which spice_qxl_set_max_monitors doesn't touch.

---
 server/red-qxl.c   | 1 +
 server/spice-qxl.h | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
server/red-qxl.c +1 -0
index 0ea424cd..6ffd8286 100644
@@ -888,6 +888,7 @@ void spice_qxl_set_device_info(QXLInstance *instance,
     }
 
     instance->st->monitors_count = device_display_id_count;
+    instance->st->max_monitors = device_display_id_count;
 }
 
 void red_qxl_init(RedsState *reds, QXLInstance *qxl)
server/spice-qxl.h +2 -2
index 547d3d93..e7af5e5e 100644
@@ -101,9 +101,9 @@ void spice_qxl_monitors_config_async(QXLInstance *instance, QXLPHYSICAL monitors
                                      int group_id, uint64_t cookie);
 /* since spice 0.12.3 */
 void spice_qxl_driver_unload(QXLInstance *instance);
-/* since spice 0.12.6 */
+/* since spice 0.12.6, deprecated since 0.14.2, spice_qxl_set_device_info replaces it */
 void spice_qxl_set_max_monitors(QXLInstance *instance,
-                                unsigned int max_monitors);
+                                unsigned int max_monitors) SPICE_GNUC_DEPRECATED;
 /* since spice 0.13.1 */
 void spice_qxl_gl_scanout(QXLInstance *instance,
                           int fd,
Signature · 1 line
2.19.1
#9 lore raw

RFC PATCH v3 3/3 spice: set device address and device display ID in QXL interface

In reply to Lukáš Hrázký

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.

---
 hw/display/qxl.c           | 14 ++++++++++++-
 include/ui/spice-display.h |  2 ++
 ui/spice-core.c            | 42 ++++++++++++++++++++++++++++++++++++++
 ui/spice-display.c         | 11 ++++++++++
 4 files changed, 68 insertions(+), 1 deletion(-)
hw/display/qxl.c +13 -1
index f608abc769..f4bef8e4da 100644
@@ -276,7 +276,8 @@ static void qxl_spice_monitors_config_async(PCIQXLDevice *qxl, int replay)
                     QXL_COOKIE_TYPE_POST_LOAD_MONITORS_CONFIG,
                     0));
     } else {
-#if SPICE_SERVER_VERSION >= 0x000c06 /* release 0.12.6 */
+#if SPICE_SERVER_VERSION >= 0x000c06 /* release 0.12.6 */ && \
+    SPICE_SERVER_VERSION < 0x000e02
         if (qxl->max_outputs) {
             spice_qxl_set_max_monitors(&qxl->ssd.qxl, qxl->max_outputs);
         }
@@ -2184,6 +2185,17 @@ static void qxl_realize_common(PCIQXLDevice *qxl, Error **errp)
                    SPICE_INTERFACE_QXL_MAJOR, SPICE_INTERFACE_QXL_MINOR);
         return;
     }
+
+#if SPICE_SERVER_VERSION >= 0x000e02 /* release 0.14.2 */
+    char device_address[256] = "";
+    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);
 
     qxl->update_irq = qemu_bh_new(qxl_update_irq_bh, qxl);
include/ui/spice-display.h +2 -0
index 87a84a59d4..7608fa7ebd 100644
@@ -179,3 +179,5 @@ 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);
ui/spice-core.c +42 -0

54 lines not on this page · raw message

ui/spice-display.c +11 -0
index 2f8adb6b9f..578ec6bf8b 100644
@@ -1129,6 +1129,17 @@ static void qemu_spice_display_init_one(QemuConsole *con)
 
     ssd->qxl.base.sif = &dpy_interface.base;
     qemu_spice_add_display_interface(&ssd->qxl, con);
+
+#if SPICE_SERVER_VERSION >= 0x000e02 /* release 0.14.2 */
+    char device_address[256] = "";
+    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);
 
     register_displaychangelistener(&ssd->dcl);
Signature · 1 line
2.19.1