]> git.proxmox.com Git - qemu.git/blobdiff - hw/pl110.c
virtio-serial: Turn props any virtio-serial-bus device must have into bus props
[qemu.git] / hw / pl110.c
index 7340d4b4a33d3965cc8121eee1f384afb8d7f2f5..06d2dfada694e35e3e15c0def03d6aaddb20d508 100644 (file)
@@ -1,15 +1,18 @@
-/* 
+/*
  * Arm PrimeCell PL110 Color LCD Controller
  *
- * Copyright (c) 2005-2006 CodeSourcery.
+ * Copyright (c) 2005-2009 CodeSourcery.
  * Written by Paul Brook
  *
  * This code is licenced under the GNU LGPL
  */
 
-#include "vl.h"
+#include "sysbus.h"
+#include "console.h"
+#include "framebuffer.h"
 
 #define PL110_CR_EN   0x001
+#define PL110_CR_BGR  0x100
 #define PL110_CR_BEBO 0x200
 #define PL110_CR_BEPO 0x400
 #define PL110_CR_PWR  0x800
@@ -25,8 +28,9 @@ enum pl110_bppmode
 };
 
 typedef struct {
-    uint32_t base;
+    SysBusDevice busdev;
     DisplayState *ds;
+
     /* The Versatile/PB uses a slightly modified PL110 controller.  */
     int versatile;
     uint32_t timing[4];
@@ -44,6 +48,28 @@ typedef struct {
     qemu_irq irq;
 } pl110_state;
 
+static const VMStateDescription vmstate_pl110 = {
+    .name = "pl110",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_INT32(versatile, pl110_state),
+        VMSTATE_UINT32_ARRAY(timing, pl110_state, 4),
+        VMSTATE_UINT32(cr, pl110_state),
+        VMSTATE_UINT32(upbase, pl110_state),
+        VMSTATE_UINT32(lpbase, pl110_state),
+        VMSTATE_UINT32(int_status, pl110_state),
+        VMSTATE_UINT32(int_mask, pl110_state),
+        VMSTATE_INT32(cols, pl110_state),
+        VMSTATE_INT32(rows, pl110_state),
+        VMSTATE_UINT32(bpp, pl110_state),
+        VMSTATE_INT32(invalidate, pl110_state),
+        VMSTATE_UINT32_ARRAY(pallette, pl110_state, 256),
+        VMSTATE_UINT32_ARRAY(raw_pallette, pl110_state, 128),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static const unsigned char pl110_id[] =
 { 0x10, 0x11, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };
 
@@ -56,32 +82,7 @@ static const unsigned char pl110_versatile_id[] =
 #define pl110_versatile_id pl110_id
 #endif
 
-static inline uint32_t rgb_to_pixel8(unsigned int r, unsigned int g, unsigned b)
-{
-    return ((r >> 5) << 5) | ((g >> 5) << 2) | (b >> 6);
-}
-
-static inline uint32_t rgb_to_pixel15(unsigned int r, unsigned int g, unsigned b)
-{
-    return ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3);
-}
-
-static inline uint32_t rgb_to_pixel16(unsigned int r, unsigned int g, unsigned b)
-{
-    return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
-}
-
-static inline uint32_t rgb_to_pixel24(unsigned int r, unsigned int g, unsigned b)
-{
-    return (r << 16) | (g << 8) | b;
-}
-
-static inline uint32_t rgb_to_pixel32(unsigned int r, unsigned int g, unsigned b)
-{
-    return (r << 16) | (g << 8) | b;
-}
-
-typedef void (*drawfn)(uint32_t *, uint8_t *, const uint8_t *, int);
+#include "pixel_ops.h"
 
 #define BITS 8
 #include "pl110_template.h"
@@ -104,21 +105,16 @@ static void pl110_update_display(void *opaque)
     pl110_state *s = (pl110_state *)opaque;
     drawfn* fntable;
     drawfn fn;
-    uint32_t *pallette;
-    uint32_t addr;
-    uint32_t base;
     int dest_width;
     int src_width;
-    uint8_t *dest;
-    uint8_t *src;
-    int first, last = 0;
-    int dirty, new_dirty;
-    int i;
+    int bpp_offset;
+    int first;
+    int last;
 
     if (!pl110_enabled(s))
         return;
-    
-    switch (s->ds->depth) {
+
+    switch (ds_get_bits_per_pixel(s->ds)) {
     case 0:
         return;
     case 8:
@@ -145,13 +141,18 @@ static void pl110_update_display(void *opaque)
         fprintf(stderr, "pl110: Bad color depth\n");
         exit(1);
     }
+    if (s->cr & PL110_CR_BGR)
+        bpp_offset = 0;
+    else
+        bpp_offset = 18;
+
     if (s->cr & PL110_CR_BEBO)
-      fn = fntable[s->bpp + 6];
+        fn = fntable[s->bpp + 6 + bpp_offset];
     else if (s->cr & PL110_CR_BEPO)
-      fn = fntable[s->bpp + 12];
+        fn = fntable[s->bpp + 12 + bpp_offset];
     else
-      fn = fntable[s->bpp];
-    
+        fn = fntable[s->bpp + bpp_offset];
+
     src_width = s->cols;
     switch (s->bpp) {
     case BPP_1:
@@ -173,53 +174,26 @@ static void pl110_update_display(void *opaque)
         break;
     }
     dest_width *= s->cols;
-    pallette = s->pallette;
-    base = s->upbase;
-    /* HACK: Arm aliases physical memory at 0x80000000.  */
-    if (base > 0x80000000)
-        base -= 0x80000000;
-    src = phys_ram_base + base;
-    dest = s->ds->data;
-    first = -1;
-    addr = base;
-
-    dirty = cpu_physical_memory_get_dirty(addr, VGA_DIRTY_FLAG);
-    new_dirty = dirty;
-    for (i = 0; i < s->rows; i++) {
-        if ((addr & ~TARGET_PAGE_MASK) + src_width >= TARGET_PAGE_SIZE) {
-            uint32_t tmp;
-            new_dirty = 0;
-            for (tmp = 0; tmp < src_width; tmp += TARGET_PAGE_SIZE) {
-                new_dirty |= cpu_physical_memory_get_dirty(addr + tmp,
-                                                           VGA_DIRTY_FLAG);
-            }
-        }
-
-        if (dirty || new_dirty || s->invalidate) {
-            fn(pallette, dest, src, s->cols);
-            if (first == -1)
-                first = i;
-            last = i;
-        }
-        dirty = new_dirty;
-        addr += src_width;
-        dest += dest_width;
-        src += src_width;
+    first = 0;
+    framebuffer_update_display(s->ds,
+                               s->upbase, s->cols, s->rows,
+                               src_width, dest_width, 0,
+                               s->invalidate,
+                               fn, s->pallette,
+                               &first, &last);
+    if (first >= 0) {
+        dpy_update(s->ds, 0, first, s->cols, last - first + 1);
     }
-    if (first < 0)
-      return;
-
     s->invalidate = 0;
-    cpu_physical_memory_reset_dirty(base + first * src_width,
-                                    base + (last + 1) * src_width,
-                                    VGA_DIRTY_FLAG);
-    dpy_update(s->ds, 0, first, s->cols, last - first + 1);
 }
 
 static void pl110_invalidate_display(void * opaque)
 {
     pl110_state *s = (pl110_state *)opaque;
     s->invalidate = 1;
+    if (pl110_enabled(s)) {
+        qemu_console_resize(s->ds, s->cols, s->rows);
+    }
 }
 
 static void pl110_update_pallette(pl110_state *s, int n)
@@ -238,7 +212,7 @@ static void pl110_update_pallette(pl110_state *s, int n)
         b = (raw & 0x1f) << 3;
         /* The I bit is ignored.  */
         raw >>= 6;
-        switch (s->ds->depth) {
+        switch (ds_get_bits_per_pixel(s->ds)) {
         case 8:
             s->pallette[n] = rgb_to_pixel8(r, g, b);
             break;
@@ -261,7 +235,7 @@ static void pl110_resize(pl110_state *s, int width, int height)
 {
     if (width != s->cols || height != s->rows) {
         if (pl110_enabled(s)) {
-            dpy_resize(s->ds, width, height);
+            qemu_console_resize(s->ds, width, height);
         }
     }
     s->cols = width;
@@ -278,7 +252,6 @@ static uint32_t pl110_read(void *opaque, target_phys_addr_t offset)
 {
     pl110_state *s = (pl110_state *)opaque;
 
-    offset -= s->base;
     if (offset >= 0xfe0 && offset < 0x1000) {
         if (s->versatile)
             return pl110_versatile_id[(offset - 0xfe0) >> 2];
@@ -302,8 +275,12 @@ static uint32_t pl110_read(void *opaque, target_phys_addr_t offset)
     case 5: /* LCDLPBASE */
         return s->lpbase;
     case 6: /* LCDIMSC */
+       if (s->versatile)
+         return s->cr;
         return s->int_mask;
     case 7: /* LCDControl */
+       if (s->versatile)
+         return s->int_mask;
         return s->cr;
     case 8: /* LCDRIS */
         return s->int_status;
@@ -315,7 +292,7 @@ static uint32_t pl110_read(void *opaque, target_phys_addr_t offset)
     case 12: /* LCDLPCURR */
         return s->lpbase;
     default:
-        cpu_abort (cpu_single_env, "pl110_read: Bad offset %x\n", offset);
+        hw_error("pl110_read: Bad offset %x\n", (int)offset);
         return 0;
     }
 }
@@ -329,7 +306,6 @@ static void pl110_write(void *opaque, target_phys_addr_t offset,
     /* For simplicity invalidate the display whenever a control register
        is writen to.  */
     s->invalidate = 1;
-    offset -= s->base;
     if (offset >= 0x200 && offset < 0x400) {
         /* Pallette.  */
         n = (offset - 0x200) >> 2;
@@ -374,7 +350,7 @@ static void pl110_write(void *opaque, target_phys_addr_t offset,
         s->cr = val;
         s->bpp = (val >> 1) & 7;
         if (pl110_enabled(s)) {
-            dpy_resize(s->ds, s->cols, s->rows);
+            qemu_console_resize(s->ds, s->cols, s->rows);
         }
         break;
     case 10: /* LCDICR */
@@ -382,38 +358,65 @@ static void pl110_write(void *opaque, target_phys_addr_t offset,
         pl110_update(s);
         break;
     default:
-        cpu_abort (cpu_single_env, "pl110_write: Bad offset %x\n", offset);
+        hw_error("pl110_write: Bad offset %x\n", (int)offset);
     }
 }
 
-static CPUReadMemoryFunc *pl110_readfn[] = {
+static CPUReadMemoryFunc * const pl110_readfn[] = {
    pl110_read,
    pl110_read,
    pl110_read
 };
 
-static CPUWriteMemoryFunc *pl110_writefn[] = {
+static CPUWriteMemoryFunc * const pl110_writefn[] = {
    pl110_write,
    pl110_write,
    pl110_write
 };
 
-void *pl110_init(DisplayState *ds, uint32_t base, qemu_irq irq,
-                 int versatile)
+static int pl110_init(SysBusDevice *dev)
 {
-    pl110_state *s;
+    pl110_state *s = FROM_SYSBUS(pl110_state, dev);
     int iomemtype;
 
-    s = (pl110_state *)qemu_mallocz(sizeof(pl110_state));
-    iomemtype = cpu_register_io_memory(0, pl110_readfn,
-                                       pl110_writefn, s);
-    cpu_register_physical_memory(base, 0x00001000, iomemtype);
-    s->base = base;
-    s->ds = ds;
-    s->versatile = versatile;
-    s->irq = irq;
-    graphic_console_init(ds, pl110_update_display, pl110_invalidate_display,
-                         NULL, s);
-    /* ??? Save/restore.  */
-    return s;
+    iomemtype = cpu_register_io_memory(pl110_readfn,
+                                       pl110_writefn, s,
+                                       DEVICE_NATIVE_ENDIAN);
+    sysbus_init_mmio(dev, 0x1000, iomemtype);
+    sysbus_init_irq(dev, &s->irq);
+    s->ds = graphic_console_init(pl110_update_display,
+                                 pl110_invalidate_display,
+                                 NULL, NULL, s);
+    return 0;
+}
+
+static int pl110_versatile_init(SysBusDevice *dev)
+{
+    pl110_state *s = FROM_SYSBUS(pl110_state, dev);
+    s->versatile = 1;
+    return pl110_init(dev);
+}
+
+static SysBusDeviceInfo pl110_info = {
+    .init = pl110_init,
+    .qdev.name = "pl110",
+    .qdev.size = sizeof(pl110_state),
+    .qdev.vmsd = &vmstate_pl110,
+    .qdev.no_user = 1,
+};
+
+static SysBusDeviceInfo pl110_versatile_info = {
+    .init = pl110_versatile_init,
+    .qdev.name = "pl110_versatile",
+    .qdev.size = sizeof(pl110_state),
+    .qdev.vmsd = &vmstate_pl110,
+    .qdev.no_user = 1,
+};
+
+static void pl110_register_devices(void)
+{
+    sysbus_register_withprop(&pl110_info);
+    sysbus_register_withprop(&pl110_versatile_info);
 }
+
+device_init(pl110_register_devices)