aboutsummaryrefslogtreecommitdiffstats
path: root/tools/virtio
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2014-10-07 10:39:42 -0400
committerMichael S. Tsirkin <mst@redhat.com>2014-12-09 05:05:23 -0500
commite16e12be34648777606a2c03a3526409b38f0e63 (patch)
tree36298911ba8eed0a4805c2c30a56d92520d23432 /tools/virtio
parentd4024af56f7c6cdb7e721994204fb07b2cda8be9 (diff)
virtio: use u32, not bitmap for features
It seemed like a good idea to use bitmap for features in struct virtio_device, but it's actually a pain, and seems to become even more painful when we get more than 32 feature bits. Just change it to a u32 for now. Based on patch by Rusty. Suggested-by: David Hildenbrand <dahi@linux.vnet.ibm.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Diffstat (limited to 'tools/virtio')
-rw-r--r--tools/virtio/linux/virtio.h22
-rw-r--r--tools/virtio/linux/virtio_config.h2
-rw-r--r--tools/virtio/virtio_test.c5
-rw-r--r--tools/virtio/vringh_test.c16
4 files changed, 12 insertions, 33 deletions
diff --git a/tools/virtio/linux/virtio.h b/tools/virtio/linux/virtio.h
index 5a2d1f0f6bc7..72bff70bfeeb 100644
--- a/tools/virtio/linux/virtio.h
+++ b/tools/virtio/linux/virtio.h
@@ -6,31 +6,11 @@
6/* TODO: empty stubs for now. Broken but enough for virtio_ring.c */ 6/* TODO: empty stubs for now. Broken but enough for virtio_ring.c */
7#define list_add_tail(a, b) do {} while (0) 7#define list_add_tail(a, b) do {} while (0)
8#define list_del(a) do {} while (0) 8#define list_del(a) do {} while (0)
9
10#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
11#define BITS_PER_BYTE 8
12#define BITS_PER_LONG (sizeof(long) * BITS_PER_BYTE)
13#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
14
15/* TODO: Not atomic as it should be:
16 * we don't use this for anything important. */
17static inline void clear_bit(int nr, volatile unsigned long *addr)
18{
19 unsigned long mask = BIT_MASK(nr);
20 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
21
22 *p &= ~mask;
23}
24
25static inline int test_bit(int nr, const volatile unsigned long *addr)
26{
27 return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));
28}
29/* end of stubs */ 9/* end of stubs */
30 10
31struct virtio_device { 11struct virtio_device {
32 void *dev; 12 void *dev;
33 unsigned long features[1]; 13 u32 features;
34}; 14};
35 15
36struct virtqueue { 16struct virtqueue {
diff --git a/tools/virtio/linux/virtio_config.h b/tools/virtio/linux/virtio_config.h
index 5049967f99f7..83b27e8e9d72 100644
--- a/tools/virtio/linux/virtio_config.h
+++ b/tools/virtio/linux/virtio_config.h
@@ -2,5 +2,5 @@
2#define VIRTIO_TRANSPORT_F_END 32 2#define VIRTIO_TRANSPORT_F_END 32
3 3
4#define virtio_has_feature(dev, feature) \ 4#define virtio_has_feature(dev, feature) \
5 test_bit((feature), (dev)->features) 5 (__virtio_test_bit((dev), feature))
6 6
diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c
index 00ea679b3826..db3437c641a6 100644
--- a/tools/virtio/virtio_test.c
+++ b/tools/virtio/virtio_test.c
@@ -60,7 +60,7 @@ void vhost_vq_setup(struct vdev_info *dev, struct vq_info *info)
60{ 60{
61 struct vhost_vring_state state = { .index = info->idx }; 61 struct vhost_vring_state state = { .index = info->idx };
62 struct vhost_vring_file file = { .index = info->idx }; 62 struct vhost_vring_file file = { .index = info->idx };
63 unsigned long long features = dev->vdev.features[0]; 63 unsigned long long features = dev->vdev.features;
64 struct vhost_vring_addr addr = { 64 struct vhost_vring_addr addr = {
65 .index = info->idx, 65 .index = info->idx,
66 .desc_user_addr = (uint64_t)(unsigned long)info->vring.desc, 66 .desc_user_addr = (uint64_t)(unsigned long)info->vring.desc,
@@ -113,8 +113,7 @@ static void vdev_info_init(struct vdev_info* dev, unsigned long long features)
113{ 113{
114 int r; 114 int r;
115 memset(dev, 0, sizeof *dev); 115 memset(dev, 0, sizeof *dev);
116 dev->vdev.features[0] = features; 116 dev->vdev.features = features;
117 dev->vdev.features[1] = features >> 32;
118 dev->buf_size = 1024; 117 dev->buf_size = 1024;
119 dev->buf = malloc(dev->buf_size); 118 dev->buf = malloc(dev->buf_size);
120 assert(dev->buf); 119 assert(dev->buf);
diff --git a/tools/virtio/vringh_test.c b/tools/virtio/vringh_test.c
index 14a4f4cab5b9..9d4b1bca54be 100644
--- a/tools/virtio/vringh_test.c
+++ b/tools/virtio/vringh_test.c
@@ -304,7 +304,7 @@ static int parallel_test(unsigned long features,
304 close(to_guest[1]); 304 close(to_guest[1]);
305 close(to_host[0]); 305 close(to_host[0]);
306 306
307 gvdev.vdev.features[0] = features; 307 gvdev.vdev.features = features;
308 gvdev.to_host_fd = to_host[1]; 308 gvdev.to_host_fd = to_host[1];
309 gvdev.notifies = 0; 309 gvdev.notifies = 0;
310 310
@@ -449,13 +449,13 @@ int main(int argc, char *argv[])
449 bool fast_vringh = false, parallel = false; 449 bool fast_vringh = false, parallel = false;
450 450
451 getrange = getrange_iov; 451 getrange = getrange_iov;
452 vdev.features[0] = 0; 452 vdev.features = 0;
453 453
454 while (argv[1]) { 454 while (argv[1]) {
455 if (strcmp(argv[1], "--indirect") == 0) 455 if (strcmp(argv[1], "--indirect") == 0)
456 vdev.features[0] |= (1 << VIRTIO_RING_F_INDIRECT_DESC); 456 __virtio_set_bit(&vdev, VIRTIO_RING_F_INDIRECT_DESC);
457 else if (strcmp(argv[1], "--eventidx") == 0) 457 else if (strcmp(argv[1], "--eventidx") == 0)
458 vdev.features[0] |= (1 << VIRTIO_RING_F_EVENT_IDX); 458 __virtio_set_bit(&vdev, VIRTIO_RING_F_EVENT_IDX);
459 else if (strcmp(argv[1], "--slow-range") == 0) 459 else if (strcmp(argv[1], "--slow-range") == 0)
460 getrange = getrange_slow; 460 getrange = getrange_slow;
461 else if (strcmp(argv[1], "--fast-vringh") == 0) 461 else if (strcmp(argv[1], "--fast-vringh") == 0)
@@ -468,7 +468,7 @@ int main(int argc, char *argv[])
468 } 468 }
469 469
470 if (parallel) 470 if (parallel)
471 return parallel_test(vdev.features[0], getrange, fast_vringh); 471 return parallel_test(vdev.features, getrange, fast_vringh);
472 472
473 if (posix_memalign(&__user_addr_min, PAGE_SIZE, USER_MEM) != 0) 473 if (posix_memalign(&__user_addr_min, PAGE_SIZE, USER_MEM) != 0)
474 abort(); 474 abort();
@@ -483,7 +483,7 @@ int main(int argc, char *argv[])
483 483
484 /* Set up host side. */ 484 /* Set up host side. */
485 vring_init(&vrh.vring, RINGSIZE, __user_addr_min, ALIGN); 485 vring_init(&vrh.vring, RINGSIZE, __user_addr_min, ALIGN);
486 vringh_init_user(&vrh, vdev.features[0], RINGSIZE, true, 486 vringh_init_user(&vrh, vdev.features, RINGSIZE, true,
487 vrh.vring.desc, vrh.vring.avail, vrh.vring.used); 487 vrh.vring.desc, vrh.vring.avail, vrh.vring.used);
488 488
489 /* No descriptor to get yet... */ 489 /* No descriptor to get yet... */
@@ -652,13 +652,13 @@ int main(int argc, char *argv[])
652 } 652 }
653 653
654 /* Test weird (but legal!) indirect. */ 654 /* Test weird (but legal!) indirect. */
655 if (vdev.features[0] & (1 << VIRTIO_RING_F_INDIRECT_DESC)) { 655 if (__virtio_test_bit(&vdev, VIRTIO_RING_F_INDIRECT_DESC)) {
656 char *data = __user_addr_max - USER_MEM/4; 656 char *data = __user_addr_max - USER_MEM/4;
657 struct vring_desc *d = __user_addr_max - USER_MEM/2; 657 struct vring_desc *d = __user_addr_max - USER_MEM/2;
658 struct vring vring; 658 struct vring vring;
659 659
660 /* Force creation of direct, which we modify. */ 660 /* Force creation of direct, which we modify. */
661 vdev.features[0] &= ~(1 << VIRTIO_RING_F_INDIRECT_DESC); 661 __virtio_clear_bit(&vdev, VIRTIO_RING_F_INDIRECT_DESC);
662 vq = vring_new_virtqueue(0, RINGSIZE, ALIGN, &vdev, true, 662 vq = vring_new_virtqueue(0, RINGSIZE, ALIGN, &vdev, true,
663 __user_addr_min, 663 __user_addr_min,
664 never_notify_host, 664 never_notify_host,