Skip to contentSkip to conversation

xenfb: Add support for Windows PV frontend

PATCH Superseded Owen smith 3 participants 21 messages Sep 10, 2014 – Sep 29, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Owen smith

author
#0 lore raw

cover xenfb: Add support for Windows PV frontend

This patch series contains improvments for the Xen vkbd backend to support a Windows PV frontend mouse and keyboard. This allows VNC connections to have an absolute pointer without the USB tablet device enabled, and any unneccessary polling associated with the USB devices.

This patch series contains the following patches

1-2) Fixes to the vkbd device model
3) Adds a feature to not scale axes to DisplaySurface size

Owen smith (3):
xenfb: Unregister keyboard event handler correctly
xenfb: Add option to use grant ref instead of mfn for shared page.
xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

 hw/display/xenfb.c | 104 +++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 77 insertions(+), 27 deletions(-)
Signature · 1 line
2.1.0
author
#1 lore raw

PATCH 1/3 xenfb: Unregister keyboard event handler correctly

Keyboard event handler was replaced with a new handler on disconnect. Use the unregister function to remove keyboard handler.

---
 hw/display/xenfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
hw/display/xenfb.c +11 -2
index 07ddc9d..2c39753 100644
@@ -62,6 +62,7 @@ struct XenInput {
     int abs_pointer_wanted; /* Whether guest supports absolute pointer */
     int button_state;       /* Last seen pointer button state */
     int extended;
+    QEMUPutKbdEntry *qkbd;
     QEMUPutMouseEntry *qmouse;
 };
 
@@ -364,7 +365,6 @@ static int input_initialise(struct XenDevice *xendev)
     if (rc != 0)
 	return rc;
 
-    qemu_add_kbd_event_handler(xenfb_key_event, in);
     return 0;
 }
 
@@ -383,17 +383,26 @@ static void input_connected(struct XenDevice *xendev)
     in->qmouse = qemu_add_mouse_event_handler(xenfb_mouse_event, in,
 					      in->abs_pointer_wanted,
 					      "Xen PVFB Mouse");
+    qemu_activate_mouse_event_handler(in->qmouse);
+
+    if (in->qkbd) {
+        qemu_remove_kbd_event_handler(in->qkbd);
+    }
+    in->qkbd = qemu_add_kbd_event_handler(xenfb_key_event, in);
 }
 
 static void input_disconnect(struct XenDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
 
+    if (in->qkbd) {
+        qemu_remove_kbd_event_handler(in->qkbd);
+        in->qkbd = NULL;
+    }
     if (in->qmouse) {
 	qemu_remove_mouse_event_handler(in->qmouse);
 	in->qmouse = NULL;
     }
-    qemu_add_kbd_event_handler(NULL, NULL);
     common_unbind(&in->c);
 }
 
Signature · 1 line
2.1.0
#2 lore raw

Re: [PATCH 1/3] xenfb: Unregister keyboard event handler correctly

Quoted 29 lines · Owen smith

Keyboard event handler was replaced with a new handler on disconnect. Use the unregister function to remove keyboard handler.

---
 hw/display/xenfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
hw/display/xenfb.c +1 -1
index 07ddc9d..2c39753 100644
@@ -62,6 +62,7 @@ struct XenInput {
     int abs_pointer_wanted; /* Whether guest supports absolute pointer */
     int button_state;       /* Last seen pointer button state */
     int extended;
+    QEMUPutKbdEntry *qkbd;
     QEMUPutMouseEntry *qmouse;
 };
 
@@ -364,7 +365,6 @@ static int input_initialise(struct XenDevice *xendev)
     if (rc != 0)
 	return rc;
 
-    qemu_add_kbd_event_handler(xenfb_key_event, in);
     return 0;
 }
 

hw/display/xenfb.c static void input_connected(struct XenDevice *xendev) · line 386

Quoted 4 lines
hw/display/xenfb.c +1 -0
@@ -383,17 +383,26 @@ static void input_connected(struct XenDevice *xendev)
     in->qmouse = qemu_add_mouse_event_handler(xenfb_mouse_event, in,
 					      in->abs_pointer_wanted,
 					      "Xen PVFB Mouse");
+    qemu_activate_mouse_event_handler(in->qmouse);

This change is not described in the commit message. Why is this necessary? Is it related to the keyboard change?

Quoted 25 lines
hw/display/xenfb.c +8 -1
+    if (in->qkbd) {
+        qemu_remove_kbd_event_handler(in->qkbd);
+    }
+    in->qkbd = qemu_add_kbd_event_handler(xenfb_key_event, in);
 }
 
 static void input_disconnect(struct XenDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
 
+    if (in->qkbd) {
+        qemu_remove_kbd_event_handler(in->qkbd);
+        in->qkbd = NULL;
+    }
     if (in->qmouse) {
 	qemu_remove_mouse_event_handler(in->qmouse);
 	in->qmouse = NULL;
     }
-    qemu_add_kbd_event_handler(NULL, NULL);
     common_unbind(&in->c);
 }
 
Signature · 1 line
2.1.0
#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] xenfb: Unregister keyboard event handler correctly

In reply to Owen smith
Quoted 29 lines · Owen smith

Keyboard event handler was replaced with a new handler on disconnect. Use the unregister function to remove keyboard handler.

---
 hw/display/xenfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
hw/display/xenfb.c +1 -1
index 07ddc9d..2c39753 100644
@@ -62,6 +62,7 @@ struct XenInput {
     int abs_pointer_wanted; /* Whether guest supports absolute pointer */
     int button_state;       /* Last seen pointer button state */
     int extended;
+    QEMUPutKbdEntry *qkbd;
     QEMUPutMouseEntry *qmouse;
 };
 
@@ -364,7 +365,6 @@ static int input_initialise(struct XenDevice *xendev)
     if (rc != 0)
 	return rc;
 
-    qemu_add_kbd_event_handler(xenfb_key_event, in);
     return 0;
 }
 

hw/display/xenfb.c static void input_connected(struct XenDevice *xendev) · line 386

Quoted 4 lines
hw/display/xenfb.c +1 -0
@@ -383,17 +383,26 @@ static void input_connected(struct XenDevice *xendev)
     in->qmouse = qemu_add_mouse_event_handler(xenfb_mouse_event, in,
 					      in->abs_pointer_wanted,
 					      "Xen PVFB Mouse");
+    qemu_activate_mouse_event_handler(in->qmouse);

This change is not described in the commit message. Why is this necessary? Is it related to the keyboard change?

Quoted 25 lines
hw/display/xenfb.c +8 -1
+    if (in->qkbd) {
+        qemu_remove_kbd_event_handler(in->qkbd);
+    }
+    in->qkbd = qemu_add_kbd_event_handler(xenfb_key_event, in);
 }
 
 static void input_disconnect(struct XenDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
 
+    if (in->qkbd) {
+        qemu_remove_kbd_event_handler(in->qkbd);
+        in->qkbd = NULL;
+    }
     if (in->qmouse) {
 	qemu_remove_mouse_event_handler(in->qmouse);
 	in->qmouse = NULL;
     }
-    qemu_add_kbd_event_handler(NULL, NULL);
     common_unbind(&in->c);
 }
 
Signature · 1 line
2.1.0
author
#4 lore raw

Re: [PATCH 1/3] xenfb: Unregister keyboard event handler correctly

Quoted 39 lines

-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 11 September 2014 01:33
To: Owen Smith
Cc: [email protected]; [email protected]; Stefano Stabellini
Subject: Re: [PATCH 1/3] xenfb: Unregister keyboard event handler correctly

hw/display/xenfb.c static void input_connected(struct XenDevice

Quoted 29 lines · Owen smith

Keyboard event handler was replaced with a new handler on disconnect. Use the unregister function to remove keyboard handler.

---
 hw/display/xenfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
hw/display/xenfb.c index renamed from hw/display/xenfb.c +0 -0

07ddc9d..2c39753 100644

hw/display/xenfb.c +1 -1
@@ -62,6 +62,7 @@ struct XenInput {
     int abs_pointer_wanted; /* Whether guest supports absolute pointer */
     int button_state;       /* Last seen pointer button state */
     int extended;
+    QEMUPutKbdEntry *qkbd;
     QEMUPutMouseEntry *qmouse;
 };
 
@@ -364,7 +365,6 @@ static int input_initialise(struct XenDevice *xendev)
     if (rc != 0)
 	return rc;
 
-    qemu_add_kbd_event_handler(xenfb_key_event, in);
     return 0;
 }
 
@@ -383,17 +383,26 @@ static void input_connected(struct XenDevice

*xendev)

Quoted 9 lines

hw/display/xenfb.c static void input_connected(struct XenDevice · line 383

Quoted 1 line
hw/display/xenfb.c +0 -0
     in->qmouse = qemu_add_mouse_event_handler(xenfb_mouse_event,

in,

hw/display/xenfb.c static void input_connected(struct XenDevice *xendev) · line 386

Quoted 3 lines
hw/display/xenfb.c +1 -0
 					      in->abs_pointer_wanted,
 					      "Xen PVFB Mouse");
+    qemu_activate_mouse_event_handler(in->qmouse);

This change is not described in the commit message. Why is this necessary? Is it related to the keyboard change?

I'll split this change into a separate patch for v2.
Without this, the xenfb_mouse_event callback was not being called in response to mouse events, as events are only delivered to the first matching handler in the input chain.
Calling qemu_add_kbd_event_handler activates the handler internally, but qemu_add_mouse_event_handler does not activate the handler.

Quoted 26 lines
Quoted 26 lines
hw/display/xenfb.c +8 -2
+    if (in->qkbd) {
+        qemu_remove_kbd_event_handler(in->qkbd);
+    }
+    in->qkbd = qemu_add_kbd_event_handler(xenfb_key_event, in);
 }
 
 static void input_disconnect(struct XenDevice *xendev)  {
     struct XenInput *in = container_of(xendev, struct XenInput,
 c.xendev);
 
+    if (in->qkbd) {
+        qemu_remove_kbd_event_handler(in->qkbd);
+        in->qkbd = NULL;
+    }
     if (in->qmouse) {
 	qemu_remove_mouse_event_handler(in->qmouse);
 	in->qmouse = NULL;
     }
-    qemu_add_kbd_event_handler(NULL, NULL);
     common_unbind(&in->c);
 }
 
