iodev.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef __KVM_IODEV_H__
  16. #define __KVM_IODEV_H__
  17. #include <linux/kvm_types.h>
  18. struct kvm_io_device;
  19. /**
  20. * kvm_io_device_ops are called under kvm slots_lock.
  21. **/
  22. struct kvm_io_device_ops {
  23. void (*read)(struct kvm_io_device *this,
  24. gpa_t addr,
  25. int len,
  26. void *val);
  27. void (*write)(struct kvm_io_device *this,
  28. gpa_t addr,
  29. int len,
  30. const void *val);
  31. int (*in_range)(struct kvm_io_device *this, gpa_t addr, int len,
  32. int is_write);
  33. void (*destructor)(struct kvm_io_device *this);
  34. };
  35. struct kvm_io_device {
  36. const struct kvm_io_device_ops *ops;
  37. };
  38. static inline void kvm_iodevice_init(struct kvm_io_device *dev,
  39. const struct kvm_io_device_ops *ops)
  40. {
  41. dev->ops = ops;
  42. }
  43. static inline void kvm_iodevice_read(struct kvm_io_device *dev,
  44. gpa_t addr,
  45. int len,
  46. void *val)
  47. {
  48. dev->ops->read(dev, addr, len, val);
  49. }
  50. static inline void kvm_iodevice_write(struct kvm_io_device *dev,
  51. gpa_t addr,
  52. int len,
  53. const void *val)
  54. {
  55. dev->ops->write(dev, addr, len, val);
  56. }
  57. static inline int kvm_iodevice_in_range(struct kvm_io_device *dev,
  58. gpa_t addr, int len, int is_write)
  59. {
  60. return dev->ops->in_range(dev, addr, len, is_write);
  61. }
  62. static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
  63. {
  64. if (dev->ops->destructor)
  65. dev->ops->destructor(dev);
  66. }
  67. #endif /* __KVM_IODEV_H__ */