vfio_pci_private.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include <linux/irqbypass.h>
  16. #ifndef VFIO_PCI_PRIVATE_H
  17. #define VFIO_PCI_PRIVATE_H
  18. #define VFIO_PCI_OFFSET_SHIFT 40
  19. #define VFIO_PCI_OFFSET_TO_INDEX(off) (off >> VFIO_PCI_OFFSET_SHIFT)
  20. #define VFIO_PCI_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_PCI_OFFSET_SHIFT)
  21. #define VFIO_PCI_OFFSET_MASK (((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1)
  22. struct vfio_pci_irq_ctx {
  23. struct eventfd_ctx *trigger;
  24. struct virqfd *unmask;
  25. struct virqfd *mask;
  26. char *name;
  27. bool masked;
  28. struct irq_bypass_producer producer;
  29. };
  30. struct vfio_pci_device {
  31. struct pci_dev *pdev;
  32. void __iomem *barmap[PCI_STD_RESOURCE_END + 1];
  33. u8 *pci_config_map;
  34. u8 *vconfig;
  35. struct perm_bits *msi_perm;
  36. spinlock_t irqlock;
  37. struct mutex igate;
  38. struct msix_entry *msix;
  39. struct vfio_pci_irq_ctx *ctx;
  40. int num_ctx;
  41. int irq_type;
  42. u8 msi_qmax;
  43. u8 msix_bar;
  44. u16 msix_size;
  45. u32 msix_offset;
  46. u32 rbar[7];
  47. bool pci_2_3;
  48. bool virq_disabled;
  49. bool reset_works;
  50. bool extended_caps;
  51. bool bardirty;
  52. bool has_vga;
  53. bool needs_reset;
  54. struct pci_saved_state *pci_saved_state;
  55. int refcnt;
  56. struct eventfd_ctx *err_trigger;
  57. struct eventfd_ctx *req_trigger;
  58. };
  59. #define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX)
  60. #define is_msi(vdev) (vdev->irq_type == VFIO_PCI_MSI_IRQ_INDEX)
  61. #define is_msix(vdev) (vdev->irq_type == VFIO_PCI_MSIX_IRQ_INDEX)
  62. #define is_irq_none(vdev) (!(is_intx(vdev) || is_msi(vdev) || is_msix(vdev)))
  63. #define irq_is(vdev, type) (vdev->irq_type == type)
  64. extern void vfio_pci_intx_mask(struct vfio_pci_device *vdev);
  65. extern void vfio_pci_intx_unmask(struct vfio_pci_device *vdev);
  66. extern int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev,
  67. uint32_t flags, unsigned index,
  68. unsigned start, unsigned count, void *data);
  69. extern ssize_t vfio_pci_config_rw(struct vfio_pci_device *vdev,
  70. char __user *buf, size_t count,
  71. loff_t *ppos, bool iswrite);
  72. extern ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
  73. size_t count, loff_t *ppos, bool iswrite);
  74. extern ssize_t vfio_pci_vga_rw(struct vfio_pci_device *vdev, char __user *buf,
  75. size_t count, loff_t *ppos, bool iswrite);
  76. extern int vfio_pci_init_perm_bits(void);
  77. extern void vfio_pci_uninit_perm_bits(void);
  78. extern int vfio_config_init(struct vfio_pci_device *vdev);
  79. extern void vfio_config_free(struct vfio_pci_device *vdev);
  80. #endif /* VFIO_PCI_PRIVATE_H */