iodev.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <asm/errno.h>
  19. struct kvm_io_device;
  20. /**
  21. * kvm_io_device_ops are called under kvm slots_lock.
  22. * read and write handlers return 0 if the transaction has been handled,
  23. * or non-zero to have it passed to the next device.
  24. **/
  25. struct kvm_io_device_ops {
  26. int (*read)(struct kvm_io_device *this,
  27. gpa_t addr,
  28. int len,
  29. void *val);
  30. int (*write)(struct kvm_io_device *this,
  31. gpa_t addr,
  32. int len,
  33. const void *val);
  34. void (*destructor)(struct kvm_io_device *this);
  35. };
  36. struct kvm_io_device {
  37. const struct kvm_io_device_ops *ops;
  38. };
  39. static inline void kvm_iodevice_init(struct kvm_io_device *dev,
  40. const struct kvm_io_device_ops *ops)
  41. {
  42. dev->ops = ops;
  43. }
  44. static inline int kvm_iodevice_read(struct kvm_io_device *dev,
  45. gpa_t addr, int l, void *v)
  46. {
  47. return dev->ops->read ? dev->ops->read(dev, addr, l, v) : -EOPNOTSUPP;
  48. }
  49. static inline int kvm_iodevice_write(struct kvm_io_device *dev,
  50. gpa_t addr, int l, const void *v)
  51. {
  52. return dev->ops->write ? dev->ops->write(dev, addr, l, v) : -EOPNOTSUPP;
  53. }
  54. static inline void kvm_iodevice_destructor(struct kvm_io_device *dev)
  55. {
  56. if (dev->ops->destructor)
  57. dev->ops->destructor(dev);
  58. }
  59. #endif /* __KVM_IODEV_H__ */