--

2.1.0

author
#5 lore raw

Re: [Qemu-devel] [PATCH 1/3] xenfb: Unregister keyboard event handler correctly

In reply to Stefano Stabellini
Quoted 39 lines

-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 11 September 2014 01:33
To: Owen Smith
Cc: [email protected]; [email protected]; Stefano Stabellini
Subject: Re: [PATCH 1/3] xenfb: Unregister keyboard event handler correctly

hw/display/xenfb.c static void input_connected(struct XenDevice

Quoted 29 lines · Owen smith

Keyboard event handler was replaced with a new handler on disconnect. Use the unregister function to remove keyboard handler.

---
 hw/display/xenfb.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
hw/display/xenfb.c index renamed from hw/display/xenfb.c +0 -0

07ddc9d..2c39753 100644

hw/display/xenfb.c +1 -1
@@ -62,6 +62,7 @@ struct XenInput {
     int abs_pointer_wanted; /* Whether guest supports absolute pointer */
     int button_state;       /* Last seen pointer button state */
     int extended;
+    QEMUPutKbdEntry *qkbd;
     QEMUPutMouseEntry *qmouse;
 };
 
@@ -364,7 +365,6 @@ static int input_initialise(struct XenDevice *xendev)
     if (rc != 0)
 	return rc;
 
-    qemu_add_kbd_event_handler(xenfb_key_event, in);
     return 0;
 }
 
@@ -383,17 +383,26 @@ static void input_connected(struct XenDevice

*xendev)

Quoted 9 lines

hw/display/xenfb.c static void input_connected(struct XenDevice · line 383

Quoted 1 line
hw/display/xenfb.c +0 -0
     in->qmouse = qemu_add_mouse_event_handler(xenfb_mouse_event,

in,

hw/display/xenfb.c static void input_connected(struct XenDevice *xendev) · line 386

Quoted 3 lines
hw/display/xenfb.c +1 -0
 					      in->abs_pointer_wanted,
 					      "Xen PVFB Mouse");
+    qemu_activate_mouse_event_handler(in->qmouse);

This change is not described in the commit message. Why is this necessary? Is it related to the keyboard change?

I'll split this change into a separate patch for v2.
Without this, the xenfb_mouse_event callback was not being called in response to mouse events, as events are only delivered to the first matching handler in the input chain.
Calling qemu_add_kbd_event_handler activates the handler internally, but qemu_add_mouse_event_handler does not activate the handler.

Quoted 26 lines
Quoted 26 lines
hw/display/xenfb.c +8 -2
+    if (in->qkbd) {
+        qemu_remove_kbd_event_handler(in->qkbd);
+    }
+    in->qkbd = qemu_add_kbd_event_handler(xenfb_key_event, in);
 }
 
 static void input_disconnect(struct XenDevice *xendev)  {
     struct XenInput *in = container_of(xendev, struct XenInput,
 c.xendev);
 
+    if (in->qkbd) {
+        qemu_remove_kbd_event_handler(in->qkbd);
+        in->qkbd = NULL;
+    }
     if (in->qmouse) {
 	qemu_remove_mouse_event_handler(in->qmouse);
 	in->qmouse = NULL;
     }
-    qemu_add_kbd_event_handler(NULL, NULL);
     common_unbind(&in->c);
 }
 
--

2.1.0

author
#6 lore raw

PATCH 2/3 xenfb: Add option to use grant ref for shared page.

In reply to Owen smith

The vkbd device should be able to use a grant reference to map the shared page.

---
 hw/display/xenfb.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
hw/display/xenfb.c +31 -10
index 2c39753..c4375c8 100644
@@ -54,6 +54,7 @@
 struct common {
     struct XenDevice  xendev;  /* must be first */
     void              *page;
+    int               page_gref;
     QemuConsole       *con;
 };
 
@@ -96,22 +97,36 @@ static int common_bind(struct common *c)
 {
     uint64_t mfn;
 
-    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1)
-	return -1;
-    assert(mfn == (xen_pfn_t)mfn);
-
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
-				   XC_PAGE_SIZE,
-				   PROT_READ | PROT_WRITE, mfn);
+    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1) {
+        if (xenstore_read_fe_int(&c->xendev, "page-gref", &c->page_gref) == -1) {
+            return -1;
+        }
+        c->page = xc_gnttab_map_grant_ref(c->xendev.gnttabdev,
+                                          c->xendev.dom,
+                                          c->page_gref,
+                                          PROT_READ | PROT_WRITE);
+    } else {
+        assert(mfn == (xen_pfn_t)mfn);
+
+        c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
+                                       XC_PAGE_SIZE,
+                                       PROT_READ | PROT_WRITE, mfn);
+    }
     if (c->page == NULL)
 	return -1;
 
     xen_be_bind_evtchn(&c->xendev);
-    xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d, local-port %d\n",
-		  mfn, c->xendev.remote_port, c->xendev.local_port);
+
+    if (c->page_gref) {
+        xen_be_printf(&c->xendev, 1, "ring gref %d, remote-port %d, local-port %d\n",
+                      c->page_gref, c->xendev.remote_port, c->xendev.local_port);
+    } else {
+        xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d, local-port %d\n",
+                      mfn, c->xendev.remote_port, c->xendev.local_port);
+    }
 
     return 0;
 }
@@ -120,8 +135,13 @@ static void common_unbind(struct common *c)
 {
     xen_be_unbind_evtchn(&c->xendev);
     if (c->page) {
-	munmap(c->page, XC_PAGE_SIZE);
+        if (c->page_gref) {
+            xc_gnttab_munmap(c->xendev.gnttabdev, c->page, 1);
+        } else {
+            munmap(c->page, XC_PAGE_SIZE);
+        }
 	c->page = NULL;
+        c->page_gref = 0;
     }
 }
 
@@ -954,6 +974,7 @@ static void fb_event(struct XenDevice *xendev)
 
 struct XenDevOps xen_kbdmouse_ops = {
     .size       = sizeof(struct XenInput),
+    .flags      = DEVOPS_FLAG_NEED_GNTDEV,
     .init       = input_init,
     .initialise = input_initialise,
     .connected  = input_connected,
Signature · 1 line
2.1.0
#7 lore raw

Re: [PATCH 2/3] xenfb: Add option to use grant ref for shared page.

Quoted 39 lines · Owen smith

The vkbd device should be able to use a grant reference to map the shared page.

---
 hw/display/xenfb.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
hw/display/xenfb.c +6 -7
index 2c39753..c4375c8 100644
@@ -54,6 +54,7 @@
 struct common {
     struct XenDevice  xendev;  /* must be first */
     void              *page;
+    int               page_gref;
     QemuConsole       *con;
 };
 
@@ -96,22 +97,36 @@ static int common_bind(struct common *c)
 {
     uint64_t mfn;
 
-    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1)
-	return -1;
-    assert(mfn == (xen_pfn_t)mfn);
-
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
-				   XC_PAGE_SIZE,
-				   PROT_READ | PROT_WRITE, mfn);
+    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1) {
+        if (xenstore_read_fe_int(&c->xendev, "page-gref", &c->page_gref) == -1) {
+            return -1;
+        }
+        c->page = xc_gnttab_map_grant_ref(c->xendev.gnttabdev,

hw/display/xenfb.c static int common_bind(struct common *c) · line 117

Quoted 10 lines
hw/display/xenfb.c +10 -0
+                                          c->xendev.dom,
+                                          c->page_gref,
+                                          PROT_READ | PROT_WRITE);
+    } else {
+        assert(mfn == (xen_pfn_t)mfn);
+
+        c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
+                                       XC_PAGE_SIZE,
+                                       PROT_READ | PROT_WRITE, mfn);
+    }

This is an extension of the protocol. It should be documented somewhere. At least in the commit message and somewhere under docs/misc or xen/include/public/io/fbif.h.

Quoted 43 lines
hw/display/xenfb.c +15 -3
     if (c->page == NULL)
 	return -1;
 
     xen_be_bind_evtchn(&c->xendev);
-    xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d, local-port %d\n",
-		  mfn, c->xendev.remote_port, c->xendev.local_port);
+
+    if (c->page_gref) {
+        xen_be_printf(&c->xendev, 1, "ring gref %d, remote-port %d, local-port %d\n",
+                      c->page_gref, c->xendev.remote_port, c->xendev.local_port);
+    } else {
+        xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d, local-port %d\n",
+                      mfn, c->xendev.remote_port, c->xendev.local_port);
+    }
 
     return 0;
 }
@@ -120,8 +135,13 @@ static void common_unbind(struct common *c)
 {
     xen_be_unbind_evtchn(&c->xendev);
     if (c->page) {
-	munmap(c->page, XC_PAGE_SIZE);
+        if (c->page_gref) {
+            xc_gnttab_munmap(c->xendev.gnttabdev, c->page, 1);
+        } else {
+            munmap(c->page, XC_PAGE_SIZE);
+        }
 	c->page = NULL;
+        c->page_gref = 0;
     }
 }
 
