.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2012 Red Hat, Inc. All rights reserved. |
---|
3 | 4 | * 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 | 5 | * |
---|
9 | 6 | * Derived from original vfio: |
---|
10 | 7 | * Copyright 2010 Cisco Systems, Inc. All rights reserved. |
---|
.. | .. |
---|
15 | 12 | #include <linux/pci.h> |
---|
16 | 13 | #include <linux/irqbypass.h> |
---|
17 | 14 | #include <linux/types.h> |
---|
| 15 | +#include <linux/uuid.h> |
---|
| 16 | +#include <linux/notifier.h> |
---|
18 | 17 | |
---|
19 | 18 | #ifndef VFIO_PCI_PRIVATE_H |
---|
20 | 19 | #define VFIO_PCI_PRIVATE_H |
---|
.. | .. |
---|
34 | 33 | |
---|
35 | 34 | struct vfio_pci_ioeventfd { |
---|
36 | 35 | struct list_head next; |
---|
| 36 | + struct vfio_pci_device *vdev; |
---|
37 | 37 | struct virqfd *virqfd; |
---|
38 | 38 | void __iomem *addr; |
---|
39 | 39 | uint64_t data; |
---|
40 | 40 | loff_t pos; |
---|
41 | 41 | int bar; |
---|
42 | 42 | int count; |
---|
| 43 | + bool test_mem; |
---|
43 | 44 | }; |
---|
44 | 45 | |
---|
45 | 46 | struct vfio_pci_irq_ctx { |
---|
.. | .. |
---|
59 | 60 | size_t count, loff_t *ppos, bool iswrite); |
---|
60 | 61 | void (*release)(struct vfio_pci_device *vdev, |
---|
61 | 62 | struct vfio_pci_region *region); |
---|
| 63 | + int (*mmap)(struct vfio_pci_device *vdev, |
---|
| 64 | + struct vfio_pci_region *region, |
---|
| 65 | + struct vm_area_struct *vma); |
---|
| 66 | + int (*add_capability)(struct vfio_pci_device *vdev, |
---|
| 67 | + struct vfio_pci_region *region, |
---|
| 68 | + struct vfio_info_cap *caps); |
---|
62 | 69 | }; |
---|
63 | 70 | |
---|
64 | 71 | struct vfio_pci_region { |
---|
.. | .. |
---|
76 | 83 | struct list_head res_next; |
---|
77 | 84 | }; |
---|
78 | 85 | |
---|
| 86 | +struct vfio_pci_reflck { |
---|
| 87 | + struct kref kref; |
---|
| 88 | + struct mutex lock; |
---|
| 89 | +}; |
---|
| 90 | + |
---|
| 91 | +struct vfio_pci_vf_token { |
---|
| 92 | + struct mutex lock; |
---|
| 93 | + uuid_t uuid; |
---|
| 94 | + int users; |
---|
| 95 | +}; |
---|
| 96 | + |
---|
79 | 97 | struct vfio_pci_mmap_vma { |
---|
80 | 98 | struct vm_area_struct *vma; |
---|
81 | 99 | struct list_head vma_next; |
---|
.. | .. |
---|
83 | 101 | |
---|
84 | 102 | struct vfio_pci_device { |
---|
85 | 103 | struct pci_dev *pdev; |
---|
86 | | - void __iomem *barmap[PCI_STD_RESOURCE_END + 1]; |
---|
87 | | - bool bar_mmap_supported[PCI_STD_RESOURCE_END + 1]; |
---|
| 104 | + void __iomem *barmap[PCI_STD_NUM_BARS]; |
---|
| 105 | + bool bar_mmap_supported[PCI_STD_NUM_BARS]; |
---|
88 | 106 | u8 *pci_config_map; |
---|
89 | 107 | u8 *vconfig; |
---|
90 | 108 | struct perm_bits *msi_perm; |
---|
.. | .. |
---|
108 | 126 | bool has_vga; |
---|
109 | 127 | bool needs_reset; |
---|
110 | 128 | bool nointx; |
---|
| 129 | + bool needs_pm_restore; |
---|
111 | 130 | struct pci_saved_state *pci_saved_state; |
---|
| 131 | + struct pci_saved_state *pm_save; |
---|
| 132 | + struct vfio_pci_reflck *reflck; |
---|
112 | 133 | int refcnt; |
---|
113 | 134 | int ioeventfds_nr; |
---|
114 | 135 | struct eventfd_ctx *err_trigger; |
---|
.. | .. |
---|
116 | 137 | struct list_head dummy_resources_list; |
---|
117 | 138 | struct mutex ioeventfds_lock; |
---|
118 | 139 | struct list_head ioeventfds_list; |
---|
| 140 | + struct vfio_pci_vf_token *vf_token; |
---|
| 141 | + struct notifier_block nb; |
---|
119 | 142 | struct mutex vma_lock; |
---|
120 | 143 | struct list_head vma_list; |
---|
121 | 144 | struct rw_semaphore memory_lock; |
---|
.. | .. |
---|
158 | 181 | const struct vfio_pci_regops *ops, |
---|
159 | 182 | size_t size, u32 flags, void *data); |
---|
160 | 183 | |
---|
| 184 | +extern int vfio_pci_set_power_state(struct vfio_pci_device *vdev, |
---|
| 185 | + pci_power_t state); |
---|
| 186 | + |
---|
161 | 187 | extern bool __vfio_pci_memory_enabled(struct vfio_pci_device *vdev); |
---|
162 | 188 | extern void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_device |
---|
163 | 189 | *vdev); |
---|
.. | .. |
---|
173 | 199 | return -ENODEV; |
---|
174 | 200 | } |
---|
175 | 201 | #endif |
---|
| 202 | +#ifdef CONFIG_VFIO_PCI_NVLINK2 |
---|
| 203 | +extern int vfio_pci_nvdia_v100_nvlink2_init(struct vfio_pci_device *vdev); |
---|
| 204 | +extern int vfio_pci_ibm_npu2_init(struct vfio_pci_device *vdev); |
---|
| 205 | +#else |
---|
| 206 | +static inline int vfio_pci_nvdia_v100_nvlink2_init(struct vfio_pci_device *vdev) |
---|
| 207 | +{ |
---|
| 208 | + return -ENODEV; |
---|
| 209 | +} |
---|
| 210 | + |
---|
| 211 | +static inline int vfio_pci_ibm_npu2_init(struct vfio_pci_device *vdev) |
---|
| 212 | +{ |
---|
| 213 | + return -ENODEV; |
---|
| 214 | +} |
---|
| 215 | +#endif |
---|
| 216 | + |
---|
| 217 | +#ifdef CONFIG_VFIO_PCI_ZDEV |
---|
| 218 | +extern int vfio_pci_info_zdev_add_caps(struct vfio_pci_device *vdev, |
---|
| 219 | + struct vfio_info_cap *caps); |
---|
| 220 | +#else |
---|
| 221 | +static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_device *vdev, |
---|
| 222 | + struct vfio_info_cap *caps) |
---|
| 223 | +{ |
---|
| 224 | + return -ENODEV; |
---|
| 225 | +} |
---|
| 226 | +#endif |
---|
| 227 | + |
---|
176 | 228 | #endif /* VFIO_PCI_PRIVATE_H */ |
---|