Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
89e1f7d4 AW |
2 | /* |
3 | * Copyright (C) 2012 Red Hat, Inc. All rights reserved. | |
4 | * Author: Alex Williamson <alex.williamson@redhat.com> | |
5 | * | |
89e1f7d4 AW |
6 | * Derived from original vfio: |
7 | * Copyright 2010 Cisco Systems, Inc. All rights reserved. | |
8 | * Author: Tom Lyon, pugs@cisco.com | |
9 | */ | |
10 | ||
11 | #include <linux/mutex.h> | |
12 | #include <linux/pci.h> | |
c39f8fa7 | 13 | #include <linux/vfio.h> |
6d7425f1 | 14 | #include <linux/irqbypass.h> |
28541d41 | 15 | #include <linux/types.h> |
cc20d799 | 16 | #include <linux/uuid.h> |
137e5531 | 17 | #include <linux/notifier.h> |
89e1f7d4 | 18 | |
9a389938 MG |
19 | #ifndef VFIO_PCI_CORE_H |
20 | #define VFIO_PCI_CORE_H | |
89e1f7d4 AW |
21 | |
22 | #define VFIO_PCI_OFFSET_SHIFT 40 | |
89e1f7d4 AW |
23 | #define VFIO_PCI_OFFSET_TO_INDEX(off) (off >> VFIO_PCI_OFFSET_SHIFT) |
24 | #define VFIO_PCI_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_PCI_OFFSET_SHIFT) | |
25 | #define VFIO_PCI_OFFSET_MASK (((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1) | |
26 | ||
53647510 | 27 | struct vfio_pci_core_device; |
28541d41 AW |
28 | struct vfio_pci_region; |
29 | ||
30 | struct vfio_pci_regops { | |
53647510 | 31 | ssize_t (*rw)(struct vfio_pci_core_device *vdev, char __user *buf, |
28541d41 | 32 | size_t count, loff_t *ppos, bool iswrite); |
53647510 | 33 | void (*release)(struct vfio_pci_core_device *vdev, |
28541d41 | 34 | struct vfio_pci_region *region); |
53647510 | 35 | int (*mmap)(struct vfio_pci_core_device *vdev, |
a15b1883 AK |
36 | struct vfio_pci_region *region, |
37 | struct vm_area_struct *vma); | |
53647510 | 38 | int (*add_capability)(struct vfio_pci_core_device *vdev, |
c2c0f1cd AK |
39 | struct vfio_pci_region *region, |
40 | struct vfio_info_cap *caps); | |
28541d41 AW |
41 | }; |
42 | ||
43 | struct vfio_pci_region { | |
44 | u32 type; | |
45 | u32 subtype; | |
46 | const struct vfio_pci_regops *ops; | |
47 | void *data; | |
48 | size_t size; | |
49 | u32 flags; | |
50 | }; | |
51 | ||
53647510 | 52 | struct vfio_pci_core_device { |
6b018e20 | 53 | struct vfio_device vdev; |
89e1f7d4 | 54 | struct pci_dev *pdev; |
c9c13ba4 DE |
55 | void __iomem *barmap[PCI_STD_NUM_BARS]; |
56 | bool bar_mmap_supported[PCI_STD_NUM_BARS]; | |
89e1f7d4 AW |
57 | u8 *pci_config_map; |
58 | u8 *vconfig; | |
59 | struct perm_bits *msi_perm; | |
60 | spinlock_t irqlock; | |
61 | struct mutex igate; | |
89e1f7d4 AW |
62 | struct vfio_pci_irq_ctx *ctx; |
63 | int num_ctx; | |
64 | int irq_type; | |
28541d41 AW |
65 | int num_regions; |
66 | struct vfio_pci_region *region; | |
89e1f7d4 AW |
67 | u8 msi_qmax; |
68 | u8 msix_bar; | |
69 | u16 msix_size; | |
70 | u32 msix_offset; | |
71 | u32 rbar[7]; | |
72 | bool pci_2_3; | |
73 | bool virq_disabled; | |
74 | bool reset_works; | |
75 | bool extended_caps; | |
76 | bool bardirty; | |
84237a82 | 77 | bool has_vga; |
bc4fba77 | 78 | bool needs_reset; |
45074405 | 79 | bool nointx; |
51ef3a00 | 80 | bool needs_pm_restore; |
4813724c | 81 | bool pm_intx_masked; |
cc2742fe | 82 | bool pm_runtime_engaged; |
89e1f7d4 | 83 | struct pci_saved_state *pci_saved_state; |
51ef3a00 | 84 | struct pci_saved_state *pm_save; |
30656177 | 85 | int ioeventfds_nr; |
dad9f897 | 86 | struct eventfd_ctx *err_trigger; |
6140a8f5 | 87 | struct eventfd_ctx *req_trigger; |
453e6c98 | 88 | struct eventfd_ctx *pm_wake_eventfd_ctx; |
05f0c03f | 89 | struct list_head dummy_resources_list; |
30656177 AW |
90 | struct mutex ioeventfds_lock; |
91 | struct list_head ioeventfds_list; | |
cc20d799 | 92 | struct vfio_pci_vf_token *vf_token; |
1ef3342a JG |
93 | struct list_head sriov_pfs_item; |
94 | struct vfio_pci_core_device *sriov_pf_core_dev; | |
137e5531 | 95 | struct notifier_block nb; |
11c4cd07 AW |
96 | struct mutex vma_lock; |
97 | struct list_head vma_list; | |
abafbc55 | 98 | struct rw_semaphore memory_lock; |
89e1f7d4 AW |
99 | }; |
100 | ||
e34a0425 | 101 | /* Will be exported for vfio pci drivers usage */ |
1e979ef5 JG |
102 | int vfio_pci_core_register_dev_region(struct vfio_pci_core_device *vdev, |
103 | unsigned int type, unsigned int subtype, | |
104 | const struct vfio_pci_regops *ops, | |
105 | size_t size, u32 flags, void *data); | |
c61302aa YH |
106 | void vfio_pci_core_set_params(bool nointxmask, bool is_disable_vga, |
107 | bool is_disable_idle_d3); | |
ff53edf6 | 108 | void vfio_pci_core_close_device(struct vfio_device *core_vdev); |
63d7c779 YL |
109 | int vfio_pci_core_init_dev(struct vfio_device *core_vdev); |
110 | void vfio_pci_core_release_dev(struct vfio_device *core_vdev); | |
ff53edf6 | 111 | int vfio_pci_core_register_device(struct vfio_pci_core_device *vdev); |
ff53edf6 | 112 | void vfio_pci_core_unregister_device(struct vfio_pci_core_device *vdev); |
ff53edf6 | 113 | extern const struct pci_error_handlers vfio_pci_core_err_handlers; |
ff806cbd JG |
114 | int vfio_pci_core_sriov_configure(struct vfio_pci_core_device *vdev, |
115 | int nr_virtfn); | |
ff53edf6 MG |
116 | long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, |
117 | unsigned long arg); | |
445ad495 JG |
118 | int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags, |
119 | void __user *arg, size_t argsz); | |
ff53edf6 MG |
120 | ssize_t vfio_pci_core_read(struct vfio_device *core_vdev, char __user *buf, |
121 | size_t count, loff_t *ppos); | |
122 | ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *buf, | |
123 | size_t count, loff_t *ppos); | |
124 | int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma); | |
125 | void vfio_pci_core_request(struct vfio_device *core_vdev, unsigned int count); | |
126 | int vfio_pci_core_match(struct vfio_device *core_vdev, char *buf); | |
2fb89f56 MG |
127 | int vfio_pci_core_enable(struct vfio_pci_core_device *vdev); |
128 | void vfio_pci_core_disable(struct vfio_pci_core_device *vdev); | |
129 | void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev); | |
915076f7 YH |
130 | pci_ers_result_t vfio_pci_core_aer_err_detected(struct pci_dev *pdev, |
131 | pci_channel_state_t state); | |
2fb89f56 | 132 | |
9a389938 | 133 | #endif /* VFIO_PCI_CORE_H */ |