@@ -954,6 +974,7 @@ static void fb_event(struct XenDevice *xendev)
 
 struct XenDevOps xen_kbdmouse_ops = {
     .size       = sizeof(struct XenInput),
+    .flags      = DEVOPS_FLAG_NEED_GNTDEV,
     .init       = input_init,
     .initialise = input_initialise,
     .connected  = input_connected,
Signature · 1 line
2.1.0
#8 lore raw

Re: [Qemu-devel] [PATCH 2/3] xenfb: Add option to use grant ref for shared page.

In reply to Owen smith
Quoted 39 lines · Owen smith

The vkbd device should be able to use a grant reference to map the shared page.

---
 hw/display/xenfb.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
hw/display/xenfb.c +6 -7
index 2c39753..c4375c8 100644
@@ -54,6 +54,7 @@
 struct common {
     struct XenDevice  xendev;  /* must be first */
     void              *page;
+    int               page_gref;
     QemuConsole       *con;
 };
 
@@ -96,22 +97,36 @@ static int common_bind(struct common *c)
 {
     uint64_t mfn;
 
-    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1)
-	return -1;
-    assert(mfn == (xen_pfn_t)mfn);
-
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c->xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
-				   XC_PAGE_SIZE,
-				   PROT_READ | PROT_WRITE, mfn);
+    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1) {
+        if (xenstore_read_fe_int(&c->xendev, "page-gref", &c->page_gref) == -1) {
+            return -1;
+        }
+        c->page = xc_gnttab_map_grant_ref(c->xendev.gnttabdev,

hw/display/xenfb.c static int common_bind(struct common *c) · line 117

Quoted 10 lines
hw/display/xenfb.c +10 -0
+                                          c->xendev.dom,
+                                          c->page_gref,
+                                          PROT_READ | PROT_WRITE);
+    } else {
+        assert(mfn == (xen_pfn_t)mfn);
+
+        c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
+                                       XC_PAGE_SIZE,
+                                       PROT_READ | PROT_WRITE, mfn);
+    }

This is an extension of the protocol. It should be documented somewhere. At least in the commit message and somewhere under docs/misc or xen/include/public/io/fbif.h.

Quoted 43 lines
hw/display/xenfb.c +15 -3
     if (c->page == NULL)
 	return -1;
 
     xen_be_bind_evtchn(&c->xendev);
-    xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d, local-port %d\n",
-		  mfn, c->xendev.remote_port, c->xendev.local_port);
+
+    if (c->page_gref) {
+        xen_be_printf(&c->xendev, 1, "ring gref %d, remote-port %d, local-port %d\n",
+                      c->page_gref, c->xendev.remote_port, c->xendev.local_port);
+    } else {
+        xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d, local-port %d\n",
+                      mfn, c->xendev.remote_port, c->xendev.local_port);
+    }
 
     return 0;
 }
@@ -120,8 +135,13 @@ static void common_unbind(struct common *c)
 {
     xen_be_unbind_evtchn(&c->xendev);
     if (c->page) {
-	munmap(c->page, XC_PAGE_SIZE);
+        if (c->page_gref) {
+            xc_gnttab_munmap(c->xendev.gnttabdev, c->page, 1);
+        } else {
+            munmap(c->page, XC_PAGE_SIZE);
+        }
 	c->page = NULL;
+        c->page_gref = 0;
     }
 }
 
@@ -954,6 +974,7 @@ static void fb_event(struct XenDevice *xendev)
 
 struct XenDevOps xen_kbdmouse_ops = {
     .size       = sizeof(struct XenInput),
+    .flags      = DEVOPS_FLAG_NEED_GNTDEV,
     .init       = input_init,
     .initialise = input_initialise,
     .connected  = input_connected,
Signature · 1 line
2.1.0
author
#9 lore raw

Re: [PATCH 2/3] xenfb: Add option to use grant ref for shared page.

Quoted 60 lines

-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 11 September 2014 02:01
To: Owen Smith
Cc: [email protected]; [email protected]; Stefano Stabellini
Subject: Re: [PATCH 2/3] xenfb: Add option to use grant ref for shared page.

Quoted 26 lines · Owen smith

The vkbd device should be able to use a grant reference to map the shared page.

---
 hw/display/xenfb.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
hw/display/xenfb.c index renamed from hw/display/xenfb.c +0 -0

2c39753..c4375c8 100644

hw/display/xenfb.c +1 -3
@@ -54,6 +54,7 @@
 struct common {
     struct XenDevice  xendev;  /* must be first */
     void              *page;
+    int               page_gref;
     QemuConsole       *con;
 };
 
@@ -96,22 +97,36 @@ static int common_bind(struct common *c)  {
     uint64_t mfn;
 
-    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1)
-	return -1;
-    assert(mfn == (xen_pfn_t)mfn);

hw/display/xenfb.c static int common_bind(struct common *c) { · line 104

Quoted 10 lines
hw/display/xenfb.c +2 -4
-
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c-
 xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
-				   XC_PAGE_SIZE,
-				   PROT_READ | PROT_WRITE, mfn);
+    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1) {
+        if (xenstore_read_fe_int(&c->xendev, "page-gref", &c->page_gref)

== -1) {

hw/display/xenfb.c static int common_bind(struct common *c) · line 117

Quoted 13 lines
hw/display/xenfb.c +13 -0
+            return -1;
+        }
+        c->page = xc_gnttab_map_grant_ref(c->xendev.gnttabdev,
+                                          c->xendev.dom,
+                                          c->page_gref,
+                                          PROT_READ | PROT_WRITE);
+    } else {
+        assert(mfn == (xen_pfn_t)mfn);
+
+        c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
+                                       XC_PAGE_SIZE,
+                                       PROT_READ | PROT_WRITE, mfn);
+    }
Quoted 4 lines

This is an extension of the protocol. It should be documented somewhere. At least in the commit message and somewhere under docs/misc or xen/include/public/io/fbif.h.

V2 will contain a better commit message, and I'll add a patch to the headers to document the changes.
The same protocol extension docs should be in xen/include/public/io/fbif.h and xen/include/public/io/kdbif.h, as this change covers the vfb and vkbd, or would it be better to change the patch to only affect the vkbd?

Quoted 46 lines

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 6 lines
hw/display/xenfb.c +0 -1
     if (c->page == NULL)
 	return -1;
 
     xen_be_bind_evtchn(&c->xendev);
-    xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d,

local-port %d\n",

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 4 lines
hw/display/xenfb.c +3 -1
-		  mfn, c->xendev.remote_port, c->xendev.local_port);
+
+    if (c->page_gref) {
+        xen_be_printf(&c->xendev, 1, "ring gref %d, remote-port %d, local-

port %d\n",

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 3 lines
hw/display/xenfb.c +3 -0
+                      c->page_gref, c->xendev.remote_port, c->xendev.local_port);
+    } else {
+        xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d,

local-port %d\n",

Quoted 30 lines
hw/display/xenfb.c +9 -2
+                      mfn, c->xendev.remote_port, c->xendev.local_port);
+    }
 
     return 0;
 }
@@ -120,8 +135,13 @@ static void common_unbind(struct common *c)  {
     xen_be_unbind_evtchn(&c->xendev);
     if (c->page) {
-	munmap(c->page, XC_PAGE_SIZE);
+        if (c->page_gref) {
+            xc_gnttab_munmap(c->xendev.gnttabdev, c->page, 1);
+        } else {
+            munmap(c->page, XC_PAGE_SIZE);
+        }
 	c->page = NULL;
+        c->page_gref = 0;
     }
 }
 
@@ -954,6 +974,7 @@ static void fb_event(struct XenDevice *xendev)
 
 struct XenDevOps xen_kbdmouse_ops = {
     .size       = sizeof(struct XenInput),
+    .flags      = DEVOPS_FLAG_NEED_GNTDEV,
     .init       = input_init,
     .initialise = input_initialise,
     .connected  = input_connected,
--

2.1.0

author
#10 lore raw

Re: [Qemu-devel] [PATCH 2/3] xenfb: Add option to use grant ref for shared page.

In reply to Stefano Stabellini
Quoted 60 lines

-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 11 September 2014 02:01
To: Owen Smith
Cc: [email protected]; [email protected]; Stefano Stabellini
Subject: Re: [PATCH 2/3] xenfb: Add option to use grant ref for shared page.

Quoted 26 lines · Owen smith

The vkbd device should be able to use a grant reference to map the shared page.

---
 hw/display/xenfb.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
hw/display/xenfb.c index renamed from hw/display/xenfb.c +0 -0

2c39753..c4375c8 100644

hw/display/xenfb.c +1 -3
@@ -54,6 +54,7 @@
 struct common {
     struct XenDevice  xendev;  /* must be first */
     void              *page;
+    int               page_gref;
     QemuConsole       *con;
 };
 
@@ -96,22 +97,36 @@ static int common_bind(struct common *c)  {
     uint64_t mfn;
 
-    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1)
-	return -1;
-    assert(mfn == (xen_pfn_t)mfn);

hw/display/xenfb.c static int common_bind(struct common *c) { · line 104

Quoted 10 lines
hw/display/xenfb.c +2 -4
-
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c-
 xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
-				   XC_PAGE_SIZE,
-				   PROT_READ | PROT_WRITE, mfn);
+    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1) {
+        if (xenstore_read_fe_int(&c->xendev, "page-gref", &c->page_gref)

== -1) {

hw/display/xenfb.c static int common_bind(struct common *c) · line 117

Quoted 13 lines
hw/display/xenfb.c +13 -0
+            return -1;
+        }
+        c->page = xc_gnttab_map_grant_ref(c->xendev.gnttabdev,
+                                          c->xendev.dom,
+                                          c->page_gref,
+                                          PROT_READ | PROT_WRITE);
+    } else {
+        assert(mfn == (xen_pfn_t)mfn);
+
+        c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
+                                       XC_PAGE_SIZE,
+                                       PROT_READ | PROT_WRITE, mfn);
+    }
Quoted 4 lines

