vfio_platform_private.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. /*
  52. * These fields should be filled by the bus specific binder
  53. */
  54. void *opaque;
  55. const char *name;
  56. uint32_t flags;
  57. /* callbacks to discover device resources */
  58. struct resource*
  59. (*get_resource)(struct vfio_platform_device *vdev, int i);
  60. int (*get_irq)(struct vfio_platform_device *vdev, int i);
  61. };
  62. extern int vfio_platform_probe_common(struct vfio_platform_device *vdev,
  63. struct device *dev);
  64. extern struct vfio_platform_device *vfio_platform_remove_common
  65. (struct device *dev);
  66. extern int vfio_platform_irq_init(struct vfio_platform_device *vdev);
  67. extern void vfio_platform_irq_cleanup(struct vfio_platform_device *vdev);
  68. extern int vfio_platform_set_irqs_ioctl(struct vfio_platform_device *vdev,
  69. uint32_t flags, unsigned index,
  70. unsigned start, unsigned count,
  71. void *data);
  72. #endif /* VFIO_PLATFORM_PRIVATE_H */