gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / vfio / pci / vfio_pci_private.h
blob36ec69081ecd327a7012ea50ddbdcd7d6986d42a
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2012 Red Hat, Inc. All rights reserved.
4 * Author: Alex Williamson <alex.williamson@redhat.com>
6 * Derived from original vfio:
7 * Copyright 2010 Cisco Systems, Inc. All rights reserved.
8 * Author: Tom Lyon, pugs@cisco.com
9 */
11 #include <linux/mutex.h>
12 #include <linux/pci.h>
13 #include <linux/irqbypass.h>
14 #include <linux/types.h>
15 #include <linux/uuid.h>
16 #include <linux/notifier.h>
18 #ifndef VFIO_PCI_PRIVATE_H
19 #define VFIO_PCI_PRIVATE_H
21 #define VFIO_PCI_OFFSET_SHIFT 40
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)
27 /* Special capability IDs predefined access */
28 #define PCI_CAP_ID_INVALID 0xFF /* default raw access */
29 #define PCI_CAP_ID_INVALID_VIRT 0xFE /* default virt access */
31 /* Cap maximum number of ioeventfds per device (arbitrary) */
32 #define VFIO_PCI_IOEVENTFD_MAX 1000
34 struct vfio_pci_ioeventfd {
35 struct list_head next;
36 struct virqfd *virqfd;
37 void __iomem *addr;
38 uint64_t data;
39 loff_t pos;
40 int bar;
41 int count;
44 struct vfio_pci_irq_ctx {
45 struct eventfd_ctx *trigger;
46 struct virqfd *unmask;
47 struct virqfd *mask;
48 char *name;
49 bool masked;
50 struct irq_bypass_producer producer;
53 struct vfio_pci_device;
54 struct vfio_pci_region;
56 struct vfio_pci_regops {
57 size_t (*rw)(struct vfio_pci_device *vdev, char __user *buf,
58 size_t count, loff_t *ppos, bool iswrite);
59 void (*release)(struct vfio_pci_device *vdev,
60 struct vfio_pci_region *region);
61 int (*mmap)(struct vfio_pci_device *vdev,
62 struct vfio_pci_region *region,
63 struct vm_area_struct *vma);
64 int (*add_capability)(struct vfio_pci_device *vdev,
65 struct vfio_pci_region *region,
66 struct vfio_info_cap *caps);
69 struct vfio_pci_region {
70 u32 type;
71 u32 subtype;
72 const struct vfio_pci_regops *ops;
73 void *data;
74 size_t size;
75 u32 flags;
78 struct vfio_pci_dummy_resource {
79 struct resource resource;
80 int index;
81 struct list_head res_next;
84 struct vfio_pci_reflck {
85 struct kref kref;
86 struct mutex lock;
89 struct vfio_pci_vf_token {
90 struct mutex lock;
91 uuid_t uuid;
92 int users;
95 struct vfio_pci_device {
96 struct pci_dev *pdev;
97 void __iomem *barmap[PCI_STD_NUM_BARS];
98 bool bar_mmap_supported[PCI_STD_NUM_BARS];
99 u8 *pci_config_map;
100 u8 *vconfig;
101 struct perm_bits *msi_perm;
102 spinlock_t irqlock;
103 struct mutex igate;
104 struct vfio_pci_irq_ctx *ctx;
105 int num_ctx;
106 int irq_type;
107 int num_regions;
108 struct vfio_pci_region *region;
109 u8 msi_qmax;
110 u8 msix_bar;
111 u16 msix_size;
112 u32 msix_offset;
113 u32 rbar[7];
114 bool pci_2_3;
115 bool virq_disabled;
116 bool reset_works;
117 bool extended_caps;
118 bool bardirty;
119 bool has_vga;
120 bool needs_reset;
121 bool nointx;
122 bool needs_pm_restore;
123 struct pci_saved_state *pci_saved_state;
124 struct pci_saved_state *pm_save;
125 struct vfio_pci_reflck *reflck;
126 int refcnt;
127 int ioeventfds_nr;
128 struct eventfd_ctx *err_trigger;
129 struct eventfd_ctx *req_trigger;
130 struct list_head dummy_resources_list;
131 struct mutex ioeventfds_lock;
132 struct list_head ioeventfds_list;
133 struct vfio_pci_vf_token *vf_token;
134 struct notifier_block nb;
137 #define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX)
138 #define is_msi(vdev) (vdev->irq_type == VFIO_PCI_MSI_IRQ_INDEX)
139 #define is_msix(vdev) (vdev->irq_type == VFIO_PCI_MSIX_IRQ_INDEX)
140 #define is_irq_none(vdev) (!(is_intx(vdev) || is_msi(vdev) || is_msix(vdev)))
141 #define irq_is(vdev, type) (vdev->irq_type == type)
143 extern void vfio_pci_intx_mask(struct vfio_pci_device *vdev);
144 extern void vfio_pci_intx_unmask(struct vfio_pci_device *vdev);
146 extern int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev,
147 uint32_t flags, unsigned index,
148 unsigned start, unsigned count, void *data);
150 extern ssize_t vfio_pci_config_rw(struct vfio_pci_device *vdev,
151 char __user *buf, size_t count,
152 loff_t *ppos, bool iswrite);
154 extern ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
155 size_t count, loff_t *ppos, bool iswrite);
157 extern ssize_t vfio_pci_vga_rw(struct vfio_pci_device *vdev, char __user *buf,
158 size_t count, loff_t *ppos, bool iswrite);
160 extern long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset,
161 uint64_t data, int count, int fd);
163 extern int vfio_pci_init_perm_bits(void);
164 extern void vfio_pci_uninit_perm_bits(void);
166 extern int vfio_config_init(struct vfio_pci_device *vdev);
167 extern void vfio_config_free(struct vfio_pci_device *vdev);
169 extern int vfio_pci_register_dev_region(struct vfio_pci_device *vdev,
170 unsigned int type, unsigned int subtype,
171 const struct vfio_pci_regops *ops,
172 size_t size, u32 flags, void *data);
174 extern int vfio_pci_set_power_state(struct vfio_pci_device *vdev,
175 pci_power_t state);
177 #ifdef CONFIG_VFIO_PCI_IGD
178 extern int vfio_pci_igd_init(struct vfio_pci_device *vdev);
179 #else
180 static inline int vfio_pci_igd_init(struct vfio_pci_device *vdev)
182 return -ENODEV;
184 #endif
185 #ifdef CONFIG_VFIO_PCI_NVLINK2
186 extern int vfio_pci_nvdia_v100_nvlink2_init(struct vfio_pci_device *vdev);
187 extern int vfio_pci_ibm_npu2_init(struct vfio_pci_device *vdev);
188 #else
189 static inline int vfio_pci_nvdia_v100_nvlink2_init(struct vfio_pci_device *vdev)
191 return -ENODEV;
194 static inline int vfio_pci_ibm_npu2_init(struct vfio_pci_device *vdev)
196 return -ENODEV;
198 #endif
199 #endif /* VFIO_PCI_PRIVATE_H */