Merge branch 'master' of /home/nchip/public_html/qemu into garage-push
[qemu] / hw / pl110.c
index f21b63b..b45204c 100644 (file)
@@ -1,14 +1,13 @@
 /*
  * 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 "hw.h"
-#include "primecell.h"
+#include "sysbus.h"
 #include "console.h"
 #include "framebuffer.h"
 
@@ -29,6 +28,7 @@ enum pl110_bppmode
 };
 
 typedef struct {
+    SysBusDevice busdev;
     DisplayState *ds;
 
     /* The Versatile/PB uses a slightly modified PL110 controller.  */
@@ -267,7 +267,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", (int)offset);
+        hw_error("pl110_read: Bad offset %x\n", (int)offset);
         return 0;
     }
 }
@@ -333,7 +333,7 @@ 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", (int)offset);
+        hw_error("pl110_write: Bad offset %x\n", (int)offset);
     }
 }
 
@@ -349,20 +349,33 @@ static CPUWriteMemoryFunc *pl110_writefn[] = {
    pl110_write
 };
 
-void *pl110_init(uint32_t base, qemu_irq irq, int versatile)
+static void 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->versatile = versatile;
-    s->irq = irq;
+    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);
     /* ??? Save/restore.  */
-    return s;
 }
+
+static void pl110_versatile_init(SysBusDevice *dev)
+{
+    pl110_state *s = FROM_SYSBUS(pl110_state, dev);
+    s->versatile = 1;
+    pl110_init(dev);
+}
+
+static void pl110_register_devices(void)
+{
+    sysbus_register_dev("pl110", sizeof(pl110_state), pl110_init);
+    sysbus_register_dev("pl110_versatile", sizeof(pl110_state),
+                        pl110_versatile_init);
+}
+
+device_init(pl110_register_devices)