Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 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 | |
Avi Kivity | edf8841 | 2007-12-16 11:02:48 +0200 | [diff] [blame] | 19 | #include <linux/kvm_types.h> |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 20 | |
| 21 | struct kvm_io_device { |
| 22 | void (*read)(struct kvm_io_device *this, |
| 23 | gpa_t addr, |
| 24 | int len, |
| 25 | void *val); |
| 26 | void (*write)(struct kvm_io_device *this, |
| 27 | gpa_t addr, |
| 28 | int len, |
| 29 | const void *val); |
Laurent Vivier | 9276049 | 2008-05-30 16:05:53 +0200 | [diff] [blame] | 30 | int (*in_range)(struct kvm_io_device *this, gpa_t addr, int len, |
| 31 | int is_write); |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 32 | void (*destructor)(struct kvm_io_device *this); |
| 33 | |
| 34 | void *private; |
| 35 | }; |
| 36 | |
| 37 | static inline void kvm_iodevice_read(struct kvm_io_device *dev, |
| 38 | gpa_t addr, |
| 39 | int len, |
| 40 | void *val) |
| 41 | { |
| 42 | dev->read(dev, addr, len, val); |
| 43 | } |
| 44 | |
| 45 | static inline void kvm_iodevice_write(struct kvm_io_device *dev, |
| 46 | gpa_t addr, |
| 47 | int len, |
| 48 | const void *val) |
| 49 | { |
| 50 | dev->write(dev, addr, len, val); |
| 51 | } |
| 52 | |
Laurent Vivier | 9276049 | 2008-05-30 16:05:53 +0200 | [diff] [blame] | 53 | static inline int kvm_iodevice_inrange(struct kvm_io_device *dev, |
| 54 | gpa_t addr, int len, int is_write) |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 55 | { |
Laurent Vivier | 9276049 | 2008-05-30 16:05:53 +0200 | [diff] [blame] | 56 | return dev->in_range(dev, addr, len, is_write); |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static inline void kvm_iodevice_destructor(struct kvm_io_device *dev) |
| 60 | { |
| 61 | if (dev->destructor) |
| 62 | dev->destructor(dev); |
| 63 | } |
| 64 | |
| 65 | #endif /* __KVM_IODEV_H__ */ |