vfio.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * VFIO API definition
  3. *
  4. * Copyright (C) 2012 Red Hat, Inc. All rights reserved.
  5. * Author: Alex Williamson <alex.williamson@redhat.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef VFIO_H
  12. #define VFIO_H
  13. #include <linux/iommu.h>
  14. #include <linux/mm.h>
  15. #include <linux/workqueue.h>
  16. #include <linux/poll.h>
  17. #include <uapi/linux/vfio.h>
  18. /**
  19. * struct vfio_device_ops - VFIO bus driver device callbacks
  20. *
  21. * @open: Called when userspace creates new file descriptor for device
  22. * @release: Called when userspace releases file descriptor for device
  23. * @read: Perform read(2) on device file descriptor
  24. * @write: Perform write(2) on device file descriptor
  25. * @ioctl: Perform ioctl(2) on device file descriptor, supporting VFIO_DEVICE_*
  26. * operations documented below
  27. * @mmap: Perform mmap(2) on a region of the device file descriptor
  28. * @request: Request for the bus driver to release the device
  29. */
  30. struct vfio_device_ops {
  31. char *name;
  32. int (*open)(void *device_data);
  33. void (*release)(void *device_data);
  34. ssize_t (*read)(void *device_data, char __user *buf,
  35. size_t count, loff_t *ppos);
  36. ssize_t (*write)(void *device_data, const char __user *buf,
  37. size_t count, loff_t *size);
  38. long (*ioctl)(void *device_data, unsigned int cmd,
  39. unsigned long arg);
  40. int (*mmap)(void *device_data, struct vm_area_struct *vma);
  41. void (*request)(void *device_data, unsigned int count);
  42. };
  43. extern int vfio_add_group_dev(struct device *dev,
  44. const struct vfio_device_ops *ops,
  45. void *device_data);
  46. extern void *vfio_del_group_dev(struct device *dev);
  47. extern struct vfio_device *vfio_device_get_from_dev(struct device *dev);
  48. extern void vfio_device_put(struct vfio_device *device);
  49. extern void *vfio_device_data(struct vfio_device *device);
  50. /**
  51. * struct vfio_iommu_driver_ops - VFIO IOMMU driver callbacks
  52. */
  53. struct vfio_iommu_driver_ops {
  54. char *name;
  55. struct module *owner;
  56. void *(*open)(unsigned long arg);
  57. void (*release)(void *iommu_data);
  58. ssize_t (*read)(void *iommu_data, char __user *buf,
  59. size_t count, loff_t *ppos);
  60. ssize_t (*write)(void *iommu_data, const char __user *buf,
  61. size_t count, loff_t *size);
  62. long (*ioctl)(void *iommu_data, unsigned int cmd,
  63. unsigned long arg);
  64. int (*mmap)(void *iommu_data, struct vm_area_struct *vma);
  65. int (*attach_group)(void *iommu_data,
  66. struct iommu_group *group);
  67. void (*detach_group)(void *iommu_data,
  68. struct iommu_group *group);
  69. };
  70. extern int vfio_register_iommu_driver(const struct vfio_iommu_driver_ops *ops);
  71. extern void vfio_unregister_iommu_driver(
  72. const struct vfio_iommu_driver_ops *ops);
  73. /*
  74. * External user API
  75. */
  76. extern struct vfio_group *vfio_group_get_external_user(struct file *filep);
  77. extern void vfio_group_put_external_user(struct vfio_group *group);
  78. extern bool vfio_external_group_match_file(struct vfio_group *group,
  79. struct file *filep);
  80. extern int vfio_external_user_iommu_id(struct vfio_group *group);
  81. extern long vfio_external_check_extension(struct vfio_group *group,
  82. unsigned long arg);
  83. struct pci_dev;
  84. #ifdef CONFIG_EEH
  85. extern void vfio_spapr_pci_eeh_open(struct pci_dev *pdev);
  86. extern void vfio_spapr_pci_eeh_release(struct pci_dev *pdev);
  87. extern long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
  88. unsigned int cmd,
  89. unsigned long arg);
  90. #else
  91. static inline void vfio_spapr_pci_eeh_open(struct pci_dev *pdev)
  92. {
  93. }
  94. static inline void vfio_spapr_pci_eeh_release(struct pci_dev *pdev)
  95. {
  96. }
  97. static inline long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
  98. unsigned int cmd,
  99. unsigned long arg)
  100. {
  101. return -ENOTTY;
  102. }
  103. #endif /* CONFIG_EEH */
  104. /*
  105. * IRQfd - generic
  106. */
  107. struct virqfd {
  108. void *opaque;
  109. struct eventfd_ctx *eventfd;
  110. int (*handler)(void *, void *);
  111. void (*thread)(void *, void *);
  112. void *data;
  113. struct work_struct inject;
  114. wait_queue_t wait;
  115. poll_table pt;
  116. struct work_struct shutdown;
  117. struct virqfd **pvirqfd;
  118. };
  119. extern int vfio_virqfd_enable(void *opaque,
  120. int (*handler)(void *, void *),
  121. void (*thread)(void *, void *),
  122. void *data, struct virqfd **pvirqfd, int fd);
  123. extern void vfio_virqfd_disable(struct virqfd **pvirqfd);
  124. #endif /* VFIO_H */