Commit c5ae742b authored by Sasha Levin's avatar Sasha Levin Committed by Will Deacon
Browse files

kvm tools: simplify virtio config handling



Instead of a get/set for config values, just request the address of the
config region, and handle that by simply reading directly from that region.

Signed-off-by: default avatarSasha Levin <levinsasha928@gmail.com>
Signed-off-by: default avatarPekka Enberg <penberg@kernel.org>
parent 47c03393
......@@ -78,8 +78,7 @@ struct virtio_device {
};
struct virtio_ops {
void (*set_config)(struct kvm *kvm, void *dev, u8 data, u32 offset);
u8 (*get_config)(struct kvm *kvm, void *dev, u32 offset);
u8 *(*get_config)(struct kvm *kvm, void *dev);
u32 (*get_host_features)(struct kvm *kvm, void *dev);
void (*set_guest_features)(struct kvm *kvm, void *dev, u32 features);
int (*init_vq)(struct kvm *kvm, void *dev, u32 vq, u32 pfn);
......
......@@ -1250,18 +1250,11 @@ static void virtio_p9_do_io(struct kvm *kvm, void *param)
}
}
static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset)
static u8 *get_config(struct kvm *kvm, void *dev)
{
struct p9_dev *p9dev = dev;
((u8 *)(p9dev->config))[offset] = data;
}
static u8 get_config(struct kvm *kvm, void *dev, u32 offset)
{
struct p9_dev *p9dev = dev;
return ((u8 *)(p9dev->config))[offset];
return ((u8 *)(p9dev->config));
}
static u32 get_host_features(struct kvm *kvm, void *dev)
......@@ -1323,7 +1316,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq)
}
struct virtio_ops p9_dev_virtio_ops = (struct virtio_ops) {
.set_config = set_config,
.get_config = get_config,
.get_host_features = get_host_features,
.set_guest_features = set_guest_features,
......
......@@ -175,18 +175,11 @@ static void handle_mem(int fd, u32 type, u32 len, u8 *msg)
bdev.vdev.ops->signal_config(kvm, &bdev.vdev);
}
static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset)
static u8 *get_config(struct kvm *kvm, void *dev)
{
struct bln_dev *bdev = dev;
((u8 *)(&bdev->config))[offset] = data;
}
static u8 get_config(struct kvm *kvm, void *dev, u32 offset)
{
struct bln_dev *bdev = dev;
return ((u8 *)(&bdev->config))[offset];
return ((u8 *)(&bdev->config));
}
static u32 get_host_features(struct kvm *kvm, void *dev)
......@@ -241,7 +234,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq)
}
struct virtio_ops bln_dev_virtio_ops = (struct virtio_ops) {
.set_config = set_config,
.get_config = get_config,
.get_host_features = get_host_features,
.set_guest_features = set_guest_features,
......
......@@ -134,18 +134,11 @@ static void virtio_blk_do_io(struct kvm *kvm, struct virt_queue *vq, struct blk_
}
}
static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset)
static u8 *get_config(struct kvm *kvm, void *dev)
{
struct blk_dev *bdev = dev;
((u8 *)(&bdev->blk_config))[offset] = data;
}
static u8 get_config(struct kvm *kvm, void *dev, u32 offset)
{
struct blk_dev *bdev = dev;
return ((u8 *)(&bdev->blk_config))[offset];
return ((u8 *)(&bdev->blk_config));
}
static u32 get_host_features(struct kvm *kvm, void *dev)
......@@ -230,7 +223,6 @@ static int set_size_vq(struct kvm *kvm, void *dev, u32 vq, int size)
}
static struct virtio_ops blk_dev_virtio_ops = (struct virtio_ops) {
.set_config = set_config,
.get_config = get_config,
.get_host_features = get_host_features,
.set_guest_features = set_guest_features,
......
......@@ -105,18 +105,11 @@ static void virtio_console_handle_callback(struct kvm *kvm, void *param)
}
static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset)
static u8 *get_config(struct kvm *kvm, void *dev)
{
struct con_dev *cdev = dev;
((u8 *)(&cdev->config))[offset] = data;
}
static u8 get_config(struct kvm *kvm, void *dev, u32 offset)
{
struct con_dev *cdev = dev;
return ((u8 *)(&cdev->config))[offset];
return ((u8 *)(&cdev->config));
}
static u32 get_host_features(struct kvm *kvm, void *dev)
......@@ -174,7 +167,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq)
}
static struct virtio_ops con_dev_virtio_ops = (struct virtio_ops) {
.set_config = set_config,
.get_config = get_config,
.get_host_features = get_host_features,
.set_guest_features = set_guest_features,
......
......@@ -94,11 +94,11 @@ static void virtio_mmio_device_specific(u64 addr, u8 *data, u32 len,
for (i = 0; i < len; i++) {
if (is_write)
vdev->ops->set_config(vmmio->kvm, vmmio->dev,
*(u8 *)data + i, addr + i);
vdev->ops->get_config(vmmio->kvm, vmmio->dev)[addr + i] =
*(u8 *)data + i;
else
data[i] = vdev->ops->get_config(vmmio->kvm,
vmmio->dev, addr + i);
vmmio->dev)[addr + i];
}
}
......
......@@ -290,18 +290,11 @@ static struct net_dev_operations uip_ops = {
.tx = uip_ops_tx,
};
static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset)
static u8 *get_config(struct kvm *kvm, void *dev)
{
struct net_dev *ndev = dev;
((u8 *)(&ndev->config))[offset] = data;
}
static u8 get_config(struct kvm *kvm, void *dev, u32 offset)
{
struct net_dev *ndev = dev;
return ((u8 *)(&ndev->config))[offset];
return ((u8 *)(&ndev->config));
}
static u32 get_host_features(struct kvm *kvm, void *dev)
......@@ -448,7 +441,6 @@ static int set_size_vq(struct kvm *kvm, void *dev, u32 vq, int size)
}
static struct virtio_ops net_dev_virtio_ops = (struct virtio_ops) {
.set_config = set_config,
.get_config = get_config,
.get_host_features = get_host_features,
.set_guest_features = set_guest_features,
......
......@@ -86,7 +86,7 @@ static bool virtio_pci__specific_io_in(struct kvm *kvm, struct virtio_device *vd
} else if (type == VIRTIO_PCI_O_CONFIG) {
u8 cfg;
cfg = vdev->ops->get_config(kvm, vpci->dev, config_offset);
cfg = vdev->ops->get_config(kvm, vpci->dev)[config_offset];
ioport__write8(data, cfg);
return true;
}
......@@ -164,7 +164,7 @@ static bool virtio_pci__specific_io_out(struct kvm *kvm, struct virtio_device *v
return true;
} else if (type == VIRTIO_PCI_O_CONFIG) {
vdev->ops->set_config(kvm, vpci->dev, *(u8 *)data, config_offset);
vdev->ops->get_config(kvm, vpci->dev)[config_offset] = *(u8 *)data;
return true;
}
......
......@@ -41,12 +41,7 @@ struct rng_dev {
static LIST_HEAD(rdevs);
static int compat_id = -1;
static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset)
{
/* Unused */
}
static u8 get_config(struct kvm *kvm, void *dev, u32 offset)
static u8 *get_config(struct kvm *kvm, void *dev)
{
/* Unused */
return 0;
......@@ -138,7 +133,6 @@ static int get_size_vq(struct kvm *kvm, void *dev, u32 vq)
}
static struct virtio_ops rng_dev_virtio_ops = (struct virtio_ops) {
.set_config = set_config,
.get_config = get_config,
.get_host_features = get_host_features,
.set_guest_features = set_guest_features,
......
......@@ -29,18 +29,11 @@ struct scsi_dev {
struct kvm *kvm;
};
static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset)
static u8 *get_config(struct kvm *kvm, void *dev)
{
struct scsi_dev *sdev = dev;
((u8 *)(&sdev->config))[offset] = data;
}
static u8 get_config(struct kvm *kvm, void *dev, u32 offset)
{
struct scsi_dev *sdev = dev;
return ((u8 *)(&sdev->config))[offset];
return ((u8 *)(&sdev->config));
}
static u32 get_host_features(struct kvm *kvm, void *dev)
......@@ -174,7 +167,6 @@ static int set_size_vq(struct kvm *kvm, void *dev, u32 vq, int size)
}
static struct virtio_ops scsi_dev_virtio_ops = (struct virtio_ops) {
.set_config = set_config,
.get_config = get_config,
.get_host_features = get_host_features,
.set_guest_features = set_guest_features,
......
Supports Markdown
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