]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/kvm/iodev.h
drm: mst: Fix query_payload ack reply struct
[mirror_ubuntu-bionic-kernel.git] / include / kvm / iodev.h
CommitLineData
e2174021
HB
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
af669ac6 12 * along with this program. If not, see <http://www.gnu.org/licenses/>.
e2174021
HB
13 */
14
15#ifndef __KVM_IODEV_H__
16#define __KVM_IODEV_H__
17
edf88417 18#include <linux/kvm_types.h>
af669ac6 19#include <linux/errno.h>
e2174021 20
d76685c4 21struct kvm_io_device;
e32edf4f 22struct kvm_vcpu;
d76685c4 23
69fa2d78
MT
24/**
25 * kvm_io_device_ops are called under kvm slots_lock.
bda9020e
MT
26 * read and write handlers return 0 if the transaction has been handled,
27 * or non-zero to have it passed to the next device.
69fa2d78 28 **/
d76685c4 29struct kvm_io_device_ops {
e32edf4f
NN
30 int (*read)(struct kvm_vcpu *vcpu,
31 struct kvm_io_device *this,
bda9020e
MT
32 gpa_t addr,
33 int len,
34 void *val);
e32edf4f
NN
35 int (*write)(struct kvm_vcpu *vcpu,
36 struct kvm_io_device *this,
e2174021
HB
37 gpa_t addr,
38 int len,
bda9020e 39 const void *val);
e2174021 40 void (*destructor)(struct kvm_io_device *this);
d76685c4
GH
41};
42
e2174021 43
d76685c4
GH
44struct kvm_io_device {
45 const struct kvm_io_device_ops *ops;
e2174021
HB
46};
47
d76685c4
GH
48static inline void kvm_iodevice_init(struct kvm_io_device *dev,
49 const struct kvm_io_device_ops *ops)
50{
51 dev->ops = ops;
52}
53
e32edf4f
NN
54static inline int kvm_iodevice_read(struct kvm_vcpu *vcpu,
55 struct kvm_io_device *dev, gpa_t addr,
56 int l, void *v)
e2174021 57{
e32edf4f
NN
58 return dev->ops->read ? dev->ops->read(vcpu, dev, addr, l, v)
59 : -EOPNOTSUPP;
e2174021
HB
60}
61
e32edf4f
NN
62static inline int kvm_iodevice_write(struct kvm_vcpu *vcpu,
63 struct kvm_io_device *dev, gpa_t addr,
64 int l, const void *v)
e2174021 65{
e32edf4f
NN
66 return dev->ops->write ? dev->ops->write(vcpu, dev, addr, l, v)
67 : -EOPNOTSUPP;
e2174021
HB
68}
69
70static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
71{
d76685c4
GH
72 if (dev->ops->destructor)
73 dev->ops->destructor(dev);
e2174021
HB
74}
75
76#endif /* __KVM_IODEV_H__ */