QXL interface to set monitor ID
v2 cover QXL interface to set monitor ID
Hello,
sending version 2 of the RFC on the new QXL interface to identify the graphics device monitors in the guest.
Still keeping it as RFC, I'd like to get this agreed upon but not merge until the whole mechanism is implemented.
Gerd, I didn't split the QEMU patch, as I feel it kind of goes together, one without the other is not really functional. I'll still do it if you insist...
Changes since v1:
* Renamed both functions according to suggestions.
* Changed the spice_qxl_monitor_set_device_display_id() so that it actually takes the monitor_id as an argument from QEMU. Please see the documentation of the function for some explanation.
* Updated the docs.
Cheers,
Lukas
Signature · 1 line
2.19.1
RFC PATCH v2 1/2 QXL interface: add functions to identify monitors in the guest
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(...)
--- server/red-qxl.c | 89 ++++++++++++++++++++++++++++++++++++++++ server/spice-qxl.h | 5 +++ server/spice-server.syms | 6 +++ 3 files changed, 100 insertions(+)
server/red-qxl.c +89 -0
@@ -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_address[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,89 @@ void red_qxl_gl_draw_async_complete(QXLInstance *qxl)red_qxl_async_complete (qxl, cookie); } +/** +* 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/<DOMAIN>/<SLOT>.<FUNCTION>/.../<SLOT>.<FUNCTION>" +* +* 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 later. +* <DOMAIN> is the PCI domain, followed by <SLOT>.<FUNCTION> of any PCI bridges +* in the chain leading to the device. The last <SLOT>.<FUNCTION> is the +* graphics device. +*/ +SPICE_GNUC_VISIBLE +void spice_qxl_set_device_address(QXLInstance *instance, const char *device_address) +{ +g_return_if_fail (device_address !=NULL ); + +size_t dp_len =strnlen (device_address,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_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 graphics 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 starting +* at 0. The function requires the calls to be made in the sequence to prevent +* holes. +* +* The requirement for the monitor ID to be a sequence starting from 0 comes +* from the mechanism of generating a single display_id from channel_id and +* monitor_id on the client: +* +* display_id = channel_id + monitor_id +* +* This is unambiguous either if there is only a single channel with multiple +* 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 sequence +* 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 >=MAX_MONITORS_COUNT ) { +spice_error ("Cannot register more than %u monitors per QXL interface" ,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 to %lu." , + monitor_id, instance->st->monitors_count); +return ; + } + + instance->st->device_display_ids[monitor_id] = 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), increment the array length +if (monitor_id == instance->st->monitors_count) { + instance->st->monitors_count++; + } +} +void red_qxl_init (RedsState *reds,QXLInstance *qxl) {QXLState *qxl_state;
server/spice-qxl.h +5 -0
@@ -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 *device_path); +void spice_qxl_monitor_set_device_display_id (QXLInstance *instance, +uint32_t monitor_id, +uint32_t device_display_id); typedef struct QXLDevInitInfo { uint32_t num_memslots_groups;
server/spice-server.syms +6 -0
@@ -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;
Signature · 1 line
2.19.1
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
Quoted 10 lines
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(...)
This seems to indicate that this device is bound in some way to the previous information but having 2 APIs make more fragile, potentially one could call a function and not the other or in different order or mismatch them.
Quoted 13 lines
Signed-off-by Lukáš Hrázký <[email protected]>--- server/red-qxl.c | 89 ++++++++++++++++++++++++++++++++++++++++ server/spice-qxl.h | 5 +++ server/spice-server.syms | 6 +++ 3 files changed, 100 insertions(+)server/red-qxl.c +0
-0
server/red-qxl.c line 44
Quoted 4 lines
server/red-qxl.c +1
-0@@ -41,6 +41,9 @@#include "red-qxl.h" +#define MAX_PATH_LEN 256
Different OSes uses MAX_PATH/MAXPATH to specify filename limit so this sounds confusing, maybe MAX_DEVICE_PATH_LEN would be better.
server/red-qxl.c struct QXLState { · line 61
Quoted 12 lines
server/red-qxl.c +5
-0+#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 ^^^
size_t look a bit too much for a number of item in a small array.
Quoted 13 lines
server/red-qxl.c +6
-0pthread_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); } +/** +* 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
Quoted 8 lines
by
+ * this QXL interface instance.
+ *
+ * The supported format is:
+ * "pci/<DOMAIN>/<SLOT>.<FUNCTION>/.../<SLOT>.<FUNCTION>"
+ *
+ * The "pci" identifies the rest of the string as a PCI adress. It is the only
typo: adress
Quoted 6 lines
+ * supported address at the moment, other identifiers can be introduced later.
+ * <DOMAIN> is the PCI domain, followed by <SLOT>.<FUNCTION> of any PCI bridges
+ * in the chain leading to the device. The last <SLOT>.<FUNCTION> is the
+ * graphics device.
Maybe better to specify also the encoding, like decimal/hexadecimal and number of digits.
Quoted 1 line
+ */
I would prefer documentation in the header so people don't have to open the source to get it, also considering the the header is public.
Quoted 31 lines
server/red-qxl.c +2
-0+SPICE_GNUC_VISIBLE +void spice_qxl_set_device_address(QXLInstance *instance, const char
*device_address)server/red-qxl.c +6
-0+{ +g_return_if_fail (device_address !=NULL ); + +size_t dp_len =strnlen (device_address,MAX_PATH_LEN ); +if (dp_len >=MAX_PATH_LEN ) { + spice_error("PCI device path too long: %lu > %u", dp_len,
MAX_PATH_LEN);server/red-qxl.c +6
-0+return ; + } + +strncpy (instance->st->device_address, device_address,MAX_PATH_LEN ); + + g_debug("QXL Instance %d setting device address \"%s\"", instance->id,
device_address);server/red-qxl.c +7
-0+} + +/** +* 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 graphics 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 starting
+ * at 0. The function requires the calls to be made in the sequence to prevent
Quoted 8 lines
+ * holes.
+ *
+ * The requirement for the monitor ID to be a sequence starting from 0 comes
+ * from the mechanism of generating a singledisplay_idfromchannel_idand
+ *monitor_idon the client:
+ *
+ *display_id=channel_id+monitor_id
+ *
No, the monitor_id sequence is defined as a sequence from 0, has nothing to do with display_id. Also this comment seems to indicate that this new interface is bad designed having the same limit, which is not.
Quoted 5 lines
+ * This is unambiguous either if there is only a single channel with multiple
+ * monitors ("legacy" QXL on linux case) or multiple channels with only a
+ * single monitor. Also bothchannel_idandmonitor_idneed to be a sequence
+ * starting from 0, otherwise there is still a possibility of collisions.
They are both defined (channel_id and monitor_id) as sequences starting from 0. I don't see why need to be specified here.
server/red-qxl.c void red_qxl_gl_draw_async_complete(QXLInstance *qxl) · line 913
Quoted 5 lines
+ */
server/red-qxl.c +4
-0+SPICE_GNUC_VISIBLE +void spice_qxl_monitor_set_device_display_id(QXLInstance *instance, +uint32_t monitor_id, +uint32_t device_display_id)
I still don't understand why, as suggested by Gerd, we need another function instead of 2 additional parameters to the above API specifying start and number, this API looks much more prone to errors.
Also there's no much documentation for this "device display ID" in the code, potentially can be generated with something like:
uint32_t next_device_display_id(void)
{
static unsigned id = 0;
return (id++ + 0xf00) * 0xbeef;
}
which probably won't work for you.
Quoted 54 lines
server/red-qxl.c +3
-0+{ +if (instance->st->monitors_count >=MAX_MONITORS_COUNT ) { + spice_error("Cannot register more than %u monitors per QXLinterface",
MAX_MONITORS_COUNT);server/red-qxl.c +5
-0+return ; + } + +if (monitor_id > instance->st->monitors_count) { + spice_error("Monitor ID %u is not inside a consecutive sequence ofmonitor IDs "
+ "starting from zero. Needs to be lower than or equal to
%lu.",server/red-qxl.c +7
-0+ monitor_id, instance->st->monitors_count); +return ; + } + + instance->st->device_display_ids[monitor_id] = device_display_id; + + g_debug("QXL Instance %d setting device display ID %u for monitor ID%u",
server/red-qxl.c +3
-0+ instance->id, device_display_id, monitor_id); + +// if we're adding a new ID (and not resetting an existing one), increment the array length
server/red-qxl.c +5
-0+if (monitor_id == instance->st->monitors_count) { + instance->st->monitors_count++; + } +} +void red_qxl_init (RedsState *reds,QXLInstance *qxl) {QXLState *qxl_state;server/spice-qxl.h +5
-0@@ -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 *device_path); +void spice_qxl_monitor_set_device_display_id (QXLInstance *instance, +uint32_t monitor_id, +uint32_t device_display_id); typedef struct QXLDevInitInfo {uint32_t num_memslots_groups;server/spice-server.syms +0
-0
server/spice-server.syms SPICE_SERVER_0.13.2 { · line 181
Quoted 9 lines
server/spice-server.syms +6
-0@@ -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;
Frediano
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
Quoted 9 lines
Quoted 6 lines
+ * supported address at the moment, other identifiers can be introduced later.
+ * <DOMAIN> is the PCI domain, followed by <SLOT>.<FUNCTION> of any PCI bridges
+ * in the chain leading to the device. The last <SLOT>.<FUNCTION> is the
+ * graphics device.Maybe better to specify also the encoding, like decimal/hexadecimal and number of digits.
lspci style (i.e. slot is two digits hex, function is one digit).
Quoted 6 lines
Quoted 6 lines
+/**
+ *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 graphics device
Hmm, why do we need the monitor_id here?
The reason to have this function is to allow the guest agent figure which channel is which head in case we have multiple display channels registered for one device.
For linux-qxl multihead we don't need this as all heads use the same display channel, right?
Quoted 8 lines
server/red-qxl.c void red_qxl_gl_draw_async_complete(QXLInstance *qxl) · line 913
Quoted 4 lines
server/red-qxl.c +4
-0+SPICE_GNUC_VISIBLE +void spice_qxl_monitor_set_device_display_id(QXLInstance *instance, +uint32_t monitor_id, +uint32_t device_display_id)I still don't understand why, as suggested by Gerd, we need another function instead of 2 additional parameters to the above API specifying start and number, this API looks much more prone to errors.
We can also just add a device_display_id parameter to the other function, that should work too.
Quoted 2 lines
Also there's no much documentation for this "device display ID" in the code, potentially can be generated with something like:
It's the head index, starting at zero.
cheers,
Gerd
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
In reply to Frediano ZiglioHello,
Quoted 8 lines · Frediano Ziglio
Quoted 8 lines
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(...)
Quoted 6 lines
Quoted 2 lines
* device display ID - The index of the monitor on the graphics device:
spice_qxl_monitor_set_device_display_id(...)This seems to indicate that this device is bound in some way to the previous information but having 2 APIs make more fragile, potentially one could call a function and not the other or in different order or mismatch them.
Not sure what you mean by "previous information".
Yes, you need to call both functions... The order doesn't matter and you can always send wrong data in a single function as well. I agree in this regard a single function would be better but don't find it a big issue. Note that the functions are called in different places in QEMU too.
Quoted 16 lines
Quoted 16 lines
Signed-off-by Lukáš Hrázký <[email protected]>--- server/red-qxl.c | 89 ++++++++++++++++++++++++++++++++++++++++ server/spice-qxl.h | 5 +++ server/spice-server.syms | 6 +++ 3 files changed, 100 insertions(+)server/red-qxl.c +0
-0@@ -41,6 +41,9 @@#include "red-qxl.h"
Quoted 4 lines
server/red-qxl.c line 44
Quoted 1 line
server/red-qxl.c +1
-0+#define MAX_PATH_LEN 256Different OSes uses MAX_PATH/MAXPATH to specify filename limit so this sounds confusing, maybe
MAX_DEVICE_PATH_LENwould be better.
Will do.
Quoted 6 lines
Quoted 6 lines
server/red-qxl.c +2
-0+#define MAX_MONITORS_COUNT 16 +struct QXLState {QXLWorker qxl_worker;QXLInstance *qxl;@@ -53,6 +56,9 @@ struct QXLState {
Quoted 8 lines
server/red-qxl.c struct QXLState { · line 61
Quoted 6 lines
server/red-qxl.c +3
-0unsigned 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 ^^^
size_tlook a bit too much for a number of item in a small array.
It's the go-to type for indexes for me, I'm not used to doing these little optimizations. If you think it matters, I can change it to like uint8_t...
Quoted 31 lines
Quoted 13 lines
server/red-qxl.c +6
-0pthread_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); } +/** +* 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 Quoted 8 lines
by
+ * this QXL interface instance.
+ *
+ * The supported format is:
+ * "pci/<DOMAIN>/<SLOT>.<FUNCTION>/.../<SLOT>.<FUNCTION>"
+ *
+ * The "pci" identifies the rest of the string as a PCI adress. It is the onlytypo: adress
Quoted 6 lines
+ * supported address at the moment, other identifiers can be introduced later.
+ * <DOMAIN> is the PCI domain, followed by <SLOT>.<FUNCTION> of any PCI bridges
+ * in the chain leading to the device. The last <SLOT>.<FUNCTION> is the
+ * graphics device.
Quoted 2 lines
Maybe better to specify also the encoding, like decimal/hexadecimal and number of digits.
Right, I'll improve on that.
Quoted 4 lines
Quoted 1 line
+ */
I would prefer documentation in the header so people don't have to open the source to get it, also considering the the header is public.
Sure, makes sense. I just did it the same way as it's done in spice- gtk, which has the docstrings in .c files for some reason...
Quoted 35 lines
Quoted 35 lines
server/red-qxl.c +2
-0+SPICE_GNUC_VISIBLE +void spice_qxl_set_device_address(QXLInstance *instance, const char
*device_address)server/red-qxl.c +6
-0+{ +g_return_if_fail (device_address !=NULL ); + +size_t dp_len =strnlen (device_address,MAX_PATH_LEN ); +if (dp_len >=MAX_PATH_LEN ) { + spice_error("PCI device path too long: %lu > %u", dp_len,
MAX_PATH_LEN);server/red-qxl.c +6
-0+return ; + } + +strncpy (instance->st->device_address, device_address,MAX_PATH_LEN ); + + g_debug("QXL Instance %d setting device address \"%s\"", instance->id,
device_address);server/red-qxl.c +7
-0+} + +/** +* 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 graphics 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 starting
+ * at 0. The function requires the calls to be made in the sequence to prevent
+ * holes.
+ *
+ * The requirement for the monitor ID to be a sequence starting from 0 comes
+ * from the mechanism of generating a singledisplay_idfromchannel_idand
Quoted 8 lines
Quoted 4 lines
+ *
monitor_idon the client:
+ *
+ *display_id=channel_id+monitor_id
+ *No, the
monitor_idsequence is defined as a sequence from 0, has nothing to do withdisplay_id. Also this comment seems to indicate that this new interface is bad designed having the same limit, which is not.
I don't think monitor_id is defined anywhere to be a sequence starting from 0. If it is, please point me to it. From what I understand, monitor_id is an arbitrary identifier without further specification which happens to always be a sequence starting from 0. The thing is that the way display_id is calculated depends on it, so it is practically required to start from 0. That's what the docstring is trying to say.
If I understood correctly, Gerd actually at some point suggested to use device_display_id as monitor_id, which would not always be a sequence starting from 0 and that would break the display_id calculation.
Not sure if I can improve the documentation in any way, suggestions welcome.
Quoted 8 lines
Quoted 5 lines
+ * This is unambiguous either if there is only a single channel with multiple
+ * monitors ("legacy" QXL on linux case) or multiple channels with only a
+ * single monitor. Also bothchannel_idandmonitor_idneed to be a sequence
+ * starting from 0, otherwise there is still a possibility of collisions.They are both defined (
channel_idandmonitor_id) as sequences starting from 0. I don't see why need to be specified here.
As I said, I don't know of such a definition...
Quoted 9 lines
server/red-qxl.c void red_qxl_gl_draw_async_complete(QXLInstance *qxl) · line 913
Quoted 5 lines
+ */
server/red-qxl.c +4
-0+SPICE_GNUC_VISIBLE +void spice_qxl_monitor_set_device_display_id(QXLInstance *instance, +uint32_t monitor_id, +uint32_t device_display_id)I still don't understand why, as suggested by Gerd, we need another function instead of 2 additional parameters to the above API specifying start and number, this API looks much more prone to errors.
Possibly. I (and I think Jonathon too?) didn't like the start and number API, this was proposed as an alternative.
Quoted 2 lines
Also there's no much documentation for this "device display ID" in the code, potentially can be generated with something like:
I'll add it to the documentation. I think we do agree it's the index of the actual monitor output on the graphics device?
Cheers,
Lukas
Quoted 73 lines
uint32_tnext_device_display_id(void){ static unsigned id = 0; return (id++ + 0xf00) * 0xbeef; }which probably won't work for you.
Quoted 54 lines
server/red-qxl.c +3
-0+{ +if (instance->st->monitors_count >=MAX_MONITORS_COUNT ) { + spice_error("Cannot register more than %u monitors per QXLinterface",
MAX_MONITORS_COUNT);server/red-qxl.c +5
-0+return ; + } + +if (monitor_id > instance->st->monitors_count) { + spice_error("Monitor ID %u is not inside a consecutive sequence ofmonitor IDs "
+ "starting from zero. Needs to be lower than or equal to
%lu.",server/red-qxl.c +7
-0+ monitor_id, instance->st->monitors_count); +return ; + } + + instance->st->device_display_ids[monitor_id] = device_display_id; + + g_debug("QXL Instance %d setting device display ID %u for monitor ID%u",
server/red-qxl.c +3
-0+ instance->id, device_display_id, monitor_id); + +// if we're adding a new ID (and not resetting an existing one), increment the array length
server/red-qxl.c +5
-0+if (monitor_id == instance->st->monitors_count) { + instance->st->monitors_count++; + } +} +void red_qxl_init (RedsState *reds,QXLInstance *qxl) {QXLState *qxl_state;server/spice-qxl.h +5
-0@@ -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 *device_path); +void spice_qxl_monitor_set_device_display_id (QXLInstance *instance, +uint32_t monitor_id, +uint32_t device_display_id); typedef struct QXLDevInitInfo {uint32_t num_memslots_groups;server/spice-server.syms +0
-0server/spice-server.syms SPICE_SERVER_0.13.2 { · line 181
Quoted 9 lines
server/spice-server.syms +6
-0@@ -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;Frediano
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
Hello,
Quoted 45 lines · Lukáš Hrázký
Hello,
Quoted 8 lines · Frediano Ziglio
Quoted 8 lines
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(...)Quoted 6 lines
Quoted 2 lines
* device display ID - The index of the monitor on the graphics device:
spice_qxl_monitor_set_device_display_id(...)This seems to indicate that this device is bound in some way to the previous information but having 2 APIs make more fragile, potentially one could call a function and not the other or in different order or mismatch them.
Not sure what you mean by "previous information".
Yes, you need to call both functions... The order doesn't matter and you can always send wrong data in a single function as well. I agree in this regard a single function would be better but don't find it a big issue. Note that the functions are called in different places in QEMU too.
...
Quoted 7 lines
Quoted 7 lines
(quoted diff) +2
-0+SPICE_GNUC_VISIBLE +void spice_qxl_set_device_address(QXLInstance *instance, const char
*device_address)
+{...
Quoted 9 lines
server/red-qxl.c void red_qxl_gl_draw_async_complete(QXLInstance *qxl) · line 913
Quoted 5 lines
+ */
server/red-qxl.c +4
-0+SPICE_GNUC_VISIBLE +void spice_qxl_monitor_set_device_display_id(QXLInstance *instance, +uint32_t monitor_id, +uint32_t device_display_id)I still don't understand why, as suggested by Gerd, we need another function instead of 2 additional parameters to the above API specifying start and number, this API looks much more prone to errors.
Quoted 2 lines
Possibly. I (and I think Jonathon too?) didn't like the start and number API, this was proposed as an alternative.
this topic of the API functions should be resolved. I think the options are:
1. Keep the two functions proposed in this patch:
void spice_qxl_set_device_address(QXLInstance *instance,
const char *device_address);
void spice_qxl_monitor_set_device_display_id(QXLInstance *instance,
uint32_t monitor_id,
uint32_t device_display_id);2. Have a single function as follows:
void spice_qxl_set_device_info(QXLInstance *instance,
const char *device_address, uint32_t device_display_id_start, uint32_t device_display_id_count);
The semantics of the single function in 2. (with a sort-of placeholder name) would be setting the device_address for the QXLInstance as well as setting a mapping of monitor IDs to device display IDs of [0, count-1] -> [start, start+count-1].
The usage of 1. in QEMU is what's in patch 2/2. The usage of 2. would mean calling the new single function in the two places where spice_qxl_monitor_set_device_display_id() is now called in patch 2/2. The code that composes the device_address would need to be put in a function somewhere in QEMU (not sure where yet) that can then be called from the two places where it's needed.
I'm still somewhat more inclined to keep the two functions, as their API seems a bit cleaner to me and you can call/not call a single function in a wrong way too. Frediano prefers a single function. Jonathon, Gerd?
Thanks,
Lukas
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
Quoted 6 lines
2. Have a single function as follows:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id_start,uint32_tdevice_display_id_count);
How about:
void spice_qxl_set_device_info(QXLInstance *instance,
const char *device_address, uint32_t device_display_id);
I don't think we need start+count:
* For single-head devices device_display_id will be zero.
* For one-channel-per-head multihead devices (i.e. virtio-gpu) device_display_id will enumerate the heads (so everybody can figure which channel is which head).
* For one-channel-per-device multihead devices (i.e. qxl/linux) device_display_id will be zero too. Number of heads is set via spice_qxl_set_max_monitors().
cheers,
Gerd
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
Quoted 24 lines
Quoted 7 lines
2. Have a single function as follows:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id_start,uint32_tdevice_display_id_count);How about:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id);I don't think we need start+count:
* For single-head devices
device_display_idwill be zero.
* For one-channel-per-head multihead devices (i.e. virtio-gpu)device_display_idwill enumerate the heads (so everybody can figure which channel is which head).
* For one-channel-per-device multihead devices (i.e. qxl/linux)device_display_idwill be zero too. Number of heads is set viaspice_qxl_set_max_monitors().
Quoted 3 lines
cheers,
Gerd
What about "Console VNC" case? Passing a dummy (like -1) value for device_display_id ? Kind of "I don't know which output is."
Frediano
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
Quoted 24 lines · Frediano Ziglio
Quoted 24 lines
Quoted 7 lines
2. Have a single function as follows:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id_start,uint32_tdevice_display_id_count);How about:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id);I don't think we need start+count:
* For single-head devices
device_display_idwill be zero.
* For one-channel-per-head multihead devices (i.e. virtio-gpu)device_display_idwill enumerate the heads (so everybody can figure which channel is which head).
* For one-channel-per-device multihead devices (i.e. qxl/linux)device_display_idwill be zero too. Number of heads is set viaspice_qxl_set_max_monitors().
Quoted 6 lines
Quoted 3 lines
cheers,
GerdWhat about "Console VNC" case? Passing a dummy (like -1) value for
device_display_id? Kind of "I don't know which output is."
I'm not sure -1 will be practically helpful for anything? What will happen if we use 0 for it? We still aren't sure how we want to handle the VNC console anyway, should we wait untill we know?
Maybe I should use int32_t instead of uint32_t to have the option to use -1 if we need it later?
Cheers,
Lukas
Quoted 1 line
Frediano
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
In reply to Frediano ZiglioQuoted 24 lines · Frediano Ziglio
Quoted 24 lines
Quoted 7 lines
2. Have a single function as follows:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id_start,uint32_tdevice_display_id_count);How about:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id);I don't think we need start+count:
* For single-head devices
device_display_idwill be zero.
* For one-channel-per-head multihead devices (i.e. virtio-gpu)device_display_idwill enumerate the heads (so everybody can figure which channel is which head).
* For one-channel-per-device multihead devices (i.e. qxl/linux)device_display_idwill be zero too. Number of heads is set viaspice_qxl_set_max_monitors().
Quoted 6 lines
Quoted 3 lines
cheers,
GerdWhat about "Console VNC" case? Passing a dummy (like -1) value for
device_display_id? Kind of "I don't know which output is."
I'd use zero, assuming in case only one of multiple heads shows up as vnc console it'll be the primary head.
But using -1 kind-of makes sense too.
cheers,
Gerd
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
In reply to Gerd HoffmannQuoted 15 lines · Gerd Hoffmann
Quoted 6 lines
2. Have a single function as follows:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id_start,uint32_tdevice_display_id_count);How about:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id);I don't think we need start+count:
Quoted 7 lines
* For single-head devices
device_display_idwill be zero.
* For one-channel-per-head multihead devices (i.e. virtio-gpu)device_display_idwill enumerate the heads (so everybody can figure which channel is which head).
* For one-channel-per-device multihead devices (i.e. qxl/linux)device_display_idwill be zero too. Number of heads is set viaspice_qxl_set_max_monitors().
That requires nontrivial and unexpected logic for the one-channel-per- device multihead devices case. The API should be doing what it says and
the dumber the better, this seems too smart to me...
That said, I don't find it significantly worse than the other options (none of which seems great), so I'd just like we reached some consesus and be done with it...
Cheers,
Lukas
Quoted 3 lines
cheers,
Gerd
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
Quoted 28 lines · Gerd Hoffmann
Quoted 15 lines
Quoted 6 lines
2. Have a single function as follows:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id_start,uint32_tdevice_display_id_count);How about:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id);I don't think we need start+count:
Quoted 7 lines
* For single-head devices
device_display_idwill be zero.
* For one-channel-per-head multihead devices (i.e. virtio-gpu)device_display_idwill enumerate the heads (so everybody can figure which channel is which head).
* For one-channel-per-device multihead devices (i.e. qxl/linux)device_display_idwill be zero too. Number of heads is set viaspice_qxl_set_max_monitors().That requires nontrivial and unexpected logic for the one-channel-per- device multihead devices case. The API should be doing what it says and
the dumber the better, this seems too smart to me...
Quoted 10 lines
That said, I don't find it significantly worse than the other options (none of which seems great), so I'd just like we reached some consesus and be done with it...
Cheers,
LukasQuoted 3 lines
cheers,
Gerd
Personally I prefer the single function API, either with or without count.
About the not trivial for compatibility you'll have to support Qemu versions that either:
- does not call new APIs or spice_qxl_set_max_monitors. A QXL card will have the maximum possible number of monitors in the guest;
- does not call new APIs but call spice_qxl_set_max_monitors. A QXL card will have a maximum of monitor specified by spice_qxl_set_max_monitors in the guest;
- call new APIs (the choice in this case to call spice_qxl_set_max_monitors or not is yours).
Frediano
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
In reply to Lukáš HrázkýQuoted 24 lines · Lukáš Hrázký
Quoted 15 lines · Gerd Hoffmann
Quoted 6 lines
2. Have a single function as follows:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id_start,uint32_tdevice_display_id_count);How about:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id);I don't think we need start+count:
Quoted 7 lines
* For single-head devices
device_display_idwill be zero.
* For one-channel-per-head multihead devices (i.e. virtio-gpu)device_display_idwill enumerate the heads (so everybody can figure which channel is which head).
* For one-channel-per-device multihead devices (i.e. qxl/linux)device_display_idwill be zero too. Number of heads is set viaspice_qxl_set_max_monitors().
Quoted 3 lines
That requires nontrivial and unexpected logic for the one-channel-per- device multihead devices case. The API should be doing what it says and
the dumber the better, this seems too smart to me...
Well, the device_display_id_count argument is redundant with spice_qxl_set_max_monitors(). That isn't a great API either.
I can see that it simplifies the logic in spice-server if we have a single function call instead of two. So we could deprecate spice_qxl_set_max_monitors() in favour of your spice_qxl_set_device_info() variant.
spice_qxl_set_max_monitors() would then basically do this:
spice_qxl_set_max_monitors(qxl, max)
{
spice_qxl_set_device_info(qxl, NULL, 0, max);
}cheers,
Gerd
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
Quoted 37 lines · Gerd Hoffmann
Quoted 24 lines · Lukáš Hrázký
Quoted 15 lines · Gerd Hoffmann
Quoted 6 lines
2. Have a single function as follows:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id_start,uint32_tdevice_display_id_count);How about:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id);I don't think we need start+count:
Quoted 7 lines
* For single-head devices
device_display_idwill be zero.
* For one-channel-per-head multihead devices (i.e. virtio-gpu)device_display_idwill enumerate the heads (so everybody can figure which channel is which head).
* For one-channel-per-device multihead devices (i.e. qxl/linux)device_display_idwill be zero too. Number of heads is set viaspice_qxl_set_max_monitors().Quoted 3 lines
That requires nontrivial and unexpected logic for the one-channel-per- device multihead devices case. The API should be doing what it says and
the dumber the better, this seems too smart to me...Well, the
device_display_id_countargument is redundant withspice_qxl_set_max_monitors(). That isn't a great API either.I can see that it simplifies the logic in spice-server if we have a single function call instead of two. So we could deprecate
spice_qxl_set_max_monitors()in favour of yourspice_qxl_set_device_info()variant.
Quoted 6 lines
spice_qxl_set_max_monitors()would then basically do this:spice_qxl_set_max_monitors(qxl, max) { spice_qxl_set_device_info(qxl, NULL, 0, max); }
I can't actually do this, it does the wrong thing for the one-channel- per-head (virtio-gpu) case. For that case it would send all device_display_ids to 0 on all interfaces, but they need to be different numbers.
For backwards compatibility when spice_qxl_set_device_info() is not called I think we need to fallback to the old behaviour, as we are missing the necessary information.
I'll send v3 with a single function using start + count and deprecate the set_max_monitors one.
Cheers,
Lukas
Quoted 3 lines
cheers,
Gerd
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
Quoted 46 lines · Gerd Hoffmann
Quoted 37 lines · Lukáš Hrázký
Quoted 24 lines · Gerd Hoffmann
Quoted 15 lines
Quoted 6 lines
2. Have a single function as follows:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id_start,uint32_tdevice_display_id_count);How about:
void spice_qxl_set_device_info(QXLInstance *instance,
const char*device_address,uint32_tdevice_display_id);I don't think we need start+count:
Quoted 7 lines
* For single-head devices
device_display_idwill be zero.
* For one-channel-per-head multihead devices (i.e. virtio-gpu)device_display_idwill enumerate the heads (so everybody can figure which channel is which head).
* For one-channel-per-device multihead devices (i.e. qxl/linux)device_display_idwill be zero too. Number of heads is set viaspice_qxl_set_max_monitors().Quoted 3 lines
That requires nontrivial and unexpected logic for the one-channel-per- device multihead devices case. The API should be doing what it says and
the dumber the better, this seems too smart to me...Well, the
device_display_id_countargument is redundant withspice_qxl_set_max_monitors(). That isn't a great API either.I can see that it simplifies the logic in spice-server if we have a single function call instead of two. So we could deprecate
spice_qxl_set_max_monitors()in favour of yourspice_qxl_set_device_info()variant.Quoted 6 lines
spice_qxl_set_max_monitors()would then basically do this:spice_qxl_set_max_monitors(qxl, max) { spice_qxl_set_device_info(qxl, NULL, 0, max); }
Quoted 5 lines
I can't actually do this, it does the wrong thing for the one-channel- per-head (virtio-gpu) case. For that case it would send all
device_display_idsto 0 on all interfaces, but they need to be different numbers.
This function is only called for QXL cards devices so no virtio-gpu, no cirrus, no svga or anything else.
Quoted 4 lines
For backwards compatibility when
spice_qxl_set_device_info()is not called I think we need to fallback to the old behaviour, as we are missing the necessary information.
Quoted 10 lines
I'll send v3 with a single function using start + count and deprecate the
set_max_monitorsone.Cheers,
LukasQuoted 3 lines
cheers,
Gerd
Frediano
Re: [Qemu-devel] [RFC PATCH spice v2 1/2] QXL interface: add functions to identify monitors in the guest
In reply to Lukáš HrázkýHi,
Quoted 12 lines
Quoted 11 lines
I can see that it simplifies the logic in spice-server if we have a single function call instead of two. So we could deprecate
spice_qxl_set_max_monitors()in favour of yourspice_qxl_set_device_info()variant.
spice_qxl_set_max_monitors()would then basically do this:spice_qxl_set_max_monitors(qxl, max) { spice_qxl_set_device_info(qxl, NULL, 0, max); }
Quoted 4 lines
I can't actually do this, it does the wrong thing for the one-channel- per-head (virtio-gpu) case. For that case it would send all
device_display_idsto 0 on all interfaces, but they need to be different numbers.
Well, qemu calls spice_qxl_set_max_monitors() only in case there are multiple monitors in one channel, i.e. qxl.
cheers,
Gerd
RFC PATCH v2 2/2 spice: set device address and device display ID in QXL interface
In reply to Lukáš Hrázký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(...)
--- hw/display/qxl.c | 8 ++++++++ ui/spice-core.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- ui/spice-display.c | 5 +++++ 3 files changed, 57 insertions(+), 1 deletion(-)
hw/display/qxl.c +8 -0
@@ -2184,6 +2184,14 @@ 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 */ +// register all possible device display IDs to SPICE server +for (int i =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); qxl->update_irq =qemu_bh_new (qxl_update_irq_bh, qxl);
ui/spice-core.c +44 -1
63 lines not on this page · raw message
ui/spice-display.c +5 -0
@@ -1129,6 +1129,11 @@ 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 */ +spice_qxl_monitor_set_device_display_id (&ssd->qxl,0 ,qemu_console_get_head (con)); +#endif +qemu_spice_create_host_memslot (ssd);register_displaychangelistener (&ssd->dcl);
Signature · 1 line
2.19.1
Re: [Qemu-devel] [RFC PATCH qemu v2 2/2] spice: set device address and device display ID in QXL interface
Quoted 25 lines
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áš Hrázký <[email protected]>--- hw/display/qxl.c | 8 ++++++++ ui/spice-core.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- ui/spice-display.c | 5 +++++ 3 files changed, 57 insertions(+), 1 deletion(-)hw/display/qxl.c +0
-0@@ -2184,6 +2184,14 @@ static void qxl_realize_common(PCIQXLDevice *qxl, Error **errp) SPICE_INTERFACE_QXL_MAJOR, SPICE_INTERFACE_QXL_MINOR);
hw/display/qxl.c static void qxl_realize_common(PCIQXLDevice *qxl, · line 2195
Quoted 10 lines
hw/display/qxl.c +8
-0return ; } + +#if SPICE_SERVER_VERSION >=0x000e02 /* release 0.14.2 */ +// register all possible device display IDs to SPICE server +for (int i =0 ; i < qxl->max_outputs; ++i) { +spice_qxl_monitor_set_device_display_id (&qxl->ssd.qxl, i, i); + } +#endif +
I think would be better if this were the default in spice-server.
Quoted 22 lines
hw/display/qxl.c +0
-0qemu_add_vm_change_state_handler (qxl_vm_change_state_handler, qxl);qxl->update_irq = qemu_bh_new(qxl_update_irq_bh, qxl);ui/spice-core.c +4
-0@@ -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" /* core bits */ @@ -871,6 +873,26 @@ bool qemu_spice_have_display_interface(QemuConsole *con)return false; } +/* +* Recursively (in reverse order) appends addresses of PCI devices as it
Quoted 7 lines
moves
+ * up in the PCI hierarchy.
+ *
+ * @returns true on success, false when the buffer wasn't large enough
+ */
+static boolappend_pci_address_recursive(char *buf, size_t buf_size, const PCIDevice *pci)
I won't use the "_recursive" in the name, looks like more an implementation detail.
ui/spice-core.c bool qemu_spice_have_display_interface(QemuConsole *con) · line 893
Quoted 11 lines
ui/spice-core.c +11
-0+{ +PCIBus *bus =pci_get_bus (pci); +if (!pci_bus_is_root (bus)) { +append_pci_address_recursive (buf, buf_size, bus->parent_dev); + } + +size_t len =strlen (buf); +size_t written =snprintf (buf + len, buf_size - len,"/%02x.%x" , +PCI_SLOT (pci->devfn),PCI_FUNC (pci->devfn)); + +return written >0 && written < buf_size - len;
written is always > 0, unless there's a bug in snprintf. Note that Qemu uses MingW snprintf on Windows so even on Windows this returns always > 0 (note that snprintf returns an int which is signed while size_t is unsigned and some implementation could return < 0, but not in Qemu).
Quoted 45 lines
ui/spice-core.c +10
-1+} +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 *qxlin, QemuConsole *con) } qxlin->id =qemu_console_get_index (con); spice_consoles =g_slist_append (spice_consoles, con); -return qemu_spice_add_interface (&qxlin->base); +int res =qemu_spice_add_interface (&qxlin->base); + +#if SPICE_SERVER_VERSION >=0x000e02 /* release 0.14.2 */ +DeviceState *dev =DEVICE (object_property_get_link (OBJECT (con),"device" , &error_abort)); +PCIDevice *pci = (PCIDevice *)object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE ); + +if (pci ==NULL ) { + warn_report("Setting PCI path of a display device to SPICE: Not aPCI device.");
ui/spice-core.c +5
-0+return res; + } + +char device_path[128 ] ="pci/0000" ;// hardcoded PCI domain 0000 + if (!append_pci_address_recursive(device_path, sizeof(device_path),pci)) {
ui/spice-core.c +9
-0+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; }static int qemu_spice_set_ticket (bool fail_if_conn,bool disconnect_if_conn)ui/spice-display.c +0
-0
ui/spice-display.c static void qemu_spice_display_init_one(QemuConsole · line 1134
Quoted 6 lines
ui/spice-display.c +2
-0@@ -1129,6 +1129,11 @@ 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 */
Surely OT: won't be better to have something like
#if SPICE_SERVER_VERSION >= SPICE_SERVER_VERSION_NUMBER(0,14,2)
Quoted 7 lines
ui/spice-display.c +3
-0+spice_qxl_monitor_set_device_display_id (&ssd->qxl,0 ,qemu_console_get_head (con)); +#endif +qemu_spice_create_host_memslot (ssd);register_displaychangelistener(&ssd->dcl);
Frediano
Re: [Qemu-devel] [RFC PATCH qemu v2 2/2] spice: set device address and device display ID in QXL interface
Quoted 29 lines · Frediano Ziglio
Quoted 29 lines
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áš Hrázký <[email protected]>--- hw/display/qxl.c | 8 ++++++++ ui/spice-core.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- ui/spice-display.c | 5 +++++ 3 files changed, 57 insertions(+), 1 deletion(-)hw/display/qxl.c +2
-0@@ -2184,6 +2184,14 @@ 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 */
Quoted 8 lines
hw/display/qxl.c static void qxl_realize_common(PCIQXLDevice *qxl, Error **errp) · line 2194
Quoted 6 lines
hw/display/qxl.c +6
-0+// register all possible device display IDs to SPICE server +for (int i =0 ; i < qxl->max_outputs; ++i) { +spice_qxl_monitor_set_device_display_id (&qxl->ssd.qxl, i, i); + } +#endif +I think would be better if this were the default in spice-server.
I don't know what you mean by this...
Quoted 20 lines
Quoted 20 lines
hw/display/qxl.c +0
-0qemu_add_vm_change_state_handler (qxl_vm_change_state_handler, qxl);qxl->update_irq = qemu_bh_new(qxl_update_irq_bh, qxl);ui/spice-core.c +2
-0@@ -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" /* core bits */ @@ -871,6 +873,26 @@ bool qemu_spice_have_display_interface(QemuConsole *con)return false; }
Quoted 12 lines
Quoted 9 lines
ui/spice-core.c +2
-0+/* +* Recursively (in reverse order) appends addresses of PCI devices as it moves
+ * up in the PCI hierarchy.
+ *
+ * @returns true on success, false when the buffer wasn't large enough
+ */
+static boolappend_pci_address_recursive(char *buf, size_t buf_size, const PCIDevice *pci)I won't use the "
_recursive" in the name, looks like more an implementation detail.
Allright.
Quoted 8 lines
Quoted 8 lines
ui/spice-core.c +8
-0+{ +PCIBus *bus =pci_get_bus (pci); +if (!pci_bus_is_root (bus)) { +append_pci_address_recursive (buf, buf_size, bus->parent_dev); + } + +size_t len =strlen (buf); + size_t written = snprintf(buf + len, buf_size - len, "/%02x.%x",
Quoted 8 lines
ui/spice-core.c bool qemu_spice_have_display_interface(QemuConsole *con) · line 893
Quoted 3 lines
ui/spice-core.c +3
-0+ PCI_SLOT(pci->devfn), PCI_FUNC(pci->devfn)); + +return written >0 && written < buf_size - len;written is always > 0, unless there's a bug in snprintf. Note that Qemu uses MingW snprintf on Windows so even on Windows this returns always > 0 (note that snprintf returns an int which is signed while
size_tis unsigned and some implementation could return < 0, but not in Qemu).
Right. The man page says it returns negative values on errors. I've missed the fact I'm storing the result in size_t. Do you think I should drop the "written > 0" condition or change the type of "written" to ssize_t for extra safety? :)
Quoted 47 lines
Quoted 47 lines
ui/spice-core.c +10
-1+} +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 *qxlin, QemuConsole *con) } qxlin->id =qemu_console_get_index (con); spice_consoles =g_slist_append (spice_consoles, con); -return qemu_spice_add_interface (&qxlin->base); +int res =qemu_spice_add_interface (&qxlin->base); + +#if SPICE_SERVER_VERSION >=0x000e02 /* release 0.14.2 */ +DeviceState *dev =DEVICE (object_property_get_link (OBJECT (con),"device" , &error_abort)); +PCIDevice *pci = (PCIDevice *)object_dynamic_cast (OBJECT (dev),TYPE_PCI_DEVICE ); + +if (pci ==NULL ) { + warn_report("Setting PCI path of a display device to SPICE: Not aPCI device.");
ui/spice-core.c +5
-0+return res; + } + +char device_path[128 ] ="pci/0000" ;// hardcoded PCI domain 0000 + if (!append_pci_address_recursive(device_path, sizeof(device_path),pci)) {
ui/spice-core.c +9
-0+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; }static int qemu_spice_set_ticket (bool fail_if_conn,bool disconnect_if_conn)ui/spice-display.c +0
-0@@ -1129,6 +1129,11 @@ static void qemu_spice_display_init_one(QemuConsole *con)
Quoted 8 lines
ui/spice-display.c static void qemu_spice_display_init_one(QemuConsole *con) · line 1133
Quoted 4 lines
ui/spice-display.c +2
-0ssd->qxl.base.sif = &dpy_interface.base;qemu_spice_add_display_interface (&ssd->qxl, con); + +#if SPICE_SERVER_VERSION >=0x000e02 /* release 0.14.2 */ Surely OT: won't be better to have something like
#if
SPICE_SERVER_VERSION>=SPICE_SERVER_VERSION_NUMBER(0,14,2)
It surely would be better :)
Cheers,
Lukas
Quoted 9 lines
Quoted 7 lines
ui/spice-display.c +3
-0+spice_qxl_monitor_set_device_display_id (&ssd->qxl,0 ,qemu_console_get_head (con)); +#endif +qemu_spice_create_host_memslot (ssd);register_displaychangelistener(&ssd->dcl);Frediano