Re: [Qemu-devel] [PATCH 4/9] fbdev: add linux framebuffer display driver.

2012-09-24 Thread Stefano Stabellini
On Fri, 21 Sep 2012, Gerd Hoffmann wrote:
   Hi,
 
  +case FB_ACQ_REQ:
  +fbdev_switch_acquire();
  +redraw_screen++;
  
  Rather than introducing redraw_screen, I would just call vga_hw_invalidate
  instead here. It is always a win if we can avoid to introduce one more
  state machine.
 
 Wouldn't that make the vga emulation do additional work which is simply
 not needed?

It causes full_update to be set and that causes vga_draw_line to be
called for every line on the screen.
However in the important cases (32bpp and 16bpp) the buffer is shared
and nothing happens. So no more work.



Re: [Qemu-devel] [PATCH 4/9] fbdev: add linux framebuffer display driver.

2012-09-24 Thread Gerd Hoffmann
On 09/24/12 13:06, Stefano Stabellini wrote:
 On Fri, 21 Sep 2012, Gerd Hoffmann wrote:
   Hi,

 +case FB_ACQ_REQ:
 +fbdev_switch_acquire();
 +redraw_screen++;

 Rather than introducing redraw_screen, I would just call vga_hw_invalidate
 instead here. It is always a win if we can avoid to introduce one more
 state machine.

 Wouldn't that make the vga emulation do additional work which is simply
 not needed?
 
 It causes full_update to be set and that causes vga_draw_line to be
 called for every line on the screen.
 However in the important cases (32bpp and 16bpp) the buffer is shared
 and nothing happens. So no more work.

When looking at the code I feel again like this is one relict we should
just get rid of ...

The reason it exists in the first place seems to be console switching.
The qemu-internal one, via Ctrl-Alt-nr, to serial / monitor text
consoles.  In that case the vga emulation must be able to restore the
display, and vga_hw_invalidate will handle it.

That logic predates the display surfaces though.  I think today we could
just assign a displaysurface to each qemu console and be done with it.
Console switching will just switch display surfaces without any
re-rendering needed.  Likewise screendumping can stop hoping through all
the loops it hops today.

Any other vga_hw_invalidate calls creped in over time (ab-)use it to
kick a redraw in the ui code.  They kick the vga emulation for no
reason, there is nothing the vga emulation must redraw.

cheers,
  Gerd



Re: [Qemu-devel] [PATCH 4/9] fbdev: add linux framebuffer display driver.

2012-09-21 Thread Gerd Hoffmann
  Hi,

 +case FB_ACQ_REQ:
 +fbdev_switch_acquire();
 +redraw_screen++;
 
 Rather than introducing redraw_screen, I would just call vga_hw_invalidate
 instead here. It is always a win if we can avoid to introduce one more
 state machine.

Wouldn't that make the vga emulation do additional work which is simply
not needed?

cheers,
  Gerd




[Qemu-devel] [PATCH 4/9] fbdev: add linux framebuffer display driver.

2012-09-19 Thread 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 enough to type monitor commands.  Not goot enough to
work seriously on a serial terminal.  But the qemu terminal emulation
isn't good enough for that anyway ;)

Hot keys:
  Ctrl-Alt-Fnr  - 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/ttynr).

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 console.h   |4 +
 qemu-options.hx |8 +
 sysemu.h|1 +
 trace-events|   15 +
 ui/Makefile.objs|1 +
 ui/fbdev.c  |  965 +++
 ui/linux-keynames.h |  388 +
 vl.c|   19 +
 8 files changed, 1401 insertions(+), 0 deletions(-)
 create mode 100644 ui/fbdev.c
 create mode 100644 ui/linux-keynames.h

diff --git a/console.h b/console.h
index bef2d2d..aa9959b 100644
--- a/console.h
+++ b/console.h
@@ -417,6 +417,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 */
+int fbdev_display_init(DisplayState *ds, const char *device, Error **err);
+void fbdev_display_uninit(DisplayState *ds);
+
 /* cocoa.m */
 void cocoa_display_init(DisplayState *ds, int full_screen);
 
diff --git a/qemu-options.hx b/qemu-options.hx
index 09c86c4..3445655 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -947,6 +947,14 @@ Enable/disable spice seamless migration. Default is off.
 @end table
 ETEXI
 
