File Index
Files and directories
Sign in
FILE

common.h

File preview with syntax highlighting.

linux-6.19.14/drivers/vfio/pci/virtio/common.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2
  3#ifndef VIRTIO_VFIO_COMMON_H
  4#define VIRTIO_VFIO_COMMON_H
  5
  6#include <linux/kernel.h>
  7#include <linux/virtio.h>
  8#include <linux/vfio_pci_core.h>
  9#include <linux/virtio_pci.h>
 10
 11enum virtiovf_migf_state {
 12	VIRTIOVF_MIGF_STATE_ERROR = 1,
 13	VIRTIOVF_MIGF_STATE_PRECOPY = 2,
 14	VIRTIOVF_MIGF_STATE_COMPLETE = 3,
 15};
 16
 17enum virtiovf_load_state {
 18	VIRTIOVF_LOAD_STATE_READ_HEADER,
 19	VIRTIOVF_LOAD_STATE_PREP_HEADER_DATA,
 20	VIRTIOVF_LOAD_STATE_READ_HEADER_DATA,
 21	VIRTIOVF_LOAD_STATE_PREP_CHUNK,
 22	VIRTIOVF_LOAD_STATE_READ_CHUNK,
 23	VIRTIOVF_LOAD_STATE_LOAD_CHUNK,
 24};
 25
 26struct virtiovf_data_buffer {
 27	struct sg_append_table table;
 28	loff_t start_pos;
 29	u64 length;
 30	u64 allocated_length;
 31	struct list_head buf_elm;
 32	u8 include_header_object:1;
 33	struct virtiovf_migration_file *migf;
 34	/* Optimize virtiovf_get_migration_page() for sequential access */
 35	struct scatterlist *last_offset_sg;
 36	unsigned int sg_last_entry;
 37	unsigned long last_offset;
 38};
 39
 40enum virtiovf_migf_header_flags {
 41	VIRTIOVF_MIGF_HEADER_FLAGS_TAG_MANDATORY = 0,
 42	VIRTIOVF_MIGF_HEADER_FLAGS_TAG_OPTIONAL = 1 << 0,
 43};
 44
 45enum virtiovf_migf_header_tag {
 46	VIRTIOVF_MIGF_HEADER_TAG_DEVICE_DATA = 0,
 47};
 48
 49struct virtiovf_migration_header {
 50	__le64 record_size;
 51	/* For future use in case we may need to change the kernel protocol */
 52	__le32 flags; /* Use virtiovf_migf_header_flags */
 53	__le32 tag; /* Use virtiovf_migf_header_tag */
 54	__u8 data[]; /* Its size is given in the record_size */
 55};
 56
 57struct virtiovf_migration_file {
 58	struct file *filp;
 59	/* synchronize access to the file state */
 60	struct mutex lock;
 61	loff_t max_pos;
 62	u64 pre_copy_initial_bytes;
 63	struct ratelimit_state pre_copy_rl_state;
 64	u64 record_size;
 65	u32 record_tag;
 66	u8 has_obj_id:1;
 67	u32 obj_id;
 68	enum virtiovf_migf_state state;
 69	enum virtiovf_load_state load_state;
 70	/* synchronize access to the lists */
 71	spinlock_t list_lock;
 72	struct list_head buf_list;
 73	struct list_head avail_list;
 74	struct virtiovf_data_buffer *buf;
 75	struct virtiovf_data_buffer *buf_header;
 76	struct virtiovf_pci_core_device *virtvdev;
 77};
 78
 79struct virtiovf_pci_core_device {
 80	struct vfio_pci_core_device core_device;
 81#ifdef CONFIG_VIRTIO_VFIO_PCI_ADMIN_LEGACY
 82	u8 *bar0_virtual_buf;
 83	/* synchronize access to the virtual buf */
 84	struct mutex bar_mutex;
 85	void __iomem *notify_addr;
 86	u64 notify_offset;
 87	__le32 pci_base_addr_0;
 88	__le16 pci_cmd;
 89	u8 bar0_virtual_buf_size;
 90	u8 notify_bar;
 91#endif
 92
 93	/* LM related */
 94	u8 migrate_cap:1;
 95	u8 deferred_reset:1;
 96	/* protect migration state */
 97	struct mutex state_mutex;
 98	enum vfio_device_mig_state mig_state;
 99	/* protect the reset_done flow */
100	spinlock_t reset_lock;
101	struct virtiovf_migration_file *resuming_migf;
102	struct virtiovf_migration_file *saving_migf;
103};
104
105void virtiovf_set_migratable(struct virtiovf_pci_core_device *virtvdev);
106void virtiovf_open_migration(struct virtiovf_pci_core_device *virtvdev);
107void virtiovf_close_migration(struct virtiovf_pci_core_device *virtvdev);
108void virtiovf_migration_reset_done(struct pci_dev *pdev);
109
110#ifdef CONFIG_VIRTIO_VFIO_PCI_ADMIN_LEGACY
111int virtiovf_open_legacy_io(struct virtiovf_pci_core_device *virtvdev);
112int virtiovf_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
113				       struct vfio_region_info *info,
114				       struct vfio_info_cap *caps);
115ssize_t virtiovf_pci_core_write(struct vfio_device *core_vdev,
116				const char __user *buf, size_t count,
117				loff_t *ppos);
118ssize_t virtiovf_pci_core_read(struct vfio_device *core_vdev, char __user *buf,
119			       size_t count, loff_t *ppos);
120bool virtiovf_support_legacy_io(struct pci_dev *pdev);
121int virtiovf_init_legacy_io(struct virtiovf_pci_core_device *virtvdev);
122void virtiovf_release_legacy_io(struct virtiovf_pci_core_device *virtvdev);
123void virtiovf_legacy_io_reset_done(struct pci_dev *pdev);
124#endif
125
126#endif /* VIRTIO_VFIO_COMMON_H */
~/ Read-only file preview.