Commit | Line | Data |
---|---|---|
5dfa3c2f | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
e2174021 HB |
2 | |
3 | #ifndef __KVM_IODEV_H__ | |
4 | #define __KVM_IODEV_H__ | |
5 | ||
edf88417 | 6 | #include <linux/kvm_types.h> |
af669ac6 | 7 | #include <linux/errno.h> |
e2174021 | 8 | |
d76685c4 | 9 | struct kvm_io_device; |
e32edf4f | 10 | struct kvm_vcpu; |
d76685c4 | 11 | |
69fa2d78 MT |
12 | /** |
13 | * kvm_io_device_ops are called under kvm slots_lock. | |
bda9020e MT |
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. | |
69fa2d78 | 16 | **/ |
d76685c4 | 17 | struct kvm_io_device_ops { |
e32edf4f NN |
18 | int (*read)(struct kvm_vcpu *vcpu, |
19 | struct kvm_io_device *this, | |
bda9020e MT |
20 | gpa_t addr, |
21 | int len, | |
22 | void *val); | |
e32edf4f NN |
23 | int (*write)(struct kvm_vcpu *vcpu, |
24 | struct kvm_io_device *this, | |
e2174021 HB |
25 | gpa_t addr, |
26 | int len, | |
bda9020e | 27 | const void *val); |
e2174021 | 28 | void (*destructor)(struct kvm_io_device *this); |
d76685c4 GH |
29 | }; |
30 | ||
e2174021 | 31 | |
d76685c4 GH |
32 | struct kvm_io_device { |
33 | const struct kvm_io_device_ops *ops; | |
e2174021 HB |
34 | }; |
35 | ||
d76685c4 GH |
36 | static inline void kvm_iodevice_init(struct kvm_io_device *dev, |
37 | const struct kvm_io_device_ops *ops) | |
38 | { | |
39 | dev->ops = ops; | |
40 | } | |
41 | ||
e32edf4f NN |
42 | static inline int kvm_iodevice_read(struct kvm_vcpu *vcpu, |
43 | struct kvm_io_device *dev, gpa_t addr, | |
44 | int l, void *v) | |
e2174021 | 45 | { |
e32edf4f NN |
46 | return dev->ops->read ? dev->ops->read(vcpu, dev, addr, l, v) |
47 | : -EOPNOTSUPP; | |
e2174021 HB |
48 | } |
49 | ||
e32edf4f NN |
50 | static inline int kvm_iodevice_write(struct kvm_vcpu *vcpu, |
51 | struct kvm_io_device *dev, gpa_t addr, | |
52 | int l, const void *v) | |
e2174021 | 53 | { |
e32edf4f NN |
54 | return dev->ops->write ? dev->ops->write(vcpu, dev, addr, l, v) |
55 | : -EOPNOTSUPP; | |
e2174021 HB |
56 | } |
57 | ||
58 | static inline void kvm_iodevice_destructor(struct kvm_io_device *dev) | |
59 | { | |
d76685c4 GH |
60 | if (dev->ops->destructor) |
61 | dev->ops->destructor(dev); | |
e2174021 HB |
62 | } |
63 | ||
64 | #endif /* __KVM_IODEV_H__ */ |