+DEF(fbdev, 0, QEMU_OPTION_fbdev,
+-fbdev  enable fbdev\n, QEMU_ARCH_ALL)
+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)
diff --git a/sysemu.h b/sysemu.h
index 65552ac..34e6bfa 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -93,6 +93,7 @@ typedef enum DisplayType
 DT_DEFAULT,
 DT_CURSES,
 DT_SDL,
+DT_FBDEV,
 DT_NOGRAPHIC,
 DT_NONE,
 } DisplayType;
diff --git a/trace-events b/trace-events
index b48fe2d..0d0b7fa 100644
--- a/trace-events
+++ b/trace-events
@@ -994,3 +994,18 @@ spapr_pci_rtas_ibm_change_msi(unsigned func, unsigned req) 
func %u, requested %
 spapr_pci_rtas_ibm_query_interrupt_source_number(unsigned ioa, unsigned intr) 
queries for #%u, IRQ%u
 spapr_pci_msi_write(uint64_t addr, uint64_t data, uint32_t dt_irq) 
@%PRIx64=%PRIx64 IRQ %u
 spapr_pci_lsi_set(const char *busname, int pin, uint32_t irq) %s PIN%d IRQ %u
+
+# ui/fbdev.c
+fbdev_enabled(void) 
+fbdev_cleanup(void) 
+fbdev_vt_activate(int vtno, int wait) vtno %d, wait %d
+fbdev_vt_activated(void) 
+fbdev_vt_release_request(void) 
+fbdev_vt_released(void) 
+fbdev_vt_aquire_request(void) 
+fbdev_vt_aquired(void) 
+fbdev_kbd_raw(int enable) enable %d
+fbdev_kbd_event(int keycode, const char *kname, int up) keycode 0x%x [%s], 
down %d
+fbdev_dpy_resize(int w, int h) %dx%d
+fbdev_dpy_redraw(void)
+
diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index adc07be..55ddcf2 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -12,3 +12,4 @@ common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
 common-obj-$(CONFIG_CURSES) += curses.o
 common-obj-$(CONFIG_VNC) += $(vnc-obj-y)
+common-obj-$(CONFIG_LINUX) += fbdev.o
diff --git a/ui/fbdev.c b/ui/fbdev.c
new file mode 100644
index 000..6dfbacc
--- /dev/null
+++ b/ui/fbdev.c
@@ -0,0 +1,965 @@
+/*
+ * linux fbdev output driver.
+ *
+ * Author: Gerd Hoffmann kra...@redhat.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+#include stdio.h
+#include stdlib.h
+#include stdbool.h
+#include string.h
+#include unistd.h
+#include fcntl.h
+#include signal.h
+#include termios.h
+
+#include sys/ioctl.h
+#include sys/mman.h
+
+#include linux/kd.h
+#include linux/vt.h
+#include linux/fb.h
+
+#include qemu-common.h
+#include console.h
+#include keymaps.h
+#include sysemu.h
+#include pflib.h
+
+/*
+ * must be last so 

Re: [Qemu-devel] [PATCH 4/9] fbdev: add linux framebuffer display driver.

2012-09-19 Thread Stefano Stabellini
On Wed, 19 Sep 2012, Gerd Hoffmann wrote:
 +/*  */
 +/* rendering*/
 +
 +static void fbdev_render(DisplayState *ds, int x, int y, int w, int h)
 +{
 +uint8_t *dst;
 +uint8_t *src;
 +int line;
 +
 +if (!conv) {
 +return;
 +}
 +
 +src = ds_get_data(ds) + 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;
 +
 +dst += cy * fb_fix.line_length;
 +dst += cx * fbpf.bytes_per_pixel;
 +
 +if (h  fb_var.yres - y) {
 +h = fb_var.yres - y;
 +}
 +if (w  fb_var.xres - x) {
 +w = fb_var.xres - x;
 +}
 +
 +for (line = y; line  y+h; line++) {
 +qemu_pf_conv_run(conv, dst, src, w);
 +dst += fb_fix.line_length;
 +src += ds_get_linesize(ds);
 +}
 +}
 +
 +/*  */
 +/* qemu interfaces  */
 +
 +static void fbdev_update(DisplayState *ds, int x, int y, int w, int h)
 +{
 +if (fb_switch_state != FB_ACTIVE) {
 +return;
 +}
 +
 +if (resize_screen) {
 +trace_fbdev_dpy_resize(ds_get_width(ds), ds_get_height(ds));
 +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 (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);
 +}
 +}
 +
 +if (redraw_screen) {
 +trace_fbdev_dpy_redraw();
 +redraw_screen = 0;
 +fbdev_cls();
 +x = 0; y = 0; w = ds_get_width(ds); h = ds_get_height(ds);
 +}
 +
 +fbdev_render(ds, x, y, w, h);
 +}
 +
 +static void fbdev_resize(DisplayState *ds)
 +{
 +resize_screen++;
 +redraw_screen++;
 +}
 +
 +static void fbdev_refresh(DisplayState *ds)
 +{
 +switch (fb_switch_state) {
 +case FB_REL_REQ:
 +fbdev_switch_release();
 +case FB_INACTIVE:
 +return;
 +case FB_ACQ_REQ:
 +fbdev_switch_acquire();
 +redraw_screen++;

Rather than introducing redraw_screen, I would just call vga_hw_invalidate
instead here. It is always a win if we can avoid to introduce one more
state machine.


 +case FB_ACTIVE:
 +break;
 +}
 +
 +vga_hw_update();
 +if (redraw_screen) {
 +fbdev_update(ds, 0, 0, 0, 0);
 +}
 +}




