1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/virtio_byteorder.h>
3 #include <linux/virtio.h>
4 #include <uapi/linux/virtio_config.h>
6 struct virtio_config_ops {
7 int (*disable_vq_and_reset)(struct virtqueue *vq);
8 int (*enable_vq_after_reset)(struct virtqueue *vq);
12 * __virtio_test_bit - helper to test feature bits. For use by transports.
13 * Devices should normally use virtio_has_feature,
14 * which includes more checks.
16 * @fbit: the feature bit
18 static inline bool __virtio_test_bit(const struct virtio_device *vdev,
21 return vdev->features & (1ULL << fbit);
25 * __virtio_set_bit - helper to set feature bits. For use by transports.
27 * @fbit: the feature bit
29 static inline void __virtio_set_bit(struct virtio_device *vdev,
32 vdev->features |= (1ULL << fbit);
36 * __virtio_clear_bit - helper to clear feature bits. For use by transports.
38 * @fbit: the feature bit
40 static inline void __virtio_clear_bit(struct virtio_device *vdev,
43 vdev->features &= ~(1ULL << fbit);
46 #define virtio_has_feature(dev, feature) \
47 (__virtio_test_bit((dev), feature))
50 * virtio_has_dma_quirk - determine whether this device has the DMA quirk
53 static inline bool virtio_has_dma_quirk(const struct virtio_device *vdev)
56 * Note the reverse polarity of the quirk feature (compared to most
57 * other features), this is for compatibility with legacy systems.
59 return !virtio_has_feature(vdev, VIRTIO_F_ACCESS_PLATFORM);
62 static inline bool virtio_is_little_endian(struct virtio_device *vdev)
64 return virtio_has_feature(vdev, VIRTIO_F_VERSION_1) ||
65 virtio_legacy_is_little_endian();
68 /* Memory accessors */
69 static inline u16 virtio16_to_cpu(struct virtio_device *vdev, __virtio16 val)
71 return __virtio16_to_cpu(virtio_is_little_endian(vdev), val);
74 static inline __virtio16 cpu_to_virtio16(struct virtio_device *vdev, u16 val)
76 return __cpu_to_virtio16(virtio_is_little_endian(vdev), val);
79 static inline u32 virtio32_to_cpu(struct virtio_device *vdev, __virtio32 val)
81 return __virtio32_to_cpu(virtio_is_little_endian(vdev), val);
84 static inline __virtio32 cpu_to_virtio32(struct virtio_device *vdev, u32 val)
86 return __cpu_to_virtio32(virtio_is_little_endian(vdev), val);
89 static inline u64 virtio64_to_cpu(struct virtio_device *vdev, __virtio64 val)
91 return __virtio64_to_cpu(virtio_is_little_endian(vdev), val);
94 static inline __virtio64 cpu_to_virtio64(struct virtio_device *vdev, u64 val)
96 return __cpu_to_virtio64(virtio_is_little_endian(vdev), val);