Skip to contentSkip to conversation

Multi-head support infrastructure

PATCH New John Baboval 1 participant 8 messages Dec 19, 2013

lore
Share & tools
lore
#0 lore raw

cover Multi-head support infrastructure

From: "John V. Baboval" <[email protected]>

This is mostly just RFC at this point, since I'm not quite ready to submit the associated multi-head video adapter, drivers and UI that consume this stuff. (I still have to remove some Xen/XenClient specific stuff from it).

These are the infrastructure hooks I needed to add in order to support XenClient Enterprise style multi-head with the current QEMU tip.

The general architecture is as follows:

Other than the initial display (which works as it always has), displays are dynamically added by the UI. This can be the result of command line parameters, hotplug notifications from UDEV, the user clicking an "Add Display" button in a menu, or whatever. The UI adds the display by calling graphic_hw_add_display(), which returns the QemuConsole for the new display.

The video adapter can either allocate all supported displays up-front, or spoof up a new one when its add_display handler is called, either way, it's responsible for providing the new QemuConsole to the UI. If the display hardware doesn't support multi-head (add_display handler == NULL), or if the maximum number of displays are already connected, graphic_hw_add_display returns NULL.

Once the UI has the new QemuConsole, it needs to do basic configuration. A new opaque pointer has been added to the DisplayChangeListener. The UI should set this to something which will allow it to determine which QemuConsole its handlers have been called for. It should then register its DisplayChangeListener with the QemuConsole. It should then provide a sane EDID with graphic_hw_store_edid(), and notify the adapter of the relative positions of the display windows with graphic_hw_set_orientation().