This is an extension of the protocol. It should be documented somewhere. At least in the commit message and somewhere under docs/misc or xen/include/public/io/fbif.h.

V2 will contain a better commit message, and I'll add a patch to the headers to document the changes.
The same protocol extension docs should be in xen/include/public/io/fbif.h and xen/include/public/io/kdbif.h, as this change covers the vfb and vkbd, or would it be better to change the patch to only affect the vkbd?

Quoted 46 lines

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 6 lines
hw/display/xenfb.c +0 -1
     if (c->page == NULL)
 	return -1;
 
     xen_be_bind_evtchn(&c->xendev);
-    xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d,

local-port %d\n",

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 4 lines
hw/display/xenfb.c +3 -1
-		  mfn, c->xendev.remote_port, c->xendev.local_port);
+
+    if (c->page_gref) {
+        xen_be_printf(&c->xendev, 1, "ring gref %d, remote-port %d, local-

port %d\n",

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 3 lines
hw/display/xenfb.c +3 -0
+                      c->page_gref, c->xendev.remote_port, c->xendev.local_port);
+    } else {
+        xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d,

local-port %d\n",

Quoted 30 lines
hw/display/xenfb.c +9 -2
+                      mfn, c->xendev.remote_port, c->xendev.local_port);
+    }
 
     return 0;
 }
@@ -120,8 +135,13 @@ static void common_unbind(struct common *c)  {
     xen_be_unbind_evtchn(&c->xendev);
     if (c->page) {
-	munmap(c->page, XC_PAGE_SIZE);
+        if (c->page_gref) {
+            xc_gnttab_munmap(c->xendev.gnttabdev, c->page, 1);
+        } else {
+            munmap(c->page, XC_PAGE_SIZE);
+        }
 	c->page = NULL;
+        c->page_gref = 0;
     }
 }
 
@@ -954,6 +974,7 @@ static void fb_event(struct XenDevice *xendev)
 
 struct XenDevOps xen_kbdmouse_ops = {
     .size       = sizeof(struct XenInput),
+    .flags      = DEVOPS_FLAG_NEED_GNTDEV,
     .init       = input_init,
     .initialise = input_initialise,
     .connected  = input_connected,
--

2.1.0

#11 lore raw

Re: [PATCH 2/3] xenfb: Add option to use grant ref for shared page.

Quoted 64 lines · Owen Smith
Quoted 59 lines

-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 11 September 2014 02:01
To: Owen Smith
Cc: [email protected]; [email protected]; Stefano Stabellini
Subject: Re: [PATCH 2/3] xenfb: Add option to use grant ref for shared page.

Quoted 26 lines · Owen smith

The vkbd device should be able to use a grant reference to map the shared page.

---
 hw/display/xenfb.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
hw/display/xenfb.c index renamed from hw/display/xenfb.c +0 -0

2c39753..c4375c8 100644

hw/display/xenfb.c +1 -3
@@ -54,6 +54,7 @@
 struct common {
     struct XenDevice  xendev;  /* must be first */
     void              *page;
+    int               page_gref;
     QemuConsole       *con;
 };
 
@@ -96,22 +97,36 @@ static int common_bind(struct common *c)  {
     uint64_t mfn;
 
-    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1)
-	return -1;
-    assert(mfn == (xen_pfn_t)mfn);

hw/display/xenfb.c static int common_bind(struct common *c) { · line 104

Quoted 10 lines
hw/display/xenfb.c +2 -4
-
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c-
 xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
-				   XC_PAGE_SIZE,
-				   PROT_READ | PROT_WRITE, mfn);
+    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1) {
+        if (xenstore_read_fe_int(&c->xendev, "page-gref", &c->page_gref)

== -1) {

hw/display/xenfb.c static int common_bind(struct common *c) · line 117

Quoted 13 lines
hw/display/xenfb.c +13 -0
+            return -1;
+        }
+        c->page = xc_gnttab_map_grant_ref(c->xendev.gnttabdev,
+                                          c->xendev.dom,
+                                          c->page_gref,
+                                          PROT_READ | PROT_WRITE);
+    } else {
+        assert(mfn == (xen_pfn_t)mfn);
+
+        c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
+                                       XC_PAGE_SIZE,
+                                       PROT_READ | PROT_WRITE, mfn);
+    }
Quoted 4 lines

This is an extension of the protocol. It should be documented somewhere. At least in the commit message and somewhere under docs/misc or xen/include/public/io/fbif.h.

Quoted 5 lines

V2 will contain a better commit message, and I'll add a patch to the headers to document the changes.
The same protocol extension docs should be in xen/include/public/io/fbif.h and xen/include/public/io/kdbif.h, as this change covers the vfb and vkbd, or would it be better to change the patch to only affect the vkbd?

I am OK with changing both vfb and vkbd but in that case you need to document both.

Quoted 47 lines
Quoted 46 lines

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 6 lines
hw/display/xenfb.c +0 -1
     if (c->page == NULL)
 	return -1;
 
     xen_be_bind_evtchn(&c->xendev);
-    xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d,

local-port %d\n",

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 4 lines
hw/display/xenfb.c +3 -1
-		  mfn, c->xendev.remote_port, c->xendev.local_port);
+
+    if (c->page_gref) {
+        xen_be_printf(&c->xendev, 1, "ring gref %d, remote-port %d, local-

port %d\n",

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 3 lines
hw/display/xenfb.c +3 -0
+                      c->page_gref, c->xendev.remote_port, c->xendev.local_port);
+    } else {
+        xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d,

local-port %d\n",

Quoted 30 lines
hw/display/xenfb.c +9 -2
+                      mfn, c->xendev.remote_port, c->xendev.local_port);
+    }
 
     return 0;
 }
@@ -120,8 +135,13 @@ static void common_unbind(struct common *c)  {
     xen_be_unbind_evtchn(&c->xendev);
     if (c->page) {
-	munmap(c->page, XC_PAGE_SIZE);
+        if (c->page_gref) {
+            xc_gnttab_munmap(c->xendev.gnttabdev, c->page, 1);
+        } else {
+            munmap(c->page, XC_PAGE_SIZE);
+        }
 	c->page = NULL;
+        c->page_gref = 0;
     }
 }
 
@@ -954,6 +974,7 @@ static void fb_event(struct XenDevice *xendev)
 
 struct XenDevOps xen_kbdmouse_ops = {
     .size       = sizeof(struct XenInput),
+    .flags      = DEVOPS_FLAG_NEED_GNTDEV,
     .init       = input_init,
     .initialise = input_initialise,
     .connected  = input_connected,
--

2.1.0

#12 lore raw

Re: [Qemu-devel] [PATCH 2/3] xenfb: Add option to use grant ref for shared page.

In reply to Owen Smith
Quoted 64 lines · Owen Smith
Quoted 59 lines

-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 11 September 2014 02:01
To: Owen Smith
Cc: [email protected]; [email protected]; Stefano Stabellini
Subject: Re: [PATCH 2/3] xenfb: Add option to use grant ref for shared page.

Quoted 26 lines · Owen smith

The vkbd device should be able to use a grant reference to map the shared page.

---
 hw/display/xenfb.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
hw/display/xenfb.c index renamed from hw/display/xenfb.c +0 -0

2c39753..c4375c8 100644

hw/display/xenfb.c +1 -3
@@ -54,6 +54,7 @@
 struct common {
     struct XenDevice  xendev;  /* must be first */
     void              *page;
+    int               page_gref;
     QemuConsole       *con;
 };
 
@@ -96,22 +97,36 @@ static int common_bind(struct common *c)  {
     uint64_t mfn;
 
-    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1)
-	return -1;
-    assert(mfn == (xen_pfn_t)mfn);

hw/display/xenfb.c static int common_bind(struct common *c) { · line 104

Quoted 10 lines
hw/display/xenfb.c +2 -4
-
     if (xenstore_read_fe_int(&c->xendev, "event-channel", &c-
 xendev.remote_port) == -1)
 	return -1;
 
-    c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
-				   XC_PAGE_SIZE,
-				   PROT_READ | PROT_WRITE, mfn);
+    if (xenstore_read_fe_uint64(&c->xendev, "page-ref", &mfn) == -1) {
+        if (xenstore_read_fe_int(&c->xendev, "page-gref", &c->page_gref)

== -1) {

hw/display/xenfb.c static int common_bind(struct common *c) · line 117

Quoted 13 lines
hw/display/xenfb.c +13 -0
+            return -1;
+        }
+        c->page = xc_gnttab_map_grant_ref(c->xendev.gnttabdev,
+                                          c->xendev.dom,
+                                          c->page_gref,
+                                          PROT_READ | PROT_WRITE);
+    } else {
+        assert(mfn == (xen_pfn_t)mfn);
+
+        c->page = xc_map_foreign_range(xen_xc, c->xendev.dom,
+                                       XC_PAGE_SIZE,
+                                       PROT_READ | PROT_WRITE, mfn);
+    }
Quoted 4 lines

This is an extension of the protocol. It should be documented somewhere. At least in the commit message and somewhere under docs/misc or xen/include/public/io/fbif.h.

Quoted 5 lines

V2 will contain a better commit message, and I'll add a patch to the headers to document the changes.
The same protocol extension docs should be in xen/include/public/io/fbif.h and xen/include/public/io/kdbif.h, as this change covers the vfb and vkbd, or would it be better to change the patch to only affect the vkbd?

I am OK with changing both vfb and vkbd but in that case you need to document both.

Quoted 47 lines
Quoted 46 lines

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 6 lines
hw/display/xenfb.c +0 -1
     if (c->page == NULL)
 	return -1;
 
     xen_be_bind_evtchn(&c->xendev);
-    xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d,

local-port %d\n",

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 4 lines
hw/display/xenfb.c +3 -1
-		  mfn, c->xendev.remote_port, c->xendev.local_port);
+
+    if (c->page_gref) {
+        xen_be_printf(&c->xendev, 1, "ring gref %d, remote-port %d, local-

port %d\n",

hw/display/xenfb.c static int common_bind(struct common *c)

Quoted 3 lines
hw/display/xenfb.c +3 -0
+                      c->page_gref, c->xendev.remote_port, c->xendev.local_port);
+    } else {
+        xen_be_printf(&c->xendev, 1, "ring mfn %"PRIx64", remote-port %d,

local-port %d\n",

Quoted 30 lines
hw/display/xenfb.c +9 -2
+                      mfn, c->xendev.remote_port, c->xendev.local_port);
+    }
 
     return 0;
 }