Re: [Qemu-devel] [PATCH 4/9] fbdev: add linux framebuffer display driver.

2012-09-19 Thread Blue Swirl
On Tue, Sep 18, 2012 at 7:17 AM, Gerd Hoffmann kra...@redhat.com wrote:
 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 enough to type monitor commands.  Not goot enough to
 work seriously on a serial terminal.  But the qemu terminal emulation
 isn't good enough for that anyway ;)

 Hot keys:
   Ctrl-Alt-Fnr  - 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/ttynr).

 Signed-off-by: Gerd Hoffmann kra...@redhat.com
 ---
  console.h   |4 +
  qemu-options.hx |8 +
  sysemu.h|1 +
  trace-events|   15 +
  ui/Makefile.objs|1 +
  ui/fbdev.c  |  974 
 +++
  ui/linux-keynames.h |  388 
  vl.c|   12 +
  8 files changed, 1403 insertions(+), 0 deletions(-)
  create mode 100644 ui/fbdev.c
  create mode 100644 ui/linux-keynames.h

 diff --git a/console.h b/console.h
 index bef2d2d..0a3bae2 100644
 --- a/console.h
 +++ b/console.h
 @@ -417,6 +417,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 */
 +int fbdev_display_init(DisplayState *ds, const char *device);
 +void fbdev_display_uninit(DisplayState *ds);
 +
  /* cocoa.m */
  void cocoa_display_init(DisplayState *ds, int full_screen);

 diff --git a/qemu-options.hx b/qemu-options.hx
 index 09c86c4..3445655 100644
 --- a/qemu-options.hx
 +++ b/qemu-options.hx
 @@ -947,6 +947,14 @@ Enable/disable spice seamless migration. Default is off.
  @end table
  ETEXI

 +DEF(fbdev, 0, QEMU_OPTION_fbdev,
 +-fbdev  enable fbdev\n, QEMU_ARCH_ALL)
 +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)
 diff --git a/sysemu.h b/sysemu.h
 index 65552ac..34e6bfa 100644
 --- a/sysemu.h
 +++ b/sysemu.h
 @@ -93,6 +93,7 @@ typedef enum DisplayType
  DT_DEFAULT,
  DT_CURSES,
  DT_SDL,
 +DT_FBDEV,
  DT_NOGRAPHIC,
  DT_NONE,
  } DisplayType;
 diff --git a/trace-events b/trace-events
 index b48fe2d..0d0b7fa 100644
 --- a/trace-events
 +++ b/trace-events
 @@ -994,3 +994,18 @@ spapr_pci_rtas_ibm_change_msi(unsigned func, unsigned 
 req) func %u, requested %
  spapr_pci_rtas_ibm_query_interrupt_source_number(unsigned ioa, unsigned 
 intr) queries for #%u, IRQ%u
  spapr_pci_msi_write(uint64_t addr, uint64_t data, uint32_t dt_irq) 
 @%PRIx64=%PRIx64 IRQ %u
  spapr_pci_lsi_set(const char *busname, int pin, uint32_t irq) %s PIN%d IRQ 
 %u
 +
 +# ui/fbdev.c
 +fbdev_enabled(void) 
 +fbdev_cleanup(void) 
 +fbdev_vt_activate(int vtno, int wait) vtno %d, wait %d
 +fbdev_vt_activated(void) 
 +fbdev_vt_release_request(void) 
 +fbdev_vt_released(void) 
 +fbdev_vt_aquire_request(void) 
 +fbdev_vt_aquired(void) 
 +fbdev_kbd_raw(int enable) enable %d
 +fbdev_kbd_event(int keycode, const char *kname, int up) keycode 0x%x [%s], 
 down %d
 +fbdev_dpy_resize(int w, int h) %dx%d
 +fbdev_dpy_redraw(void)
 +
 diff --git a/ui/Makefile.objs b/ui/Makefile.objs
 index adc07be..55ddcf2 100644
 --- a/ui/Makefile.objs
 +++ b/ui/Makefile.objs
 @@ -12,3 +12,4 @@ common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
  common-obj-$(CONFIG_COCOA) += cocoa.o
  common-obj-$(CONFIG_CURSES) += curses.o
  common-obj-$(CONFIG_VNC) += $(vnc-obj-y)
 +common-obj-$(CONFIG_LINUX) += fbdev.o
 diff --git a/ui/fbdev.c b/ui/fbdev.c
 new file mode 100644
 index 000..40fc7d4
 --- /dev/null
 +++ b/ui/fbdev.c
 @@ -0,0 +1,974 @@
 +/*
 + * linux fbdev output driver.
 + *
 + * Author: Gerd Hoffmann kra...@redhat.com
 + *
 + * This work is licensed under the terms of the GNU GPL, version 2 or later.
 + * See the COPYING file in the top-level directory.
 + *
 + */
 +#include stdio.h
 +#include stdlib.h
 +#include stdbool.h
 +#include string.h
 +#include unistd.h
 +#include fcntl.h
 +#include signal.h
 +#include termios.h
 +
 +#include sys/ioctl.h
 +#include 

