dect
/
linux-2.6
Archived
13
0
Fork 0

virtio: Rename set_features to finalize_features

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>
This commit is contained in:
Rusty Russell 2008-07-25 12:06:07 -05:00
parent dd7c7bc462
commit c624896e48
5 changed files with 24 additions and 20 deletions

View 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,

View 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,

View 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;

View 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 */

View File

@ -61,9 +61,10 @@
* @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. */