vfio_pci_private.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2012 Red Hat, Inc. All rights reserved.
  3. * Author: Alex Williamson <alex.williamson@redhat.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. * Derived from original vfio:
  10. * Copyright 2010 Cisco Systems, Inc. All rights reserved.
  11. * Author: Tom Lyon, pugs@cisco.com
  12. */
  13. #include <linux/mutex.h>
  14. #include <linux/pci.h>
  15. #ifndef VFIO_PCI_PRIVATE_H
  16. #define VFIO_PCI_PRIVATE_H
  17. #define VFIO_PCI_OFFSET_SHIFT 40
  18. #define VFIO_PCI_OFFSET_TO_INDEX(off) (off >> VFIO_PCI_OFFSET_SHIFT)
  19. #define VFIO_PCI_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_PCI_OFFSET_SHIFT)
  20. #define VFIO_PCI_OFFSET_MASK (((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1)
  21. struct vfio_pci_irq_ctx {
  22. struct eventfd_ctx *trigger;
  23. struct virqfd *unmask;
  24. struct virqfd *mask;
  25. char *name;
  26. bool masked;
  27. };
  28. struct vfio_pci_device {
  29. struct pci_dev *pdev;
  30. void __iomem *barmap[PCI_STD_RESOURCE_END + 1];
  31. u8 *pci_config_map;
  32. u8 *vconfig;
  33. struct perm_bits *msi_perm;
  34. spinlock_t irqlock;
  35. struct mutex igate;
  36. struct msix_entry *msix;
  37. struct vfio_pci_irq_ctx *ctx;
  38. int num_ctx;
  39. int irq_type;
  40. u8 msi_qmax;
  41. u8 msix_bar;
  42. u16 msix_size;
  43. u32 msix_offset;
  44. u32 rbar[7];
  45. bool pci_2_3;
  46. bool virq_disabled;
  47. bool reset_works;
  48. bool extended_caps;
  49. bool bardirty;
  50. bool has_vga;
  51. struct pci_saved_state *pci_saved_state;
  52. atomic_t refcnt;
  53. };
  54. #define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX)
  55. #define is_msi(vdev) (vdev->irq_type == VFIO_PCI_MSI_IRQ_INDEX)
  56. #define is_msix(vdev) (vdev->irq_type == VFIO_PCI_MSIX_IRQ_INDEX)
  57. #define is_irq_none(vdev) (!(is_intx(vdev) || is_msi(vdev) || is_msix(vdev)))
  58. #define irq_is(vdev, type) (vdev->irq_type == type)
  59. extern void vfio_pci_intx_mask(struct vfio_pci_device *vdev);
  60. extern void vfio_pci_intx_unmask(struct vfio_pci_device *vdev);
  61. extern int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev,
  62. uint32_t flags, unsigned index,
  63. unsigned start, unsigned count, void *data);
  64. extern ssize_t vfio_pci_config_rw(struct vfio_pci_device *vdev,
  65. char __user *buf, size_t count,
  66. loff_t *ppos, bool iswrite);
  67. extern ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
  68. size_t count, loff_t *ppos, bool iswrite);
  69. extern ssize_t vfio_pci_vga_rw(struct vfio_pci_device *vdev, char __user *buf,
  70. size_t count, loff_t *ppos, bool iswrite);
  71. extern int vfio_pci_init_perm_bits(void);
  72. extern void vfio_pci_uninit_perm_bits(void);
  73. extern int vfio_pci_virqfd_init(void);
  74. extern void vfio_pci_virqfd_exit(void);
  75. extern int vfio_config_init(struct vfio_pci_device *vdev);
  76. extern void vfio_config_free(struct vfio_pci_device *vdev);
  77. #endif /* VFIO_PCI_PRIVATE_H */