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.
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.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #ifndef __KVM_IODEV_H__
17 #define __KVM_IODEV_H__
19 #include <linux/kvm_types.h>
23 struct kvm_io_device_ops {
24 void (*read)(struct kvm_io_device *this,
28 void (*write)(struct kvm_io_device *this,
32 int (*in_range)(struct kvm_io_device *this, gpa_t addr, int len,
34 void (*destructor)(struct kvm_io_device *this);
38 struct kvm_io_device {
39 const struct kvm_io_device_ops *ops;
42 static inline void kvm_iodevice_init(struct kvm_io_device *dev,
43 const struct kvm_io_device_ops *ops)
48 static inline void kvm_iodevice_read(struct kvm_io_device *dev,
53 dev->ops->read(dev, addr, len, val);
56 static inline void kvm_iodevice_write(struct kvm_io_device *dev,
61 dev->ops->write(dev, addr, len, val);
64 static inline int kvm_iodevice_in_range(struct kvm_io_device *dev,
65 gpa_t addr, int len, int is_write)
67 return dev->ops->in_range(dev, addr, len, is_write);
70 static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
72 if (dev->ops->destructor)
73 dev->ops->destructor(dev);
76 #endif /* __KVM_IODEV_H__ */