summaryrefslogtreecommitdiff
path: root/hw/tcx.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/tcx.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/tcx.c')
-rw-r--r--hw/tcx.c65
1 files changed, 48 insertions, 17 deletions
diff --git a/hw/tcx.c b/hw/tcx.c
index 76acae809d..c5925240b5 100644
--- a/hw/tcx.c
+++ b/hw/tcx.c
@@ -26,6 +26,7 @@
#include "console.h"
#include "pixel_ops.h"
#include "sysbus.h"
+#include "qdev-addr.h"
#define MAXX 1024
#define MAXY 768
@@ -41,6 +42,7 @@ typedef struct TCXState {
uint8_t *vram;
uint32_t *vram24, *cplane;
ram_addr_t vram_offset, vram24_offset, cplane_offset;
+ uint32_t vram_size;
uint16_t width, height, depth;
uint8_t r[256], g[256], b[256];
uint32_t palette[256];
@@ -520,11 +522,11 @@ void tcx_init(target_phys_addr_t addr, int vram_size, int width, int height,
SysBusDevice *s;
dev = qdev_create(NULL, "SUNW,tcx");
- qdev_set_prop_int(dev, "addr", addr);
- qdev_set_prop_int(dev, "vram_size", vram_size);
- qdev_set_prop_int(dev, "width", width);
- qdev_set_prop_int(dev, "height", height);
- qdev_set_prop_int(dev, "depth", depth);
+ qdev_prop_set_taddr(dev, "addr", addr);
+ qdev_prop_set_uint32(dev, "vram_size", vram_size);
+ qdev_prop_set_uint16(dev, "width", width);
+ qdev_prop_set_uint16(dev, "height", height);
+ qdev_prop_set_uint16(dev, "depth", depth);
qdev_init(dev);
s = sysbus_from_qdev(dev);
/* 8-bit plane */
@@ -551,22 +553,16 @@ static void tcx_init1(SysBusDevice *dev)
TCXState *s = FROM_SYSBUS(TCXState, dev);
int io_memory, dummy_memory;
ram_addr_t vram_offset;
- int size, vram_size;
+ int size;
uint8_t *vram_base;
- vram_size = qdev_get_prop_int(&dev->qdev, "vram_size", -1);
-
- vram_offset = qemu_ram_alloc(vram_size * (1 + 4 + 4));
+ vram_offset = qemu_ram_alloc(s->vram_size * (1 + 4 + 4));
vram_base = qemu_get_ram_ptr(vram_offset);
- s->addr = qdev_get_prop_int(&dev->qdev, "addr", -1);
s->vram_offset = vram_offset;
- s->width = qdev_get_prop_int(&dev->qdev, "width", -1);
- s->height = qdev_get_prop_int(&dev->qdev, "height", -1);
- s->depth = qdev_get_prop_int(&dev->qdev, "depth", -1);
/* 8-bit plane */
s->vram = vram_base;
- size = vram_size;
+ size = s->vram_size;
sysbus_init_mmio(dev, size, s->vram_offset);
vram_offset += size;
vram_base += size;
@@ -584,7 +580,7 @@ static void tcx_init1(SysBusDevice *dev)
if (s->depth == 24) {
/* 24-bit plane */
- size = vram_size * 4;
+ size = s->vram_size * 4;
s->vram24 = (uint32_t *)vram_base;
s->vram24_offset = vram_offset;
sysbus_init_mmio(dev, size, vram_offset);
@@ -592,7 +588,7 @@ static void tcx_init1(SysBusDevice *dev)
vram_base += size;
/* Control plane */
- size = vram_size * 4;
+ size = s->vram_size * 4;
s->cplane = (uint32_t *)vram_base;
s->cplane_offset = vram_offset;
sysbus_init_mmio(dev, size, vram_offset);
@@ -678,9 +674,44 @@ static void tcx24_screen_dump(void *opaque, const char *filename)
return;
}
+static SysBusDeviceInfo tcx_info = {
+ .init = tcx_init1,
+ .qdev.name = "SUNW,tcx",
+ .qdev.size = sizeof(TCXState),
+ .qdev.props = (Property[]) {
+ {
+ .name = "addr",
+ .info = &qdev_prop_taddr,
+ .offset = offsetof(TCXState, addr),
+ .defval = (target_phys_addr_t[]) { -1 },
+ },{
+ .name = "vram_size",
+ .info = &qdev_prop_hex32,
+ .offset = offsetof(TCXState, vram_size),
+ .defval = (uint32_t[]) { -1 },
+ },{
+ .name = "width",
+ .info = &qdev_prop_uint16,
+ .offset = offsetof(TCXState, width),
+ .defval = (uint16_t[]) { -1 },
+ },{
+ .name = "height",
+ .info = &qdev_prop_uint16,
+ .offset = offsetof(TCXState, height),
+ .defval = (uint16_t[]) { -1 },
+ },{
+ .name = "depth",
+ .info = &qdev_prop_uint16,
+ .offset = offsetof(TCXState, depth),
+ .defval = (uint16_t[]) { -1 },
+ },
+ {/* end of list */}
+ }
+};
+
static void tcx_register_devices(void)
{
- sysbus_register_dev("SUNW,tcx", sizeof(TCXState), tcx_init1);
+ sysbus_register_withprop(&tcx_info);
}
device_init(tcx_register_devices)