Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / vdpa / vdpa_sim / vdpa_sim.h
blobb02142293d5bc4cfe2fe4a2b32eb0726f42de369
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (c) 2020, Red Hat Inc. All rights reserved.
4 */
6 #ifndef _VDPA_SIM_H
7 #define _VDPA_SIM_H
9 #include <linux/vringh.h>
10 #include <linux/vdpa.h>
11 #include <linux/virtio_byteorder.h>
12 #include <linux/vhost_iotlb.h>
13 #include <uapi/linux/virtio_config.h>
15 #define VDPASIM_FEATURES ((1ULL << VIRTIO_F_ANY_LAYOUT) | \
16 (1ULL << VIRTIO_F_VERSION_1) | \
17 (1ULL << VIRTIO_F_ACCESS_PLATFORM))
19 struct vdpasim;
21 struct vdpasim_virtqueue {
22 struct vringh vring;
23 struct vringh_kiov in_iov;
24 struct vringh_kiov out_iov;
25 unsigned short head;
26 bool ready;
27 u64 desc_addr;
28 u64 device_addr;
29 u64 driver_addr;
30 u32 num;
31 void *private;
32 irqreturn_t (*cb)(void *data);
35 struct vdpasim_dev_attr {
36 u64 supported_features;
37 size_t config_size;
38 size_t buffer_size;
39 int nvqs;
40 u32 id;
42 work_func_t work_fn;
43 void (*get_config)(struct vdpasim *vdpasim, void *config);
44 void (*set_config)(struct vdpasim *vdpasim, const void *config);
47 /* State of each vdpasim device */
48 struct vdpasim {
49 struct vdpa_device vdpa;
50 struct vdpasim_virtqueue *vqs;
51 struct work_struct work;
52 struct vdpasim_dev_attr dev_attr;
53 /* spinlock to synchronize virtqueue state */
54 spinlock_t lock;
55 /* virtio config according to device type */
56 void *config;
57 struct vhost_iotlb *iommu;
58 void *buffer;
59 u32 status;
60 u32 generation;
61 u64 features;
62 /* spinlock to synchronize iommu table */
63 spinlock_t iommu_lock;
66 struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *attr);
68 /* TODO: cross-endian support */
69 static inline bool vdpasim_is_little_endian(struct vdpasim *vdpasim)
71 return virtio_legacy_is_little_endian() ||
72 (vdpasim->features & (1ULL << VIRTIO_F_VERSION_1));
75 static inline u16 vdpasim16_to_cpu(struct vdpasim *vdpasim, __virtio16 val)
77 return __virtio16_to_cpu(vdpasim_is_little_endian(vdpasim), val);
80 static inline __virtio16 cpu_to_vdpasim16(struct vdpasim *vdpasim, u16 val)
82 return __cpu_to_virtio16(vdpasim_is_little_endian(vdpasim), val);
85 static inline u32 vdpasim32_to_cpu(struct vdpasim *vdpasim, __virtio32 val)
87 return __virtio32_to_cpu(vdpasim_is_little_endian(vdpasim), val);
90 static inline __virtio32 cpu_to_vdpasim32(struct vdpasim *vdpasim, u32 val)
92 return __cpu_to_virtio32(vdpasim_is_little_endian(vdpasim), val);
95 static inline u64 vdpasim64_to_cpu(struct vdpasim *vdpasim, __virtio64 val)
97 return __virtio64_to_cpu(vdpasim_is_little_endian(vdpasim), val);
100 static inline __virtio64 cpu_to_vdpasim64(struct vdpasim *vdpasim, u64 val)
102 return __cpu_to_virtio64(vdpasim_is_little_endian(vdpasim), val);
105 #endif