@@ -58,7 +58,7 @@ static void an5206_init(MachineState *machine)
vmstate_register_ram_global(sram);
memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
- mcf5206_init(address_space_mem, AN5206_MBAR_ADDR, cpu);
+ mcf5206_init(address_space_mem, AN5206_MBAR_ADDR);
/* Load kernel. */
if (!kernel_filename) {
@@ -7,6 +7,7 @@
*/
#include "hw/hw.h"
#include "hw/m68k/mcf.h"
+#include "hw/sysbus.h"
#include "qemu/timer.h"
#include "hw/ptimer.h"
#include "sysemu/sysemu.h"
@@ -142,9 +143,15 @@ static m5206_timer_state *m5206_timer_init(qemu_irq irq)
return s;
}
+#define TYPE_M5206_MBAR "m5206_mbar"
+#define M5206_MBAR(obj) \
+ OBJECT_CHECK(m5206_mbar_state, (obj), TYPE_M5206_MBAR)
+
/* System Integration Module. */
typedef struct {
+ SysBusDevice parent;
+
M68kCPU *cpu;
MemoryRegion iomem;
m5206_timer_state *timer[2];
@@ -242,8 +249,10 @@ static void m5206_mbar_set_irq(void *opaque, int irq, int level)
/* System Integration Module. */
-static void m5206_mbar_reset(m5206_mbar_state *s)
+static void m5206_mbar_reset(DeviceState *dev)
{
+ m5206_mbar_state *s = M5206_MBAR(dev);
+
s->scr = 0xc0;
s->icr[1] = 0x04;
s->icr[2] = 0x08;
@@ -525,24 +534,62 @@ static const MemoryRegionOps m5206_mbar_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
-qemu_irq *mcf5206_init(MemoryRegion *sysmem, uint32_t base, M68kCPU *cpu)
+static void m5206_mbar_initfn(Object *obj)
{
- m5206_mbar_state *s;
- qemu_irq *pic;
+ DeviceState *dev = DEVICE(obj);
+ m5206_mbar_state *s = M5206_MBAR(obj);
+ SysBusDevice *sysbus = SYS_BUS_DEVICE(obj);
+
+ qdev_init_gpio_in(dev, m5206_mbar_set_irq, 14);
+ sysbus_init_mmio(sysbus, &s->iomem);
+}
- s = (m5206_mbar_state *)g_malloc0(sizeof(m5206_mbar_state));
+static void m5206_mbar_realize(DeviceState *dev, Error **errp)
+{
+ m5206_mbar_state *s = M5206_MBAR(dev);
memory_region_init_io(&s->iomem, NULL, &m5206_mbar_ops, s,
"mbar", 0x00001000);
- memory_region_add_subregion(sysmem, base, &s->iomem);
- pic = qemu_allocate_irqs(m5206_mbar_set_irq, s, 14);
- s->timer[0] = m5206_timer_init(pic[9]);
- s->timer[1] = m5206_timer_init(pic[10]);
- s->uart[0] = mcf_uart_init(pic[12], serial_hds[0]);
- s->uart[1] = mcf_uart_init(pic[13], serial_hds[1]);
- s->cpu = cpu;
+ s->timer[0] = m5206_timer_init(qdev_get_gpio_in(dev, 9));
+ s->timer[1] = m5206_timer_init(qdev_get_gpio_in(dev, 10));
+ s->uart[0] = mcf_uart_init(qdev_get_gpio_in(dev, 12), serial_hds[0]);
+ s->uart[1] = mcf_uart_init(qdev_get_gpio_in(dev, 13), serial_hds[1]);
+ s->cpu = M68K_CPU(first_cpu);
+}
+
+static void m5206_mbar_class_init(ObjectClass *klass, void *class_data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ dc->realize = m5206_mbar_realize;
+ dc->reset = m5206_mbar_reset;
+}
+
+static const TypeInfo m5206_mbar_info = {
+ .name = TYPE_M5206_MBAR,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(m5206_mbar_state),
+ .instance_init = m5206_mbar_initfn,
+ .class_init = m5206_mbar_class_init,
+};
+
+static void m5206_mbar_register_types(void)
+{
+ type_register_static(&m5206_mbar_info);
+}
+
+type_init(m5206_mbar_register_types);
+
+void mcf5206_init(MemoryRegion *sysmem, uint32_t base)
+{
+ DeviceState *dev;
+ SysBusDevice *sysbus;
+
+ dev = qdev_create(NULL, TYPE_M5206_MBAR);
+ qdev_init_nofail(dev);
- m5206_mbar_reset(s);
- return pic;
+ sysbus = SYS_BUS_DEVICE(dev);
+ memory_region_add_subregion(sysmem, base,
+ sysbus_mmio_get_region(sysbus, 0));
}
@@ -24,7 +24,6 @@ void mcf_fec_init(struct MemoryRegion *sysmem, NICInfo *nd,
hwaddr base, qemu_irq *irq);
/* mcf5206.c */
-qemu_irq *mcf5206_init(struct MemoryRegion *sysmem,
- uint32_t base, M68kCPU *cpu);
+void mcf5206_init(struct MemoryRegion *sysmem, uint32_t base);
#endif