Commit 0b017708 authored by Jason Wang's avatar Jason Wang Committed by Michael S. Tsirkin

virtio-pci-modern: introduce helpers for setting and getting features

This patch introduces helpers for setting and getting features.
Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
Link: https://lore.kernel.org/r/20210104065503.199631-8-jasowang@redhat.comSigned-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent e3669129
......@@ -137,12 +137,16 @@ static void __iomem *map_capability(struct pci_dev *dev, int off,
return p;
}
/* virtio config->get_features() implementation */
static u64 vp_get_features(struct virtio_device *vdev)
/*
* vp_modern_get_features - get features from device
* @mdev: the modern virtio-pci device
*
* Returns the features read from the device
*/
static u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev)
{
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
struct virtio_pci_modern_device *mdev = &vp_dev->mdev;
struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
u64 features;
vp_iowrite32(0, &cfg->device_feature_select);
......@@ -153,6 +157,14 @@ static u64 vp_get_features(struct virtio_device *vdev)
return features;
}
/* virtio config->get_features() implementation */
static u64 vp_get_features(struct virtio_device *vdev)
{
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
return vp_modern_get_features(&vp_dev->mdev);
}
static void vp_transport_features(struct virtio_device *vdev, u64 features)
{
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
......@@ -163,12 +175,26 @@ static void vp_transport_features(struct virtio_device *vdev, u64 features)
__virtio_set_bit(vdev, VIRTIO_F_SR_IOV);
}
/*
* vp_modern_set_features - set features to device
* @mdev: the modern virtio-pci device
* @features: the features set to device
*/
static void vp_modern_set_features(struct virtio_pci_modern_device *mdev,
u64 features)
{
struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
vp_iowrite32(0, &cfg->guest_feature_select);
vp_iowrite32((u32)features, &cfg->guest_feature);
vp_iowrite32(1, &cfg->guest_feature_select);
vp_iowrite32(features >> 32, &cfg->guest_feature);
}
/* virtio config->finalize_features() implementation */
static int vp_finalize_features(struct virtio_device *vdev)
{
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
struct virtio_pci_modern_device *mdev = &vp_dev->mdev;
struct virtio_pci_common_cfg __iomem *cfg = mdev->common;
u64 features = vdev->features;
/* Give virtio_ring a chance to accept features. */
......@@ -183,10 +209,7 @@ static int vp_finalize_features(struct virtio_device *vdev)
return -EINVAL;
}
vp_iowrite32(0, &cfg->guest_feature_select);
vp_iowrite32((u32)vdev->features, &cfg->guest_feature);
vp_iowrite32(1, &cfg->guest_feature_select);
vp_iowrite32(vdev->features >> 32, &cfg->guest_feature);
vp_modern_set_features(&vp_dev->mdev, vdev->features);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment