/* We actually represent this as a bitstring, as it could be
* arbitrary length in future. */ for (i = 0; i < VIRTIO_FEATURES_MAX; i++)
len += sysfs_emit_at(buf, len, "%c",
__virtio_test_bit(dev, i) ? '1' : '0');
len += sysfs_emit_at(buf, len, "\n"); return len;
} static DEVICE_ATTR_RO(features);
/* This looks through all the IDs a driver claims to support. If any of them
* match, we return 1 and the kernel will call virtio_dev_probe(). */ staticint virtio_dev_match(struct device *_dv, conststruct device_driver *_dr)
{ unsignedint i; struct virtio_device *dev = dev_to_virtio(_dv); conststruct virtio_device_id *ids;
ids = drv_to_virtio(_dr)->id_table; for (i = 0; ids[i].device; i++) if (virtio_id_match(dev, &ids[i])) return1; return0;
}
/* Do some validation, then set FEATURES_OK */ staticint virtio_features_ok(struct virtio_device *dev)
{ unsignedint status;
might_sleep();
if (virtio_check_mem_acc_cb(dev)) { if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) {
dev_warn(&dev->dev, "device must provide VIRTIO_F_VERSION_1\n"); return -ENODEV;
}
if (!virtio_has_feature(dev, VIRTIO_F_ACCESS_PLATFORM)) {
dev_warn(&dev->dev, "device must provide VIRTIO_F_ACCESS_PLATFORM\n"); return -ENODEV;
}
}
if (!virtio_has_feature(dev, VIRTIO_F_VERSION_1)) return0;
/* We have a driver! */
virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER);
/* Figure out what features the device supports. */
virtio_get_features(dev, device_features);
/* Figure out what features the driver supports. */
virtio_features_zero(driver_features); for (i = 0; i < drv->feature_table_size; i++) { unsignedint f = drv->feature_table[i]; if (!WARN_ON_ONCE(f >= VIRTIO_FEATURES_MAX))
virtio_features_set_bit(driver_features, 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++) { unsignedint f = drv->feature_table_legacy[i]; if (!WARN_ON_ONCE(f >= 64))
driver_features_legacy |= (1ULL << f);
}
} else {
driver_features_legacy = driver_features[0];
}
if (virtio_features_test_bit(device_features, VIRTIO_F_VERSION_1)) { for (i = 0; i < VIRTIO_FEATURES_DWORDS; ++i)
dev->features_array[i] = driver_features[i] &
device_features[i];
} else {
virtio_features_from_u64(dev->features_array,
driver_features_legacy &
device_features[0]);
}
/* When debugging, user may filter some features by hand. */
virtio_debug_device_filter_features(dev);
/* Transport features always preserved to pass to finalize_features. */ for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++) if (virtio_features_test_bit(device_features, i))
__virtio_set_bit(dev, i);
err = dev->config->finalize_features(dev); if (err) goto err;
if (drv->validate) {
u64 features[VIRTIO_FEATURES_DWORDS];
virtio_features_copy(features, dev->features_array);
err = drv->validate(dev); if (err) goto err;
/* Did validation change any features? Then write them again. */ if (!virtio_features_equal(features, dev->features_array)) {
err = dev->config->finalize_features(dev); if (err) goto err;
}
}
err = virtio_features_ok(dev); if (err) goto err;
err = drv->probe(dev); if (err) goto err;
/* If probe didn't do it, mark device DRIVER_OK ourselves. */ if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
virtio_device_ready(dev);
/* We always start by resetting the device, in case a previous
* driver messed it up. This also tests that code path a little. */
virtio_reset_device(dev);
/* Acknowledge that we've seen the device. */
virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
/* We always start by resetting the device, in case a previous
* driver messed it up. */
virtio_reset_device(dev);
/* Acknowledge that we've seen the device. */
virtio_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
/* Maybe driver failed before freeze.
* Restore the failed status, for debugging. */ if (dev->failed)
virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);
if (!drv) return0;
/* We have a driver! */
virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER);
ret = dev->config->finalize_features(dev); if (ret) goto err;
ret = virtio_features_ok(dev); if (ret) goto err;
if (restore) { if (drv->restore) {
ret = drv->restore(dev); if (ret) goto err;
}
} else {
ret = drv->reset_done(dev); if (ret) goto err;
}
/* If restore didn't do it, mark device DRIVER_OK ourselves. */ if (!(dev->config->get_status(dev) & VIRTIO_CONFIG_S_DRIVER_OK))
virtio_device_ready(dev);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.