2012-07-31 21:16:24 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc. All rights reserved.
|
|
|
|
* Author: Alex Williamson <alex.williamson@redhat.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Derived from original vfio:
|
|
|
|
* Copyright 2010 Cisco Systems, Inc. All rights reserved.
|
|
|
|
* Author: Tom Lyon, pugs@cisco.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/pci.h>
|
2015-09-18 21:29:50 +07:00
|
|
|
#include <linux/irqbypass.h>
|
2016-02-23 06:02:39 +07:00
|
|
|
#include <linux/types.h>
|
2012-07-31 21:16:24 +07:00
|
|
|
|
|
|
|
#ifndef VFIO_PCI_PRIVATE_H
|
|
|
|
#define VFIO_PCI_PRIVATE_H
|
|
|
|
|
|
|
|
#define VFIO_PCI_OFFSET_SHIFT 40
|
|
|
|
|
|
|
|
#define VFIO_PCI_OFFSET_TO_INDEX(off) (off >> VFIO_PCI_OFFSET_SHIFT)
|
|
|
|
#define VFIO_PCI_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_PCI_OFFSET_SHIFT)
|
|
|
|
#define VFIO_PCI_OFFSET_MASK (((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1)
|
|
|
|
|
2016-02-23 06:02:41 +07:00
|
|
|
/* Special capability IDs predefined access */
|
|
|
|
#define PCI_CAP_ID_INVALID 0xFF /* default raw access */
|
|
|
|
#define PCI_CAP_ID_INVALID_VIRT 0xFE /* default virt access */
|
|
|
|
|
2012-07-31 21:16:24 +07:00
|
|
|
struct vfio_pci_irq_ctx {
|
|
|
|
struct eventfd_ctx *trigger;
|
|
|
|
struct virqfd *unmask;
|
|
|
|
struct virqfd *mask;
|
|
|
|
char *name;
|
|
|
|
bool masked;
|
2015-09-18 21:29:50 +07:00
|
|
|
struct irq_bypass_producer producer;
|
2012-07-31 21:16:24 +07:00
|
|
|
};
|
|
|
|
|
2016-02-23 06:02:39 +07:00
|
|
|
struct vfio_pci_device;
|
|
|
|
struct vfio_pci_region;
|
|
|
|
|
|
|
|
struct vfio_pci_regops {
|
|
|
|
size_t (*rw)(struct vfio_pci_device *vdev, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos, bool iswrite);
|
|
|
|
void (*release)(struct vfio_pci_device *vdev,
|
|
|
|
struct vfio_pci_region *region);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vfio_pci_region {
|
|
|
|
u32 type;
|
|
|
|
u32 subtype;
|
|
|
|
const struct vfio_pci_regops *ops;
|
|
|
|
void *data;
|
|
|
|
size_t size;
|
|
|
|
u32 flags;
|
|
|
|
};
|
|
|
|
|
2012-07-31 21:16:24 +07:00
|
|
|
struct vfio_pci_device {
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
void __iomem *barmap[PCI_STD_RESOURCE_END + 1];
|
|
|
|
u8 *pci_config_map;
|
|
|
|
u8 *vconfig;
|
|
|
|
struct perm_bits *msi_perm;
|
|
|
|
spinlock_t irqlock;
|
|
|
|
struct mutex igate;
|
|
|
|
struct msix_entry *msix;
|
|
|
|
struct vfio_pci_irq_ctx *ctx;
|
|
|
|
int num_ctx;
|
|
|
|
int irq_type;
|
2016-02-23 06:02:39 +07:00
|
|
|
int num_regions;
|
|
|
|
struct vfio_pci_region *region;
|
2012-07-31 21:16:24 +07:00
|
|
|
u8 msi_qmax;
|
|
|
|
u8 msix_bar;
|
|
|
|
u16 msix_size;
|
|
|
|
u32 msix_offset;
|
|
|
|
u32 rbar[7];
|
|
|
|
bool pci_2_3;
|
|
|
|
bool virq_disabled;
|
|
|
|
bool reset_works;
|
|
|
|
bool extended_caps;
|
|
|
|
bool bardirty;
|
2013-02-19 00:11:13 +07:00
|
|
|
bool has_vga;
|
2014-08-08 00:12:07 +07:00
|
|
|
bool needs_reset;
|
2012-07-31 21:16:24 +07:00
|
|
|
struct pci_saved_state *pci_saved_state;
|
2014-08-08 00:12:04 +07:00
|
|
|
int refcnt;
|
2013-03-11 22:31:22 +07:00
|
|
|
struct eventfd_ctx *err_trigger;
|
2015-02-07 05:05:08 +07:00
|
|
|
struct eventfd_ctx *req_trigger;
|
2012-07-31 21:16:24 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX)
|
|
|
|
#define is_msi(vdev) (vdev->irq_type == VFIO_PCI_MSI_IRQ_INDEX)
|
|
|
|
#define is_msix(vdev) (vdev->irq_type == VFIO_PCI_MSIX_IRQ_INDEX)
|
|
|
|
#define is_irq_none(vdev) (!(is_intx(vdev) || is_msi(vdev) || is_msix(vdev)))
|
|
|
|
#define irq_is(vdev, type) (vdev->irq_type == type)
|
|
|
|
|
|
|
|
extern void vfio_pci_intx_mask(struct vfio_pci_device *vdev);
|
|
|
|
extern void vfio_pci_intx_unmask(struct vfio_pci_device *vdev);
|
|
|
|
|
|
|
|
extern int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev,
|
|
|
|
uint32_t flags, unsigned index,
|
|
|
|
unsigned start, unsigned count, void *data);
|
|
|
|
|
2013-02-15 04:02:12 +07:00
|
|
|
extern ssize_t vfio_pci_config_rw(struct vfio_pci_device *vdev,
|
|
|
|
char __user *buf, size_t count,
|
|
|
|
loff_t *ppos, bool iswrite);
|
|
|
|
|
|
|
|
extern ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos, bool iswrite);
|
2012-07-31 21:16:24 +07:00
|
|
|
|
2013-02-19 00:11:13 +07:00
|
|
|
extern ssize_t vfio_pci_vga_rw(struct vfio_pci_device *vdev, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos, bool iswrite);
|
|
|
|
|
2012-07-31 21:16:24 +07:00
|
|
|
extern int vfio_pci_init_perm_bits(void);
|
|
|
|
extern void vfio_pci_uninit_perm_bits(void);
|
|
|
|
|
|
|
|
extern int vfio_config_init(struct vfio_pci_device *vdev);
|
|
|
|
extern void vfio_config_free(struct vfio_pci_device *vdev);
|
2016-02-23 06:02:39 +07:00
|
|
|
|
|
|
|
extern int vfio_pci_register_dev_region(struct vfio_pci_device *vdev,
|
|
|
|
unsigned int type, unsigned int subtype,
|
|
|
|
const struct vfio_pci_regops *ops,
|
|
|
|
size_t size, u32 flags, void *data);
|
2012-07-31 21:16:24 +07:00
|
|
|
#endif /* VFIO_PCI_PRIVATE_H */
|