]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
virtio: Rename set_features to finalize_features
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 25 Jul 2008 17:06:07 +0000 (12:06 -0500)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 25 Jul 2008 02:06:12 +0000 (12:06 +1000)
Rather than explicitly handing the features to the lower-level, we just
hand the virtio_device and have it set the features.  This make it clear
that it has the chance to manipulate the features of the device at this
point (and that all feature negotiation is already done).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
drivers/lguest/lguest_device.c
drivers/s390/kvm/kvm_virtio.c
drivers/virtio/virtio.c
drivers/virtio/virtio_pci.c
include/linux/virtio_config.h

index 1a8de57289eb97e5877b9016855cfe9e99adaac1..54fdc2aa48067e28062f8d53484116bc7f7ea1e8 100644 (file)
@@ -98,16 +98,17 @@ static u32 lg_get_features(struct virtio_device *vdev)
        return features;
 }
 
-static void lg_set_features(struct virtio_device *vdev, u32 features)
+static void lg_finalize_features(struct virtio_device *vdev)
 {
-       unsigned int i;
+       unsigned int i, bits;
        struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
        /* Second half of bitmap is features we accept. */
        u8 *out_features = lg_features(desc) + desc->feature_len;
 
        memset(out_features, 0, desc->feature_len);
-       for (i = 0; i < min(desc->feature_len * 8, 32); i++) {
-               if (features & (1 << i))
+       bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
+       for (i = 0; i < bits; i++) {
+               if (test_bit(i, vdev->features))
                        out_features[i / 8] |= (1 << (i % 8));
        }
 }
@@ -297,7 +298,7 @@ static void lg_del_vq(struct virtqueue *vq)
 /* The ops structure which hooks everything together. */
 static struct virtio_config_ops lguest_config_ops = {
        .get_features = lg_get_features,
-       .set_features = lg_set_features,
+       .finalize_features = lg_finalize_features,
        .get = lg_get,
        .set = lg_set,
        .get_status = lg_get_status,
index d41f234bb2c28445361f3027cd39bb2542c93b81..5953510e7d5fe35a6d2b35c2b664c30b655ab089 100644 (file)
@@ -88,16 +88,17 @@ static u32 kvm_get_features(struct virtio_device *vdev)
        return features;
 }
 
-static void kvm_set_features(struct virtio_device *vdev, u32 features)
+static void kvm_finalize_features(struct virtio_device *vdev)
 {
-       unsigned int i;
+       unsigned int i, bits;
        struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
        /* Second half of bitmap is features we accept. */
        u8 *out_features = kvm_vq_features(desc) + desc->feature_len;
 
        memset(out_features, 0, desc->feature_len);
-       for (i = 0; i < min(desc->feature_len * 8, 32); i++) {
-               if (features & (1 << i))
+       bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
+       for (i = 0; i < bits; i++) {
+               if (test_bit(i, vdev->features))
                        out_features[i / 8] |= (1 << (i % 8));
        }
 }
@@ -223,7 +224,7 @@ static void kvm_del_vq(struct virtqueue *vq)
  */
 static struct virtio_config_ops kvm_vq_configspace_ops = {
        .get_features = kvm_get_features,
-       .set_features = kvm_set_features,
+       .finalize_features = kvm_finalize_features,
        .get = kvm_get,
        .set = kvm_set,
        .get_status = kvm_get_status,
index baf103361e3a2053f255f7f7782f955bd4883320..5b78fd0aff0a6d50306c75f80d99f52f97dbe99e 100644 (file)
@@ -113,7 +113,7 @@ static int virtio_dev_probe(struct device *_d)
                        set_bit(f, dev->features);
        }
 
-       /* Transport features are always preserved to pass to set_features. */
+       /* Transport features always preserved to pass to finalize_features. */
        for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++)
                if (device_features & (1 << i))
                        set_bit(i, dev->features);
@@ -122,8 +122,7 @@ static int virtio_dev_probe(struct device *_d)
        if (err)
                add_status(dev, VIRTIO_CONFIG_S_FAILED);
        else {
-               /* They should never have set feature bits beyond 32 */
-               dev->config->set_features(dev, dev->features[0]);
+               dev->config->finalize_features(dev);
                add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
        }
        return err;
index eae7236310e450ce1647a25a480eccad9147dec4..9855975a72a30d5ba166262fec1904961ddce2b8 100644 (file)
@@ -94,12 +94,14 @@ static u32 vp_get_features(struct virtio_device *vdev)
        return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
 }
 
-/* virtio config->set_features() implementation */
-static void vp_set_features(struct virtio_device *vdev, u32 features)
+/* virtio config->finalize_features() implementation */
+static void vp_finalize_features(struct virtio_device *vdev)
 {
        struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 
-       iowrite32(features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
+       /* We only support 32 feature bits. */
+       BUILD_BUG_ON(ARRAY_SIZE(vdev->features) != 1);
+       iowrite32(vdev->features[0], vp_dev->ioaddr+VIRTIO_PCI_GUEST_FEATURES);
 }
 
 /* virtio config->get() implementation */
@@ -297,7 +299,7 @@ static struct virtio_config_ops virtio_pci_config_ops = {
        .find_vq        = vp_find_vq,
        .del_vq         = vp_del_vq,
        .get_features   = vp_get_features,
-       .set_features   = vp_set_features,
+       .finalize_features = vp_finalize_features,
 };
 
 /* the PCI probing function */
index 5a30cfb7934b3fb02caefe7cdf988d3ec6df0953..bf8ec283b232af65116af4fa338ad602f1b8d798 100644 (file)
  * @get_features: get the array of feature bits for this device.
  *     vdev: the virtio_device
  *     Returns the first 32 feature bits (all we currently need).
- * @set_features: confirm what device features we'll be using.
+ * @finalize_features: confirm what device features we'll be using.
  *     vdev: the virtio_device
- *     feature: the first 32 feature bits
+ *     This gives the final feature bits for the device: it can change
+ *     the dev->feature bits if it wants.
  */
 struct virtio_config_ops
 {
@@ -79,7 +80,7 @@ struct virtio_config_ops
                                     void (*callback)(struct virtqueue *));
        void (*del_vq)(struct virtqueue *vq);
        u32 (*get_features)(struct virtio_device *vdev);
-       void (*set_features)(struct virtio_device *vdev, u32 features);
+       void (*finalize_features)(struct virtio_device *vdev);
 };
 
 /* If driver didn't advertise the feature, it will never appear. */