Skip to contentSkip to conversation

fbdev display driver + misc bits

PATCH In review Gerd Hoffmann 3 participants 14 messages Jun 15, 2010 – Jun 24, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

cover fbdev display driver + misc bits

Hi,

This patch series features the linux fbdev display driver and a few more patches the fbdev driver depends on. Most of the patches have been on the list before. If you wondered what they are good for -- here is the big picture ;)

As usual the individual patches carry more verbose descriptions.

cheers,
Gerd

Gerd Hoffmann (5):
QLIST-ify display change listeners.
add unregister_displaychangelistener
Fix and simplify gui timer logic.
add pflib: PixelFormat conversion library.
linux fbdev display driver.

 Makefile.objs    |    2 +
 console.h        |   82 +++--
 fbdev.c          |  931 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xenfb.c       |    2 +-
 linux-keynames.h |  386 ++++++++++++++++++++++
 monitor.c        |   14 +
 pflib.c          |  213 +++++++++++++
 pflib.h          |   20 ++
 qemu-options.hx  |   10 +
 sysemu.h         |    1 +
 vl.c             |   55 ++--
 11 files changed, 1648 insertions(+), 68 deletions(-)
 create mode 100644 fbdev.c
 create mode 100644 linux-keynames.h
 create mode 100644 pflib.c
 create mode 100644 pflib.h
#2 lore raw

PATCH 2/5 add unregister_displaychangelistener

---
 console.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
console.h +5 -0
index 2263971..3f77661 100644
@@ -228,6 +228,11 @@ static inline void register_displaychangelistener(DisplayState *ds, DisplayChang
     QLIST_INSERT_HEAD(&ds->listeners, dcl, next);
 }
 