@@ -120,8 +135,13 @@ static void common_unbind(struct common *c)  {
     xen_be_unbind_evtchn(&c->xendev);
     if (c->page) {
-	munmap(c->page, XC_PAGE_SIZE);
+        if (c->page_gref) {
+            xc_gnttab_munmap(c->xendev.gnttabdev, c->page, 1);
+        } else {
+            munmap(c->page, XC_PAGE_SIZE);
+        }
 	c->page = NULL;
+        c->page_gref = 0;
     }
 }
 
@@ -954,6 +974,7 @@ static void fb_event(struct XenDevice *xendev)
 
 struct XenDevOps xen_kbdmouse_ops = {
     .size       = sizeof(struct XenInput),
+    .flags      = DEVOPS_FLAG_NEED_GNTDEV,
     .init       = input_init,
     .initialise = input_initialise,
     .connected  = input_connected,
--

2.1.0

author
#13 lore raw

PATCH 3/3 xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

In reply to Owen smith

Windows PV frontend requires absolute mouse values in the range [0, 0x7fff]. Add a feature to not rescale the axes to DisplaySurface size. Also allows Windows PV frontend to connect without a vfb device. Moves the rescaling of axes to a seperate function with additional null-pointer checks.

---
 hw/display/xenfb.c | 52 +++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)
hw/display/xenfb.c +39 -15
index c4375c8..65c373b 100644
@@ -61,6 +61,7 @@ struct common {
 struct XenInput {
     struct common c;
     int abs_pointer_wanted; /* Whether guest supports absolute pointer */
+    int no_abs_rescale;     /* Whether guest wants rescaled abs axes */
     int button_state;       /* Last seen pointer button state */
     int extended;
     QEMUPutKbdEntry *qkbd;
@@ -325,6 +326,25 @@ static void xenfb_key_event(void *opaque, int scancode)
     xenfb_send_key(xenfb, down, scancode2linux[scancode]);
 }
 
+static void xenfb_rescale_mouse(struct XenInput *xenfb, int *dx, int *dy)
+{
+    DisplaySurface *surface;
+    int dw, dh;
+
+    if (xenfb->c.con == NULL) {
+        return;
+    }
+    surface = qemu_console_surface(xenfb->c.con);
+    if (surface == NULL) {
+        return;
+    }
+    dw = surface_width(surface);
+    dh = surface_height(surface);
+
+    *dx = *dx * (dw - 1) / 0x7fff;
+    *dy = *dy * (dh - 1) / 0x7fff;
+}
+
 /*
  * Send a mouse event from the client to the guest OS
  *
@@ -338,18 +358,16 @@ static void xenfb_mouse_event(void *opaque,
 			      int dx, int dy, int dz, int button_state)
 {
     struct XenInput *xenfb = opaque;
-    DisplaySurface *surface = qemu_console_surface(xenfb->c.con);
-    int dw = surface_width(surface);
-    int dh = surface_height(surface);
     int i;
 
-    if (xenfb->abs_pointer_wanted)
-	xenfb_send_position(xenfb,
-			    dx * (dw - 1) / 0x7fff,
-			    dy * (dh - 1) / 0x7fff,
-			    dz);
-    else
+    if (xenfb->abs_pointer_wanted) {
+        if (!xenfb->no_abs_rescale) {
+            xenfb_rescale_mouse(xenfb, &dx, &dy);
+        }
+        xenfb_send_position(xenfb, dx, dy, dz);
+    } else {
 	xenfb_send_motion(xenfb, dx, dy, dz);
+    }
 
     for (i = 0 ; i < 8 ; i++) {
 	int lastDown = xenfb->button_state & (1 << i);
@@ -366,6 +382,7 @@ static void xenfb_mouse_event(void *opaque,
 static int input_init(struct XenDevice *xendev)
 {
     xenstore_write_be_int(xendev, "feature-abs-pointer", 1);
+    xenstore_write_be_int(xendev, "feature-no-abs-rescale", 1);
     return 0;
 }
 
@@ -374,7 +391,17 @@ static int input_initialise(struct XenDevice *xendev)
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
     int rc;
 
-    if (!in->c.con) {
+    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
+                             &in->abs_pointer_wanted) == -1) {
+        in->abs_pointer_wanted = 0;
+    }
+
+    if (xenstore_read_fe_int(xendev, "request-no-abs-rescale",
+                             &in->no_abs_rescale) == -1) {
+        in->no_abs_rescale = 0;
+    }
+
+    if (!in->c.con && !in->no_abs_rescale) {
         xen_be_printf(xendev, 1, "ds not set (yet)\n");
         return -1;
     }
@@ -390,11 +417,6 @@ static void input_connected(struct XenDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
 
-    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
-                             &in->abs_pointer_wanted) == -1) {
-        in->abs_pointer_wanted = 0;
-    }
-
     if (in->qmouse) {
         qemu_remove_mouse_event_handler(in->qmouse);
     }
Signature · 1 line
2.1.0
#14 lore raw

Re: [PATCH 3/3] xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

Quoted 87 lines · Owen smith

Windows PV frontend requires absolute mouse values in the range [0, 0x7fff]. Add a feature to not rescale the axes to DisplaySurface size. Also allows Windows PV frontend to connect without a vfb device. Moves the rescaling of axes to a seperate function with additional null-pointer checks.

---
 hw/display/xenfb.c | 52 +++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)
hw/display/xenfb.c +28 -9
index c4375c8..65c373b 100644
@@ -61,6 +61,7 @@ struct common {
 struct XenInput {
     struct common c;
     int abs_pointer_wanted; /* Whether guest supports absolute pointer */
+    int no_abs_rescale;     /* Whether guest wants rescaled abs axes */
     int button_state;       /* Last seen pointer button state */
     int extended;
     QEMUPutKbdEntry *qkbd;
@@ -325,6 +326,25 @@ static void xenfb_key_event(void *opaque, int scancode)
     xenfb_send_key(xenfb, down, scancode2linux[scancode]);
 }
 
+static void xenfb_rescale_mouse(struct XenInput *xenfb, int *dx, int *dy)
+{
+    DisplaySurface *surface;
+    int dw, dh;
+
+    if (xenfb->c.con == NULL) {
+        return;
+    }
+    surface = qemu_console_surface(xenfb->c.con);
+    if (surface == NULL) {
+        return;
+    }
+    dw = surface_width(surface);
+    dh = surface_height(surface);
+
+    *dx = *dx * (dw - 1) / 0x7fff;
+    *dy = *dy * (dh - 1) / 0x7fff;
+}
+
 /*
  * Send a mouse event from the client to the guest OS
  *
@@ -338,18 +358,16 @@ static void xenfb_mouse_event(void *opaque,
 			      int dx, int dy, int dz, int button_state)
 {
     struct XenInput *xenfb = opaque;
-    DisplaySurface *surface = qemu_console_surface(xenfb->c.con);
-    int dw = surface_width(surface);
-    int dh = surface_height(surface);
     int i;
 
-    if (xenfb->abs_pointer_wanted)
-	xenfb_send_position(xenfb,
-			    dx * (dw - 1) / 0x7fff,
-			    dy * (dh - 1) / 0x7fff,
-			    dz);
-    else
+    if (xenfb->abs_pointer_wanted) {
+        if (!xenfb->no_abs_rescale) {
+            xenfb_rescale_mouse(xenfb, &dx, &dy);
+        }
+        xenfb_send_position(xenfb, dx, dy, dz);
+    } else {
 	xenfb_send_motion(xenfb, dx, dy, dz);
+    }
 
     for (i = 0 ; i < 8 ; i++) {
 	int lastDown = xenfb->button_state & (1 << i);
@@ -366,6 +382,7 @@ static void xenfb_mouse_event(void *opaque,
 static int input_init(struct XenDevice *xendev)
 {
     xenstore_write_be_int(xendev, "feature-abs-pointer", 1);
+    xenstore_write_be_int(xendev, "feature-no-abs-rescale", 1);
     return 0;
 }
 
@@ -374,7 +391,17 @@ static int input_initialise(struct XenDevice *xendev)
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
     int rc;
 

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 402

Quoted 10 lines
hw/display/xenfb.c +9 -1
-    if (!in->c.con) {
+    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
+                             &in->abs_pointer_wanted) == -1) {
+        in->abs_pointer_wanted = 0;
+    }
+
+    if (xenstore_read_fe_int(xendev, "request-no-abs-rescale",
+                             &in->no_abs_rescale) == -1) {
+        in->no_abs_rescale = 0;
+    }

I don't think is safe to move checking for "request-abs-pointer" so
early: what if the guest writes request-abs-pointer after initialise but before connect?

Also it would be nice to document this protocol extension somewhere. I do realize that the existing documentation on vfb is somewhat lacking.

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 404

Quoted 1 line
hw/display/xenfb.c +1 -0
+    if (!in->c.con && !in->no_abs_rescale) {

Why this change?

Quoted 18 lines
hw/display/xenfb.c +0 -5
         xen_be_printf(xendev, 1, "ds not set (yet)\n");
         return -1;
     }
@@ -390,11 +417,6 @@ static void input_connected(struct XenDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
 
-    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
-                             &in->abs_pointer_wanted) == -1) {
-        in->abs_pointer_wanted = 0;
-    }
-
     if (in->qmouse) {
         qemu_remove_mouse_event_handler(in->qmouse);
     }
Signature · 1 line
2.1.0
#15 lore raw

Re: [Qemu-devel] [PATCH 3/3] xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

In reply to Owen smith
Quoted 87 lines · Owen smith

Windows PV frontend requires absolute mouse values in the range [0, 0x7fff]. Add a feature to not rescale the axes to DisplaySurface size. Also allows Windows PV frontend to connect without a vfb device. Moves the rescaling of axes to a seperate function with additional null-pointer checks.

---
 hw/display/xenfb.c | 52 +++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)
hw/display/xenfb.c +28 -9
index c4375c8..65c373b 100644
@@ -61,6 +61,7 @@ struct common {
 struct XenInput {
     struct common c;
     int abs_pointer_wanted; /* Whether guest supports absolute pointer */
