2019-05-30 06:57:56 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2007-12-04 04:30:24 +07:00
|
|
|
|
|
|
|
#ifndef __KVM_IODEV_H__
|
|
|
|
#define __KVM_IODEV_H__
|
|
|
|
|
2007-12-16 16:02:48 +07:00
|
|
|
#include <linux/kvm_types.h>
|
2015-03-26 21:39:29 +07:00
|
|
|
#include <linux/errno.h>
|
2007-12-04 04:30:24 +07:00
|
|
|
|
2009-06-01 23:54:50 +07:00
|
|
|
struct kvm_io_device;
|
2015-03-26 21:39:28 +07:00
|
|
|
struct kvm_vcpu;
|
2009-06-01 23:54:50 +07:00
|
|
|
|
2009-06-30 02:24:07 +07:00
|
|
|
/**
|
|
|
|
* kvm_io_device_ops are called under kvm slots_lock.
|
2009-06-30 02:24:32 +07:00
|
|
|
* read and write handlers return 0 if the transaction has been handled,
|
|
|
|
* or non-zero to have it passed to the next device.
|
2009-06-30 02:24:07 +07:00
|
|
|
**/
|
2009-06-01 23:54:50 +07:00
|
|
|
struct kvm_io_device_ops {
|
2015-03-26 21:39:28 +07:00
|
|
|
int (*read)(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_io_device *this,
|
2009-06-30 02:24:32 +07:00
|
|
|
gpa_t addr,
|
|
|
|
int len,
|
|
|
|
void *val);
|
2015-03-26 21:39:28 +07:00
|
|
|
int (*write)(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_io_device *this,
|
2007-12-04 04:30:24 +07:00
|
|
|
gpa_t addr,
|
|
|
|
int len,
|
2009-06-30 02:24:32 +07:00
|
|
|
const void *val);
|
2007-12-04 04:30:24 +07:00
|
|
|
void (*destructor)(struct kvm_io_device *this);
|
2009-06-01 23:54:50 +07:00
|
|
|
};
|
|
|
|
|
2007-12-04 04:30:24 +07:00
|
|
|
|
2009-06-01 23:54:50 +07:00
|
|
|
struct kvm_io_device {
|
|
|
|
const struct kvm_io_device_ops *ops;
|
2007-12-04 04:30:24 +07:00
|
|
|
};
|
|
|
|
|
2009-06-01 23:54:50 +07:00
|
|
|
static inline void kvm_iodevice_init(struct kvm_io_device *dev,
|
|
|
|
const struct kvm_io_device_ops *ops)
|
|
|
|
{
|
|
|
|
dev->ops = ops;
|
|
|
|
}
|
|
|
|
|
2015-03-26 21:39:28 +07:00
|
|
|
static inline int kvm_iodevice_read(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_io_device *dev, gpa_t addr,
|
|
|
|
int l, void *v)
|
2007-12-04 04:30:24 +07:00
|
|
|
{
|
2015-03-26 21:39:28 +07:00
|
|
|
return dev->ops->read ? dev->ops->read(vcpu, dev, addr, l, v)
|
|
|
|
: -EOPNOTSUPP;
|
2007-12-04 04:30:24 +07:00
|
|
|
}
|
|
|
|
|
2015-03-26 21:39:28 +07:00
|
|
|
static inline int kvm_iodevice_write(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_io_device *dev, gpa_t addr,
|
|
|
|
int l, const void *v)
|
2007-12-04 04:30:24 +07:00
|
|
|
{
|
2015-03-26 21:39:28 +07:00
|
|
|
return dev->ops->write ? dev->ops->write(vcpu, dev, addr, l, v)
|
|
|
|
: -EOPNOTSUPP;
|
2007-12-04 04:30:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
|
|
|
|
{
|
2009-06-01 23:54:50 +07:00
|
|
|
if (dev->ops->destructor)
|
|
|
|
dev->ops->destructor(dev);
|
2007-12-04 04:30:24 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __KVM_IODEV_H__ */
|