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