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 | |
Gregory Haskins | d76685c | 2009-06-01 12:54:50 -0400 | [diff] [blame^] | 21 | struct kvm_io_device; |
| 22 | |
| 23 | struct kvm_io_device_ops { |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 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); |
Laurent Vivier | 9276049 | 2008-05-30 16:05:53 +0200 | [diff] [blame] | 32 | int (*in_range)(struct kvm_io_device *this, gpa_t addr, int len, |
| 33 | int is_write); |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 34 | void (*destructor)(struct kvm_io_device *this); |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 35 | }; |
| 36 | |
Gregory Haskins | d76685c | 2009-06-01 12:54:50 -0400 | [diff] [blame^] | 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 | |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 48 | static inline void kvm_iodevice_read(struct kvm_io_device *dev, |
| 49 | gpa_t addr, |
| 50 | int len, |
| 51 | void *val) |
| 52 | { |
Gregory Haskins | d76685c | 2009-06-01 12:54:50 -0400 | [diff] [blame^] | 53 | dev->ops->read(dev, addr, len, val); |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 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 | { |
Gregory Haskins | d76685c | 2009-06-01 12:54:50 -0400 | [diff] [blame^] | 61 | dev->ops->write(dev, addr, len, val); |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 62 | } |
| 63 | |
Gregory Haskins | d76685c | 2009-06-01 12:54:50 -0400 | [diff] [blame^] | 64 | static inline int kvm_iodevice_in_range(struct kvm_io_device *dev, |
| 65 | gpa_t addr, int len, int is_write) |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 66 | { |
Gregory Haskins | d76685c | 2009-06-01 12:54:50 -0400 | [diff] [blame^] | 67 | return dev->ops->in_range(dev, addr, len, is_write); |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static inline void kvm_iodevice_destructor(struct kvm_io_device *dev) |
| 71 | { |
Gregory Haskins | d76685c | 2009-06-01 12:54:50 -0400 | [diff] [blame^] | 72 | if (dev->ops->destructor) |
| 73 | dev->ops->destructor(dev); |
Hollis Blanchard | e217402 | 2007-12-03 15:30:24 -0600 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | #endif /* __KVM_IODEV_H__ */ |