xref: /spdk/lib/vfio_user/host/vfio_user_internal.h (revision 73fe04a8198479b2e7c1fde69fb4e5cceb7b954c)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2020 Intel Corporation. All rights reserved.
3  */
4 
5 #ifndef _VFIO_INTERNAL_H
6 #define _VFIO_INTERNAL_H
7 
8 #include <linux/vfio.h>
9 #include "spdk/vfio_user_spec.h"
10 
11 #define VFIO_USER_MAJOR_VER			0
12 #define VFIO_USER_MINOR_VER			1
13 
14 /* Maximum memory regions supported */
15 #define VFIO_MAXIMUM_MEMORY_REGIONS		16
16 /* Maximum sparse memory regions in one BAR region */
17 #define VFIO_MAXIMUM_SPARSE_MMAP_REGIONS	8
18 
19 struct vfio_memory_region {
20 	uint64_t iova;
21 	uint64_t size; /* bytes */
22 	uint64_t vaddr;
23 	uint64_t offset;
24 	int fd;
25 	TAILQ_ENTRY(vfio_memory_region) link;
26 };
27 
28 struct vfio_sparse_mmaps {
29 	void *mem;
30 	uint64_t offset;
31 	size_t size;
32 };
33 
34 struct vfio_pci_region {
35 	uint64_t offset;
36 	size_t size;
37 	uint64_t flags;
38 	uint32_t nr_mmaps;
39 	struct vfio_sparse_mmaps mmaps[VFIO_MAXIMUM_SPARSE_MMAP_REGIONS];
40 };
41 
42 struct vfio_device {
43 	int fd;
44 
45 	char name[64];
46 	char path[PATH_MAX];
47 
48 	TAILQ_ENTRY(vfio_device) link;
49 
50 	/* PCI Regions */
51 	uint32_t pci_regions;
52 	struct vfio_pci_region regions[VFIO_PCI_NUM_REGIONS + 1];
53 	uint64_t flags;
54 
55 	struct spdk_mem_map *map;
56 	TAILQ_HEAD(, vfio_memory_region) mrs_head;
57 	uint32_t nr_mrs;
58 };
59 
60 int vfio_user_dev_setup(struct vfio_device *dev);
61 int vfio_user_get_dev_info(struct vfio_device *dev, struct vfio_user_device_info *dev_info,
62 			   size_t buf_len);
63 int vfio_user_get_dev_region_info(struct vfio_device *dev, struct vfio_region_info *region_info,
64 				  size_t buf_len, int *fds, int num_fds);
65 int vfio_user_dev_dma_map_unmap(struct vfio_device *dev, struct vfio_memory_region *mr, bool map);
66 int vfio_user_dev_mmio_access(struct vfio_device *dev, uint32_t index, uint64_t offset, size_t len,
67 			      void *buf, bool is_write);
68 /* For fuzzing only */
69 int vfio_user_dev_send_request(struct vfio_device *dev, enum vfio_user_command command,
70 			       void *arg, size_t arg_len, size_t buf_len, int *fds,
71 			       int max_fds);
72 
73 #endif
74