vfio_platform_private.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. struct module *reset_module;
  54. struct device *device;
  55. /*
  56. * These fields should be filled by the bus specific binder
  57. */
  58. void *opaque;
  59. const char *name;
  60. uint32_t flags;
  61. /* callbacks to discover device resources */
  62. struct resource*
  63. (*get_resource)(struct vfio_platform_device *vdev, int i);
  64. int (*get_irq)(struct vfio_platform_device *vdev, int i);
  65. int (*reset)(struct vfio_platform_device *vdev);
  66. };
  67. typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev);
  68. struct vfio_platform_reset_node {
  69. struct list_head link;
  70. char *compat;
  71. struct module *owner;
  72. vfio_platform_reset_fn_t reset;
  73. };
  74. extern int vfio_platform_probe_common(struct vfio_platform_device *vdev,
  75. struct device *dev);
  76. extern struct vfio_platform_device *vfio_platform_remove_common
  77. (struct device *dev);
  78. extern int vfio_platform_irq_init(struct vfio_platform_device *vdev);
  79. extern void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
  80. extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
  81. uint32_t flags, unsigned index,
  82. unsigned start, unsigned count,
  83. void *data);
  84. extern void __vfio_platform_register_reset(struct vfio_platform_reset_node *n);
  85. extern void vfio_platform_unregister_reset(const char *compat,
  86. vfio_platform_reset_fn_t fn);
  87. #define vfio_platform_register_reset(__compat, __reset) \
  88. static struct vfio_platform_reset_node __reset ## _node = { \
  89. .owner = THIS_MODULE, \
  90. .compat = __compat, \
  91. .reset = __reset, \
  92. }; \
  93. __vfio_platform_register_reset(&__reset ## _node)
  94. #define module_vfio_reset_handler(compat, reset) \
  95. MODULE_ALIAS("vfio-reset:" compat); \
  96. static int __init reset ## _module_init(void) \
  97. { \
  98. vfio_platform_register_reset(compat, reset); \
  99. return 0; \
  100. }; \
  101. static void __exit reset ## _module_exit(void) \
  102. { \
  103. vfio_platform_unregister_reset(compat, reset); \
  104. }; \
  105. module_init(reset ## _module_init); \
  106. module_exit(reset ## _module_exit)
  107. #endif /* VFIO_PLATFORM_PRIVATE_H */