virtio.c (0175409df42c20257171df87657dd705558aa94d) | virtio.c (95129d6fc9ead97155627a4ca0cfd37282883658) |
---|---|
1/* 2 * Virtio Support 3 * 4 * Copyright IBM, Corp. 2007 5 * 6 * Authors: 7 * Anthony Liguori <aliguori@us.ibm.com> 8 * --- 206 unchanged lines hidden (view full) --- 215 } 216 pa = vq->vring.used + offsetof(VRingUsed, ring[vq->vring.num]); 217 virtio_stw_phys(vq->vdev, pa, val); 218} 219 220void virtio_queue_set_notification(VirtQueue *vq, int enable) 221{ 222 vq->notification = enable; | 1/* 2 * Virtio Support 3 * 4 * Copyright IBM, Corp. 2007 5 * 6 * Authors: 7 * Anthony Liguori <aliguori@us.ibm.com> 8 * --- 206 unchanged lines hidden (view full) --- 215 } 216 pa = vq->vring.used + offsetof(VRingUsed, ring[vq->vring.num]); 217 virtio_stw_phys(vq->vdev, pa, val); 218} 219 220void virtio_queue_set_notification(VirtQueue *vq, int enable) 221{ 222 vq->notification = enable; |
223 if (virtio_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) { | 223 if (virtio_vdev_has_feature(vq->vdev, VIRTIO_RING_F_EVENT_IDX)) { |
224 vring_set_avail_event(vq, vring_avail_idx(vq)); 225 } else if (enable) { 226 vring_used_flags_unset_bit(vq, VRING_USED_F_NO_NOTIFY); 227 } else { 228 vring_used_flags_set_bit(vq, VRING_USED_F_NO_NOTIFY); 229 } 230 if (enable) { 231 /* Expose avail event/used flags before caller checks the avail idx. */ --- 234 unchanged lines hidden (view full) --- 466 return 0; 467 468 /* When we start there are none of either input nor output. */ 469 elem->out_num = elem->in_num = 0; 470 471 max = vq->vring.num; 472 473 i = head = virtqueue_get_head(vq, vq->last_avail_idx++); | 224 vring_set_avail_event(vq, vring_avail_idx(vq)); 225 } else if (enable) { 226 vring_used_flags_unset_bit(vq, VRING_USED_F_NO_NOTIFY); 227 } else { 228 vring_used_flags_set_bit(vq, VRING_USED_F_NO_NOTIFY); 229 } 230 if (enable) { 231 /* Expose avail event/used flags before caller checks the avail idx. */ --- 234 unchanged lines hidden (view full) --- 466 return 0; 467 468 /* When we start there are none of either input nor output. */ 469 elem->out_num = elem->in_num = 0; 470 471 max = vq->vring.num; 472 473 i = head = virtqueue_get_head(vq, vq->last_avail_idx++); |
474 if (virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { | 474 if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { |
475 vring_set_avail_event(vq, vq->last_avail_idx); 476 } 477 478 if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_INDIRECT) { 479 if (vring_desc_len(vdev, desc_pa, i) % sizeof(VRingDesc)) { 480 error_report("Invalid size for indirect buffer table"); 481 exit(1); 482 } --- 72 unchanged lines hidden (view full) --- 555 } 556} 557 558int virtio_set_status(VirtIODevice *vdev, uint8_t val) 559{ 560 VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); 561 trace_virtio_set_status(vdev, val); 562 | 475 vring_set_avail_event(vq, vq->last_avail_idx); 476 } 477 478 if (vring_desc_flags(vdev, desc_pa, i) & VRING_DESC_F_INDIRECT) { 479 if (vring_desc_len(vdev, desc_pa, i) % sizeof(VRingDesc)) { 480 error_report("Invalid size for indirect buffer table"); 481 exit(1); 482 } --- 72 unchanged lines hidden (view full) --- 555 } 556} 557 558int virtio_set_status(VirtIODevice *vdev, uint8_t val) 559{ 560 VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); 561 trace_virtio_set_status(vdev, val); 562 |
563 if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) { | 563 if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { |
564 if (!(vdev->status & VIRTIO_CONFIG_S_FEATURES_OK) && 565 val & VIRTIO_CONFIG_S_FEATURES_OK) { 566 int ret = virtio_validate_features(vdev); 567 568 if (ret) { 569 return ret; 570 } 571 } --- 321 unchanged lines hidden (view full) --- 893} 894 895void virtio_queue_set_align(VirtIODevice *vdev, int n, int align) 896{ 897 BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); 898 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); 899 900 /* virtio-1 compliant devices cannot change the alignment */ | 564 if (!(vdev->status & VIRTIO_CONFIG_S_FEATURES_OK) && 565 val & VIRTIO_CONFIG_S_FEATURES_OK) { 566 int ret = virtio_validate_features(vdev); 567 568 if (ret) { 569 return ret; 570 } 571 } --- 321 unchanged lines hidden (view full) --- 893} 894 895void virtio_queue_set_align(VirtIODevice *vdev, int n, int align) 896{ 897 BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); 898 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); 899 900 /* virtio-1 compliant devices cannot change the alignment */ |
901 if (virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) { | 901 if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { |
902 error_report("tried to modify queue alignment for virtio-1 device"); 903 return; 904 } 905 /* Check that the transport told us it was going to do this 906 * (so a buggy transport will immediately assert rather than 907 * silently failing to migrate this state) 908 */ 909 assert(k->has_variable_vring_alignment); --- 78 unchanged lines hidden (view full) --- 988 989static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq) 990{ 991 uint16_t old, new; 992 bool v; 993 /* We need to expose used array entries before checking used event. */ 994 smp_mb(); 995 /* Always notify when queue is empty (when feature acknowledge) */ | 902 error_report("tried to modify queue alignment for virtio-1 device"); 903 return; 904 } 905 /* Check that the transport told us it was going to do this 906 * (so a buggy transport will immediately assert rather than 907 * silently failing to migrate this state) 908 */ 909 assert(k->has_variable_vring_alignment); --- 78 unchanged lines hidden (view full) --- 988 989static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq) 990{ 991 uint16_t old, new; 992 bool v; 993 /* We need to expose used array entries before checking used event. */ 994 smp_mb(); 995 /* Always notify when queue is empty (when feature acknowledge) */ |
996 if (virtio_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) && | 996 if (virtio_vdev_has_feature(vdev, VIRTIO_F_NOTIFY_ON_EMPTY) && |
997 !vq->inuse && vring_avail_idx(vq) == vq->last_avail_idx) { 998 return true; 999 } 1000 | 997 !vq->inuse && vring_avail_idx(vq) == vq->last_avail_idx) { 998 return true; 999 } 1000 |
1001 if (!virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { | 1001 if (!virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { |
1002 return !(vring_avail_flags(vq) & VRING_AVAIL_F_NO_INTERRUPT); 1003 } 1004 1005 v = vq->signalled_used_valid; 1006 vq->signalled_used_valid = true; 1007 old = vq->signalled_used; 1008 new = vq->signalled_used = vring_used_idx(vq); 1009 return !v || vring_need_event(vring_get_used_event(vq), new, old); --- 20 unchanged lines hidden (view full) --- 1030 virtio_notify_vector(vdev, vdev->config_vector); 1031} 1032 1033static bool virtio_device_endian_needed(void *opaque) 1034{ 1035 VirtIODevice *vdev = opaque; 1036 1037 assert(vdev->device_endian != VIRTIO_DEVICE_ENDIAN_UNKNOWN); | 1002 return !(vring_avail_flags(vq) & VRING_AVAIL_F_NO_INTERRUPT); 1003 } 1004 1005 v = vq->signalled_used_valid; 1006 vq->signalled_used_valid = true; 1007 old = vq->signalled_used; 1008 new = vq->signalled_used = vring_used_idx(vq); 1009 return !v || vring_need_event(vring_get_used_event(vq), new, old); --- 20 unchanged lines hidden (view full) --- 1030 virtio_notify_vector(vdev, vdev->config_vector); 1031} 1032 1033static bool virtio_device_endian_needed(void *opaque) 1034{ 1035 VirtIODevice *vdev = opaque; 1036 1037 assert(vdev->device_endian != VIRTIO_DEVICE_ENDIAN_UNKNOWN); |
1038 if (!virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) { | 1038 if (!virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { |
1039 return vdev->device_endian != virtio_default_endian(); 1040 } 1041 /* Devices conforming to VIRTIO 1.0 or later are always LE. */ 1042 return vdev->device_endian != VIRTIO_DEVICE_ENDIAN_LITTLE; 1043} 1044 1045static bool virtio_64bit_features_needed(void *opaque) 1046{ --- 592 unchanged lines hidden --- | 1039 return vdev->device_endian != virtio_default_endian(); 1040 } 1041 /* Devices conforming to VIRTIO 1.0 or later are always LE. */ 1042 return vdev->device_endian != VIRTIO_DEVICE_ENDIAN_LITTLE; 1043} 1044 1045static bool virtio_64bit_features_needed(void *opaque) 1046{ --- 592 unchanged lines hidden --- |