Skip to contentSkip to conversation

[6965] Implement and use shared memory framebuffer device rendering reoutine.

Qemu-devel Paul Brook 3 participants 3 messages Apr 1, 2009 – Apr 2, 2009 Kbuild

lore
Share & tools
lore

Paul Brook

author
#0 lore raw

Revision: 6965

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6965
Author:   pbrook
Date:     2009-04-01 12:27:59 +0000 (Wed, 01 Apr 2009)

Log Message:
-----------
Implement and use shared memory framebuffer device rendering reoutine. Use DMA mapping API.

Modified Paths:
--------------

    trunk/Makefile.target
    trunk/hw/omap.h
    trunk/hw/omap_lcd_template.h
    trunk/hw/omap_lcdc.c
    trunk/hw/pl110.c
    trunk/hw/pl110_template.h
    trunk/hw/pxa2xx_lcd.c
    trunk/hw/pxa2xx_template.h

Added Paths:
-----------
trunk/hw/framebuffer.c
trunk/hw/framebuffer.h

Modified: trunk/Makefile.target
===================================================================

Makefile.target +1 -0
@@ -672,6 +672,7 @@
 OBJS+= tsc2005.o bt-hci-csr.o
 OBJS+= mst_fpga.o mainstone.o
 OBJS+= musicpal.o pflash_cfi02.o
+OBJS+= framebuffer.o
 CPPFLAGS += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), sh4)

Added: trunk/hw/framebuffer.c
===================================================================

hw/framebuffer.c +119 -0

119 lines not on this page · raw message

Added: trunk/hw/framebuffer.h
===================================================================

hw/framebuffer.h +22 -0
@@ -0,0 +1,22 @@
+#ifndef QEMU_FRAMEBUFFER_H
+#define QEMU_FRAMEBUFFER_H
+
+/* Framebuffer device helper routines.  */
+
+typedef void (*drawfn)(void *, uint8_t *, const uint8_t *, int, int);
+
+void framebuffer_update_display(
+    DisplayState *ds,
+    target_phys_addr_t base,
+    int cols,
+    int rows,
+    int src_width,
+    int dest_row_pitch,
+    int dest_col_pitch,
+    int invalidate,
+    drawfn fn,
+    void *opaque,
+    int *first_row,
+    int *last_row);
+
+#endif

Modified: trunk/hw/omap.h
===================================================================

hw/omap.h +1 -1
@@ -490,7 +490,7 @@
     int dual;
 
     int current_frame;
-    ram_addr_t phys_framebuffer[2];
+    target_phys_addr_t phys_framebuffer[2];
     qemu_irq irq;
     struct omap_mpu_state_s *mpu;
 } *omap_dma_get_lcdch(struct soc_dma_s *s);

Modified: trunk/hw/omap_lcd_template.h
===================================================================

hw/omap_lcd_template.h +13 -10
@@ -43,9 +43,10 @@
 /*
  * 2-bit colour
  */
