]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/virtio/virtio.c
virtio: add legacy feature table support
[karo-tx-linux.git] / drivers / virtio / virtio.c
index df598dd8c5c8c42ae366307d409aa5423c0c7fba..f9ad99c8b35241681393670801f5aaa037cd6538 100644 (file)
@@ -49,9 +49,9 @@ static ssize_t features_show(struct device *_d,
 
        /* We actually represent this as a bitstring, as it could be
         * arbitrary length in future. */
-       for (i = 0; i < ARRAY_SIZE(dev->features)*BITS_PER_LONG; i++)
+       for (i = 0; i < sizeof(dev->features)*8; i++)
                len += sprintf(buf+len, "%c",
-                              test_bit(i, dev->features) ? '1' : '0');
+                              __virtio_test_bit(dev, i) ? '1' : '0');
        len += sprintf(buf+len, "\n");
        return len;
 }
@@ -113,6 +113,13 @@ void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
        for (i = 0; i < drv->feature_table_size; i++)
                if (drv->feature_table[i] == fbit)
                        return;
+
+       if (drv->feature_table_legacy) {
+               for (i = 0; i < drv->feature_table_size_legacy; i++)
+                       if (drv->feature_table_legacy[i] == fbit)
+                               return;
+       }
+
        BUG();
 }
 EXPORT_SYMBOL_GPL(virtio_check_driver_offered_feature);
@@ -159,7 +166,10 @@ static int virtio_dev_probe(struct device *_d)
        int err, i;
        struct virtio_device *dev = dev_to_virtio(_d);
        struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
-       u32 device_features;
+       u64 device_features;
+       u64 driver_features;
+       u64 driver_features_legacy;
+       unsigned status;
 
        /* We have a driver! */
        add_status(dev, VIRTIO_CONFIG_S_DRIVER);
@@ -167,34 +177,64 @@ static int virtio_dev_probe(struct device *_d)
        /* Figure out what features the device supports. */
        device_features = dev->config->get_features(dev);
 
-       /* Features supported by both device and driver into dev->features. */
-       memset(dev->features, 0, sizeof(dev->features));
+       /* Figure out what features the driver supports. */
+       driver_features = 0;
        for (i = 0; i < drv->feature_table_size; i++) {
                unsigned int f = drv->feature_table[i];
-               BUG_ON(f >= 32);
-               if (device_features & (1 << f))
-                       set_bit(f, dev->features);
+               BUG_ON(f >= 64);
+               driver_features |= (1ULL << f);
        }
 
+       /* Some drivers have a separate feature table for virtio v1.0 */
+       if (drv->feature_table_legacy) {
+               driver_features_legacy = 0;
+               for (i = 0; i < drv->feature_table_size_legacy; i++) {
+                       unsigned int f = drv->feature_table_legacy[i];
+                       BUG_ON(f >= 64);
+                       driver_features_legacy |= (1ULL << f);
+               }
+       } else {
+               driver_features_legacy = driver_features;
+       }
+
+       if (driver_features & device_features & (1ULL << VIRTIO_F_VERSION_1))
+               dev->features = driver_features & device_features;
+       else
+               dev->features = driver_features_legacy & device_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);
+               if (device_features & (1ULL << i))
+                       __virtio_set_bit(dev, i);
 
        dev->config->finalize_features(dev);
 
+       if (virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
+               add_status(dev, VIRTIO_CONFIG_S_FEATURES_OK);
+               status = dev->config->get_status(dev);
+               if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {
+                       dev_err(_d, "virtio: device refuses features: %x\n",
+                              status);
+                       err = -ENODEV;
+                       goto err;
+               }
+       }
+
        err = drv->probe(dev);
        if (err)
-               add_status(dev, VIRTIO_CONFIG_S_FAILED);
-       else {
-               add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
-               if (drv->scan)
-                       drv->scan(dev);
+               goto err;
 
-               virtio_config_enable(dev);
-       }
+       add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
+       if (drv->scan)
+               drv->scan(dev);
 
+       virtio_config_enable(dev);
+
+       return 0;
+err:
+       add_status(dev, VIRTIO_CONFIG_S_FAILED);
        return err;
+
 }
 
 static int virtio_dev_remove(struct device *_d)