+static inline void unregister_displaychangelistener(DisplayChangeListener *dcl)
+{
+    QLIST_REMOVE(dcl, next);
+}
+
 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
 {
     struct DisplayChangeListener *dcl;
Signature · 1 line
1.6.5.2
#1 lore raw

PATCH 1/5 QLIST-ify display change listeners.

In reply to Gerd Hoffmann
---
 console.h  |   72 +++++++++++++++++++++++++++++++----------------------------
 hw/xenfb.c |    2 +-
 vl.c       |    9 ++-----
 3 files changed, 42 insertions(+), 41 deletions(-)
console.h +38 -34
index aafb031..2263971 100644
@@ -162,7 +162,7 @@ struct DisplayChangeListener {
                      int w, int h, uint32_t c);
     void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
 
-    struct DisplayChangeListener *next;
+    QLIST_ENTRY(DisplayChangeListener) next;
 };
 
 struct DisplayAllocator {
@@ -177,7 +177,7 @@ struct DisplayState {
     struct QEMUTimer *gui_timer;
 
     struct DisplayAllocator* allocator;
-    struct DisplayChangeListener* listeners;
+    QLIST_HEAD(, DisplayChangeListener) listeners;
 
     void (*mouse_set)(int x, int y, int on);
     void (*cursor_define)(QEMUCursor *cursor);
@@ -225,72 +225,76 @@ static inline int is_buffer_shared(DisplaySurface *surface)
 
 static inline void register_displaychangelistener(DisplayState *ds, DisplayChangeListener *dcl)
 {
-    dcl->next = ds->listeners;
-    ds->listeners = dcl;
+    QLIST_INSERT_HEAD(&ds->listeners, dcl, next);
 }
 
 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
 {
-    struct DisplayChangeListener *dcl = s->listeners;
-    while (dcl != NULL) {
+    struct DisplayChangeListener *dcl;
+    QLIST_FOREACH(dcl, &s->listeners, next) {
         dcl->dpy_update(s, x, y, w, h);
-        dcl = dcl->next;
     }
 }
 
 static inline void dpy_resize(DisplayState *s)
 {
-    struct DisplayChangeListener *dcl = s->listeners;
-    while (dcl != NULL) {
+    struct DisplayChangeListener *dcl;
+    QLIST_FOREACH(dcl, &s->listeners, next) {
         dcl->dpy_resize(s);
-        dcl = dcl->next;
     }
 }
 
 static inline void dpy_setdata(DisplayState *s)
 {
-    struct DisplayChangeListener *dcl = s->listeners;
-    while (dcl != NULL) {
-        if (dcl->dpy_setdata) dcl->dpy_setdata(s);
-        dcl = dcl->next;
+    struct DisplayChangeListener *dcl;
+    QLIST_FOREACH(dcl, &s->listeners, next) {
+        if (dcl->dpy_setdata) {
+            dcl->dpy_setdata(s);
+        }
     }
 }
 
 static inline void dpy_refresh(DisplayState *s)
 {
-    struct DisplayChangeListener *dcl = s->listeners;
-    while (dcl != NULL) {
-        if (dcl->dpy_refresh) dcl->dpy_refresh(s);
-        dcl = dcl->next;
+    struct DisplayChangeListener *dcl;
+    QLIST_FOREACH(dcl, &s->listeners, next) {
+        if (dcl->dpy_refresh) {
+            dcl->dpy_refresh(s);
+        }
     }
 }
 
 static inline void dpy_copy(struct DisplayState *s, int src_x, int src_y,
-                             int dst_x, int dst_y, int w, int h) {
-    struct DisplayChangeListener *dcl = s->listeners;
-    while (dcl != NULL) {
-        if (dcl->dpy_copy)
+                             int dst_x, int dst_y, int w, int h)
+{
+    struct DisplayChangeListener *dcl;
+    QLIST_FOREACH(dcl, &s->listeners, next) {
+        if (dcl->dpy_copy) {
             dcl->dpy_copy(s, src_x, src_y, dst_x, dst_y, w, h);
-        else /* TODO */
+        } else { /* TODO */
             dcl->dpy_update(s, dst_x, dst_y, w, h);
-        dcl = dcl->next;
+        }
     }
 }
 
 static inline void dpy_fill(struct DisplayState *s, int x, int y,
-                             int w, int h, uint32_t c) {
-    struct DisplayChangeListener *dcl = s->listeners;
-    while (dcl != NULL) {
-        if (dcl->dpy_fill) dcl->dpy_fill(s, x, y, w, h, c);
-        dcl = dcl->next;
+                             int w, int h, uint32_t c)
+{
+    struct DisplayChangeListener *dcl;
+    QLIST_FOREACH(dcl, &s->listeners, next) {
+        if (dcl->dpy_fill) {
+            dcl->dpy_fill(s, x, y, w, h, c);
+        }
     }
 }
 
-static inline void dpy_cursor(struct DisplayState *s, int x, int y) {
-    struct DisplayChangeListener *dcl = s->listeners;
-    while (dcl != NULL) {
-        if (dcl->dpy_text_cursor) dcl->dpy_text_cursor(s, x, y);
-        dcl = dcl->next;
+static inline void dpy_cursor(struct DisplayState *s, int x, int y)
+{
+    struct DisplayChangeListener *dcl;
+    QLIST_FOREACH(dcl, &s->listeners, next) {
+        if (dcl->dpy_text_cursor) {
+            dcl->dpy_text_cursor(s, x, y);
+        }
     }
 }
 
hw/xenfb.c +1 -1
index da5297b..5076beb 100644
@@ -706,7 +706,7 @@ static void xenfb_update(void *opaque)
 	if (xenfb_queue_full(xenfb))
 	    return;
 
-        for (l = xenfb->c.ds->listeners; l != NULL; l = l->next) {
+        QLIST_FOREACH(l, &xenfb->c.ds->listeners, next) {
             if (l->idle)
                 continue;
             idle = 0;
vl.c +3 -6
index e5e43b3..34aa388 100644
@@ -1045,16 +1045,15 @@ static void gui_update(void *opaque)
 {
     uint64_t interval = GUI_REFRESH_INTERVAL;
     DisplayState *ds = opaque;
-    DisplayChangeListener *dcl = ds->listeners;
+    DisplayChangeListener *dcl;
 
     qemu_flush_coalesced_mmio_buffer();
     dpy_refresh(ds);
 
-    while (dcl != NULL) {
+    QLIST_FOREACH(dcl, &ds->listeners, next) {
         if (dcl->gui_timer_interval &&
             dcl->gui_timer_interval < interval)
             interval = dcl->gui_timer_interval;
-        dcl = dcl->next;
     }
     qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
 }
@@ -2925,14 +2924,12 @@ int main(int argc, char **argv, char **envp)
     }
     dpy_resize(ds);
 
-    dcl = ds->listeners;
-    while (dcl != NULL) {
+    QLIST_FOREACH(dcl, &ds->listeners, next) {
         if (dcl->dpy_refresh != NULL) {
             ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
             qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock));
             break;
         }
-        dcl = dcl->next;
     }
 
     if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) {
Signature · 1 line
1.6.5.2
#3 lore raw

PATCH 3/5 Fix and simplify gui timer logic.

In reply to Gerd Hoffmann

Kill the nographic and gui timers. Add a single periodic_timer to replace them. We have a timer running anyway, so so the gui/nographic separation is pretty pointless, we can just drive everything we need from the single periodic timer.

Don't allocate the timer twice in case we have two display listeners.

---
 console.h |    1 -
 vl.c      |   40 ++++++++++++----------------------------
 2 files changed, 12 insertions(+), 29 deletions(-)
console.h +0 -1
index 3f77661..f866987 100644
@@ -174,7 +174,6 @@ struct DisplayAllocator {
 struct DisplayState {
     struct DisplaySurface *surface;
     void *opaque;
-    struct QEMUTimer *gui_timer;
 
     struct DisplayAllocator* allocator;
     QLIST_HEAD(, DisplayChangeListener) listeners;
vl.c +12 -28
index 34aa388..8fc63c7 100644
@@ -227,7 +227,7 @@ int nb_numa_nodes;
 uint64_t node_mem[MAX_NODES];
 uint64_t node_cpumask[MAX_NODES];
 
-static QEMUTimer *nographic_timer;
+static QEMUTimer *periodic_timer;
 
 uint8_t qemu_uuid[16];
 
@@ -1041,29 +1041,24 @@ static QEMUMachine *find_default_machine(void)
 /***********************************************************/
 /* main execution loop */
 
-static void gui_update(void *opaque)
+static void periodic_update(void *opaque)
 {
     uint64_t interval = GUI_REFRESH_INTERVAL;
     DisplayState *ds = opaque;
     DisplayChangeListener *dcl;
 
     qemu_flush_coalesced_mmio_buffer();
-    dpy_refresh(ds);
 
-    QLIST_FOREACH(dcl, &ds->listeners, next) {
-        if (dcl->gui_timer_interval &&
-            dcl->gui_timer_interval < interval)
-            interval = dcl->gui_timer_interval;
+    if (ds != NULL && !QLIST_EMPTY(&ds->listeners)) {
+        dpy_refresh(ds);
+        QLIST_FOREACH(dcl, &ds->listeners, next) {
+            if (dcl->gui_timer_interval &&
+                dcl->gui_timer_interval < interval)
+                interval = dcl->gui_timer_interval;
+        }
     }
-    qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
-}
-
-static void nographic_update(void *opaque)
-{
-    uint64_t interval = GUI_REFRESH_INTERVAL;
 
-    qemu_flush_coalesced_mmio_buffer();
-    qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
+    qemu_mod_timer(periodic_timer, interval + qemu_get_clock(rt_clock));
 }
 
 struct vm_change_state_entry {
@@ -1807,7 +1802,6 @@ int main(int argc, char **argv, char **envp)
     const char *kernel_filename, *kernel_cmdline;
     char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
     DisplayState *ds;
-    DisplayChangeListener *dcl;
     int cyls, heads, secs, translation;
     QemuOpts *hda_opts = NULL, *opts;
     int optind;
@@ -2924,18 +2918,8 @@ int main(int argc, char **argv, char **envp)
     }
     dpy_resize(ds);
 
-    QLIST_FOREACH(dcl, &ds->listeners, next) {
-        if (dcl->dpy_refresh != NULL) {
-            ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
-            qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock));
-            break;
-        }
-    }
-
-    if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) {
-        nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
-        qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
-    }
+    periodic_timer = qemu_new_timer(rt_clock, periodic_update, ds);
+    qemu_mod_timer(periodic_timer, qemu_get_clock(rt_clock));
 
     text_consoles_set_display(ds);
 
Signature · 1 line
1.6.5.2
#4 lore raw

PATCH 4/5 add pflib: PixelFormat conversion library.

In reply to Gerd Hoffmann
---
 Makefile.objs |    1 +
 pflib.c       |  213 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 pflib.h       |   20 ++++++
 3 files changed, 234 insertions(+), 0 deletions(-)
 create mode 100644 pflib.c
 create mode 100644 pflib.h
Makefile.objs +1 -0
index 2bfb6d1..acc6179 100644
@@ -83,6 +83,7 @@ common-obj-y += qemu-char.o savevm.o #aio.o
 common-obj-y += msmouse.o ps2.o
 common-obj-y += qdev.o qdev-properties.o
 common-obj-y += block-migration.o
+common-obj-y += pflib.o
 
 common-obj-$(CONFIG_BRLAPI) += baum.o
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
pflib.c new file +213 -0

213 lines not on this page · raw message

pflib.h new file +20 -0
new file mode 100644
index 0000000..b70c313
@@ -0,0 +1,20 @@
+#ifndef __QEMU_PFLIB_H
+#define __QEMU_PFLIB_H
+
+/*
+ * PixelFormat conversion library.
+ *
+ * Author: Gerd Hoffmann <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+typedef struct QemuPfConv QemuPfConv;
+
+QemuPfConv *qemu_pf_conv_get(PixelFormat *dst, PixelFormat *src);
+void qemu_pf_conv_run(QemuPfConv *conv, void *dst, void *src, uint32_t cnt);
+void qemu_pf_conv_put(QemuPfConv *conv);
+
+#endif
Signature · 1 line
1.6.5.2
#5 lore raw

PATCH 5/5 linux fbdev display driver.

In reply to Gerd Hoffmann

Display works, requires truecolor framebuffer with 16 or 32 bpp on the host. 32bpp is recommended. The framebuffer is used as-is, qemu doesn't try to switch modes. With LCD displays mode switching is pretty pointless IMHO, also it wouldn't work anyway with the most common fbdev drivers (vesafb, KMS). Guest display is centered on the host screen.

Mouse works, uses /dev/input/mice.

Keyboard works. Guest screen has whatever keymap you load inside the guest. Text windows (monitor, serial, ...) have a simple en-us keymap. Good enougth to type monitor commands. Not goot enougth to work seriously on a serial terminal. But the qemu terminal emulation isn't good enougth for that anyway ;)

Hot keys:

  Ctrl-Alt-F<nr>  -> host console switching.
  Ctrl-Alt-<nr>   -> qemu console switching.
  Ctrl-Alt-ESC    -> exit qemu.

Special feature: Sane console switching. Switching away stops screen updates. Switching back redraws the screen. When started from the linux console qemu uses the vt you've started it from (requires just read/write access to /dev/fb0). When starting from somewhere else qemu tries to open a unused virtual terminal and switch to it (usually requires root privileges to open /dev/tty<nr>).

For some strange reason console switching from X11 to qemu doesn't work. Anything else (including X11 -> text console -> qemu) works fine. To be investigated ...

Can be enabled/disabled via monitor, use "change fbdev [ on | off ]"

Cc Julian Pidancet <[email protected]>
Cc Stefano Stabellini <[email protected]>
---
 Makefile.objs    |    1 +
 console.h        |    4 +
 fbdev.c          |  931 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 linux-keynames.h |  386 ++++++++++++++++++++++
 monitor.c        |   14 +
 qemu-options.hx  |   10 +
 sysemu.h         |    1 +
 vl.c             |   10 +
 8 files changed, 1357 insertions(+), 0 deletions(-)
 create mode 100644 fbdev.c
 create mode 100644 linux-keynames.h
Makefile.objs +1 -0
index acc6179..be6a03c 100644
@@ -106,6 +106,7 @@ common-obj-y += $(addprefix audio/, $(audio-obj-y))
 common-obj-y += keymaps.o
 common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
 common-obj-$(CONFIG_CURSES) += curses.o
+common-obj-$(CONFIG_LINUX) += fbdev.o
 common-obj-y += vnc.o acl.o d3des.o
 common-obj-y += vnc-encoding-zlib.o vnc-encoding-hextile.o
 common-obj-y += vnc-encoding-tight.o
console.h +4 -0
index f866987..124a22b 100644
@@ -369,6 +369,10 @@ void qemu_console_copy(DisplayState *ds, int src_x, int src_y,
 /* sdl.c */
 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
 
+/* fbdev.c */
+void fbdev_display_init(DisplayState *ds, const char *device);
+void fbdev_display_uninit(void);
+
 /* cocoa.m */
 void cocoa_display_init(DisplayState *ds, int full_screen);
 
fbdev.c new file +931 -0

931 lines not on this page · raw message

linux-keynames.h new file +386 -0

386 lines not on this page · raw message

monitor.c +14 -0
index 05a7ed1..7442f1a 100644
@@ -959,6 +959,18 @@ static int do_change_vnc(Monitor *mon, const char *target, const char *arg)
     return 0;
 }
 
+static int do_change_fbdev(Monitor *mon, const char *target)
+{
+#ifdef CONFIG_LINUX
+    if (strcmp(target, "on") == 0) {
+        fbdev_display_init(get_displaystate(), NULL);
+    } else {
+        fbdev_display_uninit();
+    }
+    return 0;
+#endif
+}
+
 /**
  * do_change(): Change a removable medium, or VNC configuration
  */
@@ -971,6 +983,8 @@ static int do_change(Monitor *mon, const QDict *qdict, QObject **ret_data)
 
     if (strcmp(device, "vnc") == 0) {
         ret = do_change_vnc(mon, target, arg);
+    } else if (strcmp(device, "fbdev") == 0) {
+        ret = do_change_fbdev(mon, target);
     } else {
         ret = do_change_block(mon, device, target, arg);
     }
qemu-options.hx +10 -0
index a6928b7..8224a32 100644
@@ -667,6 +667,16 @@ STEXI
 Enable SDL.
 ETEXI
 
+#ifdef CONFIG_LINUX
+DEF("fbdev", 0, QEMU_OPTION_fbdev,
+    "-fbdev          enable fbdev\n", QEMU_ARCH_ALL)
+#endif
+STEXI
+@item -fbdev
+@findex -fbdev
+Enable fbdev (linux framebuffer).
+ETEXI
+
 DEF("portrait", 0, QEMU_OPTION_portrait,
     "-portrait       rotate graphical output 90 deg left (only PXA LCD)\n",
     QEMU_ARCH_ALL)
sysemu.h +1 -0
index c758243..e40fefd 100644
@@ -95,6 +95,7 @@ typedef enum DisplayType
     DT_CURSES,
     DT_SDL,
     DT_VNC,
+    DT_FBDEV,
     DT_NOGRAPHIC,
 } DisplayType;
 
vl.c +10 -0
index 8fc63c7..39e43fa 100644
@@ -2400,6 +2400,11 @@ int main(int argc, char **argv, char **envp)
                 display_type = DT_SDL;
                 break;
 #endif
+#ifdef CONFIG_LINUX
+            case QEMU_OPTION_fbdev:
+                display_type = DT_FBDEV;
+                break;
+#endif
             case QEMU_OPTION_pidfile:
                 pid_file = optarg;
                 break;
@@ -2895,6 +2900,11 @@ int main(int argc, char **argv, char **envp)
         curses_display_init(ds, full_screen);
         break;
 #endif
+#if defined(CONFIG_LINUX)
+    case DT_FBDEV:
+        fbdev_display_init(ds, NULL);
+        break;
+#endif
 #if defined(CONFIG_SDL)
     case DT_SDL:
         sdl_display_init(ds, full_screen, no_frame);
Signature · 1 line
1.6.5.2
#6 lore raw

[Qemu-devel] Re: [PATCH 5/5] linux fbdev display driver.

Quoted 27 lines · Gerd Hoffmann

Display works, requires truecolor framebuffer with 16 or 32 bpp on the host. 32bpp is recommended. The framebuffer is used as-is, qemu doesn't try to switch modes. With LCD displays mode switching is pretty pointless IMHO, also it wouldn't work anyway with the most common fbdev drivers (vesafb, KMS). Guest display is centered on the host screen.

Mouse works, uses /dev/input/mice.

Keyboard works. Guest screen has whatever keymap you load inside the guest. Text windows (monitor, serial, ...) have a simple en-us keymap. Good enougth to type monitor commands. Not goot enougth to work seriously on a serial terminal. But the qemu terminal emulation isn't good enougth for that anyway ;)

Hot keys:

  Ctrl-Alt-F<nr>  -> host console switching.
  Ctrl-Alt-<nr>   -> qemu console switching.
  Ctrl-Alt-ESC    -> exit qemu.

Special feature: Sane console switching. Switching away stops screen updates. Switching back redraws the screen. When started from the linux console qemu uses the vt you've started it from (requires just read/write access to /dev/fb0). When starting from somewhere else qemu tries to open a unused virtual terminal and switch to it (usually requires root privileges to open /dev/tty<nr>).

Quoted 5 lines

For some strange reason console switching from X11 to qemu doesn't work. Anything else (including X11 -> text console -> qemu) works fine. To be investigated ...

Can be enabled/disabled via monitor, use "change fbdev [ on | off ]"

the patch still doesn't use the display allocator interface, but it shouldn't be difficult to implement support for it on top of this patch, so it is fine by me.

#7 lore raw

[Qemu-devel] Re: [PATCH 5/5] linux fbdev display driver.

Quoted 5 lines · Stefano Stabellini

the patch still doesn't use the display allocator interface, but it shouldn't be difficult to implement support for it on top of this patch, so it is fine by me.

This patch adds display allocator support in the fbdev driver.
This way we avoid memcpying when the guest surface is compatible with the physical surface.

fbdev.c +100 -41
index 54f2381..83104c0 100644
@@ -69,11 +69,10 @@ static int fb_switch_state = FB_ACTIVE;
 static DisplayChangeListener      *dcl;
 static QemuPfConv                 *conv;
 static PixelFormat                fbpf;
-static int                        resize_screen;
-static int                        redraw_screen;
 static int                        cx, cy, cw, ch;
 static int                        debug = 0;
 static Notifier                   exit_notifier;
+uint8_t                           *guest_surface;
 
 /* fwd decls */
 static int fbdev_activate_vt(int tty, int vtno, bool wait);
@@ -786,10 +785,10 @@ static void fbdev_render(DisplayState *ds, int x, int y, int w, int h)
     uint8_t *src;
     int line;
 
-    if (!conv)
+    if (!conv || !guest_surface)
         return;
 
-    src = ds_get_data(ds) + y * ds_get_linesize(ds)
+    src = guest_surface + y * ds_get_linesize(ds)
         + x * ds_get_bytes_per_pixel(ds);
     dst = fb_mem + y * fb_fix.line_length
         + x * fbpf.bytes_per_pixel;
@@ -819,46 +818,50 @@ static void fbdev_update(DisplayState *ds, int x, int y, int w, int h)
     if (fb_switch_state != FB_ACTIVE)
         return;
 
-    if (resize_screen) {
-        if (debug)
-            fprintf(stderr, "%s: handle resize\n", __FUNCTION__);
-        resize_screen = 0;
-        cx = 0; cy = 0;
-        cw = ds_get_width(ds);
-        ch = ds_get_height(ds);
-        if (ds_get_width(ds) < fb_var.xres) {
-            cx = (fb_var.xres - ds_get_width(ds)) / 2;
-        }
-        if (ds_get_height(ds) < fb_var.yres) {
-            cy = (fb_var.yres - ds_get_height(ds)) / 2;
-        }
+    if (guest_surface != NULL) {
+        fbdev_render(ds, x, y, w, h);
+    }
+}
 
-        if (conv) {
-            qemu_pf_conv_put(conv);
-        }
-        conv = qemu_pf_conv_get(&fbpf, &ds->surface->pf);
-        if (conv == NULL) {
-            fprintf(stderr, "fbdev: unsupported PixelFormat conversion\n");
-        }
+static void fbdev_setdata(DisplayState *ds)
+{
+    if (conv) {
+        qemu_pf_conv_put(conv);
     }
 
-    if (redraw_screen) {
-        if (debug)
-            fprintf(stderr, "%s: handle redraw\n", __FUNCTION__);
-        redraw_screen = 0;
-        fbdev_cls();
-        x = 0; y = 0; w = ds_get_width(ds); h = ds_get_height(ds);
+    conv = qemu_pf_conv_get(&fbpf, &ds->surface->pf);
+    if (conv == NULL) {
+        fprintf(stderr, "fbdev: unsupported PixelFormat conversion\n");
     }
 
-    fbdev_render(ds, x, y, w, h);
+    guest_surface = ds_get_data(ds);
 }
 
 static void fbdev_resize(DisplayState *ds)
 {
-    if (debug)
-        fprintf(stderr, "%s: request resize+redraw\n", __FUNCTION__);
-    resize_screen++;
-    redraw_screen++;
+    int is_video_ptr;
+
+    if (fb_switch_state == FB_ACTIVE) {
+        fbdev_cls();
+    }
+
+    is_video_ptr = ds_get_data(ds) >= fb_mem + fb_mem_offset &&
+                   ds_get_data(ds) < fb_mem + fb_fix.smem_len + fb_mem_offset;
+
+    if (ds_get_bits_per_pixel(ds) != fbpf.bits_per_pixel ||
+        ds_get_linesize(ds) != fb_fix.line_length ||
+        !is_video_ptr) {
+        cx = 0; cy = 0;
+        if (ds_get_width(ds) < fb_var.xres) {
+            cx = (fb_var.xres - ds_get_width(ds)) / 2;
+        }
+        if (ds_get_height(ds) < fb_var.yres) {
+            cy = (fb_var.yres - ds_get_height(ds)) / 2;
+        }
+        fbdev_setdata(ds);
+    } else {
+        guest_surface = NULL;
+    }
 }
 
 static void fbdev_refresh(DisplayState *ds)
@@ -866,21 +869,17 @@ static void fbdev_refresh(DisplayState *ds)
     switch (fb_switch_state) {
     case FB_REL_REQ:
         fbdev_switch_release();
+        vga_hw_invalidate();
     case FB_INACTIVE:
         return;
     case FB_ACQ_REQ:
         fbdev_switch_acquire();
-        redraw_screen++;
-        if (debug)
-            fprintf(stderr, "%s: request redraw\n", __FUNCTION__);
+        vga_hw_invalidate();
     case FB_ACTIVE:
         break;
     }
 
     vga_hw_update();
-    if (redraw_screen) {
-        fbdev_update(ds, 0, 0, 0, 0);
-    }
 }
 
 static void fbdev_exit_notifier(Notifier *notifier)
@@ -888,8 +887,58 @@ static void fbdev_exit_notifier(Notifier *notifier)
     fbdev_cleanup();
 }
 
+static DisplaySurface *fbdev_create_displaysurface(int width, int height)
+{
+    DisplaySurface *surface = qemu_mallocz(sizeof (DisplaySurface));
+
+    surface->width = width;
+    surface->height = height;
+
+    surface->pf = fbpf;
+    surface->linesize = fb_fix.line_length;
+
+    if (fb_switch_state == FB_INACTIVE) {
+        surface->flags = QEMU_ALLOCATED_FLAG;
+        surface->data = qemu_mallocz(surface->linesize * surface->height);
+    } else {
+        surface->flags = QEMU_REALPIXELS_FLAG;
+        surface->data = fb_mem;
+
+        if (width < fb_var.xres)
+            surface->data += ((fb_var.xres - width) / 2) * fbpf.bytes_per_pixel;
+        if (height < fb_var.yres)
+            surface->data += ((fb_var.yres - height) / 2) * fb_fix.line_length;
+    }
+
+    return surface;
+}
+
+static void fbdev_free_displaysurface(DisplaySurface *surface)
+{
+    if (surface == NULL)
+        return;
+
+    if (surface->flags & QEMU_ALLOCATED_FLAG) {
+        qemu_free(surface->data);
+    }
+
+    surface->data = NULL;
+
+    qemu_free(surface);
+}
+
+static DisplaySurface *fbdev_resize_displaysurface(DisplaySurface *surface,
+                                                   int width,
+                                                   int height)
+{
+    fbdev_free_displaysurface(surface);
+    return fbdev_create_displaysurface(width, height);
+}
+
 void fbdev_display_init(DisplayState *ds, const char *device)
 {
+    DisplayAllocator *da;
+
     if (dcl != NULL) {
         if (debug)
             fprintf(stderr, "%s: already active\n", __FUNCTION__);
@@ -910,7 +959,17 @@ void fbdev_display_init(DisplayState *ds, const char *device)
     dcl->dpy_update  = fbdev_update;
     dcl->dpy_resize  = fbdev_resize;
     dcl->dpy_refresh = fbdev_refresh;
+    dcl->dpy_setdata = fbdev_setdata;
     register_displaychangelistener(ds, dcl);
+
+    da = qemu_mallocz(sizeof (DisplayAllocator));
+    da->create_displaysurface = fbdev_create_displaysurface;
+    da->resize_displaysurface = fbdev_resize_displaysurface;
+    da->free_displaysurface = fbdev_free_displaysurface;
+
+    if (register_displayallocator(ds, da) == da) {
+        dpy_resize(ds);
+    }
 }
 
 void fbdev_display_uninit(void)
Signature · 1 line
Julian Pidancet <[email protected]>
#8 lore raw

[Qemu-devel] Re: [PATCH 5/5] linux fbdev display driver.

Hi,

Review

Quoted 10 lines
(quoted diff) +10 -0
+static void fbdev_free_displaysurface(DisplaySurface *surface)
+{
+    if (surface == NULL)
+        return;
+
+    if (surface->flags&  QEMU_ALLOCATED_FLAG) {
+        qemu_free(surface->data);
+    }
+
+    surface->data = NULL;

This is pretty pointless ...

Quoted 1 line

+ qemu_free(surface);

... as you free surface anyway ;)

Quoted 5 lines
(quoted diff) +1 -0
@@ -910,7 +959,17 @@ void fbdev_display_init(DisplayState *ds, const char *device)
      dcl->dpy_update  = fbdev_update;
      dcl->dpy_resize  = fbdev_resize;
      dcl->dpy_refresh = fbdev_refresh;
+    dcl->dpy_setdata = fbdev_setdata;

Review void fbdev_display_init(DisplayState *ds, const char *device) · line 972

Quoted 10 lines
(quoted diff) +9 -0
      register_displaychangelistener(ds, dcl);
+
+    da = qemu_mallocz(sizeof (DisplayAllocator));
+    da->create_displaysurface = fbdev_create_displaysurface;
+    da->resize_displaysurface = fbdev_resize_displaysurface;
+    da->free_displaysurface = fbdev_free_displaysurface;
+
+    if (register_displayallocator(ds, da) == da) {
+        dpy_resize(ds);
+    }

You register the display allocator, but don't unregister in fbdev_display_uninit().

You are just lucky that fbdev_cleanup() forgets to unmap the framebuffer.

Apply the attached fix, start qemu with vnc, then do "change fbdev on" and "change fbdev off" in the monitor and watch qemu segfault.

Also after "change fbdev on" the guest screen isn't rendered correctly.

cheers,
Gerd

Quoted 1 line

From 685849ae48eaef7927b90e012fb6afb4494052d0 Mon Sep 17 00:00:00 2001

From: Gerd Hoffmann <[email protected]>
Date: Thu, 17 Jun 2010 12:32:53 +0200
Subject: [PATCH] fbdev: unmap framebuffer on cleanup

---
 fbdev.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
fbdev.c +4 -0
index 6623a4f..1a95ede 100644
@@ -518,6 +518,10 @@ static void fbdev_cleanup(void)
         fprintf(stderr, "%s\n", __FUNCTION__);
 
     /* restore console */
+    if (fb_mem != NULL) {
+        munmap(fb_mem, fb_fix.smem_len+fb_mem_offset);
+        fb_mem = NULL;
+    }
     if (fb != -1) {
         if (ioctl(fb,FBIOPUT_VSCREENINFO, &fb_ovar) < 0)
             perror("ioctl FBIOPUT_VSCREENINFO");
Signature · 1 line
1.6.5.2
#9 lore raw

[Qemu-devel] Re: [PATCH 5/5] linux fbdev display driver.

Quoted 7 lines · Gerd Hoffmann
   Hi,

You register the display allocator, but don't unregister in fbdev_display_uninit().

You are just lucky that fbdev_cleanup() forgets to unmap the framebuffer.

Quoted 8 lines

Apply the attached fix, start qemu with vnc, then do "change fbdev on" and "change fbdev off" in the monitor and watch qemu segfault.

Also after "change fbdev on" the guest screen isn't rendered correctly.

cheers,
Gerd

Hi,

Thanks for spotting these errors. Here is a respin of my patch to address you concerns. (The munmap call is included).

Cheers,

Julian

console.c +10 -0
index 698bc10..12ce215 100644
@@ -1376,6 +1376,16 @@ DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *
     return ds->allocator;
 }
 
+void unregister_displayallocator(DisplayState *ds)
+{
+    if (ds->allocator != &default_allocator) {
+        ds->allocator->free_displaysurface(ds->surface);
+        ds->surface = defaultallocator_create_displaysurface(ds_get_width(ds),
+                                                             ds_get_height(ds));
+        ds->allocator = &default_allocator;
+    }
+}
+
 DisplayState *graphic_console_init(vga_hw_update_ptr update,
                                    vga_hw_invalidate_ptr invalidate,
                                    vga_hw_screen_dump_ptr screen_dump,
console.h +2 -1
index 124a22b..40bd927 100644
@@ -192,6 +192,7 @@ PixelFormat qemu_different_endianness_pixelformat(int bpp);
 PixelFormat qemu_default_pixelformat(int bpp);
 
 DisplayAllocator *register_displayallocator(DisplayState *ds, DisplayAllocator *da);
+void unregister_displayallocator(DisplayState *ds);
 
 static inline DisplaySurface* qemu_create_displaysurface(DisplayState *ds, int width, int height)
 {
@@ -371,7 +372,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
 
 /* fbdev.c */
 void fbdev_display_init(DisplayState *ds, const char *device);
-void fbdev_display_uninit(void);
+void fbdev_display_uninit(DisplayState *ds);
 
 /* cocoa.m */
 void cocoa_display_init(DisplayState *ds, int full_screen);
fbdev.c +105 -43

228 lines not on this page · raw message

monitor.c +1 -1
index 7442f1a..5d6efb4 100644
@@ -965,7 +965,7 @@ static int do_change_fbdev(Monitor *mon, const char *target)
     if (strcmp(target, "on") == 0) {
         fbdev_display_init(get_displaystate(), NULL);
     } else {
-        fbdev_display_uninit();
+        fbdev_display_uninit(get_displaystate());
     }
     return 0;
 #endif
#10 lore raw

Re: [Qemu-devel] Re: [PATCH 5/5] linux fbdev display driver.

Quoted 10 lines · Julian Pidancet

Hi,

Thanks for spotting these errors. Here is a respin of my patch to address you concerns. (The munmap call is included).

Cheers,

Julian

Oh, I actually tested the last patch only with the -nographic switch. There's still a segfault when starting qemu with vnc. You can fix it by adding a call to dpy_resize(ds) after the dcl = NULL; line in fbdev_display_uninit().

For some reason, the display is extremely slow when using vnc and fbdev at the same time.

Julian

#11 lore raw

Re: [Qemu-devel] Re: [PATCH 5/5] linux fbdev display driver.

Hi,

Quoted 2 lines

For some reason, the display is extremely slow when using vnc and fbdev at the same time.

Gotcha. Didn't notice, but it probably depends on the hardware. Very likely the reason is that graphic cards usually are optimized for write access and reads might be slow as hell. vnc must read though.

Hmm. No easy way out.

cheers,
Gerd

#12 lore raw

Re: [Qemu-devel] Re: [PATCH 5/5] linux fbdev display driver.

Quoted 9 lines · Gerd Hoffmann
   Hi,
Quoted 2 lines

For some reason, the display is extremely slow when using vnc and fbdev at the same time.

Gotcha. Didn't notice, but it probably depends on the hardware. Very likely the reason is that graphic cards usually are optimized for write
access and reads might be slow as hell. vnc must read though.

Access to the framebuffer are cached Write-Combining by default with fbdev, which is probably causing this latency.

One solution would be to disable the display allocator when vnc is present, and let it read from a software surface instead of reading from the framebuffer (like in your initial patch). It would probably decrease display performance, but not as much as it is now if we let the vnc driver read from the hardware framebuffer.

We can easily implement a surface usage counter in the display allocator code, so the fbdev driver can know whether or not the surface is read by other drivers at the same time.

Signature · 1 line
Julian Pidancet
#13 lore raw
In reply to Gerd Hoffmann
Quoted 19 lines · Gerd Hoffmann

Hi,

This patch series features the linux fbdev display driver and a few more patches the fbdev driver depends on. Most of the patches have been on the list before. If you wondered what they are good for -- here is the big picture ;)

As usual the individual patches carry more verbose descriptions.

cheers,
Gerd

Gerd Hoffmann (5):
QLIST-ify display change listeners.
add unregister_displaychangelistener
Fix and simplify gui timer logic.
add pflib: PixelFormat conversion library.
linux fbdev display driver.

Quoted 18 lines
 Makefile.objs    |    2 +
 console.h        |   82 +++--
 fbdev.c          |  931 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xenfb.c       |    2 +-
 linux-keynames.h |  386 ++++++++++++++++++++++
 monitor.c        |   14 +
 pflib.c          |  213 +++++++++++++
 pflib.h          |   20 ++
 qemu-options.hx  |   10 +
 sysemu.h         |    1 +
 vl.c             |   55 ++--
 11 files changed, 1648 insertions(+), 68 deletions(-)
 create mode 100644 fbdev.c
 create mode 100644 linux-keynames.h
 create mode 100644 pflib.c
 create mode 100644 pflib.h

Have anyone got the time to review this yet ?

Signature · 1 line
Julian