vfio_platform_private.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2013 - Virtual Open Systems
  3. * Author: Antonios Motakis <a.motakis@virtualopensystems.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License, version 2, as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef VFIO_PLATFORM_PRIVATE_H
  15. #define VFIO_PLATFORM_PRIVATE_H
  16. #include <linux/types.h>
  17. #include <linux/interrupt.h>
  18. #define VFIO_PLATFORM_OFFSET_SHIFT 40
  19. #define VFIO_PLATFORM_OFFSET_MASK (((u64)(1) << VFIO_PLATFORM_OFFSET_SHIFT) - 1)
  20. #define VFIO_PLATFORM_OFFSET_TO_INDEX(off) \
  21. (off >> VFIO_PLATFORM_OFFSET_SHIFT)
  22. #define VFIO_PLATFORM_INDEX_TO_OFFSET(index) \
  23. ((u64)(index) << VFIO_PLATFORM_OFFSET_SHIFT)
  24. struct vfio_platform_irq {
  25. u32 flags;
  26. u32 count;
  27. int hwirq;
  28. char *name;
  29. struct eventfd_ctx *trigger;
  30. bool masked;
  31. spinlock_t lock;
  32. struct virqfd *unmask;
  33. struct virqfd *mask;
  34. };
  35. struct vfio_platform_region {
  36. u64 addr;
  37. resource_size_t size;
  38. u32 flags;
  39. u32 type;
  40. #define VFIO_PLATFORM_REGION_TYPE_MMIO 1
  41. #define VFIO_PLATFORM_REGION_TYPE_PIO 2
  42. void __iomem *ioaddr;
  43. };
  44. struct vfio_platform_device {
  45. struct vfio_platform_region *regions;
  46. u32 num_regions;
  47. struct vfio_platform_irq *irqs;
  48. u32 num_irqs;
  49. int refcnt;
  50. struct mutex igate;
  51. struct module *parent_module;
  52. const char *compat;
  53. const char *acpihid;
  54. struct module *reset_module;
  55. struct device *device;
  56. /*
  57. * These fields should be filled by the bus specific binder
  58. */
  59. void *opaque;
  60. const char *name;
  61. uint32_t flags;
  62. /* callbacks to discover device resources */
  63. struct resource*
  64. (*get_resource)(struct vfio_platform_device *vdev, int i);
  65. int (*get_irq)(struct vfio_platform_device *vdev, int i);
  66. int (*of_reset)(struct vfio_platform_device *vdev);
  67. bool reset_required;
  68. };
  69. typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev);
  70. struct vfio_platform_reset_node {
  71. struct list_head link;
  72. char *compat;
  73. struct module *owner;
  74. vfio_platform_reset_fn_t of_reset;
  75. };
  76. extern int vfio_platform_probe_common(struct vfio_platform_device *vdev,
  77. struct device *dev);
  78. extern struct vfio_platform_device *vfio_platform_remove_common
  79. (struct device *dev);
  80. extern int vfio_platform_irq_init(struct vfio_platform_device *vdev);
  81. extern void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
  82. extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
  83. uint32_t flags, unsigned index,
  84. unsigned start, unsigned count,
  85. void *data);
  86. extern void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
  87. extern void vfio_platform_unregister_reset(const char *compat,
  88. vfio_platform_reset_fn_t fn);
  89. #define vfio_platform_register_reset(__compat, __reset) \
  90. static struct vfio_platform_reset_node __reset ## _node = { \
  91. .owner = THIS_MODULE, \
  92. .compat = __compat, \
  93. .of_reset = __reset, \
  94. }; \
  95. __vfio_platform_register_reset(&__reset ## _node)
  96. #define module_vfio_reset_handler(compat, reset) \
  97. MODULE_ALIAS("vfio-reset:" compat); \
  98. static int __init reset ## _module_init(void) \
  99. { \
  100. vfio_platform_register_reset(compat, reset); \
  101. return 0; \
  102. }; \
  103. static void __exit reset ## _module_exit(void) \
  104. { \
  105. vfio_platform_unregister_reset(compat, reset); \
  106. }; \
  107. module_init(reset ## _module_init); \
  108. module_exit(reset ## _module_exit)
  109. #endif /* VFIO_PLATFORM_PRIVATE_H */