qdev: property fixups.
v2 cover qdev: property fixups.
Hi,
Oops, v1 was incomplete, missing some tcx bits and eccmemctl, here is a respin. Sorry for the noise.
Rebased my qdev patches. Figured build broke. BlueSwirl converted a few devices to qdev, using the old property implementation. This patch series fixes it up. Done as incremental as anthony has my qdev patches already in his queue. Changes:
* adds 16bit integer property.
* adds target_phys_addr_t property (separate source+header to not drag the target_phys_addr_t dependeny into everything which includes qdev.h).
* switch over m48t59 and tcx to the new property implementation.
This is purely to fixup the build, the type checking issues raised by Paul are not (yet) addressed. Will look into this later today.
cheers,
Gerd
PATCH v2 1/7 qdev/prop: make uint32 accept both hex and decimal.
--- hw/qdev-properties.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
hw/qdev-properties.c +4 -1
@@ -12,8 +12,11 @@ static void *prop_ptr(DeviceState *dev, Property *prop)static int parse_uint32 (DeviceState *dev,Property *prop,const char *str) {uint32_t *ptr =prop_ptr (dev, prop); +const char *fmt; -if (sscanf (str,"%" PRIu32, ptr) !=1 ) +/* accept both hex and decimal */ + fmt =strncasecmp (str,"0x" ,2 ) ==0 ?"%" PRIx32 :"%" PRIu32; +if (sscanf (str, fmt, ptr) !=1 )return -1 ;return 0 ; }
Signature · 1 line
1.6.2.5
PATCH v2 2/7 qdev/prop: add 16bit integer type.
In reply to Gerd Hoffmann--- hw/qdev-properties.c | 32 ++++++++++++++++++++++++++++++++ hw/qdev.h | 2 ++ 2 files changed, 34 insertions(+), 0 deletions(-)
hw/qdev-properties.c +32 -0
@@ -7,6 +7,33 @@ static void *prop_ptr(DeviceState *dev, Property *prop)return ptr; } +/* --- 16bit integer --- */ + +static int parse_uint16 (DeviceState *dev,Property *prop,const char *str) +{ +uint16_t *ptr =prop_ptr (dev, prop); +const char *fmt; + +/* accept both hex and decimal */ + fmt =strncasecmp (str,"0x" ,2 ) ==0 ?"%" PRIx16 :"%" PRIu16; +if (sscanf (str, fmt, ptr) !=1 ) +return -1 ; +return 0 ; +} + +static int print_uint16 (DeviceState *dev,Property *prop,char *dest,size_t len) +{ +uint16_t *ptr =prop_ptr (dev, prop); +return snprintf (dest, len,"%" PRIu16, *ptr); +} + +PropertyInfo qdev_prop_uint16 = { + .name ="uint16" , + .size =sizeof (uint16_t ), + .parse = parse_uint16, + .print = print_uint16, +}; +/* --- 32bit integer --- */ static int parse_uint32 (DeviceState *dev,Property *prop,const char *str)
@@ -183,6 +210,11 @@ int qdev_prop_set(DeviceState *dev, const char *name, void *src, size_t size)return 0 ; } +int qdev_prop_set_uint16 (DeviceState *dev,const char *name,uint16_t value) +{ +return qdev_prop_set (dev, name, &value,sizeof (value)); +} +int qdev_prop_set_uint32 (DeviceState *dev,const char *name,uint32_t value) {return qdev_prop_set (dev, name, &value,sizeof (value));
hw/qdev.h +2 -0
@@ -128,6 +128,7 @@ void do_info_qtree(Monitor *mon);/*** qdev-properties.c ***/ +extern PropertyInfo qdev_prop_uint16;extern PropertyInfo qdev_prop_uint32;extern PropertyInfo qdev_prop_hex32;extern PropertyInfo qdev_prop_ptr;
@@ -136,6 +137,7 @@ extern PropertyInfo qdev_prop_mac;/* Set properties between creation and init. */ int qdev_prop_parse (DeviceState *dev,const char *name,const char *value);int qdev_prop_set (DeviceState *dev,const char *name,void *src,size_t size); +int qdev_prop_set_uint16 (DeviceState *dev,const char *name,uint16_t value);int qdev_prop_set_uint32 (DeviceState *dev,const char *name,uint32_t value);/* FIXME: Remove opaque pointer properties. */ int qdev_prop_set_ptr (DeviceState *dev,const char *name,void *value);
Signature · 1 line
1.6.2.5
PATCH v2 3/7 qdev/prop: unstatic and rename prop_ptr()
In reply to Gerd Hoffmann--- hw/qdev-properties.c | 24 ++++++++++++------------ hw/qdev.h | 1 + 2 files changed, 13 insertions(+), 12 deletions(-)
hw/qdev-properties.c +12 -12
@@ -1,6 +1,6 @@#include "qdev.h" -static void *prop_ptr (DeviceState *dev,Property *prop) +void *qdev_get_prop_ptr (DeviceState *dev,Property *prop) {void *ptr = dev; ptr += prop->offset;
@@ -11,7 +11,7 @@ static void *prop_ptr(DeviceState *dev, Property *prop)static int parse_uint16 (DeviceState *dev,Property *prop,const char *str) { -uint16_t *ptr =prop_ptr (dev, prop); +uint16_t *ptr =qdev_get_prop_ptr (dev, prop);const char *fmt;/* accept both hex and decimal */
@@ -23,7 +23,7 @@ static int parse_uint16(DeviceState *dev, Property *prop, const char *str)static int print_uint16 (DeviceState *dev,Property *prop,char *dest,size_t len) { -uint16_t *ptr =prop_ptr (dev, prop); +uint16_t *ptr =qdev_get_prop_ptr (dev, prop);return snprintf (dest, len,"%" PRIu16, *ptr); }
@@ -38,7 +38,7 @@ PropertyInfo qdev_prop_uint16 = {static int parse_uint32 (DeviceState *dev,Property *prop,const char *str) { -uint32_t *ptr =prop_ptr (dev, prop); +uint32_t *ptr =qdev_get_prop_ptr (dev, prop);const char *fmt;/* accept both hex and decimal */
@@ -50,7 +50,7 @@ static int parse_uint32(DeviceState *dev, Property *prop, const char *str)static int print_uint32 (DeviceState *dev,Property *prop,char *dest,size_t len) { -uint32_t *ptr =prop_ptr (dev, prop); +uint32_t *ptr =qdev_get_prop_ptr (dev, prop);return snprintf (dest, len,"%" PRIu32, *ptr); }
@@ -65,7 +65,7 @@ PropertyInfo qdev_prop_uint32 = {static int parse_hex32 (DeviceState *dev,Property *prop,const char *str) { -uint32_t *ptr =prop_ptr (dev, prop); +uint32_t *ptr =qdev_get_prop_ptr (dev, prop);if (sscanf (str,"%" PRIx32, ptr) !=1 )return -1 ;
@@ -74,7 +74,7 @@ static int parse_hex32(DeviceState *dev, Property *prop, const char *str)static int print_hex32 (DeviceState *dev,Property *prop,char *dest,size_t len) { -uint32_t *ptr =prop_ptr (dev, prop); +uint32_t *ptr =qdev_get_prop_ptr (dev, prop);return snprintf (dest, len,"0x%" PRIx32, *ptr); }
@@ -89,7 +89,7 @@ PropertyInfo qdev_prop_hex32 = {static int print_ptr (DeviceState *dev,Property *prop,char *dest,size_t len) { -void **ptr =prop_ptr (dev, prop); +void **ptr =qdev_get_prop_ptr (dev, prop);return snprintf (dest, len,"<%p>" , *ptr); }
@@ -108,7 +108,7 @@ PropertyInfo qdev_prop_ptr = {*/ static int parse_mac (DeviceState *dev,Property *prop,const char *str) { -uint8_t *mac =prop_ptr (dev, prop); +uint8_t *mac =qdev_get_prop_ptr (dev, prop);int i, pos;char *p;
@@ -128,7 +128,7 @@ static int parse_mac(DeviceState *dev, Property *prop, const char *str)static int print_mac (DeviceState *dev,Property *prop,char *dest,size_t len) { -uint8_t *mac =prop_ptr (dev, prop); +uint8_t *mac =qdev_get_prop_ptr (dev, prop);return snprintf (dest, len,"%02x:%02x:%02x:%02x:%02x:%02x" , mac[0 ], mac[1 ], mac[2 ], mac[3 ], mac[4 ], mac[5 ]); }
@@ -205,7 +205,7 @@ int qdev_prop_set(DeviceState *dev, const char *name, void *src, size_t size) dev->info->name, name, prop->info->size, size);return -1 ; } - dst =prop_ptr (dev, prop); + dst =qdev_get_prop_ptr (dev, prop);memcpy (dst, src, size);return 0 ; }
@@ -233,7 +233,7 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props)return ;while (props->name) {if (props->defval) { - dst =prop_ptr (dev, props); + dst =qdev_get_prop_ptr (dev, props);memcpy (dst, props->defval, props->info->size); } props++;
hw/qdev.h +1 -0
@@ -135,6 +135,7 @@ extern PropertyInfo qdev_prop_ptr;extern PropertyInfo qdev_prop_mac;/* Set properties between creation and init. */ +void *qdev_get_prop_ptr (DeviceState *dev,Property *prop);int qdev_prop_parse (DeviceState *dev,const char *name,const char *value);int qdev_prop_set (DeviceState *dev,const char *name,void *src,size_t size);int qdev_prop_set_uint16 (DeviceState *dev,const char *name,uint16_t value);
Signature · 1 line
1.6.2.5
PATCH v2 4/7 qdev/prop: add property for target_phys_addr_t
In reply to Gerd Hoffmann--- Makefile.hw | 2 +- hw/qdev-addr.c | 31 +++++++++++++++++++++++++++++++ hw/qdev-addr.h | 2 ++ 3 files changed, 34 insertions(+), 1 deletions(-) create mode 100644 hw/qdev-addr.c create mode 100644 hw/qdev-addr.h
Makefile.hw +1 -1
@@ -26,7 +26,7 @@ obj-y += m48t59.o escc.o # SCSI layer obj-y += lsi53c895a.o esp.o -obj-y += dma-helpers.o sysbus.o +obj-y += dma-helpers.o sysbus.o qdev-addr.o all: $(HWLIB) # Dummy command so that make thinks it has done something
hw/qdev-addr.c new file +31 -0
@@ -0,0 +1,31 @@ +#include "qdev.h" +#include "qdev-addr.h" +#include "targphys.h" + +/* --- target physical address --- */ + +static int parse_taddr (DeviceState *dev,Property *prop,const char *str) +{ +target_phys_addr_t *ptr =qdev_get_prop_ptr (dev, prop); + + *ptr =strtoull (str,NULL ,16 ); +return 0 ; +} + +static int print_taddr (DeviceState *dev,Property *prop,char *dest,size_t len) +{ +target_phys_addr_t *ptr =qdev_get_prop_ptr (dev, prop); +return snprintf (dest, len,"0x" TARGET_FMT_plx, *ptr); +} + +PropertyInfo qdev_prop_taddr = { + .name ="taddr" , + .size =sizeof (target_phys_addr_t), + .parse = parse_taddr, + .print = print_taddr, +}; + +int qdev_prop_set_taddr (DeviceState *dev,const char *name,target_phys_addr_t value) +{ +return qdev_prop_set (dev, name, &value,sizeof (value)); +}
hw/qdev-addr.h new file +2 -0
@@ -0,0 +1,2 @@ +extern PropertyInfo qdev_prop_taddr; +int qdev_prop_set_taddr (DeviceState *dev,const char *name,target_phys_addr_t value);
Signature · 1 line
1.6.2.5
PATCH v2 5/7 qdev/prop: convert m48t59
In reply to Gerd Hoffmann--- hw/m48t59.c | 39 ++++++++++++++++++++++++++++++--------- 1 files changed, 30 insertions(+), 9 deletions(-)
hw/m48t59.c +30 -9
@@ -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)
Signature · 1 line
1.6.2.5
PATCH v2 6/7 qdev/prop: convert tcx
In reply to Gerd Hoffmann--- hw/tcx.c | 65 +++++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 48 insertions(+), 17 deletions(-)
hw/tcx.c +48 -17
@@ -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 ];
@@ -506,11 +508,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 */
@@ -537,22 +539,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;
@@ -570,7 +566,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);
@@ -578,7 +574,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);
@@ -664,9 +660,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)
Signature · 1 line
1.6.2.5
PATCH v2 7/7 qdev/prop: convert eccmemctl
In reply to Gerd Hoffmann--- hw/eccmemctl.c | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-)
hw/eccmemctl.c +18 -3
@@ -321,7 +321,6 @@ static void ecc_init1(SysBusDevice *dev)ECCState *s =FROM_SYSBUS (ECCState, dev);sysbus_init_irq (dev, &s->irq); - s->version =qdev_get_prop_int (&dev->qdev,"version" ,-1 ); s->regs[0 ] = s->version; ecc_io_memory =cpu_register_io_memory (ecc_mem_read, ecc_mem_write, s);sysbus_init_mmio (dev,ECC_SIZE , ecc_io_memory);
@@ -342,7 +341,7 @@ void ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version)SysBusDevice *s; dev =qdev_create (NULL ,"eccmemctl" ); -qdev_set_prop_int (dev,"version" , version); +qdev_prop_set_uint32 (dev,"version" , version);qdev_init (dev); s =sysbus_from_qdev (dev);sysbus_connect_irq (s,0 , irq);
@@ -352,9 +351,25 @@ void ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version) } } +static SysBusDeviceInfo ecc_info = { + .init = ecc_init1, + .qdev.name ="eccmemctl" , + .qdev.size =sizeof (ECCState), + .qdev.props = (Property []) { + { + .name ="version" , + .info = &qdev_prop_uint32, + .offset = offsetof(ECCState , version), + .defval = (uint32_t []) {-1 }, + }, + {/* end of list */ } + } +}; + +static void ecc_register_devices (void ) { -sysbus_register_dev ("eccmemctl" ,sizeof (ECCState), ecc_init1); +sysbus_register_withprop (&ecc_info); }device_init (ecc_register_devices)
Signature · 1 line
1.6.2.5
Quoted 11 lines · Gerd Hoffmann
Hi,
Oops, v1 was incomplete, missing some tcx bits and eccmemctl, here is a respin. Sorry for the noise.
Rebased my qdev patches. Figured build broke. BlueSwirl converted a few devices to qdev, using the old property implementation. This patch series fixes it up. Done as incremental as anthony has my qdev patches already in his queue. Changes:
Quoted 8 lines
* adds 16bit integer property.
* addstarget_phys_addr_tproperty (separate source+header to not drag thetarget_phys_addr_tdependeny into everything which includesqdev.h).
* switch over m48t59 and tcx to the new property implementation.This is purely to fixup the build, the type checking issues raised by Paul are not (yet) addressed. Will look into this later today.
At least the m48t59, tcx and eccmemctl bits look fine.