qdev: add 64bit properties
PATCH v2 1/2 qdev: add 64bit properties
Needed for virtio features which go from 32bit to 64bit with virtio 1.0
Signed-off-by Gerd Hoffmann <[email protected]>
--- hw/core/qdev-properties.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/qdev-properties.h | 10 ++++++++ 2 files changed, 68 insertions(+)
hw/core/qdev-properties.c +58 -0
@@ -125,6 +125,64 @@ PropertyInfo qdev_prop_bit = { .set = prop_set_bit, }; +/* Bit64 */ + +static uint64_t qdev_get_prop_mask64 (Property *prop) +{ +assert (prop->info == &qdev_prop_bit); +return 0x1 << prop->bitnr; +} + +static void bit64_prop_set (DeviceState *dev,Property *props,bool val) +{ +uint64_t *p =qdev_get_prop_ptr (dev, props); +uint64_t mask =qdev_get_prop_mask64 (props); +if (val) { + *p |= mask; + }else { + *p &= ~mask; + } +} + +static void prop_get_bit64 (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +Property *prop = opaque; +uint64_t *p =qdev_get_prop_ptr (dev, prop); +bool value = (*p &qdev_get_prop_mask64 (prop)) !=0 ; + +visit_type_bool (v, &value, name, errp); +} + +static void prop_set_bit64 (Object *obj,Visitor *v,void *opaque, +const char *name,Error **errp) +{ +DeviceState *dev =DEVICE (obj); +Property *prop = opaque; +Error *local_err =NULL ; +bool value; + +if (dev->realized) { +qdev_prop_set_after_realize (dev, name, errp); +return ; + } + +visit_type_bool (v, &value, name, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } +bit64_prop_set (dev, prop, value); +} + +PropertyInfo qdev_prop_bit64 = { + .name ="bool" , + .description ="on/off" , + .get = prop_get_bit64, + .set = prop_set_bit64, +}; +/* --- bool --- */ static void get_bool(Object *obj, Visitor *v, void *opaque,
include/hw/qdev-properties.h +10 -0
@@ -6,6 +6,7 @@/*** qdev-properties.c ***/ extern PropertyInfo qdev_prop_bit; +extern PropertyInfo qdev_prop_bit64;extern PropertyInfo qdev_prop_bool;extern PropertyInfo qdev_prop_uint8;extern PropertyInfo qdev_prop_uint16;
@@ -50,6 +51,15 @@ extern PropertyInfo qdev_prop_arraylen; .qtype = QTYPE_QBOOL, \ .defval = (bool)_defval, \ } +#define DEFINE_PROP_BIT64 (_name, _state, _field, _bit, _defval) { \ + .name = (_name), \ + .info = &(qdev_prop_bit), \ + .bitnr = (_bit), \ + .offset = offsetof(_state, _field) \ + + type_check(uint64_t, typeof_field(_state, _field)), \ + .qtype = QTYPE_QBOOL, \ + .defval = (bool)_defval, \ + }#define DEFINE_PROP_BOOL (_name, _state, _field, _defval) { \ .name = (_name), \
Signature · 1 line
1.8.3.1
PATCH v2 2/2 virtio: make features 64bit wide
Make features 64bit wide everywhere.
On migration a full 64bit guest_features field is sent if one of the high bits is set, in addition to the lower 32bit guest_features field which must stay for compatibility reasons. That way we send the lower 32 feature bits twice, but the code is simpler because we don't have to split and compose the 64bit features into two 32bit fields.
Signed-off-by Gerd Hoffmann <[email protected]>
--- hw/9pfs/virtio-9p-device.c | 2 +- hw/block/virtio-blk.c | 2 +- hw/char/virtio-serial-bus.c | 2 +- hw/input/virtio-input.c | 2 +- hw/net/virtio-net.c | 18 +++++++++------- hw/scsi/vhost-scsi.c | 4 ++-- hw/scsi/virtio-scsi.c | 4 ++-- hw/virtio/virtio-balloon.c | 2 +- hw/virtio/virtio-rng.c | 2 +- hw/virtio/virtio.c | 51 +++++++++++++++++++++++++++++++++++++++------ include/hw/virtio/virtio.h | 28 ++++++++++++------------- 11 files changed, 79 insertions(+), 38 deletions(-)
hw/9pfs/virtio-9p-device.c +1 -1
@@ -21,7 +21,7 @@#include "virtio-9p-coth.h" #include "hw/virtio/virtio-access.h" -static uint32_t virtio_9p_get_features (VirtIODevice *vdev,uint32_t features) +static uint64_t virtio_9p_get_features (VirtIODevice *vdev,uint64_t features) {virtio_add_feature (&features,VIRTIO_9P_MOUNT_TAG );return features;
hw/block/virtio-blk.c +1 -1
@@ -718,7 +718,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)aio_context_release (blk_get_aio_context (s->blk)); } -static uint32_t virtio_blk_get_features (VirtIODevice *vdev,uint32_t features) +static uint64_t virtio_blk_get_features (VirtIODevice *vdev,uint64_t features) {VirtIOBlock *s =VIRTIO_BLK (vdev);
hw/char/virtio-serial-bus.c +1 -1
@@ -498,7 +498,7 @@ static void handle_input(VirtIODevice *vdev, VirtQueue *vq) } } -static uint32_t get_features (VirtIODevice *vdev,uint32_t features) +static uint64_t get_features (VirtIODevice *vdev,uint64_t features) {VirtIOSerial *vser;
hw/input/virtio-input.c +1 -1
@@ -166,7 +166,7 @@ static void virtio_input_set_config(VirtIODevice *vdev,virtio_notify_config (vdev); } -static uint32_t virtio_input_get_features (VirtIODevice *vdev,uint32_t f) +static uint64_t virtio_input_get_features (VirtIODevice *vdev,uint64_t f) {return f; }
hw/net/virtio-net.c +10 -8
@@ -435,7 +435,7 @@ static void virtio_net_set_queues(VirtIONet *n)static void virtio_net_set_multiqueue (VirtIONet *n,int multiqueue); -static uint32_t virtio_net_get_features (VirtIODevice *vdev,uint32_t features) +static uint64_t virtio_net_get_features (VirtIODevice *vdev,uint64_t features) {VirtIONet *n =VIRTIO_NET (vdev);NetClientState *nc =qemu_get_queue (n->nic);
@@ -468,9 +468,9 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev, uint32_t features)return vhost_net_get_features (get_vhost_net (nc->peer), features); } -static uint32_t virtio_net_bad_features (VirtIODevice *vdev) +static uint64_t virtio_net_bad_features (VirtIODevice *vdev) { -uint32_t features =0 ; +uint64_t features =0 ;/* Linux kernel 2.6.25. It understood MAC (as everyone must), * but also these: */
@@ -1032,10 +1032,12 @@ static ssize_t virtio_net_receive(NetClientState *nc, const uint8_t *buf, size_tif (i ==0 )return -1 ;error_report ("virtio-net unexpected empty queue: " -"i %zd mergeable %d offset %zd, size %zd, " -"guest hdr len %zd, host hdr len %zd guest features 0x%x" , - i, n->mergeable_rx_bufs, offset, size, - n->guest_hdr_len, n->host_hdr_len, vdev->guest_features); +"i %zd mergeable %d offset %zd, size %zd, " +"guest hdr len %zd, host hdr len %zd " +"guest features 0x%" PRIx64, + i, n->mergeable_rx_bufs, offset, size, + n->guest_hdr_len, n->host_hdr_len, + vdev->guest_features);exit (1 ); }
@@ -1549,7 +1551,7 @@ static void virtio_net_guest_notifier_mask(VirtIODevice *vdev, int idx, vdev, idx, mask); } -static void virtio_net_set_config_size (VirtIONet *n,uint32_t host_features) +static void virtio_net_set_config_size (VirtIONet *n,uint64_t host_features) {int i, config_size =0 ;virtio_add_feature (&host_features,VIRTIO_NET_F_MAC );
hw/scsi/vhost-scsi.c +2 -2
@@ -151,8 +151,8 @@ static void vhost_scsi_stop(VHostSCSI *s)vhost_dev_disable_notifiers (&s->dev, vdev); } -static uint32_t vhost_scsi_get_features (VirtIODevice *vdev, -uint32_t features) +static uint64_t vhost_scsi_get_features (VirtIODevice *vdev, +uint64_t features) {VHostSCSI *s =VHOST_SCSI (vdev);
hw/scsi/virtio-scsi.c +2 -2
@@ -628,8 +628,8 @@ static void virtio_scsi_set_config(VirtIODevice *vdev, vs->cdb_size =virtio_ldl_p (vdev, &scsiconf->cdb_size); } -static uint32_t virtio_scsi_get_features (VirtIODevice *vdev, -uint32_t requested_features) +static uint64_t virtio_scsi_get_features (VirtIODevice *vdev, +uint64_t requested_features) {VirtIOSCSI *s =VIRTIO_SCSI (vdev);
hw/virtio/virtio-balloon.c +1 -1
@@ -310,7 +310,7 @@ static void virtio_balloon_set_config(VirtIODevice *vdev,trace_virtio_balloon_set_config (dev->actual, oldactual); } -static uint32_t virtio_balloon_get_features (VirtIODevice *vdev,uint32_t f) +static uint64_t virtio_balloon_get_features (VirtIODevice *vdev,uint64_t f) { f |= (1 <<VIRTIO_BALLOON_F_STATS_VQ );return f;
hw/virtio/virtio-rng.c +1 -1
@@ -99,7 +99,7 @@ static void handle_input(VirtIODevice *vdev, VirtQueue *vq)virtio_rng_process (vrng); } -static uint32_t get_features (VirtIODevice *vdev,uint32_t f) +static uint64_t get_features (VirtIODevice *vdev,uint64_t f) {return f; }
hw/virtio/virtio.c +45 -6
93 lines not on this page · raw message
include/hw/virtio/virtio.h +14 -14
@@ -73,8 +73,8 @@ struct VirtIODeviceuint8_t status;uint8_t isr;uint16_t queue_sel; -uint32_t guest_features; -uint32_t host_features; +uint64_t guest_features; +uint64_t host_features;size_t config_len;void *config;uint16_t config_vector;
@@ -96,8 +96,8 @@ typedef struct VirtioDeviceClass {/* This is what a VirtioDevice must implement */ DeviceRealize realize;DeviceUnrealize unrealize; -uint32_t (*get_features)(VirtIODevice *vdev,uint32_t requested_features); -uint32_t (*bad_features)(VirtIODevice *vdev); +uint64_t (*get_features)(VirtIODevice *vdev,uint64_t requested_features); +uint64_t (*bad_features)(VirtIODevice *vdev);void (*set_features)(VirtIODevice *vdev,uint32_t val);void (*get_config)(VirtIODevice *vdev,uint8_t *config);void (*set_config)(VirtIODevice *vdev,const uint8_t *config);
@@ -194,10 +194,10 @@ typedef struct VirtIOSCSIConf VirtIOSCSIConf;typedef struct VirtIORNGConf VirtIORNGConf ;#define DEFINE_VIRTIO_COMMON_FEATURES (_state, _field) \ - DEFINE_PROP_BIT("indirect_desc", _state, _field, \ - VIRTIO_RING_F_INDIRECT_DESC, true), \ - DEFINE_PROP_BIT("event_idx", _state, _field, \ - VIRTIO_RING_F_EVENT_IDX, true) + DEFINE_PROP_BIT64("indirect_desc", _state, _field, \ + VIRTIO_RING_F_INDIRECT_DESC, true), \ + DEFINE_PROP_BIT64("event_idx", _state, _field, \ + VIRTIO_RING_F_EVENT_IDX, true)hwaddr virtio_queue_get_desc_addr (VirtIODevice *vdev,int n);hwaddr virtio_queue_get_avail_addr (VirtIODevice *vdev,int n);
@@ -224,21 +224,21 @@ void virtio_irq(VirtQueue *vq);VirtQueue *virtio_vector_first_queue (VirtIODevice *vdev,uint16_t vector);VirtQueue *virtio_vector_next_queue (VirtQueue *vq); -static inline void virtio_add_feature (uint32_t *features,unsigned int fbit) +static inline void virtio_add_feature (uint64_t *features,unsigned int fbit) { -assert (fbit <32 ); +assert (fbit <64 ); *features |= (1 << fbit); } -static inline void virtio_clear_feature (uint32_t *features,unsigned int fbit) +static inline void virtio_clear_feature (uint64_t *features,unsigned int fbit) { -assert (fbit <32 ); +assert (fbit <64 ); *features &= ~(1 << fbit); } -static inline bool __virtio_has_feature (uint32_t features,unsigned int fbit) +static inline bool __virtio_has_feature (uint64_t features,unsigned int fbit) { -assert (fbit <32 ); +assert (fbit <64 );return !!(features & (1 << fbit)); }
Signature · 1 line
1.8.3.1