Skip to contentSkip to conversation

initial spice support.

PATCH In review Gerd Hoffmann 2 participants 9 messages Jun 15, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

cover initial spice support.

Hi,

/me wants getting the spice support merging started, here is the first batch of patches. It brings just the very basic bits:

* Detect spice in configure, Makefile windup.
* Support for keyboard, mouse and tablet.
* Support for simple display output (works as DisplayChangeListener, plays with any gfx card, sends simple draw commands to update dirty regions).

Note that this patch series does *not* yet contain the qxl paravirtual gfx card. The patch series depends on the pflib bits submitted earlier today as part of the fbdev patch series.

Patches are also available from
http://cgit.freedesktop.org/spice/qemu/

This patch series is tagged 'submit.1'.
The latest spice branch is 'spice.v11' (qxl is included there).

cheers,
Gerd

Gerd Hoffmann (7):
configure: add logging
add spice into the configure file
spice: core bits
spice: add keyboard
spice: add mouse
spice: simple display
spice: add tablet support

 Makefile.objs   |    2 +
 configure       |   43 ++++++-
 qemu-config.c   |   23 +++
 qemu-config.h   |    1 +
 qemu-options.hx |    8 +
 qemu-spice.h    |   24 ++++
 spice-display.c |  404 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 spice-display.h |   52 +++++++
 spice-input.c   |  173 ++++++++++++++++++++++++
 spice.c         |  155 +++++++++++++++++++++
 vl.c            |   22 +++-
 11 files changed, 904 insertions(+), 3 deletions(-)
 create mode 100644 qemu-spice.h
 create mode 100644 spice-display.c
 create mode 100644 spice-display.h
 create mode 100644 spice-input.c
 create mode 100644 spice.c
#1 lore raw

PATCH 1/7 configure: add logging

Write compile commands and messages to config.log. Useful for debugging configure.

---
 configure |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
configure +5 -2
index c0d8aa5..8220226 100755
@@ -16,15 +16,18 @@ TMPO="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.o"
 TMPE="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.exe"
 
 trap "rm -f $TMPC $TMPO $TMPE ; exit" EXIT INT QUIT TERM
+rm -f config.log
 
 compile_object() {
-  $cc $QEMU_CFLAGS -c -o $TMPO $TMPC > /dev/null 2> /dev/null
+  echo $cc $QEMU_CFLAGS -c -o $TMPO $TMPC >> config.log
+  $cc $QEMU_CFLAGS -c -o $TMPO $TMPC >> config.log 2>&1
 }
 
 compile_prog() {
   local_cflags="$1"
   local_ldflags="$2"
-  $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags > /dev/null 2> /dev/null
+  echo $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags >> config.log
+  $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags >> config.log 2>&1
 }
 
 # check whether a command is available to this shell (may be either an
Signature · 1 line
1.6.5.2
Acked-by on v1 1/7
#2 lore raw

[Qemu-devel] Re: [PATCH 1/7] configure: add logging

Quoted 23 lines · Gerd Hoffmann

Write compile commands and messages to config.log. Useful for debugging configure.

---
  configure |    7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)
configure +3 -1
index c0d8aa5..8220226 100755
@@ -16,15 +16,18 @@ TMPO="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.o"
  TMPE="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.exe"
 
  trap "rm -f $TMPC $TMPO $TMPE ; exit" EXIT INT QUIT TERM
+rm -f config.log
 
  compile_object() {
-  $cc $QEMU_CFLAGS -c -o $TMPO $TMPC>  /dev/null 2>  /dev/null
+  echo $cc $QEMU_CFLAGS -c -o $TMPO $TMPC>>  config.log
+  $cc $QEMU_CFLAGS -c -o $TMPO $TMPC>>  config.log 2>&1
  }

configure TMPO="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.o" · line 33

