From ee6847d19be16c789b8bd4e553b7cd6701ba1245 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 15 Jul 2009 13:43:31 +0200 Subject: 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 Signed-off-by: Anthony Liguori --- hw/sun4m.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'hw/sun4m.c') diff --git a/hw/sun4m.c b/hw/sun4m.c index 220eaae..4954ba3 100644 --- a/hw/sun4m.c +++ b/hw/sun4m.c @@ -373,8 +373,7 @@ static void lance_init(NICInfo *nd, target_phys_addr_t leaddr, qemu_check_nic_model(&nd_table[0], "lance"); dev = qdev_create(NULL, "lance"); - qdev_set_netdev(dev, nd); - qdev_set_prop_ptr(dev, "dma", dma_opaque); + dev->nd = nd; qdev_init(dev); s = sysbus_from_qdev(dev); sysbus_mmio_map(s, 0, leaddr); @@ -410,9 +409,6 @@ static SysBusDeviceInfo idreg_info = { .init = idreg_init1, .qdev.name = "macio_idreg", .qdev.size = sizeof(SysBusDevice), - .qdev.props = (DevicePropList[]) { - {.name = NULL} - } }; static void idreg_register_devices(void) @@ -468,8 +464,8 @@ static SysBusDeviceInfo prom_info = { .init = prom_init1, .qdev.name = "openprom", .qdev.size = sizeof(SysBusDevice), - .qdev.props = (DevicePropList[]) { - {.name = NULL} + .qdev.props = (Property[]) { + {/* end of property list */} } }; @@ -480,12 +476,19 @@ static void prom_register_devices(void) device_init(prom_register_devices); +typedef struct RamDevice +{ + SysBusDevice busdev; + uint32_t size; +} RamDevice; + /* System RAM */ static void ram_init1(SysBusDevice *dev) { ram_addr_t RAM_size, ram_offset; + RamDevice *d = FROM_SYSBUS(RamDevice, dev); - RAM_size = qdev_get_prop_int(&dev->qdev, "size", 0); + RAM_size = d->size; ram_offset = qemu_ram_alloc(RAM_size); sysbus_init_mmio(dev, RAM_size, ram_offset); @@ -496,6 +499,7 @@ static void ram_init(target_phys_addr_t addr, ram_addr_t RAM_size, { DeviceState *dev; SysBusDevice *s; + RamDevice *d; /* allocate RAM */ if ((uint64_t)RAM_size > max_mem) { @@ -506,20 +510,26 @@ static void ram_init(target_phys_addr_t addr, ram_addr_t RAM_size, exit(1); } dev = qdev_create(NULL, "memory"); - qdev_set_prop_int(dev, "size", RAM_size); qdev_init(dev); s = sysbus_from_qdev(dev); + d = FROM_SYSBUS(RamDevice, s); + d->size = RAM_size; + sysbus_mmio_map(s, 0, addr); } static SysBusDeviceInfo ram_info = { .init = ram_init1, .qdev.name = "memory", - .qdev.size = sizeof(SysBusDevice), - .qdev.props = (DevicePropList[]) { - {.name = "size", .type = PROP_TYPE_INT}, - {.name = NULL} + .qdev.size = sizeof(RamDevice), + .qdev.props = (Property[]) { + { + .name = "size", + .info = &qdev_prop_uint32, + .offset = offsetof(RamDevice, size), + }, + {/* end of property list */} } }; -- cgit v1.1