vfio: Define device specific region type capability
[linux-block.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>
89e1f7d4
AW
17
18#ifndef VFIO_PCI_PRIVATE_H
19#define VFIO_PCI_PRIVATE_H
20
21#define VFIO_PCI_OFFSET_SHIFT 40
22
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
27struct vfio_pci_irq_ctx {
28 struct eventfd_ctx *trigger;
29 struct virqfd *unmask;
30 struct virqfd *mask;
31 char *name;
32 bool masked;
6d7425f1 33 struct irq_bypass_producer producer;
89e1f7d4
AW
34};
35
36struct vfio_pci_device {
37 struct pci_dev *pdev;
38 void __iomem *barmap[PCI_STD_RESOURCE_END + 1];
39 u8 *pci_config_map;
40 u8 *vconfig;
41 struct perm_bits *msi_perm;
42 spinlock_t irqlock;
43 struct mutex igate;
44 struct msix_entry *msix;
45 struct vfio_pci_irq_ctx *ctx;
46 int num_ctx;
47 int irq_type;
48 u8 msi_qmax;
49 u8 msix_bar;
50 u16 msix_size;
51 u32 msix_offset;
52 u32 rbar[7];
53 bool pci_2_3;
54 bool virq_disabled;
55 bool reset_works;
56 bool extended_caps;
57 bool bardirty;
84237a82 58 bool has_vga;
bc4fba77 59 bool needs_reset;
89e1f7d4 60 struct pci_saved_state *pci_saved_state;
61d79256 61 int refcnt;
dad9f897 62 struct eventfd_ctx *err_trigger;
6140a8f5 63 struct eventfd_ctx *req_trigger;
89e1f7d4
AW
64};
65
66#define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX)
67#define is_msi(vdev) (vdev->irq_type == VFIO_PCI_MSI_IRQ_INDEX)
68#define is_msix(vdev) (vdev->irq_type == VFIO_PCI_MSIX_IRQ_INDEX)
69#define is_irq_none(vdev) (!(is_intx(vdev) || is_msi(vdev) || is_msix(vdev)))
70#define irq_is(vdev, type) (vdev->irq_type == type)
71
72extern void vfio_pci_intx_mask(struct vfio_pci_device *vdev);
73extern void vfio_pci_intx_unmask(struct vfio_pci_device *vdev);
74
75extern int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev,
76 uint32_t flags, unsigned index,
77 unsigned start, unsigned count, void *data);
78
906ee99d
AW
79extern ssize_t vfio_pci_config_rw(struct vfio_pci_device *vdev,
80 char __user *buf, size_t count,
81 loff_t *ppos, bool iswrite);
82
83extern ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
84 size_t count, loff_t *ppos, bool iswrite);
89e1f7d4 85
84237a82
AW
86extern ssize_t vfio_pci_vga_rw(struct vfio_pci_device *vdev, char __user *buf,
87 size_t count, loff_t *ppos, bool iswrite);
88
89e1f7d4
AW
89extern int vfio_pci_init_perm_bits(void);
90extern void vfio_pci_uninit_perm_bits(void);
91
89e1f7d4
AW
92extern int vfio_config_init(struct vfio_pci_device *vdev);
93extern void vfio_config_free(struct vfio_pci_device *vdev);
94#endif /* VFIO_PCI_PRIVATE_H */