aboutsummaryrefslogtreecommitdiff
path: root/hw/m48t59.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-07-15 13:43:31 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-07-16 17:28:51 -0500
commitee6847d19be16c789b8bd4e553b7cd6701ba1245 (patch)
tree41845b3b1e8740ce97daf0582e124c6b6e0a6873 /hw/m48t59.c
parentf114784f69ec3b9af342148025de14dbd1b429a5 (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/m48t59.c')
-rw-r--r--hw/m48t59.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/hw/m48t59.c b/hw/m48t59.c
index 798d292853..7e53dceb37 100644
--- a/hw/m48t59.c
+++ b/hw/m48t59.c
@@ -43,11 +43,11 @@
struct m48t59_t {
SysBusDevice busdev;
/* Model parameters */
- int type; // 2 = m48t02, 8 = m48t08, 59 = m48t59
+ uint32_t type; // 2 = m48t02, 8 = m48t08, 59 = m48t59
/* Hardware parameters */
qemu_irq IRQ;
uint32_t io_base;
- uint16_t size;
+ uint32_t size;
/* RTC management */
time_t time_offset;
time_t stop_time;
@@ -623,9 +623,9 @@ m48t59_t *m48t59_init (qemu_irq IRQ, target_phys_addr_t mem_base,
m48t59_t *d;
dev = qdev_create(NULL, "m48t59");
- qdev_set_prop_int(dev, "type", type);
- qdev_set_prop_int(dev, "size", size);
- qdev_set_prop_int(dev, "io_base", io_base);
+ qdev_prop_set_uint32(dev, "type", type);
+ qdev_prop_set_uint32(dev, "size", size);
+ qdev_prop_set_uint32(dev, "io_base", io_base);
qdev_init(dev);
s = sysbus_from_qdev(dev);
sysbus_connect_irq(s, 0, IRQ);
@@ -647,11 +647,8 @@ static void m48t59_init1(SysBusDevice *dev)
m48t59_t *s = FROM_SYSBUS(m48t59_t, dev);
int mem_index;
- s->size = qdev_get_prop_int(&dev->qdev, "size", -1);
s->buffer = qemu_mallocz(s->size);
sysbus_init_irq(dev, &s->IRQ);
- s->io_base = qdev_get_prop_int(&dev->qdev, "io_base", 0);
- s->type = qdev_get_prop_int(&dev->qdev, "type", -1);
mem_index = cpu_register_io_memory(nvram_read, nvram_write, s);
sysbus_init_mmio(dev, s->size, mem_index);
@@ -666,9 +663,33 @@ static void m48t59_init1(SysBusDevice *dev)
register_savevm("m48t59", -1, 1, m48t59_save, m48t59_load, s);
}
+static SysBusDeviceInfo m48t59_info = {
+ .init = m48t59_init1,
+ .qdev.name = "m48t59",
+ .qdev.size = sizeof(m48t59_t),
+ .qdev.props = (Property[]) {
+ {
+ .name = "size",
+ .info = &qdev_prop_uint32,
+ .offset = offsetof(m48t59_t, size),
+ .defval = (uint32_t[]) { -1 },
+ },{
+ .name = "type",
+ .info = &qdev_prop_uint32,
+ .offset = offsetof(m48t59_t, type),
+ .defval = (uint32_t[]) { -1 },
+ },{
+ .name = "io_base",
+ .info = &qdev_prop_hex32,
+ .offset = offsetof(m48t59_t, io_base),
+ },
+ {/* end of list */}
+ }
+};
+
static void m48t59_register_devices(void)
{
- sysbus_register_dev("m48t59", sizeof(m48t59_t), m48t59_init1);
+ sysbus_register_withprop(&m48t59_info);
}
device_init(m48t59_register_devices)