[Qemu-devel] [PATCH 4/9] fbdev: add linux framebuffer display driver.

2012-09-18 Thread 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 enough to type monitor commands.  Not goot enough to
work seriously on a serial terminal.  But the qemu terminal emulation
isn't good enough for that anyway ;)

Hot keys:
  Ctrl-Alt-Fnr  - 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/ttynr).

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 console.h   |4 +
 qemu-options.hx |8 +
 sysemu.h|1 +
 trace-events|   15 +
 ui/Makefile.objs|1 +
 ui/fbdev.c  |  974 +++
 ui/linux-keynames.h |  388 
 vl.c|   12 +
 8 files changed, 1403 insertions(+), 0 deletions(-)
 create mode 100644 ui/fbdev.c
 create mode 100644 ui/linux-keynames.h

diff --git a/console.h b/console.h
index bef2d2d..0a3bae2 100644
--- a/console.h
+++ b/console.h
@@ -417,6 +417,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 */
+int fbdev_display_init(DisplayState *ds, const char *device);
+void fbdev_display_uninit(DisplayState *ds);
+
 /* cocoa.m */
 void cocoa_display_init(DisplayState *ds, int full_screen);
 
diff --git a/qemu-options.hx b/qemu-options.hx
index 09c86c4..3445655 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -947,6 +947,14 @@ Enable/disable spice seamless migration. Default is off.
 @end table
 ETEXI
 
+DEF(fbdev, 0, QEMU_OPTION_fbdev,
+-fbdev  enable fbdev\n, QEMU_ARCH_ALL)
+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)
diff --git a/sysemu.h b/sysemu.h
index 65552ac..34e6bfa 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -93,6 +93,7 @@ typedef enum DisplayType
 DT_DEFAULT,
 DT_CURSES,
 DT_SDL,
+DT_FBDEV,
 DT_NOGRAPHIC,
 DT_NONE,
 } DisplayType;
diff --git a/trace-events b/trace-events
index b48fe2d..0d0b7fa 100644
--- a/trace-events
+++ b/trace-events
@@ -994,3 +994,18 @@ spapr_pci_rtas_ibm_change_msi(unsigned func, unsigned req) 
func %u, requested %
 spapr_pci_rtas_ibm_query_interrupt_source_number(unsigned ioa, unsigned intr) 
queries for #%u, IRQ%u
 spapr_pci_msi_write(uint64_t addr, uint64_t data, uint32_t dt_irq) 
