iodev.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. void (*read)(struct kvm_io_device *this,
  20. gpa_t addr,
  21. int len,
  22. void *val);
  23. void (*write)(struct kvm_io_device *this,
  24. gpa_t addr,
  25. int len,
  26. const void *val);
  27. int (*in_range)(struct kvm_io_device *this, gpa_t addr, int len,
  28. int is_write);
  29. void (*destructor)(struct kvm_io_device *this);
  30. void *private;
  31. };
  32. static inline void kvm_iodevice_read(struct kvm_io_device *dev,
  33. gpa_t addr,
  34. int len,
  35. void *val)
  36. {
  37. dev->read(dev, addr, len, val);
  38. }
  39. static inline void kvm_iodevice_write(struct kvm_io_device *dev,
  40. gpa_t addr,
  41. int len,
  42. const void *val)
  43. {
  44. dev->write(dev, addr, len, val);
  45. }
  46. static inline int kvm_iodevice_inrange(struct kvm_io_device *dev,
  47. gpa_t addr, int len, int is_write)
  48. {
  49. return dev->in_range(dev, addr, len, is_write);
  50. }
  51. static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
  52. {
  53. if (dev->destructor)
  54. dev->destructor(dev);
  55. }
  56. #endif /* __KVM_IODEV_H__ */