Quoted 10 lines
configure +2 -1
 
  compile_prog() {
    local_cflags="$1"
    local_ldflags="$2"
-  $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags>  /dev/null 2>  /dev/null
+  echo $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags>>  config.log
+  $cc $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags>>  config.log 2>&1
  }
 
  # check whether a command is available to this shell (may be either an

Paolo

#3 lore raw

PATCH 2/7 add spice into the configure file

In reply to Gerd Hoffmann
---
 configure |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
configure +36 -0
index 8220226..ca0942a 100755
@@ -314,6 +314,7 @@ pkgversion=""
 check_utests="no"
 user_pie="no"
 zero_malloc=""
+spice=""
 
 # OS specific
 if check_define __linux__ ; then
@@ -603,6 +604,10 @@ for opt do
   ;;
   --enable-kvm) kvm="yes"
   ;;
+  --disable-spice) spice="no"
+  ;;
+  --enable-spice) spice="yes"
+  ;;
   --enable-profiler) profiler="yes"
   ;;
   --enable-cocoa)
@@ -868,6 +873,8 @@ echo "  --enable-docs            enable documentation build"
 echo "  --disable-docs           disable documentation build"
 echo "  --disable-vhost-net      disable vhost-net acceleration support"
 echo "  --enable-vhost-net       enable vhost-net acceleration support"
+echo "  --disable-spice          disable spice"
+echo "  --enable-spice           enable spice"
 echo ""
 echo "NOTE: The object files are built at the place where configure is launched"
 exit 1
@@ -1951,6 +1958,30 @@ if compile_prog "" ""; then
     gcc_attribute_warn_unused_result=yes
 fi
 
+# spice probe
+if test "$spice" != "no" ; then
+  cat > $TMPC << EOF
+#include <spice.h>
+int main(void) { spice_server_new(); return 0; }
+EOF
+  spice_proto_ver=$($pkgconfig --modversion spice-protocol 2>/dev/null)
+  spice_server_ver=$($pkgconfig --modversion spice-server 2>/dev/null)
+  spice_cflags=$($pkgconfig --cflags spice-protocol spice-server 2>/dev/null)
+  spice_libs=$($pkgconfig --libs spice-protocol spice-server 2>/dev/null)
+  if compile_prog "$spice_cflags" "$spice_libs" ; then
+    spice="yes"
+    libs_softmmu="$libs_softmmu $spice_libs"
+    QEMU_CFLAGS="$QEMU_CFLAGS $spice_cflags"
+  else
+    if test "$spice" = "yes" ; then
+      feature_not_found "spice"
+    fi
+    spice="no"
+  fi
+fi
+
+##########################################
+
 ##########################################
 # check if we have fdatasync
 
@@ -2089,6 +2120,7 @@ echo "preadv support    $preadv"
 echo "fdatasync         $fdatasync"
 echo "uuid support      $uuid"
 echo "vhost-net support $vhost_net"
+echo "spice support     $spice"
 
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -2305,6 +2337,10 @@ if test "$fdatasync" = "yes" ; then
   echo "CONFIG_FDATASYNC=y" >> $config_host_mak
 fi
 
+if test "$spice" = "yes" ; then
+  echo "CONFIG_SPICE=y" >> $config_host_mak
+fi
+
 # XXX: suppress that
 if [ "$bsd" = "yes" ] ; then
   echo "CONFIG_BSD=y" >> $config_host_mak
Signature · 1 line
1.6.5.2
#4 lore raw

PATCH 3/7 spice: core bits

In reply to Gerd Hoffmann

Add -spice command line switch. Has support setting passwd and port for now. With this patch applied the spice client can successfully connect to qemu. You can't do anything useful yet though.

---
 Makefile.objs   |    2 +
 qemu-config.c   |   23 ++++++++
 qemu-config.h   |    1 +
 qemu-options.hx |    8 +++
 qemu-spice.h    |   22 ++++++++
 spice.c         |  153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 vl.c            |   15 +++++
 7 files changed, 224 insertions(+), 0 deletions(-)
 create mode 100644 qemu-spice.h
 create mode 100644 spice.c
