diff options
Diffstat (limited to 'drivers/vfio/pci/vfio_pci_private.h')
-rw-r--r-- | drivers/vfio/pci/vfio_pci_private.h | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h new file mode 100644 index 000000000000..611827cba8cd --- /dev/null +++ b/drivers/vfio/pci/vfio_pci_private.h | |||
@@ -0,0 +1,91 @@ | |||
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 | |||
14 | #include <linux/mutex.h> | ||
15 | #include <linux/pci.h> | ||
16 | |||
17 | #ifndef VFIO_PCI_PRIVATE_H | ||
18 | #define VFIO_PCI_PRIVATE_H | ||
19 | |||
20 | #define VFIO_PCI_OFFSET_SHIFT 40 | ||
21 | |||
22 | #define VFIO_PCI_OFFSET_TO_INDEX(off) (off >> VFIO_PCI_OFFSET_SHIFT) | ||
23 | #define VFIO_PCI_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_PCI_OFFSET_SHIFT) | ||
24 | #define VFIO_PCI_OFFSET_MASK (((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1) | ||
25 | |||
26 | struct vfio_pci_irq_ctx { | ||
27 | struct eventfd_ctx *trigger; | ||
28 | struct virqfd *unmask; | ||
29 | struct virqfd *mask; | ||
30 | char *name; | ||
31 | bool masked; | ||
32 | }; | ||
33 | |||
34 | struct vfio_pci_device { | ||
35 | struct pci_dev *pdev; | ||
36 | void __iomem *barmap[PCI_STD_RESOURCE_END + 1]; | ||
37 | u8 *pci_config_map; | ||
38 | u8 *vconfig; | ||
39 | struct perm_bits *msi_perm; | ||
40 | spinlock_t irqlock; | ||
41 | struct mutex igate; | ||
42 | struct msix_entry *msix; | ||
43 | struct vfio_pci_irq_ctx *ctx; | ||
44 | int num_ctx; | ||
45 | int irq_type; | ||
46 | u8 msi_qmax; | ||
47 | u8 msix_bar; | ||
48 | u16 msix_size; | ||
49 | u32 msix_offset; | ||
50 | u32 rbar[7]; | ||
51 | bool pci_2_3; | ||
52 | bool virq_disabled; | ||
53 | bool reset_works; | ||
54 | bool extended_caps; | ||
55 | bool bardirty; | ||
56 | struct pci_saved_state *pci_saved_state; | ||
57 | atomic_t refcnt; | ||
58 | }; | ||
59 | |||
60 | #define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX) | ||
61 | #define is_msi(vdev) (vdev->irq_type == VFIO_PCI_MSI_IRQ_INDEX) | ||
62 | #define is_msix(vdev) (vdev->irq_type == VFIO_PCI_MSIX_IRQ_INDEX) | ||
63 | #define is_irq_none(vdev) (!(is_intx(vdev) || is_msi(vdev) || is_msix(vdev))) | ||
64 | #define irq_is(vdev, type) (vdev->irq_type == type) | ||
65 | |||
66 | extern void vfio_pci_intx_mask(struct vfio_pci_device *vdev); | ||
67 | extern void vfio_pci_intx_unmask(struct vfio_pci_device *vdev); | ||
68 | |||
69 | extern int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, | ||
70 | uint32_t flags, unsigned index, | ||
71 | unsigned start, unsigned count, void *data); | ||
72 | |||
73 | extern ssize_t vfio_pci_config_readwrite(struct vfio_pci_device *vdev, | ||
74 | char __user *buf, size_t count, | ||
75 | loff_t *ppos, bool iswrite); | ||
76 | extern ssize_t vfio_pci_mem_readwrite(struct vfio_pci_device *vdev, | ||
77 | char __user *buf, size_t count, | ||
78 | loff_t *ppos, bool iswrite); | ||
79 | extern ssize_t vfio_pci_io_readwrite(struct vfio_pci_device *vdev, | ||
80 | char __user *buf, size_t count, | ||
81 | loff_t *ppos, bool iswrite); | ||
82 | |||
83 | extern int vfio_pci_init_perm_bits(void); | ||
84 | extern void vfio_pci_uninit_perm_bits(void); | ||
85 | |||
86 | extern int vfio_pci_virqfd_init(void); | ||
87 | extern void vfio_pci_virqfd_exit(void); | ||
88 | |||
89 | extern int vfio_config_init(struct vfio_pci_device *vdev); | ||
90 | extern void vfio_config_free(struct vfio_pci_device *vdev); | ||
91 | #endif /* VFIO_PCI_PRIVATE_H */ | ||