2019-05-30 02:57:56 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2007-12-04 00:30:24 +03:00
|
|
|
|
|
|
|
#ifndef __KVM_IODEV_H__
|
|
|
|
#define __KVM_IODEV_H__
|
|
|
|
|
2007-12-16 12:02:48 +03:00
|
|
|
#include <linux/kvm_types.h>
|
2015-03-26 17:39:29 +03:00
|
|
|
#include <linux/errno.h>
|
2007-12-04 00:30:24 +03:00
|
|
|
|
2009-06-01 20:54:50 +04:00
|
|
|
struct kvm_io_device;
|
2015-03-26 17:39:28 +03:00
|
|
|
struct kvm_vcpu;
|
2009-06-01 20:54:50 +04:00
|
|
|
|
2009-06-29 23:24:07 +04:00
|
|
|
/**
|
|
|
|
* kvm_io_device_ops are called under kvm slots_lock.
|
2009-06-29 23:24:32 +04: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-29 23:24:07 +04:00
|
|
|
**/
|
2009-06-01 20:54:50 +04:00
|
|
|
struct kvm_io_device_ops {
|
2015-03-26 17:39:28 +03:00
|
|
|
int (*read)(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_io_device *this,
|
2009-06-29 23:24:32 +04:00
|
|
|
gpa_t addr,
|
|
|
|
int len,
|
|
|
|
void *val);
|
2015-03-26 17:39:28 +03:00
|
|
|
int (*write)(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_io_device *this,
|
2007-12-04 00:30:24 +03:00
|
|
|
gpa_t addr,
|
|
|
|
int len,
|
2009-06-29 23:24:32 +04:00
|
|
|
const void *val);
|
2007-12-04 00:30:24 +03:00
|
|
|
void (*destructor)(struct kvm_io_device *this);
|
2009-06-01 20:54:50 +04:00
|
|
|
};
|
|
|
|
|
2007-12-04 00:30:24 +03:00
|
|
|
|
2009-06-01 20:54:50 +04:00
|
|
|
struct kvm_io_device {
|
|
|
|
const struct kvm_io_device_ops *ops;
|
2007-12-04 00:30:24 +03:00
|
|
|
};
|
|
|
|
|
2009-06-01 20:54:50 +04: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 17:39:28 +03: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 00:30:24 +03:00
|
|
|
{
|
2015-03-26 17:39:28 +03:00
|
|
|
return dev->ops->read ? dev->ops->read(vcpu, dev, addr, l, v)
|
|
|
|
: -EOPNOTSUPP;
|
2007-12-04 00:30:24 +03:00
|
|
|
}
|
|
|
|
|
2015-03-26 17:39:28 +03: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 00:30:24 +03:00
|
|
|
{
|
2015-03-26 17:39:28 +03:00
|
|
|
return dev->ops->write ? dev->ops->write(vcpu, dev, addr, l, v)
|
|
|
|
: -EOPNOTSUPP;
|
2007-12-04 00:30:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
|
|
|
|
{
|
2009-06-01 20:54:50 +04:00
|
|
|
if (dev->ops->destructor)
|
|
|
|
dev->ops->destructor(dev);
|
2007-12-04 00:30:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __KVM_IODEV_H__ */
|