Makefile.objs +2 -0
index acc6179..1d0ee0f 100644
@@ -88,6 +88,8 @@ common-obj-y += pflib.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
 
+common-obj-$(CONFIG_SPICE) += spice.o
+
 audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
 audio-obj-$(CONFIG_SDL) += sdlaudio.o
 audio-obj-$(CONFIG_OSS) += ossaudio.o
qemu-config.c +23 -0
index 5a4e61b..fd613c2 100644
@@ -336,6 +336,26 @@ QemuOptsList qemu_cpudef_opts = {
     },
 };
 
+#ifdef CONFIG_SPICE
+QemuOptsList qemu_spice_opts = {
+    .name = "spice",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_spice_opts.head),
+    .desc = {
+        {
+            .name = "port",
+            .type = QEMU_OPT_NUMBER,
+        },{
+            .name = "password",
+            .type = QEMU_OPT_STRING,
+        },{
+            .name = "disable-ticketing",
+            .type = QEMU_OPT_BOOL,
+        },
+        { /* end if list */ }
+    },
+};
+#endif
+
 static QemuOptsList *vm_config_groups[] = {
     &qemu_drive_opts,
     &qemu_chardev_opts,
@@ -346,6 +366,9 @@ static QemuOptsList *vm_config_groups[] = {
     &qemu_global_opts,
     &qemu_mon_opts,
     &qemu_cpudef_opts,
+#ifdef CONFIG_SPICE
+    &qemu_spice_opts,
+#endif
     NULL,
 };
 
qemu-config.h +1 -0
index dca69d4..3a90213 100644
@@ -14,6 +14,7 @@ extern QemuOptsList qemu_rtc_opts;
 extern QemuOptsList qemu_global_opts;
 extern QemuOptsList qemu_mon_opts;
 extern QemuOptsList qemu_cpudef_opts;
+extern QemuOptsList qemu_spice_opts;
 
 QemuOptsList *qemu_find_opts(const char *group);
 int qemu_set_option(const char *str);
qemu-options.hx +8 -0
index a6928b7..d4ea047 100644
@@ -667,6 +667,14 @@ STEXI
 Enable SDL.
 ETEXI
 
+#ifdef CONFIG_SPICE
+DEF("spice", HAS_ARG, QEMU_OPTION_spice,
+    "-spice <args>   use spice\n", QEMU_ARCH_ALL)
+STEXI
+Use Spice.
+ETEXI
+#endif
+
 DEF("portrait", 0, QEMU_OPTION_portrait,
     "-portrait       rotate graphical output 90 deg left (only PXA LCD)\n",
     QEMU_ARCH_ALL)
qemu-spice.h new file +22 -0
new file mode 100644
index 0000000..5597576
@@ -0,0 +1,22 @@
+#ifndef QEMU_SPICE_H
+#define QEMU_SPICE_H
+
+#ifdef CONFIG_SPICE
+
+#include <spice.h>
+
+#include "qemu-option.h"
+#include "qemu-config.h"
+
+extern SpiceServer *spice_server;
+extern int using_spice;
+
+void qemu_spice_init(void);
+
+#else  /* CONFIG_SPICE */
+
+#define using_spice 0
+
+#endif /* CONFIG_SPICE */
+
+#endif /* QEMU_SPICE_H */
spice.c new file +153 -0

153 lines not on this page · raw message

vl.c +15 -0
index e5e43b3..eedba3d 100644
@@ -161,6 +161,8 @@ int main(int argc, char **argv)
 #include "cpus.h"
 #include "arch_init.h"
 
+#include "qemu-spice.h"
+
 //#define DEBUG_NET
 //#define DEBUG_SLIRP
 
@@ -2588,6 +2590,15 @@ int main(int argc, char **argv, char **envp)
                     }
                     break;
                 }
