]> git.ipfire.org Git - thirdparty/kernel/linux.git/blame - drivers/vfio/pci/vfio_pci_private.h
vfio/pci: Parallelize device open and release
[thirdparty/kernel/linux.git] / drivers / vfio / pci / vfio_pci_private.h
CommitLineData
89e1f7d4
AW
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>
6d7425f1 16#include <linux/irqbypass.h>
28541d41 17#include <linux/types.h>
89e1f7d4
AW
18
19#ifndef VFIO_PCI_PRIVATE_H
20#define VFIO_PCI_PRIVATE_H
21
22#define VFIO_PCI_OFFSET_SHIFT 40
23
24#define VFIO_PCI_OFFSET_TO_INDEX(off) (off >> VFIO_PCI_OFFSET_SHIFT)
25#define VFIO_PCI_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_PCI_OFFSET_SHIFT)
26#define VFIO_PCI_OFFSET_MASK (((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1)
27
345d7104
AW
28/* Special capability IDs predefined access */
29#define PCI_CAP_ID_INVALID 0xFF /* default raw access */
30#define PCI_CAP_ID_INVALID_VIRT 0xFE /* default virt access */
31
30656177
AW
32/* Cap maximum number of ioeventfds per device (arbitrary) */
33#define VFIO_PCI_IOEVENTFD_MAX 1000
34
35struct vfio_pci_ioeventfd {
36 struct list_head next;
37 struct virqfd *virqfd;
38 void __iomem *addr;
39 uint64_t data;
40 loff_t pos;
41 int bar;
42 int count;
43};
44
89e1f7d4
AW
45struct vfio_pci_irq_ctx {
46 struct eventfd_ctx *trigger;
47 struct virqfd *unmask;
48 struct virqfd *mask;
49 char *name;
50 bool masked;
6d7425f1 51 struct irq_bypass_producer producer;
89e1f7d4
AW
52};
53
28541d41
AW
54struct vfio_pci_device;
55struct vfio_pci_region;
56
57struct vfio_pci_regops {
58 size_t (*rw)(struct vfio_pci_device *vdev, char __user *buf,
59 size_t count, loff_t *ppos, bool iswrite);
60 void (*release)(struct vfio_pci_device *vdev,
61 struct vfio_pci_region *region);
62};
63
64struct vfio_pci_region {
65 u32 type;
66 u32 subtype;
67 const struct vfio_pci_regops *ops;
68 void *data;
69 size_t size;
70 u32 flags;
71};
72
05f0c03f
YX
73struct vfio_pci_dummy_resource {
74 struct resource resource;
75 int index;
76 struct list_head res_next;
77};
78
e309df5b
AW
79struct vfio_pci_reflck {
80 struct kref kref;
81 struct mutex lock;
82};
83
89e1f7d4
AW
84struct vfio_pci_device {
85 struct pci_dev *pdev;
86 void __iomem *barmap[PCI_STD_RESOURCE_END + 1];
05f0c03f 87 bool bar_mmap_supported[PCI_STD_RESOURCE_END + 1];
89e1f7d4
AW
88 u8 *pci_config_map;
89 u8 *vconfig;
90 struct perm_bits *msi_perm;
91 spinlock_t irqlock;
92 struct mutex igate;
89e1f7d4
AW
93 struct vfio_pci_irq_ctx *ctx;
94 int num_ctx;
95 int irq_type;
28541d41
AW
96 int num_regions;
97 struct vfio_pci_region *region;
89e1f7d4
AW
98 u8 msi_qmax;
99 u8 msix_bar;
100 u16 msix_size;
101 u32 msix_offset;
102 u32 rbar[7];
103 bool pci_2_3;
104 bool virq_disabled;
105 bool reset_works;
106 bool extended_caps;
107 bool bardirty;
84237a82 108 bool has_vga;
bc4fba77 109 bool needs_reset;
45074405 110 bool nointx;
89e1f7d4 111 struct pci_saved_state *pci_saved_state;
e309df5b 112 struct vfio_pci_reflck *reflck;
61d79256 113 int refcnt;
30656177 114 int ioeventfds_nr;
dad9f897 115 struct eventfd_ctx *err_trigger;
6140a8f5 116 struct eventfd_ctx *req_trigger;
05f0c03f 117 struct list_head dummy_resources_list;
30656177
AW
118 struct mutex ioeventfds_lock;
119 struct list_head ioeventfds_list;
89e1f7d4
AW
120};
121
122#define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX)
123#define is_msi(vdev) (vdev->irq_type == VFIO_PCI_MSI_IRQ_INDEX)
124#define is_msix(vdev) (vdev->irq_type == VFIO_PCI_MSIX_IRQ_INDEX)
125#define is_irq_none(vdev) (!(is_intx(vdev) || is_msi(vdev) || is_msix(vdev)))
126#define irq_is(vdev, type) (vdev->irq_type == type)
127
128extern void vfio_pci_intx_mask(struct vfio_pci_device *vdev);
129extern void vfio_pci_intx_unmask(struct vfio_pci_device *vdev);
130
131extern int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev,
132 uint32_t flags, unsigned index,
133 unsigned start, unsigned count, void *data);
134
906ee99d
AW
135extern ssize_t vfio_pci_config_rw(struct vfio_pci_device *vdev,
136 char __user *buf, size_t count,
137 loff_t *ppos, bool iswrite);
138
139extern ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
140 size_t count, loff_t *ppos, bool iswrite);
89e1f7d4 141
84237a82
AW
142extern ssize_t vfio_pci_vga_rw(struct vfio_pci_device *vdev, char __user *buf,
143 size_t count, loff_t *ppos, bool iswrite);
144
30656177
AW
145extern long vfio_pci_ioeventfd(struct vfio_pci_device *vdev, loff_t offset,
146 uint64_t data, int count, int fd);
147
89e1f7d4
AW
148extern int vfio_pci_init_perm_bits(void);
149extern void vfio_pci_uninit_perm_bits(void);
150
89e1f7d4
AW
151extern int vfio_config_init(struct vfio_pci_device *vdev);
152extern void vfio_config_free(struct vfio_pci_device *vdev);
28541d41
AW
153
154extern int vfio_pci_register_dev_region(struct vfio_pci_device *vdev,
155 unsigned int type, unsigned int subtype,
156 const struct vfio_pci_regops *ops,
157 size_t size, u32 flags, void *data);
5846ff54 158#ifdef CONFIG_VFIO_PCI_IGD
f572a960 159extern int vfio_pci_igd_init(struct vfio_pci_device *vdev);
5846ff54 160#else
f572a960 161static inline int vfio_pci_igd_init(struct vfio_pci_device *vdev)
5846ff54
AW
162{
163 return -ENODEV;
164}
165#endif
89e1f7d4 166#endif /* VFIO_PCI_PRIVATE_H */