vfio_platform_private.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013 - Virtual Open Systems
  4. * Author: Antonios Motakis <a.motakis@virtualopensystems.com>
  5. */
  6. #ifndef VFIO_PLATFORM_PRIVATE_H
  7. #define VFIO_PLATFORM_PRIVATE_H
  8. #include <linux/types.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/vfio.h>
  11. #define VFIO_PLATFORM_OFFSET_SHIFT 40
  12. #define VFIO_PLATFORM_OFFSET_MASK (((u64)(1) << VFIO_PLATFORM_OFFSET_SHIFT) - 1)
  13. #define VFIO_PLATFORM_OFFSET_TO_INDEX(off) \
  14. (off >> VFIO_PLATFORM_OFFSET_SHIFT)
  15. #define VFIO_PLATFORM_INDEX_TO_OFFSET(index) \
  16. ((u64)(index) << VFIO_PLATFORM_OFFSET_SHIFT)
  17. struct vfio_platform_irq {
  18. u32 flags;
  19. u32 count;
  20. int hwirq;
  21. char *name;
  22. struct eventfd_ctx *trigger;
  23. bool masked;
  24. spinlock_t lock;
  25. struct virqfd *unmask;
  26. struct virqfd *mask;
  27. };
  28. struct vfio_platform_region {
  29. u64 addr;
  30. resource_size_t size;
  31. u32 flags;
  32. u32 type;
  33. #define VFIO_PLATFORM_REGION_TYPE_MMIO 1
  34. #define VFIO_PLATFORM_REGION_TYPE_PIO 2
  35. void __iomem *ioaddr;
  36. };
  37. struct vfio_platform_device {
  38. struct vfio_device vdev;
  39. struct vfio_platform_region *regions;
  40. u32 num_regions;
  41. struct vfio_platform_irq *irqs;
  42. u32 num_irqs;
  43. struct mutex igate;
  44. const char *compat;
  45. const char *acpihid;
  46. struct module *reset_module;
  47. struct device *device;
  48. /*
  49. * These fields should be filled by the bus specific binder
  50. */
  51. void *opaque;
  52. const char *name;
  53. uint32_t flags;
  54. /* callbacks to discover device resources */
  55. struct resource*
  56. (*get_resource)(struct vfio_platform_device *vdev, int i);
  57. int (*get_irq)(struct vfio_platform_device *vdev, int i);
  58. int (*of_reset)(struct vfio_platform_device *vdev);
  59. bool reset_required;
  60. };
  61. typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev);
  62. struct vfio_platform_reset_node {
  63. struct list_head link;
  64. char *compat;
  65. struct module *owner;
  66. vfio_platform_reset_fn_t of_reset;
  67. };
  68. int vfio_platform_init_common(struct vfio_platform_device *vdev);
  69. void vfio_platform_release_common(struct vfio_platform_device *vdev);
  70. int vfio_platform_open_device(struct vfio_device *core_vdev);
  71. void vfio_platform_close_device(struct vfio_device *core_vdev);
  72. long vfio_platform_ioctl(struct vfio_device *core_vdev,
  73. unsigned int cmd, unsigned long arg);
  74. ssize_t vfio_platform_read(struct vfio_device *core_vdev,
  75. char __user *buf, size_t count,
  76. loff_t *ppos);
  77. ssize_t vfio_platform_write(struct vfio_device *core_vdev,
  78. const char __user *buf,
  79. size_t count, loff_t *ppos);
  80. int vfio_platform_mmap(struct vfio_device *core_vdev,
  81. struct vm_area_struct *vma);
  82. int vfio_platform_irq_init(struct vfio_platform_device *vdev);
  83. void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
  84. int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
  85. uint32_t flags, unsigned index,
  86. unsigned start, unsigned count, void *data);
  87. void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
  88. void vfio_platform_unregister_reset(const char *compat,
  89. vfio_platform_reset_fn_t fn);
  90. #define vfio_platform_register_reset(__compat, __reset) \
  91. static struct vfio_platform_reset_node __reset ## _node = { \
  92. .owner = THIS_MODULE, \
  93. .compat = __compat, \
  94. .of_reset = __reset, \
  95. }; \
  96. __vfio_platform_register_reset(&__reset ## _node)
  97. #define module_vfio_reset_handler(compat, reset) \
  98. MODULE_ALIAS("vfio-reset:" compat); \
  99. static int __init reset ## _module_init(void) \
  100. { \
  101. vfio_platform_register_reset(compat, reset); \
  102. return 0; \
  103. }; \
  104. static void __exit reset ## _module_exit(void) \
  105. { \
  106. vfio_platform_unregister_reset(compat, reset); \
  107. }; \
  108. module_init(reset ## _module_init); \
  109. module_exit(reset ## _module_exit)
  110. #endif /* VFIO_PLATFORM_PRIVATE_H */