+#ifdef CONFIG_SPICE
+            case QEMU_OPTION_spice:
+                opts = qemu_opts_parse(&qemu_spice_opts, optarg, 0);
+                if (!opts) {
+                    fprintf(stderr, "parse error: %s\n", optarg);
+                    exit(1);
+                }
+                break;
+#endif
             case QEMU_OPTION_writeconfig:
                 {
                     FILE *fp;
@@ -2856,6 +2867,10 @@ int main(int argc, char **argv, char **envp)
     }
     qemu_add_globals();
 
+#ifdef CONFIG_SPICE
+    qemu_spice_init();
+#endif
+
     machine->init(ram_size, boot_devices,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
 
Signature · 1 line
1.6.5.2
#5 lore raw

PATCH 4/7 spice: add keyboard

In reply to Gerd Hoffmann

Open keyboard channel. Now you can type into the spice client and the keyboard events are sent to your guest. You'll need some other display like vnc to actually see the guest responding to them though.

---
 Makefile.objs |    2 +-
 qemu-spice.h  |    1 +
 spice-input.c |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 spice.c       |    2 ++
 4 files changed, 61 insertions(+), 1 deletions(-)
 create mode 100644 spice-input.c
Makefile.objs +1 -1
index 1d0ee0f..ad8b4b6 100644
@@ -88,7 +88,7 @@ common-obj-y += pflib.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
 
-common-obj-$(CONFIG_SPICE) += spice.o
+common-obj-$(CONFIG_SPICE) += spice.o spice-input.o
 
 audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
 audio-obj-$(CONFIG_SDL) += sdlaudio.o
qemu-spice.h +1 -0
index 5597576..ceb3db2 100644
@@ -12,6 +12,7 @@ extern SpiceServer *spice_server;
 extern int using_spice;
 
 void qemu_spice_init(void);
+void qemu_spice_input_init(void);
 
 #else  /* CONFIG_SPICE */
 
spice-input.c new file +57 -0

57 lines not on this page · raw message

spice.c +2 -0
index 59bd753..1546f97 100644
@@ -150,4 +150,6 @@ void qemu_spice_init(void)
 
     spice_server_init(spice_server, &core_interface);
     using_spice = 1;
+
+    qemu_spice_input_init();
 }
Signature · 1 line
1.6.5.2
#6 lore raw

PATCH 5/7 spice: add mouse

In reply to Gerd Hoffmann

Open mouse channel. Now you can move the guests mouse pointer. No tablet / absolute positioning (yet) though.

---
 spice-input.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)
spice-input.c +31 -0
index e1014d7..8f3deb4 100644
@@ -46,12 +46,43 @@ static void kbd_leds(void *opaque, int ledstate)
     spice_server_kbd_leds(&kbd->sin, ledstate);
 }
 
+/* mouse bits */
+
+typedef struct QemuSpiceMouse {
+    SpiceMouseInstance sin;
+} QemuSpiceMouse;
+
+static void mouse_motion(SpiceMouseInstance *sin, int dx, int dy, int dz,
+                         uint32_t buttons_state)
+{
+    kbd_mouse_event(dx, dy, dz, buttons_state);
+}
+
+static void mouse_buttons(SpiceMouseInstance *sin, uint32_t buttons_state)
+{
+    kbd_mouse_event(0, 0, 0, buttons_state);
+}
+
+static const SpiceMouseInterface mouse_interface = {
+    .base.type          = SPICE_INTERFACE_MOUSE,
+    .base.description   = "mouse",
+    .base.major_version = SPICE_INTERFACE_MOUSE_MAJOR,
+    .base.minor_version = SPICE_INTERFACE_MOUSE_MINOR,
+    .motion             = mouse_motion,
+    .buttons            = mouse_buttons,
+};
+
 void qemu_spice_input_init(void)
 {
     QemuSpiceKbd *kbd;
+    QemuSpiceMouse *mouse;
 
     kbd = qemu_mallocz(sizeof(*kbd));
     kbd->sin.base.sif = &kbd_interface.base;
     spice_server_add_interface(spice_server, &kbd->sin.base);
     qemu_add_led_event_handler(kbd_leds, kbd);
+
+    mouse = qemu_mallocz(sizeof(*mouse));
+    mouse->sin.base.sif = &mouse_interface.base;
+    spice_server_add_interface(spice_server, &mouse->sin.base);
 }