+    int no_abs_rescale;     /* Whether guest wants rescaled abs axes */
     int button_state;       /* Last seen pointer button state */
     int extended;
     QEMUPutKbdEntry *qkbd;
@@ -325,6 +326,25 @@ static void xenfb_key_event(void *opaque, int scancode)
     xenfb_send_key(xenfb, down, scancode2linux[scancode]);
 }
 
+static void xenfb_rescale_mouse(struct XenInput *xenfb, int *dx, int *dy)
+{
+    DisplaySurface *surface;
+    int dw, dh;
+
+    if (xenfb->c.con == NULL) {
+        return;
+    }
+    surface = qemu_console_surface(xenfb->c.con);
+    if (surface == NULL) {
+        return;
+    }
+    dw = surface_width(surface);
+    dh = surface_height(surface);
+
+    *dx = *dx * (dw - 1) / 0x7fff;
+    *dy = *dy * (dh - 1) / 0x7fff;
+}
+
 /*
  * Send a mouse event from the client to the guest OS
  *
@@ -338,18 +358,16 @@ static void xenfb_mouse_event(void *opaque,
 			      int dx, int dy, int dz, int button_state)
 {
     struct XenInput *xenfb = opaque;
-    DisplaySurface *surface = qemu_console_surface(xenfb->c.con);
-    int dw = surface_width(surface);
-    int dh = surface_height(surface);
     int i;
 
-    if (xenfb->abs_pointer_wanted)
-	xenfb_send_position(xenfb,
-			    dx * (dw - 1) / 0x7fff,
-			    dy * (dh - 1) / 0x7fff,
-			    dz);
-    else
+    if (xenfb->abs_pointer_wanted) {
+        if (!xenfb->no_abs_rescale) {
+            xenfb_rescale_mouse(xenfb, &dx, &dy);
+        }
+        xenfb_send_position(xenfb, dx, dy, dz);
+    } else {
 	xenfb_send_motion(xenfb, dx, dy, dz);
+    }
 
     for (i = 0 ; i < 8 ; i++) {
 	int lastDown = xenfb->button_state & (1 << i);
@@ -366,6 +382,7 @@ static void xenfb_mouse_event(void *opaque,
 static int input_init(struct XenDevice *xendev)
 {
     xenstore_write_be_int(xendev, "feature-abs-pointer", 1);
+    xenstore_write_be_int(xendev, "feature-no-abs-rescale", 1);
     return 0;
 }
 
@@ -374,7 +391,17 @@ static int input_initialise(struct XenDevice *xendev)
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
     int rc;
 

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 402

Quoted 10 lines
hw/display/xenfb.c +9 -1
-    if (!in->c.con) {
+    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
+                             &in->abs_pointer_wanted) == -1) {
+        in->abs_pointer_wanted = 0;
+    }
+
+    if (xenstore_read_fe_int(xendev, "request-no-abs-rescale",
+                             &in->no_abs_rescale) == -1) {
+        in->no_abs_rescale = 0;
+    }

I don't think is safe to move checking for "request-abs-pointer" so
early: what if the guest writes request-abs-pointer after initialise but before connect?

Also it would be nice to document this protocol extension somewhere. I do realize that the existing documentation on vfb is somewhat lacking.

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 404

Quoted 1 line
hw/display/xenfb.c +1 -0
+    if (!in->c.con && !in->no_abs_rescale) {

Why this change?

Quoted 18 lines
hw/display/xenfb.c +0 -5
         xen_be_printf(xendev, 1, "ds not set (yet)\n");
         return -1;
     }
@@ -390,11 +417,6 @@ static void input_connected(struct XenDevice *xendev)
 {
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
 
-    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
-                             &in->abs_pointer_wanted) == -1) {
-        in->abs_pointer_wanted = 0;
-    }
-
     if (in->qmouse) {
         qemu_remove_mouse_event_handler(in->qmouse);
     }
Signature · 1 line
2.1.0
author
#16 lore raw

Re: [PATCH 3/3] xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

Quoted 110 lines

-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 11 September 2014 02:23
To: Owen Smith
Cc: [email protected]; [email protected]; Stefano Stabellini
Subject: Re: [PATCH 3/3] xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

hw/display/xenfb.c static void xenfb_key_event(void *opaque, int

Quoted 26 lines · Owen smith

Windows PV frontend requires absolute mouse values in the range [0, 0x7fff]. Add a feature to not rescale the axes to DisplaySurface size. Also allows Windows PV frontend to connect without a vfb device. Moves the rescaling of axes to a seperate function with additional null-pointer checks.

---
 hw/display/xenfb.c | 52
+++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)
hw/display/xenfb.c index renamed from hw/display/xenfb.c +0 -0

c4375c8..65c373b 100644

hw/display/xenfb.c +0 -0
@@ -61,6 +61,7 @@ struct common {
 struct XenInput {
     struct common c;
     int abs_pointer_wanted; /* Whether guest supports absolute

pointer */

hw/display/xenfb.c +1 -0
+    int no_abs_rescale;     /* Whether guest wants rescaled abs axes */
     int button_state;       /* Last seen pointer button state */
     int extended;
     QEMUPutKbdEntry *qkbd;
@@ -325,6 +326,25 @@ static void xenfb_key_event(void *opaque, int

scancode)

Quoted 39 lines
hw/display/xenfb.c +20 -9
     xenfb_send_key(xenfb, down, scancode2linux[scancode]);  }
 
+static void xenfb_rescale_mouse(struct XenInput *xenfb, int *dx, int
+*dy) {
+    DisplaySurface *surface;
+    int dw, dh;
+
+    if (xenfb->c.con == NULL) {
+        return;
+    }
+    surface = qemu_console_surface(xenfb->c.con);
+    if (surface == NULL) {
+        return;
+    }
+    dw = surface_width(surface);
+    dh = surface_height(surface);
+
+    *dx = *dx * (dw - 1) / 0x7fff;
+    *dy = *dy * (dh - 1) / 0x7fff;
+}
+
 /*
  * Send a mouse event from the client to the guest OS
  *
@@ -338,18 +358,16 @@ static void xenfb_mouse_event(void *opaque,
 			      int dx, int dy, int dz, int button_state)  {
     struct XenInput *xenfb = opaque;
-    DisplaySurface *surface = qemu_console_surface(xenfb->c.con);
-    int dw = surface_width(surface);
-    int dh = surface_height(surface);
     int i;
 
-    if (xenfb->abs_pointer_wanted)
-	xenfb_send_position(xenfb,
-			    dx * (dw - 1) / 0x7fff,
-			    dy * (dh - 1) / 0x7fff,
-			    dz);
-    else
+    if (xenfb->abs_pointer_wanted) {

hw/display/xenfb.c static void xenfb_mouse_event(void *opaque, · line 372

Quoted 10 lines
hw/display/xenfb.c +6 -0
+        if (!xenfb->no_abs_rescale) {
+            xenfb_rescale_mouse(xenfb, &dx, &dy);
+        }
+        xenfb_send_position(xenfb, dx, dy, dz);
+    } else {
 	xenfb_send_motion(xenfb, dx, dy, dz);
+    }
 
     for (i = 0 ; i < 8 ; i++) {
 	int lastDown = xenfb->button_state & (1 << i); @@ -366,6 +382,7

@@

hw/display/xenfb.c static int input_initialise(struct XenDevice

Quoted 8 lines

static void xenfb_mouse_event(void *opaque, static int

input_init(struct XenDevice *xendev)  {
     xenstore_write_be_int(xendev, "feature-abs-pointer", 1);
hw/display/xenfb.c +1 -0
+    xenstore_write_be_int(xendev, "feature-no-abs-rescale", 1);
     return 0;
 }
@@ -374,7 +391,17 @@ static int input_initialise(struct XenDevice

*xendev)

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 402

Quoted 13 lines
hw/display/xenfb.c +9 -1
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
     int rc;
 
-    if (!in->c.con) {
+    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
+                             &in->abs_pointer_wanted) == -1) {
+        in->abs_pointer_wanted = 0;
+    }
+
+    if (xenstore_read_fe_int(xendev, "request-no-abs-rescale",
+                             &in->no_abs_rescale) == -1) {
+        in->no_abs_rescale = 0;
+    }
Quoted 7 lines

I don't think is safe to move checking for "request-abs-pointer" so
early: what if the guest writes request-abs-pointer after initialise but before connect?

Also it would be nice to document this protocol extension somewhere. I do realize that the existing documentation on vfb is somewhat lacking.

I'll change this to read the feature flags during the input_connected for v2. I've spotted that neither feature has anything in the xen header, so I'll include a patch to document this with v2.

Quoted 5 lines

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 404

Quoted 2 lines
hw/display/xenfb.c +1 -0
+    if (!in->c.con && !in->no_abs_rescale) {

Why this change?

Without an additional check here, the frontend would not connect. in->c.con is not initialised without a vfb device. Overloading no_abs_rescale here is not right, I'll add an option that the frontend can set to ignore the absence of the console.

Quoted 20 lines
Quoted 20 lines
hw/display/xenfb.c +0 -5
         xen_be_printf(xendev, 1, "ds not set (yet)\n");
         return -1;
     }
@@ -390,11 +417,6 @@ static void input_connected(struct XenDevice
 *xendev)  {
     struct XenInput *in = container_of(xendev, struct XenInput,
 c.xendev);
 
-    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
-                             &in->abs_pointer_wanted) == -1) {
-        in->abs_pointer_wanted = 0;
-    }
-
     if (in->qmouse) {
         qemu_remove_mouse_event_handler(in->qmouse);
     }

--
2.1.0

author
#17 lore raw

Re: [Qemu-devel] [PATCH 3/3] xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

In reply to Stefano Stabellini
Quoted 110 lines

-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 11 September 2014 02:23
To: Owen Smith
Cc: [email protected]; [email protected]; Stefano Stabellini
Subject: Re: [PATCH 3/3] xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

hw/display/xenfb.c static void xenfb_key_event(void *opaque, int

Quoted 26 lines · Owen smith

Windows PV frontend requires absolute mouse values in the range [0, 0x7fff]. Add a feature to not rescale the axes to DisplaySurface size. Also allows Windows PV frontend to connect without a vfb device. Moves the rescaling of axes to a seperate function with additional null-pointer checks.

---
 hw/display/xenfb.c | 52
+++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)
hw/display/xenfb.c index renamed from hw/display/xenfb.c +0 -0

c4375c8..65c373b 100644

hw/display/xenfb.c +0 -0
@@ -61,6 +61,7 @@ struct common {
 struct XenInput {
     struct common c;
     int abs_pointer_wanted; /* Whether guest supports absolute

pointer */

