blob: 2c67f5acd6db54eee5713ee58a04534d1567e3cf [file] [log] [blame]
Hollis Blancharde2174022007-12-03 15:30:24 -06001/*
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
12 * along with this program; if not, write to the Free Software
13 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14 */
15
16#ifndef __KVM_IODEV_H__
17#define __KVM_IODEV_H__
18
Avi Kivityedf88412007-12-16 11:02:48 +020019#include <linux/kvm_types.h>
Hollis Blancharde2174022007-12-03 15:30:24 -060020
Gregory Haskinsd76685c2009-06-01 12:54:50 -040021struct kvm_io_device;
22
23struct kvm_io_device_ops {
Hollis Blancharde2174022007-12-03 15:30:24 -060024 void (*read)(struct kvm_io_device *this,
25 gpa_t addr,
26 int len,
27 void *val);
28 void (*write)(struct kvm_io_device *this,
29 gpa_t addr,
30 int len,
31 const void *val);
Laurent Vivier92760492008-05-30 16:05:53 +020032 int (*in_range)(struct kvm_io_device *this, gpa_t addr, int len,
33 int is_write);
Hollis Blancharde2174022007-12-03 15:30:24 -060034 void (*destructor)(struct kvm_io_device *this);
Hollis Blancharde2174022007-12-03 15:30:24 -060035};
36
Gregory Haskinsd76685c2009-06-01 12:54:50 -040037
38struct kvm_io_device {
39 const struct kvm_io_device_ops *ops;
40};
41
42static inline void kvm_iodevice_init(struct kvm_io_device *dev,
43 const struct kvm_io_device_ops *ops)
44{
45 dev->ops = ops;
46}
47
Hollis Blancharde2174022007-12-03 15:30:24 -060048static inline void kvm_iodevice_read(struct kvm_io_device *dev,
49 gpa_t addr,
50 int len,
51 void *val)
52{
Gregory Haskinsd76685c2009-06-01 12:54:50 -040053 dev->ops->read(dev, addr, len, val);
Hollis Blancharde2174022007-12-03 15:30:24 -060054}
55
56static inline void kvm_iodevice_write(struct kvm_io_device *dev,
57 gpa_t addr,
58 int len,
59 const void *val)
60{
Gregory Haskinsd76685c2009-06-01 12:54:50 -040061 dev->ops->write(dev, addr, len, val);
Hollis Blancharde2174022007-12-03 15:30:24 -060062}
63
Gregory Haskinsd76685c2009-06-01 12:54:50 -040064static inline int kvm_iodevice_in_range(struct kvm_io_device *dev,
65 gpa_t addr, int len, int is_write)
Hollis Blancharde2174022007-12-03 15:30:24 -060066{
Gregory Haskinsd76685c2009-06-01 12:54:50 -040067 return dev->ops->in_range(dev, addr, len, is_write);
Hollis Blancharde2174022007-12-03 15:30:24 -060068}
69
70static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
71{
Gregory Haskinsd76685c2009-06-01 12:54:50 -040072 if (dev->ops->destructor)
73 dev->ops->destructor(dev);
Hollis Blancharde2174022007-12-03 15:30:24 -060074}
75
76#endif /* __KVM_IODEV_H__ */