(Per earlier discussions with Gerd, the orientation should eventually live on the QemuConsole itself, in which case graphic_hw_set_orientation would need to be replaced with something like qemu_console_set_orientation(). I'll take care of that before the next version; I wanted to get something out for people to see before leaving for holiday travel though.)

Once configuration is complete, and anytime the UI has completed configuration changes (plugs/unplugs, re-orientation, change in "supported resolution" due to window resizing), the UI should call graphic_hw_notify().

If the display adapter needs to re-initialize, it can call dpy_reset(). The UI should then reconfigure the EDID and orientation.

The last hook added here is not really multi-head related, but is an optimization for showing/hiding the cursor.

Things I'd still like to do:

Submit the emulated multi-head graphics adapter along with the GPL Xorg and binary Windows drivers.

Clean up the "active_console" stuff, which doesn't make a lot of sense anymore.

Modify one of the stock UIs to consume this stuff.

John V. Baboval (7):
console: Add graphic_hw_store_edid()
console: Add graphic_hw_set_orientation()
console: Add graphic_hw_add_display()
console: Add graphic_hw_notify()
ui: Add dpy_reset()
ui: Add dpy_cursor_enable()
ui: Add an opaque pointer to the DisplayChangeListener

 include/ui/console.h |   22 ++++++++++++++++++++
 ui/console.c         |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/7 console: Add graphic_hw_store_edid()

From: "John V. Baboval" <[email protected]>

Add a hook in GraphicHwOps to pass monitor EDID for a QemuConsole from the ui to the hw.

---
 include/ui/console.h |    2 ++
 ui/console.c         |   10 ++++++++++
 2 files changed, 12 insertions(+)
include/ui/console.h +2 -0
index 4156a87..9c928fa 100644
@@ -274,6 +274,7 @@ typedef struct GraphicHwOps {
     void (*gfx_update)(void *opaque);
     void (*text_update)(void *opaque, console_ch_t *text);
     void (*update_interval)(void *opaque, uint64_t interval);
+    void (*store_edid)(void *opaque, uint8_t *edid, size_t edid_size);
 } GraphicHwOps;
 
 QemuConsole *graphic_console_init(DeviceState *dev,
@@ -281,6 +282,7 @@ QemuConsole *graphic_console_init(DeviceState *dev,
                                   void *opaque);
 
 void graphic_hw_update(QemuConsole *con);
+void graphic_hw_store_edid(QemuConsole *con, uint8_t *edid, size_t edid_size);
 void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
 
ui/console.c +10 -0
index 502e160..1f6c840 100644
@@ -245,6 +245,16 @@ static void gui_setup_refresh(DisplayState *ds)
     ds->have_text = have_text;
 }
 
+void graphic_hw_store_edid(QemuConsole *con, uint8_t *edid, size_t edid_size)
+{
+    if (!con) {
+        con = active_console;
+    }
+    if (con && con->hw_ops->store_edid) {
+        con->hw_ops->store_edid(con->hw, edid, edid_size);
+    }
+}
+
 void graphic_hw_update(QemuConsole *con)
 {
     if (!con) {
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/7 console: Add graphic_hw_set_orientation()

In reply to John Baboval

From: "John V. Baboval" <[email protected]>

Add a hook in GraphicHwOps for the ui to inform the hw of display orientation changes

---
 include/ui/console.h |    2 ++
 ui/console.c         |   10 ++++++++++
 2 files changed, 12 insertions(+)
include/ui/console.h +3 -0
index 9c928fa..61455d6 100644
@@ -275,6 +275,7 @@ typedef struct GraphicHwOps {
     void (*text_update)(void *opaque, console_ch_t *text);
     void (*update_interval)(void *opaque, uint64_t interval);
     void (*store_edid)(void *opaque, uint8_t *edid, size_t edid_size);
+    void (*set_orientation)(void *opaque, uint32_t x, uint32_t y, uint32_t r);
 } GraphicHwOps;
 
 QemuConsole *graphic_console_init(DeviceState *dev,
@@ -283,6 +284,8 @@ QemuConsole *graphic_console_init(DeviceState *dev,
 
 void graphic_hw_update(QemuConsole *con);
 void graphic_hw_store_edid(QemuConsole *con, uint8_t *edid, size_t edid_size);
+void graphic_hw_set_orientation(QemuConsole *con, uint32_t x, uint32_t y,
+                                uint32_t r);
 void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
 
ui/console.c +11 -0
index 1f6c840..22de32c 100644
@@ -255,6 +255,17 @@ void graphic_hw_store_edid(QemuConsole *con, uint8_t *edid, size_t edid_size)
     }
 }
 
+void graphic_hw_set_orientation(QemuConsole *con, uint32_t x, uint32_t y,
+                                uint32_t r)
+{
+    if (!con) {
+        con = active_console;
+    }
+    if (con && con->hw_ops->set_orientation) {
+        con->hw_ops->set_orientation(con->hw, x, y, r);
+    }
+}
+
 void graphic_hw_update(QemuConsole *con)
 {
     if (!con) {
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 3/7 console: Add graphic_hw_add_display()

In reply to John Baboval

From: "John V. Baboval" <[email protected]>

Hook for adding another QemuConsole to the active display adapter.

---
 include/ui/console.h |    2 ++
 ui/console.c         |    8 ++++++++
 2 files changed, 10 insertions(+)
include/ui/console.h +2 -0
index 61455d6..95ed12a 100644
@@ -275,6 +275,7 @@ typedef struct GraphicHwOps {
     void (*text_update)(void *opaque, console_ch_t *text);
     void (*update_interval)(void *opaque, uint64_t interval);
     void (*store_edid)(void *opaque, uint8_t *edid, size_t edid_size);
+    QemuConsole *(*add_display)(void *opaque);
     void (*set_orientation)(void *opaque, uint32_t x, uint32_t y, uint32_t r);
 } GraphicHwOps;
 
@@ -287,6 +288,7 @@ void graphic_hw_store_edid(QemuConsole *con, uint8_t *edid, size_t edid_size);
 void graphic_hw_set_orientation(QemuConsole *con, uint32_t x, uint32_t y, uint32_t r);
 void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
+QemuConsole *graphic_hw_add_display(void);
 
 QemuConsole *qemu_console_lookup_by_index(unsigned int index);
 QemuConsole *qemu_console_lookup_by_device(DeviceState *dev);
ui/console.c +9 -0
index 22de32c..fc60570 100644
@@ -285,6 +285,15 @@ void graphic_hw_invalidate(QemuConsole *con)
     }
 }
 
+QemuConsole *graphic_hw_add_display(void)
+{
+    if (active_console && active_console->hw_ops->add_display) {
+        return active_console->hw_ops->add_display(active_console->hw);
+    }
+
+    return NULL;
+}
+
 static void ppm_save(const char *filename, struct DisplaySurface *ds,
                      Error **errp)
 {
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 4/7 console: Add graphic_hw_notify()

In reply to John Baboval

From: "John V. Baboval" <[email protected]>

Hook to notify a display adapter of interesting UI changes such as monitor hotplug, orientation changes, etc...

---
 include/ui/console.h |    9 +++++++++
 ui/console.c         |    7 +++++++
 2 files changed, 16 insertions(+)
include/ui/console.h +9 -0
index 95ed12a..a69ac3d 100644
@@ -110,6 +110,13 @@ struct QemuConsoleClass {
 #define QEMU_BIG_ENDIAN_FLAG    0x01
 #define QEMU_ALLOCATED_FLAG     0x02
 
+typedef enum {
+    GN_PNP,            /* Guest should rescan PCI bus */
+    GN_MONITOR_PNP,    /* Guest should reload monitor port EDIDs */
+    GN_DISPLAY_CONFIG, /* Guest should reload display orientation */
+    GN_MOUSE_ENABLED,  /* Guest should reconfigure cursor */
+} gn_cmd_t;
+
 struct PixelFormat {
     uint8_t bits_per_pixel;
     uint8_t bytes_per_pixel;
@@ -277,6 +284,7 @@ typedef struct GraphicHwOps {
     void (*store_edid)(void *opaque, uint8_t *edid, size_t edid_size);
     QemuConsole *(*add_display)(void *opaque);
     void (*set_orientation)(void *opaque, uint32_t x, uint32_t y, uint32_t r);
+    void (*notify)(void *opaque, gn_cmd_t cmd, int value);
 } GraphicHwOps;
 
 QemuConsole *graphic_console_init(DeviceState *dev,
@@ -289,6 +297,7 @@ void graphic_hw_set_orientation(QemuConsole *con, uint32_t x, uint32_t y, uint32
 void graphic_hw_invalidate(QemuConsole *con);
 void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
 QemuConsole *graphic_hw_add_display(void);
+void graphic_hw_notify(QemuConsole *con, gn_cmd_t cmd, int value);
 
 QemuConsole *qemu_console_lookup_by_index(unsigned int index);
 QemuConsole *qemu_console_lookup_by_device(DeviceState *dev);
ui/console.c +7 -0
index fc60570..0919973 100644
@@ -293,6 +293,13 @@ QemuConsole *graphic_hw_add_display(void)
     return NULL;
 }
 
+void graphic_hw_notify(QemuConsole *con, gn_cmd_t cmd, int value)
+{
+    if (con && con->hw_ops->notify)
+        con->hw_ops->notify(con->hw, cmd, value);
+}
+
+
 static void ppm_save(const char *filename, struct DisplaySurface *ds,
                      Error **errp)
 {
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH 5/7 ui: Add dpy_reset()

In reply to John Baboval

From: "John V. Baboval" <[email protected]>

To be called by graphics adapter to have the ui re-initialize monitor state.

---
 include/ui/console.h |    3 +++
 ui/console.c         |    8 ++++++++
 2 files changed, 11 insertions(+)
include/ui/console.h +3 -0
index a69ac3d..a7171cc 100644
@@ -176,6 +176,8 @@ typedef struct DisplayChangeListenerOps {
     void (*dpy_text_update)(DisplayChangeListener *dcl,
                             int x, int y, int w, int h);
 
+    void (*dpy_reset)(DisplayChangeListener *dcl);
+
     void (*dpy_mouse_set)(DisplayChangeListener *dcl,
                           int x, int y, int on);
     void (*dpy_cursor_define)(DisplayChangeListener *dcl,
@@ -230,6 +232,7 @@ void dpy_text_resize(QemuConsole *con, int w, int h);
 void dpy_mouse_set(QemuConsole *con, int x, int y, int on);
 void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor);
 bool dpy_cursor_define_supported(QemuConsole *con);
+void dpy_reset(QemuConsole *con);
 
 static inline int surface_stride(DisplaySurface *s)
 {
ui/console.c +11 -0
index 0919973..201e602 100644
@@ -1560,6 +1560,17 @@ bool dpy_cursor_define_supported(QemuConsole *con)
     return false;
 }
 
+void dpy_reset(QemuConsole *con)
+{
+    DisplayState *s = con->ds;
+    struct DisplayChangeListener *dcl;
+    QLIST_FOREACH(dcl, &s->listeners, next) {
+        if (dcl->ops->dpy_reset) {
+            dcl->ops->dpy_reset(dcl);
+        }
+    }
+}
+
 /***********************************************************/
 /* register display */
 
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH 6/7 ui: Add dpy_cursor_enable()

In reply to John Baboval

From: "John V. Baboval" <[email protected]>

This is an optimization to allow the UI to show/hide the current cursor without setting it to a new bitmap.

In-guest screen sharing applications which show/hide the cursor when capturing the screen every frame (GoToMeeting, WebEx, etc.) cause high QEMU CPU usage if cursor hiding/restoring is implemented as setting a blank cursor and re-setting the original glyph. In-guest driver APIs typically have enable/disable called out as a separate operation to provide input for this optimization.

---
 include/ui/console.h |    3 +++
 ui/console.c         |   11 +++++++++++
 2 files changed, 14 insertions(+)
include/ui/console.h +3 -0
index a7171cc..7efa119 100644
@@ -182,6 +182,8 @@ typedef struct DisplayChangeListenerOps {
                           int x, int y, int on);
     void (*dpy_cursor_define)(DisplayChangeListener *dcl,
                               QEMUCursor *cursor);
+    void (*dpy_cursor_enable)(DisplayChangeListener *dcl,
+                              bool state);
 } DisplayChangeListenerOps;
 
 struct DisplayChangeListener {
@@ -232,6 +234,7 @@ void dpy_text_resize(QemuConsole *con, int w, int h);
 void dpy_mouse_set(QemuConsole *con, int x, int y, int on);
 void dpy_cursor_define(QemuConsole *con, QEMUCursor *cursor);
 bool dpy_cursor_define_supported(QemuConsole *con);
+void dpy_cursor_enable(QemuConsole *con, bool state);
 void dpy_reset(QemuConsole *con);
 
 static inline int surface_stride(DisplaySurface *s)
ui/console.c +11 -0
index 201e602..e9f74c9 100644
@@ -1560,6 +1560,17 @@ bool dpy_cursor_define_supported(QemuConsole *con)
     return false;
 }
 
+void dpy_cursor_enable(QemuConsole *con, bool state)
+{
+    DisplayState *s = con->ds;
+    struct DisplayChangeListener *dcl;
+    QLIST_FOREACH(dcl, &s->listeners, next) {
+        if (dcl->ops->dpy_cursor_enable) {
+            dcl->ops->dpy_cursor_enable(dcl, state);
+        }
+    }
+}
+
 void dpy_reset(QemuConsole *con)
 {
     DisplayState *s = con->ds;
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH 7/7 ui: Add an opaque pointer to the DisplayChangeListener

In reply to John Baboval

From: "John V. Baboval" <[email protected]>

The pointer is a place for the UI to hang a structure off of. In the multi-head case, the UI can use this pointer to distinguish which QemuConsole a dpy_* call was made for.

---
 include/ui/console.h |    1 +
 1 file changed, 1 insertion(+)
include/ui/console.h +1 -0
index 7efa119..271f577 100644
@@ -191,6 +191,7 @@ struct DisplayChangeListener {
     const DisplayChangeListenerOps *ops;
     DisplayState *ds;
     QemuConsole *con;
+    void *ui;
 
     QLIST_ENTRY(DisplayChangeListener) next;
 };
Signature · 1 line
1.7.9.5