1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef __KVM_IODEV_H__
4 #define __KVM_IODEV_H__
6 #include <linux/kvm_types.h>
7 #include <linux/errno.h>
13 * kvm_io_device_ops are called under kvm slots_lock.
14 * read and write handlers return 0 if the transaction has been handled,
15 * or non-zero to have it passed to the next device.
17 struct kvm_io_device_ops
{
18 int (*read
)(struct kvm_vcpu
*vcpu
,
19 struct kvm_io_device
*this,
23 int (*write
)(struct kvm_vcpu
*vcpu
,
24 struct kvm_io_device
*this,
28 void (*destructor
)(struct kvm_io_device
*this);
32 struct kvm_io_device
{
33 const struct kvm_io_device_ops
*ops
;
36 static inline void kvm_iodevice_init(struct kvm_io_device
*dev
,
37 const struct kvm_io_device_ops
*ops
)
42 static inline int kvm_iodevice_read(struct kvm_vcpu
*vcpu
,
43 struct kvm_io_device
*dev
, gpa_t addr
,
46 return dev
->ops
->read
? dev
->ops
->read(vcpu
, dev
, addr
, l
, v
)
50 static inline int kvm_iodevice_write(struct kvm_vcpu
*vcpu
,
51 struct kvm_io_device
*dev
, gpa_t addr
,
54 return dev
->ops
->write
? dev
->ops
->write(vcpu
, dev
, addr
, l
, v
)
58 static inline void kvm_iodevice_destructor(struct kvm_io_device
*dev
)
60 if (dev
->ops
->destructor
)
61 dev
->ops
->destructor(dev
);
64 #endif /* __KVM_IODEV_H__ */