KVM: cleanup io_device code
[safe/jmp/linux-2.6] / virt / kvm / iodev.h
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
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
19 #include <linux/kvm_types.h>
20
21 struct kvm_io_device;
22
23 struct kvm_io_device_ops {
24         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);
32         int (*in_range)(struct kvm_io_device *this, gpa_t addr, int len,
33                         int is_write);
34         void (*destructor)(struct kvm_io_device *this);
35 };
36
37
38 struct kvm_io_device {
39         const struct kvm_io_device_ops *ops;
40 };
41
42 static 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
48 static inline void kvm_iodevice_read(struct kvm_io_device *dev,
49                                      gpa_t addr,
50                                      int len,
51                                      void *val)
52 {
53         dev->ops->read(dev, addr, len, val);
54 }
55
56 static inline void kvm_iodevice_write(struct kvm_io_device *dev,
57                                       gpa_t addr,
58                                       int len,
59                                       const void *val)
60 {
61         dev->ops->write(dev, addr, len, val);
62 }
63
64 static inline int kvm_iodevice_in_range(struct kvm_io_device *dev,
65                                         gpa_t addr, int len, int is_write)
66 {
67         return dev->ops->in_range(dev, addr, len, is_write);
68 }
69
70 static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
71 {
72         if (dev->ops->destructor)
73                 dev->ops->destructor(dev);
74 }
75
76 #endif /* __KVM_IODEV_H__ */