Signature · 1 line
1.6.5.2
#7 lore raw

PATCH 6/7 spice: simple display

In reply to Gerd Hoffmann

With that patch applied you'll actually see the guests screen in the spice client. This does *not* bring qxl and full spice support though. This is basically the qxl vga mode made more generic, so it plays together with any qemu-emulated gfx card. You can display stdvga or cirrus via spice client. You can have both vnc and spice enabled and clients connected at the same time.

---
 Makefile.objs   |    2 +-
 qemu-spice.h    |    1 +
 spice-display.c |  404 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 spice-display.h |   52 +++++++
 vl.c            |    7 +-
 5 files changed, 464 insertions(+), 2 deletions(-)
 create mode 100644 spice-display.c
 create mode 100644 spice-display.h
Makefile.objs +1 -1
index ad8b4b6..6e873e9 100644
@@ -88,7 +88,7 @@ common-obj-y += pflib.o
 common-obj-$(CONFIG_BRLAPI) += baum.o
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
 
-common-obj-$(CONFIG_SPICE) += spice.o spice-input.o
+common-obj-$(CONFIG_SPICE) += spice.o spice-input.o spice-display.o
 
 audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
 audio-obj-$(CONFIG_SDL) += sdlaudio.o
qemu-spice.h +1 -0
index ceb3db2..f061004 100644
@@ -13,6 +13,7 @@ extern int using_spice;
 
 void qemu_spice_init(void);
 void qemu_spice_input_init(void);
+void qemu_spice_display_init(DisplayState *ds);
 
 #else  /* CONFIG_SPICE */
 
spice-display.c new file +404 -0

404 lines not on this page · raw message

spice-display.h new file +52 -0

52 lines not on this page · raw message

vl.c +6 -1
index eedba3d..73e943b 100644
@@ -2898,7 +2898,7 @@ int main(int argc, char **argv, char **envp)
     /* just use the first displaystate for the moment */
     ds = get_displaystate();
 
-    if (display_type == DT_DEFAULT) {
+    if (display_type == DT_DEFAULT && !using_spice) {
 #if defined(CONFIG_SDL) || defined(CONFIG_COCOA)
         display_type = DT_SDL;
 #else
@@ -2938,6 +2938,11 @@ int main(int argc, char **argv, char **envp)
     default:
         break;
     }
+#ifdef CONFIG_SPICE
+    if (using_spice) {
+        qemu_spice_display_init(ds);
+    }
+#endif
     dpy_resize(ds);
 
     dcl = ds->listeners;
Signature · 1 line
1.6.5.2
#8 lore raw

PATCH 7/7 spice: add tablet support

In reply to Gerd Hoffmann

Add support for the spice tablet interface. The tablet interface will be registered (and then used by the spice client) as soon as a absolute pointing device is available and used by the guest, i.e. you'll have to configure your guest with '-usbdevice tablet'.

---
 spice-display.c |    2 +-
 spice-input.c   |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 93 insertions(+), 8 deletions(-)
spice-display.c +1 -1
index f0c610b..2d9ebd7 100644
@@ -143,7 +143,7 @@ void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd)
     surface.width      = ds_get_width(ssd->ds);
     surface.height     = ds_get_height(ssd->ds);
     surface.stride     = -surface.width * 4;
-    surface.mouse_mode = 0;
+    surface.mouse_mode = true;
     surface.flags      = 0;
     surface.type       = 0;
     surface.mem        = (intptr_t)ssd->buf;
spice-input.c +92 -7

123 lines not on this page · raw message

Signature · 1 line
1.6.5.2