diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2009-07-15 13:43:31 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-07-16 17:28:51 -0500 |
commit | ee6847d19be16c789b8bd4e553b7cd6701ba1245 (patch) | |
tree | 41845b3b1e8740ce97daf0582e124c6b6e0a6873 /hw/escc.c | |
parent | f114784f69ec3b9af342148025de14dbd1b429a5 (diff) |
qdev: rework device properties.
This patch is a major overhaul of the device properties. The properties
are saved directly in the device state struct now, the linked list of
property values is gone.
Advantages:
* We don't have to maintain the list with the property values.
* The value in the property list and the value actually used by
the device can't go out of sync any more (used to happen for
the pci.devfn == -1 case) because there is only one place where
the value is stored.
* A record describing the property is required now, you can't set
random properties any more.
There are bus-specific and device-specific properties. The former
should be used for properties common to all bus drivers. Typical
use case is bus addressing, i.e. pci.devfn and i2c.address.
Properties have a PropertyInfo struct attached with name, size and
function pointers to parse and print properties. A few common property
types have PropertyInfos defined in qdev-properties.c. Drivers are free
to implement their own very special property parsers if needed.
Properties can have default values. If unset they are zero-filled.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/escc.c')
-rw-r--r-- | hw/escc.c | 92 |
1 files changed, 57 insertions, 35 deletions
@@ -120,6 +120,8 @@ struct SerialState { struct ChannelState chn[2]; int it_shift; int mmio_index; + uint32_t disabled; + uint32_t frequency; }; #define SERIAL_CTRL 0 @@ -732,13 +734,13 @@ int escc_init(target_phys_addr_t base, qemu_irq irqA, qemu_irq irqB, SerialState *d; dev = qdev_create(NULL, "escc"); - qdev_set_prop_int(dev, "disabled", 0); - qdev_set_prop_int(dev, "frequency", clock); - qdev_set_prop_int(dev, "it_shift", it_shift); - qdev_set_prop_ptr(dev, "chrB", chrB); - qdev_set_prop_ptr(dev, "chrA", chrA); - qdev_set_prop_int(dev, "chnBtype", ser); - qdev_set_prop_int(dev, "chnAtype", ser); + qdev_prop_set_uint32(dev, "disabled", 0); + qdev_prop_set_uint32(dev, "frequency", clock); + qdev_prop_set_uint32(dev, "it_shift", it_shift); + qdev_prop_set_ptr(dev, "chrB", chrB); + qdev_prop_set_ptr(dev, "chrA", chrA); + qdev_prop_set_uint32(dev, "chnBtype", ser); + qdev_prop_set_uint32(dev, "chnAtype", ser); qdev_init(dev); s = sysbus_from_qdev(dev); sysbus_connect_irq(s, 0, irqA); @@ -895,13 +897,13 @@ void slavio_serial_ms_kbd_init(target_phys_addr_t base, qemu_irq irq, SysBusDevice *s; dev = qdev_create(NULL, "escc"); - qdev_set_prop_int(dev, "disabled", disabled); - qdev_set_prop_int(dev, "frequency", clock); - qdev_set_prop_int(dev, "it_shift", it_shift); - qdev_set_prop_ptr(dev, "chrB", NULL); - qdev_set_prop_ptr(dev, "chrA", NULL); - qdev_set_prop_int(dev, "chnBtype", mouse); - qdev_set_prop_int(dev, "chnAtype", kbd); + qdev_prop_set_uint32(dev, "disabled", disabled); + qdev_prop_set_uint32(dev, "frequency", clock); + qdev_prop_set_uint32(dev, "it_shift", it_shift); + qdev_prop_set_ptr(dev, "chrB", NULL); + qdev_prop_set_ptr(dev, "chrA", NULL); + qdev_prop_set_uint32(dev, "chnBtype", mouse); + qdev_prop_set_uint32(dev, "chnAtype", kbd); qdev_init(dev); s = sysbus_from_qdev(dev); sysbus_connect_irq(s, 0, irq); @@ -914,19 +916,13 @@ static void escc_init1(SysBusDevice *dev) SerialState *s = FROM_SYSBUS(SerialState, dev); int io; unsigned int i; - uint32_t clock, disabled; - - s->it_shift = qdev_get_prop_int(&dev->qdev, "it_shift", 0); - clock = qdev_get_prop_int(&dev->qdev, "frequency", 0); - s->chn[0].chr = qdev_get_prop_ptr(&dev->qdev, "chrB"); - s->chn[1].chr = qdev_get_prop_ptr(&dev->qdev, "chrA"); - disabled = qdev_get_prop_int(&dev->qdev, "disabled", 0); - s->chn[0].disabled = disabled; - s->chn[1].disabled = disabled; + + s->chn[0].disabled = s->disabled; + s->chn[1].disabled = s->disabled; for (i = 0; i < 2; i++) { sysbus_init_irq(dev, &s->chn[i].irq); s->chn[i].chn = 1 - i; - s->chn[i].clock = clock / 2; + s->chn[i].clock = s->frequency / 2; if (s->chn[i].chr) { qemu_chr_add_handlers(s->chn[i].chr, serial_can_receive, serial_receive1, serial_event, &s->chn[i]); @@ -934,8 +930,6 @@ static void escc_init1(SysBusDevice *dev) } s->chn[0].otherchn = &s->chn[1]; s->chn[1].otherchn = &s->chn[0]; - s->chn[0].type = qdev_get_prop_int(&dev->qdev, "chnBtype", 0); - s->chn[1].type = qdev_get_prop_int(&dev->qdev, "chnAtype", 0); io = cpu_register_io_memory(escc_mem_read, escc_mem_write, s); sysbus_init_mmio(dev, ESCC_SIZE << s->it_shift, io); @@ -957,15 +951,43 @@ static SysBusDeviceInfo escc_info = { .init = escc_init1, .qdev.name = "escc", .qdev.size = sizeof(SerialState), - .qdev.props = (DevicePropList[]) { - {.name = "frequency", .type = PROP_TYPE_INT}, - {.name = "it_shift", .type = PROP_TYPE_INT}, - {.name = "disabled", .type = PROP_TYPE_INT}, - {.name = "chrB", .type = PROP_TYPE_PTR}, - {.name = "chrA", .type = PROP_TYPE_PTR}, - {.name = "chnBtype", .type = PROP_TYPE_INT}, - {.name = "chnAtype", .type = PROP_TYPE_INT}, - {.name = NULL} + .qdev.props = (Property[]) { + { + .name = "frequency", + .info = &qdev_prop_uint32, + .offset = offsetof(SerialState, frequency), + }, + { + .name = "it_shift", + .info = &qdev_prop_uint32, + .offset = offsetof(SerialState, it_shift), + }, + { + .name = "disabled", + .info = &qdev_prop_uint32, + .offset = offsetof(SerialState, disabled), + }, + { + .name = "chrB", + .info = &qdev_prop_ptr, + .offset = offsetof(SerialState, chn[1].chr), + }, + { + .name = "chrA", + .info = &qdev_prop_ptr, + .offset = offsetof(SerialState, chn[0].chr), + }, + { + .name = "chnBtype", + .info = &qdev_prop_uint32, + .offset = offsetof(SerialState, chn[1].type), + }, + { + .name = "chnAtype", + .info = &qdev_prop_uint32, + .offset = offsetof(SerialState, chn[0].type), + }, + {/* end of list */} } }; |