@%PRIx64=%PRIx64 IRQ %u
 spapr_pci_lsi_set(const char *busname, int pin, uint32_t irq) %s PIN%d IRQ %u
+
+# ui/fbdev.c
+fbdev_enabled(void) 
+fbdev_cleanup(void) 
+fbdev_vt_activate(int vtno, int wait) vtno %d, wait %d
+fbdev_vt_activated(void) 
+fbdev_vt_release_request(void) 
+fbdev_vt_released(void) 
+fbdev_vt_aquire_request(void) 
+fbdev_vt_aquired(void) 
+fbdev_kbd_raw(int enable) enable %d
+fbdev_kbd_event(int keycode, const char *kname, int up) keycode 0x%x [%s], 
down %d
+fbdev_dpy_resize(int w, int h) %dx%d
+fbdev_dpy_redraw(void)
+
diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index adc07be..55ddcf2 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -12,3 +12,4 @@ common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
 common-obj-$(CONFIG_CURSES) += curses.o
 common-obj-$(CONFIG_VNC) += $(vnc-obj-y)
+common-obj-$(CONFIG_LINUX) += fbdev.o
diff --git a/ui/fbdev.c b/ui/fbdev.c
new file mode 100644
index 000..40fc7d4
--- /dev/null
+++ b/ui/fbdev.c
@@ -0,0 +1,974 @@
+/*
+ * linux fbdev output driver.
+ *
+ * Author: Gerd Hoffmann kra...@redhat.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+#include stdio.h
+#include stdlib.h
+#include stdbool.h
+#include string.h
+#include unistd.h
+#include fcntl.h
+#include signal.h
+#include termios.h
+
+#include sys/ioctl.h
+#include sys/mman.h
+
+#include linux/kd.h
+#include linux/vt.h
+#include linux/fb.h
+
+#include qemu-common.h
+#include console.h
+#include keymaps.h
+#include sysemu.h
+#include pflib.h
+
+/*
+ * must be last so we get the 

Re: [Qemu-devel] [PATCH 4/9] fbdev: add linux framebuffer display driver.

2012-09-18 Thread Stefano Stabellini
On Tue, 18 Sep 2012, Gerd Hoffmann wrote:
 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 enough to type monitor commands.  Not goot enough to
 work seriously on a serial terminal.  But the qemu terminal emulation
 isn't good enough for that anyway ;)
 
 Hot keys:
   Ctrl-Alt-Fnr  - 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/ttynr).
 
 Signed-off-by: Gerd Hoffmann kra...@redhat.com

This series is not bisectable: this patch references functions and
variables only defined in later patches (surface,
pixman_from_displaystate). Please make it bisectable.
It also makes it harder to review.
At the very least the Makefile changes should be in the last patch.


  console.h   |4 +
  qemu-options.hx |8 +
  sysemu.h|1 +
  trace-events|   15 +
  ui/Makefile.objs|1 +
  ui/fbdev.c  |  974 
 +++
  ui/linux-keynames.h |  388 
  vl.c|   12 +
  8 files changed, 1403 insertions(+), 0 deletions(-)
  create mode 100644 ui/fbdev.c
  create mode 100644 ui/linux-keynames.h
 
 diff --git a/console.h b/console.h
 index bef2d2d..0a3bae2 100644
 --- a/console.h
 +++ b/console.h
 @@ -417,6 +417,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 */
 +int fbdev_display_init(DisplayState *ds, const char *device);
 +void fbdev_display_uninit(DisplayState *ds);
 +
  /* cocoa.m */
  void cocoa_display_init(DisplayState *ds, int full_screen);
 
 diff --git a/qemu-options.hx b/qemu-options.hx
 index 09c86c4..3445655 100644
 --- a/qemu-options.hx
 +++ b/qemu-options.hx
 @@ -947,6 +947,14 @@ Enable/disable spice seamless migration. Default is off.
  @end table
  ETEXI
 
 +DEF(fbdev, 0, QEMU_OPTION_fbdev,
 +-fbdev  enable fbdev\n, QEMU_ARCH_ALL)
 +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)
 diff --git a/sysemu.h b/sysemu.h
 index 65552ac..34e6bfa 100644
 --- a/sysemu.h
 +++ b/sysemu.h
 @@ -93,6 +93,7 @@ typedef enum DisplayType
  DT_DEFAULT,
  DT_CURSES,
  DT_SDL,
 +DT_FBDEV,
  DT_NOGRAPHIC,
  DT_NONE,
  } DisplayType;
 diff --git a/trace-events b/trace-events
 index b48fe2d..0d0b7fa 100644
 --- a/trace-events
 +++ b/trace-events
 @@ -994,3 +994,18 @@ spapr_pci_rtas_ibm_change_msi(unsigned func, unsigned 
 req) func %u, requested %
  spapr_pci_rtas_ibm_query_interrupt_source_number(unsigned ioa, unsigned 
 intr) queries for #%u, IRQ%u
  spapr_pci_msi_write(uint64_t addr, uint64_t data, uint32_t dt_irq) 
 @%PRIx64=%PRIx64 IRQ %u
  spapr_pci_lsi_set(const char *busname, int pin, uint32_t irq) %s PIN%d IRQ 
 %u
 +
 +# ui/fbdev.c
 +fbdev_enabled(void) 
 +fbdev_cleanup(void) 
 +fbdev_vt_activate(int vtno, int wait) vtno %d, wait %d
 +fbdev_vt_activated(void) 
 +fbdev_vt_release_request(void) 
 +fbdev_vt_released(void) 
 +fbdev_vt_aquire_request(void) 
 +fbdev_vt_aquired(void) 
 +fbdev_kbd_raw(int enable) enable %d
 +fbdev_kbd_event(int keycode, const char *kname, int up) keycode 0x%x [%s], 
 down %d
 +fbdev_dpy_resize(int w, int h) %dx%d
 +fbdev_dpy_redraw(void)
 +
 diff --git a/ui/Makefile.objs b/ui/Makefile.objs
 index adc07be..55ddcf2 100644
 --- a/ui/Makefile.objs
 +++ b/ui/Makefile.objs
 @@ -12,3 +12,4 @@ common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
  common-obj-$(CONFIG_COCOA) += cocoa.o
  common-obj-$(CONFIG_CURSES) += curses.o
  common-obj-$(CONFIG_VNC) += $(vnc-obj-y)
 +common-obj-$(CONFIG_LINUX) += fbdev.o
 diff --git a/ui/fbdev.c b/ui/fbdev.c
 new file mode 100644
 index 000..40fc7d4
 --- /dev/null
 +++ b/ui/fbdev.c
 @@ -0,0 +1,974 @@
 +/*
 + * linux fbdev output driver.
 + *
 + * Author: Gerd Hoffmann kra...@redhat.com
 + *
 + * This work is licensed under the terms of the GNU GPL, version 2 or later.
 + * See the 

Re: [Qemu-devel] [PATCH 4/9] fbdev: add linux framebuffer display driver.

2012-09-18 Thread Gerd Hoffmann
On 09/18/12 17:01, Stefano Stabellini wrote:
 On Tue, 18 Sep 2012, Gerd Hoffmann wrote:
 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 enough to type monitor commands.  Not goot enough to
 work seriously on a serial terminal.  But the qemu terminal emulation
 isn't good enough for that anyway ;)

 Hot keys:
   Ctrl-Alt-Fnr  - 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/ttynr).

 Signed-off-by: Gerd Hoffmann kra...@redhat.com
 
 This series is not bisectable: this patch references functions and
 variables only defined in later patches (surface,
 pixman_from_displaystate). Please make it bisectable.

Oops, that wasn't intentionally, squashed bugfix into the wrong patch,
will fixup.

 +static void fbdev_setdata(DisplayState *ds)
 +{
 +if (surface) {
 ^ where is this coming from?
 

See above ;)

 +int fbdev_display_init(DisplayState *ds, const char *device)
 +{
 +if (dcl != NULL) {
 +return 0;
 +}
 
 is it actually possible that fbdev_display_init gets called multiple
 times?

With the next patch (enable/disable fbdev via monitor) yes.

 +fbdev_resize(ds);
 +dcl = g_new0(DisplayChangeListener, 1);
 +dcl-dpy_update  = fbdev_update;
 +dcl-dpy_resize  = fbdev_resize;
 +dcl-dpy_setdata = fbdev_setdata;
 +dcl-dpy_refresh = fbdev_refresh;
 +register_displaychangelistener(ds, dcl);
 
 The fbdev driver could benefit from registering a DisplayAllocator (see
 sdl.c).

I don't think so, at least not once the whole series is applied and
support for scaling  cursor rendering is there.

cheers,
  Gerd