hw/display/xenfb.c +1 -0
+    int no_abs_rescale;     /* Whether guest wants rescaled abs axes */
     int button_state;       /* Last seen pointer button state */
     int extended;
     QEMUPutKbdEntry *qkbd;
@@ -325,6 +326,25 @@ static void xenfb_key_event(void *opaque, int

scancode)

Quoted 39 lines
hw/display/xenfb.c +20 -9
     xenfb_send_key(xenfb, down, scancode2linux[scancode]);  }
 
+static void xenfb_rescale_mouse(struct XenInput *xenfb, int *dx, int
+*dy) {
+    DisplaySurface *surface;
+    int dw, dh;
+
+    if (xenfb->c.con == NULL) {
+        return;
+    }
+    surface = qemu_console_surface(xenfb->c.con);
+    if (surface == NULL) {
+        return;
+    }
+    dw = surface_width(surface);
+    dh = surface_height(surface);
+
+    *dx = *dx * (dw - 1) / 0x7fff;
+    *dy = *dy * (dh - 1) / 0x7fff;
+}
+
 /*
  * Send a mouse event from the client to the guest OS
  *
@@ -338,18 +358,16 @@ static void xenfb_mouse_event(void *opaque,
 			      int dx, int dy, int dz, int button_state)  {
     struct XenInput *xenfb = opaque;
-    DisplaySurface *surface = qemu_console_surface(xenfb->c.con);
-    int dw = surface_width(surface);
-    int dh = surface_height(surface);
     int i;
 
-    if (xenfb->abs_pointer_wanted)
-	xenfb_send_position(xenfb,
-			    dx * (dw - 1) / 0x7fff,
-			    dy * (dh - 1) / 0x7fff,
-			    dz);
-    else
+    if (xenfb->abs_pointer_wanted) {

hw/display/xenfb.c static void xenfb_mouse_event(void *opaque, · line 372

Quoted 10 lines
hw/display/xenfb.c +6 -0
+        if (!xenfb->no_abs_rescale) {
+            xenfb_rescale_mouse(xenfb, &dx, &dy);
+        }
+        xenfb_send_position(xenfb, dx, dy, dz);
+    } else {
 	xenfb_send_motion(xenfb, dx, dy, dz);
+    }
 
     for (i = 0 ; i < 8 ; i++) {
 	int lastDown = xenfb->button_state & (1 << i); @@ -366,6 +382,7

@@

hw/display/xenfb.c static int input_initialise(struct XenDevice

Quoted 8 lines

static void xenfb_mouse_event(void *opaque, static int

input_init(struct XenDevice *xendev)  {
     xenstore_write_be_int(xendev, "feature-abs-pointer", 1);
hw/display/xenfb.c +1 -0
+    xenstore_write_be_int(xendev, "feature-no-abs-rescale", 1);
     return 0;
 }
@@ -374,7 +391,17 @@ static int input_initialise(struct XenDevice

*xendev)

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 402

Quoted 13 lines
hw/display/xenfb.c +9 -1
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
     int rc;
 
-    if (!in->c.con) {
+    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
+                             &in->abs_pointer_wanted) == -1) {
+        in->abs_pointer_wanted = 0;
+    }
+
+    if (xenstore_read_fe_int(xendev, "request-no-abs-rescale",
+                             &in->no_abs_rescale) == -1) {
+        in->no_abs_rescale = 0;
+    }
Quoted 7 lines

I don't think is safe to move checking for "request-abs-pointer" so
early: what if the guest writes request-abs-pointer after initialise but before connect?

Also it would be nice to document this protocol extension somewhere. I do realize that the existing documentation on vfb is somewhat lacking.

I'll change this to read the feature flags during the input_connected for v2. I've spotted that neither feature has anything in the xen header, so I'll include a patch to document this with v2.

Quoted 5 lines

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 404

Quoted 2 lines
hw/display/xenfb.c +1 -0
+    if (!in->c.con && !in->no_abs_rescale) {

Why this change?

Without an additional check here, the frontend would not connect. in->c.con is not initialised without a vfb device. Overloading no_abs_rescale here is not right, I'll add an option that the frontend can set to ignore the absence of the console.

Quoted 20 lines
Quoted 20 lines
hw/display/xenfb.c +0 -5
         xen_be_printf(xendev, 1, "ds not set (yet)\n");
         return -1;
     }
@@ -390,11 +417,6 @@ static void input_connected(struct XenDevice
 *xendev)  {
     struct XenInput *in = container_of(xendev, struct XenInput,
 c.xendev);
 
-    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
-                             &in->abs_pointer_wanted) == -1) {
-        in->abs_pointer_wanted = 0;
-    }
-
     if (in->qmouse) {
         qemu_remove_mouse_event_handler(in->qmouse);
     }

--
2.1.0

#18 lore raw

Re: [PATCH 3/3] xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

Quoted 113 lines · Owen Smith
Quoted 113 lines

-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 11 September 2014 02:23
To: Owen Smith
Cc: [email protected]; [email protected]; Stefano Stabellini
Subject: Re: [PATCH 3/3] xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

hw/display/xenfb.c static void xenfb_key_event(void *opaque, int

Quoted 26 lines · Owen smith

Windows PV frontend requires absolute mouse values in the range [0, 0x7fff]. Add a feature to not rescale the axes to DisplaySurface size. Also allows Windows PV frontend to connect without a vfb device. Moves the rescaling of axes to a seperate function with additional null-pointer checks.

---
 hw/display/xenfb.c | 52
+++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)
hw/display/xenfb.c index renamed from hw/display/xenfb.c +0 -0

c4375c8..65c373b 100644

hw/display/xenfb.c +0 -0
@@ -61,6 +61,7 @@ struct common {
 struct XenInput {
     struct common c;
     int abs_pointer_wanted; /* Whether guest supports absolute

pointer */

hw/display/xenfb.c +1 -0
+    int no_abs_rescale;     /* Whether guest wants rescaled abs axes */
     int button_state;       /* Last seen pointer button state */
     int extended;
     QEMUPutKbdEntry *qkbd;
@@ -325,6 +326,25 @@ static void xenfb_key_event(void *opaque, int

scancode)

Quoted 39 lines
hw/display/xenfb.c +20 -9
     xenfb_send_key(xenfb, down, scancode2linux[scancode]);  }
 
