[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 090/173] pl050: QOM'ify pl050_keyboard and pl050_mous
From: |
Andreas Färber |
Subject: |
[Qemu-devel] [PULL 090/173] pl050: QOM'ify pl050_keyboard and pl050_mouse |
Date: |
Mon, 29 Jul 2013 21:19:07 +0200 |
Introduce an abstract type pl050 and let pl050_keyboar and pl050_mouse
inherit from it, using different instance_init functions.
Introduce a type constant and use QOM casts.
Signed-off-by: Andreas Färber <address@hidden>
---
hw/input/pl050.c | 62 +++++++++++++++++++++++++++++++-------------------------
1 file changed, 34 insertions(+), 28 deletions(-)
diff --git a/hw/input/pl050.c b/hw/input/pl050.c
index 8493abd..c1b08d5 100644
--- a/hw/input/pl050.c
+++ b/hw/input/pl050.c
@@ -10,8 +10,12 @@
#include "hw/sysbus.h"
#include "hw/input/ps2.h"
+#define TYPE_PL050 "pl050"
+#define PL050(obj) OBJECT_CHECK(PL050State, (obj), TYPE_PL050)
+
typedef struct PL050State {
- SysBusDevice busdev;
+ SysBusDevice parent_obj;
+
MemoryRegion iomem;
void *dev;
uint32_t cr;
@@ -19,7 +23,7 @@ typedef struct PL050State {
uint32_t last;
int pending;
qemu_irq irq;
- int is_mouse;
+ bool is_mouse;
} PL050State;
static const VMStateDescription vmstate_pl050 = {
@@ -133,65 +137,67 @@ static const MemoryRegionOps pl050_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
-static int pl050_init(SysBusDevice *dev, int is_mouse)
+static int pl050_initfn(SysBusDevice *dev)
{
- PL050State *s = FROM_SYSBUS(PL050State, dev);
+ PL050State *s = PL050(dev);
memory_region_init_io(&s->iomem, OBJECT(s), &pl050_ops, s, "pl050",
0x1000);
sysbus_init_mmio(dev, &s->iomem);
sysbus_init_irq(dev, &s->irq);
- s->is_mouse = is_mouse;
- if (s->is_mouse)
+ if (s->is_mouse) {
s->dev = ps2_mouse_init(pl050_update, s);
- else
+ } else {
s->dev = ps2_kbd_init(pl050_update, s);
+ }
return 0;
}
-static int pl050_init_keyboard(SysBusDevice *dev)
+static void pl050_keyboard_init(Object *obj)
{
- return pl050_init(dev, 0);
-}
+ PL050State *s = PL050(obj);
-static int pl050_init_mouse(SysBusDevice *dev)
-{
- return pl050_init(dev, 1);
+ s->is_mouse = false;
}
-static void pl050_kbd_class_init(ObjectClass *klass, void *data)
+static void pl050_mouse_init(Object *obj)
{
- DeviceClass *dc = DEVICE_CLASS(klass);
- SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+ PL050State *s = PL050(obj);
- k->init = pl050_init_keyboard;
- dc->vmsd = &vmstate_pl050;
+ s->is_mouse = true;
}
static const TypeInfo pl050_kbd_info = {
.name = "pl050_keyboard",
- .parent = TYPE_SYS_BUS_DEVICE,
- .instance_size = sizeof(PL050State),
- .class_init = pl050_kbd_class_init,
+ .parent = TYPE_PL050,
+ .instance_init = pl050_keyboard_init,
};
-static void pl050_mouse_class_init(ObjectClass *klass, void *data)
+static const TypeInfo pl050_mouse_info = {
+ .name = "pl050_mouse",
+ .parent = TYPE_PL050,
+ .instance_init = pl050_mouse_init,
+};
+
+static void pl050_class_init(ObjectClass *oc, void *data)
{
- DeviceClass *dc = DEVICE_CLASS(klass);
- SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+ DeviceClass *dc = DEVICE_CLASS(oc);
+ SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(oc);
- k->init = pl050_init_mouse;
+ sdc->init = pl050_initfn;
dc->vmsd = &vmstate_pl050;
}
-static const TypeInfo pl050_mouse_info = {
- .name = "pl050_mouse",
+static const TypeInfo pl050_type_info = {
+ .name = TYPE_PL050,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(PL050State),
- .class_init = pl050_mouse_class_init,
+ .abstract = true,
+ .class_init = pl050_class_init,
};
static void pl050_register_types(void)
{
+ type_register_static(&pl050_type_info);
type_register_static(&pl050_kbd_info);
type_register_static(&pl050_mouse_info);
}
--
1.8.1.4
- [Qemu-devel] [PULL 079/173] omap_gpio: QOM cast cleanup for omap_gpif_s, (continued)
- [Qemu-devel] [PULL 079/173] omap_gpio: QOM cast cleanup for omap_gpif_s, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 080/173] omap_gpio: QOM cast cleanup for omap2_gpif_s, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 078/173] sun4m_iommu: QOM cast cleanup, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 081/173] pl061: Rename pl061_state to PL061State, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 083/173] puv3_gpio: QOM cast cleanup, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 085/173] bitbang_i2c: QOM cast cleanup, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 082/173] pl061: QOM'ify pl061 and pl061_luminary, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 086/173] omap_i2c: QOM cast cleanup, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 084/173] gpio/zaurus: QOM cast cleanup, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 088/173] milkymist-softusb: QOM cast cleanup, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 090/173] pl050: QOM'ify pl050_keyboard and pl050_mouse,
Andreas Färber <=
- [Qemu-devel] [PULL 091/173] arm_gic: QOM cast cleanup, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 089/173] pl050: Rename pl050_state to PL050State, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 092/173] etraxfs_pic: QOM cast cleanup, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 093/173] exynos4210_combiner: QOM cast cleanup, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 096/173] grlib_irqmp: QOM cast cleanup, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 094/173] exynos4210_gic: QOM cast cleanup for exynos4210.gic, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 095/173] exynos4210_gic: QOM cast cleanup for exynos4210.irq_gate, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 097/173] lm32_pic: QOM cast cleanup, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 105/173] arm_l2x0: Rename l2x0_state to L2x0State, Andreas Färber, 2013/07/29
- [Qemu-devel] [PULL 106/173] arm_l2x0: QOM cast cleanup, Andreas Färber, 2013/07/29