hw/sd: QOM'ify pl181.c
split the old SysBus init function into an instance_init and a Device realize function Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com> Message-id: 1465815255-21776-13-git-send-email-zxq_yx_007@163.com Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
c9796d714c
commit
0d554cb043
@ -13,6 +13,7 @@
|
|||||||
#include "hw/sysbus.h"
|
#include "hw/sysbus.h"
|
||||||
#include "hw/sd/sd.h"
|
#include "hw/sd/sd.h"
|
||||||
#include "qemu/log.h"
|
#include "qemu/log.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
|
|
||||||
//#define DEBUG_PL181 1
|
//#define DEBUG_PL181 1
|
||||||
|
|
||||||
@ -481,43 +482,48 @@ static void pl181_reset(DeviceState *d)
|
|||||||
sd_set_cb(s->card, s->cardstatus[0], s->cardstatus[1]);
|
sd_set_cb(s->card, s->cardstatus[0], s->cardstatus[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pl181_init(SysBusDevice *sbd)
|
static void pl181_init(Object *obj)
|
||||||
{
|
{
|
||||||
DeviceState *dev = DEVICE(sbd);
|
DeviceState *dev = DEVICE(obj);
|
||||||
PL181State *s = PL181(dev);
|
PL181State *s = PL181(obj);
|
||||||
DriveInfo *dinfo;
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
||||||
|
|
||||||
memory_region_init_io(&s->iomem, OBJECT(s), &pl181_ops, s, "pl181", 0x1000);
|
memory_region_init_io(&s->iomem, obj, &pl181_ops, s, "pl181", 0x1000);
|
||||||
sysbus_init_mmio(sbd, &s->iomem);
|
sysbus_init_mmio(sbd, &s->iomem);
|
||||||
sysbus_init_irq(sbd, &s->irq[0]);
|
sysbus_init_irq(sbd, &s->irq[0]);
|
||||||
sysbus_init_irq(sbd, &s->irq[1]);
|
sysbus_init_irq(sbd, &s->irq[1]);
|
||||||
qdev_init_gpio_out(dev, s->cardstatus, 2);
|
qdev_init_gpio_out(dev, s->cardstatus, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pl181_realize(DeviceState *dev, Error **errp)
|
||||||
|
{
|
||||||
|
PL181State *s = PL181(dev);
|
||||||
|
DriveInfo *dinfo;
|
||||||
|
|
||||||
/* FIXME use a qdev drive property instead of drive_get_next() */
|
/* FIXME use a qdev drive property instead of drive_get_next() */
|
||||||
dinfo = drive_get_next(IF_SD);
|
dinfo = drive_get_next(IF_SD);
|
||||||
s->card = sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, false);
|
s->card = sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, false);
|
||||||
if (s->card == NULL) {
|
if (s->card == NULL) {
|
||||||
return -1;
|
error_setg(errp, "sd_init failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pl181_class_init(ObjectClass *klass, void *data)
|
static void pl181_class_init(ObjectClass *klass, void *data)
|
||||||
{
|
{
|
||||||
SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
|
|
||||||
DeviceClass *k = DEVICE_CLASS(klass);
|
DeviceClass *k = DEVICE_CLASS(klass);
|
||||||
|
|
||||||
sdc->init = pl181_init;
|
|
||||||
k->vmsd = &vmstate_pl181;
|
k->vmsd = &vmstate_pl181;
|
||||||
k->reset = pl181_reset;
|
k->reset = pl181_reset;
|
||||||
/* Reason: init() method uses drive_get_next() */
|
/* Reason: init() method uses drive_get_next() */
|
||||||
k->cannot_instantiate_with_device_add_yet = true;
|
k->cannot_instantiate_with_device_add_yet = true;
|
||||||
|
k->realize = pl181_realize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const TypeInfo pl181_info = {
|
static const TypeInfo pl181_info = {
|
||||||
.name = TYPE_PL181,
|
.name = TYPE_PL181,
|
||||||
.parent = TYPE_SYS_BUS_DEVICE,
|
.parent = TYPE_SYS_BUS_DEVICE,
|
||||||
.instance_size = sizeof(PL181State),
|
.instance_size = sizeof(PL181State),
|
||||||
|
.instance_init = pl181_init,
|
||||||
.class_init = pl181_class_init,
|
.class_init = pl181_class_init,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user