+static void xenfb_rescale_mouse(struct XenInput *xenfb, int *dx, int
+*dy) {
+    DisplaySurface *surface;
+    int dw, dh;
+
+    if (xenfb->c.con == NULL) {
+        return;
+    }
+    surface = qemu_console_surface(xenfb->c.con);
+    if (surface == NULL) {
+        return;
+    }
+    dw = surface_width(surface);
+    dh = surface_height(surface);
+
+    *dx = *dx * (dw - 1) / 0x7fff;
+    *dy = *dy * (dh - 1) / 0x7fff;
+}
+
 /*
  * Send a mouse event from the client to the guest OS
  *
@@ -338,18 +358,16 @@ static void xenfb_mouse_event(void *opaque,
 			      int dx, int dy, int dz, int button_state)  {
     struct XenInput *xenfb = opaque;
-    DisplaySurface *surface = qemu_console_surface(xenfb->c.con);
-    int dw = surface_width(surface);
-    int dh = surface_height(surface);
     int i;
 
-    if (xenfb->abs_pointer_wanted)
-	xenfb_send_position(xenfb,
-			    dx * (dw - 1) / 0x7fff,
-			    dy * (dh - 1) / 0x7fff,
-			    dz);
-    else
+    if (xenfb->abs_pointer_wanted) {

hw/display/xenfb.c static void xenfb_mouse_event(void *opaque, · line 372

Quoted 10 lines
hw/display/xenfb.c +6 -0
+        if (!xenfb->no_abs_rescale) {
+            xenfb_rescale_mouse(xenfb, &dx, &dy);
+        }
+        xenfb_send_position(xenfb, dx, dy, dz);
+    } else {
 	xenfb_send_motion(xenfb, dx, dy, dz);
+    }
 
     for (i = 0 ; i < 8 ; i++) {
 	int lastDown = xenfb->button_state & (1 << i); @@ -366,6 +382,7

@@

hw/display/xenfb.c static int input_initialise(struct XenDevice

Quoted 8 lines

static void xenfb_mouse_event(void *opaque, static int

input_init(struct XenDevice *xendev)  {
     xenstore_write_be_int(xendev, "feature-abs-pointer", 1);
hw/display/xenfb.c +1 -0
+    xenstore_write_be_int(xendev, "feature-no-abs-rescale", 1);
     return 0;
 }
@@ -374,7 +391,17 @@ static int input_initialise(struct XenDevice

*xendev)

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 402

Quoted 13 lines
hw/display/xenfb.c +9 -1
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
     int rc;
 
-    if (!in->c.con) {
+    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
+                             &in->abs_pointer_wanted) == -1) {
+        in->abs_pointer_wanted = 0;
+    }
+
+    if (xenstore_read_fe_int(xendev, "request-no-abs-rescale",
+                             &in->no_abs_rescale) == -1) {
+        in->no_abs_rescale = 0;
+    }

I don't think is safe to move checking for "request-abs-pointer" so
early: what if the guest writes request-abs-pointer after initialise but before connect?

Quoted 7 lines
Quoted 3 lines

Also it would be nice to document this protocol extension somewhere. I do realize that the existing documentation on vfb is somewhat lacking.

I'll change this to read the feature flags during the input_connected for v2. I've spotted that neither feature has anything in the xen header, so I'll include a patch to document this with v2.

Thanks

Quoted 8 lines
Quoted 4 lines

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 404

Quoted 1 line
hw/display/xenfb.c +1 -0
+    if (!in->c.con && !in->no_abs_rescale) {

Why this change?

Without an additional check here, the frontend would not connect. in->c.con is not initialised without a vfb device. Overloading no_abs_rescale here is not right, I'll add an option that the frontend can set to ignore the absence of the console.

You don't need a new option for that. We wouldn't be introducing any regression by letting vkdb connect without a vfb device. You could just remove the check.

Quoted 22 lines
Quoted 21 lines
Quoted 21 lines
hw/display/xenfb.c +0 -5
         xen_be_printf(xendev, 1, "ds not set (yet)\n");
         return -1;
     }
@@ -390,11 +417,6 @@ static void input_connected(struct XenDevice
 *xendev)  {
     struct XenInput *in = container_of(xendev, struct XenInput,
 c.xendev);
 
-    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
-                             &in->abs_pointer_wanted) == -1) {
-        in->abs_pointer_wanted = 0;
-    }
-
     if (in->qmouse) {
         qemu_remove_mouse_event_handler(in->qmouse);
     }

--
2.1.0

#19 lore raw

Re: [Qemu-devel] [PATCH 3/3] xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

In reply to Owen Smith
Quoted 113 lines · Owen Smith
Quoted 113 lines

-----Original Message-----
From: Stefano Stabellini [mailto:[email protected]]
Sent: 11 September 2014 02:23
To: Owen Smith
Cc: [email protected]; [email protected]; Stefano Stabellini
Subject: Re: [PATCH 3/3] xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

hw/display/xenfb.c static void xenfb_key_event(void *opaque, int

Quoted 26 lines · Owen smith

Windows PV frontend requires absolute mouse values in the range [0, 0x7fff]. Add a feature to not rescale the axes to DisplaySurface size. Also allows Windows PV frontend to connect without a vfb device. Moves the rescaling of axes to a seperate function with additional null-pointer checks.

---
 hw/display/xenfb.c | 52
+++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 37 insertions(+), 15 deletions(-)
hw/display/xenfb.c index renamed from hw/display/xenfb.c +0 -0

c4375c8..65c373b 100644

hw/display/xenfb.c +0 -0
@@ -61,6 +61,7 @@ struct common {
 struct XenInput {
     struct common c;
     int abs_pointer_wanted; /* Whether guest supports absolute

pointer */

hw/display/xenfb.c +1 -0
+    int no_abs_rescale;     /* Whether guest wants rescaled abs axes */
     int button_state;       /* Last seen pointer button state */
     int extended;
     QEMUPutKbdEntry *qkbd;
@@ -325,6 +326,25 @@ static void xenfb_key_event(void *opaque, int

scancode)

Quoted 39 lines
hw/display/xenfb.c +20 -9
     xenfb_send_key(xenfb, down, scancode2linux[scancode]);  }
 
+static void xenfb_rescale_mouse(struct XenInput *xenfb, int *dx, int
+*dy) {
+    DisplaySurface *surface;
+    int dw, dh;
+
+    if (xenfb->c.con == NULL) {
+        return;
+    }
+    surface = qemu_console_surface(xenfb->c.con);
+    if (surface == NULL) {
+        return;
+    }
+    dw = surface_width(surface);
+    dh = surface_height(surface);
+
+    *dx = *dx * (dw - 1) / 0x7fff;
+    *dy = *dy * (dh - 1) / 0x7fff;
+}
+
 /*
  * Send a mouse event from the client to the guest OS
  *
@@ -338,18 +358,16 @@ static void xenfb_mouse_event(void *opaque,
 			      int dx, int dy, int dz, int button_state)  {
     struct XenInput *xenfb = opaque;
-    DisplaySurface *surface = qemu_console_surface(xenfb->c.con);
-    int dw = surface_width(surface);
-    int dh = surface_height(surface);
     int i;
 
-    if (xenfb->abs_pointer_wanted)
-	xenfb_send_position(xenfb,
-			    dx * (dw - 1) / 0x7fff,
-			    dy * (dh - 1) / 0x7fff,
-			    dz);
-    else
+    if (xenfb->abs_pointer_wanted) {

hw/display/xenfb.c static void xenfb_mouse_event(void *opaque, · line 372

Quoted 10 lines
hw/display/xenfb.c +6 -0
+        if (!xenfb->no_abs_rescale) {
+            xenfb_rescale_mouse(xenfb, &dx, &dy);
+        }
+        xenfb_send_position(xenfb, dx, dy, dz);
+    } else {
 	xenfb_send_motion(xenfb, dx, dy, dz);
+    }
 
     for (i = 0 ; i < 8 ; i++) {
 	int lastDown = xenfb->button_state & (1 << i); @@ -366,6 +382,7

@@

hw/display/xenfb.c static int input_initialise(struct XenDevice

Quoted 8 lines

static void xenfb_mouse_event(void *opaque, static int

input_init(struct XenDevice *xendev)  {
     xenstore_write_be_int(xendev, "feature-abs-pointer", 1);
hw/display/xenfb.c +1 -0
+    xenstore_write_be_int(xendev, "feature-no-abs-rescale", 1);
     return 0;
 }
@@ -374,7 +391,17 @@ static int input_initialise(struct XenDevice

*xendev)

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 402

Quoted 13 lines
hw/display/xenfb.c +9 -1
     struct XenInput *in = container_of(xendev, struct XenInput, c.xendev);
     int rc;
 
-    if (!in->c.con) {
+    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
+                             &in->abs_pointer_wanted) == -1) {
+        in->abs_pointer_wanted = 0;
+    }
+
+    if (xenstore_read_fe_int(xendev, "request-no-abs-rescale",
+                             &in->no_abs_rescale) == -1) {
+        in->no_abs_rescale = 0;
+    }

I don't think is safe to move checking for "request-abs-pointer" so
early: what if the guest writes request-abs-pointer after initialise but before connect?

Quoted 7 lines
Quoted 3 lines

Also it would be nice to document this protocol extension somewhere. I do realize that the existing documentation on vfb is somewhat lacking.

I'll change this to read the feature flags during the input_connected for v2. I've spotted that neither feature has anything in the xen header, so I'll include a patch to document this with v2.

Thanks

Quoted 8 lines
Quoted 4 lines

hw/display/xenfb.c static int input_initialise(struct XenDevice *xendev) · line 404

Quoted 1 line
hw/display/xenfb.c +1 -0
+    if (!in->c.con && !in->no_abs_rescale) {

Why this change?

Without an additional check here, the frontend would not connect. in->c.con is not initialised without a vfb device. Overloading no_abs_rescale here is not right, I'll add an option that the frontend can set to ignore the absence of the console.

You don't need a new option for that. We wouldn't be introducing any regression by letting vkdb connect without a vfb device. You could just remove the check.

Quoted 22 lines
Quoted 21 lines
Quoted 21 lines
hw/display/xenfb.c +0 -5
         xen_be_printf(xendev, 1, "ds not set (yet)\n");
         return -1;
     }
@@ -390,11 +417,6 @@ static void input_connected(struct XenDevice
 *xendev)  {
     struct XenInput *in = container_of(xendev, struct XenInput,
 c.xendev);
 
-    if (xenstore_read_fe_int(xendev, "request-abs-pointer",
-                             &in->abs_pointer_wanted) == -1) {
-        in->abs_pointer_wanted = 0;
-    }
-
     if (in->qmouse) {
         qemu_remove_mouse_event_handler(in->qmouse);
     }

--
2.1.0

#20 lore raw

Re: [Qemu-devel] [Xen-devel] [PATCH 3/3] xenfb: Add "feature-no-abs-rescale" for Windows PV frontend

In reply to Stefano Stabellini

On Thu, 2014-09-11 at 02:23 +0100, Stefano Stabellini wrote:

Stefano,

In the context of this patch could you also take a look at Owen's xenfb documentation patches[0], I think you probably know the most about this particular protocol.

Ian.

[0] <[email protected]> and friends.