aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/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 /drivers/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 'drivers/virtio')
-rw-r--r--drivers/virtio/virtio.c10
-rw-r--r--drivers/virtio/virtio_mmio.c8
-rw-r--r--drivers/virtio/virtio_pci.c3
-rw-r--r--drivers/virtio/virtio_ring.c2
4 files changed, 9 insertions, 14 deletions
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index df598dd8c5c8..2b9aafb4d679 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -49,9 +49,9 @@ static ssize_t features_show(struct device *_d,
49 49
50 /* We actually represent this as a bitstring, as it could be 50 /* We actually represent this as a bitstring, as it could be
51 * arbitrary length in future. */ 51 * arbitrary length in future. */
52 for (i = 0; i < ARRAY_SIZE(dev->features)*BITS_PER_LONG; i++) 52 for (i = 0; i < sizeof(dev->features)*8; i++)
53 len += sprintf(buf+len, "%c", 53 len += sprintf(buf+len, "%c",
54 test_bit(i, dev->features) ? '1' : '0'); 54 __virtio_test_bit(dev, i) ? '1' : '0');
55 len += sprintf(buf+len, "\n"); 55 len += sprintf(buf+len, "\n");
56 return len; 56 return len;
57} 57}
@@ -168,18 +168,18 @@ static int virtio_dev_probe(struct device *_d)
168 device_features = dev->config->get_features(dev); 168 device_features = dev->config->get_features(dev);
169 169
170 /* Features supported by both device and driver into dev->features. */ 170 /* Features supported by both device and driver into dev->features. */
171 memset(dev->features, 0, sizeof(dev->features)); 171 dev->features = 0;
172 for (i = 0; i < drv->feature_table_size; i++) { 172 for (i = 0; i < drv->feature_table_size; i++) {
173 unsigned int f = drv->feature_table[i]; 173 unsigned int f = drv->feature_table[i];
174 BUG_ON(f >= 32); 174 BUG_ON(f >= 32);
175 if (device_features & (1 << f)) 175 if (device_features & (1 << f))
176 set_bit(f, dev->features); 176 __virtio_set_bit(dev, f);
177 } 177 }
178 178
179 /* Transport features always preserved to pass to finalize_features. */ 179 /* Transport features always preserved to pass to finalize_features. */
180 for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++) 180 for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++)
181 if (device_features & (1 << i)) 181 if (device_features & (1 << i))
182 set_bit(i, dev->features); 182 __virtio_set_bit(dev, i);
183 183
184 dev->config->finalize_features(dev); 184 dev->config->finalize_features(dev);
185 185
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index ef9a1650bb80..eb5b0e2b434a 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -155,16 +155,12 @@ static u32 vm_get_features(struct virtio_device *vdev)
155static void vm_finalize_features(struct virtio_device *vdev) 155static void vm_finalize_features(struct virtio_device *vdev)
156{ 156{
157 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev); 157 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
158 int i;
159 158
160 /* Give virtio_ring a chance to accept features. */ 159 /* Give virtio_ring a chance to accept features. */
161 vring_transport_features(vdev); 160 vring_transport_features(vdev);
162 161
163 for (i = 0; i < ARRAY_SIZE(vdev->features); i++) { 162 writel(0, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL);
164 writel(i, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL); 163 writel(vdev->features, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
165 writel(vdev->features[i],
166 vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
167 }
168} 164}
169 165
170static void vm_get(struct virtio_device *vdev, unsigned offset, 166static void vm_get(struct virtio_device *vdev, unsigned offset,
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index d34ebfa604f3..4e112c158488 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -120,8 +120,7 @@ static void vp_finalize_features(struct virtio_device *vdev)
120 vring_transport_features(vdev); 120 vring_transport_features(vdev);
121 121
122 /* We only support 32 feature bits. */ 122 /* We only support 32 feature bits. */
123 BUILD_BUG_ON(ARRAY_SIZE(vdev->features) != 1); 123 iowrite32(vdev->features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
124 iowrite32(vdev->features[0], vp_dev->ioaddr+VIRTIO_PCI_GUEST_FEATURES);
125} 124}
126 125
127/* virtio config->get() implementation */ 126/* virtio config->get() implementation */
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 3b1f89b6e743..839247cd8263 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -781,7 +781,7 @@ void vring_transport_features(struct virtio_device *vdev)
781 break; 781 break;
782 default: 782 default:
783 /* We don't understand this bit. */ 783 /* We don't understand this bit. */
784 clear_bit(i, vdev->features); 784 __virtio_clear_bit(vdev, i);
785 } 785 }
786 } 786 }
787} 787}