-static void glue(draw_line2_, DEPTH)(
-                uint8_t *d, const uint8_t *s, int width, const uint16_t *pal)
+static void glue(draw_line2_, DEPTH)(void *opaque,
+                uint8_t *d, const uint8_t *s, int width, int deststep)
 {
+    uint16_t *pal = opaque;
     uint8_t v, r, g, b;
 
     do {
@@ -81,9 +82,10 @@
 /*
  * 4-bit colour
  */
-static void glue(draw_line4_, DEPTH)(
-                uint8_t *d, const uint8_t *s, int width, const uint16_t *pal)
+static void glue(draw_line4_, DEPTH)(void *opaque,
+                uint8_t *d, const uint8_t *s, int width, int deststep)
 {
+    uint16_t *pal = opaque;
     uint8_t v, r, g, b;
 
     do {
@@ -107,9 +109,10 @@
 /*
  * 8-bit colour
  */
-static void glue(draw_line8_, DEPTH)(
-                uint8_t *d, const uint8_t *s, int width, const uint16_t *pal)
+static void glue(draw_line8_, DEPTH)(void *opaque,
+                uint8_t *d, const uint8_t *s, int width, int deststep)
 {
+    uint16_t *pal = opaque;
     uint8_t v, r, g, b;
 
     do {
@@ -126,8 +129,8 @@
 /*
  * 12-bit colour
  */
-static void glue(draw_line12_, DEPTH)(
-                uint8_t *d, const uint8_t *s, int width, const uint16_t *pal)
+static void glue(draw_line12_, DEPTH)(void *opaque,
+                uint8_t *d, const uint8_t *s, int width, int deststep)
 {
     uint16_t v;
     uint8_t r, g, b;
@@ -146,8 +149,8 @@
 /*
  * 16-bit colour
  */
-static void glue(draw_line16_, DEPTH)(
-                uint8_t *d, const uint8_t *s, int width, const uint16_t *pal)
+static void glue(draw_line16_, DEPTH)(void *opaque,
+                uint8_t *d, const uint8_t *s, int width, int deststep)
 {
 #if DEPTH == 16 && defined(WORDS_BIGENDIAN) == defined(TARGET_WORDS_BIGENDIAN)
     memcpy(d, s, width * 2);

Modified: trunk/hw/omap_lcdc.c
===================================================================

hw/omap_lcdc.c +31 -65

170 lines not on this page · raw message

Modified: trunk/hw/pl110.c
===================================================================

hw/pl110.c +12 -49

90 lines not on this page · raw message

Modified: trunk/hw/pl110_template.h
===================================================================

hw/pl110_template.h +10 -6
@@ -115,8 +115,9 @@
 #define FN_4(x, y) FN_2(x, y) FN_2(x+2, y)
 #define FN_8(y) FN_4(0, y) FN_4(4, y)
 
-static void glue(pl110_draw_line1_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
+static void glue(pl110_draw_line1_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
 {
+    uint32_t *pallette = opaque;
     uint32_t data;
     while (width > 0) {
         data = *(uint32_t *)src;
@@ -142,8 +143,9 @@
     }
 }
 
-static void glue(pl110_draw_line2_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
+static void glue(pl110_draw_line2_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
 {
+    uint32_t *pallette = opaque;
     uint32_t data;
     while (width > 0) {
         data = *(uint32_t *)src;
@@ -169,8 +171,9 @@
     }
 }
 
-static void glue(pl110_draw_line4_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
+static void glue(pl110_draw_line4_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
 {
+    uint32_t *pallette = opaque;
     uint32_t data;
     while (width > 0) {
         data = *(uint32_t *)src;
@@ -196,8 +199,9 @@
     }
 }
 
-static void glue(pl110_draw_line8_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
+static void glue(pl110_draw_line8_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
 {
+    uint32_t *pallette = opaque;
     uint32_t data;
     while (width > 0) {
         data = *(uint32_t *)src;
@@ -219,7 +223,7 @@
     }
 }
 
-static void glue(pl110_draw_line16_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
+static void glue(pl110_draw_line16_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
 {
     uint32_t data;
     unsigned int r, g, b;
@@ -265,7 +269,7 @@
     }
 }
 
-static void glue(pl110_draw_line32_,NAME)(uint32_t *pallette, uint8_t *d, const uint8_t *src, int width)
+static void glue(pl110_draw_line32_,NAME)(void *opaque, uint8_t *d, const uint8_t *src, int width, int deststep)
 {
     uint32_t data;
     unsigned int r, g, b;

Modified: trunk/hw/pxa2xx_lcd.c
===================================================================

hw/pxa2xx_lcd.c +29 -88

192 lines not on this page · raw message

Modified: trunk/hw/pxa2xx_template.h
===================================================================

hw/pxa2xx_template.h +15 -12
@@ -30,9 +30,10 @@
 #define FN_2(x)		FN(x + 1) FN(x)
 #define FN_4(x)		FN_2(x + 2) FN_2(x)
 
-static void glue(pxa2xx_draw_line2_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line2_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
+    uint32_t *palette = opaque;
     uint32_t data;
     while (width > 0) {
         data = *(uint32_t *) src;
@@ -54,9 +55,10 @@
     }
 }
 
-static void glue(pxa2xx_draw_line4_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line4_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
+    uint32_t *palette = opaque;
     uint32_t data;
     while (width > 0) {
         data = *(uint32_t *) src;
@@ -78,9 +80,10 @@
     }
 }
 
-static void glue(pxa2xx_draw_line8_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line8_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
+    uint32_t *palette = opaque;
     uint32_t data;
     while (width > 0) {
         data = *(uint32_t *) src;
@@ -102,7 +105,7 @@
     }
 }
 
-static void glue(pxa2xx_draw_line16_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line16_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
     uint32_t data;
@@ -130,7 +133,7 @@
     }
 }
 
-static void glue(pxa2xx_draw_line16t_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line16t_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
     uint32_t data;
@@ -166,7 +169,7 @@
     }
 }
 
-static void glue(pxa2xx_draw_line18_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line18_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
     uint32_t data;
@@ -188,7 +191,7 @@
 }
 
 /* The wicked packed format */
-static void glue(pxa2xx_draw_line18p_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line18p_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
     uint32_t data[3];
@@ -236,7 +239,7 @@
     }
 }
 
-static void glue(pxa2xx_draw_line19_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line19_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
     uint32_t data;
@@ -262,7 +265,7 @@
 }
 
 /* The wicked packed format */
-static void glue(pxa2xx_draw_line19p_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line19p_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
     uint32_t data[3];
@@ -326,7 +329,7 @@
     }
 }
 
-static void glue(pxa2xx_draw_line24_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line24_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
     uint32_t data;
@@ -347,7 +350,7 @@
     }
 }
 
-static void glue(pxa2xx_draw_line24t_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line24t_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
     uint32_t data;
@@ -372,7 +375,7 @@
     }
 }
 
-static void glue(pxa2xx_draw_line25_, BITS)(uint32_t *palette,
+static void glue(pxa2xx_draw_line25_, BITS)(void *opaque,
                 uint8_t *dest, const uint8_t *src, int width, int deststep)
 {
     uint32_t data;
#1 lore raw

2009/4/1 Paul Brook <[email protected]>:

Quoted 120 lines

Revision: 6965
         http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6965
Author:   pbrook
Date:     2009-04-01 12:27:59 +0000 (Wed, 01 Apr 2009)
Log Message:
-----------
Implement and use shared memory framebuffer device rendering reoutine. Use DMA mapping API.

Modified Paths:
--------------
   trunk/Makefile.target
   trunk/hw/omap.h
   trunk/hw/omap_lcd_template.h
   trunk/hw/omap_lcdc.c
   trunk/hw/pl110.c
   trunk/hw/pl110_template.h
   trunk/hw/pxa2xx_lcd.c
   trunk/hw/pxa2xx_template.h

Added Paths:
-----------
   trunk/hw/framebuffer.c
   trunk/hw/framebuffer.h

Modified: trunk/Makefile.target
===================================================================

Makefile.target       2009-04-01 12:27:59 UTC (rev 6965) renamed from Makefile.target       2009-04-01 11:43:02 UTC (rev 6964) +0 -0
@@ -672,6 +672,7 @@

 OBJS+= tsc2005.o bt-hci-csr.o
 OBJS+= mst_fpga.o mainstone.o
 OBJS+= musicpal.o pflash_cfi02.o
+OBJS+= framebuffer.o
 CPPFLAGS += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), sh4)

Added: trunk/hw/framebuffer.c
===================================================================

hw/framebuffer.c      2009-04-01 12:27:59 UTC (rev 6965) renamed from hw/framebuffer.c                              (rev 0) +75 -0
@@ -0,0 +1,119 @@
+/*
+ * Framebuffer device helper routines
+ *
+ * Copyright (c) 2009 CodeSourcery
+ * Written by Paul Brook <[email protected]>
+ *
+ * This code is licensed under the GNU GPLv2.
+ */
+
+/* TODO:
+   - Do something similar for framebuffers with local ram
+   - Handle rotation here instead of hacking dest_pitch
+   - Use common pixel conversion routines instead of per-device drawfn
+   - Remove all DisplayState knowledge from devices.
+ */
+
+#include "hw.h"
+#include "console.h"
+#include "framebuffer.h"
+#include "kvm.h"
+
+/* Render an image from a shared memory framebuffer.  */
+
+void framebuffer_update_display(
+    DisplayState *ds,
+    target_phys_addr_t base,
+    int cols, /* Width in pixels.  */
+    int rows, /* Leight in pixels.  */
+    int src_width, /* Length of source line, in bytes.  */
+    int dest_row_pitch, /* Bytes between adjacent horizontal output pixels.  */
+    int dest_col_pitch, /* Bytes between adjacent vertical output pixels.  */
+    int invalidate, /* nonzero to redraw the whole image.  */
+    drawfn fn,
+    void *opaque,
+    int *first_row, /* Input and output.  */
+    int *last_row /* Output only */)
+{
+    target_phys_addr_t src_len;
+    uint8_t *dest;
+    uint8_t *src;
+    uint8_t *src_base;
+    int first, last = 0;
+    int dirty;
+    int i;
+    ram_addr_t addr;
+    ram_addr_t pd;
+    ram_addr_t pd2;
+
+    i = *first_row;
+    *first_row = -1;
+    src_len = src_width * rows;
+
+    if (kvm_enabled()) {
+        kvm_physical_sync_dirty_bitmap(base, src_len);
+    }
+    pd = cpu_get_physical_page_desc(base);
+    pd2 = cpu_get_physical_page_desc(base + src_len - 1);
+    /* We should reall check that this is a continuous ram region.
+       Instead we just check that the first and last pages are
+       both ram, and the right distance apart.  */
+    if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM
+        || (pd2 & ~TARGET_PAGE_MASK) > IO_MEM_ROM) {
+        return;
+    }
+    pd = (pd & TARGET_PAGE_MASK) + (base & ~TARGET_PAGE_MASK);
+    if (((pd + src_len - 1) & TARGET_PAGE_MASK) != (pd2 & TARGET_PAGE_MASK)) {
+        return;
+    }
+
+    src_base = cpu_physical_memory_map(base, &src_len, 0);
+    /* If we can't map the framebuffer then bail.  We could try harder,
+       but it's not really worth it as dirty flag tracking will probably
+       already have failed above.  */
+    if (!src_base)
+        return;

hw/framebuffer.c      2009-04-01 12:27:59 UTC (rev 6965) line 85

Quoted 10 lines
hw/framebuffer.c      2009-04-01 12:27:59 UTC (rev 6965) renamed from hw/framebuffer.c                              (rev 0) +10 -0
+    if (src_len != src_width * rows) {
+        cpu_physical_memory_unmap(src_base, src_len, 0, 0);
+        return;
+    }
+    src = src_base;
+    dest = ds_get_data(ds);
+    if (dest_col_pitch < 0)
+        dest -= dest_col_pitch * (cols - 1);
+    first = -1;
+    addr = pd;

If we must use the map/unmap api for framebuffers (even though we know this memory is continuous in qemu) then we could map omly the region we determined is dirty.

Cheers

#2 lore raw
Quoted 3 lines

If we must use the map/unmap api for framebuffers (even though we know this memory is continuous in qemu) then we could map only the region we determined is dirty.

Maybe. In practice I doubt there's that much difference. In general we don't actually know the memory is contiguous, though for well behaved guests with current boards it probably is. The proper solution is probably to replace l1_phys_map with an extent bases system, so that map time is not proportional to region size.

My main motivation for this patch is that it is the first step in eliminating phys_ram_base.

Paul